@milaboratories/pl-drivers 1.13.1 → 1.14.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 (141) hide show
  1. package/dist/clients/download.cjs +5 -3
  2. package/dist/clients/download.cjs.map +1 -1
  3. package/dist/clients/download.d.ts.map +1 -1
  4. package/dist/clients/download.js +6 -4
  5. package/dist/clients/download.js.map +1 -1
  6. package/dist/clients/logs.cjs +10 -6
  7. package/dist/clients/logs.cjs.map +1 -1
  8. package/dist/clients/logs.d.ts.map +1 -1
  9. package/dist/clients/logs.js +11 -7
  10. package/dist/clients/logs.js.map +1 -1
  11. package/dist/clients/ls_api.cjs +5 -3
  12. package/dist/clients/ls_api.cjs.map +1 -1
  13. package/dist/clients/ls_api.js +6 -4
  14. package/dist/clients/ls_api.js.map +1 -1
  15. package/dist/clients/progress.cjs +7 -3
  16. package/dist/clients/progress.cjs.map +1 -1
  17. package/dist/clients/progress.d.ts.map +1 -1
  18. package/dist/clients/progress.js +8 -4
  19. package/dist/clients/progress.js.map +1 -1
  20. package/dist/clients/upload.cjs +22 -12
  21. package/dist/clients/upload.cjs.map +1 -1
  22. package/dist/clients/upload.d.ts.map +1 -1
  23. package/dist/clients/upload.js +23 -13
  24. package/dist/clients/upload.js.map +1 -1
  25. package/dist/drivers/download_blob/blob_key.cjs +3 -2
  26. package/dist/drivers/download_blob/blob_key.cjs.map +1 -1
  27. package/dist/drivers/download_blob/blob_key.js +3 -2
  28. package/dist/drivers/download_blob/blob_key.js.map +1 -1
  29. package/dist/drivers/download_blob/download_blob.cjs.map +1 -1
  30. package/dist/drivers/download_blob/download_blob.js.map +1 -1
  31. package/dist/drivers/download_blob_url/driver.cjs +2 -1
  32. package/dist/drivers/download_blob_url/driver.cjs.map +1 -1
  33. package/dist/drivers/download_blob_url/driver.d.ts +2 -2
  34. package/dist/drivers/download_blob_url/driver.d.ts.map +1 -1
  35. package/dist/drivers/download_blob_url/driver.js +3 -2
  36. package/dist/drivers/download_blob_url/driver.js.map +1 -1
  37. package/dist/drivers/download_blob_url/driver_id.cjs +4 -1
  38. package/dist/drivers/download_blob_url/driver_id.cjs.map +1 -1
  39. package/dist/drivers/download_blob_url/driver_id.js +3 -1
  40. package/dist/drivers/download_blob_url/driver_id.js.map +1 -1
  41. package/dist/drivers/download_url/task.cjs +1 -1
  42. package/dist/drivers/download_url/task.cjs.map +1 -1
  43. package/dist/drivers/download_url/task.d.ts.map +1 -1
  44. package/dist/drivers/download_url/task.js +1 -1
  45. package/dist/drivers/download_url/task.js.map +1 -1
  46. package/dist/drivers/helpers/download_remote_handle.cjs +7 -4
  47. package/dist/drivers/helpers/download_remote_handle.cjs.map +1 -1
  48. package/dist/drivers/helpers/download_remote_handle.js +8 -5
  49. package/dist/drivers/helpers/download_remote_handle.js.map +1 -1
  50. package/dist/drivers/helpers/logs_handle.cjs +9 -6
  51. package/dist/drivers/helpers/logs_handle.cjs.map +1 -1
  52. package/dist/drivers/helpers/logs_handle.js +10 -7
  53. package/dist/drivers/helpers/logs_handle.js.map +1 -1
  54. package/dist/drivers/helpers/ls_remote_import_handle.cjs +2 -2
  55. package/dist/drivers/helpers/ls_remote_import_handle.cjs.map +1 -1
  56. package/dist/drivers/helpers/ls_remote_import_handle.js +2 -2
  57. package/dist/drivers/helpers/ls_remote_import_handle.js.map +1 -1
  58. package/dist/drivers/helpers/ls_storage_entry.cjs +10 -16
  59. package/dist/drivers/helpers/ls_storage_entry.cjs.map +1 -1
  60. package/dist/drivers/helpers/ls_storage_entry.js +11 -17
  61. package/dist/drivers/helpers/ls_storage_entry.js.map +1 -1
  62. package/dist/drivers/logs_stream.cjs.map +1 -1
  63. package/dist/drivers/logs_stream.js.map +1 -1
  64. package/dist/drivers/ls.cjs +31 -29
  65. package/dist/drivers/ls.cjs.map +1 -1
  66. package/dist/drivers/ls.d.ts +10 -10
  67. package/dist/drivers/ls.d.ts.map +1 -1
  68. package/dist/drivers/ls.js +31 -29
  69. package/dist/drivers/ls.js.map +1 -1
  70. package/dist/drivers/types.cjs.map +1 -1
  71. package/dist/drivers/types.d.ts +2 -1
  72. package/dist/drivers/types.d.ts.map +1 -1
  73. package/dist/drivers/types.js.map +1 -1
  74. package/dist/drivers/upload.cjs.map +1 -1
  75. package/dist/drivers/upload.js.map +1 -1
  76. package/dist/drivers/virtual_storages.cjs +3 -0
  77. package/dist/drivers/virtual_storages.cjs.map +1 -1
  78. package/dist/drivers/virtual_storages.js +3 -0
  79. package/dist/drivers/virtual_storages.js.map +1 -1
  80. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs +2 -2
  81. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.cjs.map +1 -1
  82. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts +2 -2
  83. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.d.ts.map +1 -1
  84. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js +2 -2
  85. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.js.map +1 -1
  86. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs +2 -2
  87. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.cjs.map +1 -1
  88. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.d.ts.map +1 -1
  89. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js +2 -2
  90. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.js.map +1 -1
  91. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs +4 -4
  92. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.cjs.map +1 -1
  93. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts +4 -4
  94. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.d.ts.map +1 -1
  95. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js +4 -4
  96. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.js.map +1 -1
  97. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs +6 -6
  98. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.cjs.map +1 -1
  99. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts +6 -6
  100. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.d.ts.map +1 -1
  101. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js +6 -6
  102. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.js.map +1 -1
  103. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs +10 -10
  104. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.cjs.map +1 -1
  105. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js +10 -10
  106. package/dist/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.js.map +1 -1
  107. package/dist/proto-rest/downloadapi.d.ts +6 -6
  108. package/dist/proto-rest/downloadapi.d.ts.map +1 -1
  109. package/dist/proto-rest/progressapi.d.ts +19 -19
  110. package/dist/proto-rest/progressapi.d.ts.map +1 -1
  111. package/package.json +7 -7
  112. package/src/clients/download.ts +6 -3
  113. package/src/clients/logs.ts +22 -7
  114. package/src/clients/ls_api.ts +6 -4
  115. package/src/clients/progress.ts +18 -4
  116. package/src/clients/upload.ts +31 -14
  117. package/src/drivers/download_blob/blob_key.ts +4 -8
  118. package/src/drivers/download_blob/download_blob.ts +2 -2
  119. package/src/drivers/download_blob_url/driver.ts +10 -5
  120. package/src/drivers/download_blob_url/driver_id.ts +5 -3
  121. package/src/drivers/download_url/task.ts +5 -1
  122. package/src/drivers/helpers/download_remote_handle.ts +16 -5
  123. package/src/drivers/helpers/logs_handle.ts +16 -7
  124. package/src/drivers/helpers/ls_remote_import_handle.ts +2 -2
  125. package/src/drivers/helpers/ls_storage_entry.ts +15 -17
  126. package/src/drivers/logs_stream.ts +5 -5
  127. package/src/drivers/ls.test.ts +4 -4
  128. package/src/drivers/ls.ts +44 -58
  129. package/src/drivers/types.ts +3 -1
  130. package/src/drivers/upload.ts +3 -3
  131. package/src/drivers/virtual_storages.ts +3 -0
  132. package/src/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.ts +7 -6
  133. package/src/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.ts +7 -6
  134. package/src/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.ts +14 -12
  135. package/src/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.ts +21 -18
  136. package/src/proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/uploadapi/protocol.ts +35 -30
  137. package/src/proto-grpc/google/protobuf/descriptor.ts +5 -2
  138. package/src/proto-rest/downloadapi.ts +6 -6
  139. package/src/proto-rest/lsapi.ts +30 -30
  140. package/src/proto-rest/progressapi.ts +21 -21
  141. package/src/proto-rest/uploadapi.ts +41 -41
@@ -79,15 +79,17 @@ var ClientDownload = class {
79
79
  async grpcGetDownloadUrl({ id, type }, options, signal) {
80
80
  const withAbort = options ?? {};
81
81
  withAbort.abort = signal;
82
+ const { globalId, signature } = (0, _milaboratories_pl_client.parseSignedResourceId)(id);
82
83
  const client = this.wire.get();
83
84
  if (client instanceof require_protocol_client.DownloadClient) return await client.getDownloadURL({
84
- resourceId: id,
85
+ resourceId: globalId,
86
+ resourceSignature: signature,
85
87
  isInternalUse: false
86
88
  }, (0, _milaboratories_pl_client.addRTypeToMetadata)(type, withAbort)).response;
87
89
  else return (await client.POST("/v1/get-download-url", {
88
90
  body: {
89
- resourceId: id.toString(),
90
- resourceSignature: "",
91
+ resourceId: globalId.toString(),
92
+ resourceSignature: (0, _milaboratories_pl_client.signatureToBase64Url)(signature),
91
93
  isInternalUse: false
92
94
  },
93
95
  headers: { ...(0, _milaboratories_pl_client.createRTypeRoutingHeader)(type) }
@@ -1 +1 @@
1
- {"version":3,"file":"download.cjs","names":["ConcurrencyLimitingExecutor","DownloadClient","RestAPI","RemoteFileDownloader","PerfTimer","fsp","fs","Readable","path"],"sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n stringifyWithResourceId,\n RestAPI,\n createRTypeRoutingHeader,\n} from \"@milaboratories/pl-client\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\nimport { PerfTimer } from \"@milaboratories/helpers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConcurrencyLimitingExecutor } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport type { Dispatcher } from \"undici\";\nimport type { LocalStorageProjection } from \"../drivers/types\";\nimport { type ContentHandler, RemoteFileDownloader } from \"../helpers/download\";\nimport { validateAbsolute } from \"../helpers/validate\";\nimport type { DownloadAPI_GetDownloadURL_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol\";\nimport { DownloadClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client\";\nimport type { DownloadApiPaths, DownloadRestClientType } from \"../proto-rest\";\nimport { type GetContentOptions } from \"@milaboratories/pl-model-common\";\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {\n if (wireConn.type === \"grpc\") {\n return new DownloadClient(wireConn.Transport);\n } else {\n return RestAPI.createClient<DownloadApiPaths>({\n hostAndPort: wireConn.Config.hostAndPort,\n ssl: wireConn.Config.ssl,\n dispatcher: wireConn.Dispatcher,\n middlewares: wireConn.Middlewares,\n });\n }\n });\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, ` +\n `url: ${downloadUrl}, ` +\n `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, ` + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n const client = this.wire.get();\n if (client instanceof DownloadClient) {\n return await client.getDownloadURL(\n { resourceId: id, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n } else {\n return (\n await client.POST(\"/v1/get-download-url\", {\n body: {\n resourceId: id.toString(),\n resourceSignature: \"\",\n isInternalUse: false,\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!;\n }\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == \"\")\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === \"\") return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = \"storage://\";\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = \"WrongLocalFileUrl\";\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = \"UnknownStorageError\";\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== \"\") {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,IAAa,iBAAb,MAA4B;CAC1B;CACA;;CAGA;;CAGA,uBAAwC,IAAIA,2BAAAA,4BAA4B,GAAG;CAE3E,YACE,2BACA,YACA,QAEA,kBACA;AAJgB,OAAA,aAAA;AACA,OAAA,SAAA;AAIhB,OAAK,OAAO,0BAA0B,0BAA0B,aAAa;AAC3E,OAAI,SAAS,SAAS,OACpB,QAAO,IAAIC,wBAAAA,eAAe,SAAS,UAAU;OAE7C,QAAOC,0BAAAA,QAAQ,aAA+B;IAC5C,aAAa,SAAS,OAAO;IAC7B,KAAK,SAAS,OAAO;IACrB,YAAY,SAAS;IACrB,aAAa,SAAS;IACvB,CAAC;IAEJ;AACF,OAAK,uBAAuB,IAAIC,iBAAAA,qBAAqB,WAAW;AAChE,OAAK,wBAAwB,yBAAyB,iB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kBAAA,iBAAiB,GAAG,UAAU;AAEhC,WAAS,IAAI,GAAG,WAAW,GAAG,UAAU;;AAG1C,QAAO"}
1
+ {"version":3,"file":"download.cjs","names":["ConcurrencyLimitingExecutor","DownloadClient","RestAPI","RemoteFileDownloader","PerfTimer","fsp","fs","Readable","path"],"sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n stringifyWithResourceId,\n RestAPI,\n createRTypeRoutingHeader,\n parseSignedResourceId,\n signatureToBase64Url,\n} from \"@milaboratories/pl-client\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\nimport { PerfTimer } from \"@milaboratories/helpers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConcurrencyLimitingExecutor } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport type { Dispatcher } from \"undici\";\nimport type { LocalStorageProjection } from \"../drivers/types\";\nimport { type ContentHandler, RemoteFileDownloader } from \"../helpers/download\";\nimport { validateAbsolute } from \"../helpers/validate\";\nimport type { DownloadAPI_GetDownloadURL_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol\";\nimport { DownloadClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client\";\nimport type { DownloadApiPaths, DownloadRestClientType } from \"../proto-rest\";\nimport { type GetContentOptions } from \"@milaboratories/pl-model-common\";\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {\n if (wireConn.type === \"grpc\") {\n return new DownloadClient(wireConn.Transport);\n } else {\n return RestAPI.createClient<DownloadApiPaths>({\n hostAndPort: wireConn.Config.hostAndPort,\n ssl: wireConn.Config.ssl,\n dispatcher: wireConn.Dispatcher,\n middlewares: wireConn.Middlewares,\n });\n }\n });\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, ` +\n `url: ${downloadUrl}, ` +\n `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, ` + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n const { globalId, signature } = parseSignedResourceId(id);\n const client = this.wire.get();\n if (client instanceof DownloadClient) {\n return await client.getDownloadURL(\n { resourceId: globalId, resourceSignature: signature, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n } else {\n return (\n await client.POST(\"/v1/get-download-url\", {\n body: {\n resourceId: globalId.toString(),\n resourceSignature: signatureToBase64Url(signature),\n isInternalUse: false,\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!;\n }\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == \"\")\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === \"\") return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = \"storage://\";\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = \"WrongLocalFileUrl\";\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = \"UnknownStorageError\";\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== \"\") {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,IAAa,iBAAb,MAA4B;CAC1B;CACA;;CAGA;;CAGA,uBAAwC,IAAIA,2BAAAA,4BAA4B,GAAG;CAE3E,YACE,2BACA,YACA,QAEA,kBACA;AAJgB,OAAA,aAAA;AACA,OAAA,SAAA;AAIhB,OAAK,OAAO,0BAA0B,0BAA0B,aAAa;AAC3E,OAAI,SAAS,SAAS,OACpB,QAAO,IAAIC,wBAAAA,eAAe,SAAS,UAAU;OAE7C,QAAOC,0BAAAA,QAAQ,aAA+B;IAC5C,aAAa,SAAS,OAAO;IAC7B,KAAK,SAAS,OAAO;IACrB,YAAY,SAAS;IACrB,aAAa,SAAS;IACvB,CAAC;IAEJ;AACF,OAAK,uBAAuB,IAAIC,iBAAAA,qBAAqB,WAAW;AAChE,OAAK,wBAAwB,yBAAyB,iBAAiB;;CAGzE,QAAQ;;;;;;;CAQR,MAAM,gBACJ,MACA,SACA,KACA,SACY;EACZ,MAAM,EAAE,aAAa,YAAY,MAAM,KAAK,mBAAmB,MAAM,SAAS,IAAI,OAAO;EAEzF,MAAM,gBAAgB,OAAO,YAAY,QAAQ,KAAK,EAAE,MAAM,YAAY,CAAC,MAAM,MAAM,C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names":[],"sources":["../../src/clients/download.ts"],"mappings":";;;;;;;;;;;;;;cA4Ba,cAAA;EAAA,SAYO,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,QAAA;EAAA,SAZV,IAAA,EAAM,kBAAA,CAAmB,sBAAA,GAAyB,cAAA;EAAA,iBACjD,oBAAA;EADwB;EAAA,iBAIxB,qBAAA;EAJK;EAAA,iBAOL,oBAAA;cAGf,yBAAA,EAA2B,yBAAA,EACX,UAAA,EAAY,UAAA,EACZ,MAAA,EAAQ,QAAA,EAAA;;EAExB,gBAAA,EAAkB,sBAAA;EAkBpB,KAAA,CAAA;EAUW;;;;;;EAFL,eAAA,GAAA,CACJ,IAAA,EAAM,YAAA,EACN,OAAA,EAAS,UAAA,cACT,GAAA,EAAK,iBAAA,EACL,OAAA,EAAS,gBAAA,CAAe,CAAA,IACvB,OAAA,CAAQ,CAAA;EAqBL,oBAAA,GAAA,CACJ,GAAA,UACA,GAAA,EAAK,iBAAA,EACL,OAAA,EAAS,gBAAA,CAAe,CAAA,IACvB,OAAA,CAAQ,CAAA;EAAA,QA+BG,kBAAA;AAAA;AAAA,iBA6BA,aAAA,CAAc,GAAA;;;;iBAWd,WAAA,CACd,SAAA,UACA,qBAAA,EAAuB,GAAA,kBACvB,YAAA;;cAgBW,iBAAA,SAA0B,KAAA;EACrC,IAAA;AAAA;;cAIW,mBAAA,SAA4B,KAAA;EACvC,IAAA;AAAA;AAAA,iBAGc,wBAAA,CAAyB,WAAA,EAAa,sBAAA,KAAwB,GAAA"}
1
+ {"version":3,"file":"download.d.ts","names":[],"sources":["../../src/clients/download.ts"],"mappings":";;;;;;;;;;;;;;cA8Ba,cAAA;EAAA,SAYO,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,QAAA;EAAA,SAZV,IAAA,EAAM,kBAAA,CAAmB,sBAAA,GAAyB,cAAA;EAAA,iBACjD,oBAAA;EADwB;EAAA,iBAIxB,qBAAA;EAJK;EAAA,iBAOL,oBAAA;cAGf,yBAAA,EAA2B,yBAAA,EACX,UAAA,EAAY,UAAA,EACZ,MAAA,EAAQ,QAAA,EAAA;;EAExB,gBAAA,EAAkB,sBAAA;EAkBpB,KAAA,CAAA;EAUW;;;;;;EAFL,eAAA,GAAA,CACJ,IAAA,EAAM,YAAA,EACN,OAAA,EAAS,UAAA,cACT,GAAA,EAAK,iBAAA,EACL,OAAA,EAAS,gBAAA,CAAe,CAAA,IACvB,OAAA,CAAQ,CAAA;EAqBL,oBAAA,GAAA,CACJ,GAAA,UACA,GAAA,EAAK,iBAAA,EACL,OAAA,EAAS,gBAAA,CAAe,CAAA,IACvB,OAAA,CAAQ,CAAA;EAAA,QA+BG,kBAAA;AAAA;AAAA,iBA8BA,aAAA,CAAc,GAAA;;;;iBAWd,WAAA,CACd,SAAA,UACA,qBAAA,EAAuB,GAAA,kBACvB,YAAA;;cAgBW,iBAAA,SAA0B,KAAA;EACrC,IAAA;AAAA;;cAIW,mBAAA,SAA4B,KAAA;EACvC,IAAA;AAAA;AAAA,iBAGc,wBAAA,CAAyB,WAAA,EAAa,sBAAA,KAAwB,GAAA"}
@@ -1,7 +1,7 @@
1
1
  import { RemoteFileDownloader } from "../helpers/download.js";
2
2
  import { validateAbsolute } from "../helpers/validate.js";
3
3
  import { DownloadClient } from "../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client.js";
4
- import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader, stringifyWithResourceId } from "@milaboratories/pl-client";
4
+ import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader, parseSignedResourceId, signatureToBase64Url, stringifyWithResourceId } from "@milaboratories/pl-client";
5
5
  import * as fsp from "node:fs/promises";
6
6
  import { ConcurrencyLimitingExecutor } from "@milaboratories/ts-helpers";
7
7
  import { PerfTimer } from "@milaboratories/helpers";
@@ -75,15 +75,17 @@ var ClientDownload = class {
75
75
  async grpcGetDownloadUrl({ id, type }, options, signal) {
76
76
  const withAbort = options ?? {};
77
77
  withAbort.abort = signal;
78
+ const { globalId, signature } = parseSignedResourceId(id);
78
79
  const client = this.wire.get();
79
80
  if (client instanceof DownloadClient) return await client.getDownloadURL({
80
- resourceId: id,
81
+ resourceId: globalId,
82
+ resourceSignature: signature,
81
83
  isInternalUse: false
82
84
  }, addRTypeToMetadata(type, withAbort)).response;
83
85
  else return (await client.POST("/v1/get-download-url", {
84
86
  body: {
85
- resourceId: id.toString(),
86
- resourceSignature: "",
87
+ resourceId: globalId.toString(),
88
+ resourceSignature: signatureToBase64Url(signature),
87
89
  isInternalUse: false
88
90
  },
89
91
  headers: { ...createRTypeRoutingHeader(type) }
@@ -1 +1 @@
1
- {"version":3,"file":"download.js","names":["fs","path"],"sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n stringifyWithResourceId,\n RestAPI,\n createRTypeRoutingHeader,\n} from \"@milaboratories/pl-client\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\nimport { PerfTimer } from \"@milaboratories/helpers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConcurrencyLimitingExecutor } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport type { Dispatcher } from \"undici\";\nimport type { LocalStorageProjection } from \"../drivers/types\";\nimport { type ContentHandler, RemoteFileDownloader } from \"../helpers/download\";\nimport { validateAbsolute } from \"../helpers/validate\";\nimport type { DownloadAPI_GetDownloadURL_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol\";\nimport { DownloadClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client\";\nimport type { DownloadApiPaths, DownloadRestClientType } from \"../proto-rest\";\nimport { type GetContentOptions } from \"@milaboratories/pl-model-common\";\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {\n if (wireConn.type === \"grpc\") {\n return new DownloadClient(wireConn.Transport);\n } else {\n return RestAPI.createClient<DownloadApiPaths>({\n hostAndPort: wireConn.Config.hostAndPort,\n ssl: wireConn.Config.ssl,\n dispatcher: wireConn.Dispatcher,\n middlewares: wireConn.Middlewares,\n });\n }\n });\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, ` +\n `url: ${downloadUrl}, ` +\n `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, ` + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n const client = this.wire.get();\n if (client instanceof DownloadClient) {\n return await client.getDownloadURL(\n { resourceId: id, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n } else {\n return (\n await client.POST(\"/v1/get-download-url\", {\n body: {\n resourceId: id.toString(),\n resourceSignature: \"\",\n isInternalUse: false,\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!;\n }\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == \"\")\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === \"\") return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = \"storage://\";\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = \"WrongLocalFileUrl\";\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = \"UnknownStorageError\";\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== \"\") {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,IAAa,iBAAb,MAA4B;CAC1B;CACA;;CAGA;;CAGA,uBAAwC,IAAI,4BAA4B,GAAG;CAE3E,YACE,2BACA,YACA,QAEA,kBACA;AAJgB,OAAA,aAAA;AACA,OAAA,SAAA;AAIhB,OAAK,OAAO,0BAA0B,0BAA0B,aAAa;AAC3E,OAAI,SAAS,SAAS,OACpB,QAAO,IAAI,eAAe,SAAS,UAAU;OAE7C,QAAO,QAAQ,aAA+B;IAC5C,aAAa,SAAS,OAAO;IAC7B,KAAK,SAAS,OAAO;IACrB,YAAY,SAAS;IACrB,aAAa,SAAS;IACvB,CAAC;IAEJ;AACF,OAAK,uBAAuB,IAAI,qBAAqB,WAAW;AAChE,OAAK,wBAAwB,yBAAyB,iBAAiB;;CAGzE,QAAQ;;;;;;;CAQR,MAAM,gBACJ,MACA,SACA,KACA,SACY;EACZ,MAAM,EAAE,aAAa,YAAY,MAA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AAM,SAAS,KAAK,KAAK,KAAK;AAC9B,MAAI,kBAAkB,eACpB,QAAO,MAAM,OAAO,eAClB;GAAE,YAAY;GAAI,eAAe;GAAO,EACxC,mBAAmB,MAAM,UAAU,CACpC,CAAC;MAEF,SACE,MAAM,OAAO,KAAK,wBAAwB;GACxC,MAAM;IACJ,YAAY,GAAG,UAAU;IACzB,mBAAmB;IACnB,eAAe;IAChB;GACD,SAAS,EAAE,GAAG,yBAAyB,KAAK,EAAE;GAC/C,CAAC,EACF;;;AAKR,SAAgB,cAAc,KAAa;CACzC,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,KAAI,OAAO,YAAY,GACrB,OAAM,IAAI,kBAAkB,0BAA0B,IAAI,4BAA4B;AAExF,QAAO;EACL,WAAW,OAAO;EAClB,cAAc,mBAAmB,OAAO,SAAS,MAAM,EAAE,CAAC;EAC3D;;AAGH,SAAgB,YACd,WACA,uBACA,cACA;CACA,MAAM,OAAO,sBAAsB,IAAI,UAAU;AACjD,KAAI,SAAS,KAAA,EAAW,OAAM,IAAI,oBAAoB,6BAA6B,YAAY;AAE/F,KAAI,SAAS,GAAI,QAAO;AAExB,QAAOC,OAAK,KAAK,MAAM,aAAa;;AAGtC,MAAM,kBAAkB;AACxB,SAAS,QAAQ,KAAa;AAC5B,QAAO,IAAI,WAAW,gBAAgB;;;AAIxC,IAAa,oBAAb,cAAuC,MAAM;CAC3C,OAAO;;;AAIT,IAAa,sBAAb,cAAyC,MAAM;CAC7C,OAAO;;AAGT,SAAgB,yBAAyB,aAAuC;CAC9E,MAAM,2BAAgC,IAAI,KAAK;AAC/C,MAAK,MAAM,MAAM,aAAa;AAE5B,MAAI,GAAG,cAAc,GACnB,kBAAiB,GAAG,UAAU;AAEhC,WAAS,IAAI,GAAG,WAAW,GAAG,UAAU;;AAG1C,QAAO"}
1
+ {"version":3,"file":"download.js","names":["fs","path"],"sources":["../../src/clients/download.ts"],"sourcesContent":["/* eslint-disable n/no-unsupported-features/node-builtins */\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n stringifyWithResourceId,\n RestAPI,\n createRTypeRoutingHeader,\n parseSignedResourceId,\n signatureToBase64Url,\n} from \"@milaboratories/pl-client\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\nimport { PerfTimer } from \"@milaboratories/helpers\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { ConcurrencyLimitingExecutor } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport * as fs from \"node:fs\";\nimport * as fsp from \"node:fs/promises\";\nimport * as path from \"node:path\";\nimport { Readable } from \"node:stream\";\nimport type { Dispatcher } from \"undici\";\nimport type { LocalStorageProjection } from \"../drivers/types\";\nimport { type ContentHandler, RemoteFileDownloader } from \"../helpers/download\";\nimport { validateAbsolute } from \"../helpers/validate\";\nimport type { DownloadAPI_GetDownloadURL_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol\";\nimport { DownloadClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/downloadapi/protocol.client\";\nimport type { DownloadApiPaths, DownloadRestClientType } from \"../proto-rest\";\nimport { type GetContentOptions } from \"@milaboratories/pl-model-common\";\n\n/** Gets URLs for downloading from pl-core, parses them and reads or downloads\n * files locally and from the web. */\nexport class ClientDownload {\n public readonly wire: WireClientProvider<DownloadRestClientType | DownloadClient>;\n private readonly remoteFileDownloader: RemoteFileDownloader;\n\n /** Helps to find a storage root directory by a storage id from URL scheme. */\n private readonly localStorageIdsToRoot: Map<string, string>;\n\n /** Concurrency limiter for local file reads - limit to 32 parallel reads */\n private readonly localFileReadLimiter = new ConcurrencyLimitingExecutor(32);\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n /** Pl storages available locally */\n localProjections: LocalStorageProjection[],\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wireConn) => {\n if (wireConn.type === \"grpc\") {\n return new DownloadClient(wireConn.Transport);\n } else {\n return RestAPI.createClient<DownloadApiPaths>({\n hostAndPort: wireConn.Config.hostAndPort,\n ssl: wireConn.Config.ssl,\n dispatcher: wireConn.Dispatcher,\n middlewares: wireConn.Middlewares,\n });\n }\n });\n this.remoteFileDownloader = new RemoteFileDownloader(httpClient);\n this.localStorageIdsToRoot = newLocalStorageIdsToRoot(localProjections);\n }\n\n close() {}\n\n /**\n * Gets a presign URL and downloads the file.\n * An optional range with 2 numbers from what byte and to what byte to download can be provided.\n * @param fromBytes - from byte including this byte\n * @param toBytes - to byte excluding this byte\n */\n async withBlobContent<T>(\n info: ResourceInfo,\n options: RpcOptions | undefined,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { downloadUrl, headers } = await this.grpcGetDownloadUrl(info, options, ops.signal);\n\n const remoteHeaders = Object.fromEntries(headers.map(({ name, value }) => [name, value]));\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download started, ` +\n `url: ${downloadUrl}, ` +\n `range: ${JSON.stringify(ops.range ?? null)}`,\n );\n\n const timer = PerfTimer.start();\n const result = isLocal(downloadUrl)\n ? await this.withLocalFileContent(downloadUrl, ops, handler)\n : await this.remoteFileDownloader.withContent(downloadUrl, remoteHeaders, ops, handler);\n\n this.logger.info(\n `blob ${stringifyWithResourceId(info)} download finished, ` + `took: ${timer.elapsed()}`,\n );\n return result;\n }\n\n async withLocalFileContent<T>(\n url: string,\n ops: GetContentOptions,\n handler: ContentHandler<T>,\n ): Promise<T> {\n const { storageId, relativePath } = parseLocalUrl(url);\n const fullPath = getFullPath(storageId, this.localStorageIdsToRoot, relativePath);\n\n return await this.localFileReadLimiter.run(async () => {\n const readOps = {\n start: ops.range?.from,\n end: ops.range?.to !== undefined ? ops.range.to - 1 : undefined,\n signal: ops.signal,\n };\n let stream: fs.ReadStream | undefined;\n let handlerSuccess = false;\n\n try {\n const stat = await fsp.stat(fullPath);\n stream = fs.createReadStream(fullPath, readOps);\n const webStream = Readable.toWeb(stream);\n\n const result = await handler(webStream, stat.size);\n handlerSuccess = true;\n return result;\n } catch (error) {\n // Cleanup on error (including handler errors)\n if (!handlerSuccess && stream && !stream.destroyed) {\n stream.destroy();\n }\n throw error;\n }\n });\n }\n\n private async grpcGetDownloadUrl(\n { id, type }: ResourceInfo,\n options?: RpcOptions,\n signal?: AbortSignal,\n ): Promise<DownloadAPI_GetDownloadURL_Response> {\n const withAbort = options ?? {};\n withAbort.abort = signal;\n\n const { globalId, signature } = parseSignedResourceId(id);\n const client = this.wire.get();\n if (client instanceof DownloadClient) {\n return await client.getDownloadURL(\n { resourceId: globalId, resourceSignature: signature, isInternalUse: false },\n addRTypeToMetadata(type, withAbort),\n ).response;\n } else {\n return (\n await client.POST(\"/v1/get-download-url\", {\n body: {\n resourceId: globalId.toString(),\n resourceSignature: signatureToBase64Url(signature),\n isInternalUse: false,\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!;\n }\n }\n}\n\nexport function parseLocalUrl(url: string) {\n const parsed = new URL(url);\n if (parsed.pathname == \"\")\n throw new WrongLocalFileUrl(`url for local filepath ${url} does not match url scheme`);\n\n return {\n storageId: parsed.host,\n relativePath: decodeURIComponent(parsed.pathname.slice(1)),\n };\n}\n\nexport function getFullPath(\n storageId: string,\n localStorageIdsToRoot: Map<string, string>,\n relativePath: string,\n) {\n const root = localStorageIdsToRoot.get(storageId);\n if (root === undefined) throw new UnknownStorageError(`Unknown storage location: ${storageId}`);\n\n if (root === \"\") return relativePath;\n\n return path.join(root, relativePath);\n}\n\nconst storageProtocol = \"storage://\";\nfunction isLocal(url: string) {\n return url.startsWith(storageProtocol);\n}\n\n/** Throws when a local URL have invalid scheme. */\nexport class WrongLocalFileUrl extends Error {\n name = \"WrongLocalFileUrl\";\n}\n\n/** Happens when a storage for a local file can't be found. */\nexport class UnknownStorageError extends Error {\n name = \"UnknownStorageError\";\n}\n\nexport function newLocalStorageIdsToRoot(projections: LocalStorageProjection[]) {\n const idToRoot: Map<string, string> = new Map();\n for (const lp of projections) {\n // Empty string means no prefix, i.e. any file on this machine can be got from the storage.\n if (lp.localPath !== \"\") {\n validateAbsolute(lp.localPath);\n }\n idToRoot.set(lp.storageId, lp.localPath);\n }\n\n return idToRoot;\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,IAAa,iBAAb,MAA4B;CAC1B;CACA;;CAGA;;CAGA,uBAAwC,IAAI,4BAA4B,GAAG;CAE3E,YACE,2BACA,YACA,QAEA,kBACA;AAJgB,OAAA,aAAA;AACA,OAAA,SAAA;AAIhB,OAAK,OAAO,0BAA0B,0BAA0B,aAAa;AAC3E,OAAI,SAAS,SAAS,OACpB,QAAO,IAAI,eAAe,SAAS,UAAU;OAE7C,QAAO,QAAQ,aAA+B;IAC5C,aAAa,SAAS,OAAO;IAC7B,KAAK,SAAS,OAAO;IACrB,YAAY,SAAS;IACrB,aAAa,SAAS;IACvB,CAAC;IAEJ;AACF,OAAK,uBAAuB,IAAI,qBAAqB,WAAW;AAChE,OAAK,wBAAwB,yBAAyB,iBAAiB;;CAGzE,QAAQ;;;;;;;CAQR,MAAM,gBACJ,MACA,SACA,KACA,SACY;EACZ,MAAM,EAAE,aAAa,YAAY,MAAM,KAAK,mBAAmB,MAAM,SAAS,IAAI,OAAO;EAEzF,MAAM,gBAAgB,OAAO,YAAY,QAAQ,KAAK,EAAE,MAAM,YAAY,CAAC,MAAM,MAAM,CAAC,CAAC;AACzF,OAAK,OAAO,KACV,QAAQ,wBAAwB,KAAK,CAAC,0BAC5B,YAAY,WACV,KAAK,UAAU,IAAI,SAAS,KAAK,GAC9C;EAED,MAAM,QAAQ,UAAU,OAAO;EAC/B,MAAM,SAAS,QAAQ,YAAY,GAC/B,MAAM,KAAK,qBAAqB,aAAa,KAAK,QAAQ,GAC1D,MAAM,KAAK,qBAAqB,YAAY,aAAa,eAAe,KAAK,QAAQ;AAEzF,OAAK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C,MAAM,SAAS,IAAI,IAAI,IAAI;AAC3B,KAAI,OAAO,YAAY,GACrB,OAAM,IAAI,kBAAkB,0BAA0B,IAAI,4BAA4B;AAExF,QAAO;EACL,WAAW,OAAO;EAClB,cAAc,mBAAmB,OAAO,SAAS,MAAM,EAAE,CAAC;EAC3D;;AAGH,SAAgB,YACd,WACA,uBACA,cACA;CACA,MAAM,OAAO,sBAAsB,IAAI,UAAU;AACjD,KAAI,SAAS,KAAA,EAAW,OAAM,IAAI,oBAAoB,6BAA6B,YAAY;AAE/F,KAAI,SAAS,GAAI,QAAO;AAExB,QAAOC,OAAK,KAAK,MAAM,aAAa;;AAGtC,MAAM,kBAAkB;AACxB,SAAS,QAAQ,KAAa;AAC5B,QAAO,IAAI,WAAW,gBAAgB;;;AAIxC,IAAa,oBAAb,cAAuC,MAAM;CAC3C,OAAO;;;AAIT,IAAa,sBAAb,cAAyC,MAAM;CAC7C,OAAO;;AAGT,SAAgB,yBAAyB,aAAuC;CAC9E,MAAM,2BAAgC,IAAI,KAAK;AAC/C,MAAK,MAAM,MAAM,aAAa;AAE5B,MAAI,GAAG,cAAc,GACnB,kBAAiB,GAAG,UAAU;AAEhC,WAAS,IAAI,GAAG,WAAW,GAAG,UAAU;;AAG1C,QAAO"}
@@ -23,17 +23,19 @@ var ClientLogs = class {
23
23
  * the new offset
24
24
  * and the total size of the (currently existing) file. */
25
25
  async lastLines({ id: rId, type: rType }, lineCount, offsetBytes = 0n, searchStr, options) {
26
+ const { globalId: rIdGlobal, signature: rIdSig } = (0, _milaboratories_pl_client.parseSignedResourceId)(rId);
26
27
  const client = this.wire.get();
27
28
  if (client instanceof require_protocol_client.StreamingClient) return (await client.lastLines({
28
- resourceId: rId,
29
+ resourceId: rIdGlobal,
30
+ resourceSignature: rIdSig,
29
31
  lineCount,
30
32
  offset: offsetBytes,
31
33
  search: searchStr
32
34
  }, (0, _milaboratories_pl_client.addRTypeToMetadata)(rType, options))).response;
33
35
  const resp = (await client.POST("/v1/last-lines", {
34
36
  body: {
35
- resourceId: rId.toString(),
36
- resourceSignature: "",
37
+ resourceId: rIdGlobal.toString(),
38
+ resourceSignature: (0, _milaboratories_pl_client.signatureToBase64Url)(rIdSig),
37
39
  lineCount,
38
40
  offset: offsetBytes.toString(),
39
41
  search: searchStr ?? "",
@@ -51,17 +53,19 @@ var ClientLogs = class {
51
53
  * the new offset
52
54
  * and the total size of the (currently existing) file. */
53
55
  async readText({ id: rId, type: rType }, lineCount, offsetBytes = 0n, searchStr, options) {
56
+ const { globalId: rIdGlobal2, signature: rIdSig2 } = (0, _milaboratories_pl_client.parseSignedResourceId)(rId);
54
57
  const client = this.wire.get();
55
58
  if (client instanceof require_protocol_client.StreamingClient) return (await client.readText({
56
- resourceId: (0, _milaboratories_ts_helpers.notEmpty)(rId),
59
+ resourceId: (0, _milaboratories_ts_helpers.notEmpty)(rIdGlobal2),
60
+ resourceSignature: rIdSig2,
57
61
  readLimit: BigInt(lineCount),
58
62
  offset: offsetBytes,
59
63
  search: searchStr
60
64
  }, (0, _milaboratories_pl_client.addRTypeToMetadata)(rType, options))).response;
61
65
  const resp = (await client.POST("/v1/read/text", {
62
66
  body: {
63
- resourceId: rId.toString(),
64
- resourceSignature: "",
67
+ resourceId: rIdGlobal2.toString(),
68
+ resourceSignature: (0, _milaboratories_pl_client.signatureToBase64Url)(rIdSig2),
65
69
  readLimit: lineCount.toString(),
66
70
  offset: offsetBytes.toString(),
67
71
  search: searchStr ?? "",
@@ -1 +1 @@
1
- {"version":3,"file":"logs.cjs","names":["StreamingClient","RestAPI"],"sources":["../../src/clients/logs.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from \"@milaboratories/pl-client\";\nimport type { StreamingAPI_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol\";\nimport { StreamingClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client\";\nimport type { StreamingApiPaths, StreamingRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLogs {\n public readonly wire: WireClientProvider<StreamingRestClientType | StreamingClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new StreamingClient(wire.Transport);\n }\n\n return RestAPI.createClient<StreamingApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** Reads text back and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async lastLines(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the end.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const client = this.wire.get();\n if (client instanceof StreamingClient) {\n return (\n await client.lastLines(\n { resourceId: rId, lineCount: lineCount, offset: offsetBytes, search: searchStr },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/last-lines\", {\n body: {\n resourceId: rId.toString(),\n resourceSignature: \"\",\n lineCount: lineCount,\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n\n /** Reads the file forward and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async readText(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the beginning.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const client = this.wire.get();\n\n if (client instanceof StreamingClient) {\n return (\n await client.readText(\n {\n resourceId: notEmpty(rId),\n readLimit: BigInt(lineCount),\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/read/text\", {\n body: {\n resourceId: rId.toString(),\n resourceSignature: \"\",\n readLimit: lineCount.toString(),\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n}\n"],"mappings":";;;;;AAWA,IAAa,aAAb,MAAwB;CACtB;CAEA,YACE,2BACA,YACA,QACA;AAFgB,OAAA,aAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAIA,wBAAAA,gBAAgB,KAAK,UAAU;AAG5C,UAAOC,0BAAAA,QAAQ,aAAgC;IAC7C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;;;CAKR,MAAa,UACX,EAAE,IAAI,KAAK,MAAM,SACjB,WACA,cAAsB,IACtB,WACA,SACgC;EAChC,MAAM,SAAS,KAAK,KAAK,KAAK;AAC9B,MAAI,kBAAkBD,wBAAAA,gBACpB,SACE,MAAM,OAAO,UACX;GAAE,YAAY;GAAgB;GAAW,QAAQ;GAAa,QAAQ;GAAW,GAAA,GAAA,0BAAA,oBAC9D,OAAO,QAAQ,CACnC,EACD;EAGJ,MAAM,QACJ,MAAM,OAAO,KAAK,kBAAkB;GAClC,MAAM;IACJ,YAAY,IAAI,UAAU;IAC1B,mBAAmB;IACR;IACX,QAAQ,YAAY,UAAU;IAC9B,QAAQ,aAAa;IACrB,UAAU;IACX;GACD,SAAS,EAAE,IAAA,GAAA,0BAAA,0BAA4B,MAAM,EAAE;GAChD,CAAC,EACF;AAEF,SAAO;GACL,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS;GACtC,MAAM,OAAO,KAAK,KAAK;GACvB,WAAW,OAAO,KAAK,UAAU;GAClC;;;;;CAMH,MAAa,SACX,EAAE,IAAI,KAAK,MAAM,SACjB,WACA,cAAsB,IACtB,WACA,SACgC;EAChC,MAAM,SAAS,KAAK,KAAK,KAAK;AAE9B,MAAI,kBAAkBA,wBAAAA,gBACpB,SACE,MAAM,OAAO,SACX;GACE,aAAA,GAAA,2BAAA,UAAqB,IAAI;GACzB,WAAW,OAAO,UAAU;GAC5B,QAAQ;GACR,QAAQ;GACT,GAAA,GAAA,0BAAA,oBACkB,OAAO,QAAQ,CACnC,EACD;EAGJ,MAAM,QACJ,MAAM,OAAO,KAAK,iBAAiB;GACjC,MAAM;IACJ,YAAY,IAAI,UAAU;IAC1B,mBAAmB;IACnB,WAAW,UAAU,UAAU;IAC/B,QAAQ,YAAY,UAAU;IAC9B,QAAQ,aAAa;IACrB,UAAU;IACX;GACD,SAAS,EAAE,IAAA,GAAA,0BAAA,0BAA4B,MAAM,EAAE;GAChD,CAAC,EACF;AAEF,SAAO;GACL,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS;GACtC,MAAM,OAAO,KAAK,KAAK;GACvB,WAAW,OAAO,KAAK,UAAU;GAClC"}
1
+ {"version":3,"file":"logs.cjs","names":["StreamingClient","RestAPI"],"sources":["../../src/clients/logs.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n createRTypeRoutingHeader,\n RestAPI,\n parseSignedResourceId,\n signatureToBase64Url,\n} from \"@milaboratories/pl-client\";\nimport type { StreamingAPI_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol\";\nimport { StreamingClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client\";\nimport type { StreamingApiPaths, StreamingRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLogs {\n public readonly wire: WireClientProvider<StreamingRestClientType | StreamingClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new StreamingClient(wire.Transport);\n }\n\n return RestAPI.createClient<StreamingApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** Reads text back and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async lastLines(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the end.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const { globalId: rIdGlobal, signature: rIdSig } = parseSignedResourceId(rId);\n const client = this.wire.get();\n if (client instanceof StreamingClient) {\n return (\n await client.lastLines(\n {\n resourceId: rIdGlobal,\n resourceSignature: rIdSig,\n lineCount: lineCount,\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/last-lines\", {\n body: {\n resourceId: rIdGlobal.toString(),\n resourceSignature: signatureToBase64Url(rIdSig),\n lineCount: lineCount,\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n\n /** Reads the file forward and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async readText(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the beginning.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const { globalId: rIdGlobal2, signature: rIdSig2 } = parseSignedResourceId(rId);\n const client = this.wire.get();\n\n if (client instanceof StreamingClient) {\n return (\n await client.readText(\n {\n resourceId: notEmpty(rIdGlobal2),\n resourceSignature: rIdSig2,\n readLimit: BigInt(lineCount),\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/read/text\", {\n body: {\n resourceId: rIdGlobal2.toString(),\n resourceSignature: signatureToBase64Url(rIdSig2),\n readLimit: lineCount.toString(),\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n}\n"],"mappings":";;;;;AAiBA,IAAa,aAAb,MAAwB;CACtB;CAEA,YACE,2BACA,YACA,QACA;AAFgB,OAAA,aAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAIA,wBAAAA,gBAAgB,KAAK,UAAU;AAG5C,UAAOC,0BAAAA,QAAQ,a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AAA,oBACkB,OAAO,QAAQ,CACnC,EACD;EAGJ,MAAM,QACJ,MAAM,OAAO,KAAK,iBAAiB;GACjC,MAAM;IACJ,YAAY,WAAW,UAAU;IACjC,oBAAA,GAAA,0BAAA,sBAAwC,QAAQ;IAChD,WAAW,UAAU,UAAU;IAC/B,QAAQ,YAAY,UAAU;IAC9B,QAAQ,aAAa;IACrB,UAAU;IACX;GACD,SAAS,EAAE,IAAA,GAAA,0BAAA,0BAA4B,MAAM,EAAE;GAChD,CAAC,EACF;AAEF,SAAO;GACL,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS;GACtC,MAAM,OAAO,KAAK,KAAK;GACvB,WAAW,OAAO,KAAK,UAAU;GAClC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logs.d.ts","names":[],"sources":["../../src/clients/logs.ts"],"mappings":";;;;;;;;;;cAWa,UAAA;EAAA,SAKO,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,QAAA;EAAA,SALV,IAAA,EAAM,kBAAA,CAAmB,uBAAA,GAA0B,eAAA;cAGjE,yBAAA,EAA2B,yBAAA,EACX,UAAA,EAAY,UAAA,EACZ,MAAA,EAAQ,QAAA;EAgB1B,KAAA,CAAA;EAhB0B;;;EAqBb,SAAA,CAAA;IACT,EAAA,EAAI,GAAA;IAAK,IAAA,EAAM;EAAA,GAAS,YAAA,EAC1B,SAAA,UACA,WAAA;EACA,SAAA,WACA,OAAA,GAAU,UAAA,GACT,OAAA,CAAQ,qBAAA;EA5BmB;;;EA+DjB,QAAA,CAAA;IACT,EAAA,EAAI,GAAA;IAAK,IAAA,EAAM;EAAA,GAAS,YAAA,EAC1B,SAAA,UACA,WAAA;EACA,SAAA,WACA,OAAA,GAAU,UAAA,GACT,OAAA,CAAQ,qBAAA;AAAA"}
1
+ {"version":3,"file":"logs.d.ts","names":[],"sources":["../../src/clients/logs.ts"],"mappings":";;;;;;;;;;cAiBa,UAAA;EAAA,SAKO,UAAA,EAAY,UAAA;EAAA,SACZ,MAAA,EAAQ,QAAA;EAAA,SALV,IAAA,EAAM,kBAAA,CAAmB,uBAAA,GAA0B,eAAA;cAGjE,yBAAA,EAA2B,yBAAA,EACX,UAAA,EAAY,UAAA,EACZ,MAAA,EAAQ,QAAA;EAgB1B,KAAA,CAAA;EAhB0B;;;EAqBb,SAAA,CAAA;IACT,EAAA,EAAI,GAAA;IAAK,IAAA,EAAM;EAAA,GAAS,YAAA,EAC1B,SAAA,UACA,WAAA;EACA,SAAA,WACA,OAAA,GAAU,UAAA,GACT,OAAA,CAAQ,qBAAA;EA5BmB;;;EAsEjB,QAAA,CAAA;IACT,EAAA,EAAI,GAAA;IAAK,IAAA,EAAM;EAAA,GAAS,YAAA,EAC1B,SAAA,UACA,WAAA;EACA,SAAA,WACA,OAAA,GAAU,UAAA,GACT,OAAA,CAAQ,qBAAA;AAAA"}
@@ -1,5 +1,5 @@
1
1
  import { StreamingClient } from "../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client.js";
2
- import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader } from "@milaboratories/pl-client";
2
+ import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader, parseSignedResourceId, signatureToBase64Url } from "@milaboratories/pl-client";
3
3
  import { notEmpty } from "@milaboratories/ts-helpers";
4
4
  //#region src/clients/logs.ts
5
5
  var ClientLogs = class {
@@ -22,17 +22,19 @@ var ClientLogs = class {
22
22
  * the new offset
23
23
  * and the total size of the (currently existing) file. */
24
24
  async lastLines({ id: rId, type: rType }, lineCount, offsetBytes = 0n, searchStr, options) {
25
+ const { globalId: rIdGlobal, signature: rIdSig } = parseSignedResourceId(rId);
25
26
  const client = this.wire.get();
26
27
  if (client instanceof StreamingClient) return (await client.lastLines({
27
- resourceId: rId,
28
+ resourceId: rIdGlobal,
29
+ resourceSignature: rIdSig,
28
30
  lineCount,
29
31
  offset: offsetBytes,
30
32
  search: searchStr
31
33
  }, addRTypeToMetadata(rType, options))).response;
32
34
  const resp = (await client.POST("/v1/last-lines", {
33
35
  body: {
34
- resourceId: rId.toString(),
35
- resourceSignature: "",
36
+ resourceId: rIdGlobal.toString(),
37
+ resourceSignature: signatureToBase64Url(rIdSig),
36
38
  lineCount,
37
39
  offset: offsetBytes.toString(),
38
40
  search: searchStr ?? "",
@@ -50,17 +52,19 @@ var ClientLogs = class {
50
52
  * the new offset
51
53
  * and the total size of the (currently existing) file. */
52
54
  async readText({ id: rId, type: rType }, lineCount, offsetBytes = 0n, searchStr, options) {
55
+ const { globalId: rIdGlobal2, signature: rIdSig2 } = parseSignedResourceId(rId);
53
56
  const client = this.wire.get();
54
57
  if (client instanceof StreamingClient) return (await client.readText({
55
- resourceId: notEmpty(rId),
58
+ resourceId: notEmpty(rIdGlobal2),
59
+ resourceSignature: rIdSig2,
56
60
  readLimit: BigInt(lineCount),
57
61
  offset: offsetBytes,
58
62
  search: searchStr
59
63
  }, addRTypeToMetadata(rType, options))).response;
60
64
  const resp = (await client.POST("/v1/read/text", {
61
65
  body: {
62
- resourceId: rId.toString(),
63
- resourceSignature: "",
66
+ resourceId: rIdGlobal2.toString(),
67
+ resourceSignature: signatureToBase64Url(rIdSig2),
64
68
  readLimit: lineCount.toString(),
65
69
  offset: offsetBytes.toString(),
66
70
  search: searchStr ?? "",
@@ -1 +1 @@
1
- {"version":3,"file":"logs.js","names":[],"sources":["../../src/clients/logs.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from \"@milaboratories/pl-client\";\nimport type { StreamingAPI_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol\";\nimport { StreamingClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client\";\nimport type { StreamingApiPaths, StreamingRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLogs {\n public readonly wire: WireClientProvider<StreamingRestClientType | StreamingClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new StreamingClient(wire.Transport);\n }\n\n return RestAPI.createClient<StreamingApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** Reads text back and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async lastLines(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the end.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const client = this.wire.get();\n if (client instanceof StreamingClient) {\n return (\n await client.lastLines(\n { resourceId: rId, lineCount: lineCount, offset: offsetBytes, search: searchStr },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/last-lines\", {\n body: {\n resourceId: rId.toString(),\n resourceSignature: \"\",\n lineCount: lineCount,\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n\n /** Reads the file forward and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async readText(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the beginning.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const client = this.wire.get();\n\n if (client instanceof StreamingClient) {\n return (\n await client.readText(\n {\n resourceId: notEmpty(rId),\n readLimit: BigInt(lineCount),\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/read/text\", {\n body: {\n resourceId: rId.toString(),\n resourceSignature: \"\",\n readLimit: lineCount.toString(),\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n}\n"],"mappings":";;;;AAWA,IAAa,aAAb,MAAwB;CACtB;CAEA,YACE,2BACA,YACA,QACA;AAFgB,OAAA,aAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAI,gBAAgB,KAAK,UAAU;AAG5C,UAAO,QAAQ,aAAgC;IAC7C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;;;CAKR,MAAa,UACX,EAAE,IAAI,KAAK,MAAM,SACjB,WACA,cAAsB,IACtB,WACA,SACgC;EAChC,MAAM,SAAS,KAAK,KAAK,KAAK;AAC9B,MAAI,kBAAkB,gBACpB,SACE,MAAM,OAAO,UACX;GAAE,YAAY;GAAgB;GAAW,QAAQ;GAAa,QAAQ;GAAW,EACjF,mBAAmB,OAAO,QAAQ,CACnC,EACD;EAGJ,MAAM,QACJ,MAAM,OAAO,KAAK,kBAAkB;GAClC,MAAM;IACJ,YAAY,IAAI,UAAU;IAC1B,mBAAmB;IACR;IACX,QAAQ,YAAY,UAAU;IAC9B,QAAQ,aAAa;IACrB,UAAU;IACX;GACD,SAAS,EAAE,GAAG,yBAAyB,MAAM,EAAE;GAChD,CAAC,EACF;AAEF,SAAO;GACL,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS;GACtC,MAAM,OAAO,KAAK,KAAK;GACvB,WAAW,OAAO,KAAK,UAAU;GAClC;;;;;CAMH,MAAa,SACX,EAAE,IAAI,KAAK,MAAM,SACjB,WACA,cAAsB,IACtB,WACA,SACgC;EAChC,MAAM,SAAS,KAAK,KAAK,KAAK;AAE9B,MAAI,kBAAkB,gBACpB,SACE,MAAM,OAAO,SACX;GACE,YAAY,SAAS,IAAI;GACzB,WAAW,OAAO,UAAU;GAC5B,QAAQ;GACR,QAAQ;GACT,EACD,mBAAmB,OAAO,QAAQ,CACnC,EACD;EAGJ,MAAM,QACJ,MAAM,OAAO,KAAK,iBAAiB;GACjC,MAAM;IACJ,YAAY,IAAI,UAAU;IAC1B,mBAAmB;IACnB,WAAW,UAAU,UAAU;IAC/B,QAAQ,YAAY,UAAU;IAC9B,QAAQ,aAAa;IACrB,UAAU;IACX;GACD,SAAS,EAAE,GAAG,yBAAyB,MAAM,EAAE;GAChD,CAAC,EACF;AAEF,SAAO;GACL,MAAM,OAAO,KAAK,KAAK,MAAM,SAAS;GACtC,MAAM,OAAO,KAAK,KAAK;GACvB,WAAW,OAAO,KAAK,UAAU;GAClC"}
1
+ {"version":3,"file":"logs.js","names":[],"sources":["../../src/clients/logs.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n createRTypeRoutingHeader,\n RestAPI,\n parseSignedResourceId,\n signatureToBase64Url,\n} from \"@milaboratories/pl-client\";\nimport type { StreamingAPI_Response } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol\";\nimport { StreamingClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/streamingapi/protocol.client\";\nimport type { StreamingApiPaths, StreamingRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLogs {\n public readonly wire: WireClientProvider<StreamingRestClientType | StreamingClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n public readonly httpClient: Dispatcher,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new StreamingClient(wire.Transport);\n }\n\n return RestAPI.createClient<StreamingApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** Reads text back and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async lastLines(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the end.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const { globalId: rIdGlobal, signature: rIdSig } = parseSignedResourceId(rId);\n const client = this.wire.get();\n if (client instanceof StreamingClient) {\n return (\n await client.lastLines(\n {\n resourceId: rIdGlobal,\n resourceSignature: rIdSig,\n lineCount: lineCount,\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/last-lines\", {\n body: {\n resourceId: rIdGlobal.toString(),\n resourceSignature: signatureToBase64Url(rIdSig),\n lineCount: lineCount,\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n\n /** Reads the file forward and returns the text,\n * the new offset\n * and the total size of the (currently existing) file. */\n public async readText(\n { id: rId, type: rType }: ResourceInfo,\n lineCount: number,\n offsetBytes: bigint = 0n, // if 0n, then start from the beginning.\n searchStr?: string,\n options?: RpcOptions,\n ): Promise<StreamingAPI_Response> {\n const { globalId: rIdGlobal2, signature: rIdSig2 } = parseSignedResourceId(rId);\n const client = this.wire.get();\n\n if (client instanceof StreamingClient) {\n return (\n await client.readText(\n {\n resourceId: notEmpty(rIdGlobal2),\n resourceSignature: rIdSig2,\n readLimit: BigInt(lineCount),\n offset: offsetBytes,\n search: searchStr,\n },\n addRTypeToMetadata(rType, options),\n )\n ).response;\n }\n\n const resp = (\n await client.POST(\"/v1/read/text\", {\n body: {\n resourceId: rIdGlobal2.toString(),\n resourceSignature: signatureToBase64Url(rIdSig2),\n readLimit: lineCount.toString(),\n offset: offsetBytes.toString(),\n search: searchStr ?? \"\",\n searchRe: \"\",\n },\n headers: { ...createRTypeRoutingHeader(rType) },\n })\n ).data!;\n\n return {\n data: Buffer.from(resp.data, \"base64\"),\n size: BigInt(resp.size),\n newOffset: BigInt(resp.newOffset),\n };\n }\n}\n"],"mappings":";;;;AAiBA,IAAa,aAAb,MAAwB;CACtB;CAEA,YACE,2BACA,YACA,QACA;AAFgB,OAAA,aAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAI,gBAAgB,KAAK,UAAU;AAG5C,UAAO,QAAQ,aAAgC;IAC7C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;;;CAKR,MAAa,UACX,EAAE,IAAI,KAAK,MAAM,SACjB,WACA,cAAsB,IACtB,WACA,SACgC;EAChC,MAAM,EAAE,UAAU,WAAW,WAAW,WAAW,sBAAsB,IAAI;EAC7E,MAAM,S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AAW,OAAO,KAAK,UAAU;GAClC"}
@@ -19,15 +19,17 @@ var ClientLs = class {
19
19
  close() {}
20
20
  async list(rInfo, path, options) {
21
21
  const client = this.wire.get();
22
+ const { globalId, signature } = (0, _milaboratories_pl_client.parseSignedResourceId)(rInfo.id);
22
23
  if (client instanceof require_protocol_client.LSClient) return await client.list({
23
- resourceId: rInfo.id,
24
+ resourceId: globalId,
25
+ resourceSignature: signature,
24
26
  location: path
25
27
  }, (0, _milaboratories_pl_client.addRTypeToMetadata)(rInfo.type, options)).response;
26
28
  else {
27
29
  const resp = (await client.POST("/v1/list", {
28
30
  body: {
29
- resourceId: rInfo.id.toString(),
30
- resourceSignature: "",
31
+ resourceId: globalId.toString(),
32
+ resourceSignature: (0, _milaboratories_pl_client.signatureToBase64Url)(signature),
31
33
  location: path
32
34
  },
33
35
  headers: { ...(0, _milaboratories_pl_client.createRTypeRoutingHeader)(rInfo.type) }
@@ -1 +1 @@
1
- {"version":3,"file":"ls_api.cjs","names":["LSClient","RestAPI"],"sources":["../../src/clients/ls_api.ts"],"sourcesContent":["import type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport { RestAPI } from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader } from \"@milaboratories/pl-client\";\nimport type {\n LsAPI_List_Response,\n LsAPI_ListItem,\n} from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol\";\nimport { LSClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client\";\nimport type { LsApiPaths, LsRestClientType } from \"../proto-rest\";\n\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLs {\n private readonly wire: WireClientProvider<LsRestClientType | LSClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n private readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new LSClient(wire.Transport);\n }\n\n return RestAPI.createClient<LsApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n public async list(\n rInfo: ResourceInfo,\n path: string,\n options?: RpcOptions,\n ): Promise<LsAPI_List_Response> {\n const client = this.wire.get();\n\n if (client instanceof LSClient) {\n return await client.list(\n {\n resourceId: rInfo.id,\n location: path,\n },\n addRTypeToMetadata(rInfo.type, options),\n ).response;\n } else {\n const resp = (\n await client.POST(\"/v1/list\", {\n body: {\n resourceId: rInfo.id.toString(),\n resourceSignature: \"\",\n location: path,\n },\n headers: { ...createRTypeRoutingHeader(rInfo.type) },\n })\n ).data!;\n\n const items: LsAPI_ListItem[] = resp.items.map((item) => ({\n name: item.name,\n size: BigInt(item.size),\n isDir: item.isDir,\n fullName: item.fullName,\n directory: item.directory,\n lastModified: parseTimestamp(item.lastModified),\n version: item.version,\n }));\n\n return {\n items,\n delimiter: resp.delimiter,\n };\n }\n }\n}\n\nfunction parseTimestamp(timestamp: string): { seconds: bigint; nanos: number } {\n // Parse ISO 8601 format: 2025-08-08T11:12:44.145635532Z\n const date = new Date(timestamp);\n const seconds = BigInt(Math.floor(date.getTime() / 1000));\n\n // Extract fractional seconds from the original string\n const fractionalMatch = timestamp.match(/\\.(\\d+)Z?$/);\n let nanos = 0;\n if (fractionalMatch) {\n const fractionalPart = fractionalMatch[1];\n // Pad or truncate to 9 digits (nanoseconds)\n const padded = fractionalPart.padEnd(9, \"0\").slice(0, 9);\n nanos = parseInt(padded, 10);\n }\n\n return { seconds, nanos };\n}\n"],"mappings":";;;;AAcA,IAAa,WAAb,MAAsB;CACpB;CAEA,YACE,2BACA,QACA;AADiB,OAAA,SAAA;AAEjB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE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 {"version":3,"file":"ls_api.cjs","names":["LSClient","RestAPI"],"sources":["../../src/clients/ls_api.ts"],"sourcesContent":["import type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport { RestAPI, parseSignedResourceId, signatureToBase64Url } from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader } from \"@milaboratories/pl-client\";\nimport type {\n LsAPI_List_Response,\n LsAPI_ListItem,\n} from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol\";\nimport { LSClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client\";\nimport type { LsApiPaths, LsRestClientType } from \"../proto-rest\";\n\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLs {\n private readonly wire: WireClientProvider<LsRestClientType | LSClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n private readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new LSClient(wire.Transport);\n }\n\n return RestAPI.createClient<LsApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n public async list(\n rInfo: ResourceInfo,\n path: string,\n options?: RpcOptions,\n ): Promise<LsAPI_List_Response> {\n const client = this.wire.get();\n\n const { globalId, signature } = parseSignedResourceId(rInfo.id);\n if (client instanceof LSClient) {\n return await client.list(\n {\n resourceId: globalId,\n resourceSignature: signature,\n location: path,\n },\n addRTypeToMetadata(rInfo.type, options),\n ).response;\n } else {\n const resp = (\n await client.POST(\"/v1/list\", {\n body: {\n resourceId: globalId.toString(),\n resourceSignature: signatureToBase64Url(signature),\n location: path,\n },\n headers: { ...createRTypeRoutingHeader(rInfo.type) },\n })\n ).data!;\n\n const items: LsAPI_ListItem[] = resp.items.map((item) => ({\n name: item.name,\n size: BigInt(item.size),\n isDir: item.isDir,\n fullName: item.fullName,\n directory: item.directory,\n lastModified: parseTimestamp(item.lastModified),\n version: item.version,\n }));\n\n return {\n items,\n delimiter: resp.delimiter,\n };\n }\n }\n}\n\nfunction parseTimestamp(timestamp: string): { seconds: bigint; nanos: number } {\n // Parse ISO 8601 format: 2025-08-08T11:12:44.145635532Z\n const date = new Date(timestamp);\n const seconds = BigInt(Math.floor(date.getTime() / 1000));\n\n // Extract fractional seconds from the original string\n const fractionalMatch = timestamp.match(/\\.(\\d+)Z?$/);\n let nanos = 0;\n if (fractionalMatch) {\n const fractionalPart = fractionalMatch[1];\n // Pad or truncate to 9 digits (nanoseconds)\n const padded = fractionalPart.padEnd(9, \"0\").slice(0, 9);\n nanos = parseInt(padded, 10);\n }\n\n return { seconds, nanos };\n}\n"],"mappings":";;;;AAcA,IAAa,WAAb,MAAsB;CACpB;CAEA,YACE,2BACA,QACA;AADiB,OAAA,SAAA;AAEjB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAIA,wBAAAA,SAAS,KAAK,UAAU;AAGrC,UAAOC,0BAAAA,QAAQ,aAAyB;IACtC,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;CAER,MAAa,KACX,OACA,MACA,SAC8B;EAC9B,MAAM,SAAS,KAAK,KAAK,KAAK;EAE9B,MAAM,EAAE,UAAU,eAAA,GAAA,0BAAA,uBAAoC,MAAM,GAAG;AAC/D,MAAI,kBAAkBD,wBAAAA,SACpB,QAAO,MAAM,OAAO,KAClB;GACE,YAAY;GACZ,mBAAmB;GACnB,UAAU;GACX,GAAA,GAAA,0BAAA,oBACkB,MAAM,MAAM,QAAQ,CACxC,CAAC;OACG;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,YAAY;IAC5B,MAAM;KACJ,YAAY,SAAS,UAAU;KAC/B,oBAAA,GAAA,0BAAA,sBAAwC,UAAU;KAClD,UAAU;KACX;IACD,SAAS,EAAE,IAAA,GAAA,0BAAA,0BAA4B,MAAM,KAAK,EAAE;IACrD,CAAC,EACF;AAYF,UAAO;IACL,OAX8B,KAAK,MAAM,KAAK,UAAU;KACxD,MAAM,KAAK;KACX,MAAM,OAAO,KAAK,KAAK;KACvB,OAAO,KAAK;KACZ,UAAU,KAAK;KACf,WAAW,KAAK;KAChB,cAAc,eAAe,KAAK,aAAa;KAC/C,SAAS,KAAK;KACf,EAAE;IAID,WAAW,KAAK;IACjB;;;;AAKP,SAAS,eAAe,WAAuD;CAE7E,MAAM,OAAO,IAAI,KAAK,UAAU;CAChC,MAAM,UAAU,OAAO,KAAK,MAAM,KAAK,SAAS,GAAG,IAAK,CAAC;CAGzD,MAAM,kBAAkB,UAAU,MAAM,aAAa;CACrD,IAAI,QAAQ;AACZ,KAAI,iBAAiB;EAGnB,MAAM,SAFiB,gBAAgB,GAET,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE;AACxD,UAAQ,SAAS,QAAQ,GAAG;;AAG9B,QAAO;EAAE;EAAS;EAAO"}
@@ -1,5 +1,5 @@
1
1
  import { LSClient } from "../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client.js";
2
- import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader } from "@milaboratories/pl-client";
2
+ import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader, parseSignedResourceId, signatureToBase64Url } from "@milaboratories/pl-client";
3
3
  //#region src/clients/ls_api.ts
4
4
  var ClientLs = class {
5
5
  wire;
@@ -18,15 +18,17 @@ var ClientLs = class {
18
18
  close() {}
19
19
  async list(rInfo, path, options) {
20
20
  const client = this.wire.get();
21
+ const { globalId, signature } = parseSignedResourceId(rInfo.id);
21
22
  if (client instanceof LSClient) return await client.list({
22
- resourceId: rInfo.id,
23
+ resourceId: globalId,
24
+ resourceSignature: signature,
23
25
  location: path
24
26
  }, addRTypeToMetadata(rInfo.type, options)).response;
25
27
  else {
26
28
  const resp = (await client.POST("/v1/list", {
27
29
  body: {
28
- resourceId: rInfo.id.toString(),
29
- resourceSignature: "",
30
+ resourceId: globalId.toString(),
31
+ resourceSignature: signatureToBase64Url(signature),
30
32
  location: path
31
33
  },
32
34
  headers: { ...createRTypeRoutingHeader(rInfo.type) }
@@ -1 +1 @@
1
- {"version":3,"file":"ls_api.js","names":[],"sources":["../../src/clients/ls_api.ts"],"sourcesContent":["import type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport { RestAPI } from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader } from \"@milaboratories/pl-client\";\nimport type {\n LsAPI_List_Response,\n LsAPI_ListItem,\n} from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol\";\nimport { LSClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client\";\nimport type { LsApiPaths, LsRestClientType } from \"../proto-rest\";\n\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLs {\n private readonly wire: WireClientProvider<LsRestClientType | LSClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n private readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new LSClient(wire.Transport);\n }\n\n return RestAPI.createClient<LsApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n public async list(\n rInfo: ResourceInfo,\n path: string,\n options?: RpcOptions,\n ): Promise<LsAPI_List_Response> {\n const client = this.wire.get();\n\n if (client instanceof LSClient) {\n return await client.list(\n {\n resourceId: rInfo.id,\n location: path,\n },\n addRTypeToMetadata(rInfo.type, options),\n ).response;\n } else {\n const resp = (\n await client.POST(\"/v1/list\", {\n body: {\n resourceId: rInfo.id.toString(),\n resourceSignature: \"\",\n location: path,\n },\n headers: { ...createRTypeRoutingHeader(rInfo.type) },\n })\n ).data!;\n\n const items: LsAPI_ListItem[] = resp.items.map((item) => ({\n name: item.name,\n size: BigInt(item.size),\n isDir: item.isDir,\n fullName: item.fullName,\n directory: item.directory,\n lastModified: parseTimestamp(item.lastModified),\n version: item.version,\n }));\n\n return {\n items,\n delimiter: resp.delimiter,\n };\n }\n }\n}\n\nfunction parseTimestamp(timestamp: string): { seconds: bigint; nanos: number } {\n // Parse ISO 8601 format: 2025-08-08T11:12:44.145635532Z\n const date = new Date(timestamp);\n const seconds = BigInt(Math.floor(date.getTime() / 1000));\n\n // Extract fractional seconds from the original string\n const fractionalMatch = timestamp.match(/\\.(\\d+)Z?$/);\n let nanos = 0;\n if (fractionalMatch) {\n const fractionalPart = fractionalMatch[1];\n // Pad or truncate to 9 digits (nanoseconds)\n const padded = fractionalPart.padEnd(9, \"0\").slice(0, 9);\n nanos = parseInt(padded, 10);\n }\n\n return { seconds, nanos };\n}\n"],"mappings":";;;AAcA,IAAa,WAAb,MAAsB;CACpB;CAEA,YACE,2BACA,QACA;AADiB,OAAA,SAAA;AAEjB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAI,SAAS,KAAK,UAAU;AAGrC,UAAO,QAAQ,aAAyB;IACtC,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;CAER,MAAa,KACX,OACA,MACA,SAC8B;EAC9B,MAAM,SAAS,KAAK,KAAK,KAAK;AAE9B,MAAI,kBAAkB,SACpB,QAAO,MAAM,OAAO,KAClB;GACE,YAAY,MAAM;GAClB,UAAU;GACX,EACD,mBAAmB,MAAM,MAAM,QAAQ,CACxC,CAAC;OACG;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,YAAY;IAC5B,MAAM;KACJ,YAAY,MAAM,GAAG,UAAU;KAC/B,mBAAmB;KACnB,UAAU;KACX;IACD,SAAS,EAAE,GAAG,yBAAyB,MAAM,KAAK,EAAE;IACrD,CAAC,EACF;AAYF,UAAO;IACL,OAX8B,KAAK,MAAM,KAAK,UAAU;KACxD,MAAM,KAAK;KACX,MAAM,OAAO,KAAK,KAAK;KACvB,OAAO,KAAK;KACZ,UAAU,KAAK;KACf,WAAW,KAAK;KAChB,cAAc,eAAe,KAAK,aAAa;KAC/C,SAAS,KAAK;KACf,EAAE;IAID,WAAW,KAAK;IACjB;;;;AAKP,SAAS,eAAe,WAAuD;CAE7E,MAAM,OAAO,IAAI,KAAK,UAAU;CAChC,MAAM,UAAU,OAAO,KAAK,MAAM,KAAK,SAAS,GAAG,IAAK,CAAC;CAGzD,MAAM,kBAAkB,UAAU,MAAM,aAAa;CACrD,IAAI,QAAQ;AACZ,KAAI,iBAAiB;EAGnB,MAAM,SAFiB,gBAAgB,GAET,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE;AACxD,UAAQ,SAAS,QAAQ,GAAG;;AAG9B,QAAO;EAAE;EAAS;EAAO"}
1
+ {"version":3,"file":"ls_api.js","names":[],"sources":["../../src/clients/ls_api.ts"],"sourcesContent":["import type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type { WireClientProvider, WireClientProviderFactory } from \"@milaboratories/pl-client\";\nimport { RestAPI, parseSignedResourceId, signatureToBase64Url } from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader } from \"@milaboratories/pl-client\";\nimport type {\n LsAPI_List_Response,\n LsAPI_ListItem,\n} from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol\";\nimport { LSClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/lsapi/protocol.client\";\nimport type { LsApiPaths, LsRestClientType } from \"../proto-rest\";\n\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport class ClientLs {\n private readonly wire: WireClientProvider<LsRestClientType | LSClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n private readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new LSClient(wire.Transport);\n }\n\n return RestAPI.createClient<LsApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n public async list(\n rInfo: ResourceInfo,\n path: string,\n options?: RpcOptions,\n ): Promise<LsAPI_List_Response> {\n const client = this.wire.get();\n\n const { globalId, signature } = parseSignedResourceId(rInfo.id);\n if (client instanceof LSClient) {\n return await client.list(\n {\n resourceId: globalId,\n resourceSignature: signature,\n location: path,\n },\n addRTypeToMetadata(rInfo.type, options),\n ).response;\n } else {\n const resp = (\n await client.POST(\"/v1/list\", {\n body: {\n resourceId: globalId.toString(),\n resourceSignature: signatureToBase64Url(signature),\n location: path,\n },\n headers: { ...createRTypeRoutingHeader(rInfo.type) },\n })\n ).data!;\n\n const items: LsAPI_ListItem[] = resp.items.map((item) => ({\n name: item.name,\n size: BigInt(item.size),\n isDir: item.isDir,\n fullName: item.fullName,\n directory: item.directory,\n lastModified: parseTimestamp(item.lastModified),\n version: item.version,\n }));\n\n return {\n items,\n delimiter: resp.delimiter,\n };\n }\n }\n}\n\nfunction parseTimestamp(timestamp: string): { seconds: bigint; nanos: number } {\n // Parse ISO 8601 format: 2025-08-08T11:12:44.145635532Z\n const date = new Date(timestamp);\n const seconds = BigInt(Math.floor(date.getTime() / 1000));\n\n // Extract fractional seconds from the original string\n const fractionalMatch = timestamp.match(/\\.(\\d+)Z?$/);\n let nanos = 0;\n if (fractionalMatch) {\n const fractionalPart = fractionalMatch[1];\n // Pad or truncate to 9 digits (nanoseconds)\n const padded = fractionalPart.padEnd(9, \"0\").slice(0, 9);\n nanos = parseInt(padded, 10);\n }\n\n return { seconds, nanos };\n}\n"],"mappings":";;;AAcA,IAAa,WAAb,MAAsB;CACpB;CAEA,YACE,2BACA,QACA;AADiB,OAAA,SAAA;AAEjB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAI,SAAS,KAAK,UAAU;AAGrC,UAAO,QAAQ,aAAyB;IACtC,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;CAER,MAAa,KACX,OACA,MACA,SAC8B;EAC9B,MAAM,SAAS,KAAK,KAAK,KAAK;EAE9B,MAAM,EAAE,UAAU,cAAc,sBAAsB,MAAM,GAAG;AAC/D,MAAI,kBAAkB,SACpB,QAAO,MAAM,OAAO,KAClB;GACE,YAAY;GACZ,mBAAmB;GACnB,UAAU;GACX,EACD,mBAAmB,MAAM,MAAM,QAAQ,CACxC,CAAC;OACG;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,YAAY;IAC5B,MAAM;KACJ,YAAY,SAAS,UAAU;KAC/B,mBAAmB,qBAAqB,UAAU;KAClD,UAAU;KACX;IACD,SAAS,EAAE,GAAG,yBAAyB,MAAM,KAAK,EAAE;IACrD,CAAC,EACF;AAYF,UAAO;IACL,OAX8B,KAAK,MAAM,KAAK,UAAU;KACxD,MAAM,KAAK;KACX,MAAM,OAAO,KAAK,KAAK;KACvB,OAAO,KAAK;KACZ,UAAU,KAAK;KACf,WAAW,KAAK;KAChB,cAAc,eAAe,KAAK,aAAa;KAC/C,SAAS,KAAK;KACf,EAAE;IAID,WAAW,KAAK;IACjB;;;;AAKP,SAAS,eAAe,WAAuD;CAE7E,MAAM,OAAO,IAAI,KAAK,UAAU;CAChC,MAAM,UAAU,OAAO,KAAK,MAAM,KAAK,SAAS,GAAG,IAAK,CAAC;CAGzD,MAAM,kBAAkB,UAAU,MAAM,aAAa;CACrD,IAAI,QAAQ;AACZ,KAAI,iBAAiB;EAGnB,MAAM,SAFiB,gBAAgB,GAET,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,EAAE;AACxD,UAAQ,SAAS,QAAQ,GAAG;;AAG9B,QAAO;EAAE;EAAS;EAAO"}
@@ -22,13 +22,17 @@ var ClientProgress = class {
22
22
  /** getStatus gets a progress status by given rId and rType. */
23
23
  async getStatus({ id, type }, options) {
24
24
  const client = this.wire.get();
25
+ const { globalId, signature } = (0, _milaboratories_pl_client.parseSignedResourceId)(id);
25
26
  let report;
26
- if (client instanceof require_protocol_client.ProgressClient) report = (0, _milaboratories_ts_helpers.notEmpty)((await client.getStatus({ resourceId: id }, (0, _milaboratories_pl_client.addRTypeToMetadata)(type, options)).response).report);
27
+ if (client instanceof require_protocol_client.ProgressClient) report = (0, _milaboratories_ts_helpers.notEmpty)((await client.getStatus({
28
+ resourceId: globalId,
29
+ resourceSignature: signature
30
+ }, (0, _milaboratories_pl_client.addRTypeToMetadata)(type, options)).response).report);
27
31
  else {
28
32
  const resp = (await client.POST("/v1/get-progress", {
29
33
  body: {
30
- resourceId: id.toString(),
31
- resourceSignature: ""
34
+ resourceId: globalId.toString(),
35
+ resourceSignature: (0, _milaboratories_pl_client.signatureToBase64Url)(signature)
32
36
  },
33
37
  headers: { ...(0, _milaboratories_pl_client.createRTypeRoutingHeader)(type) }
34
38
  })).data.report;
@@ -1 +1 @@
1
- {"version":3,"file":"progress.cjs","names":["ProgressClient","RestAPI"],"sources":["../../src/clients/progress.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type {\n WireClientProvider,\n WireClientProviderFactory,\n PlClient,\n} from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from \"@milaboratories/pl-client\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport { ProgressClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client\";\nimport type { ProgressAPI_Report } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol\";\nimport type { ProgressApiPaths, ProgressRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport type ProgressStatus = {\n done: boolean;\n progress: number;\n bytesProcessed?: string;\n bytesTotal?: string;\n};\n\n// ClientProgress holds a grpc connection to the platform\n// but for Progress API service.\n// When blobs are transfered, one can got a status of transfering\n// using this API.\nexport class ClientProgress {\n public readonly wire: WireClientProvider<ProgressRestClientType | ProgressClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n _: Dispatcher,\n public readonly client: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new ProgressClient(wire.Transport);\n }\n\n return RestAPI.createClient<ProgressApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** getStatus gets a progress status by given rId and rType. */\n async getStatus({ id, type }: ResourceInfo, options?: RpcOptions): Promise<ProgressStatus> {\n const client = this.wire.get();\n\n let report: ProgressAPI_Report;\n if (client instanceof ProgressClient) {\n report = notEmpty(\n (await client.getStatus({ resourceId: id }, addRTypeToMetadata(type, options)).response)\n .report,\n );\n } else {\n const resp = (\n await client.POST(\"/v1/get-progress\", {\n body: { resourceId: id.toString(), resourceSignature: \"\" },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!.report;\n report = {\n done: resp.done,\n progress: resp.progress,\n bytesProcessed: BigInt(resp.bytesProcessed),\n bytesTotal: BigInt(resp.bytesTotal),\n name: resp.name,\n };\n }\n\n return {\n done: report.done,\n progress: report.progress,\n bytesProcessed: String(report.bytesProcessed),\n bytesTotal: String(report.bytesTotal),\n };\n }\n}\n"],"mappings":";;;;;AA0BA,IAAa,iBAAb,MAA4B;CAC1B;CAEA,YACE,2BACA,GACA,QACA,QACA;AAFgB,OAAA,SAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAIA,wBAAAA,eAAe,KAAK,UAAU;AAG3C,UAAOC,0BAAAA,QAAQ,aAA+B;IAC5C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;CAGR,MAAM,UAAU,EAAE,IAAI,QAAsB,SAA+C;EACzF,MAAM,SAAS,KAAK,KAAK,KAAK;EAE9B,IAAI;AACJ,MAAI,kBAAkBD,wBAAAA,eACpB,WAAA,GAAA,2BAAA,WACG,MAAM,OAAO,UAAU,EAAE,YAAY,IAAI,GAAA,GAAA,0BAAA,oBAAqB,MAAM,QAAQ,CAAC,CAAC,UAC5E,OACJ;OACI;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,oBAAoB;IACpC,MAAM;KAAE,YAAY,GAAG,UAAU;KAAE,mBAAmB;KAAI;IAC1D,SAAS,EAAE,IAAA,GAAA,0BAAA,0BAA4B,KAAK,EAAE;IAC/C,CAAC,EACF,KAAM;AACR,YAAS;IACP,MAAM,KAAK;IACX,UAAU,KAAK;IACf,gBAAgB,OAAO,KAAK,eAAe;IAC3C,YAAY,OAAO,KAAK,WAAW;IACnC,MAAM,KAAK;IACZ;;AAGH,SAAO;GACL,MAAM,OAAO;GACb,UAAU,OAAO;GACjB,gBAAgB,OAAO,OAAO,eAAe;GAC7C,YAAY,OAAO,OAAO,WAAW;GACtC"}
1
+ {"version":3,"file":"progress.cjs","names":["ProgressClient","RestAPI"],"sources":["../../src/clients/progress.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type {\n WireClientProvider,\n WireClientProviderFactory,\n PlClient,\n} from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n createRTypeRoutingHeader,\n RestAPI,\n parseSignedResourceId,\n signatureToBase64Url,\n} from \"@milaboratories/pl-client\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport { ProgressClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client\";\nimport type { ProgressAPI_Report } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol\";\nimport type { ProgressApiPaths, ProgressRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport type ProgressStatus = {\n done: boolean;\n progress: number;\n bytesProcessed?: string;\n bytesTotal?: string;\n};\n\n// ClientProgress holds a grpc connection to the platform\n// but for Progress API service.\n// When blobs are transfered, one can got a status of transfering\n// using this API.\nexport class ClientProgress {\n public readonly wire: WireClientProvider<ProgressRestClientType | ProgressClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n _: Dispatcher,\n public readonly client: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new ProgressClient(wire.Transport);\n }\n\n return RestAPI.createClient<ProgressApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** getStatus gets a progress status by given rId and rType. */\n async getStatus({ id, type }: ResourceInfo, options?: RpcOptions): Promise<ProgressStatus> {\n const client = this.wire.get();\n\n const { globalId, signature } = parseSignedResourceId(id);\n let report: ProgressAPI_Report;\n if (client instanceof ProgressClient) {\n report = notEmpty(\n (\n await client.getStatus(\n { resourceId: globalId, resourceSignature: signature },\n addRTypeToMetadata(type, options),\n ).response\n ).report,\n );\n } else {\n const resp = (\n await client.POST(\"/v1/get-progress\", {\n body: {\n resourceId: globalId.toString(),\n resourceSignature: signatureToBase64Url(signature),\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!.report;\n report = {\n done: resp.done,\n progress: resp.progress,\n bytesProcessed: BigInt(resp.bytesProcessed),\n bytesTotal: BigInt(resp.bytesTotal),\n name: resp.name,\n };\n }\n\n return {\n done: report.done,\n progress: report.progress,\n bytesProcessed: String(report.bytesProcessed),\n bytesTotal: String(report.bytesTotal),\n };\n }\n}\n"],"mappings":";;;;;AAgCA,IAAa,iBAAb,MAA4B;CAC1B;CAEA,YACE,2BACA,GACA,QACA,QACA;AAFgB,OAAA,SAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAIA,wBAAAA,eAAe,KAAK,UAAU;AAG3C,UAAOC,0BAAAA,QAAQ,aAA+B;IAC5C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;CAGR,MAAM,UAAU,EAAE,IAAI,QAAsB,SAA+C;EACzF,MAAM,SAAS,KAAK,KAAK,KAAK;EAE9B,MAAM,EAAE,UAAU,eAAA,GAAA,0BAAA,uBAAoC,GAAG;EACzD,IAAI;AACJ,MAAI,kBAAkBD,wBAAAA,eACpB,WAAA,GAAA,2BAAA,WAEI,MAAM,OAAO,UACX;GAAE,YAAY;GAAU,mBAAmB;GAAW,GAAA,GAAA,0BAAA,oBACnC,MAAM,QAAQ,CAClC,CAAC,UACF,OACH;OACI;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,oBAAoB;IACpC,MAAM;KACJ,YAAY,SAAS,UAAU;KAC/B,oBAAA,GAAA,0BAAA,sBAAwC,UAAU;KACnD;IACD,SAAS,EAAE,IAAA,GAAA,0BAAA,0BAA4B,KAAK,EAAE;IAC/C,CAAC,EACF,KAAM;AACR,YAAS;IACP,MAAM,KAAK;IACX,UAAU,KAAK;IACf,gBAAgB,OAAO,KAAK,eAAe;IAC3C,YAAY,OAAO,KAAK,WAAW;IACnC,MAAM,KAAK;IACZ;;AAGH,SAAO;GACL,MAAM,OAAO;GACb,UAAU,OAAO;GACjB,gBAAgB,OAAO,OAAO,eAAe;GAC7C,YAAY,OAAO,OAAO,WAAW;GACtC"}
@@ -1 +1 @@
1
- {"version":3,"file":"progress.d.ts","names":[],"sources":["../../src/clients/progress.ts"],"mappings":";;;;;;;;;KAeY,cAAA;EACV,IAAA;EACA,QAAA;EACA,cAAA;EACA,UAAA;AAAA;AAAA,cAOW,cAAA;EAAA,SAMO,MAAA,EAAQ,QAAA;EAAA,SACR,MAAA,EAAQ,QAAA;EAAA,SANV,IAAA,EAAM,kBAAA,CAAmB,sBAAA,GAAyB,cAAA;cAGhE,yBAAA,EAA2B,yBAAA,EAC3B,CAAA,EAAG,UAAA,EACa,MAAA,EAAQ,QAAA,EACR,MAAA,EAAQ,QAAA;EAgB1B,KAAA,CAAA;EAvBW;EA0BL,SAAA,CAAA;IAAY,EAAA;IAAI;EAAA,GAAQ,YAAA,EAAc,OAAA,GAAU,UAAA,GAAa,OAAA,CAAQ,cAAA;AAAA"}
1
+ {"version":3,"file":"progress.d.ts","names":[],"sources":["../../src/clients/progress.ts"],"mappings":";;;;;;;;;KAqBY,cAAA;EACV,IAAA;EACA,QAAA;EACA,cAAA;EACA,UAAA;AAAA;AAAA,cAOW,cAAA;EAAA,SAMO,MAAA,EAAQ,QAAA;EAAA,SACR,MAAA,EAAQ,QAAA;EAAA,SANV,IAAA,EAAM,kBAAA,CAAmB,sBAAA,GAAyB,cAAA;cAGhE,yBAAA,EAA2B,yBAAA,EAC3B,CAAA,EAAG,UAAA,EACa,MAAA,EAAQ,QAAA,EACR,MAAA,EAAQ,QAAA;EAgB1B,KAAA,CAAA;EAvBW;EA0BL,SAAA,CAAA;IAAY,EAAA;IAAI;EAAA,GAAQ,YAAA,EAAc,OAAA,GAAU,UAAA,GAAa,OAAA,CAAQ,cAAA;AAAA"}
@@ -1,5 +1,5 @@
1
1
  import { ProgressClient } from "../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client.js";
2
- import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader } from "@milaboratories/pl-client";
2
+ import { RestAPI, addRTypeToMetadata, createRTypeRoutingHeader, parseSignedResourceId, signatureToBase64Url } from "@milaboratories/pl-client";
3
3
  import { notEmpty } from "@milaboratories/ts-helpers";
4
4
  //#region src/clients/progress.ts
5
5
  var ClientProgress = class {
@@ -21,13 +21,17 @@ var ClientProgress = class {
21
21
  /** getStatus gets a progress status by given rId and rType. */
22
22
  async getStatus({ id, type }, options) {
23
23
  const client = this.wire.get();
24
+ const { globalId, signature } = parseSignedResourceId(id);
24
25
  let report;
25
- if (client instanceof ProgressClient) report = notEmpty((await client.getStatus({ resourceId: id }, addRTypeToMetadata(type, options)).response).report);
26
+ if (client instanceof ProgressClient) report = notEmpty((await client.getStatus({
27
+ resourceId: globalId,
28
+ resourceSignature: signature
29
+ }, addRTypeToMetadata(type, options)).response).report);
26
30
  else {
27
31
  const resp = (await client.POST("/v1/get-progress", {
28
32
  body: {
29
- resourceId: id.toString(),
30
- resourceSignature: ""
33
+ resourceId: globalId.toString(),
34
+ resourceSignature: signatureToBase64Url(signature)
31
35
  },
32
36
  headers: { ...createRTypeRoutingHeader(type) }
33
37
  })).data.report;
@@ -1 +1 @@
1
- {"version":3,"file":"progress.js","names":[],"sources":["../../src/clients/progress.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type {\n WireClientProvider,\n WireClientProviderFactory,\n PlClient,\n} from \"@milaboratories/pl-client\";\nimport { addRTypeToMetadata, createRTypeRoutingHeader, RestAPI } from \"@milaboratories/pl-client\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport { ProgressClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client\";\nimport type { ProgressAPI_Report } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol\";\nimport type { ProgressApiPaths, ProgressRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport type ProgressStatus = {\n done: boolean;\n progress: number;\n bytesProcessed?: string;\n bytesTotal?: string;\n};\n\n// ClientProgress holds a grpc connection to the platform\n// but for Progress API service.\n// When blobs are transfered, one can got a status of transfering\n// using this API.\nexport class ClientProgress {\n public readonly wire: WireClientProvider<ProgressRestClientType | ProgressClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n _: Dispatcher,\n public readonly client: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new ProgressClient(wire.Transport);\n }\n\n return RestAPI.createClient<ProgressApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** getStatus gets a progress status by given rId and rType. */\n async getStatus({ id, type }: ResourceInfo, options?: RpcOptions): Promise<ProgressStatus> {\n const client = this.wire.get();\n\n let report: ProgressAPI_Report;\n if (client instanceof ProgressClient) {\n report = notEmpty(\n (await client.getStatus({ resourceId: id }, addRTypeToMetadata(type, options)).response)\n .report,\n );\n } else {\n const resp = (\n await client.POST(\"/v1/get-progress\", {\n body: { resourceId: id.toString(), resourceSignature: \"\" },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!.report;\n report = {\n done: resp.done,\n progress: resp.progress,\n bytesProcessed: BigInt(resp.bytesProcessed),\n bytesTotal: BigInt(resp.bytesTotal),\n name: resp.name,\n };\n }\n\n return {\n done: report.done,\n progress: report.progress,\n bytesProcessed: String(report.bytesProcessed),\n bytesTotal: String(report.bytesTotal),\n };\n }\n}\n"],"mappings":";;;;AA0BA,IAAa,iBAAb,MAA4B;CAC1B;CAEA,YACE,2BACA,GACA,QACA,QACA;AAFgB,OAAA,SAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAI,eAAe,KAAK,UAAU;AAG3C,UAAO,QAAQ,aAA+B;IAC5C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;CAGR,MAAM,UAAU,EAAE,IAAI,QAAsB,SAA+C;EACzF,MAAM,SAAS,KAAK,KAAK,KAAK;EAE9B,IAAI;AACJ,MAAI,kBAAkB,eACpB,UAAS,UACN,MAAM,OAAO,UAAU,EAAE,YAAY,IAAI,EAAE,mBAAmB,MAAM,QAAQ,CAAC,CAAC,UAC5E,OACJ;OACI;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,oBAAoB;IACpC,MAAM;KAAE,YAAY,GAAG,UAAU;KAAE,mBAAmB;KAAI;IAC1D,SAAS,EAAE,GAAG,yBAAyB,KAAK,EAAE;IAC/C,CAAC,EACF,KAAM;AACR,YAAS;IACP,MAAM,KAAK;IACX,UAAU,KAAK;IACf,gBAAgB,OAAO,KAAK,eAAe;IAC3C,YAAY,OAAO,KAAK,WAAW;IACnC,MAAM,KAAK;IACZ;;AAGH,SAAO;GACL,MAAM,OAAO;GACb,UAAU,OAAO;GACjB,gBAAgB,OAAO,OAAO,eAAe;GAC7C,YAAY,OAAO,OAAO,WAAW;GACtC"}
1
+ {"version":3,"file":"progress.js","names":[],"sources":["../../src/clients/progress.ts"],"sourcesContent":["import type { RpcOptions } from \"@protobuf-ts/runtime-rpc\";\nimport type {\n WireClientProvider,\n WireClientProviderFactory,\n PlClient,\n} from \"@milaboratories/pl-client\";\nimport {\n addRTypeToMetadata,\n createRTypeRoutingHeader,\n RestAPI,\n parseSignedResourceId,\n signatureToBase64Url,\n} from \"@milaboratories/pl-client\";\nimport type { MiLogger } from \"@milaboratories/ts-helpers\";\nimport { notEmpty } from \"@milaboratories/ts-helpers\";\nimport type { Dispatcher } from \"undici\";\nimport { ProgressClient } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol.client\";\nimport type { ProgressAPI_Report } from \"../proto-grpc/github.com/milaboratory/pl/controllers/shared/grpc/progressapi/protocol\";\nimport type { ProgressApiPaths, ProgressRestClientType } from \"../proto-rest\";\nimport type { ResourceInfo } from \"@milaboratories/pl-tree\";\n\nexport type ProgressStatus = {\n done: boolean;\n progress: number;\n bytesProcessed?: string;\n bytesTotal?: string;\n};\n\n// ClientProgress holds a grpc connection to the platform\n// but for Progress API service.\n// When blobs are transfered, one can got a status of transfering\n// using this API.\nexport class ClientProgress {\n public readonly wire: WireClientProvider<ProgressRestClientType | ProgressClient>;\n\n constructor(\n wireClientProviderFactory: WireClientProviderFactory,\n _: Dispatcher,\n public readonly client: PlClient,\n public readonly logger: MiLogger,\n ) {\n this.wire = wireClientProviderFactory.createWireClientProvider((wire) => {\n if (wire.type === \"grpc\") {\n return new ProgressClient(wire.Transport);\n }\n\n return RestAPI.createClient<ProgressApiPaths>({\n hostAndPort: wire.Config.hostAndPort,\n ssl: wire.Config.ssl,\n dispatcher: wire.Dispatcher,\n middlewares: wire.Middlewares,\n });\n });\n }\n\n close() {}\n\n /** getStatus gets a progress status by given rId and rType. */\n async getStatus({ id, type }: ResourceInfo, options?: RpcOptions): Promise<ProgressStatus> {\n const client = this.wire.get();\n\n const { globalId, signature } = parseSignedResourceId(id);\n let report: ProgressAPI_Report;\n if (client instanceof ProgressClient) {\n report = notEmpty(\n (\n await client.getStatus(\n { resourceId: globalId, resourceSignature: signature },\n addRTypeToMetadata(type, options),\n ).response\n ).report,\n );\n } else {\n const resp = (\n await client.POST(\"/v1/get-progress\", {\n body: {\n resourceId: globalId.toString(),\n resourceSignature: signatureToBase64Url(signature),\n },\n headers: { ...createRTypeRoutingHeader(type) },\n })\n ).data!.report;\n report = {\n done: resp.done,\n progress: resp.progress,\n bytesProcessed: BigInt(resp.bytesProcessed),\n bytesTotal: BigInt(resp.bytesTotal),\n name: resp.name,\n };\n }\n\n return {\n done: report.done,\n progress: report.progress,\n bytesProcessed: String(report.bytesProcessed),\n bytesTotal: String(report.bytesTotal),\n };\n }\n}\n"],"mappings":";;;;AAgCA,IAAa,iBAAb,MAA4B;CAC1B;CAEA,YACE,2BACA,GACA,QACA,QACA;AAFgB,OAAA,SAAA;AACA,OAAA,SAAA;AAEhB,OAAK,OAAO,0BAA0B,0BAA0B,SAAS;AACvE,OAAI,KAAK,SAAS,OAChB,QAAO,IAAI,eAAe,KAAK,UAAU;AAG3C,UAAO,QAAQ,aAA+B;IAC5C,aAAa,KAAK,OAAO;IACzB,KAAK,KAAK,OAAO;IACjB,YAAY,KAAK;IACjB,aAAa,KAAK;IACnB,CAAC;IACF;;CAGJ,QAAQ;;CAGR,MAAM,UAAU,EAAE,IAAI,QAAsB,SAA+C;EACzF,MAAM,SAAS,KAAK,KAAK,KAAK;EAE9B,MAAM,EAAE,UAAU,cAAc,sBAAsB,GAAG;EACzD,IAAI;AACJ,MAAI,kBAAkB,eACpB,UAAS,UAEL,MAAM,OAAO,UACX;GAAE,YAAY;GAAU,mBAAmB;GAAW,EACtD,mBAAmB,MAAM,QAAQ,CAClC,CAAC,UACF,OACH;OACI;GACL,MAAM,QACJ,MAAM,OAAO,KAAK,oBAAoB;IACpC,MAAM;KACJ,YAAY,SAAS,UAAU;KAC/B,mBAAmB,qBAAqB,UAAU;KACnD;IACD,SAAS,EAAE,GAAG,yBAAyB,KAAK,EAAE;IAC/C,CAAC,EACF,KAAM;AACR,YAAS;IACP,MAAM,KAAK;IACX,UAAU,KAAK;IACf,gBAAgB,OAAO,KAAK,eAAe;IAC3C,YAAY,OAAO,KAAK,WAAW;IACnC,MAAM,KAAK;IACZ;;AAGH,SAAO;GACL,MAAM,OAAO;GACb,UAAU,OAAO;GACjB,gBAAgB,OAAO,OAAO,eAAe;GAC7C,YAAY,OAAO,OAAO,WAAW;GACtC"}