@geonosis/document 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +61 -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
@@ -12,6 +12,11 @@ import {
12
12
  unknownSchema
13
13
  } from "../core/schema.js";
14
14
  import { canTransition } from "../core/status.js";
15
+ import { HEAD_FIELDS, REVISION_KINDS } from "../store/ddl.js";
16
+ import {
17
+ runInline,
18
+ startRun
19
+ } from "../workflows/bindings.js";
15
20
  var doorFor = (store, name) => {
16
21
  const door = store[name];
17
22
  if (door === undefined) {
@@ -19,20 +24,56 @@ var doorFor = (store, name) => {
19
24
  }
20
25
  return door;
21
26
  };
22
- var HEAD_COLUMNS = Object.keys(Document.headFields);
23
- var SORT_COLUMNS = [...HEAD_COLUMNS, "number", "createdAt", "updatedAt"];
24
- var rowsFor = (definition, store, schema) => {
27
+ var SORT_COLUMNS = [...HEAD_FIELDS, "number", "createdAt", "updatedAt"];
28
+ var orderTerm = (schema, columns) => schema.object({
29
+ column: schema.enum(columns),
30
+ direction: optional(schema.enum(["asc", "desc"]))
31
+ });
32
+ var listInputFor = (schema, orderColumns, extra = {}) => schema.object({
33
+ cursor: optional(nullable(stringSchema)),
34
+ ...extra,
35
+ filter: optional(schema.object(Object.fromEntries(HEAD_FIELDS.map((column) => [column, optional(stringSchema)])))),
36
+ limit: optional(numberSchema),
37
+ order: optional(orderTerm(schema, orderColumns))
38
+ });
39
+ var instanceSchemaFor = (definition, schema) => merge([
40
+ Document.head,
41
+ Document.record,
42
+ schema.object({
43
+ body: definition.view,
44
+ entity: schema.enum([definition.name]),
45
+ number: stringSchema
46
+ })
47
+ ]);
48
+ var NO_NAMES = new Map;
49
+ var namesFor = async (resolve, items) => {
50
+ const ids = [
51
+ ...new Set(items.flatMap((item) => item.counterparty === null ? [] : [item.counterparty]))
52
+ ];
53
+ if (resolve === undefined || ids.length === 0)
54
+ return NO_NAMES;
55
+ return resolve.counterpartyName(ids);
56
+ };
57
+ var cardOf = (definition, item, names) => definition.card.of(item, {
58
+ counterpartyName: item.counterparty === null ? "" : names.get(item.counterparty) ?? ""
59
+ });
60
+ var rowsFor = (definition, store, schema, bound) => {
25
61
  const { name } = definition;
26
62
  const door = doorFor(store, name);
27
63
  const basePath = `/${definition.basePath}`;
28
- const instanceSchema = merge([
29
- Document.head,
30
- Document.record,
31
- schema.object({ body: definition.view, entity: schema.enum([name]), number: stringSchema })
32
- ]);
64
+ const instanceSchema = instanceSchemaFor(definition, schema);
65
+ const head = Document.head;
66
+ const createdOutput = schema.object({
67
+ body: definition.body,
68
+ entity: schema.enum([name]),
69
+ minted: nullable(schema.object({ sequence: numberSchema })),
70
+ number: stringSchema
71
+ });
72
+ const startedOutput = schema.object({ deduplicated: booleanSchema, runId: stringSchema });
33
73
  const commitOutput = schema.union([
34
74
  schema.object({
35
75
  committed: literalOf(false),
76
+ head,
36
77
  lineage: numberSchema,
37
78
  ref: stringSchema,
38
79
  version: numberSchema
@@ -41,6 +82,7 @@ var rowsFor = (definition, store, schema) => {
41
82
  archived: optional(booleanSchema),
42
83
  committed: literalOf(true),
43
84
  hash: stringSchema,
85
+ head,
44
86
  lineage: numberSchema,
45
87
  previous: nullable(schema.object({ hash: stringSchema, version: numberSchema })),
46
88
  ref: stringSchema,
@@ -49,6 +91,7 @@ var rowsFor = (definition, store, schema) => {
49
91
  ]);
50
92
  const retireLikeOutput = schema.object({
51
93
  hash: stringSchema,
94
+ head,
52
95
  lineage: numberSchema,
53
96
  ref: stringSchema,
54
97
  version: numberSchema
@@ -67,27 +110,24 @@ var rowsFor = (definition, store, schema) => {
67
110
  at: numberSchema,
68
111
  body: unknownSchema,
69
112
  hash: stringSchema,
70
- kind: schema.enum(["committed", "retired", "reinstated"]),
113
+ kind: schema.enum(REVISION_KINDS),
71
114
  reason: nullable(stringSchema),
72
115
  version: numberSchema
73
116
  }));
74
- const listInput = schema.object({
75
- cursor: optional(nullable(stringSchema)),
76
- filter: optional(schema.object(Object.fromEntries(HEAD_COLUMNS.map((column) => [column, optional(stringSchema)])))),
77
- limit: optional(numberSchema),
78
- order: optional(schema.object({
79
- column: schema.enum(SORT_COLUMNS),
80
- direction: optional(schema.enum(["asc", "desc"]))
81
- }))
82
- });
83
117
  const listOutput = schema.object({
84
118
  items: arrayOf(merge([instanceSchema, schema.object({ card: definition.card.schema })])),
85
119
  nextCursor: nullable(stringSchema)
86
120
  });
87
- const ackOutput = schema.object({ ref: stringSchema });
121
+ const streamInput = schema.object({ lineage: optional(numberSchema), ref: stringSchema });
122
+ const actedInput = schema.object({
123
+ actor: stringSchema,
124
+ reason: optional(stringSchema),
125
+ ref: stringSchema
126
+ });
127
+ const via = (verb) => (handle, params) => door[verb](handle, params);
88
128
  return [
89
129
  {
90
- call: (handle, params) => door.get(handle, params),
130
+ call: via("get"),
91
131
  input: schema.object({ ref: stringSchema }),
92
132
  name: `${name}.get`,
93
133
  output: nullable(instanceSchema),
@@ -98,15 +138,16 @@ var rowsFor = (definition, store, schema) => {
98
138
  {
99
139
  call: async (handle, params) => {
100
140
  const page = await door.list(handle, params);
141
+ const names = await namesFor(bound.resolve, page.items);
101
142
  return {
102
143
  items: page.items.map((item) => ({
103
144
  ...item,
104
- card: definition.card.of(item, { counterpartyName: "" })
145
+ card: cardOf(definition, item, names)
105
146
  })),
106
147
  nextCursor: page.nextCursor
107
148
  };
108
149
  },
109
- input: listInput,
150
+ input: listInputFor(schema, SORT_COLUMNS),
110
151
  name: `${name}.list`,
111
152
  output: listOutput,
112
153
  path: basePath,
@@ -114,8 +155,8 @@ var rowsFor = (definition, store, schema) => {
114
155
  verb: "query"
115
156
  },
116
157
  {
117
- call: (handle, params) => door.history(handle, params),
118
- input: schema.object({ lineage: optional(numberSchema), ref: stringSchema }),
158
+ call: via("history"),
159
+ input: streamInput,
119
160
  name: `${name}.history`,
120
161
  output: historyOutput,
121
162
  path: `${basePath}/:ref/history`,
@@ -123,8 +164,8 @@ var rowsFor = (definition, store, schema) => {
123
164
  verb: "query"
124
165
  },
125
166
  {
126
- call: (handle, params) => door.verify(handle, params),
127
- input: schema.object({ lineage: optional(numberSchema), ref: stringSchema }),
167
+ call: via("verify"),
168
+ input: streamInput,
128
169
  name: `${name}.verify`,
129
170
  output: verifyOutput,
130
171
  path: `${basePath}/:ref/verify`,
@@ -132,7 +173,7 @@ var rowsFor = (definition, store, schema) => {
132
173
  verb: "query"
133
174
  },
134
175
  {
135
- call: (handle, params) => door.commit(handle, params),
176
+ call: via("commit"),
136
177
  input: schema.object({
137
178
  actor: stringSchema,
138
179
  body: definition.body,
@@ -146,12 +187,8 @@ var rowsFor = (definition, store, schema) => {
146
187
  verb: "mutation"
147
188
  },
148
189
  {
149
- call: (handle, params) => door.retire(handle, params),
150
- input: schema.object({
151
- actor: stringSchema,
152
- reason: optional(stringSchema),
153
- ref: stringSchema
154
- }),
190
+ call: via("retire"),
191
+ input: actedInput,
155
192
  name: `${name}.retire`,
156
193
  output: retireLikeOutput,
157
194
  path: `${basePath}/:ref/retire`,
@@ -159,12 +196,8 @@ var rowsFor = (definition, store, schema) => {
159
196
  verb: "mutation"
160
197
  },
161
198
  {
162
- call: (handle, params) => door.reinstate(handle, params),
163
- input: schema.object({
164
- actor: stringSchema,
165
- reason: optional(stringSchema),
166
- ref: stringSchema
167
- }),
199
+ call: via("reinstate"),
200
+ input: actedInput,
168
201
  name: `${name}.reinstate`,
169
202
  output: retireLikeOutput,
170
203
  path: `${basePath}/:ref/reinstate`,
@@ -198,53 +231,53 @@ var rowsFor = (definition, store, schema) => {
198
231
  verb: "mutation"
199
232
  },
200
233
  {
201
- call: { pending: "T3", workflow: `${name}.create` },
202
- input: schema.object({ draft: definition.draft }),
234
+ call: (handle, params) => runInline(bound.workflows.create, params, bound.runFor(handle, params)),
235
+ input: schema.object({
236
+ body: definition.draft,
237
+ ref: optional(stringSchema),
238
+ templateId: optional(stringSchema)
239
+ }),
203
240
  name: `${name}.create`,
204
- output: commitOutput,
241
+ output: createdOutput,
205
242
  path: basePath,
206
243
  scope: "org",
207
244
  verb: "mutation"
208
245
  },
209
246
  {
210
- call: { pending: "T3", workflow: `${name}.send` },
211
- input: schema.object({ ref: stringSchema }),
247
+ call: (handle, params) => startRun(bound.workflows.send, params, {
248
+ launcher: bound.launcher,
249
+ runtime: bound.runFor(handle, params)
250
+ }),
251
+ input: schema.object({
252
+ now: numberSchema,
253
+ ref: stringSchema,
254
+ to: stringSchema,
255
+ ttlDays: optional(numberSchema)
256
+ }),
212
257
  name: `${name}.send`,
213
- output: ackOutput,
258
+ output: startedOutput,
214
259
  path: `${basePath}/:ref/send`,
215
260
  scope: "org",
216
261
  verb: "mutation"
217
262
  },
218
263
  {
219
- call: { pending: "T3", workflow: `${name}.duplicate` },
220
- input: schema.object({ ref: stringSchema }),
264
+ call: (handle, params) => runInline(bound.workflows.duplicate, params, bound.runFor(handle, params)),
265
+ input: schema.object({ ref: stringSchema, targetRef: optional(stringSchema) }),
221
266
  name: `${name}.duplicate`,
222
- output: commitOutput,
267
+ output: createdOutput,
223
268
  path: `${basePath}/:ref/duplicate`,
224
269
  scope: "org",
225
270
  verb: "mutation"
226
- },
227
- {
228
- call: { pending: "T3", workflow: `${name}.runStarted` },
229
- input: schema.object({ ref: stringSchema }),
230
- name: `${name}.runStarted`,
231
- output: ackOutput,
232
- path: `${basePath}/:ref/run-started`,
233
- scope: "org",
234
- verb: "mutation"
235
271
  }
236
272
  ];
237
273
  };
238
274
  var documentSurface = (options) => {
239
- const { registry, schema, store } = options;
240
- const headsColumns = [...HEAD_COLUMNS, "entity", "number"];
275
+ const { registry, resolve, schema, store } = options;
276
+ const headsColumns = [...HEAD_FIELDS, "createdAt", "entity", "number", "updatedAt"];
241
277
  const headsInput = schema.object({
242
- columns: arrayOf(schema.enum(headsColumns)),
278
+ columns: schema.union([literalOf("all"), arrayOf(schema.enum(headsColumns))]),
243
279
  entity: optional(schema.union([stringSchema, arrayOf(stringSchema)])),
244
- order: arrayOf(schema.object({
245
- column: schema.enum([...SORT_COLUMNS, "entity"]),
246
- direction: optional(schema.enum(["asc", "desc"]))
247
- })),
280
+ order: arrayOf(orderTerm(schema, [...SORT_COLUMNS, "entity"])),
248
281
  where: optional(unknownSchema)
249
282
  });
250
283
  const aggregateInput = schema.object({
@@ -260,8 +293,41 @@ var documentSurface = (options) => {
260
293
  sum: optional(stringSchema)
261
294
  }));
262
295
  const sharedOutput = schema.union(registry.fold((entity) => schema.object({ entity: schema.enum([entity.name]), view: entity.view })));
296
+ const listEverywhereOutput = schema.object({
297
+ items: arrayOf(schema.union(registry.fold((entity) => merge([instanceSchemaFor(entity, schema), schema.object({ card: entity.card.schema })])))),
298
+ nextCursor: nullable(stringSchema)
299
+ });
263
300
  return [
264
- ...registry.fold((entity) => rowsFor(entity, store, schema)).flat(),
301
+ ...registry.names.flatMap((name) => rowsFor(registry.named(name), store, schema, {
302
+ launcher: options.launcher,
303
+ resolve,
304
+ runFor: options.runFor,
305
+ workflows: options.workflows[name]
306
+ })),
307
+ {
308
+ call: async (handle, params) => {
309
+ const page = await store.list(handle, params);
310
+ const names = await namesFor(resolve, page.items);
311
+ return {
312
+ items: page.items.map((item) => {
313
+ const definition = registry.entities[item.entity];
314
+ if (definition === undefined) {
315
+ throw new Error(`"${item.entity}" is no entity of this table's registry`);
316
+ }
317
+ return { ...item, card: cardOf(definition, item, names) };
318
+ }),
319
+ nextCursor: page.nextCursor
320
+ };
321
+ },
322
+ input: listInputFor(schema, [...SORT_COLUMNS, "entity"], {
323
+ entities: optional(arrayOf(stringSchema))
324
+ }),
325
+ name: "documents.list",
326
+ output: listEverywhereOutput,
327
+ path: "/documents",
328
+ scope: "org",
329
+ verb: "query"
330
+ },
265
331
  {
266
332
  call: (handle, params) => store.heads(handle, params),
267
333
  input: headsInput,
@@ -281,7 +347,7 @@ var documentSurface = (options) => {
281
347
  verb: "query"
282
348
  },
283
349
  {
284
- call: { pending: "T3", workflow: "document.shared" },
350
+ call: (handle, params) => runInline(options.shared.workflow, params, options.shared.runFor(handle)),
285
351
  input: schema.object({ token: stringSchema }),
286
352
  name: "shared",
287
353
  output: sharedOutput,
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ function __accessProp(key) {
6
+ return this[key];
7
+ }
8
+ var __toCommonJS = (from) => {
9
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
10
+ if (entry)
11
+ return entry;
12
+ entry = __defProp({}, "__esModule", { value: true });
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (var key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(entry, key))
16
+ __defProp(entry, key, {
17
+ get: __accessProp.bind(from, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ __moduleCache.set(from, entry);
22
+ return entry;
23
+ };
24
+ var __moduleCache;
25
+ var __returnValue = (v) => v;
26
+ function __exportSetter(name, newValue) {
27
+ this[name] = __returnValue.bind(null, newValue);
28
+ }
29
+ var __export = (target, all) => {
30
+ for (var name in all)
31
+ __defProp(target, name, {
32
+ get: all[name],
33
+ enumerable: true,
34
+ configurable: true,
35
+ set: __exportSetter.bind(all, name)
36
+ });
37
+ };
38
+
39
+ // src/workflows/bindings.ts
40
+ var exports_bindings = {};
41
+ __export(exports_bindings, {
42
+ runInline: () => runInline,
43
+ startRun: () => startRun
44
+ });
45
+ module.exports = __toCommonJS(exports_bindings);
46
+ var import_workflows = require("@geonosis/workflows");
47
+ var runInline = async (workflow, input, runtime) => (await workflow.run({ input, runtime })).result;
48
+ var startRun = (workflow, input, on) => import_workflows.startDurable({ input, launcher: on.launcher, runtime: on.runtime, workflow });
@@ -0,0 +1,15 @@
1
+ import { type DurableLauncher, type Workflow, type WorkflowRuntime } from '@geonosis/workflows';
2
+ export type { DurableLauncher, Workflow, WorkflowRuntime };
3
+ export type SurfaceWorkflows<Ctx extends object> = {
4
+ create: Workflow<never, unknown, Ctx>;
5
+ duplicate: Workflow<never, unknown, Ctx>;
6
+ send: Workflow<never, unknown, Ctx>;
7
+ };
8
+ export declare const runInline: <Input, Output, Ctx extends object>(workflow: Workflow<Input, Output, Ctx>, input: Input, runtime: WorkflowRuntime<Ctx>) => Promise<Output>;
9
+ export declare const startRun: <Input, Output, Ctx extends object>(workflow: Workflow<Input, Output, Ctx>, input: Input, on: {
10
+ launcher: DurableLauncher;
11
+ runtime: WorkflowRuntime<Ctx>;
12
+ }) => Promise<{
13
+ deduplicated: boolean;
14
+ runId: string;
15
+ }>;
@@ -0,0 +1,15 @@
1
+ import { type DurableLauncher, type Workflow, type WorkflowRuntime } from '@geonosis/workflows';
2
+ export type { DurableLauncher, Workflow, WorkflowRuntime };
3
+ export type SurfaceWorkflows<Ctx extends object> = {
4
+ create: Workflow<never, unknown, Ctx>;
5
+ duplicate: Workflow<never, unknown, Ctx>;
6
+ send: Workflow<never, unknown, Ctx>;
7
+ };
8
+ export declare const runInline: <Input, Output, Ctx extends object>(workflow: Workflow<Input, Output, Ctx>, input: Input, runtime: WorkflowRuntime<Ctx>) => Promise<Output>;
9
+ export declare const startRun: <Input, Output, Ctx extends object>(workflow: Workflow<Input, Output, Ctx>, input: Input, on: {
10
+ launcher: DurableLauncher;
11
+ runtime: WorkflowRuntime<Ctx>;
12
+ }) => Promise<{
13
+ deduplicated: boolean;
14
+ runId: string;
15
+ }>;
@@ -0,0 +1,10 @@
1
+ // src/workflows/bindings.ts
2
+ import {
3
+ startDurable
4
+ } from "@geonosis/workflows";
5
+ var runInline = async (workflow, input, runtime) => (await workflow.run({ input, runtime })).result;
6
+ var startRun = (workflow, input, on) => startDurable({ input, launcher: on.launcher, runtime: on.runtime, workflow });
7
+ export {
8
+ runInline,
9
+ startRun
10
+ };
@@ -62,7 +62,8 @@ var defaultActor = (ctx, workflowName) => {
62
62
  };
63
63
  var documentWorkflows = (entity, options) => {
64
64
  const { effects, ports } = options;
65
- const name = entity.name;
65
+ const entityName = entity.name;
66
+ const name = entityName;
66
67
  const article = withArticle(entity.noun);
67
68
  const noun = capitalised(entity.noun);
68
69
  const actorOf = ports.actor ?? defaultActor;
@@ -89,10 +90,10 @@ var documentWorkflows = (entity, options) => {
89
90
  return written;
90
91
  };
91
92
  const stored = async (ctx, at) => {
92
- const found = await ports.door(ctx, name).get({ ref: at.ref });
93
+ const found = await ports.door(ctx, entityName).get({ ref: at.ref });
93
94
  if (!found) {
94
95
  throw new import_refusals.DocumentNotFound({
95
- entity: name,
96
+ entity: entityName,
96
97
  message: `no ${entity.noun} is stored as ${at.ref}`,
97
98
  ref: at.ref
98
99
  });
@@ -100,7 +101,7 @@ var documentWorkflows = (entity, options) => {
100
101
  return found;
101
102
  };
102
103
  const refuseTaken = async (ctx, at) => {
103
- const owner = at.entity ?? name;
104
+ const owner = at.entity ?? entityName;
104
105
  if (await ports.door(ctx, owner).get({ ref: at.ref })) {
105
106
  throw new import_refusals.DocumentTaken({
106
107
  entity: owner,
@@ -114,7 +115,7 @@ var documentWorkflows = (entity, options) => {
114
115
  if (numbering.mode === "given") {
115
116
  if (given === undefined) {
116
117
  throw new import_refusals.NumberingRefused({
117
- entity: name,
118
+ entity: entityName,
118
119
  message: `${article} is numbered by whoever creates it`,
119
120
  mode: "given"
120
121
  });
@@ -124,14 +125,14 @@ var documentWorkflows = (entity, options) => {
124
125
  }
125
126
  if (given !== undefined) {
126
127
  throw new import_refusals.NumberingRefused({
127
- entity: name,
128
+ entity: entityName,
128
129
  message: `${article} is numbered by the organisation`,
129
130
  mode: "counter"
130
131
  });
131
132
  }
132
133
  if (ports.counter === undefined) {
133
134
  throw new import_refusals.NumberingRefused({
134
- entity: name,
135
+ entity: entityName,
135
136
  message: `${article} is numbered from a counter and this host declares no counter port`,
136
137
  mode: "counter"
137
138
  });
@@ -140,18 +141,24 @@ var documentWorkflows = (entity, options) => {
140
141
  const { number: sequence } = await ports.counter(ctx, numbering.counter);
141
142
  return { ref: numbering.format(series, sequence), minted: { sequence } };
142
143
  };
143
- const shareLink = import_workflows.createStep({ name: "create-share-link", noCompensation: true }, (input, ctx) => ports.link(ctx, { entity: name, ...input }));
144
+ const shareLink = import_workflows.createStep({ name: "create-share-link", noCompensation: true }, (input, ctx) => ports.link(ctx, { entity: entityName, ...input }));
144
145
  const sendMail = import_workflows.createStep({ name: "send-email", noCompensation: true }, async (input, ctx) => {
145
146
  const sent = await ports.mail(ctx, input);
146
147
  if (sent.isErr())
147
148
  throw sent.error;
148
149
  return { to: input.to };
149
150
  });
151
+ const linkFor = (input) => shareLink({
152
+ ref: input.ref,
153
+ now: input.now,
154
+ ...input.ttlDays === undefined ? {} : { ttlDays: input.ttlDays }
155
+ });
156
+ const linkShape = { now: import_schema.positiveInt, ref: import_schema.nonEmptyString, ttlDays: import_schema.optional(import_schema.positiveInt) };
150
157
  const createName = `${name}.create`;
151
158
  const create = import_workflows.createWorkflow(createName, async (input, ctx) => {
152
159
  await guard(ctx);
153
160
  const draft = await import_schema.validate(entity.draft, await seed(ctx, {
154
- entity: name,
161
+ entity: entityName,
155
162
  templateId: input.templateId,
156
163
  input: input.body
157
164
  }));
@@ -182,7 +189,7 @@ var documentWorkflows = (entity, options) => {
182
189
  const from = entity.statusOf(current.body);
183
190
  if (!import_status.canTransition(entity.statuses, from, input.to)) {
184
191
  throw new import_refusals.TransitionRefused({
185
- entity: name,
192
+ entity: entityName,
186
193
  from,
187
194
  message: `${article} cannot go from ${from} to ${input.to}`,
188
195
  ref: input.ref,
@@ -204,20 +211,15 @@ var documentWorkflows = (entity, options) => {
204
211
  const remove = import_workflows.createWorkflow(deleteName, async (input, ctx) => {
205
212
  if (!entity.removable) {
206
213
  throw new import_refusals.DocumentNotRemovable({
207
- entity: name,
214
+ entity: entityName,
208
215
  message: `deleting is not something ${article} does`
209
216
  });
210
217
  }
211
- const door = ports.door(ctx, name);
212
- const found = await door.get({ ref: input.ref });
213
- if (!found) {
214
- throw new import_refusals.DocumentNotFound({
215
- entity: name,
216
- message: `no ${entity.noun} is stored as ${input.ref}`,
217
- ref: input.ref
218
- });
219
- }
220
- await door.retire({ actor: actorOf(ctx, deleteName), ref: input.ref });
218
+ await stored(ctx, input);
219
+ await ports.door(ctx, entityName).retire({
220
+ actor: actorOf(ctx, deleteName),
221
+ ref: input.ref
222
+ });
221
223
  return { number: input.ref };
222
224
  }, {
223
225
  announce: (removed) => announce({ kind: "deleted", number: removed.number }),
@@ -226,11 +228,7 @@ var documentWorkflows = (entity, options) => {
226
228
  const sendName = `${name}.send`;
227
229
  const send = import_workflows.createWorkflow(sendName, async (input, ctx) => {
228
230
  const current = await stored(ctx, input);
229
- const link = await shareLink({
230
- ref: input.ref,
231
- now: input.now,
232
- ...input.ttlDays === undefined ? {} : { ttlDays: input.ttlDays }
233
- });
231
+ const link = await linkFor(input);
234
232
  const marked = entity.onSent(current.body);
235
233
  const written = marked === current.body ? { entity: name, number: input.ref, body: current.body } : await write(ctx, { entity: name, number: input.ref, body: marked }, sendName);
236
234
  const words = mailWords(input.ref);
@@ -244,19 +242,14 @@ var documentWorkflows = (entity, options) => {
244
242
  announce: ({ to, url, expiresAt, ...written }) => announce({ kind: "sent", written, to, url, expiresAt }),
245
243
  execution: "durable",
246
244
  idempotent: (input) => `${sendName}:${input.ref}:${input.to}`,
247
- input: typed(import_schema.objectOf({
248
- now: import_schema.positiveInt,
249
- ref: import_schema.nonEmptyString,
250
- to: import_schema.nonEmptyString,
251
- ttlDays: import_schema.optional(import_schema.positiveInt)
252
- }))
245
+ input: typed(import_schema.objectOf({ ...linkShape, to: import_schema.nonEmptyString }))
253
246
  });
254
247
  const convertName = `${name}.convert`;
255
248
  const convert = import_workflows.createWorkflow(convertName, async (input, ctx) => {
256
249
  const conversion = effects.conversion;
257
250
  if (conversion === undefined) {
258
251
  throw new import_refusals.ConversionRefused({
259
- entity: name,
252
+ entity: entityName,
260
253
  message: `converting is not something ${article} does`,
261
254
  ref: input.ref
262
255
  });
@@ -265,7 +258,7 @@ var documentWorkflows = (entity, options) => {
265
258
  const refusal = conversion.refuse(source.body);
266
259
  if (refusal !== null) {
267
260
  throw new import_refusals.ConversionRefused({
268
- entity: name,
261
+ entity: entityName,
269
262
  message: `${input.ref} ${refusal}`,
270
263
  ref: input.ref
271
264
  });
@@ -300,15 +293,11 @@ var documentWorkflows = (entity, options) => {
300
293
  });
301
294
  const share = import_workflows.createWorkflow(`${name}.share`, async (input, ctx) => {
302
295
  await stored(ctx, input);
303
- const link = await shareLink({
304
- ref: input.ref,
305
- now: input.now,
306
- ...input.ttlDays === undefined ? {} : { ttlDays: input.ttlDays }
307
- });
296
+ const link = await linkFor(input);
308
297
  return { number: input.ref, token: link.token, url: link.url, expiresAt: link.expiresAt };
309
298
  }, {
310
299
  announce: (link) => announce({ kind: "shared", number: link.number, url: link.url, expiresAt: link.expiresAt }),
311
- input: typed(import_schema.objectOf({ now: import_schema.positiveInt, ref: import_schema.nonEmptyString, ttlDays: import_schema.optional(import_schema.positiveInt) }))
300
+ input: typed(import_schema.objectOf(linkShape))
312
301
  });
313
302
  return { entity, create, save, setStatus, remove, send, convert, duplicate, share };
314
303
  };
@@ -5,12 +5,6 @@ import type { DocumentNumbering } from '../core/numbering.cjs';
5
5
  import { type DocumentStatusMachine } from '../core/status.cjs';
6
6
  import type { DocumentEffects, Written } from './effects.cjs';
7
7
  import type { DocumentWorkflowPorts } from './ports.cjs';
8
- /**
9
- * What the body needs off an entity: the registry's minimal bound plus the facts and pure
10
- * decisions every workflow is written over — the shape `Document.extend` returns, never a second
11
- * one. `never` parameters are the same device the surface uses: a definition typed to its own
12
- * body still fits, and the factory writes what that definition decided.
13
- */
14
8
  export type WorkflowDocumentEntity = AnyDocumentEntity & {
15
9
  noun: string;
16
10
  draft: StandardSchemaV1;
@@ -33,12 +27,6 @@ export type DocumentWorkflowOptions<E, Ctx> = {
33
27
  type Minted = {
34
28
  sequence: number;
35
29
  } | null;
36
- /**
37
- * `documentWorkflows(entity, { effects, ports })`: the whole of what a Document can do, minted
38
- * once per entity that extends it. The workflows are named for the entity (`invoice.create`,
39
- * `purchase-order.send`), their inputs are the entity's own schemas, and their bodies are written
40
- * here exactly once — a workflow named for one entity anywhere else is the fork this replaces.
41
- */
42
30
  export declare const documentWorkflows: <E extends WorkflowDocumentEntity, Ctx extends object>(entity: E, options: DocumentWorkflowOptions<E, Ctx>) => {
43
31
  entity: E;
44
32
  create: import("@geonosis/workflows").Workflow<{
@@ -5,12 +5,6 @@ import type { DocumentNumbering } from '../core/numbering.js';
5
5
  import { type DocumentStatusMachine } from '../core/status.js';
6
6
  import type { DocumentEffects, Written } from './effects.js';
7
7
  import type { DocumentWorkflowPorts } from './ports.js';
8
- /**
9
- * What the body needs off an entity: the registry's minimal bound plus the facts and pure
10
- * decisions every workflow is written over — the shape `Document.extend` returns, never a second
11
- * one. `never` parameters are the same device the surface uses: a definition typed to its own
12
- * body still fits, and the factory writes what that definition decided.
13
- */
14
8
  export type WorkflowDocumentEntity = AnyDocumentEntity & {
15
9
  noun: string;
16
10
  draft: StandardSchemaV1;
@@ -33,12 +27,6 @@ export type DocumentWorkflowOptions<E, Ctx> = {
33
27
  type Minted = {
34
28
  sequence: number;
35
29
  } | null;
36
- /**
37
- * `documentWorkflows(entity, { effects, ports })`: the whole of what a Document can do, minted
38
- * once per entity that extends it. The workflows are named for the entity (`invoice.create`,
39
- * `purchase-order.send`), their inputs are the entity's own schemas, and their bodies are written
40
- * here exactly once — a workflow named for one entity anywhere else is the fork this replaces.
41
- */
42
30
  export declare const documentWorkflows: <E extends WorkflowDocumentEntity, Ctx extends object>(entity: E, options: DocumentWorkflowOptions<E, Ctx>) => {
43
31
  entity: E;
44
32
  create: import("@geonosis/workflows").Workflow<{