@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,67 @@
1
+ import { generator, toFile, before, mergeJSON } from '@feathershq/pinion'
2
+ import { ConnectionGeneratorContext } from '../index'
3
+ import { injectSource, renderSource } from '../../commons'
4
+
5
+ const template = ({
6
+ database
7
+ }: ConnectionGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
8
+ import knex from 'knex'
9
+ import type { Knex } from 'knex'
10
+ import type { Application } from './declarations'
11
+
12
+ declare module './declarations' {
13
+ interface Configuration {
14
+ ${database}Client: Knex
15
+ }
16
+ }
17
+
18
+ export const ${database} = (app: Application) => {
19
+ const config = app.get('${database}')
20
+ const db = knex(config!)
21
+
22
+ app.set('${database}Client', db)
23
+ }
24
+ `
25
+
26
+ const knexfile = ({
27
+ lib,
28
+ language,
29
+ database
30
+ }: ConnectionGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
31
+ import { app } from './${lib}/app'
32
+
33
+ // Load our database connection info from the app configuration
34
+ const config = app.get('${database}')
35
+
36
+ ${language === 'js' ? 'export default config' : 'module.exports = config'}
37
+ `
38
+
39
+ const importTemplate = ({ database }: ConnectionGeneratorContext) =>
40
+ `import { ${database} } from './${database}'`
41
+ const configureTemplate = ({ database }: ConnectionGeneratorContext) => `app.configure(${database})`
42
+
43
+ const toAppFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'app'])
44
+
45
+ export const generate = (ctx: ConnectionGeneratorContext) =>
46
+ generator(ctx)
47
+ .then(
48
+ renderSource(
49
+ template,
50
+ toFile<ConnectionGeneratorContext>(({ lib, database }) => [lib, database])
51
+ )
52
+ )
53
+ .then(renderSource(knexfile, toFile('knexfile')))
54
+ .then(
55
+ mergeJSON<ConnectionGeneratorContext>(
56
+ {
57
+ scripts: {
58
+ migrate: 'knex migrate:latest',
59
+ 'migrate:make': 'knex migrate:make',
60
+ test: 'cross-env NODE_ENV=test npm run migrate && npm run mocha'
61
+ }
62
+ },
63
+ toFile('package.json')
64
+ )
65
+ )
66
+ .then(injectSource(importTemplate, before('import { services } from'), toAppFile))
67
+ .then(injectSource(configureTemplate, before('app.configure(services)'), toAppFile))
@@ -0,0 +1,2 @@
1
+ import { ConnectionGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: ConnectionGeneratorContext) => Promise<ConnectionGeneratorContext>;
@@ -0,0 +1,34 @@
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 = ({}) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
7
+ import { MongoClient } from 'mongodb'
8
+ import type { Db } from 'mongodb'
9
+ import type { Application } from './declarations'
10
+
11
+ declare module './declarations' {
12
+ interface Configuration {
13
+ mongodbClient: Promise<Db>
14
+ }
15
+ }
16
+
17
+ export const mongodb = (app: Application) => {
18
+ const connection = app.get('mongodb') as string
19
+ const database = new URL(connection).pathname.substring(1)
20
+ const mongoClient = MongoClient.connect(connection)
21
+ .then(client => client.db(database))
22
+
23
+ app.set('mongodbClient', mongoClient)
24
+ }
25
+ `;
26
+ const importTemplate = "import { mongodb } from './mongodb'";
27
+ const configureTemplate = 'app.configure(mongodb)';
28
+ const toAppFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'app']);
29
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
30
+ .then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib }) => lib, 'mongodb')))
31
+ .then((0, commons_1.injectSource)(importTemplate, (0, pinion_1.before)('import { services } from'), toAppFile))
32
+ .then((0, commons_1.injectSource)(configureTemplate, (0, pinion_1.before)('app.configure(services)'), toAppFile));
33
+ exports.generate = generate;
34
+ //# sourceMappingURL=mongodb.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/mongodb.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAE9D,2CAA0D;AAE1D,MAAM,QAAQ,GACZ,CAAC,EAA8B,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;CAmB9C,CAAA;AAED,MAAM,cAAc,GAAG,qCAAqC,CAAA;AAC5D,MAAM,iBAAiB,GAAG,wBAAwB,CAAA;AAClD,MAAM,SAAS,GAAG,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAExE,MAAM,QAAQ,GAAG,CAAC,GAA+B,EAAE,EAAE,CAC1D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,CAChE,CACF;KACA,IAAI,CAAC,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,eAAM,EAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC,CAAC;KACjF,IAAI,CAAC,IAAA,sBAAY,EAAC,iBAAiB,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAA;AAT3E,QAAA,QAAQ,YASmE"}
@@ -0,0 +1,40 @@
1
+ import { generator, toFile, before } from '@feathershq/pinion'
2
+ import { ConnectionGeneratorContext } from '../index'
3
+ import { injectSource, renderSource } from '../../commons'
4
+
5
+ const template =
6
+ ({}: ConnectionGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/databases.html
7
+ import { MongoClient } from 'mongodb'
8
+ import type { Db } from 'mongodb'
9
+ import type { Application } from './declarations'
10
+
11
+ declare module './declarations' {
12
+ interface Configuration {
13
+ mongodbClient: Promise<Db>
14
+ }
15
+ }
16
+
17
+ export const mongodb = (app: Application) => {
18
+ const connection = app.get('mongodb') as string
19
+ const database = new URL(connection).pathname.substring(1)
20
+ const mongoClient = MongoClient.connect(connection)
21
+ .then(client => client.db(database))
22
+
23
+ app.set('mongodbClient', mongoClient)
24
+ }
25
+ `
26
+
27
+ const importTemplate = "import { mongodb } from './mongodb'"
28
+ const configureTemplate = 'app.configure(mongodb)'
29
+ const toAppFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'app'])
30
+
31
+ export const generate = (ctx: ConnectionGeneratorContext) =>
32
+ generator(ctx)
33
+ .then(
34
+ renderSource(
35
+ template,
36
+ toFile<ConnectionGeneratorContext>(({ lib }) => lib, 'mongodb')
37
+ )
38
+ )
39
+ .then(injectSource(importTemplate, before('import { services } from'), toAppFile))
40
+ .then(injectSource(configureTemplate, before('app.configure(services)'), toAppFile))
@@ -0,0 +1,22 @@
1
+ import { FeathersBaseContext } from '../commons';
2
+ export interface HookGeneratorContext extends FeathersBaseContext {
3
+ name: string;
4
+ camelName: string;
5
+ kebabName: string;
6
+ type: 'regular' | 'around';
7
+ }
8
+ export declare const generate: (ctx: HookGeneratorContext) => Promise<{
9
+ kebabName: string;
10
+ camelName: string;
11
+ name: string;
12
+ type: 'regular' | 'around';
13
+ feathers: import("../commons").FeathersAppInfo;
14
+ pkg: import("../commons").AppPackageJson;
15
+ lib: string;
16
+ test: string;
17
+ language: "ts" | "js";
18
+ dependencyVersions?: import("../commons").DependencyVersions;
19
+ cwd: string;
20
+ _?: (string | number)[];
21
+ pinion: import("@feathershq/pinion").Configuration;
22
+ }>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generate = void 0;
7
+ const pinion_1 = require("@feathershq/pinion");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const commons_1 = require("../commons");
10
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
11
+ .then((0, commons_1.initializeBaseContext)())
12
+ .then((0, commons_1.checkPreconditions)())
13
+ .then((0, pinion_1.prompt)(({ type, name }) => [
14
+ {
15
+ type: 'input',
16
+ name: 'name',
17
+ message: 'What is the name of the hook?',
18
+ when: !name
19
+ },
20
+ {
21
+ name: 'type',
22
+ type: 'list',
23
+ when: !type,
24
+ message: 'What kind of hook is it?',
25
+ choices: [
26
+ { value: 'around', name: 'Around' },
27
+ { value: 'regular', name: 'Before, After or Error' }
28
+ ]
29
+ }
30
+ ]))
31
+ .then((ctx) => {
32
+ const { name } = ctx;
33
+ const kebabName = lodash_1.default.kebabCase(name);
34
+ const camelName = lodash_1.default.camelCase(name);
35
+ return {
36
+ ...ctx,
37
+ kebabName,
38
+ camelName
39
+ };
40
+ })
41
+ .then((0, pinion_1.runGenerators)(__dirname, 'templates'));
42
+ exports.generate = generate;
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hook/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAqE;AACrE,oDAAsB;AACtB,wCAA2F;AASpF,MAAM,QAAQ,GAAG,CAAC,GAAyB,EAAE,EAAE,CACpD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CAAC,IAAA,+BAAqB,GAAE,CAAC;KAC7B,IAAI,CAAC,IAAA,4BAAkB,GAAE,CAAC;KAC1B,IAAI,CACH,IAAA,eAAM,EAAuB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC/C;QACE,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,+BAA+B;QACxC,IAAI,EAAE,CAAC,IAAI;KACZ;IACD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,CAAC,IAAI;QACX,OAAO,EAAE,0BAA0B;QACnC,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;YACnC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,wBAAwB,EAAE;SACrD;KACF;CACF,CAAC,CACH;KACA,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IACZ,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;IACpB,MAAM,SAAS,GAAG,gBAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,SAAS,GAAG,gBAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAEnC,OAAO;QACL,GAAG,GAAG;QACN,SAAS;QACT,SAAS;KACV,CAAA;AACH,CAAC,CAAC;KACD,IAAI,CAAC,IAAA,sBAAa,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAA;AAnCnC,QAAA,QAAQ,YAmC2B"}
@@ -0,0 +1,47 @@
1
+ import { generator, prompt, runGenerators } from '@feathershq/pinion'
2
+ import _ from 'lodash'
3
+ import { checkPreconditions, FeathersBaseContext, initializeBaseContext } from '../commons'
4
+
5
+ export interface HookGeneratorContext extends FeathersBaseContext {
6
+ name: string
7
+ camelName: string
8
+ kebabName: string
9
+ type: 'regular' | 'around'
10
+ }
11
+
12
+ export const generate = (ctx: HookGeneratorContext) =>
13
+ generator(ctx)
14
+ .then(initializeBaseContext())
15
+ .then(checkPreconditions())
16
+ .then(
17
+ prompt<HookGeneratorContext>(({ type, name }) => [
18
+ {
19
+ type: 'input',
20
+ name: 'name',
21
+ message: 'What is the name of the hook?',
22
+ when: !name
23
+ },
24
+ {
25
+ name: 'type',
26
+ type: 'list',
27
+ when: !type,
28
+ message: 'What kind of hook is it?',
29
+ choices: [
30
+ { value: 'around', name: 'Around' },
31
+ { value: 'regular', name: 'Before, After or Error' }
32
+ ]
33
+ }
34
+ ])
35
+ )
36
+ .then((ctx) => {
37
+ const { name } = ctx
38
+ const kebabName = _.kebabCase(name)
39
+ const camelName = _.camelCase(name)
40
+
41
+ return {
42
+ ...ctx,
43
+ kebabName,
44
+ camelName
45
+ }
46
+ })
47
+ .then(runGenerators(__dirname, 'templates'))
@@ -0,0 +1,2 @@
1
+ import { HookGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: HookGeneratorContext) => Promise<HookGeneratorContext>;
@@ -0,0 +1,22 @@
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 aroundTemplate = ({ camelName, name }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
7
+ import type { HookContext, NextFunction } from '../declarations'
8
+
9
+ export const ${camelName} = async (context: HookContext, next: NextFunction) => {
10
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
11
+ await next()
12
+ }
13
+ `;
14
+ const regularTemplate = ({ camelName, name }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
15
+ import type { HookContext } from '../declarations'
16
+
17
+ export const ${camelName} = async (context: HookContext) => {
18
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
19
+ }`;
20
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)((ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)), (0, pinion_1.toFile)(({ lib, kebabName }) => [lib, 'hooks', kebabName])));
21
+ exports.generate = generate;
22
+ //# sourceMappingURL=hook.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.tpl.js","sourceRoot":"","sources":["../../../src/hook/templates/hook.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AAEtD,2CAA4C;AAE5C,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,IAAI,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;eAGtB,SAAS;+BACO,IAAI;;;CAGlC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,EACvB,SAAS,EACT,IAAI,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;eAGtB,SAAS;+BACO,IAAI;EACjC,CAAA;AAEK,MAAM,QAAQ,GAAG,CAAC,GAAyB,EAAE,EAAE,CACpD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,EAC7E,IAAA,eAAM,EAAuB,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAChF,CACF,CAAA;AANU,QAAA,QAAQ,YAMlB"}
@@ -0,0 +1,33 @@
1
+ import { generator, toFile } from '@feathershq/pinion'
2
+ import { HookGeneratorContext } from '../index'
3
+ import { renderSource } from '../../commons'
4
+
5
+ const aroundTemplate = ({
6
+ camelName,
7
+ name
8
+ }: HookGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
9
+ import type { HookContext, NextFunction } from '../declarations'
10
+
11
+ export const ${camelName} = async (context: HookContext, next: NextFunction) => {
12
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
13
+ await next()
14
+ }
15
+ `
16
+
17
+ const regularTemplate = ({
18
+ camelName,
19
+ name
20
+ }: HookGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
21
+ import type { HookContext } from '../declarations'
22
+
23
+ export const ${camelName} = async (context: HookContext) => {
24
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
25
+ }`
26
+
27
+ export const generate = (ctx: HookGeneratorContext) =>
28
+ generator(ctx).then(
29
+ renderSource(
30
+ (ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)),
31
+ toFile<HookGeneratorContext>(({ lib, kebabName }) => [lib, 'hooks', kebabName])
32
+ )
33
+ )
package/lib/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from '@feathershq/pinion';
2
+ export * from './commons';
3
+ export * as app from './app';
4
+ export * as authentication from './authentication';
5
+ export * as connection from './connection';
6
+ export * as hook from './hook';
7
+ export * as service from './service';
package/lib/index.js ADDED
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.service = exports.hook = exports.connection = exports.authentication = exports.app = void 0;
30
+ __exportStar(require("@feathershq/pinion"), exports);
31
+ __exportStar(require("./commons"), exports);
32
+ exports.app = __importStar(require("./app"));
33
+ exports.authentication = __importStar(require("./authentication"));
34
+ exports.connection = __importStar(require("./connection"));
35
+ exports.hook = __importStar(require("./hook"));
36
+ exports.service = __importStar(require("./service"));
37
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAkC;AAElC,4CAAyB;AACzB,6CAA4B;AAC5B,mEAAkD;AAClD,2DAA0C;AAC1C,+CAA8B;AAC9B,qDAAoC"}
package/lib/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from '@feathershq/pinion'
2
+
3
+ export * from './commons'
4
+ export * as app from './app'
5
+ export * as authentication from './authentication'
6
+ export * as connection from './connection'
7
+ export * as hook from './hook'
8
+ export * as service from './service'
@@ -0,0 +1,64 @@
1
+ import { FeathersBaseContext } from '../commons';
2
+ export interface ServiceGeneratorContext extends FeathersBaseContext {
3
+ /**
4
+ * The chosen service name
5
+ */
6
+ name: string;
7
+ /**
8
+ * The path the service is registered on
9
+ */
10
+ path: string;
11
+ /**
12
+ * The list of subfolders this service is in
13
+ */
14
+ folder: string[];
15
+ /**
16
+ * The `camelCase` service name starting with a lowercase letter
17
+ */
18
+ camelName: string;
19
+ /**
20
+ * The `CamelCase` service name starting with an uppercase letter
21
+ */
22
+ upperName: string;
23
+ /**
24
+ * The service class name combined as `CamelCaseService`
25
+ */
26
+ className: string;
27
+ /**
28
+ * A kebab-cased (filename friendly) version of the service name
29
+ */
30
+ kebabName: string;
31
+ /**
32
+ * The actual filename (the last element of the path)
33
+ */
34
+ fileName: string;
35
+ /**
36
+ * The kebab-cased name of the path. Will be used for e.g. database names
37
+ */
38
+ kebabPath: string;
39
+ /**
40
+ * Indicates how many file paths we should go up to import other things (e.g. `../../`)
41
+ */
42
+ relative: string;
43
+ /**
44
+ * The chosen service type
45
+ */
46
+ type: 'knex' | 'mongodb' | 'custom';
47
+ /**
48
+ * Which schema definition format to use
49
+ */
50
+ schema: 'typebox' | 'json' | false;
51
+ /**
52
+ * Wether this service uses authentication
53
+ */
54
+ authentication: boolean;
55
+ /**
56
+ * Set to true if this service is for an authentication entity
57
+ */
58
+ isEntityService?: boolean;
59
+ }
60
+ /**
61
+ * Parameters the generator is called with
62
+ */
63
+ export type ServiceGeneratorArguments = FeathersBaseContext & Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>>;
64
+ export declare const generate: (ctx: ServiceGeneratorArguments) => Promise<ServiceGeneratorContext>;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generate = void 0;
7
+ const lodash_1 = __importDefault(require("lodash"));
8
+ const pinion_1 = require("@feathershq/pinion");
9
+ const commons_1 = require("../commons");
10
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
11
+ .then((0, commons_1.initializeBaseContext)())
12
+ .then((0, commons_1.checkPreconditions)())
13
+ .then((0, pinion_1.prompt)(({ name, path, type, schema, authentication, isEntityService, feathers }) => [
14
+ {
15
+ name: 'name',
16
+ type: 'input',
17
+ when: !name,
18
+ message: 'What is the name of your service?',
19
+ validate: (input) => {
20
+ if (!input || input === 'authentication') {
21
+ return 'Invalid service name';
22
+ }
23
+ return true;
24
+ }
25
+ },
26
+ {
27
+ name: 'path',
28
+ type: 'input',
29
+ when: !path,
30
+ message: 'Which path should the service be registered on?',
31
+ default: (answers) => `${lodash_1.default.kebabCase(answers.name)}`,
32
+ validate: (input) => {
33
+ if (!input || input === 'authentication') {
34
+ return 'Invalid service path';
35
+ }
36
+ return true;
37
+ }
38
+ },
39
+ {
40
+ name: 'authentication',
41
+ type: 'confirm',
42
+ when: authentication === undefined && !isEntityService,
43
+ message: 'Does this service require authentication?'
44
+ },
45
+ {
46
+ name: 'type',
47
+ type: 'list',
48
+ when: !type,
49
+ message: 'What kind of service is it?',
50
+ default: (0, commons_1.getDatabaseAdapter)(feathers === null || feathers === void 0 ? void 0 : feathers.database),
51
+ choices: [
52
+ {
53
+ value: 'knex',
54
+ name: 'SQL'
55
+ },
56
+ {
57
+ value: 'mongodb',
58
+ name: 'MongoDB'
59
+ },
60
+ {
61
+ value: 'custom',
62
+ name: 'A custom service'
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ name: 'schema',
68
+ type: 'list',
69
+ when: schema === undefined,
70
+ message: 'Which schema definition format do you want to use?',
71
+ default: feathers === null || feathers === void 0 ? void 0 : feathers.schema,
72
+ choices: [
73
+ {
74
+ value: 'typebox',
75
+ name: 'TypeBox'
76
+ },
77
+ {
78
+ value: 'json',
79
+ name: 'JSON schema'
80
+ },
81
+ {
82
+ value: false,
83
+ name: 'No schema'
84
+ }
85
+ ]
86
+ }
87
+ ]))
88
+ .then(async (ctx) => {
89
+ const { name, path, type } = ctx;
90
+ const kebabName = lodash_1.default.kebabCase(name);
91
+ const camelName = lodash_1.default.camelCase(name);
92
+ const upperName = lodash_1.default.upperFirst(camelName);
93
+ const className = `${upperName}Service`;
94
+ const folder = path.split('/').filter((el) => el !== '');
95
+ const relative = ['', ...folder].map(() => '..').join('/');
96
+ const fileName = lodash_1.default.last(folder);
97
+ const kebabPath = lodash_1.default.kebabCase(path);
98
+ return {
99
+ name,
100
+ type,
101
+ path,
102
+ folder,
103
+ fileName,
104
+ upperName,
105
+ className,
106
+ kebabName,
107
+ camelName,
108
+ kebabPath,
109
+ relative,
110
+ ...ctx
111
+ };
112
+ })
113
+ .then((0, pinion_1.runGenerators)(__dirname, 'templates'))
114
+ .then((0, pinion_1.runGenerator)(__dirname, 'type', ({ type }) => `${type}.tpl`));
115
+ exports.generate = generate;
116
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAsB;AACtB,+CAAmF;AAEnF,wCAKmB;AAqEZ,MAAM,QAAQ,GAAG,CAAC,GAA8B,EAAE,EAAE,CACzD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CAAC,IAAA,+BAAqB,GAAE,CAAC;KAC7B,IAAI,CAAC,IAAA,4BAAkB,GAAE,CAAC;KAC1B,IAAI,CACH,IAAA,eAAM,EACJ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC3E;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,OAAO;Q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