@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,211 @@
1
- import Q from"../../../utils/constants/defaults.json" with { type: 'json' };import{BundlerEnum as H,RuntimeEnum as O}from "../../../utils/models/enums/index.js";import{seedFromTmp as U}from "../../../utils/helpers/tmp/seed-from-tmp.js";import{interpolateWithContext as Z}from "../../../utils/helpers/tmp/tmp-interpolate.js";import{normalizeLayoutPaths as _,normalizeRootFolder as $,normalizeSourceFolder as I}from "../../../utils/helpers/tmp/path-normalize.js";function D(j){return typeof j==="object"&&j!==null&&!Array.isArray(j)}function x(j){if(typeof j==="number"||typeof j==="string")return j;return}export function normalizeRuntime(j){const q=typeof j==="string"?j.trim().toLowerCase():"";if(q===O.NODE)return O.NODE;if(q===O.BUN)return O.BUN;if(!q)throw Error(`${Q.packageName}: configs.global.runtime is required (${Object.values(O).join("|")})`);throw Error(`${Q.packageName}: unknown configs.global.runtime "${String(j)}" (expected ${Object.values(O).join("|")})`)}export function normalizeBundler(j){const q=typeof j==="string"?j.trim().toLowerCase():"";if(!q)return H.AUTO;if(q===H.TSC)return H.TSC;if(q===H.ESBUILD)return H.ESBUILD;if(q===H.BUN)return H.BUN;if(q===H.AUTO)return H.AUTO;throw Error(`${Q.packageName}: unknown build.bundler "${String(j)}" (expected ${Object.values(H).join("|")})`)}export function resolveEffectiveBundler(j,q){if(j!==H.AUTO)return j;return H.TSC}export function normalizeRootFolder(j){return $(j,Q.packageRootFolder)}export function normalizeSourceFolder(j){return I(j,U.sourceFolder)}export function readTmpGlobalBlock(j){const q=D(j?.global)?j.global:{},A=D(q.vars)?q.vars:{};return{runtime:normalizeRuntime(q.runtime),vars:{...A}}}export function readTmpCoreBlock(j){const q=D(j?.core)?j.core:{},A=D(q.tmp)?q.tmp:{};return{tmp:{fileWatchIntervalMs:x(A.fileWatchIntervalMs)}}}export function readTmpServiceBlock(j){const q=D(j?.service)?j.service:{},A=D(q.paths)?q.paths:{},J=D(A.special)?A.special:{};let K=D(q.loaders)?{...q.loaders}:void 0,M=D(q.build)?q.build:void 0;if(K&&D(K.build)){const{build:X,...Y}=K;K=Y;if(!M&&D(X))M=X}return{name:typeof q.name==="string"?q.name:void 0,framework:typeof q.framework==="string"?q.framework:void 0,paths:{root:typeof A.root==="string"?A.root:void 0,source:typeof A.source==="string"?A.source:void 0,special:{tests:typeof J.tests==="string"?J.tests:void 0,environments:typeof J.environments==="string"?J.environments:void 0,dist:typeof J.dist==="string"?J.dist:void 0}},protocols:q.protocols,loaders:K,build:M}}export function resolveServiceLayoutPaths(j){return _(j.paths?.special,U.layout)}function L(j){const q=resolveServiceLayoutPaths(j);return{name:j.name,framework:j.framework??U.framework,paths:{root:j.paths?.root??Q.packageRootFolder,source:j.paths?.source??U.sourceFolder,special:q},protocols:j.protocols,loaders:j.loaders,build:j.build}}function N(j){return{tmp:{fileWatchIntervalMs:j.tmp?.fileWatchIntervalMs}}}export function buildTmpVarContext(j){return{...j.vars,runtime:j.runtime,global:j}}export function applyTmpGlobalVars(j){const q=D(j.configs)?j.configs:{},A=readTmpGlobalBlock(q);return Z(j,buildTmpVarContext(A))}export function resolveTmpRuntimeConfigs(j){const q=D(j?.configs)?j.configs:{},A=readTmpGlobalBlock(q),J=readTmpServiceBlock(q),K=readTmpCoreBlock(q),M=L(J);return{global:A,service:M,core:N(K),rootFolderPath:normalizeRootFolder(M.paths.root)}}export function normalizeTmpDocument(j){const q=applyTmpGlobalVars(j);return{...q,configs:resolveTmpRuntimeConfigs(q)}}
1
+ import defaults from '../../../utils/constants/defaults.json' with { type: 'json' };
2
+ import { BundlerEnum, GlobalTypeEnum, RuntimeEnum } from '../../../utils/models/enums/index.js';
3
+ import { seedFromTmp } from '../../../utils/helpers/tmp/seed-from-tmp.js';
4
+ import { interpolateWithContext } from '../../../utils/helpers/tmp/tmp-interpolate.js';
5
+ import { normalizeLayoutPaths, normalizeRootFolder as normalizeRootFolderValue, normalizeSourceFolder as normalizeSourceFolderValue, } from '../../../utils/helpers/tmp/path-normalize.js';
6
+ function isRecord(value) {
7
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
8
+ }
9
+ function stripDotSlash(value) {
10
+ return value.replace(/^\.\//, '').replace(/\/$/, '');
11
+ }
12
+ function readWatchIntervalValue(raw) {
13
+ if (typeof raw === 'number' || typeof raw === 'string')
14
+ return raw;
15
+ return undefined;
16
+ }
17
+ export function normalizeGlobalType(value) {
18
+ if (value === undefined || value === null || value === '')
19
+ return undefined;
20
+ const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
21
+ if (raw === GlobalTypeEnum.WORKSPACE)
22
+ return GlobalTypeEnum.WORKSPACE;
23
+ if (raw === GlobalTypeEnum.API_SERVICE)
24
+ return GlobalTypeEnum.API_SERVICE;
25
+ if (raw === GlobalTypeEnum.FRONTEND)
26
+ return GlobalTypeEnum.FRONTEND;
27
+ throw new Error(`${defaults.packageName}: configs.global.type must be one of ${Object.values(GlobalTypeEnum).join('|')} (got "${String(value)}")`);
28
+ }
29
+ export function normalizeRuntime(value) {
30
+ const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
31
+ if (raw === RuntimeEnum.NODE)
32
+ return RuntimeEnum.NODE;
33
+ if (raw === RuntimeEnum.BUN)
34
+ return RuntimeEnum.BUN;
35
+ if (!raw) {
36
+ throw new Error(`${defaults.packageName}: configs.global.runtime is required (${Object.values(RuntimeEnum).join('|')})`);
37
+ }
38
+ throw new Error(`${defaults.packageName}: unknown configs.global.runtime "${String(value)}" (expected ${Object.values(RuntimeEnum).join('|')})`);
39
+ }
40
+ export function normalizeBundler(value) {
41
+ const raw = typeof value === 'string' ? value.trim().toLowerCase() : '';
42
+ if (!raw)
43
+ return BundlerEnum.AUTO;
44
+ if (raw === BundlerEnum.TSC)
45
+ return BundlerEnum.TSC;
46
+ if (raw === BundlerEnum.ESBUILD)
47
+ return BundlerEnum.ESBUILD;
48
+ if (raw === BundlerEnum.BUN)
49
+ return BundlerEnum.BUN;
50
+ if (raw === BundlerEnum.AUTO)
51
+ return BundlerEnum.AUTO;
52
+ throw new Error(`${defaults.packageName}: unknown configs.global.build.bundler "${String(value)}" (expected ${Object.values(BundlerEnum).join('|')})`);
53
+ }
54
+ export function resolveEffectiveBundler(bundler, _runtime) {
55
+ if (bundler !== BundlerEnum.AUTO)
56
+ return bundler;
57
+ return BundlerEnum.TSC;
58
+ }
59
+ export function normalizeRootFolder(value) {
60
+ return normalizeRootFolderValue(value, defaults.packageRootFolder);
61
+ }
62
+ export function normalizeSourceFolder(value) {
63
+ return normalizeSourceFolderValue(value, seedFromTmp.sourceFolder);
64
+ }
65
+ export function readTmpGlobalPathsBlock(configs) {
66
+ const global = isRecord(configs?.global) ? configs.global : {};
67
+ const paths = isRecord(global.paths) ? global.paths : {};
68
+ const special = isRecord(paths.special) ? paths.special : {};
69
+ const root = typeof paths.root === 'string' ? paths.root.trim() : '';
70
+ if (!root) {
71
+ throw new Error(`${defaults.packageName}: configs.global.paths.root is required`);
72
+ }
73
+ return {
74
+ root,
75
+ tmp: typeof paths.tmp === 'string' ? paths.tmp : 'tmp.yml',
76
+ source: typeof paths.source === 'string' ? paths.source : seedFromTmp.sourceFolder,
77
+ special: {
78
+ tests: typeof special.tests === 'string' ? special.tests : undefined,
79
+ environments: typeof special.environments === 'string' ? special.environments : undefined,
80
+ dist: typeof special.dist === 'string' ? special.dist : undefined,
81
+ },
82
+ };
83
+ }
84
+ export function resolveMergedPaths(configs) {
85
+ const paths = readTmpGlobalPathsBlock(configs);
86
+ const root = stripDotSlash(normalizeRootFolder(paths.root));
87
+ const tmpName = stripDotSlash(paths.tmp ?? 'tmp.yml');
88
+ const source = stripDotSlash(normalizeSourceFolder(paths.source));
89
+ const special = normalizeLayoutPaths(paths.special, seedFromTmp.layout);
90
+ return {
91
+ root,
92
+ source,
93
+ special,
94
+ tmpRelPath: `${root}/${tmpName}`.replace(/\/+/g, '/'),
95
+ };
96
+ }
97
+ export function readTmpGlobalBlock(configs) {
98
+ const global = isRecord(configs?.global) ? configs.global : {};
99
+ const varsRaw = isRecord(global.vars) ? global.vars : {};
100
+ const typeRaw = global.type;
101
+ if (typeof global.framework !== 'string' || !global.framework.trim()) {
102
+ throw new Error(`${defaults.packageName}: configs.global.framework is required`);
103
+ }
104
+ return {
105
+ runtime: normalizeRuntime(global.runtime),
106
+ type: typeRaw !== undefined ? normalizeGlobalType(typeRaw) : undefined,
107
+ framework: global.framework.trim(),
108
+ paths: readTmpGlobalPathsBlock(configs),
109
+ vars: { ...varsRaw },
110
+ build: isRecord(global.build) ? { ...global.build } : undefined,
111
+ options: isRecord(global.options)
112
+ ? {
113
+ fileWatchIntervalMs: readWatchIntervalValue(global.options.fileWatchIntervalMs),
114
+ }
115
+ : undefined,
116
+ };
117
+ }
118
+ /** Reject removed tmp.yml keys (depends.build, cluster, etc.). */
119
+ export function assertNoLegacyTmpKeys(configs) {
120
+ const depends = isRecord(configs?.depends) ? configs.depends : {};
121
+ if ('build' in depends && depends.build !== undefined && depends.build !== null) {
122
+ throw new Error(`${defaults.packageName}: configs.depends.build removed — use configs.global.build`);
123
+ }
124
+ const loaders = isRecord(depends.loaders) ? depends.loaders : {};
125
+ if ('build' in loaders && loaders.build !== undefined && loaders.build !== null) {
126
+ throw new Error(`${defaults.packageName}: configs.depends.loaders.build removed — use configs.global.build`);
127
+ }
128
+ if (isRecord(configs?.cluster)) {
129
+ throw new Error(`${defaults.packageName}: configs.cluster removed — deployment name is project.name (CLI --deployment overrides)`);
130
+ }
131
+ const global = isRecord(configs?.global) ? configs.global : {};
132
+ if ('fileWatchIntervalMs' in global && global.fileWatchIntervalMs !== undefined && global.fileWatchIntervalMs !== null) {
133
+ throw new Error(`${defaults.packageName}: configs.global.fileWatchIntervalMs removed — use configs.global.options.fileWatchIntervalMs`);
134
+ }
135
+ }
136
+ /** Build options from configs.global.build only. */
137
+ export function readTmpBuildBlock(configs) {
138
+ assertNoLegacyTmpKeys(configs);
139
+ const global = isRecord(configs?.global) ? configs.global : {};
140
+ return isRecord(global.build) ? { ...global.build } : {};
141
+ }
142
+ export function readTmpDependsBlock(configs) {
143
+ assertNoLegacyTmpKeys(configs);
144
+ const depends = isRecord(configs?.depends) ? configs.depends : {};
145
+ const loaders = isRecord(depends.loaders) ? { ...depends.loaders } : undefined;
146
+ return {
147
+ protocols: depends.protocols,
148
+ loaders,
149
+ };
150
+ }
151
+ export function resolveTmpDeploymentName(tmp) {
152
+ assertNoLegacyTmpKeys(isRecord(tmp?.configs) ? tmp.configs : undefined);
153
+ const project = isRecord(tmp?.project) ? tmp.project : {};
154
+ const projectName = typeof project.name === 'string' ? project.name.trim() : undefined;
155
+ return projectName || undefined;
156
+ }
157
+ function buildNormalizedDepends(depends) {
158
+ return {
159
+ protocols: depends.protocols,
160
+ loaders: depends.loaders,
161
+ };
162
+ }
163
+ export function buildTmpVarContext(global) {
164
+ return {
165
+ ...global.vars,
166
+ runtime: global.runtime,
167
+ global,
168
+ };
169
+ }
170
+ export function applyTmpGlobalVars(tmp) {
171
+ const configs = isRecord(tmp.configs) ? tmp.configs : {};
172
+ const global = readTmpGlobalBlock(configs);
173
+ return interpolateWithContext(tmp, buildTmpVarContext(global));
174
+ }
175
+ export function resolveTmpRuntimeConfigs(tmp) {
176
+ const configs = isRecord(tmp?.configs) ? tmp.configs : {};
177
+ assertNoLegacyTmpKeys(configs);
178
+ const global = readTmpGlobalBlock(configs);
179
+ const depends = readTmpDependsBlock(configs);
180
+ const merged = resolveMergedPaths(configs);
181
+ return {
182
+ global: {
183
+ ...global,
184
+ build: readTmpBuildBlock(configs),
185
+ },
186
+ depends: buildNormalizedDepends(depends),
187
+ deploymentName: resolveTmpDeploymentName(tmp),
188
+ rootFolderPath: merged.root,
189
+ tmpRelPath: merged.tmpRelPath,
190
+ };
191
+ }
192
+ export function normalizeTmpDocument(tmp) {
193
+ const interpolated = applyTmpGlobalVars(tmp);
194
+ return {
195
+ ...interpolated,
196
+ configs: resolveTmpRuntimeConfigs(interpolated),
197
+ };
198
+ }
199
+ export function resolveProjectRootFromTmpPath(tmpFilePath, configs) {
200
+ const merged = resolveMergedPaths(configs);
201
+ const abs = tmpFilePath.replace(/\\/g, '/');
202
+ const rel = merged.tmpRelPath;
203
+ if (abs.endsWith(`/${rel}`)) {
204
+ return abs.slice(0, -(rel.length + 1));
205
+ }
206
+ throw new Error(`${defaults.packageName}: tmp path ${tmpFilePath} does not match configs.global.paths (${rel})`);
207
+ }
208
+ export function resolveTmpAbsPath(projectRoot, configs) {
209
+ const merged = resolveMergedPaths(configs);
210
+ return `${projectRoot.replace(/\\/g, '/').replace(/\/$/, '')}/${merged.tmpRelPath}`;
211
+ }
@@ -1 +1,23 @@
1
- import{packageDefaults as J}from "../../../utils/constants/index.js";import{readTmpCoreBlock as P}from "../../../utils/helpers/tmp/tmp-schema.js";const Q=J.tmpWatchDefaults;function z(y){const j=Q?.[y];if(typeof j!=="number"||!Number.isFinite(j))throw Error(`${J.packageName}: tmpWatchDefaults.${y} missing in defaults.json`);return j}export function resolveTmpWatchIntervalMs(y){const j=y?.configs,K=P(j),G=z("intervalMs"),M=K.tmp?.fileWatchIntervalMs??G,I=Number(M);if(!Number.isFinite(I))return G;const N=z("minIntervalMs"),O=z("maxIntervalMs");return Math.min(O,Math.max(N,Math.round(I)))}
1
+ import { packageDefaults } from '../../../utils/constants/index.js';
2
+ const WATCH_DEFAULTS = packageDefaults.tmpWatchDefaults;
3
+ function requireWatchBound(name) {
4
+ const value = WATCH_DEFAULTS?.[name];
5
+ if (typeof value !== 'number' || !Number.isFinite(value)) {
6
+ throw new Error(`${packageDefaults.packageName}: tmpWatchDefaults.${name} missing in defaults.json`);
7
+ }
8
+ return value;
9
+ }
10
+ export function resolveTmpWatchIntervalMs(tmp) {
11
+ const configs = tmp?.configs;
12
+ const global = configs?.global;
13
+ const options = global?.options;
14
+ const fallback = requireWatchBound('intervalMs');
15
+ const raw = options?.fileWatchIntervalMs ?? fallback;
16
+ const parsed = Number(raw);
17
+ if (!Number.isFinite(parsed)) {
18
+ return fallback;
19
+ }
20
+ const min = requireWatchBound('minIntervalMs');
21
+ const max = requireWatchBound('maxIntervalMs');
22
+ return Math.min(max, Math.max(min, Math.round(parsed)));
23
+ }
@@ -1,2 +1,157 @@
1
- import Q from"node:fs";import Y from"node:path";import{packageDefaults as M}from "../../../utils/constants/index.js";import{normalizeSourceFolder as C}from "../../../utils/helpers/tmp/path-normalize.js";function Z(j){return String(j).replace(/^\.\//,"")}function _(){const j=M.buildDefaults?.tsconfig;if(!j||!String(j).trim())throw Error(`${M.packageName}: buildDefaults.tsconfig missing in defaults.json`);return String(j)}export function layoutOptionsFromRuntimeConfigs(j){const B=j.service?.paths,G=B?.special;return{rootFolderPath:j.rootFolderPath||M.packageRootFolder,mainFolderPath:C(B?.source,M.mainSourceFolder),pathsDist:G?.dist||M.layoutPaths.dist,pathsTests:G?.tests||M.layoutPaths.tests}}export function layoutFingerprint(j){return[j.rootFolderPath,Z(j.mainFolderPath),j.pathsDist,j.pathsTests].join("\x00")}export function resolveRecommendedTsconfig(j){const B=Z(j.mainFolderPath),G=j.rootFolderPath,I=M.pathAliasKey;return{include:[B],exclude:[`${G}/${j.pathsTests}`],compilerOptions:{baseUrl:".",paths:{[I]:[`${B}/*`]},rootDir:`./${B}`,outDir:`./${G}/${j.pathsDist}`}}}function E(j){const B=Y.join(j,"package.json");if(!Q.existsSync(B))return`${M.packageName}/tsconfig.base.json`;try{if(JSON.parse(Q.readFileSync(B,"utf8")).name===M.packageName)return"./tsconfig.base.json"}catch{}return`${M.packageName}/tsconfig.base.json`}function W(j,B,G){const I=B.compilerOptions??{};return{...B,extends:B.extends??G,include:j.include,exclude:j.exclude,compilerOptions:{...I,baseUrl:j.compilerOptions.baseUrl,paths:j.compilerOptions.paths,rootDir:j.compilerOptions.rootDir,outDir:j.compilerOptions.outDir}}}export function auditTsconfigAgainstLayout(j,B,G=_()){const I=Y.join(j,G);if(!Q.existsSync(I))return{ok:!1,missing:!0,notes:[`${G} missing`]};let J;try{J=JSON.parse(Q.readFileSync(I,"utf8"))}catch{return{ok:!1,missing:!1,notes:[`${G} unreadable`]}}const H=resolveRecommendedTsconfig(B),N=[],V=J.compilerOptions??{},X=M.pathAliasKey;if(V.outDir!==H.compilerOptions.outDir)N.push("outDir drift");if(!(Array.isArray(J.include)?J.include.map(String):[]).some((A)=>Z(A)===H.include[0]))N.push("include drift");const $=V.paths?.[X];if(JSON.stringify($)!==JSON.stringify(H.compilerOptions.paths[X]))N.push(`paths ${X} drift`);return{ok:N.length===0,missing:!1,notes:N}}export function writeTsconfigFromLayout(j,B,G=_()){const I=Y.join(j,G),J=!Q.existsSync(I);let H={};if(!J)try{H=JSON.parse(Q.readFileSync(I,"utf8"))}catch{H={}}const N=resolveRecommendedTsconfig(B),V=W(N,H,E(j));Q.writeFileSync(I,`${JSON.stringify(V,null,2)}
2
- `,"utf8");return{wrote:!0,created:J,abs:I}}let U=null;export function resetToolchainHealState(){U=null}export function healToolchainIfLayoutNeedsSync(j,B,G={}){const I=layoutOptionsFromRuntimeConfigs(B),J=layoutFingerprint(I),H=_(),N=auditTsconfigAgainstLayout(j,I,H);if(U===null){U=J;if(N.ok)return{healed:!1,tsconfigRel:H,fingerprint:J};writeTsconfigFromLayout(j,I,H);if(!G.quiet)console.info(`[${M.packageName}] toolchain auto-synced (${H}) — bootstrap layout drift`);return{healed:!0,reason:"bootstrap",tsconfigRel:H,fingerprint:J}}if(J===U)return{healed:!1,tsconfigRel:H,fingerprint:J};U=J;writeTsconfigFromLayout(j,I,H);if(!G.quiet)console.info(`[${M.packageName}] toolchain auto-synced (${H}) — tmp layout paths changed`);return{healed:!0,reason:"layout-changed",tsconfigRel:H,fingerprint:J}}
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { packageDefaults } from '../../../utils/constants/index.js';
4
+ import { normalizeSourceFolder } from '../../../utils/helpers/tmp/path-normalize.js';
5
+ function stripLeadingDotSlash(value) {
6
+ return String(value).replace(/^\.\//, '');
7
+ }
8
+ function requireTsconfigRel() {
9
+ const rel = packageDefaults.buildDefaults?.tsconfig;
10
+ if (!rel || !String(rel).trim()) {
11
+ throw new Error(`${packageDefaults.packageName}: buildDefaults.tsconfig missing in defaults.json`);
12
+ }
13
+ return String(rel);
14
+ }
15
+ export function layoutOptionsFromRuntimeConfigs(configs) {
16
+ const special = configs.global.paths?.special;
17
+ return {
18
+ rootFolderPath: configs.rootFolderPath || packageDefaults.packageRootFolder,
19
+ mainFolderPath: normalizeSourceFolder(configs.global.paths?.source, packageDefaults.mainSourceFolder),
20
+ pathsDist: special?.dist || packageDefaults.layoutPaths.dist,
21
+ pathsTests: special?.tests || packageDefaults.layoutPaths.tests,
22
+ };
23
+ }
24
+ export function layoutFingerprint(options) {
25
+ return [
26
+ options.rootFolderPath,
27
+ stripLeadingDotSlash(options.mainFolderPath),
28
+ options.pathsDist,
29
+ options.pathsTests,
30
+ ].join('\0');
31
+ }
32
+ export function resolveRecommendedTsconfig(options) {
33
+ const mainFolder = stripLeadingDotSlash(options.mainFolderPath);
34
+ const rootFolder = options.rootFolderPath;
35
+ const aliasKey = packageDefaults.pathAliasKey;
36
+ return {
37
+ include: [mainFolder],
38
+ exclude: [`${rootFolder}/${options.pathsTests}`],
39
+ compilerOptions: {
40
+ baseUrl: '.',
41
+ paths: { [aliasKey]: [`${mainFolder}/*`] },
42
+ rootDir: `./${mainFolder}`,
43
+ outDir: `./${rootFolder}/${options.pathsDist}`,
44
+ },
45
+ };
46
+ }
47
+ function resolveTsconfigExtends(root) {
48
+ const pkgPath = path.join(root, 'package.json');
49
+ if (!fs.existsSync(pkgPath))
50
+ return `${packageDefaults.packageName}/tsconfig.base.json`;
51
+ try {
52
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
53
+ if (pkg.name === packageDefaults.packageName)
54
+ return './tsconfig.base.json';
55
+ }
56
+ catch {
57
+ /* fall through */
58
+ }
59
+ return `${packageDefaults.packageName}/tsconfig.base.json`;
60
+ }
61
+ function mergeTsconfigWithLayout(recommended, existing, extendsPath) {
62
+ const existingOpts = (existing.compilerOptions ?? {});
63
+ return {
64
+ ...existing,
65
+ extends: existing.extends ?? extendsPath,
66
+ include: recommended.include,
67
+ exclude: recommended.exclude,
68
+ compilerOptions: {
69
+ ...existingOpts,
70
+ baseUrl: recommended.compilerOptions.baseUrl,
71
+ paths: recommended.compilerOptions.paths,
72
+ rootDir: recommended.compilerOptions.rootDir,
73
+ outDir: recommended.compilerOptions.outDir,
74
+ },
75
+ };
76
+ }
77
+ export function auditTsconfigAgainstLayout(root, options, tsconfigRel = requireTsconfigRel()) {
78
+ const abs = path.join(root, tsconfigRel);
79
+ if (!fs.existsSync(abs)) {
80
+ return { ok: false, missing: true, notes: [`${tsconfigRel} missing`] };
81
+ }
82
+ let raw;
83
+ try {
84
+ raw = JSON.parse(fs.readFileSync(abs, 'utf8'));
85
+ }
86
+ catch {
87
+ return { ok: false, missing: false, notes: [`${tsconfigRel} unreadable`] };
88
+ }
89
+ const recommended = resolveRecommendedTsconfig(options);
90
+ const notes = [];
91
+ const opts = (raw.compilerOptions ?? {});
92
+ const aliasKey = packageDefaults.pathAliasKey;
93
+ if (opts.outDir !== recommended.compilerOptions.outDir) {
94
+ notes.push(`outDir drift`);
95
+ }
96
+ const include = Array.isArray(raw.include) ? raw.include.map(String) : [];
97
+ if (!include.some((item) => stripLeadingDotSlash(item) === recommended.include[0])) {
98
+ notes.push(`include drift`);
99
+ }
100
+ const alias = opts.paths?.[aliasKey];
101
+ if (JSON.stringify(alias) !== JSON.stringify(recommended.compilerOptions.paths[aliasKey])) {
102
+ notes.push(`paths ${aliasKey} drift`);
103
+ }
104
+ return { ok: notes.length === 0, missing: false, notes };
105
+ }
106
+ export function writeTsconfigFromLayout(root, options, tsconfigRel = requireTsconfigRel()) {
107
+ const abs = path.join(root, tsconfigRel);
108
+ const created = !fs.existsSync(abs);
109
+ let existing = {};
110
+ if (!created) {
111
+ try {
112
+ existing = JSON.parse(fs.readFileSync(abs, 'utf8'));
113
+ }
114
+ catch {
115
+ existing = {};
116
+ }
117
+ }
118
+ const recommended = resolveRecommendedTsconfig(options);
119
+ const merged = mergeTsconfigWithLayout(recommended, existing, resolveTsconfigExtends(root));
120
+ fs.writeFileSync(abs, `${JSON.stringify(merged, null, 2)}\n`, 'utf8');
121
+ return { wrote: true, created, abs };
122
+ }
123
+ let lastLayoutFingerprint = null;
124
+ /** Test/reset helper — clears in-memory layout fingerprint. */
125
+ export function resetToolchainHealState() {
126
+ lastLayoutFingerprint = null;
127
+ }
128
+ /**
129
+ * Live pulse: sync tsconfig only when layout paths change, or once on bootstrap if already drifted.
130
+ * Non-path tmp edits do not rewrite toolchain files.
131
+ */
132
+ export function healToolchainIfLayoutNeedsSync(root, configs, options = {}) {
133
+ const layout = layoutOptionsFromRuntimeConfigs(configs);
134
+ const fingerprint = layoutFingerprint(layout);
135
+ const tsconfigRel = requireTsconfigRel();
136
+ const audit = auditTsconfigAgainstLayout(root, layout, tsconfigRel);
137
+ if (lastLayoutFingerprint === null) {
138
+ lastLayoutFingerprint = fingerprint;
139
+ if (audit.ok) {
140
+ return { healed: false, tsconfigRel, fingerprint };
141
+ }
142
+ writeTsconfigFromLayout(root, layout, tsconfigRel);
143
+ if (!options.quiet) {
144
+ console.info(`[${packageDefaults.packageName}] toolchain auto-synced (${tsconfigRel}) — bootstrap layout drift`);
145
+ }
146
+ return { healed: true, reason: 'bootstrap', tsconfigRel, fingerprint };
147
+ }
148
+ if (fingerprint === lastLayoutFingerprint) {
149
+ return { healed: false, tsconfigRel, fingerprint };
150
+ }
151
+ lastLayoutFingerprint = fingerprint;
152
+ writeTsconfigFromLayout(root, layout, tsconfigRel);
153
+ if (!options.quiet) {
154
+ console.info(`[${packageDefaults.packageName}] toolchain auto-synced (${tsconfigRel}) — tmp layout paths changed`);
155
+ }
156
+ return { healed: true, reason: 'layout-changed', tsconfigRel, fingerprint };
157
+ }
@@ -1 +1,20 @@
1
- export const validateScopes=({scopes:i,permissions:t,resources:o})=>{const s=i.split(" ");function r(e){if(new Set(e).size!==e.length)return!0;return!1}if(r(s))return!1;return!s.some((e)=>{const[n,c]=e.split(":"),u=o.includes(n),l=t.includes(c);return!u||!l})};
1
+ export const validateScopes = ({ scopes, permissions, resources }) => {
2
+ const parsedScopes = scopes.split(' ');
3
+ function dublicateControl(parsedScopes) {
4
+ const uniqueScopes = new Set(parsedScopes);
5
+ if (uniqueScopes.size !== parsedScopes.length) {
6
+ return true;
7
+ }
8
+ return false;
9
+ }
10
+ if (dublicateControl(parsedScopes)) {
11
+ return false;
12
+ }
13
+ const isInvalid = parsedScopes.some((scope) => {
14
+ const [resource, permission] = scope.split(':');
15
+ const isValidResource = resources.includes(resource);
16
+ const isValidPermission = permissions.includes(permission);
17
+ return !isValidResource || !isValidPermission;
18
+ });
19
+ return !isInvalid;
20
+ };
@@ -0,0 +1,42 @@
1
+ import { GlobalTypeEnum } from '../../../utils/models/enums';
2
+ export declare const TMP_FILE = "tmp.yml";
3
+ export declare const SKIP_DIRS: Set<string>;
4
+ export type FolderStructure = {
5
+ api: string;
6
+ admin: string;
7
+ web: string;
8
+ };
9
+ export declare const DEFAULT_FOLDER_STRUCTURE: FolderStructure;
10
+ export type TmpMeta = {
11
+ path: string;
12
+ projectName?: string;
13
+ globalType?: string;
14
+ kubeconfig?: string;
15
+ clusterDeployment?: string;
16
+ pathsTmp?: string;
17
+ pathsRoot?: string;
18
+ folderStructure: FolderStructure;
19
+ };
20
+ export type WorkspaceEntry = {
21
+ name: string;
22
+ type: GlobalTypeEnum.API_SERVICE | GlobalTypeEnum.FRONTEND;
23
+ path: string;
24
+ tmp: string;
25
+ slot: keyof FolderStructure;
26
+ cluster?: string;
27
+ };
28
+ export declare function readTmpFile(filePath: string): TmpMeta;
29
+ export declare function parseFolderStructure(text: string): FolderStructure;
30
+ export { normalizeGlobalType } from '../../../utils/helpers/tmp/tmp-schema';
31
+ export declare function entryName(meta: TmpMeta): string | null;
32
+ export declare function entryType(meta: TmpMeta, slot: keyof FolderStructure): GlobalTypeEnum | null;
33
+ export declare function findWorkspaceRoot(startDir?: string): string | null;
34
+ export declare function findEntries(workspaceRoot: string): WorkspaceEntry[];
35
+ export declare function findApiServices(workspaceRoot: string): WorkspaceEntry[];
36
+ export declare function resolveEntryPath(workspaceRoot: string, name: string): string | null;
37
+ export declare function workspaceProjectName(workspaceRoot: string): string;
38
+ export declare function readWorkspaceGlobalTmp(workspaceRoot: string): {
39
+ fileWatchIntervalMs?: number;
40
+ };
41
+ /** @deprecated */ export declare const readWorkspaceCoreTmp: typeof readWorkspaceGlobalTmp;
42
+ export declare function workspaceTmpTemplate(projectName: string): string;