@geonosis/document 0.2.0 → 0.4.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 +64 -0
- package/README.md +78 -34
- package/dist/index.cjs +811 -751
- package/dist/index.d.cts +124 -95
- package/dist/index.d.ts +124 -95
- package/dist/index.js +812 -753
- package/migrations/0001_documents.sql +22 -14
- package/migrations/0003_document_revisions.sql +4 -5
- package/package.json +2 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
1
|
# @geonosis/document
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 748795d: 0.4.0, read off the consumer's own callers (#427–#430). Head columns are snake by default
|
|
8
|
+
(`issue_date`, `due_date`, `external_ref`; `columns.heads` renames any, `physicalColumnsOf` is the
|
|
9
|
+
one map) — a rename done before anyone has data. Every entity's `list` sorts by `number`, `createdAt`
|
|
10
|
+
and `updatedAt` beside the head fields, and `documentMigrations` renders the two clock indexes per
|
|
11
|
+
entity. `heads` and `aggregate` narrow by ANY head field (equality, a set, or `{ from, to }` — the
|
|
12
|
+
tuple ranges are gone) plus `createdAt`/`updatedAt` ranges; `aggregate` groups by any head field;
|
|
13
|
+
`heads` answers `HeadRow<Columns>` typed off its `columns`. `freeze` and `names` pass through
|
|
14
|
+
`documentMigrations` to both tables' walls (#429). The shapes that
|
|
15
|
+
carry it: `HeadColumn` (off `HeadField`), `HeadsArgs<Columns>`, `HeadsWhere` (any head field, a set
|
|
16
|
+
or a range, plus the two clocks), `AggregateWhere` (the same), `AggregateBy` (any head field, `entity`,
|
|
17
|
+
or a date bucket), `HeadsOrder` (a clock or `number` beside the heads), `HeadRow<Columns>`,
|
|
18
|
+
`DocumentSortColumn`.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 8d82c01: `documentMigrations` renders `status` as `not null` and the six other head columns nullable, now that
|
|
23
|
+
the entity floor renders indexed columns `not null` by default; `0001_documents.sql` follows.
|
|
24
|
+
- Updated dependencies [e08161b]
|
|
25
|
+
- Updated dependencies [d470d30]
|
|
26
|
+
- @geonosis/db@0.10.0
|
|
27
|
+
|
|
28
|
+
## 0.3.0
|
|
29
|
+
|
|
30
|
+
### Minor Changes
|
|
31
|
+
|
|
32
|
+
- 115366f: `documentStore` is a composition over `@geonosis/db`'s doors — `defineLog` for the revisions,
|
|
33
|
+
`projectionOf` per entity for the documents table, `project`/`aggregate` for `heads` and
|
|
34
|
+
`aggregate` — and the domain spells no SQL (#411). Every contract holds: `hashOf` over the same
|
|
35
|
+
eleven facts, `succeed` at lineage+1 version 1, `at` the database clock, the walls on both legs.
|
|
36
|
+
`documentMigrations` renders through `projectionMigrations` and `logMigrations`: the log's
|
|
37
|
+
`version` and `compensation_of` columns are `bigint` (were `integer`); everything else reads the
|
|
38
|
+
same; `0003_document_revisions.sql` is the one file that changes. The surface table's clock cast is gone — `EntityRow`'s
|
|
39
|
+
clocks are numbers at the floor (#412).
|
|
40
|
+
- eac9ead: `Document.extend` gains `view?: StandardSchemaV1` — what a single-document read RENDERS, defaulting
|
|
41
|
+
to the entity's own `body`; `ViewOf<Entity>` reads it back, and `documentEntities` folds `views`
|
|
42
|
+
beside `bodies`/`cards`. `DocumentDefinition` and `DocumentEntity` gain the type parameter
|
|
43
|
+
`ViewSchema` (defaulting to the body schema) that carries it.
|
|
44
|
+
|
|
45
|
+
`documentSurface({ registry, store, schema })` (#403's T4+T5, folded into one) is new: the wire
|
|
46
|
+
contract as a TABLE, folded over the registry rather than authored by hand. Per entity: `get`,
|
|
47
|
+
`list` (the cursor/sort/filter shape off `EntityListing`, the page envelope with each item's
|
|
48
|
+
instance and card), `history`, `verify`, `commit`, `retire`, `reinstate`, `setStatus` (a `commit` of
|
|
49
|
+
`withStatus` guarded by `canTransition`). Across entities: `heads`, `aggregate`, `shared` (the link
|
|
50
|
+
door: `scope: 'token'`, `{ token }` in, `{ entity, view }` out as a union folded over the registry,
|
|
51
|
+
pending on `document.shared`; `LinkVerifierPort` declared beside the archive and timestamp ports).
|
|
52
|
+
The saga rows (`create`, `send`, `duplicate`, `runStarted`) are
|
|
53
|
+
declared with their own input/output and `call: { pending: 'T3', workflow }` — bound once
|
|
54
|
+
`src/workflows/` lands. `schema: { enum, object, union }` is the one place a consumer's validator
|
|
55
|
+
library (zod) enters; `@geonosis/document` itself stays library-free.
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- Updated dependencies [75dcf32]
|
|
60
|
+
- Updated dependencies [eb688df]
|
|
61
|
+
- Updated dependencies [8bc67fa]
|
|
62
|
+
- Updated dependencies [00ccfd5]
|
|
63
|
+
- Updated dependencies [c985c38]
|
|
64
|
+
- Updated dependencies [ae4a081]
|
|
65
|
+
- @geonosis/db@0.9.0
|
|
66
|
+
|
|
3
67
|
## 0.2.0
|
|
4
68
|
|
|
5
69
|
### 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. `
|
|
43
|
-
`
|
|
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 `
|
|
66
|
-
by identity) — the layer that needs a union or a compiled decoder builds it with its
|
|
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,31 @@ 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
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
`
|
|
109
|
-
|
|
110
|
-
|
|
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, freeze?, names? })` is
|
|
110
|
+
`projectionMigrations` (the seven head columns typed off `FieldKind`, `status` not null and the rest
|
|
111
|
+
nullable, `lineage` carried, `hash`, the version column as the sequence, one index per head field
|
|
112
|
+
and per clock under `(tenant, entity, …)`) plus the `(entity, issue_date)` listing index, then
|
|
113
|
+
`logMigrations` for the revisions table unless `revisions: false` — the same walls the floor renders
|
|
114
|
+
for any log, with `revision_kind` constrained to `committed | retired | reinstated`, and `freeze`/
|
|
115
|
+
`names` passed to both. Head columns are snake by default (`issue_date`, `due_date`,
|
|
116
|
+
`external_ref`); `columns.heads` renames any of them, `columns.total` is the same for `total`.
|
|
117
|
+
`physicalColumnsOf(columns)` is the one map from a head field to its column, exported. `appRole` is
|
|
118
|
+
required whenever the log renders (the default): the name a consumer's application connects as, the
|
|
119
|
+
same law as `@geonosis/db`'s own `appRoleStatements`. The log's own kind column is
|
|
120
|
+
`columns.revisionKind`, `'revision_kind'` when unnamed — never `'kind'`, which is what these docs
|
|
121
|
+
use for `columns.entity` (#407).
|
|
111
122
|
|
|
112
123
|
## Writes
|
|
113
124
|
|
|
@@ -177,29 +188,62 @@ version of its latest lineage, per `(entity, ref)`, and answers how many rows it
|
|
|
177
188
|
consumer's repair tool, and the exam's own way of proving the projection is truly DERIVED.
|
|
178
189
|
|
|
179
190
|
`store.heads({ columns, entity?, order, where? })` is a PROJECTION, never an aggregate: the head
|
|
180
|
-
|
|
181
|
-
ordered by (the tie-break included
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
191
|
+
fields plus `entity` and `number`, typed off `columns` (`HeadRow<Columns>` — no cast), `entity` one
|
|
192
|
+
kind or a set, `order` every column a page is ordered by (the tie-break included; the two clocks
|
|
193
|
+
sort too), `where` any head field as equality, a set, or `{ from, to }`, plus `createdAt`/`updatedAt`
|
|
194
|
+
ranges. `store.aggregate({ by?, entity?, entities?, measures, where? })` answers `count` and
|
|
195
|
+
`sum:total` — `where` the same shape, OPTIONAL — grouped by any head field, `'entity'`, or `{ bucket:
|
|
196
|
+
'day' | 'week' | 'month', of: 'issueDate' | 'dueDate' }`. `count` is a number; `sum:total` is a
|
|
197
|
+
DECIMAL STRING (`'0'` for an empty group) — money never crosses this door as a float either. Both
|
|
198
|
+
are tenant-scoped by the seam and exclude retired rows. `store.<entity>.list` sorts by any head
|
|
199
|
+
field, `number`, `createdAt` or `updatedAt`, and narrows by any head field — logical names in, the
|
|
200
|
+
physical columns underneath.
|
|
201
|
+
|
|
202
|
+
## Surfaces
|
|
203
|
+
|
|
204
|
+
`documentSurface({ registry, store, schema })` (#403's T4+T5, folded into one) is the wire
|
|
205
|
+
CONTRACT — never a second file naming a domain's shapes twice. It returns a TABLE, an array of
|
|
206
|
+
rows (`{ name, verb: 'query' | 'mutation', path, scope: 'org' | 'public' | 'token', input, output,
|
|
207
|
+
call }`), derived by FOLDING over the registry, never a map a caller fills: per entity `get`,
|
|
208
|
+
`list` (input the cursor/sort/filter shape `EntityListing` already answers, output the page
|
|
209
|
+
envelope with each item's own instance AND card), `history`, `verify`, `commit`, `retire`,
|
|
210
|
+
`reinstate`, `setStatus` (a `commit` of `withStatus(body)` guarded by `canTransition` — refuses a
|
|
211
|
+
transition the entity's own status machine never declared, before it writes); across entities,
|
|
212
|
+
`heads`, `aggregate` and `shared`. `shared` is the link door: `scope: 'token'`, input `{ token }`,
|
|
213
|
+
output the union over every entity of `{ entity, view }` folded off the registry, the tenant read
|
|
214
|
+
from the token by `LinkVerifierPort` and never from the handle; it is declared pending on the
|
|
215
|
+
`document.shared` workflow like the saga rows. The saga rows an entity gets for free — `create`
|
|
216
|
+
(with numbering), `send`, `duplicate`, `runStarted` — are DECLARED with their own input/output and
|
|
217
|
+
`call: { pending: 'T3', workflow }` in place of a function: an adapter mounting the table refuses
|
|
218
|
+
those BY NAME (`typeof row.call !== 'function'`), never with a stub answer.
|
|
219
|
+
|
|
220
|
+
The table is the contract; an adapter (tRPC, REST, MCP) is thin — it reads a row's `name`, `verb`,
|
|
221
|
+
`path` and `scope` for its own wiring, hands `input`/`output` to whatever transport-level
|
|
222
|
+
validation it already does, and calls `call(handle, params)` with a handle already open for the
|
|
223
|
+
right tenant. `documentSurface` never touches a validator library itself: `schema: { enum, object,
|
|
224
|
+
union }` is a three-builder adapter the CALLER hands in, so `setStatus`'s enum (built from the
|
|
225
|
+
entity's own `statuses`) and `shared`'s union (folded from the registry's views) come back as REAL
|
|
226
|
+
schemas of whatever library the caller's `object`/`union`/`enum` wrap them in — zod is the one
|
|
227
|
+
place it enters a repo composing this domain, never a dependency of `@geonosis/document` itself
|
|
228
|
+
(`src/no-schema-library-at-runtime.test.ts` holds the built door to that).
|
|
187
229
|
|
|
188
230
|
## What does not exist yet
|
|
189
231
|
|
|
190
232
|
`src/store/` ships the commits (`commit`, `retire`, `succeed`, `reinstate`, `get`, `at`, `asOf`,
|
|
191
233
|
`history`, `verify`, `rebuild`, `heads`, `aggregate`) and the archive/timestamp ports declared, not
|
|
192
234
|
mirrored; it ships no search projection yet. `upsert` and `revisions` are GONE (replaced by
|
|
193
|
-
`commit`; `history`). `src/
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
235
|
+
`commit`; `history`). `src/surface/` ships the table above; its saga rows stay PENDING until
|
|
236
|
+
`src/workflows/` (the org's engine, the only internal folder that may import it — the archive
|
|
237
|
+
mirror lands there too) lands and binds them. `src/contract/` (a layer the surface table already
|
|
238
|
+
supersedes — #403), `src/ui/` (the view axis) and `src/conformance/` (the exam a consumer runs
|
|
239
|
+
against their own provider) are later tickets — the internal layout is declared now (and held by
|
|
240
|
+
`layer-walls`) so each lands inside the wall already drawn for it.
|
|
198
241
|
|
|
199
242
|
## One door, and what holds it
|
|
200
243
|
|
|
201
244
|
`sideEffects: false`; inside the package the in-package wall is `layer-walls`, planted in
|
|
202
245
|
`src/__fixtures__/walls/` and proved through the real binary in `src/walls.test.ts` — the core may
|
|
203
246
|
reach `@geonosis/conformance` and nothing else, the store may reach `@geonosis/db` and
|
|
204
|
-
`@geonosis/conformance` and nothing else,
|
|
247
|
+
`@geonosis/conformance` and nothing else, `src/surface/` may reach the core, the store and the
|
|
248
|
+
workflows layer and nothing lower, and only `src/workflows/` may reach `@geonosis/workflows`
|
|
205
249
|
directly (D-052 — the org's engine is a direct dependency of this domain).
|