phecda-server 5.0.0-beta.19 → 5.0.0-beta.21
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.
- package/dist/{chunk-WNTTAFLC.js → chunk-562XCEUU.js} +9 -11
- package/dist/{chunk-PXI5J4LR.mjs → chunk-AL36AJMH.mjs} +8 -10
- package/dist/{chunk-VBYDVWRK.js → chunk-FMPVMJLE.js} +38 -32
- package/dist/{chunk-LSMNOIFA.mjs → chunk-TCW7B6MG.mjs} +39 -33
- package/dist/core-895ed04d.d.ts +112 -0
- package/dist/index.d.ts +39 -15
- package/dist/index.js +27 -24
- package/dist/index.mjs +8 -5
- package/dist/rpc/kafka/index.d.ts +2 -2
- package/dist/rpc/kafka/index.js +9 -6
- package/dist/rpc/kafka/index.mjs +6 -3
- package/dist/rpc/rabbitmq/index.d.ts +2 -2
- package/dist/rpc/rabbitmq/index.js +9 -6
- package/dist/rpc/rabbitmq/index.mjs +6 -3
- package/dist/rpc/redis/index.d.ts +2 -2
- package/dist/rpc/redis/index.js +9 -6
- package/dist/rpc/redis/index.mjs +6 -3
- package/dist/server/express/index.d.ts +1 -1
- package/dist/server/express/index.js +18 -14
- package/dist/server/express/index.mjs +9 -5
- package/dist/server/fastify/index.d.ts +1 -1
- package/dist/server/fastify/index.js +23 -16
- package/dist/server/fastify/index.mjs +13 -6
- package/dist/server/h3/index.d.ts +1 -1
- package/dist/server/h3/index.js +18 -14
- package/dist/server/h3/index.mjs +9 -5
- package/dist/server/koa/index.d.ts +1 -1
- package/dist/server/koa/index.js +18 -14
- package/dist/server/koa/index.mjs +9 -5
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/test.mjs +1 -1
- package/package.json +3 -2
- package/register/loader.mjs +3 -5
- package/register/utils.mjs +46 -5
- package/dist/core-eb2a0799.d.ts +0 -131
package/dist/test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkFMPVMJLEjs = require('./chunk-FMPVMJLE.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkXHKBG2VAjs = require('./chunk-XHKBG2VA.js');
|
|
@@ -8,7 +8,7 @@ var _chunkXHKBG2VAjs = require('./chunk-XHKBG2VA.js');
|
|
|
8
8
|
// src/test.ts
|
|
9
9
|
var _phecdacore = require('phecda-core');
|
|
10
10
|
async function TestFactory(...Modules) {
|
|
11
|
-
const { moduleMap, constructorMap } = await
|
|
11
|
+
const { moduleMap, constructorMap } = await _chunkFMPVMJLEjs.Factory.call(void 0, Modules);
|
|
12
12
|
return {
|
|
13
13
|
get(Module) {
|
|
14
14
|
const tag = _phecdacore.getTag.call(void 0, Module);
|
package/dist/test.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-server",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.21",
|
|
4
4
|
"description": "provide express middlewares, `nestjs` format",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"amqplib": "^0.10.3",
|
|
104
104
|
"chokidar": "^3.5.3",
|
|
105
105
|
"express": "^4.18.2",
|
|
106
|
+
"fast-glob": "^3.3.2",
|
|
106
107
|
"fastify": "^4.25.1",
|
|
107
108
|
"h3": "^1.9.0",
|
|
108
109
|
"ioredis": "^5.3.2",
|
|
@@ -121,7 +122,7 @@
|
|
|
121
122
|
"debug": "^4.3.4",
|
|
122
123
|
"picocolors": "^1.0.0",
|
|
123
124
|
"reflect-metadata": "^0.1.13",
|
|
124
|
-
"phecda-core": "3.0.0-beta.
|
|
125
|
+
"phecda-core": "3.0.0-beta.14"
|
|
125
126
|
},
|
|
126
127
|
"scripts": {
|
|
127
128
|
"dev": "tsup --watch",
|
package/register/loader.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'url'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
3
2
|
import { writeFile } from 'fs/promises'
|
|
4
3
|
import { extname, isAbsolute, relative } from 'path'
|
|
5
4
|
import ts from 'typescript'
|
|
6
5
|
import chokidar from 'chokidar'
|
|
7
6
|
import { PS_FILE_RE, log } from '../dist/index.mjs'
|
|
8
|
-
import { compile, genUnImportRet } from './utils.mjs'
|
|
7
|
+
import { compile, genUnImportRet, handleClassTypes } from './utils.mjs'
|
|
9
8
|
let port
|
|
10
9
|
const isLowVersion = parseFloat(process.version.slice(1)) < 18.18
|
|
11
10
|
// this part is important or not?
|
|
@@ -35,15 +34,14 @@ export async function initialize(data) {
|
|
|
35
34
|
if (data)
|
|
36
35
|
port = data.port
|
|
37
36
|
|
|
38
|
-
if (process.env.
|
|
37
|
+
if (process.env.PS_UNIMPORT_BAN)
|
|
39
38
|
return
|
|
40
39
|
|
|
41
40
|
unimportRet = await genUnImportRet()
|
|
42
41
|
|
|
43
42
|
if (unimportRet) {
|
|
44
43
|
log('auto import...')
|
|
45
|
-
|
|
46
|
-
writeFile(dtsPath, await unimportRet.generateTypeDeclarations())
|
|
44
|
+
writeFile(dtsPath, handleClassTypes(await unimportRet.generateTypeDeclarations()))
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
|
package/register/utils.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbsolute } from 'path'
|
|
1
2
|
import { transform } from '@swc-node/core'
|
|
2
3
|
const injectInlineSourceMap = ({ code, map }) => {
|
|
3
4
|
if (map) {
|
|
@@ -18,7 +19,6 @@ export async function compile(sourcecode, filename) {
|
|
|
18
19
|
emitDecoratorMetadata: true,
|
|
19
20
|
experimentalDecorators: true,
|
|
20
21
|
esModuleInterop: false,
|
|
21
|
-
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
return injectInlineSourceMap({ code, map })
|
|
@@ -26,16 +26,57 @@ export async function compile(sourcecode, filename) {
|
|
|
26
26
|
|
|
27
27
|
export async function genUnImportRet() {
|
|
28
28
|
try {
|
|
29
|
-
const
|
|
29
|
+
const psExports = Object.keys(await import('../dist/index.mjs'))
|
|
30
30
|
const { createUnimport } = await import('unimport')
|
|
31
31
|
|
|
32
|
+
const workspaceExports = await findWorkspaceExports()
|
|
32
33
|
return createUnimport({
|
|
33
|
-
imports:
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
imports: psExports
|
|
35
|
+
.map((k) => {
|
|
36
|
+
return { name: k, from: 'phecda-server' }
|
|
37
|
+
})
|
|
38
|
+
.concat(workspaceExports),
|
|
36
39
|
})
|
|
37
40
|
}
|
|
38
41
|
catch (e) {
|
|
39
42
|
return false
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
|
|
46
|
+
function slash(str) {
|
|
47
|
+
return str.replace(/\\/g, '/')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function findWorkspaceExports() {
|
|
51
|
+
try {
|
|
52
|
+
const { default: fg } = await import('fast-glob')
|
|
53
|
+
const { scanExports } = await import('unimport')
|
|
54
|
+
const result = await fg(
|
|
55
|
+
'**/*.@(controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge).ts',
|
|
56
|
+
{
|
|
57
|
+
ignore: ['node_modules'],
|
|
58
|
+
absolute: true,
|
|
59
|
+
cwd: process.cwd(),
|
|
60
|
+
onlyFiles: true,
|
|
61
|
+
followSymbolicLinks: true,
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const files = Array.from(new Set(result.flat())).map(slash)
|
|
66
|
+
|
|
67
|
+
return (await Promise.all(files.map(i => scanExports(i, false))))
|
|
68
|
+
.flat()
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return []
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function handleClassTypes(input) {
|
|
76
|
+
return input.replace(/const\s+(\w+)\s*:\s*typeof\s+import\(['"](.+)['"]\)\['(\w+)'\]/g, (_, n, p, e) => {
|
|
77
|
+
if (isAbsolute(p))
|
|
78
|
+
return `${_}\n type ${n} = InstanceType<typeof import('${p}')['${e}']>`
|
|
79
|
+
|
|
80
|
+
return _
|
|
81
|
+
})
|
|
82
|
+
}
|
package/dist/core-eb2a0799.d.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { Events, Construct } from 'phecda-core';
|
|
2
|
-
import { IncomingHttpHeaders } from 'node:http';
|
|
3
|
-
|
|
4
|
-
declare class Exception extends Error {
|
|
5
|
-
message: string;
|
|
6
|
-
status: number;
|
|
7
|
-
description: string;
|
|
8
|
-
constructor(message: string, status: number, description?: string);
|
|
9
|
-
get data(): {
|
|
10
|
-
message: string;
|
|
11
|
-
description: string;
|
|
12
|
-
status: number;
|
|
13
|
-
__PS_ERROR__: boolean;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
declare const MERGE_SYMBOL = "__PS_MERGE__";
|
|
18
|
-
declare const UNMOUNT_SYMBOL = "__PS_UNMOUNT__";
|
|
19
|
-
declare const MODULE_SYMBOL = "__PS_MODULE__";
|
|
20
|
-
declare const META_SYMBOL = "__PS_META__";
|
|
21
|
-
declare const APP_SYMBOL = "__PS__";
|
|
22
|
-
declare const IS_DEV: boolean;
|
|
23
|
-
declare const IS_STRICT: boolean;
|
|
24
|
-
declare const IS_LOG_BAN: boolean;
|
|
25
|
-
declare const ERROR_SYMBOL = "__PS_ERROR__";
|
|
26
|
-
declare const PS_FILE_RE: RegExp;
|
|
27
|
-
declare const PS_IMPORT_RE: RegExp;
|
|
28
|
-
|
|
29
|
-
declare class Meta {
|
|
30
|
-
data: P.MetaData;
|
|
31
|
-
paramsType: any[];
|
|
32
|
-
constructor(data: P.MetaData, paramsType: any[]);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface Emitter {
|
|
36
|
-
on<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
37
|
-
once<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
38
|
-
off<N extends keyof Events>(eventName: N, cb: (args: Events[N]) => void): void;
|
|
39
|
-
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
40
|
-
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
41
|
-
}
|
|
42
|
-
type ToControllerMap<T = any> = {
|
|
43
|
-
[K in keyof T]: T[K] extends (new (...args: any) => any) ? PickFunc<InstanceType<T[K]>> : void;
|
|
44
|
-
};
|
|
45
|
-
type PickKeysByValue<Type, Value> = {
|
|
46
|
-
[Key in keyof Type]: Type[Key] extends Value ? Key : never;
|
|
47
|
-
}[keyof Type];
|
|
48
|
-
type PickFunc<T> = Pick<T, PickKeysByValue<T, (...args: any) => any>>;
|
|
49
|
-
type RequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
50
|
-
declare namespace P {
|
|
51
|
-
interface BaseContext {
|
|
52
|
-
meta: Meta;
|
|
53
|
-
moduleMap: Record<string, any>;
|
|
54
|
-
parallel?: boolean;
|
|
55
|
-
type: string;
|
|
56
|
-
tag: string;
|
|
57
|
-
[key: string]: any;
|
|
58
|
-
}
|
|
59
|
-
interface HttpContext extends BaseContext {
|
|
60
|
-
query: Record<string, any>;
|
|
61
|
-
params: Record<string, string>;
|
|
62
|
-
body: Record<string, any>;
|
|
63
|
-
headers: IncomingHttpHeaders;
|
|
64
|
-
index?: number;
|
|
65
|
-
}
|
|
66
|
-
interface Error {
|
|
67
|
-
[ERROR_SYMBOL]: true;
|
|
68
|
-
status: number;
|
|
69
|
-
message: string;
|
|
70
|
-
description: string;
|
|
71
|
-
}
|
|
72
|
-
type ResOrErr<R> = {
|
|
73
|
-
[K in keyof R]: Awaited<R[K]> | Error;
|
|
74
|
-
};
|
|
75
|
-
type Res<T> = T extends {
|
|
76
|
-
toJSON(): infer R;
|
|
77
|
-
} ? R : T;
|
|
78
|
-
type Guard<C extends BaseContext = any> = ((ctx: C) => Promise<boolean> | boolean);
|
|
79
|
-
type Interceptor<C extends BaseContext = any> = (ctx: C) => (any | ((ret: any) => any));
|
|
80
|
-
type Pipe<C extends BaseContext = any> = (arg: {
|
|
81
|
-
arg: any;
|
|
82
|
-
option?: any;
|
|
83
|
-
key: string;
|
|
84
|
-
type: string;
|
|
85
|
-
index: number;
|
|
86
|
-
reflect: any;
|
|
87
|
-
}, ctx: C) => Promise<any>;
|
|
88
|
-
type Filter<C extends BaseContext = any, E extends Exception = any> = (err: E | Error, ctx?: C) => Error | any;
|
|
89
|
-
interface MetaData {
|
|
90
|
-
http?: {
|
|
91
|
-
type: RequestType;
|
|
92
|
-
route: string;
|
|
93
|
-
};
|
|
94
|
-
rpc?: {
|
|
95
|
-
type: string[];
|
|
96
|
-
isEvent: boolean;
|
|
97
|
-
};
|
|
98
|
-
define?: any;
|
|
99
|
-
header: Record<string, string>;
|
|
100
|
-
params: {
|
|
101
|
-
type: string;
|
|
102
|
-
index: number;
|
|
103
|
-
key: string;
|
|
104
|
-
pipe?: string;
|
|
105
|
-
pipeOpts?: any;
|
|
106
|
-
}[];
|
|
107
|
-
guards: string[];
|
|
108
|
-
filter?: string;
|
|
109
|
-
interceptors: string[];
|
|
110
|
-
plugins: string[];
|
|
111
|
-
method: string;
|
|
112
|
-
name: string;
|
|
113
|
-
tag: PropertyKey;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
declare function Injectable(): (target: any) => void;
|
|
118
|
-
declare const emitter: Emitter;
|
|
119
|
-
declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
|
|
120
|
-
http?: string;
|
|
121
|
-
rpc?: string;
|
|
122
|
-
}): Promise<{
|
|
123
|
-
moduleMap: Map<PropertyKey, any>;
|
|
124
|
-
meta: Meta[];
|
|
125
|
-
constructorMap: Map<any, any>;
|
|
126
|
-
add: (Module: Construct) => Promise<void>;
|
|
127
|
-
del: (tag: PropertyKey) => Promise<any>;
|
|
128
|
-
destroy: () => Promise<void>;
|
|
129
|
-
}>;
|
|
130
|
-
|
|
131
|
-
export { APP_SYMBOL as A, Exception as E, Factory as F, Injectable as I, Meta as M, P, RequestType as R, ToControllerMap as T, UNMOUNT_SYMBOL as U, Emitter as a, PickKeysByValue as b, PickFunc as c, MERGE_SYMBOL as d, emitter as e, MODULE_SYMBOL as f, META_SYMBOL as g, IS_DEV as h, IS_STRICT as i, IS_LOG_BAN as j, ERROR_SYMBOL as k, PS_FILE_RE as l, PS_IMPORT_RE as m };
|