@dremio/js-sdk 0.36.2 → 0.37.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/cloud/ai/AIResource.d.ts +1 -1
- package/dist/cloud/ai/AIResource.js +2 -2
- package/dist/cloud/ai/AIResource.js.map +1 -1
- package/dist/cloud/catalog/EnterpriseCatalogResource.d.ts +5 -0
- package/dist/cloud/catalog/EnterpriseCatalogResource.js +17 -0
- package/dist/cloud/catalog/EnterpriseCatalogResource.js.map +1 -1
- package/package.json +1 -1
|
@@ -66,7 +66,7 @@ export declare class AIResource {
|
|
|
66
66
|
tag: string;
|
|
67
67
|
}> | undefined>;
|
|
68
68
|
listModelProviders(): {
|
|
69
|
-
data(): AsyncGenerator<import("ts-results-es").Ok<ModelProvider | DremioModelProvider> | import("ts-results-es").Err<z.core.$ZodError<{
|
|
69
|
+
data({ signal }?: SignalParam): AsyncGenerator<import("ts-results-es").Ok<ModelProvider | DremioModelProvider> | import("ts-results-es").Err<z.core.$ZodError<{
|
|
70
70
|
name: string;
|
|
71
71
|
id: string;
|
|
72
72
|
tag: string;
|
|
@@ -64,8 +64,8 @@ export class AIResource {
|
|
|
64
64
|
}));
|
|
65
65
|
};
|
|
66
66
|
return {
|
|
67
|
-
async *data() {
|
|
68
|
-
yield* (await getPage().promise).map((response) => response.data).unwrap();
|
|
67
|
+
async *data({ signal } = {}) {
|
|
68
|
+
yield* (await getPage({ signal }).promise).map((response) => response.data).unwrap();
|
|
69
69
|
},
|
|
70
70
|
getPage,
|
|
71
71
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIResource.js","sourceRoot":"","sources":["../../../src/cloud/ai/AIResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAEtE,OAAO,EAAE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F,CAAC;aACD,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAyD,CAAC;aAC/E,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;OAGG;IACH,eAAe,CAAC,WAAwB;QACtC,OAAO,CAAC,WAA4B,EAAE,EAAE,CACtC,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CACjC,IAAI,CAAC,OAAO;aACT,cAAc,CAAC,OAAO,EAAE;YACvB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,WAAW,CAAC,QAAQ,EAAE;gBAC/B,SAAS,EAAE,WAAW,CAAC,SAAS;aAKjC,CAAC;YACF,OAAO,EAAE;gBACP,MAAM,EAAE,mBAAmB;gBAC3B,cAAc,EAAE,kBAAkB;aACnC;YACD,MAAM,EAAE,MAAM;YACd,MAAM;SACP,CAAC;aACD,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YACvB,IAAI,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;gBACnB,MAAM,MAAM,CAAC,KAAK,CAAC;YACrB,CAAC;YACD,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC,CAAC,CACL,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/E,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 { map } from \"rxjs\";\nimport { ChatSession } from \"../../enterprise/ai/chat/ChatSession.ts\";\nimport type { UserChatMessage } from \"../../enterprise/ai/chat/UserChatMessage.ts\";\nimport { AgentChatResponse } from \"../../enterprise/ai/chat/AgentChatResponse.ts\";\nimport type { Logger, SonarV4Config, V4Config } from \"../../common/Config.ts\";\nimport { fromTextEventStream } from \"../../common/fromTextEventStream.ts\";\nimport { ModelProvider } from \"../../enterprise/ai/ModelProvider.ts\";\nimport * as z from \"zod/mini\";\nimport {\n dremioProvidedSchema,\n modelProviderCreateCodec,\n modelProviderRetrieveCodec,\n safeDecodeModelProvider,\n type SafeDecodeResultWithoutDremioLLM,\n} from \"./modelProviderCodec.js\";\nimport { modelProviderRetrieveCodec as baseModelProviderRetrieveCodec } from \"../../enterprise/ai/modelProviderCodec.ts\";\nimport { DremioModelProvider } from \"./DremioModelProvider.ts\";\nimport { safeParseResultToResult } from \"../../common/safeParseResultToResult.ts\";\nimport { listAvailableModels } from \"../../enterprise/ai/AIResource.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\n\nexport class AIResource {\n #config: Logger & V4Config & SonarV4Config;\n\n constructor(config: Logger & V4Config & SonarV4Config) {\n this.#config = config;\n }\n\n createModelProvider(properties: z.output<typeof modelProviderCreateCodec>) {\n const body = z.encode(modelProviderCreateCodec, properties);\n return this.#config\n .v4Request(`model-provider/config`, {\n body: JSON.stringify(body),\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .andThen(\n (entity) =>\n safeDecodeModelProvider(this.#config, entity) as SafeDecodeResultWithoutDremioLLM,\n );\n }\n\n listModelProviders() {\n const getPage = ({ signal }: SignalParam = {}) => {\n return this.#config\n .v4Request(\"model-provider/config\", {\n headers: {\n Accept: \"application/json\",\n },\n signal,\n })\n .map(\n (res) => res.json() as Promise<{ configs: z.input<typeof modelProviderRetrieveCodec>[] }>,\n )\n .map((response) => ({\n data: response.configs.map((entity) =>\n safeParseResultToResult(z.safeDecode(modelProviderRetrieveCodec, entity)).map(\n (properties) => {\n if (\"dremioProvided\" in properties.config) {\n return new DremioModelProvider(\n this.#config,\n properties as z.infer<typeof dremioProvidedSchema>,\n );\n }\n return new ModelProvider(\n this.#config,\n properties as z.output<typeof baseModelProviderRetrieveCodec>,\n );\n },\n ),\n ),\n }));\n };\n return {\n async *data({ signal }: SignalParam = {}) {\n yield* (await getPage({ signal }).promise).map((response) => response.data).unwrap();\n },\n getPage,\n };\n }\n\n listAvailableModels(...args: Parameters<ReturnType<typeof listAvailableModels>>) {\n return listAvailableModels(this.#config)(...args);\n }\n\n retrieveModelProvider(id: string) {\n return this.#config\n .v4Request(`model-provider/config/${id}`, {\n headers: {\n Accept: \"application/json\",\n },\n })\n .map((res) => res.json() as Promise<z.input<typeof modelProviderRetrieveCodec>>)\n .andThen((entity) => safeDecodeModelProvider(this.#config, entity));\n }\n\n /**\n * Sends a chat message to the Dremio AI Agent and returns an Observable containing\n * Agent replies.\n */\n sendChatMessage(chatSession: ChatSession) {\n return (chatMessage: UserChatMessage) =>\n fromTextEventStream(({ signal }) =>\n this.#config\n .sonarV4Request(\"agent\", {\n body: JSON.stringify({\n message: chatMessage.toString(),\n sessionId: chatSession.sessionId,\n } satisfies {\n message: string;\n modelProviderId?: string;\n sessionId?: string;\n }),\n headers: {\n Accept: \"text/event-stream\",\n \"Content-Type\": \"application/json\",\n },\n method: \"POST\",\n signal,\n })\n .promise.then((result) => {\n if (result.isErr()) {\n throw result.error;\n }\n return result.value;\n }),\n ).pipe(map((event) => AgentChatResponse.fromJSON(JSON.parse(event.data))));\n }\n}\n"]}
|
|
@@ -14,6 +14,11 @@ export declare class EnterpriseCatalogResource {
|
|
|
14
14
|
list(): {
|
|
15
15
|
data(): AsyncGenerator<EnterpriseFunctionCatalogReference | EnterpriseHomeCatalogReference | EnterpriseSourceCatalogReference | EnterpriseSpaceCatalogReference, void, unknown>;
|
|
16
16
|
};
|
|
17
|
+
copyFromObjectStore({ extension, path, sourceName, }: {
|
|
18
|
+
extension: z.infer<typeof uploadExtensionSchema>;
|
|
19
|
+
path: string[];
|
|
20
|
+
sourceName: string;
|
|
21
|
+
}): AsyncResult<FileUpload, import("../index.ts").HttpError>;
|
|
17
22
|
upload(fileStream: ReadableStream, extension: z.infer<typeof uploadExtensionSchema>): AsyncResult<FileUpload, import("../index.ts").HttpError>;
|
|
18
23
|
uploadXHR(file: Blob, extension: z.infer<typeof uploadExtensionSchema>, options?: {
|
|
19
24
|
onProgress?: (e: ProgressEvent<XMLHttpRequestEventTarget>) => void;
|
|
@@ -43,6 +43,23 @@ export class EnterpriseCatalogResource {
|
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
+
copyFromObjectStore({ extension, path, sourceName, }) {
|
|
47
|
+
return this.#config
|
|
48
|
+
.sonarV3Request(`uploads/${sourceName}`, {
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
extension,
|
|
51
|
+
pathComponents: path,
|
|
52
|
+
}),
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: "text/plain",
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
},
|
|
57
|
+
keepalive: true,
|
|
58
|
+
method: "POST",
|
|
59
|
+
})
|
|
60
|
+
.map((res) => res.text())
|
|
61
|
+
.map((id) => new FileUpload(this.#config, id));
|
|
62
|
+
}
|
|
46
63
|
upload(fileStream, extension) {
|
|
47
64
|
return new AsyncResult((async () => {
|
|
48
65
|
const body = new FormData();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnterpriseCatalogResource.js","sourceRoot":"","sources":["../../../src/cloud/catalog/EnterpriseCatalogResource.ts"],"names":[],"mappings":"AAAA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,IAAI,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;gBAC5C,OAAO,aAAa,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC;oBACzC,MAAM,cAAc,GAAG,MAAM,OAAO,CAAC,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC;oBACnF,IAAI,cAAc,CAAC,KAAK,EAAE,EAAE,CAAC;wBAC3B,MAAM,cAAc,CAAC,KAAK,CAAC;oBAC7B,CAAC;oBACD,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC;oBACtC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;oBACrB,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC;gBACzC,CAAC;YACH,CAAC;YACD,OAAO;SACR,CAAC;IACJ,CAAC;IAED,2BAA2B,CAAC,MAAe;QACzC,OAAO,8BAA8B,CACnC,kCAAkC,CAAC,MAAM,CAAC,EAC1C,IAAI,CAAC,OAAO,EACZ,IAAI,CAAC,cAAc,CACpB,CAAC;IACJ,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 { AsyncResult } from \"ts-results-es\";\nimport type { SonarV2Config, SonarV3Config, XHRConfig } from \"../../common/Config.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { catalogReferenceFromProperties } from \"../../enterprise/catalog/catalogReferenceFromProperties.ts\";\nimport { baseRetrieve, baseRetrieveByPath } from \"../../enterprise/catalog/catalogRetrieve.js\";\nimport type { CatalogSearchParams } from \"../../enterprise/catalog/catalogSearch/CatalogSearchParams.ts\";\nimport { createCatalogSearch } from \"../../enterprise/catalog/catalogSearch/createCatalogSearch.js\";\nimport { catalogReferenceEntityToProperties } from \"../../oss/catalog/CatalogReferences/utils/catalogReferenceEntityToProperties.ts\";\nimport type {\n EnterpriseFunctionCatalogReference,\n EnterpriseHomeCatalogReference,\n EnterpriseSourceCatalogReference,\n EnterpriseSpaceCatalogReference,\n} from \"../interfaces.ts\";\nimport { FileUpload, uploadExtensionSchema } from \"./FileUpload.ts\";\nimport * as z from \"zod/mini\";\n\nexport class EnterpriseCatalogResource {\n #config: SonarV2Config & SonarV3Config & XHRConfig;\n #catalogSearch: ReturnType<typeof createCatalogSearch>;\n\n retrieve: ReturnType<typeof baseRetrieve>;\n retrieveByPath: ReturnType<typeof baseRetrieveByPath>;\n\n constructor(config: SonarV2Config & SonarV3Config & XHRConfig) {\n this.#config = config;\n this.retrieve = baseRetrieve(config);\n this.retrieveByPath = baseRetrieveByPath(config);\n this.#catalogSearch = createCatalogSearch(\n this.#config,\n this._catalogReferenceFromEntity.bind(this),\n );\n }\n\n list() {\n const getRoot = () =>\n this.#config\n .sonarV3Request(\"catalog\")\n .map((res) => res.json() as Promise<{ data: unknown[] }>)\n .map((response) =>\n response.data.map(\n (entity: unknown) =>\n catalogReferenceFromProperties(\n catalogReferenceEntityToProperties(entity),\n this.#config,\n this.retrieveByPath,\n ) as\n | EnterpriseFunctionCatalogReference\n | EnterpriseHomeCatalogReference\n | EnterpriseSourceCatalogReference\n | EnterpriseSpaceCatalogReference,\n ),\n )\n .promise.then((result) => result.unwrap());\n return {\n async *data() {\n yield* await getRoot();\n },\n };\n }\n\n upload(fileStream: ReadableStream, extension: z.infer<typeof uploadExtensionSchema>) {\n return new AsyncResult(\n (async () => {\n const body = new FormData();\n body.set(\"file\", await new Response(fileStream).blob());\n body.set(\"extension\", extension);\n\n return this.#config\n .sonarV3Request(\"uploads\", {\n body,\n headers: {\n Accept: \"text/plain\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.text())\n .map((id) => new FileUpload(this.#config, id)).promise;\n })(),\n );\n }\n\n uploadXHR(\n file: Blob,\n extension: z.infer<typeof uploadExtensionSchema>,\n options: { onProgress?: (e: ProgressEvent<XMLHttpRequestEventTarget>) => void } = {},\n ) {\n const body = new FormData();\n body.set(\"file\", file);\n body.set(\"extension\", extension);\n return this.#config\n .xhr(\n \"POST\",\n this.#config.sonarV3URL(\"uploads\").toString(),\n { Accept: \"text/plain\" },\n body,\n (xhr) => {\n if (typeof options.onProgress === \"function\") {\n xhr.upload.addEventListener(\"progress\", options.onProgress);\n }\n },\n )\n .map((xhr) => {\n if (typeof options.onProgress === \"function\") {\n xhr.upload.removeEventListener(\"progress\", options.onProgress);\n }\n return new FileUpload(this.#config, xhr.responseText);\n });\n }\n\n search(params: CatalogSearchParams) {\n const getPage = ({ pageParam, signal }: { pageParam?: string } & SignalParam = {}) =>\n this.#catalogSearch(params, { pageParam, signal });\n return {\n async *data({ signal }: SignalParam = {}) {\n const firstPageResult = await getPage({ signal }).promise;\n if (firstPageResult.isErr()) {\n throw firstPageResult.error;\n }\n const firstPage = firstPageResult.value;\n yield* firstPage.data;\n let nextPageToken = firstPage.nextPageToken;\n while (nextPageToken && !signal?.aborted) {\n const nextPageResult = await getPage({ pageParam: nextPageToken, signal }).promise;\n if (nextPageResult.isErr()) {\n throw nextPageResult.error;\n }\n const nextPage = nextPageResult.value;\n yield* nextPage.data;\n nextPageToken = nextPage.nextPageToken;\n }\n },\n getPage,\n };\n }\n\n _catalogReferenceFromEntity(entity: unknown) {\n return catalogReferenceFromProperties(\n catalogReferenceEntityToProperties(entity),\n this.#config,\n this.retrieveByPath,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"EnterpriseCatalogResource.js","sourceRoot":"","sources":["../../../src/cloud/catalog/EnterpriseCatalogResource.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,WAA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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 } from \"ts-results-es\";\nimport type { SonarV2Config, SonarV3Config, XHRConfig } from \"../../common/Config.ts\";\nimport type { SignalParam } from \"../../common/Params.ts\";\nimport { catalogReferenceFromProperties } from \"../../enterprise/catalog/catalogReferenceFromProperties.ts\";\nimport { baseRetrieve, baseRetrieveByPath } from \"../../enterprise/catalog/catalogRetrieve.js\";\nimport type { CatalogSearchParams } from \"../../enterprise/catalog/catalogSearch/CatalogSearchParams.ts\";\nimport { createCatalogSearch } from \"../../enterprise/catalog/catalogSearch/createCatalogSearch.js\";\nimport { catalogReferenceEntityToProperties } from \"../../oss/catalog/CatalogReferences/utils/catalogReferenceEntityToProperties.ts\";\nimport type {\n EnterpriseFunctionCatalogReference,\n EnterpriseHomeCatalogReference,\n EnterpriseSourceCatalogReference,\n EnterpriseSpaceCatalogReference,\n} from \"../interfaces.ts\";\nimport { FileUpload, uploadExtensionSchema } from \"./FileUpload.ts\";\nimport * as z from \"zod/mini\";\n\nexport class EnterpriseCatalogResource {\n #config: SonarV2Config & SonarV3Config & XHRConfig;\n #catalogSearch: ReturnType<typeof createCatalogSearch>;\n\n retrieve: ReturnType<typeof baseRetrieve>;\n retrieveByPath: ReturnType<typeof baseRetrieveByPath>;\n\n constructor(config: SonarV2Config & SonarV3Config & XHRConfig) {\n this.#config = config;\n this.retrieve = baseRetrieve(config);\n this.retrieveByPath = baseRetrieveByPath(config);\n this.#catalogSearch = createCatalogSearch(\n this.#config,\n this._catalogReferenceFromEntity.bind(this),\n );\n }\n\n list() {\n const getRoot = () =>\n this.#config\n .sonarV3Request(\"catalog\")\n .map((res) => res.json() as Promise<{ data: unknown[] }>)\n .map((response) =>\n response.data.map(\n (entity: unknown) =>\n catalogReferenceFromProperties(\n catalogReferenceEntityToProperties(entity),\n this.#config,\n this.retrieveByPath,\n ) as\n | EnterpriseFunctionCatalogReference\n | EnterpriseHomeCatalogReference\n | EnterpriseSourceCatalogReference\n | EnterpriseSpaceCatalogReference,\n ),\n )\n .promise.then((result) => result.unwrap());\n return {\n async *data() {\n yield* await getRoot();\n },\n };\n }\n\n copyFromObjectStore({\n extension,\n path,\n sourceName,\n }: {\n extension: z.infer<typeof uploadExtensionSchema>;\n path: string[];\n sourceName: string;\n }) {\n return this.#config\n .sonarV3Request(`uploads/${sourceName}`, {\n body: JSON.stringify({\n extension,\n pathComponents: path,\n }),\n headers: {\n Accept: \"text/plain\",\n \"Content-Type\": \"application/json\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.text())\n .map((id) => new FileUpload(this.#config, id));\n }\n\n upload(fileStream: ReadableStream, extension: z.infer<typeof uploadExtensionSchema>) {\n return new AsyncResult(\n (async () => {\n const body = new FormData();\n body.set(\"file\", await new Response(fileStream).blob());\n body.set(\"extension\", extension);\n\n return this.#config\n .sonarV3Request(\"uploads\", {\n body,\n headers: {\n Accept: \"text/plain\",\n },\n keepalive: true,\n method: \"POST\",\n })\n .map((res) => res.text())\n .map((id) => new FileUpload(this.#config, id)).promise;\n })(),\n );\n }\n\n uploadXHR(\n file: Blob,\n extension: z.infer<typeof uploadExtensionSchema>,\n options: { onProgress?: (e: ProgressEvent<XMLHttpRequestEventTarget>) => void } = {},\n ) {\n const body = new FormData();\n body.set(\"file\", file);\n body.set(\"extension\", extension);\n return this.#config\n .xhr(\n \"POST\",\n this.#config.sonarV3URL(\"uploads\").toString(),\n { Accept: \"text/plain\" },\n body,\n (xhr) => {\n if (typeof options.onProgress === \"function\") {\n xhr.upload.addEventListener(\"progress\", options.onProgress);\n }\n },\n )\n .map((xhr) => {\n if (typeof options.onProgress === \"function\") {\n xhr.upload.removeEventListener(\"progress\", options.onProgress);\n }\n return new FileUpload(this.#config, xhr.responseText);\n });\n }\n\n search(params: CatalogSearchParams) {\n const getPage = ({ pageParam, signal }: { pageParam?: string } & SignalParam = {}) =>\n this.#catalogSearch(params, { pageParam, signal });\n return {\n async *data({ signal }: SignalParam = {}) {\n const firstPageResult = await getPage({ signal }).promise;\n if (firstPageResult.isErr()) {\n throw firstPageResult.error;\n }\n const firstPage = firstPageResult.value;\n yield* firstPage.data;\n let nextPageToken = firstPage.nextPageToken;\n while (nextPageToken && !signal?.aborted) {\n const nextPageResult = await getPage({ pageParam: nextPageToken, signal }).promise;\n if (nextPageResult.isErr()) {\n throw nextPageResult.error;\n }\n const nextPage = nextPageResult.value;\n yield* nextPage.data;\n nextPageToken = nextPage.nextPageToken;\n }\n },\n getPage,\n };\n }\n\n _catalogReferenceFromEntity(entity: unknown) {\n return catalogReferenceFromProperties(\n catalogReferenceEntityToProperties(entity),\n this.#config,\n this.retrieveByPath,\n );\n }\n}\n"]}
|