@xrystal/core 3.51.6 → 3.52.1
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.
- package/README.md +35 -1
- package/package.json +2 -1
- package/x/bin/commands/create.mjs +44 -0
- package/x/bin/commands/projects.mjs +53 -0
- package/x/bin/commands/sync.mjs +49 -1
- package/x/bin/commands/tmp.mjs +1 -1
- package/x/bin/helpers/.generated/.generated-from +2 -0
- package/x/bin/helpers/.generated/seed-from-tmp.mjs +25 -31
- package/x/bin/helpers/.generated/tmp-schema.mjs +156 -96
- package/x/bin/helpers/.generated/workspace.mjs +402 -0
- package/x/bin/helpers/.generated/xrystal-home-registry.mjs +310 -0
- package/x/bin/helpers/build-config.mjs +3 -2
- package/x/bin/helpers/cli-help.mjs +3 -1
- package/x/bin/helpers/project-artifacts.mjs +10 -0
- package/x/bin/helpers/tmp-config.mjs +13 -12
- package/x/bin/helpers/tmp-layout.mjs +28 -52
- package/x/bin/helpers/tmp-schema.mjs +9 -3
- package/x/bin/helpers/workspace-resolve.mjs +11 -0
- package/x/bin/helpers/workspace-scaffold.mjs +23 -0
- package/x/bin/helpers/xrystal-registry.mjs +13 -0
- package/x/bin/main-cli.js +2 -0
- package/x/dist/index.js +5 -1
- package/x/dist/loader/clients/index.js +22 -1
- package/x/dist/loader/configs/index.js +97 -1
- package/x/dist/loader/controller/index.js +267 -1
- package/x/dist/loader/dto/index.js +92 -1
- package/x/dist/loader/events/index.js +39 -1
- package/x/dist/loader/index.js +13 -1
- package/x/dist/loader/kafka/index.js +142 -1
- package/x/dist/loader/kafka/resolve-ssl.js +23 -1
- package/x/dist/loader/localizations/index.js +46 -1
- package/x/dist/loader/logger/index.js +229 -2
- package/x/dist/loader/mongo/index.js +52 -1
- package/x/dist/loader/mongo/resolve-connect.js +16 -1
- package/x/dist/loader/redis/index.js +57 -1
- package/x/dist/loader/redis/resolve-socket.js +31 -1
- package/x/dist/loader/registry/index.js +1 -1
- package/x/dist/loader/service/index.js +7 -1
- package/x/dist/loader/system/index.js +26 -1
- package/x/dist/project/index.js +51 -1
- package/x/dist/utils/constants/defaults.json +3 -1
- package/x/dist/utils/constants/index.d.ts +1 -0
- package/x/dist/utils/constants/index.js +42 -1
- package/x/dist/utils/constants/package-root.js +6 -1
- package/x/dist/utils/helpers/configs/index.js +1 -1
- package/x/dist/utils/helpers/context/controller-store.js +12 -1
- package/x/dist/utils/helpers/context/index.js +24 -1
- package/x/dist/utils/helpers/core/handlebars-resolve.js +15 -1
- package/x/dist/utils/helpers/core/index.js +46 -1
- package/x/dist/utils/helpers/core/paths.js +78 -1
- package/x/dist/utils/helpers/core/tmp-layout.d.ts +4 -4
- package/x/dist/utils/helpers/core/tmp-layout.js +229 -1
- package/x/dist/utils/helpers/date/index.js +48 -1
- package/x/dist/utils/helpers/dispatch/index.js +53 -1
- package/x/dist/utils/helpers/dto/index.js +10 -1
- package/x/dist/utils/helpers/filters/index.js +44 -1
- package/x/dist/utils/helpers/framework/index.js +18 -1
- package/x/dist/utils/helpers/handlers/adapters.js +41 -1
- package/x/dist/utils/helpers/handlers/execute.js +82 -1
- package/x/dist/utils/helpers/handlers/index.js +31 -1
- package/x/dist/utils/helpers/hash/crypto.js +22 -1
- package/x/dist/utils/helpers/id/index.js +24 -1
- package/x/dist/utils/helpers/index.d.ts +1 -0
- package/x/dist/utils/helpers/index.js +28 -1
- package/x/dist/utils/helpers/ip/index.js +21 -1
- package/x/dist/utils/helpers/is/index.js +35 -1
- package/x/dist/utils/helpers/kafka-loader-options/index.js +14 -1
- package/x/dist/utils/helpers/locales/index.js +82 -1
- package/x/dist/utils/helpers/logger-layer/index.js +33 -1
- package/x/dist/utils/helpers/math/index.js +14 -1
- package/x/dist/utils/helpers/middleware/index.js +36 -1
- package/x/dist/utils/helpers/node-env/index.js +20 -1
- package/x/dist/utils/helpers/objects/index.js +55 -1
- package/x/dist/utils/helpers/path/index.js +5 -1
- package/x/dist/utils/helpers/path/resolve-alias-path.d.ts +1 -1
- package/x/dist/utils/helpers/path/resolve-alias-path.js +62 -1
- package/x/dist/utils/helpers/protocol/index.d.ts +1 -1
- package/x/dist/utils/helpers/protocol/index.js +100 -1
- package/x/dist/utils/helpers/protocol/options.js +13 -1
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +3 -1
- package/x/dist/utils/helpers/registry/index.js +103 -1
- package/x/dist/utils/helpers/runtime/dto-access.js +5 -1
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -1
- package/x/dist/utils/helpers/runtime/index.js +2 -1
- package/x/dist/utils/helpers/runtime/shutdown.js +36 -1
- package/x/dist/utils/helpers/state/index.js +185 -1
- package/x/dist/utils/helpers/state/props-from-tmp.js +46 -1
- package/x/dist/utils/helpers/state/request-key-guard.js +43 -1
- package/x/dist/utils/helpers/state/scopes.js +69 -1
- package/x/dist/utils/helpers/string/index.js +9 -1
- package/x/dist/utils/helpers/timer/index.js +5 -1
- package/x/dist/utils/helpers/tmp/index.d.ts +2 -2
- package/x/dist/utils/helpers/tmp/index.js +8 -1
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +14 -1
- package/x/dist/utils/helpers/tmp/path-normalize.js +27 -1
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +42 -1
- package/x/dist/utils/helpers/tmp/seed-from-tmp.d.ts +2 -2
- package/x/dist/utils/helpers/tmp/seed-from-tmp.js +62 -1
- package/x/dist/utils/helpers/tmp/tmp-interpolate.js +22 -1
- package/x/dist/utils/helpers/tmp/tmp-loader.js +56 -1
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +35 -23
- package/x/dist/utils/helpers/tmp/tmp-schema.js +211 -1
- package/x/dist/utils/helpers/tmp/tmp-watch.js +23 -1
- package/x/dist/utils/helpers/tmp/toolchain-heal.js +157 -2
- package/x/dist/utils/helpers/validates/index.js +20 -1
- package/x/dist/utils/helpers/workspace/index.d.ts +42 -0
- package/x/dist/utils/helpers/workspace/index.js +222 -0
- package/x/dist/utils/helpers/xrystal-home/registry.d.ts +32 -0
- package/x/dist/utils/helpers/xrystal-home/registry.js +92 -0
- package/x/dist/utils/index.js +3 -1
- package/x/dist/utils/models/classes/class.clients.js +142 -1
- package/x/dist/utils/models/classes/class.interfaces.js +10 -1
- package/x/dist/utils/models/classes/class.service-locator.js +16 -1
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +61 -1
- package/x/dist/utils/models/classes/class.x.js +181 -1
- package/x/dist/utils/models/enums/index.d.ts +9 -1
- package/x/dist/utils/models/enums/index.js +169 -1
- package/x/dist/utils/models/index.js +9 -1
- package/x/dist/utils/models/types/index.js +2 -1
- package/x/templates/api-service/tmp.yml +59 -0
- package/x/tmp.yml +7 -50
|
@@ -1 +1,69 @@
|
|
|
1
|
-
import{GStoreScopeEnum
|
|
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(
|
|
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
|
+
}
|
|
@@ -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,
|
|
6
|
-
export { loadSeedFromBundledTmp, seedFromTmp, type SeedFromTmp,
|
|
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
|
|
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
|
|
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(
|
|
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
|
|
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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
8
|
-
root
|
|
7
|
+
export type TmpGlobalPathsBlock = {
|
|
8
|
+
root: string;
|
|
9
|
+
tmp?: string;
|
|
9
10
|
source?: string;
|
|
10
|
-
special?:
|
|
11
|
+
special?: TmpSpecialPaths;
|
|
11
12
|
};
|
|
12
|
-
export type
|
|
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
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
51
|
-
export declare function
|
|
52
|
-
|
|
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;
|