@feathersjs/generators 5.0.0-pre.35

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 (169) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +22 -0
  3. package/README.md +23 -0
  4. package/lib/app/index.d.ts +29 -0
  5. package/lib/app/index.js +146 -0
  6. package/lib/app/index.js.map +1 -0
  7. package/lib/app/index.ts +228 -0
  8. package/lib/app/static/.gitignore +121 -0
  9. package/lib/app/templates/app.test.tpl.d.ts +2 -0
  10. package/lib/app/templates/app.test.tpl.js +49 -0
  11. package/lib/app/templates/app.test.tpl.js.map +1 -0
  12. package/lib/app/templates/app.test.tpl.ts +50 -0
  13. package/lib/app/templates/app.tpl.d.ts +2 -0
  14. package/lib/app/templates/app.tpl.js +123 -0
  15. package/lib/app/templates/app.tpl.js.map +1 -0
  16. package/lib/app/templates/app.tpl.ts +138 -0
  17. package/lib/app/templates/channels.tpl.d.ts +2 -0
  18. package/lib/app/templates/channels.tpl.js +50 -0
  19. package/lib/app/templates/channels.tpl.js.map +1 -0
  20. package/lib/app/templates/channels.tpl.ts +56 -0
  21. package/lib/app/templates/client.test.tpl.d.ts +2 -0
  22. package/lib/app/templates/client.test.tpl.js +27 -0
  23. package/lib/app/templates/client.test.tpl.js.map +1 -0
  24. package/lib/app/templates/client.test.tpl.ts +26 -0
  25. package/lib/app/templates/client.tpl.d.ts +2 -0
  26. package/lib/app/templates/client.tpl.js +38 -0
  27. package/lib/app/templates/client.tpl.js.map +1 -0
  28. package/lib/app/templates/client.tpl.ts +45 -0
  29. package/lib/app/templates/configuration.tpl.d.ts +2 -0
  30. package/lib/app/templates/configuration.tpl.js +71 -0
  31. package/lib/app/templates/configuration.tpl.js.map +1 -0
  32. package/lib/app/templates/configuration.tpl.ts +82 -0
  33. package/lib/app/templates/declarations.tpl.d.ts +2 -0
  34. package/lib/app/templates/declarations.tpl.js +28 -0
  35. package/lib/app/templates/declarations.tpl.js.map +1 -0
  36. package/lib/app/templates/declarations.tpl.ts +37 -0
  37. package/lib/app/templates/index.html.tpl.d.ts +2 -0
  38. package/lib/app/templates/index.html.tpl.js +45 -0
  39. package/lib/app/templates/index.html.tpl.js.map +1 -0
  40. package/lib/app/templates/index.html.tpl.ts +44 -0
  41. package/lib/app/templates/index.tpl.d.ts +2 -0
  42. package/lib/app/templates/index.tpl.js +22 -0
  43. package/lib/app/templates/index.tpl.js.map +1 -0
  44. package/lib/app/templates/index.tpl.ts +26 -0
  45. package/lib/app/templates/logger.tpl.d.ts +3 -0
  46. package/lib/app/templates/logger.tpl.js +45 -0
  47. package/lib/app/templates/logger.tpl.js.map +1 -0
  48. package/lib/app/templates/logger.tpl.ts +56 -0
  49. package/lib/app/templates/package.json.tpl.d.ts +2 -0
  50. package/lib/app/templates/package.json.tpl.js +58 -0
  51. package/lib/app/templates/package.json.tpl.js.map +1 -0
  52. package/lib/app/templates/package.json.tpl.ts +71 -0
  53. package/lib/app/templates/prettierrc.tpl.d.ts +2 -0
  54. package/lib/app/templates/prettierrc.tpl.js +11 -0
  55. package/lib/app/templates/prettierrc.tpl.js.map +1 -0
  56. package/lib/app/templates/prettierrc.tpl.ts +14 -0
  57. package/lib/app/templates/readme.md.tpl.d.ts +2 -0
  58. package/lib/app/templates/readme.md.tpl.js +54 -0
  59. package/lib/app/templates/readme.md.tpl.js.map +1 -0
  60. package/lib/app/templates/readme.md.tpl.ts +57 -0
  61. package/lib/app/templates/services.tpl.d.ts +2 -0
  62. package/lib/app/templates/services.tpl.js +15 -0
  63. package/lib/app/templates/services.tpl.js.map +1 -0
  64. package/lib/app/templates/services.tpl.ts +20 -0
  65. package/lib/app/templates/tsconfig.json.tpl.d.ts +2 -0
  66. package/lib/app/templates/tsconfig.json.tpl.js +22 -0
  67. package/lib/app/templates/tsconfig.json.tpl.js.map +1 -0
  68. package/lib/app/templates/tsconfig.json.tpl.ts +28 -0
  69. package/lib/app/templates/validators.tpl.d.ts +2 -0
  70. package/lib/app/templates/validators.tpl.js +36 -0
  71. package/lib/app/templates/validators.tpl.js.map +1 -0
  72. package/lib/app/templates/validators.tpl.ts +40 -0
  73. package/lib/authentication/index.d.ts +73 -0
  74. package/lib/authentication/index.js +107 -0
  75. package/lib/authentication/index.js.map +1 -0
  76. package/lib/authentication/index.ts +126 -0
  77. package/lib/authentication/templates/authentication.tpl.d.ts +2 -0
  78. package/lib/authentication/templates/authentication.tpl.js +40 -0
  79. package/lib/authentication/templates/authentication.tpl.js.map +1 -0
  80. package/lib/authentication/templates/authentication.tpl.ts +51 -0
  81. package/lib/authentication/templates/client.test.tpl.d.ts +2 -0
  82. package/lib/authentication/templates/client.test.tpl.js +62 -0
  83. package/lib/authentication/templates/client.test.tpl.js.map +1 -0
  84. package/lib/authentication/templates/client.test.tpl.ts +74 -0
  85. package/lib/authentication/templates/config.tpl.d.ts +2 -0
  86. package/lib/authentication/templates/config.tpl.js +50 -0
  87. package/lib/authentication/templates/config.tpl.js.map +1 -0
  88. package/lib/authentication/templates/config.tpl.ts +57 -0
  89. package/lib/authentication/templates/declarations.tpl.d.ts +2 -0
  90. package/lib/authentication/templates/declarations.tpl.js +19 -0
  91. package/lib/authentication/templates/declarations.tpl.js.map +1 -0
  92. package/lib/authentication/templates/declarations.tpl.ts +34 -0
  93. package/lib/authentication/templates/knex.tpl.d.ts +2 -0
  94. package/lib/authentication/templates/knex.tpl.js +45 -0
  95. package/lib/authentication/templates/knex.tpl.js.map +1 -0
  96. package/lib/authentication/templates/knex.tpl.ts +62 -0
  97. package/lib/authentication/templates/schema.json.tpl.d.ts +2 -0
  98. package/lib/authentication/templates/schema.json.tpl.js +103 -0
  99. package/lib/authentication/templates/schema.json.tpl.js.map +1 -0
  100. package/lib/authentication/templates/schema.json.tpl.ts +124 -0
  101. package/lib/authentication/templates/schema.typebox.tpl.d.ts +3 -0
  102. package/lib/authentication/templates/schema.typebox.tpl.js +86 -0
  103. package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
  104. package/lib/authentication/templates/schema.typebox.tpl.ts +108 -0
  105. package/lib/commons.d.ts +150 -0
  106. package/lib/commons.js +198 -0
  107. package/lib/commons.js.map +1 -0
  108. package/lib/commons.ts +284 -0
  109. package/lib/connection/index.d.ts +55 -0
  110. package/lib/connection/index.js +88 -0
  111. package/lib/connection/index.js.map +1 -0
  112. package/lib/connection/index.ts +123 -0
  113. package/lib/connection/templates/knex.tpl.d.ts +2 -0
  114. package/lib/connection/templates/knex.tpl.js +48 -0
  115. package/lib/connection/templates/knex.tpl.js.map +1 -0
  116. package/lib/connection/templates/knex.tpl.ts +67 -0
  117. package/lib/connection/templates/mongodb.tpl.d.ts +2 -0
  118. package/lib/connection/templates/mongodb.tpl.js +34 -0
  119. package/lib/connection/templates/mongodb.tpl.js.map +1 -0
  120. package/lib/connection/templates/mongodb.tpl.ts +40 -0
  121. package/lib/hook/index.d.ts +22 -0
  122. package/lib/hook/index.js +43 -0
  123. package/lib/hook/index.js.map +1 -0
  124. package/lib/hook/index.ts +47 -0
  125. package/lib/hook/templates/hook.tpl.d.ts +2 -0
  126. package/lib/hook/templates/hook.tpl.js +22 -0
  127. package/lib/hook/templates/hook.tpl.js.map +1 -0
  128. package/lib/hook/templates/hook.tpl.ts +33 -0
  129. package/lib/index.d.ts +7 -0
  130. package/lib/index.js +37 -0
  131. package/lib/index.js.map +1 -0
  132. package/lib/index.ts +8 -0
  133. package/lib/service/index.d.ts +64 -0
  134. package/lib/service/index.js +116 -0
  135. package/lib/service/index.js.map +1 -0
  136. package/lib/service/index.ts +191 -0
  137. package/lib/service/templates/client.tpl.d.ts +2 -0
  138. package/lib/service/templates/client.tpl.js +30 -0
  139. package/lib/service/templates/client.tpl.js.map +1 -0
  140. package/lib/service/templates/client.tpl.ts +56 -0
  141. package/lib/service/templates/schema.json.tpl.d.ts +2 -0
  142. package/lib/service/templates/schema.json.tpl.js +83 -0
  143. package/lib/service/templates/schema.json.tpl.js.map +1 -0
  144. package/lib/service/templates/schema.json.tpl.ts +98 -0
  145. package/lib/service/templates/schema.typebox.tpl.d.ts +2 -0
  146. package/lib/service/templates/schema.typebox.tpl.js +61 -0
  147. package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
  148. package/lib/service/templates/schema.typebox.tpl.ts +76 -0
  149. package/lib/service/templates/service.tpl.d.ts +3 -0
  150. package/lib/service/templates/service.tpl.js +112 -0
  151. package/lib/service/templates/service.tpl.js.map +1 -0
  152. package/lib/service/templates/service.tpl.ts +152 -0
  153. package/lib/service/templates/test.tpl.d.ts +2 -0
  154. package/lib/service/templates/test.tpl.js +25 -0
  155. package/lib/service/templates/test.tpl.js.map +1 -0
  156. package/lib/service/templates/test.tpl.ts +33 -0
  157. package/lib/service/type/custom.tpl.d.ts +3 -0
  158. package/lib/service/type/custom.tpl.js +98 -0
  159. package/lib/service/type/custom.tpl.js.map +1 -0
  160. package/lib/service/type/custom.tpl.ts +109 -0
  161. package/lib/service/type/knex.tpl.d.ts +3 -0
  162. package/lib/service/type/knex.tpl.js +71 -0
  163. package/lib/service/type/knex.tpl.js.map +1 -0
  164. package/lib/service/type/knex.tpl.ts +92 -0
  165. package/lib/service/type/mongodb.tpl.d.ts +3 -0
  166. package/lib/service/type/mongodb.tpl.js +50 -0
  167. package/lib/service/type/mongodb.tpl.js.map +1 -0
  168. package/lib/service/type/mongodb.tpl.ts +62 -0
  169. package/package.json +89 -0
@@ -0,0 +1,191 @@
1
+ import _ from 'lodash'
2
+ import { generator, runGenerator, runGenerators, prompt } from '@feathershq/pinion'
3
+
4
+ import {
5
+ checkPreconditions,
6
+ FeathersBaseContext,
7
+ getDatabaseAdapter,
8
+ initializeBaseContext
9
+ } from '../commons'
10
+
11
+ export interface ServiceGeneratorContext extends FeathersBaseContext {
12
+ /**
13
+ * The chosen service name
14
+ */
15
+ name: string
16
+ /**
17
+ * The path the service is registered on
18
+ */
19
+ path: string
20
+ /**
21
+ * The list of subfolders this service is in
22
+ */
23
+ folder: string[]
24
+ /**
25
+ * The `camelCase` service name starting with a lowercase letter
26
+ */
27
+ camelName: string
28
+ /**
29
+ * The `CamelCase` service name starting with an uppercase letter
30
+ */
31
+ upperName: string
32
+ /**
33
+ * The service class name combined as `CamelCaseService`
34
+ */
35
+ className: string
36
+ /**
37
+ * A kebab-cased (filename friendly) version of the service name
38
+ */
39
+ kebabName: string
40
+ /**
41
+ * The actual filename (the last element of the path)
42
+ */
43
+ fileName: string
44
+ /**
45
+ * The kebab-cased name of the path. Will be used for e.g. database names
46
+ */
47
+ kebabPath: string
48
+ /**
49
+ * Indicates how many file paths we should go up to import other things (e.g. `../../`)
50
+ */
51
+ relative: string
52
+ /**
53
+ * The chosen service type
54
+ */
55
+ type: 'knex' | 'mongodb' | 'custom'
56
+ /**
57
+ * Which schema definition format to use
58
+ */
59
+ schema: 'typebox' | 'json' | false
60
+ /**
61
+ * Wether this service uses authentication
62
+ */
63
+ authentication: boolean
64
+ /**
65
+ * Set to true if this service is for an authentication entity
66
+ */
67
+ isEntityService?: boolean
68
+ }
69
+
70
+ /**
71
+ * Parameters the generator is called with
72
+ */
73
+ export type ServiceGeneratorArguments = FeathersBaseContext &
74
+ Partial<
75
+ Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>
76
+ >
77
+
78
+ export const generate = (ctx: ServiceGeneratorArguments) =>
79
+ generator(ctx)
80
+ .then(initializeBaseContext())
81
+ .then(checkPreconditions())
82
+ .then(
83
+ prompt<ServiceGeneratorArguments, ServiceGeneratorContext>(
84
+ ({ name, path, type, schema, authentication, isEntityService, feathers }) => [
85
+ {
86
+ name: 'name',
87
+ type: 'input',
88
+ when: !name,
89
+ message: 'What is the name of your service?',
90
+ validate: (input) => {
91
+ if (!input || input === 'authentication') {
92
+ return 'Invalid service name'
93
+ }
94
+
95
+ return true
96
+ }
97
+ },
98
+ {
99
+ name: 'path',
100
+ type: 'input',
101
+ when: !path,
102
+ message: 'Which path should the service be registered on?',
103
+ default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`,
104
+ validate: (input) => {
105
+ if (!input || input === 'authentication') {
106
+ return 'Invalid service path'
107
+ }
108
+
109
+ return true
110
+ }
111
+ },
112
+ {
113
+ name: 'authentication',
114
+ type: 'confirm',
115
+ when: authentication === undefined && !isEntityService,
116
+ message: 'Does this service require authentication?'
117
+ },
118
+ {
119
+ name: 'type',
120
+ type: 'list',
121
+ when: !type,
122
+ message: 'What kind of service is it?',
123
+ default: getDatabaseAdapter(feathers?.database),
124
+ choices: [
125
+ {
126
+ value: 'knex',
127
+ name: 'SQL'
128
+ },
129
+ {
130
+ value: 'mongodb',
131
+ name: 'MongoDB'
132
+ },
133
+ {
134
+ value: 'custom',
135
+ name: 'A custom service'
136
+ }
137
+ ]
138
+ },
139
+ {
140
+ name: 'schema',
141
+ type: 'list',
142
+ when: schema === undefined,
143
+ message: 'Which schema definition format do you want to use?',
144
+ default: feathers?.schema,
145
+ choices: [
146
+ {
147
+ value: 'typebox',
148
+ name: 'TypeBox'
149
+ },
150
+ {
151
+ value: 'json',
152
+ name: 'JSON schema'
153
+ },
154
+ {
155
+ value: false,
156
+ name: 'No schema'
157
+ }
158
+ ]
159
+ }
160
+ ]
161
+ )
162
+ )
163
+ .then(async (ctx): Promise<ServiceGeneratorContext> => {
164
+ const { name, path, type } = ctx
165
+ const kebabName = _.kebabCase(name)
166
+ const camelName = _.camelCase(name)
167
+ const upperName = _.upperFirst(camelName)
168
+ const className = `${upperName}Service`
169
+
170
+ const folder = path.split('/').filter((el) => el !== '')
171
+ const relative = ['', ...folder].map(() => '..').join('/')
172
+ const fileName = _.last(folder)
173
+ const kebabPath = _.kebabCase(path)
174
+
175
+ return {
176
+ name,
177
+ type,
178
+ path,
179
+ folder,
180
+ fileName,
181
+ upperName,
182
+ className,
183
+ kebabName,
184
+ camelName,
185
+ kebabPath,
186
+ relative,
187
+ ...ctx
188
+ }
189
+ })
190
+ .then(runGenerators<ServiceGeneratorContext>(__dirname, 'templates'))
191
+ .then(runGenerator<ServiceGeneratorContext>(__dirname, 'type', ({ type }) => `${type}.tpl`))
@@ -0,0 +1,2 @@
1
+ import { ServiceGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -0,0 +1,30 @@
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 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}'
12
+ export type {
13
+ ${upperName},
14
+ ${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]>
19
+ `;
20
+ const declarationTemplate = ({ path, upperName }) => ` '${path}': ${upperName}ClientService`;
21
+ const registrationTemplate = ({ camelName, path }) => ` client.use('${path}', connection.service('${path}'), {
22
+ methods: ${camelName}ServiceMethods
23
+ })`;
24
+ const toClientFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'client']);
25
+ const generate = async (ctx) => (0, pinion_1.generator)(ctx)
26
+ .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)));
29
+ exports.generate = generate;
30
+ //# sourceMappingURL=client.tpl.js.map
@@ -0,0 +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,EACoB,EAAE,EAAE,CAAC,QAAQ,CAAC;IACpC,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;qBACQ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ;;IAE7C,SAAS;IACT,SAAS;IACT,SAAS;;eAEE,SAAS;cACV,SAAS,wBAAwB,SAAS,GACtD,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,SAAS,SAAS,CAAC,CAAC,CAAC,EACtD,YAAY,SAAS;CACpB,CAAA;AAED,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAA2B,EAAE,EAAE,CAC3E,MAAM,IAAI,MAAM,SAAS,eAAe,CAAA;AAE1C,MAAM,oBAAoB,GAAG,CAAC,EAC5B,SAAS,EACT,IAAI,EACoB,EAAE,EAAE,CAAC,iBAAiB,IAAI,0BAA0B,IAAI;aACrE,SAAS;GACnB,CAAA;AAEH,MAAM,YAAY,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAA;AAE3E,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CAAC,IAAA,sBAAY,EAAC,oBAAoB,EAAE,IAAA,eAAM,EAAC,eAAe,CAAC,EAAE,YAAY,CAAC,CAAC;KAC/E,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,cAAK,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,CACjF,CACF;KACA,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,cAAK,EAAC,6CAA6C,CAAC,EAAE,YAAY,CAAC,EAChG,IAAA,sBAAY,EAAC,mBAAmB,EAAE,IAAA,cAAK,EAAC,+BAA+B,CAAC,EAAE,YAAY,CAAC,CACxF,CACF,CAAA;AAfQ,QAAA,QAAQ,YAehB"}
@@ -0,0 +1,56 @@
1
+ import { generator, toFile, when, after, before } from '@feathershq/pinion'
2
+ import { injectSource } from '../../commons'
3
+ import { ServiceGeneratorContext } from '../index'
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}'
18
+ export type {
19
+ ${upperName},
20
+ ${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]>
27
+ `
28
+
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
+ })`
38
+
39
+ const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
40
+
41
+ export const generate = async (ctx: ServiceGeneratorContext) =>
42
+ generator(ctx)
43
+ .then(injectSource(registrationTemplate, before('return client'), toClientFile))
44
+ .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)
55
+ )
56
+ )
@@ -0,0 +1,2 @@
1
+ import { ServiceGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -0,0 +1,83 @@
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, cwd, lib }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
7
+ import { resolve, getValidator, querySyntax } from '@feathersjs/schema'
8
+ import type { FromSchema } from '@feathersjs/schema'
9
+
10
+ import type { HookContext } from '${relative}/declarations'
11
+ import { dataValidator, queryValidator } from '${relative}/${(0, commons_1.fileExists)(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
12
+ }validators'
13
+
14
+ // Main data model schema
15
+ export const ${camelName}Schema = {
16
+ $id: '${upperName}',
17
+ type: 'object',
18
+ additionalProperties: false,
19
+ required: [ '${type === 'mongodb' ? '_id' : 'id'}', 'text' ],
20
+ properties: {
21
+ ${type === 'mongodb' ? '_id' : 'id'}: {
22
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
23
+ },
24
+ text: {
25
+ type: 'string'
26
+ }
27
+ }
28
+ } as const
29
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
30
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
31
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
32
+
33
+ // Schema for creating new data
34
+ export const ${camelName}DataSchema = {
35
+ $id: '${upperName}Data',
36
+ type: 'object',
37
+ additionalProperties: false,
38
+ required: [ 'text' ],
39
+ properties: {
40
+ text: {
41
+ type: 'string'
42
+ }
43
+ }
44
+ } as const
45
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
46
+ export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
47
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({})
48
+
49
+ // Schema for updating existing data
50
+ export const ${camelName}PatchSchema = {
51
+ $id: '${upperName}Patch',
52
+ type: 'object',
53
+ additionalProperties: false,
54
+ required: [],
55
+ properties: {
56
+ ...${camelName}Schema.properties
57
+ }
58
+ } as const
59
+ export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
60
+ export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
61
+ export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({})
62
+
63
+ // Schema for allowed query properties
64
+ export const ${camelName}QuerySchema = {
65
+ $id: '${upperName}Query',
66
+ type: 'object',
67
+ additionalProperties: false,
68
+ properties: {
69
+ ...querySyntax(${camelName}Schema.properties)
70
+ }
71
+ } as const
72
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
73
+ export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
74
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({})
75
+ `;
76
+ 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 }) => [
77
+ lib,
78
+ 'services',
79
+ ...folder,
80
+ `${fileName}.schema`
81
+ ]))));
82
+ exports.generate = generate;
83
+ //# 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,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,IAAA,oBAAU,EAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,6CAA6C;AACjG;;;eAGe,SAAS;UACd,SAAS;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;MAE5C,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;eACxB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;;;;;;;cAOzC,SAAS,wBAAwB,SAAS;eACzC,SAAS,sBAAsB,SAAS;eACxC,SAAS,8BAA8B,SAAS;;;eAGhD,SAAS;UACd,SAAS;;;;;;;;;;cAUL,SAAS,4BAA4B,SAAS;eAC7C,SAAS,gCAAgC,SAAS;eAClD,SAAS,0BAA0B,SAAS;;;eAG5C,SAAS;UACd,SAAS;;;;;SAKV,SAAS;;;cAGJ,SAAS,6BAA6B,SAAS;eAC9C,SAAS,iCAAiC,SAAS;eACnD,SAAS,2BAA2B,SAAS;;;eAG7C,SAAS;UACd,SAAS;;;;qBAIE,SAAS;;;cAGhB,SAAS,6BAA6B,SAAS;eAC9C,SAAS,iCAAiC,SAAS;eACnD,SAAS,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,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,98 @@
1
+ import { generator, toFile, when } from '@feathershq/pinion'
2
+ import { fileExists, renderSource } from '../../commons'
3
+ import { ServiceGeneratorContext } from '../index'
4
+
5
+ const template = ({
6
+ camelName,
7
+ upperName,
8
+ relative,
9
+ type,
10
+ cwd,
11
+ lib
12
+ }: ServiceGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
13
+ import { resolve, getValidator, querySyntax } from '@feathersjs/schema'
14
+ import type { FromSchema } from '@feathersjs/schema'
15
+
16
+ import type { HookContext } from '${relative}/declarations'
17
+ import { dataValidator, queryValidator } from '${relative}/${
18
+ fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
19
+ }validators'
20
+
21
+ // Main data model schema
22
+ export const ${camelName}Schema = {
23
+ $id: '${upperName}',
24
+ type: 'object',
25
+ additionalProperties: false,
26
+ required: [ '${type === 'mongodb' ? '_id' : 'id'}', 'text' ],
27
+ properties: {
28
+ ${type === 'mongodb' ? '_id' : 'id'}: {
29
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
30
+ },
31
+ text: {
32
+ type: 'string'
33
+ }
34
+ }
35
+ } as const
36
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
37
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
38
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
39
+
40
+ // Schema for creating new data
41
+ export const ${camelName}DataSchema = {
42
+ $id: '${upperName}Data',
43
+ type: 'object',
44
+ additionalProperties: false,
45
+ required: [ 'text' ],
46
+ properties: {
47
+ text: {
48
+ type: 'string'
49
+ }
50
+ }
51
+ } as const
52
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
53
+ export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
54
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({})
55
+
56
+ // Schema for updating existing data
57
+ export const ${camelName}PatchSchema = {
58
+ $id: '${upperName}Patch',
59
+ type: 'object',
60
+ additionalProperties: false,
61
+ required: [],
62
+ properties: {
63
+ ...${camelName}Schema.properties
64
+ }
65
+ } as const
66
+ export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
67
+ export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
68
+ export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({})
69
+
70
+ // Schema for allowed query properties
71
+ export const ${camelName}QuerySchema = {
72
+ $id: '${upperName}Query',
73
+ type: 'object',
74
+ additionalProperties: false,
75
+ properties: {
76
+ ...querySyntax(${camelName}Schema.properties)
77
+ }
78
+ } as const
79
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
80
+ export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
81
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({})
82
+ `
83
+
84
+ export const generate = (ctx: ServiceGeneratorContext) =>
85
+ generator(ctx).then(
86
+ when<ServiceGeneratorContext>(
87
+ ({ schema }) => schema === 'json',
88
+ renderSource(
89
+ template,
90
+ toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
91
+ lib,
92
+ 'services',
93
+ ...folder,
94
+ `${fileName}.schema`
95
+ ])
96
+ )
97
+ )
98
+ )
@@ -0,0 +1,2 @@
1
+ import { ServiceGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;
@@ -0,0 +1,61 @@
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, cwd, lib }) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
7
+ import { resolve } from '@feathersjs/schema'
8
+ import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox'
9
+ import type { Static } from '@feathersjs/typebox'
10
+
11
+ import type { HookContext } from '${relative}/declarations'
12
+ import { dataValidator, queryValidator } from '${relative}/${(0, commons_1.fileExists)(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
13
+ }validators'
14
+
15
+ // Main data model schema
16
+ export const ${camelName}Schema = Type.Object({
17
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
18
+ text: Type.String()
19
+ }, { $id: '${upperName}', additionalProperties: false })
20
+ export type ${upperName} = Static<typeof ${camelName}Schema>
21
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
22
+
23
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
24
+
25
+ // Schema for creating new entries
26
+ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, ['text'], {
27
+ $id: '${upperName}Data'
28
+ })
29
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
30
+ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
31
+ export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({})
32
+
33
+ // Schema for updating existing entries
34
+ export const ${camelName}PatchSchema = Type.Partial(${camelName}DataSchema, {
35
+ $id: '${upperName}Patch'
36
+ })
37
+ export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
38
+ export const ${camelName}PatchValidator = getDataValidator(${camelName}PatchSchema, dataValidator)
39
+ export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({})
40
+
41
+ // Schema for allowed query properties
42
+ export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, [
43
+ '${type === 'mongodb' ? '_id' : 'id'}', 'text'
44
+ ])
45
+ export const ${camelName}QuerySchema = Type.Intersect([
46
+ querySyntax(${camelName}QueryProperties),
47
+ // Add additional query properties here
48
+ Type.Object({}, { additionalProperties: false })
49
+ ], { additionalProperties: false })
50
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
51
+ export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
52
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({})
53
+ `;
54
+ 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 }) => [
55
+ lib,
56
+ 'services',
57
+ ...folder,
58
+ `${fileName}.schema`
59
+ ]))));
60
+ exports.generate = generate;
61
+ //# 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,2CAAwD;AAGxD,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACJ,GAAG,EACH,GAAG,EACqB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;oCAKJ,QAAQ;iDACK,QAAQ,IACvD,IAAA,oBAAU,EAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,6CAA6C;AACjG;;;eAGe,SAAS;MAClB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,mBAAmB;;eAEtD,SAAS;cACV,SAAS,oBAAoB,SAAS;eACrC,SAAS,sBAAsB,SAAS;;eAExC,SAAS,8BAA8B,SAAS;;;eAGhD,SAAS,0BAA0B,SAAS;UACjD,SAAS;;cAEL,SAAS,wBAAwB,SAAS;eACzC,SAAS,oCAAoC,SAAS;eACtD,SAAS,0BAA0B,SAAS;;;eAG5C,SAAS,8BAA8B,SAAS;UACrD,SAAS;;cAEL,SAAS,yBAAyB,SAAS;eAC1C,SAAS,qCAAqC,SAAS;eACvD,SAAS,2BAA2B,SAAS;;;eAG7C,SAAS,+BAA+B,SAAS;KAC3D,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;eAEvB,SAAS;gBACR,SAAS;;;;cAIX,SAAS,yBAAyB,SAAS;eAC1C,SAAS,iCAAiC,SAAS;eACnD,SAAS,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"}
@@ -0,0 +1,76 @@
1
+ import { generator, toFile, when } from '@feathershq/pinion'
2
+ import { fileExists, renderSource } from '../../commons'
3
+ import { ServiceGeneratorContext } from '../index'
4
+
5
+ const template = ({
6
+ camelName,
7
+ upperName,
8
+ relative,
9
+ type,
10
+ cwd,
11
+ lib
12
+ }: ServiceGeneratorContext) => /* ts */ `// // For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
13
+ import { resolve } from '@feathersjs/schema'
14
+ import { Type, getDataValidator, getValidator, querySyntax } from '@feathersjs/typebox'
15
+ import type { Static } from '@feathersjs/typebox'
16
+
17
+ import type { HookContext } from '${relative}/declarations'
18
+ import { dataValidator, queryValidator } from '${relative}/${
19
+ fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
20
+ }validators'
21
+
22
+ // Main data model schema
23
+ export const ${camelName}Schema = Type.Object({
24
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
25
+ text: Type.String()
26
+ }, { $id: '${upperName}', additionalProperties: false })
27
+ export type ${upperName} = Static<typeof ${camelName}Schema>
28
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
29
+
30
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({})
31
+
32
+ // Schema for creating new entries
33
+ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, ['text'], {
34
+ $id: '${upperName}Data'
35
+ })
36
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
37
+ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
38
+ export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({})
39
+
40
+ // Schema for updating existing entries
41
+ export const ${camelName}PatchSchema = Type.Partial(${camelName}DataSchema, {
42
+ $id: '${upperName}Patch'
43
+ })
44
+ export type ${upperName}Patch = Static<typeof ${camelName}PatchSchema>
45
+ export const ${camelName}PatchValidator = getDataValidator(${camelName}PatchSchema, dataValidator)
46
+ export const ${camelName}PatchResolver = resolve<${upperName}, HookContext>({})
47
+
48
+ // Schema for allowed query properties
49
+ export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, [
50
+ '${type === 'mongodb' ? '_id' : 'id'}', 'text'
51
+ ])
52
+ export const ${camelName}QuerySchema = Type.Intersect([
53
+ querySyntax(${camelName}QueryProperties),
54
+ // Add additional query properties here
55
+ Type.Object({}, { additionalProperties: false })
56
+ ], { additionalProperties: false })
57
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
58
+ export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
59
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({})
60
+ `
61
+
62
+ export const generate = (ctx: ServiceGeneratorContext) =>
63
+ generator(ctx).then(
64
+ when<ServiceGeneratorContext>(
65
+ ({ schema }) => schema === 'typebox',
66
+ renderSource(
67
+ template,
68
+ toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
69
+ lib,
70
+ 'services',
71
+ ...folder,
72
+ `${fileName}.schema`
73
+ ])
74
+ )
75
+ )
76
+ )
@@ -0,0 +1,3 @@
1
+ import { ServiceGeneratorContext } from '../index';
2
+ export declare const template: ({ camelName, authentication, isEntityService, path, className, relative, schema, fileName }: ServiceGeneratorContext) => string;
3
+ export declare const generate: (ctx: ServiceGeneratorContext) => Promise<ServiceGeneratorContext>;