@oxilite/common 0.1.0 → 0.5.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/README.md CHANGED
@@ -1,5 +1,52 @@
1
+ <p align="center">
2
+ <a href="https://oxilitedb.com"><img src="https://raw.githubusercontent.com/Volland/oxilite/main/site/assets/logo.png" alt="oxilite" width="120"></a>
3
+ </p>
4
+
1
5
  # @oxilite/common
2
6
 
3
- RDF/JS terms (`DataFactory`, `NamedNode`, `Literal`, `Quad`…), JSON conversions and result types shared by [`@oxilite/node`](https://www.npmjs.com/package/@oxilite/node) and [`@oxilite/d1`](https://www.npmjs.com/package/@oxilite/d1). You normally get it through one of those packages.
7
+ [![npm](https://img.shields.io/npm/v/@oxilite/common.svg)](https://www.npmjs.com/package/@oxilite/common) [![license](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](https://github.com/Volland/oxilite#license)
8
+
9
+ **RDF/JS terms and the shared TypeScript types of oxilite**, used by [`@oxilite/node`](https://www.npmjs.com/package/@oxilite/node) and [`@oxilite/d1`](https://www.npmjs.com/package/@oxilite/d1).
10
+
11
+ **[Website](https://oxilitedb.com)** · [npm](https://www.npmjs.com/package/@oxilite/common) · **[Guide and architecture](https://github.com/Volland/oxilite#readme)** · [Changelog and issues](https://github.com/Volland/oxilite/issues)
12
+
13
+ You rarely install it directly: both packages re-export everything here.
14
+
15
+ ```ts
16
+ import { namedNode, literal, quad, DataFactory, type Term } from "@oxilite/node"; // or "@oxilite/d1"
17
+
18
+ const q = quad(namedNode("http://example.com/ada"), namedNode("http://example.com/name"), literal("Ada", "en"));
19
+ ```
20
+
21
+ ## What is inside
22
+
23
+ - **RDF/JS terms:** `NamedNode`, `BlankNode`, `Literal` (with language and direction), `DefaultGraph`, `Variable` and `Quad` (also usable as an RDF 1.2 triple term), plus `DataFactory` and its shortcuts `namedNode`, `blankNode`, `literal`, `defaultGraph`, `variable`, `quad`, `triple`. They follow the [RDF/JS data model](https://rdf.js.org/data-model-spec/), so they mix with other RDF/JS libraries.
24
+ - **SPARQL types:** `QueryOptions` (with oxilite's `reasoning` and `include_inferred`), `LoadOptions`, `DumpOptions`, `QueryResult`.
25
+ - **Cypher types:** `CypherValue`, `CypherNode`, `CypherRelationship`, `CypherPath`, `CypherTemporal`, `CypherResult`, `CypherStats` and `CypherOptions` (`base`, `prefixes`, `names`, `multiValue`, `reasoning`, `shapes`…).
26
+ - **JSON-LD and credential types:** `JsonLdOptions`, `CredentialOptions`, `KeyStrategy`, `GraphStrategy`, `StoredDocument`, `DocumentFilter`, `Drift`, `PresentationKeys` and the `JsonLdError` class (with its JSON-LD error `code`).
27
+ - **JSON helpers:** `toJson` / `fromJson` convert terms to and from the JSON form the oxilite core exchanges.
28
+
29
+ ## The oxilite family
30
+
31
+ oxilite is an Oxigraph-compatible RDF database and SPARQL 1.1 engine that stores its data in SQLite, so it runs anywhere SQLite runs: in-process, on a system or vendor `libsqlite3`, on Cloudflare D1 and in Durable Objects. The same data can be queried with SPARQL and openCypher, reasoned over with RDFS / OWL, and validated with SHACL and ShEx. Read the overview on **[oxilitedb.com](https://oxilitedb.com)** and the full guide in the [main README](https://github.com/Volland/oxilite#readme).
32
+
33
+ | Package | What it is for |
34
+ |---|---|
35
+ | [`oxilite`](https://crates.io/crates/oxilite) | The store: a drop-in for `oxigraph::store::Store`, plus `AsyncStore` for D1 |
36
+ | [`oxilite-core`](https://crates.io/crates/oxilite-core) | The sans-IO core: term encoding, schema, SPARQL → SQL compiler and planner |
37
+ | [`oxilite-rusqlite`](https://crates.io/crates/oxilite-rusqlite) | In-process backend with a bundled SQLite (the default) |
38
+ | [`oxilite-dylib`](https://crates.io/crates/oxilite-dylib) | Backend that loads your own `libsqlite3` at runtime |
39
+ | [`oxilite-d1`](https://crates.io/crates/oxilite-d1) | Cloudflare D1 backend for Rust Workers |
40
+ | [`oxilite-cypher`](https://crates.io/crates/oxilite-cypher) | openCypher over the same data, OWL- and SHACL-aware |
41
+ | [`oxilite-jsonld`](https://crates.io/crates/oxilite-jsonld) | JSON-LD documents stored verbatim, one named graph each |
42
+ | [`oxilite-vc`](https://crates.io/crates/oxilite-vc) | Verifiable Credentials: stored under their id, indexed, queryable |
43
+ | [`oxilite-reason`](https://crates.io/crates/oxilite-reason) | OWL 2 RL materialization with `reasonable` |
44
+ | [`oxilite-validate`](https://crates.io/crates/oxilite-validate) | SHACL and ShEx validation with rudof |
45
+ | [`oxilite-cli`](https://crates.io/crates/oxilite-cli) | The `oxilite` command and a SPARQL endpoint like `oxigraph serve` |
46
+ | [`@oxilite/node`](https://www.npmjs.com/package/@oxilite/node) | Node.js bindings, API of Oxigraph's JS package |
47
+ | [`@oxilite/d1`](https://www.npmjs.com/package/@oxilite/d1) | Cloudflare D1 and Durable Objects from TypeScript (WebAssembly core) |
48
+ | [`@oxilite/common`](https://www.npmjs.com/package/@oxilite/common) | RDF/JS terms and shared TypeScript types |
49
+
50
+ ## License
4
51
 
5
- See the [oxilite repository](https://github.com/Volland/oxilite) for documentation.
52
+ Dual-licensed under [MIT](https://github.com/Volland/oxilite/blob/main/LICENSE-MIT) or [Apache-2.0](https://github.com/Volland/oxilite/blob/main/LICENSE-APACHE), at your option, like Oxigraph.
package/dist/index.d.ts CHANGED
@@ -130,6 +130,16 @@ export interface QueryOptions {
130
130
  reasoning?: "none" | "rdfs" | "owl-ql";
131
131
  /** Also match inferences stored by `materialize()` (oxilite extension). */
132
132
  include_inferred?: boolean;
133
+ /**
134
+ * Match the triples of registered schema graphs (oxilite extension, default true); `false`
135
+ * queries the data without the ontologies and shapes that describe it.
136
+ */
137
+ include_schema_graphs?: boolean;
138
+ /**
139
+ * Read the store as it was at this version (oxilite extension, versioning `log`):
140
+ * `"HEAD~2"`, `"#42"` (a tick) or `"@2026-09-01T12:00:00Z"`.
141
+ */
142
+ as_of?: string;
133
143
  }
134
144
  /** Load options (Oxigraph's JS option names). */
135
145
  export interface LoadOptions {
@@ -147,4 +157,334 @@ export interface DumpOptions {
147
157
  /** Content of `load()`: a string, bytes, or a list of them (like Oxigraph's JS API). */
148
158
  export type LoadData = string | Uint8Array | (string | Uint8Array)[];
149
159
  export declare function loadDataToString(data: LoadData): string;
160
+ /** A node of the property-graph view of the dataset. */
161
+ export interface CypherNode {
162
+ type: "node";
163
+ /** The node's IRI (or `_:label` for a blank node). */
164
+ id: string;
165
+ labels: string[];
166
+ properties: Record<string, CypherValue>;
167
+ }
168
+ /** A relationship: an RDF triple, identified by its reifier when it has one. */
169
+ export interface CypherRelationship {
170
+ type: "relationship";
171
+ id: string;
172
+ relType: string;
173
+ start: string;
174
+ end: string;
175
+ properties: Record<string, CypherValue>;
176
+ }
177
+ export interface CypherPath {
178
+ type: "path";
179
+ nodes: CypherNode[];
180
+ relationships: CypherRelationship[];
181
+ }
182
+ /** A temporal value in its ISO 8601 form (`value`). */
183
+ export interface CypherTemporal {
184
+ type: "date" | "datetime" | "localdatetime" | "time" | "localtime" | "duration";
185
+ value: string;
186
+ }
187
+ export type CypherValue = null | boolean | number | string | CypherValue[] | CypherNode | CypherRelationship | CypherPath | CypherTemporal | {
188
+ [key: string]: CypherValue;
189
+ };
190
+ /** What a statement changed. */
191
+ export interface CypherStats {
192
+ nodesCreated: number;
193
+ nodesDeleted: number;
194
+ relationshipsCreated: number;
195
+ relationshipsDeleted: number;
196
+ propertiesSet: number;
197
+ labelsAdded: number;
198
+ labelsRemoved: number;
199
+ }
200
+ export interface CypherResult {
201
+ columns: string[];
202
+ rows: CypherValue[][];
203
+ /** Rows as objects keyed by column. */
204
+ records: Record<string, CypherValue>[];
205
+ stats: CypherStats;
206
+ }
207
+ /** Options of the Datalog frontend (see `oxilite_datalog::json`). */
208
+ export interface DatalogOptions {
209
+ /** Match every graph rather than only the default graph. */
210
+ useDefaultGraphAsUnion?: boolean;
211
+ /** Also match materialized inferences. */
212
+ includeInferred?: boolean;
213
+ /** Rounds a component evaluated by iteration may take (default 100). */
214
+ maxIterations?: number;
215
+ /** Run the program on this version of the store (like an `@version` directive). */
216
+ asOf?: string;
217
+ }
218
+ /** What the native side returns for a Datalog program. */
219
+ export interface DatalogOutput {
220
+ kind: "datalog";
221
+ columns: string[];
222
+ rows: (TermJson | null)[][];
223
+ /** Rounds each iterated component took; empty when nothing had to be iterated. */
224
+ rounds: number[];
225
+ }
226
+ /** The solutions of a Datalog program, as RDF/JS terms. */
227
+ export interface DatalogResult {
228
+ columns: string[];
229
+ rows: (Term | null)[][];
230
+ /** Rows as objects keyed by the goal's variables. */
231
+ records: Record<string, Term | null>[];
232
+ rounds: number[];
233
+ }
234
+ /** What a materialization did. */
235
+ export interface DatalogMaterializeResult {
236
+ kind: "datalogMaterialize";
237
+ /** Triples in the inference table afterwards. */
238
+ inferred: number;
239
+ /** Relations whose conclusions were stored. */
240
+ relations: number;
241
+ }
242
+ export declare function datalogResult(out: DatalogOutput): DatalogResult;
243
+ /** Options of the Cypher frontend (see `oxilite_cypher::json`). */
244
+ export interface CypherOptions {
245
+ /** Namespace of labels, relationship types and keys without a prefix (default `urn:oxilite:pg:`). */
246
+ base?: string;
247
+ /** Prefixes usable in names: `` :`schema:Person` ``. */
248
+ prefixes?: Record<string, string>;
249
+ /** Explicit name → IRI mappings. */
250
+ names?: Record<string, string>;
251
+ /** How a property with several RDF values reads: a list (default), its first value, or an error. */
252
+ multiValue?: "list" | "first" | "error";
253
+ /** Maximum hops of an unbounded variable-length relationship that binds a variable. */
254
+ varLengthCap?: number;
255
+ /** Maximum depth of an unbounded shortest-path search. */
256
+ shortestPathCap?: number;
257
+ /** Check writes against the SHACL shapes of the dataset (default true). */
258
+ shapes?: boolean;
259
+ /**
260
+ * Match the store as it was at this version (versioning `log`): `"HEAD~1"`, `"#42"` or
261
+ * `"@2026-09-01T12:00:00Z"`. Writing statements are refused with a version.
262
+ */
263
+ asOf?: string;
264
+ /** Give created nodes an `rdf:type rdfs:Resource` triple (default true). */
265
+ nodeMarker?: boolean;
266
+ /** Entailment for matching: `"rdfs"` or `"owl-ql"` make labels follow class hierarchies. */
267
+ reasoning?: "none" | "rdfs" | "owl-ql";
268
+ useDefaultGraphAsUnion?: boolean;
269
+ }
270
+ /** Output of a Cypher job (`kind: "cypher"`). */
271
+ export interface CypherOutput {
272
+ kind: "cypher";
273
+ columns: string[];
274
+ rows: CypherValue[][];
275
+ stats: CypherStats;
276
+ }
277
+ export declare function cypherResult(out: CypherOutput): CypherResult;
278
+ /** Where a document's key comes from. */
279
+ export type KeyStrategy = "id" | "contentHash" | "explicit" | {
280
+ pointer: string;
281
+ };
282
+ /** Which graph a document's triples go to: the key itself (default), an IRI template with `{key}`, one fixed graph, or the default graph. */
283
+ export type GraphStrategy = "key" | "default" | {
284
+ template: string;
285
+ } | {
286
+ fixed: string;
287
+ };
288
+ /** Options of a JSON-LD document handle. */
289
+ export interface JsonLdOptions {
290
+ /** Default `"id"`: the top-level `@id` / `id`. */
291
+ key?: KeyStrategy;
292
+ /** When the key strategy finds nothing: fail (default for documents) or use `urn:oxilite:doc:sha256:<hex>` (default for credentials). */
293
+ onMissingKey?: "reject" | "contentHash";
294
+ /** Default `"key"`: one named graph per document, named after its key. */
295
+ graph?: GraphStrategy;
296
+ /** Base IRI for relative IRIs in documents. */
297
+ baseIri?: string;
298
+ rdfDirection?: "i18n-datatype" | "compound-literal";
299
+ processingMode?: "json-ld-1.0" | "json-ld-1.1";
300
+ /** Contexts available in memory: IRI → context document. */
301
+ contexts?: Record<string, object | string>;
302
+ /** Fetch unknown remote contexts over HTTP (Node only; default false: no network access). */
303
+ network?: boolean;
304
+ /** Persist fetched contexts in the store, so later loads work offline. */
305
+ cacheFetched?: boolean;
306
+ /** Metadata indexes created with the tables (all default true). */
307
+ indexes?: {
308
+ issuer?: boolean;
309
+ subject?: boolean;
310
+ validUntil?: boolean;
311
+ };
312
+ }
313
+ /** Options of a credentials handle. */
314
+ export interface CredentialOptions extends JsonLdOptions {
315
+ /** Also store each credential embedded in a presentation on its own (default true). */
316
+ embedCredentials?: boolean;
317
+ }
318
+ /** A stored document (or credential). */
319
+ export interface StoredDocument {
320
+ key: string;
321
+ /** The graph its default-graph triples were written to. */
322
+ graph: Term;
323
+ /** The JSON exactly as it was stored. */
324
+ json: string;
325
+ /** Hex SHA-256 of `json`. */
326
+ sha256: string;
327
+ /** `jsonld`, or `vc1` / `vc2` / `vp1` / `vp2` for credentials and presentations. */
328
+ profile: string;
329
+ issuer: string | null;
330
+ subject: string | null;
331
+ types: string[];
332
+ validFrom: Date | null;
333
+ validUntil: Date | null;
334
+ /** Keys of the credentials a presentation embeds. */
335
+ refs: string[];
336
+ storedAt: Date;
337
+ }
338
+ /** Metadata filter of `find`. */
339
+ export interface DocumentFilter {
340
+ issuer?: string;
341
+ subject?: string;
342
+ /** One value of the `type` array. */
343
+ type?: string;
344
+ /** Valid at this instant (validFrom ≤ t < validUntil; open ends allowed). */
345
+ validAt?: Date | number;
346
+ profile?: string;
347
+ /** Keyset paging: keys after this one. */
348
+ after?: string;
349
+ limit?: number;
350
+ }
351
+ /** A document whose graphs differ from a fresh conversion of its JSON. */
352
+ export interface Drift {
353
+ key: string;
354
+ missing: number;
355
+ extra: number;
356
+ }
357
+ /** Keys written by `putPresentation`. */
358
+ export interface PresentationKeys {
359
+ key: string;
360
+ credentials: string[];
361
+ }
362
+ /** A JSON-LD or credential error; `code` is the JSON-LD error code (e.g. `invalid local context`) or `missing-key`, `invalid-graph-name`, `graph-owned`, `document-too-large`, `invalid`, `json`, `store`. */
363
+ export declare class JsonLdError extends Error {
364
+ readonly code: string;
365
+ constructor(code: string, message: string);
366
+ }
367
+ /** Rethrows an error of the core's JSON-LD operations as a `JsonLdError`. */
368
+ export declare function jsonLdError(e: unknown): unknown;
369
+ /** A stored document from the core's JSON (epoch seconds become `Date`s). */
370
+ export declare function storedDocument(j: Record<string, unknown> | null): StoredDocument | null;
371
+ /** A filter in the core's JSON form. */
372
+ export declare function filterJson(f: DocumentFilter): Record<string, unknown>;
373
+ /** A document argument: JSON text is stored verbatim, objects are serialized. */
374
+ export declare function documentText(doc: string | object): string;
375
+ /** How much history a store keeps. */
376
+ export type Versioning = "off" | "stamped" | "log";
377
+ /** The versioning level of a store and where its clock and history stand. */
378
+ export interface VersionStatus {
379
+ level: Versioning;
380
+ history: "none" | "live" | "frozen";
381
+ stampColumn: boolean;
382
+ stampIndex: boolean;
383
+ asOfIndex: boolean;
384
+ /** The latest tick. */
385
+ head: number | null;
386
+ /** Wall time of the latest tick, in seconds since the epoch. */
387
+ headTime: number | null;
388
+ /** Where the recorded history (re)starts. */
389
+ genesis: number | null;
390
+ /** The latest freeze, while the history is frozen. */
391
+ frozenAt: number | null;
392
+ commits: number | null;
393
+ }
394
+ /** One entry of the history: a commit or a level change. */
395
+ export interface CommitRecord {
396
+ tick: number;
397
+ /** Seconds since the epoch. */
398
+ time: number;
399
+ kind: "write" | "genesis" | "freeze" | "resume" | "dropped" | "level" | "purge";
400
+ author: string | null;
401
+ message: string | null;
402
+ added: number | null;
403
+ removed: number | null;
404
+ }
405
+ /** A quad added or removed at a tick. */
406
+ export interface Change {
407
+ tick: number;
408
+ added: boolean;
409
+ quad: Quad;
410
+ }
411
+ /** Options of a level change. */
412
+ export interface LevelChange {
413
+ asOfIndex?: boolean;
414
+ stampIndex?: boolean;
415
+ /** Allow a downgrade to delete the history, the ticks and the stamp column. */
416
+ allowLoss?: boolean;
417
+ author?: string;
418
+ message?: string;
419
+ }
420
+ /** Author and message recorded on the commits of later writes. */
421
+ export interface CommitInfo {
422
+ author?: string;
423
+ message?: string;
424
+ }
425
+ /** Changes from their JSON form (`{tick, added, quad}`). */
426
+ export declare function toChanges(v: unknown): Change[];
427
+ /** The system graph holding the schema registry. */
428
+ export declare const SCHEMA_GRAPH = "oxilite:schema";
429
+ /** The oxilite vocabulary namespace (`oxl:`). */
430
+ export declare const OXL = "https://oxilite.dev/ns#";
431
+ /** Names the default graph in the registry (as a schema graph or an `appliesTo` target). */
432
+ export declare const DEFAULT_GRAPH_IRI = "https://oxilite.dev/ns#DefaultGraph";
433
+ /** What a registered graph holds. */
434
+ export type SchemaRole = "ontology" | "shacl" | "shex";
435
+ /** What is recorded about a graph when it is registered (every field optional). */
436
+ export interface SchemaRegistration {
437
+ /** The `owl:Ontology` IRI, when it differs from the graph name. */
438
+ iri?: string;
439
+ /** `owl:versionIRI`, a version string, or anything else worth pinning. */
440
+ version?: string;
441
+ /** Digest of the document the graph was loaded from, for drift detection. */
442
+ sha256?: string;
443
+ /** `owl:imports` targets, recorded but not resolved. */
444
+ imports?: string[];
445
+ /**
446
+ * The graphs the schema applies to (`oxl:appliesTo`): IRIs, or `DEFAULT_GRAPH_IRI`. Absent or
447
+ * empty: every graph.
448
+ */
449
+ appliesTo?: GraphArg[];
450
+ /** An inactive graph stays registered (and hidden) but stops contributing (default true). */
451
+ active?: boolean;
452
+ }
453
+ /** One entry of the schema registry. */
454
+ export interface SchemaGraphEntry {
455
+ graph: Term;
456
+ role: SchemaRole;
457
+ iri: string | null;
458
+ version: string | null;
459
+ sha256: string | null;
460
+ imports: string[];
461
+ /** The graphs the schema applies to (IRIs, `DEFAULT_GRAPH_IRI`); empty: every graph. */
462
+ appliesTo: string[];
463
+ active: boolean;
464
+ /** When the graph was registered (`xsd:dateTime`). */
465
+ loadedAt: string | null;
466
+ }
467
+ /** One compiled SHACL property shape: every constraint declared on a target class and path. */
468
+ export interface PropertyShapeEntry {
469
+ target: string;
470
+ path: string;
471
+ datatype: string | null;
472
+ minCount: number | null;
473
+ maxCount: number | null;
474
+ pattern: string | null;
475
+ /** The `sh:in` values. */
476
+ in: Term[];
477
+ /** Relationship-valued (`sh:class` / `sh:node`). */
478
+ relationship: boolean;
479
+ }
480
+ /** A graph argument: an RDF/JS term, or an IRI string. */
481
+ export type GraphArg = TermLike | string;
482
+ /** The JSON text of a graph argument. */
483
+ export declare function graphJson(g: GraphArg): string;
484
+ /** A registration's JSON text. */
485
+ export declare function registrationJson(r?: SchemaRegistration): string;
486
+ /** Registry entries from their JSON form. */
487
+ export declare function toSchemaGraphs(v: unknown): SchemaGraphEntry[];
488
+ /** Shape index entries from their JSON form. */
489
+ export declare function toShapeIndex(v: unknown): PropertyShapeEntry[];
150
490
  export {};
package/dist/index.js CHANGED
@@ -209,3 +209,114 @@ export function loadDataToString(data) {
209
209
  const one = (d) => (typeof d === "string" ? d : new TextDecoder().decode(d));
210
210
  return Array.isArray(data) ? data.map(one).join("\n") : one(data);
211
211
  }
212
+ export function datalogResult(out) {
213
+ const rows = out.rows.map((row) => row.map((c) => (c === null ? null : fromJson(c))));
214
+ return {
215
+ columns: out.columns,
216
+ rows,
217
+ records: rows.map((row) => Object.fromEntries(out.columns.map((c, i) => [c, row[i] ?? null]))),
218
+ rounds: out.rounds,
219
+ };
220
+ }
221
+ export function cypherResult(out) {
222
+ return {
223
+ columns: out.columns,
224
+ rows: out.rows,
225
+ records: out.rows.map((row) => Object.fromEntries(out.columns.map((c, i) => [c, row[i] ?? null]))),
226
+ stats: out.stats,
227
+ };
228
+ }
229
+ /** A JSON-LD or credential error; `code` is the JSON-LD error code (e.g. `invalid local context`) or `missing-key`, `invalid-graph-name`, `graph-owned`, `document-too-large`, `invalid`, `json`, `store`. */
230
+ export class JsonLdError extends Error {
231
+ code;
232
+ constructor(code, message) {
233
+ super(message);
234
+ this.name = "JsonLdError";
235
+ this.code = code;
236
+ }
237
+ }
238
+ /** Rethrows an error of the core's JSON-LD operations as a `JsonLdError`. */
239
+ export function jsonLdError(e) {
240
+ const message = e instanceof Error ? e.message : String(e);
241
+ const at = message.indexOf("oxilite-jsonld:");
242
+ if (at < 0)
243
+ return e;
244
+ try {
245
+ const { code, message: m } = JSON.parse(message.slice(at + "oxilite-jsonld:".length));
246
+ return new JsonLdError(code, m);
247
+ }
248
+ catch {
249
+ return e;
250
+ }
251
+ }
252
+ /** A stored document from the core's JSON (epoch seconds become `Date`s). */
253
+ export function storedDocument(j) {
254
+ if (!j)
255
+ return null;
256
+ const date = (v) => (typeof v === "number" ? new Date(v * 1000) : null);
257
+ return {
258
+ key: j.key,
259
+ graph: fromJson(j.graph),
260
+ json: j.json,
261
+ sha256: j.sha256,
262
+ profile: j.profile,
263
+ issuer: j.issuer ?? null,
264
+ subject: j.subject ?? null,
265
+ types: j.types ?? [],
266
+ validFrom: date(j.validFrom),
267
+ validUntil: date(j.validUntil),
268
+ refs: j.refs ?? [],
269
+ storedAt: date(j.storedAt),
270
+ };
271
+ }
272
+ /** A filter in the core's JSON form. */
273
+ export function filterJson(f) {
274
+ const t = f.validAt;
275
+ return { ...f, validAt: t === undefined ? undefined : (t instanceof Date ? t.getTime() : t) / 1000 };
276
+ }
277
+ /** A document argument: JSON text is stored verbatim, objects are serialized. */
278
+ export function documentText(doc) {
279
+ return typeof doc === "string" ? doc : JSON.stringify(doc);
280
+ }
281
+ /** Changes from their JSON form (`{tick, added, quad}`). */
282
+ export function toChanges(v) {
283
+ return v.map((c) => ({
284
+ tick: c.tick,
285
+ added: c.added,
286
+ quad: fromJson(c.quad),
287
+ }));
288
+ }
289
+ // ------------------------------------------------------------------------- schema registry
290
+ //
291
+ // The registry is RDF in the system graph <oxilite:schema> (vocabulary: https://oxilite.dev/ns#):
292
+ // each registered graph is typed oxl:OntologyGraph, oxl:ShapesGraph or oxl:ShExGraph and names
293
+ // the graphs it applies to with oxl:appliesTo. The same triples work on any SPARQL store.
294
+ /** The system graph holding the schema registry. */
295
+ export const SCHEMA_GRAPH = "oxilite:schema";
296
+ /** The oxilite vocabulary namespace (`oxl:`). */
297
+ export const OXL = "https://oxilite.dev/ns#";
298
+ /** Names the default graph in the registry (as a schema graph or an `appliesTo` target). */
299
+ export const DEFAULT_GRAPH_IRI = "https://oxilite.dev/ns#DefaultGraph";
300
+ /** The JSON text of a graph argument. */
301
+ export function graphJson(g) {
302
+ return JSON.stringify(typeof g === "string" ? { termType: "NamedNode", value: g } : toJson(g));
303
+ }
304
+ /** A registration's JSON text. */
305
+ export function registrationJson(r = {}) {
306
+ const iri = (g) => (typeof g === "string" ? g : g.termType === "DefaultGraph" ? DEFAULT_GRAPH_IRI : g.value);
307
+ return JSON.stringify({ ...r, appliesTo: r.appliesTo?.map(iri) });
308
+ }
309
+ /** Registry entries from their JSON form. */
310
+ export function toSchemaGraphs(v) {
311
+ return v.map((e) => ({
312
+ ...e,
313
+ graph: fromJson(e.graph),
314
+ }));
315
+ }
316
+ /** Shape index entries from their JSON form. */
317
+ export function toShapeIndex(v) {
318
+ return v.map((e) => ({
319
+ ...e,
320
+ in: e.in.map(fromJson),
321
+ }));
322
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxilite/common",
3
- "version": "0.1.0",
3
+ "version": "0.5.0",
4
4
  "description": "RDF/JS terms and result conversion shared by the oxilite JavaScript packages",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
@@ -17,15 +17,15 @@
17
17
  "url": "git+https://github.com/Volland/oxilite.git",
18
18
  "directory": "packages/common"
19
19
  },
20
- "homepage": "https://github.com/Volland/oxilite#readme",
20
+ "homepage": "https://oxilitedb.com",
21
21
  "bugs": "https://github.com/Volland/oxilite/issues",
22
22
  "author": "Volodymyr Pavlyshyn",
23
23
  "keywords": [
24
24
  "rdf",
25
+ "rdfjs",
25
26
  "sparql",
26
- "sqlite",
27
- "oxigraph",
28
- "rdfjs"
27
+ "cypher",
28
+ "oxilite"
29
29
  ],
30
30
  "publishConfig": {
31
31
  "access": "public"