@feathersjs/generators 5.0.0-pre.36 → 5.0.0-pre.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +0 -1
- package/lib/app/index.d.ts +38 -5
- package/lib/app/index.js +11 -21
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +18 -41
- package/lib/app/templates/app.tpl.js +10 -9
- package/lib/app/templates/app.tpl.js.map +1 -1
- package/lib/app/templates/app.tpl.ts +12 -9
- package/lib/app/templates/channels.tpl.js +1 -6
- package/lib/app/templates/channels.tpl.js.map +1 -1
- package/lib/app/templates/channels.tpl.ts +7 -9
- package/lib/app/templates/client.test.tpl.js +1 -1
- package/lib/app/templates/client.test.tpl.js.map +1 -1
- package/lib/app/templates/client.test.tpl.ts +4 -2
- package/lib/app/templates/client.tpl.js +1 -1
- package/lib/app/templates/client.tpl.js.map +1 -1
- package/lib/app/templates/client.tpl.ts +7 -4
- package/lib/app/templates/configuration.tpl.js +8 -4
- package/lib/app/templates/configuration.tpl.js.map +1 -1
- package/lib/app/templates/configuration.tpl.ts +15 -8
- package/lib/app/templates/declarations.tpl.js +4 -2
- package/lib/app/templates/declarations.tpl.js.map +1 -1
- package/lib/app/templates/declarations.tpl.ts +7 -2
- package/lib/app/templates/package.json.tpl.js +9 -3
- package/lib/app/templates/package.json.tpl.js.map +1 -1
- package/lib/app/templates/package.json.tpl.ts +9 -2
- package/lib/authentication/index.d.ts +3 -38
- package/lib/authentication/index.js +8 -23
- package/lib/authentication/index.js.map +1 -1
- package/lib/authentication/index.ts +58 -75
- package/lib/authentication/templates/authentication.tpl.js +4 -4
- package/lib/authentication/templates/authentication.tpl.js.map +1 -1
- package/lib/authentication/templates/authentication.tpl.ts +2 -1
- package/lib/authentication/templates/client.test.tpl.js +5 -5
- package/lib/authentication/templates/client.test.tpl.js.map +1 -1
- package/lib/authentication/templates/client.test.tpl.ts +11 -7
- package/lib/commons.d.ts +24 -3
- package/lib/commons.js +33 -1
- package/lib/commons.js.map +1 -1
- package/lib/commons.ts +41 -3
- package/lib/connection/index.d.ts +3 -20
- package/lib/connection/index.js +13 -10
- package/lib/connection/index.js.map +1 -1
- package/lib/connection/index.ts +58 -50
- package/lib/connection/templates/knex.tpl.js +10 -1
- package/lib/connection/templates/knex.tpl.js.map +1 -1
- package/lib/connection/templates/knex.tpl.ts +6 -0
- package/lib/connection/templates/mongodb.tpl.js +15 -9
- package/lib/connection/templates/mongodb.tpl.js.map +1 -1
- package/lib/connection/templates/mongodb.tpl.ts +20 -10
- package/lib/service/index.d.ts +4 -0
- package/lib/service/index.js +82 -73
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +94 -74
- package/lib/service/templates/client.tpl.js +2 -3
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +14 -14
- package/lib/service/templates/schema.json.tpl.js +43 -17
- package/lib/service/templates/schema.json.tpl.js.map +1 -1
- package/lib/service/templates/schema.json.tpl.ts +57 -16
- package/lib/service/templates/schema.typebox.tpl.js +46 -11
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/service/templates/schema.typebox.tpl.ts +63 -11
- package/lib/service/templates/service.tpl.d.ts +1 -1
- package/lib/service/templates/service.tpl.js +6 -2
- package/lib/service/templates/service.tpl.js.map +1 -1
- package/lib/service/templates/service.tpl.ts +11 -2
- package/lib/service/templates/shared.tpl.js +2 -2
- package/lib/service/templates/shared.tpl.js.map +1 -1
- package/lib/service/templates/shared.tpl.ts +13 -10
- package/lib/service/type/custom.tpl.js +1 -1
- package/lib/service/type/custom.tpl.js.map +1 -1
- package/lib/service/type/custom.tpl.ts +1 -1
- package/lib/service/type/knex.tpl.js +14 -8
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +21 -10
- package/lib/service/type/mongodb.tpl.js +1 -1
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +1 -1
- package/package.json +29 -24
- package/lib/authentication/templates/knex.tpl.d.ts +0 -2
- package/lib/authentication/templates/knex.tpl.js +0 -45
- package/lib/authentication/templates/knex.tpl.js.map +0 -1
- package/lib/authentication/templates/knex.tpl.ts +0 -62
- package/lib/authentication/templates/schema.json.tpl.d.ts +0 -2
- package/lib/authentication/templates/schema.json.tpl.js +0 -104
- package/lib/authentication/templates/schema.json.tpl.js.map +0 -1
- package/lib/authentication/templates/schema.json.tpl.ts +0 -125
- package/lib/authentication/templates/schema.typebox.tpl.d.ts +0 -3
- package/lib/authentication/templates/schema.typebox.tpl.js +0 -87
- package/lib/authentication/templates/schema.typebox.tpl.js.map +0 -1
- package/lib/authentication/templates/schema.typebox.tpl.ts +0 -109
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
|
-
import { fileExists, renderSource } from '../../commons'
|
|
3
|
-
import { AuthenticationGeneratorContext, localTemplate } from '../index'
|
|
4
|
-
|
|
5
|
-
export const template = ({
|
|
6
|
-
cwd,
|
|
7
|
-
lib,
|
|
8
|
-
camelName,
|
|
9
|
-
upperName,
|
|
10
|
-
authStrategies,
|
|
11
|
-
type,
|
|
12
|
-
relative
|
|
13
|
-
}: AuthenticationGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
14
|
-
import { resolve } from '@feathersjs/schema'
|
|
15
|
-
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'
|
|
16
|
-
import type { Static } from '@feathersjs/typebox'
|
|
17
|
-
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
18
|
-
|
|
19
|
-
import type { HookContext } from '${relative}/declarations'
|
|
20
|
-
import { dataValidator, queryValidator } from '${relative}/${
|
|
21
|
-
fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
|
|
22
|
-
}validators'
|
|
23
|
-
|
|
24
|
-
// Main data model schema
|
|
25
|
-
export const ${camelName}Schema = Type.Object({
|
|
26
|
-
${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
|
|
27
|
-
${authStrategies
|
|
28
|
-
.map((name) =>
|
|
29
|
-
name === 'local'
|
|
30
|
-
? ` email: Type.String(),
|
|
31
|
-
password: Type.Optional(Type.String())`
|
|
32
|
-
: ` ${name}Id: Type.Optional(Type.String())`
|
|
33
|
-
)
|
|
34
|
-
.join(',\n')}
|
|
35
|
-
},{ $id: '${upperName}', additionalProperties: false })
|
|
36
|
-
export type ${upperName} = Static<typeof ${camelName}Schema>
|
|
37
|
-
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
|
|
38
|
-
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
|
|
39
|
-
|
|
40
|
-
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
41
|
-
${localTemplate(
|
|
42
|
-
authStrategies,
|
|
43
|
-
`// The password should never be visible externally
|
|
44
|
-
password: async () => undefined`
|
|
45
|
-
)}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
// Schema for creating new users
|
|
49
|
-
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
50
|
-
${authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')}
|
|
51
|
-
],
|
|
52
|
-
{ $id: '${upperName}Data', additionalProperties: false }
|
|
53
|
-
)
|
|
54
|
-
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
55
|
-
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
56
|
-
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
57
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
// Schema for updating existing users
|
|
61
|
-
export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, {
|
|
62
|
-
$id: '${upperName}Patch'
|
|
63
|
-
})
|
|
64
|
-
export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
|
|
65
|
-
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
66
|
-
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({
|
|
67
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
// Schema for allowed query properties
|
|
71
|
-
export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, ['${
|
|
72
|
-
type === 'mongodb' ? '_id' : 'id'
|
|
73
|
-
}', ${authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')}
|
|
74
|
-
])
|
|
75
|
-
export const ${camelName}QuerySchema = Type.Intersect([
|
|
76
|
-
querySyntax(${camelName}QueryProperties),
|
|
77
|
-
// Add additional query properties here
|
|
78
|
-
Type.Object({}, { additionalProperties: false })
|
|
79
|
-
], { additionalProperties: false })
|
|
80
|
-
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
|
|
81
|
-
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
82
|
-
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
83
|
-
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
84
|
-
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
85
|
-
if (context.params.user) {
|
|
86
|
-
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return value
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
`
|
|
93
|
-
|
|
94
|
-
export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
95
|
-
generator(ctx).then(
|
|
96
|
-
when<AuthenticationGeneratorContext>(
|
|
97
|
-
({ schema }) => schema === 'typebox',
|
|
98
|
-
renderSource(
|
|
99
|
-
template,
|
|
100
|
-
toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
|
|
101
|
-
lib,
|
|
102
|
-
'services',
|
|
103
|
-
...folder,
|
|
104
|
-
`${fileName}.schema`
|
|
105
|
-
]),
|
|
106
|
-
{ force: true }
|
|
107
|
-
)
|
|
108
|
-
)
|
|
109
|
-
)
|