underpost 2.8.843 → 2.8.844

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.
@@ -119,10 +119,11 @@ const Panel = {
119
119
  });
120
120
  s(`.a-${payload._id}`).onclick = async (e) => {
121
121
  e.preventDefault();
122
+ if (options.onClick) await options.onClick({ payload });
122
123
  };
123
124
  s(`.container-${idPanel}-${id}`).onclick = async (e) => {
124
125
  e.preventDefault();
125
- if (options.onClick) await options.onClick({ payload });
126
+ // if (options.onClick) await options.onClick({ payload });
126
127
  };
127
128
  });
128
129
  if (s(`.${idPanel}-${id}`)) s(`.${idPanel}-${id}`).remove();
@@ -540,7 +541,6 @@ const Panel = {
540
541
  background: #f6f6f6;
541
542
  color: black;
542
543
  padding: 10px;
543
- cursor: pointer;
544
544
  min-height: 400px;
545
545
  }
546
546
  .${idPanel}:hover {
@@ -425,7 +425,9 @@ const PanelForm = {
425
425
  });
426
426
  let firsUpdateEvent = false;
427
427
  let lastCid;
428
+ console.warn('-------------> updatePanel 1');
428
429
  this.Data[idPanel].updatePanel = async () => {
430
+ console.warn('-------------> updatePanel 2');
429
431
  const cid = getQueryParams().cid ? getQueryParams().cid : '';
430
432
  if (lastCid === cid) return;
431
433
  lastCid = cid;
@@ -62,7 +62,7 @@ const Recover = {
62
62
 
63
63
  setTimeout(async () => {
64
64
  if (user && user.email) {
65
- s(`.recover-email`).value = user.email;
65
+ s(`.recover-email`).value = user.role === 'guest' ? '' : user.email;
66
66
  if (user.emailConfirmed) s(`.recover-email`).setAttribute('disabled', '');
67
67
  }
68
68
 
package/src/index.js CHANGED
@@ -34,7 +34,7 @@ class Underpost {
34
34
  * @type {String}
35
35
  * @memberof Underpost
36
36
  */
37
- static version = 'v2.8.843';
37
+ static version = 'v2.8.844';
38
38
  /**
39
39
  * Repository cli API
40
40
  * @static
@@ -577,9 +577,6 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
577
577
  fs.mkdirSync(coverageBuildPath, { recursive: true });
578
578
  fs.copySync(`./coverage`, coverageBuildPath);
579
579
 
580
- // uml
581
- // shellExec(`node bin/deploy uml ${host} ${path}`);
582
-
583
580
  // https://swagger-autogen.github.io/docs/
584
581
 
585
582
  const basePath = path === '/' ? `${process.env.BASE_API}` : `/${process.env.BASE_API}`;
@@ -667,10 +664,6 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
667
664
  },
668
665
  };
669
666
 
670
- // plantuml
671
- logger.info('copy plantuml', `${rootClientPath}/docs/plantuml`);
672
- fs.copySync(`./src/client/public/default/plantuml`, `${rootClientPath}/docs/plantuml`);
673
-
674
667
  logger.warn('build swagger api docs', doc.info);
675
668
 
676
669
  const outputFile = `./public/${host}${path === '/' ? path : `${path}/`}swagger-output.json`;
@@ -683,19 +676,6 @@ Sitemap: https://${host}${path === '/' ? '' : path}/sitemap.xml`,
683
676
  root file where the route starts, such as index.js, app.js, routes.js, etc ... */
684
677
 
685
678
  await swaggerAutoGen({ openapi: '3.0.0' })(outputFile, routes, doc);
686
-
687
- const htmlFiles = await fs.readdir(`./public/${host}/docs/engine/${Underpost.version.replace('v', '')}`);
688
- for (const htmlFile of htmlFiles) {
689
- if (htmlFile.match('.html')) {
690
- fs.writeFileSync(
691
- `./public/${host}/docs/engine/${Underpost.version.replace('v', '')}/${htmlFile}`,
692
- fs
693
- .readFileSync(`./public/${host}/docs/engine/${Underpost.version.replace('v', '')}/${htmlFile}`, 'utf8')
694
- .replaceAll('Tutorials', 'References'),
695
- 'utf8',
696
- );
697
- }
698
- }
699
679
  }
700
680
 
701
681
  if (client) {
@@ -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