@holo-js/cli 0.3.0 → 0.3.2
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/bin/holo.mjs +38 -35
- package/dist/{broadcast-5VZM5SGQ.mjs → broadcast-GUQFANQ4.mjs} +9 -11
- package/dist/{cache-A42JSVYA.mjs → cache-PCM2BJJ2.mjs} +8 -9
- package/dist/{cache-migrations-4WKSEN2Q.mjs → cache-migrations-M6VC3JW3.mjs} +13 -15
- package/dist/{chunk-6BHJLCAO.mjs → chunk-BVULOZZ4.mjs} +52 -14
- package/dist/{chunk-TRYHX5S4.mjs → chunk-I6EXRSZM.mjs} +1 -1
- package/dist/{chunk-TH5YCOZB.mjs → chunk-JLZNWWFV.mjs} +28 -17
- package/dist/{chunk-R4ZYMEDU.mjs → chunk-NSG3OJDY.mjs} +116 -7
- package/dist/{chunk-YACY2572.mjs → chunk-OQEZ3MOE.mjs} +47 -47
- package/dist/{chunk-3RFRE7XG.mjs → chunk-SCVF2F3I.mjs} +2 -2
- package/dist/{chunk-EQUFFLRG.mjs → chunk-VQP6GHIQ.mjs} +6 -6
- package/dist/{chunk-QSVMXMTQ.mjs → chunk-VUJ4ITXR.mjs} +3 -3
- package/dist/{chunk-OLZEMIDQ.mjs → chunk-WMBFSYWK.mjs} +1 -1
- package/dist/{chunk-LHK5YUR4.mjs → chunk-XXQUCGBO.mjs} +1 -1
- package/dist/{chunk-I7QBCEV7.mjs → chunk-Y355VYRN.mjs} +5 -3
- package/dist/{chunk-VRGB6DIS.mjs → chunk-YJWHIQ45.mjs} +2 -0
- package/dist/{chunk-JVLZ3SOW.mjs → chunk-ZNJ4APGF.mjs} +2 -2
- package/dist/{config-BZHQK532.mjs → config-43W3SZUI.mjs} +3 -3
- package/dist/{dev-7KGRV56X.mjs → dev-SNXMGPLU.mjs} +9 -10
- package/dist/{discovery-HNH3BLDL.mjs → discovery-7TQXEUYW.mjs} +4 -4
- package/dist/{generators-3FVW4AEJ.mjs → generators-2KJ6OFWA.mjs} +14 -16
- package/dist/index.mjs +38 -35
- package/dist/{media-migrations-EG34NYAG.mjs → media-migrations-JMA7QMX7.mjs} +10 -12
- package/dist/{plugins-ZGLB6JO6.mjs → plugins-D6FWODCH.mjs} +3 -3
- package/dist/{queue-BEZDCZCY.mjs → queue-6QSL5VFZ.mjs} +11 -13
- package/dist/{queue-R54DUUYA.mjs → queue-SAPFMTB7.mjs} +13 -15
- package/dist/{queue-migrations-AM3AKT76.mjs → queue-migrations-GSREPIHP.mjs} +13 -15
- package/dist/{runtime-VR5BDPYQ.mjs → runtime-HYSSH54H.mjs} +1 -1
- package/dist/{runtime-4TJYZLQV.mjs → runtime-RX46GVZQ.mjs} +8 -10
- package/dist/runtime-worker.mjs +18 -1
- package/dist/{scaffold-ASEX5LEX.mjs → scaffold-HPNFLBF2.mjs} +7 -6
- package/dist/{security-KYTLP4DF.mjs → security-NR2WEPQ6.mjs} +8 -9
- package/package.json +19 -19
- package/dist/broadcast-AABT52BK.mjs +0 -206
- package/dist/cache-DUVBBOZU.mjs +0 -138
- package/dist/cache-migrations-PD2T5AV4.mjs +0 -175
- package/dist/chunk-HX6MOYBO.mjs +0 -2
- package/dist/chunk-KRADH7PK.mjs +0 -501
- package/dist/chunk-LALDNNPH.mjs +0 -428
- package/dist/chunk-M3IPUCTM.mjs +0 -25
- package/dist/chunk-OI54DOHK.mjs +0 -3170
- package/dist/dev-GQT37XJU.mjs +0 -46
- package/dist/generators-JWVNGUUE.mjs +0 -523
- package/dist/media-migrations-LGI7R7AR.mjs +0 -108
- package/dist/queue-migrations-U477YSFD.mjs +0 -173
- package/dist/runtime-MSRQD5W5.mjs +0 -59
- package/dist/scaffold-ZAD3XUSD.mjs +0 -143
- package/dist/security-4QLV7QCH.mjs +0 -73
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
initializeProjectRuntime
|
|
3
|
-
} from "./chunk-LALDNNPH.mjs";
|
|
4
|
-
import "./chunk-M3IPUCTM.mjs";
|
|
5
|
-
import {
|
|
6
|
-
writeLine
|
|
7
|
-
} from "./chunk-I7QBCEV7.mjs";
|
|
8
|
-
import "./chunk-HX6MOYBO.mjs";
|
|
9
|
-
import {
|
|
10
|
-
prepareProjectDiscovery
|
|
11
|
-
} from "./chunk-QSVMXMTQ.mjs";
|
|
12
|
-
import "./chunk-OI54DOHK.mjs";
|
|
13
|
-
import {
|
|
14
|
-
loadProjectConfig
|
|
15
|
-
} from "./chunk-JVLZ3SOW.mjs";
|
|
16
|
-
import {
|
|
17
|
-
loadGeneratedProjectRegistry
|
|
18
|
-
} from "./chunk-R4ZYMEDU.mjs";
|
|
19
|
-
import "./chunk-3RFRE7XG.mjs";
|
|
20
|
-
import "./chunk-TRYHX5S4.mjs";
|
|
21
|
-
import {
|
|
22
|
-
importProjectModule,
|
|
23
|
-
resolveProjectPackageImportSpecifier
|
|
24
|
-
} from "./chunk-YACY2572.mjs";
|
|
25
|
-
|
|
26
|
-
// src/broadcast.ts
|
|
27
|
-
import { basename, extname, resolve } from "path";
|
|
28
|
-
import { readFile } from "fs/promises";
|
|
29
|
-
import { loadConfigDirectory } from "@holo-js/config";
|
|
30
|
-
function hasLoadedRedisConfigSection(loadedFiles) {
|
|
31
|
-
return Array.isArray(loadedFiles) && loadedFiles.some((filePath) => {
|
|
32
|
-
return basename(filePath, extname(filePath)) === "redis";
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async function hasProjectPackageDependency(projectRoot, packageName) {
|
|
36
|
-
try {
|
|
37
|
-
const manifest = JSON.parse(await readFile(resolve(projectRoot, "package.json"), "utf8"));
|
|
38
|
-
return Boolean(
|
|
39
|
-
manifest.dependencies?.[packageName] || manifest.devDependencies?.[packageName] || manifest.optionalDependencies?.[packageName] || manifest.peerDependencies?.[packageName]
|
|
40
|
-
);
|
|
41
|
-
} catch {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function loadBroadcastCliModule(projectRoot) {
|
|
46
|
-
try {
|
|
47
|
-
return await import(resolveProjectPackageImportSpecifier(projectRoot, "@holo-js/broadcast"));
|
|
48
|
-
} catch (error) {
|
|
49
|
-
const details = error instanceof Error ? error.message : String(error);
|
|
50
|
-
throw new Error(
|
|
51
|
-
`Unable to load @holo-js/broadcast from ${projectRoot}. Install it with "holo install broadcast". ${details}`
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
async function loadRealtimeServerModule(projectRoot) {
|
|
56
|
-
const specifier = resolveProjectPackageImportSpecifier(projectRoot, "@holo-js/realtime/server");
|
|
57
|
-
try {
|
|
58
|
-
return await import(specifier);
|
|
59
|
-
} catch (error) {
|
|
60
|
-
const details = error instanceof Error ? error.message : String(error);
|
|
61
|
-
if (/Cannot find module|ERR_MODULE_NOT_FOUND|MODULE_NOT_FOUND/i.test(details) && details.includes(specifier)) {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function safeDecodeCookieSegment(value) {
|
|
68
|
-
try {
|
|
69
|
-
return decodeURIComponent(value);
|
|
70
|
-
} catch {
|
|
71
|
-
return value;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function readCookieFromHeader(header, name) {
|
|
75
|
-
for (const segment of header?.split(";") ?? []) {
|
|
76
|
-
const separator = segment.indexOf("=");
|
|
77
|
-
if (separator <= 0) {
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
const cookieName = safeDecodeCookieSegment(segment.slice(0, separator).trim());
|
|
81
|
-
if (cookieName === name) {
|
|
82
|
-
return safeDecodeCookieSegment(segment.slice(separator + 1).trim());
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return void 0;
|
|
86
|
-
}
|
|
87
|
-
function createRealtimeAuthRequestAccessors(headers) {
|
|
88
|
-
return {
|
|
89
|
-
async getCookie(name) {
|
|
90
|
-
return readCookieFromHeader(headers.get("cookie"), name);
|
|
91
|
-
},
|
|
92
|
-
async getHeader(name) {
|
|
93
|
-
return headers.get(name) ?? void 0;
|
|
94
|
-
},
|
|
95
|
-
async appendResponseCookie(_cookie) {
|
|
96
|
-
},
|
|
97
|
-
async redirectResponse(url) {
|
|
98
|
-
throw new Error(`Realtime auth attempted to redirect to "${url}". Realtime requests cannot redirect.`);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
async function createRealtimeWorkerBindings(projectRoot) {
|
|
103
|
-
if (!await hasProjectPackageDependency(projectRoot, "@holo-js/realtime")) {
|
|
104
|
-
return void 0;
|
|
105
|
-
}
|
|
106
|
-
const realtime = await loadRealtimeServerModule(projectRoot);
|
|
107
|
-
if (!realtime) {
|
|
108
|
-
return void 0;
|
|
109
|
-
}
|
|
110
|
-
const runtime = await initializeProjectRuntime(projectRoot);
|
|
111
|
-
realtime.configureRealtimeRuntime?.({
|
|
112
|
-
async runWithAuthRequestAccessors(accessors, callback) {
|
|
113
|
-
const runner = runtime.runWithAuthRequestAccessors;
|
|
114
|
-
return runner ? await runner(accessors, callback) : await callback();
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
const definitions = /* @__PURE__ */ new Map();
|
|
118
|
-
const resolveDefinition = async (name) => {
|
|
119
|
-
const cached = definitions.get(name);
|
|
120
|
-
if (cached) {
|
|
121
|
-
return await cached;
|
|
122
|
-
}
|
|
123
|
-
const resolved = realtime.resolveRealtimeDefinition(name, {
|
|
124
|
-
projectRoot,
|
|
125
|
-
importModule: async (absolutePath) => await importProjectModule(projectRoot, absolutePath)
|
|
126
|
-
}).catch((error) => {
|
|
127
|
-
definitions.delete(name);
|
|
128
|
-
throw error;
|
|
129
|
-
});
|
|
130
|
-
definitions.set(name, resolved);
|
|
131
|
-
return await resolved;
|
|
132
|
-
};
|
|
133
|
-
const withRealtimeRequest = async (context, callback) => {
|
|
134
|
-
return await callback(createRealtimeAuthRequestAccessors(context.headers));
|
|
135
|
-
};
|
|
136
|
-
return {
|
|
137
|
-
async query(name, args, context) {
|
|
138
|
-
return await withRealtimeRequest(context, async (authRequest) => {
|
|
139
|
-
return await realtime.executeRealtimeQuery(await resolveDefinition(name), args, { authRequest });
|
|
140
|
-
});
|
|
141
|
-
},
|
|
142
|
-
async mutate(name, args, context) {
|
|
143
|
-
return await withRealtimeRequest(context, async (authRequest) => {
|
|
144
|
-
return await realtime.executeRealtimeMutation(await resolveDefinition(name), args, { authRequest });
|
|
145
|
-
});
|
|
146
|
-
},
|
|
147
|
-
async subscribe(name, args, options) {
|
|
148
|
-
return await withRealtimeRequest(options.context, async (authRequest) => {
|
|
149
|
-
return await realtime.subscribeRealtimeQuery(await resolveDefinition(name), args, {
|
|
150
|
-
onData: options.onData,
|
|
151
|
-
onPatch: options.onPatch,
|
|
152
|
-
onError: options.onError
|
|
153
|
-
}, { authRequest });
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
async function runBroadcastWorkCommand(io, projectRoot, dependencies = {}) {
|
|
159
|
-
const loadConfig = dependencies.loadConfig ?? loadConfigDirectory;
|
|
160
|
-
const loadModule = dependencies.loadModule ?? loadBroadcastCliModule;
|
|
161
|
-
const config = await loadConfig(projectRoot);
|
|
162
|
-
const project = await loadProjectConfig(projectRoot);
|
|
163
|
-
const loadRegistry = dependencies.loadRegistry ?? loadGeneratedProjectRegistry;
|
|
164
|
-
await loadRegistry(projectRoot).catch(() => void 0);
|
|
165
|
-
const registry = await prepareProjectDiscovery(projectRoot, project.config);
|
|
166
|
-
const broadcastModule = await loadModule(projectRoot);
|
|
167
|
-
const realtime = await createRealtimeWorkerBindings(projectRoot);
|
|
168
|
-
const worker = await broadcastModule.startBroadcastWorker({
|
|
169
|
-
config: config.broadcast,
|
|
170
|
-
queue: config.queue,
|
|
171
|
-
...hasLoadedRedisConfigSection(config.loadedFiles) ? { redis: config.redis } : {},
|
|
172
|
-
...registry ? {
|
|
173
|
-
channelAuth: {
|
|
174
|
-
registry: {
|
|
175
|
-
projectRoot,
|
|
176
|
-
channels: registry.channels
|
|
177
|
-
},
|
|
178
|
-
importModule: async (absolutePath) => await importProjectModule(projectRoot, absolutePath)
|
|
179
|
-
}
|
|
180
|
-
} : {},
|
|
181
|
-
...realtime ? { realtime } : {}
|
|
182
|
-
});
|
|
183
|
-
writeLine(io.stdout, `[broadcast] Worker listening on ${worker.host}:${worker.port}`);
|
|
184
|
-
await new Promise((resolvePromise) => {
|
|
185
|
-
let stopped = false;
|
|
186
|
-
const stop = async () => {
|
|
187
|
-
if (stopped) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
stopped = true;
|
|
191
|
-
process.off("SIGINT", onSignal);
|
|
192
|
-
process.off("SIGTERM", onSignal);
|
|
193
|
-
await worker.stop();
|
|
194
|
-
resolvePromise();
|
|
195
|
-
};
|
|
196
|
-
const onSignal = () => {
|
|
197
|
-
void stop();
|
|
198
|
-
};
|
|
199
|
-
process.on("SIGINT", onSignal);
|
|
200
|
-
process.on("SIGTERM", onSignal);
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
export {
|
|
204
|
-
loadBroadcastCliModule,
|
|
205
|
-
runBroadcastWorkCommand
|
|
206
|
-
};
|
package/dist/cache-DUVBBOZU.mjs
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
loadProjectDatabaseDrivers
|
|
3
|
-
} from "./chunk-XBOVM6LO.mjs";
|
|
4
|
-
import {
|
|
5
|
-
writeLine
|
|
6
|
-
} from "./chunk-I7QBCEV7.mjs";
|
|
7
|
-
import "./chunk-HX6MOYBO.mjs";
|
|
8
|
-
import "./chunk-6BHJLCAO.mjs";
|
|
9
|
-
import "./chunk-JVLZ3SOW.mjs";
|
|
10
|
-
import "./chunk-QSVMXMTQ.mjs";
|
|
11
|
-
import "./chunk-R4ZYMEDU.mjs";
|
|
12
|
-
import "./chunk-3RFRE7XG.mjs";
|
|
13
|
-
import "./chunk-TRYHX5S4.mjs";
|
|
14
|
-
import {
|
|
15
|
-
resolveProjectPackageImportSpecifier
|
|
16
|
-
} from "./chunk-YACY2572.mjs";
|
|
17
|
-
|
|
18
|
-
// src/cache.ts
|
|
19
|
-
import { loadConfigDirectory } from "@holo-js/config";
|
|
20
|
-
import { unregisterDatabaseDriverFactory } from "@holo-js/db";
|
|
21
|
-
var BUILT_IN_CACHE_DRIVER_NAMES = /* @__PURE__ */ new Set(["database", "file", "memory", "redis"]);
|
|
22
|
-
var CONCRETE_CACHE_DRIVER_PACKAGES = {
|
|
23
|
-
database: "@holo-js/cache-db",
|
|
24
|
-
redis: "@holo-js/cache-redis"
|
|
25
|
-
};
|
|
26
|
-
async function loadConfiguredCacheDriverPackages(projectRoot, drivers, loadPackage = (specifier) => import(specifier)) {
|
|
27
|
-
const configuredDrivers = new Set(Object.values(drivers).map(resolveConfiguredCacheDriverName));
|
|
28
|
-
for (const driver of configuredDrivers) {
|
|
29
|
-
if (driver !== "database" && driver !== "redis") continue;
|
|
30
|
-
const packageName = CONCRETE_CACHE_DRIVER_PACKAGES[driver];
|
|
31
|
-
try {
|
|
32
|
-
await loadPackage(resolveProjectPackageImportSpecifier(projectRoot, packageName));
|
|
33
|
-
} catch (error) {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`[Holo CLI] Cache driver "${driver}" requires ${packageName} to be installed.`,
|
|
36
|
-
{ cause: error }
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function resolveCacheFacade(cacheModule) {
|
|
42
|
-
const candidate = cacheModule.default;
|
|
43
|
-
if (candidate) {
|
|
44
|
-
return candidate;
|
|
45
|
-
}
|
|
46
|
-
return cacheModule;
|
|
47
|
-
}
|
|
48
|
-
function resolveConfiguredCacheDriverName(driverConfig) {
|
|
49
|
-
if (!driverConfig || typeof driverConfig !== "object" || Array.isArray(driverConfig)) {
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
const value = driverConfig.driver;
|
|
53
|
-
return typeof value === "string" ? value : void 0;
|
|
54
|
-
}
|
|
55
|
-
function resolveCachePluginDriverLoader(cacheModule, cache, drivers, requestedDriverName, defaultDriverName) {
|
|
56
|
-
const loadCachePluginDrivers = ("loadCachePluginDrivers" in cache ? cache.loadCachePluginDrivers?.bind(cache) : void 0) ?? ("loadCachePluginDrivers" in cacheModule ? cacheModule.loadCachePluginDrivers?.bind(cacheModule) : void 0);
|
|
57
|
-
const storeName = requestedDriverName?.trim() || defaultDriverName;
|
|
58
|
-
const driverName = resolveConfiguredCacheDriverName(drivers[storeName]);
|
|
59
|
-
if (!driverName || BUILT_IN_CACHE_DRIVER_NAMES.has(driverName)) {
|
|
60
|
-
return void 0;
|
|
61
|
-
}
|
|
62
|
-
if (loadCachePluginDrivers) {
|
|
63
|
-
return loadCachePluginDrivers;
|
|
64
|
-
}
|
|
65
|
-
throw new Error(
|
|
66
|
-
`[Holo CLI] Cache store "${storeName}" uses plugin driver "${driverName}", but the installed @holo-js/cache package does not support cache plugin drivers.`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
var cacheCommandInternals = {
|
|
70
|
-
loadConfiguredCacheDriverPackages,
|
|
71
|
-
resolveCachePluginDriverLoader
|
|
72
|
-
};
|
|
73
|
-
async function loadCacheCliModule(projectRoot) {
|
|
74
|
-
return await import(resolveProjectPackageImportSpecifier(projectRoot, "@holo-js/cache"));
|
|
75
|
-
}
|
|
76
|
-
async function initializeCacheMaintenanceEnvironment(projectRoot, driverName) {
|
|
77
|
-
const loadedConfig = await loadConfigDirectory(projectRoot);
|
|
78
|
-
const databaseDriverFactories = await loadProjectDatabaseDrivers(projectRoot, loadedConfig.database);
|
|
79
|
-
const cacheModule = await loadCacheCliModule(projectRoot);
|
|
80
|
-
const cache = resolveCacheFacade(cacheModule);
|
|
81
|
-
await loadConfiguredCacheDriverPackages(projectRoot, loadedConfig.cache.drivers);
|
|
82
|
-
const loadCachePluginDrivers = resolveCachePluginDriverLoader(
|
|
83
|
-
cacheModule,
|
|
84
|
-
cache,
|
|
85
|
-
loadedConfig.cache.drivers,
|
|
86
|
-
driverName,
|
|
87
|
-
loadedConfig.cache.default
|
|
88
|
-
);
|
|
89
|
-
cache.configureCacheRuntime({
|
|
90
|
-
config: loadedConfig.cache,
|
|
91
|
-
databaseConfig: loadedConfig.database,
|
|
92
|
-
redisConfig: loadedConfig.redis
|
|
93
|
-
});
|
|
94
|
-
if (loadCachePluginDrivers) {
|
|
95
|
-
try {
|
|
96
|
-
await loadCachePluginDrivers(projectRoot, loadedConfig.app.plugins);
|
|
97
|
-
} catch (error) {
|
|
98
|
-
cache.resetCacheRuntime();
|
|
99
|
-
throw error;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
cache,
|
|
104
|
-
async cleanup() {
|
|
105
|
-
cache.resetCacheRuntime();
|
|
106
|
-
for (const factory of [...databaseDriverFactories].reverse()) {
|
|
107
|
-
unregisterDatabaseDriverFactory(factory);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async function runCacheClearCommand(io, projectRoot, driverName, dependencies = {}) {
|
|
113
|
-
const environment = await (dependencies.initializeCache ?? initializeCacheMaintenanceEnvironment)(projectRoot, driverName);
|
|
114
|
-
try {
|
|
115
|
-
const repository = driverName?.trim() ? environment.cache.driver(driverName) : environment.cache;
|
|
116
|
-
await (dependencies.flush ?? (async (target) => await target.flush()))(repository);
|
|
117
|
-
writeLine(io.stdout, driverName?.trim() ? `[cache] Cleared cache store "${driverName}".` : "[cache] Cleared the default cache store.");
|
|
118
|
-
} finally {
|
|
119
|
-
await environment.cleanup();
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async function runCacheForgetCommand(io, projectRoot, key, driverName, dependencies = {}) {
|
|
123
|
-
const environment = await (dependencies.initializeCache ?? initializeCacheMaintenanceEnvironment)(projectRoot, driverName);
|
|
124
|
-
try {
|
|
125
|
-
const repository = driverName?.trim() ? environment.cache.driver(driverName) : environment.cache;
|
|
126
|
-
const forgotten = await (dependencies.forget ?? (async (target, targetKey) => await target.forget(targetKey)))(repository, key);
|
|
127
|
-
writeLine(io.stdout, forgotten ? `[cache] Forgot key "${key}".` : `[cache] Key "${key}" was not present.`);
|
|
128
|
-
} finally {
|
|
129
|
-
await environment.cleanup();
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
export {
|
|
133
|
-
cacheCommandInternals,
|
|
134
|
-
initializeCacheMaintenanceEnvironment,
|
|
135
|
-
loadCacheCliModule,
|
|
136
|
-
runCacheClearCommand,
|
|
137
|
-
runCacheForgetCommand
|
|
138
|
-
};
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
runProjectPrepare
|
|
3
|
-
} from "./chunk-TH5YCOZB.mjs";
|
|
4
|
-
import "./chunk-LHK5YUR4.mjs";
|
|
5
|
-
import {
|
|
6
|
-
getRegistryMigrationSlug,
|
|
7
|
-
hasRegisteredCreateTableMigration,
|
|
8
|
-
hasRegisteredMigrationSlug,
|
|
9
|
-
nextMigrationTemplate
|
|
10
|
-
} from "./chunk-OLZEMIDQ.mjs";
|
|
11
|
-
import "./chunk-M3IPUCTM.mjs";
|
|
12
|
-
import {
|
|
13
|
-
writeLine
|
|
14
|
-
} from "./chunk-I7QBCEV7.mjs";
|
|
15
|
-
import "./chunk-HX6MOYBO.mjs";
|
|
16
|
-
import "./chunk-6BHJLCAO.mjs";
|
|
17
|
-
import {
|
|
18
|
-
ensureProjectConfig
|
|
19
|
-
} from "./chunk-JVLZ3SOW.mjs";
|
|
20
|
-
import {
|
|
21
|
-
prepareProjectDiscovery
|
|
22
|
-
} from "./chunk-QSVMXMTQ.mjs";
|
|
23
|
-
import {
|
|
24
|
-
loadGeneratedProjectRegistry
|
|
25
|
-
} from "./chunk-R4ZYMEDU.mjs";
|
|
26
|
-
import "./chunk-3RFRE7XG.mjs";
|
|
27
|
-
import "./chunk-TRYHX5S4.mjs";
|
|
28
|
-
import {
|
|
29
|
-
makeProjectRelativePath,
|
|
30
|
-
resolveDefaultArtifactPath,
|
|
31
|
-
writeTextFile
|
|
32
|
-
} from "./chunk-YACY2572.mjs";
|
|
33
|
-
|
|
34
|
-
// src/cache-migrations.ts
|
|
35
|
-
import { resolve } from "path";
|
|
36
|
-
import {
|
|
37
|
-
CACHE_DATABASE_TABLE_DEFINITIONS,
|
|
38
|
-
DEFAULT_CACHE_DATABASE_LOCK_TABLE as CACHE_DB_DEFAULT_LOCK_TABLE,
|
|
39
|
-
DEFAULT_CACHE_DATABASE_TABLE as CACHE_DB_DEFAULT_TABLE
|
|
40
|
-
} from "@holo-js/cache-db";
|
|
41
|
-
import { loadConfigDirectory } from "@holo-js/config";
|
|
42
|
-
import { normalizeMigrationSlug } from "@holo-js/db";
|
|
43
|
-
var DEFAULT_CACHE_DATABASE_TABLE = CACHE_DB_DEFAULT_TABLE;
|
|
44
|
-
var DEFAULT_CACHE_DATABASE_LOCK_TABLE = CACHE_DB_DEFAULT_LOCK_TABLE;
|
|
45
|
-
async function loadCacheConfig(projectRoot) {
|
|
46
|
-
const loadedConfig = await loadConfigDirectory(projectRoot);
|
|
47
|
-
if (!loadedConfig || typeof loadedConfig !== "object" || !("cache" in loadedConfig) || !loadedConfig.cache || typeof loadedConfig.cache !== "object" || !("drivers" in loadedConfig.cache) || typeof loadedConfig.cache.drivers !== "object" || loadedConfig.cache.drivers === null || Array.isArray(loadedConfig.cache.drivers)) {
|
|
48
|
-
throw new Error("Cache config is missing or malformed. Expected a cache config object with a drivers property.");
|
|
49
|
-
}
|
|
50
|
-
const cacheConfig = loadedConfig.cache;
|
|
51
|
-
for (const [driverName, driverConfig] of Object.entries(cacheConfig.drivers)) {
|
|
52
|
-
if (driverConfig.driver !== "database") {
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
const databaseDriver = driverConfig;
|
|
56
|
-
if (typeof databaseDriver.table !== "string" || !databaseDriver.table.trim() || typeof databaseDriver.lockTable !== "string" || !databaseDriver.lockTable.trim()) {
|
|
57
|
-
throw new Error(`Database cache driver "${driverName}" must define non-empty "table" and "lockTable" strings.`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return cacheConfig;
|
|
61
|
-
}
|
|
62
|
-
function normalizeCacheMigrationName(tableName) {
|
|
63
|
-
return normalizeMigrationSlug(`create_${tableName.replaceAll(".", "_")}_cache_table`);
|
|
64
|
-
}
|
|
65
|
-
function escapeSingleQuotedString(value) {
|
|
66
|
-
return value.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
|
|
67
|
-
}
|
|
68
|
-
function renderCacheTableColumn(columnDefinition) {
|
|
69
|
-
const calls = [
|
|
70
|
-
`table.${columnDefinition.kind}('${escapeSingleQuotedString(columnDefinition.name)}')`
|
|
71
|
-
];
|
|
72
|
-
if (columnDefinition.primaryKey) {
|
|
73
|
-
calls.push("primaryKey()");
|
|
74
|
-
}
|
|
75
|
-
if (columnDefinition.nullable) {
|
|
76
|
-
calls.push("nullable()");
|
|
77
|
-
}
|
|
78
|
-
return ` ${calls.join(".")}`;
|
|
79
|
-
}
|
|
80
|
-
function renderCacheTableCreateStatement(tableName, tableDefinition) {
|
|
81
|
-
return [
|
|
82
|
-
` await schema.createTable('${escapeSingleQuotedString(tableName)}', (table) => {`,
|
|
83
|
-
...tableDefinition.columns.map(renderCacheTableColumn),
|
|
84
|
-
` table.index(['${escapeSingleQuotedString(tableDefinition.indexColumn)}'], '${escapeSingleQuotedString(tableDefinition.indexName(tableName))}')`,
|
|
85
|
-
" })"
|
|
86
|
-
];
|
|
87
|
-
}
|
|
88
|
-
function resolveCacheDatabaseTableDefinition(role) {
|
|
89
|
-
const tableDefinition = CACHE_DATABASE_TABLE_DEFINITIONS.find((definition) => definition.role === role);
|
|
90
|
-
if (!tableDefinition) {
|
|
91
|
-
throw new Error(`Missing cache database table definition for "${role}".`);
|
|
92
|
-
}
|
|
93
|
-
return tableDefinition;
|
|
94
|
-
}
|
|
95
|
-
function renderCacheTableMigration(tableName = DEFAULT_CACHE_DATABASE_TABLE, lockTableName = DEFAULT_CACHE_DATABASE_LOCK_TABLE) {
|
|
96
|
-
const entryTableDefinition = resolveCacheDatabaseTableDefinition("entries");
|
|
97
|
-
const lockTableDefinition = resolveCacheDatabaseTableDefinition("locks");
|
|
98
|
-
return [
|
|
99
|
-
"import { defineMigration } from '@holo-js/db'",
|
|
100
|
-
"",
|
|
101
|
-
"export default defineMigration({",
|
|
102
|
-
" async up({ schema }) {",
|
|
103
|
-
...renderCacheTableCreateStatement(tableName, entryTableDefinition),
|
|
104
|
-
...renderCacheTableCreateStatement(lockTableName, lockTableDefinition),
|
|
105
|
-
" },",
|
|
106
|
-
" async down({ schema }) {",
|
|
107
|
-
` await schema.dropTable('${escapeSingleQuotedString(lockTableName)}')`,
|
|
108
|
-
` await schema.dropTable('${escapeSingleQuotedString(tableName)}')`,
|
|
109
|
-
" },",
|
|
110
|
-
"})",
|
|
111
|
-
""
|
|
112
|
-
].join("\n");
|
|
113
|
-
}
|
|
114
|
-
function resolveDatabaseCacheTables(cacheConfig) {
|
|
115
|
-
const configured = Object.values(cacheConfig.drivers).filter((driver) => driver.driver === "database").map((driver) => ({
|
|
116
|
-
table: driver.table,
|
|
117
|
-
lockTable: driver.lockTable
|
|
118
|
-
}));
|
|
119
|
-
if (configured.length === 0) {
|
|
120
|
-
throw new Error("The configured cache drivers do not use the database driver.");
|
|
121
|
-
}
|
|
122
|
-
return Object.freeze(configured);
|
|
123
|
-
}
|
|
124
|
-
async function runCacheTableCommand(io, projectRoot) {
|
|
125
|
-
const project = await ensureProjectConfig(projectRoot);
|
|
126
|
-
const registry = await loadGeneratedProjectRegistry(projectRoot) ?? await prepareProjectDiscovery(projectRoot, project.config);
|
|
127
|
-
const cacheConfig = await loadCacheConfig(projectRoot);
|
|
128
|
-
const migrationsDir = resolve(projectRoot, project.config.paths.migrations);
|
|
129
|
-
const createdFiles = [];
|
|
130
|
-
const resolvedTables = resolveDatabaseCacheTables(cacheConfig);
|
|
131
|
-
const seenPhysicalTables = /* @__PURE__ */ new Set();
|
|
132
|
-
const seenSlugs = /* @__PURE__ */ new Map();
|
|
133
|
-
for (const { table, lockTable } of resolvedTables) {
|
|
134
|
-
const migrationName = normalizeCacheMigrationName(table);
|
|
135
|
-
const previousTable = seenSlugs.get(migrationName);
|
|
136
|
-
if (table === lockTable || seenPhysicalTables.has(table) || seenPhysicalTables.has(lockTable) || previousTable && previousTable !== table) {
|
|
137
|
-
throw new Error(`A migration for cache tables "${table}" and "${lockTable}" already exists.`);
|
|
138
|
-
}
|
|
139
|
-
seenPhysicalTables.add(table);
|
|
140
|
-
seenPhysicalTables.add(lockTable);
|
|
141
|
-
seenSlugs.set(migrationName, table);
|
|
142
|
-
}
|
|
143
|
-
for (const { table, lockTable } of resolvedTables) {
|
|
144
|
-
const migrationName = normalizeCacheMigrationName(table);
|
|
145
|
-
if (hasRegisteredMigrationSlug(registry, migrationName) || hasRegisteredCreateTableMigration(registry, table) || hasRegisteredCreateTableMigration(registry, lockTable)) {
|
|
146
|
-
throw new Error(`A migration for cache tables "${table}" and "${lockTable}" already exists.`);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
for (const { table, lockTable } of resolvedTables) {
|
|
150
|
-
const migrationTemplate = await nextMigrationTemplate(normalizeCacheMigrationName(table), migrationsDir);
|
|
151
|
-
const migrationFilePath = resolveDefaultArtifactPath(projectRoot, project.config.paths.migrations, migrationTemplate.fileName);
|
|
152
|
-
await writeTextFile(migrationFilePath, renderCacheTableMigration(table, lockTable));
|
|
153
|
-
createdFiles.push(migrationFilePath);
|
|
154
|
-
}
|
|
155
|
-
await runProjectPrepare(projectRoot);
|
|
156
|
-
for (const filePath of createdFiles) {
|
|
157
|
-
writeLine(io.stdout, `Created migration: ${makeProjectRelativePath(projectRoot, filePath)}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
var cacheMigrationInternals = {
|
|
161
|
-
getRegistryMigrationSlug,
|
|
162
|
-
hasRegisteredMigrationSlug,
|
|
163
|
-
hasRegisteredCreateTableMigration,
|
|
164
|
-
nextMigrationTemplate
|
|
165
|
-
};
|
|
166
|
-
export {
|
|
167
|
-
DEFAULT_CACHE_DATABASE_LOCK_TABLE,
|
|
168
|
-
DEFAULT_CACHE_DATABASE_TABLE,
|
|
169
|
-
cacheMigrationInternals,
|
|
170
|
-
loadCacheConfig,
|
|
171
|
-
normalizeCacheMigrationName,
|
|
172
|
-
renderCacheTableMigration,
|
|
173
|
-
resolveDatabaseCacheTables,
|
|
174
|
-
runCacheTableCommand
|
|
175
|
-
};
|
package/dist/chunk-HX6MOYBO.mjs
DELETED