@feathersjs/cli 5.0.0-pre.29 → 5.0.0-pre.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -39
- package/bin/feathers +3 -6
- package/lib/app/index.js +33 -10
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +81 -53
- package/lib/app/templates/app.test.tpl.js +1 -1
- package/lib/app/templates/app.test.tpl.js.map +1 -1
- package/lib/app/templates/app.test.tpl.ts +1 -2
- package/lib/app/templates/app.tpl.js +7 -7
- package/lib/app/templates/app.tpl.js.map +1 -1
- package/lib/app/templates/app.tpl.ts +7 -9
- package/lib/app/templates/channels.tpl.js +1 -1
- package/lib/app/templates/channels.tpl.js.map +1 -1
- package/lib/app/templates/channels.tpl.ts +1 -2
- package/lib/app/templates/client.tpl.js +2 -2
- package/lib/app/templates/client.tpl.js.map +1 -1
- package/lib/app/templates/client.tpl.ts +2 -3
- package/lib/app/templates/declarations.tpl.js +3 -3
- package/lib/app/templates/declarations.tpl.js.map +1 -1
- package/lib/app/templates/declarations.tpl.ts +5 -4
- package/lib/app/templates/index.html.tpl.js +12 -52
- package/lib/app/templates/index.html.tpl.js.map +1 -1
- package/lib/app/templates/index.html.tpl.ts +12 -53
- package/lib/app/templates/index.tpl.js +1 -1
- package/lib/app/templates/index.tpl.js.map +1 -1
- package/lib/app/templates/index.tpl.ts +1 -2
- package/lib/app/templates/logger.tpl.js +1 -1
- package/lib/app/templates/logger.tpl.js.map +1 -1
- package/lib/app/templates/logger.tpl.ts +2 -2
- package/lib/app/templates/package.json.tpl.js +4 -3
- package/lib/app/templates/package.json.tpl.js.map +1 -1
- package/lib/app/templates/package.json.tpl.ts +5 -3
- package/lib/app/templates/readme.md.tpl.js +11 -7
- package/lib/app/templates/readme.md.tpl.js.map +1 -1
- package/lib/app/templates/readme.md.tpl.ts +15 -8
- package/lib/app/templates/{configuration.tpl.d.ts → schemas.tpl.d.ts} +0 -0
- package/lib/app/templates/schemas.tpl.js +76 -0
- package/lib/app/templates/schemas.tpl.js.map +1 -0
- package/lib/app/templates/schemas.tpl.ts +90 -0
- package/lib/app/templates/services.tpl.js +1 -1
- package/lib/app/templates/services.tpl.js.map +1 -1
- package/lib/app/templates/services.tpl.ts +1 -2
- package/lib/authentication/index.d.ts +4 -3
- package/lib/authentication/index.js +12 -3
- package/lib/authentication/index.js.map +1 -1
- package/lib/authentication/index.ts +23 -5
- package/lib/authentication/templates/authentication.tpl.js +1 -1
- package/lib/authentication/templates/authentication.tpl.js.map +1 -1
- package/lib/authentication/templates/authentication.tpl.ts +3 -2
- package/lib/authentication/templates/config.tpl.js +1 -1
- package/lib/authentication/templates/config.tpl.js.map +1 -1
- package/lib/authentication/templates/config.tpl.ts +1 -1
- package/lib/authentication/templates/declarations.tpl.js +3 -3
- package/lib/authentication/templates/declarations.tpl.js.map +1 -1
- package/lib/authentication/templates/declarations.tpl.ts +9 -4
- 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/{user.resolver.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
- package/lib/authentication/templates/schema.json.tpl.js +92 -0
- package/lib/authentication/templates/schema.json.tpl.js.map +1 -0
- package/lib/authentication/templates/schema.json.tpl.ts +108 -0
- package/lib/authentication/templates/{user.schema.tpl.d.ts → schema.typebox.tpl.d.ts} +1 -0
- package/lib/authentication/templates/schema.typebox.tpl.js +79 -0
- package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
- package/lib/authentication/templates/schema.typebox.tpl.ts +94 -0
- package/lib/authentication/templates/test.tpl.js +2 -2
- package/lib/authentication/templates/test.tpl.js.map +1 -1
- package/lib/authentication/templates/test.tpl.ts +6 -3
- package/lib/cli.d.ts +6 -0
- package/lib/cli.js +75 -0
- package/lib/cli.js.map +1 -0
- package/lib/cli.ts +68 -0
- package/lib/commons.d.ts +14 -1
- package/lib/commons.js +24 -4
- package/lib/commons.js.map +1 -1
- package/lib/commons.ts +29 -1
- package/lib/connection/index.d.ts +5 -3
- package/lib/connection/index.js +5 -3
- package/lib/connection/index.js.map +1 -1
- package/lib/connection/index.ts +19 -5
- package/lib/connection/templates/knex.tpl.js +2 -12
- package/lib/connection/templates/knex.tpl.js.map +1 -1
- package/lib/connection/templates/knex.tpl.ts +6 -20
- package/lib/connection/templates/mongodb.tpl.js +1 -3
- package/lib/connection/templates/mongodb.tpl.js.map +1 -1
- package/lib/connection/templates/mongodb.tpl.ts +1 -12
- package/lib/hook/index.d.ts +1 -1
- package/lib/hook/index.js +3 -0
- package/lib/hook/index.js.map +1 -1
- package/lib/hook/index.ts +3 -1
- package/lib/hook/templates/hook.tpl.js +2 -3
- package/lib/hook/templates/hook.tpl.js.map +1 -1
- package/lib/hook/templates/hook.tpl.ts +5 -3
- package/lib/index.d.ts +2 -16
- package/lib/index.js +16 -24
- package/lib/index.js.map +1 -1
- package/lib/index.ts +2 -28
- package/lib/service/index.d.ts +10 -2
- package/lib/service/index.js +79 -41
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +54 -6
- package/lib/service/templates/client.tpl.js +19 -11
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +34 -17
- package/lib/service/templates/{class.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
- package/lib/service/templates/schema.json.tpl.js +73 -0
- package/lib/service/templates/schema.json.tpl.js.map +1 -0
- package/lib/service/templates/schema.json.tpl.ts +85 -0
- package/lib/service/templates/{resolver.tpl.d.ts → schema.typebox.tpl.d.ts} +0 -0
- package/lib/service/templates/schema.typebox.tpl.js +58 -0
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
- package/lib/service/templates/schema.typebox.tpl.ts +70 -0
- package/lib/service/templates/service.tpl.d.ts +1 -0
- package/lib/service/templates/service.tpl.js +67 -15
- package/lib/service/templates/service.tpl.js.map +1 -1
- package/lib/service/templates/service.tpl.ts +98 -19
- package/lib/service/templates/test.tpl.js +1 -1
- package/lib/service/templates/test.tpl.js.map +1 -1
- package/lib/service/templates/test.tpl.ts +1 -2
- package/lib/service/type/custom.tpl.d.ts +1 -2
- package/lib/service/type/custom.tpl.js +32 -25
- package/lib/service/type/custom.tpl.js.map +1 -1
- package/lib/service/type/custom.tpl.ts +44 -35
- package/lib/service/type/knex.tpl.d.ts +1 -3
- package/lib/service/type/knex.tpl.js +33 -23
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +51 -29
- package/lib/service/type/mongodb.tpl.d.ts +1 -2
- package/lib/service/type/mongodb.tpl.js +30 -20
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +47 -29
- package/package.json +22 -23
- package/lib/app/templates/configuration.tpl.js +0 -45
- package/lib/app/templates/configuration.tpl.js.map +0 -1
- package/lib/app/templates/configuration.tpl.ts +0 -50
- package/lib/authentication/templates/user.resolver.tpl.js +0 -98
- package/lib/authentication/templates/user.resolver.tpl.js.map +0 -1
- package/lib/authentication/templates/user.resolver.tpl.ts +0 -111
- package/lib/authentication/templates/user.schema.tpl.js +0 -79
- package/lib/authentication/templates/user.schema.tpl.js.map +0 -1
- package/lib/authentication/templates/user.schema.tpl.ts +0 -87
- package/lib/service/templates/class.tpl.js +0 -63
- package/lib/service/templates/class.tpl.js.map +0 -1
- package/lib/service/templates/class.tpl.ts +0 -79
- package/lib/service/templates/resolver.tpl.js +0 -73
- package/lib/service/templates/resolver.tpl.js.map +0 -1
- package/lib/service/templates/resolver.tpl.ts +0 -78
- package/lib/service/templates/schema.tpl.d.ts +0 -2
- package/lib/service/templates/schema.tpl.js +0 -75
- package/lib/service/templates/schema.tpl.js.map +0 -1
- package/lib/service/templates/schema.tpl.ts +0 -80
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { generator, toFile } from '@feathershq/pinion'
|
|
2
|
+
import { renderSource } from '../../commons'
|
|
3
|
+
import { AppGeneratorContext } from '../index'
|
|
4
|
+
|
|
5
|
+
const validatorTemplate = /* ts */ `import { Ajv, addFormats } from '@feathersjs/schema'
|
|
6
|
+
import type { FormatsPluginOptions } from '@feathersjs/schema'
|
|
7
|
+
|
|
8
|
+
const formats: FormatsPluginOptions = [
|
|
9
|
+
'date-time',
|
|
10
|
+
'time',
|
|
11
|
+
'date',
|
|
12
|
+
'email',
|
|
13
|
+
'hostname',
|
|
14
|
+
'ipv4',
|
|
15
|
+
'ipv6',
|
|
16
|
+
'uri',
|
|
17
|
+
'uri-reference',
|
|
18
|
+
'uuid',
|
|
19
|
+
'uri-template',
|
|
20
|
+
'json-pointer',
|
|
21
|
+
'relative-json-pointer',
|
|
22
|
+
'regex'
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
export const dataValidator = addFormats(new Ajv({}), formats)
|
|
26
|
+
|
|
27
|
+
export const queryValidator = addFormats(new Ajv({
|
|
28
|
+
coerceTypes: true
|
|
29
|
+
}), formats)
|
|
30
|
+
`
|
|
31
|
+
|
|
32
|
+
const configurationJsonTemplate =
|
|
33
|
+
({}: AppGeneratorContext) => /* ts */ `import { defaultAppSettings, jsonSchema } from '@feathersjs/schema'
|
|
34
|
+
import type { FromSchema } from '@feathersjs/schema'
|
|
35
|
+
|
|
36
|
+
import { dataValidator } from './validators'
|
|
37
|
+
|
|
38
|
+
export const configurationSchema = {
|
|
39
|
+
type: 'object',
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
required: [ 'host', 'port', 'public' ],
|
|
42
|
+
properties: {
|
|
43
|
+
...defaultAppSettings,
|
|
44
|
+
host: { type: 'string' },
|
|
45
|
+
port: { type: 'number' },
|
|
46
|
+
public: { type: 'string' }
|
|
47
|
+
}
|
|
48
|
+
} as const
|
|
49
|
+
|
|
50
|
+
export const configurationValidator = jsonSchema.getValidator(configurationSchema, dataValidator)
|
|
51
|
+
|
|
52
|
+
export type ApplicationConfiguration = FromSchema<typeof configurationSchema>
|
|
53
|
+
`
|
|
54
|
+
|
|
55
|
+
const configurationTypeboxTemplate =
|
|
56
|
+
({}: AppGeneratorContext) => /* ts */ `import { jsonSchema } from '@feathersjs/schema'
|
|
57
|
+
import { Type, defaultAppConfiguration } from '@feathersjs/typebox'
|
|
58
|
+
import type { Static } from '@feathersjs/typebox'
|
|
59
|
+
|
|
60
|
+
import { dataValidator } from './validators'
|
|
61
|
+
|
|
62
|
+
export const configurationSchema = Type.Intersect([
|
|
63
|
+
defaultAppConfiguration,
|
|
64
|
+
Type.Object({
|
|
65
|
+
host: Type.String(),
|
|
66
|
+
port: Type.Number(),
|
|
67
|
+
public: Type.String()
|
|
68
|
+
})
|
|
69
|
+
])
|
|
70
|
+
|
|
71
|
+
export type ApplicationConfiguration = Static<typeof configurationSchema>
|
|
72
|
+
|
|
73
|
+
export const configurationValidator = jsonSchema.getValidator(configurationSchema, dataValidator)
|
|
74
|
+
`
|
|
75
|
+
|
|
76
|
+
export const generate = (ctx: AppGeneratorContext) =>
|
|
77
|
+
generator(ctx)
|
|
78
|
+
.then(
|
|
79
|
+
renderSource(
|
|
80
|
+
async (ctx) =>
|
|
81
|
+
ctx.schema === 'typebox' ? configurationTypeboxTemplate(ctx) : configurationJsonTemplate(ctx),
|
|
82
|
+
toFile<AppGeneratorContext>(({ lib }) => lib, 'schemas', 'configuration')
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
.then(
|
|
86
|
+
renderSource(
|
|
87
|
+
validatorTemplate,
|
|
88
|
+
toFile<AppGeneratorContext>(({ lib }) => lib, 'schemas', 'validators')
|
|
89
|
+
)
|
|
90
|
+
)
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const template = ({}) => `import type { Application } from '../declarations'
|
|
6
|
+
const template = ({}) => /* ts */ `import type { Application } from '../declarations'
|
|
7
7
|
|
|
8
8
|
export const services = (app: Application) => {
|
|
9
9
|
// 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,GAAG,CAAC,EAAuB,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"services.tpl.js","sourceRoot":"","sources":["../../../src/app/templates/services.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;CAKtD,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,8 +2,7 @@ import { generator, toFile } from '@feathershq/pinion'
|
|
|
2
2
|
import { renderSource } from '../../commons'
|
|
3
3
|
import { AppGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
|
-
const template = ({}: AppGeneratorContext) =>
|
|
6
|
-
`import type { Application } from '../declarations'
|
|
5
|
+
const template = ({}: AppGeneratorContext) => /* ts */ `import type { Application } from '../declarations'
|
|
7
6
|
|
|
8
7
|
export const services = (app: Application) => {
|
|
9
8
|
// All services will be registered here
|
|
@@ -6,7 +6,7 @@ export interface AuthenticationGeneratorContext extends ServiceGeneratorContext
|
|
|
6
6
|
authStrategies: string[];
|
|
7
7
|
dependencies: string[];
|
|
8
8
|
}
|
|
9
|
-
export declare type AuthenticationGeneratorArguments = FeathersBaseContext & Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity'>>;
|
|
9
|
+
export declare type AuthenticationGeneratorArguments = FeathersBaseContext & Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity' | 'path'>>;
|
|
10
10
|
export declare const prompts: (ctx: AuthenticationGeneratorArguments) => ({
|
|
11
11
|
type: string;
|
|
12
12
|
name: string;
|
|
@@ -51,14 +51,15 @@ export declare const generate: (ctx: AuthenticationGeneratorArguments) => Promis
|
|
|
51
51
|
kebabName: string;
|
|
52
52
|
fileName: string;
|
|
53
53
|
relative: string;
|
|
54
|
-
type: "
|
|
54
|
+
type: "mongodb" | "knex" | "custom";
|
|
55
|
+
schema: false | "typebox" | "json";
|
|
55
56
|
authentication: boolean;
|
|
56
57
|
isEntityService?: boolean;
|
|
57
58
|
feathers: import("../commons").FeathersAppInfo;
|
|
58
59
|
pkg: import("../commons").AppPackageJson;
|
|
59
60
|
lib: string;
|
|
60
61
|
test: string;
|
|
61
|
-
language: "
|
|
62
|
+
language: "ts" | "js";
|
|
62
63
|
dependencyVersions?: import("../commons").DependencyVersions;
|
|
63
64
|
cwd: string;
|
|
64
65
|
_?: (string | number)[];
|
|
@@ -48,6 +48,13 @@ const prompts = (ctx) => [
|
|
|
48
48
|
type: 'input',
|
|
49
49
|
when: !ctx.service,
|
|
50
50
|
message: 'What is your authentication service name?',
|
|
51
|
+
default: 'user'
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: 'path',
|
|
55
|
+
type: 'input',
|
|
56
|
+
when: !ctx.path,
|
|
57
|
+
message: 'What path should the service be registered on?',
|
|
51
58
|
default: 'users'
|
|
52
59
|
},
|
|
53
60
|
{
|
|
@@ -61,14 +68,16 @@ const prompts = (ctx) => [
|
|
|
61
68
|
];
|
|
62
69
|
exports.prompts = prompts;
|
|
63
70
|
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
71
|
+
.then((0, commons_1.initializeBaseContext)())
|
|
72
|
+
.then((0, commons_1.checkPreconditions)())
|
|
64
73
|
.then((0, pinion_1.prompt)(exports.prompts))
|
|
65
74
|
.then(async (ctx) => {
|
|
75
|
+
var _a;
|
|
66
76
|
const serviceContext = await (0, index_1.generate)({
|
|
67
77
|
...ctx,
|
|
68
78
|
name: ctx.service,
|
|
69
|
-
path: ctx.service,
|
|
70
79
|
isEntityService: true,
|
|
71
|
-
type: (0, commons_1.getDatabaseAdapter)(ctx.feathers.database)
|
|
80
|
+
type: (0, commons_1.getDatabaseAdapter)((_a = ctx.feathers) === null || _a === void 0 ? void 0 : _a.database)
|
|
72
81
|
});
|
|
73
82
|
return {
|
|
74
83
|
...ctx,
|
|
@@ -88,7 +97,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
88
97
|
dependencies: [...ctx.dependencies, ...dependencies]
|
|
89
98
|
};
|
|
90
99
|
}
|
|
91
|
-
return (0, pinion_1.install)((0, commons_1.addVersions)(dependencies, ctx.dependencyVersions))(ctx);
|
|
100
|
+
return (0, pinion_1.install)((0, commons_1.addVersions)(dependencies, ctx.dependencyVersions), false, ctx.feathers.packager)(ctx);
|
|
92
101
|
});
|
|
93
102
|
exports.generate = generate;
|
|
94
103
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAyB;AACzB,+CAA8E;AAC9E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import chalk from 'chalk'
|
|
2
2
|
import { generator, runGenerators, prompt, install } from '@feathershq/pinion'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
addVersions,
|
|
5
|
+
checkPreconditions,
|
|
6
|
+
FeathersBaseContext,
|
|
7
|
+
getDatabaseAdapter,
|
|
8
|
+
initializeBaseContext
|
|
9
|
+
} from '../commons'
|
|
4
10
|
import { generate as serviceGenerator, ServiceGeneratorContext } from '../service/index'
|
|
5
11
|
|
|
6
12
|
export interface AuthenticationGeneratorContext extends ServiceGeneratorContext {
|
|
@@ -11,7 +17,7 @@ export interface AuthenticationGeneratorContext extends ServiceGeneratorContext
|
|
|
11
17
|
}
|
|
12
18
|
|
|
13
19
|
export type AuthenticationGeneratorArguments = FeathersBaseContext &
|
|
14
|
-
Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity'>>
|
|
20
|
+
Partial<Pick<AuthenticationGeneratorContext, 'service' | 'authStrategies' | 'entity' | 'path'>>
|
|
15
21
|
|
|
16
22
|
export const prompts = (ctx: AuthenticationGeneratorArguments) => [
|
|
17
23
|
{
|
|
@@ -53,6 +59,13 @@ export const prompts = (ctx: AuthenticationGeneratorArguments) => [
|
|
|
53
59
|
type: 'input',
|
|
54
60
|
when: !ctx.service,
|
|
55
61
|
message: 'What is your authentication service name?',
|
|
62
|
+
default: 'user'
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'path',
|
|
66
|
+
type: 'input',
|
|
67
|
+
when: !ctx.path,
|
|
68
|
+
message: 'What path should the service be registered on?',
|
|
56
69
|
default: 'users'
|
|
57
70
|
},
|
|
58
71
|
{
|
|
@@ -67,14 +80,15 @@ export const prompts = (ctx: AuthenticationGeneratorArguments) => [
|
|
|
67
80
|
|
|
68
81
|
export const generate = (ctx: AuthenticationGeneratorArguments) =>
|
|
69
82
|
generator(ctx)
|
|
83
|
+
.then(initializeBaseContext())
|
|
84
|
+
.then(checkPreconditions())
|
|
70
85
|
.then(prompt<AuthenticationGeneratorArguments, AuthenticationGeneratorContext>(prompts))
|
|
71
86
|
.then(async (ctx) => {
|
|
72
87
|
const serviceContext = await serviceGenerator({
|
|
73
88
|
...ctx,
|
|
74
89
|
name: ctx.service,
|
|
75
|
-
path: ctx.service,
|
|
76
90
|
isEntityService: true,
|
|
77
|
-
type: getDatabaseAdapter(ctx.feathers
|
|
91
|
+
type: getDatabaseAdapter(ctx.feathers?.database)
|
|
78
92
|
})
|
|
79
93
|
|
|
80
94
|
return {
|
|
@@ -99,5 +113,9 @@ export const generate = (ctx: AuthenticationGeneratorArguments) =>
|
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
115
|
|
|
102
|
-
return install<AuthenticationGeneratorContext>(
|
|
116
|
+
return install<AuthenticationGeneratorContext>(
|
|
117
|
+
addVersions(dependencies, ctx.dependencyVersions),
|
|
118
|
+
false,
|
|
119
|
+
ctx.feathers.packager
|
|
120
|
+
)(ctx)
|
|
103
121
|
})
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const template = ({ authStrategies }) => `import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
6
|
+
const template = ({ authStrategies }) => /* ts */ `import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
7
7
|
import { LocalStrategy } from '@feathersjs/authentication-local'
|
|
8
8
|
import { OAuthStrategy } from '@feathersjs/authentication-oauth'
|
|
9
9
|
import { oauth } from '@feathersjs/authentication-oauth'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/authentication.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAC9D,2CAA0D;AAG1D,MAAM,QAAQ,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"authentication.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/authentication.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAC9D,2CAA0D;AAG1D,MAAM,QAAQ,GAAG,CAAC,EAChB,cAAc,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;;;;;;;;;;;;IAgB3C,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;;;;;CAKd,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"}
|
|
@@ -2,8 +2,9 @@ import { generator, before, toFile } from '@feathershq/pinion'
|
|
|
2
2
|
import { injectSource, renderSource } from '../../commons'
|
|
3
3
|
import { AuthenticationGeneratorContext } from '../index'
|
|
4
4
|
|
|
5
|
-
const template = ({
|
|
6
|
-
|
|
5
|
+
const template = ({
|
|
6
|
+
authStrategies
|
|
7
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
|
|
7
8
|
import { LocalStrategy } from '@feathersjs/authentication-local'
|
|
8
9
|
import { OAuthStrategy } from '@feathersjs/authentication-oauth'
|
|
9
10
|
import { oauth } from '@feathersjs/authentication-oauth'
|
|
@@ -10,7 +10,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
10
10
|
.then((0, pinion_1.mergeJSON)(({ authStrategies }) => {
|
|
11
11
|
const authentication = {
|
|
12
12
|
entity: ctx.entity,
|
|
13
|
-
service: ctx.
|
|
13
|
+
service: ctx.path,
|
|
14
14
|
secret: crypto_1.default.randomBytes(24).toString('base64'),
|
|
15
15
|
authStrategies: ['jwt'],
|
|
16
16
|
jwtOptions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/config.tpl.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,+CAAiE;AAG1D,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,kBAAS,EAAiC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;IAC/D,MAAM,cAAc,GAAQ;QAC1B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"config.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/config.tpl.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,+CAAiE;AAG1D,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,kBAAS,EAAiC,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE;IAC/D,MAAM,cAAc,GAAQ;QAC1B,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,GAAG,CAAC,IAAI;QACjB,MAAM,EAAE,gBAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;QACjD,cAAc,EAAE,CAAC,KAAK,CAAC;QACvB,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,GAAG,EAAE,QAAQ;aACd;YACD,QAAQ,EAAE,wBAAwB;YAClC,SAAS,EAAE,OAAO;YAClB,SAAS,EAAE,IAAI;SAChB;KACF,CAAA;IAED,IAAI,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACpC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3C,cAAc,CAAC,KAAK,GAAG;YACrB,aAAa,EAAE,OAAO;YACtB,aAAa,EAAE,UAAU;SAC1B,CAAA;KACF;IAED,MAAM,eAAe,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,OAAO,CAAC,CAAA;IAEzE,IAAI,eAAe,CAAC,MAAM,EAAE;QAC1B,cAAc,CAAC,KAAK,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;YAC5D,KAAK,CAAC,IAAI,CAAC,GAAG;gBACZ,GAAG,EAAE,aAAa;gBAClB,MAAM,EAAE,iBAAiB;aAC1B,CAAA;YAED,OAAO,KAAK,CAAA;QACd,CAAC,EAAE,EAAS,CAAC,CAAA;KACd;IAED,OAAO,EAAE,cAAc,EAAE,CAAA;AAC3B,CAAC,EAAE,IAAA,eAAM,EAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CACrC;KACA,IAAI,CACH,IAAA,kBAAS,EACP;IACE,cAAc,EAAE;QACd,MAAM,EAAE,iBAAiB;KAC1B;CACF,EACD,IAAA,eAAM,EAAC,QAAQ,EAAE,mCAAmC,CAAC,CACtD,CACF,CAAA;AApDQ,QAAA,QAAQ,YAoDhB"}
|
|
@@ -8,7 +8,7 @@ export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
|
8
8
|
mergeJSON<AuthenticationGeneratorContext>(({ authStrategies }) => {
|
|
9
9
|
const authentication: any = {
|
|
10
10
|
entity: ctx.entity,
|
|
11
|
-
service: ctx.
|
|
11
|
+
service: ctx.path,
|
|
12
12
|
secret: crypto.randomBytes(24).toString('base64'),
|
|
13
13
|
authStrategies: ['jwt'],
|
|
14
14
|
jwtOptions: {
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
-
const importTemplate = ({ upperName, folder, fileName }) => `import { ${upperName}
|
|
5
|
+
const importTemplate = ({ upperName, folder, fileName }) => /* ts */ `import { ${upperName} } from './services/${folder.join('/')}/${fileName}.schema'
|
|
6
6
|
`;
|
|
7
|
-
const paramsTemplate = ({ entity, upperName }) => `// Add the ${entity} as an optional property to all params
|
|
7
|
+
const paramsTemplate = ({ entity, upperName }) => /* ts */ `// Add the ${entity} as an optional property to all params
|
|
8
8
|
declare module '@feathersjs/feathers' {
|
|
9
9
|
interface Params {
|
|
10
|
-
${entity}?: ${upperName}
|
|
10
|
+
${entity}?: ${upperName}
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declarations.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/declarations.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAoF;AAGpF,MAAM,cAAc,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"declarations.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/declarations.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAoF;AAGpF,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,MAAM,EACN,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC,YAAY,SAAS,uBAAuB,MAAM,CAAC,IAAI,CACpG,GAAG,CACJ,IAAI,QAAQ;CACZ,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,EACtB,MAAM,EACN,SAAS,EACsB,EAAE,EAAE,CAAC,QAAQ,CAAC,cAAc,MAAM;;;MAG7D,MAAM,MAAM,SAAS;;;CAG1B,CAAA;AAED,MAAM,iBAAiB,GAAG,IAAA,eAAM,EAAiC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAA;AAE9F,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,eAAM,EAAC,cAAc,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,iBAAiB,CAAC,CAC7E,CACF;KACA,IAAI,CAAC,IAAA,aAAI,EAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAAE,IAAA,eAAM,EAAC,cAAc,EAAE,IAAA,eAAM,GAAE,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAA;AARvF,QAAA,QAAQ,YAQ+E"}
|
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { generator, inject, before, toFile, when, append } from '@feathershq/pinion'
|
|
2
2
|
import { AuthenticationGeneratorContext } from '../index'
|
|
3
3
|
|
|
4
|
-
const importTemplate = ({
|
|
5
|
-
|
|
4
|
+
const importTemplate = ({
|
|
5
|
+
upperName,
|
|
6
|
+
folder,
|
|
7
|
+
fileName
|
|
8
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import { ${upperName} } from './services/${folder.join(
|
|
9
|
+
'/'
|
|
10
|
+
)}/${fileName}.schema'
|
|
6
11
|
`
|
|
7
12
|
|
|
8
13
|
const paramsTemplate = ({
|
|
9
14
|
entity,
|
|
10
15
|
upperName
|
|
11
|
-
}: AuthenticationGeneratorContext) => `// Add the ${entity} as an optional property to all params
|
|
16
|
+
}: AuthenticationGeneratorContext) => /* ts */ `// Add the ${entity} as an optional property to all params
|
|
12
17
|
declare module '@feathersjs/feathers' {
|
|
13
18
|
interface Params {
|
|
14
|
-
${entity}?: ${upperName}
|
|
19
|
+
${entity}?: ${upperName}
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
`
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
5
|
const commons_1 = require("../../commons");
|
|
6
|
-
const migrationTemplate = ({ kebabName, authStrategies }) => `import type { Knex } from 'knex'
|
|
6
|
+
const migrationTemplate = ({ kebabName, authStrategies }) => /* ts */ `import type { Knex } from 'knex'
|
|
7
7
|
|
|
8
8
|
export async function up(knex: Knex): Promise<void> {
|
|
9
9
|
await knex.schema.alterTable('${kebabName}', function (table) {
|
|
@@ -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;;;
|
|
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,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;;iCAEqB;IACvB,CAAC,CAAC;wBACY,IAAI;KACvB,CACE;KACA,IAAI,CAAC,IAAI,CAAC;;;CAGhB,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,WAAC,OAAA,IAAA,4BAAkB,EAAC,MAAA,GAAG,CAAC,QAAQ,0CAAE,QAAQ,CAAC,KAAK,MAAM,CAAA,EAAA,EAC9D,IAAA,sBAAY,EACV,iBAAiB,EACjB,IAAA,eAAM,EACJ,IAAA,eAAM,EAAiC,YAAY,EAAE,GAAG,EAAE;IACxD,+EAA+E;IAC/E,mEAAmE;IACnE,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;SAC9C,WAAW,EAAE;SACb,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;SAClB,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEnB,OAAO,GAAG,aAAa,iBAAiB,CAAA;AAC1C,CAAC,CAAC,CACH,CACF,CACF,CACF,CAAA;AApBU,QAAA,QAAQ,YAoBlB"}
|
|
@@ -5,7 +5,7 @@ import { AuthenticationGeneratorContext } from '../index'
|
|
|
5
5
|
const migrationTemplate = ({
|
|
6
6
|
kebabName,
|
|
7
7
|
authStrategies
|
|
8
|
-
}: AuthenticationGeneratorContext) => `import type { Knex } from 'knex'
|
|
8
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import type { Knex } from 'knex'
|
|
9
9
|
|
|
10
10
|
export async function up(knex: Knex): Promise<void> {
|
|
11
11
|
await knex.schema.alterTable('${kebabName}', function (table) {
|
|
@@ -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
|
|
45
|
+
(ctx) => getDatabaseAdapter(ctx.feathers?.database) === 'knex',
|
|
46
46
|
renderSource(
|
|
47
47
|
migrationTemplate,
|
|
48
48
|
toFile(
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
+
const commons_1 = require("../../commons");
|
|
6
|
+
const template = ({ camelName, upperName, authStrategies, type, relative }) => /* ts */ `import { resolve, jsonSchema } from '@feathersjs/schema'
|
|
7
|
+
import type { FromSchema } from '@feathersjs/schema'
|
|
8
|
+
${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
|
|
9
|
+
|
|
10
|
+
import type { HookContext } from '${relative}/declarations'
|
|
11
|
+
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
12
|
+
|
|
13
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
14
|
+
export const ${camelName}DataSchema = {
|
|
15
|
+
$id: '${upperName}Data',
|
|
16
|
+
type: 'object',
|
|
17
|
+
additionalProperties: false,
|
|
18
|
+
required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
|
|
19
|
+
properties: {
|
|
20
|
+
${authStrategies
|
|
21
|
+
.map((name) => name === 'local'
|
|
22
|
+
? ` email: { type: 'string' },
|
|
23
|
+
password: { type: 'string' }`
|
|
24
|
+
: ` ${name}Id: { type: 'string' }`)
|
|
25
|
+
.join(',\n')}
|
|
26
|
+
}
|
|
27
|
+
} as const
|
|
28
|
+
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
29
|
+
export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
|
|
30
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
31
|
+
properties: {
|
|
32
|
+
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Schema for the data that is being returned
|
|
37
|
+
export const ${camelName}Schema = {
|
|
38
|
+
$id: '${upperName}',
|
|
39
|
+
type: 'object',
|
|
40
|
+
additionalProperties: false,
|
|
41
|
+
required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
|
|
42
|
+
properties: {
|
|
43
|
+
...${camelName}DataSchema.properties,
|
|
44
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
45
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} as const
|
|
49
|
+
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
50
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
51
|
+
properties: {}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
55
|
+
properties: {
|
|
56
|
+
// The password should never be visible externally
|
|
57
|
+
password: async () => undefined
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Schema for allowed query properties
|
|
62
|
+
export const ${camelName}QuerySchema = {
|
|
63
|
+
$id: '${upperName}Query',
|
|
64
|
+
type: 'object',
|
|
65
|
+
additionalProperties: false,
|
|
66
|
+
properties: {
|
|
67
|
+
...jsonSchema.querySyntax(${camelName}Schema.properties)
|
|
68
|
+
}
|
|
69
|
+
} as const
|
|
70
|
+
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
71
|
+
export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
|
|
72
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
73
|
+
properties: {
|
|
74
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
75
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
76
|
+
if (context.params.user) {
|
|
77
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return value
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
`;
|
|
85
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, pinion_1.when)(({ schema }) => schema === 'json', (0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
86
|
+
lib,
|
|
87
|
+
'services',
|
|
88
|
+
...folder,
|
|
89
|
+
`${fileName}.schema`
|
|
90
|
+
]), { force: true })));
|
|
91
|
+
exports.generate = generate;
|
|
92
|
+
//# sourceMappingURL=schema.json.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/authentication/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,cAAc,EACd,IAAI,EACJ,QAAQ,EACuB,EAAE,EAAE,CAAC,QAAQ,CAAC;;EAE7C,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,EAAE;;oCAEvE,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;UACd,SAAS;;;gBAGH,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE;;MAE3D,cAAc;KACb,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACZ,IAAI,KAAK,OAAO;IACd,CAAC,CAAC;iCACqB;IACvB,CAAC,CAAC,OAAO,IAAI,wBAAwB,CACxC;KACA,IAAI,CAAC,KAAK,CAAC;;;cAGJ,SAAS,4BAA4B,SAAS;eAC7C,SAAS,+CAA+C,SAAS;eACjE,SAAS,0BAA0B,SAAS;;MAErD,cAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,+CAA+C,CAAC,CAAC,CAAC,EAAE;;;;;eAK9E,SAAS;UACd,SAAS;;;mBAGA,SAAS,yBAAyB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;SAE7E,SAAS;MACZ,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;eACxB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;;;;cAIzC,SAAS,wBAAwB,SAAS;eACzC,SAAS,sBAAsB,SAAS;;;;eAIxC,SAAS,8BAA8B,SAAS;;;;;;;;eAQhD,SAAS;UACd,SAAS;;;;gCAIa,SAAS;;;cAG3B,SAAS,6BAA6B,SAAS;eAC9C,SAAS,4CAA4C,SAAS;eAC9D,SAAS,2BAA2B,SAAS;;;MAGtD,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;qCAEF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;;;;;;CAOrE,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAmC,EAAE,EAAE,CAC9D,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,aAAI,EACF,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,EACjC,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAkC,EAAE,EAAE,CAAC;IACpE,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,EACF,EAAE,KAAK,EAAE,IAAI,EAAE,CAChB,CACF,CACF,CAAA;AAfU,QAAA,QAAQ,YAelB"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { generator, toFile, when } from '@feathershq/pinion'
|
|
2
|
+
import { renderSource } from '../../commons'
|
|
3
|
+
import { AuthenticationGeneratorContext } from '../index'
|
|
4
|
+
|
|
5
|
+
const template = ({
|
|
6
|
+
camelName,
|
|
7
|
+
upperName,
|
|
8
|
+
authStrategies,
|
|
9
|
+
type,
|
|
10
|
+
relative
|
|
11
|
+
}: AuthenticationGeneratorContext) => /* ts */ `import { resolve, jsonSchema } from '@feathersjs/schema'
|
|
12
|
+
import type { FromSchema } from '@feathersjs/schema'
|
|
13
|
+
${authStrategies.includes('local') ? `import { passwordHash } from '@feathersjs/authentication-local'` : ''}
|
|
14
|
+
|
|
15
|
+
import type { HookContext } from '${relative}/declarations'
|
|
16
|
+
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
17
|
+
|
|
18
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
19
|
+
export const ${camelName}DataSchema = {
|
|
20
|
+
$id: '${upperName}Data',
|
|
21
|
+
type: 'object',
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
required: [ ${authStrategies.includes('local') ? "'email'" : ''} ],
|
|
24
|
+
properties: {
|
|
25
|
+
${authStrategies
|
|
26
|
+
.map((name) =>
|
|
27
|
+
name === 'local'
|
|
28
|
+
? ` email: { type: 'string' },
|
|
29
|
+
password: { type: 'string' }`
|
|
30
|
+
: ` ${name}Id: { type: 'string' }`
|
|
31
|
+
)
|
|
32
|
+
.join(',\n')}
|
|
33
|
+
}
|
|
34
|
+
} as const
|
|
35
|
+
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
36
|
+
export const ${camelName}DataValidator = jsonSchema.getDataValidator(${camelName}DataSchema, dataValidator)
|
|
37
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
38
|
+
properties: {
|
|
39
|
+
${authStrategies.includes('local') ? `password: passwordHash({ strategy: 'local' })` : ''}
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// Schema for the data that is being returned
|
|
44
|
+
export const ${camelName}Schema = {
|
|
45
|
+
$id: '${upperName}',
|
|
46
|
+
type: 'object',
|
|
47
|
+
additionalProperties: false,
|
|
48
|
+
required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
|
|
49
|
+
properties: {
|
|
50
|
+
...${camelName}DataSchema.properties,
|
|
51
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
52
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} as const
|
|
56
|
+
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
57
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
58
|
+
properties: {}
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
62
|
+
properties: {
|
|
63
|
+
// The password should never be visible externally
|
|
64
|
+
password: async () => undefined
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Schema for allowed query properties
|
|
69
|
+
export const ${camelName}QuerySchema = {
|
|
70
|
+
$id: '${upperName}Query',
|
|
71
|
+
type: 'object',
|
|
72
|
+
additionalProperties: false,
|
|
73
|
+
properties: {
|
|
74
|
+
...jsonSchema.querySyntax(${camelName}Schema.properties)
|
|
75
|
+
}
|
|
76
|
+
} as const
|
|
77
|
+
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
78
|
+
export const ${camelName}QueryValidator = jsonSchema.getValidator(${camelName}QuerySchema, queryValidator)
|
|
79
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
80
|
+
properties: {
|
|
81
|
+
// If there is a user (e.g. with authentication), they are only allowed to see their own data
|
|
82
|
+
${type === 'mongodb' ? '_id' : 'id'}: async (value, user, context) => {
|
|
83
|
+
if (context.params.user) {
|
|
84
|
+
return context.params.user.${type === 'mongodb' ? '_id' : 'id'}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return value
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
`
|
|
92
|
+
|
|
93
|
+
export const generate = (ctx: AuthenticationGeneratorContext) =>
|
|
94
|
+
generator(ctx).then(
|
|
95
|
+
when<AuthenticationGeneratorContext>(
|
|
96
|
+
({ schema }) => schema === 'json',
|
|
97
|
+
renderSource(
|
|
98
|
+
template,
|
|
99
|
+
toFile(({ lib, folder, fileName }: AuthenticationGeneratorContext) => [
|
|
100
|
+
lib,
|
|
101
|
+
'services',
|
|
102
|
+
...folder,
|
|
103
|
+
`${fileName}.schema`
|
|
104
|
+
]),
|
|
105
|
+
{ force: true }
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
)
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { AuthenticationGeneratorContext } from '../index';
|
|
2
|
+
export declare const template: ({ camelName, upperName, authStrategies, type, relative }: AuthenticationGeneratorContext) => string;
|
|
2
3
|
export declare const generate: (ctx: AuthenticationGeneratorContext) => Promise<AuthenticationGeneratorContext>;
|