@geonosis/document 0.9.3 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +78 -13
- package/dist/core/actor.d.cts +0 -1
- package/dist/core/actor.d.ts +0 -1
- package/dist/core/body-version.d.cts +0 -9
- package/dist/core/body-version.d.ts +0 -9
- package/dist/core/canonical.cjs +2 -3
- package/dist/core/canonical.d.cts +0 -4
- package/dist/core/canonical.d.ts +0 -4
- package/dist/core/canonical.js +2 -3
- package/dist/core/document.cjs +28 -25
- package/dist/core/document.d.cts +3 -22
- package/dist/core/document.d.ts +3 -22
- package/dist/core/document.js +28 -25
- package/dist/core/entities.d.cts +0 -19
- package/dist/core/entities.d.ts +0 -19
- package/dist/core/naming.d.cts +0 -5
- package/dist/core/naming.d.ts +0 -5
- package/dist/core/numbering.d.cts +0 -4
- package/dist/core/numbering.d.ts +0 -4
- package/dist/core/ports.d.cts +0 -6
- package/dist/core/ports.d.ts +0 -6
- package/dist/core/schema.cjs +44 -76
- package/dist/core/schema.d.cts +1 -13
- package/dist/core/schema.d.ts +1 -13
- package/dist/core/schema.js +44 -76
- package/dist/core/status.d.cts +0 -1
- package/dist/core/status.d.ts +0 -1
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -0
- package/dist/store/ddl.cjs +35 -38
- package/dist/store/ddl.d.cts +6 -6
- package/dist/store/ddl.d.ts +6 -6
- package/dist/store/ddl.js +37 -39
- package/dist/store/hash.d.cts +0 -1
- package/dist/store/hash.d.ts +0 -1
- package/dist/store/number-for.cjs +52 -0
- package/dist/store/number-for.d.cts +11 -0
- package/dist/store/number-for.d.ts +11 -0
- package/dist/store/number-for.js +12 -0
- package/dist/store/store.cjs +188 -162
- package/dist/store/store.d.cts +57 -16
- package/dist/store/store.d.ts +57 -16
- package/dist/store/store.js +190 -163
- package/dist/store.cjs +2 -0
- package/dist/store.d.cts +3 -2
- package/dist/store.d.ts +3 -2
- package/dist/store.js +2 -0
- package/dist/surface/table.cjs +129 -66
- package/dist/surface/table.d.cts +20 -28
- package/dist/surface/table.d.ts +20 -28
- package/dist/surface/table.js +132 -66
- package/dist/workflows/bindings.cjs +48 -0
- package/dist/workflows/bindings.d.cts +15 -0
- package/dist/workflows/bindings.d.ts +15 -0
- package/dist/workflows/bindings.js +10 -0
- package/dist/workflows/document-workflows.cjs +29 -40
- package/dist/workflows/document-workflows.d.cts +0 -12
- package/dist/workflows/document-workflows.d.ts +0 -12
- package/dist/workflows/document-workflows.js +29 -40
- package/dist/workflows/effects.d.cts +0 -12
- package/dist/workflows/effects.d.ts +0 -12
- package/dist/workflows/ports.d.cts +0 -17
- package/dist/workflows/ports.d.ts +0 -17
- package/dist/workflows/refusals.cjs +30 -0
- package/dist/workflows/refusals.d.cts +37 -9
- package/dist/workflows/refusals.d.ts +37 -9
- package/dist/workflows/refusals.js +30 -0
- package/dist/workflows/shared.cjs +93 -0
- package/dist/workflows/shared.d.cts +28 -0
- package/dist/workflows/shared.d.ts +28 -0
- package/dist/workflows/shared.js +60 -0
- package/dist/workflows.cjs +16 -1
- package/dist/workflows.d.cts +3 -1
- package/dist/workflows.d.ts +3 -1
- package/dist/workflows.js +31 -1
- package/package.json +4 -4
package/dist/core/document.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// src/core/document.ts
|
|
2
|
+
import { schemaOf } from "./schema.js";
|
|
3
|
+
var LEAP_FEBRUARY_29 = "(?:\\d\\d(?:0[48]|[2468][048]|[13579][26])|(?:[02468][048]|[13579][26])00)-02-29";
|
|
4
|
+
var CALENDAR_DATE = new RegExp(`^(?!0000)(?:\\d{4}-(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|\\d{4}-(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|\\d{4}-02-(?:0[1-9]|1\\d|2[0-8])|${LEAP_FEBRUARY_29})$`);
|
|
2
5
|
var fieldPatterns = {
|
|
3
|
-
calendarDate:
|
|
6
|
+
calendarDate: CALENDAR_DATE,
|
|
4
7
|
decimal: /^-?\d+(?:\.\d+)?$/
|
|
5
8
|
};
|
|
6
9
|
var FIELD_CHECKS = {
|
|
@@ -24,30 +27,25 @@ var FIELD_CHECKS = {
|
|
|
24
27
|
};
|
|
25
28
|
var validatorOf = (fields, options) => {
|
|
26
29
|
const nullable = options?.nullable ?? false;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return { issues: [{ message: "expected an object" }] };
|
|
32
|
-
}
|
|
33
|
-
const record = input;
|
|
34
|
-
const issues = [];
|
|
35
|
-
const value = {};
|
|
36
|
-
for (const [key, kind] of Object.entries(fields)) {
|
|
37
|
-
const held = record[key];
|
|
38
|
-
value[key] = held;
|
|
39
|
-
if (nullable && held === null)
|
|
40
|
-
continue;
|
|
41
|
-
if (!FIELD_CHECKS[kind].test(held)) {
|
|
42
|
-
issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return issues.length > 0 ? { issues } : { value };
|
|
46
|
-
},
|
|
47
|
-
vendor: "geonosis-document",
|
|
48
|
-
version: 1
|
|
30
|
+
const required = options?.required ?? [];
|
|
31
|
+
return schemaOf((input) => {
|
|
32
|
+
if (input === null || typeof input !== "object") {
|
|
33
|
+
return { issues: [{ message: "expected an object" }] };
|
|
49
34
|
}
|
|
50
|
-
|
|
35
|
+
const record = input;
|
|
36
|
+
const issues = [];
|
|
37
|
+
const value = {};
|
|
38
|
+
for (const [key, kind] of Object.entries(fields)) {
|
|
39
|
+
const held = record[key];
|
|
40
|
+
value[key] = held;
|
|
41
|
+
if (nullable && held === null && !required.includes(key))
|
|
42
|
+
continue;
|
|
43
|
+
if (!FIELD_CHECKS[kind].test(held)) {
|
|
44
|
+
issues.push({ message: FIELD_CHECKS[kind].message, path: [{ key }] });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return issues.length > 0 ? { issues } : { value };
|
|
48
|
+
});
|
|
51
49
|
};
|
|
52
50
|
var parseWith = (schema, input) => {
|
|
53
51
|
const result = schema["~standard"].validate(input);
|
|
@@ -73,7 +71,11 @@ var recordFields = {
|
|
|
73
71
|
createdAt: "int",
|
|
74
72
|
updatedAt: "int"
|
|
75
73
|
};
|
|
76
|
-
var
|
|
74
|
+
var requiredHeadFields = ["status"];
|
|
75
|
+
var headValidator = validatorOf(headFields, {
|
|
76
|
+
nullable: true,
|
|
77
|
+
required: requiredHeadFields
|
|
78
|
+
});
|
|
77
79
|
var recordValidator = validatorOf(recordFields);
|
|
78
80
|
var Document = {
|
|
79
81
|
head: headValidator,
|
|
@@ -92,5 +94,6 @@ export {
|
|
|
92
94
|
fieldPatterns,
|
|
93
95
|
headFields,
|
|
94
96
|
recordFields,
|
|
97
|
+
requiredHeadFields,
|
|
95
98
|
validatorOf
|
|
96
99
|
};
|
package/dist/core/entities.d.cts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { DocumentInstance, InstanceOf } from './document.cjs';
|
|
3
|
-
/**
|
|
4
|
-
* The least a map's value has to be for `documentEntities` to do its own work: a name to check
|
|
5
|
-
* against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
|
|
6
|
-
* caller passed — this is a constraint bound, not the type inference reads back — because a status
|
|
7
|
-
* machine typed to its own narrow union is not assignable to one held at `string`, and widening it
|
|
8
|
-
* here would break every entity's own `withStatus` the moment two of them met in one map.
|
|
9
|
-
*
|
|
10
|
-
* Exported for a layer that composes over the registry's OWN values generically (the store): the
|
|
11
|
-
* same minimal bound, never a second one.
|
|
12
|
-
*/
|
|
13
3
|
export type AnyDocumentEntity = {
|
|
14
4
|
body: StandardSchemaV1;
|
|
15
5
|
card: {
|
|
@@ -18,14 +8,6 @@ export type AnyDocumentEntity = {
|
|
|
18
8
|
name: string;
|
|
19
9
|
view: StandardSchemaV1;
|
|
20
10
|
};
|
|
21
|
-
/**
|
|
22
|
-
* `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
|
|
23
|
-
*
|
|
24
|
-
* A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
|
|
25
|
-
* every entity the registry holds, in one place, typed over the union of the map's own values.
|
|
26
|
-
* Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
|
|
27
|
-
* `names` union is DERIVED from the map's own keys.
|
|
28
|
-
*/
|
|
29
11
|
export declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
|
|
30
12
|
bodies: StandardSchemaV1[];
|
|
31
13
|
cards: StandardSchemaV1[];
|
|
@@ -34,7 +16,6 @@ export declare const documentEntities: <Map extends Readonly<Record<string, AnyD
|
|
|
34
16
|
instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, 'entity' | 'body'> & {
|
|
35
17
|
body: unknown;
|
|
36
18
|
}) => DocumentInstance<Name, InstanceOf<Map[Name]>['body']>;
|
|
37
|
-
/** One answer per entity, keyed by the name its rows carry — total by construction. */
|
|
38
19
|
keyed: <Result>(pick: (entity: Map[keyof Map], name: keyof Map & string) => Result) => { [Name in keyof Map & string]: Result; };
|
|
39
20
|
named: <Name extends keyof Map & string>(name: Name) => Map[Name];
|
|
40
21
|
names: readonly (keyof Map & string)[];
|
package/dist/core/entities.d.ts
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
2
|
import type { DocumentInstance, InstanceOf } from './document.js';
|
|
3
|
-
/**
|
|
4
|
-
* The least a map's value has to be for `documentEntities` to do its own work: a name to check
|
|
5
|
-
* against the key, a body and a card schema to fold over. The FULL entity type stays whatever the
|
|
6
|
-
* caller passed — this is a constraint bound, not the type inference reads back — because a status
|
|
7
|
-
* machine typed to its own narrow union is not assignable to one held at `string`, and widening it
|
|
8
|
-
* here would break every entity's own `withStatus` the moment two of them met in one map.
|
|
9
|
-
*
|
|
10
|
-
* Exported for a layer that composes over the registry's OWN values generically (the store): the
|
|
11
|
-
* same minimal bound, never a second one.
|
|
12
|
-
*/
|
|
13
3
|
export type AnyDocumentEntity = {
|
|
14
4
|
body: StandardSchemaV1;
|
|
15
5
|
card: {
|
|
@@ -18,14 +8,6 @@ export type AnyDocumentEntity = {
|
|
|
18
8
|
name: string;
|
|
19
9
|
view: StandardSchemaV1;
|
|
20
10
|
};
|
|
21
|
-
/**
|
|
22
|
-
* `documentEntities(map)`: every entity that extends `Document`, by the name its rows carry.
|
|
23
|
-
*
|
|
24
|
-
* A per-entity fact is never read off a map a caller fills in per entity — `fold` reads it off
|
|
25
|
-
* every entity the registry holds, in one place, typed over the union of the map's own values.
|
|
26
|
-
* Adding an entity is one `Document.extend` call and one line in the map handed here; the returned
|
|
27
|
-
* `names` union is DERIVED from the map's own keys.
|
|
28
|
-
*/
|
|
29
11
|
export declare const documentEntities: <Map extends Readonly<Record<string, AnyDocumentEntity>>>(map: Map) => {
|
|
30
12
|
bodies: StandardSchemaV1[];
|
|
31
13
|
cards: StandardSchemaV1[];
|
|
@@ -34,7 +16,6 @@ export declare const documentEntities: <Map extends Readonly<Record<string, AnyD
|
|
|
34
16
|
instance: <Name extends keyof Map & string>(name: Name, parts: Omit<InstanceOf<Map[Name]>, 'entity' | 'body'> & {
|
|
35
17
|
body: unknown;
|
|
36
18
|
}) => DocumentInstance<Name, InstanceOf<Map[Name]>['body']>;
|
|
37
|
-
/** One answer per entity, keyed by the name its rows carry — total by construction. */
|
|
38
19
|
keyed: <Result>(pick: (entity: Map[keyof Map], name: keyof Map & string) => Result) => { [Name in keyof Map & string]: Result; };
|
|
39
20
|
named: <Name extends keyof Map & string>(name: Name) => Map[Name];
|
|
40
21
|
names: readonly (keyof Map & string)[];
|
package/dist/core/naming.d.cts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
|
|
2
1
|
export type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
|
|
3
2
|
type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
|
|
4
|
-
/**
|
|
5
|
-
* Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
|
|
6
|
-
* a consumer keys a router map or a path table by them without a cast.
|
|
7
|
-
*/
|
|
8
3
|
export type DocumentIdentifiers<Name extends string> = {
|
|
9
4
|
camel: CamelOf<Name>;
|
|
10
5
|
pascal: Capitalize<CamelOf<Name>>;
|
package/dist/core/naming.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
/** `purchase-order` → `purchaseOrder`, at the type level and at runtime alike. */
|
|
2
1
|
export type CamelOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}${Capitalize<CamelOf<Tail>>}` : Name;
|
|
3
2
|
type SnakeOf<Name extends string> = Name extends `${infer Head}-${infer Tail}` ? `${Head}_${SnakeOf<Tail>}` : Name;
|
|
4
|
-
/**
|
|
5
|
-
* Every spelling a surface needs, derived from one hyphenated entity name — as literal types, so
|
|
6
|
-
* a consumer keys a router map or a path table by them without a cast.
|
|
7
|
-
*/
|
|
8
3
|
export type DocumentIdentifiers<Name extends string> = {
|
|
9
4
|
camel: CamelOf<Name>;
|
|
10
5
|
pascal: Capitalize<CamelOf<Name>>;
|
package/dist/core/numbering.d.ts
CHANGED
package/dist/core/ports.d.cts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
export type ArchivePort = {
|
|
7
2
|
head: (key: string) => Promise<{
|
|
8
3
|
hash: string;
|
|
@@ -12,7 +7,6 @@ export type ArchivePort = {
|
|
|
12
7
|
immutable: true;
|
|
13
8
|
}) => Promise<void>;
|
|
14
9
|
};
|
|
15
|
-
/** A trusted third party's timestamp over a hash — never implemented here, only declared. */
|
|
16
10
|
export type TimestampPort = {
|
|
17
11
|
stamp: (hash: string) => Promise<{
|
|
18
12
|
at: number;
|
package/dist/core/ports.d.ts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
export type ArchivePort = {
|
|
7
2
|
head: (key: string) => Promise<{
|
|
8
3
|
hash: string;
|
|
@@ -12,7 +7,6 @@ export type ArchivePort = {
|
|
|
12
7
|
immutable: true;
|
|
13
8
|
}) => Promise<void>;
|
|
14
9
|
};
|
|
15
|
-
/** A trusted third party's timestamp over a hash — never implemented here, only declared. */
|
|
16
10
|
export type TimestampPort = {
|
|
17
11
|
stamp: (hash: string) => Promise<{
|
|
18
12
|
at: number;
|
package/dist/core/schema.cjs
CHANGED
|
@@ -50,28 +50,26 @@ __export(exports_schema, {
|
|
|
50
50
|
objectOf: () => objectOf,
|
|
51
51
|
optional: () => optional,
|
|
52
52
|
positiveInt: () => positiveInt,
|
|
53
|
+
schemaOf: () => schemaOf,
|
|
53
54
|
stringSchema: () => stringSchema,
|
|
54
55
|
unknownSchema: () => unknownSchema,
|
|
55
56
|
validate: () => validate
|
|
56
57
|
});
|
|
57
58
|
module.exports = __toCommonJS(exports_schema);
|
|
58
59
|
var VENDOR = "geonosis-document";
|
|
60
|
+
var schemaOf = (validate2) => ({
|
|
61
|
+
"~standard": { validate: validate2, vendor: VENDOR, version: 1 }
|
|
62
|
+
});
|
|
59
63
|
var isString = (value) => typeof value === "string";
|
|
60
64
|
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
|
-
});
|
|
65
|
+
var scalar = (test, message) => schemaOf((input) => test(input) ? { value: input } : { issues: [{ message }] });
|
|
68
66
|
var stringSchema = scalar(isString, "expected a string");
|
|
69
67
|
var numberSchema = scalar(isNumber, "expected a number");
|
|
70
68
|
var booleanSchema = scalar((value) => typeof value === "boolean", "expected a boolean");
|
|
71
69
|
var literalOf = (literal) => scalar((value) => value === literal, `expected exactly ${JSON.stringify(literal)}`);
|
|
72
|
-
var unknownSchema = {
|
|
73
|
-
|
|
74
|
-
};
|
|
70
|
+
var unknownSchema = schemaOf((input) => ({
|
|
71
|
+
value: input
|
|
72
|
+
}));
|
|
75
73
|
var syncResult = (schema, input) => {
|
|
76
74
|
const result = schema["~standard"].validate(input);
|
|
77
75
|
if (result instanceof Promise) {
|
|
@@ -79,58 +77,35 @@ var syncResult = (schema, input) => {
|
|
|
79
77
|
}
|
|
80
78
|
return result;
|
|
81
79
|
};
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
}
|
|
80
|
+
var orElse = (inner, absent) => schemaOf((input) => input === absent ? { value: absent } : syncResult(inner, input));
|
|
81
|
+
var optional = (inner) => orElse(inner, undefined);
|
|
82
|
+
var nullable = (inner) => orElse(inner, null);
|
|
83
|
+
var under = (key, issues) => issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] }));
|
|
84
|
+
var arrayOf = (item) => schemaOf((input) => {
|
|
85
|
+
if (!Array.isArray(input))
|
|
86
|
+
return { issues: [{ message: "expected an array" }] };
|
|
87
|
+
const value = [];
|
|
88
|
+
const issues = [];
|
|
89
|
+
input.forEach((one, at) => {
|
|
90
|
+
const result = syncResult(item, one);
|
|
91
|
+
if (result.issues !== undefined)
|
|
92
|
+
issues.push(...under(at, result.issues));
|
|
93
|
+
else
|
|
94
|
+
value.push(result.value);
|
|
95
|
+
});
|
|
96
|
+
return issues.length > 0 ? { issues } : { value };
|
|
116
97
|
});
|
|
117
|
-
var merge = (schemas) => ({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
else
|
|
127
|
-
value = { ...value, ...result.value };
|
|
128
|
-
}
|
|
129
|
-
return issues.length > 0 ? { issues } : { value };
|
|
130
|
-
},
|
|
131
|
-
vendor: VENDOR,
|
|
132
|
-
version: 1
|
|
98
|
+
var merge = (schemas) => schemaOf((input) => {
|
|
99
|
+
let value = {};
|
|
100
|
+
const issues = [];
|
|
101
|
+
for (const schema of schemas) {
|
|
102
|
+
const result = syncResult(schema, input);
|
|
103
|
+
if (result.issues !== undefined)
|
|
104
|
+
issues.push(...result.issues);
|
|
105
|
+
else
|
|
106
|
+
value = { ...value, ...result.value };
|
|
133
107
|
}
|
|
108
|
+
return issues.length > 0 ? { issues } : { value };
|
|
134
109
|
});
|
|
135
110
|
var nonEmptyString = scalar((value) => typeof value === "string" && value.length > 0, "expected a non-empty string");
|
|
136
111
|
var positiveInt = scalar((value) => Number.isInteger(value) && value > 0, "expected a positive integer");
|
|
@@ -149,25 +124,18 @@ var settle = (fields) => {
|
|
|
149
124
|
const value = {};
|
|
150
125
|
const issues = [];
|
|
151
126
|
for (const [key, result] of fields) {
|
|
152
|
-
if (result.issues !== undefined)
|
|
153
|
-
issues.push(...
|
|
154
|
-
|
|
127
|
+
if (result.issues !== undefined)
|
|
128
|
+
issues.push(...under(key, result.issues));
|
|
129
|
+
else if (result.value !== undefined)
|
|
155
130
|
value[key] = result.value;
|
|
156
|
-
}
|
|
157
131
|
}
|
|
158
132
|
return issues.length > 0 ? { issues } : { value };
|
|
159
133
|
};
|
|
160
|
-
var objectOf = (shape) => ({
|
|
161
|
-
"
|
|
162
|
-
|
|
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
|
|
134
|
+
var objectOf = (shape) => schemaOf((input) => {
|
|
135
|
+
if (input === null || typeof input !== "object") {
|
|
136
|
+
return { issues: [{ message: "expected an object" }] };
|
|
172
137
|
}
|
|
138
|
+
const record = input;
|
|
139
|
+
const fields = Object.entries(shape).map(([key, schema]) => [key, schema["~standard"].validate(record[key])]);
|
|
140
|
+
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(settle) : settle(fields);
|
|
173
141
|
});
|
package/dist/core/schema.d.cts
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
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
2
|
export type SchemaAdapter = {
|
|
8
3
|
enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
|
|
9
4
|
object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
|
|
10
5
|
union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
|
|
11
6
|
};
|
|
7
|
+
export declare const schemaOf: <Output>(validate: StandardSchemaV1.Props<unknown, Output>['validate']) => StandardSchemaV1<unknown, Output>;
|
|
12
8
|
export declare const stringSchema: StandardSchemaV1<unknown, string>;
|
|
13
9
|
export declare const numberSchema: StandardSchemaV1<unknown, number>;
|
|
14
10
|
export declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
|
|
15
11
|
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
12
|
export declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
|
|
18
13
|
export declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
|
|
19
14
|
export declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
|
|
20
15
|
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
16
|
export declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
|
|
23
17
|
export declare const nonEmptyString: StandardSchemaV1<unknown, string>;
|
|
24
18
|
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
19
|
export declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
|
|
27
20
|
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
21
|
export declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
|
package/dist/core/schema.d.ts
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
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
2
|
export type SchemaAdapter = {
|
|
8
3
|
enum: (values: readonly string[]) => StandardSchemaV1<unknown, string>;
|
|
9
4
|
object: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1;
|
|
10
5
|
union: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1;
|
|
11
6
|
};
|
|
7
|
+
export declare const schemaOf: <Output>(validate: StandardSchemaV1.Props<unknown, Output>['validate']) => StandardSchemaV1<unknown, Output>;
|
|
12
8
|
export declare const stringSchema: StandardSchemaV1<unknown, string>;
|
|
13
9
|
export declare const numberSchema: StandardSchemaV1<unknown, number>;
|
|
14
10
|
export declare const booleanSchema: StandardSchemaV1<unknown, boolean>;
|
|
15
11
|
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
12
|
export declare const unknownSchema: StandardSchemaV1<unknown, unknown>;
|
|
18
13
|
export declare const optional: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | undefined>;
|
|
19
14
|
export declare const nullable: <Output>(inner: StandardSchemaV1<unknown, Output>) => StandardSchemaV1<unknown, Output | null>;
|
|
20
15
|
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
16
|
export declare const merge: (schemas: readonly StandardSchemaV1[]) => StandardSchemaV1<unknown, Readonly<Record<string, unknown>>>;
|
|
23
17
|
export declare const nonEmptyString: StandardSchemaV1<unknown, string>;
|
|
24
18
|
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
19
|
export declare const validate: <Output>(schema: StandardSchemaV1<unknown, Output>, input: unknown) => Promise<Output>;
|
|
27
20
|
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
21
|
export declare const objectOf: (shape: Readonly<Record<string, StandardSchemaV1>>) => StandardSchemaV1<unknown, Record<string, unknown>>;
|
package/dist/core/schema.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
// src/core/schema.ts
|
|
2
2
|
var VENDOR = "geonosis-document";
|
|
3
|
+
var schemaOf = (validate) => ({
|
|
4
|
+
"~standard": { validate, vendor: VENDOR, version: 1 }
|
|
5
|
+
});
|
|
3
6
|
var isString = (value) => typeof value === "string";
|
|
4
7
|
var isNumber = (value) => typeof value === "number";
|
|
5
|
-
var scalar = (test, message) => ({
|
|
6
|
-
"~standard": {
|
|
7
|
-
validate: (input) => test(input) ? { value: input } : { issues: [{ message }] },
|
|
8
|
-
vendor: VENDOR,
|
|
9
|
-
version: 1
|
|
10
|
-
}
|
|
11
|
-
});
|
|
8
|
+
var scalar = (test, message) => schemaOf((input) => test(input) ? { value: input } : { issues: [{ message }] });
|
|
12
9
|
var stringSchema = scalar(isString, "expected a string");
|
|
13
10
|
var numberSchema = scalar(isNumber, "expected a number");
|
|
14
11
|
var booleanSchema = scalar((value) => typeof value === "boolean", "expected a boolean");
|
|
15
12
|
var literalOf = (literal) => scalar((value) => value === literal, `expected exactly ${JSON.stringify(literal)}`);
|
|
16
|
-
var unknownSchema = {
|
|
17
|
-
|
|
18
|
-
};
|
|
13
|
+
var unknownSchema = schemaOf((input) => ({
|
|
14
|
+
value: input
|
|
15
|
+
}));
|
|
19
16
|
var syncResult = (schema, input) => {
|
|
20
17
|
const result = schema["~standard"].validate(input);
|
|
21
18
|
if (result instanceof Promise) {
|
|
@@ -23,58 +20,35 @@ var syncResult = (schema, input) => {
|
|
|
23
20
|
}
|
|
24
21
|
return result;
|
|
25
22
|
};
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (!Array.isArray(input))
|
|
44
|
-
return { issues: [{ message: "expected an array" }] };
|
|
45
|
-
const value = [];
|
|
46
|
-
const issues = [];
|
|
47
|
-
input.forEach((one, at) => {
|
|
48
|
-
const result = syncResult(item, one);
|
|
49
|
-
if (result.issues !== undefined) {
|
|
50
|
-
issues.push(...result.issues.map((issue) => ({ ...issue, path: [at, ...issue.path ?? []] })));
|
|
51
|
-
} else {
|
|
52
|
-
value.push(result.value);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return issues.length > 0 ? { issues } : { value };
|
|
56
|
-
},
|
|
57
|
-
vendor: VENDOR,
|
|
58
|
-
version: 1
|
|
59
|
-
}
|
|
23
|
+
var orElse = (inner, absent) => schemaOf((input) => input === absent ? { value: absent } : syncResult(inner, input));
|
|
24
|
+
var optional = (inner) => orElse(inner, undefined);
|
|
25
|
+
var nullable = (inner) => orElse(inner, null);
|
|
26
|
+
var under = (key, issues) => issues.map((issue) => ({ ...issue, path: [key, ...issue.path ?? []] }));
|
|
27
|
+
var arrayOf = (item) => schemaOf((input) => {
|
|
28
|
+
if (!Array.isArray(input))
|
|
29
|
+
return { issues: [{ message: "expected an array" }] };
|
|
30
|
+
const value = [];
|
|
31
|
+
const issues = [];
|
|
32
|
+
input.forEach((one, at) => {
|
|
33
|
+
const result = syncResult(item, one);
|
|
34
|
+
if (result.issues !== undefined)
|
|
35
|
+
issues.push(...under(at, result.issues));
|
|
36
|
+
else
|
|
37
|
+
value.push(result.value);
|
|
38
|
+
});
|
|
39
|
+
return issues.length > 0 ? { issues } : { value };
|
|
60
40
|
});
|
|
61
|
-
var merge = (schemas) => ({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
else
|
|
71
|
-
value = { ...value, ...result.value };
|
|
72
|
-
}
|
|
73
|
-
return issues.length > 0 ? { issues } : { value };
|
|
74
|
-
},
|
|
75
|
-
vendor: VENDOR,
|
|
76
|
-
version: 1
|
|
41
|
+
var merge = (schemas) => schemaOf((input) => {
|
|
42
|
+
let value = {};
|
|
43
|
+
const issues = [];
|
|
44
|
+
for (const schema of schemas) {
|
|
45
|
+
const result = syncResult(schema, input);
|
|
46
|
+
if (result.issues !== undefined)
|
|
47
|
+
issues.push(...result.issues);
|
|
48
|
+
else
|
|
49
|
+
value = { ...value, ...result.value };
|
|
77
50
|
}
|
|
51
|
+
return issues.length > 0 ? { issues } : { value };
|
|
78
52
|
});
|
|
79
53
|
var nonEmptyString = scalar((value) => typeof value === "string" && value.length > 0, "expected a non-empty string");
|
|
80
54
|
var positiveInt = scalar((value) => Number.isInteger(value) && value > 0, "expected a positive integer");
|
|
@@ -93,27 +67,20 @@ var settle = (fields) => {
|
|
|
93
67
|
const value = {};
|
|
94
68
|
const issues = [];
|
|
95
69
|
for (const [key, result] of fields) {
|
|
96
|
-
if (result.issues !== undefined)
|
|
97
|
-
issues.push(...
|
|
98
|
-
|
|
70
|
+
if (result.issues !== undefined)
|
|
71
|
+
issues.push(...under(key, result.issues));
|
|
72
|
+
else if (result.value !== undefined)
|
|
99
73
|
value[key] = result.value;
|
|
100
|
-
}
|
|
101
74
|
}
|
|
102
75
|
return issues.length > 0 ? { issues } : { value };
|
|
103
76
|
};
|
|
104
|
-
var objectOf = (shape) => ({
|
|
105
|
-
"
|
|
106
|
-
|
|
107
|
-
if (input === null || typeof input !== "object") {
|
|
108
|
-
return { issues: [{ message: "expected an object" }] };
|
|
109
|
-
}
|
|
110
|
-
const record = input;
|
|
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);
|
|
113
|
-
},
|
|
114
|
-
vendor: VENDOR,
|
|
115
|
-
version: 1
|
|
77
|
+
var objectOf = (shape) => schemaOf((input) => {
|
|
78
|
+
if (input === null || typeof input !== "object") {
|
|
79
|
+
return { issues: [{ message: "expected an object" }] };
|
|
116
80
|
}
|
|
81
|
+
const record = input;
|
|
82
|
+
const fields = Object.entries(shape).map(([key, schema]) => [key, schema["~standard"].validate(record[key])]);
|
|
83
|
+
return fields.some(([, result]) => result instanceof Promise) ? Promise.all(fields.map(async ([key, result]) => [key, await result])).then(settle) : settle(fields);
|
|
117
84
|
});
|
|
118
85
|
export {
|
|
119
86
|
arrayOf,
|
|
@@ -127,6 +94,7 @@ export {
|
|
|
127
94
|
objectOf,
|
|
128
95
|
optional,
|
|
129
96
|
positiveInt,
|
|
97
|
+
schemaOf,
|
|
130
98
|
stringSchema,
|
|
131
99
|
unknownSchema,
|
|
132
100
|
validate
|
package/dist/core/status.d.cts
CHANGED
package/dist/core/status.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,7 @@ __export(exports_src, {
|
|
|
61
61
|
objectOf: () => import_schema.objectOf,
|
|
62
62
|
optional: () => import_schema.optional,
|
|
63
63
|
positiveInt: () => import_schema.positiveInt,
|
|
64
|
+
requiredHeadFields: () => import_document.requiredHeadFields,
|
|
64
65
|
stampBody: () => import_body_version.stampBody,
|
|
65
66
|
stringSchema: () => import_schema.stringSchema,
|
|
66
67
|
systemActor: () => import_actor.systemActor,
|