@littlebigbrain/client 0.1.0 → 0.2.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 +57 -15
- package/dist/client.d.ts +208 -433
- package/dist/client.js +368 -318
- package/dist/index.d.ts +1 -1
- package/dist/namespaces.d.ts +201 -0
- package/dist/namespaces.js +482 -0
- package/dist/schema.d.ts +10653 -3600
- package/dist/transport.d.ts +44 -0
- package/dist/transport.js +93 -0
- package/dist/types.d.ts +314 -0
- package/dist/types.js +47 -0
- package/package.json +34 -5
- 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/LICENSE
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
package/README.md
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
|
-
# @
|
|
1
|
+
# @littlebigbrain/client
|
|
2
2
|
|
|
3
|
-
TypeScript client for the [Little Big Brain](
|
|
3
|
+
TypeScript client for the [Little Big Brain](https://littlebigbrain.com) graph + hybrid search HTTP
|
|
4
4
|
API. Request and response types are generated from the committed
|
|
5
|
-
[`contracts/openapi.json`](
|
|
5
|
+
[`contracts/openapi.json`](https://github.com/littlebigbrains/lbb-typescript/blob/main/contracts/openapi.json) (the single source of
|
|
6
6
|
truth, derived from the Rust `lbb-api` types); the client itself is a thin,
|
|
7
7
|
dependency-free wrapper over the platform `fetch`.
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install @
|
|
10
|
+
npm install @littlebigbrain/client
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { LbbClient, LbbError } from "@
|
|
16
|
+
import { LbbClient, LbbError } from "@littlebigbrain/client";
|
|
17
17
|
|
|
18
18
|
const lbb = new LbbClient({
|
|
19
19
|
baseUrl: "https://db.eu.littlebigbrain.com",
|
|
20
20
|
apiKey: process.env.LBB_API_KEY, // lbb_sk_test_… or lbb_sk_live_…
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
const graph = lbb.graph("main");
|
|
24
|
+
|
|
25
|
+
await graph.facts.create({
|
|
24
26
|
triplets: [
|
|
25
27
|
{
|
|
26
28
|
source: { type: "SERVICE", name: "auth-service" },
|
|
@@ -34,9 +36,9 @@ await lbb.graph("main").facts.create({
|
|
|
34
36
|
idempotencyKey: "import-2026-06-13",
|
|
35
37
|
});
|
|
36
38
|
|
|
37
|
-
await
|
|
39
|
+
await graph.indexes.run({ wait: true });
|
|
38
40
|
|
|
39
|
-
const results = await
|
|
41
|
+
const results = await graph.search.hybrid("which systems store customer identity data", {
|
|
40
42
|
topK: 5,
|
|
41
43
|
source: "persisted",
|
|
42
44
|
consistency: "strong",
|
|
@@ -52,25 +54,63 @@ when you need response metadata (`requestId`, `version`, headers). Every method
|
|
|
52
54
|
returns parsed JSON and throws `LbbError` with `status`, `type`, `code`,
|
|
53
55
|
`message`, `param`, `requestId`, and `docUrl` on a non-2xx response.
|
|
54
56
|
|
|
57
|
+
Requests have a 120-second per-attempt timeout by default (`timeoutMs: 0`
|
|
58
|
+
disables it). Safe reads and idempotency-keyed writes retry `429`/`5xx` and
|
|
59
|
+
network failures up to twice, honoring `Retry-After` with a one-minute cap.
|
|
60
|
+
Bulk NDJSON and RDF imports receive an idempotency key automatically unless you
|
|
61
|
+
provide one explicitly. The preferred namespaced surface accepts the same final
|
|
62
|
+
request options everywhere: `timeoutMs`, `maxRetries`, `signal`, `headers`, and
|
|
63
|
+
`idempotencyKey` for mutations.
|
|
64
|
+
|
|
65
|
+
## Preferred surface
|
|
66
|
+
|
|
67
|
+
Scope once with `client.graph("name", { branch })`; its `facts`, `search`,
|
|
68
|
+
`entities`, `indexes`, `schema`, `ontology`, `query`, and `context` namespaces
|
|
69
|
+
all carry that graph and branch. The original flat methods remain available for
|
|
70
|
+
compatibility.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
const graph = lbb.graph("main", { branch: "review" });
|
|
74
|
+
|
|
75
|
+
const answer = await graph.context.ask({ question: "what stores identity data?" });
|
|
76
|
+
const ontology = await graph.ontology.view({ counts: true });
|
|
77
|
+
const rows = await graph.query.sparql({ query: "SELECT ?s WHERE { ?s ?p ?o }" });
|
|
78
|
+
|
|
79
|
+
for await (const entity of graph.entities.iterate({ fields: ["owner", "status"] })) {
|
|
80
|
+
console.log(entity.name, entity.attributes);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Use `entities.pages(...)` when page metadata matters, or `entities.iterate(...)`
|
|
85
|
+
to yield rows directly. Both follow the server cursor and fail if a cursor
|
|
86
|
+
repeats instead of looping forever.
|
|
87
|
+
|
|
88
|
+
For instrumentation, `onRequest` fires before each attempt and `onResponse`
|
|
89
|
+
fires once for the final response; neither event contains bodies or
|
|
90
|
+
credentials. `rawRequest(...)` additionally reports `attempts`, `retryCount`,
|
|
91
|
+
and `elapsedMs`.
|
|
92
|
+
|
|
55
93
|
## Methods
|
|
56
94
|
|
|
57
95
|
| Area | Methods |
|
|
58
96
|
| --- | --- |
|
|
59
97
|
| Write | `graph("main").facts.create` |
|
|
60
98
|
| Search | `search.hybrid`, `search.multi`, `search.fullText`, `search.vector` |
|
|
61
|
-
|
|
|
99
|
+
| Context substrate | `context.ask`, `context.suggest`, `context.resolve`, `context.decode`, `context.groundability` |
|
|
100
|
+
| Search feedback (training data) | `search.feedback`, `search.feedbackExport` |
|
|
62
101
|
| Traversal | `traverse`, `semanticTraverse` |
|
|
63
102
|
| Temporal / lineage / shapes | `currentState`, `history`, `why`, `shacl` |
|
|
64
|
-
|
|
|
65
|
-
| Ontology | `
|
|
103
|
+
| Query | `query.sparql`, `query.structured`, `query.analytics`, `query.shacl`, `query.infer`, `query.premises` |
|
|
104
|
+
| Ontology | `ontology.view`, `ontology.conformance`, `ontology.search`, `ontology.resolve`, `ontology.define`, `ontology.evolve` |
|
|
66
105
|
| Index lifecycle | `indexes.run`, `indexes.build`, `indexes.delta`, `indexes.gc`, `compact` |
|
|
67
106
|
| Inspection | `entities.list`, `entities.filterByAttributes`, `status`, `metadata`, `summary` |
|
|
68
107
|
| Schema activation | `schema.view`, `schema.preview`, `schema.publish`, `schema.audit` |
|
|
69
|
-
| Database admin | `
|
|
108
|
+
| Database admin | `admin.createStack`, `admin.stack`, `admin.rotateStackKey`, `admin.deleteStack` |
|
|
70
109
|
|
|
71
|
-
|
|
72
|
-
`
|
|
73
|
-
`
|
|
110
|
+
Common request/response shapes have direct imports such as `SearchRequest`,
|
|
111
|
+
`SearchResponse`, `Entity`, `GraphSummary`, `CommitRequest`, `AskResponse`, and
|
|
112
|
+
`SchemaView`. Every generated shape remains available as `Schemas["TypeName"]`;
|
|
113
|
+
the raw `components`, `paths`, and `operations` are exported too.
|
|
74
114
|
|
|
75
115
|
## SPARQL
|
|
76
116
|
|
|
@@ -121,6 +161,8 @@ npm install
|
|
|
121
161
|
npm run generate # regenerate src/schema.ts from ../../contracts/openapi.json
|
|
122
162
|
npm run build # tsc -> dist/
|
|
123
163
|
npm test # build + node:test (mocked fetch)
|
|
164
|
+
npm run test:coverage
|
|
165
|
+
npm run pack:check # exact tarball: publint + ATTW
|
|
124
166
|
```
|
|
125
167
|
|
|
126
168
|
`runtime`: any environment with a global `fetch` (Node 18+, browsers, edge
|