@holo-js/cli 0.2.5 → 0.3.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.
Files changed (53) hide show
  1. package/dist/{agent-skills-MSEMQUXT.mjs → agent-skills-CHAXS2YN.mjs} +13 -6
  2. package/dist/bin/holo.mjs +436 -109
  3. package/dist/{broadcast-5MJ3GJK7.mjs → broadcast-5VZM5SGQ.mjs} +13 -10
  4. package/dist/{broadcast-MRJGFCFH.mjs → broadcast-AABT52BK.mjs} +13 -10
  5. package/dist/cache-A42JSVYA.mjs +138 -0
  6. package/dist/cache-DUVBBOZU.mjs +138 -0
  7. package/dist/{cache-migrations-CPYQC7T6.mjs → cache-migrations-4WKSEN2Q.mjs} +12 -10
  8. package/dist/{cache-migrations-APDFSFEX.mjs → cache-migrations-PD2T5AV4.mjs} +14 -12
  9. package/dist/chunk-3RFRE7XG.mjs +491 -0
  10. package/dist/{chunk-PT72AMV7.mjs → chunk-6BHJLCAO.mjs} +256 -392
  11. package/dist/{chunk-KS5TWO75.mjs → chunk-EQUFFLRG.mjs} +7 -7
  12. package/dist/chunk-HX6MOYBO.mjs +2 -0
  13. package/dist/{chunk-YEFJBN56.mjs → chunk-JVLZ3SOW.mjs} +11 -8
  14. package/dist/{chunk-UPXQONEH.mjs → chunk-KRADH7PK.mjs} +55 -51
  15. package/dist/chunk-LALDNNPH.mjs +428 -0
  16. package/dist/chunk-LHK5YUR4.mjs +156 -0
  17. package/dist/{chunk-LBJAJLKU.mjs → chunk-M3IPUCTM.mjs} +1 -1
  18. package/dist/{chunk-TWITVSFZ.mjs → chunk-OI54DOHK.mjs} +256 -392
  19. package/dist/{chunk-LXGQCG56.mjs → chunk-OLZEMIDQ.mjs} +1 -1
  20. package/dist/{chunk-VP2E62DF.mjs → chunk-QSVMXMTQ.mjs} +49 -349
  21. package/dist/{chunk-J76GH2DR.mjs → chunk-R4ZYMEDU.mjs} +129 -86
  22. package/dist/{chunk-XDRCZ3Z5.mjs → chunk-TH5YCOZB.mjs} +57 -53
  23. package/dist/chunk-TRYHX5S4.mjs +360 -0
  24. package/dist/chunk-XBOVM6LO.mjs +41 -0
  25. package/dist/{chunk-ILU426CF.mjs → chunk-YACY2572.mjs} +482 -2
  26. package/dist/{config-MD27U4FM.mjs → config-BZHQK532.mjs} +3 -3
  27. package/dist/{dev-CT4DRTLN.mjs → dev-7KGRV56X.mjs} +10 -8
  28. package/dist/{dev-QDLR6C7K.mjs → dev-GQT37XJU.mjs} +10 -8
  29. package/dist/{discovery-GWTBF5RZ.mjs → discovery-HNH3BLDL.mjs} +8 -6
  30. package/dist/{generators-PUN5TFP5.mjs → generators-3FVW4AEJ.mjs} +18 -15
  31. package/dist/{generators-WQHI7DBW.mjs → generators-JWVNGUUE.mjs} +14 -11
  32. package/dist/index.d.ts +1 -1
  33. package/dist/index.mjs +434 -107
  34. package/dist/{media-migrations-D3CDNMPT.mjs → media-migrations-EG34NYAG.mjs} +13 -11
  35. package/dist/{media-migrations-IWCSCKSA.mjs → media-migrations-LGI7R7AR.mjs} +11 -9
  36. package/dist/plugins-ZGLB6JO6.mjs +24 -0
  37. package/dist/{queue-O3OSLGOV.mjs → queue-BEZDCZCY.mjs} +54 -16
  38. package/dist/{queue-GRB2IH5M.mjs → queue-R54DUUYA.mjs} +54 -16
  39. package/dist/{queue-migrations-7T42S4FX.mjs → queue-migrations-AM3AKT76.mjs} +16 -11
  40. package/dist/{queue-migrations-HFZB64OG.mjs → queue-migrations-U477YSFD.mjs} +18 -13
  41. package/dist/{runtime-TTRP2DGL.mjs → runtime-4TJYZLQV.mjs} +10 -8
  42. package/dist/{runtime-M3G5OKQV.mjs → runtime-MSRQD5W5.mjs} +10 -8
  43. package/dist/{runtime-GSXF4NB3.mjs → runtime-VR5BDPYQ.mjs} +1 -1
  44. package/dist/runtime-worker.mjs +7 -1
  45. package/dist/{scaffold-5BOVJYF3.mjs → scaffold-ASEX5LEX.mjs} +8 -4
  46. package/dist/{scaffold-NY3MWUZF.mjs → scaffold-ZAD3XUSD.mjs} +8 -4
  47. package/dist/{security-ST6ED7EK.mjs → security-4QLV7QCH.mjs} +8 -6
  48. package/dist/{security-H7AGDFBX.mjs → security-KYTLP4DF.mjs} +8 -6
  49. package/package.json +35 -8
  50. package/dist/cache-KVRYC7FB.mjs +0 -66
  51. package/dist/cache-WWE4Q4YE.mjs +0 -66
  52. package/dist/chunk-D7O4SU6N.mjs +0 -2
  53. package/dist/chunk-FGQ2I2YH.mjs +0 -22
@@ -0,0 +1,360 @@
1
+ import {
2
+ COMMAND_FILE_PATTERN,
3
+ MIGRATION_NAME_PATTERN,
4
+ isRecord,
5
+ makeProjectRelativePath,
6
+ pathExists,
7
+ readTextFile,
8
+ toPosixPath
9
+ } from "./chunk-YACY2572.mjs";
10
+
11
+ // src/project/discovery-helpers.ts
12
+ import { readdir } from "fs/promises";
13
+ import { basename, dirname, extname, join, relative, resolve } from "path";
14
+ async function collectFiles(root) {
15
+ if (!await pathExists(root)) {
16
+ return [];
17
+ }
18
+ const entries = await readdir(root, { withFileTypes: true });
19
+ const files = [];
20
+ for (const entry of entries) {
21
+ const target = join(root, entry.name);
22
+ if (entry.isDirectory()) {
23
+ files.push(...await collectFiles(target));
24
+ continue;
25
+ }
26
+ if (entry.isFile() && COMMAND_FILE_PATTERN.test(entry.name)) {
27
+ files.push(target);
28
+ }
29
+ }
30
+ return files;
31
+ }
32
+ function deriveCommandNameFromPath(commandsRoot, sourcePath) {
33
+ const relativePath = toPosixPath(relative(commandsRoot, sourcePath));
34
+ return relativePath.replace(COMMAND_FILE_PATTERN, "").split("/").filter(Boolean).join(":");
35
+ }
36
+ function deriveJobNameFromPath(jobsRoot, sourcePath) {
37
+ const relativePath = toPosixPath(relative(jobsRoot, sourcePath));
38
+ return relativePath.replace(COMMAND_FILE_PATTERN, "").split("/").filter(Boolean).join(".");
39
+ }
40
+ function deriveDottedNameFromPath(root, sourcePath, emptyMessage) {
41
+ const relativePath = toPosixPath(relative(root, sourcePath)).replace(COMMAND_FILE_PATTERN, "");
42
+ const derived = relativePath.split("/").map((part) => part.trim()).filter(Boolean).join(".");
43
+ if (!derived) {
44
+ throw new Error(emptyMessage);
45
+ }
46
+ return derived;
47
+ }
48
+ function deriveEventNameFromPath(eventsRoot, sourcePath) {
49
+ return deriveDottedNameFromPath(eventsRoot, sourcePath, "[Holo Events] Derived event names require a non-empty source path.");
50
+ }
51
+ function deriveListenerIdFromPath(listenersRoot, sourcePath) {
52
+ return deriveDottedNameFromPath(listenersRoot, sourcePath, "[Holo Events] Derived listener identifiers require a non-empty source path.");
53
+ }
54
+ function deriveBroadcastNameFromPath(root, sourcePath) {
55
+ return deriveDottedNameFromPath(root, sourcePath, "[Holo Broadcast] Derived broadcast names require a non-empty source path.");
56
+ }
57
+ function deriveChannelPatternFromPath(root, sourcePath) {
58
+ return deriveDottedNameFromPath(root, sourcePath, "[Holo Broadcast] Derived channel patterns require a non-empty source path.");
59
+ }
60
+ function resolveDiscoveredJobMetadata(job, sourcePath, derivedName, queueConfig) {
61
+ const connection = job.connection ?? queueConfig.default;
62
+ let queue = job.queue;
63
+ if (!queue) {
64
+ const configuredConnection = queueConfig.connections[connection];
65
+ queue = configuredConnection ? configuredConnection.queue : "default";
66
+ }
67
+ return {
68
+ sourcePath,
69
+ name: derivedName,
70
+ connection,
71
+ queue,
72
+ ...typeof job.tries === "number" ? { tries: job.tries } : {},
73
+ ...typeof job.backoff !== "undefined" ? { backoff: job.backoff } : {},
74
+ ...typeof job.timeout === "number" ? { timeout: job.timeout } : {}
75
+ };
76
+ }
77
+ function isAppCommand(value) {
78
+ return isRecord(value) && typeof value.description === "string" && typeof value.run === "function";
79
+ }
80
+ function resolveCommandExport(moduleValue) {
81
+ if (isRecord(moduleValue) && isAppCommand(moduleValue.default)) {
82
+ return moduleValue.default;
83
+ }
84
+ if (isRecord(moduleValue)) {
85
+ for (const value of Object.values(moduleValue)) {
86
+ if (isAppCommand(value)) {
87
+ return value;
88
+ }
89
+ }
90
+ }
91
+ return void 0;
92
+ }
93
+ function normalizeCommandAliases(value) {
94
+ if (!value) {
95
+ return void 0;
96
+ }
97
+ const normalized = [...new Set(value.map((alias) => alias.trim()).filter(Boolean))];
98
+ return normalized.length > 0 ? normalized : void 0;
99
+ }
100
+ function assertUniqueEntries(kind, entries) {
101
+ const seen = /* @__PURE__ */ new Map();
102
+ for (const entry of entries) {
103
+ const existing = seen.get(entry.name);
104
+ if (existing) {
105
+ throw new Error(`Discovered duplicate ${kind} "${entry.name}" in "${existing}" and "${entry.sourcePath}".`);
106
+ }
107
+ seen.set(entry.name, entry.sourcePath);
108
+ }
109
+ }
110
+ function assertUniqueCommandTokens(entries) {
111
+ const seen = /* @__PURE__ */ new Map();
112
+ for (const entry of entries) {
113
+ for (const token of [entry.name, ...entry.aliases]) {
114
+ const existing = seen.get(token);
115
+ if (existing) {
116
+ throw new Error(`Discovered duplicate command token "${token}" in "${existing}" and "${entry.sourcePath}".`);
117
+ }
118
+ seen.set(token, entry.sourcePath);
119
+ }
120
+ }
121
+ }
122
+ function resolveRegisteredPath(projectRoot, entry) {
123
+ return resolve(projectRoot, entry);
124
+ }
125
+ function resolveNamedExport(moduleValue, matcher) {
126
+ if (!isRecord(moduleValue)) return void 0;
127
+ if (matcher(moduleValue.default)) return moduleValue.default;
128
+ for (const value of Object.values(moduleValue)) {
129
+ if (matcher(value)) return value;
130
+ }
131
+ return void 0;
132
+ }
133
+ function resolveNamedExportEntry(moduleValue, matcher) {
134
+ if (!isRecord(moduleValue)) return void 0;
135
+ if (matcher(moduleValue.default)) {
136
+ return { exportName: "default", value: moduleValue.default };
137
+ }
138
+ for (const [exportName, value] of Object.entries(moduleValue)) {
139
+ if (matcher(value)) return { exportName, value };
140
+ }
141
+ return void 0;
142
+ }
143
+ function isCliModelReference(value) {
144
+ return isRecord(value) && isRecord(value.definition) && value.definition.kind === "model" && typeof value.definition.name === "string" && typeof value.prune === "function";
145
+ }
146
+ function isMissingGeneratedSchemaModelError(error) {
147
+ return error instanceof Error && error.message.includes("is not present in the generated schema registry");
148
+ }
149
+ function isInactiveGeneratedModelModule(value) {
150
+ return isRecord(value) && value.holoModelPendingSchema === true;
151
+ }
152
+ function isMigrationDefinition(value) {
153
+ return isRecord(value) && typeof value.up === "function";
154
+ }
155
+ function isSeederDefinition(value) {
156
+ return isRecord(value) && typeof value.name === "string" && typeof value.run === "function";
157
+ }
158
+ function resolveListenerEventNamesForDiscovery(listener, eventNamesByReference = /* @__PURE__ */ new Map()) {
159
+ return Object.freeze([...new Set(listener.listensTo.map((reference) => {
160
+ if (typeof reference === "string") {
161
+ return reference.trim();
162
+ }
163
+ if (typeof reference.name === "string" && reference.name.trim()) {
164
+ return reference.name.trim();
165
+ }
166
+ if (eventNamesByReference.has(reference)) {
167
+ return eventNamesByReference.get(reference);
168
+ }
169
+ throw new Error("[Holo Events] Listener event references must resolve to explicit event names before discovery registration.");
170
+ }))]);
171
+ }
172
+ function resolveAuthorizationTargetName(target) {
173
+ const modelFacadeTarget = target;
174
+ if (typeof modelFacadeTarget.definition?.name === "string" && modelFacadeTarget.definition.name.trim()) {
175
+ return modelFacadeTarget.definition.name.trim();
176
+ }
177
+ const namedTarget = target;
178
+ return typeof namedTarget.name === "string" && namedTarget.name.trim() ? namedTarget.name.trim() : void 0;
179
+ }
180
+ function captureAuthorizationDefinitionNames(definitions) {
181
+ return new Set(definitions.keys());
182
+ }
183
+ function findAddedAuthorizationDefinitionNames(definitions, existingNames) {
184
+ return [...definitions.keys()].filter((name) => !existingNames.has(name));
185
+ }
186
+ function unregisterAuthorizationDefinitionNames(authorizationDiscovery, policyNames, abilityNames) {
187
+ if (typeof authorizationDiscovery.authorizationInternals.unregisterPolicyDefinition !== "function" || typeof authorizationDiscovery.authorizationInternals.unregisterAbilityDefinition !== "function") {
188
+ authorizationDiscovery.authorizationInternals.resetAuthorizationRuntimeState?.();
189
+ return;
190
+ }
191
+ for (const policyName of policyNames) {
192
+ authorizationDiscovery.authorizationInternals.unregisterPolicyDefinition(policyName);
193
+ }
194
+ for (const abilityName of abilityNames) {
195
+ authorizationDiscovery.authorizationInternals.unregisterAbilityDefinition(abilityName);
196
+ }
197
+ }
198
+ function collectImportedBindingsBySource(sourceText) {
199
+ const bindings = /* @__PURE__ */ new Map();
200
+ const importPattern = /import\s+([\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g;
201
+ for (const match of sourceText.matchAll(importPattern)) {
202
+ const clause = match[1]?.trim();
203
+ const source = match[2]?.trim();
204
+ if (!clause || !source) {
205
+ continue;
206
+ }
207
+ const namedMatch = clause.match(/\{([\s\S]+)\}/);
208
+ const defaultClause = clause.replace(/\{[\s\S]+\}/, "").replace(/,$/, "").trim();
209
+ if (defaultClause && defaultClause !== "*") {
210
+ bindings.set(defaultClause, source);
211
+ }
212
+ if (namedMatch?.[1]) {
213
+ for (const specifier of namedMatch[1].split(",")) {
214
+ const trimmed = specifier.trim();
215
+ if (!trimmed) {
216
+ continue;
217
+ }
218
+ const [imported, local] = trimmed.split(/\s+as\s+/);
219
+ const bindingName = (local ?? imported)?.trim();
220
+ if (bindingName) {
221
+ bindings.set(bindingName, source);
222
+ }
223
+ }
224
+ }
225
+ }
226
+ return bindings;
227
+ }
228
+ function extractListensToItems(sourceText) {
229
+ const markerIndex = sourceText.indexOf("listensTo");
230
+ if (markerIndex < 0) {
231
+ return [];
232
+ }
233
+ const colonIndex = sourceText.indexOf(":", markerIndex);
234
+ if (colonIndex < 0) {
235
+ return [];
236
+ }
237
+ let cursor = colonIndex + 1;
238
+ while (cursor < sourceText.length && /\s/.test(sourceText[cursor])) {
239
+ cursor += 1;
240
+ }
241
+ const startChar = sourceText[cursor];
242
+ let depth = 0;
243
+ let inString;
244
+ let expression = "";
245
+ for (; cursor < sourceText.length; cursor += 1) {
246
+ const char = sourceText[cursor];
247
+ expression += char;
248
+ if (inString) {
249
+ if (char === inString && sourceText[cursor - 1] !== "\\") {
250
+ inString = void 0;
251
+ }
252
+ continue;
253
+ }
254
+ if (char === "'" || char === '"' || char === "`") {
255
+ inString = char;
256
+ continue;
257
+ }
258
+ if (char === "[" || char === "{" || char === "(") {
259
+ depth += 1;
260
+ continue;
261
+ }
262
+ if (char === "]" || char === "}" || char === ")") {
263
+ depth -= 1;
264
+ if (depth === 0 && startChar === "[") {
265
+ break;
266
+ }
267
+ continue;
268
+ }
269
+ if (depth === 0 && startChar !== "[" && (char === "," || char === "\n" || char === "\r")) {
270
+ expression = expression.slice(0, -1);
271
+ break;
272
+ }
273
+ }
274
+ if (startChar !== "[") {
275
+ const item = expression.trim().replace(/\s+as\s+const$/, "");
276
+ return item ? [item] : [];
277
+ }
278
+ return expression.slice(1, -1).split(",").map((item) => item.trim().replace(/\s+as\s+const$/, "")).filter(Boolean);
279
+ }
280
+ async function resolveListenerEventNamesFromSource(projectRoot, listenerPath, discoveredEventNamesBySourcePath) {
281
+ const sourceText = await readTextFile(listenerPath) ?? "";
282
+ const bindingsByName = collectImportedBindingsBySource(sourceText);
283
+ const discoveredEventNamesByExtensionlessSourcePath = new Map(
284
+ [...discoveredEventNamesBySourcePath.entries()].map(([sourcePath, eventName]) => {
285
+ return [sourcePath.replace(/\.[^.]+$/, ""), eventName];
286
+ })
287
+ );
288
+ const resolvedEventNames = [];
289
+ for (const item of extractListensToItems(sourceText)) {
290
+ const quoted = item.match(/^['"](.+)['"]$/);
291
+ if (quoted) {
292
+ resolvedEventNames.push(quoted[1].trim());
293
+ continue;
294
+ }
295
+ const importSource = bindingsByName.get(item);
296
+ if (!importSource) {
297
+ throw new Error("[Holo Events] Listener event references must resolve to explicit event names before discovery registration.");
298
+ }
299
+ const importedPath = makeProjectRelativePath(projectRoot, resolve(dirname(listenerPath), importSource));
300
+ const eventName = discoveredEventNamesBySourcePath.get(importedPath) ?? discoveredEventNamesByExtensionlessSourcePath.get(importedPath.replace(/\.[^.]+$/, ""));
301
+ if (!eventName) {
302
+ throw new Error("[Holo Events] Listener event references must resolve to explicit event names before discovery registration.");
303
+ }
304
+ resolvedEventNames.push(eventName);
305
+ }
306
+ return Object.freeze([...new Set(resolvedEventNames)]);
307
+ }
308
+ function resolveBroadcastArtifactsPath(config, key) {
309
+ const configuredPaths = config.paths;
310
+ return configuredPaths[key] ?? `server/${key}`;
311
+ }
312
+ function inferMigrationNameFromEntry(entry) {
313
+ const fileName = basename(entry, extname(entry));
314
+ return validateMigrationName(
315
+ fileName,
316
+ `Registered migration "${entry}" must use a timestamped file name matching YYYY_MM_DD_HHMMSS_description.`
317
+ );
318
+ }
319
+ function validateMigrationName(name, message) {
320
+ if (!MIGRATION_NAME_PATTERN.test(name)) {
321
+ throw new Error(
322
+ message ?? `Migration name "${name}" must match YYYY_MM_DD_HHMMSS_description.`
323
+ );
324
+ }
325
+ return name;
326
+ }
327
+
328
+ export {
329
+ collectFiles,
330
+ deriveCommandNameFromPath,
331
+ deriveJobNameFromPath,
332
+ deriveEventNameFromPath,
333
+ deriveListenerIdFromPath,
334
+ deriveBroadcastNameFromPath,
335
+ deriveChannelPatternFromPath,
336
+ resolveDiscoveredJobMetadata,
337
+ resolveCommandExport,
338
+ normalizeCommandAliases,
339
+ assertUniqueEntries,
340
+ assertUniqueCommandTokens,
341
+ resolveRegisteredPath,
342
+ resolveNamedExport,
343
+ resolveNamedExportEntry,
344
+ isCliModelReference,
345
+ isMissingGeneratedSchemaModelError,
346
+ isInactiveGeneratedModelModule,
347
+ isMigrationDefinition,
348
+ isSeederDefinition,
349
+ resolveListenerEventNamesForDiscovery,
350
+ resolveAuthorizationTargetName,
351
+ captureAuthorizationDefinitionNames,
352
+ findAddedAuthorizationDefinitionNames,
353
+ unregisterAuthorizationDefinitionNames,
354
+ collectImportedBindingsBySource,
355
+ extractListensToItems,
356
+ resolveListenerEventNamesFromSource,
357
+ resolveBroadcastArtifactsPath,
358
+ inferMigrationNameFromEntry,
359
+ validateMigrationName
360
+ };
@@ -0,0 +1,41 @@
1
+ // src/database-drivers.ts
2
+ import { createRequire } from "module";
3
+ import { join } from "path";
4
+ import { pathToFileURL } from "url";
5
+ import { registerDatabaseDriverFactory } from "@holo-js/db";
6
+ async function loadProjectDatabaseDrivers(projectRoot, config) {
7
+ const packageByDriver = {
8
+ sqlite: { packageName: "@holo-js/db-sqlite", factoryExport: "sqliteDatabaseDriverFactory" },
9
+ postgres: { packageName: "@holo-js/db-postgres", factoryExport: "postgresDatabaseDriverFactory" },
10
+ mysql: { packageName: "@holo-js/db-mysql", factoryExport: "mysqlDatabaseDriverFactory" }
11
+ };
12
+ const connections = Object.values(config?.connections ?? { default: "./data/database.sqlite" });
13
+ const drivers = /* @__PURE__ */ new Set();
14
+ for (const connection of connections) {
15
+ const driver = (() => {
16
+ if (typeof connection === "string") {
17
+ if (connection.startsWith("postgres://") || connection.startsWith("postgresql://")) return "postgres";
18
+ if (connection.startsWith("mysql://") || connection.startsWith("mysql2://")) return "mysql";
19
+ return "sqlite";
20
+ }
21
+ return connection.driver ?? "sqlite";
22
+ })();
23
+ if (!(driver in packageByDriver)) throw new Error(`Unsupported Holo database driver "${driver}".`);
24
+ drivers.add(driver);
25
+ }
26
+ const require2 = createRequire(join(projectRoot, "package.json"));
27
+ const factories = [];
28
+ for (const driver of drivers) {
29
+ const { packageName, factoryExport } = packageByDriver[driver];
30
+ const module = await import(pathToFileURL(require2.resolve(packageName)).href);
31
+ const factory = module[factoryExport];
32
+ if (!factory) throw new Error(`Database driver package ${packageName} does not export ${factoryExport}.`);
33
+ registerDatabaseDriverFactory(factory);
34
+ factories.push(factory);
35
+ }
36
+ return factories;
37
+ }
38
+
39
+ export {
40
+ loadProjectDatabaseDrivers
41
+ };