@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.
@@ -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
- } from "./chunk-NEUDKUBC.mjs";
44
+ validateAdvisory,
45
+ validateDefaults
46
+ } from "./chunk-AU3QZNYC.mjs";
39
47
  import {
40
48
  HM_SCHEMAS,
41
49
  HM_SCHEMA_MANIFEST
42
- } from "./chunk-T7SWLR32.mjs";
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
  };
@@ -2,7 +2,7 @@ import {
2
2
  HM_SCHEMAS,
3
3
  HM_SCHEMA_MANIFEST,
4
4
  HM_SCHEMA_PAGES
5
- } from "./chunk-T7SWLR32.mjs";
5
+ } from "./chunk-U5K6COJT.mjs";
6
6
  import "./chunk-7P6ASYW6.mjs";
7
7
  export {
8
8
  HM_SCHEMAS,
@@ -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, or the reason the reference could not be loaded. Empty when fine.
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[]>;
@@ -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-JQKYF5NB.mjs";
21
- import "./chunk-NEUDKUBC.mjs";
22
- import "./chunk-T7SWLR32.mjs";
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 schema this schema extends or includes: its `type` when that names another schema rather
10
- * than a kind. A union, a literal or a kind-grounded node has no parent.
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 extensionParentRef(schema: HypermediaSchema | undefined): string | null;
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 reference this schema extends or includes, if any. */
18
- parent: string | null;
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, with every spelling of each
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
  */
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  classifyRef
3
- } from "./chunk-JQKYF5NB.mjs";
3
+ } from "./chunk-ZFMYEBAU.mjs";
4
4
  import {
5
5
  kindOf,
6
6
  nameForCid,
7
7
  nameToUrl,
8
8
  schemaCid
9
- } from "./chunk-NEUDKUBC.mjs";
9
+ } from "./chunk-AU3QZNYC.mjs";
10
10
  import {
11
11
  HM_SCHEMAS
12
- } from "./chunk-T7SWLR32.mjs";
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 extensionParentRef(schema) {
40
- if (!schema || typeof schema !== "object" || Array.isArray(schema)) return null;
41
- const type = schema.type;
42
- if (typeof type !== "string" || !type) return null;
43
- return kindOf(type) === type ? type : null;
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
- parent: extensionParentRef(schema)
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
- parentKey: candidate.parent ? schemaRefKey(candidate.parent) : null
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 = !!candidate.parentKey && keys.has(candidate.parentKey);
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
- extensionParentRef,
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, and a description of what it is for.
1560
- * One field of a struct: the schema its value must match, whether it is required, and what it is for.
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
@@ -5,8 +5,8 @@ import {
5
5
  literalValue,
6
6
  resolveSchema,
7
7
  structFields
8
- } from "./chunk-NEUDKUBC.mjs";
9
- import "./chunk-T7SWLR32.mjs";
8
+ } from "./chunk-AU3QZNYC.mjs";
9
+ import "./chunk-U5K6COJT.mjs";
10
10
  import {
11
11
  dagJsonToIpld,
12
12
  findSeedIndexerCollision
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-hypermedia/client",
3
- "version": "0.0.133",
3
+ "version": "0.0.135",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",