vovk-cli 0.0.1-draft.88 → 0.0.1-draft.90
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/client-templates/main/main.cjs.ejs +7 -7
- package/client-templates/main/main.d.cts.ejs +5 -5
- package/client-templates/module/module.d.mts.ejs +5 -5
- package/client-templates/module/module.mjs.ejs +8 -8
- package/client-templates/ts/index.ts.ejs +9 -9
- package/dist/dev/index.mjs +2 -2
- package/dist/generate/index.mjs +3 -3
- package/dist/index.mjs +1 -0
- package/dist/new/index.d.mts +1 -1
- package/dist/new/index.mjs +2 -1
- package/dist/new/newModule.d.mts +2 -1
- package/dist/new/newModule.mjs +2 -1
- package/dist/new/render.d.mts +2 -1
- package/dist/new/render.mjs +31 -8
- package/dist/types.d.mts +1 -0
- package/package.json +1 -1
- package/templates/controller.ejs +20 -22
- package/templates/service.ejs +12 -12
- /package/dist/dev/{isMetadataEmpty.d.mts → isSchemaEmpty.d.mts} +0 -0
- /package/dist/dev/{isMetadataEmpty.mjs → isSchemaEmpty.mjs} +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<%- `// auto-generated ${new Date().toISOString()}\n/* eslint-disable */` %>
|
|
2
|
-
const { default: fetcher } = require('<%=
|
|
3
|
-
const { default: createRPC } = require('<%=
|
|
4
|
-
const schema = require('<%=
|
|
5
|
-
const { default: validateOnClient = null } = <%-
|
|
6
|
-
const apiRoot = '<%=
|
|
7
|
-
<%
|
|
8
|
-
Object.keys(
|
|
2
|
+
const { default: fetcher } = require('<%= t.imports.fetcher %>');
|
|
3
|
+
const { default: createRPC } = require('<%= t.imports.createRPC %>');
|
|
4
|
+
const schema = require('<%= t.imports.schema %>');
|
|
5
|
+
const { default: validateOnClient = null } = <%- t.imports.validateOnClient ? `require('${t.imports.validateOnClient}')` : '{}'%>;
|
|
6
|
+
const apiRoot = '<%= t.apiRoot %>';
|
|
7
|
+
<% t.segments.forEach((segment) => {
|
|
8
|
+
Object.keys(t.fullSchema[segment.segmentName].controllers).forEach((key) => { %>
|
|
9
9
|
exports.<%= key %> = createRPC(
|
|
10
10
|
schema['<%= segment.segmentName %>'].controllers.<%= key %>,
|
|
11
11
|
'<%= segment.segmentName %>',
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
<%- `// auto-generated ${new Date().toISOString()}\n/* eslint-disable */` %>
|
|
3
3
|
import type { VovkClientFetcher } from 'vovk';
|
|
4
|
-
import type fetcher from '<%=
|
|
5
|
-
import type createRPC from '<%=
|
|
6
|
-
<%
|
|
4
|
+
import type fetcher from '<%= t.imports.fetcher %>';
|
|
5
|
+
import type createRPC from '<%= t.imports.createRPC %>';
|
|
6
|
+
<% t.segments.forEach((segment, i) => { if(Object.keys(t.fullSchema[segment.segmentName].controllers).length) { %>
|
|
7
7
|
import type { Controllers as Controllers<%= i %> } from "<%= segment.segmentImportPath %>";
|
|
8
8
|
<% }}) %>
|
|
9
9
|
type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
10
|
-
<%
|
|
11
|
-
Object.keys(
|
|
10
|
+
<% t.segments.forEach((segment, i) => {
|
|
11
|
+
Object.keys(t.fullSchema[segment.segmentName].controllers).forEach((key) => { %>
|
|
12
12
|
export const <%= key %>: ReturnType<typeof createRPC<Controllers<%= i %>["<%= key %>"], Options>>;
|
|
13
13
|
<% })
|
|
14
14
|
}) %>
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
<%- `// auto-generated ${new Date().toISOString()}\n/* eslint-disable */` %>
|
|
3
3
|
import type { VovkClientFetcher } from 'vovk';
|
|
4
|
-
import type fetcher from '<%=
|
|
5
|
-
import type createRPC from '<%=
|
|
6
|
-
<%
|
|
4
|
+
import type fetcher from '<%= t.imports.module.fetcher %>';
|
|
5
|
+
import type createRPC from '<%= t.imports.module.createRPC %>';
|
|
6
|
+
<% t.segments.forEach((segment, i) => { if(Object.keys(t.fullSchema[segment.segmentName].controllers).length) { %>
|
|
7
7
|
import type { Controllers as Controllers<%= i %> } from "<%= segment.segmentImportPath %>";
|
|
8
8
|
<% }}) %>
|
|
9
9
|
type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
10
|
-
<%
|
|
11
|
-
Object.keys(
|
|
10
|
+
<% t.segments.forEach((segment, i) => {
|
|
11
|
+
Object.keys(t.fullSchema[segment.segmentName].controllers).forEach((key) => { %>
|
|
12
12
|
export const <%= key %>: ReturnType<typeof createRPC<Controllers<%= i %>["<%= key %>"], Options>>;
|
|
13
13
|
<% })
|
|
14
14
|
}) %>
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
<%- `// auto-generated ${new Date().toISOString()}\n/* eslint-disable */` %>
|
|
2
|
-
import fetcherImport from '<%=
|
|
3
|
-
import createRPCImport from '<%=
|
|
4
|
-
import schema from '<%=
|
|
5
|
-
<% if (
|
|
6
|
-
import validateOnClientImport from '<%=
|
|
2
|
+
import fetcherImport from '<%= t.imports.module.fetcher %>';
|
|
3
|
+
import createRPCImport from '<%= t.imports.module.createRPC %>';
|
|
4
|
+
import schema from '<%= t.imports.module.schema %>';
|
|
5
|
+
<% if (t.imports.module.validateOnClient) { %>
|
|
6
|
+
import validateOnClientImport from '<%= t.imports.module.validateOnClient %>';
|
|
7
7
|
const validateOnClient = validateOnClientImport.default || validateOnClientImport;
|
|
8
8
|
<% } else { %>
|
|
9
9
|
const validateOnClient = undefined;
|
|
10
10
|
<% } %>
|
|
11
|
-
const apiRoot = '<%=
|
|
11
|
+
const apiRoot = '<%= t.apiRoot %>';
|
|
12
12
|
const fetcher = fetcherImport.default || fetcherImport;
|
|
13
13
|
const createRPC = createRPCImport.default || createRPCImport;
|
|
14
|
-
<%
|
|
15
|
-
Object.keys(
|
|
14
|
+
<% t.segments.forEach((segment, i) => {
|
|
15
|
+
Object.keys(t.fullSchema[segment.segmentName].controllers).forEach((key) => { %>
|
|
16
16
|
export const <%= key %> = createRPC(
|
|
17
17
|
schema['<%= segment.segmentName %>'].controllers.<%= key %>,
|
|
18
18
|
'<%= segment.segmentName %>',
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
<%- `// auto-generated ${new Date().toISOString()}\n/* eslint-disable */` %>
|
|
2
2
|
import type { VovkClientFetcher } from 'vovk';
|
|
3
|
-
import fetcher from '<%=
|
|
4
|
-
import createRPC from '<%=
|
|
5
|
-
import schema from '<%=
|
|
6
|
-
<%
|
|
3
|
+
import fetcher from '<%= t.imports.fetcher %>';
|
|
4
|
+
import createRPC from '<%= t.imports.createRPC %>';
|
|
5
|
+
import schema from '<%= t.imports.schema %>';
|
|
6
|
+
<% t.segments.forEach((segment, i) => { if(Object.keys(t.fullSchema[segment.segmentName].controllers).length) { %>
|
|
7
7
|
import type { Controllers as Controllers<%= i %> } from "<%= segment.segmentImportPath %>";
|
|
8
8
|
<% }}) %>
|
|
9
|
-
<% if (
|
|
10
|
-
import validateOnClient from '<%=
|
|
9
|
+
<% if (t.imports.validateOnClient) { %>
|
|
10
|
+
import validateOnClient from '<%= t.imports.validateOnClient %>';
|
|
11
11
|
<% } else { %>
|
|
12
12
|
const validateOnClient = undefined;
|
|
13
13
|
<% } %>
|
|
14
14
|
type Options = typeof fetcher extends VovkClientFetcher<infer U> ? U : never;
|
|
15
|
-
const apiRoot = '<%=
|
|
15
|
+
const apiRoot = '<%= t.apiRoot %>';
|
|
16
16
|
|
|
17
|
-
<%
|
|
18
|
-
<% Object.keys(
|
|
17
|
+
<% t.segments.forEach((segment, i) => { %>
|
|
18
|
+
<% Object.keys(t.fullSchema[segment.segmentName].controllers).forEach((key) => { %>
|
|
19
19
|
export const <%= key %> = createRPC<Controllers<%= i %>["<%= key %>"], Options>(
|
|
20
20
|
schema['<%= segment.segmentName %>'].controllers.<%= key %>,
|
|
21
21
|
'<%= segment.segmentName %>',
|
package/dist/dev/index.mjs
CHANGED
|
@@ -5,7 +5,6 @@ import { Agent, setGlobalDispatcher } from 'undici';
|
|
|
5
5
|
import keyBy from 'lodash/keyBy.js';
|
|
6
6
|
import capitalize from 'lodash/capitalize.js';
|
|
7
7
|
import debounce from 'lodash/debounce.js';
|
|
8
|
-
import isEmpty from 'lodash/isEmpty.js';
|
|
9
8
|
import once from 'lodash/once.js';
|
|
10
9
|
import { debouncedEnsureSchemaFiles } from './ensureSchemaFiles.mjs';
|
|
11
10
|
import writeOneSchemaFile from './writeOneSchemaFile.mjs';
|
|
@@ -16,6 +15,7 @@ import generate from '../generate/index.mjs';
|
|
|
16
15
|
import locateSegments from '../locateSegments.mjs';
|
|
17
16
|
import debounceWithArgs from '../utils/debounceWithArgs.mjs';
|
|
18
17
|
import formatLoggedSegmentName from '../utils/formatLoggedSegmentName.mjs';
|
|
18
|
+
import isSchemaEmpty from './isSchemaEmpty.mjs';
|
|
19
19
|
export class VovkDev {
|
|
20
20
|
#projectInfo;
|
|
21
21
|
#segments = [];
|
|
@@ -280,7 +280,7 @@ export class VovkDev {
|
|
|
280
280
|
log.info(`Schema for ${formatLoggedSegmentName(segment.segmentName)} has been updated in ${timeTook}ms`);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
|
-
else if (schema && !
|
|
283
|
+
else if (schema && !isSchemaEmpty(schema)) {
|
|
284
284
|
log.error(`Non-empty schema provided for ${formatLoggedSegmentName(segment.segmentName)} but "emitSchema" is false`);
|
|
285
285
|
}
|
|
286
286
|
if (this.#segments.every((s) => this.#schemas[s.segmentName])) {
|
package/dist/generate/index.mjs
CHANGED
|
@@ -23,7 +23,7 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
23
23
|
}
|
|
24
24
|
const now = Date.now();
|
|
25
25
|
// Data for the EJS templates:
|
|
26
|
-
const
|
|
26
|
+
const t = {
|
|
27
27
|
apiRoot,
|
|
28
28
|
imports: clientImports,
|
|
29
29
|
segments,
|
|
@@ -37,7 +37,7 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
37
37
|
const templateContent = await fs.readFile(templatePath, 'utf-8');
|
|
38
38
|
// Render the template
|
|
39
39
|
let rendered = templatePath.endsWith('.ejs')
|
|
40
|
-
? ejs.render(templateContent, {
|
|
40
|
+
? ejs.render(templateContent, { t }, {
|
|
41
41
|
filename: templatePath,
|
|
42
42
|
})
|
|
43
43
|
: templateContent;
|
|
@@ -79,6 +79,6 @@ export default async function generate({ projectInfo, segments, segmentsSchema,
|
|
|
79
79
|
}
|
|
80
80
|
return null;
|
|
81
81
|
}));
|
|
82
|
-
log.info(`Client generated from template${usedTemplateNames.length !== 1 ? 's' : ''} ${chalkHighlightThing(usedTemplateNames.map((s) => `"${s}"`).join(', '))}${unusedTemplateNames.length ? ` (
|
|
82
|
+
log.info(`Client generated from template${usedTemplateNames.length !== 1 ? 's' : ''} ${chalkHighlightThing(usedTemplateNames.map((s) => `"${s}"`).join(', '))}${unusedTemplateNames.length ? ` (${chalkHighlightThing(unusedTemplateNames.map((s) => `"${s}"`).join(', '))} ${unusedTemplateNames.length !== 1 ? 'are' : 'is'} up to date)` : ''} at ${clientOutDirAbsolutePath} in ${Date.now() - now}ms`);
|
|
83
83
|
return { written: true, path: clientOutDirAbsolutePath };
|
|
84
84
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -102,6 +102,7 @@ program
|
|
|
102
102
|
.option('-o, --overwrite', 'overwrite existing files')
|
|
103
103
|
.option('--template, --templates <templates...>', 'override config template; accepts an array of strings that correspond the order of the components')
|
|
104
104
|
.option('--dir <dirname>', 'override dirName in template file; relative to the root of the project')
|
|
105
|
+
.option('--empty', 'create an empty module')
|
|
105
106
|
.option('--no-segment-update', 'do not update segment files when creating a new module')
|
|
106
107
|
.option('--dry-run', 'do not write files to disk')
|
|
107
108
|
.action((components, options) => newComponents(components, options));
|
package/dist/new/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { NewOptions } from '../types.mjs';
|
|
2
|
-
export default function newComponents(components: string[], { dryRun, dir, templates, overwrite, noSegmentUpdate }: NewOptions): Promise<void>;
|
|
2
|
+
export default function newComponents(components: string[], { dryRun, dir, templates, overwrite, noSegmentUpdate, empty }: NewOptions): Promise<void>;
|
package/dist/new/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import newModule from './newModule.mjs';
|
|
2
2
|
import newSegment from './newSegment.mjs';
|
|
3
|
-
export default async function newComponents(components, { dryRun, dir, templates, overwrite, noSegmentUpdate }) {
|
|
3
|
+
export default async function newComponents(components, { dryRun, dir, templates, overwrite, noSegmentUpdate, empty }) {
|
|
4
4
|
if (components[0] === 'segment' || components[0] === 'segments') {
|
|
5
5
|
// vovk new segment [segmentName]
|
|
6
6
|
let segmentNames = components
|
|
@@ -31,6 +31,7 @@ export default async function newComponents(components, { dryRun, dir, templates
|
|
|
31
31
|
overwrite,
|
|
32
32
|
noSegmentUpdate,
|
|
33
33
|
dryRun,
|
|
34
|
+
empty,
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
}
|
package/dist/new/newModule.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, }: {
|
|
1
|
+
export default function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }: {
|
|
2
2
|
what: string[];
|
|
3
3
|
moduleNameWithOptionalSegment: string;
|
|
4
4
|
dryRun?: boolean;
|
|
@@ -6,4 +6,5 @@ export default function newModule({ what, moduleNameWithOptionalSegment, dryRun,
|
|
|
6
6
|
templates?: string[];
|
|
7
7
|
noSegmentUpdate?: boolean;
|
|
8
8
|
overwrite?: boolean;
|
|
9
|
+
empty?: boolean;
|
|
9
10
|
}): Promise<void>;
|
package/dist/new/newModule.mjs
CHANGED
|
@@ -18,7 +18,7 @@ function splitByLast(str, delimiter = '/') {
|
|
|
18
18
|
const after = str.substring(index + delimiter.length);
|
|
19
19
|
return [before, after];
|
|
20
20
|
}
|
|
21
|
-
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, }) {
|
|
21
|
+
export default async function newModule({ what, moduleNameWithOptionalSegment, dryRun, dir: dirFlag, templates: templatesFlag, noSegmentUpdate, overwrite, empty, }) {
|
|
22
22
|
const { config, log, apiDir, cwd } = await getProjectInfo();
|
|
23
23
|
let templates = config.templates;
|
|
24
24
|
const [segmentName, moduleName] = splitByLast(moduleNameWithOptionalSegment);
|
|
@@ -64,6 +64,7 @@ export default async function newModule({ what, moduleNameWithOptionalSegment, d
|
|
|
64
64
|
withService: what.includes('service'),
|
|
65
65
|
segmentName,
|
|
66
66
|
moduleName,
|
|
67
|
+
empty,
|
|
67
68
|
});
|
|
68
69
|
const dir = dirFlag || renderedDir;
|
|
69
70
|
if (!dir) {
|
package/dist/new/render.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { VovkConfig, VovkModuleRenderResult } from '../types.mjs';
|
|
2
|
-
export default function render(codeTemplate: string, { config, withService, segmentName, moduleName, }: {
|
|
2
|
+
export default function render(codeTemplate: string, { config, withService, segmentName, moduleName, empty, }: {
|
|
3
3
|
cwd: string;
|
|
4
4
|
config: VovkConfig;
|
|
5
5
|
withService: boolean;
|
|
6
6
|
segmentName: string;
|
|
7
7
|
moduleName: string;
|
|
8
|
+
empty?: boolean;
|
|
8
9
|
}): Promise<VovkModuleRenderResult>;
|
package/dist/new/render.mjs
CHANGED
|
@@ -4,25 +4,48 @@ import _ from 'lodash';
|
|
|
4
4
|
import pluralize from 'pluralize';
|
|
5
5
|
import addCommonTerms from './addCommonTerms.mjs';
|
|
6
6
|
addCommonTerms();
|
|
7
|
-
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, }) {
|
|
7
|
+
export default async function render(codeTemplate, { config, withService, segmentName, moduleName, empty, }) {
|
|
8
8
|
const getModuleDirName = (givenSegmentName, givenModuleName) => [config.modulesDir, givenSegmentName || config.rootSegmentModulesDirName, _.camelCase(givenModuleName)]
|
|
9
9
|
.filter(Boolean)
|
|
10
10
|
.join('/');
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/*
|
|
12
|
+
<% var modulePascalName = _.upperFirst(_.camelCase(moduleName)); %>
|
|
13
|
+
<% var modulePascalNamePlural = pluralize(modulePascalName); %>
|
|
14
|
+
<% var controllerName = modulePascalName + 'Controller'; %>
|
|
15
|
+
<% var compiledName = modulePascalName + 'RPC'; %>
|
|
16
|
+
<% var serviceName = modulePascalName + 'Service'; %>
|
|
17
|
+
<% var prefix = pluralize(_.kebabCase(moduleName).toLowerCase()); %>
|
|
18
|
+
*/
|
|
19
|
+
const theThing = _.camelCase(moduleName);
|
|
20
|
+
const TheThing = _.upperFirst(theThing);
|
|
21
|
+
const the_thing = _.snakeCase(moduleName);
|
|
22
|
+
const THE_THING = _.toUpper(the_thing);
|
|
23
|
+
const the__thing = _.kebabCase(moduleName);
|
|
24
|
+
const t = {
|
|
25
|
+
// module name variations
|
|
26
|
+
moduleName,
|
|
27
|
+
theThing,
|
|
28
|
+
theThings: pluralize(theThing),
|
|
29
|
+
TheThing,
|
|
30
|
+
TheThings: pluralize(TheThing),
|
|
31
|
+
the_thing,
|
|
32
|
+
the_things: pluralize(the_thing),
|
|
33
|
+
THE_THING,
|
|
34
|
+
THE_THINGS: pluralize(THE_THING),
|
|
35
|
+
'the-thing': the__thing,
|
|
36
|
+
'the-things': pluralize(the__thing),
|
|
37
|
+
// data
|
|
13
38
|
config,
|
|
14
39
|
withService,
|
|
15
40
|
segmentName,
|
|
16
|
-
|
|
17
|
-
// utils
|
|
18
|
-
getModuleDirName,
|
|
41
|
+
defaultDir: getModuleDirName(segmentName, theThing),
|
|
19
42
|
// libraries
|
|
20
43
|
_, // lodash
|
|
21
44
|
pluralize,
|
|
22
45
|
};
|
|
23
|
-
const parsed = matter((await ejs.render(codeTemplate,
|
|
46
|
+
const parsed = matter((await ejs.render(codeTemplate, { t }, { async: true })).trim());
|
|
24
47
|
const { dir, fileName, sourceName, compiledName } = parsed.data;
|
|
25
|
-
const code = parsed.content;
|
|
48
|
+
const code = empty ? (sourceName ? `export default class ${sourceName} {}` : '') : parsed.content;
|
|
26
49
|
return {
|
|
27
50
|
dir,
|
|
28
51
|
fileName,
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
package/templates/controller.ejs
CHANGED
|
@@ -1,52 +1,50 @@
|
|
|
1
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<% var serviceName = modulePascalName + 'Service'; %>
|
|
6
|
-
<% var prefix = pluralize(_.kebabCase(moduleName).toLowerCase()); %>
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ControllerName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName = t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
7
5
|
---
|
|
8
|
-
dir: <%=
|
|
9
|
-
fileName: <%=
|
|
10
|
-
sourceName: <%=
|
|
11
|
-
compiledName: <%=
|
|
6
|
+
dir: <%= t.defaultDir %>
|
|
7
|
+
fileName: <%= vars.ControllerName + '.ts' %>
|
|
8
|
+
sourceName: <%= vars.ControllerName %>
|
|
9
|
+
compiledName: <%= t.TheThing + 'RPC' %>
|
|
12
10
|
---
|
|
13
11
|
|
|
14
12
|
import { prefix, get, put, post, del, type VovkRequest } from 'vovk';
|
|
15
|
-
<% if(withService) { %>
|
|
16
|
-
import <%=
|
|
13
|
+
<% if(t.withService) { %>
|
|
14
|
+
import <%= vars.ServiceName %> from './<%= vars.ServiceName %>';
|
|
17
15
|
<% } %>
|
|
18
16
|
|
|
19
|
-
@prefix('<%=
|
|
20
|
-
export default class <%=
|
|
17
|
+
@prefix('<%= t['the-things'] %>')
|
|
18
|
+
export default class <%= vars.ControllerName %> {
|
|
21
19
|
@get()
|
|
22
|
-
static get<%=
|
|
20
|
+
static get<%= t.TheThings %> = async (req: VovkRequest<null, { search: string }>) => {
|
|
23
21
|
const search = req.nextUrl.searchParams.get('search');
|
|
24
|
-
<% if(withService) { %>
|
|
25
|
-
return <%=
|
|
22
|
+
<% if(t.withService) { %>
|
|
23
|
+
return <%= vars.ServiceName %>.get<%= t.TheThings %>(search);
|
|
26
24
|
<% } else { %>
|
|
27
25
|
return { results: [], search };
|
|
28
26
|
<% } %>
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
@put(':id')
|
|
32
|
-
static update<%=
|
|
30
|
+
static update<%= t.TheThing %> = async (req: VovkRequest<{ foo: 'bar' | 'baz' }, { q: string }>, params: { id: string }) => {
|
|
33
31
|
const { id } = params;
|
|
34
32
|
const body = await req.json();
|
|
35
33
|
const q = req.nextUrl.searchParams.get('q');
|
|
36
|
-
<% if(withService) { %>
|
|
37
|
-
return <%=
|
|
34
|
+
<% if(t.withService) { %>
|
|
35
|
+
return <%= vars.ServiceName %>.update<%= t.TheThing %>(id, q, body);
|
|
38
36
|
<% } else { %>
|
|
39
37
|
return { id, body, q };
|
|
40
38
|
<% } %>
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
@post()
|
|
44
|
-
static create<%=
|
|
42
|
+
static create<%= t.TheThing %> = () => {
|
|
45
43
|
// ...
|
|
46
44
|
};
|
|
47
45
|
|
|
48
46
|
@del(':id')
|
|
49
|
-
static delete<%=
|
|
47
|
+
static delete<%= t.TheThing %> = () => {
|
|
50
48
|
// ...
|
|
51
49
|
};
|
|
52
50
|
}
|
package/templates/service.ejs
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
<%
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
<% const vars = {
|
|
2
|
+
ControllerName: t.TheThing + 'Controller',
|
|
3
|
+
ServiceName: t.TheThing + 'Service',
|
|
4
|
+
}; %>
|
|
5
5
|
---
|
|
6
|
-
dir: <%=
|
|
7
|
-
fileName: <%=
|
|
6
|
+
dir: <%= t.defaultDir %>
|
|
7
|
+
fileName: <%= vars.ServiceName + '.ts' %>
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
import type { VovkControllerBody, VovkControllerQuery } from 'vovk';
|
|
11
|
-
import type <%=
|
|
11
|
+
import type <%= vars.ControllerName %> from './<%= vars.ControllerName %>';
|
|
12
12
|
|
|
13
|
-
export default class <%=
|
|
14
|
-
static get<%=
|
|
13
|
+
export default class <%= vars.ServiceName %> {
|
|
14
|
+
static get<%= t.TheThings %> = (search: VovkControllerQuery<typeof <%= vars.ControllerName %>.get<%= t.TheThings %>>['search']) => {
|
|
15
15
|
return { results: [], search };
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
static update<%=
|
|
18
|
+
static update<%= t.TheThing %> = (
|
|
19
19
|
id: string,
|
|
20
|
-
q: VovkControllerQuery<typeof <%=
|
|
21
|
-
body: VovkControllerBody<typeof <%=
|
|
20
|
+
q: VovkControllerQuery<typeof <%= vars.ControllerName %>.update<%= t.TheThing %>>['q'],
|
|
21
|
+
body: VovkControllerBody<typeof <%= vars.ControllerName %>.update<%= t.TheThing %>>
|
|
22
22
|
) => {
|
|
23
23
|
return { id, q, body };
|
|
24
24
|
};
|
|
File without changes
|
|
File without changes
|