@seedprotocol/rdf 0.0.0-stage → 0.8.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/dist/index.js ADDED
@@ -0,0 +1,388 @@
1
+ import { _ as e, a as t, b as n, c as r, d as i, f as a, g as o, h as s, i as c, l, m as u, n as d, o as f, p, r as m, s as h, t as ee, u as te, v as g, y as _ } from "./sidecar-BjHSnqHK.js";
2
+ import { getSeedAttestations as v, listRelationEasName as y } from "@seedprotocol/query";
3
+ import { sha256 as b } from "@noble/hashes/sha256";
4
+ import { bytesToHex as x, utf8ToBytes as S } from "@noble/hashes/utils";
5
+ import { easName as C } from "@seedprotocol/eas";
6
+ //#region src/graph.ts
7
+ var w = "https://schema.org/contentUrl", T = "storage_transaction_id", ne = /* @__PURE__ */ new Set([T, "storage_provider_transaction_id"]), re = "0x0000000000000000000000000000000000000000000000000000000000000020";
8
+ function ie({ schemaId: e, terms: t, "@context": n }) {
9
+ return b(S(h({
10
+ schemaId: e,
11
+ terms: t,
12
+ "@context": n ?? {}
13
+ })));
14
+ }
15
+ var ae = (e) => btoa(String.fromCharCode(...e)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), E = (e) => ({
16
+ kind: "iri",
17
+ iri: e
18
+ }), D = (e, t) => ({
19
+ kind: "literal",
20
+ value: e,
21
+ datatype: t
22
+ });
23
+ function O(e) {
24
+ return D((/* @__PURE__ */ new Date(e * 1e3)).toISOString().replace(".000Z", "Z"), `${g}dateTime`);
25
+ }
26
+ var k = /^0x([0-9a-fA-F]*)$/, A = /^[+-]?(?:\d+\.\d*|\.\d+)$/, j = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)[eE][+-]?\d+$/, M = 864e10;
27
+ function N(e) {
28
+ if (/^[+-]?\d+$/.test(e)) return D(e, `${g}integer`);
29
+ if (A.test(e)) return D(e, `${g}decimal`);
30
+ if (j.test(e) && Number.isFinite(Number(e))) return D(Number(e).toExponential(15).replace(/(\d)0*e\+?/, "$1E"), `${g}double`);
31
+ }
32
+ function P(e, t, n, r) {
33
+ if (typeof n == "string") {
34
+ if (e === "number" && t === "string") {
35
+ let e = N(n);
36
+ return e || r(`"${n}" isn't a number; exported as a string`), e;
37
+ }
38
+ if (e === "date" && /^u?int\d*$/.test(t) && Math.abs(Number(n)) <= M) return O(Number(n));
39
+ }
40
+ }
41
+ function F(e, t) {
42
+ if (typeof t == "boolean") return D(String(t), `${g}boolean`);
43
+ if (/^u?int\d*$/.test(e) && /^-?\d+$/.test(t)) return D(t, `${g}integer`);
44
+ let n = /^bytes\d*$/.test(e) ? k.exec(t) : null;
45
+ return n && n[1].length % 2 == 0 ? D(n[1].toLowerCase(), `${g}hexBinary`) : D(t, `${g}string`);
46
+ }
47
+ var I = (e) => e.kind === "iri" ? `<${e.iri}>` : e.kind === "literal" ? `${e.value}^^${e.datatype}` : void 0, L = (e, t) => e < t ? -1 : +(e > t), R = (e, t) => L(e.easName, t.easName) || L(e.easType, t.easType) || L(e.attestationUid, t.attestationUid), z = class {
48
+ id;
49
+ properties = /* @__PURE__ */ new Map();
50
+ seen = /* @__PURE__ */ new Set();
51
+ constructor(e) {
52
+ this.id = e;
53
+ }
54
+ add(e, t) {
55
+ let n = I(t);
56
+ if (n !== void 0) {
57
+ if (this.seen.has(`${e} ${n}`)) return;
58
+ this.seen.add(`${e} ${n}`);
59
+ }
60
+ let r = this.properties.get(e);
61
+ r ? r.push(t) : this.properties.set(e, [t]);
62
+ }
63
+ };
64
+ function B(e, t, n, r) {
65
+ let { easType: i, value: a } = t;
66
+ if (t.isRelation) {
67
+ let t = (typeof a == "string" ? [a] : Array.isArray(a) ? a : []).filter((e) => e !== re);
68
+ return typeof a == "string" ? t[0] ? E(e.attestation(t[0])) : null : {
69
+ kind: "list",
70
+ items: t.map((t) => E(e.attestation(t)))
71
+ };
72
+ }
73
+ if (Array.isArray(a)) {
74
+ let e = i.replace(/\[\]$/, "");
75
+ return {
76
+ kind: "list",
77
+ items: a.map((t) => F(e, t))
78
+ };
79
+ }
80
+ return (n ? P(n, i, a, r) : void 0) ?? F(i, a);
81
+ }
82
+ function V(t, a) {
83
+ let o = n(a.chainId, a.base), s = o.seed, c = a.lens && r(a.lens), l = c?.warnings ?? [], u = (e) => {
84
+ l.includes(e) || l.push(e);
85
+ }, d = /* @__PURE__ */ new Map(), f = (e) => {
86
+ let t = d.get(e);
87
+ return t || d.set(e, t = new z(e)), t;
88
+ };
89
+ for (let { record: n, properties: r, versions: l = [] } of t) {
90
+ if (d.has(o.attestation(n.seedUid))) continue;
91
+ let t = f(o.attestation(n.seedUid));
92
+ t.add(e, E(`${s}Seed`)), t.add(e, E(c?.classOf(n.schemaName) ?? o.modelClass(n.schemaName))), n.attester && t.add(`${i}wasAttributedTo`, E(o.account(n.attester))), n.timeCreated > 0 && t.add(`${i}generatedAtTime`, O(n.timeCreated)), n.versionUid && t.add(`${s}currentVersion`, E(o.attestation(n.versionUid)));
93
+ let p = l.length > 0 ? l : n.versionUid ? [{
94
+ attestationUid: n.versionUid,
95
+ timeCreated: 0
96
+ }] : [], m;
97
+ for (let { attestationUid: n, attester: r, timeCreated: a } of p) {
98
+ let c = f(o.attestation(n));
99
+ c.add(e, E(`${s}Version`)), c.add(`${s}versionOf`, E(t.id)), a > 0 && c.add(`${i}generatedAtTime`, O(a)), r && c.add(`${i}wasAttributedTo`, E(o.account(r))), m && c.add(`${i}wasRevisionOf`, E(m)), m = c.id;
100
+ }
101
+ for (let e of [...r].sort(R)) {
102
+ let r = ne.has(e.easName) ? void 0 : c?.propertyOf(n.schemaName, e.easName), i = B(o, e, r?.dataType, u);
103
+ if (i && (t.add(r?.term ?? o.property(e.easType, e.easName), i), e.easName === T && typeof e.value == "string" && e.value)) {
104
+ let n = encodeURIComponent(e.value);
105
+ t.add(`${s}content`, E(`ar://${n}`)), a.contentUrl && t.add(w, E(_(a.contentUrl(e.value), "contentUrl")));
106
+ }
107
+ }
108
+ }
109
+ if (a.lens) {
110
+ let t = ie(a.lens.sidecar), n = f(`${o.base}export/${x(t)}`);
111
+ n.add(e, E(`${i}Activity`)), n.add(`${i}used`, E(`ni:///sha-256;${ae(t)}`));
112
+ }
113
+ return {
114
+ iris: o,
115
+ nodes: [...d.values()],
116
+ prefixes: c?.prefixes ?? /* @__PURE__ */ new Map(),
117
+ warnings: l
118
+ };
119
+ }
120
+ //#endregion
121
+ //#region src/quads.ts
122
+ var H = `${g}string`, U = class {
123
+ value;
124
+ termType = "NamedNode";
125
+ constructor(e) {
126
+ this.value = e;
127
+ }
128
+ equals(e) {
129
+ return !!e && e.termType === this.termType && e.value === this.value;
130
+ }
131
+ }, W = class {
132
+ value;
133
+ termType = "BlankNode";
134
+ constructor(e) {
135
+ this.value = e;
136
+ }
137
+ equals(e) {
138
+ return !!e && e.termType === this.termType && e.value === this.value;
139
+ }
140
+ }, G = class {
141
+ value;
142
+ termType = "Literal";
143
+ language = "";
144
+ direction = "";
145
+ datatype;
146
+ constructor(e, t) {
147
+ this.value = e, this.datatype = new U(t);
148
+ }
149
+ equals(e) {
150
+ return !!e && e.termType === this.termType && e.value === this.value && e.language === "" && e.datatype.equals(this.datatype);
151
+ }
152
+ }, K = new class {
153
+ termType = "DefaultGraph";
154
+ value = "";
155
+ equals(e) {
156
+ return !!e && e.termType === this.termType;
157
+ }
158
+ }(), q = class {
159
+ subject;
160
+ predicate;
161
+ object;
162
+ termType = "Quad";
163
+ value = "";
164
+ graph = K;
165
+ constructor(e, t, n) {
166
+ this.subject = e, this.predicate = t, this.object = n;
167
+ }
168
+ equals(e) {
169
+ return !e || e.termType !== "Quad" ? !1 : this.subject.equals(e.subject) && this.predicate.equals(e.predicate) && this.object.equals(e.object) && this.graph.equals(e.graph);
170
+ }
171
+ };
172
+ function J(e) {
173
+ let t = [], n = 0, r = (e) => {
174
+ if (e.kind === "iri") return new U(e.iri);
175
+ if (e.kind === "literal") return new G(e.value, e.datatype);
176
+ if (e.items.length === 0) return new U(s);
177
+ let i = e.items.map(() => new W(`l${n++}`));
178
+ return e.items.forEach((e, n) => {
179
+ t.push(new q(i[n], new U(u), r(e))), t.push(new q(i[n], new U(o), i[n + 1] ?? new U(s)));
180
+ }), i[0];
181
+ };
182
+ for (let n of e.nodes) {
183
+ let e = new U(n.id);
184
+ for (let [i, a] of n.properties) for (let n of a) t.push(new q(e, new U(i), r(n)));
185
+ }
186
+ return t;
187
+ }
188
+ var Y = (e) => e.replace(/[\\"\n\r]/g, (e) => e === "\\" ? "\\\\" : e === "\"" ? "\\\"" : e === "\n" ? "\\n" : "\\r");
189
+ function X(e) {
190
+ if (e.termType === "NamedNode") return `<${e.value}>`;
191
+ if (e.termType === "BlankNode") return `_:${e.value}`;
192
+ if (e.termType === "Literal") {
193
+ let t = `"${Y(e.value)}"`;
194
+ return e.datatype.value === H ? t : `${t}^^<${e.datatype.value}>`;
195
+ }
196
+ throw TypeError(`Can't write a ${e.termType} term`);
197
+ }
198
+ function oe(e) {
199
+ return J(e).map((e) => `${X(e.subject)} ${X(e.predicate)} ${X(e.object)} .\n`).join("");
200
+ }
201
+ //#endregion
202
+ //#region src/names.ts
203
+ var se = /^[A-Za-z_][A-Za-z0-9_-]*$/, ce = /^[a-z][a-z0-9]*$/, le = /^[A-Za-z][A-Za-z0-9_-]*$/;
204
+ function Z(e) {
205
+ let { base: t } = e.iris, n = /* @__PURE__ */ new Map([
206
+ ["rdf", p],
207
+ ["xsd", g],
208
+ ["prov", i],
209
+ ["schema", "https://schema.org/"],
210
+ ["seed", e.iris.seed],
211
+ ["c", `${t}c/`]
212
+ ]);
213
+ for (let r of e.nodes) for (let e of r.properties.keys()) {
214
+ if (!e.startsWith(`${t}p/`)) continue;
215
+ let r = e.slice(t.length + 2).split("/")[0];
216
+ ce.test(r) && n.set(`p_${r}`, `${t}p/${r}/`);
217
+ }
218
+ for (let [t, r] of e.prefixes) le.test(t) && /[/#:]$/.test(r) && !n.has(t) && n.set(t, r);
219
+ return n;
220
+ }
221
+ function Q(e) {
222
+ let t = /* @__PURE__ */ new Set();
223
+ return {
224
+ compact: (n) => {
225
+ let r;
226
+ for (let [t, i] of e) {
227
+ if (!n.startsWith(i) || r && e.get(r[0]).length >= i.length) continue;
228
+ let a = n.slice(i.length);
229
+ se.test(a) && (r = [t, a]);
230
+ }
231
+ return r && t.add(r[0]), r;
232
+ },
233
+ used: t
234
+ };
235
+ }
236
+ //#endregion
237
+ //#region src/turtle.ts
238
+ function $(t) {
239
+ let n = Z(t), { compact: r, used: i } = Q(n), a = (e) => {
240
+ let t = r(e);
241
+ return t ? `${t[0]}:${t[1]}` : `<${e}>`;
242
+ }, o = (e) => {
243
+ if (e.kind === "iri") return a(e.iri);
244
+ if (e.kind === "list") return e.items.length === 0 ? a(`${p}nil`) : `( ${e.items.map(o).join(" ")} )`;
245
+ let t = `"${Y(e.value)}"`;
246
+ return e.datatype === "http://www.w3.org/2001/XMLSchema#string" ? t : `${t}^^${a(e.datatype)}`;
247
+ }, s = t.nodes.map((t) => {
248
+ let n = [...t.properties].map(([t, n]) => ` ${t === e ? "a" : a(t)} ${n.map(o).join(", ")}`);
249
+ return `${a(t.id)}\n${n.join(" ;\n")} .\n`;
250
+ }), c = [...n].filter(([e]) => i.has(e)).map(([e, t]) => `@prefix ${e}: <${t}> .\n`).join("");
251
+ return `${c}${c ? "\n" : ""}${s.join("\n")}`;
252
+ }
253
+ //#endregion
254
+ //#region src/jsonld.ts
255
+ function ue(t) {
256
+ let n = Z(t);
257
+ n.delete("rdf");
258
+ let { compact: r, used: i } = Q(n), a = (e) => {
259
+ let t = r(e);
260
+ return t ? `${t[0]}:${t[1]}` : e;
261
+ }, o = (e) => e.kind === "iri" ? { "@id": e.iri } : e.kind === "list" ? { "@list": e.items.map(o) } : e.datatype === "http://www.w3.org/2001/XMLSchema#string" ? e.value : e.datatype === "http://www.w3.org/2001/XMLSchema#boolean" ? e.value === "true" : {
262
+ "@value": e.value,
263
+ "@type": a(e.datatype)
264
+ }, s = t.nodes.map((t) => {
265
+ let n = { "@id": t.id };
266
+ for (let [r, i] of t.properties) {
267
+ if (r === e) {
268
+ n["@type"] = i.map((e) => e.kind === "iri" ? a(e.iri) : "").filter(Boolean);
269
+ continue;
270
+ }
271
+ let t = i.map(o);
272
+ n[a(r)] = t.length === 1 ? t[0] : t;
273
+ }
274
+ return n;
275
+ }), c = {};
276
+ for (let [e, t] of n) i.has(e) && (c[e] = t);
277
+ return {
278
+ "@context": c,
279
+ "@graph": s
280
+ };
281
+ }
282
+ //#endregion
283
+ //#region src/vocabulary.ts
284
+ function de(e = a) {
285
+ return _(e, "base"), `@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
286
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
287
+ @prefix seed: <${e}ns#> .
288
+
289
+ seed:Seed a rdfs:Class ;
290
+ rdfs:label "Seed" ;
291
+ rdfs:comment "An item: the EAS attestation that names it. Its IRI carries the chain id and attestation uid." .
292
+
293
+ seed:Version a rdfs:Class ;
294
+ rdfs:label "Version" ;
295
+ rdfs:comment "A version of a Seed: an EAS attestation whose refUID is the Seed. Property attestations reference a Version." .
296
+
297
+ seed:versionOf a rdf:Property ;
298
+ rdfs:label "version of" ;
299
+ rdfs:domain seed:Version ;
300
+ rdfs:range seed:Seed .
301
+
302
+ seed:currentVersion a rdf:Property ;
303
+ rdfs:label "current version" ;
304
+ rdfs:comment "The Version the exported values were read from." ;
305
+ rdfs:domain seed:Seed ;
306
+ rdfs:range seed:Version .
307
+
308
+ seed:content a rdf:Property ;
309
+ rdfs:label "content" ;
310
+ rdfs:comment "The stored bytes of an Image, File, Html or Json seed, as an ar:// IRI." ;
311
+ rdfs:domain seed:Seed .
312
+ `;
313
+ }
314
+ //#endregion
315
+ //#region src/shacl.ts
316
+ var fe = "http://www.w3.org/ns/shacl#", pe = {
317
+ text: ["string"],
318
+ number: [
319
+ "integer",
320
+ "decimal",
321
+ "double"
322
+ ],
323
+ boolean: ["boolean"],
324
+ date: ["dateTime"]
325
+ }, me = {
326
+ text: "string",
327
+ number: "string",
328
+ boolean: "bool",
329
+ date: "uint256",
330
+ list: "bytes32[]"
331
+ };
332
+ function he(e, t = {}) {
333
+ let { schema: r, sidecar: i } = e;
334
+ if (!r.id || r.id !== i.schemaId) throw TypeError(`The sidecar is for schema ${i.schemaId}, not ${r.id ?? "a schema with no id"}`);
335
+ let a = n(1, t.base), o = te(i), s = (e) => {
336
+ let t = e ? i.terms[e] : void 0;
337
+ return t === void 0 ? void 0 : l(t, o);
338
+ }, c = (e) => `"${Y(e)}"`, u = Object.entries(r.models).map(([e, t]) => {
339
+ let n = Object.entries(t.properties).flatMap(([e, t]) => {
340
+ let n = (t.type ?? t.dataType ?? "").toLowerCase(), r = t.ref ?? t.refModelName, i = f.has(n), o = i ? "bytes32" : me[n];
341
+ if (!o) return [];
342
+ let l = n === "list" && r ? y(e, r) : C(e), u = `<${s(t.id) ?? a.property(o, l)}>`, d = [
343
+ `sh:path ${u}`,
344
+ `sh:name ${c(e)}`,
345
+ "sh:maxCount 1"
346
+ ];
347
+ t.required === !0 && d.push("sh:minCount 1");
348
+ let p = pe[n];
349
+ p?.length === 1 ? d.push(`sh:datatype xsd:${p[0]}`) : p ? d.push(`sh:or ( ${p.map((e) => `[ sh:datatype xsd:${e} ]`).join(" ")} )`) : i && d.push("sh:nodeKind sh:IRI");
350
+ let m = [d];
351
+ return n === "list" && m.push([`sh:path ( ${u} [ sh:zeroOrMorePath rdf:rest ] )`, "sh:node _:listCell"]), n === "list" && r && m.push([`sh:path ( ${u} [ sh:zeroOrMorePath rdf:rest ] rdf:first )`, "sh:nodeKind sh:IRI"]), m.map((e) => ` sh:property [\n ${e.join(" ;\n ")}\n ]`);
352
+ }), r = s(t.id) ?? a.modelClass(C(e));
353
+ return `${[
354
+ "[] a sh:NodeShape",
355
+ ` sh:name ${c(e)}`,
356
+ ` sh:targetClass <${r}>`,
357
+ ...n
358
+ ].join(" ;\n")} .\n`;
359
+ });
360
+ return `${[
361
+ ["sh", fe],
362
+ ["rdf", p],
363
+ ["xsd", g]
364
+ ].map(([e, t]) => `@prefix ${e}: <${t}> .\n`).join("")}\n_:listCell a sh:NodeShape ;
365
+ sh:or (
366
+ [ sh:hasValue rdf:nil ]
367
+ [
368
+ sh:nodeKind sh:BlankNodeOrIRI ;
369
+ sh:property [ sh:path rdf:first ; sh:minCount 1 ; sh:maxCount 1 ] ;
370
+ sh:property [ sh:path rdf:rest ; sh:minCount 1 ; sh:maxCount 1 ]
371
+ ]
372
+ ) .
373
+ \n${u.join("\n")}`;
374
+ }
375
+ //#endregion
376
+ //#region src/index.ts
377
+ async function ge(e, t) {
378
+ let { source: n, pins: r, asOf: i, ...a } = t;
379
+ return V([...(await v(e, {
380
+ source: n,
381
+ pins: r,
382
+ asOf: i
383
+ })).values()], a);
384
+ }
385
+ //#endregion
386
+ export { a as PROVISIONAL_BASE_IRI, ee as SUGGESTED_PREFIXES, d as checkSidecar, ge as exportSeeds, n as iriScheme, de as seedVocabulary, m as sidecarContext, V as stateGraph, c as suggestTerms, t as syncSidecar, ue as toJsonLd, oe as toNQuads, J as toQuads, he as toShacl, $ as toTurtle };
387
+
388
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["RDF_TYPE","syncSidecar","iriScheme","compileLens","PROV","PROVISIONAL_BASE_IRI","RDF_REST","RDF_NIL","suggestTerms","RDF_FIRST","checkSidecar","RELATION_TYPES","sidecarContext","canonicalJson","SUGGESTED_PREFIXES","prefixesOf","XSD","assertIri","SCHEMA_CONTENT_URL","STORAGE_TRANSACTION","STORAGE_NAMES","NOT_A_SEED","sidecarHash","context","sha256","utf8ToBytes","base64Url","bytes","iri","value","literal","dateTime","seconds","HEX","DECIMAL","DOUBLE","MAX_DATE_SECONDS","numberLiteral","typedByLens","dataType","easType","number","warn","scalar","hex","objectKey","object","compare","a","b","byName","NodeBuilder","id","key","predicate","objects","propertyObject","property","seeds","uid","iris","itemType","v","stateGraph","options","ns","lens","warnings","message","nodes","node","found","record","seed","history","versions","previous","version","attestationUid","timeCreated","attester","properties","local","transactionId","hash","activity","bytesToHex","XSD_STRING","NamedNode","other","BlankNode","Literal","datatype","DEFAULT_GRAPH","Quad","subject","toQuads","quads","cells","term","heads","i","item","graph","escapeLiteral","c","writeTerm","quoted","toNQuads","q","SAFE_LOCAL","SAFE_PREFIX","SAFE_LENS_PREFIX","prefixesFor","prefixes","RDF","base","prefix","compacter","used","best","toTurtle","name","short","compact","o","blocks","lines","header","toJsonLd","toPrefixed","out","values","seedVocabulary","SH","DATATYPES","EAS_TYPES","toShacl","schema","sidecar","termOf","expandTerm","shapes","modelName","model","ref","relation","listRelationEasName","easName","path","datatypes","d","shape","targetClass","exportSeeds","graphOptions","getSeedAttestations","seedUids"],"sources":["../src/graph.ts","../src/quads.ts","../src/names.ts","../src/turtle.ts","../src/jsonld.ts","../src/vocabulary.ts","../src/shacl.ts","../src/index.ts"],"sourcesContent":["import { sha256 } from '@noble/hashes/sha256'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils'\nimport type { SeedAttestations, SeedPropertyAttestation, SeedVersionAttestation } from '@seedprotocol/query'\nimport { PROV, RDF_TYPE, XSD, assertIri, iriScheme, type IriScheme } from './iri.js'\nimport { canonicalJson, compileLens, type CompiledLens, type RdfLens, type RdfSidecar } from './lens.js'\n\n/** An IRI, a typed literal, or an RDF list of either. */\nexport type RdfObject =\n | { readonly kind: 'iri'; readonly iri: string }\n | { readonly kind: 'literal'; readonly value: string; readonly datatype: string }\n | { readonly kind: 'list'; readonly items: readonly RdfObject[] }\n\n/** One subject and its statements, predicates in the order they were added. */\nexport type RdfNode = {\n readonly id: string\n readonly properties: ReadonlyMap<string, readonly RdfObject[]>\n}\n\n/**\n * A state graph: each seed's current values at its head Version, in the default graph. Every\n * subject is an IRI; the only blank nodes are the cells of RDF lists, which writers create.\n */\nexport type StateGraph = {\n readonly iris: IriScheme\n readonly nodes: readonly RdfNode[]\n /** Prefixes from the lens, for the writers. */\n readonly prefixes: ReadonlyMap<string, string>\n /** Lens terms that couldn't be used, and values that don't fit their data type. Empty without a lens. */\n readonly warnings: readonly string[]\n}\n\nexport type StateGraphOptions = {\n /** The chain the seeds were attested on. EAS uids don't include it, so every IRI does. */\n chainId: number\n /** Base of the minted IRIs. Default PROVISIONAL_BASE_IRI. */\n base?: string\n /**\n * An `https://` URL for an Arweave transaction, given as `schema:contentUrl` beside the\n * `ar://` content IRI, since most RDF tools can't fetch `ar://`. None by default.\n */\n contentUrl?: (transactionId: string) => string\n /**\n * The app's Schema and sidecar. Mapped classes and predicates replace the protocol IRIs in the\n * graph, and a Number or Date gets its literal type. None by default.\n */\n lens?: RdfLens\n}\n\nconst SCHEMA_CONTENT_URL = 'https://schema.org/contentUrl'\nconst STORAGE_TRANSACTION = 'storage_transaction_id'\nconst STORAGE_NAMES = new Set([STORAGE_TRANSACTION, 'storage_provider_transaction_id'])\n// Assembly skips this value as a relation (see relationValuesToExclude in @seedprotocol/query).\nconst NOT_A_SEED = '0x0000000000000000000000000000000000000000000000000000000000000020'\n\n/**\n * The SHA-256 of the parts of a sidecar the lens reads (`schemaId`, `terms`, `@context`), as\n * canonical JSON with sorted keys. `schemaVersion` is left out: it changes no term.\n */\nfunction sidecarHash({ schemaId, terms, '@context': context }: RdfSidecar): Uint8Array {\n return sha256(utf8ToBytes(canonicalJson({ schemaId, terms, '@context': context ?? {} })))\n}\n\nconst base64Url = (bytes: Uint8Array): string =>\n btoa(String.fromCharCode(...bytes)).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/, '')\n\nconst iri = (value: string): RdfObject => ({ kind: 'iri', iri: value })\nconst literal = (value: string, datatype: string): RdfObject => ({ kind: 'literal', value, datatype })\n\n/** `xsd:dateTime` in UTC for Unix seconds. */\nfunction dateTime(seconds: number): RdfObject {\n return literal(new Date(seconds * 1000).toISOString().replace('.000Z', 'Z'), `${XSD}dateTime`)\n}\n\nconst HEX = /^0x([0-9a-fA-F]*)$/\nconst DECIMAL = /^[+-]?(?:\\d+\\.\\d*|\\.\\d+)$/\nconst DOUBLE = /^[+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)[eE][+-]?\\d+$/\nconst MAX_DATE_SECONDS = 8.64e12\n\n/** The literal for a Number's string (ADR 0010), typed per value: `1e+21` is no `xsd:decimal`. */\nfunction numberLiteral(value: string): RdfObject | undefined {\n if (/^[+-]?\\d+$/.test(value)) return literal(value, `${XSD}integer`)\n if (DECIMAL.test(value)) return literal(value, `${XSD}decimal`)\n if (!DOUBLE.test(value) || !Number.isFinite(Number(value))) return undefined\n // The canonical form, which JSON-LD processors write: RDFC-1.0 compares literals as text.\n return literal(Number(value).toExponential(15).replace(/(\\d)0*e\\+?/, '$1E'), `${XSD}double`)\n}\n\n/** The literal for a value of local type `dataType`, or undefined when the type doesn't change it. */\nfunction typedByLens(dataType: string, easType: string, value: unknown, warn: (message: string) => void): RdfObject | undefined {\n if (typeof value !== 'string') return undefined\n if (dataType === 'number' && easType === 'string') {\n const number = numberLiteral(value)\n if (!number) warn(`\"${value}\" isn't a number; exported as a string`)\n return number\n }\n if (dataType === 'date' && /^u?int\\d*$/.test(easType) && Math.abs(Number(value)) <= MAX_DATE_SECONDS) {\n return dateTime(Number(value))\n }\n return undefined\n}\n\n/** The literal for one non-relation value of EAS type `easType`. */\nfunction scalar(easType: string, value: string | boolean): RdfObject {\n if (typeof value === 'boolean') return literal(String(value), `${XSD}boolean`)\n if (/^u?int\\d*$/.test(easType) && /^-?\\d+$/.test(value)) return literal(value, `${XSD}integer`)\n const hex = /^bytes\\d*$/.test(easType) ? HEX.exec(value) : null\n if (hex && hex[1]!.length % 2 === 0) return literal(hex[1]!.toLowerCase(), `${XSD}hexBinary`)\n return literal(value, `${XSD}string`)\n}\n\nconst objectKey = (object: RdfObject): string | undefined =>\n object.kind === 'iri' ? `<${object.iri}>` : object.kind === 'literal' ? `${object.value}^^${object.datatype}` : undefined\n\nconst compare = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0)\nconst byName = (a: SeedPropertyAttestation, b: SeedPropertyAttestation): number =>\n compare(a.easName, b.easName) || compare(a.easType, b.easType) || compare(a.attestationUid, b.attestationUid)\n\nclass NodeBuilder {\n readonly properties = new Map<string, RdfObject[]>()\n // A graph is a set: the same statement twice is written once.\n private readonly seen = new Set<string>()\n constructor(readonly id: string) {}\n add(predicate: string, object: RdfObject): void {\n const key = objectKey(object)\n if (key !== undefined) {\n if (this.seen.has(`${predicate} ${key}`)) return\n this.seen.add(`${predicate} ${key}`)\n }\n const objects = this.properties.get(predicate)\n if (objects) objects.push(object)\n else this.properties.set(predicate, [object])\n }\n}\n\nfunction propertyObject(\n iris: IriScheme,\n property: SeedPropertyAttestation,\n dataType: string | undefined,\n warn: (message: string) => void,\n): RdfObject | null {\n const { easType, value } = property\n if (property.isRelation) {\n const seeds = (typeof value === 'string' ? [value] : Array.isArray(value) ? value : []).filter(\n (uid) => uid !== NOT_A_SEED,\n )\n if (typeof value === 'string') return seeds[0] ? iri(iris.attestation(seeds[0])) : null\n return { kind: 'list', items: seeds.map((uid) => iri(iris.attestation(uid))) }\n }\n if (Array.isArray(value)) {\n const itemType = easType.replace(/\\[\\]$/, '')\n return { kind: 'list', items: value.map((v: string) => scalar(itemType, v)) }\n }\n const typed = dataType ? typedByLens(dataType, easType, value, warn) : undefined\n return typed ?? scalar(easType, value as string | boolean)\n}\n\n/**\n * The state graph of `seeds` (from `getSeedAttestations` in @seedprotocol/query). Each seed is\n * typed `seed:Seed` and its model class (`{base}c/{model}`), attributed to its attester as a\n * `did:pkh`, and linked to its head Version (`seed:currentVersion`). Its live Versions up to the head\n * are `seed:Version`s with `prov:generatedAtTime`, `prov:wasAttributedTo`, and `prov:wasRevisionOf`\n * the Version before; revoked Versions are left out, as in an archive bag. Each property is one statement with the protocol\n * predicate `{base}p/{easType}/{easName}`. Relations are Seed IRIs, lists are RDF lists, and an\n * Image, File, Html or Json seed's `storage_transaction_id` also gives `seed:content <ar://…>`.\n * Without a lens, values are typed from the EAS type alone: a Number (an EAS `string`, ADR 0010)\n * is an `xsd:string`, and a Date (`uint256` seconds) an `xsd:integer`. With one, a Number is typed\n * per value and a Date is an `xsd:dateTime`, and mapped terms replace the protocol IRIs, and the\n * graph gets a `prov:Activity` `{base}export/{sha256}` whose `prov:used` is the sidecar's hash as\n * an RFC 6920 `ni:///sha-256;…` IRI. That IRI is under the provisional base: keep it out of\n * anything anchored, such as an archive bag.\n */\nexport function stateGraph(seeds: readonly SeedAttestations[], options: StateGraphOptions): StateGraph {\n const iris = iriScheme(options.chainId, options.base)\n const ns = iris.seed\n const lens: CompiledLens | undefined = options.lens && compileLens(options.lens)\n const warnings = lens?.warnings ?? []\n const warn = (message: string) => {\n if (!warnings.includes(message)) warnings.push(message)\n }\n const nodes = new Map<string, NodeBuilder>()\n const node = (id: string) => {\n let found = nodes.get(id)\n if (!found) nodes.set(id, (found = new NodeBuilder(id)))\n return found\n }\n\n for (const { record, properties, versions = [] } of seeds) {\n if (nodes.has(iris.attestation(record.seedUid))) continue\n const seed = node(iris.attestation(record.seedUid))\n seed.add(RDF_TYPE, iri(`${ns}Seed`))\n seed.add(RDF_TYPE, iri(lens?.classOf(record.schemaName) ?? iris.modelClass(record.schemaName)))\n if (record.attester) seed.add(`${PROV}wasAttributedTo`, iri(iris.account(record.attester)))\n if (record.timeCreated > 0) seed.add(`${PROV}generatedAtTime`, dateTime(record.timeCreated))\n\n if (record.versionUid) seed.add(`${ns}currentVersion`, iri(iris.attestation(record.versionUid)))\n // The history ends at the current Version; without one (an older query), that Version alone.\n const history: readonly SeedVersionAttestation[] =\n versions.length > 0 ? versions : record.versionUid ? [{ attestationUid: record.versionUid, timeCreated: 0 }] : []\n let previous: string | undefined\n for (const { attestationUid, attester, timeCreated } of history) {\n const version = node(iris.attestation(attestationUid))\n version.add(RDF_TYPE, iri(`${ns}Version`))\n version.add(`${ns}versionOf`, iri(seed.id))\n if (timeCreated > 0) version.add(`${PROV}generatedAtTime`, dateTime(timeCreated))\n if (attester) version.add(`${PROV}wasAttributedTo`, iri(iris.account(attester)))\n if (previous) version.add(`${PROV}wasRevisionOf`, iri(previous))\n previous = version.id\n }\n\n // By name, not in the order the source returned them, so the same state gives the same bytes.\n for (const property of [...properties].sort(byName)) {\n const local = STORAGE_NAMES.has(property.easName) ? undefined : lens?.propertyOf(record.schemaName, property.easName)\n const object = propertyObject(iris, property, local?.dataType, warn)\n if (!object) continue\n seed.add(local?.term ?? iris.property(property.easType, property.easName), object)\n if (property.easName === STORAGE_TRANSACTION && typeof property.value === 'string' && property.value) {\n const transactionId = encodeURIComponent(property.value)\n seed.add(`${ns}content`, iri(`ar://${transactionId}`))\n if (options.contentUrl) {\n seed.add(SCHEMA_CONTENT_URL, iri(assertIri(options.contentUrl(property.value), 'contentUrl')))\n }\n }\n }\n }\n\n if (options.lens) {\n // The node stands for the mapping, not for one export: its IRI comes from the hash, so exports\n // made with the same sidecar name the same node. No time or agent, which would differ per export.\n const hash = sidecarHash(options.lens.sidecar)\n const activity = node(`${iris.base}export/${bytesToHex(hash)}`)\n activity.add(RDF_TYPE, iri(`${PROV}Activity`))\n activity.add(`${PROV}used`, iri(`ni:///sha-256;${base64Url(hash)}`))\n }\n\n return { iris, nodes: [...nodes.values()], prefixes: lens?.prefixes ?? new Map(), warnings }\n}\n","import type * as RDF from '@rdfjs/types'\nimport type { RdfObject, StateGraph } from './graph.js'\nimport { RDF_FIRST, RDF_NIL, RDF_REST, XSD } from './iri.js'\n\nconst XSD_STRING = `${XSD}string`\n\nclass NamedNode implements RDF.NamedNode {\n readonly termType = 'NamedNode'\n constructor(readonly value: string) {}\n equals(other: RDF.Term | null | undefined): boolean {\n return !!other && other.termType === this.termType && other.value === this.value\n }\n}\n\nclass BlankNode implements RDF.BlankNode {\n readonly termType = 'BlankNode'\n constructor(readonly value: string) {}\n equals(other: RDF.Term | null | undefined): boolean {\n return !!other && other.termType === this.termType && other.value === this.value\n }\n}\n\nclass Literal implements RDF.Literal {\n readonly termType = 'Literal'\n readonly language = ''\n readonly direction = ''\n readonly datatype: RDF.NamedNode\n constructor(\n readonly value: string,\n datatype: string,\n ) {\n this.datatype = new NamedNode(datatype)\n }\n equals(other: RDF.Term | null | undefined): boolean {\n return (\n !!other &&\n other.termType === this.termType &&\n other.value === this.value &&\n other.language === '' &&\n other.datatype.equals(this.datatype)\n )\n }\n}\n\nclass DefaultGraph implements RDF.DefaultGraph {\n readonly termType = 'DefaultGraph'\n readonly value = ''\n equals(other: RDF.Term | null | undefined): boolean {\n return !!other && other.termType === this.termType\n }\n}\n\nconst DEFAULT_GRAPH = new DefaultGraph()\n\nclass Quad implements RDF.BaseQuad {\n readonly termType = 'Quad'\n readonly value = ''\n readonly graph = DEFAULT_GRAPH\n constructor(\n readonly subject: RDF.NamedNode | RDF.BlankNode,\n readonly predicate: RDF.NamedNode,\n readonly object: RDF.NamedNode | RDF.BlankNode | RDF.Literal,\n ) {}\n equals(other: RDF.Term | null | undefined): boolean {\n if (!other || other.termType !== 'Quad') return false\n return (\n this.subject.equals(other.subject) &&\n this.predicate.equals(other.predicate) &&\n this.object.equals(other.object) &&\n this.graph.equals(other.graph)\n )\n }\n}\n\n/**\n * The graph as RDF/JS quads (`@rdfjs/types`), all in the default graph, for N3.js, Comunica,\n * Oxigraph or rdf-ext. List cells are blank nodes labelled `l0`, `l1`, … in the order written.\n */\nexport function toQuads(graph: StateGraph): RDF.Quad[] {\n const quads: RDF.Quad[] = []\n let cells = 0\n\n const term = (object: RdfObject): RDF.NamedNode | RDF.BlankNode | RDF.Literal => {\n if (object.kind === 'iri') return new NamedNode(object.iri)\n if (object.kind === 'literal') return new Literal(object.value, object.datatype)\n if (object.items.length === 0) return new NamedNode(RDF_NIL)\n const heads = object.items.map(() => new BlankNode(`l${cells++}`))\n object.items.forEach((item, i) => {\n quads.push(new Quad(heads[i]!, new NamedNode(RDF_FIRST), term(item)))\n quads.push(new Quad(heads[i]!, new NamedNode(RDF_REST), heads[i + 1] ?? new NamedNode(RDF_NIL)))\n })\n return heads[0]!\n }\n\n for (const node of graph.nodes) {\n const subject = new NamedNode(node.id)\n for (const [predicate, objects] of node.properties) {\n for (const object of objects) {\n quads.push(new Quad(subject, new NamedNode(predicate), term(object)))\n }\n }\n }\n return quads\n}\n\n/** A string's characters escaped for a double-quoted N-Triples or Turtle literal. */\nexport const escapeLiteral = (value: string): string =>\n value.replace(/[\\\\\"\\n\\r]/g, (c) => (c === '\\\\' ? '\\\\\\\\' : c === '\"' ? '\\\\\"' : c === '\\n' ? '\\\\n' : '\\\\r'))\n\nfunction writeTerm(term: RDF.Term): string {\n if (term.termType === 'NamedNode') return `<${term.value}>`\n if (term.termType === 'BlankNode') return `_:${term.value}`\n if (term.termType === 'Literal') {\n const quoted = `\"${escapeLiteral(term.value)}\"`\n return term.datatype.value === XSD_STRING ? quoted : `${quoted}^^<${term.datatype.value}>`\n }\n throw new TypeError(`Can't write a ${term.termType} term`)\n}\n\n/** N-Quads (RDF 1.1), one statement per line, in the order of `toQuads`. */\nexport function toNQuads(graph: StateGraph): string {\n return toQuads(graph)\n .map((q) => `${writeTerm(q.subject)} ${writeTerm(q.predicate)} ${writeTerm(q.object)} .\\n`)\n .join('')\n}\n","import type { StateGraph } from './graph.js'\nimport { PROV, RDF, XSD } from './iri.js'\n\n// A local part that needs no escaping in Turtle and stays a compact IRI in JSON-LD.\nconst SAFE_LOCAL = /^[A-Za-z_][A-Za-z0-9_-]*$/\nconst SAFE_PREFIX = /^[a-z][a-z0-9]*$/\nconst SAFE_LENS_PREFIX = /^[A-Za-z][A-Za-z0-9_-]*$/\n\n/** Namespace by prefix for the graph: the fixed ones, then `c:` and one `p_<type>:` per EAS type. */\nexport function prefixesFor(graph: StateGraph): Map<string, string> {\n const { base } = graph.iris\n const prefixes = new Map<string, string>([\n ['rdf', RDF],\n ['xsd', XSD],\n ['prov', PROV],\n ['schema', 'https://schema.org/'],\n ['seed', graph.iris.seed],\n ['c', `${base}c/`],\n ])\n for (const node of graph.nodes) {\n for (const predicate of node.properties.keys()) {\n if (!predicate.startsWith(`${base}p/`)) continue\n const easType = predicate.slice(base.length + 2).split('/')[0]!\n if (SAFE_PREFIX.test(easType)) prefixes.set(`p_${easType}`, `${base}p/${easType}/`)\n }\n }\n // A prefix must end in a delimiter to compact in JSON-LD 1.1; the rest stay full IRIs.\n for (const [prefix, ns] of graph.prefixes) {\n if (SAFE_LENS_PREFIX.test(prefix) && /[/#:]$/.test(ns) && !prefixes.has(prefix)) prefixes.set(prefix, ns)\n }\n return prefixes\n}\n\n/**\n * A function giving `[prefix, local]` for an IRI under the longest namespace whose local part is\n * safe, or undefined, and the prefixes it has used.\n */\nexport function compacter(prefixes: ReadonlyMap<string, string>) {\n const used = new Set<string>()\n const compact = (iri: string): [string, string] | undefined => {\n let best: [string, string] | undefined\n for (const [prefix, ns] of prefixes) {\n if (!iri.startsWith(ns) || (best && prefixes.get(best[0])!.length >= ns.length)) continue\n const local = iri.slice(ns.length)\n if (SAFE_LOCAL.test(local)) best = [prefix, local]\n }\n if (best) used.add(best[0])\n return best\n }\n return { compact, used }\n}\n","import type { RdfObject, StateGraph } from './graph.js'\nimport { RDF, RDF_TYPE, XSD } from './iri.js'\nimport { compacter, prefixesFor } from './names.js'\nimport { escapeLiteral } from './quads.js'\n\n/**\n * Turtle (RDF 1.1): prefixes, then one block per subject. Names are prefixed where the local\n * part needs no escaping and written as full IRIs otherwise; lists use collection syntax.\n */\nexport function toTurtle(graph: StateGraph): string {\n const prefixes = prefixesFor(graph)\n const { compact, used } = compacter(prefixes)\n const name = (iri: string): string => {\n const short = compact(iri)\n return short ? `${short[0]}:${short[1]}` : `<${iri}>`\n }\n\n const object = (o: RdfObject): string => {\n if (o.kind === 'iri') return name(o.iri)\n if (o.kind === 'list') return o.items.length === 0 ? name(`${RDF}nil`) : `( ${o.items.map(object).join(' ')} )`\n const quoted = `\"${escapeLiteral(o.value)}\"`\n return o.datatype === `${XSD}string` ? quoted : `${quoted}^^${name(o.datatype)}`\n }\n\n const blocks = graph.nodes.map((node) => {\n const lines = [...node.properties].map(([predicate, objects]) => {\n const verb = predicate === RDF_TYPE ? 'a' : name(predicate)\n return ` ${verb} ${objects.map(object).join(', ')}`\n })\n return `${name(node.id)}\\n${lines.join(' ;\\n')} .\\n`\n })\n\n const header = [...prefixes]\n .filter(([prefix]) => used.has(prefix))\n .map(([prefix, ns]) => `@prefix ${prefix}: <${ns}> .\\n`)\n .join('')\n return `${header}${header ? '\\n' : ''}${blocks.join('\\n')}`\n}\n","import type { RdfObject, StateGraph } from './graph.js'\nimport { RDF_TYPE, XSD } from './iri.js'\nimport { compacter, prefixesFor } from './names.js'\n\ntype JsonLdValue = string | boolean | { '@id': string } | { '@value': string; '@type': string } | { '@list': JsonLdValue[] }\n\nexport type JsonLdDocument = {\n '@context': Record<string, string>\n '@graph': Array<Record<string, unknown>>\n}\n\n/**\n * JSON-LD 1.1 with an inline context: one node object per subject in `@graph`. A string literal is\n * a JSON string, a boolean a JSON boolean, every other literal a typed value object (so large\n * integers keep their digits), and a list `@list`. Expands to the same graph as `toQuads`.\n */\nexport function toJsonLd(graph: StateGraph): JsonLdDocument {\n const prefixes = prefixesFor(graph)\n prefixes.delete('rdf')\n const { compact: toPrefixed, used } = compacter(prefixes)\n const compact = (iri: string): string => {\n const short = toPrefixed(iri)\n return short ? `${short[0]}:${short[1]}` : iri\n }\n\n const value = (o: RdfObject): JsonLdValue => {\n if (o.kind === 'iri') return { '@id': o.iri }\n if (o.kind === 'list') return { '@list': o.items.map(value) }\n if (o.datatype === `${XSD}string`) return o.value\n if (o.datatype === `${XSD}boolean`) return o.value === 'true'\n return { '@value': o.value, '@type': compact(o.datatype) }\n }\n\n const nodes = graph.nodes.map((node) => {\n const out: Record<string, unknown> = { '@id': node.id }\n for (const [predicate, objects] of node.properties) {\n if (predicate === RDF_TYPE) {\n out['@type'] = objects.map((o) => (o.kind === 'iri' ? compact(o.iri) : '')).filter(Boolean)\n continue\n }\n const values = objects.map(value)\n out[compact(predicate)] = values.length === 1 ? values[0] : values\n }\n return out\n })\n\n const context: Record<string, string> = {}\n for (const [prefix, ns] of prefixes) if (used.has(prefix)) context[prefix] = ns\n return { '@context': context, '@graph': nodes }\n}\n","import { PROVISIONAL_BASE_IRI, assertIri } from './iri.js'\n\n/**\n * The Seed vocabulary (`{base}ns#`) in Turtle: the classes and properties the state graph uses\n * that PROV-O and schema.org don't already have.\n */\nexport function seedVocabulary(base: string = PROVISIONAL_BASE_IRI): string {\n assertIri(base, 'base')\n return `@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n@prefix seed: <${base}ns#> .\n\nseed:Seed a rdfs:Class ;\n rdfs:label \"Seed\" ;\n rdfs:comment \"An item: the EAS attestation that names it. Its IRI carries the chain id and attestation uid.\" .\n\nseed:Version a rdfs:Class ;\n rdfs:label \"Version\" ;\n rdfs:comment \"A version of a Seed: an EAS attestation whose refUID is the Seed. Property attestations reference a Version.\" .\n\nseed:versionOf a rdf:Property ;\n rdfs:label \"version of\" ;\n rdfs:domain seed:Version ;\n rdfs:range seed:Seed .\n\nseed:currentVersion a rdf:Property ;\n rdfs:label \"current version\" ;\n rdfs:comment \"The Version the exported values were read from.\" ;\n rdfs:domain seed:Seed ;\n rdfs:range seed:Version .\n\nseed:content a rdf:Property ;\n rdfs:label \"content\" ;\n rdfs:comment \"The stored bytes of an Image, File, Html or Json seed, as an ar:// IRI.\" ;\n rdfs:domain seed:Seed .\n`\n}\n","import { easName } from '@seedprotocol/eas'\nimport { listRelationEasName } from '@seedprotocol/query'\nimport { RDF, XSD, iriScheme } from './iri.js'\nimport { RELATION_TYPES, expandTerm, prefixesOf, type RdfLens } from './lens.js'\nimport { escapeLiteral } from './quads.js'\n\nconst SH = 'http://www.w3.org/ns/shacl#'\n\n// What the state graph writes for each local data type when a lens gives it.\nconst DATATYPES: { readonly [dataType: string]: readonly string[] } = {\n text: ['string'],\n number: ['integer', 'decimal', 'double'],\n boolean: ['boolean'],\n date: ['dateTime'],\n}\nconst EAS_TYPES: { readonly [dataType: string]: string } = {\n text: 'string',\n number: 'string',\n boolean: 'bool',\n date: 'uint256',\n list: 'bytes32[]',\n}\n\nexport type ShaclOptions = {\n /** Base of the protocol IRIs, as given to the export. Default PROVISIONAL_BASE_IRI. */\n base?: string\n}\n\n/**\n * SHACL 2017 shapes in Turtle for state graphs exported with `lens`: one `sh:NodeShape` per model,\n * targeting the class the export gives its seeds (the mapped term, else `{base}c/{model}`), with a\n * property shape per property on the predicate the export uses. Text, Number, Boolean and Date\n * values get `sh:datatype` (a Number any of `xsd:integer`, `xsd:decimal` or `xsd:double`), and every\n * property `sh:maxCount 1`. Relations, Image, File, Html and Json values must be IRIs; their class\n * isn't checked, because the related seed is often not in the export. A List is checked as a\n * well-formed `rdf:List`, and a List of relations' members must be IRIs. `required: true` adds\n * `sh:minCount 1`. Pass a sidecar with no `terms` for shapes over the protocol IRIs.\n */\nexport function toShacl(lens: RdfLens, options: ShaclOptions = {}): string {\n const { schema, sidecar } = lens\n if (!schema.id || schema.id !== sidecar.schemaId) {\n throw new TypeError(`The sidecar is for schema ${sidecar.schemaId}, not ${schema.id ?? 'a schema with no id'}`)\n }\n // c/ and p/ IRIs don't name a chain.\n const iris = iriScheme(1, options.base)\n const prefixes = prefixesOf(sidecar)\n const termOf = (id: string | undefined): string | undefined => {\n const term = id ? sidecar.terms[id] : undefined\n return term === undefined ? undefined : expandTerm(term, prefixes)\n }\n const literal = (value: string) => `\"${escapeLiteral(value)}\"`\n\n const shapes = Object.entries(schema.models).map(([modelName, model]) => {\n const properties = Object.entries(model.properties).flatMap(([key, property]) => {\n const dataType = (property.type ?? property.dataType ?? '').toLowerCase()\n const ref = property.ref ?? property.refModelName\n const relation = RELATION_TYPES.has(dataType)\n const easType = relation ? 'bytes32' : EAS_TYPES[dataType]\n if (!easType) return []\n const name = dataType === 'list' && ref ? listRelationEasName(key, ref) : easName(key)\n const path = `<${termOf(property.id) ?? iris.property(easType, name)}>`\n const lines = [`sh:path ${path}`, `sh:name ${literal(key)}`, 'sh:maxCount 1']\n if (property.required === true) lines.push('sh:minCount 1')\n const datatypes = DATATYPES[dataType]\n if (datatypes?.length === 1) lines.push(`sh:datatype xsd:${datatypes[0]}`)\n else if (datatypes) lines.push(`sh:or ( ${datatypes.map((d) => `[ sh:datatype xsd:${d} ]`).join(' ')} )`)\n else if (relation) lines.push('sh:nodeKind sh:IRI')\n const shapes = [lines]\n if (dataType === 'list') shapes.push([`sh:path ( ${path} [ sh:zeroOrMorePath rdf:rest ] )`, 'sh:node _:listCell'])\n if (dataType === 'list' && ref) {\n shapes.push([`sh:path ( ${path} [ sh:zeroOrMorePath rdf:rest ] rdf:first )`, 'sh:nodeKind sh:IRI'])\n }\n return shapes.map((shape) => ` sh:property [\\n ${shape.join(' ;\\n ')}\\n ]`)\n })\n const targetClass = termOf(model.id) ?? iris.modelClass(easName(modelName))\n const head = [`[] a sh:NodeShape`, ` sh:name ${literal(modelName)}`, ` sh:targetClass <${targetClass}>`]\n return `${[...head, ...properties].join(' ;\\n')} .\\n`\n })\n\n // Each cell of a list: rdf:nil, or one rdf:first and one rdf:rest. Applied to every cell along\n // the path rather than by recursion, which SHACL 2017 leaves undefined.\n const listCell = `_:listCell a sh:NodeShape ;\n sh:or (\n [ sh:hasValue rdf:nil ]\n [\n sh:nodeKind sh:BlankNodeOrIRI ;\n sh:property [ sh:path rdf:first ; sh:minCount 1 ; sh:maxCount 1 ] ;\n sh:property [ sh:path rdf:rest ; sh:minCount 1 ; sh:maxCount 1 ]\n ]\n ) .\n`\n const header = [\n ['sh', SH],\n ['rdf', RDF],\n ['xsd', XSD],\n ]\n .map(([prefix, ns]) => `@prefix ${prefix}: <${ns}> .\\n`)\n .join('')\n return `${header}\\n${listCell}\\n${shapes.join('\\n')}`\n}\n","import { getSeedAttestations, type GetSeedAttestationsOptions } from '@seedprotocol/query'\nimport { stateGraph, type StateGraph, type StateGraphOptions } from './graph.js'\n\nexport { PROVISIONAL_BASE_IRI, iriScheme } from './iri.js'\nexport type { IriScheme } from './iri.js'\nexport { stateGraph } from './graph.js'\nexport type { RdfNode, RdfObject, StateGraph, StateGraphOptions } from './graph.js'\nexport type { LensSchema, RdfLens, RdfSidecar } from './lens.js'\nexport { toQuads, toNQuads } from './quads.js'\nexport { toTurtle } from './turtle.js'\nexport { toJsonLd } from './jsonld.js'\nexport type { JsonLdDocument } from './jsonld.js'\nexport { seedVocabulary } from './vocabulary.js'\nexport { toShacl } from './shacl.js'\nexport type { ShaclOptions } from './shacl.js'\nexport { SUGGESTED_PREFIXES, checkSidecar, sidecarContext, suggestTerms, syncSidecar } from './sidecar.js'\nexport type {\n SchemaTarget,\n SidecarContext,\n SidecarContextOptions,\n SidecarReport,\n SidecarSchema,\n TermSuggestion,\n} from './sidecar.js'\n\nexport type ExportSeedsOptions = StateGraphOptions & Pick<GetSeedAttestationsOptions, 'source' | 'pins' | 'asOf'>\n\n/**\n * The state graph of the seeds, read with `getSeedAttestations` from @seedprotocol/query (same\n * sources and pins as `getSeeds`). Seeds that aren't found are left out. With `asOf` (unix\n * seconds), the graph is what EAS held then, the same attestations a reproducible archive bag with\n * that `Seed-Bag-As-Of` holds; it reads EAS and refuses `source: 'local'`. Two exports with the\n * same seeds, `asOf`, options and sidecar give the same bytes from every writer.\n */\nexport async function exportSeeds(\n seedUids: readonly string[],\n options: ExportSeedsOptions,\n): Promise<StateGraph> {\n const { source, pins, asOf, ...graphOptions } = options\n const found = await getSeedAttestations(seedUids, { source, pins, asOf })\n return stateGraph([...found.values()], graphOptions)\n}\n"],"mappings":";;;;;;AAgDA,IAAMkB,IAAqB,iCACrBC,IAAsB,0BACtBC,qBAAgB,IAAI,IAAI,CAACD,GAAqB,iCAAiC,CAAC,GAEhFE,KAAa;AAMnB,SAASC,GAAY,EAAE,aAAU,UAAO,YAAYC,KAAmC;CACrF,OAAOC,EAAOC,EAAYZ,EAAc;EAAE;EAAU;EAAO,YAAYU,KAAW,C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,EAAK,8CAA8C,oBAAoB,CAAC,GAE7FP,EAAO,KAAK,MAAU,8BAA8BU,EAAM,KAAK,cAAc,EAAE,QAAQ;EAChG,CAAC,GACKC,IAAcb,EAAOI,EAAM,EAAE,KAAKpF,EAAK,WAAWwF,EAAQL,CAAS,CAAC;EAE1E,OAAO,GAAG;GADI;GAAqB,eAAejH,EAAQiH,CAAS;GAAK,uBAAuBU,EAAY;GACvF,GAAGxE;EAAU,CAAC,CAAC,KAAK,MAAM,EAAE;CAClD,CAAC;CAqBD,OAAO,GAPQ;EACb,CAAC,MAAMqD,EAAE;EACT,CAAC,OAAOnB,CAAG;EACX,CAAC,OAAOnG,CAAG;CACb,CAAC,CACE,KAAK,CAACqG,GAAQpD,OAAQ,WAAWoD,EAAO,KAAKpD,EAAG,MAAM,CAAC,CACvD,KAAK,EACE,EAAO;;;;;;;;;IAAiB6E,EAAO,KAAK,IAAI;AACpD;;;ACjEA,eAAsBY,GACpB,GACA,GACqB;CACrB,IAAM,EAAE,WAAQ,SAAM,SAAM,GAAGC,MAAiB3F;CAEhD,OAAOD,EAAW,CAAC,IAAG,MADF6F,EAAoBC,GAAU;EAAE;EAAQ;EAAM;CAAK,CAAC,EAClD,CAAM,OAAO,CAAC,GAAGF,CAAY;AACrD"}
package/dist/iri.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Base of every IRI the export mints. Provisional: the permanent namespace (w3id.org, see the RDF
3
+ * plan) isn't registered yet, so don't publish exports that use it anywhere they can't be
4
+ * replaced, such as an archive on Arweave.
5
+ */
6
+ export declare const PROVISIONAL_BASE_IRI = "https://w3id.org/seedprotocol/";
7
+ export declare const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
8
+ export declare const XSD = "http://www.w3.org/2001/XMLSchema#";
9
+ export declare const PROV = "http://www.w3.org/ns/prov#";
10
+ export declare const RDF_TYPE = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
11
+ export declare const RDF_FIRST = "http://www.w3.org/1999/02/22-rdf-syntax-ns#first";
12
+ export declare const RDF_REST = "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest";
13
+ export declare const RDF_NIL = "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil";
14
+ /** Throws when `iri` can't be written as an IRI in N-Quads, Turtle or JSON-LD. */
15
+ export declare function assertIri(iri: string, what: string): string;
16
+ /** The IRIs one export uses, from its base and chain. */
17
+ export type IriScheme = {
18
+ readonly base: string;
19
+ readonly chainId: number;
20
+ /** The Seed vocabulary namespace, `{base}ns#`. */
21
+ readonly seed: string;
22
+ /** A Seed, Version or other attestation on this chain. */
23
+ attestation(uid: string): string;
24
+ /** The class for an on-chain model type (the Seed schema `bytes32 <model>`). */
25
+ modelClass(modelType: string): string;
26
+ /** The predicate for an on-chain property schema `<easType> <easName>`. */
27
+ property(easType: string, easName: string): string;
28
+ /** An attester address as a CAIP-10 `did:pkh`. */
29
+ account(address: string): string;
30
+ };
31
+ export declare function iriScheme(chainId: number, base?: string): IriScheme;
32
+ //# sourceMappingURL=iri.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iri.d.ts","sourceRoot":"","sources":["../src/iri.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,mCAAmC,CAAA;AAEpE,eAAO,MAAM,GAAG,gDAAgD,CAAA;AAChE,eAAO,MAAM,GAAG,sCAAsC,CAAA;AACtD,eAAO,MAAM,IAAI,+BAA+B,CAAA;AAEhD,eAAO,MAAM,QAAQ,oDAAe,CAAA;AACpC,eAAO,MAAM,SAAS,qDAAgB,CAAA;AACtC,eAAO,MAAM,QAAQ,oDAAe,CAAA;AACpC,eAAO,MAAM,OAAO,mDAAc,CAAA;AAKlC,kFAAkF;AAClF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAK3D;AAED,yDAAyD;AACzD,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,kDAAkD;IAClD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,0DAA0D;IAC1D,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;IAChC,gFAAgF;IAChF,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;IACrC,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;IAClD,kDAAkD;IAClD,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CACjC,CAAA;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAA6B,GAAG,SAAS,CAgBzF"}
@@ -0,0 +1,12 @@
1
+ import type { StateGraph } from './graph.js';
2
+ export type JsonLdDocument = {
3
+ '@context': Record<string, string>;
4
+ '@graph': Array<Record<string, unknown>>;
5
+ };
6
+ /**
7
+ * JSON-LD 1.1 with an inline context: one node object per subject in `@graph`. A string literal is
8
+ * a JSON string, a boolean a JSON boolean, every other literal a typed value object (so large
9
+ * integers keep their digits), and a list `@list`. Expands to the same graph as `toQuads`.
10
+ */
11
+ export declare function toJsonLd(graph: StateGraph): JsonLdDocument;
12
+ //# sourceMappingURL=jsonld.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonld.d.ts","sourceRoot":"","sources":["../src/jsonld.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,UAAU,EAAE,MAAM,YAAY,CAAA;AAMvD,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAClC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;CACzC,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,cAAc,CAiC1D"}
package/dist/lens.d.ts ADDED
@@ -0,0 +1,71 @@
1
+ type LensProperty = {
2
+ readonly id?: string;
3
+ readonly type?: string;
4
+ readonly dataType?: string;
5
+ readonly ref?: string;
6
+ readonly refModelName?: string;
7
+ readonly nameMatch?: string;
8
+ readonly [key: string]: unknown;
9
+ };
10
+ type LensModel = {
11
+ readonly id?: string;
12
+ readonly nameMatch?: string;
13
+ readonly properties: {
14
+ readonly [propertyName: string]: LensProperty;
15
+ };
16
+ };
17
+ /** As much of a schema file as the lens reads. A `SchemaFileFormat` can be passed as it is. */
18
+ export type LensSchema = {
19
+ readonly id?: string;
20
+ readonly nameMatch?: string;
21
+ readonly models: {
22
+ readonly [modelName: string]: LensModel;
23
+ };
24
+ };
25
+ /**
26
+ * What an app says its models and properties mean. `terms` is keyed by model or property id, which
27
+ * survive renames, so no older schema file is needed. Each term is a prefixed name or an absolute
28
+ * IRI; prefixes come from the top level of `@context`.
29
+ */
30
+ export type RdfSidecar = {
31
+ /** The schema these terms were written for. Must equal the schema's `id`. */
32
+ readonly schemaId: string;
33
+ /** The schema `version` the sidecar was last synced with. Informational: terms are read by id. */
34
+ readonly schemaVersion?: number;
35
+ readonly '@context'?: {
36
+ readonly [prefix: string]: unknown;
37
+ };
38
+ readonly terms: {
39
+ readonly [id: string]: string;
40
+ };
41
+ };
42
+ /** JSON with object keys sorted, so key order doesn't change it. */
43
+ export declare const canonicalJson: (value: unknown) => string;
44
+ export type RdfLens = {
45
+ readonly schema: LensSchema;
46
+ readonly sidecar: RdfSidecar;
47
+ };
48
+ type PropertyEntry = {
49
+ readonly term?: string;
50
+ readonly dataType: string;
51
+ };
52
+ /** How a lens reads one export's seeds and properties. */
53
+ export type CompiledLens = {
54
+ readonly prefixes: ReadonlyMap<string, string>;
55
+ readonly warnings: string[];
56
+ /** The class term of a seed's on-chain model, if the lens maps it. */
57
+ classOf(modelType: string): string | undefined;
58
+ /** The local data type and term of an on-chain property of a model. */
59
+ propertyOf(modelType: string, easPropertyName: string): PropertyEntry | undefined;
60
+ };
61
+ export declare const RELATION_TYPES: Set<string>;
62
+ export declare function prefixesOf(sidecar: RdfSidecar): Map<string, string>;
63
+ /** The absolute IRI of a term, or undefined when it can't be read. */
64
+ export declare function expandTerm(term: string, prefixes: ReadonlyMap<string, string>): string | undefined;
65
+ /**
66
+ * Reads a lens for one export. A sidecar written for another schema throws; a term that matches no
67
+ * model or property, or can't be expanded, is a warning, and the export uses the protocol IRI.
68
+ */
69
+ export declare function compileLens({ schema, sidecar }: RdfLens): CompiledLens;
70
+ export {};
71
+ //# sourceMappingURL=lens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lens.d.ts","sourceRoot":"","sources":["../src/lens.ts"],"names":[],"mappings":"AAIA,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAChC,CAAA;AAED,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,YAAY,CAAA;KAAE,CAAA;CACvE,CAAA;AAED,+FAA+F;AAC/F,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAA;IACp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,CAAA;CAClF,CAAA;AAED,eAAO,MAAM,cAAc,aAAiE,CAAA;AAK5F,wBAAgB,UAAU,CAAC,OAAO,EAAE,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAMnE;AAED,sEAAsE;AACtE,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,CAUlG;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,GAAG,YAAY,CAoDtE"}
@@ -0,0 +1,12 @@
1
+ import type { StateGraph } from './graph.js';
2
+ /** Namespace by prefix for the graph: the fixed ones, then `c:` and one `p_<type>:` per EAS type. */
3
+ export declare function prefixesFor(graph: StateGraph): Map<string, string>;
4
+ /**
5
+ * A function giving `[prefix, local]` for an IRI under the longest namespace whose local part is
6
+ * safe, or undefined, and the prefixes it has used.
7
+ */
8
+ export declare function compacter(prefixes: ReadonlyMap<string, string>): {
9
+ compact: (iri: string) => [string, string] | undefined;
10
+ used: Set<string>;
11
+ };
12
+ //# sourceMappingURL=names.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../src/names.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAQ5C,qGAAqG;AACrG,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAsBlE;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC;mBAEvC,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;;EAW5D"}