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.
- package/README.md +3 -5
- package/dist/schemas/actor-persist/v1.ts +225 -0
- package/dist/schemas/client-protocol/v1.ts +435 -0
- package/dist/schemas/file-system-driver/v1.ts +102 -0
- package/dist/tsup/actor/errors.cjs +77 -0
- package/dist/tsup/actor/errors.cjs.map +1 -0
- package/dist/tsup/actor/errors.d.cts +156 -0
- package/dist/tsup/actor/errors.d.ts +156 -0
- package/dist/tsup/actor/errors.js +77 -0
- package/dist/tsup/actor/errors.js.map +1 -0
- package/dist/tsup/chunk-3F2YSRJL.js +117 -0
- package/dist/tsup/chunk-3F2YSRJL.js.map +1 -0
- package/dist/tsup/chunk-4CXBCT26.cjs +250 -0
- package/dist/tsup/chunk-4CXBCT26.cjs.map +1 -0
- package/dist/tsup/chunk-4R73YDN3.cjs +20 -0
- package/dist/tsup/chunk-4R73YDN3.cjs.map +1 -0
- package/dist/tsup/chunk-6LJT3QRL.cjs +539 -0
- package/dist/tsup/chunk-6LJT3QRL.cjs.map +1 -0
- package/dist/tsup/chunk-GICQ3YCU.cjs +1792 -0
- package/dist/tsup/chunk-GICQ3YCU.cjs.map +1 -0
- package/dist/tsup/chunk-H26RP6GD.js +251 -0
- package/dist/tsup/chunk-H26RP6GD.js.map +1 -0
- package/dist/tsup/chunk-HI3HWJRC.js +20 -0
- package/dist/tsup/chunk-HI3HWJRC.js.map +1 -0
- package/dist/tsup/chunk-HLLF4B4Q.js +1792 -0
- package/dist/tsup/chunk-HLLF4B4Q.js.map +1 -0
- package/dist/tsup/chunk-IH6CKNDW.cjs +117 -0
- package/dist/tsup/chunk-IH6CKNDW.cjs.map +1 -0
- package/dist/tsup/chunk-LV2S3OU3.js +250 -0
- package/dist/tsup/chunk-LV2S3OU3.js.map +1 -0
- package/dist/tsup/chunk-LWNKVZG5.cjs +251 -0
- package/dist/tsup/chunk-LWNKVZG5.cjs.map +1 -0
- package/dist/tsup/chunk-NFU2BBT5.js +374 -0
- package/dist/tsup/chunk-NFU2BBT5.js.map +1 -0
- package/dist/tsup/chunk-PQY7KKTL.js +539 -0
- package/dist/tsup/chunk-PQY7KKTL.js.map +1 -0
- package/dist/tsup/chunk-QK72M5JB.js +45 -0
- package/dist/tsup/chunk-QK72M5JB.js.map +1 -0
- package/dist/tsup/chunk-QNNXFOQV.cjs +45 -0
- package/dist/tsup/chunk-QNNXFOQV.cjs.map +1 -0
- package/dist/tsup/chunk-SBHHJ6QS.cjs +374 -0
- package/dist/tsup/chunk-SBHHJ6QS.cjs.map +1 -0
- package/dist/tsup/chunk-TQ62L3X7.js +325 -0
- package/dist/tsup/chunk-TQ62L3X7.js.map +1 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs +6293 -0
- package/dist/tsup/chunk-VO7ZRVVD.cjs.map +1 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs +325 -0
- package/dist/tsup/chunk-WHBPJNGW.cjs.map +1 -0
- package/dist/tsup/chunk-XJQHKJ4P.js +6293 -0
- package/dist/tsup/chunk-XJQHKJ4P.js.map +1 -0
- package/dist/tsup/client/mod.cjs +32 -0
- package/dist/tsup/client/mod.cjs.map +1 -0
- package/dist/tsup/client/mod.d.cts +20 -0
- package/dist/tsup/client/mod.d.ts +20 -0
- package/dist/tsup/client/mod.js +32 -0
- package/dist/tsup/client/mod.js.map +1 -0
- package/dist/tsup/common/log.cjs +21 -0
- package/dist/tsup/common/log.cjs.map +1 -0
- package/dist/tsup/common/log.d.cts +26 -0
- package/dist/tsup/common/log.d.ts +26 -0
- package/dist/tsup/common/log.js +21 -0
- package/dist/tsup/common/log.js.map +1 -0
- package/dist/tsup/common/websocket.cjs +10 -0
- package/dist/tsup/common/websocket.cjs.map +1 -0
- package/dist/tsup/common/websocket.d.cts +3 -0
- package/dist/tsup/common/websocket.d.ts +3 -0
- package/dist/tsup/common/websocket.js +10 -0
- package/dist/tsup/common/websocket.js.map +1 -0
- package/dist/tsup/common-CXCe7s6i.d.cts +218 -0
- package/dist/tsup/common-CXCe7s6i.d.ts +218 -0
- package/dist/tsup/connection-BI-6UIBJ.d.ts +2087 -0
- package/dist/tsup/connection-Dyd4NLGW.d.cts +2087 -0
- package/dist/tsup/driver-helpers/mod.cjs +30 -0
- package/dist/tsup/driver-helpers/mod.cjs.map +1 -0
- package/dist/tsup/driver-helpers/mod.d.cts +17 -0
- package/dist/tsup/driver-helpers/mod.d.ts +17 -0
- package/dist/tsup/driver-helpers/mod.js +30 -0
- package/dist/tsup/driver-helpers/mod.js.map +1 -0
- package/dist/tsup/driver-test-suite/mod.cjs +3411 -0
- package/dist/tsup/driver-test-suite/mod.cjs.map +1 -0
- package/dist/tsup/driver-test-suite/mod.d.cts +63 -0
- package/dist/tsup/driver-test-suite/mod.d.ts +63 -0
- package/dist/tsup/driver-test-suite/mod.js +3411 -0
- package/dist/tsup/driver-test-suite/mod.js.map +1 -0
- package/dist/tsup/inspector/mod.cjs +51 -0
- package/dist/tsup/inspector/mod.cjs.map +1 -0
- package/dist/tsup/inspector/mod.d.cts +408 -0
- package/dist/tsup/inspector/mod.d.ts +408 -0
- package/dist/tsup/inspector/mod.js +51 -0
- package/dist/tsup/inspector/mod.js.map +1 -0
- package/dist/tsup/mod.cjs +67 -0
- package/dist/tsup/mod.cjs.map +1 -0
- package/dist/tsup/mod.d.cts +105 -0
- package/dist/tsup/mod.d.ts +105 -0
- package/dist/tsup/mod.js +67 -0
- package/dist/tsup/mod.js.map +1 -0
- package/dist/tsup/router-endpoints-BTe_Rsdn.d.cts +65 -0
- package/dist/tsup/router-endpoints-CBSrKHmo.d.ts +65 -0
- package/dist/tsup/test/mod.cjs +17 -0
- package/dist/tsup/test/mod.cjs.map +1 -0
- package/dist/tsup/test/mod.d.cts +26 -0
- package/dist/tsup/test/mod.d.ts +26 -0
- package/dist/tsup/test/mod.js +17 -0
- package/dist/tsup/test/mod.js.map +1 -0
- package/dist/tsup/utils-fwx3o3K9.d.cts +18 -0
- package/dist/tsup/utils-fwx3o3K9.d.ts +18 -0
- package/dist/tsup/utils.cjs +26 -0
- package/dist/tsup/utils.cjs.map +1 -0
- package/dist/tsup/utils.d.cts +36 -0
- package/dist/tsup/utils.d.ts +36 -0
- package/dist/tsup/utils.js +26 -0
- package/dist/tsup/utils.js.map +1 -0
- package/package.json +208 -5
- package/src/actor/action.ts +178 -0
- package/src/actor/config.ts +497 -0
- package/src/actor/connection.ts +257 -0
- package/src/actor/context.ts +168 -0
- package/src/actor/database.ts +23 -0
- package/src/actor/definition.ts +82 -0
- package/src/actor/driver.ts +84 -0
- package/src/actor/errors.ts +422 -0
- package/src/actor/generic-conn-driver.ts +246 -0
- package/src/actor/instance.ts +1844 -0
- package/src/actor/keys.test.ts +266 -0
- package/src/actor/keys.ts +89 -0
- package/src/actor/log.ts +6 -0
- package/src/actor/mod.ts +108 -0
- package/src/actor/persisted.ts +42 -0
- package/src/actor/protocol/old.ts +297 -0
- package/src/actor/protocol/serde.ts +131 -0
- package/src/actor/router-endpoints.ts +688 -0
- package/src/actor/router.ts +265 -0
- package/src/actor/schedule.ts +17 -0
- package/src/actor/unstable-react.ts +110 -0
- package/src/actor/utils.ts +102 -0
- package/src/client/actor-common.ts +30 -0
- package/src/client/actor-conn.ts +865 -0
- package/src/client/actor-handle.ts +268 -0
- package/src/client/actor-query.ts +65 -0
- package/src/client/client.ts +554 -0
- package/src/client/config.ts +44 -0
- package/src/client/errors.ts +42 -0
- package/src/client/log.ts +5 -0
- package/src/client/mod.ts +60 -0
- package/src/client/raw-utils.ts +149 -0
- package/src/client/test.ts +44 -0
- package/src/client/utils.ts +152 -0
- package/src/common/eventsource-interface.ts +47 -0
- package/src/common/eventsource.ts +80 -0
- package/src/common/fake-event-source.ts +267 -0
- package/src/common/inline-websocket-adapter2.ts +454 -0
- package/src/common/log-levels.ts +27 -0
- package/src/common/log.ts +214 -0
- package/src/common/logfmt.ts +219 -0
- package/src/common/network.ts +2 -0
- package/src/common/router.ts +80 -0
- package/src/common/utils.ts +336 -0
- package/src/common/versioned-data.ts +95 -0
- package/src/common/websocket-interface.ts +49 -0
- package/src/common/websocket.ts +42 -0
- package/src/driver-helpers/mod.ts +22 -0
- package/src/driver-helpers/utils.ts +17 -0
- package/src/driver-test-suite/log.ts +5 -0
- package/src/driver-test-suite/mod.ts +239 -0
- package/src/driver-test-suite/tests/action-features.ts +136 -0
- package/src/driver-test-suite/tests/actor-conn-state.ts +249 -0
- package/src/driver-test-suite/tests/actor-conn.ts +349 -0
- package/src/driver-test-suite/tests/actor-driver.ts +25 -0
- package/src/driver-test-suite/tests/actor-error-handling.ts +158 -0
- package/src/driver-test-suite/tests/actor-handle.ts +292 -0
- package/src/driver-test-suite/tests/actor-inline-client.ts +152 -0
- package/src/driver-test-suite/tests/actor-inspector.ts +570 -0
- package/src/driver-test-suite/tests/actor-metadata.ts +116 -0
- package/src/driver-test-suite/tests/actor-onstatechange.ts +95 -0
- package/src/driver-test-suite/tests/actor-schedule.ts +108 -0
- package/src/driver-test-suite/tests/actor-sleep.ts +413 -0
- package/src/driver-test-suite/tests/actor-state.ts +54 -0
- package/src/driver-test-suite/tests/actor-vars.ts +93 -0
- package/src/driver-test-suite/tests/manager-driver.ts +367 -0
- package/src/driver-test-suite/tests/raw-http-direct-registry.ts +227 -0
- package/src/driver-test-suite/tests/raw-http-request-properties.ts +414 -0
- package/src/driver-test-suite/tests/raw-http.ts +347 -0
- package/src/driver-test-suite/tests/raw-websocket-direct-registry.ts +393 -0
- package/src/driver-test-suite/tests/raw-websocket.ts +484 -0
- package/src/driver-test-suite/tests/request-access.ts +230 -0
- package/src/driver-test-suite/utils.ts +71 -0
- package/src/drivers/default.ts +34 -0
- package/src/drivers/engine/actor-driver.ts +369 -0
- package/src/drivers/engine/config.ts +31 -0
- package/src/drivers/engine/kv.ts +3 -0
- package/src/drivers/engine/log.ts +5 -0
- package/src/drivers/engine/mod.ts +35 -0
- package/src/drivers/file-system/actor.ts +91 -0
- package/src/drivers/file-system/global-state.ts +686 -0
- package/src/drivers/file-system/log.ts +5 -0
- package/src/drivers/file-system/manager.ts +329 -0
- package/src/drivers/file-system/mod.ts +48 -0
- package/src/drivers/file-system/utils.ts +109 -0
- package/src/globals.d.ts +6 -0
- package/src/inspector/actor.ts +298 -0
- package/src/inspector/config.ts +88 -0
- package/src/inspector/log.ts +5 -0
- package/src/inspector/manager.ts +86 -0
- package/src/inspector/mod.ts +2 -0
- package/src/inspector/protocol/actor.ts +10 -0
- package/src/inspector/protocol/common.ts +196 -0
- package/src/inspector/protocol/manager.ts +10 -0
- package/src/inspector/protocol/mod.ts +2 -0
- package/src/inspector/utils.ts +76 -0
- package/src/manager/driver.ts +88 -0
- package/src/manager/hono-websocket-adapter.ts +342 -0
- package/src/manager/log.ts +5 -0
- package/src/manager/mod.ts +2 -0
- package/src/manager/protocol/mod.ts +24 -0
- package/src/manager/protocol/query.ts +89 -0
- package/src/manager/router.ts +412 -0
- package/src/manager-api/routes/actors-create.ts +16 -0
- package/src/manager-api/routes/actors-delete.ts +4 -0
- package/src/manager-api/routes/actors-get-by-id.ts +7 -0
- package/src/manager-api/routes/actors-get-or-create-by-id.ts +29 -0
- package/src/manager-api/routes/actors-get.ts +7 -0
- package/src/manager-api/routes/common.ts +18 -0
- package/src/mod.ts +18 -0
- package/src/registry/config.ts +32 -0
- package/src/registry/log.ts +5 -0
- package/src/registry/mod.ts +157 -0
- package/src/registry/run-config.ts +52 -0
- package/src/registry/serve.ts +52 -0
- package/src/remote-manager-driver/actor-http-client.ts +72 -0
- package/src/remote-manager-driver/actor-websocket-client.ts +63 -0
- package/src/remote-manager-driver/api-endpoints.ts +79 -0
- package/src/remote-manager-driver/api-utils.ts +43 -0
- package/src/remote-manager-driver/log.ts +5 -0
- package/src/remote-manager-driver/mod.ts +274 -0
- package/src/remote-manager-driver/ws-proxy.ts +180 -0
- package/src/schemas/actor-persist/mod.ts +1 -0
- package/src/schemas/actor-persist/versioned.ts +25 -0
- package/src/schemas/client-protocol/mod.ts +1 -0
- package/src/schemas/client-protocol/versioned.ts +63 -0
- package/src/schemas/file-system-driver/mod.ts +1 -0
- package/src/schemas/file-system-driver/versioned.ts +28 -0
- package/src/serde.ts +90 -0
- package/src/test/config.ts +16 -0
- package/src/test/log.ts +5 -0
- package/src/test/mod.ts +154 -0
- package/src/utils.ts +172 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { registry } from "../../../fixtures/driver-test-suite/registry";
|
|
4
|
+
import type { DriverTestConfig } from "../mod";
|
|
5
|
+
import { setupDriverTest } from "../utils";
|
|
6
|
+
|
|
7
|
+
export function runRawHttpRequestPropertiesTests(
|
|
8
|
+
driverTestConfig: DriverTestConfig,
|
|
9
|
+
) {
|
|
10
|
+
describe("raw http request properties", () => {
|
|
11
|
+
test("should pass all Request properties correctly to onFetch", async (c) => {
|
|
12
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
13
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
14
|
+
|
|
15
|
+
// Test basic request properties
|
|
16
|
+
const response = await actor.fetch("test/path?foo=bar&baz=qux", {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json",
|
|
20
|
+
"X-Custom-Header": "custom-value",
|
|
21
|
+
Authorization: "Bearer test-token",
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({ test: "data" }),
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(response.ok).toBe(true);
|
|
27
|
+
const data = (await response.json()) as any;
|
|
28
|
+
|
|
29
|
+
// Verify URL properties
|
|
30
|
+
expect(data.url).toContain("/test/path?foo=bar&baz=qux");
|
|
31
|
+
expect(data.pathname).toBe("/test/path");
|
|
32
|
+
expect(data.search).toBe("?foo=bar&baz=qux");
|
|
33
|
+
expect(data.searchParams).toEqual({
|
|
34
|
+
foo: "bar",
|
|
35
|
+
baz: "qux",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Verify method
|
|
39
|
+
expect(data.method).toBe("POST");
|
|
40
|
+
|
|
41
|
+
// Verify headers
|
|
42
|
+
expect(data.headers["content-type"]).toBe("application/json");
|
|
43
|
+
expect(data.headers["x-custom-header"]).toBe("custom-value");
|
|
44
|
+
expect(data.headers["authorization"]).toBe("Bearer test-token");
|
|
45
|
+
|
|
46
|
+
// Verify body
|
|
47
|
+
expect(data.body).toEqual({ test: "data" });
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("should handle GET requests with no body", async (c) => {
|
|
51
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
52
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
53
|
+
|
|
54
|
+
const response = await actor.fetch("test/get", {
|
|
55
|
+
method: "GET",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(response.ok).toBe(true);
|
|
59
|
+
const data = (await response.json()) as any;
|
|
60
|
+
|
|
61
|
+
expect(data.method).toBe("GET");
|
|
62
|
+
expect(data.body).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("should handle different content types", async (c) => {
|
|
66
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
67
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
68
|
+
|
|
69
|
+
// Test form data
|
|
70
|
+
const formData = new URLSearchParams();
|
|
71
|
+
formData.append("field1", "value1");
|
|
72
|
+
formData.append("field2", "value2");
|
|
73
|
+
|
|
74
|
+
const formResponse = await actor.fetch("test/form", {
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: {
|
|
77
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
78
|
+
},
|
|
79
|
+
body: formData.toString(),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(formResponse.ok).toBe(true);
|
|
83
|
+
const formResult = (await formResponse.json()) as any;
|
|
84
|
+
expect(formResult.headers["content-type"]).toBe(
|
|
85
|
+
"application/x-www-form-urlencoded",
|
|
86
|
+
);
|
|
87
|
+
expect(formResult.bodyText).toBe("field1=value1&field2=value2");
|
|
88
|
+
|
|
89
|
+
// Test plain text
|
|
90
|
+
const textResponse = await actor.fetch("test/text", {
|
|
91
|
+
method: "POST",
|
|
92
|
+
headers: {
|
|
93
|
+
"Content-Type": "text/plain",
|
|
94
|
+
},
|
|
95
|
+
body: "Hello, World!",
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(textResponse.ok).toBe(true);
|
|
99
|
+
const textResult = (await textResponse.json()) as any;
|
|
100
|
+
expect(textResult.headers["content-type"]).toBe("text/plain");
|
|
101
|
+
expect(textResult.bodyText).toBe("Hello, World!");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("should preserve all header casing and values", async (c) => {
|
|
105
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
106
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
107
|
+
|
|
108
|
+
const response = await actor.fetch("test/headers", {
|
|
109
|
+
headers: {
|
|
110
|
+
Accept: "application/json",
|
|
111
|
+
"Accept-Language": "en-US,en;q=0.9",
|
|
112
|
+
"Cache-Control": "no-cache",
|
|
113
|
+
"User-Agent": "RivetKit-Test/1.0",
|
|
114
|
+
"X-Request-ID": "12345",
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(response.ok).toBe(true);
|
|
119
|
+
const data = (await response.json()) as any;
|
|
120
|
+
|
|
121
|
+
// Headers should be normalized to lowercase
|
|
122
|
+
expect(data.headers["accept"]).toBe("application/json");
|
|
123
|
+
expect(data.headers["accept-language"]).toBe("en-US,en;q=0.9");
|
|
124
|
+
expect(data.headers["cache-control"]).toBe("no-cache");
|
|
125
|
+
// User-Agent might be overwritten by the HTTP client, so just check it exists
|
|
126
|
+
expect(data.headers["user-agent"]).toBeTruthy();
|
|
127
|
+
expect(data.headers["x-request-id"]).toBe("12345");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test("should handle empty and special URL paths", async (c) => {
|
|
131
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
132
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
133
|
+
|
|
134
|
+
// Test root path
|
|
135
|
+
const rootResponse = await actor.fetch("");
|
|
136
|
+
expect(rootResponse.ok).toBe(true);
|
|
137
|
+
const rootData = (await rootResponse.json()) as any;
|
|
138
|
+
expect(rootData.pathname).toBe("/");
|
|
139
|
+
|
|
140
|
+
// Test path with special characters
|
|
141
|
+
const specialResponse = await actor.fetch(
|
|
142
|
+
"test/path%20with%20spaces/and%2Fslashes",
|
|
143
|
+
);
|
|
144
|
+
expect(specialResponse.ok).toBe(true);
|
|
145
|
+
const specialData = (await specialResponse.json()) as any;
|
|
146
|
+
// Note: The URL path may or may not be decoded depending on the HTTP client/server
|
|
147
|
+
// Just verify it contains the expected segments
|
|
148
|
+
expect(specialData.pathname).toMatch(/path.*with.*spaces.*and.*slashes/);
|
|
149
|
+
|
|
150
|
+
// Test path with fragment (should be ignored in server-side)
|
|
151
|
+
const fragmentResponse = await actor.fetch("test/path#fragment");
|
|
152
|
+
expect(fragmentResponse.ok).toBe(true);
|
|
153
|
+
const fragmentData = (await fragmentResponse.json()) as any;
|
|
154
|
+
expect(fragmentData.pathname).toBe("/test/path");
|
|
155
|
+
expect(fragmentData.hash).toBe(""); // Fragments are not sent to server
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("should handle request properties for all HTTP methods", async (c) => {
|
|
159
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
160
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
161
|
+
|
|
162
|
+
const methods = [
|
|
163
|
+
"GET",
|
|
164
|
+
"POST",
|
|
165
|
+
"PUT",
|
|
166
|
+
"DELETE",
|
|
167
|
+
"PATCH",
|
|
168
|
+
"HEAD",
|
|
169
|
+
"OPTIONS",
|
|
170
|
+
];
|
|
171
|
+
|
|
172
|
+
for (const method of methods) {
|
|
173
|
+
const response = await actor.fetch(`test/${method.toLowerCase()}`, {
|
|
174
|
+
method,
|
|
175
|
+
// Only include body for methods that support it
|
|
176
|
+
body: ["POST", "PUT", "PATCH"].includes(method)
|
|
177
|
+
? JSON.stringify({ method })
|
|
178
|
+
: undefined,
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// HEAD responses have no body
|
|
182
|
+
if (method === "HEAD") {
|
|
183
|
+
expect(response.status).toBe(200);
|
|
184
|
+
const text = await response.text();
|
|
185
|
+
expect(text).toBe("");
|
|
186
|
+
} else if (method === "OPTIONS") {
|
|
187
|
+
expect(response.status).toBe(204);
|
|
188
|
+
const text = await response.text();
|
|
189
|
+
expect(text).toBe("");
|
|
190
|
+
} else {
|
|
191
|
+
expect(response.ok).toBe(true);
|
|
192
|
+
const data = (await response.json()) as any;
|
|
193
|
+
expect(data.method).toBe(method);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test("should handle complex query parameters", async (c) => {
|
|
199
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
200
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
201
|
+
|
|
202
|
+
// Test multiple values for same key
|
|
203
|
+
const response = await actor.fetch(
|
|
204
|
+
"test?key=value1&key=value2&array[]=1&array[]=2&nested[prop]=val",
|
|
205
|
+
);
|
|
206
|
+
expect(response.ok).toBe(true);
|
|
207
|
+
const data = (await response.json()) as any;
|
|
208
|
+
|
|
209
|
+
// Note: URLSearchParams only keeps the last value for duplicate keys
|
|
210
|
+
expect(data.searchParams.key).toBe("value2");
|
|
211
|
+
expect(data.searchParams["array[]"]).toBe("2");
|
|
212
|
+
expect(data.searchParams["nested[prop]"]).toBe("val");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
test("should handle multipart form data", async (c) => {
|
|
216
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
217
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
218
|
+
|
|
219
|
+
// Create multipart boundary
|
|
220
|
+
const boundary = "----RivetKitBoundary";
|
|
221
|
+
const body = [
|
|
222
|
+
`------${boundary}`,
|
|
223
|
+
'Content-Disposition: form-data; name="field1"',
|
|
224
|
+
"",
|
|
225
|
+
"value1",
|
|
226
|
+
`------${boundary}`,
|
|
227
|
+
'Content-Disposition: form-data; name="field2"',
|
|
228
|
+
"",
|
|
229
|
+
"value2",
|
|
230
|
+
`------${boundary}--`,
|
|
231
|
+
].join("\r\n");
|
|
232
|
+
|
|
233
|
+
const response = await actor.fetch("test/multipart", {
|
|
234
|
+
method: "POST",
|
|
235
|
+
headers: {
|
|
236
|
+
"Content-Type": `multipart/form-data; boundary=----${boundary}`,
|
|
237
|
+
},
|
|
238
|
+
body: body,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(response.ok).toBe(true);
|
|
242
|
+
const data = (await response.json()) as any;
|
|
243
|
+
expect(data.headers["content-type"]).toContain("multipart/form-data");
|
|
244
|
+
expect(data.bodyText).toContain("field1");
|
|
245
|
+
expect(data.bodyText).toContain("value1");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
test("should handle very long URLs", async (c) => {
|
|
249
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
250
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
251
|
+
|
|
252
|
+
// Create a very long query string
|
|
253
|
+
const longValue = "x".repeat(1000);
|
|
254
|
+
const response = await actor.fetch(`test/long?param=${longValue}`);
|
|
255
|
+
|
|
256
|
+
expect(response.ok).toBe(true);
|
|
257
|
+
const data = (await response.json()) as any;
|
|
258
|
+
expect(data.searchParams.param).toBe(longValue);
|
|
259
|
+
expect(data.search.length).toBeGreaterThan(1000);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test("should handle large request bodies", async (c) => {
|
|
263
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
264
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
265
|
+
|
|
266
|
+
// Create a large JSON body (1MB+)
|
|
267
|
+
const largeArray = new Array(10000).fill({
|
|
268
|
+
id: 1,
|
|
269
|
+
name: "Test",
|
|
270
|
+
description: "This is a test object with some data",
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
const response = await actor.fetch("test/large", {
|
|
274
|
+
method: "POST",
|
|
275
|
+
headers: {
|
|
276
|
+
"Content-Type": "application/json",
|
|
277
|
+
},
|
|
278
|
+
body: JSON.stringify(largeArray),
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
expect(response.ok).toBe(true);
|
|
282
|
+
const data = (await response.json()) as any;
|
|
283
|
+
expect(data.body).toHaveLength(10000);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test("should handle missing content-type header", async (c) => {
|
|
287
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
288
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
289
|
+
|
|
290
|
+
const response = await actor.fetch("test/no-content-type", {
|
|
291
|
+
method: "POST",
|
|
292
|
+
body: "plain text without content-type",
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expect(response.ok).toBe(true);
|
|
296
|
+
const data = (await response.json()) as any;
|
|
297
|
+
expect(data.bodyText).toBe("plain text without content-type");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("should handle empty request body", async (c) => {
|
|
301
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
302
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
303
|
+
|
|
304
|
+
const response = await actor.fetch("test/empty", {
|
|
305
|
+
method: "POST",
|
|
306
|
+
headers: {
|
|
307
|
+
"Content-Type": "application/json",
|
|
308
|
+
},
|
|
309
|
+
body: "",
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
expect(response.ok).toBe(true);
|
|
313
|
+
const data = (await response.json()) as any;
|
|
314
|
+
expect(data.body).toBeNull();
|
|
315
|
+
expect(data.bodyText).toBe("");
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
test("should handle custom HTTP methods", async (c) => {
|
|
319
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
320
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
321
|
+
|
|
322
|
+
// Test a custom method (though most HTTP clients may not support this)
|
|
323
|
+
try {
|
|
324
|
+
const response = await actor.fetch("test/custom", {
|
|
325
|
+
method: "CUSTOM",
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// If the request succeeds, verify the method
|
|
329
|
+
if (response.ok) {
|
|
330
|
+
const data = (await response.json()) as any;
|
|
331
|
+
expect(data.method).toBe("CUSTOM");
|
|
332
|
+
}
|
|
333
|
+
} catch (error) {
|
|
334
|
+
// Some HTTP clients may reject custom methods
|
|
335
|
+
// This is expected behavior
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
test("should handle cookies in headers", async (c) => {
|
|
340
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
341
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
342
|
+
|
|
343
|
+
const response = await actor.fetch("test/cookies", {
|
|
344
|
+
headers: {
|
|
345
|
+
Cookie: "session=abc123; user=test; preferences=dark_mode",
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
expect(response.ok).toBe(true);
|
|
350
|
+
const data = (await response.json()) as any;
|
|
351
|
+
expect(data.headers.cookie).toBe(
|
|
352
|
+
"session=abc123; user=test; preferences=dark_mode",
|
|
353
|
+
);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
test("should handle URL encoding properly", async (c) => {
|
|
357
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
358
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
359
|
+
|
|
360
|
+
// Test various encoded characters
|
|
361
|
+
const response = await actor.fetch(
|
|
362
|
+
"test/encoded?special=%20%21%40%23%24%25%5E%26&unicode=%E2%9C%93&email=test%40example.com",
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
expect(response.ok).toBe(true);
|
|
366
|
+
const data = (await response.json()) as any;
|
|
367
|
+
|
|
368
|
+
// Verify URL decoding
|
|
369
|
+
expect(data.searchParams.special).toBe(" !@#$%^&");
|
|
370
|
+
expect(data.searchParams.unicode).toBe("✓");
|
|
371
|
+
expect(data.searchParams.email).toBe("test@example.com");
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
test("should handle concurrent requests maintaining separate contexts", async (c) => {
|
|
375
|
+
const { client } = await setupDriverTest(c, driverTestConfig);
|
|
376
|
+
const actor = client.rawHttpRequestPropertiesActor.getOrCreate(["test"]);
|
|
377
|
+
|
|
378
|
+
// Send multiple concurrent requests with different data
|
|
379
|
+
const requests = [
|
|
380
|
+
actor.fetch("test/concurrent?id=1", {
|
|
381
|
+
method: "POST",
|
|
382
|
+
headers: { "Content-Type": "application/json" },
|
|
383
|
+
body: JSON.stringify({ request: 1 }),
|
|
384
|
+
}),
|
|
385
|
+
actor.fetch("test/concurrent?id=2", {
|
|
386
|
+
method: "PUT",
|
|
387
|
+
headers: { "Content-Type": "application/json" },
|
|
388
|
+
body: JSON.stringify({ request: 2 }),
|
|
389
|
+
}),
|
|
390
|
+
actor.fetch("test/concurrent?id=3", {
|
|
391
|
+
method: "DELETE",
|
|
392
|
+
}),
|
|
393
|
+
];
|
|
394
|
+
|
|
395
|
+
const responses = await Promise.all(requests);
|
|
396
|
+
const results = (await Promise.all(
|
|
397
|
+
responses.map((r) => r.json()),
|
|
398
|
+
)) as any[];
|
|
399
|
+
|
|
400
|
+
// Verify each request maintained its own context
|
|
401
|
+
expect(results[0].searchParams.id).toBe("1");
|
|
402
|
+
expect(results[0].method).toBe("POST");
|
|
403
|
+
expect(results[0].body).toEqual({ request: 1 });
|
|
404
|
+
|
|
405
|
+
expect(results[1].searchParams.id).toBe("2");
|
|
406
|
+
expect(results[1].method).toBe("PUT");
|
|
407
|
+
expect(results[1].body).toEqual({ request: 2 });
|
|
408
|
+
|
|
409
|
+
expect(results[2].searchParams.id).toBe("3");
|
|
410
|
+
expect(results[2].method).toBe("DELETE");
|
|
411
|
+
expect(results[2].body).toBeNull();
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
}
|