@rotorsoft/act-http 1.10.22 → 1.10.24
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/README.md +7 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/api/dispatch.d.ts +44 -0
- package/dist/@types/api/dispatch.d.ts.map +1 -0
- package/dist/@types/hono/index.d.ts +2 -20
- package/dist/@types/hono/index.d.ts.map +1 -1
- package/dist/@types/openapi/index.d.ts +2 -19
- package/dist/@types/openapi/index.d.ts.map +1 -1
- package/dist/@types/sse/broadcast.d.ts +2 -3
- package/dist/@types/sse/broadcast.d.ts.map +1 -1
- package/dist/@types/trpc/index.d.ts +1 -73
- package/dist/@types/trpc/index.d.ts.map +1 -1
- package/dist/chunk-H545LMMV.js +28 -0
- package/dist/chunk-H545LMMV.js.map +1 -0
- package/dist/hono/index.cjs +72 -64
- package/dist/hono/index.cjs.map +1 -1
- package/dist/hono/index.js +43 -52
- package/dist/hono/index.js.map +1 -1
- package/dist/openapi/index.cjs.map +1 -1
- package/dist/openapi/index.js.map +1 -1
- package/dist/sse/index.cjs +1 -13
- package/dist/sse/index.cjs.map +1 -1
- package/dist/sse/index.js +1 -3
- package/dist/sse/index.js.map +1 -1
- package/dist/trpc/index.cjs +54 -55
- package/dist/trpc/index.cjs.map +1 -1
- package/dist/trpc/index.js +25 -43
- package/dist/trpc/index.js.map +1 -1
- package/package.json +6 -6
package/dist/trpc/index.cjs
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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 =
|
|
20087
|
-
|
|
20088
|
-
|
|
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 }) {
|