@geonosis/document 0.9.3 → 0.10.1

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 (79) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +78 -13
  3. package/dist/core/actor.d.cts +0 -1
  4. package/dist/core/actor.d.ts +0 -1
  5. package/dist/core/body-version.d.cts +0 -9
  6. package/dist/core/body-version.d.ts +0 -9
  7. package/dist/core/canonical.cjs +2 -3
  8. package/dist/core/canonical.d.cts +0 -4
  9. package/dist/core/canonical.d.ts +0 -4
  10. package/dist/core/canonical.js +2 -3
  11. package/dist/core/document.cjs +28 -25
  12. package/dist/core/document.d.cts +3 -22
  13. package/dist/core/document.d.ts +3 -22
  14. package/dist/core/document.js +28 -25
  15. package/dist/core/entities.d.cts +0 -19
  16. package/dist/core/entities.d.ts +0 -19
  17. package/dist/core/naming.d.cts +0 -5
  18. package/dist/core/naming.d.ts +0 -5
  19. package/dist/core/numbering.d.cts +0 -4
  20. package/dist/core/numbering.d.ts +0 -4
  21. package/dist/core/ports.d.cts +0 -6
  22. package/dist/core/ports.d.ts +0 -6
  23. package/dist/core/schema.cjs +44 -76
  24. package/dist/core/schema.d.cts +1 -13
  25. package/dist/core/schema.d.ts +1 -13
  26. package/dist/core/schema.js +44 -76
  27. package/dist/core/status.d.cts +0 -1
  28. package/dist/core/status.d.ts +0 -1
  29. package/dist/index.cjs +1 -0
  30. package/dist/index.d.cts +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.js +2 -0
  33. package/dist/store/ddl.cjs +35 -38
  34. package/dist/store/ddl.d.cts +6 -6
  35. package/dist/store/ddl.d.ts +6 -6
  36. package/dist/store/ddl.js +37 -39
  37. package/dist/store/hash.d.cts +0 -1
  38. package/dist/store/hash.d.ts +0 -1
  39. package/dist/store/number-for.cjs +52 -0
  40. package/dist/store/number-for.d.cts +11 -0
  41. package/dist/store/number-for.d.ts +11 -0
  42. package/dist/store/number-for.js +12 -0
  43. package/dist/store/store.cjs +188 -162
  44. package/dist/store/store.d.cts +57 -16
  45. package/dist/store/store.d.ts +57 -16
  46. package/dist/store/store.js +190 -163
  47. package/dist/store.cjs +2 -0
  48. package/dist/store.d.cts +3 -2
  49. package/dist/store.d.ts +3 -2
  50. package/dist/store.js +2 -0
  51. package/dist/surface/table.cjs +129 -66
  52. package/dist/surface/table.d.cts +20 -28
  53. package/dist/surface/table.d.ts +20 -28
  54. package/dist/surface/table.js +132 -66
  55. package/dist/workflows/bindings.cjs +48 -0
  56. package/dist/workflows/bindings.d.cts +15 -0
  57. package/dist/workflows/bindings.d.ts +15 -0
  58. package/dist/workflows/bindings.js +10 -0
  59. package/dist/workflows/document-workflows.cjs +29 -40
  60. package/dist/workflows/document-workflows.d.cts +0 -12
  61. package/dist/workflows/document-workflows.d.ts +0 -12
  62. package/dist/workflows/document-workflows.js +29 -40
  63. package/dist/workflows/effects.d.cts +0 -12
  64. package/dist/workflows/effects.d.ts +0 -12
  65. package/dist/workflows/ports.d.cts +0 -17
  66. package/dist/workflows/ports.d.ts +0 -17
  67. package/dist/workflows/refusals.cjs +30 -0
  68. package/dist/workflows/refusals.d.cts +37 -9
  69. package/dist/workflows/refusals.d.ts +37 -9
  70. package/dist/workflows/refusals.js +30 -0
  71. package/dist/workflows/shared.cjs +93 -0
  72. package/dist/workflows/shared.d.cts +28 -0
  73. package/dist/workflows/shared.d.ts +28 -0
  74. package/dist/workflows/shared.js +60 -0
  75. package/dist/workflows.cjs +16 -1
  76. package/dist/workflows.d.cts +3 -1
  77. package/dist/workflows.d.ts +3 -1
  78. package/dist/workflows.js +31 -1
  79. package/package.json +4 -4
@@ -45,6 +45,8 @@ module.exports = __toCommonJS(exports_table);
45
45
  var import_document = require("../core/document.cjs");
46
46
  var import_schema = require("../core/schema.cjs");
47
47
  var import_status = require("../core/status.cjs");
48
+ var import_ddl = require("../store/ddl.cjs");
49
+ var import_bindings = require("../workflows/bindings.cjs");
48
50
  var doorFor = (store, name) => {
49
51
  const door = store[name];
50
52
  if (door === undefined) {
@@ -52,20 +54,56 @@ var doorFor = (store, name) => {
52
54
  }
53
55
  return door;
54
56
  };
55
- var HEAD_COLUMNS = Object.keys(import_document.Document.headFields);
56
- var SORT_COLUMNS = [...HEAD_COLUMNS, "number", "createdAt", "updatedAt"];
57
- var rowsFor = (definition, store, schema) => {
57
+ var SORT_COLUMNS = [...import_ddl.HEAD_FIELDS, "number", "createdAt", "updatedAt"];
58
+ var orderTerm = (schema, columns) => schema.object({
59
+ column: schema.enum(columns),
60
+ direction: import_schema.optional(schema.enum(["asc", "desc"]))
61
+ });
62
+ var listInputFor = (schema, orderColumns, extra = {}) => schema.object({
63
+ cursor: import_schema.optional(import_schema.nullable(import_schema.stringSchema)),
64
+ ...extra,
65
+ filter: import_schema.optional(schema.object(Object.fromEntries(import_ddl.HEAD_FIELDS.map((column) => [column, import_schema.optional(import_schema.stringSchema)])))),
66
+ limit: import_schema.optional(import_schema.numberSchema),
67
+ order: import_schema.optional(orderTerm(schema, orderColumns))
68
+ });
69
+ var instanceSchemaFor = (definition, schema) => import_schema.merge([
70
+ import_document.Document.head,
71
+ import_document.Document.record,
72
+ schema.object({
73
+ body: definition.view,
74
+ entity: schema.enum([definition.name]),
75
+ number: import_schema.stringSchema
76
+ })
77
+ ]);
78
+ var NO_NAMES = new Map;
79
+ var namesFor = async (resolve, items) => {
80
+ const ids = [
81
+ ...new Set(items.flatMap((item) => item.counterparty === null ? [] : [item.counterparty]))
82
+ ];
83
+ if (resolve === undefined || ids.length === 0)
84
+ return NO_NAMES;
85
+ return resolve.counterpartyName(ids);
86
+ };
87
+ var cardOf = (definition, item, names) => definition.card.of(item, {
88
+ counterpartyName: item.counterparty === null ? "" : names.get(item.counterparty) ?? ""
89
+ });
90
+ var rowsFor = (definition, store, schema, bound) => {
58
91
  const { name } = definition;
59
92
  const door = doorFor(store, name);
60
93
  const basePath = `/${definition.basePath}`;
61
- const instanceSchema = import_schema.merge([
62
- import_document.Document.head,
63
- import_document.Document.record,
64
- schema.object({ body: definition.view, entity: schema.enum([name]), number: import_schema.stringSchema })
65
- ]);
94
+ const instanceSchema = instanceSchemaFor(definition, schema);
95
+ const head = import_document.Document.head;
96
+ const createdOutput = schema.object({
97
+ body: definition.body,
98
+ entity: schema.enum([name]),
99
+ minted: import_schema.nullable(schema.object({ sequence: import_schema.numberSchema })),
100
+ number: import_schema.stringSchema
101
+ });
102
+ const startedOutput = schema.object({ deduplicated: import_schema.booleanSchema, runId: import_schema.stringSchema });
66
103
  const commitOutput = schema.union([
67
104
  schema.object({
68
105
  committed: import_schema.literalOf(false),
106
+ head,
69
107
  lineage: import_schema.numberSchema,
70
108
  ref: import_schema.stringSchema,
71
109
  version: import_schema.numberSchema
@@ -74,6 +112,7 @@ var rowsFor = (definition, store, schema) => {
74
112
  archived: import_schema.optional(import_schema.booleanSchema),
75
113
  committed: import_schema.literalOf(true),
76
114
  hash: import_schema.stringSchema,
115
+ head,
77
116
  lineage: import_schema.numberSchema,
78
117
  previous: import_schema.nullable(schema.object({ hash: import_schema.stringSchema, version: import_schema.numberSchema })),
79
118
  ref: import_schema.stringSchema,
@@ -82,6 +121,7 @@ var rowsFor = (definition, store, schema) => {
82
121
  ]);
83
122
  const retireLikeOutput = schema.object({
84
123
  hash: import_schema.stringSchema,
124
+ head,
85
125
  lineage: import_schema.numberSchema,
86
126
  ref: import_schema.stringSchema,
87
127
  version: import_schema.numberSchema
@@ -100,27 +140,24 @@ var rowsFor = (definition, store, schema) => {
100
140
  at: import_schema.numberSchema,
101
141
  body: import_schema.unknownSchema,
102
142
  hash: import_schema.stringSchema,
103
- kind: schema.enum(["committed", "retired", "reinstated"]),
143
+ kind: schema.enum(import_ddl.REVISION_KINDS),
104
144
  reason: import_schema.nullable(import_schema.stringSchema),
105
145
  version: import_schema.numberSchema
106
146
  }));
107
- const listInput = schema.object({
108
- cursor: import_schema.optional(import_schema.nullable(import_schema.stringSchema)),
109
- filter: import_schema.optional(schema.object(Object.fromEntries(HEAD_COLUMNS.map((column) => [column, import_schema.optional(import_schema.stringSchema)])))),
110
- limit: import_schema.optional(import_schema.numberSchema),
111
- order: import_schema.optional(schema.object({
112
- column: schema.enum(SORT_COLUMNS),
113
- direction: import_schema.optional(schema.enum(["asc", "desc"]))
114
- }))
115
- });
116
147
  const listOutput = schema.object({
117
148
  items: import_schema.arrayOf(import_schema.merge([instanceSchema, schema.object({ card: definition.card.schema })])),
118
149
  nextCursor: import_schema.nullable(import_schema.stringSchema)
119
150
  });
120
- const ackOutput = schema.object({ ref: import_schema.stringSchema });
151
+ const streamInput = schema.object({ lineage: import_schema.optional(import_schema.numberSchema), ref: import_schema.stringSchema });
152
+ const actedInput = schema.object({
153
+ actor: import_schema.stringSchema,
154
+ reason: import_schema.optional(import_schema.stringSchema),
155
+ ref: import_schema.stringSchema
156
+ });
157
+ const via = (verb) => (handle, params) => door[verb](handle, params);
121
158
  return [
122
159
  {
123
- call: (handle, params) => door.get(handle, params),
160
+ call: via("get"),
124
161
  input: schema.object({ ref: import_schema.stringSchema }),
125
162
  name: `${name}.get`,
126
163
  output: import_schema.nullable(instanceSchema),
@@ -131,15 +168,16 @@ var rowsFor = (definition, store, schema) => {
131
168
  {
132
169
  call: async (handle, params) => {
133
170
  const page = await door.list(handle, params);
171
+ const names = await namesFor(bound.resolve, page.items);
134
172
  return {
135
173
  items: page.items.map((item) => ({
136
174
  ...item,
137
- card: definition.card.of(item, { counterpartyName: "" })
175
+ card: cardOf(definition, item, names)
138
176
  })),
139
177
  nextCursor: page.nextCursor
140
178
  };
141
179
  },
142
- input: listInput,
180
+ input: listInputFor(schema, SORT_COLUMNS),
143
181
  name: `${name}.list`,
144
182
  output: listOutput,
145
183
  path: basePath,
@@ -147,8 +185,8 @@ var rowsFor = (definition, store, schema) => {
147
185
  verb: "query"
148
186
  },
149
187
  {
150
- call: (handle, params) => door.history(handle, params),
151
- input: schema.object({ lineage: import_schema.optional(import_schema.numberSchema), ref: import_schema.stringSchema }),
188
+ call: via("history"),
189
+ input: streamInput,
152
190
  name: `${name}.history`,
153
191
  output: historyOutput,
154
192
  path: `${basePath}/:ref/history`,
@@ -156,8 +194,8 @@ var rowsFor = (definition, store, schema) => {
156
194
  verb: "query"
157
195
  },
158
196
  {
159
- call: (handle, params) => door.verify(handle, params),
160
- input: schema.object({ lineage: import_schema.optional(import_schema.numberSchema), ref: import_schema.stringSchema }),
197
+ call: via("verify"),
198
+ input: streamInput,
161
199
  name: `${name}.verify`,
162
200
  output: verifyOutput,
163
201
  path: `${basePath}/:ref/verify`,
@@ -165,7 +203,7 @@ var rowsFor = (definition, store, schema) => {
165
203
  verb: "query"
166
204
  },
167
205
  {
168
- call: (handle, params) => door.commit(handle, params),
206
+ call: via("commit"),
169
207
  input: schema.object({
170
208
  actor: import_schema.stringSchema,
171
209
  body: definition.body,
@@ -179,12 +217,8 @@ var rowsFor = (definition, store, schema) => {
179
217
  verb: "mutation"
180
218
  },
181
219
  {
182
- call: (handle, params) => door.retire(handle, params),
183
- input: schema.object({
184
- actor: import_schema.stringSchema,
185
- reason: import_schema.optional(import_schema.stringSchema),
186
- ref: import_schema.stringSchema
187
- }),
220
+ call: via("retire"),
221
+ input: actedInput,
188
222
  name: `${name}.retire`,
189
223
  output: retireLikeOutput,
190
224
  path: `${basePath}/:ref/retire`,
@@ -192,12 +226,8 @@ var rowsFor = (definition, store, schema) => {
192
226
  verb: "mutation"
193
227
  },
194
228
  {
195
- call: (handle, params) => door.reinstate(handle, params),
196
- input: schema.object({
197
- actor: import_schema.stringSchema,
198
- reason: import_schema.optional(import_schema.stringSchema),
199
- ref: import_schema.stringSchema
200
- }),
229
+ call: via("reinstate"),
230
+ input: actedInput,
201
231
  name: `${name}.reinstate`,
202
232
  output: retireLikeOutput,
203
233
  path: `${basePath}/:ref/reinstate`,
@@ -231,53 +261,53 @@ var rowsFor = (definition, store, schema) => {
231
261
  verb: "mutation"
232
262
  },
233
263
  {
234
- call: { pending: "T3", workflow: `${name}.create` },
235
- input: schema.object({ draft: definition.draft }),
264
+ call: (handle, params) => import_bindings.runInline(bound.workflows.create, params, bound.runFor(handle, params)),
265
+ input: schema.object({
266
+ body: definition.draft,
267
+ ref: import_schema.optional(import_schema.stringSchema),
268
+ templateId: import_schema.optional(import_schema.stringSchema)
269
+ }),
236
270
  name: `${name}.create`,
237
- output: commitOutput,
271
+ output: createdOutput,
238
272
  path: basePath,
239
273
  scope: "org",
240
274
  verb: "mutation"
241
275
  },
242
276
  {
243
- call: { pending: "T3", workflow: `${name}.send` },
244
- input: schema.object({ ref: import_schema.stringSchema }),
277
+ call: (handle, params) => import_bindings.startRun(bound.workflows.send, params, {
278
+ launcher: bound.launcher,
279
+ runtime: bound.runFor(handle, params)
280
+ }),
281
+ input: schema.object({
282
+ now: import_schema.numberSchema,
283
+ ref: import_schema.stringSchema,
284
+ to: import_schema.stringSchema,
285
+ ttlDays: import_schema.optional(import_schema.numberSchema)
286
+ }),
245
287
  name: `${name}.send`,
246
- output: ackOutput,
288
+ output: startedOutput,
247
289
  path: `${basePath}/:ref/send`,
248
290
  scope: "org",
249
291
  verb: "mutation"
250
292
  },
251
293
  {
252
- call: { pending: "T3", workflow: `${name}.duplicate` },
253
- input: schema.object({ ref: import_schema.stringSchema }),
294
+ call: (handle, params) => import_bindings.runInline(bound.workflows.duplicate, params, bound.runFor(handle, params)),
295
+ input: schema.object({ ref: import_schema.stringSchema, targetRef: import_schema.optional(import_schema.stringSchema) }),
254
296
  name: `${name}.duplicate`,
255
- output: commitOutput,
297
+ output: createdOutput,
256
298
  path: `${basePath}/:ref/duplicate`,
257
299
  scope: "org",
258
300
  verb: "mutation"
259
- },
260
- {
261
- call: { pending: "T3", workflow: `${name}.runStarted` },
262
- input: schema.object({ ref: import_schema.stringSchema }),
263
- name: `${name}.runStarted`,
264
- output: ackOutput,
265
- path: `${basePath}/:ref/run-started`,
266
- scope: "org",
267
- verb: "mutation"
268
301
  }
269
302
  ];
270
303
  };
271
304
  var documentSurface = (options) => {
272
- const { registry, schema, store } = options;
273
- const headsColumns = [...HEAD_COLUMNS, "entity", "number"];
305
+ const { registry, resolve, schema, store } = options;
306
+ const headsColumns = [...import_ddl.HEAD_FIELDS, "createdAt", "entity", "number", "updatedAt"];
274
307
  const headsInput = schema.object({
275
- columns: import_schema.arrayOf(schema.enum(headsColumns)),
308
+ columns: schema.union([import_schema.literalOf("all"), import_schema.arrayOf(schema.enum(headsColumns))]),
276
309
  entity: import_schema.optional(schema.union([import_schema.stringSchema, import_schema.arrayOf(import_schema.stringSchema)])),
277
- order: import_schema.arrayOf(schema.object({
278
- column: schema.enum([...SORT_COLUMNS, "entity"]),
279
- direction: import_schema.optional(schema.enum(["asc", "desc"]))
280
- })),
310
+ order: import_schema.arrayOf(orderTerm(schema, [...SORT_COLUMNS, "entity"])),
281
311
  where: import_schema.optional(import_schema.unknownSchema)
282
312
  });
283
313
  const aggregateInput = schema.object({
@@ -293,8 +323,41 @@ var documentSurface = (options) => {
293
323
  sum: import_schema.optional(import_schema.stringSchema)
294
324
  }));
295
325
  const sharedOutput = schema.union(registry.fold((entity) => schema.object({ entity: schema.enum([entity.name]), view: entity.view })));
326
+ const listEverywhereOutput = schema.object({
327
+ items: import_schema.arrayOf(schema.union(registry.fold((entity) => import_schema.merge([instanceSchemaFor(entity, schema), schema.object({ card: entity.card.schema })])))),
328
+ nextCursor: import_schema.nullable(import_schema.stringSchema)
329
+ });
296
330
  return [
297
- ...registry.fold((entity) => rowsFor(entity, store, schema)).flat(),
331
+ ...registry.names.flatMap((name) => rowsFor(registry.named(name), store, schema, {
332
+ launcher: options.launcher,
333
+ resolve,
334
+ runFor: options.runFor,
335
+ workflows: options.workflows[name]
336
+ })),
337
+ {
338
+ call: async (handle, params) => {
339
+ const page = await store.list(handle, params);
340
+ const names = await namesFor(resolve, page.items);
341
+ return {
342
+ items: page.items.map((item) => {
343
+ const definition = registry.entities[item.entity];
344
+ if (definition === undefined) {
345
+ throw new Error(`"${item.entity}" is no entity of this table's registry`);
346
+ }
347
+ return { ...item, card: cardOf(definition, item, names) };
348
+ }),
349
+ nextCursor: page.nextCursor
350
+ };
351
+ },
352
+ input: listInputFor(schema, [...SORT_COLUMNS, "entity"], {
353
+ entities: import_schema.optional(import_schema.arrayOf(import_schema.stringSchema))
354
+ }),
355
+ name: "documents.list",
356
+ output: listEverywhereOutput,
357
+ path: "/documents",
358
+ scope: "org",
359
+ verb: "query"
360
+ },
298
361
  {
299
362
  call: (handle, params) => store.heads(handle, params),
300
363
  input: headsInput,
@@ -314,7 +377,7 @@ var documentSurface = (options) => {
314
377
  verb: "query"
315
378
  },
316
379
  {
317
- call: { pending: "T3", workflow: "document.shared" },
380
+ call: (handle, params) => import_bindings.runInline(options.shared.workflow, params, options.shared.runFor(handle)),
318
381
  input: schema.object({ token: import_schema.stringSchema }),
319
382
  name: "shared",
320
383
  output: sharedOutput,
@@ -5,24 +5,13 @@ import { documentEntities, type AnyDocumentEntity } from '../core/entities.cjs';
5
5
  import { type SchemaAdapter } from '../core/schema.cjs';
6
6
  import { type DocumentStatusMachine } from '../core/status.cjs';
7
7
  import type { DocumentStore, DocumentStoreHandle } from '../store/store.cjs';
8
+ import { type DurableLauncher, type SurfaceWorkflows, type Workflow, type WorkflowRuntime } from '../workflows/bindings.cjs';
8
9
  export type SurfaceVerb = 'query' | 'mutation';
9
10
  export type SurfaceScope = 'org' | 'public' | 'token';
10
- /** The row's own declaration of what a workflow (not yet landed) will bind it to. */
11
- export type PendingCall = {
12
- pending: 'T3';
13
- workflow: string;
14
- };
15
- /**
16
- * A row as a caller calls it — the entity's own signature (D-065's `ref`, never `number`) with a
17
- * leading handle, the same convention `BoundQuery` already states in `@geonosis/workflows`, made
18
- * explicit here since a row is DATA before it is a function: reading `params.ref` off `never`
19
- * compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
20
- */
21
11
  export type SurfaceCall = (handle: never, params: never) => Promise<unknown>;
22
- /** The adapter as the surface first named it; the builders live in the core now. */
23
12
  export type SurfaceSchemaAdapter = SchemaAdapter;
24
13
  export type SurfaceRow = {
25
- call: PendingCall | SurfaceCall;
14
+ call: SurfaceCall;
26
15
  input: StandardSchemaV1;
27
16
  name: string;
28
17
  output: StandardSchemaV1;
@@ -30,11 +19,6 @@ export type SurfaceRow = {
30
19
  scope: SurfaceScope;
31
20
  verb: SurfaceVerb;
32
21
  };
33
- /**
34
- * What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
35
- * what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
36
- * caller never sees two overlapping bounds for the one registry it built.
37
- */
38
22
  type SurfaceDocumentEntity = AnyDocumentEntity & {
39
23
  basePath: string;
40
24
  bodyVersion?: number;
@@ -48,23 +32,31 @@ type SurfaceDocumentEntity = AnyDocumentEntity & {
48
32
  headOf: (body: never) => DocumentHead;
49
33
  migrations?: DocumentBodyMigrations<Record<string, unknown>>;
50
34
  prepare: (body: never) => unknown;
35
+ searchText: (body: never) => {
36
+ body: string;
37
+ };
51
38
  statusOf: (body: never) => string;
52
39
  statuses: DocumentStatusMachine<string>;
53
40
  withStatus: (body: never, status: string, at: string) => unknown;
54
41
  };
55
42
  type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
56
- export type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle> = {
43
+ export type SurfaceResolve = {
44
+ counterpartyName: (ids: readonly string[]) => Promise<ReadonlyMap<string, string>>;
45
+ };
46
+ export type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle, Ctx extends object = object> = {
47
+ launcher: DurableLauncher;
57
48
  registry: Registry<Map>;
49
+ resolve?: SurfaceResolve;
50
+ runFor: (handle: Handle, call: Readonly<Record<Key, string>>) => WorkflowRuntime<Ctx>;
58
51
  schema: SurfaceSchemaAdapter;
52
+ shared: {
53
+ runFor: (handle: Handle) => WorkflowRuntime<Ctx>;
54
+ workflow: Workflow<never, unknown, Ctx>;
55
+ };
59
56
  store: DocumentStore<Map, Key, Handle>;
57
+ workflows: {
58
+ [Name in keyof Map & string]: SurfaceWorkflows<Ctx>;
59
+ };
60
60
  };
61
- /**
62
- * `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
63
- * from — never authored by hand, and never a map a caller fills in per entity (#383). Reads and
64
- * `commit`/`retire`/`reinstate`/`setStatus` bind `call` to the store already composed; the saga
65
- * rows (`create`, `send`, `duplicate`, `run-started`) are declared with their own input/output and
66
- * a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
67
- * BY NAME, never with a stub answer.
68
- */
69
- export declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
61
+ export declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle, Ctx extends object = object>(options: DocumentSurfaceOptions<Map, Key, Handle, Ctx>) => SurfaceRow[];
70
62
  export {};
@@ -5,24 +5,13 @@ import { documentEntities, type AnyDocumentEntity } from '../core/entities.js';
5
5
  import { type SchemaAdapter } from '../core/schema.js';
6
6
  import { type DocumentStatusMachine } from '../core/status.js';
7
7
  import type { DocumentStore, DocumentStoreHandle } from '../store/store.js';
8
+ import { type DurableLauncher, type SurfaceWorkflows, type Workflow, type WorkflowRuntime } from '../workflows/bindings.js';
8
9
  export type SurfaceVerb = 'query' | 'mutation';
9
10
  export type SurfaceScope = 'org' | 'public' | 'token';
10
- /** The row's own declaration of what a workflow (not yet landed) will bind it to. */
11
- export type PendingCall = {
12
- pending: 'T3';
13
- workflow: string;
14
- };
15
- /**
16
- * A row as a caller calls it — the entity's own signature (D-065's `ref`, never `number`) with a
17
- * leading handle, the same convention `BoundQuery` already states in `@geonosis/workflows`, made
18
- * explicit here since a row is DATA before it is a function: reading `params.ref` off `never`
19
- * compiles (#325) but answers nothing, so a mounting adapter narrows before it reads.
20
- */
21
11
  export type SurfaceCall = (handle: never, params: never) => Promise<unknown>;
22
- /** The adapter as the surface first named it; the builders live in the core now. */
23
12
  export type SurfaceSchemaAdapter = SchemaAdapter;
24
13
  export type SurfaceRow = {
25
- call: PendingCall | SurfaceCall;
14
+ call: SurfaceCall;
26
15
  input: StandardSchemaV1;
27
16
  name: string;
28
17
  output: StandardSchemaV1;
@@ -30,11 +19,6 @@ export type SurfaceRow = {
30
19
  scope: SurfaceScope;
31
20
  verb: SurfaceVerb;
32
21
  };
33
- /**
34
- * What the table needs off an entity beyond `documentEntities`'s own minimal bound — plus exactly
35
- * what `documentStore`'s own `StorableDocumentEntity` needs, so `Map` satisfies both at once and a
36
- * caller never sees two overlapping bounds for the one registry it built.
37
- */
38
22
  type SurfaceDocumentEntity = AnyDocumentEntity & {
39
23
  basePath: string;
40
24
  bodyVersion?: number;
@@ -48,23 +32,31 @@ type SurfaceDocumentEntity = AnyDocumentEntity & {
48
32
  headOf: (body: never) => DocumentHead;
49
33
  migrations?: DocumentBodyMigrations<Record<string, unknown>>;
50
34
  prepare: (body: never) => unknown;
35
+ searchText: (body: never) => {
36
+ body: string;
37
+ };
51
38
  statusOf: (body: never) => string;
52
39
  statuses: DocumentStatusMachine<string>;
53
40
  withStatus: (body: never, status: string, at: string) => unknown;
54
41
  };
55
42
  type Registry<Map extends Readonly<Record<string, SurfaceDocumentEntity>>> = ReturnType<typeof documentEntities<Map>>;
56
- export type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle> = {
43
+ export type SurfaceResolve = {
44
+ counterpartyName: (ids: readonly string[]) => Promise<ReadonlyMap<string, string>>;
45
+ };
46
+ export type DocumentSurfaceOptions<Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle, Ctx extends object = object> = {
47
+ launcher: DurableLauncher;
57
48
  registry: Registry<Map>;
49
+ resolve?: SurfaceResolve;
50
+ runFor: (handle: Handle, call: Readonly<Record<Key, string>>) => WorkflowRuntime<Ctx>;
58
51
  schema: SurfaceSchemaAdapter;
52
+ shared: {
53
+ runFor: (handle: Handle) => WorkflowRuntime<Ctx>;
54
+ workflow: Workflow<never, unknown, Ctx>;
55
+ };
59
56
  store: DocumentStore<Map, Key, Handle>;
57
+ workflows: {
58
+ [Name in keyof Map & string]: SurfaceWorkflows<Ctx>;
59
+ };
60
60
  };
61
- /**
62
- * `documentSurface({ registry, store, schema })`: the table every tRPC/REST/MCP mount is derived
63
- * from — never authored by hand, and never a map a caller fills in per entity (#383). Reads and
64
- * `commit`/`retire`/`reinstate`/`setStatus` bind `call` to the store already composed; the saga
65
- * rows (`create`, `send`, `duplicate`, `run-started`) are declared with their own input/output and
66
- * a `{ pending: 'T3', workflow }` in place of `call` — an adapter mounting the table refuses those
67
- * BY NAME, never with a stub answer.
68
- */
69
- export declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle>(options: DocumentSurfaceOptions<Map, Key, Handle>) => SurfaceRow[];
61
+ export declare const documentSurface: <Map extends Readonly<Record<string, SurfaceDocumentEntity>>, Key extends string, Handle extends DocumentStoreHandle = DocumentStoreHandle, Ctx extends object = object>(options: DocumentSurfaceOptions<Map, Key, Handle, Ctx>) => SurfaceRow[];
70
62
  export {};