@geonosis/document 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -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.cjs
CHANGED
|
@@ -1,513 +1,61 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
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 });
|
|
11
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (
|
|
13
|
-
if (!__hasOwnProp.call(
|
|
14
|
-
__defProp(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/workflows.ts
|
|
21
|
-
var workflows_exports = {};
|
|
22
|
-
__export(workflows_exports, {
|
|
23
|
-
CONVERSION_REFUSED_TAG: () => CONVERSION_REFUSED_TAG,
|
|
24
|
-
ConversionRefused: () => ConversionRefused,
|
|
25
|
-
DOCUMENT_NOT_FOUND_TAG: () => DOCUMENT_NOT_FOUND_TAG,
|
|
26
|
-
DOCUMENT_NOT_REMOVABLE_TAG: () => DOCUMENT_NOT_REMOVABLE_TAG,
|
|
27
|
-
DOCUMENT_TAKEN_TAG: () => DOCUMENT_TAKEN_TAG,
|
|
28
|
-
DocumentNotFound: () => DocumentNotFound,
|
|
29
|
-
DocumentNotRemovable: () => DocumentNotRemovable,
|
|
30
|
-
DocumentTaken: () => DocumentTaken,
|
|
31
|
-
MAIL_UNDELIVERED_TAG: () => MAIL_UNDELIVERED_TAG,
|
|
32
|
-
MailUndelivered: () => MailUndelivered,
|
|
33
|
-
NUMBERING_REFUSED_TAG: () => NUMBERING_REFUSED_TAG,
|
|
34
|
-
NumberingRefused: () => NumberingRefused,
|
|
35
|
-
TRANSITION_REFUSED_TAG: () => TRANSITION_REFUSED_TAG,
|
|
36
|
-
TransitionRefused: () => TransitionRefused,
|
|
37
|
-
documentWorkflows: () => documentWorkflows
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(workflows_exports);
|
|
40
|
-
|
|
41
|
-
// src/workflows/document-workflows.ts
|
|
42
|
-
var import_workflows = require("@geonosis/workflows");
|
|
43
|
-
|
|
44
|
-
// src/core/actor.ts
|
|
45
|
-
var SYSTEM_PREFIX = "system:";
|
|
46
|
-
var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
|
|
47
|
-
|
|
48
|
-
// src/core/schema.ts
|
|
49
|
-
var VENDOR = "geonosis-document";
|
|
50
|
-
var isString = (value) => typeof value === "string";
|
|
51
|
-
var isNumber = (value) => typeof value === "number";
|
|
52
|
-
var scalar = (test, message) => ({
|
|
53
|
-
"~standard": {
|
|
54
|
-
validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
|
|
55
|
-
vendor: VENDOR,
|
|
56
|
-
version: 1
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
var stringSchema = scalar(isString, "expected a string");
|
|
60
|
-
var numberSchema = scalar(isNumber, "expected a number");
|
|
61
|
-
var booleanSchema = scalar(
|
|
62
|
-
(value) => typeof value === "boolean",
|
|
63
|
-
"expected a boolean"
|
|
64
|
-
);
|
|
65
|
-
var syncResult = (schema, input) => {
|
|
66
|
-
const result = schema["~standard"].validate(input);
|
|
67
|
-
if (result instanceof Promise) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
"a document surface schema validates synchronously; an async Standard Schema cannot back a row"
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
return result;
|
|
73
|
-
};
|
|
74
|
-
var optional = (inner) => ({
|
|
75
|
-
"~standard": {
|
|
76
|
-
validate: (input) => input === void 0 ? { value: void 0 } : syncResult(inner, input),
|
|
77
|
-
vendor: VENDOR,
|
|
78
|
-
version: 1
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
var nonEmptyString = scalar(
|
|
82
|
-
(value) => typeof value === "string" && value.length > 0,
|
|
83
|
-
"expected a non-empty string"
|
|
84
|
-
);
|
|
85
|
-
var positiveInt = scalar(
|
|
86
|
-
(value) => Number.isInteger(value) && value > 0,
|
|
87
|
-
"expected a positive integer"
|
|
88
|
-
);
|
|
89
|
-
var validate = async (schema, input) => {
|
|
90
|
-
const result = await schema["~standard"].validate(input);
|
|
91
|
-
if (result.issues !== void 0) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
result.issues.map((issue) => {
|
|
94
|
-
const path = (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
95
|
-
return path === "" ? issue.message : `${path}: ${issue.message}`;
|
|
96
|
-
}).join("; ")
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
return result.value;
|
|
100
|
-
};
|
|
101
|
-
var enumOf = (values) => scalar(
|
|
102
|
-
(value) => typeof value === "string" && values.includes(value),
|
|
103
|
-
`expected one of ${values.map((value) => JSON.stringify(value)).join(", ")}`
|
|
104
|
-
);
|
|
105
|
-
var settle = (fields) => {
|
|
106
|
-
const value = {};
|
|
107
|
-
const issues = [];
|
|
108
|
-
for (const [key, result] of fields) {
|
|
109
|
-
if (result.issues !== void 0) {
|
|
110
|
-
issues.push(
|
|
111
|
-
...result.issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] }))
|
|
112
|
-
);
|
|
113
|
-
} else if (result.value !== void 0) {
|
|
114
|
-
value[key] = result.value;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return issues.length > 0 ? { issues } : { value };
|
|
118
|
-
};
|
|
119
|
-
var objectOf = (shape) => ({
|
|
120
|
-
"~standard": {
|
|
121
|
-
validate: (input) => {
|
|
122
|
-
if (input === null || typeof input !== "object") {
|
|
123
|
-
return { issues: [{ message: "expected an object" }] };
|
|
124
|
-
}
|
|
125
|
-
const record = input;
|
|
126
|
-
const fields = Object.entries(shape).map(
|
|
127
|
-
([key, schema]) => [key, schema["~standard"].validate(record[key])]
|
|
128
|
-
);
|
|
129
|
-
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(
|
|
130
|
-
settle
|
|
131
|
-
) : settle(fields);
|
|
132
|
-
},
|
|
133
|
-
vendor: VENDOR,
|
|
134
|
-
version: 1
|
|
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
|
+
});
|
|
135
20
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
var
|
|
145
|
-
var
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
var DocumentTaken = class extends (/* @__PURE__ */ (0, import_better_result.TaggedError)(DOCUMENT_TAKEN_TAG)) {
|
|
152
|
-
};
|
|
153
|
-
var NumberingRefused = class extends (/* @__PURE__ */ (0, import_better_result.TaggedError)(NUMBERING_REFUSED_TAG)) {
|
|
154
|
-
};
|
|
155
|
-
var TransitionRefused = class extends (/* @__PURE__ */ (0, import_better_result.TaggedError)(TRANSITION_REFUSED_TAG)) {
|
|
156
|
-
};
|
|
157
|
-
var DocumentNotRemovable = class extends (/* @__PURE__ */ (0, import_better_result.TaggedError)(DOCUMENT_NOT_REMOVABLE_TAG)) {
|
|
158
|
-
};
|
|
159
|
-
var ConversionRefused = class extends (/* @__PURE__ */ (0, import_better_result.TaggedError)(CONVERSION_REFUSED_TAG)) {
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
// src/workflows/document-workflows.ts
|
|
163
|
-
var withArticle = (noun) => `${/^[aeiou]/i.test(noun) ? "an" : "a"} ${noun}`;
|
|
164
|
-
var capitalised = (noun) => `${noun.charAt(0).toUpperCase()}${noun.slice(1)}`;
|
|
165
|
-
var mailText = (opening, url, ttlDays) => `${opening}
|
|
166
|
-
|
|
167
|
-
${url}
|
|
168
|
-
|
|
169
|
-
The link works for ${ttlDays} days.
|
|
170
|
-
`;
|
|
171
|
-
var typed = (schema) => schema;
|
|
172
|
-
var defaultActor = (ctx, workflowName) => {
|
|
173
|
-
const held = ctx?.actor;
|
|
174
|
-
return typeof held === "string" ? held : systemActor(workflowName);
|
|
175
|
-
};
|
|
176
|
-
var documentWorkflows = (entity, options) => {
|
|
177
|
-
const { effects, ports } = options;
|
|
178
|
-
const name = entity.name;
|
|
179
|
-
const article = withArticle(entity.noun);
|
|
180
|
-
const noun = capitalised(entity.noun);
|
|
181
|
-
const actorOf = ports.actor ?? defaultActor;
|
|
182
|
-
const guard = ports.guard ?? (() => Promise.resolve());
|
|
183
|
-
const now = ports.now ?? (() => (/* @__PURE__ */ new Date()).toISOString());
|
|
184
|
-
const seed = ports.seed ?? ((_ctx, seeding) => {
|
|
185
|
-
if (seeding.templateId !== void 0) {
|
|
186
|
-
throw new Error(`${article} takes no template: this host declares no seed port`);
|
|
187
|
-
}
|
|
188
|
-
return Promise.resolve(seeding.input);
|
|
189
|
-
});
|
|
190
|
-
const beforeCreate = effects.beforeCreate ?? ((_ctx, body) => Promise.resolve(body));
|
|
191
|
-
const mailWords = effects.mail ?? ((number) => ({
|
|
192
|
-
subject: `${noun} ${number}`,
|
|
193
|
-
opening: `${noun} ${number} is ready for you to read.`
|
|
194
|
-
}));
|
|
195
|
-
const announce = (fact) => effects.announce(fact);
|
|
196
|
-
const write = async (ctx, written, workflowName) => {
|
|
197
|
-
await ports.door(ctx, written.entity).commit({
|
|
198
|
-
actor: actorOf(ctx, workflowName),
|
|
199
|
-
body: written.body,
|
|
200
|
-
ref: written.number
|
|
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)
|
|
201
36
|
});
|
|
202
|
-
return written;
|
|
203
|
-
};
|
|
204
|
-
const stored = async (ctx, at) => {
|
|
205
|
-
const found = await ports.door(ctx, name).get({ ref: at.ref });
|
|
206
|
-
if (!found) {
|
|
207
|
-
throw new DocumentNotFound({
|
|
208
|
-
entity: name,
|
|
209
|
-
message: `no ${entity.noun} is stored as ${at.ref}`,
|
|
210
|
-
ref: at.ref
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
return found;
|
|
214
|
-
};
|
|
215
|
-
const refuseTaken = async (ctx, at) => {
|
|
216
|
-
const owner = at.entity ?? name;
|
|
217
|
-
if (await ports.door(ctx, owner).get({ ref: at.ref })) {
|
|
218
|
-
throw new DocumentTaken({
|
|
219
|
-
entity: owner,
|
|
220
|
-
message: `a ${owner} is already stored as ${at.ref}`,
|
|
221
|
-
ref: at.ref
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
const refFor = async (ctx, given, draft) => {
|
|
226
|
-
const numbering = entity.numbering;
|
|
227
|
-
if (numbering.mode === "given") {
|
|
228
|
-
if (given === void 0) {
|
|
229
|
-
throw new NumberingRefused({
|
|
230
|
-
entity: name,
|
|
231
|
-
message: `${article} is numbered by whoever creates it`,
|
|
232
|
-
mode: "given"
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
await refuseTaken(ctx, { ref: given });
|
|
236
|
-
return { ref: given, minted: null };
|
|
237
|
-
}
|
|
238
|
-
if (given !== void 0) {
|
|
239
|
-
throw new NumberingRefused({
|
|
240
|
-
entity: name,
|
|
241
|
-
message: `${article} is numbered by the organisation`,
|
|
242
|
-
mode: "counter"
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
if (ports.counter === void 0) {
|
|
246
|
-
throw new NumberingRefused({
|
|
247
|
-
entity: name,
|
|
248
|
-
message: `${article} is numbered from a counter and this host declares no counter port`,
|
|
249
|
-
mode: "counter"
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
const series = numbering.series(draft);
|
|
253
|
-
const { number: sequence } = await ports.counter(ctx, numbering.counter);
|
|
254
|
-
return { ref: numbering.format(series, sequence), minted: { sequence } };
|
|
255
|
-
};
|
|
256
|
-
const shareLink = (0, import_workflows.createStep)(
|
|
257
|
-
{ name: "create-share-link", noCompensation: true },
|
|
258
|
-
(input, ctx) => ports.link(ctx, { entity: name, ...input })
|
|
259
|
-
);
|
|
260
|
-
const sendMail = (0, import_workflows.createStep)(
|
|
261
|
-
{ name: "send-email", noCompensation: true },
|
|
262
|
-
async (input, ctx) => {
|
|
263
|
-
const sent = await ports.mail(ctx, input);
|
|
264
|
-
if (sent.isErr()) throw sent.error;
|
|
265
|
-
return { to: input.to };
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
const createName = `${name}.create`;
|
|
269
|
-
const create = (0, import_workflows.createWorkflow)(
|
|
270
|
-
createName,
|
|
271
|
-
async (input, ctx) => {
|
|
272
|
-
await guard(ctx);
|
|
273
|
-
const draft = await validate(
|
|
274
|
-
entity.draft,
|
|
275
|
-
await seed(ctx, {
|
|
276
|
-
entity: name,
|
|
277
|
-
templateId: input.templateId,
|
|
278
|
-
input: input.body
|
|
279
|
-
})
|
|
280
|
-
);
|
|
281
|
-
const minted = await refFor(ctx, input.ref, draft);
|
|
282
|
-
const body = entity.prepare(
|
|
283
|
-
await beforeCreate(ctx, entity.fromDraft(draft, minted.ref))
|
|
284
|
-
);
|
|
285
|
-
const written = await write(ctx, { entity: name, number: minted.ref, body }, createName);
|
|
286
|
-
return { ...written, minted: minted.minted };
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
announce: ({ minted, ...written }) => announce({ kind: "created", written, minted }),
|
|
290
|
-
input: typed(
|
|
291
|
-
objectOf({
|
|
292
|
-
body: entity.draft,
|
|
293
|
-
ref: optional(nonEmptyString),
|
|
294
|
-
templateId: optional(nonEmptyString)
|
|
295
|
-
})
|
|
296
|
-
)
|
|
297
|
-
}
|
|
298
|
-
);
|
|
299
|
-
const saveName = `${name}.save`;
|
|
300
|
-
const save = (0, import_workflows.createWorkflow)(
|
|
301
|
-
saveName,
|
|
302
|
-
async (input, ctx) => {
|
|
303
|
-
const current = await stored(ctx, input);
|
|
304
|
-
const body = entity.prepare(
|
|
305
|
-
entity.merge(current.body, input.body, now())
|
|
306
|
-
);
|
|
307
|
-
return write(ctx, { entity: name, number: input.ref, body }, saveName);
|
|
308
|
-
},
|
|
309
|
-
{
|
|
310
|
-
announce: (written) => announce({ kind: "saved", written }),
|
|
311
|
-
input: typed(objectOf({ body: entity.incoming, ref: nonEmptyString }))
|
|
312
|
-
}
|
|
313
|
-
);
|
|
314
|
-
const setStatusName = `${name}.set-status`;
|
|
315
|
-
const setStatus = (0, import_workflows.createWorkflow)(
|
|
316
|
-
setStatusName,
|
|
317
|
-
async (input, ctx) => {
|
|
318
|
-
const current = await stored(ctx, input);
|
|
319
|
-
const from = entity.statusOf(current.body);
|
|
320
|
-
if (!canTransition(entity.statuses, from, input.to)) {
|
|
321
|
-
throw new TransitionRefused({
|
|
322
|
-
entity: name,
|
|
323
|
-
from,
|
|
324
|
-
message: `${article} cannot go from ${from} to ${input.to}`,
|
|
325
|
-
ref: input.ref,
|
|
326
|
-
to: input.to
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
const written = await write(
|
|
330
|
-
ctx,
|
|
331
|
-
{
|
|
332
|
-
entity: name,
|
|
333
|
-
number: input.ref,
|
|
334
|
-
body: entity.withStatus(current.body, input.to, now())
|
|
335
|
-
},
|
|
336
|
-
setStatusName
|
|
337
|
-
);
|
|
338
|
-
return { ...written, to: input.to };
|
|
339
|
-
},
|
|
340
|
-
{
|
|
341
|
-
announce: ({ to, ...written }) => announce({ kind: "moved", written, to }),
|
|
342
|
-
input: typed(
|
|
343
|
-
objectOf({ ref: nonEmptyString, to: enumOf(entity.statuses.statuses) })
|
|
344
|
-
)
|
|
345
|
-
}
|
|
346
|
-
);
|
|
347
|
-
const refInput = typed(objectOf({ ref: nonEmptyString }));
|
|
348
|
-
const deleteName = `${name}.delete`;
|
|
349
|
-
const remove = (0, import_workflows.createWorkflow)(
|
|
350
|
-
deleteName,
|
|
351
|
-
async (input, ctx) => {
|
|
352
|
-
if (!entity.removable) {
|
|
353
|
-
throw new DocumentNotRemovable({
|
|
354
|
-
entity: name,
|
|
355
|
-
message: `deleting is not something ${article} does`
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
const door = ports.door(ctx, name);
|
|
359
|
-
const found = await door.get({ ref: input.ref });
|
|
360
|
-
if (!found) {
|
|
361
|
-
throw new DocumentNotFound({
|
|
362
|
-
entity: name,
|
|
363
|
-
message: `no ${entity.noun} is stored as ${input.ref}`,
|
|
364
|
-
ref: input.ref
|
|
365
|
-
});
|
|
366
|
-
}
|
|
367
|
-
await door.retire({ actor: actorOf(ctx, deleteName), ref: input.ref });
|
|
368
|
-
return { number: input.ref };
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
announce: (removed) => announce({ kind: "deleted", number: removed.number }),
|
|
372
|
-
input: refInput
|
|
373
|
-
}
|
|
374
|
-
);
|
|
375
|
-
const sendName = `${name}.send`;
|
|
376
|
-
const send = (0, import_workflows.createWorkflow)(
|
|
377
|
-
sendName,
|
|
378
|
-
async (input, ctx) => {
|
|
379
|
-
const current = await stored(ctx, input);
|
|
380
|
-
const link = await shareLink({
|
|
381
|
-
ref: input.ref,
|
|
382
|
-
now: input.now,
|
|
383
|
-
...input.ttlDays === void 0 ? {} : { ttlDays: input.ttlDays }
|
|
384
|
-
});
|
|
385
|
-
const marked = entity.onSent(current.body);
|
|
386
|
-
const written = marked === current.body ? { entity: name, number: input.ref, body: current.body } : await write(ctx, { entity: name, number: input.ref, body: marked }, sendName);
|
|
387
|
-
const words = mailWords(input.ref);
|
|
388
|
-
await sendMail({
|
|
389
|
-
to: input.to,
|
|
390
|
-
subject: words.subject,
|
|
391
|
-
text: mailText(words.opening, link.url, link.ttlDays)
|
|
392
|
-
});
|
|
393
|
-
return { ...written, to: input.to, url: link.url, expiresAt: link.expiresAt };
|
|
394
|
-
},
|
|
395
|
-
{
|
|
396
|
-
announce: ({ to, url, expiresAt, ...written }) => announce({ kind: "sent", written, to, url, expiresAt }),
|
|
397
|
-
execution: "durable",
|
|
398
|
-
idempotent: (input) => `${sendName}:${input.ref}:${input.to}`,
|
|
399
|
-
input: typed(
|
|
400
|
-
objectOf({
|
|
401
|
-
now: positiveInt,
|
|
402
|
-
ref: nonEmptyString,
|
|
403
|
-
to: nonEmptyString,
|
|
404
|
-
ttlDays: optional(positiveInt)
|
|
405
|
-
})
|
|
406
|
-
)
|
|
407
|
-
}
|
|
408
|
-
);
|
|
409
|
-
const convertName = `${name}.convert`;
|
|
410
|
-
const convert = (0, import_workflows.createWorkflow)(
|
|
411
|
-
convertName,
|
|
412
|
-
async (input, ctx) => {
|
|
413
|
-
const conversion = effects.conversion;
|
|
414
|
-
if (conversion === void 0) {
|
|
415
|
-
throw new ConversionRefused({
|
|
416
|
-
entity: name,
|
|
417
|
-
message: `converting is not something ${article} does`,
|
|
418
|
-
ref: input.ref
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
const source = await stored(ctx, input);
|
|
422
|
-
const refusal = conversion.refuse(source.body);
|
|
423
|
-
if (refusal !== null) {
|
|
424
|
-
throw new ConversionRefused({
|
|
425
|
-
entity: name,
|
|
426
|
-
message: `${input.ref} ${refusal}`,
|
|
427
|
-
ref: input.ref
|
|
428
|
-
});
|
|
429
|
-
}
|
|
430
|
-
await refuseTaken(ctx, { ref: input.ref, entity: conversion.to.name });
|
|
431
|
-
await ports.door(ctx, conversion.to.name).commit({
|
|
432
|
-
actor: actorOf(ctx, convertName),
|
|
433
|
-
body: conversion.bodyFor(source.body, input.ref),
|
|
434
|
-
ref: input.ref
|
|
435
|
-
});
|
|
436
|
-
await write(
|
|
437
|
-
ctx,
|
|
438
|
-
{
|
|
439
|
-
entity: name,
|
|
440
|
-
number: input.ref,
|
|
441
|
-
body: conversion.markSource(source.body, input.ref)
|
|
442
|
-
},
|
|
443
|
-
convertName
|
|
444
|
-
);
|
|
445
|
-
return { entity: conversion.to.name, number: input.ref };
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
announce: (converted) => announce({ kind: "converted", number: converted.number, to: converted.entity }),
|
|
449
|
-
input: refInput
|
|
450
|
-
}
|
|
451
|
-
);
|
|
452
|
-
const duplicateName = `${name}.duplicate`;
|
|
453
|
-
const duplicate = (0, import_workflows.createWorkflow)(
|
|
454
|
-
duplicateName,
|
|
455
|
-
async (input, ctx) => {
|
|
456
|
-
await guard(ctx);
|
|
457
|
-
const current = await stored(ctx, input);
|
|
458
|
-
const body = entity.copy(current.body);
|
|
459
|
-
const minted = await refFor(ctx, input.targetRef, body);
|
|
460
|
-
const written = await write(ctx, { entity: name, number: minted.ref, body }, duplicateName);
|
|
461
|
-
return { ...written, minted: minted.minted };
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
announce: ({ minted, ...written }) => announce({ kind: "created", written, minted }),
|
|
465
|
-
input: typed(
|
|
466
|
-
objectOf({ ref: nonEmptyString, targetRef: optional(nonEmptyString) })
|
|
467
|
-
)
|
|
468
|
-
}
|
|
469
|
-
);
|
|
470
|
-
const share = (0, import_workflows.createWorkflow)(
|
|
471
|
-
`${name}.share`,
|
|
472
|
-
async (input, ctx) => {
|
|
473
|
-
await stored(ctx, input);
|
|
474
|
-
const link = await shareLink({
|
|
475
|
-
ref: input.ref,
|
|
476
|
-
now: input.now,
|
|
477
|
-
...input.ttlDays === void 0 ? {} : { ttlDays: input.ttlDays }
|
|
478
|
-
});
|
|
479
|
-
return { number: input.ref, token: link.token, url: link.url, expiresAt: link.expiresAt };
|
|
480
|
-
},
|
|
481
|
-
{
|
|
482
|
-
announce: (link) => announce({ kind: "shared", number: link.number, url: link.url, expiresAt: link.expiresAt }),
|
|
483
|
-
input: typed(
|
|
484
|
-
objectOf({ now: positiveInt, ref: nonEmptyString, ttlDays: optional(positiveInt) })
|
|
485
|
-
)
|
|
486
|
-
}
|
|
487
|
-
);
|
|
488
|
-
return { entity, create, save, setStatus, remove, send, convert, duplicate, share };
|
|
489
37
|
};
|
|
490
38
|
|
|
491
|
-
// src/workflows
|
|
492
|
-
var
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
NumberingRefused,
|
|
510
|
-
TRANSITION_REFUSED_TAG,
|
|
511
|
-
TransitionRefused,
|
|
512
|
-
documentWorkflows
|
|
39
|
+
// src/workflows.ts
|
|
40
|
+
var exports_workflows = {};
|
|
41
|
+
__export(exports_workflows, {
|
|
42
|
+
CONVERSION_REFUSED_TAG: () => import_refusals.CONVERSION_REFUSED_TAG,
|
|
43
|
+
ConversionRefused: () => import_refusals.ConversionRefused,
|
|
44
|
+
DOCUMENT_NOT_FOUND_TAG: () => import_refusals.DOCUMENT_NOT_FOUND_TAG,
|
|
45
|
+
DOCUMENT_NOT_REMOVABLE_TAG: () => import_refusals.DOCUMENT_NOT_REMOVABLE_TAG,
|
|
46
|
+
DOCUMENT_TAKEN_TAG: () => import_refusals.DOCUMENT_TAKEN_TAG,
|
|
47
|
+
DocumentNotFound: () => import_refusals.DocumentNotFound,
|
|
48
|
+
DocumentNotRemovable: () => import_refusals.DocumentNotRemovable,
|
|
49
|
+
DocumentTaken: () => import_refusals.DocumentTaken,
|
|
50
|
+
MAIL_UNDELIVERED_TAG: () => import_ports.MAIL_UNDELIVERED_TAG,
|
|
51
|
+
MailUndelivered: () => import_ports.MailUndelivered,
|
|
52
|
+
NUMBERING_REFUSED_TAG: () => import_refusals.NUMBERING_REFUSED_TAG,
|
|
53
|
+
NumberingRefused: () => import_refusals.NumberingRefused,
|
|
54
|
+
TRANSITION_REFUSED_TAG: () => import_refusals.TRANSITION_REFUSED_TAG,
|
|
55
|
+
TransitionRefused: () => import_refusals.TransitionRefused,
|
|
56
|
+
documentWorkflows: () => import_document_workflows.documentWorkflows
|
|
513
57
|
});
|
|
58
|
+
module.exports = __toCommonJS(exports_workflows);
|
|
59
|
+
var import_document_workflows = require("./workflows/document-workflows.cjs");
|
|
60
|
+
var import_ports = require("./workflows/ports.cjs");
|
|
61
|
+
var import_refusals = require("./workflows/refusals.cjs");
|