@xrystal/core 3.53.0 → 3.53.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.
Files changed (32) hide show
  1. package/package.json +1 -1
  2. package/x/bin/commands/create.mjs +6 -1
  3. package/x/bin/commands/project-info.mjs +2 -1
  4. package/x/bin/commands/sync.mjs +16 -8
  5. package/x/bin/commands/tmp.mjs +5 -4
  6. package/x/bin/helpers/.generated/workspace.mjs +110 -28
  7. package/x/bin/helpers/.generated/xrystal-home-registry.mjs +119 -37
  8. package/x/bin/helpers/cli-context-guard.mjs +2 -1
  9. package/x/bin/helpers/cli-enums.mjs +33 -0
  10. package/x/bin/helpers/create-target.mjs +3 -2
  11. package/x/bin/helpers/project-context.mjs +18 -10
  12. package/x/bin/helpers/tmp-config.mjs +6 -5
  13. package/x/bin/helpers/workspace-heal.mjs +30 -0
  14. package/x/bin/helpers/workspace-resolve.mjs +2 -0
  15. package/x/bin/helpers/workspace-scaffold.mjs +4 -3
  16. package/x/bin/helpers/workspace-tmp.mjs +2 -0
  17. package/x/bin/helpers/xrystal-registry.mjs +1 -0
  18. package/x/dist/loader/mongo/index.js +2 -1
  19. package/x/dist/loader/redis/index.js +2 -1
  20. package/x/dist/project/index.js +5 -4
  21. package/x/dist/utils/helpers/loader-options/index.d.ts +5 -1
  22. package/x/dist/utils/helpers/loader-options/index.js +15 -0
  23. package/x/dist/utils/helpers/tmp/index.d.ts +1 -1
  24. package/x/dist/utils/helpers/tmp/index.js +1 -1
  25. package/x/dist/utils/helpers/tmp/loader-boot-plan.d.ts +7 -6
  26. package/x/dist/utils/helpers/tmp/loader-boot-plan.js +27 -16
  27. package/x/dist/utils/helpers/workspace/index.d.ts +7 -7
  28. package/x/dist/utils/helpers/workspace/index.js +47 -12
  29. package/x/dist/utils/helpers/xrystal-home/registry.d.ts +7 -0
  30. package/x/dist/utils/helpers/xrystal-home/registry.js +32 -3
  31. package/x/dist/utils/models/enums/index.d.ts +26 -0
  32. package/x/dist/utils/models/enums/index.js +30 -0
@@ -1,11 +1,11 @@
1
1
  // source/utils/helpers/xrystal-home/registry.ts
2
2
  import fs3 from "node:fs";
3
3
  import os from "node:os";
4
- import path3 from "node:path";
4
+ import path5 from "node:path";
5
5
 
6
6
  // source/utils/helpers/workspace/index.ts
7
7
  import fs2 from "node:fs";
8
- import path2 from "node:path";
8
+ import path4 from "node:path";
9
9
 
10
10
  // source/utils/models/enums/index.ts
11
11
  var GlobalTypeEnum;
@@ -14,6 +14,16 @@ var GlobalTypeEnum;
14
14
  GlobalTypeEnum2["API_SERVICE"] = "api-service";
15
15
  GlobalTypeEnum2["FRONTEND"] = "frontend";
16
16
  })(GlobalTypeEnum ||= {});
17
+
18
+ // source/utils/constants/index.ts
19
+ import path3 from "node:path";
20
+
21
+ // source/utils/constants/package-root.ts
22
+ import path from "node:path";
23
+ import { fileURLToPath } from "node:url";
24
+ var constantsDir = path.dirname(fileURLToPath(import.meta.url));
25
+ var sourceDir = path.resolve(constantsDir, "..", "..");
26
+ var packageRootDir = path.resolve(constantsDir, "..", "..", "..");
17
27
  // source/utils/constants/defaults.json
18
28
  var defaults_default = {
19
29
  packageName: "@xrystal/core",
@@ -86,8 +96,8 @@ var defaults_default = {
86
96
 
87
97
  // source/utils/helpers/tmp/seed-from-tmp.ts
88
98
  import fs from "node:fs";
89
- import path from "node:path";
90
- import { fileURLToPath } from "node:url";
99
+ import path2 from "node:path";
100
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
91
101
  import yaml from "yaml";
92
102
 
93
103
  // source/utils/helpers/tmp/path-normalize.ts
@@ -106,7 +116,7 @@ function normalizeSourceFolder(value, fallback) {
106
116
  }
107
117
 
108
118
  // source/utils/helpers/tmp/seed-from-tmp.ts
109
- var here = path.dirname(fileURLToPath(import.meta.url));
119
+ var here = path2.dirname(fileURLToPath2(import.meta.url));
110
120
  var templateRel = defaults_default.apiServiceTemplateRel ?? "x/templates/api-service/tmp.yml";
111
121
  function requireString(value, label) {
112
122
  if (typeof value !== "string" || !value.trim()) {
@@ -123,14 +133,14 @@ function readLayoutFromSpecial(special) {
123
133
  };
124
134
  }
125
135
  function findApiTemplate() {
126
- const starts = [here, process.cwd()].map((value) => path.resolve(value));
136
+ const starts = [here, process.cwd()].map((value) => path2.resolve(value));
127
137
  for (const start of starts) {
128
138
  let dir = start;
129
139
  for (;; ) {
130
- const candidate = path.join(dir, templateRel);
140
+ const candidate = path2.join(dir, templateRel);
131
141
  if (fs.existsSync(candidate))
132
142
  return candidate;
133
- const parent = path.dirname(dir);
143
+ const parent = path2.dirname(dir);
134
144
  if (parent === dir)
135
145
  break;
136
146
  dir = parent;
@@ -159,6 +169,42 @@ function loadSeedFromBundledTmp(tmpFilePath) {
159
169
  }
160
170
  var seedFromTmp = loadSeedFromBundledTmp();
161
171
 
172
+ // source/utils/constants/index.ts
173
+ var packageDefaults = Object.freeze({
174
+ ...defaults_default,
175
+ mainSourceFolder: seedFromTmp.sourceFolder,
176
+ framework: seedFromTmp.framework,
177
+ layoutPaths: Object.freeze({ ...seedFromTmp.layout }),
178
+ brand: Object.freeze({ ...defaults_default.brand }),
179
+ runtimes: Object.freeze(Object.fromEntries(Object.entries(defaults_default.runtimes).map(([key, value]) => [key, Object.freeze({ ...value })]))),
180
+ bundlers: Object.freeze([...defaults_default.bundlers]),
181
+ buildDefaults: Object.freeze({ ...defaults_default.buildDefaults }),
182
+ tmpWatchDefaults: Object.freeze({ ...defaults_default.tmpWatchDefaults }),
183
+ cliBinNames: Object.freeze([...defaults_default.cliBinNames ?? [defaults_default.cliName]])
184
+ });
185
+ var tmpFileName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;
186
+
187
+ class Constants {
188
+ static packageName = packageDefaults.packageName;
189
+ static packageRootFolder = packageDefaults.packageRootFolder;
190
+ static tmpBaseName = packageDefaults.tmpBaseName;
191
+ static tmpExtension = packageDefaults.tmpExtension;
192
+ static publicFolderName = packageDefaults.publicFolderName;
193
+ static kafkaLogsTopic = packageDefaults.kafkaLogsTopic;
194
+ static templateRepoUri = packageDefaults.templateRepoUri;
195
+ static cliName = packageDefaults.cliName;
196
+ static cliBinNames = packageDefaults.cliBinNames;
197
+ static pathAliasKey = packageDefaults.pathAliasKey;
198
+ static brand = packageDefaults.brand;
199
+ static mainSourceFolder = packageDefaults.mainSourceFolder;
200
+ static framework = packageDefaults.framework;
201
+ static layoutPaths = packageDefaults.layoutPaths;
202
+ static cliBinFile = packageDefaults.cliBinFile;
203
+ static logTag = packageDefaults.packageName;
204
+ static bundledApiServiceTmpPath = path3.join(packageRootDir, packageDefaults.apiServiceTemplateRel ?? `${packageDefaults.packageRootFolder}/templates/api-service/${tmpFileName}`);
205
+ static bundledCoreTmpPath = path3.join(packageRootDir, packageDefaults.packageRootFolder, tmpFileName);
206
+ }
207
+
162
208
  // source/utils/helpers/tmp/tmp-interpolate.ts
163
209
  import Handlebars from "handlebars";
164
210
 
@@ -180,9 +226,9 @@ function normalizeGlobalType(value) {
180
226
  var TMP_FILE = "tmp.yml";
181
227
  var SKIP_DIRS = new Set(["node_modules", ".git", "dist", ".turbo", "coverage"]);
182
228
  var DEFAULT_FOLDER_STRUCTURE = {
183
- api: "api",
184
- admin: "admin",
185
- web: "web"
229
+ ["api" /* API */]: "api",
230
+ ["web" /* WEB */]: "web",
231
+ ["mobile" /* MOBILE */]: "mobile"
186
232
  };
187
233
  function parseScalar(raw) {
188
234
  const trimmed = raw.trim();
@@ -216,18 +262,28 @@ function readTmpFile(filePath) {
216
262
  }
217
263
  function parseFolderStructure(text) {
218
264
  const fsBlock = text.match(/folder-structure:\s*\n((?:[ \t]+[^\n]+\n?)*)/)?.[1] ?? "";
265
+ if (/^[ \t]+admin:/m.test(fsBlock)) {
266
+ throw new Error("configs.folder-structure.admin removed — put admin panels under web/ (e.g. web/admin-ui)");
267
+ }
219
268
  const readSlot = (key) => {
220
- const scalar = fsBlock.match(new RegExp(`^[ ]+${key}:s*(.+?)(?:s+#.*)?$`, "m"));
269
+ const scalar = fsBlock.match(new RegExp(`^[ \\t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, "m"));
221
270
  if (scalar)
222
271
  return parseScalar(scalar[1]);
223
272
  return DEFAULT_FOLDER_STRUCTURE[key];
224
273
  };
225
274
  return {
226
- api: readSlot("api"),
227
- admin: readSlot("admin"),
228
- web: readSlot("web")
275
+ ["api" /* API */]: readSlot("api" /* API */),
276
+ ["web" /* WEB */]: readSlot("web" /* WEB */),
277
+ ["mobile" /* MOBILE */]: readSlot("mobile" /* MOBILE */)
229
278
  };
230
279
  }
280
+ function workspaceDiscoverySlots(fsMap) {
281
+ return [
282
+ { slot: "api" /* API */, folder: fsMap["api" /* API */], frontendOnly: false },
283
+ { slot: "web" /* WEB */, folder: fsMap["web" /* WEB */], frontendOnly: true },
284
+ { slot: "mobile" /* MOBILE */, folder: fsMap["mobile" /* MOBILE */], frontendOnly: true }
285
+ ];
286
+ }
231
287
  function entryName(meta) {
232
288
  const project = (meta.projectName ?? "").trim();
233
289
  return project || null;
@@ -241,20 +297,20 @@ function entryType(meta, slot) {
241
297
  return null;
242
298
  }
243
299
  }
244
- if (slot === "api")
300
+ if (slot === "api" /* API */)
245
301
  return "api-service" /* API_SERVICE */;
246
302
  return null;
247
303
  }
248
304
  function findWorkspaceRoot(startDir = process.cwd()) {
249
- let cur = path2.resolve(startDir);
305
+ let cur = path4.resolve(startDir);
250
306
  for (;; ) {
251
- const candidate = path2.join(cur, TMP_FILE);
307
+ const candidate = path4.join(cur, TMP_FILE);
252
308
  if (fs2.existsSync(candidate)) {
253
309
  const meta = readTmpFile(candidate);
254
310
  if (meta.globalType === "workspace" /* WORKSPACE */)
255
311
  return cur;
256
312
  }
257
- const parent = path2.dirname(cur);
313
+ const parent = path4.dirname(cur);
258
314
  if (parent === cur)
259
315
  break;
260
316
  cur = parent;
@@ -287,7 +343,7 @@ function walkTmpUnder(rootDir) {
287
343
  continue;
288
344
  }
289
345
  for (const entry of entries) {
290
- const full = path2.join(dir, entry.name);
346
+ const full = path4.join(dir, entry.name);
291
347
  if (isTraversableDir(entry, full)) {
292
348
  if (SKIP_DIRS.has(entry.name) || entry.name.startsWith("."))
293
349
  continue;
@@ -314,21 +370,20 @@ function repoRootFromTmp(tmpPath, meta) {
314
370
  throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
315
371
  }
316
372
  function findEntries(workspaceRoot) {
317
- const wsMeta = readTmpFile(path2.join(workspaceRoot, TMP_FILE));
373
+ const wsMeta = readTmpFile(path4.join(workspaceRoot, TMP_FILE));
318
374
  const fsMap = wsMeta.folderStructure;
319
375
  const entries = [];
320
376
  const seen = new Set;
321
- const slots = ["api", "admin", "web"];
322
- for (const slot of slots) {
323
- const folder = path2.join(workspaceRoot, fsMap[slot]);
377
+ for (const { slot, folder: folderRel, frontendOnly } of workspaceDiscoverySlots(fsMap)) {
378
+ const folder = path4.join(workspaceRoot, folderRel);
324
379
  for (const tmpPath of walkTmpUnder(folder)) {
325
- if (path2.resolve(tmpPath) === path2.join(workspaceRoot, TMP_FILE))
380
+ if (path4.resolve(tmpPath) === path4.join(workspaceRoot, TMP_FILE))
326
381
  continue;
327
382
  const meta = readTmpFile(tmpPath);
328
383
  const kind = entryType(meta, slot);
329
384
  if (kind === "workspace" /* WORKSPACE */)
330
385
  continue;
331
- if (slot !== "api" && kind !== "frontend" /* FRONTEND */)
386
+ if (frontendOnly && kind !== "frontend" /* FRONTEND */)
332
387
  continue;
333
388
  if (kind !== "api-service" /* API_SERVICE */ && kind !== "frontend" /* FRONTEND */)
334
389
  continue;
@@ -355,14 +410,14 @@ function findEntries(workspaceRoot) {
355
410
  // source/utils/helpers/xrystal-home/registry.ts
356
411
  var XRYSTAL_HOME_DIR = ".xrystal";
357
412
  function resolveXrystalHome() {
358
- return path3.join(os.homedir(), XRYSTAL_HOME_DIR);
413
+ return path5.join(os.homedir(), XRYSTAL_HOME_DIR);
359
414
  }
360
415
  function registryFilePath() {
361
- return path3.join(resolveXrystalHome(), "registry.json");
416
+ return path5.join(resolveXrystalHome(), "registry.json");
362
417
  }
363
418
  function ensureXrystalHome() {
364
419
  const home = resolveXrystalHome();
365
- fs3.mkdirSync(path3.join(home, "workspaces"), { recursive: true });
420
+ fs3.mkdirSync(path5.join(home, "workspaces"), { recursive: true });
366
421
  return home;
367
422
  }
368
423
  function entryToRegistryProject(entry) {
@@ -375,7 +430,7 @@ function entryToRegistryProject(entry) {
375
430
  };
376
431
  }
377
432
  function normalizeRegistryPath(input) {
378
- const resolved = path3.resolve(input);
433
+ const resolved = path5.resolve(input);
379
434
  try {
380
435
  return fs3.realpathSync.native(resolved);
381
436
  } catch {
@@ -385,7 +440,7 @@ function normalizeRegistryPath(input) {
385
440
  function scanWorkspace(workspacePath, workspaceName) {
386
441
  const root = normalizeRegistryPath(workspacePath);
387
442
  const entries = findEntries(root);
388
- const name = workspaceName ?? path3.basename(root);
443
+ const name = workspaceName ?? path5.basename(root);
389
444
  return {
390
445
  name,
391
446
  path: root,
@@ -407,12 +462,12 @@ function writeRegistry(registry) {
407
462
  fs3.writeFileSync(registryFilePath(), `${JSON.stringify(registry, null, 2)}
408
463
  `);
409
464
  for (const ws of registry.workspaces) {
410
- const wsDir = path3.join(resolveXrystalHome(), "workspaces", ws.name);
465
+ const wsDir = path5.join(resolveXrystalHome(), "workspaces", ws.name);
411
466
  fs3.mkdirSync(wsDir, { recursive: true });
412
- fs3.writeFileSync(path3.join(wsDir, "workspace.json"), `${JSON.stringify(ws, null, 2)}
467
+ fs3.writeFileSync(path5.join(wsDir, "workspace.json"), `${JSON.stringify(ws, null, 2)}
413
468
  `);
414
469
  for (const project of ws.projects) {
415
- fs3.writeFileSync(path3.join(wsDir, `${project.name}.json`), `${JSON.stringify(project, null, 2)}
470
+ fs3.writeFileSync(path5.join(wsDir, `${project.name}.json`), `${JSON.stringify(project, null, 2)}
416
471
  `);
417
472
  }
418
473
  }
@@ -429,11 +484,37 @@ function syncRegistryFromPath(startDir = process.cwd()) {
429
484
  if (!workspaceRoot) {
430
485
  throw new Error("No workspace tmp.yml found — run xry create demo --workspace first");
431
486
  }
432
- const scanned = scanWorkspace(workspaceRoot);
433
- const registry = upsertWorkspace(readRegistry(), scanned);
434
- writeRegistry(registry);
487
+ const { registry } = healRegistryAtPath(workspaceRoot, { force: true });
435
488
  return registry;
436
489
  }
490
+ function projectsFingerprint(projects) {
491
+ return JSON.stringify([...projects].sort((a, b) => a.path.localeCompare(b.path) || a.name.localeCompare(b.name)));
492
+ }
493
+ function healRegistryAtPath(workspaceRoot, { force = false } = {}) {
494
+ const root = normalizeRegistryPath(workspaceRoot);
495
+ let registry = readRegistry();
496
+ const beforeLen = registry.workspaces.length;
497
+ registry = {
498
+ ...registry,
499
+ workspaces: registry.workspaces.filter((ws) => {
500
+ try {
501
+ return fs3.existsSync(normalizeRegistryPath(ws.path));
502
+ } catch {
503
+ return false;
504
+ }
505
+ })
506
+ };
507
+ const pruned = registry.workspaces.length !== beforeLen;
508
+ const scanned = scanWorkspace(root);
509
+ const existing = registry.workspaces.find((ws) => normalizeRegistryPath(ws.path) === root);
510
+ const projectsChanged = !existing || projectsFingerprint(existing.projects) !== projectsFingerprint(scanned.projects);
511
+ if (force || pruned || projectsChanged) {
512
+ registry = upsertWorkspace(registry, scanned);
513
+ writeRegistry(registry);
514
+ return { changed: true, registry };
515
+ }
516
+ return { changed: false, registry };
517
+ }
437
518
  function listRegistryProjects(registry = readRegistry()) {
438
519
  const rows = [];
439
520
  for (const ws of registry.workspaces) {
@@ -452,6 +533,7 @@ export {
452
533
  registryFilePath,
453
534
  readRegistry,
454
535
  listRegistryProjects,
536
+ healRegistryAtPath,
455
537
  entryToRegistryProject,
456
538
  ensureXrystalHome,
457
539
  XRYSTAL_HOME_DIR
@@ -4,6 +4,7 @@ import path from 'node:path'
4
4
  import chalk from 'chalk'
5
5
 
6
6
  import { resolveProjectContext } from './project-context.mjs'
7
+ import { ProjectScopeKindEnum } from './cli-enums.mjs'
7
8
 
8
9
  export class CliContextError extends Error {
9
10
  constructor(message, { hints = [] } = {}) {
@@ -20,7 +21,7 @@ export function getCliContext(startDir = process.cwd()) {
20
21
  export function requireServiceRoot(startDir = process.cwd(), { cliName = 'xry', command = 'dev' } = {}) {
21
22
  const ctx = getCliContext(startDir)
22
23
 
23
- if (ctx.kind === 'workspace-root') {
24
+ if (ctx.kind === ProjectScopeKindEnum.WORKSPACE_ROOT) {
24
25
  const examples = (ctx.workspaceEntries ?? [])
25
26
  .slice(0, 3)
26
27
  .map((entry) => {
@@ -0,0 +1,33 @@
1
+ /** Mirrors source/utils/models/enums — keep in sync with TS enums. */
2
+
3
+ export const GlobalTypeEnum = {
4
+ WORKSPACE: 'workspace',
5
+ API_SERVICE: 'api-service',
6
+ FRONTEND: 'frontend',
7
+ }
8
+
9
+ export const ProjectScopeKindEnum = {
10
+ CORE_LIBRARY: 'core-library',
11
+ WORKSPACE_ROOT: 'workspace-root',
12
+ WORKSPACE_SERVICE: 'workspace-service',
13
+ STANDALONE_SERVICE: 'standalone-service',
14
+ }
15
+
16
+ export const WorkspaceSlotEnum = {
17
+ API: 'api',
18
+ WEB: 'web',
19
+ MOBILE: 'mobile',
20
+ }
21
+
22
+ export const LoaderBootProfileEnum = {
23
+ API_SERVICE: 'api-service',
24
+ FRONTEND: 'frontend',
25
+ WORKSPACE: 'workspace',
26
+ MINIMAL: 'minimal',
27
+ }
28
+
29
+ export const InfraLoaderEnum = {
30
+ KAFKA: 'kafka',
31
+ REDIS: 'redis',
32
+ MONGO: 'mongo',
33
+ }
@@ -6,6 +6,7 @@ import {
6
6
  findWorkspaceRoot,
7
7
  readTmpFile,
8
8
  } from './workspace-resolve.mjs'
9
+ import { WorkspaceSlotEnum } from './cli-enums.mjs'
9
10
 
10
11
  function resolveReal(input) {
11
12
  const resolved = path.resolve(input)
@@ -24,9 +25,9 @@ function resolveReal(input) {
24
25
  *
25
26
  * @param {string} projectName Folder name or `.` for current directory
26
27
  * @param {string | undefined} targetDir Optional parent path (default: cwd)
27
- * @param {{ slot?: 'api' | 'web' | 'mobile' }} options
28
+ * @param {{ slot?: import('./cli-enums.mjs').WorkspaceSlotEnum[keyof import('./cli-enums.mjs').WorkspaceSlotEnum] }} options
28
29
  */
29
- export function resolveCreateTarget(projectName, targetDir, { slot = 'api' } = {}) {
30
+ export function resolveCreateTarget(projectName, targetDir, { slot = WorkspaceSlotEnum.API } = {}) {
30
31
  const cwd = process.cwd()
31
32
  const name = String(projectName ?? '').trim()
32
33
 
@@ -7,8 +7,8 @@ import { isCorePackageRoot } from './tmp-layout.mjs'
7
7
  import { findEntries, findWorkspaceRoot, workspaceProjectName } from './workspace-resolve.mjs'
8
8
  import { getInstalledCoreVersion, readCliPackageJson, readProjectPackageJson, resolveProjectRoot } from './project-root.mjs'
9
9
  import { readTmpSchemaVersion, TMP_SCHEMA_VERSION } from './tmp-schema-version.mjs'
10
-
11
- const WORKSPACE_TYPE = 'workspace'
10
+ import { GlobalTypeEnum, ProjectScopeKindEnum } from './cli-enums.mjs'
11
+ import { runWorkspaceSelfHeal } from './workspace-heal.mjs'
12
12
 
13
13
  function readTmpMeta(tmpFilePath) {
14
14
  if (!tmpFilePath || !fs.existsSync(tmpFilePath)) return null
@@ -46,7 +46,7 @@ export function resolveProjectContext(startDir = process.cwd()) {
46
46
  const innerTmpPath = path.join(coreRoot, packageDefaults.packageRootFolder, `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`)
47
47
  const innerMeta = readTmpMeta(fs.existsSync(innerTmpPath) ? innerTmpPath : null)
48
48
  return {
49
- kind: 'core-library',
49
+ kind: ProjectScopeKindEnum.CORE_LIBRARY,
50
50
  label: '@xrystal/core (library source)',
51
51
  cwd,
52
52
  projectRoot: coreRoot,
@@ -92,27 +92,35 @@ export function resolveProjectContext(startDir = process.cwd()) {
92
92
  }
93
93
  const innerMeta = innerTmpPath ? readTmpMeta(innerTmpPath) : null
94
94
 
95
- let kind = 'standalone-service'
95
+ let kind = ProjectScopeKindEnum.STANDALONE_SERVICE
96
96
  let label = 'Standalone service'
97
- if (atWorkspaceRoot && outerMeta?.globalType === WORKSPACE_TYPE) {
98
- kind = 'workspace-root'
97
+ if (atWorkspaceRoot && outerMeta?.globalType === GlobalTypeEnum.WORKSPACE) {
98
+ kind = ProjectScopeKindEnum.WORKSPACE_ROOT
99
99
  label = 'Workspace root (outer tmp.yml)'
100
- } else if (workspaceRoot && outerMeta?.globalType === WORKSPACE_TYPE) {
101
- kind = 'workspace-service'
100
+ } else if (workspaceRoot && outerMeta?.globalType === GlobalTypeEnum.WORKSPACE) {
101
+ kind = ProjectScopeKindEnum.WORKSPACE_SERVICE
102
102
  label = 'Workspace linked service (inner x/tmp.yml)'
103
103
  }
104
104
 
105
+ if (workspaceRoot && outerMeta?.globalType === GlobalTypeEnum.WORKSPACE) {
106
+ try {
107
+ runWorkspaceSelfHeal(workspaceRoot, { ensureTmp: false })
108
+ } catch {
109
+ // layout/registry heal is best-effort during context resolution
110
+ }
111
+ }
112
+
105
113
  const workspaceEntries = workspaceRoot ? findEntries(workspaceRoot) : []
106
114
  const selfEntry = workspaceEntries.find((e) => path.resolve(e.path) === path.resolve(projectRoot))
107
115
 
108
116
  const hints = []
109
- if (kind === 'workspace-root') {
117
+ if (kind === ProjectScopeKindEnum.WORKSPACE_ROOT) {
110
118
  hints.push('Outer tmp: ./tmp.yml · inner tmp: each api|web|mobile project (admin → web/)')
111
119
  hints.push('xry sync — all linked projects + ~/.xrystal registry')
112
120
  hints.push('xry create <name> — adds api/<name> (or --web / --mobile)')
113
121
  hints.push('dev/build/start — run inside a linked service, not here')
114
122
  hints.push('xry workspaces — global registry (~/.xrystal), not repo tmp files')
115
- } else if (kind === 'workspace-service') {
123
+ } else if (kind === ProjectScopeKindEnum.WORKSPACE_SERVICE) {
116
124
  hints.push(`Outer workspace: ${workspaceRoot}`)
117
125
  hints.push('xry sync — this service only (tsconfig + @xrystal/core pin)')
118
126
  hints.push('xry sync --all — every linked api/web/mobile project + registry')
@@ -1,5 +1,6 @@
1
1
  import { readTmpDependsBlock, readTmpGlobalBlock } from './tmp-schema.mjs'
2
2
  import { packageDefaults } from './package-defaults.mjs'
3
+ import { GlobalTypeEnum, InfraLoaderEnum } from './cli-enums.mjs'
3
4
  const PROTOCOL_ALIASES = {
4
5
  http: 'http',
5
6
  https: 'https',
@@ -30,11 +31,11 @@ function summarizeInfraLoaders(depends) {
30
31
  return fallback
31
32
  }
32
33
  const type = depends?.globalType ?? null
33
- const isFrontend = type === 'frontend'
34
+ const isFrontend = type === GlobalTypeEnum.FRONTEND
34
35
  return {
35
- kafka: readEnabled('kafka', !isFrontend),
36
- redis: readEnabled('redis', !isFrontend),
37
- mongo: readEnabled('mongo', !isFrontend),
36
+ [InfraLoaderEnum.KAFKA]: readEnabled(InfraLoaderEnum.KAFKA, !isFrontend),
37
+ [InfraLoaderEnum.REDIS]: readEnabled(InfraLoaderEnum.REDIS, !isFrontend),
38
+ [InfraLoaderEnum.MONGO]: readEnabled(InfraLoaderEnum.MONGO, !isFrontend),
38
39
  }
39
40
  }
40
41
 
@@ -81,7 +82,7 @@ export function formatLoaderSummary(summary) {
81
82
  `protocols: ${summary.protocols.join(', ')}`,
82
83
  ]
83
84
  if (summary.infra) {
84
- const flags = ['kafka', 'redis', 'mongo']
85
+ const flags = [InfraLoaderEnum.KAFKA, InfraLoaderEnum.REDIS, InfraLoaderEnum.MONGO]
85
86
  .map((key) => `${key}:${summary.infra[key] ? 'on' : 'off'}`)
86
87
  .join(' · ')
87
88
  lines.push(`infra: ${flags}`)
@@ -0,0 +1,30 @@
1
+ import {
2
+ ensureWorkspaceSlotDirs,
3
+ healWorkspaceOuterTmpOptions,
4
+ } from './workspace-resolve.mjs'
5
+ import { healRegistryAtPath } from './xrystal-registry.mjs'
6
+ import { ensureOuterWorkspaceTmp } from './workspace-tmp.mjs'
7
+
8
+ /**
9
+ * Workspace self-heal: slot dirs, outer tmp options, ~/.xrystal registry.
10
+ * Runs automatically on sync / project context — no explicit CLI flag required.
11
+ */
12
+ export function runWorkspaceSelfHeal(workspaceRoot, {
13
+ ensureTmp = true,
14
+ healRegistry = true,
15
+ forceRegistry = false,
16
+ } = {}) {
17
+ if (ensureTmp) {
18
+ ensureOuterWorkspaceTmp(workspaceRoot)
19
+ }
20
+
21
+ const slotDirsCreated = ensureWorkspaceSlotDirs(workspaceRoot)
22
+ const tmpOptionsPatched = healWorkspaceOuterTmpOptions(workspaceRoot)
23
+
24
+ let registryChanged = false
25
+ if (healRegistry) {
26
+ registryChanged = healRegistryAtPath(workspaceRoot, { force: forceRegistry }).changed
27
+ }
28
+
29
+ return { slotDirsCreated, tmpOptionsPatched, registryChanged }
30
+ }
@@ -1,8 +1,10 @@
1
1
  export {
2
2
  DEFAULT_FOLDER_STRUCTURE,
3
+ ensureWorkspaceSlotDirs,
3
4
  findApiServices,
4
5
  findEntries,
5
6
  findWorkspaceRoot,
7
+ healWorkspaceOuterTmpOptions,
6
8
  normalizeGlobalType,
7
9
  parseFolderStructure,
8
10
  readTmpFile,
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
- import { DEFAULT_FOLDER_STRUCTURE, workspaceTmpTemplate } from './workspace-resolve.mjs'
4
+ import { readTmpFile, workspaceTmpTemplate } from './workspace-resolve.mjs'
5
5
  import { scaffoldServiceFromTemplate } from './scaffold-service.mjs'
6
6
  import { ensureServiceTelepresenceEnv, writeWorkspaceTelepresenceFiles } from './telepresence-layout.mjs'
7
7
  import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
@@ -28,13 +28,14 @@ export function scaffoldWorkspace(targetPath, projectName, {
28
28
 
29
29
  writeWorkspaceTelepresenceFiles(resolved)
30
30
 
31
- for (const dir of Object.values(DEFAULT_FOLDER_STRUCTURE)) {
31
+ const fsMap = readTmpFile(tmpPath).folderStructure
32
+ for (const dir of Object.values(fsMap)) {
32
33
  fs.mkdirSync(path.join(resolved, dir), { recursive: true })
33
34
  }
34
35
 
35
36
  let general = null
36
37
  if (scaffoldGeneral) {
37
- const generalPath = path.join(resolved, DEFAULT_FOLDER_STRUCTURE.api, 'general')
38
+ const generalPath = path.join(resolved, fsMap.api, 'general')
38
39
  general = scaffoldServiceFromTemplate(generalPath, {
39
40
  projectName: 'general',
40
41
  templateRepoUri,
@@ -3,6 +3,7 @@ import path from 'node:path'
3
3
 
4
4
  import { ensureTmpSchemaVersion } from './tmp-schema-version.mjs'
5
5
  import { workspaceProjectName, workspaceTmpTemplate } from './workspace-resolve.mjs'
6
+ import { runWorkspaceSelfHeal } from './workspace-heal.mjs'
6
7
 
7
8
  export function ensureOuterWorkspaceTmp(workspaceRoot, { projectName } = {}) {
8
9
  const resolved = path.resolve(workspaceRoot)
@@ -16,5 +17,6 @@ export function ensureOuterWorkspaceTmp(workspaceRoot, { projectName } = {}) {
16
17
  }
17
18
 
18
19
  const schema = ensureTmpSchemaVersion(tmpPath)
20
+ runWorkspaceSelfHeal(resolved, { ensureTmp: false })
19
21
  return { tmpFilePath: tmpPath, created, schema, workspaceRoot: resolved }
20
22
  }
@@ -1,6 +1,7 @@
1
1
  export {
2
2
  ensureXrystalHome,
3
3
  entryToRegistryProject,
4
+ healRegistryAtPath,
4
5
  listRegistryProjects,
5
6
  readRegistry,
6
7
  registryFilePath,
@@ -2,6 +2,7 @@ export { resolveMongoConnectOptions } from './resolve-connect.js';
2
2
  import { MongoClient } from 'mongodb';
3
3
  import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
4
4
  import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
5
+ import { InfraLoaderEnum } from '../../utils/models/enums/index.js';
5
6
  import { resolveMongoConnectOptions } from './resolve-connect.js';
6
7
  export default class MongoForCore {
7
8
  #client = null;
@@ -26,7 +27,7 @@ export default class MongoForCore {
26
27
  syncFromTmp = async () => {
27
28
  await this.teardown();
28
29
  const loaders = this.#resolveDependsLoaders();
29
- if (!readInfraLoaderEnabled(loaders, 'mongo', true)) {
30
+ if (!readInfraLoaderEnabled(loaders, InfraLoaderEnum.MONGO, true)) {
30
31
  return;
31
32
  }
32
33
  if (this.#configs.all.isMongoPassive) {
@@ -2,6 +2,7 @@ export { resolveRedisSocketOptions } from './resolve-socket.js';
2
2
  import { createClient } from 'redis';
3
3
  import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
4
4
  import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
5
+ import { InfraLoaderEnum } from '../../utils/models/enums/index.js';
5
6
  import { resolveRedisSocketOptions } from './resolve-socket.js';
6
7
  export default class RedisForCore {
7
8
  #client = null;
@@ -25,7 +26,7 @@ export default class RedisForCore {
25
26
  syncFromTmp = async () => {
26
27
  await this.teardown();
27
28
  const loaders = this.#resolveDependsLoaders();
28
- if (!readInfraLoaderEnabled(loaders, 'redis', true)) {
29
+ if (!readInfraLoaderEnabled(loaders, InfraLoaderEnum.REDIS, true)) {
29
30
  return;
30
31
  }
31
32
  if (this.#configs.all.isRedisPassive) {
@@ -4,7 +4,8 @@ import { System, Configs, Logger, Events, Localizations, DtoRuntime, Clients, Co
4
4
  import { Constants, getCore, x } from '../utils/index.js';
5
5
  import { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
6
6
  import { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
7
- import { resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan.js';
7
+ import { isInfraLoaderEnabled, resolveLoaderBootPlan } from '../utils/helpers/tmp/loader-boot-plan.js';
8
+ import { InfraLoaderEnum } from '../utils/models/enums/index.js';
8
9
  import { resolveTmpRuntimeConfigs } from '../utils/helpers/tmp/tmp-schema.js';
9
10
  export { ensureCoreTmpEntry, isCorePackageRoot } from '../utils/helpers/core/tmp-layout.js';
10
11
  export { getTmpSnapshot } from '../utils/helpers/tmp/tmp-loader.js';
@@ -24,11 +25,11 @@ function buildLoaderInitList(plan, coreRef) {
24
25
  { service: System, props: { core: coreRef } },
25
26
  { service: Configs, props: {} },
26
27
  ];
27
- if (plan.kafka)
28
+ if (isInfraLoaderEnabled(plan, InfraLoaderEnum.KAFKA))
28
29
  entries.push({ service: KafkaForCore, props: {} });
29
- if (plan.redis)
30
+ if (isInfraLoaderEnabled(plan, InfraLoaderEnum.REDIS))
30
31
  entries.push({ service: RedisForCore, props: {} });
31
- if (plan.mongo)
32
+ if (isInfraLoaderEnabled(plan, InfraLoaderEnum.MONGO))
32
33
  entries.push({ service: MongoForCore, props: {} });
33
34
  entries.push({ service: Logger, props: {} }, { service: Events, props: {} }, { service: Localizations, props: {} }, { service: DtoRuntime, props: {} }, { service: Controller, props: {} }, { service: Clients, props: {} });
34
35
  return entries;
@@ -1,5 +1,9 @@
1
+ import { InfraLoaderEnum } from '../../../utils/models/enums';
1
2
  export type InfraLoaderOptions = {
2
3
  enabled: boolean;
3
4
  };
4
- export declare function readInfraLoaderEnabled(loaders: Record<string, unknown> | undefined, key: string, defaultEnabled: boolean): boolean;
5
+ export type InfraLoaderFlags = Record<InfraLoaderEnum, boolean>;
6
+ export declare function createInfraLoaderFlags(overrides?: Partial<InfraLoaderFlags>): InfraLoaderFlags;
7
+ export declare function readInfraLoaderEnabled(loaders: Record<string, unknown> | undefined, key: InfraLoaderEnum, defaultEnabled: boolean): boolean;
8
+ export declare function readInfraLoaderFlags(loaders: Record<string, unknown> | undefined, defaults: InfraLoaderFlags): InfraLoaderFlags;
5
9
  export { readKafkaLoaderOptions, type KafkaLoaderOptions } from '../../../utils/helpers/kafka-loader-options';