@geonosis/document 0.9.0 → 0.9.2

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 +16 -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
package/dist/store.d.cts CHANGED
@@ -1,277 +1,4 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { f as DocumentHead, A as AnyDocumentEntity, b as DocumentBodyMigrations, g as DocumentInstance, o as documentEntities, j as DocumentStatusMachine } from './entities-DTNJMeVf.cjs';
3
- import { A as ArchivePort, S as SchemaAdapter } from './ports-C_OfflMQ.cjs';
4
- import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, AggregateRow, SessionSeam } from '@geonosis/db';
5
- export { AggregateRow, ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
6
-
7
- /** sha256 hex over the canonical JSON of `payload` — no whitespace, keys sorted recursively. */
8
- declare const hashOf: (payload: unknown) => Promise<string>;
9
-
10
- declare const DEFAULT_DOCUMENT_TABLE = "documents";
11
- declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
12
- declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
13
- type HeadField = keyof DocumentHead;
14
- declare const HEAD_FIELDS: HeadField[];
15
- type DocumentColumns = EntityColumns & {
16
- entity?: string;
17
- heads?: Partial<Record<HeadField, EntityName>>;
18
- revisionKind?: string;
19
- total?: EntityName;
20
- };
21
- type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
22
- createdAt: string;
23
- entity: string;
24
- tenant: string;
25
- updatedAt: string;
26
- };
27
- declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
28
- type DocumentRevisionsOptions = {
29
- table?: string;
30
- };
31
- type DocumentMigrationsOptions = {
32
- appRole?: string;
33
- columns?: DocumentColumns;
34
- freeze?: FreezeRegister;
35
- names?: TenantPolicyNames;
36
- revisions?: DocumentRevisionsOptions | false;
37
- schema?: string;
38
- settings: SessionSettings;
39
- table?: string;
40
- };
41
- type AppendOnlyTablesOptions = {
42
- table?: string;
43
- revisions?: DocumentRevisionsOptions | false;
44
- };
45
- declare const appendOnlyTables: (options?: AppendOnlyTablesOptions) => string[];
46
- declare const documentRoleStatements: (appRole: string, options?: AppendOnlyTablesOptions & {
47
- schema?: string;
48
- }) => string[];
49
- declare const documentMigrations: (options: DocumentMigrationsOptions) => EntityMigration[];
50
-
51
- type StorableDocumentEntity = AnyDocumentEntity & {
52
- bodyVersion?: number;
53
- headOf: (body: never) => DocumentHead;
54
- migrations?: DocumentBodyMigrations<Record<string, unknown>>;
55
- prepare: (body: never) => unknown;
56
- };
57
- type Registry$1<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
58
- type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
59
- archive?: ArchivePort;
60
- columns?: DocumentColumns;
61
- registry: Registry$1<Map>;
62
- revisions?: DocumentRevisionsOptions | false;
63
- schema?: string;
64
- seam: SessionSeam<Key, Handle>;
65
- table?: string;
66
- };
67
- /** What a head projection may carry: the business head, the entity, the number, and the record's clocks. */
68
- type HeadColumn = HeadField | 'createdAt' | 'entity' | 'number' | 'updatedAt';
69
- type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
70
- type HeadsOrder = {
71
- column: DocumentSortColumn | 'entity';
72
- direction?: 'asc' | 'desc';
73
- };
74
- type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt', unknown | readonly unknown[] | {
75
- from: unknown;
76
- to: unknown;
77
- }>>>;
78
- type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
79
- createdAt: number;
80
- entity: string;
81
- number: string;
82
- updatedAt: number;
83
- }, Columns[number]>;
84
- type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
85
- columns: Columns;
86
- entity?: string | readonly string[];
87
- order: readonly HeadsOrder[];
88
- where?: HeadsWhere;
89
- };
90
- type AggregateMeasure = 'count' | 'sum:total';
91
- type AggregateBy = HeadField | 'entity' | {
92
- bucket: 'day' | 'month' | 'week';
93
- of: 'dueDate' | 'issueDate';
94
- };
95
- type AggregateWhere = HeadsWhere;
96
-
97
- type AggregateArgs = {
98
- by?: AggregateBy;
99
- entities?: readonly string[];
100
- entity?: string;
101
- measures: readonly AggregateMeasure[];
102
- where?: AggregateWhere;
103
- };
104
- type Item = DocumentInstance<string, unknown>;
105
- type DocumentKind = 'committed' | 'reinstated' | 'retired';
106
- type CommitOutput = {
107
- archived?: undefined;
108
- committed: false;
109
- hash?: undefined;
110
- lineage: number;
111
- previous?: undefined;
112
- ref: string;
113
- version: number;
114
- } | {
115
- archived?: boolean;
116
- committed: true;
117
- hash: string;
118
- lineage: number;
119
- previous: {
120
- hash: string;
121
- version: number;
122
- } | null;
123
- ref: string;
124
- version: number;
125
- };
126
- type RetireOutput = {
127
- hash: string;
128
- lineage: number;
129
- ref: string;
130
- version: number;
131
- };
132
- type ReinstateOutput = {
133
- hash: string;
134
- lineage: number;
135
- ref: string;
136
- version: number;
137
- };
138
- type HistoryEntry = {
139
- actor: string;
140
- at: number;
141
- body: unknown;
142
- hash: string;
143
- kind: DocumentKind;
144
- reason: string | null;
145
- version: number;
146
- };
147
- type VerifyResult = {
148
- brokenAt: number;
149
- expected: string;
150
- found: string;
151
- ok: false;
152
- } | {
153
- ok: true;
154
- versions: number;
155
- };
156
- type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pick<Projection<unknown, Item, Key, 'ref', Handle, string, string>, 'get' | 'listAll'> & {
157
- asOf: Query<Readonly<Record<Key, string>> & {
158
- at: number;
159
- ref: string;
160
- }, Item | null, Handle>;
161
- at: Query<Readonly<Record<Key, string>> & {
162
- ref: string;
163
- version: number;
164
- }, Item | null, Handle>;
165
- commit: Query<Readonly<Record<Key, string>> & {
166
- actor: string;
167
- body: unknown;
168
- reason?: string;
169
- ref: string;
170
- }, CommitOutput, Handle>;
171
- history: Query<Readonly<Record<Key, string>> & {
172
- lineage?: number;
173
- ref: string;
174
- }, HistoryEntry[], Handle>;
175
- list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
176
- reinstate: Query<Readonly<Record<Key, string>> & {
177
- actor: string;
178
- reason?: string;
179
- ref: string;
180
- }, ReinstateOutput, Handle>;
181
- retire: Query<Readonly<Record<Key, string>> & {
182
- actor: string;
183
- reason?: string;
184
- ref: string;
185
- }, RetireOutput, Handle>;
186
- succeed: Query<Readonly<Record<Key, string>> & {
187
- actor: string;
188
- body: unknown;
189
- reason?: string;
190
- ref: string;
191
- }, CommitOutput, Handle>;
192
- undos: {
193
- commit: EntityUndo<CommitOutput, Handle>;
194
- retire: EntityUndo<RetireOutput, Handle>;
195
- };
196
- verify: Query<Readonly<Record<Key, string>> & {
197
- lineage?: number;
198
- ref: string;
199
- }, VerifyResult, Handle>;
200
- };
201
- type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
202
- [Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
203
- } & {
204
- aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
205
- heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
206
- rebuild: Query<Readonly<Record<Key, string>> & {
207
- entity?: string;
208
- }, {
209
- rows: number;
210
- }, Handle>;
211
- };
212
- 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>;
213
-
214
- type SurfaceVerb = 'query' | 'mutation';
215
- type SurfaceScope = 'org' | 'public' | 'token';
216
- /** The row's own declaration of what a workflow (not yet landed) will bind it to. */
217
- type PendingCall = {
218
- pending: 'T3';
219
- workflow: string;
220
- };
221
- /**
222
- * A row as a caller calls it — the entity's own signature (D-065's `ref`, never `number`) with a
223
- * leading handle, the same convention `BoundQuery` already states in `@geonosis/workflows`, made
224
- * explicit here since a row is DATA before it is a function: reading `params.ref` off `never`
225
- * compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
226
- */
227
- type SurfaceCall = (handle: never, params: never) => Promise<unknown>;
228
- /** The adapter as the surface first named it; the builders live in the core now. */
229
- type SurfaceSchemaAdapter = SchemaAdapter;
230
- type SurfaceRow = {
231
- call: PendingCall | SurfaceCall;
232
- input: StandardSchemaV1;
233
- name: string;
234
- output: StandardSchemaV1;
235
- path: string;
236
- scope: SurfaceScope;
237
- verb: SurfaceVerb;
238
- };
239
- /**
240
- * What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
241
- * what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
242
- * caller never sees two overlapping bounds for the one registry it built.
243
- */
244
- type SurfaceDocumentEntity = AnyDocumentEntity & {
245
- basePath: string;
246
- bodyVersion?: number;
247
- card: {
248
- of: (document: never, names: {
249
- counterpartyName: string;
250
- }) => unknown;
251
- schema: StandardSchemaV1;
252
- };
253
- draft: StandardSchemaV1;
254
- headOf: (body: never) => DocumentHead;
255
- migrations?: DocumentBodyMigrations<Record<string, unknown>>;
256
- prepare: (body: never) => unknown;
257
- statusOf: (body: never) => string;
258
- statuses: DocumentStatusMachine<string>;
259
- withStatus: (body: never, status: string, at: string) => unknown;
260
- };
261
- type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
262
- type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
263
- registry: Registry<Map>;
264
- schema: SurfaceSchemaAdapter;
265
- store: DocumentStore<Map, Key, Handle>;
266
- };
267
- /**
268
- * `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
269
- * from — never authored by hand, and never a map a caller fills in per entity (#383). Reads and
270
- * `commit`/`retire`/`reinstate`/`setStatus` bind `call` to the store already composed; the saga
271
- * rows (`create`, `send`, `duplicate`, `run-started`) are declared with their own input/output and
272
- * a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
273
- * BY NAME, never with a stub answer.
274
- */
275
- declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
276
-
277
- export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateWhere, type AppendOnlyTablesOptions, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, type DocumentColumns, type DocumentKind, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type PendingCall, type ReinstateOutput, type RetireOutput, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type VerifyResult, appendOnlyTables, documentMigrations, documentRoleStatements, documentStore, documentSurface, hashOf, physicalColumnsOf };
1
+ export { hashOf } from './store/hash.cjs';
2
+ export { documentSurface, type DocumentSurfaceOptions, type PendingCall, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.cjs';
3
+ export { appendOnlyTables, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISION_KIND_COLUMN, DEFAULT_REVISIONS_TABLE, DOCUMENT_MIGRATION_PLACEHOLDERS, documentMigrations, documentRoleStatements, HEAD_FIELDS, type AppendOnlyTablesOptions, type DocumentColumns, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type HeadField, physicalColumnsOf } from './store/ddl.cjs';
4
+ export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.cjs';
package/dist/store.d.ts CHANGED
@@ -1,277 +1,4 @@
1
- import { StandardSchemaV1 } from '@standard-schema/spec';
2
- import { f as DocumentHead, A as AnyDocumentEntity, b as DocumentBodyMigrations, g as DocumentInstance, o as documentEntities, j as DocumentStatusMachine } from './entities-DTNJMeVf.js';
3
- import { A as ArchivePort, S as SchemaAdapter } from './ports-C_OfflMQ.js';
4
- import { EntityColumns, EntityName, FreezeRegister, TenantPolicyNames, SessionSettings, EntityMigration, DrizzleHandle, Projection, Query, EntityListing, EntityPage, EntityUndo, AggregateRow, SessionSeam } from '@geonosis/db';
5
- export { AggregateRow, ENTITY_PLACEHOLDERS as DOCUMENT_MIGRATION_PLACEHOLDERS } from '@geonosis/db';
6
-
7
- /** sha256 hex over the canonical JSON of `payload` — no whitespace, keys sorted recursively. */
8
- declare const hashOf: (payload: unknown) => Promise<string>;
9
-
10
- declare const DEFAULT_DOCUMENT_TABLE = "documents";
11
- declare const DEFAULT_REVISIONS_TABLE = "document_revisions";
12
- declare const DEFAULT_REVISION_KIND_COLUMN = "revision_kind";
13
- type HeadField = keyof DocumentHead;
14
- declare const HEAD_FIELDS: HeadField[];
15
- type DocumentColumns = EntityColumns & {
16
- entity?: string;
17
- heads?: Partial<Record<HeadField, EntityName>>;
18
- revisionKind?: string;
19
- total?: EntityName;
20
- };
21
- type DocumentPhysicalColumns = Readonly<Record<HeadField, string>> & {
22
- createdAt: string;
23
- entity: string;
24
- tenant: string;
25
- updatedAt: string;
26
- };
27
- declare const physicalColumnsOf: (columns: DocumentColumns | undefined) => DocumentPhysicalColumns;
28
- type DocumentRevisionsOptions = {
29
- table?: string;
30
- };
31
- type DocumentMigrationsOptions = {
32
- appRole?: string;
33
- columns?: DocumentColumns;
34
- freeze?: FreezeRegister;
35
- names?: TenantPolicyNames;
36
- revisions?: DocumentRevisionsOptions | false;
37
- schema?: string;
38
- settings: SessionSettings;
39
- table?: string;
40
- };
41
- type AppendOnlyTablesOptions = {
42
- table?: string;
43
- revisions?: DocumentRevisionsOptions | false;
44
- };
45
- declare const appendOnlyTables: (options?: AppendOnlyTablesOptions) => string[];
46
- declare const documentRoleStatements: (appRole: string, options?: AppendOnlyTablesOptions & {
47
- schema?: string;
48
- }) => string[];
49
- declare const documentMigrations: (options: DocumentMigrationsOptions) => EntityMigration[];
50
-
51
- type StorableDocumentEntity = AnyDocumentEntity & {
52
- bodyVersion?: number;
53
- headOf: (body: never) => DocumentHead;
54
- migrations?: DocumentBodyMigrations<Record<string, unknown>>;
55
- prepare: (body: never) => unknown;
56
- };
57
- type Registry$1<Map extends Readonly<Record<string, StorableDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
58
- type DocumentStoreOptions<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
59
- archive?: ArchivePort;
60
- columns?: DocumentColumns;
61
- registry: Registry$1<Map>;
62
- revisions?: DocumentRevisionsOptions | false;
63
- schema?: string;
64
- seam: SessionSeam<Key, Handle>;
65
- table?: string;
66
- };
67
- /** What a head projection may carry: the business head, the entity, the number, and the record's clocks. */
68
- type HeadColumn = HeadField | 'createdAt' | 'entity' | 'number' | 'updatedAt';
69
- type DocumentSortColumn = HeadField | 'createdAt' | 'number' | 'updatedAt';
70
- type HeadsOrder = {
71
- column: DocumentSortColumn | 'entity';
72
- direction?: 'asc' | 'desc';
73
- };
74
- type HeadsWhere = Readonly<Partial<Record<HeadField | 'createdAt' | 'updatedAt', unknown | readonly unknown[] | {
75
- from: unknown;
76
- to: unknown;
77
- }>>>;
78
- type HeadRow<Columns extends readonly HeadColumn[]> = Pick<DocumentHead & {
79
- createdAt: number;
80
- entity: string;
81
- number: string;
82
- updatedAt: number;
83
- }, Columns[number]>;
84
- type HeadsArgs<Columns extends readonly HeadColumn[] = readonly HeadColumn[]> = {
85
- columns: Columns;
86
- entity?: string | readonly string[];
87
- order: readonly HeadsOrder[];
88
- where?: HeadsWhere;
89
- };
90
- type AggregateMeasure = 'count' | 'sum:total';
91
- type AggregateBy = HeadField | 'entity' | {
92
- bucket: 'day' | 'month' | 'week';
93
- of: 'dueDate' | 'issueDate';
94
- };
95
- type AggregateWhere = HeadsWhere;
96
-
97
- type AggregateArgs = {
98
- by?: AggregateBy;
99
- entities?: readonly string[];
100
- entity?: string;
101
- measures: readonly AggregateMeasure[];
102
- where?: AggregateWhere;
103
- };
104
- type Item = DocumentInstance<string, unknown>;
105
- type DocumentKind = 'committed' | 'reinstated' | 'retired';
106
- type CommitOutput = {
107
- archived?: undefined;
108
- committed: false;
109
- hash?: undefined;
110
- lineage: number;
111
- previous?: undefined;
112
- ref: string;
113
- version: number;
114
- } | {
115
- archived?: boolean;
116
- committed: true;
117
- hash: string;
118
- lineage: number;
119
- previous: {
120
- hash: string;
121
- version: number;
122
- } | null;
123
- ref: string;
124
- version: number;
125
- };
126
- type RetireOutput = {
127
- hash: string;
128
- lineage: number;
129
- ref: string;
130
- version: number;
131
- };
132
- type ReinstateOutput = {
133
- hash: string;
134
- lineage: number;
135
- ref: string;
136
- version: number;
137
- };
138
- type HistoryEntry = {
139
- actor: string;
140
- at: number;
141
- body: unknown;
142
- hash: string;
143
- kind: DocumentKind;
144
- reason: string | null;
145
- version: number;
146
- };
147
- type VerifyResult = {
148
- brokenAt: number;
149
- expected: string;
150
- found: string;
151
- ok: false;
152
- } | {
153
- ok: true;
154
- versions: number;
155
- };
156
- type DocumentEntityStore<Key extends string, Handle extends DrizzleHandle> = Pick<Projection<unknown, Item, Key, 'ref', Handle, string, string>, 'get' | 'listAll'> & {
157
- asOf: Query<Readonly<Record<Key, string>> & {
158
- at: number;
159
- ref: string;
160
- }, Item | null, Handle>;
161
- at: Query<Readonly<Record<Key, string>> & {
162
- ref: string;
163
- version: number;
164
- }, Item | null, Handle>;
165
- commit: Query<Readonly<Record<Key, string>> & {
166
- actor: string;
167
- body: unknown;
168
- reason?: string;
169
- ref: string;
170
- }, CommitOutput, Handle>;
171
- history: Query<Readonly<Record<Key, string>> & {
172
- lineage?: number;
173
- ref: string;
174
- }, HistoryEntry[], Handle>;
175
- list: Query<Readonly<Record<Key, string>> & EntityListing<DocumentSortColumn, HeadField>, EntityPage<Item>, Handle>;
176
- reinstate: Query<Readonly<Record<Key, string>> & {
177
- actor: string;
178
- reason?: string;
179
- ref: string;
180
- }, ReinstateOutput, Handle>;
181
- retire: Query<Readonly<Record<Key, string>> & {
182
- actor: string;
183
- reason?: string;
184
- ref: string;
185
- }, RetireOutput, Handle>;
186
- succeed: Query<Readonly<Record<Key, string>> & {
187
- actor: string;
188
- body: unknown;
189
- reason?: string;
190
- ref: string;
191
- }, CommitOutput, Handle>;
192
- undos: {
193
- commit: EntityUndo<CommitOutput, Handle>;
194
- retire: EntityUndo<RetireOutput, Handle>;
195
- };
196
- verify: Query<Readonly<Record<Key, string>> & {
197
- lineage?: number;
198
- ref: string;
199
- }, VerifyResult, Handle>;
200
- };
201
- type DocumentStore<Map extends Readonly<Record<string, StorableDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
202
- [Name in keyof Map & string]: DocumentEntityStore<Key, Handle>;
203
- } & {
204
- aggregate: Query<Readonly<Record<Key, string>> & AggregateArgs, AggregateRow[], Handle>;
205
- heads: <Columns extends readonly HeadColumn[]>(handle: Handle, params: Readonly<Record<Key, string>> & HeadsArgs<Columns>) => Promise<HeadRow<Columns>[]>;
206
- rebuild: Query<Readonly<Record<Key, string>> & {
207
- entity?: string;
208
- }, {
209
- rows: number;
210
- }, Handle>;
211
- };
212
- 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>;
213
-
214
- type SurfaceVerb = 'query' | 'mutation';
215
- type SurfaceScope = 'org' | 'public' | 'token';
216
- /** The row's own declaration of what a workflow (not yet landed) will bind it to. */
217
- type PendingCall = {
218
- pending: 'T3';
219
- workflow: string;
220
- };
221
- /**
222
- * A row as a caller calls it — the entity's own signature (D-065's `ref`, never `number`) with a
223
- * leading handle, the same convention `BoundQuery` already states in `@geonosis/workflows`, made
224
- * explicit here since a row is DATA before it is a function: reading `params.ref` off `never`
225
- * compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
226
- */
227
- type SurfaceCall = (handle: never, params: never) => Promise<unknown>;
228
- /** The adapter as the surface first named it; the builders live in the core now. */
229
- type SurfaceSchemaAdapter = SchemaAdapter;
230
- type SurfaceRow = {
231
- call: PendingCall | SurfaceCall;
232
- input: StandardSchemaV1;
233
- name: string;
234
- output: StandardSchemaV1;
235
- path: string;
236
- scope: SurfaceScope;
237
- verb: SurfaceVerb;
238
- };
239
- /**
240
- * What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
241
- * what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
242
- * caller never sees two overlapping bounds for the one registry it built.
243
- */
244
- type SurfaceDocumentEntity = AnyDocumentEntity & {
245
- basePath: string;
246
- bodyVersion?: number;
247
- card: {
248
- of: (document: never, names: {
249
- counterpartyName: string;
250
- }) => unknown;
251
- schema: StandardSchemaV1;
252
- };
253
- draft: StandardSchemaV1;
254
- headOf: (body: never) => DocumentHead;
255
- migrations?: DocumentBodyMigrations<Record<string, unknown>>;
256
- prepare: (body: never) => unknown;
257
- statusOf: (body: never) => string;
258
- statuses: DocumentStatusMachine<string>;
259
- withStatus: (body: never, status: string, at: string) => unknown;
260
- };
261
- type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
262
- type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle> = {
263
- registry: Registry<Map>;
264
- schema: SurfaceSchemaAdapter;
265
- store: DocumentStore<Map, Key, Handle>;
266
- };
267
- /**
268
- * `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
269
- * from — never authored by hand, and never a map a caller fills in per entity (#383). Reads and
270
- * `commit`/`retire`/`reinstate`/`setStatus` bind `call` to the store already composed; the saga
271
- * rows (`create`, `send`, `duplicate`, `run-started`) are declared with their own input/output and
272
- * a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
273
- * BY NAME, never with a stub answer.
274
- */
275
- declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DrizzleHandle = DrizzleHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
276
-
277
- export { type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateWhere, type AppendOnlyTablesOptions, type CommitOutput, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISIONS_TABLE, DEFAULT_REVISION_KIND_COLUMN, type DocumentColumns, type DocumentKind, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type DocumentSurfaceOptions, HEAD_FIELDS, type HeadColumn, type HeadField, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type PendingCall, type ReinstateOutput, type RetireOutput, type SurfaceCall, type SurfaceRow, type SurfaceSchemaAdapter, type SurfaceScope, type SurfaceVerb, type VerifyResult, appendOnlyTables, documentMigrations, documentRoleStatements, documentStore, documentSurface, hashOf, physicalColumnsOf };
1
+ export { hashOf } from './store/hash.js';
2
+ export { documentSurface, type DocumentSurfaceOptions, type PendingCall, type SurfaceCall, type SurfaceRow, type SurfaceScope, type SurfaceSchemaAdapter, type SurfaceVerb } from './surface/table.js';
3
+ export { appendOnlyTables, DEFAULT_DOCUMENT_TABLE, DEFAULT_REVISION_KIND_COLUMN, DEFAULT_REVISIONS_TABLE, DOCUMENT_MIGRATION_PLACEHOLDERS, documentMigrations, documentRoleStatements, HEAD_FIELDS, type AppendOnlyTablesOptions, type DocumentColumns, type DocumentMigrationsOptions, type DocumentPhysicalColumns, type DocumentRevisionsOptions, type HeadField, physicalColumnsOf } from './store/ddl.js';
4
+ export { documentStore, type AggregateArgs, type AggregateBy, type AggregateMeasure, type AggregateRow, type AggregateWhere, type CommitOutput, type DocumentKind, type DocumentSortColumn, type DocumentStore, type DocumentStoreOptions, type HeadColumn, type HeadRow, type HeadsArgs, type HeadsOrder, type HeadsWhere, type HistoryEntry, type ReinstateOutput, type RetireOutput, type VerifyResult } from './store/store.js';