@xrystal/core 3.32.1 → 3.37.4
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 +676 -136
- package/package.json +27 -24
- package/tsconfig.base.json +15 -0
- package/x/bin/commands/create.mjs +34 -5
- package/x/bin/commands/doctor.mjs +115 -25
- package/x/bin/commands/hooks.mjs +55 -0
- package/x/bin/commands/project.mjs +75 -42
- package/x/bin/commands/release.mjs +8 -3
- package/x/bin/commands/sync-toolchain.mjs +43 -0
- package/x/bin/commands/tmp.mjs +13 -4
- package/x/bin/helpers/.generated/.generated-from +1 -0
- package/x/bin/helpers/.generated/tmp-schema.mjs +192 -0
- package/x/bin/helpers/banner.mjs +66 -12
- package/x/bin/helpers/build-config.mjs +342 -0
- package/x/bin/helpers/cli-help.mjs +164 -0
- package/x/bin/helpers/create-target.mjs +18 -2
- package/x/bin/helpers/project-artifacts.mjs +142 -0
- package/x/bin/helpers/runtime-info.mjs +172 -0
- package/x/bin/helpers/tmp-config.mjs +11 -10
- package/x/bin/helpers/tmp-layout.mjs +10 -16
- package/x/bin/helpers/tmp-schema.mjs +9 -0
- package/x/bin/helpers/toolchain-config.mjs +233 -0
- package/x/bin/main-cli.js +31 -3
- package/x/bin/scripts/clean-source-types.mjs +19 -0
- package/x/bin/scripts/fix-dist-imports.mjs +80 -0
- package/x/bin/scripts/install-git-hooks.mjs +86 -0
- package/x/bin/scripts/minify-dist.mjs +50 -0
- package/x/bin/scripts/prepare-npm-publish.mjs +39 -0
- package/x/bin/scripts/publish-guard.mjs +113 -0
- package/x/bin/scripts/verify-npm-pack.mjs +12 -0
- package/x/bin/scripts/verify-publish-config.mjs +10 -0
- package/x/bin/scripts/verify-version-bump.mjs +27 -0
- package/x/bin/scripts/version-check.mjs +173 -0
- package/x/dist/index.js +1 -0
- package/x/dist/loader/clients/index.js +1 -0
- package/x/dist/loader/configs/index.js +1 -0
- package/{source → x/dist}/loader/controller/index.d.ts +20 -17
- package/x/dist/loader/controller/index.js +1 -0
- package/x/dist/loader/dto/index.js +1 -0
- package/x/dist/loader/events/index.js +1 -0
- package/x/dist/loader/index.d.ts +11 -0
- package/x/dist/loader/index.js +1 -0
- package/{source → x/dist}/loader/kafka/index.d.ts +1 -0
- package/x/dist/loader/kafka/index.js +1 -0
- package/x/dist/loader/localizations/index.js +1 -0
- package/{source → x/dist}/loader/logger/index.d.ts +1 -0
- package/x/dist/loader/logger/index.js +2 -0
- package/x/dist/loader/service/index.js +1 -0
- package/x/dist/loader/system/index.js +1 -0
- package/x/dist/project/index.d.ts +12 -0
- package/x/dist/project/index.js +1 -0
- package/x/dist/utils/constants/defaults.json +44 -0
- package/x/dist/utils/constants/index.js +1 -0
- package/x/dist/utils/helpers/configs/index.js +1 -0
- package/x/dist/utils/helpers/context/controller-store.js +1 -0
- package/x/dist/utils/helpers/context/index.js +1 -0
- package/{source → x/dist}/utils/helpers/core/index.d.ts +1 -1
- package/x/dist/utils/helpers/core/index.js +1 -0
- package/x/dist/utils/helpers/core/paths.js +1 -0
- package/x/dist/utils/helpers/core/tmp-layout.js +1 -0
- package/x/dist/utils/helpers/date/index.js +1 -0
- package/x/dist/utils/helpers/dispatch/index.js +1 -0
- package/x/dist/utils/helpers/dto/index.js +1 -0
- package/x/dist/utils/helpers/filters/index.js +1 -0
- package/x/dist/utils/helpers/framework/index.js +1 -0
- package/x/dist/utils/helpers/handlers/adapters.js +1 -0
- package/x/dist/utils/helpers/handlers/execute.js +1 -0
- package/x/dist/utils/helpers/handlers/index.js +1 -0
- package/x/dist/utils/helpers/hash/crypto.js +1 -0
- package/x/dist/utils/helpers/id/index.js +1 -0
- package/x/dist/utils/helpers/index.js +1 -0
- package/x/dist/utils/helpers/ip/index.js +1 -0
- package/x/dist/utils/helpers/is/index.js +1 -0
- package/x/dist/utils/helpers/locales/index.js +1 -0
- package/x/dist/utils/helpers/math/index.js +1 -0
- package/{source → x/dist}/utils/helpers/middleware/index.d.ts +2 -2
- package/x/dist/utils/helpers/middleware/index.js +1 -0
- package/x/dist/utils/helpers/objects/index.js +1 -0
- package/x/dist/utils/helpers/path/index.js +1 -0
- package/{source → x/dist}/utils/helpers/protocol/index.d.ts +2 -10
- package/x/dist/utils/helpers/protocol/index.js +1 -0
- package/x/dist/utils/helpers/protocol/options.js +1 -0
- package/x/dist/utils/helpers/regex/checkSpecialRegexControl.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-access.js +1 -0
- package/x/dist/utils/helpers/runtime/dto-types.js +1 -0
- package/{source → x/dist}/utils/helpers/runtime/index.d.ts +1 -0
- package/x/dist/utils/helpers/runtime/index.js +1 -0
- package/x/dist/utils/helpers/runtime/shutdown.d.ts +3 -0
- package/x/dist/utils/helpers/runtime/shutdown.js +1 -0
- package/x/dist/utils/helpers/state/index.js +1 -0
- package/x/dist/utils/helpers/state/props-from-tmp.js +1 -0
- package/x/dist/utils/helpers/state/request-key-guard.js +1 -0
- package/x/dist/utils/helpers/state/scopes.js +1 -0
- package/x/dist/utils/helpers/string/index.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-schema.test.js +1 -0
- package/x/dist/utils/helpers/tests/tmp-watch.test.d.ts +1 -0
- package/x/dist/utils/helpers/tests/tmp-watch.test.js +1 -0
- package/x/dist/utils/helpers/timer/index.js +1 -0
- package/x/dist/utils/helpers/tmp/index.d.ts +5 -0
- package/x/dist/utils/helpers/tmp/index.js +1 -0
- package/x/dist/utils/helpers/tmp/loader-tmp-sync.js +1 -0
- package/{source → x/dist}/utils/helpers/tmp/runtime-tmp.d.ts +2 -6
- package/x/dist/utils/helpers/tmp/runtime-tmp.js +1 -0
- package/{source → x/dist}/utils/helpers/tmp/tmp-loader.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-loader.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.d.ts +47 -0
- package/x/dist/utils/helpers/tmp/tmp-schema.js +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.d.ts +1 -0
- package/x/dist/utils/helpers/tmp/tmp-watch.js +1 -0
- package/x/dist/utils/helpers/validates/index.js +1 -0
- package/x/dist/utils/index.js +1 -0
- package/x/dist/utils/models/classes/class.clients.js +1 -0
- package/x/dist/utils/models/classes/class.interfaces.js +1 -0
- package/x/dist/utils/models/classes/class.service-locator.js +1 -0
- package/{source → x/dist}/utils/models/classes/class.tmp-file-loader.d.ts +3 -2
- package/x/dist/utils/models/classes/class.tmp-file-loader.js +1 -0
- package/x/dist/utils/models/classes/class.x.js +1 -0
- package/x/dist/utils/models/enums/index.js +1 -0
- package/x/dist/utils/models/index.js +1 -0
- package/x/dist/utils/models/types/index.js +1 -0
- package/x/dist/utils/package-root.js +1 -0
- package/x/tmp.yml +51 -42
- package/source/index.js +0 -11
- package/source/loader/clients/index.js +0 -22
- package/source/loader/configs/index.js +0 -88
- package/source/loader/controller/index.js +0 -236
- package/source/loader/dto/index.js +0 -92
- package/source/loader/events/index.js +0 -44
- package/source/loader/index.d.ts +0 -11
- package/source/loader/index.js +0 -11
- package/source/loader/kafka/index.js +0 -137
- package/source/loader/localizations/index.js +0 -46
- package/source/loader/logger/index.js +0 -217
- package/source/loader/service/index.js +0 -7
- package/source/loader/system/index.js +0 -25
- package/source/project/index.d.ts +0 -8
- package/source/project/index.js +0 -70
- package/source/utils/constants/defaults.json +0 -15
- package/source/utils/constants/defaults.mjs +0 -10
- package/source/utils/constants/index.js +0 -22
- package/source/utils/helpers/configs/index.js +0 -1
- package/source/utils/helpers/context/controller-store.js +0 -12
- package/source/utils/helpers/context/index.js +0 -24
- package/source/utils/helpers/core/index.js +0 -58
- package/source/utils/helpers/core/paths.js +0 -78
- package/source/utils/helpers/core/tmp-layout.js +0 -241
- package/source/utils/helpers/date/index.js +0 -48
- package/source/utils/helpers/dispatch/index.js +0 -53
- package/source/utils/helpers/dto/index.js +0 -10
- package/source/utils/helpers/filters/index.js +0 -44
- package/source/utils/helpers/framework/index.js +0 -17
- package/source/utils/helpers/handlers/adapters.js +0 -40
- package/source/utils/helpers/handlers/execute.js +0 -82
- package/source/utils/helpers/handlers/index.js +0 -31
- package/source/utils/helpers/hash/crypto.js +0 -22
- package/source/utils/helpers/id/index.js +0 -24
- package/source/utils/helpers/index.js +0 -26
- package/source/utils/helpers/ip/index.js +0 -21
- package/source/utils/helpers/is/index.js +0 -35
- package/source/utils/helpers/locales/index.js +0 -82
- package/source/utils/helpers/math/index.js +0 -14
- package/source/utils/helpers/middleware/index.js +0 -36
- package/source/utils/helpers/objects/index.js +0 -55
- package/source/utils/helpers/path/index.js +0 -4
- package/source/utils/helpers/protocol/index.js +0 -99
- package/source/utils/helpers/protocol/options.js +0 -13
- package/source/utils/helpers/regex/checkSpecialRegexControl.js +0 -3
- package/source/utils/helpers/runtime/dto-access.js +0 -5
- package/source/utils/helpers/runtime/index.js +0 -1
- package/source/utils/helpers/state/index.js +0 -185
- package/source/utils/helpers/state/props-from-tmp.js +0 -44
- package/source/utils/helpers/state/request-key-guard.js +0 -42
- package/source/utils/helpers/state/scopes.js +0 -69
- package/source/utils/helpers/string/index.js +0 -9
- package/source/utils/helpers/timer/index.js +0 -5
- package/source/utils/helpers/tmp/index.d.ts +0 -3
- package/source/utils/helpers/tmp/index.js +0 -3
- package/source/utils/helpers/tmp/loader-tmp-sync.js +0 -13
- package/source/utils/helpers/tmp/runtime-tmp.js +0 -30
- package/source/utils/helpers/tmp/tmp-loader.js +0 -48
- package/source/utils/helpers/validates/index.js +0 -20
- package/source/utils/index.js +0 -3
- package/source/utils/models/classes/class.clients.js +0 -142
- package/source/utils/models/classes/class.interfaces.js +0 -10
- package/source/utils/models/classes/class.service-locator.js +0 -16
- package/source/utils/models/classes/class.tmp-file-loader.js +0 -38
- package/source/utils/models/classes/class.x.js +0 -180
- package/source/utils/models/enums/index.js +0 -148
- package/source/utils/models/index.js +0 -9
- package/source/utils/models/types/index.js +0 -2
- package/source/utils/models/types/shims.d.ts +0 -123
- package/source/utils/package-root.js +0 -5
- package/x/tests/cli.test.ts +0 -85
- package/x/tests/context.test.ts +0 -25
- package/x/tests/dispatch.test.ts +0 -84
- package/x/tests/fixtures/locales/en/translation.json +0 -8
- package/x/tests/fixtures/locales/tr/translation.json +0 -8
- package/x/tests/frameworks.integration.test.ts +0 -185
- package/x/tests/helpers/i18n-setup.ts +0 -52
- package/x/tests/helpers/middleware.ts +0 -23
- package/x/tests/helpers/register-test-dto.ts +0 -52
- package/x/tests/i18n.integration.test.ts +0 -77
- package/x/tests/i18n.test.ts +0 -96
- package/x/tests/middleware.test.ts +0 -83
- package/x/tests/project-layout.test.ts +0 -65
- package/x/tests/protocol.test.ts +0 -75
- package/x/tests/realtime.examples.test.ts +0 -198
- package/x/tests/runtime-tmp.test.ts +0 -49
- package/x/tests/socket.integration.test.ts +0 -174
- package/x/tests/state.test.ts +0 -183
- package/x/tests/tmp-layout-guard.test.ts +0 -40
- /package/{source → x/dist}/index.d.ts +0 -0
- /package/{source → x/dist}/loader/clients/index.d.ts +0 -0
- /package/{source → x/dist}/loader/configs/index.d.ts +0 -0
- /package/{source → x/dist}/loader/dto/index.d.ts +0 -0
- /package/{source → x/dist}/loader/events/index.d.ts +0 -0
- /package/{source → x/dist}/loader/localizations/index.d.ts +0 -0
- /package/{source → x/dist}/loader/service/index.d.ts +0 -0
- /package/{source → x/dist}/loader/system/index.d.ts +0 -0
- /package/{source → x/dist}/utils/constants/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/configs/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/context/controller-store.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/context/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/core/paths.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/core/tmp-layout.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/date/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/dispatch/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/dto/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/filters/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/framework/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/adapters.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/execute.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/handlers/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/hash/crypto.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/id/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/ip/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/is/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/locales/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/math/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/objects/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/path/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/protocol/options.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/regex/checkSpecialRegexControl.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/runtime/dto-access.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/runtime/dto-types.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/props-from-tmp.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/request-key-guard.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/state/scopes.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/string/index.d.ts +0 -0
- /package/{source/utils/helpers/runtime/dto-types.js → x/dist/utils/helpers/tests/tmp-schema.test.d.ts} +0 -0
- /package/{source → x/dist}/utils/helpers/timer/index.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/tmp/loader-tmp-sync.d.ts +0 -0
- /package/{source → x/dist}/utils/helpers/validates/index.d.ts +0 -0
- /package/{source → x/dist}/utils/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.clients.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.interfaces.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.service-locator.d.ts +0 -0
- /package/{source → x/dist}/utils/models/classes/class.x.d.ts +0 -0
- /package/{source → x/dist}/utils/models/enums/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/index.d.ts +0 -0
- /package/{source → x/dist}/utils/models/types/index.d.ts +0 -0
- /package/{source → x/dist}/utils/package-root.d.ts +0 -0
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
export function findFileRecursively(startDir, baseName, extName = '', excludedDirs = ['node_modules', '.git']) {
|
|
4
|
-
if (typeof startDir !== 'string' || !fs.existsSync(startDir)) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const targetName = baseName + (extName.startsWith('.') ? extName : (extName ? `.${extName}` : ''));
|
|
8
|
-
try {
|
|
9
|
-
const entries = fs.readdirSync(startDir, { withFileTypes: true });
|
|
10
|
-
for (const entry of entries) {
|
|
11
|
-
const fullPath = path.join(startDir, entry.name);
|
|
12
|
-
if (entry.isFile()) {
|
|
13
|
-
if (!extName) {
|
|
14
|
-
const entryExt = path.extname(entry.name);
|
|
15
|
-
const entryBase = path.basename(entry.name, entryExt);
|
|
16
|
-
if (entryBase === baseName) {
|
|
17
|
-
return fullPath;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else if (entry.name === targetName) {
|
|
21
|
-
return fullPath;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (entry.isDirectory()) {
|
|
25
|
-
const isHiddenOrExcluded = entry.name.startsWith('.') || excludedDirs.includes(entry.name);
|
|
26
|
-
if (isHiddenOrExcluded)
|
|
27
|
-
continue;
|
|
28
|
-
const foundPath = findFileRecursively(fullPath, baseName, extName, excludedDirs);
|
|
29
|
-
if (foundPath)
|
|
30
|
-
return foundPath;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (error && typeof error === 'object' && 'code' in error && error.code === 'EACCES') {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export function findAllFilesRecursively(startDir, baseName, extName = '', excludedDirs = ['node_modules', '.git']) {
|
|
43
|
-
const targetName = baseName + (extName.startsWith('.') ? extName : extName ? `.${extName}` : '');
|
|
44
|
-
const found = [];
|
|
45
|
-
function walk(dir) {
|
|
46
|
-
if (!fs.existsSync(dir))
|
|
47
|
-
return;
|
|
48
|
-
let entries;
|
|
49
|
-
try {
|
|
50
|
-
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
for (const entry of entries) {
|
|
56
|
-
const fullPath = path.join(dir, entry.name);
|
|
57
|
-
if (entry.isFile()) {
|
|
58
|
-
if (!extName) {
|
|
59
|
-
const entryExt = path.extname(entry.name);
|
|
60
|
-
const entryBase = path.basename(entry.name, entryExt);
|
|
61
|
-
if (entryBase === baseName)
|
|
62
|
-
found.push(fullPath);
|
|
63
|
-
}
|
|
64
|
-
else if (entry.name === targetName) {
|
|
65
|
-
found.push(fullPath);
|
|
66
|
-
}
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
if (entry.isDirectory()) {
|
|
70
|
-
if (entry.name.startsWith('.') || excludedDirs.includes(entry.name))
|
|
71
|
-
continue;
|
|
72
|
-
walk(fullPath);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
walk(path.resolve(startDir));
|
|
77
|
-
return found;
|
|
78
|
-
}
|
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import yaml from 'yaml';
|
|
4
|
-
import { Constants } from '../../../utils/constants';
|
|
5
|
-
import { findAllFilesRecursively, findFileRecursively } from '../../../utils/helpers/core/paths';
|
|
6
|
-
const DEFAULT_PATHS = {
|
|
7
|
-
tests: Constants.layoutPaths.tests,
|
|
8
|
-
environments: Constants.layoutPaths.environments,
|
|
9
|
-
dist: Constants.layoutPaths.dist,
|
|
10
|
-
};
|
|
11
|
-
function formatTmpTarget(name, ext) {
|
|
12
|
-
return `${name}${ext.startsWith('.') ? ext : `.${ext}`}`;
|
|
13
|
-
}
|
|
14
|
-
export function coreCanonicalTmpPath(projectRoot = process.cwd()) {
|
|
15
|
-
return path.join(path.resolve(projectRoot), Constants.packageRootFolder, formatTmpTarget(Constants.tmpBaseName, Constants.tmpExtension));
|
|
16
|
-
}
|
|
17
|
-
export function assertCoreTmpGuard(projectRoot, tmpFilePath) {
|
|
18
|
-
if (!isCorePackageRoot(projectRoot))
|
|
19
|
-
return;
|
|
20
|
-
const canonical = coreCanonicalTmpPath(projectRoot);
|
|
21
|
-
if (path.resolve(tmpFilePath) !== path.resolve(canonical)) {
|
|
22
|
-
throw new Error(`@xrystal/core: tmp.yml must stay at ${Constants.packageRootFolder}/tmp.yml (expected ${canonical}, got ${tmpFilePath})`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function findStrayCoreTmpFiles(projectRoot, canonicalPath) {
|
|
26
|
-
const resolvedRoot = path.resolve(projectRoot);
|
|
27
|
-
const canonical = path.resolve(canonicalPath);
|
|
28
|
-
return findAllFilesRecursively(resolvedRoot, Constants.tmpBaseName, Constants.tmpExtension).filter((filePath) => path.resolve(filePath) !== canonical);
|
|
29
|
-
}
|
|
30
|
-
export function ensureCoreTmpEntry(projectRoot = process.cwd(), options = {}) {
|
|
31
|
-
const resolvedRoot = path.resolve(projectRoot);
|
|
32
|
-
if (!isCorePackageRoot(resolvedRoot)) {
|
|
33
|
-
throw new Error('ensureCoreTmpEntry is only for @xrystal/core package root');
|
|
34
|
-
}
|
|
35
|
-
const canonical = coreCanonicalTmpPath(resolvedRoot);
|
|
36
|
-
const strays = findStrayCoreTmpFiles(resolvedRoot, canonical);
|
|
37
|
-
if (strays.length > 0) {
|
|
38
|
-
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ');
|
|
39
|
-
throw new Error(`@xrystal/core: tmp.yml must only exist under ${Constants.packageRootFolder}/. Remove extra copies: ${rel}`);
|
|
40
|
-
}
|
|
41
|
-
if (fs.existsSync(canonical)) {
|
|
42
|
-
assertCoreTmpGuard(resolvedRoot, canonical);
|
|
43
|
-
return {
|
|
44
|
-
tmpFilePath: canonical,
|
|
45
|
-
created: false,
|
|
46
|
-
layout: buildTmpLayout(resolvedRoot, readTmpFile(canonical), canonical),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
return ensureTmpFile(resolvedRoot, { ...options, patchServiceName: false });
|
|
50
|
-
}
|
|
51
|
-
function resolveTmpFilePath(projectRoot, tmpFileName, ext) {
|
|
52
|
-
const resolvedRoot = path.resolve(projectRoot);
|
|
53
|
-
if (isCorePackageRoot(resolvedRoot)) {
|
|
54
|
-
const canonical = coreCanonicalTmpPath(resolvedRoot);
|
|
55
|
-
return fs.existsSync(canonical) ? canonical : null;
|
|
56
|
-
}
|
|
57
|
-
return findFileRecursively(resolvedRoot, tmpFileName, ext);
|
|
58
|
-
}
|
|
59
|
-
function readTmpFile(filePath) {
|
|
60
|
-
return yaml.parse(fs.readFileSync(filePath, 'utf8'));
|
|
61
|
-
}
|
|
62
|
-
export function isCorePackageRoot(projectRoot) {
|
|
63
|
-
const pkgPath = path.join(path.resolve(projectRoot), 'package.json');
|
|
64
|
-
if (!fs.existsSync(pkgPath))
|
|
65
|
-
return false;
|
|
66
|
-
try {
|
|
67
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
68
|
-
return pkg.name === Constants.packageName;
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
export function resolveRootFolderPath(tmp, tmpFilePath, projectRoot) {
|
|
75
|
-
const configs = tmp.configs;
|
|
76
|
-
if (typeof configs?.rootFolderPath === 'string' && configs.rootFolderPath.trim()) {
|
|
77
|
-
return configs.rootFolderPath.trim();
|
|
78
|
-
}
|
|
79
|
-
const project = tmp.project;
|
|
80
|
-
if (typeof project?.name === 'string' && project.name.trim()) {
|
|
81
|
-
return project.name.trim();
|
|
82
|
-
}
|
|
83
|
-
const relativeDir = path.relative(path.resolve(projectRoot), path.dirname(path.resolve(tmpFilePath)));
|
|
84
|
-
if (relativeDir && relativeDir !== '.') {
|
|
85
|
-
return relativeDir;
|
|
86
|
-
}
|
|
87
|
-
return Constants.packageRootFolder;
|
|
88
|
-
}
|
|
89
|
-
export function resolveLayoutPaths(configs) {
|
|
90
|
-
const paths = configs?.paths;
|
|
91
|
-
return {
|
|
92
|
-
tests: typeof paths?.tests === 'string' && paths.tests.trim() ? paths.tests.trim() : DEFAULT_PATHS.tests,
|
|
93
|
-
environments: typeof paths?.environments === 'string' && paths.environments.trim()
|
|
94
|
-
? paths.environments.trim()
|
|
95
|
-
: DEFAULT_PATHS.environments,
|
|
96
|
-
dist: typeof paths?.dist === 'string' && paths.dist.trim() ? paths.dist.trim() : DEFAULT_PATHS.dist,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
export function resolveMainFolderPath(configs) {
|
|
100
|
-
if (typeof configs?.mainFolderPath === 'string' && configs.mainFolderPath.trim()) {
|
|
101
|
-
return configs.mainFolderPath.trim();
|
|
102
|
-
}
|
|
103
|
-
return Constants.mainSourceFolder;
|
|
104
|
-
}
|
|
105
|
-
export function buildTmpLayout(projectRoot, tmp, tmpFilePath) {
|
|
106
|
-
const resolvedRoot = path.resolve(projectRoot);
|
|
107
|
-
const configs = tmp?.configs;
|
|
108
|
-
const rootFolderPath = tmp && tmpFilePath && !isCorePackageRoot(resolvedRoot)
|
|
109
|
-
? resolveRootFolderPath(tmp, tmpFilePath, resolvedRoot)
|
|
110
|
-
: Constants.packageRootFolder;
|
|
111
|
-
const rootFolderAbs = path.join(resolvedRoot, rootFolderPath);
|
|
112
|
-
const paths = resolveLayoutPaths(configs);
|
|
113
|
-
const mainFolderPath = resolveMainFolderPath(configs);
|
|
114
|
-
const pathsAbs = {
|
|
115
|
-
tests: path.join(rootFolderAbs, paths.tests),
|
|
116
|
-
environments: path.join(rootFolderAbs, paths.environments),
|
|
117
|
-
dist: path.join(rootFolderAbs, paths.dist),
|
|
118
|
-
};
|
|
119
|
-
return {
|
|
120
|
-
projectRoot: resolvedRoot,
|
|
121
|
-
rootFolderPath,
|
|
122
|
-
rootFolderAbs,
|
|
123
|
-
tmpFilePath,
|
|
124
|
-
mainFolderPath,
|
|
125
|
-
paths,
|
|
126
|
-
pathsAbs,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
export function resolveTmpLayout(projectRoot = process.cwd(), options = {}) {
|
|
130
|
-
const tmpFileName = options.tmpFileName ?? Constants.tmpBaseName;
|
|
131
|
-
const ext = options.ext ?? Constants.tmpExtension;
|
|
132
|
-
const tmpFilePath = resolveTmpFilePath(projectRoot, tmpFileName, ext);
|
|
133
|
-
if (!tmpFilePath) {
|
|
134
|
-
throw new Error(`${formatTmpTarget(tmpFileName, ext)} not found under ${path.resolve(projectRoot)}`);
|
|
135
|
-
}
|
|
136
|
-
if (isCorePackageRoot(path.resolve(projectRoot))) {
|
|
137
|
-
assertCoreTmpGuard(projectRoot, tmpFilePath);
|
|
138
|
-
}
|
|
139
|
-
return buildTmpLayout(projectRoot, readTmpFile(tmpFilePath), tmpFilePath);
|
|
140
|
-
}
|
|
141
|
-
export function resolveTmpLayoutOrDefaults(projectRoot = process.cwd()) {
|
|
142
|
-
const tmpFilePath = resolveTmpFilePath(projectRoot, Constants.tmpBaseName, Constants.tmpExtension);
|
|
143
|
-
if (!tmpFilePath) {
|
|
144
|
-
return buildTmpLayout(projectRoot, null, null);
|
|
145
|
-
}
|
|
146
|
-
return buildTmpLayout(projectRoot, readTmpFile(tmpFilePath), tmpFilePath);
|
|
147
|
-
}
|
|
148
|
-
export function resolveBundledCoreTmpPath(projectRoot = process.cwd()) {
|
|
149
|
-
if (fs.existsSync(Constants.bundledCoreTmpPath)) {
|
|
150
|
-
return Constants.bundledCoreTmpPath;
|
|
151
|
-
}
|
|
152
|
-
let dir = path.resolve(projectRoot);
|
|
153
|
-
while (dir !== path.dirname(dir)) {
|
|
154
|
-
const candidate = path.join(dir, 'node_modules', '@xrystal', 'core', Constants.packageRootFolder, formatTmpTarget(Constants.tmpBaseName, Constants.tmpExtension));
|
|
155
|
-
if (fs.existsSync(candidate))
|
|
156
|
-
return candidate;
|
|
157
|
-
const pkgPath = path.join(dir, 'package.json');
|
|
158
|
-
if (fs.existsSync(pkgPath)) {
|
|
159
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
160
|
-
if (pkg.name === Constants.packageName) {
|
|
161
|
-
const inCore = path.join(dir, Constants.packageRootFolder, formatTmpTarget(Constants.tmpBaseName, Constants.tmpExtension));
|
|
162
|
-
if (fs.existsSync(inCore))
|
|
163
|
-
return inCore;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
dir = path.dirname(dir);
|
|
167
|
-
}
|
|
168
|
-
throw new Error('@xrystal/core bundled x/tmp.yml not found');
|
|
169
|
-
}
|
|
170
|
-
export function ownerTmpFilePath(projectRoot = process.cwd(), layout) {
|
|
171
|
-
const resolved = layout ?? resolveTmpLayoutOrDefaults(projectRoot);
|
|
172
|
-
return path.join(resolved.rootFolderAbs, formatTmpTarget(Constants.tmpBaseName, Constants.tmpExtension));
|
|
173
|
-
}
|
|
174
|
-
export function ensureTmpFile(projectRoot = process.cwd(), options = {}) {
|
|
175
|
-
const resolvedRoot = path.resolve(projectRoot);
|
|
176
|
-
const patchServiceName = options.patchServiceName ?? true;
|
|
177
|
-
if (isCorePackageRoot(resolvedRoot)) {
|
|
178
|
-
const canonical = coreCanonicalTmpPath(resolvedRoot);
|
|
179
|
-
const strays = findStrayCoreTmpFiles(resolvedRoot, canonical);
|
|
180
|
-
if (strays.length > 0) {
|
|
181
|
-
const rel = strays.map((p) => path.relative(resolvedRoot, p)).join(', ');
|
|
182
|
-
throw new Error(`@xrystal/core: tmp.yml must only exist under ${Constants.packageRootFolder}/. Remove extra copies: ${rel}`);
|
|
183
|
-
}
|
|
184
|
-
if (fs.existsSync(canonical)) {
|
|
185
|
-
assertCoreTmpGuard(resolvedRoot, canonical);
|
|
186
|
-
return {
|
|
187
|
-
tmpFilePath: canonical,
|
|
188
|
-
created: false,
|
|
189
|
-
layout: buildTmpLayout(resolvedRoot, readTmpFile(canonical), canonical),
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
const existing = findFileRecursively(resolvedRoot, Constants.tmpBaseName, Constants.tmpExtension);
|
|
195
|
-
if (existing) {
|
|
196
|
-
return {
|
|
197
|
-
tmpFilePath: existing,
|
|
198
|
-
created: false,
|
|
199
|
-
layout: buildTmpLayout(resolvedRoot, readTmpFile(existing), existing),
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
const resolvedTemplate = options.templatePath ?? resolveBundledCoreTmpPath(resolvedRoot);
|
|
204
|
-
if (!fs.existsSync(resolvedTemplate)) {
|
|
205
|
-
throw new Error('@xrystal/core bundled x/tmp.yml not found');
|
|
206
|
-
}
|
|
207
|
-
const layout = buildTmpLayout(resolvedRoot, null, null);
|
|
208
|
-
fs.mkdirSync(layout.rootFolderAbs, { recursive: true });
|
|
209
|
-
const targetPath = ownerTmpFilePath(resolvedRoot, layout);
|
|
210
|
-
let content = fs.readFileSync(resolvedTemplate, 'utf8');
|
|
211
|
-
if (patchServiceName) {
|
|
212
|
-
try {
|
|
213
|
-
const pkgPath = path.join(resolvedRoot, 'package.json');
|
|
214
|
-
if (fs.existsSync(pkgPath)) {
|
|
215
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
216
|
-
const serviceName = typeof pkg.name === 'string'
|
|
217
|
-
? pkg.name.replace(/^@/, '').replace(/\//g, '-')
|
|
218
|
-
: null;
|
|
219
|
-
if (serviceName) {
|
|
220
|
-
const tmp = yaml.parse(content);
|
|
221
|
-
const configs = tmp.configs ?? {};
|
|
222
|
-
configs.service = serviceName;
|
|
223
|
-
tmp.configs = configs;
|
|
224
|
-
content = yaml.stringify(tmp);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch {
|
|
229
|
-
// keep template as-is
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
fs.writeFileSync(targetPath, content);
|
|
233
|
-
return {
|
|
234
|
-
tmpFilePath: targetPath,
|
|
235
|
-
created: true,
|
|
236
|
-
layout: buildTmpLayout(resolvedRoot, readTmpFile(targetPath), targetPath),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
export function resolveTmpLayoutEnsured(projectRoot = process.cwd()) {
|
|
240
|
-
return ensureTmpFile(projectRoot).layout;
|
|
241
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { PolarityTypeEnum } from "../../../utils/models";
|
|
2
|
-
export function dateZoneConverter({ polarity, date, zone, factor = 1000 }) {
|
|
3
|
-
let convertedZoneTime = null;
|
|
4
|
-
if (polarity === PolarityTypeEnum.NEGATIVE) {
|
|
5
|
-
convertedZoneTime = date.getTime() - factor * zone;
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
convertedZoneTime = date.getTime() + factor * zone;
|
|
9
|
-
}
|
|
10
|
-
return new Date(convertedZoneTime).toISOString();
|
|
11
|
-
}
|
|
12
|
-
export function convertDate(date, splitCharacter = '/', replaceCharacter = '-') {
|
|
13
|
-
const convertDate = date.split(splitCharacter).map((value, index) => index !== 2 ? replaceCharacter : value);
|
|
14
|
-
return convertDate;
|
|
15
|
-
}
|
|
16
|
-
export function convertTime(time, splitCharacter = ':', replaceCharacter = '-') {
|
|
17
|
-
const convertDate = time.split(splitCharacter).map((value, index) => index !== 2 ? replaceCharacter : value);
|
|
18
|
-
return convertDate;
|
|
19
|
-
}
|
|
20
|
-
export function getDateAndTime({ getDate = true, getTime = true, dateCharacter = '-', timeCharacter = ':', separatorCharacter = '&' }) {
|
|
21
|
-
const date = new Date();
|
|
22
|
-
let formattedDate = '';
|
|
23
|
-
if (!getDate && !getTime) {
|
|
24
|
-
throw new Error("Invalid options! Required one true value");
|
|
25
|
-
}
|
|
26
|
-
if (getDate) {
|
|
27
|
-
const day = date.getDate().toString().padStart(2, '0');
|
|
28
|
-
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
29
|
-
const year = date.getFullYear();
|
|
30
|
-
formattedDate = `${year}${dateCharacter}${month}${dateCharacter}${day}`;
|
|
31
|
-
}
|
|
32
|
-
if (getTime) {
|
|
33
|
-
const hours = date.getHours().toString().padStart(2, '0');
|
|
34
|
-
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
35
|
-
const seconds = date.getSeconds().toString().padStart(2, '0');
|
|
36
|
-
formattedDate = `${hours}${timeCharacter}${minutes}${timeCharacter}${seconds}`;
|
|
37
|
-
}
|
|
38
|
-
if (getDate && getTime) {
|
|
39
|
-
const day = date.getDate().toString().padStart(2, '0');
|
|
40
|
-
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
41
|
-
const year = date.getFullYear();
|
|
42
|
-
const hours = date.getHours().toString().padStart(2, '0');
|
|
43
|
-
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
44
|
-
const seconds = date.getSeconds().toString().padStart(2, '0');
|
|
45
|
-
formattedDate = `${year}${dateCharacter}${month}${dateCharacter}${day}${separatorCharacter}${hours}${timeCharacter}${minutes}${timeCharacter}${seconds}`;
|
|
46
|
-
}
|
|
47
|
-
return formattedDate;
|
|
48
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { expressSink } from '@xrystal/dto/express';
|
|
2
|
-
import { nodeSink } from '@xrystal/dto/node';
|
|
3
|
-
import { fetchSink } from '@xrystal/dto/fetch';
|
|
4
|
-
import { elysiaSink } from '@xrystal/dto/elysia';
|
|
5
|
-
import { websocketSink } from '@xrystal/dto/websocket';
|
|
6
|
-
import { socketIoSink } from '@xrystal/dto/socketio';
|
|
7
|
-
import { FrameworkEnum, ProtocolEnum } from '../../../utils/models';
|
|
8
|
-
import { getFramework } from '../../../utils/helpers/framework';
|
|
9
|
-
import { getDtoRuntime } from '../../../utils/helpers/runtime';
|
|
10
|
-
export { expressSink } from '@xrystal/dto/express';
|
|
11
|
-
export { nodeSink } from '@xrystal/dto/node';
|
|
12
|
-
export { fetchSink } from '@xrystal/dto/fetch';
|
|
13
|
-
export { elysiaSink } from '@xrystal/dto/elysia';
|
|
14
|
-
export { websocketSink } from '@xrystal/dto/websocket';
|
|
15
|
-
export { socketIoSink } from '@xrystal/dto/socketio';
|
|
16
|
-
export { dispatchExpressResponse, dispatchNodeResponse, toFetchResponse, applyElysiaTransport, dispatchWebSocketMessage, dispatchSocketIoMessage, } from '@xrystal/dto/response';
|
|
17
|
-
const isFinalResult = (value) => !!value && typeof value === 'object' && 'body' in value && 'statusCode' in value;
|
|
18
|
-
const isRawResponse = (value) => value instanceof Response || value instanceof Blob || value instanceof Uint8Array || value instanceof ArrayBuffer;
|
|
19
|
-
const socketOf = (store) => store.socket ?? store.ctx?.ws ?? store.ctx;
|
|
20
|
-
const socketEvent = () => getDtoRuntime().config.socket?.event ?? 'response';
|
|
21
|
-
export function dispatchResult(result, store, res) {
|
|
22
|
-
if (result === undefined || result === null)
|
|
23
|
-
return;
|
|
24
|
-
if (isRawResponse(result))
|
|
25
|
-
return result;
|
|
26
|
-
if (!isFinalResult(result))
|
|
27
|
-
return result;
|
|
28
|
-
if (store.protocol === ProtocolEnum.SOCKETIO || store.framework === FrameworkEnum.SOCKETIO) {
|
|
29
|
-
socketIoSink(socketOf(store), socketEvent()).dispatch(result);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (store.protocol === ProtocolEnum.WEBSOCKET || store.framework === FrameworkEnum.WEBSOCKET) {
|
|
33
|
-
websocketSink(socketOf(store)).dispatch(result);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const fw = store.framework ?? getFramework();
|
|
37
|
-
const response = res;
|
|
38
|
-
switch (fw) {
|
|
39
|
-
case FrameworkEnum.EXPRESS:
|
|
40
|
-
if (response && !response.headersSent)
|
|
41
|
-
expressSink(res).dispatch(result);
|
|
42
|
-
return;
|
|
43
|
-
case FrameworkEnum.NODE:
|
|
44
|
-
if (response && !response.headersSent)
|
|
45
|
-
nodeSink(res).dispatch(result);
|
|
46
|
-
return;
|
|
47
|
-
case FrameworkEnum.FETCH:
|
|
48
|
-
return fetchSink.dispatch(result);
|
|
49
|
-
case FrameworkEnum.ELYSIA:
|
|
50
|
-
default:
|
|
51
|
-
return elysiaSink(store.ctx?.set ?? {}).dispatch(result);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { DTO, createDTO } from '@xrystal/dto/dto';
|
|
2
|
-
export { ResponseDTO, Builder, createBuilderProxy, ResponsePresets, assembleResponseBody, dispatchExpressResponse, dispatchNodeResponse, toFetchResponse, applyElysiaTransport, dispatchWebSocketMessage, dispatchSocketIoMessage, } from '@xrystal/dto/response';
|
|
3
|
-
export { expressSink, expressMiddleware, ExpressAdapter } from '@xrystal/dto/express';
|
|
4
|
-
export { nodeSink, nodeMiddleware, NodeAdapter } from '@xrystal/dto/node';
|
|
5
|
-
export { fetchSink, fetchDerive, FetchAdapter } from '@xrystal/dto/fetch';
|
|
6
|
-
export { elysiaSink, ElysiaAdapter } from '@xrystal/dto/elysia';
|
|
7
|
-
export { websocketSink, WebSocketAdapter } from '@xrystal/dto/websocket';
|
|
8
|
-
export { socketIoSink, SocketIoAdapter } from '@xrystal/dto/socketio';
|
|
9
|
-
export { LogDTO, assembleLogBody, } from '@xrystal/dto/log';
|
|
10
|
-
export { QueueDTO, assembleQueueMessage, } from '@xrystal/dto/queue';
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
function mongoFilter(start, end, objPath) {
|
|
2
|
-
const filter = {};
|
|
3
|
-
if (!objPath) {
|
|
4
|
-
throw new Error('MongoFilter helper property is required.');
|
|
5
|
-
}
|
|
6
|
-
filter[objPath] = filter[objPath] || {};
|
|
7
|
-
if (start && end) {
|
|
8
|
-
filter[objPath].$gte = start;
|
|
9
|
-
filter[objPath].$lte = end;
|
|
10
|
-
}
|
|
11
|
-
else if (start) {
|
|
12
|
-
filter[objPath].$gte = start;
|
|
13
|
-
}
|
|
14
|
-
else if (end) {
|
|
15
|
-
filter[objPath].$lte = end;
|
|
16
|
-
}
|
|
17
|
-
return filter;
|
|
18
|
-
}
|
|
19
|
-
function filterUniqueOnce({ arr, key, uniqueOnceValues }) {
|
|
20
|
-
const seen = new Set();
|
|
21
|
-
return arr.filter(item => {
|
|
22
|
-
const val = item[key];
|
|
23
|
-
if (uniqueOnceValues.includes(val)) {
|
|
24
|
-
if (seen.has(val))
|
|
25
|
-
return false;
|
|
26
|
-
seen.add(val);
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
return true;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
function filterSortByPropOrder({ arr, key, desiredOrder }) {
|
|
33
|
-
const orderMap = new Map();
|
|
34
|
-
desiredOrder.forEach((value, index) => orderMap.set(value, index));
|
|
35
|
-
return [...arr].sort((a, b) => {
|
|
36
|
-
const aIndex = orderMap.get(a[key]) ?? Infinity;
|
|
37
|
-
const bIndex = orderMap.get(b[key]) ?? Infinity;
|
|
38
|
-
return aIndex - bIndex;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function filterRemoveItemsByProps({ arr, key, valuesToRemove }) {
|
|
42
|
-
return arr.filter(item => !valuesToRemove.includes(item[key]));
|
|
43
|
-
}
|
|
44
|
-
export { mongoFilter, filterUniqueOnce, filterSortByPropOrder, filterRemoveItemsByProps };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getRuntimeTmpConfigs } from '../../../utils/helpers/tmp/runtime-tmp';
|
|
2
|
-
import { FrameworkEnum } from '../../../utils/models';
|
|
3
|
-
const values = new Set(Object.values(FrameworkEnum));
|
|
4
|
-
export function parseFramework(value) {
|
|
5
|
-
const key = value ? String(value).toLowerCase() : undefined;
|
|
6
|
-
return key && values.has(key) ? key : FrameworkEnum.ELYSIA;
|
|
7
|
-
}
|
|
8
|
-
export function getFramework(override) {
|
|
9
|
-
if (override)
|
|
10
|
-
return override;
|
|
11
|
-
try {
|
|
12
|
-
return parseFramework(getRuntimeTmpConfigs()?.framework);
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return FrameworkEnum.ELYSIA;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { FrameworkEnum, ProtocolEnum } from '../../../utils/models';
|
|
2
|
-
import { detectSocketProtocol } from '../../../utils/helpers/protocol';
|
|
3
|
-
import { getFramework } from '../../../utils/helpers/framework';
|
|
4
|
-
import { runAction } from '../../../utils/helpers/handlers/execute';
|
|
5
|
-
export function toRealtimeHandler(action, protocol) {
|
|
6
|
-
const runFor = (socket) => {
|
|
7
|
-
const resolved = detectSocketProtocol(socket, protocol);
|
|
8
|
-
return runAction({ socket: socket, ctx: { ws: socket }, protocol: resolved }, action);
|
|
9
|
-
};
|
|
10
|
-
const handler = (socket) => runFor(socket);
|
|
11
|
-
handler.with = (socket) => () => runFor(socket);
|
|
12
|
-
return handler;
|
|
13
|
-
}
|
|
14
|
-
export const toHandler = (action, framework) => {
|
|
15
|
-
const fw = framework ?? getFramework();
|
|
16
|
-
switch (fw) {
|
|
17
|
-
case FrameworkEnum.ELYSIA:
|
|
18
|
-
return (elysiaCtx) => runAction({ framework: fw, ctx: elysiaCtx }, action);
|
|
19
|
-
case FrameworkEnum.FETCH:
|
|
20
|
-
return (req, serverCtx) => runAction({ framework: fw, ctx: { request: req, ...serverCtx } }, action);
|
|
21
|
-
case FrameworkEnum.NODE:
|
|
22
|
-
return (req, res) => runAction({ framework: fw, req: req, res: res }, action, res);
|
|
23
|
-
case FrameworkEnum.EXPRESS:
|
|
24
|
-
return (req, res, next) => {
|
|
25
|
-
runAction({
|
|
26
|
-
framework: fw,
|
|
27
|
-
req: req,
|
|
28
|
-
res: res,
|
|
29
|
-
metadata: { locals: res.locals || {} },
|
|
30
|
-
}, action, res).catch(next);
|
|
31
|
-
};
|
|
32
|
-
case FrameworkEnum.WEBSOCKET:
|
|
33
|
-
case FrameworkEnum.SOCKETIO:
|
|
34
|
-
throw new Error('[xrystal] realtime: ctr({ ... }, { protocol: "ws" | "socketio" })');
|
|
35
|
-
default:
|
|
36
|
-
return (elysiaCtx) => runAction({ framework: FrameworkEnum.ELYSIA, ctx: elysiaCtx }, action);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
export const toWebSocket = (socket, action) => toRealtimeHandler(action, ProtocolEnum.WEBSOCKET)(socket);
|
|
40
|
-
export const toSocketIo = (socket, action) => toRealtimeHandler(action, ProtocolEnum.SOCKETIO)(socket);
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { FrameworkEnum, ProtocolEnum } from '../../../utils/models';
|
|
3
|
-
import { runControllerStore, } from '../../../utils/helpers/context';
|
|
4
|
-
import { runWithRequestId } from '../../../utils/helpers/context';
|
|
5
|
-
import { dispatchResult } from '../../../utils/helpers/dispatch';
|
|
6
|
-
import { getFramework } from '../../../utils/helpers/framework';
|
|
7
|
-
import { attachSocketTransport, isRealtimeProtocol, } from '../../../utils/helpers/protocol';
|
|
8
|
-
import { getDtoRuntime } from '../../../utils/helpers/runtime';
|
|
9
|
-
export const runController = runControllerStore;
|
|
10
|
-
const ctx = (partial) => ({
|
|
11
|
-
framework: partial.framework ?? (isRealtimeProtocol(partial.protocol) ? undefined : getFramework()),
|
|
12
|
-
protocol: partial.protocol ?? ProtocolEnum.HTTP,
|
|
13
|
-
...partial,
|
|
14
|
-
metadata: { locals: {}, ...partial.metadata },
|
|
15
|
-
});
|
|
16
|
-
const header = (headers, name) => {
|
|
17
|
-
if (!headers)
|
|
18
|
-
return undefined;
|
|
19
|
-
if (headers instanceof Headers)
|
|
20
|
-
return headers.get(name) ?? headers.get(name.toLowerCase());
|
|
21
|
-
if (typeof headers.get === 'function') {
|
|
22
|
-
const get = headers.get;
|
|
23
|
-
return get(name) ?? get(name.toLowerCase());
|
|
24
|
-
}
|
|
25
|
-
const record = headers;
|
|
26
|
-
return record[name] ?? record[name.toLowerCase()];
|
|
27
|
-
};
|
|
28
|
-
const readRequestId = (partial) => {
|
|
29
|
-
const c = partial.ctx ?? {};
|
|
30
|
-
const r = partial.req ?? {};
|
|
31
|
-
const h = (r.headers ?? c.request?.headers);
|
|
32
|
-
return partial.requestId
|
|
33
|
-
?? c.requestId
|
|
34
|
-
?? r.ctx?.requestId
|
|
35
|
-
?? header(h, 'x-request-id')
|
|
36
|
-
?? header(h, 'x-correlation-id')
|
|
37
|
-
?? '';
|
|
38
|
-
};
|
|
39
|
-
const ensureRequestId = (store) => {
|
|
40
|
-
const id = String(readRequestId(store) || randomUUID());
|
|
41
|
-
store.requestId = id;
|
|
42
|
-
store.ctx = { ...store.ctx, requestId: id };
|
|
43
|
-
if (store.req)
|
|
44
|
-
store.req.ctx = { ...store.req.ctx, requestId: id };
|
|
45
|
-
return id;
|
|
46
|
-
};
|
|
47
|
-
const attachFetchBuilder = (store) => {
|
|
48
|
-
if (store.framework !== FrameworkEnum.FETCH || store.ctx?.builder)
|
|
49
|
-
return;
|
|
50
|
-
const request = store.ctx?.request ?? store.req;
|
|
51
|
-
if (!(request instanceof Request))
|
|
52
|
-
return;
|
|
53
|
-
store.ctx = { ...store.ctx, ...getDtoRuntime().forRequest(request) };
|
|
54
|
-
if (store.ctx.requestId)
|
|
55
|
-
store.requestId = String(store.ctx.requestId);
|
|
56
|
-
};
|
|
57
|
-
const send = async (result, store, res) => {
|
|
58
|
-
const out = dispatchResult(result, store, res);
|
|
59
|
-
const response = res;
|
|
60
|
-
if (out instanceof Response && response?.send) {
|
|
61
|
-
response.status?.(out.status);
|
|
62
|
-
out.headers.forEach((v, k) => response.setHeader?.(k, v));
|
|
63
|
-
const type = out.headers.get('content-type') || '';
|
|
64
|
-
if (type.includes('json') || type.includes('text/'))
|
|
65
|
-
return response.send(await out.text());
|
|
66
|
-
return response.send(Buffer.from(await out.arrayBuffer()));
|
|
67
|
-
}
|
|
68
|
-
return out;
|
|
69
|
-
};
|
|
70
|
-
const runKind = (store) => isRealtimeProtocol(store.protocol) ? 'ws' : 'http';
|
|
71
|
-
export async function runAction(partial, action, res) {
|
|
72
|
-
const store = ctx(partial);
|
|
73
|
-
if (isRealtimeProtocol(store.protocol) && store.socket && !store.socket.builder) {
|
|
74
|
-
attachSocketTransport(store.socket, store.protocol, getDtoRuntime());
|
|
75
|
-
}
|
|
76
|
-
attachFetchBuilder(store);
|
|
77
|
-
const id = ensureRequestId(store);
|
|
78
|
-
return runWithRequestId(id, () => runController(store, async () => send(await action(), store, res)), runKind(store));
|
|
79
|
-
}
|
|
80
|
-
export function configureDto(config, options) {
|
|
81
|
-
return getDtoRuntime().configure(config, options);
|
|
82
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { FrameworkEnum } from '../../../utils/models';
|
|
2
|
-
import { createDtoMiddleware } from '../../../utils/helpers/middleware';
|
|
3
|
-
import { attachSocketTransport, detectSocketProtocol, resolveRealtimeMiddlewareProtocol, } from '../../../utils/helpers/protocol';
|
|
4
|
-
import { getDtoRuntime } from '../../../utils/helpers/runtime';
|
|
5
|
-
export { runAction, runController, configureDto } from '../../../utils/helpers/handlers/execute';
|
|
6
|
-
export { toHandler, toRealtimeHandler, toWebSocket, toSocketIo } from '../../../utils/helpers/handlers/adapters';
|
|
7
|
-
export { getFramework } from '../../../utils/helpers/framework';
|
|
8
|
-
export { dispatchResult } from '../../../utils/helpers/dispatch';
|
|
9
|
-
export { getRequestId, getRunContext, runWithContext, runWithRequestId, runWithTrace } from '../../../utils/helpers/context';
|
|
10
|
-
export { G, propsFromTmp, resolveGStoreBoot, G_PROP_NOT_ALLOWED, G_REQUEST_KEY_WARN, looksLikeRequestScopedKey, GStoreScopeEnum, } from '../../../utils/helpers/state';
|
|
11
|
-
export { bindLoaderTmpSync, getRuntimeTmpConfigs, setRuntimeTmpConfigs, onRuntimeTmpChange, notifyRuntimeTmpChange, getTmpSnapshot, onTmpReload, } from '../../../utils/helpers/tmp';
|
|
12
|
-
export { normalizeFrameworkKind, createDtoMiddleware, resolveDtoAdapter, } from '../../../utils/helpers/middleware';
|
|
13
|
-
export { resolveCtrOptions } from '../../../utils/helpers/protocol/options';
|
|
14
|
-
export { parseProtocol, getConfiguredProtocols, getConfiguredRealtimeProtocols, defaultRealtimeProtocolFromConfig, getDefaultRealtimeProtocol, resolveRealtimeMiddlewareProtocol, detectSocketProtocol, isRealtimeProtocol, isHttpProtocol, resolveProtocolsFromConfig, REALTIME_MIDDLEWARE_HINT, } from '../../../utils/helpers/protocol';
|
|
15
|
-
export { getDtoRuntime } from '../../../utils/helpers/runtime';
|
|
16
|
-
export const dtoMiddleware = (config) => createDtoMiddleware(getDtoRuntime(), config);
|
|
17
|
-
export function realtimeMiddleware(protocol) {
|
|
18
|
-
const fixed = resolveRealtimeMiddlewareProtocol(protocol);
|
|
19
|
-
return (socket, next) => {
|
|
20
|
-
try {
|
|
21
|
-
const resolved = detectSocketProtocol(socket, fixed);
|
|
22
|
-
attachSocketTransport(socket, resolved, getDtoRuntime());
|
|
23
|
-
next?.();
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
next?.(error instanceof Error ? error : new Error(String(error)));
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
export const websocketMiddleware = (config) => config ? createDtoMiddleware(getDtoRuntime(), config) : realtimeMiddleware('ws');
|
|
31
|
-
export const socketIoMiddleware = (config) => config ? createDtoMiddleware(getDtoRuntime(), config ?? FrameworkEnum.SOCKETIO) : realtimeMiddleware('socketio');
|