@oddington/sdk 0.1.81 → 0.1.82

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/browser.js CHANGED
@@ -8442,6 +8442,7 @@ var routineOperationMessages = {
8442
8442
  location;
8443
8443
  };
8444
8444
  function routineOperationFailure(value) {
8445
+ if (value instanceof RoutineOperationError) return value;
8445
8446
  let code = value?.code;
8446
8447
  return new RoutineOperationError(code && Object.hasOwn(routineOperationMessages, code) ? code : "unavailable");
8447
8448
  }
@@ -8513,7 +8514,23 @@ function routineOperations(routine, host) {
8513
8514
  let selectedItem = (id5) => (value) => {
8514
8515
  let item = parseQueueItem(value);
8515
8516
  return id5 !== void 0 && item.id !== id5 && fail3("unavailable"), item;
8516
- }, summary3 = (value) => {
8517
+ };
8518
+ async function managedQueue(operation2, input, parse, local2 = !1) {
8519
+ let transport;
8520
+ try {
8521
+ transport = routineTransport() ?? (local2 ? void 0 : void 0);
8522
+ } catch {
8523
+ return fail3("context_unavailable");
8524
+ }
8525
+ if (!transport) return fail3("context_unavailable");
8526
+ try {
8527
+ let result2 = parse(await transport.request(operation2, input));
8528
+ return transport.isCurrent() || fail3("context_unavailable"), result2;
8529
+ } catch (error) {
8530
+ throw transport.isCurrent() || fail3("context_unavailable"), routineOperationFailure(error);
8531
+ }
8532
+ }
8533
+ let summary3 = (value) => {
8517
8534
  let result2 = parseQueueSummary(value);
8518
8535
  return result2.routineId !== routine && fail3("unavailable"), result2;
8519
8536
  }, readRun = (id5) => (value) => parseRemoteRun(value, { routine, id: id5 }), runHandle = (id5) => routineRunHandle({
@@ -8530,22 +8547,11 @@ function routineOperations(routine, host) {
8530
8547
  async add(input, options = {}) {
8531
8548
  (!options || Object.keys(options).some((key) => key !== "idempotencyKey") || options.idempotencyKey !== void 0 && typeof options.idempotencyKey != "string") && fail3("invalid_input");
8532
8549
  let body = { input, ...options };
8533
- if (new TextEncoder().encode(json2(input)).byteLength > 262144 && fail3("invalid_input"), host) return request3(`${root}/queue/items`, selectedItem(), body);
8534
- let transport;
8535
- try {
8536
- transport = routineTransport() ?? void 0;
8537
- } catch {
8538
- return fail3("context_unavailable");
8539
- }
8540
- if (!transport) return fail3("context_unavailable");
8541
- try {
8542
- let result2 = selectedItem()(await transport.request("queue/add", { routineId: routine, ...body }));
8543
- return transport.isCurrent() || fail3("context_unavailable"), result2;
8544
- } catch (error) {
8545
- throw transport.isCurrent() || fail3("context_unavailable"), routineOperationFailure(error);
8546
- }
8550
+ return new TextEncoder().encode(json2(input)).byteLength > 262144 && fail3("invalid_input"), host ? request3(`${root}/queue/items`, selectedItem(), body) : managedQueue("queue/add", { routineId: routine, ...body }, selectedItem(), !0);
8551
+ },
8552
+ async remove(id5) {
8553
+ return id5 = identity2(id5), host ? request3(`${root}/queue/items/${id5}/remove`, selectedItem(id5), {}) : managedQueue("queue/remove", { routineId: routine, itemId: id5 }, selectedItem(id5));
8547
8554
  },
8548
- remove: (id5) => request3(`${root}/queue/items/${identity2(id5)}/remove`, selectedItem(id5), {}),
8549
8555
  retry: (id5, options) => ((!options || Object.keys(options).join() !== "failureId") && fail3("invalid_input"), identity2(options.failureId), request3(`${root}/queue/items/${identity2(id5)}/retry`, selectedItem(id5), options))
8550
8556
  },
8551
8557
  queries: {