@feathersjs/generators 5.0.28 → 5.0.29
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 +6 -0
- package/lib/app/index.js +1 -2
- package/lib/app/index.js.map +1 -1
- package/lib/app/templates/gitignore.tpl.d.ts +5 -0
- package/lib/app/templates/gitignore.tpl.js +125 -0
- package/lib/app/templates/gitignore.tpl.js.map +1 -0
- package/package.json +20 -21
- package/lib/app/index.ts +0 -215
- package/lib/app/templates/app.test.tpl.ts +0 -50
- package/lib/app/templates/app.tpl.ts +0 -141
- package/lib/app/templates/channels.tpl.ts +0 -54
- package/lib/app/templates/client.test.tpl.ts +0 -28
- package/lib/app/templates/client.tpl.ts +0 -53
- package/lib/app/templates/configuration.tpl.ts +0 -89
- package/lib/app/templates/declarations.tpl.ts +0 -42
- package/lib/app/templates/index.html.tpl.ts +0 -44
- package/lib/app/templates/index.tpl.ts +0 -26
- package/lib/app/templates/logger.tpl.ts +0 -56
- package/lib/app/templates/package.json.tpl.ts +0 -78
- package/lib/app/templates/prettierrc.tpl.ts +0 -14
- package/lib/app/templates/readme.md.tpl.ts +0 -57
- package/lib/app/templates/services.tpl.ts +0 -20
- package/lib/app/templates/tsconfig.json.tpl.ts +0 -29
- package/lib/app/templates/validators.tpl.ts +0 -39
- package/lib/authentication/index.ts +0 -119
- package/lib/authentication/templates/authentication.tpl.ts +0 -52
- package/lib/authentication/templates/client.test.tpl.ts +0 -78
- package/lib/authentication/templates/config.tpl.ts +0 -60
- package/lib/authentication/templates/declarations.tpl.ts +0 -38
- package/lib/commons.ts +0 -346
- package/lib/connection/index.ts +0 -138
- package/lib/connection/templates/knex.tpl.ts +0 -73
- package/lib/connection/templates/mongodb.tpl.ts +0 -50
- package/lib/hook/index.ts +0 -52
- package/lib/hook/templates/hook.tpl.ts +0 -33
- package/lib/index.ts +0 -8
- package/lib/service/index.ts +0 -214
- package/lib/service/templates/client.tpl.ts +0 -33
- package/lib/service/templates/schema.json.tpl.ts +0 -143
- package/lib/service/templates/schema.typebox.tpl.ts +0 -131
- package/lib/service/templates/service.tpl.ts +0 -161
- package/lib/service/templates/shared.tpl.ts +0 -64
- package/lib/service/templates/test.tpl.ts +0 -33
- package/lib/service/type/custom.tpl.ts +0 -112
- package/lib/service/type/knex.tpl.ts +0 -105
- package/lib/service/type/mongodb.tpl.ts +0 -64
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { toFile, when } from '@featherscloud/pinion'
|
|
2
|
-
import { fileExists, localTemplate, renderSource } from '../../commons.js'
|
|
3
|
-
import { ServiceGeneratorContext } from '../index.js'
|
|
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
|
-
|
|
15
|
-
const template = ({
|
|
16
|
-
camelName,
|
|
17
|
-
upperName,
|
|
18
|
-
fileName,
|
|
19
|
-
relative,
|
|
20
|
-
authStrategies,
|
|
21
|
-
isEntityService,
|
|
22
|
-
type,
|
|
23
|
-
cwd,
|
|
24
|
-
lib
|
|
25
|
-
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
26
|
-
import { resolve, getValidator, querySyntax } from '@feathersjs/schema'${
|
|
27
|
-
type === 'mongodb'
|
|
28
|
-
? `
|
|
29
|
-
import { ObjectIdSchema } from '@feathersjs/schema'`
|
|
30
|
-
: ''
|
|
31
|
-
}
|
|
32
|
-
import type { FromSchema } from '@feathersjs/schema'
|
|
33
|
-
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
34
|
-
|
|
35
|
-
import type { HookContext } from '${relative}/declarations'
|
|
36
|
-
import { dataValidator, queryValidator } from '${relative}/${
|
|
37
|
-
fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
|
|
38
|
-
}validators'
|
|
39
|
-
import type { ${upperName}Service } from './${fileName}.class'
|
|
40
|
-
|
|
41
|
-
// Main data model schema
|
|
42
|
-
export const ${camelName}Schema = {
|
|
43
|
-
$id: '${upperName}',
|
|
44
|
-
type: 'object',
|
|
45
|
-
additionalProperties: false,
|
|
46
|
-
required: [ '${type === 'mongodb' ? '_id' : 'id'}', ${localTemplate(authStrategies, `'email'`, `'text'`)} ],
|
|
47
|
-
properties: {
|
|
48
|
-
${type === 'mongodb' ? `_id: ObjectIdSchema(),` : `id: { type: 'number' },`}
|
|
49
|
-
${
|
|
50
|
-
isEntityService
|
|
51
|
-
? authFieldsTemplate(authStrategies)
|
|
52
|
-
: `
|
|
53
|
-
text: { type: 'string' }`
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} as const
|
|
57
|
-
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
58
|
-
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
|
|
59
|
-
export const ${camelName}Resolver = resolve<${upperName}, HookContext<${upperName}Service>>({})
|
|
60
|
-
|
|
61
|
-
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
|
|
62
|
-
${localTemplate(
|
|
63
|
-
authStrategies,
|
|
64
|
-
`// The password should never be visible externally
|
|
65
|
-
password: async () => undefined`
|
|
66
|
-
)}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
// Schema for creating new data
|
|
70
|
-
export const ${camelName}DataSchema = {
|
|
71
|
-
$id: '${upperName}Data',
|
|
72
|
-
type: 'object',
|
|
73
|
-
additionalProperties: false,
|
|
74
|
-
required: [ ${localTemplate(authStrategies, `'email'`, `'text'`)} ],
|
|
75
|
-
properties: {
|
|
76
|
-
...${camelName}Schema.properties
|
|
77
|
-
}
|
|
78
|
-
} as const
|
|
79
|
-
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
80
|
-
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
81
|
-
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext<${upperName}Service>>({
|
|
82
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// Schema for updating existing data
|
|
86
|
-
export const ${camelName}PatchSchema = {
|
|
87
|
-
$id: '${upperName}Patch',
|
|
88
|
-
type: 'object',
|
|
89
|
-
additionalProperties: false,
|
|
90
|
-
required: [],
|
|
91
|
-
properties: {
|
|
92
|
-
...${camelName}Schema.properties
|
|
93
|
-
}
|
|
94
|
-
} as const
|
|
95
|
-
export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
|
|
96
|
-
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
97
|
-
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext<${upperName}Service>>({
|
|
98
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
// Schema for allowed query properties
|
|
102
|
-
export const ${camelName}QuerySchema = {
|
|
103
|
-
$id: '${upperName}Query',
|
|
104
|
-
type: 'object',
|
|
105
|
-
additionalProperties: false,
|
|
106
|
-
properties: {
|
|
107
|
-
...querySyntax(${camelName}Schema.properties)
|
|
108
|
-
}
|
|
109
|
-
} as const
|
|
110
|
-
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
111
|
-
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
112
|
-
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext<${upperName}Service>>({
|
|
113
|
-
${
|
|
114
|
-
isEntityService
|
|
115
|
-
? `
|
|
116
|
-
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
117
|
-
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
118
|
-
if (context.params.user) {
|
|
119
|
-
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return value
|
|
123
|
-
}`
|
|
124
|
-
: ''
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
`
|
|
128
|
-
|
|
129
|
-
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
130
|
-
Promise.resolve(ctx).then(
|
|
131
|
-
when<ServiceGeneratorContext>(
|
|
132
|
-
({ schema }) => schema === 'json',
|
|
133
|
-
renderSource(
|
|
134
|
-
template,
|
|
135
|
-
toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
|
|
136
|
-
lib,
|
|
137
|
-
'services',
|
|
138
|
-
...folder,
|
|
139
|
-
`${fileName}.schema`
|
|
140
|
-
])
|
|
141
|
-
)
|
|
142
|
-
)
|
|
143
|
-
)
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { toFile, when } from '@featherscloud/pinion'
|
|
2
|
-
import { fileExists, localTemplate, renderSource } from '../../commons.js'
|
|
3
|
-
import { ServiceGeneratorContext } from '../index.js'
|
|
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
|
-
|
|
15
|
-
const template = ({
|
|
16
|
-
camelName,
|
|
17
|
-
upperName,
|
|
18
|
-
fileName,
|
|
19
|
-
relative,
|
|
20
|
-
authStrategies,
|
|
21
|
-
isEntityService,
|
|
22
|
-
type,
|
|
23
|
-
cwd,
|
|
24
|
-
lib
|
|
25
|
-
}: ServiceGeneratorContext) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
26
|
-
import { resolve } from '@feathersjs/schema'
|
|
27
|
-
import { Type, getValidator, querySyntax } from '@feathersjs/typebox'${
|
|
28
|
-
type === 'mongodb'
|
|
29
|
-
? `
|
|
30
|
-
import { ObjectIdSchema } from '@feathersjs/typebox'`
|
|
31
|
-
: ''
|
|
32
|
-
}
|
|
33
|
-
import type { Static } from '@feathersjs/typebox'
|
|
34
|
-
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
35
|
-
|
|
36
|
-
import type { HookContext } from '${relative}/declarations'
|
|
37
|
-
import { dataValidator, queryValidator } from '${relative}/${
|
|
38
|
-
fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
|
|
39
|
-
}validators'
|
|
40
|
-
import type { ${upperName}Service } from './${fileName}.class'
|
|
41
|
-
|
|
42
|
-
// Main data model schema
|
|
43
|
-
export const ${camelName}Schema = Type.Object({
|
|
44
|
-
${type === 'mongodb' ? '_id: ObjectIdSchema()' : 'id: Type.Number()'},
|
|
45
|
-
${isEntityService ? authFieldsTemplate(authStrategies) : `text: Type.String()`}
|
|
46
|
-
}, { $id: '${upperName}', additionalProperties: false })
|
|
47
|
-
export type ${upperName} = Static<typeof ${camelName}Schema>
|
|
48
|
-
export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
|
|
49
|
-
export const ${camelName}Resolver = resolve<${upperName}, HookContext<${upperName}Service>>({})
|
|
50
|
-
|
|
51
|
-
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
|
|
52
|
-
${localTemplate(
|
|
53
|
-
authStrategies,
|
|
54
|
-
`// The password should never be visible externally
|
|
55
|
-
password: async () => undefined`
|
|
56
|
-
)}
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
// Schema for creating new entries
|
|
60
|
-
export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
|
|
61
|
-
${
|
|
62
|
-
isEntityService
|
|
63
|
-
? authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')
|
|
64
|
-
: `'text'`
|
|
65
|
-
}
|
|
66
|
-
], {
|
|
67
|
-
$id: '${upperName}Data'
|
|
68
|
-
})
|
|
69
|
-
export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
|
|
70
|
-
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
71
|
-
export const ${camelName}DataResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
|
|
72
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
// Schema for updating existing entries
|
|
76
|
-
export const ${camelName}PatchSchema = Type.Partial(${camelName}Schema, {
|
|
77
|
-
$id: '${upperName}Patch'
|
|
78
|
-
})
|
|
79
|
-
export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
|
|
80
|
-
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
81
|
-
export const ${camelName}PatchResolver = resolve<${upperName}, HookContext<${upperName}Service>>({
|
|
82
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
// Schema for allowed query properties
|
|
86
|
-
export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, [
|
|
87
|
-
'${type === 'mongodb' ? '_id' : 'id'}', ${
|
|
88
|
-
isEntityService
|
|
89
|
-
? authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')
|
|
90
|
-
: `'text'`
|
|
91
|
-
}
|
|
92
|
-
])
|
|
93
|
-
export const ${camelName}QuerySchema = Type.Intersect([
|
|
94
|
-
querySyntax(${camelName}QueryProperties),
|
|
95
|
-
// Add additional query properties here
|
|
96
|
-
Type.Object({}, { additionalProperties: false })
|
|
97
|
-
], { additionalProperties: false })
|
|
98
|
-
export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
|
|
99
|
-
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
100
|
-
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext<${upperName}Service>>({
|
|
101
|
-
${
|
|
102
|
-
isEntityService
|
|
103
|
-
? `
|
|
104
|
-
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
105
|
-
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
106
|
-
if (context.params.user) {
|
|
107
|
-
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return value
|
|
111
|
-
}`
|
|
112
|
-
: ''
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
`
|
|
116
|
-
|
|
117
|
-
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
118
|
-
Promise.resolve(ctx).then(
|
|
119
|
-
when<ServiceGeneratorContext>(
|
|
120
|
-
({ schema }) => schema === 'typebox',
|
|
121
|
-
renderSource(
|
|
122
|
-
template,
|
|
123
|
-
toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
|
|
124
|
-
lib,
|
|
125
|
-
'services',
|
|
126
|
-
...folder,
|
|
127
|
-
`${fileName}.schema`
|
|
128
|
-
])
|
|
129
|
-
)
|
|
130
|
-
)
|
|
131
|
-
)
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { toFile, after, prepend } from '@featherscloud/pinion'
|
|
2
|
-
import { fileExists, injectSource, renderSource } from '../../commons.js'
|
|
3
|
-
import { ServiceGeneratorContext } from '../index.js'
|
|
4
|
-
|
|
5
|
-
export const template = ({
|
|
6
|
-
camelName,
|
|
7
|
-
authentication,
|
|
8
|
-
isEntityService,
|
|
9
|
-
path,
|
|
10
|
-
lib,
|
|
11
|
-
language,
|
|
12
|
-
className,
|
|
13
|
-
relative,
|
|
14
|
-
schema,
|
|
15
|
-
fileName
|
|
16
|
-
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.html
|
|
17
|
-
${authentication || isEntityService ? `import { authenticate } from '@feathersjs/authentication'` : ''}
|
|
18
|
-
${
|
|
19
|
-
schema
|
|
20
|
-
? `
|
|
21
|
-
import { hooks as schemaHooks } from '@feathersjs/schema'
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
${camelName}DataValidator,
|
|
25
|
-
${camelName}PatchValidator,
|
|
26
|
-
${camelName}QueryValidator,
|
|
27
|
-
${camelName}Resolver,
|
|
28
|
-
${camelName}ExternalResolver,
|
|
29
|
-
${camelName}DataResolver,
|
|
30
|
-
${camelName}PatchResolver,
|
|
31
|
-
${camelName}QueryResolver
|
|
32
|
-
} from './${fileName}.schema'
|
|
33
|
-
`
|
|
34
|
-
: ''
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
import type { Application } from '${relative}/declarations'
|
|
38
|
-
import { ${className}, getOptions } from './${fileName}.class'
|
|
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: Array<keyof ${className}> = ['find', 'get', 'create', 'patch', 'remove']`
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export * from './${fileName}.class'
|
|
48
|
-
${schema ? `export * from './${fileName}.schema'` : ''}
|
|
49
|
-
|
|
50
|
-
// A configure function that registers the service and its hooks via \`app.configure\`
|
|
51
|
-
export const ${camelName} = (app: Application) => {
|
|
52
|
-
// Register our service on the Feathers application
|
|
53
|
-
app.use(${camelName}Path, new ${className}(getOptions(app)), {
|
|
54
|
-
// A list of all methods this service exposes externally
|
|
55
|
-
methods: ${camelName}Methods,
|
|
56
|
-
// You can add additional custom events to be sent to clients here
|
|
57
|
-
events: []
|
|
58
|
-
})
|
|
59
|
-
// Initialize hooks
|
|
60
|
-
app.service(${camelName}Path).hooks({
|
|
61
|
-
around: {
|
|
62
|
-
all: [${
|
|
63
|
-
authentication
|
|
64
|
-
? `
|
|
65
|
-
authenticate('jwt'),`
|
|
66
|
-
: ''
|
|
67
|
-
} ${
|
|
68
|
-
schema
|
|
69
|
-
? `
|
|
70
|
-
schemaHooks.resolveExternal(${camelName}ExternalResolver),
|
|
71
|
-
schemaHooks.resolveResult(${camelName}Resolver),`
|
|
72
|
-
: ''
|
|
73
|
-
}
|
|
74
|
-
],${
|
|
75
|
-
isEntityService
|
|
76
|
-
? `
|
|
77
|
-
find: [authenticate('jwt')],
|
|
78
|
-
get: [authenticate('jwt')],
|
|
79
|
-
create: [],
|
|
80
|
-
update: [authenticate('jwt')],
|
|
81
|
-
patch: [authenticate('jwt')],
|
|
82
|
-
remove: [authenticate('jwt')]`
|
|
83
|
-
: ''
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
before: {
|
|
87
|
-
all: [${
|
|
88
|
-
schema
|
|
89
|
-
? `
|
|
90
|
-
schemaHooks.validateQuery(${camelName}QueryValidator),
|
|
91
|
-
schemaHooks.resolveQuery(${camelName}QueryResolver)
|
|
92
|
-
`
|
|
93
|
-
: ''
|
|
94
|
-
}],
|
|
95
|
-
find: [],
|
|
96
|
-
get: [],
|
|
97
|
-
create: [${
|
|
98
|
-
schema
|
|
99
|
-
? `
|
|
100
|
-
schemaHooks.validateData(${camelName}DataValidator),
|
|
101
|
-
schemaHooks.resolveData(${camelName}DataResolver)
|
|
102
|
-
`
|
|
103
|
-
: ''
|
|
104
|
-
}],
|
|
105
|
-
patch: [${
|
|
106
|
-
schema
|
|
107
|
-
? `
|
|
108
|
-
schemaHooks.validateData(${camelName}PatchValidator),
|
|
109
|
-
schemaHooks.resolveData(${camelName}PatchResolver)
|
|
110
|
-
`
|
|
111
|
-
: ''
|
|
112
|
-
}],
|
|
113
|
-
remove: []
|
|
114
|
-
},
|
|
115
|
-
after: {
|
|
116
|
-
all: []
|
|
117
|
-
},
|
|
118
|
-
error: {
|
|
119
|
-
all: []
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Add this service to the service type index
|
|
125
|
-
declare module '${relative}/declarations' {
|
|
126
|
-
interface ServiceTypes {
|
|
127
|
-
[${camelName}Path]: ${className}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
`
|
|
131
|
-
|
|
132
|
-
const toServiceIndex = toFile(({ lib }: ServiceGeneratorContext) => [lib, 'services', `index`])
|
|
133
|
-
|
|
134
|
-
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
135
|
-
Promise.resolve(ctx)
|
|
136
|
-
.then(
|
|
137
|
-
renderSource(
|
|
138
|
-
template,
|
|
139
|
-
toFile(({ lib, fileName, folder }: ServiceGeneratorContext) => [
|
|
140
|
-
lib,
|
|
141
|
-
'services',
|
|
142
|
-
...folder,
|
|
143
|
-
`${fileName}`
|
|
144
|
-
])
|
|
145
|
-
)
|
|
146
|
-
)
|
|
147
|
-
.then(
|
|
148
|
-
injectSource<ServiceGeneratorContext>(
|
|
149
|
-
({ camelName, folder, fileName }) =>
|
|
150
|
-
`import { ${camelName} } from './${folder.join('/')}/${fileName}'`,
|
|
151
|
-
prepend(),
|
|
152
|
-
toServiceIndex
|
|
153
|
-
)
|
|
154
|
-
)
|
|
155
|
-
.then(
|
|
156
|
-
injectSource<ServiceGeneratorContext>(
|
|
157
|
-
({ camelName }) => ` app.configure(${camelName})`,
|
|
158
|
-
after('export const services'),
|
|
159
|
-
toServiceIndex
|
|
160
|
-
)
|
|
161
|
-
)
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { toFile, when } from '@featherscloud/pinion'
|
|
2
|
-
import { fileExists, renderSource } from '../../commons.js'
|
|
3
|
-
import { ServiceGeneratorContext } from '../index.js'
|
|
4
|
-
|
|
5
|
-
const sharedTemplate = ({
|
|
6
|
-
camelName,
|
|
7
|
-
upperName,
|
|
8
|
-
className,
|
|
9
|
-
fileName,
|
|
10
|
-
relative,
|
|
11
|
-
path
|
|
12
|
-
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.shared.html
|
|
13
|
-
import type { Params } from '@feathersjs/feathers'
|
|
14
|
-
import type { ClientApplication } from '${relative}/client'
|
|
15
|
-
import type {
|
|
16
|
-
${upperName},
|
|
17
|
-
${upperName}Data,
|
|
18
|
-
${upperName}Patch,
|
|
19
|
-
${upperName}Query,
|
|
20
|
-
${className}
|
|
21
|
-
} from './${fileName}.class'
|
|
22
|
-
|
|
23
|
-
export type { ${upperName}, ${upperName}Data, ${upperName}Patch, ${upperName}Query }
|
|
24
|
-
|
|
25
|
-
export type ${upperName}ClientService = Pick<
|
|
26
|
-
${className}<Params<${upperName}Query>>,
|
|
27
|
-
typeof ${camelName}Methods[number]
|
|
28
|
-
>
|
|
29
|
-
|
|
30
|
-
export const ${camelName}Path = '${path}'
|
|
31
|
-
|
|
32
|
-
export const ${camelName}Methods: Array<keyof ${className}> = ['find', 'get', 'create', 'patch', 'remove']
|
|
33
|
-
|
|
34
|
-
export const ${camelName}Client = (client: ClientApplication) => {
|
|
35
|
-
const connection = client.get('connection')
|
|
36
|
-
|
|
37
|
-
client.use(${camelName}Path, connection.service(${camelName}Path), {
|
|
38
|
-
methods: ${camelName}Methods
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Add this service to the client service type index
|
|
43
|
-
declare module '${relative}/client' {
|
|
44
|
-
interface ServiceTypes {
|
|
45
|
-
[${camelName}Path]: ${upperName}ClientService
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
`
|
|
49
|
-
|
|
50
|
-
export const generate = async (ctx: ServiceGeneratorContext) =>
|
|
51
|
-
Promise.resolve(ctx).then(
|
|
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
|
-
)
|
|
63
|
-
)
|
|
64
|
-
)
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { toFile } from '@featherscloud/pinion'
|
|
2
|
-
import { renderSource } from '../../commons.js'
|
|
3
|
-
import { ServiceGeneratorContext } from '../index.js'
|
|
4
|
-
|
|
5
|
-
const template = ({
|
|
6
|
-
relative,
|
|
7
|
-
lib,
|
|
8
|
-
path
|
|
9
|
-
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.test.html
|
|
10
|
-
import assert from 'assert'
|
|
11
|
-
import { app } from '../${relative}/${lib}/app'
|
|
12
|
-
|
|
13
|
-
describe('${path} service', () => {
|
|
14
|
-
it('registered the service', () => {
|
|
15
|
-
const service = app.service('${path}')
|
|
16
|
-
|
|
17
|
-
assert.ok(service, 'Registered the service')
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
`
|
|
21
|
-
|
|
22
|
-
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
23
|
-
Promise.resolve(ctx).then(
|
|
24
|
-
renderSource(
|
|
25
|
-
template,
|
|
26
|
-
toFile<ServiceGeneratorContext>(({ test, folder, fileName }) => [
|
|
27
|
-
test,
|
|
28
|
-
'services',
|
|
29
|
-
...folder,
|
|
30
|
-
`${fileName}.test`
|
|
31
|
-
])
|
|
32
|
-
)
|
|
33
|
-
)
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { toFile } from '@featherscloud/pinion'
|
|
2
|
-
import { renderSource } from '../../commons.js'
|
|
3
|
-
import { ServiceGeneratorContext } from '../index.js'
|
|
4
|
-
|
|
5
|
-
export const template = ({
|
|
6
|
-
className,
|
|
7
|
-
upperName,
|
|
8
|
-
schema,
|
|
9
|
-
fileName,
|
|
10
|
-
relative
|
|
11
|
-
}: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.class.html#custom-services
|
|
12
|
-
import type { Id, NullableId, Params, ServiceInterface } from '@feathersjs/feathers'
|
|
13
|
-
|
|
14
|
-
import type { Application } from '${relative}/declarations'
|
|
15
|
-
${
|
|
16
|
-
schema
|
|
17
|
-
? `import type {
|
|
18
|
-
${upperName},
|
|
19
|
-
${upperName}Data,
|
|
20
|
-
${upperName}Patch,
|
|
21
|
-
${upperName}Query
|
|
22
|
-
} from './${fileName}.schema'
|
|
23
|
-
`
|
|
24
|
-
: `
|
|
25
|
-
type ${upperName} = any
|
|
26
|
-
type ${upperName}Data = any
|
|
27
|
-
type ${upperName}Patch = any
|
|
28
|
-
type ${upperName}Query = any
|
|
29
|
-
`
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export type { ${upperName}, ${upperName}Data, ${upperName}Patch, ${upperName}Query }
|
|
33
|
-
|
|
34
|
-
export interface ${className}Options {
|
|
35
|
-
app: Application
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ${upperName}Params extends Params<${upperName}Query> {
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// This is a skeleton for a custom service class. Remove or add the methods you need here
|
|
43
|
-
export class ${className}<ServiceParams extends ${upperName}Params = ${upperName}Params>
|
|
44
|
-
implements ServiceInterface<${upperName}, ${upperName}Data, ServiceParams, ${upperName}Patch> {
|
|
45
|
-
constructor (public options: ${className}Options) {
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async find (_params?: ServiceParams): Promise<${upperName}[]> {
|
|
49
|
-
return []
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async get (id: Id, _params?: ServiceParams): Promise<${upperName}> {
|
|
53
|
-
return {
|
|
54
|
-
id: 0,
|
|
55
|
-
text: \`A new message with ID: \${id}!\`
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async create (data: ${upperName}Data, params?: ServiceParams): Promise<${upperName}>
|
|
60
|
-
async create (data: ${upperName}Data[], params?: ServiceParams): Promise<${upperName}[]>
|
|
61
|
-
async create (data: ${upperName}Data|${upperName}Data[], params?: ServiceParams): Promise<${upperName}|${upperName}[]> {
|
|
62
|
-
if (Array.isArray(data)) {
|
|
63
|
-
return Promise.all(data.map(current => this.create(current, params)));
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
id: 0,
|
|
68
|
-
...data
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// This method has to be added to the 'methods' option to make it available to clients
|
|
73
|
-
async update (id: NullableId, data: ${upperName}Data, _params?: ServiceParams): Promise<${upperName}> {
|
|
74
|
-
return {
|
|
75
|
-
id: 0,
|
|
76
|
-
...data
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async patch (id: NullableId, data: ${upperName}Patch, _params?: ServiceParams): Promise<${upperName}> {
|
|
81
|
-
return {
|
|
82
|
-
id: 0,
|
|
83
|
-
text: \`Fallback for \${id}\`,
|
|
84
|
-
...data
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async remove (id: NullableId, _params?: ServiceParams): Promise<${upperName}> {
|
|
89
|
-
return {
|
|
90
|
-
id: 0,
|
|
91
|
-
text: 'removed'
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export const getOptions = (app: Application) => {
|
|
97
|
-
return { app }
|
|
98
|
-
}
|
|
99
|
-
`
|
|
100
|
-
|
|
101
|
-
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
102
|
-
Promise.resolve(ctx).then(
|
|
103
|
-
renderSource(
|
|
104
|
-
template,
|
|
105
|
-
toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
|
|
106
|
-
lib,
|
|
107
|
-
'services',
|
|
108
|
-
...folder,
|
|
109
|
-
`${fileName}.class`
|
|
110
|
-
])
|
|
111
|
-
)
|
|
112
|
-
)
|