phecda-server 6.0.2 → 7.0.0-alpha.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 (83) hide show
  1. package/bin/cli.mjs +160 -157
  2. package/dist/{chunk-HDQAT2IM.mjs → chunk-5622RBNB.mjs} +118 -90
  3. package/dist/chunk-BGXSMOLX.js +265 -0
  4. package/dist/{chunk-F3W3NN7F.mjs → chunk-HMVLXNV3.mjs} +5 -14
  5. package/dist/{chunk-GHFSIZUO.js → chunk-J5CFUN4V.js} +18 -3
  6. package/dist/{chunk-XCND2QW3.js → chunk-MBCHNDAY.js} +27 -36
  7. package/dist/{chunk-WXFZZZRY.mjs → chunk-P75VKZJY.mjs} +101 -137
  8. package/dist/chunk-SW5IKE5H.js +503 -0
  9. package/dist/{chunk-UXD62LGG.mjs → chunk-WHJ5FALK.mjs} +17 -2
  10. package/dist/core-BIcUwV18.d.mts +47 -0
  11. package/dist/core-CYwEPfN4.d.ts +47 -0
  12. package/dist/helper.d.mts +4 -6
  13. package/dist/helper.d.ts +4 -6
  14. package/dist/helper.js +3 -3
  15. package/dist/helper.mjs +2 -2
  16. package/dist/{server → http}/elysia/index.d.mts +5 -5
  17. package/dist/{server → http}/elysia/index.d.ts +5 -5
  18. package/dist/{server → http}/elysia/index.js +80 -62
  19. package/dist/{server → http}/elysia/index.mjs +50 -32
  20. package/dist/{server → http}/express/index.d.mts +5 -5
  21. package/dist/{server → http}/express/index.d.ts +5 -5
  22. package/dist/{server → http}/express/index.js +71 -55
  23. package/dist/{server → http}/express/index.mjs +42 -26
  24. package/dist/{server → http}/fastify/index.d.mts +5 -5
  25. package/dist/{server → http}/fastify/index.d.ts +5 -5
  26. package/dist/{server → http}/fastify/index.js +72 -72
  27. package/dist/{server → http}/fastify/index.mjs +47 -47
  28. package/dist/{server → http}/h3/index.d.mts +5 -5
  29. package/dist/{server → http}/h3/index.d.ts +5 -5
  30. package/dist/http/h3/index.js +160 -0
  31. package/dist/{server → http}/h3/index.mjs +68 -62
  32. package/dist/{server → http}/hono/index.d.mts +5 -5
  33. package/dist/{server → http}/hono/index.d.ts +5 -5
  34. package/dist/{server → http}/hono/index.js +69 -54
  35. package/dist/{server → http}/hono/index.mjs +41 -26
  36. package/dist/{server → http}/hyper-express/index.d.mts +5 -5
  37. package/dist/{server → http}/hyper-express/index.d.ts +5 -5
  38. package/dist/{server → http}/hyper-express/index.js +69 -56
  39. package/dist/{server → http}/hyper-express/index.mjs +41 -28
  40. package/dist/{server → http}/koa/index.d.mts +5 -5
  41. package/dist/{server → http}/koa/index.d.ts +5 -5
  42. package/dist/{server → http}/koa/index.js +71 -55
  43. package/dist/{server → http}/koa/index.mjs +42 -26
  44. package/dist/index.d.mts +53 -41
  45. package/dist/index.d.ts +53 -41
  46. package/dist/index.js +62 -78
  47. package/dist/index.mjs +46 -62
  48. package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
  49. package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
  50. package/dist/rpc/bullmq/index.d.mts +6 -6
  51. package/dist/rpc/bullmq/index.d.ts +6 -6
  52. package/dist/rpc/bullmq/index.js +24 -24
  53. package/dist/rpc/bullmq/index.mjs +14 -14
  54. package/dist/rpc/kafka/index.d.mts +3 -3
  55. package/dist/rpc/kafka/index.d.ts +3 -3
  56. package/dist/rpc/kafka/index.js +25 -21
  57. package/dist/rpc/kafka/index.mjs +15 -11
  58. package/dist/rpc/nats/index.d.mts +3 -3
  59. package/dist/rpc/nats/index.d.ts +3 -3
  60. package/dist/rpc/nats/index.js +22 -21
  61. package/dist/rpc/nats/index.mjs +13 -12
  62. package/dist/rpc/rabbitmq/index.d.mts +3 -3
  63. package/dist/rpc/rabbitmq/index.d.ts +3 -3
  64. package/dist/rpc/rabbitmq/index.js +23 -22
  65. package/dist/rpc/rabbitmq/index.mjs +12 -11
  66. package/dist/rpc/redis/index.d.mts +3 -3
  67. package/dist/rpc/redis/index.d.ts +3 -3
  68. package/dist/rpc/redis/index.js +24 -20
  69. package/dist/rpc/redis/index.mjs +15 -11
  70. package/dist/test.d.mts +3 -3
  71. package/dist/test.d.ts +3 -3
  72. package/dist/test.js +6 -6
  73. package/dist/test.mjs +2 -2
  74. package/dist/{types-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
  75. package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
  76. package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
  77. package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
  78. package/package.json +24 -24
  79. package/dist/chunk-7SYPUIBY.js +0 -539
  80. package/dist/chunk-LYEZ6RGX.js +0 -237
  81. package/dist/core-2SNw8m2B.d.mts +0 -30
  82. package/dist/core-BmJJLUqj.d.ts +0 -30
  83. package/dist/server/h3/index.js +0 -154
@@ -1,237 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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
-
6
- var _chunkGHFSIZUOjs = require('./chunk-GHFSIZUO.js');
7
-
8
- // src/meta.ts
9
- var Meta = class {
10
- static {
11
- _chunkGHFSIZUOjs.__name.call(void 0, this, "Meta");
12
- }
13
-
14
-
15
- constructor(data, paramsType) {
16
- this.data = data;
17
- this.paramsType = paramsType;
18
- }
19
- };
20
-
21
- // src/core.ts
22
- require('reflect-metadata');
23
- var _events = require('events'); var _events2 = _interopRequireDefault(_events);
24
- var _phecdacore = require('phecda-core');
25
- var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
26
- var debug = _debug2.default.call(void 0, "phecda-server(createPhecda)");
27
- var emitter = new (0, _events2.default)();
28
- async function createPhecda(models, opts = {}) {
29
- const moduleMap = /* @__PURE__ */ new Map();
30
- const meta = [];
31
- const modelMap = /* @__PURE__ */ new WeakMap();
32
- const modelSet = /* @__PURE__ */ new WeakSet();
33
- const dependenceGraph = /* @__PURE__ */ new Map();
34
- const { parseModule = /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (module) => module, "parseModule"), parseMeta = /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (meta2) => meta2, "parseMeta"), generators } = opts;
35
- if (!_phecdacore.getInject.call(void 0, "watcher")) {
36
- _phecdacore.setInject.call(void 0, "watcher", ({ eventName, instance, property, options }) => {
37
- const fn = typeof instance[property] === "function" ? instance[property].bind(instance) : (v) => instance[property] = v;
38
- if (_optionalChain([options, 'optionalAccess', _ => _.once])) emitter.once(eventName, fn);
39
- else emitter.on(eventName, fn);
40
- return () => {
41
- emitter.off(eventName, fn);
42
- };
43
- });
44
- }
45
- async function del(tag) {
46
- if (!moduleMap.has(tag)) return;
47
- const module = moduleMap.get(tag);
48
- debug(`unmount module "${String(tag)}"`);
49
- await _phecdacore.invokeUnmount.call(void 0, module);
50
- debug(`del module "${String(tag)}"`);
51
- moduleMap.delete(tag);
52
- modelMap.delete(module);
53
- for (let i = meta.length - 1; i >= 0; i--) {
54
- if (meta[i].data.tag === tag) meta.splice(i, 1);
55
- }
56
- return module;
57
- }
58
- _chunkGHFSIZUOjs.__name.call(void 0, del, "del");
59
- async function destroy() {
60
- debug("destroy all");
61
- for (const [tag] of moduleMap) await del(tag);
62
- }
63
- _chunkGHFSIZUOjs.__name.call(void 0, destroy, "destroy");
64
- async function add(Model) {
65
- const tag = _phecdacore.getTag.call(void 0, Model);
66
- const oldInstance = await del(tag);
67
- const { module: newModule } = await buildDepModule(Model);
68
- if (oldInstance && dependenceGraph.has(tag)) {
69
- debug(`replace module "${String(tag)}"`);
70
- [
71
- ...dependenceGraph.get(tag)
72
- ].forEach((tag2) => {
73
- const module = moduleMap.get(tag2);
74
- for (const key in module) {
75
- if (module[key] === oldInstance) module[key] = newModule;
76
- }
77
- });
78
- }
79
- }
80
- _chunkGHFSIZUOjs.__name.call(void 0, add, "add");
81
- async function buildDepModule(Model) {
82
- const paramtypes = getParamTypes(Model);
83
- let module;
84
- const tag = _phecdacore.getTag.call(void 0, Model);
85
- if (moduleMap.has(tag)) {
86
- module = moduleMap.get(tag);
87
- if (!module) throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Model}`);
88
- if (modelMap.get(module) !== Model && !modelSet.has(Model)) {
89
- modelSet.add(Model);
90
- if (module instanceof Model) _chunkGHFSIZUOjs.log.call(void 0, `Module taged ${String(tag)} has been overridden`);
91
- else _chunkGHFSIZUOjs.log.call(void 0, `Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Model.name}"`, "warn");
92
- }
93
- return {
94
- module,
95
- tag
96
- };
97
- }
98
- moduleMap.set(tag, void 0);
99
- debug(`instantiate module "${String(tag)}"`);
100
- if (paramtypes) {
101
- const paramtypesInstances = [];
102
- for (const i in paramtypes) {
103
- const { module: sub, tag: subTag } = await buildDepModule(paramtypes[i]);
104
- paramtypesInstances[i] = sub;
105
- if (!dependenceGraph.has(subTag)) dependenceGraph.set(subTag, /* @__PURE__ */ new Set());
106
- dependenceGraph.get(subTag).add(tag);
107
- }
108
- module = parseModule(new Model(...paramtypesInstances));
109
- } else {
110
- module = parseModule(new Model());
111
- }
112
- meta.push(...getMetaFromInstance(module, tag, Model.name).map(parseMeta).filter((item) => !!item));
113
- debug(`init module "${String(tag)}"`);
114
- if (!_chunkGHFSIZUOjs.IS_ONLY_GENERATE) await _phecdacore.invokeInit.call(void 0, module);
115
- debug(`add module "${String(tag)}"`);
116
- moduleMap.set(tag, module);
117
- modelMap.set(module, Model);
118
- return {
119
- module,
120
- tag
121
- };
122
- }
123
- _chunkGHFSIZUOjs.__name.call(void 0, buildDepModule, "buildDepModule");
124
- for (const model of models) await buildDepModule(model);
125
- async function generateCode() {
126
- if (generators && _chunkGHFSIZUOjs.IS_HMR) {
127
- return Promise.all(generators.map((generator) => {
128
- debug(`generate "${generator.name}" code to ${generator.path}`);
129
- return generator.output(meta);
130
- }));
131
- }
132
- }
133
- _chunkGHFSIZUOjs.__name.call(void 0, generateCode, "generateCode");
134
- generateCode().then(() => {
135
- if (_chunkGHFSIZUOjs.IS_ONLY_GENERATE) process.exit(4);
136
- });
137
- if (_chunkGHFSIZUOjs.IS_HMR) {
138
- if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
139
- _optionalChain([globalThis, 'access', _2 => _2.__PS_HMR__, 'optionalAccess', _3 => _3.push, 'call', _4 => _4(async (files) => {
140
- debug("reload files ");
141
- for (const file of files) {
142
- const models2 = await Promise.resolve().then(() => _interopRequireWildcard(require(file)));
143
- for (const i in models2) {
144
- if (_phecdacore.isPhecda.call(void 0, models2[i])) await add(models2[i]);
145
- }
146
- }
147
- generateCode();
148
- })]);
149
- }
150
- return {
151
- moduleMap,
152
- modelMap,
153
- meta,
154
- add,
155
- del,
156
- destroy
157
- };
158
- }
159
- _chunkGHFSIZUOjs.__name.call(void 0, createPhecda, "createPhecda");
160
- var Factory = createPhecda;
161
- function getMetaFromInstance(instance, tag, name) {
162
- const propertyKeys = _phecdacore.getMetaKey.call(void 0, instance).filter((item) => typeof item === "string");
163
- const baseMeta = _phecdacore.getMergedMeta.call(void 0, instance, void 0);
164
- const ctxs = baseMeta.ctxs;
165
- return propertyKeys.filter((i) => typeof instance[i] === "function").map((i) => {
166
- const meta = _phecdacore.getMergedMeta.call(void 0, instance, i);
167
- const metaData = {
168
- ...meta,
169
- name,
170
- tag,
171
- func: i
172
- };
173
- if (baseMeta.controller) {
174
- if (typeof tag !== "string") _chunkGHFSIZUOjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
175
- metaData.controller = baseMeta.controller;
176
- metaData[baseMeta.controller] = {
177
- ...baseMeta[baseMeta.controller],
178
- ...meta[baseMeta.controller]
179
- };
180
- const params = _phecdacore.getMetaParams.call(void 0, instance, i).map((item) => _phecdacore.getMergedMeta.call(void 0, instance, i, item));
181
- params.forEach((item, index) => {
182
- if (!item.pipe) item.pipe = meta.pipe || baseMeta.pipe;
183
- if (!item.define) item.define = {};
184
- item.index = index;
185
- });
186
- metaData.ctxs = ctxs;
187
- metaData.params = params;
188
- metaData.filter = meta.filter || baseMeta.filter;
189
- metaData.define = {
190
- ...baseMeta.define,
191
- ...meta.define
192
- };
193
- for (const item of [
194
- "plugins",
195
- "guards",
196
- "interceptors"
197
- ]) {
198
- const set = new Set(baseMeta[item]);
199
- if (meta[item]) {
200
- meta[item].forEach((part) => {
201
- set.delete(part);
202
- set.add(part);
203
- });
204
- }
205
- metaData[item] = [
206
- ...set
207
- ];
208
- }
209
- }
210
- return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
211
- });
212
- }
213
- _chunkGHFSIZUOjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
214
- function deepFreeze(object) {
215
- Object.freeze(object);
216
- Object.getOwnPropertyNames(object).forEach((prop) => {
217
- if (object[prop] !== null && (typeof object[prop] === "object" || typeof object[prop] === "function") && !Object.isFrozen(object[prop])) deepFreeze(object[prop]);
218
- });
219
- return object;
220
- }
221
- _chunkGHFSIZUOjs.__name.call(void 0, deepFreeze, "deepFreeze");
222
- function getParamTypes(Model, key) {
223
- return Reflect.getMetadata("design:paramtypes", Model, key);
224
- }
225
- _chunkGHFSIZUOjs.__name.call(void 0, getParamTypes, "getParamTypes");
226
- function isObject(o) {
227
- return Object.prototype.toString.call(o) === "[object Object]";
228
- }
229
- _chunkGHFSIZUOjs.__name.call(void 0, isObject, "isObject");
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
- exports.Meta = Meta; exports.emitter = emitter; exports.createPhecda = createPhecda; exports.Factory = Factory; exports.isObject = isObject;
@@ -1,30 +0,0 @@
1
- import { Construct } from 'phecda-core';
2
- import { b as MetaData, M as Meta, E as Emitter } from './meta-KtfiBIde.mjs';
3
-
4
- declare abstract class Generator {
5
- private _path;
6
- constructor(path?: string);
7
- abstract name: string;
8
- get path(): string;
9
- abstract generateCode(meta: MetaData[]): string;
10
- output(meta: Meta[]): Promise<void>;
11
- }
12
-
13
- declare const emitter: Emitter;
14
- interface Options {
15
- parseModule?: (module: any) => any;
16
- parseMeta?: (meta: Meta) => Meta | null | undefined;
17
- generators?: Generator[];
18
- }
19
- declare function createPhecda(models: Construct[], opts?: Options): Promise<{
20
- moduleMap: Map<PropertyKey, any>;
21
- modelMap: WeakMap<any, Construct>;
22
- meta: Meta[];
23
- add: (Model: Construct) => Promise<void>;
24
- del: (tag: PropertyKey) => Promise<any>;
25
- destroy: () => Promise<void>;
26
- }>;
27
- declare const Factory: typeof createPhecda;
28
- declare function isObject(o: any): boolean;
29
-
30
- export { Factory as F, Generator as G, type Options as O, createPhecda as c, emitter as e, isObject as i };
@@ -1,30 +0,0 @@
1
- import { Construct } from 'phecda-core';
2
- import { b as MetaData, M as Meta, E as Emitter } from './meta-KtfiBIde.js';
3
-
4
- declare abstract class Generator {
5
- private _path;
6
- constructor(path?: string);
7
- abstract name: string;
8
- get path(): string;
9
- abstract generateCode(meta: MetaData[]): string;
10
- output(meta: Meta[]): Promise<void>;
11
- }
12
-
13
- declare const emitter: Emitter;
14
- interface Options {
15
- parseModule?: (module: any) => any;
16
- parseMeta?: (meta: Meta) => Meta | null | undefined;
17
- generators?: Generator[];
18
- }
19
- declare function createPhecda(models: Construct[], opts?: Options): Promise<{
20
- moduleMap: Map<PropertyKey, any>;
21
- modelMap: WeakMap<any, Construct>;
22
- meta: Meta[];
23
- add: (Model: Construct) => Promise<void>;
24
- del: (tag: PropertyKey) => Promise<any>;
25
- destroy: () => Promise<void>;
26
- }>;
27
- declare const Factory: typeof createPhecda;
28
- declare function isObject(o: any): boolean;
29
-
30
- export { Factory as F, Generator as G, type Options as O, createPhecda as c, emitter as e, isObject as i };
@@ -1,154 +0,0 @@
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
-
6
-
7
- var _chunk7SYPUIBYjs = require('../../chunk-7SYPUIBY.js');
8
-
9
-
10
- var _chunkGHFSIZUOjs = require('../../chunk-GHFSIZUO.js');
11
-
12
- // src/server/h3/bind.ts
13
- var _h3 = require('h3');
14
- var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
15
- var debug = _debug2.default.call(void 0, "phecda-server/h3");
16
- function bind(router, data, opts = {}) {
17
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
18
- const { moduleMap, meta } = data;
19
- const metaMap = _chunk7SYPUIBYjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
- const { controller, http, func, tag } = meta2.data;
21
- if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
22
- debug(`register method "${func}" in module "${tag}"`);
23
- return true;
24
- }
25
- });
26
- _chunk7SYPUIBYjs.detectAopDep.call(void 0, meta, {
27
- plugins: [
28
- ...globalPlugins,
29
- ...parallelPlugins
30
- ],
31
- guards: globalGuards,
32
- interceptors: globalInterceptors
33
- });
34
- registerRoute();
35
- async function registerRoute() {
36
- if (parallelRoute) {
37
- router.post(parallelRoute, _h3.eventHandler.call(void 0, {
38
- onRequest: _chunk7SYPUIBYjs.Context.usePlugin([
39
- ...globalPlugins,
40
- ...parallelPlugins
41
- ], "h3").map(_h3.defineRequestMiddleware),
42
- handler: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, async (event) => {
43
- const body = await _h3.readBody.call(void 0, event, {
44
- strict: true
45
- });
46
- async function errorHandler(e) {
47
- const error = await _chunk7SYPUIBYjs.Context.filterRecord.default(e);
48
- _h3.setResponseStatus.call(void 0, event, error.status);
49
- return error;
50
- }
51
- _chunkGHFSIZUOjs.__name.call(void 0, errorHandler, "errorHandler");
52
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk7SYPUIBYjs.BadRequestException)("data format should be an array"));
53
- try {
54
- return Promise.all(body.map((item, i) => {
55
- return new Promise(async (resolve) => {
56
- const { tag, func } = item;
57
- debug(`(parallel)invoke method "${func}" in module "${tag}"`);
58
- if (!metaMap.has(tag)) return resolve(await _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.BadRequestException)(`module "${tag}" doesn't exist`)));
59
- const meta2 = metaMap.get(tag)[func];
60
- if (!meta2) return resolve(await _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
61
- const { data: { params } } = meta2;
62
- const contextData = {
63
- type: "h3",
64
- index: i,
65
- event,
66
- meta: meta2,
67
- moduleMap,
68
- tag,
69
- func,
70
- parallel: true,
71
- app: router,
72
- ..._chunk7SYPUIBYjs.argToReq.call(void 0, params, item.args, _h3.getRequestHeaders.call(void 0, event)),
73
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _h3.getCookie.call(void 0, event, key), "getCookie"),
74
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => _h3.setCookie.call(void 0, event, key, value, opts2), "setCookie"),
75
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _h3.deleteCookie.call(void 0, event, key), "delCookie"),
76
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url, status) => _h3.sendRedirect.call(void 0, event, url, status), "redirect"),
77
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => _h3.setResponseHeaders.call(void 0, event, headers), "setResHeaders"),
78
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => _h3.setResponseStatus.call(void 0, event, code), "setResStatus"),
79
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => event.node.req, "getRequest"),
80
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => event.node.res, "getResponse")
81
- };
82
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
83
- context.run({
84
- globalGuards,
85
- globalInterceptors,
86
- globalFilter,
87
- globalPipe
88
- }, resolve, resolve);
89
- });
90
- }));
91
- } catch (e) {
92
- return errorHandler(e);
93
- }
94
- }, "handler")
95
- }));
96
- }
97
- for (const [tag, record] of metaMap) {
98
- for (const func in record) {
99
- const meta2 = metaMap.get(tag)[func];
100
- const { data: { http, params, plugins } } = meta2;
101
- if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
102
- const needBody = params.some((item) => item.type === "body");
103
- router[http.type](http.prefix + http.route, _h3.eventHandler.call(void 0, {
104
- onRequest: _chunk7SYPUIBYjs.Context.usePlugin([
105
- ...globalPlugins,
106
- ...plugins
107
- ], "h3").map(_h3.defineRequestMiddleware),
108
- handler: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, async (event) => {
109
- debug(`invoke method "${func}" in module "${tag}"`);
110
- const contextData = {
111
- type: "h3",
112
- meta: meta2,
113
- event,
114
- moduleMap,
115
- tag,
116
- func,
117
- headers: _h3.getRequestHeaders.call(void 0, event),
118
- params: _h3.getRouterParams.call(void 0, event),
119
- query: _h3.getQuery.call(void 0, event),
120
- app: router,
121
- body: needBody ? await _h3.readBody.call(void 0, event, {
122
- strict: true
123
- }) : void 0,
124
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _h3.getCookie.call(void 0, event, key), "getCookie"),
125
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => _h3.setCookie.call(void 0, event, key, value, opts2), "setCookie"),
126
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url) => _h3.sendRedirect.call(void 0, event, url), "redirect"),
127
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => _h3.setResponseHeaders.call(void 0, event, headers), "setResHeaders"),
128
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => _h3.setResponseStatus.call(void 0, event, code), "setResStatus"),
129
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _h3.deleteCookie.call(void 0, event, key), "delCookie"),
130
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => event.node.req, "getRequest"),
131
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => event.node.res, "getResponse")
132
- };
133
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
134
- _h3.setHeaders.call(void 0, event, http.headers || {});
135
- return context.run({
136
- globalGuards,
137
- globalInterceptors,
138
- globalFilter,
139
- globalPipe
140
- }, (returnData) => returnData, (err) => {
141
- _h3.setResponseStatus.call(void 0, event, err.status);
142
- return err;
143
- });
144
- }, "handler")
145
- }));
146
- }
147
- }
148
- }
149
- _chunkGHFSIZUOjs.__name.call(void 0, registerRoute, "registerRoute");
150
- }
151
- _chunkGHFSIZUOjs.__name.call(void 0, bind, "bind");
152
-
153
-
154
- exports.bind = bind;