@geonosis/document 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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,44 @@
1
1
  # @geonosis/document
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 115366f: `documentStore` is a composition over `@geonosis/db`'s doors — `defineLog` for the revisions,
8
+ `projectionOf` per entity for the documents table, `project`/`aggregate` for `heads` and
9
+ `aggregate` — and the domain spells no SQL (#411). Every contract holds: `hashOf` over the same
10
+ eleven facts, `succeed` at lineage+1 version 1, `at` the database clock, the walls on both legs.
11
+ `documentMigrations` renders through `projectionMigrations` and `logMigrations`: the log's
12
+ `version` and `compensation_of` columns are `bigint` (were `integer`); everything else reads the
13
+ same; `0003_document_revisions.sql` is the one file that changes. The surface table's clock cast is gone — `EntityRow`'s
14
+ clocks are numbers at the floor (#412).
15
+ - eac9ead: `Document.extend` gains `view?: StandardSchemaV1` — what a single-document read RENDERS, defaulting
16
+ to the entity's own `body`; `ViewOf<Entity>` reads it back, and `documentEntities` folds `views`
17
+ beside `bodies`/`cards`. `DocumentDefinition` and `DocumentEntity` gain the type parameter
18
+ `ViewSchema` (defaulting to the body schema) that carries it.
19
+
20
+ `documentSurface({ registry, store, schema })` (#403's T4+T5, folded into one) is new: the wire
21
+ contract as a TABLE, folded over the registry rather than authored by hand. Per entity: `get`,
22
+ `list` (the cursor/sort/filter shape off `EntityListing`, the page envelope with each item's
23
+ instance and card), `history`, `verify`, `commit`, `retire`, `reinstate`, `setStatus` (a `commit` of
24
+ `withStatus` guarded by `canTransition`). Across entities: `heads`, `aggregate`, `shared` (the link
25
+ door: `scope: 'token'`, `{ token }` in, `{ entity, view }` out as a union folded over the registry,
26
+ pending on `document.shared`; `LinkVerifierPort` declared beside the archive and timestamp ports).
27
+ The saga rows (`create`, `send`, `duplicate`, `runStarted`) are
28
+ declared with their own input/output and `call: { pending: 'T3', workflow }` — bound once
29
+ `src/workflows/` lands. `schema: { enum, object, union }` is the one place a consumer's validator
30
+ library (zod) enters; `@geonosis/document` itself stays library-free.
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [75dcf32]
35
+ - Updated dependencies [eb688df]
36
+ - Updated dependencies [8bc67fa]
37
+ - Updated dependencies [00ccfd5]
38
+ - Updated dependencies [c985c38]
39
+ - Updated dependencies [ae4a081]
40
+ - @geonosis/db@0.9.0
41
+
3
42
  ## 0.2.0
4
43
 
5
44
  ### Minor Changes
package/README.md CHANGED
@@ -39,8 +39,10 @@ its derived validator — what storage adds once a document is written.
39
39
  `bodyVersion`/`migrations` — see body versioning below) and returns it with `is()`, a type guard
40
40
  narrowing on the entity's own name. `card` is `{ schema, of(document, { counterpartyName }) }` — ONE
41
41
  shape, what the list endpoint returns per row and what the UI's list reads; the floor carries the
42
- card's schema and never looks inside it. `InstanceOf`, `BodyOf`, `DraftOf`, `IncomingOf`, `StatusOf`,
43
- `CardOf` and `NameOf` read the pieces back off an entity, generically, through
42
+ card's schema and never looks inside it. `view` (optional) is what a single-document READ renders —
43
+ absent, `Document.extend` fills it with the entity's own `body` schema, so a consumer that never
44
+ needs a distinct render shape names nothing extra. `InstanceOf`, `BodyOf`, `DraftOf`, `IncomingOf`,
45
+ `StatusOf`, `CardOf`, `ViewOf` and `NameOf` read the pieces back off an entity, generically, through
44
46
  `StandardSchemaV1.InferOutput`.
45
47
 
46
48
  ## `documentEntities`
@@ -62,8 +64,9 @@ keyed by name, and:
62
64
  cross-entity concern (a union type, a compiled decoder, a per-entity effect) registers by
63
65
  extending the fold and checks its own coverage once, at ITS composition root; that layer, never
64
66
  this one, is where `z.union`/`z.compile`/`z.enum` now live;
65
- - `bodies` and `cards` are the DISTINCT declared body/card schemas (`StandardSchemaV1[]`, deduplicated
66
- by identity) — the layer that needs a union or a compiled decoder builds it with its OWN library;
67
+ - `bodies`, `cards` and `views` are the DISTINCT declared body/card/view schemas (`StandardSchemaV1[]`,
68
+ deduplicated by identity) — the layer that needs a union or a compiled decoder builds it with its
69
+ OWN library;
67
70
  - `instance(name, parts)` stamps a document with the entity name it was minted for; `named(name)`
68
71
  hands back one entity's own definition.
69
72
 
@@ -91,23 +94,26 @@ nothing.
91
94
 
92
95
  `documentStore({ registry, seam, table?, schema?, columns?, revisions?, archive? })` is ONE table
93
96
  for every document entity the registry holds — never one table per entity — plus the append-only
94
- log beside it. Per entity, a `defineEntity` (`@geonosis/db`) supplies `get`/`list`/`listAll` only
95
- — the write model below has its own transaction shape and does not go through `defineEntity`'s
96
- upsert path. `key: { column: 'number', param: 'ref' }`: `ref` (D-065) is the parameter every write
97
- and read addresses a document by; `number` stays the PROJECTION's own physical column and head
98
- field, unchanged. `constants: { [columns.entity ?? 'entity']: name }` is the discriminator two
99
- entities on one table disagree on — a `ref` may repeat ACROSS entities and both rows exist,
100
- discriminated by nothing else. `indexed`/`sortable`/`filterable` are the seven
101
- `Document.headFields` columns, named off the field spec — never a second list.
102
-
103
- `documentMigrations({ table?, schema?, columns?, revisions?, appRole })` renders the projection's
104
- DDL — the seven head columns typed off `FieldKind`, `lineage` and `hash` beside the usual clocks —
105
- and the log's, unless `revisions: false`. `appRole` is required whenever the log renders (the
106
- default): the name a consumer's application connects as, the same law as
107
- `@geonosis/db`'s own `appRoleStatements` (nothing here can pick it). The log's own
108
- `committed | retired | reinstated` column is `columns.revisionKind`, `'revision_kind'` when
109
- unnamed — never `'kind'`, which is what these docs use for `columns.entity`, and a consumer who
110
- names their own entity column `kind` would otherwise get one physical column declared twice (#407).
97
+ log beside it, and it spells no SQL: the log is `@geonosis/db`'s `defineLog` keyed by `(entity,
98
+ ref, lineage)` with `revision_kind` as its extra column and `hashOf` as its `hash`; each entity's
99
+ projection is `projectionOf` over the documents table, keyed `{ column: 'number', param: 'ref' }`
100
+ (`ref` per D-065 is the parameter, `number` the head field and column), discriminated by
101
+ `constants: { [columns.entity ?? 'entity']: name }`, carrying `lineage` beside its row;
102
+ `get`/`list`/`listAll` are the projection's own; `heads` and `aggregate` are `project` and
103
+ `aggregate` on one further `defineEntity` over the same table with no constant, whose `filterable`
104
+ columns are the seven head columns, the entity column and `created_at`. Every write is `lockLatest`
105
+ → `append` → `write` in one transaction; `at`, `asOf`, `history`, `verify` are the log's own doors
106
+ on the current lineage; `rebuild` folds `latestPerStream` to the highest lineage per `(entity, ref)`
107
+ and writes it back.
108
+
109
+ `documentMigrations({ table?, schema?, columns?, revisions?, appRole })` is `projectionMigrations`
110
+ (the seven head columns typed off `FieldKind`, `lineage` carried, `hash`, the version column as the
111
+ sequence) plus the `(entity, issueDate)` listing index, then `logMigrations` for the revisions
112
+ table unless `revisions: false` — the same walls the floor renders for any log, with `revision_kind`
113
+ constrained to `committed | retired | reinstated`. `appRole` is required whenever the log renders
114
+ (the default): the name a consumer's application connects as, the same law as `@geonosis/db`'s own
115
+ `appRoleStatements`. The log's own kind column is `columns.revisionKind`, `'revision_kind'` when
116
+ unnamed — never `'kind'`, which is what these docs use for `columns.entity` (#407).
111
117
 
112
118
  ## Writes
113
119
 
@@ -185,21 +191,51 @@ a number; `sum:total` is a DECIMAL STRING (`sum("total")::text`, `'0'` for an em
185
191
  never crosses this door as a float either. Both are tenant-scoped by the seam and exclude retired
186
192
  rows.
187
193
 
194
+ ## Surfaces
195
+
196
+ `documentSurface({ registry, store, schema })` (#403's T4+T5, folded into one) is the wire
197
+ CONTRACT — never a second file naming a domain's shapes twice. It returns a TABLE, an array of
198
+ rows (`{ name, verb: 'query' | 'mutation', path, scope: 'org' | 'public' | 'token', input, output,
199
+ call }`), derived by FOLDING over the registry, never a map a caller fills: per entity `get`,
200
+ `list` (input the cursor/sort/filter shape `EntityListing` already answers, output the page
201
+ envelope with each item's own instance AND card), `history`, `verify`, `commit`, `retire`,
202
+ `reinstate`, `setStatus` (a `commit` of `withStatus(body)` guarded by `canTransition` — refuses a
203
+ transition the entity's own status machine never declared, before it writes); across entities,
204
+ `heads`, `aggregate` and `shared`. `shared` is the link door: `scope: 'token'`, input `{ token }`,
205
+ output the union over every entity of `{ entity, view }` folded off the registry, the tenant read
206
+ from the token by `LinkVerifierPort` and never from the handle; it is declared pending on the
207
+ `document.shared` workflow like the saga rows. The saga rows an entity gets for free — `create`
208
+ (with numbering), `send`, `duplicate`, `runStarted` — are DECLARED with their own input/output and
209
+ `call: { pending: 'T3', workflow }` in place of a function: an adapter mounting the table refuses
210
+ those BY NAME (`typeof row.call !== 'function'`), never with a stub answer.
211
+
212
+ The table is the contract; an adapter (tRPC, REST, MCP) is thin — it reads a row's `name`, `verb`,
213
+ `path` and `scope` for its own wiring, hands `input`/`output` to whatever transport-level
214
+ validation it already does, and calls `call(handle, params)` with a handle already open for the
215
+ right tenant. `documentSurface` never touches a validator library itself: `schema: { enum, object,
216
+ union }` is a three-builder adapter the CALLER hands in, so `setStatus`'s enum (built from the
217
+ entity's own `statuses`) and `shared`'s union (folded from the registry's views) come back as REAL
218
+ schemas of whatever library the caller's `object`/`union`/`enum` wrap them in — zod is the one
219
+ place it enters a repo composing this domain, never a dependency of `@geonosis/document` itself
220
+ (`src/no-schema-library-at-runtime.test.ts` holds the built door to that).
221
+
188
222
  ## What does not exist yet
189
223
 
190
224
  `src/store/` ships the commits (`commit`, `retire`, `succeed`, `reinstate`, `get`, `at`, `asOf`,
191
225
  `history`, `verify`, `rebuild`, `heads`, `aggregate`) and the archive/timestamp ports declared, not
192
226
  mirrored; it ships no search projection yet. `upsert` and `revisions` are GONE (replaced by
193
- `commit`; `history`). `src/workflows/` (the org's engine, the only internal folder that may import
194
- it — the archive mirror lands there), `src/contract/` (the wire schemas), `src/surface/` (the
195
- procedure/route/tool mounts), `src/ui/` (the view axis) and `src/conformance/` (the exam a consumer
196
- runs against their own provider) are later tickets — the internal layout is declared now (and held
197
- by `layer-walls`) so each lands inside the wall already drawn for it.
227
+ `commit`; `history`). `src/surface/` ships the table above; its saga rows stay PENDING until
228
+ `src/workflows/` (the org's engine, the only internal folder that may import it — the archive
229
+ mirror lands there too) lands and binds them. `src/contract/` (a layer the surface table already
230
+ supersedes — #403), `src/ui/` (the view axis) and `src/conformance/` (the exam a consumer runs
231
+ against their own provider) are later tickets — the internal layout is declared now (and held by
232
+ `layer-walls`) so each lands inside the wall already drawn for it.
198
233
 
199
234
  ## One door, and what holds it
200
235
 
201
236
  `sideEffects: false`; inside the package the in-package wall is `layer-walls`, planted in
202
237
  `src/__fixtures__/walls/` and proved through the real binary in `src/walls.test.ts` — the core may
203
238
  reach `@geonosis/conformance` and nothing else, the store may reach `@geonosis/db` and
204
- `@geonosis/conformance` and nothing else, and only `src/workflows/` may reach `@geonosis/workflows`
239
+ `@geonosis/conformance` and nothing else, `src/surface/` may reach the core, the store and the
240
+ workflows layer and nothing lower, and only `src/workflows/` may reach `@geonosis/workflows`
205
241
  directly (D-052 — the org's engine is a direct dependency of this domain).