@xrystal/core 3.51.5 → 3.52.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 (121) hide show
  1. package/README.md +35 -1
  2. package/package.json +1 -1
  3. package/x/bin/commands/create.mjs +44 -0
  4. package/x/bin/commands/projects.mjs +53 -0
  5. package/x/bin/commands/sync.mjs +49 -1
  6. package/x/bin/commands/tmp.mjs +1 -1
  7. package/x/bin/helpers/.generated/.generated-from +2 -0
  8. package/x/bin/helpers/.generated/seed-from-tmp.mjs +25 -31
  9. package/x/bin/helpers/.generated/tmp-schema.mjs +156 -96
  10. package/x/bin/helpers/.generated/workspace.mjs +402 -0
  11. package/x/bin/helpers/.generated/xrystal-home-registry.mjs +310 -0
  12. package/x/bin/helpers/build-config.mjs +3 -2
  13. package/x/bin/helpers/cli-help.mjs +3 -1
  14. package/x/bin/helpers/project-artifacts.mjs +9 -0
  15. package/x/bin/helpers/tmp-config.mjs +13 -12
  16. package/x/bin/helpers/tmp-layout.mjs +28 -52
  17. package/x/bin/helpers/tmp-schema.mjs +9 -3
  18. package/x/bin/helpers/workspace-resolve.mjs +11 -0
  19. package/x/bin/helpers/workspace-scaffold.mjs +23 -0
  20. package/x/bin/helpers/xrystal-registry.mjs +13 -0
  21. package/x/bin/main-cli.js +2 -0
  22. package/x/dist/index.js +5 -1
  23. package/x/dist/loader/clients/index.js +22 -1
  24. package/x/dist/loader/configs/index.js +97 -1
  25. package/x/dist/loader/controller/index.js +267 -1
  26. package/x/dist/loader/dto/index.js +92 -1
  27. package/x/dist/loader/events/index.js +39 -1
  28. package/x/dist/loader/index.js +13 -1
  29. package/x/dist/loader/kafka/index.js +142 -1
  30. package/x/dist/loader/kafka/resolve-ssl.js +23 -1
  31. package/x/dist/loader/localizations/index.js +46 -1
  32. package/x/dist/loader/logger/index.js +229 -2
  33. package/x/dist/loader/mongo/index.js +52 -1
  34. package/x/dist/loader/mongo/resolve-connect.js +16 -1
  35. package/x/dist/loader/redis/index.js +57 -1
  36. package/x/dist/loader/redis/resolve-socket.js +31 -1
  37. package/x/dist/loader/registry/index.js +1 -1
  38. package/x/dist/loader/service/index.js +7 -1
  39. package/x/dist/loader/system/index.js +26 -1
  40. package/x/dist/project/index.js +51 -1
  41. package/x/dist/utils/constants/defaults.json +3 -1
  42. package/x/dist/utils/constants/index.d.ts +1 -0
  43. package/x/dist/utils/constants/index.js +42 -1
  44. package/x/dist/utils/constants/package-root.js +6 -1
  45. package/x/dist/utils/helpers/configs/index.js +1 -1
  46. package/x/dist/utils/helpers/context/controller-store.js +12 -1
  47. package/x/dist/utils/helpers/context/index.js +24 -1
  48. package/x/dist/utils/helpers/core/handlebars-resolve.js +15 -1
  49. package/x/dist/utils/helpers/core/index.js +46 -1
  50. package/x/dist/utils/helpers/core/paths.js +78 -1
  51. package/x/dist/utils/helpers/core/tmp-layout.d.ts +4 -4
  52. package/x/dist/utils/helpers/core/tmp-layout.js +229 -1
  53. package/x/dist/utils/helpers/date/index.js +48 -1
  54. package/x/dist/utils/helpers/dispatch/index.js +53 -1
  55. package/x/dist/utils/helpers/dto/index.js +10 -1
  56. package/x/dist/utils/helpers/filters/index.js +44 -1
  57. package/x/dist/utils/helpers/framework/index.js +18 -1
  58. package/x/dist/utils/helpers/handlers/adapters.js +41 -1
  59. package/x/dist/utils/helpers/handlers/execute.js +82 -1
  60. package/x/dist/utils/helpers/handlers/index.js +31 -1
  61. package/x/dist/utils/helpers/hash/crypto.js +22 -1
  62. package/x/dist/utils/helpers/id/index.js +24 -1
  63. package/x/dist/utils/helpers/index.d.ts +1 -0
  64. package/x/dist/utils/helpers/index.js +28 -1
  65. package/x/dist/utils/helpers/ip/index.js +21 -1
  66. package/x/dist/utils/helpers/is/index.js +35 -1
  67. package/x/dist/utils/helpers/kafka-loader-options/index.js +14 -1
  68. package/x/dist/utils/helpers/locales/index.js +82 -1
  69. package/x/dist/utils/helpers/logger-layer/index.js +33 -1
  70. package/x/dist/utils/helpers/math/index.js +14 -1
  71. package/x/dist/utils/helpers/middleware/index.js +36 -1
  72. package/x/dist/utils/helpers/node-env/index.js +20 -1
  73. package/x/dist/utils/helpers/objects/index.js +55 -1
  74. package/x/dist/utils/helpers/path/index.js +5 -1
  75. package/x/dist/utils/helpers/path/resolve-alias-path.d.ts +1 -1
  76. package/x/dist/utils/helpers/path/resolve-alias-path.js +62 -1
  77. package/x/dist/utils/helpers/protocol/index.d.ts +1 -1
  78. package/x/dist/utils/helpers/protocol/index.js +100 -1
  79. package/x/dist/utils/helpers/protocol/options.js +13 -1
  80. package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +3 -1
  81. package/x/dist/utils/helpers/registry/index.d.ts +6 -0
  82. package/x/dist/utils/helpers/registry/index.js +103 -1
  83. package/x/dist/utils/helpers/runtime/dto-access.js +5 -1
  84. package/x/dist/utils/helpers/runtime/dto-types.js +1 -1
  85. package/x/dist/utils/helpers/runtime/index.js +2 -1
  86. package/x/dist/utils/helpers/runtime/shutdown.js +36 -1
  87. package/x/dist/utils/helpers/state/index.js +185 -1
  88. package/x/dist/utils/helpers/state/props-from-tmp.js +46 -1
  89. package/x/dist/utils/helpers/state/request-key-guard.js +43 -1
  90. package/x/dist/utils/helpers/state/scopes.js +69 -1
  91. package/x/dist/utils/helpers/string/index.js +9 -1
  92. package/x/dist/utils/helpers/timer/index.js +5 -1
  93. package/x/dist/utils/helpers/tmp/index.d.ts +2 -2
  94. package/x/dist/utils/helpers/tmp/index.js +8 -1
  95. package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +14 -1
  96. package/x/dist/utils/helpers/tmp/path-normalize.js +27 -1
  97. package/x/dist/utils/helpers/tmp/runtime-tmp.js +42 -1
  98. package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -2
  99. package/x/dist/utils/helpers/tmp/seed-from-tmp.js +62 -1
  100. package/x/dist/utils/helpers/tmp/tmp-interpolate.js +22 -1
  101. package/x/dist/utils/helpers/tmp/tmp-loader.js +56 -1
  102. package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +35 -23
  103. package/x/dist/utils/helpers/tmp/tmp-schema.js +211 -1
  104. package/x/dist/utils/helpers/tmp/tmp-watch.js +23 -1
  105. package/x/dist/utils/helpers/tmp/toolchain-heal.js +157 -2
  106. package/x/dist/utils/helpers/validates/index.js +20 -1
  107. package/x/dist/utils/helpers/workspace/index.d.ts +42 -0
  108. package/x/dist/utils/helpers/workspace/index.js +222 -0
  109. package/x/dist/utils/helpers/xrystal-home/registry.d.ts +32 -0
  110. package/x/dist/utils/helpers/xrystal-home/registry.js +92 -0
  111. package/x/dist/utils/index.js +3 -1
  112. package/x/dist/utils/models/classes/class.clients.js +142 -1
  113. package/x/dist/utils/models/classes/class.interfaces.js +10 -1
  114. package/x/dist/utils/models/classes/class.service-locator.js +16 -1
  115. package/x/dist/utils/models/classes/class.tmp-file-loader.js +61 -1
  116. package/x/dist/utils/models/classes/class.x.js +181 -1
  117. package/x/dist/utils/models/enums/index.d.ts +9 -1
  118. package/x/dist/utils/models/enums/index.js +169 -1
  119. package/x/dist/utils/models/index.js +9 -1
  120. package/x/dist/utils/models/types/index.js +2 -1
  121. package/x/tmp.yml +7 -50
@@ -1 +1,43 @@
1
- import{Constants as B}from "../../../utils/constants/index.js";import{getRunContext as D}from "../../../utils/helpers/context/index.js";import{getControllerCtx as F}from "../../../utils/helpers/context/controller-store.js";export const G_REQUEST_KEY_WARN=`[${B.packageName}] G: key looks request-scoped — use run/controller context, not global G`;const H=new Set(["requestid","reqid","correlationid","cookies","cookie","headers","header","body","query","queries","params","locals","session","sessionid"]);export function looksLikeRequestScopedKey(j){const z=j.trim();if(!z)return!1;const f=z.toLowerCase();if(H.has(f))return!0;if(f.endsWith("requestid")||f.endsWith("correlationid"))return!0;if(f==="req"||f==="res")return!0;return!1}export function warnIfRequestScopedKey(j,z){if(!z||!looksLikeRequestScopedKey(j))return;const f=D()?"run":F()?"controller":"outside-request";console.warn(`${G_REQUEST_KEY_WARN} (key: ${j}, scope: ${f})`)}
1
+ import { Constants } from '../../../utils/constants/index.js';
2
+ import { getRunContext } from '../../../utils/helpers/context/index.js';
3
+ import { getControllerCtx } from '../../../utils/helpers/context/controller-store.js';
4
+ export const G_REQUEST_KEY_WARN = `[${Constants.packageName}] G: key looks request-scoped — use run/controller context, not global G`;
5
+ const EXACT = new Set([
6
+ 'requestid',
7
+ 'reqid',
8
+ 'correlationid',
9
+ 'cookies',
10
+ 'cookie',
11
+ 'headers',
12
+ 'header',
13
+ 'body',
14
+ 'query',
15
+ 'queries',
16
+ 'params',
17
+ 'locals',
18
+ 'session',
19
+ 'sessionid',
20
+ ]);
21
+ export function looksLikeRequestScopedKey(key) {
22
+ const trimmed = key.trim();
23
+ if (!trimmed)
24
+ return false;
25
+ const lower = trimmed.toLowerCase();
26
+ if (EXACT.has(lower))
27
+ return true;
28
+ if (lower.endsWith('requestid') || lower.endsWith('correlationid'))
29
+ return true;
30
+ if (lower === 'req' || lower === 'res')
31
+ return true;
32
+ return false;
33
+ }
34
+ export function warnIfRequestScopedKey(key, enabled) {
35
+ if (!enabled || !looksLikeRequestScopedKey(key))
36
+ return;
37
+ const activeScope = getRunContext()
38
+ ? 'run'
39
+ : getControllerCtx()
40
+ ? 'controller'
41
+ : 'outside-request';
42
+ console.warn(`${G_REQUEST_KEY_WARN} (key: ${key}, scope: ${activeScope})`);
43
+ }
@@ -1 +1,69 @@
1
- import{GStoreScopeEnum as j}from "../../../utils/models/enums/index.js";import{getRunContext as q,patchRunContext as w}from "../../../utils/helpers/context/index.js";import{getControllerCtx as v}from "../../../utils/helpers/context/controller-store.js";export function summarizeController(d){if(!d)return null;return{protocol:d.protocol,framework:d.framework,requestId:d.requestId,metadata:d.metadata,hasReq:!!d.req,hasRes:!!d.res,hasSocket:!!d.socket}}export function runContextValues(d){if(!d)return null;return{...d}}export function buildStoresSnapshot(d){const f=q(),k=summarizeController(v());return{[j.GLOBAL]:{name:j.GLOBAL,active:!0,keys:Object.keys(d),values:{...d}},[j.RUN]:{name:j.RUN,active:!!f,keys:f?Object.keys(f):[],values:runContextValues(f)},[j.CONTROLLER]:{name:j.CONTROLLER,active:!!k,keys:k?Object.keys(k):[],values:k}}}export function patchControllerScope(d){const f=v();if(!f)return!1;if(d.requestId!==void 0)f.requestId=d.requestId;if(d.metadata)f.metadata={...f.metadata,...d.metadata,locals:{...f.metadata?.locals??{},...d.metadata.locals??{}}};return!0}export function patchRunScope(d){if(!q())return!1;w(d);return!0}
1
+ import { GStoreScopeEnum } from '../../../utils/models/enums/index.js';
2
+ import { getRunContext, patchRunContext } from '../../../utils/helpers/context/index.js';
3
+ import { getControllerCtx } from '../../../utils/helpers/context/controller-store.js';
4
+ export function summarizeController(ctx) {
5
+ if (!ctx)
6
+ return null;
7
+ return {
8
+ protocol: ctx.protocol,
9
+ framework: ctx.framework,
10
+ requestId: ctx.requestId,
11
+ metadata: ctx.metadata,
12
+ hasReq: !!ctx.req,
13
+ hasRes: !!ctx.res,
14
+ hasSocket: !!ctx.socket,
15
+ };
16
+ }
17
+ export function runContextValues(ctx) {
18
+ if (!ctx)
19
+ return null;
20
+ return { ...ctx };
21
+ }
22
+ export function buildStoresSnapshot(globalValues) {
23
+ const run = getRunContext();
24
+ const controller = summarizeController(getControllerCtx());
25
+ return {
26
+ [GStoreScopeEnum.GLOBAL]: {
27
+ name: GStoreScopeEnum.GLOBAL,
28
+ active: true,
29
+ keys: Object.keys(globalValues),
30
+ values: { ...globalValues },
31
+ },
32
+ [GStoreScopeEnum.RUN]: {
33
+ name: GStoreScopeEnum.RUN,
34
+ active: !!run,
35
+ keys: run ? Object.keys(run) : [],
36
+ values: runContextValues(run),
37
+ },
38
+ [GStoreScopeEnum.CONTROLLER]: {
39
+ name: GStoreScopeEnum.CONTROLLER,
40
+ active: !!controller,
41
+ keys: controller ? Object.keys(controller) : [],
42
+ values: controller,
43
+ },
44
+ };
45
+ }
46
+ export function patchControllerScope(patch) {
47
+ const ctx = getControllerCtx();
48
+ if (!ctx)
49
+ return false;
50
+ if (patch.requestId !== undefined)
51
+ ctx.requestId = patch.requestId;
52
+ if (patch.metadata) {
53
+ ctx.metadata = {
54
+ ...ctx.metadata,
55
+ ...patch.metadata,
56
+ locals: {
57
+ ...(ctx.metadata?.locals ?? {}),
58
+ ...(patch.metadata.locals ?? {}),
59
+ },
60
+ };
61
+ }
62
+ return true;
63
+ }
64
+ export function patchRunScope(patch) {
65
+ if (!getRunContext())
66
+ return false;
67
+ patchRunContext(patch);
68
+ return true;
69
+ }
@@ -1 +1,9 @@
1
- export function cleanStringForNormalize(e){if(typeof e!=="string")return"";return e.normalize("NFD").replace(/\u0307/g,"").normalize("NFC")}
1
+ export function cleanStringForNormalize(input) {
2
+ if (typeof input !== 'string')
3
+ return '';
4
+ const cleaned = input
5
+ .normalize('NFD')
6
+ .replace(/\u0307/g, '')
7
+ .normalize('NFC');
8
+ return cleaned;
9
+ }
@@ -1 +1,5 @@
1
- export async function delay({duration:e}){return new Promise((t,n)=>{setTimeout(()=>t(delay),e)})}
1
+ export async function delay({ duration, }) {
2
+ return new Promise((resolve, reject) => {
3
+ setTimeout(() => resolve(delay), duration);
4
+ });
5
+ }
@@ -2,7 +2,7 @@ export { setRuntimeTmpConfigs, getRuntimeTmpConfigs, onRuntimeTmpChange, notifyR
2
2
  export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLoaderForTests, stopTmpLoader, } from '../../../utils/helpers/tmp/tmp-loader';
3
3
  export { bindLoaderTmpSync, type ITmpSyncLoader, } from '../../../utils/helpers/tmp/loader-tmp-sync';
4
4
  export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch';
5
- export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpCoreBlock, readTmpServiceBlock, readTmpGlobalBlock, applyTmpGlobalVars, resolveServiceLayoutPaths, resolveTmpRuntimeConfigs, } from '../../../utils/helpers/tmp/tmp-schema';
6
- export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, type SeedLayoutPaths, } from '../../../utils/helpers/tmp/seed-from-tmp';
5
+ export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema';
6
+ export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp, } from '../../../utils/helpers/tmp/seed-from-tmp';
7
7
  export { normalizeLayoutPaths, type LayoutPaths, } from '../../../utils/helpers/tmp/path-normalize';
8
8
  export { healToolchainIfLayoutNeedsSync, layoutFingerprint, layoutOptionsFromRuntimeConfigs, resetToolchainHealState, writeTsconfigFromLayout, auditTsconfigAgainstLayout, type ToolchainHealResult, type ToolchainLayoutOptions, } from '../../../utils/helpers/tmp/toolchain-heal';
@@ -1 +1,8 @@
1
- export{setRuntimeTmpConfigs,getRuntimeTmpConfigs,onRuntimeTmpChange,notifyRuntimeTmpChange,clearRuntimeTmpConfigs}from "../../../utils/helpers/tmp/runtime-tmp.js";export{getTmpLoader,getTmpLoaderPath,getTmpSnapshot,onTmpReload,resetTmpLoaderForTests,stopTmpLoader}from "../../../utils/helpers/tmp/tmp-loader.js";export{bindLoaderTmpSync}from "../../../utils/helpers/tmp/loader-tmp-sync.js";export{resolveTmpWatchIntervalMs}from "../../../utils/helpers/tmp/tmp-watch.js";export{normalizeTmpDocument,normalizeRootFolder,normalizeSourceFolder,normalizeRuntime,normalizeBundler,resolveEffectiveBundler,readTmpCoreBlock,readTmpServiceBlock,readTmpGlobalBlock,applyTmpGlobalVars,resolveServiceLayoutPaths,resolveTmpRuntimeConfigs}from "../../../utils/helpers/tmp/tmp-schema.js";export{loadSeedFromBundledTmp,seedFromTmp}from "../../../utils/helpers/tmp/seed-from-tmp.js";export{normalizeLayoutPaths}from "../../../utils/helpers/tmp/path-normalize.js";export{healToolchainIfLayoutNeedsSync,layoutFingerprint,layoutOptionsFromRuntimeConfigs,resetToolchainHealState,writeTsconfigFromLayout,auditTsconfigAgainstLayout}from "../../../utils/helpers/tmp/toolchain-heal.js";
1
+ export { setRuntimeTmpConfigs, getRuntimeTmpConfigs, onRuntimeTmpChange, notifyRuntimeTmpChange, clearRuntimeTmpConfigs, } from '../../../utils/helpers/tmp/runtime-tmp.js';
2
+ export { getTmpLoader, getTmpLoaderPath, getTmpSnapshot, onTmpReload, resetTmpLoaderForTests, stopTmpLoader, } from '../../../utils/helpers/tmp/tmp-loader.js';
3
+ export { bindLoaderTmpSync, } from '../../../utils/helpers/tmp/loader-tmp-sync.js';
4
+ export { resolveTmpWatchIntervalMs } from '../../../utils/helpers/tmp/tmp-watch.js';
5
+ export { normalizeTmpDocument, normalizeRootFolder, normalizeSourceFolder, normalizeRuntime, normalizeBundler, resolveEffectiveBundler, readTmpDependsBlock, readTmpBuildBlock, readTmpGlobalBlock, assertNoLegacyTmpKeys, resolveTmpDeploymentName, readTmpGlobalPathsBlock, applyTmpGlobalVars, resolveMergedPaths, resolveTmpRuntimeConfigs, resolveProjectRootFromTmpPath, resolveTmpAbsPath, normalizeGlobalType, } from '../../../utils/helpers/tmp/tmp-schema.js';
6
+ export { loadSeedFromBundledTmp, seedFromTmp, } from '../../../utils/helpers/tmp/seed-from-tmp.js';
7
+ export { normalizeLayoutPaths, } from '../../../utils/helpers/tmp/path-normalize.js';
8
+ export { healToolchainIfLayoutNeedsSync, layoutFingerprint, layoutOptionsFromRuntimeConfigs, resetToolchainHealState, writeTsconfigFromLayout, auditTsconfigAgainstLayout, } from '../../../utils/helpers/tmp/toolchain-heal.js';
@@ -1 +1,14 @@
1
- import{packageDefaults as w}from "../../../utils/constants/index.js";import{onRuntimeTmpChange as x}from "../../../utils/helpers/tmp/runtime-tmp.js";export function bindLoaderTmpSync(j){const q=j.constructor.name;x(async()=>{try{await j.syncFromTmp()}catch(b){const v=b instanceof Error?b.message:String(b);console.warn(`[${w.packageName}] ${q} tmp reload failed: ${v}`)}})}
1
+ import { packageDefaults } from '../../../utils/constants/index.js';
2
+ import { onRuntimeTmpChange } from '../../../utils/helpers/tmp/runtime-tmp.js';
3
+ export function bindLoaderTmpSync(loader) {
4
+ const tag = loader.constructor.name;
5
+ onRuntimeTmpChange(async () => {
6
+ try {
7
+ await loader.syncFromTmp();
8
+ }
9
+ catch (error) {
10
+ const message = error instanceof Error ? error.message : String(error);
11
+ console.warn(`[${packageDefaults.packageName}] ${tag} tmp reload failed: ${message}`);
12
+ }
13
+ });
14
+ }
@@ -1 +1,27 @@
1
- export function normalizeRootFolder(t,n){if(typeof t!=="string"||!t.trim())return n;return t.trim().replace(/^\.\/+/,"")}export function normalizeSourceFolder(t,n){if(typeof t!=="string"||!t.trim())return n;const r=t.trim();if(r.startsWith("./")||r.startsWith("../"))return r;return`./${r}`}export function normalizeLayoutPaths(t,n){const r=t&&typeof t==="object"&&!Array.isArray(t)?t:{},o=(e)=>{const i=r[e];return typeof i==="string"&&i.trim()?i.trim():n[e]};return{tests:o("tests"),environments:o("environments"),dist:o("dist")}}
1
+ export function normalizeRootFolder(value, fallback) {
2
+ if (typeof value !== 'string' || !value.trim())
3
+ return fallback;
4
+ return value.trim().replace(/^\.\/+/, '');
5
+ }
6
+ export function normalizeSourceFolder(value, fallback) {
7
+ if (typeof value !== 'string' || !value.trim())
8
+ return fallback;
9
+ const trimmed = value.trim();
10
+ if (trimmed.startsWith('./') || trimmed.startsWith('../'))
11
+ return trimmed;
12
+ return `./${trimmed}`;
13
+ }
14
+ export function normalizeLayoutPaths(special, fallback) {
15
+ const block = special && typeof special === 'object' && !Array.isArray(special)
16
+ ? special
17
+ : {};
18
+ const pick = (key) => {
19
+ const raw = block[key];
20
+ return typeof raw === 'string' && raw.trim() ? raw.trim() : fallback[key];
21
+ };
22
+ return {
23
+ tests: pick('tests'),
24
+ environments: pick('environments'),
25
+ dist: pick('dist'),
26
+ };
27
+ }
@@ -1 +1,42 @@
1
- import{packageDefaults as A}from "../../../utils/constants/index.js";import{healToolchainIfLayoutNeedsSync as B,resetToolchainHealState as E}from "../../../utils/helpers/tmp/toolchain-heal.js";let v;const w=[];export function setRuntimeTmpConfigs(j){v=j}export function getRuntimeTmpConfigs(){return v}export function onRuntimeTmpChange(j){w.push(j);return()=>{const b=w.indexOf(j);if(b>=0)w.splice(b,1)}}export async function notifyRuntimeTmpChange(j){if(j)v=j;const b=v;if(!b)return;if(b.rootFolderPath&&b.service?.paths)try{B(process.cwd(),b)}catch(q){const z=q instanceof Error?q.message:String(q);console.warn(`[${A.packageName}] toolchain auto-sync skipped: ${z}`)}for(const q of w)await q(b)}export function clearRuntimeTmpConfigs(){v=void 0;w.length=0;E()}
1
+ import { packageDefaults } from '../../../utils/constants/index.js';
2
+ import { healToolchainIfLayoutNeedsSync, resetToolchainHealState, } from '../../../utils/helpers/tmp/toolchain-heal.js';
3
+ let runtimeConfigs;
4
+ const listeners = [];
5
+ export function setRuntimeTmpConfigs(configs) {
6
+ runtimeConfigs = configs;
7
+ }
8
+ export function getRuntimeTmpConfigs() {
9
+ return runtimeConfigs;
10
+ }
11
+ export function onRuntimeTmpChange(listener) {
12
+ listeners.push(listener);
13
+ return () => {
14
+ const index = listeners.indexOf(listener);
15
+ if (index >= 0)
16
+ listeners.splice(index, 1);
17
+ };
18
+ }
19
+ export async function notifyRuntimeTmpChange(configs) {
20
+ if (configs)
21
+ runtimeConfigs = configs;
22
+ const snapshot = runtimeConfigs;
23
+ if (!snapshot)
24
+ return;
25
+ if (snapshot.rootFolderPath && snapshot.global?.paths) {
26
+ try {
27
+ healToolchainIfLayoutNeedsSync(process.cwd(), snapshot);
28
+ }
29
+ catch (error) {
30
+ const message = error instanceof Error ? error.message : String(error);
31
+ console.warn(`[${packageDefaults.packageName}] toolchain auto-sync skipped: ${message}`);
32
+ }
33
+ }
34
+ for (const listener of listeners) {
35
+ await listener(snapshot);
36
+ }
37
+ }
38
+ export function clearRuntimeTmpConfigs() {
39
+ runtimeConfigs = undefined;
40
+ listeners.length = 0;
41
+ resetToolchainHealState();
42
+ }
@@ -1,12 +1,12 @@
1
1
  import defaults from '../../../utils/constants/defaults.json';
2
2
  import { type LayoutPaths } from '../../../utils/helpers/tmp/path-normalize';
3
3
  export { defaults as packageIdentityDefaults };
4
- export type SeedLayoutPaths = LayoutPaths;
5
4
  export type SeedFromTmp = {
6
5
  rootFolder: string;
7
6
  sourceFolder: string;
8
7
  framework: string;
9
- layout: SeedLayoutPaths;
8
+ layout: LayoutPaths;
9
+ tmpRelPath: string;
10
10
  };
11
11
  export declare function loadSeedFromBundledTmp(tmpFilePath?: string): SeedFromTmp;
12
12
  export declare const seedFromTmp: SeedFromTmp;
@@ -1 +1,62 @@
1
- import K from"node:fs";import J from"node:path";import{fileURLToPath as V}from"node:url";import W from"yaml";import defaults from"../../../utils/constants/defaults.json" with { type: 'json' };import{normalizeRootFolder as X,normalizeSourceFolder as Y}from "../../../utils/helpers/tmp/path-normalize.js";export{defaults as packageIdentityDefaults};const O=J.dirname(V(import.meta.url)),Q=`${defaults.tmpBaseName}${defaults.tmpExtension}`;function I(j,A){if(typeof j!=="string"||!j.trim())throw Error(`${defaults.packageName}: bundled tmp.yml missing ${A}`);return j.trim()}function Z(j){const A=j&&typeof j==="object"&&!Array.isArray(j)?j:{};return{tests:I(A.tests,"configs.service.paths.special.tests"),environments:I(A.environments,"configs.service.paths.special.environments"),dist:I(A.dist,"configs.service.paths.special.dist")}}function _(){try{return process.cwd()}catch{return null}}function $(j){if(j){if(!K.existsSync(j))throw Error(`${defaults.packageName}: bundled tmp.yml missing at ${j}`);return j}const A=[O,_()].filter((E)=>Boolean(E));for(const E of A){let D=J.resolve(E);for(;;){const G=J.join(D,defaults.packageRootFolder,Q);if(K.existsSync(G))return G;const H=J.dirname(D);if(H===D)break;D=H}}throw Error(`${defaults.packageName}: bundled ${defaults.packageRootFolder}/${Q} not found from ${O}`)}export function loadSeedFromBundledTmp(j){const A=$(j),E=W.parse(K.readFileSync(A,"utf8")),D=E?.configs&&typeof E.configs==="object"?E.configs:{},G=D.service&&typeof D.service==="object"?D.service:{},H=G.paths&&typeof G.paths==="object"?G.paths:{},M=I(H.source,"configs.service.paths.source");return{rootFolder:X(H.root,defaults.packageRootFolder),sourceFolder:Y(M,M),framework:I(G.framework,"configs.service.framework"),layout:Z(H.special)}}export const seedFromTmp=loadSeedFromBundledTmp();
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import yaml from 'yaml';
5
+ import defaults from '../../../utils/constants/defaults.json' with { type: 'json' };
6
+ import { normalizeRootFolder, normalizeSourceFolder, } from '../../../utils/helpers/tmp/path-normalize.js';
7
+ export { defaults as packageIdentityDefaults };
8
+ const here = path.dirname(fileURLToPath(import.meta.url));
9
+ const templateRel = defaults.apiServiceTemplateRel
10
+ ?? 'x/templates/api-service/tmp.yml';
11
+ function requireString(value, label) {
12
+ if (typeof value !== 'string' || !value.trim()) {
13
+ throw new Error(`${defaults.packageName}: bundled template missing ${label}`);
14
+ }
15
+ return value.trim();
16
+ }
17
+ function readLayoutFromSpecial(special) {
18
+ const block = special && typeof special === 'object' && !Array.isArray(special)
19
+ ? special
20
+ : {};
21
+ return {
22
+ tests: requireString(block.tests, 'configs.global.paths.special.tests'),
23
+ environments: requireString(block.environments, 'configs.global.paths.special.environments'),
24
+ dist: requireString(block.dist, 'configs.global.paths.special.dist'),
25
+ };
26
+ }
27
+ function findApiTemplate() {
28
+ const starts = [here, process.cwd()].map((value) => path.resolve(value));
29
+ for (const start of starts) {
30
+ let dir = start;
31
+ for (;;) {
32
+ const candidate = path.join(dir, templateRel);
33
+ if (fs.existsSync(candidate))
34
+ return candidate;
35
+ const parent = path.dirname(dir);
36
+ if (parent === dir)
37
+ break;
38
+ dir = parent;
39
+ }
40
+ }
41
+ throw new Error(`${defaults.packageName}: api-service template not found (${templateRel})`);
42
+ }
43
+ export function loadSeedFromBundledTmp(tmpFilePath) {
44
+ const file = tmpFilePath ?? findApiTemplate();
45
+ const doc = yaml.parse(fs.readFileSync(file, 'utf8'));
46
+ const configs = (doc?.configs && typeof doc.configs === 'object' ? doc.configs : {});
47
+ const global = (configs.global && typeof configs.global === 'object' ? configs.global : {});
48
+ const paths = (global.paths && typeof global.paths === 'object' ? global.paths : {});
49
+ const special = paths.special;
50
+ const root = requireString(paths.root, 'configs.global.paths.root');
51
+ const rootNorm = normalizeRootFolder(root, defaults.packageRootFolder).replace(/^\.\//, '');
52
+ const tmpName = typeof paths.tmp === 'string' && paths.tmp.trim() ? paths.tmp.trim().replace(/^\.\//, '') : 'tmp.yml';
53
+ const sourceRaw = requireString(paths.source, 'configs.global.paths.source');
54
+ return {
55
+ rootFolder: rootNorm,
56
+ sourceFolder: normalizeSourceFolder(sourceRaw, sourceRaw),
57
+ framework: requireString(global.framework, 'configs.global.framework'),
58
+ layout: readLayoutFromSpecial(special),
59
+ tmpRelPath: `${rootNorm}/${tmpName}`.replace(/\/+/g, '/'),
60
+ };
61
+ }
62
+ export const seedFromTmp = loadSeedFromBundledTmp();
@@ -1 +1,22 @@
1
- import f from"handlebars";function e(r){return typeof r==="object"&&r!==null&&!Array.isArray(r)}export function interpolateWithContext(r,n){if(typeof r==="string"){if(!r.includes("{{"))return r;return f.compile(r)(n)}if(Array.isArray(r))return r.map((t)=>interpolateWithContext(t,n));if(e(r)){const t={};for(const[i,o]of Object.entries(r))t[i]=interpolateWithContext(o,n);return t}return r}
1
+ import Handlebars from 'handlebars';
2
+ function isRecord(value) {
3
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
4
+ }
5
+ export function interpolateWithContext(value, context) {
6
+ if (typeof value === 'string') {
7
+ if (!value.includes('{{'))
8
+ return value;
9
+ return Handlebars.compile(value)(context);
10
+ }
11
+ if (Array.isArray(value)) {
12
+ return value.map((item) => interpolateWithContext(item, context));
13
+ }
14
+ if (isRecord(value)) {
15
+ const next = {};
16
+ for (const [key, child] of Object.entries(value)) {
17
+ next[key] = interpolateWithContext(child, context);
18
+ }
19
+ return next;
20
+ }
21
+ return value;
22
+ }
@@ -1 +1,56 @@
1
- import J from"node:fs";import K from"node:path";import{Constants as z}from "../../../utils/constants/index.js";import{assertCoreTmpGuard as M,coreCanonicalTmpPath as O,isCorePackageRoot as Q}from "../../../utils/helpers/core/tmp-layout.js";import{findFileRecursively as U}from "../../../utils/helpers/core/paths.js";import{TmpFileLoader as V}from "../../../utils/models/classes/class.tmp-file-loader.js";import{registerGracefulShutdown as W}from "../../../utils/helpers/runtime/shutdown.js";let q=null,B=null;function X(D=process.cwd(),j=z.tmpBaseName,b=z.tmpExtension){const A=K.resolve(D);if(Q(A)){const E=O(A);if(!J.existsSync(E))throw Error(`${z.packageRootFolder}/tmp.yml not found. Run ${z.cliName} tmp or ensureCoreTmpEntry() before starting ${z.packageName}`);M(A,E);return E}const H=U(A,j,b);if(!H)throw Error(`${j}${b.startsWith(".")?b:`.${b}`} file not found`);return H}export function getTmpLoaderPath(){if(!B)B=X();return B}export function getTmpLoader(){if(!q){q=new V({filePath:getTmpLoaderPath()});W()}return q}export function getTmpSnapshot(){return getTmpLoader().getResolvedTmpFile()}export function onTmpReload(D){const j=getTmpLoader(),b=()=>D(j.getResolvedTmpFile());j.on("reload",b);return()=>j.off("reload",b)}export function stopTmpLoader(){if(q){q.stop();q=null;B=null}}export function resetTmpLoaderForTests(){stopTmpLoader()}
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { Constants } from '../../../utils/constants/index.js';
4
+ import { assertCoreTmpGuard, coreCanonicalTmpPath, isCorePackageRoot, } from '../../../utils/helpers/core/tmp-layout.js';
5
+ import { findFileRecursively } from '../../../utils/helpers/core/paths.js';
6
+ import { TmpFileLoader } from '../../../utils/models/classes/class.tmp-file-loader.js';
7
+ import { registerGracefulShutdown } from '../../../utils/helpers/runtime/shutdown.js';
8
+ let loaderInstance = null;
9
+ let loaderPath = null;
10
+ function resolveTmpPath(root = process.cwd(), tmpFileName = Constants.tmpBaseName, ext = Constants.tmpExtension) {
11
+ const resolvedRoot = path.resolve(root);
12
+ if (isCorePackageRoot(resolvedRoot)) {
13
+ const canonical = coreCanonicalTmpPath(resolvedRoot);
14
+ if (!fs.existsSync(canonical)) {
15
+ throw new Error(`${Constants.packageRootFolder}/tmp.yml not found. Run ${Constants.cliName} tmp or ensureCoreTmpEntry() before starting ${Constants.packageName}`);
16
+ }
17
+ assertCoreTmpGuard(resolvedRoot, canonical);
18
+ return canonical;
19
+ }
20
+ const filePath = findFileRecursively(resolvedRoot, tmpFileName, ext);
21
+ if (!filePath) {
22
+ throw new Error(`${tmpFileName}${ext.startsWith('.') ? ext : `.${ext}`} file not found`);
23
+ }
24
+ return filePath;
25
+ }
26
+ export function getTmpLoaderPath() {
27
+ if (!loaderPath)
28
+ loaderPath = resolveTmpPath();
29
+ return loaderPath;
30
+ }
31
+ export function getTmpLoader() {
32
+ if (!loaderInstance) {
33
+ loaderInstance = new TmpFileLoader({ filePath: getTmpLoaderPath() });
34
+ registerGracefulShutdown();
35
+ }
36
+ return loaderInstance;
37
+ }
38
+ export function getTmpSnapshot() {
39
+ return getTmpLoader().getResolvedTmpFile();
40
+ }
41
+ export function onTmpReload(listener) {
42
+ const loader = getTmpLoader();
43
+ const handler = () => listener(loader.getResolvedTmpFile());
44
+ loader.on('reload', handler);
45
+ return () => loader.off('reload', handler);
46
+ }
47
+ export function stopTmpLoader() {
48
+ if (loaderInstance) {
49
+ loaderInstance.stop();
50
+ loaderInstance = null;
51
+ loaderPath = null;
52
+ }
53
+ }
54
+ export function resetTmpLoaderForTests() {
55
+ stopTmpLoader();
56
+ }
@@ -1,56 +1,68 @@
1
- import { BundlerEnum, RuntimeEnum } from '../../../utils/models/enums';
2
- export type TmpServiceSpecialPaths = {
1
+ import { BundlerEnum, GlobalTypeEnum, RuntimeEnum } from '../../../utils/models/enums';
2
+ export type TmpSpecialPaths = {
3
3
  tests?: string;
4
4
  environments?: string;
5
5
  dist?: string;
6
6
  };
7
- export type TmpServicePathsBlock = {
8
- root?: string;
7
+ export type TmpGlobalPathsBlock = {
8
+ root: string;
9
+ tmp?: string;
9
10
  source?: string;
10
- special?: TmpServiceSpecialPaths;
11
+ special?: TmpSpecialPaths;
11
12
  };
12
- export type TmpServiceBlock = {
13
- name?: string;
14
- framework?: string;
15
- paths?: TmpServicePathsBlock;
13
+ export type TmpDependsBlock = {
16
14
  protocols?: unknown;
17
15
  loaders?: Record<string, unknown>;
18
- build?: Record<string, unknown>;
19
16
  };
20
- export type TmpCoreBlock = {
21
- tmp?: {
22
- fileWatchIntervalMs?: number | string;
23
- };
17
+ export type TmpBuildBlock = Record<string, unknown>;
18
+ export type TmpGlobalOptionsBlock = {
19
+ fileWatchIntervalMs?: number | string;
24
20
  };
25
21
  export type TmpGlobalBlock = {
26
22
  runtime: RuntimeEnum;
23
+ type?: GlobalTypeEnum;
24
+ framework?: string;
25
+ paths: TmpGlobalPathsBlock;
27
26
  vars: Record<string, unknown>;
27
+ build?: TmpBuildBlock;
28
+ options?: TmpGlobalOptionsBlock;
28
29
  };
29
30
  export type TmpLayoutPathsFlat = {
30
31
  tests: string;
31
32
  environments: string;
32
33
  dist: string;
33
34
  };
35
+ export type TmpMergedPaths = {
36
+ tmpRelPath: string;
37
+ root: string;
38
+ source: string;
39
+ special: TmpLayoutPathsFlat;
40
+ };
34
41
  export type TmpRuntimeConfigs = {
35
42
  global: TmpGlobalBlock;
36
- service: TmpServiceBlock & {
37
- paths: Required<Pick<TmpServicePathsBlock, 'root' | 'source'>> & {
38
- special: TmpLayoutPathsFlat;
39
- };
40
- };
41
- core: TmpCoreBlock;
43
+ depends: TmpDependsBlock;
44
+ deploymentName?: string;
42
45
  rootFolderPath: string;
46
+ tmpRelPath: string;
43
47
  };
48
+ export declare function normalizeGlobalType(value: unknown): GlobalTypeEnum | undefined;
44
49
  export declare function normalizeRuntime(value: unknown): RuntimeEnum;
45
50
  export declare function normalizeBundler(value: unknown): BundlerEnum;
46
51
  export declare function resolveEffectiveBundler(bundler: BundlerEnum, _runtime: RuntimeEnum): Exclude<BundlerEnum, BundlerEnum.AUTO>;
47
52
  export declare function normalizeRootFolder(value?: string): string;
48
53
  export declare function normalizeSourceFolder(value?: string): string;
54
+ export declare function readTmpGlobalPathsBlock(configs?: Record<string, unknown>): TmpGlobalPathsBlock;
55
+ export declare function resolveMergedPaths(configs?: Record<string, unknown>): TmpMergedPaths;
49
56
  export declare function readTmpGlobalBlock(configs?: Record<string, unknown>): TmpGlobalBlock;
50
- export declare function readTmpCoreBlock(configs?: Record<string, unknown>): TmpCoreBlock;
51
- export declare function readTmpServiceBlock(configs?: Record<string, unknown>): TmpServiceBlock;
52
- export declare function resolveServiceLayoutPaths(service: TmpServiceBlock): TmpLayoutPathsFlat;
57
+ /** Reject removed tmp.yml keys (depends.build, cluster, etc.). */
58
+ export declare function assertNoLegacyTmpKeys(configs?: Record<string, unknown>): void;
59
+ /** Build options from configs.global.build only. */
60
+ export declare function readTmpBuildBlock(configs?: Record<string, unknown>): TmpBuildBlock;
61
+ export declare function readTmpDependsBlock(configs?: Record<string, unknown>): TmpDependsBlock;
62
+ export declare function resolveTmpDeploymentName(tmp?: Record<string, unknown> | null): string | undefined;
53
63
  export declare function buildTmpVarContext(global: TmpGlobalBlock): Record<string, unknown>;
54
64
  export declare function applyTmpGlobalVars(tmp: Record<string, unknown>): Record<string, unknown>;
55
65
  export declare function resolveTmpRuntimeConfigs(tmp?: Record<string, unknown> | null): TmpRuntimeConfigs;
56
66
  export declare function normalizeTmpDocument(tmp: Record<string, unknown>): Record<string, unknown>;
67
+ export declare function resolveProjectRootFromTmpPath(tmpFilePath: string, configs?: Record<string, unknown>): string;
68
+ export declare function resolveTmpAbsPath(projectRoot: string, configs?: Record<string, unknown>): string;