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,86 +1,216 @@
|
|
|
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 { type Ref } from "vue";
|
|
5
6
|
import { defineStore } from "pinia";
|
|
6
|
-
import { MobilettoOrmValidationErrors } from "mobiletto-orm-typedef";
|
|
7
|
-
import { {{Name}}Type, {{Name}}TypeDef } from "{{typeDefPackage}}";
|
|
8
|
-
import { {{
|
|
9
|
-
import { MobilettoOrmFindApiOpts, updateOrmList } from "{{utilsImportPath}}/storeHelper.js";
|
|
7
|
+
import type { MobilettoOrmValidationErrors, MobilettoOrmResult } from "mobiletto-orm-typedef";
|
|
8
|
+
import { type {{Name}}Type, {{Name}}TypeDef } from "{{typeDefPackage}}";
|
|
9
|
+
import { {{fullStoreName}}Service } from "{{servicesImportPath}}/{{firstParentTypeDef.typeName}}/{{fullStoreName}}Service";
|
|
10
|
+
import { type MobilettoOrmFindApiOpts, updateOrmList } from "{{utilsImportPath}}/storeHelper.js";
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
type {{Name}}SearchQuery = {{{curlyOpen}}}{{#if parentPaths}}{{#each parentPaths}}
|
|
13
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
14
|
+
query?: MobilettoOrmFindApiOpts
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
type {{Name}}SearchResult = MobilettoOrmResult<{{Name}}Type> & {
|
|
18
|
+
searchQuery?: {{Name}}SearchQuery;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
interface {{Name}}State {{{curlyOpen}}}{{#unless apiConfig.lookup.disabled}}
|
|
22
|
+
finding: boolean;
|
|
23
|
+
found{{Name}}: {{Name}}Type | null,{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
24
|
+
creating: boolean;
|
|
25
|
+
created: {{Name}}Type | null,{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
26
|
+
updating: boolean,
|
|
27
|
+
updated: {{Name}}Type | null,{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
28
|
+
deleting: boolean,
|
|
29
|
+
deleted: boolean | null,{{/unless}}{{#unless apiConfig.search.disabled}}
|
|
30
|
+
searching: boolean,
|
|
31
|
+
{{name}}ResultsByCursor: Map<string, {{Name}}SearchResult>,
|
|
32
|
+
{{name}}ResultsByQuery: Map<string, {{Name}}SearchResult>,
|
|
33
|
+
{{name}}Results: {{Name}}SearchResult,{{/unless}}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const updateResults = (state: {{Name}}State, id: string, opts: { object?: {{Name}}Type; remove?: boolean }) => {
|
|
37
|
+
const updated = new Set<{{Name}}Type[]>();
|
|
38
|
+
if (state.{{name}}Results?.objects) {
|
|
39
|
+
updateOrmList<{{Name}}Type>({{Name}}TypeDef, state.{{name}}Results.objects, id, opts)
|
|
40
|
+
updated.add(state.{{name}}Results.objects);
|
|
41
|
+
}
|
|
42
|
+
for (const objs of Object.values(state.{{name}}ResultsByQuery).map((r) => r.objects)) {
|
|
43
|
+
if (!updated.has(objs)) {
|
|
44
|
+
updateOrmList<{{Name}}Type>({{Name}}TypeDef, objs, id, opts);
|
|
45
|
+
updated.add(objs);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
for (const objs of Object.values(state.{{name}}ResultsByCursor).map((r) => r.objects)) {
|
|
49
|
+
if (!updated.has(objs)) {
|
|
50
|
+
updateOrmList<{{Name}}Type>({{Name}}TypeDef, objs, id, opts);
|
|
51
|
+
updated.add(objs);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const to{{Name}}SearchQuery = ({{#if parentPaths}}{{#each parentPaths}}
|
|
57
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
58
|
+
query?: MobilettoOrmFindApiOpts
|
|
59
|
+
): {{Name}}SearchQuery => ({{{curlyOpen}}}{{#if parentPaths}}{{#each parentPaths}}
|
|
60
|
+
{{refField}},{{/each}}{{/if}}
|
|
61
|
+
query
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
export const use{{FullStoreName}}Store = defineStore("{{fullStoreName}}", {
|
|
65
|
+
state: (): {{Name}}State => ({{{curlyOpen}}}{{#unless apiConfig.lookup.disabled}}
|
|
17
66
|
finding: false,
|
|
18
|
-
found: null as {{Name}}Type | null,
|
|
67
|
+
found{{Name}}: null as {{Name}}Type | null,{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
19
68
|
creating: false,
|
|
20
|
-
created: null as {{Name}}Type | null,
|
|
69
|
+
created: null as {{Name}}Type | null,{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
21
70
|
updating: false,
|
|
22
|
-
updated: null as {{Name}}Type | null,
|
|
71
|
+
updated: null as {{Name}}Type | null,{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
23
72
|
deleting: false,
|
|
24
|
-
deleted: null as boolean | null,
|
|
73
|
+
deleted: null as boolean | null,{{/unless}}{{#unless apiConfig.search.disabled}}
|
|
25
74
|
searching: false,
|
|
26
|
-
{{name}}
|
|
75
|
+
{{name}}ResultsByCursor: new Map<string, {{Name}}SearchResult>(),
|
|
76
|
+
{{name}}ResultsByQuery: new Map<string, {{Name}}SearchResult>(),
|
|
77
|
+
{{name}}Results: { objects: [] } as {{Name}}SearchResult,{{/unless}}
|
|
27
78
|
}),
|
|
28
79
|
getters: {
|
|
29
|
-
|
|
80
|
+
// eslint-disable-next-line no-constant-binary-expression
|
|
81
|
+
{{name}}Busy: (state) => false{{#unless apiConfig.lookup.disabled}} || state.finding{{/unless}}{{#unless apiConfig.create.disabled}} || state.creating{{/unless}}{{#unless apiConfig.update.disabled}} || state.updating{{/unless}}{{#unless apiConfig.delete.disabled}} || state.deleting{{/unless}}{{#unless apiConfig.search.disabled}} || state.searching{{/unless}},
|
|
30
82
|
},
|
|
31
|
-
actions: {
|
|
32
|
-
async lookup(
|
|
33
|
-
|
|
83
|
+
actions: {{{curlyOpen}}}{{#unless apiConfig.lookup.disabled}}
|
|
84
|
+
async lookup({{#if parentPaths}}{{#each parentPaths}}
|
|
85
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
86
|
+
id: string,
|
|
87
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>
|
|
88
|
+
): Promise<{{Name}}Type> {
|
|
89
|
+
this.found{{Name}} = null;
|
|
34
90
|
this.finding = true;
|
|
35
91
|
try {
|
|
36
|
-
this.found = await {{
|
|
37
|
-
if (this.found) {
|
|
38
|
-
|
|
92
|
+
this.found{{Name}} = await {{fullStoreName}}Service.find{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}id, serverErrors);
|
|
93
|
+
if (this.found{{Name}}) {
|
|
94
|
+
if (this.{{name}}Results) {
|
|
95
|
+
updateResults(this.$state, {{Name}}TypeDef.id(this.found{{Name}}), { object: this.found{{Name}} });
|
|
96
|
+
}
|
|
39
97
|
}
|
|
40
|
-
return this.found;
|
|
98
|
+
return this.found{{Name}} as {{Name}}Type;
|
|
41
99
|
} finally {
|
|
42
100
|
this.finding = false;
|
|
43
101
|
}
|
|
44
|
-
},
|
|
45
|
-
async
|
|
102
|
+
},{{/unless}}{{#unless apiConfig.search.disabled}}
|
|
103
|
+
async searchByQuery(searchQuery: {{Name}}SearchQuery): Promise<{{Name}}SearchResult> {
|
|
46
104
|
try {
|
|
47
105
|
this.searching = true;
|
|
48
|
-
|
|
49
|
-
|
|
106
|
+
const cacheKey = JSON.stringify(searchQuery);
|
|
107
|
+
if (this.{{name}}ResultsByQuery.has(cacheKey)) {
|
|
108
|
+
return this.{{name}}ResultsByQuery.get(cacheKey) as {{Name}}SearchResult;
|
|
109
|
+
}
|
|
110
|
+
const searchResult = await {{fullStoreName}}Service.search{{Name}}({{#if parentPaths}}{{#each parentPaths}}searchQuery.{{refField}}, {{/each}}{{/if}}searchQuery.query);
|
|
111
|
+
if (!searchResult || !searchResult.object || !searchResult.objects) {
|
|
112
|
+
return this.{{name}}Results as {{Name}}SearchResult;
|
|
113
|
+
}
|
|
114
|
+
if (searchResult.objects) {
|
|
115
|
+
this.{{name}}Results = { ...searchResult, searchQuery };
|
|
116
|
+
} else if (searchResult.object) {
|
|
117
|
+
this.{{name}}Results = { ...searchResult, objects: [searchResult.object], searchQuery };
|
|
118
|
+
} else {
|
|
119
|
+
return this.{{name}}Results as {{Name}}SearchResult;
|
|
120
|
+
}
|
|
121
|
+
this.{{name}}ResultsByQuery.set(cacheKey, this.{{name}}Results);
|
|
122
|
+
if (typeof searchResult.cursor === "string" && searchResult.cursor.length > 0) {
|
|
123
|
+
this.{{name}}ResultsByCursor.set(searchResult.cursor, this.{{name}}Results);
|
|
124
|
+
}
|
|
125
|
+
return this.{{name}}Results as {{Name}}SearchResult;
|
|
50
126
|
} finally {
|
|
51
127
|
this.searching = false;
|
|
52
128
|
}
|
|
53
129
|
},
|
|
54
|
-
async
|
|
130
|
+
async search({{#if parentPaths}}{{#each parentPaths}}
|
|
131
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
132
|
+
query?: MobilettoOrmFindApiOpts
|
|
133
|
+
): Promise<{{Name}}SearchResult> {
|
|
134
|
+
const searchQuery = to{{Name}}SearchQuery({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}query);
|
|
135
|
+
return await this.searchByQuery(searchQuery);
|
|
136
|
+
},
|
|
137
|
+
previousPage(): {{Name}}SearchResult {
|
|
138
|
+
if (this.{{name}}Results && this.{{name}}Results.previous && this.{{name}}ResultsByCursor.has(this.{{name}}Results.previous)) {
|
|
139
|
+
this.{{name}}Results = this.{{name}}ResultsByCursor.get(this.{{name}}Results.previous) as {{Name}}SearchResult;
|
|
140
|
+
}
|
|
141
|
+
return this.{{name}}Results as {{Name}}SearchResult;
|
|
142
|
+
},
|
|
143
|
+
async nextPage(): Promise<{{Name}}SearchResult> {
|
|
144
|
+
if (this.{{name}}Results && this.{{name}}Results.next) {
|
|
145
|
+
if (this.{{name}}ResultsByCursor.has(this.{{name}}Results.next)) {
|
|
146
|
+
this.{{name}}Results = this.{{name}}ResultsByCursor.get(this.{{name}}Results.next) as {{Name}}SearchResult;
|
|
147
|
+
return this.{{name}}Results as {{Name}}SearchResult;
|
|
148
|
+
} else if (this.{{name}}Results && this.{{name}}Results.searchQuery) {
|
|
149
|
+
const nextQuery = { ...this.{{name}}Results.searchQuery, cursor: this.{{name}}Results.next };
|
|
150
|
+
return await this.searchByQuery(nextQuery);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return this.{{name}}Results;
|
|
154
|
+
},{{/unless}}{{#unless apiConfig.create.disabled}}
|
|
155
|
+
async create({{#if parentPaths}}{{#each parentPaths}}
|
|
156
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
157
|
+
object: {{Name}}Type,
|
|
158
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>
|
|
159
|
+
): Promise<{{Name}}Type> {
|
|
55
160
|
try {
|
|
56
161
|
this.created = null;
|
|
57
162
|
this.creating = true;
|
|
58
|
-
this.created = await {{
|
|
59
|
-
|
|
163
|
+
this.created = await {{fullStoreName}}Service.create{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
|
|
164
|
+
this.{{name}}Results.objects?.unshift(this.created);
|
|
165
|
+
return this.created as {{Name}}Type;
|
|
60
166
|
} finally {
|
|
61
167
|
this.creating = false;
|
|
62
168
|
}
|
|
63
|
-
},
|
|
64
|
-
async
|
|
169
|
+
},{{#if typeDef.autoId}}
|
|
170
|
+
async createWithoutId({{#if parentPaths}}{{#each parentPaths}}
|
|
171
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
172
|
+
object: {{Name}}Type,
|
|
173
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>
|
|
174
|
+
): Promise<{{Name}}Type> {
|
|
175
|
+
try {
|
|
176
|
+
this.created = null;
|
|
177
|
+
this.creating = true;
|
|
178
|
+
this.created = await {{fullStoreName}}Service.create{{Name}}WithoutId({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
|
|
179
|
+
this.{{name}}Results.objects?.unshift(this.created);
|
|
180
|
+
return this.created as {{Name}}Type;
|
|
181
|
+
} finally {
|
|
182
|
+
this.creating = false;
|
|
183
|
+
}
|
|
184
|
+
},{{/if}}{{/unless}}{{#unless apiConfig.update.disabled}}
|
|
185
|
+
async update({{#if parentPaths}}{{#each parentPaths}}
|
|
186
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
187
|
+
object: {{Name}}Type,
|
|
188
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>
|
|
189
|
+
): Promise<{{Name}}Type> {
|
|
65
190
|
try {
|
|
66
191
|
this.updated = null;
|
|
67
192
|
this.updating = true;
|
|
68
|
-
this.updated = await {{
|
|
193
|
+
this.updated = await {{fullStoreName}}Service.update{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
|
|
69
194
|
if (this.updated) {
|
|
70
|
-
|
|
195
|
+
updateResults(this.$state, {{Name}}TypeDef.id(this.updated), { object: this.updated });
|
|
71
196
|
}
|
|
72
|
-
return this.updated;
|
|
197
|
+
return this.updated as {{Name}}Type;
|
|
73
198
|
} finally {
|
|
74
199
|
this.updating = false;
|
|
75
200
|
}
|
|
76
|
-
},
|
|
77
|
-
async delete(
|
|
201
|
+
},{{/unless}}{{#unless apiConfig.delete.disabled}}
|
|
202
|
+
async delete({{#if parentPaths}}{{#each parentPaths}}
|
|
203
|
+
{{refField}}: string,{{/each}}{{/if}}
|
|
204
|
+
id: string,
|
|
205
|
+
serverErrors: Ref<MobilettoOrmValidationErrors>,
|
|
206
|
+
purge?: boolean
|
|
207
|
+
): Promise<boolean> {
|
|
78
208
|
try {
|
|
79
209
|
this.deleted = null;
|
|
80
210
|
this.deleting = true;
|
|
81
|
-
const deleteResult = await {{
|
|
211
|
+
const deleteResult = await {{fullStoreName}}Service.delete{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}id, serverErrors, !!purge);
|
|
82
212
|
if (deleteResult) {
|
|
83
|
-
|
|
213
|
+
updateResults(this.$state, id, { remove: true });
|
|
84
214
|
this.deleted = true;
|
|
85
215
|
} else {
|
|
86
216
|
this.deleted = false;
|
|
@@ -89,6 +219,6 @@ export const use{{Name}}Store = defineStore("{{name}}", {
|
|
|
89
219
|
} finally {
|
|
90
220
|
this.deleting = false;
|
|
91
221
|
}
|
|
92
|
-
},
|
|
222
|
+
},{{/unless}}
|
|
93
223
|
},
|
|
94
224
|
});
|
|
@@ -1,34 +1,46 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
2
|
{{{header}}}{{/if}}{{/if}}
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type MobilettoOrmObject,
|
|
6
|
+
type MobilettoOrmTypeDef,
|
|
7
|
+
FIND_FIRST,
|
|
8
|
+
FIND_ALL,
|
|
9
|
+
} from 'mobiletto-orm-typedef'
|
|
5
10
|
|
|
6
11
|
export type MobilettoOrmFindApiOpts = {
|
|
7
12
|
field?: string;
|
|
8
13
|
value?: string;
|
|
14
|
+
indexes?: Record<string, string>;
|
|
9
15
|
textSearch?: string;
|
|
10
16
|
opts?: {
|
|
11
17
|
first?: boolean;
|
|
12
18
|
removed?: boolean;
|
|
13
19
|
noRedact?: boolean;
|
|
14
|
-
|
|
15
|
-
|
|
20
|
+
limit?: number;
|
|
21
|
+
cursor?: string;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const STORE_FIND_FIRST: MobilettoOrmFindApiOpts = { opts: FIND_FIRST }
|
|
26
|
+
export const STORE_FIND_ALL: MobilettoOrmFindApiOpts = { opts: FIND_ALL }
|
|
16
27
|
|
|
17
28
|
export const updateOrmList = <T extends MobilettoOrmObject>(
|
|
18
29
|
typeDef: MobilettoOrmTypeDef,
|
|
19
30
|
list: T[] | null,
|
|
20
31
|
id: string,
|
|
21
32
|
opts?: { object?: T; remove?: boolean },
|
|
22
|
-
) => {
|
|
23
|
-
if (!opts) return
|
|
33
|
+
): T[] => {
|
|
34
|
+
if (!opts) return list || []
|
|
24
35
|
if (list) {
|
|
25
|
-
const foundIndex = list.findIndex((e) => typeDef.id(e) === id)
|
|
36
|
+
const foundIndex = list.findIndex((e) => typeDef.id(e) === id)
|
|
26
37
|
if (foundIndex && foundIndex >= 0) {
|
|
27
38
|
if (opts && opts.remove === true) {
|
|
28
|
-
list.splice(foundIndex, 1)
|
|
39
|
+
list.splice(foundIndex, 1)
|
|
29
40
|
} else if (opts && opts.object) {
|
|
30
|
-
list.splice(foundIndex, 1, opts.object)
|
|
41
|
+
list.splice(foundIndex, 1, opts.object)
|
|
31
42
|
}
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
|
-
|
|
45
|
+
return list || []
|
|
46
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{{#if disclaimer}}// {{{ disclaimer }}}{{#if header}}
|
|
2
2
|
{{{header}}}{{/if}}
|
|
3
|
-
import { MobilettoOrmObject } from "{{mobilettoOrmObjectPackage}}";
|
|
4
|
-
{{/if}}
|
|
5
|
-
{{#each
|
|
3
|
+
import { type MobilettoOrmObject } from "{{mobilettoOrmObjectPackage}}";
|
|
4
|
+
{{/if}}{{#notEmpty tsTypeImports}}
|
|
5
|
+
{{#each tsTypeImports}}{{#notEmpty tsTypes}}
|
|
6
|
+
import { {{#each tsTypes}}type {{this}}{{#unless @last}}, {{/unless}}{{/each}} } from "{{tsTypePackage}}";
|
|
7
|
+
{{/notEmpty}}{{/each}}{{/notEmpty}}
|
|
8
|
+
export type {{ Name }}Type = {{#if root}}MobilettoOrmObject & {{/if}}{
|
|
9
|
+
{{#each fields}} {{name}}{{#if optional}}?{{/if}}: {{#if tsType}}{{{tsType}}}{{else if typeIsObject}}{{ ../Name }}_{{name}}Type{{else if typeIsArray}}{{valueType}}[]{{else}}{{type}}{{/if}};
|
|
6
10
|
{{/each}}
|
|
7
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobiletto-orm-typedef-gen",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "generate various files based on mobiletto-orm-typedef definitions",
|
|
6
6
|
"keywords": [
|
|
@@ -25,39 +25,54 @@
|
|
|
25
25
|
"url": "https://github.com/cobbzilla/mobiletto-orm-typedef-gen.git"
|
|
26
26
|
},
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"prettier": "npx prettier src test --check",
|
|
34
|
-
"prettier:fix": "npm run prettier -- --write"
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"handlebars": "^4.7.7",
|
|
30
|
+
"mobiletto-orm-typedef": "^3.1.0",
|
|
31
|
+
"pathe": "^1.1.2",
|
|
32
|
+
"zilla-util": "^1.3.0"
|
|
35
33
|
},
|
|
36
|
-
"main": "./lib/
|
|
34
|
+
"main": "./lib/esm/index.js",
|
|
37
35
|
"module": "./lib/esm/index.js",
|
|
38
36
|
"exports": {
|
|
39
37
|
".": "./lib/esm/index.js"
|
|
40
38
|
},
|
|
41
39
|
"files": [
|
|
42
|
-
"lib/"
|
|
40
|
+
"lib/",
|
|
41
|
+
"src/**/*.ts"
|
|
43
42
|
],
|
|
44
43
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
44
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
45
|
+
"@eslint/js": "^9.18.0",
|
|
46
|
+
"@types/chai": "^5.2.3",
|
|
47
|
+
"@types/json-schema": "^7.0.15",
|
|
48
|
+
"@types/mocha": "^10.0.10",
|
|
47
49
|
"@types/node": "^20.4.2",
|
|
48
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
49
|
-
"@typescript-eslint/parser": "^
|
|
50
|
-
"
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^8.20.0",
|
|
51
|
+
"@typescript-eslint/parser": "^8.20.0",
|
|
52
|
+
"ajv": "^8.17.1",
|
|
53
|
+
"ajv-formats": "^3.0.1",
|
|
54
|
+
"chai": "^6.3.0",
|
|
51
55
|
"copyfiles": "^2.4.1",
|
|
52
|
-
"eslint": "^
|
|
53
|
-
"eslint-config-prettier": "^
|
|
54
|
-
"
|
|
55
|
-
"hokey-runtime": "^1.
|
|
56
|
-
"
|
|
57
|
-
"mocha": "^10.2.0",
|
|
56
|
+
"eslint": "^9.18.0",
|
|
57
|
+
"eslint-config-prettier": "^10.0.1",
|
|
58
|
+
"globals": "^15.14.0",
|
|
59
|
+
"hokey-runtime": "^1.1.2",
|
|
60
|
+
"mocha": "^12.0.3",
|
|
58
61
|
"prettier": "^3.0.0",
|
|
62
|
+
"randexp": "^0.5.3",
|
|
59
63
|
"tslint-config-prettier": "^1.18.0",
|
|
64
|
+
"tsx": "^4.23.15",
|
|
60
65
|
"typescript": "^5.1.6",
|
|
61
66
|
"yup": "^1.2.0"
|
|
67
|
+
},
|
|
68
|
+
"scripts": {
|
|
69
|
+
"tsc": "tsc -p tsconfig.json && cd src && copyfiles \"./templates/**/*.hbs\" ../lib/esm/",
|
|
70
|
+
"build": "tsc -p tsconfig.json && cd src && copyfiles \"./templates/**/*.hbs\" ../lib/esm/",
|
|
71
|
+
"lint": "npx eslint src test",
|
|
72
|
+
"lint:fix": "npm run lint -- --fix",
|
|
73
|
+
"prettier": "npx prettier src test --check",
|
|
74
|
+
"prettier:fix": "npm run prettier -- --write",
|
|
75
|
+
"test": "if [[ -z \"$SKIP_TESTS\" ]] ; then mocha ./test/*.spec.ts; else echo 'Skipping tests due to SKIP_TESTS env variable'; fi",
|
|
76
|
+
"release": "pnpm tsc && pnpm prettier && pnpm lint && pnpm test"
|
|
62
77
|
}
|
|
63
|
-
}
|
|
78
|
+
}
|