Skip to content

Commit 7bda860

Browse files
committed
chore(rivetkit-typescript): remove dependency on node modules
1 parent 0e6327a commit 7bda860

File tree

20 files changed

+389
-260
lines changed

20 files changed

+389
-260
lines changed

biome.json

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,56 @@
4343
"noExplicitAny": "off"
4444
}
4545
}
46-
}
46+
},
47+
"overrides": [
48+
{
49+
"includes": [
50+
"rivetkit-typescript/packages/rivetkit/src/**/*",
51+
"!rivetkit-typescript/packages/rivetkit/src/test/**/*"
52+
],
53+
"linter": {
54+
"rules": {
55+
"style": {
56+
"noRestrictedImports": {
57+
"level": "error",
58+
"options": {
59+
"paths": {
60+
"node:crypto": "Use '@/utils/node' getNodeCrypto() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
61+
"node:fs": "Use '@/utils/node' getNodeFsSync() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
62+
"node:fs/promises": "Use '@/utils/node' getNodeFs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
63+
"node:path": "Use '@/utils/node' getNodePath() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
64+
"node:os": "Use '@/utils/node' getNodeOs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
65+
"node:child_process": "Use '@/utils/node' getNodeChildProcess() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
66+
"node:stream": "Use '@/utils/node' getNodeStream() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
67+
"node:net": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts",
68+
"node:url": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts",
69+
"crypto": "Use '@/utils/node' getNodeCrypto() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
70+
"fs": "Use '@/utils/node' getNodeFsSync() or getNodeFs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
71+
"fs/promises": "Use '@/utils/node' getNodeFs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
72+
"path": "Use '@/utils/node' getNodePath() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
73+
"os": "Use '@/utils/node' getNodeOs() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
74+
"child_process": "Use '@/utils/node' getNodeChildProcess() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
75+
"stream": "Use '@/utils/node' getNodeStream() instead. Direct Node.js imports are only allowed in src/utils/node.ts",
76+
"net": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts",
77+
"url": "Use '@/utils/node' instead. Direct Node.js imports are only allowed in src/utils/node.ts"
78+
}
79+
}
80+
}
81+
}
82+
}
83+
}
84+
},
85+
{
86+
"includes": [
87+
"rivetkit-typescript/packages/rivetkit/src/utils/node.ts"
88+
],
89+
"linter": {
90+
"rules": {
91+
"style": {
92+
"noRestrictedImports": "off"
93+
}
94+
}
95+
}
96+
}
97+
]
4798
}

engine/artifacts/openapi.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

engine/package.json

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,11 @@
11
{
22
"name": "@rivetkit/engine",
3-
"private": true,
3+
"version": "1.0.0",
4+
"keywords": [],
5+
"author": "",
6+
"license": "ISC",
47
"packageManager": "pnpm@10.13.1",
5-
"scripts": {
6-
"start": "npx turbo watch build",
7-
"build": "npx turbo build",
8-
"test": "npx turbo test",
9-
"test:watch": "npx turbo watch test",
10-
"check-types": "npx turbo check-types",
11-
"fmt": "pnpm biome check --write --diagnostic-level=error ."
12-
},
13-
"devDependencies": {
14-
"@bare-ts/tools": "0.15.0",
15-
"@biomejs/biome": "^2.2.3",
16-
"lefthook": "^1.12.4",
17-
"tsup": "^8.5.0",
18-
"turbo": "^2.5.6",
19-
"typescript": "^5.9.2"
20-
},
218
"dependencies": {
22-
"@sentry/vite-plugin": "^2.23.1"
23-
},
24-
"resolutions": {
25-
"rivetkit": "workspace:*",
26-
"@clerk/shared": "3.27.1"
9+
"@vbare/compiler": "^0.0.3"
2710
}
2811
}

engine/sdks/typescript/runner-protocol/src/index.ts

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
packages:
2+
- engine
23
- engine/docker/template
34
- engine/sdks/typescript/api-full
45
- engine/sdks/typescript/runner

rivetkit-typescript/packages/rivetkit/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
"build": "tsup src/mod.ts src/client/mod.ts src/common/log.ts src/common/websocket.ts src/actor/errors.ts src/topologies/coordinate/mod.ts src/topologies/partition/mod.ts src/utils.ts src/driver-helpers/mod.ts src/driver-test-suite/mod.ts src/test/mod.ts src/inspector/mod.ts",
156156
"build:schema": "./scripts/compile-bare.ts compile schemas/client-protocol/v1.bare -o dist/schemas/client-protocol/v1.ts && ./scripts/compile-bare.ts compile schemas/client-protocol/v2.bare -o dist/schemas/client-protocol/v2.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v1.bare -o dist/schemas/file-system-driver/v1.ts && ./scripts/compile-bare.ts compile schemas/file-system-driver/v2.bare -o dist/schemas/file-system-driver/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v1.bare -o dist/schemas/actor-persist/v1.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v2.bare -o dist/schemas/actor-persist/v2.ts && ./scripts/compile-bare.ts compile schemas/actor-persist/v3.bare -o dist/schemas/actor-persist/v3.ts",
157157
"check-types": "tsc --noEmit",
158+
"lint": "biome check .",
159+
"lint:fix": "biome check --write .",
160+
"format": "biome format .",
161+
"format:write": "biome format --write .",
158162
"test": "vitest run",
159163
"test:watch": "vitest",
160164
"dump-openapi": "tsx scripts/dump-openapi.ts",
@@ -178,6 +182,7 @@
178182
},
179183
"devDependencies": {
180184
"@bare-ts/tools": "^0.13.0",
185+
"@biomejs/biome": "^2.2.3",
181186
"@hono/node-server": "^1.18.2",
182187
"@hono/node-ws": "^1.1.1",
183188
"@types/invariant": "^2",

rivetkit-typescript/packages/rivetkit/scripts/dump-openapi.ts

Lines changed: 5 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from "node:fs/promises";
22
import { resolve } from "node:path";
3-
import { zodToJsonSchema } from "zod-to-json-schema";
43
import { ClientConfigSchema } from "@/client/config";
54
import { createFileSystemOrMemoryDriver } from "@/drivers/file-system/mod";
65
import type { ManagerDriver } from "@/manager/driver";
@@ -12,20 +11,16 @@ import {
1211
setup,
1312
} from "@/mod";
1413
import { type RunnerConfig, RunnerConfigSchema } from "@/registry/run-config";
15-
import {
16-
HttpActionRequestSchema,
17-
HttpActionResponseSchema,
18-
} from "@/schemas/client-protocol-zod/mod";
1914
import { VERSION } from "@/utils";
2015

21-
function main() {
16+
async function main() {
2217
const registryConfig: RegistryConfig = RegistryConfigSchema.parse({
2318
use: {},
2419
});
2520
const registry = setup(registryConfig);
2621

2722
const driverConfig: RunnerConfig = RunnerConfigSchema.parse({
28-
driver: createFileSystemOrMemoryDriver(false),
23+
driver: await createFileSystemOrMemoryDriver(false),
2924
getUpgradeWebSocket: () => () => unimplemented(),
3025
inspector: {
3126
enabled: false,
@@ -37,7 +32,6 @@ function main() {
3732
getWithKey: unimplemented,
3833
getOrCreateWithKey: unimplemented,
3934
createActor: unimplemented,
40-
listActors: unimplemented,
4135
sendRequest: unimplemented,
4236
openWebSocket: unimplemented,
4337
proxyRequest: unimplemented,
@@ -51,26 +45,22 @@ function main() {
5145
ClientConfigSchema.parse({}),
5246
);
5347

54-
const { openapi: managerOpenapi } = createManagerRouter(
48+
const { openapi } = createManagerRouter(
5549
registryConfig,
5650
driverConfig,
5751
managerDriver,
5852
driverConfig.driver!,
5953
client,
6054
);
6155

62-
// Get OpenAPI document
63-
const managerOpenApiDoc = managerOpenapi.getOpenAPIDocument({
56+
const openApiDoc = openapi.getOpenAPIDocument({
6457
openapi: "3.0.0",
6558
info: {
6659
version: VERSION,
6760
title: "RivetKit API",
6861
},
6962
});
7063

71-
// Inject actor router paths
72-
injectActorRouter(managerOpenApiDoc);
73-
7464
const outputPath = resolve(
7565
import.meta.dirname,
7666
"..",
@@ -80,136 +70,10 @@ function main() {
8070
"rivetkit-openapi",
8171
"openapi.json",
8272
);
83-
fs.writeFile(outputPath, JSON.stringify(managerOpenApiDoc, null, 2));
73+
await fs.writeFile(outputPath, JSON.stringify(openApiDoc, null, 2));
8474
console.log("Dumped OpenAPI to", outputPath);
8575
}
8676

87-
/**
88-
* Manually inject actor router paths into the OpenAPI spec.
89-
*
90-
* We do this manually instead of extracting from the actual router since the
91-
* actor routes support multiple encodings (JSON, CBOR, bare), but OpenAPI
92-
* specs are JSON-focused and don't cleanly represent multi-encoding routes.
93-
*/
94-
function injectActorRouter(openApiDoc: any) {
95-
if (!openApiDoc.paths) {
96-
openApiDoc.paths = {};
97-
}
98-
99-
// Convert Zod schemas to JSON Schema and remove $schema property
100-
const actionRequestSchema = zodToJsonSchema(HttpActionRequestSchema, {
101-
$refStrategy: "none",
102-
});
103-
delete (actionRequestSchema as any).$schema;
104-
105-
const actionResponseSchema = zodToJsonSchema(HttpActionResponseSchema, {
106-
$refStrategy: "none",
107-
});
108-
delete (actionResponseSchema as any).$schema;
109-
110-
// Common actorId parameter
111-
const actorIdParam = {
112-
name: "actorId",
113-
in: "path" as const,
114-
required: true,
115-
schema: {
116-
type: "string",
117-
},
118-
description: "The ID of the actor to target",
119-
};
120-
121-
// GET /gateway/{actorId}/health
122-
openApiDoc.paths["/gateway/{actorId}/health"] = {
123-
get: {
124-
parameters: [actorIdParam],
125-
responses: {
126-
200: {
127-
description: "Health check",
128-
content: {
129-
"text/plain": {
130-
schema: {
131-
type: "string",
132-
},
133-
},
134-
},
135-
},
136-
},
137-
},
138-
};
139-
140-
// POST /gateway/{actorId}/action/{action}
141-
openApiDoc.paths["/gateway/{actorId}/action/{action}"] = {
142-
post: {
143-
parameters: [
144-
actorIdParam,
145-
{
146-
name: "action",
147-
in: "path" as const,
148-
required: true,
149-
schema: {
150-
type: "string",
151-
},
152-
description: "The name of the action to execute",
153-
},
154-
],
155-
requestBody: {
156-
content: {
157-
"application/json": {
158-
schema: actionRequestSchema,
159-
},
160-
},
161-
},
162-
responses: {
163-
200: {
164-
description: "Action executed successfully",
165-
content: {
166-
"application/json": {
167-
schema: actionResponseSchema,
168-
},
169-
},
170-
},
171-
400: {
172-
description: "Invalid action",
173-
},
174-
500: {
175-
description: "Internal error",
176-
},
177-
},
178-
},
179-
};
180-
181-
// ALL /gateway/{actorId}/request/{path}
182-
const requestPath = {
183-
parameters: [
184-
actorIdParam,
185-
{
186-
name: "path",
187-
in: "path" as const,
188-
required: true,
189-
schema: {
190-
type: "string",
191-
},
192-
description: "The HTTP path to forward to the actor",
193-
},
194-
],
195-
responses: {
196-
200: {
197-
description: "Response from actor's raw HTTP handler",
198-
},
199-
},
200-
};
201-
202-
openApiDoc.paths["/gateway/{actorId}/request/{path}"] = {
203-
get: requestPath,
204-
post: requestPath,
205-
put: requestPath,
206-
delete: requestPath,
207-
patch: requestPath,
208-
head: requestPath,
209-
options: requestPath,
210-
};
211-
}
212-
21377
function unimplemented(): never {
21478
throw new Error("UNIMPLEMENTED");
21579
}

rivetkit-typescript/packages/rivetkit/src/drivers/default.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import type { DriverConfig, RunnerConfig } from "@/registry/run-config";
77
/**
88
* Chooses the appropriate driver based on the run configuration.
99
*/
10-
export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig {
10+
export async function chooseDefaultDriver(
11+
runConfig: RunnerConfig,
12+
): Promise<DriverConfig> {
1113
if (runConfig.endpoint && runConfig.driver) {
1214
throw new UserError(
1315
"Cannot specify both 'endpoint' and 'driver' in configuration",
@@ -31,5 +33,5 @@ export function chooseDefaultDriver(runConfig: RunnerConfig): DriverConfig {
3133
}
3234

3335
loggerWithoutContext().debug({ msg: "using default file system driver" });
34-
return createFileSystemOrMemoryDriver(true);
36+
return await createFileSystemOrMemoryDriver(true);
3537
}

0 commit comments

Comments
 (0)