@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,7 +1,12 @@
1
1
  import _ from 'lodash'
2
2
  import { generator, runGenerator, runGenerators, prompt } from '@feathershq/pinion'
3
3
 
4
- import { FeathersBaseContext, getDatabaseAdapter } from '../commons'
4
+ import {
5
+ checkPreconditions,
6
+ FeathersBaseContext,
7
+ getDatabaseAdapter,
8
+ initializeBaseContext
9
+ } from '../commons'
5
10
 
6
11
  export interface ServiceGeneratorContext extends FeathersBaseContext {
7
12
  /**
@@ -44,6 +49,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
44
49
  * The chosen service type
45
50
  */
46
51
  type: 'knex' | 'mongodb' | 'custom'
52
+ /**
53
+ * Which schema definition format to use
54
+ */
55
+ schema: 'typebox' | 'json' | false
47
56
  /**
48
57
  * Wether this service uses authentication
49
58
  */
@@ -58,25 +67,43 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
58
67
  * Parameters the generator is called with
59
68
  */
60
69
  export type ServiceGeneratorArguments = FeathersBaseContext &
61
- Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService'>>
70
+ Partial<
71
+ Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>
72
+ >
62
73
 
63
74
  export const generate = (ctx: ServiceGeneratorArguments) =>
64
75
  generator(ctx)
76
+ .then(initializeBaseContext())
77
+ .then(checkPreconditions())
65
78
  .then(
66
79
  prompt<ServiceGeneratorArguments, ServiceGeneratorContext>(
67
- ({ name, path, type, authentication, isEntityService }) => [
80
+ ({ name, path, type, schema, authentication, isEntityService }) => [
68
81
  {
69
82
  name: 'name',
70
83
  type: 'input',
71
84
  when: !name,
72
- message: 'What is the name of your service?'
85
+ message: 'What is the name of your service?',
86
+ validate: (input) => {
87
+ if (!input || input === 'authentication') {
88
+ return 'Invalid service name'
89
+ }
90
+
91
+ return true
92
+ }
73
93
  },
74
94
  {
75
95
  name: 'path',
76
96
  type: 'input',
77
97
  when: !path,
78
98
  message: 'Which path should the service be registered on?',
79
- default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`
99
+ default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`,
100
+ validate: (input) => {
101
+ if (!input || input === 'authentication') {
102
+ return 'Invalid service path'
103
+ }
104
+
105
+ return true
106
+ }
80
107
  },
81
108
  {
82
109
  name: 'authentication',
@@ -89,7 +116,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
89
116
  type: 'list',
90
117
  when: !type,
91
118
  message: 'What kind of service is it?',
92
- default: getDatabaseAdapter(ctx.feathers.database),
119
+ default: getDatabaseAdapter(ctx.feathers?.database),
93
120
  choices: [
94
121
  {
95
122
  value: 'knex',
@@ -104,6 +131,27 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
104
131
  name: 'A custom service'
105
132
  }
106
133
  ]
134
+ },
135
+ {
136
+ name: 'schema',
137
+ type: 'list',
138
+ when: schema === undefined,
139
+ message: 'Which schema definition format do you want to use?',
140
+ default: ctx.feathers?.schema || 'json',
141
+ choices: [
142
+ {
143
+ value: 'typebox',
144
+ name: 'TypeBox'
145
+ },
146
+ {
147
+ value: 'json',
148
+ name: 'JSON schema'
149
+ },
150
+ {
151
+ value: false,
152
+ name: 'No schema'
153
+ }
154
+ ]
107
155
  }
108
156
  ]
109
157
  )
@@ -2,27 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
4
  const pinion_1 = require("@feathershq/pinion");
5
- const schemaImports = ({ upperName, folder, fileName }) => `import type {
5
+ const commons_1 = require("../../commons");
6
+ const schemaImports = ({ upperName, folder, fileName }) => /* ts */ `import type {
7
+ ${upperName},
6
8
  ${upperName}Data,
7
- ${upperName}Patch,
8
- ${upperName}Result,
9
9
  ${upperName}Query,
10
- } from './services/${folder.join('/')}/${fileName}.schema'
10
+ } from './services/${folder.join('/')}/${fileName}'
11
11
 
12
12
  export type {
13
+ ${upperName},
13
14
  ${upperName}Data,
14
- ${upperName}Patch,
15
- ${upperName}Result,
16
15
  ${upperName}Query,
17
16
  }`;
18
17
  const declarationTemplate = ({ path, upperName }) => ` '${path}': ClientService<
19
- ${upperName}Result,
18
+ ${upperName},
20
19
  ${upperName}Data,
21
- ${upperName}Patch,
22
- Paginated<${upperName}Result>,
20
+ Partial<${upperName}Data>,
21
+ Paginated<${upperName}>,
23
22
  Params<${upperName}Query>
24
- >`;
23
+ > & {
24
+ // Add custom methods here
25
+ }`;
26
+ const registrationTemplate = ({ path }) => ` client.use('${path}', connection.service('${path}'), {
27
+ // List all standard and custom methods
28
+ methods: ['find', 'get', 'create', 'update', 'patch', 'remove']
29
+ })
30
+ `;
25
31
  const toClientFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'client.ts']);
26
- const generate = async (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)((ctx) => ctx.language === 'ts', (0, pinion_1.inject)(schemaImports, (0, pinion_1.after)("from '@feathersjs/feathers'"), toClientFile), (0, pinion_1.inject)(declarationTemplate, (0, pinion_1.after)('export interface ServiceTypes'), toClientFile)));
32
+ const generate = async (ctx) => (0, pinion_1.generator)(ctx)
33
+ .then((0, commons_1.injectSource)(registrationTemplate, (0, pinion_1.before)('return client'), (0, pinion_1.toFile)(({ lib }) => [lib, 'client'])))
34
+ .then((0, pinion_1.when)((ctx) => ctx.language === 'ts', (0, pinion_1.inject)(schemaImports, (0, pinion_1.after)("from '@feathersjs/feathers'"), toClientFile), (0, pinion_1.inject)(declarationTemplate, (0, pinion_1.after)('export interface ServiceTypes'), toClientFile)));
27
35
  exports.generate = generate;
28
36
  //# 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;AAG3E,MAAM,aAAa,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAAC;IAChF,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;qBACQ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ;;;IAG7C,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;EACX,CAAA;AAEF,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAA2B,EAAE,EAAE,CAC3E,MAAM,IAAI;MACN,SAAS;MACT,SAAS;MACT,SAAS;gBACC,SAAS;aACZ,SAAS;IAClB,CAAA;AAEJ,MAAM,YAAY,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAA;AAE9E,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,eAAM,EAAC,aAAa,EAAE,IAAA,cAAK,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,EACzE,IAAA,eAAM,EAAC,mBAAmB,EAAE,IAAA,cAAK,EAAC,+BAA+B,CAAC,EAAE,YAAY,CAAC,CAClF,CACF,CAAA;AAPU,QAAA,QAAQ,YAOlB"}
1
+ {"version":3,"file":"client.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/client.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAmF;AACnF,2CAA4C;AAG5C,MAAM,aAAa,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAAC,QAAQ,CAAC;IACzF,SAAS;IACT,SAAS;IACT,SAAS;qBACQ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ;;;IAG7C,SAAS;IACT,SAAS;IACT,SAAS;EACX,CAAA;AAEF,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAA2B,EAAE,EAAE,CAC3E,MAAM,IAAI;MACN,SAAS;MACT,SAAS;cACD,SAAS;gBACP,SAAS;aACZ,SAAS;;;IAGlB,CAAA;AAEJ,MAAM,oBAAoB,GAAG,CAAC,EAC5B,IAAI,EACoB,EAAE,EAAE,CAAC,iBAAiB,IAAI,0BAA0B,IAAI;;;;CAIjF,CAAA;AAED,MAAM,YAAY,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAA;AAE9E,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,oBAAoB,EACpB,IAAA,eAAM,EAAC,eAAe,CAAC,EACvB,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAC9D,CACF;KACA,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,eAAM,EAAC,aAAa,EAAE,IAAA,cAAK,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,EACzE,IAAA,eAAM,EAAC,mBAAmB,EAAE,IAAA,cAAK,EAAC,+BAA+B,CAAC,EAAE,YAAY,CAAC,CAClF,CACF,CAAA;AAfQ,QAAA,QAAQ,YAehB"}
@@ -1,36 +1,53 @@
1
- import { generator, inject, toFile, when, after } from '@feathershq/pinion'
1
+ import { generator, inject, toFile, when, after, before } from '@feathershq/pinion'
2
+ import { injectSource } from '../../commons'
2
3
  import { ServiceGeneratorContext } from '../index'
3
4
 
4
- const schemaImports = ({ upperName, folder, fileName }: ServiceGeneratorContext) => `import type {
5
+ const schemaImports = ({ upperName, folder, fileName }: ServiceGeneratorContext) => /* ts */ `import type {
6
+ ${upperName},
5
7
  ${upperName}Data,
6
- ${upperName}Patch,
7
- ${upperName}Result,
8
8
  ${upperName}Query,
9
- } from './services/${folder.join('/')}/${fileName}.schema'
9
+ } from './services/${folder.join('/')}/${fileName}'
10
10
 
11
11
  export type {
12
+ ${upperName},
12
13
  ${upperName}Data,
13
- ${upperName}Patch,
14
- ${upperName}Result,
15
14
  ${upperName}Query,
16
15
  }`
17
16
 
18
17
  const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
19
18
  ` '${path}': ClientService<
20
- ${upperName}Result,
19
+ ${upperName},
21
20
  ${upperName}Data,
22
- ${upperName}Patch,
23
- Paginated<${upperName}Result>,
21
+ Partial<${upperName}Data>,
22
+ Paginated<${upperName}>,
24
23
  Params<${upperName}Query>
25
- >`
24
+ > & {
25
+ // Add custom methods here
26
+ }`
27
+
28
+ const registrationTemplate = ({
29
+ path
30
+ }: ServiceGeneratorContext) => ` client.use('${path}', connection.service('${path}'), {
31
+ // List all standard and custom methods
32
+ methods: ['find', 'get', 'create', 'update', 'patch', 'remove']
33
+ })
34
+ `
26
35
 
27
36
  const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client.ts'])
28
37
 
29
38
  export const generate = async (ctx: ServiceGeneratorContext) =>
30
- generator(ctx).then(
31
- when(
32
- (ctx) => ctx.language === 'ts',
33
- inject(schemaImports, after("from '@feathersjs/feathers'"), toClientFile),
34
- inject(declarationTemplate, after('export interface ServiceTypes'), toClientFile)
39
+ generator(ctx)
40
+ .then(
41
+ injectSource(
42
+ registrationTemplate,
43
+ before('return client'),
44
+ toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
45
+ )
46
+ )
47
+ .then(
48
+ when(
49
+ (ctx) => ctx.language === 'ts',
50
+ inject(schemaImports, after("from '@feathersjs/feathers'"), toClientFile),
51
+ inject(declarationTemplate, after('export interface ServiceTypes'), toClientFile)
52
+ )
35
53
  )
36
- )
@@ -0,0 +1,73 @@
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 template = ({ camelName, upperName, relative, type }) => /* ts */ `import { jsonSchema, resolve } from '@feathersjs/schema'
7
+ import type { FromSchema } from '@feathersjs/schema'
8
+
9
+ import type { HookContext } from '${relative}/declarations'
10
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
11
+
12
+ // Schema for the basic data model (e.g. creating new entries)
13
+ export const ${camelName}DataSchema = {
14
+ $id: '${upperName}Data',
15
+ type: 'object',
16
+ additionalProperties: false,
17
+ required: [ 'text' ],
18
+ properties: {
19
+ text: {
20
+ type: 'string'
21
+ }
22
+ }
23
+ } as const
24
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
25
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
26
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
27
+ properties: {}
28
+ })
29
+
30
+ // Schema for the data that is being returned
31
+ export const ${camelName}Schema = {
32
+ $id: '${upperName}',
33
+ type: 'object',
34
+ additionalProperties: false,
35
+ required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
36
+ properties: {
37
+ ...${camelName}DataSchema.properties,
38
+ ${type === 'mongodb' ? '_id' : 'id'}: {
39
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
40
+ }
41
+ }
42
+ } as const
43
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
44
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
45
+ properties: {}
46
+ })
47
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
48
+ properties: {}
49
+ })
50
+
51
+ // Schema for allowed query properties
52
+ export const ${camelName}QuerySchema = {
53
+ $id: '${upperName}Query',
54
+ type: 'object',
55
+ additionalProperties: false,
56
+ properties: {
57
+ ...jsonSchema.querySyntax(${camelName}Schema.properties)
58
+ }
59
+ } as const
60
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
61
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
62
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
63
+ properties: {}
64
+ })
65
+ `;
66
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)(({ schema }) => schema === 'json', (0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
67
+ lib,
68
+ 'services',
69
+ ...folder,
70
+ `${fileName}.schema`
71
+ ]))));
72
+ exports.generate = generate;
73
+ //# sourceMappingURL=schema.json.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACoB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;oCAGJ,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;UACd,SAAS;;;;;;;;;;cAUL,SAAS,4BAA4B,SAAS;eAC7C,SAAS,+CAA+C,SAAS;eACjE,SAAS,0BAA0B,SAAS;;;;;eAK5C,SAAS;UACd,SAAS;;;mBAGA,SAAS,yBAAyB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;SAE7E,SAAS;MACZ,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;eACxB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;;;;cAIzC,SAAS,wBAAwB,SAAS;eACzC,SAAS,sBAAsB,SAAS;;;eAGxC,SAAS,8BAA8B,SAAS;;;;;eAKhD,SAAS;UACd,SAAS;;;;gCAIa,SAAS;;;cAG3B,SAAS,6BAA6B,SAAS;eAC9C,SAAS,4CAA4C,SAAS;eAC9D,SAAS,2BAA2B,SAAS;;;CAG3D,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,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"}
@@ -0,0 +1,85 @@
1
+ import { generator, toFile, when } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
+ import { ServiceGeneratorContext } from '../index'
4
+
5
+ const template = ({
6
+ camelName,
7
+ upperName,
8
+ relative,
9
+ type
10
+ }: ServiceGeneratorContext) => /* ts */ `import { jsonSchema, resolve } from '@feathersjs/schema'
11
+ import type { FromSchema } from '@feathersjs/schema'
12
+
13
+ import type { HookContext } from '${relative}/declarations'
14
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
15
+
16
+ // Schema for the basic data model (e.g. creating new entries)
17
+ export const ${camelName}DataSchema = {
18
+ $id: '${upperName}Data',
19
+ type: 'object',
20
+ additionalProperties: false,
21
+ required: [ 'text' ],
22
+ properties: {
23
+ text: {
24
+ type: 'string'
25
+ }
26
+ }
27
+ } as const
28
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
29
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
30
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
31
+ properties: {}
32
+ })
33
+
34
+ // Schema for the data that is being returned
35
+ export const ${camelName}Schema = {
36
+ $id: '${upperName}',
37
+ type: 'object',
38
+ additionalProperties: false,
39
+ required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
40
+ properties: {
41
+ ...${camelName}DataSchema.properties,
42
+ ${type === 'mongodb' ? '_id' : 'id'}: {
43
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
44
+ }
45
+ }
46
+ } as const
47
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
48
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
49
+ properties: {}
50
+ })
51
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
52
+ properties: {}
53
+ })
54
+
55
+ // Schema for allowed query properties
56
+ export const ${camelName}QuerySchema = {
57
+ $id: '${upperName}Query',
58
+ type: 'object',
59
+ additionalProperties: false,
60
+ properties: {
61
+ ...jsonSchema.querySyntax(${camelName}Schema.properties)
62
+ }
63
+ } as const
64
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
65
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
66
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
67
+ properties: {}
68
+ })
69
+ `
70
+
71
+ export const generate = (ctx: ServiceGeneratorContext) =>
72
+ generator(ctx).then(
73
+ when<ServiceGeneratorContext>(
74
+ ({ schema }) => schema === 'json',
75
+ renderSource(
76
+ template,
77
+ toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
78
+ lib,
79
+ 'services',
80
+ ...folder,
81
+ `${fileName}.schema`
82
+ ])
83
+ )
84
+ )
85
+ )
@@ -0,0 +1,58 @@
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 template = ({ camelName, upperName, relative, type }) => /* ts */ `import { jsonSchema, resolve } from '@feathersjs/schema'
7
+ import { Type, querySyntax } from '@feathersjs/typebox'
8
+ import type { Static } from '@feathersjs/typebox'
9
+
10
+ import type { HookContext } from '${relative}/declarations'
11
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
12
+
13
+ // Schema for the basic data model (e.g. creating new entries)
14
+ export const ${camelName}DataSchema = Type.Object({
15
+ text: Type.String()
16
+ }, { $id: '${upperName}Data', additionalProperties: false })
17
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
18
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
19
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
20
+ properties: {}
21
+ })
22
+
23
+ // Schema for the data that is being returned
24
+ export const ${camelName}Schema = Type.Intersect([
25
+ ${camelName}DataSchema,
26
+ Type.Object({
27
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'}
28
+ })
29
+ ], { $id: '${upperName}', additionalProperties: false })
30
+ export type ${upperName} = Static<typeof ${camelName}Schema>
31
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
32
+ properties: {}
33
+ })
34
+
35
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
36
+ properties: {}
37
+ })
38
+
39
+ // Schema for allowed query properties
40
+ export const ${camelName}QuerySchema = Type.Intersect([
41
+ querySyntax(${camelName}Schema),
42
+ // Add additional query properties here
43
+ Type.Object({})
44
+ ])
45
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
46
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
47
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
48
+ properties: {}
49
+ })
50
+ `;
51
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)(({ schema }) => schema === 'typebox', (0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
52
+ lib,
53
+ 'services',
54
+ ...folder,
55
+ `${fileName}.schema`
56
+ ]))));
57
+ exports.generate = generate;
58
+ //# sourceMappingURL=schema.typebox.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACoB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;oCAIJ,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;;aAEX,SAAS;cACR,SAAS,wBAAwB,SAAS;eACzC,SAAS,+CAA+C,SAAS;eACjE,SAAS,0BAA0B,SAAS;;;;;eAK5C,SAAS;IACpB,SAAS;;MAEP,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,mBAAmB;;aAExD,SAAS;cACR,SAAS,oBAAoB,SAAS;eACrC,SAAS,sBAAsB,SAAS;;;;eAIxC,SAAS,8BAA8B,SAAS;;;;;eAKhD,SAAS;gBACR,SAAS;;;;cAIX,SAAS,yBAAyB,SAAS;eAC1C,SAAS,4CAA4C,SAAS;eAC9D,SAAS,2BAA2B,SAAS;;;CAG3D,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"}
@@ -0,0 +1,70 @@
1
+ import { generator, toFile, when } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
+ import { ServiceGeneratorContext } from '../index'
4
+
5
+ const template = ({
6
+ camelName,
7
+ upperName,
8
+ relative,
9
+ type
10
+ }: ServiceGeneratorContext) => /* ts */ `import { jsonSchema, resolve } from '@feathersjs/schema'
11
+ import { Type, querySyntax } from '@feathersjs/typebox'
12
+ import type { Static } from '@feathersjs/typebox'
13
+
14
+ import type { HookContext } from '${relative}/declarations'
15
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
16
+
17
+ // Schema for the basic data model (e.g. creating new entries)
18
+ export const ${camelName}DataSchema = Type.Object({
19
+ text: Type.String()
20
+ }, { $id: '${upperName}Data', additionalProperties: false })
21
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
22
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
23
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
24
+ properties: {}
25
+ })
26
+
27
+ // Schema for the data that is being returned
28
+ export const ${camelName}Schema = Type.Intersect([
29
+ ${camelName}DataSchema,
30
+ Type.Object({
31
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'}
32
+ })
33
+ ], { $id: '${upperName}', additionalProperties: false })
34
+ export type ${upperName} = Static<typeof ${camelName}Schema>
35
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
36
+ properties: {}
37
+ })
38
+
39
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
40
+ properties: {}
41
+ })
42
+
43
+ // Schema for allowed query properties
44
+ export const ${camelName}QuerySchema = Type.Intersect([
45
+ querySyntax(${camelName}Schema),
46
+ // Add additional query properties here
47
+ Type.Object({})
48
+ ])
49
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
50
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
51
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
52
+ properties: {}
53
+ })
54
+ `
55
+
56
+ export const generate = (ctx: ServiceGeneratorContext) =>
57
+ generator(ctx).then(
58
+ when<ServiceGeneratorContext>(
59
+ ({ schema }) => schema === 'typebox',
60
+ renderSource(
61
+ template,
62
+ toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
63
+ lib,
64
+ 'services',
65
+ ...folder,
66
+ `${fileName}.schema`
67
+ ])
68
+ )
69
+ )
70
+ )
@@ -1,2 +1,3 @@
1
1
  import { ServiceGeneratorContext } from '../index';
2
+ export declare const template: ({ camelName, authentication, isEntityService, path, className, relative, schema, fileName }: ServiceGeneratorContext) => string;
2
3
  export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -1,26 +1,79 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = 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 = ({ relative, path, className, camelName, fileName }) => `import type { Application } from '${relative}/declarations'
6
+ const template = ({ camelName, authentication, isEntityService, path, className, relative, schema, fileName }) => /* ts */ `
7
+ ${authentication || isEntityService ? `import { authenticate } from '@feathersjs/authentication'` : ''}
8
+ ${schema
9
+ ? `
10
+ import { hooks as schemaHooks } from '@feathersjs/schema'
11
+
12
+ import {
13
+ ${camelName}DataValidator,
14
+ ${camelName}QueryValidator,
15
+ ${camelName}Resolver,
16
+ ${camelName}DataResolver,
17
+ ${camelName}QueryResolver,
18
+ ${camelName}ExternalResolver
19
+ } from './${fileName}.schema'
20
+ `
21
+ : ''}
7
22
 
8
- import { ${className}, ${camelName}Hooks } from './${fileName}.class'
23
+ import type { Application } from '${relative}/declarations'
24
+ import { ${className}, getOptions } from './${fileName}.class'
9
25
 
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
- }
26
+ export * from './${fileName}.class'
27
+ ${schema ? `export * from './${fileName}.schema'` : ''}
14
28
 
29
+ // A configure function that registers the service and its hooks via \`app.configure\`
30
+ export const ${camelName} = (app: Application) => {
15
31
  // Register our service on the Feathers application
16
- app.use('${path}', new ${className}(options), {
32
+ app.use('${path}', new ${className}(getOptions(app)), {
17
33
  // A list of all methods this service exposes externally
18
34
  methods: ['find', 'get', 'create', 'update', 'patch', 'remove'],
19
35
  // You can add additional custom events to be sent to clients here
20
36
  events: []
21
37
  })
22
38
  // Initialize hooks
23
- app.service('${path}').hooks(${camelName}Hooks)
39
+ app.service('${path}').hooks({
40
+ around: {
41
+ all: [${authentication
42
+ ? `
43
+ authenticate('jwt'),`
44
+ : ''}
45
+ ]${isEntityService
46
+ ? `,
47
+ find: [ authenticate('jwt') ],
48
+ get: [ authenticate('jwt') ],
49
+ create: [],
50
+ update: [ authenticate('jwt') ],
51
+ patch: [ authenticate('jwt') ],
52
+ remove: [ authenticate('jwt') ]`
53
+ : ''}
54
+ },
55
+ before: {
56
+ all: [${schema
57
+ ? `
58
+ schemaHooks.validateQuery(${camelName}QueryValidator),
59
+ schemaHooks.validateData(${camelName}DataValidator),
60
+ schemaHooks.resolveQuery(${camelName}QueryResolver),
61
+ schemaHooks.resolveData(${camelName}DataResolver)
62
+ `
63
+ : ''}]
64
+ },
65
+ after: {
66
+ all: [${schema
67
+ ? `
68
+ schemaHooks.resolveResult(${camelName}Resolver),
69
+ schemaHooks.resolveExternal(${camelName}ExternalResolver)
70
+ `
71
+ : ''}]
72
+ },
73
+ error: {
74
+ all: []
75
+ }
76
+ })
24
77
  }
25
78
 
26
79
  // Add this service to the service type index
@@ -30,17 +83,16 @@ declare module '${relative}/declarations' {
30
83
  }
31
84
  }
32
85
  `;
33
- const importTemplate = ({ camelName, folder, fileName }) => `import { ${camelName} } from './${folder.join('/')}/${fileName}.service'`;
34
- const configureTemplate = ({ camelName }) => ` app.configure(${camelName})`;
86
+ exports.template = template;
35
87
  const toServiceIndex = (0, pinion_1.toFile)(({ lib }) => [lib, 'services', `index`]);
36
88
  const generate = (ctx) => (0, pinion_1.generator)(ctx)
37
- .then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
89
+ .then((0, commons_1.renderSource)(exports.template, (0, pinion_1.toFile)(({ lib, fileName, folder }) => [
38
90
  lib,
39
91
  'services',
40
92
  ...folder,
41
- `${fileName}.service`
93
+ `${fileName}`
42
94
  ])))
43
- .then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.prepend)(), toServiceIndex))
44
- .then((0, commons_1.injectSource)(configureTemplate, (0, pinion_1.after)('export const services'), toServiceIndex));
95
+ .then((0, commons_1.injectSource)(({ camelName, folder, fileName }) => `import { ${camelName} } from './${folder.join('/')}/${fileName}'`, (0, pinion_1.prepend)(), toServiceIndex))
96
+ .then((0, commons_1.injectSource)(({ camelName }) => ` app.configure(${camelName})`, (0, pinion_1.after)('export const services'), toServiceIndex));
45
97
  exports.generate = generate;
46
98
  //# sourceMappingURL=service.tpl.js.map