phecda-server 7.0.0-alpha.10 → 7.0.0-alpha.12
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/bin/cli.mjs +3 -3
- package/dist/{chunk-G7JFKM2M.js → chunk-IJFIY6QN.js} +1 -9
- package/dist/{chunk-Z7NAAE4M.mjs → chunk-VX4BZEL7.mjs} +0 -8
- package/dist/{core-CUTbX_IS.d.ts → core-CDzIy2g0.d.ts} +1 -1
- package/dist/{core-DIfgUKIU.d.mts → core-jUg1HvYT.d.mts} +1 -1
- package/dist/helper.d.mts +2 -4
- package/dist/helper.d.ts +2 -4
- package/dist/helper.js +2 -4
- package/dist/helper.mjs +1 -3
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +18 -17
- package/dist/http/elysia/index.mjs +2 -1
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +17 -16
- package/dist/http/express/index.mjs +2 -1
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +17 -16
- package/dist/http/fastify/index.mjs +2 -1
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +18 -17
- package/dist/http/h3/index.mjs +2 -1
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +15 -14
- package/dist/http/hono/index.mjs +2 -1
- package/dist/http/hyper-express/index.d.mts +3 -3
- package/dist/http/hyper-express/index.d.ts +3 -3
- package/dist/http/hyper-express/index.js +16 -15
- package/dist/http/hyper-express/index.mjs +2 -1
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +17 -16
- package/dist/http/koa/index.mjs +2 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +19 -19
- package/dist/index.mjs +1 -1
- package/dist/{meta-CR-D39hQ.d.mts → meta-xvg6V7pH.d.mts} +2 -19
- package/dist/{meta-CR-D39hQ.d.ts → meta-xvg6V7pH.d.ts} +2 -19
- package/dist/rpc/bullmq/index.d.mts +4 -6
- package/dist/rpc/bullmq/index.d.ts +4 -6
- package/dist/rpc/bullmq/index.js +7 -75
- package/dist/rpc/bullmq/index.mjs +3 -71
- package/dist/rpc/kafka/index.d.mts +4 -9
- package/dist/rpc/kafka/index.d.ts +4 -9
- package/dist/rpc/kafka/index.js +7 -86
- package/dist/rpc/kafka/index.mjs +3 -82
- package/dist/rpc/nats/index.d.mts +4 -6
- package/dist/rpc/nats/index.d.ts +4 -6
- package/dist/rpc/nats/index.js +7 -67
- package/dist/rpc/nats/index.mjs +2 -62
- package/dist/rpc/rabbitmq/index.d.mts +4 -6
- package/dist/rpc/rabbitmq/index.d.ts +4 -6
- package/dist/rpc/rabbitmq/index.js +7 -73
- package/dist/rpc/rabbitmq/index.mjs +3 -69
- package/dist/rpc/redis/index.d.mts +4 -9
- package/dist/rpc/redis/index.d.ts +4 -9
- package/dist/rpc/redis/index.js +7 -74
- package/dist/rpc/redis/index.mjs +3 -70
- package/dist/test.d.mts +8 -4
- package/dist/test.d.ts +8 -4
- package/dist/types-6qaaUIKZ.d.mts +14 -0
- package/dist/{types-BF1TDbFV.d.ts → types-B-1OL-3P.d.ts} +1 -1
- package/dist/types-BtXOT5rI.d.ts +14 -0
- package/dist/{types-DYviSl5B.d.mts → types-Ctd6pLNE.d.mts} +1 -1
- package/package.json +2 -3
- package/register/loader.mjs +31 -22
- package/register/utils.mjs +26 -0
- package/dist/types-DYRu0vic.d.ts +0 -19
- package/dist/types-DqH1qA-q.d.mts +0 -19
package/dist/rpc/redis/index.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
var _chunkG7JFKM2Mjs = require('../../chunk-G7JFKM2M.js');
|
|
5
|
+
var _chunkIJFIY6QNjs = require('../../chunk-IJFIY6QN.js');
|
|
7
6
|
|
|
8
7
|
|
|
9
8
|
|
|
@@ -14,19 +13,19 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
|
14
13
|
var debug = _debug2.default.call(void 0, "phecda-server/redis");
|
|
15
14
|
function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
16
15
|
const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
|
|
17
|
-
const metaMap =
|
|
16
|
+
const metaMap = _chunkIJFIY6QNjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
18
17
|
const { controller, rpc, func, tag } = meta2.data;
|
|
19
18
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
20
19
|
debug(`register method "${func}" in module "${tag}"`);
|
|
21
20
|
return true;
|
|
22
21
|
}
|
|
23
22
|
});
|
|
24
|
-
|
|
23
|
+
_chunkIJFIY6QNjs.detectAopDep.call(void 0, meta, {
|
|
25
24
|
guards: globalGuards,
|
|
26
25
|
addons: globalAddons
|
|
27
26
|
}, "rpc");
|
|
28
27
|
const existQueue = /* @__PURE__ */ new Set();
|
|
29
|
-
|
|
28
|
+
_chunkIJFIY6QNjs.Context.applyAddons(globalAddons, {
|
|
30
29
|
pub,
|
|
31
30
|
sub
|
|
32
31
|
}, "redis");
|
|
@@ -55,12 +54,12 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
|
55
54
|
if (_ps !== 1) return;
|
|
56
55
|
const meta2 = metaMap.get(tag)[func];
|
|
57
56
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
58
|
-
const aop =
|
|
57
|
+
const aop = _chunkIJFIY6QNjs.Context.getAop(meta2, {
|
|
59
58
|
globalFilter,
|
|
60
59
|
globalGuards,
|
|
61
60
|
globalPipe
|
|
62
61
|
});
|
|
63
|
-
const context = new (0,
|
|
62
|
+
const context = new (0, _chunkIJFIY6QNjs.Context)({
|
|
64
63
|
type: "redis",
|
|
65
64
|
category: "rpc",
|
|
66
65
|
moduleMap,
|
|
@@ -99,71 +98,5 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
|
99
98
|
}
|
|
100
99
|
_chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
|
|
101
100
|
|
|
102
|
-
// src/rpc/redis/client.ts
|
|
103
|
-
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
104
|
-
async function createClient({ pub, sub }, controllers, opts) {
|
|
105
|
-
const ret = {};
|
|
106
|
-
let eventId = 1;
|
|
107
|
-
let eventCount = 0;
|
|
108
|
-
const emitter = new (0, _events2.default)();
|
|
109
|
-
const clientQueue = _chunkG7JFKM2Mjs.genClientQueue.call(void 0, _optionalChain([opts, 'optionalAccess', _2 => _2.key]));
|
|
110
|
-
await sub.subscribe(clientQueue);
|
|
111
|
-
for (const i in controllers) {
|
|
112
|
-
ret[i] = new Proxy(new controllers[i](), {
|
|
113
|
-
get(target, p) {
|
|
114
|
-
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
115
|
-
let { tag, queue, isEvent } = target[p]();
|
|
116
|
-
return async (...args) => {
|
|
117
|
-
if (!queue) queue = tag;
|
|
118
|
-
const id = `${eventId++}`;
|
|
119
|
-
pub.publish(queue, JSON.stringify({
|
|
120
|
-
_ps: 1,
|
|
121
|
-
args,
|
|
122
|
-
id,
|
|
123
|
-
queue: clientQueue,
|
|
124
|
-
tag,
|
|
125
|
-
func: p
|
|
126
|
-
}));
|
|
127
|
-
if (isEvent) return null;
|
|
128
|
-
return new Promise((resolve, reject) => {
|
|
129
|
-
if (_optionalChain([opts, 'optionalAccess', _3 => _3.max]) && eventCount >= opts.max) reject({
|
|
130
|
-
type: "exceeded"
|
|
131
|
-
});
|
|
132
|
-
let isEnd = false;
|
|
133
|
-
const timer = setTimeout(() => {
|
|
134
|
-
if (!isEnd) {
|
|
135
|
-
eventCount--;
|
|
136
|
-
emitter.off(id, listener);
|
|
137
|
-
reject({
|
|
138
|
-
type: "timeout"
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}, _optionalChain([opts, 'optionalAccess', _4 => _4.timeout]) || 5e3);
|
|
142
|
-
function listener(data, error) {
|
|
143
|
-
eventCount--;
|
|
144
|
-
isEnd = true;
|
|
145
|
-
clearTimeout(timer);
|
|
146
|
-
if (error) reject(data);
|
|
147
|
-
else resolve(data);
|
|
148
|
-
}
|
|
149
|
-
_chunk4LLLQOMFjs.__name.call(void 0, listener, "listener");
|
|
150
|
-
eventCount++;
|
|
151
|
-
emitter.once(id, listener);
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
sub.on("message", async (channel, msg) => {
|
|
158
|
-
if (channel === clientQueue && msg) {
|
|
159
|
-
const { data, id, error } = JSON.parse(msg);
|
|
160
|
-
emitter.emit(id, data, error);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
return ret;
|
|
164
|
-
}
|
|
165
|
-
_chunk4LLLQOMFjs.__name.call(void 0, createClient, "createClient");
|
|
166
|
-
|
|
167
|
-
|
|
168
101
|
|
|
169
|
-
exports.bind = bind;
|
|
102
|
+
exports.bind = bind;
|
package/dist/rpc/redis/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
3
|
createControllerMetaMap,
|
|
4
|
-
detectAopDep
|
|
5
|
-
|
|
6
|
-
} from "../../chunk-Z7NAAE4M.mjs";
|
|
4
|
+
detectAopDep
|
|
5
|
+
} from "../../chunk-VX4BZEL7.mjs";
|
|
7
6
|
import {
|
|
8
7
|
HMR,
|
|
9
8
|
__name
|
|
@@ -98,72 +97,6 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
|
|
|
98
97
|
});
|
|
99
98
|
}
|
|
100
99
|
__name(bind, "bind");
|
|
101
|
-
|
|
102
|
-
// src/rpc/redis/client.ts
|
|
103
|
-
import EventEmitter from "events";
|
|
104
|
-
async function createClient({ pub, sub }, controllers, opts) {
|
|
105
|
-
const ret = {};
|
|
106
|
-
let eventId = 1;
|
|
107
|
-
let eventCount = 0;
|
|
108
|
-
const emitter = new EventEmitter();
|
|
109
|
-
const clientQueue = genClientQueue(opts?.key);
|
|
110
|
-
await sub.subscribe(clientQueue);
|
|
111
|
-
for (const i in controllers) {
|
|
112
|
-
ret[i] = new Proxy(new controllers[i](), {
|
|
113
|
-
get(target, p) {
|
|
114
|
-
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
115
|
-
let { tag, queue, isEvent } = target[p]();
|
|
116
|
-
return async (...args) => {
|
|
117
|
-
if (!queue) queue = tag;
|
|
118
|
-
const id = `${eventId++}`;
|
|
119
|
-
pub.publish(queue, JSON.stringify({
|
|
120
|
-
_ps: 1,
|
|
121
|
-
args,
|
|
122
|
-
id,
|
|
123
|
-
queue: clientQueue,
|
|
124
|
-
tag,
|
|
125
|
-
func: p
|
|
126
|
-
}));
|
|
127
|
-
if (isEvent) return null;
|
|
128
|
-
return new Promise((resolve, reject) => {
|
|
129
|
-
if (opts?.max && eventCount >= opts.max) reject({
|
|
130
|
-
type: "exceeded"
|
|
131
|
-
});
|
|
132
|
-
let isEnd = false;
|
|
133
|
-
const timer = setTimeout(() => {
|
|
134
|
-
if (!isEnd) {
|
|
135
|
-
eventCount--;
|
|
136
|
-
emitter.off(id, listener);
|
|
137
|
-
reject({
|
|
138
|
-
type: "timeout"
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}, opts?.timeout || 5e3);
|
|
142
|
-
function listener(data, error) {
|
|
143
|
-
eventCount--;
|
|
144
|
-
isEnd = true;
|
|
145
|
-
clearTimeout(timer);
|
|
146
|
-
if (error) reject(data);
|
|
147
|
-
else resolve(data);
|
|
148
|
-
}
|
|
149
|
-
__name(listener, "listener");
|
|
150
|
-
eventCount++;
|
|
151
|
-
emitter.once(id, listener);
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
sub.on("message", async (channel, msg) => {
|
|
158
|
-
if (channel === clientQueue && msg) {
|
|
159
|
-
const { data, id, error } = JSON.parse(msg);
|
|
160
|
-
emitter.emit(id, data, error);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
return ret;
|
|
164
|
-
}
|
|
165
|
-
__name(createClient, "createClient");
|
|
166
100
|
export {
|
|
167
|
-
bind
|
|
168
|
-
createClient
|
|
101
|
+
bind
|
|
169
102
|
};
|
package/dist/test.d.mts
CHANGED
|
@@ -2,17 +2,21 @@ 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-
|
|
6
|
-
import {
|
|
5
|
+
import { F as Factory } from './core-jUg1HvYT.mjs';
|
|
6
|
+
import { e as CustomResponse } from './meta-xvg6V7pH.mjs';
|
|
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
|
}>;
|
|
11
15
|
type SuperTestRequest<T> = {
|
|
12
16
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
17
|
};
|
|
14
|
-
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "
|
|
18
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "set" | "key" | "use" | "on" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
|
|
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 };
|
package/dist/test.d.ts
CHANGED
|
@@ -2,17 +2,21 @@ 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-
|
|
6
|
-
import {
|
|
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
|
}>;
|
|
11
15
|
type SuperTestRequest<T> = {
|
|
12
16
|
[K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
|
|
13
17
|
};
|
|
14
|
-
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "
|
|
18
|
+
declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "set" | "key" | "use" | "on" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
|
|
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-
|
|
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-
|
|
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.
|
|
3
|
+
"version": "7.0.0-alpha.12",
|
|
4
4
|
"description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
|
|
5
5
|
"author": "fgsreally",
|
|
6
6
|
"license": "MIT",
|
|
@@ -148,7 +148,6 @@
|
|
|
148
148
|
"picocolors": "^1.0.0",
|
|
149
149
|
"reflect-metadata": "^0.1.13",
|
|
150
150
|
"ts-mixer": "^6.0.4",
|
|
151
|
-
"unconfig": "^0.6.0",
|
|
152
151
|
"phecda-core": "4.1.0-alpha.0"
|
|
153
152
|
},
|
|
154
153
|
"devDependencies": {
|
|
@@ -178,7 +177,7 @@
|
|
|
178
177
|
"nats": "^2.22.0",
|
|
179
178
|
"supertest": "^6.3.3",
|
|
180
179
|
"tsup": "^8.1.0",
|
|
181
|
-
"typescript": "^5.
|
|
180
|
+
"typescript": "^5.7.2",
|
|
182
181
|
"unimport": "^3.7.1"
|
|
183
182
|
},
|
|
184
183
|
"scripts": {
|
package/register/loader.mjs
CHANGED
|
@@ -3,18 +3,18 @@ import { writeFile } from 'fs/promises'
|
|
|
3
3
|
import {
|
|
4
4
|
basename,
|
|
5
5
|
dirname,
|
|
6
|
-
extname,
|
|
7
6
|
isAbsolute,
|
|
8
7
|
relative,
|
|
9
8
|
resolve as resolvePath,
|
|
10
9
|
} from 'path'
|
|
11
10
|
import { existsSync } from 'fs'
|
|
11
|
+
import { createRequire } from 'module'
|
|
12
12
|
import ts from 'typescript'
|
|
13
13
|
import chokidar from 'chokidar'
|
|
14
14
|
import Debug from 'debug'
|
|
15
|
-
import { loadConfig } from 'unconfig'
|
|
16
15
|
import { compile, genUnImportRet, handleClassTypes, slash } from './utils.mjs'
|
|
17
16
|
|
|
17
|
+
const require = createRequire(import.meta.url)
|
|
18
18
|
const debug = Debug('phecda-server/loader')
|
|
19
19
|
|
|
20
20
|
const isLowVersion = parseFloat(process.version.slice(1)) < 18.19
|
|
@@ -72,16 +72,17 @@ export async function initialize(data) {
|
|
|
72
72
|
|
|
73
73
|
debug('read config...')
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
config = require(configPath)
|
|
76
|
+
// const unconfigRet = await loadConfig({
|
|
77
|
+
// sources: [
|
|
78
|
+
// {
|
|
79
|
+
// files: configPath,
|
|
80
|
+
// extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json', ''],
|
|
81
|
+
// },
|
|
82
|
+
// ],
|
|
83
|
+
// merge: false,
|
|
84
|
+
// })
|
|
85
|
+
// config = unconfigRet.config
|
|
85
86
|
if (!config.virtualFile)
|
|
86
87
|
config.virtualFile = {}
|
|
87
88
|
if (!config.paths)
|
|
@@ -170,14 +171,14 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
170
171
|
}
|
|
171
172
|
// url import
|
|
172
173
|
// it seems useless
|
|
173
|
-
if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
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
|
+
// }
|
|
181
182
|
|
|
182
183
|
// hmr import
|
|
183
184
|
if (
|
|
@@ -201,7 +202,7 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
201
202
|
moduleResolutionCache,
|
|
202
203
|
)
|
|
203
204
|
|
|
204
|
-
// import
|
|
205
|
+
// import among files in local project
|
|
205
206
|
if (
|
|
206
207
|
resolvedModule
|
|
207
208
|
&& !resolvedModule.resolvedFileName.includes('/node_modules/')
|
|
@@ -253,6 +254,12 @@ export const load = async (url, context, nextLoad) => {
|
|
|
253
254
|
}
|
|
254
255
|
}
|
|
255
256
|
|
|
257
|
+
let mode
|
|
258
|
+
if (context.importAttributes.ps) {
|
|
259
|
+
mode = context.importAttributes.ps
|
|
260
|
+
delete context.importAttributes.ps
|
|
261
|
+
}
|
|
262
|
+
|
|
256
263
|
url = url.split('?')[0]
|
|
257
264
|
if (
|
|
258
265
|
!url.includes('/node_modules/')
|
|
@@ -262,7 +269,7 @@ export const load = async (url, context, nextLoad) => {
|
|
|
262
269
|
) {
|
|
263
270
|
watchFiles.add(url)
|
|
264
271
|
|
|
265
|
-
if (IS_DEV) {
|
|
272
|
+
if (IS_DEV && mode !== 'not-hmr') {
|
|
266
273
|
if (isModuleFileUrl(url)) {
|
|
267
274
|
port.postMessage(
|
|
268
275
|
JSON.stringify({
|
|
@@ -306,10 +313,12 @@ export const load = async (url, context, nextLoad) => {
|
|
|
306
313
|
|
|
307
314
|
const code
|
|
308
315
|
= typeof source === 'string' ? source : Buffer.from(source).toString()
|
|
316
|
+
|
|
309
317
|
const compiled = (await compile(code, url)).replace(/_ts_metadata\(\"design:paramtypes\"\,/g, '_ts_metadata("design:paramtypes",()=>')// handle cycle
|
|
310
318
|
|
|
311
319
|
if (unimportRet) {
|
|
312
320
|
const { injectImports } = unimportRet
|
|
321
|
+
|
|
313
322
|
return {
|
|
314
323
|
format: 'module',
|
|
315
324
|
source: (
|
package/register/utils.mjs
CHANGED
|
@@ -20,6 +20,32 @@ export async function compile(sourcecode, filename) {
|
|
|
20
20
|
emitDecoratorMetadata: true,
|
|
21
21
|
experimentalDecorators: true,
|
|
22
22
|
esModuleInterop: false,
|
|
23
|
+
swc: {
|
|
24
|
+
|
|
25
|
+
jsc: {
|
|
26
|
+
parser: {
|
|
27
|
+
syntax: "typescript",
|
|
28
|
+
importAttributes: true,
|
|
29
|
+
decorators: true,
|
|
30
|
+
tsx: false,
|
|
31
|
+
dynamicImport: true,
|
|
32
|
+
strictPropertyInitialization: false
|
|
33
|
+
},
|
|
34
|
+
experimental: {
|
|
35
|
+
keepImportAssertions: true
|
|
36
|
+
},
|
|
37
|
+
transform: {
|
|
38
|
+
legacyDecorator: true,
|
|
39
|
+
decoratorMetadata: true
|
|
40
|
+
}
|
|
41
|
+
// parser: {
|
|
42
|
+
// importAttributes: true
|
|
43
|
+
// },
|
|
44
|
+
// experimental: {
|
|
45
|
+
// keepImportAssertions: true
|
|
46
|
+
// }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
23
49
|
})
|
|
24
50
|
|
|
25
51
|
return injectInlineSourceMap({ code, map })
|
package/dist/types-DYRu0vic.d.ts
DELETED
|
@@ -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 };
|