@dremio/js-sdk 0.10.0 → 0.11.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 (124) hide show
  1. package/dist/cloud/ai/AiResource.d.ts +3 -15
  2. package/dist/cloud/ai/AiResource.js +11 -14
  3. package/dist/cloud/ai/AiResource.js.map +1 -1
  4. package/dist/cloud/arctic/ArcticResource.d.ts +2 -3
  5. package/dist/cloud/arctic/ArcticResource.js +4 -6
  6. package/dist/cloud/arctic/ArcticResource.js.map +1 -1
  7. package/dist/cloud/engines/Engine.d.ts +2 -3
  8. package/dist/cloud/engines/Engine.js +5 -6
  9. package/dist/cloud/engines/Engine.js.map +1 -1
  10. package/dist/cloud/engines/EnginesResource.d.ts +2 -2
  11. package/dist/cloud/engines/EnginesResource.js +4 -4
  12. package/dist/cloud/engines/EnginesResource.js.map +1 -1
  13. package/dist/cloud/index.d.ts +3 -5
  14. package/dist/cloud/index.js +0 -1
  15. package/dist/cloud/index.js.map +1 -1
  16. package/dist/cloud/oauth/OAuthApplication.d.ts +1 -2
  17. package/dist/cloud/oauth/OAuthApplication.js +1 -3
  18. package/dist/cloud/oauth/OAuthApplication.js.map +1 -1
  19. package/dist/cloud/oauth/OAuthApplicationsResource.d.ts +3 -4
  20. package/dist/cloud/oauth/OAuthApplicationsResource.js +7 -10
  21. package/dist/cloud/oauth/OAuthApplicationsResource.js.map +1 -1
  22. package/dist/cloud/projects/Project.d.ts +2 -2
  23. package/dist/cloud/projects/ProjectsResource.d.ts +4 -5
  24. package/dist/cloud/projects/ProjectsResource.js +7 -16
  25. package/dist/cloud/projects/ProjectsResource.js.map +1 -1
  26. package/dist/cloud/users/CloudUsersResource.d.ts +2 -3
  27. package/dist/cloud/users/CloudUsersResource.js +4 -7
  28. package/dist/cloud/users/CloudUsersResource.js.map +1 -1
  29. package/dist/common/Config.d.ts +4 -2
  30. package/dist/common/Config.js.map +1 -1
  31. package/dist/common/HttpError.d.ts +7 -13
  32. package/dist/common/HttpError.js +19 -36
  33. package/dist/common/HttpError.js.map +1 -1
  34. package/dist/common/Problem.d.ts +29 -34
  35. package/dist/common/Problem.js +47 -19
  36. package/dist/common/Problem.js.map +1 -1
  37. package/dist/common/createRequest.js +8 -33
  38. package/dist/common/createRequest.js.map +1 -1
  39. package/dist/common/problems.d.ts +11 -9
  40. package/dist/common/problems.js +18 -9
  41. package/dist/common/problems.js.map +1 -1
  42. package/dist/enterprise/catalog/CatalogReferences/retrieveCatalogGrants.d.ts +2 -3
  43. package/dist/enterprise/catalog/CatalogReferences/retrieveCatalogGrants.js +3 -5
  44. package/dist/enterprise/catalog/CatalogReferences/retrieveCatalogGrants.js.map +1 -1
  45. package/dist/enterprise/catalog/EnterpriseCatalogResource.js +3 -2
  46. package/dist/enterprise/catalog/EnterpriseCatalogResource.js.map +1 -1
  47. package/dist/enterprise/catalog/catalogRetrieve.js +4 -0
  48. package/dist/enterprise/catalog/catalogRetrieve.js.map +1 -1
  49. package/dist/enterprise/credentials/exchangePat.d.ts +2 -4
  50. package/dist/enterprise/credentials/exchangePat.js +3 -3
  51. package/dist/enterprise/credentials/exchangePat.js.map +1 -1
  52. package/dist/enterprise/engines/Engine.d.ts +3 -5
  53. package/dist/enterprise/engines/Engine.js +7 -11
  54. package/dist/enterprise/engines/Engine.js.map +1 -1
  55. package/dist/enterprise/engines/EnginesResource.d.ts +2 -4
  56. package/dist/enterprise/engines/EnginesResource.js +4 -6
  57. package/dist/enterprise/engines/EnginesResource.js.map +1 -1
  58. package/dist/enterprise/index.d.ts +7 -9
  59. package/dist/enterprise/index.js +0 -1
  60. package/dist/enterprise/index.js.map +1 -1
  61. package/dist/enterprise/roles/RolesResource.d.ts +2 -3
  62. package/dist/enterprise/roles/RolesResource.js +4 -7
  63. package/dist/enterprise/roles/RolesResource.js.map +1 -1
  64. package/dist/enterprise/scripts/EnterpriseScript.d.ts +3 -13
  65. package/dist/enterprise/scripts/EnterpriseScript.js +4 -6
  66. package/dist/enterprise/scripts/EnterpriseScript.js.map +1 -1
  67. package/dist/enterprise/scripts/EnterpriseScriptsResource.d.ts +6 -2
  68. package/dist/enterprise/scripts/EnterpriseScriptsResource.js +1 -1
  69. package/dist/enterprise/scripts/EnterpriseScriptsResource.js.map +1 -1
  70. package/dist/enterprise/users/EnterpriseUser.d.ts +2 -3
  71. package/dist/enterprise/users/EnterpriseUser.js +3 -5
  72. package/dist/enterprise/users/EnterpriseUser.js.map +1 -1
  73. package/dist/enterprise/users/EnterpriseUsersResource.d.ts +2 -3
  74. package/dist/enterprise/users/EnterpriseUsersResource.js +4 -7
  75. package/dist/enterprise/users/EnterpriseUsersResource.js.map +1 -1
  76. package/dist/oss/catalog/CatalogReferences/DatasetCatalogReference.d.ts +1 -1
  77. package/dist/oss/catalog/CatalogReferences/FolderCatalogReference.d.ts +1 -1
  78. package/dist/oss/catalog/CatalogReferences/HomeCatalogReference.d.ts +1 -1
  79. package/dist/oss/catalog/CatalogReferences/SourceCatalogReference.d.ts +1 -1
  80. package/dist/oss/catalog/CatalogReferences/SpaceCatalogReference.d.ts +1 -1
  81. package/dist/oss/catalog/CatalogReferences/utils/catalogChildren.js +1 -0
  82. package/dist/oss/catalog/CatalogReferences/utils/catalogChildren.js.map +1 -1
  83. package/dist/oss/catalog/CatalogReferences/utils/getTags.d.ts +1 -2
  84. package/dist/oss/catalog/CatalogReferences/utils/getTags.js +2 -4
  85. package/dist/oss/catalog/CatalogReferences/utils/getTags.js.map +1 -1
  86. package/dist/oss/catalog/CatalogReferences/utils/getWiki.d.ts +1 -2
  87. package/dist/oss/catalog/CatalogReferences/utils/getWiki.js +2 -4
  88. package/dist/oss/catalog/CatalogReferences/utils/getWiki.js.map +1 -1
  89. package/dist/oss/catalog/CatalogResource.js +1 -0
  90. package/dist/oss/catalog/CatalogResource.js.map +1 -1
  91. package/dist/oss/catalog/CatalogTags.d.ts +2 -6
  92. package/dist/oss/catalog/CatalogTags.js +8 -13
  93. package/dist/oss/catalog/CatalogTags.js.map +1 -1
  94. package/dist/oss/catalog/CatalogWiki.d.ts +2 -6
  95. package/dist/oss/catalog/CatalogWiki.js +8 -13
  96. package/dist/oss/catalog/CatalogWiki.js.map +1 -1
  97. package/dist/oss/catalog/catalogErrors.d.ts +3 -14
  98. package/dist/oss/catalog/catalogErrors.js +9 -12
  99. package/dist/oss/catalog/catalogErrors.js.map +1 -1
  100. package/dist/oss/catalog/catalogRetrieve.d.ts +3 -2
  101. package/dist/oss/catalog/catalogRetrieve.js +6 -2
  102. package/dist/oss/catalog/catalogRetrieve.js.map +1 -1
  103. package/dist/oss/index.d.ts +4 -7
  104. package/dist/oss/index.js +0 -1
  105. package/dist/oss/index.js.map +1 -1
  106. package/dist/oss/jobs/Job.d.ts +3 -3
  107. package/dist/oss/jobs/Job.js +7 -9
  108. package/dist/oss/jobs/Job.js.map +1 -1
  109. package/dist/oss/jobs/JobsResource.d.ts +4 -5
  110. package/dist/oss/jobs/JobsResource.js +5 -7
  111. package/dist/oss/jobs/JobsResource.js.map +1 -1
  112. package/dist/oss/scripts/Script.d.ts +3 -22
  113. package/dist/oss/scripts/Script.js +12 -16
  114. package/dist/oss/scripts/Script.js.map +1 -1
  115. package/dist/oss/scripts/ScriptErrors.d.ts +6 -18
  116. package/dist/oss/scripts/ScriptErrors.js +10 -13
  117. package/dist/oss/scripts/ScriptErrors.js.map +1 -1
  118. package/dist/oss/scripts/ScriptsResource.d.ts +14 -6
  119. package/dist/oss/scripts/ScriptsResource.js +19 -21
  120. package/dist/oss/scripts/ScriptsResource.js.map +1 -1
  121. package/dist/oss/users/UsersResource.d.ts +2 -3
  122. package/dist/oss/users/UsersResource.js +4 -7
  123. package/dist/oss/users/UsersResource.js.map +1 -1
  124. package/package.json +1 -1
@@ -13,22 +13,19 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export const emptyPathError = {
17
- errors: [
18
- {
19
- detail: "`path` parameter is required and cannot be empty",
20
- pointer: "#/path",
21
- type: "https://api.dremio.dev/problems/validation/min-length",
22
- },
23
- ],
24
- title: "There was a problem validating the content of the request",
25
- type: "https://api.dremio.dev/problems/validation-problem",
26
- };
16
+ import { Problem, ValidationProblem } from "../../common/Problem.js";
17
+ export const emptyPathError = new ValidationProblem([
18
+ {
19
+ detail: "`path` parameter is required and cannot be empty",
20
+ pointer: "#/path",
21
+ type: "https://api.dremio.dev/problems/validation/min-length",
22
+ },
23
+ ]);
27
24
  /**
28
25
  * Generic problem for when we don't know what specifically caused the retrieval
29
26
  * to fail.
30
27
  */
31
- export const unableToRetrieveProblem = (internalErrorMessage) => ({
28
+ export const unableToRetrieveProblem = (internalErrorMessage) => new Problem({
32
29
  detail: internalErrorMessage,
33
30
  title: "We were unable to fetch details for this catalog object",
34
31
  type: "https://api.dremio.dev/problems/catalog/failed-to-retrieve",
@@ -1 +1 @@
1
- {"version":3,"file":"catalogErrors.js","sourceRoot":"","sources":["../../../src/oss/catalog/catalogErrors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,MAAM,EAAE;QACN;YACE,MAAM,EAAE,kDAAkD;YAC1D,OAAO,EAAE,QAAQ;YACjB,IAAI,EAAE,uDAAuD;SAC9D;KACF;IACD,KAAK,EAAE,2DAA2D;IAClE,IAAI,EAAE,oDAAoD;CACtB,CAAC;AAEvC;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,oBAA6B,EAAE,EAAE,CACvE,CAAC;IACC,MAAM,EAAE,oBAAoB;IAC5B,KAAK,EAAE,yDAAyD;IAChE,IAAI,EAAE,4DAA4D;CACnE,CAA4B,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 { Problem, ValidationProblem } from \"../../common/Problem.ts\";\n\nexport const emptyPathError = {\n errors: [\n {\n detail: \"`path` parameter is required and cannot be empty\",\n pointer: \"#/path\",\n type: \"https://api.dremio.dev/problems/validation/min-length\",\n },\n ],\n title: \"There was a problem validating the content of the request\",\n type: \"https://api.dremio.dev/problems/validation-problem\",\n} as const satisfies ValidationProblem;\n\n/**\n * Generic problem for when we don't know what specifically caused the retrieval\n * to fail.\n */\nexport const unableToRetrieveProblem = (internalErrorMessage?: string) =>\n ({\n detail: internalErrorMessage,\n title: \"We were unable to fetch details for this catalog object\",\n type: \"https://api.dremio.dev/problems/catalog/failed-to-retrieve\",\n }) as const satisfies Problem;\n"]}
1
+ {"version":3,"file":"catalogErrors.js","sourceRoot":"","sources":["../../../src/oss/catalog/catalogErrors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAErE,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,iBAAiB,CAAC;IAClD;QACE,MAAM,EAAE,kDAAkD;QAC1D,OAAO,EAAE,QAAQ;QACjB,IAAI,EAAE,uDAAuD;KAC9D;CACF,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,oBAA6B,EAAE,EAAE,CACvE,IAAI,OAAO,CAAC;IACV,MAAM,EAAE,oBAAoB;IAC5B,KAAK,EAAE,yDAAyD;IAChE,IAAI,EAAE,4DAA4D;CACnE,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 { Problem, ValidationProblem } from \"../../common/Problem.js\";\n\nexport const emptyPathError = new ValidationProblem([\n {\n detail: \"`path` parameter is required and cannot be empty\",\n pointer: \"#/path\",\n type: \"https://api.dremio.dev/problems/validation/min-length\",\n },\n]);\n\n/**\n * Generic problem for when we don't know what specifically caused the retrieval\n * to fail.\n */\nexport const unableToRetrieveProblem = (internalErrorMessage?: string) =>\n new Problem({\n detail: internalErrorMessage,\n title: \"We were unable to fetch details for this catalog object\",\n type: \"https://api.dremio.dev/problems/catalog/failed-to-retrieve\",\n });\n"]}
@@ -1,6 +1,7 @@
1
1
  import { type Result } from "ts-results-es";
2
2
  import type { SonarV3Config } from "../../common/Config.ts";
3
+ import { HttpError } from "../../common/HttpError.ts";
3
4
  import type { CatalogObject } from "./CatalogObjects/index.ts";
4
5
  import type { Problem } from "../../common/Problem.ts";
5
- export declare const baseRetrieve: (config: SonarV3Config) => (key: string) => Promise<Result<CatalogObject, Problem>>;
6
- export declare const baseRetrieveByPath: (config: SonarV3Config) => (key: string[]) => Promise<Result<CatalogObject, Problem>>;
6
+ export declare const baseRetrieve: (config: SonarV3Config) => (key: string) => Promise<Result<CatalogObject, Problem<string, undefined> | HttpError>>;
7
+ export declare const baseRetrieveByPath: (config: SonarV3Config) => (key: string[]) => Promise<Result<CatalogObject, Problem<string, undefined> | HttpError>>;
@@ -24,6 +24,7 @@ export const baseRetrieve = (config) => batch(async (ids) => {
24
24
  const id = Array.from(ids).at(0);
25
25
  return config
26
26
  .sonarV3Request(`catalog/${id}?maxChildren=0`)
27
+ .promise.then((result) => result.unwrap())
27
28
  .then((res) => res.json())
28
29
  .then((response) => {
29
30
  results.set(id, Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(response)));
@@ -31,7 +32,7 @@ export const baseRetrieve = (config) => batch(async (ids) => {
31
32
  })
32
33
  .catch((e) => {
33
34
  if (e instanceof HttpError) {
34
- results.set(id, Err(e.body));
35
+ results.set(id, Err(e));
35
36
  }
36
37
  else {
37
38
  results.set(id, Err(unableToRetrieveProblem()));
@@ -50,6 +51,7 @@ export const baseRetrieve = (config) => batch(async (ids) => {
50
51
  headers: { "Content-Type": "application/json" },
51
52
  method: "POST",
52
53
  })
54
+ .promise.then((result) => result.unwrap())
53
55
  .then((res) => res.json())
54
56
  .then((response) => response.data))).then((chunks) => chunks.flat());
55
57
  for (const catalogItem of catalogItems) {
@@ -74,6 +76,7 @@ export const baseRetrieveByPath = (config) => batch(async (paths) => {
74
76
  const path = Array.from(paths).at(0);
75
77
  return config
76
78
  .sonarV3Request(`catalog/by-path/${path.map(encodeURIComponent).join("/")}?maxChildren=0`)
79
+ .promise.then((result) => result.unwrap())
77
80
  .then((res) => res.json())
78
81
  .then((response) => {
79
82
  results.set(path, Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(response)));
@@ -81,7 +84,7 @@ export const baseRetrieveByPath = (config) => batch(async (paths) => {
81
84
  })
82
85
  .catch((e) => {
83
86
  if (e instanceof HttpError) {
84
- results.set(path, Err(e.body));
87
+ results.set(path, Err(e));
85
88
  }
86
89
  else {
87
90
  results.set(path, Err(unableToRetrieveProblem()));
@@ -100,6 +103,7 @@ export const baseRetrieveByPath = (config) => batch(async (paths) => {
100
103
  headers: { "Content-Type": "application/json" },
101
104
  method: "POST",
102
105
  })
106
+ .promise.then((result) => result.unwrap())
103
107
  .then((res) => res.json())
104
108
  .then((response) => response.data))).then((chunks) => chunks.flat());
105
109
  for (const catalogItem of catalogItems) {
@@ -1 +1 @@
1
- {"version":3,"file":"catalogRetrieve.js","sourceRoot":"","sources":["../../../src/oss/catalog/catalogRetrieve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE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AAM,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QAC1F,MAAM,WAAW,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QACtE,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,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 { batch } from \"../../common/batch.ts\";\nimport { Err, Ok, type Result } from \"ts-results-es\";\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { catalogObjectFromEntity } from \"./CatalogObjects/utils/catalogObjectFromEntity.ts\";\nimport { HttpError } from \"../../common/HttpError.ts\";\nimport { unableToRetrieveProblem } from \"./catalogErrors.ts\";\nimport type { CatalogObject } from \"./CatalogObjects/index.ts\";\nimport type { Problem } from \"../../common/Problem.ts\";\n\nexport const baseRetrieve = (config: SonarV3Config) =>\n batch(async (ids: Set<string>) => {\n const results = new Map<string, Result<CatalogObject, Problem>>();\n\n if (ids.size === 1) {\n const id = Array.from(ids).at(0)!;\n return config\n .sonarV3Request(`catalog/${id}?maxChildren=0`)\n .then((res) => res.json())\n .then((response) => {\n results.set(\n id,\n Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(response)),\n );\n return results;\n })\n .catch((e) => {\n if (e instanceof HttpError) {\n results.set(id, Err(e.body));\n } else {\n results.set(id, Err(unableToRetrieveProblem()));\n }\n\n return results;\n });\n }\n\n const idsArray = Array.from(ids);\n const chunks = [];\n\n while (idsArray.length > 0) {\n chunks.push(idsArray.splice(0, Math.min(50, idsArray.length)));\n }\n\n const catalogItems = await Promise.all(\n chunks.map((chunk) =>\n config\n .sonarV3Request(`catalog/by-ids?maxChildren=0`, {\n body: JSON.stringify(chunk),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n })\n .then((res) => res.json())\n .then((response) => response.data),\n ),\n ).then((chunks) => chunks.flat());\n\n for (const catalogItem of catalogItems) {\n results.set(\n catalogItem.id,\n Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(catalogItem)),\n );\n }\n\n for (const id of ids) {\n if (!results.has(id)) {\n results.set(id, Err(unableToRetrieveProblem()));\n }\n }\n\n return results;\n });\n\nexport const baseRetrieveByPath = (config: SonarV3Config) =>\n batch(async (paths: Set<string[]>) => {\n const results = new Map<string[], Result<CatalogObject, Problem>>();\n\n // Because the key is a reference type (array), we need to store the\n // original path reference\n const originalKeyRef = new Map<string, string[]>();\n for (const key of paths) {\n originalKeyRef.set(JSON.stringify(key), key);\n }\n\n if (paths.size === 1) {\n const path = Array.from(paths).at(0)!;\n return config\n .sonarV3Request(`catalog/by-path/${path.map(encodeURIComponent).join(\"/\")}?maxChildren=0`)\n .then((res) => res.json())\n .then((response) => {\n results.set(\n path,\n Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(response)),\n );\n return results;\n })\n .catch((e) => {\n if (e instanceof HttpError) {\n results.set(path, Err(e.body));\n } else {\n results.set(path, Err(unableToRetrieveProblem()));\n }\n return results;\n });\n }\n\n const pathsArray = Array.from(paths);\n const chunks = [];\n\n while (pathsArray.length > 0) {\n chunks.push(pathsArray.splice(0, Math.min(50, pathsArray.length)));\n }\n\n const catalogItems = await Promise.all(\n chunks.map((chunk) =>\n config\n .sonarV3Request(`catalog/by-paths?maxChildren=0`, {\n body: JSON.stringify(chunk),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n })\n .then((res) => res.json())\n .then((response) => response.data),\n ),\n ).then((chunks) => chunks.flat());\n\n for (const catalogItem of catalogItems) {\n const resolved = catalogObjectFromEntity(config, baseRetrieveByPath(config))(catalogItem);\n const originalKey = originalKeyRef.get(JSON.stringify(resolved.path));\n if (originalKey) {\n results.set(originalKey, Ok(resolved));\n }\n }\n\n for (const path of paths) {\n if (!results.has(path)) {\n results.set(path, Err(unableToRetrieveProblem()));\n }\n }\n\n return results;\n });\n"]}
1
+ {"version":3,"file":"catalogRetrieve.js","sourceRoot":"","sources":["../../../src/oss/catalog/catalogRetrieve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,EAAE,EAAe,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mDAAmD,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAI7D,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAqB,EAAE,EAAE,CACpD,KAAK,CAAC,KAAK,EAAE,GAAgB,EAAE,EAAE;IAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsD,CAAC;IAE9E,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QACnB,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC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ChB,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzC,CAAC;IACH,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,uBAAuB,EAAE,CAAC,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,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 { batch } from \"../../common/batch.ts\";\nimport { Err, Ok, type Result } from \"ts-results-es\";\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { catalogObjectFromEntity } from \"./CatalogObjects/utils/catalogObjectFromEntity.ts\";\nimport { HttpError } from \"../../common/HttpError.ts\";\nimport { unableToRetrieveProblem } from \"./catalogErrors.ts\";\nimport type { CatalogObject } from \"./CatalogObjects/index.ts\";\nimport type { Problem } from \"../../common/Problem.ts\";\n\nexport const baseRetrieve = (config: SonarV3Config) =>\n batch(async (ids: Set<string>) => {\n const results = new Map<string, Result<CatalogObject, HttpError | Problem>>();\n\n if (ids.size === 1) {\n const id = Array.from(ids).at(0)!;\n return config\n .sonarV3Request(`catalog/${id}?maxChildren=0`)\n .promise.then((result) => result.unwrap())\n .then((res) => res.json())\n .then((response) => {\n results.set(\n id,\n Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(response)),\n );\n return results;\n })\n .catch((e) => {\n if (e instanceof HttpError) {\n results.set(id, Err(e));\n } else {\n results.set(id, Err(unableToRetrieveProblem()));\n }\n\n return results;\n });\n }\n\n const idsArray = Array.from(ids);\n const chunks = [];\n\n while (idsArray.length > 0) {\n chunks.push(idsArray.splice(0, Math.min(50, idsArray.length)));\n }\n\n const catalogItems = await Promise.all(\n chunks.map((chunk) =>\n config\n .sonarV3Request(`catalog/by-ids?maxChildren=0`, {\n body: JSON.stringify(chunk),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n })\n .promise.then((result) => result.unwrap())\n .then((res) => res.json())\n .then((response) => response.data),\n ),\n ).then((chunks) => chunks.flat());\n\n for (const catalogItem of catalogItems) {\n results.set(\n catalogItem.id,\n Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(catalogItem)),\n );\n }\n\n for (const id of ids) {\n if (!results.has(id)) {\n results.set(id, Err(unableToRetrieveProblem()));\n }\n }\n\n return results;\n });\n\nexport const baseRetrieveByPath = (config: SonarV3Config) =>\n batch(async (paths: Set<string[]>) => {\n const results = new Map<string[], Result<CatalogObject, HttpError | Problem>>();\n\n // Because the key is a reference type (array), we need to store the\n // original path reference\n const originalKeyRef = new Map<string, string[]>();\n for (const key of paths) {\n originalKeyRef.set(JSON.stringify(key), key);\n }\n\n if (paths.size === 1) {\n const path = Array.from(paths).at(0)!;\n return config\n .sonarV3Request(`catalog/by-path/${path.map(encodeURIComponent).join(\"/\")}?maxChildren=0`)\n .promise.then((result) => result.unwrap())\n .then((res) => res.json())\n .then((response) => {\n results.set(\n path,\n Ok(catalogObjectFromEntity(config, baseRetrieveByPath(config))(response)),\n );\n return results;\n })\n .catch((e) => {\n if (e instanceof HttpError) {\n results.set(path, Err(e));\n } else {\n results.set(path, Err(unableToRetrieveProblem()));\n }\n return results;\n });\n }\n\n const pathsArray = Array.from(paths);\n const chunks = [];\n\n while (pathsArray.length > 0) {\n chunks.push(pathsArray.splice(0, Math.min(50, pathsArray.length)));\n }\n\n const catalogItems = await Promise.all(\n chunks.map((chunk) =>\n config\n .sonarV3Request(`catalog/by-paths?maxChildren=0`, {\n body: JSON.stringify(chunk),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n })\n .promise.then((result) => result.unwrap())\n .then((res) => res.json())\n .then((response) => response.data),\n ),\n ).then((chunks) => chunks.flat());\n\n for (const catalogItem of catalogItems) {\n const resolved = catalogObjectFromEntity(config, baseRetrieveByPath(config))(catalogItem);\n const originalKey = originalKeyRef.get(JSON.stringify(resolved.path));\n if (originalKey) {\n results.set(originalKey, Ok(resolved));\n }\n }\n\n for (const path of paths) {\n if (!results.has(path)) {\n results.set(path, Err(unableToRetrieveProblem()));\n }\n }\n\n return results;\n });\n"]}
@@ -1,6 +1,4 @@
1
- import { createRequest } from "../common/createRequest.ts";
2
1
  import type { Config } from "../common/Config.ts";
3
- import { Resources } from "./resources.ts";
4
2
  export declare const Dremio: (config: Config) => {
5
3
  _request: import("../common/Config.ts").RequestFn;
6
4
  _sonarResourceConfig: {
@@ -12,11 +10,11 @@ export declare const Dremio: (config: Config) => {
12
10
  } | undefined;
13
11
  origin: string;
14
12
  request: import("../common/Config.ts").RequestFn;
15
- sonarV2Request: (path: string, init: RequestInit | undefined) => Promise<Response>;
16
- sonarV3Request: (path: string, init: RequestInit | undefined) => Promise<Response>;
13
+ sonarV2Request: (path: string, init: RequestInit | undefined) => import("ts-results-es").AsyncResult<Response, import("../common/HttpError.ts").HttpError>;
14
+ sonarV3Request: (path: string, init: RequestInit | undefined) => import("ts-results-es").AsyncResult<Response, import("../common/HttpError.ts").HttpError>;
17
15
  };
18
- _sonarV2Request: (path: string, init: RequestInit | undefined) => Promise<Response>;
19
- _sonarV3Request: (path: string, init: RequestInit | undefined) => Promise<Response>;
16
+ _sonarV2Request: (path: string, init: RequestInit | undefined) => import("ts-results-es").AsyncResult<Response, import("../common/HttpError.ts").HttpError>;
17
+ _sonarV3Request: (path: string, init: RequestInit | undefined) => import("ts-results-es").AsyncResult<Response, import("../common/HttpError.ts").HttpError>;
20
18
  catalog: import("./catalog/CatalogResource.ts").CatalogResource;
21
19
  jobs: import("./jobs/JobsResource.ts").JobsResource;
22
20
  scripts: import("./scripts/ScriptsResource.ts").ScriptsResource;
@@ -25,4 +23,3 @@ export declare const Dremio: (config: Config) => {
25
23
  export * from "../common/sharedExports.ts";
26
24
  export * from "./credentials/index.ts";
27
25
  export * from "./interfaces.ts";
28
- export { createRequest, Resources as _Resources };
package/dist/oss/index.js CHANGED
@@ -38,5 +38,4 @@ export const Dremio = (config) => {
38
38
  export * from "../common/sharedExports.js";
39
39
  export * from "./credentials/index.js";
40
40
  export * from "./interfaces.js";
41
- export { createRequest, Resources as _Resources };
42
41
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oss/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAE,EAAE;IAChD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO;QACP,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,IAAI,CAAC;QAC/D,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,EAAE,IAAI,CAAC;KACR,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;IACvC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC3D,OAAO;QACL,GAAG,SAAS,CAAC,mBAAmB,CAAC;QACjC,QAAQ,EAAE,mBAAmB,CAAC,OAAO;QACrC,oBAAoB,EAAE,mBAAmB;QACzC,eAAe,EAAE,mBAAmB,CAAC,cAAc;QACnD,eAAe,EAAE,mBAAmB,CAAC,cAAc;KACpD,CAAC;AACJ,CAAC,CAAC;AAEF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,SAAS,IAAI,UAAU,EAAE,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 { createRequest } from \"../common/createRequest.ts\";\nimport type { Config, ResourceConfig, SonarV2Config, SonarV3Config } from \"../common/Config.ts\";\nimport { Resources } from \"./resources.ts\";\n\nconst getSonarResourceConfig = (config: Config) => {\n const request = createRequest(config);\n return {\n logger: config.logger,\n origin: config.origin,\n request,\n sonarV2Request: (path, init) => request(`/apiv2/${path}`, init),\n sonarV3Request: (path, init) => request(`/api/v3/${path}`, init),\n } satisfies ResourceConfig & SonarV2Config & SonarV3Config;\n};\n\nexport const Dremio = (config: Config) => {\n const sonarResourceConfig = getSonarResourceConfig(config);\n return {\n ...Resources(sonarResourceConfig),\n _request: sonarResourceConfig.request,\n _sonarResourceConfig: sonarResourceConfig,\n _sonarV2Request: sonarResourceConfig.sonarV2Request,\n _sonarV3Request: sonarResourceConfig.sonarV3Request,\n };\n};\n\nexport * from \"../common/sharedExports.ts\";\nexport * from \"./credentials/index.ts\";\nexport * from \"./interfaces.ts\";\nexport { createRequest, Resources as _Resources };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/oss/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAE,EAAE;IAChD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO;QACP,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,EAAE,IAAI,CAAC;QAC/D,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,EAAE,IAAI,CAAC;KACR,CAAC;AAC7D,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE;IACvC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC3D,OAAO;QACL,GAAG,SAAS,CAAC,mBAAmB,CAAC;QACjC,QAAQ,EAAE,mBAAmB,CAAC,OAAO;QACrC,oBAAoB,EAAE,mBAAmB;QACzC,eAAe,EAAE,mBAAmB,CAAC,cAAc;QACnD,eAAe,EAAE,mBAAmB,CAAC,cAAc;KACpD,CAAC;AACJ,CAAC,CAAC;AAEF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,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 { createRequest } from \"../common/createRequest.ts\";\nimport type { Config, ResourceConfig, SonarV2Config, SonarV3Config } from \"../common/Config.ts\";\nimport { Resources } from \"./resources.ts\";\n\nconst getSonarResourceConfig = (config: Config) => {\n const request = createRequest(config);\n return {\n logger: config.logger,\n origin: config.origin,\n request,\n sonarV2Request: (path, init) => request(`/apiv2/${path}`, init),\n sonarV3Request: (path, init) => request(`/api/v3/${path}`, init),\n } satisfies ResourceConfig & SonarV2Config & SonarV3Config;\n};\n\nexport const Dremio = (config: Config) => {\n const sonarResourceConfig = getSonarResourceConfig(config);\n return {\n ...Resources(sonarResourceConfig),\n _request: sonarResourceConfig.request,\n _sonarResourceConfig: sonarResourceConfig,\n _sonarV2Request: sonarResourceConfig.sonarV2Request,\n _sonarV3Request: sonarResourceConfig.sonarV3Request,\n };\n};\n\nexport * from \"../common/sharedExports.ts\";\nexport * from \"./credentials/index.ts\";\nexport * from \"./interfaces.ts\";\n"]}
@@ -32,15 +32,15 @@ export declare class Job {
32
32
  };
33
33
  readonly totalRows: number;
34
34
  }, void, unknown>;
35
- metadata: ({ signal }?: SignalParam) => Promise<Err<unknown> | Ok<{
35
+ metadata: ({ signal }?: SignalParam) => Promise<Result<{
36
36
  schema: import("./utils/JobResultsResponse.ts").JobResultsSchema<string>;
37
37
  totalRows: number;
38
- }>>;
38
+ }, import("../index.ts").HttpError>>;
39
39
  slice: <T extends Record<string, unknown> = Record<string, unknown>>(start?: number, end?: number, { signal }?: SignalParam) => Promise<Err<unknown> | Ok<T[]>>;
40
40
  };
41
41
  /**
42
42
  * @returns A `Job` instance once it's reached a settled state
43
43
  */
44
44
  retrieveSettled(): Promise<Job>;
45
- cancel(): Promise<Err<any> | Ok<undefined>>;
45
+ cancel(): Promise<Result<undefined, import("../index.ts").HttpError>>;
46
46
  }
@@ -103,9 +103,9 @@ export class Job {
103
103
  while (hasMore && offset < stopAfterOffset) {
104
104
  // Make batch_size dynamic to allow for requesting a smaller final page
105
105
  const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);
106
- const batch = await this.#config
106
+ const batch = (await this.#config
107
107
  .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })
108
- .then((res) => res.json());
108
+ .map((res) => res.json()).promise).unwrap();
109
109
  offset += batch.rows.length;
110
110
  hasMore = batch.rows.length === batch_size;
111
111
  if (batch.rows.length) {
@@ -125,12 +125,11 @@ export class Job {
125
125
  async #metadata({ signal } = {}) {
126
126
  return this.#config
127
127
  .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })
128
- .then((res) => res.json())
129
- .then((response) => Ok({
128
+ .map((res) => res.json())
129
+ .map((response) => ({
130
130
  schema: response.schema,
131
131
  totalRows: response.rowCount,
132
- }))
133
- .catch((e) => Err(e));
132
+ })).promise;
134
133
  }
135
134
  async #slice(start = 0, end = Infinity, { signal } = {}) {
136
135
  try {
@@ -144,14 +143,13 @@ export class Job {
144
143
  return Err(e);
145
144
  }
146
145
  }
147
- async cancel() {
146
+ cancel() {
148
147
  return this.#config
149
148
  .sonarV3Request(`job/${this.id}/cancel`, {
150
149
  keepalive: true,
151
150
  method: "POST",
152
151
  })
153
- .then(() => Ok(undefined))
154
- .catch((e) => Err(e));
152
+ .map(() => undefined).promise;
155
153
  }
156
154
  }
157
155
  const MAX_BATCH_SIZE = 500;
@@ -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,eAA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AAE,KAAK,EAAE,EACrC,EAAE,MAAM,EAAE,CACX,EAAE,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;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,KAAK,CAAC,MAAM;QACV,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,OAAO,IAAI,CAAC,EAAE,SAAS,EAAE;YACvC,SAAS,EAAE,IAAI;YACf,MAAM,EAAE,MAAM;SACf,CAAC;aACD,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;aACzB,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1B,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\";\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, unknown>>,\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 = await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .then((res) => res.json() as Promise<JobResultsResponse<T>>);\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 .then((res) => res.json() as Promise<JobResultsResponse>)\n .then((response) =>\n Ok({\n schema: response.schema,\n totalRows: response.rowCount,\n }),\n )\n .catch((e: unknown) => Err(e));\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 async cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .then(() => Ok(undefined))\n .catch((e) => Err(e));\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,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAInD,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,CAA4B;IACpC,SAAS,CAA6B;IACtC,KAAK,CAAyB;IAEvB,QAAQ,CAAkB;IAC1C,OAAO,CAAgB;IAEvB,YACE,UAAyB,EACzB,MAAqB,EACrB,OAAyD;QAEzD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC;QAC5C,IAAI,CAAC,kBAAkB,GAAG,UAAU,CAAC,kBAAkB,CAAC;QACxD,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,UA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,CAAC;YAClB,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,SAAS,EAAE,QAAQ,CAAC,QAAQ;SAC7B,CAAC,CAAC,CAAC,OAAO,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,MAAM,CACV,QAAgB,CAAC,EACjB,MAAc,QAAQ,EACtB,EAAE,MAAM,KAAkB,EAAE;QAE5B,IAAI,CAAC;YACH,MAAM,IAAI,GAAQ,EAAE,CAAC;YACrB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,YAAY,CACzC,EAAE,KAAK,EAAE,GAAG,GAAG,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,EACrC,EAAE,MAAM,EAAE,CACX,EAAE,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;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,SAAS,CAAC,CAAC,OAAO,CAAC;IAClC,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\";\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, unknown>>,\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).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
@@ -1,18 +1,17 @@
1
1
  import type { SonarV3Config } from "../../common/Config.ts";
2
2
  import { Job } from "./Job.ts";
3
3
  import { Query } from "../../common/Query.ts";
4
- import { Err, Ok } from "ts-results-es";
5
4
  import type { SignalParam } from "../../common/Params.ts";
6
5
  import { type JobEntity } from "./utils/jobEntityToProperties.ts";
7
6
  export declare class JobsResource {
8
7
  #private;
9
8
  constructor(config: SonarV3Config);
10
9
  _jobFromEntity(id: string, entity: JobEntity): Job;
11
- create(query: Query): Promise<Err<unknown> | Ok<string>>;
10
+ create(query: Query): Promise<import("ts-results-es").Result<string, import("../index.ts").HttpError>>;
12
11
  /**
13
12
  * A convenience method to combine job creation and retrieval
14
13
  */
15
- createAndRetrieve(query: Query): Promise<import("ts-results-es").Result<Job, unknown>>;
16
- observe(id: string): import("rxjs").Observable<Err<unknown> | Ok<Job>>;
17
- retrieve(id: string, { signal }?: SignalParam): Promise<Err<unknown> | Ok<Job>>;
14
+ createAndRetrieve(query: Query): Promise<import("ts-results-es").Result<Job, import("../index.ts").HttpError>>;
15
+ observe(id: string): import("rxjs").Observable<import("ts-results-es").Result<Job, import("../index.ts").HttpError>>;
16
+ retrieve(id: string, { signal }?: SignalParam): Promise<import("ts-results-es").Result<Job, import("../index.ts").HttpError>>;
18
17
  }
@@ -15,7 +15,7 @@
15
15
  */
16
16
  import { Job } from "./Job.js";
17
17
  import { Query } from "../../common/Query.js";
18
- import { Err, Ok, AsyncResult } from "ts-results-es";
18
+ import { AsyncResult } from "ts-results-es";
19
19
  import { concatMap, shareReplay, takeWhile, timer } from "rxjs";
20
20
  import { fromAbortable } from "../../common/fromAbortable.js";
21
21
  import { jobEntityToProperties } from "./utils/jobEntityToProperties.js";
@@ -41,9 +41,8 @@ export class JobsResource {
41
41
  keepalive: true,
42
42
  method: "POST",
43
43
  })
44
- .then((res) => res.json())
45
- .then((response) => Ok(response.id))
46
- .catch((e) => Err(e));
44
+ .map((response) => response.json())
45
+ .map((response) => response.id).promise;
47
46
  }
48
47
  /**
49
48
  * A convenience method to combine job creation and retrieval
@@ -79,9 +78,8 @@ export class JobsResource {
79
78
  retrieve(id, { signal } = {}) {
80
79
  return this.#config
81
80
  .sonarV3Request(`job/${id}`, { signal })
82
- .then((res) => res.json())
83
- .then((entity) => Ok(this._jobFromEntity(id, entity)))
84
- .catch((e) => Err(e));
81
+ .map((res) => res.json())
82
+ .map((entity) => this._jobFromEntity(id, entity)).promise;
85
83
  }
86
84
  }
87
85
  //# 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,GAAG,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAChE,OA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AC,CAAC,CAAC,OAAO,CAAC;IAC9F,CAAC;IAED,OAAO,CAAC,EAAU;QAChB;;;WAGG;QACH,OAAO,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI;QACxB;;;;WAIG;QACH,SAAS,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;QAC7E;;WAEG;QACH,SAAS,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC;QAC5E;;;WAGG;QACH,WAAW,CAAC;YACV,UAAU,EAAE,CAAC;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CACH,CAAC;IACJ,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,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAwB,CAAC;aAC/C,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;aACrD,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,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 { Err, Ok, AsyncResult } from \"ts-results-es\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { concatMap, shareReplay, takeWhile, timer } from \"rxjs\";\nimport { fromAbortable } from \"../../common/fromAbortable.ts\";\nimport { jobEntityToProperties, type JobEntity } from \"./utils/jobEntityToProperties.ts\";\n\nexport class JobsResource {\n #config: SonarV3Config;\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 .then((res) => res.json() as Promise<{ id: string }>)\n .then((response) => Ok(response.id))\n .catch((e: unknown) => Err(e));\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 /**\n * Check every 1000ms for job status changes. 1000ms may seem too frequent,\n * but it helps keep the client feeling snappy, especially for jobs that complete quickly.\n */\n return timer(0, 1000).pipe(\n /**\n * Use `concatMap` instead of `switchMap` to avoid a situation where the call takes longer than\n * 1000ms (possibly due to network conditions or API slowdowns) which would cause switchMap to\n * constantly cancel unfinished requests (in which case, no requests would ever complete)\n */\n concatMap(() => fromAbortable(({ signal }) => this.retrieve(id, { signal }))),\n /**\n * Continue polling until the job has reached a settled state\n */\n takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true),\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 retrieve(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${id}`, { signal })\n .then((res) => res.json() as Promise<JobEntity>)\n .then((entity) => Ok(this._jobFromEntity(id, entity)))\n .catch((e: unknown) => Err(e));\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,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAkB,MAAM,kCAAkC,CAAC;AAEzF,MAAM,OAAO,YAAY;IACvB,OAAO,CAAgB;IAEvB,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,cAAc,CAAC,EAAU,EAAE,MAAiB;QAC1C,OAAO,IAAI,GAAG,CAAC,qBAAqB,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAC3F,CAAC;IAED,MAAM,CAAC,KAAY;QACjB,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,KAAK,EAAE;YACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,KA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,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","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 { concatMap, shareReplay, takeWhile, timer } from \"rxjs\";\nimport { fromAbortable } from \"../../common/fromAbortable.ts\";\nimport { jobEntityToProperties, type JobEntity } from \"./utils/jobEntityToProperties.ts\";\n\nexport class JobsResource {\n #config: SonarV3Config;\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 /**\n * Check every 1000ms for job status changes. 1000ms may seem too frequent,\n * but it helps keep the client feeling snappy, especially for jobs that complete quickly.\n */\n return timer(0, 1000).pipe(\n /**\n * Use `concatMap` instead of `switchMap` to avoid a situation where the call takes longer than\n * 1000ms (possibly due to network conditions or API slowdowns) which would cause switchMap to\n * constantly cancel unfinished requests (in which case, no requests would ever complete)\n */\n concatMap(() => fromAbortable(({ signal }) => this.retrieve(id, { signal }))),\n /**\n * Continue polling until the job has reached a settled state\n */\n takeWhile((jobResult) => jobResult.isOk() && !jobResult.value.settled, true),\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 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,4 +1,3 @@
1
- import { Err, Ok } from "ts-results-es";
2
1
  import { Query } from "../../common/Query.ts";
3
2
  import type { SonarV3Config } from "../../common/Config.ts";
4
3
  import { Temporal } from "temporal-polyfill";
@@ -12,17 +11,8 @@ export declare class Script {
12
11
  readonly name: ScriptProperties["name"];
13
12
  readonly query: ScriptProperties["query"];
14
13
  constructor(properties: ScriptProperties, config: SonarV3Config);
15
- delete(): Promise<Err<unknown> | Ok<undefined>>;
16
- save(properties: ScriptPatchableProperties): Promise<Err<{
17
- readonly errors: [{
18
- readonly detail: "A script with this name already exists";
19
- readonly pointer: "#/name";
20
- readonly type: "https://api.dremio.dev/problems/validation/field-conflict";
21
- readonly value: string;
22
- }];
23
- readonly title: "There was a problem validating the content of the request";
24
- readonly type: "https://api.dremio.dev/problems/validation-problem";
25
- }> | Err<import("../index.ts").Problem> | Ok<Script>>;
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>>;
26
16
  }
27
17
  export declare const scriptEntityToProperties: (entity: ScriptEntity) => {
28
18
  createdAt: Temporal.Instant;
@@ -53,13 +43,4 @@ export declare const createScriptPatchedFields: (properties: ScriptPatchableProp
53
43
  content?: string;
54
44
  context?: string[];
55
45
  };
56
- export declare const saveScript: (id: string, config: SonarV3Config) => (body: Record<string, any>) => Promise<Ok<ScriptEntity> | Err<{
57
- readonly errors: [{
58
- readonly detail: "A script with this name already exists";
59
- readonly pointer: "#/name";
60
- readonly type: "https://api.dremio.dev/problems/validation/field-conflict";
61
- readonly value: string;
62
- }];
63
- readonly title: "There was a problem validating the content of the request";
64
- readonly type: "https://api.dremio.dev/problems/validation-problem";
65
- }> | Err<import("../index.ts").Problem>>;
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>;
@@ -13,11 +13,10 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Err, Ok } from "ts-results-es";
17
16
  import { Query } from "../../common/Query.js";
18
- import { HttpError } from "../../common/HttpError.js";
19
17
  import { duplicateScriptNameError } from "./ScriptErrors.js";
20
18
  import { Temporal } from "temporal-polyfill";
19
+ import { Problem } from "../../common/Problem.js";
21
20
  export class Script {
22
21
  createdAt;
23
22
  createdBy;
@@ -37,17 +36,17 @@ export class Script {
37
36
  this.query = properties.query;
38
37
  this.#config = config;
39
38
  }
40
- async delete() {
39
+ delete() {
41
40
  return this.#config
42
41
  .sonarV3Request(`scripts/${this.id}`, {
43
42
  keepalive: true,
44
43
  method: "DELETE",
45
44
  })
46
- .then(() => Ok(undefined))
47
- .catch((e) => Err(e));
45
+ .map(() => undefined).promise;
48
46
  }
49
- async save(properties) {
50
- return saveScript(this.id, this.#config)(properties).then((result) => result.map((value) => new Script(scriptEntityToProperties(value), this.#config)));
47
+ save(properties) {
48
+ return saveScript(this.id, this.#config)(properties).map((entity) => new Script(scriptEntityToProperties(entity), this.#config))
49
+ .promise;
51
50
  }
52
51
  }
53
52
  export const scriptEntityToProperties = (entity) => ({
@@ -80,16 +79,13 @@ export const saveScript = (id, config) => (body) => {
80
79
  keepalive: true,
81
80
  method: "PATCH",
82
81
  })
83
- .then((res) => res.json())
84
- .then((entity) => Ok(entity))
85
- .catch((e) => {
86
- if (e instanceof HttpError) {
87
- if (e.body.detail?.includes("Cannot reuse the same script name")) {
88
- return Err(duplicateScriptNameError(body["name"]));
89
- }
90
- return Err(e.body);
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"]);
91
87
  }
92
- throw e;
88
+ return err;
93
89
  });
94
90
  };
95
91
  //# sourceMappingURL=Script.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Script.js","sourceRoot":"","sources":["../../../src/oss/scripts/Script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,MAAM,OAAO,MAAM;IACR,SAAS,CAAgC;IACzC,SAAS,CAAgC;IACzC,EAAE,CAAyB;IAC3B,UAAU,CAAiC;IAC3C,U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,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;SACzB,IAAI,CAAC,CAAC,MAAoB,EAAE,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;SAC1C,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;QACpB,IAAI,CAAC,YAAY,SAAS,EAAE,CAAC;YAC3B,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,mCAAmC,CAAC,EAAE,CAAC;gBACjE,OAAO,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACrD,CAAC;YACD,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;QAED,MAAM,CAAC,CAAC;IACV,CAAC,CAAC,CAAC;AACP,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 { Err, Ok } from \"ts-results-es\";\nimport { Query } from \"../../common/Query.ts\";\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { HttpError } from \"../../common/HttpError.ts\";\nimport { duplicateScriptNameError } from \"./ScriptErrors.ts\";\nimport { Temporal } from \"temporal-polyfill\";\n\nexport class Script {\n readonly createdAt: ScriptProperties[\"createdAt\"];\n readonly createdBy: ScriptProperties[\"createdBy\"];\n readonly id: ScriptProperties[\"id\"];\n readonly modifiedAt: ScriptProperties[\"modifiedAt\"];\n readonly modifiedBy: ScriptProperties[\"modifiedBy\"];\n readonly name: ScriptProperties[\"name\"];\n readonly query: ScriptProperties[\"query\"];\n #config: SonarV3Config;\n\n constructor(properties: ScriptProperties, config: SonarV3Config) {\n this.createdAt = properties.createdAt;\n this.createdBy = properties.createdBy;\n this.id = properties.id;\n this.modifiedAt = properties.modifiedAt;\n this.modifiedBy = properties.modifiedBy;\n this.name = properties.name;\n this.query = properties.query;\n this.#config = config;\n }\n\n async delete() {\n return this.#config\n .sonarV3Request(`scripts/${this.id}`, {\n keepalive: true,\n method: \"DELETE\",\n })\n .then(() => Ok(undefined))\n .catch((e: unknown) => Err(e));\n }\n\n async save(properties: ScriptPatchableProperties) {\n return saveScript(\n this.id,\n this.#config,\n )(properties).then((result) =>\n result.map((value) => new Script(scriptEntityToProperties(value), this.#config)),\n );\n }\n}\n\nexport const scriptEntityToProperties = (entity: ScriptEntity) => ({\n createdAt: Temporal.Instant.from(entity.createdAt),\n createdBy: entity.createdBy,\n id: entity.id,\n modifiedAt: Temporal.Instant.from(entity.modifiedAt),\n modifiedBy: entity.modifiedBy,\n name: entity.name,\n query: new Query(entity.content, entity.context),\n});\n\nexport type ScriptEntity = {\n content: string;\n context: string[];\n createdAt: string;\n createdBy: string;\n id: string;\n modifiedAt: string;\n modifiedBy: string;\n name: string;\n};\n\nexport type ScriptPatchableProperties = {\n name?: ScriptProperties[\"name\"];\n query?: ScriptProperties[\"query\"];\n};\n\nexport type ScriptProperties = ReturnType<typeof scriptEntityToProperties>;\n\nexport const createScriptPatchedFields = (properties: ScriptPatchableProperties) => {\n const patchedFields = {} as {\n name?: string;\n content?: string;\n context?: string[];\n };\n if (properties.name) {\n patchedFields.name = properties.name;\n }\n if (properties.query) {\n patchedFields.content = properties.query.sql;\n patchedFields.context = properties.query.context;\n }\n return patchedFields;\n};\n\nexport const saveScript = (id: string, config: SonarV3Config) => (body: Record<string, any>) => {\n return config\n .sonarV3Request(`scripts/${id}`, {\n body: JSON.stringify(body),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"PATCH\",\n })\n .then((res) => res.json())\n .then((entity: ScriptEntity) => Ok(entity))\n .catch((e: unknown) => {\n if (e instanceof HttpError) {\n if (e.body.detail?.includes(\"Cannot reuse the same script name\")) {\n return Err(duplicateScriptNameError(body[\"name\"]));\n }\n return Err(e.body);\n }\n\n throw e;\n });\n};\n"]}
1
+ {"version":3,"file":"Script.js","sourceRoot":"","sources":["../../../src/oss/scripts/Script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,MAAM,OAAO,MAAM;IACR,SAAS,CAAgC;IACzC,SAAS,CAAgC;IACzC,EAAE,CAAyB;IAC3B,UAAU,CAAiC;IAC3C,UAAU,CAAiC;IAC3C,IAAI,CAA2B;IAC/B,KAAK,CAA4B;IAC1C,OAAO,CAAgB;IAEvB,YAAY,UAA4B,EAAE,MAAqB;QAC7D,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,SAAS,CAAC;QACtC,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;QACxC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,OAAO;aAChB,cAAc,CAAC,WAAW,IAAI,CAAC,EA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,aAAa,CAAC,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC;IACnD,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAU,EAAE,MAAqB,EAAE,EAAE,CAAC,CAAC,IAAyB,EAAE,EAAE;IAC7F,OAAO,MAAM;SACV,cAAc,CAAC,WAAW,EAAE,EAAE,EAAE;QAC/B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAC1B,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;QACD,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,OAAO;KAChB,CAAC;SACD,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAA2B,CAAC;SAC3D,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QACd,IACE,GAAG,CAAC,IAAI,YAAY,OAAO;YAC3B,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,mCAAmC,CAAC,EAC9D,CAAC;YACD,OAAO,wBAAwB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC,CAAC,CAAC;AACP,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 { Query } from \"../../common/Query.ts\";\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { duplicateScriptNameError } from \"./ScriptErrors.ts\";\nimport { Temporal } from \"temporal-polyfill\";\nimport { Problem } from \"../../common/Problem.ts\";\n\nexport class Script {\n readonly createdAt: ScriptProperties[\"createdAt\"];\n readonly createdBy: ScriptProperties[\"createdBy\"];\n readonly id: ScriptProperties[\"id\"];\n readonly modifiedAt: ScriptProperties[\"modifiedAt\"];\n readonly modifiedBy: ScriptProperties[\"modifiedBy\"];\n readonly name: ScriptProperties[\"name\"];\n readonly query: ScriptProperties[\"query\"];\n #config: SonarV3Config;\n\n constructor(properties: ScriptProperties, config: SonarV3Config) {\n this.createdAt = properties.createdAt;\n this.createdBy = properties.createdBy;\n this.id = properties.id;\n this.modifiedAt = properties.modifiedAt;\n this.modifiedBy = properties.modifiedBy;\n this.name = properties.name;\n this.query = properties.query;\n this.#config = config;\n }\n\n delete() {\n return this.#config\n .sonarV3Request(`scripts/${this.id}`, {\n keepalive: true,\n method: \"DELETE\",\n })\n .map(() => undefined as void).promise;\n }\n\n save(properties: ScriptPatchableProperties) {\n return saveScript(\n this.id,\n this.#config,\n )(properties).map((entity) => new Script(scriptEntityToProperties(entity), this.#config))\n .promise;\n }\n}\n\nexport const scriptEntityToProperties = (entity: ScriptEntity) => ({\n createdAt: Temporal.Instant.from(entity.createdAt),\n createdBy: entity.createdBy,\n id: entity.id,\n modifiedAt: Temporal.Instant.from(entity.modifiedAt),\n modifiedBy: entity.modifiedBy,\n name: entity.name,\n query: new Query(entity.content, entity.context),\n});\n\nexport type ScriptEntity = {\n content: string;\n context: string[];\n createdAt: string;\n createdBy: string;\n id: string;\n modifiedAt: string;\n modifiedBy: string;\n name: string;\n};\n\nexport type ScriptPatchableProperties = {\n name?: ScriptProperties[\"name\"];\n query?: ScriptProperties[\"query\"];\n};\n\nexport type ScriptProperties = ReturnType<typeof scriptEntityToProperties>;\n\nexport const createScriptPatchedFields = (properties: ScriptPatchableProperties) => {\n const patchedFields = {} as {\n name?: string;\n content?: string;\n context?: string[];\n };\n if (properties.name) {\n patchedFields.name = properties.name;\n }\n if (properties.query) {\n patchedFields.content = properties.query.sql;\n patchedFields.context = properties.query.context;\n }\n return patchedFields;\n};\n\nexport const saveScript = (id: string, config: SonarV3Config) => (body: Record<string, any>) => {\n return config\n .sonarV3Request(`scripts/${id}`, {\n body: JSON.stringify(body),\n headers: {\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"PATCH\",\n })\n .map((response) => response.json() as Promise<ScriptEntity>)\n .mapErr((err) => {\n if (\n err.body instanceof Problem &&\n err.body.detail?.includes(\"Cannot reuse the same script name\")\n ) {\n return duplicateScriptNameError(body[\"name\"]);\n }\n return err;\n });\n};\n"]}
@@ -1,19 +1,7 @@
1
- export declare const scriptNotFoundError: (id: string) => {
2
- readonly meta: {
3
- readonly provided: {
4
- readonly id: string;
5
- };
1
+ import { Problem, ValidationProblem } from "../../common/Problem.js";
2
+ export declare const scriptNotFoundError: (id: string) => Problem<"https://api.dremio.dev/problems/scripts/not-found", {
3
+ provided: {
4
+ id: string;
6
5
  };
7
- readonly title: "The script could not be found or you do not have permission to view it";
8
- readonly type: "https://api.dremio.dev/problems/scripts/not-found";
9
- };
10
- export declare const duplicateScriptNameError: (name: string) => {
11
- readonly errors: [{
12
- readonly detail: "A script with this name already exists";
13
- readonly pointer: "#/name";
14
- readonly type: "https://api.dremio.dev/problems/validation/field-conflict";
15
- readonly value: string;
16
- }];
17
- readonly title: "There was a problem validating the content of the request";
18
- readonly type: "https://api.dremio.dev/problems/validation-problem";
19
- };
6
+ }>;
7
+ export declare const duplicateScriptNameError: (name: string) => ValidationProblem;