tsondb 0.5.16 → 0.5.17
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/schema/declarations/Declaration.d.ts +1 -0
- package/dist/src/node/schema/types/references/IncludeIdentifierType.d.ts +3 -2
- package/dist/src/node/schema/types/references/IncludeIdentifierType.js +3 -2
- package/dist/src/node/schema/types/references/NestedEntityMapType.d.ts +7 -4
- package/dist/src/node/schema/types/references/NestedEntityMapType.js +20 -10
- package/package.json +1 -1
|
@@ -17,6 +17,7 @@ export declare const getTypeArgumentsRecord: <Params extends TypeParameter[]>(de
|
|
|
17
17
|
export type Decl = EntityDecl | EnumDecl | TypeAliasDecl;
|
|
18
18
|
export type SerializedDecl = SerializedEntityDecl | SerializedEnumDecl | SerializedTypeAliasDecl;
|
|
19
19
|
export type DeclP<Params extends TypeParameter[] = TypeParameter[]> = EntityDecl | EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
|
|
20
|
+
export type IncludableDeclP<Params extends TypeParameter[] = TypeParameter[]> = EnumDecl<string, Record<string, EnumCaseDecl>, Params> | TypeAliasDecl<string, Type, Params>;
|
|
20
21
|
export type SerializedDeclP<Params extends SerializedTypeParameter[] = SerializedTypeParameter[]> = SerializedEntityDecl | SerializedEnumDecl<string, Record<string, SerializedEnumCaseDecl>, Params> | SerializedTypeAliasDecl<string, SerializedType, Params>;
|
|
21
22
|
export type SecondaryDecl = EnumDecl | TypeAliasDecl;
|
|
22
23
|
export type SerializedSecondaryDecl = SerializedEnumDecl | SerializedTypeAliasDecl;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GetNestedDeclarations, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.ts";
|
|
1
|
+
import type { GetNestedDeclarations, IncludableDeclP, SerializedTypeArguments, TypeArguments } from "../../declarations/Declaration.ts";
|
|
2
2
|
import type { EnumDecl } from "../../declarations/EnumDecl.ts";
|
|
3
3
|
import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.ts";
|
|
4
4
|
import type { GetReferences, Node, Serializer } from "../../Node.ts";
|
|
@@ -23,9 +23,10 @@ export { GenIncludeIdentifierType as GenIncludeIdentifier };
|
|
|
23
23
|
export declare const IncludeIdentifierType: <T extends TConstraint<[]>>(reference: T) => IncludeIdentifierType<[], T>;
|
|
24
24
|
export { IncludeIdentifierType as IncludeIdentifier };
|
|
25
25
|
export declare const isIncludeIdentifierType: (node: Node) => node is IncludeIdentifierType;
|
|
26
|
+
export declare const isNoGenericIncludeIdentifierType: (node: IncludeIdentifierType) => node is IncludeIdentifierType<[], IncludableDeclP<[]>>;
|
|
26
27
|
export declare const getNestedDeclarationsInIncludeIdentifierType: GetNestedDeclarations<IncludeIdentifierType>;
|
|
27
28
|
export declare const validateIncludeIdentifierType: Validator<IncludeIdentifierType>;
|
|
28
|
-
export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type:
|
|
29
|
+
export declare const resolveTypeArgumentsInIncludeIdentifierType: <T extends IncludeIdentifierType>(args: Record<string, Type>, type: T) => T extends IncludeIdentifierType<[], IncludableDeclP<[]>> ? T : Type;
|
|
29
30
|
export declare const serializeIncludeIdentifierType: Serializer<IncludeIdentifierType, SerializedIncludeIdentifierType>;
|
|
30
31
|
export declare const getReferencesForIncludeIdentifierType: GetReferences<IncludeIdentifierType>;
|
|
31
32
|
export declare const formatIncludeIdentifierValue: StructureFormatter<IncludeIdentifierType>;
|
|
@@ -15,13 +15,14 @@ export const IncludeIdentifierType = (reference) => ({
|
|
|
15
15
|
});
|
|
16
16
|
export { IncludeIdentifierType as IncludeIdentifier };
|
|
17
17
|
export const isIncludeIdentifierType = (node) => node.kind === NodeKind.IncludeIdentifierType;
|
|
18
|
+
export const isNoGenericIncludeIdentifierType = (node) => node.args.length === 0 && node.reference.parameters.length === 0;
|
|
18
19
|
export const getNestedDeclarationsInIncludeIdentifierType = (addedDecls, type) => type.args.reduce((accAddedDecls, arg) => getNestedDeclarations(accAddedDecls, arg), addedDecls.includes(type.reference)
|
|
19
20
|
? addedDecls
|
|
20
21
|
: getNestedDeclarations([type.reference, ...addedDecls], type.reference));
|
|
21
22
|
export const validateIncludeIdentifierType = (helpers, type, value) => validateDecl(helpers, type.reference, type.args, value);
|
|
22
|
-
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => type
|
|
23
|
+
export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => (isNoGenericIncludeIdentifierType(type)
|
|
23
24
|
? type
|
|
24
|
-
: resolveTypeArgumentsInDecl(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg))).type.value;
|
|
25
|
+
: resolveTypeArgumentsInDecl(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg))).type.value);
|
|
25
26
|
export const serializeIncludeIdentifierType = type => ({
|
|
26
27
|
...removeParentKey(type),
|
|
27
28
|
reference: type.reference.name,
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { Lazy } from "../../../../shared/utils/lazy.ts";
|
|
2
|
-
import type
|
|
2
|
+
import { type GetNestedDeclarations } from "../../declarations/Declaration.ts";
|
|
3
3
|
import type { EntityDecl } from "../../declarations/EntityDecl.ts";
|
|
4
|
+
import type { TypeAliasDecl } from "../../declarations/TypeAliasDecl.ts";
|
|
4
5
|
import type { GetReferences, Node, Serializer } from "../../Node.ts";
|
|
5
6
|
import { NodeKind } from "../../Node.ts";
|
|
6
7
|
import type { Validator } from "../../validation/type.ts";
|
|
7
8
|
import type { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.ts";
|
|
8
9
|
import type { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.ts";
|
|
10
|
+
import { type IncludeIdentifier, type SerializedIncludeIdentifierType } from "./IncludeIdentifierType.ts";
|
|
9
11
|
type TConstraint = Record<string, MemberDecl>;
|
|
12
|
+
type PossibleType<T extends TConstraint> = ObjectType<T> | IncludeIdentifier<[], TypeAliasDecl<string, ObjectType<T>, []>>;
|
|
10
13
|
export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
|
|
11
14
|
kind: NodeKind["NestedEntityMapType"];
|
|
12
15
|
name: Name;
|
|
13
16
|
comment?: string;
|
|
14
17
|
secondaryEntity: EntityDecl;
|
|
15
|
-
type: Lazy<
|
|
18
|
+
type: Lazy<PossibleType<T>>;
|
|
16
19
|
}
|
|
17
20
|
type TSerializedConstraint = Record<string, SerializedMemberDecl>;
|
|
18
21
|
export interface SerializedNestedEntityMapType<Name extends string = string, T extends TSerializedConstraint = TSerializedConstraint> extends SerializedBaseType {
|
|
@@ -20,13 +23,13 @@ export interface SerializedNestedEntityMapType<Name extends string = string, T e
|
|
|
20
23
|
name: Name;
|
|
21
24
|
comment?: string;
|
|
22
25
|
secondaryEntity: string;
|
|
23
|
-
type: SerializedObjectType<T
|
|
26
|
+
type: SerializedObjectType<T> | SerializedIncludeIdentifierType;
|
|
24
27
|
}
|
|
25
28
|
export declare const NestedEntityMapType: <Name extends string, T extends TConstraint>(options: {
|
|
26
29
|
name: Name;
|
|
27
30
|
comment?: string;
|
|
28
31
|
secondaryEntity: EntityDecl;
|
|
29
|
-
type:
|
|
32
|
+
type: PossibleType<T>;
|
|
30
33
|
}) => NestedEntityMapType<Name, T>;
|
|
31
34
|
export { NestedEntityMapType as NestedEntityMap };
|
|
32
35
|
export declare const isNestedEntityMapType: (node: Node) => node is NestedEntityMapType;
|
|
@@ -3,9 +3,11 @@ import { sortObjectKeysAlphabetically } from "../../../../shared/utils/object.js
|
|
|
3
3
|
import { parallelizeErrors } from "../../../../shared/utils/validation.js";
|
|
4
4
|
import { wrapErrorsIfAny } from "../../../utils/error.js";
|
|
5
5
|
import { entity, json, key as keyColor } from "../../../utils/errorFormatting.js";
|
|
6
|
+
import { getNestedDeclarations, } from "../../declarations/Declaration.js";
|
|
6
7
|
import { NodeKind } from "../../Node.js";
|
|
7
|
-
import {
|
|
8
|
-
import { formatValue, removeParentKey, setParent } from "../Type.js";
|
|
8
|
+
import { getReferencesForObjectType, isObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, } from "../generic/ObjectType.js";
|
|
9
|
+
import { formatValue, removeParentKey, setParent, validate } from "../Type.js";
|
|
10
|
+
import { formatIncludeIdentifierValue, getReferencesForIncludeIdentifierType, resolveTypeArgumentsInIncludeIdentifierType, serializeIncludeIdentifierType, } from "./IncludeIdentifierType.js";
|
|
9
11
|
export const NestedEntityMapType = (options) => {
|
|
10
12
|
const nestedEntityMapType = {
|
|
11
13
|
...options,
|
|
@@ -24,30 +26,38 @@ const _NestedEntityMapType = (options) => {
|
|
|
24
26
|
return nestedEntityMapType;
|
|
25
27
|
};
|
|
26
28
|
export const isNestedEntityMapType = (node) => node.kind === NodeKind.NestedEntityMapType;
|
|
27
|
-
export const getNestedDeclarationsInNestedEntityMapType = (addedDecls, type) =>
|
|
29
|
+
export const getNestedDeclarationsInNestedEntityMapType = (addedDecls, type) => getNestedDeclarations(addedDecls.includes(type.secondaryEntity) ? addedDecls : [type.secondaryEntity, ...addedDecls], type.type.value);
|
|
28
30
|
export const validateNestedEntityMapType = (helpers, type, value) => {
|
|
29
31
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
30
32
|
return [TypeError(`expected an object, but got ${json(value, helpers.useStyling)}`)];
|
|
31
33
|
}
|
|
32
|
-
return parallelizeErrors(Object.keys(value).map(key => wrapErrorsIfAny(`at nested entity map ${entity(`"${type.name}"`, helpers.useStyling)} at key ${keyColor(`"${key}"`, helpers.useStyling)}`,
|
|
34
|
+
return parallelizeErrors(Object.keys(value).map(key => wrapErrorsIfAny(`at nested entity map ${entity(`"${type.name}"`, helpers.useStyling)} at key ${keyColor(`"${key}"`, helpers.useStyling)}`, validate(helpers, type.type.value, value[key]).concat(helpers.checkReferentialIntegrity({
|
|
33
35
|
name: type.secondaryEntity.name,
|
|
34
36
|
value: key,
|
|
35
37
|
})))));
|
|
36
38
|
};
|
|
37
39
|
export const resolveTypeArgumentsInNestedEntityMapType = (args, type) => _NestedEntityMapType({
|
|
38
40
|
...type,
|
|
39
|
-
type: () =>
|
|
41
|
+
type: () => isObjectType(type.type.value)
|
|
42
|
+
? resolveTypeArgumentsInObjectType(args, type.type.value)
|
|
43
|
+
: resolveTypeArgumentsInIncludeIdentifierType(args, type.type.value),
|
|
40
44
|
});
|
|
41
45
|
export const serializeNestedEntityMapType = type => ({
|
|
42
46
|
...removeParentKey(type),
|
|
43
47
|
secondaryEntity: type.secondaryEntity.name,
|
|
44
|
-
type:
|
|
48
|
+
type: isObjectType(type.type.value)
|
|
49
|
+
? serializeObjectType(type.type.value)
|
|
50
|
+
: serializeIncludeIdentifierType(type.type.value),
|
|
45
51
|
});
|
|
46
52
|
export const getReferencesForNestedEntityMapType = (type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
47
53
|
? Object.values(value)
|
|
48
|
-
.flatMap(item =>
|
|
54
|
+
.flatMap(item => isObjectType(type.type.value)
|
|
55
|
+
? getReferencesForObjectType(type.type.value, item)
|
|
56
|
+
: getReferencesForIncludeIdentifierType(type.type.value, item))
|
|
49
57
|
.concat(Object.keys(value))
|
|
50
58
|
: [];
|
|
51
|
-
export const formatNestedEntityMapValue = (type, value) =>
|
|
52
|
-
?
|
|
53
|
-
|
|
59
|
+
export const formatNestedEntityMapValue = (type, value) => isObjectType(type.type.value)
|
|
60
|
+
? typeof value === "object" && value !== null && !Array.isArray(value)
|
|
61
|
+
? sortObjectKeysAlphabetically(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, formatValue(type.type.value, item)])))
|
|
62
|
+
: value
|
|
63
|
+
: formatIncludeIdentifierValue(type.type.value, value);
|