@feathersjs/cli 5.0.0-pre.30 → 5.0.0-pre.31
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 +7 -0
- package/lib/app/index.js +1 -1
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +10 -1
- package/lib/app/templates/client.test.tpl.d.ts +2 -0
- package/lib/app/templates/client.test.tpl.js +27 -0
- package/lib/app/templates/client.test.tpl.js.map +1 -0
- package/lib/app/templates/client.test.tpl.ts +26 -0
- package/lib/app/templates/client.tpl.js +1 -1
- package/lib/app/templates/client.tpl.ts +1 -1
- package/lib/app/templates/logger.tpl.js +8 -2
- package/lib/app/templates/logger.tpl.js.map +1 -1
- package/lib/app/templates/logger.tpl.ts +8 -2
- package/lib/app/templates/schemas.tpl.js +4 -5
- package/lib/app/templates/schemas.tpl.js.map +1 -1
- package/lib/app/templates/schemas.tpl.ts +4 -5
- package/lib/authentication/index.d.ts +1 -0
- package/lib/authentication/templates/{test.tpl.d.ts → client.test.tpl.d.ts} +0 -0
- package/lib/authentication/templates/client.test.tpl.js +66 -0
- package/lib/authentication/templates/client.test.tpl.js.map +1 -0
- package/lib/authentication/templates/client.test.tpl.ts +80 -0
- package/lib/authentication/templates/client.tpl.d.ts +2 -0
- package/lib/authentication/templates/client.tpl.js +14 -0
- package/lib/authentication/templates/client.tpl.js.map +1 -0
- package/lib/authentication/templates/client.tpl.ts +19 -0
- package/lib/authentication/templates/declarations.tpl.js +1 -1
- package/lib/authentication/templates/declarations.tpl.ts +1 -1
- package/lib/authentication/templates/knex.tpl.js +3 -3
- package/lib/authentication/templates/knex.tpl.ts +3 -3
- package/lib/authentication/templates/schema.json.tpl.js +24 -24
- package/lib/authentication/templates/schema.json.tpl.js.map +1 -1
- package/lib/authentication/templates/schema.json.tpl.ts +24 -24
- package/lib/authentication/templates/schema.typebox.tpl.js +24 -26
- package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/authentication/templates/schema.typebox.tpl.ts +26 -26
- package/lib/service/index.d.ts +5 -63
- package/lib/service/index.js +74 -75
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +10 -4
- package/lib/service/templates/client.tpl.js +14 -19
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +32 -21
- package/lib/service/templates/schema.json.tpl.js +24 -22
- package/lib/service/templates/schema.json.tpl.js.map +1 -1
- package/lib/service/templates/schema.json.tpl.ts +24 -22
- package/lib/service/templates/schema.typebox.tpl.js +22 -25
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/service/templates/schema.typebox.tpl.ts +22 -25
- package/lib/service/type/knex.tpl.d.ts +1 -1
- package/lib/service/type/knex.tpl.js +10 -8
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +10 -9
- package/lib/service/type/mongodb.tpl.d.ts +1 -1
- package/lib/service/type/mongodb.tpl.js +7 -5
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +8 -6
- package/package.json +18 -16
- package/lib/authentication/templates/test.tpl.js +0 -43
- package/lib/authentication/templates/test.tpl.js.map +0 -1
- package/lib/authentication/templates/test.tpl.ts +0 -53
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;EAE7C,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;;oCAEvE,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;UACd,SAAS;;;
|
|
1
|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,SAAS;;;;qBAIE,SAAS;;;cAGhB,SAAS,6BAA6B,SAAS;eAC9C,SAAS,iCAAiC,SAAS;eACnD,SAAS,2BAA2B,SAAS;;;MAGtD,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;qCAEF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;;;;;;CAOrE,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,EACjC,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CACF,CAAA;AAfU,QAAA,QAAQ,YAelB"}
|
|
@@ -8,20 +8,23 @@ const template = ({
|
|
|
8
8
|
authStrategies,
|
|
9
9
|
type,
|
|
10
10
|
relative
|
|
11
|
-
}: AuthenticationGeneratorContext) => /* ts */ `import { resolve,
|
|
11
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import { resolve, querySyntax, getValidator, getDataValidator } from '@feathersjs/schema'
|
|
12
12
|
import type { FromSchema } from '@feathersjs/schema'
|
|
13
13
|
${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
|
|
14
14
|
|
|
15
15
|
import type { HookContext } from '${relative}/declarations'
|
|
16
16
|
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
export const ${camelName}
|
|
20
|
-
$id: '${upperName}
|
|
18
|
+
// Main data model schema
|
|
19
|
+
export const ${camelName}Schema = {
|
|
20
|
+
$id: '${upperName}',
|
|
21
21
|
type: 'object',
|
|
22
22
|
additionalProperties: false,
|
|
23
|
-
required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
|
|
23
|
+
required: [ '${type === 'mongodb' ? '_id' : 'id'}'${authStrategies.includes('local') ? ", 'email'" : ''} ],
|
|
24
24
|
properties: {
|
|
25
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
26
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
27
|
+
},
|
|
25
28
|
${authStrategies
|
|
26
29
|
.map((name) =>
|
|
27
30
|
name === 'local'
|
|
@@ -32,30 +35,27 @@ export const ${camelName}DataSchema = {
|
|
|
32
35
|
.join(',\n')}
|
|
33
36
|
}
|
|
34
37
|
} as const
|
|
35
|
-
export type ${upperName}
|
|
36
|
-
export const ${camelName}
|
|
37
|
-
|
|
38
|
-
properties: {
|
|
39
|
-
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
40
|
-
}
|
|
38
|
+
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
39
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
40
|
+
properties: {}
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
// Schema for the data
|
|
44
|
-
export const ${camelName}
|
|
45
|
-
$id: '${upperName}',
|
|
43
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
44
|
+
export const ${camelName}DataSchema = {
|
|
45
|
+
$id: '${upperName}Data',
|
|
46
46
|
type: 'object',
|
|
47
47
|
additionalProperties: false,
|
|
48
|
-
required: [
|
|
48
|
+
required: [ ],
|
|
49
49
|
properties: {
|
|
50
|
-
...${camelName}
|
|
51
|
-
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
52
|
-
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
53
|
-
}
|
|
50
|
+
...${camelName}Schema.properties
|
|
54
51
|
}
|
|
55
52
|
} as const
|
|
56
|
-
export type ${upperName} = FromSchema<typeof ${camelName}
|
|
57
|
-
export const ${camelName}
|
|
58
|
-
|
|
53
|
+
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
54
|
+
export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
|
|
55
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
56
|
+
properties: {
|
|
57
|
+
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
58
|
+
}
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
@@ -71,11 +71,11 @@ export const ${camelName}QuerySchema = {
|
|
|
71
71
|
type: 'object',
|
|
72
72
|
additionalProperties: false,
|
|
73
73
|
properties: {
|
|
74
|
-
...
|
|
74
|
+
...querySyntax(${camelName}Schema.properties)
|
|
75
75
|
}
|
|
76
76
|
} as const
|
|
77
77
|
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
78
|
-
export const ${camelName}QueryValidator =
|
|
78
|
+
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
79
79
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
80
80
|
properties: {
|
|
81
81
|
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
@@ -3,38 +3,24 @@ 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, upperName, authStrategies, type, relative }) => /* ts */ `import {
|
|
7
|
-
import { Type, querySyntax } from '@feathersjs/typebox'
|
|
6
|
+
const template = ({ camelName, upperName, authStrategies, type, relative }) => /* ts */ `import { resolve } from '@feathersjs/schema'
|
|
7
|
+
import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox'
|
|
8
8
|
import type { Static } from '@feathersjs/typebox'
|
|
9
9
|
${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
|
|
10
10
|
|
|
11
11
|
import type { HookContext } from '${relative}/declarations'
|
|
12
12
|
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
export const ${camelName}
|
|
14
|
+
// Main data model schema
|
|
15
|
+
export const ${camelName}Schema = Type.Object({
|
|
16
|
+
${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
|
|
16
17
|
${authStrategies
|
|
17
18
|
.map((name) => name === 'local'
|
|
18
19
|
? ` email: Type.String(),
|
|
19
|
-
password: Type.String()`
|
|
20
|
+
password: Type.Optional(Type.String())`
|
|
20
21
|
: ` ${name}Id: Type.Optional(Type.String())`)
|
|
21
22
|
.join(',\n')}
|
|
22
|
-
},
|
|
23
|
-
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
24
|
-
export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
|
|
25
|
-
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
26
|
-
properties: {
|
|
27
|
-
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
// Schema for the data that is being returned
|
|
32
|
-
export const ${camelName}Schema = Type.Intersect([
|
|
33
|
-
${camelName}DataSchema,
|
|
34
|
-
Type.Object({
|
|
35
|
-
${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'}
|
|
36
|
-
})
|
|
37
|
-
], { $id: '${upperName}' })
|
|
23
|
+
},{ $id: '${upperName}', additionalProperties: false })
|
|
38
24
|
export type ${upperName} = Static<typeof ${camelName}Schema>
|
|
39
25
|
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
40
26
|
properties: {}
|
|
@@ -47,14 +33,26 @@ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
|
47
33
|
}
|
|
48
34
|
})
|
|
49
35
|
|
|
36
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
37
|
+
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
38
|
+
${authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')}
|
|
39
|
+
],
|
|
40
|
+
{ $id: '${upperName}Data', additionalProperties: false }
|
|
41
|
+
)
|
|
42
|
+
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
43
|
+
export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
|
|
44
|
+
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
45
|
+
properties: {
|
|
46
|
+
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
|
|
50
50
|
// Schema for allowed query properties
|
|
51
|
-
export const ${camelName}
|
|
52
|
-
querySyntax(${camelName}Schema),
|
|
53
|
-
// Add additional query properties here
|
|
54
|
-
Type.Object({})
|
|
51
|
+
export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, ['${type === 'mongodb' ? '_id' : 'id'}', ${authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')}
|
|
55
52
|
])
|
|
53
|
+
export const ${camelName}QuerySchema = querySyntax(${camelName}QueryProperties)
|
|
56
54
|
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
|
|
57
|
-
export const ${camelName}QueryValidator =
|
|
55
|
+
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
58
56
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
59
57
|
properties: {
|
|
60
58
|
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;EAG7C,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;;oCAEvE,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;IACpB,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;EAG7C,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;;oCAEvE,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;IACpB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,mBAAmB;IAC/D,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;yCAC+B;IACjC,CAAC,CAAC,OAAO,IAAI,kCAAkC,CAClD;KACA,IAAI,CAAC,KAAK,CAAC;YACJ,SAAS;cACP,SAAS,oBAAoB,SAAS;eACrC,SAAS,sBAA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AAK,SAAS,EACpC,IAAA,sBAAY,EACV,gBAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CACF,CAAA;AAfU,QAAA,QAAQ,YAelB"}
|
|
@@ -8,40 +8,26 @@ export const template = ({
|
|
|
8
8
|
authStrategies,
|
|
9
9
|
type,
|
|
10
10
|
relative
|
|
11
|
-
}: AuthenticationGeneratorContext) => /* ts */ `import {
|
|
12
|
-
import { Type, querySyntax } from '@feathersjs/typebox'
|
|
11
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import { resolve } from '@feathersjs/schema'
|
|
12
|
+
import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox'
|
|
13
13
|
import type { Static } from '@feathersjs/typebox'
|
|
14
14
|
${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
|
|
15
15
|
|
|
16
16
|
import type { HookContext } from '${relative}/declarations'
|
|
17
17
|
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
export const ${camelName}
|
|
19
|
+
// Main data model schema
|
|
20
|
+
export const ${camelName}Schema = Type.Object({
|
|
21
|
+
${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
|
|
21
22
|
${authStrategies
|
|
22
23
|
.map((name) =>
|
|
23
24
|
name === 'local'
|
|
24
25
|
? ` email: Type.String(),
|
|
25
|
-
password: Type.String()`
|
|
26
|
+
password: Type.Optional(Type.String())`
|
|
26
27
|
: ` ${name}Id: Type.Optional(Type.String())`
|
|
27
28
|
)
|
|
28
29
|
.join(',\n')}
|
|
29
|
-
},
|
|
30
|
-
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
31
|
-
export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
|
|
32
|
-
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
33
|
-
properties: {
|
|
34
|
-
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
// Schema for the data that is being returned
|
|
39
|
-
export const ${camelName}Schema = Type.Intersect([
|
|
40
|
-
${camelName}DataSchema,
|
|
41
|
-
Type.Object({
|
|
42
|
-
${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'}
|
|
43
|
-
})
|
|
44
|
-
], { $id: '${upperName}' })
|
|
30
|
+
},{ $id: '${upperName}', additionalProperties: false })
|
|
45
31
|
export type ${upperName} = Static<typeof ${camelName}Schema>
|
|
46
32
|
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
47
33
|
properties: {}
|
|
@@ -54,14 +40,28 @@ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
|
54
40
|
}
|
|
55
41
|
})
|
|
56
42
|
|
|
43
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
44
|
+
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
45
|
+
${authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')}
|
|
46
|
+
],
|
|
47
|
+
{ $id: '${upperName}Data', additionalProperties: false }
|
|
48
|
+
)
|
|
49
|
+
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
50
|
+
export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
|
|
51
|
+
export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
|
|
52
|
+
properties: {
|
|
53
|
+
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
57
|
// Schema for allowed query properties
|
|
58
|
-
export const ${camelName}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Type.Object({})
|
|
58
|
+
export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, ['${
|
|
59
|
+
type === 'mongodb' ? '_id' : 'id'
|
|
60
|
+
}', ${authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')}
|
|
62
61
|
])
|
|
62
|
+
export const ${camelName}QuerySchema = querySyntax(${camelName}QueryProperties)
|
|
63
63
|
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
|
|
64
|
-
export const ${camelName}QueryValidator =
|
|
64
|
+
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
65
65
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
66
66
|
properties: {
|
|
67
67
|
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
package/lib/service/index.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
32
32
|
* The actual filename (the last element of the path)
|
|
33
33
|
*/
|
|
34
34
|
fileName: string;
|
|
35
|
+
/**
|
|
36
|
+
* The kebab-cased name of the path. Will be used for e.g. database names
|
|
37
|
+
*/
|
|
38
|
+
kebabPath: string;
|
|
35
39
|
/**
|
|
36
40
|
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
37
41
|
*/
|
|
@@ -57,66 +61,4 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
57
61
|
* Parameters the generator is called with
|
|
58
62
|
*/
|
|
59
63
|
export declare type ServiceGeneratorArguments = FeathersBaseContext & Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>>;
|
|
60
|
-
export declare const generate: (ctx: ServiceGeneratorArguments) => Promise<
|
|
61
|
-
/**
|
|
62
|
-
* The chosen service name
|
|
63
|
-
*/
|
|
64
|
-
name: string;
|
|
65
|
-
/**
|
|
66
|
-
* The path the service is registered on
|
|
67
|
-
*/
|
|
68
|
-
path: string;
|
|
69
|
-
/**
|
|
70
|
-
* The list of subfolders this service is in
|
|
71
|
-
*/
|
|
72
|
-
folder: string[];
|
|
73
|
-
/**
|
|
74
|
-
* The `camelCase` service name starting with a lowercase letter
|
|
75
|
-
*/
|
|
76
|
-
camelName: string;
|
|
77
|
-
/**
|
|
78
|
-
* The `CamelCase` service name starting with an uppercase letter
|
|
79
|
-
*/
|
|
80
|
-
upperName: string;
|
|
81
|
-
/**
|
|
82
|
-
* The service class name combined as `CamelCaseService`
|
|
83
|
-
*/
|
|
84
|
-
className: string;
|
|
85
|
-
/**
|
|
86
|
-
* A kebab-cased (filename friendly) version of the service name
|
|
87
|
-
*/
|
|
88
|
-
kebabName: string;
|
|
89
|
-
/**
|
|
90
|
-
* The actual filename (the last element of the path)
|
|
91
|
-
*/
|
|
92
|
-
fileName: string;
|
|
93
|
-
/**
|
|
94
|
-
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
95
|
-
*/
|
|
96
|
-
relative: string;
|
|
97
|
-
/**
|
|
98
|
-
* The chosen service type
|
|
99
|
-
*/
|
|
100
|
-
type: 'knex' | 'mongodb' | 'custom';
|
|
101
|
-
/**
|
|
102
|
-
* Which schema definition format to use
|
|
103
|
-
*/
|
|
104
|
-
schema: 'typebox' | 'json' | false;
|
|
105
|
-
/**
|
|
106
|
-
* Wether this service uses authentication
|
|
107
|
-
*/
|
|
108
|
-
authentication: boolean;
|
|
109
|
-
/**
|
|
110
|
-
* Set to true if this service is for an authentication entity
|
|
111
|
-
*/
|
|
112
|
-
isEntityService?: boolean;
|
|
113
|
-
feathers: import("../commons").FeathersAppInfo;
|
|
114
|
-
pkg: import("../commons").AppPackageJson;
|
|
115
|
-
lib: string;
|
|
116
|
-
test: string;
|
|
117
|
-
language: "ts" | "js";
|
|
118
|
-
dependencyVersions?: import("../commons").DependencyVersions;
|
|
119
|
-
cwd: string;
|
|
120
|
-
_?: (string | number)[];
|
|
121
|
-
pinion: import("@feathershq/pinion").Configuration;
|
|
122
|
-
}>;
|
|
64
|
+
export declare const generate: (ctx: ServiceGeneratorArguments) => Promise<ServiceGeneratorContext>;
|
package/lib/service/index.js
CHANGED
|
@@ -10,84 +10,81 @@ const commons_1 = require("../commons");
|
|
|
10
10
|
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
11
11
|
.then((0, commons_1.initializeBaseContext)())
|
|
12
12
|
.then((0, commons_1.checkPreconditions)())
|
|
13
|
-
.then((0, pinion_1.prompt)(({ name, path, type, schema, authentication, isEntityService }) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (!input || input === 'authentication') {
|
|
23
|
-
return 'Invalid service name';
|
|
24
|
-
}
|
|
25
|
-
return true;
|
|
13
|
+
.then((0, pinion_1.prompt)(({ name, path, type, schema, authentication, isEntityService, feathers }) => [
|
|
14
|
+
{
|
|
15
|
+
name: 'name',
|
|
16
|
+
type: 'input',
|
|
17
|
+
when: !name,
|
|
18
|
+
message: 'What is the name of your service?',
|
|
19
|
+
validate: (input) => {
|
|
20
|
+
if (!input || input === 'authentication') {
|
|
21
|
+
return 'Invalid service name';
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'path',
|
|
28
|
+
type: 'input',
|
|
29
|
+
when: !path,
|
|
30
|
+
message: 'Which path should the service be registered on?',
|
|
31
|
+
default: (answers) => `${lodash_1.default.kebabCase(answers.name)}`,
|
|
32
|
+
validate: (input) => {
|
|
33
|
+
if (!input || input === 'authentication') {
|
|
34
|
+
return 'Invalid service path';
|
|
39
35
|
}
|
|
40
|
-
|
|
41
|
-
{
|
|
42
|
-
name: 'authentication',
|
|
43
|
-
type: 'confirm',
|
|
44
|
-
when: authentication === undefined && !isEntityService,
|
|
45
|
-
message: 'Does this service require authentication?'
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
name: 'type',
|
|
49
|
-
type: 'list',
|
|
50
|
-
when: !type,
|
|
51
|
-
message: 'What kind of service is it?',
|
|
52
|
-
default: (0, commons_1.getDatabaseAdapter)((_a = ctx.feathers) === null || _a === void 0 ? void 0 : _a.database),
|
|
53
|
-
choices: [
|
|
54
|
-
{
|
|
55
|
-
value: 'knex',
|
|
56
|
-
name: 'SQL'
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
value: 'mongodb',
|
|
60
|
-
name: 'MongoDB'
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
value: 'custom',
|
|
64
|
-
name: 'A custom service'
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
name: 'schema',
|
|
70
|
-
type: 'list',
|
|
71
|
-
when: schema === undefined,
|
|
72
|
-
message: 'Which schema definition format do you want to use?',
|
|
73
|
-
default: ((_b = ctx.feathers) === null || _b === void 0 ? void 0 : _b.schema) || 'json',
|
|
74
|
-
choices: [
|
|
75
|
-
{
|
|
76
|
-
value: 'typebox',
|
|
77
|
-
name: 'TypeBox'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
value: 'json',
|
|
81
|
-
name: 'JSON schema'
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
value: false,
|
|
85
|
-
name: 'No schema'
|
|
86
|
-
}
|
|
87
|
-
]
|
|
36
|
+
return true;
|
|
88
37
|
}
|
|
89
|
-
|
|
90
|
-
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'authentication',
|
|
41
|
+
type: 'confirm',
|
|
42
|
+
when: authentication === undefined && !isEntityService,
|
|
43
|
+
message: 'Does this service require authentication?'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: 'type',
|
|
47
|
+
type: 'list',
|
|
48
|
+
when: !type,
|
|
49
|
+
message: 'What kind of service is it?',
|
|
50
|
+
default: (0, commons_1.getDatabaseAdapter)(feathers === null || feathers === void 0 ? void 0 : feathers.database),
|
|
51
|
+
choices: [
|
|
52
|
+
{
|
|
53
|
+
value: 'knex',
|
|
54
|
+
name: 'SQL'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
value: 'mongodb',
|
|
58
|
+
name: 'MongoDB'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
value: 'custom',
|
|
62
|
+
name: 'A custom service'
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'schema',
|
|
68
|
+
type: 'list',
|
|
69
|
+
when: schema === undefined,
|
|
70
|
+
message: 'Which schema definition format do you want to use?',
|
|
71
|
+
default: feathers === null || feathers === void 0 ? void 0 : feathers.schema,
|
|
72
|
+
choices: [
|
|
73
|
+
{
|
|
74
|
+
value: 'typebox',
|
|
75
|
+
name: 'TypeBox'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: 'json',
|
|
79
|
+
name: 'JSON schema'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: false,
|
|
83
|
+
name: 'No schema'
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
]))
|
|
91
88
|
.then(async (ctx) => {
|
|
92
89
|
const { name, path, type } = ctx;
|
|
93
90
|
const kebabName = lodash_1.default.kebabCase(name);
|
|
@@ -97,6 +94,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
97
94
|
const folder = path.split('/').filter((el) => el !== '');
|
|
98
95
|
const relative = ['', ...folder].map(() => '..').join('/');
|
|
99
96
|
const fileName = lodash_1.default.last(folder);
|
|
97
|
+
const kebabPath = lodash_1.default.kebabCase(path);
|
|
100
98
|
return {
|
|
101
99
|
name,
|
|
102
100
|
type,
|
|
@@ -107,6 +105,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
107
105
|
className,
|
|
108
106
|
kebabName,
|
|
109
107
|
camelName,
|
|
108
|
+
kebabPath,
|
|
110
109
|
relative,
|
|
111
110
|
...ctx
|
|
112
111
|
};
|
package/lib/service/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAsB;AACtB,+CAAmF;AAEnF,wCAKmB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAsB;AACtB,+CAAmF;AAEnF,wCAKmB;AAqEZ,MAAM,QAAQ,GAAG,CAAC,GAA8B,EAAE,EAAE,CACzD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CAAC,IAAA,+BAAqB,GAAE,CAAC;KAC7B,IAAI,CAAC,IAAA,4BAAkB,GAAE,CAAC;KAC1B,IAAI,CACH,IAAA,eAAM,EACJ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC3E;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,CAAC,IAAI;QACX,OAAO,EAAE,mCAAmC;QAC5C,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,gBAAgB,EAAE;gBACxC,OAAO,sBAAsB,CAAA;aAC9B;YAED,OAAO,IAAI,CAAA;QACb,CAAC;KACF;IACD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,CAAC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,QAAA,QAAQ,YAiH2E"}
|
package/lib/service/index.ts
CHANGED
|
@@ -41,6 +41,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
41
41
|
* The actual filename (the last element of the path)
|
|
42
42
|
*/
|
|
43
43
|
fileName: string
|
|
44
|
+
/**
|
|
45
|
+
* The kebab-cased name of the path. Will be used for e.g. database names
|
|
46
|
+
*/
|
|
47
|
+
kebabPath: string
|
|
44
48
|
/**
|
|
45
49
|
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
46
50
|
*/
|
|
@@ -77,7 +81,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
77
81
|
.then(checkPreconditions())
|
|
78
82
|
.then(
|
|
79
83
|
prompt<ServiceGeneratorArguments, ServiceGeneratorContext>(
|
|
80
|
-
({ name, path, type, schema, authentication, isEntityService }) => [
|
|
84
|
+
({ name, path, type, schema, authentication, isEntityService, feathers }) => [
|
|
81
85
|
{
|
|
82
86
|
name: 'name',
|
|
83
87
|
type: 'input',
|
|
@@ -116,7 +120,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
116
120
|
type: 'list',
|
|
117
121
|
when: !type,
|
|
118
122
|
message: 'What kind of service is it?',
|
|
119
|
-
default: getDatabaseAdapter(
|
|
123
|
+
default: getDatabaseAdapter(feathers?.database),
|
|
120
124
|
choices: [
|
|
121
125
|
{
|
|
122
126
|
value: 'knex',
|
|
@@ -137,7 +141,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
137
141
|
type: 'list',
|
|
138
142
|
when: schema === undefined,
|
|
139
143
|
message: 'Which schema definition format do you want to use?',
|
|
140
|
-
default:
|
|
144
|
+
default: feathers?.schema,
|
|
141
145
|
choices: [
|
|
142
146
|
{
|
|
143
147
|
value: 'typebox',
|
|
@@ -156,7 +160,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
156
160
|
]
|
|
157
161
|
)
|
|
158
162
|
)
|
|
159
|
-
.then(async (ctx) => {
|
|
163
|
+
.then(async (ctx): Promise<ServiceGeneratorContext> => {
|
|
160
164
|
const { name, path, type } = ctx
|
|
161
165
|
const kebabName = _.kebabCase(name)
|
|
162
166
|
const camelName = _.camelCase(name)
|
|
@@ -166,6 +170,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
166
170
|
const folder = path.split('/').filter((el) => el !== '')
|
|
167
171
|
const relative = ['', ...folder].map(() => '..').join('/')
|
|
168
172
|
const fileName = _.last(folder)
|
|
173
|
+
const kebabPath = _.kebabCase(path)
|
|
169
174
|
|
|
170
175
|
return {
|
|
171
176
|
name,
|
|
@@ -177,6 +182,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
177
182
|
className,
|
|
178
183
|
kebabName,
|
|
179
184
|
camelName,
|
|
185
|
+
kebabPath,
|
|
180
186
|
relative,
|
|
181
187
|
...ctx
|
|
182
188
|
}
|