@runlot/next 0.1.0-rc.73 → 0.1.0-rc.75
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/dist/build.d.ts +22 -17
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +43 -27
- package/dist/build.js.map +1 -1
- package/dist/entry.d.ts +4 -3
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +11 -9
- package/dist/entry.js.map +1 -1
- package/dist/index.d.ts +13 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -25
- package/dist/index.js.map +1 -1
- package/dist/opennext/context.d.ts +6 -3
- package/dist/opennext/context.d.ts.map +1 -1
- package/dist/opennext/context.js +17 -12
- package/dist/opennext/context.js.map +1 -1
- package/dist/opennext/incremental-cache.d.ts +2 -1
- package/dist/opennext/incremental-cache.d.ts.map +1 -1
- package/dist/opennext/incremental-cache.js +18 -12
- package/dist/opennext/incremental-cache.js.map +1 -1
- package/dist/opennext/tag-cache.d.ts +3 -3
- package/dist/opennext/tag-cache.d.ts.map +1 -1
- package/dist/opennext/tag-cache.js +15 -11
- package/dist/opennext/tag-cache.js.map +1 -1
- package/dist/store.d.ts +12 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +22 -20
- package/dist/store.js.map +1 -1
- package/package.json +4 -4
package/dist/build.d.ts
CHANGED
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** Where the generated OpenNext config lives. It is kept outside `.open-next`
|
|
2
|
+
* because the build erases that every time. */
|
|
2
3
|
export declare const WORK_DIR = ".runlot-next";
|
|
3
4
|
export declare const ENTRY_NAME = "runlot-entry.js";
|
|
4
5
|
export interface BuildNextOptions {
|
|
5
|
-
/** Next
|
|
6
|
+
/** The Next project root (where `runlot.json` is). */
|
|
6
7
|
dir: string;
|
|
7
|
-
/** `
|
|
8
|
+
/** The `compatibilityDate` from `runlot.json`. OpenNext uses it only for one
|
|
9
|
+
* warning line. */
|
|
8
10
|
compatibilityDate?: string;
|
|
9
11
|
log?: (line: string) => void;
|
|
10
12
|
}
|
|
11
13
|
export interface BuildNextResult {
|
|
12
|
-
/**
|
|
14
|
+
/** The entry point to hand to our bundler (an absolute path). */
|
|
13
15
|
worker: string;
|
|
14
|
-
/**
|
|
16
|
+
/** The static asset directory (an absolute path). */
|
|
15
17
|
assets: string;
|
|
16
|
-
/** OpenNext
|
|
18
|
+
/** The OpenNext output directory (an absolute path). It is the bundler's
|
|
19
|
+
* `absWorkingDir`. */
|
|
17
20
|
outputDir: string;
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
|
-
*
|
|
23
|
+
* The entry point we stand up.
|
|
21
24
|
*
|
|
22
|
-
* OpenNext
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
+
* It wraps the default export of OpenNext's `worker.js` and lets the other
|
|
26
|
+
* exports (Durable Object classes and so on) pass straight through. `export *`
|
|
27
|
+
* does not re-export the default, so the two lines do not collide.
|
|
25
28
|
*/
|
|
26
|
-
export declare const ENTRY_SOURCE = "//
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
export declare const ENTRY_SOURCE = "// This file was made by runlot. Edits are overwritten on the next deploy.\nimport worker from \"./worker.js\";\nimport { wrap } from \"@runlot/next/entry\";\n\nexport * from \"./worker.js\";\nexport default wrap(worker);\n";
|
|
30
|
+
/** The OpenNext config we use when the user has not put down one of their own
|
|
31
|
+
* (the table in docs/nextjs.md §2). */
|
|
32
|
+
export declare const OPEN_NEXT_CONFIG_SOURCE = "// This file was made by runlot. Edits are overwritten on the next deploy.\n// To handle it yourself, put an open-next.config.ts in the project root \u2014 if one\n// is there, that is the one we use.\nimport { defineCloudflareConfig } from \"@opennextjs/cloudflare\";\nimport queue from \"@opennextjs/cloudflare/overrides/queue/memory-queue\";\nimport incrementalCache from \"@runlot/next/opennext/incremental-cache\";\nimport tagCache from \"@runlot/next/opennext/tag-cache\";\n\nexport default defineCloudflareConfig({\n incrementalCache,\n tagCache,\n queue,\n enableCacheInterception: true,\n});\n";
|
|
33
|
+
/** Gives the path of the project's own OpenNext config when it has one, and
|
|
34
|
+
* otherwise creates ours and gives that path. */
|
|
30
35
|
export declare function openNextConfigPath(dir: string, log: (line: string) => void): string;
|
|
31
36
|
/**
|
|
32
|
-
* `next build` → OpenNext →
|
|
37
|
+
* `next build` → OpenNext → our entry point.
|
|
33
38
|
*
|
|
34
|
-
* `process.cwd()`
|
|
35
|
-
*
|
|
39
|
+
* It moves `process.cwd()` to the project: OpenNext's `normalizeOptions` builds
|
|
40
|
+
* the app path and the output path out of the cwd. It is moved back at the end.
|
|
36
41
|
*/
|
|
37
42
|
export declare function buildNext(opts: BuildNextOptions): Promise<BuildNextResult>;
|
|
38
43
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAgBA;gDACgD;AAChD,eAAO,MAAM,QAAQ,iBAAiB,CAAC;AACvC,eAAO,MAAM,UAAU,oBAAoB,CAAC;AAE5C,MAAM,WAAW,gBAAgB;IAC/B,sDAAsD;IACtD,GAAG,EAAE,MAAM,CAAC;IACZ;wBACoB;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,MAAM,EAAE,MAAM,CAAC;IACf;2BACuB;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,oOAMxB,CAAC;AAEF;wCACwC;AACxC,eAAO,MAAM,uBAAuB,mmBAcnC,CAAC;AAIF;kDACkD;AAClD,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAanF;AAWD;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAqFhF"}
|
package/dist/build.js
CHANGED
|
@@ -1,36 +1,41 @@
|
|
|
1
|
-
// `@runlot/next/build` — `runlot deploy`
|
|
2
|
-
// (docs/nextjs.md §2).
|
|
1
|
+
// `@runlot/next/build` — the one function `runlot deploy` calls in a Next
|
|
2
|
+
// project (docs/nextjs.md §2).
|
|
3
3
|
//
|
|
4
|
-
// OpenNext
|
|
5
|
-
// wrangler
|
|
6
|
-
//
|
|
7
|
-
// `
|
|
4
|
+
// It calls OpenNext's **build function directly, not its CLI**. The CLI carries
|
|
5
|
+
// yargs and wrangler's `unstable_readConfig`, and the only values it actually
|
|
6
|
+
// reads out of that config are `compatibility_date` and
|
|
7
|
+
// `assets.run_worker_first`. We supply those two from `runlot.json` — no
|
|
8
|
+
// `wrangler.toml` is created.
|
|
8
9
|
//
|
|
9
|
-
//
|
|
10
|
+
// This file runs in node (not in a worker). That is why it uses `node:fs`
|
|
11
|
+
// directly.
|
|
10
12
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
11
13
|
import { createRequire } from "node:module";
|
|
12
14
|
import { dirname, join, resolve } from "node:path";
|
|
13
15
|
import { pathToFileURL } from "node:url";
|
|
14
|
-
/**
|
|
16
|
+
/** Where the generated OpenNext config lives. It is kept outside `.open-next`
|
|
17
|
+
* because the build erases that every time. */
|
|
15
18
|
export const WORK_DIR = ".runlot-next";
|
|
16
19
|
export const ENTRY_NAME = "runlot-entry.js";
|
|
17
20
|
/**
|
|
18
|
-
*
|
|
21
|
+
* The entry point we stand up.
|
|
19
22
|
*
|
|
20
|
-
* OpenNext
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
+
* It wraps the default export of OpenNext's `worker.js` and lets the other
|
|
24
|
+
* exports (Durable Object classes and so on) pass straight through. `export *`
|
|
25
|
+
* does not re-export the default, so the two lines do not collide.
|
|
23
26
|
*/
|
|
24
|
-
export const ENTRY_SOURCE = `// runlot
|
|
27
|
+
export const ENTRY_SOURCE = `// This file was made by runlot. Edits are overwritten on the next deploy.
|
|
25
28
|
import worker from "./worker.js";
|
|
26
29
|
import { wrap } from "@runlot/next/entry";
|
|
27
30
|
|
|
28
31
|
export * from "./worker.js";
|
|
29
32
|
export default wrap(worker);
|
|
30
33
|
`;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
/** The OpenNext config we use when the user has not put down one of their own
|
|
35
|
+
* (the table in docs/nextjs.md §2). */
|
|
36
|
+
export const OPEN_NEXT_CONFIG_SOURCE = `// This file was made by runlot. Edits are overwritten on the next deploy.
|
|
37
|
+
// To handle it yourself, put an open-next.config.ts in the project root — if one
|
|
38
|
+
// is there, that is the one we use.
|
|
34
39
|
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
|
|
35
40
|
import queue from "@opennextjs/cloudflare/overrides/queue/memory-queue";
|
|
36
41
|
import incrementalCache from "@runlot/next/opennext/incremental-cache";
|
|
@@ -44,7 +49,8 @@ export default defineCloudflareConfig({
|
|
|
44
49
|
});
|
|
45
50
|
`;
|
|
46
51
|
const USER_CONFIG_NAMES = ["open-next.config.ts", "open-next.config.mjs", "open-next.config.js"];
|
|
47
|
-
/**
|
|
52
|
+
/** Gives the path of the project's own OpenNext config when it has one, and
|
|
53
|
+
* otherwise creates ours and gives that path. */
|
|
48
54
|
export function openNextConfigPath(dir, log) {
|
|
49
55
|
for (const name of USER_CONFIG_NAMES) {
|
|
50
56
|
const path = join(dir, name);
|
|
@@ -63,10 +69,10 @@ async function load(path) {
|
|
|
63
69
|
return (await import(pathToFileURL(path).href));
|
|
64
70
|
}
|
|
65
71
|
/**
|
|
66
|
-
* `next build` → OpenNext →
|
|
72
|
+
* `next build` → OpenNext → our entry point.
|
|
67
73
|
*
|
|
68
|
-
* `process.cwd()`
|
|
69
|
-
*
|
|
74
|
+
* It moves `process.cwd()` to the project: OpenNext's `normalizeOptions` builds
|
|
75
|
+
* the app path and the output path out of the cwd. It is moved back at the end.
|
|
70
76
|
*/
|
|
71
77
|
export async function buildNext(opts) {
|
|
72
78
|
const dir = resolve(opts.dir);
|
|
@@ -79,8 +85,9 @@ export async function buildNext(opts) {
|
|
|
79
85
|
catch {
|
|
80
86
|
throw new Error("Could not find @opennextjs/cloudflare. Reinstall @runlot/next.");
|
|
81
87
|
}
|
|
82
|
-
//
|
|
83
|
-
//
|
|
88
|
+
// The package's exports only open `dist/api/*`. The build function is under
|
|
89
|
+
// `dist/cli/`, so it cannot be reached by specifier; we walk sideways from
|
|
90
|
+
// the resolved path.
|
|
84
91
|
const distDir = resolve(dirname(apiIndex), "..");
|
|
85
92
|
const fromCloudflare = createRequire(apiIndex);
|
|
86
93
|
const awsIndex = fromCloudflare.resolve("@opennextjs/aws/index.js");
|
|
@@ -88,7 +95,8 @@ export async function buildNext(opts) {
|
|
|
88
95
|
const { ensureCloudflareConfig } = await load(join(distDir, "cli", "build", "utils", "ensure-cf-config.js"));
|
|
89
96
|
const { compileOpenNextConfig } = await load(fromCloudflare.resolve("@opennextjs/aws/build/compileConfig.js"));
|
|
90
97
|
const { normalizeOptions } = await load(fromCloudflare.resolve("@opennextjs/aws/build/helper.js"));
|
|
91
|
-
// Next
|
|
98
|
+
// Next itself belongs to the user's project. Using ours would split the
|
|
99
|
+
// versions.
|
|
92
100
|
const fromProject = createRequire(join(dir, "package.json"));
|
|
93
101
|
let nextBin;
|
|
94
102
|
try {
|
|
@@ -103,9 +111,10 @@ export async function buildNext(opts) {
|
|
|
103
111
|
try {
|
|
104
112
|
const { config, buildDir } = await compileOpenNextConfig(configPath, { compileEdge: true });
|
|
105
113
|
ensureCloudflareConfig(config);
|
|
106
|
-
//
|
|
107
|
-
// `npm run build
|
|
108
|
-
//
|
|
114
|
+
// Call the next binary directly rather than the user's `package.json`
|
|
115
|
+
// scripts. It is common for `npm run build` to also do deployment, linting
|
|
116
|
+
// and type checking, and running those again is not something our deploy
|
|
117
|
+
// promised to do.
|
|
109
118
|
config.buildCommand = [JSON.stringify(process.execPath), JSON.stringify(nextBin), "build"].join(" ");
|
|
110
119
|
const options = normalizeOptions(config, dirname(awsIndex), buildDir);
|
|
111
120
|
log("Building Next.js…");
|
|
@@ -113,7 +122,14 @@ export async function buildNext(opts) {
|
|
|
113
122
|
...(opts.compatibilityDate !== undefined
|
|
114
123
|
? { compatibility_date: opts.compatibilityDate }
|
|
115
124
|
: {}),
|
|
116
|
-
|
|
125
|
+
// **The worker is first here.** On Cloudflare the platform answers
|
|
126
|
+
// static paths before the worker sees them, and OpenNext's asset
|
|
127
|
+
// resolver reads this flag to decide whether it has to look at ASSETS
|
|
128
|
+
// itself. runlot's socket hands every request to `main`
|
|
129
|
+
// (node/internal/workerd/config.go), so with `false` the resolver
|
|
130
|
+
// returned early and Next answered its own 404 for a file that was
|
|
131
|
+
// sitting right there in the bundle (docs/nextjs.md §8).
|
|
132
|
+
assets: { run_worker_first: true },
|
|
117
133
|
}, false);
|
|
118
134
|
const outputDir = join(dir, ".open-next");
|
|
119
135
|
const worker = join(outputDir, ENTRY_NAME);
|
package/dist/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+BAA+B;AAC/B,EAAE;AACF,gFAAgF;AAChF,8EAA8E;AAC9E,wDAAwD;AACxD,yEAAyE;AACzE,8BAA8B;AAC9B,EAAE;AACF,0EAA0E;AAC1E,YAAY;AACZ,OAAO,EAAE,UAAU,EAAE,SAAS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AO,EACP,MAAM,EACN,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,EAAE,KAAK,EAAE,uBAAuB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,EACrF;YACE,GAAG,CAAC,IAAI,CAAC,iBAAiB,KAAK,SAAS;gBACtC,CAAC,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,iBAAiB,EAAE;gBAChD,CAAC,CAAC,EAAE,CAAC;YACP,mEAAmE;YACnE,iEAAiE;YACjE,sEAAsE;YACtE,wDAAwD;YACxD,kEAAkE;YAClE,mEAAmE;YACnE,yDAAyD;YACzD,MAAM,EAAE,EAAE,gBAAgB,EAAE,IAAI,EAAE;SACnC,EACD,KAAK,CACN,CAAC;QAEF,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;QAC1C,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,kBAAkB,SAAS,kDAAkD,CAAC,CAAC;QACjG,CAAC;QACD,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QACpC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC;IAClE,CAAC;YAAS,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC"}
|
package/dist/entry.d.ts
CHANGED
|
@@ -5,9 +5,10 @@ export interface FetchHandler {
|
|
|
5
5
|
fetch(request: Request, env: RunlotEnv, ctx: RunlotContext): Response | Promise<Response>;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* OpenNext
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Wraps OpenNext's worker. The exports other than `fetch` (Durable Object
|
|
9
|
+
* classes and so on) are re-exported as they are by the generated
|
|
10
|
+
* `runlot-entry.js`, not by this function — because the only thing that needs
|
|
11
|
+
* wrapping is the request path.
|
|
11
12
|
*/
|
|
12
13
|
export declare function wrap(handler: FetchHandler): FetchHandler;
|
|
13
14
|
//# sourceMappingURL=entry.d.ts.map
|
package/dist/entry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entry.d.ts","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAaA,OAAO,EAAO,KAAK,aAAa,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAExF,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,aAAa,GAAG,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3F;AAED;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CAMxD"}
|
package/dist/entry.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
|
-
//
|
|
1
|
+
// The entry wrapper (docs/nextjs.md §4).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
3
|
+
// The build emits `.open-next/runlot-entry.js`, and that file wraps the default
|
|
4
|
+
// export of OpenNext's `worker.js` with this:
|
|
5
5
|
//
|
|
6
6
|
// import worker from "./worker.js";
|
|
7
7
|
// import { wrap } from "@runlot/next/entry";
|
|
8
8
|
// export default wrap(worker);
|
|
9
9
|
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
10
|
+
// It does one thing — it puts one request's `(request, env, ctx)` into the
|
|
11
|
+
// store and calls OpenNext's fetch inside it. That is what lets
|
|
12
|
+
// `env.auth.user()` inside a server component find its own request without an
|
|
13
|
+
// argument.
|
|
13
14
|
import { als } from "./store.js";
|
|
14
15
|
export { als } from "./store.js";
|
|
15
16
|
/**
|
|
16
|
-
* OpenNext
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* Wraps OpenNext's worker. The exports other than `fetch` (Durable Object
|
|
18
|
+
* classes and so on) are re-exported as they are by the generated
|
|
19
|
+
* `runlot-entry.js`, not by this function — because the only thing that needs
|
|
20
|
+
* wrapping is the request path.
|
|
19
21
|
*/
|
|
20
22
|
export function wrap(handler) {
|
|
21
23
|
return {
|
package/dist/entry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../src/entry.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,gFAAgF;AAChF,8CAA8C;AAC9C,EAAE;AACF,sCAAsC;AACtC,+CAA+C;AAC/C,iCAAiC;AACjC,EAAE;AACF,2EAA2E;AAC3E,gEAAgE;AAChE,8EAA8E;AAC9E,YAAY;AACZ,OAAO,EAAE,GAAG,EAAsC,MAAM,YAAY,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAOjC;;;;;GAKG;AACH,MAAM,UAAU,IAAI,CAAC,OAAqB;IACxC,OAAO;QACL,KAAK,CAAC,OAAgB,EAAE,GAAc,EAAE,GAAkB;YACxD,OAAO,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;QAChF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,21 +4,26 @@ export type { RunlotAuth, RunlotBindings, RunlotContext, RunlotEnv, RunlotStore,
|
|
|
4
4
|
export type { User, SignOutHeaders } from "@runlot/auth";
|
|
5
5
|
export type { Db, DbSession, Storage, StorageObject } from "@runlot/pg";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* The bindings of this request.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* The name is the single `env`, but at every moment of reading it belongs to
|
|
10
|
+
* that request. Reading it outside a request throws an `Error`
|
|
11
|
+
* (`OUTSIDE_REQUEST`).
|
|
11
12
|
*/
|
|
12
13
|
export declare const env: RunlotEnv;
|
|
13
|
-
/**
|
|
14
|
+
/** The `Request` of this request. For when you need to look at the headers or
|
|
15
|
+
* the URL directly. */
|
|
14
16
|
export declare function request(): Request;
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
18
|
+
* Work that runs to the end even after the response has been sent. Shipping
|
|
19
|
+
* logs and filling a cache are those places.
|
|
17
20
|
*
|
|
18
|
-
* `ctx.waitUntil`
|
|
19
|
-
*
|
|
21
|
+
* In a deployment with no `ctx.waitUntil` (a fake context for tests, say) it
|
|
22
|
+
* does nothing and hands the promise back — it swallows the rejection so a
|
|
23
|
+
* floating one does not kill the process.
|
|
20
24
|
*/
|
|
21
25
|
export declare function waitUntil(promise: Promise<unknown>): void;
|
|
22
|
-
/**
|
|
26
|
+
/** Are we inside a request right now? Only for a library that needs to branch
|
|
27
|
+
* — app code just reads `env`. */
|
|
23
28
|
export declare function inRequest(): boolean;
|
|
24
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAA+B,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAClD,YAAY,EACV,UAAU,EACV,cAAc,EACd,aAAa,EACb,SAAS,EACT,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACzD,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA6BxE;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,EAAE,SAgChB,CAAC;AAEH;wBACwB;AACxB,wBAAgB,OAAO,IAAI,OAAO,CAEjC;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAOzD;AAED;mCACmC;AACnC,wBAAgB,SAAS,IAAI,OAAO,CAEnC"}
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
// `runlot/next` — Next.js
|
|
1
|
+
// `runlot/next` — the bindings as seen from inside Next.js (docs/nextjs.md §4).
|
|
2
2
|
//
|
|
3
3
|
// import { env } from "runlot/next";
|
|
4
|
-
// const user = await env.auth.user(); //
|
|
4
|
+
// const user = await env.auth.user(); // the adapter hides the request
|
|
5
5
|
// const rows = await env.db.exec("select 1");
|
|
6
6
|
//
|
|
7
|
-
// `env`
|
|
8
|
-
//
|
|
9
|
-
//
|
|
7
|
+
// `env` is a Proxy, not a value. That is the only way to call a bundle that
|
|
8
|
+
// differs per request by one module-level name, and it is why **reading it
|
|
9
|
+
// outside a request throws** — module top level and build-time static rendering
|
|
10
|
+
// are those places.
|
|
10
11
|
//
|
|
11
|
-
//
|
|
12
|
+
// Package name: `@runlot/next` inside the workspace, `runlot/next` on npm.
|
|
12
13
|
import { als, store } from "./store.js";
|
|
13
14
|
export { als, OUTSIDE_REQUEST } from "./store.js";
|
|
14
15
|
/**
|
|
15
|
-
* `env.auth
|
|
16
|
-
*
|
|
16
|
+
* One layer over `env.auth`. When `user()` or `signOut()` is called without an
|
|
17
|
+
* argument it puts in the request from the store, and everything else
|
|
18
|
+
* (`users`, `sessions`, the flat aliases) is passed straight through.
|
|
17
19
|
*/
|
|
18
20
|
function wrapAuth(auth, request) {
|
|
19
21
|
return new Proxy(auth, {
|
|
@@ -21,29 +23,39 @@ function wrapAuth(auth, request) {
|
|
|
21
23
|
const value = Reflect.get(target, prop, receiver);
|
|
22
24
|
if (typeof value !== "function")
|
|
23
25
|
return value;
|
|
26
|
+
// **`target` is a workerd RPC stub, not an object.** Reading `.call` or
|
|
27
|
+
// `.bind` off one of its methods does not reach Function.prototype — it
|
|
28
|
+
// asks the *remote* side for a method by that name, and the answer is
|
|
29
|
+
// `TypeError: The RPC receiver does not implement the method "call"`.
|
|
30
|
+
// Measured on dev, not in tests: the unit tests pass a plain object, and
|
|
31
|
+
// on a plain object both work (docs/nextjs.md §9). Go through the
|
|
32
|
+
// property on every invocation instead, which is right for both.
|
|
33
|
+
const invoke = (...args) => target[prop](...args);
|
|
24
34
|
if (prop === "user" || prop === "signOut") {
|
|
25
|
-
return (given) =>
|
|
35
|
+
return (given) => invoke(given ?? request);
|
|
26
36
|
}
|
|
27
|
-
return
|
|
37
|
+
return invoke;
|
|
28
38
|
},
|
|
29
39
|
});
|
|
30
40
|
}
|
|
31
41
|
/**
|
|
32
|
-
*
|
|
42
|
+
* The bindings of this request.
|
|
33
43
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
44
|
+
* The name is the single `env`, but at every moment of reading it belongs to
|
|
45
|
+
* that request. Reading it outside a request throws an `Error`
|
|
46
|
+
* (`OUTSIDE_REQUEST`).
|
|
36
47
|
*/
|
|
37
48
|
export const env = new Proxy({}, {
|
|
38
49
|
get(_target, prop) {
|
|
39
50
|
const s = store();
|
|
40
51
|
if (prop === "auth") {
|
|
41
52
|
const auth = s.env["auth"];
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
53
|
+
// For a project with no binding (before `"auth": true` is declared) it
|
|
54
|
+
// is undefined. Wrapping it would raise a "user is not a function"
|
|
55
|
+
// TypeError from inside our proxy, so instead we say right here what is
|
|
56
|
+
// missing.
|
|
45
57
|
if (auth === undefined || auth === null) {
|
|
46
|
-
throw new Error('env.auth
|
|
58
|
+
throw new Error('There is no env.auth binding. Add "auth": true to runlot.json and deploy again.');
|
|
47
59
|
}
|
|
48
60
|
return wrapAuth(auth, s.request);
|
|
49
61
|
}
|
|
@@ -57,23 +69,27 @@ export const env = new Proxy({}, {
|
|
|
57
69
|
},
|
|
58
70
|
getOwnPropertyDescriptor(_target, prop) {
|
|
59
71
|
const d = Reflect.getOwnPropertyDescriptor(store().env, prop);
|
|
60
|
-
//
|
|
61
|
-
//
|
|
72
|
+
// The target is an empty object. Returning `configurable: false` as it is
|
|
73
|
+
// violates a proxy invariant and makes `Object.keys(env)` throw a
|
|
74
|
+
// TypeError.
|
|
62
75
|
return d === undefined ? undefined : { ...d, configurable: true };
|
|
63
76
|
},
|
|
64
77
|
set() {
|
|
65
|
-
throw new Error("env
|
|
78
|
+
throw new Error("env is read-only. To change a value, change a secret or a binding.");
|
|
66
79
|
},
|
|
67
80
|
});
|
|
68
|
-
/**
|
|
81
|
+
/** The `Request` of this request. For when you need to look at the headers or
|
|
82
|
+
* the URL directly. */
|
|
69
83
|
export function request() {
|
|
70
84
|
return store().request;
|
|
71
85
|
}
|
|
72
86
|
/**
|
|
73
|
-
*
|
|
87
|
+
* Work that runs to the end even after the response has been sent. Shipping
|
|
88
|
+
* logs and filling a cache are those places.
|
|
74
89
|
*
|
|
75
|
-
* `ctx.waitUntil`
|
|
76
|
-
*
|
|
90
|
+
* In a deployment with no `ctx.waitUntil` (a fake context for tests, say) it
|
|
91
|
+
* does nothing and hands the promise back — it swallows the rejection so a
|
|
92
|
+
* floating one does not kill the process.
|
|
77
93
|
*/
|
|
78
94
|
export function waitUntil(promise) {
|
|
79
95
|
const { ctx } = store();
|
|
@@ -83,7 +99,8 @@ export function waitUntil(promise) {
|
|
|
83
99
|
}
|
|
84
100
|
void promise.catch(() => { });
|
|
85
101
|
}
|
|
86
|
-
/**
|
|
102
|
+
/** Are we inside a request right now? Only for a library that needs to branch
|
|
103
|
+
* — app code just reads `env`. */
|
|
87
104
|
export function inRequest() {
|
|
88
105
|
return als.getStore() !== undefined;
|
|
89
106
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,EAAE;AACF,uCAAuC;AACvC,kFAAkF;AAClF,gDAAgD;AAChD,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,gFAAgF;AAChF,oBAAoB;AACpB,EAAE;AACF,2EAA2E;AAC3E,OAAO,EAAE,GAAG,EAAE,KAAK,EAAmC,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAWlD;;;;GAIG;AACH,SAAS,QAAQ,CAAC,IAAY,EAAE,OAAgB;IAC9C,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;QACrB,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC3D,IAAI,OAAO,KAAK,KAAK,UAAU;gBAAE,OAAO,KAAK,CAAC;YAC9C,wEAAwE;YACxE,wEAAwE;YACxE,sEAAsE;YACtE,sEAAsE;YACtE,yEAAyE;YACzE,kEAAkE;YAClE,iEA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QACpC,MAAM,CAAC,GAAG,OAAO,CAAC,wBAAwB,CAAC,KAAK,EAAE,CAAC,GAAa,EAAE,IAAI,CAAC,CAAC;QACxE,0EAA0E;QAC1E,kEAAkE;QAClE,aAAa;QACb,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACpE,CAAC;IACD,GAAG;QACD,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IACxF,CAAC;CACF,CAAC,CAAC;AAEH;wBACwB;AACxB,MAAM,UAAU,OAAO;IACrB,OAAO,KAAK,EAAE,CAAC,OAAO,CAAC;AACzB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,OAAyB;IACjD,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IACxB,IAAI,OAAO,GAAG,EAAE,SAAS,KAAK,UAAU,EAAE,CAAC;QACzC,GAAG,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACvB,OAAO;IACT,CAAC;IACD,KAAK,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;mCACmC;AACnC,MAAM,UAAU,SAAS;IACvB,OAAO,GAAG,CAAC,QAAQ,EAAE,KAAK,SAAS,CAAC;AACtC,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** The env of this request. When it is in no store, an empty bundle — the
|
|
2
|
+
* caller reads that as having no bindings. */
|
|
2
3
|
export declare function bindings(): Record<string, unknown>;
|
|
3
|
-
/**
|
|
4
|
+
/** The build id OpenNext plants. When the deployment changes, the cache keys
|
|
5
|
+
* are separated. */
|
|
4
6
|
export declare function buildId(): string;
|
|
5
|
-
/**
|
|
7
|
+
/** A notice printed only once per deployment. It does not pile up the same
|
|
8
|
+
* line on every request. */
|
|
6
9
|
export declare function sayOnce(key: string, line: string): void;
|
|
7
10
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/opennext/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/opennext/context.ts"],"names":[],"mappings":"AAoBA;+CAC+C;AAC/C,wBAAgB,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAElD;AAED;qBACqB;AACrB,wBAAgB,OAAO,IAAI,MAAM,CAKhC;AAID;6BAC6B;AAC7B,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAIvD"}
|
package/dist/opennext/context.js
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
//
|
|
1
|
+
// Where a cache override finds the bindings.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// (`Symbol.for("__cloudflare-context__")`)
|
|
3
|
+
// It reads OpenNext's own request context
|
|
4
|
+
// (`Symbol.for("__cloudflare-context__")`), not our store (`../store.js`).
|
|
5
|
+
// There are two reasons:
|
|
5
6
|
//
|
|
6
|
-
// 1.
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
7
|
+
// 1. The overrides also go into the middleware bundle. That bundle is built
|
|
8
|
+
// with esbuild's `browser` platform and its only external is
|
|
9
|
+
// `node:crypto`, so importing our store — which drags in
|
|
10
|
+
// `node:async_hooks` — **breaks the build** (not measured — read off the
|
|
11
|
+
// external list in compileOpenNextConfigEdge).
|
|
12
|
+
// 2. A cache override always runs inside OpenNext's request context. Our
|
|
13
|
+
// bindings are in that context as they are — it is the same `env`.
|
|
12
14
|
const CF_CONTEXT = Symbol.for("__cloudflare-context__");
|
|
13
|
-
/**
|
|
15
|
+
/** The env of this request. When it is in no store, an empty bundle — the
|
|
16
|
+
* caller reads that as having no bindings. */
|
|
14
17
|
export function bindings() {
|
|
15
18
|
return globalThis[CF_CONTEXT]?.env ?? {};
|
|
16
19
|
}
|
|
17
|
-
/**
|
|
20
|
+
/** The build id OpenNext plants. When the deployment changes, the cache keys
|
|
21
|
+
* are separated. */
|
|
18
22
|
export function buildId() {
|
|
19
23
|
const id = globalThis.process?.env?.["OPEN_NEXT_BUILD_ID"];
|
|
20
24
|
return typeof id === "string" && id !== "" ? id : "no-build-id";
|
|
21
25
|
}
|
|
22
26
|
const said = new Set();
|
|
23
|
-
/**
|
|
27
|
+
/** A notice printed only once per deployment. It does not pile up the same
|
|
28
|
+
* line on every request. */
|
|
24
29
|
export function sayOnce(key, line) {
|
|
25
30
|
if (said.has(key))
|
|
26
31
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/opennext/context.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/opennext/context.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,EAAE;AACF,0CAA0C;AAC1C,2EAA2E;AAC3E,yBAAyB;AACzB,EAAE;AACF,8EAA8E;AAC9E,kEAAkE;AAClE,8DAA8D;AAC9D,8EAA8E;AAC9E,oDAAoD;AACpD,2EAA2E;AAC3E,wEAAwE;AAExE,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAMxD;+CAC+C;AAC/C,MAAM,UAAU,QAAQ;IACtB,OAAQ,UAAqB,CAAC,UAAU,CAAC,EAAE,GAAG,IAAI,EAAE,CAAC;AACvD,CAAC;AAED;qBACqB;AACrB,MAAM,UAAU,OAAO;IACrB,MAAM,EAAE,GAAa,UAAyE,CAAC,OAAO,EAAE,GAAG,EAAE,CAC3G,oBAAoB,CACrB,CAAC;IACF,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;AAClE,CAAC;AAED,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;AAE/B;6BAC6B;AAC7B,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,IAAY;IAC/C,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO;IAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CacheEntryType, CacheValue, IncrementalCache, WithLastModified } from "@opennextjs/aws/types/overrides";
|
|
2
2
|
export declare const NAME = "runlot-storage";
|
|
3
|
-
/** `__next/cache/<buildId>/<key>.<type>`.
|
|
3
|
+
/** `__next/cache/<buildId>/<key>.<type>`. A leading `/` and any doubled `/`
|
|
4
|
+
* are erased. */
|
|
4
5
|
export declare function cacheKey(key: string, cacheType?: CacheEntryType, id?: string): string;
|
|
5
6
|
declare class RunlotStorageIncrementalCache implements IncrementalCache {
|
|
6
7
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incremental-cache.d.ts","sourceRoot":"","sources":["../../src/opennext/incremental-cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"incremental-cache.d.ts","sourceRoot":"","sources":["../../src/opennext/incremental-cache.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,iCAAiC,CAAC;AAGzC,eAAO,MAAM,IAAI,mBAAmB,CAAC;AAMrC;kBACkB;AAClB,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,cAAwB,EAAE,EAAE,SAAY,GAAG,MAAM,CAEjG;AAOD,cAAM,6BAA8B,YAAW,gBAAgB;IAC7D,IAAI,SAAQ;IAEN,GAAG,CAAC,SAAS,SAAS,cAAc,GAAG,OAAO,EAClD,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC;IAsBpD,GAAG,CAAC,SAAS,SAAS,cAAc,GAAG,OAAO,EAClD,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,EAC5B,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,IAAI,CAAC;IAWV,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKzC;;AAED,wBAAmD"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
// ISR
|
|
1
|
+
// The ISR cache — on top of `env.storage` (the first row of the table in
|
|
2
|
+
// docs/nextjs.md §2).
|
|
2
3
|
//
|
|
3
|
-
// OpenNext
|
|
4
|
-
//
|
|
5
|
-
//
|
|
4
|
+
// OpenNext's default (the static asset cache) is **read-only**, so revalidation
|
|
5
|
+
// does not work: it hands back the pages baked at build time but has nowhere to
|
|
6
|
+
// write the new page after a `revalidatePath`. The only place we can write is
|
|
7
|
+
// object storage.
|
|
6
8
|
//
|
|
7
|
-
// `env.storage`
|
|
8
|
-
//
|
|
9
|
+
// Without `env.storage` (that is, before `"storage": true` is declared) it falls
|
|
10
|
+
// back to the static asset cache and says one line. Why it does not throw: the
|
|
11
|
+
// page has to come up even without ISR.
|
|
9
12
|
import staticAssetsCache from "@opennextjs/cloudflare/overrides/incremental-cache/static-assets-incremental-cache";
|
|
10
13
|
import { bindings, buildId, sayOnce } from "./context.js";
|
|
11
14
|
export const NAME = "runlot-storage";
|
|
12
|
-
const NO_STORAGE = '
|
|
13
|
-
"
|
|
14
|
-
/** `__next/cache/<buildId>/<key>.<type>`.
|
|
15
|
+
const NO_STORAGE = 'There is no storage to keep the ISR cache in. Set "storage": true in runlot.json and deploy again ' +
|
|
16
|
+
"to be able to use cache revalidation. Until then, only the pages generated at build time are returned.";
|
|
17
|
+
/** `__next/cache/<buildId>/<key>.<type>`. A leading `/` and any doubled `/`
|
|
18
|
+
* are erased. */
|
|
15
19
|
export function cacheKey(key, cacheType = "cache", id = buildId()) {
|
|
16
20
|
return `__next/cache/${id}/${key}.${cacheType}`.replace(/\/+/g, "/").replace(/^\//, "");
|
|
17
21
|
}
|
|
@@ -32,13 +36,15 @@ class RunlotStorageIncrementalCache {
|
|
|
32
36
|
return null;
|
|
33
37
|
try {
|
|
34
38
|
const value = (await new Response(object.body).json());
|
|
35
|
-
// `lastModified`
|
|
36
|
-
//
|
|
39
|
+
// `lastModified` is RFC 1123. When it cannot be read it has to be read
|
|
40
|
+
// as "written just now", not as 0 — at 0 every entry becomes stale in the
|
|
41
|
+
// tag check.
|
|
37
42
|
const at = Date.parse(object.lastModified);
|
|
38
43
|
return { value, lastModified: Number.isNaN(at) ? Date.now() : at };
|
|
39
44
|
}
|
|
40
45
|
catch {
|
|
41
|
-
//
|
|
46
|
+
// A half-written entry. Read it as a cache miss and let the next render
|
|
47
|
+
// overwrite it.
|
|
42
48
|
return null;
|
|
43
49
|
}
|
|
44
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"incremental-cache.js","sourceRoot":"","sources":["../../src/opennext/incremental-cache.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"incremental-cache.js","sourceRoot":"","sources":["../../src/opennext/incremental-cache.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,sBAAsB;AACtB,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,kBAAkB;AAClB,EAAE;AACF,iFAAiF;AACjF,+EAA+E;AAC/E,wCAAwC;AACxC,OAAO,iBAAiB,MAAM,oFAAoF,CAAC;AAQnH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc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MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC3C,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACrE,CAAC;QAAC,MAAM,CAAC;YACP,wEAAwE;YACxE,gBAAgB;YAChB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CACP,GAAW,EACX,KAA4B,EAC5B,SAAqB;QAErB,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YACjE,WAAW,EAAE,kBAAkB;SAChC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACtC,CAAC;CACF;AAED,eAAe,IAAI,6BAA6B,EAAE,CAAC"}
|
|
@@ -2,7 +2,7 @@ import type { OriginalTagCache, OriginalTagCacheWriteInput } from "@opennextjs/a
|
|
|
2
2
|
export declare const NAME = "runlot-db";
|
|
3
3
|
export declare const SCHEMA = "runlot_next";
|
|
4
4
|
export declare const TABLE = "runlot_next.tags";
|
|
5
|
-
/**
|
|
5
|
+
/** For when a test imitates opening a fresh isolate. */
|
|
6
6
|
export declare function resetBootstrap(): void;
|
|
7
7
|
declare class RunlotDbTagCache implements OriginalTagCache {
|
|
8
8
|
#private;
|
|
@@ -11,8 +11,8 @@ declare class RunlotDbTagCache implements OriginalTagCache {
|
|
|
11
11
|
getByTag(tag: string): Promise<string[]>;
|
|
12
12
|
getByPath(path: string): Promise<string[]>;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
* `-1`
|
|
14
|
+
* `-1` when any tag of this path was invalidated after `lastModified`.
|
|
15
|
+
* To the adapter, `-1` means "throw this entry away".
|
|
16
16
|
*/
|
|
17
17
|
getLastModified(path: string, lastModified?: number): Promise<number>;
|
|
18
18
|
writeTags(tags: OriginalTagCacheWriteInput[]): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag-cache.d.ts","sourceRoot":"","sources":["../../src/opennext/tag-cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tag-cache.d.ts","sourceRoot":"","sources":["../../src/opennext/tag-cache.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAGpG,eAAO,MAAM,IAAI,cAAc,CAAC;AAChC,eAAO,MAAM,MAAM,gBAAgB,CAAC;AACpC,eAAO,MAAM,KAAK,qBAAqB,CAAC;AAsCxC,wDAAwD;AACxD,wBAAgB,cAAc,IAAI,IAAI,CAErC;AAiBD,cAAM,gBAAiB,YAAW,gBAAgB;;IAChD,IAAI,EAAG,UAAU,CAAU;IAC3B,IAAI,SAAQ;IA8BN,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOxC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAOhD;;;OAGG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAWrE,SAAS,CAAC,IAAI,EAAE,0BAA0B,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAgBnE;;AAED,wBAAsC"}
|
|
@@ -2,8 +2,8 @@ import { bindings, buildId, sayOnce } from "./context.js";
|
|
|
2
2
|
export const NAME = "runlot-db";
|
|
3
3
|
export const SCHEMA = "runlot_next";
|
|
4
4
|
export const TABLE = "runlot_next.tags";
|
|
5
|
-
const NO_DB = '
|
|
6
|
-
"
|
|
5
|
+
const NO_DB = 'The database the tag cache needs is not available. Set "database": true in runlot.json and deploy again ' +
|
|
6
|
+
"to be able to use revalidateTag. Until the database is available, calling revalidateTag does not invalidate the cache.";
|
|
7
7
|
const BOOTSTRAP = [
|
|
8
8
|
`create schema if not exists ${SCHEMA}`,
|
|
9
9
|
`create table if not exists ${TABLE} (
|
|
@@ -18,12 +18,13 @@ function dbOf() {
|
|
|
18
18
|
const db = bindings()["db"];
|
|
19
19
|
return db === undefined || db === null ? undefined : db;
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
21
|
+
/** Once per isolate. On failure the next call tries again — we do not leave a
|
|
22
|
+
* cached rejection behind. */
|
|
22
23
|
let ready;
|
|
23
24
|
async function ensure(db) {
|
|
24
25
|
ready ??= (async () => {
|
|
25
|
-
//
|
|
26
|
-
//
|
|
26
|
+
// Send the statements one at a time. `exec` is an extended query, so it
|
|
27
|
+
// does not take several statements joined by semicolons at once.
|
|
27
28
|
for (const sql of BOOTSTRAP)
|
|
28
29
|
await db.exec(sql);
|
|
29
30
|
})().catch((err) => {
|
|
@@ -32,14 +33,15 @@ async function ensure(db) {
|
|
|
32
33
|
});
|
|
33
34
|
return ready;
|
|
34
35
|
}
|
|
35
|
-
/**
|
|
36
|
+
/** For when a test imitates opening a fresh isolate. */
|
|
36
37
|
export function resetBootstrap() {
|
|
37
38
|
ready = undefined;
|
|
38
39
|
}
|
|
39
40
|
function rowsOf(value) {
|
|
40
41
|
return Array.isArray(value) ? value : [];
|
|
41
42
|
}
|
|
42
|
-
/** bigint
|
|
43
|
+
/** Depending on the driver, a bigint arrives as a string. Read it as a
|
|
44
|
+
* number. */
|
|
43
45
|
function num(value) {
|
|
44
46
|
if (typeof value === "number")
|
|
45
47
|
return value;
|
|
@@ -52,7 +54,8 @@ function num(value) {
|
|
|
52
54
|
class RunlotDbTagCache {
|
|
53
55
|
mode = "original";
|
|
54
56
|
name = NAME;
|
|
55
|
-
/**
|
|
57
|
+
/** Keeps the tag names separated per deployment. An invalidation from an old
|
|
58
|
+
* deployment does not shake a new one. */
|
|
56
59
|
#key(tag) {
|
|
57
60
|
return `${buildId()}/${tag}`.replace(/\/+/g, "/");
|
|
58
61
|
}
|
|
@@ -70,7 +73,8 @@ class RunlotDbTagCache {
|
|
|
70
73
|
await ensure(db);
|
|
71
74
|
}
|
|
72
75
|
catch {
|
|
73
|
-
//
|
|
76
|
+
// Either there is no permission or the DB is not attached yet. Carry on
|
|
77
|
+
// with no tags.
|
|
74
78
|
sayOnce("no-db-bootstrap", NO_DB);
|
|
75
79
|
return undefined;
|
|
76
80
|
}
|
|
@@ -91,8 +95,8 @@ class RunlotDbTagCache {
|
|
|
91
95
|
return rows.map((r) => this.#bare(String(r["tag"])));
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
|
-
*
|
|
95
|
-
* `-1`
|
|
98
|
+
* `-1` when any tag of this path was invalidated after `lastModified`.
|
|
99
|
+
* To the adapter, `-1` means "throw this entry away".
|
|
96
100
|
*/
|
|
97
101
|
async getLastModified(path, lastModified) {
|
|
98
102
|
const at = lastModified ?? Date.now();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag-cache.js","sourceRoot":"","sources":["../../src/opennext/tag-cache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tag-cache.js","sourceRoot":"","sources":["../../src/opennext/tag-cache.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE1D,MAAM,CAAC,MAAM,I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C,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QACjE,OAAO,WAAW,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAkC;QAChD,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC9B,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,EAAE;YAAE,OAAO;QAChB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,MAAM,GAAc,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YAC/B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,aAAa,IAAI,GAAG,CAAC,CAAC;YAC9D,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;QACzD,CAAC,CAAC,CAAC;QACH,MAAM,EAAE,CAAC,IAAI,CACX,eAAe,KAAK,uCAAuC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC7E,gFAAgF,EAClF,MAAM,CACP,CAAC;IACJ,CAAC;CACF;AAED,eAAe,IAAI,gBAAgB,EAAE,CAAC"}
|
package/dist/store.d.ts
CHANGED
|
@@ -2,21 +2,23 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
2
2
|
import type { AuthBinding, SignOutHeaders, User } from "@runlot/auth";
|
|
3
3
|
import type { Db, Storage } from "@runlot/pg";
|
|
4
4
|
/**
|
|
5
|
-
* `env.auth`.
|
|
6
|
-
*
|
|
5
|
+
* `env.auth`. The same as `AuthBinding` in `@runlot/auth`, except that the
|
|
6
|
+
* request argument of `user()` and `signOut()` is optional — without it the
|
|
7
|
+
* adapter puts in the request from the store (docs/nextjs.md §4).
|
|
7
8
|
*/
|
|
8
9
|
export interface RunlotAuth extends Omit<AuthBinding, "user" | "signOut"> {
|
|
9
10
|
user(request?: Request): Promise<User | null>;
|
|
10
11
|
signOut(request?: Request): Promise<SignOutHeaders>;
|
|
11
12
|
}
|
|
12
|
-
/**
|
|
13
|
+
/** The bundle of bindings the worker receives. The unnamed rest are secrets
|
|
14
|
+
* and environment variables (strings). */
|
|
13
15
|
export interface RunlotBindings {
|
|
14
16
|
db: Db;
|
|
15
17
|
auth: RunlotAuth;
|
|
16
18
|
storage: Storage;
|
|
17
19
|
}
|
|
18
20
|
export type RunlotEnv = RunlotBindings & Record<string, string>;
|
|
19
|
-
/** workerd
|
|
21
|
+
/** The part of workerd's `ExecutionContext` that we use. */
|
|
20
22
|
export interface RunlotContext {
|
|
21
23
|
waitUntil(promise: Promise<unknown>): void;
|
|
22
24
|
passThroughOnException?(): void;
|
|
@@ -26,14 +28,15 @@ export interface RunlotStore {
|
|
|
26
28
|
env: RunlotEnv;
|
|
27
29
|
ctx: RunlotContext;
|
|
28
30
|
}
|
|
29
|
-
/**
|
|
31
|
+
/** The request-context store. The entry wrapper puts into it and `env`,
|
|
32
|
+
* `request()` and `waitUntil()` read from it. */
|
|
30
33
|
export declare const als: AsyncLocalStorage<RunlotStore>;
|
|
31
34
|
/**
|
|
32
|
-
*
|
|
35
|
+
* The sentence for being called outside the store.
|
|
33
36
|
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
+
* The reason it does not quietly hand back `null` or `undefined` is the same as
|
|
38
|
+
* docs/auth.md §4 — when "cannot be done" becomes an empty value, every page
|
|
39
|
+
* looks logged out, and the only place that is noticed is after a deploy.
|
|
37
40
|
*/
|
|
38
41
|
export declare const OUTSIDE_REQUEST: string;
|
|
39
42
|
export declare function store(): RunlotStore;
|
package/dist/store.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE9C;;;;GAIG;AACH,MAAM,WAAW,UAAW,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IACvE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IAC9C,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CACrD;AAED;2CAC2C;AAC3C,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,EAAE,CAAC;IACP,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEhE,4DAA4D;AAC5D,MAAM,WAAW,aAAa;IAC5B,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC3C,sBAAsB,CAAC,IAAI,IAAI,CAAC;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,SAAS,CAAC;IACf,GAAG,EAAE,aAAa,CAAC;CACpB;AAUD;kDACkD;AAClD,eAAO,MAAM,GAAG,EAAE,iBAAiB,CAAC,WAAW,CAAuD,CAAC;AAEvG;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,QAIwE,CAAC;AAErG,wBAAgB,KAAK,IAAI,WAAW,CAInC"}
|
package/dist/store.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
//
|
|
1
|
+
// The request-context store (docs/nextjs.md §4).
|
|
2
2
|
//
|
|
3
|
-
// `
|
|
4
|
-
// Next
|
|
5
|
-
// `page.tsx`
|
|
6
|
-
//
|
|
3
|
+
// The `env` of `runlot/next` reads the `(request, env, ctx)` the worker entry
|
|
4
|
+
// point received. A Next server component has no place to pass those three down
|
|
5
|
+
// as arguments — `page.tsx` only receives `props` — so the entry wrapper puts
|
|
6
|
+
// them into an AsyncLocalStorage and this module takes them back out.
|
|
7
7
|
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
8
|
+
// **The store is one symbol on `globalThis`.** Because there is no guarantee of
|
|
9
|
+
// a single module instance: the `worker.js` OpenNext emits is an already-bundled
|
|
10
|
+
// bundle that contains a copy of this package inside it, and bundling the
|
|
11
|
+
// `runlot-entry.js` we stand up beside it makes one more copy. Keep the store in
|
|
12
|
+
// a module-local variable and the page cannot see the value the wrapper put in —
|
|
13
|
+
// it quietly becomes "there is no request". OpenNext itself uses
|
|
14
|
+
// `Symbol.for("__cloudflare-context__")` for the same reason.
|
|
14
15
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
15
16
|
const STORE = Symbol.for("runlot.next.store");
|
|
16
17
|
const g = globalThis;
|
|
17
|
-
/**
|
|
18
|
+
/** The request-context store. The entry wrapper puts into it and `env`,
|
|
19
|
+
* `request()` and `waitUntil()` read from it. */
|
|
18
20
|
export const als = (g[STORE] ??= new AsyncLocalStorage());
|
|
19
21
|
/**
|
|
20
|
-
*
|
|
22
|
+
* The sentence for being called outside the store.
|
|
21
23
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* The reason it does not quietly hand back `null` or `undefined` is the same as
|
|
25
|
+
* docs/auth.md §4 — when "cannot be done" becomes an empty value, every page
|
|
26
|
+
* looks logged out, and the only place that is noticed is after a deploy.
|
|
25
27
|
*/
|
|
26
|
-
export const OUTSIDE_REQUEST = "runlot/next
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"`next dev
|
|
28
|
+
export const OUTSIDE_REQUEST = "The `env` of runlot/next can only be read inside a request. " +
|
|
29
|
+
"There is no request at module top level or in a build-time static render — " +
|
|
30
|
+
"move it inside a server component, a route handler or middleware. " +
|
|
31
|
+
"Runlot bindings are not available under `next dev`. Deploy with `runlot deploy` and check there.";
|
|
30
32
|
export function store() {
|
|
31
33
|
const s = als.getStore();
|
|
32
34
|
if (!s)
|
package/dist/store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,EAAE;AACF,8EAA8E;AAC9E,gFAAgF;AAChF,8EAA8E;AAC9E,sEAAsE;AACtE,EAAE;AACF,gFAAgF;AAChF,iFAAiF;AACjF,0EAA0E;AAC1E,iFAAiF;AACjF,iFAAiF;AACjF,iEAAiE;AACjE,8DAA8D;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAoCrD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAM9C,MAAM,CAAC,GAAG,UAAoB,CAAC;AAE/B;kDACkD;AAClD,MAAM,CAAC,MAAM,GAAG,GAAmC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,iBAAiB,EAAe,CAAC,CAAC;AAEvG;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAC1B,8DAA8D;IAC9D,6EAA6E;IAC7E,oEAAoE;IACpE,kGAAkG,CAAC;AAErG,MAAM,UAAU,KAAK;IACnB,MAAM,CAAC,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IACzB,IAAI,CAAC,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;IACzC,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runlot/next",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.75",
|
|
4
4
|
"description": "Next.js adapter for Runlot — request-scoped env plus the OpenNext build",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@opennextjs/aws": "4.1.4",
|
|
44
44
|
"@opennextjs/cloudflare": "^1.20.6",
|
|
45
|
-
"@runlot/auth": "0.1.0-rc.
|
|
46
|
-
"@runlot/pg": "0.1.0-rc.
|
|
45
|
+
"@runlot/auth": "0.1.0-rc.75",
|
|
46
|
+
"@runlot/pg": "0.1.0-rc.75"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^22.10.2",
|
|
50
50
|
"esbuild": "^0.24.2",
|
|
51
51
|
"typescript": "^5.7.2",
|
|
52
|
-
"@runlot/config": "0.1.0-rc.
|
|
52
|
+
"@runlot/config": "0.1.0-rc.75"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "tsc -p tsconfig.build.json",
|