@rotorsoft/act-http 1.10.21 → 1.10.23

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 (60) hide show
  1. package/README.md +11 -6
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/@types/api/dispatch.d.ts +44 -0
  4. package/dist/@types/api/dispatch.d.ts.map +1 -0
  5. package/dist/@types/api/sse-wiring.d.ts +1 -1
  6. package/dist/@types/hono/index.d.ts +2 -20
  7. package/dist/@types/hono/index.d.ts.map +1 -1
  8. package/dist/@types/openapi/index.d.ts +2 -19
  9. package/dist/@types/openapi/index.d.ts.map +1 -1
  10. package/dist/@types/receiver/express/index.d.ts.map +1 -1
  11. package/dist/@types/receiver/fastify/index.d.ts.map +1 -1
  12. package/dist/@types/receiver/finalize.d.ts +15 -2
  13. package/dist/@types/receiver/finalize.d.ts.map +1 -1
  14. package/dist/@types/receiver/hono/index.d.ts.map +1 -1
  15. package/dist/@types/receiver/index.d.ts +8 -4
  16. package/dist/@types/receiver/index.d.ts.map +1 -1
  17. package/dist/@types/receiver/trpc/index.d.ts.map +1 -1
  18. package/dist/@types/trpc/index.d.ts +19 -91
  19. package/dist/@types/trpc/index.d.ts.map +1 -1
  20. package/dist/api/index.cjs.map +1 -1
  21. package/dist/api/index.js +1 -1
  22. package/dist/{chunk-DMDU25DN.js → chunk-G5FNOSDX.js} +5 -3
  23. package/dist/{chunk-DMDU25DN.js.map → chunk-G5FNOSDX.js.map} +1 -1
  24. package/dist/chunk-H545LMMV.js +28 -0
  25. package/dist/chunk-H545LMMV.js.map +1 -0
  26. package/dist/{chunk-KC2NW7XQ.js → chunk-TTVMQYNN.js} +8 -17
  27. package/dist/chunk-TTVMQYNN.js.map +1 -0
  28. package/dist/{chunk-BGXQRSSQ.js → chunk-ZQGGGU4E.js} +1 -1
  29. package/dist/chunk-ZQGGGU4E.js.map +1 -0
  30. package/dist/hono/index.cjs +72 -64
  31. package/dist/hono/index.cjs.map +1 -1
  32. package/dist/hono/index.js +44 -53
  33. package/dist/hono/index.js.map +1 -1
  34. package/dist/openapi/index.cjs.map +1 -1
  35. package/dist/openapi/index.js.map +1 -1
  36. package/dist/receiver/express/index.cjs +4 -12
  37. package/dist/receiver/express/index.cjs.map +1 -1
  38. package/dist/receiver/express/index.js +3 -13
  39. package/dist/receiver/express/index.js.map +1 -1
  40. package/dist/receiver/fastify/index.cjs +4 -12
  41. package/dist/receiver/fastify/index.cjs.map +1 -1
  42. package/dist/receiver/fastify/index.js +3 -13
  43. package/dist/receiver/fastify/index.js.map +1 -1
  44. package/dist/receiver/hono/index.cjs +8 -15
  45. package/dist/receiver/hono/index.cjs.map +1 -1
  46. package/dist/receiver/hono/index.js +2 -2
  47. package/dist/receiver/index.cjs +8 -15
  48. package/dist/receiver/index.cjs.map +1 -1
  49. package/dist/receiver/index.js +2 -2
  50. package/dist/receiver/trpc/index.cjs +8 -15
  51. package/dist/receiver/trpc/index.cjs.map +1 -1
  52. package/dist/receiver/trpc/index.js +7 -16
  53. package/dist/receiver/trpc/index.js.map +1 -1
  54. package/dist/trpc/index.cjs +54 -55
  55. package/dist/trpc/index.cjs.map +1 -1
  56. package/dist/trpc/index.js +26 -44
  57. package/dist/trpc/index.js.map +1 -1
  58. package/package.json +4 -4
  59. package/dist/chunk-BGXQRSSQ.js.map +0 -1
  60. package/dist/chunk-KC2NW7XQ.js.map +0 -1
@@ -19744,6 +19744,23 @@ function date4(params) {
19744
19744
  return _coercedDate(ZodDate, params);
19745
19745
  }
19746
19746
 
19747
+ // src/api/idempotency.ts
19748
+ async function withIdempotency(store, key, handler) {
19749
+ const fresh = await store.claim(key);
19750
+ if (!fresh) {
19751
+ return { deduped: true };
19752
+ }
19753
+ let result;
19754
+ try {
19755
+ result = await handler();
19756
+ } catch (err) {
19757
+ await store.release(key);
19758
+ throw err;
19759
+ }
19760
+ await store.commit(key);
19761
+ return { deduped: false, result };
19762
+ }
19763
+
19747
19764
  // src/api/in-flight.ts
19748
19765
  function track_in_flight(store) {
19749
19766
  let tracker = trackers.get(store);
@@ -19804,6 +19821,23 @@ function make_tracker(store) {
19804
19821
  };
19805
19822
  }
19806
19823
 
19824
+ // src/api/dispatch.ts
19825
+ function make_dispatch(app, resolvers, store) {
19826
+ const tracker = store && track_in_flight(store);
19827
+ return async (action_name, input2, payload, ctx, actor, key) => {
19828
+ const stream = await resolvers.stream(action_name, input2, ctx);
19829
+ const expected = await resolvers.expectedVersion?.(action_name, input2, ctx);
19830
+ const target = expected === void 0 ? { stream, actor } : { stream, actor, expectedVersion: expected };
19831
+ const run = () => app.do(action_name, target, payload);
19832
+ if (!tracker) return { kind: "done", result: await run() };
19833
+ const k = key();
19834
+ if (!k) return { kind: "missing-key" };
19835
+ const outcome = await withIdempotency(tracker.store, k, run);
19836
+ if (!outcome.deduped) return { kind: "done", result: outcome.result };
19837
+ return { kind: tracker.in_flight(k) ? "in-flight" : "conflict" };
19838
+ };
19839
+ }
19840
+
19807
19841
  // src/api/errors.ts
19808
19842
  var import_act = require("@rotorsoft/act");
19809
19843
  var ERROR_MAP = {
@@ -19846,23 +19880,6 @@ function toApiError(err) {
19846
19880
  };
19847
19881
  }
19848
19882
 
19849
- // src/api/idempotency.ts
19850
- async function withIdempotency(store, key, handler) {
19851
- const fresh = await store.claim(key);
19852
- if (!fresh) {
19853
- return { deduped: true };
19854
- }
19855
- let result;
19856
- try {
19857
- result = await handler();
19858
- } catch (err) {
19859
- await store.release(key);
19860
- throw err;
19861
- }
19862
- await store.commit(key);
19863
- return { deduped: false, result };
19864
- }
19865
-
19866
19883
  // src/sse/types.ts
19867
19884
  var resync_frame = () => ({ _resync: true });
19868
19885
  var is_version_neutral = (msg) => msg._overlay === true || msg._resync === true;
@@ -20011,7 +20028,7 @@ function status_to_trpc_code(status) {
20011
20028
  }
20012
20029
  function trpc(app, options) {
20013
20030
  const t = import_server.initTRPC.context().create();
20014
- const tracker = options.idempotency ? track_in_flight(options.idempotency.store) : void 0;
20031
+ const dispatch = make_dispatch(app, options, options.idempotency?.store);
20015
20032
  const resolve_actor = async (host_ctx) => {
20016
20033
  try {
20017
20034
  return await options.actor(host_ctx);
@@ -20035,40 +20052,23 @@ function trpc(app, options) {
20035
20052
  input2,
20036
20053
  action_schema
20037
20054
  );
20038
- const stream = await options.stream(action_name, validated, host_ctx);
20039
- const expected_version = options.expectedVersion ? await options.expectedVersion(action_name, validated, host_ctx) : void 0;
20040
- const target = expected_version === void 0 ? { stream, actor } : { stream, actor, expectedVersion: expected_version };
20041
- if (options.idempotency) {
20042
- const key = options.idempotency.keyFrom(host_ctx);
20043
- if (!key) {
20044
- throw new import_server.TRPCError({
20045
- code: "BAD_REQUEST",
20046
- message: "Idempotency-Key required"
20047
- });
20048
- }
20049
- const outcome = await withIdempotency(
20050
- tracker.store,
20051
- key,
20052
- () => app.do(action_name, target, input2)
20053
- );
20054
- if (outcome.deduped && tracker.in_flight(key)) {
20055
- throw new import_server.TRPCError({
20056
- code: "SERVICE_UNAVAILABLE",
20057
- message: "Idempotency-Key in flight; the original request has not finished, retry later"
20058
- });
20059
- }
20060
- if (outcome.deduped) {
20061
- throw new import_server.TRPCError({
20062
- code: "CONFLICT",
20063
- message: "Idempotency-Key already used; original result not cached"
20064
- });
20065
- }
20066
- return outcome.result;
20067
- }
20068
- return await app.do(
20055
+ const outcome = await dispatch(
20069
20056
  action_name,
20070
- target,
20071
- input2
20057
+ validated,
20058
+ input2,
20059
+ host_ctx,
20060
+ actor,
20061
+ () => options.idempotency?.keyFrom(host_ctx)
20062
+ );
20063
+ if (outcome.kind === "done") return outcome.result;
20064
+ throw new import_server.TRPCError(
20065
+ outcome.kind === "missing-key" ? { code: "BAD_REQUEST", message: "Idempotency-Key required" } : outcome.kind === "in-flight" ? {
20066
+ code: "SERVICE_UNAVAILABLE",
20067
+ message: "Idempotency-Key in flight; the original request has not finished, retry later"
20068
+ } : {
20069
+ code: "CONFLICT",
20070
+ message: "Idempotency-Key already used; original result not cached"
20071
+ }
20072
20072
  );
20073
20073
  } catch (err) {
20074
20074
  if (err instanceof import_server.TRPCError) throw err;
@@ -20083,10 +20083,9 @@ function trpc(app, options) {
20083
20083
  );
20084
20084
  const sse_config = resolveSseConfig(options.sse);
20085
20085
  const sse_counter = new SseConnectionCounter(sse_config.maxConnections);
20086
- const state_names = /* @__PURE__ */ new Set();
20087
- for (const action of Object.values(app.registry.actions)) {
20088
- state_names.add(action.name);
20089
- }
20086
+ const state_names = new Set(
20087
+ Object.values(app.registry.actions).map((a) => a.name)
20088
+ );
20090
20089
  const sse_handlers = {};
20091
20090
  for (const state_name of state_names) {
20092
20091
  sse_handlers[state_name] = t.procedure.input(external_exports.object({ stream: external_exports.string().min(1) })).subscription(async function* ({ input: input2, ctx, signal }) {