@geonosis/document 0.6.0 → 0.8.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 +73 -0
- package/README.md +44 -5
- package/dist/{chunk-WWP7MNI7.js → chunk-A6ZU4QU3.js} +6 -15
- package/dist/chunk-NA3DLROL.js +171 -0
- package/dist/{ports-D0NtPwAO.d.cts → entities-DTNJMeVf.d.cts} +3 -31
- package/dist/{ports-D0NtPwAO.d.ts → entities-DTNJMeVf.d.ts} +3 -31
- package/dist/index.cjs +177 -3
- package/dist/index.d.cts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +35 -5
- package/dist/ports-C_OfflMQ.d.cts +66 -0
- package/dist/ports-C_OfflMQ.d.ts +66 -0
- package/dist/store.cjs +19 -6
- package/dist/store.d.cts +12 -20
- package/dist/store.d.ts +12 -20
- package/dist/store.js +15 -88
- package/dist/workflows.cjs +513 -0
- package/dist/workflows.d.cts +310 -0
- package/dist/workflows.d.ts +310 -0
- package/dist/workflows.js +386 -0
- package/package.json +15 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,78 @@
|
|
|
1
1
|
# @geonosis/document
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0f99e26: `ConformanceCase` and `CaseContext` move here — the shape `@geonosis/db`, `@geonosis/workflows` and
|
|
8
|
+
search's `SearchConformanceCase` each declared on their own, for the third time (#192's pattern,
|
|
9
|
+
this pass's row 743). Both floors and the domain re-export the same names unchanged; no consumer
|
|
10
|
+
import moves.
|
|
11
|
+
|
|
12
|
+
`@geonosis/document` stops restating `AggregateRow` and imports the one `@geonosis/db` already exports — same shape, one declaration. No consumer import moves.
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 0f99e26: `canonicalOf` — the form `hashOf` and every stored chain are computed over — no longer depends on the machine's language: keys sort with the `en-US` collation every stored hash was written under, named rather than inherited, so a recomputation on a machine set to another locale (Estonian sorts `z` before `t`) agrees with the chain. It also reads a value as JSON writes it, so a `Date` is its ISO string rather than `{}`. Every hash computed in an `en-US` runtime is unchanged, held by golden hashes; a hash computed over an in-memory `Date` never matched the string it was stored as, and now does.
|
|
17
|
+
- Updated dependencies [0f99e26]
|
|
18
|
+
- Updated dependencies [0f99e26]
|
|
19
|
+
- Updated dependencies [0f99e26]
|
|
20
|
+
- Updated dependencies [0f99e26]
|
|
21
|
+
- Updated dependencies [0f99e26]
|
|
22
|
+
- Updated dependencies [0f99e26]
|
|
23
|
+
- Updated dependencies [0f99e26]
|
|
24
|
+
- Updated dependencies [0f99e26]
|
|
25
|
+
- Updated dependencies [0f99e26]
|
|
26
|
+
- Updated dependencies [0f99e26]
|
|
27
|
+
- Updated dependencies [0f99e26]
|
|
28
|
+
- Updated dependencies [0f99e26]
|
|
29
|
+
- Updated dependencies [0f99e26]
|
|
30
|
+
- Updated dependencies [0f99e26]
|
|
31
|
+
- Updated dependencies [0f99e26]
|
|
32
|
+
- Updated dependencies [0f99e26]
|
|
33
|
+
- Updated dependencies [0f99e26]
|
|
34
|
+
- @geonosis/workflows@0.6.0
|
|
35
|
+
- @geonosis/db@0.13.0
|
|
36
|
+
|
|
37
|
+
## 0.7.0
|
|
38
|
+
|
|
39
|
+
### Minor Changes
|
|
40
|
+
|
|
41
|
+
- d90986b: Every refusal the document workflows throw is named. `DocumentNotFound` (entity, ref),
|
|
42
|
+
`DocumentTaken` (entity, ref), `NumberingRefused` (entity, mode `given` | `counter`),
|
|
43
|
+
`TransitionRefused` (entity, ref, from, to), `DocumentNotRemovable` (entity) and
|
|
44
|
+
`ConversionRefused` (entity, ref) are `TaggedError`s exported from `./workflows` with their tags
|
|
45
|
+
and a `DocumentRefusal` union; the messages are the sentences they always were. The engine wraps
|
|
46
|
+
what a body throws in `RunFailedError` with the refusal as `cause`, so a host reads the name off
|
|
47
|
+
the cause and answers 404, 409 or 400 — during.day's `/v1` answered 500 to a missing ref, with the
|
|
48
|
+
sentence inside the problem document, because a plain `Error` is all `problemOf` had to map.
|
|
49
|
+
- d90986b: `heads` carries the record's clocks: `HeadColumn` admits `createdAt` and `updatedAt` beside the
|
|
50
|
+
business head, the entity and the number, and `HeadRow` types them as instants. The store already
|
|
51
|
+
projected them — `where` and `order` took the clocks — but the column type did not, so a consumer
|
|
52
|
+
bucketing documents by the month they were created read every instance through `listAll`
|
|
53
|
+
(during.day `documents.ts:350`). A type fixture pins it and the Postgres exam reads them back.
|
|
54
|
+
- c8c5d51: `documentWorkflows(entity, { effects, ports })` at `@geonosis/document/workflows` — T3, the org
|
|
55
|
+
workflows over the engine, one body per Document: `create`, `save`, `setStatus`, `remove`, `send`
|
|
56
|
+
(durable), `convert`, `duplicate`, `share`, each named for the entity. A host decides
|
|
57
|
+
`effects.announce(fact)` — the product's events off a `DocumentFact` — and answers three ports,
|
|
58
|
+
`door`, `link` and `mail` (`Result<void, MailUndelivered>` from `better-result`); `beforeCreate`,
|
|
59
|
+
`conversion`, the mail words, `counter`, `actor`, `guard`, `now` and `seed` default, and a
|
|
60
|
+
counter-numbered entity or a template on a host that declares neither is refused by name. The
|
|
61
|
+
factory makes the two steps that reach the outside world, so the durable-body law holds on every
|
|
62
|
+
host. A third entry, like `./store`, so the core stays off every floor and browser-safe. The
|
|
63
|
+
Standard Schema builders the surface wrote for itself move to the core (`objectOf`, `enumOf`,
|
|
64
|
+
`optional`, `nullable`, `arrayOf`, `merge`, the scalars, `validate`) and `SchemaAdapter` is the
|
|
65
|
+
adapter's name (`SurfaceSchemaAdapter` stays as an alias). `@geonosis/workflows` and
|
|
66
|
+
`better-result` join the package's dependencies. The plugin's `document-sagas-are-generic` and
|
|
67
|
+
`documents-share-one-table` no longer carry `floor: pending`: the store shipped at 0.4 and the
|
|
68
|
+
workflows ship here. `documentIdentifiers` spells every identifier as a literal type off the name it was given (`CamelOf`, `DocumentIdentifiers`), so a consumer indexes a typed router map by the camel name without a cast. `documentEntities(map).keyed(pick)` answers one value per entity under its name, total by construction.
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- Updated dependencies [d90986b]
|
|
73
|
+
- Updated dependencies [d90986b]
|
|
74
|
+
- @geonosis/db@0.12.0
|
|
75
|
+
|
|
3
76
|
## 0.6.0
|
|
4
77
|
|
|
5
78
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -70,6 +70,11 @@ keyed by name, and:
|
|
|
70
70
|
- `instance(name, parts)` stamps a document with the entity name it was minted for; `named(name)`
|
|
71
71
|
hands back one entity's own definition.
|
|
72
72
|
|
|
73
|
+
`registry.keyed(pick)` is the fold a consumer keys a map by: one answer per entity under the
|
|
74
|
+
name its rows carry, total by construction — `registry.keyed((entity, name) => …)` gives
|
|
75
|
+
`{ [name]: … }` over every entity the registry holds, so no layer writes `Object.fromEntries`
|
|
76
|
+
over `names` and casts the result.
|
|
77
|
+
|
|
73
78
|
## Per-entity body versioning
|
|
74
79
|
|
|
75
80
|
`documentBodyVersioning(definition)` returns `{ migrate, stamp }`, bound to ONE entity's own
|
|
@@ -88,7 +93,9 @@ nothing.
|
|
|
88
93
|
## `documentIdentifiers`
|
|
89
94
|
|
|
90
95
|
`documentIdentifiers(name)` derives every spelling a surface needs from one hyphenated entity name:
|
|
91
|
-
`camel`, `pascal`, `pluralCamel`, `snake`, `snakePlural`, `path
|
|
96
|
+
`camel`, `pascal`, `pluralCamel`, `snake`, `snakePlural`, `path` — each a literal type off the name
|
|
97
|
+
(`documentIdentifiers('purchase-order').camel` is `'purchaseOrder'`), so a consumer keys a router
|
|
98
|
+
map or a path table by them with no cast.
|
|
92
99
|
|
|
93
100
|
## Store
|
|
94
101
|
|
|
@@ -231,14 +238,46 @@ schemas of whatever library the caller's `object`/`union`/`enum` wrap them in
|
|
|
231
238
|
place it enters a repo composing this domain, never a dependency of `@geonosis/document` itself
|
|
232
239
|
(`src/no-schema-library-at-runtime.test.ts` holds the built door to that).
|
|
233
240
|
|
|
241
|
+
## Workflows
|
|
242
|
+
|
|
243
|
+
`documentWorkflows(entity, { effects, ports })` is the `@geonosis/document/workflows` entry — a
|
|
244
|
+
server's import, like `./store`, because it reaches `@geonosis/workflows`. It mints the whole of
|
|
245
|
+
what a Document can do for one entity, from one body: `create` (guarded, seeded, numbered — the
|
|
246
|
+
`ref` given by the caller or minted from the entity's counter off the series the draft names),
|
|
247
|
+
`save` (merged through the entity), `setStatus` (guarded by `canTransition`), `remove` (refused
|
|
248
|
+
when the entity is not `removable`), `send` (durable: the share link, the paper marked `onSent`,
|
|
249
|
+
the mail — in that order, so a mail that never goes reverses the move), `convert` (into the entity
|
|
250
|
+
`effects.conversion` names, at the same ref, the source marked once), `duplicate` (a copy under
|
|
251
|
+
`targetRef` or a minted number) and `share` (a link). Every workflow is named for the entity
|
|
252
|
+
(`invoice.create`, `purchase-order.send`, `memo.set-status`); `document-sagas-are-generic` refuses
|
|
253
|
+
the literal spelling anywhere else. Inputs are Standard Schemas built in the core (`objectOf`,
|
|
254
|
+
`enumOf`, `nonEmptyString`, `positiveInt`, `optional`) over the entity's own `draft` and
|
|
255
|
+
`incoming`; the wire's copy in a consumer's own library stays the surface's business.
|
|
256
|
+
|
|
257
|
+
A host writes only what the kit cannot decide for it. `effects.announce(fact)` is the one required
|
|
258
|
+
decision: a `DocumentFact` (`created`, `saved`, `moved`, `deleted`, `sent`, `shared`, `converted`)
|
|
259
|
+
becomes the product's own events, one or several, or `null`. `beforeCreate`, `conversion` and the
|
|
260
|
+
mail words are optional — absent, nothing runs before the write, nothing converts, and the mail
|
|
261
|
+
reads `<Noun> <number> is ready for you to read.` off the entity's noun. `ports` names three the
|
|
262
|
+
host alone can answer — `door(ctx, entity)` to a store door bound to the run's organisation,
|
|
263
|
+
`link`, and `mail` (answering `Result<void, MailUndelivered>` from `better-result`) — and the rest
|
|
264
|
+
default: `counter` is asked for only by an entity numbered from one and refused by name when
|
|
265
|
+
absent, `actor` reads a string `actor` off the context or names the system, `guard` allows, `now`
|
|
266
|
+
is the clock, `seed` refuses a template. Ports are plain functions: the factory makes the steps
|
|
267
|
+
(`create-share-link`, `send-email`) of the two that reach the outside world, so a replayed durable
|
|
268
|
+
body answers from the journal on every host, and a door bound through `stepsOf` journals every
|
|
269
|
+
read and write of its own. `src/workflows/document-workflows.test.ts` runs every workflow over an
|
|
270
|
+
in-memory door and the memory journal, `send` through the durable door, and one entity on nothing
|
|
271
|
+
but `announce` and the three required ports.
|
|
272
|
+
|
|
234
273
|
## What does not exist yet
|
|
235
274
|
|
|
236
275
|
`src/store/` ships the commits (`commit`, `retire`, `succeed`, `reinstate`, `get`, `at`, `asOf`,
|
|
237
276
|
`history`, `verify`, `rebuild`, `heads`, `aggregate`) and the archive/timestamp ports declared, not
|
|
238
277
|
mirrored; it ships no search projection yet. `upsert` and `revisions` are GONE (replaced by
|
|
239
|
-
`commit`; `history`). `src/surface/` ships the table above; its saga rows
|
|
240
|
-
`
|
|
241
|
-
|
|
278
|
+
`commit`; `history`). `src/surface/` ships the table above; its saga rows still say `pending: 'T3'` because a row's
|
|
279
|
+
`call(handle, params)` has no runtime to open a run with — binding them to `documentWorkflows` is
|
|
280
|
+
#512, and the archive mirror still lands in `src/workflows/`. `src/contract/` (a layer the surface table already
|
|
242
281
|
supersedes — #403), `src/ui/` (the view axis) and `src/conformance/` (the exam a consumer runs
|
|
243
282
|
against their own provider) are later tickets — the internal layout is declared now (and held by
|
|
244
283
|
`layer-walls`) so each lands inside the wall already drawn for it.
|
|
@@ -246,7 +285,7 @@ against their own provider) are later tickets — the internal layout is declare
|
|
|
246
285
|
## One door, and what holds it
|
|
247
286
|
|
|
248
287
|
`sideEffects: false`; inside the package the in-package wall is `layer-walls`, planted in
|
|
249
|
-
`src/__fixtures__/walls/` and proved through the real binary in `src/walls.test.ts` — the core may
|
|
288
|
+
`src/__fixtures__/walls/` and proved through the real binary in `src/walls.bin.test.ts` — the core may
|
|
250
289
|
reach `@geonosis/conformance` and nothing else, the store may reach `@geonosis/db` and
|
|
251
290
|
`@geonosis/conformance` and nothing else, `src/surface/` may reach the core, the store and the
|
|
252
291
|
workflows layer and nothing lower, and only `src/workflows/` may reach `@geonosis/workflows`
|
|
@@ -138,30 +138,25 @@ var documentEntities = (map) => {
|
|
|
138
138
|
entities: map,
|
|
139
139
|
fold,
|
|
140
140
|
instance: (name, parts) => ({ ...parts, entity: name, body: parts.body }),
|
|
141
|
+
keyed: (pick) => Object.fromEntries(names.map((name) => [name, pick(map[name], name)])),
|
|
141
142
|
named: (name) => map[name],
|
|
142
143
|
names,
|
|
143
144
|
views: distinctBy((entity) => entity.view)
|
|
144
145
|
};
|
|
145
146
|
};
|
|
146
147
|
|
|
147
|
-
// src/core/actor.ts
|
|
148
|
-
var SYSTEM_PREFIX = "system:";
|
|
149
|
-
var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
|
|
150
|
-
var isSystemActor = (actor) => actor.startsWith(SYSTEM_PREFIX);
|
|
151
|
-
|
|
152
148
|
// src/core/canonical.ts
|
|
149
|
+
var KEY_ORDER = new Intl.Collator("en-US");
|
|
153
150
|
var canonicalOf = (input) => {
|
|
154
151
|
if (input === null || typeof input !== "object") return input;
|
|
152
|
+
const { toJSON } = input;
|
|
153
|
+
if (typeof toJSON === "function") return canonicalOf(toJSON.call(input));
|
|
155
154
|
if (Array.isArray(input)) return input.map(canonicalOf);
|
|
156
155
|
return Object.fromEntries(
|
|
157
|
-
Object.entries(input).toSorted(([a], [b]) =>
|
|
156
|
+
Object.entries(input).toSorted(([a], [b]) => KEY_ORDER.compare(a, b)).map(([key, held]) => [key, canonicalOf(held)])
|
|
158
157
|
);
|
|
159
158
|
};
|
|
160
159
|
|
|
161
|
-
// src/core/status.ts
|
|
162
|
-
var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
|
|
163
|
-
var isTerminalStatus = (machine, status) => machine.transitions[status].length === 0;
|
|
164
|
-
|
|
165
160
|
export {
|
|
166
161
|
BODY_VERSION_KEY,
|
|
167
162
|
migrateBody,
|
|
@@ -172,9 +167,5 @@ export {
|
|
|
172
167
|
headFields,
|
|
173
168
|
Document,
|
|
174
169
|
documentEntities,
|
|
175
|
-
|
|
176
|
-
isSystemActor,
|
|
177
|
-
canonicalOf,
|
|
178
|
-
canTransition,
|
|
179
|
-
isTerminalStatus
|
|
170
|
+
canonicalOf
|
|
180
171
|
};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// src/core/schema.ts
|
|
2
|
+
var VENDOR = "geonosis-document";
|
|
3
|
+
var isString = (value) => typeof value === "string";
|
|
4
|
+
var isNumber = (value) => typeof value === "number";
|
|
5
|
+
var scalar = (test, message) => ({
|
|
6
|
+
"~standard": {
|
|
7
|
+
validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
|
|
8
|
+
vendor: VENDOR,
|
|
9
|
+
version: 1
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var stringSchema = scalar(isString, "expected a string");
|
|
13
|
+
var numberSchema = scalar(isNumber, "expected a number");
|
|
14
|
+
var booleanSchema = scalar(
|
|
15
|
+
(value) => typeof value === "boolean",
|
|
16
|
+
"expected a boolean"
|
|
17
|
+
);
|
|
18
|
+
var literalOf = (literal) => scalar(
|
|
19
|
+
(value) => value === literal,
|
|
20
|
+
`expected exactly ${JSON.stringify(literal)}`
|
|
21
|
+
);
|
|
22
|
+
var unknownSchema = {
|
|
23
|
+
"~standard": { validate: (input) => ({ value: input }), vendor: VENDOR, version: 1 }
|
|
24
|
+
};
|
|
25
|
+
var syncResult = (schema, input) => {
|
|
26
|
+
const result = schema["~standard"].validate(input);
|
|
27
|
+
if (result instanceof Promise) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
"a document surface schema validates synchronously; an async Standard Schema cannot back a row"
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
var optional = (inner) => ({
|
|
35
|
+
"~standard": {
|
|
36
|
+
validate: (input) => input === void 0 ? { value: void 0 } : syncResult(inner, input),
|
|
37
|
+
vendor: VENDOR,
|
|
38
|
+
version: 1
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
var nullable = (inner) => ({
|
|
42
|
+
"~standard": {
|
|
43
|
+
validate: (input) => input === null ? { value: null } : syncResult(inner, input),
|
|
44
|
+
vendor: VENDOR,
|
|
45
|
+
version: 1
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var arrayOf = (item) => ({
|
|
49
|
+
"~standard": {
|
|
50
|
+
validate: (input) => {
|
|
51
|
+
if (!Array.isArray(input)) return { issues: [{ message: "expected an array" }] };
|
|
52
|
+
const value = [];
|
|
53
|
+
const issues = [];
|
|
54
|
+
input.forEach((one, at) => {
|
|
55
|
+
const result = syncResult(item, one);
|
|
56
|
+
if (result.issues !== void 0) {
|
|
57
|
+
issues.push(
|
|
58
|
+
...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] }))
|
|
59
|
+
);
|
|
60
|
+
} else {
|
|
61
|
+
value.push(result.value);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return issues.length > 0 ? { issues } : { value };
|
|
65
|
+
},
|
|
66
|
+
vendor: VENDOR,
|
|
67
|
+
version: 1
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
var merge = (schemas) => ({
|
|
71
|
+
"~standard": {
|
|
72
|
+
validate: (input) => {
|
|
73
|
+
let value = {};
|
|
74
|
+
const issues = [];
|
|
75
|
+
for (const schema of schemas) {
|
|
76
|
+
const result = syncResult(schema, input);
|
|
77
|
+
if (result.issues !== void 0) issues.push(...result.issues);
|
|
78
|
+
else value = { ...value, ...result.value };
|
|
79
|
+
}
|
|
80
|
+
return issues.length > 0 ? { issues } : { value };
|
|
81
|
+
},
|
|
82
|
+
vendor: VENDOR,
|
|
83
|
+
version: 1
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
var nonEmptyString = scalar(
|
|
87
|
+
(value) => typeof value === "string" && value.length > 0,
|
|
88
|
+
"expected a non-empty string"
|
|
89
|
+
);
|
|
90
|
+
var positiveInt = scalar(
|
|
91
|
+
(value) => Number.isInteger(value) && value > 0,
|
|
92
|
+
"expected a positive integer"
|
|
93
|
+
);
|
|
94
|
+
var validate = async (schema, input) => {
|
|
95
|
+
const result = await schema["~standard"].validate(input);
|
|
96
|
+
if (result.issues !== void 0) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
result.issues.map((issue) => {
|
|
99
|
+
const path = (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
100
|
+
return path === "" ? issue.message : `${path}: ${issue.message}`;
|
|
101
|
+
}).join("; ")
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return result.value;
|
|
105
|
+
};
|
|
106
|
+
var enumOf = (values) => scalar(
|
|
107
|
+
(value) => typeof value === "string" && values.includes(value),
|
|
108
|
+
`expected one of ${values.map((value) => JSON.stringify(value)).join(", ")}`
|
|
109
|
+
);
|
|
110
|
+
var settle = (fields) => {
|
|
111
|
+
const value = {};
|
|
112
|
+
const issues = [];
|
|
113
|
+
for (const [key, result] of fields) {
|
|
114
|
+
if (result.issues !== void 0) {
|
|
115
|
+
issues.push(
|
|
116
|
+
...result.issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] }))
|
|
117
|
+
);
|
|
118
|
+
} else if (result.value !== void 0) {
|
|
119
|
+
value[key] = result.value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return issues.length > 0 ? { issues } : { value };
|
|
123
|
+
};
|
|
124
|
+
var objectOf = (shape) => ({
|
|
125
|
+
"~standard": {
|
|
126
|
+
validate: (input) => {
|
|
127
|
+
if (input === null || typeof input !== "object") {
|
|
128
|
+
return { issues: [{ message: "expected an object" }] };
|
|
129
|
+
}
|
|
130
|
+
const record = input;
|
|
131
|
+
const fields = Object.entries(shape).map(
|
|
132
|
+
([key, schema]) => [key, schema["~standard"].validate(record[key])]
|
|
133
|
+
);
|
|
134
|
+
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(
|
|
135
|
+
settle
|
|
136
|
+
) : settle(fields);
|
|
137
|
+
},
|
|
138
|
+
vendor: VENDOR,
|
|
139
|
+
version: 1
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// src/core/actor.ts
|
|
144
|
+
var SYSTEM_PREFIX = "system:";
|
|
145
|
+
var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
|
|
146
|
+
var isSystemActor = (actor) => actor.startsWith(SYSTEM_PREFIX);
|
|
147
|
+
|
|
148
|
+
// src/core/status.ts
|
|
149
|
+
var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
|
|
150
|
+
var isTerminalStatus = (machine, status) => machine.transitions[status].length === 0;
|
|
151
|
+
|
|
152
|
+
export {
|
|
153
|
+
stringSchema,
|
|
154
|
+
numberSchema,
|
|
155
|
+
booleanSchema,
|
|
156
|
+
literalOf,
|
|
157
|
+
unknownSchema,
|
|
158
|
+
optional,
|
|
159
|
+
nullable,
|
|
160
|
+
arrayOf,
|
|
161
|
+
merge,
|
|
162
|
+
nonEmptyString,
|
|
163
|
+
positiveInt,
|
|
164
|
+
validate,
|
|
165
|
+
enumOf,
|
|
166
|
+
objectOf,
|
|
167
|
+
systemActor,
|
|
168
|
+
isSystemActor,
|
|
169
|
+
canTransition,
|
|
170
|
+
isTerminalStatus
|
|
171
|
+
};
|
|
@@ -195,39 +195,11 @@ declare const documentEntities: <Map extends Readonly<Record<string, AnyDocument
|
|
|
195
195
|
instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, "entity" | "body"> & {
|
|
196
196
|
body: unknown;
|
|
197
197
|
}) => DocumentInstance<Name, InstanceOf<Map[Name]>["body"]>;
|
|
198
|
+
/** One answer per entity, keyed by the name its rows carry — total by construction. */
|
|
199
|
+
keyed: <Result>(pick: (entity: Map[keyof Map], name: keyof Map & string) => Result) => { [Name in keyof Map & string]: Result; };
|
|
198
200
|
named: <Name extends keyof Map & string>(name: Name) => Map[Name];
|
|
199
201
|
names: readonly (keyof Map & string)[];
|
|
200
202
|
views: StandardSchemaV1[];
|
|
201
203
|
};
|
|
202
204
|
|
|
203
|
-
|
|
204
|
-
* The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
|
|
205
|
-
* revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
|
|
206
|
-
* collides with the one it replaced.
|
|
207
|
-
*/
|
|
208
|
-
type ArchivePort = {
|
|
209
|
-
head: (key: string) => Promise<{
|
|
210
|
-
hash: string;
|
|
211
|
-
} | null>;
|
|
212
|
-
put: (key: string, bytes: Uint8Array, meta: {
|
|
213
|
-
hash: string;
|
|
214
|
-
immutable: true;
|
|
215
|
-
}) => Promise<void>;
|
|
216
|
-
};
|
|
217
|
-
/** A trusted third party's timestamp over a hash — never implemented here, only declared. */
|
|
218
|
-
type TimestampPort = {
|
|
219
|
-
stamp: (hash: string) => Promise<{
|
|
220
|
-
at: number;
|
|
221
|
-
token: Uint8Array;
|
|
222
|
-
}>;
|
|
223
|
-
};
|
|
224
|
-
type LinkVerifierPort = {
|
|
225
|
-
verify: (token: string) => Promise<{
|
|
226
|
-
entity: string;
|
|
227
|
-
exp: number;
|
|
228
|
-
org: string;
|
|
229
|
-
ref: string;
|
|
230
|
-
} | null>;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
export { type AnyDocumentEntity as A, BODY_VERSION_KEY as B, type CardOf as C, Document as D, type FieldKind as F, type IncomingOf as I, type LinkVerifierPort as L, type NameOf as N, type StatusOf as S, type TimestampPort as T, type ViewOf as V, type ArchivePort as a, type BodyOf as b, type DocumentBodyMigrations as c, type DocumentBodyVersion as d, type DocumentDefinition as e, type DocumentEntity as f, type DocumentHead as g, type DocumentInstance as h, type DocumentNumbering as i, type DocumentRecord as j, type DocumentStatusMachine as k, type DraftOf as l, type InstanceOf as m, canTransition as n, documentBodyVersioning as o, documentEntities as p, fieldPatterns as q, isTerminalStatus as r, migrateBody as s, stampBody as t, validatorOf as v };
|
|
205
|
+
export { type AnyDocumentEntity as A, BODY_VERSION_KEY as B, type CardOf as C, Document as D, type FieldKind as F, type IncomingOf as I, type NameOf as N, type StatusOf as S, type ViewOf as V, type BodyOf as a, type DocumentBodyMigrations as b, type DocumentBodyVersion as c, type DocumentDefinition as d, type DocumentEntity as e, type DocumentHead as f, type DocumentInstance as g, type DocumentNumbering as h, type DocumentRecord as i, type DocumentStatusMachine as j, type DraftOf as k, type InstanceOf as l, canTransition as m, documentBodyVersioning as n, documentEntities as o, fieldPatterns as p, isTerminalStatus as q, migrateBody as r, stampBody as s, validatorOf as v };
|
|
@@ -195,39 +195,11 @@ declare const documentEntities: <Map extends Readonly<Record<string, AnyDocument
|
|
|
195
195
|
instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, "entity" | "body"> & {
|
|
196
196
|
body: unknown;
|
|
197
197
|
}) => DocumentInstance<Name, InstanceOf<Map[Name]>["body"]>;
|
|
198
|
+
/** One answer per entity, keyed by the name its rows carry — total by construction. */
|
|
199
|
+
keyed: <Result>(pick: (entity: Map[keyof Map], name: keyof Map & string) => Result) => { [Name in keyof Map & string]: Result; };
|
|
198
200
|
named: <Name extends keyof Map & string>(name: Name) => Map[Name];
|
|
199
201
|
names: readonly (keyof Map & string)[];
|
|
200
202
|
views: StandardSchemaV1[];
|
|
201
203
|
};
|
|
202
204
|
|
|
203
|
-
|
|
204
|
-
* The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
|
|
205
|
-
* revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
|
|
206
|
-
* collides with the one it replaced.
|
|
207
|
-
*/
|
|
208
|
-
type ArchivePort = {
|
|
209
|
-
head: (key: string) => Promise<{
|
|
210
|
-
hash: string;
|
|
211
|
-
} | null>;
|
|
212
|
-
put: (key: string, bytes: Uint8Array, meta: {
|
|
213
|
-
hash: string;
|
|
214
|
-
immutable: true;
|
|
215
|
-
}) => Promise<void>;
|
|
216
|
-
};
|
|
217
|
-
/** A trusted third party's timestamp over a hash — never implemented here, only declared. */
|
|
218
|
-
type TimestampPort = {
|
|
219
|
-
stamp: (hash: string) => Promise<{
|
|
220
|
-
at: number;
|
|
221
|
-
token: Uint8Array;
|
|
222
|
-
}>;
|
|
223
|
-
};
|
|
224
|
-
type LinkVerifierPort = {
|
|
225
|
-
verify: (token: string) => Promise<{
|
|
226
|
-
entity: string;
|
|
227
|
-
exp: number;
|
|
228
|
-
org: string;
|
|
229
|
-
ref: string;
|
|
230
|
-
} | null>;
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
export { type AnyDocumentEntity as A, BODY_VERSION_KEY as B, type CardOf as C, Document as D, type FieldKind as F, type IncomingOf as I, type LinkVerifierPort as L, type NameOf as N, type StatusOf as S, type TimestampPort as T, type ViewOf as V, type ArchivePort as a, type BodyOf as b, type DocumentBodyMigrations as c, type DocumentBodyVersion as d, type DocumentDefinition as e, type DocumentEntity as f, type DocumentHead as g, type DocumentInstance as h, type DocumentNumbering as i, type DocumentRecord as j, type DocumentStatusMachine as k, type DraftOf as l, type InstanceOf as m, canTransition as n, documentBodyVersioning as o, documentEntities as p, fieldPatterns as q, isTerminalStatus as r, migrateBody as s, stampBody as t, validatorOf as v };
|
|
205
|
+
export { type AnyDocumentEntity as A, BODY_VERSION_KEY as B, type CardOf as C, Document as D, type FieldKind as F, type IncomingOf as I, type NameOf as N, type StatusOf as S, type ViewOf as V, type BodyOf as a, type DocumentBodyMigrations as b, type DocumentBodyVersion as c, type DocumentDefinition as d, type DocumentEntity as e, type DocumentHead as f, type DocumentInstance as g, type DocumentNumbering as h, type DocumentRecord as i, type DocumentStatusMachine as j, type DraftOf as k, type InstanceOf as l, canTransition as m, documentBodyVersioning as n, documentEntities as o, fieldPatterns as p, isTerminalStatus as q, migrateBody as r, stampBody as s, validatorOf as v };
|