@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
package/src/Action.ts ADDED
@@ -0,0 +1,231 @@
1
+ import { type Effect, Predicate, Schema } from "effect";
2
+
3
+ const TypeId = "~@rivetkit/effect/Action";
4
+
5
+ export const isAction = (u: unknown): u is Action<any, any, any, any> =>
6
+ Predicate.hasProperty(u, TypeId);
7
+
8
+ /**
9
+ * A value-level definition for a non-durable, request-response call.
10
+ */
11
+ export interface Action<
12
+ Tag extends string,
13
+ Payload extends Schema.Top = Schema.Void,
14
+ Success extends Schema.Top = Schema.Void,
15
+ Error extends Schema.Top = Schema.Never,
16
+ > {
17
+ readonly [TypeId]: typeof TypeId;
18
+ readonly _tag: Tag;
19
+ readonly key: string;
20
+ /**
21
+ * Raw RivetKit clients omit the argument for no-payload actions, so
22
+ * the actor wrapper uses this to adapt only those calls to the Effect
23
+ * JSON Void codec's null representation.
24
+ */
25
+ readonly hasPayload: boolean;
26
+ readonly payloadSchema: Payload;
27
+ readonly successSchema: Success;
28
+ readonly errorSchema: Error;
29
+ }
30
+
31
+ /**
32
+ * Type-erased view of any `Action`. Useful for collections of actions
33
+ * where the specific schemas don't matter.
34
+ */
35
+ export interface Any {
36
+ readonly [TypeId]: typeof TypeId;
37
+ readonly _tag: string;
38
+ readonly key: string;
39
+ }
40
+
41
+ /**
42
+ * Like `Any`, but with the prop fields (`*Schema`) accessible. Used
43
+ * by internal builders that need to read schemas off an action.
44
+ */
45
+ export interface AnyWithProps {
46
+ readonly [TypeId]: typeof TypeId;
47
+ readonly _tag: string;
48
+ readonly key: string;
49
+ readonly hasPayload: boolean;
50
+ readonly payloadSchema: Schema.Top;
51
+ readonly successSchema: Schema.Top;
52
+ readonly errorSchema: Schema.Top;
53
+ }
54
+
55
+ // --- Type helpers ---------------------------------------------------
56
+
57
+ export type Tag<R> =
58
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
59
+ ? _Tag
60
+ : never;
61
+
62
+ export type PayloadSchema<R> =
63
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
64
+ ? _Payload
65
+ : never;
66
+
67
+ export type Payload<R> = PayloadSchema<R>["Type"];
68
+
69
+ /**
70
+ * The shape accepted by the payload schema's `make` constructor on the
71
+ * client side (i.e. before encoding). Useful for typing the call site.
72
+ */
73
+ export type PayloadConstructor<R> =
74
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
75
+ ? _Payload["~type.make.in"]
76
+ : never;
77
+
78
+ export type SuccessSchema<R> =
79
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
80
+ ? _Success
81
+ : never;
82
+
83
+ export type Success<R> = SuccessSchema<R>["Type"];
84
+
85
+ export type ErrorSchema<R> =
86
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
87
+ ? _Error
88
+ : never;
89
+
90
+ export type Error<R> = ErrorSchema<R>["Type"];
91
+
92
+ /**
93
+ * The full set of decoding/encoding services required by every schema
94
+ * referenced by the action. Code generators include this in the `R`
95
+ * channel of any effect that handles or invokes the action.
96
+ */
97
+ export type Services<R> =
98
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
99
+ ?
100
+ | _Payload["DecodingServices"]
101
+ | _Payload["EncodingServices"]
102
+ | _Success["DecodingServices"]
103
+ | _Success["EncodingServices"]
104
+ | _Error["DecodingServices"]
105
+ | _Error["EncodingServices"]
106
+ : never;
107
+
108
+ /**
109
+ * The subset of `Services` actually needed on the client side: encoding
110
+ * the payload, decoding the success response, decoding the error.
111
+ */
112
+ export type ServicesClient<R> =
113
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
114
+ ?
115
+ | _Payload["EncodingServices"]
116
+ | _Success["DecodingServices"]
117
+ | _Error["DecodingServices"]
118
+ : never;
119
+
120
+ /**
121
+ * The subset of `Services` needed on the server side: decoding the
122
+ * payload, encoding the success response, encoding the error.
123
+ */
124
+ export type ServicesServer<R> =
125
+ R extends Action<infer _Tag, infer _Payload, infer _Success, infer _Error>
126
+ ?
127
+ | _Payload["DecodingServices"]
128
+ | _Success["EncodingServices"]
129
+ | _Error["EncodingServices"]
130
+ : never;
131
+
132
+ /**
133
+ * Extract the action with the matching tag from a union of actions.
134
+ */
135
+ export type ExtractTag<R extends Any, Tag extends string> = R extends {
136
+ readonly _tag: Tag;
137
+ }
138
+ ? R
139
+ : never;
140
+
141
+ export type ResultFrom<R extends Any, Services> = R extends Action<
142
+ infer _Tag,
143
+ infer _Payload,
144
+ infer _Success,
145
+ infer _Error
146
+ >
147
+ ? Effect.Effect<_Success["Type"], _Error["Type"], Services>
148
+ : never;
149
+
150
+ // --- Implementation -------------------------------------------------
151
+
152
+ const Proto = {
153
+ [TypeId]: TypeId,
154
+ };
155
+
156
+ const makeProto = <
157
+ const Tag extends string,
158
+ Payload extends Schema.Top,
159
+ Success extends Schema.Top,
160
+ Error extends Schema.Top,
161
+ >(options: {
162
+ readonly _tag: Tag;
163
+ readonly hasPayload: boolean;
164
+ readonly payloadSchema: Payload;
165
+ readonly successSchema: Success;
166
+ readonly errorSchema: Error;
167
+ }): Action<Tag, Payload, Success, Error> => {
168
+ const self = Object.assign(Object.create(Proto), options);
169
+ self.key = `@rivetkit/effect/Action/${options._tag}`;
170
+ return self;
171
+ };
172
+
173
+ /**
174
+ * Define a Rivet Actor action.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * import { Schema } from "effect"
179
+ * import { Action } from "@rivetkit/effect"
180
+ *
181
+ * class CounterOverflow extends Schema.TaggedErrorClass<CounterOverflow>()(
182
+ * "CounterOverflow",
183
+ * { limit: Schema.Number },
184
+ * ) {}
185
+ *
186
+ * export const Increment = Action.make("Increment", {
187
+ * payload: { amount: Schema.Number },
188
+ * success: Schema.Number,
189
+ * error: CounterOverflow,
190
+ * })
191
+ * ```
192
+ */
193
+ export const make = <
194
+ const Tag extends string,
195
+ Payload extends Schema.Top | Schema.Struct.Fields = Schema.Void,
196
+ Success extends Schema.Top = Schema.Void,
197
+ Error extends Schema.Top = Schema.Never,
198
+ >(
199
+ tag: Tag,
200
+ options?: {
201
+ readonly payload?: Payload;
202
+ readonly success?: Success;
203
+ readonly error?: Error;
204
+ },
205
+ ): Action<
206
+ Tag,
207
+ Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload,
208
+ Success,
209
+ Error
210
+ > => {
211
+ const successSchema = options?.success ?? Schema.Void;
212
+ const errorSchema = options?.error ?? Schema.Never;
213
+ const hasPayload = options?.payload !== undefined;
214
+ const payloadSchema: Schema.Top = Schema.isSchema(options?.payload)
215
+ ? (options?.payload as any)
216
+ : options?.payload
217
+ ? Schema.Struct(options?.payload as any)
218
+ : Schema.Void;
219
+ return makeProto({
220
+ _tag: tag,
221
+ hasPayload,
222
+ payloadSchema,
223
+ successSchema,
224
+ errorSchema,
225
+ }) as Action<
226
+ Tag,
227
+ Payload extends Schema.Struct.Fields ? Schema.Struct<Payload> : Payload,
228
+ Success,
229
+ Error
230
+ >;
231
+ };