rivetkit 0.0.0-sqlite-sync-3x-release.a00b07f → 0.0.0-sqlite-query-metrics-v2.f5d3605

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 (137) hide show
  1. package/dist/browser/client.d.ts +59 -99
  2. package/dist/browser/client.js +20 -193
  3. package/dist/browser/client.js.map +1 -1
  4. package/dist/browser/inspector/client.js +2 -1
  5. package/dist/browser/inspector/client.js.map +1 -1
  6. package/dist/tsup/{chunk-D5WUPE47.js → chunk-3URZ4UV5.js} +2 -2
  7. package/dist/tsup/{chunk-TSQTI6H6.js → chunk-D4G35VTO.js} +4 -4
  8. package/dist/tsup/{chunk-OTVJYZ2L.cjs → chunk-DDS7OOVF.cjs} +166 -326
  9. package/dist/tsup/chunk-DDS7OOVF.cjs.map +1 -0
  10. package/dist/tsup/{chunk-6KXVLIXL.cjs → chunk-DHL2M2E2.cjs} +3 -3
  11. package/dist/tsup/{chunk-6KXVLIXL.cjs.map → chunk-DHL2M2E2.cjs.map} +1 -1
  12. package/dist/tsup/{chunk-ZYK4B5WV.js → chunk-E2CUROR3.js} +2 -2
  13. package/dist/tsup/{chunk-JUWMP5O3.js → chunk-EPRA2TCT.js} +2 -2
  14. package/dist/tsup/{chunk-3DONDAMG.js → chunk-F7IGTKGM.js} +2 -2
  15. package/dist/tsup/{chunk-BTSDFFDC.cjs → chunk-FYDB45YU.cjs} +10 -10
  16. package/dist/tsup/{chunk-BTSDFFDC.cjs.map → chunk-FYDB45YU.cjs.map} +1 -1
  17. package/dist/tsup/{chunk-73RNTXHB.cjs → chunk-HO76AEDH.cjs} +3 -3
  18. package/dist/tsup/{chunk-73RNTXHB.cjs.map → chunk-HO76AEDH.cjs.map} +1 -1
  19. package/dist/tsup/{chunk-A2CF6PFH.js → chunk-JI6GZ2C2.js} +1 -18
  20. package/dist/tsup/chunk-JI6GZ2C2.js.map +1 -0
  21. package/dist/tsup/{chunk-Z7E2G3JZ.cjs → chunk-JW2WPE6Z.cjs} +4 -4
  22. package/dist/tsup/{chunk-Z7E2G3JZ.cjs.map → chunk-JW2WPE6Z.cjs.map} +1 -1
  23. package/dist/tsup/{chunk-2MOLY6AM.cjs → chunk-KDT56V3Y.cjs} +11 -10
  24. package/dist/tsup/chunk-KDT56V3Y.cjs.map +1 -0
  25. package/dist/tsup/{chunk-DJUBJQEQ.js → chunk-KSP3NXGY.js} +3 -3
  26. package/dist/tsup/{chunk-JUHXV3HF.cjs → chunk-L3Z3W44Q.cjs} +3 -3
  27. package/dist/tsup/{chunk-JUHXV3HF.cjs.map → chunk-L3Z3W44Q.cjs.map} +1 -1
  28. package/dist/tsup/{chunk-RTWH3AX3.cjs → chunk-MYWZCDML.cjs} +2 -19
  29. package/dist/tsup/chunk-MYWZCDML.cjs.map +1 -0
  30. package/dist/tsup/{chunk-TRUHDXOU.js → chunk-PJ5EXY6F.js} +25 -185
  31. package/dist/tsup/chunk-PJ5EXY6F.js.map +1 -0
  32. package/dist/tsup/{chunk-TM76Z7XT.cjs → chunk-QR6EAWEC.cjs} +7 -7
  33. package/dist/tsup/{chunk-TM76Z7XT.cjs.map → chunk-QR6EAWEC.cjs.map} +1 -1
  34. package/dist/tsup/{chunk-BRH4PQS5.js → chunk-USKGKQZM.js} +11 -10
  35. package/dist/tsup/chunk-USKGKQZM.js.map +1 -0
  36. package/dist/tsup/client/mod.cjs +6 -6
  37. package/dist/tsup/client/mod.d.cts +3 -15
  38. package/dist/tsup/client/mod.d.ts +3 -15
  39. package/dist/tsup/client/mod.js +5 -5
  40. package/dist/tsup/common/log.cjs +2 -2
  41. package/dist/tsup/common/log.js +1 -1
  42. package/dist/tsup/common/websocket.cjs +3 -3
  43. package/dist/tsup/common/websocket.js +2 -2
  44. package/dist/tsup/{config-DK144OAw.d.cts → config-CkmVg2fG.d.cts} +12 -58
  45. package/dist/tsup/{config-B4erdavw.d.ts → config-Cw_BwH_G.d.ts} +12 -58
  46. package/dist/tsup/{config-BfG1qpYz.d.cts → config-D4clT6mq.d.cts} +52 -34
  47. package/dist/tsup/{config-BfG1qpYz.d.ts → config-D4clT6mq.d.ts} +52 -34
  48. package/dist/tsup/{context-Oxi6YWcG.d.ts → context-BYOKTQJi.d.ts} +2 -2
  49. package/dist/tsup/{context-Cvnf3BRe.d.cts → context-_xIcgBnE.d.cts} +2 -2
  50. package/dist/tsup/db/drizzle.cjs +2 -2
  51. package/dist/tsup/db/drizzle.d.cts +1 -1
  52. package/dist/tsup/db/drizzle.d.ts +1 -1
  53. package/dist/tsup/db/drizzle.js +1 -1
  54. package/dist/tsup/db/mod.cjs +3 -3
  55. package/dist/tsup/db/mod.d.cts +2 -2
  56. package/dist/tsup/db/mod.d.ts +2 -2
  57. package/dist/tsup/db/mod.js +2 -2
  58. package/dist/tsup/dynamic/mod.d.cts +2 -2
  59. package/dist/tsup/dynamic/mod.d.ts +2 -2
  60. package/dist/tsup/inspector/mod.cjs +5 -5
  61. package/dist/tsup/inspector/mod.js +4 -4
  62. package/dist/tsup/inspector/workflow.cjs +4 -4
  63. package/dist/tsup/inspector/workflow.js +3 -3
  64. package/dist/tsup/inspector-tab/mod.d.cts +3 -3
  65. package/dist/tsup/inspector-tab/mod.d.ts +3 -3
  66. package/dist/tsup/mod.cjs +201 -548
  67. package/dist/tsup/mod.cjs.map +1 -1
  68. package/dist/tsup/mod.d.cts +4 -4
  69. package/dist/tsup/mod.d.ts +4 -4
  70. package/dist/tsup/mod.js +116 -463
  71. package/dist/tsup/mod.js.map +1 -1
  72. package/dist/tsup/test/mod.cjs +7 -7
  73. package/dist/tsup/test/mod.d.cts +2 -2
  74. package/dist/tsup/test/mod.d.ts +2 -2
  75. package/dist/tsup/test/mod.js +5 -5
  76. package/dist/tsup/unstable/migrations.d.cts +1 -1
  77. package/dist/tsup/unstable/migrations.d.ts +1 -1
  78. package/dist/tsup/utils.cjs +2 -2
  79. package/dist/tsup/utils.js +1 -1
  80. package/dist/tsup/workflow/mod.cjs +17 -17
  81. package/dist/tsup/workflow/mod.cjs.map +1 -1
  82. package/dist/tsup/workflow/mod.d.cts +4 -4
  83. package/dist/tsup/workflow/mod.d.ts +4 -4
  84. package/dist/tsup/workflow/mod.js +5 -5
  85. package/package.json +10 -9
  86. package/src/actor/config.test.ts +78 -0
  87. package/src/actor/keys.test.ts +275 -0
  88. package/src/actor/keys.ts +0 -86
  89. package/src/actor/utils.test.ts +48 -0
  90. package/src/client/actor-conn.ts +6 -92
  91. package/src/client/actor-handle.ts +3 -21
  92. package/src/client/client.ts +0 -6
  93. package/src/client/config.ts +1 -12
  94. package/src/client/lifecycle-errors.ts +1 -16
  95. package/src/client/test.ts +44 -0
  96. package/src/client/token-provider.test.ts +86 -0
  97. package/src/client/utils.ts +2 -13
  98. package/src/common/database/config.ts +52 -46
  99. package/src/common/database/mod.test.ts +364 -0
  100. package/src/common/database/native-database.test.ts +220 -0
  101. package/src/common/database/native-database.ts +27 -247
  102. package/src/common/inline-websocket-adapter.test.ts +51 -0
  103. package/src/common/router.ts +1 -1
  104. package/src/db/drizzle.test.ts +164 -0
  105. package/src/db/mod.ts +1 -0
  106. package/src/engine-api/actors.ts +3 -3
  107. package/src/engine-client/actor-websocket-client.ts +2 -4
  108. package/src/engine-client/api-endpoints.ts +14 -44
  109. package/src/engine-client/mod.ts +2 -2
  110. package/src/registry/config/envoy.ts +1 -1
  111. package/src/registry/config/index.test.ts +25 -0
  112. package/src/registry/config/index.ts +31 -28
  113. package/src/registry/index.ts +19 -51
  114. package/src/registry/napi-runtime.ts +2 -81
  115. package/src/registry/native.ts +51 -183
  116. package/src/registry/run-handler-coordinator.test.ts +252 -0
  117. package/src/registry/runtime.test.ts +124 -0
  118. package/src/registry/runtime.ts +10 -79
  119. package/src/registry/wasm-runtime.ts +3 -94
  120. package/src/unstable/migrations.test.ts +170 -0
  121. package/src/utils/endpoint-parser.test.ts +206 -0
  122. package/src/utils/env-vars.ts +10 -15
  123. package/src/utils.test.ts +34 -0
  124. package/src/workflow/driver.test.ts +62 -0
  125. package/dist/tsup/chunk-2MOLY6AM.cjs.map +0 -1
  126. package/dist/tsup/chunk-A2CF6PFH.js.map +0 -1
  127. package/dist/tsup/chunk-BRH4PQS5.js.map +0 -1
  128. package/dist/tsup/chunk-OTVJYZ2L.cjs.map +0 -1
  129. package/dist/tsup/chunk-RTWH3AX3.cjs.map +0 -1
  130. package/dist/tsup/chunk-TRUHDXOU.js.map +0 -1
  131. package/src/client/retry-budget.ts +0 -78
  132. /package/dist/tsup/{chunk-D5WUPE47.js.map → chunk-3URZ4UV5.js.map} +0 -0
  133. /package/dist/tsup/{chunk-TSQTI6H6.js.map → chunk-D4G35VTO.js.map} +0 -0
  134. /package/dist/tsup/{chunk-ZYK4B5WV.js.map → chunk-E2CUROR3.js.map} +0 -0
  135. /package/dist/tsup/{chunk-JUWMP5O3.js.map → chunk-EPRA2TCT.js.map} +0 -0
  136. /package/dist/tsup/{chunk-3DONDAMG.js.map → chunk-F7IGTKGM.js.map} +0 -0
  137. /package/dist/tsup/{chunk-DJUBJQEQ.js.map → chunk-KSP3NXGY.js.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rivetkit",
3
- "version": "0.0.0-sqlite-sync-3x-release.a00b07f",
3
+ "version": "0.0.0-sqlite-query-metrics-v2.f5d3605",
4
4
  "description": "Lightweight libraries for building stateful actors on edge platforms",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -210,16 +210,17 @@
210
210
  "dependencies": {
211
211
  "@hono/zod-openapi": "^1.1.5",
212
212
  "@opentelemetry/api": "^1.1.0",
213
+ "@rivet-dev/services": "^0.2.3",
213
214
  "@rivetkit/bare-ts": "^0.6.2",
214
- "@rivetkit/engine-api-full": "0.0.0-sqlite-sync-3x-release.a00b07f",
215
- "@rivetkit/engine-cli": "0.0.0-sqlite-sync-3x-release.a00b07f",
216
- "@rivetkit/engine-envoy-protocol": "0.0.0-sqlite-sync-3x-release.a00b07f",
215
+ "@rivetkit/engine-api-full": "0.0.0-sqlite-query-metrics-v2.f5d3605",
216
+ "@rivetkit/engine-cli": "0.0.0-sqlite-query-metrics-v2.f5d3605",
217
+ "@rivetkit/engine-envoy-protocol": "0.0.0-sqlite-query-metrics-v2.f5d3605",
217
218
  "@rivetkit/on-change": "6.0.1",
218
- "@rivetkit/rivetkit-napi": "0.0.0-sqlite-sync-3x-release.a00b07f",
219
- "@rivetkit/rivetkit-wasm": "0.0.0-sqlite-sync-3x-release.a00b07f",
220
- "@rivetkit/traces": "0.0.0-sqlite-sync-3x-release.a00b07f",
221
- "@rivetkit/virtual-websocket": "0.0.0-sqlite-sync-3x-release.a00b07f",
222
- "@rivetkit/workflow-engine": "0.0.0-sqlite-sync-3x-release.a00b07f",
219
+ "@rivetkit/rivetkit-napi": "0.0.0-sqlite-query-metrics-v2.f5d3605",
220
+ "@rivetkit/rivetkit-wasm": "0.0.0-sqlite-query-metrics-v2.f5d3605",
221
+ "@rivetkit/traces": "0.0.0-sqlite-query-metrics-v2.f5d3605",
222
+ "@rivetkit/virtual-websocket": "0.0.0-sqlite-query-metrics-v2.f5d3605",
223
+ "@rivetkit/workflow-engine": "0.0.0-sqlite-query-metrics-v2.f5d3605",
223
224
  "cbor-x": "^1.6.0",
224
225
  "drizzle-orm": "0.45.2",
225
226
  "hono": "^4.7.0",
@@ -0,0 +1,78 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import {
3
+ ActorOptionsSchema,
4
+ type DefineRunHandlerOptions,
5
+ defineRunHandler,
6
+ getRunFunction,
7
+ getRunInspectorKind,
8
+ getRunMetadata,
9
+ } from "./config";
10
+
11
+ describe("ActorOptionsSchema", () => {
12
+ test("keeps the Actor Runtime Socket opt-in", () => {
13
+ expect(ActorOptionsSchema.parse({}).enableActorRuntimeSocket).toBe(
14
+ false,
15
+ );
16
+ expect(
17
+ ActorOptionsSchema.parse({ enableActorRuntimeSocket: true })
18
+ .enableActorRuntimeSocket,
19
+ ).toBe(true);
20
+ });
21
+ });
22
+
23
+ describe("defineRunHandler", () => {
24
+ test("preserves the callable and exposes static metadata without creating an inspector", () => {
25
+ let inspectorCreates = 0;
26
+ const run = async (value: number): Promise<string> => String(value);
27
+ const defined = defineRunHandler(run, {
28
+ name: "Durable import",
29
+ icon: "diagram-project",
30
+ inspectorKind: "workflow",
31
+ createInspector: () => {
32
+ inspectorCreates += 1;
33
+ return {
34
+ inspector: {
35
+ workflow: {
36
+ getHistory: () => null,
37
+ getState: async () => null,
38
+ onHistoryUpdated: () => () => {},
39
+ replayFromStep: async () => null,
40
+ },
41
+ },
42
+ };
43
+ },
44
+ });
45
+
46
+ const exactType: (value: number) => Promise<string> = defined;
47
+ expect(exactType).toBe(run);
48
+ expect(getRunFunction(defined)).toBe(run);
49
+ expect(getRunMetadata(defined)).toEqual({
50
+ name: "Durable import",
51
+ icon: "diagram-project",
52
+ });
53
+ expect(getRunInspectorKind(defined)).toBe("workflow");
54
+ expect(inspectorCreates).toBe(0);
55
+ });
56
+
57
+ test("requires static inspector metadata and its factory together", () => {
58
+ expect(() =>
59
+ defineRunHandler(async () => {}, {
60
+ inspectorKind: "workflow",
61
+ } as unknown as DefineRunHandlerOptions),
62
+ ).toThrow("requires inspectorKind and createInspector together");
63
+ expect(() =>
64
+ defineRunHandler(async () => {}, {
65
+ createInspector: () => ({
66
+ inspector: {
67
+ workflow: {
68
+ getHistory: () => null,
69
+ getState: async () => null,
70
+ onHistoryUpdated: () => () => {},
71
+ replayFromStep: async () => null,
72
+ },
73
+ },
74
+ }),
75
+ } as unknown as DefineRunHandlerOptions),
76
+ ).toThrow("requires inspectorKind and createInspector together");
77
+ });
78
+ });
@@ -0,0 +1,275 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import {
3
+ deserializeActorKey,
4
+ EMPTY_KEY,
5
+ KEY_SEPARATOR,
6
+ serializeActorKey,
7
+ } from "./keys";
8
+
9
+ describe("Key serialization and deserialization", () => {
10
+ // Test serialization
11
+ describe("serializeActorKey", () => {
12
+ test("serializes empty key array", () => {
13
+ expect(serializeActorKey([])).toBe(EMPTY_KEY);
14
+ });
15
+
16
+ test("serializes single key", () => {
17
+ expect(serializeActorKey(["test"])).toBe("test");
18
+ });
19
+
20
+ test("serializes multiple keys", () => {
21
+ expect(serializeActorKey(["a", "b", "c"])).toBe(
22
+ `a${KEY_SEPARATOR}b${KEY_SEPARATOR}c`,
23
+ );
24
+ });
25
+
26
+ test("escapes forward slashes in keys", () => {
27
+ expect(serializeActorKey(["a/b"])).toBe("a\\/b");
28
+ expect(serializeActorKey(["a/b", "c"])).toBe(
29
+ `a\\/b${KEY_SEPARATOR}c`,
30
+ );
31
+ });
32
+
33
+ test("escapes empty key marker in keys", () => {
34
+ expect(serializeActorKey([EMPTY_KEY])).toBe(`\\${EMPTY_KEY}`);
35
+ });
36
+
37
+ test("handles complex keys", () => {
38
+ expect(serializeActorKey(["a/b", EMPTY_KEY, "c/d"])).toBe(
39
+ `a\\/b${KEY_SEPARATOR}\\${EMPTY_KEY}${KEY_SEPARATOR}c\\/d`,
40
+ );
41
+ });
42
+ });
43
+
44
+ // Test deserialization
45
+ describe("deserializeActorKey", () => {
46
+ test("deserializes empty string", () => {
47
+ expect(deserializeActorKey("")).toEqual([]);
48
+ });
49
+
50
+ test("deserializes undefined/null", () => {
51
+ expect(deserializeActorKey(undefined as unknown as string)).toEqual(
52
+ [],
53
+ );
54
+ expect(deserializeActorKey(null as unknown as string)).toEqual([]);
55
+ });
56
+
57
+ test("deserializes empty key marker", () => {
58
+ expect(deserializeActorKey(EMPTY_KEY)).toEqual([]);
59
+ });
60
+
61
+ test("deserializes single key", () => {
62
+ expect(deserializeActorKey("test")).toEqual(["test"]);
63
+ });
64
+
65
+ test("deserializes multiple keys", () => {
66
+ expect(
67
+ deserializeActorKey(`a${KEY_SEPARATOR}b${KEY_SEPARATOR}c`),
68
+ ).toEqual(["a", "b", "c"]);
69
+ });
70
+
71
+ test("deserializes keys with escaped forward slashes", () => {
72
+ expect(deserializeActorKey("a\\/b")).toEqual(["a/b"]);
73
+ expect(deserializeActorKey(`a\\/b${KEY_SEPARATOR}c`)).toEqual([
74
+ "a/b",
75
+ "c",
76
+ ]);
77
+ });
78
+
79
+ test("deserializes keys with escaped empty key marker", () => {
80
+ expect(deserializeActorKey(`\\${EMPTY_KEY}`)).toEqual([EMPTY_KEY]);
81
+ });
82
+
83
+ test("deserializes complex keys", () => {
84
+ expect(
85
+ deserializeActorKey(
86
+ `a\\/b${KEY_SEPARATOR}\\${EMPTY_KEY}${KEY_SEPARATOR}c\\/d`,
87
+ ),
88
+ ).toEqual(["a/b", EMPTY_KEY, "c/d"]);
89
+ });
90
+ });
91
+
92
+ // Test edge cases
93
+ describe("edge cases", () => {
94
+ test("handles empty string parts", () => {
95
+ const testCases: Array<[string[], string]> = [
96
+ [[""], "\\0"],
97
+ [["a", "", "b"], "a/\\0/b"],
98
+ [["", "a"], "\\0/a"],
99
+ [["a", ""], "a/\\0"],
100
+ [["", "", ""], "\\0/\\0/\\0"],
101
+ [["", "a", "", "b", ""], "\\0/a/\\0/b/\\0"],
102
+ [[], "/"],
103
+ [["test"], "test"],
104
+ [["a", "b", "c"], "a/b/c"],
105
+ [["a/b", "c"], "a\\/b/c"],
106
+ [[EMPTY_KEY], "\\/"],
107
+ [["a/b", EMPTY_KEY, "c/d"], "a\\/b/\\//c\\/d"],
108
+ [
109
+ ["special\\chars", "more:complex,keys", "final key"],
110
+ "special\\\\chars/more:complex,keys/final key",
111
+ ],
112
+ ];
113
+
114
+ for (const [key, expectedSerialized] of testCases) {
115
+ const serialized = serializeActorKey(key);
116
+ expect(serialized).toBe(expectedSerialized);
117
+ const deserialized = deserializeActorKey(serialized);
118
+ expect(deserialized).toEqual(key);
119
+ }
120
+ });
121
+
122
+ test("differentiates empty array from array with empty string", () => {
123
+ const emptyArray: string[] = [];
124
+ const arrayWithEmptyString = [""];
125
+
126
+ const serialized1 = serializeActorKey(emptyArray);
127
+ const serialized2 = serializeActorKey(arrayWithEmptyString);
128
+
129
+ expect(serialized1).toBe(EMPTY_KEY); // Should be "/"
130
+ expect(serialized2).not.toBe(EMPTY_KEY); // Should NOT be "/"
131
+ expect(serialized2).toBe("\\0"); // Empty string becomes \0 marker
132
+
133
+ expect(deserializeActorKey(serialized1)).toEqual(emptyArray);
134
+ expect(deserializeActorKey(serialized2)).toEqual(
135
+ arrayWithEmptyString,
136
+ );
137
+ });
138
+
139
+ test("handles mix of empty strings and forward slash (EMPTY_KEY)", () => {
140
+ const testCases: Array<[string[], string]> = [
141
+ [["", EMPTY_KEY, ""], "\\0/\\//\\0"],
142
+ [[EMPTY_KEY, ""], "\\//\\0"],
143
+ [["", EMPTY_KEY], "\\0/\\/"],
144
+ [["a", "", EMPTY_KEY, "", "b"], "a/\\0/\\//\\0/b"],
145
+ ];
146
+
147
+ for (const [key, expectedSerialized] of testCases) {
148
+ const serialized = serializeActorKey(key);
149
+ expect(serialized).toBe(expectedSerialized);
150
+ const deserialized = deserializeActorKey(serialized);
151
+ expect(deserialized).toEqual(key);
152
+ }
153
+ });
154
+
155
+ test("handles literal backslash-zero string", () => {
156
+ const testCases: Array<[string[], string]> = [
157
+ [["\\0"], "\\\\0"], // Literal \0 string
158
+ [["a\\0b"], "a\\\\0b"], // Literal \0 in middle
159
+ [["\\0", ""], "\\\\0/\\0"], // Literal \0 with empty string
160
+ [["", "\\0"], "\\0/\\\\0"], // Empty string with literal \0
161
+ ];
162
+
163
+ for (const [key, expectedSerialized] of testCases) {
164
+ const serialized = serializeActorKey(key);
165
+ expect(serialized).toBe(expectedSerialized);
166
+ const deserialized = deserializeActorKey(serialized);
167
+ expect(deserialized).toEqual(key);
168
+ }
169
+ });
170
+
171
+ test("handles backslash at the end", () => {
172
+ const key = ["abc\\"];
173
+ const serialized = serializeActorKey(key);
174
+ expect(serialized).toBe("abc\\\\");
175
+ const deserialized = deserializeActorKey(serialized);
176
+ expect(deserialized).toEqual(key);
177
+ });
178
+
179
+ test("handles backslashes in middle of string", () => {
180
+ const testCases: Array<[string[], string]> = [
181
+ [["abc\\def"], "abc\\\\def"],
182
+ [["abc\\\\def"], "abc\\\\\\\\def"],
183
+ [["path\\to\\file"], "path\\\\to\\\\file"],
184
+ ];
185
+
186
+ for (const [key, expectedSerialized] of testCases) {
187
+ const serialized = serializeActorKey(key);
188
+ expect(serialized).toBe(expectedSerialized);
189
+ const deserialized = deserializeActorKey(serialized);
190
+ expect(deserialized).toEqual(key);
191
+ }
192
+ });
193
+
194
+ test("handles forward slashes at the end of strings", () => {
195
+ const serialized = serializeActorKey(["abc\\/"]);
196
+ expect(deserializeActorKey(serialized)).toEqual(["abc\\/"]);
197
+ });
198
+
199
+ test("handles mixed backslashes and forward slashes", () => {
200
+ const testCases: Array<[string[], string]> = [
201
+ [["path\\to\\file/dir"], "path\\\\to\\\\file\\/dir"],
202
+ [["file\\with/slash"], "file\\\\with\\/slash"],
203
+ [
204
+ ["path\\to\\file", "with/slash"],
205
+ "path\\\\to\\\\file/with\\/slash",
206
+ ],
207
+ ];
208
+
209
+ for (const [key, expectedSerialized] of testCases) {
210
+ const serialized = serializeActorKey(key);
211
+ expect(serialized).toBe(expectedSerialized);
212
+ const deserialized = deserializeActorKey(serialized);
213
+ expect(deserialized).toEqual(key);
214
+ }
215
+ });
216
+
217
+ test("handles multiple consecutive forward slashes", () => {
218
+ const key = ["a//b"];
219
+ const serialized = serializeActorKey(key);
220
+ expect(serialized).toBe("a\\/\\/b");
221
+ const deserialized = deserializeActorKey(serialized);
222
+ expect(deserialized).toEqual(key);
223
+ });
224
+
225
+ test("handles special characters", () => {
226
+ const key = ["a💻b", "c🔑d"];
227
+ const serialized = serializeActorKey(key);
228
+ expect(serialized).toBe("a💻b/c🔑d");
229
+ const deserialized = deserializeActorKey(serialized);
230
+ expect(deserialized).toEqual(key);
231
+ });
232
+
233
+ test("handles escaped forward slashes immediately after separator", () => {
234
+ const key = ["abc", "/def"];
235
+ const serialized = serializeActorKey(key);
236
+ expect(serialized).toBe(`abc${KEY_SEPARATOR}\\/def`);
237
+ expect(deserializeActorKey(serialized)).toEqual(key);
238
+ });
239
+ });
240
+
241
+ // Test exact key matching
242
+ describe("exact key matching", () => {
243
+ test("differentiates [a,b] from [a,b,c]", () => {
244
+ const key1 = ["a", "b"];
245
+ const key2 = ["a", "b", "c"];
246
+
247
+ const serialized1 = serializeActorKey(key1);
248
+ const serialized2 = serializeActorKey(key2);
249
+
250
+ expect(serialized1).not.toBe(serialized2);
251
+ });
252
+
253
+ test("differentiates [a,b] from [a]", () => {
254
+ const key1 = ["a", "b"];
255
+ const key2 = ["a"];
256
+
257
+ const serialized1 = serializeActorKey(key1);
258
+ const serialized2 = serializeActorKey(key2);
259
+
260
+ expect(serialized1).not.toBe(serialized2);
261
+ });
262
+
263
+ test("differentiates [a/b] from [a,b]", () => {
264
+ const key1 = ["a/b"];
265
+ const key2 = ["a", "b"];
266
+
267
+ const serialized1 = serializeActorKey(key1);
268
+ const serialized2 = serializeActorKey(key2);
269
+
270
+ expect(serialized1).not.toBe(serialized2);
271
+ expect(deserializeActorKey(serialized1)).toEqual(key1);
272
+ expect(deserializeActorKey(serialized2)).toEqual(key2);
273
+ });
274
+ });
275
+ });
package/src/actor/keys.ts CHANGED
@@ -60,8 +60,6 @@ const TRACES_STORAGE_PREFIX = concatPrefix(
60
60
  STORAGE_VERSION_BYTES.TRACES,
61
61
  );
62
62
 
63
- // The slash key form the actor REST API and the actor runtime use. The engine translates it to
64
- // the canonical form (`encodeActorKey`) at those boundaries.
65
63
  export function serializeActorKey(key: ActorKey): string {
66
64
  // Use a special marker for empty key arrays
67
65
  if (key.length === 0) {
@@ -147,90 +145,6 @@ export function deserializeActorKey(keyString: string | undefined): ActorKey {
147
145
  return parts;
148
146
  }
149
147
 
150
- // The canonical actor key: parts joined with `,`, with `\` and `,` escaped by a backslash, an
151
- // empty part written as `\0`, and the empty key as the empty string. The engine hashes, stores
152
- // and compares only canonical keys, and the gateway's `rvt-key` carries one. The Rust twin is
153
- // `rivetkit_shared_types::actor_key`; both run the vectors in
154
- // `rivetkit-rust/packages/shared-types/tests/fixtures/actor_key_vectors.json`.
155
- const CANONICAL_SEPARATOR = ",";
156
- const CANONICAL_EMPTY_PART = "\\0";
157
-
158
- /** Encodes `key` in the canonical form. */
159
- export function encodeActorKey(key: ActorKey): string {
160
- return key
161
- .map((part) => {
162
- if (part === "") {
163
- return CANONICAL_EMPTY_PART;
164
- }
165
- return part.replace(/\\/g, "\\\\").replace(/,/g, "\\,");
166
- })
167
- .join(CANONICAL_SEPARATOR);
168
- }
169
-
170
- /**
171
- * Decodes a canonical key, or an unescaped `rvt-key` value from an earlier client. Only `\\` and
172
- * `\,` are escapes; any other backslash is literal, and a part written as exactly `\0` is empty.
173
- */
174
- export function decodeActorKey(key: string): ActorKey {
175
- if (key === "") {
176
- return [];
177
- }
178
-
179
- const parts: string[] = [];
180
- let raw = "";
181
- let current = "";
182
- const finishPart = () => {
183
- parts.push(raw === CANONICAL_EMPTY_PART ? "" : current);
184
- raw = "";
185
- current = "";
186
- };
187
- for (let i = 0; i < key.length; i++) {
188
- const char = key[i];
189
- if (char === CANONICAL_SEPARATOR) {
190
- finishPart();
191
- continue;
192
- }
193
-
194
- raw += char;
195
- if (char !== "\\") {
196
- current += char;
197
- continue;
198
- }
199
-
200
- const next = key[i + 1];
201
- if (next === "\\" || next === CANONICAL_SEPARATOR) {
202
- raw += next;
203
- current += next;
204
- i++;
205
- } else {
206
- current += char;
207
- }
208
- }
209
- finishPart();
210
- return parts;
211
- }
212
-
213
- /**
214
- * The gateway's `rvt-key` query value for `key`: the canonical key, or `undefined` when the
215
- * parameter is omitted, as it is for the empty key.
216
- */
217
- export function actorKeyToGatewayQuery(key: ActorKey): string | undefined {
218
- if (key.length === 0) {
219
- return undefined;
220
- }
221
- return encodeActorKey(key);
222
- }
223
-
224
- /** Reads the gateway's `rvt-key` query value. A missing value is the empty key. */
225
- export function actorKeyFromGatewayQuery(
226
- rvtKey: string | null | undefined,
227
- ): ActorKey {
228
- if (rvtKey === undefined || rvtKey === null) {
229
- return [];
230
- }
231
- return decodeActorKey(rvtKey);
232
- }
233
-
234
148
  export function makePrefixedKey(key: Uint8Array): Uint8Array {
235
149
  const prefixed = new Uint8Array(KEYS.KV.length + key.length);
236
150
  prefixed.set(KEYS.KV, 0);
@@ -0,0 +1,48 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { isConnStatePath, isStatePath } from "./utils";
3
+
4
+ describe("isStatePath", () => {
5
+ test("matches exact state", () => {
6
+ expect(isStatePath("state")).toBe(true);
7
+ });
8
+
9
+ test("matches nested state paths", () => {
10
+ expect(isStatePath("state.foo")).toBe(true);
11
+ expect(isStatePath("state.foo.bar")).toBe(true);
12
+ });
13
+
14
+ test("does not match other paths", () => {
15
+ expect(isStatePath("connections")).toBe(false);
16
+ expect(isStatePath("stateX")).toBe(false);
17
+ expect(isStatePath("mystate")).toBe(false);
18
+ });
19
+ });
20
+
21
+ describe("isConnStatePath", () => {
22
+ test("matches connection state paths", () => {
23
+ expect(isConnStatePath("connections.0.state")).toBe(true);
24
+ expect(isConnStatePath("connections.123.state")).toBe(true);
25
+ });
26
+
27
+ test("matches nested connection state paths", () => {
28
+ expect(isConnStatePath("connections.0.state.foo")).toBe(true);
29
+ expect(isConnStatePath("connections.5.state.bar.baz")).toBe(true);
30
+ });
31
+
32
+ test("does not match non-state connection paths", () => {
33
+ expect(isConnStatePath("connections.0.params")).toBe(false);
34
+ expect(isConnStatePath("connections.0.token")).toBe(false);
35
+ expect(isConnStatePath("connections.0")).toBe(false);
36
+ });
37
+
38
+ test("does not match other paths", () => {
39
+ expect(isConnStatePath("state")).toBe(false);
40
+ expect(isConnStatePath("connections")).toBe(false);
41
+ expect(isConnStatePath("other.0.state")).toBe(false);
42
+ });
43
+
44
+ test("does not match malformed paths", () => {
45
+ expect(isConnStatePath("connections.state")).toBe(false);
46
+ expect(isConnStatePath("connections.0.stateX")).toBe(false);
47
+ });
48
+ });