@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,50 +0,0 @@
1
- import { generator, toFile } from '@feathershq/pinion'
2
- import { renderSource } from '../../commons'
3
- import { AppGeneratorContext } from '../index'
4
-
5
- const template = ({}: AppGeneratorContext) =>
6
- `import { schema, Ajv } from '@feathersjs/schema'
7
- import type { Infer } from '@feathersjs/schema'
8
- import { authenticationSettingsSchema } from '@feathersjs/authentication'
9
-
10
- export const configurationSchema = schema(
11
- {
12
- $id: 'ApplicationConfiguration',
13
- type: 'object',
14
- additionalProperties: false,
15
- required: [ 'host', 'port', 'public', 'paginate' ],
16
- properties: {
17
- host: { type: 'string' },
18
- port: { type: 'number' },
19
- public: { type: 'string' },
20
- authentication: authenticationSettingsSchema,
21
- origins: {
22
- type: 'array',
23
- items: {
24
- type: 'string'
25
- }
26
- },
27
- paginate: {
28
- type: 'object',
29
- additionalProperties: false,
30
- required: [ 'default', 'max' ],
31
- properties: {
32
- default: { type: 'number' },
33
- max: { type: 'number' }
34
- }
35
- }
36
- }
37
- } as const,
38
- new Ajv()
39
- )
40
-
41
- export type ConfigurationSchema = Infer<typeof configurationSchema>
42
- `
43
-
44
- export const generate = (ctx: AppGeneratorContext) =>
45
- generator(ctx).then(
46
- renderSource(
47
- template,
48
- toFile<AppGeneratorContext>(({ lib }) => lib, 'configuration')
49
- )
50
- )
@@ -1,43 +0,0 @@
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 = ({ authStrategies, lib }) => `import assert from 'assert';
7
- import { app } from '../${lib}/app';
8
-
9
- describe('authentication', () => {
10
- ${authStrategies.includes('local')
11
- ? `
12
- const userInfo = {
13
- email: 'someone@example.com',
14
- password: 'supersecret'
15
- }
16
-
17
- before(async () => {
18
- try {
19
- await app.service('users').create(userInfo)
20
- } catch (error) {
21
- // Do nothing, it just means the user already exists and can be tested
22
- }
23
- });
24
-
25
- it('authenticates user and creates accessToken', async () => {
26
- const { user, accessToken } = await app.service('authentication').create({
27
- strategy: 'local',
28
- ...userInfo
29
- }, {})
30
-
31
- assert.ok(accessToken, 'Created access token for user')
32
- assert.ok(user, 'Includes user in authentication data')
33
- })`
34
- : ''}
35
-
36
- it('registered the authentication service', () => {
37
- assert.ok(app.service('authentication'))
38
- })
39
- })
40
- `;
41
- const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ test }) => test, 'authentication.test')));
42
- exports.generate = generate;
43
- //# sourceMappingURL=test.tpl.js.map
@@ -1 +0,0 @@
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,50 +0,0 @@
1
- import { generator, toFile } from '@feathershq/pinion'
2
- import { renderSource } from '../../commons'
3
- import { AuthenticationGeneratorContext } from '../index'
4
-
5
- const template = ({ authStrategies, lib }: AuthenticationGeneratorContext) =>
6
- `import assert from 'assert';
7
- import { app } from '../${lib}/app';
8
-
9
- describe('authentication', () => {
10
- ${
11
- authStrategies.includes('local')
12
- ? `
13
- const userInfo = {
14
- email: 'someone@example.com',
15
- password: 'supersecret'
16
- }
17
-
18
- before(async () => {
19
- try {
20
- await app.service('users').create(userInfo)
21
- } catch (error) {
22
- // Do nothing, it just means the user already exists and can be tested
23
- }
24
- });
25
-
26
- it('authenticates user and creates accessToken', async () => {
27
- const { user, accessToken } = await app.service('authentication').create({
28
- strategy: 'local',
29
- ...userInfo
30
- }, {})
31
-
32
- assert.ok(accessToken, 'Created access token for user')
33
- assert.ok(user, 'Includes user in authentication data')
34
- })`
35
- : ''
36
- }
37
-
38
- it('registered the authentication service', () => {
39
- assert.ok(app.service('authentication'))
40
- })
41
- })
42
- `
43
-
44
- export const generate = (ctx: AuthenticationGeneratorContext) =>
45
- generator(ctx).then(
46
- renderSource(
47
- template,
48
- toFile<AuthenticationGeneratorContext>(({ test }) => test, 'authentication.test')
49
- )
50
- )
@@ -1,98 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generate = void 0;
4
- const pinion_1 = require("@feathershq/pinion");
5
- const commons_1 = require("../../commons");
6
- const template = ({ camelName, upperName, relative, authStrategies, type, fileName }) => `import { resolve } from '@feathersjs/schema'
7
- ${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
8
- import type { HookContext } from '${relative}/declarations'
9
- import type {
10
- ${upperName}Data,
11
- ${upperName}Patch,
12
- ${upperName}Result,
13
- ${upperName}Query,
14
- } from './${fileName}.schema'
15
- import {
16
- ${camelName}DataSchema,
17
- ${camelName}PatchSchema,
18
- ${camelName}ResultSchema,
19
- ${camelName}QuerySchema
20
- } from './${fileName}.schema'
21
-
22
-
23
- // Resolver for the basic data model (e.g. creating new entries)
24
- export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
25
- schema: ${camelName}DataSchema,
26
- validate: 'before',
27
- properties: {
28
- ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
29
- }
30
- })
31
-
32
-
33
- // Resolver for making partial updates
34
- export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
35
- schema: ${camelName}PatchSchema,
36
- validate: 'before',
37
- properties: {
38
- ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
39
- }
40
- })
41
-
42
-
43
- // Resolver for the data that is being returned
44
- export const ${camelName}ResultResolver = resolve<${upperName}Result, HookContext>({
45
- schema: ${camelName}ResultSchema,
46
- validate: false,
47
- properties: {}
48
- })
49
-
50
-
51
- // Resolver for the "safe" version that external clients are allowed to see
52
- export const ${camelName}DispatchResolver = resolve<${upperName}Result, HookContext>({
53
- schema: ${camelName}ResultSchema,
54
- validate: false,
55
- properties: {
56
- // The password should never be visible externally
57
- password: async () => undefined
58
- }
59
- })
60
-
61
-
62
- // Resolver for allowed query properties
63
- export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
64
- schema: ${camelName}QuerySchema,
65
- validate: 'before',
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 all resolvers in a format that can be used with the resolveAll hook
80
- export const ${camelName}Resolvers = {
81
- result: ${camelName}ResultResolver,
82
- dispatch: ${camelName}DispatchResolver,
83
- data: {
84
- create: ${camelName}DataResolver,
85
- update: ${camelName}DataResolver,
86
- patch: ${camelName}PatchResolver
87
- },
88
- query: ${camelName}QueryResolver
89
- }
90
- `;
91
- const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
92
- lib,
93
- 'services',
94
- ...folder,
95
- `${fileName}.resolver`
96
- ]), { force: true }));
97
- exports.generate = generate;
98
- //# sourceMappingURL=user.resolver.tpl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.resolver.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/user.resolver.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CACnC;EACA,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;oCACvE,QAAQ;;IAExC,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;;IAEhB,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;;;;eAIL,SAAS,0BAA0B,SAAS;YAC/C,SAAS;;;MAGf,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,EAAE;;;;;;eAM9E,SAAS,2BAA2B,SAAS;YAChD,SAAS;;;MAGf,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,EAAE;;;;;;eAM9E,SAAS,4BAA4B,SAAS;YACjD,SAAS;;;;;;;eAON,SAAS,8BAA8B,SAAS;YACnD,SAAS;;;;;;;;;;eAUN,SAAS,2BAA2B,SAAS;YAChD,SAAS;;;;MAIf,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;qCAEF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;;;;;;;;;eAUvD,SAAS;YACZ,SAAS;cACP,SAAS;;cAET,SAAS;cACT,SAAS;aACV,SAAS;;WAEX,SAAS;;CAEnB,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,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,WAAW;CACvB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAA;AAZU,QAAA,QAAQ,YAYlB"}
@@ -1,111 +0,0 @@
1
- import { generator, toFile } from '@feathershq/pinion'
2
- import { renderSource } from '../../commons'
3
- import { AuthenticationGeneratorContext } from '../index'
4
-
5
- const template = ({
6
- camelName,
7
- upperName,
8
- relative,
9
- authStrategies,
10
- type,
11
- fileName
12
- }: AuthenticationGeneratorContext) =>
13
- `import { resolve } from '@feathersjs/schema'
14
- ${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
15
- import type { HookContext } from '${relative}/declarations'
16
- import type {
17
- ${upperName}Data,
18
- ${upperName}Patch,
19
- ${upperName}Result,
20
- ${upperName}Query,
21
- } from './${fileName}.schema'
22
- import {
23
- ${camelName}DataSchema,
24
- ${camelName}PatchSchema,
25
- ${camelName}ResultSchema,
26
- ${camelName}QuerySchema
27
- } from './${fileName}.schema'
28
-
29
-
30
- // Resolver for the basic data model (e.g. creating new entries)
31
- export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
32
- schema: ${camelName}DataSchema,
33
- validate: 'before',
34
- properties: {
35
- ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
36
- }
37
- })
38
-
39
-
40
- // Resolver for making partial updates
41
- export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
42
- schema: ${camelName}PatchSchema,
43
- validate: 'before',
44
- properties: {
45
- ${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
46
- }
47
- })
48
-
49
-
50
- // Resolver for the data that is being returned
51
- export const ${camelName}ResultResolver = resolve<${upperName}Result, HookContext>({
52
- schema: ${camelName}ResultSchema,
53
- validate: false,
54
- properties: {}
55
- })
56
-
57
-
58
- // Resolver for the "safe" version that external clients are allowed to see
59
- export const ${camelName}DispatchResolver = resolve<${upperName}Result, HookContext>({
60
- schema: ${camelName}ResultSchema,
61
- validate: false,
62
- properties: {
63
- // The password should never be visible externally
64
- password: async () => undefined
65
- }
66
- })
67
-
68
-
69
- // Resolver for allowed query properties
70
- export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
71
- schema: ${camelName}QuerySchema,
72
- validate: 'before',
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
-
86
- // Export all resolvers in a format that can be used with the resolveAll hook
87
- export const ${camelName}Resolvers = {
88
- result: ${camelName}ResultResolver,
89
- dispatch: ${camelName}DispatchResolver,
90
- data: {
91
- create: ${camelName}DataResolver,
92
- update: ${camelName}DataResolver,
93
- patch: ${camelName}PatchResolver
94
- },
95
- query: ${camelName}QueryResolver
96
- }
97
- `
98
-
99
- export const generate = (ctx: AuthenticationGeneratorContext) =>
100
- generator(ctx).then(
101
- renderSource(
102
- template,
103
- toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
104
- lib,
105
- 'services',
106
- ...folder,
107
- `${fileName}.resolver`
108
- ]),
109
- { force: true }
110
- )
111
- )
@@ -1,79 +0,0 @@
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 }) => `import { schema, querySyntax } from '@feathersjs/schema'
7
- import type { Infer } from '@feathersjs/schema'
8
-
9
- // Schema for the basic data model (e.g. creating new entries)
10
- export const ${camelName}DataSchema = schema({
11
- $id: '${upperName}Data',
12
- type: 'object',
13
- additionalProperties: false,
14
- required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
15
- properties: {
16
- ${authStrategies
17
- .map((name) => name === 'local'
18
- ? ` email: { type: 'string' },
19
- password: { type: 'string' }`
20
- : ` ${name}Id: { type: 'string' }`)
21
- .join(',\n')}
22
- }
23
- } as const)
24
-
25
- export type ${upperName}Data = Infer<typeof ${camelName}DataSchema>
26
-
27
-
28
- // Schema for making partial updates
29
- export const ${camelName}PatchSchema = schema({
30
- $id: '${upperName}Patch',
31
- type: 'object',
32
- additionalProperties: false,
33
- required: [],
34
- properties: {
35
- ...${camelName}DataSchema.properties
36
- }
37
- } as const)
38
-
39
- export type ${upperName}Patch = Infer<typeof ${camelName}PatchSchema>
40
-
41
- // Schema for the data that is being returned
42
- export const ${camelName}ResultSchema = schema({
43
- $id: '${upperName}Result',
44
- type: 'object',
45
- additionalProperties: false,
46
- required: [ '${type === 'mongodb' ? '_id' : 'id'}' ],
47
- properties: {
48
- ...${camelName}DataSchema.properties,
49
- ${type === 'mongodb' ? '_id' : 'id'}: {
50
- type: '${type === 'mongodb' ? 'string' : 'number'}'
51
- }
52
- }
53
- } as const)
54
-
55
- export type ${upperName}Result = Infer<typeof ${camelName}ResultSchema>
56
-
57
- // Queries shouldn't allow doing anything with the password
58
- const { password, ...${camelName}QueryProperties } = ${camelName}ResultSchema.properties
59
-
60
- // Schema for allowed query properties
61
- export const ${camelName}QuerySchema = schema({
62
- $id: '${upperName}Query',
63
- type: 'object',
64
- additionalProperties: false,
65
- properties: {
66
- ...querySyntax(${camelName}QueryProperties)
67
- }
68
- } as const)
69
-
70
- export type ${upperName}Query = Infer<typeof ${camelName}QuerySchema>
71
- `;
72
- const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(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=user.schema.tpl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.schema.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/user.schema.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,cAAc,EAAE,IAAI,EAAkC,EAAE,EAAE,CAClG;;;;eAIa,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;;;;cAIJ,SAAS,uBAAuB,SAAS;;;;eAIxC,SAAS;UACd,SAAS;;;;;SAKV,SAAS;;;;cAIJ,SAAS,wBAAwB,SAAS;;;eAGzC,SAAS;UACd,SAAS;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;SAEzC,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;;;;;cAKzC,SAAS,yBAAyB,SAAS;;;uBAGlC,SAAS,uBAAuB,SAAS;;;eAGjD,SAAS;UACd,SAAS;;;;qBAIE,SAAS;;;;cAIhB,SAAS,wBAAwB,SAAS;CACvD,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,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,CAAA;AAZU,QAAA,QAAQ,YAYlB"}
@@ -1,87 +0,0 @@
1
- import { generator, toFile } from '@feathershq/pinion'
2
- import { renderSource } from '../../commons'
3
- import { AuthenticationGeneratorContext } from '../index'
4
-
5
- const template = ({ camelName, upperName, authStrategies, type }: AuthenticationGeneratorContext) =>
6
- `import { schema, querySyntax } from '@feathersjs/schema'
7
- import type { Infer } from '@feathersjs/schema'
8
-
9
- // Schema for the basic data model (e.g. creating new entries)
10
- export const ${camelName}DataSchema = schema({
11
- $id: '${upperName}Data',
12
- type: 'object',
13
- additionalProperties: false,
14
- required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
15
- properties: {
16
- ${authStrategies
17
- .map((name) =>
18
- name === 'local'
19
- ? ` email: { type: 'string' },
20
- password: { type: 'string' }`
21
- : ` ${name}Id: { type: 'string' }`
22
- )
23
- .join(',\n')}
24
- }
25
- } as const)
26
-
27
- export type ${upperName}Data = Infer<typeof ${camelName}DataSchema>
28
-
29
-
30
- // Schema for making partial updates
31
- export const ${camelName}PatchSchema = schema({
32
- $id: '${upperName}Patch',
33
- type: 'object',
34
- additionalProperties: false,
35
- required: [],
36
- properties: {
37
- ...${camelName}DataSchema.properties
38
- }
39
- } as const)
40
-
41
- export type ${upperName}Patch = Infer<typeof ${camelName}PatchSchema>
42
-
43
- // Schema for the data that is being returned
44
- export const ${camelName}ResultSchema = schema({
45
- $id: '${upperName}Result',
46
- type: 'object',
47
- additionalProperties: false,
48
- 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
-
57
- export type ${upperName}Result = Infer<typeof ${camelName}ResultSchema>
58
-
59
- // Queries shouldn't allow doing anything with the password
60
- const { password, ...${camelName}QueryProperties } = ${camelName}ResultSchema.properties
61
-
62
- // Schema for allowed query properties
63
- export const ${camelName}QuerySchema = schema({
64
- $id: '${upperName}Query',
65
- type: 'object',
66
- additionalProperties: false,
67
- properties: {
68
- ...querySyntax(${camelName}QueryProperties)
69
- }
70
- } as const)
71
-
72
- export type ${upperName}Query = Infer<typeof ${camelName}QuerySchema>
73
- `
74
-
75
- export const generate = (ctx: AuthenticationGeneratorContext) =>
76
- generator(ctx).then(
77
- renderSource(
78
- template,
79
- toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
80
- lib,
81
- 'services',
82
- ...folder,
83
- `${fileName}.schema`
84
- ]),
85
- { force: true }
86
- )
87
- )
@@ -1,63 +0,0 @@
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, fileName, isEntityService, authentication }) => `import { resolveAll } from '@feathersjs/schema'
7
- ${isEntityService || authentication ? `import { authenticate } from '@feathersjs/authentication'` : ''}
8
- import type {
9
- ${upperName}Data,
10
- ${upperName}Result,
11
- ${upperName}Query,
12
- } from './${fileName}.schema'
13
- import { ${camelName}Resolvers } from './${fileName}.resolver'
14
-
15
- export const ${camelName}Hooks = {
16
- around: {
17
- all: [${authentication
18
- ? `
19
- authenticate('jwt'),`
20
- : ''} ${!isEntityService
21
- ? `
22
- resolveAll(${camelName}Resolvers)`
23
- : ''}
24
- ]${isEntityService
25
- ? `,
26
- get: [
27
- authenticate('jwt'),
28
- resolveAll(${camelName}Resolvers)
29
- ],
30
- find: [
31
- authenticate('jwt'),
32
- resolveAll(${camelName}Resolvers)
33
- ],
34
- create: [
35
- resolveAll(${camelName}Resolvers)
36
- ],
37
- patch: [
38
- authenticate('jwt'),
39
- resolveAll(${camelName}Resolvers)
40
- ],
41
- update: [
42
- authenticate('jwt'),
43
- resolveAll(${camelName}Resolvers)
44
- ],
45
- remove: [
46
- authenticate('jwt'),
47
- resolveAll(${camelName}Resolvers)
48
- ]`
49
- : ''}
50
- },
51
- before: {},
52
- after: {},
53
- error: {}
54
- }
55
- `;
56
- const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
57
- lib,
58
- 'services',
59
- ...folder,
60
- `${fileName}.class`
61
- ])));
62
- exports.generate = generate;
63
- //# sourceMappingURL=class.tpl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"class.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/class.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,eAAe,EACf,cAAc,EACU,EAAE,EAAE,CAC5B;EACA,eAAe,IAAI,cAAc,CAAC,CAAC,CAAC,2DAA2D,CAAC,CAAC,CAAC,EAAE;;IAElG,SAAS;IACT,SAAS;IACT,SAAS;YACD,QAAQ;WACT,SAAS,uBAAuB,QAAQ;;eAEpC,SAAS;;YAGlB,cAAc;IACZ,CAAC,CAAC;2BACiB;IACnB,CAAC,CAAC,EACN,IACA,CAAC,eAAe;IACd,CAAC,CAAC;mBACW,SAAS,YAAY;IAClC,CAAC,CAAC,EACN;OAEI,eAAe;IACb,CAAC,CAAC;;;mBAGS,SAAS;;;;mBAIT,SAAS;;;mBAGT,SAAS;;;;mBAIT,SAAS;;;;mBAIT,SAAS;;;;mBAIT,SAAS;MACtB;IACE,CAAC,CAAC,EACN;;;;;;CAMH,CAAA;AACM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,QAAQ;CACpB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
@@ -1,79 +0,0 @@
1
- import { generator, toFile } from '@feathershq/pinion'
2
- import { renderSource } from '../../commons'
3
- import { ServiceGeneratorContext } from '../index'
4
-
5
- const template = ({
6
- camelName,
7
- upperName,
8
- fileName,
9
- isEntityService,
10
- authentication
11
- }: ServiceGeneratorContext) =>
12
- `import { resolveAll } from '@feathersjs/schema'
13
- ${isEntityService || authentication ? `import { authenticate } from '@feathersjs/authentication'` : ''}
14
- import type {
15
- ${upperName}Data,
16
- ${upperName}Result,
17
- ${upperName}Query,
18
- } from './${fileName}.schema'
19
- import { ${camelName}Resolvers } from './${fileName}.resolver'
20
-
21
- export const ${camelName}Hooks = {
22
- around: {
23
- all: [${
24
- authentication
25
- ? `
26
- authenticate('jwt'),`
27
- : ''
28
- } ${
29
- !isEntityService
30
- ? `
31
- resolveAll(${camelName}Resolvers)`
32
- : ''
33
- }
34
- ]${
35
- isEntityService
36
- ? `,
37
- get: [
38
- authenticate('jwt'),
39
- resolveAll(${camelName}Resolvers)
40
- ],
41
- find: [
42
- authenticate('jwt'),
43
- resolveAll(${camelName}Resolvers)
44
- ],
45
- create: [
46
- resolveAll(${camelName}Resolvers)
47
- ],
48
- patch: [
49
- authenticate('jwt'),
50
- resolveAll(${camelName}Resolvers)
51
- ],
52
- update: [
53
- authenticate('jwt'),
54
- resolveAll(${camelName}Resolvers)
55
- ],
56
- remove: [
57
- authenticate('jwt'),
58
- resolveAll(${camelName}Resolvers)
59
- ]`
60
- : ''
61
- }
62
- },
63
- before: {},
64
- after: {},
65
- error: {}
66
- }
67
- `
68
- export const generate = (ctx: ServiceGeneratorContext) =>
69
- generator(ctx).then(
70
- renderSource(
71
- template,
72
- toFile<ServiceGeneratorContext>(({ lib, folder, fileName }) => [
73
- lib,
74
- 'services',
75
- ...folder,
76
- `${fileName}.class`
77
- ])
78
- )
79
- )