@milaboratories/pframes-rs-serv 1.1.18 → 1.1.20
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/export.cjs +16 -17
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.ts +6 -2
- package/dist/export.d.ts.map +1 -1
- package/dist/export.js +16 -15
- package/dist/export.js.map +1 -1
- package/dist/fs-store.cjs +83 -87
- package/dist/fs-store.cjs.map +1 -1
- package/dist/fs-store.d.ts +14 -10
- package/dist/fs-store.d.ts.map +1 -1
- package/dist/fs-store.js +83 -85
- package/dist/fs-store.js.map +1 -1
- package/dist/handler.cjs +132 -157
- package/dist/handler.cjs.map +1 -1
- package/dist/handler.d.ts +8 -4
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +132 -155
- package/dist/handler.js.map +1 -1
- package/dist/index.cjs +13 -18
- package/dist/index.d.ts +6 -6
- package/dist/index.js +6 -6
- package/dist/parquet-server.cjs +95 -101
- package/dist/parquet-server.cjs.map +1 -1
- package/dist/parquet-server.d.ts +16 -12
- package/dist/parquet-server.d.ts.map +1 -1
- package/dist/parquet-server.js +95 -98
- package/dist/parquet-server.js.map +1 -1
- package/dist/serve.cjs +98 -94
- package/dist/serve.cjs.map +1 -1
- package/dist/serve.d.ts +11 -2
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +98 -92
- package/dist/serve.js.map +1 -1
- package/dist/utils/etag.cjs +5 -7
- package/dist/utils/etag.cjs.map +1 -1
- package/dist/utils/etag.js +5 -5
- package/dist/utils/etag.js.map +1 -1
- package/dist/utils/filename.cjs +9 -11
- package/dist/utils/filename.cjs.map +1 -1
- package/dist/utils/filename.js +9 -9
- package/dist/utils/filename.js.map +1 -1
- package/dist/utils/headers.cjs +28 -21
- package/dist/utils/headers.cjs.map +1 -1
- package/dist/utils/headers.js +28 -19
- package/dist/utils/headers.js.map +1 -1
- package/dist/utils/method.cjs +7 -7
- package/dist/utils/method.cjs.map +1 -1
- package/dist/utils/method.js +7 -5
- package/dist/utils/method.js.map +1 -1
- package/dist/utils/options.cjs +111 -134
- package/dist/utils/options.cjs.map +1 -1
- package/dist/utils/options.js +111 -132
- package/dist/utils/options.js.map +1 -1
- package/dist/utils/range.cjs +26 -31
- package/dist/utils/range.cjs.map +1 -1
- package/dist/utils/range.js +26 -29
- package/dist/utils/range.js.map +1 -1
- package/dist/utils/status.cjs +17 -17
- package/dist/utils/status.cjs.map +1 -1
- package/dist/utils/status.js +17 -15
- package/dist/utils/status.js.map +1 -1
- package/package.json +4 -4
- package/src/parquet-server.ts +16 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/etag.d.ts +0 -15
- package/dist/utils/etag.d.ts.map +0 -1
- package/dist/utils/filename.d.ts +0 -4
- package/dist/utils/filename.d.ts.map +0 -1
- package/dist/utils/headers.d.ts +0 -31
- package/dist/utils/headers.d.ts.map +0 -1
- package/dist/utils/index.d.ts +0 -8
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/method.d.ts +0 -6
- package/dist/utils/method.d.ts.map +0 -1
- package/dist/utils/options.d.ts +0 -64
- package/dist/utils/options.d.ts.map +0 -1
- package/dist/utils/range.d.ts +0 -4
- package/dist/utils/range.d.ts.map +0 -1
- package/dist/utils/status.d.ts +0 -17
- package/dist/utils/status.d.ts.map +0 -1
package/dist/serve.cjs
CHANGED
|
@@ -1,103 +1,107 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var handler = require('./handler.cjs');
|
|
10
|
-
|
|
1
|
+
const require_handler = require("./handler.cjs");
|
|
2
|
+
let node_crypto = require("node:crypto");
|
|
3
|
+
let _milaboratories_pl_model_common = require("@milaboratories/pl-model-common");
|
|
4
|
+
let node_http = require("node:http");
|
|
5
|
+
let node_https = require("node:https");
|
|
6
|
+
let _milaboratories_helpers = require("@milaboratories/helpers");
|
|
7
|
+
let selfsigned = require("selfsigned");
|
|
8
|
+
//#region src/serve.ts
|
|
11
9
|
/** Generate a self-signed certificate for localhost */
|
|
12
10
|
async function generateCertificate() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
11
|
+
return await (0, selfsigned.generate)([{
|
|
12
|
+
name: "commonName",
|
|
13
|
+
value: "localhost"
|
|
14
|
+
}], {
|
|
15
|
+
keySize: 2048,
|
|
16
|
+
algorithm: "sha256",
|
|
17
|
+
extensions: [{
|
|
18
|
+
name: "subjectAltName",
|
|
19
|
+
altNames: [
|
|
20
|
+
{
|
|
21
|
+
type: 2,
|
|
22
|
+
value: "localhost"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 7,
|
|
26
|
+
ip: "127.0.0.1"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 7,
|
|
30
|
+
ip: "::1"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}]
|
|
34
|
+
});
|
|
27
35
|
}
|
|
28
36
|
/** Create an object store URL from the server address info. */
|
|
29
37
|
function createObjectStoreUrl(info, noHttps) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
default:
|
|
37
|
-
return `${protocol}://localhost:${info.port}/`;
|
|
38
|
-
}
|
|
38
|
+
const protocol = noHttps ? "http" : "https";
|
|
39
|
+
switch (info.family) {
|
|
40
|
+
case "IPv4": return `${protocol}://${info.address}:${info.port}/`;
|
|
41
|
+
case "IPv6": return `${protocol}://[${info.address}]:${info.port}/`;
|
|
42
|
+
default: return `${protocol}://localhost:${info.port}/`;
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
async function serve({ handler
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
return started.promise;
|
|
46
|
+
* Serve HTTP requests using the provided handler.
|
|
47
|
+
* Returns a promise that resolves when the server is stopped.
|
|
48
|
+
*/
|
|
49
|
+
async function serve({ handler, port = 0, noHttps, noAuth }) {
|
|
50
|
+
const started = new _milaboratories_helpers.Deferred();
|
|
51
|
+
try {
|
|
52
|
+
let stopped = null;
|
|
53
|
+
let authToken;
|
|
54
|
+
let effectiveHandler = handler;
|
|
55
|
+
if (!noAuth) {
|
|
56
|
+
authToken = (0, node_crypto.randomUUID)();
|
|
57
|
+
effectiveHandler = require_handler.authorizeRequestHandler(effectiveHandler, authToken);
|
|
58
|
+
}
|
|
59
|
+
let encodedCaCert;
|
|
60
|
+
const defaultOptions = { keepAlive: true };
|
|
61
|
+
let server;
|
|
62
|
+
if (noHttps) server = (0, node_http.createServer)(defaultOptions, effectiveHandler);
|
|
63
|
+
else {
|
|
64
|
+
const { cert, private: key, public: ca } = await generateCertificate();
|
|
65
|
+
encodedCaCert = (0, _milaboratories_pl_model_common.base64Encode)(cert);
|
|
66
|
+
server = (0, node_https.createServer)({
|
|
67
|
+
...defaultOptions,
|
|
68
|
+
cert,
|
|
69
|
+
key,
|
|
70
|
+
ca
|
|
71
|
+
}, effectiveHandler);
|
|
72
|
+
}
|
|
73
|
+
server.on("listening", () => {
|
|
74
|
+
const url = createObjectStoreUrl(server.address(), noHttps);
|
|
75
|
+
stopped = new _milaboratories_helpers.Deferred();
|
|
76
|
+
started.resolve({
|
|
77
|
+
get info() {
|
|
78
|
+
return {
|
|
79
|
+
url,
|
|
80
|
+
authToken,
|
|
81
|
+
encodedCaCert
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
get stopped() {
|
|
85
|
+
return stopped.promise;
|
|
86
|
+
},
|
|
87
|
+
stop() {
|
|
88
|
+
server.close();
|
|
89
|
+
return stopped.promise;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}).on("error", (err) => {
|
|
93
|
+
started.reject(err);
|
|
94
|
+
stopped?.reject(err);
|
|
95
|
+
}).on("close", () => stopped?.resolve()).listen({
|
|
96
|
+
host: "localhost",
|
|
97
|
+
port
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
started.reject((0, _milaboratories_pl_model_common.ensureError)(error));
|
|
101
|
+
}
|
|
102
|
+
return started.promise;
|
|
100
103
|
}
|
|
101
|
-
|
|
104
|
+
//#endregion
|
|
102
105
|
exports.serve = serve;
|
|
103
|
-
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=serve.cjs.map
|
package/dist/serve.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.cjs","sources":["../src/serve.ts"],"sourcesContent":["import {\n createServer as createHttpServer,\n type RequestListener,\n type Server as HttpServer,\n type ServerOptions,\n} from \"node:http\";\nimport { createServer as createHttpsServer, type Server as HttpsServer } from \"node:https\";\nimport type { AddressInfo } from \"node:net\";\nimport { Deferred } from \"@milaboratories/helpers\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport { base64Encode, Base64Encoded, ensureError } from \"@milaboratories/pl-model-common\";\nimport { generate, type GenerateResult } from \"selfsigned\";\nimport { randomUUID } from \"node:crypto\";\nimport { authorizeRequestHandler } from \"./handler\";\n\n/** Generate a self-signed certificate for localhost */\nasync function generateCertificate(): Promise<GenerateResult> {\n return await generate([{ name: \"commonName\", value: \"localhost\" }], {\n keySize: 2048,\n algorithm: \"sha256\",\n extensions: [\n {\n name: \"subjectAltName\",\n altNames: [\n { type: 2, value: \"localhost\" }, // DNS\n { type: 7, ip: \"127.0.0.1\" }, // IPv4\n { type: 7, ip: \"::1\" }, // IPv6\n ],\n },\n ],\n });\n}\n\n/** Create an object store URL from the server address info. */\nfunction createObjectStoreUrl(info: AddressInfo, noHttps?: true): PFrameInternal.ObjectStoreUrl {\n const protocol = noHttps ? \"http\" : \"https\";\n switch (info.family) {\n case \"IPv4\":\n return `${protocol}://${info.address}:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n case \"IPv6\":\n return `${protocol}://[${info.address}]:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n default:\n return `${protocol}://localhost:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n }\n}\n\n/**\n * Serve HTTP requests using the provided handler.\n * Returns a promise that resolves when the server is stopped.\n */\nexport async function serve({\n handler,\n port = 0,\n noHttps,\n noAuth,\n}: PFrameInternal.HttpServerOptions): Promise<PFrameInternal.HttpServer> {\n const started = new Deferred<PFrameInternal.HttpServer>();\n try {\n let stopped: Deferred<void> | null = null;\n\n let authToken: PFrameInternal.HttpAuthorizationToken | undefined;\n let effectiveHandler: RequestListener = handler;\n if (!noAuth) {\n authToken = randomUUID() as PFrameInternal.HttpAuthorizationToken;\n effectiveHandler = authorizeRequestHandler(effectiveHandler, authToken);\n }\n\n // Create HTTP server\n let encodedCaCert: Base64Encoded<PFrameInternal.PemCertificate> | undefined;\n const defaultOptions: ServerOptions = {\n keepAlive: true,\n };\n let server: HttpServer | HttpsServer;\n\n if (noHttps) {\n server = createHttpServer(defaultOptions, effectiveHandler);\n } else {\n const { cert, private: key, public: ca } = await generateCertificate();\n encodedCaCert = base64Encode(cert as PFrameInternal.PemCertificate);\n server = createHttpsServer({ ...defaultOptions, cert, key, ca }, effectiveHandler);\n }\n\n server\n .on(\"listening\", () => {\n // Cast is safe by specification <https://nodejs.org/api/net.html#serveraddress>\n const url = createObjectStoreUrl(server.address() as AddressInfo, noHttps);\n stopped = new Deferred<void>();\n\n started.resolve({\n get info(): PFrameInternal.HttpServerInfo {\n return { url, authToken, encodedCaCert };\n },\n get stopped(): Promise<void> {\n return stopped!.promise;\n },\n stop(): Promise<void> {\n server.close();\n return stopped!.promise;\n },\n });\n })\n .on(\"error\", (err) => {\n started.reject(err);\n stopped?.reject(err);\n })\n .on(\"close\", () => stopped?.resolve())\n .listen({\n host: \"localhost\",\n port,\n });\n } catch (error: unknown) {\n started.reject(ensureError(error));\n }\n\n return started.promise;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"serve.cjs","names":["Deferred","authorizeRequestHandler"],"sources":["../src/serve.ts"],"sourcesContent":["import {\n createServer as createHttpServer,\n type RequestListener,\n type Server as HttpServer,\n type ServerOptions,\n} from \"node:http\";\nimport { createServer as createHttpsServer, type Server as HttpsServer } from \"node:https\";\nimport type { AddressInfo } from \"node:net\";\nimport { Deferred } from \"@milaboratories/helpers\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport { base64Encode, Base64Encoded, ensureError } from \"@milaboratories/pl-model-common\";\nimport { generate, type GenerateResult } from \"selfsigned\";\nimport { randomUUID } from \"node:crypto\";\nimport { authorizeRequestHandler } from \"./handler\";\n\n/** Generate a self-signed certificate for localhost */\nasync function generateCertificate(): Promise<GenerateResult> {\n return await generate([{ name: \"commonName\", value: \"localhost\" }], {\n keySize: 2048,\n algorithm: \"sha256\",\n extensions: [\n {\n name: \"subjectAltName\",\n altNames: [\n { type: 2, value: \"localhost\" }, // DNS\n { type: 7, ip: \"127.0.0.1\" }, // IPv4\n { type: 7, ip: \"::1\" }, // IPv6\n ],\n },\n ],\n });\n}\n\n/** Create an object store URL from the server address info. */\nfunction createObjectStoreUrl(info: AddressInfo, noHttps?: true): PFrameInternal.ObjectStoreUrl {\n const protocol = noHttps ? \"http\" : \"https\";\n switch (info.family) {\n case \"IPv4\":\n return `${protocol}://${info.address}:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n case \"IPv6\":\n return `${protocol}://[${info.address}]:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n default:\n return `${protocol}://localhost:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n }\n}\n\n/**\n * Serve HTTP requests using the provided handler.\n * Returns a promise that resolves when the server is stopped.\n */\nexport async function serve({\n handler,\n port = 0,\n noHttps,\n noAuth,\n}: PFrameInternal.HttpServerOptions): Promise<PFrameInternal.HttpServer> {\n const started = new Deferred<PFrameInternal.HttpServer>();\n try {\n let stopped: Deferred<void> | null = null;\n\n let authToken: PFrameInternal.HttpAuthorizationToken | undefined;\n let effectiveHandler: RequestListener = handler;\n if (!noAuth) {\n authToken = randomUUID() as PFrameInternal.HttpAuthorizationToken;\n effectiveHandler = authorizeRequestHandler(effectiveHandler, authToken);\n }\n\n // Create HTTP server\n let encodedCaCert: Base64Encoded<PFrameInternal.PemCertificate> | undefined;\n const defaultOptions: ServerOptions = {\n keepAlive: true,\n };\n let server: HttpServer | HttpsServer;\n\n if (noHttps) {\n server = createHttpServer(defaultOptions, effectiveHandler);\n } else {\n const { cert, private: key, public: ca } = await generateCertificate();\n encodedCaCert = base64Encode(cert as PFrameInternal.PemCertificate);\n server = createHttpsServer({ ...defaultOptions, cert, key, ca }, effectiveHandler);\n }\n\n server\n .on(\"listening\", () => {\n // Cast is safe by specification <https://nodejs.org/api/net.html#serveraddress>\n const url = createObjectStoreUrl(server.address() as AddressInfo, noHttps);\n stopped = new Deferred<void>();\n\n started.resolve({\n get info(): PFrameInternal.HttpServerInfo {\n return { url, authToken, encodedCaCert };\n },\n get stopped(): Promise<void> {\n return stopped!.promise;\n },\n stop(): Promise<void> {\n server.close();\n return stopped!.promise;\n },\n });\n })\n .on(\"error\", (err) => {\n started.reject(err);\n stopped?.reject(err);\n })\n .on(\"close\", () => stopped?.resolve())\n .listen({\n host: \"localhost\",\n port,\n });\n } catch (error: unknown) {\n started.reject(ensureError(error));\n }\n\n return started.promise;\n}\n"],"mappings":";;;;;;;;;AAgBA,eAAe,sBAA+C;AAC5D,QAAO,OAAA,GAAA,WAAA,UAAe,CAAC;EAAE,MAAM;EAAc,OAAO;EAAa,CAAC,EAAE;EAClE,SAAS;EACT,WAAW;EACX,YAAY,CACV;GACE,MAAM;GACN,UAAU;IACR;KAAE,MAAM;KAAG,OAAO;KAAa;IAC/B;KAAE,MAAM;KAAG,IAAI;KAAa;IAC5B;KAAE,MAAM;KAAG,IAAI;KAAO;IACvB;GACF,CACF;EACF,CAAC;;;AAIJ,SAAS,qBAAqB,MAAmB,SAA+C;CAC9F,MAAM,WAAW,UAAU,SAAS;AACpC,SAAQ,KAAK,QAAb;EACE,KAAK,OACH,QAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,GAAG,KAAK,KAAK;EACpD,KAAK,OACH,QAAO,GAAG,SAAS,MAAM,KAAK,QAAQ,IAAI,KAAK,KAAK;EACtD,QACE,QAAO,GAAG,SAAS,eAAe,KAAK,KAAK;;;;;;;AAQlD,eAAsB,MAAM,EAC1B,SACA,OAAO,GACP,SACA,UACuE;CACvE,MAAM,UAAU,IAAIA,wBAAAA,UAAqC;AACzD,KAAI;EACF,IAAI,UAAiC;EAErC,IAAI;EACJ,IAAI,mBAAoC;AACxC,MAAI,CAAC,QAAQ;AACX,gBAAA,GAAA,YAAA,aAAwB;AACxB,sBAAmBC,gBAAAA,wBAAwB,kBAAkB,UAAU;;EAIzE,IAAI;EACJ,MAAM,iBAAgC,EACpC,WAAW,MACZ;EACD,IAAI;AAEJ,MAAI,QACF,WAAA,GAAA,UAAA,cAA0B,gBAAgB,iBAAiB;OACtD;GACL,MAAM,EAAE,MAAM,SAAS,KAAK,QAAQ,OAAO,MAAM,qBAAqB;AACtE,oBAAA,GAAA,gCAAA,cAA6B,KAAsC;AACnE,aAAA,GAAA,WAAA,cAA2B;IAAE,GAAG;IAAgB;IAAM;IAAK;IAAI,EAAE,iBAAiB;;AAGpF,SACG,GAAG,mBAAmB;GAErB,MAAM,MAAM,qBAAqB,OAAO,SAAS,EAAiB,QAAQ;AAC1E,aAAU,IAAID,wBAAAA,UAAgB;AAE9B,WAAQ,QAAQ;IACd,IAAI,OAAsC;AACxC,YAAO;MAAE;MAAK;MAAW;MAAe;;IAE1C,IAAI,UAAyB;AAC3B,YAAO,QAAS;;IAElB,OAAsB;AACpB,YAAO,OAAO;AACd,YAAO,QAAS;;IAEnB,CAAC;IACF,CACD,GAAG,UAAU,QAAQ;AACpB,WAAQ,OAAO,IAAI;AACnB,YAAS,OAAO,IAAI;IACpB,CACD,GAAG,eAAe,SAAS,SAAS,CAAC,CACrC,OAAO;GACN,MAAM;GACN;GACD,CAAC;UACG,OAAgB;AACvB,UAAQ,QAAA,GAAA,gCAAA,aAAmB,MAAM,CAAC;;AAGpC,QAAO,QAAQ"}
|
package/dist/serve.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { PFrameInternal } from "@milaboratories/pl-model-middle-layer";
|
|
2
|
+
|
|
3
|
+
//#region src/serve.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Serve HTTP requests using the provided handler.
|
|
4
6
|
* Returns a promise that resolves when the server is stopped.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
declare function serve({
|
|
9
|
+
handler,
|
|
10
|
+
port,
|
|
11
|
+
noHttps,
|
|
12
|
+
noAuth
|
|
13
|
+
}: PFrameInternal.HttpServerOptions): Promise<PFrameInternal.HttpServer>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { serve };
|
|
7
16
|
//# sourceMappingURL=serve.d.ts.map
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","
|
|
1
|
+
{"version":3,"file":"serve.d.ts","names":[],"sources":["../src/serve.ts"],"mappings":";;;;;AAkDA;;iBAAsB,KAAA,CAAA;EACpB,OAAA;EACA,IAAA;EACA,OAAA;EACA;AAAA,GACC,cAAA,CAAe,iBAAA,GAAoB,OAAA,CAAQ,cAAA,CAAe,UAAA"}
|
package/dist/serve.js
CHANGED
|
@@ -1,101 +1,107 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
1
|
+
import { authorizeRequestHandler } from "./handler.js";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { base64Encode, ensureError } from "@milaboratories/pl-model-common";
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
import { createServer as createServer$1 } from "node:https";
|
|
6
|
+
import { Deferred } from "@milaboratories/helpers";
|
|
7
|
+
import { generate } from "selfsigned";
|
|
8
|
+
//#region src/serve.ts
|
|
9
9
|
/** Generate a self-signed certificate for localhost */
|
|
10
10
|
async function generateCertificate() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
return await generate([{
|
|
12
|
+
name: "commonName",
|
|
13
|
+
value: "localhost"
|
|
14
|
+
}], {
|
|
15
|
+
keySize: 2048,
|
|
16
|
+
algorithm: "sha256",
|
|
17
|
+
extensions: [{
|
|
18
|
+
name: "subjectAltName",
|
|
19
|
+
altNames: [
|
|
20
|
+
{
|
|
21
|
+
type: 2,
|
|
22
|
+
value: "localhost"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
type: 7,
|
|
26
|
+
ip: "127.0.0.1"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
type: 7,
|
|
30
|
+
ip: "::1"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}]
|
|
34
|
+
});
|
|
25
35
|
}
|
|
26
36
|
/** Create an object store URL from the server address info. */
|
|
27
37
|
function createObjectStoreUrl(info, noHttps) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
default:
|
|
35
|
-
return `${protocol}://localhost:${info.port}/`;
|
|
36
|
-
}
|
|
38
|
+
const protocol = noHttps ? "http" : "https";
|
|
39
|
+
switch (info.family) {
|
|
40
|
+
case "IPv4": return `${protocol}://${info.address}:${info.port}/`;
|
|
41
|
+
case "IPv6": return `${protocol}://[${info.address}]:${info.port}/`;
|
|
42
|
+
default: return `${protocol}://localhost:${info.port}/`;
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
async function serve({ handler, port = 0, noHttps, noAuth
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
return started.promise;
|
|
46
|
+
* Serve HTTP requests using the provided handler.
|
|
47
|
+
* Returns a promise that resolves when the server is stopped.
|
|
48
|
+
*/
|
|
49
|
+
async function serve({ handler, port = 0, noHttps, noAuth }) {
|
|
50
|
+
const started = new Deferred();
|
|
51
|
+
try {
|
|
52
|
+
let stopped = null;
|
|
53
|
+
let authToken;
|
|
54
|
+
let effectiveHandler = handler;
|
|
55
|
+
if (!noAuth) {
|
|
56
|
+
authToken = randomUUID();
|
|
57
|
+
effectiveHandler = authorizeRequestHandler(effectiveHandler, authToken);
|
|
58
|
+
}
|
|
59
|
+
let encodedCaCert;
|
|
60
|
+
const defaultOptions = { keepAlive: true };
|
|
61
|
+
let server;
|
|
62
|
+
if (noHttps) server = createServer(defaultOptions, effectiveHandler);
|
|
63
|
+
else {
|
|
64
|
+
const { cert, private: key, public: ca } = await generateCertificate();
|
|
65
|
+
encodedCaCert = base64Encode(cert);
|
|
66
|
+
server = createServer$1({
|
|
67
|
+
...defaultOptions,
|
|
68
|
+
cert,
|
|
69
|
+
key,
|
|
70
|
+
ca
|
|
71
|
+
}, effectiveHandler);
|
|
72
|
+
}
|
|
73
|
+
server.on("listening", () => {
|
|
74
|
+
const url = createObjectStoreUrl(server.address(), noHttps);
|
|
75
|
+
stopped = new Deferred();
|
|
76
|
+
started.resolve({
|
|
77
|
+
get info() {
|
|
78
|
+
return {
|
|
79
|
+
url,
|
|
80
|
+
authToken,
|
|
81
|
+
encodedCaCert
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
get stopped() {
|
|
85
|
+
return stopped.promise;
|
|
86
|
+
},
|
|
87
|
+
stop() {
|
|
88
|
+
server.close();
|
|
89
|
+
return stopped.promise;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}).on("error", (err) => {
|
|
93
|
+
started.reject(err);
|
|
94
|
+
stopped?.reject(err);
|
|
95
|
+
}).on("close", () => stopped?.resolve()).listen({
|
|
96
|
+
host: "localhost",
|
|
97
|
+
port
|
|
98
|
+
});
|
|
99
|
+
} catch (error) {
|
|
100
|
+
started.reject(ensureError(error));
|
|
101
|
+
}
|
|
102
|
+
return started.promise;
|
|
98
103
|
}
|
|
99
|
-
|
|
104
|
+
//#endregion
|
|
100
105
|
export { serve };
|
|
101
|
-
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=serve.js.map
|
package/dist/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sources":["../src/serve.ts"],"sourcesContent":["import {\n createServer as createHttpServer,\n type RequestListener,\n type Server as HttpServer,\n type ServerOptions,\n} from \"node:http\";\nimport { createServer as createHttpsServer, type Server as HttpsServer } from \"node:https\";\nimport type { AddressInfo } from \"node:net\";\nimport { Deferred } from \"@milaboratories/helpers\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport { base64Encode, Base64Encoded, ensureError } from \"@milaboratories/pl-model-common\";\nimport { generate, type GenerateResult } from \"selfsigned\";\nimport { randomUUID } from \"node:crypto\";\nimport { authorizeRequestHandler } from \"./handler\";\n\n/** Generate a self-signed certificate for localhost */\nasync function generateCertificate(): Promise<GenerateResult> {\n return await generate([{ name: \"commonName\", value: \"localhost\" }], {\n keySize: 2048,\n algorithm: \"sha256\",\n extensions: [\n {\n name: \"subjectAltName\",\n altNames: [\n { type: 2, value: \"localhost\" }, // DNS\n { type: 7, ip: \"127.0.0.1\" }, // IPv4\n { type: 7, ip: \"::1\" }, // IPv6\n ],\n },\n ],\n });\n}\n\n/** Create an object store URL from the server address info. */\nfunction createObjectStoreUrl(info: AddressInfo, noHttps?: true): PFrameInternal.ObjectStoreUrl {\n const protocol = noHttps ? \"http\" : \"https\";\n switch (info.family) {\n case \"IPv4\":\n return `${protocol}://${info.address}:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n case \"IPv6\":\n return `${protocol}://[${info.address}]:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n default:\n return `${protocol}://localhost:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n }\n}\n\n/**\n * Serve HTTP requests using the provided handler.\n * Returns a promise that resolves when the server is stopped.\n */\nexport async function serve({\n handler,\n port = 0,\n noHttps,\n noAuth,\n}: PFrameInternal.HttpServerOptions): Promise<PFrameInternal.HttpServer> {\n const started = new Deferred<PFrameInternal.HttpServer>();\n try {\n let stopped: Deferred<void> | null = null;\n\n let authToken: PFrameInternal.HttpAuthorizationToken | undefined;\n let effectiveHandler: RequestListener = handler;\n if (!noAuth) {\n authToken = randomUUID() as PFrameInternal.HttpAuthorizationToken;\n effectiveHandler = authorizeRequestHandler(effectiveHandler, authToken);\n }\n\n // Create HTTP server\n let encodedCaCert: Base64Encoded<PFrameInternal.PemCertificate> | undefined;\n const defaultOptions: ServerOptions = {\n keepAlive: true,\n };\n let server: HttpServer | HttpsServer;\n\n if (noHttps) {\n server = createHttpServer(defaultOptions, effectiveHandler);\n } else {\n const { cert, private: key, public: ca } = await generateCertificate();\n encodedCaCert = base64Encode(cert as PFrameInternal.PemCertificate);\n server = createHttpsServer({ ...defaultOptions, cert, key, ca }, effectiveHandler);\n }\n\n server\n .on(\"listening\", () => {\n // Cast is safe by specification <https://nodejs.org/api/net.html#serveraddress>\n const url = createObjectStoreUrl(server.address() as AddressInfo, noHttps);\n stopped = new Deferred<void>();\n\n started.resolve({\n get info(): PFrameInternal.HttpServerInfo {\n return { url, authToken, encodedCaCert };\n },\n get stopped(): Promise<void> {\n return stopped!.promise;\n },\n stop(): Promise<void> {\n server.close();\n return stopped!.promise;\n },\n });\n })\n .on(\"error\", (err) => {\n started.reject(err);\n stopped?.reject(err);\n })\n .on(\"close\", () => stopped?.resolve())\n .listen({\n host: \"localhost\",\n port,\n });\n } catch (error: unknown) {\n started.reject(ensureError(error));\n }\n\n return started.promise;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"serve.js","names":["createHttpServer","createHttpsServer"],"sources":["../src/serve.ts"],"sourcesContent":["import {\n createServer as createHttpServer,\n type RequestListener,\n type Server as HttpServer,\n type ServerOptions,\n} from \"node:http\";\nimport { createServer as createHttpsServer, type Server as HttpsServer } from \"node:https\";\nimport type { AddressInfo } from \"node:net\";\nimport { Deferred } from \"@milaboratories/helpers\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport { base64Encode, Base64Encoded, ensureError } from \"@milaboratories/pl-model-common\";\nimport { generate, type GenerateResult } from \"selfsigned\";\nimport { randomUUID } from \"node:crypto\";\nimport { authorizeRequestHandler } from \"./handler\";\n\n/** Generate a self-signed certificate for localhost */\nasync function generateCertificate(): Promise<GenerateResult> {\n return await generate([{ name: \"commonName\", value: \"localhost\" }], {\n keySize: 2048,\n algorithm: \"sha256\",\n extensions: [\n {\n name: \"subjectAltName\",\n altNames: [\n { type: 2, value: \"localhost\" }, // DNS\n { type: 7, ip: \"127.0.0.1\" }, // IPv4\n { type: 7, ip: \"::1\" }, // IPv6\n ],\n },\n ],\n });\n}\n\n/** Create an object store URL from the server address info. */\nfunction createObjectStoreUrl(info: AddressInfo, noHttps?: true): PFrameInternal.ObjectStoreUrl {\n const protocol = noHttps ? \"http\" : \"https\";\n switch (info.family) {\n case \"IPv4\":\n return `${protocol}://${info.address}:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n case \"IPv6\":\n return `${protocol}://[${info.address}]:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n default:\n return `${protocol}://localhost:${info.port}/` as PFrameInternal.ObjectStoreUrl;\n }\n}\n\n/**\n * Serve HTTP requests using the provided handler.\n * Returns a promise that resolves when the server is stopped.\n */\nexport async function serve({\n handler,\n port = 0,\n noHttps,\n noAuth,\n}: PFrameInternal.HttpServerOptions): Promise<PFrameInternal.HttpServer> {\n const started = new Deferred<PFrameInternal.HttpServer>();\n try {\n let stopped: Deferred<void> | null = null;\n\n let authToken: PFrameInternal.HttpAuthorizationToken | undefined;\n let effectiveHandler: RequestListener = handler;\n if (!noAuth) {\n authToken = randomUUID() as PFrameInternal.HttpAuthorizationToken;\n effectiveHandler = authorizeRequestHandler(effectiveHandler, authToken);\n }\n\n // Create HTTP server\n let encodedCaCert: Base64Encoded<PFrameInternal.PemCertificate> | undefined;\n const defaultOptions: ServerOptions = {\n keepAlive: true,\n };\n let server: HttpServer | HttpsServer;\n\n if (noHttps) {\n server = createHttpServer(defaultOptions, effectiveHandler);\n } else {\n const { cert, private: key, public: ca } = await generateCertificate();\n encodedCaCert = base64Encode(cert as PFrameInternal.PemCertificate);\n server = createHttpsServer({ ...defaultOptions, cert, key, ca }, effectiveHandler);\n }\n\n server\n .on(\"listening\", () => {\n // Cast is safe by specification <https://nodejs.org/api/net.html#serveraddress>\n const url = createObjectStoreUrl(server.address() as AddressInfo, noHttps);\n stopped = new Deferred<void>();\n\n started.resolve({\n get info(): PFrameInternal.HttpServerInfo {\n return { url, authToken, encodedCaCert };\n },\n get stopped(): Promise<void> {\n return stopped!.promise;\n },\n stop(): Promise<void> {\n server.close();\n return stopped!.promise;\n },\n });\n })\n .on(\"error\", (err) => {\n started.reject(err);\n stopped?.reject(err);\n })\n .on(\"close\", () => stopped?.resolve())\n .listen({\n host: \"localhost\",\n port,\n });\n } catch (error: unknown) {\n started.reject(ensureError(error));\n }\n\n return started.promise;\n}\n"],"mappings":";;;;;;;;;AAgBA,eAAe,sBAA+C;AAC5D,QAAO,MAAM,SAAS,CAAC;EAAE,MAAM;EAAc,OAAO;EAAa,CAAC,EAAE;EAClE,SAAS;EACT,WAAW;EACX,YAAY,CACV;GACE,MAAM;GACN,UAAU;IACR;KAAE,MAAM;KAAG,OAAO;KAAa;IAC/B;KAAE,MAAM;KAAG,IAAI;KAAa;IAC5B;KAAE,MAAM;KAAG,IAAI;KAAO;IACvB;GACF,CACF;EACF,CAAC;;;AAIJ,SAAS,qBAAqB,MAAmB,SAA+C;CAC9F,MAAM,WAAW,UAAU,SAAS;AACpC,SAAQ,KAAK,QAAb;EACE,KAAK,OACH,QAAO,GAAG,SAAS,KAAK,KAAK,QAAQ,GAAG,KAAK,KAAK;EACpD,KAAK,OACH,QAAO,GAAG,SAAS,MAAM,KAAK,QAAQ,IAAI,KAAK,KAAK;EACtD,QACE,QAAO,GAAG,SAAS,eAAe,KAAK,KAAK;;;;;;;AAQlD,eAAsB,MAAM,EAC1B,SACA,OAAO,GACP,SACA,UACuE;CACvE,MAAM,UAAU,IAAI,UAAqC;AACzD,KAAI;EACF,IAAI,UAAiC;EAErC,IAAI;EACJ,IAAI,mBAAoC;AACxC,MAAI,CAAC,QAAQ;AACX,eAAY,YAAY;AACxB,sBAAmB,wBAAwB,kBAAkB,UAAU;;EAIzE,IAAI;EACJ,MAAM,iBAAgC,EACpC,WAAW,MACZ;EACD,IAAI;AAEJ,MAAI,QACF,UAASA,aAAiB,gBAAgB,iBAAiB;OACtD;GACL,MAAM,EAAE,MAAM,SAAS,KAAK,QAAQ,OAAO,MAAM,qBAAqB;AACtE,mBAAgB,aAAa,KAAsC;AACnE,YAASC,eAAkB;IAAE,GAAG;IAAgB;IAAM;IAAK;IAAI,EAAE,iBAAiB;;AAGpF,SACG,GAAG,mBAAmB;GAErB,MAAM,MAAM,qBAAqB,OAAO,SAAS,EAAiB,QAAQ;AAC1E,aAAU,IAAI,UAAgB;AAE9B,WAAQ,QAAQ;IACd,IAAI,OAAsC;AACxC,YAAO;MAAE;MAAK;MAAW;MAAe;;IAE1C,IAAI,UAAyB;AAC3B,YAAO,QAAS;;IAElB,OAAsB;AACpB,YAAO,OAAO;AACd,YAAO,QAAS;;IAEnB,CAAC;IACF,CACD,GAAG,UAAU,QAAQ;AACpB,WAAQ,OAAO,IAAI;AACnB,YAAS,OAAO,IAAI;IACpB,CACD,GAAG,eAAe,SAAS,SAAS,CAAC,CACrC,OAAO;GACN,MAAM;GACN;GACD,CAAC;UACG,OAAgB;AACvB,UAAQ,OAAO,YAAY,MAAM,CAAC;;AAGpC,QAAO,QAAQ"}
|
package/dist/utils/etag.cjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/utils/etag.ts
|
|
3
2
|
function createETag(filename) {
|
|
4
|
-
|
|
5
|
-
const filenameETag = Buffer.from(filename, "utf8").toString("base64url");
|
|
6
|
-
return `"${filenameETag}"`;
|
|
3
|
+
return `"${Buffer.from(filename, "utf8").toString("base64url")}"`;
|
|
7
4
|
}
|
|
8
|
-
|
|
5
|
+
//#endregion
|
|
9
6
|
exports.createETag = createETag;
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=etag.cjs.map
|
package/dist/utils/etag.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etag.cjs","sources":["../../src/utils/etag.ts"],"sourcesContent":["import type { Branded } from \"@milaboratories/pl-model-common\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\n\n/**\n * See <https://datatracker.ietf.org/doc/html/rfc9110#section-8.8.3>\n *\n * Examples:\n *\n * ```text\n * ETag: \"xyzzy\"\n * ETag: W/\"xyzzy\"\n * ```\n */\nexport type Etag = Branded<string, \"Etag\">;\n\nexport function createETag(filename: PFrameInternal.ParquetFileName): Etag {\n // For immutable files, use URL-safe base64 encoded filename as ETag\n const filenameETag = Buffer.from(filename, \"utf8\").toString(\"base64url\");\n return `\"${filenameETag}\"` as Etag;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"etag.cjs","names":[],"sources":["../../src/utils/etag.ts"],"sourcesContent":["import type { Branded } from \"@milaboratories/pl-model-common\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\n\n/**\n * See <https://datatracker.ietf.org/doc/html/rfc9110#section-8.8.3>\n *\n * Examples:\n *\n * ```text\n * ETag: \"xyzzy\"\n * ETag: W/\"xyzzy\"\n * ```\n */\nexport type Etag = Branded<string, \"Etag\">;\n\nexport function createETag(filename: PFrameInternal.ParquetFileName): Etag {\n // For immutable files, use URL-safe base64 encoded filename as ETag\n const filenameETag = Buffer.from(filename, \"utf8\").toString(\"base64url\");\n return `\"${filenameETag}\"` as Etag;\n}\n"],"mappings":";AAeA,SAAgB,WAAW,UAAgD;AAGzE,QAAO,IADc,OAAO,KAAK,UAAU,OAAO,CAAC,SAAS,YAAY,CAChD"}
|
package/dist/utils/etag.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
//#region src/utils/etag.ts
|
|
1
2
|
function createETag(filename) {
|
|
2
|
-
|
|
3
|
-
const filenameETag = Buffer.from(filename, "utf8").toString("base64url");
|
|
4
|
-
return `"${filenameETag}"`;
|
|
3
|
+
return `"${Buffer.from(filename, "utf8").toString("base64url")}"`;
|
|
5
4
|
}
|
|
6
|
-
|
|
5
|
+
//#endregion
|
|
7
6
|
export { createETag };
|
|
8
|
-
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=etag.js.map
|
package/dist/utils/etag.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"etag.js","sources":["../../src/utils/etag.ts"],"sourcesContent":["import type { Branded } from \"@milaboratories/pl-model-common\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\n\n/**\n * See <https://datatracker.ietf.org/doc/html/rfc9110#section-8.8.3>\n *\n * Examples:\n *\n * ```text\n * ETag: \"xyzzy\"\n * ETag: W/\"xyzzy\"\n * ```\n */\nexport type Etag = Branded<string, \"Etag\">;\n\nexport function createETag(filename: PFrameInternal.ParquetFileName): Etag {\n // For immutable files, use URL-safe base64 encoded filename as ETag\n const filenameETag = Buffer.from(filename, \"utf8\").toString(\"base64url\");\n return `\"${filenameETag}\"` as Etag;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"etag.js","names":[],"sources":["../../src/utils/etag.ts"],"sourcesContent":["import type { Branded } from \"@milaboratories/pl-model-common\";\nimport type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\n\n/**\n * See <https://datatracker.ietf.org/doc/html/rfc9110#section-8.8.3>\n *\n * Examples:\n *\n * ```text\n * ETag: \"xyzzy\"\n * ETag: W/\"xyzzy\"\n * ```\n */\nexport type Etag = Branded<string, \"Etag\">;\n\nexport function createETag(filename: PFrameInternal.ParquetFileName): Etag {\n // For immutable files, use URL-safe base64 encoded filename as ETag\n const filenameETag = Buffer.from(filename, \"utf8\").toString(\"base64url\");\n return `\"${filenameETag}\"` as Etag;\n}\n"],"mappings":";AAeA,SAAgB,WAAW,UAAgD;AAGzE,QAAO,IADc,OAAO,KAAK,UAAU,OAAO,CAAC,SAAS,YAAY,CAChD"}
|
package/dist/utils/filename.cjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
//#region src/utils/filename.ts
|
|
3
2
|
const PARQUET_FILENAME_REGEX = /^\/([\w\-.]+.parquet)$/;
|
|
4
3
|
function getFilenameFromUrl(request) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return null;
|
|
11
|
-
return match[1];
|
|
4
|
+
const url = request.url;
|
|
5
|
+
if (url === void 0) return null;
|
|
6
|
+
const match = url.match(PARQUET_FILENAME_REGEX);
|
|
7
|
+
if (!match) return null;
|
|
8
|
+
return match[1];
|
|
12
9
|
}
|
|
13
|
-
|
|
10
|
+
//#endregion
|
|
14
11
|
exports.getFilenameFromUrl = getFilenameFromUrl;
|
|
15
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=filename.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filename.cjs","sources":["../../src/utils/filename.ts"],"sourcesContent":["import type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport type { IncomingMessage } from \"node:http\";\n\nconst PARQUET_FILENAME_REGEX = /^\\/([\\w\\-.]+.parquet)$/;\n\nexport function getFilenameFromUrl(\n request: IncomingMessage,\n): PFrameInternal.ParquetFileName | null {\n const url = request.url;\n if (url === undefined) return null;\n\n const match = url.match(PARQUET_FILENAME_REGEX);\n if (!match) return null;\n\n return match[1] as PFrameInternal.ParquetFileName;\n}\n"],"
|
|
1
|
+
{"version":3,"file":"filename.cjs","names":[],"sources":["../../src/utils/filename.ts"],"sourcesContent":["import type { PFrameInternal } from \"@milaboratories/pl-model-middle-layer\";\nimport type { IncomingMessage } from \"node:http\";\n\nconst PARQUET_FILENAME_REGEX = /^\\/([\\w\\-.]+.parquet)$/;\n\nexport function getFilenameFromUrl(\n request: IncomingMessage,\n): PFrameInternal.ParquetFileName | null {\n const url = request.url;\n if (url === undefined) return null;\n\n const match = url.match(PARQUET_FILENAME_REGEX);\n if (!match) return null;\n\n return match[1] as PFrameInternal.ParquetFileName;\n}\n"],"mappings":";AAGA,MAAM,yBAAyB;AAE/B,SAAgB,mBACd,SACuC;CACvC,MAAM,MAAM,QAAQ;AACpB,KAAI,QAAQ,KAAA,EAAW,QAAO;CAE9B,MAAM,QAAQ,IAAI,MAAM,uBAAuB;AAC/C,KAAI,CAAC,MAAO,QAAO;AAEnB,QAAO,MAAM"}
|
package/dist/utils/filename.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
//#region src/utils/filename.ts
|
|
1
2
|
const PARQUET_FILENAME_REGEX = /^\/([\w\-.]+.parquet)$/;
|
|
2
3
|
function getFilenameFromUrl(request) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return null;
|
|
9
|
-
return match[1];
|
|
4
|
+
const url = request.url;
|
|
5
|
+
if (url === void 0) return null;
|
|
6
|
+
const match = url.match(PARQUET_FILENAME_REGEX);
|
|
7
|
+
if (!match) return null;
|
|
8
|
+
return match[1];
|
|
10
9
|
}
|
|
11
|
-
|
|
10
|
+
//#endregion
|
|
12
11
|
export { getFilenameFromUrl };
|
|
13
|
-
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=filename.js.map
|