@milaboratories/pl-model-middle-layer 1.30.4 → 1.30.6
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/block_meta/block_description.d.ts +2 -2
- package/dist/block_registry/overview.d.ts +18 -18
- package/dist/block_registry/registry_spec.d.ts +12 -12
- package/dist/pframe/internal_api/api_read.d.ts +2 -24
- package/dist/pframe/internal_api/api_read.d.ts.map +1 -1
- package/dist/pframe/internal_api/http_helpers.cjs.map +1 -1
- package/dist/pframe/internal_api/http_helpers.d.ts +71 -2
- package/dist/pframe/internal_api/http_helpers.d.ts.map +1 -1
- package/dist/pframe/internal_api/http_helpers.js.map +1 -1
- package/dist/pframe/internal_api/index.d.ts +5 -5
- package/dist/pframe/internal_api/pframe.d.ts +3 -36
- package/dist/pframe/internal_api/pframe.d.ts.map +1 -1
- package/dist/pframe/internal_api/table.d.ts +4 -73
- package/dist/pframe/internal_api/table.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/pframe/internal_api/api_read.ts +1 -28
- package/src/pframe/internal_api/http_helpers.ts +91 -2
- package/src/pframe/internal_api/pframe.ts +2 -38
- package/src/pframe/internal_api/table.ts +3 -79
|
@@ -679,6 +679,7 @@ declare const BlockPackDescriptionFromPackageJsonRaw: z.ZodObject<{
|
|
|
679
679
|
};
|
|
680
680
|
title: string;
|
|
681
681
|
description: string;
|
|
682
|
+
url?: string | undefined;
|
|
682
683
|
longDescription?: {
|
|
683
684
|
type: "relative";
|
|
684
685
|
path: string;
|
|
@@ -710,7 +711,6 @@ declare const BlockPackDescriptionFromPackageJsonRaw: z.ZodObject<{
|
|
|
710
711
|
type: "absolute-file";
|
|
711
712
|
file: string;
|
|
712
713
|
} | undefined;
|
|
713
|
-
url?: string | undefined;
|
|
714
714
|
docs?: string | undefined;
|
|
715
715
|
support?: string | undefined;
|
|
716
716
|
tags?: string[] | undefined;
|
|
@@ -751,6 +751,7 @@ declare const BlockPackDescriptionFromPackageJsonRaw: z.ZodObject<{
|
|
|
751
751
|
};
|
|
752
752
|
title: string;
|
|
753
753
|
description: string;
|
|
754
|
+
url?: string | undefined;
|
|
754
755
|
longDescription?: string | {
|
|
755
756
|
type: "relative";
|
|
756
757
|
path: string;
|
|
@@ -782,7 +783,6 @@ declare const BlockPackDescriptionFromPackageJsonRaw: z.ZodObject<{
|
|
|
782
783
|
type: "absolute-file";
|
|
783
784
|
file: string;
|
|
784
785
|
} | undefined;
|
|
785
|
-
url?: string | undefined;
|
|
786
786
|
docs?: string | undefined;
|
|
787
787
|
support?: string | undefined;
|
|
788
788
|
tags?: string[] | undefined;
|
|
@@ -10006,28 +10006,28 @@ declare const RegistryStatus: z.ZodObject<{
|
|
|
10006
10006
|
status: "online" | "offline";
|
|
10007
10007
|
id: string;
|
|
10008
10008
|
spec: {
|
|
10009
|
+
type: "local-dev";
|
|
10010
|
+
path: string;
|
|
10011
|
+
} | {
|
|
10009
10012
|
type: "remote-v1";
|
|
10010
10013
|
url: string;
|
|
10011
10014
|
} | {
|
|
10012
10015
|
type: "remote-v2";
|
|
10013
10016
|
url: string;
|
|
10014
|
-
} | {
|
|
10015
|
-
type: "local-dev";
|
|
10016
|
-
path: string;
|
|
10017
10017
|
};
|
|
10018
10018
|
title?: string | undefined;
|
|
10019
10019
|
}, {
|
|
10020
10020
|
status: "online" | "offline";
|
|
10021
10021
|
id: string;
|
|
10022
10022
|
spec: {
|
|
10023
|
+
type: "local-dev";
|
|
10024
|
+
path: string;
|
|
10025
|
+
} | {
|
|
10023
10026
|
type: "remote-v1";
|
|
10024
10027
|
url: string;
|
|
10025
10028
|
} | {
|
|
10026
10029
|
type: "remote-v2";
|
|
10027
10030
|
url: string;
|
|
10028
|
-
} | {
|
|
10029
|
-
type: "local-dev";
|
|
10030
|
-
path: string;
|
|
10031
10031
|
};
|
|
10032
10032
|
title?: string | undefined;
|
|
10033
10033
|
}>;
|
|
@@ -10070,28 +10070,28 @@ declare const BlockPackListing: z.ZodObject<{
|
|
|
10070
10070
|
status: "online" | "offline";
|
|
10071
10071
|
id: string;
|
|
10072
10072
|
spec: {
|
|
10073
|
+
type: "local-dev";
|
|
10074
|
+
path: string;
|
|
10075
|
+
} | {
|
|
10073
10076
|
type: "remote-v1";
|
|
10074
10077
|
url: string;
|
|
10075
10078
|
} | {
|
|
10076
10079
|
type: "remote-v2";
|
|
10077
10080
|
url: string;
|
|
10078
|
-
} | {
|
|
10079
|
-
type: "local-dev";
|
|
10080
|
-
path: string;
|
|
10081
10081
|
};
|
|
10082
10082
|
title?: string | undefined;
|
|
10083
10083
|
}, {
|
|
10084
10084
|
status: "online" | "offline";
|
|
10085
10085
|
id: string;
|
|
10086
10086
|
spec: {
|
|
10087
|
+
type: "local-dev";
|
|
10088
|
+
path: string;
|
|
10089
|
+
} | {
|
|
10087
10090
|
type: "remote-v1";
|
|
10088
10091
|
url: string;
|
|
10089
10092
|
} | {
|
|
10090
10093
|
type: "remote-v2";
|
|
10091
10094
|
url: string;
|
|
10092
|
-
} | {
|
|
10093
|
-
type: "local-dev";
|
|
10094
|
-
path: string;
|
|
10095
10095
|
};
|
|
10096
10096
|
title?: string | undefined;
|
|
10097
10097
|
}>, "many">;
|
|
@@ -13197,14 +13197,14 @@ declare const BlockPackListing: z.ZodObject<{
|
|
|
13197
13197
|
status: "online" | "offline";
|
|
13198
13198
|
id: string;
|
|
13199
13199
|
spec: {
|
|
13200
|
+
type: "local-dev";
|
|
13201
|
+
path: string;
|
|
13202
|
+
} | {
|
|
13200
13203
|
type: "remote-v1";
|
|
13201
13204
|
url: string;
|
|
13202
13205
|
} | {
|
|
13203
13206
|
type: "remote-v2";
|
|
13204
13207
|
url: string;
|
|
13205
|
-
} | {
|
|
13206
|
-
type: "local-dev";
|
|
13207
|
-
path: string;
|
|
13208
13208
|
};
|
|
13209
13209
|
title?: string | undefined;
|
|
13210
13210
|
}[];
|
|
@@ -14246,14 +14246,14 @@ declare const BlockPackListing: z.ZodObject<{
|
|
|
14246
14246
|
status: "online" | "offline";
|
|
14247
14247
|
id: string;
|
|
14248
14248
|
spec: {
|
|
14249
|
+
type: "local-dev";
|
|
14250
|
+
path: string;
|
|
14251
|
+
} | {
|
|
14249
14252
|
type: "remote-v1";
|
|
14250
14253
|
url: string;
|
|
14251
14254
|
} | {
|
|
14252
14255
|
type: "remote-v2";
|
|
14253
14256
|
url: string;
|
|
14254
|
-
} | {
|
|
14255
|
-
type: "local-dev";
|
|
14256
|
-
path: string;
|
|
14257
14257
|
};
|
|
14258
14258
|
title?: string | undefined;
|
|
14259
14259
|
}[];
|
|
@@ -99,27 +99,27 @@ declare const RegistryEntry: z.ZodObject<{
|
|
|
99
99
|
}, "strip", z.ZodTypeAny, {
|
|
100
100
|
id: string;
|
|
101
101
|
spec: {
|
|
102
|
+
type: "local-dev";
|
|
103
|
+
path: string;
|
|
104
|
+
} | {
|
|
102
105
|
type: "remote-v1";
|
|
103
106
|
url: string;
|
|
104
107
|
} | {
|
|
105
108
|
type: "remote-v2";
|
|
106
109
|
url: string;
|
|
107
|
-
} | {
|
|
108
|
-
type: "local-dev";
|
|
109
|
-
path: string;
|
|
110
110
|
};
|
|
111
111
|
title?: string | undefined;
|
|
112
112
|
}, {
|
|
113
113
|
id: string;
|
|
114
114
|
spec: {
|
|
115
|
+
type: "local-dev";
|
|
116
|
+
path: string;
|
|
117
|
+
} | {
|
|
115
118
|
type: "remote-v1";
|
|
116
119
|
url: string;
|
|
117
120
|
} | {
|
|
118
121
|
type: "remote-v2";
|
|
119
122
|
url: string;
|
|
120
|
-
} | {
|
|
121
|
-
type: "local-dev";
|
|
122
|
-
path: string;
|
|
123
123
|
};
|
|
124
124
|
title?: string | undefined;
|
|
125
125
|
}>;
|
|
@@ -158,27 +158,27 @@ declare const RegistryList: z.ZodArray<z.ZodObject<{
|
|
|
158
158
|
}, "strip", z.ZodTypeAny, {
|
|
159
159
|
id: string;
|
|
160
160
|
spec: {
|
|
161
|
+
type: "local-dev";
|
|
162
|
+
path: string;
|
|
163
|
+
} | {
|
|
161
164
|
type: "remote-v1";
|
|
162
165
|
url: string;
|
|
163
166
|
} | {
|
|
164
167
|
type: "remote-v2";
|
|
165
168
|
url: string;
|
|
166
|
-
} | {
|
|
167
|
-
type: "local-dev";
|
|
168
|
-
path: string;
|
|
169
169
|
};
|
|
170
170
|
title?: string | undefined;
|
|
171
171
|
}, {
|
|
172
172
|
id: string;
|
|
173
173
|
spec: {
|
|
174
|
+
type: "local-dev";
|
|
175
|
+
path: string;
|
|
176
|
+
} | {
|
|
174
177
|
type: "remote-v1";
|
|
175
178
|
url: string;
|
|
176
179
|
} | {
|
|
177
180
|
type: "remote-v2";
|
|
178
181
|
url: string;
|
|
179
|
-
} | {
|
|
180
|
-
type: "local-dev";
|
|
181
|
-
path: string;
|
|
182
182
|
};
|
|
183
183
|
title?: string | undefined;
|
|
184
184
|
}>, "many">;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PTableV12 } from "./table.js";
|
|
2
2
|
import { PTableId } from "./common.js";
|
|
3
3
|
import { DataQuery, DataQueryBooleanExpression, PObjectId, UniqueValuesResponse } from "@milaboratories/pl-model-common";
|
|
4
4
|
|
|
@@ -32,9 +32,6 @@ interface UniqueValuesRequestV2 {
|
|
|
32
32
|
* `PTableV*` interface is dropped, so this declaration repeats the full
|
|
33
33
|
* method surface rather than referencing the predecessors.
|
|
34
34
|
*
|
|
35
|
-
* Same surface as {@link PFrameReadAPIV14}; the only change is that
|
|
36
|
-
* {@link PFrameReadAPIV15.createTable} returns {@link PTableV12}.
|
|
37
|
-
*
|
|
38
35
|
* Spec-side operations (finding columns, listing columns, retrieving
|
|
39
36
|
* column specs, computing axis integrations) are not part of this
|
|
40
37
|
* surface — callers cache column specs themselves or route through
|
|
@@ -50,25 +47,6 @@ interface PFrameReadAPIV15 {
|
|
|
50
47
|
signal?: AbortSignal;
|
|
51
48
|
}): Promise<UniqueValuesResponse>;
|
|
52
49
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Read interface exposed by PFrames library. Returns the {@link PTableV11}
|
|
55
|
-
* table view, whose `export` takes a column-index → header map.
|
|
56
|
-
*
|
|
57
|
-
* Spec-side operations (finding columns, listing columns, retrieving
|
|
58
|
-
* column specs, computing axis integrations) are not part of this
|
|
59
|
-
* surface — callers cache column specs themselves or route through
|
|
60
|
-
* WASM-spec. The data-side `createTable` accepts a pre-lowered
|
|
61
|
-
* `DataQuery`; `getUniqueValues` takes pre-resolved indices via
|
|
62
|
-
* {@link UniqueValuesRequestV2}.
|
|
63
|
-
*/
|
|
64
|
-
interface PFrameReadAPIV14 {
|
|
65
|
-
/** Creates table from a pre-lowered data query. */
|
|
66
|
-
createTable(tableId: PTableId, dataQuery: DataQuery): PTableV11;
|
|
67
|
-
/** Calculate set of unique values for a specific axis for the filtered set of records. */
|
|
68
|
-
getUniqueValues(request: UniqueValuesRequestV2, ops?: {
|
|
69
|
-
signal?: AbortSignal;
|
|
70
|
-
}): Promise<UniqueValuesResponse>;
|
|
71
|
-
}
|
|
72
50
|
//#endregion
|
|
73
|
-
export {
|
|
51
|
+
export { PFrameReadAPIV15, UniqueValuesRequestV2 };
|
|
74
52
|
//# sourceMappingURL=api_read.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api_read.d.ts","names":[],"sources":["../../../src/pframe/internal_api/api_read.ts"],"mappings":";;;;;;;AAeA;;;;UAAiB,qBAAA;EAEI;EAAA,SAAV,QAAA,EAAU,SAAA;EASV;;;;EAAA,SAHA,SAAA;
|
|
1
|
+
{"version":3,"file":"api_read.d.ts","names":[],"sources":["../../../src/pframe/internal_api/api_read.ts"],"mappings":";;;;;;;AAeA;;;;UAAiB,qBAAA;EAEI;EAAA,SAAV,QAAA,EAAU,SAAA;EASV;;;;EAAA,SAHA,SAAA;EA0BM;EAAA,SAvBN,OAAA,EAAS,0BAAA;;WAGT,KAAA;AAAA;;;;;;;;;;;;;;;;;;UAoBM,gBAAA;EAOb;EALF,WAAA,CAAY,OAAA,EAAS,QAAA,EAAU,SAAA,EAAW,SAAA,GAAY,SAAA;EAQ3C;EALX,eAAA,CACE,OAAA,EAAS,qBAAA,EACT,GAAA;IACE,MAAA,GAAS,WAAA;EAAA,IAEV,OAAA,CAAQ,oBAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_helpers.cjs","names":[],"sources":["../../../src/pframe/internal_api/http_helpers.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport type { RequestListener } from \"node:http\";\nimport type { Branded, Base64Encoded } from \"@milaboratories/pl-model-common\";\nimport type { Logger } from \"./common\";\n\n/** Parquet file extension */\nexport const ParquetExtension = \".parquet\" as const;\n\n/** Parquet file name */\nexport type ParquetFileName = Branded<`${string}.parquet`, \"PFrameInternal.ParquetFileName\">;\n\nexport type FileRange = {\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n};\n\n/** HTTP range as of RFC 9110 <https://datatracker.ietf.org/doc/html/rfc9110#name-range> */\nexport type HttpRange =\n | {\n /**\n * Get file content in the specified byte range\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=0-1023\n * ```\n */\n type: \"bounded\";\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n }\n | {\n /**\n * Get byte range starting from the specified offset\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=1024-\n * ```\n */\n type: \"offset\";\n /** Start byte position (inclusive) */\n offset: number;\n }\n | {\n /**\n * Get byte range starting from the specified suffix\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=-1024\n * ```\n */\n type: \"suffix\";\n /** End byte position (inclusive) */\n suffix: number;\n };\n\n/** HTTP method passed to object store */\nexport type HttpMethod = \"GET\" | \"HEAD\";\n\n/** HTTP response from object store */\nexport type ObjectStoreResponse =\n | {\n /**\n * Will be translated to 500 Internal Server Error by the handler\n * or 408 Request Timeout if the request was aborted\n */\n type: \"InternalError\";\n }\n | {\n /** Will be translated to 404 Not Found by the handler */\n type: \"NotFound\";\n }\n | {\n /** Will be translated to 416 Range Not Satisfiable by the handler */\n type: \"RangeNotSatisfiable\";\n /** Total file size in bytes */\n size: number;\n }\n | {\n /** Will be translated to 200 OK or 206 Partial Content by the handler */\n type: \"Ok\";\n /** Total file size in bytes */\n size: number;\n /** File range translated from HTTP range */\n range: FileRange;\n /** Stream of file content, undefined for HEAD requests */\n data?: Readable;\n };\n\n/** Common options for object store creation */\nexport interface ObjectStoreOptions {\n /** Logger instance, no logging is performed when not provided */\n logger?: Logger;\n}\n\n/** Options for file system object store creation */\nexport interface FsStoreOptions extends ObjectStoreOptions {\n /** Local directory to serve files from */\n rootDir: string;\n}\n\nexport interface ObjectStore {\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): void;\n}\n\n/** File system abstraction for request handler factory, @see HttpHelpers.createRequestHandler */\nexport abstract class BaseObjectStore implements ObjectStore {\n protected readonly logger: Logger;\n\n constructor(options: ObjectStoreOptions) {\n this.logger = options.logger ?? (() => {});\n }\n\n /** Translate HTTP range to file range, @returns null if the range is not satisfiable */\n protected translate(fileSize: number, range?: HttpRange): FileRange | null {\n if (!range) return { start: 0, end: fileSize - 1 };\n switch (range.type) {\n case \"bounded\":\n if (range.end >= fileSize) return null;\n return { start: range.start, end: range.end };\n case \"offset\":\n if (range.offset >= fileSize) return null;\n return { start: range.offset, end: fileSize - 1 };\n case \"suffix\":\n if (range.suffix > fileSize) return null;\n return { start: fileSize - range.suffix, end: fileSize - 1 };\n }\n }\n\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n abstract request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): Promise<void>;\n}\n\n/** Object store base URL in format accepted by Apache DataFusion and DuckDB */\nexport type ObjectStoreUrl = Branded<string, \"PFrameInternal.ObjectStoreUrl\">;\n\n/** HTTP(S) request handler creation options */\nexport type RequestHandlerOptions = {\n /** Object store to serve files from, @see HttpHelpers.createFsStore */\n store: ObjectStore;\n /** Here will go caching options... */\n};\n\n/** Server configuration options */\nexport type HttpServerOptions = {\n /** HTTP(S) request handler function, @see HttpHelpers.createRequestHandler */\n handler: RequestListener;\n /** Port to bind to, @default 0 for auto-assignment */\n port?: number;\n /** Do not apply authorization middleware to @param handler */\n noAuth?: true;\n /** Downgrade default HTTPS server to plain HTTP, @warning use only for testing */\n noHttps?: true;\n};\n\n/**\n * Long unique opaque string for use in Bearer authorization header\n *\n * @example\n * ```ts\n * request.setHeader('Authorization', `Bearer ${authToken}`);\n * ```\n */\nexport type HttpAuthorizationToken = Branded<string, \"PFrameInternal.HttpAuthorizationToken\">;\n\n/**\n * TLS certificate in PEM format\n *\n * @example\n * ```txt\n * -----BEGIN CERTIFICATE-----\n * MIIC2zCCAcOgAwIBAgIJaVW7...\n * ...\n * ...Yf9CRK8fgnukKM7TJ\n * -----END CERTIFICATE-----\n * ```\n */\nexport type PemCertificate = Branded<string, \"PFrameInternal.PemCertificate\">;\n\n/** HTTP(S) server connection settings, {@link HttpHelpers.createHttpServer} */\nexport type HttpServerInfo = {\n /** URL of the HTTP(S) server formatted as `http{s}://<host>:<port>/` */\n url: ObjectStoreUrl;\n /** Authorization token for Bearer scheme, undefined when @see HttpServerOptions.noAuth flag is set */\n authToken?: HttpAuthorizationToken;\n /** Encoded CA certificate of HTTPS server, undefined when @see HttpServerOptions.noHttps flag is set */\n encodedCaCert?: Base64Encoded<PemCertificate>;\n};\n\n/** HTTP(S) server information and controls, @see HttpHelpers.createHttpServer */\nexport interface HttpServer {\n /** Server configuration information for initiating connections from clients */\n get info(): HttpServerInfo;\n /** Promise that resolves when the server is stopped */\n get stopped(): Promise<void>;\n /** Request server stop, returns the same promise as @see HttpServer.stopped */\n stop(): Promise<void>;\n}\n\n/** List of HTTP(S) related helper functions exposed by PFrame module */\nexport interface HttpHelpers {\n /**\n * Create an object store for serving files from a local directory.\n * Rejects if the provided path does not exist or is not a directory.\n */\n createFsStore(options: FsStoreOptions): Promise<ObjectStore>;\n\n /**\n * Create an HTTP request handler for serving files from an object store.\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 otherwise.\n * Assumes that files are immutable (and sets cache headers accordingly).\n */\n createRequestHandler(options: RequestHandlerOptions): RequestListener;\n\n /**\n * Serve HTTP(S) requests using the provided handler on localhost port.\n * @returns promise that resolves when the server has stopped.\n *\n * @example\n * ```ts\n * const rootDir = '/path/to/directory/with/parquet/files';\n *\n * let store = await HttpHelpers.createFsStore({ rootDir }).catch((err: unknown) => {\n * throw new Error(`Failed to create file store for ${rootDir} - ${ensureError(err)}`);\n * });\n *\n * const server = await HttpHelpers.createHttpServer({\n * handler: HttpHelpers.createRequestHandler({ store }),\n * }).catch((err: unknown) => {\n * throw new Error(`Failed to start HTTPS server - ${ensureError(err)}`);\n * });\n *\n * const { url, authToken, encodedCaCert } = server.info;\n *\n * await server.stop();\n * ```\n */\n createHttpServer(options: HttpServerOptions): Promise<HttpServer>;\n}\n"],"mappings":";;AAMA,MAAa,mBAAmB;;AA0HhC,IAAsB,kBAAtB,MAA6D;CAC3D;CAEA,YAAY,SAA6B;AACvC,OAAK,SAAS,QAAQ,iBAAiB;;;CAIzC,UAAoB,UAAkB,OAAqC;AACzE,MAAI,CAAC,MAAO,QAAO;GAAE,OAAO;GAAG,KAAK,WAAW;GAAG;AAClD,UAAQ,MAAM,MAAd;GACE,KAAK;AACH,QAAI,MAAM,OAAO,SAAU,QAAO;AAClC,WAAO;KAAE,OAAO,MAAM;KAAO,KAAK,MAAM;KAAK;GAC/C,KAAK;AACH,QAAI,MAAM,UAAU,SAAU,QAAO;AACrC,WAAO;KAAE,OAAO,MAAM;KAAQ,KAAK,WAAW;KAAG;GACnD,KAAK;AACH,QAAI,MAAM,SAAS,SAAU,QAAO;AACpC,WAAO;KAAE,OAAO,WAAW,MAAM;KAAQ,KAAK,WAAW;KAAG"}
|
|
1
|
+
{"version":3,"file":"http_helpers.cjs","names":[],"sources":["../../../src/pframe/internal_api/http_helpers.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport type { RequestListener } from \"node:http\";\nimport type { Branded, Base64Encoded } from \"@milaboratories/pl-model-common\";\nimport type { Logger } from \"./common\";\n\n/** Parquet file extension */\nexport const ParquetExtension = \".parquet\" as const;\n\n/** Parquet file name */\nexport type ParquetFileName = Branded<`${string}.parquet`, \"PFrameInternal.ParquetFileName\">;\n\nexport type FileRange = {\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n};\n\n/** HTTP range as of RFC 9110 <https://datatracker.ietf.org/doc/html/rfc9110#name-range> */\nexport type HttpRange =\n | {\n /**\n * Get file content in the specified byte range\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=0-1023\n * ```\n */\n type: \"bounded\";\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n }\n | {\n /**\n * Get byte range starting from the specified offset\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=1024-\n * ```\n */\n type: \"offset\";\n /** Start byte position (inclusive) */\n offset: number;\n }\n | {\n /**\n * Get byte range starting from the specified suffix\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=-1024\n * ```\n */\n type: \"suffix\";\n /** End byte position (inclusive) */\n suffix: number;\n };\n\n/** HTTP method passed to object store */\nexport type HttpMethod = \"GET\" | \"HEAD\";\n\n/** HTTP response from object store */\nexport type ObjectStoreResponse =\n | {\n /**\n * Will be translated to 500 Internal Server Error by the handler\n * or 408 Request Timeout if the request was aborted\n */\n type: \"InternalError\";\n }\n | {\n /** Will be translated to 404 Not Found by the handler */\n type: \"NotFound\";\n }\n | {\n /** Will be translated to 416 Range Not Satisfiable by the handler */\n type: \"RangeNotSatisfiable\";\n /** Total file size in bytes */\n size: number;\n }\n | {\n /** Will be translated to 200 OK or 206 Partial Content by the handler */\n type: \"Ok\";\n /** Total file size in bytes */\n size: number;\n /** File range translated from HTTP range */\n range: FileRange;\n /** Stream of file content, undefined for HEAD requests */\n data?: Readable;\n };\n\n/** Common options for object store creation */\nexport interface ObjectStoreOptions {\n /** Logger instance, no logging is performed when not provided */\n logger?: Logger;\n}\n\n/** Options for file system object store creation */\nexport interface FsStoreOptions extends ObjectStoreOptions {\n /** Local directory to serve files from */\n rootDir: string;\n}\n\nexport interface ObjectStore {\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): void;\n}\n\n/** File system abstraction for request handler factory, @see HttpHelpers.createRequestHandler */\nexport abstract class BaseObjectStore implements ObjectStore {\n protected readonly logger: Logger;\n\n constructor(options: ObjectStoreOptions) {\n this.logger = options.logger ?? (() => {});\n }\n\n /** Translate HTTP range to file range, @returns null if the range is not satisfiable */\n protected translate(fileSize: number, range?: HttpRange): FileRange | null {\n if (!range) return { start: 0, end: fileSize - 1 };\n switch (range.type) {\n case \"bounded\":\n if (range.end >= fileSize) return null;\n return { start: range.start, end: range.end };\n case \"offset\":\n if (range.offset >= fileSize) return null;\n return { start: range.offset, end: fileSize - 1 };\n case \"suffix\":\n if (range.suffix > fileSize) return null;\n return { start: fileSize - range.suffix, end: fileSize - 1 };\n }\n }\n\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n abstract request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): Promise<void>;\n}\n\n/** Configuration for {@link HttpHelpers.createCachingObjectStore} */\nexport type CacheConfig = {\n /** Filesystem path where the cache persists its data */\n cachePath: string;\n /** Hard total size budget in bytes; the cache self-stabilizes near this size */\n maxSizeBytes: number;\n /**\n * Max share of the budget a single file may occupy (0..1); when a file exceeds it, that\n * file's oldest ranges are evicted first. Stops one large scan from flushing the working set.\n */\n admissionFraction: number;\n /** Upper bound on previously-evicted (ghost) files remembered to guide readmission; resident files are already byte-bounded */\n maxFilesTracked: number;\n};\n\n/**\n * Cumulative cache event counters. Surfaced both as lifetime totals (persisted across restarts)\n * and as a per-process session view, @see CacheMetrics.\n */\nexport type CacheCounters = {\n /** Requests fully served from cache */\n hits: number;\n /** Requests that fell through to upstream */\n misses: number;\n /** Bytes served from cache */\n bytesServed: number;\n /** Bytes downloaded from upstream on misses */\n bytesFetched: number;\n /** Bytes evicted to keep the cache within its total size budget, @see CacheConfig.maxSizeBytes */\n bytesEvictedByBudget: number;\n /** Bytes evicted because a single file exceeded its allowed share of the budget, @see CacheConfig.admissionFraction */\n bytesEvictedByFileCap: number;\n /** Files promoted on observed reuse, so they are retained longer than first-time entries */\n promotions: number;\n /** Previously evicted files that were re-requested and readmitted */\n ghostReadmissions: number;\n};\n\n/** Snapshot of cache state and counters, @see CachingObjectStore.getMetrics */\nexport type CacheMetrics = {\n /** Current resident bytes */\n sizeBytes: number;\n /** Number of files with resident (cached) bytes */\n residentFiles: number;\n /** Number of previously-evicted (ghost) files remembered, <= @see CacheConfig.maxFilesTracked */\n ghostFiles: number;\n /** Counters cumulative across all sessions (persisted) */\n lifetime: CacheCounters;\n /** The same counters scoped to the current process */\n session: CacheCounters;\n};\n\n/**\n * Options for caching object store creation, @see HttpHelpers.createCachingObjectStore.\n * Standalone (not extending {@link ObjectStoreOptions}): a caching store is a decorator over\n * `upstream`, so source-store options do not apply to it.\n */\nexport interface CachingObjectStoreOptions {\n /** Upstream store consulted on cache misses */\n upstream: ObjectStore;\n /** Cache configuration */\n config: CacheConfig;\n /** Logger instance, no logging is performed when not provided */\n logger?: Logger;\n}\n\n/**\n * An {@link ObjectStore} that serves byte ranges from a persistent local cache, fetching misses\n * from an upstream store. This is the single handle for the cache: pass it as\n * {@link RequestHandlerOptions.store}, read {@link CachingObjectStore.getMetrics}, and dispose it\n * to release the cache, @see HttpHelpers.createCachingObjectStore.\n */\nexport interface CachingObjectStore extends ObjectStore, AsyncDisposable {\n /** Instantaneous cache state plus lifetime/session counters */\n getMetrics(): CacheMetrics;\n /** Drop all cached data and zero the counters (test/benchmark use) */\n reset(): Promise<void>;\n}\n\n/** Object store base URL in format accepted by Apache DataFusion and DuckDB */\nexport type ObjectStoreUrl = Branded<string, \"PFrameInternal.ObjectStoreUrl\">;\n\n/** HTTP(S) request handler creation options */\nexport type RequestHandlerOptions = {\n /**\n * Object store to serve files from. Compose caching by wrapping the upstream store with\n * {@link HttpHelpers.createCachingObjectStore} and passing the result here,\n * @see HttpHelpers.createFsStore\n */\n store: ObjectStore;\n};\n\n/** Server configuration options */\nexport type HttpServerOptions = {\n /** HTTP(S) request handler function, @see HttpHelpers.createRequestHandler */\n handler: RequestListener;\n /** Port to bind to, @default 0 for auto-assignment */\n port?: number;\n /** Do not apply authorization middleware to @param handler */\n noAuth?: true;\n /** Downgrade default HTTPS server to plain HTTP, @warning use only for testing */\n noHttps?: true;\n};\n\n/**\n * Long unique opaque string for use in Bearer authorization header\n *\n * @example\n * ```ts\n * request.setHeader('Authorization', `Bearer ${authToken}`);\n * ```\n */\nexport type HttpAuthorizationToken = Branded<string, \"PFrameInternal.HttpAuthorizationToken\">;\n\n/**\n * TLS certificate in PEM format\n *\n * @example\n * ```txt\n * -----BEGIN CERTIFICATE-----\n * MIIC2zCCAcOgAwIBAgIJaVW7...\n * ...\n * ...Yf9CRK8fgnukKM7TJ\n * -----END CERTIFICATE-----\n * ```\n */\nexport type PemCertificate = Branded<string, \"PFrameInternal.PemCertificate\">;\n\n/** HTTP(S) server connection settings, {@link HttpHelpers.createHttpServer} */\nexport type HttpServerInfo = {\n /** URL of the HTTP(S) server formatted as `http{s}://<host>:<port>/` */\n url: ObjectStoreUrl;\n /** Authorization token for Bearer scheme, undefined when @see HttpServerOptions.noAuth flag is set */\n authToken?: HttpAuthorizationToken;\n /** Encoded CA certificate of HTTPS server, undefined when @see HttpServerOptions.noHttps flag is set */\n encodedCaCert?: Base64Encoded<PemCertificate>;\n};\n\n/** HTTP(S) server information and controls, @see HttpHelpers.createHttpServer */\nexport interface HttpServer {\n /** Server configuration information for initiating connections from clients */\n get info(): HttpServerInfo;\n /** Promise that resolves when the server is stopped */\n get stopped(): Promise<void>;\n /** Request server stop, returns the same promise as @see HttpServer.stopped */\n stop(): Promise<void>;\n}\n\n/** List of HTTP(S) related helper functions exposed by PFrame module */\nexport interface HttpHelpers {\n /**\n * Create an object store for serving files from a local directory.\n * Rejects if the provided path does not exist or is not a directory.\n */\n createFsStore(options: FsStoreOptions): Promise<ObjectStore>;\n\n /**\n * Wrap an upstream object store in a persistent byte-range cache backed by SQLite.\n * The returned store is itself an {@link ObjectStore} (pass it to {@link createRequestHandler})\n * and additionally exposes metrics and reset. Dispose it to close the cache database.\n */\n createCachingObjectStore(options: CachingObjectStoreOptions): Promise<CachingObjectStore>;\n\n /**\n * Create an HTTP request handler for serving files from an object store.\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 otherwise.\n * Assumes that files are immutable (and sets cache headers accordingly).\n */\n createRequestHandler(options: RequestHandlerOptions): RequestListener;\n\n /**\n * Serve HTTP(S) requests using the provided handler on localhost port.\n * @returns promise that resolves when the server has stopped.\n *\n * @example\n * ```ts\n * const rootDir = '/path/to/directory/with/parquet/files';\n *\n * let store = await HttpHelpers.createFsStore({ rootDir }).catch((err: unknown) => {\n * throw new Error(`Failed to create file store for ${rootDir} - ${ensureError(err)}`);\n * });\n *\n * const server = await HttpHelpers.createHttpServer({\n * handler: HttpHelpers.createRequestHandler({ store }),\n * }).catch((err: unknown) => {\n * throw new Error(`Failed to start HTTPS server - ${ensureError(err)}`);\n * });\n *\n * const { url, authToken, encodedCaCert } = server.info;\n *\n * await server.stop();\n * ```\n */\n createHttpServer(options: HttpServerOptions): Promise<HttpServer>;\n}\n"],"mappings":";;AAMA,MAAa,mBAAmB;;AA0HhC,IAAsB,kBAAtB,MAA6D;CAC3D;CAEA,YAAY,SAA6B;AACvC,OAAK,SAAS,QAAQ,iBAAiB;;;CAIzC,UAAoB,UAAkB,OAAqC;AACzE,MAAI,CAAC,MAAO,QAAO;GAAE,OAAO;GAAG,KAAK,WAAW;GAAG;AAClD,UAAQ,MAAM,MAAd;GACE,KAAK;AACH,QAAI,MAAM,OAAO,SAAU,QAAO;AAClC,WAAO;KAAE,OAAO,MAAM;KAAO,KAAK,MAAM;KAAK;GAC/C,KAAK;AACH,QAAI,MAAM,UAAU,SAAU,QAAO;AACrC,WAAO;KAAE,OAAO,MAAM;KAAQ,KAAK,WAAW;KAAG;GACnD,KAAK;AACH,QAAI,MAAM,SAAS,SAAU,QAAO;AACpC,WAAO;KAAE,OAAO,WAAW,MAAM;KAAQ,KAAK,WAAW;KAAG"}
|
|
@@ -112,11 +112,74 @@ declare abstract class BaseObjectStore implements ObjectStore {
|
|
|
112
112
|
callback: (response: ObjectStoreResponse) => Promise<void>;
|
|
113
113
|
}): Promise<void>;
|
|
114
114
|
}
|
|
115
|
+
/** Configuration for {@link HttpHelpers.createCachingObjectStore} */
|
|
116
|
+
type CacheConfig = {
|
|
117
|
+
/** Filesystem path where the cache persists its data */cachePath: string; /** Hard total size budget in bytes; the cache self-stabilizes near this size */
|
|
118
|
+
maxSizeBytes: number;
|
|
119
|
+
/**
|
|
120
|
+
* Max share of the budget a single file may occupy (0..1); when a file exceeds it, that
|
|
121
|
+
* file's oldest ranges are evicted first. Stops one large scan from flushing the working set.
|
|
122
|
+
*/
|
|
123
|
+
admissionFraction: number; /** Upper bound on previously-evicted (ghost) files remembered to guide readmission; resident files are already byte-bounded */
|
|
124
|
+
maxFilesTracked: number;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Cumulative cache event counters. Surfaced both as lifetime totals (persisted across restarts)
|
|
128
|
+
* and as a per-process session view, @see CacheMetrics.
|
|
129
|
+
*/
|
|
130
|
+
type CacheCounters = {
|
|
131
|
+
/** Requests fully served from cache */hits: number; /** Requests that fell through to upstream */
|
|
132
|
+
misses: number; /** Bytes served from cache */
|
|
133
|
+
bytesServed: number; /** Bytes downloaded from upstream on misses */
|
|
134
|
+
bytesFetched: number; /** Bytes evicted to keep the cache within its total size budget, @see CacheConfig.maxSizeBytes */
|
|
135
|
+
bytesEvictedByBudget: number; /** Bytes evicted because a single file exceeded its allowed share of the budget, @see CacheConfig.admissionFraction */
|
|
136
|
+
bytesEvictedByFileCap: number; /** Files promoted on observed reuse, so they are retained longer than first-time entries */
|
|
137
|
+
promotions: number; /** Previously evicted files that were re-requested and readmitted */
|
|
138
|
+
ghostReadmissions: number;
|
|
139
|
+
};
|
|
140
|
+
/** Snapshot of cache state and counters, @see CachingObjectStore.getMetrics */
|
|
141
|
+
type CacheMetrics = {
|
|
142
|
+
/** Current resident bytes */sizeBytes: number; /** Number of files with resident (cached) bytes */
|
|
143
|
+
residentFiles: number; /** Number of previously-evicted (ghost) files remembered, <= @see CacheConfig.maxFilesTracked */
|
|
144
|
+
ghostFiles: number; /** Counters cumulative across all sessions (persisted) */
|
|
145
|
+
lifetime: CacheCounters; /** The same counters scoped to the current process */
|
|
146
|
+
session: CacheCounters;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Options for caching object store creation, @see HttpHelpers.createCachingObjectStore.
|
|
150
|
+
* Standalone (not extending {@link ObjectStoreOptions}): a caching store is a decorator over
|
|
151
|
+
* `upstream`, so source-store options do not apply to it.
|
|
152
|
+
*/
|
|
153
|
+
interface CachingObjectStoreOptions {
|
|
154
|
+
/** Upstream store consulted on cache misses */
|
|
155
|
+
upstream: ObjectStore;
|
|
156
|
+
/** Cache configuration */
|
|
157
|
+
config: CacheConfig;
|
|
158
|
+
/** Logger instance, no logging is performed when not provided */
|
|
159
|
+
logger?: Logger;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* An {@link ObjectStore} that serves byte ranges from a persistent local cache, fetching misses
|
|
163
|
+
* from an upstream store. This is the single handle for the cache: pass it as
|
|
164
|
+
* {@link RequestHandlerOptions.store}, read {@link CachingObjectStore.getMetrics}, and dispose it
|
|
165
|
+
* to release the cache, @see HttpHelpers.createCachingObjectStore.
|
|
166
|
+
*/
|
|
167
|
+
interface CachingObjectStore extends ObjectStore, AsyncDisposable {
|
|
168
|
+
/** Instantaneous cache state plus lifetime/session counters */
|
|
169
|
+
getMetrics(): CacheMetrics;
|
|
170
|
+
/** Drop all cached data and zero the counters (test/benchmark use) */
|
|
171
|
+
reset(): Promise<void>;
|
|
172
|
+
}
|
|
115
173
|
/** Object store base URL in format accepted by Apache DataFusion and DuckDB */
|
|
116
174
|
type ObjectStoreUrl = Branded<string, "PFrameInternal.ObjectStoreUrl">;
|
|
117
175
|
/** HTTP(S) request handler creation options */
|
|
118
176
|
type RequestHandlerOptions = {
|
|
119
|
-
/**
|
|
177
|
+
/**
|
|
178
|
+
* Object store to serve files from. Compose caching by wrapping the upstream store with
|
|
179
|
+
* {@link HttpHelpers.createCachingObjectStore} and passing the result here,
|
|
180
|
+
* @see HttpHelpers.createFsStore
|
|
181
|
+
*/
|
|
182
|
+
store: ObjectStore;
|
|
120
183
|
};
|
|
121
184
|
/** Server configuration options */
|
|
122
185
|
type HttpServerOptions = {
|
|
@@ -169,6 +232,12 @@ interface HttpHelpers {
|
|
|
169
232
|
* Rejects if the provided path does not exist or is not a directory.
|
|
170
233
|
*/
|
|
171
234
|
createFsStore(options: FsStoreOptions): Promise<ObjectStore>;
|
|
235
|
+
/**
|
|
236
|
+
* Wrap an upstream object store in a persistent byte-range cache backed by SQLite.
|
|
237
|
+
* The returned store is itself an {@link ObjectStore} (pass it to {@link createRequestHandler})
|
|
238
|
+
* and additionally exposes metrics and reset. Dispose it to close the cache database.
|
|
239
|
+
*/
|
|
240
|
+
createCachingObjectStore(options: CachingObjectStoreOptions): Promise<CachingObjectStore>;
|
|
172
241
|
/**
|
|
173
242
|
* Create an HTTP request handler for serving files from an object store.
|
|
174
243
|
* Accepts only paths of the form `/<filename>.parquet`, returns 410 otherwise.
|
|
@@ -201,5 +270,5 @@ interface HttpHelpers {
|
|
|
201
270
|
createHttpServer(options: HttpServerOptions): Promise<HttpServer>;
|
|
202
271
|
}
|
|
203
272
|
//#endregion
|
|
204
|
-
export { BaseObjectStore, FileRange, FsStoreOptions, HttpAuthorizationToken, HttpHelpers, HttpMethod, HttpRange, HttpServer, HttpServerInfo, HttpServerOptions, ObjectStore, ObjectStoreOptions, ObjectStoreResponse, ObjectStoreUrl, ParquetExtension, ParquetFileName, PemCertificate, RequestHandlerOptions };
|
|
273
|
+
export { BaseObjectStore, CacheConfig, CacheCounters, CacheMetrics, CachingObjectStore, CachingObjectStoreOptions, FileRange, FsStoreOptions, HttpAuthorizationToken, HttpHelpers, HttpMethod, HttpRange, HttpServer, HttpServerInfo, HttpServerOptions, ObjectStore, ObjectStoreOptions, ObjectStoreResponse, ObjectStoreUrl, ParquetExtension, ParquetFileName, PemCertificate, RequestHandlerOptions };
|
|
205
274
|
//# sourceMappingURL=http_helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_helpers.d.ts","names":[],"sources":["../../../src/pframe/internal_api/http_helpers.ts"],"mappings":";;;;;;;cAMa,gBAAA;AAAb;AAAA,KAGY,eAAA,GAAkB,OAAA;AAAA,KAElB,SAAA;EALuC,sCAOjD,KAAA,UAJU;EAMV,GAAA;AAAA;;KAIU,SAAA;EARA;;;;;AAQZ;;;;EAWM,IAAA,aAEA;EAAA,KAAA,UAcA;EAZA,GAAA;AAAA;EA4BA;;;AAIN;;;;;AAGA;EAvBM,IAAA;EAEA,MAAA;AAAA;EA+BA;;;;;;;;;EAnBA,IAAA,YAmCe;EAjCf,MAAA;AAAA;;KAIM,UAAA;;KAGA,mBAAA;EAoCoB;;;;EA9B1B,IAAA;AAAA;2DAIA,IAAA;AAAA;EAyCQ,qEArCR,IAAA,yBAuCqB;EArCrB,IAAA;AAAA;EAqCoD,yEAjCpD,IAAA,QA4BQ;EA1BR,IAAA,UA4BA;EA1BA,KAAA,EAAO,SAAA,EA2BP;EAzBA,IAAA,GAAO,QAAA;AAAA;;UAII,kBAAA;EAuBU;EArBzB,MAAA,GAAS,MAAA;AAAA;;UAIM,cAAA,SAAuB,kBAAA;EAkBnC;EAhBH,OAAA;AAAA;AAAA,UAGe,WAAA;EAmBY;;;;;EAb3B,OAAA,CACE,QAAA,EAAU,eAAA,EACV,MAAA;IACE,MAAA,EAAQ,UAAA;IACR,KAAA,GAAQ,SAAA;IACR,MAAA,EAAQ,WAAA;IACR,QAAA,GAAW,QAAA,EAAU,mBAAA,KAAwB,OAAA;EAAA;AAAA;;uBAM7B,eAAA,YAA2B,WAAA;EAAA,mBAC5B,MAAA,EAAQ,MAAA;cAEf,OAAA,EAAS,kBAAA;EAFM;EAAA,UAOjB,SAAA,CAAU,QAAA,UAAkB,KAAA,GAAQ,SAAA,GAAY,SAAA;EALrC;;;;;EAAA,SAyBZ,OAAA,CACP,QAAA,EAAU,eAAA,EACV,MAAA;IACE,MAAA,EAAQ,UAAA;IACR,KAAA,GAAQ,SAAA;IACR,MAAA,EAAQ,WAAA;IACR,QAAA,GAAW,QAAA,EAAU,mBAAA,KAAwB,OAAA;EAAA,IAE9C,OAAA;AAAA;;KAIO,cAAA,GAAiB,OAAA;;KAGjB,qBAAA;
|
|
1
|
+
{"version":3,"file":"http_helpers.d.ts","names":[],"sources":["../../../src/pframe/internal_api/http_helpers.ts"],"mappings":";;;;;;;cAMa,gBAAA;AAAb;AAAA,KAGY,eAAA,GAAkB,OAAA;AAAA,KAElB,SAAA;EALuC,sCAOjD,KAAA,UAJU;EAMV,GAAA;AAAA;;KAIU,SAAA;EARA;;;;;AAQZ;;;;EAWM,IAAA,aAEA;EAAA,KAAA,UAcA;EAZA,GAAA;AAAA;EA4BA;;;AAIN;;;;;AAGA;EAvBM,IAAA;EAEA,MAAA;AAAA;EA+BA;;;;;;;;;EAnBA,IAAA,YAmCe;EAjCf,MAAA;AAAA;;KAIM,UAAA;;KAGA,mBAAA;EAoCoB;;;;EA9B1B,IAAA;AAAA;2DAIA,IAAA;AAAA;EAyCQ,qEArCR,IAAA,yBAuCqB;EArCrB,IAAA;AAAA;EAqCoD,yEAjCpD,IAAA,QA4BQ;EA1BR,IAAA,UA4BA;EA1BA,KAAA,EAAO,SAAA,EA2BP;EAzBA,IAAA,GAAO,QAAA;AAAA;;UAII,kBAAA;EAuBU;EArBzB,MAAA,GAAS,MAAA;AAAA;;UAIM,cAAA,SAAuB,kBAAA;EAkBnC;EAhBH,OAAA;AAAA;AAAA,UAGe,WAAA;EAmBY;;;;;EAb3B,OAAA,CACE,QAAA,EAAU,eAAA,EACV,MAAA;IACE,MAAA,EAAQ,UAAA;IACR,KAAA,GAAQ,SAAA;IACR,MAAA,EAAQ,WAAA;IACR,QAAA,GAAW,QAAA,EAAU,mBAAA,KAAwB,OAAA;EAAA;AAAA;;uBAM7B,eAAA,YAA2B,WAAA;EAAA,mBAC5B,MAAA,EAAQ,MAAA;cAEf,OAAA,EAAS,kBAAA;EAFM;EAAA,UAOjB,SAAA,CAAU,QAAA,UAAkB,KAAA,GAAQ,SAAA,GAAY,SAAA;EALrC;;;;;EAAA,SAyBZ,OAAA,CACP,QAAA,EAAU,eAAA,EACV,MAAA;IACE,MAAA,EAAQ,UAAA;IACR,KAAA,GAAQ,SAAA;IACR,MAAA,EAAQ,WAAA;IACR,QAAA,GAAW,QAAA,EAAU,mBAAA,KAAwB,OAAA;EAAA,IAE9C,OAAA;AAAA;;KAIO,WAAA;EAPN,wDASJ,SAAA,UARI;EAUJ,YAAA;EAVe;;;;EAef,iBAAA,UAbU;EAeV,eAAA;AAAA;;;;;KAOU,aAAA;EAPV,uCASA,IAAA,UATe;EAWf,MAAA,UAJuB;EAMvB,WAAA,UANuB;EAQvB,YAAA,UAJA;EAMA,oBAAA,UAFA;EAIA,qBAAA;EAEA,UAAA,UAEA;EAAA,iBAAA;AAAA;AAIF;AAAA,KAAY,YAAA;+BAEV,SAAA;EAEA,aAAA,UAEA;EAAA,UAAA,UAEU;EAAV,QAAA,EAAU,aAAA,EAED;EAAT,OAAA,EAAS,aAAA;AAAA;AAQX;;;;;AAAA,UAAiB,yBAAA;EAMA;EAJf,QAAA,EAAU,WAAA;EAAV;EAEA,MAAA,EAAQ,WAAA;EAAR;EAEA,MAAA,GAAS,MAAA;AAAA;;;;AASX;;;UAAiB,kBAAA,SAA2B,WAAA,EAAa,eAAA;EAI9C;EAFT,UAAA,IAAc,YAAA;EAFyC;EAIvD,KAAA,IAAS,OAAA;AAAA;;KAIC,cAAA,GAAiB,OAAA;;KAGjB,qBAAA;EAPV;;;;AAIF;EASE,KAAA,EAAO,WAAA;AAAA;;KAIG,iBAAA;EAVA,8EAYV,OAAA,EAAS,eAAA;EAET,IAAA,WARkB;EAUlB,MAAA,SAN2B;EAQ3B,OAAA;AAAA;;;;;;;;AAWF;KAAY,sBAAA,GAAyB,OAAA;;;;AAcrC;;;;;AAGA;;;;KAHY,cAAA,GAAiB,OAAA;;KAGjB,cAAA;EAMmB,wEAJ7B,GAAA,EAAK,cAAA,EAAL;EAEA,SAAA,GAAY,sBAAA,EAAZ;EAEA,aAAA,GAAgB,aAAA,CAAc,cAAA;AAAA;;UAIf,UAAA;EAJ6B;EAAA,IAMxC,IAAA,IAAQ,cAAA;EAFG;EAAA,IAIX,OAAA,IAAW,OAAA;;EAEf,IAAA,IAAQ,OAAA;AAAA;;UAIO,WAAA;EAJA;;;;EASf,aAAA,CAAc,OAAA,EAAS,cAAA,GAAiB,OAAA,CAAQ,WAAA;EAThD;;;;AAIF;EAYE,wBAAA,CAAyB,OAAA,EAAS,yBAAA,GAA4B,OAAA,CAAQ,kBAAA;;;;;;EAOtE,oBAAA,CAAqB,OAAA,EAAS,qBAAA,GAAwB,eAAA;EAPQ;;;;;;;;;;;;;;;;;;;;;;;EAgC9D,gBAAA,CAAiB,OAAA,EAAS,iBAAA,GAAoB,OAAA,CAAQ,UAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http_helpers.js","names":[],"sources":["../../../src/pframe/internal_api/http_helpers.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport type { RequestListener } from \"node:http\";\nimport type { Branded, Base64Encoded } from \"@milaboratories/pl-model-common\";\nimport type { Logger } from \"./common\";\n\n/** Parquet file extension */\nexport const ParquetExtension = \".parquet\" as const;\n\n/** Parquet file name */\nexport type ParquetFileName = Branded<`${string}.parquet`, \"PFrameInternal.ParquetFileName\">;\n\nexport type FileRange = {\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n};\n\n/** HTTP range as of RFC 9110 <https://datatracker.ietf.org/doc/html/rfc9110#name-range> */\nexport type HttpRange =\n | {\n /**\n * Get file content in the specified byte range\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=0-1023\n * ```\n */\n type: \"bounded\";\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n }\n | {\n /**\n * Get byte range starting from the specified offset\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=1024-\n * ```\n */\n type: \"offset\";\n /** Start byte position (inclusive) */\n offset: number;\n }\n | {\n /**\n * Get byte range starting from the specified suffix\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=-1024\n * ```\n */\n type: \"suffix\";\n /** End byte position (inclusive) */\n suffix: number;\n };\n\n/** HTTP method passed to object store */\nexport type HttpMethod = \"GET\" | \"HEAD\";\n\n/** HTTP response from object store */\nexport type ObjectStoreResponse =\n | {\n /**\n * Will be translated to 500 Internal Server Error by the handler\n * or 408 Request Timeout if the request was aborted\n */\n type: \"InternalError\";\n }\n | {\n /** Will be translated to 404 Not Found by the handler */\n type: \"NotFound\";\n }\n | {\n /** Will be translated to 416 Range Not Satisfiable by the handler */\n type: \"RangeNotSatisfiable\";\n /** Total file size in bytes */\n size: number;\n }\n | {\n /** Will be translated to 200 OK or 206 Partial Content by the handler */\n type: \"Ok\";\n /** Total file size in bytes */\n size: number;\n /** File range translated from HTTP range */\n range: FileRange;\n /** Stream of file content, undefined for HEAD requests */\n data?: Readable;\n };\n\n/** Common options for object store creation */\nexport interface ObjectStoreOptions {\n /** Logger instance, no logging is performed when not provided */\n logger?: Logger;\n}\n\n/** Options for file system object store creation */\nexport interface FsStoreOptions extends ObjectStoreOptions {\n /** Local directory to serve files from */\n rootDir: string;\n}\n\nexport interface ObjectStore {\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): void;\n}\n\n/** File system abstraction for request handler factory, @see HttpHelpers.createRequestHandler */\nexport abstract class BaseObjectStore implements ObjectStore {\n protected readonly logger: Logger;\n\n constructor(options: ObjectStoreOptions) {\n this.logger = options.logger ?? (() => {});\n }\n\n /** Translate HTTP range to file range, @returns null if the range is not satisfiable */\n protected translate(fileSize: number, range?: HttpRange): FileRange | null {\n if (!range) return { start: 0, end: fileSize - 1 };\n switch (range.type) {\n case \"bounded\":\n if (range.end >= fileSize) return null;\n return { start: range.start, end: range.end };\n case \"offset\":\n if (range.offset >= fileSize) return null;\n return { start: range.offset, end: fileSize - 1 };\n case \"suffix\":\n if (range.suffix > fileSize) return null;\n return { start: fileSize - range.suffix, end: fileSize - 1 };\n }\n }\n\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n abstract request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): Promise<void>;\n}\n\n/** Object store base URL in format accepted by Apache DataFusion and DuckDB */\nexport type ObjectStoreUrl = Branded<string, \"PFrameInternal.ObjectStoreUrl\">;\n\n/** HTTP(S) request handler creation options */\nexport type RequestHandlerOptions = {\n /** Object store to serve files from, @see HttpHelpers.createFsStore */\n store: ObjectStore;\n /** Here will go caching options... */\n};\n\n/** Server configuration options */\nexport type HttpServerOptions = {\n /** HTTP(S) request handler function, @see HttpHelpers.createRequestHandler */\n handler: RequestListener;\n /** Port to bind to, @default 0 for auto-assignment */\n port?: number;\n /** Do not apply authorization middleware to @param handler */\n noAuth?: true;\n /** Downgrade default HTTPS server to plain HTTP, @warning use only for testing */\n noHttps?: true;\n};\n\n/**\n * Long unique opaque string for use in Bearer authorization header\n *\n * @example\n * ```ts\n * request.setHeader('Authorization', `Bearer ${authToken}`);\n * ```\n */\nexport type HttpAuthorizationToken = Branded<string, \"PFrameInternal.HttpAuthorizationToken\">;\n\n/**\n * TLS certificate in PEM format\n *\n * @example\n * ```txt\n * -----BEGIN CERTIFICATE-----\n * MIIC2zCCAcOgAwIBAgIJaVW7...\n * ...\n * ...Yf9CRK8fgnukKM7TJ\n * -----END CERTIFICATE-----\n * ```\n */\nexport type PemCertificate = Branded<string, \"PFrameInternal.PemCertificate\">;\n\n/** HTTP(S) server connection settings, {@link HttpHelpers.createHttpServer} */\nexport type HttpServerInfo = {\n /** URL of the HTTP(S) server formatted as `http{s}://<host>:<port>/` */\n url: ObjectStoreUrl;\n /** Authorization token for Bearer scheme, undefined when @see HttpServerOptions.noAuth flag is set */\n authToken?: HttpAuthorizationToken;\n /** Encoded CA certificate of HTTPS server, undefined when @see HttpServerOptions.noHttps flag is set */\n encodedCaCert?: Base64Encoded<PemCertificate>;\n};\n\n/** HTTP(S) server information and controls, @see HttpHelpers.createHttpServer */\nexport interface HttpServer {\n /** Server configuration information for initiating connections from clients */\n get info(): HttpServerInfo;\n /** Promise that resolves when the server is stopped */\n get stopped(): Promise<void>;\n /** Request server stop, returns the same promise as @see HttpServer.stopped */\n stop(): Promise<void>;\n}\n\n/** List of HTTP(S) related helper functions exposed by PFrame module */\nexport interface HttpHelpers {\n /**\n * Create an object store for serving files from a local directory.\n * Rejects if the provided path does not exist or is not a directory.\n */\n createFsStore(options: FsStoreOptions): Promise<ObjectStore>;\n\n /**\n * Create an HTTP request handler for serving files from an object store.\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 otherwise.\n * Assumes that files are immutable (and sets cache headers accordingly).\n */\n createRequestHandler(options: RequestHandlerOptions): RequestListener;\n\n /**\n * Serve HTTP(S) requests using the provided handler on localhost port.\n * @returns promise that resolves when the server has stopped.\n *\n * @example\n * ```ts\n * const rootDir = '/path/to/directory/with/parquet/files';\n *\n * let store = await HttpHelpers.createFsStore({ rootDir }).catch((err: unknown) => {\n * throw new Error(`Failed to create file store for ${rootDir} - ${ensureError(err)}`);\n * });\n *\n * const server = await HttpHelpers.createHttpServer({\n * handler: HttpHelpers.createRequestHandler({ store }),\n * }).catch((err: unknown) => {\n * throw new Error(`Failed to start HTTPS server - ${ensureError(err)}`);\n * });\n *\n * const { url, authToken, encodedCaCert } = server.info;\n *\n * await server.stop();\n * ```\n */\n createHttpServer(options: HttpServerOptions): Promise<HttpServer>;\n}\n"],"mappings":";;AAMA,MAAa,mBAAmB;;AA0HhC,IAAsB,kBAAtB,MAA6D;CAC3D;CAEA,YAAY,SAA6B;AACvC,OAAK,SAAS,QAAQ,iBAAiB;;;CAIzC,UAAoB,UAAkB,OAAqC;AACzE,MAAI,CAAC,MAAO,QAAO;GAAE,OAAO;GAAG,KAAK,WAAW;GAAG;AAClD,UAAQ,MAAM,MAAd;GACE,KAAK;AACH,QAAI,MAAM,OAAO,SAAU,QAAO;AAClC,WAAO;KAAE,OAAO,MAAM;KAAO,KAAK,MAAM;KAAK;GAC/C,KAAK;AACH,QAAI,MAAM,UAAU,SAAU,QAAO;AACrC,WAAO;KAAE,OAAO,MAAM;KAAQ,KAAK,WAAW;KAAG;GACnD,KAAK;AACH,QAAI,MAAM,SAAS,SAAU,QAAO;AACpC,WAAO;KAAE,OAAO,WAAW,MAAM;KAAQ,KAAK,WAAW;KAAG"}
|
|
1
|
+
{"version":3,"file":"http_helpers.js","names":[],"sources":["../../../src/pframe/internal_api/http_helpers.ts"],"sourcesContent":["import type { Readable } from \"node:stream\";\nimport type { RequestListener } from \"node:http\";\nimport type { Branded, Base64Encoded } from \"@milaboratories/pl-model-common\";\nimport type { Logger } from \"./common\";\n\n/** Parquet file extension */\nexport const ParquetExtension = \".parquet\" as const;\n\n/** Parquet file name */\nexport type ParquetFileName = Branded<`${string}.parquet`, \"PFrameInternal.ParquetFileName\">;\n\nexport type FileRange = {\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n};\n\n/** HTTP range as of RFC 9110 <https://datatracker.ietf.org/doc/html/rfc9110#name-range> */\nexport type HttpRange =\n | {\n /**\n * Get file content in the specified byte range\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=0-1023\n * ```\n */\n type: \"bounded\";\n /** Start byte position (inclusive) */\n start: number;\n /** End byte position (inclusive) */\n end: number;\n }\n | {\n /**\n * Get byte range starting from the specified offset\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=1024-\n * ```\n */\n type: \"offset\";\n /** Start byte position (inclusive) */\n offset: number;\n }\n | {\n /**\n * Get byte range starting from the specified suffix\n *\n * @example\n * ```\n * GET /file.parquet HTTP/1.1\n * Range: bytes=-1024\n * ```\n */\n type: \"suffix\";\n /** End byte position (inclusive) */\n suffix: number;\n };\n\n/** HTTP method passed to object store */\nexport type HttpMethod = \"GET\" | \"HEAD\";\n\n/** HTTP response from object store */\nexport type ObjectStoreResponse =\n | {\n /**\n * Will be translated to 500 Internal Server Error by the handler\n * or 408 Request Timeout if the request was aborted\n */\n type: \"InternalError\";\n }\n | {\n /** Will be translated to 404 Not Found by the handler */\n type: \"NotFound\";\n }\n | {\n /** Will be translated to 416 Range Not Satisfiable by the handler */\n type: \"RangeNotSatisfiable\";\n /** Total file size in bytes */\n size: number;\n }\n | {\n /** Will be translated to 200 OK or 206 Partial Content by the handler */\n type: \"Ok\";\n /** Total file size in bytes */\n size: number;\n /** File range translated from HTTP range */\n range: FileRange;\n /** Stream of file content, undefined for HEAD requests */\n data?: Readable;\n };\n\n/** Common options for object store creation */\nexport interface ObjectStoreOptions {\n /** Logger instance, no logging is performed when not provided */\n logger?: Logger;\n}\n\n/** Options for file system object store creation */\nexport interface FsStoreOptions extends ObjectStoreOptions {\n /** Local directory to serve files from */\n rootDir: string;\n}\n\nexport interface ObjectStore {\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): void;\n}\n\n/** File system abstraction for request handler factory, @see HttpHelpers.createRequestHandler */\nexport abstract class BaseObjectStore implements ObjectStore {\n protected readonly logger: Logger;\n\n constructor(options: ObjectStoreOptions) {\n this.logger = options.logger ?? (() => {});\n }\n\n /** Translate HTTP range to file range, @returns null if the range is not satisfiable */\n protected translate(fileSize: number, range?: HttpRange): FileRange | null {\n if (!range) return { start: 0, end: fileSize - 1 };\n switch (range.type) {\n case \"bounded\":\n if (range.end >= fileSize) return null;\n return { start: range.start, end: range.end };\n case \"offset\":\n if (range.offset >= fileSize) return null;\n return { start: range.offset, end: fileSize - 1 };\n case \"suffix\":\n if (range.suffix > fileSize) return null;\n return { start: fileSize - range.suffix, end: fileSize - 1 };\n }\n }\n\n /**\n * Proxy HTTP(S) request for parquet file to object store.\n * Callback promise resolves when stream is closed by handler @see HttpHelpers.createRequestHandler\n * Callback API is used so that ObjectStore can limit the number of concurrent requests.\n */\n abstract request(\n filename: ParquetFileName,\n params: {\n method: HttpMethod;\n range?: HttpRange;\n signal: AbortSignal;\n callback: (response: ObjectStoreResponse) => Promise<void>;\n },\n ): Promise<void>;\n}\n\n/** Configuration for {@link HttpHelpers.createCachingObjectStore} */\nexport type CacheConfig = {\n /** Filesystem path where the cache persists its data */\n cachePath: string;\n /** Hard total size budget in bytes; the cache self-stabilizes near this size */\n maxSizeBytes: number;\n /**\n * Max share of the budget a single file may occupy (0..1); when a file exceeds it, that\n * file's oldest ranges are evicted first. Stops one large scan from flushing the working set.\n */\n admissionFraction: number;\n /** Upper bound on previously-evicted (ghost) files remembered to guide readmission; resident files are already byte-bounded */\n maxFilesTracked: number;\n};\n\n/**\n * Cumulative cache event counters. Surfaced both as lifetime totals (persisted across restarts)\n * and as a per-process session view, @see CacheMetrics.\n */\nexport type CacheCounters = {\n /** Requests fully served from cache */\n hits: number;\n /** Requests that fell through to upstream */\n misses: number;\n /** Bytes served from cache */\n bytesServed: number;\n /** Bytes downloaded from upstream on misses */\n bytesFetched: number;\n /** Bytes evicted to keep the cache within its total size budget, @see CacheConfig.maxSizeBytes */\n bytesEvictedByBudget: number;\n /** Bytes evicted because a single file exceeded its allowed share of the budget, @see CacheConfig.admissionFraction */\n bytesEvictedByFileCap: number;\n /** Files promoted on observed reuse, so they are retained longer than first-time entries */\n promotions: number;\n /** Previously evicted files that were re-requested and readmitted */\n ghostReadmissions: number;\n};\n\n/** Snapshot of cache state and counters, @see CachingObjectStore.getMetrics */\nexport type CacheMetrics = {\n /** Current resident bytes */\n sizeBytes: number;\n /** Number of files with resident (cached) bytes */\n residentFiles: number;\n /** Number of previously-evicted (ghost) files remembered, <= @see CacheConfig.maxFilesTracked */\n ghostFiles: number;\n /** Counters cumulative across all sessions (persisted) */\n lifetime: CacheCounters;\n /** The same counters scoped to the current process */\n session: CacheCounters;\n};\n\n/**\n * Options for caching object store creation, @see HttpHelpers.createCachingObjectStore.\n * Standalone (not extending {@link ObjectStoreOptions}): a caching store is a decorator over\n * `upstream`, so source-store options do not apply to it.\n */\nexport interface CachingObjectStoreOptions {\n /** Upstream store consulted on cache misses */\n upstream: ObjectStore;\n /** Cache configuration */\n config: CacheConfig;\n /** Logger instance, no logging is performed when not provided */\n logger?: Logger;\n}\n\n/**\n * An {@link ObjectStore} that serves byte ranges from a persistent local cache, fetching misses\n * from an upstream store. This is the single handle for the cache: pass it as\n * {@link RequestHandlerOptions.store}, read {@link CachingObjectStore.getMetrics}, and dispose it\n * to release the cache, @see HttpHelpers.createCachingObjectStore.\n */\nexport interface CachingObjectStore extends ObjectStore, AsyncDisposable {\n /** Instantaneous cache state plus lifetime/session counters */\n getMetrics(): CacheMetrics;\n /** Drop all cached data and zero the counters (test/benchmark use) */\n reset(): Promise<void>;\n}\n\n/** Object store base URL in format accepted by Apache DataFusion and DuckDB */\nexport type ObjectStoreUrl = Branded<string, \"PFrameInternal.ObjectStoreUrl\">;\n\n/** HTTP(S) request handler creation options */\nexport type RequestHandlerOptions = {\n /**\n * Object store to serve files from. Compose caching by wrapping the upstream store with\n * {@link HttpHelpers.createCachingObjectStore} and passing the result here,\n * @see HttpHelpers.createFsStore\n */\n store: ObjectStore;\n};\n\n/** Server configuration options */\nexport type HttpServerOptions = {\n /** HTTP(S) request handler function, @see HttpHelpers.createRequestHandler */\n handler: RequestListener;\n /** Port to bind to, @default 0 for auto-assignment */\n port?: number;\n /** Do not apply authorization middleware to @param handler */\n noAuth?: true;\n /** Downgrade default HTTPS server to plain HTTP, @warning use only for testing */\n noHttps?: true;\n};\n\n/**\n * Long unique opaque string for use in Bearer authorization header\n *\n * @example\n * ```ts\n * request.setHeader('Authorization', `Bearer ${authToken}`);\n * ```\n */\nexport type HttpAuthorizationToken = Branded<string, \"PFrameInternal.HttpAuthorizationToken\">;\n\n/**\n * TLS certificate in PEM format\n *\n * @example\n * ```txt\n * -----BEGIN CERTIFICATE-----\n * MIIC2zCCAcOgAwIBAgIJaVW7...\n * ...\n * ...Yf9CRK8fgnukKM7TJ\n * -----END CERTIFICATE-----\n * ```\n */\nexport type PemCertificate = Branded<string, \"PFrameInternal.PemCertificate\">;\n\n/** HTTP(S) server connection settings, {@link HttpHelpers.createHttpServer} */\nexport type HttpServerInfo = {\n /** URL of the HTTP(S) server formatted as `http{s}://<host>:<port>/` */\n url: ObjectStoreUrl;\n /** Authorization token for Bearer scheme, undefined when @see HttpServerOptions.noAuth flag is set */\n authToken?: HttpAuthorizationToken;\n /** Encoded CA certificate of HTTPS server, undefined when @see HttpServerOptions.noHttps flag is set */\n encodedCaCert?: Base64Encoded<PemCertificate>;\n};\n\n/** HTTP(S) server information and controls, @see HttpHelpers.createHttpServer */\nexport interface HttpServer {\n /** Server configuration information for initiating connections from clients */\n get info(): HttpServerInfo;\n /** Promise that resolves when the server is stopped */\n get stopped(): Promise<void>;\n /** Request server stop, returns the same promise as @see HttpServer.stopped */\n stop(): Promise<void>;\n}\n\n/** List of HTTP(S) related helper functions exposed by PFrame module */\nexport interface HttpHelpers {\n /**\n * Create an object store for serving files from a local directory.\n * Rejects if the provided path does not exist or is not a directory.\n */\n createFsStore(options: FsStoreOptions): Promise<ObjectStore>;\n\n /**\n * Wrap an upstream object store in a persistent byte-range cache backed by SQLite.\n * The returned store is itself an {@link ObjectStore} (pass it to {@link createRequestHandler})\n * and additionally exposes metrics and reset. Dispose it to close the cache database.\n */\n createCachingObjectStore(options: CachingObjectStoreOptions): Promise<CachingObjectStore>;\n\n /**\n * Create an HTTP request handler for serving files from an object store.\n * Accepts only paths of the form `/<filename>.parquet`, returns 410 otherwise.\n * Assumes that files are immutable (and sets cache headers accordingly).\n */\n createRequestHandler(options: RequestHandlerOptions): RequestListener;\n\n /**\n * Serve HTTP(S) requests using the provided handler on localhost port.\n * @returns promise that resolves when the server has stopped.\n *\n * @example\n * ```ts\n * const rootDir = '/path/to/directory/with/parquet/files';\n *\n * let store = await HttpHelpers.createFsStore({ rootDir }).catch((err: unknown) => {\n * throw new Error(`Failed to create file store for ${rootDir} - ${ensureError(err)}`);\n * });\n *\n * const server = await HttpHelpers.createHttpServer({\n * handler: HttpHelpers.createRequestHandler({ store }),\n * }).catch((err: unknown) => {\n * throw new Error(`Failed to start HTTPS server - ${ensureError(err)}`);\n * });\n *\n * const { url, authToken, encodedCaCert } = server.info;\n *\n * await server.stop();\n * ```\n */\n createHttpServer(options: HttpServerOptions): Promise<HttpServer>;\n}\n"],"mappings":";;AAMA,MAAa,mBAAmB;;AA0HhC,IAAsB,kBAAtB,MAA6D;CAC3D;CAEA,YAAY,SAA6B;AACvC,OAAK,SAAS,QAAQ,iBAAiB;;;CAIzC,UAAoB,UAAkB,OAAqC;AACzE,MAAI,CAAC,MAAO,QAAO;GAAE,OAAO;GAAG,KAAK,WAAW;GAAG;AAClD,UAAQ,MAAM,MAAd;GACE,KAAK;AACH,QAAI,MAAM,OAAO,SAAU,QAAO;AAClC,WAAO;KAAE,OAAO,MAAM;KAAO,KAAK,MAAM;KAAK;GAC/C,KAAK;AACH,QAAI,MAAM,UAAU,SAAU,QAAO;AACrC,WAAO;KAAE,OAAO,MAAM;KAAQ,KAAK,WAAW;KAAG;GACnD,KAAK;AACH,QAAI,MAAM,SAAS,SAAU,QAAO;AACpC,WAAO;KAAE,OAAO,WAAW,MAAM;KAAQ,KAAK,WAAW;KAAG"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PTableV12 } from "./table.js";
|
|
2
2
|
import { AxisQualification, ColumnAxesWithQualifications, ConstantAxisFilter, Logger, PFrameId, PTableId } from "./common.js";
|
|
3
|
-
import {
|
|
4
|
-
import { BaseObjectStore, FileRange, FsStoreOptions, HttpAuthorizationToken, HttpHelpers, HttpMethod, HttpRange, HttpServer, HttpServerInfo, HttpServerOptions, ObjectStore, ObjectStoreOptions, ObjectStoreResponse, ObjectStoreUrl, ParquetExtension, ParquetFileName, PemCertificate, RequestHandlerOptions } from "./http_helpers.js";
|
|
3
|
+
import { PFrameReadAPIV15, UniqueValuesRequestV2 } from "./api_read.js";
|
|
4
|
+
import { BaseObjectStore, CacheConfig, CacheCounters, CacheMetrics, CachingObjectStore, CachingObjectStoreOptions, FileRange, FsStoreOptions, HttpAuthorizationToken, HttpHelpers, HttpMethod, HttpRange, HttpServer, HttpServerInfo, HttpServerOptions, ObjectStore, ObjectStoreOptions, ObjectStoreResponse, ObjectStoreUrl, ParquetExtension, ParquetFileName, PemCertificate, RequestHandlerOptions } from "./http_helpers.js";
|
|
5
5
|
import { AddColumnEntryV2, DataInfo, DataInfoExtension, DataInfoV2, FilePath, PColumnValueTypeSpec, PFrameBlobId, PFrameDataSourceV2, PFrameFactoryAPIV6, SpecExtension } from "./api_factory.js";
|
|
6
6
|
import { DeleteColumnFromColumnsRequest, DeleteColumnFromColumnsResponse } from "./delete_column.js";
|
|
7
7
|
import { DiscoverColumnsConstraints, DiscoverColumnsMappingVariant, DiscoverColumnsRequestV2, DiscoverColumnsResponse, DiscoverColumnsResponseHit, DiscoverColumnsResponseQualifications, DiscoverColumnsStepInfo, MatcherMap, MultiAxisSelector, MultiColumnSelector, StringMatcher } from "./discover_columns.js";
|
|
8
8
|
import { FindColumnResponseQualifications, FindColumnsMappingVariant, FindColumnsRequest, FindColumnsResponse, FindColumnsResponseHit } from "./find_columns.js";
|
|
9
9
|
import { EvaluateQueryResponse, LegacyQuery, PFrameWasmAPIV2, PFrameWasmAPIV3, PFrameWasmAPIV4, PFrameWasmAPIV5, PFrameWasmV2, PFrameWasmV3, PFrameWasmV4 } from "./api_wasm.js";
|
|
10
10
|
import { ArtificialColumnJoinEntry, ColumnJoinEntry, CreateTableRequestV4, FullJoinV4, InlineColumnJoinEntry, InnerJoinV4, JoinEntryV4, OuterJoinV4, SlicedColumnJoinEntry } from "./create_table.js";
|
|
11
|
-
import {
|
|
11
|
+
import { PFrameFactoryV9, PFrameOptionsV2, PFrameV18 } from "./pframe.js";
|
|
12
12
|
import { SingleAxisSelector as SingleAxisSelector$1 } from "@milaboratories/pl-model-common";
|
|
13
13
|
|
|
14
14
|
//#region src/pframe/internal_api/index.d.ts
|
|
15
15
|
declare namespace index_d_exports {
|
|
16
|
-
export { AddColumnEntryV2, ArtificialColumnJoinEntry, AxisQualification, BaseObjectStore, ColumnAxesWithQualifications, ColumnJoinEntry, ConstantAxisFilter, CreateTableRequestV4, DataInfo, DataInfoExtension, DataInfoV2, DeleteColumnFromColumnsRequest, DeleteColumnFromColumnsResponse, DiscoverColumnsConstraints, DiscoverColumnsMappingVariant, DiscoverColumnsRequestV2, DiscoverColumnsResponse, DiscoverColumnsResponseHit, DiscoverColumnsResponseQualifications, DiscoverColumnsStepInfo, EvaluateQueryResponse, FilePath, FileRange, FindColumnResponseQualifications, FindColumnsMappingVariant, FindColumnsRequest, FindColumnsResponse, FindColumnsResponseHit, FsStoreOptions, FullJoinV4, HttpAuthorizationToken, HttpHelpers, HttpMethod, HttpRange, HttpServer, HttpServerInfo, HttpServerOptions, InlineColumnJoinEntry, InnerJoinV4, JoinEntryV4, LegacyQuery, Logger, MatcherMap, MultiAxisSelector, MultiColumnSelector, ObjectStore, ObjectStoreOptions, ObjectStoreResponse, ObjectStoreUrl, OuterJoinV4, PColumnValueTypeSpec, PFrameBlobId, PFrameDataSourceV2, PFrameFactoryAPIV6,
|
|
16
|
+
export { AddColumnEntryV2, ArtificialColumnJoinEntry, AxisQualification, BaseObjectStore, CacheConfig, CacheCounters, CacheMetrics, CachingObjectStore, CachingObjectStoreOptions, ColumnAxesWithQualifications, ColumnJoinEntry, ConstantAxisFilter, CreateTableRequestV4, DataInfo, DataInfoExtension, DataInfoV2, DeleteColumnFromColumnsRequest, DeleteColumnFromColumnsResponse, DiscoverColumnsConstraints, DiscoverColumnsMappingVariant, DiscoverColumnsRequestV2, DiscoverColumnsResponse, DiscoverColumnsResponseHit, DiscoverColumnsResponseQualifications, DiscoverColumnsStepInfo, EvaluateQueryResponse, FilePath, FileRange, FindColumnResponseQualifications, FindColumnsMappingVariant, FindColumnsRequest, FindColumnsResponse, FindColumnsResponseHit, FsStoreOptions, FullJoinV4, HttpAuthorizationToken, HttpHelpers, HttpMethod, HttpRange, HttpServer, HttpServerInfo, HttpServerOptions, InlineColumnJoinEntry, InnerJoinV4, JoinEntryV4, LegacyQuery, Logger, MatcherMap, MultiAxisSelector, MultiColumnSelector, ObjectStore, ObjectStoreOptions, ObjectStoreResponse, ObjectStoreUrl, OuterJoinV4, PColumnValueTypeSpec, PFrameBlobId, PFrameDataSourceV2, PFrameFactoryAPIV6, PFrameFactoryV9, PFrameId, PFrameOptionsV2, PFrameReadAPIV15, PFrameV18, PFrameWasmAPIV2, PFrameWasmAPIV3, PFrameWasmAPIV4, PFrameWasmAPIV5, PFrameWasmV2, PFrameWasmV3, PFrameWasmV4, PTableId, PTableV12, ParquetExtension, ParquetFileName, PemCertificate, RequestHandlerOptions, SingleAxisSelector$1 as SingleAxisSelector, SlicedColumnJoinEntry, SpecExtension, StringMatcher, UniqueValuesRequestV2 };
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
export { index_d_exports };
|
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
import { Logger, PFrameId } from "./common.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PFrameReadAPIV15 } from "./api_read.js";
|
|
3
3
|
import { PFrameFactoryAPIV6 } from "./api_factory.js";
|
|
4
4
|
|
|
5
5
|
//#region src/pframe/internal_api/pframe.d.ts
|
|
6
|
-
/**
|
|
7
|
-
* Full PFrame surface — factory operations plus data-side reads. Exposes
|
|
8
|
-
* the self-contained {@link PFrameFactoryAPIV6} (column `typeSpec` embedded in
|
|
9
|
-
* `data`) plus {@link PFrameReadAPIV14}, whose tables' `export` takes a
|
|
10
|
-
* column-index → header map.
|
|
11
|
-
*/
|
|
12
|
-
interface PFrameV17 extends PFrameFactoryAPIV6, PFrameReadAPIV14 {}
|
|
13
6
|
/**
|
|
14
7
|
* Full PFrame surface — factory operations plus data-side reads. Exposes
|
|
15
8
|
* the self-contained {@link PFrameFactoryAPIV6} (column `typeSpec` embedded in
|
|
16
9
|
* `data`) plus {@link PFrameReadAPIV15}, whose tables' `export` takes an
|
|
17
10
|
* `ops.headers` list of `[column index, header name]` pairs.
|
|
18
|
-
*
|
|
19
|
-
* Same surface as {@link PFrameV17}; the only change is that the read side is
|
|
20
|
-
* upgraded from {@link PFrameReadAPIV14} to {@link PFrameReadAPIV15}, so
|
|
21
|
-
* {@link PFrameReadAPIV15.createTable} returns {@link PTableV12}.
|
|
22
11
|
*/
|
|
23
12
|
interface PFrameV18 extends PFrameFactoryAPIV6, PFrameReadAPIV15 {}
|
|
24
13
|
type PFrameOptionsV2 = {
|
|
@@ -28,29 +17,7 @@ type PFrameOptionsV2 = {
|
|
|
28
17
|
};
|
|
29
18
|
/**
|
|
30
19
|
* PFrame management functions exposed by the PFrame module. Creates
|
|
31
|
-
* {@link
|
|
32
|
-
*/
|
|
33
|
-
interface PFrameFactoryV8 {
|
|
34
|
-
/**
|
|
35
|
-
* Create a new PFrame instance.
|
|
36
|
-
* @warning Use concurrency limiting to avoid OOM crashes when multiple instances are simultaneously in use.
|
|
37
|
-
*/
|
|
38
|
-
createPFrame(options: PFrameOptionsV2): PFrameV17;
|
|
39
|
-
/**
|
|
40
|
-
* Dump active allocations from all PFrames instances in pprof format.
|
|
41
|
-
* The result of this function should be saved as `profile.pb.gz`.
|
|
42
|
-
* Use {@link https://pprof.me/} or {@link https://www.speedscope.app/}
|
|
43
|
-
* to view the allocation flamechart.
|
|
44
|
-
* @warning This method will always reject on Windows!
|
|
45
|
-
*/
|
|
46
|
-
pprofDump: () => Promise<Uint8Array>;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* PFrame management functions exposed by the PFrame module. Creates
|
|
50
|
-
* {@link PFrameV18} instances (self-contained column data info).
|
|
51
|
-
*
|
|
52
|
-
* Same surface as {@link PFrameFactoryV8}; the only change is that
|
|
53
|
-
* {@link PFrameFactoryV9.createPFrame} returns {@link PFrameV18}, whose tables'
|
|
20
|
+
* {@link PFrameV18} instances (self-contained column data info), whose tables'
|
|
54
21
|
* `export` takes an `ops.headers` list of `[column index, header name]` pairs.
|
|
55
22
|
*/
|
|
56
23
|
interface PFrameFactoryV9 {
|
|
@@ -69,5 +36,5 @@ interface PFrameFactoryV9 {
|
|
|
69
36
|
pprofDump: () => Promise<Uint8Array>;
|
|
70
37
|
}
|
|
71
38
|
//#endregion
|
|
72
|
-
export {
|
|
39
|
+
export { PFrameFactoryV9, PFrameOptionsV2, PFrameV18 };
|
|
73
40
|
//# sourceMappingURL=pframe.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pframe.d.ts","names":[],"sources":["../../../src/pframe/internal_api/pframe.ts"],"mappings":";;;;;;AAWA;;;;;UAAiB,SAAA,SAAkB,kBAAA,EAAoB,gBAAA
|
|
1
|
+
{"version":3,"file":"pframe.d.ts","names":[],"sources":["../../../src/pframe/internal_api/pframe.ts"],"mappings":";;;;;;AAWA;;;;;UAAiB,SAAA,SAAkB,kBAAA,EAAoB,gBAAA;AAAA,KAE3C,eAAA;EAMK,qCAJf,OAAA,EAAS,QAAA,EAAA;EAET,SAAA,UAEA;EAAA,MAAA,GAAS,MAAA;AAAA;;AAQX;;;;UAAiB,eAAA;EAcU;;;;EATzB,YAAA,CAAa,OAAA,EAAS,eAAA,GAAkB,SAAA;EAAlB;;;;;;;EAStB,SAAA,QAAiB,OAAA,CAAQ,UAAA;AAAA"}
|
|
@@ -1,74 +1,6 @@
|
|
|
1
1
|
import { PTableShape, PTableVector, TableRange } from "@milaboratories/pl-model-common";
|
|
2
2
|
|
|
3
3
|
//#region src/pframe/internal_api/table.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Table view returned by `createTable`.
|
|
6
|
-
*
|
|
7
|
-
* {@link PTableV11.export} takes a `headers` map (unified column index →
|
|
8
|
-
* header name) that both selects the columns to export and names them.
|
|
9
|
-
*
|
|
10
|
-
* PTable can be thought as having a composite primary key, consisting
|
|
11
|
-
* of axes, and a set of data columns derived from PColumn values.
|
|
12
|
-
* The table's column spec is owned by the caller — selector → index
|
|
13
|
-
* resolution runs on the caller side via WASM-spec.
|
|
14
|
-
*/
|
|
15
|
-
interface PTableV11 extends Disposable {
|
|
16
|
-
/**
|
|
17
|
-
* Get PTable disk footprint in bytes.
|
|
18
|
-
*
|
|
19
|
-
* @param ops.withPredecessors When true, the footprint includes
|
|
20
|
-
* every registered predecessor table reachable through the
|
|
21
|
-
* query lineage. When false or omitted, only this table's own
|
|
22
|
-
* materialised data is counted.
|
|
23
|
-
*
|
|
24
|
-
* Warning: This call materializes the join.
|
|
25
|
-
*/
|
|
26
|
-
getFootprint(ops?: {
|
|
27
|
-
withPredecessors?: boolean;
|
|
28
|
-
signal?: AbortSignal;
|
|
29
|
-
}): Promise<number>;
|
|
30
|
-
/**
|
|
31
|
-
* Unified table shape
|
|
32
|
-
* Warning: This call materializes the join.
|
|
33
|
-
*/
|
|
34
|
-
getShape(ops?: {
|
|
35
|
-
signal?: AbortSignal;
|
|
36
|
-
}): Promise<PTableShape>;
|
|
37
|
-
/**
|
|
38
|
-
* Retrieve the data from the table. To retrieve only data required, it can be
|
|
39
|
-
* sliced both horizontally ({@link columnIndices}) and vertically
|
|
40
|
-
* ({@link range}).
|
|
41
|
-
* This call materializes the join.
|
|
42
|
-
*
|
|
43
|
-
* @param columnIndices unified indices of columns to be retrieved
|
|
44
|
-
* @param range optionally limit the range of records to retrieve
|
|
45
|
-
* */
|
|
46
|
-
getData(columnIndices: number[], ops?: {
|
|
47
|
-
range?: TableRange;
|
|
48
|
-
signal?: AbortSignal;
|
|
49
|
-
}): Promise<PTableVector[]>;
|
|
50
|
-
/**
|
|
51
|
-
* Stream the sorted table to a file at `path`. The output format is
|
|
52
|
-
* selected from the file extension: `csv`, `tsv`, `parquet`, or `xlsx`.
|
|
53
|
-
* Writing is bounded-memory.
|
|
54
|
-
* This call materializes the join.
|
|
55
|
-
*
|
|
56
|
-
* @param path destination file path; its extension selects the format
|
|
57
|
-
* @param headers map from unified column index (axes first, then data
|
|
58
|
-
* columns) to the header name to use for that column. Only the columns
|
|
59
|
-
* present as keys are exported, in ascending index order — the map both
|
|
60
|
-
* selects the columns and names them (the data layer is name-independent,
|
|
61
|
-
* so names are supplied by the caller).
|
|
62
|
-
*
|
|
63
|
-
* @remarks For `xlsx` the caller must ensure the row count is below Excel's
|
|
64
|
-
* 1,048,576-row per-sheet limit.
|
|
65
|
-
*/
|
|
66
|
-
export(path: string, headers: Record<number, string>, ops?: {
|
|
67
|
-
signal?: AbortSignal;
|
|
68
|
-
}): Promise<void>;
|
|
69
|
-
/** Deallocates all underlying resources */
|
|
70
|
-
dispose(): void;
|
|
71
|
-
}
|
|
72
4
|
/**
|
|
73
5
|
* Table view returned by `createTable`.
|
|
74
6
|
*
|
|
@@ -77,10 +9,9 @@ interface PTableV11 extends Disposable {
|
|
|
77
9
|
* declaration repeats the full method surface rather than referencing the
|
|
78
10
|
* predecessors.
|
|
79
11
|
*
|
|
80
|
-
*
|
|
81
|
-
* `
|
|
82
|
-
*
|
|
83
|
-
* `Record<number, string>` map.
|
|
12
|
+
* {@link PTableV12.export} takes an `ops.headers` list of
|
|
13
|
+
* `[unified column index, header name]` pairs that both selects the columns
|
|
14
|
+
* to export and names them.
|
|
84
15
|
*
|
|
85
16
|
* PTable can be thought as having a composite primary key, consisting
|
|
86
17
|
* of axes, and a set of data columns derived from PColumn values.
|
|
@@ -146,5 +77,5 @@ interface PTableV12 extends Disposable {
|
|
|
146
77
|
dispose(): void;
|
|
147
78
|
}
|
|
148
79
|
//#endregion
|
|
149
|
-
export {
|
|
80
|
+
export { PTableV12 };
|
|
150
81
|
//# sourceMappingURL=table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","names":[],"sources":["../../../src/pframe/internal_api/table.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"table.d.ts","names":[],"sources":["../../../src/pframe/internal_api/table.ts"],"mappings":";;;;;AAmBA;;;;;;;;;;;;;;;UAAiB,SAAA,SAAkB,UAAA;EAAU;;;;;;;;;;EAW3C,YAAA,CAAa,GAAA;IAAQ,gBAAA;IAA4B,MAAA,GAAS,WAAA;EAAA,IAAgB,OAAA;EAiB1E;;;;EAXA,QAAA,CAAS,GAAA;IAAQ,MAAA,GAAS,WAAA;EAAA,IAAgB,OAAA,CAAQ,WAAA;EAiB/C;;;;;;;;;EANH,OAAA,CACE,aAAA,YACA,GAAA;IACE,KAAA,GAAQ,UAAA;IACR,MAAA,GAAS,WAAA;EAAA,IAEV,OAAA,CAAQ,YAAA;;;;;;;;;;;;;;;;;EAkBX,MAAA,CACE,IAAA,UACA,GAAA;IACE,OAAA;IACA,MAAA,GAAS,WAAA;EAAA,IAEV,OAAA;;EAGH,OAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milaboratories/pl-model-middle-layer",
|
|
3
|
-
"version": "1.30.
|
|
3
|
+
"version": "1.30.6",
|
|
4
4
|
"description": "Common model between middle layer and non-block UI code",
|
|
5
5
|
"files": [
|
|
6
6
|
"./dist/**/*",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/node": "~24.5.2",
|
|
28
28
|
"typescript": "~5.9.3",
|
|
29
|
-
"@milaboratories/ts-builder": "1.5.0",
|
|
30
29
|
"@milaboratories/build-configs": "2.0.0",
|
|
30
|
+
"@milaboratories/ts-builder": "1.5.0",
|
|
31
31
|
"@milaboratories/ts-configs": "1.2.3"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
DataQuery,
|
|
5
5
|
DataQueryBooleanExpression,
|
|
6
6
|
} from "@milaboratories/pl-model-common";
|
|
7
|
-
import type {
|
|
7
|
+
import type { PTableV12 } from "./table";
|
|
8
8
|
import type { PTableId } from "./common";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -40,9 +40,6 @@ export interface UniqueValuesRequestV2 {
|
|
|
40
40
|
* `PTableV*` interface is dropped, so this declaration repeats the full
|
|
41
41
|
* method surface rather than referencing the predecessors.
|
|
42
42
|
*
|
|
43
|
-
* Same surface as {@link PFrameReadAPIV14}; the only change is that
|
|
44
|
-
* {@link PFrameReadAPIV15.createTable} returns {@link PTableV12}.
|
|
45
|
-
*
|
|
46
43
|
* Spec-side operations (finding columns, listing columns, retrieving
|
|
47
44
|
* column specs, computing axis integrations) are not part of this
|
|
48
45
|
* surface — callers cache column specs themselves or route through
|
|
@@ -62,27 +59,3 @@ export interface PFrameReadAPIV15 {
|
|
|
62
59
|
},
|
|
63
60
|
): Promise<UniqueValuesResponse>;
|
|
64
61
|
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Read interface exposed by PFrames library. Returns the {@link PTableV11}
|
|
68
|
-
* table view, whose `export` takes a column-index → header map.
|
|
69
|
-
*
|
|
70
|
-
* Spec-side operations (finding columns, listing columns, retrieving
|
|
71
|
-
* column specs, computing axis integrations) are not part of this
|
|
72
|
-
* surface — callers cache column specs themselves or route through
|
|
73
|
-
* WASM-spec. The data-side `createTable` accepts a pre-lowered
|
|
74
|
-
* `DataQuery`; `getUniqueValues` takes pre-resolved indices via
|
|
75
|
-
* {@link UniqueValuesRequestV2}.
|
|
76
|
-
*/
|
|
77
|
-
export interface PFrameReadAPIV14 {
|
|
78
|
-
/** Creates table from a pre-lowered data query. */
|
|
79
|
-
createTable(tableId: PTableId, dataQuery: DataQuery): PTableV11;
|
|
80
|
-
|
|
81
|
-
/** Calculate set of unique values for a specific axis for the filtered set of records. */
|
|
82
|
-
getUniqueValues(
|
|
83
|
-
request: UniqueValuesRequestV2,
|
|
84
|
-
ops?: {
|
|
85
|
-
signal?: AbortSignal;
|
|
86
|
-
},
|
|
87
|
-
): Promise<UniqueValuesResponse>;
|
|
88
|
-
}
|
|
@@ -165,14 +165,96 @@ export abstract class BaseObjectStore implements ObjectStore {
|
|
|
165
165
|
): Promise<void>;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/** Configuration for {@link HttpHelpers.createCachingObjectStore} */
|
|
169
|
+
export type CacheConfig = {
|
|
170
|
+
/** Filesystem path where the cache persists its data */
|
|
171
|
+
cachePath: string;
|
|
172
|
+
/** Hard total size budget in bytes; the cache self-stabilizes near this size */
|
|
173
|
+
maxSizeBytes: number;
|
|
174
|
+
/**
|
|
175
|
+
* Max share of the budget a single file may occupy (0..1); when a file exceeds it, that
|
|
176
|
+
* file's oldest ranges are evicted first. Stops one large scan from flushing the working set.
|
|
177
|
+
*/
|
|
178
|
+
admissionFraction: number;
|
|
179
|
+
/** Upper bound on previously-evicted (ghost) files remembered to guide readmission; resident files are already byte-bounded */
|
|
180
|
+
maxFilesTracked: number;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Cumulative cache event counters. Surfaced both as lifetime totals (persisted across restarts)
|
|
185
|
+
* and as a per-process session view, @see CacheMetrics.
|
|
186
|
+
*/
|
|
187
|
+
export type CacheCounters = {
|
|
188
|
+
/** Requests fully served from cache */
|
|
189
|
+
hits: number;
|
|
190
|
+
/** Requests that fell through to upstream */
|
|
191
|
+
misses: number;
|
|
192
|
+
/** Bytes served from cache */
|
|
193
|
+
bytesServed: number;
|
|
194
|
+
/** Bytes downloaded from upstream on misses */
|
|
195
|
+
bytesFetched: number;
|
|
196
|
+
/** Bytes evicted to keep the cache within its total size budget, @see CacheConfig.maxSizeBytes */
|
|
197
|
+
bytesEvictedByBudget: number;
|
|
198
|
+
/** Bytes evicted because a single file exceeded its allowed share of the budget, @see CacheConfig.admissionFraction */
|
|
199
|
+
bytesEvictedByFileCap: number;
|
|
200
|
+
/** Files promoted on observed reuse, so they are retained longer than first-time entries */
|
|
201
|
+
promotions: number;
|
|
202
|
+
/** Previously evicted files that were re-requested and readmitted */
|
|
203
|
+
ghostReadmissions: number;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/** Snapshot of cache state and counters, @see CachingObjectStore.getMetrics */
|
|
207
|
+
export type CacheMetrics = {
|
|
208
|
+
/** Current resident bytes */
|
|
209
|
+
sizeBytes: number;
|
|
210
|
+
/** Number of files with resident (cached) bytes */
|
|
211
|
+
residentFiles: number;
|
|
212
|
+
/** Number of previously-evicted (ghost) files remembered, <= @see CacheConfig.maxFilesTracked */
|
|
213
|
+
ghostFiles: number;
|
|
214
|
+
/** Counters cumulative across all sessions (persisted) */
|
|
215
|
+
lifetime: CacheCounters;
|
|
216
|
+
/** The same counters scoped to the current process */
|
|
217
|
+
session: CacheCounters;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Options for caching object store creation, @see HttpHelpers.createCachingObjectStore.
|
|
222
|
+
* Standalone (not extending {@link ObjectStoreOptions}): a caching store is a decorator over
|
|
223
|
+
* `upstream`, so source-store options do not apply to it.
|
|
224
|
+
*/
|
|
225
|
+
export interface CachingObjectStoreOptions {
|
|
226
|
+
/** Upstream store consulted on cache misses */
|
|
227
|
+
upstream: ObjectStore;
|
|
228
|
+
/** Cache configuration */
|
|
229
|
+
config: CacheConfig;
|
|
230
|
+
/** Logger instance, no logging is performed when not provided */
|
|
231
|
+
logger?: Logger;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* An {@link ObjectStore} that serves byte ranges from a persistent local cache, fetching misses
|
|
236
|
+
* from an upstream store. This is the single handle for the cache: pass it as
|
|
237
|
+
* {@link RequestHandlerOptions.store}, read {@link CachingObjectStore.getMetrics}, and dispose it
|
|
238
|
+
* to release the cache, @see HttpHelpers.createCachingObjectStore.
|
|
239
|
+
*/
|
|
240
|
+
export interface CachingObjectStore extends ObjectStore, AsyncDisposable {
|
|
241
|
+
/** Instantaneous cache state plus lifetime/session counters */
|
|
242
|
+
getMetrics(): CacheMetrics;
|
|
243
|
+
/** Drop all cached data and zero the counters (test/benchmark use) */
|
|
244
|
+
reset(): Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
|
|
168
247
|
/** Object store base URL in format accepted by Apache DataFusion and DuckDB */
|
|
169
248
|
export type ObjectStoreUrl = Branded<string, "PFrameInternal.ObjectStoreUrl">;
|
|
170
249
|
|
|
171
250
|
/** HTTP(S) request handler creation options */
|
|
172
251
|
export type RequestHandlerOptions = {
|
|
173
|
-
/**
|
|
252
|
+
/**
|
|
253
|
+
* Object store to serve files from. Compose caching by wrapping the upstream store with
|
|
254
|
+
* {@link HttpHelpers.createCachingObjectStore} and passing the result here,
|
|
255
|
+
* @see HttpHelpers.createFsStore
|
|
256
|
+
*/
|
|
174
257
|
store: ObjectStore;
|
|
175
|
-
/** Here will go caching options... */
|
|
176
258
|
};
|
|
177
259
|
|
|
178
260
|
/** Server configuration options */
|
|
@@ -239,6 +321,13 @@ export interface HttpHelpers {
|
|
|
239
321
|
*/
|
|
240
322
|
createFsStore(options: FsStoreOptions): Promise<ObjectStore>;
|
|
241
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Wrap an upstream object store in a persistent byte-range cache backed by SQLite.
|
|
326
|
+
* The returned store is itself an {@link ObjectStore} (pass it to {@link createRequestHandler})
|
|
327
|
+
* and additionally exposes metrics and reset. Dispose it to close the cache database.
|
|
328
|
+
*/
|
|
329
|
+
createCachingObjectStore(options: CachingObjectStoreOptions): Promise<CachingObjectStore>;
|
|
330
|
+
|
|
242
331
|
/**
|
|
243
332
|
* Create an HTTP request handler for serving files from an object store.
|
|
244
333
|
* Accepts only paths of the form `/<filename>.parquet`, returns 410 otherwise.
|
|
@@ -1,25 +1,13 @@
|
|
|
1
1
|
import type { PFrameFactoryAPIV6 } from "./api_factory";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PFrameReadAPIV15 } from "./api_read";
|
|
3
3
|
import type { Logger } from "./common";
|
|
4
4
|
import type { PFrameId } from "./common";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Full PFrame surface — factory operations plus data-side reads. Exposes
|
|
8
|
-
* the self-contained {@link PFrameFactoryAPIV6} (column `typeSpec` embedded in
|
|
9
|
-
* `data`) plus {@link PFrameReadAPIV14}, whose tables' `export` takes a
|
|
10
|
-
* column-index → header map.
|
|
11
|
-
*/
|
|
12
|
-
export interface PFrameV17 extends PFrameFactoryAPIV6, PFrameReadAPIV14 {}
|
|
13
|
-
|
|
14
6
|
/**
|
|
15
7
|
* Full PFrame surface — factory operations plus data-side reads. Exposes
|
|
16
8
|
* the self-contained {@link PFrameFactoryAPIV6} (column `typeSpec` embedded in
|
|
17
9
|
* `data`) plus {@link PFrameReadAPIV15}, whose tables' `export` takes an
|
|
18
10
|
* `ops.headers` list of `[column index, header name]` pairs.
|
|
19
|
-
*
|
|
20
|
-
* Same surface as {@link PFrameV17}; the only change is that the read side is
|
|
21
|
-
* upgraded from {@link PFrameReadAPIV14} to {@link PFrameReadAPIV15}, so
|
|
22
|
-
* {@link PFrameReadAPIV15.createTable} returns {@link PTableV12}.
|
|
23
11
|
*/
|
|
24
12
|
export interface PFrameV18 extends PFrameFactoryAPIV6, PFrameReadAPIV15 {}
|
|
25
13
|
|
|
@@ -34,31 +22,7 @@ export type PFrameOptionsV2 = {
|
|
|
34
22
|
|
|
35
23
|
/**
|
|
36
24
|
* PFrame management functions exposed by the PFrame module. Creates
|
|
37
|
-
* {@link
|
|
38
|
-
*/
|
|
39
|
-
export interface PFrameFactoryV8 {
|
|
40
|
-
/**
|
|
41
|
-
* Create a new PFrame instance.
|
|
42
|
-
* @warning Use concurrency limiting to avoid OOM crashes when multiple instances are simultaneously in use.
|
|
43
|
-
*/
|
|
44
|
-
createPFrame(options: PFrameOptionsV2): PFrameV17;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Dump active allocations from all PFrames instances in pprof format.
|
|
48
|
-
* The result of this function should be saved as `profile.pb.gz`.
|
|
49
|
-
* Use {@link https://pprof.me/} or {@link https://www.speedscope.app/}
|
|
50
|
-
* to view the allocation flamechart.
|
|
51
|
-
* @warning This method will always reject on Windows!
|
|
52
|
-
*/
|
|
53
|
-
pprofDump: () => Promise<Uint8Array>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* PFrame management functions exposed by the PFrame module. Creates
|
|
58
|
-
* {@link PFrameV18} instances (self-contained column data info).
|
|
59
|
-
*
|
|
60
|
-
* Same surface as {@link PFrameFactoryV8}; the only change is that
|
|
61
|
-
* {@link PFrameFactoryV9.createPFrame} returns {@link PFrameV18}, whose tables'
|
|
25
|
+
* {@link PFrameV18} instances (self-contained column data info), whose tables'
|
|
62
26
|
* `export` takes an `ops.headers` list of `[column index, header name]` pairs.
|
|
63
27
|
*/
|
|
64
28
|
export interface PFrameFactoryV9 {
|
|
@@ -1,80 +1,5 @@
|
|
|
1
1
|
import type { PTableShape, PTableVector, TableRange } from "@milaboratories/pl-model-common";
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Table view returned by `createTable`.
|
|
5
|
-
*
|
|
6
|
-
* {@link PTableV11.export} takes a `headers` map (unified column index →
|
|
7
|
-
* header name) that both selects the columns to export and names them.
|
|
8
|
-
*
|
|
9
|
-
* PTable can be thought as having a composite primary key, consisting
|
|
10
|
-
* of axes, and a set of data columns derived from PColumn values.
|
|
11
|
-
* The table's column spec is owned by the caller — selector → index
|
|
12
|
-
* resolution runs on the caller side via WASM-spec.
|
|
13
|
-
*/
|
|
14
|
-
export interface PTableV11 extends Disposable {
|
|
15
|
-
/**
|
|
16
|
-
* Get PTable disk footprint in bytes.
|
|
17
|
-
*
|
|
18
|
-
* @param ops.withPredecessors When true, the footprint includes
|
|
19
|
-
* every registered predecessor table reachable through the
|
|
20
|
-
* query lineage. When false or omitted, only this table's own
|
|
21
|
-
* materialised data is counted.
|
|
22
|
-
*
|
|
23
|
-
* Warning: This call materializes the join.
|
|
24
|
-
*/
|
|
25
|
-
getFootprint(ops?: { withPredecessors?: boolean; signal?: AbortSignal }): Promise<number>;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Unified table shape
|
|
29
|
-
* Warning: This call materializes the join.
|
|
30
|
-
*/
|
|
31
|
-
getShape(ops?: { signal?: AbortSignal }): Promise<PTableShape>;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Retrieve the data from the table. To retrieve only data required, it can be
|
|
35
|
-
* sliced both horizontally ({@link columnIndices}) and vertically
|
|
36
|
-
* ({@link range}).
|
|
37
|
-
* This call materializes the join.
|
|
38
|
-
*
|
|
39
|
-
* @param columnIndices unified indices of columns to be retrieved
|
|
40
|
-
* @param range optionally limit the range of records to retrieve
|
|
41
|
-
* */
|
|
42
|
-
getData(
|
|
43
|
-
columnIndices: number[],
|
|
44
|
-
ops?: {
|
|
45
|
-
range?: TableRange;
|
|
46
|
-
signal?: AbortSignal;
|
|
47
|
-
},
|
|
48
|
-
): Promise<PTableVector[]>;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Stream the sorted table to a file at `path`. The output format is
|
|
52
|
-
* selected from the file extension: `csv`, `tsv`, `parquet`, or `xlsx`.
|
|
53
|
-
* Writing is bounded-memory.
|
|
54
|
-
* This call materializes the join.
|
|
55
|
-
*
|
|
56
|
-
* @param path destination file path; its extension selects the format
|
|
57
|
-
* @param headers map from unified column index (axes first, then data
|
|
58
|
-
* columns) to the header name to use for that column. Only the columns
|
|
59
|
-
* present as keys are exported, in ascending index order — the map both
|
|
60
|
-
* selects the columns and names them (the data layer is name-independent,
|
|
61
|
-
* so names are supplied by the caller).
|
|
62
|
-
*
|
|
63
|
-
* @remarks For `xlsx` the caller must ensure the row count is below Excel's
|
|
64
|
-
* 1,048,576-row per-sheet limit.
|
|
65
|
-
*/
|
|
66
|
-
export(
|
|
67
|
-
path: string,
|
|
68
|
-
headers: Record<number, string>,
|
|
69
|
-
ops?: {
|
|
70
|
-
signal?: AbortSignal;
|
|
71
|
-
},
|
|
72
|
-
): Promise<void>;
|
|
73
|
-
|
|
74
|
-
/** Deallocates all underlying resources */
|
|
75
|
-
dispose(): void;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
3
|
/**
|
|
79
4
|
* Table view returned by `createTable`.
|
|
80
5
|
*
|
|
@@ -83,10 +8,9 @@ export interface PTableV11 extends Disposable {
|
|
|
83
8
|
* declaration repeats the full method surface rather than referencing the
|
|
84
9
|
* predecessors.
|
|
85
10
|
*
|
|
86
|
-
*
|
|
87
|
-
* `
|
|
88
|
-
*
|
|
89
|
-
* `Record<number, string>` map.
|
|
11
|
+
* {@link PTableV12.export} takes an `ops.headers` list of
|
|
12
|
+
* `[unified column index, header name]` pairs that both selects the columns
|
|
13
|
+
* to export and names them.
|
|
90
14
|
*
|
|
91
15
|
* PTable can be thought as having a composite primary key, consisting
|
|
92
16
|
* of axes, and a set of data columns derived from PColumn values.
|