@holo-js/cli 0.1.9 → 0.2.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/dist/bin/holo.mjs +179 -81
- package/dist/broadcast-III5MB3R.mjs +203 -0
- package/dist/broadcast-ZIFYFOUQ.mjs +203 -0
- package/dist/{cache-ETOIQ5IG.mjs → cache-634WUR3T.mjs} +6 -6
- package/dist/cache-7J7DIOP6.mjs +66 -0
- package/dist/{cache-migrations-2GGI4TJK.mjs → cache-migrations-2NBEUF2T.mjs} +50 -30
- package/dist/cache-migrations-S2LJMDOQ.mjs +173 -0
- package/dist/{chunk-WRZFATUT.mjs → chunk-4OHJC3GL.mjs} +232 -143
- package/dist/{chunk-ASTSSSL2.mjs → chunk-5TEH2QPK.mjs} +99 -122
- package/dist/{chunk-F4MT6GBK.mjs → chunk-FGQ2I2YH.mjs} +1 -1
- package/dist/chunk-I7QBCEV7.mjs +33 -0
- package/dist/{chunk-R6BWRY3E.mjs → chunk-ILU426CF.mjs} +3 -1
- package/dist/{chunk-IMOGEKB4.mjs → chunk-J76GH2DR.mjs} +229 -119
- package/dist/{chunk-HB4Q7VYK.mjs → chunk-KS5TWO75.mjs} +30 -273
- package/dist/{chunk-57SJ566R.mjs → chunk-LBJAJLKU.mjs} +1 -1
- package/dist/{chunk-BAFQ2GOA.mjs → chunk-LXGQCG56.mjs} +1 -1
- package/dist/chunk-MCVRN7KX.mjs +3308 -0
- package/dist/chunk-SFRAGRHY.mjs +472 -0
- package/dist/{chunk-7JR73TOH.mjs → chunk-VP2E62DF.mjs} +36 -25
- package/dist/{chunk-5EU32E7X.mjs → chunk-VRGB6DIS.mjs} +116 -12
- package/dist/{chunk-SRPGIWCF.mjs → chunk-YEFJBN56.mjs} +2 -2
- package/dist/{config-ARLE6PKR.mjs → config-MD27U4FM.mjs} +3 -3
- package/dist/{dev-6RG5SSZ7.mjs → dev-M2GGURAX.mjs} +9 -7
- package/dist/dev-PBNFQK6Y.mjs +44 -0
- package/dist/{discovery-FCVGQQVD.mjs → discovery-GWTBF5RZ.mjs} +3 -3
- package/dist/{generators-UI2LJK3O.mjs → generators-BZJ53PUU.mjs} +13 -36
- package/dist/generators-DEPLONDJ.mjs +520 -0
- package/dist/index.mjs +181 -83
- package/dist/{media-migrations-JQSDCC7S.mjs → media-migrations-5EISZBSD.mjs} +9 -20
- package/dist/media-migrations-NMUWBEKE.mjs +106 -0
- package/dist/{queue-BY3PLH4I.mjs → queue-FRAVPNFJ.mjs} +12 -12
- package/dist/queue-GY7BWGTX.mjs +625 -0
- package/dist/{queue-migrations-YZUKEZK7.mjs → queue-migrations-J7YPIKRB.mjs} +13 -12
- package/dist/queue-migrations-O24ERNFF.mjs +167 -0
- package/dist/{runtime-BI343WHS.mjs → runtime-2AA7ZLJ6.mjs} +9 -9
- package/dist/{runtime-ZKD6URAV.mjs → runtime-GSXF4NB3.mjs} +1 -1
- package/dist/runtime-HGK2MWSC.mjs +57 -0
- package/dist/runtime-worker.d.ts +2 -0
- package/dist/runtime-worker.mjs +276 -0
- package/dist/{scaffold-UBOS2NZR.mjs → scaffold-DEOTRALR.mjs} +9 -5
- package/dist/scaffold-Y232IGYS.mjs +139 -0
- package/dist/{security-TYPVOYGF.mjs → security-MZW2CJKS.mjs} +6 -6
- package/dist/security-XVG673UR.mjs +71 -0
- package/package.json +9 -7
- package/dist/broadcast-VR46UZEL.mjs +0 -84
- package/dist/chunk-ZXDU7RHU.mjs +0 -9
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
fileExists
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LBJAJLKU.mjs";
|
|
4
4
|
import {
|
|
5
5
|
prepareProjectDiscovery
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-VP2E62DF.mjs";
|
|
7
7
|
import {
|
|
8
8
|
loadProjectConfig,
|
|
9
9
|
resolveGeneratedSchemaPath
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-YEFJBN56.mjs";
|
|
11
11
|
import {
|
|
12
12
|
loadGeneratedProjectRegistry
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-J76GH2DR.mjs";
|
|
14
14
|
import {
|
|
15
15
|
CLI_RUNTIME_ROOT,
|
|
16
|
+
GENERATED_SCHEMA_RUNTIME_PATH,
|
|
16
17
|
bundleProjectModule
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-ILU426CF.mjs";
|
|
18
19
|
|
|
19
20
|
// src/runtime.ts
|
|
20
21
|
import { spawn } from "child_process";
|
|
@@ -189,270 +190,6 @@ async function getRuntimeEnvironment(projectRoot) {
|
|
|
189
190
|
}
|
|
190
191
|
};
|
|
191
192
|
}
|
|
192
|
-
var nodeRuntimeScript = `
|
|
193
|
-
import { mkdir, writeFile } from 'node:fs/promises'
|
|
194
|
-
import { dirname } from 'node:path'
|
|
195
|
-
import {
|
|
196
|
-
configureDB,
|
|
197
|
-
createSchemaService,
|
|
198
|
-
createMigrationService,
|
|
199
|
-
createSeederService,
|
|
200
|
-
registerGeneratedTables,
|
|
201
|
-
renderGeneratedSchemaModule,
|
|
202
|
-
resetDB,
|
|
203
|
-
resolveRuntimeConnectionManagerOptions,
|
|
204
|
-
} from '@holo-js/db'
|
|
205
|
-
|
|
206
|
-
const payload = JSON.parse(process.env.HOLO_RUNTIME_PAYLOAD ?? '{}')
|
|
207
|
-
process.chdir(payload.projectRoot)
|
|
208
|
-
|
|
209
|
-
function isRecord(value) {
|
|
210
|
-
return !!value && typeof value === 'object' && !Array.isArray(value)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async function loadModule(path) {
|
|
214
|
-
return import(\`\${path}?t=\${Date.now()}\`)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function resolveExport(moduleValue, matcher) {
|
|
218
|
-
if (isRecord(moduleValue) && matcher(moduleValue.default)) {
|
|
219
|
-
return moduleValue.default
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (isRecord(moduleValue)) {
|
|
223
|
-
for (const value of Object.values(moduleValue)) {
|
|
224
|
-
if (matcher(value)) {
|
|
225
|
-
return value
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return undefined
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
const isModel = (value) => isRecord(value) && isRecord(value.definition) && value.definition.kind === 'model' && typeof value.prune === 'function'
|
|
234
|
-
const isMigration = (value) => isRecord(value) && typeof value.up === 'function'
|
|
235
|
-
const isSeeder = (value) => isRecord(value) && typeof value.name === 'string' && typeof value.run === 'function'
|
|
236
|
-
const isTable = (value) => isRecord(value) && value.kind === 'table' && typeof value.tableName === 'string' && isRecord(value.columns)
|
|
237
|
-
const RUNTIME_MIGRATION_NAME_PATTERN = ${RUNTIME_MIGRATION_NAME_PATTERN}
|
|
238
|
-
const inferRuntimeMigrationName = ${inferRuntimeMigrationName.toString()}
|
|
239
|
-
const normalizeRuntimeMigration = ${normalizeRuntimeMigration.toString()}
|
|
240
|
-
const compileFreshDropIdentifierPath = ${compileFreshDropIdentifierPath.toString()}
|
|
241
|
-
const dropAllTablesForFresh = ${dropAllTablesForFresh.toString()}
|
|
242
|
-
|
|
243
|
-
function extractTables(moduleValue) {
|
|
244
|
-
if (isRecord(moduleValue) && isRecord(moduleValue.tables)) {
|
|
245
|
-
return Object.values(moduleValue.tables).filter(isTable)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (isRecord(moduleValue) && isTable(moduleValue.default)) {
|
|
249
|
-
return [moduleValue.default]
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (isRecord(moduleValue)) {
|
|
253
|
-
return Object.values(moduleValue).filter(isTable)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return []
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
async function preloadGeneratedSchema(manager, entry) {
|
|
260
|
-
if (!entry) {
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
const tables = extractTables(await loadModule(entry))
|
|
265
|
-
for (const table of tables) {
|
|
266
|
-
manager.connection().getSchemaRegistry().replace(table)
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async function writeGeneratedSchemaArtifact(manager, outputPath) {
|
|
271
|
-
if (!outputPath) {
|
|
272
|
-
return
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const source = renderGeneratedSchemaModule(manager.connection().getSchemaRegistry().list())
|
|
276
|
-
await mkdir(dirname(outputPath), { recursive: true })
|
|
277
|
-
await writeFile(outputPath, source, 'utf8')
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function syncGeneratedSchemaFromManager(manager) {
|
|
281
|
-
registerGeneratedTables(Object.fromEntries(
|
|
282
|
-
manager.connection().getSchemaRegistry().list().map(table => [table.tableName, table]),
|
|
283
|
-
))
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const manager = resolveRuntimeConnectionManagerOptions(payload.runtimeConfig)
|
|
287
|
-
configureDB(manager)
|
|
288
|
-
|
|
289
|
-
try {
|
|
290
|
-
await manager.initializeAll()
|
|
291
|
-
|
|
292
|
-
if (payload.kind === 'migrate') {
|
|
293
|
-
await preloadGeneratedSchema(manager, payload.generatedSchema)
|
|
294
|
-
const migrations = []
|
|
295
|
-
for (const entry of payload.migrations) {
|
|
296
|
-
const migration = resolveExport(await loadModule(entry), isMigration)
|
|
297
|
-
if (!migration) {
|
|
298
|
-
throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
|
|
299
|
-
}
|
|
300
|
-
migrations.push(normalizeRuntimeMigration(entry, migration))
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const executed = await createMigrationService(manager.connection(), migrations).migrate(payload.options ?? {})
|
|
304
|
-
await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
|
|
305
|
-
if (executed.length === 0) {
|
|
306
|
-
console.log('No migrations were executed.')
|
|
307
|
-
} else {
|
|
308
|
-
console.log('Migrations executed:')
|
|
309
|
-
for (const item of executed) {
|
|
310
|
-
console.log(\` \${item.name}\`)
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
} else if (payload.kind === 'fresh') {
|
|
314
|
-
const migrations = []
|
|
315
|
-
for (const entry of payload.migrations) {
|
|
316
|
-
const migration = resolveExport(await loadModule(entry), isMigration)
|
|
317
|
-
if (!migration) {
|
|
318
|
-
throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
|
|
319
|
-
}
|
|
320
|
-
migrations.push(normalizeRuntimeMigration(entry, migration))
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
const schema = createSchemaService(manager.connection())
|
|
324
|
-
await dropAllTablesForFresh(manager.connection(), schema)
|
|
325
|
-
manager.connection().getSchemaRegistry().clear()
|
|
326
|
-
|
|
327
|
-
const executed = await createMigrationService(manager.connection(), migrations).migrate({})
|
|
328
|
-
await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
|
|
329
|
-
syncGeneratedSchemaFromManager(manager)
|
|
330
|
-
if (executed.length === 0) {
|
|
331
|
-
console.log('No migrations were executed.')
|
|
332
|
-
} else {
|
|
333
|
-
console.log('Migrations executed:')
|
|
334
|
-
for (const item of executed) {
|
|
335
|
-
console.log(\` \${item.name}\`)
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
if (payload.options?.seed) {
|
|
340
|
-
const seeders = []
|
|
341
|
-
for (const entry of payload.seeders) {
|
|
342
|
-
const seeder = resolveExport(await loadModule(entry), isSeeder)
|
|
343
|
-
if (!seeder) {
|
|
344
|
-
throw new Error(\`Registered seeder "\${entry}" does not export a Holo seeder.\`)
|
|
345
|
-
}
|
|
346
|
-
seeders.push(seeder)
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
const seeded = await createSeederService(manager.connection(), seeders).seed({
|
|
350
|
-
...(Array.isArray(payload.options.only) ? { only: payload.options.only } : {}),
|
|
351
|
-
quietly: payload.options.quietly === true,
|
|
352
|
-
force: payload.options.force === true,
|
|
353
|
-
environment: payload.options.environment ?? 'development',
|
|
354
|
-
})
|
|
355
|
-
if (seeded.length === 0) {
|
|
356
|
-
console.log('No seeders were executed.')
|
|
357
|
-
} else {
|
|
358
|
-
console.log('Seeders executed:')
|
|
359
|
-
for (const item of seeded) {
|
|
360
|
-
console.log(\` \${item.name}\`)
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
} else if (payload.kind === 'rollback') {
|
|
365
|
-
await preloadGeneratedSchema(manager, payload.generatedSchema)
|
|
366
|
-
const migrations = []
|
|
367
|
-
for (const entry of payload.migrations) {
|
|
368
|
-
const migration = resolveExport(await loadModule(entry), isMigration)
|
|
369
|
-
if (!migration) {
|
|
370
|
-
throw new Error(\`Registered migration "\${entry}" does not export a Holo migration.\`)
|
|
371
|
-
}
|
|
372
|
-
migrations.push(normalizeRuntimeMigration(entry, migration))
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
const rolledBack = await createMigrationService(manager.connection(), migrations).rollback(payload.options ?? {})
|
|
376
|
-
await writeGeneratedSchemaArtifact(manager, payload.generatedSchemaOutputPath)
|
|
377
|
-
if (rolledBack.length === 0) {
|
|
378
|
-
console.log('No migrations were rolled back.')
|
|
379
|
-
} else {
|
|
380
|
-
console.log('Migrations rolled back:')
|
|
381
|
-
for (const item of rolledBack) {
|
|
382
|
-
console.log(\` \${item.name}\`)
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
} else if (payload.kind === 'seed') {
|
|
386
|
-
if (payload.generatedSchema) {
|
|
387
|
-
await preloadGeneratedSchema(manager, payload.generatedSchema)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
const seeders = []
|
|
391
|
-
for (const entry of payload.seeders) {
|
|
392
|
-
const seeder = resolveExport(await loadModule(entry), isSeeder)
|
|
393
|
-
if (!seeder) {
|
|
394
|
-
throw new Error(\`Registered seeder "\${entry}" does not export a Holo seeder.\`)
|
|
395
|
-
}
|
|
396
|
-
seeders.push(seeder)
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const executed = await createSeederService(manager.connection(), seeders).seed(payload.options ?? {})
|
|
400
|
-
if (executed.length === 0) {
|
|
401
|
-
console.log('No seeders were executed.')
|
|
402
|
-
} else {
|
|
403
|
-
console.log('Seeders executed:')
|
|
404
|
-
for (const item of executed) {
|
|
405
|
-
console.log(\` \${item.name}\`)
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
} else if (payload.kind === 'prune') {
|
|
409
|
-
const models = []
|
|
410
|
-
for (const entry of payload.models) {
|
|
411
|
-
const model = resolveExport(await loadModule(entry), isModel)
|
|
412
|
-
if (!model) {
|
|
413
|
-
throw new Error(\`Registered model "\${entry}" does not export a Holo model.\`)
|
|
414
|
-
}
|
|
415
|
-
models.push(model)
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const byName = new Map(models.map(model => [model.definition.name, model]))
|
|
419
|
-
const requested = payload.options?.models ?? []
|
|
420
|
-
const selected = []
|
|
421
|
-
|
|
422
|
-
if (requested.length === 0) {
|
|
423
|
-
selected.push(...models.filter(model => Boolean(model.definition.prunable)))
|
|
424
|
-
} else {
|
|
425
|
-
for (const name of requested) {
|
|
426
|
-
const model = byName.get(name)
|
|
427
|
-
if (!model) {
|
|
428
|
-
throw new Error(\`Unknown model "\${name}".\`)
|
|
429
|
-
}
|
|
430
|
-
if (!model.definition.prunable) {
|
|
431
|
-
throw new Error(\`Model "\${name}" does not define a prunable query.\`)
|
|
432
|
-
}
|
|
433
|
-
selected.push(model)
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
if (selected.length === 0) {
|
|
438
|
-
console.log('No prunable models were registered.')
|
|
439
|
-
} else {
|
|
440
|
-
let total = 0
|
|
441
|
-
for (const model of selected) {
|
|
442
|
-
const deleted = await model.prune()
|
|
443
|
-
total += deleted
|
|
444
|
-
console.log(\`\${model.definition.name}: deleted \${deleted}\`)
|
|
445
|
-
}
|
|
446
|
-
console.log(\`Total deleted: \${total}\`)
|
|
447
|
-
}
|
|
448
|
-
} else {
|
|
449
|
-
throw new Error(\`Unknown runtime command "\${payload.kind}".\`)
|
|
450
|
-
}
|
|
451
|
-
} finally {
|
|
452
|
-
await manager.disconnectAll()
|
|
453
|
-
resetDB()
|
|
454
|
-
}
|
|
455
|
-
`;
|
|
456
193
|
async function resolvePackageRootFromSpecifier(specifier) {
|
|
457
194
|
let current = dirname(fileURLToPath(import.meta.resolve(specifier)));
|
|
458
195
|
while (true) {
|
|
@@ -526,10 +263,29 @@ async function cleanupRuntimeDependencyLink(projectRoot) {
|
|
|
526
263
|
await writeFile(refPath, String(nextReferences), "utf8");
|
|
527
264
|
});
|
|
528
265
|
}
|
|
529
|
-
function
|
|
266
|
+
function resolveRuntimeWorkerPath() {
|
|
267
|
+
const runtimePath = fileURLToPath(import.meta.url);
|
|
268
|
+
return runtimePath.endsWith("/src/runtime.ts") ? resolve(dirname(runtimePath), "runtime-worker.ts") : resolve(dirname(runtimePath), "runtime-worker.mjs");
|
|
269
|
+
}
|
|
270
|
+
function supportsNodeTypeStripping(version = process.versions.node) {
|
|
271
|
+
const [major = "0", minor = "0"] = version.split(".");
|
|
272
|
+
const majorVersion = Number.parseInt(major, 10);
|
|
273
|
+
const minorVersion = Number.parseInt(minor, 10);
|
|
274
|
+
return majorVersion > 22 || majorVersion === 22 && minorVersion >= 6;
|
|
275
|
+
}
|
|
276
|
+
function resolveCompiledRuntimeWorkerPath(workerPath) {
|
|
277
|
+
return resolve(dirname(workerPath), "../dist/runtime-worker.mjs");
|
|
278
|
+
}
|
|
279
|
+
function createRuntimeInvocation(workerPath = resolveRuntimeWorkerPath()) {
|
|
280
|
+
if (workerPath.endsWith(".ts")) {
|
|
281
|
+
return {
|
|
282
|
+
command: "node",
|
|
283
|
+
args: supportsNodeTypeStripping() ? ["--experimental-strip-types", workerPath] : [resolveCompiledRuntimeWorkerPath(workerPath)]
|
|
284
|
+
};
|
|
285
|
+
}
|
|
530
286
|
return {
|
|
531
287
|
command: "node",
|
|
532
|
-
args: [
|
|
288
|
+
args: [workerPath]
|
|
533
289
|
};
|
|
534
290
|
}
|
|
535
291
|
function runRuntimeInvocation(command, args, options) {
|
|
@@ -622,9 +378,10 @@ async function withRuntimeEnvironment(projectRoot, kind, options, callback) {
|
|
|
622
378
|
seeders: environment.bundledSeeders.map((entry) => pathToFileURL(entry).href),
|
|
623
379
|
generatedSchema: environment.bundledGeneratedSchema ? pathToFileURL(environment.bundledGeneratedSchema).href : void 0,
|
|
624
380
|
generatedSchemaOutputPath: resolveGeneratedSchemaPath(projectRoot, environment.project.config),
|
|
381
|
+
generatedSchemaRuntimeOutputPath: resolve(projectRoot, GENERATED_SCHEMA_RUNTIME_PATH),
|
|
625
382
|
options
|
|
626
383
|
});
|
|
627
|
-
const runtime = createRuntimeInvocation(
|
|
384
|
+
const runtime = createRuntimeInvocation();
|
|
628
385
|
const result = await runRuntimeInvocation(runtime.command, runtime.args, {
|
|
629
386
|
cwd: runtimeRoot,
|
|
630
387
|
env: {
|
|
@@ -660,10 +417,10 @@ export {
|
|
|
660
417
|
compileFreshDropIdentifierPath,
|
|
661
418
|
dropAllTablesForFresh,
|
|
662
419
|
getRuntimeEnvironment,
|
|
663
|
-
nodeRuntimeScript,
|
|
664
420
|
resolvePackageRootFromSpecifier,
|
|
665
421
|
ensureRuntimeDependencyLink,
|
|
666
422
|
cleanupRuntimeDependencyLink,
|
|
423
|
+
resolveRuntimeWorkerPath,
|
|
667
424
|
createRuntimeInvocation,
|
|
668
425
|
runRuntimeInvocation,
|
|
669
426
|
getRuntimeFailureMessage,
|