tsondb 0.1.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/lib/ModelContainer.js +9 -7
  2. package/lib/Schema.js +1 -3
  3. package/lib/client/api.d.ts +14 -1
  4. package/lib/client/api.js +119 -0
  5. package/lib/client/components/Git.d.ts +2 -0
  6. package/lib/client/components/Git.js +116 -0
  7. package/lib/client/components/Layout.js +2 -1
  8. package/lib/client/components/typeInputs/ArrayTypeInput.js +3 -2
  9. package/lib/client/components/typeInputs/EnumTypeInput.d.ts +13 -0
  10. package/lib/client/components/typeInputs/{utils/EnumDeclField.js → EnumTypeInput.js} +13 -13
  11. package/lib/client/components/typeInputs/IncludeIdentifierTypeInput.js +1 -10
  12. package/lib/client/components/typeInputs/StringTypeInput.js +8 -5
  13. package/lib/client/components/typeInputs/TypeInput.js +3 -0
  14. package/lib/client/components/typeInputs/utils/Markdown.d.ts +6 -0
  15. package/lib/client/components/typeInputs/utils/Markdown.js +26 -0
  16. package/lib/client/hooks/useAPIResource.d.ts +1 -0
  17. package/lib/client/hooks/useAPIResource.js +2 -0
  18. package/lib/client/hooks/useMappedAPIResource.d.ts +1 -0
  19. package/lib/client/hooks/useMappedAPIResource.js +19 -0
  20. package/lib/client/routes/Entity.js +18 -24
  21. package/lib/client/routes/Home.js +3 -12
  22. package/lib/client/utils/typeSkeleton.js +10 -16
  23. package/lib/renderers/jsonschema/index.d.ts +1 -1
  24. package/lib/renderers/jsonschema/index.js +30 -7
  25. package/lib/renderers/jsonschema/render.d.ts +5 -1
  26. package/lib/renderers/jsonschema/render.js +43 -16
  27. package/lib/renderers/ts/index.d.ts +1 -1
  28. package/lib/renderers/ts/index.js +37 -6
  29. package/lib/renderers/ts/render.d.ts +2 -0
  30. package/lib/renderers/ts/render.js +59 -33
  31. package/lib/schema/Node.d.ts +2 -0
  32. package/lib/schema/Node.js +7 -1
  33. package/lib/schema/declarations/Declaration.d.ts +5 -3
  34. package/lib/schema/declarations/Declaration.js +14 -10
  35. package/lib/schema/declarations/EntityDecl.d.ts +6 -0
  36. package/lib/schema/declarations/EnumDecl.d.ts +11 -8
  37. package/lib/schema/declarations/EnumDecl.js +16 -68
  38. package/lib/schema/declarations/TypeAliasDecl.d.ts +4 -0
  39. package/lib/schema/declarations/TypeAliasDecl.js +1 -1
  40. package/lib/schema/index.d.ts +1 -0
  41. package/lib/schema/index.js +1 -0
  42. package/lib/schema/types/Type.d.ts +8 -2
  43. package/lib/schema/types/Type.js +57 -11
  44. package/lib/schema/types/generic/ArrayType.d.ts +2 -1
  45. package/lib/schema/types/generic/ArrayType.js +3 -2
  46. package/lib/schema/types/generic/EnumType.d.ts +38 -0
  47. package/lib/schema/types/generic/EnumType.js +96 -0
  48. package/lib/schema/types/generic/ObjectType.d.ts +6 -1
  49. package/lib/schema/types/generic/ObjectType.js +9 -4
  50. package/lib/schema/types/primitives/BooleanType.d.ts +2 -1
  51. package/lib/schema/types/primitives/BooleanType.js +1 -0
  52. package/lib/schema/types/primitives/DateType.d.ts +2 -1
  53. package/lib/schema/types/primitives/DateType.js +1 -0
  54. package/lib/schema/types/primitives/FloatType.d.ts +2 -1
  55. package/lib/schema/types/primitives/FloatType.js +1 -0
  56. package/lib/schema/types/primitives/IntegerType.d.ts +2 -1
  57. package/lib/schema/types/primitives/IntegerType.js +1 -0
  58. package/lib/schema/types/primitives/StringType.d.ts +2 -1
  59. package/lib/schema/types/primitives/StringType.js +1 -0
  60. package/lib/schema/types/references/GenericArgumentIdentifierType.d.ts +2 -1
  61. package/lib/schema/types/references/GenericArgumentIdentifierType.js +1 -0
  62. package/lib/schema/types/references/IncludeIdentifierType.d.ts +5 -3
  63. package/lib/schema/types/references/IncludeIdentifierType.js +18 -3
  64. package/lib/schema/types/references/NestedEntityMapType.d.ts +2 -1
  65. package/lib/schema/types/references/NestedEntityMapType.js +6 -13
  66. package/lib/schema/types/references/ReferenceIdentifierType.d.ts +6 -7
  67. package/lib/schema/types/references/ReferenceIdentifierType.js +5 -2
  68. package/lib/server/api/declarations.d.ts +1 -0
  69. package/lib/server/api/declarations.js +154 -0
  70. package/lib/server/api/git.d.ts +1 -0
  71. package/lib/server/api/git.js +174 -0
  72. package/lib/server/api/index.d.ts +1 -0
  73. package/lib/server/api/index.js +8 -0
  74. package/lib/server/api/instanceOperations.d.ts +6 -0
  75. package/lib/server/api/instanceOperations.js +82 -0
  76. package/lib/server/api/instances.d.ts +1 -0
  77. package/lib/server/api/instances.js +23 -0
  78. package/lib/server/index.d.ts +22 -1
  79. package/lib/server/index.js +11 -165
  80. package/lib/server/init.d.ts +5 -0
  81. package/lib/server/init.js +56 -0
  82. package/lib/shared/api.d.ts +12 -1
  83. package/lib/shared/utils/array.d.ts +19 -0
  84. package/lib/shared/utils/array.js +27 -0
  85. package/lib/shared/utils/git.d.ts +12 -0
  86. package/lib/shared/utils/git.js +98 -0
  87. package/lib/shared/utils/instances.d.ts +10 -0
  88. package/lib/shared/utils/instances.js +8 -1
  89. package/lib/shared/utils/markdown.d.ts +14 -0
  90. package/lib/shared/utils/markdown.js +42 -0
  91. package/lib/shared/utils/object.d.ts +1 -0
  92. package/lib/shared/utils/object.js +4 -0
  93. package/lib/shared/utils/string.d.ts +1 -0
  94. package/lib/shared/utils/string.js +9 -0
  95. package/lib/tsconfig.tsbuildinfo +1 -1
  96. package/lib/utils/git.d.ts +3 -0
  97. package/lib/utils/git.js +12 -0
  98. package/lib/utils/instances.d.ts +3 -2
  99. package/lib/utils/instances.js +9 -2
  100. package/lib/utils/path.d.ts +1 -0
  101. package/lib/utils/path.js +2 -0
  102. package/lib/utils/references.d.ts +7 -0
  103. package/lib/utils/references.js +40 -0
  104. package/lib/utils/render.d.ts +6 -1
  105. package/lib/utils/render.js +27 -1
  106. package/package.json +8 -2
  107. package/public/css/styles.css +238 -1
  108. package/lib/client/components/typeInputs/utils/EnumDeclField.d.ts +0 -13
  109. package/lib/server/instanceOperations.d.ts +0 -7
  110. package/lib/server/instanceOperations.js +0 -67
@@ -15,3 +15,4 @@ export const validateDateType = (_helpers, type, value) => {
15
15
  };
16
16
  export const serializeDateType = type => removeParentKey(type);
17
17
  export const getReferencesForDateType = (_type, _value) => [];
18
+ export const formatDateValue = (_type, value) => value;
@@ -1,7 +1,7 @@
1
1
  import { RangeBound } from "../../../shared/validation/number.js";
2
2
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
3
3
  import { Validator } from "../../validation/type.js";
4
- import { BaseType, SerializedBaseType } from "../Type.js";
4
+ import { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
5
5
  export interface FloatType extends BaseType {
6
6
  kind: NodeKind["FloatType"];
7
7
  minimum?: RangeBound;
@@ -24,3 +24,4 @@ export declare const isFloatType: (node: Node) => node is FloatType;
24
24
  export declare const validateFloatType: Validator<FloatType>;
25
25
  export declare const serializeFloatType: Serializer<FloatType, SerializedFloatType>;
26
26
  export declare const getReferencesForFloatType: GetReferences<FloatType>;
27
+ export declare const formatFloatValue: StructureFormatter<FloatType>;
@@ -15,3 +15,4 @@ export const validateFloatType = (_helpers, type, value) => {
15
15
  };
16
16
  export const serializeFloatType = type => removeParentKey(type);
17
17
  export const getReferencesForFloatType = (_type, _value) => [];
18
+ export const formatFloatValue = (_type, value) => value;
@@ -1,7 +1,7 @@
1
1
  import { RangeBound } from "../../../shared/validation/number.js";
2
2
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
3
3
  import { Validator } from "../../validation/type.js";
4
- import { BaseType, SerializedBaseType } from "../Type.js";
4
+ import { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
5
5
  export interface IntegerType extends BaseType {
6
6
  kind: NodeKind["IntegerType"];
7
7
  minimum?: RangeBound;
@@ -24,3 +24,4 @@ export declare const isIntegerType: (node: Node) => node is IntegerType;
24
24
  export declare const validateIntegerType: Validator<IntegerType>;
25
25
  export declare const serializeIntegerType: Serializer<IntegerType, SerializedIntegerType>;
26
26
  export declare const getReferencesForIntegerType: GetReferences<IntegerType>;
27
+ export declare const formatIntegerValue: StructureFormatter<IntegerType>;
@@ -19,3 +19,4 @@ export const validateIntegerType = (_helpers, type, value) => {
19
19
  };
20
20
  export const serializeIntegerType = type => removeParentKey(type);
21
21
  export const getReferencesForIntegerType = (_type, _value) => [];
22
+ export const formatIntegerValue = (_type, value) => value;
@@ -1,7 +1,7 @@
1
1
  import { StringConstraints } from "../../../shared/validation/string.js";
2
2
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
3
3
  import { Validator } from "../../validation/type.js";
4
- import { BaseType, SerializedBaseType } from "../Type.js";
4
+ import { BaseType, SerializedBaseType, StructureFormatter } from "../Type.js";
5
5
  export interface StringType extends BaseType, StringConstraints {
6
6
  kind: NodeKind["StringType"];
7
7
  pattern?: RegExp;
@@ -23,3 +23,4 @@ export declare const isStringType: (node: Node) => node is StringType;
23
23
  export declare const validateStringType: Validator<StringType>;
24
24
  export declare const serializeStringType: Serializer<StringType, SerializedStringType>;
25
25
  export declare const getReferencesForStringType: GetReferences<StringType>;
26
+ export declare const formatStringValue: StructureFormatter<StringType>;
@@ -18,3 +18,4 @@ export const serializeStringType = type => removeParentKey({
18
18
  pattern: type.pattern?.source,
19
19
  });
20
20
  export const getReferencesForStringType = (_type, _value) => [];
21
+ export const formatStringValue = (_type, value) => value;
@@ -1,7 +1,7 @@
1
1
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
2
2
  import { SerializedTypeParameter, TypeParameter } from "../../parameters/TypeParameter.js";
3
3
  import { Validator } from "../../validation/type.js";
4
- import { BaseType, SerializedBaseType, Type } from "../Type.js";
4
+ import { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
5
5
  type TConstraint = TypeParameter;
6
6
  export interface GenericArgumentIdentifierType<T extends TConstraint = TConstraint> extends BaseType {
7
7
  kind: NodeKind["GenericArgumentIdentifierType"];
@@ -19,3 +19,4 @@ export declare const validateGenericArgumentIdentifierType: Validator<GenericArg
19
19
  export declare const resolveTypeArgumentsInGenericArgumentIdentifierType: <T extends TConstraint, Args extends Record<string, Type>>(args: Args, type: GenericArgumentIdentifierType<T>) => Args[T["name"]];
20
20
  export declare const serializeGenericArgumentIdentifierType: Serializer<GenericArgumentIdentifierType, SerializedGenericArgumentIdentifierType>;
21
21
  export declare const getReferencesForGenericArgumentIdentifierType: GetReferences<GenericArgumentIdentifierType>;
22
+ export declare const formatGenericArgumentIdentifierValue: StructureFormatter<GenericArgumentIdentifierType>;
@@ -16,3 +16,4 @@ export const serializeGenericArgumentIdentifierType = type => ({
16
16
  argument: serializeTypeParameter(type.argument),
17
17
  });
18
18
  export const getReferencesForGenericArgumentIdentifierType = (_type, _value) => [];
19
+ export const formatGenericArgumentIdentifierValue = (_type, value) => value;
@@ -4,8 +4,9 @@ import { TypeAliasDecl } from "../../declarations/TypeAliasDecl.js";
4
4
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
5
5
  import { SerializedTypeParameter, TypeParameter } from "../../parameters/TypeParameter.js";
6
6
  import { Validator } from "../../validation/type.js";
7
- import { BaseType, SerializedBaseType, Type } from "../Type.js";
8
- type TConstraint<Params extends TypeParameter[]> = TypeAliasDecl<string, Type, Params> | EnumDecl<string, Record<string, Type | null>, Params>;
7
+ import { EnumCaseDecl } from "../generic/EnumType.js";
8
+ import { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
9
+ type TConstraint<Params extends TypeParameter[]> = TypeAliasDecl<string, Type, Params> | EnumDecl<string, Record<string, EnumCaseDecl>, Params>;
9
10
  export interface IncludeIdentifierType<Params extends TypeParameter[] = TypeParameter[], T extends TConstraint<Params> = TConstraint<Params>> extends BaseType {
10
11
  kind: NodeKind["IncludeIdentifierType"];
11
12
  reference: T;
@@ -23,6 +24,7 @@ export { IncludeIdentifierType as IncludeIdentifier };
23
24
  export declare const isIncludeIdentifierType: (node: Node) => node is IncludeIdentifierType;
24
25
  export declare const getNestedDeclarationsInIncludeIdentifierType: GetNestedDeclarations<IncludeIdentifierType>;
25
26
  export declare const validateIncludeIdentifierType: Validator<IncludeIdentifierType>;
26
- export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type: IncludeIdentifierType) => IncludeIdentifierType;
27
+ export declare const resolveTypeArgumentsInIncludeIdentifierType: (args: Record<string, Type>, type: IncludeIdentifierType) => Type;
27
28
  export declare const serializeIncludeIdentifierType: Serializer<IncludeIdentifierType, SerializedIncludeIdentifierType>;
28
29
  export declare const getReferencesForIncludeIdentifierType: GetReferences<IncludeIdentifierType>;
30
+ export declare const formatIncludeIdentifierValue: StructureFormatter<IncludeIdentifierType>;
@@ -1,6 +1,7 @@
1
1
  import { getNestedDeclarations, getReferencesForDecl, resolveTypeArgumentsInDecl, validateDecl, } from "../../declarations/Declaration.js";
2
2
  import { NodeKind } from "../../Node.js";
3
- import { removeParentKey, resolveTypeArgumentsInType, serializeType, } from "../Type.js";
3
+ import { formatEnumType } from "../generic/EnumType.js";
4
+ import { formatValue, removeParentKey, resolveTypeArgumentsInType, serializeType, } from "../Type.js";
4
5
  export const GenIncludeIdentifierType = (reference, args) => ({
5
6
  kind: NodeKind.IncludeIdentifierType,
6
7
  reference,
@@ -14,12 +15,26 @@ export const IncludeIdentifierType = (reference) => ({
14
15
  });
15
16
  export { IncludeIdentifierType as IncludeIdentifier };
16
17
  export const isIncludeIdentifierType = (node) => node.kind === NodeKind.IncludeIdentifierType;
17
- export const getNestedDeclarationsInIncludeIdentifierType = (isDeclAdded, type) => [type.reference, ...getNestedDeclarations(isDeclAdded, type.reference)];
18
+ export const getNestedDeclarationsInIncludeIdentifierType = (addedDecls, type) => addedDecls.includes(type.reference)
19
+ ? addedDecls
20
+ : getNestedDeclarations([type.reference, ...addedDecls], type.reference);
18
21
  export const validateIncludeIdentifierType = (helpers, type, value) => validateDecl(helpers, type.reference, type.args, value);
19
- export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => GenIncludeIdentifierType(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg)));
22
+ export const resolveTypeArgumentsInIncludeIdentifierType = (args, type) => type.args.length === 0
23
+ ? type
24
+ : resolveTypeArgumentsInDecl(type.reference, type.args.map(arg => resolveTypeArgumentsInType(args, arg))).type.value;
20
25
  export const serializeIncludeIdentifierType = type => ({
21
26
  ...removeParentKey(type),
22
27
  reference: type.reference.name,
23
28
  args: type.args.map(arg => serializeType(arg)),
24
29
  });
25
30
  export const getReferencesForIncludeIdentifierType = (type, value) => getReferencesForDecl(resolveTypeArgumentsInDecl(type.reference, type.args), value);
31
+ export const formatIncludeIdentifierValue = (type, value) => {
32
+ switch (type.reference.kind) {
33
+ case NodeKind.TypeAliasDecl:
34
+ return formatValue(type.reference.type.value, value);
35
+ case NodeKind.EnumDecl:
36
+ return formatEnumType(type.reference.type.value, value);
37
+ default:
38
+ return value;
39
+ }
40
+ };
@@ -4,7 +4,7 @@ import { EntityDecl } from "../../declarations/EntityDecl.js";
4
4
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
5
5
  import { Validator } from "../../validation/type.js";
6
6
  import { MemberDecl, ObjectType, SerializedMemberDecl, SerializedObjectType } from "../generic/ObjectType.js";
7
- import { BaseType, SerializedBaseType, SerializedType, Type } from "../Type.js";
7
+ import { BaseType, SerializedBaseType, SerializedType, StructureFormatter, Type } from "../Type.js";
8
8
  type TConstraint = Record<string, MemberDecl<Type, boolean>>;
9
9
  export interface NestedEntityMapType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
10
10
  kind: NodeKind["NestedEntityMapType"];
@@ -34,3 +34,4 @@ export declare const validateNestedEntityMapType: Validator<NestedEntityMapType>
34
34
  export declare const resolveTypeArgumentsInNestedEntityMapType: (args: Record<string, Type>, type: NestedEntityMapType) => NestedEntityMapType;
35
35
  export declare const serializeNestedEntityMapType: Serializer<NestedEntityMapType, SerializedNestedEntityMapType>;
36
36
  export declare const getReferencesForNestedEntityMapType: GetReferences<NestedEntityMapType>;
37
+ export declare const formatNestedEntityMapValue: StructureFormatter<NestedEntityMapType>;
@@ -1,22 +1,15 @@
1
+ import { sortObjectKeysAlphabetically } from "../../../shared/utils/object.js";
1
2
  import { parallelizeErrors } from "../../../shared/utils/validation.js";
2
3
  import { wrapErrorsIfAny } from "../../../utils/error.js";
3
4
  import { Lazy } from "../../../utils/lazy.js";
4
- import { isEntityDecl } from "../../declarations/EntityDecl.js";
5
5
  import { NodeKind } from "../../Node.js";
6
6
  import { getNestedDeclarationsInObjectType, getReferencesForObjectType, resolveTypeArgumentsInObjectType, serializeObjectType, validateObjectType, } from "../generic/ObjectType.js";
7
- import { getParentDecl, removeParentKey, } from "../Type.js";
7
+ import { removeParentKey, } from "../Type.js";
8
8
  export const NestedEntityMapType = (options) => {
9
9
  const nestedEntityMapType = {
10
10
  ...options,
11
11
  kind: NodeKind.NestedEntityMapType,
12
12
  type: Lazy.of(() => {
13
- const parentDecl = getParentDecl(nestedEntityMapType);
14
- if (!parentDecl) {
15
- throw new Error("Parent declaration not found");
16
- }
17
- if (!isEntityDecl(parentDecl)) {
18
- throw new Error(`Parent declaration "${parentDecl.name}" is not an entity declaration`);
19
- }
20
13
  const type = options.type;
21
14
  type.parent = nestedEntityMapType;
22
15
  return type;
@@ -38,10 +31,7 @@ const _NestedEntityMapType = (options) => {
38
31
  return nestedEntityMapType;
39
32
  };
40
33
  export const isNestedEntityMapType = (node) => node.kind === NodeKind.NestedEntityMapType;
41
- export const getNestedDeclarationsInNestedEntityMapType = (isDeclAdded, type) => [
42
- type.secondaryEntity,
43
- ...getNestedDeclarationsInObjectType(isDeclAdded, type.type.value),
44
- ];
34
+ export const getNestedDeclarationsInNestedEntityMapType = (addedDecls, type) => getNestedDeclarationsInObjectType(addedDecls.includes(type.secondaryEntity) ? addedDecls : [type.secondaryEntity, ...addedDecls], type.type.value);
45
35
  export const validateNestedEntityMapType = (helpers, type, value) => {
46
36
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
47
37
  return [TypeError(`expected an object, but got ${JSON.stringify(value)}`)];
@@ -65,3 +55,6 @@ export const getReferencesForNestedEntityMapType = (type, value) => typeof value
65
55
  .flatMap(item => getReferencesForObjectType(type.type.value, item))
66
56
  .concat(Object.keys(value))
67
57
  : [];
58
+ export const formatNestedEntityMapValue = (_type, value) => typeof value === "object" && value !== null && !Array.isArray(value)
59
+ ? sortObjectKeysAlphabetically(value)
60
+ : value;
@@ -2,22 +2,21 @@ import { GetNestedDeclarations } from "../../declarations/Declaration.js";
2
2
  import { EntityDecl } from "../../declarations/EntityDecl.js";
3
3
  import { GetReferences, Node, NodeKind, Serializer } from "../../Node.js";
4
4
  import { Validator } from "../../validation/type.js";
5
- import { MemberDecl, ObjectType } from "../generic/ObjectType.js";
6
- import { BaseType, SerializedBaseType, Type } from "../Type.js";
7
- type TConstraint = Record<string, MemberDecl<Type, boolean>>;
8
- export interface ReferenceIdentifierType<Name extends string = string, T extends TConstraint = TConstraint> extends BaseType {
5
+ import { BaseType, SerializedBaseType, StructureFormatter, Type } from "../Type.js";
6
+ export interface ReferenceIdentifierType extends BaseType {
9
7
  kind: NodeKind["ReferenceIdentifierType"];
10
- entity: EntityDecl<Name, ObjectType<T>>;
8
+ entity: EntityDecl;
11
9
  }
12
10
  export interface SerializedReferenceIdentifierType extends SerializedBaseType {
13
11
  kind: NodeKind["ReferenceIdentifierType"];
14
12
  entity: string;
15
13
  }
16
- export declare const ReferenceIdentifierType: <Name extends string, T extends TConstraint>(entity: EntityDecl<Name, ObjectType<T>>) => ReferenceIdentifierType<Name, T>;
14
+ export declare const ReferenceIdentifierType: (entity: EntityDecl) => ReferenceIdentifierType;
17
15
  export { ReferenceIdentifierType as ReferenceIdentifier };
18
16
  export declare const isReferenceIdentifierType: (node: Node) => node is ReferenceIdentifierType;
19
17
  export declare const getNestedDeclarationsInReferenceIdentifierType: GetNestedDeclarations<ReferenceIdentifierType>;
20
18
  export declare const validateReferenceIdentifierType: Validator<ReferenceIdentifierType>;
21
- export declare const resolveTypeArgumentsInReferenceIdentifierType: <Name extends string, T extends TConstraint, Args extends Record<string, Type>>(_args: Args, type: ReferenceIdentifierType<Name, T>) => ReferenceIdentifierType<Name, T>;
19
+ export declare const resolveTypeArgumentsInReferenceIdentifierType: <Args extends Record<string, Type>>(_args: Args, type: ReferenceIdentifierType) => ReferenceIdentifierType;
22
20
  export declare const serializeReferenceIdentifierType: Serializer<ReferenceIdentifierType, SerializedReferenceIdentifierType>;
23
21
  export declare const getReferencesForReferenceIdentifierType: GetReferences<ReferenceIdentifierType>;
22
+ export declare const formatReferenceIdentifierValue: StructureFormatter<ReferenceIdentifierType>;
@@ -1,14 +1,16 @@
1
1
  import { getNestedDeclarations } from "../../declarations/Declaration.js";
2
2
  import { createEntityIdentifierType } from "../../declarations/EntityDecl.js";
3
3
  import { NodeKind } from "../../Node.js";
4
- import { removeParentKey, validate } from "../Type.js";
4
+ import { removeParentKey, validate, } from "../Type.js";
5
5
  export const ReferenceIdentifierType = (entity) => ({
6
6
  kind: NodeKind.ReferenceIdentifierType,
7
7
  entity,
8
8
  });
9
9
  export { ReferenceIdentifierType as ReferenceIdentifier };
10
10
  export const isReferenceIdentifierType = (node) => node.kind === NodeKind.ReferenceIdentifierType;
11
- export const getNestedDeclarationsInReferenceIdentifierType = (isDeclAdded, type) => [type.entity, ...getNestedDeclarations(isDeclAdded, type.entity)];
11
+ export const getNestedDeclarationsInReferenceIdentifierType = (addedDecls, type) => addedDecls.includes(type.entity)
12
+ ? addedDecls
13
+ : getNestedDeclarations([...addedDecls, type.entity], type.entity);
12
14
  export const validateReferenceIdentifierType = (helpers, type, value) => validate(helpers, createEntityIdentifierType(), value).concat(helpers.checkReferentialIntegrity({
13
15
  name: type.entity.name,
14
16
  value: value,
@@ -19,3 +21,4 @@ export const serializeReferenceIdentifierType = type => ({
19
21
  entity: type.entity.name,
20
22
  });
21
23
  export const getReferencesForReferenceIdentifierType = (_type, value) => (typeof value === "string" ? [value] : []);
24
+ export const formatReferenceIdentifierValue = (_type, value) => value;
@@ -0,0 +1 @@
1
+ export declare const declarationsApi: import("express-serve-static-core").Router;
@@ -0,0 +1,154 @@
1
+ import Debug from "debug";
2
+ import express from "express";
3
+ import { serializeDecl } from "../../schema/declarations/Declaration.js";
4
+ import { isEntityDecl } from "../../schema/declarations/EntityDecl.js";
5
+ import { isEnumDecl } from "../../schema/declarations/EnumDecl.js";
6
+ import { isTypeAliasDecl } from "../../schema/declarations/TypeAliasDecl.js";
7
+ import { isOk } from "../../utils/result.js";
8
+ import { createInstance, deleteInstance, updateInstance } from "./instanceOperations.js";
9
+ const debug = Debug("tsondb:server:api:declarations");
10
+ export const declarationsApi = express.Router();
11
+ declarationsApi.use((req, _res, next) => {
12
+ debug(req.path);
13
+ next();
14
+ });
15
+ declarationsApi.get("/", (req, res) => {
16
+ let filteredEntities;
17
+ switch (req.query["kind"]) {
18
+ case "Entity":
19
+ filteredEntities = req.entities;
20
+ break;
21
+ case "TypeAlias":
22
+ filteredEntities = req.declarations.filter(isTypeAliasDecl);
23
+ break;
24
+ case "Enum":
25
+ filteredEntities = req.declarations.filter(isEnumDecl);
26
+ break;
27
+ default:
28
+ filteredEntities = req.declarations;
29
+ }
30
+ const body = {
31
+ declarations: filteredEntities.map(decl => ({
32
+ declaration: serializeDecl(decl),
33
+ instanceCount: req.instancesByEntityName[decl.name]?.length ?? 0,
34
+ })),
35
+ localeEntity: req.localeEntity?.name,
36
+ };
37
+ res.json(body);
38
+ });
39
+ declarationsApi.get("/:name", (req, res) => {
40
+ const decl = req.declarations.find(decl => decl.name === req.params.name);
41
+ if (decl === undefined) {
42
+ res.status(404).send(`Declaration "${req.params.name}" not found`);
43
+ return;
44
+ }
45
+ const body = {
46
+ declaration: serializeDecl(decl),
47
+ instanceCount: req.instancesByEntityName[decl.name]?.length ?? 0,
48
+ isLocaleEntity: decl === req.localeEntity,
49
+ };
50
+ res.json(body);
51
+ });
52
+ declarationsApi.get("/:name/instances", (req, res) => {
53
+ const decl = req.declarations.find(decl => decl.name === req.params.name);
54
+ if (decl === undefined) {
55
+ res.status(404).send(`Declaration "${req.params.name}" not found`);
56
+ return;
57
+ }
58
+ if (!isEntityDecl(decl)) {
59
+ res.status(400).send(`Declaration "${decl.name}" is not an entity`);
60
+ return;
61
+ }
62
+ const body = {
63
+ instances: req.instancesByEntityName[req.params.name] ?? [],
64
+ isLocaleEntity: decl === req.localeEntity,
65
+ };
66
+ res.json(body);
67
+ });
68
+ declarationsApi.post("/:name/instances", async (req, res) => {
69
+ const decl = req.declarations.find(decl => decl.name === req.params.name);
70
+ if (decl === undefined) {
71
+ res.status(404).send(`Declaration "${req.params.name}" not found`);
72
+ return;
73
+ }
74
+ if (!isEntityDecl(decl)) {
75
+ res.status(400).send(`Declaration "${decl.name}" is not an entity`);
76
+ return;
77
+ }
78
+ const result = await createInstance(req, req.params.name, req.body, req.query["id"]);
79
+ if (isOk(result)) {
80
+ const body = {
81
+ instance: result.value,
82
+ isLocaleEntity: decl === req.localeEntity,
83
+ };
84
+ res.json(body);
85
+ }
86
+ else {
87
+ res.status(result.error[0]).send(result.error[1]);
88
+ }
89
+ });
90
+ declarationsApi.get("/:name/instances/:id", (req, res) => {
91
+ const decl = req.declarations.find(decl => decl.name === req.params.name);
92
+ if (decl === undefined) {
93
+ res.status(404).send(`Declaration "${req.params.name}" not found`);
94
+ return;
95
+ }
96
+ if (!isEntityDecl(decl)) {
97
+ res.status(400).send(`Declaration "${decl.name}" is not an entity`);
98
+ return;
99
+ }
100
+ const instance = req.instancesByEntityName[decl.name]?.find(instance => instance.id === req.params.id);
101
+ if (instance === undefined) {
102
+ res.status(404).send(`Instance "${req.params.id}" not found`);
103
+ return;
104
+ }
105
+ const body = {
106
+ instance: instance,
107
+ isLocaleEntity: decl === req.localeEntity,
108
+ };
109
+ res.json(body);
110
+ });
111
+ declarationsApi.put("/:name/instances/:id", async (req, res) => {
112
+ const decl = req.declarations.find(decl => decl.name === req.params.name);
113
+ if (decl === undefined) {
114
+ res.status(404).send(`Declaration "${req.params.name}" not found`);
115
+ return;
116
+ }
117
+ if (!isEntityDecl(decl)) {
118
+ res.status(400).send(`Declaration "${decl.name}" is not an entity`);
119
+ return;
120
+ }
121
+ const result = await updateInstance(req, req.params.name, req.params.id, req.body);
122
+ if (isOk(result)) {
123
+ const body = {
124
+ instance: result.value,
125
+ isLocaleEntity: decl === req.localeEntity,
126
+ };
127
+ res.json(body);
128
+ }
129
+ else {
130
+ res.status(result.error[0]).send(result.error[1]);
131
+ }
132
+ });
133
+ declarationsApi.delete("/:name/instances/:id", async (req, res) => {
134
+ const decl = req.declarations.find(decl => decl.name === req.params.name);
135
+ if (decl === undefined) {
136
+ res.status(404).send(`Declaration "${req.params.name}" not found`);
137
+ return;
138
+ }
139
+ if (!isEntityDecl(decl)) {
140
+ res.status(400).send(`Declaration "${decl.name}" is not an entity`);
141
+ return;
142
+ }
143
+ const result = await deleteInstance(req, req.params.name, req.params.id);
144
+ if (isOk(result)) {
145
+ const body = {
146
+ instance: result.value,
147
+ isLocaleEntity: decl === req.localeEntity,
148
+ };
149
+ res.json(body);
150
+ }
151
+ else {
152
+ res.status(result.error[0]).send(result.error[1]);
153
+ }
154
+ });
@@ -0,0 +1 @@
1
+ export declare const gitApi: import("express-serve-static-core").Router;
@@ -0,0 +1,174 @@
1
+ import Debug from "debug";
2
+ import express from "express";
3
+ import { join } from "node:path";
4
+ import { serializeEntityDecl } from "../../schema/index.js";
5
+ import { hasFileChanges } from "../../shared/utils/git.js";
6
+ import { getInstanceContainerOverview } from "../../shared/utils/instances.js";
7
+ import { attachGitStatusToInstancesByEntityName } from "../../utils/instances.js";
8
+ import { reinit } from "../init.js";
9
+ const debug = Debug("tsondb:server:api:git");
10
+ export const gitApi = express.Router();
11
+ gitApi.use((req, res, next) => {
12
+ debug(req.path);
13
+ if (req.gitRoot === undefined) {
14
+ res.status(500).send("Git repository not found");
15
+ return;
16
+ }
17
+ next();
18
+ });
19
+ gitApi.get("/status", async (req, res) => {
20
+ const locales = (Array.isArray(req.query["locales"]) ? req.query["locales"] : [req.query["locales"]]).filter(locale => typeof locale === "string");
21
+ const status = await req.git.status();
22
+ attachGitStatusToInstancesByEntityName(req.instancesByEntityName, req.dataRoot, req.gitRoot, status);
23
+ const body = {
24
+ commitsAhead: status.ahead,
25
+ commitsBehind: status.behind,
26
+ instances: Object.fromEntries(Object.entries(req.instancesByEntityName).map(([entityName, instances]) => [
27
+ entityName,
28
+ instances
29
+ .filter(instance => hasFileChanges(instance.gitStatus))
30
+ .map(instance => getInstanceContainerOverview(serializeEntityDecl(req.entitiesByName[entityName]), instance, locales)),
31
+ ])),
32
+ };
33
+ res.json(body);
34
+ });
35
+ gitApi.post("/stage", async (req, res) => {
36
+ try {
37
+ await req.git.add(req.dataRoot);
38
+ res.status(200).send("Added all database files to index");
39
+ }
40
+ catch (error) {
41
+ debug(`${req.path}: ${error.message}`);
42
+ res.status(500).send("Adding all database files to index failed");
43
+ }
44
+ });
45
+ gitApi.post("/stage/:entityName", async (req, res) => {
46
+ try {
47
+ await req.git.add(join(req.dataRoot, req.params.entityName));
48
+ res.status(200).send(`Added all database files for entity ${req.params.entityName} to index`);
49
+ }
50
+ catch (error) {
51
+ debug(`${req.path}: ${error.message}`);
52
+ res
53
+ .status(500)
54
+ .send(`Adding all database files for entity ${req.params.entityName} to index failed`);
55
+ }
56
+ });
57
+ gitApi.post("/stage/:entityName/:instanceId", async (req, res) => {
58
+ try {
59
+ await req.git.add(join(req.dataRoot, req.params.entityName, `${req.params.instanceId}.json`));
60
+ res
61
+ .status(200)
62
+ .send(`Added database file ${req.params.instanceId} for entity ${req.params.entityName} to index`);
63
+ }
64
+ catch (error) {
65
+ debug(`${req.path}: ${error.message}`);
66
+ res
67
+ .status(500)
68
+ .send(`Adding database file ${req.params.instanceId} for entity ${req.params.entityName} to index failed`);
69
+ }
70
+ });
71
+ gitApi.post("/unstage", async (req, res) => {
72
+ try {
73
+ await req.git.reset(["HEAD", "--", req.dataRoot]);
74
+ res.status(200).send("Removed all database files to index");
75
+ }
76
+ catch (error) {
77
+ debug(`${req.path}: ${error.message}`);
78
+ res.status(500).send("Removing all database files to index failed");
79
+ }
80
+ });
81
+ gitApi.post("/unstage/:entityName", async (req, res) => {
82
+ try {
83
+ await req.git.reset(["HEAD", "--", join(req.dataRoot, req.params.entityName)]);
84
+ res.status(200).send(`Removed all database files for entity ${req.params.entityName} to index`);
85
+ }
86
+ catch (error) {
87
+ debug(`${req.path}: ${error.message}`);
88
+ res
89
+ .status(500)
90
+ .send(`Removing all database files for entity ${req.params.entityName} to index failed`);
91
+ }
92
+ });
93
+ gitApi.post("/unstage/:entityName/:instanceId", async (req, res) => {
94
+ try {
95
+ await req.git.reset([
96
+ "HEAD",
97
+ "--",
98
+ join(req.dataRoot, req.params.entityName, `${req.params.instanceId}.json`),
99
+ ]);
100
+ res
101
+ .status(200)
102
+ .send(`Removed database file ${req.params.instanceId} for entity ${req.params.entityName} to index`);
103
+ }
104
+ catch (error) {
105
+ debug(`${req.path}: ${error.message}`);
106
+ res
107
+ .status(500)
108
+ .send(`Removing database file ${req.params.instanceId} for entity ${req.params.entityName} to index failed`);
109
+ }
110
+ });
111
+ gitApi.post("/commit", async (req, res) => {
112
+ const message = req.body.message;
113
+ if (typeof message !== "string" || message.length === 0) {
114
+ res.status(400).send("Invalid commit message");
115
+ return;
116
+ }
117
+ try {
118
+ await req.git.commit(message);
119
+ res.status(200).send("Commit successful");
120
+ }
121
+ catch (error) {
122
+ res.status(500).send("Commit failed");
123
+ }
124
+ });
125
+ gitApi.post("/push", async (req, res) => {
126
+ try {
127
+ await req.git.push();
128
+ res.status(200).send("Push successful");
129
+ }
130
+ catch (error) {
131
+ res.status(500).send("Push failed");
132
+ }
133
+ });
134
+ gitApi.post("/pull", async (req, res) => {
135
+ try {
136
+ await req.git.pull();
137
+ res.status(200).send("Pull successful");
138
+ }
139
+ catch (error) {
140
+ res.status(500).send("Pull failed");
141
+ }
142
+ });
143
+ gitApi.get("/branch", async (req, res) => {
144
+ const branchSummary = await req.git.branchLocal();
145
+ const body = {
146
+ allBranches: branchSummary.all,
147
+ currentBranch: branchSummary.current,
148
+ };
149
+ res.json(body);
150
+ });
151
+ gitApi.post("/branch", async (req, res) => {
152
+ const branchName = req.body.branchName;
153
+ if (typeof branchName !== "string" || branchName.length === 0) {
154
+ res.status(400).send("Invalid branch name");
155
+ return;
156
+ }
157
+ try {
158
+ await req.git.checkoutLocalBranch(branchName);
159
+ await reinit(req);
160
+ res.status(200).send(`Creation of branch "${branchName}" successful`);
161
+ }
162
+ catch (error) {
163
+ res.status(500).send(`Creation of branch "${branchName}" failed`);
164
+ }
165
+ });
166
+ gitApi.post("/branch/:branchName", async (req, res) => {
167
+ try {
168
+ await req.git.checkout(req.params.branchName);
169
+ res.status(200).send(`Switch to branch "${req.params.branchName}" successful`);
170
+ }
171
+ catch (error) {
172
+ res.status(500).send(`Switch to branch "${req.params.branchName}" failed`);
173
+ }
174
+ });
@@ -0,0 +1 @@
1
+ export declare const api: import("express-serve-static-core").Router;
@@ -0,0 +1,8 @@
1
+ import express from "express";
2
+ import { declarationsApi } from "./declarations.js";
3
+ import { gitApi } from "./git.js";
4
+ import { instancesApi } from "./instances.js";
5
+ export const api = express.Router();
6
+ api.use("/declarations", declarationsApi);
7
+ api.use("/instances", instancesApi);
8
+ api.use("/git", gitApi);
@@ -0,0 +1,6 @@
1
+ import { InstanceContainer } from "../../shared/utils/instances.js";
2
+ import { Result } from "../../utils/result.js";
3
+ import { TSONDBRequestLocals } from "../index.js";
4
+ export declare const createInstance: (locals: TSONDBRequestLocals, entityName: string, instance: unknown, idQueryParam: unknown) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
5
+ export declare const updateInstance: (locals: TSONDBRequestLocals, entityName: string, instanceId: string, instance: unknown) => Promise<Result<InstanceContainer, [code: number, message: string]>>;
6
+ export declare const deleteInstance: (locals: TSONDBRequestLocals, entityName: string, instanceId: string) => Promise<Result<InstanceContainer, [code: number, message: string]>>;