@feathersjs/cli 5.0.0-pre.28 → 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 (155) hide show
  1. package/CHANGELOG.md +28 -28
  2. package/bin/feathers +3 -6
  3. package/lib/app/index.js +34 -11
  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 +24 -12
  10. package/lib/app/templates/app.tpl.js.map +1 -1
  11. package/lib/app/templates/app.tpl.ts +28 -14
  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 +3 -3
  16. package/lib/app/templates/client.tpl.js.map +1 -1
  17. package/lib/app/templates/client.tpl.ts +3 -4
  18. package/lib/app/templates/config.tpl.js +10 -1
  19. package/lib/app/templates/config.tpl.js.map +1 -1
  20. package/lib/app/templates/config.tpl.ts +10 -0
  21. package/lib/app/templates/declarations.tpl.js +3 -3
  22. package/lib/app/templates/declarations.tpl.js.map +1 -1
  23. package/lib/app/templates/declarations.tpl.ts +5 -4
  24. package/lib/app/templates/index.html.tpl.js +12 -52
  25. package/lib/app/templates/index.html.tpl.js.map +1 -1
  26. package/lib/app/templates/index.html.tpl.ts +12 -53
  27. package/lib/app/templates/index.tpl.js +1 -1
  28. package/lib/app/templates/index.tpl.js.map +1 -1
  29. package/lib/app/templates/index.tpl.ts +1 -2
  30. package/lib/app/templates/logger.tpl.js +1 -1
  31. package/lib/app/templates/logger.tpl.js.map +1 -1
  32. package/lib/app/templates/logger.tpl.ts +2 -2
  33. package/lib/app/templates/package.json.tpl.js +4 -3
  34. package/lib/app/templates/package.json.tpl.js.map +1 -1
  35. package/lib/app/templates/package.json.tpl.ts +5 -3
  36. package/lib/app/templates/readme.md.tpl.js +11 -7
  37. package/lib/app/templates/readme.md.tpl.js.map +1 -1
  38. package/lib/app/templates/readme.md.tpl.ts +15 -8
  39. package/lib/app/templates/{configuration.tpl.d.ts → schemas.tpl.d.ts} +0 -0
  40. package/lib/app/templates/schemas.tpl.js +76 -0
  41. package/lib/app/templates/schemas.tpl.js.map +1 -0
  42. package/lib/app/templates/schemas.tpl.ts +90 -0
  43. package/lib/app/templates/services.tpl.js +1 -1
  44. package/lib/app/templates/services.tpl.js.map +1 -1
  45. package/lib/app/templates/services.tpl.ts +1 -2
  46. package/lib/authentication/index.d.ts +4 -3
  47. package/lib/authentication/index.js +12 -3
  48. package/lib/authentication/index.js.map +1 -1
  49. package/lib/authentication/index.ts +23 -5
  50. package/lib/authentication/templates/authentication.tpl.js +4 -6
  51. package/lib/authentication/templates/authentication.tpl.js.map +1 -1
  52. package/lib/authentication/templates/authentication.tpl.ts +6 -9
  53. package/lib/authentication/templates/config.tpl.js +10 -6
  54. package/lib/authentication/templates/config.tpl.js.map +1 -1
  55. package/lib/authentication/templates/config.tpl.ts +40 -34
  56. package/lib/authentication/templates/declarations.tpl.js +3 -3
  57. package/lib/authentication/templates/declarations.tpl.js.map +1 -1
  58. package/lib/authentication/templates/declarations.tpl.ts +9 -4
  59. package/lib/authentication/templates/knex.tpl.js +5 -4
  60. package/lib/authentication/templates/knex.tpl.js.map +1 -1
  61. package/lib/authentication/templates/knex.tpl.ts +5 -4
  62. package/lib/authentication/templates/{user.resolver.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
  63. package/lib/authentication/templates/schema.json.tpl.js +92 -0
  64. package/lib/authentication/templates/schema.json.tpl.js.map +1 -0
  65. package/lib/authentication/templates/schema.json.tpl.ts +108 -0
  66. package/lib/authentication/templates/{user.schema.tpl.d.ts → schema.typebox.tpl.d.ts} +1 -0
  67. package/lib/authentication/templates/schema.typebox.tpl.js +79 -0
  68. package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
  69. package/lib/authentication/templates/schema.typebox.tpl.ts +94 -0
  70. package/lib/authentication/templates/test.tpl.js +2 -2
  71. package/lib/authentication/templates/test.tpl.js.map +1 -1
  72. package/lib/authentication/templates/test.tpl.ts +6 -3
  73. package/lib/cli.d.ts +6 -0
  74. package/lib/cli.js +75 -0
  75. package/lib/cli.js.map +1 -0
  76. package/lib/cli.ts +68 -0
  77. package/lib/commons.d.ts +14 -1
  78. package/lib/commons.js +24 -4
  79. package/lib/commons.js.map +1 -1
  80. package/lib/commons.ts +29 -1
  81. package/lib/connection/index.d.ts +5 -3
  82. package/lib/connection/index.js +5 -3
  83. package/lib/connection/index.js.map +1 -1
  84. package/lib/connection/index.ts +19 -5
  85. package/lib/connection/templates/knex.tpl.js +2 -12
  86. package/lib/connection/templates/knex.tpl.js.map +1 -1
  87. package/lib/connection/templates/knex.tpl.ts +6 -20
  88. package/lib/connection/templates/mongodb.tpl.js +1 -3
  89. package/lib/connection/templates/mongodb.tpl.js.map +1 -1
  90. package/lib/connection/templates/mongodb.tpl.ts +1 -12
  91. package/lib/hook/index.d.ts +1 -1
  92. package/lib/hook/index.js +3 -0
  93. package/lib/hook/index.js.map +1 -1
  94. package/lib/hook/index.ts +3 -1
  95. package/lib/hook/templates/hook.tpl.js +2 -3
  96. package/lib/hook/templates/hook.tpl.js.map +1 -1
  97. package/lib/hook/templates/hook.tpl.ts +5 -3
  98. package/lib/index.d.ts +2 -16
  99. package/lib/index.js +16 -24
  100. package/lib/index.js.map +1 -1
  101. package/lib/index.ts +2 -28
  102. package/lib/service/index.d.ts +10 -2
  103. package/lib/service/index.js +79 -41
  104. package/lib/service/index.js.map +1 -1
  105. package/lib/service/index.ts +54 -6
  106. package/lib/service/templates/client.tpl.js +26 -6
  107. package/lib/service/templates/client.tpl.js.map +1 -1
  108. package/lib/service/templates/client.tpl.ts +41 -12
  109. package/lib/service/templates/{class.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
  110. package/lib/service/templates/schema.json.tpl.js +73 -0
  111. package/lib/service/templates/schema.json.tpl.js.map +1 -0
  112. package/lib/service/templates/schema.json.tpl.ts +85 -0
  113. package/lib/service/templates/{resolver.tpl.d.ts → schema.typebox.tpl.d.ts} +0 -0
  114. package/lib/service/templates/schema.typebox.tpl.js +58 -0
  115. package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
  116. package/lib/service/templates/schema.typebox.tpl.ts +70 -0
  117. package/lib/service/templates/service.tpl.d.ts +1 -0
  118. package/lib/service/templates/service.tpl.js +67 -15
  119. package/lib/service/templates/service.tpl.js.map +1 -1
  120. package/lib/service/templates/service.tpl.ts +98 -19
  121. package/lib/service/templates/test.tpl.js +1 -1
  122. package/lib/service/templates/test.tpl.js.map +1 -1
  123. package/lib/service/templates/test.tpl.ts +1 -2
  124. package/lib/service/type/custom.tpl.d.ts +1 -2
  125. package/lib/service/type/custom.tpl.js +32 -25
  126. package/lib/service/type/custom.tpl.js.map +1 -1
  127. package/lib/service/type/custom.tpl.ts +44 -35
  128. package/lib/service/type/knex.tpl.d.ts +1 -3
  129. package/lib/service/type/knex.tpl.js +33 -23
  130. package/lib/service/type/knex.tpl.js.map +1 -1
  131. package/lib/service/type/knex.tpl.ts +51 -29
  132. package/lib/service/type/mongodb.tpl.d.ts +1 -2
  133. package/lib/service/type/mongodb.tpl.js +30 -20
  134. package/lib/service/type/mongodb.tpl.js.map +1 -1
  135. package/lib/service/type/mongodb.tpl.ts +47 -29
  136. package/package.json +23 -24
  137. package/lib/app/templates/configuration.tpl.js +0 -39
  138. package/lib/app/templates/configuration.tpl.js.map +0 -1
  139. package/lib/app/templates/configuration.tpl.ts +0 -44
  140. package/lib/authentication/templates/user.resolver.tpl.js +0 -98
  141. package/lib/authentication/templates/user.resolver.tpl.js.map +0 -1
  142. package/lib/authentication/templates/user.resolver.tpl.ts +0 -111
  143. package/lib/authentication/templates/user.schema.tpl.js +0 -79
  144. package/lib/authentication/templates/user.schema.tpl.js.map +0 -1
  145. package/lib/authentication/templates/user.schema.tpl.ts +0 -87
  146. package/lib/service/templates/class.tpl.js +0 -63
  147. package/lib/service/templates/class.tpl.js.map +0 -1
  148. package/lib/service/templates/class.tpl.ts +0 -79
  149. package/lib/service/templates/resolver.tpl.js +0 -73
  150. package/lib/service/templates/resolver.tpl.js.map +0 -1
  151. package/lib/service/templates/resolver.tpl.ts +0 -78
  152. package/lib/service/templates/schema.tpl.d.ts +0 -2
  153. package/lib/service/templates/schema.tpl.js +0 -75
  154. package/lib/service/templates/schema.tpl.js.map +0 -1
  155. package/lib/service/templates/schema.tpl.ts +0 -80
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
4
  const pinion_1 = require("@feathershq/pinion");
5
- const importTemplate = ({ upperName, folder, fileName }) => `import { ${upperName}Result } from './services/${folder.join('/')}/${fileName}.schema'
5
+ const importTemplate = ({ upperName, folder, fileName }) => /* ts */ `import { ${upperName} } from './services/${folder.join('/')}/${fileName}.schema'
6
6
  `;
7
- const paramsTemplate = ({ entity, upperName }) => `// Add the ${entity} as an optional property to all params
7
+ const paramsTemplate = ({ entity, upperName }) => /* ts */ `// Add the ${entity} as an optional property to all params
8
8
  declare module '@feathersjs/feathers' {
9
9
  interface Params {
10
- ${entity}?: ${upperName}Result
10
+ ${entity}?: ${upperName}
11
11
  }
12
12
  }
13
13
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"declarations.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/declarations.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAoF;AAGpF,MAAM,cAAc,GAAG,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CACzF,YAAY,SAAS,6BAA6B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ;CAC/E,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,EACtB,MAAM,EACN,SAAS,EACsB,EAAE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,CAAC,CAAA;AAE9F,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,eAAM,EAAC,cAAc,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,iBAAiB,CAAC,CAC7E,CACF;KACA,IAAI,CAAC,IAAA,aAAI,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAAE,IAAA,eAAM,EAAC,cAAc,EAAE,IAAA,eAAM,GAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;AARvF,QAAA,QAAQ,YAQ+E"}
@@ -1,17 +1,22 @@
1
1
  import { generator, inject, before, toFile, when, append } from '@feathershq/pinion'
2
2
  import { AuthenticationGeneratorContext } from '../index'
3
3
 
4
- const importTemplate = ({ upperName, folder, fileName }: AuthenticationGeneratorContext) =>
5
- `import { ${upperName}Result } from './services/${folder.join('/')}/${fileName}.schema'
4
+ const importTemplate = ({
5
+ upperName,
6
+ folder,
7
+ fileName
8
+ }: AuthenticationGeneratorContext) => /* ts */ `import { ${upperName} } from './services/${folder.join(
9
+ '/'
10
+ )}/${fileName}.schema'
6
11
  `
7
12
 
8
13
  const paramsTemplate = ({
9
14
  entity,
10
15
  upperName
11
- }: AuthenticationGeneratorContext) => `// Add the ${entity} as an optional property to all params
16
+ }: AuthenticationGeneratorContext) => /* ts */ `// Add the ${entity} as an optional property to all params
12
17
  declare module '@feathersjs/feathers' {
13
18
  interface Params {
14
- ${entity}?: ${upperName}Result
19
+ ${entity}?: ${upperName}
15
20
  }
16
21
  }
17
22
  `
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
4
  const pinion_1 = require("@feathershq/pinion");
5
5
  const commons_1 = require("../../commons");
6
- const migrationTemplate = ({ kebabName, authStrategies }) => `import type { Knex } from 'knex'
6
+ const migrationTemplate = ({ kebabName, authStrategies }) => /* ts */ `import type { Knex } from 'knex'
7
7
 
8
8
  export async function up(knex: Knex): Promise<void> {
9
9
  await knex.schema.alterTable('${kebabName}', function (table) {
@@ -26,12 +26,13 @@ export async function down(knex: Knex): Promise<void> {
26
26
  table.dropColumn('email')
27
27
  table.dropColumn('password')`
28
28
  : `
29
- table.dropColumn('${name}Id')`)
30
- .join(',\n')}
29
+ table.dropColumn('${name}Id')
30
+ `)
31
+ .join('\n')}
31
32
  })
32
33
  }
33
34
  `;
34
- const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)((ctx) => (0, commons_1.getDatabaseAdapter)(ctx.feathers.database) === 'knex', (0, commons_1.renderSource)(migrationTemplate, (0, pinion_1.toFile)((0, pinion_1.toFile)('migrations', () => {
35
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)((ctx) => { var _a; return (0, commons_1.getDatabaseAdapter)((_a = ctx.feathers) === null || _a === void 0 ? void 0 : _a.database) === 'knex'; }, (0, commons_1.renderSource)(migrationTemplate, (0, pinion_1.toFile)((0, pinion_1.toFile)('migrations', () => {
35
36
  // Probably not great but it works to align with the Knex migration file format
36
37
  // We add 2 seconds so that the migrations run in the correct order
37
38
  const migrationDate = new Date(Date.now() + 2000)
@@ -1 +1 @@
1
- {"version":3,"file":"knex.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/knex.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAAgE;AAGhE,MAAM,iBAAiB,GAAG,CAAC,EACzB,SAAS,EACT,cAAc,EACiB,EAAE,EAAE,CAAC;;;kCAGJ,SAAS;8BACb,cAAc;KACrC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;;6BAEiB;IACnB,CAAC,CAAC;oBACQ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d,CAAC,CAAC;;6BAEiB;IACnB,CAAC,CAAC;oBACQ,IAAI,MAAM,CACvB;KACA,IAAI,CAAC,IAAI,CAAC;;;;;kCAKiB,SAAS;0BACjB,cAAc;KACjC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;;iCAEqB;IACvB,CAAC,CAAC;wBACY,IAAI;KACvB,CACE;KACA,IAAI,CAAC,IAAI,CAAC;;;CAGhB,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,WAAC,OAAA,IAAA,4BAAkB,EAAC,MAAA,GAAG,CAAC,QAAQ,0CAAE,QAAQ,CAAC,KAAK,MAAM,CAAA,EAAA,EAC9D,IAAA,sBAAY,EACV,iBAAiB,EACjB,IAAA,eAAM,EACJ,IAAA,eAAM,EAAiC,YAAY,EAAE,GAAG,EAAE;IACxD,+EAA+E;IAC/E,mEAAmE;IACnE,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;SAC9C,WAAW,EAAE;SACb,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;SAClB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEnB,OAAO,GAAG,aAAa,iBAAiB,CAAA;AAC1C,CAAC,CAAC,CACH,CACF,CACF,CACF,CAAA;AApBU,QAAA,QAAQ,YAoBlB"}
@@ -5,7 +5,7 @@ import { AuthenticationGeneratorContext } from '../index'
5
5
  const migrationTemplate = ({
6
6
  kebabName,
7
7
  authStrategies
8
- }: AuthenticationGeneratorContext) => `import type { Knex } from 'knex'
8
+ }: AuthenticationGeneratorContext) => /* ts */ `import type { Knex } from 'knex'
9
9
 
10
10
  export async function up(knex: Knex): Promise<void> {
11
11
  await knex.schema.alterTable('${kebabName}', function (table) {
@@ -31,9 +31,10 @@ export async function down(knex: Knex): Promise<void> {
31
31
  table.dropColumn('email')
32
32
  table.dropColumn('password')`
33
33
  : `
34
- table.dropColumn('${name}Id')`
34
+ table.dropColumn('${name}Id')
35
+ `
35
36
  )
36
- .join(',\n')}
37
+ .join('\n')}
37
38
  })
38
39
  }
39
40
  `
@@ -41,7 +42,7 @@ export async function down(knex: Knex): Promise<void> {
41
42
  export const generate = (ctx: AuthenticationGeneratorContext) =>
42
43
  generator(ctx).then(
43
44
  when(
44
- (ctx) => getDatabaseAdapter(ctx.feathers.database) === 'knex',
45
+ (ctx) => getDatabaseAdapter(ctx.feathers?.database) === 'knex',
45
46
  renderSource(
46
47
  migrationTemplate,
47
48
  toFile(
@@ -0,0 +1,92 @@
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, authStrategies, type, relative }) => /* ts */ `import { resolve, jsonSchema } from '@feathersjs/schema'
7
+ import type { FromSchema } from '@feathersjs/schema'
8
+ ${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
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 = {
15
+ $id: '${upperName}Data',
16
+ type: 'object',
17
+ additionalProperties: false,
18
+ required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
19
+ properties: {
20
+ ${authStrategies
21
+ .map((name) => name === 'local'
22
+ ? ` email: { type: 'string' },
23
+ password: { type: 'string' }`
24
+ : ` ${name}Id: { type: 'string' }`)
25
+ .join(',\n')}
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
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
33
+ }
34
+ })
35
+
36
+ // Schema for the data that is being returned
37
+ export const ${camelName}Schema = {
38
+ $id: '${upperName}',
39
+ type: 'object',
40
+ additionalProperties: false,
41
+ required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
42
+ properties: {
43
+ ...${camelName}DataSchema.properties,
44
+ ${type === 'mongodb' ? '_id' : 'id'}: {
45
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
46
+ }
47
+ }
48
+ } as const
49
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
50
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
51
+ properties: {}
52
+ })
53
+
54
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
55
+ properties: {
56
+ // The password should never be visible externally
57
+ password: async () => undefined
58
+ }
59
+ })
60
+
61
+ // Schema for allowed query properties
62
+ export const ${camelName}QuerySchema = {
63
+ $id: '${upperName}Query',
64
+ type: 'object',
65
+ additionalProperties: false,
66
+ properties: {
67
+ ...jsonSchema.querySyntax(${camelName}Schema.properties)
68
+ }
69
+ } as const
70
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
71
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
72
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
73
+ properties: {
74
+ // If there is a user (e.g. with authentication), they are only allowed to see their own data
75
+ ${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
76
+ if (context.params.user) {
77
+ return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
78
+ }
79
+
80
+ return value
81
+ }
82
+ }
83
+ })
84
+ `;
85
+ 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 }) => [
86
+ lib,
87
+ 'services',
88
+ ...folder,
89
+ `${fileName}.schema`
90
+ ]), { force: true })));
91
+ exports.generate = generate;
92
+ //# sourceMappingURL=schema.json.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;EAE7C,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;;oCAEvE,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;UACd,SAAS;;;gBAGH,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;;MAE3D,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;iCACqB;IACvB,CAAC,CAAC,OAAO,IAAI,wBAAwB,CACxC;KACA,IAAI,CAAC,KAAK,CAAC;;;cAGJ,SAAS,4BAA4B,SAAS;eAC7C,SAAS,+CAA+C,SAAS;eACjE,SAAS,0BAA0B,SAAS;;MAErD,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,EAAE;;;;;eAK9E,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;;;;eAIxC,SAAS,8BAA8B,SAAS;;;;;;;;eAQhD,SAAS;UACd,SAAS;;;;gCAIa,SAAS;;;cAG3B,SAAS,6BAA6B,SAAS;eAC9C,SAAS,4CAA4C,SAAS;eAC9D,SAAS,2BAA2B,SAAS;;;MAGtD,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;qCAEF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;;;;;;CAOrE,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,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,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CACF,CAAA;AAfU,QAAA,QAAQ,YAelB"}
@@ -0,0 +1,108 @@
1
+ import { generator, toFile, when } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
+ import { AuthenticationGeneratorContext } from '../index'
4
+
5
+ const template = ({
6
+ camelName,
7
+ upperName,
8
+ authStrategies,
9
+ type,
10
+ relative
11
+ }: AuthenticationGeneratorContext) => /* ts */ `import { resolve, jsonSchema } from '@feathersjs/schema'
12
+ import type { FromSchema } from '@feathersjs/schema'
13
+ ${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
14
+
15
+ import type { HookContext } from '${relative}/declarations'
16
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
17
+
18
+ // Schema for the basic data model (e.g. creating new entries)
19
+ export const ${camelName}DataSchema = {
20
+ $id: '${upperName}Data',
21
+ type: 'object',
22
+ additionalProperties: false,
23
+ required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
24
+ properties: {
25
+ ${authStrategies
26
+ .map((name) =>
27
+ name === 'local'
28
+ ? ` email: { type: 'string' },
29
+ password: { type: 'string' }`
30
+ : ` ${name}Id: { type: 'string' }`
31
+ )
32
+ .join(',\n')}
33
+ }
34
+ } as const
35
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
36
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
37
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
38
+ properties: {
39
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
40
+ }
41
+ })
42
+
43
+ // Schema for the data that is being returned
44
+ export const ${camelName}Schema = {
45
+ $id: '${upperName}',
46
+ type: 'object',
47
+ additionalProperties: false,
48
+ required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
49
+ properties: {
50
+ ...${camelName}DataSchema.properties,
51
+ ${type === 'mongodb' ? '_id' : 'id'}: {
52
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
53
+ }
54
+ }
55
+ } as const
56
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
57
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
58
+ properties: {}
59
+ })
60
+
61
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
62
+ properties: {
63
+ // The password should never be visible externally
64
+ password: async () => undefined
65
+ }
66
+ })
67
+
68
+ // Schema for allowed query properties
69
+ export const ${camelName}QuerySchema = {
70
+ $id: '${upperName}Query',
71
+ type: 'object',
72
+ additionalProperties: false,
73
+ properties: {
74
+ ...jsonSchema.querySyntax(${camelName}Schema.properties)
75
+ }
76
+ } as const
77
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
78
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
79
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
80
+ properties: {
81
+ // If there is a user (e.g. with authentication), they are only allowed to see their own data
82
+ ${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
83
+ if (context.params.user) {
84
+ return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
85
+ }
86
+
87
+ return value
88
+ }
89
+ }
90
+ })
91
+ `
92
+
93
+ export const generate = (ctx: AuthenticationGeneratorContext) =>
94
+ generator(ctx).then(
95
+ when<AuthenticationGeneratorContext>(
96
+ ({ schema }) => schema === 'json',
97
+ renderSource(
98
+ template,
99
+ toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
100
+ lib,
101
+ 'services',
102
+ ...folder,
103
+ `${fileName}.schema`
104
+ ]),
105
+ { force: true }
106
+ )
107
+ )
108
+ )
@@ -1,2 +1,3 @@
1
1
  import { AuthenticationGeneratorContext } from '../index';
2
+ export declare const template: ({ camelName, upperName, authStrategies, type, relative }: AuthenticationGeneratorContext) => string;
2
3
  export declare const generate: (ctx: AuthenticationGeneratorContext) => Promise<AuthenticationGeneratorContext>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = exports.template = void 0;
4
+ const pinion_1 = require("@feathershq/pinion");
5
+ const commons_1 = require("../../commons");
6
+ const template = ({ camelName, upperName, authStrategies, type, relative }) => /* ts */ `import { jsonSchema, resolve } from '@feathersjs/schema'
7
+ import { Type, querySyntax } from '@feathersjs/typebox'
8
+ import type { Static } from '@feathersjs/typebox'
9
+ ${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
10
+
11
+ import type { HookContext } from '${relative}/declarations'
12
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
13
+
14
+ // Schema for the basic data model (e.g. creating new entries)
15
+ export const ${camelName}DataSchema = Type.Object({
16
+ ${authStrategies
17
+ .map((name) => name === 'local'
18
+ ? ` email: Type.String(),
19
+ password: Type.String()`
20
+ : ` ${name}Id: Type.Optional(Type.String())`)
21
+ .join(',\n')}
22
+ }, { $id: '${upperName}Data', additionalProperties: false })
23
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
24
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
25
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
26
+ properties: {
27
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
28
+ }
29
+ })
30
+
31
+ // Schema for the data that is being returned
32
+ export const ${camelName}Schema = Type.Intersect([
33
+ ${camelName}DataSchema,
34
+ Type.Object({
35
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'}
36
+ })
37
+ ], { $id: '${upperName}' })
38
+ export type ${upperName} = Static<typeof ${camelName}Schema>
39
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
40
+ properties: {}
41
+ })
42
+
43
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
44
+ properties: {
45
+ // The password should never be visible externally
46
+ password: async () => undefined
47
+ }
48
+ })
49
+
50
+ // Schema for allowed query properties
51
+ export const ${camelName}QuerySchema = Type.Intersect([
52
+ querySyntax(${camelName}Schema),
53
+ // Add additional query properties here
54
+ Type.Object({})
55
+ ])
56
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
57
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
58
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
59
+ properties: {
60
+ // If there is a user (e.g. with authentication), they are only allowed to see their own data
61
+ ${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
62
+ if (context.params.user) {
63
+ return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
64
+ }
65
+
66
+ return value
67
+ }
68
+ }
69
+ })
70
+ `;
71
+ exports.template = template;
72
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)(({ schema }) => schema === 'typebox', (0, commons_1.renderSource)(exports.template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
73
+ lib,
74
+ 'services',
75
+ ...folder,
76
+ `${fileName}.schema`
77
+ ]), { force: true })));
78
+ exports.generate = generate;
79
+ //# sourceMappingURL=schema.typebox.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.typebox.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.typebox.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAGrC,MAAM,QAAQ,GAAG,CAAC,EACvB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;EAG7C,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;;oCAEvE,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;IACpB,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;0BACgB;IAClB,CAAC,CAAC,OAAO,IAAI,kCAAkC,CAClD;KACA,IAAI,CAAC,KAAK,CAAC;aACH,SAAS;cACR,SAAS,wBAAwB,SAAS;eACzC,SAAS,+CAA+C,SAAS;eACjE,SAAS,0BAA0B,SAAS;;MAErD,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,EAAE;;;;;eAK9E,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;;;;;;;;eAQhD,SAAS;gBACR,SAAS;;;;cAIX,SAAS,yBAAyB,SAAS;eAC1C,SAAS,4CAA4C,SAAS;eAC9D,SAAS,2BAA2B,SAAS;;;MAGtD,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;qCAEF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;;;;;;CAOrE,CAAA;AAxEY,QAAA,QAAQ,YAwEpB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,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,gBAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CACF,CAAA;AAfU,QAAA,QAAQ,YAelB"}
@@ -0,0 +1,94 @@
1
+ import { generator, toFile, when } from '@feathershq/pinion'
2
+ import { renderSource } from '../../commons'
3
+ import { AuthenticationGeneratorContext } from '../index'
4
+
5
+ export const template = ({
6
+ camelName,
7
+ upperName,
8
+ authStrategies,
9
+ type,
10
+ relative
11
+ }: AuthenticationGeneratorContext) => /* ts */ `import { jsonSchema, resolve } from '@feathersjs/schema'
12
+ import { Type, querySyntax } from '@feathersjs/typebox'
13
+ import type { Static } from '@feathersjs/typebox'
14
+ ${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
15
+
16
+ import type { HookContext } from '${relative}/declarations'
17
+ import { dataValidator, queryValidator } from '${relative}/schemas/validators'
18
+
19
+ // Schema for the basic data model (e.g. creating new entries)
20
+ export const ${camelName}DataSchema = Type.Object({
21
+ ${authStrategies
22
+ .map((name) =>
23
+ name === 'local'
24
+ ? ` email: Type.String(),
25
+ password: Type.String()`
26
+ : ` ${name}Id: Type.Optional(Type.String())`
27
+ )
28
+ .join(',\n')}
29
+ }, { $id: '${upperName}Data', additionalProperties: false })
30
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
31
+ export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
32
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
33
+ properties: {
34
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
35
+ }
36
+ })
37
+
38
+ // Schema for the data that is being returned
39
+ export const ${camelName}Schema = Type.Intersect([
40
+ ${camelName}DataSchema,
41
+ Type.Object({
42
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'}
43
+ })
44
+ ], { $id: '${upperName}' })
45
+ export type ${upperName} = Static<typeof ${camelName}Schema>
46
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
47
+ properties: {}
48
+ })
49
+
50
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
51
+ properties: {
52
+ // The password should never be visible externally
53
+ password: async () => undefined
54
+ }
55
+ })
56
+
57
+ // Schema for allowed query properties
58
+ export const ${camelName}QuerySchema = Type.Intersect([
59
+ querySyntax(${camelName}Schema),
60
+ // Add additional query properties here
61
+ Type.Object({})
62
+ ])
63
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
64
+ export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
65
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
66
+ properties: {
67
+ // If there is a user (e.g. with authentication), they are only allowed to see their own data
68
+ ${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
69
+ if (context.params.user) {
70
+ return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
71
+ }
72
+
73
+ return value
74
+ }
75
+ }
76
+ })
77
+ `
78
+
79
+ export const generate = (ctx: AuthenticationGeneratorContext) =>
80
+ generator(ctx).then(
81
+ when<AuthenticationGeneratorContext>(
82
+ ({ schema }) => schema === 'typebox',
83
+ renderSource(
84
+ template,
85
+ toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
86
+ lib,
87
+ 'services',
88
+ ...folder,
89
+ `${fileName}.schema`
90
+ ]),
91
+ { force: true }
92
+ )
93
+ )
94
+ )
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generate = void 0;
4
4
  const pinion_1 = require("@feathershq/pinion");
5
5
  const commons_1 = require("../../commons");
6
- const template = ({ authStrategies, lib }) => `import assert from 'assert';
6
+ const template = ({ authStrategies, path, lib }) => /* ts */ `import assert from 'assert';
7
7
  import { app } from '../${lib}/app';
8
8
 
9
9
  describe('authentication', () => {
@@ -16,7 +16,7 @@ describe('authentication', () => {
16
16
 
17
17
  before(async () => {
18
18
  try {
19
- await app.service('users').create(userInfo)
19
+ await app.service('${path}').create(userInfo)
20
20
  } catch (error) {
21
21
  // Do nothing, it just means the user already exists and can be tested
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"file":"test.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,cAAc,EAAE,GAAG,EAAkC,EAAE,EAAE,CAC3E;0BACwB,GAAG;;;IAIzB,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC;IAC9B,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;KAsBH;IACC,CAAC,CAAC,EACN;;;;;;CAMD,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAiC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAClF,CACF,CAAA;AANU,QAAA,QAAQ,YAMlB"}
1
+ {"version":3,"file":"test.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACd,IAAI,EACJ,GAAG,EAC4B,EAAE,EAAE,CAAC,QAAQ,CAAC;0BACrB,GAAG;;;IAIzB,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC;IAC9B,CAAC,CAAC;;;;;;;;2BAQmB,IAAI;;;;;;;;;;;;;;KAc1B;IACC,CAAC,CAAC,EACN;;;;;;CAMD,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAiC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAClF,CACF,CAAA;AANU,QAAA,QAAQ,YAMlB"}
@@ -2,8 +2,11 @@ import { generator, toFile } from '@feathershq/pinion'
2
2
  import { renderSource } from '../../commons'
3
3
  import { AuthenticationGeneratorContext } from '../index'
4
4
 
5
- const template = ({ authStrategies, lib }: AuthenticationGeneratorContext) =>
6
- `import assert from 'assert';
5
+ const template = ({
6
+ authStrategies,
7
+ path,
8
+ lib
9
+ }: AuthenticationGeneratorContext) => /* ts */ `import assert from 'assert';
7
10
  import { app } from '../${lib}/app';
8
11
 
9
12
  describe('authentication', () => {
@@ -17,7 +20,7 @@ describe('authentication', () => {
17
20
 
18
21
  before(async () => {
19
22
  try {
20
- await app.service('users').create(userInfo)
23
+ await app.service('${path}').create(userInfo)
21
24
  } catch (error) {
22
25
  // Do nothing, it just means the user already exists and can be tested
23
26
  }
package/lib/cli.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import chalk from 'chalk';
2
+ import { Command } from 'commander';
3
+ export * from 'commander';
4
+ export { chalk };
5
+ export declare const commandRunner: (name: string) => (options: any) => Promise<void>;
6
+ export declare const program: Command;
package/lib/cli.js ADDED
@@ -0,0 +1,75 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.program = exports.commandRunner = exports.chalk = void 0;
21
+ const chalk_1 = __importDefault(require("chalk"));
22
+ exports.chalk = chalk_1.default;
23
+ const commander_1 = require("commander");
24
+ const pinion_1 = require("@feathershq/pinion");
25
+ const commons_1 = require("./commons");
26
+ __exportStar(require("commander"), exports);
27
+ const commandRunner = (name) => async (options) => {
28
+ const ctx = (0, pinion_1.getContext)({
29
+ ...options
30
+ });
31
+ await (0, pinion_1.generator)(ctx)
32
+ .then((0, pinion_1.runGenerator)(__dirname, name, 'index'))
33
+ .catch((error) => {
34
+ const { logger } = ctx.pinion;
35
+ logger.error(`Error: ${chalk_1.default.white(error.message)}`);
36
+ });
37
+ };
38
+ exports.commandRunner = commandRunner;
39
+ exports.program = new commander_1.Command();
40
+ exports.program
41
+ .name('feathers')
42
+ .description('The Feathers command line interface 🕊️')
43
+ .version(commons_1.version)
44
+ .showHelpAfterError();
45
+ const generate = exports.program.command('generate').alias('g');
46
+ generate
47
+ .command('app')
48
+ .description('Generate a new application')
49
+ .option('--name <name>', 'The name of the application')
50
+ .action((0, exports.commandRunner)('app'));
51
+ generate
52
+ .command('service')
53
+ .description('Generate a new service')
54
+ .option('--name <name>', 'The service name')
55
+ .option('--path <path>', 'The path to register the service on')
56
+ .option('--type <type>', 'The service type (knex, mongodb, custom)')
57
+ .action((0, exports.commandRunner)('service'));
58
+ generate
59
+ .command('hook')
60
+ .description('Generate a hook')
61
+ .option('--name <name>', 'The name of the hook')
62
+ .option('--type <type>', 'The hook type (around or regular)')
63
+ .action((0, exports.commandRunner)('hook'));
64
+ generate
65
+ .command('connection')
66
+ .description('Add a new database connection')
67
+ .action((0, exports.commandRunner)('connection'));
68
+ generate
69
+ .command('authentication')
70
+ .description('Add authentication to the application')
71
+ .action((0, exports.commandRunner)('authentication'));
72
+ generate.description(`Run a generator. Currently available: \n ${generate.commands
73
+ .map((cmd) => `${chalk_1.default.blue(cmd.name())}: ${cmd.description()} `)
74
+ .join('\n ')}`);
75
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kDAAyB;AAMhB,gBANF,eAAK,CAME;AALd,yCAAmC;AACnC,+CAAwE;AACxE,uCAAwD;AAExD,4CAAyB;AAGlB,MAAM,aAAa,GAAG,CAAC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