@feathersjs/cli 5.0.0-pre.29 → 5.0.0-pre.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 (152) hide show
  1. package/CHANGELOG.md +25 -39
  2. package/bin/feathers +3 -6
  3. package/lib/app/index.js +33 -10
  4. package/lib/app/index.js.map +1 -1
  5. package/lib/app/index.ts +81 -53
  6. package/lib/app/templates/app.test.tpl.js +1 -1
  7. package/lib/app/templates/app.test.tpl.js.map +1 -1
  8. package/lib/app/templates/app.test.tpl.ts +1 -2
  9. package/lib/app/templates/app.tpl.js +7 -7
  10. package/lib/app/templates/app.tpl.js.map +1 -1
  11. package/lib/app/templates/app.tpl.ts +7 -9
  12. package/lib/app/templates/channels.tpl.js +1 -1
  13. package/lib/app/templates/channels.tpl.js.map +1 -1
  14. package/lib/app/templates/channels.tpl.ts +1 -2
  15. package/lib/app/templates/client.tpl.js +2 -2
  16. package/lib/app/templates/client.tpl.js.map +1 -1
  17. package/lib/app/templates/client.tpl.ts +2 -3
  18. package/lib/app/templates/declarations.tpl.js +3 -3
  19. package/lib/app/templates/declarations.tpl.js.map +1 -1
  20. package/lib/app/templates/declarations.tpl.ts +5 -4
  21. package/lib/app/templates/index.html.tpl.js +12 -52
  22. package/lib/app/templates/index.html.tpl.js.map +1 -1
  23. package/lib/app/templates/index.html.tpl.ts +12 -53
  24. package/lib/app/templates/index.tpl.js +1 -1
  25. package/lib/app/templates/index.tpl.js.map +1 -1
  26. package/lib/app/templates/index.tpl.ts +1 -2
  27. package/lib/app/templates/logger.tpl.js +1 -1
  28. package/lib/app/templates/logger.tpl.js.map +1 -1
  29. package/lib/app/templates/logger.tpl.ts +2 -2
  30. package/lib/app/templates/package.json.tpl.js +4 -3
  31. package/lib/app/templates/package.json.tpl.js.map +1 -1
  32. package/lib/app/templates/package.json.tpl.ts +5 -3
  33. package/lib/app/templates/readme.md.tpl.js +11 -7
  34. package/lib/app/templates/readme.md.tpl.js.map +1 -1
  35. package/lib/app/templates/readme.md.tpl.ts +15 -8
  36. package/lib/app/templates/{configuration.tpl.d.ts → schemas.tpl.d.ts} +0 -0
  37. package/lib/app/templates/schemas.tpl.js +76 -0
  38. package/lib/app/templates/schemas.tpl.js.map +1 -0
  39. package/lib/app/templates/schemas.tpl.ts +90 -0
  40. package/lib/app/templates/services.tpl.js +1 -1
  41. package/lib/app/templates/services.tpl.js.map +1 -1
  42. package/lib/app/templates/services.tpl.ts +1 -2
  43. package/lib/authentication/index.d.ts +4 -3
  44. package/lib/authentication/index.js +12 -3
  45. package/lib/authentication/index.js.map +1 -1
  46. package/lib/authentication/index.ts +23 -5
  47. package/lib/authentication/templates/authentication.tpl.js +1 -1
  48. package/lib/authentication/templates/authentication.tpl.js.map +1 -1
  49. package/lib/authentication/templates/authentication.tpl.ts +3 -2
  50. package/lib/authentication/templates/config.tpl.js +1 -1
  51. package/lib/authentication/templates/config.tpl.js.map +1 -1
  52. package/lib/authentication/templates/config.tpl.ts +1 -1
  53. package/lib/authentication/templates/declarations.tpl.js +3 -3
  54. package/lib/authentication/templates/declarations.tpl.js.map +1 -1
  55. package/lib/authentication/templates/declarations.tpl.ts +9 -4
  56. package/lib/authentication/templates/knex.tpl.js +2 -2
  57. package/lib/authentication/templates/knex.tpl.js.map +1 -1
  58. package/lib/authentication/templates/knex.tpl.ts +2 -2
  59. package/lib/authentication/templates/{user.resolver.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
  60. package/lib/authentication/templates/schema.json.tpl.js +92 -0
  61. package/lib/authentication/templates/schema.json.tpl.js.map +1 -0
  62. package/lib/authentication/templates/schema.json.tpl.ts +108 -0
  63. package/lib/authentication/templates/{user.schema.tpl.d.ts → schema.typebox.tpl.d.ts} +1 -0
  64. package/lib/authentication/templates/schema.typebox.tpl.js +79 -0
  65. package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
  66. package/lib/authentication/templates/schema.typebox.tpl.ts +94 -0
  67. package/lib/authentication/templates/test.tpl.js +2 -2
  68. package/lib/authentication/templates/test.tpl.js.map +1 -1
  69. package/lib/authentication/templates/test.tpl.ts +6 -3
  70. package/lib/cli.d.ts +6 -0
  71. package/lib/cli.js +75 -0
  72. package/lib/cli.js.map +1 -0
  73. package/lib/cli.ts +68 -0
  74. package/lib/commons.d.ts +14 -1
  75. package/lib/commons.js +24 -4
  76. package/lib/commons.js.map +1 -1
  77. package/lib/commons.ts +29 -1
  78. package/lib/connection/index.d.ts +5 -3
  79. package/lib/connection/index.js +5 -3
  80. package/lib/connection/index.js.map +1 -1
  81. package/lib/connection/index.ts +19 -5
  82. package/lib/connection/templates/knex.tpl.js +2 -12
  83. package/lib/connection/templates/knex.tpl.js.map +1 -1
  84. package/lib/connection/templates/knex.tpl.ts +6 -20
  85. package/lib/connection/templates/mongodb.tpl.js +1 -3
  86. package/lib/connection/templates/mongodb.tpl.js.map +1 -1
  87. package/lib/connection/templates/mongodb.tpl.ts +1 -12
  88. package/lib/hook/index.d.ts +1 -1
  89. package/lib/hook/index.js +3 -0
  90. package/lib/hook/index.js.map +1 -1
  91. package/lib/hook/index.ts +3 -1
  92. package/lib/hook/templates/hook.tpl.js +2 -3
  93. package/lib/hook/templates/hook.tpl.js.map +1 -1
  94. package/lib/hook/templates/hook.tpl.ts +5 -3
  95. package/lib/index.d.ts +2 -16
  96. package/lib/index.js +16 -24
  97. package/lib/index.js.map +1 -1
  98. package/lib/index.ts +2 -28
  99. package/lib/service/index.d.ts +10 -2
  100. package/lib/service/index.js +79 -41
  101. package/lib/service/index.js.map +1 -1
  102. package/lib/service/index.ts +54 -6
  103. package/lib/service/templates/client.tpl.js +19 -11
  104. package/lib/service/templates/client.tpl.js.map +1 -1
  105. package/lib/service/templates/client.tpl.ts +34 -17
  106. package/lib/service/templates/{class.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
  107. package/lib/service/templates/schema.json.tpl.js +73 -0
  108. package/lib/service/templates/schema.json.tpl.js.map +1 -0
  109. package/lib/service/templates/schema.json.tpl.ts +85 -0
  110. package/lib/service/templates/{resolver.tpl.d.ts → schema.typebox.tpl.d.ts} +0 -0
  111. package/lib/service/templates/schema.typebox.tpl.js +58 -0
  112. package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
  113. package/lib/service/templates/schema.typebox.tpl.ts +70 -0
  114. package/lib/service/templates/service.tpl.d.ts +1 -0
  115. package/lib/service/templates/service.tpl.js +67 -15
  116. package/lib/service/templates/service.tpl.js.map +1 -1
  117. package/lib/service/templates/service.tpl.ts +98 -19
  118. package/lib/service/templates/test.tpl.js +1 -1
  119. package/lib/service/templates/test.tpl.js.map +1 -1
  120. package/lib/service/templates/test.tpl.ts +1 -2
  121. package/lib/service/type/custom.tpl.d.ts +1 -2
  122. package/lib/service/type/custom.tpl.js +32 -25
  123. package/lib/service/type/custom.tpl.js.map +1 -1
  124. package/lib/service/type/custom.tpl.ts +44 -35
  125. package/lib/service/type/knex.tpl.d.ts +1 -3
  126. package/lib/service/type/knex.tpl.js +33 -23
  127. package/lib/service/type/knex.tpl.js.map +1 -1
  128. package/lib/service/type/knex.tpl.ts +51 -29
  129. package/lib/service/type/mongodb.tpl.d.ts +1 -2
  130. package/lib/service/type/mongodb.tpl.js +30 -20
  131. package/lib/service/type/mongodb.tpl.js.map +1 -1
  132. package/lib/service/type/mongodb.tpl.ts +47 -29
  133. package/package.json +22 -23
  134. package/lib/app/templates/configuration.tpl.js +0 -45
  135. package/lib/app/templates/configuration.tpl.js.map +0 -1
  136. package/lib/app/templates/configuration.tpl.ts +0 -50
  137. package/lib/authentication/templates/user.resolver.tpl.js +0 -98
  138. package/lib/authentication/templates/user.resolver.tpl.js.map +0 -1
  139. package/lib/authentication/templates/user.resolver.tpl.ts +0 -111
  140. package/lib/authentication/templates/user.schema.tpl.js +0 -79
  141. package/lib/authentication/templates/user.schema.tpl.js.map +0 -1
  142. package/lib/authentication/templates/user.schema.tpl.ts +0 -87
  143. package/lib/service/templates/class.tpl.js +0 -63
  144. package/lib/service/templates/class.tpl.js.map +0 -1
  145. package/lib/service/templates/class.tpl.ts +0 -79
  146. package/lib/service/templates/resolver.tpl.js +0 -73
  147. package/lib/service/templates/resolver.tpl.js.map +0 -1
  148. package/lib/service/templates/resolver.tpl.ts +0 -78
  149. package/lib/service/templates/schema.tpl.d.ts +0 -2
  150. package/lib/service/templates/schema.tpl.js +0 -75
  151. package/lib/service/templates/schema.tpl.js.map +0 -1
  152. package/lib/service/templates/schema.tpl.ts +0 -80
@@ -1 +1 @@
1
- {"version":3,"file":"service.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/service.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AACtE,2CAA0D;AAG1D,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAC/F,qCAAqC,QAAQ;;WAEpC,SAAS,KAAK,SAAS,mBAAmB,QAAQ;;;kBAG3C,SAAS;;;;;aAKd,IAAI,UAAU,SAAS;;;;;;;iBAOnB,IAAI,YAAY,SAAS;;;;kBAIxB,QAAQ;;OAEnB,IAAI,MAAM,SAAS;;;CAGzB,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAClF,YAAY,SAAS,cAAc,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,WAAW,CAAA;AAE5E,MAAM,iBAAiB,GAAG,CAAC,EAAE,SAAS,EAA2B,EAAE,EAAE,CAAC,mBAAmB,SAAS,GAAG,CAAA;AAErG,MAAM,cAAc,GAAG,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAA2B,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AAExF,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,I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q/pinion'
1
+ import { generator, toFile, after, prepend } from '@feathershq/pinion'
2
2
  import { injectSource, renderSource } from '../../commons'
3
3
  import { ServiceGeneratorContext } from '../index'
4
4
 
5
- const template = ({ relative, path, className, camelName, fileName }: ServiceGeneratorContext) =>
6
- `import type { Application } from '${relative}/declarations'
5
+ export const template = ({
6
+ camelName,
7
+ authentication,
8
+ isEntityService,
9
+ path,
10
+ className,
11
+ relative,
12
+ schema,
13
+ fileName
14
+ }: ServiceGeneratorContext) => /* ts */ `
15
+ ${authentication || isEntityService ? `import { authenticate } from '@feathersjs/authentication'` : ''}
16
+ ${
17
+ schema
18
+ ? `
19
+ import { hooks as schemaHooks } from '@feathersjs/schema'
20
+
21
+ import {
22
+ ${camelName}DataValidator,
23
+ ${camelName}QueryValidator,
24
+ ${camelName}Resolver,
25
+ ${camelName}DataResolver,
26
+ ${camelName}QueryResolver,
27
+ ${camelName}ExternalResolver
28
+ } from './${fileName}.schema'
29
+ `
30
+ : ''
31
+ }
7
32
 
8
- import { ${className}, ${camelName}Hooks } from './${fileName}.class'
33
+ import type { Application } from '${relative}/declarations'
34
+ import { ${className}, getOptions } from './${fileName}.class'
9
35
 
10
- // A configure function that registers the service and its hooks via \`app.configure\`
11
- export function ${camelName} (app: Application) {
12
- const options = { // Service options will go here
13
- }
36
+ export * from './${fileName}.class'
37
+ ${schema ? `export * from './${fileName}.schema'` : ''}
14
38
 
39
+ // A configure function that registers the service and its hooks via \`app.configure\`
40
+ export const ${camelName} = (app: Application) => {
15
41
  // Register our service on the Feathers application
16
- app.use('${path}', new ${className}(options), {
42
+ app.use('${path}', new ${className}(getOptions(app)), {
17
43
  // A list of all methods this service exposes externally
18
44
  methods: ['find', 'get', 'create', 'update', 'patch', 'remove'],
19
45
  // You can add additional custom events to be sent to clients here
20
46
  events: []
21
47
  })
22
48
  // Initialize hooks
23
- app.service('${path}').hooks(${camelName}Hooks)
49
+ app.service('${path}').hooks({
50
+ around: {
51
+ all: [${
52
+ authentication
53
+ ? `
54
+ authenticate('jwt'),`
55
+ : ''
56
+ }
57
+ ]${
58
+ isEntityService
59
+ ? `,
60
+ find: [ authenticate('jwt') ],
61
+ get: [ authenticate('jwt') ],
62
+ create: [],
63
+ update: [ authenticate('jwt') ],
64
+ patch: [ authenticate('jwt') ],
65
+ remove: [ authenticate('jwt') ]`
66
+ : ''
67
+ }
68
+ },
69
+ before: {
70
+ all: [${
71
+ schema
72
+ ? `
73
+ schemaHooks.validateQuery(${camelName}QueryValidator),
74
+ schemaHooks.validateData(${camelName}DataValidator),
75
+ schemaHooks.resolveQuery(${camelName}QueryResolver),
76
+ schemaHooks.resolveData(${camelName}DataResolver)
77
+ `
78
+ : ''
79
+ }]
80
+ },
81
+ after: {
82
+ all: [${
83
+ schema
84
+ ? `
85
+ schemaHooks.resolveResult(${camelName}Resolver),
86
+ schemaHooks.resolveExternal(${camelName}ExternalResolver)
87
+ `
88
+ : ''
89
+ }]
90
+ },
91
+ error: {
92
+ all: []
93
+ }
94
+ })
24
95
  }
25
96
 
26
97
  // Add this service to the service type index
@@ -31,11 +102,6 @@ declare module '${relative}/declarations' {
31
102
  }
32
103
  `
33
104
 
34
- const importTemplate = ({ camelName, folder, fileName }: ServiceGeneratorContext) =>
35
- `import { ${camelName} } from './${folder.join('/')}/${fileName}.service'`
36
-
37
- const configureTemplate = ({ camelName }: ServiceGeneratorContext) => ` app.configure(${camelName})`
38
-
39
105
  const toServiceIndex = toFile(({ lib }: ServiceGeneratorContext) => [lib, 'services', `index`])
40
106
 
41
107
  export const generate = (ctx: ServiceGeneratorContext) =>
@@ -43,13 +109,26 @@ export const generate = (ctx: ServiceGeneratorContext) =>
43
109
  .then(
44
110
  renderSource(
45
111
  template,
46
- toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
112
+ toFile(({ lib, fileName, folder }: ServiceGeneratorContext) => [
47
113
  lib,
48
114
  'services',
49
115
  ...folder,
50
- `${fileName}.service`
116
+ `${fileName}`
51
117
  ])
52
118
  )
53
119
  )
54
- .then(injectSource(importTemplate, prepend(), toServiceIndex))
55
- .then(injectSource(configureTemplate, after('export const services'), toServiceIndex))
120
+ .then(
121
+ injectSource<ServiceGeneratorContext>(
122
+ ({ camelName, folder, fileName }) =>
123
+ `import { ${camelName} } from './${folder.join('/')}/${fileName}'`,
124
+ prepend(),
125
+ toServiceIndex
126
+ )
127
+ )
128
+ .then(
129
+ injectSource<ServiceGeneratorContext>(
130
+ ({ camelName }) => ` app.configure(${camelName})`,
131
+ after('export const services'),
132
+ toServiceIndex
133
+ )
134
+ )
@@ -3,7 +3,7 @@ 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 template = ({ relative, lib, path }) => `import assert from 'assert'
6
+ const template = ({ relative, lib, path }) => /* ts */ `import assert from 'assert'
7
7
  import { app } from '../${relative}/${lib}/app'
8
8
 
9
9
  describe('${path} service', () => {
@@ -1 +1 @@
1
- {"version":3,"file":"test.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAA2B,EAAE,EAAE,CACpE;0BACwB,QAAQ,IAAI,GAAG;;YAE7B,IAAI;;mCAEmB,IAAI;;;;;CAKtC,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAA0B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC9D,IAAI;IACJ,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,OAAO;CACnB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
1
+ {"version":3,"file":"test.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAA2B,EAAE,EAAE,CAAC,QAAQ,CAAC;0BACtD,QAAQ,IAAI,GAAG;;YAE7B,IAAI;;mCAEmB,IAAI;;;;;CAKtC,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAA0B,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC9D,IAAI;IACJ,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,OAAO;CACnB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
@@ -2,8 +2,7 @@ import { generator, toFile } from '@feathershq/pinion'
2
2
  import { renderSource } from '../../commons'
3
3
  import { ServiceGeneratorContext } from '../index'
4
4
 
5
- const template = ({ relative, lib, path }: ServiceGeneratorContext) =>
6
- `import assert from 'assert'
5
+ const template = ({ relative, lib, path }: ServiceGeneratorContext) => /* ts */ `import assert from 'assert'
7
6
  import { app } from '../${relative}/${lib}/app'
8
7
 
9
8
  describe('${path} service', () => {
@@ -1,4 +1,3 @@
1
1
  import { ServiceGeneratorContext } from '../index';
2
- export declare const template: ({ className, upperName, relative }: ServiceGeneratorContext) => string;
3
- export declare const importTemplate = "import type { Id, NullableId, Params } from '@feathersjs/feathers'";
2
+ export declare const template: ({ className, upperName, schema, fileName, relative }: ServiceGeneratorContext) => string;
4
3
  export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -1,10 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = exports.importTemplate = exports.template = void 0;
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 = ({ className, upperName, relative }) => `import type { Application } from '${relative}/declarations'
7
-
6
+ const template = ({ className, upperName, schema, fileName, relative }) => `
7
+ import type { Id, NullableId, Params } from '@feathersjs/feathers'
8
+
9
+ import type { Application } from '${relative}/declarations'
10
+ ${schema
11
+ ? `import type {
12
+ ${upperName},
13
+ ${upperName}Data,
14
+ ${upperName}Query
15
+ } from './${fileName}.schema'
16
+ `
17
+ : `
18
+ export type ${upperName} = any
19
+ export type ${upperName}Data = any
20
+ export type ${upperName}Query = any
21
+ `}
22
+
8
23
  export interface ${className}Options {
9
24
  app: Application
10
25
  }
@@ -18,20 +33,20 @@ export class ${className} {
18
33
  constructor (public options: ${className}Options) {
19
34
  }
20
35
 
21
- async find (_params?: ${upperName}Params): Promise<${upperName}Result[]> {
36
+ async find (_params?: ${upperName}Params): Promise<${upperName}[]> {
22
37
  return []
23
38
  }
24
39
 
25
- async get (id: Id, _params?: ${upperName}Params): Promise<${upperName}Result> {
40
+ async get (id: Id, _params?: ${upperName}Params): Promise<${upperName}> {
26
41
  return {
27
42
  id: 0,
28
43
  text: \`A new message with ID: \${id}!\`
29
44
  }
30
45
  }
31
46
 
32
- async create (data: ${upperName}Data, params?: ${upperName}Params): Promise<${upperName}Result>
33
- async create (data: ${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}Result[]>
34
- async create (data: ${upperName}Data|${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}Result|${upperName}Result[]> {
47
+ async create (data: ${upperName}Data, params?: ${upperName}Params): Promise<${upperName}>
48
+ async create (data: ${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}[]>
49
+ async create (data: ${upperName}Data|${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}|${upperName}[]> {
35
50
  if (Array.isArray(data)) {
36
51
  return Promise.all(data.map(current => this.create(current, params)));
37
52
  }
@@ -42,46 +57,38 @@ export class ${className} {
42
57
  }
43
58
  }
44
59
 
45
- async update (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}Result> {
60
+ async update (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}> {
46
61
  return {
47
62
  id: 0,
48
63
  ...data
49
64
  }
50
65
  }
51
66
 
52
- async patch (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}Result> {
67
+ async patch (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}> {
53
68
  return {
54
69
  id: 0,
55
70
  ...data
56
71
  }
57
72
  }
58
73
 
59
- async remove (id: NullableId, _params?: ${upperName}Params): Promise<${upperName}Result> {
74
+ async remove (id: NullableId, _params?: ${upperName}Params): Promise<${upperName}> {
60
75
  return {
61
76
  id: 0,
62
77
  text: 'removed'
63
78
  }
64
79
  }
65
80
  }
81
+
82
+ export const getOptions = (app: Application) => {
83
+ return { app }
84
+ }
66
85
  `;
67
86
  exports.template = template;
68
- exports.importTemplate = "import type { Id, NullableId, Params } from '@feathersjs/feathers'";
69
- const optionTemplate = ({}) => ` app`;
70
- const toServiceFile = (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
71
- lib,
72
- 'services',
73
- ...folder,
74
- `${fileName}.service`
75
- ]);
76
- const toClassFile = (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
87
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(exports.template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
77
88
  lib,
78
89
  'services',
79
90
  ...folder,
80
91
  `${fileName}.class`
81
- ]);
82
- const generate = (ctx) => (0, pinion_1.generator)(ctx)
83
- .then((0, commons_1.injectSource)(exports.template, (0, pinion_1.append)(), toClassFile))
84
- .then((0, commons_1.injectSource)(exports.importTemplate, (0, pinion_1.prepend)(), toClassFile))
85
- .then((0, commons_1.injectSource)(optionTemplate, (0, pinion_1.after)('const options ='), toServiceFile, false));
92
+ ])));
86
93
  exports.generate = generate;
87
94
  //# sourceMappingURL=custom.tpl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"custom.tpl.js","sourceRoot":"","sources":["../../../src/service/type/custom.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8E;AAC9E,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAA2B,EAAE,EAAE,CACtF,qCAAqC,QAAQ;;mBAE5B,SAAS;;;;mBAIT,SAAS,yBAAyB,SAAS;;;;;eAK/C,SAAS;iCACS,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,UAAU,SAAS;;;;;;;;;;;wCAWvF,SAAS,mBAAmB,SAAS,oBAAoB,SAAS;;;;;;;uCAOnE,SAAS,mBAAmB,SAAS,oBAAoB,SAAS;;;;;;;4CAO7D,SAAS,oBAAoB,SAAS;;;;;;;CAOjF,CAAA;AA7DY,QAAA,QAAQ,YA6DpB;AAEY,QAAA,cAAc,GAAG,oEAAoE,CAAA;AAElG,MAAM,cAAc,GAAG,CAAC,EAA2B,EAAE,EAAE,CAAC,SAAS,CAAA;AAEjE,MAAM,aAAa,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACnF,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,UAAU;CACtB,CAAC,CAAA;AAEF,MAAM,WAAW,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,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;;;;;;;wCAWjF,SAAS,mBAAmB,SAAS,oBAAoB,SAAS;;;;;;;uCAOnE,SAAS,mBAAmB,SAAS,oBAAoB,SAAS;;;;;;;4CAO7D,SAAS,oBAAoB,SAAS;;;;;;;;;;;CAWjF,CAAA;AAjFY,QAAA,QAAQ,YAiFpB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,gBAAQ,EACR,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,QAAQ;CACpB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
@@ -1,10 +1,26 @@
1
- import { generator, toFile, after, prepend, append } from '@feathershq/pinion'
2
- import { injectSource } from '../../commons'
1
+ import { generator, toFile } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
3
  import { ServiceGeneratorContext } from '../index'
4
4
 
5
- export const template = ({ className, upperName, relative }: ServiceGeneratorContext) =>
6
- `import type { Application } from '${relative}/declarations'
7
-
5
+ export const template = ({ className, upperName, schema, fileName, relative }: ServiceGeneratorContext) => `
6
+ import type { Id, NullableId, Params } from '@feathersjs/feathers'
7
+
8
+ import type { Application } from '${relative}/declarations'
9
+ ${
10
+ schema
11
+ ? `import type {
12
+ ${upperName},
13
+ ${upperName}Data,
14
+ ${upperName}Query
15
+ } from './${fileName}.schema'
16
+ `
17
+ : `
18
+ export type ${upperName} = any
19
+ export type ${upperName}Data = any
20
+ export type ${upperName}Query = any
21
+ `
22
+ }
23
+
8
24
  export interface ${className}Options {
9
25
  app: Application
10
26
  }
@@ -18,20 +34,20 @@ export class ${className} {
18
34
  constructor (public options: ${className}Options) {
19
35
  }
20
36
 
21
- async find (_params?: ${upperName}Params): Promise<${upperName}Result[]> {
37
+ async find (_params?: ${upperName}Params): Promise<${upperName}[]> {
22
38
  return []
23
39
  }
24
40
 
25
- async get (id: Id, _params?: ${upperName}Params): Promise<${upperName}Result> {
41
+ async get (id: Id, _params?: ${upperName}Params): Promise<${upperName}> {
26
42
  return {
27
43
  id: 0,
28
44
  text: \`A new message with ID: \${id}!\`
29
45
  }
30
46
  }
31
47
 
32
- async create (data: ${upperName}Data, params?: ${upperName}Params): Promise<${upperName}Result>
33
- async create (data: ${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}Result[]>
34
- async create (data: ${upperName}Data|${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}Result|${upperName}Result[]> {
48
+ async create (data: ${upperName}Data, params?: ${upperName}Params): Promise<${upperName}>
49
+ async create (data: ${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}[]>
50
+ async create (data: ${upperName}Data|${upperName}Data[], params?: ${upperName}Params): Promise<${upperName}|${upperName}[]> {
35
51
  if (Array.isArray(data)) {
36
52
  return Promise.all(data.map(current => this.create(current, params)));
37
53
  }
@@ -42,49 +58,42 @@ export class ${className} {
42
58
  }
43
59
  }
44
60
 
45
- async update (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}Result> {
61
+ async update (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}> {
46
62
  return {
47
63
  id: 0,
48
64
  ...data
49
65
  }
50
66
  }
51
67
 
52
- async patch (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}Result> {
68
+ async patch (id: NullableId, data: ${upperName}Data, _params?: ${upperName}Params): Promise<${upperName}> {
53
69
  return {
54
70
  id: 0,
55
71
  ...data
56
72
  }
57
73
  }
58
74
 
59
- async remove (id: NullableId, _params?: ${upperName}Params): Promise<${upperName}Result> {
75
+ async remove (id: NullableId, _params?: ${upperName}Params): Promise<${upperName}> {
60
76
  return {
61
77
  id: 0,
62
78
  text: 'removed'
63
79
  }
64
80
  }
65
81
  }
66
- `
67
82
 
68
- export const importTemplate = "import type { Id, NullableId, Params } from '@feathersjs/feathers'"
69
-
70
- const optionTemplate = ({}: ServiceGeneratorContext) => ` app`
71
-
72
- const toServiceFile = toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
73
- lib,
74
- 'services',
75
- ...folder,
76
- `${fileName}.service`
77
- ])
78
-
79
- const toClassFile = toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
80
- lib,
81
- 'services',
82
- ...folder,
83
- `${fileName}.class`
84
- ])
83
+ export const getOptions = (app: Application) => {
84
+ return { app }
85
+ }
86
+ `
85
87
 
86
88
  export const generate = (ctx: ServiceGeneratorContext) =>
87
- generator(ctx)
88
- .then(injectSource(template, append(), toClassFile))
89
- .then(injectSource(importTemplate, prepend(), toClassFile))
90
- .then(injectSource(optionTemplate, after('const options ='), toServiceFile, false))
89
+ generator(ctx).then(
90
+ renderSource(
91
+ template,
92
+ toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
93
+ lib,
94
+ 'services',
95
+ ...folder,
96
+ `${fileName}.class`
97
+ ])
98
+ )
99
+ )
@@ -1,5 +1,3 @@
1
1
  import { ServiceGeneratorContext } from '../index';
2
- export declare const importTemplate = "import { KnexService } from '@feathersjs/knex'\nimport type { KnexAdapterParams } from '@feathersjs/knex'";
3
- export declare const classCode: ({ className, upperName }: ServiceGeneratorContext) => string;
4
- export declare const optionTemplate: ({ kebabName, feathers }: ServiceGeneratorContext) => string;
2
+ export declare const template: ({ className, upperName, kebabName, feathers, schema, fileName, relative }: ServiceGeneratorContext) => string;
5
3
  export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = exports.optionTemplate = exports.classCode = exports.importTemplate = void 0;
3
+ exports.generate = exports.template = void 0;
4
4
  const pinion_1 = require("@feathershq/pinion");
5
5
  const commons_1 = require("../../commons");
6
- const migrationTemplate = ({ kebabName }) => `import type { Knex } from 'knex'
6
+ const migrationTemplate = ({ kebabName }) => /* ts */ `import type { Knex } from 'knex'
7
7
 
8
8
  export async function up(knex: Knex): Promise<void> {
9
9
  await knex.schema.createTable('${kebabName}', table => {
@@ -16,36 +16,46 @@ export async function down(knex: Knex): Promise<void> {
16
16
  await knex.schema.dropTable('${kebabName}')
17
17
  }
18
18
  `;
19
- exports.importTemplate = `import { KnexService } from \'@feathersjs/knex\'
20
- import type { KnexAdapterParams } from \'@feathersjs/knex\'`;
21
- const classCode = ({ className, upperName }) => `export interface ${upperName}Params extends KnexAdapterParams<${upperName}Query> {
19
+ const template = ({ className, upperName, kebabName, feathers, schema, fileName, relative }) => /* ts */ `import { KnexService } from '@feathersjs/knex'
20
+ import type { KnexAdapterParams } from '@feathersjs/knex'
21
+
22
+ import type { Application } from '${relative}/declarations'
23
+ ${schema
24
+ ? `import type {
25
+ ${upperName},
26
+ ${upperName}Data,
27
+ ${upperName}Query
28
+ } from './${fileName}.schema'
29
+ `
30
+ : `
31
+ export type ${upperName} = any
32
+ export type ${upperName}Data = any
33
+ export type ${upperName}Query = any
34
+ `}
35
+
36
+ export interface ${upperName}Params extends KnexAdapterParams<${upperName}Query> {
22
37
  }
23
38
 
24
39
  // By default calls the standard Knex adapter service methods but can be customized with your own functionality.
25
- export class ${className} extends KnexService<${upperName}Result, ${upperName}Data, ${upperName}Params> {
40
+ export class ${className} extends KnexService<${upperName}, ${upperName}Data, ${upperName}Params> {
26
41
  }
27
- `;
28
- exports.classCode = classCode;
29
- const optionTemplate = ({ kebabName, feathers }) => ` paginate: app.get('paginate'),
42
+
43
+ export const getOptions = (app: Application) => {
44
+ return {
45
+ paginate: app.get('paginate'),
30
46
  Model: app.get('${feathers.database}Client'),
31
- name: '${kebabName}'`;
32
- exports.optionTemplate = optionTemplate;
33
- const toServiceFile = (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
34
- lib,
35
- 'services',
36
- ...folder,
37
- `${fileName}.service`
38
- ]);
39
- const toClassFile = (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
47
+ name: '${kebabName}'
48
+ }
49
+ }
50
+ `;
51
+ exports.template = template;
52
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
53
+ .then((0, commons_1.renderSource)(exports.template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
40
54
  lib,
41
55
  'services',
42
56
  ...folder,
43
57
  `${fileName}.class`
44
- ]);
45
- const generate = (ctx) => (0, pinion_1.generator)(ctx)
46
- .then((0, commons_1.injectSource)(exports.classCode, (0, pinion_1.append)(), toClassFile))
47
- .then((0, commons_1.injectSource)(exports.importTemplate, (0, pinion_1.prepend)(), toClassFile))
48
- .then((0, commons_1.injectSource)(exports.optionTemplate, (0, pinion_1.after)('const options ='), toServiceFile, false))
58
+ ])))
49
59
  .then((0, commons_1.renderSource)(migrationTemplate, (0, pinion_1.toFile)('migrations', ({ kebabName }) => {
50
60
  // Probably not great but it works to align with the Knex migration file format
51
61
  const migrationDate = new Date().toISOString().replace(/\D/g, '').substring(0, 14);
@@ -1 +1 @@
1
- {"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/service/type/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8E;AAC9E,2CAA0D;AAG1D,MAAM,iBAAiB,GAAG,CAAC,EAAE,SAAS,EAA2B,EAAE,EAAE,CAAC;;;mCAGnC,SAAS;;;;;;;iCAOX,SAAS;;CAEzC,CAAA;AAEY,QAAA,cAAc,GAAG;4DAC8B,CAAA;AAErD,MAAM,SAAS,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAA2B,EAAE,EAAE,CAC7E,oBAAoB,SAAS,oCAAoC,SAAS;;;;eAI7D,SAAS,wBAAwB,SAAS,WAAW,SAAS,SAAS,SAAS;;CAE9F,CAAA;AAPY,QAAA,SAAS,aAOrB;AAEM,MAAM,cAAc,GAAG,CAAC,EAAE,SAAS,EAAE,QAAQ,EAA2B,E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G,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAElF,OAAO,GAAG,aAAa,IAAI,SAAS,EAAE,CAAA;AACxC,CAAC,CAAC,CACH,CACF,CAAA;AAvBQ,QAAA,QAAQ,YAuBhB"}
@@ -1,8 +1,10 @@
1
- import { generator, toFile, after, prepend, append } from '@feathershq/pinion'
2
- import { injectSource, renderSource } from '../../commons'
1
+ import { generator, toFile } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
3
  import { ServiceGeneratorContext } from '../index'
4
4
 
5
- const migrationTemplate = ({ kebabName }: ServiceGeneratorContext) => `import type { Knex } from 'knex'
5
+ const migrationTemplate = ({
6
+ kebabName
7
+ }: ServiceGeneratorContext) => /* ts */ `import type { Knex } from 'knex'
6
8
 
7
9
  export async function up(knex: Knex): Promise<void> {
8
10
  await knex.schema.createTable('${kebabName}', table => {
@@ -16,42 +18,62 @@ export async function down(knex: Knex): Promise<void> {
16
18
  }
17
19
  `
18
20
 
19
- export const importTemplate = `import { KnexService } from \'@feathersjs/knex\'
20
- import type { KnexAdapterParams } from \'@feathersjs/knex\'`
21
+ export const template = ({
22
+ className,
23
+ upperName,
24
+ kebabName,
25
+ feathers,
26
+ schema,
27
+ fileName,
28
+ relative
29
+ }: ServiceGeneratorContext) => /* ts */ `import { KnexService } from '@feathersjs/knex'
30
+ import type { KnexAdapterParams } from '@feathersjs/knex'
21
31
 
22
- export const classCode = ({ className, upperName }: ServiceGeneratorContext) =>
23
- `export interface ${upperName}Params extends KnexAdapterParams<${upperName}Query> {
32
+ import type { Application } from '${relative}/declarations'
33
+ ${
34
+ schema
35
+ ? `import type {
36
+ ${upperName},
37
+ ${upperName}Data,
38
+ ${upperName}Query
39
+ } from './${fileName}.schema'
40
+ `
41
+ : `
42
+ export type ${upperName} = any
43
+ export type ${upperName}Data = any
44
+ export type ${upperName}Query = any
45
+ `
46
+ }
47
+
48
+ export interface ${upperName}Params extends KnexAdapterParams<${upperName}Query> {
24
49
  }
25
50
 
26
51
  // By default calls the standard Knex adapter service methods but can be customized with your own functionality.
27
- export class ${className} extends KnexService<${upperName}Result, ${upperName}Data, ${upperName}Params> {
52
+ export class ${className} extends KnexService<${upperName}, ${upperName}Data, ${upperName}Params> {
28
53
  }
29
- `
30
54
 
31
- export const optionTemplate = ({ kebabName, feathers }: ServiceGeneratorContext) =>
32
- ` paginate: app.get('paginate'),
55
+ export const getOptions = (app: Application) => {
56
+ return {
57
+ paginate: app.get('paginate'),
33
58
  Model: app.get('${feathers.database}Client'),
34
- name: '${kebabName}'`
35
-
36
- const toServiceFile = toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
37
- lib,
38
- 'services',
39
- ...folder,
40
- `${fileName}.service`
41
- ])
42
-
43
- const toClassFile = toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
44
- lib,
45
- 'services',
46
- ...folder,
47
- `${fileName}.class`
48
- ])
59
+ name: '${kebabName}'
60
+ }
61
+ }
62
+ `
49
63
 
50
64
  export const generate = (ctx: ServiceGeneratorContext) =>
51
65
  generator(ctx)
52
- .then(injectSource(classCode, append(), toClassFile))
53
- .then(injectSource(importTemplate, prepend(), toClassFile))
54
- .then(injectSource(optionTemplate, after('const options ='), toServiceFile, false))
66
+ .then(
67
+ renderSource(
68
+ template,
69
+ toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
70
+ lib,
71
+ 'services',
72
+ ...folder,
73
+ `${fileName}.class`
74
+ ])
75
+ )
76
+ )
55
77
  .then(
56
78
  renderSource(
57
79
  migrationTemplate,
@@ -1,4 +1,3 @@
1
1
  import { ServiceGeneratorContext } from '../index';
2
- export declare const importTemplate = "import { MongoDBService } from '@feathersjs/mongodb'\nimport type { MongoDBAdapterParams } from '@feathersjs/mongodb'";
3
- export declare const classCode: ({ className, upperName }: ServiceGeneratorContext) => string;
2
+ export declare const template: ({ className, upperName, kebabName, schema, fileName, relative }: ServiceGeneratorContext) => string;
4
3
  export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;