@feathersjs/generators 5.0.28 → 5.0.30

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/lib/app/index.js +1 -2
  5. package/lib/app/index.js.map +1 -1
  6. package/lib/app/templates/gitignore.tpl.d.ts +5 -0
  7. package/lib/app/templates/gitignore.tpl.js +125 -0
  8. package/lib/app/templates/gitignore.tpl.js.map +1 -0
  9. package/package.json +28 -29
  10. package/lib/app/index.ts +0 -215
  11. package/lib/app/templates/app.test.tpl.ts +0 -50
  12. package/lib/app/templates/app.tpl.ts +0 -141
  13. package/lib/app/templates/channels.tpl.ts +0 -54
  14. package/lib/app/templates/client.test.tpl.ts +0 -28
  15. package/lib/app/templates/client.tpl.ts +0 -53
  16. package/lib/app/templates/configuration.tpl.ts +0 -89
  17. package/lib/app/templates/declarations.tpl.ts +0 -42
  18. package/lib/app/templates/index.html.tpl.ts +0 -44
  19. package/lib/app/templates/index.tpl.ts +0 -26
  20. package/lib/app/templates/logger.tpl.ts +0 -56
  21. package/lib/app/templates/package.json.tpl.ts +0 -78
  22. package/lib/app/templates/prettierrc.tpl.ts +0 -14
  23. package/lib/app/templates/readme.md.tpl.ts +0 -57
  24. package/lib/app/templates/services.tpl.ts +0 -20
  25. package/lib/app/templates/tsconfig.json.tpl.ts +0 -29
  26. package/lib/app/templates/validators.tpl.ts +0 -39
  27. package/lib/authentication/index.ts +0 -119
  28. package/lib/authentication/templates/authentication.tpl.ts +0 -52
  29. package/lib/authentication/templates/client.test.tpl.ts +0 -78
  30. package/lib/authentication/templates/config.tpl.ts +0 -60
  31. package/lib/authentication/templates/declarations.tpl.ts +0 -38
  32. package/lib/commons.ts +0 -346
  33. package/lib/connection/index.ts +0 -138
  34. package/lib/connection/templates/knex.tpl.ts +0 -73
  35. package/lib/connection/templates/mongodb.tpl.ts +0 -50
  36. package/lib/hook/index.ts +0 -52
  37. package/lib/hook/templates/hook.tpl.ts +0 -33
  38. package/lib/index.ts +0 -8
  39. package/lib/service/index.ts +0 -214
  40. package/lib/service/templates/client.tpl.ts +0 -33
  41. package/lib/service/templates/schema.json.tpl.ts +0 -143
  42. package/lib/service/templates/schema.typebox.tpl.ts +0 -131
  43. package/lib/service/templates/service.tpl.ts +0 -161
  44. package/lib/service/templates/shared.tpl.ts +0 -64
  45. package/lib/service/templates/test.tpl.ts +0 -33
  46. package/lib/service/type/custom.tpl.ts +0 -112
  47. package/lib/service/type/knex.tpl.ts +0 -105
  48. package/lib/service/type/mongodb.tpl.ts +0 -64
package/lib/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export * from '@featherscloud/pinion'
2
-
3
- export * from './commons.js'
4
- export * as app from './app/index.js'
5
- export * as authentication from './authentication/index.js'
6
- export * as connection from './connection/index.js'
7
- export * as hook from './hook/index.js'
8
- export * as service from './service/index.js'
@@ -1,214 +0,0 @@
1
- import { dirname } from 'path'
2
- import _ from 'lodash'
3
- import { runGenerator, runGenerators, prompt } from '@featherscloud/pinion'
4
- import { fileURLToPath } from 'url'
5
- import chalk from 'chalk'
6
-
7
- import {
8
- checkPreconditions,
9
- DATABASE_TYPES,
10
- FeathersBaseContext,
11
- fileExists,
12
- getDatabaseAdapter,
13
- initializeBaseContext
14
- } from '../commons.js'
15
-
16
- // Set __dirname in es module
17
- const __dirname = dirname(fileURLToPath(import.meta.url))
18
-
19
- export interface ServiceGeneratorContext extends FeathersBaseContext {
20
- /**
21
- * The chosen service name
22
- */
23
- name: string
24
- /**
25
- * The path the service is registered on
26
- */
27
- path: string
28
- /**
29
- * The list of subfolders this service is in
30
- */
31
- folder: string[]
32
- /**
33
- * The `camelCase` service name starting with a lowercase letter
34
- */
35
- camelName: string
36
- /**
37
- * The `CamelCase` service name starting with an uppercase letter
38
- */
39
- upperName: string
40
- /**
41
- * The service class name combined as `CamelCaseService`
42
- */
43
- className: string
44
- /**
45
- * A kebab-cased (filename friendly) version of the service name
46
- */
47
- kebabName: string
48
- /**
49
- * The actual filename (the last element of the path)
50
- */
51
- fileName: string
52
- /**
53
- * The kebab-cased name of the path. Will be used for e.g. database names
54
- */
55
- kebabPath: string
56
- /**
57
- * Indicates how many file paths we should go up to import other things (e.g. `../../`)
58
- */
59
- relative: string
60
- /**
61
- * The chosen service type
62
- */
63
- type: 'knex' | 'mongodb' | 'custom'
64
- /**
65
- * Which schema definition format to use
66
- */
67
- schema: 'typebox' | 'json' | false
68
- /**
69
- * Wether this service uses authentication
70
- */
71
- authentication: boolean
72
- /**
73
- * Set to true if this service is for an authentication entity
74
- */
75
- isEntityService?: boolean
76
- /**
77
- * The authentication strategies (if it is an entity service)
78
- */
79
- authStrategies: string[]
80
- }
81
-
82
- /**
83
- * Parameters the generator is called with
84
- */
85
- export type ServiceGeneratorArguments = FeathersBaseContext &
86
- Partial<
87
- Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>
88
- >
89
-
90
- export const generate = (ctx: ServiceGeneratorArguments) =>
91
- Promise.resolve(ctx)
92
- .then(initializeBaseContext())
93
- .then(checkPreconditions())
94
- .then(
95
- prompt(({ name, path, type, schema, authentication, isEntityService, feathers, lib, language }) => {
96
- const sqlDisabled = DATABASE_TYPES.every(
97
- (name) => name === 'mongodb' || name === 'other' || !fileExists(lib, `${name}.${language}`)
98
- )
99
- const mongodbDisabled = !fileExists(lib, `mongodb.${language}`)
100
-
101
- return [
102
- {
103
- name: 'name',
104
- type: 'input',
105
- when: !name,
106
- message: 'What is the name of your service?',
107
- validate: (input: any) => {
108
- if (!input || input === 'authentication') {
109
- return 'Invalid service name'
110
- }
111
-
112
- return true
113
- }
114
- },
115
- {
116
- name: 'path',
117
- type: 'input',
118
- when: !path,
119
- message: 'Which path should the service be registered on?',
120
- default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`,
121
- validate: (input: any) => {
122
- if (!input || input === 'authentication') {
123
- return 'Invalid service path'
124
- }
125
-
126
- return true
127
- }
128
- },
129
- {
130
- name: 'authentication',
131
- type: 'confirm',
132
- when: authentication === undefined && !isEntityService,
133
- message: 'Does this service require authentication?'
134
- },
135
- {
136
- name: 'type',
137
- type: 'list',
138
- when: !type,
139
- message: 'What database is the service using?',
140
- default: getDatabaseAdapter(feathers?.database),
141
- choices: [
142
- {
143
- value: 'knex',
144
- name: `SQL${sqlDisabled ? chalk.gray(' (connection not available)') : ''}`,
145
- disabled: sqlDisabled
146
- },
147
- {
148
- value: 'mongodb',
149
- name: `MongoDB${mongodbDisabled ? chalk.gray(' (connection not available)') : ''}`,
150
- disabled: mongodbDisabled
151
- },
152
- {
153
- value: 'custom',
154
- name: 'A custom service'
155
- }
156
- ]
157
- },
158
- {
159
- name: 'schema',
160
- type: 'list',
161
- when: schema === undefined,
162
- message: 'Which schema definition format do you want to use?',
163
- suffix: chalk.grey(' Schemas allow to type, validate, secure and populate data'),
164
- default: feathers?.schema,
165
- choices: (answers: ServiceGeneratorContext) => [
166
- {
167
- value: 'typebox',
168
- name: `TypeBox ${chalk.gray(' (recommended)')}`
169
- },
170
- {
171
- value: 'json',
172
- name: 'JSON schema'
173
- },
174
- {
175
- value: false,
176
- name: `No schema${
177
- answers.type !== 'custom' ? chalk.gray(' (not recommended with a database)') : ''
178
- }`
179
- }
180
- ]
181
- }
182
- ]
183
- })
184
- )
185
- .then(async (ctx): Promise<ServiceGeneratorContext> => {
186
- const { name, path, type, authStrategies = [] } = ctx as any as ServiceGeneratorContext
187
- const kebabName = _.kebabCase(name)
188
- const camelName = _.camelCase(name)
189
- const upperName = _.upperFirst(camelName)
190
- const className = `${upperName}Service`
191
-
192
- const folder = path.split('/').filter((el) => el !== '')
193
- const relative = ['', ...folder].map(() => '..').join('/')
194
- const fileName = _.last(folder)
195
- const kebabPath = _.kebabCase(path)
196
-
197
- return {
198
- name,
199
- type,
200
- path,
201
- folder,
202
- fileName,
203
- upperName,
204
- className,
205
- kebabName,
206
- camelName,
207
- kebabPath,
208
- relative,
209
- authStrategies,
210
- ...ctx
211
- } as ServiceGeneratorContext
212
- })
213
- .then(runGenerators<ServiceGeneratorContext>(__dirname, 'templates'))
214
- .then(runGenerator<ServiceGeneratorContext>(__dirname, 'type', ({ type }) => `${type}.tpl.js`))
@@ -1,33 +0,0 @@
1
- import { toFile, after, before, when } from '@featherscloud/pinion'
2
- import { fileExists, injectSource } from '../../commons.js'
3
- import { ServiceGeneratorContext } from '../index.js'
4
-
5
- const importTemplate = ({ upperName, folder, fileName, camelName }: ServiceGeneratorContext) => /* ts */ `
6
- import { ${camelName}Client } from './services/${folder.join('/')}/${fileName}.shared'
7
- export type {
8
- ${upperName},
9
- ${upperName}Data,
10
- ${upperName}Query,
11
- ${upperName}Patch
12
- } from './services/${folder.join('/')}/${fileName}.shared'
13
- `
14
-
15
- const registrationTemplate = ({ camelName }: ServiceGeneratorContext) =>
16
- ` client.configure(${camelName}Client)`
17
-
18
- const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
19
-
20
- export const generate = async (ctx: ServiceGeneratorContext) =>
21
- Promise.resolve(ctx).then(
22
- when<ServiceGeneratorContext>(
23
- ({ lib, language }) => fileExists(lib, `client.${language}`),
24
- injectSource(registrationTemplate, before('return client'), toClientFile),
25
- injectSource(
26
- importTemplate,
27
- after<ServiceGeneratorContext>(({ language }) =>
28
- language === 'ts' ? 'import type { AuthenticationClientOptions }' : 'import authenticationClient'
29
- ),
30
- toClientFile
31
- )
32
- )
33
- )
@@ -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
- )