@feathersjs/cli 4.6.2 → 5.0.0-pre.24
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 +10 -917
- package/LICENSE +1 -1
- package/README.md +9 -34
- package/bin/feathers +9 -0
- package/lib/app/index.d.ts +29 -0
- package/lib/app/index.js +123 -0
- package/lib/app/index.js.map +1 -0
- package/lib/app/index.ts +198 -0
- package/lib/app/static/.gitignore +121 -0
- package/lib/app/templates/app.test.tpl.d.ts +2 -0
- package/lib/app/templates/app.test.tpl.js +48 -0
- package/lib/app/templates/app.test.tpl.js.map +1 -0
- package/lib/app/templates/app.test.tpl.ts +48 -0
- package/lib/app/templates/app.tpl.d.ts +2 -0
- package/lib/app/templates/app.tpl.js +110 -0
- package/lib/app/templates/app.tpl.js.map +1 -0
- package/lib/app/templates/app.tpl.ts +119 -0
- package/lib/app/templates/channels.tpl.d.ts +2 -0
- package/lib/app/templates/channels.tpl.js +76 -0
- package/lib/app/templates/channels.tpl.js.map +1 -0
- package/lib/app/templates/channels.tpl.ts +81 -0
- package/lib/app/templates/client.tpl.d.ts +2 -0
- package/lib/app/templates/client.tpl.js +22 -0
- package/lib/app/templates/client.tpl.js.map +1 -0
- package/lib/app/templates/client.tpl.ts +27 -0
- package/lib/app/templates/config.tpl.d.ts +2 -0
- package/lib/app/templates/config.tpl.js +21 -0
- package/lib/app/templates/config.tpl.js.map +1 -0
- package/lib/app/templates/config.tpl.ts +21 -0
- package/lib/app/templates/configuration.tpl.d.ts +2 -0
- package/lib/app/templates/configuration.tpl.js +36 -0
- package/lib/app/templates/configuration.tpl.js.map +1 -0
- package/lib/app/templates/configuration.tpl.ts +41 -0
- package/lib/app/templates/declarations.tpl.d.ts +2 -0
- package/lib/app/templates/declarations.tpl.js +23 -0
- package/lib/app/templates/declarations.tpl.js.map +1 -0
- package/lib/app/templates/declarations.tpl.ts +31 -0
- package/lib/app/templates/index.html.tpl.d.ts +2 -0
- package/lib/app/templates/index.html.tpl.js +85 -0
- package/lib/app/templates/index.html.tpl.js.map +1 -0
- package/lib/app/templates/index.html.tpl.ts +85 -0
- package/lib/app/templates/index.tpl.d.ts +2 -0
- package/lib/app/templates/index.tpl.js +18 -0
- package/lib/app/templates/index.tpl.js.map +1 -0
- package/lib/app/templates/index.tpl.ts +23 -0
- package/lib/app/templates/logger.tpl.d.ts +2 -0
- package/lib/app/templates/logger.tpl.js +33 -0
- package/lib/app/templates/logger.tpl.js.map +1 -0
- package/lib/app/templates/logger.tpl.ts +38 -0
- package/lib/app/templates/package.json.tpl.d.ts +2 -0
- package/lib/app/templates/package.json.tpl.js +53 -0
- package/lib/app/templates/package.json.tpl.js.map +1 -0
- package/lib/app/templates/package.json.tpl.ts +65 -0
- package/lib/app/templates/readme.md.tpl.d.ts +2 -0
- package/lib/app/templates/readme.md.tpl.js +50 -0
- package/lib/app/templates/readme.md.tpl.js.map +1 -0
- package/lib/app/templates/readme.md.tpl.ts +50 -0
- package/lib/app/templates/services.tpl.d.ts +2 -0
- package/lib/app/templates/services.tpl.js +14 -0
- package/lib/app/templates/services.tpl.js.map +1 -0
- package/lib/app/templates/services.tpl.ts +19 -0
- package/lib/app/templates/tsconfig.json.tpl.d.ts +2 -0
- package/lib/app/templates/tsconfig.json.tpl.js +20 -0
- package/lib/app/templates/tsconfig.json.tpl.js.map +1 -0
- package/lib/app/templates/tsconfig.json.tpl.ts +26 -0
- package/lib/authentication/index.d.ts +71 -0
- package/lib/authentication/index.js +94 -0
- package/lib/authentication/index.js.map +1 -0
- package/lib/authentication/index.ts +103 -0
- package/lib/authentication/templates/authentication.tpl.d.ts +2 -0
- package/lib/authentication/templates/authentication.tpl.js +40 -0
- package/lib/authentication/templates/authentication.tpl.js.map +1 -0
- package/lib/authentication/templates/authentication.tpl.ts +53 -0
- package/lib/authentication/templates/config.tpl.d.ts +2 -0
- package/lib/authentication/templates/config.tpl.js +46 -0
- package/lib/authentication/templates/config.tpl.js.map +1 -0
- package/lib/authentication/templates/config.tpl.ts +51 -0
- package/lib/authentication/templates/declarations.tpl.d.ts +2 -0
- package/lib/authentication/templates/declarations.tpl.js +19 -0
- package/lib/authentication/templates/declarations.tpl.js.map +1 -0
- package/lib/authentication/templates/declarations.tpl.ts +29 -0
- package/lib/authentication/templates/knex.tpl.d.ts +2 -0
- package/lib/authentication/templates/knex.tpl.js +41 -0
- package/lib/authentication/templates/knex.tpl.js.map +1 -0
- package/lib/authentication/templates/knex.tpl.ts +59 -0
- package/lib/authentication/templates/test.tpl.d.ts +2 -0
- package/lib/authentication/templates/test.tpl.js +43 -0
- package/lib/authentication/templates/test.tpl.js.map +1 -0
- package/lib/authentication/templates/test.tpl.ts +50 -0
- package/lib/authentication/templates/user.resolver.tpl.d.ts +2 -0
- package/lib/authentication/templates/user.resolver.tpl.js +96 -0
- package/lib/authentication/templates/user.resolver.tpl.js.map +1 -0
- package/lib/authentication/templates/user.resolver.tpl.ts +109 -0
- package/lib/authentication/templates/user.schema.tpl.d.ts +2 -0
- package/lib/authentication/templates/user.schema.tpl.js +85 -0
- package/lib/authentication/templates/user.schema.tpl.js.map +1 -0
- package/lib/authentication/templates/user.schema.tpl.ts +93 -0
- package/lib/commons.d.ts +120 -0
- package/lib/commons.js +137 -0
- package/lib/commons.js.map +1 -0
- package/lib/commons.ts +187 -0
- package/lib/connection/index.d.ts +53 -0
- package/lib/connection/index.js +86 -0
- package/lib/connection/index.js.map +1 -0
- package/lib/connection/index.ts +109 -0
- package/lib/connection/templates/knex.tpl.d.ts +2 -0
- package/lib/connection/templates/knex.tpl.js +59 -0
- package/lib/connection/templates/knex.tpl.js.map +1 -0
- package/lib/connection/templates/knex.tpl.ts +79 -0
- package/lib/connection/templates/mongodb.tpl.d.ts +2 -0
- package/lib/connection/templates/mongodb.tpl.js +39 -0
- package/lib/connection/templates/mongodb.tpl.js.map +1 -0
- package/lib/connection/templates/mongodb.tpl.ts +51 -0
- package/lib/hook/index.d.ts +22 -0
- package/lib/hook/index.js +40 -0
- package/lib/hook/index.js.map +1 -0
- package/lib/hook/index.ts +45 -0
- package/lib/hook/templates/hook.tpl.d.ts +2 -0
- package/lib/hook/templates/hook.tpl.js +21 -0
- package/lib/hook/templates/hook.tpl.js.map +1 -0
- package/lib/hook/templates/hook.tpl.ts +28 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +24 -62
- package/lib/index.js.map +1 -0
- package/lib/index.ts +27 -0
- package/lib/service/index.d.ts +130 -0
- package/lib/service/index.js +84 -0
- package/lib/service/index.js.map +1 -0
- package/lib/service/index.ts +150 -0
- package/lib/service/templates/client.tpl.d.ts +2 -0
- package/lib/service/templates/client.tpl.js +16 -0
- package/lib/service/templates/client.tpl.js.map +1 -0
- package/lib/service/templates/client.tpl.ts +27 -0
- package/lib/service/templates/resolver.tpl.d.ts +2 -0
- package/lib/service/templates/resolver.tpl.js +73 -0
- package/lib/service/templates/resolver.tpl.js.map +1 -0
- package/lib/service/templates/resolver.tpl.ts +78 -0
- package/lib/service/templates/schema.tpl.d.ts +2 -0
- package/lib/service/templates/schema.tpl.js +75 -0
- package/lib/service/templates/schema.tpl.js.map +1 -0
- package/lib/service/templates/schema.tpl.ts +80 -0
- package/lib/service/templates/service.tpl.d.ts +2 -0
- package/lib/service/templates/service.tpl.js +92 -0
- package/lib/service/templates/service.tpl.js.map +1 -0
- package/lib/service/templates/service.tpl.ts +117 -0
- package/lib/service/templates/test.tpl.d.ts +2 -0
- package/lib/service/templates/test.tpl.js +24 -0
- package/lib/service/templates/test.tpl.js.map +1 -0
- package/lib/service/templates/test.tpl.ts +29 -0
- package/lib/service/type/custom.tpl.d.ts +4 -0
- package/lib/service/type/custom.tpl.js +79 -0
- package/lib/service/type/custom.tpl.js.map +1 -0
- package/lib/service/type/custom.tpl.ts +81 -0
- package/lib/service/type/knex.tpl.d.ts +5 -0
- package/lib/service/type/knex.tpl.js +50 -0
- package/lib/service/type/knex.tpl.js.map +1 -0
- package/lib/service/type/knex.tpl.ts +62 -0
- package/lib/service/type/mongodb.tpl.d.ts +4 -0
- package/lib/service/type/mongodb.tpl.js +29 -0
- package/lib/service/type/mongodb.tpl.js.map +1 -0
- package/lib/service/type/mongodb.tpl.ts +34 -0
- package/package.json +56 -36
- package/bin/feathers.js +0 -5
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generate = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
9
|
+
const commons_1 = require("../commons");
|
|
10
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
11
|
+
.then((0, pinion_1.prompt)(({ name, path, type, authentication, isEntityService }) => [
|
|
12
|
+
{
|
|
13
|
+
name: 'name',
|
|
14
|
+
type: 'input',
|
|
15
|
+
when: !name,
|
|
16
|
+
message: 'What is the name of your service?'
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'path',
|
|
20
|
+
type: 'input',
|
|
21
|
+
when: !path,
|
|
22
|
+
message: 'Which path should the service be registered on?',
|
|
23
|
+
default: (answers) => `${lodash_1.default.kebabCase(answers.name)}`
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
name: 'authentication',
|
|
27
|
+
type: 'confirm',
|
|
28
|
+
when: authentication === undefined && !isEntityService,
|
|
29
|
+
message: 'Does this service require authentication?'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: 'type',
|
|
33
|
+
type: 'list',
|
|
34
|
+
when: !type,
|
|
35
|
+
message: 'What kind of service is it?',
|
|
36
|
+
default: (0, commons_1.getDatabaseAdapter)(ctx.feathers.database),
|
|
37
|
+
choices: [
|
|
38
|
+
{
|
|
39
|
+
value: 'knex',
|
|
40
|
+
name: 'SQL'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
value: 'mongodb',
|
|
44
|
+
name: 'MongoDB'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
value: 'custom',
|
|
48
|
+
name: 'A custom service'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
]))
|
|
53
|
+
.then(async (ctx) => {
|
|
54
|
+
const { name, path, type } = ctx;
|
|
55
|
+
const kebabName = lodash_1.default.kebabCase(name);
|
|
56
|
+
const camelName = lodash_1.default.camelCase(name);
|
|
57
|
+
const upperName = lodash_1.default.upperFirst(camelName);
|
|
58
|
+
const className = `${upperName}Service`;
|
|
59
|
+
const pathElements = path.split('/').filter((el) => el !== '');
|
|
60
|
+
const relative = pathElements.map(() => '..').join('/');
|
|
61
|
+
const folder = lodash_1.default.initial(pathElements);
|
|
62
|
+
const fileName = lodash_1.default.last(pathElements);
|
|
63
|
+
const schemaPath = ['schemas', ...folder, `${fileName}.schema`].join('/');
|
|
64
|
+
const resolverPath = ['resolvers', ...folder, `${fileName}.resolver`].join('/');
|
|
65
|
+
return {
|
|
66
|
+
name,
|
|
67
|
+
type,
|
|
68
|
+
path,
|
|
69
|
+
folder,
|
|
70
|
+
fileName,
|
|
71
|
+
upperName,
|
|
72
|
+
className,
|
|
73
|
+
kebabName,
|
|
74
|
+
camelName,
|
|
75
|
+
relative,
|
|
76
|
+
resolverPath,
|
|
77
|
+
schemaPath,
|
|
78
|
+
...ctx
|
|
79
|
+
};
|
|
80
|
+
})
|
|
81
|
+
.then((0, pinion_1.runGenerators)(__dirname, 'templates'))
|
|
82
|
+
.then((0, pinion_1.runGenerator)(__dirname, 'type', ({ type }) => `${type}.tpl`));
|
|
83
|
+
exports.generate = generate;
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import _ from 'lodash'
|
|
2
|
+
import { generator, runGenerator, runGenerators, prompt } from '@feathershq/pinion'
|
|
3
|
+
|
|
4
|
+
import { FeathersBaseContext, getDatabaseAdapter } from '../commons'
|
|
5
|
+
|
|
6
|
+
export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
7
|
+
/**
|
|
8
|
+
* The chosen service name
|
|
9
|
+
*/
|
|
10
|
+
name: string
|
|
11
|
+
/**
|
|
12
|
+
* The path the service is registered on
|
|
13
|
+
*/
|
|
14
|
+
path: string
|
|
15
|
+
/**
|
|
16
|
+
* The list of subfolders this service is in
|
|
17
|
+
*/
|
|
18
|
+
folder: string[]
|
|
19
|
+
/**
|
|
20
|
+
* The `camelCase` service name starting with a lowercase letter
|
|
21
|
+
*/
|
|
22
|
+
camelName: string
|
|
23
|
+
/**
|
|
24
|
+
* The `CamelCase` service name starting with an uppercase letter
|
|
25
|
+
*/
|
|
26
|
+
upperName: string
|
|
27
|
+
/**
|
|
28
|
+
* The service class name combined as `CamelCaseService`
|
|
29
|
+
*/
|
|
30
|
+
className: string
|
|
31
|
+
/**
|
|
32
|
+
* A kebab-cased (filename friendly) version of the service name
|
|
33
|
+
*/
|
|
34
|
+
kebabName: string
|
|
35
|
+
/**
|
|
36
|
+
* The actual filename (the last element of the path)
|
|
37
|
+
*/
|
|
38
|
+
fileName: string
|
|
39
|
+
/**
|
|
40
|
+
* Indicates how many file paths we should go up to import other things (e.g. `../../`)
|
|
41
|
+
*/
|
|
42
|
+
relative: string
|
|
43
|
+
/**
|
|
44
|
+
* The chosen service type
|
|
45
|
+
*/
|
|
46
|
+
type: 'knex' | 'mongodb' | 'custom'
|
|
47
|
+
/**
|
|
48
|
+
* Wether this service uses authentication
|
|
49
|
+
*/
|
|
50
|
+
authentication: boolean
|
|
51
|
+
/**
|
|
52
|
+
* Set to true if this service is for an authentication entity
|
|
53
|
+
*/
|
|
54
|
+
isEntityService?: boolean
|
|
55
|
+
/**
|
|
56
|
+
* The name of the schema file
|
|
57
|
+
*/
|
|
58
|
+
schemaPath: string
|
|
59
|
+
/**
|
|
60
|
+
* The name of the resolver file
|
|
61
|
+
*/
|
|
62
|
+
resolverPath: string
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Parameters the generator is called with
|
|
67
|
+
*/
|
|
68
|
+
export type ServiceGeneratorArguments = FeathersBaseContext &
|
|
69
|
+
Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService'>>
|
|
70
|
+
|
|
71
|
+
export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
72
|
+
generator(ctx)
|
|
73
|
+
.then(
|
|
74
|
+
prompt<ServiceGeneratorArguments, ServiceGeneratorContext>(
|
|
75
|
+
({ name, path, type, authentication, isEntityService }) => [
|
|
76
|
+
{
|
|
77
|
+
name: 'name',
|
|
78
|
+
type: 'input',
|
|
79
|
+
when: !name,
|
|
80
|
+
message: 'What is the name of your service?'
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'path',
|
|
84
|
+
type: 'input',
|
|
85
|
+
when: !path,
|
|
86
|
+
message: 'Which path should the service be registered on?',
|
|
87
|
+
default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: 'authentication',
|
|
91
|
+
type: 'confirm',
|
|
92
|
+
when: authentication === undefined && !isEntityService,
|
|
93
|
+
message: 'Does this service require authentication?'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: 'type',
|
|
97
|
+
type: 'list',
|
|
98
|
+
when: !type,
|
|
99
|
+
message: 'What kind of service is it?',
|
|
100
|
+
default: getDatabaseAdapter(ctx.feathers.database),
|
|
101
|
+
choices: [
|
|
102
|
+
{
|
|
103
|
+
value: 'knex',
|
|
104
|
+
name: 'SQL'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
value: 'mongodb',
|
|
108
|
+
name: 'MongoDB'
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
value: 'custom',
|
|
112
|
+
name: 'A custom service'
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
]
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
.then(async (ctx) => {
|
|
120
|
+
const { name, path, type } = ctx
|
|
121
|
+
const kebabName = _.kebabCase(name)
|
|
122
|
+
const camelName = _.camelCase(name)
|
|
123
|
+
const upperName = _.upperFirst(camelName)
|
|
124
|
+
const className = `${upperName}Service`
|
|
125
|
+
|
|
126
|
+
const pathElements = path.split('/').filter((el) => el !== '')
|
|
127
|
+
const relative = pathElements.map(() => '..').join('/')
|
|
128
|
+
const folder = _.initial(pathElements)
|
|
129
|
+
const fileName = _.last(pathElements)
|
|
130
|
+
const schemaPath = ['schemas', ...folder, `${fileName}.schema`].join('/')
|
|
131
|
+
const resolverPath = ['resolvers', ...folder, `${fileName}.resolver`].join('/')
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
name,
|
|
135
|
+
type,
|
|
136
|
+
path,
|
|
137
|
+
folder,
|
|
138
|
+
fileName,
|
|
139
|
+
upperName,
|
|
140
|
+
className,
|
|
141
|
+
kebabName,
|
|
142
|
+
camelName,
|
|
143
|
+
relative,
|
|
144
|
+
resolverPath,
|
|
145
|
+
schemaPath,
|
|
146
|
+
...ctx
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
.then(runGenerators<ServiceGeneratorContext>(__dirname, 'templates'))
|
|
150
|
+
.then(runGenerator<ServiceGeneratorContext>(__dirname, 'type', ({ type }) => `${type}.tpl`))
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
+
const schemaImports = ({ upperName, schemaPath }) => `import type {
|
|
6
|
+
${upperName}Data,
|
|
7
|
+
${upperName}Result,
|
|
8
|
+
${upperName}Query,
|
|
9
|
+
} from './${schemaPath}'`;
|
|
10
|
+
const declarationTemplate = ({ path, upperName }) => ` '${path}': Service<${upperName}Data, ${upperName}Result, Params<${upperName}Query>>`;
|
|
11
|
+
const toClientFile = (0, pinion_1.toFile)(({ lib, language }) => [lib, `client.${language}`]);
|
|
12
|
+
const generate = async (ctx) => (0, pinion_1.generator)(ctx)
|
|
13
|
+
.then((0, pinion_1.when)((ctx) => ctx.language === 'ts', (0, pinion_1.inject)(schemaImports, (0, pinion_1.after)("from '@feathersjs/feathers'"), toClientFile)))
|
|
14
|
+
.then((0, pinion_1.when)((ctx) => ctx.language === 'ts', (0, pinion_1.inject)(declarationTemplate, (0, pinion_1.after)('export interface ServiceTypes'), toClientFile)));
|
|
15
|
+
exports.generate = generate;
|
|
16
|
+
//# sourceMappingURL=client.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/client.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAA2E;AAG3E,MAAM,aAAa,GAAG,CAAC,EAAE,SAAS,EAAE,UAAU,EAA2B,EAAE,EAAE,CAAC;IAC1E,SAAS;IACT,SAAS;IACT,SAAS;YACD,UAAU,GAAG,CAAA;AACzB,MAAM,mBAAmB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAA2B,EAAE,EAAE,CAC3E,MAAM,IAAI,cAAc,SAAS,SAAS,SAAS,kBAAkB,SAAS,SAAS,CAAA;AAEzF,MAAM,YAAY,GAAG,IAAA,eAAM,EAA0B,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,UAAU,QAAQ,EAAE,CAAC,CAAC,CAAA;AAEjG,MAAM,QAAQ,GAAG,KAAK,EAAE,GAA4B,EAAE,EAAE,CAC7D,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,aAAa,EAAE,IAAA,cAAK,EAAC,6BAA6B,CAAC,EAAE,YAAY,CAAC,CAC1E,CACF;KACA,IAAI,CACH,IAAA,aAAI,EACF,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,EAC9B,IAAA,eAAM,EAAC,mBAAmB,EAAE,IAAA,cAAK,EAAC,+BAA+B,CAAC,EAAE,YAAY,CAAC,CAClF,CACF,CAAA;AAbQ,QAAA,QAAQ,YAahB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { generator, inject, toFile, when, after } from '@feathershq/pinion'
|
|
2
|
+
import { ServiceGeneratorContext } from '../index'
|
|
3
|
+
|
|
4
|
+
const schemaImports = ({ upperName, schemaPath }: ServiceGeneratorContext) => `import type {
|
|
5
|
+
${upperName}Data,
|
|
6
|
+
${upperName}Result,
|
|
7
|
+
${upperName}Query,
|
|
8
|
+
} from './${schemaPath}'`
|
|
9
|
+
const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
|
|
10
|
+
` '${path}': Service<${upperName}Data, ${upperName}Result, Params<${upperName}Query>>`
|
|
11
|
+
|
|
12
|
+
const toClientFile = toFile<ServiceGeneratorContext>(({ lib, language }) => [lib, `client.${language}`])
|
|
13
|
+
|
|
14
|
+
export const generate = async (ctx: ServiceGeneratorContext) =>
|
|
15
|
+
generator(ctx)
|
|
16
|
+
.then(
|
|
17
|
+
when(
|
|
18
|
+
(ctx) => ctx.language === 'ts',
|
|
19
|
+
inject(schemaImports, after("from '@feathersjs/feathers'"), toClientFile)
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
.then(
|
|
23
|
+
when(
|
|
24
|
+
(ctx) => ctx.language === 'ts',
|
|
25
|
+
inject(declarationTemplate, after('export interface ServiceTypes'), toClientFile)
|
|
26
|
+
)
|
|
27
|
+
)
|
|
@@ -0,0 +1,73 @@
|
|
|
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, schemaPath }) => `import { resolve } from '@feathersjs/schema'
|
|
7
|
+
import type { HookContext } from '${relative}/declarations'
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
${upperName}Data,
|
|
11
|
+
${upperName}Patch,
|
|
12
|
+
${upperName}Result,
|
|
13
|
+
${upperName}Query,
|
|
14
|
+
} from '${relative}/${schemaPath}'
|
|
15
|
+
import {
|
|
16
|
+
${camelName}DataSchema,
|
|
17
|
+
${camelName}PatchSchema,
|
|
18
|
+
${camelName}ResultSchema,
|
|
19
|
+
${camelName}QuerySchema
|
|
20
|
+
} from '${relative}/${schemaPath}'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// Resolver for the basic data model (e.g. creating new entries)
|
|
24
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
25
|
+
schema: ${camelName}DataSchema,
|
|
26
|
+
validate: 'before',
|
|
27
|
+
properties: {}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// Resolver for making partial updates
|
|
32
|
+
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
|
|
33
|
+
schema: ${camelName}PatchSchema,
|
|
34
|
+
validate: 'before',
|
|
35
|
+
properties: {}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// Resolver for the data that is being returned
|
|
40
|
+
export const ${camelName}ResultResolver = resolve<${upperName}Result, HookContext>({
|
|
41
|
+
schema: ${camelName}ResultSchema,
|
|
42
|
+
validate: false,
|
|
43
|
+
properties: {}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// Resolver for query properties
|
|
48
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
49
|
+
schema: ${camelName}QuerySchema,
|
|
50
|
+
validate: 'before',
|
|
51
|
+
properties: {}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// Export all resolvers in a format that can be used with the resolveAll hook
|
|
56
|
+
export const ${camelName}Resolvers = {
|
|
57
|
+
result: ${camelName}ResultResolver,
|
|
58
|
+
data: {
|
|
59
|
+
create: ${camelName}DataResolver,
|
|
60
|
+
update: ${camelName}DataResolver,
|
|
61
|
+
patch: ${camelName}PatchResolver
|
|
62
|
+
},
|
|
63
|
+
query: ${camelName}QueryResolver
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
67
|
+
lib,
|
|
68
|
+
'resolvers',
|
|
69
|
+
...folder,
|
|
70
|
+
`${fileName}.resolver`
|
|
71
|
+
])));
|
|
72
|
+
exports.generate = generate;
|
|
73
|
+
//# sourceMappingURL=resolver.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/resolver.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAA2B,EAAE,EAAE,CAC3F;oCACkC,QAAQ;;;IAGxC,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;UACH,QAAQ,IAAI,UAAU;;IAE5B,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;UACH,QAAQ,IAAI,UAAU;;;;eAIjB,SAAS,0BAA0B,SAAS;YAC/C,SAAS;;;;;;;eAON,SAAS,2BAA2B,SAAS;YAChD,SAAS;;;;;;;eAON,SAAS,4BAA4B,SAAS;YACjD,SAAS;;;;;;;eAON,SAAS,2BAA2B,SAAS;YAChD,SAAS;;;;;;;eAON,SAAS;YACZ,SAAS;;cAEP,SAAS;cACT,SAAS;aACV,SAAS;;WAEX,SAAS;;CAEnB,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,WAAW;IACX,GAAG,MAAM;IACT,GAAG,QAAQ,WAAW;CACvB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { generator, toFile } from '@feathershq/pinion'
|
|
2
|
+
import { renderSource } from '../../commons'
|
|
3
|
+
import { ServiceGeneratorContext } from '../index'
|
|
4
|
+
|
|
5
|
+
const template = ({ camelName, upperName, relative, schemaPath }: ServiceGeneratorContext) =>
|
|
6
|
+
`import { resolve } from '@feathersjs/schema'
|
|
7
|
+
import type { HookContext } from '${relative}/declarations'
|
|
8
|
+
|
|
9
|
+
import type {
|
|
10
|
+
${upperName}Data,
|
|
11
|
+
${upperName}Patch,
|
|
12
|
+
${upperName}Result,
|
|
13
|
+
${upperName}Query,
|
|
14
|
+
} from '${relative}/${schemaPath}'
|
|
15
|
+
import {
|
|
16
|
+
${camelName}DataSchema,
|
|
17
|
+
${camelName}PatchSchema,
|
|
18
|
+
${camelName}ResultSchema,
|
|
19
|
+
${camelName}QuerySchema
|
|
20
|
+
} from '${relative}/${schemaPath}'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
// Resolver for the basic data model (e.g. creating new entries)
|
|
24
|
+
export const ${camelName}DataResolver = resolve<${upperName}Data, HookContext>({
|
|
25
|
+
schema: ${camelName}DataSchema,
|
|
26
|
+
validate: 'before',
|
|
27
|
+
properties: {}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// Resolver for making partial updates
|
|
32
|
+
export const ${camelName}PatchResolver = resolve<${upperName}Patch, HookContext>({
|
|
33
|
+
schema: ${camelName}PatchSchema,
|
|
34
|
+
validate: 'before',
|
|
35
|
+
properties: {}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// Resolver for the data that is being returned
|
|
40
|
+
export const ${camelName}ResultResolver = resolve<${upperName}Result, HookContext>({
|
|
41
|
+
schema: ${camelName}ResultSchema,
|
|
42
|
+
validate: false,
|
|
43
|
+
properties: {}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
// Resolver for query properties
|
|
48
|
+
export const ${camelName}QueryResolver = resolve<${upperName}Query, HookContext>({
|
|
49
|
+
schema: ${camelName}QuerySchema,
|
|
50
|
+
validate: 'before',
|
|
51
|
+
properties: {}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// Export all resolvers in a format that can be used with the resolveAll hook
|
|
56
|
+
export const ${camelName}Resolvers = {
|
|
57
|
+
result: ${camelName}ResultResolver,
|
|
58
|
+
data: {
|
|
59
|
+
create: ${camelName}DataResolver,
|
|
60
|
+
update: ${camelName}DataResolver,
|
|
61
|
+
patch: ${camelName}PatchResolver
|
|
62
|
+
},
|
|
63
|
+
query: ${camelName}QueryResolver
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
|
|
67
|
+
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
68
|
+
generator(ctx).then(
|
|
69
|
+
renderSource(
|
|
70
|
+
template,
|
|
71
|
+
toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
|
|
72
|
+
lib,
|
|
73
|
+
'resolvers',
|
|
74
|
+
...folder,
|
|
75
|
+
`${fileName}.resolver`
|
|
76
|
+
])
|
|
77
|
+
)
|
|
78
|
+
)
|
|
@@ -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, type }) => `import { schema, querySyntax } from '@feathersjs/schema'
|
|
7
|
+
import type { Infer } from '@feathersjs/schema'
|
|
8
|
+
|
|
9
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
10
|
+
export const ${camelName}DataSchema = schema({
|
|
11
|
+
$id: '${upperName}Data',
|
|
12
|
+
type: 'object',
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
required: [ 'text' ],
|
|
15
|
+
properties: {
|
|
16
|
+
text: {
|
|
17
|
+
type: 'string'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
} as const)
|
|
21
|
+
|
|
22
|
+
export type ${upperName}Data = Infer<typeof ${camelName}DataSchema>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// Schema for making partial updates
|
|
26
|
+
export const ${camelName}PatchSchema = schema({
|
|
27
|
+
$id: '${upperName}Patch',
|
|
28
|
+
type: 'object',
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
required: [],
|
|
31
|
+
properties: {
|
|
32
|
+
...${camelName}DataSchema.properties
|
|
33
|
+
}
|
|
34
|
+
} as const)
|
|
35
|
+
|
|
36
|
+
export type ${upperName}Patch = Infer<typeof ${camelName}PatchSchema>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// Schema for the data that is being returned
|
|
40
|
+
export const ${camelName}ResultSchema = schema({
|
|
41
|
+
$id: '${upperName}Result',
|
|
42
|
+
type: 'object',
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
|
|
45
|
+
properties: {
|
|
46
|
+
...${camelName}DataSchema.properties,
|
|
47
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
48
|
+
type: 'string'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} as const)
|
|
52
|
+
|
|
53
|
+
export type ${upperName}Result = Infer<typeof ${camelName}ResultSchema>
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// Schema for allowed query properties
|
|
57
|
+
export const ${camelName}QuerySchema = schema({
|
|
58
|
+
$id: '${upperName}Query',
|
|
59
|
+
type: 'object',
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
properties: {
|
|
62
|
+
...querySyntax(${camelName}ResultSchema.properties)
|
|
63
|
+
}
|
|
64
|
+
} as const)
|
|
65
|
+
|
|
66
|
+
export type ${upperName}Query = Infer<typeof ${camelName}QuerySchema>
|
|
67
|
+
`;
|
|
68
|
+
const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib, folder, fileName }) => [
|
|
69
|
+
lib,
|
|
70
|
+
'schemas',
|
|
71
|
+
...folder,
|
|
72
|
+
`${fileName}.schema`
|
|
73
|
+
])));
|
|
74
|
+
exports.generate = generate;
|
|
75
|
+
//# sourceMappingURL=schema.tpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.tpl.js","sourceRoot":"","sources":["../../../src/service/templates/schema.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AACtD,2CAA4C;AAG5C,MAAM,QAAQ,GAAG,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAA2B,EAAE,EAAE,CAC3E;;;;eAIa,SAAS;UACd,SAAS;;;;;;;;;;;cAWL,SAAS,uBAAuB,SAAS;;;;eAIxC,SAAS;UACd,SAAS;;;;;SAKV,SAAS;;;;cAIJ,SAAS,wBAAwB,SAAS;;;;eAIzC,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;;;;;;cAMzB,SAAS,yBAAyB,SAAS;;;;eAI1C,SAAS;UACd,SAAS;;;;qBAIE,SAAS;;;;cAIhB,SAAS,wBAAwB,SAAS;CACvD,CAAA;AAEM,MAAM,QAAQ,GAAG,CAAC,GAA4B,EAAE,EAAE,CACvD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAA2B,EAAE,EAAE,CAAC;IAC7D,GAAG;IACH,SAAS;IACT,GAAG,MAAM;IACT,GAAG,QAAQ,SAAS;CACrB,CAAC,CACH,CACF,CAAA;AAXU,QAAA,QAAQ,YAWlB"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { generator, toFile } from '@feathershq/pinion'
|
|
2
|
+
import { renderSource } from '../../commons'
|
|
3
|
+
import { ServiceGeneratorContext } from '../index'
|
|
4
|
+
|
|
5
|
+
const template = ({ camelName, upperName, type }: ServiceGeneratorContext) =>
|
|
6
|
+
`import { schema, querySyntax } from '@feathersjs/schema'
|
|
7
|
+
import type { Infer } from '@feathersjs/schema'
|
|
8
|
+
|
|
9
|
+
// Schema for the basic data model (e.g. creating new entries)
|
|
10
|
+
export const ${camelName}DataSchema = schema({
|
|
11
|
+
$id: '${upperName}Data',
|
|
12
|
+
type: 'object',
|
|
13
|
+
additionalProperties: false,
|
|
14
|
+
required: [ 'text' ],
|
|
15
|
+
properties: {
|
|
16
|
+
text: {
|
|
17
|
+
type: 'string'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
} as const)
|
|
21
|
+
|
|
22
|
+
export type ${upperName}Data = Infer<typeof ${camelName}DataSchema>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// Schema for making partial updates
|
|
26
|
+
export const ${camelName}PatchSchema = schema({
|
|
27
|
+
$id: '${upperName}Patch',
|
|
28
|
+
type: 'object',
|
|
29
|
+
additionalProperties: false,
|
|
30
|
+
required: [],
|
|
31
|
+
properties: {
|
|
32
|
+
...${camelName}DataSchema.properties
|
|
33
|
+
}
|
|
34
|
+
} as const)
|
|
35
|
+
|
|
36
|
+
export type ${upperName}Patch = Infer<typeof ${camelName}PatchSchema>
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// Schema for the data that is being returned
|
|
40
|
+
export const ${camelName}ResultSchema = schema({
|
|
41
|
+
$id: '${upperName}Result',
|
|
42
|
+
type: 'object',
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
required: [ ...${camelName}DataSchema.required, '${type === 'mongodb' ? '_id' : 'id'}' ],
|
|
45
|
+
properties: {
|
|
46
|
+
...${camelName}DataSchema.properties,
|
|
47
|
+
${type === 'mongodb' ? '_id' : 'id'}: {
|
|
48
|
+
type: 'string'
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} as const)
|
|
52
|
+
|
|
53
|
+
export type ${upperName}Result = Infer<typeof ${camelName}ResultSchema>
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// Schema for allowed query properties
|
|
57
|
+
export const ${camelName}QuerySchema = schema({
|
|
58
|
+
$id: '${upperName}Query',
|
|
59
|
+
type: 'object',
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
properties: {
|
|
62
|
+
...querySyntax(${camelName}ResultSchema.properties)
|
|
63
|
+
}
|
|
64
|
+
} as const)
|
|
65
|
+
|
|
66
|
+
export type ${upperName}Query = Infer<typeof ${camelName}QuerySchema>
|
|
67
|
+
`
|
|
68
|
+
|
|
69
|
+
export const generate = (ctx: ServiceGeneratorContext) =>
|
|
70
|
+
generator(ctx).then(
|
|
71
|
+
renderSource(
|
|
72
|
+
template,
|
|
73
|
+
toFile(({ lib, folder, fileName }: ServiceGeneratorContext) => [
|
|
74
|
+
lib,
|
|
75
|
+
'schemas',
|
|
76
|
+
...folder,
|
|
77
|
+
`${fileName}.schema`
|
|
78
|
+
])
|
|
79
|
+
)
|
|
80
|
+
)
|