@dremio/js-sdk 0.16.1 → 0.16.2

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.
@@ -16,13 +16,13 @@
16
16
  import { Job } from "./Job.js";
17
17
  import { Query } from "../../common/Query.js";
18
18
  import { AsyncResult } from "ts-results-es";
19
- import { repeat, shareReplay, takeWhile, tap } from "rxjs";
19
+ import { repeat, shareReplay, takeWhile, tap, timer } from "rxjs";
20
20
  import { fromAbortable } from "../../common/fromAbortable.js";
21
21
  import { jobEntityToProperties } from "./utils/jobEntityToProperties.js";
22
22
  import moize from "moize";
23
23
  export class JobsResource {
24
24
  #config;
25
- #createJobObservable = (id) => fromAbortable(({ signal }) => this.retrieve(id, { signal })).pipe(repeat({ delay: 1000 }), takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true));
25
+ #createJobObservable = (id) => fromAbortable(({ signal }) => this.retrieve(id, { signal })).pipe(repeat({ delay: (count) => timer(jobPollingBackoff(count - 1)) }), takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true));
26
26
  /**
27
27
  * Reuse the same observable every time the `observe` method is called.
28
28
  */
@@ -87,4 +87,5 @@ export class JobsResource {
87
87
  .map((entity) => this._jobFromEntity(id, entity)).promise;
88
88
  }
89
89
  }
90
+ const jobPollingBackoff = (count) => Math.min(Math.ceil((Math.max(count, 0) ** 2 / 40 + 1) * 1000), 3_000);
90
91
  //# sourceMappingURL=JobsResource.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JobsResource.js","sourceRoot":"","sources":["../../../src/oss/jobs/JobsResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE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CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC9D,CAAC;CACF","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 { Job } from \"./Job.ts\";\nimport { Query } from \"../../common/Query.ts\";\nimport { AsyncResult } from \"ts-results-es\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { repeat, shareReplay, takeWhile, tap } from \"rxjs\";\nimport { fromAbortable } from \"../../common/fromAbortable.ts\";\nimport { jobEntityToProperties, type JobEntity } from \"./utils/jobEntityToProperties.ts\";\nimport moize from \"moize\";\n\nexport class JobsResource {\n #config: SonarV3Config;\n\n #createJobObservable = (id: string) =>\n fromAbortable(({ signal }) => this.retrieve(id, { signal })).pipe(\n repeat({ delay: 1000 }),\n takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true),\n );\n\n /**\n * Reuse the same observable every time the `observe` method is called.\n */\n #jobObserverCache = moize.default(\n (id: string) =>\n this.#createJobObservable(id).pipe(\n tap({\n finalize: () => {\n this.#jobObserverCache.remove([id]);\n },\n }),\n /**\n * Reuse the same polling for multiple subscribers, buffering only the latest result.\n * Make sure to unsubscribe from the source to stop polling when there are no subscribers (refCount: true)\n */\n shareReplay({\n bufferSize: 1,\n refCount: true,\n }),\n ),\n {\n /**\n * Evict cached observables after 60s. We need some way to prevent a memory\n * leak for long-running SDK processes, and a maxAge of 60 seconds should be\n * enough to handle multiple subscribers attached programmatically to a job.\n * If it's not, then the worst case is that we'd make additional API calls.\n */\n maxAge: 60_000,\n maxSize: Infinity,\n },\n );\n\n constructor(config: SonarV3Config) {\n this.#config = config;\n }\n\n _jobFromEntity(id: string, entity: JobEntity): Job {\n return new Job(jobEntityToProperties(id, entity), this.#config, this.observe.bind(this));\n }\n\n create(query: Query) {\n return this.#config\n .sonarV3Request(`sql`, {\n body: JSON.stringify({\n context: query.context,\n sql: query.sql,\n }),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((response) => response.json() as Promise<{ id: string }>)\n .map((response) => response.id).promise;\n }\n\n /**\n * A convenience method to combine job creation and retrieval\n */\n createAndRetrieve(query: Query) {\n return new AsyncResult(this.create(query)).andThen((jobId) => this.retrieve(jobId)).promise;\n }\n\n observe(id: string) {\n return this.#jobObserverCache(id);\n }\n\n retrieve(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${id}`, { signal })\n .map((res) => res.json() as Promise<JobEntity>)\n .map((entity) => this._jobFromEntity(id, entity)).promise;\n }\n}\n"]}
1
+ {"version":3,"file":"JobsResource.js","sourceRoot":"","sources":["../../../src/oss/jobs/JobsResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAkB,MAAM,kCAAkC,CAAC;AACzF,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,OAAO,YAA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ED,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,EAAE,CAC1C,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,EAAE,KAAK,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 { SonarV3Config } from \"../../common/Config.ts\";\nimport { Job } from \"./Job.ts\";\nimport { Query } from \"../../common/Query.ts\";\nimport { AsyncResult } from \"ts-results-es\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { repeat, shareReplay, takeWhile, tap, timer } from \"rxjs\";\nimport { fromAbortable } from \"../../common/fromAbortable.ts\";\nimport { jobEntityToProperties, type JobEntity } from \"./utils/jobEntityToProperties.ts\";\nimport moize from \"moize\";\n\nexport class JobsResource {\n #config: SonarV3Config;\n\n #createJobObservable = (id: string) =>\n fromAbortable(({ signal }) => this.retrieve(id, { signal })).pipe(\n repeat({ delay: (count) => timer(jobPollingBackoff(count - 1)) }),\n takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true),\n );\n\n /**\n * Reuse the same observable every time the `observe` method is called.\n */\n #jobObserverCache = moize.default(\n (id: string) =>\n this.#createJobObservable(id).pipe(\n tap({\n finalize: () => {\n this.#jobObserverCache.remove([id]);\n },\n }),\n /**\n * Reuse the same polling for multiple subscribers, buffering only the latest result.\n * Make sure to unsubscribe from the source to stop polling when there are no subscribers (refCount: true)\n */\n shareReplay({\n bufferSize: 1,\n refCount: true,\n }),\n ),\n {\n /**\n * Evict cached observables after 60s. We need some way to prevent a memory\n * leak for long-running SDK processes, and a maxAge of 60 seconds should be\n * enough to handle multiple subscribers attached programmatically to a job.\n * If it's not, then the worst case is that we'd make additional API calls.\n */\n maxAge: 60_000,\n maxSize: Infinity,\n },\n );\n\n constructor(config: SonarV3Config) {\n this.#config = config;\n }\n\n _jobFromEntity(id: string, entity: JobEntity): Job {\n return new Job(jobEntityToProperties(id, entity), this.#config, this.observe.bind(this));\n }\n\n create(query: Query) {\n return this.#config\n .sonarV3Request(`sql`, {\n body: JSON.stringify({\n context: query.context,\n sql: query.sql,\n }),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((response) => response.json() as Promise<{ id: string }>)\n .map((response) => response.id).promise;\n }\n\n /**\n * A convenience method to combine job creation and retrieval\n */\n createAndRetrieve(query: Query) {\n return new AsyncResult(this.create(query)).andThen((jobId) => this.retrieve(jobId)).promise;\n }\n\n observe(id: string) {\n return this.#jobObserverCache(id);\n }\n\n retrieve(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${id}`, { signal })\n .map((res) => res.json() as Promise<JobEntity>)\n .map((entity) => this._jobFromEntity(id, entity)).promise;\n }\n}\n\nconst jobPollingBackoff = (count: number) =>\n Math.min(Math.ceil((Math.max(count, 0) ** 2 / 40 + 1) * 1000), 3_000);\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dremio/js-sdk",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "JavaScript library for the Dremio API",
5
5
  "keywords": [
6
6
  "dremio",