@feathersjs/generators 5.0.0-pre.37 → 5.0.0
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 +13 -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 +7 -4
- package/lib/app/templates/configuration.tpl.js.map +1 -1
- package/lib/app/templates/configuration.tpl.ts +14 -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 +19 -3
- package/lib/commons.js +19 -1
- package/lib/commons.js.map +1 -1
- package/lib/commons.ts +24 -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 +8 -8
- package/lib/connection/templates/mongodb.tpl.js.map +1 -1
- package/lib/connection/templates/mongodb.tpl.ts +11 -9
- 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 +1 -3
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +7 -5
- package/lib/service/templates/schema.json.tpl.js +43 -22
- package/lib/service/templates/schema.json.tpl.js.map +1 -1
- package/lib/service/templates/schema.json.tpl.ts +56 -22
- 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 +13 -3
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +19 -3
- 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 +24 -24
- package/lib/authentication/templates/knex.tpl.d.ts +0 -2
- package/lib/authentication/templates/knex.tpl.js +0 -37
- package/lib/authentication/templates/knex.tpl.js.map +0 -1
- package/lib/authentication/templates/knex.tpl.ts +0 -56
- package/lib/authentication/templates/schema.json.tpl.d.ts +0 -2
- package/lib/authentication/templates/schema.json.tpl.js +0 -109
- package/lib/authentication/templates/schema.json.tpl.js.map +0 -1
- package/lib/authentication/templates/schema.json.tpl.ts +0 -132
- 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,17 +1,35 @@
|
|
|
1
1
|
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
|
-
import { fileExists, renderSource } from '../../commons'
|
|
2
|
+
import { fileExists, localTemplate, renderSource } from '../../commons'
|
|
3
3
|
import { ServiceGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
|
+
const authFieldsTemplate = (authStrategies: string[]) =>
|
|
6
|
+
authStrategies
|
|
7
|
+
.map((name) =>
|
|
8
|
+
name === 'local'
|
|
9
|
+
? ` email: { type: 'string' },
|
|
10
|
+
password: { type: 'string' }`
|
|
11
|
+
: ` ${name}Id: { type: 'string' }`
|
|
12
|
+
)
|
|
13
|
+
.join(',\n')
|
|
14
|
+
|
|
5
15
|
const template = ({
|
|
6
16
|
camelName,
|
|
7
17
|
upperName,
|
|
8
18
|
relative,
|
|
19
|
+
authStrategies,
|
|
20
|
+
isEntityService,
|
|
9
21
|
type,
|
|
10
22
|
cwd,
|
|
11
23
|
lib
|
|
12
24
|
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
13
|
-
import { resolve, getValidator, querySyntax } from '@feathersjs/schema'
|
|
25
|
+
import { resolve, getValidator, querySyntax } from '@feathersjs/schema'${
|
|
26
|
+
type === 'mongodb'
|
|
27
|
+
? `
|
|
28
|
+
import { ObjectIdSchema } from '@feathersjs/schema'`
|
|
29
|
+
: ''
|
|
30
|
+
}
|
|
14
31
|
import type { FromSchema } from '@feathersjs/schema'
|
|
32
|
+
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
15
33
|
|
|
16
34
|
import type { HookContext } from '${relative}/declarations'
|
|
17
35
|
import { dataValidator, queryValidator } from '${relative}/${
|
|
@@ -23,20 +41,14 @@ export const ${camelName}Schema = {
|
|
|
23
41
|
$id: '${upperName}',
|
|
24
42
|
type: 'object',
|
|
25
43
|
additionalProperties: false,
|
|
26
|
-
required: [ '${type === 'mongodb' ? '_id' : 'id'}', 'text' ],
|
|
44
|
+
required: [ '${type === 'mongodb' ? '_id' : 'id'}', ${localTemplate(authStrategies, `'email'`, `'text'`)} ],
|
|
27
45
|
properties: {
|
|
46
|
+
${type === 'mongodb' ? `_id: ObjectIdSchema(),` : `id: { type: 'number' },`}
|
|
28
47
|
${
|
|
29
|
-
|
|
30
|
-
?
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},`
|
|
34
|
-
: `id: {
|
|
35
|
-
type: 'number'
|
|
36
|
-
},`
|
|
37
|
-
}
|
|
38
|
-
text: {
|
|
39
|
-
type: 'string'
|
|
48
|
+
isEntityService
|
|
49
|
+
? authFieldsTemplate(authStrategies)
|
|
50
|
+
: `
|
|
51
|
+
text: { type: 'string' }`
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
} as const
|
|
@@ -44,23 +56,29 @@ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
|
44
56
|
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
|
|
45
57
|
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
|
|
46
58
|
|
|
47
|
-
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
59
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
60
|
+
${localTemplate(
|
|
61
|
+
authStrategies,
|
|
62
|
+
`// The password should never be visible externally
|
|
63
|
+
password: async () => undefined`
|
|
64
|
+
)}
|
|
65
|
+
})
|
|
48
66
|
|
|
49
67
|
// Schema for creating new data
|
|
50
68
|
export const ${camelName}DataSchema = {
|
|
51
69
|
$id: '${upperName}Data',
|
|
52
70
|
type: 'object',
|
|
53
71
|
additionalProperties: false,
|
|
54
|
-
required: [ 'text' ],
|
|
72
|
+
required: [ ${localTemplate(authStrategies, `'email'`, `'text'`)} ],
|
|
55
73
|
properties: {
|
|
56
|
-
|
|
57
|
-
type: 'string'
|
|
58
|
-
}
|
|
74
|
+
...${camelName}Schema.properties
|
|
59
75
|
}
|
|
60
76
|
} as const
|
|
61
77
|
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
62
78
|
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
63
|
-
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
79
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
80
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
81
|
+
})
|
|
64
82
|
|
|
65
83
|
// Schema for updating existing data
|
|
66
84
|
export const ${camelName}PatchSchema = {
|
|
@@ -74,7 +92,9 @@ export const ${camelName}PatchSchema = {
|
|
|
74
92
|
} as const
|
|
75
93
|
export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
|
|
76
94
|
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
77
|
-
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
|
|
95
|
+
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
|
|
96
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
97
|
+
})
|
|
78
98
|
|
|
79
99
|
// Schema for allowed query properties
|
|
80
100
|
export const ${camelName}QuerySchema = {
|
|
@@ -87,7 +107,21 @@ export const ${camelName}QuerySchema = {
|
|
|
87
107
|
} as const
|
|
88
108
|
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
89
109
|
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
90
|
-
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
110
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
111
|
+
${
|
|
112
|
+
isEntityService
|
|
113
|
+
? `
|
|
114
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
115
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
116
|
+
if (context.params.user) {
|
|
117
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return value
|
|
121
|
+
}`
|
|
122
|
+
: ''
|
|
123
|
+
}
|
|
124
|
+
})
|
|
91
125
|
`
|
|
92
126
|
|
|
93
127
|
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
@@ -3,10 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const
|
|
6
|
+
const authFieldsTemplate = (authStrategies) => authStrategies
|
|
7
|
+
.map((name) => name === 'local'
|
|
8
|
+
? ` email: Type.String(),
|
|
9
|
+
password: Type.Optional(Type.String())`
|
|
10
|
+
: ` ${name}Id: Type.Optional(Type.String())`)
|
|
11
|
+
.join(',\n');
|
|
12
|
+
const template = ({ camelName, upperName, relative, authStrategies, isEntityService, type, cwd, lib }) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
7
13
|
import { resolve } from '@feathersjs/schema'
|
|
8
|
-
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'
|
|
14
|
+
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'${type === 'mongodb'
|
|
15
|
+
? `
|
|
16
|
+
import { ObjectIdSchema } from '@feathersjs/typebox'`
|
|
17
|
+
: ''}
|
|
9
18
|
import type { Static } from '@feathersjs/typebox'
|
|
19
|
+
${(0, commons_1.localTemplate)(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
10
20
|
|
|
11
21
|
import type { HookContext } from '${relative}/declarations'
|
|
12
22
|
import { dataValidator, queryValidator } from '${relative}/${(0, commons_1.fileExists)(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
|
|
@@ -14,34 +24,47 @@ import { dataValidator, queryValidator } from '${relative}/${(0, commons_1.fileE
|
|
|
14
24
|
|
|
15
25
|
// Main data model schema
|
|
16
26
|
export const ${camelName}Schema = Type.Object({
|
|
17
|
-
${type === 'mongodb' ? '_id:
|
|
18
|
-
text: Type.String()
|
|
27
|
+
${type === 'mongodb' ? '_id: ObjectIdSchema()' : 'id: Type.Number()'},
|
|
28
|
+
${isEntityService ? authFieldsTemplate(authStrategies) : `text: Type.String()`}
|
|
19
29
|
}, { $id: '${upperName}', additionalProperties: false })
|
|
20
30
|
export type ${upperName} = Static<typeof ${camelName}Schema>
|
|
21
31
|
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
|
|
22
32
|
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
|
|
23
33
|
|
|
24
|
-
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
34
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
35
|
+
${(0, commons_1.localTemplate)(authStrategies, `// The password should never be visible externally
|
|
36
|
+
password: async () => undefined`)}
|
|
37
|
+
})
|
|
25
38
|
|
|
26
39
|
// Schema for creating new entries
|
|
27
|
-
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
40
|
+
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
41
|
+
${isEntityService
|
|
42
|
+
? authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')
|
|
43
|
+
: `'text'`}
|
|
44
|
+
], {
|
|
28
45
|
$id: '${upperName}Data'
|
|
29
46
|
})
|
|
30
47
|
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
31
48
|
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
32
|
-
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
49
|
+
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
50
|
+
${(0, commons_1.localTemplate)(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
51
|
+
})
|
|
33
52
|
|
|
34
53
|
// Schema for updating existing entries
|
|
35
|
-
export const ${camelName}PatchSchema = Type.Partial(${camelName}
|
|
54
|
+
export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, {
|
|
36
55
|
$id: '${upperName}Patch'
|
|
37
56
|
})
|
|
38
57
|
export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
|
|
39
58
|
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
40
|
-
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({
|
|
59
|
+
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({
|
|
60
|
+
${(0, commons_1.localTemplate)(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
61
|
+
})
|
|
41
62
|
|
|
42
63
|
// Schema for allowed query properties
|
|
43
64
|
export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, [
|
|
44
|
-
'${type === 'mongodb' ? '_id' : 'id'}',
|
|
65
|
+
'${type === 'mongodb' ? '_id' : 'id'}', ${isEntityService
|
|
66
|
+
? authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')
|
|
67
|
+
: `'text'`}
|
|
45
68
|
])
|
|
46
69
|
export const ${camelName}QuerySchema = Type.Intersect([
|
|
47
70
|
querySyntax(${camelName}QueryProperties),
|
|
@@ -50,7 +73,19 @@ export const ${camelName}QuerySchema = Type.Intersect([
|
|
|
50
73
|
], { additionalProperties: false })
|
|
51
74
|
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
|
|
52
75
|
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
53
|
-
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
76
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
77
|
+
${isEntityService
|
|
78
|
+
? `
|
|
79
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
80
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
81
|
+
if (context.params.user) {
|
|
82
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return value
|
|
86
|
+
}`
|
|
87
|
+
: ''}
|
|
88
|
+
})
|
|
54
89
|
`;
|
|
55
90
|
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)(({ schema }) => schema === 'typebox', (0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
56
91
|
lib,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAAuE;AAGvE,MAAM,kBAAkB,GAAG,CAAC,cAAwB,EAAE,EAAE,CACtD,cAAc;KACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,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AE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,CACH,CACF,CACF,CAAA;AAdU,QAAA,QAAQ,YAclB"}
|
|
@@ -1,18 +1,36 @@
|
|
|
1
1
|
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
|
-
import { fileExists, renderSource } from '../../commons'
|
|
2
|
+
import { fileExists, localTemplate, renderSource } from '../../commons'
|
|
3
3
|
import { ServiceGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
|
+
const authFieldsTemplate = (authStrategies: string[]) =>
|
|
6
|
+
authStrategies
|
|
7
|
+
.map((name) =>
|
|
8
|
+
name === 'local'
|
|
9
|
+
? ` email: Type.String(),
|
|
10
|
+
password: Type.Optional(Type.String())`
|
|
11
|
+
: ` ${name}Id: Type.Optional(Type.String())`
|
|
12
|
+
)
|
|
13
|
+
.join(',\n')
|
|
14
|
+
|
|
5
15
|
const template = ({
|
|
6
16
|
camelName,
|
|
7
17
|
upperName,
|
|
8
18
|
relative,
|
|
19
|
+
authStrategies,
|
|
20
|
+
isEntityService,
|
|
9
21
|
type,
|
|
10
22
|
cwd,
|
|
11
23
|
lib
|
|
12
24
|
}: ServiceGeneratorContext) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
13
25
|
import { resolve } from '@feathersjs/schema'
|
|
14
|
-
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'
|
|
26
|
+
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'${
|
|
27
|
+
type === 'mongodb'
|
|
28
|
+
? `
|
|
29
|
+
import { ObjectIdSchema } from '@feathersjs/typebox'`
|
|
30
|
+
: ''
|
|
31
|
+
}
|
|
15
32
|
import type { Static } from '@feathersjs/typebox'
|
|
33
|
+
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
16
34
|
|
|
17
35
|
import type { HookContext } from '${relative}/declarations'
|
|
18
36
|
import { dataValidator, queryValidator } from '${relative}/${
|
|
@@ -21,34 +39,54 @@ import { dataValidator, queryValidator } from '${relative}/${
|
|
|
21
39
|
|
|
22
40
|
// Main data model schema
|
|
23
41
|
export const ${camelName}Schema = Type.Object({
|
|
24
|
-
${type === 'mongodb' ? '_id:
|
|
25
|
-
text: Type.String()
|
|
42
|
+
${type === 'mongodb' ? '_id: ObjectIdSchema()' : 'id: Type.Number()'},
|
|
43
|
+
${isEntityService ? authFieldsTemplate(authStrategies) : `text: Type.String()`}
|
|
26
44
|
}, { $id: '${upperName}', additionalProperties: false })
|
|
27
45
|
export type ${upperName} = Static<typeof ${camelName}Schema>
|
|
28
46
|
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
|
|
29
47
|
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
|
|
30
48
|
|
|
31
|
-
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
49
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
50
|
+
${localTemplate(
|
|
51
|
+
authStrategies,
|
|
52
|
+
`// The password should never be visible externally
|
|
53
|
+
password: async () => undefined`
|
|
54
|
+
)}
|
|
55
|
+
})
|
|
32
56
|
|
|
33
57
|
// Schema for creating new entries
|
|
34
|
-
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
58
|
+
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
59
|
+
${
|
|
60
|
+
isEntityService
|
|
61
|
+
? authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')
|
|
62
|
+
: `'text'`
|
|
63
|
+
}
|
|
64
|
+
], {
|
|
35
65
|
$id: '${upperName}Data'
|
|
36
66
|
})
|
|
37
67
|
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
38
68
|
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
39
|
-
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
69
|
+
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
70
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
71
|
+
})
|
|
40
72
|
|
|
41
73
|
// Schema for updating existing entries
|
|
42
|
-
export const ${camelName}PatchSchema = Type.Partial(${camelName}
|
|
74
|
+
export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, {
|
|
43
75
|
$id: '${upperName}Patch'
|
|
44
76
|
})
|
|
45
77
|
export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
|
|
46
78
|
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
47
|
-
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({
|
|
79
|
+
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({
|
|
80
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
81
|
+
})
|
|
48
82
|
|
|
49
83
|
// Schema for allowed query properties
|
|
50
84
|
export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, [
|
|
51
|
-
'${type === 'mongodb' ? '_id' : 'id'}',
|
|
85
|
+
'${type === 'mongodb' ? '_id' : 'id'}', ${
|
|
86
|
+
isEntityService
|
|
87
|
+
? authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')
|
|
88
|
+
: `'text'`
|
|
89
|
+
}
|
|
52
90
|
])
|
|
53
91
|
export const ${camelName}QuerySchema = Type.Intersect([
|
|
54
92
|
querySyntax(${camelName}QueryProperties),
|
|
@@ -57,7 +95,21 @@ export const ${camelName}QuerySchema = Type.Intersect([
|
|
|
57
95
|
], { additionalProperties: false })
|
|
58
96
|
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
|
|
59
97
|
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
60
|
-
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
98
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
99
|
+
${
|
|
100
|
+
isEntityService
|
|
101
|
+
? `
|
|
102
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
103
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
104
|
+
if (context.params.user) {
|
|
105
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return value
|
|
109
|
+
}`
|
|
110
|
+
: ''
|
|
111
|
+
}
|
|
112
|
+
})
|
|
61
113
|
`
|
|
62
114
|
|
|
63
115
|
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ServiceGeneratorContext } from '../index';
|
|
2
|
-
export declare const template: ({ camelName, authentication, isEntityService, className, relative, schema, fileName }: ServiceGeneratorContext) => string;
|
|
2
|
+
export declare const template: ({ camelName, authentication, isEntityService, path, lib, language, className, relative, schema, fileName }: ServiceGeneratorContext) => string;
|
|
3
3
|
export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = exports.template = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const template = ({ camelName, authentication, isEntityService, className, relative, schema, fileName }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.html
|
|
6
|
+
const template = ({ camelName, authentication, isEntityService, path, lib, language, className, relative, schema, fileName }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.html
|
|
7
7
|
${authentication || isEntityService ? `import { authenticate } from '@feathersjs/authentication'` : ''}
|
|
8
8
|
${schema
|
|
9
9
|
? `
|
|
@@ -24,7 +24,11 @@ import {
|
|
|
24
24
|
|
|
25
25
|
import type { Application } from '${relative}/declarations'
|
|
26
26
|
import { ${className}, getOptions } from './${fileName}.class'
|
|
27
|
-
|
|
27
|
+
${(0, commons_1.fileExists)(lib, `client.${language}`)
|
|
28
|
+
? `import { ${camelName}Path, ${camelName}Methods } from './${fileName}.shared'`
|
|
29
|
+
: `
|
|
30
|
+
export const ${camelName}Path = '${path}'
|
|
31
|
+
export const ${camelName}Methods = ['find', 'get', 'create', 'patch', 'remove'] as const`}
|
|
28
32
|
|
|
29
33
|
export * from './${fileName}.class'
|
|
30
34
|
${schema ? `export * from './${fileName}.schema'` : ''}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/service.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AACtE,
|
|
1
|
+
{"version":3,"file":"service.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/service.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AACtE,2CAAsE;AAG/D,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,cAAc,EACd,eAAe,EACf,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,MAAM,EACN,QAAQ,EACgB,EAAE,EAAE,CAAC,QAAQ,CAAC;EACtC,cAAc,IAAI,eAAe,CAAC,CAAC,CAAC,2DAA2D,CAAC,CAAC,CAAC,EAAE;EAEpG,MAAM;IACJ,CAAC,CAAC;;;;IAIF,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;CACnB;IACG,CAAC,CAAC,EACN;;oCAEoC,QAAQ;WACjC,SAAS,0BAA0B,QAAQ;EAEpD,IAAA,oBAAU,EAAC,GAAG,EAAE,UAAU,QAAQ,EAAE,CAAC;IACnC,CAAC,CAAC,YAAY,SAAS,SAAS,SAAS,qBAAqB,QAAQ,UAAU;IAChF,CAAC,CAAC;eACS,SAAS,WAAW,IAAI;eACxB,SA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C,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAClC,YAAY,SAAS,cAAc,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,GAAG,EACpE,IAAA,gBAAO,GAAE,EACT,cAAc,CACf,CACF;KACA,IAAI,CACH,IAAA,sBAAY,EACV,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,mBAAmB,SAAS,GAAG,EAClD,IAAA,cAAK,EAAC,uBAAuB,CAAC,EAC9B,cAAc,CACf,CACF,CAAA;AA3BQ,QAAA,QAAQ,YA2BhB"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { generator, toFile, after, prepend } from '@feathershq/pinion'
|
|
2
|
-
import { injectSource, renderSource } from '../../commons'
|
|
2
|
+
import { fileExists, injectSource, renderSource } from '../../commons'
|
|
3
3
|
import { ServiceGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
5
|
export const template = ({
|
|
6
6
|
camelName,
|
|
7
7
|
authentication,
|
|
8
8
|
isEntityService,
|
|
9
|
+
path,
|
|
10
|
+
lib,
|
|
11
|
+
language,
|
|
9
12
|
className,
|
|
10
13
|
relative,
|
|
11
14
|
schema,
|
|
@@ -33,7 +36,13 @@ import {
|
|
|
33
36
|
|
|
34
37
|
import type { Application } from '${relative}/declarations'
|
|
35
38
|
import { ${className}, getOptions } from './${fileName}.class'
|
|
36
|
-
|
|
39
|
+
${
|
|
40
|
+
fileExists(lib, `client.${language}`)
|
|
41
|
+
? `import { ${camelName}Path, ${camelName}Methods } from './${fileName}.shared'`
|
|
42
|
+
: `
|
|
43
|
+
export const ${camelName}Path = '${path}'
|
|
44
|
+
export const ${camelName}Methods = ['find', 'get', 'create', 'patch', 'remove'] as const`
|
|
45
|
+
}
|
|
37
46
|
|
|
38
47
|
export * from './${fileName}.class'
|
|
39
48
|
${schema ? `export * from './${fileName}.schema'` : ''}
|
|
@@ -40,11 +40,11 @@ declare module '${relative}/client' {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
`;
|
|
43
|
-
const generate = async (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(sharedTemplate, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
43
|
+
const generate = async (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)(({ lib, language }) => (0, commons_1.fileExists)(lib, `client.${language}`), (0, commons_1.renderSource)(sharedTemplate, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
44
44
|
lib,
|
|
45
45
|
'services',
|
|
46
46
|
...folder,
|
|
47
47
|
`${fileName}.shared`
|
|
48
|
-
])));
|
|
48
|
+
]))));
|
|
49
49
|
exports.generate = generate;
|
|
50
50
|
//# sourceMappingURL=shared.tpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/shared.tpl.ts"],"names":[],"mappings":";;;AAAA,+
|
|
1
|
+
{"version":3,"file":"shared.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/shared.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAAwD;AAGxD,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,IAAI,EACoB,EAAE,EAAE,CAAC,QAAQ,CAAC;;0CAEE,QAAQ;;IAE9C,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;;gBAEJ,SAAS,KAAK,SAAS,SAAS,SAAS,UAAU,SAAS;;cAE9D,SAAS;IACnB,SAAS,WAAW,SAAS;WACtB,SAAS;;;eAGL,SAAS,WAAW,IAAI;;eAExB,SAAS;;eAET,SAAS;;;eAGT,SAAS,4BAA4B,SAAS;eAC9C,SAAS;;;;;kBAKN,QAAQ;;OAEnB,SAAS,UAAU,SAAS;;;CAGlC,CAAA;AAEM,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,IAAA,oBAAU,EAAC,GAAG,EAAE,UAAU,QAAQ,EAAE,CAAC,EAC5D,IAAA,sBAAY,EACV,cAAc,EACd,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,CACH,CACF,CACF,CAAA;AAdU,QAAA,QAAQ,YAclB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { generator, toFile } from '@feathershq/pinion'
|
|
2
|
-
import { renderSource } from '../../commons'
|
|
1
|
+
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
|
+
import { fileExists, renderSource } from '../../commons'
|
|
3
3
|
import { ServiceGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
5
|
const sharedTemplate = ({
|
|
@@ -49,13 +49,16 @@ declare module '${relative}/client' {
|
|
|
49
49
|
|
|
50
50
|
export const generate = async (ctx: ServiceGeneratorContext) =>
|
|
51
51
|
generator(ctx).then(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
when<ServiceGeneratorContext>(
|
|
53
|
+
({ lib, language }) => fileExists(lib, `client.${language}`),
|
|
54
|
+
renderSource(
|
|
55
|
+
sharedTemplate,
|
|
56
|
+
toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
|
|
57
|
+
lib,
|
|
58
|
+
'services',
|
|
59
|
+
...folder,
|
|
60
|
+
`${fileName}.shared`
|
|
61
|
+
])
|
|
62
|
+
)
|
|
60
63
|
)
|
|
61
64
|
)
|
|
@@ -33,7 +33,7 @@ export interface ${upperName}Params extends Params<${upperName}Query> {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
// This is a skeleton for a custom service class. Remove or add the methods you need here
|
|
36
|
-
export class ${className}<ServiceParams extends Params = ${upperName}Params>
|
|
36
|
+
export class ${className}<ServiceParams extends ${upperName}Params = ${upperName}Params>
|
|
37
37
|
implements ServiceInterface<${upperName}, ${upperName}Data, ServiceParams, ${upperName}Patch> {
|
|
38
38
|
constructor (public options: ${className}Options) {
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.tpl.js","sourceRoot":"","sources":["../../../src/service/type/custom.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,MAAM,EACN,QAAQ,EACR,QAAQ,EACgB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;oCAGJ,QAAQ;EAE1C,MAAM;IACJ,CAAC,CAAC;IACF,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;CACnB;IACG,CAAC,CAAC;OACC,SAAS;OACT,SAAS;OACT,SAAS;OACT,SAAS;CAEhB;;gBAEgB,SAAS,KAAK,SAAS,SAAS,SAAS,UAAU,SAAS;;mBAEzD,SAAS;;;;mBAIT,SAAS,yBAAyB,SAAS;;;;;eAK/C,SAAS,
|
|
1
|
+
{"version":3,"file":"custom.tpl.js","sourceRoot":"","sources":["../../../src/service/type/custom.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,MAAM,EACN,QAAQ,EACR,QAAQ,EACgB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;oCAGJ,QAAQ;EAE1C,MAAM;IACJ,CAAC,CAAC;IACF,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;CACnB;IACG,CAAC,CAAC;OACC,SAAS;OACT,SAAS;OACT,SAAS;OACT,SAAS;CAEhB;;gBAEgB,SAAS,KAAK,SAAS,SAAS,SAAS,UAAU,SAAS;;mBAEzD,SAAS;;;;mBAIT,SAAS,yBAAyB,SAAS;;;;;eAK/C,SAAS,0BAA0B,SAAS,YAAY,SAAS;kCAC9C,SAAS,KAAK,SAAS,wBAAwB,SAAS;iCACzD,SAAS;;;kDAGQ,SAAS;;;;yDAIF,SAAS;;;;;;;wBAO1C,SAAS,0CAA0C,SAAS;wBAC5D,SAAS,4CAA4C,SAAS;wBAC9D,SAAS,QAAQ,SAAS,4CAA4C,SAAS,IAAI,SAAS;;;;;;;;;;;;wCAY5E,SAAS,2CAA2C,SAAS;;;;;;;uCAO9D,SAAS,4CAA4C,SAAS;;;;;;;;oEAQjC,SAAS;;;;;;;;;;;CAW5E,CAAA;AA9FY,QAAA,QAAQ,YA8FpB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,gBAAQ,EACR,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,QAAQ;CACpB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
|
|
@@ -40,7 +40,7 @@ export interface ${upperName}Params extends Params<${upperName}Query> {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// This is a skeleton for a custom service class. Remove or add the methods you need here
|
|
43
|
-
export class ${className}<ServiceParams extends Params = ${upperName}Params>
|
|
43
|
+
export class ${className}<ServiceParams extends ${upperName}Params = ${upperName}Params>
|
|
44
44
|
implements ServiceInterface<${upperName}, ${upperName}Data, ServiceParams, ${upperName}Patch> {
|
|
45
45
|
constructor (public options: ${className}Options) {
|
|
46
46
|
}
|
|
@@ -3,13 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = exports.template = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const migrationTemplate = ({ kebabPath }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/knexfile.html
|
|
6
|
+
const migrationTemplate = ({ kebabPath, authStrategies, isEntityService }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/knexfile.html
|
|
7
7
|
import type { Knex } from 'knex'
|
|
8
8
|
|
|
9
9
|
export async function up(knex: Knex): Promise<void> {
|
|
10
10
|
await knex.schema.createTable('${kebabPath}', table => {
|
|
11
11
|
table.increments('id')
|
|
12
|
-
|
|
12
|
+
${isEntityService
|
|
13
|
+
? authStrategies
|
|
14
|
+
.map((name) => name === 'local'
|
|
15
|
+
? `
|
|
16
|
+
table.string('email').unique()
|
|
17
|
+
table.string('password')`
|
|
18
|
+
: `
|
|
19
|
+
table.string('${name}Id')`)
|
|
20
|
+
.join('\n')
|
|
21
|
+
: `
|
|
22
|
+
table.string('text')`}
|
|
13
23
|
})
|
|
14
24
|
}
|
|
15
25
|
|
|
@@ -45,7 +55,7 @@ export interface ${upperName}Params extends KnexAdapterParams<${upperName}Query>
|
|
|
45
55
|
|
|
46
56
|
// By default calls the standard Knex adapter service methods but can be customized with your own functionality.
|
|
47
57
|
export class ${className}<ServiceParams extends Params = ${upperName}Params>
|
|
48
|
-
extends KnexService<${upperName}, ${upperName}Data,
|
|
58
|
+
extends KnexService<${upperName}, ${upperName}Data, ${upperName}Params, ${upperName}Patch> {
|
|
49
59
|
}
|
|
50
60
|
|
|
51
61
|
export const getOptions = (app: Application): KnexAdapterOptions => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/service/type/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4D;AAG5D,MAAM,iBAAiB,GAAG,CAAC,EACzB,SAAS,
|
|
1
|
+
{"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/service/type/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4D;AAG5D,MAAM,iBAAiB,GAAG,CAAC,EACzB,SAAS,EACT,cAAc,EACd,eAAe,EACS,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;mCAIL,SAAS;;MAGtC,eAAe;IACb,CAAC,CAAC,cAAc;SACX,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;QACd,CAAC,CAAC;;6BAEW;QACb,CAAC,CAAC;oBACE,IAAI,MAAM,CACjB;SACA,IAAI,CAAC,IAAI,CAAC;IACf,CAAC,CAAC;yBAEN;;;;;iCAK6B,SAAS;;CAEzC,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,QAAQ,EACgB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;oCAKJ,QAAQ;EAE1C,MAAM;IACJ,CAAC,CAAC;IACF,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;CACnB;IACG,CAAC,CAAC;OACC,SAAS;OACT,SAAS;OACT,SAAS;OACT,SAAS;CAEhB;;gBAEgB,SAAS,KAAK,SAAS,SAAS,SAAS,UAAU,SAAS;;mBAEzD,SAAS,oCAAoC,SAAS;;;;eAI1D,SAAS,mCAAmC,SAAS;wBAC5C,SAAS,KAAK,SAAS,SAAS,SAAS,WAAW,SAAS;;;;;;sBAM/D,QAAQ,CAAC,QAAQ;aAC1B,QAAQ;;;CAGpB,CAAA;AA/CY,QAAA,QAAQ,YA+CpB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,gBAAQ,EACR,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,QAAQ;CACpB,CAAC,CACH,CACF;KACA,IAAI,CACH,IAAA,sBAAY,EACV,iBAAiB,EACjB,IAAA,eAAM,EAA0B,YAAY,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,GAAG,IAAA,wBAAc,GAAE,IAAI,SAAS,EAAE,CAAC,CACrG,CACF,CAAA;AAlBQ,QAAA,QAAQ,YAkBhB"}
|
|
@@ -3,14 +3,30 @@ import { renderSource, yyyymmddhhmmss } from '../../commons'
|
|
|
3
3
|
import { ServiceGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
5
|
const migrationTemplate = ({
|
|
6
|
-
kebabPath
|
|
6
|
+
kebabPath,
|
|
7
|
+
authStrategies,
|
|
8
|
+
isEntityService
|
|
7
9
|
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/knexfile.html
|
|
8
10
|
import type { Knex } from 'knex'
|
|
9
11
|
|
|
10
12
|
export async function up(knex: Knex): Promise<void> {
|
|
11
13
|
await knex.schema.createTable('${kebabPath}', table => {
|
|
12
14
|
table.increments('id')
|
|
13
|
-
|
|
15
|
+
${
|
|
16
|
+
isEntityService
|
|
17
|
+
? authStrategies
|
|
18
|
+
.map((name) =>
|
|
19
|
+
name === 'local'
|
|
20
|
+
? `
|
|
21
|
+
table.string('email').unique()
|
|
22
|
+
table.string('password')`
|
|
23
|
+
: `
|
|
24
|
+
table.string('${name}Id')`
|
|
25
|
+
)
|
|
26
|
+
.join('\n')
|
|
27
|
+
: `
|
|
28
|
+
table.string('text')`
|
|
29
|
+
}
|
|
14
30
|
})
|
|
15
31
|
}
|
|
16
32
|
|
|
@@ -56,7 +72,7 @@ export interface ${upperName}Params extends KnexAdapterParams<${upperName}Query>
|
|
|
56
72
|
|
|
57
73
|
// By default calls the standard Knex adapter service methods but can be customized with your own functionality.
|
|
58
74
|
export class ${className}<ServiceParams extends Params = ${upperName}Params>
|
|
59
|
-
extends KnexService<${upperName}, ${upperName}Data,
|
|
75
|
+
extends KnexService<${upperName}, ${upperName}Data, ${upperName}Params, ${upperName}Patch> {
|
|
60
76
|
}
|
|
61
77
|
|
|
62
78
|
export const getOptions = (app: Application): KnexAdapterOptions => {
|
|
@@ -31,7 +31,7 @@ export interface ${upperName}Params extends MongoDBAdapterParams<${upperName}Que
|
|
|
31
31
|
|
|
32
32
|
// By default calls the standard MongoDB adapter service methods but can be customized with your own functionality.
|
|
33
33
|
export class ${className}<ServiceParams extends Params = ${upperName}Params>
|
|
34
|
-
extends MongoDBService<${upperName}, ${upperName}Data,
|
|
34
|
+
extends MongoDBService<${upperName}, ${upperName}Data, ${upperName}Params, ${upperName}Patch> {
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export const getOptions = (app: Application): MongoDBAdapterOptions => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/service/type/mongodb.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,QAAQ,EACgB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;oCAKJ,QAAQ;EAE1C,MAAM;IACJ,CAAC,CAAC;IACF,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;CACnB;IACG,CAAC,CAAC;OACC,SAAS;OACT,SAAS;OACT,SAAS;OACT,SAAS;CAEhB;;gBAEgB,SAAS,KAAK,SAAS,SAAS,SAAS,UAAU,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