@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
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import { resolve } from "node:path";
|
|
5
|
-
|
|
6
|
-
// Contract-drift guard for the hand-written TS client surface (S8). The
|
|
7
|
-
// generated types (schema.ts) are gated by the `contracts` CI job, but the
|
|
8
|
-
// hand-written `this.request("METHOD", "/path")` calls embed route strings
|
|
9
|
-
// nothing checks. This asserts every literal route the client issues is either
|
|
10
|
-
// a real operation in contracts/openapi.json or an explicitly allow-listed
|
|
11
|
-
// control-plane route.
|
|
12
|
-
//
|
|
13
|
-
// `npm test` runs from the package dir, so cwd is packages/lbb-client.
|
|
14
|
-
const REPO_ROOT = resolve(process.cwd(), "../..");
|
|
15
|
-
const OPENAPI = resolve(REPO_ROOT, "contracts/openapi.json");
|
|
16
|
-
const CLIENT = resolve(process.cwd(), "src/client.ts");
|
|
17
|
-
|
|
18
|
-
// Control-plane routes the TS client legitimately calls that are intentionally
|
|
19
|
-
// NOT in the public data-plane OpenAPI contract (SaaS admin/session
|
|
20
|
-
// orchestration). This allow-list is the visible debt register: adding a route
|
|
21
|
-
// here is a conscious decision to leave it uncontracted.
|
|
22
|
-
const UNCONTRACTED = new Set<string>([
|
|
23
|
-
"DELETE /api/admin/stacks",
|
|
24
|
-
"GET /api/admin/stacks",
|
|
25
|
-
"GET /api/admin/stacks/activity",
|
|
26
|
-
"GET /v1/stack/activity",
|
|
27
|
-
"POST /api/admin/sessions",
|
|
28
|
-
"POST /api/admin/stacks",
|
|
29
|
-
"POST /api/admin/stacks/rotate-key",
|
|
30
|
-
]);
|
|
31
|
-
|
|
32
|
-
const HTTP_METHODS = new Set(["get", "post", "put", "patch", "delete"]);
|
|
33
|
-
|
|
34
|
-
function specOperations(): Set<string> {
|
|
35
|
-
const spec = JSON.parse(readFileSync(OPENAPI, "utf8")) as {
|
|
36
|
-
paths: Record<string, Record<string, unknown>>;
|
|
37
|
-
};
|
|
38
|
-
const ops = new Set<string>();
|
|
39
|
-
for (const [path, methods] of Object.entries(spec.paths)) {
|
|
40
|
-
for (const method of Object.keys(methods)) {
|
|
41
|
-
if (HTTP_METHODS.has(method.toLowerCase())) {
|
|
42
|
-
ops.add(`${method.toUpperCase()} ${path}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return ops;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function clientRoutes(): Set<string> {
|
|
50
|
-
// Matches `this.request("POST", "/v1/graph/commit"`; only static string-literal
|
|
51
|
-
// paths are captured (template-literal path-param routes are covered by the
|
|
52
|
-
// methods that build them and are invisible here).
|
|
53
|
-
const source = readFileSync(CLIENT, "utf8");
|
|
54
|
-
const re = /request\(\s*"([A-Z]+)",\s*"([^"]+)"/g;
|
|
55
|
-
const routes = new Set<string>();
|
|
56
|
-
let match: RegExpExecArray | null;
|
|
57
|
-
while ((match = re.exec(source)) !== null) {
|
|
58
|
-
routes.add(`${match[1]} ${match[2]}`);
|
|
59
|
-
}
|
|
60
|
-
return routes;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
test("every TS client route is contracted or explicitly allow-listed", () => {
|
|
64
|
-
const spec = specOperations();
|
|
65
|
-
const routes = clientRoutes();
|
|
66
|
-
assert.ok(routes.size > 0, "no request routes parsed from client.ts");
|
|
67
|
-
const missing = [...routes]
|
|
68
|
-
.filter((route) => !spec.has(route) && !UNCONTRACTED.has(route))
|
|
69
|
-
.sort();
|
|
70
|
-
assert.deepEqual(
|
|
71
|
-
missing,
|
|
72
|
-
[],
|
|
73
|
-
`client calls route(s) absent from contracts/openapi.json and not allow-listed ` +
|
|
74
|
-
`(typo or removed route?): ${missing.join(", ")}`,
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test("the uncontracted allow-list has no stale entries", () => {
|
|
79
|
-
// Prune an allow-listed route the client no longer calls, or that has since
|
|
80
|
-
// been added to the contract — keep the debt register honest.
|
|
81
|
-
const spec = specOperations();
|
|
82
|
-
const routes = clientRoutes();
|
|
83
|
-
const stale = [...UNCONTRACTED]
|
|
84
|
-
.filter((route) => !routes.has(route) || spec.has(route))
|
|
85
|
-
.sort();
|
|
86
|
-
assert.deepEqual(
|
|
87
|
-
stale,
|
|
88
|
-
[],
|
|
89
|
-
`stale allow-list entries (client no longer calls, or now contracted): ${stale.join(", ")}`,
|
|
90
|
-
);
|
|
91
|
-
});
|
package/src/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export { LbbClient, LbbError, parseSparqlResults } from "./client.js";
|
|
2
|
-
export type {
|
|
3
|
-
LbbAdminStackCreateRequest,
|
|
4
|
-
LbbAdminStackDeleteResponse,
|
|
5
|
-
LbbAdminStackResponse,
|
|
6
|
-
LbbClientOptions,
|
|
7
|
-
LbbStackActivityResponse,
|
|
8
|
-
LbbStackActivityWindow,
|
|
9
|
-
LbbStackView,
|
|
10
|
-
FetchLike,
|
|
11
|
-
Schemas,
|
|
12
|
-
SparqlResults,
|
|
13
|
-
SparqlResultsJson,
|
|
14
|
-
SparqlTerm,
|
|
15
|
-
} from "./client.js";
|
|
16
|
-
export type { components, paths, operations } from "./schema.js";
|
package/src/node-test-shim.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
declare module "node:test" {
|
|
2
|
-
export function test(name: string, fn: () => unknown | Promise<unknown>): void;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
declare module "node:assert/strict" {
|
|
6
|
-
const assert: {
|
|
7
|
-
equal(actual: unknown, expected: unknown, message?: string): void;
|
|
8
|
-
deepEqual(actual: unknown, expected: unknown, message?: string): void;
|
|
9
|
-
match(actual: string, expected: RegExp, message?: string): void;
|
|
10
|
-
rejects(
|
|
11
|
-
fn: () => unknown | Promise<unknown>,
|
|
12
|
-
predicate?: (error: unknown) => boolean,
|
|
13
|
-
): Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
export default assert;
|
|
16
|
-
}
|