@rivetkit/effect 0.0.0-06-09-refactor-rivetkit-split-workflow-context-into-workflowcontext-workflowstepcontext.e0c9540

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 (89) hide show
  1. package/dist/Action.d.ts +104 -0
  2. package/dist/Action.d.ts.map +1 -0
  3. package/dist/Action.js +50 -0
  4. package/dist/Action.js.map +1 -0
  5. package/dist/Actor.d.ts +133 -0
  6. package/dist/Actor.d.ts.map +1 -0
  7. package/dist/Actor.js +104 -0
  8. package/dist/Actor.js.map +1 -0
  9. package/dist/Client.d.ts +31 -0
  10. package/dist/Client.d.ts.map +1 -0
  11. package/dist/Client.js +98 -0
  12. package/dist/Client.js.map +1 -0
  13. package/dist/Logger.d.ts +29 -0
  14. package/dist/Logger.d.ts.map +1 -0
  15. package/dist/Logger.js +31 -0
  16. package/dist/Logger.js.map +1 -0
  17. package/dist/Registry.d.ts +72 -0
  18. package/dist/Registry.d.ts.map +1 -0
  19. package/dist/Registry.js +125 -0
  20. package/dist/Registry.js.map +1 -0
  21. package/dist/RivetError.d.ts +438 -0
  22. package/dist/RivetError.d.ts.map +1 -0
  23. package/dist/RivetError.js +873 -0
  24. package/dist/RivetError.js.map +1 -0
  25. package/dist/State.d.ts +123 -0
  26. package/dist/State.d.ts.map +1 -0
  27. package/dist/State.js +104 -0
  28. package/dist/State.js.map +1 -0
  29. package/dist/internal/ActionDispatcher.d.ts +14 -0
  30. package/dist/internal/ActionDispatcher.d.ts.map +1 -0
  31. package/dist/internal/ActionDispatcher.js +100 -0
  32. package/dist/internal/ActionDispatcher.js.map +1 -0
  33. package/dist/internal/ActionErrorEnvelope.d.ts +11 -0
  34. package/dist/internal/ActionErrorEnvelope.d.ts.map +1 -0
  35. package/dist/internal/ActionErrorEnvelope.js +14 -0
  36. package/dist/internal/ActionErrorEnvelope.js.map +1 -0
  37. package/dist/internal/ActorInstanceManager.d.ts +28 -0
  38. package/dist/internal/ActorInstanceManager.d.ts.map +1 -0
  39. package/dist/internal/ActorInstanceManager.js +51 -0
  40. package/dist/internal/ActorInstanceManager.js.map +1 -0
  41. package/dist/internal/ActorStateAdapter.d.ts +18 -0
  42. package/dist/internal/ActorStateAdapter.d.ts.map +1 -0
  43. package/dist/internal/ActorStateAdapter.js +29 -0
  44. package/dist/internal/ActorStateAdapter.js.map +1 -0
  45. package/dist/internal/StateOptions.d.ts +12 -0
  46. package/dist/internal/StateOptions.d.ts.map +1 -0
  47. package/dist/internal/StateOptions.js +2 -0
  48. package/dist/internal/StateOptions.js.map +1 -0
  49. package/dist/internal/logging.d.ts +23 -0
  50. package/dist/internal/logging.d.ts.map +1 -0
  51. package/dist/internal/logging.js +162 -0
  52. package/dist/internal/logging.js.map +1 -0
  53. package/dist/internal/tracing.d.ts +23 -0
  54. package/dist/internal/tracing.d.ts.map +1 -0
  55. package/dist/internal/tracing.js +30 -0
  56. package/dist/internal/tracing.js.map +1 -0
  57. package/dist/internal/utils.d.ts +7 -0
  58. package/dist/internal/utils.d.ts.map +1 -0
  59. package/dist/internal/utils.js +7 -0
  60. package/dist/internal/utils.js.map +1 -0
  61. package/dist/mod.d.ts +8 -0
  62. package/dist/mod.d.ts.map +1 -0
  63. package/dist/mod.js +8 -0
  64. package/dist/mod.js.map +1 -0
  65. package/package.json +46 -0
  66. package/src/Action.ts +231 -0
  67. package/src/Actor.test-d.ts +603 -0
  68. package/src/Actor.test.ts +206 -0
  69. package/src/Actor.ts +550 -0
  70. package/src/Client.test.ts +210 -0
  71. package/src/Client.ts +216 -0
  72. package/src/Logger.ts +43 -0
  73. package/src/Registry.test-d.ts +126 -0
  74. package/src/Registry.test.ts +411 -0
  75. package/src/Registry.ts +243 -0
  76. package/src/RivetError.test.ts +188 -0
  77. package/src/RivetError.ts +1044 -0
  78. package/src/State.test.ts +181 -0
  79. package/src/State.ts +224 -0
  80. package/src/internal/ActionDispatcher.ts +192 -0
  81. package/src/internal/ActionErrorEnvelope.ts +19 -0
  82. package/src/internal/ActorInstanceManager.ts +143 -0
  83. package/src/internal/ActorStateAdapter.ts +88 -0
  84. package/src/internal/StateOptions.ts +17 -0
  85. package/src/internal/logging.test.ts +288 -0
  86. package/src/internal/logging.ts +237 -0
  87. package/src/internal/tracing.ts +42 -0
  88. package/src/internal/utils.ts +12 -0
  89. package/src/mod.ts +7 -0
@@ -0,0 +1,188 @@
1
+ import { assert, describe, it } from "@effect/vitest";
2
+ import { RivetError } from "@rivetkit/effect";
3
+ import { Duration, Effect, Schema } from "effect";
4
+ import * as RivetkitErrors from "rivetkit/errors";
5
+
6
+ describe("RivetError", () => {
7
+ it("preserves non-Rivet causes as UnknownError", () => {
8
+ const cause = new Error("plain failure");
9
+ const error = RivetError.fromUnknown(cause);
10
+
11
+ assert.instanceOf(error, RivetError.RivetError);
12
+ assert.instanceOf(error.reason, RivetError.UnknownError);
13
+ assert.strictEqual(error.reason.message, "plain failure");
14
+ assert.strictEqual(error.reason.cause, cause);
15
+ });
16
+
17
+ it("allows UnknownError to wrap arbitrary causes", () => {
18
+ const cause = { group: "not-a-rivet-error", code: 123 };
19
+ const error = new RivetError.UnknownError({
20
+ message: "malformed failure",
21
+ cause,
22
+ });
23
+
24
+ assert.strictEqual(error.cause, cause);
25
+ assert.strictEqual(error.group, undefined);
26
+ assert.strictEqual(error.code, undefined);
27
+ });
28
+
29
+ it("keeps structured Rivet errors classified by group and code", () => {
30
+ const cause = new RivetkitErrors.RivetError(
31
+ "rivetkit",
32
+ RivetkitErrors.INTERNAL_ERROR_CODE,
33
+ "internal failure",
34
+ );
35
+ const error = RivetError.fromUnknown(cause);
36
+
37
+ assert.instanceOf(error.reason, RivetError.InternalError);
38
+ assert.strictEqual(error.reason.group, cause.group);
39
+ assert.strictEqual(error.reason.code, cause.code);
40
+ assert.strictEqual(error.reason.message, cause.message);
41
+ });
42
+
43
+ it("exposes normalized isRetryable on every reason", () => {
44
+ const restarting = RivetError.fromUnknown(
45
+ new RivetkitErrors.RivetError("actor", "restarting", "restarting"),
46
+ );
47
+ const forbidden = RivetError.fromUnknown(
48
+ new RivetkitErrors.RivetError("auth", "forbidden", "forbidden"),
49
+ );
50
+ const overloaded = RivetError.fromUnknown(
51
+ new RivetkitErrors.RivetError("actor", "overloaded", "overloaded"),
52
+ );
53
+ const serviceUnavailable = RivetError.fromUnknown(
54
+ new RivetkitErrors.RivetError(
55
+ "guard",
56
+ "service_unavailable",
57
+ "service unavailable",
58
+ ),
59
+ );
60
+ const incomingTooLong = RivetError.fromUnknown(
61
+ new RivetkitErrors.RivetError(
62
+ "message",
63
+ "incoming_too_long",
64
+ "too long",
65
+ ),
66
+ );
67
+
68
+ assert.strictEqual(restarting.isRetryable, true);
69
+ assert.strictEqual(restarting.reason.isRetryable, true);
70
+ assert.strictEqual(forbidden.isRetryable, false);
71
+ assert.strictEqual(overloaded.isRetryable, true);
72
+ assert.strictEqual(serviceUnavailable.isRetryable, true);
73
+ assert.strictEqual(incomingTooLong.isRetryable, false);
74
+ });
75
+
76
+ it("exposes retryAfter from ActorRestarting metadata", () => {
77
+ const restarting = RivetError.fromUnknown(
78
+ new RivetkitErrors.RivetError(
79
+ "actor",
80
+ "restarting",
81
+ "actor restarting",
82
+ { metadata: { retryAfterMs: 250 } },
83
+ ),
84
+ );
85
+ const restartingNoHint = RivetError.fromUnknown(
86
+ new RivetkitErrors.RivetError(
87
+ "actor",
88
+ "restarting",
89
+ "actor restarting",
90
+ ),
91
+ );
92
+
93
+ assert.instanceOf(restarting.reason, RivetError.ActorRestarting);
94
+ assert.deepStrictEqual(restarting.retryAfter, Duration.millis(250));
95
+ assert.deepStrictEqual(
96
+ restarting.reason.retryAfter,
97
+ Duration.millis(250),
98
+ );
99
+ assert.strictEqual(restartingNoHint.retryAfter, undefined);
100
+ });
101
+
102
+ it("returns retryAfter undefined for reasons without retry-timing hints", () => {
103
+ const overloaded = RivetError.fromUnknown(
104
+ new RivetkitErrors.RivetError("actor", "overloaded", "overloaded"),
105
+ );
106
+ assert.strictEqual(overloaded.retryAfter, undefined);
107
+ });
108
+
109
+ it("classifies known guard errors into specific reasons", () => {
110
+ const serviceUnavailable = RivetError.fromUnknown(
111
+ new RivetkitErrors.RivetError(
112
+ "guard",
113
+ "service_unavailable",
114
+ "service unavailable",
115
+ ),
116
+ );
117
+ const readyTimeout = RivetError.fromUnknown(
118
+ new RivetkitErrors.RivetError(
119
+ "guard",
120
+ "actor_ready_timeout",
121
+ "actor ready timeout",
122
+ ),
123
+ );
124
+ const tunnelTimeout = RivetError.fromUnknown(
125
+ new RivetkitErrors.RivetError(
126
+ "guard",
127
+ "tunnel_message_timeout",
128
+ "tunnel message timeout",
129
+ ),
130
+ );
131
+
132
+ assert.instanceOf(
133
+ serviceUnavailable.reason,
134
+ RivetError.GuardServiceUnavailable,
135
+ );
136
+ assert.instanceOf(
137
+ readyTimeout.reason,
138
+ RivetError.GuardActorReadyTimeout,
139
+ );
140
+ assert.instanceOf(
141
+ tunnelTimeout.reason,
142
+ RivetError.GuardTunnelMessageTimeout,
143
+ );
144
+ assert.strictEqual(
145
+ serviceUnavailable.reason.code,
146
+ "service_unavailable",
147
+ );
148
+ });
149
+
150
+ it("keeps unknown guard errors in UnknownError", () => {
151
+ const error = RivetError.fromUnknown(
152
+ new RivetkitErrors.RivetError(
153
+ "guard",
154
+ "new_guard_code",
155
+ "new guard code",
156
+ ),
157
+ );
158
+
159
+ assert.instanceOf(error.reason, RivetError.UnknownError);
160
+ assert.strictEqual(error.reason.code, "new_guard_code");
161
+ });
162
+
163
+ it("exposes action error decode failures with decode context", () => {
164
+ const cause = new RivetkitErrors.RivetError(
165
+ "user",
166
+ "CounterOverflow",
167
+ "counter overflow",
168
+ { metadata: { _tag: "EffectActionError", version: 1, error: {} } },
169
+ );
170
+ const schemaError = Effect.runSync(
171
+ Schema.decodeUnknownEffect(Schema.String)(123).pipe(Effect.flip),
172
+ );
173
+ const error = new RivetError.RivetError({
174
+ reason: new RivetError.ActionErrorDecodeFailed({
175
+ cause: schemaError,
176
+ rivetError: cause,
177
+ }),
178
+ });
179
+
180
+ assert.instanceOf(error.reason, RivetError.ActionErrorDecodeFailed);
181
+ assert.strictEqual(error.reason.cause, schemaError);
182
+ assert.strictEqual(error.reason.rivetError, cause);
183
+ assert.strictEqual(
184
+ error.reason.message,
185
+ "Failed to decode action error user.CounterOverflow",
186
+ );
187
+ });
188
+ });