@dremio/js-sdk 0.22.0 → 0.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import { Observable } from "rxjs";
2
+ import { type EventSourceMessage } from "eventsource-parser/stream";
3
+ /**
4
+ * Takes an instance of `Response` that will resolve to a `text/event-stream` and maps it
5
+ * into an observable that emits for each event as it arrives
6
+ */
7
+ export declare const fromTextEventStream: (response: Promise<Response>) => Observable<EventSourceMessage>;
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Copyright (C) 2024-2025 Dremio Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Observable } from "rxjs";
17
+ import { EventSourceParserStream } from "eventsource-parser/stream";
18
+ import { HttpError } from "./HttpError.js";
19
+ /**
20
+ * Takes an instance of `Response` that will resolve to a `text/event-stream` and maps it
21
+ * into an observable that emits for each event as it arrives
22
+ */
23
+ export const fromTextEventStream = (response) => new Observable((subscriber) => {
24
+ /**
25
+ * Create an internal AbortController so that the response stream
26
+ * can be canceled early if the subscriber unsubscribes early
27
+ */
28
+ const controller = new AbortController();
29
+ const { signal } = controller;
30
+ response
31
+ .then(async (response) => {
32
+ if (!response.ok) {
33
+ throw await HttpError.fromResponse(response);
34
+ }
35
+ /**
36
+ * Even though the correct Content-Type header isn't strictly required,
37
+ * it's indicates either a client mistake or server implementation bug
38
+ */
39
+ if (response.headers.get("Content-Type") !== "text/event-stream") {
40
+ throw new Error(`Expected response type to be text/event-stream. Received ${response.headers.get("Content-Type")}.`);
41
+ }
42
+ /**
43
+ * Response body should never be undefined for a text/event-stream
44
+ */
45
+ if (!response.body) {
46
+ throw new Error(`Response body was undefined`);
47
+ }
48
+ /**
49
+ * Pipe the raw byte stream through a text decoder, and then
50
+ * through a parser that extracts individual SSE events
51
+ */
52
+ return response.body
53
+ .pipeThrough(new TextDecoderStream())
54
+ .pipeThrough(new EventSourceParserStream());
55
+ })
56
+ .then(async (readableStream) => {
57
+ const reader = readableStream.getReader();
58
+ /**
59
+ * Check if the observable has been unsubscribed before reading
60
+ * each chunk
61
+ */
62
+ while (!signal.aborted) {
63
+ const { done, value } = await reader.read();
64
+ /**
65
+ * Check again after reading a chunk if the observable
66
+ * has been unsubscribed to avoid calling .next() or
67
+ * .complete() unnecessarily on the observable
68
+ */
69
+ if (signal.aborted) {
70
+ break;
71
+ }
72
+ if (done) {
73
+ subscriber.complete();
74
+ break;
75
+ }
76
+ subscriber.next(value);
77
+ }
78
+ /**
79
+ * Always call .cancel() on the reader even if the while loop
80
+ * was exited due to stream completion in order to indicate it
81
+ * can be fully cleaned up
82
+ */
83
+ await reader.cancel();
84
+ })
85
+ .catch((e) => {
86
+ subscriber.error(e);
87
+ });
88
+ return () => {
89
+ controller.abort();
90
+ };
91
+ });
92
+ //# sourceMappingURL=fromTextEventStream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromTextEventStream.js","sourceRoot":"","sources":["../../src/common/fromTextEventStream.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAA2B,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,QAA2B,EAAE,EAAE,CACjE,IAAI,UAAU,CAAqB,CAAC,UAAU,EAAE,EAAE;IAChD;;;OA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AAK,CAAC,CAAC;QACzB,CAAC;QAED;;;;WAIG;QACH,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;QACpB,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC,CAAC,CAAC;IAEL,OAAO,GAAG,EAAE;QACV,UAAU,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Observable } from \"rxjs\";\nimport { type EventSourceMessage, EventSourceParserStream } from \"eventsource-parser/stream\";\nimport { HttpError } from \"./HttpError.ts\";\n\n/**\n * Takes an instance of `Response` that will resolve to a `text/event-stream` and maps it\n * into an observable that emits for each event as it arrives\n */\nexport const fromTextEventStream = (response: Promise<Response>) =>\n new Observable<EventSourceMessage>((subscriber) => {\n /**\n * Create an internal AbortController so that the response stream\n * can be canceled early if the subscriber unsubscribes early\n */\n const controller = new AbortController();\n const { signal } = controller;\n\n response\n .then(async (response) => {\n if (!response.ok) {\n throw await HttpError.fromResponse(response);\n }\n\n /**\n * Even though the correct Content-Type header isn't strictly required,\n * it's indicates either a client mistake or server implementation bug\n */\n if (response.headers.get(\"Content-Type\") !== \"text/event-stream\") {\n throw new Error(\n `Expected response type to be text/event-stream. Received ${response.headers.get(\"Content-Type\")}.`,\n );\n }\n\n /**\n * Response body should never be undefined for a text/event-stream\n */\n if (!response.body) {\n throw new Error(`Response body was undefined`);\n }\n\n /**\n * Pipe the raw byte stream through a text decoder, and then\n * through a parser that extracts individual SSE events\n */\n return response.body\n .pipeThrough(new TextDecoderStream())\n .pipeThrough(new EventSourceParserStream());\n })\n .then(async (readableStream) => {\n const reader = readableStream.getReader();\n\n /**\n * Check if the observable has been unsubscribed before reading\n * each chunk\n */\n while (!signal.aborted) {\n const { done, value } = await reader.read();\n\n /**\n * Check again after reading a chunk if the observable\n * has been unsubscribed to avoid calling .next() or\n * .complete() unnecessarily on the observable\n */\n if (signal.aborted) {\n break;\n }\n\n if (done) {\n subscriber.complete();\n break;\n }\n\n subscriber.next(value);\n }\n\n /**\n * Always call .cancel() on the reader even if the while loop\n * was exited due to stream completion in order to indicate it\n * can be fully cleaned up\n */\n await reader.cancel();\n })\n .catch((e: unknown) => {\n subscriber.error(e);\n });\n\n return () => {\n controller.abort();\n };\n });\n"]}
@@ -1,5 +1,6 @@
1
1
  import { HttpError } from "../common/HttpError.ts";
2
2
  export { HttpError };
3
3
  export * from "./CredentialProvider.ts";
4
+ export * from "./fromTextEventStream.ts";
4
5
  export * from "./Problem.ts";
5
6
  export * from "./Query.ts";
@@ -16,6 +16,7 @@
16
16
  import { HttpError } from "../common/HttpError.js";
17
17
  export { HttpError };
18
18
  export * from "./CredentialProvider.js";
19
+ export * from "./fromTextEventStream.js";
19
20
  export * from "./Problem.js";
20
21
  export * from "./Query.js";
21
22
  //# sourceMappingURL=sharedExports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedExports.js","sourceRoot":"","sources":["../../src/common/sharedExports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HttpError } from \"../common/HttpError.ts\";\nexport { HttpError };\nexport * from \"./CredentialProvider.ts\";\nexport * from \"./Problem.ts\";\nexport * from \"./Query.ts\";\n"]}
1
+ {"version":3,"file":"sharedExports.js","sourceRoot":"","sources":["../../src/common/sharedExports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { HttpError } from \"../common/HttpError.ts\";\nexport { HttpError };\nexport * from \"./CredentialProvider.ts\";\nexport * from \"./fromTextEventStream.ts\";\nexport * from \"./Problem.ts\";\nexport * from \"./Query.ts\";\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { SonarV3Config } from "../../common/Config.ts";
2
2
  import { Err, Ok, Result } from "ts-results-es";
3
3
  import { type Observable } from "rxjs";
4
+ import { type MappedFieldValue } from "./utils/mapRowData.ts";
4
5
  import type { SignalParam } from "../../common/Params.ts";
5
6
  import type { JobProperties } from "./utils/jobEntityToProperties.ts";
6
7
  import type { HttpError } from "../../common/HttpError.ts";
@@ -22,14 +23,14 @@ export declare class Job {
22
23
  constructor(properties: JobProperties, config: SonarV3Config, observe: (id: string) => Observable<Result<Job, HttpError>>);
23
24
  get settled(): boolean;
24
25
  get results(): {
25
- jsonBatches: <T extends Record<string, unknown> = Record<string, unknown>>(args?: {
26
+ jsonBatches: <T extends Record<string, MappedFieldValue> = Record<string, string | number | bigint | boolean | import("temporal-polyfill").Temporal.PlainDateTime | import("temporal-polyfill").Temporal.PlainDate | import("temporal-polyfill").Temporal.PlainTime | null>>(args?: {
26
27
  limit?: number;
27
28
  offset?: number;
28
29
  }, { signal }?: SignalParam) => AsyncGenerator<{
29
- readonly columns: Record<Extract<keyof T, string>, unknown[] | Float64Array<ArrayBuffer> | Float32Array<ArrayBuffer> | Int32Array<ArrayBuffer>>;
30
+ readonly columns: Record<string, unknown[] | Float64Array<ArrayBuffer> | Float32Array<ArrayBuffer> | Int32Array<ArrayBuffer>>;
30
31
  readonly rows: T[];
31
32
  readonly schema: {
32
- fields: import("./utils/JobResultsResponse.ts").JobResultsSchema<Extract<keyof T, string>>;
33
+ readonly fields: import("./utils/JobResultsResponse.ts").JobResultsSchema<Extract<keyof T, string>>;
33
34
  };
34
35
  readonly totalRows: number;
35
36
  }, void, unknown>;
@@ -37,7 +38,7 @@ export declare class Job {
37
38
  schema: import("./utils/JobResultsResponse.ts").JobResultsSchema<string>;
38
39
  totalRows: number;
39
40
  }, HttpError>>;
40
- slice: <T extends Record<string, unknown> = Record<string, unknown>>(start?: number, end?: number, { signal }?: SignalParam) => Promise<Ok<T[]> | Err<unknown>>;
41
+ slice: <T extends Record<string, MappedFieldValue> = Record<string, string | number | bigint | boolean | import("temporal-polyfill").Temporal.PlainDateTime | import("temporal-polyfill").Temporal.PlainDate | import("temporal-polyfill").Temporal.PlainTime | null>>(start?: number, end?: number, { signal }?: SignalParam) => Promise<Ok<T[]> | Err<unknown>>;
41
42
  };
42
43
  /**
43
44
  * @returns A `Job` instance once it's reached a settled state
@@ -105,18 +105,19 @@ export class Job {
105
105
  const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);
106
106
  const batch = (await this.#config
107
107
  .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })
108
- .map((res) => res.json()).promise).unwrap();
108
+ .map((res) => res.json())
109
+ .promise).unwrap();
109
110
  offset += batch.rows.length;
110
111
  hasMore = batch.rows.length === batch_size;
111
112
  if (batch.rows.length) {
112
- const schema = { fields: batch.schema };
113
- mapRowData(batch.rows, batch.schema);
113
+ const batchT = batch;
114
+ mapRowData(batch.rows, batchT.schema);
114
115
  yield {
115
116
  get columns() {
116
117
  return mapRowsToColumns(batch);
117
118
  },
118
- rows: batch.rows,
119
- schema,
119
+ rows: batchT.rows,
120
+ schema: { fields: batchT.schema },
120
121
  totalRows: batch.rowCount,
121
122
  };
122
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAmB,MAAM,MAAM,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKnD,MAAM,OAAO,GAAG;IACL,YAAY,CAAgC;IAC5C,kBAAkB,CAAsC;IACxD,YAAY,CAAU;IACtB,OAAO,CAA2B;IAClC,EAAE,CAAsB;IACxB,OAAO,CAA2B;IAClC,SAAS,CAA6B;IACtC,yBAAyB,CAA6C;IACtE,2BAA2B,CAA+C;IAC1E,QAAQ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G,CAAC,GAAG,EAAE,CAAC,SAAiB,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,cAAc,GAAG,GAAG,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { Err, Ok, Result } from \"ts-results-es\";\nimport { lastValueFrom, map, of, switchMap, type Observable } from \"rxjs\";\nimport type { JobResultsResponse } from \"./utils/JobResultsResponse.ts\";\nimport { mapRowsToColumns } from \"./utils/mapRowsToColumns.ts\";\nimport { mapRowData } from \"./utils/mapRowData.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport type { JobProperties } from \"./utils/jobEntityToProperties.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\n readonly errorMessage?: string;\n readonly endedAt: JobProperties[\"endedAt\"];\n readonly id: JobProperties[\"id\"];\n readonly problem: JobProperties[\"problem\"];\n readonly queryType: JobProperties[\"queryType\"];\n readonly resourceSchedulingEndedAt: JobProperties[\"resourceSchedulingEndedAt\"];\n readonly resourceSchedulingStartedAt: JobProperties[\"resourceSchedulingStartedAt\"];\n readonly rowCount: JobProperties[\"rowCount\"];\n readonly startedAt: JobProperties[\"startedAt\"];\n readonly state: JobProperties[\"state\"];\n\n public readonly observer: Observable<Job>;\n #config: SonarV3Config;\n\n constructor(\n properties: JobProperties,\n config: SonarV3Config,\n observe: (id: string) => Observable<Result<Job, HttpError>>,\n ) {\n this.acceleration = properties.acceleration;\n this.cancellationReason = properties.cancellationReason;\n this.endedAt = properties.endedAt;\n this.id = properties.id;\n this.problem = properties.problem;\n this.queryType = properties.queryType;\n this.resourceSchedulingEndedAt = properties.resourceSchedulingEndedAt;\n this.resourceSchedulingStartedAt = properties.resourceSchedulingStartedAt;\n this.rowCount = properties.rowCount;\n this.startedAt = properties.startedAt;\n this.state = properties.state;\n this.#config = config;\n this.observer = of(this).pipe(\n switchMap((job) => {\n if (!job.settled) {\n return observe(this.id).pipe(\n map((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n );\n } else {\n return of(job);\n }\n }),\n );\n\n if (properties.errorMessage) {\n this.errorMessage = properties.errorMessage;\n }\n }\n\n get settled() {\n return (\n this.state === \"COMPLETED\" ||\n this.state === \"FAILED\" ||\n this.state === \"INVALID_STATE\" ||\n this.state === \"CANCELED\"\n );\n }\n\n get results() {\n return {\n jsonBatches: this.#jsonBatches.bind(this),\n metadata: this.#metadata.bind(this),\n slice: this.#slice.bind(this),\n };\n }\n\n /**\n * @returns A `Job` instance once it's reached a settled state\n */\n retrieveSettled() {\n return lastValueFrom(this.observer);\n }\n\n async *#jsonBatches<T extends Record<string, unknown> = Record<string, unknown>>(\n args: { limit?: number; offset?: number } = {},\n { signal }: SignalParam = {},\n ) {\n if (typeof args.limit === \"number\" && args.limit < 0) {\n throw new Error(\"Limit cannot be negative\");\n }\n\n if (typeof args.offset === \"number\" && args.offset < 0) {\n throw new Error(\"Offset cannot be negative\");\n }\n\n // Wait for job to enter a settled state before attempting to fetch batches\n if (!this.settled) {\n await this.retrieveSettled();\n }\n\n const limitArg = args.limit ?? Infinity;\n const offsetArg = args.offset || 0;\n\n // Tracks whether there are more rows available from the job results endpoint\n let hasMore = true;\n\n // Tracks the currently requested offset. If the offset arg is provided, start from there instead of 0.\n let offset = offsetArg;\n\n // Keeps track of the total number of rows that need to be loaded\n const stopAfterOffset = limitArg + offsetArg;\n\n while (hasMore && offset < stopAfterOffset) {\n // Make batch_size dynamic to allow for requesting a smaller final page\n const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);\n\n const batch = (\n await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse<T>>).promise\n ).unwrap();\n\n offset += batch.rows.length;\n hasMore = batch.rows.length === batch_size;\n\n if (batch.rows.length) {\n const schema = { fields: batch.schema };\n mapRowData(batch.rows, batch.schema);\n yield {\n get columns() {\n return mapRowsToColumns(batch);\n },\n rows: batch.rows,\n schema,\n totalRows: batch.rowCount,\n } as const;\n }\n }\n }\n\n async #metadata({ signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse>)\n .map((response) => ({\n schema: response.schema,\n totalRows: response.rowCount,\n })).promise;\n }\n\n async #slice<T extends Record<string, unknown> = Record<string, unknown>>(\n start: number = 0,\n end: number = Infinity,\n { signal }: SignalParam = {},\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>(\n { limit: end - start, offset: start },\n { signal },\n )) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .map(() => undefined as void).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
1
+ {"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAmB,MAAM,MAAM,CAAC;AAE1E,OAAO,EA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;YAC3B,CAAC;YACD,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;QAClB,CAAC;QAAC,OAAO,CAAU,EAAE,CAAC;YACpB,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE;YACvC,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,MAAM;SACf,CAAC;aACD,GAAG,CAAC,GAAG,EAAE,CAAC,SAAiB,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,cAAc,GAAG,GAAG,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { Err, Ok, Result } from \"ts-results-es\";\nimport { lastValueFrom, map, of, switchMap, type Observable } from \"rxjs\";\nimport type { JobResultsResponse } from \"./utils/JobResultsResponse.ts\";\nimport { mapRowsToColumns } from \"./utils/mapRowsToColumns.ts\";\nimport { mapRowData, type MappedFieldValue } from \"./utils/mapRowData.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport type { JobProperties } from \"./utils/jobEntityToProperties.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\nimport type { JSONValue } from \"./utils/JSONValue.ts\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\n readonly errorMessage?: string;\n readonly endedAt: JobProperties[\"endedAt\"];\n readonly id: JobProperties[\"id\"];\n readonly problem: JobProperties[\"problem\"];\n readonly queryType: JobProperties[\"queryType\"];\n readonly resourceSchedulingEndedAt: JobProperties[\"resourceSchedulingEndedAt\"];\n readonly resourceSchedulingStartedAt: JobProperties[\"resourceSchedulingStartedAt\"];\n readonly rowCount: JobProperties[\"rowCount\"];\n readonly startedAt: JobProperties[\"startedAt\"];\n readonly state: JobProperties[\"state\"];\n\n public readonly observer: Observable<Job>;\n #config: SonarV3Config;\n\n constructor(\n properties: JobProperties,\n config: SonarV3Config,\n observe: (id: string) => Observable<Result<Job, HttpError>>,\n ) {\n this.acceleration = properties.acceleration;\n this.cancellationReason = properties.cancellationReason;\n this.endedAt = properties.endedAt;\n this.id = properties.id;\n this.problem = properties.problem;\n this.queryType = properties.queryType;\n this.resourceSchedulingEndedAt = properties.resourceSchedulingEndedAt;\n this.resourceSchedulingStartedAt = properties.resourceSchedulingStartedAt;\n this.rowCount = properties.rowCount;\n this.startedAt = properties.startedAt;\n this.state = properties.state;\n this.#config = config;\n this.observer = of(this).pipe(\n switchMap((job) => {\n if (!job.settled) {\n return observe(this.id).pipe(\n map((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n );\n } else {\n return of(job);\n }\n }),\n );\n\n if (properties.errorMessage) {\n this.errorMessage = properties.errorMessage;\n }\n }\n\n get settled() {\n return (\n this.state === \"COMPLETED\" ||\n this.state === \"FAILED\" ||\n this.state === \"INVALID_STATE\" ||\n this.state === \"CANCELED\"\n );\n }\n\n get results() {\n return {\n jsonBatches: this.#jsonBatches.bind(this),\n metadata: this.#metadata.bind(this),\n slice: this.#slice.bind(this),\n };\n }\n\n /**\n * @returns A `Job` instance once it's reached a settled state\n */\n retrieveSettled() {\n return lastValueFrom(this.observer);\n }\n\n async *#jsonBatches<\n T extends Record<string, MappedFieldValue> = Record<string, MappedFieldValue>,\n >(args: { limit?: number; offset?: number } = {}, { signal }: SignalParam = {}) {\n if (typeof args.limit === \"number\" && args.limit < 0) {\n throw new Error(\"Limit cannot be negative\");\n }\n\n if (typeof args.offset === \"number\" && args.offset < 0) {\n throw new Error(\"Offset cannot be negative\");\n }\n\n // Wait for job to enter a settled state before attempting to fetch batches\n if (!this.settled) {\n await this.retrieveSettled();\n }\n\n const limitArg = args.limit ?? Infinity;\n const offsetArg = args.offset || 0;\n\n // Tracks whether there are more rows available from the job results endpoint\n let hasMore = true;\n\n // Tracks the currently requested offset. If the offset arg is provided, start from there instead of 0.\n let offset = offsetArg;\n\n // Keeps track of the total number of rows that need to be loaded\n const stopAfterOffset = limitArg + offsetArg;\n\n while (hasMore && offset < stopAfterOffset) {\n // Make batch_size dynamic to allow for requesting a smaller final page\n const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);\n\n const batch = (\n await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse<Record<string, JSONValue>>>)\n .promise\n ).unwrap();\n\n offset += batch.rows.length;\n hasMore = batch.rows.length === batch_size;\n\n if (batch.rows.length) {\n const batchT = batch as unknown as JobResultsResponse<T>;\n mapRowData(batch.rows, batchT.schema);\n yield {\n get columns() {\n return mapRowsToColumns(batch);\n },\n rows: batchT.rows,\n schema: { fields: batchT.schema },\n totalRows: batch.rowCount,\n } as const;\n }\n }\n }\n\n async #metadata({ signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse>)\n .map((response) => ({\n schema: response.schema,\n totalRows: response.rowCount,\n })).promise;\n }\n\n async #slice<T extends Record<string, MappedFieldValue> = Record<string, MappedFieldValue>>(\n start: number = 0,\n end: number = Infinity,\n { signal }: SignalParam = {},\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>(\n { limit: end - start, offset: start },\n { signal },\n )) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .map(() => undefined as void).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
@@ -0,0 +1,3 @@
1
+ export type JSONValue = string | number | boolean | null | JSONValue[] | {
2
+ [key: string]: JSONValue;
3
+ };
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright (C) 2024-2025 Dremio Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=JSONValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JSONValue.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/JSONValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport type JSONValue =\n | string\n | number\n | boolean\n | null\n | JSONValue[]\n | { [key: string]: JSONValue };\n"]}
@@ -1,3 +1,4 @@
1
+ import type { JSONValue } from "./JSONValue.ts";
1
2
  type VarcharType = {
2
3
  name: "VARCHAR";
3
4
  };
@@ -77,7 +78,7 @@ export type JobResultsSchema<TName extends string = string> = {
77
78
  name: TName;
78
79
  type: SimpleTypes | ComplexTypes;
79
80
  }[];
80
- export type JobResultsResponse<T extends Record<string, unknown> = Record<string, unknown>> = {
81
+ export type JobResultsResponse<T extends Record<string, unknown> = Record<string, JSONValue>> = {
81
82
  rowCount: number;
82
83
  rows: T[];
83
84
  schema: JobResultsSchema<Extract<keyof T, string>>;
@@ -1 +1 @@
1
- {"version":3,"file":"JobResultsResponse.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/JobResultsResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\ntype VarcharType = {\n name: \"VARCHAR\";\n};\n\ntype TextType = {\n name: \"TEXT\";\n};\n\ntype BinaryType = {\n name: \"BINARY\";\n};\n\ntype VarbinaryType = {\n name: \"VARBINARY\";\n};\n\ntype FloatType = {\n name: \"FLOAT\";\n};\n\ntype DecimalType = {\n name: \"DECIMAL\";\n};\n\ntype IntegerType = {\n name: \"INTEGER\";\n};\n\ntype MixedType = {\n name: \"MIXED\";\n};\n\ntype UnionType = {\n name: \"UNION\";\n};\n\ntype DateType = {\n name: \"DATE\";\n};\n\ntype TimeType = {\n name: \"TIME\";\n};\n\ntype DatetimeType = {\n name: \"DATETIME\";\n};\n\ntype MapType = {\n name: \"MAP\";\n};\n\ntype GeoType = {\n name: \"GEO\";\n};\n\ntype OtherType = {\n name: \"OTHER\";\n};\n\ntype AnyType = {\n name: \"ANY\";\n};\n\ntype DoubleType = {\n name: \"DOUBLE\";\n};\n\ntype BigintType = {\n name: \"BIGINT\";\n};\n\ntype BooleanType = {\n name: \"BOOLEAN\";\n};\n\ntype TimestampType = {\n name: \"TIMESTAMP\";\n};\n\ntype SimpleTypes =\n | VarcharType\n | DoubleType\n | BigintType\n | BooleanType\n | TimestampType\n | TextType\n | BinaryType\n | VarbinaryType\n | FloatType\n | DecimalType\n | IntegerType\n | MixedType\n | UnionType\n | DateType\n | TimeType\n | DatetimeType\n | MapType\n | GeoType\n | OtherType\n | AnyType;\n\ntype ListType = {\n name: \"LIST\";\n subSchema: {\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype StructType = {\n name: \"STRUCT\";\n subSchema: {\n name: string;\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype ComplexTypes = ListType | StructType;\n\nexport type JobResultsSchema<TName extends string = string> = {\n name: TName;\n type: SimpleTypes | ComplexTypes;\n}[];\n\nexport type JobResultsResponse<T extends Record<string, unknown> = Record<string, unknown>> = {\n rowCount: number;\n rows: T[];\n schema: JobResultsSchema<Extract<keyof T, string>>;\n};\n"]}
1
+ {"version":3,"file":"JobResultsResponse.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/JobResultsResponse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { JSONValue } from \"./JSONValue.ts\";\n\ntype VarcharType = {\n name: \"VARCHAR\";\n};\n\ntype TextType = {\n name: \"TEXT\";\n};\n\ntype BinaryType = {\n name: \"BINARY\";\n};\n\ntype VarbinaryType = {\n name: \"VARBINARY\";\n};\n\ntype FloatType = {\n name: \"FLOAT\";\n};\n\ntype DecimalType = {\n name: \"DECIMAL\";\n};\n\ntype IntegerType = {\n name: \"INTEGER\";\n};\n\ntype MixedType = {\n name: \"MIXED\";\n};\n\ntype UnionType = {\n name: \"UNION\";\n};\n\ntype DateType = {\n name: \"DATE\";\n};\n\ntype TimeType = {\n name: \"TIME\";\n};\n\ntype DatetimeType = {\n name: \"DATETIME\";\n};\n\ntype MapType = {\n name: \"MAP\";\n};\n\ntype GeoType = {\n name: \"GEO\";\n};\n\ntype OtherType = {\n name: \"OTHER\";\n};\n\ntype AnyType = {\n name: \"ANY\";\n};\n\ntype DoubleType = {\n name: \"DOUBLE\";\n};\n\ntype BigintType = {\n name: \"BIGINT\";\n};\n\ntype BooleanType = {\n name: \"BOOLEAN\";\n};\n\ntype TimestampType = {\n name: \"TIMESTAMP\";\n};\n\ntype SimpleTypes =\n | VarcharType\n | DoubleType\n | BigintType\n | BooleanType\n | TimestampType\n | TextType\n | BinaryType\n | VarbinaryType\n | FloatType\n | DecimalType\n | IntegerType\n | MixedType\n | UnionType\n | DateType\n | TimeType\n | DatetimeType\n | MapType\n | GeoType\n | OtherType\n | AnyType;\n\ntype ListType = {\n name: \"LIST\";\n subSchema: {\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype StructType = {\n name: \"STRUCT\";\n subSchema: {\n name: string;\n type: SimpleTypes | ComplexTypes;\n }[];\n};\n\ntype ComplexTypes = ListType | StructType;\n\nexport type JobResultsSchema<TName extends string = string> = {\n name: TName;\n type: SimpleTypes | ComplexTypes;\n}[];\n\nexport type JobResultsResponse<T extends Record<string, unknown> = Record<string, JSONValue>> = {\n rowCount: number;\n rows: T[];\n schema: JobResultsSchema<Extract<keyof T, string>>;\n};\n"]}
@@ -1,3 +1,7 @@
1
1
  import type { JobResultsResponse } from "./JobResultsResponse.ts";
2
+ import { Temporal } from "temporal-polyfill";
3
+ declare const mapFieldValue: (fieldType: JobResultsResponse["schema"][number]["type"]["name"], fieldValue: unknown) => string | number | bigint | boolean | Temporal.PlainDateTime | Temporal.PlainDate | Temporal.PlainTime | null;
4
+ export type MappedFieldValue = ReturnType<typeof mapFieldValue>;
2
5
  export declare const createRowTypeMapper: (schema: JobResultsResponse["schema"]) => (row: Record<string, unknown>) => void;
3
6
  export declare const mapRowData: (rows: JobResultsResponse["rows"], schema: JobResultsResponse["schema"]) => void;
7
+ export {};
@@ -13,13 +13,21 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ import { Temporal } from "temporal-polyfill";
16
17
  const mapFieldValue = (fieldType, fieldValue) => {
17
- if (fieldValue === null) {
18
+ if (fieldValue === null || fieldValue === undefined) {
18
19
  return null;
19
20
  }
20
21
  switch (fieldType) {
21
22
  case "TIMESTAMP":
22
- return new Date(fieldValue + "Z");
23
+ // Example: 2000-01-01 17:30:50.123
24
+ return Temporal.PlainDateTime.from(fieldValue.replace(" ", "T"));
25
+ case "DATE":
26
+ // Example: 2000-01-01
27
+ return Temporal.PlainDate.from(fieldValue);
28
+ case "TIME":
29
+ // Example: 17:30:50.235
30
+ return Temporal.PlainTime.from(fieldValue);
23
31
  case "BIGINT":
24
32
  return BigInt(fieldValue);
25
33
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"mapRowData.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,aAAa,GAAG,CACpB,SAA+D,EAC/D,UAAmB,EACnB,EAAE;IACF,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,WAAW;YACd,OAAO,IAAI,IAAI,CAAE,UAAqB,GAAG,GAAG,CAAC,CAAC;QAChD,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,UAAoB,CAAC,CAAC;QACtC;YACE,OAAO,UAAU,CAAC;IACtB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAoC,EAAE,EAAE;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,IAAI,GAAG,EAAgE,CAAC,CAAC;IAE5E,OAAO,CAAC,GAA4B,EAAE,EAAE;QACtC,KAAK,MAAM,QAAQ,IAAI,GAAG,EAAE,CAAC;YAC3B,GAAG,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAgC,EAChC,MAAoC,EAC9B,EAAE;IACR,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,SAAS,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { JobResultsResponse } from \"./JobResultsResponse.ts\";\n\nconst mapFieldValue = (\n fieldType: JobResultsResponse[\"schema\"][number][\"type\"][\"name\"],\n fieldValue: unknown,\n) => {\n if (fieldValue === null) {\n return null;\n }\n\n switch (fieldType) {\n case \"TIMESTAMP\":\n return new Date((fieldValue as string) + \"Z\");\n case \"BIGINT\":\n return BigInt(fieldValue as number);\n default:\n return fieldValue;\n }\n};\n\nexport const createRowTypeMapper = (schema: JobResultsResponse[\"schema\"]) => {\n const fieldTypes = schema.reduce((accum, field) => {\n accum.set(field.name, field.type.name);\n return accum;\n }, new Map<string, JobResultsResponse[\"schema\"][number][\"type\"][\"name\"]>());\n\n return (row: Record<string, unknown>) => {\n for (const property in row) {\n row[property] = mapFieldValue(fieldTypes.get(property)!, row[property]);\n }\n };\n};\n\nexport const mapRowData = (\n rows: JobResultsResponse[\"rows\"],\n schema: JobResultsResponse[\"schema\"],\n): void => {\n const rowMapper = createRowTypeMapper(schema);\n\n for (const row of rows) {\n rowMapper(row);\n }\n};\n"]}
1
+ {"version":3,"file":"mapRowData.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowData.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,aAAa,GAAG,CACpB,SAA+D,EAC/D,UAAmB,EACnB,EAAE;IACF,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QACpD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,WAAW;YACd,mCAAmC;YACnC,OAAO,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAE,UAAqB,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAC/E,KAAK,MAAM;YACT,sBAAsB;YACtB,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,UAAoB,CAAC,CAAC;QACvD,KAAK,MAAM;YACT,wBAAwB;YACxB,OAAO,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,UAAoB,CAAC,CAAC;QACvD,KAAK,QAAQ;YACX,OAAO,MAAM,CAAC,UAA6B,CAAC,CAAC;QAC/C;YACE,OAAO,UAAuC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC;AAIF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAoC,EAAE,EAAE;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAChD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACvC,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,IAAI,GAAG,EAAgE,CAAC,CAAC;IAE5E,OAAO,CAAC,GAA4B,EAAE,EAAE;QACtC,KAAK,MAAM,QAAQ,IAAI,GAAG,EAAE,CAAC;YAC3B,GAAG,CAAC,QAAQ,CAAC,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAE,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,IAAgC,EAChC,MAAoC,EAC9B,EAAE;IACR,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE9C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,SAAS,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { JobResultsResponse } from \"./JobResultsResponse.ts\";\nimport { Temporal } from \"temporal-polyfill\";\n\nconst mapFieldValue = (\n fieldType: JobResultsResponse[\"schema\"][number][\"type\"][\"name\"],\n fieldValue: unknown,\n) => {\n if (fieldValue === null || fieldValue === undefined) {\n return null;\n }\n switch (fieldType) {\n case \"TIMESTAMP\":\n // Example: 2000-01-01 17:30:50.123\n return Temporal.PlainDateTime.from((fieldValue as string).replace(\" \", \"T\"));\n case \"DATE\":\n // Example: 2000-01-01\n return Temporal.PlainDate.from(fieldValue as string);\n case \"TIME\":\n // Example: 17:30:50.235\n return Temporal.PlainTime.from(fieldValue as string);\n case \"BIGINT\":\n return BigInt(fieldValue as string | number);\n default:\n return fieldValue as string | number | boolean;\n }\n};\n\nexport type MappedFieldValue = ReturnType<typeof mapFieldValue>;\n\nexport const createRowTypeMapper = (schema: JobResultsResponse[\"schema\"]) => {\n const fieldTypes = schema.reduce((accum, field) => {\n accum.set(field.name, field.type.name);\n return accum;\n }, new Map<string, JobResultsResponse[\"schema\"][number][\"type\"][\"name\"]>());\n\n return (row: Record<string, unknown>) => {\n for (const property in row) {\n row[property] = mapFieldValue(fieldTypes.get(property)!, row[property]);\n }\n };\n};\n\nexport const mapRowData = (\n rows: JobResultsResponse[\"rows\"],\n schema: JobResultsResponse[\"schema\"],\n): void => {\n const rowMapper = createRowTypeMapper(schema);\n\n for (const row of rows) {\n rowMapper(row);\n }\n};\n"]}
@@ -1,2 +1,3 @@
1
1
  import type { JobResultsResponse } from "./JobResultsResponse.ts";
2
- export declare const mapRowsToColumns: <T extends Record<string, unknown>>(jobResults: JobResultsResponse<T>) => Record<Extract<keyof T, string>, unknown[] | Float64Array<ArrayBuffer> | Float32Array<ArrayBuffer> | Int32Array<ArrayBuffer>>;
2
+ import type { JSONValue } from "./JSONValue.ts";
3
+ export declare const mapRowsToColumns: <T extends Record<string, JSONValue>>(jobResults: JobResultsResponse<T>) => Record<Extract<keyof T, string>, unknown[] | Float64Array<ArrayBuffer> | Float32Array<ArrayBuffer> | Int32Array<ArrayBuffer>>;
@@ -1 +1 @@
1
- {"version":3,"file":"mapRowsToColumns.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowsToColumns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAGjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAAiC,EACjC,EAAE;IACF,MAAM,SAAS,GAAG,4BAA4B,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE1F,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACrD,KAAK,MAAM,UAAU,IAAI,GAAG,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YAClC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createColumnRecordFromSchema } from \"./createColumnRecordFromSchema.ts\";\nimport type { JobResultsResponse } from \"./JobResultsResponse.ts\";\n\nexport const mapRowsToColumns = <T extends Record<string, unknown>>(\n jobResults: JobResultsResponse<T>,\n) => {\n const columnMap = createColumnRecordFromSchema(jobResults.schema, jobResults.rows.length);\n\n for (const [index, row] of jobResults.rows.entries()) {\n for (const columnName in row) {\n const col = columnMap[columnName];\n col[index] = row[columnName];\n }\n }\n\n return columnMap;\n};\n"]}
1
+ {"version":3,"file":"mapRowsToColumns.js","sourceRoot":"","sources":["../../../../src/oss/jobs/utils/mapRowsToColumns.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AAIjF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,UAAiC,EACjC,EAAE;IACF,MAAM,SAAS,GAAG,4BAA4B,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE1F,KAAK,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;QACrD,KAAK,MAAM,UAAU,IAAI,GAAG,EAAE,CAAC;YAC7B,MAAM,GAAG,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC;YAClC,GAAG,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createColumnRecordFromSchema } from \"./createColumnRecordFromSchema.ts\";\nimport type { JobResultsResponse } from \"./JobResultsResponse.ts\";\nimport type { JSONValue } from \"./JSONValue.ts\";\n\nexport const mapRowsToColumns = <T extends Record<string, JSONValue>>(\n jobResults: JobResultsResponse<T>,\n) => {\n const columnMap = createColumnRecordFromSchema(jobResults.schema, jobResults.rows.length);\n\n for (const [index, row] of jobResults.rows.entries()) {\n for (const columnName in row) {\n const col = columnMap[columnName];\n col[index] = row[columnName];\n }\n }\n\n return columnMap;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.22.0",
3
+ "version": "0.24.0",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",
@@ -32,6 +32,7 @@
32
32
  "prepare": "node --run dist"
33
33
  },
34
34
  "dependencies": {
35
+ "eventsource-parser": "^3.0.1",
35
36
  "moize": "^6",
36
37
  "parse-ms": "^4",
37
38
  "rxjs": "^7",