@medyll/idae-data-tpl 0.66.0 → 0.67.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.
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { TplCollectionName,
|
|
1
|
+
import type { TplCollectionName, IdaeCollectionTemplate, IDbForgeFields, IDbFieldRules, IDbForgeArgs, IDbFieldType, IdaeModelRoot, IdaeTemplateFields, ForgeFieldTypes, CoreModel } from './types.js';
|
|
2
2
|
export declare const exampleModel: IdaeModelRoot;
|
|
3
3
|
export declare class IdaeModelCore<T = Record<string, any>> {
|
|
4
4
|
#private;
|
|
5
5
|
model: IdaeModelRoot<T>;
|
|
6
6
|
constructor();
|
|
7
7
|
setModel<C = Record<string, any>>(model: IdaeModelRoot<C>): void;
|
|
8
|
-
addCollectionTemplate(collection: string, template:
|
|
8
|
+
addCollectionTemplate(collection: string, template: IdaeCollectionTemplate): void;
|
|
9
9
|
parseAllCollections(): Record<string, Record<string, any> | undefined>;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
parseCollection(collection: TplCollectionName): Record<string, IDbForgeFields | undefined> | undefined;
|
|
11
|
+
parseCollectionFields(collection: TplCollectionName, fieldName: keyof IdaeTemplateFields<any>): IDbForgeFields<T> | undefined;
|
|
12
12
|
parsFieldRule(fieldRule: IDbFieldRules): Partial<IDbForgeFields<T>> | undefined;
|
|
13
13
|
private forge;
|
|
14
14
|
getCollection(collection: TplCollectionName): CoreModel;
|
|
15
|
-
getCollectionTemplate(collection: TplCollectionName):
|
|
16
|
-
getCollectionTemplateFks(collection: TplCollectionName):
|
|
15
|
+
getCollectionTemplate(collection: TplCollectionName): IdaeCollectionTemplate;
|
|
16
|
+
getCollectionTemplateFks(collection: TplCollectionName): IdaeCollectionTemplate["fks"];
|
|
17
17
|
getIndexName(collection: string): any;
|
|
18
18
|
getCollectionTemplateFields(collection: TplCollectionName): IdaeTemplateFields;
|
|
19
19
|
getTemplatePresentation(collection: TplCollectionName): string;
|
|
@@ -24,7 +24,7 @@ export declare class IdaeModelCore<T = Record<string, any>> {
|
|
|
24
24
|
indexValue(collection: TplCollectionName, data: Record<string, any>): any;
|
|
25
25
|
extract(type: ForgeFieldTypes, fieldRule: IDbFieldRules): Partial<IDbForgeFields<T>>;
|
|
26
26
|
fks(collection: string): {
|
|
27
|
-
[collection: string]:
|
|
27
|
+
[collection: string]: IdaeCollectionTemplate;
|
|
28
28
|
};
|
|
29
29
|
reverseFks(targetCollection: TplCollectionName): Record<string, any>;
|
|
30
30
|
iterateArrayField(collection: TplCollectionName, fieldName: string, data: T[]): IDbForgeFields<T>[];
|
|
@@ -37,11 +37,11 @@ export class IdaeModelCore {
|
|
|
37
37
|
parseAllCollections() {
|
|
38
38
|
let out = {};
|
|
39
39
|
Object.keys(this.model).forEach((collection) => {
|
|
40
|
-
out[collection] = this.
|
|
40
|
+
out[collection] = this.parseCollection(collection);
|
|
41
41
|
});
|
|
42
42
|
return out;
|
|
43
43
|
}
|
|
44
|
-
|
|
44
|
+
parseCollection(collection) {
|
|
45
45
|
const fields = this.getCollectionTemplateFields(collection);
|
|
46
46
|
if (!fields)
|
|
47
47
|
return;
|
|
@@ -49,12 +49,12 @@ export class IdaeModelCore {
|
|
|
49
49
|
Object.keys(fields).forEach((fieldName) => {
|
|
50
50
|
let fieldType = fields[fieldName];
|
|
51
51
|
if (fieldType) {
|
|
52
|
-
out[fieldName] = this.
|
|
52
|
+
out[fieldName] = this.parseCollectionFields(collection, fieldName);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
55
|
return out;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
parseCollectionFields(collection, fieldName) {
|
|
58
58
|
const field = this.#getTemplateFieldRule(collection, fieldName);
|
|
59
59
|
if (!field) {
|
|
60
60
|
IDbError.throwError(`Field ${fieldName} not found in collection ${collection}`, 'FIELD_NOT_FOUND');
|
|
@@ -184,7 +184,7 @@ export class IdaeModelCore {
|
|
|
184
184
|
// loop over fks
|
|
185
185
|
if (fks) {
|
|
186
186
|
Object.keys(fks).forEach((collection) => {
|
|
187
|
-
out[collection] = this.
|
|
187
|
+
out[collection] = this.parseCollection(collection);
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
190
|
return out;
|
|
@@ -208,18 +208,18 @@ export class IdaeModelCore {
|
|
|
208
208
|
}
|
|
209
209
|
// iterate base
|
|
210
210
|
iterateArrayField(collection, fieldName, data) {
|
|
211
|
-
const fieldInfo = this.
|
|
211
|
+
const fieldInfo = this.parseCollectionFields(collection, fieldName);
|
|
212
212
|
if (fieldInfo?.is !== 'array' || !Array.isArray(data)) {
|
|
213
213
|
return [];
|
|
214
214
|
}
|
|
215
|
-
return data.map(() => this.
|
|
215
|
+
return data.map(() => this.parseCollectionFields(collection, fieldName)) ?? [];
|
|
216
216
|
}
|
|
217
217
|
iterateObjectField(collection, fieldName, data) {
|
|
218
|
-
const fieldInfo = this.
|
|
218
|
+
const fieldInfo = this.parseCollectionFields(collection, fieldName);
|
|
219
219
|
if (fieldInfo?.is !== 'object' || typeof data !== 'object') {
|
|
220
220
|
return [];
|
|
221
221
|
}
|
|
222
|
-
return Object.keys(data).map((key) => this.
|
|
222
|
+
return Object.keys(data).map((key) => this.parseCollectionFields(collection, key));
|
|
223
223
|
}
|
|
224
224
|
}
|
|
225
225
|
export const IdaeModel = new IdaeModelCore();
|
|
@@ -273,7 +273,7 @@ export class IDbCollectionValues {
|
|
|
273
273
|
try {
|
|
274
274
|
this.#checkError(!this.#checkAccess(), 'Access denied', 'ACCESS_DENIED');
|
|
275
275
|
this.#checkError(!(fieldName in data), `Field ${String(fieldName)} not found in data`, 'FIELD_NOT_FOUND');
|
|
276
|
-
const fieldInfo = this.dbCollections.
|
|
276
|
+
const fieldInfo = this.dbCollections.parseCollectionFields(this.collection, fieldName);
|
|
277
277
|
this.#checkError(!fieldInfo, `Field ${String(fieldName)} not found in collection`, 'FIELD_NOT_FOUND');
|
|
278
278
|
switch (fieldInfo?.fieldType) {
|
|
279
279
|
case 'number':
|
|
@@ -295,7 +295,7 @@ export class IDbCollectionValues {
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
getInputDataSet(fieldName, data) {
|
|
298
|
-
const fieldInfo = this.dbCollections.
|
|
298
|
+
const fieldInfo = this.dbCollections.parseCollectionFields(this.collection, fieldName);
|
|
299
299
|
const fieldType = fieldInfo?.fieldType ?? '';
|
|
300
300
|
const fieldArgs = fieldInfo?.fieldArgs?.join(' ') ?? '';
|
|
301
301
|
const indexName = this.dbCollections.getIndexName(this.collection);
|
|
@@ -348,7 +348,7 @@ export class IDbCollectionFieldValues {
|
|
|
348
348
|
this.#data = data;
|
|
349
349
|
}
|
|
350
350
|
format(fieldName) {
|
|
351
|
-
const fieldInfo = this.#collectionValues.dbCollections.
|
|
351
|
+
const fieldInfo = this.#collectionValues.dbCollections.parseCollectionFields(this.#collection, fieldName);
|
|
352
352
|
if (fieldInfo?.is === 'array') {
|
|
353
353
|
return this.iterateArray(String(fieldName), this.#data);
|
|
354
354
|
}
|
|
@@ -362,7 +362,7 @@ export class IDbCollectionFieldValues {
|
|
|
362
362
|
}
|
|
363
363
|
// renamed from parseCollectionFieldName
|
|
364
364
|
getForge(fieldName) {
|
|
365
|
-
return this.#collectionValues.dbCollections.
|
|
365
|
+
return this.#collectionValues.dbCollections.parseCollectionFields(this.#collection, String(fieldName));
|
|
366
366
|
}
|
|
367
367
|
iterateArray(fieldName, data) {
|
|
368
368
|
return this.#collectionValues.iterateArrayField(fieldName, data);
|
|
@@ -390,7 +390,7 @@ export class IDbCollectionFieldForge {
|
|
|
390
390
|
}
|
|
391
391
|
// renamed from parseCollectionFieldName
|
|
392
392
|
get forge() {
|
|
393
|
-
return this.#collectionValues.dbCollections.
|
|
393
|
+
return this.#collectionValues.dbCollections.parseCollectionFields(this.#collection, String(this.#fieldName));
|
|
394
394
|
}
|
|
395
395
|
get fieldArgs() {
|
|
396
396
|
return this.forge?.fieldArgs;
|
|
@@ -16,16 +16,9 @@ export type IDbTypes = TemplateFieldPrimitive | IDbObjectPrimitive | IDbFk | IDb
|
|
|
16
16
|
export type IDBArgumentsTypes = `${IDbTypes}(${CombinedArgs})`;
|
|
17
17
|
export type IDbFieldRules = IDBArgumentsTypes | IDbTypes;
|
|
18
18
|
export type IDbFieldType = IDBArgumentsTypes | IDbTypes;
|
|
19
|
-
export type
|
|
20
|
-
template: IdaeTemplate<T[keyof T]>;
|
|
21
|
-
};
|
|
22
|
-
export type IdaeModelRoot<T = Record<string, any>> = Record<string, any> & {
|
|
23
|
-
[K in keyof T]: {
|
|
24
|
-
template?: IdaeTemplate<T[K]>;
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export type IdaeTemplate<C = Record<string, any>, M = IdaeModelRoot> = {
|
|
19
|
+
export type IdaeCollectionTemplate<C = Record<string, any>, M = IdaeModelRoot> = {
|
|
28
20
|
index: string;
|
|
21
|
+
ts: any;
|
|
29
22
|
presentation: CombineElements<keyof C>;
|
|
30
23
|
fields: IdaeTemplateFields<C>;
|
|
31
24
|
fks: {
|
|
@@ -36,6 +29,14 @@ export type IdaeTemplate<C = Record<string, any>, M = IdaeModelRoot> = {
|
|
|
36
29
|
};
|
|
37
30
|
};
|
|
38
31
|
};
|
|
32
|
+
export type CoreModel<T> = {
|
|
33
|
+
template: IdaeCollectionTemplate<T[keyof T]>;
|
|
34
|
+
};
|
|
35
|
+
export type IdaeModelRoot<T = Record<string, any>> = Record<string, any> & {
|
|
36
|
+
[K in keyof T]: {
|
|
37
|
+
template?: IdaeCollectionTemplate<T[K]>;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
39
40
|
export type IdaeTemplateFields<T> = {
|
|
40
41
|
[K in keyof T]: TplFieldRules;
|
|
41
42
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medyll/idae-data-tpl",
|
|
3
3
|
"scope": "@medyll",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.67.0",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite dev",
|
|
7
7
|
"build": "vite build && npm run package",
|
|
@@ -30,27 +30,27 @@
|
|
|
30
30
|
"svelte": "^5.0.0-next"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@sveltejs/adapter-auto": "^
|
|
34
|
-
"@sveltejs/kit": "^2.
|
|
35
|
-
"@sveltejs/package": "^2.3.
|
|
36
|
-
"@sveltejs/vite-plugin-svelte": "^
|
|
37
|
-
"@types/eslint": "^9.6.
|
|
38
|
-
"eslint": "^9.
|
|
39
|
-
"eslint-config-prettier": "^
|
|
40
|
-
"eslint-plugin-svelte": "^
|
|
41
|
-
"glob": "^11.0.
|
|
42
|
-
"globals": "^
|
|
43
|
-
"prettier": "^3.
|
|
44
|
-
"prettier-plugin-svelte": "^3.
|
|
45
|
-
"svelte": "^5.
|
|
46
|
-
"svelte-check": "^
|
|
47
|
-
"tslib": "^2.
|
|
33
|
+
"@sveltejs/adapter-auto": "^4.0.0",
|
|
34
|
+
"@sveltejs/kit": "^2.18.0",
|
|
35
|
+
"@sveltejs/package": "^2.3.10",
|
|
36
|
+
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
37
|
+
"@types/eslint": "^9.6.1",
|
|
38
|
+
"eslint": "^9.21.0",
|
|
39
|
+
"eslint-config-prettier": "^10.0.2",
|
|
40
|
+
"eslint-plugin-svelte": "^3.0.3",
|
|
41
|
+
"glob": "^11.0.1",
|
|
42
|
+
"globals": "^16.0.0",
|
|
43
|
+
"prettier": "^3.5.3",
|
|
44
|
+
"prettier-plugin-svelte": "^3.3.3",
|
|
45
|
+
"svelte": "^5.22.4",
|
|
46
|
+
"svelte-check": "^4.1.4",
|
|
47
|
+
"tslib": "^2.8.1",
|
|
48
48
|
"typescript": "^5.8.2",
|
|
49
|
-
"typescript-eslint": "^8.
|
|
50
|
-
"vite": "^
|
|
51
|
-
"vitest": "^
|
|
49
|
+
"typescript-eslint": "^8.26.0",
|
|
50
|
+
"vite": "^6.2.0",
|
|
51
|
+
"vitest": "^3.0.7"
|
|
52
52
|
},
|
|
53
53
|
"svelte": "./dist/index.js",
|
|
54
54
|
"types": "./dist/index.d.ts",
|
|
55
55
|
"type": "module"
|
|
56
|
-
}
|
|
56
|
+
}
|