@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.
- package/CHANGELOG.md +16 -0
- package/dist/core/actor.cjs +48 -0
- package/dist/core/actor.d.cts +3 -0
- package/dist/core/actor.d.ts +3 -0
- package/dist/core/actor.js +8 -0
- package/dist/core/body-version.cjs +75 -0
- package/dist/core/body-version.d.cts +25 -0
- package/dist/core/body-version.d.ts +25 -0
- package/dist/core/body-version.js +35 -0
- package/dist/core/canonical.cjs +55 -0
- package/dist/core/canonical.d.cts +5 -0
- package/dist/core/canonical.d.ts +5 -0
- package/dist/core/canonical.js +15 -0
- package/dist/core/document.cjs +136 -0
- package/dist/core/document.d.cts +137 -0
- package/dist/core/document.d.ts +137 -0
- package/dist/core/document.js +96 -0
- package/dist/core/entities.cjs +68 -0
- package/dist/core/entities.d.cts +42 -0
- package/dist/core/entities.d.ts +42 -0
- package/dist/core/entities.js +28 -0
- package/dist/core/naming.cjs +56 -0
- package/dist/core/naming.d.cts +17 -0
- package/dist/core/naming.d.ts +17 -0
- package/dist/core/naming.js +16 -0
- package/dist/core/numbering.cjs +41 -0
- package/dist/core/numbering.d.cts +12 -0
- package/dist/core/numbering.d.ts +12 -0
- package/dist/core/numbering.js +0 -0
- package/dist/core/ports.cjs +41 -0
- package/dist/core/ports.d.cts +29 -0
- package/dist/core/ports.d.ts +29 -0
- package/dist/core/ports.js +0 -0
- package/dist/core/schema.cjs +173 -0
- package/dist/core/schema.d.cts +33 -0
- package/dist/core/schema.d.ts +33 -0
- package/dist/{chunk-NA3DLROL.js → core/schema.js} +34 -72
- package/dist/core/status.cjs +47 -0
- package/dist/core/status.d.cts +8 -0
- package/dist/core/status.d.ts +8 -0
- package/dist/core/status.js +7 -0
- package/dist/index.cjs +70 -398
- package/dist/index.d.cts +11 -32
- package/dist/index.d.ts +11 -32
- package/dist/index.js +13 -25
- package/dist/store/ddl.cjs +209 -0
- package/dist/store/ddl.d.cts +56 -0
- package/dist/store/ddl.d.ts +56 -0
- package/dist/store/ddl.js +175 -0
- package/dist/store/hash.cjs +50 -0
- package/dist/store/hash.d.cts +2 -0
- package/dist/store/hash.d.ts +2 -0
- package/dist/store/hash.js +10 -0
- package/dist/store/store.cjs +606 -0
- package/dist/store/store.d.cts +169 -0
- package/dist/store/store.d.ts +169 -0
- package/dist/store/store.js +578 -0
- package/dist/store.cjs +51 -1358
- package/dist/store.d.cts +4 -277
- package/dist/store.d.ts +4 -277
- package/dist/store.js +17 -1114
- package/dist/surface/table.cjs +326 -0
- package/dist/surface/table.d.cts +70 -0
- package/dist/surface/table.d.ts +70 -0
- package/dist/surface/table.js +296 -0
- package/dist/workflows/document-workflows.cjs +314 -0
- package/dist/workflows/document-workflows.d.cts +112 -0
- package/dist/workflows/document-workflows.d.ts +112 -0
- package/dist/workflows/document-workflows.js +281 -0
- package/dist/workflows/effects.cjs +41 -0
- package/dist/workflows/effects.d.cts +68 -0
- package/dist/workflows/effects.d.ts +68 -0
- package/dist/workflows/effects.js +0 -0
- package/dist/workflows/ports.cjs +50 -0
- package/dist/workflows/ports.d.cts +72 -0
- package/dist/workflows/ports.d.ts +72 -0
- package/dist/workflows/ports.js +10 -0
- package/dist/workflows/refusals.cjs +80 -0
- package/dist/workflows/refusals.d.cts +59 -0
- package/dist/workflows/refusals.d.ts +59 -0
- package/dist/workflows/refusals.js +40 -0
- package/dist/workflows.cjs +52 -504
- package/dist/workflows.d.cts +4 -310
- package/dist/workflows.d.ts +4 -310
- package/dist/workflows.js +21 -368
- package/package.json +8 -8
- package/dist/chunk-A6ZU4QU3.js +0 -171
- package/dist/entities-DTNJMeVf.d.cts +0 -205
- package/dist/entities-DTNJMeVf.d.ts +0 -205
- package/dist/ports-C_OfflMQ.d.cts +0 -66
- package/dist/ports-C_OfflMQ.d.ts +0 -66
package/dist/workflows.d.cts
CHANGED
|
@@ -1,310 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import * as better_result from 'better-result';
|
|
6
|
-
import { Result } from 'better-result';
|
|
7
|
-
|
|
8
|
-
/** What a write left behind: the entity, the number the document carries, and its body. */
|
|
9
|
-
type Written<E> = {
|
|
10
|
-
entity: NameOf<E>;
|
|
11
|
-
number: string;
|
|
12
|
-
body: BodyOf<E>;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* What a workflow did, as the entity is asked to announce it: one function per entity turns
|
|
16
|
-
* these into the product's own events — or into nothing, which is a decision too. `sent` and
|
|
17
|
-
* `shared` carry the link so a product that publishes a shared-link event can say so from either.
|
|
18
|
-
*/
|
|
19
|
-
type DocumentFact<E> = {
|
|
20
|
-
kind: 'created';
|
|
21
|
-
written: Written<E>;
|
|
22
|
-
minted: {
|
|
23
|
-
sequence: number;
|
|
24
|
-
} | null;
|
|
25
|
-
} | {
|
|
26
|
-
kind: 'saved';
|
|
27
|
-
written: Written<E>;
|
|
28
|
-
} | {
|
|
29
|
-
kind: 'moved';
|
|
30
|
-
written: Written<E>;
|
|
31
|
-
to: string;
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'deleted';
|
|
34
|
-
number: string;
|
|
35
|
-
} | {
|
|
36
|
-
kind: 'sent';
|
|
37
|
-
written: Written<E>;
|
|
38
|
-
to: string;
|
|
39
|
-
url: string;
|
|
40
|
-
expiresAt: number;
|
|
41
|
-
} | {
|
|
42
|
-
kind: 'shared';
|
|
43
|
-
number: string;
|
|
44
|
-
url: string;
|
|
45
|
-
expiresAt: number;
|
|
46
|
-
} | {
|
|
47
|
-
kind: 'converted';
|
|
48
|
-
number: string;
|
|
49
|
-
to: string;
|
|
50
|
-
};
|
|
51
|
-
/** One entity's conversion into another: what refuses it, the target's body, how the source is marked. */
|
|
52
|
-
type DocumentConversion<E, To> = {
|
|
53
|
-
to: To;
|
|
54
|
-
refuse: (body: BodyOf<E>) => string | null;
|
|
55
|
-
bodyFor: (body: BodyOf<E>, number: string) => BodyOf<To>;
|
|
56
|
-
markSource: (body: BodyOf<E>, number: string) => BodyOf<E>;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* What an entity decides with a side effect. `announce` is the one decision every entity makes —
|
|
60
|
-
* the events are the product's, and the kit cannot guess their names. The rest default: no
|
|
61
|
-
* `beforeCreate`, no `conversion`, and mail words made of the entity's noun and the number.
|
|
62
|
-
*/
|
|
63
|
-
type DocumentEffects<E, Ctx> = {
|
|
64
|
-
announce: (fact: DocumentFact<E>) => Announcement | readonly Announcement[] | null;
|
|
65
|
-
beforeCreate?: (ctx: Ctx, body: BodyOf<E>) => Promise<BodyOf<E>>;
|
|
66
|
-
conversion?: DocumentConversion<E, {
|
|
67
|
-
name: string;
|
|
68
|
-
}>;
|
|
69
|
-
mail?: (number: string) => {
|
|
70
|
-
subject: string;
|
|
71
|
-
opening: string;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
declare const MAIL_UNDELIVERED_TAG = "DocumentMailUndelivered";
|
|
76
|
-
declare const MailUndelivered_base: better_result.TaggedErrorClass<"DocumentMailUndelivered">;
|
|
77
|
-
/**
|
|
78
|
-
* What a mail port answers with when the message did not leave; the step it runs in fails on it.
|
|
79
|
-
* `TaggedError` is aliased the way observability aliases it: oxlint reads the bare call as an
|
|
80
|
-
* error thrown without `new`.
|
|
81
|
-
*/
|
|
82
|
-
declare class MailUndelivered extends /* @__PURE__ */ MailUndelivered_base<{
|
|
83
|
-
to: string;
|
|
84
|
-
cause: unknown;
|
|
85
|
-
}> {
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* One entity's rows, bound to the run's organisation by the host: `stepsOf` over a store door is
|
|
89
|
-
* the shape, so every call is a journalled step in a durable run. `body` is `never` on purpose —
|
|
90
|
-
* the factory writes what the entity decided and a door typed to one body still fits.
|
|
91
|
-
*/
|
|
92
|
-
type DocumentDoorPort = {
|
|
93
|
-
get: (params: {
|
|
94
|
-
ref: string;
|
|
95
|
-
}) => Promise<{
|
|
96
|
-
body: unknown;
|
|
97
|
-
} | null>;
|
|
98
|
-
commit: (params: {
|
|
99
|
-
actor: string;
|
|
100
|
-
body: never;
|
|
101
|
-
ref: string;
|
|
102
|
-
}) => Promise<unknown>;
|
|
103
|
-
retire: (params: {
|
|
104
|
-
actor: string;
|
|
105
|
-
ref: string;
|
|
106
|
-
}) => Promise<unknown>;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* What a host answers the generic body with. Three are the host's alone — its doors, its links,
|
|
110
|
-
* its mail — and the rest default: `counter` is asked for only by an entity numbered from one,
|
|
111
|
-
* `actor` reads a string `actor` off the context or names the system, `guard` allows, `now` is
|
|
112
|
-
* the clock, and `seed` refuses a template. Plain functions — the factory makes the steps of the
|
|
113
|
-
* two that reach the outside world, so the durable-body law holds on every host.
|
|
114
|
-
*/
|
|
115
|
-
type DocumentWorkflowPorts<Ctx> = {
|
|
116
|
-
door: (ctx: Ctx, entity: string) => DocumentDoorPort;
|
|
117
|
-
link: (ctx: Ctx, link: {
|
|
118
|
-
entity: string;
|
|
119
|
-
ref: string;
|
|
120
|
-
now: number;
|
|
121
|
-
ttlDays?: number;
|
|
122
|
-
}) => Promise<{
|
|
123
|
-
token: string;
|
|
124
|
-
url: string;
|
|
125
|
-
expiresAt: number;
|
|
126
|
-
ttlDays: number;
|
|
127
|
-
}>;
|
|
128
|
-
mail: (ctx: Ctx, mail: {
|
|
129
|
-
to: string;
|
|
130
|
-
subject: string;
|
|
131
|
-
text: string;
|
|
132
|
-
}) => Promise<Result<void, MailUndelivered>>;
|
|
133
|
-
actor?: (ctx: Ctx, workflowName: string) => string;
|
|
134
|
-
counter?: (ctx: Ctx, key: string) => Promise<{
|
|
135
|
-
number: number;
|
|
136
|
-
}>;
|
|
137
|
-
guard?: (ctx: Ctx) => Promise<unknown>;
|
|
138
|
-
now?: () => string;
|
|
139
|
-
seed?: (ctx: Ctx, seeding: {
|
|
140
|
-
entity: string;
|
|
141
|
-
templateId: string | undefined;
|
|
142
|
-
input: Record<string, unknown>;
|
|
143
|
-
}) => Promise<Record<string, unknown>>;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* What the body needs off an entity: the registry's minimal bound plus the facts and pure
|
|
148
|
-
* decisions every workflow is written over — the shape `Document.extend` returns, never a second
|
|
149
|
-
* one. `never` parameters are the same device the surface uses: a definition typed to its own
|
|
150
|
-
* body still fits, and the factory writes what that definition decided.
|
|
151
|
-
*/
|
|
152
|
-
type WorkflowDocumentEntity = AnyDocumentEntity & {
|
|
153
|
-
noun: string;
|
|
154
|
-
draft: StandardSchemaV1;
|
|
155
|
-
incoming: StandardSchemaV1;
|
|
156
|
-
statuses: DocumentStatusMachine<string>;
|
|
157
|
-
numbering: DocumentNumbering<never>;
|
|
158
|
-
fromDraft: (draft: never, number: string) => unknown;
|
|
159
|
-
prepare: (body: never) => unknown;
|
|
160
|
-
merge: (stored: never, incoming: never, at: string) => unknown;
|
|
161
|
-
statusOf: (body: never) => string;
|
|
162
|
-
withStatus: (body: never, status: never, at: string) => unknown;
|
|
163
|
-
onSent: (body: never) => unknown;
|
|
164
|
-
copy: (body: never) => unknown;
|
|
165
|
-
removable: boolean;
|
|
166
|
-
};
|
|
167
|
-
type DocumentWorkflowOptions<E, Ctx> = {
|
|
168
|
-
effects: DocumentEffects<E, Ctx>;
|
|
169
|
-
ports: DocumentWorkflowPorts<Ctx>;
|
|
170
|
-
};
|
|
171
|
-
type Minted = {
|
|
172
|
-
sequence: number;
|
|
173
|
-
} | null;
|
|
174
|
-
/**
|
|
175
|
-
* `documentWorkflows(entity, { effects, ports })`: the whole of what a Document can do, minted
|
|
176
|
-
* once per entity that extends it. The workflows are named for the entity (`invoice.create`,
|
|
177
|
-
* `purchase-order.send`), their inputs are the entity's own schemas, and their bodies are written
|
|
178
|
-
* here exactly once — a workflow named for one entity anywhere else is the fork this replaces.
|
|
179
|
-
*/
|
|
180
|
-
declare const documentWorkflows: <E extends WorkflowDocumentEntity, Ctx extends object>(entity: E, options: DocumentWorkflowOptions<E, Ctx>) => {
|
|
181
|
-
entity: E;
|
|
182
|
-
create: _geonosis_workflows.Workflow<{
|
|
183
|
-
ref?: string;
|
|
184
|
-
body: DraftOf<E>;
|
|
185
|
-
templateId?: string;
|
|
186
|
-
}, {
|
|
187
|
-
minted: Minted;
|
|
188
|
-
entity: NameOf<E>;
|
|
189
|
-
number: string;
|
|
190
|
-
body: BodyOf<E>;
|
|
191
|
-
}, Ctx>;
|
|
192
|
-
save: _geonosis_workflows.Workflow<{
|
|
193
|
-
ref: string;
|
|
194
|
-
body: IncomingOf<E>;
|
|
195
|
-
}, Written<E>, Ctx>;
|
|
196
|
-
setStatus: _geonosis_workflows.Workflow<{
|
|
197
|
-
ref: string;
|
|
198
|
-
to: string;
|
|
199
|
-
}, {
|
|
200
|
-
to: string;
|
|
201
|
-
entity: NameOf<E>;
|
|
202
|
-
number: string;
|
|
203
|
-
body: BodyOf<E>;
|
|
204
|
-
}, Ctx>;
|
|
205
|
-
remove: _geonosis_workflows.Workflow<{
|
|
206
|
-
ref: string;
|
|
207
|
-
}, {
|
|
208
|
-
number: string;
|
|
209
|
-
}, Ctx>;
|
|
210
|
-
send: _geonosis_workflows.Workflow<{
|
|
211
|
-
ref: string;
|
|
212
|
-
to: string;
|
|
213
|
-
ttlDays?: number;
|
|
214
|
-
now: number;
|
|
215
|
-
}, {
|
|
216
|
-
to: string;
|
|
217
|
-
url: string;
|
|
218
|
-
expiresAt: number;
|
|
219
|
-
entity: NameOf<E>;
|
|
220
|
-
number: string;
|
|
221
|
-
body: BodyOf<E>;
|
|
222
|
-
}, Ctx>;
|
|
223
|
-
convert: _geonosis_workflows.Workflow<{
|
|
224
|
-
ref: string;
|
|
225
|
-
}, {
|
|
226
|
-
entity: string;
|
|
227
|
-
number: string;
|
|
228
|
-
}, Ctx>;
|
|
229
|
-
duplicate: _geonosis_workflows.Workflow<{
|
|
230
|
-
ref: string;
|
|
231
|
-
targetRef?: string;
|
|
232
|
-
}, {
|
|
233
|
-
minted: Minted;
|
|
234
|
-
entity: NameOf<E>;
|
|
235
|
-
number: string;
|
|
236
|
-
body: BodyOf<E>;
|
|
237
|
-
}, Ctx>;
|
|
238
|
-
share: _geonosis_workflows.Workflow<{
|
|
239
|
-
ref: string;
|
|
240
|
-
now: number;
|
|
241
|
-
ttlDays?: number;
|
|
242
|
-
}, {
|
|
243
|
-
number: string;
|
|
244
|
-
token: string;
|
|
245
|
-
url: string;
|
|
246
|
-
expiresAt: number;
|
|
247
|
-
}, Ctx>;
|
|
248
|
-
};
|
|
249
|
-
type DocumentWorkflows<E extends WorkflowDocumentEntity, Ctx extends object> = ReturnType<typeof documentWorkflows<E, Ctx>>;
|
|
250
|
-
|
|
251
|
-
declare const DOCUMENT_NOT_FOUND_TAG = "DocumentNotFound";
|
|
252
|
-
declare const DOCUMENT_TAKEN_TAG = "DocumentTaken";
|
|
253
|
-
declare const NUMBERING_REFUSED_TAG = "NumberingRefused";
|
|
254
|
-
declare const TRANSITION_REFUSED_TAG = "TransitionRefused";
|
|
255
|
-
declare const DOCUMENT_NOT_REMOVABLE_TAG = "DocumentNotRemovable";
|
|
256
|
-
declare const CONVERSION_REFUSED_TAG = "ConversionRefused";
|
|
257
|
-
declare const DocumentNotFound_base: better_result.TaggedErrorClass<"DocumentNotFound">;
|
|
258
|
-
/**
|
|
259
|
-
* What a document workflow refuses, named. The engine wraps whatever a body throws in its own
|
|
260
|
-
* `RunFailedError` with the refusal as `cause`, so a host reads the name off the cause and answers
|
|
261
|
-
* with it — 404 for a document that is not there, 409 for a ref that is taken or a move the machine
|
|
262
|
-
* refuses, 400 for a numbering it cannot honour — instead of a 500 with the sentence inside it.
|
|
263
|
-
* Aliased the way `MailUndelivered` is: oxlint reads the bare call as an error thrown without `new`.
|
|
264
|
-
*/
|
|
265
|
-
declare class DocumentNotFound extends /* @__PURE__ */ DocumentNotFound_base<{
|
|
266
|
-
entity: string;
|
|
267
|
-
message: string;
|
|
268
|
-
ref: string;
|
|
269
|
-
}> {
|
|
270
|
-
}
|
|
271
|
-
declare const DocumentTaken_base: better_result.TaggedErrorClass<"DocumentTaken">;
|
|
272
|
-
declare class DocumentTaken extends /* @__PURE__ */ DocumentTaken_base<{
|
|
273
|
-
entity: string;
|
|
274
|
-
message: string;
|
|
275
|
-
ref: string;
|
|
276
|
-
}> {
|
|
277
|
-
}
|
|
278
|
-
declare const NumberingRefused_base: better_result.TaggedErrorClass<"NumberingRefused">;
|
|
279
|
-
/** `given` — a number the caller had to supply and did not; `counter` — one the caller supplied to an entity that mints its own, or the host declares no counter. */
|
|
280
|
-
declare class NumberingRefused extends /* @__PURE__ */ NumberingRefused_base<{
|
|
281
|
-
entity: string;
|
|
282
|
-
message: string;
|
|
283
|
-
mode: 'counter' | 'given';
|
|
284
|
-
}> {
|
|
285
|
-
}
|
|
286
|
-
declare const TransitionRefused_base: better_result.TaggedErrorClass<"TransitionRefused">;
|
|
287
|
-
declare class TransitionRefused extends /* @__PURE__ */ TransitionRefused_base<{
|
|
288
|
-
entity: string;
|
|
289
|
-
from: string;
|
|
290
|
-
message: string;
|
|
291
|
-
ref: string;
|
|
292
|
-
to: string;
|
|
293
|
-
}> {
|
|
294
|
-
}
|
|
295
|
-
declare const DocumentNotRemovable_base: better_result.TaggedErrorClass<"DocumentNotRemovable">;
|
|
296
|
-
declare class DocumentNotRemovable extends /* @__PURE__ */ DocumentNotRemovable_base<{
|
|
297
|
-
entity: string;
|
|
298
|
-
message: string;
|
|
299
|
-
}> {
|
|
300
|
-
}
|
|
301
|
-
declare const ConversionRefused_base: better_result.TaggedErrorClass<"ConversionRefused">;
|
|
302
|
-
declare class ConversionRefused extends /* @__PURE__ */ ConversionRefused_base<{
|
|
303
|
-
entity: string;
|
|
304
|
-
message: string;
|
|
305
|
-
ref: string;
|
|
306
|
-
}> {
|
|
307
|
-
}
|
|
308
|
-
type DocumentRefusal = ConversionRefused | DocumentNotFound | DocumentNotRemovable | DocumentTaken | NumberingRefused | TransitionRefused;
|
|
309
|
-
|
|
310
|
-
export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, type DocumentConversion, type DocumentDoorPort, type DocumentEffects, type DocumentFact, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, type DocumentWorkflowOptions, type DocumentWorkflowPorts, type DocumentWorkflows, MAIL_UNDELIVERED_TAG, MailUndelivered, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused, type WorkflowDocumentEntity, type Written, documentWorkflows };
|
|
1
|
+
export { documentWorkflows, type DocumentWorkflowOptions, type DocumentWorkflows, type WorkflowDocumentEntity } from './workflows/document-workflows.cjs';
|
|
2
|
+
export type { DocumentConversion, DocumentEffects, DocumentFact, Written } from './workflows/effects.cjs';
|
|
3
|
+
export { type DocumentDoorPort, type DocumentWorkflowPorts, MAIL_UNDELIVERED_TAG, MailUndelivered } from './workflows/ports.cjs';
|
|
4
|
+
export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused } from './workflows/refusals.cjs';
|
package/dist/workflows.d.ts
CHANGED
|
@@ -1,310 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import * as better_result from 'better-result';
|
|
6
|
-
import { Result } from 'better-result';
|
|
7
|
-
|
|
8
|
-
/** What a write left behind: the entity, the number the document carries, and its body. */
|
|
9
|
-
type Written<E> = {
|
|
10
|
-
entity: NameOf<E>;
|
|
11
|
-
number: string;
|
|
12
|
-
body: BodyOf<E>;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* What a workflow did, as the entity is asked to announce it: one function per entity turns
|
|
16
|
-
* these into the product's own events — or into nothing, which is a decision too. `sent` and
|
|
17
|
-
* `shared` carry the link so a product that publishes a shared-link event can say so from either.
|
|
18
|
-
*/
|
|
19
|
-
type DocumentFact<E> = {
|
|
20
|
-
kind: 'created';
|
|
21
|
-
written: Written<E>;
|
|
22
|
-
minted: {
|
|
23
|
-
sequence: number;
|
|
24
|
-
} | null;
|
|
25
|
-
} | {
|
|
26
|
-
kind: 'saved';
|
|
27
|
-
written: Written<E>;
|
|
28
|
-
} | {
|
|
29
|
-
kind: 'moved';
|
|
30
|
-
written: Written<E>;
|
|
31
|
-
to: string;
|
|
32
|
-
} | {
|
|
33
|
-
kind: 'deleted';
|
|
34
|
-
number: string;
|
|
35
|
-
} | {
|
|
36
|
-
kind: 'sent';
|
|
37
|
-
written: Written<E>;
|
|
38
|
-
to: string;
|
|
39
|
-
url: string;
|
|
40
|
-
expiresAt: number;
|
|
41
|
-
} | {
|
|
42
|
-
kind: 'shared';
|
|
43
|
-
number: string;
|
|
44
|
-
url: string;
|
|
45
|
-
expiresAt: number;
|
|
46
|
-
} | {
|
|
47
|
-
kind: 'converted';
|
|
48
|
-
number: string;
|
|
49
|
-
to: string;
|
|
50
|
-
};
|
|
51
|
-
/** One entity's conversion into another: what refuses it, the target's body, how the source is marked. */
|
|
52
|
-
type DocumentConversion<E, To> = {
|
|
53
|
-
to: To;
|
|
54
|
-
refuse: (body: BodyOf<E>) => string | null;
|
|
55
|
-
bodyFor: (body: BodyOf<E>, number: string) => BodyOf<To>;
|
|
56
|
-
markSource: (body: BodyOf<E>, number: string) => BodyOf<E>;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* What an entity decides with a side effect. `announce` is the one decision every entity makes —
|
|
60
|
-
* the events are the product's, and the kit cannot guess their names. The rest default: no
|
|
61
|
-
* `beforeCreate`, no `conversion`, and mail words made of the entity's noun and the number.
|
|
62
|
-
*/
|
|
63
|
-
type DocumentEffects<E, Ctx> = {
|
|
64
|
-
announce: (fact: DocumentFact<E>) => Announcement | readonly Announcement[] | null;
|
|
65
|
-
beforeCreate?: (ctx: Ctx, body: BodyOf<E>) => Promise<BodyOf<E>>;
|
|
66
|
-
conversion?: DocumentConversion<E, {
|
|
67
|
-
name: string;
|
|
68
|
-
}>;
|
|
69
|
-
mail?: (number: string) => {
|
|
70
|
-
subject: string;
|
|
71
|
-
opening: string;
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
declare const MAIL_UNDELIVERED_TAG = "DocumentMailUndelivered";
|
|
76
|
-
declare const MailUndelivered_base: better_result.TaggedErrorClass<"DocumentMailUndelivered">;
|
|
77
|
-
/**
|
|
78
|
-
* What a mail port answers with when the message did not leave; the step it runs in fails on it.
|
|
79
|
-
* `TaggedError` is aliased the way observability aliases it: oxlint reads the bare call as an
|
|
80
|
-
* error thrown without `new`.
|
|
81
|
-
*/
|
|
82
|
-
declare class MailUndelivered extends /* @__PURE__ */ MailUndelivered_base<{
|
|
83
|
-
to: string;
|
|
84
|
-
cause: unknown;
|
|
85
|
-
}> {
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* One entity's rows, bound to the run's organisation by the host: `stepsOf` over a store door is
|
|
89
|
-
* the shape, so every call is a journalled step in a durable run. `body` is `never` on purpose —
|
|
90
|
-
* the factory writes what the entity decided and a door typed to one body still fits.
|
|
91
|
-
*/
|
|
92
|
-
type DocumentDoorPort = {
|
|
93
|
-
get: (params: {
|
|
94
|
-
ref: string;
|
|
95
|
-
}) => Promise<{
|
|
96
|
-
body: unknown;
|
|
97
|
-
} | null>;
|
|
98
|
-
commit: (params: {
|
|
99
|
-
actor: string;
|
|
100
|
-
body: never;
|
|
101
|
-
ref: string;
|
|
102
|
-
}) => Promise<unknown>;
|
|
103
|
-
retire: (params: {
|
|
104
|
-
actor: string;
|
|
105
|
-
ref: string;
|
|
106
|
-
}) => Promise<unknown>;
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* What a host answers the generic body with. Three are the host's alone — its doors, its links,
|
|
110
|
-
* its mail — and the rest default: `counter` is asked for only by an entity numbered from one,
|
|
111
|
-
* `actor` reads a string `actor` off the context or names the system, `guard` allows, `now` is
|
|
112
|
-
* the clock, and `seed` refuses a template. Plain functions — the factory makes the steps of the
|
|
113
|
-
* two that reach the outside world, so the durable-body law holds on every host.
|
|
114
|
-
*/
|
|
115
|
-
type DocumentWorkflowPorts<Ctx> = {
|
|
116
|
-
door: (ctx: Ctx, entity: string) => DocumentDoorPort;
|
|
117
|
-
link: (ctx: Ctx, link: {
|
|
118
|
-
entity: string;
|
|
119
|
-
ref: string;
|
|
120
|
-
now: number;
|
|
121
|
-
ttlDays?: number;
|
|
122
|
-
}) => Promise<{
|
|
123
|
-
token: string;
|
|
124
|
-
url: string;
|
|
125
|
-
expiresAt: number;
|
|
126
|
-
ttlDays: number;
|
|
127
|
-
}>;
|
|
128
|
-
mail: (ctx: Ctx, mail: {
|
|
129
|
-
to: string;
|
|
130
|
-
subject: string;
|
|
131
|
-
text: string;
|
|
132
|
-
}) => Promise<Result<void, MailUndelivered>>;
|
|
133
|
-
actor?: (ctx: Ctx, workflowName: string) => string;
|
|
134
|
-
counter?: (ctx: Ctx, key: string) => Promise<{
|
|
135
|
-
number: number;
|
|
136
|
-
}>;
|
|
137
|
-
guard?: (ctx: Ctx) => Promise<unknown>;
|
|
138
|
-
now?: () => string;
|
|
139
|
-
seed?: (ctx: Ctx, seeding: {
|
|
140
|
-
entity: string;
|
|
141
|
-
templateId: string | undefined;
|
|
142
|
-
input: Record<string, unknown>;
|
|
143
|
-
}) => Promise<Record<string, unknown>>;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* What the body needs off an entity: the registry's minimal bound plus the facts and pure
|
|
148
|
-
* decisions every workflow is written over — the shape `Document.extend` returns, never a second
|
|
149
|
-
* one. `never` parameters are the same device the surface uses: a definition typed to its own
|
|
150
|
-
* body still fits, and the factory writes what that definition decided.
|
|
151
|
-
*/
|
|
152
|
-
type WorkflowDocumentEntity = AnyDocumentEntity & {
|
|
153
|
-
noun: string;
|
|
154
|
-
draft: StandardSchemaV1;
|
|
155
|
-
incoming: StandardSchemaV1;
|
|
156
|
-
statuses: DocumentStatusMachine<string>;
|
|
157
|
-
numbering: DocumentNumbering<never>;
|
|
158
|
-
fromDraft: (draft: never, number: string) => unknown;
|
|
159
|
-
prepare: (body: never) => unknown;
|
|
160
|
-
merge: (stored: never, incoming: never, at: string) => unknown;
|
|
161
|
-
statusOf: (body: never) => string;
|
|
162
|
-
withStatus: (body: never, status: never, at: string) => unknown;
|
|
163
|
-
onSent: (body: never) => unknown;
|
|
164
|
-
copy: (body: never) => unknown;
|
|
165
|
-
removable: boolean;
|
|
166
|
-
};
|
|
167
|
-
type DocumentWorkflowOptions<E, Ctx> = {
|
|
168
|
-
effects: DocumentEffects<E, Ctx>;
|
|
169
|
-
ports: DocumentWorkflowPorts<Ctx>;
|
|
170
|
-
};
|
|
171
|
-
type Minted = {
|
|
172
|
-
sequence: number;
|
|
173
|
-
} | null;
|
|
174
|
-
/**
|
|
175
|
-
* `documentWorkflows(entity, { effects, ports })`: the whole of what a Document can do, minted
|
|
176
|
-
* once per entity that extends it. The workflows are named for the entity (`invoice.create`,
|
|
177
|
-
* `purchase-order.send`), their inputs are the entity's own schemas, and their bodies are written
|
|
178
|
-
* here exactly once — a workflow named for one entity anywhere else is the fork this replaces.
|
|
179
|
-
*/
|
|
180
|
-
declare const documentWorkflows: <E extends WorkflowDocumentEntity, Ctx extends object>(entity: E, options: DocumentWorkflowOptions<E, Ctx>) => {
|
|
181
|
-
entity: E;
|
|
182
|
-
create: _geonosis_workflows.Workflow<{
|
|
183
|
-
ref?: string;
|
|
184
|
-
body: DraftOf<E>;
|
|
185
|
-
templateId?: string;
|
|
186
|
-
}, {
|
|
187
|
-
minted: Minted;
|
|
188
|
-
entity: NameOf<E>;
|
|
189
|
-
number: string;
|
|
190
|
-
body: BodyOf<E>;
|
|
191
|
-
}, Ctx>;
|
|
192
|
-
save: _geonosis_workflows.Workflow<{
|
|
193
|
-
ref: string;
|
|
194
|
-
body: IncomingOf<E>;
|
|
195
|
-
}, Written<E>, Ctx>;
|
|
196
|
-
setStatus: _geonosis_workflows.Workflow<{
|
|
197
|
-
ref: string;
|
|
198
|
-
to: string;
|
|
199
|
-
}, {
|
|
200
|
-
to: string;
|
|
201
|
-
entity: NameOf<E>;
|
|
202
|
-
number: string;
|
|
203
|
-
body: BodyOf<E>;
|
|
204
|
-
}, Ctx>;
|
|
205
|
-
remove: _geonosis_workflows.Workflow<{
|
|
206
|
-
ref: string;
|
|
207
|
-
}, {
|
|
208
|
-
number: string;
|
|
209
|
-
}, Ctx>;
|
|
210
|
-
send: _geonosis_workflows.Workflow<{
|
|
211
|
-
ref: string;
|
|
212
|
-
to: string;
|
|
213
|
-
ttlDays?: number;
|
|
214
|
-
now: number;
|
|
215
|
-
}, {
|
|
216
|
-
to: string;
|
|
217
|
-
url: string;
|
|
218
|
-
expiresAt: number;
|
|
219
|
-
entity: NameOf<E>;
|
|
220
|
-
number: string;
|
|
221
|
-
body: BodyOf<E>;
|
|
222
|
-
}, Ctx>;
|
|
223
|
-
convert: _geonosis_workflows.Workflow<{
|
|
224
|
-
ref: string;
|
|
225
|
-
}, {
|
|
226
|
-
entity: string;
|
|
227
|
-
number: string;
|
|
228
|
-
}, Ctx>;
|
|
229
|
-
duplicate: _geonosis_workflows.Workflow<{
|
|
230
|
-
ref: string;
|
|
231
|
-
targetRef?: string;
|
|
232
|
-
}, {
|
|
233
|
-
minted: Minted;
|
|
234
|
-
entity: NameOf<E>;
|
|
235
|
-
number: string;
|
|
236
|
-
body: BodyOf<E>;
|
|
237
|
-
}, Ctx>;
|
|
238
|
-
share: _geonosis_workflows.Workflow<{
|
|
239
|
-
ref: string;
|
|
240
|
-
now: number;
|
|
241
|
-
ttlDays?: number;
|
|
242
|
-
}, {
|
|
243
|
-
number: string;
|
|
244
|
-
token: string;
|
|
245
|
-
url: string;
|
|
246
|
-
expiresAt: number;
|
|
247
|
-
}, Ctx>;
|
|
248
|
-
};
|
|
249
|
-
type DocumentWorkflows<E extends WorkflowDocumentEntity, Ctx extends object> = ReturnType<typeof documentWorkflows<E, Ctx>>;
|
|
250
|
-
|
|
251
|
-
declare const DOCUMENT_NOT_FOUND_TAG = "DocumentNotFound";
|
|
252
|
-
declare const DOCUMENT_TAKEN_TAG = "DocumentTaken";
|
|
253
|
-
declare const NUMBERING_REFUSED_TAG = "NumberingRefused";
|
|
254
|
-
declare const TRANSITION_REFUSED_TAG = "TransitionRefused";
|
|
255
|
-
declare const DOCUMENT_NOT_REMOVABLE_TAG = "DocumentNotRemovable";
|
|
256
|
-
declare const CONVERSION_REFUSED_TAG = "ConversionRefused";
|
|
257
|
-
declare const DocumentNotFound_base: better_result.TaggedErrorClass<"DocumentNotFound">;
|
|
258
|
-
/**
|
|
259
|
-
* What a document workflow refuses, named. The engine wraps whatever a body throws in its own
|
|
260
|
-
* `RunFailedError` with the refusal as `cause`, so a host reads the name off the cause and answers
|
|
261
|
-
* with it — 404 for a document that is not there, 409 for a ref that is taken or a move the machine
|
|
262
|
-
* refuses, 400 for a numbering it cannot honour — instead of a 500 with the sentence inside it.
|
|
263
|
-
* Aliased the way `MailUndelivered` is: oxlint reads the bare call as an error thrown without `new`.
|
|
264
|
-
*/
|
|
265
|
-
declare class DocumentNotFound extends /* @__PURE__ */ DocumentNotFound_base<{
|
|
266
|
-
entity: string;
|
|
267
|
-
message: string;
|
|
268
|
-
ref: string;
|
|
269
|
-
}> {
|
|
270
|
-
}
|
|
271
|
-
declare const DocumentTaken_base: better_result.TaggedErrorClass<"DocumentTaken">;
|
|
272
|
-
declare class DocumentTaken extends /* @__PURE__ */ DocumentTaken_base<{
|
|
273
|
-
entity: string;
|
|
274
|
-
message: string;
|
|
275
|
-
ref: string;
|
|
276
|
-
}> {
|
|
277
|
-
}
|
|
278
|
-
declare const NumberingRefused_base: better_result.TaggedErrorClass<"NumberingRefused">;
|
|
279
|
-
/** `given` — a number the caller had to supply and did not; `counter` — one the caller supplied to an entity that mints its own, or the host declares no counter. */
|
|
280
|
-
declare class NumberingRefused extends /* @__PURE__ */ NumberingRefused_base<{
|
|
281
|
-
entity: string;
|
|
282
|
-
message: string;
|
|
283
|
-
mode: 'counter' | 'given';
|
|
284
|
-
}> {
|
|
285
|
-
}
|
|
286
|
-
declare const TransitionRefused_base: better_result.TaggedErrorClass<"TransitionRefused">;
|
|
287
|
-
declare class TransitionRefused extends /* @__PURE__ */ TransitionRefused_base<{
|
|
288
|
-
entity: string;
|
|
289
|
-
from: string;
|
|
290
|
-
message: string;
|
|
291
|
-
ref: string;
|
|
292
|
-
to: string;
|
|
293
|
-
}> {
|
|
294
|
-
}
|
|
295
|
-
declare const DocumentNotRemovable_base: better_result.TaggedErrorClass<"DocumentNotRemovable">;
|
|
296
|
-
declare class DocumentNotRemovable extends /* @__PURE__ */ DocumentNotRemovable_base<{
|
|
297
|
-
entity: string;
|
|
298
|
-
message: string;
|
|
299
|
-
}> {
|
|
300
|
-
}
|
|
301
|
-
declare const ConversionRefused_base: better_result.TaggedErrorClass<"ConversionRefused">;
|
|
302
|
-
declare class ConversionRefused extends /* @__PURE__ */ ConversionRefused_base<{
|
|
303
|
-
entity: string;
|
|
304
|
-
message: string;
|
|
305
|
-
ref: string;
|
|
306
|
-
}> {
|
|
307
|
-
}
|
|
308
|
-
type DocumentRefusal = ConversionRefused | DocumentNotFound | DocumentNotRemovable | DocumentTaken | NumberingRefused | TransitionRefused;
|
|
309
|
-
|
|
310
|
-
export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, type DocumentConversion, type DocumentDoorPort, type DocumentEffects, type DocumentFact, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, type DocumentWorkflowOptions, type DocumentWorkflowPorts, type DocumentWorkflows, MAIL_UNDELIVERED_TAG, MailUndelivered, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused, type WorkflowDocumentEntity, type Written, documentWorkflows };
|
|
1
|
+
export { documentWorkflows, type DocumentWorkflowOptions, type DocumentWorkflows, type WorkflowDocumentEntity } from './workflows/document-workflows.js';
|
|
2
|
+
export type { DocumentConversion, DocumentEffects, DocumentFact, Written } from './workflows/effects.js';
|
|
3
|
+
export { type DocumentDoorPort, type DocumentWorkflowPorts, MAIL_UNDELIVERED_TAG, MailUndelivered } from './workflows/ports.js';
|
|
4
|
+
export { CONVERSION_REFUSED_TAG, ConversionRefused, DOCUMENT_NOT_FOUND_TAG, DOCUMENT_NOT_REMOVABLE_TAG, DOCUMENT_TAKEN_TAG, DocumentNotFound, DocumentNotRemovable, type DocumentRefusal, DocumentTaken, NUMBERING_REFUSED_TAG, NumberingRefused, TRANSITION_REFUSED_TAG, TransitionRefused } from './workflows/refusals.js';
|