@hypequery/serve 0.19.2 → 0.19.3
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/adapters/node.d.ts.map +1 -1
- package/dist/adapters/node.js +12 -2
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +4 -1
- package/dist/utils/error-headers.d.ts +5 -0
- package/dist/utils/error-headers.d.ts.map +1 -0
- package/dist/utils/error-headers.js +15 -0
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/adapters/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,CAAC;AAG/E,OAAO,KAAK,EAEV,YAAY,EAGZ,kBAAkB,EACnB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/adapters/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,CAAC;AAG/E,OAAO,KAAK,EAEV,YAAY,EAGZ,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAoIrB,eAAO,MAAM,iBAAiB,GAC5B,SAAS,YAAY,EACrB,UAAS,kBAAuB,MAKlB,KAAK,eAAe,EAAE,KAAK,cAAc,kBAwCxD,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,SAAS,YAAY,EACrB,UAAS,kBAAuB;;gBA0BP,OAAO,CAAC,IAAI,CAAC;EAiEvC,CAAC"}
|
package/dist/adapters/node.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createServer } from "http";
|
|
2
2
|
import { once } from "node:events";
|
|
3
3
|
import { normalizeHeaders, parseQueryParams, parseRequestBody, serializeResponseBody, } from "./utils.js";
|
|
4
|
+
import { adapterErrorHeaders } from "../utils/error-headers.js";
|
|
4
5
|
const DEFAULT_REQUEST_TIMEOUT = 30_000; // 30 seconds
|
|
5
6
|
const DEFAULT_BODY_LIMIT = 1_048_576; // 1 MB
|
|
6
7
|
const DEFAULT_GRACEFUL_SHUTDOWN_TIMEOUT = 10_000; // 10 seconds
|
|
@@ -70,6 +71,7 @@ const sendError = (res, error) => {
|
|
|
70
71
|
error.code === "PAYLOAD_TOO_LARGE") {
|
|
71
72
|
sendResponse(res, {
|
|
72
73
|
status: 413,
|
|
74
|
+
headers: adapterErrorHeaders(),
|
|
73
75
|
body: {
|
|
74
76
|
error: {
|
|
75
77
|
type: "PAYLOAD_TOO_LARGE",
|
|
@@ -86,11 +88,18 @@ const sendError = (res, error) => {
|
|
|
86
88
|
body: {
|
|
87
89
|
error: {
|
|
88
90
|
type: "INTERNAL_SERVER_ERROR",
|
|
89
|
-
|
|
91
|
+
// Never the thrown message: an error escaping the pipeline can
|
|
92
|
+
// carry a stack, a file path, SQL, or a driver detail.
|
|
93
|
+
message: "An unexpected error occurred",
|
|
90
94
|
},
|
|
91
95
|
},
|
|
92
96
|
};
|
|
93
|
-
sendResponse(res,
|
|
97
|
+
sendResponse(res, {
|
|
98
|
+
...payload,
|
|
99
|
+
// A thrown response-shaped object is still an adapter error. These
|
|
100
|
+
// headers must override any supplied casing or value.
|
|
101
|
+
headers: adapterErrorHeaders(payload.headers),
|
|
102
|
+
});
|
|
94
103
|
};
|
|
95
104
|
export const createNodeHandler = (handler, options = {}) => {
|
|
96
105
|
const bodyLimit = options.bodyLimit ?? DEFAULT_BODY_LIMIT;
|
|
@@ -107,6 +116,7 @@ export const createNodeHandler = (handler, options = {}) => {
|
|
|
107
116
|
const timer = setTimeout(() => {
|
|
108
117
|
resolve({
|
|
109
118
|
status: 504,
|
|
119
|
+
headers: adapterErrorHeaders(),
|
|
110
120
|
body: {
|
|
111
121
|
error: {
|
|
112
122
|
type: "GATEWAY_TIMEOUT",
|
package/dist/pipeline.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAmB,MAAM,KAAK,CAAC;AAEzC,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EAKX,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,YAAY,EAGb,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAmB,MAAM,KAAK,CAAC;AAEzC,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,WAAW,EAKX,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,aAAa,EACb,YAAY,EAGb,MAAM,YAAY,CAAC;AAOpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAOrD,OAAO,EAAE,KAAK,kBAAkB,EAAqB,MAAM,WAAW,CAAC;AA6PvE,MAAM,WAAW,sBAAsB,CACrC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACxC,KAAK,SAAS,WAAW;IAEzB,QAAQ,EAAE,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IACnD,OAAO,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;IACtC,cAAc,CAAC,EAAE,mBAAmB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACtD,iBAAiB,EAAE,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC;IAChE,YAAY,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AE,OAAO,CAAC,EACxC,KAAK,SAAS,WAAW,EACzB,iIAUC,cAAc,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAG,YAkDpC,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,MAAM,MAAM,EACZ,cAAc,MAAM,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EACvD,UAAU,cAAc;;;;;;;;;;;;;;;;;;;;;CA8BzB,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAC7B,MAAM,MAAM,EACZ,aAAa,MAAM,EACnB,UAAU,WAAW;;;;;;;;;;;;;;;;;;;;;;;;CAyBmD,CAAC"}
|
package/dist/pipeline.js
CHANGED
|
@@ -2,6 +2,7 @@ import { z } from 'zod';
|
|
|
2
2
|
import { warnTenantMisconfiguration } from './tenant.js';
|
|
3
3
|
import { applySemanticTenantRuntime } from './semantic/utils/tenant-runtime.js';
|
|
4
4
|
import { generateRequestId, validateCorrelationId } from './utils.js';
|
|
5
|
+
import { withNoStoreErrorHeaders } from './utils/error-headers.js';
|
|
5
6
|
import { buildOpenApiDocument } from './openapi.js';
|
|
6
7
|
import { buildDocsHtml } from './docs-ui.js';
|
|
7
8
|
import { ServeHttpError } from './errors.js';
|
|
@@ -21,7 +22,9 @@ const safeInvokeHook = async (name, hook, payload) => {
|
|
|
21
22
|
};
|
|
22
23
|
const createErrorResponse = (status, type, message, details, headers) => ({
|
|
23
24
|
status,
|
|
24
|
-
|
|
25
|
+
// An error answers one request; a shared cache must never replay it to
|
|
26
|
+
// another caller. Matches the errors-v1 HTTP fixtures shared with Python.
|
|
27
|
+
headers: withNoStoreErrorHeaders(headers),
|
|
25
28
|
body: { error: { type, message, ...(details ? { details } : {}) } },
|
|
26
29
|
});
|
|
27
30
|
/**
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Override cache policy regardless of the supplied header casing. */
|
|
2
|
+
export declare function withNoStoreErrorHeaders(headers?: Record<string, string>): Record<string, string>;
|
|
3
|
+
/** Headers for errors answered by an adapter outside the request pipeline. */
|
|
4
|
+
export declare function adapterErrorHeaders(headers?: Record<string, string>): Record<string, string>;
|
|
5
|
+
//# sourceMappingURL=error-headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-headers.d.ts","sourceRoot":"","sources":["../../src/utils/error-headers.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { generateRequestId } from '../utils.js';
|
|
2
|
+
/** Override cache policy regardless of the supplied header casing. */
|
|
3
|
+
export function withNoStoreErrorHeaders(headers = {}) {
|
|
4
|
+
return {
|
|
5
|
+
...Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== 'cache-control')),
|
|
6
|
+
'cache-control': 'no-store',
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/** Headers for errors answered by an adapter outside the request pipeline. */
|
|
10
|
+
export function adapterErrorHeaders(headers = {}) {
|
|
11
|
+
return {
|
|
12
|
+
...withNoStoreErrorHeaders(Object.fromEntries(Object.entries(headers).filter(([name]) => name.toLowerCase() !== 'x-request-id'))),
|
|
13
|
+
'x-request-id': generateRequestId(),
|
|
14
|
+
};
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/serve",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.3",
|
|
4
4
|
"description": "Code-first TypeScript runtime for validated ClickHouse analytics APIs, OpenAPI, auth, and tenancy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clickhouse",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"jose": "^5.9.6",
|
|
38
38
|
"openapi-typescript": "^7.13.0",
|
|
39
39
|
"zod": "^3.23.8",
|
|
40
|
-
"zod-to-json-schema": "^3.
|
|
41
|
-
"@hypequery/datasets": "^0.
|
|
40
|
+
"zod-to-json-schema": "^3.25.2",
|
|
41
|
+
"@hypequery/datasets": "^0.21.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"tsx": "^4.0.0",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/node": "^20.11.30",
|
|
57
|
-
"@vitest/coverage-v8": "^
|
|
58
|
-
"tsx": "^4.
|
|
57
|
+
"@vitest/coverage-v8": "^5.0.2",
|
|
58
|
+
"tsx": "^4.23.15",
|
|
59
59
|
"typescript": "^5.7.3",
|
|
60
|
-
"vitest": "^
|
|
60
|
+
"vitest": "^5.0.2"
|
|
61
61
|
},
|
|
62
62
|
"repository": {
|
|
63
63
|
"type": "git",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"scripts": {
|
|
75
75
|
"build": "tsc --project tsconfig.json",
|
|
76
76
|
"dev": "tsc --project tsconfig.json --watch",
|
|
77
|
-
"lint": "eslint
|
|
77
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
78
78
|
"test:integration": "vitest run --config vitest.integration.config.ts",
|
|
79
79
|
"test:types": "tsc --project tsconfig.type-tests.json",
|
|
80
80
|
"test": "npm run test:types && vitest run",
|