mobiletto-orm-typedef-gen 2.3.42 → 2.8.0
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/README.md +16 -0
- package/lib/esm/generate.d.ts +12 -2
- package/lib/esm/generate.js +213 -30
- package/lib/esm/generate.js.map +1 -0
- package/lib/esm/generators/h3.d.ts +7 -0
- package/lib/esm/generators/h3.js +84 -0
- package/lib/esm/generators/h3.js.map +1 -0
- package/lib/esm/generators/jsonSchema.d.ts +3 -0
- package/lib/esm/generators/jsonSchema.js +48 -0
- package/lib/esm/generators/jsonSchema.js.map +1 -0
- package/lib/esm/generators/server.d.ts +14 -9
- package/lib/esm/generators/server.js +79 -53
- package/lib/esm/generators/server.js.map +1 -0
- package/lib/esm/generators/tsType.d.ts +2 -2
- package/lib/esm/generators/tsType.js +2 -1
- package/lib/esm/generators/tsType.js.map +1 -0
- package/lib/esm/generators/vue/admin.d.ts +5 -0
- package/lib/esm/generators/vue/admin.js +83 -0
- package/lib/esm/generators/vue/admin.js.map +1 -0
- package/lib/esm/generators/vue/service.d.ts +4 -0
- package/lib/esm/generators/vue/service.js +47 -0
- package/lib/esm/generators/vue/service.js.map +1 -0
- package/lib/esm/generators/vue/store.d.ts +5 -0
- package/lib/esm/generators/vue/store.js +43 -0
- package/lib/esm/generators/vue/store.js.map +1 -0
- package/lib/esm/helpers.d.ts +4 -0
- package/lib/esm/helpers.js +160 -0
- package/lib/esm/helpers.js.map +1 -0
- package/lib/esm/index.d.ts +6 -2
- package/lib/esm/index.js +7 -2
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/templates/admin/adminComponent.vue.hbs +662 -0
- package/lib/esm/templates/admin/adminHelper.ts.hbs +52 -0
- package/lib/esm/templates/admin/adminPage.vue.hbs +53 -0
- package/lib/esm/templates/api/h3.ts.hbs +13 -0
- package/lib/esm/templates/api/id.delete.ts.hbs +94 -32
- package/lib/esm/templates/api/id.get.ts.hbs +79 -18
- package/lib/esm/templates/api/id.patch.ts.hbs +76 -24
- package/lib/esm/templates/api/id.put.ts.hbs +65 -18
- package/lib/esm/templates/api/index.post.ts.hbs +111 -22
- package/lib/esm/templates/api/index.put.ts.hbs +75 -0
- package/lib/esm/templates/api/refs.ts.hbs +26 -0
- package/lib/esm/templates/filter/errorFilter.ts.hbs +10 -0
- package/lib/esm/templates/filter/sessionFilter.ts.hbs +125 -25
- package/lib/esm/templates/schema/jsonSchema.json.hbs +62 -0
- package/lib/esm/templates/service/service.ts.hbs +59 -29
- package/lib/esm/templates/service/serviceHelper.ts.hbs +38 -27
- package/lib/esm/templates/service/singletonService.ts.hbs +46 -24
- package/lib/esm/templates/store/singletonStore.ts.hbs +57 -28
- package/lib/esm/templates/store/store.ts.hbs +169 -39
- package/lib/esm/templates/store/storeHelper.ts.hbs +21 -9
- package/lib/esm/templates/type/tsType.ts.hbs +7 -3
- package/package.json +37 -22
- package/src/generate.ts +400 -0
- package/src/generators/h3.ts +125 -0
- package/src/generators/jsonSchema.ts +65 -0
- package/src/generators/server.ts +242 -0
- package/src/generators/tsType.ts +6 -0
- package/src/generators/vue/admin.ts +136 -0
- package/src/generators/vue/service.ts +76 -0
- package/src/generators/vue/store.ts +74 -0
- package/src/helpers.ts +195 -0
- package/src/index.ts +10 -0
- package/lib/cjs/generate.d.ts +0 -19
- package/lib/cjs/generate.js +0 -154
- package/lib/cjs/generators/client.d.ts +0 -8
- package/lib/cjs/generators/client.js +0 -75
- package/lib/cjs/generators/server.d.ts +0 -11
- package/lib/cjs/generators/server.js +0 -91
- package/lib/cjs/generators/tsType.d.ts +0 -3
- package/lib/cjs/generators/tsType.js +0 -4
- package/lib/cjs/generators/yup.d.ts +0 -3
- package/lib/cjs/generators/yup.js +0 -8
- package/lib/cjs/index.d.ts +0 -6
- package/lib/cjs/index.js +0 -6
- package/lib/cjs/package.json +0 -16
- package/lib/cjs/templates/api/id.delete.ts.hbs +0 -66
- package/lib/cjs/templates/api/id.get.ts.hbs +0 -38
- package/lib/cjs/templates/api/id.patch.ts.hbs +0 -51
- package/lib/cjs/templates/api/id.put.ts.hbs +0 -42
- package/lib/cjs/templates/api/index.post.ts.hbs +0 -39
- package/lib/cjs/templates/component/admin.vue.hbs +0 -493
- package/lib/cjs/templates/component/adminHelper.ts.hbs +0 -65
- package/lib/cjs/templates/component/componentHelper.d.ts +0 -3
- package/lib/cjs/templates/component/componentHelper.js +0 -53
- package/lib/cjs/templates/filter/errorFilter.ts.hbs +0 -51
- package/lib/cjs/templates/filter/sessionFilter.ts.hbs +0 -56
- package/lib/cjs/templates/service/service.ts.hbs +0 -58
- package/lib/cjs/templates/service/serviceHelper.ts.hbs +0 -97
- package/lib/cjs/templates/service/singletonService.ts.hbs +0 -49
- package/lib/cjs/templates/store/singletonStore.ts.hbs +0 -74
- package/lib/cjs/templates/store/store.ts.hbs +0 -94
- package/lib/cjs/templates/store/storeHelper.d.ts +0 -15
- package/lib/cjs/templates/store/storeHelper.js +0 -15
- package/lib/cjs/templates/store/storeHelper.ts.hbs +0 -34
- package/lib/cjs/templates/type/tsType.ts.hbs +0 -7
- package/lib/cjs/templates/validation/yup.ts.hbs +0 -39
- package/lib/esm/generators/client.d.ts +0 -8
- package/lib/esm/generators/client.js +0 -75
- package/lib/esm/generators/yup.d.ts +0 -3
- package/lib/esm/generators/yup.js +0 -8
- package/lib/esm/templates/component/admin.vue.hbs +0 -493
- package/lib/esm/templates/component/adminHelper.ts.hbs +0 -65
- package/lib/esm/templates/component/componentHelper.d.ts +0 -3
- package/lib/esm/templates/component/componentHelper.js +0 -53
- package/lib/esm/templates/store/storeHelper.d.ts +0 -15
- package/lib/esm/templates/store/storeHelper.js +0 -15
- package/lib/esm/templates/validation/yup.ts.hbs +0 -39
|
@@ -1,58 +1,88 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
3
|
{{{header}}}{{/if}}{{/if}}
|
|
3
4
|
|
|
4
|
-
import { Ref } from "vue";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { type Ref } from "vue";
|
|
6
|
+
import type {
|
|
7
|
+
MobilettoOrmObject,
|
|
8
|
+
MobilettoOrmPurgeResults,
|
|
9
|
+
MobilettoOrmResult,
|
|
10
|
+
MobilettoOrmValidationErrors,
|
|
11
|
+
} from "mobiletto-orm-typedef";
|
|
12
|
+
import { type {{ Name }}Type, {{ Name }}TypeDef } from "{{typeDefPackage}}";
|
|
7
13
|
import * as a from "{{utilsPath}}/serviceHelper.js";
|
|
14
|
+
import type { MobilettoOrmFindApiOpts } from "{{utilsPath}}/storeHelper.js";
|
|
8
15
|
|
|
9
|
-
export const {{
|
|
10
|
-
search{{ Name }},
|
|
11
|
-
find{{ Name }},
|
|
12
|
-
create{{ Name }},
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
+
export const {{ fullServiceName }}Service = {{{curlyOpen}}}{{#unless apiConfig.search.disabled}}
|
|
17
|
+
search{{ Name }},{{/unless}}{{#unless apiConfig.lookup.disabled}}
|
|
18
|
+
find{{ Name }},{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
19
|
+
create{{ Name }},{{#if typeDef.autoId}}
|
|
20
|
+
create{{ Name }}WithoutId,{{/if}}{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
21
|
+
update{{ Name }},{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
22
|
+
delete{{ Name }},{{/unless}}
|
|
23
|
+
};{{#unless apiConfig.search.disabled}}
|
|
16
24
|
|
|
17
|
-
function search{{ Name }}(
|
|
18
|
-
|
|
25
|
+
function search{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
26
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
27
|
+
query?: MobilettoOrmFindApiOpts,
|
|
28
|
+
): Promise<MobilettoOrmResult<{{ Name }}Type>> {
|
|
29
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}`, a.authPostJson(query)).then(
|
|
30
|
+
a.handleJsonResponse<MobilettoOrmResult<{{ Name }}Type>> as (response: unknown) => Promise<MobilettoOrmResult<{{ Name }}Type>>,
|
|
31
|
+
);
|
|
19
32
|
}
|
|
20
|
-
|
|
21
|
-
function find{{ Name }}(
|
|
33
|
+
{{/unless}}{{#unless apiConfig.lookup.disabled}}
|
|
34
|
+
function find{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
35
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
22
36
|
id: string,
|
|
23
37
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
24
38
|
): Promise<{{ Name }}Type> {
|
|
25
|
-
return
|
|
26
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
39
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}/${id}`, a.authGet())
|
|
40
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
27
41
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
28
42
|
}
|
|
29
|
-
|
|
30
|
-
function create{{ Name }}(
|
|
43
|
+
{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
44
|
+
function create{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
45
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
31
46
|
{{ name }}: {{ Name }}Type,
|
|
32
47
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
33
48
|
): Promise<{{ Name }}Type> {
|
|
34
49
|
const id = {{ Name }}TypeDef.id({{ name }});
|
|
35
|
-
return
|
|
36
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
50
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}/${{{curlyOpen}}}id{{{curlyClose}}}`, a.authPutJson({{ name }}))
|
|
51
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
37
52
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
38
53
|
}
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
{{#if typeDef.autoId}}function create{{ Name }}WithoutId({{#if parentPaths}}{{#each parentPaths}}
|
|
55
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
56
|
+
{{ name }}: {{ Name }}Type,
|
|
57
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
58
|
+
): Promise<{{ Name }}Type> {
|
|
59
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}`, a.authPutJson({{ name }}))
|
|
60
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
61
|
+
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
62
|
+
}{{/if}}
|
|
63
|
+
{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
64
|
+
function update{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
65
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
41
66
|
{{ name }}: {{ Name }}Type,
|
|
42
67
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
43
68
|
): Promise<{{ Name }}Type> {
|
|
44
69
|
const id = {{ Name }}TypeDef.id({{ name }});
|
|
45
|
-
return
|
|
46
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
70
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}/${{{curlyOpen}}}id{{{curlyClose}}}`, a.authPatchJson({{ name }}))
|
|
71
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
47
72
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
48
73
|
}
|
|
49
|
-
|
|
50
|
-
function delete{{ Name }}(
|
|
74
|
+
{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
75
|
+
function delete{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
76
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
51
77
|
id: string,
|
|
52
78
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
53
|
-
purge?: boolean
|
|
79
|
+
purge?: boolean,
|
|
54
80
|
): Promise<MobilettoOrmObject | MobilettoOrmPurgeResults> {
|
|
55
|
-
return
|
|
56
|
-
|
|
81
|
+
return fetch(
|
|
82
|
+
`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}/${id}/${purge ? `?purge=${purge}` : ""}`,
|
|
83
|
+
a.authDelete(),
|
|
84
|
+
)
|
|
85
|
+
.then(a.handleJsonResponse<MobilettoOrmObject | MobilettoOrmPurgeResults> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
57
86
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
58
87
|
}
|
|
88
|
+
{{/unless}}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
2
|
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { {{
|
|
3
|
+
{{#unless skipServiceHandlers}}
|
|
4
|
+
import type { Ref } from 'vue';
|
|
5
|
+
import type { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
6
|
+
import { {{logger}} } from '{{loggerImport}}'
|
|
7
|
+
{{/unless}}{{#eq sessionHeaderImport sessionCookieImport}}import { {{../sessionHeader}}, {{../sessionCookie}} } from "{{../sessionHeaderImport}}";
|
|
8
|
+
{{else}}import { {{../sessionHeader}} } from "{{../sessionHeaderImport}}";
|
|
9
|
+
import { {{../sessionCookie}} } from "{{../sessionCookieImport}}";
|
|
10
|
+
{{/eq}}
|
|
7
11
|
|
|
8
12
|
export function authHeader() {
|
|
9
13
|
const session = {{sessionCookie}}();
|
|
10
14
|
if (session) {
|
|
11
15
|
const headers: Record<string, string> = {};
|
|
12
|
-
headers[{{sessionHeader}}] = session
|
|
16
|
+
headers[{{sessionHeader}}] = session;
|
|
13
17
|
return headers;
|
|
14
18
|
} else {
|
|
15
19
|
return {};
|
|
@@ -28,7 +32,9 @@ export function authDelete(headers = null) {
|
|
|
28
32
|
|
|
29
33
|
export type OptionalHeaders = Record<string, string> | null;
|
|
30
34
|
|
|
31
|
-
export
|
|
35
|
+
export type HttpMethodType = "GET" | "POST" | "PUT" | "PATCH" | "HEAD" | "DELETE";
|
|
36
|
+
|
|
37
|
+
export function authReq(method: HttpMethodType, headers: OptionalHeaders = null) {
|
|
32
38
|
return {
|
|
33
39
|
method,
|
|
34
40
|
headers: headers ? Object.assign({}, headers, authHeader()) : authHeader(),
|
|
@@ -45,18 +51,18 @@ export function authPatchJson<T>(obj: T, headers: OptionalHeaders = null) {
|
|
|
45
51
|
return authDataJson<T>(obj, "PATCH", headers);
|
|
46
52
|
}
|
|
47
53
|
|
|
48
|
-
export function authDataJson<T>(obj: T, method:
|
|
54
|
+
export function authDataJson<T>(obj: T, method: HttpMethodType, headers: OptionalHeaders = null) {
|
|
49
55
|
return {
|
|
50
56
|
method,
|
|
51
57
|
headers: headers
|
|
52
|
-
?
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
58
|
+
? { ...headers, ...authHeader(), 'Content-Type': 'application/json' }
|
|
59
|
+
: typeof obj !== 'undefined' && obj != null
|
|
60
|
+
? { ...authHeader(), 'Content-Type': 'application/json' }
|
|
61
|
+
: authHeader(),
|
|
56
62
|
body: JSON.stringify(obj),
|
|
57
63
|
};
|
|
58
64
|
}
|
|
59
|
-
|
|
65
|
+
{{#unless skipServiceHandlers}}
|
|
60
66
|
export function handleJsonResponse<T>(response: Response): Promise<T> {
|
|
61
67
|
if (response && typeof response.text === "function") {
|
|
62
68
|
return response.text().then((text) => {
|
|
@@ -64,12 +70,12 @@ export function handleJsonResponse<T>(response: Response): Promise<T> {
|
|
|
64
70
|
try {
|
|
65
71
|
data = typeof text === "string" ? JSON.parse(text) : null;
|
|
66
72
|
} catch (e) {
|
|
67
|
-
|
|
73
|
+
{{logger}}.error(`handleJsonResponse: error parsing: ${text}`, e)
|
|
68
74
|
data = null;
|
|
69
75
|
}
|
|
70
76
|
if (!response.ok) {
|
|
71
77
|
const error = data || text || response.statusText;
|
|
72
|
-
return Promise.reject(error);
|
|
78
|
+
return Promise.reject(new Error(error));
|
|
73
79
|
}
|
|
74
80
|
// console.log(`handleJsonResponse returning: ${JSON.stringify(data, null, 2)}`)
|
|
75
81
|
return data;
|
|
@@ -79,19 +85,24 @@ export function handleJsonResponse<T>(response: Response): Promise<T> {
|
|
|
79
85
|
}
|
|
80
86
|
}
|
|
81
87
|
|
|
82
|
-
export const handleErrors =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (typeof e.data?.data === "string" && e.data.data.length > 0) {
|
|
88
|
-
serverErrors.value[e.data.data] = ["notFound"];
|
|
88
|
+
export const handleErrors =
|
|
89
|
+
(serverErrors?: Ref<MobilettoOrmValidationErrors>) =>
|
|
90
|
+
(e: Error & { statusCode?: number; data: unknown }) => {
|
|
91
|
+
if (!e.statusCode || !serverErrors) {
|
|
92
|
+
throw e
|
|
89
93
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
if (e.statusCode === 403) {
|
|
95
|
+
serverErrors.value.global = ['forbidden']
|
|
96
|
+
} else if (e.statusCode === 404) {
|
|
97
|
+
if (typeof e.data === 'string' && e.data.length > 0) {
|
|
98
|
+
serverErrors.value[e.data] = ['notFound']
|
|
99
|
+
}
|
|
100
|
+
} else if (e.statusCode === 422) {
|
|
101
|
+
if (typeof e.data === 'string' && e.data.length > 0) {
|
|
102
|
+
serverErrors.value = JSON.parse(e.data) as MobilettoOrmValidationErrors
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
throw e
|
|
93
106
|
}
|
|
94
|
-
} else {
|
|
95
|
-
throw e;
|
|
96
107
|
}
|
|
97
|
-
}
|
|
108
|
+
{{/unless}}
|
|
@@ -1,49 +1,71 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
1
2
|
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
3
|
{{{header}}}{{/if}}{{/if}}
|
|
3
4
|
|
|
4
|
-
import { Ref } from "vue";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { type Ref } from "vue";
|
|
6
|
+
import type {
|
|
7
|
+
MobilettoOrmObject,
|
|
8
|
+
MobilettoOrmPurgeResults,
|
|
9
|
+
MobilettoOrmValidationErrors
|
|
10
|
+
} from "mobiletto-orm-typedef";
|
|
11
|
+
import { type {{ Name }}Type, {{ Name }}TypeDef } from "{{typeDefPackage}}";
|
|
7
12
|
import * as a from "{{utilsPath}}/serviceHelper.js";
|
|
8
13
|
|
|
9
|
-
export const {{
|
|
10
|
-
find{{ Name }},
|
|
11
|
-
create{{ Name }},
|
|
12
|
-
update{{ Name }},
|
|
13
|
-
delete{{ Name }},
|
|
14
|
+
export const {{ fullServiceName }}Service = {{{curlyOpen}}}{{#unless apiConfig.lookup.disabled}}
|
|
15
|
+
find{{ Name }},{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
16
|
+
create{{ Name }},{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
17
|
+
update{{ Name }},{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
18
|
+
delete{{ Name }},{{/unless}}
|
|
14
19
|
};
|
|
15
|
-
|
|
16
|
-
function find{{ Name }}(
|
|
20
|
+
{{#unless apiConfig.lookup.disabled}}
|
|
21
|
+
function find{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
22
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
17
23
|
serverErrors?: Ref<MobilettoOrmValidationErrors>,
|
|
18
24
|
): Promise<{{ Name }}Type> {
|
|
19
|
-
return
|
|
20
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
25
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{name}}/{{ typeDef.singleton }}`, a.authGet())
|
|
26
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
21
27
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
22
28
|
}
|
|
23
|
-
|
|
24
|
-
function create{{ Name }}(
|
|
29
|
+
{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
30
|
+
function create{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
31
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
25
32
|
{{ name }}: {{ Name }}Type,
|
|
26
33
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
27
34
|
): Promise<{{ Name }}Type> {
|
|
28
|
-
return
|
|
29
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
35
|
+
return fetch("/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{name}}/{{ typeDef.singleton }}", a.authPutJson({{ name }}))
|
|
36
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
30
37
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
31
38
|
}
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
{{#if typeDef.autoId}}function create{{ Name }}WithoutId({{#if parentPaths}}{{#each parentPaths}}
|
|
40
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
41
|
+
{{ name }}: {{ Name }}Type,
|
|
42
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
43
|
+
): Promise<{{ Name }}Type> {
|
|
44
|
+
return fetch(`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{ name }}`, a.authPutJson({{ name }}))
|
|
45
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
46
|
+
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
47
|
+
}{{/if}}
|
|
48
|
+
{{/unless}}{{#unless apiConfig.edit.disabled}}
|
|
49
|
+
function update{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
50
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
34
51
|
{{ name }}: {{ Name }}Type,
|
|
35
52
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
36
53
|
): Promise<{{ Name }}Type> {
|
|
37
|
-
return
|
|
38
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
54
|
+
return fetch("/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{name}}/{{ typeDef.singleton }}", a.authPatchJson({{ name }}))
|
|
55
|
+
.then(a.handleJsonResponse<{{ Name }}Type> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
39
56
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
40
57
|
}
|
|
41
|
-
|
|
42
|
-
function delete{{ Name }}(
|
|
58
|
+
{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
59
|
+
function delete{{ Name }}({{#if parentPaths}}{{#each parentPaths}}
|
|
60
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
43
61
|
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
44
62
|
purge?: boolean
|
|
45
63
|
): Promise<MobilettoOrmObject | MobilettoOrmPurgeResults> {
|
|
46
|
-
return
|
|
47
|
-
.
|
|
64
|
+
return fetch(
|
|
65
|
+
`/api/model/{{#if parentPaths}}{{#each parentPaths}}{{refField}}/${ {{refField}} }/{{/each}}{{/if}}{{name}}/{{ typeDef.singleton }}/${purge ? `?purge=${purge}` : ""}`,
|
|
66
|
+
a.authDelete(),
|
|
67
|
+
)
|
|
68
|
+
.then(a.handleJsonResponse<MobilettoOrmObject | MobilettoOrmPurgeResults> as (response: unknown) => Promise<{{ Name }}Type>)
|
|
48
69
|
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
49
70
|
}
|
|
71
|
+
{{/unless}}
|
|
@@ -1,65 +1,94 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
2
|
{{{header}}}{{/if}}{{/if}}
|
|
3
3
|
|
|
4
|
-
import { Ref } from "vue";
|
|
4
|
+
import { type Ref } from "vue";
|
|
5
5
|
import { defineStore } from "pinia";
|
|
6
|
-
import { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
7
|
-
import { {{Name}}Type } from "{{typeDefPackage}}";
|
|
8
|
-
import { {{
|
|
6
|
+
import { type MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
7
|
+
import { type {{Name}}Type } from "{{typeDefPackage}}";
|
|
8
|
+
import { {{fullStoreName}}Service } from "{{servicesImportPath}}/{{firstParentTypeDef.typeName}}/{{fullStoreName}}Service";
|
|
9
9
|
|
|
10
|
-
export const use{{
|
|
11
|
-
state: () => ({
|
|
10
|
+
export const use{{FullStoreName}}Store = defineStore("{{fullStoreName}}", {
|
|
11
|
+
state: () => ({{{curlyOpen}}}{{#unless apiConfig.lookup.disabled}}
|
|
12
12
|
finding: false,
|
|
13
|
-
found: null as {{Name}}Type | null,
|
|
13
|
+
found: null as {{Name}}Type | null,{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
14
14
|
creating: false,
|
|
15
|
-
created: null as {{Name}}Type | null,
|
|
15
|
+
created: null as {{Name}}Type | null,{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
16
16
|
updating: false,
|
|
17
|
-
updated: null as {{Name}}Type | null,
|
|
17
|
+
updated: null as {{Name}}Type | null,{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
18
18
|
deleting: false,
|
|
19
|
-
deleted: null as boolean | null,
|
|
19
|
+
deleted: null as boolean | null,{{/unless}}
|
|
20
20
|
}),
|
|
21
21
|
getters: {
|
|
22
|
-
|
|
22
|
+
{{name}}Busy: (state) => false{{#unless apiConfig.lookup.disabled}} || state.finding{{/unless}}{{#unless apiConfig.create.disabled}} || state.creating{{/unless}}{{#unless apiConfig.edit.disabled}} || state.updating{{/unless}}{{#unless apiConfig.delete.disabled}} || state.deleting{{/unless}},
|
|
23
23
|
},
|
|
24
|
-
actions: {
|
|
25
|
-
async lookup(
|
|
24
|
+
actions: {{{curlyOpen}}}{{#unless apiConfig.lookup.disabled}}
|
|
25
|
+
async lookup({{#if parentPaths}}{{#each parentPaths}}
|
|
26
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
27
|
+
serverErrors?: Ref<MobilettoOrmValidationErrors>
|
|
28
|
+
): Promise<{{Name}}Type> {
|
|
26
29
|
this.found = null;
|
|
27
30
|
this.finding = true;
|
|
28
31
|
try {
|
|
29
|
-
this.found = await {{
|
|
30
|
-
return this.found
|
|
32
|
+
this.found = await {{fullStoreName}}Service.find{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}serverErrors);
|
|
33
|
+
return this.found as {{Name}}Type;
|
|
31
34
|
} finally {
|
|
32
35
|
this.finding = false;
|
|
33
36
|
}
|
|
34
37
|
},
|
|
35
|
-
async search(
|
|
38
|
+
async search({{#if parentPaths}}{{#each parentPaths}}
|
|
39
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
40
|
+
): Promise<{{Name}}Type[]> {
|
|
36
41
|
return [await this.lookup()];
|
|
37
|
-
},
|
|
38
|
-
async create(
|
|
42
|
+
},{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
43
|
+
async create({{#if parentPaths}}{{#each parentPaths}}
|
|
44
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
45
|
+
object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
39
46
|
try {
|
|
40
47
|
this.created = null;
|
|
41
48
|
this.creating = true;
|
|
42
|
-
this.created = await {{
|
|
43
|
-
return this.created;
|
|
49
|
+
this.created = await {{fullStoreName}}Service.create{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
|
|
50
|
+
return this.created as {{Name}}Type;
|
|
44
51
|
} finally {
|
|
45
52
|
this.creating = false;
|
|
46
53
|
}
|
|
47
|
-
},
|
|
48
|
-
async
|
|
54
|
+
},{{#if typeDef.autoId}}
|
|
55
|
+
async createWithoutId({{#if parentPaths}}{{#each parentPaths}}
|
|
56
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
57
|
+
object: {{Name}}Type,
|
|
58
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>
|
|
59
|
+
): Promise<{{Name}}Type> {
|
|
60
|
+
try {
|
|
61
|
+
this.created = null;
|
|
62
|
+
this.creating = true;
|
|
63
|
+
this.created = await {{fullStoreName}}Service.create{{Name}}WithoutId({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
|
|
64
|
+
return this.created as {{Name}}Type;
|
|
65
|
+
} finally {
|
|
66
|
+
this.creating = false;
|
|
67
|
+
}
|
|
68
|
+
},{{/if}}{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
69
|
+
async update({{#if parentPaths}}{{#each parentPaths}}
|
|
70
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
71
|
+
object: {{Name}}Type,
|
|
72
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>
|
|
73
|
+
): Promise<{{Name}}Type> {
|
|
49
74
|
try {
|
|
50
75
|
this.updated = null;
|
|
51
76
|
this.updating = true;
|
|
52
|
-
this.updated = await {{
|
|
53
|
-
return this.updated;
|
|
77
|
+
this.updated = await {{fullStoreName}}Service.update{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
|
|
78
|
+
return this.updated as {{Name}}Type;
|
|
54
79
|
} finally {
|
|
55
80
|
this.updating = false;
|
|
56
81
|
}
|
|
57
|
-
},
|
|
58
|
-
async delete(
|
|
82
|
+
},{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
83
|
+
async delete({{#if parentPaths}}{{#each parentPaths}}
|
|
84
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
85
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
86
|
+
purge?: boolean
|
|
87
|
+
): Promise<boolean> {
|
|
59
88
|
try {
|
|
60
89
|
this.deleted = null;
|
|
61
90
|
this.deleting = true;
|
|
62
|
-
const deleteResult = await {{
|
|
91
|
+
const deleteResult = await {{fullStoreName}}Service.delete{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}serverErrors, !!purge);
|
|
63
92
|
if (deleteResult) {
|
|
64
93
|
this.deleted = true;
|
|
65
94
|
} else {
|
|
@@ -69,6 +98,6 @@ export const use{{Name}}Store = defineStore("{{name}}", {
|
|
|
69
98
|
} finally {
|
|
70
99
|
this.deleting = false;
|
|
71
100
|
}
|
|
72
|
-
},
|
|
101
|
+
},{{/unless}}
|
|
73
102
|
},
|
|
74
103
|
});
|