@lilaquadrat/design-core 0.2.2 → 0.3.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 (78) hide show
  1. package/README.md +71 -3
  2. package/html/index.server.html +1 -8
  3. package/package.json +53 -53
  4. package/src/client-entry.ts +8 -8
  5. package/src/components/partials/error.partial.vue +19 -19
  6. package/src/components/partials/main-components.partial.vue +75 -70
  7. package/src/components/partials/qrcode.partial.vue +8 -8
  8. package/src/functions/AuthProviderFactory.ts +30 -0
  9. package/src/functions/PaymenyProviderFactory.ts +11 -11
  10. package/src/functions/auth0.provider.ts +75 -0
  11. package/src/functions/keycloak.provider.ts +228 -0
  12. package/src/functions/lila-dom.ts +50 -50
  13. package/src/functions/shopify.provider.ts +176 -154
  14. package/src/functions/stripe.provider.ts +120 -108
  15. package/src/globals.d.ts +1 -2
  16. package/src/index.ts +9 -7
  17. package/src/interfaces/AuthCallbackResult.interface.ts +5 -0
  18. package/src/interfaces/AuthConfig.interface.ts +13 -0
  19. package/src/interfaces/AuthProvider.interface.ts +15 -0
  20. package/src/interfaces/FrontendConfig.interface.ts +11 -40
  21. package/src/interfaces/GenericEvents.interface.ts +1 -1
  22. package/src/interfaces/IdTokenExtended.interface.ts +13 -4
  23. package/src/interfaces/PaymentProvider.interface.ts +2 -2
  24. package/src/interfaces/RenderOptions.interface.ts +12 -0
  25. package/src/libs/ActionNotice.ts +125 -125
  26. package/src/libs/Models.class.ts +219 -221
  27. package/src/main.ts +41 -36
  28. package/src/mixins/createCookieString.ts +50 -36
  29. package/src/mixins/createModelDeclaration.ts +22 -19
  30. package/src/mixins/createRouter.ts +12 -12
  31. package/src/mixins/date.ts +4 -2
  32. package/src/mixins/formatSize.ts +5 -5
  33. package/src/mixins/getAnchor.ts +1 -1
  34. package/src/mixins/getRoutes.ts +13 -25
  35. package/src/mixins/hasSlotContent.ts +22 -16
  36. package/src/mixins/hooks.ts +101 -60
  37. package/src/mixins/loadComponents.ts +60 -58
  38. package/src/mixins/logger.ts +17 -13
  39. package/src/mixins/replaceVariables.ts +10 -8
  40. package/src/mixins/scroll.ts +61 -45
  41. package/src/models/Address.model.ts +7 -7
  42. package/src/models/Contact.model.ts +14 -14
  43. package/src/plugins/analytics.ts +198 -0
  44. package/src/plugins/auth.ts +74 -60
  45. package/src/plugins/currency.ts +10 -10
  46. package/src/plugins/events.ts +101 -97
  47. package/src/plugins/filters.ts +21 -18
  48. package/src/plugins/replacer.ts +7 -6
  49. package/src/plugins/signupFlow.ts +45 -43
  50. package/src/plugins/traceable.ts +28 -26
  51. package/src/plugins/translations.ts +9 -9
  52. package/src/plugins/youtube.ts +39 -34
  53. package/src/routes.ts +108 -108
  54. package/src/server-entry.ts +75 -77
  55. package/src/stores/calls.store.ts +14 -14
  56. package/src/stores/cart.store.ts +116 -107
  57. package/src/stores/content.store.ts +87 -45
  58. package/src/stores/editor.store.ts +16 -16
  59. package/src/stores/files.store.ts +72 -72
  60. package/src/stores/main.store.ts +155 -109
  61. package/src/stores/user.store.ts +72 -68
  62. package/src/translations/de.ts +127 -127
  63. package/src/views/content.view.vue +81 -143
  64. package/src/views/download.view.vue +25 -23
  65. package/src/views/editor.view.vue +150 -125
  66. package/src/views/login.view.vue +35 -36
  67. package/src/views/signup-account.view.vue +14 -14
  68. package/tooling/cypress/config.ts +68 -54
  69. package/tooling/cypress/manifest-utils.mjs +34 -22
  70. package/tooling/cypress/run-parallel.mjs +41 -35
  71. package/tooling/cypress/support/commands.ts +458 -300
  72. package/tooling/eslint.config.js +1 -223
  73. package/tooling/preview.plugin.js +68 -68
  74. package/tooling/ssr-test/index.mjs +205 -203
  75. package/tooling/vite.d.ts +0 -6
  76. package/tooling/vite.js +170 -162
  77. package/src/interfaces/EditorConfiguration.interface.ts +0 -15
  78. package/tooling/stylelint.config.mjs +0 -24
@@ -35,7 +35,7 @@ interface ModelOptions {
35
35
  */
36
36
  extends?: string
37
37
  }
38
- // eslint-disable-next-line no-unused-vars
38
+
39
39
  type ModelHook<T> = (data: T) => void;
40
40
 
41
41
  interface ModelHooks<T> {
@@ -50,424 +50,422 @@ interface ModelHooks<T> {
50
50
 
51
51
  class Models {
52
52
 
53
- registeredModels: string[] = [];
53
+ registeredModels: string[] = [];
54
54
 
55
- declarations: Record<string, ModelDeclaration<T>> = {};
55
+ declarations: Record<string, ModelDeclaration<T>> = {};
56
56
 
57
- options: Record<string, ModelOptions> = {};
57
+ options: Record<string, ModelOptions> = {};
58
58
 
59
- hooks: Record<string, ModelHooks<T>> = {};
59
+ hooks: Record<string, ModelHooks<T>> = {};
60
60
 
61
- debug: boolean = false;
61
+ debug: boolean = false;
62
62
 
63
- constructor (debug: boolean = false) {
63
+ constructor(debug: boolean = false) {
64
64
 
65
- this.debug = debug;
65
+ this.debug = debug;
66
66
 
67
- }
68
-
69
- // eslint-disable-next-line no-unused-vars
70
- register<T>(name: string, declaration: ModelDeclaration<T>, hooks?: ModelHooks<T>, options?: ModelOptions): void;
71
-
72
- // eslint-disable-next-line no-unused-vars
73
- register<T, E>(name: string, declaration: ModelDeclarationExtended<T, E>, hooks: ModelHooks<T> | undefined, options: ModelOptions): void;
67
+ }
68
+
69
+ register<T>(name: string, declaration: ModelDeclaration<T>, hooks?: ModelHooks<T>, options?: ModelOptions): void;
70
+
71
+ register<T, E>(name: string, declaration: ModelDeclarationExtended<T, E>, hooks: ModelHooks<T> | undefined, options: ModelOptions): void;
74
72
 
75
- register<T, E> (name: string, declaration: ModelDeclaration<T > | ModelDeclarationExtended<T, E>, hooks: ModelHooks<T> | undefined, options?: ModelOptions) {
73
+ register<T, E>(name: string, declaration: ModelDeclaration<T > | ModelDeclarationExtended<T, E>, hooks: ModelHooks<T> | undefined, options?: ModelOptions) {
76
74
 
77
- if (this.debug) console.debug(`registed model ${name}`);
78
- // this.registeredModels[name] = declaration;
79
- this.registeredModels.push(name);
80
- this.declarations[name] = options?.extends ? this.extendDeclaration(declaration, options.extends) : declaration;
75
+ if (this.debug) console.debug(`registed model ${name}`);
76
+ // this.registeredModels[name] = declaration;
77
+ this.registeredModels.push(name);
78
+ this.declarations[name] = options?.extends ? this.extendDeclaration(declaration, options.extends) : declaration;
81
79
 
82
- if(options) this.options[name] = options;
83
- if(hooks) this.hooks[name] = hooks;
80
+ if(options) this.options[name] = options;
81
+ if(hooks) this.hooks[name] = hooks;
84
82
 
85
- }
83
+ }
86
84
 
87
- getDeclaration (name: string): ModelDeclaration<any> {
85
+ getDeclaration(name: string): ModelDeclaration<any> {
88
86
 
89
- if (!this.declarations[name]) console.error(`DECLARATION_NOT_FOUND - ${name}`);
87
+ if (!this.declarations[name]) console.error(`DECLARATION_NOT_FOUND - ${name}`);
90
88
 
91
- return this.declarations[name] as ModelDeclaration<any> ;
89
+ return this.declarations[name] as ModelDeclaration<any> ;
92
90
 
93
- }
91
+ }
94
92
 
95
- getOptions (name: string): ModelOptions {
93
+ getOptions(name: string): ModelOptions {
96
94
 
97
- return this.options[name];
95
+ return this.options[name];
98
96
 
99
- }
97
+ }
100
98
 
101
- extendDeclaration (declaration: ModelDeclaration, extendBase: string) {
99
+ extendDeclaration(declaration: ModelDeclaration, extendBase: string) {
102
100
 
103
- const base = this.getDeclaration(extendBase);
101
+ const base = this.getDeclaration(extendBase);
104
102
 
105
- if (!base) throw new Error('MODELS_EXTENDS_BASE_NOT_FOUND');
103
+ if (!base) throw new Error('MODELS_EXTENDS_BASE_NOT_FOUND');
106
104
 
107
- return { ...base, ...declaration };
105
+ return { ...base, ...declaration };
108
106
 
109
- }
107
+ }
110
108
 
111
- prepareTargetObject<T> (name: string, data: T & { uuid?: string }, usecase?: 'save' | 'add' | 'clone') {
109
+ prepareTargetObject<T>(name: string, data: T & { uuid?: string }, usecase?: 'save' | 'add' | 'clone') {
112
110
 
113
- const targetObject: GenericModel = {};
114
- const options = this.getOptions(name);
111
+ const targetObject: GenericModel = {};
112
+ const options = this.getOptions(name);
115
113
 
116
- if (options?.uuid) {
114
+ if (options?.uuid) {
117
115
 
118
- if (usecase === 'clone') {
116
+ if (usecase === 'clone') {
119
117
 
120
- targetObject.uuid = uuid();
118
+ targetObject.uuid = uuid();
121
119
 
122
- } else {
120
+ } else {
123
121
 
124
- targetObject.uuid = data.uuid || uuid();
122
+ targetObject.uuid = data.uuid || uuid();
125
123
 
126
- }
124
+ }
127
125
 
128
- }
126
+ }
129
127
 
130
- if (options?.nameAsType) {
128
+ if (options?.nameAsType) {
131
129
 
132
- targetObject.type = name;
130
+ targetObject.type = name;
133
131
 
134
- }
132
+ }
135
133
 
136
- return targetObject;
134
+ return targetObject;
137
135
 
138
- }
136
+ }
139
137
 
140
- add<T> (data: Partial<T>, name: string, declaration?: ModelDeclaration<T>): T {
138
+ add<T>(data: Partial<T>, name: string, declaration?: ModelDeclaration<T>): T {
141
139
 
142
- const modelData = this.setDataV2(data, this.prepareTargetObject(name, data, 'add'), declaration || this.getDeclaration(name), name, 'add');
140
+ const modelData = this.setDataV2(data, this.prepareTargetObject(name, data, 'add'), declaration || this.getDeclaration(name), name, 'add');
143
141
 
144
- // if (this.hooks[name]?.preAdd) this.hooks[name].preAdd(modelData);
142
+ // if (this.hooks[name]?.preAdd) this.hooks[name].preAdd(modelData);
145
143
 
146
- return modelData as T;
144
+ return modelData as T;
147
145
 
148
- }
146
+ }
149
147
 
150
- save<T> (data: Partial<T>, name: string, declaration?: ModelDeclaration<T>): T {
148
+ save<T>(data: Partial<T>, name: string, declaration?: ModelDeclaration<T>): T {
151
149
 
152
- const modelData = this.setDataV2(data, this.prepareTargetObject(name, data, 'save'), declaration || this.getDeclaration(name), name, 'save') as T;
150
+ const modelData = this.setDataV2(data, this.prepareTargetObject(name, data, 'save'), declaration || this.getDeclaration(name), name, 'save') as T;
153
151
 
154
- // if (this.hooks[name]?.postSave) this.hooks[name].postSave(modelData);
152
+ // if (this.hooks[name]?.postSave) this.hooks[name].postSave(modelData);
155
153
 
156
- return modelData as T;
154
+ return modelData as T;
157
155
 
158
- }
156
+ }
159
157
 
160
- clone<T> (data: Partial<T>, name: string, declaration?: ModelDeclaration<T>): T {
158
+ clone<T>(data: Partial<T>, name: string, declaration?: ModelDeclaration<T>): T {
161
159
 
162
- const modelData = this.setDataV2(data, this.prepareTargetObject(name, data, 'clone'), declaration || this.getDeclaration(name), name, 'clone') as T;
160
+ const modelData = this.setDataV2(data, this.prepareTargetObject(name, data, 'clone'), declaration || this.getDeclaration(name), name, 'clone') as T;
163
161
 
164
- // if (this.hooks[name].postClone) this.hooks[name].postClone(data);
162
+ // if (this.hooks[name].postClone) this.hooks[name].postClone(data);
165
163
 
166
- return modelData as T;
164
+ return modelData as T;
167
165
 
168
- }
166
+ }
169
167
 
170
- setDataV2<T> (data: Partial<T>, targetObject: GenericModel | GenericModel[], declaration: ModelDeclaration, name: string, usecase: 'save' | 'add' | 'clone') {
168
+ setDataV2<T>(data: Partial<T>, targetObject: GenericModel | GenericModel[], declaration: ModelDeclaration, name: string, usecase: 'save' | 'add' | 'clone') {
171
169
 
172
- if (this.debug) console.debug(data, declaration, targetObject, usecase);
170
+ if (this.debug) console.debug(data, declaration, targetObject, usecase);
173
171
 
174
- const keys = Object.keys(declaration || {});
172
+ const keys = Object.keys(declaration || {});
175
173
 
176
- // if (typeof this.legacy === 'function' && legacy) {
174
+ // if (typeof this.legacy === 'function' && legacy) {
177
175
 
178
- // if (data) data = this.legacy(data);
176
+ // if (data) data = this.legacy(data);
179
177
 
180
- // }
178
+ // }
181
179
 
182
- // if (typeof this.onSave === 'function' && usecase === 'save') {
180
+ // if (typeof this.onSave === 'function' && usecase === 'save') {
183
181
 
184
- // if (data) data = this.onSave(data);
182
+ // if (data) data = this.onSave(data);
185
183
 
186
- // }
184
+ // }
187
185
 
188
- if (usecase === 'save') {
186
+ if (usecase === 'save') {
189
187
 
190
- if (this.hooks[name]?.preSave) this.hooks[name].preSave(data);
188
+ if (this.hooks[name]?.preSave) this.hooks[name].preSave(data);
191
189
 
192
- }
190
+ }
193
191
 
194
- if (usecase === 'clone') {
192
+ if (usecase === 'clone') {
195
193
 
196
- if (this.hooks[name]?.preClone) this.hooks[name].preClone(data);
194
+ if (this.hooks[name]?.preClone) this.hooks[name].preClone(data);
197
195
 
198
- }
196
+ }
199
197
 
200
- if (usecase === 'add') {
198
+ if (usecase === 'add') {
201
199
 
202
- if (this.hooks[name]?.preAdd) this.hooks[name].preAdd(data);
200
+ if (this.hooks[name]?.preAdd) this.hooks[name].preAdd(data);
203
201
 
204
- }
202
+ }
205
203
 
206
- if (usecase === 'save' && Models.isEmpty(data)) return targetObject;
204
+ if (usecase === 'save' && Models.isEmpty(data)) return targetObject;
207
205
 
208
- // remove the changed flag on save
209
- // if (usecase === 'save') {
206
+ // remove the changed flag on save
207
+ // if (usecase === 'save') {
210
208
 
211
- // delete this.changed;
209
+ // delete this.changed;
212
210
 
213
- // }
211
+ // }
214
212
 
215
- // delete this.legacy;
216
- // delete this.onSave;
217
- // delete this.onAdd;
213
+ // delete this.legacy;
214
+ // delete this.onSave;
215
+ // delete this.onAdd;
218
216
 
219
- keys.forEach((keyName: string) => {
217
+ keys.forEach((keyName: string) => {
220
218
 
221
- if (this.debug) console.debug('START', keyName, data, declaration, declaration[keyName]);
219
+ if (this.debug) console.debug('START', keyName, data, declaration, declaration[keyName]);
222
220
 
223
- const currentDeclaration = declaration[keyName];
224
- let currentData: any;
225
- let safeData: Partial<T>;
221
+ const currentDeclaration = declaration[keyName];
222
+ let currentData: any;
223
+ let safeData: Partial<T>;
226
224
 
227
- if (data && !Models.isEmpty(data)) safeData = hardCopy<Partial<T>>(data);
228
- if (safeData && safeData[keyName]) currentData = hardCopy(safeData[keyName]);
225
+ if (data && !Models.isEmpty(data)) safeData = hardCopy<Partial<T>>(data);
226
+ if (safeData && safeData[keyName]) currentData = hardCopy(safeData[keyName]);
229
227
 
230
- if (usecase === 'save' && Models.isEmpty(currentData)) return;
228
+ if (usecase === 'save' && Models.isEmpty(currentData)) return;
231
229
 
232
- /**
230
+ /**
233
231
  * SPECIAL CASE type
234
232
  * dont override the type of the module
235
233
  */
236
- // if (name === 'type' && currentData) {
234
+ // if (name === 'type' && currentData) {
237
235
 
238
- // targetObject.type = currentData;
239
- // return;
236
+ // targetObject.type = currentData;
237
+ // return;
240
238
 
241
- // }
239
+ // }
242
240
 
243
- if ('type' in currentDeclaration) {
241
+ if ('type' in currentDeclaration) {
244
242
 
245
- if (currentData) {
243
+ if (currentData) {
246
244
 
247
- if (this.debug) console.debug('CHECK CURRENTDATA TYPE', typeof currentData === currentDeclaration.type, currentDeclaration.type, keyName, currentData, currentDeclaration);
245
+ if (this.debug) console.debug('CHECK CURRENTDATA TYPE', typeof currentData === currentDeclaration.type, currentDeclaration.type, keyName, currentData, currentDeclaration);
248
246
 
249
- if (typeof currentData !== currentDeclaration.type && currentDeclaration.type !== 'array' && !Models.isModel(currentDeclaration)) currentData = undefined;
247
+ if (typeof currentData !== currentDeclaration.type && currentDeclaration.type !== 'array' && !Models.isModel(currentDeclaration)) currentData = undefined;
250
248
 
251
- }
249
+ }
252
250
 
253
- /**
251
+ /**
254
252
  * if usecase is save an no data is given, dont add default values
255
253
  */
256
- if (usecase === 'save' && Models.isEmpty(currentData)) {
254
+ if (usecase === 'save' && Models.isEmpty(currentData)) {
257
255
 
258
- // delete declaration[name];
259
- return;
256
+ // delete declaration[name];
257
+ return;
260
258
 
261
- }
259
+ }
262
260
 
263
- // if (name === 'legacy') return targetObject;
264
- // if (name === 'onSave') return targetObject;
261
+ // if (name === 'legacy') return targetObject;
262
+ // if (name === 'onSave') return targetObject;
265
263
 
266
- /**
264
+ /**
267
265
  * string and number gets assigned
268
266
  */
269
- if (['string', 'number', 'boolean', 'object'].includes(currentDeclaration.type)) {
267
+ if (['string', 'number', 'boolean', 'object'].includes(currentDeclaration.type)) {
270
268
 
271
- targetObject[keyName] = currentData || Models.getDefaultValue(currentDeclaration);
269
+ targetObject[keyName] = currentData || Models.getDefaultValue(currentDeclaration);
272
270
 
273
- }
271
+ }
274
272
 
275
- /**
273
+ /**
276
274
  * array
277
275
  */
278
- if (currentDeclaration.type === 'array') {
276
+ if (currentDeclaration.type === 'array') {
279
277
 
280
- const arrayContains = currentDeclaration.contains;
278
+ const arrayContains = currentDeclaration.contains;
281
279
 
282
- if ('type' in arrayContains) {
280
+ if ('type' in arrayContains) {
283
281
 
284
- if (['string', 'number'].includes(arrayContains.type)) {
282
+ if (['string', 'number'].includes(arrayContains.type)) {
285
283
 
286
- if (this.debug) console.debug('SET ARRAY STRING/NUMBER', currentData);
284
+ if (this.debug) console.debug('SET ARRAY STRING/NUMBER', currentData);
287
285
 
288
- targetObject[keyName] = currentData?.slice(0) || Models.getDefaultValue(currentDeclaration);
286
+ targetObject[keyName] = currentData?.slice(0) || Models.getDefaultValue(currentDeclaration);
289
287
 
290
- }
288
+ }
291
289
 
292
- if (arrayContains.type === 'object') {
290
+ if (arrayContains.type === 'object') {
293
291
 
294
- targetObject[keyName] = [];
292
+ targetObject[keyName] = [];
295
293
 
296
- // only add non empty objects to the array
297
- currentData?.forEach((single) => {
294
+ // only add non empty objects to the array
295
+ currentData?.forEach((single) => {
298
296
 
299
- // skip if single is empty
300
- if (usecase === 'save' && Models.isEmpty(single)) return;
297
+ // skip if single is empty
298
+ if (usecase === 'save' && Models.isEmpty(single)) return;
301
299
 
302
- // only add if the result is not empty
303
- if (!Models.isEmpty(single)) targetObject[keyName].push(single);
300
+ // only add if the result is not empty
301
+ if (!Models.isEmpty(single)) targetObject[keyName].push(single);
304
302
 
305
- });
303
+ });
306
304
 
307
- if (!targetObject[keyName].length) delete targetObject[keyName];
305
+ if (!targetObject[keyName].length) delete targetObject[keyName];
308
306
 
309
- }
307
+ }
310
308
 
311
- }
309
+ }
312
310
 
313
- if ('model' in arrayContains) {
311
+ if ('model' in arrayContains) {
314
312
 
315
- if (this.debug) console.debug('SET ARRAY MODEL', keyName, currentData, arrayContains?.model);
313
+ if (this.debug) console.debug('SET ARRAY MODEL', keyName, currentData, arrayContains?.model);
316
314
 
317
- targetObject[keyName] = [];
315
+ targetObject[keyName] = [];
318
316
 
319
- if (this.debug) console.debug(keyName, currentData);
317
+ if (this.debug) console.debug(keyName, currentData);
320
318
 
321
- /**
319
+ /**
322
320
  * currentdata could be an array with an empty object [{}] which will not count as empty for the Model.isEmpty function
323
321
  * therefore we need to handle the possible empty data here
324
322
  */
325
323
 
326
- if (currentData) {
324
+ if (currentData) {
327
325
 
328
- currentData?.forEach((single) => {
326
+ currentData?.forEach((single) => {
329
327
 
330
- // skip if single is empty
331
- if (usecase === 'save' && Models.isEmpty(single)) return;
328
+ // skip if single is empty
329
+ if (usecase === 'save' && Models.isEmpty(single)) return;
332
330
 
333
- const pushData = this.setDataV2(single, {}, this.getDeclaration(arrayContains?.model), arrayContains?.model, usecase);
331
+ const pushData = this.setDataV2(single, {}, this.getDeclaration(arrayContains?.model), arrayContains?.model, usecase);
334
332
 
335
- // only add if the result is not empty
336
- if (!Models.isEmpty(pushData)) targetObject[keyName].push(pushData);
333
+ // only add if the result is not empty
334
+ if (!Models.isEmpty(pushData)) targetObject[keyName].push(pushData);
337
335
 
338
- });
336
+ });
339
337
 
340
- if (!targetObject[keyName].length) delete targetObject[keyName];
338
+ if (!targetObject[keyName].length) delete targetObject[keyName];
341
339
 
342
- } else if (usecase !== 'save') {
340
+ } else if (usecase !== 'save') {
343
341
 
344
- targetObject[keyName].push(this.setDataV2({}, {}, this.getDeclaration(arrayContains?.model), arrayContains?.model, usecase));
342
+ targetObject[keyName].push(this.setDataV2({}, {}, this.getDeclaration(arrayContains?.model), arrayContains?.model, usecase));
345
343
 
346
- }
344
+ }
347
345
 
348
- if ('defaultItems' in currentDeclaration && usecase !== 'save') {
346
+ if ('defaultItems' in currentDeclaration && usecase !== 'save') {
349
347
 
350
- if (targetObject[keyName].length < currentDeclaration.defaultItems) {
348
+ if (targetObject[keyName].length < currentDeclaration.defaultItems) {
351
349
 
352
- const neededItems = currentDeclaration.defaultItems - targetObject[keyName].length;
350
+ const neededItems = currentDeclaration.defaultItems - targetObject[keyName].length;
353
351
 
354
- for (let index = 0; index < neededItems; index += 1) {
352
+ for (let index = 0; index < neededItems; index += 1) {
355
353
 
356
- targetObject[keyName].push(this.setDataV2({}, {}, this.getDeclaration(arrayContains?.model), arrayContains?.model, usecase));
354
+ targetObject[keyName].push(this.setDataV2({}, {}, this.getDeclaration(arrayContains?.model), arrayContains?.model, usecase));
357
355
 
358
- }
356
+ }
359
357
 
360
- }
358
+ }
361
359
 
362
- }
360
+ }
363
361
 
364
- }
362
+ }
365
363
 
366
- }
364
+ }
367
365
 
368
- }
366
+ }
369
367
 
370
- /**
368
+ /**
371
369
  * if its an object, it will be a child model
372
370
  */
373
- if ('model' in currentDeclaration) {
371
+ if ('model' in currentDeclaration) {
374
372
 
375
- if (this.debug) console.debug('its a model', keyName, currentDeclaration, currentDeclaration?.model, targetObject);
373
+ if (this.debug) console.debug('its a model', keyName, currentDeclaration, currentDeclaration?.model, targetObject);
376
374
 
377
- // if (usecase === 'save' && (!currentData || (Array.isArray(currentData) && !currentData.length))) {
375
+ // if (usecase === 'save' && (!currentData || (Array.isArray(currentData) && !currentData.length))) {
378
376
 
379
- // // delete declaration[name];
380
- // return;
377
+ // // delete declaration[name];
378
+ // return;
381
379
 
382
- //
380
+ //
383
381
 
384
- targetObject[keyName]= this.setDataV2(currentData, {}, this.getDeclaration(currentDeclaration?.model), currentDeclaration?.model, usecase);
382
+ targetObject[keyName]= this.setDataV2(currentData, {}, this.getDeclaration(currentDeclaration?.model), currentDeclaration?.model, usecase);
385
383
 
386
- if (usecase === 'save') {
384
+ if (usecase === 'save') {
387
385
 
388
- if (this.debug) console.debug(124, this[name], Object.keys(this[name]).length);
386
+ if (this.debug) console.debug(124, this[name], Object.keys(this[name]).length);
389
387
 
390
- if (Models.isEmpty(targetObject[keyName])) {
388
+ if (Models.isEmpty(targetObject[keyName])) {
391
389
 
392
- delete targetObject[keyName];
390
+ delete targetObject[keyName];
393
391
 
394
- }
392
+ }
395
393
 
396
- }
394
+ }
397
395
 
398
- }
396
+ }
399
397
 
400
- });
398
+ });
401
399
 
402
- return targetObject;
400
+ return targetObject;
403
401
 
404
- }
402
+ }
405
403
 
406
- static isEmpty (data: any[] | Record<string, any>) {
404
+ static isEmpty(data: any[] | Record<string, any>) {
407
405
 
408
- if (!data) return true;
406
+ if (!data) return true;
409
407
 
410
- if (Array.isArray(data)) {
408
+ if (Array.isArray(data)) {
411
409
 
412
- return !data.length;
410
+ return !data.length;
413
411
 
414
- }
412
+ }
415
413
 
416
- if (typeof data === 'object') {
414
+ if (typeof data === 'object') {
417
415
 
418
- return !Object.keys(data).length;
416
+ return !Object.keys(data).length;
419
417
 
420
- }
418
+ }
421
419
 
422
- return false;
420
+ return false;
423
421
 
424
- }
422
+ }
425
423
 
426
- static isModel (declaration: SingleDeclaration) {
424
+ static isModel(declaration: SingleDeclaration) {
427
425
 
428
- return 'model' in declaration;
426
+ return 'model' in declaration;
429
427
 
430
- }
428
+ }
431
429
 
432
- static getDefaultValue (declaration: SingleDeclaration) {
430
+ static getDefaultValue(declaration: SingleDeclaration) {
433
431
 
434
- if (declaration.default) {
432
+ if (declaration.default) {
435
433
 
436
- return declaration.default;
434
+ return declaration.default;
437
435
 
438
- }
436
+ }
439
437
 
440
- if ('type' in declaration) {
438
+ if ('type' in declaration) {
441
439
 
442
- if (declaration.type === 'string') {
440
+ if (declaration.type === 'string') {
443
441
 
444
- return '';
442
+ return '';
445
443
 
446
- }
444
+ }
447
445
 
448
- if (declaration.type === 'number') {
446
+ if (declaration.type === 'number') {
449
447
 
450
- return 0;
448
+ return 0;
451
449
 
452
- }
450
+ }
453
451
 
454
- if (declaration.type === 'boolean') {
452
+ if (declaration.type === 'boolean') {
455
453
 
456
- return false;
454
+ return false;
457
455
 
458
- }
456
+ }
459
457
 
460
- if (declaration.type === 'array') {
458
+ if (declaration.type === 'array') {
461
459
 
462
- return [];
460
+ return [];
463
461
 
464
- }
462
+ }
465
463
 
466
- }
464
+ }
467
465
 
468
- return null;
466
+ return null;
469
467
 
470
- }
468
+ }
471
469
 
472
470
  }
473
471
 
@@ -475,8 +473,8 @@ const ModelsClass = new Models();
475
473
 
476
474
  export default ModelsClass;
477
475
  export {
478
- Models
476
+ Models
479
477
  };
480
478
  export type {
481
- ModelDeclaration, ModelDeclarationExtended, ModelOptions, ModelHooks, SingleDeclaration
479
+ ModelDeclaration, ModelDeclarationExtended, ModelOptions, ModelHooks, SingleDeclaration
482
480
  };