@ohos-ports/rivetkit-effect 2.3.17-beta.0

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 +132 -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 +100 -0
  12. package/dist/Client.js.map +1 -0
  13. package/dist/Registry.d.ts +134 -0
  14. package/dist/Registry.d.ts.map +1 -0
  15. package/dist/Registry.js +178 -0
  16. package/dist/Registry.js.map +1 -0
  17. package/dist/RivetError.d.ts +480 -0
  18. package/dist/RivetError.d.ts.map +1 -0
  19. package/dist/RivetError.js +985 -0
  20. package/dist/RivetError.js.map +1 -0
  21. package/dist/RivetLogger.d.ts +41 -0
  22. package/dist/RivetLogger.d.ts.map +1 -0
  23. package/dist/RivetLogger.js +41 -0
  24. package/dist/RivetLogger.js.map +1 -0
  25. package/dist/State.d.ts +159 -0
  26. package/dist/State.d.ts.map +1 -0
  27. package/dist/State.js +98 -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 +24 -0
  44. package/dist/internal/ActorStateAdapter.js.map +1 -0
  45. package/dist/internal/StateOptions.d.ts +13 -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 +22 -0
  50. package/dist/internal/logging.d.ts.map +1 -0
  51. package/dist/internal/logging.js +138 -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 +56 -0
  66. package/src/Action.ts +231 -0
  67. package/src/Actor.test-d.ts +641 -0
  68. package/src/Actor.test.ts +209 -0
  69. package/src/Actor.ts +575 -0
  70. package/src/Client.test.ts +206 -0
  71. package/src/Client.ts +218 -0
  72. package/src/Registry.test-d.ts +126 -0
  73. package/src/Registry.test.ts +400 -0
  74. package/src/Registry.ts +304 -0
  75. package/src/RivetError.test.ts +199 -0
  76. package/src/RivetError.ts +1163 -0
  77. package/src/RivetLogger.ts +60 -0
  78. package/src/State.test.ts +340 -0
  79. package/src/State.ts +420 -0
  80. package/src/internal/ActionDispatcher.ts +189 -0
  81. package/src/internal/ActionErrorEnvelope.ts +19 -0
  82. package/src/internal/ActorInstanceManager.ts +137 -0
  83. package/src/internal/ActorStateAdapter.ts +82 -0
  84. package/src/internal/StateOptions.ts +21 -0
  85. package/src/internal/logging.test.ts +274 -0
  86. package/src/internal/logging.ts +197 -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,1163 @@
1
+ import { Duration, Option, Predicate, Record, Schema } from "effect";
2
+ import * as RivetkitErrors from "@ohos-ports/rivetkit/errors";
3
+
4
+ const ReasonTypeId = "~@rivetkit/effect/RivetError/Reason" as const;
5
+ const TypeId = "~@rivetkit/effect/RivetError" as const;
6
+
7
+ export class Forbidden extends Schema.TaggedErrorClass<Forbidden>(
8
+ `${ReasonTypeId}/Forbidden`,
9
+ )("Forbidden", {
10
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
11
+ }) {
12
+ readonly [ReasonTypeId] = ReasonTypeId;
13
+ override get message() {
14
+ return this.cause.message;
15
+ }
16
+ get group() {
17
+ return this.cause.group;
18
+ }
19
+ get code() {
20
+ return this.cause.code;
21
+ }
22
+ get metadata() {
23
+ return this.cause.metadata;
24
+ }
25
+ get actor() {
26
+ return this.cause.actor;
27
+ }
28
+ get statusCode() {
29
+ return this.cause.statusCode;
30
+ }
31
+ get public() {
32
+ return this.cause.public;
33
+ }
34
+ get rayId() {
35
+ return this.cause.rayId;
36
+ }
37
+ get isRetryable(): boolean {
38
+ return false;
39
+ }
40
+ }
41
+
42
+ export class ActorNotFound extends Schema.TaggedErrorClass<ActorNotFound>(
43
+ `${ReasonTypeId}/ActorNotFound`,
44
+ )("ActorNotFound", {
45
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
46
+ }) {
47
+ readonly [ReasonTypeId] = ReasonTypeId;
48
+ override get message() {
49
+ return this.cause.message;
50
+ }
51
+ get group() {
52
+ return this.cause.group;
53
+ }
54
+ get code() {
55
+ return this.cause.code;
56
+ }
57
+ get metadata() {
58
+ return this.cause.metadata;
59
+ }
60
+ get actor() {
61
+ return this.cause.actor;
62
+ }
63
+ get statusCode() {
64
+ return this.cause.statusCode;
65
+ }
66
+ get public() {
67
+ return this.cause.public;
68
+ }
69
+ get rayId() {
70
+ return this.cause.rayId;
71
+ }
72
+ get isRetryable(): boolean {
73
+ return false;
74
+ }
75
+ }
76
+
77
+ export class ActorStopping extends Schema.TaggedErrorClass<ActorStopping>(
78
+ `${ReasonTypeId}/ActorStopping`,
79
+ )("ActorStopping", {
80
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
81
+ }) {
82
+ readonly [ReasonTypeId] = ReasonTypeId;
83
+ override get message() {
84
+ return this.cause.message;
85
+ }
86
+ get group() {
87
+ return this.cause.group;
88
+ }
89
+ get code() {
90
+ return this.cause.code;
91
+ }
92
+ get metadata() {
93
+ return this.cause.metadata;
94
+ }
95
+ get actor() {
96
+ return this.cause.actor;
97
+ }
98
+ get statusCode() {
99
+ return this.cause.statusCode;
100
+ }
101
+ get public() {
102
+ return this.cause.public;
103
+ }
104
+ get rayId() {
105
+ return this.cause.rayId;
106
+ }
107
+ get isRetryable(): boolean {
108
+ return true;
109
+ }
110
+ }
111
+
112
+ export class ActorRestarting extends Schema.TaggedErrorClass<ActorRestarting>(
113
+ `${ReasonTypeId}/ActorRestarting`,
114
+ )("ActorRestarting", {
115
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
116
+ }) {
117
+ readonly [ReasonTypeId] = ReasonTypeId;
118
+ override get message() {
119
+ return this.cause.message;
120
+ }
121
+ get group() {
122
+ return this.cause.group;
123
+ }
124
+ get code() {
125
+ return this.cause.code;
126
+ }
127
+ get metadata() {
128
+ return this.cause.metadata;
129
+ }
130
+ get actor() {
131
+ return this.cause.actor;
132
+ }
133
+ get statusCode() {
134
+ return this.cause.statusCode;
135
+ }
136
+ get public() {
137
+ return this.cause.public;
138
+ }
139
+ get rayId() {
140
+ return this.cause.rayId;
141
+ }
142
+ get isRetryable(): boolean {
143
+ return true;
144
+ }
145
+ get retryAfter(): Duration.Duration | undefined {
146
+ if (!Predicate.isReadonlyObject(this.metadata)) return undefined;
147
+ return Record.get(this.metadata, "retryAfterMs").pipe(
148
+ Option.filter(Predicate.isNumber),
149
+ Option.map(Duration.millis),
150
+ Option.getOrUndefined,
151
+ );
152
+ }
153
+ }
154
+
155
+ export class ActionNotFound extends Schema.TaggedErrorClass<ActionNotFound>(
156
+ `${ReasonTypeId}/ActionNotFound`,
157
+ )("ActionNotFound", {
158
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
159
+ }) {
160
+ readonly [ReasonTypeId] = ReasonTypeId;
161
+ override get message() {
162
+ return this.cause.message;
163
+ }
164
+ get group() {
165
+ return this.cause.group;
166
+ }
167
+ get code() {
168
+ return this.cause.code;
169
+ }
170
+ get metadata() {
171
+ return this.cause.metadata;
172
+ }
173
+ get actor() {
174
+ return this.cause.actor;
175
+ }
176
+ get statusCode() {
177
+ return this.cause.statusCode;
178
+ }
179
+ get public() {
180
+ return this.cause.public;
181
+ }
182
+ get rayId() {
183
+ return this.cause.rayId;
184
+ }
185
+ get isRetryable(): boolean {
186
+ return false;
187
+ }
188
+ }
189
+
190
+ export class ActionTimedOut extends Schema.TaggedErrorClass<ActionTimedOut>(
191
+ `${ReasonTypeId}/ActionTimedOut`,
192
+ )("ActionTimedOut", { cause: Schema.instanceOf(RivetkitErrors.RivetError) }) {
193
+ readonly [ReasonTypeId] = ReasonTypeId;
194
+ override get message() {
195
+ return this.cause.message;
196
+ }
197
+ get group() {
198
+ return this.cause.group;
199
+ }
200
+ get code() {
201
+ return this.cause.code;
202
+ }
203
+ get metadata() {
204
+ return this.cause.metadata;
205
+ }
206
+ get actor() {
207
+ return this.cause.actor;
208
+ }
209
+ get statusCode() {
210
+ return this.cause.statusCode;
211
+ }
212
+ get public() {
213
+ return this.cause.public;
214
+ }
215
+ get rayId() {
216
+ return this.cause.rayId;
217
+ }
218
+ get isRetryable(): boolean {
219
+ return true;
220
+ }
221
+ }
222
+
223
+ export class ActionAborted extends Schema.TaggedErrorClass<ActionAborted>(
224
+ `${ReasonTypeId}/ActionAborted`,
225
+ )("ActionAborted", {
226
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
227
+ }) {
228
+ readonly [ReasonTypeId] = ReasonTypeId;
229
+ override get message() {
230
+ return this.cause.message;
231
+ }
232
+ get group() {
233
+ return this.cause.group;
234
+ }
235
+ get code() {
236
+ return this.cause.code;
237
+ }
238
+ get metadata() {
239
+ return this.cause.metadata;
240
+ }
241
+ get actor() {
242
+ return this.cause.actor;
243
+ }
244
+ get statusCode() {
245
+ return this.cause.statusCode;
246
+ }
247
+ get public() {
248
+ return this.cause.public;
249
+ }
250
+ get rayId() {
251
+ return this.cause.rayId;
252
+ }
253
+ get isRetryable(): boolean {
254
+ return false;
255
+ }
256
+ }
257
+
258
+ export class ActorOverloaded extends Schema.TaggedErrorClass<ActorOverloaded>(
259
+ `${ReasonTypeId}/ActorOverloaded`,
260
+ )("ActorOverloaded", {
261
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
262
+ }) {
263
+ readonly [ReasonTypeId] = ReasonTypeId;
264
+ override get message() {
265
+ return this.cause.message;
266
+ }
267
+ get group() {
268
+ return this.cause.group;
269
+ }
270
+ get code() {
271
+ return this.cause.code;
272
+ }
273
+ get metadata() {
274
+ return this.cause.metadata;
275
+ }
276
+ get actor() {
277
+ return this.cause.actor;
278
+ }
279
+ get statusCode() {
280
+ return this.cause.statusCode;
281
+ }
282
+ get public() {
283
+ return this.cause.public;
284
+ }
285
+ get rayId() {
286
+ return this.cause.rayId;
287
+ }
288
+ get isRetryable(): boolean {
289
+ return true;
290
+ }
291
+ }
292
+
293
+ export class IncomingMessageTooLong extends Schema.TaggedErrorClass<IncomingMessageTooLong>(
294
+ `${ReasonTypeId}/IncomingMessageTooLong`,
295
+ )("IncomingMessageTooLong", {
296
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
297
+ }) {
298
+ readonly [ReasonTypeId] = ReasonTypeId;
299
+ override get message() {
300
+ return this.cause.message;
301
+ }
302
+ get group() {
303
+ return this.cause.group;
304
+ }
305
+ get code() {
306
+ return this.cause.code;
307
+ }
308
+ get metadata() {
309
+ return this.cause.metadata;
310
+ }
311
+ get actor() {
312
+ return this.cause.actor;
313
+ }
314
+ get statusCode() {
315
+ return this.cause.statusCode;
316
+ }
317
+ get public() {
318
+ return this.cause.public;
319
+ }
320
+ get rayId() {
321
+ return this.cause.rayId;
322
+ }
323
+ get isRetryable(): boolean {
324
+ return false;
325
+ }
326
+ }
327
+
328
+ export class OutgoingMessageTooLong extends Schema.TaggedErrorClass<OutgoingMessageTooLong>(
329
+ `${ReasonTypeId}/OutgoingMessageTooLong`,
330
+ )("OutgoingMessageTooLong", {
331
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
332
+ }) {
333
+ readonly [ReasonTypeId] = ReasonTypeId;
334
+ override get message() {
335
+ return this.cause.message;
336
+ }
337
+ get group() {
338
+ return this.cause.group;
339
+ }
340
+ get code() {
341
+ return this.cause.code;
342
+ }
343
+ get metadata() {
344
+ return this.cause.metadata;
345
+ }
346
+ get actor() {
347
+ return this.cause.actor;
348
+ }
349
+ get statusCode() {
350
+ return this.cause.statusCode;
351
+ }
352
+ get public() {
353
+ return this.cause.public;
354
+ }
355
+ get rayId() {
356
+ return this.cause.rayId;
357
+ }
358
+ get isRetryable(): boolean {
359
+ return false;
360
+ }
361
+ }
362
+
363
+ export class InvalidEncoding extends Schema.TaggedErrorClass<InvalidEncoding>(
364
+ `${ReasonTypeId}/InvalidEncoding`,
365
+ )("InvalidEncoding", {
366
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
367
+ }) {
368
+ readonly [ReasonTypeId] = ReasonTypeId;
369
+ override get message() {
370
+ return this.cause.message;
371
+ }
372
+ get group() {
373
+ return this.cause.group;
374
+ }
375
+ get code() {
376
+ return this.cause.code;
377
+ }
378
+ get metadata() {
379
+ return this.cause.metadata;
380
+ }
381
+ get actor() {
382
+ return this.cause.actor;
383
+ }
384
+ get statusCode() {
385
+ return this.cause.statusCode;
386
+ }
387
+ get public() {
388
+ return this.cause.public;
389
+ }
390
+ get rayId() {
391
+ return this.cause.rayId;
392
+ }
393
+ get isRetryable(): boolean {
394
+ return false;
395
+ }
396
+ }
397
+
398
+ export class InvalidRequest extends Schema.TaggedErrorClass<InvalidRequest>(
399
+ `${ReasonTypeId}/InvalidRequest`,
400
+ )("InvalidRequest", {
401
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
402
+ }) {
403
+ readonly [ReasonTypeId] = ReasonTypeId;
404
+ override get message() {
405
+ return this.cause.message;
406
+ }
407
+ get group() {
408
+ return this.cause.group;
409
+ }
410
+ get code() {
411
+ return this.cause.code;
412
+ }
413
+ get metadata() {
414
+ return this.cause.metadata;
415
+ }
416
+ get actor() {
417
+ return this.cause.actor;
418
+ }
419
+ get statusCode() {
420
+ return this.cause.statusCode;
421
+ }
422
+ get public() {
423
+ return this.cause.public;
424
+ }
425
+ get rayId() {
426
+ return this.cause.rayId;
427
+ }
428
+ get isRetryable(): boolean {
429
+ return false;
430
+ }
431
+ }
432
+
433
+ export class GuardActorReadyTimeout extends Schema.TaggedErrorClass<GuardActorReadyTimeout>(
434
+ `${ReasonTypeId}/GuardActorReadyTimeout`,
435
+ )("GuardActorReadyTimeout", {
436
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
437
+ }) {
438
+ readonly [ReasonTypeId] = ReasonTypeId;
439
+ override get message() {
440
+ return this.cause.message;
441
+ }
442
+ get group() {
443
+ return this.cause.group;
444
+ }
445
+ get code() {
446
+ return this.cause.code;
447
+ }
448
+ get metadata() {
449
+ return this.cause.metadata;
450
+ }
451
+ get actor() {
452
+ return this.cause.actor;
453
+ }
454
+ get statusCode() {
455
+ return this.cause.statusCode;
456
+ }
457
+ get public() {
458
+ return this.cause.public;
459
+ }
460
+ get rayId() {
461
+ return this.cause.rayId;
462
+ }
463
+ get isRetryable(): boolean {
464
+ return true;
465
+ }
466
+ }
467
+
468
+ export class GuardActorWakeRetriesExceeded extends Schema.TaggedErrorClass<GuardActorWakeRetriesExceeded>(
469
+ `${ReasonTypeId}/GuardActorWakeRetriesExceeded`,
470
+ )("GuardActorWakeRetriesExceeded", {
471
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
472
+ }) {
473
+ readonly [ReasonTypeId] = ReasonTypeId;
474
+ override get message() {
475
+ return this.cause.message;
476
+ }
477
+ get group() {
478
+ return this.cause.group;
479
+ }
480
+ get code() {
481
+ return this.cause.code;
482
+ }
483
+ get metadata() {
484
+ return this.cause.metadata;
485
+ }
486
+ get actor() {
487
+ return this.cause.actor;
488
+ }
489
+ get statusCode() {
490
+ return this.cause.statusCode;
491
+ }
492
+ get public() {
493
+ return this.cause.public;
494
+ }
495
+ get rayId() {
496
+ return this.cause.rayId;
497
+ }
498
+ get isRetryable(): boolean {
499
+ return true;
500
+ }
501
+ }
502
+
503
+ export class GuardActorRunnerFailed extends Schema.TaggedErrorClass<GuardActorRunnerFailed>(
504
+ `${ReasonTypeId}/GuardActorRunnerFailed`,
505
+ )("GuardActorRunnerFailed", {
506
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
507
+ }) {
508
+ readonly [ReasonTypeId] = ReasonTypeId;
509
+ override get message() {
510
+ return this.cause.message;
511
+ }
512
+ get group() {
513
+ return this.cause.group;
514
+ }
515
+ get code() {
516
+ return this.cause.code;
517
+ }
518
+ get metadata() {
519
+ return this.cause.metadata;
520
+ }
521
+ get actor() {
522
+ return this.cause.actor;
523
+ }
524
+ get statusCode() {
525
+ return this.cause.statusCode;
526
+ }
527
+ get public() {
528
+ return this.cause.public;
529
+ }
530
+ get rayId() {
531
+ return this.cause.rayId;
532
+ }
533
+ get isRetryable(): boolean {
534
+ return false;
535
+ }
536
+ }
537
+
538
+ export class GuardServiceUnavailable extends Schema.TaggedErrorClass<GuardServiceUnavailable>(
539
+ `${ReasonTypeId}/GuardServiceUnavailable`,
540
+ )("GuardServiceUnavailable", {
541
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
542
+ }) {
543
+ readonly [ReasonTypeId] = ReasonTypeId;
544
+ override get message() {
545
+ return this.cause.message;
546
+ }
547
+ get group() {
548
+ return this.cause.group;
549
+ }
550
+ get code() {
551
+ return this.cause.code;
552
+ }
553
+ get metadata() {
554
+ return this.cause.metadata;
555
+ }
556
+ get actor() {
557
+ return this.cause.actor;
558
+ }
559
+ get statusCode() {
560
+ return this.cause.statusCode;
561
+ }
562
+ get public() {
563
+ return this.cause.public;
564
+ }
565
+ get rayId() {
566
+ return this.cause.rayId;
567
+ }
568
+ get isRetryable(): boolean {
569
+ return true;
570
+ }
571
+ }
572
+
573
+ export class GuardActorStoppedWhileWaiting extends Schema.TaggedErrorClass<GuardActorStoppedWhileWaiting>(
574
+ `${ReasonTypeId}/GuardActorStoppedWhileWaiting`,
575
+ )("GuardActorStoppedWhileWaiting", {
576
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
577
+ }) {
578
+ readonly [ReasonTypeId] = ReasonTypeId;
579
+ override get message() {
580
+ return this.cause.message;
581
+ }
582
+ get group() {
583
+ return this.cause.group;
584
+ }
585
+ get code() {
586
+ return this.cause.code;
587
+ }
588
+ get metadata() {
589
+ return this.cause.metadata;
590
+ }
591
+ get actor() {
592
+ return this.cause.actor;
593
+ }
594
+ get statusCode() {
595
+ return this.cause.statusCode;
596
+ }
597
+ get public() {
598
+ return this.cause.public;
599
+ }
600
+ get rayId() {
601
+ return this.cause.rayId;
602
+ }
603
+ get isRetryable(): boolean {
604
+ return true;
605
+ }
606
+ }
607
+
608
+ export class GuardTunnelRequestAborted extends Schema.TaggedErrorClass<GuardTunnelRequestAborted>(
609
+ `${ReasonTypeId}/GuardTunnelRequestAborted`,
610
+ )("GuardTunnelRequestAborted", {
611
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
612
+ }) {
613
+ readonly [ReasonTypeId] = ReasonTypeId;
614
+ override get message() {
615
+ return this.cause.message;
616
+ }
617
+ get group() {
618
+ return this.cause.group;
619
+ }
620
+ get code() {
621
+ return this.cause.code;
622
+ }
623
+ get metadata() {
624
+ return this.cause.metadata;
625
+ }
626
+ get actor() {
627
+ return this.cause.actor;
628
+ }
629
+ get statusCode() {
630
+ return this.cause.statusCode;
631
+ }
632
+ get public() {
633
+ return this.cause.public;
634
+ }
635
+ get rayId() {
636
+ return this.cause.rayId;
637
+ }
638
+ get isRetryable(): boolean {
639
+ return true;
640
+ }
641
+ }
642
+
643
+ export class GuardTunnelMessageTimeout extends Schema.TaggedErrorClass<GuardTunnelMessageTimeout>(
644
+ `${ReasonTypeId}/GuardTunnelMessageTimeout`,
645
+ )("GuardTunnelMessageTimeout", {
646
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
647
+ }) {
648
+ readonly [ReasonTypeId] = ReasonTypeId;
649
+ override get message() {
650
+ return this.cause.message;
651
+ }
652
+ get group() {
653
+ return this.cause.group;
654
+ }
655
+ get code() {
656
+ return this.cause.code;
657
+ }
658
+ get metadata() {
659
+ return this.cause.metadata;
660
+ }
661
+ get actor() {
662
+ return this.cause.actor;
663
+ }
664
+ get statusCode() {
665
+ return this.cause.statusCode;
666
+ }
667
+ get public() {
668
+ return this.cause.public;
669
+ }
670
+ get rayId() {
671
+ return this.cause.rayId;
672
+ }
673
+ get isRetryable(): boolean {
674
+ return true;
675
+ }
676
+ }
677
+
678
+ export class GuardTunnelResponseClosed extends Schema.TaggedErrorClass<GuardTunnelResponseClosed>(
679
+ `${ReasonTypeId}/GuardTunnelResponseClosed`,
680
+ )("GuardTunnelResponseClosed", {
681
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
682
+ }) {
683
+ readonly [ReasonTypeId] = ReasonTypeId;
684
+ override get message() {
685
+ return this.cause.message;
686
+ }
687
+ get group() {
688
+ return this.cause.group;
689
+ }
690
+ get code() {
691
+ return this.cause.code;
692
+ }
693
+ get metadata() {
694
+ return this.cause.metadata;
695
+ }
696
+ get actor() {
697
+ return this.cause.actor;
698
+ }
699
+ get statusCode() {
700
+ return this.cause.statusCode;
701
+ }
702
+ get public() {
703
+ return this.cause.public;
704
+ }
705
+ get rayId() {
706
+ return this.cause.rayId;
707
+ }
708
+ get isRetryable(): boolean {
709
+ return true;
710
+ }
711
+ }
712
+
713
+ export class GuardGatewayResponseStartTimeout extends Schema.TaggedErrorClass<GuardGatewayResponseStartTimeout>(
714
+ `${ReasonTypeId}/GuardGatewayResponseStartTimeout`,
715
+ )("GuardGatewayResponseStartTimeout", {
716
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
717
+ }) {
718
+ readonly [ReasonTypeId] = ReasonTypeId;
719
+ override get message() {
720
+ return this.cause.message;
721
+ }
722
+ get group() {
723
+ return this.cause.group;
724
+ }
725
+ get code() {
726
+ return this.cause.code;
727
+ }
728
+ get metadata() {
729
+ return this.cause.metadata;
730
+ }
731
+ get actor() {
732
+ return this.cause.actor;
733
+ }
734
+ get statusCode() {
735
+ return this.cause.statusCode;
736
+ }
737
+ get public() {
738
+ return this.cause.public;
739
+ }
740
+ get rayId() {
741
+ return this.cause.rayId;
742
+ }
743
+ get isRetryable(): boolean {
744
+ return true;
745
+ }
746
+ }
747
+
748
+ export class InternalError extends Schema.TaggedErrorClass<InternalError>(
749
+ `${ReasonTypeId}/InternalError`,
750
+ )("InternalError", {
751
+ cause: Schema.instanceOf(RivetkitErrors.RivetError),
752
+ }) {
753
+ readonly [ReasonTypeId] = ReasonTypeId;
754
+ override get message() {
755
+ return this.cause.message;
756
+ }
757
+ get group() {
758
+ return this.cause.group;
759
+ }
760
+ get code() {
761
+ return this.cause.code;
762
+ }
763
+ get metadata() {
764
+ return this.cause.metadata;
765
+ }
766
+ get actor() {
767
+ return this.cause.actor;
768
+ }
769
+ get statusCode() {
770
+ return this.cause.statusCode;
771
+ }
772
+ get public() {
773
+ return this.cause.public;
774
+ }
775
+ get rayId() {
776
+ return this.cause.rayId;
777
+ }
778
+ get isRetryable(): boolean {
779
+ return false;
780
+ }
781
+ }
782
+
783
+ export class ActionErrorDecodeFailed extends Schema.TaggedErrorClass<ActionErrorDecodeFailed>(
784
+ `${ReasonTypeId}/ActionErrorDecodeFailed`,
785
+ )("ActionErrorDecodeFailed", {
786
+ cause: Schema.instanceOf(Schema.SchemaError),
787
+ rivetError: Schema.instanceOf(RivetkitErrors.RivetError),
788
+ }) {
789
+ readonly [ReasonTypeId] = ReasonTypeId;
790
+ override get message() {
791
+ return `Failed to decode action error ${this.rivetError.group}.${this.rivetError.code}`;
792
+ }
793
+ get group() {
794
+ return this.rivetError.group;
795
+ }
796
+ get code() {
797
+ return this.rivetError.code;
798
+ }
799
+ get metadata() {
800
+ return this.rivetError.metadata;
801
+ }
802
+ get actor() {
803
+ return this.rivetError.actor;
804
+ }
805
+ get statusCode() {
806
+ return this.rivetError.statusCode;
807
+ }
808
+ get public() {
809
+ return this.rivetError.public;
810
+ }
811
+ get rayId() {
812
+ return this.rivetError.rayId;
813
+ }
814
+ get isRetryable(): boolean {
815
+ return false;
816
+ }
817
+ }
818
+
819
+ /**
820
+ * Open-ended user error reason. Used when the actor threw `UserError` but
821
+ * the failing action did not declare a matching schema in its `error`
822
+ * field — so we can't surface it as a typed domain error in the Effect
823
+ * error channel.
824
+ *
825
+ * Actions that declare their user errors via `Action.make({ error: ... })`
826
+ * receive those errors **typed** in the error channel; this reason is
827
+ * the catch-all for everything else.
828
+ */
829
+ export class UnknownUserError extends Schema.TaggedErrorClass<UnknownUserError>(
830
+ `${ReasonTypeId}/UnknownUserError`,
831
+ )("UnknownUserError", { cause: Schema.instanceOf(RivetkitErrors.RivetError) }) {
832
+ readonly [ReasonTypeId] = ReasonTypeId;
833
+ override get message() {
834
+ return this.cause.message;
835
+ }
836
+ get group() {
837
+ return this.cause.group;
838
+ }
839
+ get code() {
840
+ return this.cause.code;
841
+ }
842
+ get metadata() {
843
+ return this.cause.metadata;
844
+ }
845
+ get actor() {
846
+ return this.cause.actor;
847
+ }
848
+ get statusCode() {
849
+ return this.cause.statusCode;
850
+ }
851
+ get public() {
852
+ return this.cause.public;
853
+ }
854
+ get rayId() {
855
+ return this.cause.rayId;
856
+ }
857
+ get isRetryable(): boolean {
858
+ return false;
859
+ }
860
+ }
861
+
862
+ /**
863
+ * Forward-compatible catch-all for `(group, code)` pairs the SDK does
864
+ * not recognize yet, and for malformed non-Rivet failures. Known wire
865
+ * fields are mirrored when present, while `cause` preserves the raw input.
866
+ */
867
+ export class UnknownError extends Schema.TaggedErrorClass<UnknownError>(
868
+ `${ReasonTypeId}/UnknownError`,
869
+ )("UnknownError", {
870
+ message: Schema.String,
871
+ cause: Schema.Unknown,
872
+ }) {
873
+ readonly [ReasonTypeId] = ReasonTypeId;
874
+ get group() {
875
+ return this.cause instanceof RivetkitErrors.RivetError
876
+ ? this.cause.group
877
+ : undefined;
878
+ }
879
+ get code() {
880
+ return this.cause instanceof RivetkitErrors.RivetError
881
+ ? this.cause.code
882
+ : undefined;
883
+ }
884
+ get metadata() {
885
+ return this.cause instanceof RivetkitErrors.RivetError
886
+ ? this.cause.metadata
887
+ : undefined;
888
+ }
889
+ get actor() {
890
+ return this.cause instanceof RivetkitErrors.RivetError
891
+ ? this.cause.actor
892
+ : undefined;
893
+ }
894
+ get statusCode() {
895
+ return this.cause instanceof RivetkitErrors.RivetError
896
+ ? this.cause.statusCode
897
+ : undefined;
898
+ }
899
+ get public() {
900
+ return this.cause instanceof RivetkitErrors.RivetError
901
+ ? this.cause.public
902
+ : undefined;
903
+ }
904
+ get rayId() {
905
+ return this.cause instanceof RivetkitErrors.RivetError
906
+ ? this.cause.rayId
907
+ : undefined;
908
+ }
909
+ get isRetryable(): boolean {
910
+ return false;
911
+ }
912
+ }
913
+
914
+ export type RivetErrorReason =
915
+ | Forbidden
916
+ | ActorNotFound
917
+ | ActorStopping
918
+ | ActorRestarting
919
+ | ActionNotFound
920
+ | ActionTimedOut
921
+ | ActionAborted
922
+ | ActorOverloaded
923
+ | IncomingMessageTooLong
924
+ | OutgoingMessageTooLong
925
+ | InvalidEncoding
926
+ | InvalidRequest
927
+ | GuardActorReadyTimeout
928
+ | GuardActorWakeRetriesExceeded
929
+ | GuardActorRunnerFailed
930
+ | GuardServiceUnavailable
931
+ | GuardActorStoppedWhileWaiting
932
+ | GuardTunnelRequestAborted
933
+ | GuardTunnelMessageTimeout
934
+ | GuardTunnelResponseClosed
935
+ | GuardGatewayResponseStartTimeout
936
+ | InternalError
937
+ | UnknownUserError
938
+ | ActionErrorDecodeFailed
939
+ | UnknownError;
940
+
941
+ export const RivetErrorReason: Schema.Union<
942
+ [
943
+ typeof Forbidden,
944
+ typeof ActorNotFound,
945
+ typeof ActorStopping,
946
+ typeof ActorRestarting,
947
+ typeof ActionNotFound,
948
+ typeof ActionTimedOut,
949
+ typeof ActionAborted,
950
+ typeof ActorOverloaded,
951
+ typeof IncomingMessageTooLong,
952
+ typeof OutgoingMessageTooLong,
953
+ typeof InvalidEncoding,
954
+ typeof InvalidRequest,
955
+ typeof GuardActorReadyTimeout,
956
+ typeof GuardActorWakeRetriesExceeded,
957
+ typeof GuardActorRunnerFailed,
958
+ typeof GuardServiceUnavailable,
959
+ typeof GuardActorStoppedWhileWaiting,
960
+ typeof GuardTunnelRequestAborted,
961
+ typeof GuardTunnelMessageTimeout,
962
+ typeof GuardTunnelResponseClosed,
963
+ typeof GuardGatewayResponseStartTimeout,
964
+ typeof InternalError,
965
+ typeof ActionErrorDecodeFailed,
966
+ typeof UnknownUserError,
967
+ typeof UnknownError,
968
+ ]
969
+ > = Schema.Union([
970
+ Forbidden,
971
+ ActorNotFound,
972
+ ActorStopping,
973
+ ActorRestarting,
974
+ ActionNotFound,
975
+ ActionTimedOut,
976
+ ActionAborted,
977
+ ActorOverloaded,
978
+ IncomingMessageTooLong,
979
+ OutgoingMessageTooLong,
980
+ InvalidEncoding,
981
+ InvalidRequest,
982
+ GuardActorReadyTimeout,
983
+ GuardActorWakeRetriesExceeded,
984
+ GuardActorRunnerFailed,
985
+ GuardServiceUnavailable,
986
+ GuardActorStoppedWhileWaiting,
987
+ GuardTunnelRequestAborted,
988
+ GuardTunnelMessageTimeout,
989
+ GuardTunnelResponseClosed,
990
+ GuardGatewayResponseStartTimeout,
991
+ InternalError,
992
+ ActionErrorDecodeFailed,
993
+ UnknownUserError,
994
+ UnknownError,
995
+ ]);
996
+
997
+ export const isRivetErrorReason = (u: unknown): u is RivetErrorReason =>
998
+ Predicate.hasProperty(u, ReasonTypeId);
999
+
1000
+ /**
1001
+ * The infrastructure-failure error surfaced by `@rivetkit/effect`
1002
+ * calls. Wraps a discriminated `reason` of all known failure
1003
+ * modes.
1004
+ *
1005
+ * Recover with `Effect.catchReason` / `Effect.catchReasons` /
1006
+ * `Effect.unwrapReason`:
1007
+ *
1008
+ * ```ts
1009
+ * program.pipe(
1010
+ * Effect.catchReasons("RivetError", {
1011
+ * Forbidden: () => Effect.fail(new MyAuthError()),
1012
+ * ConnectionLost: () => Effect.logWarning("reconnecting"),
1013
+ * }),
1014
+ * )
1015
+ * ```
1016
+ *
1017
+ * User-defined errors declared on an action via `Action.make({ error })`
1018
+ * arrive in the typed error channel separately and do NOT flow through
1019
+ * `RivetError`.
1020
+ */
1021
+ export class RivetError extends Schema.TaggedErrorClass<RivetError>(
1022
+ "@rivetkit/effect/RivetError",
1023
+ )("RivetError", {
1024
+ reason: RivetErrorReason,
1025
+ }) {
1026
+ /** Marks this value as the top-level Rivet error wrapper for runtime guards. */
1027
+ readonly [TypeId] = TypeId;
1028
+
1029
+ /** Exposes the structured Rivet error reason as the JavaScript error cause. */
1030
+ override readonly cause = this.reason;
1031
+
1032
+ /** Uses the reason message when present, otherwise falls back to the reason tag. */
1033
+ override get message() {
1034
+ return this.reason.message || this.reason._tag;
1035
+ }
1036
+
1037
+ /** Delegates to the underlying reason's `group` if present. */
1038
+ get group(): string | undefined {
1039
+ return "group" in this.reason ? this.reason.group : undefined;
1040
+ }
1041
+
1042
+ /** Delegates to the underlying reason's `code` if present. */
1043
+ get code(): string | undefined {
1044
+ return "code" in this.reason ? this.reason.code : undefined;
1045
+ }
1046
+
1047
+ /** Delegates to the underlying reason's `metadata` if present. */
1048
+ get metadata(): unknown {
1049
+ return "metadata" in this.reason ? this.reason.metadata : undefined;
1050
+ }
1051
+
1052
+ /** Delegates to the underlying reason's `actor` if present. */
1053
+ get actor() {
1054
+ return "actor" in this.reason ? this.reason.actor : undefined;
1055
+ }
1056
+
1057
+ /** Delegates to the underlying reason's `statusCode` if present. */
1058
+ get statusCode(): number | undefined {
1059
+ return "statusCode" in this.reason ? this.reason.statusCode : undefined;
1060
+ }
1061
+
1062
+ /** Delegates to the underlying reason's `public` if present. */
1063
+ get public(): boolean | undefined {
1064
+ return "public" in this.reason ? this.reason.public : undefined;
1065
+ }
1066
+
1067
+ /** Delegates to the underlying reason's `rayId` if present. */
1068
+ get rayId(): string | undefined {
1069
+ return "rayId" in this.reason ? this.reason.rayId : undefined;
1070
+ }
1071
+
1072
+ /** Delegates to the underlying reason's `isRetryable` getter. */
1073
+ get isRetryable(): boolean {
1074
+ return this.reason.isRetryable;
1075
+ }
1076
+
1077
+ /** Delegates to the underlying reason's `retryAfter` if present. */
1078
+ get retryAfter(): Duration.Duration | undefined {
1079
+ return "retryAfter" in this.reason ? this.reason.retryAfter : undefined;
1080
+ }
1081
+ }
1082
+
1083
+ export const isRivetError = (u: unknown): u is RivetError =>
1084
+ Predicate.hasProperty(u, TypeId);
1085
+
1086
+ type MakeRivetErrorReason = (
1087
+ error: RivetkitErrors.RivetError,
1088
+ ) => RivetErrorReason;
1089
+
1090
+ const reasonByCode: { [key: string]: MakeRivetErrorReason | undefined } = {
1091
+ "auth.forbidden": (error) => new Forbidden({ cause: error }),
1092
+ "actor.not_found": (error) => new ActorNotFound({ cause: error }),
1093
+ "actor.stopping": (error) => new ActorStopping({ cause: error }),
1094
+ "actor.restarting": (error) => new ActorRestarting({ cause: error }),
1095
+ "actor.action_not_found": (error) => new ActionNotFound({ cause: error }),
1096
+ "actor.action_timed_out": (error) => new ActionTimedOut({ cause: error }),
1097
+ "actor.aborted": (error) => new ActionAborted({ cause: error }),
1098
+ "actor.overloaded": (error) => new ActorOverloaded({ cause: error }),
1099
+ [`actor.${RivetkitErrors.INTERNAL_ERROR_CODE}`]: (error) =>
1100
+ new InternalError({ cause: error }),
1101
+ [`core.${RivetkitErrors.INTERNAL_ERROR_CODE}`]: (error) =>
1102
+ new InternalError({ cause: error }),
1103
+ [`rivetkit.${RivetkitErrors.INTERNAL_ERROR_CODE}`]: (error) =>
1104
+ new InternalError({ cause: error }),
1105
+ "message.incoming_too_long": (error) =>
1106
+ new IncomingMessageTooLong({ cause: error }),
1107
+ "message.outgoing_too_long": (error) =>
1108
+ new OutgoingMessageTooLong({ cause: error }),
1109
+ "encoding.invalid": (error) => new InvalidEncoding({ cause: error }),
1110
+ "request.invalid": (error) => new InvalidRequest({ cause: error }),
1111
+ "guard.actor_ready_timeout": (error) =>
1112
+ new GuardActorReadyTimeout({ cause: error }),
1113
+ "guard.actor_wake_retries_exceeded": (error) =>
1114
+ new GuardActorWakeRetriesExceeded({ cause: error }),
1115
+ "guard.actor_runner_failed": (error) =>
1116
+ new GuardActorRunnerFailed({ cause: error }),
1117
+ "guard.service_unavailable": (error) =>
1118
+ new GuardServiceUnavailable({ cause: error }),
1119
+ "guard.actor_stopped_while_waiting": (error) =>
1120
+ new GuardActorStoppedWhileWaiting({ cause: error }),
1121
+ "guard.tunnel_request_aborted": (error) =>
1122
+ new GuardTunnelRequestAborted({ cause: error }),
1123
+ "guard.tunnel_message_timeout": (error) =>
1124
+ new GuardTunnelMessageTimeout({ cause: error }),
1125
+ "guard.tunnel_response_closed": (error) =>
1126
+ new GuardTunnelResponseClosed({ cause: error }),
1127
+ "guard.gateway_response_start_timeout": (error) =>
1128
+ new GuardGatewayResponseStartTimeout({ cause: error }),
1129
+ };
1130
+
1131
+ const reasonFromRivetkitRivetError = (
1132
+ error: RivetkitErrors.RivetError,
1133
+ ): RivetErrorReason => {
1134
+ const makeReason = reasonByCode[`${error.group}.${error.code}`];
1135
+ if (makeReason) return makeReason(error);
1136
+
1137
+ if (error.group === "user") return new UnknownUserError({ cause: error });
1138
+
1139
+ return new UnknownError({
1140
+ message: error.message,
1141
+ cause: error,
1142
+ });
1143
+ };
1144
+
1145
+ export const fromRivetkitRivetError = (
1146
+ error: RivetkitErrors.RivetError,
1147
+ ): RivetError => {
1148
+ return new RivetError({ reason: reasonFromRivetkitRivetError(error) });
1149
+ };
1150
+
1151
+ export const fromUnknown = (cause: unknown): RivetError => {
1152
+ if (isRivetError(cause)) return cause;
1153
+ if (RivetkitErrors.isRivetErrorLike(cause)) {
1154
+ return fromRivetkitRivetError(RivetkitErrors.toRivetError(cause));
1155
+ }
1156
+
1157
+ return new RivetError({
1158
+ reason: new UnknownError({
1159
+ message: cause instanceof Error ? cause.message : String(cause),
1160
+ cause,
1161
+ }),
1162
+ });
1163
+ };