@substrat-run/contracts 0.75.0 → 0.77.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.
- package/dist/introspection.d.ts +1 -1
- package/dist/introspection.js +1 -1
- package/dist/model.d.ts +46 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +37 -0
- package/dist/model.js.map +1 -1
- package/dist/platform-request.d.ts +1 -1
- package/dist/platform-request.js +1 -1
- package/package.json +1 -1
package/dist/introspection.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ export type ScopeQueryResult = z.infer<typeof scopeQueryResult>;
|
|
|
80
80
|
* scope: every table, its DDL, and every row, so it can rebuild the scope elsewhere.
|
|
81
81
|
*
|
|
82
82
|
* It is the privileged primitive the preview/snapshot machinery is built on
|
|
83
|
-
* (docs/
|
|
83
|
+
* (docs/architecture/preview-and-snapshots.md §3) — the source a fork or a local pull
|
|
84
84
|
* reads. It KEEPS the `_substrat_*` spine (a fork must carry the event/migration
|
|
85
85
|
* state) and drops only SQLite's own `sqlite_*` internals (auto-managed, and
|
|
86
86
|
* `CREATE TABLE sqlite_*` is rejected on reload). Because it exfiltrates a whole
|
package/dist/introspection.js
CHANGED
|
@@ -80,7 +80,7 @@ export const scopeQueryResult = z.object({
|
|
|
80
80
|
* scope: every table, its DDL, and every row, so it can rebuild the scope elsewhere.
|
|
81
81
|
*
|
|
82
82
|
* It is the privileged primitive the preview/snapshot machinery is built on
|
|
83
|
-
* (docs/
|
|
83
|
+
* (docs/architecture/preview-and-snapshots.md §3) — the source a fork or a local pull
|
|
84
84
|
* reads. It KEEPS the `_substrat_*` spine (a fork must carry the event/migration
|
|
85
85
|
* state) and drops only SQLite's own `sqlite_*` internals (auto-managed, and
|
|
86
86
|
* `CREATE TABLE sqlite_*` is rejected on reload). Because it exfiltrates a whole
|
package/dist/model.d.ts
CHANGED
|
@@ -44,6 +44,31 @@ export interface EntityDef<Names extends string = string> {
|
|
|
44
44
|
* kernel means and cannot express the real cases.
|
|
45
45
|
*/
|
|
46
46
|
readonly parents?: readonly Names[];
|
|
47
|
+
/**
|
|
48
|
+
* The table's identity. Defaults to `['id']`.
|
|
49
|
+
*
|
|
50
|
+
* **Declared, because not every table's identity is an `id`.** The `vertical_`
|
|
51
|
+
* side table keyed by an engine's id — the composition pattern the design
|
|
52
|
+
* rules prescribe — has no id of its own to have, and inventing one would be
|
|
53
|
+
* wrong: it would permit two side rows for one work order, which is the very
|
|
54
|
+
* thing the primary key exists to prevent. Value-keyed tables are the same
|
|
55
|
+
* shape: a counter per `(kind, year)`, a budget per `(customer, year, month)`.
|
|
56
|
+
*
|
|
57
|
+
* **Kept distinct from `key`, because SQL's own distinction is the useful
|
|
58
|
+
* one.** `primaryKey` is identity; `key` is an additional uniqueness rule. A
|
|
59
|
+
* table legitimately has both — a composite primary key and a separate
|
|
60
|
+
* natural key — so reading `key` as the primary key when an entity has no
|
|
61
|
+
* `id` would conflate two facts to save a field.
|
|
62
|
+
*
|
|
63
|
+
* Order is significant and preserved: a composite primary key is also the
|
|
64
|
+
* index its columns are searched by, left to right.
|
|
65
|
+
*
|
|
66
|
+
* An entity with neither `primaryKey` nor an `id` field is an ERROR, not a
|
|
67
|
+
* table without a primary key. That silence is what let 15 of one production
|
|
68
|
+
* vertical's 63 tables emit with no primary key at all while a column-by-column
|
|
69
|
+
* parity check reported 63/63 (#804).
|
|
70
|
+
*/
|
|
71
|
+
readonly primaryKey?: readonly string[];
|
|
47
72
|
/** Natural key, if any. Must name fields that exist. */
|
|
48
73
|
readonly key?: readonly string[];
|
|
49
74
|
/** Fields an erasure must be able to reach (§12). Must name fields that exist. */
|
|
@@ -80,6 +105,7 @@ export type EntityFields<E> = E extends {
|
|
|
80
105
|
*/
|
|
81
106
|
export declare function defineEntities<T extends {
|
|
82
107
|
readonly [K in keyof T]: EntityDef<keyof T & string> & {
|
|
108
|
+
primaryKey?: readonly EntityFields<T[K]>[];
|
|
83
109
|
key?: readonly EntityFields<T[K]>[];
|
|
84
110
|
erasable?: readonly EntityFields<T[K]>[];
|
|
85
111
|
renamedFrom?: Readonly<Partial<Record<EntityFields<T[K]>, string>>>;
|
|
@@ -87,6 +113,20 @@ export declare function defineEntities<T extends {
|
|
|
87
113
|
}>(entities: T): T;
|
|
88
114
|
/** The declared entity names. */
|
|
89
115
|
export type EntityName<T> = keyof T & string;
|
|
116
|
+
/**
|
|
117
|
+
* The entity's primary key — declared, or `['id']` if it has an `id` field.
|
|
118
|
+
*
|
|
119
|
+
* Resolved in one place because two callers need the same answer and the same
|
|
120
|
+
* refusal: the DDL emitter, which cannot write a `CREATE TABLE` without it, and
|
|
121
|
+
* `emitModel`, so the artifact of record carries the fact rather than leaving it
|
|
122
|
+
* to be re-derived by whoever reads it.
|
|
123
|
+
*
|
|
124
|
+
* **It throws rather than returning nothing.** A table with no primary key is
|
|
125
|
+
* not a shape the model may express: it accepts duplicate rows silently, and a
|
|
126
|
+
* parity check that compares columns — the natural one to write — reports a
|
|
127
|
+
* perfect match over it (#804).
|
|
128
|
+
*/
|
|
129
|
+
export declare function primaryKeyOf(name: string, entity: EntityDef): readonly string[];
|
|
90
130
|
/**
|
|
91
131
|
* The serialisable form — the artifact of record.
|
|
92
132
|
*
|
|
@@ -104,6 +144,12 @@ export interface EmittedEntity {
|
|
|
104
144
|
readonly fields: Record<string, unknown>;
|
|
105
145
|
/** The permitted parent types, sorted. One shape, always. */
|
|
106
146
|
readonly parents?: readonly string[];
|
|
147
|
+
/**
|
|
148
|
+
* Present only when it is not the `['id']` default, and **unsorted** — unlike
|
|
149
|
+
* `key`, a primary key's column order is part of the fact, so sorting it for a
|
|
150
|
+
* tidier diff would emit a different index than the one declared.
|
|
151
|
+
*/
|
|
152
|
+
readonly primaryKey?: readonly string[];
|
|
107
153
|
readonly key?: readonly string[];
|
|
108
154
|
readonly erasable?: readonly string[];
|
|
109
155
|
}
|
package/dist/model.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":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C,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;IAC3F,MAAM,EAAE,MAAM,CAAC,CAAC;CACjB,GACG,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,GAClC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GACV,KAAK,GACP,KAAK,CAAC;AAGV,6EAA6E;AAC7E,eAAO,MAAM,WAAW,mBAAmB,CAAC;AAE5C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,CAGrD"}
|
package/dist/model.js
CHANGED
|
@@ -35,6 +35,39 @@ import { z } from 'zod';
|
|
|
35
35
|
export function defineEntities(entities) {
|
|
36
36
|
return entities;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The entity's primary key — declared, or `['id']` if it has an `id` field.
|
|
40
|
+
*
|
|
41
|
+
* Resolved in one place because two callers need the same answer and the same
|
|
42
|
+
* refusal: the DDL emitter, which cannot write a `CREATE TABLE` without it, and
|
|
43
|
+
* `emitModel`, so the artifact of record carries the fact rather than leaving it
|
|
44
|
+
* to be re-derived by whoever reads it.
|
|
45
|
+
*
|
|
46
|
+
* **It throws rather than returning nothing.** A table with no primary key is
|
|
47
|
+
* not a shape the model may express: it accepts duplicate rows silently, and a
|
|
48
|
+
* parity check that compares columns — the natural one to write — reports a
|
|
49
|
+
* perfect match over it (#804).
|
|
50
|
+
*/
|
|
51
|
+
export function primaryKeyOf(name, entity) {
|
|
52
|
+
const shape = entity.fields.shape;
|
|
53
|
+
const declared = entity.primaryKey;
|
|
54
|
+
if (declared?.length) {
|
|
55
|
+
for (const col of declared) {
|
|
56
|
+
if (!(col in shape)) {
|
|
57
|
+
throw new Error(`model: ${name}.primaryKey names '${col}', which is not a field`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (new Set(declared).size !== declared.length) {
|
|
61
|
+
throw new Error(`model: ${name}.primaryKey repeats a column — (${declared.join(', ')})`);
|
|
62
|
+
}
|
|
63
|
+
return declared;
|
|
64
|
+
}
|
|
65
|
+
if ('id' in shape)
|
|
66
|
+
return ['id'];
|
|
67
|
+
throw new Error(`model: ${name} has no 'id' field and declares no \`primaryKey\` — a table without a ` +
|
|
68
|
+
'primary key accepts duplicate rows. Declare the columns that identify a row, e.g. ' +
|
|
69
|
+
"`primaryKey: ['workorder_id']` for a side table keyed by an engine's id");
|
|
70
|
+
}
|
|
38
71
|
/**
|
|
39
72
|
* Render the registry to plain JSON. Deterministic: entities and their fields
|
|
40
73
|
* are emitted in sorted order, so the checked-in artifact diffs cleanly and a
|
|
@@ -51,6 +84,10 @@ export function emitModel(entities) {
|
|
|
51
84
|
table: e.table,
|
|
52
85
|
fields,
|
|
53
86
|
...(e.parents?.length ? { parents: [...e.parents].sort() } : {}),
|
|
87
|
+
// Resolved, not just copied: this also refuses an entity with no identity
|
|
88
|
+
// at all, so `lint:model --check` goes red on it the same way the DDL
|
|
89
|
+
// emitter does.
|
|
90
|
+
...(primaryKeyOf(name, e).join() === 'id' ? {} : { primaryKey: primaryKeyOf(name, e) }),
|
|
54
91
|
...(e.key ? { key: [...e.key].sort() } : {}),
|
|
55
92
|
...(e.erasable ? { erasable: [...e.erasable].sort() } : {}),
|
|
56
93
|
};
|
package/dist/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,K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|
-
* Platform intents (docs/
|
|
3
|
+
* Platform intents (docs/architecture/platform-intents.md) — how a sandbox-clean vertical asks the
|
|
4
4
|
* platform to perform a privileged action (provision a sibling scope, request quota, …) without
|
|
5
5
|
* an upward call. A vertical operation enqueues a typed intent into its own scope's
|
|
6
6
|
* `_substrat_platform_requests` spine table via `ctx.requestPlatform`; the platform pulls and
|
package/dist/platform-request.js
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { instant, platformRequestId, scopeId } from './ids.js';
|
|
3
3
|
import { actor, domainEvent } from './events.js';
|
|
4
4
|
/**
|
|
5
|
-
* Platform intents (docs/
|
|
5
|
+
* Platform intents (docs/architecture/platform-intents.md) — how a sandbox-clean vertical asks the
|
|
6
6
|
* platform to perform a privileged action (provision a sibling scope, request quota, …) without
|
|
7
7
|
* an upward call. A vertical operation enqueues a typed intent into its own scope's
|
|
8
8
|
* `_substrat_platform_requests` spine table via `ctx.requestPlatform`; the platform pulls and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@substrat-run/contracts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.77.0",
|
|
4
4
|
"description": "Substrat kernel contract schemas — Zod is the source of truth (master plan D-22); OAS/JSON Schema are emitted artifacts",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|