@geonosis/document 0.5.0 → 0.7.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 +60 -0
- package/README.md +48 -5
- package/dist/chunk-7P6FV2YX.js +168 -0
- package/dist/chunk-NA3DLROL.js +171 -0
- package/dist/entities-DTNJMeVf.d.cts +205 -0
- package/dist/entities-DTNJMeVf.d.ts +205 -0
- package/dist/index.cjs +105 -1122
- package/dist/index.d.cts +16 -518
- package/dist/index.d.ts +16 -518
- package/dist/index.js +45 -1350
- package/dist/ports-C_OfflMQ.d.cts +66 -0
- package/dist/ports-C_OfflMQ.d.ts +66 -0
- package/dist/store.cjs +1362 -0
- package/dist/store.d.cts +281 -0
- package/dist/store.d.ts +281 -0
- package/dist/store.js +1127 -0
- 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 +29 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,207 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
export { A as AnyDocumentEntity, B as BODY_VERSION_KEY, a as BodyOf, C as CardOf, D as Document, b as DocumentBodyMigrations, c as DocumentBodyVersion, d as DocumentDefinition, e as DocumentEntity, f as DocumentHead, g as DocumentInstance, h as DocumentNumbering, i as DocumentRecord, j as DocumentStatusMachine, k as DraftOf, F as FieldKind, I as IncomingOf, l as InstanceOf, N as NameOf, S as StatusOf, V as ViewOf, m as canTransition, n as documentBodyVersioning, o as documentEntities, p as fieldPatterns, q as isTerminalStatus, r as migrateBody, s as stampBody, v as validatorOf } from './entities-DTNJMeVf.js';
|
|
2
|
+
export { A as ArchivePort, L as LinkVerifierPort, S as SchemaAdapter, T as TimestampPort, a as arrayOf, b as booleanSchema, e as enumOf, l as literalOf, m as merge, n as nonEmptyString, c as nullable, d as numberSchema, o as objectOf, f as optional, p as positiveInt, s as stringSchema, u as unknownSchema, v as validate } from './ports-C_OfflMQ.js';
|
|
2
3
|
export { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
-
import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, SessionSeam } from '@geonosis/db';
|
|
4
|
-
export { ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
|
|
5
|
-
|
|
6
|
-
declare const BODY_VERSION_KEY = "_v";
|
|
7
|
-
type StoredBody = Record<string, unknown>;
|
|
8
|
-
/** A step declared for ONE entity's stored shape, keyed by the version it reads FROM. */
|
|
9
|
-
type DocumentBodyMigrations<Body extends StoredBody = StoredBody> = Readonly<Record<number, (body: Body) => Body>>;
|
|
10
|
-
/**
|
|
11
|
-
* What an entity declares about its own body's history: the version it is at today, and the steps
|
|
12
|
-
* that bring an older stored body up to it. Absent, an entity is at version 1 with no steps —
|
|
13
|
-
* every field here is per-entity, so a step declared on one entity's `migrations` can never run on
|
|
14
|
-
* another's body, which is the gap a single shared step table left open.
|
|
15
|
-
*/
|
|
16
|
-
type DocumentBodyVersion<Body extends StoredBody = StoredBody> = {
|
|
17
|
-
bodyVersion?: number;
|
|
18
|
-
migrations?: DocumentBodyMigrations<Body>;
|
|
19
|
-
};
|
|
20
|
-
/** Runs BEFORE the entity's schema parses: an older stored shape does not satisfy today's schema. */
|
|
21
|
-
declare const migrateBody: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>, stored: unknown) => unknown;
|
|
22
|
-
declare const stampBody: <Body>(definition: {
|
|
23
|
-
bodyVersion?: number;
|
|
24
|
-
}, body: Body) => unknown;
|
|
25
|
-
/** The migrate/stamp pair, bound to ONE entity's own declared version and steps. */
|
|
26
|
-
declare const documentBodyVersioning: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>) => {
|
|
27
|
-
migrate: (stored: unknown) => unknown;
|
|
28
|
-
stamp: (body: Body) => unknown;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Given by the caller, or minted from a counter. The series is read off the draft BEFORE the
|
|
33
|
-
* counter moves, so a draft that cannot be numbered burns nothing.
|
|
34
|
-
*/
|
|
35
|
-
type DocumentNumbering<Draft> = {
|
|
36
|
-
mode: 'given';
|
|
37
|
-
} | {
|
|
38
|
-
mode: 'counter';
|
|
39
|
-
counter: string;
|
|
40
|
-
series: (draft: Draft) => string;
|
|
41
|
-
format: (series: string, sequence: number) => string;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
/** A named status machine: every status it declares, and what each may move to. */
|
|
45
|
-
type DocumentStatusMachine<Status extends string> = {
|
|
46
|
-
statuses: readonly Status[];
|
|
47
|
-
initial: Status;
|
|
48
|
-
transitions: Readonly<Record<Status, readonly Status[]>>;
|
|
49
|
-
};
|
|
50
|
-
declare const canTransition: <Status extends string>(machine: DocumentStatusMachine<Status>, from: Status, to: Status) => boolean;
|
|
51
|
-
declare const isTerminalStatus: <Status extends string>(machine: DocumentStatusMachine<Status>, status: Status) => boolean;
|
|
52
|
-
|
|
53
|
-
/** The five checks `Document.head` and `Document.record` are built from — never a sixth kind. */
|
|
54
|
-
type FieldKind = 'calendarDate' | 'decimal' | 'int' | 'positiveInt' | 'text';
|
|
55
|
-
/** The two `FieldKind`s a consumer's own schema library validates by pattern — `validatorOf`'s own regexes, on the door, so a fold names one pattern once (#409). */
|
|
56
|
-
declare const fieldPatterns: Record<'calendarDate' | 'decimal', RegExp>;
|
|
57
|
-
/**
|
|
58
|
-
* A `StandardSchemaV1` derived from a declarative field spec — one small checker per `FieldKind`,
|
|
59
|
-
* never a second listing of the fields `Document.head`/`Document.record` already carry.
|
|
60
|
-
*/
|
|
61
|
-
declare const validatorOf: <Output>(fields: Readonly<Record<string, FieldKind>>, options?: {
|
|
62
|
-
nullable?: boolean;
|
|
63
|
-
}) => StandardSchemaV1<unknown, Output>;
|
|
64
|
-
type DocumentHead = {
|
|
65
|
-
status: string | null;
|
|
66
|
-
issueDate: string | null;
|
|
67
|
-
dueDate: string | null;
|
|
68
|
-
counterparty: string | null;
|
|
69
|
-
externalRef: string | null;
|
|
70
|
-
revision: string | null;
|
|
71
|
-
total: string | null;
|
|
72
|
-
};
|
|
73
|
-
type DocumentRecord = {
|
|
74
|
-
version: number;
|
|
75
|
-
createdAt: number;
|
|
76
|
-
updatedAt: number;
|
|
77
|
-
};
|
|
78
|
-
/** What an entity decides when it extends `Document`; every side effect is written once over these. */
|
|
79
|
-
type DocumentDefinition<Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema> = {
|
|
80
|
-
name: Name;
|
|
81
|
-
noun: string;
|
|
82
|
-
basePath: Path;
|
|
83
|
-
body: BodySchema;
|
|
84
|
-
draft: DraftSchema;
|
|
85
|
-
incoming: IncomingSchema;
|
|
86
|
-
statuses: DocumentStatusMachine<Status>;
|
|
87
|
-
numbering: DocumentNumbering<StandardSchemaV1.InferOutput<DraftSchema>>;
|
|
88
|
-
/** The version this entity's stored body is at today — absent, it is 1. */
|
|
89
|
-
bodyVersion?: number;
|
|
90
|
-
/** Steps that bring an older stored body up to `bodyVersion`, keyed by the version they read. */
|
|
91
|
-
migrations?: DocumentBodyMigrations<Record<string, unknown>>;
|
|
92
|
-
/** `number` is the MINTED number — read off the numbering before the counter moves, never a series. */
|
|
93
|
-
fromDraft: (draft: StandardSchemaV1.InferOutput<DraftSchema>, number: string) => StandardSchemaV1.InferOutput<BodySchema>;
|
|
94
|
-
headOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => DocumentHead;
|
|
95
|
-
searchText: (body: StandardSchemaV1.InferOutput<BodySchema>) => {
|
|
96
|
-
body: string;
|
|
97
|
-
};
|
|
98
|
-
statusOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => Status;
|
|
99
|
-
withStatus: (body: StandardSchemaV1.InferOutput<BodySchema>, status: Status, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
|
|
100
|
-
prepare: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
|
|
101
|
-
merge: (stored: StandardSchemaV1.InferOutput<BodySchema>, incoming: StandardSchemaV1.InferOutput<IncomingSchema>, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
|
|
102
|
-
onSent: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
|
|
103
|
-
copy: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
|
|
104
|
-
removable: boolean;
|
|
105
|
-
card: {
|
|
106
|
-
schema: CardSchema;
|
|
107
|
-
of: (document: DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>, names: {
|
|
108
|
-
counterpartyName: string;
|
|
109
|
-
}) => StandardSchemaV1.InferOutput<CardSchema>;
|
|
110
|
-
};
|
|
111
|
-
/** What a single-document read RENDERS — absent, the body a consumer already declared. */
|
|
112
|
-
view?: ViewSchema;
|
|
113
|
-
};
|
|
114
|
-
/** A stored document of one entity: the head every document has, the record's clocks, its body. */
|
|
115
|
-
type DocumentInstance<Name extends string, Body> = DocumentHead & DocumentRecord & {
|
|
116
|
-
entity: Name;
|
|
117
|
-
number: string;
|
|
118
|
-
body: Body;
|
|
119
|
-
};
|
|
120
|
-
type DocumentEntity<Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema> = DocumentDefinition<Name, BodySchema, DraftSchema, IncomingSchema, Status, CardSchema, Path, ViewSchema> & {
|
|
121
|
-
is: (document: {
|
|
122
|
-
entity: string;
|
|
123
|
-
}) => document is DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>;
|
|
124
|
-
view: ViewSchema;
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* The abstract Document. Never stored as itself — a consumer's entities extend it, and everything
|
|
128
|
-
* written against `Document` runs for every one of them.
|
|
129
|
-
*/
|
|
130
|
-
declare const Document: {
|
|
131
|
-
head: StandardSchemaV1<unknown, DocumentHead>;
|
|
132
|
-
headFields: {
|
|
133
|
-
readonly status: "text";
|
|
134
|
-
readonly issueDate: "calendarDate";
|
|
135
|
-
readonly dueDate: "calendarDate";
|
|
136
|
-
readonly counterparty: "text";
|
|
137
|
-
readonly externalRef: "text";
|
|
138
|
-
readonly revision: "text";
|
|
139
|
-
readonly total: "decimal";
|
|
140
|
-
};
|
|
141
|
-
record: StandardSchemaV1<unknown, DocumentRecord>;
|
|
142
|
-
recordFields: {
|
|
143
|
-
readonly version: "positiveInt";
|
|
144
|
-
readonly createdAt: "int";
|
|
145
|
-
readonly updatedAt: "int";
|
|
146
|
-
};
|
|
147
|
-
extend: <Name extends string, BodySchema extends StandardSchemaV1, DraftSchema extends StandardSchemaV1, IncomingSchema extends StandardSchemaV1, Status extends string, CardSchema extends StandardSchemaV1, Path extends string, ViewSchema extends StandardSchemaV1 = BodySchema>(definition: DocumentDefinition<Name, BodySchema, DraftSchema, IncomingSchema, Status, CardSchema, Path, ViewSchema>) => DocumentEntity<Name, BodySchema, DraftSchema, IncomingSchema, Status, CardSchema, Path, ViewSchema>;
|
|
148
|
-
};
|
|
149
|
-
type Parts<Entity> = Entity extends DocumentDefinition<infer Name, infer BodySchema, infer DraftSchema, infer IncomingSchema, infer Status, infer CardSchema, infer _Path, infer ViewSchema> ? {
|
|
150
|
-
name: Name;
|
|
151
|
-
body: StandardSchemaV1.InferOutput<BodySchema>;
|
|
152
|
-
draft: StandardSchemaV1.InferOutput<DraftSchema>;
|
|
153
|
-
incoming: StandardSchemaV1.InferOutput<IncomingSchema>;
|
|
154
|
-
status: Status;
|
|
155
|
-
card: StandardSchemaV1.InferOutput<CardSchema>;
|
|
156
|
-
view: StandardSchemaV1.InferOutput<ViewSchema>;
|
|
157
|
-
} : never;
|
|
158
|
-
type NameOf<Entity> = Parts<Entity>['name'];
|
|
159
|
-
type BodyOf<Entity> = Parts<Entity>['body'];
|
|
160
|
-
type DraftOf<Entity> = Parts<Entity>['draft'];
|
|
161
|
-
type IncomingOf<Entity> = Parts<Entity>['incoming'];
|
|
162
|
-
type StatusOf<Entity> = Parts<Entity>['status'];
|
|
163
|
-
type CardOf<Entity> = Parts<Entity>['card'];
|
|
164
|
-
type ViewOf<Entity> = Parts<Entity>['view'];
|
|
165
|
-
type InstanceOf<Entity> = DocumentInstance<NameOf<Entity>, BodyOf<Entity>>;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The least a map's value has to be for `documentEntities` to do its own work: a name to check
|
|
169
|
-
* against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
|
|
170
|
-
* caller passed — this is a constraint bound, not the type inference reads back — because a status
|
|
171
|
-
* machine typed to its own narrow union is not assignable to one held at `string`, and widening it
|
|
172
|
-
* here would break every entity's own `withStatus` the moment two of them met in one map.
|
|
173
|
-
*
|
|
174
|
-
* Exported for a layer that composes over the registry's OWN values generically (the store): the
|
|
175
|
-
* same minimal bound, never a second one.
|
|
176
|
-
*/
|
|
177
|
-
type AnyDocumentEntity = {
|
|
178
|
-
body: StandardSchemaV1;
|
|
179
|
-
card: {
|
|
180
|
-
schema: StandardSchemaV1;
|
|
181
|
-
};
|
|
182
|
-
name: string;
|
|
183
|
-
view: StandardSchemaV1;
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
|
|
187
|
-
*
|
|
188
|
-
* A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
|
|
189
|
-
* every entity the registry holds, in one place, typed over the union of the map's own values.
|
|
190
|
-
* Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
|
|
191
|
-
* `names` union is DERIVED from the map's own keys.
|
|
192
|
-
*/
|
|
193
|
-
declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
|
|
194
|
-
bodies: StandardSchemaV1[];
|
|
195
|
-
cards: StandardSchemaV1[];
|
|
196
|
-
entities: Map;
|
|
197
|
-
fold: <Result>(pick: (entity: Map[keyof Map]) => Result) => Result[];
|
|
198
|
-
instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, "entity" | "body"> & {
|
|
199
|
-
body: unknown;
|
|
200
|
-
}) => DocumentInstance<Name, InstanceOf<Map[Name]>["body"]>;
|
|
201
|
-
named: <Name extends keyof Map & string>(name: Name) => Map[Name];
|
|
202
|
-
names: readonly (keyof Map & string)[];
|
|
203
|
-
views: StandardSchemaV1[];
|
|
204
|
-
};
|
|
205
4
|
|
|
206
5
|
/** An unattended write's principal — `systemActor('recurring.generate')` — never a bare `'system'`. */
|
|
207
6
|
declare const systemActor: (name: string) => string;
|
|
@@ -213,323 +12,22 @@ declare const isSystemActor: (actor: string) => boolean;
|
|
|
213
12
|
* so a second implementation of this function is a second chain that silently stops agreeing.
|
|
214
13
|
*/
|
|
215
14
|
declare const canonicalOf: (input: unknown) => unknown;
|
|
216
|
-
/** sha256 hex over the canonical JSON of `payload` — no whitespace, keys sorted recursively. */
|
|
217
|
-
declare const hashOf: (payload: unknown) => string;
|
|
218
|
-
|
|
219
|
-
/** The identifiers a surface spells an entity with, all derived from its one hyphenated name. */
|
|
220
|
-
declare const documentIdentifiers: (name: string) => {
|
|
221
|
-
camel: string;
|
|
222
|
-
pascal: string;
|
|
223
|
-
pluralCamel: string;
|
|
224
|
-
snake: string;
|
|
225
|
-
snakePlural: string;
|
|
226
|
-
path: string;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
|
|
231
|
-
* revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
|
|
232
|
-
* collides with the one it replaced.
|
|
233
|
-
*/
|
|
234
|
-
type ArchivePort = {
|
|
235
|
-
head: (key: string) => Promise<{
|
|
236
|
-
hash: string;
|
|
237
|
-
} | null>;
|
|
238
|
-
put: (key: string, bytes: Uint8Array, meta: {
|
|
239
|
-
hash: string;
|
|
240
|
-
immutable: true;
|
|
241
|
-
}) => Promise<void>;
|
|
242
|
-
};
|
|
243
|
-
/** A trusted third party's timestamp over a hash — never implemented here, only declared. */
|
|
244
|
-
type TimestampPort = {
|
|
245
|
-
stamp: (hash: string) => Promise<{
|
|
246
|
-
at: number;
|
|
247
|
-
token: Uint8Array;
|
|
248
|
-
}>;
|
|
249
|
-
};
|
|
250
|
-
type LinkVerifierPort = {
|
|
251
|
-
verify: (token: string) => Promise<{
|
|
252
|
-
entity: string;
|
|
253
|
-
exp: number;
|
|
254
|
-
org: string;
|
|
255
|
-
ref: string;
|
|
256
|
-
} | null>;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
declare const DEFAULT_DOCUMENT_TABLE = "documents";
|
|
260
|
-
declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
|
|
261
|
-
declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
|
|
262
|
-
type HeadField = keyof DocumentHead;
|
|
263
|
-
declare const HEAD_FIELDS: HeadField[];
|
|
264
|
-
type DocumentColumns = EntityColumns & {
|
|
265
|
-
entity?: string;
|
|
266
|
-
heads?: Partial<Record<HeadField, EntityName>>;
|
|
267
|
-
revisionKind?: string;
|
|
268
|
-
total?: EntityName;
|
|
269
|
-
};
|
|
270
|
-
type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
|
|
271
|
-
createdAt: string;
|
|
272
|
-
entity: string;
|
|
273
|
-
tenant: string;
|
|
274
|
-
updatedAt: string;
|
|
275
|
-
};
|
|
276
|
-
declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
|
|
277
|
-
type DocumentRevisionsOptions = {
|
|
278
|
-
table?: string;
|
|
279
|
-
};
|
|
280
|
-
type DocumentMigrationsOptions = {
|
|
281
|
-
appRole?: string;
|
|
282
|
-
columns?: DocumentColumns;
|
|
283
|
-
freeze?: FreezeRegister;
|
|
284
|
-
names?: TenantPolicyNames;
|
|
285
|
-
revisions?: DocumentRevisionsOptions | false;
|
|
286
|
-
schema?: string;
|
|
287
|
-
settings: SessionSettings;
|
|
288
|
-
table?: string;
|
|
289
|
-
};
|
|
290
|
-
type AppendOnlyTablesOptions = {
|
|
291
|
-
table?: string;
|
|
292
|
-
revisions?: DocumentRevisionsOptions | false;
|
|
293
|
-
};
|
|
294
|
-
declare const appendOnlyTables: (options?: AppendOnlyTablesOptions) => string[];
|
|
295
|
-
declare const documentRoleStatements: (appRole: string, options?: AppendOnlyTablesOptions & {
|
|
296
|
-
schema?: string;
|
|
297
|
-
}) => string[];
|
|
298
|
-
declare const documentMigrations: (options: DocumentMigrationsOptions) => EntityMigration[];
|
|
299
|
-
|
|
300
|
-
type StorableDocumentEntity = AnyDocumentEntity & {
|
|
301
|
-
bodyVersion?: number;
|
|
302
|
-
headOf: (body: never) => DocumentHead;
|
|
303
|
-
migrations?: DocumentBodyMigrations<Record<string, unknown>>;
|
|
304
|
-
prepare: (body: never) => unknown;
|
|
305
|
-
};
|
|
306
|
-
type Registry$1<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
|
|
307
|
-
type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
|
|
308
|
-
archive?: ArchivePort;
|
|
309
|
-
columns?: DocumentColumns;
|
|
310
|
-
registry: Registry$1<Map>;
|
|
311
|
-
revisions?: DocumentRevisionsOptions | false;
|
|
312
|
-
schema?: string;
|
|
313
|
-
seam: SessionSeam<Key, Handle>;
|
|
314
|
-
table?: string;
|
|
315
|
-
};
|
|
316
|
-
type HeadColumn = HeadField | 'entity' | 'number';
|
|
317
|
-
type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
|
|
318
|
-
type HeadsOrder = {
|
|
319
|
-
column: DocumentSortColumn | 'entity';
|
|
320
|
-
direction?: 'asc' | 'desc';
|
|
321
|
-
};
|
|
322
|
-
type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt', unknown | readonly unknown[] | {
|
|
323
|
-
from: unknown;
|
|
324
|
-
to: unknown;
|
|
325
|
-
}>>>;
|
|
326
|
-
type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
|
|
327
|
-
entity: string;
|
|
328
|
-
number: string;
|
|
329
|
-
}, Columns[number]>;
|
|
330
|
-
type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
|
|
331
|
-
columns: Columns;
|
|
332
|
-
entity?: string | readonly string[];
|
|
333
|
-
order: readonly HeadsOrder[];
|
|
334
|
-
where?: HeadsWhere;
|
|
335
|
-
};
|
|
336
|
-
type AggregateMeasure = 'count' | 'sum:total';
|
|
337
|
-
type AggregateBy = HeadField | 'entity' | {
|
|
338
|
-
bucket: 'day' | 'month' | 'week';
|
|
339
|
-
of: 'dueDate' | 'issueDate';
|
|
340
|
-
};
|
|
341
|
-
type AggregateWhere = HeadsWhere;
|
|
342
|
-
type AggregateRow = {
|
|
343
|
-
by?: string;
|
|
344
|
-
count?: number;
|
|
345
|
-
sum?: string;
|
|
346
|
-
};
|
|
347
|
-
type AggregateArgs = {
|
|
348
|
-
by?: AggregateBy;
|
|
349
|
-
entities?: readonly string[];
|
|
350
|
-
entity?: string;
|
|
351
|
-
measures: readonly AggregateMeasure[];
|
|
352
|
-
where?: AggregateWhere;
|
|
353
|
-
};
|
|
354
|
-
type Item = DocumentInstance<string, unknown>;
|
|
355
|
-
type DocumentKind = 'committed' | 'reinstated' | 'retired';
|
|
356
|
-
type CommitOutput = {
|
|
357
|
-
archived?: undefined;
|
|
358
|
-
committed: false;
|
|
359
|
-
hash?: undefined;
|
|
360
|
-
lineage: number;
|
|
361
|
-
previous?: undefined;
|
|
362
|
-
ref: string;
|
|
363
|
-
version: number;
|
|
364
|
-
} | {
|
|
365
|
-
archived?: boolean;
|
|
366
|
-
committed: true;
|
|
367
|
-
hash: string;
|
|
368
|
-
lineage: number;
|
|
369
|
-
previous: {
|
|
370
|
-
hash: string;
|
|
371
|
-
version: number;
|
|
372
|
-
} | null;
|
|
373
|
-
ref: string;
|
|
374
|
-
version: number;
|
|
375
|
-
};
|
|
376
|
-
type RetireOutput = {
|
|
377
|
-
hash: string;
|
|
378
|
-
lineage: number;
|
|
379
|
-
ref: string;
|
|
380
|
-
version: number;
|
|
381
|
-
};
|
|
382
|
-
type ReinstateOutput = {
|
|
383
|
-
hash: string;
|
|
384
|
-
lineage: number;
|
|
385
|
-
ref: string;
|
|
386
|
-
version: number;
|
|
387
|
-
};
|
|
388
|
-
type HistoryEntry = {
|
|
389
|
-
actor: string;
|
|
390
|
-
at: number;
|
|
391
|
-
body: unknown;
|
|
392
|
-
hash: string;
|
|
393
|
-
kind: DocumentKind;
|
|
394
|
-
reason: string | null;
|
|
395
|
-
version: number;
|
|
396
|
-
};
|
|
397
|
-
type VerifyResult = {
|
|
398
|
-
brokenAt: number;
|
|
399
|
-
expected: string;
|
|
400
|
-
found: string;
|
|
401
|
-
ok: false;
|
|
402
|
-
} | {
|
|
403
|
-
ok: true;
|
|
404
|
-
versions: number;
|
|
405
|
-
};
|
|
406
|
-
type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pick<Projection<unknown, Item, Key, 'ref', Handle, string, string>, 'get' | 'listAll'> & {
|
|
407
|
-
asOf: Query<Readonly<Record<Key, string>> & {
|
|
408
|
-
at: number;
|
|
409
|
-
ref: string;
|
|
410
|
-
}, Item | null, Handle>;
|
|
411
|
-
at: Query<Readonly<Record<Key, string>> & {
|
|
412
|
-
ref: string;
|
|
413
|
-
version: number;
|
|
414
|
-
}, Item | null, Handle>;
|
|
415
|
-
commit: Query<Readonly<Record<Key, string>> & {
|
|
416
|
-
actor: string;
|
|
417
|
-
body: unknown;
|
|
418
|
-
reason?: string;
|
|
419
|
-
ref: string;
|
|
420
|
-
}, CommitOutput, Handle>;
|
|
421
|
-
history: Query<Readonly<Record<Key, string>> & {
|
|
422
|
-
lineage?: number;
|
|
423
|
-
ref: string;
|
|
424
|
-
}, HistoryEntry[], Handle>;
|
|
425
|
-
list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
|
|
426
|
-
reinstate: Query<Readonly<Record<Key, string>> & {
|
|
427
|
-
actor: string;
|
|
428
|
-
reason?: string;
|
|
429
|
-
ref: string;
|
|
430
|
-
}, ReinstateOutput, Handle>;
|
|
431
|
-
retire: Query<Readonly<Record<Key, string>> & {
|
|
432
|
-
actor: string;
|
|
433
|
-
reason?: string;
|
|
434
|
-
ref: string;
|
|
435
|
-
}, RetireOutput, Handle>;
|
|
436
|
-
succeed: Query<Readonly<Record<Key, string>> & {
|
|
437
|
-
actor: string;
|
|
438
|
-
body: unknown;
|
|
439
|
-
reason?: string;
|
|
440
|
-
ref: string;
|
|
441
|
-
}, CommitOutput, Handle>;
|
|
442
|
-
undos: {
|
|
443
|
-
commit: EntityUndo<CommitOutput, Handle>;
|
|
444
|
-
retire: EntityUndo<RetireOutput, Handle>;
|
|
445
|
-
};
|
|
446
|
-
verify: Query<Readonly<Record<Key, string>> & {
|
|
447
|
-
lineage?: number;
|
|
448
|
-
ref: string;
|
|
449
|
-
}, VerifyResult, Handle>;
|
|
450
|
-
};
|
|
451
|
-
type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
|
|
452
|
-
[Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
|
|
453
|
-
} & {
|
|
454
|
-
aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
|
|
455
|
-
heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
|
|
456
|
-
rebuild: Query<Readonly<Record<Key, string>> & {
|
|
457
|
-
entity?: string;
|
|
458
|
-
}, {
|
|
459
|
-
rows: number;
|
|
460
|
-
}, Handle>;
|
|
461
|
-
};
|
|
462
|
-
declare const documentStore: <Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentStoreOptions<Map, Key, Handle>) => DocumentStore<Map, Key, Handle>;
|
|
463
15
|
|
|
464
|
-
type
|
|
465
|
-
type
|
|
466
|
-
|
|
467
|
-
type PendingCall = {
|
|
468
|
-
pending: 'T3';
|
|
469
|
-
workflow: string;
|
|
470
|
-
};
|
|
16
|
+
/** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
|
|
17
|
+
type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
|
|
18
|
+
type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
|
|
471
19
|
/**
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
* explicit here since a row is DATA before it is a function: reading `params.ref` off `never`
|
|
475
|
-
* compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
|
|
20
|
+
* Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
|
|
21
|
+
* a consumer keys a router map or a path table by them without a cast.
|
|
476
22
|
*/
|
|
477
|
-
type
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
path:
|
|
484
|
-
scope: SurfaceScope;
|
|
485
|
-
verb: SurfaceVerb;
|
|
23
|
+
type DocumentIdentifiers<Name extends string> = {
|
|
24
|
+
camel: CamelOf<Name>;
|
|
25
|
+
pascal: Capitalize<CamelOf<Name>>;
|
|
26
|
+
pluralCamel: `${CamelOf<Name>}s`;
|
|
27
|
+
snake: SnakeOf<Name>;
|
|
28
|
+
snakePlural: `${SnakeOf<Name>}s`;
|
|
29
|
+
path: `/${Name}s`;
|
|
486
30
|
};
|
|
487
|
-
|
|
488
|
-
* The three builders a validator library supplies so the table stays library-free (#383) while the
|
|
489
|
-
* union/enum/object it derives are still real schemas of THAT library — the one place a consumer's
|
|
490
|
-
* zod enters `@geonosis/document` is through this adapter, never a direct dependency.
|
|
491
|
-
*/
|
|
492
|
-
type SurfaceSchemaAdapter = {
|
|
493
|
-
enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
|
|
494
|
-
object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
|
|
495
|
-
union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
|
|
496
|
-
};
|
|
497
|
-
/**
|
|
498
|
-
* What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
|
|
499
|
-
* what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
|
|
500
|
-
* caller never sees two overlapping bounds for the one registry it built.
|
|
501
|
-
*/
|
|
502
|
-
type SurfaceDocumentEntity = AnyDocumentEntity & {
|
|
503
|
-
basePath: string;
|
|
504
|
-
bodyVersion?: number;
|
|
505
|
-
card: {
|
|
506
|
-
of: (document: never, names: {
|
|
507
|
-
counterpartyName: string;
|
|
508
|
-
}) => unknown;
|
|
509
|
-
schema: StandardSchemaV1;
|
|
510
|
-
};
|
|
511
|
-
draft: StandardSchemaV1;
|
|
512
|
-
headOf: (body: never) => DocumentHead;
|
|
513
|
-
migrations?: DocumentBodyMigrations<Record<string, unknown>>;
|
|
514
|
-
prepare: (body: never) => unknown;
|
|
515
|
-
statusOf: (body: never) => string;
|
|
516
|
-
statuses: DocumentStatusMachine<string>;
|
|
517
|
-
withStatus: (body: never, status: string, at: string) => unknown;
|
|
518
|
-
};
|
|
519
|
-
type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
|
|
520
|
-
type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
|
|
521
|
-
registry: Registry<Map>;
|
|
522
|
-
schema: SurfaceSchemaAdapter;
|
|
523
|
-
store: DocumentStore<Map, Key, Handle>;
|
|
524
|
-
};
|
|
525
|
-
/**
|
|
526
|
-
* `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
|
|
527
|
-
* from — never authored by hand, and never a map a caller fills in per entity (#383). Reads and
|
|
528
|
-
* `commit`/`retire`/`reinstate`/`setStatus` bind `call` to the store already composed; the saga
|
|
529
|
-
* rows (`create`, `send`, `duplicate`, `run-started`) are declared with their own input/output and
|
|
530
|
-
* a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
|
|
531
|
-
* BY NAME, never with a stub answer.
|
|
532
|
-
*/
|
|
533
|
-
declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
|
|
31
|
+
declare const documentIdentifiers: <Name extends string>(name: Name) => DocumentIdentifiers<Name>;
|
|
534
32
|
|
|
535
|
-
export { type
|
|
33
|
+
export { type CamelOf, type DocumentIdentifiers, canonicalOf, documentIdentifiers, isSystemActor, systemActor };
|