@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.
- package/README.md +35 -1
- package/package.json +1 -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 +9 -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.d.ts +6 -0
- 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/tmp.yml +7 -50
|
@@ -1 +1,62 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import defaults from '../../../utils/constants/defaults.json' with { type: 'json' };
|
|
4
|
+
const MODULE_EXTS = ['.ts', '.js', '.mjs'];
|
|
5
|
+
function stripDotSlash(value) {
|
|
6
|
+
return String(value).replace(/^\.\//, '');
|
|
7
|
+
}
|
|
8
|
+
function findModuleFile(basePath) {
|
|
9
|
+
for (const ext of MODULE_EXTS) {
|
|
10
|
+
const asFile = `${basePath}${ext}`;
|
|
11
|
+
if (fs.existsSync(asFile))
|
|
12
|
+
return asFile;
|
|
13
|
+
}
|
|
14
|
+
for (const ext of MODULE_EXTS) {
|
|
15
|
+
const asIndex = path.join(basePath, `index${ext}`);
|
|
16
|
+
if (fs.existsSync(asIndex))
|
|
17
|
+
return asIndex;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
/** Resolve `@/…` the same way as tsconfig paths (`@/*` → `{sourceFolder}/*`), with dist fallback for prod. */
|
|
22
|
+
export function resolveAliasModulePath(spec, options = {}) {
|
|
23
|
+
const cwd = options.cwd ?? process.cwd();
|
|
24
|
+
const aliasPrefix = options.aliasPrefix ?? defaults.pathAliasKey.replace('*', '');
|
|
25
|
+
if (!spec.startsWith(aliasPrefix)) {
|
|
26
|
+
return path.isAbsolute(spec) ? spec : path.resolve(cwd, spec);
|
|
27
|
+
}
|
|
28
|
+
const sourceFolder = stripDotSlash(options.sourceFolder ?? 'source');
|
|
29
|
+
let rest = spec.slice(aliasPrefix.length).replace(/^\/+/, '');
|
|
30
|
+
// Legacy tmp.yml: `@/source/foo` → same as `@/foo` (tsconfig `@/*` already maps to source/*).
|
|
31
|
+
if (rest === sourceFolder || rest.startsWith(`${sourceFolder}/`)) {
|
|
32
|
+
rest = rest === sourceFolder ? '' : rest.slice(sourceFolder.length + 1);
|
|
33
|
+
}
|
|
34
|
+
const sourceBase = path.join(cwd, sourceFolder, rest);
|
|
35
|
+
const fromSource = findModuleFile(sourceBase);
|
|
36
|
+
if (fromSource)
|
|
37
|
+
return fromSource;
|
|
38
|
+
const rootFolder = stripDotSlash(options.rootFolder ?? defaults.packageRootFolder);
|
|
39
|
+
const distSegment = stripDotSlash(options.distSegment ?? 'dist');
|
|
40
|
+
const distBase = path.join(cwd, rootFolder, distSegment, rest);
|
|
41
|
+
const fromDist = findModuleFile(distBase);
|
|
42
|
+
if (fromDist)
|
|
43
|
+
return fromDist;
|
|
44
|
+
return sourceBase;
|
|
45
|
+
}
|
|
46
|
+
/** Resolve tmp.yml loader `loadPath` — `@/` modules or paths relative to `paths.root`. */
|
|
47
|
+
export function resolveTmpLoadPath(spec, tmp, cwd = process.cwd()) {
|
|
48
|
+
const aliasPrefix = defaults.pathAliasKey.replace('*', '');
|
|
49
|
+
const configs = tmp.configs ?? {};
|
|
50
|
+
if (!spec.startsWith(aliasPrefix)) {
|
|
51
|
+
const root = configs.rootFolderPath ?? defaults.packageRootFolder;
|
|
52
|
+
return path.resolve(cwd, root, spec);
|
|
53
|
+
}
|
|
54
|
+
const paths = configs.global?.paths ?? {};
|
|
55
|
+
const special = paths.special ?? {};
|
|
56
|
+
return resolveAliasModulePath(spec, {
|
|
57
|
+
cwd,
|
|
58
|
+
sourceFolder: stripDotSlash(String(paths.source ?? 'source')),
|
|
59
|
+
rootFolder: configs.rootFolderPath ?? defaults.packageRootFolder,
|
|
60
|
+
distSegment: stripDotSlash(String(special.dist ?? 'dist')),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
@@ -4,7 +4,7 @@ declare const REALTIME_MIDDLEWARE_HINT: string;
|
|
|
4
4
|
export declare function parseProtocol(value: unknown): ProtocolEnum;
|
|
5
5
|
export declare function isRealtimeProtocol(protocol?: ProtocolEnum): boolean;
|
|
6
6
|
export declare function isHttpProtocol(protocol?: ProtocolEnum): boolean;
|
|
7
|
-
export type TmpConfigs = NonNullable<ReturnType<typeof getRuntimeTmpConfigs>>['
|
|
7
|
+
export type TmpConfigs = NonNullable<ReturnType<typeof getRuntimeTmpConfigs>>['depends'];
|
|
8
8
|
export declare function resolveProtocolsFromConfig(configs?: TmpConfigs): ProtocolEnum[];
|
|
9
9
|
export declare function getConfiguredProtocols(): ProtocolEnum[];
|
|
10
10
|
export declare function getConfiguredRealtimeProtocols(configs?: TmpConfigs): ProtocolEnum[];
|
|
@@ -1 +1,100 @@
|
|
|
1
|
-
import{Constants
|
|
1
|
+
import { Constants } from '../../../utils/constants/index.js';
|
|
2
|
+
import { ProtocolEnum } from '../../../utils/models/enums/index.js';
|
|
3
|
+
import { getRuntimeTmpConfigs } from '../../../utils/helpers/tmp/runtime-tmp.js';
|
|
4
|
+
const PROTOCOL_ALIASES = {
|
|
5
|
+
http: ProtocolEnum.HTTP,
|
|
6
|
+
https: ProtocolEnum.HTTPS,
|
|
7
|
+
ws: ProtocolEnum.WEBSOCKET,
|
|
8
|
+
websocket: ProtocolEnum.WEBSOCKET,
|
|
9
|
+
socketio: ProtocolEnum.SOCKETIO,
|
|
10
|
+
socket: ProtocolEnum.SOCKETIO,
|
|
11
|
+
};
|
|
12
|
+
const REALTIME_MIDDLEWARE_HINT = `[${Constants.packageName}] tmp.yml lists both ws and socketio — use realtimeMiddleware("ws") or realtimeMiddleware("socketio")`;
|
|
13
|
+
export function parseProtocol(value) {
|
|
14
|
+
if (!value)
|
|
15
|
+
return ProtocolEnum.HTTP;
|
|
16
|
+
const key = String(value).toLowerCase().replace(/[-_\s.]/g, '');
|
|
17
|
+
if (PROTOCOL_ALIASES[key])
|
|
18
|
+
return PROTOCOL_ALIASES[key];
|
|
19
|
+
const values = Object.values(ProtocolEnum);
|
|
20
|
+
return values.includes(String(value)) ? value : ProtocolEnum.HTTP;
|
|
21
|
+
}
|
|
22
|
+
export function isRealtimeProtocol(protocol) {
|
|
23
|
+
return protocol === ProtocolEnum.WEBSOCKET || protocol === ProtocolEnum.SOCKETIO;
|
|
24
|
+
}
|
|
25
|
+
export function isHttpProtocol(protocol) {
|
|
26
|
+
return !protocol || protocol === ProtocolEnum.HTTP || protocol === ProtocolEnum.HTTPS;
|
|
27
|
+
}
|
|
28
|
+
function tmpConfigsFromRuntime() {
|
|
29
|
+
return getRuntimeTmpConfigs()?.depends;
|
|
30
|
+
}
|
|
31
|
+
export function resolveProtocolsFromConfig(configs) {
|
|
32
|
+
const raw = configs?.protocols;
|
|
33
|
+
if (!raw)
|
|
34
|
+
return [ProtocolEnum.HTTP];
|
|
35
|
+
return (Array.isArray(raw) ? raw : [raw]).map(parseProtocol);
|
|
36
|
+
}
|
|
37
|
+
export function getConfiguredProtocols() {
|
|
38
|
+
try {
|
|
39
|
+
return resolveProtocolsFromConfig(tmpConfigsFromRuntime());
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return [ProtocolEnum.HTTP, ProtocolEnum.WEBSOCKET];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export function getConfiguredRealtimeProtocols(configs) {
|
|
46
|
+
return resolveProtocolsFromConfig(configs).filter(isRealtimeProtocol);
|
|
47
|
+
}
|
|
48
|
+
export function defaultRealtimeProtocolFromConfig(configs) {
|
|
49
|
+
const realtime = getConfiguredRealtimeProtocols(configs);
|
|
50
|
+
if (realtime.length === 1)
|
|
51
|
+
return realtime[0];
|
|
52
|
+
if (realtime.length > 1)
|
|
53
|
+
return undefined;
|
|
54
|
+
return ProtocolEnum.WEBSOCKET;
|
|
55
|
+
}
|
|
56
|
+
export function getDefaultRealtimeProtocol() {
|
|
57
|
+
try {
|
|
58
|
+
return defaultRealtimeProtocolFromConfig(tmpConfigsFromRuntime());
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return ProtocolEnum.WEBSOCKET;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function resolveRealtimeMiddlewareProtocol(protocol, configs) {
|
|
65
|
+
if (protocol !== undefined && protocol !== null && protocol !== '') {
|
|
66
|
+
return parseProtocol(protocol);
|
|
67
|
+
}
|
|
68
|
+
let cfg = configs;
|
|
69
|
+
if (!cfg) {
|
|
70
|
+
try {
|
|
71
|
+
cfg = tmpConfigsFromRuntime();
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return ProtocolEnum.WEBSOCKET;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const realtime = getConfiguredRealtimeProtocols(cfg);
|
|
78
|
+
if (realtime.length === 1)
|
|
79
|
+
return realtime[0];
|
|
80
|
+
if (realtime.length > 1)
|
|
81
|
+
throw new Error(REALTIME_MIDDLEWARE_HINT);
|
|
82
|
+
return ProtocolEnum.WEBSOCKET;
|
|
83
|
+
}
|
|
84
|
+
export function detectSocketProtocol(socket, explicit) {
|
|
85
|
+
if (explicit)
|
|
86
|
+
return explicit;
|
|
87
|
+
const s = socket;
|
|
88
|
+
if (s?.__xrystalProtocol)
|
|
89
|
+
return s.__xrystalProtocol;
|
|
90
|
+
return ProtocolEnum.WEBSOCKET;
|
|
91
|
+
}
|
|
92
|
+
export function attachSocketTransport(socket, protocol, runtime) {
|
|
93
|
+
const s = socket;
|
|
94
|
+
if (protocol === ProtocolEnum.SOCKETIO)
|
|
95
|
+
runtime.attachSocketIo(socket);
|
|
96
|
+
else
|
|
97
|
+
runtime.attachWebSocket(socket);
|
|
98
|
+
s.__xrystalProtocol = protocol;
|
|
99
|
+
}
|
|
100
|
+
export { REALTIME_MIDDLEWARE_HINT };
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
import{FrameworkEnum
|
|
1
|
+
import { FrameworkEnum, ProtocolEnum } from '../../../utils/models/index.js';
|
|
2
|
+
import { parseProtocol } from '../../../utils/helpers/protocol/index.js';
|
|
3
|
+
export function resolveCtrOptions(opts) {
|
|
4
|
+
if (opts === undefined)
|
|
5
|
+
return { protocol: ProtocolEnum.HTTP };
|
|
6
|
+
if (typeof opts === 'string') {
|
|
7
|
+
const fwValues = Object.values(FrameworkEnum);
|
|
8
|
+
if (fwValues.includes(opts))
|
|
9
|
+
return { framework: opts, protocol: ProtocolEnum.HTTP };
|
|
10
|
+
return { protocol: parseProtocol(opts) };
|
|
11
|
+
}
|
|
12
|
+
return { protocol: ProtocolEnum.HTTP, ...opts };
|
|
13
|
+
}
|
|
@@ -14,7 +14,13 @@ export interface RegistryEntry {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function buildInternalBaseUrl(serviceName: string, port?: number): string;
|
|
16
16
|
export declare function registryRedisHashKey(nodeEnv: string): string;
|
|
17
|
+
export declare const REGISTRY_TARGET_PREFIX = "&";
|
|
17
18
|
export declare function normalizeRegistryServiceName(name: string): string;
|
|
19
|
+
/** Gateway/mongo target ref — `&iam` means resolve internalBaseUrl from registry. */
|
|
20
|
+
export declare function isRegistryTargetRef(value: string): boolean;
|
|
21
|
+
/** Strip leading `&` and normalize service name (`&root` → `core`). */
|
|
22
|
+
export declare function parseRegistryTargetRef(value: string): string;
|
|
23
|
+
export declare function resolveRegistryTargetRef(target: string, resolveService?: (name: string) => string | undefined): string | undefined;
|
|
18
24
|
export declare function isAbsoluteHttpUrl(value: string): boolean;
|
|
19
25
|
export declare function looksLikeLegacyConfigTargetKey(key: string): boolean;
|
|
20
26
|
export declare function normalizeRegistryDoc(doc: Record<string, unknown> | null | undefined): RegistryEntry | null;
|
|
@@ -1 +1,103 @@
|
|
|
1
|
-
export const REGISTRY_COLLECTION
|
|
1
|
+
export const REGISTRY_COLLECTION = 'registry';
|
|
2
|
+
export const LEGACY_TARGET_KEY_TO_SERVICE = {
|
|
3
|
+
coreTargetUri: 'core',
|
|
4
|
+
rootTargetUri: 'core',
|
|
5
|
+
iamTargetUri: 'iam',
|
|
6
|
+
websocketTargetUri: 'websocket',
|
|
7
|
+
mqttTargetUri: 'mqtt',
|
|
8
|
+
};
|
|
9
|
+
export const TARGET_SERVICE_ALIASES = {
|
|
10
|
+
root: 'core',
|
|
11
|
+
};
|
|
12
|
+
export function buildInternalBaseUrl(serviceName, port = 3000) {
|
|
13
|
+
const slug = String(serviceName ?? '').trim();
|
|
14
|
+
if (!slug)
|
|
15
|
+
return '';
|
|
16
|
+
return `http://${slug}-service:${port}`;
|
|
17
|
+
}
|
|
18
|
+
export function registryRedisHashKey(nodeEnv) {
|
|
19
|
+
return `${nodeEnv}:registry`;
|
|
20
|
+
}
|
|
21
|
+
export const REGISTRY_TARGET_PREFIX = '&';
|
|
22
|
+
export function normalizeRegistryServiceName(name) {
|
|
23
|
+
const key = String(name ?? '').trim();
|
|
24
|
+
if (!key)
|
|
25
|
+
return '';
|
|
26
|
+
return TARGET_SERVICE_ALIASES[key] ?? key;
|
|
27
|
+
}
|
|
28
|
+
/** Gateway/mongo target ref — `&iam` means resolve internalBaseUrl from registry. */
|
|
29
|
+
export function isRegistryTargetRef(value) {
|
|
30
|
+
return String(value ?? '').trim().startsWith(REGISTRY_TARGET_PREFIX);
|
|
31
|
+
}
|
|
32
|
+
/** Strip leading `&` and normalize service name (`&root` → `core`). */
|
|
33
|
+
export function parseRegistryTargetRef(value) {
|
|
34
|
+
const raw = String(value ?? '').trim();
|
|
35
|
+
if (!raw.startsWith(REGISTRY_TARGET_PREFIX)) {
|
|
36
|
+
return normalizeRegistryServiceName(raw);
|
|
37
|
+
}
|
|
38
|
+
return normalizeRegistryServiceName(raw.slice(REGISTRY_TARGET_PREFIX.length));
|
|
39
|
+
}
|
|
40
|
+
export function resolveRegistryTargetRef(target, resolveService) {
|
|
41
|
+
if (!isRegistryTargetRef(target) || !resolveService)
|
|
42
|
+
return undefined;
|
|
43
|
+
return resolveService(parseRegistryTargetRef(target));
|
|
44
|
+
}
|
|
45
|
+
export function isAbsoluteHttpUrl(value) {
|
|
46
|
+
return /^https?:\/\//i.test(String(value ?? '').trim());
|
|
47
|
+
}
|
|
48
|
+
export function looksLikeLegacyConfigTargetKey(key) {
|
|
49
|
+
return /TargetUri$/i.test(String(key ?? '').trim());
|
|
50
|
+
}
|
|
51
|
+
export function normalizeRegistryDoc(doc) {
|
|
52
|
+
if (!doc)
|
|
53
|
+
return null;
|
|
54
|
+
const name = String(doc.name ?? '').trim();
|
|
55
|
+
const internalBaseUrl = String(doc.internalBaseUrl ?? '').trim();
|
|
56
|
+
if (!name || !internalBaseUrl)
|
|
57
|
+
return null;
|
|
58
|
+
const othersRaw = doc.others;
|
|
59
|
+
const legacyCreated = doc.registeredAt;
|
|
60
|
+
const legacyUpdated = doc.lastSeenAt;
|
|
61
|
+
return {
|
|
62
|
+
...(doc._id ? { _id: String(doc._id) } : {}),
|
|
63
|
+
name,
|
|
64
|
+
internalBaseUrl,
|
|
65
|
+
...(doc.version ? { version: String(doc.version) } : {}),
|
|
66
|
+
others: {
|
|
67
|
+
created: othersRaw?.created ?? legacyCreated,
|
|
68
|
+
updated: othersRaw?.updated ?? legacyUpdated,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export function serializeRegistryEntry(entry) {
|
|
73
|
+
const others = entry.others ?? {};
|
|
74
|
+
return JSON.stringify({
|
|
75
|
+
...(entry._id ? { _id: entry._id } : {}),
|
|
76
|
+
name: entry.name,
|
|
77
|
+
internalBaseUrl: entry.internalBaseUrl,
|
|
78
|
+
...(entry.version ? { version: entry.version } : {}),
|
|
79
|
+
others: {
|
|
80
|
+
created: others.created instanceof Date ? others.created.toISOString() : others.created,
|
|
81
|
+
updated: others.updated instanceof Date ? others.updated.toISOString() : others.updated,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
export function parseRegistryEntry(raw) {
|
|
86
|
+
if (!raw)
|
|
87
|
+
return null;
|
|
88
|
+
try {
|
|
89
|
+
return normalizeRegistryDoc(JSON.parse(raw));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export function snapshotFromHash(fields) {
|
|
96
|
+
const out = {};
|
|
97
|
+
for (const [name, raw] of Object.entries(fields ?? {})) {
|
|
98
|
+
const entry = parseRegistryEntry(raw);
|
|
99
|
+
if (entry)
|
|
100
|
+
out[name] = entry;
|
|
101
|
+
}
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{x
|
|
1
|
+
import { x } from '../../../utils/models/index.js';
|
|
2
|
+
export const DTO_RUNTIME_KEY = 'dtoRuntime';
|
|
3
|
+
export function getDtoRuntime() {
|
|
4
|
+
return x.get(DTO_RUNTIME_KEY);
|
|
5
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export{getDtoRuntime,DTO_RUNTIME_KEY}from
|
|
1
|
+
export { getDtoRuntime, DTO_RUNTIME_KEY } from '../../../utils/helpers/runtime/dto-access.js';
|
|
2
|
+
export { gracefulShutdown, isShuttingDown, registerGracefulShutdown } from '../../../utils/helpers/runtime/shutdown.js';
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
import{stopTmpLoader
|
|
1
|
+
import { stopTmpLoader } from '../../../utils/helpers/tmp/tmp-loader.js';
|
|
2
|
+
import { clearRuntimeTmpConfigs } from '../../../utils/helpers/tmp/runtime-tmp.js';
|
|
3
|
+
import x from '../../../utils/models/classes/class.x.js';
|
|
4
|
+
let shuttingDown = false;
|
|
5
|
+
let registered = false;
|
|
6
|
+
export function isShuttingDown() {
|
|
7
|
+
return shuttingDown;
|
|
8
|
+
}
|
|
9
|
+
export async function gracefulShutdown(exitCode = 0) {
|
|
10
|
+
if (shuttingDown) {
|
|
11
|
+
process.exit(exitCode);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
shuttingDown = true;
|
|
15
|
+
try {
|
|
16
|
+
await x.shutdown();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// best-effort teardown
|
|
20
|
+
}
|
|
21
|
+
stopTmpLoader();
|
|
22
|
+
clearRuntimeTmpConfigs();
|
|
23
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
24
|
+
process.exit(exitCode);
|
|
25
|
+
}
|
|
26
|
+
export function registerGracefulShutdown() {
|
|
27
|
+
if (registered)
|
|
28
|
+
return;
|
|
29
|
+
registered = true;
|
|
30
|
+
const handle = (signal) => {
|
|
31
|
+
const code = signal === 'SIGINT' ? 130 : signal === 'SIGTERM' ? 143 : 0;
|
|
32
|
+
void gracefulShutdown(code);
|
|
33
|
+
};
|
|
34
|
+
process.on('SIGINT', handle);
|
|
35
|
+
process.on('SIGTERM', handle);
|
|
36
|
+
}
|
|
@@ -1 +1,185 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { createStore } from 'zustand/vanilla';
|
|
2
|
+
import { subscribeWithSelector } from 'zustand/middleware';
|
|
3
|
+
import { GStoreScopeEnum } from '../../../utils/models/enums/index.js';
|
|
4
|
+
import { propsFromTmp, resolveGStoreBoot, G_PROP_NOT_ALLOWED } from '../../../utils/helpers/state/props-from-tmp.js';
|
|
5
|
+
import { warnIfRequestScopedKey, G_REQUEST_KEY_WARN, looksLikeRequestScopedKey } from '../../../utils/helpers/state/request-key-guard.js';
|
|
6
|
+
import { buildStoresSnapshot, patchControllerScope, patchRunScope, } from '../../../utils/helpers/state/scopes.js';
|
|
7
|
+
export { propsFromTmp, resolveGStoreBoot, G_PROP_NOT_ALLOWED, G_REQUEST_KEY_WARN, looksLikeRequestScopedKey };
|
|
8
|
+
export { GStoreScopeEnum } from '../../../utils/models/enums/index.js';
|
|
9
|
+
export { buildStoresSnapshot, summarizeController, runContextValues, patchControllerScope, patchRunScope, } from '../../../utils/helpers/state/scopes.js';
|
|
10
|
+
const cloneState = (state) => JSON.parse(JSON.stringify(state));
|
|
11
|
+
function diffChanges(prev, next) {
|
|
12
|
+
const keys = new Set([...Object.keys(prev), ...Object.keys(next)]);
|
|
13
|
+
const changes = [];
|
|
14
|
+
for (const key of keys) {
|
|
15
|
+
if (prev[key] !== next[key]) {
|
|
16
|
+
changes.push({ key, value: next[key], prev: prev[key] });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return changes;
|
|
20
|
+
}
|
|
21
|
+
class GStoreFacade {
|
|
22
|
+
store;
|
|
23
|
+
baseline = {};
|
|
24
|
+
allowedKeys = new Set();
|
|
25
|
+
allowAutoCreateProps = true;
|
|
26
|
+
warnOnRequestKeys = true;
|
|
27
|
+
constructor() {
|
|
28
|
+
this.store = createStore(subscribeWithSelector(() => ({})));
|
|
29
|
+
}
|
|
30
|
+
configureFromTmp(tmp = {}) {
|
|
31
|
+
const boot = resolveGStoreBoot(tmp);
|
|
32
|
+
this.allowAutoCreateProps = boot.allowAutoCreateProps;
|
|
33
|
+
this.warnOnRequestKeys = boot.warnOnRequestKeys;
|
|
34
|
+
this.allowedKeys = new Set(Object.keys(boot.vars));
|
|
35
|
+
const next = cloneState(boot.bootstrap ? boot.vars : {});
|
|
36
|
+
this.store.setState(next, true);
|
|
37
|
+
this.baseline = cloneState(next);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
allowsAutoCreateProps() {
|
|
41
|
+
return this.allowAutoCreateProps;
|
|
42
|
+
}
|
|
43
|
+
declaredKeys() {
|
|
44
|
+
return [...this.allowedKeys];
|
|
45
|
+
}
|
|
46
|
+
guardRequestKey(key) {
|
|
47
|
+
warnIfRequestScopedKey(key, this.warnOnRequestKeys);
|
|
48
|
+
}
|
|
49
|
+
assertPropAllowed(key) {
|
|
50
|
+
if (this.allowAutoCreateProps)
|
|
51
|
+
return;
|
|
52
|
+
if (!this.allowedKeys.has(key)) {
|
|
53
|
+
throw new Error(`${G_PROP_NOT_ALLOWED}: ${key}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
registerAllowedKeys(keys) {
|
|
57
|
+
for (const key of keys)
|
|
58
|
+
this.allowedKeys.add(key);
|
|
59
|
+
}
|
|
60
|
+
getState() {
|
|
61
|
+
return this.store.getState();
|
|
62
|
+
}
|
|
63
|
+
select(selector) {
|
|
64
|
+
return selector(this.getState());
|
|
65
|
+
}
|
|
66
|
+
get(key, fallback) {
|
|
67
|
+
const state = this.getState();
|
|
68
|
+
if (!(key in state))
|
|
69
|
+
return fallback;
|
|
70
|
+
return state[key];
|
|
71
|
+
}
|
|
72
|
+
set(key, value) {
|
|
73
|
+
this.guardRequestKey(key);
|
|
74
|
+
this.assertPropAllowed(key);
|
|
75
|
+
const prev = this.getState();
|
|
76
|
+
if (prev[key] === value)
|
|
77
|
+
return this;
|
|
78
|
+
this.store.setState({ ...prev, [key]: value });
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
merge(record) {
|
|
82
|
+
for (const key of Object.keys(record)) {
|
|
83
|
+
this.guardRequestKey(key);
|
|
84
|
+
this.assertPropAllowed(key);
|
|
85
|
+
}
|
|
86
|
+
const prev = this.getState();
|
|
87
|
+
const changes = diffChanges(prev, { ...prev, ...record });
|
|
88
|
+
if (!changes.length)
|
|
89
|
+
return this;
|
|
90
|
+
this.store.setState({ ...prev, ...record });
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
has(key) {
|
|
94
|
+
return key in this.getState();
|
|
95
|
+
}
|
|
96
|
+
remove(...keys) {
|
|
97
|
+
const prev = this.getState();
|
|
98
|
+
const next = { ...prev };
|
|
99
|
+
let touched = false;
|
|
100
|
+
for (const key of keys) {
|
|
101
|
+
if (key in next) {
|
|
102
|
+
delete next[key];
|
|
103
|
+
touched = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (touched)
|
|
107
|
+
this.store.setState(next, true);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
keys() {
|
|
111
|
+
return Object.keys(this.getState());
|
|
112
|
+
}
|
|
113
|
+
entries() {
|
|
114
|
+
return Object.entries(this.getState());
|
|
115
|
+
}
|
|
116
|
+
snapshot() {
|
|
117
|
+
return { ...this.getState() };
|
|
118
|
+
}
|
|
119
|
+
subscribe(listener) {
|
|
120
|
+
return this.store.subscribe((state, prev) => listener(state, prev, diffChanges(prev, state)));
|
|
121
|
+
}
|
|
122
|
+
subscribeKey(key, listener) {
|
|
123
|
+
return this.store.subscribe((state) => state[key], (value, prev) => listener(value, prev, { key, value, prev }));
|
|
124
|
+
}
|
|
125
|
+
bootstrap(record) {
|
|
126
|
+
if (!this.allowAutoCreateProps) {
|
|
127
|
+
for (const key of Object.keys(record))
|
|
128
|
+
this.assertPropAllowed(key);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this.registerAllowedKeys(Object.keys(record));
|
|
132
|
+
}
|
|
133
|
+
this.merge(record);
|
|
134
|
+
this.baseline = cloneState(this.getState());
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
reset() {
|
|
138
|
+
this.store.setState(cloneState(this.baseline), true);
|
|
139
|
+
}
|
|
140
|
+
stores() {
|
|
141
|
+
return buildStoresSnapshot(this.snapshot());
|
|
142
|
+
}
|
|
143
|
+
list() {
|
|
144
|
+
return Object.values(this.stores());
|
|
145
|
+
}
|
|
146
|
+
scope(name) {
|
|
147
|
+
const stores = this.stores();
|
|
148
|
+
const entry = stores[name];
|
|
149
|
+
const base = {
|
|
150
|
+
name,
|
|
151
|
+
active: entry.active,
|
|
152
|
+
keys: () => entry.keys,
|
|
153
|
+
get(key, fallback) {
|
|
154
|
+
if (!entry.values || !(key in entry.values))
|
|
155
|
+
return fallback;
|
|
156
|
+
return entry.values[key];
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
if (name === GStoreScopeEnum.GLOBAL) {
|
|
160
|
+
return {
|
|
161
|
+
...base,
|
|
162
|
+
set: (key, value) => {
|
|
163
|
+
this.set(key, value);
|
|
164
|
+
return true;
|
|
165
|
+
},
|
|
166
|
+
merge: (record) => {
|
|
167
|
+
this.merge(record);
|
|
168
|
+
return true;
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
if (name === GStoreScopeEnum.RUN) {
|
|
173
|
+
return {
|
|
174
|
+
...base,
|
|
175
|
+
patch: (record) => patchRunScope(record),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
return {
|
|
179
|
+
...base,
|
|
180
|
+
patch: (record) => patchControllerScope(record),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export { GStoreFacade };
|
|
185
|
+
export const G = new GStoreFacade();
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
import{Constants
|
|
1
|
+
import { Constants } from '../../../utils/constants/index.js';
|
|
2
|
+
import { readTmpDependsBlock } from '../../../utils/helpers/tmp/tmp-schema.js';
|
|
3
|
+
export const G_PROP_NOT_ALLOWED = `[${Constants.packageName}] G prop not declared in tmp.yml vars — set autoCreateProps: true to allow runtime keys`;
|
|
4
|
+
const emptyVars = () => ({});
|
|
5
|
+
function readGStoreNode(configs) {
|
|
6
|
+
const loaders = readTmpDependsBlock(configs).loaders;
|
|
7
|
+
const fromSystem = loaders?.system;
|
|
8
|
+
return fromSystem?.gStore;
|
|
9
|
+
}
|
|
10
|
+
function readBootstrap(options) {
|
|
11
|
+
if (typeof options.bootstrap === 'boolean')
|
|
12
|
+
return options.bootstrap;
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
function readAllowAutoCreateProps(options) {
|
|
16
|
+
if (typeof options.autoCreateProps === 'boolean')
|
|
17
|
+
return options.autoCreateProps;
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
function readWarnOnRequestKeys(options) {
|
|
21
|
+
if (typeof options.warnOnRequestKeys === 'boolean')
|
|
22
|
+
return options.warnOnRequestKeys;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
export function resolveGStoreBoot(tmp = {}) {
|
|
26
|
+
const configs = (tmp.configs ?? tmp);
|
|
27
|
+
const gStore = readGStoreNode(configs);
|
|
28
|
+
if (!gStore) {
|
|
29
|
+
return { bootstrap: true, allowAutoCreateProps: true, warnOnRequestKeys: true, vars: emptyVars() };
|
|
30
|
+
}
|
|
31
|
+
const options = (gStore.options ?? {});
|
|
32
|
+
const varsRaw = gStore.vars;
|
|
33
|
+
const vars = varsRaw && typeof varsRaw === 'object' && !Array.isArray(varsRaw)
|
|
34
|
+
? { ...varsRaw }
|
|
35
|
+
: emptyVars();
|
|
36
|
+
return {
|
|
37
|
+
bootstrap: readBootstrap(options),
|
|
38
|
+
allowAutoCreateProps: readAllowAutoCreateProps(options),
|
|
39
|
+
warnOnRequestKeys: readWarnOnRequestKeys(options),
|
|
40
|
+
vars,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function propsFromTmp(tmp = {}) {
|
|
44
|
+
const boot = resolveGStoreBoot(tmp);
|
|
45
|
+
return boot.bootstrap ? boot.vars : emptyVars();
|
|
46
|
+
}
|