mobiletto-orm-typedef-gen 2.3.13 → 2.3.15
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/lib/cjs/generators/server.d.ts +2 -2
- package/lib/cjs/generators/server.js +5 -4
- package/lib/cjs/templates/api/id.get.ts.hbs +3 -2
- package/lib/cjs/templates/component/admin.vue.hbs +3 -2
- package/lib/esm/generators/server.d.ts +2 -2
- package/lib/esm/generators/server.js +5 -4
- package/lib/esm/templates/api/id.get.ts.hbs +3 -2
- package/lib/esm/templates/component/admin.vue.hbs +3 -2
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MobilettoOrmTypeDef, MobilettoOrmTypeDefConfig } from "mobiletto-orm-typedef";
|
|
2
2
|
import { GenerateOptions } from "../generate.js";
|
|
3
3
|
export declare const genApiEndpoint: (apiTemplate: string, typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, ctx?: Record<string, string>) => string;
|
|
4
|
-
export declare const generateApiIdGet: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
4
|
+
export declare const generateApiIdGet: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, singletonDefault?: string, singletonDefaultImport?: string) => string;
|
|
5
5
|
export declare const generateApiIdPut: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
6
6
|
export declare const generateApiIdPatch: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
7
7
|
export declare const generateApiIdDelete: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
8
8
|
export declare const generateApiIndexPost: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, utilsImportPath?: string) => string;
|
|
9
|
-
export declare const generateApi: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, utilsImportPath?: string) => Record<string, string>;
|
|
9
|
+
export declare const generateApi: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, singletonDefault?: string, singletonDefaultImport?: string, utilsImportPath?: string) => Record<string, string>;
|
|
10
10
|
export declare const generateErrorFilter: (typeDefPackage: string, opts?: GenerateOptions, logger?: string, loggerImport?: string) => string;
|
|
11
11
|
export declare const generateSessionFilter: (typeDefPackage: string, opts?: GenerateOptions, AccountType?: string, SessionType?: string, SESSION_HEADER?: string, sessionHeaderImport?: string, SESSION_COOKIE_NAME?: string, sessionCookieNameImport?: string, cookieOptions?: string, cookieOptionsImport?: string, errorFilterImport?: string, sessionRepository?: string, sessionRepositoryImport?: string, accountRepository?: string, accountRepositoryImport?: string) => string;
|
|
@@ -8,8 +8,9 @@ export const genApiEndpoint = (apiTemplate, typeDef, typeDefPackage, opts, ctx)
|
|
|
8
8
|
const cx = ctx ? Object.assign({}, ctx, { typeDefPackage }) : { typeDefPackage };
|
|
9
9
|
return generate(typeDef, `templates/api/${apiTemplate}.ts.hbs`, opts, cx);
|
|
10
10
|
};
|
|
11
|
-
export const generateApiIdGet = (typeDef, typeDefPackage, opts) => {
|
|
12
|
-
|
|
11
|
+
export const generateApiIdGet = (typeDef, typeDefPackage, opts, singletonDefault, singletonDefaultImport) => {
|
|
12
|
+
const ctx = singletonDefault && singletonDefaultImport ? { singletonDefault, singletonDefaultImport } : {};
|
|
13
|
+
return genApiEndpoint("id.get", typeDef, typeDefPackage, opts, ctx);
|
|
13
14
|
};
|
|
14
15
|
export const generateApiIdPut = (typeDef, typeDefPackage, opts) => {
|
|
15
16
|
return genApiEndpoint("id.put", typeDef, typeDefPackage, opts);
|
|
@@ -24,7 +25,7 @@ export const generateApiIndexPost = (typeDef, typeDefPackage, opts, utilsImportP
|
|
|
24
25
|
return genApiEndpoint("index.post", typeDef, typeDefPackage, opts, utilsImportPath ? { utilsImportPath } : undefined);
|
|
25
26
|
};
|
|
26
27
|
const apiOutfile = (opts, tsFile) => opts.outfile ? Object.assign({}, opts, { outfile: `${opts.outfile}/${tsFile}` }) : opts;
|
|
27
|
-
export const generateApi = (typeDef, typeDefPackage, opts, utilsImportPath) => {
|
|
28
|
+
export const generateApi = (typeDef, typeDefPackage, opts, singletonDefault, singletonDefaultImport, utilsImportPath) => {
|
|
28
29
|
opts || (opts = {});
|
|
29
30
|
if (opts.outfile) {
|
|
30
31
|
const stat = fs.statSync(opts.outfile, { throwIfNoEntry: false });
|
|
@@ -33,7 +34,7 @@ export const generateApi = (typeDef, typeDefPackage, opts, utilsImportPath) => {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
return {
|
|
36
|
-
find: generateApiIdGet(typeDef, typeDefPackage, apiOutfile(opts, "[id].get.ts")),
|
|
37
|
+
find: generateApiIdGet(typeDef, typeDefPackage, apiOutfile(opts, "[id].get.ts"), singletonDefault, singletonDefaultImport),
|
|
37
38
|
create: generateApiIdPut(typeDef, typeDefPackage, apiOutfile(opts, "[id].put.ts")),
|
|
38
39
|
update: generateApiIdPatch(typeDef, typeDefPackage, apiOutfile(opts, "[id].patch.ts")),
|
|
39
40
|
delete: generateApiIdDelete(typeDef, typeDefPackage, apiOutfile(opts, "[id].delete.ts")),
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
{{{header}}}{{/if}}{{/if}}
|
|
4
4
|
|
|
5
5
|
import { H3Event } from "h3";{{#if typeDef.apiConfig.lookup.hasValidate}}
|
|
6
|
-
import { {{Name}}TypeDef } from "{{typeDefPackage}}";{{/if}}
|
|
6
|
+
import { {{Name}}TypeDef } from "{{typeDefPackage}}";{{/if}}{{#if singletonDefaultImport}}
|
|
7
|
+
import { {{singletonDefault}} } from "{{singletonDefaultImport}}";{{/if}}
|
|
7
8
|
|
|
8
9
|
export default defineEventHandler(async (event: H3Event) => {
|
|
9
10
|
return await filterErrors(event, "{{name}}.lookup", async (event: H3Event) => {{{curlyOpen}}}{{#if typeDef.apiConfig.lookup.permission.admin}}
|
|
@@ -29,7 +30,7 @@ export default defineEventHandler(async (event: H3Event) => {
|
|
|
29
30
|
const {{../name}}_by_{{this}} = await {{../name}}Repo.safeFindFirstBy("{{this}}", id);
|
|
30
31
|
if ({{../name}}_by_{{this}}) return {{../name}}_by_{{this}};
|
|
31
32
|
{{/each}}
|
|
32
|
-
throw notFound(id);{{#if typeDef.apiConfig.lookup.permission.admin}}
|
|
33
|
+
{{#if singletonDefault}}return {{singletonDefault}}{{else}}throw notFound(id){{/if}};{{#if typeDef.apiConfig.lookup.permission.admin}}
|
|
33
34
|
});{{else}}{{#if typeDef.apiConfig.lookup.permission.owner}}
|
|
34
35
|
});{{else}}{{#if typeDef.apiConfig.lookup.permission.session}}
|
|
35
36
|
});{{/if}}{{/if}}{{/if}}
|
|
@@ -386,9 +386,10 @@
|
|
|
386
386
|
}
|
|
387
387
|
return true;
|
|
388
388
|
};
|
|
389
|
-
const delObject =
|
|
389
|
+
const delObject = (obj: MobilettoOrmObject) => {
|
|
390
390
|
const id = {{Name}}TypeDef.id(obj);
|
|
391
|
-
|
|
391
|
+
{{name}}Store.delete(id, delete{{Name}}ServerErrors)
|
|
392
|
+
.then(() => {{name}}Store.search());
|
|
392
393
|
};
|
|
393
394
|
watch({{name}}List, (newList) => {
|
|
394
395
|
if (newList && Array.isArray(newList) && newList.length === 0 && searchTerms.value && searchTerms.value.length === 0) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MobilettoOrmTypeDef, MobilettoOrmTypeDefConfig } from "mobiletto-orm-typedef";
|
|
2
2
|
import { GenerateOptions } from "../generate.js";
|
|
3
3
|
export declare const genApiEndpoint: (apiTemplate: string, typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, ctx?: Record<string, string>) => string;
|
|
4
|
-
export declare const generateApiIdGet: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
4
|
+
export declare const generateApiIdGet: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, singletonDefault?: string, singletonDefaultImport?: string) => string;
|
|
5
5
|
export declare const generateApiIdPut: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
6
6
|
export declare const generateApiIdPatch: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
7
7
|
export declare const generateApiIdDelete: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions) => string;
|
|
8
8
|
export declare const generateApiIndexPost: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, utilsImportPath?: string) => string;
|
|
9
|
-
export declare const generateApi: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, utilsImportPath?: string) => Record<string, string>;
|
|
9
|
+
export declare const generateApi: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, singletonDefault?: string, singletonDefaultImport?: string, utilsImportPath?: string) => Record<string, string>;
|
|
10
10
|
export declare const generateErrorFilter: (typeDefPackage: string, opts?: GenerateOptions, logger?: string, loggerImport?: string) => string;
|
|
11
11
|
export declare const generateSessionFilter: (typeDefPackage: string, opts?: GenerateOptions, AccountType?: string, SessionType?: string, SESSION_HEADER?: string, sessionHeaderImport?: string, SESSION_COOKIE_NAME?: string, sessionCookieNameImport?: string, cookieOptions?: string, cookieOptionsImport?: string, errorFilterImport?: string, sessionRepository?: string, sessionRepositoryImport?: string, accountRepository?: string, accountRepositoryImport?: string) => string;
|
|
@@ -8,8 +8,9 @@ export const genApiEndpoint = (apiTemplate, typeDef, typeDefPackage, opts, ctx)
|
|
|
8
8
|
const cx = ctx ? Object.assign({}, ctx, { typeDefPackage }) : { typeDefPackage };
|
|
9
9
|
return generate(typeDef, `templates/api/${apiTemplate}.ts.hbs`, opts, cx);
|
|
10
10
|
};
|
|
11
|
-
export const generateApiIdGet = (typeDef, typeDefPackage, opts) => {
|
|
12
|
-
|
|
11
|
+
export const generateApiIdGet = (typeDef, typeDefPackage, opts, singletonDefault, singletonDefaultImport) => {
|
|
12
|
+
const ctx = singletonDefault && singletonDefaultImport ? { singletonDefault, singletonDefaultImport } : {};
|
|
13
|
+
return genApiEndpoint("id.get", typeDef, typeDefPackage, opts, ctx);
|
|
13
14
|
};
|
|
14
15
|
export const generateApiIdPut = (typeDef, typeDefPackage, opts) => {
|
|
15
16
|
return genApiEndpoint("id.put", typeDef, typeDefPackage, opts);
|
|
@@ -24,7 +25,7 @@ export const generateApiIndexPost = (typeDef, typeDefPackage, opts, utilsImportP
|
|
|
24
25
|
return genApiEndpoint("index.post", typeDef, typeDefPackage, opts, utilsImportPath ? { utilsImportPath } : undefined);
|
|
25
26
|
};
|
|
26
27
|
const apiOutfile = (opts, tsFile) => opts.outfile ? Object.assign({}, opts, { outfile: `${opts.outfile}/${tsFile}` }) : opts;
|
|
27
|
-
export const generateApi = (typeDef, typeDefPackage, opts, utilsImportPath) => {
|
|
28
|
+
export const generateApi = (typeDef, typeDefPackage, opts, singletonDefault, singletonDefaultImport, utilsImportPath) => {
|
|
28
29
|
opts || (opts = {});
|
|
29
30
|
if (opts.outfile) {
|
|
30
31
|
const stat = fs.statSync(opts.outfile, { throwIfNoEntry: false });
|
|
@@ -33,7 +34,7 @@ export const generateApi = (typeDef, typeDefPackage, opts, utilsImportPath) => {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
return {
|
|
36
|
-
find: generateApiIdGet(typeDef, typeDefPackage, apiOutfile(opts, "[id].get.ts")),
|
|
37
|
+
find: generateApiIdGet(typeDef, typeDefPackage, apiOutfile(opts, "[id].get.ts"), singletonDefault, singletonDefaultImport),
|
|
37
38
|
create: generateApiIdPut(typeDef, typeDefPackage, apiOutfile(opts, "[id].put.ts")),
|
|
38
39
|
update: generateApiIdPatch(typeDef, typeDefPackage, apiOutfile(opts, "[id].patch.ts")),
|
|
39
40
|
delete: generateApiIdDelete(typeDef, typeDefPackage, apiOutfile(opts, "[id].delete.ts")),
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
{{{header}}}{{/if}}{{/if}}
|
|
4
4
|
|
|
5
5
|
import { H3Event } from "h3";{{#if typeDef.apiConfig.lookup.hasValidate}}
|
|
6
|
-
import { {{Name}}TypeDef } from "{{typeDefPackage}}";{{/if}}
|
|
6
|
+
import { {{Name}}TypeDef } from "{{typeDefPackage}}";{{/if}}{{#if singletonDefaultImport}}
|
|
7
|
+
import { {{singletonDefault}} } from "{{singletonDefaultImport}}";{{/if}}
|
|
7
8
|
|
|
8
9
|
export default defineEventHandler(async (event: H3Event) => {
|
|
9
10
|
return await filterErrors(event, "{{name}}.lookup", async (event: H3Event) => {{{curlyOpen}}}{{#if typeDef.apiConfig.lookup.permission.admin}}
|
|
@@ -29,7 +30,7 @@ export default defineEventHandler(async (event: H3Event) => {
|
|
|
29
30
|
const {{../name}}_by_{{this}} = await {{../name}}Repo.safeFindFirstBy("{{this}}", id);
|
|
30
31
|
if ({{../name}}_by_{{this}}) return {{../name}}_by_{{this}};
|
|
31
32
|
{{/each}}
|
|
32
|
-
throw notFound(id);{{#if typeDef.apiConfig.lookup.permission.admin}}
|
|
33
|
+
{{#if singletonDefault}}return {{singletonDefault}}{{else}}throw notFound(id){{/if}};{{#if typeDef.apiConfig.lookup.permission.admin}}
|
|
33
34
|
});{{else}}{{#if typeDef.apiConfig.lookup.permission.owner}}
|
|
34
35
|
});{{else}}{{#if typeDef.apiConfig.lookup.permission.session}}
|
|
35
36
|
});{{/if}}{{/if}}{{/if}}
|
|
@@ -386,9 +386,10 @@
|
|
|
386
386
|
}
|
|
387
387
|
return true;
|
|
388
388
|
};
|
|
389
|
-
const delObject =
|
|
389
|
+
const delObject = (obj: MobilettoOrmObject) => {
|
|
390
390
|
const id = {{Name}}TypeDef.id(obj);
|
|
391
|
-
|
|
391
|
+
{{name}}Store.delete(id, delete{{Name}}ServerErrors)
|
|
392
|
+
.then(() => {{name}}Store.search());
|
|
392
393
|
};
|
|
393
394
|
watch({{name}}List, (newList) => {
|
|
394
395
|
if (newList && Array.isArray(newList) && newList.length === 0 && searchTerms.value && searchTerms.value.length === 0) {
|