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.
Files changed (35) hide show
  1. package/.github/workflows/{ghpkg.yml → ghpkg.ci.yml} +1 -1
  2. package/.github/workflows/{npmpkg.yml → npmpkg.ci.yml} +1 -1
  3. package/.github/workflows/{publish.yml → publish.ci.yml} +1 -1
  4. package/.github/workflows/{pwa-microservices-template.page.yml → pwa-microservices-template-page.cd.yml} +1 -1
  5. package/.github/workflows/{pwa-microservices-template.test.yml → pwa-microservices-template-test.ci.yml} +1 -1
  6. package/.vscode/settings.json +0 -1
  7. package/README.md +18 -2
  8. package/bin/build.js +8 -5
  9. package/bin/deploy.js +10 -69
  10. package/bin/file.js +15 -11
  11. package/cli.md +47 -43
  12. package/docker-compose.yml +1 -1
  13. package/manifests/deployment/dd-template-development/deployment.yaml +2 -2
  14. package/manifests/maas/gpu-diag.sh +1 -1
  15. package/package.json +3 -5
  16. package/src/api/user/user.router.js +24 -1
  17. package/src/cli/cluster.js +19 -10
  18. package/src/cli/index.js +1 -0
  19. package/src/cli/run.js +21 -0
  20. package/src/client/components/core/Css.js +52 -2
  21. package/src/client/components/core/CssCore.js +0 -4
  22. package/src/client/components/core/Docs.js +10 -57
  23. package/src/client/components/core/DropDown.js +128 -82
  24. package/src/client/components/core/EventsUI.js +92 -5
  25. package/src/client/components/core/Modal.js +451 -120
  26. package/src/client/components/core/NotificationManager.js +2 -2
  27. package/src/client/components/core/Panel.js +2 -2
  28. package/src/client/components/core/PanelForm.js +12 -2
  29. package/src/client/components/core/Recover.js +1 -1
  30. package/src/client/components/core/Router.js +63 -2
  31. package/src/client/components/core/Translate.js +2 -2
  32. package/src/index.js +1 -1
  33. package/src/server/client-build-docs.js +205 -0
  34. package/src/server/client-build.js +11 -140
  35. package/src/server/valkey.js +102 -41
@@ -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
- let valkeyEnabled = true;
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 disableValkeyErrorMessage = 'valkey is not enabled';
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: '', port: 0 },
18
- valkeyServerConnectionOptions = { host: '', port: 0 },
19
+ instance = { host: '', path: '' },
20
+ valkeyServerConnectionOptions = { host: '', path: '' },
19
21
  ) => {
20
- ValkeyInstances[`${instance.host}${instance.path}`] = await ValkeyAPI.valkeyClientFactory(
21
- valkeyServerConnectionOptions,
22
- );
23
- return ValkeyInstances[`${instance.host}${instance.path}`];
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
- valkey.disconnect();
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: '', port: 0 }, key = '') => {
64
- if (!valkeyEnabled) {
65
- logger.warn(disableValkeyErrorMessage + ' get', key);
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
- return JSON.parse(object);
71
- } catch (error) {
72
- logger.error(error);
73
- return object;
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: '', port: 0 }, key = '', payload = {}) => {
78
- if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
79
- return await ValkeyInstances[`${options.host}${options.path}`].set(key, JSON.stringify(payload));
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: '', port: 0 }, key = '', payload = {}) => {
83
- if (!valkeyEnabled) throw new Error(disableValkeyErrorMessage);
84
- const object = await getValkeyObject(key);
85
- object.updatedAt = new Date().toISOString();
86
- return await ValkeyInstances[`${options.host}${options.path}`].set(key, JSON.stringify({ ...object, ...payload }));
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: {} }, module = '') => {
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 (module) {
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(`module schema not found: ${module}`);
179
+ throw new Error(`model schema not found: ${model}`);
119
180
  }
120
181
  };
121
182