@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.53.0",
4
+ "version": "3.53.2",
5
5
  "description": "microservice runtime library",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -90,7 +90,12 @@ export function registerCreateCommand(cli, { cliName = CLI_PRIMARY_NAME, runtime
90
90
  return
91
91
  }
92
92
 
93
- const slot = options.mobile ? 'mobile' : options.web ? 'web' : 'api'
93
+ const { WorkspaceSlotEnum } = await import('../helpers/cli-enums.mjs')
94
+ const slot = options.mobile
95
+ ? WorkspaceSlotEnum.MOBILE
96
+ : options.web
97
+ ? WorkspaceSlotEnum.WEB
98
+ : WorkspaceSlotEnum.API
94
99
 
95
100
  let targetPath
96
101
  let isCurrentDir
@@ -6,6 +6,7 @@ import { packageDefaults } from '../helpers/package-defaults.mjs'
6
6
  import { resolveProjectContext } from '../helpers/project-context.mjs'
7
7
  import { readCliPackageJson } from '../helpers/project-root.mjs'
8
8
  import { ensureTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
9
+ import { ProjectScopeKindEnum } from '../helpers/cli-enums.mjs'
9
10
 
10
11
  function line(label, value) {
11
12
  console.log(` ${label.padEnd(20)}${value}`)
@@ -74,7 +75,7 @@ export function registerProjectInfoCommand(cli, { cliName = CLI_PRIMARY_NAME } =
74
75
  line('slot', ctx.selfEntry.slot)
75
76
  }
76
77
 
77
- if (ctx.workspaceEntries.length > 0 && ctx.kind === 'workspace-root') {
78
+ if (ctx.workspaceEntries.length > 0 && ctx.kind === ProjectScopeKindEnum.WORKSPACE_ROOT) {
78
79
  console.log(chalk.bold.cyan(`\n Linked projects (${ctx.workspaceEntries.length})`))
79
80
  for (const entry of ctx.workspaceEntries) {
80
81
  console.log(` • ${chalk.white(entry.name)} [${entry.type}] ${chalk.gray(entry.path)}`)
@@ -6,8 +6,8 @@ import { CLI_PRIMARY_NAME } from '../helpers/cli-identity.mjs'
6
6
  import { readCliPackageJson } from '../helpers/project-root.mjs'
7
7
  import { ensureTmpFile } from '../helpers/tmp-layout.mjs'
8
8
  import { ensureTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
9
- import { syncRegistryFromPath } from '../helpers/xrystal-registry.mjs'
10
9
  import { resolveSyncScope } from '../helpers/sync-scope.mjs'
10
+ import { runWorkspaceSelfHeal } from '../helpers/workspace-heal.mjs'
11
11
  import { printSyncProjectResult, syncOneProject } from '../helpers/sync-project.mjs'
12
12
  import { formatSyncHelp } from '../helpers/cli-help.mjs'
13
13
 
@@ -25,6 +25,19 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
25
25
  }
26
26
 
27
27
  printCommandHeader({ cliName, command: 'sync', version: coreVersion })
28
+
29
+ let workspaceHeal = null
30
+ if (scope.workspaceRoot && !options.dryRun) {
31
+ workspaceHeal = runWorkspaceSelfHeal(scope.workspaceRoot, {
32
+ forceRegistry: scope.mode === 'workspace-all',
33
+ })
34
+ if (workspaceHeal.slotDirsCreated.length) {
35
+ console.log(chalk.green(` layout: created ${workspaceHeal.slotDirsCreated.join(', ')}/`))
36
+ }
37
+ if (workspaceHeal.tmpOptionsPatched) {
38
+ console.log(chalk.green(' outer tmp: added global.options.fileWatchIntervalMs'))
39
+ }
40
+ }
28
41
  if (scope.warnAllIgnored) {
29
42
  console.log(chalk.yellow(' note: not in a workspace — --all ignored, syncing this repo only'))
30
43
  }
@@ -71,13 +84,8 @@ export function registerSyncCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
71
84
  if (result.failed) failed += 1
72
85
  }
73
86
 
74
- if (scope.mode === 'workspace-all' && scope.workspaceRoot && !options.dryRun) {
75
- try {
76
- syncRegistryFromPath(scope.workspaceRoot)
77
- console.log(chalk.gray('\n registry updated (~/.xrystal)'))
78
- } catch (error) {
79
- console.log(chalk.yellow(`\n registry skipped: ${error.message}`))
80
- }
87
+ if (workspaceHeal?.registryChanged) {
88
+ console.log(chalk.gray('\n registry healed (~/.xrystal)'))
81
89
  }
82
90
 
83
91
  if (scope.hintAll) {
@@ -17,9 +17,10 @@ import { packageDefaults } from '../helpers/package-defaults.mjs'
17
17
  import { ensureTmpSchemaVersion, readTmpSchemaVersion } from '../helpers/tmp-schema-version.mjs'
18
18
  import { getCliContext } from '../helpers/cli-context-guard.mjs'
19
19
  import { ensureOuterWorkspaceTmp } from '../helpers/workspace-tmp.mjs'
20
+ import { ProjectScopeKindEnum } from '../helpers/cli-enums.mjs'
20
21
 
21
22
  function ensureTmpForContext(ctx) {
22
- if (ctx.kind === 'workspace-root') {
23
+ if (ctx.kind === ProjectScopeKindEnum.WORKSPACE_ROOT) {
23
24
  const outer = ensureOuterWorkspaceTmp(ctx.workspaceRoot)
24
25
  return {
25
26
  tmpFilePath: outer.tmpFilePath,
@@ -40,10 +41,10 @@ export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
40
41
  .action((options) => {
41
42
  const ctx = getCliContext()
42
43
  const version = readCliPackageJson().version
43
- const root = ctx.kind === 'workspace-root' ? ctx.workspaceRoot : ctx.projectRoot
44
+ const root = ctx.kind === ProjectScopeKindEnum.WORKSPACE_ROOT ? ctx.workspaceRoot : ctx.projectRoot
44
45
 
45
46
  if (options.dryRun) {
46
- const target = ctx.kind === 'workspace-root'
47
+ const target = ctx.kind === ProjectScopeKindEnum.WORKSPACE_ROOT
47
48
  ? `${ctx.workspaceRoot}/tmp.yml`
48
49
  : (resolveTmpLayoutOrDefaults(root).tmpFilePath ?? ownerTmpFilePath(root))
49
50
 
@@ -71,7 +72,7 @@ export function registerTmpCommand(cli, { cliName = CLI_PRIMARY_NAME } = {}) {
71
72
  console.log(schemaLabel)
72
73
  }
73
74
 
74
- if (ctx.kind !== 'workspace-root') {
75
+ if (ctx.kind !== ProjectScopeKindEnum.WORKSPACE_ROOT) {
75
76
  try {
76
77
  const tmp = yaml.parse(fs.readFileSync(result.tmpFilePath, 'utf8'))
77
78
  const summary = summarizeLoaders(resolveObjWithHandlebars(tmp, tmp))
@@ -1,6 +1,6 @@
1
1
  // source/utils/helpers/workspace/index.ts
2
2
  import fs2 from "node:fs";
3
- import path2 from "node:path";
3
+ import path4 from "node:path";
4
4
 
5
5
  // source/utils/models/enums/index.ts
6
6
  var GlobalTypeEnum;
@@ -9,6 +9,16 @@ var GlobalTypeEnum;
9
9
  GlobalTypeEnum2["API_SERVICE"] = "api-service";
10
10
  GlobalTypeEnum2["FRONTEND"] = "frontend";
11
11
  })(GlobalTypeEnum ||= {});
12
+
13
+ // source/utils/constants/index.ts
14
+ import path3 from "node:path";
15
+
16
+ // source/utils/constants/package-root.ts
17
+ import path from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ var constantsDir = path.dirname(fileURLToPath(import.meta.url));
20
+ var sourceDir = path.resolve(constantsDir, "..", "..");
21
+ var packageRootDir = path.resolve(constantsDir, "..", "..", "..");
12
22
  // source/utils/constants/defaults.json
13
23
  var defaults_default = {
14
24
  packageName: "@xrystal/core",
@@ -81,8 +91,8 @@ var defaults_default = {
81
91
 
82
92
  // source/utils/helpers/tmp/seed-from-tmp.ts
83
93
  import fs from "node:fs";
84
- import path from "node:path";
85
- import { fileURLToPath } from "node:url";
94
+ import path2 from "node:path";
95
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
86
96
  import yaml from "yaml";
87
97
 
88
98
  // source/utils/helpers/tmp/path-normalize.ts
@@ -101,7 +111,7 @@ function normalizeSourceFolder(value, fallback) {
101
111
  }
102
112
 
103
113
  // source/utils/helpers/tmp/seed-from-tmp.ts
104
- var here = path.dirname(fileURLToPath(import.meta.url));
114
+ var here = path2.dirname(fileURLToPath2(import.meta.url));
105
115
  var templateRel = defaults_default.apiServiceTemplateRel ?? "x/templates/api-service/tmp.yml";
106
116
  function requireString(value, label) {
107
117
  if (typeof value !== "string" || !value.trim()) {
@@ -118,14 +128,14 @@ function readLayoutFromSpecial(special) {
118
128
  };
119
129
  }
120
130
  function findApiTemplate() {
121
- const starts = [here, process.cwd()].map((value) => path.resolve(value));
131
+ const starts = [here, process.cwd()].map((value) => path2.resolve(value));
122
132
  for (const start of starts) {
123
133
  let dir = start;
124
134
  for (;; ) {
125
- const candidate = path.join(dir, templateRel);
135
+ const candidate = path2.join(dir, templateRel);
126
136
  if (fs.existsSync(candidate))
127
137
  return candidate;
128
- const parent = path.dirname(dir);
138
+ const parent = path2.dirname(dir);
129
139
  if (parent === dir)
130
140
  break;
131
141
  dir = parent;
@@ -154,6 +164,42 @@ function loadSeedFromBundledTmp(tmpFilePath) {
154
164
  }
155
165
  var seedFromTmp = loadSeedFromBundledTmp();
156
166
 
167
+ // source/utils/constants/index.ts
168
+ var packageDefaults = Object.freeze({
169
+ ...defaults_default,
170
+ mainSourceFolder: seedFromTmp.sourceFolder,
171
+ framework: seedFromTmp.framework,
172
+ layoutPaths: Object.freeze({ ...seedFromTmp.layout }),
173
+ brand: Object.freeze({ ...defaults_default.brand }),
174
+ runtimes: Object.freeze(Object.fromEntries(Object.entries(defaults_default.runtimes).map(([key, value]) => [key, Object.freeze({ ...value })]))),
175
+ bundlers: Object.freeze([...defaults_default.bundlers]),
176
+ buildDefaults: Object.freeze({ ...defaults_default.buildDefaults }),
177
+ tmpWatchDefaults: Object.freeze({ ...defaults_default.tmpWatchDefaults }),
178
+ cliBinNames: Object.freeze([...defaults_default.cliBinNames ?? [defaults_default.cliName]])
179
+ });
180
+ var tmpFileName = `${packageDefaults.tmpBaseName}${packageDefaults.tmpExtension}`;
181
+
182
+ class Constants {
183
+ static packageName = packageDefaults.packageName;
184
+ static packageRootFolder = packageDefaults.packageRootFolder;
185
+ static tmpBaseName = packageDefaults.tmpBaseName;
186
+ static tmpExtension = packageDefaults.tmpExtension;
187
+ static publicFolderName = packageDefaults.publicFolderName;
188
+ static kafkaLogsTopic = packageDefaults.kafkaLogsTopic;
189
+ static templateRepoUri = packageDefaults.templateRepoUri;
190
+ static cliName = packageDefaults.cliName;
191
+ static cliBinNames = packageDefaults.cliBinNames;
192
+ static pathAliasKey = packageDefaults.pathAliasKey;
193
+ static brand = packageDefaults.brand;
194
+ static mainSourceFolder = packageDefaults.mainSourceFolder;
195
+ static framework = packageDefaults.framework;
196
+ static layoutPaths = packageDefaults.layoutPaths;
197
+ static cliBinFile = packageDefaults.cliBinFile;
198
+ static logTag = packageDefaults.packageName;
199
+ static bundledApiServiceTmpPath = path3.join(packageRootDir, packageDefaults.apiServiceTemplateRel ?? `${packageDefaults.packageRootFolder}/templates/api-service/${tmpFileName}`);
200
+ static bundledCoreTmpPath = path3.join(packageRootDir, packageDefaults.packageRootFolder, tmpFileName);
201
+ }
202
+
157
203
  // source/utils/helpers/tmp/tmp-interpolate.ts
158
204
  import Handlebars from "handlebars";
159
205
 
@@ -175,9 +221,9 @@ function normalizeGlobalType(value) {
175
221
  var TMP_FILE = "tmp.yml";
176
222
  var SKIP_DIRS = new Set(["node_modules", ".git", "dist", ".turbo", "coverage"]);
177
223
  var DEFAULT_FOLDER_STRUCTURE = {
178
- api: "api",
179
- web: "web",
180
- mobile: "mobile"
224
+ ["api" /* API */]: "api",
225
+ ["web" /* WEB */]: "web",
226
+ ["mobile" /* MOBILE */]: "mobile"
181
227
  };
182
228
  function parseScalar(raw) {
183
229
  const trimmed = raw.trim();
@@ -215,22 +261,22 @@ function parseFolderStructure(text) {
215
261
  throw new Error("configs.folder-structure.admin removed — put admin panels under web/ (e.g. web/admin-ui)");
216
262
  }
217
263
  const readSlot = (key) => {
218
- const scalar = fsBlock.match(new RegExp(`^[ ]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, "m"));
264
+ const scalar = fsBlock.match(new RegExp(`^[ \\t]+${key}:\\s*(.+?)(?:\\s+#.*)?$`, "m"));
219
265
  if (scalar)
220
266
  return parseScalar(scalar[1]);
221
267
  return DEFAULT_FOLDER_STRUCTURE[key];
222
268
  };
223
269
  return {
224
- api: readSlot("api"),
225
- web: readSlot("web"),
226
- mobile: readSlot("mobile")
270
+ ["api" /* API */]: readSlot("api" /* API */),
271
+ ["web" /* WEB */]: readSlot("web" /* WEB */),
272
+ ["mobile" /* MOBILE */]: readSlot("mobile" /* MOBILE */)
227
273
  };
228
274
  }
229
275
  function workspaceDiscoverySlots(fsMap) {
230
276
  return [
231
- { slot: "api", folder: fsMap.api, frontendOnly: false },
232
- { slot: "web", folder: fsMap.web, frontendOnly: true },
233
- { slot: "mobile", folder: fsMap.mobile, frontendOnly: true }
277
+ { slot: "api" /* API */, folder: fsMap["api" /* API */], frontendOnly: false },
278
+ { slot: "web" /* WEB */, folder: fsMap["web" /* WEB */], frontendOnly: true },
279
+ { slot: "mobile" /* MOBILE */, folder: fsMap["mobile" /* MOBILE */], frontendOnly: true }
234
280
  ];
235
281
  }
236
282
  function entryName(meta) {
@@ -246,20 +292,20 @@ function entryType(meta, slot) {
246
292
  return null;
247
293
  }
248
294
  }
249
- if (slot === "api")
295
+ if (slot === "api" /* API */)
250
296
  return "api-service" /* API_SERVICE */;
251
297
  return null;
252
298
  }
253
299
  function findWorkspaceRoot(startDir = process.cwd()) {
254
- let cur = path2.resolve(startDir);
300
+ let cur = path4.resolve(startDir);
255
301
  for (;; ) {
256
- const candidate = path2.join(cur, TMP_FILE);
302
+ const candidate = path4.join(cur, TMP_FILE);
257
303
  if (fs2.existsSync(candidate)) {
258
304
  const meta = readTmpFile(candidate);
259
305
  if (meta.globalType === "workspace" /* WORKSPACE */)
260
306
  return cur;
261
307
  }
262
- const parent = path2.dirname(cur);
308
+ const parent = path4.dirname(cur);
263
309
  if (parent === cur)
264
310
  break;
265
311
  cur = parent;
@@ -292,7 +338,7 @@ function walkTmpUnder(rootDir) {
292
338
  continue;
293
339
  }
294
340
  for (const entry of entries) {
295
- const full = path2.join(dir, entry.name);
341
+ const full = path4.join(dir, entry.name);
296
342
  if (isTraversableDir(entry, full)) {
297
343
  if (SKIP_DIRS.has(entry.name) || entry.name.startsWith("."))
298
344
  continue;
@@ -319,14 +365,14 @@ function repoRootFromTmp(tmpPath, meta) {
319
365
  throw new Error(`tmp path mismatch: expected */${rel}, got ${abs}`);
320
366
  }
321
367
  function findEntries(workspaceRoot) {
322
- const wsMeta = readTmpFile(path2.join(workspaceRoot, TMP_FILE));
368
+ const wsMeta = readTmpFile(path4.join(workspaceRoot, TMP_FILE));
323
369
  const fsMap = wsMeta.folderStructure;
324
370
  const entries = [];
325
371
  const seen = new Set;
326
372
  for (const { slot, folder: folderRel, frontendOnly } of workspaceDiscoverySlots(fsMap)) {
327
- const folder = path2.join(workspaceRoot, folderRel);
373
+ const folder = path4.join(workspaceRoot, folderRel);
328
374
  for (const tmpPath of walkTmpUnder(folder)) {
329
- if (path2.resolve(tmpPath) === path2.join(workspaceRoot, TMP_FILE))
375
+ if (path4.resolve(tmpPath) === path4.join(workspaceRoot, TMP_FILE))
330
376
  continue;
331
377
  const meta = readTmpFile(tmpPath);
332
378
  const kind = entryType(meta, slot);
@@ -363,14 +409,46 @@ function resolveEntryPath(workspaceRoot, name) {
363
409
  return hit?.path ?? null;
364
410
  }
365
411
  function workspaceProjectName(workspaceRoot) {
366
- const meta = readTmpFile(path2.join(workspaceRoot, TMP_FILE));
367
- return meta.projectName?.trim() || path2.basename(workspaceRoot);
412
+ const meta = readTmpFile(path4.join(workspaceRoot, TMP_FILE));
413
+ return meta.projectName?.trim() || path4.basename(workspaceRoot);
368
414
  }
369
415
  function readWorkspaceGlobalTmp(workspaceRoot) {
370
- const text = fs2.readFileSync(path2.join(workspaceRoot, TMP_FILE), "utf8");
416
+ const text = fs2.readFileSync(path4.join(workspaceRoot, TMP_FILE), "utf8");
371
417
  const match = text.match(/options:\s*\n(?:[ \t]+[^\n]+\n)*?[ \t]+fileWatchIntervalMs:\s*(\d+)/m) ?? text.match(/fileWatchIntervalMs:\s*(\d+)/);
372
418
  return match ? { fileWatchIntervalMs: Number(match[1]) } : {};
373
419
  }
420
+ function ensureWorkspaceSlotDirs(workspaceRoot) {
421
+ const tmpPath = path4.join(workspaceRoot, TMP_FILE);
422
+ if (!fs2.existsSync(tmpPath))
423
+ return [];
424
+ const meta = readTmpFile(tmpPath);
425
+ const created = [];
426
+ for (const folder of Object.values(meta.folderStructure)) {
427
+ const dir = path4.join(workspaceRoot, folder);
428
+ if (!fs2.existsSync(dir)) {
429
+ fs2.mkdirSync(dir, { recursive: true });
430
+ created.push(folder);
431
+ }
432
+ }
433
+ return created;
434
+ }
435
+ function healWorkspaceOuterTmpOptions(workspaceRoot) {
436
+ const tmpPath = path4.join(workspaceRoot, TMP_FILE);
437
+ if (!fs2.existsSync(tmpPath))
438
+ return false;
439
+ const text = fs2.readFileSync(tmpPath, "utf8");
440
+ if (/fileWatchIntervalMs:\s*\d+/m.test(text))
441
+ return false;
442
+ const defaultMs = packageDefaults.tmpWatchDefaults.intervalMs;
443
+ const insertBlock = ` options:
444
+ fileWatchIntervalMs: ${defaultMs}
445
+ `;
446
+ const patched = text.replace(/(configs:\s*\n\s+global:\s*\n\s+type:\s*workspace\s*\n)/m, `$1${insertBlock}`);
447
+ if (patched === text)
448
+ return false;
449
+ fs2.writeFileSync(tmpPath, patched);
450
+ return true;
451
+ }
374
452
  var readWorkspaceCoreTmp = readWorkspaceGlobalTmp;
375
453
  function workspaceTmpTemplate(projectName) {
376
454
  return `project:
@@ -379,6 +457,8 @@ function workspaceTmpTemplate(projectName) {
379
457
  configs:
380
458
  global:
381
459
  type: workspace
460
+ options:
461
+ fileWatchIntervalMs: 500
382
462
  folder-structure:
383
463
  api: api
384
464
  web: web
@@ -400,11 +480,13 @@ export {
400
480
  readTmpFile,
401
481
  parseFolderStructure,
402
482
  normalizeGlobalType,
483
+ healWorkspaceOuterTmpOptions,
403
484
  findWorkspaceRoot,
404
485
  findEntries,
405
486
  findApiServices,
406
487
  entryType,
407
488
  entryName,
489
+ ensureWorkspaceSlotDirs,
408
490
  TMP_FILE,
409
491
  SKIP_DIRS,
410
492
  DEFAULT_FOLDER_STRUCTURE