phecda-server 7.0.0-alpha.8 → 7.0.0-alpha.9

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 (79) hide show
  1. package/dist/{chunk-VSGYTGHY.js → chunk-5RBTN33A.js} +22 -2
  2. package/dist/{chunk-B45BN7LY.mjs → chunk-7ZGYJ5OW.mjs} +88 -54
  3. package/dist/{chunk-SGMQZRP6.mjs → chunk-CVPZWDXU.mjs} +2 -23
  4. package/dist/{chunk-7EMAZGYO.js → chunk-FX3LDQII.js} +59 -80
  5. package/dist/{chunk-YKP4ODZA.mjs → chunk-FXTJ3BJ6.mjs} +23 -3
  6. package/dist/{chunk-QJIAXSLZ.js → chunk-KJUD2BKE.js} +103 -69
  7. package/dist/{chunk-7NWDKK7D.mjs → chunk-ODVWOXVB.mjs} +1 -1
  8. package/dist/{chunk-BBNJVYVX.js → chunk-V5EYXVJT.js} +24 -24
  9. package/dist/{core-BcKywWLd.d.mts → core-BDkhrEyf.d.mts} +4 -3
  10. package/dist/{core-BGEsBtTG.d.ts → core-D_cz0tKa.d.ts} +4 -3
  11. package/dist/helper.d.mts +6 -5
  12. package/dist/helper.d.ts +6 -5
  13. package/dist/helper.js +6 -3
  14. package/dist/helper.mjs +8 -5
  15. package/dist/http/elysia/index.d.mts +3 -3
  16. package/dist/http/elysia/index.d.ts +3 -3
  17. package/dist/http/elysia/index.js +41 -45
  18. package/dist/http/elysia/index.mjs +4 -8
  19. package/dist/http/express/index.d.mts +3 -3
  20. package/dist/http/express/index.d.ts +3 -3
  21. package/dist/http/express/index.js +38 -42
  22. package/dist/http/express/index.mjs +4 -8
  23. package/dist/http/fastify/index.d.mts +3 -3
  24. package/dist/http/fastify/index.d.ts +3 -3
  25. package/dist/http/fastify/index.js +39 -43
  26. package/dist/http/fastify/index.mjs +4 -8
  27. package/dist/http/h3/index.d.mts +3 -3
  28. package/dist/http/h3/index.d.ts +3 -3
  29. package/dist/http/h3/index.js +39 -43
  30. package/dist/http/h3/index.mjs +3 -7
  31. package/dist/http/hono/index.d.mts +3 -3
  32. package/dist/http/hono/index.d.ts +3 -3
  33. package/dist/http/hono/index.js +35 -39
  34. package/dist/http/hono/index.mjs +3 -7
  35. package/dist/http/hyper-express/index.d.mts +3 -3
  36. package/dist/http/hyper-express/index.d.ts +3 -3
  37. package/dist/http/hyper-express/index.js +36 -40
  38. package/dist/http/hyper-express/index.mjs +3 -7
  39. package/dist/http/koa/index.d.mts +3 -3
  40. package/dist/http/koa/index.d.ts +3 -3
  41. package/dist/http/koa/index.js +38 -42
  42. package/dist/http/koa/index.mjs +4 -8
  43. package/dist/index.d.mts +8 -8
  44. package/dist/index.d.ts +8 -8
  45. package/dist/index.js +40 -42
  46. package/dist/index.mjs +4 -6
  47. package/dist/{meta-B_HW7cWh.d.mts → meta-BX5jhe4Z.d.mts} +1 -2
  48. package/dist/{meta-B_HW7cWh.d.ts → meta-BX5jhe4Z.d.ts} +1 -2
  49. package/dist/rpc/bullmq/index.d.mts +3 -3
  50. package/dist/rpc/bullmq/index.d.ts +3 -3
  51. package/dist/rpc/bullmq/index.js +14 -14
  52. package/dist/rpc/bullmq/index.mjs +3 -3
  53. package/dist/rpc/kafka/index.d.mts +3 -3
  54. package/dist/rpc/kafka/index.d.ts +3 -3
  55. package/dist/rpc/kafka/index.js +14 -14
  56. package/dist/rpc/kafka/index.mjs +2 -2
  57. package/dist/rpc/nats/index.d.mts +3 -3
  58. package/dist/rpc/nats/index.d.ts +3 -3
  59. package/dist/rpc/nats/index.js +13 -13
  60. package/dist/rpc/nats/index.mjs +3 -3
  61. package/dist/rpc/rabbitmq/index.d.mts +3 -3
  62. package/dist/rpc/rabbitmq/index.d.ts +3 -3
  63. package/dist/rpc/rabbitmq/index.js +15 -15
  64. package/dist/rpc/rabbitmq/index.mjs +3 -3
  65. package/dist/rpc/redis/index.d.mts +3 -3
  66. package/dist/rpc/redis/index.d.ts +3 -3
  67. package/dist/rpc/redis/index.js +13 -13
  68. package/dist/rpc/redis/index.mjs +3 -3
  69. package/dist/test.d.mts +3 -3
  70. package/dist/test.d.ts +3 -3
  71. package/dist/test.js +6 -6
  72. package/dist/test.mjs +2 -2
  73. package/dist/{types-DEQb_e59.d.mts → types-B-rUM9Fm.d.mts} +1 -1
  74. package/dist/{types-PFPIQWVF.d.ts → types-CMeuFoyd.d.ts} +1 -1
  75. package/dist/{types-C2SQ9U9V.d.mts → types-DKVhyZk_.d.mts} +1 -1
  76. package/dist/{types-CYF0vha6.d.ts → types-MxxtkZXw.d.ts} +1 -1
  77. package/package.json +1 -1
  78. package/register/index.mjs +20 -11
  79. package/register/loader.mjs +12 -27
@@ -1,5 +1,5 @@
1
1
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
- import { B as BaseCtx, D as DefaultOptions } from './meta-B_HW7cWh.js';
2
+ import { D as DefaultOptions, B as BaseCtx } from './meta-BX5jhe4Z.js';
3
3
 
4
4
  interface HttpOptions extends DefaultOptions {
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
- import { B as BaseCtx, D as DefaultOptions } from './meta-B_HW7cWh.mjs';
2
+ import { D as DefaultOptions, B as BaseCtx } from './meta-BX5jhe4Z.mjs';
3
3
 
4
4
  interface HttpOptions extends DefaultOptions {
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { B as BaseCtx, D as DefaultOptions } from './meta-B_HW7cWh.js';
1
+ import { D as DefaultOptions, B as BaseCtx } from './meta-BX5jhe4Z.js';
2
2
 
3
3
  interface RpcServerOptions extends DefaultOptions {
4
4
  defaultQueue?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "7.0.0-alpha.8",
3
+ "version": "7.0.0-alpha.9",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import { register } from 'node:module'
2
2
  import { MessageChannel } from 'node:worker_threads'
3
- import { log } from '../dist/index.mjs'
4
-
3
+ import { isPhecda, log } from '../dist/index.mjs'
4
+ import { RELAUNCH, RELOAD } from '../dist/helper.mjs'
5
5
  const { port1, port2 } = new MessageChannel()
6
6
 
7
7
  register('./loader.mjs', {
@@ -12,18 +12,27 @@ register('./loader.mjs', {
12
12
 
13
13
  let isRunning = true
14
14
 
15
+ const fileModelMap = new Map()
16
+
15
17
  port1.on('message', async (data) => {
16
18
  const { type, files } = JSON.parse(data)
17
19
 
18
- if (!isRunning || !globalThis.__PS_HMR__ || type === 'relaunch')
19
- return process.exit(2)// file change -> relaunch
20
-
21
- if (type === 'change') {
22
- log('reload module...')
23
-
24
- for (const cb of globalThis.__PS_HMR__) await cb(files)
25
-
26
- log('reload done')
20
+ if (!isRunning || type === 'relaunch')
21
+ return RELAUNCH()// file change -> relaunch
22
+
23
+ if (type === 'change' || type === 'init') {
24
+ if (!files.length)
25
+ return
26
+ const oldModels = []
27
+ const newModels = []
28
+ for (const file of files) {
29
+ oldModels.push(...fileModelMap.get(file) || [])
30
+ const models = Object.values(await import(file)).filter(isPhecda)
31
+ fileModelMap.set(file, models)
32
+ newModels.push(...models)
33
+ }
34
+ if (type === 'change')
35
+ return RELOAD(oldModels, newModels)
27
36
  }
28
37
  })
29
38
 
@@ -75,7 +75,7 @@ export async function initialize(data) {
75
75
  if (!config.paths)
76
76
  config.paths = {}
77
77
 
78
- if (!process.env.PS_HMR_BAN) {
78
+ if (IS_DEV) {
79
79
  chokidar.watch(configPath, { persistent: true }).on('change', () => {
80
80
  port.postMessage(
81
81
  JSON.stringify({
@@ -254,32 +254,17 @@ export const load = async (url, context, nextLoad) => {
254
254
  && !isLowVersion
255
255
  ) {
256
256
  watchFiles.add(url)
257
- // watch(
258
- // fileURLToPath(url),
259
- // debounce((type) => {
260
- // if (type === 'change') {
261
- // try {
262
- // const files = [...findTopScope(url, Date.now())].reverse()
263
-
264
- // port.postMessage(
265
- // JSON.stringify({
266
- // type: 'change',
267
- // files,
268
- // }),
269
- // )
270
- // }
271
- // catch (e) {
272
- // port.postMessage(
273
- // JSON.stringify({
274
- // type: 'relaunch',
275
- // }),
276
- // )
277
- // }
278
- // }
279
- // }),
280
- // )
281
-
282
- if (IS_DEV && !process.env.PS_HMR_BAN) {
257
+
258
+ if (IS_DEV) {
259
+ if (isModuleFileUrl(url)) {
260
+ port.postMessage(
261
+ JSON.stringify({
262
+ type: 'init',
263
+ files: [fileURLToPath(url)],
264
+ }),
265
+ )
266
+ }
267
+
283
268
  chokidar.watch(fileURLToPath(url), { persistent: true }).on(
284
269
  'change',
285
270
  debounce(() => {