phecda-server 8.0.2 → 8.2.0

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 (52) hide show
  1. package/bin/cli.mjs +35 -5
  2. package/dist/{chunk-BLLRB5DQ.mjs → chunk-2P2UICBC.mjs} +2 -1
  3. package/dist/{chunk-UYZSUBX4.js → chunk-C424F7TV.js} +27 -27
  4. package/dist/{chunk-NQ55PA2X.mjs → chunk-JRNXLEAU.mjs} +2 -2
  5. package/dist/{chunk-FI5756JX.mjs → chunk-LYLSA56Y.mjs} +1 -1
  6. package/dist/{chunk-HKN3AAB2.js → chunk-MPKVT4SQ.js} +55 -54
  7. package/dist/{chunk-4LLLQOMF.js → chunk-OUQM7GZH.js} +2 -2
  8. package/dist/{chunk-OLNN4U3O.js → chunk-SRPCXPAQ.js} +20 -20
  9. package/dist/{chunk-PFPOEZHH.mjs → chunk-YDJAOLT2.mjs} +1 -1
  10. package/dist/helper.js +3 -3
  11. package/dist/helper.mjs +2 -2
  12. package/dist/http/elysia/index.d.mts +3 -3
  13. package/dist/http/elysia/index.d.ts +3 -3
  14. package/dist/http/elysia/index.js +40 -40
  15. package/dist/http/elysia/index.mjs +3 -3
  16. package/dist/http/express/index.js +37 -37
  17. package/dist/http/express/index.mjs +2 -2
  18. package/dist/http/fastify/index.js +38 -38
  19. package/dist/http/fastify/index.mjs +3 -3
  20. package/dist/http/h3/index.js +38 -38
  21. package/dist/http/h3/index.mjs +2 -2
  22. package/dist/http/hono/index.js +34 -34
  23. package/dist/http/hono/index.mjs +2 -2
  24. package/dist/http/hyper-express/index.js +35 -35
  25. package/dist/http/hyper-express/index.mjs +2 -2
  26. package/dist/http/koa/index.js +37 -37
  27. package/dist/http/koa/index.mjs +2 -2
  28. package/dist/index.d.mts +3 -1
  29. package/dist/index.d.ts +3 -1
  30. package/dist/index.js +46 -44
  31. package/dist/index.mjs +6 -4
  32. package/dist/rpc/bullmq/index.js +11 -11
  33. package/dist/rpc/bullmq/index.mjs +2 -2
  34. package/dist/rpc/electron/index.js +8 -8
  35. package/dist/rpc/electron/index.mjs +2 -2
  36. package/dist/rpc/kafka/index.js +10 -10
  37. package/dist/rpc/kafka/index.mjs +2 -2
  38. package/dist/rpc/nats/index.js +11 -11
  39. package/dist/rpc/nats/index.mjs +2 -2
  40. package/dist/rpc/rabbitmq/index.js +12 -12
  41. package/dist/rpc/rabbitmq/index.mjs +2 -2
  42. package/dist/rpc/redis/index.js +10 -10
  43. package/dist/rpc/redis/index.mjs +2 -2
  44. package/dist/rpc/ws/index.js +7 -7
  45. package/dist/rpc/ws/index.mjs +2 -2
  46. package/dist/test.js +6 -6
  47. package/dist/test.mjs +2 -2
  48. package/package.json +31 -31
  49. package/register/index.mjs +27 -0
  50. package/register/loader.mjs +65 -65
  51. package/register/utils.mjs +10 -15
  52. package/register/export.mjs +0 -39
@@ -2,6 +2,7 @@ import { register } from 'node:module'
2
2
  import { MessageChannel } from 'node:worker_threads'
3
3
  import { isPhecda, log } from '../dist/index.mjs'
4
4
  import { RELAUNCH, RELOAD } from '../dist/helper.mjs'
5
+ import inspector from 'inspector'
5
6
  const { port1, port2 } = new MessageChannel()
6
7
 
7
8
  register('./loader.mjs', {
@@ -47,3 +48,29 @@ process.on('unhandledRejection', (err) => {
47
48
 
48
49
  console.error(err)
49
50
  })
51
+
52
+
53
+ process.on('message', (data) => {
54
+ if (data.type === 'inspect') {
55
+ if (inspector.url()) {
56
+ inspector.close();
57
+ log('close inspector', 'info');
58
+ } else {
59
+ const { arg } = data
60
+
61
+ if (arg) {
62
+ if (arg.includes(':')) {
63
+ const [host, port] = arg.split(':')
64
+ inspector.open(Number(port), host)
65
+ } else {
66
+ inspector.open(Number(arg))
67
+ }
68
+ }else {
69
+ inspector.open();
70
+ }
71
+ // address already in use
72
+ if (inspector.url())
73
+ log(`open "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=${inspector.url().replace("ws://", '')}" in browser`, 'info');
74
+ }
75
+ }
76
+ })
@@ -35,7 +35,7 @@ const dtsPath = process.env.PS_DTS_PATH || 'ps.d.ts'
35
35
  const watchFiles = new Set()
36
36
  const filesRecord = new Map()
37
37
  const moduleGraph = {}
38
- // ts
38
+ // ts
39
39
  let tsconfig = {
40
40
  module: ts.ModuleKind.ESNext,
41
41
  moduleResolution: ts.ModuleResolutionKind.NodeNext,
@@ -81,7 +81,7 @@ export async function initialize(data) {
81
81
 
82
82
  if (loaderPath) {
83
83
  const loader = await
84
- import (loaderPath.startsWith('.') ? resolvePath(workdir, loaderPath) : loaderPath)
84
+ import(loaderPath.startsWith('.') ? resolvePath(workdir, loaderPath) : loaderPath)
85
85
 
86
86
  if (typeof loader.load === 'function')
87
87
  customLoad = loader.load
@@ -147,80 +147,80 @@ function getFileMid(file) {
147
147
  return ret[1]
148
148
  }
149
149
 
150
- export const resolve = async(specifier, context, nextResolve) => {
151
- if (customResolve) {
152
- const url = await customResolve(specifier, context)
153
- if (url) {
154
- return {
155
- format: 'ts',
156
- url,
157
- shortCircuit: true,
158
- }
150
+ export const resolve = async (specifier, context, nextResolve) => {
151
+ if (customResolve) {
152
+ const url = await customResolve(specifier, context)
153
+ if (url) {
154
+ return {
155
+ format: 'ts',
156
+ url,
157
+ shortCircuit: true,
159
158
  }
160
159
  }
160
+ }
161
161
 
162
- // entrypoint
163
- if (!context.parentURL)
164
- return nextResolve(specifier)
162
+ // entrypoint
163
+ if (!context.parentURL)
164
+ return nextResolve(specifier)
165
165
 
166
- // @todo skip resolve to improve performance
167
- // if (context.parentURL.includes('/node_modules/') && specifier.includes('/node_modules/'))
168
- // return nextResolve(specifier)
166
+ // @todo skip resolve to improve performance
167
+ // if (context.parentURL.includes('/node_modules/') && specifier.includes('/node_modules/'))
168
+ // return nextResolve(specifier)
169
169
 
170
- const { resolvedModule } = ts.resolveModuleName(
171
- specifier,
172
- fileURLToPath(context.parentURL),
173
- tsconfig,
174
- host,
175
- moduleResolutionCache,
170
+ const { resolvedModule } = ts.resolveModuleName(
171
+ specifier,
172
+ fileURLToPath(context.parentURL),
173
+ tsconfig,
174
+ host,
175
+ moduleResolutionCache,
176
+ )
177
+
178
+ // import among files in local project
179
+ if (
180
+ resolvedModule &&
181
+ !resolvedModule.resolvedFileName.includes('/node_modules/') &&
182
+ EXTENSIONS.includes(resolvedModule.extension)
183
+ ) {
184
+ const url = addUrlToGraph(
185
+ pathToFileURL(resolvedModule.resolvedFileName).href,
186
+ context.parentURL.split('?')[0],
176
187
  )
177
188
 
178
- // import among files in local project
179
- if (
180
- resolvedModule &&
181
- !resolvedModule.resolvedFileName.includes('/node_modules/') &&
182
- EXTENSIONS.includes(resolvedModule.extension)
183
- ) {
184
- const url = addUrlToGraph(
185
- pathToFileURL(resolvedModule.resolvedFileName).href,
186
- context.parentURL.split('?')[0],
189
+ const importerMid = getFileMid(context.parentURL)
190
+ const sourceMid = getFileMid(resolvedModule.resolvedFileName)
191
+ if (config.resolve && importerMid && sourceMid) {
192
+ const resolver = config.resolve.find(
193
+ item => item.source === sourceMid && item.importer === importerMid,
187
194
  )
188
-
189
- const importerMid = getFileMid(context.parentURL)
190
- const sourceMid = getFileMid(resolvedModule.resolvedFileName)
191
- if (config.resolve && importerMid && sourceMid) {
192
- const resolver = config.resolve.find(
193
- item => item.source === sourceMid && item.importer === importerMid,
194
- )
195
- if (resolver) {
196
- return {
197
- format: 'ts',
198
- url: pathToFileURL(resolvePath(workdir, resolver.path)).href,
199
- shortCircuit: true,
200
- }
195
+ if (resolver) {
196
+ return {
197
+ format: 'ts',
198
+ url: pathToFileURL(resolvePath(workdir, resolver.path)).href,
199
+ shortCircuit: true,
201
200
  }
202
201
  }
203
-
204
- return {
205
- format: 'ts',
206
- url,
207
- shortCircuit: true,
208
- }
209
202
  }
210
203
 
211
- const resolveRet = await nextResolve(specifier)
212
-
213
- // ts resolve fail in some cases
214
- if (resolveRet.url && isAbsolute(resolveRet.url)) {
215
- const [path, query] = resolveRet.url.split('?')
216
- resolveRet.url = pathToFileURL(path).href + (query ? `?${query}` : '')
204
+ return {
205
+ format: 'ts',
206
+ url,
207
+ shortCircuit: true,
217
208
  }
209
+ }
210
+
211
+ const resolveRet = await nextResolve(specifier)
218
212
 
219
- return resolveRet
213
+ // ts resolve fail in some cases
214
+ if (resolveRet.url && isAbsolute(resolveRet.url)) {
215
+ const [path, query] = resolveRet.url.split('?')
216
+ resolveRet.url = pathToFileURL(path).href + (query ? `?${query}` : '')
220
217
  }
221
- // @todo the first params may be url or path, need to distinguish
222
218
 
223
- export const load = async(url, context, nextLoad) => {
219
+ return resolveRet
220
+ }
221
+ // @todo the first params may be url or path, need to distinguish
222
+
223
+ export const load = async (url, context, nextLoad) => {
224
224
  let mode
225
225
  if (context.importAttributes.ps) {
226
226
  mode = context.importAttributes.ps
@@ -281,13 +281,13 @@ export const load = async(url, context, nextLoad) => {
281
281
  }
282
282
  }
283
283
 
284
-
284
+
285
285
  // resolveModuleName failed
286
286
  // I don't know why it failed
287
- if ( url.endsWith('.ts'))
287
+ if (url.endsWith('.ts'))
288
288
  context.format = 'ts'
289
289
 
290
- // module-typescript???
290
+ // module-typescript???
291
291
 
292
292
  if (context.format === 'ts') {
293
293
  const { source } = await nextLoad(url, context)
@@ -298,7 +298,7 @@ export const load = async(url, context, nextLoad) => {
298
298
 
299
299
  if (unimportRet) {
300
300
  const { injectImports } = unimportRet
301
-
301
+
302
302
  return {
303
303
  format: 'module',
304
304
  source: (
@@ -327,7 +327,7 @@ function findTopScope(url, time, modules = new Set()) {
327
327
  } else {
328
328
  if (!moduleGraph[url])
329
329
  throw new Error('root file update')
330
- for (const i of[...moduleGraph[url]]) findTopScope(i, time, modules)
330
+ for (const i of [...moduleGraph[url]]) findTopScope(i, time, modules)
331
331
  }
332
332
 
333
333
  return modules
@@ -1,6 +1,8 @@
1
1
  import { basename } from 'path'
2
2
  import { transform } from '@swc-node/core'
3
- import psExports from './export.mjs'
3
+ import { fileURLToPath } from 'node:url'
4
+ import path from 'node:path'
5
+
4
6
  const injectInlineSourceMap = ({ code, map }) => {
5
7
  if (map) {
6
8
  const base64Map = Buffer.from(map, 'utf8').toString('base64')
@@ -10,35 +12,28 @@ const injectInlineSourceMap = ({ code, map }) => {
10
12
  return code
11
13
  }
12
14
 
13
- export async function compile(sourcecode, filename, config = {}) {
14
- if (filename.endsWith('.d.ts'))
15
+ export async function compile(sourcecode, url, config = {}) {
16
+ if (url.endsWith('.d.ts'))
15
17
  return ''
16
18
 
19
+ const filename = path.basename(url.startsWith('file:') ? fileURLToPath(url) : url)
20
+
17
21
  const { code, map } = await transform(sourcecode, filename, {
18
- sourcemap: true,
19
22
  module: 'es6',
20
23
  emitDecoratorMetadata: true,
21
24
  experimentalDecorators: true,
22
25
  esModuleInterop: false,
26
+ sourcemap:false,
23
27
  ...config
24
28
  })
25
-
26
29
  return injectInlineSourceMap({ code, map })
27
30
  }
28
31
 
29
32
  export async function genUnImportRet(opts) {
30
33
  try {
31
34
  const { createUnimport } = await
32
- import ('unimport')
33
- return createUnimport({
34
- ...opts,
35
-
36
- presets: [{
37
- from: 'phecda-server',
38
- imports: psExports,
39
- }, ]
40
- .concat(opts.presets || []),
41
- })
35
+ import('unimport')
36
+ return createUnimport(opts)
42
37
  } catch (e) {
43
38
  return false
44
39
  }
@@ -1,39 +0,0 @@
1
- export default ['Addon', 'Arg', 'Assign', 'BadGatewayException', 'BadRequestException',
2
- 'Base', 'Body', 'Clear',
3
- 'ConflictException', 'Controller',
4
- 'Ctx', 'CustomResponse',
5
- 'Delete',
6
- 'Define',
7
- 'ERROR_SYMBOL',
8
- 'Effect', 'Empty', 'Err', 'Exception', 'Expose', 'Factory', 'Filter', 'ForbiddenException',
9
- 'FrameworkException',
10
- 'Generator', 'Get', 'Global', 'Guard', 'HTTPGenerator', 'Head', 'Header', 'HttpBase',
11
- 'If', 'Init', 'Inject', 'Injectable',
12
- 'InvalidInputException', 'Isolate',
13
- 'Mixin',
14
- 'NotFoundException', 'PAddon', 'PExtension', 'PFilter', 'PGuard',
15
- 'PPipe', 'Param', 'Patch', 'PayloadLargeException', 'Pipe', 'Pipeline', 'Post',
16
- 'Provide', 'Put', 'Query', 'Queue', 'RPCGenerator', 'Route',
17
- 'Rpc', 'RpcBase', 'Search', 'ServerBase', 'ServerPhecda', 'ServiceUnavailableException', 'Storage',
18
- 'Tag', 'TimeoutException', 'TimerException', 'UnauthorizedException', 'UndefinedException',
19
- 'Unique', 'Unmount', 'UnsupportedMediaTypeException', 'ValidateException',
20
- 'Watcher', 'WorkerException',
21
- 'addAddon', 'addDecoToClass',
22
- 'addFilter', 'addGuard', 'addPipe', 'emitter',
23
- 'getMergedMeta','getMeta', 'getMetaKey', 'getMetaParams', 'getOwnMeta', 'getOwnMetaKey', 'getOwnMetaParams',
24
- 'getTag',
25
- 'isPhecda', 'log', 'phecdaNamespace', 'runMiddleware',
26
- 'setInject',
27
- 'setLogger',
28
- 'setMeta',
29
- 'useS', 'wait', 'OneFile', 'ManyFiles',
30
- 'Rule','Required','Optional',
31
- 'validate',
32
- 'Min','Max','Enum','OneOf','Nested',
33
-
34
- 'Doc','DocGenerator',
35
- 'pick','omit','partial',
36
- 'functionToClass','objectToClass'
37
-
38
-
39
- ]