@seed-hypermedia/client 0.0.133 → 0.0.135
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/dist/{chunk-NEUDKUBC.mjs → chunk-AU3QZNYC.mjs} +154 -3
- package/dist/chunk-U5K6COJT.mjs +10 -0
- package/dist/{chunk-JQKYF5NB.mjs → chunk-ZFMYEBAU.mjs} +19 -5
- package/dist/schema-engine.d.ts +59 -4
- package/dist/schema-engine.mjs +20 -4
- package/dist/schema-registry.generated.mjs +1 -1
- package/dist/schema-resolve.d.ts +10 -1
- package/dist/schema-resolve.mjs +5 -3
- package/dist/schema-subtypes.d.ts +8 -7
- package/dist/schema-subtypes.mjs +19 -12
- package/dist/schema-types.generated.d.ts +72 -3
- package/dist/signed-blob.mjs +2 -2
- package/package.json +1 -1
- package/dist/chunk-T7SWLR32.mjs +0 -10
package/dist/schema-engine.mjs
CHANGED
|
@@ -21,25 +21,33 @@ import {
|
|
|
21
21
|
literalValue,
|
|
22
22
|
load,
|
|
23
23
|
loadFrom,
|
|
24
|
+
mergeAllOf,
|
|
24
25
|
mergeExtend,
|
|
26
|
+
missingPropertyDefaults,
|
|
25
27
|
nameForCid,
|
|
26
28
|
nameToUrl,
|
|
27
29
|
namedSchemaUrl,
|
|
30
|
+
propertyDefaults,
|
|
28
31
|
refToName,
|
|
29
32
|
requiredFieldNames,
|
|
30
33
|
resolveSchema,
|
|
31
34
|
schemaCid,
|
|
35
|
+
schemaErrors,
|
|
32
36
|
schemaForCid,
|
|
33
37
|
schemaShape,
|
|
38
|
+
seedField,
|
|
39
|
+
seedValue,
|
|
40
|
+
seedWithEnv,
|
|
34
41
|
structFields,
|
|
35
42
|
typeOf,
|
|
36
43
|
validate,
|
|
37
|
-
validateAdvisory
|
|
38
|
-
|
|
44
|
+
validateAdvisory,
|
|
45
|
+
validateDefaults
|
|
46
|
+
} from "./chunk-AU3QZNYC.mjs";
|
|
39
47
|
import {
|
|
40
48
|
HM_SCHEMAS,
|
|
41
49
|
HM_SCHEMA_MANIFEST
|
|
42
|
-
} from "./chunk-
|
|
50
|
+
} from "./chunk-U5K6COJT.mjs";
|
|
43
51
|
import "./chunk-7P6ASYW6.mjs";
|
|
44
52
|
export {
|
|
45
53
|
HM_SCHEMAS,
|
|
@@ -66,18 +74,26 @@ export {
|
|
|
66
74
|
literalValue,
|
|
67
75
|
load,
|
|
68
76
|
loadFrom,
|
|
77
|
+
mergeAllOf,
|
|
69
78
|
mergeExtend,
|
|
79
|
+
missingPropertyDefaults,
|
|
70
80
|
nameForCid,
|
|
71
81
|
nameToUrl,
|
|
72
82
|
namedSchemaUrl,
|
|
83
|
+
propertyDefaults,
|
|
73
84
|
refToName,
|
|
74
85
|
requiredFieldNames,
|
|
75
86
|
resolveSchema,
|
|
76
87
|
schemaCid,
|
|
88
|
+
schemaErrors,
|
|
77
89
|
schemaForCid,
|
|
78
90
|
schemaShape,
|
|
91
|
+
seedField,
|
|
92
|
+
seedValue,
|
|
93
|
+
seedWithEnv,
|
|
79
94
|
structFields,
|
|
80
95
|
typeOf,
|
|
81
96
|
validate,
|
|
82
|
-
validateAdvisory
|
|
97
|
+
validateAdvisory,
|
|
98
|
+
validateDefaults
|
|
83
99
|
};
|
package/dist/schema-resolve.d.ts
CHANGED
|
@@ -118,6 +118,14 @@ export type DocumentSchemaCheck = {
|
|
|
118
118
|
* thrown. With `content`, the block tree is also checked against the base document's content schema.
|
|
119
119
|
*/
|
|
120
120
|
export declare function checkDocumentSchema(client: SchemaFetchClient, id: UnpackedHypermediaId, metadata: Record<string, unknown> | undefined, content?: unknown): Promise<DocumentSchemaCheck>;
|
|
121
|
+
/**
|
|
122
|
+
* The attributes a NEW document starts with: the property defaults of its effective attributes
|
|
123
|
+
* schema (its own `attributesSchema`, else the parent's `childAttributesSchema`) for every key
|
|
124
|
+
* `metadata` does not already hold. Only for a document being created. A document that already
|
|
125
|
+
* exists is never given a default, however its schema changes. An unresolvable type yields no
|
|
126
|
+
* defaults, never a throw.
|
|
127
|
+
*/
|
|
128
|
+
export declare function newDocumentDefaults(client: SchemaFetchClient, id: UnpackedHypermediaId, metadata: Record<string, unknown> | undefined): Promise<Record<string, unknown>>;
|
|
121
129
|
/** Whether a dag-json value is a plain map (the only shape that can carry a schema link). */
|
|
122
130
|
export declare const isPlainMap: (value: unknown) => value is Record<string, unknown>;
|
|
123
131
|
/** The `schema` link a blob carries (`{"/": <cid>}` or a URL string), if any. */
|
|
@@ -130,6 +138,7 @@ export declare function blobSchemaRef(value: unknown): string | null;
|
|
|
130
138
|
export declare function withoutSchemaLink(value: unknown): unknown;
|
|
131
139
|
/**
|
|
132
140
|
* Whether the schema a document's `schemaDefinition` points at is a valid Hypermedia schema: the
|
|
133
|
-
* violations of the meta-schema
|
|
141
|
+
* violations of the meta-schema and any property default that does not match its property, or the
|
|
142
|
+
* reason the reference could not be loaded. Empty when fine.
|
|
134
143
|
*/
|
|
135
144
|
export declare function checkSchemaDefinition(client: SchemaFetchClient, ref: string): Promise<string[]>;
|
package/dist/schema-resolve.mjs
CHANGED
|
@@ -14,12 +14,13 @@ import {
|
|
|
14
14
|
isPlainMap,
|
|
15
15
|
loadSchemaRef,
|
|
16
16
|
metadataSchemaOf,
|
|
17
|
+
newDocumentDefaults,
|
|
17
18
|
resolveSchemaRef,
|
|
18
19
|
schemaDefinitionCid,
|
|
19
20
|
withoutSchemaLink
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
21
|
+
} from "./chunk-ZFMYEBAU.mjs";
|
|
22
|
+
import "./chunk-AU3QZNYC.mjs";
|
|
23
|
+
import "./chunk-U5K6COJT.mjs";
|
|
23
24
|
import "./chunk-VWSAFDOL.mjs";
|
|
24
25
|
import "./chunk-DGNAMVGH.mjs";
|
|
25
26
|
import "./chunk-AHQWDCHV.mjs";
|
|
@@ -40,6 +41,7 @@ export {
|
|
|
40
41
|
isPlainMap,
|
|
41
42
|
loadSchemaRef,
|
|
42
43
|
metadataSchemaOf,
|
|
44
|
+
newDocumentDefaults,
|
|
43
45
|
resolveSchemaRef,
|
|
44
46
|
schemaDefinitionCid,
|
|
45
47
|
withoutSchemaLink
|
|
@@ -6,16 +6,17 @@ import { type HypermediaSchema } from './schema-engine';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function schemaRefKey(ref: string | null | undefined): string | null;
|
|
8
8
|
/**
|
|
9
|
-
* The
|
|
10
|
-
* than a kind. A union, a literal or a kind-grounded
|
|
9
|
+
* The schemas this schema extends or includes: its `type` when that names another schema rather
|
|
10
|
+
* than a kind, or, for an intersection, every arm's parent. A union, a literal or a kind-grounded
|
|
11
|
+
* node has no parent.
|
|
11
12
|
*/
|
|
12
|
-
export declare function
|
|
13
|
+
export declare function extensionParentRefs(schema: HypermediaSchema | undefined): string[];
|
|
13
14
|
/** A schema the closure may include: every spelling that names it, and what it extends. */
|
|
14
15
|
export type SchemaCandidate = {
|
|
15
16
|
/** Every reference string that names this schema (document URL, `ipfs://` CID, library URL). */
|
|
16
17
|
refs: string[];
|
|
17
|
-
/** The
|
|
18
|
-
|
|
18
|
+
/** The references this schema extends or includes: one for an extension, several for an intersection. */
|
|
19
|
+
parents: string[];
|
|
19
20
|
};
|
|
20
21
|
/** The bundled library as candidates: each schema under its library URL and published CID. */
|
|
21
22
|
export declare function libraryCandidates(): SchemaCandidate[];
|
|
@@ -26,8 +27,8 @@ export type SubtypeClosure = {
|
|
|
26
27
|
refs: string[];
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
29
|
-
* The target plus every candidate whose extension chain reaches it
|
|
30
|
-
* collected. Candidates that merely re-spell a member (the target's own document and blob, say)
|
|
30
|
+
* The target plus every candidate whose extension chain reaches it (through any arm of an
|
|
31
|
+
* intersection), with every spelling of each collected. Candidates that merely re-spell a member (the target's own document and blob, say)
|
|
31
32
|
* contribute their spellings too. Cycles and unresolvable parents are harmless: the loop only ever
|
|
32
33
|
* adds, and stops when a pass adds nothing.
|
|
33
34
|
*/
|
package/dist/schema-subtypes.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
classifyRef
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZFMYEBAU.mjs";
|
|
4
4
|
import {
|
|
5
5
|
kindOf,
|
|
6
6
|
nameForCid,
|
|
7
7
|
nameToUrl,
|
|
8
8
|
schemaCid
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AU3QZNYC.mjs";
|
|
10
10
|
import {
|
|
11
11
|
HM_SCHEMAS
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-U5K6COJT.mjs";
|
|
13
13
|
import "./chunk-VWSAFDOL.mjs";
|
|
14
14
|
import {
|
|
15
15
|
unpackHmId
|
|
@@ -36,11 +36,18 @@ function schemaRefKey(ref) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
|
|
39
|
+
function extensionParentRefs(schema) {
|
|
40
|
+
if (!schema || typeof schema !== "object" || Array.isArray(schema)) return [];
|
|
41
|
+
const node = schema;
|
|
42
|
+
if (Array.isArray(node.allOf)) {
|
|
43
|
+
const out = [];
|
|
44
|
+
for (const arm of node.allOf)
|
|
45
|
+
for (const ref of extensionParentRefs(arm)) if (!out.includes(ref)) out.push(ref);
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
const type = node.type;
|
|
49
|
+
if (typeof type !== "string" || !type) return [];
|
|
50
|
+
return kindOf(type) === type ? [type] : [];
|
|
44
51
|
}
|
|
45
52
|
function libraryCandidates() {
|
|
46
53
|
return Object.entries(HM_SCHEMAS).map(([name, schema]) => {
|
|
@@ -48,7 +55,7 @@ function libraryCandidates() {
|
|
|
48
55
|
const url = nameToUrl(name);
|
|
49
56
|
return {
|
|
50
57
|
refs: [...url ? [url] : [], ...cid ? [`ipfs://${cid}`] : []],
|
|
51
|
-
|
|
58
|
+
parents: extensionParentRefs(schema)
|
|
52
59
|
};
|
|
53
60
|
});
|
|
54
61
|
}
|
|
@@ -64,14 +71,14 @@ function closeOverSubtypes(target, candidates) {
|
|
|
64
71
|
add(target, targetKey);
|
|
65
72
|
const keyed = candidates.map((candidate) => ({
|
|
66
73
|
refs: candidate.refs.map((ref) => [ref, schemaRefKey(ref)]).filter((pair) => !!pair[1]),
|
|
67
|
-
|
|
74
|
+
parentKeys: candidate.parents.map(schemaRefKey).filter((key) => !!key)
|
|
68
75
|
})).filter((candidate) => candidate.refs.length > 0);
|
|
69
76
|
let grew = true;
|
|
70
77
|
while (grew) {
|
|
71
78
|
grew = false;
|
|
72
79
|
for (const candidate of keyed) {
|
|
73
80
|
const known = candidate.refs.some(([, key]) => keys.has(key));
|
|
74
|
-
const inherits =
|
|
81
|
+
const inherits = candidate.parentKeys.some((key) => keys.has(key));
|
|
75
82
|
if (!known && !inherits) continue;
|
|
76
83
|
for (const [ref, key] of candidate.refs) {
|
|
77
84
|
if (keys.has(key) && refs.includes(ref)) continue;
|
|
@@ -88,7 +95,7 @@ function inClosure(closure, ref) {
|
|
|
88
95
|
}
|
|
89
96
|
export {
|
|
90
97
|
closeOverSubtypes,
|
|
91
|
-
|
|
98
|
+
extensionParentRefs,
|
|
92
99
|
inClosure,
|
|
93
100
|
libraryCandidates,
|
|
94
101
|
schemaRefKey
|
|
@@ -850,6 +850,18 @@ export type HMExampleConstrained = {
|
|
|
850
850
|
/** One to three string tags. */
|
|
851
851
|
tags?: string[];
|
|
852
852
|
};
|
|
853
|
+
/**
|
|
854
|
+
* Example: Contact
|
|
855
|
+
* Ways to reach someone, a required email and an optional phone number.
|
|
856
|
+
* Ways to reach someone: a required email and an optional phone number.
|
|
857
|
+
* Schema: hm://hyper.media/example/contact
|
|
858
|
+
*/
|
|
859
|
+
export type HMExampleContact = {
|
|
860
|
+
/** The address to write to. */
|
|
861
|
+
email: string;
|
|
862
|
+
/** A telephone number, in any format. */
|
|
863
|
+
phone?: string;
|
|
864
|
+
};
|
|
853
865
|
/**
|
|
854
866
|
* Example: Counts
|
|
855
867
|
* A map from string keys to integers: Map<Integer>.
|
|
@@ -1087,6 +1099,13 @@ export type HMExamplePollBlock = HMBlockBase & {
|
|
|
1087
1099
|
export type HMExampleRegistry = {
|
|
1088
1100
|
[key: string]: HMLink;
|
|
1089
1101
|
};
|
|
1102
|
+
/**
|
|
1103
|
+
* Example: Staff Member
|
|
1104
|
+
* An employee who is also a contact, the intersection of the two.
|
|
1105
|
+
* An employee who is also a contact: every field of both, with name, employeeId and email required.
|
|
1106
|
+
* Schema: hm://hyper.media/example/staff-member
|
|
1107
|
+
*/
|
|
1108
|
+
export type HMExampleStaffMember = HMExampleEmployee & HMExampleContact;
|
|
1090
1109
|
/**
|
|
1091
1110
|
* Character Stats
|
|
1092
1111
|
* A character’s stats object, stored as its own DAG-CBOR blob linked by `ipfs://` so it can hold the integers and enums document metadata cannot.
|
|
@@ -1119,6 +1138,36 @@ export type HMExampleStatus = 'draft' | 'published' | 'archived';
|
|
|
1119
1138
|
* Schema: hm://hyper.media/example/tags
|
|
1120
1139
|
*/
|
|
1121
1140
|
export type HMExampleTags = string[];
|
|
1141
|
+
/**
|
|
1142
|
+
* Example: Task Document
|
|
1143
|
+
* A document type for a task that shows property defaults: a new task starts as todo with priority 2, no tags and an unfinished checklist.
|
|
1144
|
+
* A document type for a task, showing property defaults: the values a new task starts with.
|
|
1145
|
+
* Schema: hm://hyper.media/example/task-doc
|
|
1146
|
+
*/
|
|
1147
|
+
export type HMExampleTaskDoc = {
|
|
1148
|
+
/** Where the task stands. A new task starts as `todo`. · default: "todo" */
|
|
1149
|
+
status: HMExampleTaskStatus;
|
|
1150
|
+
/** 1 is most urgent and 3 is least. A new task starts in the middle. · minimum: 1 · maximum: 3 · default: 2 */
|
|
1151
|
+
priority?: number;
|
|
1152
|
+
/** Labels for the task. A new task starts with an empty list. · default: [] */
|
|
1153
|
+
tags?: string[];
|
|
1154
|
+
/** The steps of the task. It has no default of its own, so a new task builds it from the defaults of its fields. */
|
|
1155
|
+
checklist: {
|
|
1156
|
+
/** Whether every step is finished. · default: false */
|
|
1157
|
+
done: boolean;
|
|
1158
|
+
/** The steps, in order. */
|
|
1159
|
+
steps: string[];
|
|
1160
|
+
};
|
|
1161
|
+
/** The day the task is due. It has no default, so a new task leaves it out. */
|
|
1162
|
+
due?: HMDate;
|
|
1163
|
+
};
|
|
1164
|
+
/**
|
|
1165
|
+
* Example: Task Status
|
|
1166
|
+
* The state of a task: todo, doing, or done.
|
|
1167
|
+
* The state of a task: `todo`, `doing` or `done`.
|
|
1168
|
+
* Schema: hm://hyper.media/example/task-status
|
|
1169
|
+
*/
|
|
1170
|
+
export type HMExampleTaskStatus = 'todo' | 'doing' | 'done';
|
|
1122
1171
|
/**
|
|
1123
1172
|
* Example: Tree
|
|
1124
1173
|
* A node holding an integer value and links to child nodes.
|
|
@@ -1430,7 +1479,25 @@ export type HMRole = 'WRITER' | 'AGENT';
|
|
|
1430
1479
|
* The meta-schema: the union of every shape a schema can take, itself a valid instance of this type.
|
|
1431
1480
|
* Schema: hm://hyper.media/schema
|
|
1432
1481
|
*/
|
|
1433
|
-
export type HMSchema = HMSchemaStructSchema | HMSchemaMapSchema | HMSchemaListSchema | HMSchemaScalarSchema | HMSchemaLinkSchema | HMSchemaIncludeSchema | HMSchemaAnyof | HMSchemaVarSchema | HMSchemaLiteralSchema | string | number | boolean | null;
|
|
1482
|
+
export type HMSchema = HMSchemaStructSchema | HMSchemaMapSchema | HMSchemaListSchema | HMSchemaScalarSchema | HMSchemaLinkSchema | HMSchemaIncludeSchema | HMSchemaAnyof | HMSchemaAllof | HMSchemaVarSchema | HMSchemaLiteralSchema | string | number | boolean | null;
|
|
1483
|
+
/**
|
|
1484
|
+
* Intersection schema
|
|
1485
|
+
* The variant for an intersection, which accepts a value that satisfies every schema listed under allOf, by merging its struct arms into one.
|
|
1486
|
+
* An intersection schema: a value is valid if it satisfies every schema listed under `allOf`. The arms are structs, and they merge into one.
|
|
1487
|
+
* Schema: hm://hyper.media/schema/allof
|
|
1488
|
+
*/
|
|
1489
|
+
export type HMSchemaAllof = {
|
|
1490
|
+
/** The schemas to combine; a value must satisfy every one. Each arm must be a struct or map (or name one); their fields merge into one struct. */
|
|
1491
|
+
allOf: HMSchema[];
|
|
1492
|
+
/** What the intersection is for, when it is written inline; a published schema is described by its page. */
|
|
1493
|
+
description?: string;
|
|
1494
|
+
/** Type parameters that make this schema generic, each with its default schema. */
|
|
1495
|
+
params?: {
|
|
1496
|
+
[key: string]: HMSchema;
|
|
1497
|
+
};
|
|
1498
|
+
/** Legacy: a name some published schemas still carry. New schemas are named by their page. */
|
|
1499
|
+
name?: string;
|
|
1500
|
+
};
|
|
1434
1501
|
/**
|
|
1435
1502
|
* Union schema
|
|
1436
1503
|
* The variant for a union, which accepts a value that matches any one of the schemas listed under anyOf.
|
|
@@ -1556,8 +1623,8 @@ export type HMSchemaMapSchema = {
|
|
|
1556
1623
|
};
|
|
1557
1624
|
/**
|
|
1558
1625
|
* Property
|
|
1559
|
-
* One field of a struct, holding its value schema, whether a value must include it,
|
|
1560
|
-
* One field of a struct: the schema its value must match, whether it is required,
|
|
1626
|
+
* One field of a struct, holding its value schema, whether a value must include it, a description of what it is for, and the default a new value starts with.
|
|
1627
|
+
* One field of a struct: the schema its value must match, whether it is required, what it is for, and the value a new struct starts with.
|
|
1561
1628
|
* Schema: hm://hyper.media/schema/property
|
|
1562
1629
|
*/
|
|
1563
1630
|
export type HMSchemaProperty = {
|
|
@@ -1567,6 +1634,8 @@ export type HMSchemaProperty = {
|
|
|
1567
1634
|
required?: boolean;
|
|
1568
1635
|
/** What the field is for, for people and for the editors that show it. */
|
|
1569
1636
|
description?: string;
|
|
1637
|
+
/** The value an editor writes into a new struct for this field. It must match `value`. It only initializes: a struct that lacks the field is not read as if it had this value. */
|
|
1638
|
+
default?: unknown;
|
|
1570
1639
|
};
|
|
1571
1640
|
/**
|
|
1572
1641
|
* Scalar schema
|
package/dist/signed-blob.mjs
CHANGED