@resistdesign/voltra 1.1.0 → 1.2.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/api/ORM/DataContextService.d.ts +3 -1
- package/api/ORM/TypeStructureUtils.d.ts +13 -3
- package/api/ORM/TypeStructureUtils.js +99 -30
- package/common/TypeParsing/TypeParsing.js +66 -3
- package/common/TypeParsing/TypeUtils.d.ts +14 -5
- package/common/TypeParsing/TypeUtils.js +67 -2
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncReturnValue, DBServiceItemDriver, ListItemResults, ListItemsConfig } from "./ServiceTypes/DBServiceTypes";
|
|
2
|
+
import { TypeStructureUnionType } from "../../common/TypeParsing";
|
|
2
3
|
export declare const DataContextServiceErrorTypes: {
|
|
3
4
|
OPERATION_NOT_ALLOWED: string;
|
|
4
5
|
RELATED_ITEM_SEARCH_NOT_ALLOWED: string;
|
|
@@ -14,14 +15,15 @@ export type DataContextField = {
|
|
|
14
15
|
isContext?: boolean;
|
|
15
16
|
isMultiple?: boolean;
|
|
16
17
|
allowedOperations?: DataContextOperationOptions[];
|
|
18
|
+
valueOptions?: TypeStructureUnionType[];
|
|
17
19
|
embedded?: boolean;
|
|
18
20
|
};
|
|
19
21
|
export type DataContext<ItemType extends Record<any, any>, UniquelyIdentifyingFieldName extends keyof ItemType> = {
|
|
20
22
|
itemTypeName: string;
|
|
21
23
|
resolvedType?: string;
|
|
22
|
-
isTypeAlias?: boolean;
|
|
23
24
|
uniquelyIdentifyingFieldName: UniquelyIdentifyingFieldName;
|
|
24
25
|
allowedOperations?: DataContextOperationOptions[];
|
|
26
|
+
valueOptions?: TypeStructureUnionType[];
|
|
25
27
|
fields: Partial<Record<keyof ItemType, DataContextField>>;
|
|
26
28
|
};
|
|
27
29
|
export type DataContextItemType<DC> = DC extends DataContext<infer T, any> ? T : never;
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { DataContextMap } from "./DataContextService";
|
|
2
|
-
import { TypeStructureMap } from "../../common/TypeParsing";
|
|
1
|
+
import { DataContext, DataContextField, DataContextMap } from "./DataContextService";
|
|
2
|
+
import { TypeStructure, TypeStructureMap, TypeStructureTagMap } from "../../common/TypeParsing";
|
|
3
|
+
export declare const DataContextFieldTagNames: {
|
|
4
|
+
uniquelyIdentifyingFieldName: string;
|
|
5
|
+
allowedOperations: string;
|
|
6
|
+
virtual: string;
|
|
7
|
+
};
|
|
3
8
|
export declare const getCleanedTagStringValue: (tagValue: any) => string | undefined;
|
|
9
|
+
export declare const typeStructureToDataContextField: (typeStructure: TypeStructure) => DataContextField;
|
|
10
|
+
export declare const mergeDataContextTagMaps: (tagMapA: TypeStructureTagMap, tagMapB: TypeStructureTagMap) => TypeStructureTagMap;
|
|
11
|
+
export declare const typeStructureToDataContext: (typeStructure: TypeStructure, typeStructureMap: TypeStructureMap, defaultUniquelyIdentifyingFieldName?: string, cache?: DataContextMap) => DataContext<any, any>;
|
|
12
|
+
export declare const DEFAULT_UNIQUELY_IDENTIFYING_FIELD_NAME = "id";
|
|
4
13
|
/**
|
|
5
14
|
* Create a {@link DataContextMap} from a {@link TypeStructureMap} generated from TypeScript types.
|
|
15
|
+
* Types tagged as `@virtual` will not be included in the resulting {@link DataContextMap}.
|
|
6
16
|
* */
|
|
7
|
-
export declare const typeStructureMapToDataContextMap: (typeStructureMap: TypeStructureMap) => DataContextMap;
|
|
17
|
+
export declare const typeStructureMapToDataContextMap: (typeStructureMap: TypeStructureMap, useDefaultUniquelyIdentifyingFieldName?: boolean) => DataContextMap;
|
|
@@ -1,50 +1,119 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.typeStructureMapToDataContextMap = exports.getCleanedTagStringValue = void 0;
|
|
3
|
+
exports.typeStructureMapToDataContextMap = exports.DEFAULT_UNIQUELY_IDENTIFYING_FIELD_NAME = exports.typeStructureToDataContext = exports.mergeDataContextTagMaps = exports.typeStructureToDataContextField = exports.getCleanedTagStringValue = exports.DataContextFieldTagNames = void 0;
|
|
4
4
|
const TypeParsing_1 = require("../../common/TypeParsing");
|
|
5
|
+
exports.DataContextFieldTagNames = {
|
|
6
|
+
uniquelyIdentifyingFieldName: "uniquelyIdentifyingFieldName",
|
|
7
|
+
allowedOperations: "allowedOperations",
|
|
8
|
+
virtual: "virtual",
|
|
9
|
+
};
|
|
5
10
|
const getCleanedTagStringValue = (tagValue) => {
|
|
6
11
|
const trimmed = typeof tagValue === "string" ? tagValue.trim() : undefined;
|
|
7
12
|
return !!trimmed ? trimmed : undefined;
|
|
8
13
|
};
|
|
9
14
|
exports.getCleanedTagStringValue = getCleanedTagStringValue;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const typeStructureToDataContextField = (typeStructure) => {
|
|
16
|
+
const { type, literal = false, multiple = false, isUnionType = false, unionTypes = [], } = typeStructure;
|
|
17
|
+
const allowedOperations = (0, exports.getCleanedTagStringValue)((0, TypeParsing_1.getTagValue)("allowedOperations", typeStructure));
|
|
18
|
+
const opsList = typeof allowedOperations === "string"
|
|
19
|
+
? allowedOperations.split(",").map((o) => o.trim())
|
|
20
|
+
: undefined;
|
|
21
|
+
return {
|
|
22
|
+
typeName: type,
|
|
23
|
+
isContext: !literal,
|
|
24
|
+
allowedOperations: opsList,
|
|
25
|
+
isMultiple: !!multiple,
|
|
26
|
+
valueOptions: isUnionType ? unionTypes : undefined,
|
|
27
|
+
embedded: literal,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
exports.typeStructureToDataContextField = typeStructureToDataContextField;
|
|
31
|
+
const mergeDataContextTagMaps = (tagMapA, tagMapB) => {
|
|
32
|
+
const { [exports.DataContextFieldTagNames.allowedOperations]: tagMapAAllowedOps } = tagMapA;
|
|
33
|
+
const { [exports.DataContextFieldTagNames.allowedOperations]: tagMapBAllowedOps } = tagMapB;
|
|
34
|
+
let mergedTag = Object.assign(Object.assign({}, tagMapA), tagMapB);
|
|
35
|
+
if (tagMapAAllowedOps && tagMapBAllowedOps) {
|
|
36
|
+
const { value: tagMapAAllowedOpsValue } = tagMapAAllowedOps;
|
|
37
|
+
const { value: tagMapBAllowedOpsValue } = tagMapBAllowedOps;
|
|
38
|
+
if (typeof tagMapAAllowedOpsValue === "string" &&
|
|
39
|
+
typeof tagMapBAllowedOpsValue === "string") {
|
|
40
|
+
const mergedAllowedOps = `${tagMapAAllowedOpsValue},${tagMapBAllowedOpsValue}`;
|
|
41
|
+
mergedTag = Object.assign(Object.assign({}, mergedTag), { [exports.DataContextFieldTagNames.allowedOperations]: {
|
|
42
|
+
type: "string",
|
|
43
|
+
value: mergedAllowedOps,
|
|
44
|
+
} });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return mergedTag;
|
|
48
|
+
};
|
|
49
|
+
exports.mergeDataContextTagMaps = mergeDataContextTagMaps;
|
|
50
|
+
const typeStructureToDataContext = (typeStructure, typeStructureMap, defaultUniquelyIdentifyingFieldName, cache = {}) => {
|
|
51
|
+
const tsMapCache = {};
|
|
52
|
+
const { namespace, type, isUnionType, unionTypes = [], content = [], contentNames: { allowed: allowedContentNames = [], disallowed: disallowedContentNames = [], } = {}, } = (0, TypeParsing_1.getCondensedTypeStructure)(typeStructure, typeStructureMap, exports.mergeDataContextTagMaps, tsMapCache);
|
|
53
|
+
const cleanFullTypeName = (0, TypeParsing_1.getCleanType)(type, namespace);
|
|
54
|
+
const cachedDataContext = cache[cleanFullTypeName];
|
|
55
|
+
const hasAllowedContentNames = allowedContentNames.length > 0;
|
|
56
|
+
const hasDisallowedContentNames = disallowedContentNames.length > 0;
|
|
57
|
+
if (cachedDataContext) {
|
|
58
|
+
return cachedDataContext;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const uniquelyIdentifyingFieldName = (0, exports.getCleanedTagStringValue)((0, TypeParsing_1.getTagValue)(exports.DataContextFieldTagNames.uniquelyIdentifyingFieldName, typeStructure));
|
|
62
|
+
const allowedOperations = (0, exports.getCleanedTagStringValue)((0, TypeParsing_1.getTagValue)(exports.DataContextFieldTagNames.allowedOperations, typeStructure));
|
|
21
63
|
const uuidFieldName = typeof uniquelyIdentifyingFieldName === "string"
|
|
22
64
|
? uniquelyIdentifyingFieldName.trim()
|
|
23
|
-
:
|
|
65
|
+
: defaultUniquelyIdentifyingFieldName;
|
|
24
66
|
const opsList = allowedOperations
|
|
25
67
|
? allowedOperations.split(",").map((o) => o.trim())
|
|
26
68
|
: undefined;
|
|
27
|
-
|
|
28
|
-
itemTypeName:
|
|
69
|
+
const newDataContext = {
|
|
70
|
+
itemTypeName: cleanFullTypeName,
|
|
29
71
|
resolvedType: type,
|
|
30
|
-
isTypeAlias: !(cleanFullTypeName === key),
|
|
31
72
|
uniquelyIdentifyingFieldName: uuidFieldName,
|
|
32
73
|
allowedOperations: opsList,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const subAO = (0, exports.getCleanedTagStringValue)((0, TypeParsing_1.getTagValue)("allowedOperations", subType));
|
|
36
|
-
const subOpsList = typeof subAO === "string"
|
|
37
|
-
? subAO.split(",").map((o) => o.trim())
|
|
38
|
-
: undefined;
|
|
39
|
-
return Object.assign(Object.assign({}, acc), { [name]: {
|
|
40
|
-
typeName: type,
|
|
41
|
-
isContext: !literal,
|
|
42
|
-
allowedOperations: subOpsList,
|
|
43
|
-
embedded: literal,
|
|
44
|
-
isMultiple: multiple,
|
|
45
|
-
} });
|
|
46
|
-
}, {}),
|
|
74
|
+
valueOptions: isUnionType ? unionTypes : undefined,
|
|
75
|
+
fields: {},
|
|
47
76
|
};
|
|
77
|
+
for (const field of content) {
|
|
78
|
+
const { name: fieldName } = field;
|
|
79
|
+
// IMPORTANT: Use `contentNames` (Pick/Omit) to limit fields.
|
|
80
|
+
const fieldIsAllowed = hasAllowedContentNames
|
|
81
|
+
? allowedContentNames.includes(fieldName)
|
|
82
|
+
: hasDisallowedContentNames
|
|
83
|
+
? !disallowedContentNames.includes(fieldName)
|
|
84
|
+
: true;
|
|
85
|
+
if (fieldIsAllowed) {
|
|
86
|
+
const { literal: mappedFieldTypeLiteral = false, unionTypes: mappedFieldTypeUnionTypes = [], } = (0, TypeParsing_1.getCondensedTypeStructure)(field, typeStructureMap, exports.mergeDataContextTagMaps, tsMapCache);
|
|
87
|
+
const isUnionType = mappedFieldTypeLiteral && mappedFieldTypeUnionTypes.length > 0;
|
|
88
|
+
newDataContext.fields[fieldName] = (0, exports.typeStructureToDataContextField)(Object.assign(Object.assign({}, field), { isUnionType, unionTypes: isUnionType ? mappedFieldTypeUnionTypes : undefined }));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
cache[cleanFullTypeName] = newDataContext;
|
|
92
|
+
return newDataContext;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.typeStructureToDataContext = typeStructureToDataContext;
|
|
96
|
+
exports.DEFAULT_UNIQUELY_IDENTIFYING_FIELD_NAME = "id";
|
|
97
|
+
/**
|
|
98
|
+
* Create a {@link DataContextMap} from a {@link TypeStructureMap} generated from TypeScript types.
|
|
99
|
+
* Types tagged as `@virtual` will not be included in the resulting {@link DataContextMap}.
|
|
100
|
+
* */
|
|
101
|
+
const typeStructureMapToDataContextMap = (typeStructureMap, useDefaultUniquelyIdentifyingFieldName = true) => {
|
|
102
|
+
const dataContextMap = {};
|
|
103
|
+
Object.entries(typeStructureMap).forEach(([_key, typeStructure]) => {
|
|
104
|
+
const { namespace, type } = typeStructure;
|
|
105
|
+
const isVirtual = (0, TypeParsing_1.getTagValue)(exports.DataContextFieldTagNames.virtual, typeStructure);
|
|
106
|
+
const cleanFullTypeName = (0, TypeParsing_1.getCleanType)(type, namespace);
|
|
107
|
+
// TODO: Losing pick/omit info here, because `type` is being used as the key.
|
|
108
|
+
// TODO: May need to keep the pick/omit types but mark them as not real database tables.
|
|
109
|
+
const existingDataContext = dataContextMap[cleanFullTypeName];
|
|
110
|
+
if (!isVirtual) {
|
|
111
|
+
dataContextMap[cleanFullTypeName] = !!existingDataContext
|
|
112
|
+
? existingDataContext
|
|
113
|
+
: (0, exports.typeStructureToDataContext)(typeStructure, typeStructureMap, useDefaultUniquelyIdentifyingFieldName
|
|
114
|
+
? exports.DEFAULT_UNIQUELY_IDENTIFYING_FIELD_NAME
|
|
115
|
+
: undefined, dataContextMap);
|
|
116
|
+
}
|
|
48
117
|
});
|
|
49
118
|
return dataContextMap;
|
|
50
119
|
};
|
|
@@ -17,6 +17,54 @@ const SUPPORTED_TYPE_REFERENCE_FEATURES = {
|
|
|
17
17
|
PICK: "Pick",
|
|
18
18
|
OMIT: "Omit",
|
|
19
19
|
};
|
|
20
|
+
const UNION_TYPE_SEPARATOR = "|";
|
|
21
|
+
const STRING_LITERAL_TYPE_DETECTION_REGEX = /(^'[\s\S]*'$)|(^"[\s\S]*"$)/gim;
|
|
22
|
+
const typeIsUnionType = (type = "") => type.includes(UNION_TYPE_SEPARATOR);
|
|
23
|
+
const typeIsBooleanLiteral = (type = "") => type === "true" || type === "false";
|
|
24
|
+
const getCleanBooleanLiteral = (type = "") => type === "true";
|
|
25
|
+
const typeIsStringLiteral = (type = "") => type.match(STRING_LITERAL_TYPE_DETECTION_REGEX) !== null;
|
|
26
|
+
const getCleanStringLiteral = (type = "") => type.replace(/['"]/gim, "");
|
|
27
|
+
const typeIsNumberLiteral = (type = "") => type !== "" && !isNaN(Number(type));
|
|
28
|
+
const getCleanNumberLiteral = (type = "") => Number(type);
|
|
29
|
+
const getUnionTypes = (type = "") => {
|
|
30
|
+
const cleanOverallType = type
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/^\(/gim, "")
|
|
33
|
+
.replace(/\)$/gim, "");
|
|
34
|
+
const typeParts = cleanOverallType.split(UNION_TYPE_SEPARATOR);
|
|
35
|
+
const cleanTypeParts = typeParts.map((t) => t.trim());
|
|
36
|
+
const parsedUnionTypes = cleanTypeParts.map((t) => {
|
|
37
|
+
if (typeIsBooleanLiteral(t)) {
|
|
38
|
+
return {
|
|
39
|
+
type: "boolean",
|
|
40
|
+
literal: true,
|
|
41
|
+
value: getCleanBooleanLiteral(t),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else if (typeIsStringLiteral(t)) {
|
|
45
|
+
return {
|
|
46
|
+
type: "string",
|
|
47
|
+
literal: true,
|
|
48
|
+
value: getCleanStringLiteral(t),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
else if (typeIsNumberLiteral(t)) {
|
|
52
|
+
return {
|
|
53
|
+
type: "number",
|
|
54
|
+
literal: true,
|
|
55
|
+
value: getCleanNumberLiteral(t),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return {
|
|
60
|
+
type: t,
|
|
61
|
+
literal: false,
|
|
62
|
+
value: t,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return parsedUnionTypes;
|
|
67
|
+
};
|
|
20
68
|
const TYPE_HANDLING_MAP = {
|
|
21
69
|
[typescript_1.SyntaxKind.TypeLiteral]: (name, typeNode, { parentName, namespace } = {}) => {
|
|
22
70
|
const content = [];
|
|
@@ -57,12 +105,22 @@ const TYPE_HANDLING_MAP = {
|
|
|
57
105
|
},
|
|
58
106
|
[typescript_1.SyntaxKind.UnionType]: (name, typeNode, { parentName, namespace } = {}) => {
|
|
59
107
|
const { types = [] } = typeNode;
|
|
108
|
+
const typeList = types.map((t) => {
|
|
109
|
+
const { type: parsedTypeName } = parseType(name, t, {
|
|
110
|
+
parentName,
|
|
111
|
+
namespace,
|
|
112
|
+
});
|
|
113
|
+
return parsedTypeName;
|
|
114
|
+
});
|
|
115
|
+
const unionTypes = getUnionTypes(typeList.join(UNION_TYPE_SEPARATOR));
|
|
60
116
|
return {
|
|
61
117
|
namespace,
|
|
62
118
|
name,
|
|
63
119
|
type: parentName ? `${parentName}.${name}` : name,
|
|
64
|
-
|
|
65
|
-
|
|
120
|
+
isUnionType: true,
|
|
121
|
+
unionTypes,
|
|
122
|
+
literal: unionTypes.reduce((acc, { literal }) => acc && literal, true),
|
|
123
|
+
content: [],
|
|
66
124
|
};
|
|
67
125
|
},
|
|
68
126
|
[typescript_1.SyntaxKind.IntersectionType]: (name, typeNode, { parentName, namespace } = {}) => {
|
|
@@ -167,10 +225,15 @@ const parseType = (name, typeNode, { parentName, namespace } = {}) => {
|
|
|
167
225
|
return Object.assign({ comments: [...comments, ...handledComments], tags: Object.assign(Object.assign({}, tags), handledTags) }, otherHandledTypeProps);
|
|
168
226
|
}
|
|
169
227
|
else {
|
|
228
|
+
const type = typeNode.getText();
|
|
229
|
+
const typeIsUnion = typeIsUnionType(type);
|
|
230
|
+
const unionTypes = typeIsUnion ? getUnionTypes(type) : undefined;
|
|
170
231
|
return {
|
|
171
232
|
namespace,
|
|
172
233
|
name,
|
|
173
|
-
type
|
|
234
|
+
type,
|
|
235
|
+
isUnionType: typeIsUnion,
|
|
236
|
+
unionTypes,
|
|
174
237
|
literal: true,
|
|
175
238
|
comments,
|
|
176
239
|
tags,
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
export type TypeStructureTagMap = Record<string, {
|
|
2
|
+
type?: string | undefined;
|
|
3
|
+
value?: string | boolean | undefined;
|
|
4
|
+
}>;
|
|
5
|
+
export type TypeStructureUnionType = {
|
|
6
|
+
type: string;
|
|
7
|
+
literal: boolean;
|
|
8
|
+
value: any;
|
|
9
|
+
};
|
|
1
10
|
export type TypeStructure = {
|
|
2
11
|
namespace?: string;
|
|
3
12
|
name: string;
|
|
4
13
|
typeAlias?: string;
|
|
5
14
|
type: string;
|
|
15
|
+
isUnionType?: boolean;
|
|
16
|
+
unionTypes?: TypeStructureUnionType[];
|
|
6
17
|
literal?: boolean;
|
|
7
18
|
readonly?: boolean;
|
|
8
19
|
optional?: boolean;
|
|
9
|
-
varietyType?: boolean;
|
|
10
20
|
comboType?: boolean;
|
|
11
21
|
multiple?: boolean | number;
|
|
12
22
|
contentNames?: {
|
|
@@ -15,10 +25,7 @@ export type TypeStructure = {
|
|
|
15
25
|
};
|
|
16
26
|
content?: TypeStructure[];
|
|
17
27
|
comments?: string[];
|
|
18
|
-
tags?:
|
|
19
|
-
type?: string | undefined;
|
|
20
|
-
value?: string | boolean | undefined;
|
|
21
|
-
}>;
|
|
28
|
+
tags?: TypeStructureTagMap;
|
|
22
29
|
};
|
|
23
30
|
export type TypeStructureMap = Record<string, TypeStructure>;
|
|
24
31
|
export type TypeStructureControllerItemOrdering = {
|
|
@@ -54,6 +61,8 @@ export declare const getCleanType: (typeValue?: string, namespace?: string) => s
|
|
|
54
61
|
export declare const getTypeStructureWithFilteredContent: ({ allowed, disallowed }: TypeStructure["contentNames"], typeStructure: TypeStructure) => TypeStructure;
|
|
55
62
|
export declare const getTypeStructureByName: <TypeStructureMapType extends TypeStructureMap, TypeStructureName extends keyof TypeStructureMapType>(name: TypeStructureName, map: TypeStructureMapType) => TypeStructureMapType[TypeStructureName];
|
|
56
63
|
export declare const getMergedTypeStructure: (...typeStructures: TypeStructure[]) => TypeStructure | undefined;
|
|
64
|
+
export declare const getUniqueStringArray: (arr: string[]) => string[];
|
|
65
|
+
export declare const getCondensedTypeStructure: (typeStructure: TypeStructure, typeStructureMap: TypeStructureMap, mergeTagMaps?: ((tagMapA: TypeStructureTagMap, tagMapB: TypeStructureTagMap) => TypeStructureTagMap) | undefined, cache?: TypeStructureMap) => TypeStructure;
|
|
57
66
|
export declare const getCleanTypeStructure: (typeStructure: TypeStructure, typeStructureMap?: TypeStructureMap) => TypeStructure;
|
|
58
67
|
export declare const getCleanTypeStructureMap: (typeStructureMap: TypeStructureMap) => TypeStructureMap;
|
|
59
68
|
export declare const getTypeStructureByPath: (path: (string | number)[], typeStructure: TypeStructure, typeStructureMap: TypeStructureMap) => TypeStructure;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getValueLabel = exports.getItemNameKeys = exports.getTagValues = exports.getTagValue = exports.getItemName = exports.getCleanPrimitiveStringValue = exports.TAG_TYPES = exports.getDefaultItemForTypeStructure = exports.getTypeStructureIsPrimitive = exports.getTypeStructureByPath = exports.getCleanTypeStructureMap = exports.getCleanTypeStructure = exports.getMergedTypeStructure = exports.getTypeStructureByName = exports.getTypeStructureWithFilteredContent = exports.getCleanType = exports.combineTypeStructures = exports.identifyValueType = void 0;
|
|
4
|
-
const NOOP = () => undefined;
|
|
3
|
+
exports.getValueLabel = exports.getItemNameKeys = exports.getTagValues = exports.getTagValue = exports.getItemName = exports.getCleanPrimitiveStringValue = exports.TAG_TYPES = exports.getDefaultItemForTypeStructure = exports.getTypeStructureIsPrimitive = exports.getTypeStructureByPath = exports.getCleanTypeStructureMap = exports.getCleanTypeStructure = exports.getCondensedTypeStructure = exports.getUniqueStringArray = exports.getMergedTypeStructure = exports.getTypeStructureByName = exports.getTypeStructureWithFilteredContent = exports.getCleanType = exports.combineTypeStructures = exports.identifyValueType = void 0;
|
|
5
4
|
const identifyValueType = (value, typeStructureVariety = []) => {
|
|
6
5
|
var _a;
|
|
7
6
|
const typeStructureMap = typeStructureVariety.reduce((acc, typeStructure) => {
|
|
@@ -87,6 +86,72 @@ const getMergedTypeStructure = (...typeStructures) => {
|
|
|
87
86
|
return mergedTypeStructure;
|
|
88
87
|
};
|
|
89
88
|
exports.getMergedTypeStructure = getMergedTypeStructure;
|
|
89
|
+
const getUniqueStringArray = (arr) => arr.filter((item, index) => arr.indexOf(item) === index);
|
|
90
|
+
exports.getUniqueStringArray = getUniqueStringArray;
|
|
91
|
+
const getCondensedTypeStructure = (typeStructure, typeStructureMap, mergeTagMaps, cache = {}) => {
|
|
92
|
+
const { namespace, type, typeAlias, literal = false } = typeStructure;
|
|
93
|
+
const cleanFullTypeName = (0, exports.getCleanType)(type, namespace);
|
|
94
|
+
let condensedTypeStructure = cache[cleanFullTypeName];
|
|
95
|
+
if (!condensedTypeStructure) {
|
|
96
|
+
if (literal) {
|
|
97
|
+
condensedTypeStructure = typeStructure;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const mappedType = !!typeAlias
|
|
101
|
+
? typeStructureMap[typeAlias]
|
|
102
|
+
: typeStructureMap[cleanFullTypeName];
|
|
103
|
+
const { comboType = false, isUnionType = false, content = [], } = mappedType;
|
|
104
|
+
if (mappedType) {
|
|
105
|
+
if (isUnionType) {
|
|
106
|
+
condensedTypeStructure = mappedType;
|
|
107
|
+
}
|
|
108
|
+
else if (comboType) {
|
|
109
|
+
let mergedType = Object.assign(Object.assign({}, mappedType), {
|
|
110
|
+
// TRICKY: Reset this because we don't want to keep type references, just get their fields.
|
|
111
|
+
content: [] });
|
|
112
|
+
for (const subType of content) {
|
|
113
|
+
const condensedSubType = (0, exports.getCondensedTypeStructure)(subType, typeStructureMap, mergeTagMaps, cache);
|
|
114
|
+
const { contentNames: { allowed: subTypeAllowedContentNames, disallowed: subTypeDisallowedContentNames, } = {}, content: subTypeContent = [], comments: subTypeComments = [], tags: subTypeTags = {}, } = condensedSubType;
|
|
115
|
+
const { contentNames: { allowed: mergedTypeAllowedContentNames, disallowed: mergedTypeDisallowedContentNames, } = {}, content: mergedTypeContent = [], comments: mergedTypeComments = [], tags: mergedTypeTags = {}, } = mergedType;
|
|
116
|
+
const newMergedTypeAllowedContentNames = !!subTypeAllowedContentNames || !!mergedTypeAllowedContentNames
|
|
117
|
+
? (0, exports.getUniqueStringArray)([
|
|
118
|
+
...(mergedTypeAllowedContentNames || []),
|
|
119
|
+
...(subTypeAllowedContentNames || []),
|
|
120
|
+
])
|
|
121
|
+
: undefined;
|
|
122
|
+
const newMergedTypeDisallowedContentNames = !!subTypeDisallowedContentNames ||
|
|
123
|
+
!!mergedTypeDisallowedContentNames
|
|
124
|
+
? (0, exports.getUniqueStringArray)([
|
|
125
|
+
...(mergedTypeDisallowedContentNames || []),
|
|
126
|
+
...(subTypeDisallowedContentNames || []),
|
|
127
|
+
])
|
|
128
|
+
: undefined;
|
|
129
|
+
const newMergedTypeContentNames = newMergedTypeAllowedContentNames ||
|
|
130
|
+
newMergedTypeDisallowedContentNames
|
|
131
|
+
? {
|
|
132
|
+
allowed: newMergedTypeAllowedContentNames,
|
|
133
|
+
disallowed: newMergedTypeDisallowedContentNames,
|
|
134
|
+
}
|
|
135
|
+
: undefined;
|
|
136
|
+
mergedType = Object.assign(Object.assign(Object.assign({}, mergedType), subType), { contentNames: newMergedTypeContentNames, content: [...mergedTypeContent, ...subTypeContent], comments: [...mergedTypeComments, ...subTypeComments], tags: !!mergeTagMaps
|
|
137
|
+
? mergeTagMaps(mergedTypeTags, subTypeTags)
|
|
138
|
+
: Object.assign(Object.assign({}, mergedTypeTags), subTypeTags) });
|
|
139
|
+
}
|
|
140
|
+
condensedTypeStructure = mergedType;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
condensedTypeStructure = (0, exports.getCondensedTypeStructure)(mappedType, typeStructureMap, mergeTagMaps, cache);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
condensedTypeStructure = typeStructure;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
cache[cleanFullTypeName] = condensedTypeStructure;
|
|
152
|
+
return condensedTypeStructure;
|
|
153
|
+
};
|
|
154
|
+
exports.getCondensedTypeStructure = getCondensedTypeStructure;
|
|
90
155
|
const getCleanTypeStructure = (typeStructure, typeStructureMap) => {
|
|
91
156
|
const { namespace, name, type, typeAlias, literal, comments = [], tags = {}, } = typeStructure;
|
|
92
157
|
if (literal) {
|