rivetkit 2.0.2 → 2.0.4

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 (246) hide show
  1. package/README.md +3 -5
  2. package/dist/schemas/actor-persist/v1.ts +225 -0
  3. package/dist/schemas/client-protocol/v1.ts +435 -0
  4. package/dist/schemas/file-system-driver/v1.ts +102 -0
  5. package/dist/tsup/actor/errors.cjs +77 -0
  6. package/dist/tsup/actor/errors.cjs.map +1 -0
  7. package/dist/tsup/actor/errors.d.cts +156 -0
  8. package/dist/tsup/actor/errors.d.ts +156 -0
  9. package/dist/tsup/actor/errors.js +77 -0
  10. package/dist/tsup/actor/errors.js.map +1 -0
  11. package/dist/tsup/chunk-3F2YSRJL.js +117 -0
  12. package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
  13. package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
  14. package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
  15. package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
  16. package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
  17. package/dist/tsup/chunk-6LJT3QRL.cjs +539 -0
  18. package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
  19. package/dist/tsup/chunk-GICQ3YCU.cjs +1792 -0
  20. package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
  21. package/dist/tsup/chunk-H26RP6GD.js +251 -0
  22. package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
  23. package/dist/tsup/chunk-HI3HWJRC.js +20 -0
  24. package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
  25. package/dist/tsup/chunk-HLLF4B4Q.js +1792 -0
  26. package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
  27. package/dist/tsup/chunk-IH6CKNDW.cjs +117 -0
  28. package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
  29. package/dist/tsup/chunk-LV2S3OU3.js +250 -0
  30. package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
  31. package/dist/tsup/chunk-LWNKVZG5.cjs +251 -0
  32. package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
  33. package/dist/tsup/chunk-NFU2BBT5.js +374 -0
  34. package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
  35. package/dist/tsup/chunk-PQY7KKTL.js +539 -0
  36. package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
  37. package/dist/tsup/chunk-QK72M5JB.js +45 -0
  38. package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
  39. package/dist/tsup/chunk-QNNXFOQV.cjs +45 -0
  40. package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
  41. package/dist/tsup/chunk-SBHHJ6QS.cjs +374 -0
  42. package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
  43. package/dist/tsup/chunk-TQ62L3X7.js +325 -0
  44. package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
  45. package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
  46. package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
  47. package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
  48. package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
  49. package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
  50. package/dist/tsup/chunk-XJQHKJ4P.js.map +1 -0
  51. package/dist/tsup/client/mod.cjs +32 -0
  52. package/dist/tsup/client/mod.cjs.map +1 -0
  53. package/dist/tsup/client/mod.d.cts +20 -0
  54. package/dist/tsup/client/mod.d.ts +20 -0
  55. package/dist/tsup/client/mod.js +32 -0
  56. package/dist/tsup/client/mod.js.map +1 -0
  57. package/dist/tsup/common/log.cjs +21 -0
  58. package/dist/tsup/common/log.cjs.map +1 -0
  59. package/dist/tsup/common/log.d.cts +26 -0
  60. package/dist/tsup/common/log.d.ts +26 -0
  61. package/dist/tsup/common/log.js +21 -0
  62. package/dist/tsup/common/log.js.map +1 -0
  63. package/dist/tsup/common/websocket.cjs +10 -0
  64. package/dist/tsup/common/websocket.cjs.map +1 -0
  65. package/dist/tsup/common/websocket.d.cts +3 -0
  66. package/dist/tsup/common/websocket.d.ts +3 -0
  67. package/dist/tsup/common/websocket.js +10 -0
  68. package/dist/tsup/common/websocket.js.map +1 -0
  69. package/dist/tsup/common-CXCe7s6i.d.cts +218 -0
  70. package/dist/tsup/common-CXCe7s6i.d.ts +218 -0
  71. package/dist/tsup/connection-BI-6UIBJ.d.ts +2087 -0
  72. package/dist/tsup/connection-Dyd4NLGW.d.cts +2087 -0
  73. package/dist/tsup/driver-helpers/mod.cjs +30 -0
  74. package/dist/tsup/driver-helpers/mod.cjs.map +1 -0
  75. package/dist/tsup/driver-helpers/mod.d.cts +17 -0
  76. package/dist/tsup/driver-helpers/mod.d.ts +17 -0
  77. package/dist/tsup/driver-helpers/mod.js +30 -0
  78. package/dist/tsup/driver-helpers/mod.js.map +1 -0
  79. package/dist/tsup/driver-test-suite/mod.cjs +3411 -0
  80. package/dist/tsup/driver-test-suite/mod.cjs.map +1 -0
  81. package/dist/tsup/driver-test-suite/mod.d.cts +63 -0
  82. package/dist/tsup/driver-test-suite/mod.d.ts +63 -0
  83. package/dist/tsup/driver-test-suite/mod.js +3411 -0
  84. package/dist/tsup/driver-test-suite/mod.js.map +1 -0
  85. package/dist/tsup/inspector/mod.cjs +51 -0
  86. package/dist/tsup/inspector/mod.cjs.map +1 -0
  87. package/dist/tsup/inspector/mod.d.cts +408 -0
  88. package/dist/tsup/inspector/mod.d.ts +408 -0
  89. package/dist/tsup/inspector/mod.js +51 -0
  90. package/dist/tsup/inspector/mod.js.map +1 -0
  91. package/dist/tsup/mod.cjs +67 -0
  92. package/dist/tsup/mod.cjs.map +1 -0
  93. package/dist/tsup/mod.d.cts +105 -0
  94. package/dist/tsup/mod.d.ts +105 -0
  95. package/dist/tsup/mod.js +67 -0
  96. package/dist/tsup/mod.js.map +1 -0
  97. package/dist/tsup/router-endpoints-BTe_Rsdn.d.cts +65 -0
  98. package/dist/tsup/router-endpoints-CBSrKHmo.d.ts +65 -0
  99. package/dist/tsup/test/mod.cjs +17 -0
  100. package/dist/tsup/test/mod.cjs.map +1 -0
  101. package/dist/tsup/test/mod.d.cts +26 -0
  102. package/dist/tsup/test/mod.d.ts +26 -0
  103. package/dist/tsup/test/mod.js +17 -0
  104. package/dist/tsup/test/mod.js.map +1 -0
  105. package/dist/tsup/utils-fwx3o3K9.d.cts +18 -0
  106. package/dist/tsup/utils-fwx3o3K9.d.ts +18 -0
  107. package/dist/tsup/utils.cjs +26 -0
  108. package/dist/tsup/utils.cjs.map +1 -0
  109. package/dist/tsup/utils.d.cts +36 -0
  110. package/dist/tsup/utils.d.ts +36 -0
  111. package/dist/tsup/utils.js +26 -0
  112. package/dist/tsup/utils.js.map +1 -0
  113. package/package.json +208 -5
  114. package/src/actor/action.ts +178 -0
  115. package/src/actor/config.ts +497 -0
  116. package/src/actor/connection.ts +257 -0
  117. package/src/actor/context.ts +168 -0
  118. package/src/actor/database.ts +23 -0
  119. package/src/actor/definition.ts +82 -0
  120. package/src/actor/driver.ts +84 -0
  121. package/src/actor/errors.ts +422 -0
  122. package/src/actor/generic-conn-driver.ts +246 -0
  123. package/src/actor/instance.ts +1844 -0
  124. package/src/actor/keys.test.ts +266 -0
  125. package/src/actor/keys.ts +89 -0
  126. package/src/actor/log.ts +6 -0
  127. package/src/actor/mod.ts +108 -0
  128. package/src/actor/persisted.ts +42 -0
  129. package/src/actor/protocol/old.ts +297 -0
  130. package/src/actor/protocol/serde.ts +131 -0
  131. package/src/actor/router-endpoints.ts +688 -0
  132. package/src/actor/router.ts +265 -0
  133. package/src/actor/schedule.ts +17 -0
  134. package/src/actor/unstable-react.ts +110 -0
  135. package/src/actor/utils.ts +102 -0
  136. package/src/client/actor-common.ts +30 -0
  137. package/src/client/actor-conn.ts +865 -0
  138. package/src/client/actor-handle.ts +268 -0
  139. package/src/client/actor-query.ts +65 -0
  140. package/src/client/client.ts +554 -0
  141. package/src/client/config.ts +44 -0
  142. package/src/client/errors.ts +42 -0
  143. package/src/client/log.ts +5 -0
  144. package/src/client/mod.ts +60 -0
  145. package/src/client/raw-utils.ts +149 -0
  146. package/src/client/test.ts +44 -0
  147. package/src/client/utils.ts +152 -0
  148. package/src/common/eventsource-interface.ts +47 -0
  149. package/src/common/eventsource.ts +80 -0
  150. package/src/common/fake-event-source.ts +267 -0
  151. package/src/common/inline-websocket-adapter2.ts +454 -0
  152. package/src/common/log-levels.ts +27 -0
  153. package/src/common/log.ts +214 -0
  154. package/src/common/logfmt.ts +219 -0
  155. package/src/common/network.ts +2 -0
  156. package/src/common/router.ts +80 -0
  157. package/src/common/utils.ts +336 -0
  158. package/src/common/versioned-data.ts +95 -0
  159. package/src/common/websocket-interface.ts +49 -0
  160. package/src/common/websocket.ts +42 -0
  161. package/src/driver-helpers/mod.ts +22 -0
  162. package/src/driver-helpers/utils.ts +17 -0
  163. package/src/driver-test-suite/log.ts +5 -0
  164. package/src/driver-test-suite/mod.ts +239 -0
  165. package/src/driver-test-suite/tests/action-features.ts +136 -0
  166. package/src/driver-test-suite/tests/actor-conn-state.ts +249 -0
  167. package/src/driver-test-suite/tests/actor-conn.ts +349 -0
  168. package/src/driver-test-suite/tests/actor-driver.ts +25 -0
  169. package/src/driver-test-suite/tests/actor-error-handling.ts +158 -0
  170. package/src/driver-test-suite/tests/actor-handle.ts +292 -0
  171. package/src/driver-test-suite/tests/actor-inline-client.ts +152 -0
  172. package/src/driver-test-suite/tests/actor-inspector.ts +570 -0
  173. package/src/driver-test-suite/tests/actor-metadata.ts +116 -0
  174. package/src/driver-test-suite/tests/actor-onstatechange.ts +95 -0
  175. package/src/driver-test-suite/tests/actor-schedule.ts +108 -0
  176. package/src/driver-test-suite/tests/actor-sleep.ts +413 -0
  177. package/src/driver-test-suite/tests/actor-state.ts +54 -0
  178. package/src/driver-test-suite/tests/actor-vars.ts +93 -0
  179. package/src/driver-test-suite/tests/manager-driver.ts +367 -0
  180. package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -0
  181. package/src/driver-test-suite/tests/raw-http-request-properties.ts +414 -0
  182. package/src/driver-test-suite/tests/raw-http.ts +347 -0
  183. package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -0
  184. package/src/driver-test-suite/tests/raw-websocket.ts +484 -0
  185. package/src/driver-test-suite/tests/request-access.ts +230 -0
  186. package/src/driver-test-suite/utils.ts +71 -0
  187. package/src/drivers/default.ts +34 -0
  188. package/src/drivers/engine/actor-driver.ts +369 -0
  189. package/src/drivers/engine/config.ts +31 -0
  190. package/src/drivers/engine/kv.ts +3 -0
  191. package/src/drivers/engine/log.ts +5 -0
  192. package/src/drivers/engine/mod.ts +35 -0
  193. package/src/drivers/file-system/actor.ts +91 -0
  194. package/src/drivers/file-system/global-state.ts +686 -0
  195. package/src/drivers/file-system/log.ts +5 -0
  196. package/src/drivers/file-system/manager.ts +329 -0
  197. package/src/drivers/file-system/mod.ts +48 -0
  198. package/src/drivers/file-system/utils.ts +109 -0
  199. package/src/globals.d.ts +6 -0
  200. package/src/inspector/actor.ts +298 -0
  201. package/src/inspector/config.ts +88 -0
  202. package/src/inspector/log.ts +5 -0
  203. package/src/inspector/manager.ts +86 -0
  204. package/src/inspector/mod.ts +2 -0
  205. package/src/inspector/protocol/actor.ts +10 -0
  206. package/src/inspector/protocol/common.ts +196 -0
  207. package/src/inspector/protocol/manager.ts +10 -0
  208. package/src/inspector/protocol/mod.ts +2 -0
  209. package/src/inspector/utils.ts +76 -0
  210. package/src/manager/driver.ts +88 -0
  211. package/src/manager/hono-websocket-adapter.ts +342 -0
  212. package/src/manager/log.ts +5 -0
  213. package/src/manager/mod.ts +2 -0
  214. package/src/manager/protocol/mod.ts +24 -0
  215. package/src/manager/protocol/query.ts +89 -0
  216. package/src/manager/router.ts +412 -0
  217. package/src/manager-api/routes/actors-create.ts +16 -0
  218. package/src/manager-api/routes/actors-delete.ts +4 -0
  219. package/src/manager-api/routes/actors-get-by-id.ts +7 -0
  220. package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
  221. package/src/manager-api/routes/actors-get.ts +7 -0
  222. package/src/manager-api/routes/common.ts +18 -0
  223. package/src/mod.ts +18 -0
  224. package/src/registry/config.ts +32 -0
  225. package/src/registry/log.ts +5 -0
  226. package/src/registry/mod.ts +157 -0
  227. package/src/registry/run-config.ts +52 -0
  228. package/src/registry/serve.ts +52 -0
  229. package/src/remote-manager-driver/actor-http-client.ts +72 -0
  230. package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
  231. package/src/remote-manager-driver/api-endpoints.ts +79 -0
  232. package/src/remote-manager-driver/api-utils.ts +43 -0
  233. package/src/remote-manager-driver/log.ts +5 -0
  234. package/src/remote-manager-driver/mod.ts +274 -0
  235. package/src/remote-manager-driver/ws-proxy.ts +180 -0
  236. package/src/schemas/actor-persist/mod.ts +1 -0
  237. package/src/schemas/actor-persist/versioned.ts +25 -0
  238. package/src/schemas/client-protocol/mod.ts +1 -0
  239. package/src/schemas/client-protocol/versioned.ts +63 -0
  240. package/src/schemas/file-system-driver/mod.ts +1 -0
  241. package/src/schemas/file-system-driver/versioned.ts +28 -0
  242. package/src/serde.ts +90 -0
  243. package/src/test/config.ts +16 -0
  244. package/src/test/log.ts +5 -0
  245. package/src/test/mod.ts +154 -0
  246. package/src/utils.ts +172 -0
package/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  # RivetKit
2
2
 
3
- _Lightweight Libraries for Backends_
3
+ _Library to build and scale stateful workloads_
4
4
 
5
- **This is not the RivetKit you are looking for. See [`@rivetkit/actor`](https://www.npmjs.com/package/@rivetkit/core).**
5
+ [Learn More ](https://github.com/rivet-dev/rivetkit)
6
6
 
7
- [Learn More ](https://github.com/rivet-gg/rivetkit)
8
-
9
- [Discord](https://rivet.gg/discord) — [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-gg/rivetkit/issues)
7
+ [Discord](https://rivet.dev/discord) [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-dev/rivetkit/issues)
10
8
 
11
9
  ## License
12
10
 
@@ -0,0 +1,225 @@
1
+ import * as bare from "@bare-ts/lib"
2
+
3
+ const config = /* @__PURE__ */ bare.Config({})
4
+
5
+ export type u64 = bigint
6
+
7
+ export type PersistedSubscription = {
8
+ readonly eventName: string,
9
+ }
10
+
11
+ export function readPersistedSubscription(bc: bare.ByteCursor): PersistedSubscription {
12
+ return {
13
+ eventName: bare.readString(bc),
14
+ }
15
+ }
16
+
17
+ export function writePersistedSubscription(bc: bare.ByteCursor, x: PersistedSubscription): void {
18
+ bare.writeString(bc, x.eventName)
19
+ }
20
+
21
+ function read0(bc: bare.ByteCursor): readonly PersistedSubscription[] {
22
+ const len = bare.readUintSafe(bc)
23
+ if (len === 0) { return [] }
24
+ const result = [readPersistedSubscription(bc)]
25
+ for (let i = 1; i < len; i++) {
26
+ result[i] = readPersistedSubscription(bc)
27
+ }
28
+ return result
29
+ }
30
+
31
+ function write0(bc: bare.ByteCursor, x: readonly PersistedSubscription[]): void {
32
+ bare.writeUintSafe(bc, x.length)
33
+ for (let i = 0; i < x.length; i++) {
34
+ writePersistedSubscription(bc, x[i])
35
+ }
36
+ }
37
+
38
+ export type PersistedConnection = {
39
+ readonly id: string,
40
+ readonly token: string,
41
+ readonly driver: string,
42
+ readonly driverState: ArrayBuffer,
43
+ readonly parameters: ArrayBuffer,
44
+ readonly state: ArrayBuffer,
45
+ readonly subscriptions: readonly PersistedSubscription[],
46
+ readonly lastSeen: u64,
47
+ }
48
+
49
+ export function readPersistedConnection(bc: bare.ByteCursor): PersistedConnection {
50
+ return {
51
+ id: bare.readString(bc),
52
+ token: bare.readString(bc),
53
+ driver: bare.readString(bc),
54
+ driverState: bare.readData(bc),
55
+ parameters: bare.readData(bc),
56
+ state: bare.readData(bc),
57
+ subscriptions: read0(bc),
58
+ lastSeen: bare.readU64(bc),
59
+ }
60
+ }
61
+
62
+ export function writePersistedConnection(bc: bare.ByteCursor, x: PersistedConnection): void {
63
+ bare.writeString(bc, x.id)
64
+ bare.writeString(bc, x.token)
65
+ bare.writeString(bc, x.driver)
66
+ bare.writeData(bc, x.driverState)
67
+ bare.writeData(bc, x.parameters)
68
+ bare.writeData(bc, x.state)
69
+ write0(bc, x.subscriptions)
70
+ bare.writeU64(bc, x.lastSeen)
71
+ }
72
+
73
+ function read1(bc: bare.ByteCursor): ArrayBuffer | null {
74
+ return bare.readBool(bc)
75
+ ? bare.readData(bc)
76
+ : null
77
+ }
78
+
79
+ function write1(bc: bare.ByteCursor, x: ArrayBuffer | null): void {
80
+ bare.writeBool(bc, x !== null)
81
+ if (x !== null) {
82
+ bare.writeData(bc, x)
83
+ }
84
+ }
85
+
86
+ export type GenericPersistedScheduleEvent = {
87
+ readonly action: string,
88
+ readonly args: ArrayBuffer | null,
89
+ }
90
+
91
+ export function readGenericPersistedScheduleEvent(bc: bare.ByteCursor): GenericPersistedScheduleEvent {
92
+ return {
93
+ action: bare.readString(bc),
94
+ args: read1(bc),
95
+ }
96
+ }
97
+
98
+ export function writeGenericPersistedScheduleEvent(bc: bare.ByteCursor, x: GenericPersistedScheduleEvent): void {
99
+ bare.writeString(bc, x.action)
100
+ write1(bc, x.args)
101
+ }
102
+
103
+ export type PersistedScheduleEventKind =
104
+ | { readonly tag: "GenericPersistedScheduleEvent", readonly val: GenericPersistedScheduleEvent }
105
+
106
+ export function readPersistedScheduleEventKind(bc: bare.ByteCursor): PersistedScheduleEventKind {
107
+ const offset = bc.offset
108
+ const tag = bare.readU8(bc)
109
+ switch (tag) {
110
+ case 0:
111
+ return { tag: "GenericPersistedScheduleEvent", val: readGenericPersistedScheduleEvent(bc) }
112
+ default: {
113
+ bc.offset = offset
114
+ throw new bare.BareError(offset, "invalid tag")
115
+ }
116
+ }
117
+ }
118
+
119
+ export function writePersistedScheduleEventKind(bc: bare.ByteCursor, x: PersistedScheduleEventKind): void {
120
+ switch (x.tag) {
121
+ case "GenericPersistedScheduleEvent": {
122
+ bare.writeU8(bc, 0)
123
+ writeGenericPersistedScheduleEvent(bc, x.val)
124
+ break
125
+ }
126
+ }
127
+ }
128
+
129
+ export type PersistedScheduleEvent = {
130
+ readonly eventId: string,
131
+ readonly timestamp: u64,
132
+ readonly kind: PersistedScheduleEventKind,
133
+ }
134
+
135
+ export function readPersistedScheduleEvent(bc: bare.ByteCursor): PersistedScheduleEvent {
136
+ return {
137
+ eventId: bare.readString(bc),
138
+ timestamp: bare.readU64(bc),
139
+ kind: readPersistedScheduleEventKind(bc),
140
+ }
141
+ }
142
+
143
+ export function writePersistedScheduleEvent(bc: bare.ByteCursor, x: PersistedScheduleEvent): void {
144
+ bare.writeString(bc, x.eventId)
145
+ bare.writeU64(bc, x.timestamp)
146
+ writePersistedScheduleEventKind(bc, x.kind)
147
+ }
148
+
149
+ function read2(bc: bare.ByteCursor): readonly PersistedConnection[] {
150
+ const len = bare.readUintSafe(bc)
151
+ if (len === 0) { return [] }
152
+ const result = [readPersistedConnection(bc)]
153
+ for (let i = 1; i < len; i++) {
154
+ result[i] = readPersistedConnection(bc)
155
+ }
156
+ return result
157
+ }
158
+
159
+ function write2(bc: bare.ByteCursor, x: readonly PersistedConnection[]): void {
160
+ bare.writeUintSafe(bc, x.length)
161
+ for (let i = 0; i < x.length; i++) {
162
+ writePersistedConnection(bc, x[i])
163
+ }
164
+ }
165
+
166
+ function read3(bc: bare.ByteCursor): readonly PersistedScheduleEvent[] {
167
+ const len = bare.readUintSafe(bc)
168
+ if (len === 0) { return [] }
169
+ const result = [readPersistedScheduleEvent(bc)]
170
+ for (let i = 1; i < len; i++) {
171
+ result[i] = readPersistedScheduleEvent(bc)
172
+ }
173
+ return result
174
+ }
175
+
176
+ function write3(bc: bare.ByteCursor, x: readonly PersistedScheduleEvent[]): void {
177
+ bare.writeUintSafe(bc, x.length)
178
+ for (let i = 0; i < x.length; i++) {
179
+ writePersistedScheduleEvent(bc, x[i])
180
+ }
181
+ }
182
+
183
+ export type PersistedActor = {
184
+ readonly input: ArrayBuffer | null,
185
+ readonly hasInitialized: boolean,
186
+ readonly state: ArrayBuffer,
187
+ readonly connections: readonly PersistedConnection[],
188
+ readonly scheduledEvents: readonly PersistedScheduleEvent[],
189
+ }
190
+
191
+ export function readPersistedActor(bc: bare.ByteCursor): PersistedActor {
192
+ return {
193
+ input: read1(bc),
194
+ hasInitialized: bare.readBool(bc),
195
+ state: bare.readData(bc),
196
+ connections: read2(bc),
197
+ scheduledEvents: read3(bc),
198
+ }
199
+ }
200
+
201
+ export function writePersistedActor(bc: bare.ByteCursor, x: PersistedActor): void {
202
+ write1(bc, x.input)
203
+ bare.writeBool(bc, x.hasInitialized)
204
+ bare.writeData(bc, x.state)
205
+ write2(bc, x.connections)
206
+ write3(bc, x.scheduledEvents)
207
+ }
208
+
209
+ export function encodePersistedActor(x: PersistedActor): Uint8Array {
210
+ const bc = new bare.ByteCursor(
211
+ new Uint8Array(config.initialBufferLength),
212
+ config
213
+ )
214
+ writePersistedActor(bc, x)
215
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
216
+ }
217
+
218
+ export function decodePersistedActor(bytes: Uint8Array): PersistedActor {
219
+ const bc = new bare.ByteCursor(bytes, config)
220
+ const result = readPersistedActor(bc)
221
+ if (bc.offset < bc.view.byteLength) {
222
+ throw new bare.BareError(bc.offset, "remaining bytes")
223
+ }
224
+ return result
225
+ }
@@ -0,0 +1,435 @@
1
+ import * as bare from "@bare-ts/lib"
2
+
3
+ const config = /* @__PURE__ */ bare.Config({})
4
+
5
+ export type uint = bigint
6
+
7
+ export type Init = {
8
+ readonly actorId: string,
9
+ readonly connectionId: string,
10
+ readonly connectionToken: string,
11
+ }
12
+
13
+ export function readInit(bc: bare.ByteCursor): Init {
14
+ return {
15
+ actorId: bare.readString(bc),
16
+ connectionId: bare.readString(bc),
17
+ connectionToken: bare.readString(bc),
18
+ }
19
+ }
20
+
21
+ export function writeInit(bc: bare.ByteCursor, x: Init): void {
22
+ bare.writeString(bc, x.actorId)
23
+ bare.writeString(bc, x.connectionId)
24
+ bare.writeString(bc, x.connectionToken)
25
+ }
26
+
27
+ function read0(bc: bare.ByteCursor): ArrayBuffer | null {
28
+ return bare.readBool(bc)
29
+ ? bare.readData(bc)
30
+ : null
31
+ }
32
+
33
+ function write0(bc: bare.ByteCursor, x: ArrayBuffer | null): void {
34
+ bare.writeBool(bc, x !== null)
35
+ if (x !== null) {
36
+ bare.writeData(bc, x)
37
+ }
38
+ }
39
+
40
+ function read1(bc: bare.ByteCursor): uint | null {
41
+ return bare.readBool(bc)
42
+ ? bare.readUint(bc)
43
+ : null
44
+ }
45
+
46
+ function write1(bc: bare.ByteCursor, x: uint | null): void {
47
+ bare.writeBool(bc, x !== null)
48
+ if (x !== null) {
49
+ bare.writeUint(bc, x)
50
+ }
51
+ }
52
+
53
+ export type Error = {
54
+ readonly group: string,
55
+ readonly code: string,
56
+ readonly message: string,
57
+ readonly metadata: ArrayBuffer | null,
58
+ readonly actionId: uint | null,
59
+ }
60
+
61
+ export function readError(bc: bare.ByteCursor): Error {
62
+ return {
63
+ group: bare.readString(bc),
64
+ code: bare.readString(bc),
65
+ message: bare.readString(bc),
66
+ metadata: read0(bc),
67
+ actionId: read1(bc),
68
+ }
69
+ }
70
+
71
+ export function writeError(bc: bare.ByteCursor, x: Error): void {
72
+ bare.writeString(bc, x.group)
73
+ bare.writeString(bc, x.code)
74
+ bare.writeString(bc, x.message)
75
+ write0(bc, x.metadata)
76
+ write1(bc, x.actionId)
77
+ }
78
+
79
+ export type ActionResponse = {
80
+ readonly id: uint,
81
+ readonly output: ArrayBuffer,
82
+ }
83
+
84
+ export function readActionResponse(bc: bare.ByteCursor): ActionResponse {
85
+ return {
86
+ id: bare.readUint(bc),
87
+ output: bare.readData(bc),
88
+ }
89
+ }
90
+
91
+ export function writeActionResponse(bc: bare.ByteCursor, x: ActionResponse): void {
92
+ bare.writeUint(bc, x.id)
93
+ bare.writeData(bc, x.output)
94
+ }
95
+
96
+ export type Event = {
97
+ readonly name: string,
98
+ readonly args: ArrayBuffer,
99
+ }
100
+
101
+ export function readEvent(bc: bare.ByteCursor): Event {
102
+ return {
103
+ name: bare.readString(bc),
104
+ args: bare.readData(bc),
105
+ }
106
+ }
107
+
108
+ export function writeEvent(bc: bare.ByteCursor, x: Event): void {
109
+ bare.writeString(bc, x.name)
110
+ bare.writeData(bc, x.args)
111
+ }
112
+
113
+ export type ToClientBody =
114
+ | { readonly tag: "Init", readonly val: Init }
115
+ | { readonly tag: "Error", readonly val: Error }
116
+ | { readonly tag: "ActionResponse", readonly val: ActionResponse }
117
+ | { readonly tag: "Event", readonly val: Event }
118
+
119
+ export function readToClientBody(bc: bare.ByteCursor): ToClientBody {
120
+ const offset = bc.offset
121
+ const tag = bare.readU8(bc)
122
+ switch (tag) {
123
+ case 0:
124
+ return { tag: "Init", val: readInit(bc) }
125
+ case 1:
126
+ return { tag: "Error", val: readError(bc) }
127
+ case 2:
128
+ return { tag: "ActionResponse", val: readActionResponse(bc) }
129
+ case 3:
130
+ return { tag: "Event", val: readEvent(bc) }
131
+ default: {
132
+ bc.offset = offset
133
+ throw new bare.BareError(offset, "invalid tag")
134
+ }
135
+ }
136
+ }
137
+
138
+ export function writeToClientBody(bc: bare.ByteCursor, x: ToClientBody): void {
139
+ switch (x.tag) {
140
+ case "Init": {
141
+ bare.writeU8(bc, 0)
142
+ writeInit(bc, x.val)
143
+ break
144
+ }
145
+ case "Error": {
146
+ bare.writeU8(bc, 1)
147
+ writeError(bc, x.val)
148
+ break
149
+ }
150
+ case "ActionResponse": {
151
+ bare.writeU8(bc, 2)
152
+ writeActionResponse(bc, x.val)
153
+ break
154
+ }
155
+ case "Event": {
156
+ bare.writeU8(bc, 3)
157
+ writeEvent(bc, x.val)
158
+ break
159
+ }
160
+ }
161
+ }
162
+
163
+ export type ToClient = {
164
+ readonly body: ToClientBody,
165
+ }
166
+
167
+ export function readToClient(bc: bare.ByteCursor): ToClient {
168
+ return {
169
+ body: readToClientBody(bc),
170
+ }
171
+ }
172
+
173
+ export function writeToClient(bc: bare.ByteCursor, x: ToClient): void {
174
+ writeToClientBody(bc, x.body)
175
+ }
176
+
177
+ export function encodeToClient(x: ToClient): Uint8Array {
178
+ const bc = new bare.ByteCursor(
179
+ new Uint8Array(config.initialBufferLength),
180
+ config
181
+ )
182
+ writeToClient(bc, x)
183
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
184
+ }
185
+
186
+ export function decodeToClient(bytes: Uint8Array): ToClient {
187
+ const bc = new bare.ByteCursor(bytes, config)
188
+ const result = readToClient(bc)
189
+ if (bc.offset < bc.view.byteLength) {
190
+ throw new bare.BareError(bc.offset, "remaining bytes")
191
+ }
192
+ return result
193
+ }
194
+
195
+ export type ActionRequest = {
196
+ readonly id: uint,
197
+ readonly name: string,
198
+ readonly args: ArrayBuffer,
199
+ }
200
+
201
+ export function readActionRequest(bc: bare.ByteCursor): ActionRequest {
202
+ return {
203
+ id: bare.readUint(bc),
204
+ name: bare.readString(bc),
205
+ args: bare.readData(bc),
206
+ }
207
+ }
208
+
209
+ export function writeActionRequest(bc: bare.ByteCursor, x: ActionRequest): void {
210
+ bare.writeUint(bc, x.id)
211
+ bare.writeString(bc, x.name)
212
+ bare.writeData(bc, x.args)
213
+ }
214
+
215
+ export type SubscriptionRequest = {
216
+ readonly eventName: string,
217
+ readonly subscribe: boolean,
218
+ }
219
+
220
+ export function readSubscriptionRequest(bc: bare.ByteCursor): SubscriptionRequest {
221
+ return {
222
+ eventName: bare.readString(bc),
223
+ subscribe: bare.readBool(bc),
224
+ }
225
+ }
226
+
227
+ export function writeSubscriptionRequest(bc: bare.ByteCursor, x: SubscriptionRequest): void {
228
+ bare.writeString(bc, x.eventName)
229
+ bare.writeBool(bc, x.subscribe)
230
+ }
231
+
232
+ export type ToServerBody =
233
+ | { readonly tag: "ActionRequest", readonly val: ActionRequest }
234
+ | { readonly tag: "SubscriptionRequest", readonly val: SubscriptionRequest }
235
+
236
+ export function readToServerBody(bc: bare.ByteCursor): ToServerBody {
237
+ const offset = bc.offset
238
+ const tag = bare.readU8(bc)
239
+ switch (tag) {
240
+ case 0:
241
+ return { tag: "ActionRequest", val: readActionRequest(bc) }
242
+ case 1:
243
+ return { tag: "SubscriptionRequest", val: readSubscriptionRequest(bc) }
244
+ default: {
245
+ bc.offset = offset
246
+ throw new bare.BareError(offset, "invalid tag")
247
+ }
248
+ }
249
+ }
250
+
251
+ export function writeToServerBody(bc: bare.ByteCursor, x: ToServerBody): void {
252
+ switch (x.tag) {
253
+ case "ActionRequest": {
254
+ bare.writeU8(bc, 0)
255
+ writeActionRequest(bc, x.val)
256
+ break
257
+ }
258
+ case "SubscriptionRequest": {
259
+ bare.writeU8(bc, 1)
260
+ writeSubscriptionRequest(bc, x.val)
261
+ break
262
+ }
263
+ }
264
+ }
265
+
266
+ export type ToServer = {
267
+ readonly body: ToServerBody,
268
+ }
269
+
270
+ export function readToServer(bc: bare.ByteCursor): ToServer {
271
+ return {
272
+ body: readToServerBody(bc),
273
+ }
274
+ }
275
+
276
+ export function writeToServer(bc: bare.ByteCursor, x: ToServer): void {
277
+ writeToServerBody(bc, x.body)
278
+ }
279
+
280
+ export function encodeToServer(x: ToServer): Uint8Array {
281
+ const bc = new bare.ByteCursor(
282
+ new Uint8Array(config.initialBufferLength),
283
+ config
284
+ )
285
+ writeToServer(bc, x)
286
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
287
+ }
288
+
289
+ export function decodeToServer(bytes: Uint8Array): ToServer {
290
+ const bc = new bare.ByteCursor(bytes, config)
291
+ const result = readToServer(bc)
292
+ if (bc.offset < bc.view.byteLength) {
293
+ throw new bare.BareError(bc.offset, "remaining bytes")
294
+ }
295
+ return result
296
+ }
297
+
298
+ export type HttpActionRequest = {
299
+ readonly args: ArrayBuffer,
300
+ }
301
+
302
+ export function readHttpActionRequest(bc: bare.ByteCursor): HttpActionRequest {
303
+ return {
304
+ args: bare.readData(bc),
305
+ }
306
+ }
307
+
308
+ export function writeHttpActionRequest(bc: bare.ByteCursor, x: HttpActionRequest): void {
309
+ bare.writeData(bc, x.args)
310
+ }
311
+
312
+ export function encodeHttpActionRequest(x: HttpActionRequest): Uint8Array {
313
+ const bc = new bare.ByteCursor(
314
+ new Uint8Array(config.initialBufferLength),
315
+ config
316
+ )
317
+ writeHttpActionRequest(bc, x)
318
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
319
+ }
320
+
321
+ export function decodeHttpActionRequest(bytes: Uint8Array): HttpActionRequest {
322
+ const bc = new bare.ByteCursor(bytes, config)
323
+ const result = readHttpActionRequest(bc)
324
+ if (bc.offset < bc.view.byteLength) {
325
+ throw new bare.BareError(bc.offset, "remaining bytes")
326
+ }
327
+ return result
328
+ }
329
+
330
+ export type HttpActionResponse = {
331
+ readonly output: ArrayBuffer,
332
+ }
333
+
334
+ export function readHttpActionResponse(bc: bare.ByteCursor): HttpActionResponse {
335
+ return {
336
+ output: bare.readData(bc),
337
+ }
338
+ }
339
+
340
+ export function writeHttpActionResponse(bc: bare.ByteCursor, x: HttpActionResponse): void {
341
+ bare.writeData(bc, x.output)
342
+ }
343
+
344
+ export function encodeHttpActionResponse(x: HttpActionResponse): Uint8Array {
345
+ const bc = new bare.ByteCursor(
346
+ new Uint8Array(config.initialBufferLength),
347
+ config
348
+ )
349
+ writeHttpActionResponse(bc, x)
350
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
351
+ }
352
+
353
+ export function decodeHttpActionResponse(bytes: Uint8Array): HttpActionResponse {
354
+ const bc = new bare.ByteCursor(bytes, config)
355
+ const result = readHttpActionResponse(bc)
356
+ if (bc.offset < bc.view.byteLength) {
357
+ throw new bare.BareError(bc.offset, "remaining bytes")
358
+ }
359
+ return result
360
+ }
361
+
362
+ export type HttpResponseError = {
363
+ readonly group: string,
364
+ readonly code: string,
365
+ readonly message: string,
366
+ readonly metadata: ArrayBuffer | null,
367
+ }
368
+
369
+ export function readHttpResponseError(bc: bare.ByteCursor): HttpResponseError {
370
+ return {
371
+ group: bare.readString(bc),
372
+ code: bare.readString(bc),
373
+ message: bare.readString(bc),
374
+ metadata: read0(bc),
375
+ }
376
+ }
377
+
378
+ export function writeHttpResponseError(bc: bare.ByteCursor, x: HttpResponseError): void {
379
+ bare.writeString(bc, x.group)
380
+ bare.writeString(bc, x.code)
381
+ bare.writeString(bc, x.message)
382
+ write0(bc, x.metadata)
383
+ }
384
+
385
+ export function encodeHttpResponseError(x: HttpResponseError): Uint8Array {
386
+ const bc = new bare.ByteCursor(
387
+ new Uint8Array(config.initialBufferLength),
388
+ config
389
+ )
390
+ writeHttpResponseError(bc, x)
391
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
392
+ }
393
+
394
+ export function decodeHttpResponseError(bytes: Uint8Array): HttpResponseError {
395
+ const bc = new bare.ByteCursor(bytes, config)
396
+ const result = readHttpResponseError(bc)
397
+ if (bc.offset < bc.view.byteLength) {
398
+ throw new bare.BareError(bc.offset, "remaining bytes")
399
+ }
400
+ return result
401
+ }
402
+
403
+ export type HttpResolveRequest = null
404
+
405
+ export type HttpResolveResponse = {
406
+ readonly actorId: string,
407
+ }
408
+
409
+ export function readHttpResolveResponse(bc: bare.ByteCursor): HttpResolveResponse {
410
+ return {
411
+ actorId: bare.readString(bc),
412
+ }
413
+ }
414
+
415
+ export function writeHttpResolveResponse(bc: bare.ByteCursor, x: HttpResolveResponse): void {
416
+ bare.writeString(bc, x.actorId)
417
+ }
418
+
419
+ export function encodeHttpResolveResponse(x: HttpResolveResponse): Uint8Array {
420
+ const bc = new bare.ByteCursor(
421
+ new Uint8Array(config.initialBufferLength),
422
+ config
423
+ )
424
+ writeHttpResolveResponse(bc, x)
425
+ return new Uint8Array(bc.view.buffer, bc.view.byteOffset, bc.offset)
426
+ }
427
+
428
+ export function decodeHttpResolveResponse(bytes: Uint8Array): HttpResolveResponse {
429
+ const bc = new bare.ByteCursor(bytes, config)
430
+ const result = readHttpResolveResponse(bc)
431
+ if (bc.offset < bc.view.byteLength) {
432
+ throw new bare.BareError(bc.offset, "remaining bytes")
433
+ }
434
+ return result
435
+ }