@geonosis/document 0.9.1 → 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 +10 -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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The archive's own key convention: `<tenant>/<entity>/<lineage>/<version>.json` — one object per
|
|
3
|
+
* revision, named so a lineage's own history sits together and a new lineage (`succeed`) never
|
|
4
|
+
* collides with the one it replaced.
|
|
5
|
+
*/
|
|
6
|
+
export type ArchivePort = {
|
|
7
|
+
head: (key: string) => Promise<{
|
|
8
|
+
hash: string;
|
|
9
|
+
} | null>;
|
|
10
|
+
put: (key: string, bytes: Uint8Array, meta: {
|
|
11
|
+
hash: string;
|
|
12
|
+
immutable: true;
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
/** A trusted third party's timestamp over a hash — never implemented here, only declared. */
|
|
16
|
+
export type TimestampPort = {
|
|
17
|
+
stamp: (hash: string) => Promise<{
|
|
18
|
+
at: number;
|
|
19
|
+
token: Uint8Array;
|
|
20
|
+
}>;
|
|
21
|
+
};
|
|
22
|
+
export type LinkVerifierPort = {
|
|
23
|
+
verify: (token: string) => Promise<{
|
|
24
|
+
entity: string;
|
|
25
|
+
exp: number;
|
|
26
|
+
org: string;
|
|
27
|
+
ref: string;
|
|
28
|
+
} | null>;
|
|
29
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,173 @@
|
|
|
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/core/schema.ts
|
|
40
|
+
var exports_schema = {};
|
|
41
|
+
__export(exports_schema, {
|
|
42
|
+
arrayOf: () => arrayOf,
|
|
43
|
+
booleanSchema: () => booleanSchema,
|
|
44
|
+
enumOf: () => enumOf,
|
|
45
|
+
literalOf: () => literalOf,
|
|
46
|
+
merge: () => merge,
|
|
47
|
+
nonEmptyString: () => nonEmptyString,
|
|
48
|
+
nullable: () => nullable,
|
|
49
|
+
numberSchema: () => numberSchema,
|
|
50
|
+
objectOf: () => objectOf,
|
|
51
|
+
optional: () => optional,
|
|
52
|
+
positiveInt: () => positiveInt,
|
|
53
|
+
stringSchema: () => stringSchema,
|
|
54
|
+
unknownSchema: () => unknownSchema,
|
|
55
|
+
validate: () => validate
|
|
56
|
+
});
|
|
57
|
+
module.exports = __toCommonJS(exports_schema);
|
|
58
|
+
var VENDOR = "geonosis-document";
|
|
59
|
+
var isString = (value) => typeof value === "string";
|
|
60
|
+
var isNumber = (value) => typeof value === "number";
|
|
61
|
+
var scalar = (test, message) => ({
|
|
62
|
+
"~standard": {
|
|
63
|
+
validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
|
|
64
|
+
vendor: VENDOR,
|
|
65
|
+
version: 1
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
var stringSchema = scalar(isString, "expected a string");
|
|
69
|
+
var numberSchema = scalar(isNumber, "expected a number");
|
|
70
|
+
var booleanSchema = scalar((value) => typeof value === "boolean", "expected a boolean");
|
|
71
|
+
var literalOf = (literal) => scalar((value) => value === literal, `expected exactly ${JSON.stringify(literal)}`);
|
|
72
|
+
var unknownSchema = {
|
|
73
|
+
"~standard": { validate: (input) => ({ value: input }), vendor: VENDOR, version: 1 }
|
|
74
|
+
};
|
|
75
|
+
var syncResult = (schema, input) => {
|
|
76
|
+
const result = schema["~standard"].validate(input);
|
|
77
|
+
if (result instanceof Promise) {
|
|
78
|
+
throw new Error("a document surface schema validates synchronously; an async Standard Schema cannot back a row");
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
var optional = (inner) => ({
|
|
83
|
+
"~standard": {
|
|
84
|
+
validate: (input) => input === undefined ? { value: undefined } : syncResult(inner, input),
|
|
85
|
+
vendor: VENDOR,
|
|
86
|
+
version: 1
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
var nullable = (inner) => ({
|
|
90
|
+
"~standard": {
|
|
91
|
+
validate: (input) => input === null ? { value: null } : syncResult(inner, input),
|
|
92
|
+
vendor: VENDOR,
|
|
93
|
+
version: 1
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
var arrayOf = (item) => ({
|
|
97
|
+
"~standard": {
|
|
98
|
+
validate: (input) => {
|
|
99
|
+
if (!Array.isArray(input))
|
|
100
|
+
return { issues: [{ message: "expected an array" }] };
|
|
101
|
+
const value = [];
|
|
102
|
+
const issues = [];
|
|
103
|
+
input.forEach((one, at) => {
|
|
104
|
+
const result = syncResult(item, one);
|
|
105
|
+
if (result.issues !== undefined) {
|
|
106
|
+
issues.push(...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] })));
|
|
107
|
+
} else {
|
|
108
|
+
value.push(result.value);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return issues.length > 0 ? { issues } : { value };
|
|
112
|
+
},
|
|
113
|
+
vendor: VENDOR,
|
|
114
|
+
version: 1
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
var merge = (schemas) => ({
|
|
118
|
+
"~standard": {
|
|
119
|
+
validate: (input) => {
|
|
120
|
+
let value = {};
|
|
121
|
+
const issues = [];
|
|
122
|
+
for (const schema of schemas) {
|
|
123
|
+
const result = syncResult(schema, input);
|
|
124
|
+
if (result.issues !== undefined)
|
|
125
|
+
issues.push(...result.issues);
|
|
126
|
+
else
|
|
127
|
+
value = { ...value, ...result.value };
|
|
128
|
+
}
|
|
129
|
+
return issues.length > 0 ? { issues } : { value };
|
|
130
|
+
},
|
|
131
|
+
vendor: VENDOR,
|
|
132
|
+
version: 1
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
var nonEmptyString = scalar((value) => typeof value === "string" && value.length > 0, "expected a non-empty string");
|
|
136
|
+
var positiveInt = scalar((value) => Number.isInteger(value) && value > 0, "expected a positive integer");
|
|
137
|
+
var validate = async (schema, input) => {
|
|
138
|
+
const result = await schema["~standard"].validate(input);
|
|
139
|
+
if (result.issues !== undefined) {
|
|
140
|
+
throw new Error(result.issues.map((issue) => {
|
|
141
|
+
const path = (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
142
|
+
return path === "" ? issue.message : `${path}: ${issue.message}`;
|
|
143
|
+
}).join("; "));
|
|
144
|
+
}
|
|
145
|
+
return result.value;
|
|
146
|
+
};
|
|
147
|
+
var enumOf = (values) => scalar((value) => typeof value === "string" && values.includes(value), `expected one of ${values.map((value) => JSON.stringify(value)).join(", ")}`);
|
|
148
|
+
var settle = (fields) => {
|
|
149
|
+
const value = {};
|
|
150
|
+
const issues = [];
|
|
151
|
+
for (const [key, result] of fields) {
|
|
152
|
+
if (result.issues !== undefined) {
|
|
153
|
+
issues.push(...result.issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] })));
|
|
154
|
+
} else if (result.value !== undefined) {
|
|
155
|
+
value[key] = result.value;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return issues.length > 0 ? { issues } : { value };
|
|
159
|
+
};
|
|
160
|
+
var objectOf = (shape) => ({
|
|
161
|
+
"~standard": {
|
|
162
|
+
validate: (input) => {
|
|
163
|
+
if (input === null || typeof input !== "object") {
|
|
164
|
+
return { issues: [{ message: "expected an object" }] };
|
|
165
|
+
}
|
|
166
|
+
const record = input;
|
|
167
|
+
const fields = Object.entries(shape).map(([key, schema]) => [key, schema["~standard"].validate(record[key])]);
|
|
168
|
+
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(settle) : settle(fields);
|
|
169
|
+
},
|
|
170
|
+
vendor: VENDOR,
|
|
171
|
+
version: 1
|
|
172
|
+
}
|
|
173
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
/**
|
|
3
|
+
* The three builders a validator library supplies so the surface and the workflows stay library-free
|
|
4
|
+
* (#383) while the union/enum/object they derive are still real schemas of THAT library — the one
|
|
5
|
+
* place a consumer's zod enters `@geonosis/document` is through this adapter, never a dependency.
|
|
6
|
+
*/
|
|
7
|
+
export type SchemaAdapter = {
|
|
8
|
+
enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
|
|
9
|
+
object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
|
|
10
|
+
union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
|
|
11
|
+
};
|
|
12
|
+
export declare const stringSchema: StandardSchemaV1<unknown, string>;
|
|
13
|
+
export declare const numberSchema: StandardSchemaV1<unknown, number>;
|
|
14
|
+
export declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
|
|
15
|
+
export declare const literalOf: <Value extends boolean | string>(literal: Value) => StandardSchemaV1<unknown, Value>;
|
|
16
|
+
/** A passthrough for a shape this ticket declares but does not itself narrow further. */
|
|
17
|
+
export declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
|
|
18
|
+
export declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
|
|
19
|
+
export declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
|
|
20
|
+
export declare const arrayOf: <Output>(item: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output[]>;
|
|
21
|
+
/** Every schema's own issues, folded into one — the merged VALUE is every schema's fields, spread. */
|
|
22
|
+
export declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
|
|
23
|
+
export declare const nonEmptyString: StandardSchemaV1<unknown, string>;
|
|
24
|
+
export declare const positiveInt: StandardSchemaV1<unknown, number>;
|
|
25
|
+
/** One value through one schema, whichever library wrote it; the issues are the refusal's text. */
|
|
26
|
+
export declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
|
|
27
|
+
export declare const enumOf: <Value extends string>(values: readonly Value[]) => StandardSchemaV1<unknown, Value>;
|
|
28
|
+
/**
|
|
29
|
+
* An object of named fields, each through its own schema — the one builder a workflow input needs
|
|
30
|
+
* that the adapter is not asked for, since a run's input is refused by the engine and never rendered
|
|
31
|
+
* by a host's own library. Async when a field's schema is; unknown keys are dropped.
|
|
32
|
+
*/
|
|
33
|
+
export declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
/**
|
|
3
|
+
* The three builders a validator library supplies so the surface and the workflows stay library-free
|
|
4
|
+
* (#383) while the union/enum/object they derive are still real schemas of THAT library — the one
|
|
5
|
+
* place a consumer's zod enters `@geonosis/document` is through this adapter, never a dependency.
|
|
6
|
+
*/
|
|
7
|
+
export type SchemaAdapter = {
|
|
8
|
+
enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
|
|
9
|
+
object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
|
|
10
|
+
union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
|
|
11
|
+
};
|
|
12
|
+
export declare const stringSchema: StandardSchemaV1<unknown, string>;
|
|
13
|
+
export declare const numberSchema: StandardSchemaV1<unknown, number>;
|
|
14
|
+
export declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
|
|
15
|
+
export declare const literalOf: <Value extends boolean | string>(literal: Value) => StandardSchemaV1<unknown, Value>;
|
|
16
|
+
/** A passthrough for a shape this ticket declares but does not itself narrow further. */
|
|
17
|
+
export declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
|
|
18
|
+
export declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
|
|
19
|
+
export declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
|
|
20
|
+
export declare const arrayOf: <Output>(item: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output[]>;
|
|
21
|
+
/** Every schema's own issues, folded into one — the merged VALUE is every schema's fields, spread. */
|
|
22
|
+
export declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
|
|
23
|
+
export declare const nonEmptyString: StandardSchemaV1<unknown, string>;
|
|
24
|
+
export declare const positiveInt: StandardSchemaV1<unknown, number>;
|
|
25
|
+
/** One value through one schema, whichever library wrote it; the issues are the refusal's text. */
|
|
26
|
+
export declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
|
|
27
|
+
export declare const enumOf: <Value extends string>(values: readonly Value[]) => StandardSchemaV1<unknown, Value>;
|
|
28
|
+
/**
|
|
29
|
+
* An object of named fields, each through its own schema — the one builder a workflow input needs
|
|
30
|
+
* that the adapter is not asked for, since a run's input is refused by the engine and never rendered
|
|
31
|
+
* by a host's own library. Async when a field's schema is; unknown keys are dropped.
|
|
32
|
+
*/
|
|
33
|
+
export declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
|
|
@@ -11,29 +11,21 @@ var scalar = (test, message) => ({
|
|
|
11
11
|
});
|
|
12
12
|
var stringSchema = scalar(isString, "expected a string");
|
|
13
13
|
var numberSchema = scalar(isNumber, "expected a number");
|
|
14
|
-
var booleanSchema = scalar(
|
|
15
|
-
|
|
16
|
-
"expected a boolean"
|
|
17
|
-
);
|
|
18
|
-
var literalOf = (literal) => scalar(
|
|
19
|
-
(value) => value === literal,
|
|
20
|
-
`expected exactly ${JSON.stringify(literal)}`
|
|
21
|
-
);
|
|
14
|
+
var booleanSchema = scalar((value) => typeof value === "boolean", "expected a boolean");
|
|
15
|
+
var literalOf = (literal) => scalar((value) => value === literal, `expected exactly ${JSON.stringify(literal)}`);
|
|
22
16
|
var unknownSchema = {
|
|
23
17
|
"~standard": { validate: (input) => ({ value: input }), vendor: VENDOR, version: 1 }
|
|
24
18
|
};
|
|
25
19
|
var syncResult = (schema, input) => {
|
|
26
20
|
const result = schema["~standard"].validate(input);
|
|
27
21
|
if (result instanceof Promise) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
"a document surface schema validates synchronously; an async Standard Schema cannot back a row"
|
|
30
|
-
);
|
|
22
|
+
throw new Error("a document surface schema validates synchronously; an async Standard Schema cannot back a row");
|
|
31
23
|
}
|
|
32
24
|
return result;
|
|
33
25
|
};
|
|
34
26
|
var optional = (inner) => ({
|
|
35
27
|
"~standard": {
|
|
36
|
-
validate: (input) => input ===
|
|
28
|
+
validate: (input) => input === undefined ? { value: undefined } : syncResult(inner, input),
|
|
37
29
|
vendor: VENDOR,
|
|
38
30
|
version: 1
|
|
39
31
|
}
|
|
@@ -48,15 +40,14 @@ var nullable = (inner) => ({
|
|
|
48
40
|
var arrayOf = (item) => ({
|
|
49
41
|
"~standard": {
|
|
50
42
|
validate: (input) => {
|
|
51
|
-
if (!Array.isArray(input))
|
|
43
|
+
if (!Array.isArray(input))
|
|
44
|
+
return { issues: [{ message: "expected an array" }] };
|
|
52
45
|
const value = [];
|
|
53
46
|
const issues = [];
|
|
54
47
|
input.forEach((one, at) => {
|
|
55
48
|
const result = syncResult(item, one);
|
|
56
|
-
if (result.issues !==
|
|
57
|
-
issues.push(
|
|
58
|
-
...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] }))
|
|
59
|
-
);
|
|
49
|
+
if (result.issues !== undefined) {
|
|
50
|
+
issues.push(...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] })));
|
|
60
51
|
} else {
|
|
61
52
|
value.push(result.value);
|
|
62
53
|
}
|
|
@@ -74,8 +65,10 @@ var merge = (schemas) => ({
|
|
|
74
65
|
const issues = [];
|
|
75
66
|
for (const schema of schemas) {
|
|
76
67
|
const result = syncResult(schema, input);
|
|
77
|
-
if (result.issues !==
|
|
78
|
-
|
|
68
|
+
if (result.issues !== undefined)
|
|
69
|
+
issues.push(...result.issues);
|
|
70
|
+
else
|
|
71
|
+
value = { ...value, ...result.value };
|
|
79
72
|
}
|
|
80
73
|
return issues.length > 0 ? { issues } : { value };
|
|
81
74
|
},
|
|
@@ -83,39 +76,26 @@ var merge = (schemas) => ({
|
|
|
83
76
|
version: 1
|
|
84
77
|
}
|
|
85
78
|
});
|
|
86
|
-
var nonEmptyString = scalar(
|
|
87
|
-
|
|
88
|
-
"expected a non-empty string"
|
|
89
|
-
);
|
|
90
|
-
var positiveInt = scalar(
|
|
91
|
-
(value) => Number.isInteger(value) && value > 0,
|
|
92
|
-
"expected a positive integer"
|
|
93
|
-
);
|
|
79
|
+
var nonEmptyString = scalar((value) => typeof value === "string" && value.length > 0, "expected a non-empty string");
|
|
80
|
+
var positiveInt = scalar((value) => Number.isInteger(value) && value > 0, "expected a positive integer");
|
|
94
81
|
var validate = async (schema, input) => {
|
|
95
82
|
const result = await schema["~standard"].validate(input);
|
|
96
|
-
if (result.issues !==
|
|
97
|
-
throw new Error(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}).join("; ")
|
|
102
|
-
);
|
|
83
|
+
if (result.issues !== undefined) {
|
|
84
|
+
throw new Error(result.issues.map((issue) => {
|
|
85
|
+
const path = (issue.path ?? []).map((segment) => String(typeof segment === "object" ? segment.key : segment)).join(".");
|
|
86
|
+
return path === "" ? issue.message : `${path}: ${issue.message}`;
|
|
87
|
+
}).join("; "));
|
|
103
88
|
}
|
|
104
89
|
return result.value;
|
|
105
90
|
};
|
|
106
|
-
var enumOf = (values) => scalar(
|
|
107
|
-
(value) => typeof value === "string" && values.includes(value),
|
|
108
|
-
`expected one of ${values.map((value) => JSON.stringify(value)).join(", ")}`
|
|
109
|
-
);
|
|
91
|
+
var enumOf = (values) => scalar((value) => typeof value === "string" && values.includes(value), `expected one of ${values.map((value) => JSON.stringify(value)).join(", ")}`);
|
|
110
92
|
var settle = (fields) => {
|
|
111
93
|
const value = {};
|
|
112
94
|
const issues = [];
|
|
113
95
|
for (const [key, result] of fields) {
|
|
114
|
-
if (result.issues !==
|
|
115
|
-
issues.push(
|
|
116
|
-
|
|
117
|
-
);
|
|
118
|
-
} else if (result.value !== void 0) {
|
|
96
|
+
if (result.issues !== undefined) {
|
|
97
|
+
issues.push(...result.issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] })));
|
|
98
|
+
} else if (result.value !== undefined) {
|
|
119
99
|
value[key] = result.value;
|
|
120
100
|
}
|
|
121
101
|
}
|
|
@@ -128,44 +108,26 @@ var objectOf = (shape) => ({
|
|
|
128
108
|
return { issues: [{ message: "expected an object" }] };
|
|
129
109
|
}
|
|
130
110
|
const record = input;
|
|
131
|
-
const fields = Object.entries(shape).map(
|
|
132
|
-
|
|
133
|
-
);
|
|
134
|
-
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(
|
|
135
|
-
settle
|
|
136
|
-
) : settle(fields);
|
|
111
|
+
const fields = Object.entries(shape).map(([key, schema]) => [key, schema["~standard"].validate(record[key])]);
|
|
112
|
+
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(settle) : settle(fields);
|
|
137
113
|
},
|
|
138
114
|
vendor: VENDOR,
|
|
139
115
|
version: 1
|
|
140
116
|
}
|
|
141
117
|
});
|
|
142
|
-
|
|
143
|
-
// src/core/actor.ts
|
|
144
|
-
var SYSTEM_PREFIX = "system:";
|
|
145
|
-
var systemActor = (name) => `${SYSTEM_PREFIX}${name}`;
|
|
146
|
-
var isSystemActor = (actor) => actor.startsWith(SYSTEM_PREFIX);
|
|
147
|
-
|
|
148
|
-
// src/core/status.ts
|
|
149
|
-
var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
|
|
150
|
-
var isTerminalStatus = (machine, status) => machine.transitions[status].length === 0;
|
|
151
|
-
|
|
152
118
|
export {
|
|
153
|
-
|
|
154
|
-
numberSchema,
|
|
119
|
+
arrayOf,
|
|
155
120
|
booleanSchema,
|
|
121
|
+
enumOf,
|
|
156
122
|
literalOf,
|
|
157
|
-
unknownSchema,
|
|
158
|
-
optional,
|
|
159
|
-
nullable,
|
|
160
|
-
arrayOf,
|
|
161
123
|
merge,
|
|
162
124
|
nonEmptyString,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
enumOf,
|
|
125
|
+
nullable,
|
|
126
|
+
numberSchema,
|
|
166
127
|
objectOf,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
128
|
+
optional,
|
|
129
|
+
positiveInt,
|
|
130
|
+
stringSchema,
|
|
131
|
+
unknownSchema,
|
|
132
|
+
validate
|
|
171
133
|
};
|
|
@@ -0,0 +1,47 @@
|
|
|
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/core/status.ts
|
|
40
|
+
var exports_status = {};
|
|
41
|
+
__export(exports_status, {
|
|
42
|
+
canTransition: () => canTransition,
|
|
43
|
+
isTerminalStatus: () => isTerminalStatus
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(exports_status);
|
|
46
|
+
var canTransition = (machine, from, to) => machine.transitions[from].includes(to);
|
|
47
|
+
var isTerminalStatus = (machine, status) => machine.transitions[status].length === 0;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A named status machine: every status it declares, and what each may move to. */
|
|
2
|
+
export type DocumentStatusMachine<Status extends string> = {
|
|
3
|
+
statuses: readonly Status[];
|
|
4
|
+
initial: Status;
|
|
5
|
+
transitions: Readonly<Record<Status, readonly Status[]>>;
|
|
6
|
+
};
|
|
7
|
+
export declare const canTransition: <Status extends string>(machine: DocumentStatusMachine<Status>, from: Status, to: Status) => boolean;
|
|
8
|
+
export declare const isTerminalStatus: <Status extends string>(machine: DocumentStatusMachine<Status>, status: Status) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A named status machine: every status it declares, and what each may move to. */
|
|
2
|
+
export type DocumentStatusMachine<Status extends string> = {
|
|
3
|
+
statuses: readonly Status[];
|
|
4
|
+
initial: Status;
|
|
5
|
+
transitions: Readonly<Record<Status, readonly Status[]>>;
|
|
6
|
+
};
|
|
7
|
+
export declare const canTransition: <Status extends string>(machine: DocumentStatusMachine<Status>, from: Status, to: Status) => boolean;
|
|
8
|
+
export declare const isTerminalStatus: <Status extends string>(machine: DocumentStatusMachine<Status>, status: Status) => boolean;
|