phecda-server 7.0.0-alpha.9 → 7.0.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.
- package/assets/schema.json +12 -9
- package/bin/cli.mjs +95 -36
- package/dist/{chunk-5RBTN33A.js → chunk-4LLLQOMF.js} +10 -5
- package/dist/{chunk-7ZGYJ5OW.mjs → chunk-AIAO6SV6.mjs} +10 -34
- package/dist/{chunk-V5EYXVJT.js → chunk-DPPDWBYO.js} +53 -25
- package/dist/{chunk-CVPZWDXU.mjs → chunk-E7EAPAGM.mjs} +10 -20
- package/dist/{chunk-ODVWOXVB.mjs → chunk-MKRHYZCL.mjs} +30 -2
- package/dist/{chunk-FXTJ3BJ6.mjs → chunk-NQ55PA2X.mjs} +9 -4
- package/dist/{chunk-FX3LDQII.js → chunk-XKK2SQ7W.js} +60 -70
- package/dist/{chunk-KJUD2BKE.js → chunk-ZWPOWMZP.js} +25 -49
- package/dist/{core-D_cz0tKa.d.ts → core-DbqWh47p.d.mts} +3 -2
- package/dist/{core-BDkhrEyf.d.mts → core-Rq7BhPHE.d.ts} +3 -2
- package/dist/helper.d.mts +3 -5
- package/dist/helper.d.ts +3 -5
- package/dist/helper.js +3 -5
- package/dist/helper.mjs +2 -4
- package/dist/http/elysia/index.d.mts +4 -4
- package/dist/http/elysia/index.d.ts +4 -4
- package/dist/http/elysia/index.js +41 -40
- package/dist/http/elysia/index.mjs +4 -3
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +38 -37
- package/dist/http/express/index.mjs +3 -2
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +39 -38
- package/dist/http/fastify/index.mjs +4 -3
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +39 -38
- package/dist/http/h3/index.mjs +3 -2
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +35 -34
- package/dist/http/hono/index.mjs +3 -2
- 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 +36 -35
- package/dist/http/hyper-express/index.mjs +3 -2
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +38 -37
- package/dist/http/koa/index.mjs +3 -2
- package/dist/index.d.mts +76 -12
- package/dist/index.d.ts +76 -12
- package/dist/index.js +102 -49
- package/dist/index.mjs +66 -13
- package/dist/{meta-BX5jhe4Z.d.mts → meta-BoS1E-Nz.d.mts} +6 -23
- package/dist/{meta-BX5jhe4Z.d.ts → meta-BoS1E-Nz.d.ts} +6 -23
- package/dist/rpc/bullmq/index.d.mts +4 -6
- package/dist/rpc/bullmq/index.d.ts +4 -6
- package/dist/rpc/bullmq/index.js +12 -80
- package/dist/rpc/bullmq/index.mjs +4 -72
- package/dist/rpc/electron/index.d.mts +13 -0
- package/dist/rpc/electron/index.d.ts +13 -0
- package/dist/rpc/electron/index.js +72 -0
- package/dist/rpc/electron/index.mjs +72 -0
- package/dist/rpc/kafka/index.d.mts +4 -9
- package/dist/rpc/kafka/index.d.ts +4 -9
- package/dist/rpc/kafka/index.js +11 -90
- package/dist/rpc/kafka/index.mjs +4 -83
- package/dist/rpc/nats/index.d.mts +4 -6
- package/dist/rpc/nats/index.d.ts +4 -6
- package/dist/rpc/nats/index.js +12 -72
- package/dist/rpc/nats/index.mjs +3 -63
- package/dist/rpc/rabbitmq/index.d.mts +4 -6
- package/dist/rpc/rabbitmq/index.d.ts +4 -6
- package/dist/rpc/rabbitmq/index.js +13 -79
- package/dist/rpc/rabbitmq/index.mjs +4 -70
- package/dist/rpc/redis/index.d.mts +4 -9
- package/dist/rpc/redis/index.d.ts +4 -9
- package/dist/rpc/redis/index.js +11 -78
- package/dist/rpc/redis/index.mjs +4 -71
- package/dist/rpc/web-ext/index.d.mts +2 -0
- package/dist/rpc/web-ext/index.d.ts +2 -0
- package/dist/rpc/web-ext/index.js +1 -0
- package/dist/rpc/web-ext/index.mjs +0 -0
- package/dist/rpc/ws/index.d.mts +14 -0
- package/dist/rpc/ws/index.d.ts +14 -0
- package/dist/rpc/ws/index.js +73 -0
- package/dist/rpc/ws/index.mjs +73 -0
- package/dist/test.d.mts +7 -3
- package/dist/test.d.ts +7 -3
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/types-CInz3bD0.d.ts +14 -0
- package/dist/types-E-rqlg3-.d.mts +14 -0
- package/dist/{types-DKVhyZk_.d.mts → types-SCJZFCYt.d.mts} +1 -1
- package/dist/{types-CMeuFoyd.d.ts → types-xruyYmyu.d.ts} +1 -1
- package/package.json +24 -8
- package/register/export.mjs +30 -0
- package/register/index.mjs +2 -3
- package/register/loader.mjs +83 -90
- package/register/utils.mjs +36 -6
- package/assets/ps.json +0 -24
- package/assets/tsconfig.json +0 -21
- package/dist/types-B-rUM9Fm.d.mts +0 -19
- package/dist/types-MxxtkZXw.d.ts +0 -19
package/dist/index.mjs
CHANGED
|
@@ -6,9 +6,10 @@ import {
|
|
|
6
6
|
emitter,
|
|
7
7
|
phecdaNamespace,
|
|
8
8
|
useS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-AIAO6SV6.mjs";
|
|
10
10
|
import {
|
|
11
11
|
Addon,
|
|
12
|
+
ApiDoc,
|
|
12
13
|
Arg,
|
|
13
14
|
BaseParam,
|
|
14
15
|
Body,
|
|
@@ -21,6 +22,8 @@ import {
|
|
|
21
22
|
Guard,
|
|
22
23
|
Head,
|
|
23
24
|
Header,
|
|
25
|
+
ManyFiles,
|
|
26
|
+
OneFile,
|
|
24
27
|
Param,
|
|
25
28
|
Patch,
|
|
26
29
|
Pipe,
|
|
@@ -31,7 +34,7 @@ import {
|
|
|
31
34
|
Route,
|
|
32
35
|
Rpc,
|
|
33
36
|
Search
|
|
34
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-MKRHYZCL.mjs";
|
|
35
38
|
import {
|
|
36
39
|
BadGatewayException,
|
|
37
40
|
BadRequestException,
|
|
@@ -57,11 +60,12 @@ import {
|
|
|
57
60
|
addPipe,
|
|
58
61
|
defaultPipe,
|
|
59
62
|
joinUrl
|
|
60
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-E7EAPAGM.mjs";
|
|
61
64
|
import {
|
|
62
65
|
ERROR_SYMBOL,
|
|
63
66
|
IS_DEV,
|
|
64
67
|
IS_ONLY_GENERATE,
|
|
68
|
+
IS_PURE,
|
|
65
69
|
IS_STRICT,
|
|
66
70
|
LOG_LEVEL,
|
|
67
71
|
Mixin,
|
|
@@ -71,15 +75,14 @@ import {
|
|
|
71
75
|
log,
|
|
72
76
|
runMiddleware,
|
|
73
77
|
setLogger
|
|
74
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-NQ55PA2X.mjs";
|
|
75
79
|
|
|
76
80
|
// src/types.ts
|
|
77
|
-
var ResponseSymbol = Symbol("response");
|
|
78
81
|
var CustomResponse = class {
|
|
79
82
|
static {
|
|
80
83
|
__name(this, "CustomResponse");
|
|
81
84
|
}
|
|
82
|
-
|
|
85
|
+
_ps_response;
|
|
83
86
|
};
|
|
84
87
|
|
|
85
88
|
// src/modules/base.ts
|
|
@@ -248,7 +251,7 @@ var Generator = class {
|
|
|
248
251
|
return this._path || `.ps/${this.name.toLowerCase()}.js`;
|
|
249
252
|
}
|
|
250
253
|
async output(meta) {
|
|
251
|
-
await fse.outputFile(this.path, this.generateCode(meta
|
|
254
|
+
await fse.outputFile(this.path, this.generateCode(meta));
|
|
252
255
|
}
|
|
253
256
|
};
|
|
254
257
|
|
|
@@ -281,9 +284,9 @@ var RPCGenerator = class extends Generator {
|
|
|
281
284
|
`;
|
|
282
285
|
}
|
|
283
286
|
generateCode(meta) {
|
|
284
|
-
|
|
285
|
-
if (
|
|
286
|
-
}
|
|
287
|
+
meta.forEach(({ data }) => {
|
|
288
|
+
if (data.controller === "rpc") this.addMethod(data);
|
|
289
|
+
});
|
|
287
290
|
return this.getContent();
|
|
288
291
|
}
|
|
289
292
|
};
|
|
@@ -322,9 +325,54 @@ return ret
|
|
|
322
325
|
`;
|
|
323
326
|
}
|
|
324
327
|
generateCode(meta) {
|
|
325
|
-
|
|
326
|
-
if (
|
|
327
|
-
}
|
|
328
|
+
meta.forEach(({ data }) => {
|
|
329
|
+
if (data.controller === "http") this.addMethod(data);
|
|
330
|
+
});
|
|
331
|
+
return this.getContent();
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
// src/generator/openapi.ts
|
|
336
|
+
import { getMergedMeta } from "phecda-core";
|
|
337
|
+
var OpenAPIGenerator = class extends Generator {
|
|
338
|
+
static {
|
|
339
|
+
__name(this, "OpenAPIGenerator");
|
|
340
|
+
}
|
|
341
|
+
name = "OpenAPI";
|
|
342
|
+
paths = {};
|
|
343
|
+
getContent() {
|
|
344
|
+
return JSON.stringify({
|
|
345
|
+
openapi: "3.0.0",
|
|
346
|
+
info: {
|
|
347
|
+
title: "API Documentation",
|
|
348
|
+
version: "1.0.0",
|
|
349
|
+
description: "API documentation generated by phecda-server"
|
|
350
|
+
},
|
|
351
|
+
paths: this.paths
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
addMethod(args) {
|
|
355
|
+
const { http, tag, func } = args;
|
|
356
|
+
if (!http?.type) return;
|
|
357
|
+
const path = joinUrl(http.prefix, http.route);
|
|
358
|
+
if (!this.paths[path]) this.paths[path] = {};
|
|
359
|
+
const config = getMergedMeta(useS().getModel(tag), func).openapi;
|
|
360
|
+
this.paths[path][http.type] = {
|
|
361
|
+
summary: config.summary,
|
|
362
|
+
description: config.description,
|
|
363
|
+
tags: config.tags || [
|
|
364
|
+
tag
|
|
365
|
+
],
|
|
366
|
+
deprecated: config.deprecated,
|
|
367
|
+
parameters: config.parameters,
|
|
368
|
+
requestBody: config.requestBody,
|
|
369
|
+
responses: config.responses
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
generateCode(meta) {
|
|
373
|
+
meta.forEach(({ data }) => {
|
|
374
|
+
if (data.controller === "http") this.addMethod(data);
|
|
375
|
+
});
|
|
328
376
|
return this.getContent();
|
|
329
377
|
}
|
|
330
378
|
};
|
|
@@ -333,6 +381,7 @@ return ret
|
|
|
333
381
|
export * from "phecda-core";
|
|
334
382
|
export {
|
|
335
383
|
Addon,
|
|
384
|
+
ApiDoc,
|
|
336
385
|
Arg,
|
|
337
386
|
BadGatewayException,
|
|
338
387
|
BadRequestException,
|
|
@@ -360,12 +409,16 @@ export {
|
|
|
360
409
|
HttpBase,
|
|
361
410
|
IS_DEV,
|
|
362
411
|
IS_ONLY_GENERATE,
|
|
412
|
+
IS_PURE,
|
|
363
413
|
IS_STRICT,
|
|
364
414
|
InvalidInputException,
|
|
365
415
|
LOG_LEVEL,
|
|
416
|
+
ManyFiles,
|
|
366
417
|
Meta,
|
|
367
418
|
Mixin,
|
|
368
419
|
NotFoundException,
|
|
420
|
+
OneFile,
|
|
421
|
+
OpenAPIGenerator,
|
|
369
422
|
PAddon,
|
|
370
423
|
PExtension,
|
|
371
424
|
PFilter,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Events
|
|
1
|
+
import { Events } from 'phecda-core';
|
|
2
2
|
|
|
3
3
|
declare const ERROR_SYMBOL = "__PS_ERROR__";
|
|
4
4
|
declare const IS_DEV: boolean;
|
|
5
5
|
declare const IS_ONLY_GENERATE: boolean;
|
|
6
6
|
declare const IS_STRICT: boolean;
|
|
7
|
+
declare const IS_PURE: boolean;
|
|
7
8
|
declare const LOG_LEVEL: number;
|
|
8
9
|
declare enum PS_EXIT_CODE {
|
|
9
|
-
RELAUNCH =
|
|
10
|
-
|
|
10
|
+
RELAUNCH = 4171,
|
|
11
|
+
EXIT = 4172
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
interface Emitter {
|
|
@@ -17,20 +18,6 @@ interface Emitter {
|
|
|
17
18
|
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
18
19
|
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
19
20
|
}
|
|
20
|
-
type AnyFunction = (...args: any) => any;
|
|
21
|
-
type ParseInstance<Instance extends Record<string, AnyFunction>> = {
|
|
22
|
-
[Key in keyof Instance]: ToClientFn<Instance[Key]>;
|
|
23
|
-
};
|
|
24
|
-
type PickFuncKeys<Type> = {
|
|
25
|
-
[Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never;
|
|
26
|
-
}[keyof Type];
|
|
27
|
-
type ToClientMap<ControllerMap extends Record<string, Construct>> = {
|
|
28
|
-
[Key in keyof ControllerMap]: ToClientInstance<InstanceType<ControllerMap[Key]>>;
|
|
29
|
-
};
|
|
30
|
-
type ToClientInstance<Instance extends Record<string, any>> = ParseInstance<PickFunc<Instance>>;
|
|
31
|
-
type ToClientFn<Func extends AnyFunction> = (...p: Parameters<Func>) => Promise<BaseReturn<ReturnType<Func>>>;
|
|
32
|
-
type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
|
|
33
|
-
type OmitFunction<Instance> = Omit<Instance, PickFuncKeys<Instance>>;
|
|
34
21
|
interface BaseCtx {
|
|
35
22
|
meta: ControllerMeta;
|
|
36
23
|
moduleMap: Record<string, any>;
|
|
@@ -52,13 +39,9 @@ interface BaseError {
|
|
|
52
39
|
message: string;
|
|
53
40
|
description: string;
|
|
54
41
|
}
|
|
55
|
-
type BaseReturn<T> = Awaited<T> extends {
|
|
56
|
-
toJSON(): infer R;
|
|
57
|
-
} ? R : Awaited<T>;
|
|
58
42
|
type BaseRequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
59
|
-
declare const ResponseSymbol: unique symbol;
|
|
60
43
|
declare class CustomResponse<Value> {
|
|
61
|
-
|
|
44
|
+
_ps_response: Value;
|
|
62
45
|
}
|
|
63
46
|
type ExtractResponse<Class extends CustomResponse<any>> = Class extends CustomResponse<infer Value> ? Value : never;
|
|
64
47
|
|
|
@@ -104,4 +87,4 @@ interface ControllerMeta extends Meta {
|
|
|
104
87
|
data: ControllerMetaData;
|
|
105
88
|
}
|
|
106
89
|
|
|
107
|
-
export { type BaseCtx as B,
|
|
90
|
+
export { type BaseCtx as B, CustomResponse as C, type DefaultOptions as D, type Emitter as E, IS_DEV as I, LOG_LEVEL as L, Meta as M, PS_EXIT_CODE as P, type ServiceMetaData as S, type ControllerMeta as a, type ControllerMetaData as b, type BaseError as c, type BaseRequestType as d, type ExtractResponse as e, type MetaData as f, ERROR_SYMBOL as g, IS_ONLY_GENERATE as h, IS_STRICT as i, IS_PURE as j };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Events
|
|
1
|
+
import { Events } from 'phecda-core';
|
|
2
2
|
|
|
3
3
|
declare const ERROR_SYMBOL = "__PS_ERROR__";
|
|
4
4
|
declare const IS_DEV: boolean;
|
|
5
5
|
declare const IS_ONLY_GENERATE: boolean;
|
|
6
6
|
declare const IS_STRICT: boolean;
|
|
7
|
+
declare const IS_PURE: boolean;
|
|
7
8
|
declare const LOG_LEVEL: number;
|
|
8
9
|
declare enum PS_EXIT_CODE {
|
|
9
|
-
RELAUNCH =
|
|
10
|
-
|
|
10
|
+
RELAUNCH = 4171,
|
|
11
|
+
EXIT = 4172
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
interface Emitter {
|
|
@@ -17,20 +18,6 @@ interface Emitter {
|
|
|
17
18
|
removeAllListeners<N extends keyof Events>(eventName: N): void;
|
|
18
19
|
emit<N extends keyof Events>(eventName: N, param: Events[N]): void;
|
|
19
20
|
}
|
|
20
|
-
type AnyFunction = (...args: any) => any;
|
|
21
|
-
type ParseInstance<Instance extends Record<string, AnyFunction>> = {
|
|
22
|
-
[Key in keyof Instance]: ToClientFn<Instance[Key]>;
|
|
23
|
-
};
|
|
24
|
-
type PickFuncKeys<Type> = {
|
|
25
|
-
[Key in keyof Type]: Type[Key] extends (...args: any) => any ? (ReturnType<Type[Key]> extends CustomResponse<any> ? never : Key) : never;
|
|
26
|
-
}[keyof Type];
|
|
27
|
-
type ToClientMap<ControllerMap extends Record<string, Construct>> = {
|
|
28
|
-
[Key in keyof ControllerMap]: ToClientInstance<InstanceType<ControllerMap[Key]>>;
|
|
29
|
-
};
|
|
30
|
-
type ToClientInstance<Instance extends Record<string, any>> = ParseInstance<PickFunc<Instance>>;
|
|
31
|
-
type ToClientFn<Func extends AnyFunction> = (...p: Parameters<Func>) => Promise<BaseReturn<ReturnType<Func>>>;
|
|
32
|
-
type PickFunc<Instance> = Pick<Instance, PickFuncKeys<Instance>>;
|
|
33
|
-
type OmitFunction<Instance> = Omit<Instance, PickFuncKeys<Instance>>;
|
|
34
21
|
interface BaseCtx {
|
|
35
22
|
meta: ControllerMeta;
|
|
36
23
|
moduleMap: Record<string, any>;
|
|
@@ -52,13 +39,9 @@ interface BaseError {
|
|
|
52
39
|
message: string;
|
|
53
40
|
description: string;
|
|
54
41
|
}
|
|
55
|
-
type BaseReturn<T> = Awaited<T> extends {
|
|
56
|
-
toJSON(): infer R;
|
|
57
|
-
} ? R : Awaited<T>;
|
|
58
42
|
type BaseRequestType = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options';
|
|
59
|
-
declare const ResponseSymbol: unique symbol;
|
|
60
43
|
declare class CustomResponse<Value> {
|
|
61
|
-
|
|
44
|
+
_ps_response: Value;
|
|
62
45
|
}
|
|
63
46
|
type ExtractResponse<Class extends CustomResponse<any>> = Class extends CustomResponse<infer Value> ? Value : never;
|
|
64
47
|
|
|
@@ -104,4 +87,4 @@ interface ControllerMeta extends Meta {
|
|
|
104
87
|
data: ControllerMetaData;
|
|
105
88
|
}
|
|
106
89
|
|
|
107
|
-
export { type BaseCtx as B,
|
|
90
|
+
export { type BaseCtx as B, CustomResponse as C, type DefaultOptions as D, type Emitter as E, IS_DEV as I, LOG_LEVEL as L, Meta as M, PS_EXIT_CODE as P, type ServiceMetaData as S, type ControllerMeta as a, type ControllerMetaData as b, type BaseError as c, type BaseRequestType as d, type ExtractResponse as e, type MetaData as f, ERROR_SYMBOL as g, IS_ONLY_GENERATE as h, IS_STRICT as i, IS_PURE as j };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WorkerOptions, QueueOptions, Worker, Queue } from 'bullmq';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcCtx, a as RpcServerOptions
|
|
4
|
-
import { T as ToClientMap } from '../../meta-BX5jhe4Z.mjs';
|
|
2
|
+
import { F as Factory } from '../../core-DbqWh47p.mjs';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
|
|
5
4
|
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.mjs';
|
|
6
6
|
|
|
7
7
|
interface BullmqCtx extends RpcCtx {
|
|
8
8
|
type: 'bullmq';
|
|
@@ -16,6 +16,4 @@ declare function create({ moduleMap, meta }: Awaited<ReturnType<typeof Factory>>
|
|
|
16
16
|
queueMap: Record<string, Queue<any, any, string, any, any, string>>;
|
|
17
17
|
}>;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export { type BullmqCtx, type BullmqOptions, create, createClient };
|
|
19
|
+
export { type BullmqCtx, type BullmqOptions, create };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { WorkerOptions, QueueOptions, Worker, Queue } from 'bullmq';
|
|
2
|
-
import { F as Factory } from '../../core-
|
|
3
|
-
import { R as RpcCtx, a as RpcServerOptions
|
|
4
|
-
import { T as ToClientMap } from '../../meta-BX5jhe4Z.js';
|
|
2
|
+
import { F as Factory } from '../../core-Rq7BhPHE.js';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
|
|
5
4
|
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.js';
|
|
6
6
|
|
|
7
7
|
interface BullmqCtx extends RpcCtx {
|
|
8
8
|
type: 'bullmq';
|
|
@@ -16,6 +16,4 @@ declare function create({ moduleMap, meta }: Awaited<ReturnType<typeof Factory>>
|
|
|
16
16
|
queueMap: Record<string, Queue<any, any, string, any, any, string>>;
|
|
17
17
|
}>;
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export { type BullmqCtx, type BullmqOptions, create, createClient };
|
|
19
|
+
export { type BullmqCtx, type BullmqOptions, create };
|
package/dist/rpc/bullmq/index.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
var _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.js');
|
|
5
6
|
|
|
6
|
-
var _chunkFX3LDQIIjs = require('../../chunk-FX3LDQII.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
var _chunk5RBTN33Ajs = require('../../chunk-5RBTN33A.js');
|
|
9
|
+
var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
|
|
11
10
|
|
|
12
11
|
// src/rpc/bullmq/create.ts
|
|
13
12
|
var _bullmq = require('bullmq');
|
|
@@ -18,14 +17,14 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
18
17
|
const workerMap = {};
|
|
19
18
|
const queueMap = {};
|
|
20
19
|
const existQueue = /* @__PURE__ */ new Set();
|
|
21
|
-
const metaMap =
|
|
20
|
+
const metaMap = _chunkXKK2SQ7Wjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
22
21
|
const { controller, rpc, func, tag } = meta2.data;
|
|
23
22
|
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
24
23
|
debug(`register method "${func}" in module "${tag}"`);
|
|
25
24
|
return true;
|
|
26
25
|
}
|
|
27
26
|
});
|
|
28
|
-
|
|
27
|
+
_chunkXKK2SQ7Wjs.detectAopDep.call(void 0, meta, {
|
|
29
28
|
guards: globalGuards
|
|
30
29
|
}, "rpc");
|
|
31
30
|
async function subscribeQueues() {
|
|
@@ -39,12 +38,12 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
39
38
|
if (existQueue.has(queue)) continue;
|
|
40
39
|
existQueue.add(queue);
|
|
41
40
|
workerMap[queue] = new (0, _bullmq.Worker)(queue, handleRequest, workerOpts);
|
|
42
|
-
|
|
41
|
+
_chunkXKK2SQ7Wjs.Context.applyAddons(addons, workerMap[queue], "bullmq");
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
|
-
|
|
46
|
+
_chunk4LLLQOMFjs.__name.call(void 0, subscribeQueues, "subscribeQueues");
|
|
48
47
|
async function handleRequest(job) {
|
|
49
48
|
const { data } = job;
|
|
50
49
|
const { tag, func, args, id, queue: clientQueue, _ps } = data;
|
|
@@ -53,12 +52,12 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
53
52
|
const meta2 = metaMap.get(tag)[func];
|
|
54
53
|
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
55
54
|
if (!isEvent && !(clientQueue in queueMap)) queueMap[clientQueue] = new (0, _bullmq.Queue)(clientQueue, queueOpts);
|
|
56
|
-
const aop =
|
|
55
|
+
const aop = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
|
|
57
56
|
globalFilter,
|
|
58
57
|
globalGuards,
|
|
59
58
|
globalPipe
|
|
60
59
|
});
|
|
61
|
-
const context = new (0,
|
|
60
|
+
const context = new (0, _chunkXKK2SQ7Wjs.Context)({
|
|
62
61
|
type: "bullmq",
|
|
63
62
|
category: "rpc",
|
|
64
63
|
moduleMap,
|
|
@@ -86,9 +85,9 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
86
85
|
}
|
|
87
86
|
});
|
|
88
87
|
}
|
|
89
|
-
|
|
88
|
+
_chunk4LLLQOMFjs.__name.call(void 0, handleRequest, "handleRequest");
|
|
90
89
|
subscribeQueues();
|
|
91
|
-
|
|
90
|
+
_chunk4LLLQOMFjs.HMR.call(void 0, async () => {
|
|
92
91
|
for (const i in workerMap) await workerMap[i].close(true);
|
|
93
92
|
for (const i in queueMap) await queueMap[i].close();
|
|
94
93
|
await subscribeQueues();
|
|
@@ -98,74 +97,7 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
98
97
|
queueMap
|
|
99
98
|
};
|
|
100
99
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// src/rpc/bullmq/client.ts
|
|
104
|
-
var _events = require('events');
|
|
105
|
-
|
|
106
|
-
async function createClient(controllers, opts = {}) {
|
|
107
|
-
let eventId = 1;
|
|
108
|
-
let eventCount = 0;
|
|
109
|
-
const { max, workerOpts, queueOpts, timeout, key } = opts;
|
|
110
|
-
const ret = {};
|
|
111
|
-
const emitter = new (0, _events.EventEmitter)();
|
|
112
|
-
const clientQueue = _chunkFX3LDQIIjs.genClientQueue.call(void 0, key);
|
|
113
|
-
const queueMap = {};
|
|
114
|
-
new (0, _bullmq.Worker)(clientQueue, async (job) => {
|
|
115
|
-
const { data, id, error } = job.data;
|
|
116
|
-
emitter.emit(id, data, error);
|
|
117
|
-
}, workerOpts);
|
|
118
|
-
for (const i in controllers) {
|
|
119
|
-
ret[i] = new Proxy(new controllers[i](), {
|
|
120
|
-
get(target, p) {
|
|
121
|
-
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
122
|
-
let { tag, queue, isEvent } = target[p]();
|
|
123
|
-
return async (...args) => {
|
|
124
|
-
if (!queue) queue = tag;
|
|
125
|
-
if (!(queue in queueMap)) queueMap[queue] = new (0, _bullmq.Queue)(queue, queueOpts);
|
|
126
|
-
const id = `${eventId++}`;
|
|
127
|
-
queueMap[queue].add(`${tag}-${p}`, {
|
|
128
|
-
_ps: 1,
|
|
129
|
-
id,
|
|
130
|
-
args,
|
|
131
|
-
tag,
|
|
132
|
-
queue: clientQueue,
|
|
133
|
-
func: p
|
|
134
|
-
});
|
|
135
|
-
if (isEvent) return null;
|
|
136
|
-
return new Promise((resolve, reject) => {
|
|
137
|
-
if (max && eventCount >= max) reject({
|
|
138
|
-
type: "exceeded"
|
|
139
|
-
});
|
|
140
|
-
let isEnd = false;
|
|
141
|
-
const timer = setTimeout(() => {
|
|
142
|
-
if (!isEnd) {
|
|
143
|
-
eventCount--;
|
|
144
|
-
emitter.off(id, listener);
|
|
145
|
-
reject({
|
|
146
|
-
type: "timeout"
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}, timeout || 5e3);
|
|
150
|
-
function listener(data, error) {
|
|
151
|
-
eventCount--;
|
|
152
|
-
isEnd = true;
|
|
153
|
-
clearTimeout(timer);
|
|
154
|
-
if (error) reject(data);
|
|
155
|
-
else resolve(data);
|
|
156
|
-
}
|
|
157
|
-
_chunk5RBTN33Ajs.__name.call(void 0, listener, "listener");
|
|
158
|
-
eventCount++;
|
|
159
|
-
emitter.once(id, listener);
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return ret;
|
|
166
|
-
}
|
|
167
|
-
_chunk5RBTN33Ajs.__name.call(void 0, createClient, "createClient");
|
|
168
|
-
|
|
100
|
+
_chunk4LLLQOMFjs.__name.call(void 0, create, "create");
|
|
169
101
|
|
|
170
102
|
|
|
171
|
-
exports.create = create;
|
|
103
|
+
exports.create = create;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Context,
|
|
3
3
|
createControllerMetaMap,
|
|
4
|
-
detectAopDep
|
|
5
|
-
|
|
6
|
-
} from "../../chunk-CVPZWDXU.mjs";
|
|
4
|
+
detectAopDep
|
|
5
|
+
} from "../../chunk-E7EAPAGM.mjs";
|
|
7
6
|
import {
|
|
8
7
|
HMR,
|
|
9
8
|
__name
|
|
10
|
-
} from "../../chunk-
|
|
9
|
+
} from "../../chunk-NQ55PA2X.mjs";
|
|
11
10
|
|
|
12
11
|
// src/rpc/bullmq/create.ts
|
|
13
12
|
import { Queue, Worker } from "bullmq";
|
|
@@ -99,73 +98,6 @@ async function create({ moduleMap, meta }, opts = {}) {
|
|
|
99
98
|
};
|
|
100
99
|
}
|
|
101
100
|
__name(create, "create");
|
|
102
|
-
|
|
103
|
-
// src/rpc/bullmq/client.ts
|
|
104
|
-
import { EventEmitter } from "events";
|
|
105
|
-
import { Queue as Queue2, Worker as Worker2 } from "bullmq";
|
|
106
|
-
async function createClient(controllers, opts = {}) {
|
|
107
|
-
let eventId = 1;
|
|
108
|
-
let eventCount = 0;
|
|
109
|
-
const { max, workerOpts, queueOpts, timeout, key } = opts;
|
|
110
|
-
const ret = {};
|
|
111
|
-
const emitter = new EventEmitter();
|
|
112
|
-
const clientQueue = genClientQueue(key);
|
|
113
|
-
const queueMap = {};
|
|
114
|
-
new Worker2(clientQueue, async (job) => {
|
|
115
|
-
const { data, id, error } = job.data;
|
|
116
|
-
emitter.emit(id, data, error);
|
|
117
|
-
}, workerOpts);
|
|
118
|
-
for (const i in controllers) {
|
|
119
|
-
ret[i] = new Proxy(new controllers[i](), {
|
|
120
|
-
get(target, p) {
|
|
121
|
-
if (typeof target[p] !== "function") throw new Error(`"${p}" in "${i}" is not an exposed rpc `);
|
|
122
|
-
let { tag, queue, isEvent } = target[p]();
|
|
123
|
-
return async (...args) => {
|
|
124
|
-
if (!queue) queue = tag;
|
|
125
|
-
if (!(queue in queueMap)) queueMap[queue] = new Queue2(queue, queueOpts);
|
|
126
|
-
const id = `${eventId++}`;
|
|
127
|
-
queueMap[queue].add(`${tag}-${p}`, {
|
|
128
|
-
_ps: 1,
|
|
129
|
-
id,
|
|
130
|
-
args,
|
|
131
|
-
tag,
|
|
132
|
-
queue: clientQueue,
|
|
133
|
-
func: p
|
|
134
|
-
});
|
|
135
|
-
if (isEvent) return null;
|
|
136
|
-
return new Promise((resolve, reject) => {
|
|
137
|
-
if (max && eventCount >= max) reject({
|
|
138
|
-
type: "exceeded"
|
|
139
|
-
});
|
|
140
|
-
let isEnd = false;
|
|
141
|
-
const timer = setTimeout(() => {
|
|
142
|
-
if (!isEnd) {
|
|
143
|
-
eventCount--;
|
|
144
|
-
emitter.off(id, listener);
|
|
145
|
-
reject({
|
|
146
|
-
type: "timeout"
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}, timeout || 5e3);
|
|
150
|
-
function listener(data, error) {
|
|
151
|
-
eventCount--;
|
|
152
|
-
isEnd = true;
|
|
153
|
-
clearTimeout(timer);
|
|
154
|
-
if (error) reject(data);
|
|
155
|
-
else resolve(data);
|
|
156
|
-
}
|
|
157
|
-
__name(listener, "listener");
|
|
158
|
-
eventCount++;
|
|
159
|
-
emitter.once(id, listener);
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
return ret;
|
|
166
|
-
}
|
|
167
|
-
__name(createClient, "createClient");
|
|
168
101
|
export {
|
|
169
|
-
create
|
|
170
|
-
createClient
|
|
102
|
+
create
|
|
171
103
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Electron from 'electron';
|
|
2
|
+
import { F as Factory } from '../../core-DbqWh47p.mjs';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-E-rqlg3-.mjs';
|
|
4
|
+
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.mjs';
|
|
6
|
+
|
|
7
|
+
interface ElectronCtx extends RpcCtx {
|
|
8
|
+
type: 'electron';
|
|
9
|
+
event: Electron.IpcMainEvent | Electron.IpcMainInvokeEvent;
|
|
10
|
+
}
|
|
11
|
+
declare function bind(IPC: Electron.IpcMain, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
|
|
12
|
+
|
|
13
|
+
export { type ElectronCtx, bind };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Electron from 'electron';
|
|
2
|
+
import { F as Factory } from '../../core-Rq7BhPHE.js';
|
|
3
|
+
import { R as RpcCtx, a as RpcServerOptions } from '../../types-CInz3bD0.js';
|
|
4
|
+
import 'phecda-core';
|
|
5
|
+
import '../../meta-BoS1E-Nz.js';
|
|
6
|
+
|
|
7
|
+
interface ElectronCtx extends RpcCtx {
|
|
8
|
+
type: 'electron';
|
|
9
|
+
event: Electron.IpcMainEvent | Electron.IpcMainInvokeEvent;
|
|
10
|
+
}
|
|
11
|
+
declare function bind(IPC: Electron.IpcMain, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, opts?: RpcServerOptions): void;
|
|
12
|
+
|
|
13
|
+
export { type ElectronCtx, bind };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
var _chunkXKK2SQ7Wjs = require('../../chunk-XKK2SQ7W.js');
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
|
|
9
|
+
|
|
10
|
+
// src/rpc/electron/bind.ts
|
|
11
|
+
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
12
|
+
var debug = _debug2.default.call(void 0, "phecda-server/electron");
|
|
13
|
+
function bind(IPC, { moduleMap, meta }, opts = {}) {
|
|
14
|
+
const { globalGuards, globalFilter, globalPipe, globalAddons = [] } = opts;
|
|
15
|
+
const metaMap = _chunkXKK2SQ7Wjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
|
|
16
|
+
const { controller, rpc, func, tag } = meta2.data;
|
|
17
|
+
if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
|
|
18
|
+
debug(`register method "${func}" in module "${tag}"`);
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
_chunkXKK2SQ7Wjs.detectAopDep.call(void 0, meta, {
|
|
23
|
+
guards: globalGuards,
|
|
24
|
+
addons: globalAddons
|
|
25
|
+
}, "rpc");
|
|
26
|
+
IPC.handle("phecda-server:invoke", callback);
|
|
27
|
+
IPC.on("phecda-server:send", callback);
|
|
28
|
+
async function callback(event, data) {
|
|
29
|
+
const { func, id, tag, _ps, args } = data || {};
|
|
30
|
+
debug(`invoke method "${func}" in module "${tag}"`);
|
|
31
|
+
if (_ps !== 1) return;
|
|
32
|
+
const meta2 = metaMap.get(tag)[func];
|
|
33
|
+
const { data: { rpc: { isEvent } = {} } } = meta2;
|
|
34
|
+
const aop = _chunkXKK2SQ7Wjs.Context.getAop(meta2, {
|
|
35
|
+
globalFilter,
|
|
36
|
+
globalGuards,
|
|
37
|
+
globalPipe
|
|
38
|
+
});
|
|
39
|
+
const context = new (0, _chunkXKK2SQ7Wjs.Context)({
|
|
40
|
+
type: "electron",
|
|
41
|
+
category: "rpc",
|
|
42
|
+
moduleMap,
|
|
43
|
+
meta: meta2,
|
|
44
|
+
tag,
|
|
45
|
+
func,
|
|
46
|
+
args,
|
|
47
|
+
id,
|
|
48
|
+
isEvent,
|
|
49
|
+
queue: tag,
|
|
50
|
+
event
|
|
51
|
+
});
|
|
52
|
+
return await context.run(aop, (returnData) => {
|
|
53
|
+
if (!isEvent) return {
|
|
54
|
+
data: returnData,
|
|
55
|
+
id
|
|
56
|
+
};
|
|
57
|
+
}, (err) => {
|
|
58
|
+
if (!isEvent) {
|
|
59
|
+
return {
|
|
60
|
+
data: err,
|
|
61
|
+
error: true,
|
|
62
|
+
id
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
_chunk4LLLQOMFjs.__name.call(void 0, callback, "callback");
|
|
68
|
+
}
|
|
69
|
+
_chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
exports.bind = bind;
|