tsondb 0.17.4 → 0.17.7
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/dist/src/node/renderers/ts/render.d.ts +8 -0
- package/dist/src/node/renderers/ts/render.js +13 -13
- package/dist/src/node/schema/Node.d.ts +2 -0
- package/dist/src/node/schema/Schema.js +90 -36
- package/dist/src/node/schema/declarations/Declaration.d.ts +2 -1
- package/dist/src/node/schema/declarations/Declaration.js +14 -3
- package/dist/src/node/schema/declarations/EntityDecl.d.ts +20 -2
- package/dist/src/node/schema/declarations/EntityDecl.js +2 -0
- package/dist/src/node/schema/declarations/EnumDecl.d.ts +6 -1
- package/dist/src/node/schema/declarations/EnumDecl.js +5 -0
- package/dist/src/node/schema/declarations/TypeAliasDecl.d.ts +7 -2
- package/dist/src/node/schema/declarations/TypeAliasDecl.js +6 -0
- package/dist/src/node/schema/externalTypes.d.ts +24 -0
- package/dist/src/node/schema/types/Type.d.ts +7 -5
- package/dist/src/node/schema/types/Type.js +68 -30
- package/dist/src/node/schema/types/generic/ArrayType.d.ts +2 -1
- package/dist/src/node/schema/types/generic/ArrayType.js +4 -1
- package/dist/src/node/schema/types/generic/EnumType.d.ts +2 -1
- package/dist/src/node/schema/types/generic/EnumType.js +17 -1
- package/dist/src/node/schema/types/generic/ObjectType.d.ts +2 -1
- package/dist/src/node/schema/types/generic/ObjectType.js +6 -1
- package/dist/src/node/schema/types/generic/TranslationObjectType.d.ts +2 -1
- package/dist/src/node/schema/types/generic/TranslationObjectType.js +1 -0
- package/dist/src/node/schema/types/primitives/BooleanType.d.ts +2 -1
- package/dist/src/node/schema/types/primitives/BooleanType.js +1 -0
- package/dist/src/node/schema/types/primitives/DateType.d.ts +2 -1
- package/dist/src/node/schema/types/primitives/DateType.js +1 -0
- package/dist/src/node/schema/types/primitives/FloatType.d.ts +2 -1
- package/dist/src/node/schema/types/primitives/FloatType.js +1 -0
- package/dist/src/node/schema/types/primitives/IntegerType.d.ts +2 -1
- package/dist/src/node/schema/types/primitives/IntegerType.js +1 -0
- package/dist/src/node/schema/types/primitives/StringType.d.ts +2 -1
- package/dist/src/node/schema/types/primitives/StringType.js +1 -0
- package/dist/src/node/schema/types/references/ChildEntitiesType.d.ts +2 -1
- package/dist/src/node/schema/types/references/ChildEntitiesType.js +1 -0
- package/dist/src/node/schema/types/references/IncludeIdentifierType.d.ts +2 -1
- package/dist/src/node/schema/types/references/IncludeIdentifierType.js +2 -1
- package/dist/src/node/schema/types/references/NestedEntityMapType.d.ts +2 -1
- package/dist/src/node/schema/types/references/NestedEntityMapType.js +5 -2
- package/dist/src/node/schema/types/references/ReferenceIdentifierType.d.ts +2 -1
- package/dist/src/node/schema/types/references/ReferenceIdentifierType.js +1 -0
- package/dist/src/node/schema/types/references/TypeArgumentType.d.ts +2 -1
- package/dist/src/node/schema/types/references/TypeArgumentType.js +3 -0
- package/dist/src/node/server/api/declarations.js +5 -3
- package/dist/src/node/utils/customConstraints.d.ts +37 -14
- package/dist/src/node/utils/customConstraints.js +9 -13
- package/dist/src/node/utils/displayName.js +21 -16
- package/dist/src/node/utils/unique.js +6 -13
- package/dist/src/shared/schema/declarations/EntityDecl.d.ts +6 -27
- package/dist/src/shared/schema/declarations/EntityDecl.js +0 -2
- package/dist/src/shared/schema/declarations/EnumDecl.d.ts +1 -0
- package/dist/src/shared/schema/declarations/TypeAliasDecl.d.ts +1 -0
- package/dist/src/shared/schema/types/Type.d.ts +2 -0
- package/dist/src/shared/schema/types/Type.js +30 -1
- package/dist/src/shared/schema/utils/keyPath.d.ts +16 -0
- package/dist/src/shared/schema/utils/keyPath.js +65 -0
- package/dist/src/shared/schema/utils/sortOrder.d.ts +17 -0
- package/dist/src/shared/schema/utils/sortOrder.js +38 -0
- package/dist/src/shared/schema/utils/uniqueConstraint.d.ts +25 -0
- package/dist/src/shared/schema/utils/uniqueConstraint.js +1 -0
- package/dist/src/shared/utils/array.d.ts +12 -0
- package/dist/src/shared/utils/array.js +8 -0
- package/dist/src/shared/utils/object.d.ts +1 -0
- package/dist/src/shared/utils/object.js +1 -0
- package/dist/src/shared/utils/result.d.ts +8 -2
- package/dist/src/shared/utils/result.js +1 -1
- package/dist/src/shared/utils/typeSafety.d.ts +4 -0
- package/dist/src/shared/utils/typeSafety.js +8 -0
- package/dist/src/web/components/Settings.js +6 -1
- package/dist/src/web/components/typeInputs/ArrayTypeInput.js +8 -4
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInput.js +17 -10
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInputElement.d.ts +23 -0
- package/dist/src/web/components/typeInputs/ChildEntitiesTypeInputElement.js +21 -0
- package/dist/src/web/components/typeInputs/EnumTypeInput.js +3 -2
- package/dist/src/web/components/typeInputs/ObjectTypeInput.js +19 -7
- package/dist/src/web/context/settings.js +1 -0
- package/dist/src/web/hooks/useBoolean.d.ts +1 -0
- package/dist/src/web/hooks/useBoolean.js +13 -0
- package/dist/src/web/hooks/useSettings.d.ts +1 -0
- package/dist/src/web/hooks/useSettings.js +1 -0
- package/package.json +1 -1
- package/public/css/styles.css +85 -4
|
@@ -12,6 +12,14 @@ export type TypeScriptRendererOptions = {
|
|
|
12
12
|
* If `true` or a string, generates an object type with all names of entities with parent references as the key and their corresponding generated type as well as their parent reference key as their respective value. Uses `ChildEntityMap` as a default name when using `true` or the string if set to a string.
|
|
13
13
|
*/
|
|
14
14
|
childEntityMap: boolean | string;
|
|
15
|
+
/**
|
|
16
|
+
* If `true` or a string, generates an object type with all names of the enumerations as the key and their corresponding generated type as their respective value. Uses `EnumMap` as a default name when using `true` or the string if set to a string.
|
|
17
|
+
*/
|
|
18
|
+
enumMap: boolean | string;
|
|
19
|
+
/**
|
|
20
|
+
* If `true` or a string, generates an object type with all names of the type aliases as the key and their corresponding generated type as their respective value. Uses `TypeAliasMap` as a default name when using `true` or the string if set to a string.
|
|
21
|
+
*/
|
|
22
|
+
typeAliasMap: boolean | string;
|
|
15
23
|
}>;
|
|
16
24
|
addIdentifierToEntities: boolean;
|
|
17
25
|
/**
|
|
@@ -7,7 +7,8 @@ import { extractParameterTypeNamesFromMessage, mapParameterTypeNames, } from "..
|
|
|
7
7
|
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
8
8
|
import { asDecl } from "../../schema/declarations/Declaration.js";
|
|
9
9
|
import { addEphemeralUUIDToType, createEntityIdentifierTypeAsDecl, isEntityDecl, isEntityDeclWithParentReference, } from "../../schema/declarations/EntityDecl.js";
|
|
10
|
-
import {
|
|
10
|
+
import { isEnumDecl } from "../../schema/declarations/EnumDecl.js";
|
|
11
|
+
import { isTypeAliasDecl, TypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
|
|
11
12
|
import { flatMapAuxiliaryDecls, NodeKind } from "../../schema/Node.js";
|
|
12
13
|
import { ArrayType } from "../../schema/types/generic/ArrayType.js";
|
|
13
14
|
import { isObjectType } from "../../schema/types/generic/ObjectType.js";
|
|
@@ -158,21 +159,18 @@ const renderImports = (currentUrl, imports) => {
|
|
|
158
159
|
.join(EOL);
|
|
159
160
|
return importsSyntax.length > 0 ? importsSyntax + EOL + EOL : "";
|
|
160
161
|
};
|
|
161
|
-
const
|
|
162
|
-
? `export type ${options.generateHelpers
|
|
163
|
-
.filter(
|
|
162
|
+
const renderMapHelperType = (options, declarations, key, defaultName, filterFn, renderKeyFn) => options.generateHelpers[key]
|
|
163
|
+
? `export type ${options.generateHelpers[key] === true ? defaultName : options.generateHelpers[key]} = {${EOL}${prefixLines(getIndentation(options.indentation, 1), declarations
|
|
164
|
+
.filter(filterFn)
|
|
164
165
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
165
|
-
.map(
|
|
166
|
-
.
|
|
167
|
-
: "";
|
|
168
|
-
const renderChildEntityMapType = (options, declarations) => options.generateHelpers.childEntityMap
|
|
169
|
-
? `export type ${options.generateHelpers.childEntityMap === true ? "ChildEntityMap" : options.generateHelpers.childEntityMap} = {${EOL}${prefixLines(getIndentation(options.indentation, 1), declarations
|
|
170
|
-
.filter(isEntityDecl)
|
|
171
|
-
.filter(isEntityDeclWithParentReference)
|
|
172
|
-
.sort((a, b) => a.name.localeCompare(b.name))
|
|
173
|
-
.map(decl => `${decl.name}: [${decl.name}, "${decl.parentReferenceKey}", ${decl.name}["${decl.parentReferenceKey}"]]`)
|
|
166
|
+
.map(renderKeyFn ??
|
|
167
|
+
(decl => `${decl.name}: ${decl.name}${decl.parameters.length > 0 ? "<" + decl.parameters.map(param => (param.constraint ? renderType(options, param.constraint)[1] : "unknown")).join(", ") + ">" : ""}`))
|
|
174
168
|
.join(EOL))}${EOL}}${EOL + EOL}`
|
|
175
169
|
: "";
|
|
170
|
+
const renderEntityMapType = (options, declarations) => renderMapHelperType(options, declarations, "entityMap", "EntityMap", isEntityDecl);
|
|
171
|
+
const renderChildEntityMapType = (options, declarations) => renderMapHelperType(options, declarations, "childEntityMap", "ChildEntityMap", decl => isEntityDecl(decl) && isEntityDeclWithParentReference(decl), decl => `${decl.name}: [${decl.name}, "${decl.parentReferenceKey}", ${decl.name}["${decl.parentReferenceKey}"]]`);
|
|
172
|
+
const renderEnumMapType = (options, declarations) => renderMapHelperType(options, declarations, "enumMap", "EnumMap", isEnumDecl);
|
|
173
|
+
const renderTypeAliasMapType = (options, declarations) => renderMapHelperType(options, declarations, "typeAliasMap", "TypeAliasMap", isTypeAliasDecl);
|
|
176
174
|
const renderStringableTranslationParameterType = (options) => options.inferTranslationParameters?.format === "mf2"
|
|
177
175
|
? "export type StringableTranslationParameter = {" +
|
|
178
176
|
EOL +
|
|
@@ -230,6 +228,8 @@ export const render = (options = defaultOptions, declarations) => {
|
|
|
230
228
|
}, declarations));
|
|
231
229
|
return (renderEntityMapType(finalOptions, declarations) +
|
|
232
230
|
renderChildEntityMapType(finalOptions, declarations) +
|
|
231
|
+
renderEnumMapType(finalOptions, declarations) +
|
|
232
|
+
renderTypeAliasMapType(finalOptions, declarations) +
|
|
233
233
|
renderStringableTranslationParameterType(finalOptions) +
|
|
234
234
|
(finalOptions.preserveFiles
|
|
235
235
|
? (declarations[0] === undefined ? "" : renderImports(declarations[0].sourceUrl, imports)) +
|
|
@@ -18,6 +18,7 @@ import type { SerializedStringType } from "../../shared/schema/types/StringType.
|
|
|
18
18
|
import type { SerializedTranslationObjectType } from "../../shared/schema/types/TranslationObjectType.ts";
|
|
19
19
|
import type { SerializedTypeArgumentType } from "../../shared/schema/types/TypeArgumentType.ts";
|
|
20
20
|
import type { ValidationOptions } from "../index.ts";
|
|
21
|
+
import type { CustomConstraintHelpers } from "../utils/customConstraints.ts";
|
|
21
22
|
import { type DatabaseInMemory } from "../utils/databaseInMemory.ts";
|
|
22
23
|
import { type Decl, type IncludableDeclP } from "./declarations/Declaration.ts";
|
|
23
24
|
import { type EntityDecl } from "./declarations/EntityDecl.ts";
|
|
@@ -121,3 +122,4 @@ export type Serializer<T extends Node = Node> = (node: T) => Serialized<T>;
|
|
|
121
122
|
export declare const serializeNode: <T extends Node>(node: T) => Serialized<T>;
|
|
122
123
|
export type GetReferences<T extends Node = Node> = (node: T, value: unknown, inDecl: Decl[]) => string[];
|
|
123
124
|
export declare const getReferences: GetReferences;
|
|
125
|
+
export type CustomConstraintValidator<T extends Node = Node, V = unknown> = (node: T, value: V, helpers: CustomConstraintHelpers) => string[];
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import Debug from "debug";
|
|
2
|
-
import {
|
|
2
|
+
import { renderKeyPath } from "../../shared/schema/utils/keyPath.js";
|
|
3
3
|
import { anySame } from "../../shared/utils/array.js";
|
|
4
4
|
import { deepEqual } from "../../shared/utils/compare.js";
|
|
5
|
-
import { assertExhaustive } from "../../shared/utils/typeSafety.js";
|
|
5
|
+
import { assertExhaustive, trySafe } from "../../shared/utils/typeSafety.js";
|
|
6
6
|
import { getParameterNames, walkNodeTree } from "./declarations/Declaration.js";
|
|
7
7
|
import { isEntityDecl } from "./declarations/EntityDecl.js";
|
|
8
8
|
import { cases, isEnumDecl } from "./declarations/EnumDecl.js";
|
|
9
9
|
import { getNestedDeclarations, NodeKind } from "./Node.js";
|
|
10
10
|
import { isObjectType } from "./types/generic/ObjectType.js";
|
|
11
|
+
import { isFloatType } from "./types/primitives/FloatType.js";
|
|
12
|
+
import { isIntegerType } from "./types/primitives/IntegerType.js";
|
|
11
13
|
import { isStringType } from "./types/primitives/StringType.js";
|
|
12
14
|
import { isChildEntitiesType } from "./types/references/ChildEntitiesType.js";
|
|
13
15
|
import { isIncludeIdentifierType } from "./types/references/IncludeIdentifierType.js";
|
|
14
|
-
import { isNestedEntityMapType
|
|
16
|
+
import { isNestedEntityMapType } from "./types/references/NestedEntityMapType.js";
|
|
15
17
|
import { isReferenceIdentifierType, } from "./types/references/ReferenceIdentifierType.js";
|
|
16
18
|
import { findTypeAtPath } from "./types/Type.js";
|
|
17
19
|
const debug = Debug("tsondb:schema");
|
|
@@ -42,6 +44,18 @@ const checkParameterNamesShadowing = (decls) => {
|
|
|
42
44
|
}
|
|
43
45
|
};
|
|
44
46
|
const checkEntityDisplayNamePaths = (decls, localeEntity) => {
|
|
47
|
+
const getType = (type, keyPath) => trySafe(() => {
|
|
48
|
+
try {
|
|
49
|
+
return findTypeAtPath(type, keyPath, {
|
|
50
|
+
followTypeAliasIncludes: true,
|
|
51
|
+
throwOnPathMismatch: true,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.log(error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
45
59
|
for (const decl of decls) {
|
|
46
60
|
if (isEntityDecl(decl) && decl.instanceDisplayName !== null) {
|
|
47
61
|
const displayName = decl.instanceDisplayName ?? "name";
|
|
@@ -54,22 +68,19 @@ const checkEntityDisplayNamePaths = (decls, localeEntity) => {
|
|
|
54
68
|
if (localeEntity === undefined) {
|
|
55
69
|
throw new Error(`Display name path "${pathToLocaleMap}" for entity "${decl.name}" requires a defined locale entity.`);
|
|
56
70
|
}
|
|
57
|
-
const localeMapAtPath =
|
|
58
|
-
followTypeAliasIncludes: true,
|
|
59
|
-
});
|
|
71
|
+
const localeMapAtPath = getType(decl.type.value, pathToLocaleMap);
|
|
60
72
|
if (!localeMapAtPath ||
|
|
61
73
|
!isNestedEntityMapType(localeMapAtPath) ||
|
|
62
74
|
localeMapAtPath.secondaryEntity.name !== localeEntity.name) {
|
|
63
75
|
throw new Error(`Display name path "${pathToLocaleMap}" for entity "${decl.name}" does not lead to a nested entity map for the defined locale entity.`);
|
|
64
76
|
}
|
|
65
|
-
const typeAtLocaleMapPath =
|
|
77
|
+
const typeAtLocaleMapPath = getType(localeMapAtPath.type.value, pathInLocaleMap);
|
|
66
78
|
if (!typeAtLocaleMapPath || !isStringType(typeAtLocaleMapPath)) {
|
|
67
79
|
throw new Error(`Display name path "${pathInLocaleMap}" for entity "${decl.name}" does not lead to a value of type string in nested locale map.`);
|
|
68
80
|
}
|
|
69
81
|
}
|
|
70
82
|
else {
|
|
71
|
-
const
|
|
72
|
-
const typeAtPath = findTypeAtPath(decl.type.value, path, { followTypeAliasIncludes: true });
|
|
83
|
+
const typeAtPath = getType(decl.type.value, displayName);
|
|
73
84
|
if (!typeAtPath || !isStringType(typeAtPath)) {
|
|
74
85
|
throw new Error(`Display name path "${displayName}" for entity "${decl.name}" does not lead to a value of type string.`);
|
|
75
86
|
}
|
|
@@ -218,43 +229,34 @@ const checkRecursiveGenericTypeAliasesAndEnumerationsAreOnlyParameterizedDirectl
|
|
|
218
229
|
}, decl);
|
|
219
230
|
}
|
|
220
231
|
};
|
|
221
|
-
const getNodeAtKeyPath = (decl, objectType, keyPath, parent, parentPath = []) => {
|
|
222
|
-
const [key, ...keyPathRest] = normalizeKeyPath(keyPath);
|
|
223
|
-
if (key === undefined) {
|
|
224
|
-
return objectType;
|
|
225
|
-
}
|
|
226
|
-
const memberDecl = objectType.properties[key];
|
|
227
|
-
if (memberDecl === undefined) {
|
|
228
|
-
throw TypeError(`key "${key}"${parentPath.length === 0 ? "" : " in " + renderKeyPath(parentPath)} in unique constraint of entity "${decl.name}" does not exist in the entity`);
|
|
229
|
-
}
|
|
230
|
-
const value = memberDecl.type;
|
|
231
|
-
const actualValue = isIncludeIdentifierType(value) ? value.reference.type.value : value;
|
|
232
|
-
if (keyPathRest.length > 0) {
|
|
233
|
-
if (isObjectType(actualValue)) {
|
|
234
|
-
return getNodeAtKeyPath(decl, actualValue, keyPathRest, parent, [...parentPath, key]);
|
|
235
|
-
}
|
|
236
|
-
throw TypeError(`value at key "${key}"${parentPath.length === 0 ? "" : ' in "' + renderKeyPath(parentPath) + '"'}${parent ? " " + parent : ""} in unique constraint of entity "${decl.name}" does not contain an object type`);
|
|
237
|
-
}
|
|
238
|
-
return value;
|
|
239
|
-
};
|
|
240
232
|
const checkUniqueConstraintElement = (decl, element) => {
|
|
233
|
+
const getType = (type, keyPath, additionalText = "") => {
|
|
234
|
+
try {
|
|
235
|
+
return findTypeAtPath(type, keyPath, {
|
|
236
|
+
followTypeAliasIncludes: true,
|
|
237
|
+
throwOnPathMismatch: true,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
throw TypeError(`invalid key path${additionalText} in unique constraint of entity "${decl.name}"`, {
|
|
242
|
+
cause: err,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
};
|
|
241
246
|
if ("keyPath" in element) {
|
|
242
|
-
|
|
247
|
+
getType(decl.type.value, element.keyPath);
|
|
243
248
|
if (element.keyPathFallback !== undefined) {
|
|
244
|
-
|
|
249
|
+
getType(decl.type.value, element.keyPathFallback);
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
252
|
else {
|
|
248
|
-
const entityMapType =
|
|
253
|
+
const entityMapType = getType(decl.type.value, element.entityMapKeyPath);
|
|
249
254
|
if (!isNestedEntityMapType(entityMapType)) {
|
|
250
255
|
throw TypeError(`value at key "${renderKeyPath(element.entityMapKeyPath)}" is not a nested entity map as required by the unique constraint of entity "${decl.name}"`);
|
|
251
256
|
}
|
|
252
|
-
|
|
253
|
-
const getActualType = (type) => isIncludeIdentifierType(type) ? getActualType(type.reference.type.value) : type;
|
|
254
|
-
const actualType = getActualType(nestedType);
|
|
255
|
-
getNodeAtKeyPath(decl, actualType, element.keyPathInEntityMap, `in entity map "${renderKeyPath(element.entityMapKeyPath)}"`);
|
|
257
|
+
getType(entityMapType.type.value, element.keyPathInEntityMap, `in entity map "${renderKeyPath(element.entityMapKeyPath)}"`);
|
|
256
258
|
if (element.keyPathInEntityMapFallback !== undefined) {
|
|
257
|
-
|
|
259
|
+
getType(entityMapType.type.value, element.keyPathInEntityMapFallback, `in entity map "${renderKeyPath(element.entityMapKeyPath)}"`);
|
|
258
260
|
}
|
|
259
261
|
}
|
|
260
262
|
};
|
|
@@ -277,6 +279,56 @@ const checkUniqueConstraints = (declarations) => {
|
|
|
277
279
|
}
|
|
278
280
|
}
|
|
279
281
|
};
|
|
282
|
+
const isValidSortOrderType = (type) => isStringType(type) || isIntegerType(type) || isFloatType(type);
|
|
283
|
+
const checkSortOrders = (declarations) => {
|
|
284
|
+
for (const decl of declarations) {
|
|
285
|
+
if (isEntityDecl(decl) && decl.sortOrder !== undefined) {
|
|
286
|
+
const getType = (type, keyPath, additionalText = "") => {
|
|
287
|
+
try {
|
|
288
|
+
return findTypeAtPath(type, keyPath, {
|
|
289
|
+
followTypeAliasIncludes: true,
|
|
290
|
+
throwOnPathMismatch: true,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
catch (err) {
|
|
294
|
+
throw TypeError(`invalid key path${additionalText} in sort order of entity "${decl.name}"`, {
|
|
295
|
+
cause: err,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
const sortOrder = decl.sortOrder;
|
|
300
|
+
if (sortOrder === "displayName") {
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
else if ("keyPath" in sortOrder) {
|
|
304
|
+
const type = getType(decl.type.value, sortOrder.keyPath);
|
|
305
|
+
if (!isValidSortOrderType(type)) {
|
|
306
|
+
throw TypeError(`type at key path "${renderKeyPath(sortOrder.keyPath)}" is not a valid sort order type (string, integer, or float) in entity "${decl.name}"`);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
// const entityMapType = getType(decl.type.value, sortOrder.entityMapKeyPath)
|
|
311
|
+
// if (!isNestedEntityMapType(entityMapType)) {
|
|
312
|
+
// throw TypeError(
|
|
313
|
+
// `value at key "${renderKeyPath(sortOrder.entityMapKeyPath)}" is not a nested entity map as required by the sort order of entity "${decl.name}"`,
|
|
314
|
+
// )
|
|
315
|
+
// }
|
|
316
|
+
// const nestedType = getType(
|
|
317
|
+
// entityMapType.type.value,
|
|
318
|
+
// sortOrder.keyPathInEntityMap,
|
|
319
|
+
// `in entity map "${renderKeyPath(sortOrder.entityMapKeyPath)}"`,
|
|
320
|
+
// )
|
|
321
|
+
// if (!isValidSortOrderType(nestedType)) {
|
|
322
|
+
// throw TypeError(
|
|
323
|
+
// `type at key path "${renderKeyPath(
|
|
324
|
+
// sortOrder.keyPathInEntityMap,
|
|
325
|
+
// )}" in entity map "${renderKeyPath(sortOrder.entityMapKeyPath)}" is not a valid sort order type (string, integer, or float) in entity "${decl.name}"`,
|
|
326
|
+
// )
|
|
327
|
+
// }
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
};
|
|
280
332
|
const addDeclarations = (existingDecls, declsToAdd) => declsToAdd.reduce((accDecls, decl) => {
|
|
281
333
|
if (!accDecls.includes(decl)) {
|
|
282
334
|
return getNestedDeclarations(accDecls, decl.kind === "NestedEntity" ? decl.type : decl, undefined);
|
|
@@ -306,6 +358,8 @@ export const Schema = (declarations, localeEntity) => {
|
|
|
306
358
|
checkRecursiveGenericTypeAliasesAndEnumerationsAreOnlyParameterizedDirectlyInTypeAliases(allDeclsWithoutNestedEntities);
|
|
307
359
|
debug("checking unique constraints ...");
|
|
308
360
|
checkUniqueConstraints(allDeclsWithoutNestedEntities);
|
|
361
|
+
debug("checking sort orders ...");
|
|
362
|
+
checkSortOrders(allDeclsWithoutNestedEntities);
|
|
309
363
|
debug("created schema, no integrity violations found");
|
|
310
364
|
return {
|
|
311
365
|
declarations: allDeclsWithoutNestedEntities,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseNode, Node } from "../Node.ts";
|
|
1
|
+
import type { BaseNode, CustomConstraintValidator, Node } from "../Node.ts";
|
|
2
2
|
import type { TypeParameter } from "../TypeParameter.ts";
|
|
3
3
|
import type { EnumCaseDecl } from "../types/generic/EnumType.ts";
|
|
4
4
|
import { type Type } from "../types/Type.ts";
|
|
@@ -27,3 +27,4 @@ export declare const isDeclWithoutTypeParameters: (decl: Decl) => decl is DeclP<
|
|
|
27
27
|
export declare const resolveTypeArgumentsInDecls: (decls: readonly Decl[]) => Decl[];
|
|
28
28
|
export declare function walkNodeTree(callbackFn: (node: Node, parentTypes: Type[], parentDecl: Decl) => void, decl: Decl): void;
|
|
29
29
|
export declare const groupDeclarationsBySourceUrl: (decls: readonly Decl[]) => Partial<Record<string, Decl[]>>;
|
|
30
|
+
export declare const checkCustomConstraintsInNestedDecl: CustomConstraintValidator<SecondaryDecl>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { assertExhaustive } from "../../../shared/utils/typeSafety.js";
|
|
2
|
+
import { NodeKind, resolveTypeArguments } from "../Node.js";
|
|
2
3
|
import { walkTypeNodeTree } from "../types/Type.js";
|
|
3
4
|
import { isEntityDecl } from "./EntityDecl.js";
|
|
4
|
-
import { isEnumDecl } from "./EnumDecl.js";
|
|
5
|
-
import { isTypeAliasDecl } from "./TypeAliasDecl.js";
|
|
5
|
+
import { checkCustomConstraintsInEnumDecl, isEnumDecl } from "./EnumDecl.js";
|
|
6
|
+
import { checkCustomConstraintsInTypeAliasDecl, isTypeAliasDecl } from "./TypeAliasDecl.js";
|
|
6
7
|
export const getParameterNames = (decl) => decl.parameters.map(param => param.name);
|
|
7
8
|
export const getTypeArgumentsRecord = (decl, args) => Object.fromEntries(
|
|
8
9
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -22,3 +23,13 @@ export function walkNodeTree(callbackFn, decl) {
|
|
|
22
23
|
walkTypeNodeTree(callbackFn, decl.type.value, [], decl);
|
|
23
24
|
}
|
|
24
25
|
export const groupDeclarationsBySourceUrl = (decls) => Object.groupBy(decls, decl => decl.sourceUrl);
|
|
26
|
+
export const checkCustomConstraintsInNestedDecl = (decl, value, helpers) => {
|
|
27
|
+
switch (decl.kind) {
|
|
28
|
+
case NodeKind.EnumDecl:
|
|
29
|
+
return checkCustomConstraintsInEnumDecl(decl, value, helpers);
|
|
30
|
+
case NodeKind.TypeAliasDecl:
|
|
31
|
+
return checkCustomConstraintsInTypeAliasDecl(decl, value, helpers);
|
|
32
|
+
default:
|
|
33
|
+
return assertExhaustive(decl);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SortOrder } from "../../../shared/schema/utils/sortOrder.ts";
|
|
2
|
+
import type { UniqueConstraints } from "../../../shared/schema/utils/uniqueConstraint.ts";
|
|
3
|
+
import type { InstanceContent } from "../../../shared/utils/instances.ts";
|
|
2
4
|
import { Lazy } from "../../../shared/utils/lazy.ts";
|
|
3
5
|
import type { CustomConstraint, TypedCustomConstraint } from "../../utils/customConstraints.ts";
|
|
4
6
|
import type { DisplayNameCustomizer, TypedDisplayNameCustomizer } from "../../utils/displayName.ts";
|
|
5
|
-
import type { GetNestedDeclarations, GetReferences, Predicate, Serialized, TypeArgumentsResolver, Validator } from "../Node.ts";
|
|
7
|
+
import type { CustomConstraintValidator, GetNestedDeclarations, GetReferences, Predicate, Serialized, TypeArgumentsResolver, Validator } from "../Node.ts";
|
|
6
8
|
import { NodeKind } from "../Node.ts";
|
|
7
9
|
import type { MemberDecl, ObjectType } from "../types/generic/ObjectType.ts";
|
|
8
10
|
import { StringType } from "../types/primitives/StringType.ts";
|
|
@@ -52,6 +54,10 @@ export interface EntityDecl<Name extends string = string, T extends TConstraint
|
|
|
52
54
|
isDeprecated?: boolean;
|
|
53
55
|
uniqueConstraints?: UniqueConstraints;
|
|
54
56
|
customConstraints?: CustomConstraint;
|
|
57
|
+
/**
|
|
58
|
+
* The order in which instances of an entity are sorted in the editor. This affects entity details pages and reference options.
|
|
59
|
+
*/
|
|
60
|
+
sortOrder?: SortOrder;
|
|
55
61
|
}
|
|
56
62
|
export interface EntityDeclWithParentReference<Name extends string = string, T extends TConstraint = TConstraint, FK extends Extract<keyof T, string> = Extract<keyof T, string>> extends EntityDecl<Name, T, FK> {
|
|
57
63
|
}
|
|
@@ -81,6 +87,10 @@ export declare const EntityDecl: {
|
|
|
81
87
|
isDeprecated?: boolean;
|
|
82
88
|
uniqueConstraints?: UniqueConstraints;
|
|
83
89
|
customConstraints?: TypedCustomConstraint<Name>;
|
|
90
|
+
/**
|
|
91
|
+
* The order in which instances of an entity are sorted in the editor. This affects entity details pages and reference options.
|
|
92
|
+
*/
|
|
93
|
+
sortOrder?: SortOrder;
|
|
84
94
|
}): EntityDecl<Name, T, undefined>;
|
|
85
95
|
<Name extends string, T extends TConstraint, FK extends Extract<keyof T, string>>(sourceUrl: string, options: {
|
|
86
96
|
name: Name;
|
|
@@ -108,6 +118,10 @@ export declare const EntityDecl: {
|
|
|
108
118
|
isDeprecated?: boolean;
|
|
109
119
|
uniqueConstraints?: UniqueConstraints;
|
|
110
120
|
customConstraints?: TypedCustomConstraint<Name>;
|
|
121
|
+
/**
|
|
122
|
+
* The order in which instances of an entity are sorted in the editor. This affects entity details pages and reference options.
|
|
123
|
+
*/
|
|
124
|
+
sortOrder?: SortOrder;
|
|
111
125
|
}): EntityDecl<Name, T, FK>;
|
|
112
126
|
};
|
|
113
127
|
export { EntityDecl as Entity };
|
|
@@ -123,3 +137,7 @@ export declare const createEntityIdentifierType: () => StringType;
|
|
|
123
137
|
export declare const createEntityIdentifierTypeAsDecl: <Name extends string>(decl: EntityDecl<Name>) => TypeAliasDecl<`${Name}_ID`, StringType, []>;
|
|
124
138
|
export declare const serializeEntityDecl: <Name extends string, T extends TConstraint, FK extends Extract<keyof T, string> | undefined>(type: EntityDecl<Name, T, FK>) => Serialized<EntityDecl<Name, T, FK>>;
|
|
125
139
|
export declare const getReferencesForEntityDecl: GetReferences<EntityDecl>;
|
|
140
|
+
export declare const checkCustomConstraintsInEntityDecl: CustomConstraintValidator<EntityDecl, [
|
|
141
|
+
id: string,
|
|
142
|
+
content: InstanceContent
|
|
143
|
+
]>;
|
|
@@ -2,6 +2,7 @@ import { Lazy } from "../../../shared/utils/lazy.js";
|
|
|
2
2
|
import { NodeKind, resolveTypeArguments, validateType } from "../Node.js";
|
|
3
3
|
import { getNestedDeclarationsInObjectType, getReferencesForObjectType, Required, serializeObjectType, } from "../types/generic/ObjectType.js";
|
|
4
4
|
import { StringType } from "../types/primitives/StringType.js";
|
|
5
|
+
import { checkCustomConstraintsInType } from "../types/Type.js";
|
|
5
6
|
import { validateDeclName } from "./Declaration.js";
|
|
6
7
|
import { TypeAliasDecl } from "./TypeAliasDecl.js";
|
|
7
8
|
export const EntityDecl = (sourceUrl, options) => {
|
|
@@ -59,3 +60,4 @@ export const serializeEntityDecl = ((type) => ({
|
|
|
59
60
|
customConstraints: type.customConstraints !== undefined,
|
|
60
61
|
}));
|
|
61
62
|
export const getReferencesForEntityDecl = (decl, value, inDecl) => getReferencesForObjectType(decl.type.value, value, [...inDecl, decl]);
|
|
63
|
+
export const checkCustomConstraintsInEntityDecl = (decl, value, helpers) => (decl.customConstraints?.({ ...helpers, instanceId: value[0], instanceContent: value[1] }) ?? []).concat(checkCustomConstraintsInType(decl.type.value, value, helpers));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type EnumValue } from "../../../shared/schema/declarations/EnumDecl.ts";
|
|
2
2
|
import { Lazy } from "../../../shared/utils/lazy.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { NestedCustomConstraint, TypedNestedCustomConstraint } from "../../utils/customConstraints.ts";
|
|
4
|
+
import type { CustomConstraintValidator, GetNestedDeclarations, GetReferences, Predicate, Serializer, TypeArgumentsResolver, ValidatorOfParamDecl } from "../Node.ts";
|
|
4
5
|
import { NodeKind } from "../Node.ts";
|
|
5
6
|
import type { TypeParameter } from "../TypeParameter.ts";
|
|
6
7
|
import type { EnumCaseDecl } from "../types/generic/EnumType.ts";
|
|
@@ -11,6 +12,7 @@ export interface EnumDecl<Name extends string = string, T extends TConstraint =
|
|
|
11
12
|
kind: NodeKind["EnumDecl"];
|
|
12
13
|
type: Lazy<EnumType<T>>;
|
|
13
14
|
isDeprecated?: boolean;
|
|
15
|
+
customConstraints?: NestedCustomConstraint;
|
|
14
16
|
}
|
|
15
17
|
export declare const GenEnumDecl: <Name extends string, T extends TConstraint, Params extends TypeParameter[]>(sourceUrl: string, options: {
|
|
16
18
|
name: Name;
|
|
@@ -18,6 +20,7 @@ export declare const GenEnumDecl: <Name extends string, T extends TConstraint, P
|
|
|
18
20
|
parameters: Params;
|
|
19
21
|
isDeprecated?: boolean;
|
|
20
22
|
values: (...args: Params) => T;
|
|
23
|
+
customConstraints?: TypedNestedCustomConstraint<Name>;
|
|
21
24
|
}) => EnumDecl<Name, T, Params>;
|
|
22
25
|
export { GenEnumDecl as GenEnum };
|
|
23
26
|
export declare const EnumDecl: <Name extends string, T extends Record<string, EnumCaseDecl>>(sourceUrl: string, options: {
|
|
@@ -25,6 +28,7 @@ export declare const EnumDecl: <Name extends string, T extends Record<string, En
|
|
|
25
28
|
comment?: string;
|
|
26
29
|
isDeprecated?: boolean;
|
|
27
30
|
values: () => T;
|
|
31
|
+
customConstraints?: TypedNestedCustomConstraint<Name>;
|
|
28
32
|
}) => EnumDecl<Name, T, []>;
|
|
29
33
|
export { EnumDecl as Enum };
|
|
30
34
|
export declare const isEnumDecl: Predicate<EnumDecl>;
|
|
@@ -35,3 +39,4 @@ export declare const serializeEnumDecl: Serializer<EnumDecl>;
|
|
|
35
39
|
export declare const getReferencesForEnumDecl: GetReferences<EnumDecl>;
|
|
36
40
|
export declare const cases: <T extends TConstraint>(decl: EnumDecl<string, T>) => EnumCaseDecl<T[keyof T]["type"]>[];
|
|
37
41
|
export declare const getAnyEnumCaseValue: <K extends string, V>(enumValue: { [Key in K]: EnumValue<Key, V>; }[K]) => V;
|
|
42
|
+
export declare const checkCustomConstraintsInEnumDecl: CustomConstraintValidator<EnumDecl>;
|
|
@@ -4,6 +4,7 @@ import { onlyKeys } from "../../../shared/utils/object.js";
|
|
|
4
4
|
import { NodeKind } from "../Node.js";
|
|
5
5
|
import { serializeTypeParameter } from "../TypeParameter.js";
|
|
6
6
|
import { EnumType, getNestedDeclarationsInEnumType, getReferencesForEnumType, resolveTypeArgumentsInEnumType, serializeEnumType, validateEnumType, } from "../types/generic/EnumType.js";
|
|
7
|
+
import { checkCustomConstraintsInType } from "../types/Type.js";
|
|
7
8
|
import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
|
|
8
9
|
export const GenEnumDecl = (sourceUrl, options) => {
|
|
9
10
|
validateDeclName(options.name);
|
|
@@ -12,6 +13,7 @@ export const GenEnumDecl = (sourceUrl, options) => {
|
|
|
12
13
|
kind: NodeKind.EnumDecl,
|
|
13
14
|
sourceUrl,
|
|
14
15
|
type: Lazy.of(() => EnumType(options.values(...options.parameters))),
|
|
16
|
+
customConstraints: options.customConstraints, // ignore contravariance of registered enum type
|
|
15
17
|
};
|
|
16
18
|
return decl;
|
|
17
19
|
};
|
|
@@ -24,6 +26,7 @@ export const EnumDecl = (sourceUrl, options) => {
|
|
|
24
26
|
sourceUrl,
|
|
25
27
|
parameters: [],
|
|
26
28
|
type: Lazy.of(() => EnumType(options.values())),
|
|
29
|
+
customConstraints: options.customConstraints, // ignore contravariance of registered enum type
|
|
27
30
|
};
|
|
28
31
|
return decl;
|
|
29
32
|
};
|
|
@@ -44,7 +47,9 @@ export const serializeEnumDecl = decl => ({
|
|
|
44
47
|
...decl,
|
|
45
48
|
type: serializeEnumType(decl.type.value),
|
|
46
49
|
parameters: decl.parameters.map(param => serializeTypeParameter(param)),
|
|
50
|
+
customConstraints: decl.customConstraints !== undefined,
|
|
47
51
|
});
|
|
48
52
|
export const getReferencesForEnumDecl = (decl, value, inDecl) => getReferencesForEnumType(decl.type.value, value, [...inDecl, decl]);
|
|
49
53
|
export const cases = (decl) => Object.values(decl.type.value.values);
|
|
50
54
|
export const getAnyEnumCaseValue = (enumValue) => enumValue[enumValue[ENUM_DISCRIMINATOR_KEY]];
|
|
55
|
+
export const checkCustomConstraintsInEnumDecl = (decl, value, helpers) => (decl.customConstraints?.({ ...helpers, value }) ?? []).concat(checkCustomConstraintsInType(decl.type.value, value, helpers));
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { Lazy } from "../../../shared/utils/lazy.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { NestedCustomConstraint, TypedNestedCustomConstraint } from "../../utils/customConstraints.ts";
|
|
3
|
+
import type { CustomConstraintValidator, GetNestedDeclarations, GetReferences, Predicate, Serializer, TypeArgumentsResolver, ValidationContext } from "../Node.ts";
|
|
3
4
|
import { NodeKind } from "../Node.ts";
|
|
4
5
|
import type { TypeParameter } from "../TypeParameter.ts";
|
|
5
|
-
import type
|
|
6
|
+
import { type Type } from "../types/Type.ts";
|
|
6
7
|
import type { BaseDecl, Decl, TypeArguments } from "./Declaration.ts";
|
|
7
8
|
export interface TypeAliasDecl<Name extends string = string, T extends Type = Type, Params extends TypeParameter[] = TypeParameter[]> extends BaseDecl<Name, Params> {
|
|
8
9
|
kind: NodeKind["TypeAliasDecl"];
|
|
9
10
|
type: Lazy<T>;
|
|
10
11
|
isDeprecated?: boolean;
|
|
12
|
+
customConstraints?: NestedCustomConstraint;
|
|
11
13
|
}
|
|
12
14
|
export declare const GenTypeAliasDecl: <Name extends string, T extends Type, Params extends TypeParameter[]>(sourceUrl: string, options: {
|
|
13
15
|
name: Name;
|
|
@@ -15,6 +17,7 @@ export declare const GenTypeAliasDecl: <Name extends string, T extends Type, Par
|
|
|
15
17
|
isDeprecated?: boolean;
|
|
16
18
|
parameters: Params;
|
|
17
19
|
type: (...args: Params) => T;
|
|
20
|
+
customConstraints?: TypedNestedCustomConstraint<Name>;
|
|
18
21
|
}) => TypeAliasDecl<Name, T, Params>;
|
|
19
22
|
export { GenTypeAliasDecl as GenTypeAlias };
|
|
20
23
|
export declare const TypeAliasDecl: <Name extends string, T extends Type>(sourceUrl: string, options: {
|
|
@@ -22,6 +25,7 @@ export declare const TypeAliasDecl: <Name extends string, T extends Type>(source
|
|
|
22
25
|
comment?: string;
|
|
23
26
|
isDeprecated?: boolean;
|
|
24
27
|
type: () => T;
|
|
28
|
+
customConstraints?: TypedNestedCustomConstraint<Name>;
|
|
25
29
|
}) => TypeAliasDecl<Name, T, []>;
|
|
26
30
|
export { TypeAliasDecl as TypeAlias };
|
|
27
31
|
export declare const isTypeAliasDecl: Predicate<TypeAliasDecl>;
|
|
@@ -30,3 +34,4 @@ export declare const validateTypeAliasDecl: <Params extends TypeParameter[]>(hel
|
|
|
30
34
|
export declare const resolveTypeArgumentsInTypeAliasDecl: TypeArgumentsResolver<TypeAliasDecl>;
|
|
31
35
|
export declare const serializeTypeAliasDecl: Serializer<TypeAliasDecl>;
|
|
32
36
|
export declare const getReferencesForTypeAliasDecl: GetReferences<TypeAliasDecl>;
|
|
37
|
+
export declare const checkCustomConstraintsInTypeAliasDecl: CustomConstraintValidator<TypeAliasDecl>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Lazy } from "../../../shared/utils/lazy.js";
|
|
2
2
|
import { getNestedDeclarations, getReferences, NodeKind, resolveTypeArguments, serializeNode, validateType, } from "../Node.js";
|
|
3
3
|
import { serializeTypeParameter } from "../TypeParameter.js";
|
|
4
|
+
import { checkCustomConstraintsInType } from "../types/Type.js";
|
|
4
5
|
import { getTypeArgumentsRecord, validateDeclName } from "./Declaration.js";
|
|
5
6
|
export const GenTypeAliasDecl = (sourceUrl, options) => {
|
|
6
7
|
validateDeclName(options.name);
|
|
@@ -9,6 +10,7 @@ export const GenTypeAliasDecl = (sourceUrl, options) => {
|
|
|
9
10
|
kind: NodeKind.TypeAliasDecl,
|
|
10
11
|
sourceUrl,
|
|
11
12
|
type: Lazy.of(() => options.type(...options.parameters)),
|
|
13
|
+
customConstraints: options.customConstraints, // ignore contravariance of registered enum type
|
|
12
14
|
};
|
|
13
15
|
return decl;
|
|
14
16
|
};
|
|
@@ -21,6 +23,7 @@ export const TypeAliasDecl = (sourceUrl, options) => {
|
|
|
21
23
|
sourceUrl,
|
|
22
24
|
parameters: [],
|
|
23
25
|
type: Lazy.of(() => options.type()),
|
|
26
|
+
customConstraints: options.customConstraints, // ignore contravariance of registered type alias type
|
|
24
27
|
};
|
|
25
28
|
return decl;
|
|
26
29
|
};
|
|
@@ -31,10 +34,13 @@ export const validateTypeAliasDecl = ((helpers, inDecls, decl, args, value) => v
|
|
|
31
34
|
export const resolveTypeArgumentsInTypeAliasDecl = (args, decl, inDecl) => TypeAliasDecl(decl.sourceUrl, {
|
|
32
35
|
...decl,
|
|
33
36
|
type: () => resolveTypeArguments(args, decl.type.value, [...inDecl, decl]),
|
|
37
|
+
customConstraints: decl.customConstraints, // ignore contravariance of registered type alias type
|
|
34
38
|
});
|
|
35
39
|
export const serializeTypeAliasDecl = type => ({
|
|
36
40
|
...type,
|
|
37
41
|
type: serializeNode(type.type.value),
|
|
38
42
|
parameters: type.parameters.map(param => serializeTypeParameter(param)),
|
|
43
|
+
customConstraints: type.customConstraints !== undefined,
|
|
39
44
|
});
|
|
40
45
|
export const getReferencesForTypeAliasDecl = (decl, value, inDecl) => getReferences(decl.type.value, value, [...inDecl, decl]);
|
|
46
|
+
export const checkCustomConstraintsInTypeAliasDecl = (decl, value, helpers) => (decl.customConstraints?.({ ...helpers, value }) ?? []).concat(checkCustomConstraintsInType(decl.type.value, value, helpers));
|
|
@@ -18,3 +18,27 @@ export type AnyChildEntityMap = Record<string, [
|
|
|
18
18
|
export type RegisteredChildEntityMap<T = Register> = T extends {
|
|
19
19
|
childEntityMap: AnyChildEntityMap;
|
|
20
20
|
} ? T["childEntityMap"] : AnyChildEntityMap;
|
|
21
|
+
type EnumContent = object;
|
|
22
|
+
export type AnyEnumMap = Record<string, EnumContent>;
|
|
23
|
+
export type RegisteredEnumMap<T = Register> = T extends {
|
|
24
|
+
enumMap: AnyEnumMap;
|
|
25
|
+
} ? T["enumMap"] : AnyEnumMap;
|
|
26
|
+
export type RegisteredEnum<Name extends string, T = Register> = T extends {
|
|
27
|
+
enumMap: {
|
|
28
|
+
[K in Name]: EnumContent;
|
|
29
|
+
};
|
|
30
|
+
} ? T["enumMap"][Name] : EnumContent;
|
|
31
|
+
type TypeAliasContent = unknown;
|
|
32
|
+
export type AnyTypeAliasMap = Record<string, TypeAliasContent>;
|
|
33
|
+
export type RegisteredTypeAliasMap<T = Register> = T extends {
|
|
34
|
+
typeAliasMap: AnyTypeAliasMap;
|
|
35
|
+
} ? T["typeAliasMap"] : AnyTypeAliasMap;
|
|
36
|
+
export type RegisteredTypeAlias<Name extends string, T = Register> = T extends {
|
|
37
|
+
typeAliasMap: {
|
|
38
|
+
[K in Name]: TypeAliasContent;
|
|
39
|
+
};
|
|
40
|
+
} ? T["typeAliasMap"][Name] : TypeAliasContent;
|
|
41
|
+
export type RegisteredEnumOrTypeAlias<Name extends string, T = Register> = RegisteredEnumMap extends {
|
|
42
|
+
[K in Name]: unknown;
|
|
43
|
+
} ? RegisteredEnum<Name, T> : RegisteredTypeAlias<Name, T>;
|
|
44
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { type KeyPath } from "../../../shared/schema/utils/keyPath.ts";
|
|
1
2
|
import { type Decl, type EnumDecl, type TypeAliasDecl, type TypeParameter } from "../index.ts";
|
|
2
|
-
import type { BaseNode } from "../Node.ts";
|
|
3
|
+
import type { BaseNode, CustomConstraintValidator } from "../Node.ts";
|
|
3
4
|
import type { ArrayType } from "./generic/ArrayType.ts";
|
|
4
5
|
import type { EnumCaseDecl, EnumType } from "./generic/EnumType.ts";
|
|
5
6
|
import type { MemberDecl, ObjectType } from "./generic/ObjectType.ts";
|
|
@@ -36,8 +37,7 @@ type MemberDeclsAsType<P extends Record<string, MemberDecl>> = {
|
|
|
36
37
|
[K in keyof P]: P[K] extends MemberDecl<Type, true> ? AsType<P[K]["type"]> : AsType<P[K]["type"]> | undefined;
|
|
37
38
|
};
|
|
38
39
|
type MemberDeclsAsDeepType<P extends Record<string, MemberDecl>> = {
|
|
39
|
-
[K in keyof P]: P[K] extends MemberDecl<Type, true> ? AsDeepType<P[K]["type"]> :
|
|
40
|
-
AsDeepType<P[K]["type"]> | undefined;
|
|
40
|
+
[K in keyof P]: P[K] extends MemberDecl<Type, true> ? AsDeepType<P[K]["type"]> : AsDeepType<P[K]["type"]> | undefined;
|
|
41
41
|
};
|
|
42
42
|
export type AsDeepType<T extends Type> = T extends ArrayType<infer I> ? AsDeepType<I>[] : T extends ObjectType<infer P> ? MemberDeclsAsDeepType<P> : T extends BooleanType ? boolean : T extends DateType ? Date : T extends FloatType ? number : T extends IntegerType ? number : T extends StringType ? string : T extends TypeArgumentType ? unknown : T extends IncludeIdentifierType<TypeParameter[], infer Decl> ? Decl extends TypeAliasDecl<string, infer TA> ? AsDeepType<TA> : Decl extends EnumDecl<string, infer EC> ? AsDeepType<EnumType<EC>> : unknown : T extends NestedEntityMapType<string, infer TC> ? {
|
|
43
43
|
[id: string]: MemberDeclsAsDeepType<TC>;
|
|
@@ -52,12 +52,14 @@ export type AsType<T extends Type> = T extends ArrayType<infer I> ? AsType<I>[]
|
|
|
52
52
|
export type AsNode<T> = T extends (infer I)[] ? ArrayType<AsNode<I>> : T extends Record<string, unknown> ? ObjectType<{
|
|
53
53
|
[K in keyof T]: T[K] extends MemberDecl ? T[K] : T extends null | undefined ? MemberDecl<AsNode<NonNullable<T[K]>>, false> : MemberDecl<AsNode<T[K]>, true>;
|
|
54
54
|
}> : T extends string ? StringType : T extends number ? FloatType : T extends boolean ? BooleanType : T extends Date ? DateType : never;
|
|
55
|
-
export declare const findTypeAtPath: (type: Type, path:
|
|
55
|
+
export declare const findTypeAtPath: (type: Type, path: KeyPath, options?: {
|
|
56
56
|
followTypeAliasIncludes?: boolean;
|
|
57
|
-
|
|
57
|
+
throwOnPathMismatch?: boolean;
|
|
58
|
+
}) => Type;
|
|
58
59
|
/**
|
|
59
60
|
* Format the structure of a value to always look the same when serialized as JSON.
|
|
60
61
|
*/
|
|
61
62
|
export type StructureFormatter<T extends Type> = (type: T, value: unknown) => unknown;
|
|
62
63
|
export declare const formatValue: StructureFormatter<Type>;
|
|
64
|
+
export declare const checkCustomConstraintsInType: CustomConstraintValidator<Type>;
|
|
63
65
|
export {};
|