@niscorp/vex 0.1.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/DESIGN.md +881 -0
- package/DOCS.md +1295 -0
- package/LICENSE +202 -0
- package/README.md +97 -0
- package/dist/adapters/express/index.cjs +1406 -0
- package/dist/adapters/express/index.cjs.map +1 -0
- package/dist/adapters/express/index.d.cts +25 -0
- package/dist/adapters/express/index.d.ts +25 -0
- package/dist/adapters/express/index.js +60 -0
- package/dist/adapters/express/index.js.map +1 -0
- package/dist/adapters/hono/index.cjs +1426 -0
- package/dist/adapters/hono/index.cjs.map +1 -0
- package/dist/adapters/hono/index.d.cts +25 -0
- package/dist/adapters/hono/index.d.ts +25 -0
- package/dist/adapters/hono/index.js +78 -0
- package/dist/adapters/hono/index.js.map +1 -0
- package/dist/adapters/pglite/index.cjs +17 -0
- package/dist/adapters/pglite/index.cjs.map +1 -0
- package/dist/adapters/pglite/index.d.cts +21 -0
- package/dist/adapters/pglite/index.d.ts +21 -0
- package/dist/adapters/pglite/index.js +14 -0
- package/dist/adapters/pglite/index.js.map +1 -0
- package/dist/agent/index.cjs +478 -0
- package/dist/agent/index.cjs.map +1 -0
- package/dist/agent/index.d.cts +29 -0
- package/dist/agent/index.d.ts +29 -0
- package/dist/agent/index.js +313 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/chunk-FPKW4TRX.js +1528 -0
- package/dist/chunk-FPKW4TRX.js.map +1 -0
- package/dist/chunk-HF25Q53I.js +165 -0
- package/dist/chunk-HF25Q53I.js.map +1 -0
- package/dist/handler-Cql8SJ3F.d.cts +133 -0
- package/dist/handler-mICf9ins.d.ts +133 -0
- package/dist/index.cjs +4078 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +199 -0
- package/dist/index.d.ts +199 -0
- package/dist/index.js +2340 -0
- package/dist/index.js.map +1 -0
- package/dist/introspect-D3OaXHBc.d.cts +16 -0
- package/dist/introspect-D3OaXHBc.d.ts +16 -0
- package/dist/types-BRvMB6IM.d.cts +1491 -0
- package/dist/types-BRvMB6IM.d.ts +1491 -0
- package/package.json +125 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { a as QueryEngine, ak as ScopeValues } from '../../types-BRvMB6IM.cjs';
|
|
2
|
+
import { V as VexHandlerConfig } from '../../handler-Cql8SJ3F.cjs';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import '@niscorp/prism';
|
|
5
|
+
import '@niscorp/strata';
|
|
6
|
+
|
|
7
|
+
type VexExpressRequest = {
|
|
8
|
+
method: string;
|
|
9
|
+
body: unknown;
|
|
10
|
+
query: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
type VexExpressResponse = {
|
|
13
|
+
json(body: unknown): unknown;
|
|
14
|
+
status(code: number): VexExpressResponse;
|
|
15
|
+
};
|
|
16
|
+
type VexExpressConfig<TReq extends VexExpressRequest = VexExpressRequest> = {
|
|
17
|
+
engine: QueryEngine;
|
|
18
|
+
entities?: string[];
|
|
19
|
+
locked?: boolean;
|
|
20
|
+
getScope?: (req: TReq) => Promise<ScopeValues> | ScopeValues;
|
|
21
|
+
mutations?: VexHandlerConfig['mutations'];
|
|
22
|
+
};
|
|
23
|
+
declare const vex: <TReq extends VexExpressRequest = VexExpressRequest>(config: VexExpressConfig<TReq>) => ((req: TReq, res: VexExpressResponse) => Promise<void>);
|
|
24
|
+
|
|
25
|
+
export { type VexExpressConfig, type VexExpressRequest, type VexExpressResponse, vex };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { a as QueryEngine, ak as ScopeValues } from '../../types-BRvMB6IM.js';
|
|
2
|
+
import { V as VexHandlerConfig } from '../../handler-mICf9ins.js';
|
|
3
|
+
import 'zod';
|
|
4
|
+
import '@niscorp/prism';
|
|
5
|
+
import '@niscorp/strata';
|
|
6
|
+
|
|
7
|
+
type VexExpressRequest = {
|
|
8
|
+
method: string;
|
|
9
|
+
body: unknown;
|
|
10
|
+
query: Record<string, unknown>;
|
|
11
|
+
};
|
|
12
|
+
type VexExpressResponse = {
|
|
13
|
+
json(body: unknown): unknown;
|
|
14
|
+
status(code: number): VexExpressResponse;
|
|
15
|
+
};
|
|
16
|
+
type VexExpressConfig<TReq extends VexExpressRequest = VexExpressRequest> = {
|
|
17
|
+
engine: QueryEngine;
|
|
18
|
+
entities?: string[];
|
|
19
|
+
locked?: boolean;
|
|
20
|
+
getScope?: (req: TReq) => Promise<ScopeValues> | ScopeValues;
|
|
21
|
+
mutations?: VexHandlerConfig['mutations'];
|
|
22
|
+
};
|
|
23
|
+
declare const vex: <TReq extends VexExpressRequest = VexExpressRequest>(config: VexExpressConfig<TReq>) => ((req: TReq, res: VexExpressResponse) => Promise<void>);
|
|
24
|
+
|
|
25
|
+
export { type VexExpressConfig, type VexExpressRequest, type VexExpressResponse, vex };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../chunk-FPKW4TRX.js';
|
|
2
|
+
import '../../chunk-HF25Q53I.js';
|
|
3
|
+
|
|
4
|
+
// src/adapters/express/index.ts
|
|
5
|
+
var fingerprintFromBody = (body) => {
|
|
6
|
+
if (body === null || typeof body !== "object") return void 0;
|
|
7
|
+
const fp = body["fingerprint"];
|
|
8
|
+
return typeof fp === "string" && fp.length > 0 ? fp : void 0;
|
|
9
|
+
};
|
|
10
|
+
var vex = (config) => {
|
|
11
|
+
const handlerConfig = {
|
|
12
|
+
engine: config.engine,
|
|
13
|
+
entities: config.entities,
|
|
14
|
+
...config.locked === true ? { locked: true } : {},
|
|
15
|
+
...config.mutations !== void 0 ? { mutations: config.mutations } : {}
|
|
16
|
+
};
|
|
17
|
+
return async (req, res) => {
|
|
18
|
+
if (req.method === "GET") {
|
|
19
|
+
res.json(await handleDiscovery(handlerConfig));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (req.method === "POST") {
|
|
23
|
+
const scope = config.getScope ? await config.getScope(req) : {};
|
|
24
|
+
const result = await handleQuery(handlerConfig, req.body, scope);
|
|
25
|
+
res.status(result.status).json(result.body);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (req.method === "PATCH") {
|
|
29
|
+
const fingerprint = fingerprintFromBody(req.body);
|
|
30
|
+
if (fingerprint === void 0) {
|
|
31
|
+
res.status(400).json({ error: "invalid_request", message: "Body must include { fingerprint }" });
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const wanted = req.body["protected"];
|
|
35
|
+
const result = await handleFingerprintPatch(handlerConfig, fingerprint, {
|
|
36
|
+
...typeof wanted === "boolean" ? { protected: wanted } : {}
|
|
37
|
+
});
|
|
38
|
+
res.status(result.status).json(result.body);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (req.method === "DELETE") {
|
|
42
|
+
const fingerprint = fingerprintFromBody(req.body);
|
|
43
|
+
if (fingerprint === void 0) {
|
|
44
|
+
res.status(400).json({ error: "invalid_request", message: "Body must include { fingerprint }" });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const result = await handleFingerprintDelete(handlerConfig, fingerprint);
|
|
48
|
+
res.status(result.status).json(result.body);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
res.status(405).json({
|
|
52
|
+
error: "method_not_allowed",
|
|
53
|
+
message: "GET discovery \xB7 POST query \xB7 PATCH/DELETE fingerprint management"
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export { vex };
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adapters/express/index.ts"],"names":[],"mappings":";;;;AAgCA,IAAM,mBAAA,GAAsB,CAAC,IAAA,KAAsC;AACjE,EAAA,IAAI,IAAA,KAAS,IAAA,IAAQ,OAAO,IAAA,KAAS,UAAU,OAAO,MAAA;AAC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AA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,iBAAA,EAAmB,OAAA,EAAS,mCAAA,EAAqC,CAAA;AAC/F,QAAA;AAAA,MACF;AACA,MAAA,MAAM,MAAA,GAAU,GAAA,CAAI,IAAA,CAAiC,WAAW,CAAA;AAChE,MAAA,MAAM,MAAA,GAAS,MAAM,sBAAA,CAAuB,aAAA,EAAe,WAAA,EAAa;AAAA,QACtE,GAAI,OAAO,MAAA,KAAW,SAAA,GAAY,EAAE,SAAA,EAAW,MAAA,KAAW;AAAC,OAC5D,CAAA;AACD,MAAA,GAAA,CAAI,OAAO,MAAA,CAAO,MAAM,CAAA,CAAE,IAAA,CAAK,OAAO,IAAI,CAAA;AAC1C,MAAA;AAAA,IACF;AAEA,IAAA,IAAI,GAAA,CAAI,WAAW,QAAA,EAAU;AAC3B,MAAA,MAAM,WAAA,GAAc,mBAAA,CAAoB,GAAA,CAAI,IAAI,CAAA;AAChD,MAAA,IAAI,gBAAgB,MAAA,EAAW;AAC7B,QAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,iBAAA,EAAmB,OAAA,EAAS,mCAAA,EAAqC,CAAA;AAC/F,QAAA;AAAA,MACF;AACA,MAAA,MAAM,MAAA,GAAS,MAAM,uBAAA,CAAwB,aAAA,EAAe,WAAW,CAAA;AACvE,MAAA,GAAA,CAAI,OAAO,MAAA,CAAO,MAAM,CAAA,CAAE,IAAA,CAAK,OAAO,IAAI,CAAA;AAC1C,MAAA;AAAA,IACF;AAEA,IAAA,GAAA,CAAI,MAAA,CAAO,GAAG,CAAA,CAAE,IAAA,CAAK;AAAA,MACnB,KAAA,EAAO,oBAAA;AAAA,MACP,OAAA,EAAS;AAAA,KACV,CAAA;AAAA,EACH,CAAA;AACF","file":"index.js","sourcesContent":["import type { QueryEngine } from '../../types.js';\nimport type { ScopeValues } from '../../scope/scope.types.js';\nimport type { VexHandlerConfig } from '../../handler.js';\nimport { handleDiscovery, handleQuery, handleFingerprintPatch, handleFingerprintDelete } from '../../handler.js';\n\n// Minimal structural types — Express.Request/Response satisfy these\n// without requiring express as a runtime dependency.\n\nexport type VexExpressRequest = {\n method: string;\n body: unknown;\n query: Record<string, unknown>;\n};\n\nexport type VexExpressResponse = {\n json(body: unknown): unknown;\n status(code: number): VexExpressResponse;\n};\n\nexport type VexExpressConfig<TReq extends VexExpressRequest = VexExpressRequest> = {\n engine: QueryEngine;\n entities?: string[];\n // Replay-only posture: no generation, no fingerprint management.\n // (Writes are unaffected — mutation replay is always replay-only.)\n locked?: boolean;\n getScope?: (req: TReq) => Promise<ScopeValues> | ScopeValues;\n // Enables replay of `kind: 'mutation'` cache entries on this endpoint.\n mutations?: VexHandlerConfig['mutations'];\n};\n\n// Fingerprints may contain '/' (named slots like \"deals/table\"), so\n// management rides the request BODY, not the path.\nconst fingerprintFromBody = (body: unknown): string | undefined => {\n if (body === null || typeof body !== 'object') return undefined;\n const fp = (body as Record<string, unknown>)['fingerprint'];\n return typeof fp === 'string' && fp.length > 0 ? fp : undefined;\n};\n\nexport const vex = <TReq extends VexExpressRequest = VexExpressRequest>(\n config: VexExpressConfig<TReq>,\n): ((req: TReq, res: VexExpressResponse) => Promise<void>) => {\n const handlerConfig = {\n engine: config.engine,\n entities: config.entities,\n ...(config.locked === true ? { locked: true } : {}),\n ...(config.mutations !== undefined ? { mutations: config.mutations } : {}),\n };\n\n return async (req: TReq, res: VexExpressResponse): Promise<void> => {\n if (req.method === 'GET') {\n res.json(await handleDiscovery(handlerConfig));\n return;\n }\n\n if (req.method === 'POST') {\n const scope = config.getScope ? await config.getScope(req) : {};\n const result = await handleQuery(handlerConfig, req.body, scope);\n res.status(result.status).json(result.body);\n return;\n }\n\n if (req.method === 'PATCH') {\n const fingerprint = fingerprintFromBody(req.body);\n if (fingerprint === undefined) {\n res.status(400).json({ error: 'invalid_request', message: 'Body must include { fingerprint }' });\n return;\n }\n const wanted = (req.body as Record<string, unknown>)['protected'];\n const result = await handleFingerprintPatch(handlerConfig, fingerprint, {\n ...(typeof wanted === 'boolean' ? { protected: wanted } : {}),\n });\n res.status(result.status).json(result.body);\n return;\n }\n\n if (req.method === 'DELETE') {\n const fingerprint = fingerprintFromBody(req.body);\n if (fingerprint === undefined) {\n res.status(400).json({ error: 'invalid_request', message: 'Body must include { fingerprint }' });\n return;\n }\n const result = await handleFingerprintDelete(handlerConfig, fingerprint);\n res.status(result.status).json(result.body);\n return;\n }\n\n res.status(405).json({\n error: 'method_not_allowed',\n message: 'GET discovery · POST query · PATCH/DELETE fingerprint management',\n });\n };\n};\n"]}
|