@xrystal/core 3.55.12 → 3.55.13
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 +3 -9
- package/package.json +1 -1
- package/x/bin/helpers/resolve-infra-helper.mjs +22 -3
- package/x/dist/loader/configs/index.d.ts +3 -0
- package/x/dist/loader/configs/index.js +2 -0
- package/x/dist/loader/redis/index.d.ts +1 -0
- package/x/dist/loader/redis/index.js +17 -7
- package/x/dist/loader/redis/parse-uri.d.ts +16 -0
- package/x/dist/loader/redis/parse-uri.js +92 -0
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
## Platform services / Platform servisleri
|
|
11
11
|
|
|
12
|
-
**EN:** Consumer microservices in `../services/` — pin `@xrystal/core
|
|
12
|
+
**EN:** Consumer microservices in `../services/` — table below is the **pin matrix** (service pkg + `@xrystal/core`; bump rows when you ship). Apply pins with **`xry sync`** (not manual `bun add` per repo).
|
|
13
13
|
|
|
14
|
-
**TR:** `../services/` altındaki
|
|
14
|
+
**TR:** `../services/` altındaki microservice'ler — tablo **pin matrisi** (servis sürümü + `@xrystal/core`; release sonrası satırları güncelle). Pin uygulama: **`xry sync`** (her repo için elle `bun add` yazma).
|
|
15
15
|
|
|
16
16
|
| Repo folder | `tmp.yml` name | Role | Service pkg | `@xrystal/core` |
|
|
17
17
|
|-------------|----------------|------|-------------|-----------------|
|
|
@@ -31,13 +31,7 @@ import { resolveRedisSocketOptions } from '@xrystal/core/loader/redis'
|
|
|
31
31
|
import { resolveMongoConnectOptions } from '@xrystal/core/loader/mongo'
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
**
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
cd ../services/api-<name>-svc
|
|
38
|
-
bun add @xrystal/core@3.52.5
|
|
39
|
-
bun run build
|
|
40
|
-
```
|
|
34
|
+
**After `@xrystal/core` publish / core yayın sonrası:** workspace root → `xry sync` (all linked `api/*` pins to CLI version). One service → `cd` that repo → `xry sync`. Build/tag images = each service’s own release flow (see monorepo release order in infra).
|
|
41
35
|
|
|
42
36
|
---
|
|
43
37
|
|
package/package.json
CHANGED
|
@@ -48,11 +48,30 @@ export function listInfraRootCandidates(start = process.cwd()) {
|
|
|
48
48
|
return out
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
function findHelperScriptUnderRoot(root, name) {
|
|
52
|
+
const base = path.join(root, HELPERS_DIR)
|
|
53
|
+
const direct = path.join(base, name)
|
|
54
|
+
if (fs.existsSync(direct)) return direct
|
|
55
|
+
|
|
56
|
+
let entries
|
|
57
|
+
try {
|
|
58
|
+
entries = fs.readdirSync(base, { withFileTypes: true })
|
|
59
|
+
} catch {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
for (const ent of entries) {
|
|
63
|
+
if (!ent.isDirectory()) continue
|
|
64
|
+
const nested = path.join(base, ent.name, name)
|
|
65
|
+
if (fs.existsSync(nested)) return nested
|
|
66
|
+
}
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Resolve a script under -infrastructure-/scripts/helpers (incl. domain subdirs). */
|
|
52
71
|
export function resolveInfraHelperScript(name, { cwd = process.cwd() } = {}) {
|
|
53
72
|
for (const root of listInfraRootCandidates(cwd)) {
|
|
54
|
-
const script =
|
|
55
|
-
if (
|
|
73
|
+
const script = findHelperScriptUnderRoot(root, name)
|
|
74
|
+
if (script) return script
|
|
56
75
|
}
|
|
57
76
|
return null
|
|
58
77
|
}
|
|
@@ -27,6 +27,9 @@ export interface IConfig {
|
|
|
27
27
|
kafkaLogsTopic: string;
|
|
28
28
|
isRedisPassive: boolean;
|
|
29
29
|
redisUri: string;
|
|
30
|
+
/** false = force standalone URL; default Sentinel when URI has comma hosts or :26379 */
|
|
31
|
+
isRedisSentinel: boolean;
|
|
32
|
+
redisSentinelMaster: string;
|
|
30
33
|
isMongoPassive: boolean;
|
|
31
34
|
mongodbUri: string;
|
|
32
35
|
isRegistryEnabled: boolean;
|
|
@@ -67,6 +67,8 @@ export default class Configs {
|
|
|
67
67
|
kafkaLogsTopic: this.kafkaLogsTopic,
|
|
68
68
|
isRedisPassive: process.env.IS_REDIS_PASSIVE === 'true' ? true : false,
|
|
69
69
|
redisUri: process.env.REDIS_URI ?? '',
|
|
70
|
+
isRedisSentinel: process.env.IS_REDIS_SENTINEL === 'false' ? false : true,
|
|
71
|
+
redisSentinelMaster: process.env.REDIS_SENTINEL_MASTER ?? 'mymaster',
|
|
70
72
|
isMongoPassive: process.env.IS_MONGODB_PASSIVE === 'true' ? true : false,
|
|
71
73
|
mongodbUri: process.env.MONGODB_URI ?? '',
|
|
72
74
|
isRegistryEnabled: process.env.IS_REGISTRY_ENABLED === 'true',
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export { resolveRedisSocketOptions } from './resolve-socket.js';
|
|
2
|
+
export { parseRedisUri, standaloneRedisUrl } from './parse-uri.js';
|
|
2
3
|
import { createClient, createSentinel } from 'redis';
|
|
3
4
|
import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
|
|
4
5
|
import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
|
|
5
6
|
import { InfraLoaderEnum } from '../../utils/models/enums/index.js';
|
|
7
|
+
import { parseRedisUri, standaloneRedisUrl } from './parse-uri.js';
|
|
6
8
|
import { resolveRedisSocketOptions } from './resolve-socket.js';
|
|
7
9
|
function parseSentinelRootNodes(csv) {
|
|
8
10
|
return csv
|
|
@@ -47,20 +49,27 @@ export default class RedisForCore {
|
|
|
47
49
|
if (!uri) {
|
|
48
50
|
return;
|
|
49
51
|
}
|
|
52
|
+
const parsed = parseRedisUri(uri);
|
|
50
53
|
const socketOpts = resolveRedisSocketOptions(uri);
|
|
51
|
-
const
|
|
52
|
-
|
|
54
|
+
const sentinelMaster = process.env.REDIS_SENTINEL_MASTER?.trim() ||
|
|
55
|
+
this.#configs.all.redisSentinelMaster?.trim() ||
|
|
56
|
+
'mymaster';
|
|
57
|
+
const envSentinelHosts = process.env.REDIS_SENTINEL_HOSTS?.trim();
|
|
58
|
+
const preferSentinel = this.#configs.all.isRedisSentinel !== false &&
|
|
59
|
+
(envSentinelHosts ? true : parsed.useSentinel);
|
|
53
60
|
let client;
|
|
54
|
-
if (
|
|
55
|
-
const rootNodes =
|
|
61
|
+
if (preferSentinel) {
|
|
62
|
+
const rootNodes = envSentinelHosts
|
|
63
|
+
? parseSentinelRootNodes(envSentinelHosts)
|
|
64
|
+
: parsed.endpoints.map((e) => ({ host: e.host, port: e.port }));
|
|
56
65
|
if (rootNodes.length === 0) {
|
|
57
|
-
throw new Error('
|
|
66
|
+
throw new Error('Redis Sentinel mode requires at least one sentinel endpoint');
|
|
58
67
|
}
|
|
59
68
|
client = (await createSentinel({
|
|
60
69
|
name: sentinelMaster,
|
|
61
70
|
sentinelRootNodes: rootNodes,
|
|
62
71
|
nodeClientOptions: {
|
|
63
|
-
|
|
72
|
+
...parsed.creds,
|
|
64
73
|
socket: socketOpts,
|
|
65
74
|
},
|
|
66
75
|
sentinelClientOptions: {
|
|
@@ -69,8 +78,9 @@ export default class RedisForCore {
|
|
|
69
78
|
}).connect());
|
|
70
79
|
}
|
|
71
80
|
else {
|
|
81
|
+
const standaloneUrl = standaloneRedisUrl(uri, parsed.endpoints);
|
|
72
82
|
client = (await createClient({
|
|
73
|
-
url:
|
|
83
|
+
url: standaloneUrl,
|
|
74
84
|
socket: socketOpts,
|
|
75
85
|
}).connect());
|
|
76
86
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type RedisEndpoint = {
|
|
2
|
+
host: string;
|
|
3
|
+
port: number;
|
|
4
|
+
};
|
|
5
|
+
export type ParsedRedisUri = {
|
|
6
|
+
creds: {
|
|
7
|
+
username?: string;
|
|
8
|
+
password?: string;
|
|
9
|
+
};
|
|
10
|
+
endpoints: RedisEndpoint[];
|
|
11
|
+
/** HA comma hosts or sentinel port → use createSentinel */
|
|
12
|
+
useSentinel: boolean;
|
|
13
|
+
};
|
|
14
|
+
/** Comma-host rediss:// URIs are not valid for `new URL()` — parse manually. */
|
|
15
|
+
export declare function parseRedisUri(uri: string): ParsedRedisUri;
|
|
16
|
+
export declare function standaloneRedisUrl(uri: string, endpoints: RedisEndpoint[]): string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const DEFAULT_SENTINEL_PORT = 26379;
|
|
2
|
+
const DEFAULT_DATA_PORT = 6379;
|
|
3
|
+
function decodeCred(part) {
|
|
4
|
+
if (!part) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
return decodeURIComponent(part);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return part;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function splitAuthAndHosts(netloc) {
|
|
15
|
+
const at = netloc.lastIndexOf('@');
|
|
16
|
+
if (at === -1) {
|
|
17
|
+
return { auth: '', hostsCsv: netloc };
|
|
18
|
+
}
|
|
19
|
+
return { auth: netloc.slice(0, at), hostsCsv: netloc.slice(at + 1) };
|
|
20
|
+
}
|
|
21
|
+
function parseAuth(auth) {
|
|
22
|
+
if (!auth) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
const colon = auth.indexOf(':');
|
|
26
|
+
if (colon === -1) {
|
|
27
|
+
return { username: decodeCred(auth) };
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
username: decodeCred(auth.slice(0, colon)),
|
|
31
|
+
password: decodeCred(auth.slice(colon + 1)),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function parseHostsCsv(hostsCsv) {
|
|
35
|
+
return hostsCsv
|
|
36
|
+
.split(',')
|
|
37
|
+
.map((part) => part.trim())
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.map((part) => {
|
|
40
|
+
const colon = part.lastIndexOf(':');
|
|
41
|
+
if (colon === -1) {
|
|
42
|
+
return { host: part, port: DEFAULT_DATA_PORT };
|
|
43
|
+
}
|
|
44
|
+
const host = part.slice(0, colon);
|
|
45
|
+
const port = Number.parseInt(part.slice(colon + 1), 10);
|
|
46
|
+
return { host, port: Number.isFinite(port) ? port : DEFAULT_DATA_PORT };
|
|
47
|
+
})
|
|
48
|
+
.filter((e) => e.host.length > 0);
|
|
49
|
+
}
|
|
50
|
+
function isSentinelEndpoints(endpoints) {
|
|
51
|
+
if (endpoints.length > 1) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
return endpoints.length === 1 && endpoints[0].port === DEFAULT_SENTINEL_PORT;
|
|
55
|
+
}
|
|
56
|
+
/** Comma-host rediss:// URIs are not valid for `new URL()` — parse manually. */
|
|
57
|
+
export function parseRedisUri(uri) {
|
|
58
|
+
const trimmed = uri.trim();
|
|
59
|
+
const schemeEnd = trimmed.indexOf('://');
|
|
60
|
+
if (schemeEnd === -1) {
|
|
61
|
+
throw new Error('Invalid Redis URI: missing scheme');
|
|
62
|
+
}
|
|
63
|
+
const rest = trimmed.slice(schemeEnd + 3);
|
|
64
|
+
const pathStart = rest.search(/[/?#]/);
|
|
65
|
+
const authority = pathStart === -1 ? rest : rest.slice(0, pathStart);
|
|
66
|
+
const { auth, hostsCsv } = splitAuthAndHosts(authority);
|
|
67
|
+
const endpoints = parseHostsCsv(hostsCsv);
|
|
68
|
+
if (endpoints.length === 0) {
|
|
69
|
+
throw new Error('Invalid Redis URI: no hosts');
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
creds: parseAuth(auth),
|
|
73
|
+
endpoints,
|
|
74
|
+
useSentinel: isSentinelEndpoints(endpoints),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export function standaloneRedisUrl(uri, endpoints) {
|
|
78
|
+
if (endpoints.length !== 1) {
|
|
79
|
+
throw new Error('standalone Redis URL requires exactly one endpoint');
|
|
80
|
+
}
|
|
81
|
+
const trimmed = uri.trim();
|
|
82
|
+
const schemeEnd = trimmed.indexOf('://');
|
|
83
|
+
const scheme = trimmed.slice(0, schemeEnd + 3);
|
|
84
|
+
const rest = trimmed.slice(schemeEnd + 3);
|
|
85
|
+
const pathStart = rest.search(/[/?#]/);
|
|
86
|
+
const suffix = pathStart === -1 ? '' : rest.slice(pathStart);
|
|
87
|
+
const { auth } = splitAuthAndHosts(pathStart === -1 ? rest : rest.slice(0, pathStart));
|
|
88
|
+
const ep = endpoints[0];
|
|
89
|
+
const hostPart = ep.host.includes(':') ? `[${ep.host}]` : ep.host;
|
|
90
|
+
const netloc = auth ? `${auth}@${hostPart}:${ep.port}` : `${hostPart}:${ep.port}`;
|
|
91
|
+
return `${scheme}${netloc}${suffix}`;
|
|
92
|
+
}
|