@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.
- package/CHANGELOG.md +30 -37
- 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 +88 -51
- 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/{configuration.tpl.d.ts → client.test.tpl.d.ts} +0 -0
- package/lib/app/templates/client.test.tpl.js +27 -0
- package/lib/app/templates/client.test.tpl.js.map +1 -0
- package/lib/app/templates/client.test.tpl.ts +26 -0
- package/lib/app/templates/client.tpl.js +3 -3
- package/lib/app/templates/client.tpl.js.map +1 -1
- package/lib/app/templates/client.tpl.ts +3 -4
- 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 +9 -3
- package/lib/app/templates/logger.tpl.js.map +1 -1
- package/lib/app/templates/logger.tpl.ts +10 -4
- 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/schemas.tpl.d.ts +2 -0
- package/lib/app/templates/schemas.tpl.js +75 -0
- package/lib/app/templates/schemas.tpl.js.map +1 -0
- package/lib/app/templates/schemas.tpl.ts +89 -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 +5 -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/{test.tpl.d.ts → client.test.tpl.d.ts} +0 -0
- package/lib/authentication/templates/client.test.tpl.js +66 -0
- package/lib/authentication/templates/client.test.tpl.js.map +1 -0
- package/lib/authentication/templates/client.test.tpl.ts +80 -0
- package/lib/{service/templates/schema.tpl.d.ts → authentication/templates/client.tpl.d.ts} +1 -1
- package/lib/authentication/templates/client.tpl.js +14 -0
- package/lib/authentication/templates/client.tpl.js.map +1 -0
- package/lib/authentication/templates/client.tpl.ts +19 -0
- 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 +4 -4
- package/lib/authentication/templates/knex.tpl.js.map +1 -1
- package/lib/authentication/templates/knex.tpl.ts +5 -5
- 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 +77 -0
- package/lib/authentication/templates/schema.typebox.tpl.js.map +1 -0
- package/lib/authentication/templates/schema.typebox.tpl.ts +94 -0
- 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 -60
- package/lib/service/index.js +41 -4
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +61 -7
- package/lib/service/templates/client.tpl.js +21 -18
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +52 -24
- package/lib/service/templates/{class.tpl.d.ts → schema.json.tpl.d.ts} +0 -0
- package/lib/service/templates/schema.json.tpl.js +75 -0
- package/lib/service/templates/schema.json.tpl.js.map +1 -0
- package/lib/service/templates/schema.json.tpl.ts +87 -0
- package/lib/service/templates/{resolver.tpl.d.ts → schema.typebox.tpl.d.ts} +0 -0
- package/lib/service/templates/schema.typebox.tpl.js +55 -0
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -0
- package/lib/service/templates/schema.typebox.tpl.ts +67 -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 +37 -25
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +54 -31
- package/lib/service/type/mongodb.tpl.d.ts +1 -2
- package/lib/service/type/mongodb.tpl.js +32 -20
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +49 -29
- package/package.json +24 -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/test.tpl.js +0 -43
- package/lib/authentication/templates/test.tpl.js.map +0 -1
- package/lib/authentication/templates/test.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.js +0 -75
- package/lib/service/templates/schema.tpl.js.map +0 -1
- package/lib/service/templates/schema.tpl.ts +0 -80
package/lib/index.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
15
|
};
|
|
12
|
-
exports
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
.then((0, pinion_1.runGenerator)(__dirname, (ctx) => `${ctx._[1]}`, 'index'));
|
|
16
|
-
exports.generate = generate;
|
|
17
|
-
const command = (yargs) => yargs
|
|
18
|
-
.command('generate', 'Run a generator', (yarg) => yarg
|
|
19
|
-
.command('app', 'Generate a new app', exports.commandRunner)
|
|
20
|
-
.command('service', 'Generate a service', exports.commandRunner)
|
|
21
|
-
.command('hook', 'Generate a hook', exports.commandRunner)
|
|
22
|
-
.command('connection', 'Connect to a different database', exports.commandRunner)
|
|
23
|
-
.command('authentication', 'Set up authentication with a custom entity', exports.commandRunner))
|
|
24
|
-
.usage('Usage: $0 <command> [options]')
|
|
25
|
-
.help();
|
|
26
|
-
exports.command = command;
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cli"), exports);
|
|
18
|
+
__exportStar(require("./commons"), exports);
|
|
27
19
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,4CAAyB"}
|
package/lib/index.ts
CHANGED
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const commandRunner = (yarg: any) => {
|
|
5
|
-
const ctx = getContext<FeathersBaseContext>({
|
|
6
|
-
...yarg.argv
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
return generate(ctx)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const generate = (ctx: FeathersBaseContext) =>
|
|
13
|
-
generator(ctx)
|
|
14
|
-
.then(initializeBaseContext())
|
|
15
|
-
.then(runGenerator(__dirname, (ctx: FeathersBaseContext) => `${ctx._[1]}`, 'index'))
|
|
16
|
-
|
|
17
|
-
export const command = (yargs: Argv) =>
|
|
18
|
-
yargs
|
|
19
|
-
.command('generate', 'Run a generator', (yarg) =>
|
|
20
|
-
yarg
|
|
21
|
-
.command('app', 'Generate a new app', commandRunner)
|
|
22
|
-
.command('service', 'Generate a service', commandRunner)
|
|
23
|
-
.command('hook', 'Generate a hook', commandRunner)
|
|
24
|
-
.command('connection', 'Connect to a different database', commandRunner)
|
|
25
|
-
.command('authentication', 'Set up authentication with a custom entity', commandRunner)
|
|
26
|
-
)
|
|
27
|
-
.usage('Usage: $0 <command> [options]')
|
|
28
|
-
.help()
|
|
1
|
+
export * from './cli'
|
|
2
|
+
export * from './commons'
|
package/lib/service/index.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
32
32
|
* The actual filename (the last element of the path)
|
|
33
33
|
*/
|
|
34
34
|
fileName: string;
|
|
35
|
+
/**
|
|
36
|
+
* The kebab-cased name of the path. Will be used for e.g. database names
|
|
37
|
+
*/
|
|
38
|
+
kebabPath: string;
|
|
35
39
|
/**
|
|
36
40
|
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
37
41
|
*/
|
|
@@ -40,6 +44,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
40
44
|
* The chosen service type
|
|
41
45
|
*/
|
|
42
46
|
type: 'knex' | 'mongodb' | 'custom';
|
|
47
|
+
/**
|
|
48
|
+
* Which schema definition format to use
|
|
49
|
+
*/
|
|
50
|
+
schema: 'typebox' | 'json' | false;
|
|
43
51
|
/**
|
|
44
52
|
* Wether this service uses authentication
|
|
45
53
|
*/
|
|
@@ -52,63 +60,5 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
52
60
|
/**
|
|
53
61
|
* Parameters the generator is called with
|
|
54
62
|
*/
|
|
55
|
-
export declare type ServiceGeneratorArguments = FeathersBaseContext & Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService'>>;
|
|
56
|
-
export declare const generate: (ctx: ServiceGeneratorArguments) => Promise<
|
|
57
|
-
/**
|
|
58
|
-
* The chosen service name
|
|
59
|
-
*/
|
|
60
|
-
name: string;
|
|
61
|
-
/**
|
|
62
|
-
* The path the service is registered on
|
|
63
|
-
*/
|
|
64
|
-
path: string;
|
|
65
|
-
/**
|
|
66
|
-
* The list of subfolders this service is in
|
|
67
|
-
*/
|
|
68
|
-
folder: string[];
|
|
69
|
-
/**
|
|
70
|
-
* The `camelCase` service name starting with a lowercase letter
|
|
71
|
-
*/
|
|
72
|
-
camelName: string;
|
|
73
|
-
/**
|
|
74
|
-
* The `CamelCase` service name starting with an uppercase letter
|
|
75
|
-
*/
|
|
76
|
-
upperName: string;
|
|
77
|
-
/**
|
|
78
|
-
* The service class name combined as `CamelCaseService`
|
|
79
|
-
*/
|
|
80
|
-
className: string;
|
|
81
|
-
/**
|
|
82
|
-
* A kebab-cased (filename friendly) version of the service name
|
|
83
|
-
*/
|
|
84
|
-
kebabName: string;
|
|
85
|
-
/**
|
|
86
|
-
* The actual filename (the last element of the path)
|
|
87
|
-
*/
|
|
88
|
-
fileName: string;
|
|
89
|
-
/**
|
|
90
|
-
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
91
|
-
*/
|
|
92
|
-
relative: string;
|
|
93
|
-
/**
|
|
94
|
-
* The chosen service type
|
|
95
|
-
*/
|
|
96
|
-
type: 'knex' | 'mongodb' | 'custom';
|
|
97
|
-
/**
|
|
98
|
-
* Wether this service uses authentication
|
|
99
|
-
*/
|
|
100
|
-
authentication: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* Set to true if this service is for an authentication entity
|
|
103
|
-
*/
|
|
104
|
-
isEntityService?: boolean;
|
|
105
|
-
feathers: import("../commons").FeathersAppInfo;
|
|
106
|
-
pkg: import("../commons").AppPackageJson;
|
|
107
|
-
lib: string;
|
|
108
|
-
test: string;
|
|
109
|
-
language: "js" | "ts";
|
|
110
|
-
dependencyVersions?: import("../commons").DependencyVersions;
|
|
111
|
-
cwd: string;
|
|
112
|
-
_?: (string | number)[];
|
|
113
|
-
pinion: import("@feathershq/pinion").Configuration;
|
|
114
|
-
}>;
|
|
63
|
+
export declare type ServiceGeneratorArguments = FeathersBaseContext & Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>>;
|
|
64
|
+
export declare const generate: (ctx: ServiceGeneratorArguments) => Promise<ServiceGeneratorContext>;
|
package/lib/service/index.js
CHANGED
|
@@ -8,19 +8,33 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
8
8
|
const pinion_1 = require("@feathershq/pinion");
|
|
9
9
|
const commons_1 = require("../commons");
|
|
10
10
|
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
11
|
-
.then((0,
|
|
11
|
+
.then((0, commons_1.initializeBaseContext)())
|
|
12
|
+
.then((0, commons_1.checkPreconditions)())
|
|
13
|
+
.then((0, pinion_1.prompt)(({ name, path, type, schema, authentication, isEntityService, feathers }) => [
|
|
12
14
|
{
|
|
13
15
|
name: 'name',
|
|
14
16
|
type: 'input',
|
|
15
17
|
when: !name,
|
|
16
|
-
message: 'What is the name of your service?'
|
|
18
|
+
message: 'What is the name of your service?',
|
|
19
|
+
validate: (input) => {
|
|
20
|
+
if (!input || input === 'authentication') {
|
|
21
|
+
return 'Invalid service name';
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
17
25
|
},
|
|
18
26
|
{
|
|
19
27
|
name: 'path',
|
|
20
28
|
type: 'input',
|
|
21
29
|
when: !path,
|
|
22
30
|
message: 'Which path should the service be registered on?',
|
|
23
|
-
default: (answers) => `${lodash_1.default.kebabCase(answers.name)}
|
|
31
|
+
default: (answers) => `${lodash_1.default.kebabCase(answers.name)}`,
|
|
32
|
+
validate: (input) => {
|
|
33
|
+
if (!input || input === 'authentication') {
|
|
34
|
+
return 'Invalid service path';
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
24
38
|
},
|
|
25
39
|
{
|
|
26
40
|
name: 'authentication',
|
|
@@ -33,7 +47,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
33
47
|
type: 'list',
|
|
34
48
|
when: !type,
|
|
35
49
|
message: 'What kind of service is it?',
|
|
36
|
-
default: (0, commons_1.getDatabaseAdapter)(
|
|
50
|
+
default: (0, commons_1.getDatabaseAdapter)(feathers === null || feathers === void 0 ? void 0 : feathers.database),
|
|
37
51
|
choices: [
|
|
38
52
|
{
|
|
39
53
|
value: 'knex',
|
|
@@ -48,6 +62,27 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
48
62
|
name: 'A custom service'
|
|
49
63
|
}
|
|
50
64
|
]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'schema',
|
|
68
|
+
type: 'list',
|
|
69
|
+
when: schema === undefined,
|
|
70
|
+
message: 'Which schema definition format do you want to use?',
|
|
71
|
+
default: feathers === null || feathers === void 0 ? void 0 : feathers.schema,
|
|
72
|
+
choices: [
|
|
73
|
+
{
|
|
74
|
+
value: 'typebox',
|
|
75
|
+
name: 'TypeBox'
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
value: 'json',
|
|
79
|
+
name: 'JSON schema'
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: false,
|
|
83
|
+
name: 'No schema'
|
|
84
|
+
}
|
|
85
|
+
]
|
|
51
86
|
}
|
|
52
87
|
]))
|
|
53
88
|
.then(async (ctx) => {
|
|
@@ -59,6 +94,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
59
94
|
const folder = path.split('/').filter((el) => el !== '');
|
|
60
95
|
const relative = ['', ...folder].map(() => '..').join('/');
|
|
61
96
|
const fileName = lodash_1.default.last(folder);
|
|
97
|
+
const kebabPath = lodash_1.default.kebabCase(path);
|
|
62
98
|
return {
|
|
63
99
|
name,
|
|
64
100
|
type,
|
|
@@ -69,6 +105,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
69
105
|
className,
|
|
70
106
|
kebabName,
|
|
71
107
|
camelName,
|
|
108
|
+
kebabPath,
|
|
72
109
|
relative,
|
|
73
110
|
...ctx
|
|
74
111
|
};
|
package/lib/service/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAsB;AACtB,+CAAmF;AAEnF,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"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"}
|
package/lib/service/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import _ from 'lodash'
|
|
2
2
|
import { generator, runGenerator, runGenerators, prompt } from '@feathershq/pinion'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
checkPreconditions,
|
|
6
|
+
FeathersBaseContext,
|
|
7
|
+
getDatabaseAdapter,
|
|
8
|
+
initializeBaseContext
|
|
9
|
+
} from '../commons'
|
|
5
10
|
|
|
6
11
|
export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
7
12
|
/**
|
|
@@ -36,6 +41,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
36
41
|
* The actual filename (the last element of the path)
|
|
37
42
|
*/
|
|
38
43
|
fileName: string
|
|
44
|
+
/**
|
|
45
|
+
* The kebab-cased name of the path. Will be used for e.g. database names
|
|
46
|
+
*/
|
|
47
|
+
kebabPath: string
|
|
39
48
|
/**
|
|
40
49
|
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
41
50
|
*/
|
|
@@ -44,6 +53,10 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
44
53
|
* The chosen service type
|
|
45
54
|
*/
|
|
46
55
|
type: 'knex' | 'mongodb' | 'custom'
|
|
56
|
+
/**
|
|
57
|
+
* Which schema definition format to use
|
|
58
|
+
*/
|
|
59
|
+
schema: 'typebox' | 'json' | false
|
|
47
60
|
/**
|
|
48
61
|
* Wether this service uses authentication
|
|
49
62
|
*/
|
|
@@ -58,25 +71,43 @@ export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
|
58
71
|
* Parameters the generator is called with
|
|
59
72
|
*/
|
|
60
73
|
export type ServiceGeneratorArguments = FeathersBaseContext &
|
|
61
|
-
Partial<
|
|
74
|
+
Partial<
|
|
75
|
+
Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService' | 'schema'>
|
|
76
|
+
>
|
|
62
77
|
|
|
63
78
|
export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
64
79
|
generator(ctx)
|
|
80
|
+
.then(initializeBaseContext())
|
|
81
|
+
.then(checkPreconditions())
|
|
65
82
|
.then(
|
|
66
83
|
prompt<ServiceGeneratorArguments, ServiceGeneratorContext>(
|
|
67
|
-
({ name, path, type, authentication, isEntityService }) => [
|
|
84
|
+
({ name, path, type, schema, authentication, isEntityService, feathers }) => [
|
|
68
85
|
{
|
|
69
86
|
name: 'name',
|
|
70
87
|
type: 'input',
|
|
71
88
|
when: !name,
|
|
72
|
-
message: 'What is the name of your service?'
|
|
89
|
+
message: 'What is the name of your service?',
|
|
90
|
+
validate: (input) => {
|
|
91
|
+
if (!input || input === 'authentication') {
|
|
92
|
+
return 'Invalid service name'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
73
97
|
},
|
|
74
98
|
{
|
|
75
99
|
name: 'path',
|
|
76
100
|
type: 'input',
|
|
77
101
|
when: !path,
|
|
78
102
|
message: 'Which path should the service be registered on?',
|
|
79
|
-
default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}
|
|
103
|
+
default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`,
|
|
104
|
+
validate: (input) => {
|
|
105
|
+
if (!input || input === 'authentication') {
|
|
106
|
+
return 'Invalid service path'
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
80
111
|
},
|
|
81
112
|
{
|
|
82
113
|
name: 'authentication',
|
|
@@ -89,7 +120,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
89
120
|
type: 'list',
|
|
90
121
|
when: !type,
|
|
91
122
|
message: 'What kind of service is it?',
|
|
92
|
-
default: getDatabaseAdapter(
|
|
123
|
+
default: getDatabaseAdapter(feathers?.database),
|
|
93
124
|
choices: [
|
|
94
125
|
{
|
|
95
126
|
value: 'knex',
|
|
@@ -104,11 +135,32 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
104
135
|
name: 'A custom service'
|
|
105
136
|
}
|
|
106
137
|
]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'schema',
|
|
141
|
+
type: 'list',
|
|
142
|
+
when: schema === undefined,
|
|
143
|
+
message: 'Which schema definition format do you want to use?',
|
|
144
|
+
default: feathers?.schema,
|
|
145
|
+
choices: [
|
|
146
|
+
{
|
|
147
|
+
value: 'typebox',
|
|
148
|
+
name: 'TypeBox'
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
value: 'json',
|
|
152
|
+
name: 'JSON schema'
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
value: false,
|
|
156
|
+
name: 'No schema'
|
|
157
|
+
}
|
|
158
|
+
]
|
|
107
159
|
}
|
|
108
160
|
]
|
|
109
161
|
)
|
|
110
162
|
)
|
|
111
|
-
.then(async (ctx) => {
|
|
163
|
+
.then(async (ctx): Promise<ServiceGeneratorContext> => {
|
|
112
164
|
const { name, path, type } = ctx
|
|
113
165
|
const kebabName = _.kebabCase(name)
|
|
114
166
|
const camelName = _.camelCase(name)
|
|
@@ -118,6 +170,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
118
170
|
const folder = path.split('/').filter((el) => el !== '')
|
|
119
171
|
const relative = ['', ...folder].map(() => '..').join('/')
|
|
120
172
|
const fileName = _.last(folder)
|
|
173
|
+
const kebabPath = _.kebabCase(path)
|
|
121
174
|
|
|
122
175
|
return {
|
|
123
176
|
name,
|
|
@@ -129,6 +182,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
129
182
|
className,
|
|
130
183
|
kebabName,
|
|
131
184
|
camelName,
|
|
185
|
+
kebabPath,
|
|
132
186
|
relative,
|
|
133
187
|
...ctx
|
|
134
188
|
}
|
|
@@ -2,27 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generate = void 0;
|
|
4
4
|
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
-
const
|
|
5
|
+
const commons_1 = require("../../commons");
|
|
6
|
+
const importTemplate = ({ upperName, folder, fileName, className }) => /* ts */ `import type {
|
|
7
|
+
${upperName},
|
|
6
8
|
${upperName}Data,
|
|
7
|
-
${upperName}Patch,
|
|
8
|
-
${upperName}Result,
|
|
9
9
|
${upperName}Query,
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
${className}
|
|
11
|
+
} from './services/${folder.join('/')}/${fileName}'
|
|
12
12
|
export type {
|
|
13
|
+
${upperName},
|
|
13
14
|
${upperName}Data,
|
|
14
|
-
${upperName}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
15
|
+
${upperName}Query
|
|
16
|
+
}
|
|
17
|
+
`;
|
|
18
|
+
const methodsTemplate = ({ camelName, upperName, className, type }) => `const ${camelName}ServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'] as const
|
|
19
|
+
type ${upperName}ClientService = Pick<${className}${type !== 'custom' ? `<Params<${upperName}Query>>` : ''}, typeof ${camelName}ServiceMethods[number]>
|
|
20
|
+
`;
|
|
21
|
+
const declarationTemplate = ({ path, upperName }) => ` '${path}': ${upperName}ClientService`;
|
|
22
|
+
const registrationTemplate = ({ camelName, path }) => ` client.use('${path}', connection.service('${path}'), {
|
|
23
|
+
methods: ${camelName}ServiceMethods
|
|
24
|
+
})`;
|
|
25
|
+
const toClientFile = (0, pinion_1.toFile)(({ lib }) => [lib, 'client']);
|
|
26
|
+
const generate = async (ctx) => (0, pinion_1.generator)(ctx)
|
|
27
|
+
.then((0, commons_1.injectSource)(registrationTemplate, (0, pinion_1.before)('return client'), (0, pinion_1.toFile)(({ lib }) => [lib, 'client'])))
|
|
28
|
+
.then((0, pinion_1.when)((ctx) => ctx.language === 'js', (0, commons_1.injectSource)(methodsTemplate, (0, pinion_1.before)('\nexport const createClient'), toClientFile)))
|
|
29
|
+
.then((0, pinion_1.when)((ctx) => ctx.language === 'ts', (0, commons_1.injectSource)(methodsTemplate, (0, pinion_1.before)('\nexport interface ServiceTypes'), toClientFile), (0, commons_1.injectSource)(importTemplate, (0, pinion_1.after)("from '@feathersjs/feathers'"), toClientFile), (0, commons_1.injectSource)(declarationTemplate, (0, pinion_1.after)('export interface ServiceTypes'), toClientFile)));
|
|
27
30
|
exports.generate = generate;
|
|
28
31
|
//# sourceMappingURL=client.tpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/client.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA2E;
|
|
1
|
+
{"version":3,"file":"client.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/client.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA2E;AAC3E,2CAA4C;AAG5C,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,MAAM,EACN,QAAQ,EACR,SAAS,EACe,EAAE,EAAE,CAAC,QAAQ,CAAC;IACpC,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;qBACQ,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ;;IAE7C,SAAS;IACT,SAAS;IACT,SAAS;;CAEZ,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAA2B,EAAE,EAAE,CAC7F,SAAS,SAAS;OACb,SAAS,wBAAwB,SAAS,GAC7C,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,SAAS,SAAS,CAAC,CAAC,CAAC,EACtD,YAAY,SAAS;CACtB,CAAA;AAED,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAA2B,EAAE,EAAE,CAC3E,MAAM,IAAI,MAAM,SAAS,eAAe,CAAA;AAE1C,MAAM,oBAAoB,GAAG,CAAC,EAC5B,SAAS,EACT,IAAI,EACoB,EAAE,EAAE,CAAC,iBAAiB,IAAI,0BAA0B,IAAI;aACrE,SAAS;GACnB,CAAA;AAEH,MAAM,YAAY,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAA;AAE3E,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,oBAAoB,EACpB,IAAA,eAAM,EAAC,eAAe,CAAC,EACvB,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAC9D,CACF;KACA,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,sBAAY,EAAC,eAAe,EAAE,IAAA,eAAM,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,CACnF,CACF;KACA,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,sBAAY,EAAC,eAAe,EAAE,IAAA,eAAM,EAAC,iCAAiC,CAAC,EAAE,YAAY,CAAC,EACtF,IAAA,sBAAY,EAAC,cAAc,EAAE,IAAA,cAAK,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,EAChF,IAAA,sBAAY,EAAC,mBAAmB,EAAE,IAAA,cAAK,EAAC,+BAA+B,CAAC,EAAE,YAAY,CAAC,CACxF,CACF,CAAA;AAtBQ,QAAA,QAAQ,YAsBhB"}
|
|
@@ -1,36 +1,64 @@
|
|
|
1
|
-
import { generator,
|
|
1
|
+
import { generator, toFile, when, after, before } from '@feathershq/pinion'
|
|
2
|
+
import { injectSource } from '../../commons'
|
|
2
3
|
import { ServiceGeneratorContext } from '../index'
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
+
const importTemplate = ({
|
|
6
|
+
upperName,
|
|
7
|
+
folder,
|
|
8
|
+
fileName,
|
|
9
|
+
className
|
|
10
|
+
}: ServiceGeneratorContext) => /* ts */ `import type {
|
|
11
|
+
${upperName},
|
|
5
12
|
${upperName}Data,
|
|
6
|
-
${upperName}Patch,
|
|
7
|
-
${upperName}Result,
|
|
8
13
|
${upperName}Query,
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
${className}
|
|
15
|
+
} from './services/${folder.join('/')}/${fileName}'
|
|
11
16
|
export type {
|
|
17
|
+
${upperName},
|
|
12
18
|
${upperName}Data,
|
|
13
|
-
${upperName}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
${upperName}Query
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
const methodsTemplate = ({ camelName, upperName, className, type }: ServiceGeneratorContext) =>
|
|
24
|
+
`const ${camelName}ServiceMethods = ['find', 'get', 'create', 'update', 'patch', 'remove'] as const
|
|
25
|
+
type ${upperName}ClientService = Pick<${className}${
|
|
26
|
+
type !== 'custom' ? `<Params<${upperName}Query>>` : ''
|
|
27
|
+
}, typeof ${camelName}ServiceMethods[number]>
|
|
28
|
+
`
|
|
17
29
|
|
|
18
30
|
const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
|
|
19
|
-
` '${path}': ClientService
|
|
20
|
-
${upperName}Result,
|
|
21
|
-
${upperName}Data,
|
|
22
|
-
${upperName}Patch,
|
|
23
|
-
Paginated<${upperName}Result>,
|
|
24
|
-
Params<${upperName}Query>
|
|
25
|
-
>`
|
|
31
|
+
` '${path}': ${upperName}ClientService`
|
|
26
32
|
|
|
27
|
-
const
|
|
33
|
+
const registrationTemplate = ({
|
|
34
|
+
camelName,
|
|
35
|
+
path
|
|
36
|
+
}: ServiceGeneratorContext) => ` client.use('${path}', connection.service('${path}'), {
|
|
37
|
+
methods: ${camelName}ServiceMethods
|
|
38
|
+
})`
|
|
39
|
+
|
|
40
|
+
const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
|
|
28
41
|
|
|
29
42
|
export const generate = async (ctx: ServiceGeneratorContext) =>
|
|
30
|
-
generator(ctx)
|
|
31
|
-
|
|
32
|
-
(
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
generator(ctx)
|
|
44
|
+
.then(
|
|
45
|
+
injectSource(
|
|
46
|
+
registrationTemplate,
|
|
47
|
+
before('return client'),
|
|
48
|
+
toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client'])
|
|
49
|
+
)
|
|
50
|
+
)
|
|
51
|
+
.then(
|
|
52
|
+
when(
|
|
53
|
+
(ctx) => ctx.language === 'js',
|
|
54
|
+
injectSource(methodsTemplate, before('\nexport const createClient'), toClientFile)
|
|
55
|
+
)
|
|
56
|
+
)
|
|
57
|
+
.then(
|
|
58
|
+
when(
|
|
59
|
+
(ctx) => ctx.language === 'ts',
|
|
60
|
+
injectSource(methodsTemplate, before('\nexport interface ServiceTypes'), toClientFile),
|
|
61
|
+
injectSource(importTemplate, after("from '@feathersjs/feathers'"), toClientFile),
|
|
62
|
+
injectSource(declarationTemplate, after('export interface ServiceTypes'), toClientFile)
|
|
63
|
+
)
|
|
35
64
|
)
|
|
36
|
-
)
|
|
File without changes
|
|
@@ -0,0 +1,75 @@
|
|
|
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, type }) => /* ts */ `import { resolve, getDataValidator, getValidator, querySyntax } from '@feathersjs/schema'
|
|
7
|
+
import type { FromSchema } from '@feathersjs/schema'
|
|
8
|
+
|
|
9
|
+
import type { HookContext } from '${relative}/declarations'
|
|
10
|
+
import { dataValidator, queryValidator } from '${relative}/schemas/validators'
|
|
11
|
+
|
|
12
|
+
// Main data model schema
|
|
13
|
+
export const ${camelName}Schema = {
|
|
14
|
+
$id: '${upperName}',
|
|
15
|
+
type: 'object',
|
|
16
|
+
additionalProperties: false,
|
|
17
|
+
required: [ '${type === 'mongodb' ? '_id' : 'id'}', 'text' ],
|
|
18
|
+
properties: {
|
|
19
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
20
|
+
type: '${type === 'mongodb' ? 'string' : 'number'}'
|
|
21
|
+
},
|
|
22
|
+
text: {
|
|
23
|
+
type: 'string'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} as const
|
|
27
|
+
export type ${upperName} = FromSchema<typeof ${camelName}Schema>
|
|
28
|
+
export const ${camelName}Resolver = resolve<${upperName}, HookContext>({
|
|
29
|
+
properties: {}
|
|
30
|
+
})
|
|
31
|
+
export const ${camelName}ExternalResolver = resolve<${upperName}, HookContext>({
|
|
32
|
+
properties: {}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Schema for creating new data
|
|
36
|
+
export const ${camelName}DataSchema = {
|
|
37
|
+
$id: '${upperName}Data',
|
|
38
|
+
type: 'object',
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
required: [ 'text' ],
|
|
41
|
+
properties: {
|
|
42
|
+
text: {
|
|
43
|
+
type: 'string'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} as const
|
|
47
|
+
export type ${upperName}Data = FromSchema<typeof ${camelName}DataSchema>
|
|
48
|
+
export const ${camelName}DataValidator = getDataValidator(${camelName}DataSchema, dataValidator)
|
|
49
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
50
|
+
properties: {}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// Schema for allowed query properties
|
|
54
|
+
export const ${camelName}QuerySchema = {
|
|
55
|
+
$id: '${upperName}Query',
|
|
56
|
+
type: 'object',
|
|
57
|
+
additionalProperties: false,
|
|
58
|
+
properties: {
|
|
59
|
+
...querySyntax(${camelName}Schema.properties)
|
|
60
|
+
}
|
|
61
|
+
} as const
|
|
62
|
+
export type ${upperName}Query = FromSchema<typeof ${camelName}QuerySchema>
|
|
63
|
+
export const ${camelName}QueryValidator = getValidator(${camelName}QuerySchema, queryValidator)
|
|
64
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
65
|
+
properties: {}
|
|
66
|
+
})
|
|
67
|
+
`;
|
|
68
|
+
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 }) => [
|
|
69
|
+
lib,
|
|
70
|
+
'services',
|
|
71
|
+
...folder,
|
|
72
|
+
`${fileName}.schema`
|
|
73
|
+
]))));
|
|
74
|
+
exports.generate = generate;
|
|
75
|
+
//# sourceMappingURL=schema.json.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.json.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.json.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA4D;AAC5D,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAChB,SAAS,EACT,SAAS,EACT,QAAQ,EACR,IAAI,EACoB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;oCAGJ,QAAQ;iDACK,QAAQ;;;eAG1C,SAAS;UACd,SAAS;;;iBAGF,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;;MAE5C,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;eACxB,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;;;;;;;cAOzC,SAAS,wBAAwB,SAAS;eACzC,SAAS,sBAAsB,SAAS;;;eAGxC,SAAS,8BAA8B,SAAS;;;;;eAKhD,SAAS;UACd,SAAS;;;;;;;;;;cAUL,SAAS,4BAA4B,SAAS;eAC7C,SAAS,oCAAoC,SAAS;eACtD,SAAS,0BAA0B,SAAS;;;;;eAK5C,SAAS;UACd,SAAS;;;;qBAIE,SAAS;;;cAGhB,SAAS,6BAA6B,SAAS;eAC9C,SAAS,iCAAiC,SAAS;eACnD,SAAS,2BAA2B,SAAS;;;CAG3D,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,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,EAA2B,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,UAAU;IACV,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,CACH,CACF,CACF,CAAA;AAdU,QAAA,QAAQ,YAclB"}
|