@gadicc/loom 1.20.0 → 1.21.1
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/db/databaseUrl.d.ts +26 -0
- package/db/databaseUrl.js +27 -0
- package/db/databaseUrl.test.ts +72 -0
- package/db/neonFull.js +4 -7
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +210 -6
- package/esm/src/next/jobs/run.d.ts +7 -0
- package/esm/src/next/jobs/run.d.ts.map +1 -1
- package/esm/src/next/jobs/run.js +48 -29
- package/esm/src/next/jobs/runRequest.d.ts +19 -0
- package/esm/src/next/jobs/runRequest.d.ts.map +1 -0
- package/esm/src/next/jobs/runRequest.js +76 -0
- package/package.json +8 -2
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +209 -5
- package/script/src/next/jobs/run.d.ts +7 -0
- package/script/src/next/jobs/run.d.ts.map +1 -1
- package/script/src/next/jobs/run.js +51 -29
- package/script/src/next/jobs/runRequest.d.ts +19 -0
- package/script/src/next/jobs/runRequest.d.ts.map +1 -0
- package/script/src/next/jobs/runRequest.js +81 -0
- package/skills/loom-jobs/SKILL.md +28 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const RUNTIME_DATABASE_URL_ENV_NAMES: readonly [
|
|
2
|
+
"DATABASE_URL_DIRECT",
|
|
3
|
+
"DATABASE_URL_UNPOOLED",
|
|
4
|
+
"POSTGRES_URL_NON_POOLING",
|
|
5
|
+
"DATABASE_URL",
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
export type RuntimeDatabaseUrlEnvName =
|
|
9
|
+
(typeof RUNTIME_DATABASE_URL_ENV_NAMES)[number];
|
|
10
|
+
|
|
11
|
+
export interface RuntimeDatabaseUrl {
|
|
12
|
+
/** Environment variable selected by precedence. */
|
|
13
|
+
envName: RuntimeDatabaseUrlEnvName;
|
|
14
|
+
/** Database connection URL without logging or transformation. */
|
|
15
|
+
url: string;
|
|
16
|
+
/** Whether the selected variable represents a direct/unpooled connection. */
|
|
17
|
+
direct: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Resolves a transaction-capable runtime database URL, preferring explicit and
|
|
22
|
+
* platform-managed direct connections before the pooled application fallback.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveRuntimeDatabaseUrl(
|
|
25
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
26
|
+
): RuntimeDatabaseUrl;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const RUNTIME_DATABASE_URL_ENV_NAMES = [
|
|
2
|
+
"DATABASE_URL_DIRECT",
|
|
3
|
+
"DATABASE_URL_UNPOOLED",
|
|
4
|
+
"POSTGRES_URL_NON_POOLING",
|
|
5
|
+
"DATABASE_URL",
|
|
6
|
+
];
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a transaction-capable runtime database URL, preferring explicit and
|
|
10
|
+
* platform-managed direct connections before the pooled application fallback.
|
|
11
|
+
*/
|
|
12
|
+
export function resolveRuntimeDatabaseUrl(env) {
|
|
13
|
+
const envName = RUNTIME_DATABASE_URL_ENV_NAMES.find((name) =>
|
|
14
|
+
Boolean(env[name]?.trim()) && !/(?:sensitive|redacted)/i.test(env[name])
|
|
15
|
+
);
|
|
16
|
+
if (!envName) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`${RUNTIME_DATABASE_URL_ENV_NAMES.join(" or ")} is not set`,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
envName,
|
|
24
|
+
url: env[envName],
|
|
25
|
+
direct: envName !== "DATABASE_URL",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { expect } from "@std/expect";
|
|
2
|
+
import { describe, it } from "@std/testing/bdd";
|
|
3
|
+
import { resolveRuntimeDatabaseUrl } from "./databaseUrl.js";
|
|
4
|
+
|
|
5
|
+
describe("resolveRuntimeDatabaseUrl", () => {
|
|
6
|
+
it("prefers explicit and integration-managed direct URLs", () => {
|
|
7
|
+
const resolved = resolveRuntimeDatabaseUrl({
|
|
8
|
+
DATABASE_URL_DIRECT: "postgresql://explicit.example/database",
|
|
9
|
+
DATABASE_URL_UNPOOLED: "postgresql://unpooled.example/database",
|
|
10
|
+
POSTGRES_URL_NON_POOLING: "postgresql://non-pooling.example/database",
|
|
11
|
+
DATABASE_URL: "postgresql://pooler.example/database",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
expect(resolved).toEqual({
|
|
15
|
+
envName: "DATABASE_URL_DIRECT",
|
|
16
|
+
url: "postgresql://explicit.example/database",
|
|
17
|
+
direct: true,
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("uses Vercel's integration-managed unpooled URL without an alias", () => {
|
|
22
|
+
const resolved = resolveRuntimeDatabaseUrl({
|
|
23
|
+
DATABASE_URL_UNPOOLED: "postgresql://unpooled.example/database",
|
|
24
|
+
POSTGRES_URL_NON_POOLING: "postgresql://non-pooling.example/database",
|
|
25
|
+
DATABASE_URL: "postgresql://pooler.example/database",
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(resolved.envName).toBe("DATABASE_URL_UNPOOLED");
|
|
29
|
+
expect(resolved.direct).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("supports the legacy Neon non-pooling variable", () => {
|
|
33
|
+
const resolved = resolveRuntimeDatabaseUrl({
|
|
34
|
+
POSTGRES_URL_NON_POOLING: "postgresql://non-pooling.example/database",
|
|
35
|
+
DATABASE_URL: "postgresql://pooler.example/database",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(resolved.envName).toBe("POSTGRES_URL_NON_POOLING");
|
|
39
|
+
expect(resolved.direct).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("keeps DATABASE_URL as the pooled fallback", () => {
|
|
43
|
+
const resolved = resolveRuntimeDatabaseUrl({
|
|
44
|
+
DATABASE_URL: "postgresql://pooler.example/database",
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
expect(resolved).toEqual({
|
|
48
|
+
envName: "DATABASE_URL",
|
|
49
|
+
url: "postgresql://pooler.example/database",
|
|
50
|
+
direct: false,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("skips unreadable sensitive-value sentinels during external builds", () => {
|
|
55
|
+
const resolved = resolveRuntimeDatabaseUrl({
|
|
56
|
+
DATABASE_URL_UNPOOLED: "Vercel Sensitive Value",
|
|
57
|
+
DATABASE_URL: "postgresql://pooler.example/database",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(resolved.envName).toBe("DATABASE_URL");
|
|
61
|
+
expect(resolved.direct).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("rejects empty and missing values", () => {
|
|
65
|
+
expect(() =>
|
|
66
|
+
resolveRuntimeDatabaseUrl({
|
|
67
|
+
DATABASE_URL_DIRECT: " ",
|
|
68
|
+
DATABASE_URL_UNPOOLED: "",
|
|
69
|
+
})
|
|
70
|
+
).toThrow("DATABASE_URL_DIRECT or DATABASE_URL_UNPOOLED");
|
|
71
|
+
});
|
|
72
|
+
});
|
package/db/neonFull.js
CHANGED
|
@@ -2,12 +2,9 @@ import "server-only";
|
|
|
2
2
|
import { drizzle } from "drizzle-orm/postgres-js";
|
|
3
3
|
import postgres from "postgres";
|
|
4
4
|
import process from "node:process";
|
|
5
|
+
import { resolveRuntimeDatabaseUrl } from "./databaseUrl.js";
|
|
5
6
|
|
|
6
|
-
const databaseUrl = process.env
|
|
7
|
-
process.env.DATABASE_URL ?? "";
|
|
8
|
-
if (!databaseUrl) {
|
|
9
|
-
throw new Error("DATABASE_URL is not set");
|
|
10
|
-
}
|
|
7
|
+
const { direct, url: databaseUrl } = resolveRuntimeDatabaseUrl(process.env);
|
|
11
8
|
|
|
12
9
|
const parsedUrl = new URL(databaseUrl);
|
|
13
10
|
const isLocal = parsedUrl.hostname === "db.localtest.me" ||
|
|
@@ -16,9 +13,9 @@ const isLocal = parsedUrl.hostname === "db.localtest.me" ||
|
|
|
16
13
|
const isPooler = parsedUrl.hostname.includes("pooler");
|
|
17
14
|
const ssl = isLocal ? false : "require";
|
|
18
15
|
|
|
19
|
-
if (isPooler && !
|
|
16
|
+
if (isPooler && !direct) {
|
|
20
17
|
console.warn(
|
|
21
|
-
"[db] DATABASE_URL points at a pooler.
|
|
18
|
+
"[db] DATABASE_URL points at a pooler and no direct database URL is available. Prefer DATABASE_URL_UNPOOLED or POSTGRES_URL_NON_POOLING from the platform integration, or set DATABASE_URL_DIRECT explicitly.",
|
|
22
19
|
);
|
|
23
20
|
}
|
|
24
21
|
|
package/esm/src/cli/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/cli/mod.ts"],"names":[],"mappings":"AAuCA,OAAO,EAUL,KAAK,cAAc,EAMpB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAC3C,eAAO,MAAM,eAAe,iBAAiB,CAAC;AAC9C,eAAO,MAAM,oBAAoB,2DACyB,CAAC;AAC3D,eAAO,MAAM,yBAAyB,uCAAuC,CAAC;AAC9E,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAC1E,eAAO,MAAM,8BAA8B,8CACE,CAAC;AAC9C,eAAO,MAAM,4BAA4B,4CACE,CAAC;AAC5C,eAAO,MAAM,+BAA+B,6BAA6B,CAAC;AAC1E,eAAO,MAAM,6BAA6B,2BAA2B,CAAC;AACtE,eAAO,MAAM,kCAAkC,yBAAyB,CAAC;AACzE,eAAO,MAAM,mCAAmC,yBAAyB,CAAC;AAI1E,iFAAiF;AACjF,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAAO,CAAC;AAwCtD,KAAK,a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BAAuB,EAC9B,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,YAoClD;AAu/BD,wBAAsB,aAAa,CACjC,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,IAAI,EAAE,MAAM,EAAE,EACd,EAAE,EAAE,SAAS,EACb,OAAO,GAAE;IACP,aAAa,CAAC,EAAE,aAAa,CAAC;CAC1B,mBAiBP;AA6lBD,wBAAsB,MAAM,CAC1B,IAAI,MAAwB,EAC5B,EAAE,GAAE,SAGH,mBAqKF"}
|
package/esm/src/cli/mod.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { constants as fsConstants } from "node:fs";
|
|
4
4
|
import { access, lstat, mkdir, readdir, readFile, readlink, rm, stat, symlink, unlink, writeFile, } from "node:fs/promises";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
6
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
import { parseArgs } from "node:util";
|
|
9
9
|
import { DEFAULT_API_KEY_AUDIT_RETENTION } from "../apiKeys/retention.js";
|
|
@@ -924,6 +924,7 @@ function getJobsConfig(framework) {
|
|
|
924
924
|
ui: {
|
|
925
925
|
enabled: true,
|
|
926
926
|
listPage: `${appRoot}/admin/jobs/page.tsx`,
|
|
927
|
+
requestMethod: "GET",
|
|
927
928
|
routeHandler: `${appRoot}/admin/jobs/[id]/route.ts`,
|
|
928
929
|
runPage: `${appRoot}/admin/jobs/run/[id]/page.tsx`,
|
|
929
930
|
},
|
|
@@ -3601,6 +3602,168 @@ function matchesImportSource(text, expectedSources) {
|
|
|
3601
3602
|
].map((match) => match[1]);
|
|
3602
3603
|
return expectedSources.some((source) => importSources.includes(source));
|
|
3603
3604
|
}
|
|
3605
|
+
const JOBS_RUN_SOURCE_EXTENSIONS = [
|
|
3606
|
+
".ts",
|
|
3607
|
+
".tsx",
|
|
3608
|
+
".mts",
|
|
3609
|
+
".cts",
|
|
3610
|
+
".js",
|
|
3611
|
+
".jsx",
|
|
3612
|
+
".mjs",
|
|
3613
|
+
".cjs",
|
|
3614
|
+
];
|
|
3615
|
+
const MAX_JOBS_RUN_GRAPH_MODULES = 250;
|
|
3616
|
+
function getModuleBoundaryDirective(text) {
|
|
3617
|
+
let remaining = normalizeText(text).trimStart();
|
|
3618
|
+
while (remaining.startsWith("//") || remaining.startsWith("/*")) {
|
|
3619
|
+
if (remaining.startsWith("//")) {
|
|
3620
|
+
const newline = remaining.indexOf("\n");
|
|
3621
|
+
remaining = newline < 0 ? "" : remaining.slice(newline + 1).trimStart();
|
|
3622
|
+
continue;
|
|
3623
|
+
}
|
|
3624
|
+
const end = remaining.indexOf("*/", 2);
|
|
3625
|
+
if (end < 0)
|
|
3626
|
+
return null;
|
|
3627
|
+
remaining = remaining.slice(end + 2).trimStart();
|
|
3628
|
+
}
|
|
3629
|
+
const match = remaining.match(/^(?:"use (client|server)"|'use (client|server)')\s*;?/);
|
|
3630
|
+
return (match?.[1] ?? match?.[2] ?? null);
|
|
3631
|
+
}
|
|
3632
|
+
function getStaticModuleSpecifiers(text) {
|
|
3633
|
+
const specifiers = new Set();
|
|
3634
|
+
for (const match of normalizeText(text).matchAll(/(?:^|[;\n])\s*(?:import|export)\s+(?:type\s+)?(?:[^"'`;]*?\s+from\s+)?["']([^"']+)["']/gm)) {
|
|
3635
|
+
specifiers.add(match[1]);
|
|
3636
|
+
}
|
|
3637
|
+
for (const match of normalizeText(text).matchAll(/\bimport\s*\(\s*["']([^"']+)["']\s*\)/g)) {
|
|
3638
|
+
specifiers.add(match[1]);
|
|
3639
|
+
}
|
|
3640
|
+
return [...specifiers];
|
|
3641
|
+
}
|
|
3642
|
+
function getJobsRunHelperImports(text) {
|
|
3643
|
+
const helpers = new Set();
|
|
3644
|
+
for (const match of normalizeText(text).matchAll(/import\s+(?:type\s+)?\{([^}]+)\}\s+from\s+["']@gadicc\/loom\/next\/jobs(?:\/run)?["']/g)) {
|
|
3645
|
+
for (const rawSpecifier of match[1].split(",")) {
|
|
3646
|
+
const importedName = rawSpecifier.trim().replace(/^type\s+/, "")
|
|
3647
|
+
.split(/\s+as\s+/)[0];
|
|
3648
|
+
if (importedName === "createJobsRunPage" || importedName === "JobsRunPanel") {
|
|
3649
|
+
helpers.add(importedName);
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
return helpers;
|
|
3654
|
+
}
|
|
3655
|
+
function getJobsRunRequestMethods(text) {
|
|
3656
|
+
return [
|
|
3657
|
+
...normalizeText(text).matchAll(/\brequestMethod\s*(?::|=)\s*["'](GET|POST)["']/g),
|
|
3658
|
+
].map((match) => match[1]);
|
|
3659
|
+
}
|
|
3660
|
+
async function resolveLocalSourceImport(cwd, framework, importerPath, specifier) {
|
|
3661
|
+
let basePath;
|
|
3662
|
+
if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
3663
|
+
basePath = resolve(dirname(importerPath), specifier);
|
|
3664
|
+
}
|
|
3665
|
+
else if (specifier.startsWith("@/")) {
|
|
3666
|
+
basePath = resolve(cwd, framework.srcDir ? "src" : "", specifier.slice(2));
|
|
3667
|
+
}
|
|
3668
|
+
else {
|
|
3669
|
+
return null;
|
|
3670
|
+
}
|
|
3671
|
+
const relativeBasePath = relative(cwd, basePath);
|
|
3672
|
+
if (relativeBasePath === ".." ||
|
|
3673
|
+
relativeBasePath.startsWith(`..${sep}`) ||
|
|
3674
|
+
resolve(cwd, relativeBasePath) !== basePath) {
|
|
3675
|
+
return null;
|
|
3676
|
+
}
|
|
3677
|
+
const hasSourceExtension = JOBS_RUN_SOURCE_EXTENSIONS.some((extension) => basePath.endsWith(extension));
|
|
3678
|
+
const candidates = hasSourceExtension ? [basePath] : [
|
|
3679
|
+
...JOBS_RUN_SOURCE_EXTENSIONS.map((extension) => `${basePath}${extension}`),
|
|
3680
|
+
...JOBS_RUN_SOURCE_EXTENSIONS.map((extension) => join(basePath, `index${extension}`)),
|
|
3681
|
+
];
|
|
3682
|
+
for (const candidate of candidates) {
|
|
3683
|
+
if (await exists(candidate))
|
|
3684
|
+
return candidate;
|
|
3685
|
+
}
|
|
3686
|
+
return null;
|
|
3687
|
+
}
|
|
3688
|
+
async function inspectJobsRunModuleGraph(cwd, framework, rootRelativePath) {
|
|
3689
|
+
const clientFormatImports = [];
|
|
3690
|
+
const clientNodeImports = [];
|
|
3691
|
+
const helperPaths = new Set();
|
|
3692
|
+
const requestMethods = new Set();
|
|
3693
|
+
const sourceCache = new Map();
|
|
3694
|
+
const visitedStates = new Set();
|
|
3695
|
+
const rootPath = resolve(cwd, rootRelativePath);
|
|
3696
|
+
const queue = [{
|
|
3697
|
+
chain: [rootRelativePath],
|
|
3698
|
+
inheritedClientBoundary: false,
|
|
3699
|
+
path: rootPath,
|
|
3700
|
+
}];
|
|
3701
|
+
let truncated = false;
|
|
3702
|
+
while (queue.length > 0) {
|
|
3703
|
+
const current = queue.shift();
|
|
3704
|
+
let text = sourceCache.get(current.path);
|
|
3705
|
+
if (text === undefined) {
|
|
3706
|
+
if (sourceCache.size >= MAX_JOBS_RUN_GRAPH_MODULES) {
|
|
3707
|
+
truncated = true;
|
|
3708
|
+
break;
|
|
3709
|
+
}
|
|
3710
|
+
const source = await readTextIfExists(current.path);
|
|
3711
|
+
if (source === null)
|
|
3712
|
+
continue;
|
|
3713
|
+
text = source;
|
|
3714
|
+
sourceCache.set(current.path, text);
|
|
3715
|
+
}
|
|
3716
|
+
const moduleDirective = getModuleBoundaryDirective(text);
|
|
3717
|
+
const isClient = moduleDirective === "client" ||
|
|
3718
|
+
(moduleDirective !== "server" && current.inheritedClientBoundary);
|
|
3719
|
+
const stateKey = `${current.path}\0${isClient ? "client" : "server"}`;
|
|
3720
|
+
if (visitedStates.has(stateKey))
|
|
3721
|
+
continue;
|
|
3722
|
+
visitedStates.add(stateKey);
|
|
3723
|
+
const currentRelativePath = relative(cwd, current.path).replaceAll("\\", "/");
|
|
3724
|
+
const helpers = getJobsRunHelperImports(text);
|
|
3725
|
+
if (helpers.size > 0) {
|
|
3726
|
+
helperPaths.add(currentRelativePath);
|
|
3727
|
+
for (const method of getJobsRunRequestMethods(text)) {
|
|
3728
|
+
requestMethods.add(method);
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
const specifiers = getStaticModuleSpecifiers(text);
|
|
3732
|
+
if (isClient) {
|
|
3733
|
+
for (const specifier of specifiers) {
|
|
3734
|
+
const finding = {
|
|
3735
|
+
chain: current.chain,
|
|
3736
|
+
path: currentRelativePath,
|
|
3737
|
+
specifier,
|
|
3738
|
+
};
|
|
3739
|
+
if (specifier === "@gadicc/loom/jobs/format") {
|
|
3740
|
+
clientFormatImports.push(finding);
|
|
3741
|
+
}
|
|
3742
|
+
else if (specifier.startsWith("node:")) {
|
|
3743
|
+
clientNodeImports.push(finding);
|
|
3744
|
+
}
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
for (const specifier of specifiers) {
|
|
3748
|
+
const importedPath = await resolveLocalSourceImport(cwd, framework, current.path, specifier);
|
|
3749
|
+
if (!importedPath)
|
|
3750
|
+
continue;
|
|
3751
|
+
const importedRelativePath = relative(cwd, importedPath).replaceAll("\\", "/");
|
|
3752
|
+
queue.push({
|
|
3753
|
+
chain: [...current.chain, importedRelativePath],
|
|
3754
|
+
inheritedClientBoundary: isClient,
|
|
3755
|
+
path: importedPath,
|
|
3756
|
+
});
|
|
3757
|
+
}
|
|
3758
|
+
}
|
|
3759
|
+
return {
|
|
3760
|
+
clientFormatImports,
|
|
3761
|
+
clientNodeImports,
|
|
3762
|
+
helperPaths: [...helperPaths],
|
|
3763
|
+
requestMethods,
|
|
3764
|
+
truncated,
|
|
3765
|
+
};
|
|
3766
|
+
}
|
|
3604
3767
|
function detectBetterAuthExportName(text) {
|
|
3605
3768
|
const match = normalizeText(text).match(/export\s+const\s+([A-Za-z_$][\w$]*)\s*=\s*betterAuth\s*\(/);
|
|
3606
3769
|
return match?.[1] ?? null;
|
|
@@ -3686,6 +3849,7 @@ import * as jobs from "${config.metaCatalogModule}";
|
|
|
3686
3849
|
|
|
3687
3850
|
const JobsRunPage = createJobsRunPage({
|
|
3688
3851
|
metas: jobs,
|
|
3852
|
+
requestMethod: "${config.ui.requestMethod}",
|
|
3689
3853
|
});
|
|
3690
3854
|
|
|
3691
3855
|
export default JobsRunPage;
|
|
@@ -7253,6 +7417,11 @@ async function applyJobsFeature(cwd, framework, manifest, activate) {
|
|
|
7253
7417
|
? structuredClone(currentFeature)
|
|
7254
7418
|
: { status: "planned" };
|
|
7255
7419
|
const config = mergeJobsConfig(framework, feature.config);
|
|
7420
|
+
if (currentFeature?.status !== "active" &&
|
|
7421
|
+
!feature.config?.ui
|
|
7422
|
+
?.requestMethod) {
|
|
7423
|
+
config.ui.requestMethod = "POST";
|
|
7424
|
+
}
|
|
7256
7425
|
const tooling = await getProjectTooling(cwd, manifest);
|
|
7257
7426
|
const dependencyUpdate = await mutateProjectDependencies(cwd, tooling.dependencies, {
|
|
7258
7427
|
dependencies: JOBS_DEFAULT_DEPENDENCIES,
|
|
@@ -8154,11 +8323,6 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
8154
8323
|
config.metaCatalogModule,
|
|
8155
8324
|
"Jobs list-page module does not import the configured meta catalog module",
|
|
8156
8325
|
],
|
|
8157
|
-
[
|
|
8158
|
-
config.modules.runPageModule,
|
|
8159
|
-
"createJobsRunPage",
|
|
8160
|
-
"Jobs run-page module is not wired to the shared jobs run helper",
|
|
8161
|
-
],
|
|
8162
8326
|
[
|
|
8163
8327
|
config.modules.routeModule,
|
|
8164
8328
|
"createJobsRouteHandler",
|
|
@@ -8179,6 +8343,46 @@ async function checkJobsFeature(cwd, framework, manifest) {
|
|
|
8179
8343
|
suggestions.add("Update the jobs module wiring to match loom.json, or rerun `loom add jobs` and reapply any app-local customizations.");
|
|
8180
8344
|
}
|
|
8181
8345
|
}
|
|
8346
|
+
const runModuleGraph = await inspectJobsRunModuleGraph(cwd, framework, config.modules.runPageModule);
|
|
8347
|
+
if (runModuleGraph.helperPaths.length === 0) {
|
|
8348
|
+
issues.push(`Jobs run-page module is not wired to createJobsRunPage or JobsRunPanel through its local import graph: ${config.modules.runPageModule}`);
|
|
8349
|
+
suggestions.add("Use createJobsRunPage directly, or keep a server wrapper that passes serializable metadata to a local client island using JobsRunPanel.");
|
|
8350
|
+
}
|
|
8351
|
+
if (runModuleGraph.truncated) {
|
|
8352
|
+
issues.push(`Jobs run-page local import graph exceeds ${MAX_JOBS_RUN_GRAPH_MODULES} modules: ${config.modules.runPageModule}`);
|
|
8353
|
+
suggestions.add("Keep the jobs metadata catalog dependency-free and the run-page server-wrapper/client-island graph focused.");
|
|
8354
|
+
}
|
|
8355
|
+
const seenClientImports = new Set();
|
|
8356
|
+
for (const finding of runModuleGraph.clientFormatImports) {
|
|
8357
|
+
const key = `${finding.path}\0${finding.specifier}`;
|
|
8358
|
+
if (seenClientImports.has(key))
|
|
8359
|
+
continue;
|
|
8360
|
+
seenClientImports.add(key);
|
|
8361
|
+
issues.push(`Jobs client graph imports @gadicc/loom/jobs/format, which is not browser-safe: ${finding.path} (via ${finding.chain.join(" -> ")}). formatJobLogTime is available from @gadicc/loom/jobs/log; use JobsRunPanel, renderLogValue, or another explicitly browser-safe helper for structured browser output.`);
|
|
8362
|
+
}
|
|
8363
|
+
for (const finding of runModuleGraph.clientNodeImports) {
|
|
8364
|
+
const key = `${finding.path}\0${finding.specifier}`;
|
|
8365
|
+
if (seenClientImports.has(key))
|
|
8366
|
+
continue;
|
|
8367
|
+
seenClientImports.add(key);
|
|
8368
|
+
issues.push(`Jobs client graph imports Node builtin ${finding.specifier}: ${finding.path} (via ${finding.chain.join(" -> ")}). Move the Node-only module above the client boundary or replace it with a browser-safe helper.`);
|
|
8369
|
+
}
|
|
8370
|
+
if (runModuleGraph.clientFormatImports.length > 0 ||
|
|
8371
|
+
runModuleGraph.clientNodeImports.length > 0) {
|
|
8372
|
+
suggestions.add("Keep executable catalogs and server-only formatters outside the jobs run-page client graph.");
|
|
8373
|
+
}
|
|
8374
|
+
const requestMethods = runModuleGraph.requestMethods;
|
|
8375
|
+
const requestMethodMatches = config.ui.requestMethod === "GET"
|
|
8376
|
+
? requestMethods.size === 0 ||
|
|
8377
|
+
(requestMethods.size === 1 && requestMethods.has("GET"))
|
|
8378
|
+
: requestMethods.size === 1 && requestMethods.has("POST");
|
|
8379
|
+
if (runModuleGraph.helperPaths.length > 0 && !requestMethodMatches) {
|
|
8380
|
+
const actual = requestMethods.size > 0
|
|
8381
|
+
? [...requestMethods].join(" and ")
|
|
8382
|
+
: "the GET runtime default";
|
|
8383
|
+
issues.push(`Jobs run-page request method does not match loom.json: expected ${config.ui.requestMethod}, found ${actual} in ${runModuleGraph.helperPaths.join(", ")}`);
|
|
8384
|
+
suggestions.add(`Pass requestMethod: "${config.ui.requestMethod}" to createJobsRunPage or requestMethod="${config.ui.requestMethod}" to JobsRunPanel, and keep features.jobs.config.ui.requestMethod aligned.`);
|
|
8385
|
+
}
|
|
8182
8386
|
const jobsRoot = framework.srcDir ? "src/jobs" : "jobs";
|
|
8183
8387
|
const catalogFiles = [
|
|
8184
8388
|
`${jobsRoot}/index.ts`,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type NextPageSearchParams } from "./paths.js";
|
|
3
|
+
import { buildJobsRunSearchParams, DEFAULT_JOBS_RUN_REQUEST_METHOD, getJobsRunResponseErrorMessage, type JobsRunRequestMethod } from "./runRequest.js";
|
|
4
|
+
export { buildJobsRunSearchParams, DEFAULT_JOBS_RUN_REQUEST_METHOD, getJobsRunResponseErrorMessage, type JobsRunRequestMethod, };
|
|
3
5
|
export type JobRunStatus = "idle" | "starting" | "running" | "done" | "error" | "stopped";
|
|
4
6
|
export interface JobsRunPageProps {
|
|
5
7
|
params: Promise<{
|
|
@@ -37,6 +39,11 @@ export interface JobsRunPanelProps {
|
|
|
37
39
|
id: string;
|
|
38
40
|
queryString?: string;
|
|
39
41
|
metas?: Record<string, unknown> | Iterable<unknown>;
|
|
42
|
+
/**
|
|
43
|
+
* HTTP method used to start the job. Parameters remain in the query string.
|
|
44
|
+
* Defaults to GET for compatibility with existing consumers.
|
|
45
|
+
*/
|
|
46
|
+
requestMethod?: JobsRunRequestMethod;
|
|
40
47
|
renderLogValue?: RenderJobLogValue;
|
|
41
48
|
renderPage?: (props: RenderJobsRunPageProps) => React.ReactNode;
|
|
42
49
|
renderPanel?: (props: RenderJobsRunPanelProps) => React.ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../src/src/next/jobs/run.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../../src/src/next/jobs/run.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAS1B,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,wBAAwB,EACxB,+BAA+B,EAC/B,8BAA8B,EAC9B,KAAK,oBAAoB,EAC1B,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,wBAAwB,EACxB,+BAA+B,EAC/B,8BAA8B,EAC9B,KAAK,oBAAoB,GAC1B,CAAC;AAcF,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,UAAU,GACV,SAAS,GACT,MAAM,GACN,OAAO,GACP,SAAS,CAAC;AAEd,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChC,YAA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BAAsB,KAAK,KAAK,CAAC,SAAS,CAAC;IAChE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,KAAK,CAAC,SAAS,CAAC;IAClE,iBAAiB,CAAC,EAAE,CAClB,KAAK,EAAE,wBAAwB,KAC5B,KAAK,CAAC,SAAS,CAAC;IACrB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,KAAK,CAAC,SAAS,CAAC;CACnE;AAED,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,iBAAiB,EAAE,IAAI,GAAG,aAAa,CAAC;IACrD,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1C;AAoMD,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,OAmjBpD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,wBAA6B,IAC1C,OAAO,gBAAgB,SAYpD"}
|
package/esm/src/next/jobs/run.js
CHANGED
|
@@ -5,7 +5,9 @@ import { JobController } from "../../jobs/controller.js";
|
|
|
5
5
|
import { isJobLifecycleEvent, isJobLogEvent, } from "../../jobs/events.js";
|
|
6
6
|
import { formatJobLogTime } from "../../jobs/log.js";
|
|
7
7
|
import { createJobsAdminPaths, serializePageSearchParams, } from "./paths.js";
|
|
8
|
+
import { buildJobsRunSearchParams, DEFAULT_JOBS_RUN_REQUEST_METHOD, getJobsRunResponseErrorMessage, } from "./runRequest.js";
|
|
8
9
|
import { readNdJsonResponse } from "./stream.js";
|
|
10
|
+
export { buildJobsRunSearchParams, DEFAULT_JOBS_RUN_REQUEST_METHOD, getJobsRunResponseErrorMessage, };
|
|
9
11
|
const JOB_LOG_LEVEL_COLORS = [
|
|
10
12
|
"#b91c1c",
|
|
11
13
|
"#dc2626",
|
|
@@ -163,6 +165,7 @@ export function JobsRunPanel(props) {
|
|
|
163
165
|
const scrolling = React.useRef(false);
|
|
164
166
|
const scrollTimeout = React.useRef(null);
|
|
165
167
|
const lineHeight = React.useRef(12);
|
|
168
|
+
const abortController = React.useRef(null);
|
|
166
169
|
const activeMeta = React.useMemo(() => {
|
|
167
170
|
if (!props.metas)
|
|
168
171
|
return undefined;
|
|
@@ -216,6 +219,9 @@ export function JobsRunPanel(props) {
|
|
|
216
219
|
lineHeight.current =
|
|
217
220
|
Number.parseFloat(getComputedStyle(panelRef.current).fontSize) || 12;
|
|
218
221
|
}, []);
|
|
222
|
+
React.useEffect(() => {
|
|
223
|
+
return () => abortController.current?.abort();
|
|
224
|
+
}, []);
|
|
219
225
|
React.useEffect(() => {
|
|
220
226
|
const element = panelRef.current;
|
|
221
227
|
if (!element) {
|
|
@@ -242,8 +248,14 @@ export function JobsRunPanel(props) {
|
|
|
242
248
|
};
|
|
243
249
|
}, []);
|
|
244
250
|
React.useEffect(() => {
|
|
245
|
-
|
|
246
|
-
|
|
251
|
+
const element = panelRef.current;
|
|
252
|
+
if (!element || !autoscroll.current || scrolling.current)
|
|
253
|
+
return;
|
|
254
|
+
if (typeof element.scrollTo === "function") {
|
|
255
|
+
element.scrollTo(0, element.scrollHeight);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
element.scrollTop = element.scrollHeight;
|
|
247
259
|
}
|
|
248
260
|
}, [entries]);
|
|
249
261
|
const runJob = React.useCallback(async () => {
|
|
@@ -252,24 +264,7 @@ export function JobsRunPanel(props) {
|
|
|
252
264
|
}
|
|
253
265
|
isRunning.current = true;
|
|
254
266
|
const paths = createJobsAdminPaths(props.basePath);
|
|
255
|
-
const searchParams =
|
|
256
|
-
if (activeMeta?.params) {
|
|
257
|
-
for (const [key, val] of Object.entries(formValues)) {
|
|
258
|
-
const def = activeMeta.params[key];
|
|
259
|
-
if (def?.type === "boolean") {
|
|
260
|
-
searchParams.set(key, val === "true" ? "true" : "false");
|
|
261
|
-
}
|
|
262
|
-
else if (val !== "") {
|
|
263
|
-
searchParams.set(key, val);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
const p = new URLSearchParams(props.queryString || "");
|
|
269
|
-
for (const [key, val] of p.entries()) {
|
|
270
|
-
searchParams.set(key, val);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
267
|
+
const searchParams = buildJobsRunSearchParams(props.queryString, activeMeta?.params, formValues);
|
|
273
268
|
const qString = searchParams.toString();
|
|
274
269
|
if (typeof globalThis.window !== "undefined") {
|
|
275
270
|
const newUrl = `${globalThis.location.pathname}${qString ? `?${qString}` : ""}`;
|
|
@@ -279,12 +274,16 @@ export function JobsRunPanel(props) {
|
|
|
279
274
|
setStatus("starting");
|
|
280
275
|
setEntries([]);
|
|
281
276
|
nextEntryId.current = 0;
|
|
277
|
+
const controller = new AbortController();
|
|
278
|
+
abortController.current = controller;
|
|
282
279
|
try {
|
|
283
|
-
const response = await fetch(requestPath
|
|
280
|
+
const response = await fetch(requestPath, {
|
|
281
|
+
method: props.requestMethod ?? DEFAULT_JOBS_RUN_REQUEST_METHOD,
|
|
282
|
+
signal: controller.signal,
|
|
283
|
+
});
|
|
284
284
|
if (!response.ok) {
|
|
285
285
|
setStatus("error");
|
|
286
|
-
appendEntry(toJobErrorEvent(
|
|
287
|
-
`Request failed with status ${response.status}`));
|
|
286
|
+
appendEntry(toJobErrorEvent(await getJobsRunResponseErrorMessage(response)));
|
|
288
287
|
return;
|
|
289
288
|
}
|
|
290
289
|
if (!response.body) {
|
|
@@ -308,16 +307,36 @@ export function JobsRunPanel(props) {
|
|
|
308
307
|
}
|
|
309
308
|
}
|
|
310
309
|
catch (error) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
310
|
+
if (controller.signal.aborted) {
|
|
311
|
+
setStatus("stopped");
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
setStatus("error");
|
|
315
|
+
appendEntry(toJobErrorEvent(error instanceof Error
|
|
316
|
+
? error.stack ?? error.message
|
|
317
|
+
: safeJsonStringify(error)));
|
|
318
|
+
}
|
|
315
319
|
}
|
|
316
320
|
finally {
|
|
321
|
+
if (abortController.current === controller) {
|
|
322
|
+
abortController.current = null;
|
|
323
|
+
}
|
|
317
324
|
isRunning.current = false;
|
|
318
325
|
}
|
|
319
|
-
}, [
|
|
320
|
-
|
|
326
|
+
}, [
|
|
327
|
+
props.basePath,
|
|
328
|
+
props.id,
|
|
329
|
+
props.queryString,
|
|
330
|
+
props.requestMethod,
|
|
331
|
+
formValues,
|
|
332
|
+
activeMeta,
|
|
333
|
+
]);
|
|
334
|
+
const runKey = React.useMemo(() => [
|
|
335
|
+
props.basePath ?? "",
|
|
336
|
+
props.id,
|
|
337
|
+
props.queryString ?? "",
|
|
338
|
+
props.requestMethod ?? DEFAULT_JOBS_RUN_REQUEST_METHOD,
|
|
339
|
+
].join("\0"), [props.basePath, props.id, props.queryString, props.requestMethod]);
|
|
321
340
|
React.useEffect(() => {
|
|
322
341
|
if (props.autoStart !== true) {
|
|
323
342
|
setStatus("idle");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Supported transports for starting a job from the shared browser runner. */
|
|
2
|
+
export type JobsRunRequestMethod = "GET" | "POST";
|
|
3
|
+
/** The compatibility transport used when a run panel does not choose one. */
|
|
4
|
+
export declare const DEFAULT_JOBS_RUN_REQUEST_METHOD: JobsRunRequestMethod;
|
|
5
|
+
interface JobsRunParamDefinition {
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Preserves compatibility query values while overlaying declared form fields.
|
|
10
|
+
* Empty non-boolean fields remove an existing value instead of sending it.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildJobsRunSearchParams(queryString: string | undefined, definitions: Record<string, JobsRunParamDefinition> | undefined, formValues: Record<string, string>): any;
|
|
13
|
+
/**
|
|
14
|
+
* Builds a bounded plain-text message for a failed jobs runner response.
|
|
15
|
+
* Response content is returned only as text so React escapes it when rendered.
|
|
16
|
+
*/
|
|
17
|
+
export declare function getJobsRunResponseErrorMessage(response: Response): Promise<string>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=runRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runRequest.d.ts","sourceRoot":"","sources":["../../../../src/src/next/jobs/runRequest.ts"],"names":[],"mappings":"AAEA,8EAA8E;AAC9E,MAAM,MAAM,oBAAoB,GAAG,KAAK,GAAG,MAAM,CAAC;AAElD,6EAA6E;AAC7E,eAAO,MAAM,+BAA+B,EAAE,oBAA4B,CAAC;AAE3E,UAAU,sBAAsB;IAC9B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,GAAG,SAAS,EAC/D,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAiBnC;AAqCD;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,QAAQ,EAAE,QAAQ,GACjB,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
|