mobiletto-orm-typedef-gen 2.3.41 → 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.
Files changed (108) hide show
  1. package/README.md +16 -0
  2. package/lib/esm/generate.d.ts +12 -2
  3. package/lib/esm/generate.js +213 -30
  4. package/lib/esm/generate.js.map +1 -0
  5. package/lib/esm/generators/h3.d.ts +7 -0
  6. package/lib/esm/generators/h3.js +84 -0
  7. package/lib/esm/generators/h3.js.map +1 -0
  8. package/lib/esm/generators/jsonSchema.d.ts +3 -0
  9. package/lib/esm/generators/jsonSchema.js +48 -0
  10. package/lib/esm/generators/jsonSchema.js.map +1 -0
  11. package/lib/esm/generators/server.d.ts +14 -9
  12. package/lib/esm/generators/server.js +79 -53
  13. package/lib/esm/generators/server.js.map +1 -0
  14. package/lib/esm/generators/tsType.d.ts +2 -2
  15. package/lib/esm/generators/tsType.js +2 -1
  16. package/lib/esm/generators/tsType.js.map +1 -0
  17. package/lib/esm/generators/vue/admin.d.ts +5 -0
  18. package/lib/esm/generators/vue/admin.js +83 -0
  19. package/lib/esm/generators/vue/admin.js.map +1 -0
  20. package/lib/esm/generators/vue/service.d.ts +4 -0
  21. package/lib/esm/generators/vue/service.js +47 -0
  22. package/lib/esm/generators/vue/service.js.map +1 -0
  23. package/lib/esm/generators/vue/store.d.ts +5 -0
  24. package/lib/esm/generators/vue/store.js +43 -0
  25. package/lib/esm/generators/vue/store.js.map +1 -0
  26. package/lib/esm/helpers.d.ts +4 -0
  27. package/lib/esm/helpers.js +160 -0
  28. package/lib/esm/helpers.js.map +1 -0
  29. package/lib/esm/index.d.ts +6 -2
  30. package/lib/esm/index.js +7 -2
  31. package/lib/esm/index.js.map +1 -0
  32. package/lib/esm/templates/admin/adminComponent.vue.hbs +662 -0
  33. package/lib/esm/templates/admin/adminHelper.ts.hbs +52 -0
  34. package/lib/esm/templates/admin/adminPage.vue.hbs +53 -0
  35. package/lib/esm/templates/api/h3.ts.hbs +13 -0
  36. package/lib/esm/templates/api/id.delete.ts.hbs +94 -32
  37. package/lib/esm/templates/api/id.get.ts.hbs +79 -18
  38. package/lib/esm/templates/api/id.patch.ts.hbs +76 -24
  39. package/lib/esm/templates/api/id.put.ts.hbs +65 -18
  40. package/lib/esm/templates/api/index.post.ts.hbs +111 -22
  41. package/lib/esm/templates/api/index.put.ts.hbs +75 -0
  42. package/lib/esm/templates/api/refs.ts.hbs +26 -0
  43. package/lib/esm/templates/filter/errorFilter.ts.hbs +10 -0
  44. package/lib/esm/templates/filter/sessionFilter.ts.hbs +125 -25
  45. package/lib/esm/templates/schema/jsonSchema.json.hbs +62 -0
  46. package/lib/esm/templates/service/service.ts.hbs +59 -29
  47. package/lib/esm/templates/service/serviceHelper.ts.hbs +38 -27
  48. package/lib/esm/templates/service/singletonService.ts.hbs +46 -24
  49. package/lib/esm/templates/store/singletonStore.ts.hbs +57 -28
  50. package/lib/esm/templates/store/store.ts.hbs +169 -39
  51. package/lib/esm/templates/store/storeHelper.ts.hbs +21 -9
  52. package/lib/esm/templates/type/tsType.ts.hbs +7 -3
  53. package/package.json +37 -22
  54. package/src/generate.ts +400 -0
  55. package/src/generators/h3.ts +125 -0
  56. package/src/generators/jsonSchema.ts +65 -0
  57. package/src/generators/server.ts +242 -0
  58. package/src/generators/tsType.ts +6 -0
  59. package/src/generators/vue/admin.ts +136 -0
  60. package/src/generators/vue/service.ts +76 -0
  61. package/src/generators/vue/store.ts +74 -0
  62. package/src/helpers.ts +195 -0
  63. package/src/index.ts +10 -0
  64. package/lib/cjs/generate.d.ts +0 -19
  65. package/lib/cjs/generate.js +0 -154
  66. package/lib/cjs/generators/client.d.ts +0 -8
  67. package/lib/cjs/generators/client.js +0 -75
  68. package/lib/cjs/generators/server.d.ts +0 -11
  69. package/lib/cjs/generators/server.js +0 -91
  70. package/lib/cjs/generators/tsType.d.ts +0 -3
  71. package/lib/cjs/generators/tsType.js +0 -4
  72. package/lib/cjs/generators/yup.d.ts +0 -3
  73. package/lib/cjs/generators/yup.js +0 -8
  74. package/lib/cjs/index.d.ts +0 -6
  75. package/lib/cjs/index.js +0 -6
  76. package/lib/cjs/package.json +0 -16
  77. package/lib/cjs/templates/api/id.delete.ts.hbs +0 -66
  78. package/lib/cjs/templates/api/id.get.ts.hbs +0 -38
  79. package/lib/cjs/templates/api/id.patch.ts.hbs +0 -51
  80. package/lib/cjs/templates/api/id.put.ts.hbs +0 -42
  81. package/lib/cjs/templates/api/index.post.ts.hbs +0 -39
  82. package/lib/cjs/templates/component/admin.vue.hbs +0 -493
  83. package/lib/cjs/templates/component/adminHelper.ts.hbs +0 -65
  84. package/lib/cjs/templates/component/componentHelper.d.ts +0 -3
  85. package/lib/cjs/templates/component/componentHelper.js +0 -53
  86. package/lib/cjs/templates/filter/errorFilter.ts.hbs +0 -51
  87. package/lib/cjs/templates/filter/sessionFilter.ts.hbs +0 -56
  88. package/lib/cjs/templates/service/service.ts.hbs +0 -58
  89. package/lib/cjs/templates/service/serviceHelper.ts.hbs +0 -97
  90. package/lib/cjs/templates/service/singletonService.ts.hbs +0 -49
  91. package/lib/cjs/templates/store/singletonStore.ts.hbs +0 -74
  92. package/lib/cjs/templates/store/store.ts.hbs +0 -94
  93. package/lib/cjs/templates/store/storeHelper.d.ts +0 -15
  94. package/lib/cjs/templates/store/storeHelper.js +0 -15
  95. package/lib/cjs/templates/store/storeHelper.ts.hbs +0 -34
  96. package/lib/cjs/templates/type/tsType.ts.hbs +0 -7
  97. package/lib/cjs/templates/validation/yup.ts.hbs +0 -39
  98. package/lib/esm/generators/client.d.ts +0 -8
  99. package/lib/esm/generators/client.js +0 -75
  100. package/lib/esm/generators/yup.d.ts +0 -3
  101. package/lib/esm/generators/yup.js +0 -8
  102. package/lib/esm/templates/component/admin.vue.hbs +0 -493
  103. package/lib/esm/templates/component/adminHelper.ts.hbs +0 -65
  104. package/lib/esm/templates/component/componentHelper.d.ts +0 -3
  105. package/lib/esm/templates/component/componentHelper.js +0 -53
  106. package/lib/esm/templates/store/storeHelper.d.ts +0 -15
  107. package/lib/esm/templates/store/storeHelper.js +0 -15
  108. 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 { {{name}}Service } from "{{servicesImportPath}}/{{name}}Service";
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
- const updateList = (list: {{Name}}Type[] | null, id: string, opts?: { object?: {{Name}}Type; remove?: boolean }) => {
12
- return updateOrmList<{{Name}}Type>({{Name}}TypeDef, list, id, opts);
12
+ type {{Name}}SearchQuery = {{{curlyOpen}}}{{#if parentPaths}}{{#each parentPaths}}
13
+ {{refField}}: string,{{/each}}{{/if}}
14
+ query?: MobilettoOrmFindApiOpts
13
15
  };
14
16
 
15
- export const use{{Name}}Store = defineStore("{{name}}", {
16
- state: () => ({
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}}List: null as {{Name}}Type[] | null,
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
- {{name}}Busy: (state) => state.finding || state.creating || state.updating || state.deleting || state.searching,
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(id: string, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
33
- this.found = null;
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 {{name}}Service.find{{Name}}(id, serverErrors);
37
- if (this.found) {
38
- updateList(this.{{name}}List, {{Name}}TypeDef.id(this.found), {object: this.found});
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 search(query?: MobilettoOrmFindApiOpts): Promise<{{Name}}Type[]> {
102
+ },{{/unless}}{{#unless apiConfig.search.disabled}}
103
+ async searchByQuery(searchQuery: {{Name}}SearchQuery): Promise<{{Name}}SearchResult> {
46
104
  try {
47
105
  this.searching = true;
48
- this.{{name}}List = await {{name}}Service.search{{Name}}(query);
49
- return this.{{name}}List || [];
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 create(object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
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 {{name}}Service.create{{Name}}(object, serverErrors);
59
- return this.created;
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 update(object: {{Name}}Type, serverErrors: Ref<MobilettoOrmValidationErrors>): Promise<{{Name}}Type> {
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 {{name}}Service.update{{Name}}(object, serverErrors);
193
+ this.updated = await {{fullStoreName}}Service.update{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}object, serverErrors);
69
194
  if (this.updated) {
70
- updateList(this.{{name}}List, {{Name}}TypeDef.id(this.updated), {object: this.updated});
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(id: string, serverErrors: Ref<MobilettoOrmValidationErrors>, purge?: boolean): Promise<boolean> {
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 {{name}}Service.delete{{Name}}(id, serverErrors, !!purge);
211
+ const deleteResult = await {{fullStoreName}}Service.delete{{Name}}({{#if parentPaths}}{{#each parentPaths}}{{refField}}, {{/each}}{{/if}}id, serverErrors, !!purge);
82
212
  if (deleteResult) {
83
- updateList(this.{{name}}List, id, { remove: true });
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 { MobilettoOrmObject, MobilettoOrmTypeDef } from "mobiletto-orm-typedef";
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}}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}};
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.41",
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
- "scripts": {
29
- "test": "mocha ./test/*.spec.js",
30
- "tsc": "tsc --module es2020 -p tsconfig.json && tsc --module es2020 -p tsconfig-cjs.json && cd src && copyfiles \"./templates/**/*.hbs\" ../lib/cjs/ && copyfiles \"./templates/**/*.hbs\" ../lib/esm/",
31
- "lint": "npx eslint src test",
32
- "lint:fix": "npm run lint -- --fix",
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/cjs/index.js",
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
- "@types/chai": "^4.3.5",
46
- "@types/mocha": "^10.0.1",
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": "^6.0.0",
49
- "@typescript-eslint/parser": "^6.0.0",
50
- "chai": "^4.3.7",
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": "^8.44.0",
53
- "eslint-config-prettier": "^8.8.0",
54
- "handlebars": "^4.7.7",
55
- "hokey-runtime": "^1.0.4",
56
- "mobiletto-orm-typedef": "^2.4.4",
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
+ }