rivetkit 2.0.2 → 2.0.3

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