@dxos/echo-memory 0.0.0-stage → 0.0.0
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/LICENSE +105 -0
- package/dist/lib/Fact.mjs +1 -0
- package/dist/lib/FactFeed.mjs +1 -0
- package/dist/lib/Graph.mjs +1 -0
- package/dist/lib/Hash.mjs +1 -0
- package/dist/lib/Mapping.mjs +1 -0
- package/dist/lib/MemoryError.mjs +1 -0
- package/dist/lib/MemoryQuery.mjs +1 -0
- package/dist/lib/MemoryService.mjs +1 -0
- package/dist/lib/Ontology.mjs +1 -0
- package/dist/lib/Pipeline.mjs +1 -0
- package/dist/lib/Predicate.mjs +1 -0
- package/dist/lib/Rdf.mjs +1 -0
- package/dist/lib/RdfStore.mjs +1 -0
- package/dist/lib/Sparql.mjs +1 -0
- package/dist/lib/Subscription.mjs +1 -0
- package/dist/lib/Trig.mjs +1 -0
- package/dist/lib/Vocab.mjs +1 -0
- package/dist/lib/Vocabularies.mjs +1 -0
- package/dist/lib/chunk-Fact.mjs +245 -0
- package/dist/lib/chunk-Fact.mjs.map +1 -0
- package/dist/lib/chunk-FactFeed.mjs +29 -0
- package/dist/lib/chunk-FactFeed.mjs.map +1 -0
- package/dist/lib/chunk-Graph.mjs +147 -0
- package/dist/lib/chunk-Graph.mjs.map +1 -0
- package/dist/lib/chunk-Hash.mjs +16 -0
- package/dist/lib/chunk-Hash.mjs.map +1 -0
- package/dist/lib/chunk-Mapping.mjs +226 -0
- package/dist/lib/chunk-Mapping.mjs.map +1 -0
- package/dist/lib/chunk-MemoryError.mjs +10 -0
- package/dist/lib/chunk-MemoryError.mjs.map +1 -0
- package/dist/lib/chunk-MemoryQuery.mjs +99 -0
- package/dist/lib/chunk-MemoryQuery.mjs.map +1 -0
- package/dist/lib/chunk-MemoryService.mjs +31 -0
- package/dist/lib/chunk-MemoryService.mjs.map +1 -0
- package/dist/lib/chunk-Ontology.mjs +529 -0
- package/dist/lib/chunk-Ontology.mjs.map +1 -0
- package/dist/lib/chunk-Pipeline.mjs +84 -0
- package/dist/lib/chunk-Pipeline.mjs.map +1 -0
- package/dist/lib/chunk-Predicate.mjs +66 -0
- package/dist/lib/chunk-Predicate.mjs.map +1 -0
- package/dist/lib/chunk-Rdf.mjs +120 -0
- package/dist/lib/chunk-Rdf.mjs.map +1 -0
- package/dist/lib/chunk-RdfStore.mjs +60 -0
- package/dist/lib/chunk-RdfStore.mjs.map +1 -0
- package/dist/lib/chunk-Sparql.mjs +153 -0
- package/dist/lib/chunk-Sparql.mjs.map +1 -0
- package/dist/lib/chunk-Subscription.mjs +44 -0
- package/dist/lib/chunk-Subscription.mjs.map +1 -0
- package/dist/lib/chunk-Trig.mjs +106 -0
- package/dist/lib/chunk-Trig.mjs.map +1 -0
- package/dist/lib/chunk-Vocab.mjs +164 -0
- package/dist/lib/chunk-Vocab.mjs.map +1 -0
- package/dist/lib/chunk-Vocabularies.mjs +343 -0
- package/dist/lib/chunk-Vocabularies.mjs.map +1 -0
- package/dist/lib/chunk-rolldown-runtime.mjs +13 -0
- package/dist/lib/index.mjs +19 -0
- package/dist/types/src/Fact.d.ts +339 -0
- package/dist/types/src/Fact.d.ts.map +1 -0
- package/dist/types/src/Fact.test.d.ts +2 -0
- package/dist/types/src/Fact.test.d.ts.map +1 -0
- package/dist/types/src/FactFeed.d.ts +11 -0
- package/dist/types/src/FactFeed.d.ts.map +1 -0
- package/dist/types/src/FactFeed.test.d.ts +2 -0
- package/dist/types/src/FactFeed.test.d.ts.map +1 -0
- package/dist/types/src/Graph.d.ts +31 -0
- package/dist/types/src/Graph.d.ts.map +1 -0
- package/dist/types/src/Graph.test.d.ts +2 -0
- package/dist/types/src/Graph.test.d.ts.map +1 -0
- package/dist/types/src/Hash.d.ts +3 -0
- package/dist/types/src/Hash.d.ts.map +1 -0
- package/dist/types/src/Mapping.d.ts +18 -0
- package/dist/types/src/Mapping.d.ts.map +1 -0
- package/dist/types/src/Mapping.test.d.ts +2 -0
- package/dist/types/src/Mapping.test.d.ts.map +1 -0
- package/dist/types/src/MemoryError.d.ts +33 -0
- package/dist/types/src/MemoryError.d.ts.map +1 -0
- package/dist/types/src/MemoryQuery.d.ts +136 -0
- package/dist/types/src/MemoryQuery.d.ts.map +1 -0
- package/dist/types/src/MemoryQuery.test.d.ts +2 -0
- package/dist/types/src/MemoryQuery.test.d.ts.map +1 -0
- package/dist/types/src/MemoryService.d.ts +72 -0
- package/dist/types/src/MemoryService.d.ts.map +1 -0
- package/dist/types/src/Ontology.d.ts +115 -0
- package/dist/types/src/Ontology.d.ts.map +1 -0
- package/dist/types/src/Ontology.test.d.ts +2 -0
- package/dist/types/src/Ontology.test.d.ts.map +1 -0
- package/dist/types/src/Pipeline.d.ts +103 -0
- package/dist/types/src/Pipeline.d.ts.map +1 -0
- package/dist/types/src/Predicate.d.ts +17 -0
- package/dist/types/src/Predicate.d.ts.map +1 -0
- package/dist/types/src/Predicate.test.d.ts +2 -0
- package/dist/types/src/Predicate.test.d.ts.map +1 -0
- package/dist/types/src/Rdf.d.ts +33 -0
- package/dist/types/src/Rdf.d.ts.map +1 -0
- package/dist/types/src/Rdf.test.d.ts +2 -0
- package/dist/types/src/Rdf.test.d.ts.map +1 -0
- package/dist/types/src/RdfStore.d.ts +471 -0
- package/dist/types/src/RdfStore.d.ts.map +1 -0
- package/dist/types/src/Sparql.d.ts +58 -0
- package/dist/types/src/Sparql.d.ts.map +1 -0
- package/dist/types/src/Sparql.test.d.ts +2 -0
- package/dist/types/src/Sparql.test.d.ts.map +1 -0
- package/dist/types/src/Subscription.d.ts +100 -0
- package/dist/types/src/Subscription.d.ts.map +1 -0
- package/dist/types/src/Trig.d.ts +8 -0
- package/dist/types/src/Trig.d.ts.map +1 -0
- package/dist/types/src/Trig.test.d.ts +2 -0
- package/dist/types/src/Trig.test.d.ts.map +1 -0
- package/dist/types/src/Vocab.d.ts +90 -0
- package/dist/types/src/Vocab.d.ts.map +1 -0
- package/dist/types/src/Vocabularies.d.ts +45 -0
- package/dist/types/src/Vocabularies.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +19 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +133 -3
- package/src/Fact.test.ts +74 -0
- package/src/Fact.ts +269 -0
- package/src/FactFeed.test.ts +40 -0
- package/src/FactFeed.ts +38 -0
- package/src/Graph.test.ts +106 -0
- package/src/Graph.ts +158 -0
- package/src/Hash.ts +15 -0
- package/src/Mapping.test.ts +197 -0
- package/src/Mapping.ts +320 -0
- package/src/MemoryError.ts +10 -0
- package/src/MemoryQuery.test.ts +67 -0
- package/src/MemoryQuery.ts +114 -0
- package/src/MemoryService.ts +89 -0
- package/src/Ontology.test.ts +94 -0
- package/src/Ontology.ts +571 -0
- package/src/Pipeline.ts +97 -0
- package/src/Predicate.test.ts +47 -0
- package/src/Predicate.ts +89 -0
- package/src/Rdf.test.ts +104 -0
- package/src/Rdf.ts +158 -0
- package/src/RdfStore.ts +111 -0
- package/src/Sparql.test.ts +72 -0
- package/src/Sparql.ts +237 -0
- package/src/Subscription.ts +47 -0
- package/src/Trig.test.ts +199 -0
- package/src/Trig.ts +170 -0
- package/src/Vocab.ts +134 -0
- package/src/Vocabularies.ts +204 -0
- package/src/index.ts +22 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-Graph.mjs","names":["Ontology.DEFAULT","Fact.make","Vocab.graphIri","Hash.text","Mapping.predicateOf","Mapping.idInGraph","Vocab.DX","Vocab.SX","Vocab.PROV","Vocab.RDF","Vocab.RDFS","Vocab.OWL","Vocab.XSD","Vocab.SKOS","Vocab.DCTERMS","Vocab.SCHEMA","Vocab.FOAF","Vocab.ORG","Vocab.ENTITY","Vocab.FACT","Vocab.GRAPH","Vocab.BRAIN","Vocab.SIOC","Trig.write","Mapping.factToTriples","Ontology.ontologyQuads","Ontology.nameFor","Vocab.brainNamespaceOf"],"sources":["../../src/Graph.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Fact from './Fact.ts';\nimport * as Hash from './Hash.ts';\nimport * as Mapping from './Mapping.ts';\nimport * as Ontology from './Ontology.ts';\nimport * as Rdf from './Rdf.ts';\nimport * as Trig from './Trig.ts';\nimport * as Vocab from './Vocab.ts';\n\n/** Everything a graph states once for all its statements: facts that differ in any of it need separate graphs. */\nconst provenanceKey = (fact: Fact.Fact): string =>\n JSON.stringify([\n fact.attribution.source,\n fact.attribution.agent,\n fact.attribution.agentLabel,\n fact.attribution.generatedAtTime,\n fact.attribution.wasDerivedFrom,\n fact.attribution.span,\n fact.assertion.quote,\n fact.assertion.validFrom,\n fact.assertion.validTo,\n fact.factuality,\n fact.illocution,\n fact.recordedAt,\n fact.extractor,\n fact.sourceHash,\n fact.pass,\n fact.kind,\n fact.origin,\n fact.supersedes,\n fact.retracts,\n ]);\n\nexport type AssignOptions = {\n /** Names the graph for a fact; facts given the same name and provenance share a graph. Defaults to its source. */\n readonly name?: (fact: Fact.Fact) => string;\n readonly ontology?: Ontology.Ontology;\n};\n\n/**\n * Puts facts into named graphs: facts that share their provenance (source, speaker, time, quote, factuality,\n * extraction pass, …) share a graph, and a fact that differs in any of it starts another. A fact that already names\n * a graph keeps it. Each fact gets its predicate IRI, and the id it will have once stored; facts come in their plain\n * form, since the ids they will have are only known here.\n */\nexport const assign = (\n facts: readonly Fact.Encoded[],\n { name, ontology = Ontology.DEFAULT }: AssignOptions = {},\n): Fact.Fact[] =>\n facts.map((input) => {\n const fact = Fact.make(input);\n const label = name?.(fact) ?? fact.attribution.source;\n const key = provenanceKey(fact);\n // Two independent 32-bit hashes: every memory an agent records shares one label, so 32 bits would collide.\n const graph =\n fact.graph ??\n Fact.GraphIri.make(Vocab.graphIri(`${Hash.text(label)}-${Hash.text(key)}${Hash.text(`\\u0000${key}`)}`).value);\n const placed: Fact.Fact = {\n ...fact,\n graph,\n assertion: { ...fact.assertion, predicateIri: Mapping.predicateOf(fact, ontology) },\n };\n return { ...placed, id: Mapping.idInGraph(placed, graph, ontology) };\n });\n\n/** Prefixes TriG output abbreviates. */\nexport const PREFIXES: Readonly<Record<string, string>> = {\n dx: Vocab.DX,\n sx: Vocab.SX,\n prov: Vocab.PROV,\n rdf: Vocab.RDF,\n rdfs: Vocab.RDFS,\n owl: Vocab.OWL,\n xsd: Vocab.XSD,\n skos: Vocab.SKOS,\n dcterms: Vocab.DCTERMS,\n schema: Vocab.SCHEMA,\n foaf: Vocab.FOAF,\n org: Vocab.ORG,\n entity: Vocab.ENTITY,\n fact: Vocab.FACT,\n graph: Vocab.GRAPH,\n};\n\n/** Prefixes a whole store's TriG export abbreviates: {@link PREFIXES}, the brain namespaces and SIOC. */\nexport const EXPORT_PREFIXES: Readonly<Record<string, string>> = { ...PREFIXES, brain: Vocab.BRAIN, sioc: Vocab.SIOC };\n\nconst write = (quads: Iterable<Rdf.Quad>, prefixes: Record<string, string>): string => {\n const seen = new Set<string>();\n const unique: Rdf.Quad[] = [];\n for (const quad of quads) {\n const key = `${quad.subject.value} ${quad.predicate.value} ${quad.object.termType}:${quad.object.value} ${quad.graph.value}`;\n if (!seen.has(key)) {\n seen.add(key);\n unique.push(quad);\n }\n }\n return Trig.write(unique, { prefixes });\n};\n\n/**\n * The facts as TriG: each graph's statements, then its provenance. The brain's namespace reads as `brain:`, and the\n * entities local to each graph as `g1:`, `g2:`, … so a graph-local entity is visibly not a shared one.\n */\nexport const toTriG = (facts: readonly Fact.Fact[], ontology: Ontology.Ontology = Ontology.DEFAULT): string => {\n const quads = facts.flatMap((fact) => Mapping.factToTriples(fact, ontology));\n const graphs = [...new Set(quads.flatMap((quad) => (quad.graph.termType === 'NamedNode' ? [quad.graph.value] : [])))];\n const locals = graphs.filter(\n (graph) =>\n graph !== Vocab.ONTOLOGY_GRAPH &&\n quads.some((quad) => quad.subject.value.startsWith(`${graph}#`) || quad.object.value.startsWith(`${graph}#`)),\n );\n const usesBrain = quads.some((quad) =>\n [quad.subject, quad.predicate, quad.object].some((term) => term.value.startsWith(ontology.namespace)),\n );\n return write(quads, {\n ...PREFIXES,\n ...(usesBrain ? { brain: ontology.namespace } : {}),\n ...Object.fromEntries(locals.map((graph, index) => [`g${index + 1}`, `${graph}#`])),\n });\n};\n\n/** The ontology's predicates as TriG: each an `rdf:Property` described in the ontology graph. */\nexport const ontologyToTriG = (ontology: Ontology.Ontology): string =>\n write(Ontology.ontologyQuads(ontology), { ...PREFIXES, brain: ontology.namespace });\n\n/**\n * The predicates the facts use that the ontology does not define, as entries minted in its namespace, so the next\n * extraction can reuse them; the first quote that used one is kept as its example.\n */\nexport const mintedPredicates = (\n facts: readonly Fact.Fact[],\n ontology: Ontology.Ontology = Ontology.DEFAULT,\n): Ontology.Entry[] => {\n const minted = new Map<string, Ontology.Entry>();\n for (const fact of facts) {\n const iri = Mapping.predicateOf(fact, ontology);\n if (ontology.get(iri) || minted.has(iri)) {\n continue;\n }\n minted.set(iri, {\n iri,\n name: Ontology.nameFor(fact.assertion.predicate),\n label: fact.assertion.predicate,\n ...(fact.assertion.predicateDescription ? { description: fact.assertion.predicateDescription } : {}),\n ...(Vocab.brainNamespaceOf(iri) ? { definedBy: Vocab.brainNamespaceOf(iri) } : {}),\n created: fact.recordedAt,\n creator: `${fact.extractor.id}/${fact.extractor.model}`,\n ...(fact.assertion.quote ? { example: fact.assertion.quote } : {}),\n });\n }\n return [...minted.values()];\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAeA,IAAM,iBAAiB,SACrB,KAAK,UAAU;CACb,KAAK,YAAY;CACjB,KAAK,YAAY;CACjB,KAAK,YAAY;CACjB,KAAK,YAAY;CACjB,KAAK,YAAY;CACjB,KAAK,YAAY;CACjB,KAAK,UAAU;CACf,KAAK,UAAU;CACf,KAAK,UAAU;CACf,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,K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,CAAC;GAClG,GAAIC,iBAAuB,GAAG,IAAI,EAAE,WAAWA,iBAAuB,GAAG,EAAE,IAAI,CAAC;GAChF,SAAS,KAAK;GACd,SAAS,GAAG,KAAK,UAAU,GAAG,GAAG,KAAK,UAAU;GAChD,GAAI,KAAK,UAAU,QAAQ,EAAE,SAAS,KAAK,UAAU,MAAM,IAAI,CAAC;EAClE,CAAC;CACH;CACA,OAAO,CAAC,GAAG,OAAO,OAAO,CAAC;AAC5B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
//#region src/Hash.ts
|
|
3
|
+
var Hash_exports = /* @__PURE__ */ __exportAll({ text: () => text });
|
|
4
|
+
/** Stable content hash of a text (FNV-1a), with no crypto dependency so it runs the same everywhere. */
|
|
5
|
+
var text = (text) => {
|
|
6
|
+
let hash = 2166136261;
|
|
7
|
+
for (let index = 0; index < text.length; index++) {
|
|
8
|
+
hash ^= text.charCodeAt(index);
|
|
9
|
+
hash = Math.imul(hash, 16777619);
|
|
10
|
+
}
|
|
11
|
+
return (hash >>> 0).toString(16);
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { text as n, Hash_exports as t };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=chunk-Hash.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-Hash.mjs","names":[],"sources":["../../src/Hash.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\n/** Stable content hash of a text (FNV-1a), with no crypto dependency so it runs the same everywhere. */\nexport const text = (text: string): string => {\n let hash = 0x811c9dc5;\n for (let index = 0; index < text.length; index++) {\n hash ^= text.charCodeAt(index);\n hash = Math.imul(hash, 0x01000193);\n }\n return (hash >>> 0).toString(16);\n};\n"],"mappings":";;;;AAOA,IAAa,QAAQ,SAAyB;CAC5C,IAAI,OAAO;CACX,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;EAChD,QAAQ,KAAK,WAAW,KAAK;EAC7B,OAAO,KAAK,KAAK,MAAM,QAAU;CACnC;CACA,QAAQ,SAAS,EAAA,CAAG,SAAS,EAAE;AACjC"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
import { C as graphOf, c as FactId, s as Fact } from "./chunk-Fact.mjs";
|
|
3
|
+
import { n as text } from "./chunk-Hash.mjs";
|
|
4
|
+
import { i as Rdf_exports } from "./chunk-Rdf.mjs";
|
|
5
|
+
import { F as SX_GRAPH, G as entityKey, K as entityNode, O as RDF_TYPE, Q as localEntityIri, T as RDFS_LABEL, V as brainNamespaceOf, c as FACT, et as prov, j as SKOS, k as SCHEMA, nt as sx, o as DX, q as factIdFromIri, tt as str } from "./chunk-Vocab.mjs";
|
|
6
|
+
import { d as nameFor, l as labelFromIri, p as toQuads, t as DEFAULT } from "./chunk-Ontology.mjs";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
//#region src/Mapping.ts
|
|
9
|
+
var Mapping_exports = /* @__PURE__ */ __exportAll({
|
|
10
|
+
KIND_CLASSES: () => KIND_CLASSES,
|
|
11
|
+
classIri: () => classIri,
|
|
12
|
+
factToTriples: () => factToTriples,
|
|
13
|
+
idInGraph: () => idInGraph,
|
|
14
|
+
isKindQuad: () => isKindQuad,
|
|
15
|
+
predicateOf: () => predicateOf,
|
|
16
|
+
triplesToFacts: () => triplesToFacts
|
|
17
|
+
});
|
|
18
|
+
var { quad, defaultGraph, namedNode } = Rdf_exports;
|
|
19
|
+
var decodeFact = Schema.decodeUnknownSync(Fact);
|
|
20
|
+
var localName = (iri) => iri.replace(/^.*[#/]/, "");
|
|
21
|
+
var CLASSES = {
|
|
22
|
+
person: `${SCHEMA}Person`,
|
|
23
|
+
org: `${SCHEMA}Organization`,
|
|
24
|
+
place: `${SCHEMA}Place`,
|
|
25
|
+
event: `${SCHEMA}Event`,
|
|
26
|
+
concept: `${SKOS}Concept`,
|
|
27
|
+
thing: `${SCHEMA}Thing`
|
|
28
|
+
};
|
|
29
|
+
var LEGACY_CLASSES = {
|
|
30
|
+
person: `${DX}Person`,
|
|
31
|
+
org: `${DX}Organization`,
|
|
32
|
+
place: `${DX}Place`,
|
|
33
|
+
event: `${DX}Event`,
|
|
34
|
+
concept: `${DX}Concept`,
|
|
35
|
+
thing: `${DX}Thing`
|
|
36
|
+
};
|
|
37
|
+
var KINDS = new Map([...Object.entries(CLASSES), ...Object.entries(LEGACY_CLASSES)].map(([kind, iri]) => [iri, kind]));
|
|
38
|
+
/** The class IRIs an entity's kind is typed with; an `rdf:type` to any other class is a statement, not a kind. */
|
|
39
|
+
var KIND_CLASSES = [...KINDS.keys()];
|
|
40
|
+
/** Whether a quad states an entity's kind (an `rdf:type` to a kind class) rather than making a statement. */
|
|
41
|
+
var isKindQuad = (predicate, object) => predicate === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" && KINDS.has(object);
|
|
42
|
+
/** The class IRI an entity of this kind is typed with. */
|
|
43
|
+
var classIri = (kind) => CLASSES[kind];
|
|
44
|
+
/**
|
|
45
|
+
* RDF has no literal subjects, so a literal subject is stored as the entity it names. An entity slug is local to the
|
|
46
|
+
* graph: the extractor resolved it to no stable IRI, and a label alone does not say two graphs mean one thing.
|
|
47
|
+
*/
|
|
48
|
+
var subjectNode = (term, graph) => term.kind === "entity" ? entityNode(term.entity, graph) : localEntityIri(graph, term.literal);
|
|
49
|
+
var objectNode = (term, graph) => term.kind === "entity" ? entityNode(term.entity, graph) : str(term.literal);
|
|
50
|
+
/** The predicate IRI a fact is stored with. */
|
|
51
|
+
var predicateOf = (fact, ontology = DEFAULT) => fact.assertion.predicateIri ?? ontology.resolve(fact.assertion.predicate).iri;
|
|
52
|
+
var nodeKey = (term) => term.termType === "Literal" ? JSON.stringify(term.value) : term.value;
|
|
53
|
+
/** A statement's id within a named graph, from the triple itself, so writing and reading agree. */
|
|
54
|
+
var statementId = (graph, subject, predicate, object) => `${graph}#${text(`${nodeKey(subject)} ${predicate} ${nodeKey(object)}`)}`;
|
|
55
|
+
/** The id a fact has once stored in `graph` ({@link triplesToFacts} reads it back). */
|
|
56
|
+
var idInGraph = (fact, graph, ontology = DEFAULT) => FactId.make(graph.startsWith("https://dxos.org/semantic/fact/") ? factIdFromIri(graph) : statementId(graph, subjectNode(fact.assertion.subject, graph), predicateOf(fact, ontology), objectNode(fact.assertion.object, graph)));
|
|
57
|
+
/** Expands a fact into its statement, the descriptions of its entities, and its graph's provenance. */
|
|
58
|
+
var factToTriples = (fact, ontology = DEFAULT) => {
|
|
59
|
+
const graph = namedNode(graphOf(fact));
|
|
60
|
+
const meta = defaultGraph();
|
|
61
|
+
const predicate = predicateOf(fact, ontology);
|
|
62
|
+
const subject = subjectNode(fact.assertion.subject, graph.value);
|
|
63
|
+
const object = objectNode(fact.assertion.object, graph.value);
|
|
64
|
+
const quads = [quad(subject, namedNode(predicate), object, graph)];
|
|
65
|
+
for (const [node, term] of [[subject, fact.assertion.subject], [object, fact.assertion.object]]) {
|
|
66
|
+
if (node.termType !== "NamedNode") continue;
|
|
67
|
+
const label = term.kind === "entity" ? term.label : term.literal;
|
|
68
|
+
if (label !== void 0) quads.push(quad(node, namedNode(RDFS_LABEL), str(label), graph));
|
|
69
|
+
if (term.kind === "entity" && term.type) quads.push(quad(node, namedNode(RDF_TYPE), namedNode(classIri(term.type)), graph));
|
|
70
|
+
}
|
|
71
|
+
if (!ontology.get(predicate)) {
|
|
72
|
+
const definition = {
|
|
73
|
+
iri: predicate,
|
|
74
|
+
name: nameFor(fact.assertion.predicate),
|
|
75
|
+
label: fact.assertion.predicate,
|
|
76
|
+
...fact.assertion.predicateDescription ? { description: fact.assertion.predicateDescription } : {},
|
|
77
|
+
...brainNamespaceOf(predicate) ? { definedBy: brainNamespaceOf(predicate) } : {}
|
|
78
|
+
};
|
|
79
|
+
quads.push(...toQuads(definition));
|
|
80
|
+
}
|
|
81
|
+
const about = (name, value) => quads.push(quad(graph, name, value, meta));
|
|
82
|
+
about(namedNode(RDF_TYPE), namedNode(SX_GRAPH));
|
|
83
|
+
about(sx("factuality"), str(fact.factuality.value));
|
|
84
|
+
about(sx("polarity"), str(fact.factuality.polarity));
|
|
85
|
+
about(prov("wasDerivedFrom"), str(fact.attribution.source));
|
|
86
|
+
about(prov("generatedAtTime"), str(fact.attribution.generatedAtTime));
|
|
87
|
+
about(sx("recordedAt"), str(fact.recordedAt));
|
|
88
|
+
about(sx("sourceHash"), str(fact.sourceHash));
|
|
89
|
+
about(sx("extractorId"), str(fact.extractor.id));
|
|
90
|
+
about(sx("extractorModel"), str(fact.extractor.model));
|
|
91
|
+
about(sx("extractorVersion"), str(fact.extractor.version));
|
|
92
|
+
const optional = [
|
|
93
|
+
[sx("confidence"), fact.factuality.confidence?.toString()],
|
|
94
|
+
[sx("nature"), fact.factuality.nature],
|
|
95
|
+
[sx("validFrom"), fact.assertion.validFrom],
|
|
96
|
+
[sx("validTo"), fact.assertion.validTo],
|
|
97
|
+
[sx("quote"), fact.assertion.quote],
|
|
98
|
+
[sx("agentLabel"), fact.attribution.agentLabel],
|
|
99
|
+
[sx("spanStart"), fact.attribution.span?.start.toString()],
|
|
100
|
+
[sx("spanEnd"), fact.attribution.span?.end.toString()],
|
|
101
|
+
[sx("force"), fact.illocution?.force],
|
|
102
|
+
[sx("mood"), fact.illocution?.mood],
|
|
103
|
+
[sx("addressee"), fact.illocution?.addressee],
|
|
104
|
+
[sx("pass"), fact.pass],
|
|
105
|
+
[sx("kind"), fact.kind],
|
|
106
|
+
[sx("origin"), fact.origin]
|
|
107
|
+
];
|
|
108
|
+
for (const [name, value] of optional) if (value !== void 0) about(name, str(value));
|
|
109
|
+
if (fact.attribution.agent) about(prov("wasAttributedTo"), entityNode(fact.attribution.agent, graph.value));
|
|
110
|
+
for (const derived of fact.attribution.wasDerivedFrom ?? []) about(sx("derivedFrom"), str(derived));
|
|
111
|
+
for (const superseded of fact.supersedes ?? []) about(sx("supersedes"), namedNode(superseded));
|
|
112
|
+
for (const retracted of fact.retracts ?? []) about(sx("retracts"), namedNode(retracted));
|
|
113
|
+
return quads;
|
|
114
|
+
};
|
|
115
|
+
/** Reassembles (and validates) facts from quads: the inverse of {@link factToTriples}, one fact per statement. */
|
|
116
|
+
var triplesToFacts = (quads, ontology = DEFAULT) => {
|
|
117
|
+
const labels = /* @__PURE__ */ new Map();
|
|
118
|
+
const comments = /* @__PURE__ */ new Map();
|
|
119
|
+
const provenance = /* @__PURE__ */ new Map();
|
|
120
|
+
const graphs = /* @__PURE__ */ new Map();
|
|
121
|
+
const graphFor = (iri) => {
|
|
122
|
+
let graph = graphs.get(iri);
|
|
123
|
+
if (!graph) graphs.set(iri, graph = {
|
|
124
|
+
statements: [],
|
|
125
|
+
labels: /* @__PURE__ */ new Map(),
|
|
126
|
+
types: /* @__PURE__ */ new Map()
|
|
127
|
+
});
|
|
128
|
+
return graph;
|
|
129
|
+
};
|
|
130
|
+
for (const entry of quads) if (entry.graph.termType === "DefaultGraph") {
|
|
131
|
+
let props = provenance.get(entry.subject.value);
|
|
132
|
+
if (!props) provenance.set(entry.subject.value, props = /* @__PURE__ */ new Map());
|
|
133
|
+
const name = localName(entry.predicate.value);
|
|
134
|
+
props.set(name, [...props.get(name) ?? [], entry.object]);
|
|
135
|
+
} else if (entry.graph.value === "https://dxos.org/semantic/graph/ontology") {
|
|
136
|
+
const known = entry.predicate.value === "http://www.w3.org/2000/01/rdf-schema#label" ? labels : entry.predicate.value === "http://www.w3.org/2000/01/rdf-schema#comment" ? comments : void 0;
|
|
137
|
+
if (known && !known.has(entry.subject.value)) known.set(entry.subject.value, entry.object.value);
|
|
138
|
+
} else if (entry.predicate.value === "http://www.w3.org/2000/01/rdf-schema#label") {
|
|
139
|
+
const graph = graphFor(entry.graph.value);
|
|
140
|
+
if (!graph.labels.has(entry.subject.value)) graph.labels.set(entry.subject.value, entry.object.value);
|
|
141
|
+
} else {
|
|
142
|
+
const kind = entry.predicate.value === "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" ? KINDS.get(entry.object.value) : void 0;
|
|
143
|
+
if (kind) graphFor(entry.graph.value).types.set(entry.subject.value, kind);
|
|
144
|
+
else graphFor(entry.graph.value).statements.push(entry);
|
|
145
|
+
}
|
|
146
|
+
const facts = [];
|
|
147
|
+
for (const [iri, graph] of graphs) {
|
|
148
|
+
const props = provenance.get(iri) ?? /* @__PURE__ */ new Map();
|
|
149
|
+
const one = (name) => props.get(name)?.[0]?.value;
|
|
150
|
+
const many = (name) => props.get(name)?.map((term) => term.value) ?? [];
|
|
151
|
+
const term = (node) => node.termType === "Literal" ? {
|
|
152
|
+
kind: "literal",
|
|
153
|
+
literal: node.value
|
|
154
|
+
} : node.termType === "NamedNode" ? {
|
|
155
|
+
kind: "entity",
|
|
156
|
+
entity: entityKey(node.value, iri),
|
|
157
|
+
...graph.labels.has(node.value) ? { label: graph.labels.get(node.value) } : {},
|
|
158
|
+
...graph.types.has(node.value) ? { type: graph.types.get(node.value) } : {}
|
|
159
|
+
} : void 0;
|
|
160
|
+
const agent = props.get("wasAttributedTo")?.[0];
|
|
161
|
+
const derivedFrom = many("derivedFrom");
|
|
162
|
+
const supersedes = many("supersedes");
|
|
163
|
+
const retracts = many("retracts");
|
|
164
|
+
const spanStart = one("spanStart");
|
|
165
|
+
const spanEnd = one("spanEnd");
|
|
166
|
+
const force = one("force");
|
|
167
|
+
const own = iri.startsWith(FACT);
|
|
168
|
+
for (const statement of graph.statements) {
|
|
169
|
+
const predicate = statement.predicate.value;
|
|
170
|
+
const candidate = {
|
|
171
|
+
id: own ? factIdFromIri(iri) : statementId(iri, statement.subject, predicate, statement.object),
|
|
172
|
+
...own ? {} : { graph: iri },
|
|
173
|
+
assertion: {
|
|
174
|
+
subject: term(statement.subject),
|
|
175
|
+
predicate: labels.get(predicate) ?? ontology.get(predicate)?.label ?? labelFromIri(predicate),
|
|
176
|
+
predicateIri: predicate,
|
|
177
|
+
...comments.has(predicate) && !ontology.get(predicate) ? { predicateDescription: comments.get(predicate) } : {},
|
|
178
|
+
object: term(statement.object),
|
|
179
|
+
...one("validFrom") !== void 0 ? { validFrom: one("validFrom") } : {},
|
|
180
|
+
...one("validTo") !== void 0 ? { validTo: one("validTo") } : {},
|
|
181
|
+
...one("quote") !== void 0 ? { quote: one("quote") } : {}
|
|
182
|
+
},
|
|
183
|
+
factuality: {
|
|
184
|
+
value: one("factuality"),
|
|
185
|
+
polarity: one("polarity"),
|
|
186
|
+
...one("confidence") !== void 0 ? { confidence: Number(one("confidence")) } : {},
|
|
187
|
+
...one("nature") !== void 0 ? { nature: one("nature") } : {}
|
|
188
|
+
},
|
|
189
|
+
...force !== void 0 ? { illocution: {
|
|
190
|
+
force,
|
|
191
|
+
...one("mood") !== void 0 ? { mood: one("mood") } : {},
|
|
192
|
+
...one("addressee") !== void 0 ? { addressee: one("addressee") } : {}
|
|
193
|
+
} } : {},
|
|
194
|
+
attribution: {
|
|
195
|
+
...agent !== void 0 ? { agent: entityKey(agent.value, iri) } : {},
|
|
196
|
+
...one("agentLabel") !== void 0 ? { agentLabel: one("agentLabel") } : {},
|
|
197
|
+
source: one("wasDerivedFrom"),
|
|
198
|
+
generatedAtTime: one("generatedAtTime"),
|
|
199
|
+
...derivedFrom.length > 0 ? { wasDerivedFrom: derivedFrom } : {},
|
|
200
|
+
...spanStart !== void 0 && spanEnd !== void 0 ? { span: {
|
|
201
|
+
start: Number(spanStart),
|
|
202
|
+
end: Number(spanEnd)
|
|
203
|
+
} } : {}
|
|
204
|
+
},
|
|
205
|
+
recordedAt: one("recordedAt"),
|
|
206
|
+
extractor: {
|
|
207
|
+
id: one("extractorId"),
|
|
208
|
+
model: one("extractorModel"),
|
|
209
|
+
version: one("extractorVersion")
|
|
210
|
+
},
|
|
211
|
+
sourceHash: one("sourceHash"),
|
|
212
|
+
...one("pass") !== void 0 ? { pass: one("pass") } : {},
|
|
213
|
+
...one("kind") !== void 0 ? { kind: one("kind") } : {},
|
|
214
|
+
...one("origin") !== void 0 ? { origin: one("origin") } : {},
|
|
215
|
+
...supersedes.length > 0 ? { supersedes } : {},
|
|
216
|
+
...retracts.length > 0 ? { retracts } : {}
|
|
217
|
+
};
|
|
218
|
+
facts.push(decodeFact(candidate));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return facts;
|
|
222
|
+
};
|
|
223
|
+
//#endregion
|
|
224
|
+
export { idInGraph as a, triplesToFacts as c, factToTriples as i, Mapping_exports as n, isKindQuad as o, classIri as r, predicateOf as s, KIND_CLASSES as t };
|
|
225
|
+
|
|
226
|
+
//# sourceMappingURL=chunk-Mapping.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-Mapping.mjs","names":["Rdf","Fact.Fact","Vocab.SCHEMA","Vocab.SKOS","Vocab.DX","Vocab.entityNode","Vocab.localEntityIri","Vocab.str","Ontology.DEFAULT","Hash.text","Vocab.factIdFromIri","Fact.graphOf","Vocab.RDFS_LABEL","Vocab.RDF_TYPE","Ontology.nameFor","Vocab.brainNamespaceOf","Ontology.toQuads","Vocab.SX_GRAPH","Vocab.sx","Vocab.prov","Vocab.entityKey","Vocab.FACT","Ontology.labelFromIri"],"sources":["../../src/Mapping.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport * as Fact from './Fact.ts';\nimport * as Hash from './Hash.ts';\nimport * as Ontology from './Ontology.ts';\nimport * as Rdf from './Rdf.ts';\nimport * as Vocab from './Vocab.ts';\n\nconst { quad, defaultGraph, namedNode } = Rdf;\n\nconst decodeFact = Schema.decodeUnknownSync(Fact.Fact);\n\nconst localName = (iri: string) => iri.replace(/^.*[#/]/, '');\n\n//\n// Storage shape: each statement is a real triple inside a named graph, and the graph's provenance is stated once,\n// about the graph, in the default graph. Entities carry their labels and kinds inside the graph that mentions them,\n// and one known by a label alone has an IRI local to that graph; a predicate the ontology does not define is\n// described (label, comment, defining namespace) in the ontology graph.\n//\n// Invariant: every provenance predicate has a UNIQUE local name (reassembly keys provenance by local name).\n// `attribution.source` is `prov:wasDerivedFrom`; `attribution.wasDerivedFrom` uses `sx:derivedFrom` so the two\n// never collide. `illocution` is flattened to `sx:force` / `sx:mood` / `sx:addressee`.\n//\n\nconst CLASSES: Record<Fact.EntityKind, string> = {\n person: `${Vocab.SCHEMA}Person`,\n org: `${Vocab.SCHEMA}Organization`,\n place: `${Vocab.SCHEMA}Place`,\n event: `${Vocab.SCHEMA}Event`,\n concept: `${Vocab.SKOS}Concept`,\n thing: `${Vocab.SCHEMA}Thing`,\n};\n\n// Facts stored before the kinds moved to schema.org typed entities with `dx:` classes.\nconst LEGACY_CLASSES: Record<Fact.EntityKind, string> = {\n person: `${Vocab.DX}Person`,\n org: `${Vocab.DX}Organization`,\n place: `${Vocab.DX}Place`,\n event: `${Vocab.DX}Event`,\n concept: `${Vocab.DX}Concept`,\n thing: `${Vocab.DX}Thing`,\n};\n\nconst KINDS = new Map(\n [...Object.entries(CLASSES), ...Object.entries(LEGACY_CLASSES)].map(([kind, iri]) => [iri, kind as Fact.EntityKind]),\n);\n\n/** The class IRIs an entity's kind is typed with; an `rdf:type` to any other class is a statement, not a kind. */\nexport const KIND_CLASSES: ReadonlyArray<string> = [...KINDS.keys()];\n\n/** Whether a quad states an entity's kind (an `rdf:type` to a kind class) rather than making a statement. */\nexport const isKindQuad = (predicate: string, object: string): boolean =>\n predicate === Vocab.RDF_TYPE && KINDS.has(object);\n\n/** The class IRI an entity of this kind is typed with. */\nexport const classIri = (kind: Fact.EntityKind): string => CLASSES[kind];\n\n/**\n * RDF has no literal subjects, so a literal subject is stored as the entity it names. An entity slug is local to the\n * graph: the extractor resolved it to no stable IRI, and a label alone does not say two graphs mean one thing.\n */\nconst subjectNode = (term: Fact.Term, graph: string): Rdf.NamedNode =>\n term.kind === 'entity' ? Vocab.entityNode(term.entity, graph) : Vocab.localEntityIri(graph, term.literal);\n\nconst objectNode = (term: Fact.Term, graph: string): Rdf.NamedNode | Rdf.Literal =>\n term.kind === 'entity' ? Vocab.entityNode(term.entity, graph) : Vocab.str(term.literal);\n\n/** The predicate IRI a fact is stored with. */\nexport const predicateOf = (fact: Fact.Fact, ontology: Ontology.Ontology = Ontology.DEFAULT): string =>\n fact.assertion.predicateIri ?? ontology.resolve(fact.assertion.predicate).iri;\n\nconst nodeKey = (term: Rdf.Term): string => (term.termType === 'Literal' ? JSON.stringify(term.value) : term.value);\n\n/** A statement's id within a named graph, from the triple itself, so writing and reading agree. */\nconst statementId = (graph: string, subject: Rdf.Term, predicate: string, object: Rdf.Term): string =>\n `${graph}#${Hash.text(`${nodeKey(subject)} ${predicate} ${nodeKey(object)}`)}`;\n\n/** The id a fact has once stored in `graph` ({@link triplesToFacts} reads it back). */\nexport const idInGraph = (\n fact: Fact.Fact,\n graph: string,\n ontology: Ontology.Ontology = Ontology.DEFAULT,\n): Fact.FactId =>\n Fact.FactId.make(\n graph.startsWith(Vocab.FACT)\n ? Vocab.factIdFromIri(graph)\n : statementId(\n graph,\n subjectNode(fact.assertion.subject, graph),\n predicateOf(fact, ontology),\n objectNode(fact.assertion.object, graph),\n ),\n );\n\n/** Expands a fact into its statement, the descriptions of its entities, and its graph's provenance. */\nexport const factToTriples = (fact: Fact.Fact, ontology: Ontology.Ontology = Ontology.DEFAULT): Rdf.Quad[] => {\n const graph = namedNode(Fact.graphOf(fact));\n const meta = defaultGraph();\n const predicate = predicateOf(fact, ontology);\n const subject = subjectNode(fact.assertion.subject, graph.value);\n const object = objectNode(fact.assertion.object, graph.value);\n const quads: Rdf.Quad[] = [quad(subject, namedNode(predicate), object, graph)];\n\n for (const [node, term] of [\n [subject, fact.assertion.subject],\n [object, fact.assertion.object],\n ] as const) {\n if (node.termType !== 'NamedNode') {\n continue;\n }\n const label = term.kind === 'entity' ? term.label : term.literal;\n if (label !== undefined) {\n quads.push(quad(node, namedNode(Vocab.RDFS_LABEL), Vocab.str(label), graph));\n }\n if (term.kind === 'entity' && term.type) {\n quads.push(quad(node, namedNode(Vocab.RDF_TYPE), namedNode(classIri(term.type)), graph));\n }\n }\n\n // A predicate the ontology does not define is described in the ontology graph, never inside the statement's.\n if (!ontology.get(predicate)) {\n const definition: Ontology.Entry = {\n iri: predicate,\n name: Ontology.nameFor(fact.assertion.predicate),\n label: fact.assertion.predicate,\n ...(fact.assertion.predicateDescription ? { description: fact.assertion.predicateDescription } : {}),\n ...(Vocab.brainNamespaceOf(predicate) ? { definedBy: Vocab.brainNamespaceOf(predicate) } : {}),\n };\n quads.push(...Ontology.toQuads(definition));\n }\n\n const about = (name: Rdf.NamedNode, value: Rdf.NamedNode | Rdf.Literal) => quads.push(quad(graph, name, value, meta));\n about(namedNode(Vocab.RDF_TYPE), namedNode(Vocab.SX_GRAPH));\n about(Vocab.sx('factuality'), Vocab.str(fact.factuality.value));\n about(Vocab.sx('polarity'), Vocab.str(fact.factuality.polarity));\n about(Vocab.prov('wasDerivedFrom'), Vocab.str(fact.attribution.source));\n about(Vocab.prov('generatedAtTime'), Vocab.str(fact.attribution.generatedAtTime));\n about(Vocab.sx('recordedAt'), Vocab.str(fact.recordedAt));\n about(Vocab.sx('sourceHash'), Vocab.str(fact.sourceHash));\n about(Vocab.sx('extractorId'), Vocab.str(fact.extractor.id));\n about(Vocab.sx('extractorModel'), Vocab.str(fact.extractor.model));\n about(Vocab.sx('extractorVersion'), Vocab.str(fact.extractor.version));\n const optional: ReadonlyArray<[Rdf.NamedNode, string | undefined]> = [\n [Vocab.sx('confidence'), fact.factuality.confidence?.toString()],\n [Vocab.sx('nature'), fact.factuality.nature],\n [Vocab.sx('validFrom'), fact.assertion.validFrom],\n [Vocab.sx('validTo'), fact.assertion.validTo],\n [Vocab.sx('quote'), fact.assertion.quote],\n [Vocab.sx('agentLabel'), fact.attribution.agentLabel],\n [Vocab.sx('spanStart'), fact.attribution.span?.start.toString()],\n [Vocab.sx('spanEnd'), fact.attribution.span?.end.toString()],\n [Vocab.sx('force'), fact.illocution?.force],\n [Vocab.sx('mood'), fact.illocution?.mood],\n [Vocab.sx('addressee'), fact.illocution?.addressee],\n [Vocab.sx('pass'), fact.pass],\n [Vocab.sx('kind'), fact.kind],\n [Vocab.sx('origin'), fact.origin],\n ];\n for (const [name, value] of optional) {\n if (value !== undefined) {\n about(name, Vocab.str(value));\n }\n }\n if (fact.attribution.agent) {\n about(Vocab.prov('wasAttributedTo'), Vocab.entityNode(fact.attribution.agent, graph.value));\n }\n for (const derived of fact.attribution.wasDerivedFrom ?? []) {\n about(Vocab.sx('derivedFrom'), Vocab.str(derived));\n }\n for (const superseded of fact.supersedes ?? []) {\n about(Vocab.sx('supersedes'), namedNode(superseded));\n }\n for (const retracted of fact.retracts ?? []) {\n about(Vocab.sx('retracts'), namedNode(retracted));\n }\n return quads;\n};\n\n/** Reassembles (and validates) facts from quads: the inverse of {@link factToTriples}, one fact per statement. */\nexport const triplesToFacts = (\n quads: readonly Rdf.Quad[],\n ontology: Ontology.Ontology = Ontology.DEFAULT,\n): Fact.Fact[] => {\n const labels = new Map<string, string>();\n const comments = new Map<string, string>();\n const provenance = new Map<string, Map<string, Rdf.Term[]>>();\n const graphs = new Map<\n string,\n { statements: Rdf.Quad[]; labels: Map<string, string>; types: Map<string, Fact.EntityKind> }\n >();\n const graphFor = (iri: string) => {\n let graph = graphs.get(iri);\n if (!graph) {\n graphs.set(iri, (graph = { statements: [], labels: new Map(), types: new Map() }));\n }\n return graph;\n };\n\n for (const entry of quads) {\n if (entry.graph.termType === 'DefaultGraph') {\n let props = provenance.get(entry.subject.value);\n if (!props) {\n provenance.set(entry.subject.value, (props = new Map()));\n }\n const name = localName(entry.predicate.value);\n props.set(name, [...(props.get(name) ?? []), entry.object]);\n } else if (entry.graph.value === Vocab.ONTOLOGY_GRAPH) {\n const known =\n entry.predicate.value === Vocab.RDFS_LABEL\n ? labels\n : entry.predicate.value === Vocab.RDFS_COMMENT\n ? comments\n : undefined;\n if (known && !known.has(entry.subject.value)) {\n known.set(entry.subject.value, entry.object.value);\n }\n } else if (entry.predicate.value === Vocab.RDFS_LABEL) {\n const graph = graphFor(entry.graph.value);\n if (!graph.labels.has(entry.subject.value)) {\n graph.labels.set(entry.subject.value, entry.object.value);\n }\n } else {\n const kind = entry.predicate.value === Vocab.RDF_TYPE ? KINDS.get(entry.object.value) : undefined;\n if (kind) {\n graphFor(entry.graph.value).types.set(entry.subject.value, kind);\n } else {\n graphFor(entry.graph.value).statements.push(entry);\n }\n }\n }\n\n const facts: Fact.Fact[] = [];\n for (const [iri, graph] of graphs) {\n const props = provenance.get(iri) ?? new Map<string, Rdf.Term[]>();\n const one = (name: string) => props.get(name)?.[0]?.value;\n const many = (name: string) => props.get(name)?.map((term) => term.value) ?? [];\n const term = (node: Rdf.Term): Fact.Term | undefined =>\n node.termType === 'Literal'\n ? { kind: 'literal', literal: node.value }\n : node.termType === 'NamedNode'\n ? {\n kind: 'entity',\n entity: Vocab.entityKey(node.value, iri),\n ...(graph.labels.has(node.value) ? { label: graph.labels.get(node.value) } : {}),\n ...(graph.types.has(node.value) ? { type: graph.types.get(node.value) } : {}),\n }\n : undefined;\n const agent = props.get('wasAttributedTo')?.[0];\n const derivedFrom = many('derivedFrom');\n const supersedes = many('supersedes');\n const retracts = many('retracts');\n const spanStart = one('spanStart');\n const spanEnd = one('spanEnd');\n const force = one('force');\n const own = iri.startsWith(Vocab.FACT);\n\n for (const statement of graph.statements) {\n const predicate = statement.predicate.value;\n // An untyped candidate; decoding validates required fields and literal unions, so missing provenance throws.\n const candidate = {\n id: own ? Vocab.factIdFromIri(iri) : statementId(iri, statement.subject, predicate, statement.object),\n ...(own ? {} : { graph: iri }),\n assertion: {\n subject: term(statement.subject),\n predicate: labels.get(predicate) ?? ontology.get(predicate)?.label ?? Ontology.labelFromIri(predicate),\n predicateIri: predicate,\n ...(comments.has(predicate) && !ontology.get(predicate)\n ? { predicateDescription: comments.get(predicate) }\n : {}),\n object: term(statement.object),\n ...(one('validFrom') !== undefined ? { validFrom: one('validFrom') } : {}),\n ...(one('validTo') !== undefined ? { validTo: one('validTo') } : {}),\n ...(one('quote') !== undefined ? { quote: one('quote') } : {}),\n },\n factuality: {\n value: one('factuality'),\n polarity: one('polarity'),\n ...(one('confidence') !== undefined ? { confidence: Number(one('confidence')) } : {}),\n ...(one('nature') !== undefined ? { nature: one('nature') } : {}),\n },\n ...(force !== undefined\n ? {\n illocution: {\n force,\n ...(one('mood') !== undefined ? { mood: one('mood') } : {}),\n ...(one('addressee') !== undefined ? { addressee: one('addressee') } : {}),\n },\n }\n : {}),\n attribution: {\n ...(agent !== undefined ? { agent: Vocab.entityKey(agent.value, iri) } : {}),\n ...(one('agentLabel') !== undefined ? { agentLabel: one('agentLabel') } : {}),\n source: one('wasDerivedFrom'),\n generatedAtTime: one('generatedAtTime'),\n ...(derivedFrom.length > 0 ? { wasDerivedFrom: derivedFrom } : {}),\n ...(spanStart !== undefined && spanEnd !== undefined\n ? { span: { start: Number(spanStart), end: Number(spanEnd) } }\n : {}),\n },\n recordedAt: one('recordedAt'),\n extractor: { id: one('extractorId'), model: one('extractorModel'), version: one('extractorVersion') },\n sourceHash: one('sourceHash'),\n ...(one('pass') !== undefined ? { pass: one('pass') } : {}),\n ...(one('kind') !== undefined ? { kind: one('kind') } : {}),\n ...(one('origin') !== undefined ? { origin: one('origin') } : {}),\n ...(supersedes.length > 0 ? { supersedes } : {}),\n ...(retracts.length > 0 ? { retracts } : {}),\n };\n facts.push(decodeFact(candidate));\n }\n }\n return facts;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,IAAM,EAAE,MAAM,cAAc,cAAcA;AAE1C,IAAM,aAAa,OAAO,kBAAkBC,IAAS;AAErD,IAAM,aAAa,QAAgB,IAAI,QAAQ,WAAW,EAAE;AAa5D,IAAM,UAA2C;CAC/C,QAAQ,GAAGC,OAAa;CACxB,KAAK,GAAGA,OAAa;CACrB,OAAO,GAAGA,OAAa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B,GAAI,IAAI,MAAM,MAAM,KAAA,IAAY,EAAE,MAAM,IAAI,MAAM,EAAE,IAAI,CAAC;IACzD,GAAI,IAAI,MAAM,MAAM,KAAA,IAAY,EAAE,MAAM,IAAI,MAAM,EAAE,IAAI,CAAC;IACzD,GAAI,IAAI,QAAQ,MAAM,KAAA,IAAY,EAAE,QAAQ,IAAI,QAAQ,EAAE,IAAI,CAAC;IAC/D,GAAI,WAAW,SAAS,IAAI,EAAE,WAAW,IAAI,CAAC;IAC9C,GAAI,SAAS,SAAS,IAAI,EAAE,SAAS,IAAI,CAAC;GAC5C;GACA,MAAM,KAAK,WAAW,SAAS,CAAC;EAClC;CACF;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
import { BaseError } from "@dxos/errors";
|
|
3
|
+
//#region src/MemoryError.ts
|
|
4
|
+
var MemoryError_exports = /* @__PURE__ */ __exportAll({ MemoryError: () => MemoryError });
|
|
5
|
+
/** The memory refused, could not be reached, or the input does not compile; the message says which. */
|
|
6
|
+
var MemoryError = class extends BaseError.extend("MemoryError", "Memory operation failed.") {};
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MemoryError_exports as n, MemoryError as t };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=chunk-MemoryError.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-MemoryError.mjs","names":[],"sources":["../../src/MemoryError.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport { BaseError } from '@dxos/errors';\n\n/** The memory refused, could not be reached, or the input does not compile; the message says which. */\nexport class MemoryError extends BaseError.extend('MemoryError', 'Memory operation failed.') {}\n"],"mappings":";;;;;AASA,IAAa,cAAb,cAAiC,UAAU,OAAO,eAAe,0BAA0B,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
import { _ as PredicateEntry, i as EntityKey, s as Fact, v as SourceUri } from "./chunk-Fact.mjs";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
//#region src/MemoryQuery.ts
|
|
5
|
+
var MemoryQuery_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
Any: () => Any,
|
|
7
|
+
Cursor: () => Cursor,
|
|
8
|
+
FactQuery: () => FactQuery,
|
|
9
|
+
Facts: () => Facts,
|
|
10
|
+
Graphs: () => Graphs,
|
|
11
|
+
Predicates: () => Predicates,
|
|
12
|
+
Sparql: () => Sparql,
|
|
13
|
+
SparqlRow: () => SparqlRow,
|
|
14
|
+
SparqlTerm: () => SparqlTerm,
|
|
15
|
+
cursor: () => cursor,
|
|
16
|
+
facts: () => facts,
|
|
17
|
+
graphs: () => graphs,
|
|
18
|
+
predicates: () => predicates,
|
|
19
|
+
resultOf: () => resultOf,
|
|
20
|
+
resultSchema: () => resultSchema,
|
|
21
|
+
results: () => results,
|
|
22
|
+
sparql: () => sparql
|
|
23
|
+
});
|
|
24
|
+
/** What a {@link Facts} query selects; every field set must hold. */
|
|
25
|
+
var FactQuery = Schema.Struct({
|
|
26
|
+
/** Entity in the subject position. */
|
|
27
|
+
subjectEntity: Schema.optional(EntityKey),
|
|
28
|
+
/** Entity in the subject or object position. */
|
|
29
|
+
entity: Schema.optional(EntityKey),
|
|
30
|
+
/** Predicate IRI, or a surface form resolved through the memory's ontology. */
|
|
31
|
+
predicate: Schema.optional(Schema.String),
|
|
32
|
+
/** The item the facts were read from. */
|
|
33
|
+
source: Schema.optional(SourceUri),
|
|
34
|
+
/** Inclusive lower bound on factuality confidence. */
|
|
35
|
+
minConfidence: Schema.optional(Schema.Number)
|
|
36
|
+
});
|
|
37
|
+
/** One RDF term a SPARQL solution binds; plain data, so rows cross a wire as JSON. */
|
|
38
|
+
var SparqlTerm = Schema.Union([
|
|
39
|
+
Schema.Struct({
|
|
40
|
+
termType: Schema.Literal("NamedNode"),
|
|
41
|
+
value: Schema.String
|
|
42
|
+
}),
|
|
43
|
+
Schema.Struct({
|
|
44
|
+
termType: Schema.Literal("BlankNode"),
|
|
45
|
+
value: Schema.String
|
|
46
|
+
}),
|
|
47
|
+
Schema.Struct({
|
|
48
|
+
termType: Schema.Literal("Literal"),
|
|
49
|
+
value: Schema.String,
|
|
50
|
+
datatype: Schema.optional(Schema.String),
|
|
51
|
+
language: Schema.optional(Schema.String)
|
|
52
|
+
})
|
|
53
|
+
]);
|
|
54
|
+
/** One SPARQL solution: each bound variable (named without `?`) to its term; an unbound variable is absent. */
|
|
55
|
+
var SparqlRow = Schema.Record(Schema.String, SparqlTerm);
|
|
56
|
+
/** Facts whose statement matches a pattern. Answered without SPARQL on every implementation. */
|
|
57
|
+
var Facts = Schema.TaggedStruct("facts", { pattern: FactQuery });
|
|
58
|
+
/** Every fact in the named graphs a SPARQL `SELECT ?g` binds. */
|
|
59
|
+
var Graphs = Schema.TaggedStruct("graphs", { sparql: Schema.String });
|
|
60
|
+
/** Any SPARQL `SELECT`, its solutions returned as written. */
|
|
61
|
+
var Sparql = Schema.TaggedStruct("sparql", { sparql: Schema.String });
|
|
62
|
+
/** The predicates the memory knows. */
|
|
63
|
+
var Predicates = Schema.TaggedStruct("predicates", {});
|
|
64
|
+
/** How far a source has been read: the `through` of its read cursor. */
|
|
65
|
+
var Cursor = Schema.TaggedStruct("cursor", { source: SourceUri });
|
|
66
|
+
/** Any query kind. */
|
|
67
|
+
var Any = Schema.Union([
|
|
68
|
+
Facts,
|
|
69
|
+
Graphs,
|
|
70
|
+
Sparql,
|
|
71
|
+
Predicates,
|
|
72
|
+
Cursor
|
|
73
|
+
]);
|
|
74
|
+
/** The schema of each kind's answer, so a remote client decodes an answer by the query's `_tag`. */
|
|
75
|
+
var results = {
|
|
76
|
+
facts: Schema.Array(Fact),
|
|
77
|
+
graphs: Schema.Array(Fact),
|
|
78
|
+
sparql: Schema.Array(SparqlRow),
|
|
79
|
+
predicates: Schema.Array(PredicateEntry),
|
|
80
|
+
cursor: Schema.UndefinedOr(Schema.String)
|
|
81
|
+
};
|
|
82
|
+
/** The schema of a kind's answer. */
|
|
83
|
+
var resultSchema = (tag) => results[tag];
|
|
84
|
+
/** The schema of a query's answer. */
|
|
85
|
+
var resultOf = (query) => resultSchema(query._tag);
|
|
86
|
+
/** Facts whose statement matches the pattern; answers `Fact[]`. */
|
|
87
|
+
var facts = (pattern = {}) => Facts.make({ pattern });
|
|
88
|
+
/** Every fact in the graphs a `SELECT ?g` binds; answers `Fact[]`. */
|
|
89
|
+
var graphs = (sparql) => Graphs.make({ sparql });
|
|
90
|
+
/** A SPARQL `SELECT`'s solutions; answers `SparqlRow[]`. */
|
|
91
|
+
var sparql = (sparql) => Sparql.make({ sparql });
|
|
92
|
+
/** The known predicates; answers `PredicateEntry[]`. */
|
|
93
|
+
var predicates = () => Predicates.make({});
|
|
94
|
+
/** A source's read cursor; answers `string | undefined`. */
|
|
95
|
+
var cursor = (source) => Cursor.make({ source });
|
|
96
|
+
//#endregion
|
|
97
|
+
export { results as _, Graphs as a, Sparql as c, cursor as d, facts as f, resultSchema as g, resultOf as h, Facts as i, SparqlRow as l, predicates as m, Cursor as n, MemoryQuery_exports as o, graphs as p, FactQuery as r, Predicates as s, Any as t, SparqlTerm as u, sparql as v };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=chunk-MemoryQuery.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-MemoryQuery.mjs","names":["Fact.EntityKey","Fact.SourceUri","Fact.Fact","Fact.PredicateEntry"],"sources":["../../src/MemoryQuery.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Schema from 'effect/Schema';\n\nimport * as Fact from './Fact.ts';\n\n/** What a {@link Facts} query selects; every field set must hold. */\nexport const FactQuery = Schema.Struct({\n /** Entity in the subject position. */\n subjectEntity: Schema.optional(Fact.EntityKey),\n /** Entity in the subject or object position. */\n entity: Schema.optional(Fact.EntityKey),\n /** Predicate IRI, or a surface form resolved through the memory's ontology. */\n predicate: Schema.optional(Schema.String),\n /** The item the facts were read from. */\n source: Schema.optional(Fact.SourceUri),\n /** Inclusive lower bound on factuality confidence. */\n minConfidence: Schema.optional(Schema.Number),\n});\nexport interface FactQuery extends Schema.Schema.Type<typeof FactQuery> {}\n\n/** One RDF term a SPARQL solution binds; plain data, so rows cross a wire as JSON. */\nexport const SparqlTerm = Schema.Union([\n Schema.Struct({ termType: Schema.Literal('NamedNode'), value: Schema.String }),\n Schema.Struct({ termType: Schema.Literal('BlankNode'), value: Schema.String }),\n Schema.Struct({\n termType: Schema.Literal('Literal'),\n value: Schema.String,\n datatype: Schema.optional(Schema.String),\n language: Schema.optional(Schema.String),\n }),\n]);\nexport type SparqlTerm = Schema.Schema.Type<typeof SparqlTerm>;\n\n/** One SPARQL solution: each bound variable (named without `?`) to its term; an unbound variable is absent. */\nexport const SparqlRow = Schema.Record(Schema.String, SparqlTerm);\nexport type SparqlRow = Schema.Schema.Type<typeof SparqlRow>;\n\n//\n// Query kinds. Each is a tagged struct, so a query is plain JSON; `results` names the schema of each kind's answer.\n//\n\n/** Facts whose statement matches a pattern. Answered without SPARQL on every implementation. */\nexport const Facts = Schema.TaggedStruct('facts', { pattern: FactQuery });\nexport interface Facts extends Schema.Schema.Type<typeof Facts> {}\n\n/** Every fact in the named graphs a SPARQL `SELECT ?g` binds. */\nexport const Graphs = Schema.TaggedStruct('graphs', { sparql: Schema.String });\nexport interface Graphs extends Schema.Schema.Type<typeof Graphs> {}\n\n/** Any SPARQL `SELECT`, its solutions returned as written. */\nexport const Sparql = Schema.TaggedStruct('sparql', { sparql: Schema.String });\nexport interface Sparql extends Schema.Schema.Type<typeof Sparql> {}\n\n/** The predicates the memory knows. */\nexport const Predicates = Schema.TaggedStruct('predicates', {});\nexport interface Predicates extends Schema.Schema.Type<typeof Predicates> {}\n\n/** How far a source has been read: the `through` of its read cursor. */\nexport const Cursor = Schema.TaggedStruct('cursor', { source: Fact.SourceUri });\nexport interface Cursor extends Schema.Schema.Type<typeof Cursor> {}\n\n/** Any query kind. */\nexport const Any = Schema.Union([Facts, Graphs, Sparql, Predicates, Cursor]);\nexport type Any = Schema.Schema.Type<typeof Any>;\n\nexport type Tag = Any['_tag'];\n\n/** What each kind answers. */\nexport interface Results {\n readonly facts: readonly Fact.Fact[];\n readonly graphs: readonly Fact.Fact[];\n readonly sparql: readonly SparqlRow[];\n readonly predicates: readonly Fact.PredicateEntry[];\n readonly cursor: string | undefined;\n}\n\n/** The schema of each kind's answer, so a remote client decodes an answer by the query's `_tag`. */\nexport const results: { readonly [K in Tag]: Schema.Codec<Results[K], unknown> } = {\n facts: Schema.Array(Fact.Fact),\n graphs: Schema.Array(Fact.Fact),\n sparql: Schema.Array(SparqlRow),\n predicates: Schema.Array(Fact.PredicateEntry),\n cursor: Schema.UndefinedOr(Schema.String),\n};\n\n/** The schema of a kind's answer. */\nexport const resultSchema = <K extends Tag>(tag: K): Schema.Codec<Results[K], unknown> => results[tag];\n\n/** The schema of a query's answer. */\nexport const resultOf = <Q extends Any>(query: Q): Schema.Codec<Results[Q['_tag']], unknown> =>\n resultSchema<Q['_tag']>(query._tag);\n\n/** What a query answers. */\nexport type ResultOf<Q extends Any> = Results[Q['_tag']];\n\n/** Facts whose statement matches the pattern; answers `Fact[]`. */\nexport const facts = (pattern: FactQuery = {}): Facts => Facts.make({ pattern });\n\n/** Every fact in the graphs a `SELECT ?g` binds; answers `Fact[]`. */\nexport const graphs = (sparql: string): Graphs => Graphs.make({ sparql });\n\n/** A SPARQL `SELECT`'s solutions; answers `SparqlRow[]`. */\nexport const sparql = (sparql: string): Sparql => Sparql.make({ sparql });\n\n/** The known predicates; answers `PredicateEntry[]`. */\nexport const predicates = (): Predicates => Predicates.make({});\n\n/** A source's read cursor; answers `string | undefined`. */\nexport const cursor = (source: Fact.SourceUri):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AAQ,OAAO,YAAY,OAAO,MAAM;AAC1C;;AAGA,IAAa,gBAA+B,QAA8C,QAAQ;;AAGlG,IAAa,YAA2B,UACtC,aAAwB,MAAM,IAAI;;AAMpC,IAAa,SAAS,UAAqB,CAAC,MAAa,MAAM,KAAK,EAAE,QAAQ,CAAC;;AAG/E,IAAa,UAAU,WAA2B,OAAO,KAAK,EAAE,OAAO,CAAC;;AAGxE,IAAa,UAAU,WAA2B,OAAO,KAAK,EAAE,OAAO,CAAC;;AAGxE,IAAa,mBAA+B,WAAW,KAAK,CAAC,CAAC;;AAG9D,IAAa,UAAU,WAAmC,OAAO,KAAK,EAAE,OAAO,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as __exportAll } from "./chunk-rolldown-runtime.mjs";
|
|
2
|
+
import { i as EntityKey, v as SourceUri } from "./chunk-Fact.mjs";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
//#region src/MemoryService.ts
|
|
6
|
+
var MemoryService_exports = /* @__PURE__ */ __exportAll({
|
|
7
|
+
MemoryService: () => MemoryService,
|
|
8
|
+
PutOptions: () => PutOptions,
|
|
9
|
+
ReadCursor: () => ReadCursor,
|
|
10
|
+
key: () => key
|
|
11
|
+
});
|
|
12
|
+
/** How far a source has been read into facts. */
|
|
13
|
+
var ReadCursor = Schema.Struct({
|
|
14
|
+
/** The source read (a chat, a feed, a mailbox). */
|
|
15
|
+
source: SourceUri,
|
|
16
|
+
/** URI or hash of the last item read; the next read starts after it. */
|
|
17
|
+
through: Schema.String
|
|
18
|
+
});
|
|
19
|
+
var PutOptions = Schema.Struct({
|
|
20
|
+
/** Speakers whose facts are stored but wake nothing on their own. */
|
|
21
|
+
quiet: Schema.optional(Schema.Array(EntityKey)),
|
|
22
|
+
/** Moved in the same write as the facts. */
|
|
23
|
+
read: Schema.optional(ReadCursor)
|
|
24
|
+
});
|
|
25
|
+
var MemoryService = class extends Context.Service()("@dxos/echo-memory/MemoryService") {};
|
|
26
|
+
/** Re-exported so callers importing this module as a namespace avoid `MemoryService.MemoryService.key`. */
|
|
27
|
+
var key = MemoryService.key;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { key as a, ReadCursor as i, MemoryService_exports as n, PutOptions as r, MemoryService as t };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=chunk-MemoryService.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunk-MemoryService.mjs","names":["Fact.SourceUri","Fact.EntityKey"],"sources":["../../src/MemoryService.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\nimport * as Context from 'effect/Context';\nimport type * as Effect from 'effect/Effect';\nimport * as Schema from 'effect/Schema';\n\nimport * as Fact from './Fact.ts';\nimport type * as MemoryError from './MemoryError.ts';\nimport type * as MemoryQuery from './MemoryQuery.ts';\nimport type * as Subscription from './Subscription.ts';\n\n/** How far a source has been read into facts. */\nexport const ReadCursor = Schema.Struct({\n /** The source read (a chat, a feed, a mailbox). */\n source: Fact.SourceUri,\n /** URI or hash of the last item read; the next read starts after it. */\n through: Schema.String,\n});\nexport interface ReadCursor extends Schema.Schema.Type<typeof ReadCursor> {}\n\nexport const PutOptions = Schema.Struct({\n /** Speakers whose facts are stored but wake nothing on their own. */\n quiet: Schema.optional(Schema.Array(Fact.EntityKey)),\n /** Moved in the same write as the facts. */\n read: Schema.optional(ReadCursor),\n});\nexport interface PutOptions extends Schema.Schema.Type<typeof PutOptions> {}\n\n/**\n * The memory of one space, in two halves over one store.\n *\n * - Knowledge base: {@link Service.put} stores facts and {@link Service.query} reads them back.\n * - Event base: a subscription carries goal rules; whenever put facts or the clock wake them, an event is queued\n * in that subscription's own outbox, which its consumer drains with {@link Service.take} and {@link Service.ack}.\n *\n * Time-driven rules are evaluated by the implementation on its own; the interface has no op for the clock.\n */\nexport interface Service {\n /**\n * Stores facts (a repeated put is idempotent), moves `options.read` in the same write, and returns how many\n * events the write queued. A put with no facts only moves the cursor.\n */\n readonly put: (facts: readonly Fact.Fact[], options?: PutOptions) => Effect.Effect<number, MemoryError.MemoryError>;\n\n /** The only read of the knowledge base; the query's kind fixes what it answers. */\n readonly query: <Q extends MemoryQuery.Any>(\n query: Q,\n ) => Effect.Effect<MemoryQuery.ResultOf<Q>, MemoryError.MemoryError>;\n\n /**\n * Forgets the facts, read cursors and queued events, and restores the seed vocabulary; subscriptions stay, with\n * their rule state started over.\n */\n readonly reset: () => Effect.Effect<void, MemoryError.MemoryError>;\n\n /**\n * Adds a subscription, or replaces the one with its id. False, adding nothing, when the space holds\n * `MAX_SUBSCRIPTIONS` others; fails when its rules do not compile.\n */\n readonly subscribe: (subscription: Subscription.Subscription) => Effect.Effect<boolean, MemoryError.MemoryError>;\n\n /** Subscriptions oldest first: all, or those the owner holds. */\n readonly subscriptions: (\n owner?: Fact.EntityKey,\n ) => Effect.Effect<Subscription.Subscription[], MemoryError.MemoryError>;\n\n /** Removes a subscription and its outbox; false when it was already gone. */\n readonly unsubscribe: (id: Subscription.SubscriptionId) => Effect.Effect<boolean, MemoryError.MemoryError>;\n\n /** The subscription's unacknowledged events, oldest first; empty for an unknown subscription. */\n readonly take: (\n id: Subscription.SubscriptionId,\n ) => Effect.Effect<Subscription.MemoryEvent[], MemoryError.MemoryError>;\n\n /** Removes the events from the outbox; unknown ids are ignored. */\n readonly ack: (\n id: Subscription.SubscriptionId,\n events: readonly Subscription.MemoryEventId[],\n ) => Effect.Effect<void, MemoryError.MemoryError>;\n}\n\nexport class MemoryService extends Context.Service<MemoryService, Service>()('@dxos/echo-memory/MemoryService') {}\n\n/** Re-exported so callers importing this module as a namespace avoid `MemoryService.MemoryService.key`. */\nexport const key = MemoryService.key;\n"],"mappings":";;;;;;;;;;;;AAgBA,IAAa,aAAa,OAAO,OAAO;;CAEtC,QAAQA;;CAER,SAAS,OAAO;AAClB,CAAC;AAGD,IAAa,aAAa,OAAO,OAAO;;CAEtC,OAAO,OAAO,SAAS,OAAO,MAAMC,SAAc,CAAC;;CAEnD,MAAM,OAAO,SAAS,UAAU;AAClC,CAAC;AAwDD,IAAa,gBAAb,cAAmC,QAAQ,QAAgC,CAAC,CAAC,iCAAiC,CAAC,CAAC,CAAC;;AAGjH,IAAa,MAAM,cAAc"}
|