@feathersjs/cli 5.0.0-pre.29 → 5.0.0-pre.31

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 (163) hide show
  1. package/CHANGELOG.md +30 -37
  2. package/bin/feathers +3 -6
  3. package/lib/app/index.js +33 -10
  4. package/lib/app/index.js.map +1 -1
  5. package/lib/app/index.ts +88 -51
  6. package/lib/app/templates/app.test.tpl.js +1 -1
  7. package/lib/app/templates/app.test.tpl.js.map +1 -1
  8. package/lib/app/templates/app.test.tpl.ts +1 -2
  9. package/lib/app/templates/app.tpl.js +7 -7
  10. package/lib/app/templates/app.tpl.js.map +1 -1
  11. package/lib/app/templates/app.tpl.ts +7 -9
  12. package/lib/app/templates/channels.tpl.js +1 -1
  13. package/lib/app/templates/channels.tpl.js.map +1 -1
  14. package/lib/app/templates/channels.tpl.ts +1 -2
  15. package/lib/app/templates/{configuration.tpl.d.ts → client.test.tpl.d.ts} +0 -0
  16. package/lib/app/templates/client.test.tpl.js +27 -0
  17. package/lib/app/templates/client.test.tpl.js.map +1 -0
  18. package/lib/app/templates/client.test.tpl.ts +26 -0
  19. package/lib/app/templates/client.tpl.js +3 -3
  20. package/lib/app/templates/client.tpl.js.map +1 -1
  21. package/lib/app/templates/client.tpl.ts +3 -4
  22. package/lib/app/templates/declarations.tpl.js +3 -3
  23. package/lib/app/templates/declarations.tpl.js.map +1 -1
  24. package/lib/app/templates/declarations.tpl.ts +5 -4
  25. package/lib/app/templates/index.html.tpl.js +12 -52
  26. package/lib/app/templates/index.html.tpl.js.map +1 -1
  27. package/lib/app/templates/index.html.tpl.ts +12 -53
  28. package/lib/app/templates/index.tpl.js +1 -1
  29. package/lib/app/templates/index.tpl.js.map +1 -1
  30. package/lib/app/templates/index.tpl.ts +1 -2
  31. package/lib/app/templates/logger.tpl.js +9 -3
  32. package/lib/app/templates/logger.tpl.js.map +1 -1
  33. package/lib/app/templates/logger.tpl.ts +10 -4
  34. package/lib/app/templates/package.json.tpl.js +4 -3
  35. package/lib/app/templates/package.json.tpl.js.map +1 -1
  36. package/lib/app/templates/package.json.tpl.ts +5 -3
  37. package/lib/app/templates/readme.md.tpl.js +11 -7
  38. package/lib/app/templates/readme.md.tpl.js.map +1 -1
  39. package/lib/app/templates/readme.md.tpl.ts +15 -8
  40. package/lib/app/templates/schemas.tpl.d.ts +2 -0
  41. package/lib/app/templates/schemas.tpl.js +75 -0
  42. package/lib/app/templates/schemas.tpl.js.map +1 -0
  43. package/lib/app/templates/schemas.tpl.ts +89 -0
  44. package/lib/app/templates/services.tpl.js +1 -1
  45. package/lib/app/templates/services.tpl.js.map +1 -1
  46. package/lib/app/templates/services.tpl.ts +1 -2
  47. package/lib/authentication/index.d.ts +5 -3
  48. package/lib/authentication/index.js +12 -3
  49. package/lib/authentication/index.js.map +1 -1
  50. package/lib/authentication/index.ts +23 -5
  51. package/lib/authentication/templates/authentication.tpl.js +1 -1
  52. package/lib/authentication/templates/authentication.tpl.js.map +1 -1
  53. package/lib/authentication/templates/authentication.tpl.ts +3 -2
  54. package/lib/authentication/templates/{test.tpl.d.ts → client.test.tpl.d.ts} +0 -0
  55. package/lib/authentication/templates/client.test.tpl.js +66 -0
  56. package/lib/authentication/templates/client.test.tpl.js.map +1 -0
  57. package/lib/authentication/templates/client.test.tpl.ts +80 -0
  58. package/lib/{service/templates/schema.tpl.d.ts → authentication/templates/client.tpl.d.ts} +1 -1
  59. package/lib/authentication/templates/client.tpl.js +14 -0
  60. package/lib/authentication/templates/client.tpl.js.map +1 -0
  61. package/lib/authentication/templates/client.tpl.ts +19 -0
  62. package/lib/authentication/templates/config.tpl.js +1 -1
  63. package/lib/authentication/templates/config.tpl.js.map +1 -1
  64. package/lib/authentication/templates/config.tpl.ts +1 -1
  65. package/lib/authentication/templates/declarations.tpl.js +3 -3
  66. package/lib/authentication/templates/declarations.tpl.js.map +1 -1
  67. package/lib/authentication/templates/declarations.tpl.ts +9 -4
  68. package/lib/authentication/templates/knex.tpl.js +4 -4
  69. package/lib/authentication/templates/knex.tpl.js.map +1 -1
  70. package/lib/authentication/templates/knex.tpl.ts +5 -5
  71. package/lib/authentication/templates/{user.resolver.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
  72. package/lib/authentication/templates/schema.json.tpl.js +92 -0
  73. package/lib/authentication/templates/schema.json.tpl.js.map +1 -0
  74. package/lib/authentication/templates/schema.json.tpl.ts +108 -0
  75. package/lib/authentication/templates/{user.schema.tpl.d.ts → schema.typebox.tpl.d.ts} +1 -0
  76. package/lib/authentication/templates/schema.typebox.tpl.js +77 -0
  77. package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
  78. package/lib/authentication/templates/schema.typebox.tpl.ts +94 -0
  79. package/lib/cli.d.ts +6 -0
  80. package/lib/cli.js +75 -0
  81. package/lib/cli.js.map +1 -0
  82. package/lib/cli.ts +68 -0
  83. package/lib/commons.d.ts +14 -1
  84. package/lib/commons.js +24 -4
  85. package/lib/commons.js.map +1 -1
  86. package/lib/commons.ts +29 -1
  87. package/lib/connection/index.d.ts +5 -3
  88. package/lib/connection/index.js +5 -3
  89. package/lib/connection/index.js.map +1 -1
  90. package/lib/connection/index.ts +19 -5
  91. package/lib/connection/templates/knex.tpl.js +2 -12
  92. package/lib/connection/templates/knex.tpl.js.map +1 -1
  93. package/lib/connection/templates/knex.tpl.ts +6 -20
  94. package/lib/connection/templates/mongodb.tpl.js +1 -3
  95. package/lib/connection/templates/mongodb.tpl.js.map +1 -1
  96. package/lib/connection/templates/mongodb.tpl.ts +1 -12
  97. package/lib/hook/index.d.ts +1 -1
  98. package/lib/hook/index.js +3 -0
  99. package/lib/hook/index.js.map +1 -1
  100. package/lib/hook/index.ts +3 -1
  101. package/lib/hook/templates/hook.tpl.js +2 -3
  102. package/lib/hook/templates/hook.tpl.js.map +1 -1
  103. package/lib/hook/templates/hook.tpl.ts +5 -3
  104. package/lib/index.d.ts +2 -16
  105. package/lib/index.js +16 -24
  106. package/lib/index.js.map +1 -1
  107. package/lib/index.ts +2 -28
  108. package/lib/service/index.d.ts +10 -60
  109. package/lib/service/index.js +41 -4
  110. package/lib/service/index.js.map +1 -1
  111. package/lib/service/index.ts +61 -7
  112. package/lib/service/templates/client.tpl.js +21 -18
  113. package/lib/service/templates/client.tpl.js.map +1 -1
  114. package/lib/service/templates/client.tpl.ts +52 -24
  115. package/lib/service/templates/{class.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
  116. package/lib/service/templates/schema.json.tpl.js +75 -0
  117. package/lib/service/templates/schema.json.tpl.js.map +1 -0
  118. package/lib/service/templates/schema.json.tpl.ts +87 -0
  119. package/lib/service/templates/{resolver.tpl.d.ts → schema.typebox.tpl.d.ts} +0 -0
  120. package/lib/service/templates/schema.typebox.tpl.js +55 -0
  121. package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
  122. package/lib/service/templates/schema.typebox.tpl.ts +67 -0
  123. package/lib/service/templates/service.tpl.d.ts +1 -0
  124. package/lib/service/templates/service.tpl.js +67 -15
  125. package/lib/service/templates/service.tpl.js.map +1 -1
  126. package/lib/service/templates/service.tpl.ts +98 -19
  127. package/lib/service/templates/test.tpl.js +1 -1
  128. package/lib/service/templates/test.tpl.js.map +1 -1
  129. package/lib/service/templates/test.tpl.ts +1 -2
  130. package/lib/service/type/custom.tpl.d.ts +1 -2
  131. package/lib/service/type/custom.tpl.js +32 -25
  132. package/lib/service/type/custom.tpl.js.map +1 -1
  133. package/lib/service/type/custom.tpl.ts +44 -35
  134. package/lib/service/type/knex.tpl.d.ts +1 -3
  135. package/lib/service/type/knex.tpl.js +37 -25
  136. package/lib/service/type/knex.tpl.js.map +1 -1
  137. package/lib/service/type/knex.tpl.ts +54 -31
  138. package/lib/service/type/mongodb.tpl.d.ts +1 -2
  139. package/lib/service/type/mongodb.tpl.js +32 -20
  140. package/lib/service/type/mongodb.tpl.js.map +1 -1
  141. package/lib/service/type/mongodb.tpl.ts +49 -29
  142. package/package.json +24 -23
  143. package/lib/app/templates/configuration.tpl.js +0 -45
  144. package/lib/app/templates/configuration.tpl.js.map +0 -1
  145. package/lib/app/templates/configuration.tpl.ts +0 -50
  146. package/lib/authentication/templates/test.tpl.js +0 -43
  147. package/lib/authentication/templates/test.tpl.js.map +0 -1
  148. package/lib/authentication/templates/test.tpl.ts +0 -50
  149. package/lib/authentication/templates/user.resolver.tpl.js +0 -98
  150. package/lib/authentication/templates/user.resolver.tpl.js.map +0 -1
  151. package/lib/authentication/templates/user.resolver.tpl.ts +0 -111
  152. package/lib/authentication/templates/user.schema.tpl.js +0 -79
  153. package/lib/authentication/templates/user.schema.tpl.js.map +0 -1
  154. package/lib/authentication/templates/user.schema.tpl.ts +0 -87
  155. package/lib/service/templates/class.tpl.js +0 -63
  156. package/lib/service/templates/class.tpl.js.map +0 -1
  157. package/lib/service/templates/class.tpl.ts +0 -79
  158. package/lib/service/templates/resolver.tpl.js +0 -73
  159. package/lib/service/templates/resolver.tpl.js.map +0 -1
  160. package/lib/service/templates/resolver.tpl.ts +0 -78
  161. package/lib/service/templates/schema.tpl.js +0 -75
  162. package/lib/service/templates/schema.tpl.js.map +0 -1
  163. package/lib/service/templates/schema.tpl.ts +0 -80
@@ -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}'
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,10 +3,10 @@ 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 = ({ kebabPath, authStrategies }) => /* ts */ `import type { Knex } from 'knex'
7
7
 
8
8
  export async function up(knex: Knex): Promise<void> {
9
- await knex.schema.alterTable('${kebabName}', function (table) {
9
+ await knex.schema.alterTable('${kebabPath}', function (table) {
10
10
  table.dropColumn('text')${authStrategies
11
11
  .map((name) => name === 'local'
12
12
  ? `
@@ -19,7 +19,7 @@ export async function up(knex: Knex): Promise<void> {
19
19
  }
20
20
 
21
21
  export async function down(knex: Knex): Promise<void> {
22
- await knex.schema.alterTable('${kebabName}', function (table) {
22
+ await knex.schema.alterTable('${kebabPath}', function (table) {
23
23
  table.string('text')${authStrategies
24
24
  .map((name) => name === 'local'
25
25
  ? `
@@ -32,7 +32,7 @@ export async function down(knex: Knex): Promise<void> {
32
32
  })
33
33
  }
34
34
  `;
35
- 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', () => {
36
36
  // Probably not great but it works to align with the Knex migration file format
37
37
  // We add 2 seconds so that the migrations run in the correct order
38
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,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,CAAC,IAAA,4BAAkB,EAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,MAAM,EAC7D,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,C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AE,EAAE,CAAC,CAAA;IAEnB,OAAO,GAAG,aAAa,iBAAiB,CAAA;AAC1C,CAAC,CAAC,CACH,CACF,CACF,CACF,CAAA;AApBU,QAAA,QAAQ,YAoBlB"}
@@ -3,12 +3,12 @@ import { getDatabaseAdapter, renderSource } from '../../commons'
3
3
  import { AuthenticationGeneratorContext } from '../index'
4
4
 
5
5
  const migrationTemplate = ({
6
- kebabName,
6
+ kebabPath,
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
- await knex.schema.alterTable('${kebabName}', function (table) {
11
+ await knex.schema.alterTable('${kebabPath}', function (table) {
12
12
  table.dropColumn('text')${authStrategies
13
13
  .map((name) =>
14
14
  name === 'local'
@@ -23,7 +23,7 @@ export async function up(knex: Knex): Promise<void> {
23
23
  }
24
24
 
25
25
  export async function down(knex: Knex): Promise<void> {
26
- await knex.schema.alterTable('${kebabName}', function (table) {
26
+ await knex.schema.alterTable('${kebabPath}', function (table) {
27
27
  table.string('text')${authStrategies
28
28
  .map((name) =>
29
29
  name === 'local'
@@ -42,7 +42,7 @@ export async function down(knex: Knex): Promise<void> {
42
42
  export const generate = (ctx: AuthenticationGeneratorContext) =>
43
43
  generator(ctx).then(
44
44
  when(
45
- (ctx) => getDatabaseAdapter(ctx.feathers.database) === 'knex',
45
+ (ctx) => getDatabaseAdapter(ctx.feathers?.database) === 'knex',
46
46
  renderSource(
47
47
  migrationTemplate,
48
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, querySyntax, getValidator, getDataValidator } 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
+ // Main data model schema
14
+ export const ${camelName}Schema = {
15
+ $id: '${upperName}',
16
+ type: 'object',
17
+ additionalProperties: false,
18
+ required: [ '${type === 'mongodb' ? '_id' : 'id'}'${authStrategies.includes('local') ? ", 'email'" : ''} ],
19
+ properties: {
20
+ ${type === 'mongodb' ? '_id' : 'id'}: {
21
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
22
+ },
23
+ ${authStrategies
24
+ .map((name) => name === 'local'
25
+ ? ` email: { type: 'string' },
26
+ password: { type: 'string' }`
27
+ : ` ${name}Id: { type: 'string' }`)
28
+ .join(',\n')}
29
+ }
30
+ } as const
31
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
32
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
33
+ properties: {}
34
+ })
35
+
36
+ // Schema for the basic data model (e.g. creating new entries)
37
+ export const ${camelName}DataSchema = {
38
+ $id: '${upperName}Data',
39
+ type: 'object',
40
+ additionalProperties: false,
41
+ required: [ ],
42
+ properties: {
43
+ ...${camelName}Schema.properties
44
+ }
45
+ } as const
46
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
47
+ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
48
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
49
+ properties: {
50
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
51
+ }
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
+ ...querySyntax(${camelName}Schema.properties)
68
+ }
69
+ } as const
70
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
71
+ export const ${camelName}QueryValidator = 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;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAA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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, querySyntax, getValidator, getDataValidator } 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
+ // Main data model schema
19
+ export const ${camelName}Schema = {
20
+ $id: '${upperName}',
21
+ type: 'object',
22
+ additionalProperties: false,
23
+ required: [ '${type === 'mongodb' ? '_id' : 'id'}'${authStrategies.includes('local') ? ", 'email'" : ''} ],
24
+ properties: {
25
+ ${type === 'mongodb' ? '_id' : 'id'}: {
26
+ type: '${type === 'mongodb' ? 'string' : 'number'}'
27
+ },
28
+ ${authStrategies
29
+ .map((name) =>
30
+ name === 'local'
31
+ ? ` email: { type: 'string' },
32
+ password: { type: 'string' }`
33
+ : ` ${name}Id: { type: 'string' }`
34
+ )
35
+ .join(',\n')}
36
+ }
37
+ } as const
38
+ export type ${upperName} = FromSchema<typeof ${camelName}Schema>
39
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
40
+ properties: {}
41
+ })
42
+
43
+ // Schema for the basic data model (e.g. creating new entries)
44
+ export const ${camelName}DataSchema = {
45
+ $id: '${upperName}Data',
46
+ type: 'object',
47
+ additionalProperties: false,
48
+ required: [ ],
49
+ properties: {
50
+ ...${camelName}Schema.properties
51
+ }
52
+ } as const
53
+ export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
54
+ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
55
+ export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
56
+ properties: {
57
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
58
+ }
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
+ ...querySyntax(${camelName}Schema.properties)
75
+ }
76
+ } as const
77
+ export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
78
+ export const ${camelName}QueryValidator = 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,77 @@
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 { resolve } from '@feathersjs/schema'
7
+ import { Type, getDataValidator, getValidator, 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
+ // Main data model schema
15
+ export const ${camelName}Schema = Type.Object({
16
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
17
+ ${authStrategies
18
+ .map((name) => name === 'local'
19
+ ? ` email: Type.String(),
20
+ password: Type.Optional(Type.String())`
21
+ : ` ${name}Id: Type.Optional(Type.String())`)
22
+ .join(',\n')}
23
+ },{ $id: '${upperName}', additionalProperties: false })
24
+ export type ${upperName} = Static<typeof ${camelName}Schema>
25
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
26
+ properties: {}
27
+ })
28
+
29
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
30
+ properties: {
31
+ // The password should never be visible externally
32
+ password: async () => undefined
33
+ }
34
+ })
35
+
36
+ // Schema for the basic data model (e.g. creating new entries)
37
+ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
38
+ ${authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')}
39
+ ],
40
+ { $id: '${upperName}Data', additionalProperties: false }
41
+ )
42
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
43
+ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
44
+ export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
45
+ properties: {
46
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
47
+ }
48
+ })
49
+
50
+ // Schema for allowed query properties
51
+ export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, ['${type === 'mongodb' ? '_id' : 'id'}', ${authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')}
52
+ ])
53
+ export const ${camelName}QuerySchema = querySyntax(${camelName}QueryProperties)
54
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
55
+ export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
56
+ export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
57
+ properties: {
58
+ // If there is a user (e.g. with authentication), they are only allowed to see their own data
59
+ ${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
60
+ if (context.params.user) {
61
+ return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
62
+ }
63
+
64
+ return value
65
+ }
66
+ }
67
+ })
68
+ `;
69
+ exports.template = template;
70
+ 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 }) => [
71
+ lib,
72
+ 'services',
73
+ ...folder,
74
+ `${fileName}.schema`
75
+ ]), { force: true })));
76
+ exports.generate = generate;
77
+ //# 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,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A6B,SAAS;cAChD,SAAS,yBAAyB,SAAS;eAC1C,SAAS,iCAAiC,SAAS;eACnD,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 { resolve } from '@feathersjs/schema'
12
+ import { Type, getDataValidator, getValidator, 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
+ // Main data model schema
20
+ export const ${camelName}Schema = Type.Object({
21
+ ${type === 'mongodb' ? '_id: Type.String()' : 'id: Type.Number()'},
22
+ ${authStrategies
23
+ .map((name) =>
24
+ name === 'local'
25
+ ? ` email: Type.String(),
26
+ password: Type.Optional(Type.String())`
27
+ : ` ${name}Id: Type.Optional(Type.String())`
28
+ )
29
+ .join(',\n')}
30
+ },{ $id: '${upperName}', additionalProperties: false })
31
+ export type ${upperName} = Static<typeof ${camelName}Schema>
32
+ export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
33
+ properties: {}
34
+ })
35
+
36
+ export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
37
+ properties: {
38
+ // The password should never be visible externally
39
+ password: async () => undefined
40
+ }
41
+ })
42
+
43
+ // Schema for the basic data model (e.g. creating new entries)
44
+ export const ${camelName}DataSchema = Type.Pick(${camelName}Schema, [
45
+ ${authStrategies.map((name) => (name === 'local' ? `'email', 'password'` : `'${name}Id'`)).join(', ')}
46
+ ],
47
+ { $id: '${upperName}Data', additionalProperties: false }
48
+ )
49
+ export type ${upperName}Data = Static<typeof ${camelName}DataSchema>
50
+ export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
51
+ export const ${camelName}DataResolver = resolve<${upperName}, HookContext>({
52
+ properties: {
53
+ ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
54
+ }
55
+ })
56
+
57
+ // Schema for allowed query properties
58
+ export const ${camelName}QueryProperties = Type.Pick(${camelName}Schema, ['${
59
+ type === 'mongodb' ? '_id' : 'id'
60
+ }', ${authStrategies.map((name) => (name === 'local' ? `'email'` : `'${name}Id'`)).join(', ')}
61
+ ])
62
+ export const ${camelName}QuerySchema = querySyntax(${camelName}QueryProperties)
63
+ export type ${upperName}Query = Static<typeof ${camelName}QuerySchema>
64
+ export const ${camelName}QueryValidator = 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
+ )
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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AE/B,QAAQ;KACL,OAAO,CAAC,SAAS,CAAC;KAClB,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC;KAC3C,MAAM,CAAC,eAAe,EAAE,qCAAqC,CAAC;KAC9D,MAAM,CAAC,eAAe,EAAE,0CAA0C,CAAC;KACnE,MAAM,CAAC,IAAA,qBAAa,EAAC,SAAS,CAAC,CAAC,CAAA;AAEnC,QAAQ;KACL,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,iBAAiB,CAAC;KAC9B,MAAM,CAAC,eAAe,EAAE,sBAAsB,CAAC;KAC/C,MAAM,CAAC,eAAe,EAAE,mCAAmC,CAAC;KAC5D,MAAM,CAAC,IAAA,qBAAa,EAAC,MAAM,CAAC,CAAC,CAAA;AAEhC,QAAQ;KACL,OAAO,CAAC,YAAY,CAAC;KACrB,WAAW,CAAC,+BAA+B,CAAC;KAC5C,MAAM,CAAC,IAAA,qBAAa,EAAC,YAAY,CAAC,CAAC,CAAA;AAEtC,QAAQ;KACL,OAAO,CAAC,gBAAgB,CAAC;KACzB,WAAW,CAAC,uCAAuC,CAAC;KACpD,MAAM,CAAC,IAAA,qBAAa,EAAC,gBAAgB,CAAC,CAAC,CAAA;AAE1C,QAAQ,CAAC,WAAW,CAClB,6CAA6C,QAAQ,CAAC,QAAQ;KAC3D,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC;KAChE,IAAI,CAAC,MAAM,CAAC,EAAE,CAClB,CAAA"}
package/lib/cli.ts ADDED
@@ -0,0 +1,68 @@
1
+ import chalk from 'chalk'
2
+ import { Command } from 'commander'
3
+ import { generator, runGenerator, getContext } from '@feathershq/pinion'
4
+ import { FeathersBaseContext, version } from './commons'
5
+
6
+ export * from 'commander'
7
+ export { chalk }
8
+
9
+ export const commandRunner = (name: string) => async (options: any) => {
10
+ const ctx = getContext<FeathersBaseContext>({
11
+ ...options
12
+ })
13
+
14
+ await generator(ctx)
15
+ .then(runGenerator(__dirname, name, 'index'))
16
+ .catch((error) => {
17
+ const { logger } = ctx.pinion
18
+
19
+ logger.error(`Error: ${chalk.white(error.message)}`)
20
+ })
21
+ }
22
+
23
+ export const program = new Command()
24
+
25
+ program
26
+ .name('feathers')
27
+ .description('The Feathers command line interface 🕊️')
28
+ .version(version)
29
+ .showHelpAfterError()
30
+
31
+ const generate = program.command('generate').alias('g')
32
+
33
+ generate
34
+ .command('app')
35
+ .description('Generate a new application')
36
+ .option('--name <name>', 'The name of the application')
37
+ .action(commandRunner('app'))
38
+
39
+ generate
40
+ .command('service')
41
+ .description('Generate a new service')
42
+ .option('--name <name>', 'The service name')
43
+ .option('--path <path>', 'The path to register the service on')
44
+ .option('--type <type>', 'The service type (knex, mongodb, custom)')
45
+ .action(commandRunner('service'))
46
+
47
+ generate
48
+ .command('hook')
49
+ .description('Generate a hook')
50
+ .option('--name <name>', 'The name of the hook')
51
+ .option('--type <type>', 'The hook type (around or regular)')
52
+ .action(commandRunner('hook'))
53
+
54
+ generate
55
+ .command('connection')
56
+ .description('Add a new database connection')
57
+ .action(commandRunner('connection'))
58
+
59
+ generate
60
+ .command('authentication')
61
+ .description('Add authentication to the application')
62
+ .action(commandRunner('authentication'))
63
+
64
+ generate.description(
65
+ `Run a generator. Currently available: \n ${generate.commands
66
+ .map((cmd) => `${chalk.blue(cmd.name())}: ${cmd.description()} `)
67
+ .join('\n ')}`
68
+ )