@routier/core 0.2.0 → 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 (174) hide show
  1. package/LICENSE +21 -0
  2. package/{readme.md → README.md} +2 -2
  3. package/dist/assertions/index.cjs +191 -0
  4. package/dist/assertions/index.cjs.map +1 -0
  5. package/dist/assertions/index.d.ts +30 -0
  6. package/dist/assertions/index.js +94 -30
  7. package/dist/assertions/index.js.map +1 -1
  8. package/dist/capabilities/index.cjs +820 -0
  9. package/dist/capabilities/index.cjs.map +1 -0
  10. package/dist/capabilities/index.js +580 -545
  11. package/dist/capabilities/index.js.map +1 -1
  12. package/dist/codegen/handlers/CloneHandlerBuilder.d.ts +10 -1
  13. package/dist/codegen/handlers/SetHandlerBuilder.d.ts +4 -0
  14. package/dist/codegen/handlers/clone/CloneArrayHandler.d.ts +3 -0
  15. package/dist/codegen/handlers/clone/CloneDateHandler.d.ts +13 -0
  16. package/dist/codegen/handlers/clone/CloneValueHandler.d.ts +16 -0
  17. package/dist/codegen/handlers/compare/CompareComputedHandler.d.ts +10 -0
  18. package/dist/codegen/handlers/compare/CompareFunctionHandler.d.ts +10 -0
  19. package/dist/codegen/handlers/deserialize/DeserializeArrayHandler.d.ts +14 -0
  20. package/dist/codegen/handlers/enableChangeTracking/EnableChangeTrackingArrayHandler.d.ts +11 -0
  21. package/dist/codegen/handlers/enrichment/EnrichmentArrayHandler.d.ts +11 -0
  22. package/dist/codegen/handlers/freeze/FreezeArrayHandler.d.ts +6 -0
  23. package/dist/codegen/handlers/hash/HashArrayHandler.d.ts +10 -0
  24. package/dist/codegen/handlers/hash/HashFileHandler.d.ts +24 -0
  25. package/dist/codegen/handlers/hash/HashObjectHandler.d.ts +10 -0
  26. package/dist/codegen/handlers/hash/HashTransformHandler.d.ts +23 -0
  27. package/dist/codegen/handlers/index.d.ts +1 -0
  28. package/dist/codegen/handlers/merge/MergeArrayHandler.d.ts +20 -0
  29. package/dist/codegen/handlers/merge/MergeObjectHandler.d.ts +10 -0
  30. package/dist/codegen/handlers/serialize/SerializeArrayHandler.d.ts +19 -0
  31. package/dist/codegen/handlers/serialize/SerializeComputedHandler.d.ts +6 -0
  32. package/dist/codegen/handlers/set/SetComplexHandler.d.ts +6 -0
  33. package/dist/codegen/handlers/strip/StripComputedHandler.d.ts +10 -0
  34. package/dist/codegen/handlers/strip/StripFunctionHandler.d.ts +9 -0
  35. package/dist/codegen/handlers/types.d.ts +55 -1
  36. package/dist/codegen/index.cjs +618 -0
  37. package/dist/codegen/index.cjs.map +1 -0
  38. package/dist/codegen/index.js +100 -127
  39. package/dist/codegen/index.js.map +1 -1
  40. package/dist/collections/Changes.d.ts +2 -2
  41. package/dist/collections/MemoryDataCollection.d.ts +15 -1
  42. package/dist/collections/TagCollection.d.ts +7 -8
  43. package/dist/collections/index.cjs +702 -0
  44. package/dist/collections/index.cjs.map +1 -0
  45. package/dist/collections/index.js +282 -276
  46. package/dist/collections/index.js.map +1 -1
  47. package/dist/errors/OptimisticConcurrencyError.d.ts +18 -0
  48. package/dist/errors/PluginDestroyedError.d.ts +10 -0
  49. package/dist/errors/index.cjs +132 -0
  50. package/dist/errors/index.cjs.map +1 -0
  51. package/dist/errors/index.d.ts +2 -0
  52. package/dist/errors/index.js +61 -19
  53. package/dist/errors/index.js.map +1 -1
  54. package/dist/expressions/constants.d.ts +2 -0
  55. package/dist/expressions/evaluate.d.ts +53 -0
  56. package/dist/expressions/index.cjs +2087 -0
  57. package/dist/expressions/index.cjs.map +1 -0
  58. package/dist/expressions/index.d.ts +2 -0
  59. package/dist/expressions/index.js +1784 -772
  60. package/dist/expressions/index.js.map +1 -1
  61. package/dist/expressions/parser.d.ts +19 -0
  62. package/dist/expressions/types.d.ts +87 -2
  63. package/dist/expressions/utils.d.ts +1 -2
  64. package/dist/index.cjs +13925 -0
  65. package/dist/index.cjs.map +1 -0
  66. package/dist/index.js +12094 -7049
  67. package/dist/index.js.map +1 -1
  68. package/dist/performance/index.cjs +217 -0
  69. package/dist/performance/index.cjs.map +1 -0
  70. package/dist/performance/index.js +126 -50
  71. package/dist/performance/index.js.map +1 -1
  72. package/dist/pipeline/index.cjs +576 -0
  73. package/dist/pipeline/index.cjs.map +1 -0
  74. package/dist/pipeline/index.js +229 -156
  75. package/dist/pipeline/index.js.map +1 -1
  76. package/dist/plugins/BatchingDbPlugin.d.ts +139 -0
  77. package/dist/plugins/CacheDbPlugin.d.ts +70 -0
  78. package/dist/plugins/ConcurrencyDbPlugin.d.ts +78 -0
  79. package/dist/plugins/EphemeralDataPlugin.d.ts +57 -1
  80. package/dist/plugins/RetryDbPlugin.d.ts +77 -0
  81. package/dist/plugins/index.cjs +6104 -0
  82. package/dist/plugins/index.cjs.map +1 -0
  83. package/dist/plugins/index.d.ts +5 -1
  84. package/dist/plugins/index.js +5572 -1491
  85. package/dist/plugins/index.js.map +1 -1
  86. package/dist/plugins/query/QueryOptionsCollection.d.ts +22 -0
  87. package/dist/plugins/query/index.d.ts +2 -0
  88. package/dist/plugins/query/join.d.ts +210 -0
  89. package/dist/plugins/query/similarity.d.ts +38 -0
  90. package/dist/plugins/query/types.d.ts +64 -1
  91. package/dist/plugins/translators/DataTranslator.d.ts +28 -0
  92. package/dist/plugins/translators/JsonTranslator.d.ts +27 -0
  93. package/dist/plugins/translators/SqlTranslator.d.ts +45 -0
  94. package/dist/plugins/translators/TranslatedArrayValue.d.ts +3 -1
  95. package/dist/plugins/translators/TranslatedGroupValue.d.ts +3 -1
  96. package/dist/plugins/translators/TranslatedSingleValue.d.ts +3 -1
  97. package/dist/plugins/translators/TupleTranslator.d.ts +45 -0
  98. package/dist/plugins/translators/index.d.ts +1 -0
  99. package/dist/plugins/translators/types.d.ts +8 -1
  100. package/dist/plugins/types.d.ts +87 -11
  101. package/dist/plugins/wire/handler.d.ts +122 -0
  102. package/dist/plugins/wire/index.d.ts +4 -0
  103. package/dist/plugins/wire/persist.d.ts +43 -0
  104. package/dist/plugins/wire/query.d.ts +49 -0
  105. package/dist/plugins/wire/types.d.ts +123 -0
  106. package/dist/results/Result.d.ts +2 -2
  107. package/dist/results/index.cjs +174 -0
  108. package/dist/results/index.cjs.map +1 -0
  109. package/dist/results/index.js +29 -44
  110. package/dist/results/index.js.map +1 -1
  111. package/dist/schema/PropertyInfo.d.ts +35 -2
  112. package/dist/schema/SchemaDefinition.d.ts +51 -1
  113. package/dist/schema/builder.d.ts +35 -1
  114. package/dist/schema/communication/broadcast.d.ts +17 -1
  115. package/dist/schema/index.cjs +6911 -0
  116. package/dist/schema/index.cjs.map +1 -0
  117. package/dist/schema/index.d.ts +4 -0
  118. package/dist/schema/index.js +5781 -3973
  119. package/dist/schema/index.js.map +1 -1
  120. package/dist/schema/property/base/SchemaBase.d.ts +50 -2
  121. package/dist/schema/property/modifiers/SchemaDeserialize.d.ts +5 -1
  122. package/dist/schema/property/modifiers/SchemaForeignKey.d.ts +15 -0
  123. package/dist/schema/property/modifiers/SchemaKey.d.ts +2 -0
  124. package/dist/schema/property/modifiers/SchemaNullable.d.ts +15 -1
  125. package/dist/schema/property/modifiers/SchemaOptional.d.ts +22 -1
  126. package/dist/schema/property/modifiers/SchemaSearchable.d.ts +34 -0
  127. package/dist/schema/property/modifiers/SchemaTag.d.ts +27 -0
  128. package/dist/schema/property/modifiers/SchemaTracked.d.ts +5 -1
  129. package/dist/schema/property/modifiers/index.d.ts +3 -0
  130. package/dist/schema/property/types/SchemaArray.d.ts +2 -0
  131. package/dist/schema/property/types/SchemaBoolean.d.ts +2 -0
  132. package/dist/schema/property/types/SchemaDate.d.ts +2 -0
  133. package/dist/schema/property/types/SchemaFile.d.ts +60 -0
  134. package/dist/schema/property/types/SchemaNumber.d.ts +5 -1
  135. package/dist/schema/property/types/SchemaObject.d.ts +2 -0
  136. package/dist/schema/property/types/SchemaString.d.ts +25 -1
  137. package/dist/schema/property/types/SchemaVector.d.ts +61 -0
  138. package/dist/schema/property/types/index.d.ts +2 -0
  139. package/dist/schema/table/SchemaTransform.d.ts +40 -0
  140. package/dist/schema/table/index.d.ts +1 -0
  141. package/dist/schema/types.d.ts +200 -32
  142. package/dist/schema/utils/propertyKind.d.ts +4 -0
  143. package/dist/schema/utils/standardJsonSchema.d.ts +90 -0
  144. package/dist/types/index.cjs +23 -0
  145. package/dist/types/index.cjs.map +1 -0
  146. package/dist/types/index.js +0 -14
  147. package/dist/types/index.js.map +1 -1
  148. package/dist/utilities/functions.d.ts +1 -1
  149. package/dist/utilities/index.cjs +982 -0
  150. package/dist/utilities/index.cjs.map +1 -0
  151. package/dist/utilities/index.js +590 -321
  152. package/dist/utilities/index.js.map +1 -1
  153. package/dist/utilities/logger.d.ts +48 -0
  154. package/package.json +152 -98
  155. package/dist/collections/Changes.test.d.ts +0 -1
  156. package/dist/collections/MemoryDataCollection.test.d.ts +0 -1
  157. package/dist/collections/TagCollection.test.d.ts +0 -1
  158. package/dist/expressions/parser.test.d.ts +0 -1
  159. package/dist/expressions/utils.test.d.ts +0 -1
  160. package/dist/pipeline/SyncronousQueue.test.d.ts +0 -1
  161. package/dist/pipeline/WorkPipeline.test.d.ts +0 -1
  162. package/dist/plugins/EphemeralDataPlugin.test.d.ts +0 -1
  163. package/dist/plugins/query/QueryOptionsCollection.test.d.ts +0 -1
  164. package/dist/plugins/replication/OptimisticReplicationDbPlugin.d.ts +0 -23
  165. package/dist/plugins/replication/ReplicationDbPlugin.d.ts +0 -22
  166. package/dist/plugins/replication/index.d.ts +0 -3
  167. package/dist/plugins/replication/types.d.ts +0 -5
  168. package/dist/plugins/translators/JsonTranslator.test.d.ts +0 -1
  169. package/dist/schema/PropertyInfo.test.d.ts +0 -1
  170. package/dist/schema/schemaGeneration.test.d.ts +0 -1
  171. package/dist/schema/testSchemas.test.d.ts +0 -314
  172. package/dist/utilities/arrays.test.d.ts +0 -1
  173. package/dist/utilities/dates.test.d.ts +0 -1
  174. package/dist/utilities/strings.test.d.ts +0 -1
@@ -1,4 +1,4 @@
1
- import { DefaultValue, FunctionBody, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
1
+ import { DefaultValue, ForeignKey, FunctionBody, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes, PropertyTransform } from "../../types";
2
2
  export declare abstract class SchemaBase<T extends any, TModifiers extends SchemaModifiers> {
3
3
  abstract instance: T;
4
4
  modifiers: TModifiers;
@@ -8,9 +8,57 @@ export declare abstract class SchemaBase<T extends any, TModifiers extends Schem
8
8
  isKey: boolean;
9
9
  isIdentity: boolean;
10
10
  isReadonly: boolean;
11
- isDistict: boolean;
11
+ isDistinct: boolean;
12
+ /**
13
+ * Set by `.modify(x => x.transform(...))`. A live reference, never stringified.
14
+ * `null` when the property is stored as it is.
15
+ */
16
+ transform: PropertyTransform<unknown> | null;
12
17
  indexes: string[];
13
18
  fromPropertyName: string | null;
19
+ /**
20
+ * How many numbers a vector holds. `null` for every other type.
21
+ *
22
+ * Declared here rather than on `SchemaVector` because a modifier WRAPS rather than
23
+ * extends: `s.vector(1536).optional()` is a `SchemaOptional`, and anything reachable only
24
+ * through the original class is lost the moment a modifier is added. `type` survives for
25
+ * exactly this reason — the copy constructor below carries it — and a dimension count has
26
+ * to travel with it, or an optional vector reaches a backend as a vector of unknown width
27
+ * and cannot be given a column.
28
+ *
29
+ * `innerSchema` is the cautionary example: it lives on `SchemaArray` alone, so a modified
30
+ * array arrives with no element type and clones through the slow path.
31
+ */
32
+ dimensions: number | null;
33
+ /**
34
+ * The longest string the property is declared to hold. `null` for every other type, and
35
+ * for a string that declares nothing.
36
+ *
37
+ * Declared here rather than on `SchemaString` for the same reason as `dimensions` above:
38
+ * `s.string({ maxLength: 4000 }).optional()` is a `SchemaOptional`, so anything reachable
39
+ * only through `SchemaString` is lost the moment a modifier is added.
40
+ *
41
+ * A declaration, never a validation. Core does not check a value against it and does not
42
+ * truncate. The backend that can use the number does: MySQL gives the column
43
+ * `VARCHAR(maxLength)` instead of the blanket `VARCHAR(255)`. Every other backend ignores
44
+ * it, because a string column that is already unbounded cannot be made more correct by
45
+ * knowing a bound.
46
+ */
47
+ maxLength: number | null;
48
+ /**
49
+ * Whether this string may be tokenised into a full-text search index.
50
+ *
51
+ * Set by `.searchable()`, and only ever true on a string. Eligibility, not membership: a
52
+ * collection that never declares `.searchIndex()` indexes nothing regardless.
53
+ *
54
+ * Copied by the constructor below, so `s.string().searchable().optional()` stays searchable.
55
+ * Every flag on this class is copied for the same reason: a modifier WRAPS rather than
56
+ * extends, so anything the constructor forgets is silently dropped the moment a property
57
+ * gains one more modifier.
58
+ */
59
+ isSearchable: boolean;
60
+ foreignKeyDefinition: ForeignKey<unknown> | null;
61
+ tags: string[];
14
62
  injected: any;
15
63
  defaultValue: DefaultValue<T> | null;
16
64
  valueSerializer: PropertySerializer<T> | null;
@@ -1,6 +1,8 @@
1
- import { PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
1
+ import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaDefault } from "./SchemaDefault";
3
4
  import { SchemaFrom } from "./SchemaFrom";
5
+ import { SchemaOptional } from "./SchemaOptional";
4
6
  import { SchemaSerialize } from "./SchemaSerialize";
5
7
  export declare class SchemaDeserialize<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
6
8
  instance: T;
@@ -8,4 +10,6 @@ export declare class SchemaDeserialize<T extends any, TModifiers extends SchemaM
8
10
  constructor(deserializer: PropertyDeserializer<T>, current: SchemaBase<T, TModifiers>);
9
11
  serialize(serializer: PropertySerializer<T>): SchemaSerialize<T, "serialize" | TModifiers>;
10
12
  from(propertyName: string): SchemaFrom<T, TModifiers>;
13
+ optional(): SchemaOptional<T, "optional" | TModifiers>;
14
+ default<I = never>(value: DefaultValue<T | null, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
11
15
  }
@@ -0,0 +1,15 @@
1
+ import { SchemaBase } from "../base/SchemaBase";
2
+ import { SchemaIdentity } from "./SchemaIdentity";
3
+ import { SchemaDefault } from "./SchemaDefault";
4
+ import { CompiledSchema, DefaultValue, InferType, SchemaModifiers } from "../../types";
5
+ import { SchemaFrom } from "./SchemaFrom";
6
+ import { SchemaTag } from "./SchemaTag";
7
+ export declare class SchemaForeignKey<T extends any, TModifiers extends SchemaModifiers, K extends {}> extends SchemaBase<T, TModifiers> {
8
+ instance: T;
9
+ private _schemaForeignKey;
10
+ constructor(current: SchemaBase<T, TModifiers>, relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>);
11
+ identity(): SchemaIdentity<T, "identity" | TModifiers>;
12
+ default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
13
+ from(propertyName: string): SchemaFrom<T, TModifiers>;
14
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
15
+ }
@@ -3,6 +3,7 @@ import { SchemaIdentity } from "./SchemaIdentity";
3
3
  import { SchemaDefault } from "./SchemaDefault";
4
4
  import { DefaultValue, IdType, SchemaModifiers } from "../../types";
5
5
  import { SchemaFrom } from "./SchemaFrom";
6
+ import { SchemaTag } from "./SchemaTag";
6
7
  export declare class SchemaKey<T extends IdType, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
7
8
  instance: T;
8
9
  private _schemaKey;
@@ -10,4 +11,5 @@ export declare class SchemaKey<T extends IdType, TModifiers extends SchemaModifi
10
11
  identity(): SchemaIdentity<T, "identity" | TModifiers>;
11
12
  default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
12
13
  from(propertyName: string): SchemaFrom<T, TModifiers>;
14
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
13
15
  }
@@ -1,9 +1,23 @@
1
- import { SchemaModifiers } from "../../types";
1
+ import { DefaultValue, PropertyDeserializer, SchemaModifiers } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaDefault } from "./SchemaDefault";
4
+ import { SchemaDeserialize } from "./SchemaDeserialize";
3
5
  import { SchemaOptional } from "./SchemaOptional";
6
+ import { SchemaSearchable } from "./SchemaSearchable";
4
7
  export declare class SchemaNullable<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
5
8
  instance: T;
6
9
  private _schemaNullable;
7
10
  constructor(current: SchemaBase<T, TModifiers>);
8
11
  optional(): SchemaOptional<T, "optional" | TModifiers>;
12
+ /**
13
+ * Only callable when the property underneath is a string — see the same method on
14
+ * `SchemaOptional` for why the constraint is on `instance` rather than the whole class.
15
+ *
16
+ * A null value contributes no tokens.
17
+ */
18
+ searchable(this: {
19
+ instance: string;
20
+ }): SchemaSearchable<T, "searchable" | TModifiers>;
21
+ default<I = never>(value: DefaultValue<T | null, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
22
+ deserialize(deserializer: PropertyDeserializer<T | null>): SchemaDeserialize<T, "deserialize" | TModifiers>;
9
23
  }
@@ -1,9 +1,30 @@
1
- import { SchemaModifiers } from "../../types";
1
+ import { PropertyDeserializer, SchemaModifiers } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaDeserialize } from "./SchemaDeserialize";
3
4
  import { SchemaNullable } from "./SchemaNullable";
5
+ import { SchemaSearchable } from "./SchemaSearchable";
4
6
  export declare class SchemaOptional<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
5
7
  instance: T;
6
8
  private _schemaOptional;
7
9
  constructor(current: SchemaBase<T, TModifiers>);
8
10
  nullable(): SchemaNullable<T, "nullable" | TModifiers>;
11
+ /**
12
+ * Only callable when the property underneath is a string.
13
+ *
14
+ * A wrapper does not know what it wraps at runtime, but the type does: `T` is the value
15
+ * type, so `s.number().optional()` is a `SchemaOptional<number>` and fails this `this`
16
+ * constraint. That is the gate — there is no runtime check, because a builder that offers
17
+ * a method it will then reject has already failed at its job.
18
+ *
19
+ * Constrained on `instance` alone rather than the whole class. `SchemaBase` holds `T` in
20
+ * contravariant positions too (`valueSerializer`, `defaultValue`), so requiring the full
21
+ * `SchemaOptional<string, ...>` would reject a literal union like
22
+ * `s.string("draft", "published")`, which is a perfectly good searchable string.
23
+ *
24
+ * An absent value contributes no tokens.
25
+ */
26
+ searchable(this: {
27
+ instance: string;
28
+ }): SchemaSearchable<T, "searchable" | TModifiers>;
29
+ deserialize(deserializer: PropertyDeserializer<T | undefined>): SchemaDeserialize<T, "deserialize" | TModifiers>;
9
30
  }
@@ -0,0 +1,34 @@
1
+ import { SchemaModifiers } from "../../types";
2
+ import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaNullable } from "./SchemaNullable";
4
+ import { SchemaOptional } from "./SchemaOptional";
5
+ /**
6
+ * Marks a string property as eligible for a full-text search index.
7
+ *
8
+ * Eligible, not indexed. The schema says what COULD be indexed; the collection builder's
9
+ * `.searchIndex()` says that it IS. A property marked here on a collection that never declares
10
+ * an index costs nothing at all — no rows, no write amplification, no storage.
11
+ *
12
+ * Like `s.vector()`, this exists to be RECOGNISED rather than to behave. It changes nothing
13
+ * about how the property is stored, cloned, compared, serialized or queried. The datastore
14
+ * reads the flag off the compiled schema to decide which values to tokenise; every plugin is
15
+ * unaware the property is any different from another string.
16
+ *
17
+ * Declared on `SchemaString` only, so `s.number().searchable()` is a compile error rather than
18
+ * a runtime surprise. The one case the type system cannot catch — a searchable string nested
19
+ * inside an `s.object()` — is rejected when the schema compiles: v1 indexes root-level string
20
+ * properties only.
21
+ */
22
+ export declare class SchemaSearchable<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
23
+ instance: T;
24
+ private _schemaSearchable;
25
+ constructor(current: SchemaBase<T, TModifiers>);
26
+ /**
27
+ * Declared here so `.searchable()` composes in BOTH senses — `.searchable().optional()` and
28
+ * `.optional().searchable()` mean the same thing and both keep the flag. `SchemaDistinct`
29
+ * exposes neither, which is why `.distinct().optional()` is unwritable and its copy-loss
30
+ * (see `SchemaBase.isSearchable`) has never been noticed.
31
+ */
32
+ optional(): SchemaOptional<T, "optional" | TModifiers>;
33
+ nullable(): SchemaNullable<T, "nullable" | TModifiers>;
34
+ }
@@ -0,0 +1,27 @@
1
+ import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers } from "../../types";
2
+ import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaArray } from "../types";
4
+ import { SchemaDefault } from "./SchemaDefault";
5
+ import { SchemaDeserialize } from "./SchemaDeserialize";
6
+ import { SchemaDistinct } from "./SchemaDistinct";
7
+ import { SchemaFrom } from "./SchemaFrom";
8
+ import { SchemaIndex } from "./SchemaIndex";
9
+ import { SchemaNullable } from "./SchemaNullable";
10
+ import { SchemaOptional } from "./SchemaOptional";
11
+ import { SchemaReadonly } from "./SchemaReadonly";
12
+ import { SchemaSerialize } from "./SchemaSerialize";
13
+ export declare class SchemaTag<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
14
+ instance: T;
15
+ private _schemaTag;
16
+ constructor(tags: string[], current: SchemaBase<T, TModifiers>);
17
+ from(propertyName: string): SchemaFrom<T, TModifiers>;
18
+ optional(): SchemaOptional<T, "optional" | TModifiers>;
19
+ nullable(): SchemaNullable<T, "nullable" | TModifiers>;
20
+ default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
21
+ readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
22
+ deserialize(deserializer: PropertyDeserializer<T>): SchemaDeserialize<T, "deserialize" | TModifiers>;
23
+ serialize(serializer: PropertySerializer<T>): SchemaSerialize<T, "serialize" | TModifiers>;
24
+ array(): SchemaArray<this, TModifiers>;
25
+ index(...indexes: string[]): SchemaIndex<T, TModifiers>;
26
+ distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
27
+ }
@@ -1,9 +1,13 @@
1
- import { IdType, SchemaModifiers } from "../../types";
1
+ import { CompiledSchema, IdType, InferType, SchemaModifiers } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
+ import { SchemaForeignKey } from "./SchemaForeignKey";
3
4
  import { SchemaKey } from "./SchemaKey";
5
+ import { SchemaTag } from "./SchemaTag";
4
6
  export declare class SchemaTracked<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
5
7
  instance: T;
6
8
  private _schemaTracked;
7
9
  constructor(current: SchemaBase<T, TModifiers>);
8
10
  key(): T extends IdType ? SchemaKey<T, TModifiers | "key"> : never;
11
+ foreignKey<K extends {}>(relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>): SchemaForeignKey<T, TModifiers, K>;
12
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
9
13
  }
@@ -7,6 +7,9 @@ export * from './SchemaKey';
7
7
  export * from './SchemaNullable';
8
8
  export * from './SchemaOptional';
9
9
  export * from './SchemaReadonly';
10
+ export * from './SchemaSearchable';
10
11
  export * from './SchemaSerialize';
11
12
  export * from './SchemaTracked';
12
13
  export * from './SchemaFrom';
14
+ export * from './SchemaTag';
15
+ export * from './SchemaForeignKey';
@@ -7,6 +7,7 @@ import { SchemaSerialize } from '../modifiers/SchemaSerialize';
7
7
  import { SchemaIndex } from "../modifiers/SchemaIndex";
8
8
  import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
9
9
  import { SchemaFrom } from "../modifiers/SchemaFrom";
10
+ import { SchemaTag } from "../modifiers/SchemaTag";
10
11
  export declare class SchemaArray<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T[], TModifiers> {
11
12
  instance: T[];
12
13
  type: SchemaTypes;
@@ -20,4 +21,5 @@ export declare class SchemaArray<T extends any, TModifiers extends SchemaModifie
20
21
  deserialize(deserializer: PropertyDeserializer<T[]>): SchemaDeserialize<T[], "deserialize" | TModifiers>;
21
22
  serialize(serializer: PropertySerializer<T[]>): SchemaSerialize<T[], "serialize" | TModifiers>;
22
23
  index(...indexes: string[]): SchemaIndex<T[], TModifiers>;
24
+ tag(...tags: string[]): SchemaTag<T[], TModifiers>;
23
25
  }
@@ -9,6 +9,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
9
9
  import { SchemaOptional } from "../modifiers/SchemaOptional";
10
10
  import { SchemaReadonly } from "../modifiers/SchemaReadonly";
11
11
  import { SchemaSerialize } from "../modifiers/SchemaSerialize";
12
+ import { SchemaTag } from "../modifiers/SchemaTag";
12
13
  import { SchemaArray } from "./SchemaArray";
13
14
  export declare class SchemaBoolean<T extends boolean, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
14
15
  instance: T;
@@ -24,4 +25,5 @@ export declare class SchemaBoolean<T extends boolean, TModifiers extends SchemaM
24
25
  array(): SchemaArray<this, TModifiers>;
25
26
  index(...indexes: string[]): SchemaIndex<T, TModifiers>;
26
27
  distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
28
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
27
29
  }
@@ -9,6 +9,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
9
9
  import { SchemaOptional } from "../modifiers/SchemaOptional";
10
10
  import { SchemaReadonly } from "../modifiers/SchemaReadonly";
11
11
  import { SchemaSerialize } from "../modifiers/SchemaSerialize";
12
+ import { SchemaTag } from "../modifiers/SchemaTag";
12
13
  import { SchemaArray } from "./SchemaArray";
13
14
  export declare class SchemaDate<T extends Date, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
14
15
  instance: T;
@@ -24,4 +25,5 @@ export declare class SchemaDate<T extends Date, TModifiers extends SchemaModifie
24
25
  array(): SchemaArray<this, TModifiers>;
25
26
  index(...indexes: string[]): SchemaIndex<T, TModifiers>;
26
27
  distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
28
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
27
29
  }
@@ -0,0 +1,60 @@
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 { SchemaNullable } from "../modifiers/SchemaNullable";
6
+ import { SchemaOptional } from "../modifiers/SchemaOptional";
7
+ import { SchemaReadonly } from "../modifiers/SchemaReadonly";
8
+ import { SchemaTag } from "../modifiers/SchemaTag";
9
+ /**
10
+ * A file: content on the way in, a reference on the way out.
11
+ *
12
+ * This is the one property type whose write shape differs from its stored shape. You assign
13
+ * a `File`, a `Blob`, a `Uint8Array` or a string; what is stored, and what a query gives
14
+ * back, is a reference — where the bytes live and what they are.
15
+ *
16
+ * ```ts
17
+ * const documentSchema = s.define('documents', {
18
+ * id: s.string().key().identity(),
19
+ * title: s.string(),
20
+ * file: s.file(),
21
+ * }).compile();
22
+ *
23
+ * await store.documents.addAsync({ title: 'Q3', file: fileFromInput });
24
+ * await store.saveChangesAsync();
25
+ *
26
+ * doc.file.size // 2_400_112
27
+ * doc.file.contentType // 'application/pdf'
28
+ * ```
29
+ *
30
+ * ## Why this cannot be `s.object({ key, size, ... })`
31
+ *
32
+ * The generated `preprocess` rebuilds an object property field by field from its declared
33
+ * children — `result.file = {}` and then one assignment per child. Content assigned there is
34
+ * therefore discarded by construction, before any plugin sees the entity: the property does
35
+ * not arrive mangled, it does not arrive at all.
36
+ *
37
+ * A file is a LEAF here, with no child properties, so the generated code passes it through
38
+ * untouched. The bytes survive as far as the plugin, which is the only place an upload can
39
+ * happen — `preprocess` is synchronous and is called from the change tracker and the
40
+ * broadcast path, so it cannot await one.
41
+ *
42
+ * ## What actually stores it
43
+ *
44
+ * Nothing in core uploads anything. `@routier/blob-plugin` wraps your real plugin, swaps
45
+ * pending content for a reference during `bulkPersist`, and hands the reference down. Without
46
+ * that wrapper a file property stores whatever you assigned, which is a mistake this type
47
+ * cannot detect on its own.
48
+ */
49
+ export declare class SchemaFile<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
50
+ instance: T;
51
+ type: SchemaTypes;
52
+ private _schemaFile;
53
+ constructor();
54
+ from(propertyName: string): SchemaFrom<T, TModifiers>;
55
+ optional(): SchemaOptional<T, "optional" | TModifiers>;
56
+ nullable(): SchemaNullable<T, "nullable" | TModifiers>;
57
+ readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
58
+ default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
59
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
60
+ }
@@ -1,8 +1,9 @@
1
- import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
1
+ import { CompiledSchema, DefaultValue, InferType, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
3
  import { SchemaDefault } from "../modifiers/SchemaDefault";
4
4
  import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
5
5
  import { SchemaDistinct } from "../modifiers/SchemaDistinct";
6
+ import { SchemaForeignKey } from "../modifiers/SchemaForeignKey";
6
7
  import { SchemaFrom } from "../modifiers/SchemaFrom";
7
8
  import { SchemaIdentity } from "../modifiers/SchemaIdentity";
8
9
  import { SchemaIndex } from "../modifiers/SchemaIndex";
@@ -11,6 +12,7 @@ import { SchemaNullable } from "../modifiers/SchemaNullable";
11
12
  import { SchemaOptional } from "../modifiers/SchemaOptional";
12
13
  import { SchemaReadonly } from "../modifiers/SchemaReadonly";
13
14
  import { SchemaSerialize } from "../modifiers/SchemaSerialize";
15
+ import { SchemaTag } from "../modifiers/SchemaTag";
14
16
  import { SchemaArray } from "./SchemaArray";
15
17
  export declare class SchemaNumber<T extends number, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
16
18
  instance: T;
@@ -21,6 +23,7 @@ export declare class SchemaNumber<T extends number, TModifiers extends SchemaMod
21
23
  optional(): SchemaOptional<T, "optional" | TModifiers>;
22
24
  nullable(): SchemaNullable<T, "nullable" | TModifiers>;
23
25
  key(): SchemaKey<T, "key" | TModifiers>;
26
+ foreignKey<K extends {}>(relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>): SchemaForeignKey<T, TModifiers, K>;
24
27
  default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
25
28
  readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
26
29
  deserialize(deserializer: PropertyDeserializer<T>): SchemaDeserialize<T, "deserialize" | TModifiers>;
@@ -29,4 +32,5 @@ export declare class SchemaNumber<T extends number, TModifiers extends SchemaMod
29
32
  array(): SchemaArray<this, TModifiers>;
30
33
  index(...indexes: string[]): SchemaIndex<T, TModifiers>;
31
34
  distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
35
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
32
36
  }
@@ -5,6 +5,7 @@ import { SchemaFrom } from "../modifiers/SchemaFrom";
5
5
  import { SchemaIdentity } from "../modifiers/SchemaIdentity";
6
6
  import { SchemaNullable } from "../modifiers/SchemaNullable";
7
7
  import { SchemaOptional } from "../modifiers/SchemaOptional";
8
+ import { SchemaTag } from "../modifiers/SchemaTag";
8
9
  import { SchemaArray } from "./SchemaArray";
9
10
  export declare class SchemaObject<T extends {}, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
10
11
  instance: T;
@@ -17,4 +18,5 @@ export declare class SchemaObject<T extends {}, TModifiers extends SchemaModifie
17
18
  default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
18
19
  identity(): SchemaIdentity<T, "identity" | "readonly" | TModifiers>;
19
20
  array(): SchemaArray<this, TModifiers>;
21
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
20
22
  }
@@ -1,8 +1,9 @@
1
- import { DefaultValue, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes } from "../../types";
1
+ import { CompiledSchema, DefaultValue, InferType, PropertyDeserializer, PropertySerializer, SchemaModifiers, SchemaTypes, StringOptions } from "../../types";
2
2
  import { SchemaBase } from "../base/SchemaBase";
3
3
  import { SchemaDefault } from "../modifiers/SchemaDefault";
4
4
  import { SchemaDeserialize } from "../modifiers/SchemaDeserialize";
5
5
  import { SchemaDistinct } from "../modifiers/SchemaDistinct";
6
+ import { SchemaForeignKey } from "../modifiers/SchemaForeignKey";
6
7
  import { SchemaFrom } from "../modifiers/SchemaFrom";
7
8
  import { SchemaIdentity } from "../modifiers/SchemaIdentity";
8
9
  import { SchemaIndex } from "../modifiers/SchemaIndex";
@@ -10,17 +11,26 @@ import { SchemaKey } from "../modifiers/SchemaKey";
10
11
  import { SchemaNullable } from "../modifiers/SchemaNullable";
11
12
  import { SchemaOptional } from "../modifiers/SchemaOptional";
12
13
  import { SchemaReadonly } from "../modifiers/SchemaReadonly";
14
+ import { SchemaSearchable } from "../modifiers/SchemaSearchable";
13
15
  import { SchemaSerialize } from "../modifiers/SchemaSerialize";
16
+ import { SchemaTag } from "../modifiers/SchemaTag";
14
17
  import { SchemaArray } from "./SchemaArray";
15
18
  export declare class SchemaString<T extends string, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
16
19
  instance: T;
17
20
  type: SchemaTypes;
18
21
  private _schemaString;
22
+ /**
23
+ * @param entity Copied from when a modifier wraps this property.
24
+ * @param literals The allowed values, when the string is a literal union.
25
+ * @param options Declarations a backend may use. See `StringOptions`.
26
+ */
27
+ constructor(entity?: SchemaBase<T, TModifiers> | null, literals?: T[], options?: StringOptions);
19
28
  from(propertyName: string): SchemaFrom<T, TModifiers>;
20
29
  constrain<K extends T>(): SchemaString<K, TModifiers>;
21
30
  optional(): SchemaOptional<T, "optional" | TModifiers>;
22
31
  nullable(): SchemaNullable<T, "nullable" | TModifiers>;
23
32
  key(): SchemaKey<T, "key" | TModifiers>;
33
+ foreignKey<K extends {}>(relatingSchema: CompiledSchema<K>, property: keyof InferType<CompiledSchema<K>>): SchemaForeignKey<T, TModifiers, K>;
24
34
  default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
25
35
  readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
26
36
  deserialize(deserializer: PropertyDeserializer<T>): SchemaDeserialize<T, "deserialize" | TModifiers>;
@@ -29,4 +39,18 @@ export declare class SchemaString<T extends string, TModifiers extends SchemaMod
29
39
  array(): SchemaArray<this, TModifiers>;
30
40
  index(...indexes: string[]): SchemaIndex<T, TModifiers>;
31
41
  distinct(): SchemaDistinct<T, "distinct" | TModifiers>;
42
+ /**
43
+ * Marks this string as eligible for the collection's full-text search index.
44
+ *
45
+ * ```ts
46
+ * title: s.string().searchable(),
47
+ * body: s.string({ maxLength: 4000 }).searchable(),
48
+ * ```
49
+ *
50
+ * Nothing is indexed until the collection declares `.searchIndex()`. Combines with
51
+ * `.optional()` and `.nullable()` in either sense — an absent or null value contributes no
52
+ * tokens.
53
+ */
54
+ searchable(): SchemaSearchable<T, "searchable" | TModifiers>;
55
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
32
56
  }
@@ -0,0 +1,61 @@
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 { SchemaNullable } from "../modifiers/SchemaNullable";
6
+ import { SchemaOptional } from "../modifiers/SchemaOptional";
7
+ import { SchemaReadonly } from "../modifiers/SchemaReadonly";
8
+ import { SchemaTag } from "../modifiers/SchemaTag";
9
+ /**
10
+ * An embedding: a fixed-length list of numbers you can search by similarity.
11
+ *
12
+ * ```ts
13
+ * const documentSchema = s.define('documents', {
14
+ * id: s.string().key().identity(),
15
+ * title: s.string(),
16
+ * embedding: s.vector(1536),
17
+ * }).compile();
18
+ *
19
+ * const similar = await store.documents
20
+ * .nearest(x => x.embedding, queryEmbedding, 10)
21
+ * .toArrayAsync();
22
+ * ```
23
+ *
24
+ * ## Why this is not `s.array(s.number())`
25
+ *
26
+ * By value it is exactly that, and every codegen handler treats the two the same on purpose —
27
+ * a vector clones with a spread, compares by JSON and freezes like any other array. What an
28
+ * array cannot carry is the DIMENSION COUNT, and a backend that stores vectors natively needs
29
+ * it at DDL time: pgvector's column type is `vector(1536)`, not `vector`.
30
+ *
31
+ * So this exists to be RECOGNISED, not to behave differently. A backend that knows what a
32
+ * vector is stores one; every other backend sees a list of numbers and stores JSON, which is
33
+ * why the feature works everywhere rather than only on PostgreSQL.
34
+ *
35
+ * ## Dimensions are not enforced here
36
+ *
37
+ * `dimensions` is a declaration, and core never checks a value against it. The check belongs
38
+ * where the cost of being wrong is paid: a backend with a native `vector(n)` column rejects a
39
+ * mismatched write itself, with an error naming the column. Validating in core would duplicate
40
+ * that on the backends that already do it and add a per-save array scan to the ones that
41
+ * cannot use the information at all.
42
+ *
43
+ * ## Similarity is cosine, and it is not a filter
44
+ *
45
+ * `.nearest()` is an ordering plus a limit — it returns the closest rows, not the matching
46
+ * ones. Distance itself is not exposed: the entity shape is fixed, and the ordering is what
47
+ * callers act on. A backend with no vector support scores in memory, so the answer is the
48
+ * same everywhere; only the amount of data read differs.
49
+ */
50
+ export declare class SchemaVector<T extends any, TModifiers extends SchemaModifiers> extends SchemaBase<T, TModifiers> {
51
+ instance: T;
52
+ type: SchemaTypes;
53
+ private _schemaVector;
54
+ constructor(dimensions: number);
55
+ from(propertyName: string): SchemaFrom<T, TModifiers>;
56
+ optional(): SchemaOptional<T, "optional" | TModifiers>;
57
+ nullable(): SchemaNullable<T, "nullable" | TModifiers>;
58
+ readonly(): SchemaReadonly<T, "readonly" | TModifiers>;
59
+ default<I = never>(value: DefaultValue<T, I>, injected?: I): SchemaDefault<T, I, "default" | TModifiers>;
60
+ tag(...tags: string[]): SchemaTag<T, TModifiers>;
61
+ }
@@ -4,3 +4,5 @@ export * from './SchemaDate';
4
4
  export * from './SchemaNumber';
5
5
  export * from './SchemaObject';
6
6
  export * from './SchemaString';
7
+ export * from './SchemaFile';
8
+ export * from './SchemaVector';
@@ -0,0 +1,40 @@
1
+ import { SchemaBase } from "../property/base/SchemaBase";
2
+ import { PropertyTransform, SchemaModifiers } from "../types";
3
+ /**
4
+ * A two-way transform between the value your application holds and the value that is stored.
5
+ *
6
+ * Declared in `.modify()`, beside `computed` and `function`, because it belongs to the same
7
+ * family: a property whose stored form is derived rather than assigned. `computed` derives one
8
+ * way and cannot come back; a transform declares both directions.
9
+ *
10
+ * ```ts
11
+ * const cipher = myEncryption(keyring); // whatever you use — {} with `to` and `from`
12
+ *
13
+ * const userSchema = s.define('users', {
14
+ * id: s.string().key().identity(),
15
+ * ssn: s.string(),
16
+ * }).modify(x => ({
17
+ * ssn: x.transform(cipher),
18
+ * })).compile();
19
+ * ```
20
+ *
21
+ * `to` and `from` may be async, and they are held as LIVE references — never stringified into
22
+ * generated code the way `computed` is. So they close over whatever they need, which is why
23
+ * there is no `injected` argument to pass and no property to repeat.
24
+ *
25
+ * Nothing about this is encryption. Encryption is one thing a caller might write here;
26
+ * compression, redaction, unit conversion and a custom codec are others. The library ships no
27
+ * behaviour of its own for this — it only carries what you supply.
28
+ */
29
+ export declare class SchemaTransform<T extends any, TModifiers extends SchemaModifiers = never> extends SchemaBase<T, TModifiers> {
30
+ instance: T;
31
+ private _schemaTransform;
32
+ /**
33
+ * Bound to the property it replaces when the schema is assembled.
34
+ *
35
+ * You do not pass the property in. `.modify()` already knows which one you mean — it is
36
+ * the key you assigned to — so repeating `s.string()` would be ceremony for nothing.
37
+ */
38
+ bindTo(underlying: SchemaBase<T, TModifiers>): this;
39
+ constructor(transform: PropertyTransform<T>);
40
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './SchemaComputed';
2
2
  export * from './SchemaFunction';
3
+ export * from './SchemaTransform';