@rivetkit/next-js 2.0.39 → 2.0.41

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/next-js/dist/client/mod.js","../../src/client/mod.ts"],"names":[],"mappings":"AAAA;ACAA,mEAAc","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/next-js/dist/client/mod.js","sourcesContent":[null,"export * from \"@rivetkit/react\";\n"]}
1
+ {"version":3,"sources":["/Users/nathan/rivet/rivetkit-typescript/packages/next-js/dist/client/mod.js","../../src/client/mod.ts"],"names":[],"mappings":"AAAA;ACAA,mEAAc","file":"/Users/nathan/rivet/rivetkit-typescript/packages/next-js/dist/client/mod.js","sourcesContent":[null,"export * from \"@rivetkit/react\";\n"]}
package/dist/mod.d.mts CHANGED
@@ -16,6 +16,11 @@ declare const toNextHandler: (registry: Registry<any>) => {
16
16
  all: string[];
17
17
  }>;
18
18
  }) => Promise<Response>;
19
+ DELETE: (request: Request, { params }: {
20
+ params: Promise<{
21
+ all: string[];
22
+ }>;
23
+ }) => Promise<Response>;
19
24
  PATCH: (request: Request, { params }: {
20
25
  params: Promise<{
21
26
  all: string[];
package/dist/mod.d.ts CHANGED
@@ -16,6 +16,11 @@ declare const toNextHandler: (registry: Registry<any>) => {
16
16
  all: string[];
17
17
  }>;
18
18
  }) => Promise<Response>;
19
+ DELETE: (request: Request, { params }: {
20
+ params: Promise<{
21
+ all: string[];
22
+ }>;
23
+ }) => Promise<Response>;
19
24
  PATCH: (request: Request, { params }: {
20
25
  params: Promise<{
21
26
  all: string[];
package/dist/mod.js CHANGED
@@ -1,18 +1,17 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/mod.ts
2
- var _fs = require('fs');
3
- var _path = require('path');
4
- var _utils = require('rivetkit/utils');
5
-
6
- // src/log.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/log.ts
7
2
  var _log = require('rivetkit/log');
8
3
  function logger() {
9
4
  return _log.getLogger.call(void 0, "driver-next-js");
10
5
  }
11
6
 
12
7
  // src/mod.ts
8
+ var DEV_RUNNER_VERSION = Math.floor(Date.now() / 1e3);
13
9
  var toNextHandler = (registry) => {
14
10
  registry.config.serveManager = false;
15
- registry.config.serverless = { ...registry.config.serverless, basePath: "/" };
11
+ registry.config.serverless = {
12
+ ...registry.config.serverless,
13
+ basePath: "/"
14
+ };
16
15
  if (process.env.NODE_ENV !== "production") {
17
16
  logger().debug(
18
17
  "detected development environment, auto-starting engine and auto-configuring serverless"
@@ -27,6 +26,10 @@ var toNextHandler = (registry) => {
27
26
  slotsPerRunner: 1,
28
27
  metadata: { provider: "next-js" }
29
28
  };
29
+ registry.config.runner = {
30
+ ...registry.config.runner,
31
+ version: DEV_RUNNER_VERSION
32
+ };
30
33
  } else {
31
34
  logger().debug(
32
35
  "detected production environment, will not auto-start engine and auto-configure serverless"
@@ -35,19 +38,15 @@ var toNextHandler = (registry) => {
35
38
  registry.config.noWelcome = true;
36
39
  const fetchWrapper = async (request, { params }) => {
37
40
  const { all } = await params;
38
- const newUrl = new URL(request.url);
39
- newUrl.pathname = `/${all.join("/")}`;
40
- if (false) {
41
- return await handleRequestWithFileWatcher(request, newUrl, fetch);
42
- } else {
43
- const newReq = new Request(newUrl, request);
44
- return await registry.handler(newReq);
45
- }
41
+ const targetUrl = new URL(request.url);
42
+ targetUrl.pathname = `/${all.join("/")}`;
43
+ return await registry.handler(new Request(targetUrl, request));
46
44
  };
47
45
  return {
48
46
  GET: fetchWrapper,
49
47
  POST: fetchWrapper,
50
48
  PUT: fetchWrapper,
49
+ DELETE: fetchWrapper,
51
50
  PATCH: fetchWrapper,
52
51
  HEAD: fetchWrapper,
53
52
  OPTIONS: fetchWrapper
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/rivet/rivet/rivetkit-typescript/packages/next-js/dist/mod.js","../src/mod.ts","../src/log.ts"],"names":[],"mappings":"AAAA;ACAA,wBAAqC;AACrC,4BAAqB;AAErB,uCAA+B;ADC/B;AACA;AELA,mCAA0B;AAEnB,SAAS,MAAA,CAAA,EAAS;AACxB,EAAA,OAAO,4BAAA,gBAA0B,CAAA;AAClC;AFMA;AACA;ACLO,IAAM,cAAA,EAAgB,CAAC,QAAA,EAAA,GAA4B;AAEzD,EAAA,QAAA,CAAS,MAAA,CAAO,aAAA,EAAe,KAAA;AAG/B,EAAA,QAAA,CAAS,MAAA,CAAO,WAAA,EAAa,EAAE,GAAG,QAAA,CAAS,MAAA,CAAO,UAAA,EAAY,QAAA,EAAU,IAAI,CAAA;AAE5E,EAAA,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,SAAA,IAAa,YAAA,EAAc;AAE1C,IAAA,MAAA,CAAO,CAAA,CAAE,KAAA;AAAA,MACR;AAAA,IACD,CAAA;AAEA,IAAA,MAAM,UAAA,oCACL,OAAA,CAAQ,GAAA,CAAI,oBAAA,UACZ,OAAA,CAAQ,GAAA,CAAI,wBAAA,UACZ,CAAA,iBAAA,mBAAoB,OAAA,CAAQ,GAAA,CAAI,IAAA,UAAQ,KAAI,CAAA,GAAA;AAIJ,IAAA;AACQ,IAAA;AAC/B,MAAA;AACL,MAAA;AACA,MAAA;AACK,MAAA;AACD,MAAA;AACgB,MAAA;AACjC,IAAA;AACM,EAAA;AACG,IAAA;AACR,MAAA;AACD,IAAA;AACD,EAAA;AAG4B,EAAA;AAMJ,EAAA;AACD,IAAA;AAEY,IAAA;AACC,IAAA;AAGxB,IAAA;AAEsD,MAAA;AAC1D,IAAA;AAEoC,MAAA;AACN,MAAA;AACrC,IAAA;AACD,EAAA;AAEO,EAAA;AACD,IAAA;AACC,IAAA;AACD,IAAA;AACE,IAAA;AACD,IAAA;AACG,IAAA;AACV,EAAA;AACD;ADlB4I;AACA;AACA","file":"/home/runner/work/rivet/rivet/rivetkit-typescript/packages/next-js/dist/mod.js","sourcesContent":[null,"import { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Registry } from \"rivetkit\";\nimport { stringifyError } from \"rivetkit/utils\";\nimport { logger } from \"./log\";\n\nexport const toNextHandler = (registry: Registry<any>) => {\n\t// Don't run server locally since we're using the fetch handler directly\n\tregistry.config.serveManager = false;\n\n\t// Set basePath to \"/\" since Next.js route strips the /api/rivet prefix\n\tregistry.config.serverless = { ...registry.config.serverless, basePath: \"/\" };\n\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\t// Auto-configure serverless runner if not in prod\n\t\tlogger().debug(\n\t\t\t\"detected development environment, auto-starting engine and auto-configuring serverless\",\n\t\t);\n\n\t\tconst publicUrl =\n\t\t\tprocess.env.NEXT_PUBLIC_SITE_URL ??\n\t\t\tprocess.env.NEXT_PUBLIC_VERCEL_URL ??\n\t\t\t`http://127.0.0.1:${process.env.PORT ?? 3000}`;\n\n\t\t// Set these on the registry's config directly since the legacy inputConfig\n\t\t// isn't used by the serverless router\n\t\tregistry.config.serverless.spawnEngine = true;\n\t\tregistry.config.serverless.configureRunnerPool = {\n\t\t\turl: `${publicUrl}/api/rivet`,\n\t\t\tminRunners: 0,\n\t\t\tmaxRunners: 100_000,\n\t\t\trequestLifespan: 300,\n\t\t\tslotsPerRunner: 1,\n\t\t\tmetadata: { provider: \"next-js\" },\n\t\t};\n\t} else {\n\t\tlogger().debug(\n\t\t\t\"detected production environment, will not auto-start engine and auto-configure serverless\",\n\t\t);\n\t}\n\n\t// Next logs this on every request\n\tregistry.config.noWelcome = true;\n\n\t// Function that Next will call when handling requests\n\tconst fetchWrapper = async (\n\t\trequest: Request,\n\t\t{ params }: { params: Promise<{ all: string[] }> },\n\t): Promise<Response> => {\n\t\tconst { all } = await params;\n\n\t\tconst newUrl = new URL(request.url);\n\t\tnewUrl.pathname = `/${all.join(\"/\")}`;\n\n\t\t// if (process.env.NODE_ENV === \"development\") {\n\t\tif (false) {\n\t\t\t// Special request handling for file watching\n\t\t\treturn await handleRequestWithFileWatcher(request, newUrl, fetch);\n\t\t} else {\n\t\t\t// Handle request\n\t\t\tconst newReq = new Request(newUrl, request);\n\t\t\treturn await registry.handler(newReq);\n\t\t}\n\t};\n\n\treturn {\n\t\tGET: fetchWrapper,\n\t\tPOST: fetchWrapper,\n\t\tPUT: fetchWrapper,\n\t\tPATCH: fetchWrapper,\n\t\tHEAD: fetchWrapper,\n\t\tOPTIONS: fetchWrapper,\n\t};\n};\n\n/**\n * Special request handler that will watch the source file to terminate this\n * request once complete.\n *\n * See docs on watchRouteFile for more information.\n */\nasync function handleRequestWithFileWatcher(\n\trequest: Request,\n\tnewUrl: URL,\n\tfetch: (request: Request, ...args: any) => Response | Promise<Response>,\n): Promise<Response> {\n\t// Create a new abort controller that we can abort, since the signal on\n\t// the request we cannot control\n\tconst mergedController = new AbortController();\n\tconst abortMerged = () => mergedController.abort();\n\trequest.signal?.addEventListener(\"abort\", abortMerged);\n\n\t// Watch for file changes in dev\n\t//\n\t// We spawn one watcher per-request since there is not a clean way of\n\t// cleaning up global watchers when hot reloading in Next\n\tconst watchIntervalId = watchRouteFile(mergedController);\n\n\t// Clear interval if request is aborted\n\trequest.signal.addEventListener(\"abort\", () => {\n\t\tlogger().debug(\"clearing file watcher interval: request aborted\");\n\t\tclearInterval(watchIntervalId);\n\t});\n\n\t// Replace URL and abort signal\n\tconst newReq = new Request(newUrl, {\n\t\t// Copy old request properties\n\t\tmethod: request.method,\n\t\theaders: request.headers,\n\t\tbody: request.body,\n\t\tcredentials: request.credentials,\n\t\tcache: request.cache,\n\t\tredirect: request.redirect,\n\t\treferrer: request.referrer,\n\t\tintegrity: request.integrity,\n\t\t// Override with new signal\n\t\tsignal: mergedController.signal,\n\t\t// Required for streaming body\n\t\tduplex: \"half\",\n\t} as RequestInit);\n\n\t// Handle request\n\tconst response = await fetch(newReq);\n\n\t// HACK: Next.js does not provide a way to detect when a request\n\t// finishes, so we need to tap the response stream\n\t//\n\t// We can't just wait for `await fetch` to finish since SSE streams run\n\t// for longer\n\tif (response.body) {\n\t\tconst wrappedStream = waitForStreamFinish(response.body, () => {\n\t\t\tlogger().debug(\"clearing file watcher interval: stream finished\");\n\t\t\tclearInterval(watchIntervalId);\n\t\t});\n\t\treturn new Response(wrappedStream, {\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t});\n\t} else {\n\t\t// No response body, clear interval immediately\n\t\tlogger().debug(\"clearing file watcher interval: no response body\");\n\t\tclearInterval(watchIntervalId);\n\t\treturn response;\n\t}\n}\n\n/**\n * HACK: Watch for file changes on this route in order to shut down the runner.\n * We do this because Next.js does not terminate long-running requests on file\n * change, so we need to manually shut down the runner in order to trigger a\n * new `/start` request with the new code.\n *\n * We don't use file watchers since those are frequently buggy x-platform and\n * subject to misconfigured inotify limits.\n */\nfunction watchRouteFile(abortController: AbortController): NodeJS.Timeout {\n\tlogger().debug(\"starting file watcher\");\n\n\tconst routePath = join(\n\t\tprocess.cwd(),\n\t\t\".next/server/app/api/rivet/[...all]/route.js\",\n\t);\n\n\tlet lastMtime: number | null = null;\n\tconst checkFile = () => {\n\t\tlogger().debug({ msg: \"checking for file changes\", routePath });\n\t\ttry {\n\t\t\tif (!existsSync(routePath)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst stats = statSync(routePath);\n\t\t\tconst mtime = stats.mtimeMs;\n\n\t\t\tif (lastMtime !== null && mtime !== lastMtime) {\n\t\t\t\tlogger().info({ msg: \"route file changed\", routePath });\n\t\t\t\tabortController.abort();\n\t\t\t}\n\n\t\t\tlastMtime = mtime;\n\t\t} catch (err) {\n\t\t\tlogger().info({\n\t\t\t\tmsg: \"failed to check for route file change\",\n\t\t\t\terr: stringifyError(err),\n\t\t\t});\n\t\t}\n\t};\n\n\tcheckFile();\n\n\treturn setInterval(checkFile, 1000);\n}\n\n/**\n * Waits for a stream to finish and calls onFinish on complete.\n *\n * Used for cancelling the file watcher.\n */\nfunction waitForStreamFinish(\n\tbody: ReadableStream<Uint8Array>,\n\tonFinish: () => void,\n): ReadableStream {\n\tconst reader = body.getReader();\n\treturn new ReadableStream({\n\t\tasync start(controller) {\n\t\t\ttry {\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\tlogger().debug(\"stream completed\");\n\t\t\t\t\t\tonFinish();\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tlogger().debug(\"stream errored\");\n\t\t\t\tonFinish();\n\t\t\t\tcontroller.error(err);\n\t\t\t}\n\t\t},\n\t\tcancel() {\n\t\t\tlogger().debug(\"stream cancelled\");\n\t\t\tonFinish();\n\t\t\treader.cancel();\n\t\t},\n\t});\n}\n","import { getLogger } from \"rivetkit/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-next-js\");\n}\n"]}
1
+ {"version":3,"sources":["/Users/nathan/rivet/rivetkit-typescript/packages/next-js/dist/mod.js","../src/log.ts","../src/mod.ts"],"names":[],"mappings":"AAAA;ACAA,mCAA0B;AAEnB,SAAS,MAAA,CAAA,EAAS;AACxB,EAAA,OAAO,4BAAA,gBAA0B,CAAA;AAClC;ADCA;AACA;AEIA,IAAM,mBAAA,EAAqB,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,EAAA,EAAI,GAAI,CAAA;AAEhD,IAAM,cAAA,EAAgB,CAAC,QAAA,EAAA,GAA4B;AAEzD,EAAA,QAAA,CAAS,MAAA,CAAO,aAAA,EAAe,KAAA;AAG/B,EAAA,QAAA,CAAS,MAAA,CAAO,WAAA,EAAa;AAAA,IAC5B,GAAG,QAAA,CAAS,MAAA,CAAO,UAAA;AAAA,IACnB,QAAA,EAAU;AAAA,EACX,CAAA;AAEA,EAAA,GAAA,CAAI,OAAA,CAAQ,GAAA,CAAI,SAAA,IAAa,YAAA,EAAc;AAC1C,IAAA,MAAA,CAAO,CAAA,CAAE,KAAA;AAAA,MACR;AAAA,IACD,CAAA;AAEA,IAAA,MAAM,UAAA,oCACL,OAAA,CAAQ,GAAA,CAAI,oBAAA,UACZ,OAAA,CAAQ,GAAA,CAAI,wBAAA,UACZ,CAAA,iBAAA,mBAAoB,OAAA,CAAQ,GAAA,CAAI,IAAA,UAAQ,KAAI,CAAA,GAAA;AAIJ,IAAA;AACQ,IAAA;AAC/B,MAAA;AACL,MAAA;AACA,MAAA;AACK,MAAA;AACD,MAAA;AACgB,MAAA;AACjC,IAAA;AAGyB,IAAA;AACL,MAAA;AACV,MAAA;AACV,IAAA;AACM,EAAA;AACG,IAAA;AACR,MAAA;AACD,IAAA;AACD,EAAA;AAG4B,EAAA;AAKJ,EAAA;AACD,IAAA;AACe,IAAA;AACC,IAAA;AAEuB,IAAA;AAC9D,EAAA;AAEO,EAAA;AACD,IAAA;AACC,IAAA;AACD,IAAA;AACG,IAAA;AACD,IAAA;AACD,IAAA;AACG,IAAA;AACV,EAAA;AACD;AFxB4I;AACA;AACA","file":"/Users/nathan/rivet/rivetkit-typescript/packages/next-js/dist/mod.js","sourcesContent":[null,"import { getLogger } from \"rivetkit/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-next-js\");\n}\n","import type { Registry } from \"rivetkit\";\nimport { logger } from \"./log\";\n\n// Runner version set to seconds since epoch when the module loads in development mode.\n//\n// This creates a version number that increments each time the code is updated\n// and the module reloads, allowing the engine to detect code changes via the\n// /metadata endpoint and hot-reload all actors by draining older runners.\n//\n// We use seconds (not milliseconds) because the runner version is a u32 on the engine side.\nconst DEV_RUNNER_VERSION = Math.floor(Date.now() / 1000);\n\nexport const toNextHandler = (registry: Registry<any>) => {\n\t// Don't run server locally since we're using the fetch handler directly\n\tregistry.config.serveManager = false;\n\n\t// Set basePath to \"/\" since Next.js route strips the /api/rivet prefix\n\tregistry.config.serverless = {\n\t\t...registry.config.serverless,\n\t\tbasePath: \"/\",\n\t};\n\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tlogger().debug(\n\t\t\t\"detected development environment, auto-starting engine and auto-configuring serverless\",\n\t\t);\n\n\t\tconst publicUrl =\n\t\t\tprocess.env.NEXT_PUBLIC_SITE_URL ??\n\t\t\tprocess.env.NEXT_PUBLIC_VERCEL_URL ??\n\t\t\t`http://127.0.0.1:${process.env.PORT ?? 3000}`;\n\n\t\t// Set these on the registry's config directly since the legacy inputConfig\n\t\t// isn't used by the serverless router\n\t\tregistry.config.serverless.spawnEngine = true;\n\t\tregistry.config.serverless.configureRunnerPool = {\n\t\t\turl: `${publicUrl}/api/rivet`,\n\t\t\tminRunners: 0,\n\t\t\tmaxRunners: 100_000,\n\t\t\trequestLifespan: 300,\n\t\t\tslotsPerRunner: 1,\n\t\t\tmetadata: { provider: \"next-js\" },\n\t\t};\n\n\t\t// Set runner version to enable hot-reloading on code changes\n\t\tregistry.config.runner = {\n\t\t\t...registry.config.runner,\n\t\t\tversion: DEV_RUNNER_VERSION,\n\t\t};\n\t} else {\n\t\tlogger().debug(\n\t\t\t\"detected production environment, will not auto-start engine and auto-configure serverless\",\n\t\t);\n\t}\n\n\t// Next logs this on every request\n\tregistry.config.noWelcome = true;\n\n\tconst fetchWrapper = async (\n\t\trequest: Request,\n\t\t{ params }: { params: Promise<{ all: string[] }> },\n\t): Promise<Response> => {\n\t\tconst { all } = await params;\n\t\tconst targetUrl = new URL(request.url);\n\t\ttargetUrl.pathname = `/${all.join(\"/\")}`;\n\n\t\treturn await registry.handler(new Request(targetUrl, request));\n\t};\n\n\treturn {\n\t\tGET: fetchWrapper,\n\t\tPOST: fetchWrapper,\n\t\tPUT: fetchWrapper,\n\t\tDELETE: fetchWrapper,\n\t\tPATCH: fetchWrapper,\n\t\tHEAD: fetchWrapper,\n\t\tOPTIONS: fetchWrapper,\n\t};\n};\n"]}
package/dist/mod.mjs CHANGED
@@ -1,8 +1,3 @@
1
- // src/mod.ts
2
- import { existsSync, statSync } from "fs";
3
- import { join } from "path";
4
- import { stringifyError } from "rivetkit/utils";
5
-
6
1
  // src/log.ts
7
2
  import { getLogger } from "rivetkit/log";
8
3
  function logger() {
@@ -10,9 +5,13 @@ function logger() {
10
5
  }
11
6
 
12
7
  // src/mod.ts
8
+ var DEV_RUNNER_VERSION = Math.floor(Date.now() / 1e3);
13
9
  var toNextHandler = (registry) => {
14
10
  registry.config.serveManager = false;
15
- registry.config.serverless = { ...registry.config.serverless, basePath: "/" };
11
+ registry.config.serverless = {
12
+ ...registry.config.serverless,
13
+ basePath: "/"
14
+ };
16
15
  if (process.env.NODE_ENV !== "production") {
17
16
  logger().debug(
18
17
  "detected development environment, auto-starting engine and auto-configuring serverless"
@@ -27,6 +26,10 @@ var toNextHandler = (registry) => {
27
26
  slotsPerRunner: 1,
28
27
  metadata: { provider: "next-js" }
29
28
  };
29
+ registry.config.runner = {
30
+ ...registry.config.runner,
31
+ version: DEV_RUNNER_VERSION
32
+ };
30
33
  } else {
31
34
  logger().debug(
32
35
  "detected production environment, will not auto-start engine and auto-configure serverless"
@@ -35,19 +38,15 @@ var toNextHandler = (registry) => {
35
38
  registry.config.noWelcome = true;
36
39
  const fetchWrapper = async (request, { params }) => {
37
40
  const { all } = await params;
38
- const newUrl = new URL(request.url);
39
- newUrl.pathname = `/${all.join("/")}`;
40
- if (false) {
41
- return await handleRequestWithFileWatcher(request, newUrl, fetch);
42
- } else {
43
- const newReq = new Request(newUrl, request);
44
- return await registry.handler(newReq);
45
- }
41
+ const targetUrl = new URL(request.url);
42
+ targetUrl.pathname = `/${all.join("/")}`;
43
+ return await registry.handler(new Request(targetUrl, request));
46
44
  };
47
45
  return {
48
46
  GET: fetchWrapper,
49
47
  POST: fetchWrapper,
50
48
  PUT: fetchWrapper,
49
+ DELETE: fetchWrapper,
51
50
  PATCH: fetchWrapper,
52
51
  HEAD: fetchWrapper,
53
52
  OPTIONS: fetchWrapper
package/dist/mod.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mod.ts","../src/log.ts"],"sourcesContent":["import { existsSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type { Registry } from \"rivetkit\";\nimport { stringifyError } from \"rivetkit/utils\";\nimport { logger } from \"./log\";\n\nexport const toNextHandler = (registry: Registry<any>) => {\n\t// Don't run server locally since we're using the fetch handler directly\n\tregistry.config.serveManager = false;\n\n\t// Set basePath to \"/\" since Next.js route strips the /api/rivet prefix\n\tregistry.config.serverless = { ...registry.config.serverless, basePath: \"/\" };\n\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\t// Auto-configure serverless runner if not in prod\n\t\tlogger().debug(\n\t\t\t\"detected development environment, auto-starting engine and auto-configuring serverless\",\n\t\t);\n\n\t\tconst publicUrl =\n\t\t\tprocess.env.NEXT_PUBLIC_SITE_URL ??\n\t\t\tprocess.env.NEXT_PUBLIC_VERCEL_URL ??\n\t\t\t`http://127.0.0.1:${process.env.PORT ?? 3000}`;\n\n\t\t// Set these on the registry's config directly since the legacy inputConfig\n\t\t// isn't used by the serverless router\n\t\tregistry.config.serverless.spawnEngine = true;\n\t\tregistry.config.serverless.configureRunnerPool = {\n\t\t\turl: `${publicUrl}/api/rivet`,\n\t\t\tminRunners: 0,\n\t\t\tmaxRunners: 100_000,\n\t\t\trequestLifespan: 300,\n\t\t\tslotsPerRunner: 1,\n\t\t\tmetadata: { provider: \"next-js\" },\n\t\t};\n\t} else {\n\t\tlogger().debug(\n\t\t\t\"detected production environment, will not auto-start engine and auto-configure serverless\",\n\t\t);\n\t}\n\n\t// Next logs this on every request\n\tregistry.config.noWelcome = true;\n\n\t// Function that Next will call when handling requests\n\tconst fetchWrapper = async (\n\t\trequest: Request,\n\t\t{ params }: { params: Promise<{ all: string[] }> },\n\t): Promise<Response> => {\n\t\tconst { all } = await params;\n\n\t\tconst newUrl = new URL(request.url);\n\t\tnewUrl.pathname = `/${all.join(\"/\")}`;\n\n\t\t// if (process.env.NODE_ENV === \"development\") {\n\t\tif (false) {\n\t\t\t// Special request handling for file watching\n\t\t\treturn await handleRequestWithFileWatcher(request, newUrl, fetch);\n\t\t} else {\n\t\t\t// Handle request\n\t\t\tconst newReq = new Request(newUrl, request);\n\t\t\treturn await registry.handler(newReq);\n\t\t}\n\t};\n\n\treturn {\n\t\tGET: fetchWrapper,\n\t\tPOST: fetchWrapper,\n\t\tPUT: fetchWrapper,\n\t\tPATCH: fetchWrapper,\n\t\tHEAD: fetchWrapper,\n\t\tOPTIONS: fetchWrapper,\n\t};\n};\n\n/**\n * Special request handler that will watch the source file to terminate this\n * request once complete.\n *\n * See docs on watchRouteFile for more information.\n */\nasync function handleRequestWithFileWatcher(\n\trequest: Request,\n\tnewUrl: URL,\n\tfetch: (request: Request, ...args: any) => Response | Promise<Response>,\n): Promise<Response> {\n\t// Create a new abort controller that we can abort, since the signal on\n\t// the request we cannot control\n\tconst mergedController = new AbortController();\n\tconst abortMerged = () => mergedController.abort();\n\trequest.signal?.addEventListener(\"abort\", abortMerged);\n\n\t// Watch for file changes in dev\n\t//\n\t// We spawn one watcher per-request since there is not a clean way of\n\t// cleaning up global watchers when hot reloading in Next\n\tconst watchIntervalId = watchRouteFile(mergedController);\n\n\t// Clear interval if request is aborted\n\trequest.signal.addEventListener(\"abort\", () => {\n\t\tlogger().debug(\"clearing file watcher interval: request aborted\");\n\t\tclearInterval(watchIntervalId);\n\t});\n\n\t// Replace URL and abort signal\n\tconst newReq = new Request(newUrl, {\n\t\t// Copy old request properties\n\t\tmethod: request.method,\n\t\theaders: request.headers,\n\t\tbody: request.body,\n\t\tcredentials: request.credentials,\n\t\tcache: request.cache,\n\t\tredirect: request.redirect,\n\t\treferrer: request.referrer,\n\t\tintegrity: request.integrity,\n\t\t// Override with new signal\n\t\tsignal: mergedController.signal,\n\t\t// Required for streaming body\n\t\tduplex: \"half\",\n\t} as RequestInit);\n\n\t// Handle request\n\tconst response = await fetch(newReq);\n\n\t// HACK: Next.js does not provide a way to detect when a request\n\t// finishes, so we need to tap the response stream\n\t//\n\t// We can't just wait for `await fetch` to finish since SSE streams run\n\t// for longer\n\tif (response.body) {\n\t\tconst wrappedStream = waitForStreamFinish(response.body, () => {\n\t\t\tlogger().debug(\"clearing file watcher interval: stream finished\");\n\t\t\tclearInterval(watchIntervalId);\n\t\t});\n\t\treturn new Response(wrappedStream, {\n\t\t\tstatus: response.status,\n\t\t\tstatusText: response.statusText,\n\t\t\theaders: response.headers,\n\t\t});\n\t} else {\n\t\t// No response body, clear interval immediately\n\t\tlogger().debug(\"clearing file watcher interval: no response body\");\n\t\tclearInterval(watchIntervalId);\n\t\treturn response;\n\t}\n}\n\n/**\n * HACK: Watch for file changes on this route in order to shut down the runner.\n * We do this because Next.js does not terminate long-running requests on file\n * change, so we need to manually shut down the runner in order to trigger a\n * new `/start` request with the new code.\n *\n * We don't use file watchers since those are frequently buggy x-platform and\n * subject to misconfigured inotify limits.\n */\nfunction watchRouteFile(abortController: AbortController): NodeJS.Timeout {\n\tlogger().debug(\"starting file watcher\");\n\n\tconst routePath = join(\n\t\tprocess.cwd(),\n\t\t\".next/server/app/api/rivet/[...all]/route.js\",\n\t);\n\n\tlet lastMtime: number | null = null;\n\tconst checkFile = () => {\n\t\tlogger().debug({ msg: \"checking for file changes\", routePath });\n\t\ttry {\n\t\t\tif (!existsSync(routePath)) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst stats = statSync(routePath);\n\t\t\tconst mtime = stats.mtimeMs;\n\n\t\t\tif (lastMtime !== null && mtime !== lastMtime) {\n\t\t\t\tlogger().info({ msg: \"route file changed\", routePath });\n\t\t\t\tabortController.abort();\n\t\t\t}\n\n\t\t\tlastMtime = mtime;\n\t\t} catch (err) {\n\t\t\tlogger().info({\n\t\t\t\tmsg: \"failed to check for route file change\",\n\t\t\t\terr: stringifyError(err),\n\t\t\t});\n\t\t}\n\t};\n\n\tcheckFile();\n\n\treturn setInterval(checkFile, 1000);\n}\n\n/**\n * Waits for a stream to finish and calls onFinish on complete.\n *\n * Used for cancelling the file watcher.\n */\nfunction waitForStreamFinish(\n\tbody: ReadableStream<Uint8Array>,\n\tonFinish: () => void,\n): ReadableStream {\n\tconst reader = body.getReader();\n\treturn new ReadableStream({\n\t\tasync start(controller) {\n\t\t\ttry {\n\t\t\t\twhile (true) {\n\t\t\t\t\tconst { done, value } = await reader.read();\n\t\t\t\t\tif (done) {\n\t\t\t\t\t\tlogger().debug(\"stream completed\");\n\t\t\t\t\t\tonFinish();\n\t\t\t\t\t\tcontroller.close();\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcontroller.enqueue(value);\n\t\t\t\t}\n\t\t\t} catch (err) {\n\t\t\t\tlogger().debug(\"stream errored\");\n\t\t\t\tonFinish();\n\t\t\t\tcontroller.error(err);\n\t\t\t}\n\t\t},\n\t\tcancel() {\n\t\t\tlogger().debug(\"stream cancelled\");\n\t\t\tonFinish();\n\t\t\treader.cancel();\n\t\t},\n\t});\n}\n","import { getLogger } from \"rivetkit/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-next-js\");\n}\n"],"mappings":";AAAA,SAAS,YAAY,gBAAgB;AACrC,SAAS,YAAY;AAErB,SAAS,sBAAsB;;;ACH/B,SAAS,iBAAiB;AAEnB,SAAS,SAAS;AACxB,SAAO,UAAU,gBAAgB;AAClC;;;ADEO,IAAM,gBAAgB,CAAC,aAA4B;AAEzD,WAAS,OAAO,eAAe;AAG/B,WAAS,OAAO,aAAa,EAAE,GAAG,SAAS,OAAO,YAAY,UAAU,IAAI;AAE5E,MAAI,QAAQ,IAAI,aAAa,cAAc;AAE1C,WAAO,EAAE;AAAA,MACR;AAAA,IACD;AAEA,UAAM,YACL,QAAQ,IAAI,wBACZ,QAAQ,IAAI,0BACZ,oBAAoB,QAAQ,IAAI,QAAQ,GAAI;AAI7C,aAAS,OAAO,WAAW,cAAc;AACzC,aAAS,OAAO,WAAW,sBAAsB;AAAA,MAChD,KAAK,GAAG,SAAS;AAAA,MACjB,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU,EAAE,UAAU,UAAU;AAAA,IACjC;AAAA,EACD,OAAO;AACN,WAAO,EAAE;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAGA,WAAS,OAAO,YAAY;AAG5B,QAAM,eAAe,OACpB,SACA,EAAE,OAAO,MACc;AACvB,UAAM,EAAE,IAAI,IAAI,MAAM;AAEtB,UAAM,SAAS,IAAI,IAAI,QAAQ,GAAG;AAClC,WAAO,WAAW,IAAI,IAAI,KAAK,GAAG,CAAC;AAGnC,QAAI,OAAO;AAEV,aAAO,MAAM,6BAA6B,SAAS,QAAQ,KAAK;AAAA,IACjE,OAAO;AAEN,YAAM,SAAS,IAAI,QAAQ,QAAQ,OAAO;AAC1C,aAAO,MAAM,SAAS,QAAQ,MAAM;AAAA,IACrC;AAAA,EACD;AAEA,SAAO;AAAA,IACN,KAAK;AAAA,IACL,MAAM;AAAA,IACN,KAAK;AAAA,IACL,OAAO;AAAA,IACP,MAAM;AAAA,IACN,SAAS;AAAA,EACV;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/log.ts","../src/mod.ts"],"sourcesContent":["import { getLogger } from \"rivetkit/log\";\n\nexport function logger() {\n\treturn getLogger(\"driver-next-js\");\n}\n","import type { Registry } from \"rivetkit\";\nimport { logger } from \"./log\";\n\n// Runner version set to seconds since epoch when the module loads in development mode.\n//\n// This creates a version number that increments each time the code is updated\n// and the module reloads, allowing the engine to detect code changes via the\n// /metadata endpoint and hot-reload all actors by draining older runners.\n//\n// We use seconds (not milliseconds) because the runner version is a u32 on the engine side.\nconst DEV_RUNNER_VERSION = Math.floor(Date.now() / 1000);\n\nexport const toNextHandler = (registry: Registry<any>) => {\n\t// Don't run server locally since we're using the fetch handler directly\n\tregistry.config.serveManager = false;\n\n\t// Set basePath to \"/\" since Next.js route strips the /api/rivet prefix\n\tregistry.config.serverless = {\n\t\t...registry.config.serverless,\n\t\tbasePath: \"/\",\n\t};\n\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tlogger().debug(\n\t\t\t\"detected development environment, auto-starting engine and auto-configuring serverless\",\n\t\t);\n\n\t\tconst publicUrl =\n\t\t\tprocess.env.NEXT_PUBLIC_SITE_URL ??\n\t\t\tprocess.env.NEXT_PUBLIC_VERCEL_URL ??\n\t\t\t`http://127.0.0.1:${process.env.PORT ?? 3000}`;\n\n\t\t// Set these on the registry's config directly since the legacy inputConfig\n\t\t// isn't used by the serverless router\n\t\tregistry.config.serverless.spawnEngine = true;\n\t\tregistry.config.serverless.configureRunnerPool = {\n\t\t\turl: `${publicUrl}/api/rivet`,\n\t\t\tminRunners: 0,\n\t\t\tmaxRunners: 100_000,\n\t\t\trequestLifespan: 300,\n\t\t\tslotsPerRunner: 1,\n\t\t\tmetadata: { provider: \"next-js\" },\n\t\t};\n\n\t\t// Set runner version to enable hot-reloading on code changes\n\t\tregistry.config.runner = {\n\t\t\t...registry.config.runner,\n\t\t\tversion: DEV_RUNNER_VERSION,\n\t\t};\n\t} else {\n\t\tlogger().debug(\n\t\t\t\"detected production environment, will not auto-start engine and auto-configure serverless\",\n\t\t);\n\t}\n\n\t// Next logs this on every request\n\tregistry.config.noWelcome = true;\n\n\tconst fetchWrapper = async (\n\t\trequest: Request,\n\t\t{ params }: { params: Promise<{ all: string[] }> },\n\t): Promise<Response> => {\n\t\tconst { all } = await params;\n\t\tconst targetUrl = new URL(request.url);\n\t\ttargetUrl.pathname = `/${all.join(\"/\")}`;\n\n\t\treturn await registry.handler(new Request(targetUrl, request));\n\t};\n\n\treturn {\n\t\tGET: fetchWrapper,\n\t\tPOST: fetchWrapper,\n\t\tPUT: fetchWrapper,\n\t\tDELETE: fetchWrapper,\n\t\tPATCH: fetchWrapper,\n\t\tHEAD: fetchWrapper,\n\t\tOPTIONS: fetchWrapper,\n\t};\n};\n"],"mappings":";AAAA,SAAS,iBAAiB;AAEnB,SAAS,SAAS;AACxB,SAAO,UAAU,gBAAgB;AAClC;;;ACMA,IAAM,qBAAqB,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI;AAEhD,IAAM,gBAAgB,CAAC,aAA4B;AAEzD,WAAS,OAAO,eAAe;AAG/B,WAAS,OAAO,aAAa;AAAA,IAC5B,GAAG,SAAS,OAAO;AAAA,IACnB,UAAU;AAAA,EACX;AAEA,MAAI,QAAQ,IAAI,aAAa,cAAc;AAC1C,WAAO,EAAE;AAAA,MACR;AAAA,IACD;AAEA,UAAM,YACL,QAAQ,IAAI,wBACZ,QAAQ,IAAI,0BACZ,oBAAoB,QAAQ,IAAI,QAAQ,GAAI;AAI7C,aAAS,OAAO,WAAW,cAAc;AACzC,aAAS,OAAO,WAAW,sBAAsB;AAAA,MAChD,KAAK,GAAG,SAAS;AAAA,MACjB,YAAY;AAAA,MACZ,YAAY;AAAA,MACZ,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,UAAU,EAAE,UAAU,UAAU;AAAA,IACjC;AAGA,aAAS,OAAO,SAAS;AAAA,MACxB,GAAG,SAAS,OAAO;AAAA,MACnB,SAAS;AAAA,IACV;AAAA,EACD,OAAO;AACN,WAAO,EAAE;AAAA,MACR;AAAA,IACD;AAAA,EACD;AAGA,WAAS,OAAO,YAAY;AAE5B,QAAM,eAAe,OACpB,SACA,EAAE,OAAO,MACc;AACvB,UAAM,EAAE,IAAI,IAAI,MAAM;AACtB,UAAM,YAAY,IAAI,IAAI,QAAQ,GAAG;AACrC,cAAU,WAAW,IAAI,IAAI,KAAK,GAAG,CAAC;AAEtC,WAAO,MAAM,SAAS,QAAQ,IAAI,QAAQ,WAAW,OAAO,CAAC;AAAA,EAC9D;AAEA,SAAO;AAAA,IACN,KAAK;AAAA,IACL,MAAM;AAAA,IACN,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,MAAM;AAAA,IACN,SAAS;AAAA,EACV;AACD;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivetkit/next-js",
3
- "version": "2.0.39",
3
+ "version": "2.0.41",
4
4
  "description": "Next.js integration for RivetKit actors and client",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -49,8 +49,8 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "hono": "^4.8.3",
52
- "@rivetkit/react": "2.0.39",
53
- "rivetkit": "^2.0.39"
52
+ "@rivetkit/react": "2.0.41",
53
+ "rivetkit": "^2.0.41"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "react": "^18 || ^19",