phecda-server 7.0.0-alpha.11 → 7.0.0-alpha.13

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 (86) hide show
  1. package/assets/schema.json +11 -2
  2. package/bin/cli.mjs +62 -9
  3. package/dist/{chunk-G7JFKM2M.js → chunk-IJFIY6QN.js} +1 -9
  4. package/dist/{chunk-Z7NAAE4M.mjs → chunk-VX4BZEL7.mjs} +0 -8
  5. package/dist/{core-CUTbX_IS.d.ts → core-CDzIy2g0.d.ts} +1 -1
  6. package/dist/{core-DIfgUKIU.d.mts → core-jUg1HvYT.d.mts} +1 -1
  7. package/dist/helper.d.mts +2 -4
  8. package/dist/helper.d.ts +2 -4
  9. package/dist/helper.js +2 -4
  10. package/dist/helper.mjs +1 -3
  11. package/dist/http/elysia/index.d.mts +3 -3
  12. package/dist/http/elysia/index.d.ts +3 -3
  13. package/dist/http/elysia/index.js +18 -17
  14. package/dist/http/elysia/index.mjs +2 -1
  15. package/dist/http/express/index.d.mts +3 -3
  16. package/dist/http/express/index.d.ts +3 -3
  17. package/dist/http/express/index.js +17 -16
  18. package/dist/http/express/index.mjs +2 -1
  19. package/dist/http/fastify/index.d.mts +3 -3
  20. package/dist/http/fastify/index.d.ts +3 -3
  21. package/dist/http/fastify/index.js +17 -16
  22. package/dist/http/fastify/index.mjs +2 -1
  23. package/dist/http/h3/index.d.mts +3 -3
  24. package/dist/http/h3/index.d.ts +3 -3
  25. package/dist/http/h3/index.js +18 -17
  26. package/dist/http/h3/index.mjs +2 -1
  27. package/dist/http/hono/index.d.mts +3 -3
  28. package/dist/http/hono/index.d.ts +3 -3
  29. package/dist/http/hono/index.js +15 -14
  30. package/dist/http/hono/index.mjs +2 -1
  31. package/dist/http/hyper-express/index.d.mts +3 -3
  32. package/dist/http/hyper-express/index.d.ts +3 -3
  33. package/dist/http/hyper-express/index.js +16 -15
  34. package/dist/http/hyper-express/index.mjs +2 -1
  35. package/dist/http/koa/index.d.mts +3 -3
  36. package/dist/http/koa/index.d.ts +3 -3
  37. package/dist/http/koa/index.js +17 -16
  38. package/dist/http/koa/index.mjs +2 -1
  39. package/dist/index.d.mts +8 -8
  40. package/dist/index.d.ts +8 -8
  41. package/dist/index.js +19 -19
  42. package/dist/index.mjs +1 -1
  43. package/dist/{meta-CR-D39hQ.d.mts → meta-xvg6V7pH.d.mts} +2 -19
  44. package/dist/{meta-CR-D39hQ.d.ts → meta-xvg6V7pH.d.ts} +2 -19
  45. package/dist/rpc/bullmq/index.d.mts +4 -6
  46. package/dist/rpc/bullmq/index.d.ts +4 -6
  47. package/dist/rpc/bullmq/index.js +7 -75
  48. package/dist/rpc/bullmq/index.mjs +3 -71
  49. package/dist/rpc/electron/index.d.mts +13 -0
  50. package/dist/rpc/electron/index.d.ts +13 -0
  51. package/dist/rpc/electron/index.js +72 -0
  52. package/dist/rpc/electron/index.mjs +72 -0
  53. package/dist/rpc/kafka/index.d.mts +4 -9
  54. package/dist/rpc/kafka/index.d.ts +4 -9
  55. package/dist/rpc/kafka/index.js +7 -86
  56. package/dist/rpc/kafka/index.mjs +3 -82
  57. package/dist/rpc/nats/index.d.mts +4 -6
  58. package/dist/rpc/nats/index.d.ts +4 -6
  59. package/dist/rpc/nats/index.js +7 -67
  60. package/dist/rpc/nats/index.mjs +2 -62
  61. package/dist/rpc/rabbitmq/index.d.mts +4 -6
  62. package/dist/rpc/rabbitmq/index.d.ts +4 -6
  63. package/dist/rpc/rabbitmq/index.js +7 -73
  64. package/dist/rpc/rabbitmq/index.mjs +3 -69
  65. package/dist/rpc/redis/index.d.mts +4 -9
  66. package/dist/rpc/redis/index.d.ts +4 -9
  67. package/dist/rpc/redis/index.js +7 -74
  68. package/dist/rpc/redis/index.mjs +3 -70
  69. package/dist/rpc/ws/index.d.mts +14 -0
  70. package/dist/rpc/ws/index.d.ts +14 -0
  71. package/dist/rpc/ws/index.js +73 -0
  72. package/dist/rpc/ws/index.mjs +73 -0
  73. package/dist/test.d.mts +7 -3
  74. package/dist/test.d.ts +7 -3
  75. package/dist/types-6qaaUIKZ.d.mts +14 -0
  76. package/dist/{types-BF1TDbFV.d.ts → types-B-1OL-3P.d.ts} +1 -1
  77. package/dist/types-BtXOT5rI.d.ts +14 -0
  78. package/dist/{types-DYviSl5B.d.mts → types-Ctd6pLNE.d.mts} +1 -1
  79. package/package.json +13 -2
  80. package/register/index.mjs +0 -1
  81. package/register/loader.mjs +12 -52
  82. package/register/utils.mjs +7 -7
  83. package/assets/ps.json +0 -24
  84. package/assets/tsconfig.json +0 -21
  85. package/dist/types-DYRu0vic.d.ts +0 -19
  86. package/dist/types-DqH1qA-q.d.mts +0 -19
package/dist/test.d.ts CHANGED
@@ -2,9 +2,13 @@ import * as supertest from 'supertest';
2
2
  import { Test } from 'supertest';
3
3
  import { Server } from 'node:http';
4
4
  import { Construct } from 'phecda-core';
5
- import { F as Factory } from './core-CUTbX_IS.js';
6
- import { P as PickFunc } from './meta-CR-D39hQ.js';
5
+ import { F as Factory } from './core-CDzIy2g0.js';
6
+ import { e as CustomResponse } from './meta-xvg6V7pH.js';
7
7
 
8
+ type PickFuncKeys<Type> = {
9
+ [Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never;
10
+ }[keyof Type];
11
+ type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
8
12
  declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
9
13
  get<C extends T[number]>(Model: C): InstanceType<C>;
10
14
  }>;
@@ -15,4 +19,4 @@ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<Return
15
19
  module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
16
20
  }>;
17
21
 
18
- export { type SuperTestRequest, TestFactory, TestHttp };
22
+ export { type PickFunc, type SuperTestRequest, TestFactory, TestHttp };
@@ -0,0 +1,14 @@
1
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.mjs';
2
+
3
+ interface RpcServerOptions extends DefaultOptions {
4
+ defaultQueue?: string;
5
+ }
6
+ interface RpcCtx extends BaseCtx {
7
+ args: any[];
8
+ id: string;
9
+ queue: string;
10
+ isEvent?: boolean;
11
+ category: 'rpc';
12
+ }
13
+
14
+ export type { RpcCtx as R, RpcServerOptions as a };
@@ -1,5 +1,5 @@
1
1
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.js';
2
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.js';
3
3
 
4
4
  interface HttpOptions extends DefaultOptions {
5
5
  /**
@@ -0,0 +1,14 @@
1
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.js';
2
+
3
+ interface RpcServerOptions extends DefaultOptions {
4
+ defaultQueue?: string;
5
+ }
6
+ interface RpcCtx extends BaseCtx {
7
+ args: any[];
8
+ id: string;
9
+ queue: string;
10
+ isEvent?: boolean;
11
+ category: 'rpc';
12
+ }
13
+
14
+ export type { RpcCtx as R, RpcServerOptions as a };
@@ -1,5 +1,5 @@
1
1
  import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'node:http';
2
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.mjs';
2
+ import { D as DefaultOptions, B as BaseCtx } from './meta-xvg6V7pH.mjs';
3
3
 
4
4
  interface HttpOptions extends DefaultOptions {
5
5
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "7.0.0-alpha.11",
3
+ "version": "7.0.0-alpha.13",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -74,6 +74,14 @@
74
74
  "require": "./dist/rpc/nats/index.js",
75
75
  "import": "./dist/rpc/nats/index.mjs"
76
76
  },
77
+ "./electron": {
78
+ "require": "./dist/rpc/electron/index.js",
79
+ "import": "./dist/rpc/electron/index.mjs"
80
+ },
81
+ "./ws": {
82
+ "require": "./dist/rpc/ws/index.js",
83
+ "import": "./dist/rpc/ws/index.mjs"
84
+ },
77
85
  "./register": "./register/index.mjs",
78
86
  "./*": "./*"
79
87
  },
@@ -160,8 +168,10 @@
160
168
  "@types/koa": "^2.13.12",
161
169
  "@types/koa__router": "^12.0.4",
162
170
  "@types/supertest": "^2.0.12",
171
+ "@types/ws": "^8.5.13",
163
172
  "amqplib": "^0.10.3",
164
173
  "bullmq": "^5.7.1",
174
+ "electron": "^33.2.1",
165
175
  "elysia": "^1.0.17",
166
176
  "express": "^4.18.2",
167
177
  "fastify": "^4.25.1",
@@ -178,7 +188,8 @@
178
188
  "supertest": "^6.3.3",
179
189
  "tsup": "^8.1.0",
180
190
  "typescript": "^5.7.2",
181
- "unimport": "^3.7.1"
191
+ "unimport": "^3.7.1",
192
+ "ws": "^8.18.0"
182
193
  },
183
194
  "scripts": {
184
195
  "dev": "tsup --watch",
@@ -16,7 +16,6 @@ const fileModelMap = new Map()
16
16
 
17
17
  port1.on('message', async (data) => {
18
18
  const { type, files } = JSON.parse(data)
19
-
20
19
  if (!isRunning || type === 'relaunch')
21
20
  return RELAUNCH()// file change -> relaunch
22
21
 
@@ -7,7 +7,6 @@ import {
7
7
  relative,
8
8
  resolve as resolvePath,
9
9
  } from 'path'
10
- import { existsSync } from 'fs'
11
10
  import { createRequire } from 'module'
12
11
  import ts from 'typescript'
13
12
  import chokidar from 'chokidar'
@@ -32,7 +31,6 @@ let unimportRet
32
31
  const dtsPath = process.env.PS_DTS_PATH || 'ps.d.ts'
33
32
 
34
33
  // graph
35
- let entryUrl
36
34
  const watchFiles = new Set()
37
35
  const filesRecord = new Map()
38
36
  const moduleGraph = {}
@@ -137,9 +135,12 @@ function addUrlToGraph(url, parent) {
137
135
  function getFileMid(file) {
138
136
  const filename = basename(file)
139
137
  const ret = filename.split('.')
140
- if (ret.length === 3)
141
- return ret[1]
142
- else return ''
138
+ if (!['js', 'mjs', 'cjs', 'ts', 'tsx', 'mts', 'cts'].includes(ret.pop()))
139
+ return ''
140
+ if (!ret[0])// .dockerfile
141
+ return ''
142
+
143
+ return ret[1]
143
144
  }
144
145
 
145
146
  export const resolve = async (specifier, context, nextResolve) => {
@@ -151,46 +152,12 @@ export const resolve = async (specifier, context, nextResolve) => {
151
152
  shortCircuit: true,
152
153
  }
153
154
  }
154
- // entrypoint
155
- if (!context.parentURL) {
156
- if (/^file:\/\/\//.test(specifier) && existsSync(fileURLToPath(specifier))) {
157
- entryUrl = specifier
155
+ // if (isAbsolute(specifier))
156
+ // specifier = pathToFileURL(specifier).href
158
157
 
159
- return {
160
- format: EXTENSIONS.some(ext => specifier.endsWith(ext))
161
- ? 'ts'
162
- : undefined,
163
- url: specifier,
164
- shortCircuit: true,
165
- }
166
- }
167
- else {
168
- // won't resolve virtual file as entry in vite
169
- return nextResolve(specifier)
170
- }
171
- }
172
- // url import
173
- // it seems useless
174
- // if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
175
- // const url = addUrlToGraph(specifier, context.parentURL.split('?')[0])
176
- // return {
177
- // format: 'ts',
178
- // url,
179
- // shortCircuit: true,
180
- // }
181
- // }
182
-
183
-
184
- // hmr import
185
- if (
186
- context.parentURL.includes('/node_modules/phecda-server')
187
- && isAbsolute(specifier)
188
- ) {
189
- specifier = relative(fileURLToPath(entryUrl), specifier)
190
- .replace(/\.ts$/, '')
191
- .slice(1)
192
- context.parentURL = entryUrl
193
- }
158
+ // entrypoint
159
+ if (!context.parentURL)
160
+ return nextResolve(specifier)
194
161
 
195
162
  // import/require from external library
196
163
  if (context.parentURL.includes('/node_modules/'))
@@ -236,7 +203,6 @@ export const resolve = async (specifier, context, nextResolve) => {
236
203
  }
237
204
  }
238
205
 
239
-
240
206
  const resolveRet = await nextResolve(specifier)
241
207
 
242
208
  // ts resolve fail in some cases
@@ -248,9 +214,6 @@ export const resolve = async (specifier, context, nextResolve) => {
248
214
  // @todo the first params may be url or path, need to distinguish
249
215
 
250
216
  export const load = async (url, context, nextLoad) => {
251
-
252
-
253
-
254
217
  if (config.virtualFile[url]) {
255
218
  return {
256
219
  format: 'module',
@@ -265,9 +228,8 @@ export const load = async (url, context, nextLoad) => {
265
228
  delete context.importAttributes.ps
266
229
  }
267
230
 
268
-
269
-
270
231
  url = url.split('?')[0]
232
+
271
233
  if (
272
234
  !url.includes('/node_modules/')
273
235
  && url.startsWith('file://')
@@ -324,8 +286,6 @@ export const load = async (url, context, nextLoad) => {
324
286
  const compiled = (await compile(code, url)).replace(/_ts_metadata\(\"design:paramtypes\"\,/g, '_ts_metadata("design:paramtypes",()=>')// handle cycle
325
287
 
326
288
  if (unimportRet) {
327
-
328
-
329
289
  const { injectImports } = unimportRet
330
290
 
331
291
  return {
@@ -24,28 +24,28 @@ export async function compile(sourcecode, filename) {
24
24
 
25
25
  jsc: {
26
26
  parser: {
27
- syntax: "typescript",
27
+ syntax: 'typescript',
28
28
  importAttributes: true,
29
29
  decorators: true,
30
30
  tsx: false,
31
31
  dynamicImport: true,
32
- strictPropertyInitialization: false
32
+ strictPropertyInitialization: false,
33
33
  },
34
34
  experimental: {
35
- keepImportAssertions: true
35
+ keepImportAssertions: true,
36
36
  },
37
37
  transform: {
38
38
  legacyDecorator: true,
39
- decoratorMetadata: true
40
- }
39
+ decoratorMetadata: true,
40
+ },
41
41
  // parser: {
42
42
  // importAttributes: true
43
43
  // },
44
44
  // experimental: {
45
45
  // keepImportAssertions: true
46
46
  // }
47
- }
48
- }
47
+ },
48
+ },
49
49
  })
50
50
 
51
51
  return injectInlineSourceMap({ code, map })
package/assets/ps.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "$schema": "https://unpkg.com/phecda-server/assets/schema.json",
3
- "resolve": [
4
- {
5
- "source": "controller",
6
- "importer": "http",
7
- "path": ".ps/http.js"
8
- },
9
- {
10
- "source": "rpc",
11
- "importer": "client",
12
- "path": ".ps/rpc.js"
13
- }
14
- ],
15
- "unimport": {
16
- "dirs": ["."],
17
- "dirsScanOptions": {
18
- "filePatterns": ["*.{service,controller,module,rpc,solo,guard,extension,pipe,filter,addon}.ts"]
19
- }
20
- },
21
- "virtualFile": {},
22
- "moduleFile": []
23
-
24
- }
@@ -1,21 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "esnext",
4
- "useDefineForClassFields": false,
5
- "experimentalDecorators": true,
6
- "emitDecoratorMetadata": true,
7
- "module": "esnext",
8
- "lib": ["esnext", "DOM"],
9
- "strictPropertyInitialization": false,
10
- "moduleResolution": "Node",
11
- "strict": true,
12
- "resolveJsonModule": true,
13
- "esModuleInterop": true,
14
- "noEmit": true,
15
- "noUnusedLocals": true,
16
- "noUnusedParameters": true,
17
- "noImplicitReturns": true,
18
- "skipLibCheck": true
19
- },
20
- "include": [".","./ps.d.ts"]
21
- }
@@ -1,19 +0,0 @@
1
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.js';
2
-
3
- interface RpcServerOptions extends DefaultOptions {
4
- defaultQueue?: string;
5
- }
6
- interface RpcClientOptions {
7
- key?: string;
8
- timeout?: number;
9
- max?: number;
10
- }
11
- interface RpcCtx extends BaseCtx {
12
- args: any[];
13
- id: string;
14
- queue: string;
15
- isEvent?: boolean;
16
- category: 'rpc';
17
- }
18
-
19
- export type { RpcCtx as R, RpcServerOptions as a, RpcClientOptions as b };
@@ -1,19 +0,0 @@
1
- import { D as DefaultOptions, B as BaseCtx } from './meta-CR-D39hQ.mjs';
2
-
3
- interface RpcServerOptions extends DefaultOptions {
4
- defaultQueue?: string;
5
- }
6
- interface RpcClientOptions {
7
- key?: string;
8
- timeout?: number;
9
- max?: number;
10
- }
11
- interface RpcCtx extends BaseCtx {
12
- args: any[];
13
- id: string;
14
- queue: string;
15
- isEvent?: boolean;
16
- category: 'rpc';
17
- }
18
-
19
- export type { RpcCtx as R, RpcServerOptions as a, RpcClientOptions as b };