@seed-hypermedia/client 0.0.134 → 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.
@@ -2,7 +2,7 @@ import {
2
2
  HM_SCHEMAS,
3
3
  HM_SCHEMA_MANIFEST,
4
4
  HM_SCHEMA_PAGES
5
- } from "./chunk-37QDFTT6.mjs";
5
+ } from "./chunk-U5K6COJT.mjs";
6
6
  import "./chunk-7P6ASYW6.mjs";
7
7
  export {
8
8
  HM_SCHEMAS,
@@ -18,9 +18,9 @@ import {
18
18
  resolveSchemaRef,
19
19
  schemaDefinitionCid,
20
20
  withoutSchemaLink
21
- } from "./chunk-ITUEKIQD.mjs";
22
- import "./chunk-BRNXLHBP.mjs";
23
- import "./chunk-37QDFTT6.mjs";
21
+ } from "./chunk-ZFMYEBAU.mjs";
22
+ import "./chunk-AU3QZNYC.mjs";
23
+ import "./chunk-U5K6COJT.mjs";
24
24
  import "./chunk-VWSAFDOL.mjs";
25
25
  import "./chunk-DGNAMVGH.mjs";
26
26
  import "./chunk-AHQWDCHV.mjs";
@@ -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-ITUEKIQD.mjs";
3
+ } from "./chunk-ZFMYEBAU.mjs";
4
4
  import {
5
5
  kindOf,
6
6
  nameForCid,
7
7
  nameToUrl,
8
8
  schemaCid
9
- } from "./chunk-BRNXLHBP.mjs";
9
+ } from "./chunk-AU3QZNYC.mjs";
10
10
  import {
11
11
  HM_SCHEMAS
12
- } from "./chunk-37QDFTT6.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.
@@ -1460,7 +1479,25 @@ export type HMRole = 'WRITER' | 'AGENT';
1460
1479
  * The meta-schema: the union of every shape a schema can take, itself a valid instance of this type.
1461
1480
  * Schema: hm://hyper.media/schema
1462
1481
  */
1463
- 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
+ };
1464
1501
  /**
1465
1502
  * Union schema
1466
1503
  * The variant for a union, which accepts a value that matches any one of the schemas listed under anyOf.
@@ -5,8 +5,8 @@ import {
5
5
  literalValue,
6
6
  resolveSchema,
7
7
  structFields
8
- } from "./chunk-BRNXLHBP.mjs";
9
- import "./chunk-37QDFTT6.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.134",
3
+ "version": "0.0.135",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seed-hypermedia/seed",