@routier/core 0.0.1-alpha.1

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 (168) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +91 -0
  3. package/rspack.config.mjs +65 -0
  4. package/src/assertions/index.ts +37 -0
  5. package/src/codegen/SlotPath.ts +20 -0
  6. package/src/codegen/blocks.ts +578 -0
  7. package/src/codegen/handlers/CloneHandlerBuilder.ts +13 -0
  8. package/src/codegen/handlers/CompareHandlerBuilder.ts +13 -0
  9. package/src/codegen/handlers/DeserializeHandlerBuilder.ts +20 -0
  10. package/src/codegen/handlers/EnableChangeTrackingHandlerBuilder.ts +13 -0
  11. package/src/codegen/handlers/EnrichmentHandlerBuilder.ts +28 -0
  12. package/src/codegen/handlers/FreezeHandlerBuilder.ts +13 -0
  13. package/src/codegen/handlers/HashHandlerBuilder.ts +25 -0
  14. package/src/codegen/handlers/HashTypeHandlerBuilder.ts +11 -0
  15. package/src/codegen/handlers/IdSelectorHandlerBuilder.ts +10 -0
  16. package/src/codegen/handlers/MergeHandlerBuilder.ts +19 -0
  17. package/src/codegen/handlers/PrepareHandlerBuilder.ts +23 -0
  18. package/src/codegen/handlers/SerializeHandlerBuilder.ts +15 -0
  19. package/src/codegen/handlers/StripHandlerBuilder.ts +18 -0
  20. package/src/codegen/handlers/clone/CloneObjectHandler.ts +29 -0
  21. package/src/codegen/handlers/clone/CloneValueHandler.ts +33 -0
  22. package/src/codegen/handlers/compare/CompareObjectHandler.ts +15 -0
  23. package/src/codegen/handlers/compare/CompareValueHandler.ts +27 -0
  24. package/src/codegen/handlers/deserialize/DeserializeComputedValueHandler.ts +16 -0
  25. package/src/codegen/handlers/deserialize/DeserializeDateHandler.ts +45 -0
  26. package/src/codegen/handlers/deserialize/DeserializeFunctionHandler.ts +16 -0
  27. package/src/codegen/handlers/deserialize/DeserializeObjectHandler.ts +29 -0
  28. package/src/codegen/handlers/deserialize/DeserializeValueHandler.ts +33 -0
  29. package/src/codegen/handlers/enableChangeTracking/EnableChangeTrackingObjectHandler.ts +20 -0
  30. package/src/codegen/handlers/enableChangeTracking/EnableChangeTrackingPrimitiveValueHandler.ts +15 -0
  31. package/src/codegen/handlers/enrichment/EnrichmentComputedValueHandler.ts +37 -0
  32. package/src/codegen/handlers/enrichment/EnrichmentDefaultFunctionHandler.ts +50 -0
  33. package/src/codegen/handlers/enrichment/EnrichmentDefaultValueHandler.ts +18 -0
  34. package/src/codegen/handlers/enrichment/EnrichmentFunctionHandler.ts +38 -0
  35. package/src/codegen/handlers/enrichment/EnrichmentNullableObjectHandler.ts +44 -0
  36. package/src/codegen/handlers/enrichment/EnrichmentObjectHandler.ts +29 -0
  37. package/src/codegen/handlers/enrichment/EnrichmentObjectIdentityHandler.ts +16 -0
  38. package/src/codegen/handlers/enrichment/EnrichmentPrimitiveHandler.ts +13 -0
  39. package/src/codegen/handlers/enrichment/EnrichmentPrimitiveIdentityHandler.ts +21 -0
  40. package/src/codegen/handlers/freeze/FreezeObjectHandler.ts +20 -0
  41. package/src/codegen/handlers/freeze/FreezePrimitiveValueHandler.ts +15 -0
  42. package/src/codegen/handlers/hash/HashComputedValueHandler.ts +15 -0
  43. package/src/codegen/handlers/hash/HashDateHandler.ts +26 -0
  44. package/src/codegen/handlers/hash/HashFunctionHandler.ts +16 -0
  45. package/src/codegen/handlers/hash/HashIdentityHandler.ts +15 -0
  46. package/src/codegen/handlers/hash/HashKeyHandler.ts +26 -0
  47. package/src/codegen/handlers/hash/HashValueHandler.ts +26 -0
  48. package/src/codegen/handlers/hashType/HashTypeValueHandler.ts +20 -0
  49. package/src/codegen/handlers/idSelector/IdSelectorValueHandler.ts +28 -0
  50. package/src/codegen/handlers/index.ts +13 -0
  51. package/src/codegen/handlers/merge/MergeComputedValueHandler.ts +37 -0
  52. package/src/codegen/handlers/merge/MergeDefaultFunctionHandler.ts +40 -0
  53. package/src/codegen/handlers/merge/MergeDefaultValueHandler.ts +32 -0
  54. package/src/codegen/handlers/merge/MergeFunctionHandler.ts +16 -0
  55. package/src/codegen/handlers/merge/MergePrimitiveHandler.ts +21 -0
  56. package/src/codegen/handlers/prepare/PrepareComputedValueHandler.ts +16 -0
  57. package/src/codegen/handlers/prepare/PrepareFunctionHandler.ts +16 -0
  58. package/src/codegen/handlers/prepare/PrepareIdentityHandler.ts +21 -0
  59. package/src/codegen/handlers/prepare/PrepareKeyHandler.ts +21 -0
  60. package/src/codegen/handlers/prepare/PrepareObjectHandler.ts +38 -0
  61. package/src/codegen/handlers/prepare/PrepareValueHandler.ts +36 -0
  62. package/src/codegen/handlers/serialize/SerializeDateHandler.ts +45 -0
  63. package/src/codegen/handlers/serialize/SerializeObjectHandler.ts +28 -0
  64. package/src/codegen/handlers/serialize/SerializeValueHandler.ts +33 -0
  65. package/src/codegen/handlers/strip/StripIdentityHandler.ts +15 -0
  66. package/src/codegen/handlers/strip/StripKeyHandler.ts +15 -0
  67. package/src/codegen/handlers/strip/StripObjectHandler.ts +35 -0
  68. package/src/codegen/handlers/strip/StripValueHandler.ts +36 -0
  69. package/src/codegen/handlers/types.ts +119 -0
  70. package/src/codegen/index.ts +2 -0
  71. package/src/codegen/types.ts +2 -0
  72. package/src/codegen/utils.ts +74 -0
  73. package/src/collections/Changes.test.ts +337 -0
  74. package/src/collections/Changes.ts +177 -0
  75. package/src/collections/IdSet.ts +28 -0
  76. package/src/collections/MemoryDataCollection.test.ts +424 -0
  77. package/src/collections/MemoryDataCollection.ts +134 -0
  78. package/src/collections/SchemaCollection.ts +22 -0
  79. package/src/collections/TagCollection.test.ts +443 -0
  80. package/src/collections/TagCollection.ts +62 -0
  81. package/src/collections/index.ts +5 -0
  82. package/src/errors/SchemaError.ts +6 -0
  83. package/src/errors/index.ts +1 -0
  84. package/src/expressions/index.ts +3 -0
  85. package/src/expressions/parser.test.ts +913 -0
  86. package/src/expressions/parser.ts +661 -0
  87. package/src/expressions/types.ts +184 -0
  88. package/src/expressions/utils.test.ts +346 -0
  89. package/src/expressions/utils.ts +59 -0
  90. package/src/index.ts +12 -0
  91. package/src/performance/index.ts +26 -0
  92. package/src/pipeline/SyncronousQueue.test.ts +269 -0
  93. package/src/pipeline/SyncronousQueue.ts +30 -0
  94. package/src/pipeline/TrampolinePipeline.test.ts +374 -0
  95. package/src/pipeline/TrampolinePipeline.ts +437 -0
  96. package/src/pipeline/index.ts +2 -0
  97. package/src/plugins/EphemeralDataPlugin.ts +132 -0
  98. package/src/plugins/capabilities/DbPluginCapability.ts +111 -0
  99. package/src/plugins/capabilities/index.ts +2 -0
  100. package/src/plugins/capabilities/logging/DbPluginLoggingCapability.ts +261 -0
  101. package/src/plugins/capabilities/logging/index.ts +1 -0
  102. package/src/plugins/index.ts +6 -0
  103. package/src/plugins/query/Query.ts +67 -0
  104. package/src/plugins/query/QueryOptionsCollection.test.ts +86 -0
  105. package/src/plugins/query/QueryOptionsCollection.ts +154 -0
  106. package/src/plugins/query/index.ts +3 -0
  107. package/src/plugins/query/types.ts +46 -0
  108. package/src/plugins/replication/OptimisticReplicationDbPlugin.ts +202 -0
  109. package/src/plugins/replication/ReplicationDbPlugin.ts +137 -0
  110. package/src/plugins/replication/index.ts +3 -0
  111. package/src/plugins/replication/types.ts +5 -0
  112. package/src/plugins/translators/DataTranslator.ts +46 -0
  113. package/src/plugins/translators/JsonTranslator.test.ts +618 -0
  114. package/src/plugins/translators/JsonTranslator.ts +211 -0
  115. package/src/plugins/translators/SqlTranslator.ts +45 -0
  116. package/src/plugins/translators/index.ts +3 -0
  117. package/src/plugins/types.ts +114 -0
  118. package/src/results/Result.ts +91 -0
  119. package/src/results/index.ts +3 -0
  120. package/src/results/types.ts +17 -0
  121. package/src/results/utils.ts +15 -0
  122. package/src/schema/PropertyInfo.test.ts +479 -0
  123. package/src/schema/PropertyInfo.ts +374 -0
  124. package/src/schema/SchemaDefinition.ts +626 -0
  125. package/src/schema/builder.ts +18 -0
  126. package/src/schema/index.ts +7 -0
  127. package/src/schema/property/base/SchemaBase.ts +49 -0
  128. package/src/schema/property/base/index.ts +1 -0
  129. package/src/schema/property/modifiers/SchemaDefault.ts +29 -0
  130. package/src/schema/property/modifiers/SchemaDeserialize.ts +23 -0
  131. package/src/schema/property/modifiers/SchemaDistinct.ts +14 -0
  132. package/src/schema/property/modifiers/SchemaFrom.ts +54 -0
  133. package/src/schema/property/modifiers/SchemaIdentity.ts +13 -0
  134. package/src/schema/property/modifiers/SchemaIndex.ts +60 -0
  135. package/src/schema/property/modifiers/SchemaKey.ts +28 -0
  136. package/src/schema/property/modifiers/SchemaNullable.ts +18 -0
  137. package/src/schema/property/modifiers/SchemaOptional.ts +19 -0
  138. package/src/schema/property/modifiers/SchemaReadonly.ts +34 -0
  139. package/src/schema/property/modifiers/SchemaSerialize.ts +18 -0
  140. package/src/schema/property/modifiers/SchemaTracked.ts +14 -0
  141. package/src/schema/property/modifiers/index.ts +12 -0
  142. package/src/schema/property/types/SchemaArray.ts +50 -0
  143. package/src/schema/property/types/SchemaBoolean.ts +59 -0
  144. package/src/schema/property/types/SchemaDate.ts +58 -0
  145. package/src/schema/property/types/SchemaNumber.ts +69 -0
  146. package/src/schema/property/types/SchemaObject.ts +44 -0
  147. package/src/schema/property/types/SchemaString.ts +69 -0
  148. package/src/schema/property/types/index.ts +6 -0
  149. package/src/schema/table/SchemaComputed.ts +20 -0
  150. package/src/schema/table/SchemaFunction.ts +15 -0
  151. package/src/schema/table/index.ts +2 -0
  152. package/src/schema/types.ts +238 -0
  153. package/src/types/index.ts +5 -0
  154. package/src/utilities/arrays.test.ts +312 -0
  155. package/src/utilities/arrays.ts +12 -0
  156. package/src/utilities/dates.test.ts +388 -0
  157. package/src/utilities/dates.ts +11 -0
  158. package/src/utilities/dbPluginEventUtils.ts +44 -0
  159. package/src/utilities/index.ts +10 -0
  160. package/src/utilities/objects.ts +7 -0
  161. package/src/utilities/queryOptionsCollection.ts +16 -0
  162. package/src/utilities/replication.ts +23 -0
  163. package/src/utilities/runtime.ts +3 -0
  164. package/src/utilities/strings.ts +18 -0
  165. package/src/utilities/types.ts +1 -0
  166. package/src/utilities/uuid.ts +56 -0
  167. package/tsconfig.json +28 -0
  168. package/vitest.config.ts +11 -0
@@ -0,0 +1,44 @@
1
+ import { DefaultValue, SchemaModifiers, SchemaTypes } from "../../types";
2
+ import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaDefault } from "../modifiers/SchemaDefault";
4
+ import { SchemaFrom } from "../modifiers/SchemaFrom";
5
+ import { SchemaIdentity } from "../modifiers/SchemaIdentity";
6
+ import { SchemaNullable } from "../modifiers/SchemaNullable";
7
+ import { SchemaOptional } from "../modifiers/SchemaOptional";
8
+ import { SchemaArray } from "./SchemaArray";
9
+
10
+ export class SchemaObject<T extends {}, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
11
+
12
+ instance: T;
13
+ type = SchemaTypes.Object;
14
+ private _schemaObject = true;
15
+
16
+ constructor(schema: T) {
17
+ super();
18
+ this.instance = schema;
19
+ }
20
+
21
+ from(propertyName: string) {
22
+ return new SchemaFrom<T, TModifiers>(propertyName, this);
23
+ }
24
+
25
+ optional() {
26
+ return new SchemaOptional<T, TModifiers | "optional">(this);
27
+ }
28
+
29
+ nullable() {
30
+ return new SchemaNullable<T, TModifiers | "nullable">(this);
31
+ }
32
+
33
+ default<I = never>(value: DefaultValue<T, I>, injected?: I) {
34
+ return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
35
+ }
36
+
37
+ identity() {
38
+ return new SchemaIdentity<T, TModifiers | "identity" | "readonly">(this);
39
+ }
40
+
41
+ array() {
42
+ return new SchemaArray<typeof this, TModifiers>(this as any);
43
+ }
44
+ }
@@ -0,0 +1,69 @@
1
+ import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
2
+ import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaDefault } from "../modifiers/SchemaDefault";
4
+ import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
5
+ import { SchemaDistinct } from "../modifiers/SchemaDistinct";
6
+ import { SchemaFrom } from "../modifiers/SchemaFrom";
7
+ import { SchemaIdentity } from "../modifiers/SchemaIdentity";
8
+ import { SchemaIndex } from "../modifiers/SchemaIndex";
9
+ import { SchemaKey } from "../modifiers/SchemaKey";
10
+ import { SchemaNullable } from "../modifiers/SchemaNullable";
11
+ import { SchemaOptional } from "../modifiers/SchemaOptional";
12
+ import { SchemaReadonly } from "../modifiers/SchemaReadonly";
13
+ import { SchemaSerialize } from "../modifiers/SchemaSerialize";
14
+ import { SchemaArray } from "./SchemaArray";
15
+
16
+ export class SchemaString<T extends string, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
17
+
18
+ instance: T;
19
+ type = SchemaTypes.String;
20
+ private _schemaString = true;
21
+
22
+ from(propertyName: string) {
23
+ return new SchemaFrom<T, TModifiers>(propertyName, this);
24
+ }
25
+
26
+ optional() {
27
+ return new SchemaOptional<T, TModifiers | "optional">(this);
28
+ }
29
+
30
+ nullable() {
31
+ return new SchemaNullable<T, TModifiers | "nullable">(this);
32
+ }
33
+
34
+ key() {
35
+ return new SchemaKey<T, TModifiers | "key">(this);
36
+ }
37
+
38
+ default<I = never>(value: DefaultValue<T, I>, injected?: I) {
39
+ return new SchemaDefault<T, I, TModifiers | "default">(value, injected, this);
40
+ }
41
+
42
+ readonly() {
43
+ return new SchemaReadonly<T, TModifiers | "readonly">(this);
44
+ }
45
+
46
+ deserialize(deserializer: PropertyDeserializer<T>) {
47
+ return new SchemaDeserialize<T, TModifiers | "deserialize">(deserializer, this);
48
+ }
49
+
50
+ serialize(serializer: PropertySerializer<T>) {
51
+ return new SchemaSerialize<T, TModifiers | "serialize">(serializer, this);
52
+ }
53
+
54
+ identity() {
55
+ return new SchemaIdentity<T, TModifiers | "identity" | "readonly">(this);
56
+ }
57
+
58
+ array() {
59
+ return new SchemaArray<typeof this, TModifiers>(this as any);
60
+ }
61
+
62
+ index(...indexes: string[]) {
63
+ return new SchemaIndex<T, TModifiers>(this as any, ...indexes);
64
+ }
65
+
66
+ distinct() {
67
+ return new SchemaDistinct<T, TModifiers | "distinct">(this);
68
+ }
69
+ }
@@ -0,0 +1,6 @@
1
+ export * from './SchemaArray';
2
+ export * from './SchemaBoolean';
3
+ export * from './SchemaDate';
4
+ export * from './SchemaNumber';
5
+ export * from './SchemaObject';
6
+ export * from './SchemaString';
@@ -0,0 +1,20 @@
1
+ import { SchemaBase } from "../property/base/SchemaBase";
2
+ import { SchemaTracked } from '../property/modifiers/SchemaTracked';
3
+ import { SchemaModifiers, SchemaTypes } from "../types";
4
+
5
+ export class SchemaComputed<T extends any, I, TModifiers extends SchemaModifiers = "computed"> extends SchemaBase<T, TModifiers> {
6
+ instance: T;
7
+ type = SchemaTypes.Computed;
8
+ private _schemaComputed = true;
9
+
10
+ constructor(fn: T, injected: I, current?: SchemaBase<T, TModifiers>) {
11
+ super(current);
12
+ this.injected = injected;
13
+ this.isUnmapped = true;
14
+ this.functionBody = fn as any;
15
+ }
16
+
17
+ tracked() {
18
+ return new SchemaTracked<T, TModifiers>(this);
19
+ }
20
+ }
@@ -0,0 +1,15 @@
1
+ import { SchemaBase } from "../property/base/SchemaBase";
2
+ import { SchemaModifiers, SchemaTypes } from "../types";
3
+
4
+ export class SchemaFunction<T extends any, I, TModifiers extends SchemaModifiers = "unmapped"> extends SchemaBase<() => T, TModifiers> {
5
+ instance: () => T;
6
+ type = SchemaTypes.Function;
7
+ private _schemaFunction = true;
8
+
9
+ constructor(fn: (injected: I) => T, injected: I, current?: SchemaBase<() => T, TModifiers>) {
10
+ super(current);
11
+ this.injected = injected;
12
+ this.isUnmapped = true;
13
+ this.functionBody = fn as any;
14
+ }
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from './SchemaComputed';
2
+ export * from './SchemaFunction';
@@ -0,0 +1,238 @@
1
+ import { SchemaDefinition } from "./SchemaDefinition";
2
+ import { SchemaBase } from "./property/base/SchemaBase";
3
+ import { SchemaArray } from "./property/types/SchemaArray";
4
+ import { SchemaObject } from "./property/types/SchemaObject";
5
+ import { PropertyInfo } from "./PropertyInfo";
6
+ import { DeepPartial } from "../types";
7
+ import { SchemaFunction } from "./table";
8
+
9
+ export type DefaultValue<T, I = never> = T | ((injected: I) => T);
10
+ export type FunctionBody<TEntity, TResult> = (entity: TEntity, collectionName: string) => TResult;
11
+ export type IdType = string | number;
12
+
13
+ export enum SchemaTypes {
14
+ Array = "Array",
15
+ Boolean = "Boolean",
16
+ Date = "Date",
17
+ Number = "Number",
18
+ Object = "Object",
19
+ String = "String",
20
+ Definition = "Definition",
21
+ Function = "Function",
22
+ Computed = "Computed"
23
+ }
24
+
25
+ export type ArrayShape = string | number | Date | {};
26
+
27
+ export type ExpandedProperty = ExpandedChildProperty & {
28
+ assignmentPath: string;
29
+ selectorPath: string;
30
+ properties: Map<string, ExpandedChildProperty>;
31
+ childDegree: number;
32
+ };
33
+
34
+ export type ExpandedChildProperty = {
35
+ propertyName: string;
36
+ type: SchemaTypes;
37
+ isNullableOrOptional: boolean;
38
+ isReadonly: boolean;
39
+ isIdentity: boolean;
40
+ isUnmapped: boolean;
41
+ }
42
+
43
+ export enum HashType {
44
+ Ids = "Ids",
45
+ Object = "Object"
46
+ }
47
+
48
+ export type HashFunction<TEntity extends {}> = {
49
+ (entity: InferCreateType<TEntity>, type: HashType.Object): string;
50
+ (entity: InferType<TEntity>, type: HashType.Ids): string;
51
+ }
52
+
53
+ export type GetHashTypeFunction<TEntity extends {}> = {
54
+ (entity: InferCreateType<TEntity>): HashType.Object;
55
+ (entity: InferType<TEntity>): HashType.Ids;
56
+ }
57
+
58
+ export type ChangeTrackingType = "proxy" | "diff" | "immutable";
59
+
60
+ export type IndexType = "single" | "compound" | "unique" | "primary-key"
61
+ export type Index = {
62
+ properties: PropertyInfo<any>[],
63
+ type: IndexType;
64
+ name: string;
65
+ }
66
+
67
+ /**
68
+ * Represents changes to subscriptions, categorizing them by modifications to
69
+ * entities (additions, updates, removals) or query-driven removals.
70
+ * @template T - The type of the entities in the subscription.
71
+ */
72
+ export type SubscriptionChanges<T extends {}> = {
73
+ /**
74
+ * Entities that have been added to the subscription.
75
+ */
76
+ adds: InferType<T>[];
77
+ /**
78
+ * Entities that have been updated within the subscription.
79
+ */
80
+ updates: InferType<T>[];
81
+ /**
82
+ * Entities that have been removed from the subscription.
83
+ */
84
+ removals: InferType<T>[];
85
+ /**
86
+ * Entities that have been added/updated/removed from the subscription and it is unknown
87
+ * if the entities have been added/updated/removed.
88
+ */
89
+ unknown: InferType<T>[];
90
+ }
91
+
92
+ export interface ICollectionSubscription<T extends {}> extends Disposable {
93
+ send(changes: SubscriptionChanges<T>): void;
94
+ onMessage(callback: (changes: SubscriptionChanges<T>) => void): void;
95
+ }
96
+
97
+ type Enrich<TEntity extends {}> = {
98
+ (entity: InferType<TEntity>, changeTrackingType: ChangeTrackingType): InferType<TEntity>;
99
+ (entity: InferCreateType<TEntity>, changeTrackingType: ChangeTrackingType): InferCreateType<TEntity>;
100
+ }
101
+
102
+ /**
103
+ * Represents a fully compiled schema with all utilities and metadata for an entity type.
104
+ */
105
+ export type CompiledSchema<TEntity extends {}> = {
106
+
107
+ deserializePartial: (item: Record<string, unknown>, properties: PropertyInfo<TEntity>[]) => DeepPartial<InferType<TEntity>>;
108
+
109
+ createSubscription: (abortSignal?: AbortSignal) => ICollectionSubscription<TEntity>;
110
+ /** Returns the property info for a given id (full path) */
111
+ getProperty: (id: string) => PropertyInfo<TEntity>;
112
+ /** Returns the ID of the given entity. */
113
+ getId: (entity: InferType<TEntity>) => IdType;
114
+ /** Returns a deep clone of the given entity. */
115
+ clone: (entity: InferType<TEntity>) => InferType<TEntity>;
116
+ /** Removes unmapped or extraneous properties from the entity. */
117
+ strip: (entity: InferType<TEntity>) => InferType<TEntity>;
118
+ /** Prepares a new entity for creation, applying defaults and transformations. */
119
+ prepare: (entity: InferCreateType<TEntity>) => InferCreateType<TEntity>;
120
+ /** Merges the source entity into the destination entity. */
121
+ merge: (destination: InferType<TEntity> | InferCreateType<TEntity>, source: InferType<TEntity>) => InferType<TEntity>;
122
+ /** Indicates if the schema has identity properties. */
123
+ hasIdentities: boolean;
124
+ /** List of properties that are identity keys. */
125
+ idProperties: PropertyInfo<TEntity>[];
126
+ /** All property metadata for the schema. */
127
+ properties: PropertyInfo<TEntity>[],
128
+ /** The hash type used for this schema. */
129
+ hashType: HashType;
130
+ /** Computes a hash for the given entity. */
131
+ hash: HashFunction<TEntity>;
132
+ /** Returns the hash type for the given entity. */
133
+ getHashType: GetHashTypeFunction<TEntity>;
134
+ /** Compares two entities for equality. */
135
+ compare: (a: InferType<TEntity>, fromDb: InferType<TEntity>) => boolean;
136
+ /** Deserializes an entity from storage format. */
137
+ deserialize: (entity: InferType<TEntity>) => InferType<TEntity>;
138
+ /** Serializes an entity to storage format. */
139
+ serialize: (entity: InferType<TEntity>) => InferType<TEntity>;
140
+ /** Unique id for the schema. */
141
+ id: SchemaId,
142
+ /** The name of the collection for this schema. */
143
+ collectionName: string;
144
+ /** Returns all IDs for the given entity (usually a single-element tuple). */
145
+ getIds: (entity: InferType<TEntity>) => [IdType];
146
+ /** Enriches the entity with change tracking or other metadata. */
147
+ enrich: Enrich<TEntity>;
148
+ /** Indicates if the schema has identity keys. */
149
+ hasIdentityKeys: boolean;
150
+ /** Returns a deeply frozen (immutable) version of the entity. */
151
+ freeze: (entity: InferType<TEntity>) => InferType<TEntity>;
152
+ /** Enables change tracking on the entity. */
153
+ enableChangeTracking: (entity: InferType<TEntity>) => InferType<TEntity>;
154
+ /** The schema definition object. */
155
+ definition: SchemaDefinition<TEntity>;
156
+ /** Returns all indexes defined for this schema. */
157
+ getIndexes: () => Index[];
158
+ }
159
+
160
+ export type PropertySerializer<T extends any> = (value: T) => string | number;
161
+ export type PropertyDeserializer<T extends any> = (value: string | number) => T;
162
+
163
+ export type SchemaId = number
164
+
165
+ export type SchemaModifiers = "default" | "deserialize" |
166
+ "identity" | "key" |
167
+ "nullable" | "optional" |
168
+ "readonly" | "serialize" |
169
+ "unmapped" | "computed" |
170
+ "distinct";
171
+ //SchemaFunction
172
+ type InferPrimitive<T> =
173
+ T extends SchemaArray<infer Y, infer __> ? InferPrimitive<Y>[]
174
+ : T extends SchemaObject<infer Obj, infer _> ?
175
+ { [K in keyof Obj]: InferPrimitive<Obj[K]> } : // Process nested objects
176
+ T extends SchemaFunction<infer F, infer __> ? F : T extends SchemaBase<infer X, infer _> ?
177
+ X : // Extract the primitive type
178
+ never;
179
+
180
+ export type InferType<T> = T extends CompiledSchema<infer R> ? InferCompiledSchema<R> : T extends {} ? InferCompiledSchema<T> : T;
181
+ export type InferCreateType<T> = T extends CompiledSchema<infer R> ? InferCompiledCreateSchema<R> : T extends {} ? InferCompiledCreateSchema<T> : unknown;
182
+ export type InferMappedType<T> = T extends SchemaBase<infer K, infer __> ? InferType<K> : InferCompiledSchema<T>;
183
+
184
+ type HasModifier<T, K extends keyof T, M extends SchemaModifiers> =
185
+ T[K] extends SchemaBase<any, infer Mods> ?
186
+ M extends Mods ? true : false :
187
+ false;
188
+
189
+ type IsPlainProperty<T, K extends keyof T> =
190
+ [
191
+ HasModifier<T, K, "readonly">,
192
+ HasModifier<T, K, "optional">,
193
+ HasModifier<T, K, "nullable">
194
+ ] extends [
195
+ false,
196
+ false,
197
+ false
198
+ ] ? true : false;
199
+
200
+ type IsPlainCreateProperty<T, K extends keyof T> =
201
+ [
202
+ HasModifier<T, K, "identity">,
203
+ HasModifier<T, K, "default">,
204
+ HasModifier<T, K, "computed">,
205
+ HasModifier<T, K, "unmapped">,
206
+ HasModifier<T, K, "optional">,
207
+ HasModifier<T, K, "nullable">
208
+ ] extends [
209
+ false,
210
+ false,
211
+ false,
212
+ false,
213
+ false,
214
+ false
215
+ ] ? true : false;
216
+
217
+ type InferCompiledSchema<T> = CoalesceEmpty<{
218
+ [K in keyof T as IsPlainProperty<T, K> extends true ? K : never]: InferPrimitive<T[K]>
219
+ }, {
220
+ readonly [K in keyof T as HasModifier<T, K, "readonly"> extends true ? K : never]: InferPrimitive<T[K]>
221
+ }, {
222
+ [K in keyof T as HasModifier<T, K, "optional"> extends true ? K : never]?: InferPrimitive<T[K]>
223
+ }, {
224
+ [K in keyof T as HasModifier<T, K, "nullable"> extends true ? K : never]: null | InferPrimitive<T[K]>
225
+ }>;
226
+
227
+ type InferCompiledCreateSchema<T> = CoalesceEmpty<{
228
+ [K in keyof T as IsPlainCreateProperty<T, K> extends true ? K : never]: InferPrimitive<T[K]>
229
+ }, {
230
+ [K in keyof T as HasModifier<T, K, "optional"> extends true ? K : never]?: InferPrimitive<T[K]>
231
+ }, {
232
+ [K in keyof T as HasModifier<T, K, "default"> extends true ? K : never]?: InferPrimitive<T[K]>
233
+ }, {
234
+ [K in keyof T as HasModifier<T, K, "nullable"> extends true ? K : never]: null | InferPrimitive<T[K]>
235
+ }>;
236
+
237
+ type IsEmptyObject<T> = keyof T extends never ? true : false;
238
+ type CoalesceEmpty<T1 extends {}, T2 extends {}, T3 extends {}, T4 extends {}> = (IsEmptyObject<T1> extends true ? {} : T1) & (IsEmptyObject<T2> extends true ? {} : T2) & (IsEmptyObject<T3> extends true ? {} : T3) & (IsEmptyObject<T4> extends true ? {} : T4);
@@ -0,0 +1,5 @@
1
+ export type DeepPartial<T> = T extends object ? {
2
+ [P in keyof T]?: DeepPartial<T[P]>;
3
+ } : T;
4
+
5
+ export type GenericFunction<T, R> = (value: T) => R;