@geonosis/document 0.9.1 → 0.9.3

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/core/actor.cjs +48 -0
  3. package/dist/core/actor.d.cts +3 -0
  4. package/dist/core/actor.d.ts +3 -0
  5. package/dist/core/actor.js +8 -0
  6. package/dist/core/body-version.cjs +75 -0
  7. package/dist/core/body-version.d.cts +25 -0
  8. package/dist/core/body-version.d.ts +25 -0
  9. package/dist/core/body-version.js +35 -0
  10. package/dist/core/canonical.cjs +55 -0
  11. package/dist/core/canonical.d.cts +5 -0
  12. package/dist/core/canonical.d.ts +5 -0
  13. package/dist/core/canonical.js +15 -0
  14. package/dist/core/document.cjs +136 -0
  15. package/dist/core/document.d.cts +137 -0
  16. package/dist/core/document.d.ts +137 -0
  17. package/dist/core/document.js +96 -0
  18. package/dist/core/entities.cjs +68 -0
  19. package/dist/core/entities.d.cts +42 -0
  20. package/dist/core/entities.d.ts +42 -0
  21. package/dist/core/entities.js +28 -0
  22. package/dist/core/naming.cjs +56 -0
  23. package/dist/core/naming.d.cts +17 -0
  24. package/dist/core/naming.d.ts +17 -0
  25. package/dist/core/naming.js +16 -0
  26. package/dist/core/numbering.cjs +41 -0
  27. package/dist/core/numbering.d.cts +12 -0
  28. package/dist/core/numbering.d.ts +12 -0
  29. package/dist/core/numbering.js +0 -0
  30. package/dist/core/ports.cjs +41 -0
  31. package/dist/core/ports.d.cts +29 -0
  32. package/dist/core/ports.d.ts +29 -0
  33. package/dist/core/ports.js +0 -0
  34. package/dist/core/schema.cjs +173 -0
  35. package/dist/core/schema.d.cts +33 -0
  36. package/dist/core/schema.d.ts +33 -0
  37. package/dist/{chunk-NA3DLROL.js → core/schema.js} +34 -72
  38. package/dist/core/status.cjs +47 -0
  39. package/dist/core/status.d.cts +8 -0
  40. package/dist/core/status.d.ts +8 -0
  41. package/dist/core/status.js +7 -0
  42. package/dist/index.cjs +70 -398
  43. package/dist/index.d.cts +11 -32
  44. package/dist/index.d.ts +11 -32
  45. package/dist/index.js +13 -25
  46. package/dist/store/ddl.cjs +209 -0
  47. package/dist/store/ddl.d.cts +56 -0
  48. package/dist/store/ddl.d.ts +56 -0
  49. package/dist/store/ddl.js +175 -0
  50. package/dist/store/hash.cjs +50 -0
  51. package/dist/store/hash.d.cts +2 -0
  52. package/dist/store/hash.d.ts +2 -0
  53. package/dist/store/hash.js +10 -0
  54. package/dist/store/store.cjs +606 -0
  55. package/dist/store/store.d.cts +169 -0
  56. package/dist/store/store.d.ts +169 -0
  57. package/dist/store/store.js +578 -0
  58. package/dist/store.cjs +51 -1358
  59. package/dist/store.d.cts +4 -277
  60. package/dist/store.d.ts +4 -277
  61. package/dist/store.js +17 -1114
  62. package/dist/surface/table.cjs +326 -0
  63. package/dist/surface/table.d.cts +70 -0
  64. package/dist/surface/table.d.ts +70 -0
  65. package/dist/surface/table.js +296 -0
  66. package/dist/workflows/document-workflows.cjs +314 -0
  67. package/dist/workflows/document-workflows.d.cts +112 -0
  68. package/dist/workflows/document-workflows.d.ts +112 -0
  69. package/dist/workflows/document-workflows.js +281 -0
  70. package/dist/workflows/effects.cjs +41 -0
  71. package/dist/workflows/effects.d.cts +68 -0
  72. package/dist/workflows/effects.d.ts +68 -0
  73. package/dist/workflows/effects.js +0 -0
  74. package/dist/workflows/ports.cjs +50 -0
  75. package/dist/workflows/ports.d.cts +72 -0
  76. package/dist/workflows/ports.d.ts +72 -0
  77. package/dist/workflows/ports.js +10 -0
  78. package/dist/workflows/refusals.cjs +80 -0
  79. package/dist/workflows/refusals.d.cts +59 -0
  80. package/dist/workflows/refusals.d.ts +59 -0
  81. package/dist/workflows/refusals.js +40 -0
  82. package/dist/workflows.cjs +52 -504
  83. package/dist/workflows.d.cts +4 -310
  84. package/dist/workflows.d.ts +4 -310
  85. package/dist/workflows.js +21 -368
  86. package/package.json +8 -8
  87. package/dist/chunk-A6ZU4QU3.js +0 -171
  88. package/dist/entities-DTNJMeVf.d.cts +0 -205
  89. package/dist/entities-DTNJMeVf.d.ts +0 -205
  90. package/dist/ports-C_OfflMQ.d.cts +0 -66
  91. package/dist/ports-C_OfflMQ.d.ts +0 -66
@@ -1,205 +0,0 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
-
3
- declare const BODY_VERSION_KEY = "_v";
4
- type StoredBody = Record<string, unknown>;
5
- /** A step declared for ONE entity's stored shape, keyed by the version it reads FROM. */
6
- type DocumentBodyMigrations<Body extends StoredBody = StoredBody> = Readonly<Record<number, (body: Body) => Body>>;
7
- /**
8
- * What an entity declares about its own body's history: the version it is at today, and the steps
9
- * that bring an older stored body up to it. Absent, an entity is at version 1 with no steps —
10
- * every field here is per-entity, so a step declared on one entity's `migrations` can never run on
11
- * another's body, which is the gap a single shared step table left open.
12
- */
13
- type DocumentBodyVersion<Body extends StoredBody = StoredBody> = {
14
- bodyVersion?: number;
15
- migrations?: DocumentBodyMigrations<Body>;
16
- };
17
- /** Runs BEFORE the entity's schema parses: an older stored shape does not satisfy today's schema. */
18
- declare const migrateBody: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>, stored: unknown) => unknown;
19
- declare const stampBody: <Body>(definition: {
20
- bodyVersion?: number;
21
- }, body: Body) => unknown;
22
- /** The migrate/stamp pair, bound to ONE entity's own declared version and steps. */
23
- declare const documentBodyVersioning: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>) => {
24
- migrate: (stored: unknown) => unknown;
25
- stamp: (body: Body) => unknown;
26
- };
27
-
28
- /**
29
- * Given by the caller, or minted from a counter. The series is read off the draft BEFORE the
30
- * counter moves, so a draft that cannot be numbered burns nothing.
31
- */
32
- type DocumentNumbering<Draft> = {
33
- mode: 'given';
34
- } | {
35
- mode: 'counter';
36
- counter: string;
37
- series: (draft: Draft) => string;
38
- format: (series: string, sequence: number) => string;
39
- };
40
-
41
- /** A named status machine: every status it declares, and what each may move to. */
42
- type DocumentStatusMachine<Status extends string> = {
43
- statuses: readonly Status[];
44
- initial: Status;
45
- transitions: Readonly<Record<Status, readonly Status[]>>;
46
- };
47
- declare const canTransition: <Status extends string>(machine: DocumentStatusMachine<Status>, from: Status, to: Status) => boolean;
48
- declare const isTerminalStatus: <Status extends string>(machine: DocumentStatusMachine<Status>, status: Status) => boolean;
49
-
50
- /** The five checks `Document.head` and `Document.record` are built from — never a sixth kind. */
51
- type FieldKind = 'calendarDate' | 'decimal' | 'int' | 'positiveInt' | 'text';
52
- /** 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). */
53
- declare const fieldPatterns: Record<'calendarDate' | 'decimal', RegExp>;
54
- /**
55
- * A `StandardSchemaV1` derived from a declarative field spec — one small checker per `FieldKind`,
56
- * never a second listing of the fields `Document.head`/`Document.record` already carry.
57
- */
58
- declare const validatorOf: <Output>(fields: Readonly<Record<string, FieldKind>>, options?: {
59
- nullable?: boolean;
60
- }) => StandardSchemaV1<unknown, Output>;
61
- type DocumentHead = {
62
- status: string | null;
63
- issueDate: string | null;
64
- dueDate: string | null;
65
- counterparty: string | null;
66
- externalRef: string | null;
67
- revision: string | null;
68
- total: string | null;
69
- };
70
- type DocumentRecord = {
71
- version: number;
72
- createdAt: number;
73
- updatedAt: number;
74
- };
75
- /** What an entity decides when it extends `Document`; every side effect is written once over these. */
76
- 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> = {
77
- name: Name;
78
- noun: string;
79
- basePath: Path;
80
- body: BodySchema;
81
- draft: DraftSchema;
82
- incoming: IncomingSchema;
83
- statuses: DocumentStatusMachine<Status>;
84
- numbering: DocumentNumbering<StandardSchemaV1.InferOutput<DraftSchema>>;
85
- /** The version this entity's stored body is at today — absent, it is 1. */
86
- bodyVersion?: number;
87
- /** Steps that bring an older stored body up to `bodyVersion`, keyed by the version they read. */
88
- migrations?: DocumentBodyMigrations<Record<string, unknown>>;
89
- /** `number` is the MINTED number — read off the numbering before the counter moves, never a series. */
90
- fromDraft: (draft: StandardSchemaV1.InferOutput<DraftSchema>, number: string) => StandardSchemaV1.InferOutput<BodySchema>;
91
- headOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => DocumentHead;
92
- searchText: (body: StandardSchemaV1.InferOutput<BodySchema>) => {
93
- body: string;
94
- };
95
- statusOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => Status;
96
- withStatus: (body: StandardSchemaV1.InferOutput<BodySchema>, status: Status, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
97
- prepare: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
98
- merge: (stored: StandardSchemaV1.InferOutput<BodySchema>, incoming: StandardSchemaV1.InferOutput<IncomingSchema>, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
99
- onSent: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
100
- copy: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
101
- removable: boolean;
102
- card: {
103
- schema: CardSchema;
104
- of: (document: DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>, names: {
105
- counterpartyName: string;
106
- }) => StandardSchemaV1.InferOutput<CardSchema>;
107
- };
108
- /** What a single-document read RENDERS — absent, the body a consumer already declared. */
109
- view?: ViewSchema;
110
- };
111
- /** A stored document of one entity: the head every document has, the record's clocks, its body. */
112
- type DocumentInstance<Name extends string, Body> = DocumentHead & DocumentRecord & {
113
- entity: Name;
114
- number: string;
115
- body: Body;
116
- };
117
- 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> & {
118
- is: (document: {
119
- entity: string;
120
- }) => document is DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>;
121
- view: ViewSchema;
122
- };
123
- /**
124
- * The abstract Document. Never stored as itself — a consumer's entities extend it, and everything
125
- * written against `Document` runs for every one of them.
126
- */
127
- declare const Document: {
128
- head: StandardSchemaV1<unknown, DocumentHead>;
129
- headFields: {
130
- readonly status: "text";
131
- readonly issueDate: "calendarDate";
132
- readonly dueDate: "calendarDate";
133
- readonly counterparty: "text";
134
- readonly externalRef: "text";
135
- readonly revision: "text";
136
- readonly total: "decimal";
137
- };
138
- record: StandardSchemaV1<unknown, DocumentRecord>;
139
- recordFields: {
140
- readonly version: "positiveInt";
141
- readonly createdAt: "int";
142
- readonly updatedAt: "int";
143
- };
144
- 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>;
145
- };
146
- type Parts<Entity> = Entity extends DocumentDefinition<infer Name, infer BodySchema, infer DraftSchema, infer IncomingSchema, infer Status, infer CardSchema, infer _Path, infer ViewSchema> ? {
147
- name: Name;
148
- body: StandardSchemaV1.InferOutput<BodySchema>;
149
- draft: StandardSchemaV1.InferOutput<DraftSchema>;
150
- incoming: StandardSchemaV1.InferOutput<IncomingSchema>;
151
- status: Status;
152
- card: StandardSchemaV1.InferOutput<CardSchema>;
153
- view: StandardSchemaV1.InferOutput<ViewSchema>;
154
- } : never;
155
- type NameOf<Entity> = Parts<Entity>['name'];
156
- type BodyOf<Entity> = Parts<Entity>['body'];
157
- type DraftOf<Entity> = Parts<Entity>['draft'];
158
- type IncomingOf<Entity> = Parts<Entity>['incoming'];
159
- type StatusOf<Entity> = Parts<Entity>['status'];
160
- type CardOf<Entity> = Parts<Entity>['card'];
161
- type ViewOf<Entity> = Parts<Entity>['view'];
162
- type InstanceOf<Entity> = DocumentInstance<NameOf<Entity>, BodyOf<Entity>>;
163
-
164
- /**
165
- * The least a map's value has to be for `documentEntities` to do its own work: a name to check
166
- * against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
167
- * caller passed — this is a constraint bound, not the type inference reads back — because a status
168
- * machine typed to its own narrow union is not assignable to one held at `string`, and widening it
169
- * here would break every entity's own `withStatus` the moment two of them met in one map.
170
- *
171
- * Exported for a layer that composes over the registry's OWN values generically (the store): the
172
- * same minimal bound, never a second one.
173
- */
174
- type AnyDocumentEntity = {
175
- body: StandardSchemaV1;
176
- card: {
177
- schema: StandardSchemaV1;
178
- };
179
- name: string;
180
- view: StandardSchemaV1;
181
- };
182
- /**
183
- * `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
184
- *
185
- * A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
186
- * every entity the registry holds, in one place, typed over the union of the map's own values.
187
- * Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
188
- * `names` union is DERIVED from the map's own keys.
189
- */
190
- declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
191
- bodies: StandardSchemaV1[];
192
- cards: StandardSchemaV1[];
193
- entities: Map;
194
- fold: <Result>(pick: (entity: Map[keyof Map]) => Result) => Result[];
195
- instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, "entity" | "body"> & {
196
- body: unknown;
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; };
200
- named: <Name extends keyof Map & string>(name: Name) => Map[Name];
201
- names: readonly (keyof Map & string)[];
202
- views: StandardSchemaV1[];
203
- };
204
-
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 };
@@ -1,205 +0,0 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
-
3
- declare const BODY_VERSION_KEY = "_v";
4
- type StoredBody = Record<string, unknown>;
5
- /** A step declared for ONE entity's stored shape, keyed by the version it reads FROM. */
6
- type DocumentBodyMigrations<Body extends StoredBody = StoredBody> = Readonly<Record<number, (body: Body) => Body>>;
7
- /**
8
- * What an entity declares about its own body's history: the version it is at today, and the steps
9
- * that bring an older stored body up to it. Absent, an entity is at version 1 with no steps —
10
- * every field here is per-entity, so a step declared on one entity's `migrations` can never run on
11
- * another's body, which is the gap a single shared step table left open.
12
- */
13
- type DocumentBodyVersion<Body extends StoredBody = StoredBody> = {
14
- bodyVersion?: number;
15
- migrations?: DocumentBodyMigrations<Body>;
16
- };
17
- /** Runs BEFORE the entity's schema parses: an older stored shape does not satisfy today's schema. */
18
- declare const migrateBody: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>, stored: unknown) => unknown;
19
- declare const stampBody: <Body>(definition: {
20
- bodyVersion?: number;
21
- }, body: Body) => unknown;
22
- /** The migrate/stamp pair, bound to ONE entity's own declared version and steps. */
23
- declare const documentBodyVersioning: <Body extends StoredBody>(definition: DocumentBodyVersion<Body>) => {
24
- migrate: (stored: unknown) => unknown;
25
- stamp: (body: Body) => unknown;
26
- };
27
-
28
- /**
29
- * Given by the caller, or minted from a counter. The series is read off the draft BEFORE the
30
- * counter moves, so a draft that cannot be numbered burns nothing.
31
- */
32
- type DocumentNumbering<Draft> = {
33
- mode: 'given';
34
- } | {
35
- mode: 'counter';
36
- counter: string;
37
- series: (draft: Draft) => string;
38
- format: (series: string, sequence: number) => string;
39
- };
40
-
41
- /** A named status machine: every status it declares, and what each may move to. */
42
- type DocumentStatusMachine<Status extends string> = {
43
- statuses: readonly Status[];
44
- initial: Status;
45
- transitions: Readonly<Record<Status, readonly Status[]>>;
46
- };
47
- declare const canTransition: <Status extends string>(machine: DocumentStatusMachine<Status>, from: Status, to: Status) => boolean;
48
- declare const isTerminalStatus: <Status extends string>(machine: DocumentStatusMachine<Status>, status: Status) => boolean;
49
-
50
- /** The five checks `Document.head` and `Document.record` are built from — never a sixth kind. */
51
- type FieldKind = 'calendarDate' | 'decimal' | 'int' | 'positiveInt' | 'text';
52
- /** 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). */
53
- declare const fieldPatterns: Record<'calendarDate' | 'decimal', RegExp>;
54
- /**
55
- * A `StandardSchemaV1` derived from a declarative field spec — one small checker per `FieldKind`,
56
- * never a second listing of the fields `Document.head`/`Document.record` already carry.
57
- */
58
- declare const validatorOf: <Output>(fields: Readonly<Record<string, FieldKind>>, options?: {
59
- nullable?: boolean;
60
- }) => StandardSchemaV1<unknown, Output>;
61
- type DocumentHead = {
62
- status: string | null;
63
- issueDate: string | null;
64
- dueDate: string | null;
65
- counterparty: string | null;
66
- externalRef: string | null;
67
- revision: string | null;
68
- total: string | null;
69
- };
70
- type DocumentRecord = {
71
- version: number;
72
- createdAt: number;
73
- updatedAt: number;
74
- };
75
- /** What an entity decides when it extends `Document`; every side effect is written once over these. */
76
- 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> = {
77
- name: Name;
78
- noun: string;
79
- basePath: Path;
80
- body: BodySchema;
81
- draft: DraftSchema;
82
- incoming: IncomingSchema;
83
- statuses: DocumentStatusMachine<Status>;
84
- numbering: DocumentNumbering<StandardSchemaV1.InferOutput<DraftSchema>>;
85
- /** The version this entity's stored body is at today — absent, it is 1. */
86
- bodyVersion?: number;
87
- /** Steps that bring an older stored body up to `bodyVersion`, keyed by the version they read. */
88
- migrations?: DocumentBodyMigrations<Record<string, unknown>>;
89
- /** `number` is the MINTED number — read off the numbering before the counter moves, never a series. */
90
- fromDraft: (draft: StandardSchemaV1.InferOutput<DraftSchema>, number: string) => StandardSchemaV1.InferOutput<BodySchema>;
91
- headOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => DocumentHead;
92
- searchText: (body: StandardSchemaV1.InferOutput<BodySchema>) => {
93
- body: string;
94
- };
95
- statusOf: (body: StandardSchemaV1.InferOutput<BodySchema>) => Status;
96
- withStatus: (body: StandardSchemaV1.InferOutput<BodySchema>, status: Status, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
97
- prepare: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
98
- merge: (stored: StandardSchemaV1.InferOutput<BodySchema>, incoming: StandardSchemaV1.InferOutput<IncomingSchema>, at: string) => StandardSchemaV1.InferOutput<BodySchema>;
99
- onSent: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
100
- copy: (body: StandardSchemaV1.InferOutput<BodySchema>) => StandardSchemaV1.InferOutput<BodySchema>;
101
- removable: boolean;
102
- card: {
103
- schema: CardSchema;
104
- of: (document: DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>, names: {
105
- counterpartyName: string;
106
- }) => StandardSchemaV1.InferOutput<CardSchema>;
107
- };
108
- /** What a single-document read RENDERS — absent, the body a consumer already declared. */
109
- view?: ViewSchema;
110
- };
111
- /** A stored document of one entity: the head every document has, the record's clocks, its body. */
112
- type DocumentInstance<Name extends string, Body> = DocumentHead & DocumentRecord & {
113
- entity: Name;
114
- number: string;
115
- body: Body;
116
- };
117
- 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> & {
118
- is: (document: {
119
- entity: string;
120
- }) => document is DocumentInstance<Name, StandardSchemaV1.InferOutput<BodySchema>>;
121
- view: ViewSchema;
122
- };
123
- /**
124
- * The abstract Document. Never stored as itself — a consumer's entities extend it, and everything
125
- * written against `Document` runs for every one of them.
126
- */
127
- declare const Document: {
128
- head: StandardSchemaV1<unknown, DocumentHead>;
129
- headFields: {
130
- readonly status: "text";
131
- readonly issueDate: "calendarDate";
132
- readonly dueDate: "calendarDate";
133
- readonly counterparty: "text";
134
- readonly externalRef: "text";
135
- readonly revision: "text";
136
- readonly total: "decimal";
137
- };
138
- record: StandardSchemaV1<unknown, DocumentRecord>;
139
- recordFields: {
140
- readonly version: "positiveInt";
141
- readonly createdAt: "int";
142
- readonly updatedAt: "int";
143
- };
144
- 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>;
145
- };
146
- type Parts<Entity> = Entity extends DocumentDefinition<infer Name, infer BodySchema, infer DraftSchema, infer IncomingSchema, infer Status, infer CardSchema, infer _Path, infer ViewSchema> ? {
147
- name: Name;
148
- body: StandardSchemaV1.InferOutput<BodySchema>;
149
- draft: StandardSchemaV1.InferOutput<DraftSchema>;
150
- incoming: StandardSchemaV1.InferOutput<IncomingSchema>;
151
- status: Status;
152
- card: StandardSchemaV1.InferOutput<CardSchema>;
153
- view: StandardSchemaV1.InferOutput<ViewSchema>;
154
- } : never;
155
- type NameOf<Entity> = Parts<Entity>['name'];
156
- type BodyOf<Entity> = Parts<Entity>['body'];
157
- type DraftOf<Entity> = Parts<Entity>['draft'];
158
- type IncomingOf<Entity> = Parts<Entity>['incoming'];
159
- type StatusOf<Entity> = Parts<Entity>['status'];
160
- type CardOf<Entity> = Parts<Entity>['card'];
161
- type ViewOf<Entity> = Parts<Entity>['view'];
162
- type InstanceOf<Entity> = DocumentInstance<NameOf<Entity>, BodyOf<Entity>>;
163
-
164
- /**
165
- * The least a map's value has to be for `documentEntities` to do its own work: a name to check
166
- * against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
167
- * caller passed — this is a constraint bound, not the type inference reads back — because a status
168
- * machine typed to its own narrow union is not assignable to one held at `string`, and widening it
169
- * here would break every entity's own `withStatus` the moment two of them met in one map.
170
- *
171
- * Exported for a layer that composes over the registry's OWN values generically (the store): the
172
- * same minimal bound, never a second one.
173
- */
174
- type AnyDocumentEntity = {
175
- body: StandardSchemaV1;
176
- card: {
177
- schema: StandardSchemaV1;
178
- };
179
- name: string;
180
- view: StandardSchemaV1;
181
- };
182
- /**
183
- * `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
184
- *
185
- * A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
186
- * every entity the registry holds, in one place, typed over the union of the map's own values.
187
- * Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
188
- * `names` union is DERIVED from the map's own keys.
189
- */
190
- declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
191
- bodies: StandardSchemaV1[];
192
- cards: StandardSchemaV1[];
193
- entities: Map;
194
- fold: <Result>(pick: (entity: Map[keyof Map]) => Result) => Result[];
195
- instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, "entity" | "body"> & {
196
- body: unknown;
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; };
200
- named: <Name extends keyof Map & string>(name: Name) => Map[Name];
201
- names: readonly (keyof Map & string)[];
202
- views: StandardSchemaV1[];
203
- };
204
-
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 };
@@ -1,66 +0,0 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
-
3
- /**
4
- * The three builders a validator library supplies so the surface and the workflows stay library-free
5
- * (#383) while the union/enum/object they derive are still real schemas of THAT library — the one
6
- * place a consumer's zod enters `@geonosis/document` is through this adapter, never a dependency.
7
- */
8
- type SchemaAdapter = {
9
- enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
10
- object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
11
- union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
12
- };
13
- declare const stringSchema: StandardSchemaV1<unknown, string>;
14
- declare const numberSchema: StandardSchemaV1<unknown, number>;
15
- declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
16
- declare const literalOf: <Value extends boolean | string>(literal: Value) => StandardSchemaV1<unknown, Value>;
17
- /** A passthrough for a shape this ticket declares but does not itself narrow further. */
18
- declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
19
- declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
20
- declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
21
- declare const arrayOf: <Output>(item: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output[]>;
22
- /** Every schema's own issues, folded into one — the merged VALUE is every schema's fields, spread. */
23
- declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
24
- declare const nonEmptyString: StandardSchemaV1<unknown, string>;
25
- declare const positiveInt: StandardSchemaV1<unknown, number>;
26
- /** One value through one schema, whichever library wrote it; the issues are the refusal's text. */
27
- declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
28
- declare const enumOf: <Value extends string>(values: readonly Value[]) => StandardSchemaV1<unknown, Value>;
29
- /**
30
- * An object of named fields, each through its own schema — the one builder a workflow input needs
31
- * that the adapter is not asked for, since a run's input is refused by the engine and never rendered
32
- * by a host's own library. Async when a field's schema is; unknown keys are dropped.
33
- */
34
- declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
35
-
36
- /**
37
- * The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
38
- * revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
39
- * collides with the one it replaced.
40
- */
41
- type ArchivePort = {
42
- head: (key: string) => Promise<{
43
- hash: string;
44
- } | null>;
45
- put: (key: string, bytes: Uint8Array, meta: {
46
- hash: string;
47
- immutable: true;
48
- }) => Promise<void>;
49
- };
50
- /** A trusted third party's timestamp over a hash — never implemented here, only declared. */
51
- type TimestampPort = {
52
- stamp: (hash: string) => Promise<{
53
- at: number;
54
- token: Uint8Array;
55
- }>;
56
- };
57
- type LinkVerifierPort = {
58
- verify: (token: string) => Promise<{
59
- entity: string;
60
- exp: number;
61
- org: string;
62
- ref: string;
63
- } | null>;
64
- };
65
-
66
- export { type ArchivePort as A, type LinkVerifierPort as L, type SchemaAdapter as S, type TimestampPort as T, arrayOf as a, booleanSchema as b, nullable as c, numberSchema as d, enumOf as e, optional as f, literalOf as l, merge as m, nonEmptyString as n, objectOf as o, positiveInt as p, stringSchema as s, unknownSchema as u, validate as v };
@@ -1,66 +0,0 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
-
3
- /**
4
- * The three builders a validator library supplies so the surface and the workflows stay library-free
5
- * (#383) while the union/enum/object they derive are still real schemas of THAT library — the one
6
- * place a consumer's zod enters `@geonosis/document` is through this adapter, never a dependency.
7
- */
8
- type SchemaAdapter = {
9
- enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
10
- object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
11
- union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
12
- };
13
- declare const stringSchema: StandardSchemaV1<unknown, string>;
14
- declare const numberSchema: StandardSchemaV1<unknown, number>;
15
- declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
16
- declare const literalOf: <Value extends boolean | string>(literal: Value) => StandardSchemaV1<unknown, Value>;
17
- /** A passthrough for a shape this ticket declares but does not itself narrow further. */
18
- declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
19
- declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
20
- declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
21
- declare const arrayOf: <Output>(item: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output[]>;
22
- /** Every schema's own issues, folded into one — the merged VALUE is every schema's fields, spread. */
23
- declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
24
- declare const nonEmptyString: StandardSchemaV1<unknown, string>;
25
- declare const positiveInt: StandardSchemaV1<unknown, number>;
26
- /** One value through one schema, whichever library wrote it; the issues are the refusal's text. */
27
- declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
28
- declare const enumOf: <Value extends string>(values: readonly Value[]) => StandardSchemaV1<unknown, Value>;
29
- /**
30
- * An object of named fields, each through its own schema — the one builder a workflow input needs
31
- * that the adapter is not asked for, since a run's input is refused by the engine and never rendered
32
- * by a host's own library. Async when a field's schema is; unknown keys are dropped.
33
- */
34
- declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
35
-
36
- /**
37
- * The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
38
- * revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
39
- * collides with the one it replaced.
40
- */
41
- type ArchivePort = {
42
- head: (key: string) => Promise<{
43
- hash: string;
44
- } | null>;
45
- put: (key: string, bytes: Uint8Array, meta: {
46
- hash: string;
47
- immutable: true;
48
- }) => Promise<void>;
49
- };
50
- /** A trusted third party's timestamp over a hash — never implemented here, only declared. */
51
- type TimestampPort = {
52
- stamp: (hash: string) => Promise<{
53
- at: number;
54
- token: Uint8Array;
55
- }>;
56
- };
57
- type LinkVerifierPort = {
58
- verify: (token: string) => Promise<{
59
- entity: string;
60
- exp: number;
61
- org: string;
62
- ref: string;
63
- } | null>;
64
- };
65
-
66
- export { type ArchivePort as A, type LinkVerifierPort as L, type SchemaAdapter as S, type TimestampPort as T, arrayOf as a, booleanSchema as b, nullable as c, numberSchema as d, enumOf as e, optional as f, literalOf as l, merge as m, nonEmptyString as n, objectOf as o, positiveInt as p, stringSchema as s, unknownSchema as u, validate as v };