@littlebigbrain/client 0.1.0 → 0.3.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 +56 -0
- package/README.md +56 -15
- package/dist/client.d.ts +213 -460
- package/dist/client.js +391 -350
- package/dist/index.d.ts +1 -1
- package/dist/namespaces.d.ts +185 -0
- package/dist/namespaces.js +469 -0
- package/dist/schema.d.ts +10857 -3600
- package/dist/transport.d.ts +44 -0
- package/dist/transport.js +93 -0
- package/dist/types.d.ts +299 -0
- package/dist/types.js +47 -0
- package/package.json +35 -6
- package/dist/client.test.d.ts +0 -1
- package/dist/client.test.js +0 -591
- package/dist/contract-routes.test.d.ts +0 -1
- package/dist/contract-routes.test.js +0 -74
- package/src/client.test.ts +0 -673
- package/src/client.ts +0 -1428
- package/src/contract-routes.test.ts +0 -91
- package/src/index.ts +0 -16
- package/src/node-test-shim.d.ts +0 -16
- package/src/schema.ts +0 -13865
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { LbbClient, LbbError, parseSparqlResults } from "./client.js";
|
|
2
|
-
export type {
|
|
2
|
+
export type { LbbClientOptions, CallOptions, RequestOptions, EntityListOptions, HybridSearchOptions, LbbRequestEvent, LbbResponseEvent, LbbStackActivityResponse, LbbStackActivityWindow, FetchLike, Schemas, SparqlResults, SparqlResultsJson, SparqlTerm, AskRequest, AskResponse, CommitRequest, CommitResponse, Entity, EntitySelector, GraphMetadata, GraphSummary, SchemaView, SearchRequest, SearchResponse, SearchResult, Snapshot, } from "./client.js";
|
|
3
3
|
export type { components, paths, operations } from "./schema.js";
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { LbbClient } from "./client.js";
|
|
2
|
+
import type { CallOptions } from "./transport.js";
|
|
3
|
+
import { type EntityAttributeFilterOptions, type ImportLine, type ListResponse, type RdfExportOptions, type RdfImportOptions, type Schemas } from "./types.js";
|
|
4
|
+
export interface HybridSearchOptions extends CallOptions {
|
|
5
|
+
topK?: number;
|
|
6
|
+
source?: string;
|
|
7
|
+
consistency?: string;
|
|
8
|
+
lexical?: boolean;
|
|
9
|
+
bm25?: boolean;
|
|
10
|
+
vector?: boolean;
|
|
11
|
+
targets?: string[];
|
|
12
|
+
profile?: string;
|
|
13
|
+
/** Valid-time cursor (RFC 3339): results reflect facts true at this instant. */
|
|
14
|
+
asOf?: string;
|
|
15
|
+
/** Snapshot pin: results reproduce the graph as of this commit sequence. */
|
|
16
|
+
asOfCommitSeq?: number;
|
|
17
|
+
/** Opt-in impression logging for later relevance feedback. */
|
|
18
|
+
logImpression?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare class GraphNamespace {
|
|
21
|
+
private readonly client;
|
|
22
|
+
readonly facts: FactsNamespace;
|
|
23
|
+
readonly context: ContextNamespace;
|
|
24
|
+
readonly entities: EntityNamespace;
|
|
25
|
+
readonly indexes: IndexNamespace;
|
|
26
|
+
readonly ontology: OntologyNamespace;
|
|
27
|
+
readonly query: QueryNamespace;
|
|
28
|
+
readonly schema: SchemaNamespace;
|
|
29
|
+
readonly search: SearchNamespace;
|
|
30
|
+
constructor(client: LbbClient);
|
|
31
|
+
branch(name: string): GraphNamespace;
|
|
32
|
+
create(opts?: CallOptions): Promise<Schemas["CreateGraphResponse"]>;
|
|
33
|
+
delete(opts: {
|
|
34
|
+
confirm: string;
|
|
35
|
+
} & CallOptions): Promise<unknown>;
|
|
36
|
+
/** Retract edges/entities from the scoped graph. See {@link LbbClient.retract}. */
|
|
37
|
+
retract(body: Schemas["GraphRetractRequest"], opts?: CallOptions): Promise<Schemas["GraphRetractResponse"]>;
|
|
38
|
+
/** Export this graph's current snapshot as Turtle, N-Triples, TriG, or N-Quads. */
|
|
39
|
+
exportRdf(opts?: RdfExportOptions): Promise<string>;
|
|
40
|
+
}
|
|
41
|
+
export declare class FactsNamespace {
|
|
42
|
+
private readonly client;
|
|
43
|
+
constructor(client: LbbClient);
|
|
44
|
+
create(body: Schemas["TripletCommitFile"], opts?: CallOptions): Promise<Schemas["GraphCommitResponse"]>;
|
|
45
|
+
/** Bulk-load a dataset as NDJSON. See {@link LbbClient.import}. */
|
|
46
|
+
import(lines: ImportLine[] | string, opts?: CallOptions & {
|
|
47
|
+
batch?: number;
|
|
48
|
+
strict?: boolean;
|
|
49
|
+
observedAt?: string;
|
|
50
|
+
index?: boolean;
|
|
51
|
+
idempotencyKey?: string;
|
|
52
|
+
}): Promise<Schemas["GraphImportResponse"]>;
|
|
53
|
+
/**
|
|
54
|
+
* Bulk-load N-Triples, Turtle, N-Quads, or TriG through the native RDF import endpoint.
|
|
55
|
+
*
|
|
56
|
+
* Statements are committed through the fixed RDF_TRIPLE relation; source RDF
|
|
57
|
+
* predicates and literal term details are preserved as edge metadata.
|
|
58
|
+
*/
|
|
59
|
+
importRdf(rdf: string, opts?: CallOptions & RdfImportOptions): Promise<Schemas["GraphRdfImportResponse"]>;
|
|
60
|
+
}
|
|
61
|
+
export declare class SearchNamespace {
|
|
62
|
+
private readonly client;
|
|
63
|
+
constructor(client: LbbClient);
|
|
64
|
+
hybrid(query: string, opts?: HybridSearchOptions): Promise<Schemas["SemanticGraphSearchResponse"]>;
|
|
65
|
+
hybrid(body: Schemas["SemanticGraphSearchRequest"], opts?: CallOptions): Promise<Schemas["SemanticGraphSearchResponse"]>;
|
|
66
|
+
multi(body: Schemas["HybridMultiSearchRequest"], opts?: CallOptions): Promise<Schemas["HybridMultiSearchResponse"]>;
|
|
67
|
+
feedback(body: Schemas["SearchFeedbackRequest"], opts?: CallOptions): Promise<Schemas["SearchFeedbackResponse"]>;
|
|
68
|
+
feedbackExport(opts?: CallOptions): Promise<Schemas["SearchFeedbackExportResponse"]>;
|
|
69
|
+
fullText(body: Schemas["FullTextSearchRequest"], opts?: CallOptions): Promise<Schemas["FullTextSearchResponse"]>;
|
|
70
|
+
vector(body: Schemas["EmbeddingSearchRequest"], opts?: CallOptions): Promise<Schemas["EmbeddingSearchResponse"]>;
|
|
71
|
+
}
|
|
72
|
+
export declare class SchemaNamespace {
|
|
73
|
+
private readonly client;
|
|
74
|
+
constructor(client: LbbClient);
|
|
75
|
+
/** Active graph schema bundle: ontology plus activated SHACL shapes. */
|
|
76
|
+
view(opts?: {
|
|
77
|
+
audit?: boolean;
|
|
78
|
+
} & CallOptions): Promise<Schemas["SchemaBundleView"]>;
|
|
79
|
+
/** Preview a proposed RDF/SHACL schema bundle and audit current data. */
|
|
80
|
+
preview(body: Schemas["SchemaPreviewRequest"], opts?: CallOptions): Promise<Schemas["SchemaPreviewResponse"]>;
|
|
81
|
+
/** Activate a previewed SHACL schema bundle for this graph branch. */
|
|
82
|
+
publish(body: Schemas["SchemaPublishRequest"], opts?: CallOptions): Promise<Schemas["SchemaPublishResponse"]>;
|
|
83
|
+
/** Audit current data against the active SHACL schema bundle. */
|
|
84
|
+
audit(opts?: CallOptions): Promise<Schemas["SchemaAuditReport"]>;
|
|
85
|
+
}
|
|
86
|
+
export declare class IndexNamespace {
|
|
87
|
+
private readonly client;
|
|
88
|
+
constructor(client: LbbClient);
|
|
89
|
+
run(opts?: {
|
|
90
|
+
wait?: boolean;
|
|
91
|
+
background?: boolean;
|
|
92
|
+
body?: unknown;
|
|
93
|
+
} & CallOptions): Promise<unknown>;
|
|
94
|
+
build(opts?: {
|
|
95
|
+
background?: boolean;
|
|
96
|
+
} & CallOptions): Promise<unknown>;
|
|
97
|
+
delta(opts?: CallOptions): Promise<Schemas["IndexDeltaResponse"]>;
|
|
98
|
+
gc(opts?: {
|
|
99
|
+
keepRuns?: number;
|
|
100
|
+
dryRun?: boolean;
|
|
101
|
+
} & CallOptions): Promise<Schemas["IndexGcResponse"]>;
|
|
102
|
+
}
|
|
103
|
+
export declare class EntityNamespace {
|
|
104
|
+
private readonly client;
|
|
105
|
+
constructor(client: LbbClient);
|
|
106
|
+
/**
|
|
107
|
+
* Browse entities as the unified list envelope. Pass `fields` (names or `*`)
|
|
108
|
+
* to inline each row's typed attributes as native JSON (under `attributes`) —
|
|
109
|
+
* "list entities and their titles" in one call instead of a list plus N point
|
|
110
|
+
* lookups — or `ids`
|
|
111
|
+
* to fetch a specific set. Page with `cursor` from the previous `next_cursor`.
|
|
112
|
+
*/
|
|
113
|
+
list(opts?: EntityListOptions): Promise<ListResponse<Schemas["EntityExplorerRow"]>>;
|
|
114
|
+
/** Yield list envelopes while following `next_cursor` until exhaustion. */
|
|
115
|
+
pages(opts?: EntityListOptions): AsyncGenerator<ListResponse<Schemas["EntityExplorerRow"]>>;
|
|
116
|
+
/** Yield entities directly while following the server's stable cursor. */
|
|
117
|
+
iterate(opts?: EntityListOptions): AsyncGenerator<Schemas["EntityExplorerRow"]>;
|
|
118
|
+
get(opts: {
|
|
119
|
+
id?: string;
|
|
120
|
+
type?: string;
|
|
121
|
+
name?: string;
|
|
122
|
+
asOf?: string;
|
|
123
|
+
}): Promise<Schemas["EntityMetadataResponse"]>;
|
|
124
|
+
detail(opts: {
|
|
125
|
+
id?: string;
|
|
126
|
+
type?: string;
|
|
127
|
+
name?: string;
|
|
128
|
+
}): Promise<Schemas["EntityDetailResponse"]>;
|
|
129
|
+
/**
|
|
130
|
+
* Filter entities already bound by relation patterns using typed attributes,
|
|
131
|
+
* without writing RDF property IRIs by hand. This is a convenience wrapper over
|
|
132
|
+
* the structured SPARQL route: relation `patterns` bind variables, and `where`
|
|
133
|
+
* compares ontology property fields on those bound variables.
|
|
134
|
+
*/
|
|
135
|
+
filterByAttributes(opts: EntityAttributeFilterOptions): Promise<Schemas["SparqlSelectResponse"]>;
|
|
136
|
+
}
|
|
137
|
+
export interface EntityListOptions extends CallOptions {
|
|
138
|
+
type?: string;
|
|
139
|
+
limit?: number;
|
|
140
|
+
cursor?: string | number;
|
|
141
|
+
/** @deprecated Legacy alias for `cursor`. */
|
|
142
|
+
offset?: number;
|
|
143
|
+
query?: string;
|
|
144
|
+
/** Property names to inline per row (or `"*"` / `["*"]` for all). */
|
|
145
|
+
fields?: string | string[];
|
|
146
|
+
/** Specific entity ids to fetch in one call (bulk lookup). */
|
|
147
|
+
ids?: string | string[];
|
|
148
|
+
}
|
|
149
|
+
/** Grounding and answer operations over the graph's real vocabulary. */
|
|
150
|
+
export declare class ContextNamespace {
|
|
151
|
+
private readonly client;
|
|
152
|
+
constructor(client: LbbClient);
|
|
153
|
+
ask(body: Schemas["AskRequest"], opts?: CallOptions): Promise<Schemas["AskResponse"]>;
|
|
154
|
+
suggest(body: Schemas["SearchSuggestRequest"], opts?: CallOptions): Promise<Schemas["SearchSuggestResponse"]>;
|
|
155
|
+
resolve(body: Schemas["ResolveTermRequest"], opts?: CallOptions): Promise<Schemas["ResolveTermResponse"]>;
|
|
156
|
+
decode(body: Schemas["DecodeRequest"], opts?: CallOptions): Promise<Schemas["DecodeResponse"]>;
|
|
157
|
+
groundability(options?: {
|
|
158
|
+
sample?: number;
|
|
159
|
+
} & CallOptions): Promise<Schemas["GroundabilityReport"]>;
|
|
160
|
+
}
|
|
161
|
+
/** Ontology discovery and lifecycle operations. */
|
|
162
|
+
export declare class OntologyNamespace {
|
|
163
|
+
private readonly client;
|
|
164
|
+
constructor(client: LbbClient);
|
|
165
|
+
view(options?: {
|
|
166
|
+
counts?: boolean;
|
|
167
|
+
} & CallOptions): Promise<Schemas["OntologyView"]>;
|
|
168
|
+
conformance(opts?: CallOptions): Promise<Schemas["SchemaAuditReport"]>;
|
|
169
|
+
search(body: Schemas["OntologySearchRequest"], opts?: CallOptions): Promise<Schemas["OntologySearchResponse"]>;
|
|
170
|
+
resolve(body: Schemas["OntologyResolveRequest"], opts?: CallOptions): Promise<Schemas["OntologyResolveResponse"]>;
|
|
171
|
+
define(body: Schemas["OntologyDefineRequest"], opts?: CallOptions): Promise<Schemas["OntologyDefineResponse"]>;
|
|
172
|
+
evolve(body: Schemas["OntologyEvolveRequest"], opts?: CallOptions): Promise<Schemas["OntologyEvolveResponse"]>;
|
|
173
|
+
}
|
|
174
|
+
/** Structured, SPARQL-text, reasoning, and analytical query operations. */
|
|
175
|
+
export declare class QueryNamespace {
|
|
176
|
+
private readonly client;
|
|
177
|
+
constructor(client: LbbClient);
|
|
178
|
+
structured(body: Schemas["SparqlSelectRequest"], opts?: CallOptions): Promise<Schemas["SparqlSelectResponse"]>;
|
|
179
|
+
sparql(body: Schemas["SparqlTextRequest"], opts?: CallOptions): Promise<import("./types.js").SparqlResults>;
|
|
180
|
+
sparqlRaw(body: Schemas["SparqlTextRequest"], opts?: CallOptions): Promise<Schemas["SparqlTextResponse"]>;
|
|
181
|
+
analytics(body: Schemas["AnalyticQueryRequest"], opts?: CallOptions): Promise<Schemas["AnalyticQueryResponse"]>;
|
|
182
|
+
shacl(body: Schemas["ShaclQueryRequest"], opts?: CallOptions): Promise<Schemas["ShaclQueryResponse"]>;
|
|
183
|
+
infer(body: Schemas["InferenceRunRequest"], opts?: CallOptions): Promise<Schemas["InferenceRunResponse"]>;
|
|
184
|
+
premises(body: Schemas["RetrievalPremiseRequest"], opts?: CallOptions): Promise<Schemas["RetrievalPremiseResponse"]>;
|
|
185
|
+
}
|
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
import { attributeFilter, firstPatternVariable, parseSparqlResults, } from "./types.js";
|
|
2
|
+
function transportOptions(options) {
|
|
3
|
+
return {
|
|
4
|
+
idempotencyKey: options.idempotencyKey,
|
|
5
|
+
timeoutMs: options.timeoutMs,
|
|
6
|
+
maxRetries: options.maxRetries,
|
|
7
|
+
retry: options.retry,
|
|
8
|
+
signal: options.signal,
|
|
9
|
+
headers: options.headers,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export class GraphNamespace {
|
|
13
|
+
client;
|
|
14
|
+
facts;
|
|
15
|
+
context;
|
|
16
|
+
entities;
|
|
17
|
+
indexes;
|
|
18
|
+
ontology;
|
|
19
|
+
query;
|
|
20
|
+
schema;
|
|
21
|
+
search;
|
|
22
|
+
constructor(client) {
|
|
23
|
+
this.client = client;
|
|
24
|
+
this.facts = new FactsNamespace(client);
|
|
25
|
+
this.context = client.context;
|
|
26
|
+
this.entities = client.entities;
|
|
27
|
+
this.indexes = client.indexes;
|
|
28
|
+
this.ontology = client.ontology;
|
|
29
|
+
this.query = client.query;
|
|
30
|
+
this.schema = client.schema;
|
|
31
|
+
this.search = client.search;
|
|
32
|
+
}
|
|
33
|
+
branch(name) {
|
|
34
|
+
return new GraphNamespace(this.client.withScope({ branch: name }));
|
|
35
|
+
}
|
|
36
|
+
create(opts = {}) {
|
|
37
|
+
return this.client.request("POST", "/v1/graph/create", opts);
|
|
38
|
+
}
|
|
39
|
+
delete(opts) {
|
|
40
|
+
const { confirm, ...request } = opts;
|
|
41
|
+
return this.client.request("POST", "/v1/graph/delete", {
|
|
42
|
+
...request,
|
|
43
|
+
query: { confirm },
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/** Retract edges/entities from the scoped graph. See {@link LbbClient.retract}. */
|
|
47
|
+
retract(body, opts = {}) {
|
|
48
|
+
return this.client.request("POST", "/v1/graph/retract", {
|
|
49
|
+
...opts,
|
|
50
|
+
idempotencyKey: opts.idempotencyKey ?? this.client.idempotencyKey("retract"),
|
|
51
|
+
body,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Export this graph's current snapshot as Turtle, N-Triples, TriG, or N-Quads. */
|
|
55
|
+
exportRdf(opts = {}) {
|
|
56
|
+
return this.client.exportRdf(opts);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export class FactsNamespace {
|
|
60
|
+
client;
|
|
61
|
+
constructor(client) {
|
|
62
|
+
this.client = client;
|
|
63
|
+
}
|
|
64
|
+
create(body, opts = {}) {
|
|
65
|
+
return this.client.request("POST", "/v1/graph/commit", {
|
|
66
|
+
...opts,
|
|
67
|
+
body,
|
|
68
|
+
idempotencyKey: opts.idempotencyKey ?? this.client.idempotencyKey("facts.create"),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Bulk-load a dataset as NDJSON. See {@link LbbClient.import}. */
|
|
72
|
+
import(lines, opts = {}) {
|
|
73
|
+
const { batch, strict, observedAt, index, ...request } = opts;
|
|
74
|
+
const ndjson = typeof lines === "string"
|
|
75
|
+
? lines
|
|
76
|
+
: lines.map((line) => JSON.stringify(line)).join("\n");
|
|
77
|
+
return this.client.request("POST", "/v1/graph/import", {
|
|
78
|
+
...request,
|
|
79
|
+
idempotencyKey: request.idempotencyKey ?? this.client.idempotencyKey("import"),
|
|
80
|
+
rawBody: ndjson,
|
|
81
|
+
contentType: "application/x-ndjson",
|
|
82
|
+
query: { batch, strict, observed_at: observedAt, index },
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Bulk-load N-Triples, Turtle, N-Quads, or TriG through the native RDF import endpoint.
|
|
87
|
+
*
|
|
88
|
+
* Statements are committed through the fixed RDF_TRIPLE relation; source RDF
|
|
89
|
+
* predicates and literal term details are preserved as edge metadata.
|
|
90
|
+
*/
|
|
91
|
+
importRdf(rdf, opts = {}) {
|
|
92
|
+
const { format = "ntriples", baseIri, graphUri, blankNodeScope, batch, strict, observedAt, resourceType, edgeIdempotency, ...request } = opts;
|
|
93
|
+
return this.client.request("POST", "/v1/graph/import/rdf", {
|
|
94
|
+
...request,
|
|
95
|
+
idempotencyKey: request.idempotencyKey ?? this.client.idempotencyKey("import-rdf"),
|
|
96
|
+
rawBody: rdf,
|
|
97
|
+
contentType: {
|
|
98
|
+
ntriples: "application/n-triples",
|
|
99
|
+
turtle: "text/turtle",
|
|
100
|
+
nquads: "application/n-quads",
|
|
101
|
+
trig: "application/trig",
|
|
102
|
+
}[format],
|
|
103
|
+
query: {
|
|
104
|
+
batch,
|
|
105
|
+
strict,
|
|
106
|
+
observed_at: observedAt,
|
|
107
|
+
format,
|
|
108
|
+
base_iri: baseIri,
|
|
109
|
+
graph_uri: graphUri,
|
|
110
|
+
blank_node_scope: blankNodeScope,
|
|
111
|
+
resource_type: resourceType,
|
|
112
|
+
edge_idempotency: edgeIdempotency,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export class SearchNamespace {
|
|
118
|
+
client;
|
|
119
|
+
constructor(client) {
|
|
120
|
+
this.client = client;
|
|
121
|
+
}
|
|
122
|
+
hybrid(input, opts = {}) {
|
|
123
|
+
if (typeof input !== "string") {
|
|
124
|
+
return this.client.request("POST", "/v1/graph/search", {
|
|
125
|
+
...transportOptions(opts),
|
|
126
|
+
retry: opts.retry ?? true,
|
|
127
|
+
body: input,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return this.client.request("GET", "/v1/search", {
|
|
131
|
+
...transportOptions(opts),
|
|
132
|
+
query: {
|
|
133
|
+
query: input,
|
|
134
|
+
top_k: opts.topK,
|
|
135
|
+
source: opts.source,
|
|
136
|
+
consistency: opts.consistency,
|
|
137
|
+
lexical: opts.lexical,
|
|
138
|
+
bm25: opts.bm25,
|
|
139
|
+
vector: opts.vector,
|
|
140
|
+
targets: opts.targets?.join(","),
|
|
141
|
+
profile: opts.profile,
|
|
142
|
+
as_of: opts.asOf,
|
|
143
|
+
as_of_commit_seq: opts.asOfCommitSeq,
|
|
144
|
+
log_impression: opts.logImpression,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
multi(body, opts = {}) {
|
|
149
|
+
return this.client.request("POST", "/v1/search/multi", {
|
|
150
|
+
...opts,
|
|
151
|
+
retry: opts.retry ?? true,
|
|
152
|
+
body,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
feedback(body, opts = {}) {
|
|
156
|
+
return this.client.request("POST", "/v1/search/feedback", {
|
|
157
|
+
...opts,
|
|
158
|
+
body,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
feedbackExport(opts = {}) {
|
|
162
|
+
return this.client.request("GET", "/v1/search/feedback/export", opts);
|
|
163
|
+
}
|
|
164
|
+
fullText(body, opts = {}) {
|
|
165
|
+
return this.client.request("POST", "/v1/search/full-text", {
|
|
166
|
+
...opts,
|
|
167
|
+
retry: opts.retry ?? true,
|
|
168
|
+
body,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
vector(body, opts = {}) {
|
|
172
|
+
return this.client.request("POST", "/v1/search/embedding", {
|
|
173
|
+
...opts,
|
|
174
|
+
retry: opts.retry ?? true,
|
|
175
|
+
body,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
export class SchemaNamespace {
|
|
180
|
+
client;
|
|
181
|
+
constructor(client) {
|
|
182
|
+
this.client = client;
|
|
183
|
+
}
|
|
184
|
+
/** Active graph schema bundle: ontology plus activated SHACL shapes. */
|
|
185
|
+
view(opts = {}) {
|
|
186
|
+
const { audit, ...request } = opts;
|
|
187
|
+
return this.client.request("GET", "/v1/schema", {
|
|
188
|
+
...request,
|
|
189
|
+
query: { audit: audit || undefined },
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/** Preview a proposed RDF/SHACL schema bundle and audit current data. */
|
|
193
|
+
preview(body, opts = {}) {
|
|
194
|
+
return this.client.request("POST", "/v1/schema/preview", {
|
|
195
|
+
...opts,
|
|
196
|
+
retry: opts.retry ?? true,
|
|
197
|
+
body,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
/** Activate a previewed SHACL schema bundle for this graph branch. */
|
|
201
|
+
publish(body, opts = {}) {
|
|
202
|
+
return this.client.request("POST", "/v1/schema/publish", { ...opts, body });
|
|
203
|
+
}
|
|
204
|
+
/** Audit current data against the active SHACL schema bundle. */
|
|
205
|
+
audit(opts = {}) {
|
|
206
|
+
return this.client.request("POST", "/v1/schema/audit", {
|
|
207
|
+
...opts,
|
|
208
|
+
retry: opts.retry ?? true,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
export class IndexNamespace {
|
|
213
|
+
client;
|
|
214
|
+
constructor(client) {
|
|
215
|
+
this.client = client;
|
|
216
|
+
}
|
|
217
|
+
run(opts = {}) {
|
|
218
|
+
const { wait, background: requestedBackground, body, ...request } = opts;
|
|
219
|
+
const background = requestedBackground ?? (wait === false ? true : undefined);
|
|
220
|
+
return this.client.request("POST", "/v1/index/run", {
|
|
221
|
+
...request,
|
|
222
|
+
query: { background },
|
|
223
|
+
body,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
build(opts = {}) {
|
|
227
|
+
const { background, ...request } = opts;
|
|
228
|
+
return this.client.request("POST", "/v1/index/build", {
|
|
229
|
+
...request,
|
|
230
|
+
query: { background: background || undefined },
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
delta(opts = {}) {
|
|
234
|
+
return this.client.request("POST", "/v1/index/delta", opts);
|
|
235
|
+
}
|
|
236
|
+
gc(opts = {}) {
|
|
237
|
+
const { keepRuns, dryRun, ...request } = opts;
|
|
238
|
+
return this.client.request("POST", "/v1/index/gc", {
|
|
239
|
+
...request,
|
|
240
|
+
query: { keep_runs: keepRuns, dry_run: dryRun },
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export class EntityNamespace {
|
|
245
|
+
client;
|
|
246
|
+
constructor(client) {
|
|
247
|
+
this.client = client;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Browse entities as the unified list envelope. Pass `fields` (names or `*`)
|
|
251
|
+
* to inline each row's typed attributes as native JSON (under `attributes`) —
|
|
252
|
+
* "list entities and their titles" in one call instead of a list plus N point
|
|
253
|
+
* lookups — or `ids`
|
|
254
|
+
* to fetch a specific set. Page with `cursor` from the previous `next_cursor`.
|
|
255
|
+
*/
|
|
256
|
+
list(opts = {}) {
|
|
257
|
+
const csv = (v) => Array.isArray(v) ? v.join(",") : v;
|
|
258
|
+
return this.client.request("GET", "/v1/graph/entities", {
|
|
259
|
+
...transportOptions(opts),
|
|
260
|
+
query: {
|
|
261
|
+
type: opts.type,
|
|
262
|
+
limit: opts.limit,
|
|
263
|
+
cursor: opts.cursor,
|
|
264
|
+
offset: opts.offset,
|
|
265
|
+
q: opts.query,
|
|
266
|
+
fields: csv(opts.fields),
|
|
267
|
+
ids: csv(opts.ids),
|
|
268
|
+
},
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
/** Yield list envelopes while following `next_cursor` until exhaustion. */
|
|
272
|
+
async *pages(opts = {}) {
|
|
273
|
+
let cursor = opts.cursor;
|
|
274
|
+
const seen = new Set();
|
|
275
|
+
do {
|
|
276
|
+
const page = await this.list({
|
|
277
|
+
...opts,
|
|
278
|
+
cursor,
|
|
279
|
+
offset: cursor === undefined ? opts.offset : undefined,
|
|
280
|
+
});
|
|
281
|
+
yield page;
|
|
282
|
+
if (!page.has_more || page.next_cursor === null)
|
|
283
|
+
return;
|
|
284
|
+
if (seen.has(page.next_cursor)) {
|
|
285
|
+
throw new Error(`entity pagination cursor repeated: ${page.next_cursor}`);
|
|
286
|
+
}
|
|
287
|
+
seen.add(page.next_cursor);
|
|
288
|
+
cursor = page.next_cursor;
|
|
289
|
+
} while (true);
|
|
290
|
+
}
|
|
291
|
+
/** Yield entities directly while following the server's stable cursor. */
|
|
292
|
+
async *iterate(opts = {}) {
|
|
293
|
+
for await (const page of this.pages(opts)) {
|
|
294
|
+
for (const entity of page.data)
|
|
295
|
+
yield entity;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
get(opts) {
|
|
299
|
+
return this.client.entityMetadata(opts);
|
|
300
|
+
}
|
|
301
|
+
detail(opts) {
|
|
302
|
+
return this.client.entityDetail(opts);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Filter entities already bound by relation patterns using typed attributes,
|
|
306
|
+
* without writing RDF property IRIs by hand. This is a convenience wrapper over
|
|
307
|
+
* the structured SPARQL route: relation `patterns` bind variables, and `where`
|
|
308
|
+
* compares ontology property fields on those bound variables.
|
|
309
|
+
*/
|
|
310
|
+
filterByAttributes(opts) {
|
|
311
|
+
const defaultVar = firstPatternVariable(opts.patterns);
|
|
312
|
+
const where = Array.isArray(opts.where) ? opts.where : [opts.where];
|
|
313
|
+
return this.client.sparql({
|
|
314
|
+
patterns: opts.patterns,
|
|
315
|
+
filters: [
|
|
316
|
+
...(opts.filters ?? []),
|
|
317
|
+
...where.map((filter) => attributeFilter(filter, defaultVar)),
|
|
318
|
+
],
|
|
319
|
+
select: opts.select,
|
|
320
|
+
limit: opts.limit,
|
|
321
|
+
offset: opts.offset,
|
|
322
|
+
as_of_valid_time: opts.asOfValidTime,
|
|
323
|
+
as_of_commit_seq: opts.asOfCommitSeq,
|
|
324
|
+
order_by: opts.orderBy,
|
|
325
|
+
reason: opts.reason,
|
|
326
|
+
max_solutions: opts.maxSolutions,
|
|
327
|
+
max_object_reads: opts.maxObjectReads,
|
|
328
|
+
max_fetched_bytes: opts.maxFetchedBytes,
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/** Grounding and answer operations over the graph's real vocabulary. */
|
|
333
|
+
export class ContextNamespace {
|
|
334
|
+
client;
|
|
335
|
+
constructor(client) {
|
|
336
|
+
this.client = client;
|
|
337
|
+
}
|
|
338
|
+
ask(body, opts = {}) {
|
|
339
|
+
return this.client.request("POST", "/v1/ask", {
|
|
340
|
+
...opts,
|
|
341
|
+
retry: opts.retry ?? true,
|
|
342
|
+
body,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
suggest(body, opts = {}) {
|
|
346
|
+
return this.client.request("POST", "/v1/search/suggest", {
|
|
347
|
+
...opts,
|
|
348
|
+
retry: opts.retry ?? true,
|
|
349
|
+
body,
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
resolve(body, opts = {}) {
|
|
353
|
+
return this.client.request("POST", "/v1/search/resolve-term", {
|
|
354
|
+
...opts,
|
|
355
|
+
retry: opts.retry ?? true,
|
|
356
|
+
body,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
decode(body, opts = {}) {
|
|
360
|
+
return this.client.request("POST", "/v1/decode", {
|
|
361
|
+
...opts,
|
|
362
|
+
retry: opts.retry ?? true,
|
|
363
|
+
body,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
groundability(options = {}) {
|
|
367
|
+
const { sample, ...request } = options;
|
|
368
|
+
return this.client.request("GET", "/v1/graph/groundability", {
|
|
369
|
+
...request,
|
|
370
|
+
query: sample === undefined ? undefined : { sample },
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/** Ontology discovery and lifecycle operations. */
|
|
375
|
+
export class OntologyNamespace {
|
|
376
|
+
client;
|
|
377
|
+
constructor(client) {
|
|
378
|
+
this.client = client;
|
|
379
|
+
}
|
|
380
|
+
view(options = {}) {
|
|
381
|
+
const { counts, ...request } = options;
|
|
382
|
+
return this.client.request("GET", "/v1/ontology", {
|
|
383
|
+
...request,
|
|
384
|
+
query: counts ? { counts: true } : undefined,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
conformance(opts = {}) {
|
|
388
|
+
return this.client.request("GET", "/v1/ontology/conformance", opts);
|
|
389
|
+
}
|
|
390
|
+
search(body, opts = {}) {
|
|
391
|
+
return this.client.request("POST", "/v1/ontology/search", {
|
|
392
|
+
...opts,
|
|
393
|
+
retry: opts.retry ?? true,
|
|
394
|
+
body,
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
resolve(body, opts = {}) {
|
|
398
|
+
return this.client.request("POST", "/v1/ontology/resolve", {
|
|
399
|
+
...opts,
|
|
400
|
+
retry: opts.retry ?? true,
|
|
401
|
+
body,
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
define(body, opts = {}) {
|
|
405
|
+
return this.client.request("POST", "/v1/ontology/define", {
|
|
406
|
+
...opts,
|
|
407
|
+
body,
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
evolve(body, opts = {}) {
|
|
411
|
+
return this.client.request("POST", "/v1/ontology/evolve", {
|
|
412
|
+
...opts,
|
|
413
|
+
body,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/** Structured, SPARQL-text, reasoning, and analytical query operations. */
|
|
418
|
+
export class QueryNamespace {
|
|
419
|
+
client;
|
|
420
|
+
constructor(client) {
|
|
421
|
+
this.client = client;
|
|
422
|
+
}
|
|
423
|
+
structured(body, opts = {}) {
|
|
424
|
+
return this.client.request("POST", "/v1/query/sparql", {
|
|
425
|
+
...opts,
|
|
426
|
+
retry: opts.retry ?? true,
|
|
427
|
+
body,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
async sparql(body, opts = {}) {
|
|
431
|
+
const response = await this.client.request("POST", "/v1/query/sparql-text", { ...opts, retry: opts.retry ?? true, body });
|
|
432
|
+
return parseSparqlResults(response);
|
|
433
|
+
}
|
|
434
|
+
sparqlRaw(body, opts = {}) {
|
|
435
|
+
return this.client.request("POST", "/v1/query/sparql-text", {
|
|
436
|
+
...opts,
|
|
437
|
+
retry: opts.retry ?? true,
|
|
438
|
+
body,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
analytics(body, opts = {}) {
|
|
442
|
+
return this.client.request("POST", "/v1/query/analytics", {
|
|
443
|
+
...opts,
|
|
444
|
+
retry: opts.retry ?? true,
|
|
445
|
+
body,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
shacl(body, opts = {}) {
|
|
449
|
+
return this.client.request("POST", "/v1/query/shacl", {
|
|
450
|
+
...opts,
|
|
451
|
+
retry: opts.retry ?? true,
|
|
452
|
+
body,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
infer(body, opts = {}) {
|
|
456
|
+
return this.client.request("POST", "/v1/inference/run", {
|
|
457
|
+
...opts,
|
|
458
|
+
retry: opts.retry ?? true,
|
|
459
|
+
body,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
premises(body, opts = {}) {
|
|
463
|
+
return this.client.request("POST", "/v1/inference/retrieval-premises", {
|
|
464
|
+
...opts,
|
|
465
|
+
retry: opts.retry ?? true,
|
|
466
|
+
body,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
}
|