@milaboratories/pframes-rs-serv 1.1.2 → 1.1.4
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/bin/parquet-server.mjs +2 -2
- package/dist/export.cjs +1 -1
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.ts +1 -1
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +1 -1
- package/dist/export.js.map +1 -1
- package/dist/fs-store.cjs +18 -20
- package/dist/fs-store.cjs.map +1 -1
- package/dist/fs-store.d.ts +1 -1
- package/dist/fs-store.d.ts.map +1 -1
- package/dist/fs-store.js +18 -20
- package/dist/fs-store.js.map +1 -1
- package/dist/handler.cjs +5 -5
- package/dist/handler.cjs.map +1 -1
- package/dist/handler.d.ts +2 -2
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +5 -5
- package/dist/handler.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/parquet-server.cjs +19 -19
- package/dist/parquet-server.cjs.map +1 -1
- package/dist/parquet-server.d.ts +1 -1
- package/dist/parquet-server.d.ts.map +1 -1
- package/dist/parquet-server.js +19 -19
- package/dist/parquet-server.js.map +1 -1
- package/dist/serve.cjs +20 -20
- package/dist/serve.cjs.map +1 -1
- package/dist/serve.d.ts +2 -2
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +20 -20
- package/dist/serve.js.map +1 -1
- package/dist/utils/etag.cjs +1 -1
- package/dist/utils/etag.cjs.map +1 -1
- package/dist/utils/etag.d.ts +3 -3
- package/dist/utils/etag.js +1 -1
- package/dist/utils/etag.js.map +1 -1
- package/dist/utils/filename.cjs.map +1 -1
- package/dist/utils/filename.d.ts +2 -2
- package/dist/utils/filename.js.map +1 -1
- package/dist/utils/headers.cjs +17 -17
- package/dist/utils/headers.cjs.map +1 -1
- package/dist/utils/headers.js +17 -17
- package/dist/utils/headers.js.map +1 -1
- package/dist/utils/index.d.ts +7 -7
- package/dist/utils/method.cjs +3 -3
- package/dist/utils/method.cjs.map +1 -1
- package/dist/utils/method.d.ts +5 -5
- package/dist/utils/method.js +3 -3
- package/dist/utils/method.js.map +1 -1
- package/dist/utils/options.cjs +10 -10
- package/dist/utils/options.cjs.map +1 -1
- package/dist/utils/options.d.ts +2 -2
- package/dist/utils/options.d.ts.map +1 -1
- package/dist/utils/options.js +10 -10
- package/dist/utils/options.js.map +1 -1
- package/dist/utils/range.cjs +4 -4
- package/dist/utils/range.cjs.map +1 -1
- package/dist/utils/range.d.ts +2 -2
- package/dist/utils/range.d.ts.map +1 -1
- package/dist/utils/range.js +4 -4
- package/dist/utils/range.js.map +1 -1
- package/dist/utils/status.cjs +1 -1
- package/dist/utils/status.cjs.map +1 -1
- package/dist/utils/status.js +1 -1
- package/dist/utils/status.js.map +1 -1
- package/package.json +26 -27
- package/src/export.ts +9 -11
- package/src/fs-store.ts +32 -43
- package/src/handler.ts +20 -28
- package/src/index.ts +5 -5
- package/src/parquet-server.ts +33 -37
- package/src/serve.ts +33 -49
- package/src/utils/etag.ts +4 -4
- package/src/utils/filename.ts +3 -3
- package/src/utils/headers.ts +24 -24
- package/src/utils/index.ts +7 -7
- package/src/utils/method.ts +10 -10
- package/src/utils/options.ts +14 -18
- package/src/utils/range.ts +7 -9
- package/src/utils/status.ts +1 -1
package/bin/parquet-server.mjs
CHANGED
package/dist/export.cjs
CHANGED
package/dist/export.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.cjs","sources":["../src/export.ts"],"sourcesContent":["import type { RequestListener } from
|
|
1
|
+
{"version":3,"file":"export.cjs","sources":["../src/export.ts"],"sourcesContent":["import type { RequestListener } from \"node:http\";\nimport { FileSystemStore } from \"./fs-store\";\nimport { createRequestHandler } from \"./handler\";\nimport { serve } from \"./serve\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\n\nexport const HttpHelpers: PFrameInternal.HttpHelpers = {\n createFsStore: async (\n options: PFrameInternal.FsStoreOptions,\n ): Promise<PFrameInternal.ObjectStore> => {\n return await FileSystemStore.init(options);\n },\n createRequestHandler: (options: PFrameInternal.RequestHandlerOptions): RequestListener => {\n return createRequestHandler(options);\n },\n createHttpServer: async (\n options: PFrameInternal.HttpServerOptions,\n ): Promise<PFrameInternal.HttpServer> => {\n return await serve(options);\n },\n};\n"],"names":["FileSystemStore","createRequestHandler","serve"],"mappings":";;;;;;AAMO,MAAM,WAAW,GAA+B;AACrD,IAAA,aAAa,EAAE,OACb,OAAsC,KACC;AACvC,QAAA,OAAO,MAAMA,uBAAe,CAAC,IAAI,CAAC,OAAO,CAAC;IAC5C,CAAC;AACD,IAAA,oBAAoB,EAAE,CAAC,OAA6C,KAAqB;AACvF,QAAA,OAAOC,4BAAoB,CAAC,OAAO,CAAC;IACtC,CAAC;AACD,IAAA,gBAAgB,EAAE,OAChB,OAAyC,KACH;AACtC,QAAA,OAAO,MAAMC,WAAK,CAAC,OAAO,CAAC;IAC7B,CAAC;;;;;"}
|
package/dist/export.d.ts
CHANGED
package/dist/export.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAE5E,eAAO,MAAM,WAAW,EAAE,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../src/export.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAE5E,eAAO,MAAM,WAAW,EAAE,cAAc,CAAC,WAcxC,CAAC"}
|
package/dist/export.js
CHANGED
package/dist/export.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","sources":["../src/export.ts"],"sourcesContent":["import type { RequestListener } from
|
|
1
|
+
{"version":3,"file":"export.js","sources":["../src/export.ts"],"sourcesContent":["import type { RequestListener } from \"node:http\";\nimport { FileSystemStore } from \"./fs-store\";\nimport { createRequestHandler } from \"./handler\";\nimport { serve } from \"./serve\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\n\nexport const HttpHelpers: PFrameInternal.HttpHelpers = {\n createFsStore: async (\n options: PFrameInternal.FsStoreOptions,\n ): Promise<PFrameInternal.ObjectStore> => {\n return await FileSystemStore.init(options);\n },\n createRequestHandler: (options: PFrameInternal.RequestHandlerOptions): RequestListener => {\n return createRequestHandler(options);\n },\n createHttpServer: async (\n options: PFrameInternal.HttpServerOptions,\n ): Promise<PFrameInternal.HttpServer> => {\n return await serve(options);\n },\n};\n"],"names":[],"mappings":";;;;AAMO,MAAM,WAAW,GAA+B;AACrD,IAAA,aAAa,EAAE,OACb,OAAsC,KACC;AACvC,QAAA,OAAO,MAAM,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC;IAC5C,CAAC;AACD,IAAA,oBAAoB,EAAE,CAAC,OAA6C,KAAqB;AACvF,QAAA,OAAO,oBAAoB,CAAC,OAAO,CAAC;IACtC,CAAC;AACD,IAAA,gBAAgB,EAAE,OAChB,OAAyC,KACH;AACtC,QAAA,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC;IAC7B,CAAC;;;;;"}
|
package/dist/fs-store.cjs
CHANGED
|
@@ -22,29 +22,27 @@ class FileSystemStore extends plModelMiddleLayer.PFrameInternal.BaseObjectStore
|
|
|
22
22
|
}
|
|
23
23
|
return new FileSystemStore({
|
|
24
24
|
...options,
|
|
25
|
-
rootDir: resolvedRootDir
|
|
25
|
+
rootDir: resolvedRootDir,
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
async request(filename, params) {
|
|
29
29
|
let file;
|
|
30
30
|
const respond = async (response) => {
|
|
31
31
|
try {
|
|
32
|
-
await params
|
|
33
|
-
.callback(response)
|
|
34
|
-
.finally(async () => await file?.close());
|
|
32
|
+
await params.callback(response).finally(async () => await file?.close());
|
|
35
33
|
}
|
|
36
34
|
catch (error) {
|
|
37
|
-
this.logger(
|
|
35
|
+
this.logger("warn", `File system store received unexpected rejection from callback: ${plModelCommon.ensureError(error)}`);
|
|
38
36
|
}
|
|
39
37
|
};
|
|
40
38
|
try {
|
|
41
39
|
try {
|
|
42
40
|
const path = node_path.join(this.rootDir, filename);
|
|
43
|
-
file = await promises.open(path,
|
|
41
|
+
file = await promises.open(path, "r");
|
|
44
42
|
}
|
|
45
43
|
catch (error) {
|
|
46
|
-
this.logger(
|
|
47
|
-
return await respond({ type:
|
|
44
|
+
this.logger("error", `File system store failed to open file ${filename}: ${plModelCommon.ensureError(error)}`);
|
|
45
|
+
return await respond({ type: "NotFound" });
|
|
48
46
|
}
|
|
49
47
|
params.signal.throwIfAborted();
|
|
50
48
|
let size;
|
|
@@ -52,37 +50,37 @@ class FileSystemStore extends plModelMiddleLayer.PFrameInternal.BaseObjectStore
|
|
|
52
50
|
({ size } = await file.stat());
|
|
53
51
|
}
|
|
54
52
|
catch (error) {
|
|
55
|
-
this.logger(
|
|
56
|
-
return await respond({ type:
|
|
53
|
+
this.logger("error", `File system store failed to get size of file ${filename}: ${plModelCommon.ensureError(error)}`);
|
|
54
|
+
return await respond({ type: "InternalError" });
|
|
57
55
|
}
|
|
58
56
|
params.signal.throwIfAborted();
|
|
59
57
|
const range = this.translate(size, params.range);
|
|
60
58
|
if (!range) {
|
|
61
|
-
return await respond({ type:
|
|
59
|
+
return await respond({ type: "RangeNotSatisfiable", size });
|
|
62
60
|
}
|
|
63
|
-
if (params.method ===
|
|
64
|
-
return await respond({ type:
|
|
61
|
+
if (params.method === "HEAD") {
|
|
62
|
+
return await respond({ type: "Ok", size, range });
|
|
65
63
|
}
|
|
66
64
|
let data;
|
|
67
65
|
try {
|
|
68
66
|
data = file.createReadStream({
|
|
69
67
|
start: range.start,
|
|
70
68
|
end: range.end,
|
|
71
|
-
autoClose: false
|
|
69
|
+
autoClose: false,
|
|
72
70
|
});
|
|
73
|
-
this.logger(
|
|
71
|
+
this.logger("info", `File system store created read stream for ${filename}[${range.start}..=${range.end}]`);
|
|
74
72
|
}
|
|
75
73
|
catch (error) {
|
|
76
|
-
this.logger(
|
|
77
|
-
return await respond({ type:
|
|
74
|
+
this.logger("error", `File system store failed to create read stream for ${filename}[${range.start}..=${range.end}]: ${plModelCommon.ensureError(error)}`);
|
|
75
|
+
return await respond({ type: "InternalError" });
|
|
78
76
|
}
|
|
79
|
-
return await respond({ type:
|
|
77
|
+
return await respond({ type: "Ok", size, range, data });
|
|
80
78
|
}
|
|
81
79
|
catch (error) {
|
|
82
80
|
if (!plModelCommon.isAbortError(error)) {
|
|
83
|
-
this.logger(
|
|
81
|
+
this.logger("warn", `File system store unhandled error: ${plModelCommon.ensureError(error)}`);
|
|
84
82
|
}
|
|
85
|
-
return await respond({ type:
|
|
83
|
+
return await respond({ type: "InternalError" });
|
|
86
84
|
}
|
|
87
85
|
}
|
|
88
86
|
}
|
package/dist/fs-store.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-store.cjs","sources":["../src/fs-store.ts"],"sourcesContent":["import type { Readable } from
|
|
1
|
+
{"version":3,"file":"fs-store.cjs","sources":["../src/fs-store.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport { stat, open, type FileHandle } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport { ensureError, isAbortError } from \"@milaboratories/pl-model-common\";\n\n/** Object store for serving files from a local directory */\nexport class FileSystemStore extends PFrameInternal.BaseObjectStore {\n private readonly rootDir: string;\n\n private constructor(options: PFrameInternal.FsStoreOptions) {\n super(options);\n\n this.rootDir = options.rootDir;\n }\n\n static async init(options: PFrameInternal.FsStoreOptions): Promise<FileSystemStore> {\n const resolvedRootDir = resolve(options.rootDir);\n\n const rootStats = await stat(resolvedRootDir).catch(() => {\n throw new Error(`File system store root directory does not exist: ${resolvedRootDir}`);\n });\n if (!rootStats.isDirectory()) {\n throw new Error(`File system store root path is not a directory: ${resolvedRootDir}`);\n }\n\n return new FileSystemStore({\n ...options,\n rootDir: resolvedRootDir,\n });\n }\n\n override async request(\n filename: PFrameInternal.ParquetFileName,\n params: {\n method: PFrameInternal.HttpMethod;\n range?: PFrameInternal.HttpRange;\n signal: AbortSignal;\n callback: (response: PFrameInternal.ObjectStoreResponse) => Promise<void>;\n },\n ): Promise<void> {\n let file: FileHandle | undefined;\n const respond = async (response: PFrameInternal.ObjectStoreResponse) => {\n try {\n await params.callback(response).finally(async () => await file?.close());\n } catch (error: unknown) {\n this.logger(\n \"warn\",\n `File system store received unexpected rejection from callback: ${ensureError(error)}`,\n );\n }\n };\n\n try {\n try {\n const path = join(this.rootDir, filename);\n file = await open(path, \"r\");\n } catch (error: unknown) {\n this.logger(\n \"error\",\n `File system store failed to open file ${filename}: ${ensureError(error)}`,\n );\n return await respond({ type: \"NotFound\" });\n }\n params.signal.throwIfAborted();\n\n let size: number;\n try {\n ({ size } = await file.stat());\n } catch (error: unknown) {\n this.logger(\n \"error\",\n `File system store failed to get size of file ${filename}: ${ensureError(error)}`,\n );\n return await respond({ type: \"InternalError\" });\n }\n params.signal.throwIfAborted();\n\n const range = this.translate(size, params.range);\n if (!range) {\n return await respond({ type: \"RangeNotSatisfiable\", size });\n }\n\n if (params.method === \"HEAD\") {\n return await respond({ type: \"Ok\", size, range });\n }\n\n let data: Readable;\n try {\n data = file.createReadStream({\n start: range.start,\n end: range.end,\n autoClose: false,\n });\n this.logger(\n \"info\",\n `File system store created read stream for ${filename}[${range.start}..=${range.end}]`,\n );\n } catch (error: unknown) {\n this.logger(\n \"error\",\n `File system store failed to create read stream for ${filename}[${range.start}..=${range.end}]: ${ensureError(error)}`,\n );\n return await respond({ type: \"InternalError\" });\n }\n\n return await respond({ type: \"Ok\", size, range, data });\n } catch (error: unknown) {\n if (!isAbortError(error)) {\n this.logger(\"warn\", `File system store unhandled error: ${ensureError(error)}`);\n }\n return await respond({ type: \"InternalError\" });\n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;AAClB,YAAA,IAAI;AACF,gBAAA,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC;oBAC3B,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,GAAG,EAAE,KAAK,CAAC,GAAG;AACd,oBAAA,SAAS,EAAE,KAAK;AACjB,iBAAA,CAAC;AACF,gBAAA,IAAI,CAAC,MAAM,CACT,MAAM,EACN,6CAA6C,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAC,KAAK,CAAA,GAAA,EAAM,KAAK,CAAC,GAAG,CAAA,CAAA,CAAG,CACvF;YACH;YAAE,OAAO,KAAc,EAAE;gBACvB,IAAI,CAAC,MAAM,CACT,OAAO,EACP,CAAA,mDAAA,EAAsD,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,GAAG,CAAA,GAAA,EAAMA,yBAAW,CAAC,KAAK,CAAC,CAAA,CAAE,CACvH;gBACD,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;YACjD;AAEA,YAAA,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzD;QAAE,OAAO,KAAc,EAAE;AACvB,YAAA,IAAI,CAACG,0BAAY,CAAC,KAAK,CAAC,EAAE;AACxB,gBAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA,mCAAA,EAAsCH,yBAAW,CAAC,KAAK,CAAC,CAAA,CAAE,CAAC;YACjF;YACA,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;QACjD;IACF;AACD;;;;"}
|
package/dist/fs-store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PFrameInternal } from
|
|
1
|
+
import { PFrameInternal } from "@milaboratories/pl-model-middle-layer";
|
|
2
2
|
/** Object store for serving files from a local directory */
|
|
3
3
|
export declare class FileSystemStore extends PFrameInternal.BaseObjectStore {
|
|
4
4
|
private readonly rootDir;
|
package/dist/fs-store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-store.d.ts","sourceRoot":"","sources":["../src/fs-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGvE,4DAA4D;AAC5D,qBAAa,eAAgB,SAAQ,cAAc,CAAC,eAAe;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO;WAMM,IAAI,
|
|
1
|
+
{"version":3,"file":"fs-store.d.ts","sourceRoot":"","sources":["../src/fs-store.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGvE,4DAA4D;AAC5D,qBAAa,eAAgB,SAAQ,cAAc,CAAC,eAAe;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC,OAAO;WAMM,IAAI,CAAC,OAAO,EAAE,cAAc,CAAC,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAgBpE,OAAO,CACpB,QAAQ,EAAE,cAAc,CAAC,eAAe,EACxC,MAAM,EAAE;QACN,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC;QAClC,KAAK,CAAC,EAAE,cAAc,CAAC,SAAS,CAAC;QACjC,MAAM,EAAE,WAAW,CAAC;QACpB,QAAQ,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;KAC3E,GACA,OAAO,CAAC,IAAI,CAAC;CA0EjB"}
|
package/dist/fs-store.js
CHANGED
|
@@ -20,29 +20,27 @@ class FileSystemStore extends PFrameInternal.BaseObjectStore {
|
|
|
20
20
|
}
|
|
21
21
|
return new FileSystemStore({
|
|
22
22
|
...options,
|
|
23
|
-
rootDir: resolvedRootDir
|
|
23
|
+
rootDir: resolvedRootDir,
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
async request(filename, params) {
|
|
27
27
|
let file;
|
|
28
28
|
const respond = async (response) => {
|
|
29
29
|
try {
|
|
30
|
-
await params
|
|
31
|
-
.callback(response)
|
|
32
|
-
.finally(async () => await file?.close());
|
|
30
|
+
await params.callback(response).finally(async () => await file?.close());
|
|
33
31
|
}
|
|
34
32
|
catch (error) {
|
|
35
|
-
this.logger(
|
|
33
|
+
this.logger("warn", `File system store received unexpected rejection from callback: ${ensureError(error)}`);
|
|
36
34
|
}
|
|
37
35
|
};
|
|
38
36
|
try {
|
|
39
37
|
try {
|
|
40
38
|
const path = join(this.rootDir, filename);
|
|
41
|
-
file = await open(path,
|
|
39
|
+
file = await open(path, "r");
|
|
42
40
|
}
|
|
43
41
|
catch (error) {
|
|
44
|
-
this.logger(
|
|
45
|
-
return await respond({ type:
|
|
42
|
+
this.logger("error", `File system store failed to open file ${filename}: ${ensureError(error)}`);
|
|
43
|
+
return await respond({ type: "NotFound" });
|
|
46
44
|
}
|
|
47
45
|
params.signal.throwIfAborted();
|
|
48
46
|
let size;
|
|
@@ -50,37 +48,37 @@ class FileSystemStore extends PFrameInternal.BaseObjectStore {
|
|
|
50
48
|
({ size } = await file.stat());
|
|
51
49
|
}
|
|
52
50
|
catch (error) {
|
|
53
|
-
this.logger(
|
|
54
|
-
return await respond({ type:
|
|
51
|
+
this.logger("error", `File system store failed to get size of file ${filename}: ${ensureError(error)}`);
|
|
52
|
+
return await respond({ type: "InternalError" });
|
|
55
53
|
}
|
|
56
54
|
params.signal.throwIfAborted();
|
|
57
55
|
const range = this.translate(size, params.range);
|
|
58
56
|
if (!range) {
|
|
59
|
-
return await respond({ type:
|
|
57
|
+
return await respond({ type: "RangeNotSatisfiable", size });
|
|
60
58
|
}
|
|
61
|
-
if (params.method ===
|
|
62
|
-
return await respond({ type:
|
|
59
|
+
if (params.method === "HEAD") {
|
|
60
|
+
return await respond({ type: "Ok", size, range });
|
|
63
61
|
}
|
|
64
62
|
let data;
|
|
65
63
|
try {
|
|
66
64
|
data = file.createReadStream({
|
|
67
65
|
start: range.start,
|
|
68
66
|
end: range.end,
|
|
69
|
-
autoClose: false
|
|
67
|
+
autoClose: false,
|
|
70
68
|
});
|
|
71
|
-
this.logger(
|
|
69
|
+
this.logger("info", `File system store created read stream for ${filename}[${range.start}..=${range.end}]`);
|
|
72
70
|
}
|
|
73
71
|
catch (error) {
|
|
74
|
-
this.logger(
|
|
75
|
-
return await respond({ type:
|
|
72
|
+
this.logger("error", `File system store failed to create read stream for ${filename}[${range.start}..=${range.end}]: ${ensureError(error)}`);
|
|
73
|
+
return await respond({ type: "InternalError" });
|
|
76
74
|
}
|
|
77
|
-
return await respond({ type:
|
|
75
|
+
return await respond({ type: "Ok", size, range, data });
|
|
78
76
|
}
|
|
79
77
|
catch (error) {
|
|
80
78
|
if (!isAbortError(error)) {
|
|
81
|
-
this.logger(
|
|
79
|
+
this.logger("warn", `File system store unhandled error: ${ensureError(error)}`);
|
|
82
80
|
}
|
|
83
|
-
return await respond({ type:
|
|
81
|
+
return await respond({ type: "InternalError" });
|
|
84
82
|
}
|
|
85
83
|
}
|
|
86
84
|
}
|
package/dist/fs-store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-store.js","sources":["../src/fs-store.ts"],"sourcesContent":["import type { Readable } from
|
|
1
|
+
{"version":3,"file":"fs-store.js","sources":["../src/fs-store.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport { stat, open, type FileHandle } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport { ensureError, isAbortError } from \"@milaboratories/pl-model-common\";\n\n/** Object store for serving files from a local directory */\nexport class FileSystemStore extends PFrameInternal.BaseObjectStore {\n private readonly rootDir: string;\n\n private constructor(options: PFrameInternal.FsStoreOptions) {\n super(options);\n\n this.rootDir = options.rootDir;\n }\n\n static async init(options: PFrameInternal.FsStoreOptions): Promise<FileSystemStore> {\n const resolvedRootDir = resolve(options.rootDir);\n\n const rootStats = await stat(resolvedRootDir).catch(() => {\n throw new Error(`File system store root directory does not exist: ${resolvedRootDir}`);\n });\n if (!rootStats.isDirectory()) {\n throw new Error(`File system store root path is not a directory: ${resolvedRootDir}`);\n }\n\n return new FileSystemStore({\n ...options,\n rootDir: resolvedRootDir,\n });\n }\n\n override async request(\n filename: PFrameInternal.ParquetFileName,\n params: {\n method: PFrameInternal.HttpMethod;\n range?: PFrameInternal.HttpRange;\n signal: AbortSignal;\n callback: (response: PFrameInternal.ObjectStoreResponse) => Promise<void>;\n },\n ): Promise<void> {\n let file: FileHandle | undefined;\n const respond = async (response: PFrameInternal.ObjectStoreResponse) => {\n try {\n await params.callback(response).finally(async () => await file?.close());\n } catch (error: unknown) {\n this.logger(\n \"warn\",\n `File system store received unexpected rejection from callback: ${ensureError(error)}`,\n );\n }\n };\n\n try {\n try {\n const path = join(this.rootDir, filename);\n file = await open(path, \"r\");\n } catch (error: unknown) {\n this.logger(\n \"error\",\n `File system store failed to open file ${filename}: ${ensureError(error)}`,\n );\n return await respond({ type: \"NotFound\" });\n }\n params.signal.throwIfAborted();\n\n let size: number;\n try {\n ({ size } = await file.stat());\n } catch (error: unknown) {\n this.logger(\n \"error\",\n `File system store failed to get size of file ${filename}: ${ensureError(error)}`,\n );\n return await respond({ type: \"InternalError\" });\n }\n params.signal.throwIfAborted();\n\n const range = this.translate(size, params.range);\n if (!range) {\n return await respond({ type: \"RangeNotSatisfiable\", size });\n }\n\n if (params.method === \"HEAD\") {\n return await respond({ type: \"Ok\", size, range });\n }\n\n let data: Readable;\n try {\n data = file.createReadStream({\n start: range.start,\n end: range.end,\n autoClose: false,\n });\n this.logger(\n \"info\",\n `File system store created read stream for ${filename}[${range.start}..=${range.end}]`,\n );\n } catch (error: unknown) {\n this.logger(\n \"error\",\n `File system store failed to create read stream for ${filename}[${range.start}..=${range.end}]: ${ensureError(error)}`,\n );\n return await respond({ type: \"InternalError\" });\n }\n\n return await respond({ type: \"Ok\", size, range, data });\n } catch (error: unknown) {\n if (!isAbortError(error)) {\n this.logger(\"warn\", `File system store unhandled error: ${ensureError(error)}`);\n }\n return await respond({ type: \"InternalError\" });\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAMA;AACM,MAAO,eAAgB,SAAQ,cAAc,CAAC,eAAe,CAAA;AAChD,IAAA,OAAO;AAExB,IAAA,WAAA,CAAoB,OAAsC,EAAA;QACxD,KAAK,CAAC,OAAO,CAAC;AAEd,QAAA,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO;IAChC;AAEA,IAAA,aAAa,IAAI,CAAC,OAAsC,EAAA;QACtD,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;QAEhD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,CAAC,KAAK,CAAC,MAAK;AACvD,YAAA,MAAM,IAAI,KAAK,CAAC,oDAAoD,eAAe,CAAA,CAAE,CAAC;AACxF,QAAA,CAAC,CAAC;AACF,QAAA,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE;AAC5B,YAAA,MAAM,IAAI,KAAK,CAAC,mDAAmD,eAAe,CAAA,CAAE,CAAC;QACvF;QAEA,OAAO,IAAI,eAAe,CAAC;AACzB,YAAA,GAAG,OAAO;AACV,YAAA,OAAO,EAAE,eAAe;AACzB,SAAA,CAAC;IACJ;AAES,IAAA,MAAM,OAAO,CACpB,QAAwC,EACxC,MAKC,EAAA;AAED,QAAA,IAAI,IAA4B;AAChC,QAAA,MAAM,OAAO,GAAG,OAAO,QAA4C,KAAI;AACrE,YAAA,IAAI;AACF,gBAAA,MAAM,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,YAAY,MAAM,IAAI,EAAE,KAAK,EAAE,CAAC;YAC1E;YAAE,OAAO,KAAc,EAAE;AACvB,gBAAA,IAAI,CAAC,MAAM,CACT,MAAM,EACN,CAAA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EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;YACnD;AAEA,YAAA,IAAI,IAAc;AAClB,YAAA,IAAI;AACF,gBAAA,IAAI,GAAG,IAAI,CAAC,gBAAgB,CAAC;oBAC3B,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,GAAG,EAAE,KAAK,CAAC,GAAG;AACd,oBAAA,SAAS,EAAE,KAAK;AACjB,iBAAA,CAAC;AACF,gBAAA,IAAI,CAAC,MAAM,CACT,MAAM,EACN,6CAA6C,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAC,KAAK,CAAA,GAAA,EAAM,KAAK,CAAC,GAAG,CAAA,CAAA,CAAG,CACvF;YACH;YAAE,OAAO,KAAc,EAAE;gBACvB,IAAI,CAAC,MAAM,CACT,OAAO,EACP,CAAA,mDAAA,EAAsD,QAAQ,CAAA,CAAA,EAAI,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,GAAG,CAAA,GAAA,EAAM,WAAW,CAAC,KAAK,CAAC,CAAA,CAAE,CACvH;gBACD,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;YACjD;AAEA,YAAA,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;QACzD;QAAE,OAAO,KAAc,EAAE;AACvB,YAAA,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;AACxB,gBAAA,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA,mCAAA,EAAsC,WAAW,CAAC,KAAK,CAAC,CAAA,CAAE,CAAC;YACjF;YACA,OAAO,MAAM,OAAO,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;QACjD;IACF;AACD;;;;"}
|
package/dist/handler.cjs
CHANGED
|
@@ -58,7 +58,7 @@ function handleRequest(request, response, store) {
|
|
|
58
58
|
return void response.writeHead(status.StatusCode.BadRequest).end();
|
|
59
59
|
}
|
|
60
60
|
const abortController = new AbortController();
|
|
61
|
-
request.on(
|
|
61
|
+
request.on("close", () => abortController.abort());
|
|
62
62
|
const signal = abortController.signal;
|
|
63
63
|
store.request(filename$1, {
|
|
64
64
|
method: method$1,
|
|
@@ -80,13 +80,13 @@ function handleRequest(request, response, store) {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
switch (result.type) {
|
|
83
|
-
case
|
|
83
|
+
case "InternalError":
|
|
84
84
|
// object store encountered network error, retry by client can help
|
|
85
85
|
return void response.writeHead(status.StatusCode.InternalServerError).end();
|
|
86
|
-
case
|
|
86
|
+
case "NotFound":
|
|
87
87
|
// RFC 9110 section 15.4.5: Not found
|
|
88
88
|
return void response.writeHead(status.StatusCode.NotFound).end();
|
|
89
|
-
case
|
|
89
|
+
case "RangeNotSatisfiable":
|
|
90
90
|
// RFC 9110 section 15.5.17: Range not satisfiable
|
|
91
91
|
response.setHeader(headers.HeaderName.ContentRange, `bytes */${result.size}`);
|
|
92
92
|
return void response.writeHead(status.StatusCode.RangeNotSatisfiable).end();
|
|
@@ -117,7 +117,7 @@ function handleRequest(request, response, store) {
|
|
|
117
117
|
if (!plModelCommon.isAbortError(error))
|
|
118
118
|
throw error;
|
|
119
119
|
}
|
|
120
|
-
}
|
|
120
|
+
},
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
/**
|
package/dist/handler.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.cjs","sources":["../src/handler.ts"],"sourcesContent":["import type {\n IncomingMessage,\n RequestListener,\n ServerResponse\n} from 'node:http';\nimport { pipeline } from 'node:stream/promises';\nimport { timingSafeEqual } from 'node:crypto';\nimport type { PFrameInternal } from '@milaboratories/pl-model-middle-layer';\nimport {\n createETag,\n getFilenameFromUrl,\n parseRange,\n isGetOrHead,\n isGet,\n isHead,\n Options,\n StatusCode,\n HeaderName,\n HeaderValue\n} from './utils';\nimport { isAbortError } from '@milaboratories/pl-model-common';\n\n/** Main request handler for parquet files */\nfunction handleRequest(\n request: IncomingMessage,\n response: ServerResponse,\n store: PFrameInternal.ObjectStore\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n\n // RFC 9110 section 15.5.6: Method not allowed\n const method = request.method;\n if (!isGetOrHead(method)) {\n response.setHeader(HeaderName.Allow, HeaderValue.Allow);\n return void response.writeHead(StatusCode.MethodNotAllowed).end();\n }\n\n const filename = getFilenameFromUrl(request);\n if (filename === null) {\n return void response.writeHead(StatusCode.Gone).end();\n }\n\n // From now on we are sure that the response would be a Parquet file\n response.setHeader(HeaderName.AcceptRanges, HeaderValue.AcceptRanges);\n response.setHeader(HeaderName.ContentType, HeaderValue.ContentType);\n\n // RFC 9110 section 8.8.3: ETag header is used for cache versioning\n const etag = createETag(filename);\n // RFC 9110 section 8.8.2: Last-Modified header field for cache validation\n const mtime = new Date(0); // Using fake fixed date since files are immutable\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n response.setHeader(HeaderName.ETag, etag);\n response.setHeader(HeaderName.LastModified, mtime.toUTCString());\n\n const options = new Options(request);\n // RFC 9110 section 13.1.1: If-Match precondition evaluation\n // RFC 9110 section 13.1.4: If-Unmodified-Since precondition evaluation\n if (options.preconditionFailed(etag, mtime)) {\n return void response.writeHead(StatusCode.PreconditionFailed).end();\n }\n // RFC 9110 section 13.1.2: If-None-Match precondition evaluation\n // RFC 9110 section 13.1.3: If-Modified-Since precondition evaluation\n else if (options.notModified(etag, mtime)) {\n return void response.writeHead(StatusCode.NotModified).end();\n }\n\n const range = parseRange(request);\n if (range === null) {\n return void response.writeHead(StatusCode.BadRequest).end();\n }\n\n const abortController = new AbortController();\n request.on('close', () => abortController.abort());\n const signal = abortController.signal;\n\n store.request(filename, {\n method,\n range,\n signal,\n // pipeline automatically destroys the streams if they were not gracefully closed\n callback: async (result) => {\n if (request.destroyed) {\n // request has timed out, close the connection\n if (response.destroyed) {\n return;\n } else if (response.headersSent) {\n return void response.end();\n } else {\n response.setHeader(HeaderName.Connection, HeaderValue.Connection);\n return void response.writeHead(StatusCode.RequestTimeout).end();\n }\n }\n\n switch (result.type) {\n case 'InternalError':\n // object store encountered network error, retry by client can help\n return void response.writeHead(StatusCode.InternalServerError).end();\n case 'NotFound':\n // RFC 9110 section 15.4.5: Not found\n return void response.writeHead(StatusCode.NotFound).end();\n case 'RangeNotSatisfiable':\n // RFC 9110 section 15.5.17: Range not satisfiable\n response.setHeader(HeaderName.ContentRange, `bytes */${result.size}`);\n return void response.writeHead(StatusCode.RangeNotSatisfiable).end();\n case 'Ok':\n break;\n }\n\n if (isGet(method) && !result.data) {\n // object store implementation is incorrect, retry by client cannot help\n return void response.writeHead(StatusCode.GatewayTimeout).end();\n }\n\n if (range) {\n // RFC 9110 section 14.4: Partial content response\n response.setHeader(\n HeaderName.ContentLength,\n result.range.end - result.range.start + 1\n );\n response.setHeader(\n HeaderName.ContentRange,\n `bytes ${result.range.start}-${result.range.end}/${result.size}`\n );\n response.writeHead(StatusCode.PartialContent);\n } else {\n // RFC 9110 section 15.3.1: OK response\n response.setHeader(HeaderName.ContentLength, result.size);\n response.writeHead(StatusCode.Ok);\n }\n\n // RFC 9110 section 9.3.2: HEAD method must not return message body\n if (isHead(method)) {\n return void response.end();\n }\n\n try {\n return await pipeline(result.data!, response, { signal });\n } catch (error: unknown) {\n if (!isAbortError(error)) throw error;\n }\n }\n });\n}\n\n/**\n * Create a request handler for serving files from an object store\n * compatible with HTTP/1.1 as defined in RFC 9110 and RFC 9111:\n * - <https://datatracker.ietf.org/doc/html/rfc9110>\n * - <https://datatracker.ietf.org/doc/html/rfc9111>\n *\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 Gone otherwise\n * Assumes that files are immutable (and sets cache headers accordingly)\n */\nexport function createRequestHandler(\n options: PFrameInternal.RequestHandlerOptions\n): RequestListener {\n const { store } = options;\n return (request, response) => handleRequest(request, response, store);\n}\n\n/** Request authorization middleware */\nfunction authorizeRequest(\n request: IncomingMessage,\n response: ServerResponse,\n handler: RequestListener,\n authHeader: string\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n const actualHeader = request.headers[HeaderName.Authorization];\n\n // Early length check to avoid unnecessary processing\n if (!actualHeader || actualHeader.length !== authHeader.length) {\n // RFC 9110 section 11.6.1: WWW-Authenticate header field\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n // Use timing-safe comparison to prevent timing attacks\n // <https://developers.cloudflare.com/workers/examples/protect-against-timing-attacks/>\n const encoder = new TextEncoder();\n const receivedBuffer = encoder.encode(actualHeader);\n const expectedBuffer = encoder.encode(authHeader);\n\n if (\n receivedBuffer.byteLength !== expectedBuffer.byteLength ||\n !timingSafeEqual(receivedBuffer, expectedBuffer)\n ) {\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n return handler(request, response);\n}\n\n/** Apply Bearer token authorization to @param handler */\nexport function authorizeRequestHandler(\n handler: RequestListener,\n authToken: PFrameInternal.HttpAuthorizationToken\n): RequestListener {\n const authHeader = `Bearer ${authToken}`;\n return (request, response) =>\n authorizeRequest(request, response, handler, authHeader);\n}\n"],"names":["HeaderName","HeaderValue","method","isGetOrHead","StatusCode","filename","getFilenameFromUrl","etag","createETag","options","Options","range","parseRange","isGet","isHead","pipeline","isAbortError","timingSafeEqual"],"mappings":";;;;;;;;;;;;;AAsBA;AACA,SAAS,aAAa,CACpB,OAAwB,EACxB,QAAwB,EACxB,KAAiC,EAAA;;AAGjC,IAAA,QAAQ,CAAC,QAAQ,GAAG,IAAI;;AAExB,IAAA,QAAQ,CAAC,mBAAmB,GAAG,IAAI;IACnC,QAAQ,CAAC,SAAS,CAACA,kBAAU,CAAC,aAAa,EAAE,CAAC,CAAC;;;IAI/C,QAAQ,CAAC,SAAS,CAACA,kBAAU,CAAC,YAAY,EAAEC,mBAAW,CAAC,YAAY,CAAC;;AAGrE,IAAA,MAAMC,QAAM,GAAG,OAAO,CAAC,MAAM;AAC7B,IAAA,IAAI,CAACC,kBAAW,CAACD,QAAM,CAAC,EAAE;QACxB,QAAQ,CAAC,SAAS,CAACF,kBAAU,CAAC,KAAK,EAAEC,mBAAW,CAAC,KAAK,CAAC;AACvD,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAACG,iBAAU,CAAC,gBAAgB,CAAC,CAAC,GAAG,EAAE;IACnE;AAEA,IAAA,MAAMC,UAAQ,GAAGC,2BAAkB,CAAC,OAAO,CAAC;AAC5C,IAAA,IAAID,UAAQ,KAAK,IAAI,EAAE;AACrB,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAACD,iBAAU,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE;IACvD;;IAGA,QAAQ,CAAC,SAAS,CAACJ,kBAAU,CAAC,YAAY,EAAEC,mBAAW,CAAC,YAAY,CAAC;IACrE,QAAQ,CAAC,SAAS,CAACD,kBAAU,CAAC,WAAW,EAAEC,mBAAW,CAAC,WAAW,CAAC;;AAGnE,IAAA,MAAMM,MAAI,GAAGC,eAAU,CAACH,UAAQ,CAAC;;IAEjC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;;IAE1B,Q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C,CAAC;;IAG/C,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAACA,kBAAU,CAAC,aAAa,CAAC;;IAG9D,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,UAAU,CAAC,MAAM,EAAE;;QAE9D,QAAQ,CAAC,SAAS,CAACA,kBAAU,CAAC,eAAe,EAAEC,mBAAW,CAAC,eAAe,CAAC;AAC3E,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAACG,iBAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE;IAC/D;;;AAIA,IAAA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE;IACjC,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;AAEjD,IAAA,IACE,cAAc,CAAC,UAAU,KAAK,cAAc,CAAC,UAAU;AACvD,QAAA,CAACa,2BAAe,CAAC,cAAc,EAAE,cAAc,CAAC,EAChD;QACA,QAAQ,CAAC,SAAS,CAACjB,kBAAU,CAAC,eAAe,EAAEC,mBAAW,CAAC,eAAe,CAAC;AAC3E,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAACG,iBAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE;IAC/D;AAEA,IAAA,OAAO,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC;AACnC;AAEA;AACM,SAAU,uBAAuB,CACrC,OAAwB,EACxB,SAAgD,EAAA;AAEhD,IAAA,MAAM,UAAU,GAAG,CAAA,OAAA,EAAU,SAAS,EAAE;AACxC,IAAA,OAAO,CAAC,OAAO,EAAE,QAAQ,KACvB,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC;AAC5D;;;;;"}
|
|
1
|
+
{"version":3,"file":"handler.cjs","sources":["../src/handler.ts"],"sourcesContent":["import type { IncomingMessage, RequestListener, ServerResponse } from \"node:http\";\nimport { pipeline } from \"node:stream/promises\";\nimport { timingSafeEqual } from \"node:crypto\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport {\n createETag,\n getFilenameFromUrl,\n parseRange,\n isGetOrHead,\n isGet,\n isHead,\n Options,\n StatusCode,\n HeaderName,\n HeaderValue,\n} from \"./utils\";\nimport { isAbortError } from \"@milaboratories/pl-model-common\";\n\n/** Main request handler for parquet files */\nfunction handleRequest(\n request: IncomingMessage,\n response: ServerResponse,\n store: PFrameInternal.ObjectStore,\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n\n // RFC 9110 section 15.5.6: Method not allowed\n const method = request.method;\n if (!isGetOrHead(method)) {\n response.setHeader(HeaderName.Allow, HeaderValue.Allow);\n return void response.writeHead(StatusCode.MethodNotAllowed).end();\n }\n\n const filename = getFilenameFromUrl(request);\n if (filename === null) {\n return void response.writeHead(StatusCode.Gone).end();\n }\n\n // From now on we are sure that the response would be a Parquet file\n response.setHeader(HeaderName.AcceptRanges, HeaderValue.AcceptRanges);\n response.setHeader(HeaderName.ContentType, HeaderValue.ContentType);\n\n // RFC 9110 section 8.8.3: ETag header is used for cache versioning\n const etag = createETag(filename);\n // RFC 9110 section 8.8.2: Last-Modified header field for cache validation\n const mtime = new Date(0); // Using fake fixed date since files are immutable\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n response.setHeader(HeaderName.ETag, etag);\n response.setHeader(HeaderName.LastModified, mtime.toUTCString());\n\n const options = new Options(request);\n // RFC 9110 section 13.1.1: If-Match precondition evaluation\n // RFC 9110 section 13.1.4: If-Unmodified-Since precondition evaluation\n if (options.preconditionFailed(etag, mtime)) {\n return void response.writeHead(StatusCode.PreconditionFailed).end();\n }\n // RFC 9110 section 13.1.2: If-None-Match precondition evaluation\n // RFC 9110 section 13.1.3: If-Modified-Since precondition evaluation\n else if (options.notModified(etag, mtime)) {\n return void response.writeHead(StatusCode.NotModified).end();\n }\n\n const range = parseRange(request);\n if (range === null) {\n return void response.writeHead(StatusCode.BadRequest).end();\n }\n\n const abortController = new AbortController();\n request.on(\"close\", () => abortController.abort());\n const signal = abortController.signal;\n\n store.request(filename, {\n method,\n range,\n signal,\n // pipeline automatically destroys the streams if they were not gracefully closed\n callback: async (result) => {\n if (request.destroyed) {\n // request has timed out, close the connection\n if (response.destroyed) {\n return;\n } else if (response.headersSent) {\n return void response.end();\n } else {\n response.setHeader(HeaderName.Connection, HeaderValue.Connection);\n return void response.writeHead(StatusCode.RequestTimeout).end();\n }\n }\n\n switch (result.type) {\n case \"InternalError\":\n // object store encountered network error, retry by client can help\n return void response.writeHead(StatusCode.InternalServerError).end();\n case \"NotFound\":\n // RFC 9110 section 15.4.5: Not found\n return void response.writeHead(StatusCode.NotFound).end();\n case \"RangeNotSatisfiable\":\n // RFC 9110 section 15.5.17: Range not satisfiable\n response.setHeader(HeaderName.ContentRange, `bytes */${result.size}`);\n return void response.writeHead(StatusCode.RangeNotSatisfiable).end();\n case \"Ok\":\n break;\n }\n\n if (isGet(method) && !result.data) {\n // object store implementation is incorrect, retry by client cannot help\n return void response.writeHead(StatusCode.GatewayTimeout).end();\n }\n\n if (range) {\n // RFC 9110 section 14.4: Partial content response\n response.setHeader(HeaderName.ContentLength, result.range.end - result.range.start + 1);\n response.setHeader(\n HeaderName.ContentRange,\n `bytes ${result.range.start}-${result.range.end}/${result.size}`,\n );\n response.writeHead(StatusCode.PartialContent);\n } else {\n // RFC 9110 section 15.3.1: OK response\n response.setHeader(HeaderName.ContentLength, result.size);\n response.writeHead(StatusCode.Ok);\n }\n\n // RFC 9110 section 9.3.2: HEAD method must not return message body\n if (isHead(method)) {\n return void response.end();\n }\n\n try {\n return await pipeline(result.data!, response, { signal });\n } catch (error: unknown) {\n if (!isAbortError(error)) throw error;\n }\n },\n });\n}\n\n/**\n * Create a request handler for serving files from an object store\n * compatible with HTTP/1.1 as defined in RFC 9110 and RFC 9111:\n * - <https://datatracker.ietf.org/doc/html/rfc9110>\n * - <https://datatracker.ietf.org/doc/html/rfc9111>\n *\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 Gone otherwise\n * Assumes that files are immutable (and sets cache headers accordingly)\n */\nexport function createRequestHandler(\n options: PFrameInternal.RequestHandlerOptions,\n): RequestListener {\n const { store } = options;\n return (request, response) => handleRequest(request, response, store);\n}\n\n/** Request authorization middleware */\nfunction authorizeRequest(\n request: IncomingMessage,\n response: ServerResponse,\n handler: RequestListener,\n authHeader: string,\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n const actualHeader = request.headers[HeaderName.Authorization];\n\n // Early length check to avoid unnecessary processing\n if (!actualHeader || actualHeader.length !== authHeader.length) {\n // RFC 9110 section 11.6.1: WWW-Authenticate header field\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n // Use timing-safe comparison to prevent timing attacks\n // <https://developers.cloudflare.com/workers/examples/protect-against-timing-attacks/>\n const encoder = new TextEncoder();\n const receivedBuffer = encoder.encode(actualHeader);\n const expectedBuffer = encoder.encode(authHeader);\n\n if (\n receivedBuffer.byteLength !== expectedBuffer.byteLength ||\n !timingSafeEqual(receivedBuffer, expectedBuffer)\n ) {\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n return handler(request, response);\n}\n\n/** Apply Bearer token authorization to @param handler */\nexport function authorizeRequestHandler(\n handler: RequestListener,\n authToken: PFrameInternal.HttpAuthorizationToken,\n): RequestListener {\n const authHeader = `Bearer ${authToken}`;\n return (request, response) => authorizeRequest(request, response, handler, authHeader);\n}\n"],"names":["HeaderName","HeaderValue","method","isGetOrHead","StatusCode","filename","getFilenameFromUrl","etag","createETag","options","Options","range","parseRange","isGet","isHead","pipeline","isAbortError","timingSafeEqual"],"mappings":";;;;;;;;;;;;;AAkBA;AACA,SAAS,aAAa,CACpB,OAAwB,EACxB,QAAwB,EACxB,KAAiC,EAAA;;AAGjC,IAAA,QAAQ,CAAC,QAAQ,GAAG,IAAI;;AAExB,IAAA,QAAQ,CAAC,mBAAmB,GAAG,IAAI;IACnC,QAAQ,CAAC,SAAS,CAACA,kBAAU,CAAC,aAAa,EAAE,CAAC,CAAC;;;IAI/C,QAAQ,CAAC,SAAS,CAACA,kBAAU,CAAC,YAAY,EAAEC,mBAAW,CAAC,YAAY,CAAC;;AAGrE,IAAA,MAAMC,QAAM,GAAG,OAAO,CAAC,MAAM;AAC7B,IAAA,IAAI,CAACC,kBAAW,CAACD,QAAM,CAAC,EAAE;QACxB,QAAQ,CAAC,SAAS,CAACF,kBAAU,CAAC,KAAK,EAAEC,mBAAW,CAAC,KAAK,CAAC;AACvD,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAACG,iBAAU,CAAC,gBAAgB,CAAC,CAAC,GAAG,EAAE;IACnE;AAEA,IAAA,MAAMC,UAAQ,GAAGC,2BAAkB,CAAC,OAAO,CAAC;AAC5C,IAAA,IAAID,UAAQ,KAAK,IAAI,EAAE;AACrB,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAACD,iBAAU,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE;IACvD;;IAGA,QAAQ,CAAC,SAAS,CAACJ,kBAAU,CAAC,YAAY,EAAEC,mBAAW,CAA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AAS,EAAE;AACxC,IAAA,OAAO,CAAC,OAAO,EAAE,QAAQ,KAAK,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC;AACxF;;;;;"}
|
package/dist/handler.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RequestListener } from
|
|
2
|
-
import type { PFrameInternal } from
|
|
1
|
+
import type { RequestListener } from "node:http";
|
|
2
|
+
import type { PFrameInternal } from "@milaboratories/pl-model-middle-layer";
|
|
3
3
|
/**
|
|
4
4
|
* Create a request handler for serving files from an object store
|
|
5
5
|
* compatible with HTTP/1.1 as defined in RFC 9110 and RFC 9111:
|
package/dist/handler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,eAAe,EAAkB,MAAM,WAAW,CAAC;AAGlF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AA+I5E;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,cAAc,CAAC,qBAAqB,GAC5C,eAAe,CAGjB;AA0CD,yDAAyD;AACzD,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,eAAe,EACxB,SAAS,EAAE,cAAc,CAAC,sBAAsB,GAC/C,eAAe,CAGjB"}
|
package/dist/handler.js
CHANGED
|
@@ -56,7 +56,7 @@ function handleRequest(request, response, store) {
|
|
|
56
56
|
return void response.writeHead(StatusCode.BadRequest).end();
|
|
57
57
|
}
|
|
58
58
|
const abortController = new AbortController();
|
|
59
|
-
request.on(
|
|
59
|
+
request.on("close", () => abortController.abort());
|
|
60
60
|
const signal = abortController.signal;
|
|
61
61
|
store.request(filename, {
|
|
62
62
|
method,
|
|
@@ -78,13 +78,13 @@ function handleRequest(request, response, store) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
switch (result.type) {
|
|
81
|
-
case
|
|
81
|
+
case "InternalError":
|
|
82
82
|
// object store encountered network error, retry by client can help
|
|
83
83
|
return void response.writeHead(StatusCode.InternalServerError).end();
|
|
84
|
-
case
|
|
84
|
+
case "NotFound":
|
|
85
85
|
// RFC 9110 section 15.4.5: Not found
|
|
86
86
|
return void response.writeHead(StatusCode.NotFound).end();
|
|
87
|
-
case
|
|
87
|
+
case "RangeNotSatisfiable":
|
|
88
88
|
// RFC 9110 section 15.5.17: Range not satisfiable
|
|
89
89
|
response.setHeader(HeaderName.ContentRange, `bytes */${result.size}`);
|
|
90
90
|
return void response.writeHead(StatusCode.RangeNotSatisfiable).end();
|
|
@@ -115,7 +115,7 @@ function handleRequest(request, response, store) {
|
|
|
115
115
|
if (!isAbortError(error))
|
|
116
116
|
throw error;
|
|
117
117
|
}
|
|
118
|
-
}
|
|
118
|
+
},
|
|
119
119
|
});
|
|
120
120
|
}
|
|
121
121
|
/**
|
package/dist/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sources":["../src/handler.ts"],"sourcesContent":["import type {\n IncomingMessage,\n RequestListener,\n ServerResponse\n} from 'node:http';\nimport { pipeline } from 'node:stream/promises';\nimport { timingSafeEqual } from 'node:crypto';\nimport type { PFrameInternal } from '@milaboratories/pl-model-middle-layer';\nimport {\n createETag,\n getFilenameFromUrl,\n parseRange,\n isGetOrHead,\n isGet,\n isHead,\n Options,\n StatusCode,\n HeaderName,\n HeaderValue\n} from './utils';\nimport { isAbortError } from '@milaboratories/pl-model-common';\n\n/** Main request handler for parquet files */\nfunction handleRequest(\n request: IncomingMessage,\n response: ServerResponse,\n store: PFrameInternal.ObjectStore\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n\n // RFC 9110 section 15.5.6: Method not allowed\n const method = request.method;\n if (!isGetOrHead(method)) {\n response.setHeader(HeaderName.Allow, HeaderValue.Allow);\n return void response.writeHead(StatusCode.MethodNotAllowed).end();\n }\n\n const filename = getFilenameFromUrl(request);\n if (filename === null) {\n return void response.writeHead(StatusCode.Gone).end();\n }\n\n // From now on we are sure that the response would be a Parquet file\n response.setHeader(HeaderName.AcceptRanges, HeaderValue.AcceptRanges);\n response.setHeader(HeaderName.ContentType, HeaderValue.ContentType);\n\n // RFC 9110 section 8.8.3: ETag header is used for cache versioning\n const etag = createETag(filename);\n // RFC 9110 section 8.8.2: Last-Modified header field for cache validation\n const mtime = new Date(0); // Using fake fixed date since files are immutable\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n response.setHeader(HeaderName.ETag, etag);\n response.setHeader(HeaderName.LastModified, mtime.toUTCString());\n\n const options = new Options(request);\n // RFC 9110 section 13.1.1: If-Match precondition evaluation\n // RFC 9110 section 13.1.4: If-Unmodified-Since precondition evaluation\n if (options.preconditionFailed(etag, mtime)) {\n return void response.writeHead(StatusCode.PreconditionFailed).end();\n }\n // RFC 9110 section 13.1.2: If-None-Match precondition evaluation\n // RFC 9110 section 13.1.3: If-Modified-Since precondition evaluation\n else if (options.notModified(etag, mtime)) {\n return void response.writeHead(StatusCode.NotModified).end();\n }\n\n const range = parseRange(request);\n if (range === null) {\n return void response.writeHead(StatusCode.BadRequest).end();\n }\n\n const abortController = new AbortController();\n request.on('close', () => abortController.abort());\n const signal = abortController.signal;\n\n store.request(filename, {\n method,\n range,\n signal,\n // pipeline automatically destroys the streams if they were not gracefully closed\n callback: async (result) => {\n if (request.destroyed) {\n // request has timed out, close the connection\n if (response.destroyed) {\n return;\n } else if (response.headersSent) {\n return void response.end();\n } else {\n response.setHeader(HeaderName.Connection, HeaderValue.Connection);\n return void response.writeHead(StatusCode.RequestTimeout).end();\n }\n }\n\n switch (result.type) {\n case 'InternalError':\n // object store encountered network error, retry by client can help\n return void response.writeHead(StatusCode.InternalServerError).end();\n case 'NotFound':\n // RFC 9110 section 15.4.5: Not found\n return void response.writeHead(StatusCode.NotFound).end();\n case 'RangeNotSatisfiable':\n // RFC 9110 section 15.5.17: Range not satisfiable\n response.setHeader(HeaderName.ContentRange, `bytes */${result.size}`);\n return void response.writeHead(StatusCode.RangeNotSatisfiable).end();\n case 'Ok':\n break;\n }\n\n if (isGet(method) && !result.data) {\n // object store implementation is incorrect, retry by client cannot help\n return void response.writeHead(StatusCode.GatewayTimeout).end();\n }\n\n if (range) {\n // RFC 9110 section 14.4: Partial content response\n response.setHeader(\n HeaderName.ContentLength,\n result.range.end - result.range.start + 1\n );\n response.setHeader(\n HeaderName.ContentRange,\n `bytes ${result.range.start}-${result.range.end}/${result.size}`\n );\n response.writeHead(StatusCode.PartialContent);\n } else {\n // RFC 9110 section 15.3.1: OK response\n response.setHeader(HeaderName.ContentLength, result.size);\n response.writeHead(StatusCode.Ok);\n }\n\n // RFC 9110 section 9.3.2: HEAD method must not return message body\n if (isHead(method)) {\n return void response.end();\n }\n\n try {\n return await pipeline(result.data!, response, { signal });\n } catch (error: unknown) {\n if (!isAbortError(error)) throw error;\n }\n }\n });\n}\n\n/**\n * Create a request handler for serving files from an object store\n * compatible with HTTP/1.1 as defined in RFC 9110 and RFC 9111:\n * - <https://datatracker.ietf.org/doc/html/rfc9110>\n * - <https://datatracker.ietf.org/doc/html/rfc9111>\n *\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 Gone otherwise\n * Assumes that files are immutable (and sets cache headers accordingly)\n */\nexport function createRequestHandler(\n options: PFrameInternal.RequestHandlerOptions\n): RequestListener {\n const { store } = options;\n return (request, response) => handleRequest(request, response, store);\n}\n\n/** Request authorization middleware */\nfunction authorizeRequest(\n request: IncomingMessage,\n response: ServerResponse,\n handler: RequestListener,\n authHeader: string\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n const actualHeader = request.headers[HeaderName.Authorization];\n\n // Early length check to avoid unnecessary processing\n if (!actualHeader || actualHeader.length !== authHeader.length) {\n // RFC 9110 section 11.6.1: WWW-Authenticate header field\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n // Use timing-safe comparison to prevent timing attacks\n // <https://developers.cloudflare.com/workers/examples/protect-against-timing-attacks/>\n const encoder = new TextEncoder();\n const receivedBuffer = encoder.encode(actualHeader);\n const expectedBuffer = encoder.encode(authHeader);\n\n if (\n receivedBuffer.byteLength !== expectedBuffer.byteLength ||\n !timingSafeEqual(receivedBuffer, expectedBuffer)\n ) {\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n return handler(request, response);\n}\n\n/** Apply Bearer token authorization to @param handler */\nexport function authorizeRequestHandler(\n handler: RequestListener,\n authToken: PFrameInternal.HttpAuthorizationToken\n): RequestListener {\n const authHeader = `Bearer ${authToken}`;\n return (request, response) =>\n authorizeRequest(request, response, handler, authHeader);\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAsBA;AACA,SAAS,aAAa,CACpB,OAAwB,EACxB,QAAwB,EACxB,KAAiC,EAAA;;AAGjC,IAAA,QAAQ,CAAC,QAAQ,GAAG,IAAI;;AAExB,IAAA,QAAQ,CAAC,mBAAmB,GAAG,IAAI;IACnC,QAAQ,CAA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IAAI,WAAW,EAAE;IACjC,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;AAEjD,IAAA,IACE,cAAc,CAAC,UAAU,KAAK,cAAc,CAAC,UAAU;AACvD,QAAA,CAAC,eAAe,CAAC,cAAc,EAAE,cAAc,CAAC,EAChD;QACA,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,eAAe,CAAC;AAC3E,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE;IAC/D;AAEA,IAAA,OAAO,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC;AACnC;AAEA;AACM,SAAU,uBAAuB,CACrC,OAAwB,EACxB,SAAgD,EAAA;AAEhD,IAAA,MAAM,UAAU,GAAG,CAAA,OAAA,EAAU,SAAS,EAAE;AACxC,IAAA,OAAO,CAAC,OAAO,EAAE,QAAQ,KACvB,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC;AAC5D;;;;"}
|
|
1
|
+
{"version":3,"file":"handler.js","sources":["../src/handler.ts"],"sourcesContent":["import type { IncomingMessage, RequestListener, ServerResponse } from \"node:http\";\nimport { pipeline } from \"node:stream/promises\";\nimport { timingSafeEqual } from \"node:crypto\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport {\n createETag,\n getFilenameFromUrl,\n parseRange,\n isGetOrHead,\n isGet,\n isHead,\n Options,\n StatusCode,\n HeaderName,\n HeaderValue,\n} from \"./utils\";\nimport { isAbortError } from \"@milaboratories/pl-model-common\";\n\n/** Main request handler for parquet files */\nfunction handleRequest(\n request: IncomingMessage,\n response: ServerResponse,\n store: PFrameInternal.ObjectStore,\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n\n // RFC 9110 section 15.5.6: Method not allowed\n const method = request.method;\n if (!isGetOrHead(method)) {\n response.setHeader(HeaderName.Allow, HeaderValue.Allow);\n return void response.writeHead(StatusCode.MethodNotAllowed).end();\n }\n\n const filename = getFilenameFromUrl(request);\n if (filename === null) {\n return void response.writeHead(StatusCode.Gone).end();\n }\n\n // From now on we are sure that the response would be a Parquet file\n response.setHeader(HeaderName.AcceptRanges, HeaderValue.AcceptRanges);\n response.setHeader(HeaderName.ContentType, HeaderValue.ContentType);\n\n // RFC 9110 section 8.8.3: ETag header is used for cache versioning\n const etag = createETag(filename);\n // RFC 9110 section 8.8.2: Last-Modified header field for cache validation\n const mtime = new Date(0); // Using fake fixed date since files are immutable\n // RFC 9111 section 5.2: Cache-Control header with public allows to cache authenticated responses\n response.setHeader(HeaderName.CacheControl, HeaderValue.CacheControl);\n response.setHeader(HeaderName.ETag, etag);\n response.setHeader(HeaderName.LastModified, mtime.toUTCString());\n\n const options = new Options(request);\n // RFC 9110 section 13.1.1: If-Match precondition evaluation\n // RFC 9110 section 13.1.4: If-Unmodified-Since precondition evaluation\n if (options.preconditionFailed(etag, mtime)) {\n return void response.writeHead(StatusCode.PreconditionFailed).end();\n }\n // RFC 9110 section 13.1.2: If-None-Match precondition evaluation\n // RFC 9110 section 13.1.3: If-Modified-Since precondition evaluation\n else if (options.notModified(etag, mtime)) {\n return void response.writeHead(StatusCode.NotModified).end();\n }\n\n const range = parseRange(request);\n if (range === null) {\n return void response.writeHead(StatusCode.BadRequest).end();\n }\n\n const abortController = new AbortController();\n request.on(\"close\", () => abortController.abort());\n const signal = abortController.signal;\n\n store.request(filename, {\n method,\n range,\n signal,\n // pipeline automatically destroys the streams if they were not gracefully closed\n callback: async (result) => {\n if (request.destroyed) {\n // request has timed out, close the connection\n if (response.destroyed) {\n return;\n } else if (response.headersSent) {\n return void response.end();\n } else {\n response.setHeader(HeaderName.Connection, HeaderValue.Connection);\n return void response.writeHead(StatusCode.RequestTimeout).end();\n }\n }\n\n switch (result.type) {\n case \"InternalError\":\n // object store encountered network error, retry by client can help\n return void response.writeHead(StatusCode.InternalServerError).end();\n case \"NotFound\":\n // RFC 9110 section 15.4.5: Not found\n return void response.writeHead(StatusCode.NotFound).end();\n case \"RangeNotSatisfiable\":\n // RFC 9110 section 15.5.17: Range not satisfiable\n response.setHeader(HeaderName.ContentRange, `bytes */${result.size}`);\n return void response.writeHead(StatusCode.RangeNotSatisfiable).end();\n case \"Ok\":\n break;\n }\n\n if (isGet(method) && !result.data) {\n // object store implementation is incorrect, retry by client cannot help\n return void response.writeHead(StatusCode.GatewayTimeout).end();\n }\n\n if (range) {\n // RFC 9110 section 14.4: Partial content response\n response.setHeader(HeaderName.ContentLength, result.range.end - result.range.start + 1);\n response.setHeader(\n HeaderName.ContentRange,\n `bytes ${result.range.start}-${result.range.end}/${result.size}`,\n );\n response.writeHead(StatusCode.PartialContent);\n } else {\n // RFC 9110 section 15.3.1: OK response\n response.setHeader(HeaderName.ContentLength, result.size);\n response.writeHead(StatusCode.Ok);\n }\n\n // RFC 9110 section 9.3.2: HEAD method must not return message body\n if (isHead(method)) {\n return void response.end();\n }\n\n try {\n return await pipeline(result.data!, response, { signal });\n } catch (error: unknown) {\n if (!isAbortError(error)) throw error;\n }\n },\n });\n}\n\n/**\n * Create a request handler for serving files from an object store\n * compatible with HTTP/1.1 as defined in RFC 9110 and RFC 9111:\n * - <https://datatracker.ietf.org/doc/html/rfc9110>\n * - <https://datatracker.ietf.org/doc/html/rfc9111>\n *\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 Gone otherwise\n * Assumes that files are immutable (and sets cache headers accordingly)\n */\nexport function createRequestHandler(\n options: PFrameInternal.RequestHandlerOptions,\n): RequestListener {\n const { store } = options;\n return (request, response) => handleRequest(request, response, store);\n}\n\n/** Request authorization middleware */\nfunction authorizeRequest(\n request: IncomingMessage,\n response: ServerResponse,\n handler: RequestListener,\n authHeader: string,\n): void {\n // RFC 9110 section 6.6.1: Date header should be present in all responses\n response.sendDate = true;\n // RFC 9110 section 8.6: Content-Length 0 as default for error responses\n response.strictContentLength = true;\n response.setHeader(HeaderName.ContentLength, 0);\n // Note: setting Content-Length disables Node.js default Transfer-Encoding: chunked\n\n const actualHeader = request.headers[HeaderName.Authorization];\n\n // Early length check to avoid unnecessary processing\n if (!actualHeader || actualHeader.length !== authHeader.length) {\n // RFC 9110 section 11.6.1: WWW-Authenticate header field\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n // Use timing-safe comparison to prevent timing attacks\n // <https://developers.cloudflare.com/workers/examples/protect-against-timing-attacks/>\n const encoder = new TextEncoder();\n const receivedBuffer = encoder.encode(actualHeader);\n const expectedBuffer = encoder.encode(authHeader);\n\n if (\n receivedBuffer.byteLength !== expectedBuffer.byteLength ||\n !timingSafeEqual(receivedBuffer, expectedBuffer)\n ) {\n response.setHeader(HeaderName.WWWAuthenticate, HeaderValue.WWWAuthenticate);\n return void response.writeHead(StatusCode.Unauthorized).end();\n }\n\n return handler(request, response);\n}\n\n/** Apply Bearer token authorization to @param handler */\nexport function authorizeRequestHandler(\n handler: RequestListener,\n authToken: PFrameInternal.HttpAuthorizationToken,\n): RequestListener {\n const authHeader = `Bearer ${authToken}`;\n return (request, response) => authorizeRequest(request, response, handler, authHeader);\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAkBA;AACA,SAAS,aAAa,CACpB,OAAwB,EACxB,QAAwB,EACxB,KAAiC,EAAA;;AAGjC,IAAA,QAAQ,CAAC,QAAQ,GAAG,IAAI;;AAExB,IAAA,QAAQ,CAAC,mBAAmB,GAAG,I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IA,IAAA,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE;IACjC,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC;AAEjD,IAAA,IACE,cAAc,CAAC,UAAU,KAAK,cAAc,CAAC,UAAU;AACvD,QAAA,CAAC,eAAe,CAAC,cAAc,EAAE,cAAc,CAAC,EAChD;QACA,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,eAAe,CAAC;AAC3E,QAAA,OAAO,KAAK,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,GAAG,EAAE;IAC/D;AAEA,IAAA,OAAO,OAAO,CAAC,OAAO,EAAE,QAAQ,CAAC;AACnC;AAEA;AACM,SAAU,uBAAuB,CACrC,OAAwB,EACxB,SAAgD,EAAA;AAEhD,IAAA,MAAM,UAAU,GAAG,CAAA,OAAA,EAAU,SAAS,EAAE;AACxC,IAAA,OAAO,CAAC,OAAO,EAAE,QAAQ,KAAK,gBAAgB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC;AACxF;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
1
|
+
export * from "./handler";
|
|
2
|
+
export * from "./fs-store";
|
|
3
|
+
export * from "./serve";
|
|
4
|
+
export * from "./export";
|
|
5
|
+
export * from "./parquet-server";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|