phecda-server 5.1.1 → 5.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 (62) hide show
  1. package/assets/ps.json +24 -0
  2. package/assets/tsconfig.json +21 -0
  3. package/bin/cli.mjs +41 -80
  4. package/dist/{chunk-HMPTPTFL.js → chunk-5BVUCNMA.js} +2 -2
  5. package/dist/{chunk-FSBD5R22.js → chunk-BSE2DSDK.js} +64 -66
  6. package/dist/{chunk-2HKQPZDT.mjs → chunk-CKQW3FDK.mjs} +3 -3
  7. package/dist/{chunk-665MB62T.mjs → chunk-JE6BBDXW.mjs} +63 -65
  8. package/dist/{chunk-UU6RHGRF.mjs → chunk-V3WIKOP3.mjs} +10 -4
  9. package/dist/{chunk-3BV2GRS7.js → chunk-VMLHTEW3.js} +22 -16
  10. package/dist/core-7f6d2be6.d.ts +27 -0
  11. package/dist/helper.d.ts +27 -0
  12. package/dist/helper.js +21 -0
  13. package/dist/helper.mjs +21 -0
  14. package/dist/index.d.ts +7 -24
  15. package/dist/index.js +24 -42
  16. package/dist/index.mjs +5 -23
  17. package/dist/rpc/bullmq/index.d.ts +3 -2
  18. package/dist/rpc/bullmq/index.js +6 -6
  19. package/dist/rpc/bullmq/index.mjs +1 -1
  20. package/dist/rpc/kafka/index.d.ts +3 -2
  21. package/dist/rpc/kafka/index.js +5 -5
  22. package/dist/rpc/kafka/index.mjs +1 -1
  23. package/dist/rpc/nats/index.d.ts +3 -2
  24. package/dist/rpc/nats/index.js +5 -5
  25. package/dist/rpc/nats/index.mjs +1 -1
  26. package/dist/rpc/rabbitmq/index.d.ts +3 -2
  27. package/dist/rpc/rabbitmq/index.js +6 -6
  28. package/dist/rpc/rabbitmq/index.mjs +1 -1
  29. package/dist/rpc/redis/index.d.ts +3 -2
  30. package/dist/rpc/redis/index.js +6 -6
  31. package/dist/rpc/redis/index.mjs +1 -1
  32. package/dist/server/elysia/index.d.ts +3 -2
  33. package/dist/server/elysia/index.js +15 -15
  34. package/dist/server/elysia/index.mjs +2 -2
  35. package/dist/server/express/index.d.ts +3 -2
  36. package/dist/server/express/index.js +14 -14
  37. package/dist/server/express/index.mjs +1 -1
  38. package/dist/server/fastify/index.d.ts +3 -2
  39. package/dist/server/fastify/index.js +15 -15
  40. package/dist/server/fastify/index.mjs +2 -2
  41. package/dist/server/h3/index.d.ts +3 -2
  42. package/dist/server/h3/index.js +12 -12
  43. package/dist/server/h3/index.mjs +1 -1
  44. package/dist/server/hono/index.d.ts +3 -2
  45. package/dist/server/hono/index.js +13 -13
  46. package/dist/server/hono/index.mjs +1 -1
  47. package/dist/server/hyper-express/index.d.ts +3 -2
  48. package/dist/server/hyper-express/index.js +13 -13
  49. package/dist/server/hyper-express/index.mjs +1 -1
  50. package/dist/server/koa/index.d.ts +3 -2
  51. package/dist/server/koa/index.js +14 -14
  52. package/dist/server/koa/index.mjs +1 -1
  53. package/dist/test.d.ts +3 -2
  54. package/dist/test.js +2 -2
  55. package/dist/test.mjs +1 -1
  56. package/dist/{helper-fcbf6aa8.d.ts → types-68f2ec2a.d.ts} +2 -4
  57. package/dist/{core-39f27fe8.d.ts → types-81be0ba3.d.ts} +2 -25
  58. package/dist/{helper-6133f78f.d.ts → types-f3b79218.d.ts} +2 -3
  59. package/package.json +61 -53
  60. package/register/loader.mjs +26 -13
  61. package/register/utils.mjs +6 -31
  62. /package/{bin → assets}/schema.json +0 -0
package/package.json CHANGED
@@ -1,74 +1,84 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "5.1.1",
3
+ "version": "5.2.1",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
- "bin": {
9
- "phecda": "bin/cli.mjs"
10
- },
5
+ "author": "fgsreally",
6
+ "license": "MIT",
7
+ "repository": "https://github.com/fgsreally/phecda/tree/main/packages/server",
8
+ "keywords": [
9
+ "server",
10
+ "IOC",
11
+ "rpc",
12
+ "types-share"
13
+ ],
11
14
  "exports": {
12
15
  ".": {
13
- "import": "./dist/index.mjs",
14
16
  "require": "./dist/index.js",
17
+ "import": "./dist/index.mjs",
15
18
  "node": "./dist/index.js"
16
19
  },
20
+ "./helper": {
21
+ "require": "./dist/helper.js",
22
+ "import": "./dist/helper.mjs"
23
+ },
17
24
  "./test": {
18
- "import": "./dist/test.mjs",
19
- "require": "./dist/test.js"
25
+ "require": "./dist/test.js",
26
+ "import": "./dist/test.mjs"
20
27
  },
21
28
  "./h3": {
22
- "import": "./dist/server/h3/index.mjs",
23
- "require": "./dist/server/h3/index.js"
29
+ "require": "./dist/server/h3/index.js",
30
+ "import": "./dist/server/h3/index.mjs"
24
31
  },
25
32
  "./express": {
26
- "import": "./dist/server/express/index.mjs",
27
- "require": "./dist/server/express/index.js"
33
+ "require": "./dist/server/express/index.js",
34
+ "import": "./dist/server/express/index.mjs"
28
35
  },
29
36
  "./koa": {
30
- "import": "./dist/server/koa/index.mjs",
31
- "require": "./dist/server/koa/index.js"
37
+ "require": "./dist/server/koa/index.js",
38
+ "import": "./dist/server/koa/index.mjs"
32
39
  },
33
40
  "./fastify": {
34
- "import": "./dist/server/fastify/index.mjs",
35
- "require": "./dist/server/fastify/index.js"
41
+ "require": "./dist/server/fastify/index.js",
42
+ "import": "./dist/server/fastify/index.mjs"
36
43
  },
37
44
  "./hyper-express": {
38
- "import": "./dist/server/hyper-express/index.mjs",
39
- "require": "./dist/server/hyper-express/index.js"
45
+ "require": "./dist/server/hyper-express/index.js",
46
+ "import": "./dist/server/hyper-express/index.mjs"
40
47
  },
41
48
  "./hono": {
42
- "import": "./dist/server/hono/index.mjs",
43
- "require": "./dist/server/hono/index.js"
49
+ "require": "./dist/server/hono/index.js",
50
+ "import": "./dist/server/hono/index.mjs"
44
51
  },
45
52
  "./elysia": {
46
- "import": "./dist/server/elysia/index.mjs",
47
- "require": "./dist/server/elysia/index.js"
53
+ "require": "./dist/server/elysia/index.js",
54
+ "import": "./dist/server/elysia/index.mjs"
48
55
  },
49
56
  "./redis": {
50
- "import": "./dist/rpc/redis/index.mjs",
51
- "require": "./dist/rpc/redis/index.js"
57
+ "require": "./dist/rpc/redis/index.js",
58
+ "import": "./dist/rpc/redis/index.mjs"
52
59
  },
53
60
  "./kafka": {
54
- "import": "./dist/rpc/kafka/index.mjs",
55
- "require": "./dist/rpc/kafka/index.js"
61
+ "require": "./dist/rpc/kafka/index.js",
62
+ "import": "./dist/rpc/kafka/index.mjs"
56
63
  },
57
64
  "./rabbitmq": {
58
- "import": "./dist/rpc/rabbitmq/index.mjs",
59
- "require": "./dist/rpc/rabbitmq/index.js"
65
+ "require": "./dist/rpc/rabbitmq/index.js",
66
+ "import": "./dist/rpc/rabbitmq/index.mjs"
60
67
  },
61
68
  "./bullmq": {
62
- "import": "./dist/rpc/bullmq/index.mjs",
63
- "require": "./dist/rpc/bullmq/index.js"
69
+ "require": "./dist/rpc/bullmq/index.js",
70
+ "import": "./dist/rpc/bullmq/index.mjs"
64
71
  },
65
72
  "./nats": {
66
- "import": "./dist/rpc/nats/index.mjs",
67
- "require": "./dist/rpc/nats/index.js"
73
+ "require": "./dist/rpc/nats/index.js",
74
+ "import": "./dist/rpc/nats/index.mjs"
68
75
  },
69
76
  "./register": "./register/index.mjs",
70
77
  "./*": "./*"
71
78
  },
79
+ "main": "dist/index.js",
80
+ "module": "dist/index.mjs",
81
+ "types": "dist/index.d.ts",
72
82
  "typesVersions": {
73
83
  "*": {
74
84
  ".": [
@@ -77,6 +87,9 @@
77
87
  "test": [
78
88
  "dist/test.d.ts"
79
89
  ],
90
+ "helper": [
91
+ "dist/helper.d.ts"
92
+ ],
80
93
  "h3": [
81
94
  "dist/server/h3/index.d.ts"
82
95
  ],
@@ -115,20 +128,25 @@
115
128
  ]
116
129
  }
117
130
  },
118
- "keywords": [
119
- "server",
120
- "IOC",
121
- "rpc",
122
- "types-share"
123
- ],
124
- "author": "fgsreally",
125
- "repository": "https://github.com/fgsreally/phecda/tree/main/packages/server",
131
+ "bin": {
132
+ "phecda": "bin/cli.mjs"
133
+ },
126
134
  "files": [
127
135
  "dist",
136
+ "assets",
128
137
  "register",
129
138
  "bin"
130
139
  ],
131
- "license": "MIT",
140
+ "dependencies": {
141
+ "@swc-node/core": "^1.10.6",
142
+ "cac": "^6.7.14",
143
+ "chokidar": "^3.5.3",
144
+ "debug": "^4.3.4",
145
+ "fs-extra": "^11.2.0",
146
+ "picocolors": "^1.0.0",
147
+ "reflect-metadata": "^0.1.13",
148
+ "phecda-core": "3.0.0"
149
+ },
132
150
  "devDependencies": {
133
151
  "@koa/router": "^12.0.1",
134
152
  "@nucleoidjs/kafkajs-mock": "^0.0.1",
@@ -159,16 +177,6 @@
159
177
  "typescript": "^5.4.5",
160
178
  "unimport": "^3.7.1"
161
179
  },
162
- "dependencies": {
163
- "@swc-node/core": "^1.10.6",
164
- "cac": "^6.7.14",
165
- "chokidar": "^3.5.3",
166
- "debug": "^4.3.4",
167
- "fs-extra": "^11.2.0",
168
- "picocolors": "^1.0.0",
169
- "reflect-metadata": "^0.1.13",
170
- "phecda-core": "3.0.0"
171
- },
172
180
  "scripts": {
173
181
  "dev": "tsup --watch",
174
182
  "build": "tsup"
@@ -11,7 +11,7 @@ import { createRequire } from 'module'
11
11
  import ts from 'typescript'
12
12
  import chokidar from 'chokidar'
13
13
  import { log } from '../dist/index.mjs'
14
- import { compile, genUnImportRet, handleClassTypes } from './utils.mjs'
14
+ import { compile, genUnImportRet, handleClassTypes, slash } from './utils.mjs'
15
15
 
16
16
  let port
17
17
 
@@ -39,17 +39,20 @@ if (isLowVersion)
39
39
  await initialize()
40
40
 
41
41
  let config
42
+
43
+ const workdir = process.env.PS_WORKDIR || process.cwd()
44
+
45
+ const configPath = resolvePath(
46
+ workdir,
47
+ process.env.PS_CONFIG_FILE || 'ps.json',
48
+ )
49
+
42
50
  const require = createRequire(import.meta.url)
43
51
  export async function initialize(data) {
44
52
  if (data)
45
53
  port = data.port
46
54
  log('read config...')
47
55
 
48
- const configPath = resolvePath(
49
- process.cwd(),
50
- process.env.PS_CONFIG_FILE || 'ps.json',
51
- )
52
-
53
56
  config = require(configPath)
54
57
  if (!config.virtualFile)
55
58
  config.virtualFile = {}
@@ -72,8 +75,21 @@ export async function initialize(data) {
72
75
  await unimportRet.init()
73
76
 
74
77
  writeFile(
75
- config.unimport.dtsPath || dtsPath,
76
- handleClassTypes(await unimportRet.generateTypeDeclarations()),
78
+ resolvePath(workdir, config.unimport.dtsPath || dtsPath),
79
+ handleClassTypes(
80
+ await unimportRet.generateTypeDeclarations({
81
+ resolvePath: (i) => {
82
+ if (i.from.startsWith('.') || isAbsolute(i.from)) {
83
+ const related = slash(
84
+ relative(workdir, i.from).replace(/\.ts(x)?$/, ''),
85
+ )
86
+
87
+ return !related.startsWith('.') ? `./${related}` : related
88
+ }
89
+ return i.from
90
+ },
91
+ }),
92
+ ),
77
93
  )
78
94
  }
79
95
  }
@@ -173,7 +189,7 @@ export const resolve = async (specifier, context, nextResolve) => {
173
189
  if (resolver) {
174
190
  return {
175
191
  format: 'ts',
176
- url: pathToFileURL(resolvePath(process.cwd(), resolver.path)).href,
192
+ url: pathToFileURL(resolvePath(workdir, resolver.path)).href,
177
193
  shortCircuit: true,
178
194
  }
179
195
  }
@@ -281,10 +297,7 @@ export const load = async (url, context, nextLoad) => {
281
297
  source: (
282
298
  await injectImports(
283
299
  compiled,
284
- (url.startsWith('file://') ? fileURLToPath(url) : url).replace(
285
- /\\/g,
286
- '/',
287
- ),
300
+ slash(url.startsWith('file://') ? fileURLToPath(url) : url),
288
301
  )
289
302
  ).code,
290
303
  shortCircuit: true,
@@ -1,4 +1,4 @@
1
- import { isAbsolute } from 'path'
1
+ import { basename } from 'path'
2
2
  import { transform } from '@swc-node/core'
3
3
  const injectInlineSourceMap = ({ code, map }) => {
4
4
  if (map) {
@@ -42,40 +42,15 @@ export async function genUnImportRet(opts) {
42
42
  }
43
43
  }
44
44
 
45
- // function slash(str) {
46
- // return str.replace(/\\/g, '/')
47
- // }
48
-
49
- // async function findWorkspaceExports() {
50
- // try {
51
- // const { default: fg } = await import('fast-glob')
52
- // const { scanExports } = await import('unimport')
53
- // const result = await fg(
54
- // '**/*.@(controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge).ts',
55
- // {
56
- // ignore: ['node_modules'],
57
- // absolute: true,
58
- // cwd: process.cwd(),
59
- // onlyFiles: true,
60
- // followSymbolicLinks: true,
61
- // },
62
- // )
63
-
64
- // const files = Array.from(new Set(result.flat())).map(slash)
65
-
66
- // return (await Promise.all(files.map(i => scanExports(i, false))))
67
- // .flat()
68
- // }
69
- // catch (e) {
70
- // return []
71
- // }
72
- // }
73
-
74
45
  export function handleClassTypes(input) {
75
46
  return input.replace(/const\s+(\w+)\s*:\s*typeof\s+import\(['"](.+)['"]\)\['(\w+)'\]/g, (_, n, p, e) => {
76
- if (isAbsolute(p))
47
+ // TestController in test.controller
48
+ if (p.startsWith('./') && (basename(p).replace('.', '').toLowerCase() === e.toLowerCase()))
77
49
  return `${_}\n type ${n} = InstanceType<typeof import('${p}')['${e}']>`
78
50
 
79
51
  return _
80
52
  })
81
53
  }
54
+ export function slash(str) {
55
+ return str.replace(/\\/g, '/')
56
+ }
File without changes