@oxilite/common 0.2.2 → 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/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 {
@@ -194,6 +204,42 @@ export interface CypherResult {
194
204
  records: Record<string, CypherValue>[];
195
205
  stats: CypherStats;
196
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;
197
243
  /** Options of the Cypher frontend (see `oxilite_cypher::json`). */
198
244
  export interface CypherOptions {
199
245
  /** Namespace of labels, relationship types and keys without a prefix (default `urn:oxilite:pg:`). */
@@ -210,6 +256,11 @@ export interface CypherOptions {
210
256
  shortestPathCap?: number;
211
257
  /** Check writes against the SHACL shapes of the dataset (default true). */
212
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;
213
264
  /** Give created nodes an `rdf:type rdfs:Resource` triple (default true). */
214
265
  nodeMarker?: boolean;
215
266
  /** Entailment for matching: `"rdfs"` or `"owl-ql"` make labels follow class hierarchies. */
@@ -321,4 +372,119 @@ export declare function storedDocument(j: Record<string, unknown> | null): Store
321
372
  export declare function filterJson(f: DocumentFilter): Record<string, unknown>;
322
373
  /** A document argument: JSON text is stored verbatim, objects are serialized. */
323
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[];
324
490
  export {};
package/dist/index.js CHANGED
@@ -209,6 +209,15 @@ 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
+ }
212
221
  export function cypherResult(out) {
213
222
  return {
214
223
  columns: out.columns,
@@ -269,3 +278,45 @@ export function filterJson(f) {
269
278
  export function documentText(doc) {
270
279
  return typeof doc === "string" ? doc : JSON.stringify(doc);
271
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.2.2",
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",