@dremio/js-sdk 0.17.0 → 0.19.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.
- package/dist/common/Config.d.ts +6 -0
- package/dist/common/Config.js.map +1 -1
- package/dist/common/createRequest.js +57 -12
- package/dist/common/createRequest.js.map +1 -1
- package/dist/enterprise/roles/Role.d.ts +23 -7
- package/dist/enterprise/roles/Role.js +23 -0
- package/dist/enterprise/roles/Role.js.map +1 -1
- package/dist/enterprise/roles/RolesResource.d.ts +7 -0
- package/dist/enterprise/roles/RolesResource.js +19 -0
- package/dist/enterprise/roles/RolesResource.js.map +1 -1
- package/dist/oss/jobs/Job.d.ts +1 -1
- package/dist/oss/jobs/Job.js.map +1 -1
- package/package.json +1 -1
package/dist/common/Config.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ export type Config = {
|
|
|
23
23
|
* Required unless using a custom `fetch` provider with its own credentials provision
|
|
24
24
|
*/
|
|
25
25
|
credentials?: CredentialProvider;
|
|
26
|
+
/**
|
|
27
|
+
* Configure the maximum number of times to retry requests that failed due to a
|
|
28
|
+
* temporary condition such as 429 or 503. Default is 10. Set to 0 to disable
|
|
29
|
+
* automatic retry.
|
|
30
|
+
*/
|
|
31
|
+
maxRetryCount?: number;
|
|
26
32
|
};
|
|
27
33
|
/**
|
|
28
34
|
* @hidden
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../../src/common/Config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AsyncResult } from \"ts-results-es\";\nimport type { CredentialProvider } from \"./CredentialProvider.ts\";\nimport type { HttpError } from \"./HttpError.ts\";\n\nexport type RequestFn = (input: string, init?: RequestInit) => AsyncResult<Response, HttpError>;\n\nexport type Config = {\n /**\n * Custom `fetch` provider\n * @default globalThis.fetch\n */\n fetch?: (input: string, init?: RequestInit) => Promise<Response>;\n\n /**\n * Dremio API base origin\n */\n origin: string;\n\n logger?: {\n debug: typeof console.debug;\n error: typeof console.error;\n info: typeof console.info;\n warn: typeof console.warn;\n };\n\n /**\n * Provides credentials to Dremio for all authenticated API requests.\n * Required unless using a custom `fetch` provider with its own credentials provision\n */\n credentials?: CredentialProvider;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type ResourceConfig = {\n logger?: Config[\"logger\"];\n origin: Config[\"origin\"];\n request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type SonarV2Config = {\n sonarV2Request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type SonarV3Config = {\n sonarV3Request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type SonarV4Config = {\n sonarV4Request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type V3Config = {\n v3Request: RequestFn;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"Config.js","sourceRoot":"","sources":["../../src/common/Config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AsyncResult } from \"ts-results-es\";\nimport type { CredentialProvider } from \"./CredentialProvider.ts\";\nimport type { HttpError } from \"./HttpError.ts\";\n\nexport type RequestFn = (input: string, init?: RequestInit) => AsyncResult<Response, HttpError>;\n\nexport type Config = {\n /**\n * Custom `fetch` provider\n * @default globalThis.fetch\n */\n fetch?: (input: string, init?: RequestInit) => Promise<Response>;\n\n /**\n * Dremio API base origin\n */\n origin: string;\n\n logger?: {\n debug: typeof console.debug;\n error: typeof console.error;\n info: typeof console.info;\n warn: typeof console.warn;\n };\n\n /**\n * Provides credentials to Dremio for all authenticated API requests.\n * Required unless using a custom `fetch` provider with its own credentials provision\n */\n credentials?: CredentialProvider;\n\n /**\n * Configure the maximum number of times to retry requests that failed due to a\n * temporary condition such as 429 or 503. Default is 10. Set to 0 to disable\n * automatic retry.\n */\n maxRetryCount?: number;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type ResourceConfig = {\n logger?: Config[\"logger\"];\n origin: Config[\"origin\"];\n request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type SonarV2Config = {\n sonarV2Request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type SonarV3Config = {\n sonarV3Request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type SonarV4Config = {\n sonarV4Request: RequestFn;\n};\n\n/**\n * @hidden\n * @internal\n */\nexport type V3Config = {\n v3Request: RequestFn;\n};\n"]}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { AsyncResult, Err, Ok } from "ts-results-es";
|
|
16
|
+
import { AsyncResult, Err, Ok, Result } from "ts-results-es";
|
|
17
17
|
import { HttpError } from "./HttpError.js";
|
|
18
18
|
const getHeadersFromConfig = async (config) => {
|
|
19
19
|
if (config.credentials) {
|
|
@@ -29,18 +29,63 @@ const getHeadersFromConfig = async (config) => {
|
|
|
29
29
|
*/
|
|
30
30
|
export const createRequest = (config) => {
|
|
31
31
|
const fetch = config.fetch || globalThis.fetch;
|
|
32
|
+
const MAX_RETRIES = config.maxRetryCount ?? 10;
|
|
32
33
|
return function request(input, init) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
const startFetch = async (triesRemaining) => {
|
|
35
|
+
const start = performance.now();
|
|
36
|
+
return fetch(new URL(input, config.origin), {
|
|
37
|
+
...init,
|
|
38
|
+
headers: { ...(await getHeadersFromConfig(config)), ...init?.headers },
|
|
39
|
+
}).then(async (res) => {
|
|
40
|
+
config.logger?.debug(`${init?.method?.toUpperCase() || "GET"} ${input} (${res.status}) [${Math.round(performance.now() - start)}ms]`);
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
if (isRetryableResponse(res) && triesRemaining > 0) {
|
|
43
|
+
const retryWait = getRetryWait(res, triesRemaining, MAX_RETRIES);
|
|
44
|
+
config.logger?.warn(`${init?.method?.toUpperCase() || "GET"} ${input} (${res.status}) [Retrying in ${retryWait}ms]`);
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, retryWait));
|
|
46
|
+
return startFetch(triesRemaining - 1);
|
|
47
|
+
}
|
|
48
|
+
return Err(await HttpError.fromResponse(res));
|
|
49
|
+
}
|
|
50
|
+
return Ok(res);
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return new AsyncResult(startFetch(MAX_RETRIES));
|
|
44
54
|
};
|
|
45
55
|
};
|
|
56
|
+
const getRetryWait = (res, triesRemaining, maxRetries) => {
|
|
57
|
+
const retryAfter = res.headers.get("retry-after");
|
|
58
|
+
if (retryAfter) {
|
|
59
|
+
return parseRetryAfter(retryAfter);
|
|
60
|
+
}
|
|
61
|
+
return Math.min(MAX_RETRY_INTERVAL, 2 ** (maxRetries - triesRemaining) * 1000 + 6000);
|
|
62
|
+
};
|
|
63
|
+
const isRetryableResponse = (res) => {
|
|
64
|
+
return res.status === 429 || res.status === 502 || res.status === 503;
|
|
65
|
+
};
|
|
66
|
+
const parseRetryAfter = (retryAfter) => {
|
|
67
|
+
// Try parsing as the <delay-seconds> format
|
|
68
|
+
const nval = Number(retryAfter);
|
|
69
|
+
if (Number.isFinite(nval)) {
|
|
70
|
+
return Math.min(MAX_RETRY_WAIT, Math.max(0, nval * 1000));
|
|
71
|
+
}
|
|
72
|
+
// Try parsing as the <http-date> format
|
|
73
|
+
const retryDateMs = Date.parse(retryAfter);
|
|
74
|
+
// This case is hit when value couldn't be parsed as a number or date
|
|
75
|
+
if (Number.isNaN(retryDateMs)) {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
// Return the number of millseconds between target date and now
|
|
79
|
+
return Math.min(MAX_RETRY_WAIT, Math.max(0, retryDateMs - Date.now()));
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* There really shouldn't be a case where the client needs to wait longer than
|
|
83
|
+
* five minutes before retrying a request, so if the API requests a longer retry
|
|
84
|
+
* interval, ignore it.
|
|
85
|
+
*/
|
|
86
|
+
const MAX_RETRY_WAIT = 300_000;
|
|
87
|
+
/**
|
|
88
|
+
* When no retry-after is provided, cap the retry interval to 30 seconds.
|
|
89
|
+
*/
|
|
90
|
+
const MAX_RETRY_INTERVAL = 30_000;
|
|
46
91
|
//# sourceMappingURL=createRequest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRequest.js","sourceRoot":"","sources":["../../src/common/createRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"createRequest.js","sourceRoot":"","sources":["../../src/common/createRequest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAc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CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAAC,GAAa,EAAE,EAAE;IAC5C,OAAO,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC;AACxE,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CAAC,UAAkB,EAAU,EAAE;IACrD,4CAA4C;IAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAEhC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,wCAAwC;IACxC,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAE3C,qEAAqE;IACrE,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,CAAC,CAAC;IACX,CAAC;IAED,+DAA+D;IAC/D,OAAO,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;AACzE,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B;;GAEG;AACH,MAAM,kBAAkB,GAAG,MAAM,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 { AsyncResult, Err, Ok, Result } from \"ts-results-es\";\nimport type { Config, RequestFn } from \"./Config.ts\";\nimport { HttpError } from \"./HttpError.ts\";\n\nconst getHeadersFromConfig = async (config: Config): Promise<RequestInit[\"headers\"]> => {\n if (config.credentials) {\n return {\n Authorization: `Bearer ${await config.credentials.get(config)}`,\n };\n }\n return {};\n};\n\n/**\n * @internal\n * @hidden\n */\nexport const createRequest = (config: Config): RequestFn => {\n const fetch = (config.fetch as typeof globalThis.fetch) || globalThis.fetch;\n const MAX_RETRIES = config.maxRetryCount ?? 10;\n\n return function request(input: string, init?: RequestInit) {\n const startFetch = async (triesRemaining: number): Promise<Result<Response, HttpError>> => {\n const start = performance.now();\n\n return fetch(new URL(input, config.origin), {\n ...init,\n headers: { ...(await getHeadersFromConfig(config)), ...init?.headers },\n }).then(async (res) => {\n config.logger?.debug(\n `${init?.method?.toUpperCase() || \"GET\"} ${input} (${res.status}) [${Math.round(performance.now() - start)}ms]`,\n );\n\n if (!res.ok) {\n if (isRetryableResponse(res) && triesRemaining > 0) {\n const retryWait = getRetryWait(res, triesRemaining, MAX_RETRIES);\n config.logger?.warn(\n `${init?.method?.toUpperCase() || \"GET\"} ${input} (${res.status}) [Retrying in ${retryWait}ms]`,\n );\n await new Promise((resolve) => setTimeout(resolve, retryWait));\n return startFetch(triesRemaining - 1);\n }\n return Err(await HttpError.fromResponse(res));\n }\n\n return Ok(res);\n });\n };\n\n return new AsyncResult(startFetch(MAX_RETRIES));\n };\n};\n\nconst getRetryWait = (res: Response, triesRemaining: number, maxRetries: number) => {\n const retryAfter = res.headers.get(\"retry-after\");\n\n if (retryAfter) {\n return parseRetryAfter(retryAfter);\n }\n\n return Math.min(MAX_RETRY_INTERVAL, 2 ** (maxRetries - triesRemaining) * 1000 + 6000);\n};\n\nconst isRetryableResponse = (res: Response) => {\n return res.status === 429 || res.status === 502 || res.status === 503;\n};\n\nconst parseRetryAfter = (retryAfter: string): number => {\n // Try parsing as the <delay-seconds> format\n const nval = Number(retryAfter);\n\n if (Number.isFinite(nval)) {\n return Math.min(MAX_RETRY_WAIT, Math.max(0, nval * 1000));\n }\n\n // Try parsing as the <http-date> format\n const retryDateMs = Date.parse(retryAfter);\n\n // This case is hit when value couldn't be parsed as a number or date\n if (Number.isNaN(retryDateMs)) {\n return 0;\n }\n\n // Return the number of millseconds between target date and now\n return Math.min(MAX_RETRY_WAIT, Math.max(0, retryDateMs - Date.now()));\n};\n\n/**\n * There really shouldn't be a case where the client needs to wait longer than\n * five minutes before retrying a request, so if the API requests a longer retry\n * interval, ignore it.\n */\nconst MAX_RETRY_WAIT = 300_000;\n\n/**\n * When no retry-after is provided, cap the retry interval to 30 seconds.\n */\nconst MAX_RETRY_INTERVAL = 30_000;\n"]}
|
|
@@ -6,18 +6,34 @@ export declare class Role implements RoleProperties {
|
|
|
6
6
|
readonly roles: RoleProperties["roles"];
|
|
7
7
|
readonly type: RoleProperties["type"];
|
|
8
8
|
constructor(properties: RoleProperties);
|
|
9
|
-
static fromResource(properties:
|
|
9
|
+
static fromResource(properties: RoleEntity): Role;
|
|
10
|
+
}
|
|
11
|
+
export declare class RoleReference {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
/**
|
|
15
|
+
* Origin of the role
|
|
16
|
+
*/
|
|
17
|
+
readonly type: RoleEntity["type"];
|
|
18
|
+
constructor(properties: {
|
|
19
|
+
id: RoleReference["id"];
|
|
20
|
+
name: RoleReference["name"];
|
|
21
|
+
type: RoleReference["type"];
|
|
22
|
+
});
|
|
10
23
|
}
|
|
11
|
-
export type RoleReference = {
|
|
12
|
-
id: string;
|
|
13
|
-
name: string;
|
|
14
|
-
type: string;
|
|
15
|
-
};
|
|
16
24
|
export type RoleProperties = {
|
|
17
25
|
readonly description: string | null;
|
|
18
26
|
readonly id: string;
|
|
19
27
|
readonly memberCount: number;
|
|
20
28
|
readonly name: string;
|
|
21
29
|
readonly roles: RoleReference[];
|
|
22
|
-
readonly type:
|
|
30
|
+
readonly type: RoleEntity["type"];
|
|
31
|
+
};
|
|
32
|
+
export type RoleEntity = {
|
|
33
|
+
id: string;
|
|
34
|
+
name: string;
|
|
35
|
+
type: "INTERNAL" | "EXTERNAL" | "SYSTEM";
|
|
36
|
+
roles: RoleEntity[];
|
|
37
|
+
memberCount: number;
|
|
38
|
+
description: string;
|
|
23
39
|
};
|
|
@@ -23,16 +23,39 @@ export class Role {
|
|
|
23
23
|
constructor(properties) {
|
|
24
24
|
this.description = properties.description;
|
|
25
25
|
this.id = properties.id;
|
|
26
|
+
/**
|
|
27
|
+
* Number of users and roles that are members of the role
|
|
28
|
+
*/
|
|
26
29
|
this.memberCount = properties.memberCount;
|
|
27
30
|
this.name = properties.name;
|
|
31
|
+
/**
|
|
32
|
+
* Information about the roles to which the role belong
|
|
33
|
+
*/
|
|
28
34
|
this.roles = properties.roles;
|
|
35
|
+
/**
|
|
36
|
+
* Origin of the role
|
|
37
|
+
*/
|
|
29
38
|
this.type = properties.type;
|
|
30
39
|
}
|
|
31
40
|
static fromResource(properties) {
|
|
32
41
|
return new Role({
|
|
33
42
|
...properties,
|
|
34
43
|
description: properties.description?.length ? properties.description : null,
|
|
44
|
+
roles: properties.roles.map((roleReferenceEntity) => new RoleReference(roleReferenceEntity)),
|
|
35
45
|
});
|
|
36
46
|
}
|
|
37
47
|
}
|
|
48
|
+
export class RoleReference {
|
|
49
|
+
id;
|
|
50
|
+
name;
|
|
51
|
+
/**
|
|
52
|
+
* Origin of the role
|
|
53
|
+
*/
|
|
54
|
+
type;
|
|
55
|
+
constructor(properties) {
|
|
56
|
+
this.id = properties.id;
|
|
57
|
+
this.name = properties.name;
|
|
58
|
+
this.type = properties.type;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
38
61
|
//# sourceMappingURL=Role.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Role.js","sourceRoot":"","sources":["../../../src/enterprise/roles/Role.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,OAAO,IAAI;IACN,WAAW,CAAgC;IAC3C,EAAE,CAAuB;IACzB,WAAW,CAAgC;IAC3C,IAAI,CAAyB;IAC7B,KAAK,CAA0B;IAC/B,IAAI,CAAyB;IAEtC,YAAY,UAA0B;QACpC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"Role.js","sourceRoot":"","sources":["../../../src/enterprise/roles/Role.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,OAAO,IAAI;IACN,WAAW,CAAgC;IAC3C,EAAE,CAAuB;IACzB,WAAW,CAAgC;IAC3C,IAAI,CAAyB;IAC7B,KAAK,CAA0B;IAC/B,IAAI,CAAyB;IAEtC,YAAY,UAA0B;QACpC,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QAExB;;WAEG;QACH,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAE1C,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAE5B;;WAEG;QACH,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC;QAE9B;;WAEG;QACH,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,UAAsB;QACxC,OAAO,IAAI,IAAI,CAAC;YACd,GAAG,UAAU;YACb,WAAW,EAAE,UAAU,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI;YAC3E,KAAK,EAAE,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,mBAAmB,EAAE,EAAE,CAAC,IAAI,aAAa,CAAC,mBAAmB,CAAC,CAAC;SAC7F,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,OAAO,aAAa;IACf,EAAE,CAAS;IACX,IAAI,CAAS;IAEtB;;OAEG;IACM,IAAI,CAAqB;IAElC,YAAY,UAIX;QACC,IAAI,CAAC,EAAE,GAAG,UAAU,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;IAC9B,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\nexport class Role implements RoleProperties {\n readonly description: RoleProperties[\"description\"];\n readonly id: RoleProperties[\"id\"];\n readonly memberCount: RoleProperties[\"memberCount\"];\n readonly name: RoleProperties[\"name\"];\n readonly roles: RoleProperties[\"roles\"];\n readonly type: RoleProperties[\"type\"];\n\n constructor(properties: RoleProperties) {\n this.description = properties.description;\n this.id = properties.id;\n\n /**\n * Number of users and roles that are members of the role\n */\n this.memberCount = properties.memberCount;\n\n this.name = properties.name;\n\n /**\n * Information about the roles to which the role belong\n */\n this.roles = properties.roles;\n\n /**\n * Origin of the role\n */\n this.type = properties.type;\n }\n\n static fromResource(properties: RoleEntity) {\n return new Role({\n ...properties,\n description: properties.description?.length ? properties.description : null,\n roles: properties.roles.map((roleReferenceEntity) => new RoleReference(roleReferenceEntity)),\n });\n }\n}\n\nexport class RoleReference {\n readonly id: string;\n readonly name: string;\n\n /**\n * Origin of the role\n */\n readonly type: RoleEntity[\"type\"];\n\n constructor(properties: {\n id: RoleReference[\"id\"];\n name: RoleReference[\"name\"];\n type: RoleReference[\"type\"];\n }) {\n this.id = properties.id;\n this.name = properties.name;\n this.type = properties.type;\n }\n}\n\nexport type RoleProperties = {\n readonly description: string | null;\n readonly id: string;\n readonly memberCount: number;\n readonly name: string;\n readonly roles: RoleReference[];\n readonly type: RoleEntity[\"type\"];\n};\n\nexport type RoleEntity = {\n id: string;\n name: string;\n type: \"INTERNAL\" | \"EXTERNAL\" | \"SYSTEM\";\n roles: RoleEntity[];\n memberCount: number;\n description: string;\n};\n"]}
|
|
@@ -4,6 +4,13 @@ import type { SignalParam } from "../../common/Params.ts";
|
|
|
4
4
|
export declare class RolesResource {
|
|
5
5
|
#private;
|
|
6
6
|
constructor(config: SonarV3Config);
|
|
7
|
+
list(): {
|
|
8
|
+
data(): AsyncGenerator<Role, void, unknown>;
|
|
9
|
+
getPage: ({ signal }?: SignalParam) => import("ts-results-es").AsyncResult<{
|
|
10
|
+
data: Role[];
|
|
11
|
+
totalResults: number;
|
|
12
|
+
}, import("../index.ts").HttpError>;
|
|
13
|
+
};
|
|
7
14
|
retrieve(id: string, { signal }?: SignalParam): Promise<import("ts-results-es").Result<Role, import("../index.ts").HttpError>>;
|
|
8
15
|
retrieveByName(name: string, { signal }?: SignalParam): Promise<import("ts-results-es").Result<Role, import("../index.ts").HttpError>>;
|
|
9
16
|
}
|
|
@@ -19,6 +19,25 @@ export class RolesResource {
|
|
|
19
19
|
constructor(config) {
|
|
20
20
|
this.#config = config;
|
|
21
21
|
}
|
|
22
|
+
list() {
|
|
23
|
+
const getPage = ({ signal } = {}) => this.#config
|
|
24
|
+
.sonarV3Request("role", { signal })
|
|
25
|
+
.map((res) => res.json())
|
|
26
|
+
.map((response) => {
|
|
27
|
+
return {
|
|
28
|
+
...response,
|
|
29
|
+
data: response.data.map((entity) => Role.fromResource(entity)),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
async *data() {
|
|
34
|
+
yield* await getPage()
|
|
35
|
+
.map((v) => v.data)
|
|
36
|
+
.promise.then((result) => result.unwrap());
|
|
37
|
+
},
|
|
38
|
+
getPage,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
22
41
|
retrieve(id, { signal } = {}) {
|
|
23
42
|
return this.#config
|
|
24
43
|
.sonarV3Request(`role/${id}`, { signal })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RolesResource.js","sourceRoot":"","sources":["../../../src/enterprise/roles/RolesResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,IAAI,
|
|
1
|
+
{"version":3,"file":"RolesResource.js","sourceRoot":"","sources":["../../../src/enterprise/roles/RolesResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,IAAI,EAAmB,MAAM,WAAW,CAAC;AAGlD,MAAM,OAAO,aAAa;IACxB,OAAO,CAAgB;IAEvB,YAAY,MAAqB;QAC/B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,IAAI;QACF,MAAM,OAAO,GAAG,CAAC,EAAE,MAAM,KAAkB,EAAE,EAAE,EAAE,CAC/C,IAAI,CAAC,OAAO;aACT,cAAc,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC;aAClC,GAAG,CACF,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,CAAC,IAAI,EAGN,CACL;aACA,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;YAChB,OAAO;gBACL,GAAG,QAAQ;gBACX,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;aAC/D,CAAC;QACJ,CAAC,CAAC,CAAC;QACP,OAAO;YACL,KAAK,CAAC,CAAC,IAAI;gBACT,KAAK,CAAC,CAAC,MAAM,OAAO,EAAE;qBACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;qBAClB,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YAC/C,CAAC;YACD,OAAO;SACR,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,EAAU,EAAE,EAAE,MAAM,KAAkB,EAAE;QAC/C,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,EAAE,CAAC;aACxB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;IAChE,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,EAAE,CAAC;aACxB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;IAChE,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 { Role, type RoleEntity } from \"./Role.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\n\nexport class RolesResource {\n #config: SonarV3Config;\n\n constructor(config: SonarV3Config) {\n this.#config = config;\n }\n\n list() {\n const getPage = ({ signal }: SignalParam = {}) =>\n this.#config\n .sonarV3Request(\"role\", { signal })\n .map(\n (res) =>\n res.json() as Promise<{\n data: RoleEntity[];\n totalResults: number;\n }>,\n )\n .map((response) => {\n return {\n ...response,\n data: response.data.map((entity) => Role.fromResource(entity)),\n };\n });\n return {\n async *data() {\n yield* await getPage()\n .map((v) => v.data)\n .promise.then((result) => result.unwrap());\n },\n getPage,\n };\n }\n\n retrieve(id: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`role/${id}`, { signal })\n .map((res) => res.json())\n .map((properties) => Role.fromResource(properties)).promise;\n }\n\n retrieveByName(name: string, { signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`role/by-name/${name}`, { signal })\n .map((res) => res.json())\n .map((properties) => Role.fromResource(properties)).promise;\n }\n}\n"]}
|
package/dist/oss/jobs/Job.d.ts
CHANGED
package/dist/oss/jobs/Job.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,EAAE,EAAE,SAAS,EAAmB,MAAM,MAAM,CAAC;AAE1E,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAKnD,MAAM,OAAO,GAAG;IACL,YAA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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\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\n readonly errorMessage?: string;\n readonly endedAt: JobProperties[\"endedAt\"];\n readonly id: JobProperties[\"id\"];\n readonly problem: JobProperties[\"problem\"];\n readonly queryType: JobProperties[\"queryType\"];\n readonly resourceSchedulingEndedAt: JobProperties[\"resourceSchedulingEndedAt\"];\n readonly resourceSchedulingStartedAt: JobProperties[\"resourceSchedulingStartedAt\"];\n readonly rowCount: JobProperties[\"rowCount\"];\n readonly startedAt: JobProperties[\"startedAt\"];\n readonly state: JobProperties[\"state\"];\n\n public readonly observer: Observable<Job>;\n #config: SonarV3Config;\n\n constructor(\n properties: JobProperties,\n config: SonarV3Config,\n observe: (id: string) => Observable<Result<Job, HttpError>>,\n ) {\n this.acceleration = properties.acceleration;\n this.cancellationReason = properties.cancellationReason;\n this.endedAt = properties.endedAt;\n this.id = properties.id;\n this.problem = properties.problem;\n this.queryType = properties.queryType;\n this.resourceSchedulingEndedAt = properties.resourceSchedulingEndedAt;\n this.resourceSchedulingStartedAt = properties.resourceSchedulingStartedAt;\n this.rowCount = properties.rowCount;\n this.startedAt = properties.startedAt;\n this.state = properties.state;\n this.#config = config;\n this.observer = of(this).pipe(\n switchMap((job) => {\n if (!job.settled) {\n return observe(this.id).pipe(\n map((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n );\n } else {\n return of(job);\n }\n }),\n );\n\n if (properties.errorMessage) {\n this.errorMessage = properties.errorMessage;\n }\n }\n\n get settled() {\n return (\n this.state === \"COMPLETED\" ||\n this.state === \"FAILED\" ||\n this.state === \"INVALID_STATE\" ||\n this.state === \"CANCELED\"\n );\n }\n\n get results() {\n return {\n jsonBatches: this.#jsonBatches.bind(this),\n metadata: this.#metadata.bind(this),\n slice: this.#slice.bind(this),\n };\n }\n\n /**\n * @returns A `Job` instance once it's reached a settled state\n */\n retrieveSettled() {\n return lastValueFrom(this.observer);\n }\n\n async *#jsonBatches<T extends Record<string, unknown> = Record<string, unknown>>(\n args: { limit?: number; offset?: number } = {},\n { signal }: SignalParam = {},\n ) {\n if (typeof args.limit === \"number\" && args.limit < 0) {\n throw new Error(\"Limit cannot be negative\");\n }\n\n if (typeof args.offset === \"number\" && args.offset < 0) {\n throw new Error(\"Offset cannot be negative\");\n }\n\n // Wait for job to enter a settled state before attempting to fetch batches\n if (!this.settled) {\n await this.retrieveSettled();\n }\n\n const limitArg = args.limit ?? Infinity;\n const offsetArg = args.offset || 0;\n\n // Tracks whether there are more rows available from the job results endpoint\n let hasMore = true;\n\n // Tracks the currently requested offset. If the offset arg is provided, start from there instead of 0.\n let offset = offsetArg;\n\n // Keeps track of the total number of rows that need to be loaded\n const stopAfterOffset = limitArg + offsetArg;\n\n while (hasMore && offset < stopAfterOffset) {\n // Make batch_size dynamic to allow for requesting a smaller final page\n const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);\n\n const batch = (\n await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse<T>>).promise\n ).unwrap();\n\n offset += batch.rows.length;\n hasMore = batch.rows.length === batch_size;\n\n if (batch.rows.length) {\n const schema = { fields: batch.schema };\n mapRowData(batch.rows, batch.schema);\n yield {\n get columns() {\n return mapRowsToColumns(batch);\n },\n rows: batch.rows,\n schema,\n totalRows: batch.rowCount,\n } as const;\n }\n }\n }\n\n async #metadata({ signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse>)\n .map((response) => ({\n schema: response.schema,\n totalRows: response.rowCount,\n })).promise;\n }\n\n async #slice<T extends Record<string, unknown> = Record<string, unknown>>(\n start: number = 0,\n end: number = Infinity,\n { signal }: SignalParam = {},\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>(\n { limit: end - start, offset: start },\n { signal },\n )) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .map(() => undefined).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
|
|
1
|
+
{"version":3,"file":"Job.js","sourceRoot":"","sources":["../../../src/oss/jobs/Job.ts"],"names":[],"mappings":"AAAA;;;;;;;;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AAE,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,SAAiB,CAAC,CAAC,OAAO,CAAC;IAC1C,CAAC;CACF;AAED,MAAM,cAAc,GAAG,GAAG,CAAC","sourcesContent":["/*\n * Copyright (C) 2024-2025 Dremio Corporation\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { SonarV3Config } from \"../../common/Config.ts\";\nimport { Err, Ok, Result } from \"ts-results-es\";\nimport { lastValueFrom, map, of, switchMap, type Observable } from \"rxjs\";\nimport type { JobResultsResponse } from \"./utils/JobResultsResponse.ts\";\nimport { mapRowsToColumns } from \"./utils/mapRowsToColumns.ts\";\nimport { mapRowData } from \"./utils/mapRowData.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport type { JobProperties } from \"./utils/jobEntityToProperties.ts\";\nimport type { HttpError } from \"../../common/HttpError.ts\";\n\nexport class Job {\n readonly acceleration: JobProperties[\"acceleration\"];\n readonly cancellationReason: JobProperties[\"cancellationReason\"];\n readonly errorMessage?: string;\n readonly endedAt: JobProperties[\"endedAt\"];\n readonly id: JobProperties[\"id\"];\n readonly problem: JobProperties[\"problem\"];\n readonly queryType: JobProperties[\"queryType\"];\n readonly resourceSchedulingEndedAt: JobProperties[\"resourceSchedulingEndedAt\"];\n readonly resourceSchedulingStartedAt: JobProperties[\"resourceSchedulingStartedAt\"];\n readonly rowCount: JobProperties[\"rowCount\"];\n readonly startedAt: JobProperties[\"startedAt\"];\n readonly state: JobProperties[\"state\"];\n\n public readonly observer: Observable<Job>;\n #config: SonarV3Config;\n\n constructor(\n properties: JobProperties,\n config: SonarV3Config,\n observe: (id: string) => Observable<Result<Job, HttpError>>,\n ) {\n this.acceleration = properties.acceleration;\n this.cancellationReason = properties.cancellationReason;\n this.endedAt = properties.endedAt;\n this.id = properties.id;\n this.problem = properties.problem;\n this.queryType = properties.queryType;\n this.resourceSchedulingEndedAt = properties.resourceSchedulingEndedAt;\n this.resourceSchedulingStartedAt = properties.resourceSchedulingStartedAt;\n this.rowCount = properties.rowCount;\n this.startedAt = properties.startedAt;\n this.state = properties.state;\n this.#config = config;\n this.observer = of(this).pipe(\n switchMap((job) => {\n if (!job.settled) {\n return observe(this.id).pipe(\n map((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n );\n } else {\n return of(job);\n }\n }),\n );\n\n if (properties.errorMessage) {\n this.errorMessage = properties.errorMessage;\n }\n }\n\n get settled() {\n return (\n this.state === \"COMPLETED\" ||\n this.state === \"FAILED\" ||\n this.state === \"INVALID_STATE\" ||\n this.state === \"CANCELED\"\n );\n }\n\n get results() {\n return {\n jsonBatches: this.#jsonBatches.bind(this),\n metadata: this.#metadata.bind(this),\n slice: this.#slice.bind(this),\n };\n }\n\n /**\n * @returns A `Job` instance once it's reached a settled state\n */\n retrieveSettled() {\n return lastValueFrom(this.observer);\n }\n\n async *#jsonBatches<T extends Record<string, unknown> = Record<string, unknown>>(\n args: { limit?: number; offset?: number } = {},\n { signal }: SignalParam = {},\n ) {\n if (typeof args.limit === \"number\" && args.limit < 0) {\n throw new Error(\"Limit cannot be negative\");\n }\n\n if (typeof args.offset === \"number\" && args.offset < 0) {\n throw new Error(\"Offset cannot be negative\");\n }\n\n // Wait for job to enter a settled state before attempting to fetch batches\n if (!this.settled) {\n await this.retrieveSettled();\n }\n\n const limitArg = args.limit ?? Infinity;\n const offsetArg = args.offset || 0;\n\n // Tracks whether there are more rows available from the job results endpoint\n let hasMore = true;\n\n // Tracks the currently requested offset. If the offset arg is provided, start from there instead of 0.\n let offset = offsetArg;\n\n // Keeps track of the total number of rows that need to be loaded\n const stopAfterOffset = limitArg + offsetArg;\n\n while (hasMore && offset < stopAfterOffset) {\n // Make batch_size dynamic to allow for requesting a smaller final page\n const batch_size = Math.min(MAX_BATCH_SIZE, stopAfterOffset - offset);\n\n const batch = (\n await this.#config\n .sonarV3Request(`job/${this.id}/results?offset=${offset}&limit=${batch_size}`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse<T>>).promise\n ).unwrap();\n\n offset += batch.rows.length;\n hasMore = batch.rows.length === batch_size;\n\n if (batch.rows.length) {\n const schema = { fields: batch.schema };\n mapRowData(batch.rows, batch.schema);\n yield {\n get columns() {\n return mapRowsToColumns(batch);\n },\n rows: batch.rows,\n schema,\n totalRows: batch.rowCount,\n } as const;\n }\n }\n }\n\n async #metadata({ signal }: SignalParam = {}) {\n return this.#config\n .sonarV3Request(`job/${this.id}/results?offset=0&limit=0`, { signal })\n .map((res) => res.json() as Promise<JobResultsResponse>)\n .map((response) => ({\n schema: response.schema,\n totalRows: response.rowCount,\n })).promise;\n }\n\n async #slice<T extends Record<string, unknown> = Record<string, unknown>>(\n start: number = 0,\n end: number = Infinity,\n { signal }: SignalParam = {},\n ) {\n try {\n const rows: T[] = [];\n for await (const batch of this.#jsonBatches<T>(\n { limit: end - start, offset: start },\n { signal },\n )) {\n rows.push(...batch.rows);\n }\n return Ok(rows);\n } catch (e: unknown) {\n return Err(e);\n }\n }\n\n cancel() {\n return this.#config\n .sonarV3Request(`job/${this.id}/cancel`, {\n keepalive: true,\n method: \"POST\",\n })\n .map(() => undefined as void).promise;\n }\n}\n\nconst MAX_BATCH_SIZE = 500;\n"]}
|