Skip to content
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
dacfae0
feat: added typescript support and updated docs accordingly
Jan 7, 2021
5030c1b
feat: added typescript support and updated docs accordingly
Jan 7, 2021
22d79a1
fix: added a line to the README about typescript support
Jan 7, 2021
f34e69c
Merge branch 'master' of https://github.com/LuckeeDev/nuxt-strapi
Jan 7, 2021
4e75844
fix: added "types" field in package.json
Jan 7, 2021
69ca806
added store module declaration
LuckeeDev Jan 7, 2021
e3ae2ba
refactored user type into a Record
LuckeeDev Jan 7, 2021
2a4dbbe
fix: linted code samples in the docs, refactored NuxtStrapiQueryParam…
Jan 7, 2021
2791b64
fix: removed line from index.md about ts, added declaration for NuxtA…
Jan 8, 2021
3a9c625
fix: made a link in the ts page relative to the current url; removed …
Jan 8, 2021
6eafe19
chore(release): 0.1.10
atinux Jan 8, 2021
8395829
feat: improvements
atinux Jan 11, 2021
72e0bb9
chore: use only node 10
atinux Jan 11, 2021
620946d
fix: merged changes from upstream branch
Jan 11, 2021
90f0f3e
fix: flatten config and handles dynamic expires
atinux Jan 11, 2021
572bbe5
chore: update packaging
pi0 Jan 12, 2021
e92f82f
fix: update module
pi0 Jan 12, 2021
df5c45e
chore: update tsconfig
pi0 Jan 12, 2021
1c14c01
chore: update yarn.lock
pi0 Jan 12, 2021
7ed431d
fix(plugin): extend class proto once with options
pi0 Jan 12, 2021
b55ee30
fix: set typescript target to esnext
pi0 Jan 12, 2021
1874649
fix: runtime code dosen't supports templating
pi0 Jan 12, 2021
0262284
Merge branch 'feat/improvements' of https://github.com/nuxt-community…
Jan 12, 2021
a90ffc2
fix: simplified isExpired function in utils.ts, removed index.d.ts fr…
Jan 12, 2021
3400eb1
fix: keep options.url as default
atinux Jan 12, 2021
5609f42
refactor: declared types in strapi.ts with "declaration": true in tsc…
Jan 12, 2021
5a81ece
Merge branch 'feat/improvements' of https://github.com/nuxt-community…
Jan 12, 2021
cacf5f6
refactor: rewritten types inside .ts files
Jan 12, 2021
e5a0edf
fix: the library builds correctly now
Jan 12, 2021
f2b5e97
fix: made searchParams optional in find() and count()
Jan 12, 2021
8400df5
fix: types are now correctly picked up by IDE
Jan 13, 2021
dcf6a84
chore: use ~strapi alias
atinux Jan 13, 2021
a83436b
chore: update tests
atinux Jan 13, 2021
f2d95ed
docs: add options
atinux Jan 13, 2021
e0fdf33
chore: update coverage
atinux Jan 14, 2021
548856d
docs: removed the "known issues" section in typescript.md
Jan 16, 2021
02a10b7
Update src/runtime/strapi.ts
atinux Jan 19, 2021
658c0c7
Update package.json
atinux Jan 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Common
node_modules
dist
.nuxt
*.log
cache/
lib/
types/
.DS_Store
coverage

# Plugin
lib/plugin.js

# Typings
/**/*.d.ts
sw.*
15 changes: 3 additions & 12 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},
extends: [
'@nuxtjs'
],
rules: {
'vue/singleline-html-element-content-newline': 0,
'vue/multiline-html-element-content-newline': 0,
'vue/html-self-closing': 0,
'vue/no-v-html': 0
}
'@nuxtjs',
'@nuxtjs/eslint-config-typescript'
]
}
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [10, 12]
node: [12]

steps:
- uses: actions/setup-node@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ node_modules
coverage
dist
sw.*

lib
types
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [0.1.10](https://github.com/nuxt-community/strapi-module/compare/v0.1.9...v0.1.10) (2021-01-08)


### Features

* added typescript support and updated docs accordingly ([#94](https://github.com/nuxt-community/strapi-module/issues/94)) ([64f1927](https://github.com/nuxt-community/strapi-module/commit/64f1927c2a412d0b8c0c8920431b1dbe30f35f2b))

### [0.1.9](https://github.com/nuxt-community/strapi-module/compare/v0.1.8...v0.1.9) (2020-12-18)


Expand Down
6 changes: 4 additions & 2 deletions docs/content/en/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ You can register an `error` hook to display a toast for example:

```js{}[plugins/strapi.js]
export default ({ $strapi, app }) => {
$strapi.hook('error', (e) => {
app.$toast.error(e.message)
$strapi.hook('error', (error) => {
app.$toast.error(error.message)
})
}
```

You can also get the original error from Strapi api with `error.original`.

### `userUpdated`

You can register an `userUpdated` hook to force refetch inside components:
Expand Down
56 changes: 56 additions & 0 deletions docs/content/en/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,59 @@ export default {
> Check out the [Strapi documentation](https://strapi.io/documentation/v3.x/content-api/api-endpoints.html#endpoints) on API endpoints.

See more in [Usage](/usage#entities).

## `key`

<badge>v0.2.0+</badge>

- Type: `String`
- Default: `'strapi_jwt'`

Key used for the cookie name as well as localStorage/sessionStorage key.

```js{}[nuxt.config.js]
export default {
strapi: {
key: 'userJwt'
}
}
```
## `expires`

<badge>v0.2.0+</badge>

- Type: `String` or `Number` or `'session'`
- Default: `'session'`

When `expires === 'session'`, the [sessionStorage](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) will be used to act like the cookie.

Otherwise, if the value is a string, it will be parsed using [ms](https://github.com/vercel/ms), ex: expires: '7d'

A number can also be provided as milliseconds, ex: expires: 7 * 24 * 3600 * 1000

```js{}[nuxt.config.js]
export default {
strapi: {
expires: '31d'
}
}
```

### `cookie`

<badge>v0.2.0+</badge>

- Type: `Object`
- Default: `{}`

Options to forward to the [cookie#options](https://github.com/jshttp/cookie#options-1) module, the `expires` property will be overwritten.

```js{}[nuxt.config.js]
export default {
strapi: {
cookie: {
sameSite: 'lax'
}
}
}
```
76 changes: 4 additions & 72 deletions docs/content/en/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,75 +81,7 @@ export default Vue.extend({
</script>
```

## Known issues

There are some known issues with the current implementation of TypeScript in the library,
so we have listed some workarounds.

### Entity shortcuts

The current TypeScript implementation doesn't support entity shortcuts: your code may work,
but it will throw type checking errors. This is why we made the `entity` parameter needed in
every method which involves a query.

You can however define the entities available to your Vue methods with
[string literal types](https://www.typescriptlang.org/docs/handbook/literal-types.html#string-literal-types)
as described below.

```vue
<script lang="ts">
import Vue from 'vue'
import { Context } from '@nuxt/types'

interface BlogPost {
title: string;
description: string;
}

type Entities = 'posts' | 'projects'

export default Vue.extend({
async asyncData (ctx: Context) {
const posts = await ctx.$strapi.find<BlogPost[], Entities>(
'posts'
)

return {
posts
}
}
})
</script>
```

### Query params

Some query methods won't be accepted by the compiler if you define generics as in `$strapi.find<BlogPost[]>`
(e.g.: the array methods described [here](/strapi#findentity-params)).

You can get around this issue by doing something like below.

```vue
<script lang="ts">
import Vue from 'vue'

interface BlogPost {
title: string;
description: string;
}

export default Vue.extend({
async asyncData (ctx: Context) {
const posts: BlogPost[] = await this.$strapi.find(
'posts'
)

return {
posts
}
}
})
</script>
```

> You can always declare the return type by assigning a type to the variable instead of the method.
<alert type="info">
Entity shortcuts will not be correctly picked up by the Typescript compiler,
we suggest not to use them if you're using Typescript.
</alert>
10 changes: 0 additions & 10 deletions example/nuxt.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions example/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { NuxtConfig } from '@nuxt/types'

export default <NuxtConfig>{
buildModules: ['@nuxt/typescript-build'],
modules: [
'../src/module.ts'
]
}
34 changes: 34 additions & 0 deletions example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
"DOM"
],
"esModuleInterop": true,
"allowJs": true,
"sourceMap": true,
"strict": true,
"noEmit": true,
"baseUrl": ".",
"paths": {
"~/*": [
"./*"
],
"@/*": [
"./*"
]
},
"types": [
"@types/node",
"@nuxt/types",
"../types"
]
},
"exclude": [
"node_modules"
]
}
17 changes: 4 additions & 13 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
module.exports = {
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.js',
'!lib/plugin.js'
],
preset: '@nuxt/test-utils',
moduleNameMapper: {
'^~/(.*)$': '<rootDir>/lib/$1',
'^~~$': '<rootDir>',
'^@@$': '<rootDir>',
'^@/(.*)$': '<rootDir>/lib/$1'
},
transform: {
'^.+\\.js$': 'babel-jest'
'~image': '<rootDir>/src/runtime/index.ts',
'~image/(.*)': '<rootDir>/src/runtime/$1',
'~/(.*)': '<rootDir>/$1'
}
}
Loading