@feathersjs/cli 5.0.0-pre.32 → 5.0.0-pre.34
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.
- package/CHANGELOG.md +26 -0
- package/LICENSE +1 -2
- package/README.md +3 -7
- package/lib/app/index.d.ts +2 -2
- package/lib/app/index.js +1 -1
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +1 -0
- package/lib/app/templates/app.test.tpl.js +2 -1
- package/lib/app/templates/app.test.tpl.js.map +1 -1
- package/lib/app/templates/app.test.tpl.ts +4 -1
- package/lib/app/templates/app.tpl.js +12 -10
- package/lib/app/templates/app.tpl.js.map +1 -1
- package/lib/app/templates/app.tpl.ts +12 -10
- package/lib/app/templates/channels.tpl.js +2 -1
- package/lib/app/templates/channels.tpl.js.map +1 -1
- package/lib/app/templates/channels.tpl.ts +2 -1
- package/lib/app/templates/client.tpl.js +2 -1
- package/lib/app/templates/client.tpl.js.map +1 -1
- package/lib/app/templates/client.tpl.ts +2 -1
- package/lib/app/templates/{config.tpl.d.ts → configuration.tpl.d.ts} +0 -0
- package/lib/app/templates/{schemas.tpl.js → configuration.tpl.js} +25 -29
- package/lib/app/templates/configuration.tpl.js.map +1 -0
- package/lib/app/templates/{schemas.tpl.ts → configuration.tpl.ts} +25 -32
- package/lib/app/templates/declarations.tpl.js +3 -2
- package/lib/app/templates/declarations.tpl.js.map +1 -1
- package/lib/app/templates/declarations.tpl.ts +3 -2
- package/lib/app/templates/logger.tpl.d.ts +1 -0
- package/lib/app/templates/logger.tpl.js +13 -7
- package/lib/app/templates/logger.tpl.js.map +1 -1
- package/lib/app/templates/logger.tpl.ts +22 -10
- package/lib/app/templates/package.json.tpl.js +5 -2
- package/lib/app/templates/package.json.tpl.js.map +1 -1
- package/lib/app/templates/package.json.tpl.ts +5 -2
- package/lib/app/templates/services.tpl.js +2 -1
- package/lib/app/templates/services.tpl.js.map +1 -1
- package/lib/app/templates/services.tpl.ts +3 -1
- package/lib/app/templates/{schemas.tpl.d.ts → validators.tpl.d.ts} +0 -0
- package/lib/app/templates/validators.tpl.js +36 -0
- package/lib/app/templates/validators.tpl.js.map +1 -0
- package/lib/app/templates/validators.tpl.ts +40 -0
- package/lib/authentication/index.d.ts +1 -1
- package/lib/authentication/templates/authentication.tpl.js +2 -1
- package/lib/authentication/templates/authentication.tpl.js.map +1 -1
- package/lib/authentication/templates/authentication.tpl.ts +2 -1
- package/lib/authentication/templates/client.test.tpl.js +2 -1
- package/lib/authentication/templates/client.test.tpl.js.map +1 -1
- package/lib/authentication/templates/client.test.tpl.ts +2 -1
- package/lib/authentication/templates/knex.tpl.js +2 -2
- package/lib/authentication/templates/knex.tpl.js.map +1 -1
- package/lib/authentication/templates/knex.tpl.ts +2 -2
- package/lib/authentication/templates/schema.json.tpl.js +30 -20
- package/lib/authentication/templates/schema.json.tpl.js.map +1 -1
- package/lib/authentication/templates/schema.json.tpl.ts +37 -21
- package/lib/authentication/templates/schema.typebox.tpl.d.ts +1 -1
- package/lib/authentication/templates/schema.typebox.tpl.js +30 -22
- package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/authentication/templates/schema.typebox.tpl.ts +37 -23
- package/lib/commons.d.ts +11 -4
- package/lib/commons.js +9 -1
- package/lib/commons.js.map +1 -1
- package/lib/commons.ts +8 -0
- package/lib/connection/index.d.ts +1 -1
- package/lib/connection/index.js +2 -2
- package/lib/connection/index.js.map +1 -1
- package/lib/connection/index.ts +2 -2
- package/lib/connection/templates/knex.tpl.js +4 -2
- package/lib/connection/templates/knex.tpl.js.map +1 -1
- package/lib/connection/templates/knex.tpl.ts +6 -2
- package/lib/connection/templates/mongodb.tpl.js +3 -2
- package/lib/connection/templates/mongodb.tpl.js.map +1 -1
- package/lib/connection/templates/mongodb.tpl.ts +4 -2
- package/lib/hook/templates/hook.tpl.js +4 -2
- package/lib/hook/templates/hook.tpl.js.map +1 -1
- package/lib/hook/templates/hook.tpl.ts +4 -2
- package/lib/service/index.d.ts +1 -1
- package/lib/service/templates/schema.json.tpl.js +23 -15
- package/lib/service/templates/schema.json.tpl.js.map +1 -1
- package/lib/service/templates/schema.json.tpl.ts +28 -17
- package/lib/service/templates/schema.typebox.tpl.js +21 -15
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/service/templates/schema.typebox.tpl.ts +26 -17
- package/lib/service/templates/service.tpl.js +33 -19
- package/lib/service/templates/service.tpl.js.map +1 -1
- package/lib/service/templates/service.tpl.ts +38 -20
- package/lib/service/templates/test.tpl.js +2 -1
- package/lib/service/templates/test.tpl.js.map +1 -1
- package/lib/service/templates/test.tpl.ts +6 -1
- package/lib/service/type/custom.tpl.js +8 -4
- package/lib/service/type/custom.tpl.js.map +1 -1
- package/lib/service/type/custom.tpl.ts +14 -4
- package/lib/service/type/knex.tpl.js +7 -3
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +7 -3
- package/lib/service/type/mongodb.tpl.js +5 -2
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +5 -2
- package/package.json +27 -25
- package/lib/app/templates/config.tpl.js +0 -30
- package/lib/app/templates/config.tpl.js.map +0 -1
- package/lib/app/templates/config.tpl.ts +0 -31
- package/lib/app/templates/schemas.tpl.js.map +0 -1
- package/lib/authentication/templates/client.tpl.d.ts +0 -2
- package/lib/authentication/templates/client.tpl.js +0 -14
- package/lib/authentication/templates/client.tpl.js.map +0 -1
- package/lib/authentication/templates/client.tpl.ts +0 -19
|
@@ -3,8 +3,8 @@ import { renderSource } from '../../commons'
|
|
|
3
3
|
import { AppGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
5
|
const template =
|
|
6
|
-
({}: AppGeneratorContext) => /* ts */
|
|
7
|
-
import
|
|
6
|
+
({}: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/logging.html
|
|
7
|
+
import { createLogger, format, transports } from 'winston'
|
|
8
8
|
|
|
9
9
|
// Configure the Winston logger. For the complete documentation see https://github.com/winstonjs/winston
|
|
10
10
|
export const logger = createLogger({
|
|
@@ -18,16 +18,21 @@ export const logger = createLogger({
|
|
|
18
18
|
new transports.Console()
|
|
19
19
|
]
|
|
20
20
|
})
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
export const logErrorTemplate = /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/log-error.html
|
|
24
|
+
import type { HookContext, NextFunction } from '../declarations'
|
|
25
|
+
import { logger } from '../logger'
|
|
21
26
|
|
|
22
|
-
export const
|
|
27
|
+
export const logError = async (context: HookContext, next: NextFunction) => {
|
|
23
28
|
try {
|
|
24
29
|
await next()
|
|
25
30
|
} catch (error: any) {
|
|
26
31
|
logger.error(error.stack)
|
|
27
32
|
|
|
28
33
|
// Log validation errors
|
|
29
|
-
if (error.
|
|
30
|
-
logger.error(error.
|
|
34
|
+
if (error.data) {
|
|
35
|
+
logger.error(error.data)
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
throw error
|
|
@@ -36,9 +41,16 @@ export const logErrorHook = async (context: HookContext, next: NextFunction) =>
|
|
|
36
41
|
`
|
|
37
42
|
|
|
38
43
|
export const generate = (ctx: AppGeneratorContext) =>
|
|
39
|
-
generator(ctx)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
generator(ctx)
|
|
45
|
+
.then(
|
|
46
|
+
renderSource(
|
|
47
|
+
template,
|
|
48
|
+
toFile<AppGeneratorContext>(({ lib }) => lib, 'logger')
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
.then(
|
|
52
|
+
renderSource(
|
|
53
|
+
logErrorTemplate,
|
|
54
|
+
toFile<AppGeneratorContext>(({ lib }) => lib, 'hooks', 'log-error')
|
|
55
|
+
)
|
|
43
56
|
)
|
|
44
|
-
)
|
|
@@ -9,7 +9,8 @@ const jsPackageJson = (lib) => ({
|
|
|
9
9
|
dev: `nodemon ${lib}/`,
|
|
10
10
|
prettier: 'npx prettier "**/*.js" --write',
|
|
11
11
|
mocha: 'cross-env NODE_ENV=test mocha test/ --recursive --exit',
|
|
12
|
-
test: 'npm run mocha'
|
|
12
|
+
test: 'npm run mocha',
|
|
13
|
+
'bundle:client': 'npm pack --pack-destination ./public'
|
|
13
14
|
}
|
|
14
15
|
});
|
|
15
16
|
const tsPackageJson = (lib) => ({
|
|
@@ -19,7 +20,8 @@ const tsPackageJson = (lib) => ({
|
|
|
19
20
|
start: 'node lib/',
|
|
20
21
|
prettier: 'npx prettier "**/*.ts" --write',
|
|
21
22
|
mocha: 'cross-env NODE_ENV=test mocha test/ --require ts-node/register --recursive --extension .ts --exit',
|
|
22
|
-
test: 'npm run mocha'
|
|
23
|
+
test: 'npm run mocha',
|
|
24
|
+
'bundle:client': 'npm run compile && npm pack --pack-destination ./public'
|
|
23
25
|
}
|
|
24
26
|
});
|
|
25
27
|
const packageJson = ({ name, description, language, packager, database, framework, transports, lib, test, schema }) => ({
|
|
@@ -47,6 +49,7 @@ const packageJson = ({ name, description, language, packager, database, framewor
|
|
|
47
49
|
lib,
|
|
48
50
|
test
|
|
49
51
|
},
|
|
52
|
+
files: ['lib/client.js', 'lib/**/*.d.ts'],
|
|
50
53
|
main: language === 'ts' ? 'lib/client' : `${lib}/client`,
|
|
51
54
|
...(language === 'ts' ? tsPackageJson(lib) : jsPackageJson(lib))
|
|
52
55
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.json.tpl.js","sourceRoot":"","sources":["../../../src/app/templates/package.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAiE;AAGjE,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC;IACtC,IAAI,EAAE,QAAQ;IACd,OAAO,EAAE;QACP,KAAK,EAAE,QAAQ,GAAG,EAAE;QACpB,GAAG,EAAE,WAAW,GAAG,GAAG;QACtB,QAAQ,EAAE,gCAAgC;QAC1C,KAAK,EAAE,wDAAwD;QAC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ACR,QAAQ;QACR,QAAQ;QACR,QAAQ;QACR,SAAS;QACT,UAAU;QACV,MAAM;KACP;IACD,WAAW,EAAE;QACX,GAAG;QACH,IAAI;KACL;IACD,KAAK,EAAE,CAAC,eAAe,EAAE,eAAe,CAAC;IACzC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,GAAG,SAAS;IACxD,GAAG,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;CACjE,CAAC,CAAA;AAEK,MAAM,QAAQ,GAAG,CAAC,GAAwB,EAAE,EAAE,CACnD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAA,kBAAS,EAAC,WAAW,EAAE,IAAA,eAAM,EAAC,cAAc,CAAC,CAAC,CAAC,CAAA;AADxD,QAAA,QAAQ,YACgD"}
|
|
@@ -8,7 +8,8 @@ const jsPackageJson = (lib: string) => ({
|
|
|
8
8
|
dev: `nodemon ${lib}/`,
|
|
9
9
|
prettier: 'npx prettier "**/*.js" --write',
|
|
10
10
|
mocha: 'cross-env NODE_ENV=test mocha test/ --recursive --exit',
|
|
11
|
-
test: 'npm run mocha'
|
|
11
|
+
test: 'npm run mocha',
|
|
12
|
+
'bundle:client': 'npm pack --pack-destination ./public'
|
|
12
13
|
}
|
|
13
14
|
})
|
|
14
15
|
|
|
@@ -20,7 +21,8 @@ const tsPackageJson = (lib: string) => ({
|
|
|
20
21
|
prettier: 'npx prettier "**/*.ts" --write',
|
|
21
22
|
mocha:
|
|
22
23
|
'cross-env NODE_ENV=test mocha test/ --require ts-node/register --recursive --extension .ts --exit',
|
|
23
|
-
test: 'npm run mocha'
|
|
24
|
+
test: 'npm run mocha',
|
|
25
|
+
'bundle:client': 'npm run compile && npm pack --pack-destination ./public'
|
|
24
26
|
}
|
|
25
27
|
})
|
|
26
28
|
|
|
@@ -60,6 +62,7 @@ const packageJson = ({
|
|
|
60
62
|
lib,
|
|
61
63
|
test
|
|
62
64
|
},
|
|
65
|
+
files: ['lib/client.js', 'lib/**/*.d.ts'],
|
|
63
66
|
main: language === 'ts' ? 'lib/client' : `${lib}/client`,
|
|
64
67
|
...(language === 'ts' ? tsPackageJson(lib) : jsPackageJson(lib))
|
|
65
68
|
})
|
|
@@ -3,7 +3,8 @@ 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 = ({}) => /* ts */
|
|
6
|
+
const template = ({}) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/application.html#configure-functions
|
|
7
|
+
import type { Application } from '../declarations'
|
|
7
8
|
|
|
8
9
|
export const services = (app: Application) => {
|
|
9
10
|
// All services will be registered here
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services.tpl.js","sourceRoot":"","sources":["../../../src/app/templates/services.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"services.tpl.js","sourceRoot":"","sources":["../../../src/app/templates/services.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GACZ,CAAC,EAAuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;;CAMvC,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAwB,EAAE,EAAE,CACnD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAsB,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,CACnE,CACF,CAAA;AANU,QAAA,QAAQ,YAMlB"}
|
|
@@ -2,7 +2,9 @@ import { generator, toFile } from '@feathershq/pinion'
|
|
|
2
2
|
import { renderSource } from '../../commons'
|
|
3
3
|
import { AppGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
|
-
const template =
|
|
5
|
+
const template =
|
|
6
|
+
({}: AppGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/application.html#configure-functions
|
|
7
|
+
import type { Application } from '../declarations'
|
|
6
8
|
|
|
7
9
|
export const services = (app: Application) => {
|
|
8
10
|
// All services will be registered here
|
|
File without changes
|
|
@@ -0,0 +1,36 @@
|
|
|
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 validatorTemplate = /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/validators.html
|
|
7
|
+
import { Ajv, addFormats } from '@feathersjs/schema'
|
|
8
|
+
import type { FormatsPluginOptions } from '@feathersjs/schema'
|
|
9
|
+
|
|
10
|
+
const formats: FormatsPluginOptions = [
|
|
11
|
+
'date-time',
|
|
12
|
+
'time',
|
|
13
|
+
'date',
|
|
14
|
+
'email',
|
|
15
|
+
'hostname',
|
|
16
|
+
'ipv4',
|
|
17
|
+
'ipv6',
|
|
18
|
+
'uri',
|
|
19
|
+
'uri-reference',
|
|
20
|
+
'uuid',
|
|
21
|
+
'uri-template',
|
|
22
|
+
'json-pointer',
|
|
23
|
+
'relative-json-pointer',
|
|
24
|
+
'regex'
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
export const dataValidator: Ajv = addFormats(new Ajv({}), formats)
|
|
28
|
+
|
|
29
|
+
export const queryValidator: Ajv = addFormats(new Ajv({
|
|
30
|
+
coerceTypes: true,
|
|
31
|
+
removeAdditional: true
|
|
32
|
+
}), formats)
|
|
33
|
+
`;
|
|
34
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(validatorTemplate, (0, pinion_1.toFile)(({ lib }) => lib, 'validators')));
|
|
35
|
+
exports.generate = generate;
|
|
36
|
+
//# sourceMappingURL=validators.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.tpl.js","sourceRoot":"","sources":["../../../src/app/templates/validators.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,iBAAiB,GAAG,QAAQ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BlC,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAwB,EAAE,EAAE,CACnD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,iBAAiB,EACjB,IAAA,eAAM,EAAsB,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,YAAY,CAAC,CAC5D,CACF,CAAA;AANU,QAAA,QAAQ,YAMlB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { generator, toFile } from '@feathershq/pinion'
|
|
2
|
+
import { renderSource } from '../../commons'
|
|
3
|
+
import { AppGeneratorContext } from '../index'
|
|
4
|
+
|
|
5
|
+
const validatorTemplate = /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/validators.html
|
|
6
|
+
import { Ajv, addFormats } from '@feathersjs/schema'
|
|
7
|
+
import type { FormatsPluginOptions } from '@feathersjs/schema'
|
|
8
|
+
|
|
9
|
+
const formats: FormatsPluginOptions = [
|
|
10
|
+
'date-time',
|
|
11
|
+
'time',
|
|
12
|
+
'date',
|
|
13
|
+
'email',
|
|
14
|
+
'hostname',
|
|
15
|
+
'ipv4',
|
|
16
|
+
'ipv6',
|
|
17
|
+
'uri',
|
|
18
|
+
'uri-reference',
|
|
19
|
+
'uuid',
|
|
20
|
+
'uri-template',
|
|
21
|
+
'json-pointer',
|
|
22
|
+
'relative-json-pointer',
|
|
23
|
+
'regex'
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
export const dataValidator: Ajv = addFormats(new Ajv({}), formats)
|
|
27
|
+
|
|
28
|
+
export const queryValidator: Ajv = addFormats(new Ajv({
|
|
29
|
+
coerceTypes: true,
|
|
30
|
+
removeAdditional: true
|
|
31
|
+
}), formats)
|
|
32
|
+
`
|
|
33
|
+
|
|
34
|
+
export const generate = (ctx: AppGeneratorContext) =>
|
|
35
|
+
generator(ctx).then(
|
|
36
|
+
renderSource(
|
|
37
|
+
validatorTemplate,
|
|
38
|
+
toFile<AppGeneratorContext>(({ lib }) => lib, 'validators')
|
|
39
|
+
)
|
|
40
|
+
)
|
|
@@ -6,7 +6,7 @@ export interface AuthenticationGeneratorContext extends ServiceGeneratorContext
|
|
|
6
6
|
authStrategies: string[];
|
|
7
7
|
dependencies: string[];
|
|
8
8
|
}
|
|
9
|
-
export
|
|
9
|
+
export type AuthenticationGeneratorArguments = FeathersBaseContext & Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity' | 'path'>>;
|
|
10
10
|
export declare const localTemplate: (authStrategies: string[], content: string) => string;
|
|
11
11
|
export declare const oauthTemplate: (authStrategies: string[], content: string) => string;
|
|
12
12
|
export declare const prompts: (ctx: AuthenticationGeneratorArguments) => ({
|
|
@@ -4,7 +4,8 @@ exports.generate = void 0;
|
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
6
|
const index_1 = require("../index");
|
|
7
|
-
const template = ({ authStrategies }) => /* ts */
|
|
7
|
+
const template = ({ authStrategies }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/authentication.html
|
|
8
|
+
import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
8
9
|
${(0, index_1.localTemplate)(authStrategies, `import { LocalStrategy } from '@feathersjs/authentication-local'`)}
|
|
9
10
|
${(0, index_1.oauthTemplate)(authStrategies, `import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'`)}
|
|
10
11
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/authentication.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAC9D,2CAA0D;AAC1D,oCAAuF;AAEvF,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"authentication.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/authentication.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAC9D,2CAA0D;AAC1D,oCAAuF;AAEvF,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;;EAE7C,IAAA,qBAAa,EAAC,cAAc,EAAE,kEAAkE,CAAC;EACjG,IAAA,qBAAa,EAAC,cAAc,EAAE,yEAAyE,CAAC;;;;;;;;;;;;;;IActG,cAAc;KACb,GAAG,CACF,CAAC,QAAQ,EAAE,EAAE,CACX,8BAA8B,QAAQ,MACpC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,qBACjD,GAAG,CACN;KACA,IAAI,CAAC,IAAI,CAAC;;;IAGX,IAAA,qBAAa,EAAC,cAAc,EAAE,wBAAwB,CAAC;;CAE1D,CAAA;AAED,MAAM,cAAc,GAAG,mDAAmD,CAAA;AAC1E,MAAM,iBAAiB,GAAG,+BAA+B,CAAA;AACzD,MAAM,SAAS,GAAG,IAAA,eAAM,EAAiC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAE5E,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAiC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAC3E,CACF;KACA,IAAI,CAAC,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,eAAM,EAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC,CAAC;KACjF,IAAI,CAAC,IAAA,sBAAY,EAAC,iBAAiB,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAA;AAT3E,QAAA,QAAQ,YASmE"}
|
|
@@ -4,7 +4,8 @@ import { AuthenticationGeneratorContext, localTemplate, oauthTemplate } from '..
|
|
|
4
4
|
|
|
5
5
|
const template = ({
|
|
6
6
|
authStrategies
|
|
7
|
-
}: AuthenticationGeneratorContext) => /* ts */
|
|
7
|
+
}: AuthenticationGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/authentication.html
|
|
8
|
+
import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
8
9
|
${localTemplate(authStrategies, `import { LocalStrategy } from '@feathersjs/authentication-local'`)}
|
|
9
10
|
${oauthTemplate(authStrategies, `import { oauth, OAuthStrategy } from '@feathersjs/authentication-oauth'`)}
|
|
10
11
|
|
|
@@ -4,7 +4,8 @@ exports.generate = void 0;
|
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
6
|
const index_1 = require("../index");
|
|
7
|
-
const template = ({ authStrategies, upperName, type, lib }) => /* ts */
|
|
7
|
+
const template = ({ authStrategies, upperName, type, lib }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/client.test.html
|
|
8
|
+
import assert from 'assert'
|
|
8
9
|
import axios from 'axios'
|
|
9
10
|
|
|
10
11
|
import rest from '@feathersjs/rest-client'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.test.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/client.test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAC5C,oCAAwE;AAExE,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACd,SAAS,EACT,IAAI,EACJ,GAAG,EAC4B,EAAE,EAAE,CAAC,QAAQ,CAAC
|
|
1
|
+
{"version":3,"file":"client.test.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/client.test.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAC5C,oCAAwE;AAExE,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACd,SAAS,EACT,IAAI,EACJ,GAAG,EAC4B,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;EAK7C,IAAA,qBAAa,EAAC,cAAc,EAAE,sEAAsE,CAAC;0BAC7E,GAAG;mCACM,GAAG;EACpC,IAAA,qBAAa,EAAC,cAAc,EAAE,iBAAiB,SAAS,mBAAmB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;IAoBvF,IAAA,qBAAa,EACb,cAAc,EACd;;sBAEkB,SAAS;;;;;;;;;;;;;;;;;;;6CAmBc,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;KACzE,CACF;;CAEF,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,aAAa,CAAC,EACzE,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CAAA;AAPU,QAAA,QAAQ,YAOlB"}
|
|
@@ -7,7 +7,8 @@ const template = ({
|
|
|
7
7
|
upperName,
|
|
8
8
|
type,
|
|
9
9
|
lib
|
|
10
|
-
}: AuthenticationGeneratorContext) => /* ts */
|
|
10
|
+
}: AuthenticationGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/client.test.html
|
|
11
|
+
import assert from 'assert'
|
|
11
12
|
import axios from 'axios'
|
|
12
13
|
|
|
13
14
|
import rest from '@feathersjs/rest-client'
|
|
@@ -34,8 +34,8 @@ export async function down(knex: Knex): Promise<void> {
|
|
|
34
34
|
`;
|
|
35
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
|
-
// We add
|
|
38
|
-
const migrationDate = new Date(Date.now() +
|
|
37
|
+
// We add a few seconds so that the migrations run in the correct order
|
|
38
|
+
const migrationDate = new Date(Date.now() + 10000)
|
|
39
39
|
.toISOString()
|
|
40
40
|
.replace(/\D/g, '')
|
|
41
41
|
.substring(0, 14);
|
|
@@ -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,QAAQ,CAAC;;;kCAGb,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,EA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AI,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,uEAAuE;IACvE,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;SAC/C,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"}
|
|
@@ -48,8 +48,8 @@ export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
|
48
48
|
toFile(
|
|
49
49
|
toFile<AuthenticationGeneratorContext>('migrations', () => {
|
|
50
50
|
// Probably not great but it works to align with the Knex migration file format
|
|
51
|
-
// We add
|
|
52
|
-
const migrationDate = new Date(Date.now() +
|
|
51
|
+
// We add a few seconds so that the migrations run in the correct order
|
|
52
|
+
const migrationDate = new Date(Date.now() + 10000)
|
|
53
53
|
.toISOString()
|
|
54
54
|
.replace(/\D/g, '')
|
|
55
55
|
.substring(0, 14)
|
|
@@ -4,12 +4,14 @@ exports.generate = void 0;
|
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
6
|
const index_1 = require("../index");
|
|
7
|
-
const template = ({ camelName, upperName, authStrategies, type, relative }) => /* ts */
|
|
7
|
+
const template = ({ cwd, lib, camelName, upperName, authStrategies, type, relative }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
8
|
+
import { resolve, querySyntax, getValidator } from '@feathersjs/schema'
|
|
8
9
|
import type { FromSchema } from '@feathersjs/schema'
|
|
9
10
|
${(0, index_1.localTemplate)(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
10
11
|
|
|
11
12
|
import type { HookContext } from '${relative}/declarations'
|
|
12
|
-
import { dataValidator, queryValidator } from '${relative}
|
|
13
|
+
import { dataValidator, queryValidator } from '${relative}/${(0, commons_1.fileExists)(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
|
|
14
|
+
}validators'
|
|
13
15
|
|
|
14
16
|
// Main data model schema
|
|
15
17
|
export const ${camelName}Schema = {
|
|
@@ -30,11 +32,14 @@ export const ${camelName}Schema = {
|
|
|
30
32
|
}
|
|
31
33
|
} as const
|
|
32
34
|
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
33
|
-
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
34
|
-
|
|
35
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
|
|
36
|
+
|
|
37
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
38
|
+
${(0, index_1.localTemplate)(authStrategies, `// The password should never be visible externally
|
|
39
|
+
password: async () => undefined`)}
|
|
35
40
|
})
|
|
36
41
|
|
|
37
|
-
// Schema for
|
|
42
|
+
// Schema for creating new users
|
|
38
43
|
export const ${camelName}DataSchema = {
|
|
39
44
|
$id: '${upperName}Data',
|
|
40
45
|
type: 'object',
|
|
@@ -45,18 +50,25 @@ export const ${camelName}DataSchema = {
|
|
|
45
50
|
}
|
|
46
51
|
} as const
|
|
47
52
|
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
48
|
-
export const ${camelName}DataValidator =
|
|
53
|
+
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
49
54
|
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
50
|
-
|
|
51
|
-
${(0, index_1.localTemplate)(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
52
|
-
}
|
|
55
|
+
${(0, index_1.localTemplate)(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
53
56
|
})
|
|
54
57
|
|
|
55
|
-
|
|
58
|
+
// Schema for updating existing users
|
|
59
|
+
export const ${camelName}DataSchema = {
|
|
60
|
+
$id: '${upperName}Patch',
|
|
61
|
+
type: 'object',
|
|
62
|
+
additionalProperties: false,
|
|
63
|
+
required: [],
|
|
56
64
|
properties: {
|
|
57
|
-
|
|
58
|
-
password: async () => undefined
|
|
65
|
+
...${camelName}Schema.properties
|
|
59
66
|
}
|
|
67
|
+
} as const
|
|
68
|
+
export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
|
|
69
|
+
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
70
|
+
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
|
|
71
|
+
${(0, index_1.localTemplate)(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
60
72
|
})
|
|
61
73
|
|
|
62
74
|
// Schema for allowed query properties
|
|
@@ -71,15 +83,13 @@ export const ${camelName}QuerySchema = {
|
|
|
71
83
|
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
72
84
|
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
73
85
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return value
|
|
86
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
87
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
88
|
+
if (context.params.user) {
|
|
89
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
82
90
|
}
|
|
91
|
+
|
|
92
|
+
return value
|
|
83
93
|
}
|
|
84
94
|
})
|
|
85
95
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAAwD;AACxD,oCAAwE;AAExE,MAAM,QAAQ,GAAG,CAAC,EAChB,GAAG,EACH,GAAG,EACH,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;EAG7C,IAAA,qBAAa,EAAC,cAAc,EAAE,iEAAiE,CAAC;;oCAE9D,QAAQ;iDACK,QAAQ,IACvD,IAAA,oBAAU,EAAC,GAAG,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,6CAA6C;AACjG;;;eAGe,SAAS;UACd,SAAS;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,IAAI,IAAA,qBAAa,EAAC,cAAc,EAAE,WAAW,CAAC;;MAE1F,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;eACxB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;;MAEjD,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;;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,QAAA,QAAQ,YAelB"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
|
-
import { renderSource } from '../../commons'
|
|
2
|
+
import { fileExists, renderSource } from '../../commons'
|
|
3
3
|
import { AuthenticationGeneratorContext, localTemplate } from '../index'
|
|
4
4
|
|
|
5
5
|
const template = ({
|
|
6
|
+
cwd,
|
|
7
|
+
lib,
|
|
6
8
|
camelName,
|
|
7
9
|
upperName,
|
|
8
10
|
authStrategies,
|
|
9
11
|
type,
|
|
10
12
|
relative
|
|
11
|
-
}: AuthenticationGeneratorContext) => /* ts */
|
|
13
|
+
}: AuthenticationGeneratorContext) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
|
|
14
|
+
import { resolve, querySyntax, getValidator } from '@feathersjs/schema'
|
|
12
15
|
import type { FromSchema } from '@feathersjs/schema'
|
|
13
16
|
${localTemplate(authStrategies, `import { passwordHash } from '@feathersjs/authentication-local'`)}
|
|
14
17
|
|
|
15
18
|
import type { HookContext } from '${relative}/declarations'
|
|
16
|
-
import { dataValidator, queryValidator } from '${relative}
|
|
19
|
+
import { dataValidator, queryValidator } from '${relative}/${
|
|
20
|
+
fileExists(cwd, lib, 'schemas') ? 'schemas/' : '' // This is for legacy backwards compatibility
|
|
21
|
+
}validators'
|
|
17
22
|
|
|
18
23
|
// Main data model schema
|
|
19
24
|
export const ${camelName}Schema = {
|
|
@@ -36,11 +41,17 @@ export const ${camelName}Schema = {
|
|
|
36
41
|
}
|
|
37
42
|
} as const
|
|
38
43
|
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
39
|
-
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
40
|
-
|
|
44
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({})
|
|
45
|
+
|
|
46
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
47
|
+
${localTemplate(
|
|
48
|
+
authStrategies,
|
|
49
|
+
`// The password should never be visible externally
|
|
50
|
+
password: async () => undefined`
|
|
51
|
+
)}
|
|
41
52
|
})
|
|
42
53
|
|
|
43
|
-
// Schema for
|
|
54
|
+
// Schema for creating new users
|
|
44
55
|
export const ${camelName}DataSchema = {
|
|
45
56
|
$id: '${upperName}Data',
|
|
46
57
|
type: 'object',
|
|
@@ -51,18 +62,25 @@ export const ${camelName}DataSchema = {
|
|
|
51
62
|
}
|
|
52
63
|
} as const
|
|
53
64
|
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
54
|
-
export const ${camelName}DataValidator =
|
|
65
|
+
export const ${camelName}DataValidator = getValidator(${camelName}DataSchema, dataValidator)
|
|
55
66
|
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
56
|
-
|
|
57
|
-
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
58
|
-
}
|
|
67
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
59
68
|
})
|
|
60
69
|
|
|
61
|
-
|
|
70
|
+
// Schema for updating existing users
|
|
71
|
+
export const ${camelName}DataSchema = {
|
|
72
|
+
$id: '${upperName}Patch',
|
|
73
|
+
type: 'object',
|
|
74
|
+
additionalProperties: false,
|
|
75
|
+
required: [],
|
|
62
76
|
properties: {
|
|
63
|
-
|
|
64
|
-
password: async () => undefined
|
|
77
|
+
...${camelName}Schema.properties
|
|
65
78
|
}
|
|
79
|
+
} as const
|
|
80
|
+
export type ${upperName}Patch = FromSchema<typeof ${camelName}PatchSchema>
|
|
81
|
+
export const ${camelName}PatchValidator = getValidator(${camelName}PatchSchema, dataValidator)
|
|
82
|
+
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
|
|
83
|
+
${localTemplate(authStrategies, `password: passwordHash({ strategy: 'local' })`)}
|
|
66
84
|
})
|
|
67
85
|
|
|
68
86
|
// Schema for allowed query properties
|
|
@@ -77,15 +95,13 @@ export const ${camelName}QuerySchema = {
|
|
|
77
95
|
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
78
96
|
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
79
97
|
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return value
|
|
98
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
99
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
100
|
+
if (context.params.user) {
|
|
101
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
88
102
|
}
|
|
103
|
+
|
|
104
|
+
return value
|
|
89
105
|
}
|
|
90
106
|
})
|
|
91
107
|
`
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AuthenticationGeneratorContext } from '../index';
|
|
2
|
-
export declare const template: ({ camelName, upperName, authStrategies, type, relative }: AuthenticationGeneratorContext) => string;
|
|
2
|
+
export declare const template: ({ cwd, lib, camelName, upperName, authStrategies, type, relative }: AuthenticationGeneratorContext) => string;
|
|
3
3
|
export declare const generate: (ctx: AuthenticationGeneratorContext) => Promise<AuthenticationGeneratorContext>;
|