miqro 7.1.0 → 7.2.1

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 (222) hide show
  1. package/README.md +92 -24
  2. package/build/editor.bundle.js +3 -3
  3. package/build/esm/editor/auth.js +3 -1
  4. package/build/esm/editor/auth.js.map +1 -0
  5. package/build/esm/editor/common/admin-interface.js +1 -0
  6. package/build/esm/editor/common/admin-interface.js.map +1 -0
  7. package/build/esm/editor/common/constants.js +1 -0
  8. package/build/esm/editor/common/constants.js.map +1 -0
  9. package/build/esm/editor/common/constants.server.js +1 -0
  10. package/build/esm/editor/common/constants.server.js.map +1 -0
  11. package/build/esm/editor/common/editor-index.js +1 -0
  12. package/build/esm/editor/common/editor-index.js.map +1 -0
  13. package/build/esm/editor/common/html-encode.js +1 -0
  14. package/build/esm/editor/common/html-encode.js.map +1 -0
  15. package/build/esm/editor/common/log-socket.js +1 -0
  16. package/build/esm/editor/common/log-socket.js.map +1 -0
  17. package/build/esm/editor/common/templates.js +1 -0
  18. package/build/esm/editor/common/templates.js.map +1 -0
  19. package/build/esm/editor/components/api-preview.js +1 -0
  20. package/build/esm/editor/components/api-preview.js.map +1 -0
  21. package/build/esm/editor/components/editor.js +1 -0
  22. package/build/esm/editor/components/editor.js.map +1 -0
  23. package/build/esm/editor/components/file-browser.js +1 -0
  24. package/build/esm/editor/components/file-browser.js.map +1 -0
  25. package/build/esm/editor/components/file-editor-toolbar.js +1 -0
  26. package/build/esm/editor/components/file-editor-toolbar.js.map +1 -0
  27. package/build/esm/editor/components/file-editor.js +1 -0
  28. package/build/esm/editor/components/file-editor.js.map +1 -0
  29. package/build/esm/editor/components/filter-query.js +1 -0
  30. package/build/esm/editor/components/filter-query.js.map +1 -0
  31. package/build/esm/editor/components/highlight-text-area.js +1 -0
  32. package/build/esm/editor/components/highlight-text-area.js.map +1 -0
  33. package/build/esm/editor/components/log-viewer.js +1 -0
  34. package/build/esm/editor/components/log-viewer.js.map +1 -0
  35. package/build/esm/editor/components/new-file.js +1 -0
  36. package/build/esm/editor/components/new-file.js.map +1 -0
  37. package/build/esm/editor/components/scroll-query.js +1 -0
  38. package/build/esm/editor/components/scroll-query.js.map +1 -0
  39. package/build/esm/editor/components/start-page.js +1 -0
  40. package/build/esm/editor/components/start-page.js.map +1 -0
  41. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +1 -0
  42. package/build/esm/editor/http/admin/editor/api/fs/delete.api.js.map +1 -0
  43. package/build/esm/editor/http/admin/editor/api/fs/read.api.js +3 -2
  44. package/build/esm/editor/http/admin/editor/api/fs/read.api.js.map +1 -0
  45. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +1 -0
  46. package/build/esm/editor/http/admin/editor/api/fs/rename.api.js.map +1 -0
  47. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +1 -0
  48. package/build/esm/editor/http/admin/editor/api/fs/scan.api.js.map +1 -0
  49. package/build/esm/editor/http/admin/editor/api/fs/write.api.js +1 -0
  50. package/build/esm/editor/http/admin/editor/api/fs/write.api.js.map +1 -0
  51. package/build/esm/editor/http/admin/editor/api/server/reload.api.js +1 -0
  52. package/build/esm/editor/http/admin/editor/api/server/reload.api.js.map +1 -0
  53. package/build/esm/editor/http/admin/editor/api/server/restart.api.js +1 -0
  54. package/build/esm/editor/http/admin/editor/api/server/restart.api.js.map +1 -0
  55. package/build/esm/editor/http/admin/editor/editor.js +1 -0
  56. package/build/esm/editor/http/admin/editor/editor.js.map +1 -0
  57. package/build/esm/editor/http/admin/editor/index.api.js +1 -0
  58. package/build/esm/editor/http/admin/editor/index.api.js.map +1 -0
  59. package/build/esm/editor/server.js +1 -0
  60. package/build/esm/editor/server.js.map +1 -0
  61. package/build/esm/editor/ws.js +2 -1
  62. package/build/esm/editor/ws.js.map +1 -0
  63. package/build/esm/src/bin/compile.js +1 -0
  64. package/build/esm/src/bin/compile.js.map +1 -0
  65. package/build/esm/src/bin/doc-md.js +1 -0
  66. package/build/esm/src/bin/doc-md.js.map +1 -0
  67. package/build/esm/src/bin/generate-doc.js +1 -0
  68. package/build/esm/src/bin/generate-doc.js.map +1 -0
  69. package/build/esm/src/bin/test.d.ts +2 -1
  70. package/build/esm/src/bin/test.js +3 -2
  71. package/build/esm/src/bin/test.js.map +1 -0
  72. package/build/esm/src/bin/types.js +1 -0
  73. package/build/esm/src/bin/types.js.map +1 -0
  74. package/build/esm/src/cluster.js +1 -0
  75. package/build/esm/src/cluster.js.map +1 -0
  76. package/build/esm/src/common/arguments.d.ts +8 -0
  77. package/build/esm/src/common/arguments.js +78 -1
  78. package/build/esm/src/common/arguments.js.map +1 -0
  79. package/build/esm/src/common/assets.d.ts +1 -1
  80. package/build/esm/src/common/assets.js +2 -1
  81. package/build/esm/src/common/assets.js.map +1 -0
  82. package/build/esm/src/common/checksum.js +1 -0
  83. package/build/esm/src/common/checksum.js.map +1 -0
  84. package/build/esm/src/common/constants.d.ts +1 -0
  85. package/build/esm/src/common/constants.js +2 -0
  86. package/build/esm/src/common/constants.js.map +1 -0
  87. package/build/esm/src/common/content-type.js +1 -0
  88. package/build/esm/src/common/content-type.js.map +1 -0
  89. package/build/esm/src/common/esbuild.js +2 -1
  90. package/build/esm/src/common/esbuild.js.map +1 -0
  91. package/build/esm/src/common/exit.js +1 -0
  92. package/build/esm/src/common/exit.js.map +1 -0
  93. package/build/esm/src/common/fs.js +1 -0
  94. package/build/esm/src/common/fs.js.map +1 -0
  95. package/build/esm/src/common/help.d.ts +1 -1
  96. package/build/esm/src/common/help.js +7 -1
  97. package/build/esm/src/common/help.js.map +1 -0
  98. package/build/esm/src/common/jsx.d.ts +20 -16
  99. package/build/esm/src/common/jsx.js +34 -29
  100. package/build/esm/src/common/jsx.js.map +1 -0
  101. package/build/esm/src/common/jwt.js +1 -0
  102. package/build/esm/src/common/jwt.js.map +1 -0
  103. package/build/esm/src/common/paths.js +1 -0
  104. package/build/esm/src/common/paths.js.map +1 -0
  105. package/build/esm/src/common/watch.js +1 -0
  106. package/build/esm/src/common/watch.js.map +1 -0
  107. package/build/esm/src/inflate/inflate-sea.js +1 -0
  108. package/build/esm/src/inflate/inflate-sea.js.map +1 -0
  109. package/build/esm/src/inflate/inflate.d.ts +5 -1
  110. package/build/esm/src/inflate/inflate.js +6 -5
  111. package/build/esm/src/inflate/inflate.js.map +1 -0
  112. package/build/esm/src/inflate/md.js +1 -0
  113. package/build/esm/src/inflate/md.js.map +1 -0
  114. package/build/esm/src/inflate/setup-auth.d.ts +2 -2
  115. package/build/esm/src/inflate/setup-auth.js +3 -2
  116. package/build/esm/src/inflate/setup-auth.js.map +1 -0
  117. package/build/esm/src/inflate/setup-cors.d.ts +2 -2
  118. package/build/esm/src/inflate/setup-cors.js +3 -2
  119. package/build/esm/src/inflate/setup-cors.js.map +1 -0
  120. package/build/esm/src/inflate/setup-db.d.ts +3 -3
  121. package/build/esm/src/inflate/setup-db.js +6 -5
  122. package/build/esm/src/inflate/setup-db.js.map +1 -0
  123. package/build/esm/src/inflate/setup-error.d.ts +2 -2
  124. package/build/esm/src/inflate/setup-error.js +3 -2
  125. package/build/esm/src/inflate/setup-error.js.map +1 -0
  126. package/build/esm/src/inflate/setup-http.d.ts +7 -2
  127. package/build/esm/src/inflate/setup-http.js +54 -45
  128. package/build/esm/src/inflate/setup-http.js.map +1 -0
  129. package/build/esm/src/inflate/setup-log.d.ts +2 -2
  130. package/build/esm/src/inflate/setup-log.js +3 -2
  131. package/build/esm/src/inflate/setup-log.js.map +1 -0
  132. package/build/esm/src/inflate/setup-middleware.d.ts +2 -2
  133. package/build/esm/src/inflate/setup-middleware.js +3 -2
  134. package/build/esm/src/inflate/setup-middleware.js.map +1 -0
  135. package/build/esm/src/inflate/setup-server-config.d.ts +2 -2
  136. package/build/esm/src/inflate/setup-server-config.js +3 -2
  137. package/build/esm/src/inflate/setup-server-config.js.map +1 -0
  138. package/build/esm/src/inflate/setup-test.d.ts +2 -1
  139. package/build/esm/src/inflate/setup-test.js +3 -2
  140. package/build/esm/src/inflate/setup-test.js.map +1 -0
  141. package/build/esm/src/inflate/setup-ws.d.ts +2 -2
  142. package/build/esm/src/inflate/setup-ws.js +3 -2
  143. package/build/esm/src/inflate/setup-ws.js.map +1 -0
  144. package/build/esm/src/inflate/setup.doc.d.ts +2 -2
  145. package/build/esm/src/inflate/setup.doc.js +5 -4
  146. package/build/esm/src/inflate/setup.doc.js.map +1 -0
  147. package/build/esm/src/inflate/utils/sea-utils.js +1 -0
  148. package/build/esm/src/inflate/utils/sea-utils.js.map +1 -0
  149. package/build/esm/src/lib.js +1 -0
  150. package/build/esm/src/lib.js.map +1 -0
  151. package/build/esm/src/main.js +9 -2
  152. package/build/esm/src/main.js.map +1 -0
  153. package/build/esm/src/services/app.d.ts +5 -2
  154. package/build/esm/src/services/app.js +22 -9
  155. package/build/esm/src/services/app.js.map +1 -0
  156. package/build/esm/src/services/editor.js +1 -0
  157. package/build/esm/src/services/editor.js.map +1 -0
  158. package/build/esm/src/services/hot-reload.d.ts +1 -0
  159. package/build/esm/src/services/hot-reload.js +9 -5
  160. package/build/esm/src/services/hot-reload.js.map +1 -0
  161. package/build/esm/src/services/migrations.d.ts +3 -2
  162. package/build/esm/src/services/migrations.js +5 -4
  163. package/build/esm/src/services/migrations.js.map +1 -0
  164. package/build/esm/src/services/utils/admin-interface.js +1 -0
  165. package/build/esm/src/services/utils/admin-interface.js.map +1 -0
  166. package/build/esm/src/services/utils/cache.js +1 -0
  167. package/build/esm/src/services/utils/cache.js.map +1 -0
  168. package/build/esm/src/services/utils/cluster-cache.js +91 -64
  169. package/build/esm/src/services/utils/cluster-cache.js.map +1 -0
  170. package/build/esm/src/services/utils/cluster-ws.js +1 -0
  171. package/build/esm/src/services/utils/cluster-ws.js.map +1 -0
  172. package/build/esm/src/services/utils/db-manager.js +1 -0
  173. package/build/esm/src/services/utils/db-manager.js.map +1 -0
  174. package/build/esm/src/services/utils/get-route.js +1 -0
  175. package/build/esm/src/services/utils/get-route.js.map +1 -0
  176. package/build/esm/src/services/utils/jwt.js +1 -0
  177. package/build/esm/src/services/utils/jwt.js.map +1 -0
  178. package/build/esm/src/services/utils/log-transport.js +1 -0
  179. package/build/esm/src/services/utils/log-transport.js.map +1 -0
  180. package/build/esm/src/services/utils/log.js +1 -0
  181. package/build/esm/src/services/utils/log.js.map +1 -0
  182. package/build/esm/src/services/utils/middleware.js +1 -0
  183. package/build/esm/src/services/utils/middleware.js.map +1 -0
  184. package/build/esm/src/services/utils/server-interface.js +1 -0
  185. package/build/esm/src/services/utils/server-interface.js.map +1 -0
  186. package/build/esm/src/services/utils/websocketmanager.js +3 -1
  187. package/build/esm/src/services/utils/websocketmanager.js.map +1 -0
  188. package/build/esm/src/types.js +1 -0
  189. package/build/esm/src/types.js.map +1 -0
  190. package/build/lib.cjs +1178 -1153
  191. package/editor/auth.ts +2 -1
  192. package/editor/http/admin/editor/api/fs/read.api.tsx +2 -2
  193. package/editor/ws.ts +1 -1
  194. package/package.json +10 -10
  195. package/sea/install-esbuild.sh +1 -1
  196. package/sea/install-nodejs.sh +1 -1
  197. package/sea/node.version.tag +1 -1
  198. package/src/bin/test.ts +3 -2
  199. package/src/common/arguments.ts +92 -1
  200. package/src/common/assets.ts +2 -2
  201. package/src/common/constants.ts +1 -0
  202. package/src/common/esbuild.ts +1 -1
  203. package/src/common/help.ts +6 -1
  204. package/src/common/jsx.ts +41 -30
  205. package/src/inflate/inflate.ts +9 -5
  206. package/src/inflate/setup-auth.ts +3 -3
  207. package/src/inflate/setup-cors.ts +4 -3
  208. package/src/inflate/setup-db.ts +6 -6
  209. package/src/inflate/setup-error.ts +3 -3
  210. package/src/inflate/setup-http.ts +61 -45
  211. package/src/inflate/setup-log.ts +3 -3
  212. package/src/inflate/setup-middleware.ts +3 -3
  213. package/src/inflate/setup-server-config.ts +3 -3
  214. package/src/inflate/setup-test.ts +3 -3
  215. package/src/inflate/setup-ws.ts +3 -3
  216. package/src/inflate/setup.doc.ts +5 -5
  217. package/src/main.ts +8 -2
  218. package/src/services/app.ts +27 -12
  219. package/src/services/hot-reload.ts +9 -5
  220. package/src/services/migrations.ts +5 -5
  221. package/src/services/utils/cluster-cache.ts +90 -65
  222. package/src/services/utils/websocketmanager.ts +2 -1
@@ -4,8 +4,8 @@ import { migration } from "@miqro/query";
4
4
  import { WebSocketManager } from "./utils/websocketmanager.js";
5
5
  import { DBManager } from "./utils/db-manager.js";
6
6
  import { inflateApp } from "../inflate/inflate.js";
7
- import { InflateError } from "../common/jsx.js";
8
- import { DBConfig, MigrateOptions, ServerInterface, ServerRequest, WSConfig } from "../types.js";
7
+ import { ImportJSXFileOptions, InflateError } from "../common/jsx.js";
8
+ import { DBConfig, MigrateOptions, ServerInterface, ServerRequest, ServerResponse, WSConfig } from "../types.js";
9
9
  import { RouteFileMap } from "../inflate/setup-http.js";
10
10
  import { ServerConfigMap, setupServerConfig } from "../inflate/setup-server-config.js";
11
11
  import { BASEEDITOR_PATH, LOG_SOCKET_PATH, LOG_WRITE_EVENT } from "../../editor/common/constants.js";
@@ -14,7 +14,7 @@ import editorServerConfig from "../../editor/server.js";
14
14
 
15
15
  import { ClusterCache } from "./utils/cluster-cache.js";
16
16
  import { createEditorRouter } from "./editor.js";
17
- import { EDITOR_CONFIG_KEY, HOT_RELOAD_PATH } from "../common/constants.js";
17
+ import { EDITOR_CONFIG_KEY, HOT_RELOAD_PATH, HOT_RELOAD_SCRIPT_PATH } from "../common/constants.js";
18
18
  import { watchAndServer } from "../common/watch.js";
19
19
  import { LocalCache } from "./utils/cache.js";
20
20
  // import { initGlobals } from "./globals.js";
@@ -32,8 +32,9 @@ import { createAdminInterface } from "./utils/admin-interface.js";
32
32
  import { dirname, join, relative, resolve } from "node:path";
33
33
  import { cwd } from "node:process";
34
34
  import { ServerOptions } from "node:https";
35
+ import { HOT_RELOAD_JS_SCRIPT } from "./hot-reload.js";
35
36
 
36
- export interface MiqroOptions {
37
+ export interface MiqroOptions extends ImportJSXFileOptions {
37
38
  name: string;
38
39
  logger?: Logger;
39
40
  logProviderOptions?: LogProviderOptions;
@@ -47,12 +48,15 @@ export interface MiqroOptions {
47
48
  serverOptions?: ServerOptions<any, any>;
48
49
  https?: boolean;
49
50
  httpRedirect?: number;
51
+ noMinify?: boolean;
50
52
  }
51
53
 
52
54
  export interface InflateOptions {
53
55
  inflateDir?: string;
54
56
  inflateSea?: boolean;
57
+ inflateOnlyAssets?: boolean;
55
58
  inflateParallel?: number;
59
+ inflateFlat?: boolean;
56
60
  }
57
61
 
58
62
  export interface InflatedResult {
@@ -101,8 +105,10 @@ export class Miqro {
101
105
 
102
106
  constructor(options?: Partial<MiqroOptions>) {
103
107
  this.options = {
108
+ noMinify: false,
104
109
  editor: false,
105
110
  name: "server",
111
+ noBuild: false,
106
112
  port: getPORT(),
107
113
  services: [],
108
114
  ...(options ? options : {})
@@ -127,8 +133,8 @@ export class Miqro {
127
133
  msg &&
128
134
  msg.action &&
129
135
  msg.type === MiqroApplicationMessageType &&
130
- msg.target === this.options.name,
131
- msg.fromPID !== process.pid,
136
+ msg.target === this.options.name &&
137
+ msg.fromPID !== process.pid &&
132
138
  (msg.action === "reload" || msg.action === "restart")) {
133
139
  this.logger?.debug("remote server message from [%s] [%s]", msg.fromPID, msg.action);
134
140
  switch (msg.action) {
@@ -139,7 +145,7 @@ export class Miqro {
139
145
  await this.restart(true);
140
146
  break;
141
147
  default:
142
- throw new Error("unsopported message for ApplicaitonServer");
148
+ throw new Error("unsupported message for ApplicationServer");
143
149
  }
144
150
  }
145
151
  } catch (e) {
@@ -187,6 +193,7 @@ export class Miqro {
187
193
  name: miqroJSON.name ? miqroJSON.name : undefined,
188
194
  port: miqroJSON.port ? String(miqroJSON.port) : undefined,
189
195
  services: miqroJSON.services ? miqroJSON.services.map(s => join(relative(cwd(), miqroJSONDir), s)) : undefined,
196
+ noBuild: miqroJSON.noBuild !== undefined ? miqroJSON.noBuild : false,
190
197
  ...(options ? options : {}),
191
198
  });
192
199
  await app.inflate({
@@ -244,7 +251,7 @@ export class Miqro {
244
251
  const errors: InflateError[] = [];
245
252
  for (const service of this.options.services) {
246
253
  const servicePath = getServicePath(service);
247
- await setupServerConfig(this.logger, servicePath, service, serverConfigMap, options && options.inflateSea ? options.inflateDir : undefined, errors);
254
+ await setupServerConfig(this.logger, servicePath, service, serverConfigMap, options && options.inflateSea ? options.inflateDir : undefined, errors, this.options);
248
255
  }
249
256
  return {
250
257
  serverConfigMap,
@@ -267,9 +274,9 @@ export class Miqro {
267
274
  }[] = [];
268
275
  const dbConfigListALL: DBConfig[] = [];
269
276
  for (const service of this.options.services) {
270
- const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : undefined, errors);
277
+ const dbConfig = await inflateDBConfig(this.logger, service, dbConfigListALL, options?.inflateSea ? options?.inflateDir : undefined, this.options, errors);
271
278
  if (dbConfig) {
272
- const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : undefined, errors);
279
+ const migrations = await inflateDBMigrations(this.logger, service, dbConfig.name, options?.inflateSea ? options?.inflateDir : undefined, this.options, errors);
273
280
  dbList.push({
274
281
  service,
275
282
  dbConfig,
@@ -330,7 +337,7 @@ export class Miqro {
330
337
  // block others from inflating while inflateApp is running
331
338
  this.inflated = undefined;
332
339
  // init assets only once for all ApplicationServer's
333
- if (Miqro.initAssetsPromise === null) {
340
+ if (Miqro.initAssetsPromise === null && (this.options.noBuild === false || this.options.noMinify === false)) {
334
341
  // init globals only once for all inflations
335
342
  // initGlobals();
336
343
  Miqro.initAssetsPromise = initAssets(this.logger);
@@ -363,6 +370,10 @@ export class Miqro {
363
370
  wsConfigList.push({
364
371
  path: HOT_RELOAD_PATH
365
372
  });
373
+ this.logger?.debug("setting up hot-reload script on [%s]", HOT_RELOAD_SCRIPT_PATH);
374
+ const hotReloadScriptRouter = new Router();
375
+ hotReloadScriptRouter.get(HOT_RELOAD_SCRIPT_PATH, async (req, res) => res.js(HOT_RELOAD_JS_SCRIPT));
376
+ router.use(hotReloadScriptRouter);
366
377
  }
367
378
 
368
379
  await notifiyServerConfig(this.logger, this.serverInterface, this.adminInterface, serverConfigMap, "preload");
@@ -378,7 +389,11 @@ export class Miqro {
378
389
  inflateSea: options?.inflateSea ? true : false,
379
390
  //inflateTests: options?.inflateTests ? true : false,
380
391
  hotreload: this.options?.hotreload ? true : false,
381
- inflateParallel: options?.inflateParallel
392
+ inflateParallel: options?.inflateParallel,
393
+ noBuild: this.options?.noBuild,
394
+ noMinify: this.options?.noMinify,
395
+ inflateOnlyAssets: options?.inflateOnlyAssets,
396
+ inflateFlat: options?.inflateFlat
382
397
  });
383
398
 
384
399
  wsConfigList.push(...serviceWSConfigList);
@@ -1,9 +1,8 @@
1
1
  //import { checkEnvVariable } from "@miqro/core";
2
2
 
3
- import { HOT_RELOAD_PATH } from "../common/constants.js";
3
+ import { HOT_RELOAD_PATH, HOT_RELOAD_SCRIPT_PATH } from "../common/constants.js";
4
4
 
5
- export function getHotReloadScript() {
6
- const HOT_RELOAD_JS_SCRIPT = `
5
+ export const HOT_RELOAD_JS_SCRIPT = `
7
6
  // Create WebSocket connection.
8
7
 
9
8
  function getSocket() {
@@ -13,13 +12,14 @@ function getSocket() {
13
12
  const socket = getSocket();
14
13
 
15
14
  let timeout;
15
+ let reloadtimeout;
16
16
 
17
17
  function tryConnection() {
18
18
  try {
19
19
  const newSocket = getSocket();
20
20
  newSocket.addEventListener("open", (event) => {
21
21
  console.log("reloading");
22
- setTimeout(()=>{
22
+ reloadtimeout = setTimeout(()=>{
23
23
  window.location.reload();
24
24
  }, 500);
25
25
 
@@ -37,13 +37,17 @@ function tryConnection() {
37
37
  // Connection closed
38
38
  socket.addEventListener("close", (event) => {
39
39
  clearTimeout(timeout);
40
+ clearTimeout(reloadtimeout);
40
41
  timeout = setTimeout(tryConnection, 500);
41
42
  });
42
43
 
43
44
  socket.addEventListener("error", (err) => {
45
+ clearTimeout(reloadtimeout);
44
46
  console.error(err);
45
47
  });`;
46
- return `<script>${HOT_RELOAD_JS_SCRIPT}</script>`;
48
+
49
+ export function getHotReloadScript() {
50
+ return `<script src="${HOT_RELOAD_SCRIPT_PATH}"></script>`;
47
51
  }
48
52
 
49
53
  /*export function isHotReloadEnabled() {
@@ -5,16 +5,16 @@ import { mkdirSync, writeFileSync } from "node:fs";
5
5
  import { cwd } from "node:process";
6
6
 
7
7
  import { getMigrationsPath } from "../common/paths.js";
8
- import { importJSXFile, inflateJSX } from "../common/jsx.js";
8
+ import { importJSXFile, ImportJSXFileOptions, inflateJSX } from "../common/jsx.js";
9
9
 
10
- export async function runMigrations(logger: Logger | undefined, db: Database | null, servicePath: string, service: string, inflateDir: string | undefined | false, migrations: string[]) {
10
+ export async function runMigrations(logger: Logger | undefined, db: Database | null, servicePath: string, service: string, inflateDir: string | undefined | false, migrations: string[], options: ImportJSXFileOptions) {
11
11
  const migrationsFolderPath = getMigrationsPath(servicePath);
12
12
  if (migrationsFolderPath) {
13
13
  logger?.debug("running migrations from [%s]", service);
14
14
  if (!db) {
15
15
  throw new Error("cannot run migrations with the database disabled!");
16
16
  }
17
- const serviceMigrations = await migration.up.folder(db as any, migrationsFolderPath, logger as DatabaseLogger, (inFile: string) => importJSXFile(inFile, logger));
17
+ const serviceMigrations = await migration.up.folder(db as any, migrationsFolderPath, logger as DatabaseLogger, (inFile: string) => importJSXFile(inFile, options, logger));
18
18
  migrations.push(...serviceMigrations);
19
19
 
20
20
  if (inflateDir) {
@@ -37,14 +37,14 @@ export async function runMigrations(logger: Logger | undefined, db: Database | n
37
37
  return migrations;
38
38
  }
39
39
 
40
- export async function runMigrationsDown(logger: Logger | Console | undefined, db: Database | null, servicePath: string, service: string, inflateDir: string | undefined, migrations: string[]) {
40
+ export async function runMigrationsDown(logger: Logger | Console | undefined, db: Database | null, servicePath: string, service: string, inflateDir: string | undefined, migrations: string[], options: ImportJSXFileOptions) {
41
41
  const migrationsFolderPath = getMigrationsPath(servicePath)
42
42
  if (migrationsFolderPath) {
43
43
  logger?.debug("running migrations from [%s]", service);
44
44
  if (!db) {
45
45
  throw new Error("cannot run migrations with the database disabled!");
46
46
  }
47
- const serviceMigrations = await migration.down.folder(db as any, migrationsFolderPath, logger as DatabaseLogger, (inFile: string) => importJSXFile(inFile, logger));
47
+ const serviceMigrations = await migration.down.folder(db as any, migrationsFolderPath, logger as DatabaseLogger, (inFile: string) => importJSXFile(inFile, options, logger));
48
48
  migrations.push(...serviceMigrations);
49
49
 
50
50
  if (inflateDir) {
@@ -6,7 +6,7 @@ const ClusterCacheType = "$$$$$$$$$$$ClusterCacheType$$$$$$$$$$$";
6
6
  interface ClusterCacheMessage {
7
7
  type: typeof ClusterCacheType;
8
8
  target: string;
9
- action: "set" | "unset" | "set_add" | "set_delete" | "array_push";
9
+ action: "set" | "unset" | "set_add" | "set_delete" | "array_push" | "set_clear" | "array_clear";
10
10
  fromPID: number;
11
11
  key: string;
12
12
  value?: string;
@@ -28,11 +28,29 @@ export class ClusterCache implements CacheInterface {
28
28
  msg.key &&
29
29
  msg.action &&
30
30
  msg.type === ClusterCacheType &&
31
- msg.fromPID !== process.pid,
32
- (msg.action === "set_add" || msg.action === "set" || msg.action === "unset" || msg.action === "set_delete" || msg.action === "array_push") &&
31
+ msg.fromPID !== process.pid &&
32
+ (msg.action === "set_clear" || msg.action === "array_clear" || msg.action === "set_add" || msg.action === "set" || msg.action === "unset" || msg.action === "set_delete" || msg.action === "array_push") &&
33
33
  msg.target === this.name) {
34
34
  this.logger?.debug("remote cluster cache message from [%s] [%s] [%s] [%s]", msg.fromPID, msg.target, msg.action, msg.key);
35
35
  switch (msg.action) {
36
+ case "set_clear": {
37
+ const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : new Set<string>();
38
+ if (!(list instanceof Set)) {
39
+ throw new Error("cannot apply clear on non set");
40
+ }
41
+ list.clear();
42
+ this.localCache.set(msg.key, list);
43
+ break;
44
+ }
45
+ case "array_clear": {
46
+ //this.localCache.set(msg.key, msg.value);
47
+ const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : [];
48
+ if (!(list instanceof Array)) {
49
+ throw new Error("cannot apply clear on non array");
50
+ }
51
+ this.localCache.set(msg.key, []);
52
+ break;
53
+ }
36
54
  case "unset":
37
55
  this.localCache.delete(msg.key);
38
56
  break;
@@ -43,7 +61,7 @@ export class ClusterCache implements CacheInterface {
43
61
  //this.localCache.set(msg.key, msg.value);
44
62
  const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : new Set<string>();
45
63
  if (!(list instanceof Set)) {
46
- throw new Error("cannot apply push on non array");
64
+ throw new Error("cannot apply add on non set");
47
65
  }
48
66
  if (!list.has(msg.value)) {
49
67
  list.add(msg.value);
@@ -55,7 +73,7 @@ export class ClusterCache implements CacheInterface {
55
73
  //this.localCache.set(msg.key, msg.value);
56
74
  const list = this.localCache.has(msg.key) ? this.localCache.get(msg.key) : new Set<string>();
57
75
  if (!(list instanceof Set)) {
58
- throw new Error("cannot apply push on non array");
76
+ throw new Error("cannot apply delete on non set");
59
77
  }
60
78
  if (list.has(msg.value)) {
61
79
  list.delete(msg.value);
@@ -100,33 +118,25 @@ export class ClusterCache implements CacheInterface {
100
118
  set(key: string, value: unknown): void {
101
119
  this.localCache.set(key, value);
102
120
  this.logger?.trace("set(%s, ...)", key);
103
- if (process.send) {
104
- setTimeout(() => {
105
- process.send({
106
- type: ClusterCacheType,
107
- action: "set",
108
- target: this.name,
109
- fromPID: process.pid,
110
- key,
111
- value
112
- } as ClusterCacheMessage);
113
- }, 10);
114
- }
121
+ sendTimeout({
122
+ type: ClusterCacheType,
123
+ action: "set",
124
+ target: this.name,
125
+ fromPID: process.pid,
126
+ key,
127
+ value
128
+ } as ClusterCacheMessage);
115
129
  }
116
130
  unset(key: string): void {
117
131
  this.logger?.trace("unset(%s)", key);
118
132
  this.localCache.delete(key);
119
- if (process.send) {
120
- setTimeout(() => {
121
- process.send({
122
- type: ClusterCacheType,
123
- target: this.name,
124
- action: "unset",
125
- fromPID: process.pid,
126
- key
127
- } as ClusterCacheMessage);
128
- }, 10);
129
- }
133
+ sendTimeout({
134
+ type: ClusterCacheType,
135
+ target: this.name,
136
+ action: "unset",
137
+ fromPID: process.pid,
138
+ key
139
+ } as ClusterCacheMessage);
130
140
  }
131
141
  has(key: string): boolean {
132
142
  this.logger?.trace("has(%s)", key);
@@ -143,19 +153,14 @@ export class ClusterCache implements CacheInterface {
143
153
  list.add(value);
144
154
  }
145
155
  this.localCache.set(key, list);
146
-
147
- if (process.send) {
148
- setTimeout(() => {
149
- process.send({
150
- type: ClusterCacheType,
151
- target: this.name,
152
- action: "set_add",
153
- fromPID: process.pid,
154
- key,
155
- value
156
- } as ClusterCacheMessage);
157
- }, 10);
158
- }
156
+ sendTimeout({
157
+ type: ClusterCacheType,
158
+ target: this.name,
159
+ action: "set_add",
160
+ fromPID: process.pid,
161
+ key,
162
+ value
163
+ } as ClusterCacheMessage);
159
164
  }
160
165
  set_delete(key: string, value: unknown): void {
161
166
  this.logger?.trace("delete(%s)", key);
@@ -167,18 +172,14 @@ export class ClusterCache implements CacheInterface {
167
172
  list.delete(value);
168
173
  }
169
174
  this.localCache.set(key, list);
170
- if (process.send) {
171
- setTimeout(() => {
172
- process.send({
173
- type: ClusterCacheType,
174
- target: this.name,
175
- action: "set_delete",
176
- fromPID: process.pid,
177
- key,
178
- value
179
- } as ClusterCacheMessage);
180
- }, 10);
181
- }
175
+ sendTimeout({
176
+ type: ClusterCacheType,
177
+ target: this.name,
178
+ action: "set_delete",
179
+ fromPID: process.pid,
180
+ key,
181
+ value
182
+ } as ClusterCacheMessage);
182
183
  }
183
184
  set_has(key: string, value: unknown): boolean {
184
185
  this.logger?.trace("set_has(%s)", key);
@@ -198,6 +199,13 @@ export class ClusterCache implements CacheInterface {
198
199
  }
199
200
  list.clear();
200
201
  this.localCache.set(key, list);
202
+ sendTimeout({
203
+ type: ClusterCacheType,
204
+ target: this.name,
205
+ action: "set_clear",
206
+ fromPID: process.pid,
207
+ key
208
+ } as ClusterCacheMessage);
201
209
  }
202
210
  array_push(key: string, value: unknown): void {
203
211
  this.logger?.trace("array_push(%s)", key);
@@ -207,18 +215,14 @@ export class ClusterCache implements CacheInterface {
207
215
  }
208
216
  list.push(value);
209
217
  this.localCache.set(key, list);
210
- if (process.send) {
211
- setTimeout(() => {
212
- process.send({
213
- type: ClusterCacheType,
214
- target: this.name,
215
- action: "array_push",
216
- fromPID: process.pid,
217
- key,
218
- value
219
- } as ClusterCacheMessage);
220
- }, 10);
221
- }
218
+ sendTimeout({
219
+ type: ClusterCacheType,
220
+ target: this.name,
221
+ action: "array_push",
222
+ fromPID: process.pid,
223
+ key,
224
+ value
225
+ } as ClusterCacheMessage);
222
226
  }
223
227
  array_clear(key: string): void {
224
228
  this.logger?.trace("array_clear(%s)", key);
@@ -226,5 +230,26 @@ export class ClusterCache implements CacheInterface {
226
230
  throw new Error("cannot apply on non Array");
227
231
  }
228
232
  this.localCache.set(key, []);
233
+ sendTimeout({
234
+ type: ClusterCacheType,
235
+ target: this.name,
236
+ action: "array_clear",
237
+ fromPID: process.pid,
238
+ key
239
+ } as ClusterCacheMessage);
229
240
  }
230
241
  }
242
+
243
+ function sendTimeout(msg: ClusterCacheMessage) {
244
+ if (process.send) {
245
+ setTimeout(() => {
246
+ try {
247
+ if (process.send) {
248
+ process.send(msg);
249
+ }
250
+ } catch (e) {
251
+ console.error(e);
252
+ }
253
+ }, 10);
254
+ }
255
+ }
@@ -28,7 +28,8 @@ export class WebSocketManager {
28
28
  public deleteWS(path: string) {
29
29
  const ws = this.runningGlobalWSMap.get(path);
30
30
  this.disconnectAllFrom(path);
31
- ws.dispose();
31
+ if (ws)
32
+ ws.dispose();
32
33
  this.runningGlobalWSMap.delete(path);
33
34
  }
34
35