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,56 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-duplicates */
|
|
2
|
-
{{#if disclaimer}}// {{{disclaimer}}}{{#if header}}
|
|
3
|
-
{{{header}}}{{/if}}{{/if}}
|
|
4
|
-
|
|
5
|
-
import { H3Event, deleteCookie } from "h3";
|
|
6
|
-
import { {{AccountType}}, {{SessionType}} } from "{{typeDefPackage}}";
|
|
7
|
-
import { {{SESSION_HEADER}} } from "{{sessionHeaderImport}}";
|
|
8
|
-
import { {{SESSION_COOKIE_NAME}} } from "{{sessionCookieNameImport}}";
|
|
9
|
-
import { {{cookieOptions}} } from "{{cookieOptionsImport}}";
|
|
10
|
-
import { forbidden } from "{{errorFilterImport}}";
|
|
11
|
-
import { {{sessionRepository}} } from "{{sessionRepositoryImport}}";
|
|
12
|
-
import { {{accountRepository}} } from "{{accountRepositoryImport}}";
|
|
13
|
-
|
|
14
|
-
export const requireAccount = async (
|
|
15
|
-
event: H3Event,
|
|
16
|
-
_logPrefix: string,
|
|
17
|
-
fn: (event: H3Event, session: {{SessionType}}) => Promise<unknown>,
|
|
18
|
-
) => {
|
|
19
|
-
if (!event?.node?.req?.headers[{{SESSION_HEADER}}]) {
|
|
20
|
-
deleteCookie(event, {{SESSION_COOKIE_NAME}}, await {{cookieOptions}}());
|
|
21
|
-
throw forbidden();
|
|
22
|
-
}
|
|
23
|
-
const token = event?.node?.req?.headers[{{SESSION_HEADER}}];
|
|
24
|
-
const session: {{SessionType}} | null = await {{sessionRepository}}().safeFindById(token);
|
|
25
|
-
if (!session) {
|
|
26
|
-
deleteCookie(event, {{SESSION_COOKIE_NAME}}, await {{cookieOptions}}());
|
|
27
|
-
throw forbidden();
|
|
28
|
-
}
|
|
29
|
-
return await fn(event, session);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const requireAccountObject = async (
|
|
33
|
-
event: H3Event,
|
|
34
|
-
logPrefix: string,
|
|
35
|
-
fn: (event: H3Event, session: {{SessionType}}, account: {{AccountType}}) => Promise<unknown>,
|
|
36
|
-
) => {
|
|
37
|
-
return await requireAccount(event, logPrefix, async (event, session) => {
|
|
38
|
-
const account: {{AccountType}} | null = await {{accountRepository}}().safeFindById(session.account);
|
|
39
|
-
if (!account) throw forbidden();
|
|
40
|
-
return await fn(event, session, account);
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const requireAdminAccountObject = async (
|
|
45
|
-
event: H3Event,
|
|
46
|
-
logPrefix: string,
|
|
47
|
-
fn: (event: H3Event, session: {{SessionType}}, account: {{AccountType}}) => Promise<unknown>,
|
|
48
|
-
) => {
|
|
49
|
-
return await requireAccountObject(event, logPrefix, async (event, session: {{SessionType}}, account: {{AccountType}}) => {
|
|
50
|
-
if (account.admin === true) {
|
|
51
|
-
return await fn(event, session, account);
|
|
52
|
-
} else {
|
|
53
|
-
throw forbidden();
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import { Ref } from "vue";
|
|
5
|
-
import { MobilettoOrmObject, MobilettoOrmPurgeResults, MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
6
|
-
import { {{ Name }}Type, {{ Name }}TypeDef } from "{{typeDefPackage}}";
|
|
7
|
-
import * as a from "{{utilsPath}}/serviceHelper.js";
|
|
8
|
-
|
|
9
|
-
export const {{ name }}Service = {
|
|
10
|
-
search{{ Name }},
|
|
11
|
-
find{{ Name }},
|
|
12
|
-
create{{ Name }},
|
|
13
|
-
update{{ Name }},
|
|
14
|
-
delete{{ Name }},
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function search{{ Name }}(query?: MobilettoOrmFindApiOpts): Promise<{{ Name }}Type[]> {
|
|
18
|
-
return $fetch("/api/model/{{ name }}", a.authPostJson(query)).then(a.handleJsonResponse<{{ Name }}Type[]>);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function find{{ Name }}(
|
|
22
|
-
id: string,
|
|
23
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
24
|
-
): Promise<{{ Name }}Type> {
|
|
25
|
-
return $fetch(`/api/model/{{ name }}/${id}`, a.authGet())
|
|
26
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
27
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function create{{ Name }}(
|
|
31
|
-
{{ name }}: {{ Name }}Type,
|
|
32
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
33
|
-
): Promise<{{ Name }}Type> {
|
|
34
|
-
const id = {{ Name }}TypeDef.id({{ name }});
|
|
35
|
-
return $fetch(`/api/model/{{ name }}/${{{curlyOpen}}}id{{{curlyClose}}}`, a.authPutJson({{ name }}))
|
|
36
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
37
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function update{{ Name }}(
|
|
41
|
-
{{ name }}: {{ Name }}Type,
|
|
42
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
43
|
-
): Promise<{{ Name }}Type> {
|
|
44
|
-
const id = {{ Name }}TypeDef.id({{ name }});
|
|
45
|
-
return $fetch(`/api/model/{{ name }}/${{{curlyOpen}}}id{{{curlyClose}}}`, a.authPatchJson({{ name }}))
|
|
46
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
47
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function delete{{ Name }}(
|
|
51
|
-
id: string,
|
|
52
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
53
|
-
purge?: boolean
|
|
54
|
-
): Promise<MobilettoOrmObject | MobilettoOrmPurgeResults> {
|
|
55
|
-
return $fetch(`/api/model/{{ name }}/${id}/${purge ? `?purge=${purge}` : ""}`, a.authDelete())
|
|
56
|
-
.then(a.handleJsonResponse<MobilettoOrmObject | MobilettoOrmPurgeResults>)
|
|
57
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
58
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
5
|
-
import { {{sessionHeader}} } from "{{sessionHeaderImport}}";
|
|
6
|
-
import { {{sessionCookie}} } from "{{sessionCookieImport}}";
|
|
7
|
-
|
|
8
|
-
export function authHeader() {
|
|
9
|
-
const session = {{sessionCookie}}();
|
|
10
|
-
if (session) {
|
|
11
|
-
const headers: Record<string, string> = {};
|
|
12
|
-
headers[{{sessionHeader}}] = session.value;
|
|
13
|
-
return headers;
|
|
14
|
-
} else {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function authHead(headers = null) {
|
|
20
|
-
return authReq("HEAD", headers);
|
|
21
|
-
}
|
|
22
|
-
export function authGet(headers = null) {
|
|
23
|
-
return authReq("GET", headers);
|
|
24
|
-
}
|
|
25
|
-
export function authDelete(headers = null) {
|
|
26
|
-
return authReq("DELETE", headers);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export type OptionalHeaders = Record<string, string> | null;
|
|
30
|
-
|
|
31
|
-
export function authReq(method: string, headers: OptionalHeaders = null) {
|
|
32
|
-
return {
|
|
33
|
-
method,
|
|
34
|
-
headers: headers ? Object.assign({}, headers, authHeader()) : authHeader(),
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function authPostJson<T>(obj: T, headers: OptionalHeaders = null) {
|
|
39
|
-
return authDataJson<T>(obj, "POST", headers);
|
|
40
|
-
}
|
|
41
|
-
export function authPutJson<T>(obj: T, headers: OptionalHeaders = null) {
|
|
42
|
-
return authDataJson<T>(obj, "PUT", headers);
|
|
43
|
-
}
|
|
44
|
-
export function authPatchJson<T>(obj: T, headers: OptionalHeaders = null) {
|
|
45
|
-
return authDataJson<T>(obj, "PATCH", headers);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function authDataJson<T>(obj: T, method: string, headers: OptionalHeaders = null) {
|
|
49
|
-
return {
|
|
50
|
-
method,
|
|
51
|
-
headers: headers
|
|
52
|
-
? Object.assign({}, headers, authHeader(), {
|
|
53
|
-
"Content-Type": "application/json",
|
|
54
|
-
})
|
|
55
|
-
: authHeader(),
|
|
56
|
-
body: JSON.stringify(obj),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function handleJsonResponse<T>(response: Response): Promise<T> {
|
|
61
|
-
if (response && typeof response.text === "function") {
|
|
62
|
-
return response.text().then((text) => {
|
|
63
|
-
let data;
|
|
64
|
-
try {
|
|
65
|
-
data = typeof text === "string" ? JSON.parse(text) : null;
|
|
66
|
-
} catch (e) {
|
|
67
|
-
// console.log(`handleJsonResponse: error parsing: ${text}`);
|
|
68
|
-
data = null;
|
|
69
|
-
}
|
|
70
|
-
if (!response.ok) {
|
|
71
|
-
const error = data || text || response.statusText;
|
|
72
|
-
return Promise.reject(error);
|
|
73
|
-
}
|
|
74
|
-
// console.log(`handleJsonResponse returning: ${JSON.stringify(data, null, 2)}`)
|
|
75
|
-
return data;
|
|
76
|
-
});
|
|
77
|
-
} else {
|
|
78
|
-
return Promise.resolve(response as T);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const handleErrors = (serverErrors?: Ref<MobilettoOrmValidationErrors>) => (e) => {
|
|
83
|
-
if (!e.statusCode || !serverErrors) throw e;
|
|
84
|
-
if (e.statusCode === 403) {
|
|
85
|
-
serverErrors.value.global = ["forbidden"];
|
|
86
|
-
} else if (e.statusCode === 404) {
|
|
87
|
-
if (typeof e.data?.data === "string" && e.data.data.length > 0) {
|
|
88
|
-
serverErrors.value[e.data.data] = ["notFound"];
|
|
89
|
-
}
|
|
90
|
-
} else if (e.statusCode === 422) {
|
|
91
|
-
if (typeof e.data?.data === "string" && e.data.data.length > 0) {
|
|
92
|
-
serverErrors.value = JSON.parse(e.data.data) as MobilettoOrmValidationErrors;
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
throw e;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import { Ref } from "vue";
|
|
5
|
-
import { MobilettoOrmObject, MobilettoOrmPurgeResults, MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
6
|
-
import { {{ Name }}Type, {{ Name }}TypeDef } from "{{typeDefPackage}}";
|
|
7
|
-
import * as a from "{{utilsPath}}/serviceHelper.js";
|
|
8
|
-
|
|
9
|
-
export const {{ name }}Service = {
|
|
10
|
-
find{{ Name }},
|
|
11
|
-
create{{ Name }},
|
|
12
|
-
update{{ Name }},
|
|
13
|
-
delete{{ Name }},
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function find{{ Name }}(
|
|
17
|
-
serverErrors?: Ref<MobilettoOrmValidationErrors>,
|
|
18
|
-
): Promise<{{ Name }}Type> {
|
|
19
|
-
return $fetch(`/api/model/{{ name }}/{{ typeDef.singleton }}`, a.authGet())
|
|
20
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
21
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function create{{ Name }}(
|
|
25
|
-
{{ name }}: {{ Name }}Type,
|
|
26
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
27
|
-
): Promise<{{ Name }}Type> {
|
|
28
|
-
return $fetch("/api/model/{{ name }}/{{ typeDef.singleton }}", a.authPutJson({{ name }}))
|
|
29
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
30
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function update{{ Name }}(
|
|
34
|
-
{{ name }}: {{ Name }}Type,
|
|
35
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
36
|
-
): Promise<{{ Name }}Type> {
|
|
37
|
-
return $fetch("/api/model/{{ name }}/{{ typeDef.singleton }}", a.authPatchJson({{ name }}))
|
|
38
|
-
.then(a.handleJsonResponse<{{ Name }}Type>)
|
|
39
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function delete{{ Name }}(
|
|
43
|
-
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
44
|
-
purge?: boolean
|
|
45
|
-
): Promise<MobilettoOrmObject | MobilettoOrmPurgeResults> {
|
|
46
|
-
return $fetch(`/api/model/{{ name }}/{{ typeDef.singleton }}/${purge ? `?purge=${purge}` : ""}`, a.authDelete())
|
|
47
|
-
.then(a.handleJsonResponse<MobilettoOrmObject | MobilettoOrmPurgeResults>)
|
|
48
|
-
.catch(a.handleErrors(serverErrors)) as Promise<{{Name}}Type>;
|
|
49
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import { Ref } from "vue";
|
|
5
|
-
import { defineStore } from "pinia";
|
|
6
|
-
import { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
7
|
-
import { {{Name}}Type } from "{{typeDefPackage}}";
|
|
8
|
-
import { {{name}}Service } from "{{servicesImportPath}}/{{name}}Service";
|
|
9
|
-
|
|
10
|
-
export const use{{Name}}Store = defineStore("{{name}}", {
|
|
11
|
-
state: () => ({
|
|
12
|
-
finding: false,
|
|
13
|
-
found: null as {{Name}}Type | null,
|
|
14
|
-
creating: false,
|
|
15
|
-
created: null as {{Name}}Type | null,
|
|
16
|
-
updating: false,
|
|
17
|
-
updated: null as {{Name}}Type | null,
|
|
18
|
-
deleting: false,
|
|
19
|
-
deleted: null as boolean | null,
|
|
20
|
-
}),
|
|
21
|
-
getters: {
|
|
22
|
-
{{name}}Busy: (state) => state.finding || state.creating || state.updating || state.deleting,
|
|
23
|
-
},
|
|
24
|
-
actions: {
|
|
25
|
-
async lookup(serverErrors?: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
26
|
-
this.found = null;
|
|
27
|
-
this.finding = true;
|
|
28
|
-
try {
|
|
29
|
-
this.found = await {{name}}Service.find{{Name}}(serverErrors);
|
|
30
|
-
return this.found
|
|
31
|
-
} finally {
|
|
32
|
-
this.finding = false;
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
async search(): Promise<{{Name}}Type[]> {
|
|
36
|
-
return [await this.lookup()];
|
|
37
|
-
},
|
|
38
|
-
async create(object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
39
|
-
try {
|
|
40
|
-
this.created = null;
|
|
41
|
-
this.creating = true;
|
|
42
|
-
this.created = await {{name}}Service.create{{Name}}(object, serverErrors);
|
|
43
|
-
return this.created;
|
|
44
|
-
} finally {
|
|
45
|
-
this.creating = false;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
async update(object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
49
|
-
try {
|
|
50
|
-
this.updated = null;
|
|
51
|
-
this.updating = true;
|
|
52
|
-
this.updated = await {{name}}Service.update{{Name}}(object, serverErrors);
|
|
53
|
-
return this.updated;
|
|
54
|
-
} finally {
|
|
55
|
-
this.updating = false;
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
async delete(serverErrors: Ref<MobilettoOrmValidationErrors>, purge?: boolean): Promise<boolean> {
|
|
59
|
-
try {
|
|
60
|
-
this.deleted = null;
|
|
61
|
-
this.deleting = true;
|
|
62
|
-
const deleteResult = await {{name}}Service.delete{{Name}}(serverErrors, !!purge);
|
|
63
|
-
if (deleteResult) {
|
|
64
|
-
this.deleted = true;
|
|
65
|
-
} else {
|
|
66
|
-
this.deleted = false;
|
|
67
|
-
}
|
|
68
|
-
return this.deleted;
|
|
69
|
-
} finally {
|
|
70
|
-
this.deleting = false;
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import { Ref } from "vue";
|
|
5
|
-
import { defineStore } from "pinia";
|
|
6
|
-
import { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
7
|
-
import { {{Name}}Type, {{Name}}TypeDef } from "{{typeDefPackage}}";
|
|
8
|
-
import { {{name}}Service } from "{{servicesImportPath}}/{{name}}Service";
|
|
9
|
-
import { MobilettoOrmFindApiOpts, updateOrmList } from "{{utilsImportPath}}/storeHelper.js";
|
|
10
|
-
|
|
11
|
-
const updateList = (list: {{Name}}Type[] | null, id: string, opts?: { object?: {{Name}}Type; remove?: boolean }) => {
|
|
12
|
-
return updateOrmList<{{Name}}Type>({{Name}}TypeDef, list, id, opts);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const use{{Name}}Store = defineStore("{{name}}", {
|
|
16
|
-
state: () => ({
|
|
17
|
-
finding: false,
|
|
18
|
-
found: null as {{Name}}Type | null,
|
|
19
|
-
creating: false,
|
|
20
|
-
created: null as {{Name}}Type | null,
|
|
21
|
-
updating: false,
|
|
22
|
-
updated: null as {{Name}}Type | null,
|
|
23
|
-
deleting: false,
|
|
24
|
-
deleted: null as boolean | null,
|
|
25
|
-
searching: false,
|
|
26
|
-
{{name}}List: null as {{Name}}Type[] | null,
|
|
27
|
-
}),
|
|
28
|
-
getters: {
|
|
29
|
-
{{name}}Busy: (state) => state.finding || state.creating || state.updating || state.deleting || state.searching,
|
|
30
|
-
},
|
|
31
|
-
actions: {
|
|
32
|
-
async lookup(id: string, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
33
|
-
this.found = null;
|
|
34
|
-
this.finding = true;
|
|
35
|
-
try {
|
|
36
|
-
this.found = await {{name}}Service.find{{Name}}(id, serverErrors);
|
|
37
|
-
if (this.found) {
|
|
38
|
-
updateList(this.{{name}}List, {{Name}}TypeDef.id(this.found), {object: this.found});
|
|
39
|
-
}
|
|
40
|
-
return this.found;
|
|
41
|
-
} finally {
|
|
42
|
-
this.finding = false;
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
async search(query?: MobilettoOrmFindApiOpts): Promise<{{Name}}Type[]> {
|
|
46
|
-
try {
|
|
47
|
-
this.searching = true;
|
|
48
|
-
this.{{name}}List = await {{name}}Service.search{{Name}}(query);
|
|
49
|
-
return this.{{name}}List || [];
|
|
50
|
-
} finally {
|
|
51
|
-
this.searching = false;
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
async create(object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
55
|
-
try {
|
|
56
|
-
this.created = null;
|
|
57
|
-
this.creating = true;
|
|
58
|
-
this.created = await {{name}}Service.create{{Name}}(object, serverErrors);
|
|
59
|
-
return this.created;
|
|
60
|
-
} finally {
|
|
61
|
-
this.creating = false;
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
async update(object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
|
|
65
|
-
try {
|
|
66
|
-
this.updated = null;
|
|
67
|
-
this.updating = true;
|
|
68
|
-
this.updated = await {{name}}Service.update{{Name}}(object, serverErrors);
|
|
69
|
-
if (this.updated) {
|
|
70
|
-
updateList(this.{{name}}List, {{Name}}TypeDef.id(this.updated), {object: this.updated});
|
|
71
|
-
}
|
|
72
|
-
return this.updated;
|
|
73
|
-
} finally {
|
|
74
|
-
this.updating = false;
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
async delete(id: string, serverErrors: Ref<MobilettoOrmValidationErrors>, purge?: boolean): Promise<boolean> {
|
|
78
|
-
try {
|
|
79
|
-
this.deleted = null;
|
|
80
|
-
this.deleting = true;
|
|
81
|
-
const deleteResult = await {{name}}Service.delete{{Name}}(id, serverErrors, !!purge);
|
|
82
|
-
if (deleteResult) {
|
|
83
|
-
updateList(this.{{name}}List, id, { remove: true });
|
|
84
|
-
this.deleted = true;
|
|
85
|
-
} else {
|
|
86
|
-
this.deleted = false;
|
|
87
|
-
}
|
|
88
|
-
return this.deleted;
|
|
89
|
-
} finally {
|
|
90
|
-
this.deleting = false;
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { MobilettoOrmObject, MobilettoOrmTypeDef } from "mobiletto-orm-typedef";
|
|
2
|
-
export type MobilettoOrmFindApiOpts = {
|
|
3
|
-
field?: string;
|
|
4
|
-
value?: string;
|
|
5
|
-
textSearch?: string;
|
|
6
|
-
opts?: {
|
|
7
|
-
first?: boolean;
|
|
8
|
-
removed?: boolean;
|
|
9
|
-
noRedact?: boolean;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
export declare const updateOrmList: <T extends MobilettoOrmObject>(typeDef: MobilettoOrmTypeDef, list: T[] | null, id: string, opts?: {
|
|
13
|
-
object?: T | undefined;
|
|
14
|
-
remove?: boolean | undefined;
|
|
15
|
-
} | undefined) => void;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const updateOrmList = (typeDef, list, id, opts) => {
|
|
2
|
-
if (!opts)
|
|
3
|
-
return;
|
|
4
|
-
if (list) {
|
|
5
|
-
const foundIndex = list.findIndex((e) => typeDef.id(e) === id);
|
|
6
|
-
if (foundIndex && foundIndex >= 0) {
|
|
7
|
-
if (opts && opts.remove === true) {
|
|
8
|
-
list.splice(foundIndex, 1);
|
|
9
|
-
}
|
|
10
|
-
else if (opts && opts.object) {
|
|
11
|
-
list.splice(foundIndex, 1, opts.object);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import { MobilettoOrmObject, MobilettoOrmTypeDef } from "mobiletto-orm-typedef";
|
|
5
|
-
|
|
6
|
-
export type MobilettoOrmFindApiOpts = {
|
|
7
|
-
field?: string;
|
|
8
|
-
value?: string;
|
|
9
|
-
textSearch?: string;
|
|
10
|
-
opts?: {
|
|
11
|
-
first?: boolean;
|
|
12
|
-
removed?: boolean;
|
|
13
|
-
noRedact?: boolean;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const updateOrmList = <T extends MobilettoOrmObject>(
|
|
18
|
-
typeDef: MobilettoOrmTypeDef,
|
|
19
|
-
list: T[] | null,
|
|
20
|
-
id: string,
|
|
21
|
-
opts?: { object?: T; remove?: boolean },
|
|
22
|
-
) => {
|
|
23
|
-
if (!opts) return;
|
|
24
|
-
if (list) {
|
|
25
|
-
const foundIndex = list.findIndex((e) => typeDef.id(e) === id);
|
|
26
|
-
if (foundIndex && foundIndex >= 0) {
|
|
27
|
-
if (opts && opts.remove === true) {
|
|
28
|
-
list.splice(foundIndex, 1);
|
|
29
|
-
} else if (opts && opts.object) {
|
|
30
|
-
list.splice(foundIndex, 1, opts.object);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}
|
|
3
|
-
import { MobilettoOrmObject } from "{{mobilettoOrmObjectPackage}}";
|
|
4
|
-
{{/if}}export type {{ Name }}Type = {{#if root}}MobilettoOrmObject & {{/if}}{
|
|
5
|
-
{{#each fields}} {{name}}{{#if optional}}?{{/if}}: {{#if typeIsObject}}{{ ../Name }}_{{name}}Type{{else if typeIsArray}}{{valueType}}[]{{else}}{{type}}{{/if}};
|
|
6
|
-
{{/each}}
|
|
7
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
|
-
{{{header}}}{{/if}}
|
|
3
|
-
|
|
4
|
-
import * as yup from "yup";{{/if}}
|
|
5
|
-
|
|
6
|
-
export const {{Name}}SchemaFields = {{{curlyOpen}}}{{#each fields}}
|
|
7
|
-
{{name}}: {{#if typeIsObject}}{{ ../Name }}_{{name}}Schema{{else}}{{#if typeIsArray}}yup.array().of(yup.{{valueType}}{{else}}yup.{{type}}{{/if}}(){{#if typeIsString}}.trim().transform(v => v === '' ? undefined : v){{/if}}{{#if isEnum}}
|
|
8
|
-
{{arrayIndent}}.oneOf({{{enumValues}}}, '{{labelName}}_enum'){{/if}}{{#if minValue}}
|
|
9
|
-
{{arrayIndent}}.min({{minValue}}, '{{labelName}}_minValue'){{/if}}{{#if maxValue}}
|
|
10
|
-
{{arrayIndent}}.max({{maxValue}}, '{{labelName}}_maxValue'){{/if}}{{#if min}}
|
|
11
|
-
{{arrayIndent}}.min({{min}}, '{{labelName}}_min'){{/if}}{{#if max}}
|
|
12
|
-
{{arrayIndent}}.max({{max}}, '{{labelName}}_max'){{/if}}{{#if regex}}
|
|
13
|
-
{{arrayIndent}}.matches({{{regexValue}}}, '{{labelName}}_regex'){{/if}}
|
|
14
|
-
{{arrayIndent}}.typeError('{{labelName}}_invalid'){{#if typeIsArray}})
|
|
15
|
-
.typeError('{{labelName}}_invalid'){{/if}}{{/if}}{{#if required}}
|
|
16
|
-
.required('{{labelName}}_required'){{else}}
|
|
17
|
-
.notRequired(){{/if}}{{#if default}}
|
|
18
|
-
.default({{{defaultValue}}}){{/if}}{{#if test}}
|
|
19
|
-
.test({
|
|
20
|
-
name: "{{test.message}}",
|
|
21
|
-
message: '{{labelName}}_{{test.message}}',
|
|
22
|
-
skipAbsent: true,
|
|
23
|
-
test(value{{#if ../typescript}}: string | number | boolean | null | undefined{{/if}}, ctx) {
|
|
24
|
-
const t = {{{testCode}}};
|
|
25
|
-
return typeof value === "undefined" || value == null || t({ ...ctx.parent });
|
|
26
|
-
}
|
|
27
|
-
}){{/if}}{{#if hasWhen}}
|
|
28
|
-
.when([{{{whenFieldNamesQuoted}}}], {
|
|
29
|
-
is: ({{#if ../typescript}}{{whenFieldSignature}}{{else}}{{whenFieldNames}}{{/if}}) => {
|
|
30
|
-
const w = {{{whenCode}}};
|
|
31
|
-
const v{{#if ../typescript}}: Record<string, unknown>{{/if}} = { {{whenFieldNames}} };
|
|
32
|
-
return w(v);
|
|
33
|
-
},
|
|
34
|
-
then: (schema) => schema.required('{{labelName}}_required'),
|
|
35
|
-
otherwise: (schema) => schema.notRequired(),
|
|
36
|
-
}){{/if}},{{/each}}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const {{Name}}Schema = yup.object({{Name}}SchemaFields);
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { MobilettoOrmTypeDef, MobilettoOrmTypeDefConfig } from "mobiletto-orm-typedef";
|
|
2
|
-
import { GenerateOptions } from "../generate.js";
|
|
3
|
-
export declare const generateService: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, utilsPath?: string) => string;
|
|
4
|
-
export declare const generateServiceHelper: (opts?: GenerateOptions, sessionHeader?: string, sessionHeaderImport?: string, sessionCookie?: string, sessionCookieImport?: string) => string;
|
|
5
|
-
export declare const generateStore: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, servicesImportPath?: string, utilsImportPath?: string) => string;
|
|
6
|
-
export declare const generateStoreHelper: (opts?: GenerateOptions) => string;
|
|
7
|
-
export declare const generateAdmin: (typeDef: MobilettoOrmTypeDef | MobilettoOrmTypeDefConfig, typeDefPackage: string, opts?: GenerateOptions, adminHelperPath?: string, sessionStoreImport?: string, localeMessages?: string) => string;
|
|
8
|
-
export declare const generateAdminHelper: (opts?: GenerateOptions) => string;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { DUMMY_TYPEDEF, generate } from "../generate.js";
|
|
2
|
-
export const generateService = (typeDef, typeDefPackage, opts, utilsPath) => {
|
|
3
|
-
utilsPath || (utilsPath = `~/utils/model`);
|
|
4
|
-
opts || (opts = {});
|
|
5
|
-
opts.prepareContext = (typeDef, ctx) => {
|
|
6
|
-
return ctx;
|
|
7
|
-
};
|
|
8
|
-
opts.rootOnly = true;
|
|
9
|
-
return generate(typeDef, `templates/service/${typeDef.singleton ? "singletonS" : "s"}ervice.ts.hbs`, opts, {
|
|
10
|
-
typeDefPackage,
|
|
11
|
-
utilsPath,
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
export const generateServiceHelper = (opts, sessionHeader, sessionHeaderImport, sessionCookie, sessionCookieImport) => {
|
|
15
|
-
sessionHeader || (sessionHeader = "SESSION_HEADER");
|
|
16
|
-
sessionHeaderImport || (sessionHeaderImport = "~/utils/auth");
|
|
17
|
-
sessionCookie || (sessionCookie = "sessionCookie");
|
|
18
|
-
sessionCookieImport || (sessionCookieImport = "~/utils/auth");
|
|
19
|
-
opts || (opts = {});
|
|
20
|
-
opts.prepareContext = (typeDef, ctx) => {
|
|
21
|
-
return ctx;
|
|
22
|
-
};
|
|
23
|
-
opts.rootOnly = true;
|
|
24
|
-
return generate(DUMMY_TYPEDEF, "templates/service/serviceHelper.ts.hbs", opts, {
|
|
25
|
-
sessionHeader,
|
|
26
|
-
sessionHeaderImport,
|
|
27
|
-
sessionCookie,
|
|
28
|
-
sessionCookieImport,
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
export const generateStore = (typeDef, typeDefPackage, opts, servicesImportPath, utilsImportPath) => {
|
|
32
|
-
servicesImportPath || (servicesImportPath = "~/utils/services/model");
|
|
33
|
-
utilsImportPath || (utilsImportPath = "~/utils/model");
|
|
34
|
-
opts || (opts = {});
|
|
35
|
-
opts.prepareContext = (typeDef, ctx) => {
|
|
36
|
-
return ctx;
|
|
37
|
-
};
|
|
38
|
-
opts.rootOnly = true;
|
|
39
|
-
return generate(typeDef, `templates/store/${typeDef.singleton ? "singletonS" : "s"}tore.ts.hbs`, opts, {
|
|
40
|
-
typeDefPackage,
|
|
41
|
-
servicesImportPath,
|
|
42
|
-
utilsImportPath,
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
export const generateStoreHelper = (opts) => {
|
|
46
|
-
opts || (opts = {});
|
|
47
|
-
opts.prepareContext = (typeDef, ctx) => {
|
|
48
|
-
return ctx;
|
|
49
|
-
};
|
|
50
|
-
opts.rootOnly = true;
|
|
51
|
-
return generate(DUMMY_TYPEDEF, `templates/store/storeHelper.ts.hbs`, opts);
|
|
52
|
-
};
|
|
53
|
-
export const generateAdmin = (typeDef, typeDefPackage, opts, adminHelperPath, sessionStoreImport, localeMessages) => {
|
|
54
|
-
adminHelperPath || (adminHelperPath = `~/utils/model/adminHelper`);
|
|
55
|
-
sessionStoreImport || (sessionStoreImport = `~/stores/sessionStore`);
|
|
56
|
-
localeMessages || (localeMessages = "localeMessages");
|
|
57
|
-
opts || (opts = {});
|
|
58
|
-
opts.prepareContext = (typeDef, ctx) => {
|
|
59
|
-
return ctx;
|
|
60
|
-
};
|
|
61
|
-
opts.rootOnly = true;
|
|
62
|
-
return generate(typeDef, `templates/component/admin.vue.hbs`, opts, {
|
|
63
|
-
typeDefPackage,
|
|
64
|
-
adminHelperPath,
|
|
65
|
-
sessionStoreImport,
|
|
66
|
-
localeMessages,
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
|
-
export const generateAdminHelper = (opts) => {
|
|
70
|
-
opts || (opts = {});
|
|
71
|
-
opts.prepareContext = (typeDef, ctx) => {
|
|
72
|
-
return ctx;
|
|
73
|
-
};
|
|
74
|
-
return generate(DUMMY_TYPEDEF, `templates/component/adminHelper.ts.hbs`, opts);
|
|
75
|
-
};
|