@feathersjs/generators 5.0.0-pre.35 → 5.0.0-pre.37

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 (58) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/lib/app/templates/client.tpl.js +9 -4
  5. package/lib/app/templates/client.tpl.js.map +1 -1
  6. package/lib/app/templates/client.tpl.ts +9 -4
  7. package/lib/app/templates/configuration.tpl.js +1 -0
  8. package/lib/app/templates/configuration.tpl.js.map +1 -1
  9. package/lib/app/templates/configuration.tpl.ts +1 -0
  10. package/lib/app/templates/package.json.tpl.js +1 -1
  11. package/lib/app/templates/package.json.tpl.js.map +1 -1
  12. package/lib/app/templates/package.json.tpl.ts +1 -1
  13. package/lib/app/templates/validators.tpl.js +1 -2
  14. package/lib/app/templates/validators.tpl.js.map +1 -1
  15. package/lib/app/templates/validators.tpl.ts +1 -2
  16. package/lib/authentication/templates/knex.tpl.js +1 -9
  17. package/lib/authentication/templates/knex.tpl.js.map +1 -1
  18. package/lib/authentication/templates/knex.tpl.ts +5 -11
  19. package/lib/authentication/templates/schema.json.tpl.js +10 -4
  20. package/lib/authentication/templates/schema.json.tpl.js.map +1 -1
  21. package/lib/authentication/templates/schema.json.tpl.ts +12 -4
  22. package/lib/authentication/templates/schema.typebox.tpl.js +5 -4
  23. package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -1
  24. package/lib/authentication/templates/schema.typebox.tpl.ts +5 -4
  25. package/lib/commons.d.ts +5 -0
  26. package/lib/commons.js +15 -1
  27. package/lib/commons.js.map +1 -1
  28. package/lib/commons.ts +17 -0
  29. package/lib/connection/templates/mongodb.tpl.js +7 -1
  30. package/lib/connection/templates/mongodb.tpl.js.map +1 -1
  31. package/lib/connection/templates/mongodb.tpl.ts +9 -1
  32. package/lib/service/templates/client.tpl.js +7 -16
  33. package/lib/service/templates/client.tpl.js.map +1 -1
  34. package/lib/service/templates/client.tpl.ts +14 -39
  35. package/lib/service/templates/schema.json.tpl.js +10 -3
  36. package/lib/service/templates/schema.json.tpl.js.map +1 -1
  37. package/lib/service/templates/schema.json.tpl.ts +12 -3
  38. package/lib/service/templates/schema.typebox.tpl.js +5 -4
  39. package/lib/service/templates/schema.typebox.tpl.js.map +1 -1
  40. package/lib/service/templates/schema.typebox.tpl.ts +5 -4
  41. package/lib/service/templates/service.tpl.d.ts +1 -1
  42. package/lib/service/templates/service.tpl.js +6 -5
  43. package/lib/service/templates/service.tpl.js.map +1 -1
  44. package/lib/service/templates/service.tpl.ts +5 -5
  45. package/lib/service/templates/shared.tpl.d.ts +2 -0
  46. package/lib/service/templates/shared.tpl.js +50 -0
  47. package/lib/service/templates/shared.tpl.js.map +1 -0
  48. package/lib/service/templates/shared.tpl.ts +61 -0
  49. package/lib/service/type/custom.tpl.js +16 -13
  50. package/lib/service/type/custom.tpl.js.map +1 -1
  51. package/lib/service/type/custom.tpl.ts +16 -13
  52. package/lib/service/type/knex.tpl.js +7 -9
  53. package/lib/service/type/knex.tpl.js.map +1 -1
  54. package/lib/service/type/knex.tpl.ts +8 -11
  55. package/lib/service/type/mongodb.tpl.js +6 -4
  56. package/lib/service/type/mongodb.tpl.js.map +1 -1
  57. package/lib/service/type/mongodb.tpl.ts +6 -4
  58. package/package.json +29 -24
@@ -3,28 +3,19 @@ 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 importTemplate = ({ upperName, folder, fileName, className, camelName, type }) => /* ts */ `import type {
7
- ${upperName},
8
- ${upperName}Data,
9
- ${upperName}Query,
10
- ${className}
11
- } from './services/${folder.join('/')}/${fileName}'
6
+ const importTemplate = ({ upperName, folder, fileName, camelName }) => /* ts */ `
7
+ import { ${camelName}Client } from './services/${folder.join('/')}/${fileName}.shared'
12
8
  export type {
13
9
  ${upperName},
14
10
  ${upperName}Data,
15
- ${upperName}Query
16
- }
17
- export const ${camelName}ServiceMethods = ['find', 'get', 'create', 'patch', 'remove'] as const
18
- export type ${upperName}ClientService = Pick<${className}${type !== 'custom' ? `<Params<${upperName}Query>>` : ''}, typeof ${camelName}ServiceMethods[number]>
11
+ ${upperName}Query,
12
+ ${upperName}Patch
13
+ } from './services/${folder.join('/')}/${fileName}.shared'
19
14
  `;
20
- const declarationTemplate = ({ path, upperName }) => ` '${path}': ${upperName}ClientService`;
21
- const registrationTemplate = ({ camelName, path }) => ` client.use('${path}', connection.service('${path}'), {
22
- methods: ${camelName}ServiceMethods
23
- })`;
15
+ const registrationTemplate = ({ camelName }) => ` client.configure(${camelName}Client)`;
24
16
  const toClientFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'client']);
25
17
  const generate = async (ctx) => (0, pinion_1.generator)(ctx)
26
18
  .then((0, commons_1.injectSource)(registrationTemplate, (0, pinion_1.before)('return client'), toClientFile))
27
- .then((0, pinion_1.when)((ctx) => ctx.language === 'js', (0, commons_1.injectSource)(importTemplate, (0, pinion_1.after)('import authenticationClient'), toClientFile)))
28
- .then((0, pinion_1.when)((ctx) => ctx.language === 'ts', (0, commons_1.injectSource)(importTemplate, (0, pinion_1.after)('import type { AuthenticationClientOptions }'), toClientFile), (0, commons_1.injectSource)(declarationTemplate, (0, pinion_1.after)('export interface ServiceTypes'), toClientFile)));
19
+ .then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.after)(({ language }) => language === 'ts' ? 'import type { AuthenticationClientOptions }' : 'import authenticationClient'), toClientFile));
29
20
  exports.generate = generate;
30
21
  //# sourceMappingURL=client.tpl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/client.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA2E;AAC3E,2CAA4C;AAG5C,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,EACT,IAAI,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b,CACF,CAAA;AAXQ,QAAA,QAAQ,YAWhB"}
@@ -1,40 +1,19 @@
1
- import { generator, toFile, when, after, before } from '@feathershq/pinion'
1
+ import { generator, toFile, after, before } from '@feathershq/pinion'
2
2
  import { injectSource } from '../../commons'
3
3
  import { ServiceGeneratorContext } from '../index'
4
4
 
5
- const importTemplate = ({
6
- upperName,
7
- folder,
8
- fileName,
9
- className,
10
- camelName,
11
- type
12
- }: ServiceGeneratorContext) => /* ts */ `import type {
13
- ${upperName},
14
- ${upperName}Data,
15
- ${upperName}Query,
16
- ${className}
17
- } from './services/${folder.join('/')}/${fileName}'
5
+ const importTemplate = ({ upperName, folder, fileName, camelName }: ServiceGeneratorContext) => /* ts */ `
6
+ import { ${camelName}Client } from './services/${folder.join('/')}/${fileName}.shared'
18
7
  export type {
19
8
  ${upperName},
20
9
  ${upperName}Data,
21
- ${upperName}Query
22
- }
23
- export const ${camelName}ServiceMethods = ['find', 'get', 'create', 'patch', 'remove'] as const
24
- export type ${upperName}ClientService = Pick<${className}${
25
- type !== 'custom' ? `<Params<${upperName}Query>>` : ''
26
- }, typeof ${camelName}ServiceMethods[number]>
10
+ ${upperName}Query,
11
+ ${upperName}Patch
12
+ } from './services/${folder.join('/')}/${fileName}.shared'
27
13
  `
28
14
 
29
- const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
30
- ` '${path}': ${upperName}ClientService`
31
-
32
- const registrationTemplate = ({
33
- camelName,
34
- path
35
- }: ServiceGeneratorContext) => ` client.use('${path}', connection.service('${path}'), {
36
- methods: ${camelName}ServiceMethods
37
- })`
15
+ const registrationTemplate = ({ camelName }: ServiceGeneratorContext) =>
16
+ ` client.configure(${camelName}Client)`
38
17
 
39
18
  const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
40
19
 
@@ -42,15 +21,11 @@ export const generate = async (ctx: ServiceGeneratorContext) =>
42
21
  generator(ctx)
43
22
  .then(injectSource(registrationTemplate, before('return client'), toClientFile))
44
23
  .then(
45
- when(
46
- (ctx) => ctx.language === 'js',
47
- injectSource(importTemplate, after('import authenticationClient'), toClientFile)
48
- )
49
- )
50
- .then(
51
- when(
52
- (ctx) => ctx.language === 'ts',
53
- injectSource(importTemplate, after('import type { AuthenticationClientOptions }'), toClientFile),
54
- injectSource(declarationTemplate, after('export interface ServiceTypes'), toClientFile)
24
+ injectSource(
25
+ importTemplate,
26
+ after<ServiceGeneratorContext>(({ language }) =>
27
+ language === 'ts' ? 'import type { AuthenticationClientOptions }' : 'import authenticationClient'
28
+ ),
29
+ toClientFile
55
30
  )
56
31
  )
@@ -18,16 +18,23 @@ export const ${camelName}Schema = {
18
18
  additionalProperties: false,
19
19
  required: [ '${type === 'mongodb' ? '_id' : 'id'}', 'text' ],
20
20
  properties: {
21
- ${type === 'mongodb' ? '_id' : 'id'}: {
22
- type: '${type === 'mongodb' ? 'string' : 'number'}'
23
- },
21
+ ${type === 'mongodb'
22
+ ? `_id: {
23
+ type: 'string',
24
+ objectid: true
25
+ },`
26
+ : `id: {
27
+ type: 'number'
28
+ },`}
24
29
  text: {
25
30
  type: 'string'
26
31
  }
27
32
  }
28
33
  } as const
29
34
  export type ${upperName} = FromSchema<typeof ${camelName}Schema>
35
+ export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
30
36
  export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
37
+
31
38
  export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
32
39
 
33
40
  // Schema for creating new data
@@ -1 +1 @@
1
- {"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAAwD;AAGxD,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,GAAG,EACH,GAAG,EACqB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;oCAIJ,QAAQ;iDACK,QAAQ,IACvD,IAA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AC,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,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"}
@@ -25,16 +25,25 @@ export const ${camelName}Schema = {
25
25
  additionalProperties: false,
26
26
  required: [ '${type === 'mongodb' ? '_id' : 'id'}', 'text' ],
27
27
  properties: {
28
- ${type === 'mongodb' ? '_id' : 'id'}: {
29
- type: '${type === 'mongodb' ? 'string' : 'number'}'
30
- },
28
+ ${
29
+ type === 'mongodb'
30
+ ? `_id: {
31
+ type: 'string',
32
+ objectid: true
33
+ },`
34
+ : `id: {
35
+ type: 'number'
36
+ },`
37
+ }
31
38
  text: {
32
39
  type: 'string'
33
40
  }
34
41
  }
35
42
  } as const
36
43
  export type ${upperName} = FromSchema<typeof ${camelName}Schema>
44
+ export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
37
45
  export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
46
+
38
47
  export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
39
48
 
40
49
  // Schema for creating new data
@@ -5,7 +5,7 @@ const pinion_1 = require("@feathershq/pinion");
5
5
  const commons_1 = require("../../commons");
6
6
  const template = ({ camelName, upperName, relative, type, cwd, lib }) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
7
7
  import { resolve } from '@feathersjs/schema'
8
- import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox'
8
+ import { Type, getValidator, querySyntax } from '@feathersjs/typebox'
9
9
  import type { Static } from '@feathersjs/typebox'
10
10
 
11
11
  import type { HookContext } from '${relative}/declarations'
@@ -14,10 +14,11 @@ import { dataValidator, queryValidator } from '${relative}/${(0, commons_1.fileE
14
14
 
15
15
  // Main data model schema
16
16
  export const ${camelName}Schema = Type.Object({
17
- ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
17
+ ${type === 'mongodb' ? '_id: Type.String({ objectid: true })' : 'id: Type.Number()'},
18
18
  text: Type.String()
19
19
  }, { $id: '${upperName}', additionalProperties: false })
20
20
  export type ${upperName} = Static<typeof ${camelName}Schema>
21
+ export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
21
22
  export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
22
23
 
23
24
  export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
@@ -27,7 +28,7 @@ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, ['text'], {
27
28
  $id: '${upperName}Data'
28
29
  })
29
30
  export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
30
- export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
31
+ export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
31
32
  export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({})
32
33
 
33
34
  // Schema for updating existing entries
@@ -35,7 +36,7 @@ export const ${camelName}PatchSchema = Type.Partial(${camelName}DataSchema, {
35
36
  $id: '${upperName}Patch'
36
37
  })
37
38
  export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
38
- export const ${camelName}PatchValidator = getDataValidator(${camelName}PatchSchema, dataValidator)
39
+ export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
39
40
  export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({})
40
41
 
41
42
  // Schema for allowed query properties
@@ -1 +1 @@
1
- {"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAAwD;AAGxD,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AAS,2BAA2B,SAAS;CAC3D,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,SAAS,EACpC,IAAA,sBAAY,EACV,QAAQ,EACR,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"}
@@ -11,7 +11,7 @@ const template = ({
11
11
  lib
12
12
  }: ServiceGeneratorContext) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
13
13
  import { resolve } from '@feathersjs/schema'
14
- import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox'
14
+ import { Type, getValidator, querySyntax } from '@feathersjs/typebox'
15
15
  import type { Static } from '@feathersjs/typebox'
16
16
 
17
17
  import type { HookContext } from '${relative}/declarations'
@@ -21,10 +21,11 @@ import { dataValidator, queryValidator } from '${relative}/${
21
21
 
22
22
  // Main data model schema
23
23
  export const ${camelName}Schema = Type.Object({
24
- ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
24
+ ${type === 'mongodb' ? '_id: Type.String({ objectid: true })' : 'id: Type.Number()'},
25
25
  text: Type.String()
26
26
  }, { $id: '${upperName}', additionalProperties: false })
27
27
  export type ${upperName} = Static<typeof ${camelName}Schema>
28
+ export const ${camelName}Validator = getValidator(${camelName}Schema, dataValidator)
28
29
  export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
29
30
 
30
31
  export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
@@ -34,7 +35,7 @@ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, ['text'], {
34
35
  $id: '${upperName}Data'
35
36
  })
36
37
  export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
37
- export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
38
+ export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
38
39
  export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({})
39
40
 
40
41
  // Schema for updating existing entries
@@ -42,7 +43,7 @@ export const ${camelName}PatchSchema = Type.Partial(${camelName}DataSchema, {
42
43
  $id: '${upperName}Patch'
43
44
  })
44
45
  export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
45
- export const ${camelName}PatchValidator = getDataValidator(${camelName}PatchSchema, dataValidator)
46
+ export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
46
47
  export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({})
47
48
 
48
49
  // Schema for allowed query properties
@@ -1,3 +1,3 @@
1
1
  import { ServiceGeneratorContext } from '../index';
2
- export declare const template: ({ camelName, authentication, isEntityService, path, className, relative, schema, fileName }: ServiceGeneratorContext) => string;
2
+ export declare const template: ({ camelName, authentication, isEntityService, 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, path, 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, 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,6 +24,7 @@ import {
24
24
 
25
25
  import type { Application } from '${relative}/declarations'
26
26
  import { ${className}, getOptions } from './${fileName}.class'
27
+ import { ${camelName}Path, ${camelName}Methods } from './${fileName}.shared'
27
28
 
28
29
  export * from './${fileName}.class'
29
30
  ${schema ? `export * from './${fileName}.schema'` : ''}
@@ -31,14 +32,14 @@ ${schema ? `export * from './${fileName}.schema'` : ''}
31
32
  // A configure function that registers the service and its hooks via \`app.configure\`
32
33
  export const ${camelName} = (app: Application) => {
33
34
  // Register our service on the Feathers application
34
- app.use('${path}', new ${className}(getOptions(app)), {
35
+ app.use(${camelName}Path, new ${className}(getOptions(app)), {
35
36
  // A list of all methods this service exposes externally
36
- methods: ['find', 'get', 'create', 'patch', 'remove'],
37
+ methods: ${camelName}Methods,
37
38
  // You can add additional custom events to be sent to clients here
38
39
  events: []
39
40
  })
40
41
  // Initialize hooks
41
- app.service('${path}').hooks({
42
+ app.service(${camelName}Path).hooks({
42
43
  around: {
43
44
  all: [${authentication
44
45
  ? `
@@ -93,7 +94,7 @@ export const ${camelName} = (app: Application) => {
93
94
  // Add this service to the service type index
94
95
  declare module '${relative}/declarations' {
95
96
  interface ServiceTypes {
96
- '${path}': ${className}
97
+ [${camelName}Path]: ${className}
97
98
  }
98
99
  }
99
100
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"service.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/service.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AACtE,2CAA0D;AAGnD,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,cAAc,EACd,eAAe,EACf,IAAI,EACJ,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;IAC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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"}
@@ -6,7 +6,6 @@ export const template = ({
6
6
  camelName,
7
7
  authentication,
8
8
  isEntityService,
9
- path,
10
9
  className,
11
10
  relative,
12
11
  schema,
@@ -34,6 +33,7 @@ import {
34
33
 
35
34
  import type { Application } from '${relative}/declarations'
36
35
  import { ${className}, getOptions } from './${fileName}.class'
36
+ import { ${camelName}Path, ${camelName}Methods } from './${fileName}.shared'
37
37
 
38
38
  export * from './${fileName}.class'
39
39
  ${schema ? `export * from './${fileName}.schema'` : ''}
@@ -41,14 +41,14 @@ ${schema ? `export * from './${fileName}.schema'` : ''}
41
41
  // A configure function that registers the service and its hooks via \`app.configure\`
42
42
  export const ${camelName} = (app: Application) => {
43
43
  // Register our service on the Feathers application
44
- app.use('${path}', new ${className}(getOptions(app)), {
44
+ app.use(${camelName}Path, new ${className}(getOptions(app)), {
45
45
  // A list of all methods this service exposes externally
46
- methods: ['find', 'get', 'create', 'patch', 'remove'],
46
+ methods: ${camelName}Methods,
47
47
  // You can add additional custom events to be sent to clients here
48
48
  events: []
49
49
  })
50
50
  // Initialize hooks
51
- app.service('${path}').hooks({
51
+ app.service(${camelName}Path).hooks({
52
52
  around: {
53
53
  all: [${
54
54
  authentication
@@ -115,7 +115,7 @@ export const ${camelName} = (app: Application) => {
115
115
  // Add this service to the service type index
116
116
  declare module '${relative}/declarations' {
117
117
  interface ServiceTypes {
118
- '${path}': ${className}
118
+ [${camelName}Path]: ${className}
119
119
  }
120
120
  }
121
121
  `
@@ -0,0 +1,2 @@
1
+ import { ServiceGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = void 0;
4
+ const pinion_1 = require("@feathershq/pinion");
5
+ const commons_1 = require("../../commons");
6
+ const sharedTemplate = ({ camelName, upperName, className, fileName, relative, path }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.shared.html
7
+ import type { Params } from '@feathersjs/feathers'
8
+ import type { ClientApplication } from '${relative}/client'
9
+ import type {
10
+ ${upperName},
11
+ ${upperName}Data,
12
+ ${upperName}Patch,
13
+ ${upperName}Query,
14
+ ${className}
15
+ } from './${fileName}.class'
16
+
17
+ export type { ${upperName}, ${upperName}Data, ${upperName}Patch, ${upperName}Query }
18
+
19
+ export type ${upperName}ClientService = Pick<
20
+ ${className}<Params<${upperName}Query>>,
21
+ typeof ${camelName}Methods[number]
22
+ >
23
+
24
+ export const ${camelName}Path = '${path}'
25
+
26
+ export const ${camelName}Methods = ['find', 'get', 'create', 'patch', 'remove'] as const
27
+
28
+ export const ${camelName}Client = (client: ClientApplication) => {
29
+ const connection = client.get('connection')
30
+
31
+ client.use(${camelName}Path, connection.service(${camelName}Path), {
32
+ methods: ${camelName}Methods
33
+ })
34
+ }
35
+
36
+ // Add this service to the client service type index
37
+ declare module '${relative}/client' {
38
+ interface ServiceTypes {
39
+ [${camelName}Path]: ${upperName}ClientService
40
+ }
41
+ }
42
+ `;
43
+ const generate = async (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(sharedTemplate, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
44
+ lib,
45
+ 'services',
46
+ ...folder,
47
+ `${fileName}.shared`
48
+ ])));
49
+ exports.generate = generate;
50
+ //# sourceMappingURL=shared.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/shared.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,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,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,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
@@ -0,0 +1,61 @@
1
+ import { generator, toFile } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
+ import { ServiceGeneratorContext } from '../index'
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 = ['find', 'get', 'create', 'patch', 'remove'] as const
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
+ generator(ctx).then(
52
+ renderSource(
53
+ sharedTemplate,
54
+ toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
55
+ lib,
56
+ 'services',
57
+ ...folder,
58
+ `${fileName}.shared`
59
+ ])
60
+ )
61
+ )
@@ -16,12 +16,14 @@ ${schema
16
16
  } from './${fileName}.schema'
17
17
  `
18
18
  : `
19
- export type ${upperName} = any
20
- export type ${upperName}Data = any
21
- export type ${upperName}Patch = any
22
- export type ${upperName}Query = any
19
+ type ${upperName} = any
20
+ type ${upperName}Data = any
21
+ type ${upperName}Patch = any
22
+ type ${upperName}Query = any
23
23
  `}
24
24
 
25
+ export type { ${upperName}, ${upperName}Data, ${upperName}Patch, ${upperName}Query }
26
+
25
27
  export interface ${className}Options {
26
28
  app: Application
27
29
  }
@@ -31,24 +33,25 @@ export interface ${upperName}Params extends Params<${upperName}Query> {
31
33
  }
32
34
 
33
35
  // This is a skeleton for a custom service class. Remove or add the methods you need here
34
- export class ${className} implements ServiceInterface<${upperName}, ${upperName}Data, ${upperName}Params, ${upperName}Patch> {
36
+ export class ${className}<ServiceParams extends Params = ${upperName}Params>
37
+ implements ServiceInterface<${upperName}, ${upperName}Data, ServiceParams, ${upperName}Patch> {
35
38
  constructor (public options: ${className}Options) {
36
39
  }
37
40
 
38
- async find (_params?: ${upperName}Params): Promise<${upperName}[]> {
41
+ async find (_params?: ServiceParams): Promise<${upperName}[]> {
39
42
  return []
40
43
  }
41
44
 
42
- async get (id: Id, _params?: ${upperName}Params): Promise<${upperName}> {
45
+ async get (id: Id, _params?: ServiceParams): Promise<${upperName}> {
43
46
  return {
44
47
  id: 0,
45
48
  text: \`A new message with ID: \${id}!\`
46
49
  }
47
50
  }
48
51
 
49
- async create (data: ${upperName}Data, params?: ${upperName}Params): Promise<${upperName}>
50
- async create (data: ${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}[]>
51
- async create (data: ${upperName}Data|${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}|${upperName}[]> {
52
+ async create (data: ${upperName}Data, params?: ServiceParams): Promise<${upperName}>
53
+ async create (data: ${upperName}Data[], params?: ServiceParams): Promise<${upperName}[]>
54
+ async create (data: ${upperName}Data|${upperName}Data[], params?: ServiceParams): Promise<${upperName}|${upperName}[]> {
52
55
  if (Array.isArray(data)) {
53
56
  return Promise.all(data.map(current => this.create(current, params)));
54
57
  }
@@ -60,14 +63,14 @@ export class ${className} implements ServiceInterface<${upperName}, ${upperName}
60
63
  }
61
64
 
62
65
  // This method has to be added to the 'methods' option to make it available to clients
63
- async update (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}> {
66
+ async update (id: NullableId, data: ${upperName}Data, _params?: ServiceParams): Promise<${upperName}> {
64
67
  return {
65
68
  id: 0,
66
69
  ...data
67
70
  }
68
71
  }
69
72
 
70
- async patch (id: NullableId, data: ${upperName}Patch, _params?: ${upperName}Params): Promise<${upperName}> {
73
+ async patch (id: NullableId, data: ${upperName}Patch, _params?: ServiceParams): Promise<${upperName}> {
71
74
  return {
72
75
  id: 0,
73
76
  text: \`Fallback for \${id}\`,
@@ -75,7 +78,7 @@ export class ${className} implements ServiceInterface<${upperName}, ${upperName}
75
78
  }
76
79
  }
77
80
 
78
- async remove (id: NullableId, _params?: ${upperName}Params): Promise<${upperName}> {
81
+ async remove (id: NullableId, _params?: ServiceParams): Promise<${upperName}> {
79
82
  return {
80
83
  id: 0,
81
84
  text: 'removed'
@@ -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;cACQ,SAAS;cACT,SAAS;cACT,SAAS;cACT,SAAS;CAEvB;;mBAEmB,SAAS;;;;mBAIT,SAAS,yBAAyB,SAAS;;;;;eAK/C,SAAS,gCAAgC,SAAS,KAAK,SAAS,SAAS,SAAS,WAAW,SAAS;iCACpF,SAAS;;;0BAGhB,SAAS,oBAAoB,SAAS;;;;iCAI/B,SAAS,oBAAoB,SAAS;;;;;;;wBAO/C,SAAS,kBAAkB,SAAS,oBAAoB,SAAS;wBACjE,SAAS,oBAAoB,SAAS,oBAAoB,SAAS;wBACnE,SAAS,QAAQ,SAAS,oBAAoB,SAAS,oBAAoB,SAAS,IAAI,SAAS;;;;;;;;;;;;wCAYjF,SAAS,mBAAmB,SAAS,oBAAoB,SAAS;;;;;;;uCAOnE,SAAS,oBAAoB,SAAS,oBAAoB,SAAS;;;;;;;;4CAQ9D,SAAS,oBAAoB,SAAS;;;;;;;;;;;CAWjF,CAAA;AA3FY,QAAA,QAAQ,YA2FpB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,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