@seed-hypermedia/client 0.0.90 → 0.0.92

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.
Files changed (52) hide show
  1. package/dist/auto-link.mjs +3 -3
  2. package/dist/blocks-to-markdown.mjs +2 -2
  3. package/dist/capability.mjs +2 -2
  4. package/dist/{chunk-T7WF36LU.mjs → chunk-7RJYOV4D.mjs} +1 -1
  5. package/dist/{chunk-ZNV6NTUU.mjs → chunk-BRMAKS6Z.mjs} +1 -1
  6. package/dist/{chunk-XXUI3VKA.mjs → chunk-EB45YSE7.mjs} +1 -1
  7. package/dist/{chunk-Z72PGJKG.mjs → chunk-HEATDM6O.mjs} +1 -1
  8. package/dist/{chunk-W7AGZEC2.mjs → chunk-IB26JMU5.mjs} +1 -1
  9. package/dist/{chunk-4HP5N4I7.mjs → chunk-IJOMB2VD.mjs} +3 -3
  10. package/dist/{chunk-HNQDRHGQ.mjs → chunk-IO44LDKK.mjs} +2 -2
  11. package/dist/{chunk-Z2S7TL5U.mjs → chunk-J6LPZ3QP.mjs} +1 -1
  12. package/dist/{chunk-RRXP7SCF.mjs → chunk-J6N6AF3R.mjs} +1 -1
  13. package/dist/{chunk-UTZ42CJC.mjs → chunk-JOFKLKIC.mjs} +1 -1
  14. package/dist/chunk-JSNDXUPG.mjs +407 -0
  15. package/dist/{chunk-JODNNMBZ.mjs → chunk-M6GKXROC.mjs} +2 -2
  16. package/dist/{chunk-VNZHLLJE.mjs → chunk-MK35Y35R.mjs} +148 -2
  17. package/dist/{chunk-XB6E7EVC.mjs → chunk-QVRJGK77.mjs} +1 -1
  18. package/dist/chunk-RWKSRJA3.mjs +230 -0
  19. package/dist/chunk-VWSAFDOL.mjs +110 -0
  20. package/dist/{chunk-UFLGAJWJ.mjs → chunk-WY7T2TES.mjs} +3 -3
  21. package/dist/chunk-ZWKMAGDU.mjs +10 -0
  22. package/dist/client.mjs +2 -2
  23. package/dist/comment.mjs +2 -2
  24. package/dist/dag-json.d.ts +52 -0
  25. package/dist/dag-json.mjs +23 -0
  26. package/dist/document-state.mjs +2 -2
  27. package/dist/editorblock-to-hmblock.mjs +2 -2
  28. package/dist/explore-query.d.ts +112 -0
  29. package/dist/explore-query.mjs +455 -0
  30. package/dist/hm-resolver.mjs +2 -2
  31. package/dist/hm-types.d.ts +2953 -0
  32. package/dist/hm-types.mjs +33 -1
  33. package/dist/hmblock-to-editorblock.mjs +2 -2
  34. package/dist/index.mjs +27 -27
  35. package/dist/markdown-to-blocks.mjs +1 -1
  36. package/dist/pdf-to-blocks.mjs +3 -3
  37. package/dist/resource-read.mjs +4 -4
  38. package/dist/schema-engine.d.ts +127 -0
  39. package/dist/schema-engine.mjs +83 -0
  40. package/dist/schema-registry.generated.d.ts +8 -0
  41. package/dist/schema-registry.generated.mjs +11 -0
  42. package/dist/schema-resolve.d.ts +135 -0
  43. package/dist/schema-resolve.mjs +45 -0
  44. package/dist/schema-subtypes.d.ts +36 -0
  45. package/dist/schema-subtypes.mjs +94 -0
  46. package/dist/schema-types.generated.d.ts +1598 -0
  47. package/dist/schema-types.generated.mjs +0 -0
  48. package/dist/signed-blob.d.ts +63 -0
  49. package/dist/signed-blob.mjs +123 -0
  50. package/dist/tei-to-blocks.mjs +2 -2
  51. package/dist/unicode.mjs +1 -1
  52. package/package.json +1 -1
@@ -307,7 +307,9 @@ var HMDocumentMetadataSchema = z.object({
307
307
  }).optional(),
308
308
  // Import taxonomy fields (comma-separated values from external sources like WordPress)
309
309
  importCategories: z.string().optional(),
310
- importTags: z.string().optional()
310
+ importTags: z.string().optional(),
311
+ // JSON-stringified schema definition; present iff this document describes a schema (see notes/schema-as-document.md).
312
+ schemaDefinition: z.string().optional()
311
313
  }).passthrough();
312
314
  function hmMetadataJsonCorrection(metadata) {
313
315
  if (typeof metadata.theme === "string") {
@@ -881,6 +883,128 @@ var HMSearchRequestSchema = z.object({
881
883
  input: HMSearchInputSchema,
882
884
  output: HMSearchPayloadSchema
883
885
  });
886
+ var HMAttributeValueSchema = z.object({
887
+ stringValue: z.string().optional(),
888
+ intValue: z.union([z.number(), z.string()]).optional(),
889
+ boolValue: z.boolean().optional(),
890
+ nullValue: z.union([z.object({}), z.null()]).optional()
891
+ }).strict();
892
+ var HMDocumentFilterComparisonOperatorSchema = z.enum([
893
+ "EQUAL",
894
+ "NOT_EQUAL",
895
+ "LESS_THAN",
896
+ "LESS_THAN_OR_EQUAL",
897
+ "GREATER_THAN",
898
+ "GREATER_THAN_OR_EQUAL"
899
+ ]);
900
+ var HMDocumentFilterSchema = z.lazy(
901
+ () => z.object({
902
+ and: z.object({ filters: z.array(HMDocumentFilterSchema) }).optional(),
903
+ or: z.object({ filters: z.array(HMDocumentFilterSchema) }).optional(),
904
+ not: z.object({ filter: HMDocumentFilterSchema }).optional(),
905
+ comparison: z.object({ key: z.string(), operator: HMDocumentFilterComparisonOperatorSchema, value: HMAttributeValueSchema }).optional(),
906
+ exists: z.object({ key: z.string() }).optional(),
907
+ missing: z.object({ key: z.string() }).optional(),
908
+ stringMatch: z.object({
909
+ key: z.string(),
910
+ value: z.string(),
911
+ caseSensitive: z.boolean().optional(),
912
+ prefix: z.boolean().optional()
913
+ }).optional(),
914
+ urlMatch: z.object({ url: z.string(), prefix: z.boolean().optional() }).optional(),
915
+ spaceMatch: z.object({ space: z.string() }).optional(),
916
+ pathMatch: z.object({ path: z.string(), prefix: z.boolean().optional() }).optional()
917
+ }).strict()
918
+ );
919
+ var HMBuiltinSortAttributeSchema = z.enum([
920
+ "BUILTIN_SORT_ATTRIBUTE_NAME",
921
+ "BUILTIN_SORT_ATTRIBUTE_PATH",
922
+ "BUILTIN_SORT_ATTRIBUTE_CREATE_TIME",
923
+ "BUILTIN_SORT_ATTRIBUTE_UPDATE_TIME",
924
+ "BUILTIN_SORT_ATTRIBUTE_ACTIVITY_TIME",
925
+ "BUILTIN_SORT_ATTRIBUTE_COMMENT_COUNT"
926
+ ]);
927
+ var HMDocumentSortSchema = z.object({
928
+ key: z.string().optional(),
929
+ attribute: HMBuiltinSortAttributeSchema.optional(),
930
+ descending: z.boolean().optional()
931
+ }).strict();
932
+ var HMQueryDocumentsInputSchema = z.object({
933
+ filter: HMDocumentFilterSchema.optional(),
934
+ sort: z.array(HMDocumentSortSchema).optional(),
935
+ pageSize: z.number().int().positive().optional(),
936
+ pageToken: z.string().optional()
937
+ }).strict();
938
+ var HMRawDocumentInfoSchema = z.object({
939
+ account: z.string(),
940
+ /** The document path, `/`-prefixed; empty for the space's home document. */
941
+ path: z.string().optional(),
942
+ metadata: z.record(z.unknown()).optional(),
943
+ authors: z.array(z.string()).optional(),
944
+ createTime: z.string().optional(),
945
+ updateTime: z.string().optional(),
946
+ genesis: z.string().optional(),
947
+ version: z.string().optional()
948
+ }).passthrough();
949
+ var HMQueryDocumentsOutputSchema = z.object({
950
+ documents: z.array(HMRawDocumentInfoSchema).optional(),
951
+ nextPageToken: z.string().optional()
952
+ }).passthrough();
953
+ var HMQueryDocumentsRequestSchema = z.object({
954
+ key: z.literal("QueryDocuments"),
955
+ input: HMQueryDocumentsInputSchema,
956
+ output: HMQueryDocumentsOutputSchema
957
+ });
958
+ var HMDocumentAttributeKindSchema = z.enum([
959
+ "DOCUMENT_ATTRIBUTE_KIND_UNSPECIFIED",
960
+ "DOCUMENT_ATTRIBUTE_KIND_OBJECT",
961
+ "DOCUMENT_ATTRIBUTE_KIND_STRING",
962
+ "DOCUMENT_ATTRIBUTE_KIND_INT",
963
+ "DOCUMENT_ATTRIBUTE_KIND_BOOL"
964
+ ]);
965
+ var HMListDocumentAttributeNamesInputSchema = z.object({
966
+ /** Space whose attribute names come first; omitted = ordered globally. */
967
+ account: z.string().optional(),
968
+ /** Parent object path; results are its direct children. */
969
+ parentPath: z.array(z.string()).optional(),
970
+ prefix: z.string().optional(),
971
+ pageSize: z.number().int().positive().optional(),
972
+ pageToken: z.string().optional(),
973
+ /** Complete dotted scalar paths instead of direct children. */
974
+ recursive: z.boolean().optional()
975
+ }).strict();
976
+ var HMListDocumentAttributeNamesOutputSchema = z.object({
977
+ names: z.array(
978
+ z.object({
979
+ name: z.string(),
980
+ kinds: z.array(z.object({ kind: HMDocumentAttributeKindSchema.optional() }).passthrough()).optional()
981
+ }).passthrough()
982
+ ).optional(),
983
+ nextPageToken: z.string().optional()
984
+ }).passthrough();
985
+ var HMListDocumentAttributeNamesRequestSchema = z.object({
986
+ key: z.literal("ListDocumentAttributeNames"),
987
+ input: HMListDocumentAttributeNamesInputSchema,
988
+ output: HMListDocumentAttributeNamesOutputSchema
989
+ });
990
+ var HMListDocumentAttributeValuesInputSchema = z.object({
991
+ /** Exact nested path of the attribute. */
992
+ path: z.array(z.string()),
993
+ kind: HMDocumentAttributeKindSchema,
994
+ account: z.string().optional(),
995
+ prefix: z.string().optional(),
996
+ pageSize: z.number().int().positive().optional(),
997
+ pageToken: z.string().optional()
998
+ }).strict();
999
+ var HMListDocumentAttributeValuesOutputSchema = z.object({
1000
+ values: z.array(z.object({ value: HMAttributeValueSchema.optional() }).passthrough()).optional(),
1001
+ nextPageToken: z.string().optional()
1002
+ }).passthrough();
1003
+ var HMListDocumentAttributeValuesRequestSchema = z.object({
1004
+ key: z.literal("ListDocumentAttributeValues"),
1005
+ input: HMListDocumentAttributeValuesInputSchema,
1006
+ output: HMListDocumentAttributeValuesOutputSchema
1007
+ });
884
1008
  var HMMentionCandidateSchema = z.object({
885
1009
  id: unpackedHmIdSchema,
886
1010
  type: z.enum(["account", "document"]),
@@ -1330,10 +1454,16 @@ var HMGetRequestSchema = z.discriminatedUnion("key", [
1330
1454
  ]);
1331
1455
  var HMActionSchema = z.discriminatedUnion("key", [
1332
1456
  HMPublishBlobsRequestSchema,
1333
- HMPrepareDocumentChangeRequestSchema
1457
+ HMPrepareDocumentChangeRequestSchema,
1458
+ HMQueryDocumentsRequestSchema,
1459
+ HMListDocumentAttributeNamesRequestSchema,
1460
+ HMListDocumentAttributeValuesRequestSchema
1334
1461
  ]);
1335
1462
  var HMRequestSchema = z.discriminatedUnion("key", [
1336
1463
  HMResourceRequestSchema,
1464
+ HMQueryDocumentsRequestSchema,
1465
+ HMListDocumentAttributeNamesRequestSchema,
1466
+ HMListDocumentAttributeValuesRequestSchema,
1337
1467
  HMResourceMetadataRequestSchema,
1338
1468
  HMAccountRequestSchema,
1339
1469
  HMCommentRequestSchema,
@@ -1630,6 +1760,22 @@ export {
1630
1760
  HMSearchResultItemSchema,
1631
1761
  HMSearchPayloadSchema,
1632
1762
  HMSearchRequestSchema,
1763
+ HMAttributeValueSchema,
1764
+ HMDocumentFilterComparisonOperatorSchema,
1765
+ HMDocumentFilterSchema,
1766
+ HMBuiltinSortAttributeSchema,
1767
+ HMDocumentSortSchema,
1768
+ HMQueryDocumentsInputSchema,
1769
+ HMRawDocumentInfoSchema,
1770
+ HMQueryDocumentsOutputSchema,
1771
+ HMQueryDocumentsRequestSchema,
1772
+ HMDocumentAttributeKindSchema,
1773
+ HMListDocumentAttributeNamesInputSchema,
1774
+ HMListDocumentAttributeNamesOutputSchema,
1775
+ HMListDocumentAttributeNamesRequestSchema,
1776
+ HMListDocumentAttributeValuesInputSchema,
1777
+ HMListDocumentAttributeValuesOutputSchema,
1778
+ HMListDocumentAttributeValuesRequestSchema,
1633
1779
  HMMentionCandidateSchema,
1634
1780
  HMMentionCandidatesRequestSchema,
1635
1781
  HMQueryRequestSchema,
@@ -371,7 +371,7 @@ function createImageNode(alt, url, comment) {
371
371
  function createTypedNode(visible, comment) {
372
372
  const block = baseBlock(comment.type, comment);
373
373
  const v = visible.trim();
374
- const linkOnly = /^<([a-zA-Z][a-zA-Z0-9+.-]*:[^\s<>]*)>$/.exec(v);
374
+ const linkOnly = /^<((?:[a-zA-Z][a-zA-Z0-9+.-]*:|\.{1,2}\/)[^\s<>]*)>$/.exec(v);
375
375
  const labeled = v.startsWith("[") ? readLink(v, 0) : null;
376
376
  if (linkOnly) {
377
377
  block.link = linkOnly[1];
@@ -0,0 +1,230 @@
1
+ import {
2
+ STRUCT_URL,
3
+ fieldSchema,
4
+ fieldsToProperties,
5
+ isLiteralSchema,
6
+ loadFrom,
7
+ refToName,
8
+ resolveSchema,
9
+ schemaCid,
10
+ schemaForCid,
11
+ structFields,
12
+ validate
13
+ } from "./chunk-JSNDXUPG.mjs";
14
+ import {
15
+ HM_SCHEMAS
16
+ } from "./chunk-ZWKMAGDU.mjs";
17
+ import {
18
+ parseCidString
19
+ } from "./chunk-VWSAFDOL.mjs";
20
+ import {
21
+ packHmId,
22
+ unpackHmId
23
+ } from "./chunk-MK35Y35R.mjs";
24
+
25
+ // src/schema-resolve.ts
26
+ var DAG_CBOR_CODE = 113;
27
+ function bareCid(ref) {
28
+ var _a;
29
+ const cid = ref.replace(/^ipfs:\/\//i, "").split("/")[0] ?? "";
30
+ return ((_a = parseCidString(cid)) == null ? void 0 : _a.code) === DAG_CBOR_CODE ? cid : null;
31
+ }
32
+ function classifyRef(ref) {
33
+ var _a;
34
+ let s = typeof ref === "string" ? ref.trim() : "";
35
+ if (!s) return { kind: "none" };
36
+ if (!s.startsWith("hm://")) {
37
+ const cid = bareCid(s);
38
+ if (cid) return { kind: "cid", cid };
39
+ const id = unpackHmId(s);
40
+ if (!id) return { kind: "none" };
41
+ s = `hm://${id.uid}${((_a = id.path) == null ? void 0 : _a.length) ? `/${id.path.join("/")}` : ""}`;
42
+ }
43
+ const name = refToName(s);
44
+ return HM_SCHEMAS[name] ? { kind: "hm-bundled", name } : { kind: "hm-doc", url: s };
45
+ }
46
+ function metadataSchemaOf(schema, reg = {}) {
47
+ if (!schema) return void 0;
48
+ return resolveSchema(schema, {}, reg).schema;
49
+ }
50
+ function schemaDefinitionCid(metadata) {
51
+ const value = metadata == null ? void 0 : metadata.schemaDefinition;
52
+ return typeof value === "string" ? bareCid(value) : null;
53
+ }
54
+ async function fetchSchemaBlob(client, cid) {
55
+ const bundled = schemaForCid(cid);
56
+ if (bundled) return bundled;
57
+ const result = await client.request("GetCID", { cid });
58
+ const value = withoutSchemaLink(result == null ? void 0 : result.value);
59
+ return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
60
+ }
61
+ function documentMetadataSchema(typeMetadataSchema, extraProps = {}, registry = {}) {
62
+ const base = resolveSchema(HM_SCHEMAS["metadata"]).schema;
63
+ const doc = typeMetadataSchema ? resolveSchema(typeMetadataSchema, {}, registry).schema : {};
64
+ const byName = /* @__PURE__ */ new Map();
65
+ for (const f of structFields(base)) byName.set(f.name, f);
66
+ for (const f of structFields(doc)) byName.set(f.name, f);
67
+ for (const [name, schema] of Object.entries(extraProps)) byName.set(name, { name, schema, required: false });
68
+ return { type: STRUCT_URL, properties: fieldsToProperties(Array.from(byName.values())), values: {} };
69
+ }
70
+ async function resolveSchemaRef(client, ref) {
71
+ const cls = classifyRef(ref);
72
+ if (cls.kind === "none") return { kind: "none" };
73
+ if (cls.kind === "hm-bundled") return { kind: cls.kind, schema: HM_SCHEMAS[cls.name], cid: schemaCid(cls.name) };
74
+ if (cls.kind === "cid") {
75
+ const schema2 = await fetchSchemaBlob(client, cls.cid).catch(() => void 0);
76
+ return { kind: cls.kind, schema: schema2, cid: schema2 ? cls.cid : void 0 };
77
+ }
78
+ const id = unpackHmId(cls.url);
79
+ if (!id) return { kind: "none" };
80
+ const resource = await client.request("Resource", id).catch(() => void 0);
81
+ const cid = (resource == null ? void 0 : resource.type) === "document" ? schemaDefinitionCid(resource.document.metadata) : null;
82
+ if (!cid) return { kind: cls.kind, documentUrl: cls.url };
83
+ const schema = await fetchSchemaBlob(client, cid).catch(() => void 0);
84
+ return { kind: cls.kind, schema, cid: schema ? cid : void 0, documentUrl: cls.url };
85
+ }
86
+ function referencesOf(schema, out = []) {
87
+ if (!schema || typeof schema !== "object") return out;
88
+ if (Array.isArray(schema)) {
89
+ for (const s of schema) referencesOf(s, out);
90
+ return out;
91
+ }
92
+ const node = schema;
93
+ for (const [key, value] of Object.entries(node)) {
94
+ if ((key === "ref" || key === "type") && typeof value === "string") out.push(value);
95
+ else if (key === "description" || key === "target" || key === "format" || key === "value") {
96
+ if (key === "value" && value && typeof value === "object") referencesOf(value, out);
97
+ } else if (value && typeof value === "object") referencesOf(value, out);
98
+ }
99
+ return out;
100
+ }
101
+ function externalSchemaRefs(schema) {
102
+ const out = [];
103
+ for (const ref of referencesOf(schema)) {
104
+ if (!/^(hm|ipfs):\/\//.test(ref) || out.includes(ref) || loadFrom({}, ref)) continue;
105
+ out.push(ref);
106
+ }
107
+ return out;
108
+ }
109
+ async function hydrateSchemaRegistry(client, schema, registry = {}) {
110
+ const pending = [schema];
111
+ const seen = /* @__PURE__ */ new Set();
112
+ while (pending.length) {
113
+ const next = pending.pop();
114
+ if (!next) continue;
115
+ for (const ref of referencesOf(next)) {
116
+ if (!/^(hm|ipfs):\/\//.test(ref) || seen.has(ref)) continue;
117
+ seen.add(ref);
118
+ if (loadFrom(registry, ref)) continue;
119
+ const resolved = await resolveSchemaRef(client, ref);
120
+ if (!resolved.schema) continue;
121
+ registry[refToName(ref)] = resolved.schema;
122
+ pending.push(resolved.schema);
123
+ }
124
+ }
125
+ return registry;
126
+ }
127
+ async function effectiveSchemaRef(client, id, metadata) {
128
+ var _a;
129
+ const own = metadata == null ? void 0 : metadata.attributesSchema;
130
+ if (typeof own === "string" && own) return { ref: own, source: "own" };
131
+ if (!id.path || id.path.length === 0) return { ref: null, source: "none" };
132
+ const parentPath = id.path.slice(0, -1);
133
+ const parentId = unpackHmId(`hm://${id.uid}${parentPath.length ? "/" + parentPath.join("/") : ""}`);
134
+ if (!parentId) return { ref: null, source: "none" };
135
+ const parent = await client.request("Resource", parentId).catch(() => void 0);
136
+ const inherited = (parent == null ? void 0 : parent.type) === "document" ? (_a = parent.document.metadata) == null ? void 0 : _a.childAttributesSchema : null;
137
+ return typeof inherited === "string" && inherited ? { ref: inherited, source: "inherited" } : { ref: null, source: "none" };
138
+ }
139
+ var documentUrlOf = (id) => packHmId(id);
140
+ var isFixedLiteral = (schema) => schema !== void 0 && isLiteralSchema(schema);
141
+ async function loadSchemaRef(client, ref) {
142
+ if (typeof ref !== "string") {
143
+ if (!ref || typeof ref !== "object" || Array.isArray(ref)) throw new Error("A schema must be a map");
144
+ return { schema: ref, registry: await hydrateSchemaRegistry(client, ref, {}) };
145
+ }
146
+ if (HM_SCHEMAS[ref]) return { schema: HM_SCHEMAS[ref], cid: schemaCid(ref), registry: {} };
147
+ const resolved = await resolveSchemaRef(client, ref);
148
+ if (resolved.kind === "none")
149
+ throw new Error(`Not a schema reference: ${ref} (expected an ipfs:// CID or an hm:// URL)`);
150
+ if (!resolved.schema) {
151
+ if (resolved.kind === "hm-doc")
152
+ throw new Error(
153
+ `${ref} does not define a schema (no schemaDefinition on the document, or the document was not found)`
154
+ );
155
+ throw new Error(`Could not fetch the schema at ${ref}`);
156
+ }
157
+ return {
158
+ schema: resolved.schema,
159
+ cid: resolved.cid,
160
+ registry: await hydrateSchemaRegistry(client, resolved.schema, {})
161
+ };
162
+ }
163
+ async function checkDocumentSchema(client, id, metadata, content) {
164
+ const effective = await effectiveSchemaRef(client, id, metadata).catch(() => ({ ref: null, source: "none" }));
165
+ if (!effective.ref || effective.source === "none") {
166
+ return { schema: null, via: "none", required: [], missing: [], violations: [] };
167
+ }
168
+ const base = { schema: effective.ref, via: effective.source };
169
+ let loaded;
170
+ try {
171
+ loaded = await loadSchemaRef(client, effective.ref);
172
+ } catch (error) {
173
+ return { ...base, required: [], missing: [], violations: [], error: error.message };
174
+ }
175
+ const metadataSchema = documentMetadataSchema(metadataSchemaOf(loaded.schema, loaded.registry), {}, loaded.registry);
176
+ const required = structFields(metadataSchema).filter((f) => f.required).map((f) => f.name);
177
+ const present = metadata ?? {};
178
+ const missing = required.filter((name) => !(name in present));
179
+ const violations = validate(metadataSchema, present, "$.metadata", {}, loaded.registry);
180
+ if (content !== void 0) {
181
+ const contentSchema = fieldSchema(resolveSchema(HM_SCHEMAS["document"]).schema, "content");
182
+ if (contentSchema) violations.push(...validate(contentSchema, content, "$.content", {}, loaded.registry));
183
+ }
184
+ return { ...base, required, missing, violations };
185
+ }
186
+ var isPlainMap = (value) => !!value && typeof value === "object" && !Array.isArray(value) && !("/" in value);
187
+ function blobSchemaRef(value) {
188
+ if (!isPlainMap(value)) return null;
189
+ const link = value.schema;
190
+ if (typeof link === "string") return link;
191
+ if (link && typeof link === "object" && typeof link["/"] === "string") {
192
+ return `ipfs://${link["/"]}`;
193
+ }
194
+ return null;
195
+ }
196
+ function withoutSchemaLink(value) {
197
+ if (!isPlainMap(value) || blobSchemaRef(value) === null) return value;
198
+ const { schema: _link, ...rest } = value;
199
+ return rest;
200
+ }
201
+ async function checkSchemaDefinition(client, ref) {
202
+ const meta = HM_SCHEMAS["schema"];
203
+ try {
204
+ const loaded = await loadSchemaRef(client, ref);
205
+ return validate(meta, loaded.schema, "$", {}, loaded.registry);
206
+ } catch (error) {
207
+ return [error.message];
208
+ }
209
+ }
210
+
211
+ export {
212
+ bareCid,
213
+ classifyRef,
214
+ metadataSchemaOf,
215
+ schemaDefinitionCid,
216
+ fetchSchemaBlob,
217
+ documentMetadataSchema,
218
+ resolveSchemaRef,
219
+ externalSchemaRefs,
220
+ hydrateSchemaRegistry,
221
+ effectiveSchemaRef,
222
+ documentUrlOf,
223
+ isFixedLiteral,
224
+ loadSchemaRef,
225
+ checkDocumentSchema,
226
+ isPlainMap,
227
+ blobSchemaRef,
228
+ withoutSchemaLink,
229
+ checkSchemaDefinition
230
+ };
@@ -0,0 +1,110 @@
1
+ // src/dag-json.ts
2
+ import { CID } from "multiformats/cid";
3
+ function isRecord(value) {
4
+ return !!value && typeof value === "object" && !Array.isArray(value);
5
+ }
6
+ function isDagJsonLink(value) {
7
+ return isRecord(value) && Object.keys(value).length === 1 && typeof value["/"] === "string";
8
+ }
9
+ function isDagJsonBytes(value) {
10
+ if (!isRecord(value) || Object.keys(value).length !== 1) return false;
11
+ const slash = value["/"];
12
+ return isRecord(slash) && Object.keys(slash).length === 1 && typeof slash.bytes === "string";
13
+ }
14
+ function parseCidString(text) {
15
+ try {
16
+ return CID.parse(text.trim());
17
+ } catch {
18
+ return null;
19
+ }
20
+ }
21
+ function base64ToBytes(b64) {
22
+ const normalized = b64.replace(/\s+/g, "");
23
+ const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
24
+ const binary = atob(padded);
25
+ const bytes = new Uint8Array(binary.length);
26
+ for (let i = 0; i < binary.length; i++) {
27
+ bytes[i] = binary.charCodeAt(i);
28
+ }
29
+ return bytes;
30
+ }
31
+ function bytesToBase64(bytes) {
32
+ let binary = "";
33
+ const chunkSize = 32768;
34
+ for (let i = 0; i < bytes.length; i += chunkSize) {
35
+ binary += String.fromCharCode.apply(null, Array.from(bytes.subarray(i, i + chunkSize)));
36
+ }
37
+ return btoa(binary).replace(/=+$/, "");
38
+ }
39
+ function formatByteSize(size) {
40
+ if (size < 1024) return `${size} ${size === 1 ? "byte" : "bytes"}`;
41
+ if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
42
+ return `${(size / (1024 * 1024)).toFixed(1)} MB`;
43
+ }
44
+ var SEED_INDEXED_TYPE_NAMES = ["Comment", "Change", "Ref", "Capability", "Contact", "Profile"];
45
+ var utf8Encoder = new TextEncoder();
46
+ function cborShortText(text) {
47
+ const body = utf8Encoder.encode(text);
48
+ const bytes = new Uint8Array(body.length + 1);
49
+ bytes[0] = 96 + body.length;
50
+ bytes.set(body, 1);
51
+ return bytes;
52
+ }
53
+ function bytesContain(haystack, needle) {
54
+ outer: for (let i = 0; i + needle.length <= haystack.length; i++) {
55
+ for (let j = 0; j < needle.length; j++) {
56
+ if (haystack[i + j] !== needle[j]) continue outer;
57
+ }
58
+ return true;
59
+ }
60
+ return false;
61
+ }
62
+ function findSeedIndexerCollision(data) {
63
+ const typeKey = cborShortText("type");
64
+ for (const name of SEED_INDEXED_TYPE_NAMES) {
65
+ const value = cborShortText(name);
66
+ const matcher = new Uint8Array(typeKey.length + value.length);
67
+ matcher.set(typeKey, 0);
68
+ matcher.set(value, typeKey.length);
69
+ if (bytesContain(data, matcher)) return name;
70
+ }
71
+ return null;
72
+ }
73
+ function dagJsonToIpld(value) {
74
+ if (isDagJsonLink(value)) {
75
+ const cid = parseCidString(value["/"]);
76
+ if (!cid) throw new Error(`Invalid CID link: ${value["/"]}`);
77
+ return cid;
78
+ }
79
+ if (isDagJsonBytes(value)) {
80
+ return base64ToBytes(value["/"].bytes);
81
+ }
82
+ if (Array.isArray(value)) return value.map(dagJsonToIpld);
83
+ if (isRecord(value)) {
84
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, dagJsonToIpld(child)]));
85
+ }
86
+ return value;
87
+ }
88
+ function ipldToDagJson(value) {
89
+ if (value instanceof Uint8Array) return { "/": { bytes: bytesToBase64(value) } };
90
+ if (value && typeof value === "object" && "asCID" in value && value.asCID) {
91
+ return { "/": value.toString() };
92
+ }
93
+ if (Array.isArray(value)) return value.map(ipldToDagJson);
94
+ if (isRecord(value)) {
95
+ return Object.fromEntries(Object.entries(value).map(([key, child]) => [key, ipldToDagJson(child)]));
96
+ }
97
+ return value;
98
+ }
99
+
100
+ export {
101
+ isDagJsonLink,
102
+ isDagJsonBytes,
103
+ parseCidString,
104
+ base64ToBytes,
105
+ bytesToBase64,
106
+ formatByteSize,
107
+ findSeedIndexerCollision,
108
+ dagJsonToIpld,
109
+ ipldToDagJson
110
+ };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  normalizeQuerySort,
3
3
  unpackHmId
4
- } from "./chunk-VNZHLLJE.mjs";
4
+ } from "./chunk-MK35Y35R.mjs";
5
5
 
6
6
  // src/blocks-to-markdown.ts
7
7
  import { stringify as stringifyYaml } from "yaml";
@@ -12,8 +12,8 @@ var FM_KEY_ORDER = [
12
12
  "cover",
13
13
  "displayAuthor",
14
14
  "displayPublishTime",
15
- "schema",
16
- "childrenSchema",
15
+ "attributesSchema",
16
+ "childAttributesSchema",
17
17
  "schemaDefinition",
18
18
  "siteUrl",
19
19
  "layout",