underpost 2.8.843 → 2.8.845
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/.github/workflows/{ghpkg.yml → ghpkg.ci.yml} +1 -1
- package/.github/workflows/{npmpkg.yml → npmpkg.ci.yml} +1 -1
- package/.github/workflows/{publish.yml → publish.ci.yml} +1 -1
- package/.github/workflows/{pwa-microservices-template.page.yml → pwa-microservices-template-page.cd.yml} +1 -1
- package/.github/workflows/{pwa-microservices-template.test.yml → pwa-microservices-template-test.ci.yml} +1 -1
- package/.vscode/settings.json +0 -1
- package/README.md +18 -2
- package/bin/build.js +8 -5
- package/bin/deploy.js +10 -69
- package/bin/file.js +15 -11
- package/cli.md +47 -43
- package/docker-compose.yml +1 -1
- package/manifests/deployment/dd-template-development/deployment.yaml +2 -2
- package/manifests/maas/gpu-diag.sh +1 -1
- package/package.json +3 -5
- package/src/api/user/user.router.js +24 -1
- package/src/cli/cluster.js +19 -10
- package/src/cli/index.js +1 -0
- package/src/cli/run.js +21 -0
- package/src/client/components/core/Css.js +52 -2
- package/src/client/components/core/CssCore.js +0 -4
- package/src/client/components/core/Docs.js +10 -57
- package/src/client/components/core/DropDown.js +128 -82
- package/src/client/components/core/EventsUI.js +92 -5
- package/src/client/components/core/Modal.js +451 -120
- package/src/client/components/core/NotificationManager.js +2 -2
- package/src/client/components/core/Panel.js +2 -2
- package/src/client/components/core/PanelForm.js +12 -2
- package/src/client/components/core/Recover.js +1 -1
- package/src/client/components/core/Router.js +63 -2
- package/src/client/components/core/Translate.js +2 -2
- package/src/index.js +1 -1
- package/src/server/client-build-docs.js +205 -0
- package/src/server/client-build.js +11 -140
- package/src/server/valkey.js +102 -41
package/src/server/valkey.js
CHANGED
|
@@ -5,22 +5,71 @@ import { loggerFactory } from './logger.js';
|
|
|
5
5
|
|
|
6
6
|
const logger = loggerFactory(import.meta);
|
|
7
7
|
|
|
8
|
+
// Per-instance registries keyed by `${host}${path}`
|
|
8
9
|
const ValkeyInstances = {};
|
|
10
|
+
const DummyStores = {}; // in-memory Maps per instance
|
|
11
|
+
const ValkeyStatus = {}; // 'connected' | 'dummy' | 'error' | undefined
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
// Backward-compatible overall flag: true if any instance is connected
|
|
14
|
+
const isValkeyEnable = () => Object.values(ValkeyStatus).some((s) => s === 'connected');
|
|
11
15
|
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const isValkeyEnable = () => valkeyEnabled;
|
|
16
|
+
const _instanceKey = (opts = { host: '', path: '' }) => `${opts.host || ''}${opts.path || ''}`;
|
|
15
17
|
|
|
16
18
|
const createValkeyConnection = async (
|
|
17
|
-
instance = { host: '',
|
|
18
|
-
valkeyServerConnectionOptions = { host: '',
|
|
19
|
+
instance = { host: '', path: '' },
|
|
20
|
+
valkeyServerConnectionOptions = { host: '', path: '' },
|
|
19
21
|
) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
);
|
|
23
|
-
|
|
22
|
+
const key = _instanceKey(instance);
|
|
23
|
+
// Initialize dummy store for the instance
|
|
24
|
+
if (!DummyStores[key]) DummyStores[key] = new Map();
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const client = await ValkeyAPI.valkeyClientFactory(valkeyServerConnectionOptions);
|
|
28
|
+
|
|
29
|
+
// Attach listeners for visibility
|
|
30
|
+
client.on?.('ready', () => {
|
|
31
|
+
ValkeyStatus[key] = 'connected';
|
|
32
|
+
logger.info('Valkey connected', { instance, status: ValkeyStatus[key] });
|
|
33
|
+
});
|
|
34
|
+
client.on?.('error', (err) => {
|
|
35
|
+
// Switch to dummy if not yet connected
|
|
36
|
+
if (ValkeyStatus[key] !== 'connected') {
|
|
37
|
+
ValkeyStatus[key] = 'dummy';
|
|
38
|
+
} else {
|
|
39
|
+
ValkeyStatus[key] = 'error';
|
|
40
|
+
}
|
|
41
|
+
logger.warn('Valkey error', { err: err?.message, instance, status: ValkeyStatus[key] });
|
|
42
|
+
});
|
|
43
|
+
client.on?.('end', () => {
|
|
44
|
+
if (ValkeyStatus[key] !== 'dummy') ValkeyStatus[key] = 'error';
|
|
45
|
+
logger.warn('Valkey connection ended', { instance, status: ValkeyStatus[key] });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Probe connectivity with a short timeout
|
|
49
|
+
const probe = async () => {
|
|
50
|
+
try {
|
|
51
|
+
// basic ping via SET/GET roundtrip
|
|
52
|
+
const probeKey = `__vk_probe_${Date.now()}`;
|
|
53
|
+
await client.set(probeKey, '1');
|
|
54
|
+
await client.get(probeKey);
|
|
55
|
+
ValkeyStatus[key] = 'connected';
|
|
56
|
+
} catch (e) {
|
|
57
|
+
ValkeyStatus[key] = 'dummy';
|
|
58
|
+
logger.warn('Valkey probe failed, falling back to dummy', { instance, error: e?.message });
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Race with timeout to avoid hanging
|
|
63
|
+
await Promise.race([probe(), new Promise((resolve) => setTimeout(resolve, 1000))]);
|
|
64
|
+
|
|
65
|
+
ValkeyInstances[key] = client;
|
|
66
|
+
if (!ValkeyStatus[key]) ValkeyStatus[key] = 'dummy';
|
|
67
|
+
} catch (err) {
|
|
68
|
+
ValkeyStatus[key] = 'dummy';
|
|
69
|
+
logger.warn('Valkey client creation failed, using dummy', { instance, error: err?.message });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return ValkeyInstances[key];
|
|
24
73
|
};
|
|
25
74
|
|
|
26
75
|
const selectDtoFactory = (payload, select) => {
|
|
@@ -33,18 +82,12 @@ const selectDtoFactory = (payload, select) => {
|
|
|
33
82
|
|
|
34
83
|
const valkeyClientFactory = async (options) => {
|
|
35
84
|
const valkey = new Valkey({
|
|
36
|
-
// port: 6379,
|
|
37
|
-
// host: 'valkey-service.default.svc.cluster.local',
|
|
38
85
|
port: options?.port ? options.port : undefined,
|
|
39
86
|
host: options?.host ? options.host : undefined,
|
|
87
|
+
// Keep retry strategy minimal; state handled in createValkeyConnection
|
|
40
88
|
retryStrategy: (attempt) => {
|
|
41
|
-
if (attempt === 1)
|
|
42
|
-
|
|
43
|
-
valkeyEnabled = false;
|
|
44
|
-
logger.warn('Valkey service not enabled', { ...options, valkeyEnabled });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
return 1000; // 1 second interval attempt
|
|
89
|
+
if (attempt === 1) return undefined; // stop aggressive retries early
|
|
90
|
+
return 1000; // retry interval if library continues
|
|
48
91
|
},
|
|
49
92
|
}); // Connect to 127.0.0.1:6379
|
|
50
93
|
// new Valkey(6380); // 127.0.0.1:6380
|
|
@@ -60,34 +103,52 @@ const valkeyClientFactory = async (options) => {
|
|
|
60
103
|
return valkey;
|
|
61
104
|
};
|
|
62
105
|
|
|
63
|
-
const getValkeyObject = async (options = { host: '',
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const object = await ValkeyInstances[`${options.host}${options.path}`].get(key);
|
|
106
|
+
const getValkeyObject = async (options = { host: '', path: '' }, key = '') => {
|
|
107
|
+
const k = _instanceKey(options);
|
|
108
|
+
const status = ValkeyStatus[k];
|
|
69
109
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
110
|
+
if (status === 'connected' && ValkeyInstances[k]) {
|
|
111
|
+
const value = await ValkeyInstances[k].get(key);
|
|
112
|
+
if (value == null) return null;
|
|
113
|
+
try {
|
|
114
|
+
return JSON.parse(value);
|
|
115
|
+
} catch {
|
|
116
|
+
// not JSON, return raw string
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (err) {
|
|
121
|
+
logger.warn('Valkey get failed, using dummy', { key, err: err?.message });
|
|
74
122
|
}
|
|
123
|
+
// Dummy fallback returns stored value as-is (string or object)
|
|
124
|
+
return DummyStores[k]?.get(key) ?? null;
|
|
75
125
|
};
|
|
76
126
|
|
|
77
|
-
const setValkeyObject = async (options = { host: '',
|
|
78
|
-
|
|
79
|
-
|
|
127
|
+
const setValkeyObject = async (options = { host: '', path: '' }, key = '', payload = {}) => {
|
|
128
|
+
const k = _instanceKey(options);
|
|
129
|
+
const isString = typeof payload === 'string';
|
|
130
|
+
const value = isString ? payload : JSON.stringify(payload);
|
|
131
|
+
try {
|
|
132
|
+
if (ValkeyStatus[k] === 'connected' && ValkeyInstances[k]) {
|
|
133
|
+
return await ValkeyInstances[k].set(key, value);
|
|
134
|
+
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
logger.warn('Valkey set failed, writing to dummy', { key, err: err?.message });
|
|
137
|
+
}
|
|
138
|
+
if (!DummyStores[k]) DummyStores[k] = new Map();
|
|
139
|
+
// Store raw string or object accordingly
|
|
140
|
+
DummyStores[k].set(key, isString ? payload : payload);
|
|
141
|
+
return 'OK';
|
|
80
142
|
};
|
|
81
143
|
|
|
82
|
-
const updateValkeyObject = async (options = { host: '',
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return await
|
|
144
|
+
const updateValkeyObject = async (options = { host: '', path: '' }, key = '', payload = {}) => {
|
|
145
|
+
let base = await getValkeyObject(options, key);
|
|
146
|
+
if (typeof base !== 'object' || base === null) base = {};
|
|
147
|
+
base.updatedAt = new Date().toISOString();
|
|
148
|
+
return await setValkeyObject(options, key, { ...base, ...payload });
|
|
87
149
|
};
|
|
88
150
|
|
|
89
|
-
const valkeyObjectFactory = async (options = { host: 'localhost', object: {} },
|
|
90
|
-
if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
|
|
151
|
+
const valkeyObjectFactory = async (options = { host: 'localhost', object: {} }, model = '') => {
|
|
91
152
|
const idoDate = new Date().toISOString();
|
|
92
153
|
options.object = options.object || {};
|
|
93
154
|
const { object } = options;
|
|
@@ -95,7 +156,7 @@ const valkeyObjectFactory = async (options = { host: 'localhost', object: {} },
|
|
|
95
156
|
object._id = _id;
|
|
96
157
|
object.createdAt = idoDate;
|
|
97
158
|
object.updatedAt = idoDate;
|
|
98
|
-
switch (
|
|
159
|
+
switch (model) {
|
|
99
160
|
case 'user': {
|
|
100
161
|
const role = 'guest';
|
|
101
162
|
object._id = `${role}${_id}`;
|
|
@@ -115,7 +176,7 @@ const valkeyObjectFactory = async (options = { host: 'localhost', object: {} },
|
|
|
115
176
|
};
|
|
116
177
|
}
|
|
117
178
|
default:
|
|
118
|
-
throw new Error(`
|
|
179
|
+
throw new Error(`model schema not found: ${model}`);
|
|
119
180
|
}
|
|
120
181
|
};
|
|
121
182
|
|