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