@jsm-mit/sultana-core-motoko-package 0.0.21 → 0.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { AdminActor } from "./actors/admin-actor.js";
2
- export { VideoUploadClient, uploadVideoToWorkersAsyncUnsafe, getSalonAssetsWithStatusAsyncUnsafe, parseAssetError, AssetValidationError } from "./video-upload-client.js";
2
+ export { VideoUploadClient, uploadVideoToWorkersAsyncUnsafe, getSalonAssetsWithStatusAsyncUnsafe, getSalonAssetsWithCoreStatusAsyncUnsafe, refineAssetStatusAsyncUnsafe, parseAssetError, AssetValidationError } from "./video-upload-client.js";
3
3
  export type { SalonAssetWithStatus, AssetError, AssetErrorCode, AssetFlowStatus } from "./video-upload-client.js";
4
4
  export type { VideoUploadStage, VideoUploadProgress, VideoUploadOptions, VideoUploadAcceptance, VideoUploadResult, VideoTranscodeCheck, } from "./video-upload-client.js";
5
5
  export type { ActionQuotaRole, CallActivityStats } from "./actors/admin-actor.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,+BAA+B,EAAE,mCAAmC,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC1K,YAAY,EAAE,oBAAoB,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAClH,YAAY,EACR,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,GACtB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,wB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E,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1G,YAAY,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAClH,YAAY,EACR,KAAK,EACL,SAAS,EACT,YAAY,EACZ,OAAO,EACP,aAAa,EACb,eAAe,EACf,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,GAClB,MAAM,gEAAgE,CAAC;AACxE,YAAY,EACR,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,UAAU,EACV,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,4BAA4B,EAC5B,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,sBAAsB,EACzB,MAAM,gEAAgE,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { AdminActor } from "./actors/admin-actor.js";
2
- export { VideoUploadClient, uploadVideoToWorkersAsyncUnsafe, getSalonAssetsWithStatusAsyncUnsafe, parseAssetError, AssetValidationError } from "./video-upload-client.js";
2
+ export { VideoUploadClient, uploadVideoToWorkersAsyncUnsafe, getSalonAssetsWithStatusAsyncUnsafe, getSalonAssetsWithCoreStatusAsyncUnsafe, refineAssetStatusAsyncUnsafe, parseAssetError, AssetValidationError } from "./video-upload-client.js";
3
3
  export { BulkActor } from "./actors/bulk-actor.js";
4
4
  export { AppointmentsActor } from "./actors/appointments-actor.js";
5
5
  export { AssetsActor } from "./actors/assets-actor.js";
@@ -155,6 +155,13 @@ export type SalonAssetWithStatus = SalonAsset & {
155
155
  * is presented as "failed" with TRANSCODING_INTERRUPTED. That verdict is presentational
156
156
  * only: core still holds #Pending and the stale-reservation sweep remains the durable
157
157
  * closure (~24h); the point is not to show false hope in the meantime.
158
+ *
159
+ * PERFORMANCE: this fans out per Pending entry — one get_asset_info canister query plus up
160
+ * to one HTTP status probe PER CONFIGURED WORKER for each Pending asset (in parallel, but
161
+ * the fetch waits for the slowest one; an unreachable worker costs a full fetch timeout).
162
+ * Libraries rarely hold many Pending entries at once, so users usually won't notice — but
163
+ * for latency-sensitive views prefer {@link getSalonAssetsWithCoreStatusAsyncUnsafe} for the
164
+ * list and {@link refineAssetStatusAsyncUnsafe} on demand for the entry being inspected.
158
165
  * @param assetsActor - AssetsActor bound to the core canister (any identity allowed to read the library).
159
166
  * @param videoClient - VideoUploadClient bound to the asset canister (source of worker URLs and statuses).
160
167
  * @param salonId - The salon whose library to fetch.
@@ -169,6 +176,40 @@ export type SalonAssetWithStatus = SalonAsset & {
169
176
  export declare function getSalonAssetsWithStatusAsyncUnsafe(assetsActor: AssetsActor, videoClient: VideoUploadClient, salonId: string, options?: {
170
177
  unknownGraceMs?: number;
171
178
  }): Promise<SalonAssetWithStatus[]>;
179
+ /**
180
+ * Performance-first variant of {@link getSalonAssetsWithStatusAsyncUnsafe}: exactly ONE
181
+ * canister query, no transcoding-worker probes. `flowStatus` is derived from core's status
182
+ * alone, so #Pending entries stay "pending" — a Pending entry may actually be uploading,
183
+ * processing or interrupted; call {@link refineAssetStatusAsyncUnsafe} for the entry the
184
+ * user drills into (or wherever the live verdict matters) to find out.
185
+ * @param assetsActor - AssetsActor bound to the core canister (any identity allowed to read the library).
186
+ * @param salonId - The salon whose library to fetch.
187
+ * @returns A Promise that resolves to the library entries with the core-derived `flowStatus`
188
+ * (+ `errorMessage` on #Failed ones).
189
+ * @throws Error with message 'CanisterError' / 'CriticalCanisterError' from the underlying
190
+ * getSalonAssetsAsyncUnsafe (not the salon's owner, salon not found, canister crash).
191
+ */
192
+ export declare function getSalonAssetsWithCoreStatusAsyncUnsafe(assetsActor: AssetsActor, salonId: string): Promise<SalonAssetWithStatus[]>;
193
+ /**
194
+ * Live-status refinement for ONE library entry — the companion of
195
+ * {@link getSalonAssetsWithCoreStatusAsyncUnsafe}: fetch the list cheaply, then refine the
196
+ * entry the user actually looks at. Non-Pending entries are returned as-is (their core
197
+ * status is final); a #Pending entry gets the full {@link VideoUploadClient.checkVideoStatusAsyncUnsafe}
198
+ * verdict, including the presentational TRANSCODING_INTERRUPTED once it is older than
199
+ * `unknownGraceMs` with no worker signal (core stays untouched — see
200
+ * getSalonAssetsWithStatusAsyncUnsafe for the semantics).
201
+ * @param videoClient - VideoUploadClient bound to the asset canister (source of worker URLs and statuses).
202
+ * @param asset - The library entry to refine (from any of the library fetches).
203
+ * @param options - Optional. `workerUrls` — probe these workers instead of fetching the
204
+ * canister's configured list; `unknownGraceMs` — see getSalonAssetsWithStatusAsyncUnsafe.
205
+ * @returns A Promise that resolves to the entry with its live `flowStatus` (+ `errorMessage` when failed).
206
+ * @throws Error (raw agent reject) when the asset canister calls (get_asset_info, get_workers)
207
+ * fail. Worker status fetches never throw — an unreachable worker just yields "unknown".
208
+ */
209
+ export declare function refineAssetStatusAsyncUnsafe(videoClient: VideoUploadClient, asset: SalonAsset, options?: {
210
+ workerUrls?: string[];
211
+ unknownGraceMs?: number;
212
+ }): Promise<SalonAssetWithStatus>;
172
213
  /**
173
214
  * Uploads the source to the first worker in `uploadUrls` that accepts it, restarting from
174
215
  * chunk 0 on each failover. Exported separately from the client so the failover behavior is
@@ -1 +1 @@
1
- {"version":3,"file":"video-upload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ACU,uBAAuB,CAChC,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GAClH,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAuCpC"}
@@ -127,6 +127,13 @@ const DEFAULT_UNKNOWN_GRACE_MS = 2 * 60 * 1000;
127
127
  * is presented as "failed" with TRANSCODING_INTERRUPTED. That verdict is presentational
128
128
  * only: core still holds #Pending and the stale-reservation sweep remains the durable
129
129
  * closure (~24h); the point is not to show false hope in the meantime.
130
+ *
131
+ * PERFORMANCE: this fans out per Pending entry — one get_asset_info canister query plus up
132
+ * to one HTTP status probe PER CONFIGURED WORKER for each Pending asset (in parallel, but
133
+ * the fetch waits for the slowest one; an unreachable worker costs a full fetch timeout).
134
+ * Libraries rarely hold many Pending entries at once, so users usually won't notice — but
135
+ * for latency-sensitive views prefer {@link getSalonAssetsWithCoreStatusAsyncUnsafe} for the
136
+ * list and {@link refineAssetStatusAsyncUnsafe} on demand for the entry being inspected.
130
137
  * @param assetsActor - AssetsActor bound to the core canister (any identity allowed to read the library).
131
138
  * @param videoClient - VideoUploadClient bound to the asset canister (source of worker URLs and statuses).
132
139
  * @param salonId - The salon whose library to fetch.
@@ -149,32 +156,77 @@ export async function getSalonAssetsWithStatusAsyncUnsafe(assetsActor, videoClie
149
156
  checks.set(asset.assetId, await videoClient.checkVideoStatusAsyncUnsafe(asset.assetId, workerUrls));
150
157
  }));
151
158
  }
152
- return library.map((asset) => {
153
- if ("Ready" in asset.status)
154
- return { ...asset, flowStatus: "ready" };
155
- if ("Failed" in asset.status) {
156
- return { ...asset, flowStatus: "failed", errorMessage: parseAssetError(asset.status.Failed) };
157
- }
158
- // #Pending refine with the live worker verdict.
159
- const check = checks.get(asset.assetId);
160
- if (check?.state === "uploading") {
161
- return { ...asset, flowStatus: "uploading" };
162
- }
163
- if (check?.state === "processing" || check?.state === "stored") {
164
- return { ...asset, flowStatus: "processing" };
165
- }
166
- if (check?.state === "failed") {
167
- // The worker already reported the failure show it now; core flips moments later.
168
- return { ...asset, flowStatus: "failed", errorMessage: check.errorMessage };
169
- }
170
- // No worker signal at all. Past the grace window that means the upload was interrupted
171
- // — presentational verdict only, core stays #Pending until the sweep closes it durably.
172
- const ageMs = Date.now() - Number(asset.createdAt / 1000000n);
173
- if (ageMs > unknownGraceMs) {
174
- return { ...asset, flowStatus: "failed", errorMessage: { error: "TRANSCODING_INTERRUPTED" } };
175
- }
176
- return { ...asset, flowStatus: "pending" };
177
- });
159
+ return library.map(asset => "Pending" in asset.status
160
+ ? refinePendingWithCheck(asset, checks.get(asset.assetId), unknownGraceMs)
161
+ : coreFlowStatus(asset));
162
+ }
163
+ /**
164
+ * Performance-first variant of {@link getSalonAssetsWithStatusAsyncUnsafe}: exactly ONE
165
+ * canister query, no transcoding-worker probes. `flowStatus` is derived from core's status
166
+ * alone, so #Pending entries stay "pending" — a Pending entry may actually be uploading,
167
+ * processing or interrupted; call {@link refineAssetStatusAsyncUnsafe} for the entry the
168
+ * user drills into (or wherever the live verdict matters) to find out.
169
+ * @param assetsActor - AssetsActor bound to the core canister (any identity allowed to read the library).
170
+ * @param salonId - The salon whose library to fetch.
171
+ * @returns A Promise that resolves to the library entries with the core-derived `flowStatus`
172
+ * (+ `errorMessage` on #Failed ones).
173
+ * @throws Error with message 'CanisterError' / 'CriticalCanisterError' from the underlying
174
+ * getSalonAssetsAsyncUnsafe (not the salon's owner, salon not found, canister crash).
175
+ */
176
+ export async function getSalonAssetsWithCoreStatusAsyncUnsafe(assetsActor, salonId) {
177
+ const library = await assetsActor.getSalonAssetsAsyncUnsafe(salonId);
178
+ return library.map(coreFlowStatus);
179
+ }
180
+ /**
181
+ * Live-status refinement for ONE library entry the companion of
182
+ * {@link getSalonAssetsWithCoreStatusAsyncUnsafe}: fetch the list cheaply, then refine the
183
+ * entry the user actually looks at. Non-Pending entries are returned as-is (their core
184
+ * status is final); a #Pending entry gets the full {@link VideoUploadClient.checkVideoStatusAsyncUnsafe}
185
+ * verdict, including the presentational TRANSCODING_INTERRUPTED once it is older than
186
+ * `unknownGraceMs` with no worker signal (core stays untouched — see
187
+ * getSalonAssetsWithStatusAsyncUnsafe for the semantics).
188
+ * @param videoClient - VideoUploadClient bound to the asset canister (source of worker URLs and statuses).
189
+ * @param asset - The library entry to refine (from any of the library fetches).
190
+ * @param options - Optional. `workerUrls` — probe these workers instead of fetching the
191
+ * canister's configured list; `unknownGraceMs` — see getSalonAssetsWithStatusAsyncUnsafe.
192
+ * @returns A Promise that resolves to the entry with its live `flowStatus` (+ `errorMessage` when failed).
193
+ * @throws Error (raw agent reject) when the asset canister calls (get_asset_info, get_workers)
194
+ * fail. Worker status fetches never throw — an unreachable worker just yields "unknown".
195
+ */
196
+ export async function refineAssetStatusAsyncUnsafe(videoClient, asset, options) {
197
+ if (!("Pending" in asset.status))
198
+ return coreFlowStatus(asset);
199
+ const check = await videoClient.checkVideoStatusAsyncUnsafe(asset.assetId, options?.workerUrls);
200
+ return refinePendingWithCheck(asset, check, options?.unknownGraceMs ?? DEFAULT_UNKNOWN_GRACE_MS);
201
+ }
202
+ /** flowStatus from core's status alone — #Pending stays "pending" (no worker verdict involved). */
203
+ function coreFlowStatus(asset) {
204
+ if ("Ready" in asset.status)
205
+ return { ...asset, flowStatus: "ready" };
206
+ if ("Failed" in asset.status) {
207
+ return { ...asset, flowStatus: "failed", errorMessage: parseAssetError(asset.status.Failed) };
208
+ }
209
+ return { ...asset, flowStatus: "pending" };
210
+ }
211
+ /** Refines a #Pending entry with a live worker verdict (undefined check = no signal). */
212
+ function refinePendingWithCheck(asset, check, unknownGraceMs) {
213
+ if (check?.state === "uploading") {
214
+ return { ...asset, flowStatus: "uploading" };
215
+ }
216
+ if (check?.state === "processing" || check?.state === "stored") {
217
+ return { ...asset, flowStatus: "processing" };
218
+ }
219
+ if (check?.state === "failed") {
220
+ // The worker already reported the failure — show it now; core flips moments later.
221
+ return { ...asset, flowStatus: "failed", errorMessage: check.errorMessage };
222
+ }
223
+ // No worker signal at all. Past the grace window that means the upload was interrupted
224
+ // — presentational verdict only, core stays #Pending until the sweep closes it durably.
225
+ const ageMs = Date.now() - Number(asset.createdAt / 1000000n);
226
+ if (ageMs > unknownGraceMs) {
227
+ return { ...asset, flowStatus: "failed", errorMessage: { error: "TRANSCODING_INTERRUPTED" } };
228
+ }
229
+ return { ...asset, flowStatus: "pending" };
178
230
  }
179
231
  class WorkerHttpError extends Error {
180
232
  status;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsm-mit/sultana-core-motoko-package",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "A TypeScript library for interacting with the Sultana Core Motoko actor on the Internet Computer (IC) platform.",
5
5
  "homepage": "https://github.com/JSM-Sultana/sultana-core-motoko-package#readme",
6
6
  "bugs": {