@dremio/js-sdk 0.30.0 → 0.31.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.
Files changed (63) hide show
  1. package/dist/cloud/projects/Project.d.ts +30 -24
  2. package/dist/cloud/projects/Project.js +25 -1
  3. package/dist/cloud/projects/Project.js.map +1 -1
  4. package/dist/cloud/projects/ProjectsResource.d.ts +3 -1
  5. package/dist/cloud/projects/ProjectsResource.js +10 -3
  6. package/dist/cloud/projects/ProjectsResource.js.map +1 -1
  7. package/dist/cloud/projects/projectPropertiesCodec.d.ts +122 -0
  8. package/dist/cloud/projects/projectPropertiesCodec.js +88 -0
  9. package/dist/cloud/projects/projectPropertiesCodec.js.map +1 -0
  10. package/dist/common/ConflictResolver.d.ts +1 -0
  11. package/dist/common/ConflictResolver.js +17 -0
  12. package/dist/common/ConflictResolver.js.map +1 -0
  13. package/dist/common/HttpError.js +3 -1
  14. package/dist/common/HttpError.js.map +1 -1
  15. package/dist/common/safeParseResultToResult.d.ts +3 -0
  16. package/dist/common/safeParseResultToResult.js +24 -0
  17. package/dist/common/safeParseResultToResult.js.map +1 -0
  18. package/dist/enterprise/roles/Role.d.ts +4 -4
  19. package/dist/enterprise/roles/Role.js +2 -2
  20. package/dist/enterprise/roles/Role.js.map +1 -1
  21. package/dist/enterprise/roles/RoleReference.d.ts +10 -0
  22. package/dist/enterprise/roles/RoleReference.js +22 -0
  23. package/dist/enterprise/roles/RoleReference.js.map +1 -0
  24. package/dist/enterprise/roles/RolesResource.d.ts +2 -2
  25. package/dist/enterprise/roles/RolesResource.js +3 -3
  26. package/dist/enterprise/roles/RolesResource.js.map +1 -1
  27. package/dist/enterprise/scripts/EnterpriseScript.d.ts +26 -20
  28. package/dist/enterprise/scripts/EnterpriseScript.js +47 -14
  29. package/dist/enterprise/scripts/EnterpriseScript.js.map +1 -1
  30. package/dist/enterprise/scripts/EnterpriseScriptsResource.d.ts +4 -2
  31. package/dist/enterprise/scripts/EnterpriseScriptsResource.js +4 -2
  32. package/dist/enterprise/scripts/EnterpriseScriptsResource.js.map +1 -1
  33. package/dist/enterprise/scripts/enterpriseScriptPropertiesCodec.d.ts +32 -0
  34. package/dist/enterprise/scripts/enterpriseScriptPropertiesCodec.js +51 -0
  35. package/dist/enterprise/scripts/enterpriseScriptPropertiesCodec.js.map +1 -0
  36. package/dist/enterprise/users/EnterpriseUser.d.ts +40 -0
  37. package/dist/enterprise/users/EnterpriseUser.js +23 -0
  38. package/dist/enterprise/users/EnterpriseUser.js.map +1 -1
  39. package/dist/enterprise/users/EnterpriseUsersResource.d.ts +6 -0
  40. package/dist/enterprise/users/EnterpriseUsersResource.js +28 -1
  41. package/dist/enterprise/users/EnterpriseUsersResource.js.map +1 -1
  42. package/dist/oss/jobs/JobsResource.d.ts +41 -3
  43. package/dist/oss/jobs/JobsResource.js +1 -1
  44. package/dist/oss/jobs/JobsResource.js.map +1 -1
  45. package/dist/oss/jobs/listJobs.d.ts +82 -6
  46. package/dist/oss/jobs/listJobs.js +3 -24
  47. package/dist/oss/jobs/listJobs.js.map +1 -1
  48. package/dist/oss/scripts/Script.d.ts +33 -41
  49. package/dist/oss/scripts/Script.js +35 -42
  50. package/dist/oss/scripts/Script.js.map +1 -1
  51. package/dist/oss/scripts/ScriptLike.d.ts +16 -0
  52. package/dist/oss/scripts/ScriptLike.js +17 -0
  53. package/dist/oss/scripts/ScriptLike.js.map +1 -0
  54. package/dist/oss/scripts/ScriptsResource.d.ts +4 -2
  55. package/dist/oss/scripts/ScriptsResource.js +4 -2
  56. package/dist/oss/scripts/ScriptsResource.js.map +1 -1
  57. package/dist/oss/scripts/scriptPropertiesCodec.d.ts +29 -0
  58. package/dist/oss/scripts/scriptPropertiesCodec.js +78 -0
  59. package/dist/oss/scripts/scriptPropertiesCodec.js.map +1 -0
  60. package/package.json +1 -1
  61. package/dist/cloud/projects/utils.d.ts +0 -2
  62. package/dist/cloud/projects/utils.js +0 -37
  63. package/dist/cloud/projects/utils.js.map +0 -1
@@ -13,12 +13,39 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { EnterpriseUser, enterpriseUserEntityToProperties, } from "./EnterpriseUser.js";
16
+ import { EnterpriseUser, enterpriseUserEntityToProperties, userCodec, } from "./EnterpriseUser.js";
17
+ import * as z from "zod/mini";
17
18
  export class EnterpriseUsersResource {
18
19
  #config;
19
20
  constructor(config) {
20
21
  this.#config = config;
21
22
  }
23
+ list() {
24
+ const getPage = ({ signal } = {}) => {
25
+ return this.#config
26
+ .v3Request(`user?${new URLSearchParams({ filter: "identityType==REGULAR_USER" })}`, {
27
+ signal,
28
+ })
29
+ .map((res) => res.json())
30
+ .map((response) => ({
31
+ data: response.data
32
+ .map((entity) => {
33
+ const decodeResult = z.safeDecode(userCodec, entity);
34
+ if (!decodeResult.success) {
35
+ return null;
36
+ }
37
+ return this._userFromEntity(entity);
38
+ })
39
+ .filter(Boolean),
40
+ }));
41
+ };
42
+ return {
43
+ async *data({ signal } = {}) {
44
+ yield* await getPage({ signal }).promise.then((result) => result.unwrap().data);
45
+ },
46
+ getPage,
47
+ };
48
+ }
22
49
  _userFromEntity(entity) {
23
50
  return new EnterpriseUser(enterpriseUserEntityToProperties(entity), this.#config);
24
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EnterpriseUsersResource.js","sourceRoot":"","sources":["../../../src/enterprise/users/EnterpriseUsersResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,cAAc,EACd,gCAAgC,GAEjC,MAAM,qBAAqB,CAAC;AAE7B,MAAM,OAAO,uBAAuB;IAClC,OAAO,CAA2B;IAElC,YAAY,MAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,eAAe,CAAC,MAA4B;QAC1C,OAAO,IAAI,cAAc,CAAC,gCAAgC,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACpF,CAAC;IAED,YAAY,CAAC,EAAU,EAAE,EAAE,MAAM,KAAkB,EAAE;QACnD,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;aACxC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAmC,CAAC;aACzD,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3D,CAAC;IAED,cAAc,CAAC,IAAY,EAAE,EAAE,MAAM,KAAkB,EAAE;QACvD,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,gBAAgB,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;aAClD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAmC,CAAC;aACzD,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3D,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, V3Config } from \"../../common/Config.ts\";\nimport {\n EnterpriseUser,\n enterpriseUserEntityToProperties,\n type EnterpriseUserEntity,\n} from \"./EnterpriseUser.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nexport class EnterpriseUsersResource {\n #config: SonarV3Config & V3Config;\n\n constructor(config: SonarV3Config & V3Config) {\n this.#config = config;\n }\n\n _userFromEntity(entity: EnterpriseUserEntity) {\n return new EnterpriseUser(enterpriseUserEntityToProperties(entity), this.#config);\n }\n\n retrieveById(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`user/${id}`, { signal })\n .map((res) => res.json() as Promise<EnterpriseUserEntity>)\n .map((entity) => this._userFromEntity(entity)).promise;\n }\n\n retrieveByName(name: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`user/by-name/${name}`, { signal })\n .map((res) => res.json() as Promise<EnterpriseUserEntity>)\n .map((entity) => this._userFromEntity(entity)).promise;\n }\n}\n"]}
1
+ {"version":3,"file":"EnterpriseUsersResource.js","sourceRoot":"","sources":["../../../src/enterprise/users/EnterpriseUsersResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EACL,cAAc,EACd,gCAAgC,EAChC,SAAS,GAEV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,MAAM,OAAO,uBAAuB;IAClC,OAAO,CAA2B;IAElC,YAAY,MAAgC;QAC1C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,IAAI;QACF,MAAM,OAAO,GAAG,CAAC,EAAE,MAAM,KAAkB,EAAE,EAAE,EAAE;YAC/C,OAAO,IAAI,CAAC,OAAO;iBAChB,SAAS,CAAC,QAAQ,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,4BAA4B,EAAE,CAAC,EAAE,EAAE;gBAClF,MAAM;aACP,CAAC;iBACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAoD,CAAC;iBAC1E,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAClB,IAAI,EAAE,QAAQ,CAAC,IAAI;qBAChB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;oBACd,MAAM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ClD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAmC,CAAC;aACzD,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3D,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, V3Config } from \"../../common/Config.ts\";\nimport {\n EnterpriseUser,\n enterpriseUserEntityToProperties,\n userCodec,\n type EnterpriseUserEntity,\n} from \"./EnterpriseUser.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport * as z from \"zod/mini\";\n\nexport class EnterpriseUsersResource {\n #config: SonarV3Config & V3Config;\n\n constructor(config: SonarV3Config & V3Config) {\n this.#config = config;\n }\n\n list() {\n const getPage = ({ signal }: SignalParam = {}) => {\n return this.#config\n .v3Request(`user?${new URLSearchParams({ filter: \"identityType==REGULAR_USER\" })}`, {\n signal,\n })\n .map((res) => res.json() as Promise<{ data: z.input<typeof userCodec>[] }>)\n .map((response) => ({\n data: response.data\n .map((entity) => {\n const decodeResult = z.safeDecode(userCodec, entity);\n if (!decodeResult.success) {\n return null;\n }\n\n return this._userFromEntity(entity as unknown as EnterpriseUserEntity);\n })\n .filter(Boolean) as EnterpriseUser[],\n }));\n };\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* await getPage({ signal }).promise.then((result) => result.unwrap().data);\n },\n getPage,\n };\n }\n\n _userFromEntity(entity: EnterpriseUserEntity) {\n return new EnterpriseUser(enterpriseUserEntityToProperties(entity), this.#config);\n }\n\n retrieveById(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`user/${id}`, { signal })\n .map((res) => res.json() as Promise<EnterpriseUserEntity>)\n .map((entity) => this._userFromEntity(entity)).promise;\n }\n\n retrieveByName(name: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`user/by-name/${name}`, { signal })\n .map((res) => res.json() as Promise<EnterpriseUserEntity>)\n .map((entity) => this._userFromEntity(entity)).promise;\n }\n}\n"]}
@@ -23,15 +23,53 @@ export declare class JobsResource {
23
23
  /**
24
24
  * @deprecated
25
25
  */
26
- _list(params: z.infer<typeof jobListParamsSchema>): {
27
- data({ signal }?: SignalParam): AsyncGenerator<{
26
+ _list(params?: z.infer<typeof jobListParamsSchema>): {
27
+ data({ signal }?: SignalParam): AsyncGenerator<import("ts-results-es").Result<{
28
28
  id: string;
29
29
  queryType: "UI_RUN" | "UI_PREVIEW" | "UI_INTERNAL_PREVIEW" | "UI_INTERNAL_RUN" | "UI_EXPORT" | "ODBC" | "JDBC" | "REST" | "ACCELERATOR_CREATE" | "ACCELERATOR_DROP" | "UNKNOWN" | "PREPARE_INTERNAL" | "ACCELERATOR_EXPLAIN" | "UI_INITIAL_PREVIEW" | "METADATA_REFRESH" | "FLIGHT" | "INTERNAL_ICEBERG_METADATA_DROP";
30
30
  state: string;
31
+ input: string;
32
+ output: string;
31
33
  description: string;
32
34
  user: string;
35
+ accelerated: boolean;
36
+ datasetVersion: string;
37
+ durationDetails: {
38
+ phaseDuration: string;
39
+ phaseName: "STARTING" | "RUNNING" | "PLANNING" | "PENDING" | "METADATA_RETRIEVAL" | "QUEUED" | "ENGINE_START" | "EXECUTION_PLANNING";
40
+ phaseStartTime: string;
41
+ }[];
42
+ isComplete: boolean;
43
+ outputLimited: boolean;
44
+ outputRecords: number;
45
+ plannerEstimatedCost: number;
46
+ queriedDatasets: {
47
+ datasetPathsList: string[];
48
+ datasetName?: string | undefined;
49
+ datasetPath?: string | undefined;
50
+ datasetType?: string | undefined;
51
+ versionContext?: string | undefined;
52
+ }[];
53
+ queryText: string;
54
+ requestType: string;
55
+ rowsScanned: number;
56
+ spilled: boolean;
57
+ starFlakeAccelerated: boolean;
58
+ totalAttempts: number;
59
+ waitInClient: number;
60
+ duration: import("temporal-polyfill").Temporal.Duration;
61
+ startTime: import("temporal-polyfill").Temporal.Instant;
62
+ enqueuedTime?: string | undefined;
63
+ wlmQueue?: string | undefined;
64
+ endTime?: import("temporal-polyfill").Temporal.Instant | undefined;
65
+ }, z.core.$ZodError<{
66
+ id: string;
67
+ queryType: "UI_RUN" | "UI_PREVIEW" | "UI_INTERNAL_PREVIEW" | "UI_INTERNAL_RUN" | "UI_EXPORT" | "ODBC" | "JDBC" | "REST" | "ACCELERATOR_CREATE" | "ACCELERATOR_DROP" | "UNKNOWN" | "PREPARE_INTERNAL" | "ACCELERATOR_EXPLAIN" | "UI_INITIAL_PREVIEW" | "METADATA_REFRESH" | "FLIGHT" | "INTERNAL_ICEBERG_METADATA_DROP";
68
+ state: string;
33
69
  input: string;
34
70
  output: string;
71
+ description: string;
72
+ user: string;
35
73
  accelerated: boolean;
36
74
  datasetVersion: string;
37
75
  durationDetails: {
@@ -62,7 +100,7 @@ export declare class JobsResource {
62
100
  enqueuedTime?: string | undefined;
63
101
  wlmQueue?: string | undefined;
64
102
  endTime?: import("temporal-polyfill").Temporal.Instant | undefined;
65
- }, void, unknown>;
103
+ }>>, void, unknown>;
66
104
  };
67
105
  observe(id: string): import("rxjs").Observable<import("ts-results-es").Result<Job, import("../index.ts").HttpError>>;
68
106
  retrieve(id: string, { signal }?: SignalParam): Promise<import("ts-results-es").Result<Job, import("../index.ts").HttpError>>;
@@ -102,7 +102,7 @@ export class JobsResource {
102
102
  /**
103
103
  * @deprecated
104
104
  */
105
- _list(params) {
105
+ _list(params = {}) {
106
106
  const { getNextPage, listJobs } = createListJobs(this.#config);
107
107
  return {
108
108
  async *data({ signal } = {}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AO,aAAa,EAAE,CAAC;oBACrB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CACpF,MAAM,CAAC,MAAM,EAAE,CAChB,CAAC;oBACF,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC;oBAC9B,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACvB,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,EAAE,MAAM,KAAkB,EAAE;QAC/C,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;aACvC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAwB,CAAC;aAC9C,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC9D,CAAC;CACF;AAED,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 { SonarV2Config, 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\";\nimport { createListJobs, type jobListParamsSchema } from \"./listJobs.ts\";\nimport * as z from \"zod/mini\";\n\nexport class JobsResource {\n #config: SonarV2Config & 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: SonarV2Config & 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 * Runs multiple queries sequentially, waiting for each one to finish successfully\n * before starting the next. If a query fails, any subsequent queries will not be\n * run.\n */\n async *createSequential(queries: Query[]) {\n for (let i = 0; i < queries.length; i++) {\n const result = await this.createAndRetrieve(queries.at(i)!);\n yield result;\n\n /**\n * Stop processing additional queries if the job prior to it failed\n */\n if (\n // If it's the last query, return immediately rather than waiting for it to finish\n i !== queries.length - 1 &&\n (result.isErr() || (await result.value.retrieveSettled()).state !== \"COMPLETED\")\n ) {\n break;\n }\n }\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 /**\n * @deprecated\n */\n _list(params: z.infer<typeof jobListParamsSchema>) {\n const { getNextPage, listJobs } = createListJobs(this.#config);\n return {\n async *data({ signal }: SignalParam = {}) {\n const firstPageResult = await listJobs(params).promise;\n\n if (firstPageResult.isErr()) {\n throw firstPageResult.error;\n }\n\n yield* firstPageResult.value.data;\n let nextPageToken = firstPageResult.value.next;\n\n while (nextPageToken) {\n const nextPage = await getNextPage(nextPageToken, { signal }).promise.then((result) =>\n result.unwrap(),\n );\n nextPageToken = nextPage.next;\n yield* nextPage.data;\n }\n },\n };\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((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AAK,CAAC,IAAI,CAAC;gBAE/C,OAAO,aAAa,EAAE,CAAC;oBACrB,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CACpF,MAAM,CAAC,MAAM,EAAE,CAChB,CAAC;oBACF,aAAa,GAAG,QAAQ,CAAC,IAAI,CAAC;oBAC9B,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;gBACvB,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,EAAE,MAAM,KAAkB,EAAE;QAC/C,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;aACvC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAwB,CAAC;aAC9C,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC9D,CAAC;CACF;AAED,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 { SonarV2Config, 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\";\nimport { createListJobs, type jobListParamsSchema } from \"./listJobs.ts\";\nimport * as z from \"zod/mini\";\n\nexport class JobsResource {\n #config: SonarV2Config & 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: SonarV2Config & 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 * Runs multiple queries sequentially, waiting for each one to finish successfully\n * before starting the next. If a query fails, any subsequent queries will not be\n * run.\n */\n async *createSequential(queries: Query[]) {\n for (let i = 0; i < queries.length; i++) {\n const result = await this.createAndRetrieve(queries.at(i)!);\n yield result;\n\n /**\n * Stop processing additional queries if the job prior to it failed\n */\n if (\n // If it's the last query, return immediately rather than waiting for it to finish\n i !== queries.length - 1 &&\n (result.isErr() || (await result.value.retrieveSettled()).state !== \"COMPLETED\")\n ) {\n break;\n }\n }\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 /**\n * @deprecated\n */\n _list(params: z.infer<typeof jobListParamsSchema> = {}) {\n const { getNextPage, listJobs } = createListJobs(this.#config);\n return {\n async *data({ signal }: SignalParam = {}) {\n const firstPageResult = await listJobs(params).promise;\n\n if (firstPageResult.isErr()) {\n throw firstPageResult.error;\n }\n\n yield* firstPageResult.value.data;\n let nextPageToken = firstPageResult.value.next;\n\n while (nextPageToken) {\n const nextPage = await getNextPage(nextPageToken, { signal }).promise.then((result) =>\n result.unwrap(),\n );\n nextPageToken = nextPage.next;\n yield* nextPage.data;\n }\n },\n };\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"]}
@@ -196,10 +196,10 @@ export declare const jobDetailsCodec: z.ZodMiniCodec<z.ZodMiniObject<{
196
196
  INTERNAL_ICEBERG_METADATA_DROP: "INTERNAL_ICEBERG_METADATA_DROP";
197
197
  }>;
198
198
  state: z.ZodMiniString<string>;
199
- description: z.ZodMiniString<string>;
200
- user: z.ZodMiniString<string>;
201
199
  input: z.ZodMiniString<string>;
202
200
  output: z.ZodMiniString<string>;
201
+ description: z.ZodMiniString<string>;
202
+ user: z.ZodMiniString<string>;
203
203
  accelerated: z.ZodMiniBoolean<boolean>;
204
204
  datasetVersion: z.ZodMiniString<string>;
205
205
  durationDetails: z.ZodMiniArray<z.ZodMiniObject<{
@@ -242,14 +242,52 @@ export declare const jobDetailsCodec: z.ZodMiniCodec<z.ZodMiniObject<{
242
242
  }, z.core.$strip>>;
243
243
  export declare function createListJobs(config: SonarV2Config): {
244
244
  getNextPage: (nextPage: string, { signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
245
- data: {
245
+ data: import("ts-results-es").Result<{
246
246
  id: string;
247
247
  queryType: "UI_RUN" | "UI_PREVIEW" | "UI_INTERNAL_PREVIEW" | "UI_INTERNAL_RUN" | "UI_EXPORT" | "ODBC" | "JDBC" | "REST" | "ACCELERATOR_CREATE" | "ACCELERATOR_DROP" | "UNKNOWN" | "PREPARE_INTERNAL" | "ACCELERATOR_EXPLAIN" | "UI_INITIAL_PREVIEW" | "METADATA_REFRESH" | "FLIGHT" | "INTERNAL_ICEBERG_METADATA_DROP";
248
248
  state: string;
249
+ input: string;
250
+ output: string;
249
251
  description: string;
250
252
  user: string;
253
+ accelerated: boolean;
254
+ datasetVersion: string;
255
+ durationDetails: {
256
+ phaseDuration: string;
257
+ phaseName: "STARTING" | "RUNNING" | "PLANNING" | "PENDING" | "METADATA_RETRIEVAL" | "QUEUED" | "ENGINE_START" | "EXECUTION_PLANNING";
258
+ phaseStartTime: string;
259
+ }[];
260
+ isComplete: boolean;
261
+ outputLimited: boolean;
262
+ outputRecords: number;
263
+ plannerEstimatedCost: number;
264
+ queriedDatasets: {
265
+ datasetPathsList: string[];
266
+ datasetName?: string | undefined;
267
+ datasetPath?: string | undefined;
268
+ datasetType?: string | undefined;
269
+ versionContext?: string | undefined;
270
+ }[];
271
+ queryText: string;
272
+ requestType: string;
273
+ rowsScanned: number;
274
+ spilled: boolean;
275
+ starFlakeAccelerated: boolean;
276
+ totalAttempts: number;
277
+ waitInClient: number;
278
+ duration: Temporal.Duration;
279
+ startTime: Temporal.Instant;
280
+ enqueuedTime?: string | undefined;
281
+ wlmQueue?: string | undefined;
282
+ endTime?: Temporal.Instant | undefined;
283
+ }, z.core.$ZodError<{
284
+ id: string;
285
+ queryType: "UI_RUN" | "UI_PREVIEW" | "UI_INTERNAL_PREVIEW" | "UI_INTERNAL_RUN" | "UI_EXPORT" | "ODBC" | "JDBC" | "REST" | "ACCELERATOR_CREATE" | "ACCELERATOR_DROP" | "UNKNOWN" | "PREPARE_INTERNAL" | "ACCELERATOR_EXPLAIN" | "UI_INITIAL_PREVIEW" | "METADATA_REFRESH" | "FLIGHT" | "INTERNAL_ICEBERG_METADATA_DROP";
286
+ state: string;
251
287
  input: string;
252
288
  output: string;
289
+ description: string;
290
+ user: string;
253
291
  accelerated: boolean;
254
292
  datasetVersion: string;
255
293
  durationDetails: {
@@ -280,18 +318,56 @@ export declare function createListJobs(config: SonarV2Config): {
280
318
  enqueuedTime?: string | undefined;
281
319
  wlmQueue?: string | undefined;
282
320
  endTime?: Temporal.Instant | undefined;
283
- }[];
321
+ }>>[];
284
322
  next: string | undefined;
285
323
  }, import("../index.ts").HttpError>;
286
324
  listJobs: (params: z.infer<typeof jobListParamsSchema>, { signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
287
- data: {
325
+ data: import("ts-results-es").Result<{
288
326
  id: string;
289
327
  queryType: "UI_RUN" | "UI_PREVIEW" | "UI_INTERNAL_PREVIEW" | "UI_INTERNAL_RUN" | "UI_EXPORT" | "ODBC" | "JDBC" | "REST" | "ACCELERATOR_CREATE" | "ACCELERATOR_DROP" | "UNKNOWN" | "PREPARE_INTERNAL" | "ACCELERATOR_EXPLAIN" | "UI_INITIAL_PREVIEW" | "METADATA_REFRESH" | "FLIGHT" | "INTERNAL_ICEBERG_METADATA_DROP";
290
328
  state: string;
329
+ input: string;
330
+ output: string;
291
331
  description: string;
292
332
  user: string;
333
+ accelerated: boolean;
334
+ datasetVersion: string;
335
+ durationDetails: {
336
+ phaseDuration: string;
337
+ phaseName: "STARTING" | "RUNNING" | "PLANNING" | "PENDING" | "METADATA_RETRIEVAL" | "QUEUED" | "ENGINE_START" | "EXECUTION_PLANNING";
338
+ phaseStartTime: string;
339
+ }[];
340
+ isComplete: boolean;
341
+ outputLimited: boolean;
342
+ outputRecords: number;
343
+ plannerEstimatedCost: number;
344
+ queriedDatasets: {
345
+ datasetPathsList: string[];
346
+ datasetName?: string | undefined;
347
+ datasetPath?: string | undefined;
348
+ datasetType?: string | undefined;
349
+ versionContext?: string | undefined;
350
+ }[];
351
+ queryText: string;
352
+ requestType: string;
353
+ rowsScanned: number;
354
+ spilled: boolean;
355
+ starFlakeAccelerated: boolean;
356
+ totalAttempts: number;
357
+ waitInClient: number;
358
+ duration: Temporal.Duration;
359
+ startTime: Temporal.Instant;
360
+ enqueuedTime?: string | undefined;
361
+ wlmQueue?: string | undefined;
362
+ endTime?: Temporal.Instant | undefined;
363
+ }, z.core.$ZodError<{
364
+ id: string;
365
+ queryType: "UI_RUN" | "UI_PREVIEW" | "UI_INTERNAL_PREVIEW" | "UI_INTERNAL_RUN" | "UI_EXPORT" | "ODBC" | "JDBC" | "REST" | "ACCELERATOR_CREATE" | "ACCELERATOR_DROP" | "UNKNOWN" | "PREPARE_INTERNAL" | "ACCELERATOR_EXPLAIN" | "UI_INITIAL_PREVIEW" | "METADATA_REFRESH" | "FLIGHT" | "INTERNAL_ICEBERG_METADATA_DROP";
366
+ state: string;
293
367
  input: string;
294
368
  output: string;
369
+ description: string;
370
+ user: string;
295
371
  accelerated: boolean;
296
372
  datasetVersion: string;
297
373
  durationDetails: {
@@ -322,7 +398,7 @@ export declare function createListJobs(config: SonarV2Config): {
322
398
  enqueuedTime?: string | undefined;
323
399
  wlmQueue?: string | undefined;
324
400
  endTime?: Temporal.Instant | undefined;
325
- }[];
401
+ }>>[];
326
402
  next: string | undefined;
327
403
  }, import("../index.ts").HttpError>;
328
404
  };
@@ -16,6 +16,7 @@
16
16
  import * as z from "zod/mini";
17
17
  import { Temporal } from "temporal-polyfill";
18
18
  import parseMilliseconds from "parse-ms";
19
+ import { safeParseResultToResult } from "../../common/safeParseResultToResult.js";
19
20
  export const jobListParamsSchema = z.partial(z.strictObject({
20
21
  contains: z.string().check(z.trim(), z.minLength(1)),
21
22
  dateRange: z.strictObject({
@@ -177,18 +178,7 @@ export function createListJobs(config) {
177
178
  })
178
179
  .map((res) => res.json())
179
180
  .map((response) => ({
180
- data: response.jobs.reduce((accum, curr) => {
181
- const parseResult = z.safeDecode(jobDetailsCodec, curr);
182
- if (!parseResult.success) {
183
- // config.logger?.error(
184
- // new Error(`Failed to parse job details`, { cause: parseResult.error }),
185
- // );
186
- }
187
- else {
188
- accum.push(parseResult.data);
189
- }
190
- return accum;
191
- }, []),
181
+ data: response.jobs.map((entity) => safeParseResultToResult(z.safeDecode(jobDetailsCodec, entity))),
192
182
  next: response.next,
193
183
  }));
194
184
  },
@@ -203,18 +193,7 @@ export function createListJobs(config) {
203
193
  })
204
194
  .map((res) => res.json())
205
195
  .map((response) => ({
206
- data: response.jobs.reduce((accum, curr) => {
207
- const parseResult = z.safeDecode(jobDetailsCodec, curr);
208
- if (!parseResult.success) {
209
- // config.logger?.error(
210
- // new Error(`Failed to parse job details`, { cause: parseResult.error }),
211
- // );
212
- }
213
- else {
214
- accum.push(parseResult.data);
215
- }
216
- return accum;
217
- }, []),
196
+ data: response.jobs.map((entity) => safeParseResultToResult(z.safeDecode(jobDetailsCodec, entity))),
218
197
  next: response.next,
219
198
  }));
220
199
  },
@@ -1 +1 @@
1
- {"version":3,"file":"listJobs.js","sourceRoot":"","sources":["../../../src/oss/jobs/listJobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,iBAAiB,MAAM,UAAU,CAAC;AAEzC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,CAAC;IACb,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACpD,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC;QACxB,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC/C,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC;KACtC,CAAC;IACF,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;IACpF,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC;QACnB,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAClC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;KACjD,CAAC;IACF,MAAM,EAAE,CAAC,CAAC,GAAG,CACX,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,QAAQ,EAA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AAI,CAAC,CAAC;oBAC/B,CAAC;oBACD,OAAO,KAAK,CAAC;gBACf,CAAC,EACD,EAAwC,CACzC;gBACD,IAAI,EAAE,QAAQ,CAAC,IAAI;aACpB,CAAC,CAAC,CAAC;QACR,CAAC;KACF,CAAC;AACJ,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 * as z from \"zod/mini\";\nimport type { SonarV2Config } from \"../../common/Config.ts\";\nimport { Temporal } from \"temporal-polyfill\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport parseMilliseconds from \"parse-ms\";\n\nexport const jobListParamsSchema = z.partial(\n z.strictObject({\n contains: z.string().check(z.trim(), z.minLength(1)),\n dateRange: z.strictObject({\n end: z.optional(z.instanceof(Temporal.Instant)),\n start: z.instanceof(Temporal.Instant),\n }),\n queryType: z.set(z.enum([\"ACCELERATION\", \"DOWNLOAD\", \"EXTERNAL\", \"INTERNAL\", \"UI\"])),\n sort: z.strictObject({\n direction: z.enum([\"ASC\", \"DESC\"]),\n field: z.enum([\"duration\", \"startTime\", \"user\"]),\n }),\n status: z.set(\n z.enum([\"SETUP\", \"QUEUED\", \"ENGINE_START\", \"RUNNING\", \"COMPLETED\", \"CANCELED\", \"FAILED\"]),\n ),\n user: z.set(z.string().check(z.trim(), z.minLength(1))),\n }),\n);\n\nexport function mapParams(params: z.infer<typeof jobListParamsSchema>) {\n const filter = [] as string[];\n\n if (params.contains) {\n filter.push(`*=contains=${JSON.stringify(params.contains)}`);\n }\n\n if (params.queryType?.size) {\n filter.push(\n `(${Array.from(params.queryType)\n .map((v) => `qt==\"${v}\"`)\n .join(\",\")})`,\n );\n }\n\n if (params.status?.size) {\n filter.push(\n `(${Array.from(params.status)\n .map((v) => `jst==\"${v}\"`)\n .join(\",\")})`,\n );\n }\n\n if (params.user?.size) {\n filter.push(\n `(${Array.from(params.user)\n .map((v) => `usr==\"${v}\"`)\n .join(\",\")})`,\n );\n }\n\n if (params.dateRange?.start) {\n const { end, start } = params.dateRange;\n filter.push(\n `(${[\n start && `st=gt=${start.epochMilliseconds}`,\n end && `st=lt=${end.epochMilliseconds}`,\n ].join(\";\")})`,\n );\n }\n\n return {\n detailLevel: \"1\",\n filter,\n order: params.sort\n ? params.sort.direction === \"DESC\"\n ? \"DESCENDING\"\n : \"ASCENDING\"\n : undefined,\n sort: params.sort ? fieldToV2Mapping[params.sort.field] : undefined,\n } as const;\n}\n\nconst fieldToV2Mapping = {\n duration: \"dur\",\n startTime: \"st\",\n user: \"usr\",\n} as const satisfies Record<\n NonNullable<z.infer<typeof jobListParamsSchema>[\"sort\"]>[\"field\"],\n unknown\n>;\n\nexport const jobDetailsInSchema = z.object({\n accelerated: z.boolean(),\n datasetVersion: z.string(),\n description: z.string(),\n duration: z.number(),\n durationDetails: z.array(\n z.object({\n phaseDuration: z.string(),\n phaseName: z.enum([\n \"EXECUTION_PLANNING\",\n \"METADATA_RETRIEVAL\",\n \"PENDING\",\n \"PLANNING\",\n \"QUEUED\",\n \"RUNNING\",\n \"STARTING\",\n \"ENGINE_START\",\n ]),\n phaseStartTime: z.string(),\n }),\n ),\n endTime: z.optional(z.number()),\n enqueuedTime: z.optional(z.string()),\n id: z.string(),\n input: z.string(),\n isComplete: z.boolean(),\n output: z.string(),\n outputLimited: z.boolean(),\n outputRecords: z.number(),\n plannerEstimatedCost: z.number(),\n queriedDatasets: z.array(\n z.object({\n datasetName: z.optional(z.string()),\n datasetPath: z.optional(z.string()),\n datasetPathsList: z.array(z.string()),\n datasetType: z.optional(z.string()),\n versionContext: z.optional(z.string()),\n }),\n ),\n queryText: z.string(),\n queryType: z.enum([\n \"UI_RUN\",\n \"UI_PREVIEW\",\n \"UI_INTERNAL_PREVIEW\",\n \"UI_INTERNAL_RUN\",\n \"UI_EXPORT\",\n \"ODBC\",\n \"JDBC\",\n \"REST\",\n \"ACCELERATOR_CREATE\",\n \"ACCELERATOR_DROP\",\n \"UNKNOWN\",\n \"PREPARE_INTERNAL\",\n \"ACCELERATOR_EXPLAIN\",\n \"UI_INITIAL_PREVIEW\",\n \"METADATA_REFRESH\",\n \"FLIGHT\",\n \"INTERNAL_ICEBERG_METADATA_DROP\",\n ]),\n requestType: z.string(),\n rowsScanned: z.number(),\n spilled: z.boolean(),\n starFlakeAccelerated: z.boolean(),\n startTime: z.number(),\n state: z.string(),\n totalAttempts: z.number(),\n user: z.string(),\n waitInClient: z.number(),\n wlmQueue: z.optional(z.string()),\n});\n\nexport const jobDetailsCodec = z.codec(\n jobDetailsInSchema,\n z.extend(\n z.omit(jobDetailsInSchema, {\n duration: true,\n endTime: true,\n startTime: true,\n }),\n {\n duration: z.instanceof(Temporal.Duration),\n endTime: z.optional(z.instanceof(Temporal.Instant)),\n startTime: z.instanceof(Temporal.Instant),\n },\n ),\n {\n decode(v) {\n return {\n ...v,\n duration: Temporal.Duration.from(parseMilliseconds(v.duration)),\n endTime: v.endTime ? Temporal.Instant.fromEpochMilliseconds(v.endTime) : undefined,\n startTime: Temporal.Instant.fromEpochMilliseconds(v.startTime),\n };\n },\n encode(v) {\n return {\n ...v,\n duration: 0, // Skip installing something like to-milliseconds to achieve this\n endTime: v.endTime ? v.endTime.epochMilliseconds : undefined,\n startTime: v.startTime.epochMilliseconds,\n };\n },\n },\n);\n\nexport function createListJobs(config: SonarV2Config) {\n return {\n getNextPage: (nextPage: string, { signal }: SignalParam = {}) => {\n return config\n .sonarV2Request(`jobs-listing/v1.0/${new URL(nextPage, \"https://dremio\").search}`, {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map(\n (res) =>\n res.json() as Promise<{ jobs: z.input<typeof jobDetailsCodec>[]; next?: string }>,\n )\n .map((response) => ({\n data: response.jobs.reduce(\n (accum, curr) => {\n const parseResult = z.safeDecode(jobDetailsCodec, curr);\n if (!parseResult.success) {\n // config.logger?.error(\n // new Error(`Failed to parse job details`, { cause: parseResult.error }),\n // );\n } else {\n accum.push(parseResult.data);\n }\n return accum;\n },\n [] as z.output<typeof jobDetailsCodec>[],\n ),\n next: response.next,\n }));\n },\n listJobs: (params: z.infer<typeof jobListParamsSchema>, { signal }: SignalParam = {}) => {\n const searchParams = new URLSearchParams(\n Object.entries(mapParams(z.parse(jobListParamsSchema, params))).filter(\n (entry) => !!entry[1],\n ) as string[][],\n );\n return config\n .sonarV2Request(`jobs-listing/v1.0/?${searchParams.toString()}`, {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map(\n (res) =>\n res.json() as Promise<{ jobs: z.input<typeof jobDetailsCodec>[]; next?: string }>,\n )\n .map((response) => ({\n data: response.jobs.reduce(\n (accum, curr) => {\n const parseResult = z.safeDecode(jobDetailsCodec, curr);\n if (!parseResult.success) {\n // config.logger?.error(\n // new Error(`Failed to parse job details`, { cause: parseResult.error }),\n // );\n } else {\n accum.push(parseResult.data);\n }\n return accum;\n },\n [] as z.output<typeof jobDetailsCodec>[],\n ),\n next: response.next,\n }));\n },\n };\n}\n"]}
1
+ {"version":3,"file":"listJobs.js","sourceRoot":"","sources":["../../../src/oss/jobs/listJobs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,CAAC,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,iBAAiB,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAElF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,YAAY,CAAC;IACb,QAAQ,EA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/D,OAAO,EAAE;oBACP,MAAM,EAAE,kBAAkB;iBAC3B;gBACD,MAAM;aACP,CAAC;iBACD,GAAG,CACF,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,CAAC,IAAI,EAAyE,CACpF;iBACA,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAClB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACjC,uBAAuB,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAC/D;gBACD,IAAI,EAAE,QAAQ,CAAC,IAAI;aACpB,CAAC,CAAC,CAAC;QACR,CAAC;KACF,CAAC;AACJ,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 * as z from \"zod/mini\";\nimport type { SonarV2Config } from \"../../common/Config.ts\";\nimport { Temporal } from \"temporal-polyfill\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport parseMilliseconds from \"parse-ms\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\n\nexport const jobListParamsSchema = z.partial(\n z.strictObject({\n contains: z.string().check(z.trim(), z.minLength(1)),\n dateRange: z.strictObject({\n end: z.optional(z.instanceof(Temporal.Instant)),\n start: z.instanceof(Temporal.Instant),\n }),\n queryType: z.set(z.enum([\"ACCELERATION\", \"DOWNLOAD\", \"EXTERNAL\", \"INTERNAL\", \"UI\"])),\n sort: z.strictObject({\n direction: z.enum([\"ASC\", \"DESC\"]),\n field: z.enum([\"duration\", \"startTime\", \"user\"]),\n }),\n status: z.set(\n z.enum([\"SETUP\", \"QUEUED\", \"ENGINE_START\", \"RUNNING\", \"COMPLETED\", \"CANCELED\", \"FAILED\"]),\n ),\n user: z.set(z.string().check(z.trim(), z.minLength(1))),\n }),\n);\n\nexport function mapParams(params: z.infer<typeof jobListParamsSchema>) {\n const filter = [] as string[];\n\n if (params.contains) {\n filter.push(`*=contains=${JSON.stringify(params.contains)}`);\n }\n\n if (params.queryType?.size) {\n filter.push(\n `(${Array.from(params.queryType)\n .map((v) => `qt==\"${v}\"`)\n .join(\",\")})`,\n );\n }\n\n if (params.status?.size) {\n filter.push(\n `(${Array.from(params.status)\n .map((v) => `jst==\"${v}\"`)\n .join(\",\")})`,\n );\n }\n\n if (params.user?.size) {\n filter.push(\n `(${Array.from(params.user)\n .map((v) => `usr==\"${v}\"`)\n .join(\",\")})`,\n );\n }\n\n if (params.dateRange?.start) {\n const { end, start } = params.dateRange;\n filter.push(\n `(${[\n start && `st=gt=${start.epochMilliseconds}`,\n end && `st=lt=${end.epochMilliseconds}`,\n ].join(\";\")})`,\n );\n }\n\n return {\n detailLevel: \"1\",\n filter,\n order: params.sort\n ? params.sort.direction === \"DESC\"\n ? \"DESCENDING\"\n : \"ASCENDING\"\n : undefined,\n sort: params.sort ? fieldToV2Mapping[params.sort.field] : undefined,\n } as const;\n}\n\nconst fieldToV2Mapping = {\n duration: \"dur\",\n startTime: \"st\",\n user: \"usr\",\n} as const satisfies Record<\n NonNullable<z.infer<typeof jobListParamsSchema>[\"sort\"]>[\"field\"],\n unknown\n>;\n\nexport const jobDetailsInSchema = z.object({\n accelerated: z.boolean(),\n datasetVersion: z.string(),\n description: z.string(),\n duration: z.number(),\n durationDetails: z.array(\n z.object({\n phaseDuration: z.string(),\n phaseName: z.enum([\n \"EXECUTION_PLANNING\",\n \"METADATA_RETRIEVAL\",\n \"PENDING\",\n \"PLANNING\",\n \"QUEUED\",\n \"RUNNING\",\n \"STARTING\",\n \"ENGINE_START\",\n ]),\n phaseStartTime: z.string(),\n }),\n ),\n endTime: z.optional(z.number()),\n enqueuedTime: z.optional(z.string()),\n id: z.string(),\n input: z.string(),\n isComplete: z.boolean(),\n output: z.string(),\n outputLimited: z.boolean(),\n outputRecords: z.number(),\n plannerEstimatedCost: z.number(),\n queriedDatasets: z.array(\n z.object({\n datasetName: z.optional(z.string()),\n datasetPath: z.optional(z.string()),\n datasetPathsList: z.array(z.string()),\n datasetType: z.optional(z.string()),\n versionContext: z.optional(z.string()),\n }),\n ),\n queryText: z.string(),\n queryType: z.enum([\n \"UI_RUN\",\n \"UI_PREVIEW\",\n \"UI_INTERNAL_PREVIEW\",\n \"UI_INTERNAL_RUN\",\n \"UI_EXPORT\",\n \"ODBC\",\n \"JDBC\",\n \"REST\",\n \"ACCELERATOR_CREATE\",\n \"ACCELERATOR_DROP\",\n \"UNKNOWN\",\n \"PREPARE_INTERNAL\",\n \"ACCELERATOR_EXPLAIN\",\n \"UI_INITIAL_PREVIEW\",\n \"METADATA_REFRESH\",\n \"FLIGHT\",\n \"INTERNAL_ICEBERG_METADATA_DROP\",\n ]),\n requestType: z.string(),\n rowsScanned: z.number(),\n spilled: z.boolean(),\n starFlakeAccelerated: z.boolean(),\n startTime: z.number(),\n state: z.string(),\n totalAttempts: z.number(),\n user: z.string(),\n waitInClient: z.number(),\n wlmQueue: z.optional(z.string()),\n});\n\nexport const jobDetailsCodec = z.codec(\n jobDetailsInSchema,\n z.extend(\n z.omit(jobDetailsInSchema, {\n duration: true,\n endTime: true,\n startTime: true,\n }),\n {\n duration: z.instanceof(Temporal.Duration),\n endTime: z.optional(z.instanceof(Temporal.Instant)),\n startTime: z.instanceof(Temporal.Instant),\n },\n ),\n {\n decode(v) {\n return {\n ...v,\n duration: Temporal.Duration.from(parseMilliseconds(v.duration)),\n endTime: v.endTime ? Temporal.Instant.fromEpochMilliseconds(v.endTime) : undefined,\n startTime: Temporal.Instant.fromEpochMilliseconds(v.startTime),\n };\n },\n encode(v) {\n return {\n ...v,\n duration: 0, // Skip installing something like to-milliseconds to achieve this\n endTime: v.endTime ? v.endTime.epochMilliseconds : undefined,\n startTime: v.startTime.epochMilliseconds,\n };\n },\n },\n);\n\nexport function createListJobs(config: SonarV2Config) {\n return {\n getNextPage: (nextPage: string, { signal }: SignalParam = {}) => {\n return config\n .sonarV2Request(`jobs-listing/v1.0/${new URL(nextPage, \"https://dremio\").search}`, {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map(\n (res) =>\n res.json() as Promise<{ jobs: z.input<typeof jobDetailsCodec>[]; next?: string }>,\n )\n .map((response) => ({\n data: response.jobs.map((entity) =>\n safeParseResultToResult(z.safeDecode(jobDetailsCodec, entity)),\n ),\n next: response.next,\n }));\n },\n listJobs: (params: z.infer<typeof jobListParamsSchema>, { signal }: SignalParam = {}) => {\n const searchParams = new URLSearchParams(\n Object.entries(mapParams(z.parse(jobListParamsSchema, params))).filter(\n (entry) => !!entry[1],\n ) as string[][],\n );\n return config\n .sonarV2Request(`jobs-listing/v1.0/?${searchParams.toString()}`, {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map(\n (res) =>\n res.json() as Promise<{ jobs: z.input<typeof jobDetailsCodec>[]; next?: string }>,\n )\n .map((response) => ({\n data: response.jobs.map((entity) =>\n safeParseResultToResult(z.safeDecode(jobDetailsCodec, entity)),\n ),\n next: response.next,\n }));\n },\n };\n}\n"]}
@@ -1,46 +1,38 @@
1
1
  import { Query } from "../../common/Query.ts";
2
2
  import type { SonarV3Config } from "../../common/Config.ts";
3
3
  import { Temporal } from "temporal-polyfill";
4
- export declare class Script {
4
+ import type { ScriptLike } from "./ScriptLike.ts";
5
+ import * as z from "zod/mini";
6
+ import { scriptPropertiesCodec, scriptUpdateCodec } from "./scriptPropertiesCodec.js";
7
+ import { HttpError } from "../../common/HttpError.js";
8
+ import type { Err } from "ts-results-es";
9
+ export declare class Script implements ScriptLike {
5
10
  #private;
6
- readonly createdAt: ScriptProperties["createdAt"];
7
- readonly createdBy: ScriptProperties["createdBy"];
8
- readonly id: ScriptProperties["id"];
9
- readonly modifiedAt: ScriptProperties["modifiedAt"];
10
- readonly modifiedBy: ScriptProperties["modifiedBy"];
11
- readonly name: ScriptProperties["name"];
12
- readonly query: ScriptProperties["query"];
13
- constructor(properties: ScriptProperties, config: SonarV3Config);
14
- delete(): Promise<import("ts-results-es").Result<void, import("../index.ts").HttpError>>;
15
- save(properties: ScriptPatchableProperties): Promise<import("ts-results-es").Result<Script, import("../../common/Problem.ts").ValidationProblem | import("../index.ts").HttpError>>;
11
+ readonly createdAt: Temporal.Instant;
12
+ readonly createdBy: string;
13
+ readonly id: string;
14
+ readonly modifiedAt: Temporal.Instant;
15
+ readonly modifiedBy: string;
16
+ readonly name: string;
17
+ readonly query: Query;
18
+ constructor(properties: z.output<typeof scriptPropertiesCodec>, config: SonarV3Config);
19
+ delete(): Promise<import("ts-results-es").Result<void, HttpError>>;
20
+ save(properties: z.output<typeof scriptUpdateCodec>): Promise<Err<z.core.$ZodError<z.ZodMiniCodec<z.ZodMiniObject<{
21
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
22
+ content: z.ZodMiniOptional<z.ZodMiniString<string>>;
23
+ context: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
24
+ }, z.core.$strip>, z.ZodMiniObject<{
25
+ name: z.ZodMiniOptional<z.ZodMiniString<string>>;
26
+ query: z.ZodMiniOptional<z.ZodMiniCustom<Query, Query>>;
27
+ }, z.core.$strip>>>>> | Promise<import("ts-results-es").Result<Script, import("../../common/Problem.ts").ValidationProblem | HttpError>>;
28
+ static schema: z.ZodMiniObject<{
29
+ name: z.ZodMiniString<string>;
30
+ id: z.ZodMiniString<string>;
31
+ createdBy: z.ZodMiniString<string>;
32
+ modifiedBy: z.ZodMiniString<string>;
33
+ createdAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
34
+ modifiedAt: z.ZodMiniCustom<Temporal.Instant, Temporal.Instant>;
35
+ query: z.ZodMiniCustom<Query, Query>;
36
+ }, z.core.$strip>;
16
37
  }
17
- export declare const scriptEntityToProperties: (entity: ScriptEntity) => {
18
- createdAt: Temporal.Instant;
19
- createdBy: string;
20
- id: string;
21
- modifiedAt: Temporal.Instant;
22
- modifiedBy: string;
23
- name: string;
24
- query: Query;
25
- };
26
- export type ScriptEntity = {
27
- content: string;
28
- context: string[];
29
- createdAt: string;
30
- createdBy: string;
31
- id: string;
32
- modifiedAt: string;
33
- modifiedBy: string;
34
- name: string;
35
- };
36
- export type ScriptPatchableProperties = {
37
- name?: ScriptProperties["name"];
38
- query?: ScriptProperties["query"];
39
- };
40
- export type ScriptProperties = ReturnType<typeof scriptEntityToProperties>;
41
- export declare const createScriptPatchedFields: (properties: ScriptPatchableProperties) => {
42
- name?: string;
43
- content?: string;
44
- context?: string[];
45
- };
46
- export declare const saveScript: (id: string, config: SonarV3Config) => (body: Record<string, any>) => import("ts-results-es").AsyncResult<ScriptEntity, import("../../common/Problem.ts").ValidationProblem | import("../index.ts").HttpError>;
38
+ export declare function mapScriptErrors<T extends z.output<typeof scriptUpdateCodec>>(body: T, err: HttpError): import("../../common/Problem.ts").ValidationProblem | HttpError;
@@ -17,7 +17,12 @@ import { Query } from "../../common/Query.js";
17
17
  import { duplicateScriptNameError } from "./ScriptErrors.js";
18
18
  import { Temporal } from "temporal-polyfill";
19
19
  import { Problem } from "../../common/Problem.js";
20
+ import * as z from "zod/mini";
21
+ import { scriptPropertiesCodec, scriptUpdateCodec } from "./scriptPropertiesCodec.js";
22
+ import { HttpError } from "../../common/HttpError.js";
23
+ import { safeParseResultToResult } from "../../common/safeParseResultToResult.js";
20
24
  export class Script {
25
+ #config;
21
26
  createdAt;
22
27
  createdBy;
23
28
  id;
@@ -25,8 +30,8 @@ export class Script {
25
30
  modifiedBy;
26
31
  name;
27
32
  query;
28
- #config;
29
33
  constructor(properties, config) {
34
+ this.#config = config;
30
35
  this.createdAt = properties.createdAt;
31
36
  this.createdBy = properties.createdBy;
32
37
  this.id = properties.id;
@@ -34,7 +39,6 @@ export class Script {
34
39
  this.modifiedBy = properties.modifiedBy;
35
40
  this.name = properties.name;
36
41
  this.query = properties.query;
37
- this.#config = config;
38
42
  }
39
43
  delete() {
40
44
  return this.#config
@@ -45,47 +49,36 @@ export class Script {
45
49
  .map(() => undefined).promise;
46
50
  }
47
51
  save(properties) {
48
- return saveScript(this.id, this.#config)(properties).map((entity) => new Script(scriptEntityToProperties(entity), this.#config))
49
- .promise;
52
+ const safeEncodedProperties = z.safeEncode(scriptUpdateCodec, properties);
53
+ if (!safeEncodedProperties.success) {
54
+ return Promise.resolve(safeParseResultToResult(safeEncodedProperties));
55
+ }
56
+ return (this.#config
57
+ .sonarV3Request(`scripts/${this.id}`, {
58
+ body: JSON.stringify(safeEncodedProperties.data),
59
+ headers: {
60
+ Accept: "application/json",
61
+ "Content-Type": "application/json",
62
+ },
63
+ keepalive: true,
64
+ method: "PATCH",
65
+ })
66
+ .map((response) => response.json())
67
+ /**
68
+ * Don't safe decode here, we should assume the original script decoded properly,
69
+ * so skipping safe decoding skips bloating the error side of the Result unnecessarily.
70
+ * If it really does fail to decode here, panicking is fine.
71
+ */
72
+ .map((entity) => new Script(z.decode(scriptPropertiesCodec, entity), this.#config))
73
+ .mapErr((err) => mapScriptErrors(safeEncodedProperties.data, err)).promise);
50
74
  }
75
+ static schema = scriptPropertiesCodec.def.out;
51
76
  }
52
- export const scriptEntityToProperties = (entity) => ({
53
- createdAt: Temporal.Instant.from(entity.createdAt),
54
- createdBy: entity.createdBy,
55
- id: entity.id,
56
- modifiedAt: Temporal.Instant.from(entity.modifiedAt),
57
- modifiedBy: entity.modifiedBy,
58
- name: entity.name,
59
- query: new Query(entity.content, entity.context),
60
- });
61
- export const createScriptPatchedFields = (properties) => {
62
- const patchedFields = {};
63
- if (properties.name) {
64
- patchedFields.name = properties.name;
65
- }
66
- if (properties.query) {
67
- patchedFields.content = properties.query.sql;
68
- patchedFields.context = properties.query.context;
77
+ export function mapScriptErrors(body, err) {
78
+ if (err.body instanceof Problem &&
79
+ err.body.detail?.includes("Cannot reuse the same script name")) {
80
+ return duplicateScriptNameError(body["name"]);
69
81
  }
70
- return patchedFields;
71
- };
72
- export const saveScript = (id, config) => (body) => {
73
- return config
74
- .sonarV3Request(`scripts/${id}`, {
75
- body: JSON.stringify(body),
76
- headers: {
77
- "Content-Type": "application/json",
78
- },
79
- keepalive: true,
80
- method: "PATCH",
81
- })
82
- .map((response) => response.json())
83
- .mapErr((err) => {
84
- if (err.body instanceof Problem &&
85
- err.body.detail?.includes("Cannot reuse the same script name")) {
86
- return duplicateScriptNameError(body["name"]);
87
- }
88
- return err;
89
- });
90
- };
82
+ return err;
83
+ }
91
84
  //# sourceMappingURL=Script.js.map