@sentry/junior 0.202.0 → 0.204.0
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/agent-CMyTD4DD.js +17509 -0
- package/dist/agent-hooks-Bbcp9e33.js +4040 -0
- package/dist/agent-runner-DNb1A49M.js +678 -0
- package/dist/api/schema.d.ts +2728 -2639
- package/dist/api/schema.js +4 -169
- package/dist/api.d.ts +23 -17
- package/dist/api.js +3881 -5326
- package/dist/app-B1TOqBI8.d.ts +246 -0
- package/dist/app.d.ts +4 -520
- package/dist/app.js +9522 -11875
- package/dist/auth-pause-state-DosEalIG.js +168 -0
- package/dist/catalog-runtime-BReos-D4.js +7 -0
- package/dist/checkpoint-CNrPyRJN.js +2450 -0
- package/dist/cli/chat.d.ts +20 -0
- package/dist/cli/chat.js +229 -336
- package/dist/cli/check.d.ts +8 -0
- package/dist/cli/check.js +513 -806
- package/dist/cli/env.d.ts +13 -0
- package/dist/cli/env.js +63 -12
- package/dist/cli/init.d.ts +3 -0
- package/dist/cli/init.js +90 -159
- package/dist/cli/main.d.ts +6 -0
- package/dist/cli/main.js +43 -64
- package/dist/cli/plugins.d.ts +13 -0
- package/dist/cli/plugins.js +148 -227
- package/dist/cli/run.d.ts +16 -0
- package/dist/cli/run.js +52 -8
- package/dist/cli/snapshot-create.d.ts +4 -0
- package/dist/cli/snapshot-create.js +71 -125
- package/dist/cli/upgrade.d.ts +15 -0
- package/dist/cli/upgrade.js +232 -335
- package/dist/config-nGCW1OTG.js +941 -0
- package/dist/context-B45_WqVX.js +298 -0
- package/dist/conversation-privacy-B4voFRSm.js +182 -0
- package/dist/conversation-work-C6y3T5Hx.js +51 -0
- package/dist/credential-sync-kXr1hvO1.js +2660 -0
- package/dist/db-BeyXKJOI.d.ts +5 -0
- package/dist/destinations-BeBiJeEM.js +29 -0
- package/dist/execution-stats-DWfSihcH.js +373 -0
- package/dist/executor-DcMSlI5c.js +721 -0
- package/dist/experimental-CIXf7Uye.js +46 -0
- package/dist/history-ClE4toxe.d.ts +32 -0
- package/dist/history-CqTuSAdI.js +441 -0
- package/dist/instrumentation.d.ts +3 -3
- package/dist/instrumentation.js +130 -176
- package/dist/job-queue-Drn_LXlM.js +63 -0
- package/dist/logging-BzAk1S_s.js +1210 -0
- package/dist/model-profile-CZmVoGdX.js +49 -0
- package/dist/nitro.d.ts +31 -36
- package/dist/nitro.js +275 -456
- package/dist/oauth-callback-server-JiftokvA.js +130 -0
- package/dist/oauth-relay-CdCnu80W.js +62 -0
- package/dist/package-discovery-7a9YqLhE.js +455 -0
- package/dist/pending-auth-CWmSdZVg.js +185 -0
- package/dist/plugin-module-BKGOXca2.js +81 -0
- package/dist/plugins-BI9A1vKA.d.ts +95 -0
- package/dist/plugins-egKWjgue.js +99 -0
- package/dist/private-trace-result-BLvBjy_e.js +16 -0
- package/dist/profile-CrT5nXbw.js +861 -0
- package/dist/registry-DH1xUo2N.js +1419 -0
- package/dist/reporting-schema-DosTN__Q.js +105 -0
- package/dist/resolve-CZHnfxaS.js +546 -0
- package/dist/rolldown-runtime-B4FMCO8f.js +28 -0
- package/dist/runner-CZV2sC46.js +392 -0
- package/dist/sandbox-egress-signals-bHZfmhbd.js +46 -0
- package/dist/schema-Rn8-XEaN.js +1140 -0
- package/dist/sentry-CD3SdJl-.js +26 -0
- package/dist/skills-CIcDQSgM.js +316 -0
- package/dist/spawn-DdkUFRmq.js +29 -0
- package/dist/stats-DTUbAb88.js +2634 -0
- package/dist/store-C5qxF2ac.d.ts +208 -0
- package/dist/task-queue-CJIR4RF7.js +136 -0
- package/dist/task-runner-D-O3A-Cp.js +639 -0
- package/dist/thread-state-CRc9jTJS.js +431 -0
- package/dist/turn-execution-BkinIdJF.js +47 -0
- package/dist/turn-lifecycle-DQV19VTW.js +54 -0
- package/dist/usage-D3EbSO7w.js +296 -0
- package/dist/usage-schema-CKaDkH_j.js +20 -0
- package/dist/validation-C2CR-OX3.js +40 -0
- package/dist/vercel-queue-DIkVcfK4.js +167 -0
- package/dist/vercel.d.ts +6 -6
- package/dist/vercel.js +14 -6
- package/dist/version-CnXZ614E.d.ts +5 -0
- package/dist/version-DxcWdoKa.js +8 -0
- package/dist/version.d.ts +2 -4
- package/dist/version.js +2 -6
- package/dist/web-authorization-RMBxAR_t.js +76 -0
- package/dist/web-input-3EPfpf55.js +494 -0
- package/dist/work-fGofI7Op.js +509 -0
- package/dist/worker-CsOLq-mR.js +625 -0
- package/package.json +9 -9
- package/dist/agent-hooks-UXITLYOK.js +0 -51
- package/dist/catalog-runtime-BG3JLLK2.js +0 -14
- package/dist/chunk-2LYHWMR4.js +0 -46
- package/dist/chunk-2MK3QBGA.js +0 -321
- package/dist/chunk-3PGQSKJV.js +0 -692
- package/dist/chunk-3UI3WFTX.js +0 -519
- package/dist/chunk-3Y47VMHV.js +0 -6
- package/dist/chunk-4UO6FK4G.js +0 -64
- package/dist/chunk-5NOPO64K.js +0 -198
- package/dist/chunk-5PKWYPFT.js +0 -2943
- package/dist/chunk-63NKKFJL.js +0 -1228
- package/dist/chunk-6AYH6252.js +0 -787
- package/dist/chunk-6Y5B5PEX.js +0 -80
- package/dist/chunk-7DHZP5KJ.js +0 -333
- package/dist/chunk-7H2VZTWN.js +0 -103
- package/dist/chunk-7NL7T6VU.js +0 -406
- package/dist/chunk-A76OIMYN.js +0 -102
- package/dist/chunk-AWMS3SPP.js +0 -58
- package/dist/chunk-B3LY5RCL.js +0 -229
- package/dist/chunk-BD2KT3OB.js +0 -36
- package/dist/chunk-BXCX5QKA.js +0 -2086
- package/dist/chunk-C6VVF43U.js +0 -81
- package/dist/chunk-CEMMLV5L.js +0 -98
- package/dist/chunk-CM5HNV2W.js +0 -131
- package/dist/chunk-DA2KGZZI.js +0 -13
- package/dist/chunk-DBVY6HLX.js +0 -64
- package/dist/chunk-DIB4GX3G.js +0 -8
- package/dist/chunk-DKIJ2RP5.js +0 -68
- package/dist/chunk-DL2KLKVH.js +0 -931
- package/dist/chunk-DWPN6SCH.js +0 -172
- package/dist/chunk-ELWOYVOY.js +0 -206
- package/dist/chunk-EWT7H65X.js +0 -506
- package/dist/chunk-FA6POGLH.js +0 -70
- package/dist/chunk-HMREVIO2.js +0 -135
- package/dist/chunk-IIWUT4FO.js +0 -820
- package/dist/chunk-JAL3CH4G.js +0 -27
- package/dist/chunk-JSJQEWBJ.js +0 -3295
- package/dist/chunk-KHKKHDLD.js +0 -387
- package/dist/chunk-LA6R4A7Q.js +0 -706
- package/dist/chunk-LOOU2DUR.js +0 -20428
- package/dist/chunk-M6FHWXE3.js +0 -700
- package/dist/chunk-M76HMB7M.js +0 -1856
- package/dist/chunk-MAGNK5J4.js +0 -1520
- package/dist/chunk-MTM5IFCY.js +0 -1190
- package/dist/chunk-N7TMSOZH.js +0 -235
- package/dist/chunk-NHJU2ZAL.js +0 -56
- package/dist/chunk-NSXKRGRT.js +0 -717
- package/dist/chunk-OWMPFXJA.js +0 -1764
- package/dist/chunk-PDO5BLNM.js +0 -22
- package/dist/chunk-PEQXYSSE.js +0 -45
- package/dist/chunk-PW4P4JYF.js +0 -1135
- package/dist/chunk-QB54UQUS.js +0 -320
- package/dist/chunk-QP3OGJXF.js +0 -105
- package/dist/chunk-RC745GGZ.js +0 -122
- package/dist/chunk-REOIRYPR.js +0 -37
- package/dist/chunk-SCOZRLZ4.js +0 -164
- package/dist/chunk-TXJSXBV5.js +0 -1433
- package/dist/chunk-TXKUKMVO.js +0 -417
- package/dist/chunk-U2GPUYAL.js +0 -3656
- package/dist/chunk-UIE3R5XU.js +0 -17
- package/dist/chunk-UXPG6ZIN.js +0 -84
- package/dist/chunk-VFUK3X5B.js +0 -50
- package/dist/chunk-WQSHDTTI.js +0 -1163
- package/dist/chunk-X6GDDWQH.js +0 -60
- package/dist/chunk-Y2CM7HXH.js +0 -111
- package/dist/chunk-Y7X25LFY.js +0 -15
- package/dist/chunk-YDUR3ZYW.js +0 -10
- package/dist/conversation-work-VIOQ5ZF3.js +0 -54
- package/dist/db-3L2MCVRI.js +0 -26
- package/dist/discovery-DWVDM7UK.js +0 -44
- package/dist/experimental-P5FZM4CU.js +0 -12
- package/dist/oauth-callback-server-YVV6C6T2.js +0 -243
- package/dist/oauth-relay-5XPVRPYB.js +0 -8
- package/dist/plugins-YTYJMMJF.js +0 -14
- package/dist/runner-LQ7RETDP.js +0 -522
- package/dist/sandbox-egress-signals-FIL7EGPR.js +0 -73
- package/dist/sentry-MB3NL3IR.js +0 -42
- package/dist/skills-XRWYEDCD.js +0 -27
- package/dist/spawn-RC6SJUAI.js +0 -42
- package/dist/task-runner-7DY7ARYH.js +0 -36
- package/dist/validation-7MNQGCJA.js +0 -17
- package/dist/work-COALHUCG.js +0 -51
- package/dist/worker-6MURZIPD.js +0 -24
package/dist/cli/upgrade.js
CHANGED
|
@@ -1,69 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "../
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
} from "
|
|
9
|
-
import {
|
|
10
|
-
createJuniorSqlExecutor
|
|
11
|
-
} from "../chunk-PW4P4JYF.js";
|
|
12
|
-
import "../chunk-VFUK3X5B.js";
|
|
13
|
-
import {
|
|
14
|
-
getChatConfig
|
|
15
|
-
} from "../chunk-63NKKFJL.js";
|
|
16
|
-
import "../chunk-NHJU2ZAL.js";
|
|
17
|
-
import "../chunk-5NOPO64K.js";
|
|
18
|
-
import {
|
|
19
|
-
createPluginCatalogRuntime
|
|
20
|
-
} from "../chunk-BXCX5QKA.js";
|
|
21
|
-
import "../chunk-CEMMLV5L.js";
|
|
22
|
-
import "../chunk-N7TMSOZH.js";
|
|
23
|
-
import "../chunk-DWPN6SCH.js";
|
|
24
|
-
import "../chunk-TXKUKMVO.js";
|
|
25
|
-
import "../chunk-MAGNK5J4.js";
|
|
26
|
-
import "../chunk-PEQXYSSE.js";
|
|
27
|
-
import "../chunk-HMREVIO2.js";
|
|
28
|
-
|
|
29
|
-
// src/chat/conversations/sql/migrations.ts
|
|
30
|
-
import { basename, dirname, join, resolve } from "path";
|
|
31
|
-
import { fileURLToPath } from "url";
|
|
1
|
+
import { i as getChatConfig } from "../config-nGCW1OTG.js";
|
|
2
|
+
import { t as createJuniorSqlExecutor } from "../executor-DcMSlI5c.js";
|
|
3
|
+
import { t as createPluginCatalogRuntime } from "../registry-DH1xUo2N.js";
|
|
4
|
+
import { n as pluginCatalogConfigFromEnv, r as pluginCatalogConfigFromPluginSet, t as defineJuniorPlugins } from "../plugins-egKWjgue.js";
|
|
5
|
+
import { t as loadAppPluginSet } from "../plugin-module-BKGOXca2.js";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { createJiti } from "jiti";
|
|
32
10
|
import { readMigrationFiles } from "drizzle-orm/migrator";
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
//#region src/db/postgres-error.ts
|
|
12
|
+
/** Return whether an unknown PostgreSQL failure has the requested SQLSTATE. */
|
|
35
13
|
function isPostgresErrorCode(error, code) {
|
|
36
|
-
|
|
14
|
+
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
37
15
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/chat/conversations/sql/migrations.ts
|
|
18
|
+
/** SQL schema migrations for durable Junior records. */
|
|
19
|
+
const CORE_MIGRATION_BRIDGE_VERSION = "0.107.1";
|
|
20
|
+
const MIGRATIONS_TABLE = "__drizzle_junior_core";
|
|
21
|
+
/** Resolve the packaged Drizzle migration directory in source or built output. */
|
|
42
22
|
function migrationFolder() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const packageRoot = basename(moduleDir) === "dist" ? dirname(moduleDir) : basename(dirname(moduleDir)) === "dist" ? resolve(moduleDir, "../..") : resolve(moduleDir, "../../../..");
|
|
25
|
+
return join(packageRoot, "migrations");
|
|
46
26
|
}
|
|
27
|
+
/** Read core journal progress and detect existing pre-journal Junior tables. */
|
|
47
28
|
async function loadCoreMigrationState(executor) {
|
|
48
|
-
|
|
49
|
-
|
|
29
|
+
try {
|
|
30
|
+
const [migration] = await executor.query(`
|
|
50
31
|
SELECT created_at::text AS "appliedAt"
|
|
51
32
|
FROM drizzle.__drizzle_junior_core
|
|
52
33
|
ORDER BY created_at DESC
|
|
53
34
|
LIMIT 1
|
|
54
35
|
`);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
throw error;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const [tables] = await executor.query(`
|
|
36
|
+
if (migration?.appliedAt !== null && migration?.appliedAt !== void 0) return {
|
|
37
|
+
appliedAt: Number(migration.appliedAt),
|
|
38
|
+
hasJuniorTables: true
|
|
39
|
+
};
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (!isPostgresErrorCode(error, "42P01")) throw error;
|
|
42
|
+
}
|
|
43
|
+
const [tables] = await executor.query(`
|
|
67
44
|
SELECT EXISTS (
|
|
68
45
|
SELECT 1
|
|
69
46
|
FROM information_schema.tables
|
|
@@ -71,346 +48,266 @@ SELECT EXISTS (
|
|
|
71
48
|
AND table_name LIKE 'junior\\_%' ESCAPE '\\'
|
|
72
49
|
) AS "hasJuniorTables"
|
|
73
50
|
`);
|
|
74
|
-
|
|
75
|
-
hasJuniorTables: tables?.hasJuniorTables ?? false
|
|
76
|
-
};
|
|
51
|
+
return { hasJuniorTables: tables?.hasJuniorTables ?? false };
|
|
77
52
|
}
|
|
78
53
|
function isCurrentMigrationState(state, latestMigrationAt) {
|
|
79
|
-
|
|
54
|
+
return state.appliedAt !== void 0 && state.appliedAt >= latestMigrationAt;
|
|
80
55
|
}
|
|
81
56
|
function migrationResult(migrations, state) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
57
|
+
const appliedAt = state.appliedAt;
|
|
58
|
+
const existing = appliedAt === void 0 ? 0 : migrations.filter((migration) => migration.folderMillis <= appliedAt).length;
|
|
59
|
+
return {
|
|
60
|
+
existing,
|
|
61
|
+
migrated: migrations.length - existing,
|
|
62
|
+
scanned: migrations.length
|
|
63
|
+
};
|
|
89
64
|
}
|
|
65
|
+
/** Reject legacy databases that must first run the bridge release upgrade. */
|
|
90
66
|
function assertSupportedMigrationState(state) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
throw new Error(
|
|
95
|
-
`Existing Junior SQL tables have no core Drizzle migration history. Stop old Junior workers, install @sentry/junior@${CORE_MIGRATION_BRIDGE_VERSION}, run \`junior upgrade\`, then restore this Junior version and rerun \`junior upgrade\` before restarting workers.`
|
|
96
|
-
);
|
|
67
|
+
if (!state.hasJuniorTables || state.appliedAt !== void 0) return;
|
|
68
|
+
throw new Error(`Existing Junior SQL tables have no core Drizzle migration history. Stop old Junior workers, install @sentry/junior@${CORE_MIGRATION_BRIDGE_VERSION}, run \`junior upgrade\`, then restore this Junior version and rerun \`junior upgrade\` before restarting workers.`);
|
|
97
69
|
}
|
|
70
|
+
/** Apply the packaged Drizzle migrations during `junior upgrade`. */
|
|
98
71
|
async function migrateSchema(executor) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await executor.migrate({
|
|
117
|
-
migrationsFolder,
|
|
118
|
-
migrationsTable: MIGRATIONS_TABLE
|
|
119
|
-
});
|
|
120
|
-
return migrationResult(migrations, lockedState);
|
|
121
|
-
});
|
|
72
|
+
const migrationsFolder = migrationFolder();
|
|
73
|
+
const migrations = readMigrationFiles({ migrationsFolder });
|
|
74
|
+
const latestMigration = migrations.at(-1);
|
|
75
|
+
if (!latestMigration) throw new Error("No core Drizzle migrations were packaged");
|
|
76
|
+
const initialState = await loadCoreMigrationState(executor);
|
|
77
|
+
if (isCurrentMigrationState(initialState, latestMigration.folderMillis)) return migrationResult(migrations, initialState);
|
|
78
|
+
assertSupportedMigrationState(initialState);
|
|
79
|
+
return await executor.withMigrationLock(MIGRATIONS_TABLE, async () => {
|
|
80
|
+
const lockedState = await loadCoreMigrationState(executor);
|
|
81
|
+
if (isCurrentMigrationState(lockedState, latestMigration.folderMillis)) return migrationResult(migrations, lockedState);
|
|
82
|
+
assertSupportedMigrationState(lockedState);
|
|
83
|
+
await executor.migrate({
|
|
84
|
+
migrationsFolder,
|
|
85
|
+
migrationsTable: MIGRATIONS_TABLE
|
|
86
|
+
});
|
|
87
|
+
return migrationResult(migrations, lockedState);
|
|
88
|
+
});
|
|
122
89
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
import { createJiti } from "jiti";
|
|
126
|
-
|
|
127
|
-
// src/chat/plugins/migrations.ts
|
|
128
|
-
import { createHash } from "crypto";
|
|
129
|
-
import { readMigrationFiles as readMigrationFiles2 } from "drizzle-orm/migrator";
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/chat/plugins/migrations.ts
|
|
130
92
|
function migrationTable(pluginName) {
|
|
131
|
-
|
|
132
|
-
const hash = createHash("sha256").update(pluginName).digest("hex").slice(0, 8);
|
|
133
|
-
return `__drizzle_${label}_${hash}`;
|
|
93
|
+
return `__drizzle_${pluginName.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "").slice(0, 32)}_${createHash("sha256").update(pluginName).digest("hex").slice(0, 8)}`;
|
|
134
94
|
}
|
|
135
95
|
async function appliedMigrationTime(executor, table) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
`SELECT created_at::text AS "createdAt"
|
|
96
|
+
try {
|
|
97
|
+
const [row] = await executor.query(`SELECT created_at::text AS "createdAt"
|
|
139
98
|
FROM drizzle.${table}
|
|
140
99
|
ORDER BY created_at DESC
|
|
141
|
-
LIMIT 1`
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
throw error;
|
|
149
|
-
}
|
|
100
|
+
LIMIT 1`);
|
|
101
|
+
return row?.createdAt === null || row?.createdAt === void 0 ? void 0 : Number(row.createdAt);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (isPostgresErrorCode(error, "42P01")) return;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
150
106
|
}
|
|
151
107
|
async function legacyMigrationHashes(executor, pluginName) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (!exists?.tableName) {
|
|
156
|
-
return /* @__PURE__ */ new Set();
|
|
157
|
-
}
|
|
158
|
-
const rows = await executor.query(
|
|
159
|
-
`SELECT checksum
|
|
108
|
+
const [exists] = await executor.query("SELECT to_regclass('public.junior_schema_migrations')::text AS \"tableName\"");
|
|
109
|
+
if (!exists?.tableName) return /* @__PURE__ */ new Set();
|
|
110
|
+
const rows = await executor.query(`SELECT checksum
|
|
160
111
|
FROM junior_schema_migrations
|
|
161
112
|
WHERE id LIKE $1
|
|
162
|
-
ORDER BY id ASC`,
|
|
163
|
-
|
|
164
|
-
);
|
|
165
|
-
return new Set(rows.map((row) => row.checksum));
|
|
113
|
+
ORDER BY id ASC`, [`plugin:${pluginName}/%`]);
|
|
114
|
+
return new Set(rows.map((row) => row.checksum));
|
|
166
115
|
}
|
|
167
116
|
function adoptedMigration(migrations, legacyHashes) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
return adopted;
|
|
117
|
+
let adopted;
|
|
118
|
+
for (const migration of migrations) {
|
|
119
|
+
if (!legacyHashes.has(migration.hash)) break;
|
|
120
|
+
adopted = migration;
|
|
121
|
+
}
|
|
122
|
+
return adopted;
|
|
176
123
|
}
|
|
177
124
|
async function adoptLegacyMigrationState(args) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
return void 0;
|
|
185
|
-
}
|
|
186
|
-
await args.executor.transaction(async () => {
|
|
187
|
-
await args.executor.execute("CREATE SCHEMA IF NOT EXISTS drizzle");
|
|
188
|
-
await args.executor.execute(`
|
|
125
|
+
const legacyHashes = await legacyMigrationHashes(args.executor, args.pluginName);
|
|
126
|
+
const migration = adoptedMigration(args.migrations, legacyHashes);
|
|
127
|
+
if (!migration) return;
|
|
128
|
+
await args.executor.transaction(async () => {
|
|
129
|
+
await args.executor.execute("CREATE SCHEMA IF NOT EXISTS drizzle");
|
|
130
|
+
await args.executor.execute(`
|
|
189
131
|
CREATE TABLE IF NOT EXISTS drizzle.${args.table} (
|
|
190
132
|
id SERIAL PRIMARY KEY,
|
|
191
133
|
hash TEXT NOT NULL,
|
|
192
134
|
created_at BIGINT
|
|
193
135
|
)
|
|
194
136
|
`);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
);
|
|
199
|
-
});
|
|
200
|
-
return migration.folderMillis;
|
|
137
|
+
await args.executor.execute(`INSERT INTO drizzle.${args.table} (hash, created_at) VALUES ($1, $2)`, [migration.hash, migration.folderMillis]);
|
|
138
|
+
});
|
|
139
|
+
return migration.folderMillis;
|
|
201
140
|
}
|
|
202
141
|
function appliedCount(migrations, createdAt) {
|
|
203
|
-
|
|
142
|
+
return createdAt === void 0 ? 0 : migrations.filter((migration) => migration.folderMillis <= createdAt).length;
|
|
204
143
|
}
|
|
144
|
+
/** Apply enabled plugins' packaged Drizzle migrations in plugin-name order. */
|
|
205
145
|
async function migratePluginSchemas(executor, roots, options = {}) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
255
|
-
result.scanned += summary.scanned;
|
|
256
|
-
result.existing += summary.existing;
|
|
257
|
-
result.migrated += summary.migrated;
|
|
258
|
-
options.onPluginMigration?.(summary);
|
|
259
|
-
}
|
|
260
|
-
return result;
|
|
146
|
+
const result = {
|
|
147
|
+
existing: 0,
|
|
148
|
+
migrated: 0,
|
|
149
|
+
scanned: 0
|
|
150
|
+
};
|
|
151
|
+
const orderedRoots = [...roots].sort((left, right) => left.pluginName.localeCompare(right.pluginName));
|
|
152
|
+
for (const root of orderedRoots) {
|
|
153
|
+
const migrations = readMigrationFiles({ migrationsFolder: root.dir });
|
|
154
|
+
if (migrations.length === 0) continue;
|
|
155
|
+
const table = migrationTable(root.pluginName);
|
|
156
|
+
const initialExisting = appliedCount(migrations, await appliedMigrationTime(executor, table));
|
|
157
|
+
if (initialExisting === migrations.length) {
|
|
158
|
+
const summary = {
|
|
159
|
+
existing: initialExisting,
|
|
160
|
+
migrated: 0,
|
|
161
|
+
pluginName: root.pluginName,
|
|
162
|
+
scanned: migrations.length
|
|
163
|
+
};
|
|
164
|
+
result.scanned += summary.scanned;
|
|
165
|
+
result.existing += summary.existing;
|
|
166
|
+
options.onPluginMigration?.(summary);
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
const summary = await executor.withMigrationLock(table, async () => {
|
|
170
|
+
const currentTime = await appliedMigrationTime(executor, table) ?? await adoptLegacyMigrationState({
|
|
171
|
+
executor,
|
|
172
|
+
migrations,
|
|
173
|
+
pluginName: root.pluginName,
|
|
174
|
+
table
|
|
175
|
+
});
|
|
176
|
+
const existing = appliedCount(migrations, currentTime);
|
|
177
|
+
if (existing < migrations.length) await executor.migrate({
|
|
178
|
+
migrationsFolder: root.dir,
|
|
179
|
+
migrationsTable: table
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
existing,
|
|
183
|
+
migrated: migrations.length - existing,
|
|
184
|
+
pluginName: root.pluginName,
|
|
185
|
+
scanned: migrations.length
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
result.scanned += summary.scanned;
|
|
189
|
+
result.existing += summary.existing;
|
|
190
|
+
result.migrated += summary.migrated;
|
|
191
|
+
options.onPluginMigration?.(summary);
|
|
192
|
+
}
|
|
193
|
+
return result;
|
|
261
194
|
}
|
|
262
|
-
|
|
263
|
-
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/cli/upgrade/migrations/upgrade-plugins.ts
|
|
264
197
|
function unique(values) {
|
|
265
|
-
|
|
198
|
+
return [...new Set(values)];
|
|
266
199
|
}
|
|
267
200
|
function baseCatalogConfig(context) {
|
|
268
|
-
|
|
201
|
+
return context.pluginCatalogConfig ?? (context.pluginSet ? pluginCatalogConfigFromPluginSet(context.pluginSet) : pluginCatalogConfigFromEnv());
|
|
269
202
|
}
|
|
270
203
|
function inlinePluginName(definition) {
|
|
271
|
-
|
|
204
|
+
return definition.manifest.name;
|
|
272
205
|
}
|
|
273
206
|
function mergeInlineManifests(left, right) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
return merged.size > 0 ? [...merged.values()] : void 0;
|
|
207
|
+
const merged = /* @__PURE__ */ new Map();
|
|
208
|
+
for (const definition of [...left ?? [], ...right ?? []]) merged.set(inlinePluginName(definition), definition);
|
|
209
|
+
return merged.size > 0 ? [...merged.values()] : void 0;
|
|
279
210
|
}
|
|
280
211
|
function mergeCatalogConfig(base, added) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
]);
|
|
295
|
-
const manifests = base.manifests || added.manifests ? { ...base.manifests, ...added.manifests } : void 0;
|
|
296
|
-
return {
|
|
297
|
-
...inlineManifests ? { inlineManifests } : void 0,
|
|
298
|
-
...packages.length > 0 ? { packages } : void 0,
|
|
299
|
-
...manifests ? { manifests } : void 0
|
|
300
|
-
};
|
|
212
|
+
if (!base) return added;
|
|
213
|
+
if (!added) return base;
|
|
214
|
+
const inlineManifests = mergeInlineManifests(base.inlineManifests, added.inlineManifests);
|
|
215
|
+
const packages = unique([...base.packages ?? [], ...added.packages ?? []]);
|
|
216
|
+
const manifests = base.manifests || added.manifests ? {
|
|
217
|
+
...base.manifests,
|
|
218
|
+
...added.manifests
|
|
219
|
+
} : void 0;
|
|
220
|
+
return {
|
|
221
|
+
...inlineManifests ? { inlineManifests } : void 0,
|
|
222
|
+
...packages.length > 0 ? { packages } : void 0,
|
|
223
|
+
...manifests ? { manifests } : void 0
|
|
224
|
+
};
|
|
301
225
|
}
|
|
302
226
|
function packageNamesFromContext(context, catalog) {
|
|
303
|
-
|
|
304
|
-
...context.pluginSet?.packageNames ?? [],
|
|
305
|
-
...catalog?.packages ?? []
|
|
306
|
-
]);
|
|
227
|
+
return unique([...context.pluginSet?.packageNames ?? [], ...catalog?.packages ?? []]);
|
|
307
228
|
}
|
|
229
|
+
/** Resolve the plugin catalog used by SQL upgrade migrations. */
|
|
308
230
|
async function resolveUpgradePluginCatalog(context) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
manifests ? { manifests } : {}
|
|
319
|
-
) : void 0;
|
|
320
|
-
return mergeCatalogConfig(
|
|
321
|
-
catalog,
|
|
322
|
-
pluginCatalogConfigFromPluginSet(pluginSet)
|
|
323
|
-
);
|
|
231
|
+
const catalog = baseCatalogConfig(context);
|
|
232
|
+
const packageNames = packageNamesFromContext(context, catalog);
|
|
233
|
+
const registrations = context.pluginSet?.registrations ?? [];
|
|
234
|
+
const manifests = context.pluginSet?.manifests || catalog?.manifests ? {
|
|
235
|
+
...catalog?.manifests,
|
|
236
|
+
...context.pluginSet?.manifests
|
|
237
|
+
} : void 0;
|
|
238
|
+
const pluginSet = packageNames.length > 0 || registrations.length > 0 || context.pluginSet ? defineJuniorPlugins([...packageNames, ...registrations], manifests ? { manifests } : {}) : void 0;
|
|
239
|
+
return mergeCatalogConfig(catalog, pluginCatalogConfigFromPluginSet(pluginSet));
|
|
324
240
|
}
|
|
325
|
-
|
|
326
|
-
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/cli/upgrade/migrations/plugin-sql.ts
|
|
243
|
+
/** Apply SQL schema migrations owned by explicitly enabled plugins. */
|
|
327
244
|
async function migratePluginsToSql(context, options = {}) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
context.sqlExecutor,
|
|
332
|
-
pluginCatalog.getMigrationRoots(),
|
|
333
|
-
options
|
|
334
|
-
);
|
|
245
|
+
const pluginCatalog = createPluginCatalogRuntime();
|
|
246
|
+
pluginCatalog.setConfig(await resolveUpgradePluginCatalog(context));
|
|
247
|
+
return await migratePluginSchemas(context.sqlExecutor, pluginCatalog.getMigrationRoots(), options);
|
|
335
248
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
249
|
+
//#endregion
|
|
250
|
+
//#region src/cli/upgrade.ts
|
|
251
|
+
/**
|
|
252
|
+
* SQL-only upgrade entry point.
|
|
253
|
+
*
|
|
254
|
+
* It applies core and enabled-plugin Drizzle migrations through one owned
|
|
255
|
+
* executor; legacy state conversion belongs to the required bridge release.
|
|
256
|
+
*/
|
|
257
|
+
const DEFAULT_IO = { info: console.log };
|
|
258
|
+
const localPluginLoader = createJiti(import.meta.url, { moduleCache: false });
|
|
342
259
|
function isMissingVirtualConfig(error) {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
const code = error.code;
|
|
347
|
-
return (code === "ERR_PACKAGE_IMPORT_NOT_DEFINED" || code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && error.message.includes("#junior/config");
|
|
260
|
+
if (!(error instanceof Error)) return false;
|
|
261
|
+
const code = error.code;
|
|
262
|
+
return (code === "ERR_PACKAGE_IMPORT_NOT_DEFINED" || code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") && error.message.includes("#junior/config");
|
|
348
263
|
}
|
|
264
|
+
/** Resolve the plugin set available to upgrade migrations in source and built CLI runs. */
|
|
349
265
|
async function resolveUpgradePluginSet() {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
return await loadAppPluginSet(
|
|
359
|
-
process.cwd(),
|
|
360
|
-
async (moduleRef) => localPluginLoader.import(moduleRef.importPath)
|
|
361
|
-
);
|
|
266
|
+
try {
|
|
267
|
+
return (await import("#junior/config")).pluginSet;
|
|
268
|
+
} catch (error) {
|
|
269
|
+
if (!isMissingVirtualConfig(error)) throw error;
|
|
270
|
+
}
|
|
271
|
+
return await loadAppPluginSet(process.cwd(), async (moduleRef) => localPluginLoader.import(moduleRef.importPath));
|
|
362
272
|
}
|
|
363
273
|
function migrationCount(count) {
|
|
364
|
-
|
|
274
|
+
return `${count} ${count === 1 ? "migration" : "migrations"}`;
|
|
365
275
|
}
|
|
366
276
|
function formatOwnerSummary(owner, summary) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
return ` ${owner}: applied ${migrationCount(summary.migrated)} (${summary.scanned} total)`;
|
|
277
|
+
if (summary.migrated === 0) return ` ${owner}: up to date (${migrationCount(summary.scanned)})`;
|
|
278
|
+
return ` ${owner}: applied ${migrationCount(summary.migrated)} (${summary.scanned} total)`;
|
|
371
279
|
}
|
|
372
280
|
function pluginMigrationOwner(pluginName) {
|
|
373
|
-
|
|
374
|
-
|
|
281
|
+
const unscopedName = pluginName.split("/").at(-1) ?? pluginName;
|
|
282
|
+
return unscopedName.startsWith("junior-") ? unscopedName : `junior-${unscopedName}`;
|
|
375
283
|
}
|
|
376
284
|
async function runDatabaseMigrations(context, io) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
const migrated = core.migrated + plugins.migrated;
|
|
388
|
-
const scanned = core.scanned + plugins.scanned;
|
|
389
|
-
io.info(
|
|
390
|
-
migrated === 0 ? `Database is up to date (${migrationCount(scanned)}).` : `Applied ${migrationCount(migrated)} (${scanned} total).`
|
|
391
|
-
);
|
|
285
|
+
io.info("Checking database migrations...");
|
|
286
|
+
const core = await migrateSchema(context.sqlExecutor);
|
|
287
|
+
io.info(formatOwnerSummary("junior", core));
|
|
288
|
+
const plugins = await migratePluginsToSql(context, { onPluginMigration: (summary) => {
|
|
289
|
+
io.info(formatOwnerSummary(pluginMigrationOwner(summary.pluginName), summary));
|
|
290
|
+
} });
|
|
291
|
+
const migrated = core.migrated + plugins.migrated;
|
|
292
|
+
const scanned = core.scanned + plugins.scanned;
|
|
293
|
+
io.info(migrated === 0 ? `Database is up to date (${migrationCount(scanned)}).` : `Applied ${migrationCount(migrated)} (${scanned} total).`);
|
|
392
294
|
}
|
|
295
|
+
/** Apply Junior and enabled-plugin database migrations. */
|
|
393
296
|
async function runUpgrade(io = DEFAULT_IO, options = {}) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
);
|
|
409
|
-
} finally {
|
|
410
|
-
await sqlExecutor.close();
|
|
411
|
-
}
|
|
297
|
+
const { sql } = getChatConfig();
|
|
298
|
+
const sqlExecutor = createJuniorSqlExecutor({
|
|
299
|
+
connectionString: sql.databaseUrl,
|
|
300
|
+
driver: sql.driver,
|
|
301
|
+
statementTimeoutMs: false
|
|
302
|
+
});
|
|
303
|
+
try {
|
|
304
|
+
await runDatabaseMigrations({
|
|
305
|
+
pluginSet: options.pluginSet === void 0 ? await resolveUpgradePluginSet() : options.pluginSet ?? void 0,
|
|
306
|
+
sqlExecutor
|
|
307
|
+
}, io);
|
|
308
|
+
} finally {
|
|
309
|
+
await sqlExecutor.close();
|
|
310
|
+
}
|
|
412
311
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
runUpgrade
|
|
416
|
-
};
|
|
312
|
+
//#endregion
|
|
313
|
+
export { resolveUpgradePluginSet, runUpgrade };
|