@zmdb/schema 1.0.0-beta.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 (68) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +30 -0
  3. package/dist/custom-types/index.d.ts +41 -0
  4. package/dist/custom-types/index.d.ts.map +1 -0
  5. package/dist/custom-types/index.js +32 -0
  6. package/dist/custom-types/index.js.map +1 -0
  7. package/dist/derive/index.d.ts +122 -0
  8. package/dist/derive/index.d.ts.map +1 -0
  9. package/dist/derive/index.js +13 -0
  10. package/dist/derive/index.js.map +1 -0
  11. package/dist/derive/query.d.ts +62 -0
  12. package/dist/derive/query.d.ts.map +1 -0
  13. package/dist/derive/query.js +18 -0
  14. package/dist/derive/query.js.map +1 -0
  15. package/dist/dto/index.d.ts +224 -0
  16. package/dist/dto/index.d.ts.map +1 -0
  17. package/dist/dto/index.js +118 -0
  18. package/dist/dto/index.js.map +1 -0
  19. package/dist/entity-modeling/index.d.ts +12 -0
  20. package/dist/entity-modeling/index.d.ts.map +1 -0
  21. package/dist/entity-modeling/index.js +28 -0
  22. package/dist/entity-modeling/index.js.map +1 -0
  23. package/dist/index.d.ts +151 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +84 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/ir/index.d.ts +374 -0
  28. package/dist/ir/index.d.ts.map +1 -0
  29. package/dist/ir/index.js +735 -0
  30. package/dist/ir/index.js.map +1 -0
  31. package/dist/ir/validation-shape.d.ts +46 -0
  32. package/dist/ir/validation-shape.d.ts.map +1 -0
  33. package/dist/ir/validation-shape.js +130 -0
  34. package/dist/ir/validation-shape.js.map +1 -0
  35. package/dist/ir/vocabulary.d.ts +54 -0
  36. package/dist/ir/vocabulary.d.ts.map +1 -0
  37. package/dist/ir/vocabulary.js +51 -0
  38. package/dist/ir/vocabulary.js.map +1 -0
  39. package/dist/naming/index.d.ts +26 -0
  40. package/dist/naming/index.d.ts.map +1 -0
  41. package/dist/naming/index.js +147 -0
  42. package/dist/naming/index.js.map +1 -0
  43. package/dist/openapi/index.d.ts +57 -0
  44. package/dist/openapi/index.d.ts.map +1 -0
  45. package/dist/openapi/index.js +98 -0
  46. package/dist/openapi/index.js.map +1 -0
  47. package/dist/relations/index.d.ts +23 -0
  48. package/dist/relations/index.d.ts.map +1 -0
  49. package/dist/relations/index.js +98 -0
  50. package/dist/relations/index.js.map +1 -0
  51. package/dist/tags/index.d.ts +261 -0
  52. package/dist/tags/index.d.ts.map +1 -0
  53. package/dist/tags/index.js +64 -0
  54. package/dist/tags/index.js.map +1 -0
  55. package/package.json +82 -0
  56. package/src/custom-types/index.ts +59 -0
  57. package/src/derive/index.ts +224 -0
  58. package/src/derive/query.ts +128 -0
  59. package/src/dto/index.ts +395 -0
  60. package/src/entity-modeling/index.ts +33 -0
  61. package/src/index.ts +263 -0
  62. package/src/ir/index.ts +1085 -0
  63. package/src/ir/validation-shape.ts +145 -0
  64. package/src/ir/vocabulary.ts +56 -0
  65. package/src/naming/index.ts +159 -0
  66. package/src/openapi/index.ts +133 -0
  67. package/src/relations/index.ts +134 -0
  68. package/src/tags/index.ts +284 -0
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @zmdb/schema
2
+
3
+ `@zmdb/schema` contains the schema tags and shared intermediate representation used throughout zmdb. It also derives entities and DTOs and builds relation and OpenAPI types. Provider-neutral AI tools
4
+ are now published from `@zmdb/ai`.
5
+
6
+ It is part of [zmdb](https://github.com/ambasta/zmdb), where one TypeScript schema drives validation, serialization, SQL, OpenAPI, and CRUD.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ yarn add @zmdb/schema@1.0.0-beta.1
12
+ ```
13
+
14
+ > **Prerelease** (`1.0.0-beta.1`). Requires **Node.js 26+** and is **ESM-only**. Ships built ESM `.js` + `.d.ts` under `./dist`.
15
+
16
+ ## Entry points
17
+
18
+ - Core schema APIs: `@zmdb/schema`
19
+ - Schema building blocks: `/tags`, `/ir`, `/derive`, `/dto`, `/naming`, `/relations`, `/openapi`, `/custom-types`, `/entity-modeling`
20
+
21
+ AI is not re-exported from `@zmdb/schema`. Provider-neutral tools ship from `@zmdb/ai`; Anthropic, LangChain, and Vercel integrations ship from their matching `@zmdb/ai-*` packages; MCP client and
22
+ server cores ship from `@zmdb/mcp`.
23
+
24
+ ## Documentation
25
+
26
+ Full docs: **https://ambasta.github.io/zmdb/**
27
+
28
+ ## License
29
+
30
+ GNU General Public License v3.0 or later (GPL-3.0-or-later) — see [LICENSE](./LICENSE).
@@ -0,0 +1,41 @@
1
+ import { type Codec } from '../ir/index.js';
2
+ /**
3
+ * A column type the library does not know, described by its owner.
4
+ *
5
+ * Three types, because a column has three (plan D3): `Wire` is what JSON carries,
6
+ * `TS` is what handler code holds, and `DB` is what the driver binds. A codec that
7
+ * named only two of them left the third to be guessed, and the guess was "the same
8
+ * as the app type" — which is how a `Money` instance ended up being handed to
9
+ * `JSON.stringify` and to a query parameter unchanged.
10
+ *
11
+ * All four functions are required. A codec whose `toWire` was optional would be a
12
+ * codec that sometimes converts, and the caller cannot tell which kind it has.
13
+ */
14
+ export interface CustomType<Wire, TS, DB = unknown> {
15
+ /** DDL type, e.g. `'jsonb'`. Dialect spelling is the emitter's business. */
16
+ readonly sqlType: string;
17
+ /** Serialise for the driver. */
18
+ readonly toDb: (value: TS) => DB;
19
+ /** Parse a driver row value. */
20
+ readonly fromDb: (raw: DB) => TS;
21
+ /** Serialise for a JSON response. */
22
+ readonly toWire: (value: TS) => Wire;
23
+ /** Parse a JSON request body value. */
24
+ readonly fromWire: (raw: Wire) => TS;
25
+ }
26
+ export declare function defineType<Wire, TS, DB>(def: CustomType<Wire, TS, DB>): CustomType<Wire, TS, DB>;
27
+ export declare function encodeValue<Wire, TS, DB>(type: CustomType<Wire, TS, DB>, value: TS): DB;
28
+ export declare function decodeValue<Wire, TS, DB>(type: CustomType<Wire, TS, DB>, raw: DB): TS;
29
+ /**
30
+ * Adapt a `CustomType` to the `Codec` the IR's wire crossing asks for.
31
+ *
32
+ * The IR speaks `unknown` on both sides because it is data, not generics; the
33
+ * conversion is one cast at this boundary rather than one at every registry literal.
34
+ * A `Codec<'Money'>` tag names the key this goes under:
35
+ *
36
+ * ```ts
37
+ * wireDecoder(Schema, 'create', { Money: wireCodec(MoneyType) })
38
+ * ```
39
+ */
40
+ export declare function wireCodec<Wire, TS, DB>(type: CustomType<Wire, TS, DB>): Codec;
41
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/custom-types/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,GAAG,OAAO;IAChD,4EAA4E;IAC5E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,gCAAgC;IAChC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC;IACjC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC;IACjC,qCAAqC;IACrC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,KAAK,IAAI,CAAC;IACrC,uCAAuC;IACvC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,IAAI,KAAK,EAAE,CAAC;CACtC;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAEhG;AACD,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,CAEvF;AACD,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,CAErF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,CAQ7E"}
@@ -0,0 +1,32 @@
1
+ // Custom types & codecs — see ./SPEC.md.
2
+ import {} from '../ir/index.js';
3
+ export function defineType(def) {
4
+ return Object.freeze({ ...def });
5
+ }
6
+ export function encodeValue(type, value) {
7
+ return type.toDb(value);
8
+ }
9
+ export function decodeValue(type, raw) {
10
+ return type.fromDb(raw);
11
+ }
12
+ /**
13
+ * Adapt a `CustomType` to the `Codec` the IR's wire crossing asks for.
14
+ *
15
+ * The IR speaks `unknown` on both sides because it is data, not generics; the
16
+ * conversion is one cast at this boundary rather than one at every registry literal.
17
+ * A `Codec<'Money'>` tag names the key this goes under:
18
+ *
19
+ * ```ts
20
+ * wireDecoder(Schema, 'create', { Money: wireCodec(MoneyType) })
21
+ * ```
22
+ */
23
+ export function wireCodec(type) {
24
+ // boundary: a registry is keyed by name, so the value arriving at either direction is only
25
+ // as typed as the declaration that named this codec. The validator is what proves it, and
26
+ // it runs before `decode` and after `encode`.
27
+ return {
28
+ decode: (wire) => type.fromWire(wire),
29
+ encode: (app) => type.toWire(app),
30
+ };
31
+ }
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/custom-types/index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,OAAO,EAAc,MAAM,gBAAgB,CAAC;AA2B5C,MAAM,UAAU,UAAU,CAAe,GAA6B;IACpE,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC;AACnC,CAAC;AACD,MAAM,UAAU,WAAW,CAAe,IAA8B,EAAE,KAAS;IACjF,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC1B,CAAC;AACD,MAAM,UAAU,WAAW,CAAe,IAA8B,EAAE,GAAO;IAC/E,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CAAe,IAA8B;IACpE,2FAA2F;IAC3F,0FAA0F;IAC1F,8CAA8C;IAC9C,OAAO;QACL,MAAM,EAAE,CAAC,IAAa,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAY,CAAC;QACtD,MAAM,EAAE,CAAC,GAAY,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,GAAS,CAAC;KACjD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,122 @@
1
+ import { type AnyRelation, type HasDefault, type PrimaryKey, type Sensitive, type Serial, type SoftDelete, type Sql, type Table, type Unique, type WireAs } from '../tags/index.js';
2
+ /**
3
+ * What every derivation takes: a type that could have been declared as a table.
4
+ *
5
+ * An alias for `Table<string>`, and the constraint is the point. `Table` is an
6
+ * all-optional weak type, so TypeScript's weak-type rule rejects anything with no property
7
+ * in common with it — which a generated schema *value* is. `Entity<typeof UserSchema>`, the
8
+ * spelling this design replaced, is therefore a compile error rather than the schema's own
9
+ * five properties dressed up as a row. Worth constraining for precisely because the wrong
10
+ * answer was structurally plausible: it had keys and it had types, so nothing downstream
11
+ * would have complained.
12
+ *
13
+ * An index-signature row still passes, because a string index can hold the slot — see
14
+ * `dto/index.ts`'s `UnknownRow`, the one corner of the query surface keyed by a table
15
+ * *name* instead of by a declaration.
16
+ */
17
+ export type DeclaredTable = Table<string>;
18
+ export type KeysCarrying<T, Tag> = {
19
+ [K in keyof T]-?: NonNullable<T[K]> extends Tag ? (K extends string ? K : never) : never;
20
+ }[keyof T];
21
+ /** Columns the database generates. Omitted from `CreateDTO` outright. */
22
+ export type SerialKeys<T> = KeysCarrying<T, Serial>;
23
+ /** Columns with a database default. Optional on insert, not absent. */
24
+ export type DefaultKeys<T> = KeysCarrying<T, HasDefault>;
25
+ export type PrimaryKeyKeys<T> = KeysCarrying<T, PrimaryKey>;
26
+ export type SensitiveKeys<T> = KeysCarrying<T, Sensitive>;
27
+ export type UniqueKeys<T> = KeysCarrying<T, Unique>;
28
+ /** The entity-level soft-delete tag names one managed column. */
29
+ export type SoftDeleteKeys<T> = T extends SoftDelete<infer Column> ? Extract<Column, ColumnKeys<T>> : never;
30
+ /** Columns whose declared type admits `null`. Native, not a tag. */
31
+ export type NullableKeys<T> = {
32
+ [K in keyof T]-?: null extends T[K] ? (K extends string ? K : never) : never;
33
+ }[keyof T];
34
+ /**
35
+ * Properties declared with a relation tag: a join target, not a column.
36
+ *
37
+ * These have to come out of `Entity<T>`, and therefore out of everything derived
38
+ * from it. A relation left in would be a column to `INSERT`, a column to `SELECT`
39
+ * and a JSON Schema property, none of which it is. `./query.ts` puts them back where
40
+ * they belong, in `Populated<T, K>`.
41
+ */
42
+ export type RelationKeys<T> = KeysCarrying<T, AnyRelation>;
43
+ /**
44
+ * Everything that is a column: a data key that is not a relation.
45
+ *
46
+ * Spelled as its own projection rather than as a subtraction. `Exclude<AllKeys<T>,
47
+ * RelationKeys<T>>` does not compile: for an unresolved `T` both operands normalise to
48
+ * the same deferred expression, so the subtraction yields `never`, and then
49
+ * `Pick<Entity<T>, DefaultKeys<T>>` is an error because nothing is a key of an entity
50
+ * with no keys.
51
+ */
52
+ export type ColumnKeys<T> = {
53
+ [K in keyof T]-?: NonNullable<T[K]> extends AnyRelation ? never : K extends string ? K : never;
54
+ }[keyof T];
55
+ /**
56
+ * The selectable row: every column, required, sensitive columns included, tags
57
+ * preserved. Tags must survive here or the constraints would not survive `Omit`
58
+ * and `Partial` downstream.
59
+ *
60
+ * Relations are not columns and are not here. See `RelationKeys`.
61
+ */
62
+ export type Entity<T extends DeclaredTable> = {
63
+ -readonly [K in ColumnKeys<T>]-?: T[K];
64
+ };
65
+ /**
66
+ * A tag filter's keys, narrowed to the keys `Entity<T>` actually has.
67
+ *
68
+ * `SerialKeys<T>` and friends are subsets of `ColumnKeys<T>` by construction — a
69
+ * relation cannot carry `Serial` — but TypeScript will not take it on trust. Relating
70
+ * two of these projections for an unresolved `T` works only while the *target*'s
71
+ * template is unconditional, which `DataKeys<T>` was and `ColumnKeys<T>` is not. So the
72
+ * subset is stated as an intersection, which is assignable to either side by
73
+ * definition, rather than proved. Nothing changes for a concrete type.
74
+ */
75
+ type AsColumns<T extends DeclaredTable, K> = K & keyof Entity<T>;
76
+ /**
77
+ * Insert shape. `Serial` columns are **absent** — naming one is a compile error,
78
+ * because the database generates the value. `HasDefault` columns are **present
79
+ * and optional**, because supplying one is legitimate. That distinction is the
80
+ * whole reason the two tags are separate.
81
+ *
82
+ * A nullable column is optional for the same reason a defaulted one is: omitting it
83
+ * inserts `NULL`, which is exactly what passing `null` does, so demanding the key adds
84
+ * ceremony and no information. The published document has always said this — a nullable
85
+ * column has never appeared in a `create` document's `required` — and so did the
86
+ * repository's runtime check. Requiring `bio: null` in the type while the contract said
87
+ * it was optional meant a client that followed the contract wrote a payload the type
88
+ * rejected, which is the disagreement this phase exists to remove. It stays *present* and
89
+ * optional rather than absent, because passing `null` explicitly is legitimate.
90
+ */
91
+ type OptionalCreateKeys<T extends DeclaredTable> = Exclude<DefaultKeys<T> | NullableKeys<T>, SoftDeleteKeys<T>>;
92
+ export type CreateDTO<T extends DeclaredTable> = Omit<Entity<T>, SerialKeys<T> | DefaultKeys<T> | NullableKeys<T> | SoftDeleteKeys<T>> & Partial<Pick<Entity<T>, AsColumns<T, OptionalCreateKeys<T>>>>;
93
+ /** Patch shape: identity and framework-managed columns dropped, everything else optional. */
94
+ export type UpdateDTO<T extends DeclaredTable> = Partial<Omit<Entity<T>, SerialKeys<T> | PrimaryKeyKeys<T> | SoftDeleteKeys<T>>>;
95
+ /**
96
+ * What a read endpoint may return. `Sensitive` columns are removed from the
97
+ * type, so a leak is a compile error rather than a serializer's responsibility.
98
+ */
99
+ export type ReadDTO<T extends DeclaredTable> = Omit<Entity<T>, SensitiveKeys<T>>;
100
+ type IsUnion<T, U = T> = T extends unknown ? ([U] extends [T] ? false : true) : never;
101
+ /**
102
+ * The key value: a scalar for a single-column key, an object map for a composite
103
+ * one, `unknown` when the type declares no primary key.
104
+ *
105
+ * Named `PrimaryKeyOf` so the tag can be `PrimaryKey`, which is the name typed at
106
+ * every declaration site (plan D1).
107
+ */
108
+ export type PrimaryKeyOf<T extends DeclaredTable> = [PrimaryKeyKeys<T>] extends [never] ? unknown : IsUnion<PrimaryKeyKeys<T>> extends true ? {
109
+ [K in PrimaryKeyKeys<T>]: Entity<T>[AsColumns<T, K>];
110
+ } : Entity<T>[AsColumns<T, PrimaryKeyKeys<T>>];
111
+ type OrNull<V, W> = null extends V ? W | null : W;
112
+ type WireValue<V> = NonNullable<V> extends WireAs<infer W> ? OrNull<V, W> : NonNullable<V> extends Sql<'timestamp'> ? OrNull<V, string> : NonNullable<V> extends Sql<'bigint'> ? OrNull<V, string> : V;
113
+ /** The over-the-wire shape of an entity: JSON-representable throughout. */
114
+ export type Wire<T> = {
115
+ -readonly [K in ColumnKeys<T>]-?: WireValue<T[K]>;
116
+ };
117
+ /** The over-the-wire shape of an insert payload. */
118
+ export type WireCreateDTO<T extends DeclaredTable> = {
119
+ [K in keyof CreateDTO<T>]: WireValue<CreateDTO<T>[K]>;
120
+ };
121
+ export type { GetDTO, GetOptions, JoinRow, ListDTO, ListResult, OrderByDTO, PaginationDTO, Populated, PopulatedEntity, Projection, RelationPath, WhereDTO, } from './query.js';
122
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,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CAAC;AAmBjD,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC;AAElD,KAAK,SAAS,CAAC,CAAC,IACd,WAAW,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,CAAC,CAAC,GAClC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GACZ,WAAW,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,WAAW,CAAC,GACrC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GACjB,WAAW,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,GAClC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,GACjB,CAAC,CAAC;AAEZ,2EAA2E;AAC3E,MAAM,MAAM,IAAI,CAAC,CAAC,IAAI;IAAE,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAE5E,oDAAoD;AACpD,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,aAAa,IAAI;KAAG,CAAC,IAAI,MAAM,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,CAAC;AAK/G,YAAY,EACV,MAAM,EACN,UAAU,EACV,OAAO,EACP,OAAO,EACP,UAAU,EACV,UAAU,EACV,aAAa,EACb,SAAS,EACT,eAAe,EACf,UAAU,EACV,YAAY,EACZ,QAAQ,GACT,MAAM,YAAY,CAAC"}
@@ -0,0 +1,13 @@
1
+ // @zmdb/schema/derive: the DTO suite, derived from a tagged type.
2
+ //
3
+ // There is one `Entity`, one `CreateDTO`, one `UpdateDTO`, one `PrimaryKeyOf`, and they
4
+ // are these. `../index.ts` re-exports them under the same names it used to define
5
+ // schema-value twins under; the twins are deleted, not deprecated.
6
+ //
7
+ // Every derivation takes the declared type and nothing else. Nothing here tests
8
+ // `T extends { columns: ... }`, nothing dispatches on whether it was handed a value, and
9
+ // so nothing pays for that test per use. A caller who holds a schema value crosses back
10
+ // at a boundary — `TaggedSchema<T>` in a parameter position, `T` by inference — and the
11
+ // derivations never see the value at all.
12
+ import {} from '../tags/index.js';
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/derive/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,EAAE;AACF,wFAAwF;AACxF,kFAAkF;AAClF,mEAAmE;AACnE,EAAE;AACF,gFAAgF;AAChF,yFAAyF;AACzF,wFAAwF;AACxF,wFAAwF;AACxF,0CAA0C;AAE1C,OAAO,EAWN,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { type DeclaredTable, type Entity, type RelationKeys } from './index.js';
2
+ export { type GetDTO, type GetOptions, type ListDTO, type ListResult, type OrderByDTO, type PaginationDTO, type Projection, type WhereDTO, } from '../dto/index.js';
3
+ /**
4
+ * What a populated relation holds: fetched rows, and what happens when nothing matched.
5
+ *
6
+ * Cardinality comes from the declaration and nothing else, which is the point: `comments?:
7
+ * Comment[] & OneToMany<…>` is an array because it was written as one, and `author?: User &
8
+ * ManyToOne<…>` is not. The schema-value version had to read the cardinality out of a
9
+ * `RelationMeta` and rebuild the array, through six nested conditional types named
10
+ * `RelationEntityFromDef` and `RelationCardinalityFromDef`, because a relation *value* does
11
+ * not carry the target's type. Both are deleted.
12
+ *
13
+ * Without a nested path, the target becomes `Entity<>`: its own relations are absent.
14
+ * A nested path adds only its requested descendants, using this same derivation.
15
+ * And a to-one gains `| null`, because a foreign key that matches nothing is a row the
16
+ * database can hold — `null` is what the repository attaches for it, and a type that said
17
+ * `User` there would be wrong for the case the query cannot rule out. A to-many needs no
18
+ * such arm: no match is the empty array.
19
+ */
20
+ type PopulatedValue<V, Paths extends string> = NonNullable<V> extends readonly (infer E)[] ? readonly ([Paths] extends [never] ? Entity<E & DeclaredTable> : PopulatedRow<E & DeclaredTable, Paths>)[] : ([Paths] extends [never] ? Entity<NonNullable<V> & DeclaredTable> : PopulatedRow<NonNullable<V> & DeclaredTable, Paths>) | null;
21
+ /** Validate a supplied path without expanding every path of a recursive entity graph. */
22
+ export type RelationPath<T extends DeclaredTable, Path extends string> = Path extends `${infer Head}.${infer Tail}` ? Head extends RelationKeys<T> ? `${Head}.${RelationPath<RelationTargetOf<T[Head & keyof T]>, Tail>}` : never : Path extends RelationKeys<T> ? Path : never;
23
+ type PathHead<Path extends string> = Path extends `${infer Head}.${string}` ? Head : Path;
24
+ type PathTail<Path extends string, Head extends string> = Path extends `${Head}.${infer Tail}` ? Tail : never;
25
+ type RootRelationPath<T> = (RelationKeys<T> & string) | `${RelationKeys<T> & string}.${string}`;
26
+ /**
27
+ * The row plus the relation paths named by `K`, populated.
28
+ *
29
+ * Dotted paths contribute their first segment to this row and pass their remaining
30
+ * segments to the child. Keeping direct keys in the mapped key set also lets a generic
31
+ * one-level relation loader index the result with its declared relation key.
32
+ */
33
+ type PopulatedRow<T extends DeclaredTable, K extends string> = Entity<T> & {
34
+ -readonly [P in (K | PathHead<K>) & keyof T]: PopulatedValue<T[P], PathTail<K, P & string>>;
35
+ };
36
+ export type PopulatedEntity<T extends DeclaredTable, K extends RootRelationPath<T> = RelationKeys<T> & string> = PopulatedRow<T, K> & ([Exclude<K, RelationPath<T, K>>] extends [never] ? unknown : never);
37
+ /** Alias kept because both names are in use across the repository and the docs. */
38
+ export type Populated<T extends DeclaredTable, K extends RootRelationPath<T> = RelationKeys<T> & string> = PopulatedEntity<T, K>;
39
+ /**
40
+ * The target of a relation: the element type for a to-many, the type itself for a to-one.
41
+ *
42
+ * `& DeclaredTable` on the way out rather than a constraint on the way in. A relation is
43
+ * declared as `Comment[] & OneToMany<…>`, so the element type is whatever the author wrote
44
+ * there and TypeScript cannot be told in advance that it is a table — but `Entity<>` wants
45
+ * to know, and intersecting is assignable by definition where proving is not.
46
+ */
47
+ type RelationTargetOf<V> = (NonNullable<V> extends readonly (infer E)[] ? E : NonNullable<V>) & DeclaredTable;
48
+ /**
49
+ * One row of a join: the base row's columns and the target's, flat.
50
+ *
51
+ * A `LEFT JOIN` can produce a row with no match, so the joined half is `Partial`. An
52
+ * `INNER JOIN` cannot, so it is not — and that asymmetry is the whole reason `Kind` is
53
+ * a parameter rather than always-partial.
54
+ *
55
+ * `../relations/index.ts` exports the same asymmetry as `JoinRow<Base, Joined, Kind>`, for
56
+ * the join that names its target directly instead of by a relation. Two shapes, because they
57
+ * take different arguments: that one is given both tables, this one is given a base table and
58
+ * the name of one of its relations. The conditional itself is two lines and duplicating it is
59
+ * cheaper than a shared helper neither would read more clearly.
60
+ */
61
+ export type JoinRow<T extends DeclaredTable, K extends RelationKeys<T>, Kind extends 'inner' | 'left' = 'left'> = Kind extends 'inner' ? Entity<T> & Entity<RelationTargetOf<T[K & keyof T]>> : Entity<T> & Partial<Entity<RelationTargetOf<T[K & keyof T]>>>;
62
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/derive/query.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhF,OAAO,EACL,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,QAAQ,GACd,MAAM,iBAAiB,CAAC;AAUzB;;;;;;;;;;;;;;;;GAgBG;AACH,KAAK,cAAc,CAAC,CAAC,EAAE,KAAK,SAAS,MAAM,IACzC,WAAW,CAAC,CAAC,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACvC,SAAS,CAAC,CAAC,KAAK,CAAC,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AAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,GACpD,MAAM,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,18 @@
1
+ // @zmdb/schema/derive/query — the relation-aware half of the read surface.
2
+ //
3
+ // This file used to restate the whole query DTO family, because there were two of them:
4
+ // `../dto/index.ts` was keyed by the schema value and these were keyed by the declared
5
+ // type. There is one family now — `WhereDTO`, `OrderByDTO`, `PaginationDTO`, `Projection`,
6
+ // `GetOptions`, `GetDTO` and `ListDTO` all take the declared type, and they live in
7
+ // `../dto/index.ts` alongside the operator vocabulary and the runtime folders that read
8
+ // them. Two copies of `WhereDTO` were two operator sets to keep in step; the copy is gone
9
+ // and the names below are re-exports, so importing from either path is the same type.
10
+ //
11
+ // What is genuinely *here* is the three shapes that need a relation: a populated row and
12
+ // the two spellings of a join row. Those read `RelationKeys<T>` and the relation tags off
13
+ // the declaration, which is something only a declared type can answer — a schema value
14
+ // carries no relations at all, which is why the version of `Populated` this replaced had
15
+ // to rebuild the cardinality out of a `RelationMeta` through six nested conditionals.
16
+ import {} from './index.js';
17
+ export {} from '../dto/index.js';
18
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/derive/query.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,wFAAwF;AACxF,uFAAuF;AACvF,2FAA2F;AAC3F,oFAAoF;AACpF,wFAAwF;AACxF,0FAA0F;AAC1F,sFAAsF;AACtF,EAAE;AACF,yFAAyF;AACzF,0FAA0F;AAC1F,uFAAuF;AACvF,yFAAyF;AACzF,sFAAsF;AAEtF,OAAO,EAAsD,MAAM,YAAY,CAAC;AAEhF,OAAO,EASN,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,224 @@
1
+ import { type DeclaredTable, type RelationKeys } from '../derive/index.js';
2
+ import { type Entity } from '../index.js';
3
+ /**
4
+ * A row of a table the caller named with a string.
5
+ *
6
+ * A subquery target is `{ table: 'orders' }` — a table *name*, not a declared type — so there
7
+ * is nothing for its filter to be keyed by. This says exactly that much and no more: every
8
+ * property is a column of some SQL type, and none of them is a relation, which is what keeps
9
+ * `WhereDTO` willing to derive from it. It is a named type rather than an inline
10
+ * `Record<string, unknown>` so that it stays the one corner of the query surface that is
11
+ * keyed by string; everything else is keyed by the interface the table was declared as.
12
+ */
13
+ export interface UnknownRow {
14
+ readonly [column: string]: string | number | boolean | bigint | Date | null;
15
+ }
16
+ export type SubqueryTarget<V = unknown> = {
17
+ compile(): {
18
+ readonly text: string;
19
+ readonly parameters: readonly unknown[];
20
+ readonly telemetry?: {
21
+ readonly system: string;
22
+ readonly operation: 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE';
23
+ readonly collection: string;
24
+ };
25
+ };
26
+ readonly _type?: V;
27
+ } | {
28
+ table: string;
29
+ select?: readonly string[];
30
+ where?: WhereDTO<UnknownRow>;
31
+ readonly _type?: V;
32
+ };
33
+ type VectorOperand<V> = NonNullable<V> extends {
34
+ readonly __zmdbExt?: readonly [extension: string, name: 'vector', args: readonly (string | number)[]];
35
+ } ? readonly number[] : never;
36
+ export interface FieldOps<V> {
37
+ eq?: V | SubqueryTarget<V>;
38
+ ne?: V | SubqueryTarget<V>;
39
+ lt?: V | SubqueryTarget<V>;
40
+ lte?: V | SubqueryTarget<V>;
41
+ gt?: V | SubqueryTarget<V>;
42
+ gte?: V | SubqueryTarget<V>;
43
+ in?: readonly V[] | SubqueryTarget<V>;
44
+ nin?: readonly V[] | SubqueryTarget<V>;
45
+ like?: V extends string ? string | SubqueryTarget<string> : never;
46
+ ilike?: V extends string ? string | SubqueryTarget<string> : never;
47
+ l2?: VectorOperand<V>;
48
+ cosine?: VectorOperand<V>;
49
+ ip?: VectorOperand<V>;
50
+ isNull?: boolean;
51
+ notNull?: boolean;
52
+ }
53
+ export type WhereDTO<T extends DeclaredTable> = {
54
+ [K in keyof Entity<T>]?: Entity<T>[K] | FieldOps<Entity<T>[K]>;
55
+ } & {
56
+ and?: readonly WhereDTO<T>[];
57
+ or?: readonly WhereDTO<T>[];
58
+ exists?: SubqueryTarget<unknown> | readonly SubqueryTarget<unknown>[];
59
+ notExists?: SubqueryTarget<unknown> | readonly SubqueryTarget<unknown>[];
60
+ };
61
+ export type OrderDir = 'asc' | 'desc';
62
+ export type OrderByDTO<T extends DeclaredTable> = ReadonlyArray<{
63
+ column: keyof Entity<T>;
64
+ dir?: OrderDir;
65
+ }>;
66
+ export type OffsetPage = {
67
+ limit: number;
68
+ offset?: number | undefined;
69
+ };
70
+ export type PaginationDTO<T extends DeclaredTable> = OffsetPage | {
71
+ limit: number;
72
+ after?: Partial<Entity<T>> | string | undefined;
73
+ before?: Partial<Entity<T>> | string | undefined;
74
+ };
75
+ /**
76
+ * Schema-agnostic views of the order/page DTOs — exactly the fields the folders
77
+ * read. `OrderByDTO<T>`/`PaginationDTO<T>` are structurally assignable to these
78
+ * for *any* `T`, so callers pass their own typed DTO with no
79
+ * `as OrderByDTO<CoreSchema<string>>` widening cast (which is what leaked into
80
+ * consumer code, cf. COOKBOOK "sorting" example).
81
+ */
82
+ export type OrderBySpec = ReadonlyArray<{
83
+ column: PropertyKey;
84
+ dir?: OrderDir;
85
+ }>;
86
+ export type PaginationSpec = {
87
+ limit: number;
88
+ offset?: number | undefined;
89
+ after?: Record<string, unknown> | string | undefined;
90
+ before?: Record<string, unknown> | string | undefined;
91
+ };
92
+ export declare function encodeCursor(payload: Record<string, unknown>): string;
93
+ export declare function decodeCursor(cursor: string): Record<string, unknown>;
94
+ export type Projection<T extends DeclaredTable, K extends keyof Entity<T>> = Pick<Entity<T>, K>;
95
+ /** Narrow a row to `cols` (new object, stable order); passthrough when undefined. */
96
+ export declare function project<Row extends Record<string, unknown>>(row: Row, cols: undefined): Row;
97
+ export declare function project<Row extends Record<string, unknown>, K extends keyof Row>(row: Row, cols: readonly K[]): Pick<Row, K>;
98
+ export declare function project<Row extends Record<string, unknown>, K extends keyof Row>(row: Row, cols: readonly K[] | undefined): Row | Pick<Row, K>;
99
+ export interface GetOptions<T extends DeclaredTable> {
100
+ select?: readonly (keyof Entity<T>)[];
101
+ /**
102
+ * The relations to fetch alongside the row.
103
+ *
104
+ * `RelationKeys<T>` rather than `readonly string[]`: a declared type names its relations,
105
+ * so a misspelled one is a compile error rather than a relation that silently does not
106
+ * arrive. It was a bare `string[]` while this family was keyed by the schema value, which
107
+ * carries no relations to check a name against.
108
+ */
109
+ populate?: readonly RelationKeys<T>[];
110
+ }
111
+ export type GetDTO<T extends DeclaredTable, O extends GetOptions<T> = {}> = O['select'] extends readonly (infer K extends keyof Entity<T>)[] ? Projection<T, K> : Entity<T>;
112
+ /** Apply a Get's select projection to a fetched row. */
113
+ export declare function getResult<Row extends Record<string, unknown>>(row: Row, opts?: {
114
+ select?: readonly (keyof Row)[];
115
+ }): Row | Partial<Row>;
116
+ export interface ListDTO<T extends DeclaredTable> {
117
+ where?: WhereDTO<T>;
118
+ orderBy?: OrderByDTO<T>;
119
+ page?: PaginationDTO<T>;
120
+ select?: readonly (keyof Entity<T>)[];
121
+ }
122
+ export interface ListResult<Row> {
123
+ readonly items: readonly Row[];
124
+ readonly total?: number;
125
+ readonly hasMore: boolean;
126
+ readonly cursor?: string;
127
+ }
128
+ /** Everything `buildListResult` accepts except `select`, which is what its overloads differ on. */
129
+ interface ListOptions {
130
+ limit?: number;
131
+ total?: number;
132
+ cursor?: string;
133
+ orderBy?: OrderBySpec;
134
+ pkColumn?: string;
135
+ }
136
+ /**
137
+ * Assemble a ListResult: limit+1 trim ⇒ hasMore, per-item projection, opt-in total, opaque cursor.
138
+ *
139
+ * Overloaded on `select` so the no-projection call keeps `ListResult<Row>` instead
140
+ * of widening to `ListResult<Row | Partial<Row>>` — the widening is what forced
141
+ * `as ListResult<Entity<T>>` in `@zmdb/orm`'s `list()`.
142
+ */
143
+ export declare function buildListResult<Row extends Record<string, unknown>>(rows: readonly Row[], opts?: ListOptions): ListResult<Row>;
144
+ export declare function buildListResult<Row extends Record<string, unknown>, K extends keyof Row>(rows: readonly Row[], opts: ListOptions & {
145
+ select: readonly K[];
146
+ }): ListResult<Pick<Row, K>>;
147
+ export declare function buildListResult<Row extends Record<string, unknown>>(rows: readonly Row[], opts?: ListOptions & {
148
+ select?: readonly (keyof Row)[];
149
+ }): ListResult<Row | Partial<Row>>;
150
+ export interface SearchDTO<T extends DeclaredTable> {
151
+ query: string;
152
+ columns: readonly (keyof Entity<T>)[];
153
+ where?: WhereDTO<T>;
154
+ page?: PaginationDTO<T>;
155
+ rank?: boolean;
156
+ }
157
+ export type SearchHit<Row> = Row & {
158
+ readonly _score?: number;
159
+ };
160
+ export type SearchResult<Row> = ListResult<SearchHit<Row>>;
161
+ export type AggFn = 'count' | 'sum' | 'avg' | 'min' | 'max';
162
+ /**
163
+ * `"relation.column"` for every relation the table declares.
164
+ *
165
+ * There was a second type parameter for this — the repository's relations map — and each of
166
+ * its entries named the target either as a declared type or as a schema value, so the arm
167
+ * that could see the target's columns was the one where an author had happened to write
168
+ * `entity: Order`; everything else fell back to `${Rel}.${string}`. `RelationKeys<T>` reads
169
+ * the target off the declaration, which every relation has, so every relation gets its
170
+ * columns listed.
171
+ */
172
+ type RelationTargetOf<V> = (NonNullable<V> extends readonly (infer E)[] ? E : NonNullable<V>) & DeclaredTable;
173
+ type RelatedColumns<T extends DeclaredTable> = {
174
+ [Rel in RelationKeys<T> & string]: `${Rel}.${keyof Entity<RelationTargetOf<T[Rel & keyof T]>> & string}`;
175
+ }[RelationKeys<T> & string];
176
+ export type AggregateColumn<T extends DeclaredTable> = (keyof Entity<T> & string) | RelatedColumns<T> | (string & {});
177
+ export interface ComputedSpec<T extends DeclaredTable = DeclaredTable> {
178
+ fn: AggFn;
179
+ column?: AggregateColumn<T>;
180
+ raw?: string;
181
+ }
182
+ export interface AggregateSpec<T extends DeclaredTable> {
183
+ joins?: readonly (RelationKeys<T> & string)[] | readonly {
184
+ relation: RelationKeys<T> & string;
185
+ kind?: 'inner' | 'left' | 'right';
186
+ }[];
187
+ where?: WhereDTO<T> | Record<string, unknown>;
188
+ groupBy?: readonly AggregateColumn<T>[];
189
+ computed: Record<string, ComputedSpec<T>>;
190
+ having?: Readonly<{
191
+ column: AggregateColumn<T>;
192
+ op: string;
193
+ value: unknown;
194
+ }>;
195
+ orderBy?: ReadonlyArray<{
196
+ column: AggregateColumn<T>;
197
+ dir?: OrderDir;
198
+ }>;
199
+ limit?: number;
200
+ offset?: number;
201
+ }
202
+ type AggComputedType<T extends DeclaredTable, C> = C extends {
203
+ fn: 'count';
204
+ } ? number : C extends {
205
+ fn: 'sum' | 'avg';
206
+ } ? number | null : C extends {
207
+ fn: 'min' | 'max';
208
+ column: infer Col extends keyof Entity<T>;
209
+ } ? Entity<T>[Col] | null : number | null;
210
+ export type AggregateResult<T extends DeclaredTable, Spec extends AggregateSpec<T>> = {
211
+ [K in Spec['groupBy'] extends readonly (infer G extends keyof Entity<T>)[] ? G : never]: Entity<T>[K];
212
+ } & {
213
+ [K in keyof Spec['computed']]: AggComputedType<T, Spec['computed'][K]>;
214
+ };
215
+ /** Ordered field list for an aggregate spec: group-key cols then computed keys. */
216
+ export declare function describeAggregate<T extends DeclaredTable>(spec: AggregateSpec<T>): readonly string[];
217
+ /** Assemble a SearchResult (reuses buildListResult; preserves _score on hits). */
218
+ export declare function buildSearchResult<Row extends Record<string, unknown>>(rows: readonly SearchHit<Row>[], opts?: {
219
+ limit?: number;
220
+ select?: readonly (keyof Row)[];
221
+ total?: number;
222
+ }): SearchResult<Row | Partial<Row>>;
223
+ export {};
224
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dto/index.ts"],"names":[],"mappings":"AAAA,OAAO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