@celerity-sdk/core 0.3.1 → 0.5.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.
- package/README.md +281 -47
- package/dist/index.cjs +2416 -313
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1050 -76
- package/dist/index.d.ts +1050 -76
- package/dist/index.js +2280 -240
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -37,15 +37,24 @@ __export(index_exports, {
|
|
|
37
37
|
BadGatewayException: () => BadGatewayException,
|
|
38
38
|
BadRequestException: () => BadRequestException,
|
|
39
39
|
Body: () => Body,
|
|
40
|
+
BucketEventType: () => import_types9.BucketEventType,
|
|
41
|
+
CONSUMER_HANDLER_METADATA: () => CONSUMER_HANDLER_METADATA,
|
|
42
|
+
CONSUMER_METADATA: () => CONSUMER_METADATA,
|
|
40
43
|
CONTROLLER_METADATA: () => CONTROLLER_METADATA,
|
|
41
44
|
CUSTOM_METADATA: () => CUSTOM_METADATA,
|
|
42
45
|
CelerityApplication: () => CelerityApplication,
|
|
43
46
|
CelerityFactory: () => CelerityFactory,
|
|
44
47
|
ConflictException: () => ConflictException,
|
|
48
|
+
ConnectionId: () => ConnectionId,
|
|
49
|
+
Consumer: () => Consumer,
|
|
50
|
+
ConsumerTraceContext: () => ConsumerTraceContext,
|
|
45
51
|
Container: () => Container,
|
|
46
52
|
Controller: () => Controller,
|
|
47
53
|
Cookies: () => Cookies,
|
|
54
|
+
DatastoreEventType: () => import_types9.DatastoreEventType,
|
|
48
55
|
Delete: () => Delete,
|
|
56
|
+
EventInput: () => EventInput,
|
|
57
|
+
EventType: () => EventType,
|
|
49
58
|
ForbiddenException: () => ForbiddenException,
|
|
50
59
|
GUARD_CUSTOM_METADATA: () => GUARD_CUSTOM_METADATA,
|
|
51
60
|
GUARD_PROTECTEDBY_METADATA: () => GUARD_PROTECTEDBY_METADATA,
|
|
@@ -59,21 +68,32 @@ __export(index_exports, {
|
|
|
59
68
|
Head: () => Head,
|
|
60
69
|
Headers: () => Headers,
|
|
61
70
|
HttpException: () => HttpException,
|
|
62
|
-
INJECT_METADATA: () => INJECT_METADATA,
|
|
71
|
+
INJECT_METADATA: () => import_common.INJECT_METADATA,
|
|
72
|
+
INVOKE_METADATA: () => INVOKE_METADATA,
|
|
63
73
|
Inject: () => Inject,
|
|
64
74
|
Injectable: () => Injectable,
|
|
65
75
|
InternalServerErrorException: () => InternalServerErrorException,
|
|
76
|
+
Invoke: () => Invoke,
|
|
77
|
+
InvokeContext: () => InvokeContext,
|
|
66
78
|
LAYER_METADATA: () => LAYER_METADATA,
|
|
67
79
|
MODULE_METADATA: () => MODULE_METADATA,
|
|
80
|
+
MessageBody: () => MessageBody,
|
|
81
|
+
MessageHandler: () => MessageHandler,
|
|
82
|
+
MessageId: () => MessageId,
|
|
83
|
+
Messages: () => Messages,
|
|
68
84
|
MethodNotAllowedException: () => MethodNotAllowedException,
|
|
69
85
|
Module: () => Module,
|
|
70
86
|
NotAcceptableException: () => NotAcceptableException,
|
|
71
87
|
NotFoundException: () => NotFoundException,
|
|
72
88
|
NotImplementedException: () => NotImplementedException,
|
|
89
|
+
OnConnect: () => OnConnect,
|
|
90
|
+
OnDisconnect: () => OnDisconnect,
|
|
91
|
+
OnMessage: () => OnMessage,
|
|
73
92
|
Options: () => Options,
|
|
74
93
|
PUBLIC_METADATA: () => PUBLIC_METADATA,
|
|
75
94
|
Param: () => Param,
|
|
76
95
|
Patch: () => Patch,
|
|
96
|
+
Payload: () => Payload,
|
|
77
97
|
Post: () => Post,
|
|
78
98
|
ProtectedBy: () => ProtectedBy,
|
|
79
99
|
Public: () => Public,
|
|
@@ -82,24 +102,52 @@ __export(index_exports, {
|
|
|
82
102
|
ROUTE_PATH_METADATA: () => ROUTE_PATH_METADATA,
|
|
83
103
|
RUNTIME_APP: () => RUNTIME_APP,
|
|
84
104
|
Req: () => Req,
|
|
105
|
+
RequestContext: () => RequestContext,
|
|
85
106
|
RequestId: () => RequestId,
|
|
107
|
+
RuntimeWebSocketSender: () => RuntimeWebSocketSender,
|
|
108
|
+
SCHEDULE_HANDLER_METADATA: () => SCHEDULE_HANDLER_METADATA,
|
|
109
|
+
ScheduleEventInputParam: () => ScheduleEventInput,
|
|
110
|
+
ScheduleExpression: () => ScheduleExpression,
|
|
111
|
+
ScheduleHandler: () => ScheduleHandler,
|
|
112
|
+
ScheduleId: () => ScheduleId,
|
|
113
|
+
ScheduleInput: () => ScheduleInput,
|
|
86
114
|
ServerlessApplication: () => ServerlessApplication,
|
|
87
115
|
ServiceUnavailableException: () => ServiceUnavailableException,
|
|
88
116
|
SetMetadata: () => SetMetadata,
|
|
117
|
+
SourceType: () => import_types9.SourceType,
|
|
89
118
|
TestingApplication: () => TestingApplication,
|
|
119
|
+
Token: () => Token,
|
|
90
120
|
TooManyRequestsException: () => TooManyRequestsException,
|
|
121
|
+
USE_RESOURCE_METADATA: () => import_common.USE_RESOURCE_METADATA,
|
|
91
122
|
UnauthorizedException: () => UnauthorizedException,
|
|
92
123
|
UnprocessableEntityException: () => UnprocessableEntityException,
|
|
93
124
|
UseLayer: () => UseLayer,
|
|
94
125
|
UseLayers: () => UseLayers,
|
|
126
|
+
UseResource: () => UseResource,
|
|
127
|
+
UseResources: () => UseResources,
|
|
128
|
+
Vendor: () => Vendor,
|
|
129
|
+
WEBSOCKET_CONTROLLER_METADATA: () => WEBSOCKET_CONTROLLER_METADATA,
|
|
130
|
+
WEBSOCKET_EVENT_METADATA: () => WEBSOCKET_EVENT_METADATA,
|
|
131
|
+
WebSocketController: () => WebSocketController,
|
|
132
|
+
WebSocketSender: () => import_types8.WebSocketSender,
|
|
95
133
|
bootstrap: () => bootstrap,
|
|
96
134
|
bootstrapForRuntime: () => bootstrapForRuntime,
|
|
97
135
|
buildModuleGraph: () => buildModuleGraph,
|
|
136
|
+
createConsumerHandler: () => createConsumerHandler,
|
|
137
|
+
createCustomHandler: () => createCustomHandler,
|
|
98
138
|
createDefaultSystemLayers: () => createDefaultSystemLayers,
|
|
139
|
+
createGuard: () => createGuard,
|
|
99
140
|
createHttpHandler: () => createHttpHandler,
|
|
141
|
+
createScheduleHandler: () => createScheduleHandler,
|
|
142
|
+
createWebSocketHandler: () => createWebSocketHandler,
|
|
100
143
|
discoverModule: () => discoverModule,
|
|
101
144
|
disposeLayers: () => disposeLayers,
|
|
102
|
-
|
|
145
|
+
executeConsumerPipeline: () => executeConsumerPipeline,
|
|
146
|
+
executeCustomPipeline: () => executeCustomPipeline,
|
|
147
|
+
executeGuardPipeline: () => executeGuardPipeline,
|
|
148
|
+
executeHttpPipeline: () => executeHttpPipeline,
|
|
149
|
+
executeSchedulePipeline: () => executeSchedulePipeline,
|
|
150
|
+
executeWebSocketPipeline: () => executeWebSocketPipeline,
|
|
103
151
|
flattenMultiValueRecord: () => flattenMultiValueRecord,
|
|
104
152
|
getClassDependencyTokens: () => getClassDependencyTokens,
|
|
105
153
|
getProviderDependencyTokens: () => getProviderDependencyTokens,
|
|
@@ -108,35 +156,56 @@ __export(index_exports, {
|
|
|
108
156
|
httpPatch: () => httpPatch,
|
|
109
157
|
httpPost: () => httpPost,
|
|
110
158
|
httpPut: () => httpPut,
|
|
159
|
+
mapConsumerEventInput: () => mapConsumerEventInput,
|
|
111
160
|
mapRuntimeRequest: () => mapRuntimeRequest,
|
|
161
|
+
mapScheduleEventInput: () => mapScheduleEventInput,
|
|
162
|
+
mapToNapiEventResult: () => mapToNapiEventResult,
|
|
112
163
|
mapToRuntimeResponse: () => mapToRuntimeResponse,
|
|
164
|
+
mapWebSocketMessage: () => mapWebSocketMessage,
|
|
165
|
+
mockConsumerEvent: () => mockConsumerEvent,
|
|
113
166
|
mockRequest: () => mockRequest,
|
|
167
|
+
mockScheduleEvent: () => mockScheduleEvent,
|
|
168
|
+
mockWebSocketMessage: () => mockWebSocketMessage,
|
|
114
169
|
registerModuleGraph: () => registerModuleGraph,
|
|
115
170
|
resolveHandlerByModuleRef: () => resolveHandlerByModuleRef,
|
|
171
|
+
routingKeyOf: () => routingKeyOf,
|
|
116
172
|
runLayerPipeline: () => runLayerPipeline,
|
|
173
|
+
scanConsumerHandlers: () => scanConsumerHandlers,
|
|
174
|
+
scanCustomHandlers: () => scanCustomHandlers,
|
|
175
|
+
scanHttpGuards: () => scanHttpGuards,
|
|
176
|
+
scanHttpHandlers: () => scanHttpHandlers,
|
|
177
|
+
scanModule: () => scanModule,
|
|
178
|
+
scanScheduleHandlers: () => scanScheduleHandlers,
|
|
179
|
+
scanWebSocketHandlers: () => scanWebSocketHandlers,
|
|
117
180
|
startRuntime: () => startRuntime,
|
|
118
181
|
tokenToString: () => tokenToString,
|
|
119
182
|
validate: () => validate
|
|
120
183
|
});
|
|
121
184
|
module.exports = __toCommonJS(index_exports);
|
|
122
|
-
var
|
|
185
|
+
var import_reflect_metadata27 = require("reflect-metadata");
|
|
123
186
|
|
|
124
187
|
// src/decorators/controller.ts
|
|
125
188
|
var import_reflect_metadata = require("reflect-metadata");
|
|
126
189
|
|
|
127
190
|
// src/metadata/constants.ts
|
|
128
|
-
var
|
|
129
|
-
var
|
|
130
|
-
var
|
|
131
|
-
var
|
|
132
|
-
var
|
|
133
|
-
var
|
|
134
|
-
var
|
|
135
|
-
var
|
|
136
|
-
var
|
|
137
|
-
var
|
|
138
|
-
var PUBLIC_METADATA = /* @__PURE__ */ Symbol("celerity:public");
|
|
139
|
-
var CUSTOM_METADATA = /* @__PURE__ */ Symbol("celerity:custom-metadata");
|
|
191
|
+
var import_common = require("@celerity-sdk/common");
|
|
192
|
+
var CONTROLLER_METADATA = /* @__PURE__ */ Symbol.for("celerity:controller");
|
|
193
|
+
var HTTP_METHOD_METADATA = /* @__PURE__ */ Symbol.for("celerity:http-method");
|
|
194
|
+
var ROUTE_PATH_METADATA = /* @__PURE__ */ Symbol.for("celerity:route-path");
|
|
195
|
+
var PARAM_METADATA = /* @__PURE__ */ Symbol.for("celerity:param");
|
|
196
|
+
var GUARD_PROTECTEDBY_METADATA = /* @__PURE__ */ Symbol.for("celerity:guard:protectedBy");
|
|
197
|
+
var GUARD_CUSTOM_METADATA = /* @__PURE__ */ Symbol.for("celerity:guard:custom");
|
|
198
|
+
var LAYER_METADATA = /* @__PURE__ */ Symbol.for("celerity:layer");
|
|
199
|
+
var MODULE_METADATA = /* @__PURE__ */ Symbol.for("celerity:module");
|
|
200
|
+
var INJECTABLE_METADATA = /* @__PURE__ */ Symbol.for("celerity:injectable");
|
|
201
|
+
var PUBLIC_METADATA = /* @__PURE__ */ Symbol.for("celerity:public");
|
|
202
|
+
var CUSTOM_METADATA = /* @__PURE__ */ Symbol.for("celerity:custom-metadata");
|
|
203
|
+
var WEBSOCKET_CONTROLLER_METADATA = /* @__PURE__ */ Symbol.for("celerity:websocket-controller");
|
|
204
|
+
var WEBSOCKET_EVENT_METADATA = /* @__PURE__ */ Symbol.for("celerity:websocket-event");
|
|
205
|
+
var CONSUMER_METADATA = /* @__PURE__ */ Symbol.for("celerity:consumer");
|
|
206
|
+
var CONSUMER_HANDLER_METADATA = /* @__PURE__ */ Symbol.for("celerity:consumer-handler");
|
|
207
|
+
var SCHEDULE_HANDLER_METADATA = /* @__PURE__ */ Symbol.for("celerity:schedule-handler");
|
|
208
|
+
var INVOKE_METADATA = /* @__PURE__ */ Symbol.for("celerity:invoke");
|
|
140
209
|
|
|
141
210
|
// src/decorators/controller.ts
|
|
142
211
|
function Controller(prefix) {
|
|
@@ -231,6 +300,10 @@ function Auth() {
|
|
|
231
300
|
return createParamDecorator("auth");
|
|
232
301
|
}
|
|
233
302
|
__name(Auth, "Auth");
|
|
303
|
+
function Token() {
|
|
304
|
+
return createParamDecorator("token");
|
|
305
|
+
}
|
|
306
|
+
__name(Token, "Token");
|
|
234
307
|
function Req() {
|
|
235
308
|
return createParamDecorator("request");
|
|
236
309
|
}
|
|
@@ -270,6 +343,9 @@ var import_reflect_metadata4 = require("reflect-metadata");
|
|
|
270
343
|
function Guard(name) {
|
|
271
344
|
return (target) => {
|
|
272
345
|
Reflect.defineMetadata(GUARD_CUSTOM_METADATA, name, target);
|
|
346
|
+
if (!Reflect.hasOwnMetadata(INJECTABLE_METADATA, target)) {
|
|
347
|
+
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
348
|
+
}
|
|
273
349
|
};
|
|
274
350
|
}
|
|
275
351
|
__name(Guard, "Guard");
|
|
@@ -324,8 +400,33 @@ function UseLayers(layers) {
|
|
|
324
400
|
}
|
|
325
401
|
__name(UseLayers, "UseLayers");
|
|
326
402
|
|
|
327
|
-
// src/decorators/
|
|
403
|
+
// src/decorators/resource.ts
|
|
328
404
|
var import_reflect_metadata6 = require("reflect-metadata");
|
|
405
|
+
function UseResource(...resourceNames) {
|
|
406
|
+
return (target, propertyKey, _descriptor) => {
|
|
407
|
+
if (propertyKey) {
|
|
408
|
+
const existing = Reflect.getOwnMetadata(import_common.USE_RESOURCE_METADATA, target, propertyKey) ?? [];
|
|
409
|
+
Reflect.defineMetadata(import_common.USE_RESOURCE_METADATA, [
|
|
410
|
+
...resourceNames,
|
|
411
|
+
...existing
|
|
412
|
+
], target, propertyKey);
|
|
413
|
+
} else {
|
|
414
|
+
const existing = Reflect.getOwnMetadata(import_common.USE_RESOURCE_METADATA, target) ?? [];
|
|
415
|
+
Reflect.defineMetadata(import_common.USE_RESOURCE_METADATA, [
|
|
416
|
+
...resourceNames,
|
|
417
|
+
...existing
|
|
418
|
+
], target);
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
__name(UseResource, "UseResource");
|
|
423
|
+
function UseResources(resourceNames) {
|
|
424
|
+
return UseResource(...resourceNames);
|
|
425
|
+
}
|
|
426
|
+
__name(UseResources, "UseResources");
|
|
427
|
+
|
|
428
|
+
// src/decorators/metadata.ts
|
|
429
|
+
var import_reflect_metadata7 = require("reflect-metadata");
|
|
329
430
|
function SetMetadata(key, value) {
|
|
330
431
|
return (target, propertyKey, _descriptor) => {
|
|
331
432
|
if (propertyKey) {
|
|
@@ -350,7 +451,7 @@ function Action(value) {
|
|
|
350
451
|
__name(Action, "Action");
|
|
351
452
|
|
|
352
453
|
// src/decorators/injectable.ts
|
|
353
|
-
var
|
|
454
|
+
var import_reflect_metadata8 = require("reflect-metadata");
|
|
354
455
|
function Injectable() {
|
|
355
456
|
return (target) => {
|
|
356
457
|
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
@@ -359,15 +460,15 @@ function Injectable() {
|
|
|
359
460
|
__name(Injectable, "Injectable");
|
|
360
461
|
function Inject(token) {
|
|
361
462
|
return (target, _propertyKey, parameterIndex) => {
|
|
362
|
-
const existing = Reflect.getOwnMetadata(INJECT_METADATA, target) ?? /* @__PURE__ */ new Map();
|
|
463
|
+
const existing = Reflect.getOwnMetadata(import_common.INJECT_METADATA, target) ?? /* @__PURE__ */ new Map();
|
|
363
464
|
existing.set(parameterIndex, token);
|
|
364
|
-
Reflect.defineMetadata(INJECT_METADATA, existing, target);
|
|
465
|
+
Reflect.defineMetadata(import_common.INJECT_METADATA, existing, target);
|
|
365
466
|
};
|
|
366
467
|
}
|
|
367
468
|
__name(Inject, "Inject");
|
|
368
469
|
|
|
369
470
|
// src/decorators/module.ts
|
|
370
|
-
var
|
|
471
|
+
var import_reflect_metadata9 = require("reflect-metadata");
|
|
371
472
|
function Module(metadata) {
|
|
372
473
|
return (target) => {
|
|
373
474
|
Reflect.defineMetadata(MODULE_METADATA, metadata, target);
|
|
@@ -375,6 +476,237 @@ function Module(metadata) {
|
|
|
375
476
|
}
|
|
376
477
|
__name(Module, "Module");
|
|
377
478
|
|
|
479
|
+
// src/decorators/websocket.ts
|
|
480
|
+
var import_reflect_metadata10 = require("reflect-metadata");
|
|
481
|
+
function WebSocketController() {
|
|
482
|
+
return (target) => {
|
|
483
|
+
Reflect.defineMetadata(WEBSOCKET_CONTROLLER_METADATA, true, target);
|
|
484
|
+
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
__name(WebSocketController, "WebSocketController");
|
|
488
|
+
function OnConnect() {
|
|
489
|
+
return (target, propertyKey, descriptor) => {
|
|
490
|
+
const meta = {
|
|
491
|
+
eventType: "connect",
|
|
492
|
+
route: "$connect"
|
|
493
|
+
};
|
|
494
|
+
Reflect.defineMetadata(WEBSOCKET_EVENT_METADATA, meta, target, propertyKey);
|
|
495
|
+
return descriptor;
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
__name(OnConnect, "OnConnect");
|
|
499
|
+
function OnMessage(route) {
|
|
500
|
+
return (target, propertyKey, descriptor) => {
|
|
501
|
+
const meta = {
|
|
502
|
+
eventType: "message",
|
|
503
|
+
route: route ?? "$default"
|
|
504
|
+
};
|
|
505
|
+
Reflect.defineMetadata(WEBSOCKET_EVENT_METADATA, meta, target, propertyKey);
|
|
506
|
+
return descriptor;
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
__name(OnMessage, "OnMessage");
|
|
510
|
+
function OnDisconnect() {
|
|
511
|
+
return (target, propertyKey, descriptor) => {
|
|
512
|
+
const meta = {
|
|
513
|
+
eventType: "disconnect",
|
|
514
|
+
route: "$disconnect"
|
|
515
|
+
};
|
|
516
|
+
Reflect.defineMetadata(WEBSOCKET_EVENT_METADATA, meta, target, propertyKey);
|
|
517
|
+
return descriptor;
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
__name(OnDisconnect, "OnDisconnect");
|
|
521
|
+
|
|
522
|
+
// src/decorators/websocket-params.ts
|
|
523
|
+
var import_reflect_metadata11 = require("reflect-metadata");
|
|
524
|
+
function createWsParamDecorator(type, schema) {
|
|
525
|
+
return (target, propertyKey, parameterIndex) => {
|
|
526
|
+
if (!propertyKey) return;
|
|
527
|
+
const existing = Reflect.getOwnMetadata(PARAM_METADATA, target, propertyKey) ?? [];
|
|
528
|
+
const meta = {
|
|
529
|
+
index: parameterIndex,
|
|
530
|
+
type
|
|
531
|
+
};
|
|
532
|
+
if (schema) meta.schema = schema;
|
|
533
|
+
existing.push(meta);
|
|
534
|
+
Reflect.defineMetadata(PARAM_METADATA, existing, target, propertyKey);
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
__name(createWsParamDecorator, "createWsParamDecorator");
|
|
538
|
+
function ConnectionId() {
|
|
539
|
+
return createWsParamDecorator("connectionId");
|
|
540
|
+
}
|
|
541
|
+
__name(ConnectionId, "ConnectionId");
|
|
542
|
+
function MessageBody(schema) {
|
|
543
|
+
return createWsParamDecorator("messageBody", schema);
|
|
544
|
+
}
|
|
545
|
+
__name(MessageBody, "MessageBody");
|
|
546
|
+
function MessageId() {
|
|
547
|
+
return createWsParamDecorator("messageId");
|
|
548
|
+
}
|
|
549
|
+
__name(MessageId, "MessageId");
|
|
550
|
+
function RequestContext() {
|
|
551
|
+
return createWsParamDecorator("requestContext");
|
|
552
|
+
}
|
|
553
|
+
__name(RequestContext, "RequestContext");
|
|
554
|
+
function EventType() {
|
|
555
|
+
return createWsParamDecorator("eventType");
|
|
556
|
+
}
|
|
557
|
+
__name(EventType, "EventType");
|
|
558
|
+
|
|
559
|
+
// src/decorators/consumer.ts
|
|
560
|
+
var import_reflect_metadata12 = require("reflect-metadata");
|
|
561
|
+
function Consumer(source) {
|
|
562
|
+
return (target) => {
|
|
563
|
+
const meta = {};
|
|
564
|
+
if (source !== void 0) meta.source = source;
|
|
565
|
+
Reflect.defineMetadata(CONSUMER_METADATA, meta, target);
|
|
566
|
+
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
__name(Consumer, "Consumer");
|
|
570
|
+
function MessageHandler(route) {
|
|
571
|
+
return (target, propertyKey) => {
|
|
572
|
+
const meta = {};
|
|
573
|
+
if (route !== void 0) meta.route = route;
|
|
574
|
+
Reflect.defineMetadata(CONSUMER_HANDLER_METADATA, meta, target, propertyKey);
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
__name(MessageHandler, "MessageHandler");
|
|
578
|
+
|
|
579
|
+
// src/decorators/consumer-params.ts
|
|
580
|
+
var import_reflect_metadata13 = require("reflect-metadata");
|
|
581
|
+
function createConsumerParamDecorator(type, schema) {
|
|
582
|
+
return (target, propertyKey, parameterIndex) => {
|
|
583
|
+
if (!propertyKey) return;
|
|
584
|
+
const existing = Reflect.getOwnMetadata(PARAM_METADATA, target, propertyKey) ?? [];
|
|
585
|
+
const meta = {
|
|
586
|
+
index: parameterIndex,
|
|
587
|
+
type
|
|
588
|
+
};
|
|
589
|
+
if (schema) meta.schema = schema;
|
|
590
|
+
existing.push(meta);
|
|
591
|
+
Reflect.defineMetadata(PARAM_METADATA, existing, target, propertyKey);
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
__name(createConsumerParamDecorator, "createConsumerParamDecorator");
|
|
595
|
+
function Messages(schema) {
|
|
596
|
+
return createConsumerParamDecorator("messages", schema);
|
|
597
|
+
}
|
|
598
|
+
__name(Messages, "Messages");
|
|
599
|
+
function EventInput() {
|
|
600
|
+
return createConsumerParamDecorator("consumerEvent");
|
|
601
|
+
}
|
|
602
|
+
__name(EventInput, "EventInput");
|
|
603
|
+
function Vendor() {
|
|
604
|
+
return createConsumerParamDecorator("consumerVendor");
|
|
605
|
+
}
|
|
606
|
+
__name(Vendor, "Vendor");
|
|
607
|
+
function ConsumerTraceContext() {
|
|
608
|
+
return createConsumerParamDecorator("consumerTraceContext");
|
|
609
|
+
}
|
|
610
|
+
__name(ConsumerTraceContext, "ConsumerTraceContext");
|
|
611
|
+
|
|
612
|
+
// src/decorators/schedule.ts
|
|
613
|
+
var import_reflect_metadata14 = require("reflect-metadata");
|
|
614
|
+
function isScheduleExpression(value) {
|
|
615
|
+
return value.startsWith("rate(") || value.startsWith("cron(");
|
|
616
|
+
}
|
|
617
|
+
__name(isScheduleExpression, "isScheduleExpression");
|
|
618
|
+
function parseScheduleArg(arg) {
|
|
619
|
+
if (typeof arg === "string") {
|
|
620
|
+
return isScheduleExpression(arg) ? {
|
|
621
|
+
schedule: arg
|
|
622
|
+
} : {
|
|
623
|
+
source: arg
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
const meta = {};
|
|
627
|
+
if (arg.source !== void 0) meta.source = arg.source;
|
|
628
|
+
if (arg.schedule !== void 0) meta.schedule = arg.schedule;
|
|
629
|
+
return meta;
|
|
630
|
+
}
|
|
631
|
+
__name(parseScheduleArg, "parseScheduleArg");
|
|
632
|
+
function ScheduleHandler(arg) {
|
|
633
|
+
return (target, propertyKey) => {
|
|
634
|
+
const meta = arg ? parseScheduleArg(arg) : {};
|
|
635
|
+
Reflect.defineMetadata(SCHEDULE_HANDLER_METADATA, meta, target, propertyKey);
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
__name(ScheduleHandler, "ScheduleHandler");
|
|
639
|
+
|
|
640
|
+
// src/decorators/schedule-params.ts
|
|
641
|
+
var import_reflect_metadata15 = require("reflect-metadata");
|
|
642
|
+
function createScheduleParamDecorator(type, schema) {
|
|
643
|
+
return (target, propertyKey, parameterIndex) => {
|
|
644
|
+
if (!propertyKey) return;
|
|
645
|
+
const existing = Reflect.getOwnMetadata(PARAM_METADATA, target, propertyKey) ?? [];
|
|
646
|
+
const meta = {
|
|
647
|
+
index: parameterIndex,
|
|
648
|
+
type
|
|
649
|
+
};
|
|
650
|
+
if (schema) meta.schema = schema;
|
|
651
|
+
existing.push(meta);
|
|
652
|
+
Reflect.defineMetadata(PARAM_METADATA, existing, target, propertyKey);
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
__name(createScheduleParamDecorator, "createScheduleParamDecorator");
|
|
656
|
+
function ScheduleInput(schema) {
|
|
657
|
+
return createScheduleParamDecorator("scheduleInput", schema);
|
|
658
|
+
}
|
|
659
|
+
__name(ScheduleInput, "ScheduleInput");
|
|
660
|
+
function ScheduleId() {
|
|
661
|
+
return createScheduleParamDecorator("scheduleId");
|
|
662
|
+
}
|
|
663
|
+
__name(ScheduleId, "ScheduleId");
|
|
664
|
+
function ScheduleExpression() {
|
|
665
|
+
return createScheduleParamDecorator("scheduleExpression");
|
|
666
|
+
}
|
|
667
|
+
__name(ScheduleExpression, "ScheduleExpression");
|
|
668
|
+
function ScheduleEventInput() {
|
|
669
|
+
return createScheduleParamDecorator("scheduleEvent");
|
|
670
|
+
}
|
|
671
|
+
__name(ScheduleEventInput, "ScheduleEventInput");
|
|
672
|
+
|
|
673
|
+
// src/decorators/invoke.ts
|
|
674
|
+
var import_reflect_metadata16 = require("reflect-metadata");
|
|
675
|
+
function Invoke(name) {
|
|
676
|
+
return (target, propertyKey) => {
|
|
677
|
+
const meta = {
|
|
678
|
+
name
|
|
679
|
+
};
|
|
680
|
+
Reflect.defineMetadata(INVOKE_METADATA, meta, target, propertyKey);
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
__name(Invoke, "Invoke");
|
|
684
|
+
|
|
685
|
+
// src/decorators/invoke-params.ts
|
|
686
|
+
var import_reflect_metadata17 = require("reflect-metadata");
|
|
687
|
+
function createInvokeParamDecorator(type, schema) {
|
|
688
|
+
return (target, propertyKey, parameterIndex) => {
|
|
689
|
+
if (!propertyKey) return;
|
|
690
|
+
const existing = Reflect.getOwnMetadata(PARAM_METADATA, target, propertyKey) ?? [];
|
|
691
|
+
const meta = {
|
|
692
|
+
index: parameterIndex,
|
|
693
|
+
type
|
|
694
|
+
};
|
|
695
|
+
if (schema) meta.schema = schema;
|
|
696
|
+
existing.push(meta);
|
|
697
|
+
Reflect.defineMetadata(PARAM_METADATA, existing, target, propertyKey);
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
__name(createInvokeParamDecorator, "createInvokeParamDecorator");
|
|
701
|
+
function Payload(schema) {
|
|
702
|
+
return createInvokeParamDecorator("payload", schema);
|
|
703
|
+
}
|
|
704
|
+
__name(Payload, "Payload");
|
|
705
|
+
function InvokeContext() {
|
|
706
|
+
return createInvokeParamDecorator("invokeContext");
|
|
707
|
+
}
|
|
708
|
+
__name(InvokeContext, "InvokeContext");
|
|
709
|
+
|
|
378
710
|
// src/errors/http-exception.ts
|
|
379
711
|
var HttpException = class extends Error {
|
|
380
712
|
static {
|
|
@@ -524,15 +856,48 @@ var GatewayTimeoutException = class extends HttpException {
|
|
|
524
856
|
};
|
|
525
857
|
|
|
526
858
|
// src/layers/validate.ts
|
|
859
|
+
function inferMode(schemas) {
|
|
860
|
+
if (schemas.consumerMessage) return "consumer";
|
|
861
|
+
if (schemas.scheduleInput) return "schedule";
|
|
862
|
+
if (schemas.customPayload) return "custom";
|
|
863
|
+
if (schemas.wsMessageBody) return "websocket";
|
|
864
|
+
return "http";
|
|
865
|
+
}
|
|
866
|
+
__name(inferMode, "inferMode");
|
|
527
867
|
var ValidationLayer = class ValidationLayer2 {
|
|
528
868
|
static {
|
|
529
869
|
__name(this, "ValidationLayer");
|
|
530
870
|
}
|
|
531
871
|
schemas;
|
|
872
|
+
mode;
|
|
532
873
|
constructor(schemas) {
|
|
533
874
|
this.schemas = schemas;
|
|
875
|
+
this.mode = inferMode(schemas);
|
|
876
|
+
}
|
|
877
|
+
supports(handlerType) {
|
|
878
|
+
return handlerType === this.mode;
|
|
534
879
|
}
|
|
535
880
|
async handle(context, next) {
|
|
881
|
+
switch (this.mode) {
|
|
882
|
+
case "http":
|
|
883
|
+
this.validateHttp(context);
|
|
884
|
+
break;
|
|
885
|
+
case "websocket":
|
|
886
|
+
this.validateWebSocket(context);
|
|
887
|
+
break;
|
|
888
|
+
case "consumer":
|
|
889
|
+
this.validateConsumer(context);
|
|
890
|
+
break;
|
|
891
|
+
case "schedule":
|
|
892
|
+
this.validateSchedule(context);
|
|
893
|
+
break;
|
|
894
|
+
case "custom":
|
|
895
|
+
this.validateCustom(context);
|
|
896
|
+
break;
|
|
897
|
+
}
|
|
898
|
+
return next();
|
|
899
|
+
}
|
|
900
|
+
validateHttp(context) {
|
|
536
901
|
const { request } = context;
|
|
537
902
|
if (this.schemas.body && request.textBody) {
|
|
538
903
|
try {
|
|
@@ -563,7 +928,49 @@ var ValidationLayer = class ValidationLayer2 {
|
|
|
563
928
|
throw new BadRequestException("Headers validation failed", formatError(error));
|
|
564
929
|
}
|
|
565
930
|
}
|
|
566
|
-
|
|
931
|
+
}
|
|
932
|
+
validateWebSocket(context) {
|
|
933
|
+
const schema = this.schemas.wsMessageBody;
|
|
934
|
+
if (!schema) return;
|
|
935
|
+
const body = context.message.jsonBody;
|
|
936
|
+
if (body === void 0) return;
|
|
937
|
+
context.metadata.set("validatedMessageBody", schema.parse(body));
|
|
938
|
+
}
|
|
939
|
+
validateConsumer(context) {
|
|
940
|
+
const schema = this.schemas.consumerMessage;
|
|
941
|
+
if (!schema) return;
|
|
942
|
+
const validated = [];
|
|
943
|
+
const failures = [];
|
|
944
|
+
for (const msg of context.event.messages) {
|
|
945
|
+
try {
|
|
946
|
+
const parsed = JSON.parse(msg.body);
|
|
947
|
+
const result = schema.parse(parsed);
|
|
948
|
+
validated.push({
|
|
949
|
+
...msg,
|
|
950
|
+
parsedBody: result
|
|
951
|
+
});
|
|
952
|
+
} catch (err) {
|
|
953
|
+
failures.push({
|
|
954
|
+
messageId: msg.messageId,
|
|
955
|
+
errorMessage: err instanceof Error ? err.message : String(err)
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
context.metadata.set("validatedMessages", validated);
|
|
960
|
+
if (failures.length > 0) {
|
|
961
|
+
context.metadata.set("validationFailures", failures);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
validateSchedule(context) {
|
|
965
|
+
const schema = this.schemas.scheduleInput;
|
|
966
|
+
if (!schema) return;
|
|
967
|
+
context.metadata.set("validatedInput", schema.parse(context.event.input));
|
|
968
|
+
}
|
|
969
|
+
validateCustom(context) {
|
|
970
|
+
const schema = this.schemas.customPayload;
|
|
971
|
+
if (!schema) return;
|
|
972
|
+
const raw = context.metadata.get("rawPayload");
|
|
973
|
+
context.metadata.set("validatedPayload", schema.parse(raw));
|
|
567
974
|
}
|
|
568
975
|
};
|
|
569
976
|
function formatError(error) {
|
|
@@ -584,9 +991,9 @@ __name(validate, "validate");
|
|
|
584
991
|
// src/layers/pipeline.ts
|
|
585
992
|
var import_debug = __toESM(require("debug"), 1);
|
|
586
993
|
var debug = (0, import_debug.default)("celerity:core:layers");
|
|
587
|
-
function runLayerPipeline(layers, context, handler) {
|
|
588
|
-
const resolved = layers.map((layer) => typeof layer === "function" ? new layer() : layer);
|
|
589
|
-
debug("runLayerPipeline: %d layers", resolved.length);
|
|
994
|
+
function runLayerPipeline(layers, context, handler, handlerType) {
|
|
995
|
+
const resolved = layers.map((layer) => typeof layer === "function" ? new layer() : layer).filter((layer) => !handlerType || !layer.supports || layer.supports(handlerType));
|
|
996
|
+
debug("runLayerPipeline: %d layers (handlerType=%s)", resolved.length, handlerType ?? "all");
|
|
590
997
|
let index = -1;
|
|
591
998
|
function dispatch(i) {
|
|
592
999
|
if (i <= index) {
|
|
@@ -607,6 +1014,32 @@ __name(runLayerPipeline, "runLayerPipeline");
|
|
|
607
1014
|
|
|
608
1015
|
// src/layers/system.ts
|
|
609
1016
|
var import_config = require("@celerity-sdk/config");
|
|
1017
|
+
var RESOURCE_LAYER_MAP = {
|
|
1018
|
+
datastore: {
|
|
1019
|
+
pkg: "@celerity-sdk/datastore",
|
|
1020
|
+
className: "DatastoreLayer"
|
|
1021
|
+
},
|
|
1022
|
+
bucket: {
|
|
1023
|
+
pkg: "@celerity-sdk/bucket",
|
|
1024
|
+
className: "ObjectStorageLayer"
|
|
1025
|
+
},
|
|
1026
|
+
queue: {
|
|
1027
|
+
pkg: "@celerity-sdk/queue",
|
|
1028
|
+
className: "QueueLayer"
|
|
1029
|
+
},
|
|
1030
|
+
topic: {
|
|
1031
|
+
pkg: "@celerity-sdk/topic",
|
|
1032
|
+
className: "TopicLayer"
|
|
1033
|
+
},
|
|
1034
|
+
cache: {
|
|
1035
|
+
pkg: "@celerity-sdk/cache",
|
|
1036
|
+
className: "CacheLayer"
|
|
1037
|
+
},
|
|
1038
|
+
sqlDatabase: {
|
|
1039
|
+
pkg: "@celerity-sdk/sql-database",
|
|
1040
|
+
className: "SqlDatabaseLayer"
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
610
1043
|
async function createDefaultSystemLayers() {
|
|
611
1044
|
const layers = [];
|
|
612
1045
|
try {
|
|
@@ -617,6 +1050,19 @@ async function createDefaultSystemLayers() {
|
|
|
617
1050
|
} catch {
|
|
618
1051
|
}
|
|
619
1052
|
layers.push(new import_config.ConfigLayer());
|
|
1053
|
+
const links = (0, import_config.captureResourceLinks)();
|
|
1054
|
+
const resourceTypes = (0, import_config.getResourceTypes)(links);
|
|
1055
|
+
for (const type of resourceTypes) {
|
|
1056
|
+
const entry = RESOURCE_LAYER_MAP[type];
|
|
1057
|
+
if (!entry) continue;
|
|
1058
|
+
try {
|
|
1059
|
+
const pkg = entry.pkg;
|
|
1060
|
+
const mod = await import(pkg);
|
|
1061
|
+
const LayerClass = mod[entry.className];
|
|
1062
|
+
layers.push(new LayerClass());
|
|
1063
|
+
} catch {
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
620
1066
|
return layers;
|
|
621
1067
|
}
|
|
622
1068
|
__name(createDefaultSystemLayers, "createDefaultSystemLayers");
|
|
@@ -659,11 +1105,11 @@ var HandlerMetadataStore = class {
|
|
|
659
1105
|
};
|
|
660
1106
|
|
|
661
1107
|
// src/di/container.ts
|
|
662
|
-
var
|
|
1108
|
+
var import_reflect_metadata19 = require("reflect-metadata");
|
|
663
1109
|
var import_debug2 = __toESM(require("debug"), 1);
|
|
664
1110
|
|
|
665
1111
|
// src/di/dependency-tokens.ts
|
|
666
|
-
var
|
|
1112
|
+
var import_reflect_metadata18 = require("reflect-metadata");
|
|
667
1113
|
function isClassProvider(p) {
|
|
668
1114
|
return "useClass" in p;
|
|
669
1115
|
}
|
|
@@ -674,7 +1120,7 @@ function isFactoryProvider(p) {
|
|
|
674
1120
|
__name(isFactoryProvider, "isFactoryProvider");
|
|
675
1121
|
function getClassDependencyTokens(target) {
|
|
676
1122
|
const paramTypes = Reflect.getMetadata("design:paramtypes", target) ?? [];
|
|
677
|
-
const injectOverrides = Reflect.getMetadata(INJECT_METADATA, target) ?? /* @__PURE__ */ new Map();
|
|
1123
|
+
const injectOverrides = Reflect.getMetadata(import_common.INJECT_METADATA, target) ?? /* @__PURE__ */ new Map();
|
|
678
1124
|
return paramTypes.map((paramType, index) => injectOverrides.get(index) ?? paramType);
|
|
679
1125
|
}
|
|
680
1126
|
__name(getClassDependencyTokens, "getClassDependencyTokens");
|
|
@@ -960,27 +1406,123 @@ var APP_CONFIG = /* @__PURE__ */ Symbol("celerity:app-config");
|
|
|
960
1406
|
var RUNTIME_APP = /* @__PURE__ */ Symbol("celerity:runtime-app");
|
|
961
1407
|
|
|
962
1408
|
// src/application/factory.ts
|
|
963
|
-
var
|
|
1409
|
+
var import_debug17 = __toESM(require("debug"), 1);
|
|
964
1410
|
|
|
965
1411
|
// src/bootstrap/bootstrap.ts
|
|
966
|
-
var
|
|
967
|
-
var
|
|
1412
|
+
var import_reflect_metadata26 = require("reflect-metadata");
|
|
1413
|
+
var import_debug10 = __toESM(require("debug"), 1);
|
|
968
1414
|
|
|
969
1415
|
// src/handlers/registry.ts
|
|
970
|
-
var
|
|
971
|
-
|
|
972
|
-
|
|
1416
|
+
var import_debug3 = __toESM(require("debug"), 1);
|
|
1417
|
+
|
|
1418
|
+
// src/handlers/routing.ts
|
|
1419
|
+
function routingKeyOf(handler) {
|
|
1420
|
+
switch (handler.type) {
|
|
1421
|
+
case "http":
|
|
1422
|
+
return `${handler.method} ${handler.path}`;
|
|
1423
|
+
case "websocket":
|
|
1424
|
+
return handler.route;
|
|
1425
|
+
case "consumer":
|
|
1426
|
+
return handler.handlerTag;
|
|
1427
|
+
case "schedule":
|
|
1428
|
+
return handler.handlerTag;
|
|
1429
|
+
case "custom":
|
|
1430
|
+
return handler.name;
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
__name(routingKeyOf, "routingKeyOf");
|
|
1434
|
+
|
|
1435
|
+
// src/handlers/registry.ts
|
|
1436
|
+
var debug3 = (0, import_debug3.default)("celerity:core:registry");
|
|
1437
|
+
var HandlerRegistry = class {
|
|
1438
|
+
static {
|
|
1439
|
+
__name(this, "HandlerRegistry");
|
|
1440
|
+
}
|
|
1441
|
+
byType = /* @__PURE__ */ new Map();
|
|
1442
|
+
exactLookup = /* @__PURE__ */ new Map();
|
|
1443
|
+
byId = /* @__PURE__ */ new Map();
|
|
1444
|
+
guards = /* @__PURE__ */ new Map();
|
|
1445
|
+
register(handler) {
|
|
1446
|
+
const list = this.byType.get(handler.type) ?? [];
|
|
1447
|
+
list.push(handler);
|
|
1448
|
+
this.byType.set(handler.type, list);
|
|
1449
|
+
if (handler.type !== "http") {
|
|
1450
|
+
this.exactLookup.set(`${handler.type}::${routingKeyOf(handler)}`, handler);
|
|
1451
|
+
}
|
|
1452
|
+
if (handler.id) {
|
|
1453
|
+
this.byId.set(handler.id, handler);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
getHandler(type, routingKey) {
|
|
1457
|
+
if (type === "http") return this.findHttpHandler(routingKey);
|
|
1458
|
+
const found = this.exactLookup.get(`${type}::${routingKey}`);
|
|
1459
|
+
debug3("getHandler %s %s \u2192 %s", type, routingKey, found ? "matched" : "not found");
|
|
1460
|
+
return found;
|
|
1461
|
+
}
|
|
1462
|
+
getHandlerById(type, id) {
|
|
1463
|
+
const handler = this.byId.get(id);
|
|
1464
|
+
if (handler && handler.type === type) {
|
|
1465
|
+
return handler;
|
|
1466
|
+
}
|
|
1467
|
+
debug3("getHandlerById %s %s \u2192 not found", type, id);
|
|
1468
|
+
return void 0;
|
|
1469
|
+
}
|
|
1470
|
+
getHandlersByType(type) {
|
|
1471
|
+
return this.byType.get(type) ?? [];
|
|
1472
|
+
}
|
|
1473
|
+
getAllHandlers() {
|
|
1474
|
+
const result = [];
|
|
1475
|
+
for (const list of this.byType.values()) result.push(...list);
|
|
1476
|
+
return result;
|
|
1477
|
+
}
|
|
1478
|
+
registerGuard(guard) {
|
|
1479
|
+
debug3("registerGuard: %s", guard.name);
|
|
1480
|
+
this.guards.set(guard.name, guard);
|
|
1481
|
+
}
|
|
1482
|
+
getGuard(name) {
|
|
1483
|
+
const found = this.guards.get(name);
|
|
1484
|
+
debug3("getGuard %s \u2192 %s", name, found ? "matched" : "not found");
|
|
1485
|
+
return found;
|
|
1486
|
+
}
|
|
1487
|
+
getAllGuards() {
|
|
1488
|
+
return [
|
|
1489
|
+
...this.guards.values()
|
|
1490
|
+
];
|
|
1491
|
+
}
|
|
1492
|
+
/**
|
|
1493
|
+
* HTTP routing uses path-pattern matching: `"GET /items/{id}"` matches `"GET /items/42"`.
|
|
1494
|
+
* The routing key format is `"METHOD path"` (e.g., `"GET /items/{id}"`).
|
|
1495
|
+
*/
|
|
1496
|
+
findHttpHandler(routingKey) {
|
|
1497
|
+
const spaceIdx = routingKey.indexOf(" ");
|
|
1498
|
+
if (spaceIdx < 0) return void 0;
|
|
1499
|
+
const method = routingKey.slice(0, spaceIdx);
|
|
1500
|
+
const path = routingKey.slice(spaceIdx + 1);
|
|
1501
|
+
const httpHandlers = this.byType.get("http") ?? [];
|
|
1502
|
+
const found = httpHandlers.find((h) => h.path !== void 0 && h.method !== void 0 && h.method === method && matchRoute(h.path, path));
|
|
1503
|
+
debug3("getHandler http %s \u2192 %s", routingKey, found ? "matched" : "not found");
|
|
1504
|
+
return found;
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
function matchRoute(pattern, actual) {
|
|
1508
|
+
const patternParts = pattern.split("/").filter(Boolean);
|
|
1509
|
+
const actualParts = actual.split("/").filter(Boolean);
|
|
1510
|
+
if (patternParts.length !== actualParts.length) return false;
|
|
1511
|
+
return patternParts.every((part, i) => part.startsWith("{") || part === actualParts[i]);
|
|
1512
|
+
}
|
|
1513
|
+
__name(matchRoute, "matchRoute");
|
|
973
1514
|
|
|
974
1515
|
// src/bootstrap/module-graph.ts
|
|
975
|
-
var
|
|
976
|
-
var
|
|
977
|
-
var
|
|
1516
|
+
var import_reflect_metadata20 = require("reflect-metadata");
|
|
1517
|
+
var import_debug4 = __toESM(require("debug"), 1);
|
|
1518
|
+
var import_common2 = require("@celerity-sdk/common");
|
|
1519
|
+
var debug4 = (0, import_debug4.default)("celerity:core:bootstrap");
|
|
978
1520
|
function buildModuleGraph(rootModule) {
|
|
979
1521
|
const graph = /* @__PURE__ */ new Map();
|
|
980
1522
|
const resolving = /* @__PURE__ */ new Set();
|
|
981
1523
|
function walk(moduleClass, importChain) {
|
|
982
1524
|
if (graph.has(moduleClass)) {
|
|
983
|
-
|
|
1525
|
+
debug4("walk %s \u2192 already visited", moduleClass.name);
|
|
984
1526
|
return;
|
|
985
1527
|
}
|
|
986
1528
|
if (resolving.has(moduleClass)) {
|
|
@@ -1001,6 +1543,7 @@ function buildModuleGraph(rootModule) {
|
|
|
1001
1543
|
imports: [],
|
|
1002
1544
|
controllers: [],
|
|
1003
1545
|
functionHandlers: [],
|
|
1546
|
+
guards: [],
|
|
1004
1547
|
providers: []
|
|
1005
1548
|
});
|
|
1006
1549
|
return;
|
|
@@ -1026,9 +1569,15 @@ function buildModuleGraph(rootModule) {
|
|
|
1026
1569
|
for (const controller of controllers) {
|
|
1027
1570
|
ownTokens.add(controller);
|
|
1028
1571
|
}
|
|
1572
|
+
const guards = metadata.guards ?? [];
|
|
1573
|
+
for (const guard of guards) {
|
|
1574
|
+
if (typeof guard === "function") {
|
|
1575
|
+
ownTokens.add(guard);
|
|
1576
|
+
}
|
|
1577
|
+
}
|
|
1029
1578
|
const exportTokens = new Set(metadata.exports ?? []);
|
|
1030
1579
|
resolving.delete(moduleClass);
|
|
1031
|
-
|
|
1580
|
+
debug4("walk %s: %d providers, %d controllers, %d guards, %d imports", moduleClass.name, providers.length, controllers.length, guards.length, imports.length);
|
|
1032
1581
|
graph.set(moduleClass, {
|
|
1033
1582
|
moduleClass,
|
|
1034
1583
|
ownTokens,
|
|
@@ -1036,6 +1585,7 @@ function buildModuleGraph(rootModule) {
|
|
|
1036
1585
|
imports,
|
|
1037
1586
|
controllers,
|
|
1038
1587
|
functionHandlers: metadata.functionHandlers ?? [],
|
|
1588
|
+
guards,
|
|
1039
1589
|
providers
|
|
1040
1590
|
});
|
|
1041
1591
|
}
|
|
@@ -1059,6 +1609,11 @@ function registerModuleGraph(graph, container) {
|
|
|
1059
1609
|
container.registerClass(controller);
|
|
1060
1610
|
}
|
|
1061
1611
|
}
|
|
1612
|
+
for (const guard of node.guards) {
|
|
1613
|
+
if (typeof guard === "function" && !container.has(guard)) {
|
|
1614
|
+
container.registerClass(guard);
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1062
1617
|
}
|
|
1063
1618
|
}
|
|
1064
1619
|
__name(registerModuleGraph, "registerModuleGraph");
|
|
@@ -1105,8 +1660,14 @@ function validateModuleGraph(graph, container) {
|
|
|
1105
1660
|
const depTokens = getClassDependencyTokens(controller);
|
|
1106
1661
|
checkDependencies(controller, depTokens, visibleTokens, node.moduleClass, graph, container, diagnostics);
|
|
1107
1662
|
}
|
|
1663
|
+
for (const guard of node.guards) {
|
|
1664
|
+
if (typeof guard === "function") {
|
|
1665
|
+
const depTokens = getClassDependencyTokens(guard);
|
|
1666
|
+
checkDependencies(guard, depTokens, visibleTokens, node.moduleClass, graph, container, diagnostics);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1108
1669
|
}
|
|
1109
|
-
|
|
1670
|
+
debug4("validateModuleGraph: %d modules, %d diagnostics", graph.size, diagnostics.length);
|
|
1110
1671
|
if (diagnostics.length > 0) {
|
|
1111
1672
|
const details = diagnostics.map((d) => ` ${d.message}`).join("\n");
|
|
1112
1673
|
throw new Error(`Module validation errors:
|
|
@@ -1143,6 +1704,7 @@ function checkDependencies(consumer, depTokens, visibleTokens, moduleClass, grap
|
|
|
1143
1704
|
checkDependencies(dep, adoptedDeps, visibleTokens, moduleClass, graph, container, diagnostics);
|
|
1144
1705
|
continue;
|
|
1145
1706
|
}
|
|
1707
|
+
if ((0, import_common2.isResourceLayerToken)(dep)) continue;
|
|
1146
1708
|
diagnostics.push({
|
|
1147
1709
|
type: "missing_dependency",
|
|
1148
1710
|
message: `${tokenToString(consumer)} in ${moduleClass.name} requires ${tokenToString(dep)} \u2014 no provider registered. Ensure the module providing it is included in your module's "imports" array, or register a provider for it directly.`
|
|
@@ -1160,139 +1722,171 @@ function findTokenOwner(token, graph) {
|
|
|
1160
1722
|
}
|
|
1161
1723
|
__name(findTokenOwner, "findTokenOwner");
|
|
1162
1724
|
|
|
1163
|
-
// src/handlers/
|
|
1164
|
-
var
|
|
1165
|
-
var
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
getHandlerById(id) {
|
|
1176
|
-
const found = this.handlers.find((h) => h.id !== void 0 && h.id === id);
|
|
1177
|
-
debug4("getHandlerById %s \u2192 %s", id, found ? "matched" : "not found");
|
|
1178
|
-
return found;
|
|
1179
|
-
}
|
|
1180
|
-
getAllHandlers() {
|
|
1181
|
-
return [
|
|
1182
|
-
...this.handlers
|
|
1183
|
-
];
|
|
1184
|
-
}
|
|
1185
|
-
async populateFromGraph(graph, container) {
|
|
1186
|
-
for (const [, node] of graph) {
|
|
1187
|
-
for (const controllerClass of node.controllers) {
|
|
1188
|
-
await this.registerClassHandler(controllerClass, container);
|
|
1189
|
-
}
|
|
1190
|
-
for (const fnHandler of node.functionHandlers) {
|
|
1191
|
-
this.registerFunctionHandler(fnHandler);
|
|
1192
|
-
}
|
|
1725
|
+
// src/handlers/scanners/http.ts
|
|
1726
|
+
var import_reflect_metadata21 = require("reflect-metadata");
|
|
1727
|
+
var import_debug5 = __toESM(require("debug"), 1);
|
|
1728
|
+
var import_common3 = require("@celerity-sdk/common");
|
|
1729
|
+
var debug5 = (0, import_debug5.default)("celerity:core:scanner:http");
|
|
1730
|
+
async function scanHttpHandlers(graph, container, registry) {
|
|
1731
|
+
for (const [, node] of graph) {
|
|
1732
|
+
for (const controllerClass of node.controllers) {
|
|
1733
|
+
await scanClassHandler(controllerClass, container, registry);
|
|
1734
|
+
}
|
|
1735
|
+
for (const fnHandler of node.functionHandlers) {
|
|
1736
|
+
scanFunctionHandler(fnHandler, registry);
|
|
1193
1737
|
}
|
|
1194
1738
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
const prototype = Object.getPrototypeOf(instance);
|
|
1205
|
-
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1206
|
-
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1207
|
-
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
1208
|
-
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
1209
|
-
for (const methodName of methods) {
|
|
1210
|
-
const method = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
|
|
1211
|
-
if (!method) continue;
|
|
1212
|
-
const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
|
|
1213
|
-
const fullPath = (0, import_common.joinHandlerPath)(controllerMeta.prefix ?? "", routePath);
|
|
1214
|
-
const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
|
|
1215
|
-
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
1216
|
-
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
1217
|
-
const isPublic = Reflect.getOwnMetadata(PUBLIC_METADATA, prototype, methodName) === true;
|
|
1218
|
-
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
1219
|
-
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
1220
|
-
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
1221
|
-
const layers = [
|
|
1222
|
-
...classLayers,
|
|
1223
|
-
...methodLayers
|
|
1224
|
-
];
|
|
1225
|
-
const validationSchemas = buildValidationSchemasFromParams(paramMetadata);
|
|
1226
|
-
if (validationSchemas) {
|
|
1227
|
-
layers.unshift(validate(validationSchemas));
|
|
1739
|
+
}
|
|
1740
|
+
__name(scanHttpHandlers, "scanHttpHandlers");
|
|
1741
|
+
async function scanHttpGuards(graph, container, registry) {
|
|
1742
|
+
for (const [, node] of graph) {
|
|
1743
|
+
for (const guard of node.guards) {
|
|
1744
|
+
if (typeof guard === "function") {
|
|
1745
|
+
await scanClassGuard(guard, container, registry);
|
|
1746
|
+
} else {
|
|
1747
|
+
scanFunctionGuard(guard, registry);
|
|
1228
1748
|
}
|
|
1229
|
-
debug4("registerClassHandler: %s %s (%s.%s)", method, fullPath, controllerClass.name, methodName);
|
|
1230
|
-
this.handlers.push({
|
|
1231
|
-
path: fullPath,
|
|
1232
|
-
method,
|
|
1233
|
-
protectedBy: [
|
|
1234
|
-
...classProtectedBy,
|
|
1235
|
-
...methodProtectedBy
|
|
1236
|
-
],
|
|
1237
|
-
layers,
|
|
1238
|
-
isPublic,
|
|
1239
|
-
paramMetadata,
|
|
1240
|
-
customMetadata: {
|
|
1241
|
-
...classCustomMetadata,
|
|
1242
|
-
...methodCustomMetadata
|
|
1243
|
-
},
|
|
1244
|
-
handlerFn: descriptor.value,
|
|
1245
|
-
handlerInstance: instance
|
|
1246
|
-
});
|
|
1247
1749
|
}
|
|
1248
1750
|
}
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1751
|
+
}
|
|
1752
|
+
__name(scanHttpGuards, "scanHttpGuards");
|
|
1753
|
+
async function scanModule(moduleClass, container, registry) {
|
|
1754
|
+
const graph = buildModuleGraph(moduleClass);
|
|
1755
|
+
registerModuleGraph(graph, container);
|
|
1756
|
+
await scanHttpHandlers(graph, container, registry);
|
|
1757
|
+
await scanHttpGuards(graph, container, registry);
|
|
1758
|
+
}
|
|
1759
|
+
__name(scanModule, "scanModule");
|
|
1760
|
+
async function scanClassHandler(controllerClass, container, registry) {
|
|
1761
|
+
const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
|
|
1762
|
+
if (!controllerMeta) return;
|
|
1763
|
+
const prototype = controllerClass.prototype;
|
|
1764
|
+
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1765
|
+
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1766
|
+
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
1767
|
+
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
1768
|
+
for (const methodName of methods) {
|
|
1769
|
+
const method = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
|
|
1770
|
+
if (!method) continue;
|
|
1771
|
+
const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
|
|
1772
|
+
const fullPath = (0, import_common3.joinHandlerPath)(controllerMeta.prefix ?? "", routePath);
|
|
1773
|
+
const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
|
|
1774
|
+
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
1775
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
1776
|
+
const isPublic = Reflect.getOwnMetadata(PUBLIC_METADATA, prototype, methodName) === true;
|
|
1777
|
+
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
1778
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
1779
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
1252
1780
|
const layers = [
|
|
1253
|
-
...
|
|
1781
|
+
...classLayers,
|
|
1782
|
+
...methodLayers
|
|
1254
1783
|
];
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
if (meta.schema.query) schemas.query = meta.schema.query;
|
|
1259
|
-
if (meta.schema.params) schemas.params = meta.schema.params;
|
|
1260
|
-
if (meta.schema.headers) schemas.headers = meta.schema.headers;
|
|
1261
|
-
if (Object.keys(schemas).length > 0) {
|
|
1262
|
-
layers.unshift(validate(schemas));
|
|
1263
|
-
}
|
|
1784
|
+
const validationSchemas = buildValidationSchemasFromParams(paramMetadata);
|
|
1785
|
+
if (validationSchemas) {
|
|
1786
|
+
layers.unshift(validate(validationSchemas));
|
|
1264
1787
|
}
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
path:
|
|
1269
|
-
method
|
|
1270
|
-
protectedBy: [
|
|
1788
|
+
debug5("scanClassHandler: %s %s (%s.%s)", method, fullPath, controllerClass.name, methodName);
|
|
1789
|
+
registry.register({
|
|
1790
|
+
type: "http",
|
|
1791
|
+
path: fullPath,
|
|
1792
|
+
method,
|
|
1793
|
+
protectedBy: [
|
|
1794
|
+
...classProtectedBy,
|
|
1795
|
+
...methodProtectedBy
|
|
1796
|
+
],
|
|
1271
1797
|
layers,
|
|
1272
|
-
isPublic
|
|
1273
|
-
paramMetadata
|
|
1274
|
-
customMetadata:
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1798
|
+
isPublic,
|
|
1799
|
+
paramMetadata,
|
|
1800
|
+
customMetadata: {
|
|
1801
|
+
...classCustomMetadata,
|
|
1802
|
+
...methodCustomMetadata
|
|
1803
|
+
},
|
|
1804
|
+
handlerFn: descriptor.value,
|
|
1805
|
+
controllerClass
|
|
1278
1806
|
});
|
|
1279
1807
|
}
|
|
1280
|
-
};
|
|
1281
|
-
function matchRoute(pattern, actual) {
|
|
1282
|
-
const patternParts = pattern.split("/").filter(Boolean);
|
|
1283
|
-
const actualParts = actual.split("/").filter(Boolean);
|
|
1284
|
-
if (patternParts.length !== actualParts.length) return false;
|
|
1285
|
-
return patternParts.every((part, i) => part.startsWith("{") || part === actualParts[i]);
|
|
1286
1808
|
}
|
|
1287
|
-
__name(
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1809
|
+
__name(scanClassHandler, "scanClassHandler");
|
|
1810
|
+
function scanFunctionHandler(definition, registry) {
|
|
1811
|
+
if (definition.type !== "http") return;
|
|
1812
|
+
const meta = definition.metadata;
|
|
1813
|
+
const layers = [
|
|
1814
|
+
...meta.layers ?? []
|
|
1815
|
+
];
|
|
1816
|
+
if (meta.schema) {
|
|
1817
|
+
const schemas = {};
|
|
1818
|
+
if (meta.schema.body) schemas.body = meta.schema.body;
|
|
1819
|
+
if (meta.schema.query) schemas.query = meta.schema.query;
|
|
1820
|
+
if (meta.schema.params) schemas.params = meta.schema.params;
|
|
1821
|
+
if (meta.schema.headers) schemas.headers = meta.schema.headers;
|
|
1822
|
+
if (Object.keys(schemas).length > 0) {
|
|
1823
|
+
layers.unshift(validate(schemas));
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
debug5("scanFunctionHandler: %s", definition.id ?? (meta.method && meta.path ? `${meta.method} ${meta.path}` : "(no route)"));
|
|
1827
|
+
registry.register({
|
|
1828
|
+
type: "http",
|
|
1829
|
+
id: definition.id,
|
|
1830
|
+
path: meta.path,
|
|
1831
|
+
method: meta.method,
|
|
1832
|
+
protectedBy: [],
|
|
1833
|
+
layers,
|
|
1834
|
+
isPublic: false,
|
|
1835
|
+
paramMetadata: [],
|
|
1836
|
+
customMetadata: meta.customMetadata ?? {},
|
|
1837
|
+
handlerFn: definition.handler,
|
|
1838
|
+
isFunctionHandler: true,
|
|
1839
|
+
injectTokens: meta.inject ?? []
|
|
1840
|
+
});
|
|
1841
|
+
}
|
|
1842
|
+
__name(scanFunctionHandler, "scanFunctionHandler");
|
|
1843
|
+
async function scanClassGuard(guardClass, container, registry) {
|
|
1844
|
+
const guardName = Reflect.getOwnMetadata(GUARD_CUSTOM_METADATA, guardClass);
|
|
1845
|
+
if (!guardName) return;
|
|
1846
|
+
const prototype = guardClass.prototype;
|
|
1847
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, "check");
|
|
1848
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") {
|
|
1849
|
+
debug5("scanClassGuard: %s has no check() method, skipping", guardClass.name);
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, "check") ?? [];
|
|
1853
|
+
const customMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, guardClass) ?? {};
|
|
1854
|
+
debug5("scanClassGuard: %s (name=%s)", guardClass.name, guardName);
|
|
1855
|
+
registry.registerGuard({
|
|
1856
|
+
name: guardName,
|
|
1857
|
+
handlerFn: descriptor.value,
|
|
1858
|
+
guardClass,
|
|
1859
|
+
paramMetadata,
|
|
1860
|
+
customMetadata
|
|
1861
|
+
});
|
|
1862
|
+
}
|
|
1863
|
+
__name(scanClassGuard, "scanClassGuard");
|
|
1864
|
+
function scanFunctionGuard(definition, registry) {
|
|
1865
|
+
const name = definition.name;
|
|
1866
|
+
if (!name) {
|
|
1867
|
+
debug5("scanFunctionGuard: no name, skipping");
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
const meta = definition.metadata ?? {};
|
|
1871
|
+
debug5("scanFunctionGuard: %s", name);
|
|
1872
|
+
registry.registerGuard({
|
|
1873
|
+
name,
|
|
1874
|
+
handlerFn: definition.handler,
|
|
1875
|
+
customMetadata: meta.customMetadata ?? {},
|
|
1876
|
+
paramMetadata: [],
|
|
1877
|
+
isFunctionGuard: true,
|
|
1878
|
+
injectTokens: meta.inject ?? []
|
|
1879
|
+
});
|
|
1880
|
+
}
|
|
1881
|
+
__name(scanFunctionGuard, "scanFunctionGuard");
|
|
1882
|
+
var PARAM_TYPE_TO_SCHEMA_KEY = {
|
|
1883
|
+
body: "body",
|
|
1884
|
+
query: "query",
|
|
1885
|
+
param: "params",
|
|
1886
|
+
headers: "headers"
|
|
1887
|
+
};
|
|
1888
|
+
function buildValidationSchemasFromParams(paramMetadata) {
|
|
1889
|
+
const wholeObjectSchemas = /* @__PURE__ */ new Map();
|
|
1296
1890
|
const perKeySchemas = /* @__PURE__ */ new Map();
|
|
1297
1891
|
for (const meta of paramMetadata) {
|
|
1298
1892
|
if (!meta.schema) continue;
|
|
@@ -1346,16 +1940,367 @@ function composeKeySchemas(keySchemas) {
|
|
|
1346
1940
|
}
|
|
1347
1941
|
__name(composeKeySchemas, "composeKeySchemas");
|
|
1348
1942
|
|
|
1943
|
+
// src/handlers/scanners/websocket.ts
|
|
1944
|
+
var import_reflect_metadata22 = require("reflect-metadata");
|
|
1945
|
+
var import_debug6 = __toESM(require("debug"), 1);
|
|
1946
|
+
var debug6 = (0, import_debug6.default)("celerity:core:scanner:websocket");
|
|
1947
|
+
async function scanWebSocketHandlers(graph, container, registry) {
|
|
1948
|
+
for (const [, node] of graph) {
|
|
1949
|
+
for (const controllerClass of node.controllers) {
|
|
1950
|
+
await scanClassHandler2(controllerClass, container, registry);
|
|
1951
|
+
}
|
|
1952
|
+
for (const fnHandler of node.functionHandlers) {
|
|
1953
|
+
scanFunctionHandler2(fnHandler, registry);
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
__name(scanWebSocketHandlers, "scanWebSocketHandlers");
|
|
1958
|
+
async function scanClassHandler2(controllerClass, container, registry) {
|
|
1959
|
+
const isWsController = Reflect.getOwnMetadata(WEBSOCKET_CONTROLLER_METADATA, controllerClass);
|
|
1960
|
+
if (!isWsController) return;
|
|
1961
|
+
const prototype = controllerClass.prototype;
|
|
1962
|
+
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1963
|
+
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1964
|
+
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
1965
|
+
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
1966
|
+
const classIsPublic = Reflect.getOwnMetadata(PUBLIC_METADATA, controllerClass) === true;
|
|
1967
|
+
for (const methodName of methods) {
|
|
1968
|
+
const eventMeta = Reflect.getOwnMetadata(WEBSOCKET_EVENT_METADATA, prototype, methodName);
|
|
1969
|
+
if (!eventMeta) continue;
|
|
1970
|
+
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
1971
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
1972
|
+
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
1973
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
1974
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
1975
|
+
debug6("scanClassHandler: %s %s (%s.%s)", eventMeta.eventType, eventMeta.route, controllerClass.name, methodName);
|
|
1976
|
+
const layers = [
|
|
1977
|
+
...classLayers,
|
|
1978
|
+
...methodLayers
|
|
1979
|
+
];
|
|
1980
|
+
const msgBodyParam = paramMetadata.find((p) => p.type === "messageBody");
|
|
1981
|
+
if (msgBodyParam?.schema) {
|
|
1982
|
+
layers.unshift(validate({
|
|
1983
|
+
wsMessageBody: msgBodyParam.schema
|
|
1984
|
+
}));
|
|
1985
|
+
}
|
|
1986
|
+
registry.register({
|
|
1987
|
+
type: "websocket",
|
|
1988
|
+
route: eventMeta.route,
|
|
1989
|
+
protectedBy: classProtectedBy,
|
|
1990
|
+
layers,
|
|
1991
|
+
isPublic: classIsPublic,
|
|
1992
|
+
paramMetadata,
|
|
1993
|
+
customMetadata: {
|
|
1994
|
+
...classCustomMetadata,
|
|
1995
|
+
...methodCustomMetadata
|
|
1996
|
+
},
|
|
1997
|
+
handlerFn: descriptor.value,
|
|
1998
|
+
controllerClass
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
__name(scanClassHandler2, "scanClassHandler");
|
|
2003
|
+
function scanFunctionHandler2(definition, registry) {
|
|
2004
|
+
if (definition.type !== "websocket") return;
|
|
2005
|
+
const meta = definition.metadata;
|
|
2006
|
+
const layers = [
|
|
2007
|
+
...meta.layers ?? []
|
|
2008
|
+
];
|
|
2009
|
+
if (meta.schema) {
|
|
2010
|
+
layers.unshift(validate({
|
|
2011
|
+
wsMessageBody: meta.schema
|
|
2012
|
+
}));
|
|
2013
|
+
}
|
|
2014
|
+
debug6("scanFunctionHandler: %s", definition.id ?? meta.route ?? "(no route)");
|
|
2015
|
+
registry.register({
|
|
2016
|
+
type: "websocket",
|
|
2017
|
+
id: definition.id,
|
|
2018
|
+
route: meta.route ?? "$default",
|
|
2019
|
+
protectedBy: meta.protectedBy ?? [],
|
|
2020
|
+
layers,
|
|
2021
|
+
isPublic: false,
|
|
2022
|
+
paramMetadata: [],
|
|
2023
|
+
customMetadata: meta.customMetadata ?? {},
|
|
2024
|
+
handlerFn: definition.handler,
|
|
2025
|
+
isFunctionHandler: true,
|
|
2026
|
+
injectTokens: meta.inject ?? []
|
|
2027
|
+
});
|
|
2028
|
+
}
|
|
2029
|
+
__name(scanFunctionHandler2, "scanFunctionHandler");
|
|
2030
|
+
|
|
2031
|
+
// src/handlers/scanners/consumer.ts
|
|
2032
|
+
var import_reflect_metadata23 = require("reflect-metadata");
|
|
2033
|
+
var import_debug7 = __toESM(require("debug"), 1);
|
|
2034
|
+
var debug7 = (0, import_debug7.default)("celerity:core:scanner:consumer");
|
|
2035
|
+
async function scanConsumerHandlers(graph, container, registry) {
|
|
2036
|
+
for (const [, node] of graph) {
|
|
2037
|
+
for (const controllerClass of node.controllers) {
|
|
2038
|
+
await scanClassHandler3(controllerClass, container, registry);
|
|
2039
|
+
}
|
|
2040
|
+
for (const fnHandler of node.functionHandlers) {
|
|
2041
|
+
scanFunctionHandler3(fnHandler, registry);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
__name(scanConsumerHandlers, "scanConsumerHandlers");
|
|
2046
|
+
async function scanClassHandler3(controllerClass, container, registry) {
|
|
2047
|
+
const consumerMeta = Reflect.getOwnMetadata(CONSUMER_METADATA, controllerClass);
|
|
2048
|
+
if (!consumerMeta) return;
|
|
2049
|
+
const prototype = controllerClass.prototype;
|
|
2050
|
+
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2051
|
+
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2052
|
+
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
2053
|
+
for (const methodName of methods) {
|
|
2054
|
+
const handlerMeta = Reflect.getOwnMetadata(CONSUMER_HANDLER_METADATA, prototype, methodName);
|
|
2055
|
+
if (!handlerMeta) continue;
|
|
2056
|
+
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
2057
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
2058
|
+
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
2059
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
2060
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
2061
|
+
const handlerTag = consumerMeta.source ? `${consumerMeta.source}::${methodName}` : methodName;
|
|
2062
|
+
const layers = [
|
|
2063
|
+
...classLayers,
|
|
2064
|
+
...methodLayers
|
|
2065
|
+
];
|
|
2066
|
+
const messageParam = paramMetadata.find((p) => p.type === "messages");
|
|
2067
|
+
if (messageParam?.schema) {
|
|
2068
|
+
layers.unshift(validate({
|
|
2069
|
+
consumerMessage: messageParam.schema
|
|
2070
|
+
}));
|
|
2071
|
+
}
|
|
2072
|
+
debug7("scanClassHandler: tag=%s (%s.%s)", handlerTag, controllerClass.name, methodName);
|
|
2073
|
+
registry.register({
|
|
2074
|
+
type: "consumer",
|
|
2075
|
+
handlerTag,
|
|
2076
|
+
layers,
|
|
2077
|
+
paramMetadata,
|
|
2078
|
+
customMetadata: {
|
|
2079
|
+
...classCustomMetadata,
|
|
2080
|
+
...methodCustomMetadata
|
|
2081
|
+
},
|
|
2082
|
+
handlerFn: descriptor.value,
|
|
2083
|
+
controllerClass
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
__name(scanClassHandler3, "scanClassHandler");
|
|
2088
|
+
function scanFunctionHandler3(definition, registry) {
|
|
2089
|
+
if (definition.type !== "consumer") return;
|
|
2090
|
+
const meta = definition.metadata;
|
|
2091
|
+
const handlerTag = definition.id ?? "default";
|
|
2092
|
+
const layers = [
|
|
2093
|
+
...meta.layers ?? []
|
|
2094
|
+
];
|
|
2095
|
+
if (meta.messageSchema) {
|
|
2096
|
+
layers.unshift(validate({
|
|
2097
|
+
consumerMessage: meta.messageSchema
|
|
2098
|
+
}));
|
|
2099
|
+
}
|
|
2100
|
+
debug7("scanFunctionHandler: tag=%s", handlerTag);
|
|
2101
|
+
registry.register({
|
|
2102
|
+
type: "consumer",
|
|
2103
|
+
id: definition.id,
|
|
2104
|
+
handlerTag,
|
|
2105
|
+
layers,
|
|
2106
|
+
paramMetadata: [],
|
|
2107
|
+
customMetadata: meta.customMetadata ?? {},
|
|
2108
|
+
handlerFn: definition.handler,
|
|
2109
|
+
isFunctionHandler: true,
|
|
2110
|
+
injectTokens: meta.inject ?? []
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
__name(scanFunctionHandler3, "scanFunctionHandler");
|
|
2114
|
+
|
|
2115
|
+
// src/handlers/scanners/schedule.ts
|
|
2116
|
+
var import_reflect_metadata24 = require("reflect-metadata");
|
|
2117
|
+
var import_debug8 = __toESM(require("debug"), 1);
|
|
2118
|
+
var debug8 = (0, import_debug8.default)("celerity:core:scanner:schedule");
|
|
2119
|
+
async function scanScheduleHandlers(graph, container, registry) {
|
|
2120
|
+
for (const [, node] of graph) {
|
|
2121
|
+
for (const controllerClass of node.controllers) {
|
|
2122
|
+
await scanClassHandler4(controllerClass, container, registry);
|
|
2123
|
+
}
|
|
2124
|
+
for (const fnHandler of node.functionHandlers) {
|
|
2125
|
+
scanFunctionHandler4(fnHandler, registry);
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
__name(scanScheduleHandlers, "scanScheduleHandlers");
|
|
2130
|
+
async function scanClassHandler4(controllerClass, container, registry) {
|
|
2131
|
+
const prototype = controllerClass.prototype;
|
|
2132
|
+
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2133
|
+
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2134
|
+
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
2135
|
+
for (const methodName of methods) {
|
|
2136
|
+
const handlerMeta = Reflect.getOwnMetadata(SCHEDULE_HANDLER_METADATA, prototype, methodName);
|
|
2137
|
+
if (!handlerMeta) continue;
|
|
2138
|
+
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
2139
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
2140
|
+
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
2141
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
2142
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
2143
|
+
const handlerTag = handlerMeta.source ? `${handlerMeta.source}::${methodName}` : methodName;
|
|
2144
|
+
const layers = [
|
|
2145
|
+
...classLayers,
|
|
2146
|
+
...methodLayers
|
|
2147
|
+
];
|
|
2148
|
+
const inputParam = paramMetadata.find((p) => p.type === "scheduleInput");
|
|
2149
|
+
if (inputParam?.schema) {
|
|
2150
|
+
layers.unshift(validate({
|
|
2151
|
+
scheduleInput: inputParam.schema
|
|
2152
|
+
}));
|
|
2153
|
+
}
|
|
2154
|
+
debug8("scanClassHandler: tag=%s (%s.%s)", handlerTag, controllerClass.name, methodName);
|
|
2155
|
+
registry.register({
|
|
2156
|
+
type: "schedule",
|
|
2157
|
+
handlerTag,
|
|
2158
|
+
layers,
|
|
2159
|
+
paramMetadata,
|
|
2160
|
+
customMetadata: {
|
|
2161
|
+
...classCustomMetadata,
|
|
2162
|
+
...methodCustomMetadata,
|
|
2163
|
+
...handlerMeta.schedule ? {
|
|
2164
|
+
schedule: handlerMeta.schedule
|
|
2165
|
+
} : {},
|
|
2166
|
+
...handlerMeta.source ? {
|
|
2167
|
+
source: handlerMeta.source
|
|
2168
|
+
} : {}
|
|
2169
|
+
},
|
|
2170
|
+
handlerFn: descriptor.value,
|
|
2171
|
+
controllerClass
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
__name(scanClassHandler4, "scanClassHandler");
|
|
2176
|
+
function scanFunctionHandler4(definition, registry) {
|
|
2177
|
+
if (definition.type !== "schedule") return;
|
|
2178
|
+
const meta = definition.metadata;
|
|
2179
|
+
const handlerTag = meta.source ?? definition.id ?? "default";
|
|
2180
|
+
const layers = [
|
|
2181
|
+
...meta.layers ?? []
|
|
2182
|
+
];
|
|
2183
|
+
if (meta.schema) {
|
|
2184
|
+
layers.unshift(validate({
|
|
2185
|
+
scheduleInput: meta.schema
|
|
2186
|
+
}));
|
|
2187
|
+
}
|
|
2188
|
+
const customMetadata = {
|
|
2189
|
+
...meta.customMetadata ?? {}
|
|
2190
|
+
};
|
|
2191
|
+
if (meta.schedule) customMetadata.schedule = meta.schedule;
|
|
2192
|
+
if (meta.source) customMetadata.source = meta.source;
|
|
2193
|
+
debug8("scanFunctionHandler: tag=%s", handlerTag);
|
|
2194
|
+
registry.register({
|
|
2195
|
+
type: "schedule",
|
|
2196
|
+
id: definition.id,
|
|
2197
|
+
handlerTag,
|
|
2198
|
+
layers,
|
|
2199
|
+
paramMetadata: [],
|
|
2200
|
+
customMetadata,
|
|
2201
|
+
handlerFn: definition.handler,
|
|
2202
|
+
isFunctionHandler: true,
|
|
2203
|
+
injectTokens: meta.inject ?? []
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
__name(scanFunctionHandler4, "scanFunctionHandler");
|
|
2207
|
+
|
|
2208
|
+
// src/handlers/scanners/custom.ts
|
|
2209
|
+
var import_reflect_metadata25 = require("reflect-metadata");
|
|
2210
|
+
var import_debug9 = __toESM(require("debug"), 1);
|
|
2211
|
+
var debug9 = (0, import_debug9.default)("celerity:core:scanner:custom");
|
|
2212
|
+
async function scanCustomHandlers(graph, container, registry) {
|
|
2213
|
+
for (const [, node] of graph) {
|
|
2214
|
+
for (const controllerClass of node.controllers) {
|
|
2215
|
+
await scanClassHandler5(controllerClass, container, registry);
|
|
2216
|
+
}
|
|
2217
|
+
for (const fnHandler of node.functionHandlers) {
|
|
2218
|
+
scanFunctionHandler5(fnHandler, registry);
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
__name(scanCustomHandlers, "scanCustomHandlers");
|
|
2223
|
+
async function scanClassHandler5(controllerClass, container, registry) {
|
|
2224
|
+
const prototype = controllerClass.prototype;
|
|
2225
|
+
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
2226
|
+
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
2227
|
+
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
2228
|
+
for (const methodName of methods) {
|
|
2229
|
+
const invokeMeta = Reflect.getOwnMetadata(INVOKE_METADATA, prototype, methodName);
|
|
2230
|
+
if (!invokeMeta) continue;
|
|
2231
|
+
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
2232
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
2233
|
+
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
2234
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
2235
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
2236
|
+
const layers = [
|
|
2237
|
+
...classLayers,
|
|
2238
|
+
...methodLayers
|
|
2239
|
+
];
|
|
2240
|
+
const payloadParam = paramMetadata.find((p) => p.type === "payload");
|
|
2241
|
+
if (payloadParam?.schema) {
|
|
2242
|
+
layers.unshift(validate({
|
|
2243
|
+
customPayload: payloadParam.schema
|
|
2244
|
+
}));
|
|
2245
|
+
}
|
|
2246
|
+
debug9("scanClassHandler: name=%s (%s.%s)", invokeMeta.name, controllerClass.name, methodName);
|
|
2247
|
+
registry.register({
|
|
2248
|
+
type: "custom",
|
|
2249
|
+
name: invokeMeta.name,
|
|
2250
|
+
layers,
|
|
2251
|
+
paramMetadata,
|
|
2252
|
+
customMetadata: {
|
|
2253
|
+
...classCustomMetadata,
|
|
2254
|
+
...methodCustomMetadata
|
|
2255
|
+
},
|
|
2256
|
+
handlerFn: descriptor.value,
|
|
2257
|
+
controllerClass
|
|
2258
|
+
});
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
__name(scanClassHandler5, "scanClassHandler");
|
|
2262
|
+
function scanFunctionHandler5(definition, registry) {
|
|
2263
|
+
if (definition.type !== "custom") return;
|
|
2264
|
+
const meta = definition.metadata;
|
|
2265
|
+
const name = meta.name ?? definition.id ?? "default";
|
|
2266
|
+
const layers = [
|
|
2267
|
+
...meta.layers ?? []
|
|
2268
|
+
];
|
|
2269
|
+
if (meta.schema) {
|
|
2270
|
+
layers.unshift(validate({
|
|
2271
|
+
customPayload: meta.schema
|
|
2272
|
+
}));
|
|
2273
|
+
}
|
|
2274
|
+
debug9("scanFunctionHandler: name=%s", name);
|
|
2275
|
+
registry.register({
|
|
2276
|
+
type: "custom",
|
|
2277
|
+
id: definition.id,
|
|
2278
|
+
name,
|
|
2279
|
+
layers,
|
|
2280
|
+
paramMetadata: [],
|
|
2281
|
+
customMetadata: meta.customMetadata ?? {},
|
|
2282
|
+
handlerFn: definition.handler,
|
|
2283
|
+
isFunctionHandler: true,
|
|
2284
|
+
injectTokens: meta.inject ?? []
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
__name(scanFunctionHandler5, "scanFunctionHandler");
|
|
2288
|
+
|
|
1349
2289
|
// src/bootstrap/bootstrap.ts
|
|
1350
|
-
var
|
|
2290
|
+
var debug10 = (0, import_debug10.default)("celerity:core:bootstrap");
|
|
1351
2291
|
async function bootstrap(rootModule) {
|
|
1352
|
-
|
|
2292
|
+
debug10("bootstrap: starting from %s", rootModule.name);
|
|
1353
2293
|
const container = new Container();
|
|
1354
2294
|
const registry = new HandlerRegistry();
|
|
1355
2295
|
const graph = walkModuleGraph(rootModule, container);
|
|
1356
2296
|
validateModuleGraph(graph, container);
|
|
1357
|
-
await
|
|
1358
|
-
|
|
2297
|
+
await scanHttpHandlers(graph, container, registry);
|
|
2298
|
+
await scanHttpGuards(graph, container, registry);
|
|
2299
|
+
await scanWebSocketHandlers(graph, container, registry);
|
|
2300
|
+
await scanConsumerHandlers(graph, container, registry);
|
|
2301
|
+
await scanScheduleHandlers(graph, container, registry);
|
|
2302
|
+
await scanCustomHandlers(graph, container, registry);
|
|
2303
|
+
debug10("bootstrap: complete \u2014 %d modules, %d handlers", graph.size, registry.getAllHandlers().length);
|
|
1359
2304
|
return {
|
|
1360
2305
|
container,
|
|
1361
2306
|
registry
|
|
@@ -1364,8 +2309,8 @@ async function bootstrap(rootModule) {
|
|
|
1364
2309
|
__name(bootstrap, "bootstrap");
|
|
1365
2310
|
|
|
1366
2311
|
// src/application/application.ts
|
|
1367
|
-
var
|
|
1368
|
-
var
|
|
2312
|
+
var import_debug11 = __toESM(require("debug"), 1);
|
|
2313
|
+
var debug11 = (0, import_debug11.default)("celerity:core:factory");
|
|
1369
2314
|
var CelerityApplication = class {
|
|
1370
2315
|
static {
|
|
1371
2316
|
__name(this, "CelerityApplication");
|
|
@@ -1389,7 +2334,7 @@ var CelerityApplication = class {
|
|
|
1389
2334
|
}
|
|
1390
2335
|
}
|
|
1391
2336
|
async close() {
|
|
1392
|
-
|
|
2337
|
+
debug11("close: shutting down application");
|
|
1393
2338
|
if (this.runtimeApp && typeof this.runtimeApp === "object") {
|
|
1394
2339
|
const app = this.runtimeApp;
|
|
1395
2340
|
await app.shutdown();
|
|
@@ -1415,6 +2360,13 @@ var CelerityApplication = class {
|
|
|
1415
2360
|
};
|
|
1416
2361
|
|
|
1417
2362
|
// src/application/serverless.ts
|
|
2363
|
+
var HANDLER_CREATORS = {
|
|
2364
|
+
http: /* @__PURE__ */ __name((adapter, registry, options) => adapter.createHttpHandler(registry, options), "http"),
|
|
2365
|
+
websocket: /* @__PURE__ */ __name((adapter, registry, options) => adapter.createWebSocketHandler(registry, options), "websocket"),
|
|
2366
|
+
consumer: /* @__PURE__ */ __name((adapter, registry, options) => adapter.createConsumerHandler(registry, options), "consumer"),
|
|
2367
|
+
schedule: /* @__PURE__ */ __name((adapter, registry, options) => adapter.createScheduleHandler(registry, options), "schedule"),
|
|
2368
|
+
custom: /* @__PURE__ */ __name((adapter, registry, options) => adapter.createCustomHandler(registry, options), "custom")
|
|
2369
|
+
};
|
|
1418
2370
|
var ServerlessApplication = class {
|
|
1419
2371
|
static {
|
|
1420
2372
|
__name(this, "ServerlessApplication");
|
|
@@ -1432,12 +2384,16 @@ var ServerlessApplication = class {
|
|
|
1432
2384
|
this.systemLayers = systemLayers;
|
|
1433
2385
|
this.appLayers = appLayers;
|
|
1434
2386
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
2387
|
+
createHandler(type) {
|
|
2388
|
+
const options = {
|
|
1437
2389
|
container: this.container,
|
|
1438
2390
|
systemLayers: this.systemLayers,
|
|
1439
2391
|
appLayers: this.appLayers
|
|
1440
|
-
}
|
|
2392
|
+
};
|
|
2393
|
+
return HANDLER_CREATORS[type](this.adapter, this.registry, options);
|
|
2394
|
+
}
|
|
2395
|
+
async start(type = "http") {
|
|
2396
|
+
this.handler = this.createHandler(type);
|
|
1441
2397
|
return this.handler;
|
|
1442
2398
|
}
|
|
1443
2399
|
async close() {
|
|
@@ -1461,8 +2417,8 @@ var ServerlessApplication = class {
|
|
|
1461
2417
|
}
|
|
1462
2418
|
};
|
|
1463
2419
|
|
|
1464
|
-
// src/handlers/pipeline.ts
|
|
1465
|
-
var
|
|
2420
|
+
// src/handlers/http-pipeline.ts
|
|
2421
|
+
var import_debug12 = __toESM(require("debug"), 1);
|
|
1466
2422
|
|
|
1467
2423
|
// src/functions/context.ts
|
|
1468
2424
|
function buildHttpRequest(request, metadata) {
|
|
@@ -1504,12 +2460,39 @@ function buildHttpContext(request, metadata, container, logger) {
|
|
|
1504
2460
|
}
|
|
1505
2461
|
__name(buildHttpContext, "buildHttpContext");
|
|
1506
2462
|
|
|
1507
|
-
// src/handlers/
|
|
1508
|
-
|
|
1509
|
-
|
|
2463
|
+
// src/handlers/types.ts
|
|
2464
|
+
async function resolveHandlerInstance(handler, container) {
|
|
2465
|
+
if (handler.handlerInstance) return handler.handlerInstance;
|
|
2466
|
+
if (!handler.controllerClass) {
|
|
2467
|
+
throw new Error("Handler has no controllerClass for deferred resolution");
|
|
2468
|
+
}
|
|
2469
|
+
const instance = await container.resolve(handler.controllerClass);
|
|
2470
|
+
handler.handlerInstance = instance;
|
|
2471
|
+
return instance;
|
|
2472
|
+
}
|
|
2473
|
+
__name(resolveHandlerInstance, "resolveHandlerInstance");
|
|
2474
|
+
async function resolveGuardInstance(guard, container) {
|
|
2475
|
+
if (guard.handlerInstance) return guard.handlerInstance;
|
|
2476
|
+
if (!guard.guardClass) {
|
|
2477
|
+
throw new Error("Guard has no guardClass for deferred resolution");
|
|
2478
|
+
}
|
|
2479
|
+
const instance = await container.resolve(guard.guardClass);
|
|
2480
|
+
guard.handlerInstance = instance;
|
|
2481
|
+
return instance;
|
|
2482
|
+
}
|
|
2483
|
+
__name(resolveGuardInstance, "resolveGuardInstance");
|
|
2484
|
+
|
|
2485
|
+
// src/handlers/http-pipeline.ts
|
|
2486
|
+
var debug12 = (0, import_debug12.default)("celerity:core:pipeline");
|
|
2487
|
+
async function executeHttpPipeline(handler, request, options) {
|
|
1510
2488
|
const context = {
|
|
1511
2489
|
request,
|
|
1512
|
-
metadata: new HandlerMetadataStore(
|
|
2490
|
+
metadata: new HandlerMetadataStore({
|
|
2491
|
+
...handler.customMetadata ?? {},
|
|
2492
|
+
...options.handlerName ? {
|
|
2493
|
+
handlerName: options.handlerName
|
|
2494
|
+
} : {}
|
|
2495
|
+
}),
|
|
1513
2496
|
container: options.container
|
|
1514
2497
|
};
|
|
1515
2498
|
const allLayers = [
|
|
@@ -1517,19 +2500,19 @@ async function executeHandlerPipeline(handler, request, options) {
|
|
|
1517
2500
|
...options.appLayers ?? [],
|
|
1518
2501
|
...handler.layers
|
|
1519
2502
|
];
|
|
1520
|
-
|
|
2503
|
+
debug12("%s %s \u2014 %d layers", request.method, request.path, allLayers.length);
|
|
1521
2504
|
try {
|
|
1522
2505
|
const response = await runLayerPipeline(allLayers, context, async () => {
|
|
1523
|
-
const
|
|
1524
|
-
|
|
2506
|
+
const style = handler.isFunctionHandler ? "function" : "class";
|
|
2507
|
+
debug12("invoking %s handler", style);
|
|
1525
2508
|
const result = handler.isFunctionHandler ? await invokeFunctionHandler(handler, context) : await invokeClassHandler(handler, context);
|
|
1526
2509
|
return normalizeResponse(result);
|
|
1527
|
-
});
|
|
1528
|
-
|
|
2510
|
+
}, "http");
|
|
2511
|
+
debug12("response %d", response.status);
|
|
1529
2512
|
return response;
|
|
1530
2513
|
} catch (error) {
|
|
1531
2514
|
if (error instanceof HttpException) {
|
|
1532
|
-
|
|
2515
|
+
debug12("HttpException %d: %s", error.statusCode, error.message);
|
|
1533
2516
|
return {
|
|
1534
2517
|
status: error.statusCode,
|
|
1535
2518
|
headers: {
|
|
@@ -1549,6 +2532,9 @@ async function executeHandlerPipeline(handler, request, options) {
|
|
|
1549
2532
|
error: message,
|
|
1550
2533
|
...error instanceof Error && error.stack ? {
|
|
1551
2534
|
stack: error.stack
|
|
2535
|
+
} : {},
|
|
2536
|
+
...error instanceof Error && error.cause ? {
|
|
2537
|
+
cause: String(error.cause)
|
|
1552
2538
|
} : {}
|
|
1553
2539
|
});
|
|
1554
2540
|
} else {
|
|
@@ -1565,7 +2551,7 @@ async function executeHandlerPipeline(handler, request, options) {
|
|
|
1565
2551
|
};
|
|
1566
2552
|
}
|
|
1567
2553
|
}
|
|
1568
|
-
__name(
|
|
2554
|
+
__name(executeHttpPipeline, "executeHttpPipeline");
|
|
1569
2555
|
async function invokeClassHandler(handler, context) {
|
|
1570
2556
|
const args = [];
|
|
1571
2557
|
const sorted = [
|
|
@@ -1574,7 +2560,8 @@ async function invokeClassHandler(handler, context) {
|
|
|
1574
2560
|
for (const meta of sorted) {
|
|
1575
2561
|
args[meta.index] = extractValidatedParam(meta.type, meta.key, context.request, context.metadata);
|
|
1576
2562
|
}
|
|
1577
|
-
|
|
2563
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2564
|
+
return handler.handlerFn.apply(instance, args);
|
|
1578
2565
|
}
|
|
1579
2566
|
__name(invokeClassHandler, "invokeClassHandler");
|
|
1580
2567
|
var VALIDATED_METADATA_KEYS = {
|
|
@@ -1634,94 +2621,564 @@ function isHttpResponse(value) {
|
|
|
1634
2621
|
}
|
|
1635
2622
|
__name(isHttpResponse, "isHttpResponse");
|
|
1636
2623
|
|
|
1637
|
-
// src/
|
|
1638
|
-
var
|
|
1639
|
-
|
|
1640
|
-
|
|
2624
|
+
// src/handlers/websocket-pipeline.ts
|
|
2625
|
+
var import_debug13 = __toESM(require("debug"), 1);
|
|
2626
|
+
var debug13 = (0, import_debug13.default)("celerity:core:ws-pipeline");
|
|
2627
|
+
async function executeWebSocketPipeline(handler, message, options) {
|
|
2628
|
+
const context = {
|
|
2629
|
+
message,
|
|
2630
|
+
metadata: new HandlerMetadataStore({
|
|
2631
|
+
...handler.customMetadata ?? {},
|
|
2632
|
+
...options.handlerName ? {
|
|
2633
|
+
handlerName: options.handlerName
|
|
2634
|
+
} : {}
|
|
2635
|
+
}),
|
|
2636
|
+
container: options.container
|
|
2637
|
+
};
|
|
2638
|
+
const allLayers = [
|
|
2639
|
+
...options.systemLayers ?? [],
|
|
2640
|
+
...options.appLayers ?? [],
|
|
2641
|
+
...handler.layers
|
|
2642
|
+
];
|
|
2643
|
+
debug13("%s %s \u2014 %d layers", message.eventType, message.connectionId, allLayers.length);
|
|
2644
|
+
try {
|
|
2645
|
+
await runLayerPipeline(allLayers, context, async () => {
|
|
2646
|
+
const style = handler.isFunctionHandler ? "function" : "class";
|
|
2647
|
+
debug13("invoking %s handler", style);
|
|
2648
|
+
if (handler.isFunctionHandler) {
|
|
2649
|
+
await invokeFunctionHandler2(handler, context);
|
|
2650
|
+
} else {
|
|
2651
|
+
await invokeClassHandler2(handler, context);
|
|
2652
|
+
}
|
|
2653
|
+
}, "websocket");
|
|
2654
|
+
} catch (error) {
|
|
2655
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2656
|
+
if (context.logger) {
|
|
2657
|
+
context.logger.error("Unhandled error in WebSocket handler pipeline", {
|
|
2658
|
+
error: errorMessage,
|
|
2659
|
+
connectionId: message.connectionId,
|
|
2660
|
+
eventType: message.eventType,
|
|
2661
|
+
...error instanceof Error && error.stack ? {
|
|
2662
|
+
stack: error.stack
|
|
2663
|
+
} : {},
|
|
2664
|
+
...error instanceof Error && error.cause ? {
|
|
2665
|
+
cause: String(error.cause)
|
|
2666
|
+
} : {}
|
|
2667
|
+
});
|
|
2668
|
+
} else {
|
|
2669
|
+
console.error("Unhandled error in WebSocket handler pipeline:", error);
|
|
2670
|
+
}
|
|
1641
2671
|
}
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
2672
|
+
}
|
|
2673
|
+
__name(executeWebSocketPipeline, "executeWebSocketPipeline");
|
|
2674
|
+
async function invokeClassHandler2(handler, context) {
|
|
2675
|
+
const args = [];
|
|
2676
|
+
const sorted = [
|
|
2677
|
+
...handler.paramMetadata
|
|
2678
|
+
].sort((a, b) => a.index - b.index);
|
|
2679
|
+
for (const meta of sorted) {
|
|
2680
|
+
args[meta.index] = extractWebSocketParam(meta, context);
|
|
1651
2681
|
}
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
2682
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2683
|
+
await handler.handlerFn.apply(instance, args);
|
|
2684
|
+
}
|
|
2685
|
+
__name(invokeClassHandler2, "invokeClassHandler");
|
|
2686
|
+
async function invokeFunctionHandler2(handler, context) {
|
|
2687
|
+
const validatedBody = context.metadata.get("validatedMessageBody");
|
|
2688
|
+
const message = validatedBody !== void 0 ? {
|
|
2689
|
+
...context.message,
|
|
2690
|
+
jsonBody: validatedBody
|
|
2691
|
+
} : context.message;
|
|
2692
|
+
if (handler.injectTokens && handler.injectTokens.length > 0) {
|
|
2693
|
+
const deps = [];
|
|
2694
|
+
for (const token of handler.injectTokens) {
|
|
2695
|
+
deps.push(await context.container.resolve(token));
|
|
1656
2696
|
}
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
appLayers: this.appLayers
|
|
1661
|
-
});
|
|
1662
|
-
}
|
|
1663
|
-
getContainer() {
|
|
1664
|
-
return this.container;
|
|
2697
|
+
await handler.handlerFn(message, context, ...deps);
|
|
2698
|
+
} else {
|
|
2699
|
+
await handler.handlerFn(message, context);
|
|
1665
2700
|
}
|
|
1666
|
-
|
|
1667
|
-
|
|
2701
|
+
}
|
|
2702
|
+
__name(invokeFunctionHandler2, "invokeFunctionHandler");
|
|
2703
|
+
function extractWebSocketParam(meta, context) {
|
|
2704
|
+
const { message } = context;
|
|
2705
|
+
switch (meta.type) {
|
|
2706
|
+
case "connectionId":
|
|
2707
|
+
return message.connectionId;
|
|
2708
|
+
case "messageBody": {
|
|
2709
|
+
const validated = context.metadata.get("validatedMessageBody");
|
|
2710
|
+
if (validated !== void 0) return validated;
|
|
2711
|
+
return message.jsonBody;
|
|
2712
|
+
}
|
|
2713
|
+
case "messageId":
|
|
2714
|
+
return message.messageId;
|
|
2715
|
+
case "requestContext":
|
|
2716
|
+
return message.requestContext;
|
|
2717
|
+
case "eventType":
|
|
2718
|
+
return message.eventType;
|
|
2719
|
+
default:
|
|
2720
|
+
return void 0;
|
|
1668
2721
|
}
|
|
1669
|
-
};
|
|
1670
|
-
function mockRequest(method, path, options = {}) {
|
|
1671
|
-
return {
|
|
1672
|
-
method,
|
|
1673
|
-
path,
|
|
1674
|
-
pathParams: options.pathParams ?? {},
|
|
1675
|
-
query: options.query ?? {},
|
|
1676
|
-
headers: options.headers ?? {},
|
|
1677
|
-
cookies: options.cookies ?? {},
|
|
1678
|
-
textBody: options.body !== void 0 ? JSON.stringify(options.body) : null,
|
|
1679
|
-
binaryBody: null,
|
|
1680
|
-
contentType: options.body !== void 0 ? "application/json" : null,
|
|
1681
|
-
requestId: options.requestId ?? "test-request-id",
|
|
1682
|
-
requestTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1683
|
-
auth: options.auth ?? null,
|
|
1684
|
-
clientIp: options.clientIp ?? "127.0.0.1",
|
|
1685
|
-
traceContext: null,
|
|
1686
|
-
userAgent: "celerity-testing",
|
|
1687
|
-
matchedRoute: null
|
|
1688
|
-
};
|
|
1689
2722
|
}
|
|
1690
|
-
__name(
|
|
2723
|
+
__name(extractWebSocketParam, "extractWebSocketParam");
|
|
1691
2724
|
|
|
1692
|
-
// src/
|
|
1693
|
-
var
|
|
1694
|
-
var
|
|
1695
|
-
|
|
1696
|
-
|
|
2725
|
+
// src/handlers/consumer-pipeline.ts
|
|
2726
|
+
var import_debug14 = __toESM(require("debug"), 1);
|
|
2727
|
+
var debug14 = (0, import_debug14.default)("celerity:core:consumer-pipeline");
|
|
2728
|
+
async function executeConsumerPipeline(handler, event, options) {
|
|
2729
|
+
const context = {
|
|
2730
|
+
event,
|
|
2731
|
+
metadata: new HandlerMetadataStore({
|
|
2732
|
+
...handler.customMetadata ?? {},
|
|
2733
|
+
...options.handlerName ? {
|
|
2734
|
+
handlerName: options.handlerName
|
|
2735
|
+
} : {}
|
|
2736
|
+
}),
|
|
2737
|
+
container: options.container
|
|
2738
|
+
};
|
|
2739
|
+
const allLayers = [
|
|
2740
|
+
...options.systemLayers ?? [],
|
|
2741
|
+
...options.appLayers ?? [],
|
|
2742
|
+
...handler.layers
|
|
2743
|
+
];
|
|
2744
|
+
debug14("tag=%s \u2014 %d messages, %d layers", event.handlerTag, event.messages.length, allLayers.length);
|
|
2745
|
+
let result = {
|
|
2746
|
+
success: true
|
|
2747
|
+
};
|
|
2748
|
+
try {
|
|
2749
|
+
await runLayerPipeline(allLayers, context, async () => {
|
|
2750
|
+
const style = handler.isFunctionHandler ? "function" : "class";
|
|
2751
|
+
debug14("invoking %s handler", style);
|
|
2752
|
+
const validatedMessages = context.metadata.get("validatedMessages");
|
|
2753
|
+
const validationFailures = context.metadata.get("validationFailures") ?? [];
|
|
2754
|
+
const rawMessages = validatedMessages ? void 0 : event.messages;
|
|
2755
|
+
if (handler.isFunctionHandler) {
|
|
2756
|
+
result = await invokeFunctionHandler3(handler, context, validatedMessages, rawMessages);
|
|
2757
|
+
} else {
|
|
2758
|
+
result = await invokeClassHandler3(handler, context, validatedMessages, rawMessages);
|
|
2759
|
+
}
|
|
2760
|
+
if (validationFailures.length > 0) {
|
|
2761
|
+
const existing = result.failures ?? [];
|
|
2762
|
+
result = {
|
|
2763
|
+
...result,
|
|
2764
|
+
success: result.success && validationFailures.length === 0,
|
|
2765
|
+
failures: [
|
|
2766
|
+
...validationFailures,
|
|
2767
|
+
...existing
|
|
2768
|
+
]
|
|
2769
|
+
};
|
|
2770
|
+
}
|
|
2771
|
+
}, "consumer");
|
|
2772
|
+
} catch (error) {
|
|
2773
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2774
|
+
if (context.logger) {
|
|
2775
|
+
context.logger.error("Unhandled error in consumer handler pipeline", {
|
|
2776
|
+
error: errorMessage,
|
|
2777
|
+
handlerTag: event.handlerTag,
|
|
2778
|
+
messageCount: event.messages.length,
|
|
2779
|
+
...error instanceof Error && error.stack ? {
|
|
2780
|
+
stack: error.stack
|
|
2781
|
+
} : {},
|
|
2782
|
+
...error instanceof Error && error.cause ? {
|
|
2783
|
+
cause: String(error.cause)
|
|
2784
|
+
} : {}
|
|
2785
|
+
});
|
|
2786
|
+
} else {
|
|
2787
|
+
console.error("Unhandled error in consumer handler pipeline:", error);
|
|
2788
|
+
}
|
|
2789
|
+
return {
|
|
2790
|
+
success: false,
|
|
2791
|
+
errorMessage
|
|
2792
|
+
};
|
|
1697
2793
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
2794
|
+
return result;
|
|
2795
|
+
}
|
|
2796
|
+
__name(executeConsumerPipeline, "executeConsumerPipeline");
|
|
2797
|
+
async function invokeClassHandler3(handler, context, validatedMessages, rawMessages) {
|
|
2798
|
+
const args = [];
|
|
2799
|
+
const sorted = [
|
|
2800
|
+
...handler.paramMetadata
|
|
2801
|
+
].sort((a, b) => a.index - b.index);
|
|
2802
|
+
for (const meta of sorted) {
|
|
2803
|
+
args[meta.index] = extractConsumerParam(meta, context, validatedMessages, rawMessages);
|
|
2804
|
+
}
|
|
2805
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2806
|
+
return await handler.handlerFn.apply(instance, args);
|
|
2807
|
+
}
|
|
2808
|
+
__name(invokeClassHandler3, "invokeClassHandler");
|
|
2809
|
+
async function invokeFunctionHandler3(handler, context, validatedMessages, _rawMessages) {
|
|
2810
|
+
const deps = [];
|
|
2811
|
+
if (handler.injectTokens && handler.injectTokens.length > 0) {
|
|
2812
|
+
for (const token of handler.injectTokens) {
|
|
2813
|
+
deps.push(await context.container.resolve(token));
|
|
1707
2814
|
}
|
|
1708
|
-
debug8("create: \u2192 CelerityApplication");
|
|
1709
|
-
return new CelerityApplication(registry, container, systemLayers, appLayers);
|
|
1710
2815
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
2816
|
+
const firstArg = validatedMessages ?? context.event;
|
|
2817
|
+
return await handler.handlerFn(firstArg, context, ...deps);
|
|
2818
|
+
}
|
|
2819
|
+
__name(invokeFunctionHandler3, "invokeFunctionHandler");
|
|
2820
|
+
function extractConsumerParam(meta, context, validatedMessages, rawMessages) {
|
|
2821
|
+
switch (meta.type) {
|
|
2822
|
+
case "messages":
|
|
2823
|
+
return validatedMessages ?? rawMessages ?? context.event.messages;
|
|
2824
|
+
case "consumerEvent":
|
|
2825
|
+
return context.event;
|
|
2826
|
+
case "consumerVendor":
|
|
2827
|
+
return context.event.vendor;
|
|
2828
|
+
case "consumerTraceContext":
|
|
2829
|
+
return context.event.traceContext ?? null;
|
|
2830
|
+
default:
|
|
2831
|
+
return void 0;
|
|
1717
2832
|
}
|
|
1718
|
-
}
|
|
2833
|
+
}
|
|
2834
|
+
__name(extractConsumerParam, "extractConsumerParam");
|
|
1719
2835
|
|
|
1720
|
-
// src/
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
2836
|
+
// src/handlers/schedule-pipeline.ts
|
|
2837
|
+
var import_debug15 = __toESM(require("debug"), 1);
|
|
2838
|
+
var debug15 = (0, import_debug15.default)("celerity:core:schedule-pipeline");
|
|
2839
|
+
async function executeSchedulePipeline(handler, event, options) {
|
|
2840
|
+
const context = {
|
|
2841
|
+
event,
|
|
2842
|
+
metadata: new HandlerMetadataStore({
|
|
2843
|
+
...handler.customMetadata ?? {},
|
|
2844
|
+
...options.handlerName ? {
|
|
2845
|
+
handlerName: options.handlerName
|
|
2846
|
+
} : {}
|
|
2847
|
+
}),
|
|
2848
|
+
container: options.container
|
|
2849
|
+
};
|
|
2850
|
+
const allLayers = [
|
|
2851
|
+
...options.systemLayers ?? [],
|
|
2852
|
+
...options.appLayers ?? [],
|
|
2853
|
+
...handler.layers
|
|
2854
|
+
];
|
|
2855
|
+
debug15("tag=%s \u2014 %d layers", event.handlerTag, allLayers.length);
|
|
2856
|
+
let result = {
|
|
2857
|
+
success: true
|
|
2858
|
+
};
|
|
2859
|
+
try {
|
|
2860
|
+
await runLayerPipeline(allLayers, context, async () => {
|
|
2861
|
+
const style = handler.isFunctionHandler ? "function" : "class";
|
|
2862
|
+
debug15("invoking %s handler", style);
|
|
2863
|
+
const validatedInput = context.metadata.get("validatedInput") ?? event.input;
|
|
2864
|
+
if (handler.isFunctionHandler) {
|
|
2865
|
+
result = await invokeFunctionHandler4(handler, context, validatedInput);
|
|
2866
|
+
} else {
|
|
2867
|
+
result = await invokeClassHandler4(handler, context, validatedInput);
|
|
2868
|
+
}
|
|
2869
|
+
}, "schedule");
|
|
2870
|
+
} catch (error) {
|
|
2871
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2872
|
+
if (context.logger) {
|
|
2873
|
+
context.logger.error("Unhandled error in schedule handler pipeline", {
|
|
2874
|
+
error: errorMessage,
|
|
2875
|
+
handlerTag: event.handlerTag,
|
|
2876
|
+
scheduleId: event.scheduleId,
|
|
2877
|
+
...error instanceof Error && error.stack ? {
|
|
2878
|
+
stack: error.stack
|
|
2879
|
+
} : {},
|
|
2880
|
+
...error instanceof Error && error.cause ? {
|
|
2881
|
+
cause: String(error.cause)
|
|
2882
|
+
} : {}
|
|
2883
|
+
});
|
|
2884
|
+
} else {
|
|
2885
|
+
console.error("Unhandled error in schedule handler pipeline:", error);
|
|
2886
|
+
}
|
|
2887
|
+
return {
|
|
2888
|
+
success: false,
|
|
2889
|
+
errorMessage
|
|
2890
|
+
};
|
|
2891
|
+
}
|
|
2892
|
+
return result;
|
|
2893
|
+
}
|
|
2894
|
+
__name(executeSchedulePipeline, "executeSchedulePipeline");
|
|
2895
|
+
async function invokeClassHandler4(handler, context, validatedInput) {
|
|
2896
|
+
const args = [];
|
|
2897
|
+
const sorted = [
|
|
2898
|
+
...handler.paramMetadata
|
|
2899
|
+
].sort((a, b) => a.index - b.index);
|
|
2900
|
+
for (const meta of sorted) {
|
|
2901
|
+
args[meta.index] = extractScheduleParam(meta, context, validatedInput);
|
|
2902
|
+
}
|
|
2903
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2904
|
+
return await handler.handlerFn.apply(instance, args);
|
|
2905
|
+
}
|
|
2906
|
+
__name(invokeClassHandler4, "invokeClassHandler");
|
|
2907
|
+
async function invokeFunctionHandler4(handler, context, _validatedInput) {
|
|
2908
|
+
const deps = [];
|
|
2909
|
+
if (handler.injectTokens && handler.injectTokens.length > 0) {
|
|
2910
|
+
for (const token of handler.injectTokens) {
|
|
2911
|
+
deps.push(await context.container.resolve(token));
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
return await handler.handlerFn(context.event, context, ...deps);
|
|
2915
|
+
}
|
|
2916
|
+
__name(invokeFunctionHandler4, "invokeFunctionHandler");
|
|
2917
|
+
function extractScheduleParam(meta, context, validatedInput) {
|
|
2918
|
+
switch (meta.type) {
|
|
2919
|
+
case "scheduleInput":
|
|
2920
|
+
return validatedInput;
|
|
2921
|
+
case "scheduleId":
|
|
2922
|
+
return context.event.scheduleId;
|
|
2923
|
+
case "scheduleExpression":
|
|
2924
|
+
return context.event.schedule;
|
|
2925
|
+
case "scheduleEvent":
|
|
2926
|
+
return context.event;
|
|
2927
|
+
default:
|
|
2928
|
+
return void 0;
|
|
2929
|
+
}
|
|
2930
|
+
}
|
|
2931
|
+
__name(extractScheduleParam, "extractScheduleParam");
|
|
2932
|
+
|
|
2933
|
+
// src/handlers/custom-pipeline.ts
|
|
2934
|
+
var import_debug16 = __toESM(require("debug"), 1);
|
|
2935
|
+
var debug16 = (0, import_debug16.default)("celerity:core:custom-pipeline");
|
|
2936
|
+
async function executeCustomPipeline(handler, payload, options) {
|
|
2937
|
+
const context = {
|
|
2938
|
+
metadata: new HandlerMetadataStore({
|
|
2939
|
+
...handler.customMetadata ?? {},
|
|
2940
|
+
...options.handlerName ? {
|
|
2941
|
+
handlerName: options.handlerName
|
|
2942
|
+
} : {},
|
|
2943
|
+
rawPayload: payload
|
|
2944
|
+
}),
|
|
2945
|
+
container: options.container
|
|
2946
|
+
};
|
|
2947
|
+
const allLayers = [
|
|
2948
|
+
...options.systemLayers ?? [],
|
|
2949
|
+
...options.appLayers ?? [],
|
|
2950
|
+
...handler.layers
|
|
2951
|
+
];
|
|
2952
|
+
debug16("name=%s \u2014 %d layers", options.handlerName ?? "unknown", allLayers.length);
|
|
2953
|
+
let result;
|
|
2954
|
+
await runLayerPipeline(allLayers, context, async () => {
|
|
2955
|
+
const style = handler.isFunctionHandler ? "function" : "class";
|
|
2956
|
+
debug16("invoking %s handler", style);
|
|
2957
|
+
const validatedPayload = context.metadata.get("validatedPayload") ?? payload;
|
|
2958
|
+
if (handler.isFunctionHandler) {
|
|
2959
|
+
result = await invokeFunctionHandler5(handler, context, validatedPayload);
|
|
2960
|
+
} else {
|
|
2961
|
+
result = await invokeClassHandler5(handler, context, validatedPayload);
|
|
2962
|
+
}
|
|
2963
|
+
}, "custom");
|
|
2964
|
+
return result;
|
|
2965
|
+
}
|
|
2966
|
+
__name(executeCustomPipeline, "executeCustomPipeline");
|
|
2967
|
+
async function invokeClassHandler5(handler, context, validatedPayload) {
|
|
2968
|
+
const args = [];
|
|
2969
|
+
const sorted = [
|
|
2970
|
+
...handler.paramMetadata
|
|
2971
|
+
].sort((a, b) => a.index - b.index);
|
|
2972
|
+
for (const meta of sorted) {
|
|
2973
|
+
args[meta.index] = extractCustomParam(meta, context, validatedPayload);
|
|
2974
|
+
}
|
|
2975
|
+
const instance = await resolveHandlerInstance(handler, context.container);
|
|
2976
|
+
return handler.handlerFn.apply(instance, args);
|
|
2977
|
+
}
|
|
2978
|
+
__name(invokeClassHandler5, "invokeClassHandler");
|
|
2979
|
+
async function invokeFunctionHandler5(handler, context, validatedPayload) {
|
|
2980
|
+
const deps = [];
|
|
2981
|
+
if (handler.injectTokens && handler.injectTokens.length > 0) {
|
|
2982
|
+
for (const token of handler.injectTokens) {
|
|
2983
|
+
deps.push(await context.container.resolve(token));
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
return handler.handlerFn(validatedPayload, context, ...deps);
|
|
2987
|
+
}
|
|
2988
|
+
__name(invokeFunctionHandler5, "invokeFunctionHandler");
|
|
2989
|
+
function extractCustomParam(meta, context, validatedPayload) {
|
|
2990
|
+
switch (meta.type) {
|
|
2991
|
+
case "payload":
|
|
2992
|
+
return validatedPayload;
|
|
2993
|
+
case "invokeContext":
|
|
2994
|
+
return context;
|
|
2995
|
+
default:
|
|
2996
|
+
return void 0;
|
|
2997
|
+
}
|
|
2998
|
+
}
|
|
2999
|
+
__name(extractCustomParam, "extractCustomParam");
|
|
3000
|
+
|
|
3001
|
+
// src/testing/test-app.ts
|
|
3002
|
+
var TestingApplication = class {
|
|
3003
|
+
static {
|
|
3004
|
+
__name(this, "TestingApplication");
|
|
3005
|
+
}
|
|
3006
|
+
registry;
|
|
3007
|
+
container;
|
|
3008
|
+
systemLayers;
|
|
3009
|
+
appLayers;
|
|
3010
|
+
constructor(registry, container, systemLayers = [], appLayers = []) {
|
|
3011
|
+
this.registry = registry;
|
|
3012
|
+
this.container = container;
|
|
3013
|
+
this.systemLayers = systemLayers;
|
|
3014
|
+
this.appLayers = appLayers;
|
|
3015
|
+
}
|
|
3016
|
+
async injectHttp(request) {
|
|
3017
|
+
const handler = this.registry.getHandler("http", `${request.method} ${request.path}`);
|
|
3018
|
+
if (!handler) {
|
|
3019
|
+
throw new NotFoundException(`No handler found for ${request.method} ${request.path}`);
|
|
3020
|
+
}
|
|
3021
|
+
return executeHttpPipeline(handler, request, {
|
|
3022
|
+
container: this.container,
|
|
3023
|
+
systemLayers: this.systemLayers,
|
|
3024
|
+
appLayers: this.appLayers
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
async injectWebSocket(route, message) {
|
|
3028
|
+
const handler = this.registry.getHandler("websocket", route);
|
|
3029
|
+
if (!handler) {
|
|
3030
|
+
throw new NotFoundException(`No WebSocket handler found for route: ${route}`);
|
|
3031
|
+
}
|
|
3032
|
+
await executeWebSocketPipeline(handler, message, {
|
|
3033
|
+
container: this.container,
|
|
3034
|
+
systemLayers: this.systemLayers,
|
|
3035
|
+
appLayers: this.appLayers
|
|
3036
|
+
});
|
|
3037
|
+
}
|
|
3038
|
+
async injectConsumer(handlerTag, event) {
|
|
3039
|
+
const handler = this.registry.getHandler("consumer", handlerTag);
|
|
3040
|
+
if (!handler) {
|
|
3041
|
+
throw new NotFoundException(`No consumer handler found for tag: ${handlerTag}`);
|
|
3042
|
+
}
|
|
3043
|
+
return executeConsumerPipeline(handler, event, {
|
|
3044
|
+
container: this.container,
|
|
3045
|
+
systemLayers: this.systemLayers,
|
|
3046
|
+
appLayers: this.appLayers
|
|
3047
|
+
});
|
|
3048
|
+
}
|
|
3049
|
+
async injectSchedule(handlerTag, event) {
|
|
3050
|
+
const handler = this.registry.getHandler("schedule", handlerTag);
|
|
3051
|
+
if (!handler) {
|
|
3052
|
+
throw new NotFoundException(`No schedule handler found for tag: ${handlerTag}`);
|
|
3053
|
+
}
|
|
3054
|
+
return executeSchedulePipeline(handler, event, {
|
|
3055
|
+
container: this.container,
|
|
3056
|
+
systemLayers: this.systemLayers,
|
|
3057
|
+
appLayers: this.appLayers
|
|
3058
|
+
});
|
|
3059
|
+
}
|
|
3060
|
+
async injectCustom(name, payload) {
|
|
3061
|
+
const handler = this.registry.getHandler("custom", name);
|
|
3062
|
+
if (!handler) {
|
|
3063
|
+
throw new NotFoundException(`No custom handler found for name: ${name}`);
|
|
3064
|
+
}
|
|
3065
|
+
return executeCustomPipeline(handler, payload ?? null, {
|
|
3066
|
+
container: this.container,
|
|
3067
|
+
systemLayers: this.systemLayers,
|
|
3068
|
+
appLayers: this.appLayers
|
|
3069
|
+
});
|
|
3070
|
+
}
|
|
3071
|
+
getContainer() {
|
|
3072
|
+
return this.container;
|
|
3073
|
+
}
|
|
3074
|
+
getRegistry() {
|
|
3075
|
+
return this.registry;
|
|
3076
|
+
}
|
|
3077
|
+
};
|
|
3078
|
+
function mockRequest(method, path, options = {}) {
|
|
3079
|
+
return {
|
|
3080
|
+
method,
|
|
3081
|
+
path,
|
|
3082
|
+
pathParams: options.pathParams ?? {},
|
|
3083
|
+
query: options.query ?? {},
|
|
3084
|
+
headers: options.headers ?? {},
|
|
3085
|
+
cookies: options.cookies ?? {},
|
|
3086
|
+
textBody: options.body !== void 0 ? JSON.stringify(options.body) : null,
|
|
3087
|
+
binaryBody: null,
|
|
3088
|
+
contentType: options.body !== void 0 ? "application/json" : null,
|
|
3089
|
+
requestId: options.requestId ?? "test-request-id",
|
|
3090
|
+
requestTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3091
|
+
auth: options.auth ?? null,
|
|
3092
|
+
clientIp: options.clientIp ?? "127.0.0.1",
|
|
3093
|
+
traceContext: null,
|
|
3094
|
+
userAgent: "celerity-testing",
|
|
3095
|
+
matchedRoute: null
|
|
3096
|
+
};
|
|
3097
|
+
}
|
|
3098
|
+
__name(mockRequest, "mockRequest");
|
|
3099
|
+
function mockWebSocketMessage(options = {}) {
|
|
3100
|
+
return {
|
|
3101
|
+
messageType: options.messageType ?? "json",
|
|
3102
|
+
eventType: options.eventType ?? "message",
|
|
3103
|
+
connectionId: options.connectionId ?? "test-conn-id",
|
|
3104
|
+
messageId: options.messageId ?? "test-msg-id",
|
|
3105
|
+
jsonBody: options.jsonBody ?? null,
|
|
3106
|
+
binaryBody: options.binaryBody,
|
|
3107
|
+
traceContext: options.traceContext ?? null
|
|
3108
|
+
};
|
|
3109
|
+
}
|
|
3110
|
+
__name(mockWebSocketMessage, "mockWebSocketMessage");
|
|
3111
|
+
function mockConsumerEvent(handlerTag, messages, options = {}) {
|
|
3112
|
+
const builtMessages = messages.map((msg, index) => ({
|
|
3113
|
+
messageId: msg.messageId ?? `msg-${index}`,
|
|
3114
|
+
body: msg.body,
|
|
3115
|
+
source: msg.source ?? "test",
|
|
3116
|
+
...msg.sourceType !== void 0 && {
|
|
3117
|
+
sourceType: msg.sourceType
|
|
3118
|
+
},
|
|
3119
|
+
...msg.sourceName !== void 0 && {
|
|
3120
|
+
sourceName: msg.sourceName
|
|
3121
|
+
},
|
|
3122
|
+
...msg.eventType !== void 0 && {
|
|
3123
|
+
eventType: msg.eventType
|
|
3124
|
+
},
|
|
3125
|
+
messageAttributes: msg.messageAttributes ?? {},
|
|
3126
|
+
vendor: {}
|
|
3127
|
+
}));
|
|
3128
|
+
return {
|
|
3129
|
+
handlerTag,
|
|
3130
|
+
messages: builtMessages,
|
|
3131
|
+
vendor: options.vendor ?? {},
|
|
3132
|
+
traceContext: options.traceContext ?? null
|
|
3133
|
+
};
|
|
3134
|
+
}
|
|
3135
|
+
__name(mockConsumerEvent, "mockConsumerEvent");
|
|
3136
|
+
function mockScheduleEvent(handlerTag, options = {}) {
|
|
3137
|
+
return {
|
|
3138
|
+
handlerTag,
|
|
3139
|
+
scheduleId: options.scheduleId ?? handlerTag,
|
|
3140
|
+
messageId: options.messageId ?? "test-schedule-msg-id",
|
|
3141
|
+
schedule: options.schedule ?? "rate(1 day)",
|
|
3142
|
+
input: options.input,
|
|
3143
|
+
vendor: options.vendor ?? {},
|
|
3144
|
+
traceContext: options.traceContext ?? null
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
__name(mockScheduleEvent, "mockScheduleEvent");
|
|
3148
|
+
|
|
3149
|
+
// src/application/factory.ts
|
|
3150
|
+
var debug17 = (0, import_debug17.default)("celerity:core:factory");
|
|
3151
|
+
var CelerityFactory = class {
|
|
3152
|
+
static {
|
|
3153
|
+
__name(this, "CelerityFactory");
|
|
3154
|
+
}
|
|
3155
|
+
static async create(rootModule, options) {
|
|
3156
|
+
debug17("create: bootstrapping %s", rootModule.name);
|
|
3157
|
+
const systemLayers = options?.systemLayers ?? await createDefaultSystemLayers();
|
|
3158
|
+
const appLayers = options?.layers ?? [];
|
|
3159
|
+
debug17("create: %d system layers, %d app layers", systemLayers.length, appLayers.length);
|
|
3160
|
+
const { container, registry } = await bootstrap(rootModule);
|
|
3161
|
+
if (options?.adapter) {
|
|
3162
|
+
debug17("create: using adapter \u2192 ServerlessApplication");
|
|
3163
|
+
return new ServerlessApplication(registry, container, options.adapter, systemLayers, appLayers);
|
|
3164
|
+
}
|
|
3165
|
+
debug17("create: \u2192 CelerityApplication");
|
|
3166
|
+
return new CelerityApplication(registry, container, systemLayers, appLayers);
|
|
3167
|
+
}
|
|
3168
|
+
static async createTestingApp(rootModule, options) {
|
|
3169
|
+
debug17("createTestingApp: bootstrapping %s", rootModule.name);
|
|
3170
|
+
const { container, registry } = await bootstrap(rootModule);
|
|
3171
|
+
const systemLayers = options?.systemLayers ?? [];
|
|
3172
|
+
const appLayers = options?.layers ?? [];
|
|
3173
|
+
return new TestingApplication(registry, container, systemLayers, appLayers);
|
|
3174
|
+
}
|
|
3175
|
+
};
|
|
3176
|
+
|
|
3177
|
+
// src/functions/create-handler.ts
|
|
3178
|
+
function createHttpHandler(config, handler) {
|
|
3179
|
+
const metadata = {
|
|
3180
|
+
schema: config.schema,
|
|
3181
|
+
layers: config.layers ?? [],
|
|
1725
3182
|
inject: config.inject ?? [],
|
|
1726
3183
|
customMetadata: config.metadata ?? {}
|
|
1727
3184
|
};
|
|
@@ -1806,22 +3263,130 @@ function httpDelete(path, handlerOrOptions, maybeHandler) {
|
|
|
1806
3263
|
}
|
|
1807
3264
|
__name(httpDelete, "httpDelete");
|
|
1808
3265
|
|
|
3266
|
+
// src/functions/create-guard.ts
|
|
3267
|
+
function createGuard(config, handler) {
|
|
3268
|
+
return {
|
|
3269
|
+
__celerity_guard: true,
|
|
3270
|
+
name: config.name,
|
|
3271
|
+
handler,
|
|
3272
|
+
metadata: {
|
|
3273
|
+
inject: config.inject ?? [],
|
|
3274
|
+
customMetadata: config.metadata ?? {}
|
|
3275
|
+
}
|
|
3276
|
+
};
|
|
3277
|
+
}
|
|
3278
|
+
__name(createGuard, "createGuard");
|
|
3279
|
+
|
|
3280
|
+
// src/functions/create-websocket-handler.ts
|
|
3281
|
+
function createWebSocketHandler(config, handler) {
|
|
3282
|
+
const metadata = {
|
|
3283
|
+
layers: config.layers ?? [],
|
|
3284
|
+
inject: config.inject ?? [],
|
|
3285
|
+
customMetadata: config.metadata ?? {}
|
|
3286
|
+
};
|
|
3287
|
+
if (config.route !== void 0) metadata.route = config.route;
|
|
3288
|
+
if (config.protectedBy !== void 0) metadata.protectedBy = config.protectedBy;
|
|
3289
|
+
if (config.schema !== void 0) metadata.schema = config.schema;
|
|
3290
|
+
return {
|
|
3291
|
+
__celerity_handler: true,
|
|
3292
|
+
type: "websocket",
|
|
3293
|
+
metadata,
|
|
3294
|
+
handler
|
|
3295
|
+
};
|
|
3296
|
+
}
|
|
3297
|
+
__name(createWebSocketHandler, "createWebSocketHandler");
|
|
3298
|
+
|
|
3299
|
+
// src/functions/create-consumer-handler.ts
|
|
3300
|
+
function createConsumerHandler(config, handler) {
|
|
3301
|
+
const metadata = {
|
|
3302
|
+
layers: config.layers ?? [],
|
|
3303
|
+
inject: config.inject ?? [],
|
|
3304
|
+
customMetadata: config.metadata ?? {}
|
|
3305
|
+
};
|
|
3306
|
+
if (config.route !== void 0) metadata.route = config.route;
|
|
3307
|
+
if (config.messageSchema !== void 0) metadata.messageSchema = config.messageSchema;
|
|
3308
|
+
return {
|
|
3309
|
+
__celerity_handler: true,
|
|
3310
|
+
type: "consumer",
|
|
3311
|
+
metadata,
|
|
3312
|
+
handler
|
|
3313
|
+
};
|
|
3314
|
+
}
|
|
3315
|
+
__name(createConsumerHandler, "createConsumerHandler");
|
|
3316
|
+
|
|
3317
|
+
// src/functions/create-schedule-handler.ts
|
|
3318
|
+
function isScheduleExpression2(value) {
|
|
3319
|
+
return value.startsWith("rate(") || value.startsWith("cron(");
|
|
3320
|
+
}
|
|
3321
|
+
__name(isScheduleExpression2, "isScheduleExpression");
|
|
3322
|
+
function createScheduleHandler(configOrString, configOrHandler, maybeHandler) {
|
|
3323
|
+
let config;
|
|
3324
|
+
let handler;
|
|
3325
|
+
if (typeof configOrString === "string") {
|
|
3326
|
+
config = {
|
|
3327
|
+
...configOrHandler
|
|
3328
|
+
};
|
|
3329
|
+
handler = maybeHandler;
|
|
3330
|
+
if (isScheduleExpression2(configOrString)) {
|
|
3331
|
+
config.schedule = configOrString;
|
|
3332
|
+
} else {
|
|
3333
|
+
config.source = configOrString;
|
|
3334
|
+
}
|
|
3335
|
+
} else {
|
|
3336
|
+
config = configOrString;
|
|
3337
|
+
handler = configOrHandler;
|
|
3338
|
+
}
|
|
3339
|
+
const metadata = {
|
|
3340
|
+
layers: config.layers ?? [],
|
|
3341
|
+
inject: config.inject ?? [],
|
|
3342
|
+
customMetadata: config.metadata ?? {}
|
|
3343
|
+
};
|
|
3344
|
+
if (config.source !== void 0) metadata.source = config.source;
|
|
3345
|
+
if (config.schedule !== void 0) metadata.schedule = config.schedule;
|
|
3346
|
+
if (config.schema !== void 0) metadata.schema = config.schema;
|
|
3347
|
+
return {
|
|
3348
|
+
__celerity_handler: true,
|
|
3349
|
+
type: "schedule",
|
|
3350
|
+
metadata,
|
|
3351
|
+
handler
|
|
3352
|
+
};
|
|
3353
|
+
}
|
|
3354
|
+
__name(createScheduleHandler, "createScheduleHandler");
|
|
3355
|
+
|
|
3356
|
+
// src/functions/create-custom-handler.ts
|
|
3357
|
+
function createCustomHandler(config, handler) {
|
|
3358
|
+
const metadata = {
|
|
3359
|
+
layers: config.layers ?? [],
|
|
3360
|
+
inject: config.inject ?? [],
|
|
3361
|
+
customMetadata: config.metadata ?? {}
|
|
3362
|
+
};
|
|
3363
|
+
if (config.name !== void 0) metadata.name = config.name;
|
|
3364
|
+
if (config.schema !== void 0) metadata.schema = config.schema;
|
|
3365
|
+
return {
|
|
3366
|
+
__celerity_handler: true,
|
|
3367
|
+
type: "custom",
|
|
3368
|
+
metadata,
|
|
3369
|
+
handler
|
|
3370
|
+
};
|
|
3371
|
+
}
|
|
3372
|
+
__name(createCustomHandler, "createCustomHandler");
|
|
3373
|
+
|
|
1809
3374
|
// src/handlers/module-resolver.ts
|
|
1810
3375
|
var import_node_path = require("path");
|
|
1811
|
-
var
|
|
1812
|
-
var
|
|
1813
|
-
async function resolveHandlerByModuleRef(handlerId, registry, baseDir) {
|
|
3376
|
+
var import_debug18 = __toESM(require("debug"), 1);
|
|
3377
|
+
var debug18 = (0, import_debug18.default)("celerity:core:module-resolver");
|
|
3378
|
+
async function resolveHandlerByModuleRef(handlerId, handlerType, registry, baseDir) {
|
|
1814
3379
|
const lastDot = handlerId.lastIndexOf(".");
|
|
1815
3380
|
if (lastDot > 0) {
|
|
1816
3381
|
const moduleName = handlerId.slice(0, lastDot);
|
|
1817
3382
|
const exportName = handlerId.slice(lastDot + 1);
|
|
1818
|
-
const result = await tryResolveExport(baseDir, moduleName, exportName, handlerId, registry);
|
|
3383
|
+
const result = await tryResolveExport(baseDir, moduleName, exportName, handlerId, handlerType, registry);
|
|
1819
3384
|
if (result) return result;
|
|
1820
3385
|
}
|
|
1821
|
-
return tryResolveExport(baseDir, handlerId, "default", handlerId, registry);
|
|
3386
|
+
return tryResolveExport(baseDir, handlerId, "default", handlerId, handlerType, registry);
|
|
1822
3387
|
}
|
|
1823
3388
|
__name(resolveHandlerByModuleRef, "resolveHandlerByModuleRef");
|
|
1824
|
-
async function tryResolveExport(baseDir, moduleName, exportName, handlerId, registry) {
|
|
3389
|
+
async function tryResolveExport(baseDir, moduleName, exportName, handlerId, handlerType, registry) {
|
|
1825
3390
|
const handlerModulePath = (0, import_node_path.resolve)(baseDir, moduleName);
|
|
1826
3391
|
let mod;
|
|
1827
3392
|
try {
|
|
@@ -1836,66 +3401,236 @@ async function tryResolveExport(baseDir, moduleName, exportName, handlerId, regi
|
|
|
1836
3401
|
const exported = mod[exportName];
|
|
1837
3402
|
if (!exported) return null;
|
|
1838
3403
|
const isFnDef = typeof exported === "object" && exported !== null && exported.__celerity_handler;
|
|
3404
|
+
if (isFnDef && exported.type !== handlerType) {
|
|
3405
|
+
return null;
|
|
3406
|
+
}
|
|
1839
3407
|
const handlerFn = isFnDef ? exported.handler : exported;
|
|
1840
3408
|
if (typeof handlerFn !== "function") return null;
|
|
1841
|
-
const
|
|
3409
|
+
const handlers = registry.getHandlersByType(handlerType);
|
|
3410
|
+
const match = handlers.find((h) => h.handlerFn === handlerFn);
|
|
1842
3411
|
if (match) {
|
|
1843
3412
|
match.id = handlerId;
|
|
1844
|
-
|
|
3413
|
+
debug18("matched '%s' to registry handler", handlerId);
|
|
1845
3414
|
return match;
|
|
1846
3415
|
}
|
|
1847
|
-
|
|
1848
|
-
return buildResolvedFromExport(handlerId, handlerFn, isFnDef ? exported : null);
|
|
3416
|
+
debug18("'%s' not in registry, wrapping directly", handlerId);
|
|
3417
|
+
return buildResolvedFromExport(handlerId, handlerType, handlerFn, isFnDef ? exported : null);
|
|
1849
3418
|
}
|
|
1850
3419
|
__name(tryResolveExport, "tryResolveExport");
|
|
1851
|
-
function buildResolvedFromExport(handlerId, handlerFn, fnDef) {
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
return {
|
|
1855
|
-
id: handlerId,
|
|
1856
|
-
protectedBy: [],
|
|
1857
|
-
layers: [
|
|
1858
|
-
...meta.layers ?? []
|
|
1859
|
-
],
|
|
1860
|
-
isPublic: false,
|
|
1861
|
-
paramMetadata: [],
|
|
1862
|
-
customMetadata: meta.customMetadata ?? {},
|
|
1863
|
-
handlerFn,
|
|
1864
|
-
isFunctionHandler: true,
|
|
1865
|
-
injectTokens: meta.inject ?? []
|
|
1866
|
-
};
|
|
1867
|
-
}
|
|
1868
|
-
return {
|
|
3420
|
+
function buildResolvedFromExport(handlerId, handlerType, handlerFn, fnDef) {
|
|
3421
|
+
const meta = fnDef ? fnDef.metadata : null;
|
|
3422
|
+
const base = {
|
|
1869
3423
|
id: handlerId,
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
3424
|
+
layers: [
|
|
3425
|
+
...meta?.layers ?? []
|
|
3426
|
+
],
|
|
1873
3427
|
paramMetadata: [],
|
|
1874
|
-
customMetadata: {},
|
|
3428
|
+
customMetadata: meta?.customMetadata ?? {},
|
|
1875
3429
|
handlerFn,
|
|
1876
3430
|
isFunctionHandler: true,
|
|
1877
|
-
injectTokens: []
|
|
3431
|
+
injectTokens: meta?.inject ?? []
|
|
3432
|
+
};
|
|
3433
|
+
const guardFields = {
|
|
3434
|
+
protectedBy: [],
|
|
3435
|
+
isPublic: false
|
|
1878
3436
|
};
|
|
3437
|
+
switch (handlerType) {
|
|
3438
|
+
case "http":
|
|
3439
|
+
return {
|
|
3440
|
+
...base,
|
|
3441
|
+
...guardFields,
|
|
3442
|
+
type: "http",
|
|
3443
|
+
...meta?.path !== void 0 ? {
|
|
3444
|
+
path: meta.path
|
|
3445
|
+
} : {},
|
|
3446
|
+
...meta?.method !== void 0 ? {
|
|
3447
|
+
method: meta.method
|
|
3448
|
+
} : {}
|
|
3449
|
+
};
|
|
3450
|
+
case "websocket":
|
|
3451
|
+
return {
|
|
3452
|
+
...base,
|
|
3453
|
+
...guardFields,
|
|
3454
|
+
type: "websocket",
|
|
3455
|
+
route: meta?.route ?? handlerId
|
|
3456
|
+
};
|
|
3457
|
+
case "consumer":
|
|
3458
|
+
return {
|
|
3459
|
+
...base,
|
|
3460
|
+
type: "consumer",
|
|
3461
|
+
handlerTag: meta?.route ?? handlerId
|
|
3462
|
+
};
|
|
3463
|
+
case "schedule":
|
|
3464
|
+
return {
|
|
3465
|
+
...base,
|
|
3466
|
+
type: "schedule",
|
|
3467
|
+
handlerTag: meta?.source ?? handlerId
|
|
3468
|
+
};
|
|
3469
|
+
case "custom":
|
|
3470
|
+
return {
|
|
3471
|
+
...base,
|
|
3472
|
+
type: "custom",
|
|
3473
|
+
name: meta?.name ?? handlerId
|
|
3474
|
+
};
|
|
3475
|
+
}
|
|
1879
3476
|
}
|
|
1880
3477
|
__name(buildResolvedFromExport, "buildResolvedFromExport");
|
|
1881
3478
|
|
|
3479
|
+
// src/handlers/websocket-sender.ts
|
|
3480
|
+
var RuntimeWebSocketSender = class {
|
|
3481
|
+
static {
|
|
3482
|
+
__name(this, "RuntimeWebSocketSender");
|
|
3483
|
+
}
|
|
3484
|
+
registry;
|
|
3485
|
+
constructor(registry) {
|
|
3486
|
+
this.registry = registry;
|
|
3487
|
+
}
|
|
3488
|
+
async sendMessage(connectionId, data, options) {
|
|
3489
|
+
const messageId = options?.messageId ?? crypto.randomUUID();
|
|
3490
|
+
const messageType = options?.messageType === "binary" ? "binary" : "json";
|
|
3491
|
+
const payload = typeof data === "string" ? data : JSON.stringify(data);
|
|
3492
|
+
await this.registry.sendMessage(connectionId, messageId, messageType, payload);
|
|
3493
|
+
}
|
|
3494
|
+
};
|
|
3495
|
+
|
|
3496
|
+
// src/handlers/guard-pipeline.ts
|
|
3497
|
+
var import_debug19 = __toESM(require("debug"), 1);
|
|
3498
|
+
var debug19 = (0, import_debug19.default)("celerity:core:guard-pipeline");
|
|
3499
|
+
async function executeGuardPipeline(guard, input, options) {
|
|
3500
|
+
const metadata = new HandlerMetadataStore({
|
|
3501
|
+
...guard.customMetadata ?? {},
|
|
3502
|
+
...options.handlerMetadata ?? {}
|
|
3503
|
+
});
|
|
3504
|
+
const logger = await createGuardLogger(guard.name, input, options.container);
|
|
3505
|
+
try {
|
|
3506
|
+
const result = guard.isFunctionGuard ? await invokeFunctionGuard(guard, input, metadata, options, logger) : await invokeClassGuard(guard, input, metadata, options, logger);
|
|
3507
|
+
debug19("guard %s \u2014 allowed", guard.name);
|
|
3508
|
+
return {
|
|
3509
|
+
allowed: true,
|
|
3510
|
+
auth: result ?? {}
|
|
3511
|
+
};
|
|
3512
|
+
} catch (error) {
|
|
3513
|
+
if (error instanceof HttpException) {
|
|
3514
|
+
debug19("guard %s \u2014 rejected %d: %s", guard.name, error.statusCode, error.message);
|
|
3515
|
+
return {
|
|
3516
|
+
allowed: false,
|
|
3517
|
+
statusCode: error.statusCode,
|
|
3518
|
+
message: error.message,
|
|
3519
|
+
details: error.details
|
|
3520
|
+
};
|
|
3521
|
+
}
|
|
3522
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
3523
|
+
debug19("guard %s \u2014 unexpected error: %s", guard.name, message);
|
|
3524
|
+
return {
|
|
3525
|
+
allowed: false,
|
|
3526
|
+
statusCode: 401,
|
|
3527
|
+
message: "Unauthorized"
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
__name(executeGuardPipeline, "executeGuardPipeline");
|
|
3532
|
+
async function createGuardLogger(guardName, input, container) {
|
|
3533
|
+
const attrs = {
|
|
3534
|
+
guard: guardName,
|
|
3535
|
+
requestId: input.requestId,
|
|
3536
|
+
method: input.method,
|
|
3537
|
+
path: input.path,
|
|
3538
|
+
clientIp: input.clientIp,
|
|
3539
|
+
...input.handlerName ? {
|
|
3540
|
+
handlerName: input.handlerName
|
|
3541
|
+
} : {}
|
|
3542
|
+
};
|
|
3543
|
+
if (container.has("CelerityLogger")) {
|
|
3544
|
+
const root = await container.resolve("CelerityLogger");
|
|
3545
|
+
return root.child("guard", attrs);
|
|
3546
|
+
}
|
|
3547
|
+
const pkg = "@celerity-sdk/telemetry";
|
|
3548
|
+
const { createLogger, readTelemetryEnv } = await import(pkg);
|
|
3549
|
+
const rootLogger = await createLogger(readTelemetryEnv());
|
|
3550
|
+
return rootLogger.child("guard", attrs);
|
|
3551
|
+
}
|
|
3552
|
+
__name(createGuardLogger, "createGuardLogger");
|
|
3553
|
+
async function invokeClassGuard(guard, input, metadata, options, logger) {
|
|
3554
|
+
const guardContext = {
|
|
3555
|
+
token: input.token,
|
|
3556
|
+
auth: input.auth,
|
|
3557
|
+
request: {
|
|
3558
|
+
method: input.method,
|
|
3559
|
+
path: input.path,
|
|
3560
|
+
headers: input.headers,
|
|
3561
|
+
query: input.query,
|
|
3562
|
+
cookies: input.cookies,
|
|
3563
|
+
body: input.body,
|
|
3564
|
+
requestId: input.requestId,
|
|
3565
|
+
clientIp: input.clientIp
|
|
3566
|
+
},
|
|
3567
|
+
metadata,
|
|
3568
|
+
container: options.container,
|
|
3569
|
+
logger
|
|
3570
|
+
};
|
|
3571
|
+
const paramCount = guard.handlerFn.length;
|
|
3572
|
+
const args = new Array(paramCount);
|
|
3573
|
+
const decorated = new Set(guard.paramMetadata.map((m) => m.index));
|
|
3574
|
+
for (const meta of guard.paramMetadata) {
|
|
3575
|
+
if (meta.type === "token") {
|
|
3576
|
+
args[meta.index] = guardContext.token;
|
|
3577
|
+
} else if (meta.type === "auth") {
|
|
3578
|
+
args[meta.index] = guardContext.auth;
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
for (let i = 0; i < paramCount; i++) {
|
|
3582
|
+
if (!decorated.has(i)) {
|
|
3583
|
+
args[i] = guardContext;
|
|
3584
|
+
}
|
|
3585
|
+
}
|
|
3586
|
+
const instance = await resolveGuardInstance(guard, options.container);
|
|
3587
|
+
return guard.handlerFn.apply(instance, args);
|
|
3588
|
+
}
|
|
3589
|
+
__name(invokeClassGuard, "invokeClassGuard");
|
|
3590
|
+
async function invokeFunctionGuard(guard, input, metadata, options, logger) {
|
|
3591
|
+
const req = {
|
|
3592
|
+
token: input.token,
|
|
3593
|
+
headers: input.headers,
|
|
3594
|
+
query: input.query,
|
|
3595
|
+
cookies: input.cookies,
|
|
3596
|
+
body: input.body,
|
|
3597
|
+
requestId: input.requestId,
|
|
3598
|
+
clientIp: input.clientIp
|
|
3599
|
+
};
|
|
3600
|
+
const ctx = {
|
|
3601
|
+
metadata,
|
|
3602
|
+
container: options.container,
|
|
3603
|
+
auth: input.auth,
|
|
3604
|
+
logger
|
|
3605
|
+
};
|
|
3606
|
+
if (guard.injectTokens && guard.injectTokens.length > 0) {
|
|
3607
|
+
const deps = [];
|
|
3608
|
+
for (const token of guard.injectTokens) {
|
|
3609
|
+
deps.push(await options.container.resolve(token));
|
|
3610
|
+
}
|
|
3611
|
+
return guard.handlerFn(req, ctx, ...deps);
|
|
3612
|
+
}
|
|
3613
|
+
return guard.handlerFn(req, ctx);
|
|
3614
|
+
}
|
|
3615
|
+
__name(invokeFunctionGuard, "invokeFunctionGuard");
|
|
3616
|
+
|
|
1882
3617
|
// src/bootstrap/discovery.ts
|
|
1883
3618
|
var import_node_path2 = require("path");
|
|
1884
|
-
var
|
|
1885
|
-
var
|
|
3619
|
+
var import_debug20 = __toESM(require("debug"), 1);
|
|
3620
|
+
var debug20 = (0, import_debug20.default)("celerity:core:bootstrap");
|
|
1886
3621
|
async function discoverModule(modulePath) {
|
|
1887
3622
|
const resolved = modulePath ?? process.env.CELERITY_MODULE_PATH;
|
|
1888
3623
|
if (!resolved) {
|
|
1889
3624
|
throw new Error("Cannot discover module: set CELERITY_MODULE_PATH environment variable or pass modulePath");
|
|
1890
3625
|
}
|
|
1891
3626
|
const absolutePath = (0, import_node_path2.resolve)(resolved);
|
|
1892
|
-
|
|
3627
|
+
debug20("discoverModule: importing %s", absolutePath);
|
|
1893
3628
|
const imported = await import(absolutePath);
|
|
1894
3629
|
const rootModule = imported.default ?? findModuleExport(imported);
|
|
1895
3630
|
if (!rootModule || typeof rootModule !== "function") {
|
|
1896
3631
|
throw new Error(`No module class found in "${resolved}"`);
|
|
1897
3632
|
}
|
|
1898
|
-
|
|
3633
|
+
debug20("discoverModule: found %s", rootModule.name);
|
|
1899
3634
|
return rootModule;
|
|
1900
3635
|
}
|
|
1901
3636
|
__name(discoverModule, "discoverModule");
|
|
@@ -1949,61 +3684,366 @@ function mapToRuntimeResponse(response) {
|
|
|
1949
3684
|
};
|
|
1950
3685
|
}
|
|
1951
3686
|
__name(mapToRuntimeResponse, "mapToRuntimeResponse");
|
|
3687
|
+
function mapWebSocketMessage(info) {
|
|
3688
|
+
const requestContext = info.requestContext ? {
|
|
3689
|
+
requestId: info.requestContext.requestId,
|
|
3690
|
+
requestTime: info.requestContext.requestTime,
|
|
3691
|
+
path: info.requestContext.path,
|
|
3692
|
+
protocolVersion: info.requestContext.protocolVersion,
|
|
3693
|
+
headers: flattenMultiValueRecord(info.requestContext.headers),
|
|
3694
|
+
userAgent: info.requestContext.userAgent,
|
|
3695
|
+
clientIp: info.requestContext.clientIp,
|
|
3696
|
+
query: flattenMultiValueRecord(info.requestContext.query),
|
|
3697
|
+
cookies: info.requestContext.cookies,
|
|
3698
|
+
auth: info.requestContext.auth,
|
|
3699
|
+
traceContext: info.requestContext.traceContext
|
|
3700
|
+
} : void 0;
|
|
3701
|
+
return {
|
|
3702
|
+
messageType: info.messageType,
|
|
3703
|
+
eventType: info.eventType,
|
|
3704
|
+
connectionId: info.connectionId,
|
|
3705
|
+
messageId: info.messageId,
|
|
3706
|
+
jsonBody: info.jsonBody,
|
|
3707
|
+
binaryBody: info.binaryBody,
|
|
3708
|
+
requestContext,
|
|
3709
|
+
traceContext: info.traceContext ?? null
|
|
3710
|
+
};
|
|
3711
|
+
}
|
|
3712
|
+
__name(mapWebSocketMessage, "mapWebSocketMessage");
|
|
3713
|
+
function mapConsumerEventInput(input) {
|
|
3714
|
+
return {
|
|
3715
|
+
handlerTag: input.handlerTag,
|
|
3716
|
+
messages: input.messages.map((msg) => {
|
|
3717
|
+
const m = msg;
|
|
3718
|
+
return {
|
|
3719
|
+
messageId: msg.messageId,
|
|
3720
|
+
body: msg.body,
|
|
3721
|
+
source: msg.source,
|
|
3722
|
+
...m.sourceType !== void 0 && {
|
|
3723
|
+
sourceType: m.sourceType
|
|
3724
|
+
},
|
|
3725
|
+
...m.sourceName !== void 0 && {
|
|
3726
|
+
sourceName: m.sourceName
|
|
3727
|
+
},
|
|
3728
|
+
...m.eventType !== void 0 && {
|
|
3729
|
+
eventType: m.eventType
|
|
3730
|
+
},
|
|
3731
|
+
messageAttributes: msg.messageAttributes,
|
|
3732
|
+
vendor: msg.vendor
|
|
3733
|
+
};
|
|
3734
|
+
}),
|
|
3735
|
+
vendor: input.vendor,
|
|
3736
|
+
traceContext: input.traceContext ?? null
|
|
3737
|
+
};
|
|
3738
|
+
}
|
|
3739
|
+
__name(mapConsumerEventInput, "mapConsumerEventInput");
|
|
3740
|
+
function mapScheduleEventInput(input) {
|
|
3741
|
+
return {
|
|
3742
|
+
handlerTag: input.handlerTag,
|
|
3743
|
+
scheduleId: input.scheduleId,
|
|
3744
|
+
messageId: input.messageId,
|
|
3745
|
+
schedule: input.schedule,
|
|
3746
|
+
input: input.input,
|
|
3747
|
+
vendor: input.vendor,
|
|
3748
|
+
traceContext: input.traceContext ?? null
|
|
3749
|
+
};
|
|
3750
|
+
}
|
|
3751
|
+
__name(mapScheduleEventInput, "mapScheduleEventInput");
|
|
3752
|
+
function mapToNapiEventResult(result) {
|
|
3753
|
+
return {
|
|
3754
|
+
success: result.success,
|
|
3755
|
+
failures: result.failures?.map((f) => ({
|
|
3756
|
+
messageId: f.messageId,
|
|
3757
|
+
errorMessage: f.errorMessage
|
|
3758
|
+
})),
|
|
3759
|
+
errorMessage: result.errorMessage
|
|
3760
|
+
};
|
|
3761
|
+
}
|
|
3762
|
+
__name(mapToNapiEventResult, "mapToNapiEventResult");
|
|
1952
3763
|
|
|
1953
3764
|
// src/bootstrap/runtime-entry.ts
|
|
1954
3765
|
var import_node_path3 = require("path");
|
|
3766
|
+
var import_debug21 = __toESM(require("debug"), 1);
|
|
3767
|
+
var debug21 = (0, import_debug21.default)("celerity:core:runtime-entry");
|
|
1955
3768
|
async function bootstrapForRuntime(modulePath, systemLayers) {
|
|
1956
3769
|
const layers = systemLayers ?? await createDefaultSystemLayers();
|
|
1957
3770
|
const resolvedModulePath = modulePath ?? process.env.CELERITY_MODULE_PATH;
|
|
1958
3771
|
const moduleDir = resolvedModulePath ? (0, import_node_path3.dirname)((0, import_node_path3.resolve)(resolvedModulePath)) : process.cwd();
|
|
1959
3772
|
const rootModule = await discoverModule(modulePath);
|
|
1960
3773
|
const { container, registry } = await bootstrap(rootModule);
|
|
1961
|
-
function
|
|
3774
|
+
function buildHttpCallback(handler, handlerName) {
|
|
1962
3775
|
if (!handler) return null;
|
|
1963
3776
|
return async (_err, request) => {
|
|
1964
3777
|
const httpRequest = mapRuntimeRequest(request);
|
|
1965
|
-
const httpResponse = await
|
|
3778
|
+
const httpResponse = await executeHttpPipeline(handler, httpRequest, {
|
|
1966
3779
|
container,
|
|
1967
|
-
systemLayers: layers
|
|
3780
|
+
systemLayers: layers,
|
|
3781
|
+
handlerName
|
|
1968
3782
|
});
|
|
1969
3783
|
return mapToRuntimeResponse(httpResponse);
|
|
1970
3784
|
};
|
|
1971
3785
|
}
|
|
1972
|
-
__name(
|
|
3786
|
+
__name(buildHttpCallback, "buildHttpCallback");
|
|
3787
|
+
function buildWebSocketCallback(handler, handlerName) {
|
|
3788
|
+
if (!handler) return null;
|
|
3789
|
+
return async (_err, info) => {
|
|
3790
|
+
const message = mapWebSocketMessage(info);
|
|
3791
|
+
await executeWebSocketPipeline(handler, message, {
|
|
3792
|
+
container,
|
|
3793
|
+
systemLayers: layers,
|
|
3794
|
+
handlerName
|
|
3795
|
+
});
|
|
3796
|
+
};
|
|
3797
|
+
}
|
|
3798
|
+
__name(buildWebSocketCallback, "buildWebSocketCallback");
|
|
3799
|
+
function buildConsumerCallback(handler, handlerName) {
|
|
3800
|
+
if (!handler) return null;
|
|
3801
|
+
return async (_err, input) => {
|
|
3802
|
+
const event = mapConsumerEventInput(input);
|
|
3803
|
+
const result = await executeConsumerPipeline(handler, event, {
|
|
3804
|
+
container,
|
|
3805
|
+
systemLayers: layers,
|
|
3806
|
+
handlerName
|
|
3807
|
+
});
|
|
3808
|
+
return mapToNapiEventResult(result);
|
|
3809
|
+
};
|
|
3810
|
+
}
|
|
3811
|
+
__name(buildConsumerCallback, "buildConsumerCallback");
|
|
3812
|
+
function buildScheduleCallback(handler, handlerName) {
|
|
3813
|
+
if (!handler) return null;
|
|
3814
|
+
return async (_err, input) => {
|
|
3815
|
+
const event = mapScheduleEventInput(input);
|
|
3816
|
+
const result = await executeSchedulePipeline(handler, event, {
|
|
3817
|
+
container,
|
|
3818
|
+
systemLayers: layers,
|
|
3819
|
+
handlerName
|
|
3820
|
+
});
|
|
3821
|
+
return mapToNapiEventResult(result);
|
|
3822
|
+
};
|
|
3823
|
+
}
|
|
3824
|
+
__name(buildScheduleCallback, "buildScheduleCallback");
|
|
3825
|
+
function buildCustomCallback(handler, handlerName) {
|
|
3826
|
+
if (!handler) return null;
|
|
3827
|
+
return async (_err, payload) => {
|
|
3828
|
+
return executeCustomPipeline(handler, payload, {
|
|
3829
|
+
container,
|
|
3830
|
+
systemLayers: layers,
|
|
3831
|
+
handlerName
|
|
3832
|
+
});
|
|
3833
|
+
};
|
|
3834
|
+
}
|
|
3835
|
+
__name(buildCustomCallback, "buildCustomCallback");
|
|
1973
3836
|
return {
|
|
1974
3837
|
registry,
|
|
1975
3838
|
container,
|
|
1976
|
-
createRouteCallback(path,
|
|
1977
|
-
return
|
|
3839
|
+
createRouteCallback(method, path, handlerName) {
|
|
3840
|
+
return buildHttpCallback(registry.getHandler("http", `${method} ${path}`), handlerName);
|
|
3841
|
+
},
|
|
3842
|
+
async createRouteCallbackById(handlerId, codeLocation, handlerName) {
|
|
3843
|
+
const fromRegistry = registry.getHandlerById("http", handlerId);
|
|
3844
|
+
if (fromRegistry) return buildHttpCallback(fromRegistry, handlerName);
|
|
3845
|
+
const baseDir = codeLocation ? (0, import_node_path3.resolve)(codeLocation) : moduleDir;
|
|
3846
|
+
const resolved = await resolveHandlerByModuleRef(handlerId, "http", registry, baseDir);
|
|
3847
|
+
return resolved ? buildHttpCallback(resolved, handlerName) : null;
|
|
1978
3848
|
},
|
|
1979
|
-
|
|
1980
|
-
const
|
|
1981
|
-
if (
|
|
3849
|
+
createGuardCallback(guardName) {
|
|
3850
|
+
const guard = registry.getGuard(guardName);
|
|
3851
|
+
if (!guard) return null;
|
|
3852
|
+
return async (input) => {
|
|
3853
|
+
debug21("guard %s \u2014 input method=%s path=%s", guardName, input.method, input.path);
|
|
3854
|
+
const handler = registry.getHandler("http", `${input.method} ${input.path}`);
|
|
3855
|
+
debug21("guard %s \u2014 handler %s, customMetadata=%o", guardName, handler ? "found" : "not found", handler?.customMetadata);
|
|
3856
|
+
return executeGuardPipeline(guard, input, {
|
|
3857
|
+
container,
|
|
3858
|
+
handlerMetadata: handler?.customMetadata
|
|
3859
|
+
});
|
|
3860
|
+
};
|
|
3861
|
+
},
|
|
3862
|
+
createWebSocketCallback(route, handlerName) {
|
|
3863
|
+
return buildWebSocketCallback(registry.getHandler("websocket", route), handlerName);
|
|
3864
|
+
},
|
|
3865
|
+
async createWebSocketCallbackById(handlerId, codeLocation, handlerName) {
|
|
3866
|
+
const fromRegistry = registry.getHandlerById("websocket", handlerId);
|
|
3867
|
+
if (fromRegistry) return buildWebSocketCallback(fromRegistry, handlerName);
|
|
1982
3868
|
const baseDir = codeLocation ? (0, import_node_path3.resolve)(codeLocation) : moduleDir;
|
|
1983
|
-
const resolved = await resolveHandlerByModuleRef(handlerId, registry, baseDir);
|
|
1984
|
-
return resolved ?
|
|
3869
|
+
const resolved = await resolveHandlerByModuleRef(handlerId, "websocket", registry, baseDir);
|
|
3870
|
+
return resolved ? buildWebSocketCallback(resolved, handlerName) : null;
|
|
3871
|
+
},
|
|
3872
|
+
createConsumerCallback(handlerTag, handlerName) {
|
|
3873
|
+
return buildConsumerCallback(registry.getHandler("consumer", handlerTag), handlerName);
|
|
3874
|
+
},
|
|
3875
|
+
async createConsumerCallbackById(handlerId, codeLocation, handlerName) {
|
|
3876
|
+
const fromRegistry = registry.getHandlerById("consumer", handlerId);
|
|
3877
|
+
if (fromRegistry) return buildConsumerCallback(fromRegistry, handlerName);
|
|
3878
|
+
const baseDir = codeLocation ? (0, import_node_path3.resolve)(codeLocation) : moduleDir;
|
|
3879
|
+
const resolved = await resolveHandlerByModuleRef(handlerId, "consumer", registry, baseDir);
|
|
3880
|
+
return resolved ? buildConsumerCallback(resolved, handlerName) : null;
|
|
3881
|
+
},
|
|
3882
|
+
createScheduleCallback(handlerTag, handlerName) {
|
|
3883
|
+
return buildScheduleCallback(registry.getHandler("schedule", handlerTag), handlerName);
|
|
3884
|
+
},
|
|
3885
|
+
async createScheduleCallbackById(handlerId, codeLocation, handlerName) {
|
|
3886
|
+
const fromRegistry = registry.getHandlerById("schedule", handlerId);
|
|
3887
|
+
if (fromRegistry) return buildScheduleCallback(fromRegistry, handlerName);
|
|
3888
|
+
const baseDir = codeLocation ? (0, import_node_path3.resolve)(codeLocation) : moduleDir;
|
|
3889
|
+
const resolved = await resolveHandlerByModuleRef(handlerId, "schedule", registry, baseDir);
|
|
3890
|
+
return resolved ? buildScheduleCallback(resolved, handlerName) : null;
|
|
3891
|
+
},
|
|
3892
|
+
createCustomCallback(handlerName) {
|
|
3893
|
+
return buildCustomCallback(registry.getHandler("custom", handlerName), handlerName);
|
|
3894
|
+
},
|
|
3895
|
+
async createCustomCallbackById(handlerId, codeLocation, handlerName) {
|
|
3896
|
+
const fromRegistry = registry.getHandlerById("custom", handlerId);
|
|
3897
|
+
if (fromRegistry) return buildCustomCallback(fromRegistry, handlerName);
|
|
3898
|
+
const baseDir = codeLocation ? (0, import_node_path3.resolve)(codeLocation) : moduleDir;
|
|
3899
|
+
const resolved = await resolveHandlerByModuleRef(handlerId, "custom", registry, baseDir);
|
|
3900
|
+
return resolved ? buildCustomCallback(resolved, handlerName) : null;
|
|
1985
3901
|
}
|
|
1986
3902
|
};
|
|
1987
3903
|
}
|
|
1988
3904
|
__name(bootstrapForRuntime, "bootstrapForRuntime");
|
|
1989
3905
|
|
|
1990
3906
|
// src/bootstrap/runtime-orchestrator.ts
|
|
1991
|
-
|
|
3907
|
+
var import_types7 = require("@celerity-sdk/types");
|
|
3908
|
+
async function loadRuntime() {
|
|
1992
3909
|
const pkg = "@celerity-sdk/runtime";
|
|
1993
3910
|
const runtimeModule = await import(pkg);
|
|
1994
3911
|
const config = runtimeModule.runtimeConfigFromEnv();
|
|
1995
3912
|
const app = new runtimeModule.CoreRuntimeApplication(config);
|
|
1996
3913
|
const appConfig = app.setup();
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
3914
|
+
return {
|
|
3915
|
+
app,
|
|
3916
|
+
appConfig
|
|
3917
|
+
};
|
|
3918
|
+
}
|
|
3919
|
+
__name(loadRuntime, "loadRuntime");
|
|
3920
|
+
function mapGuardResult(result) {
|
|
3921
|
+
if (result.allowed) {
|
|
3922
|
+
return {
|
|
3923
|
+
status: "allowed",
|
|
3924
|
+
auth: result.auth
|
|
3925
|
+
};
|
|
3926
|
+
}
|
|
3927
|
+
const status = result.statusCode === 403 ? "forbidden" : "unauthorised";
|
|
3928
|
+
return {
|
|
3929
|
+
status,
|
|
3930
|
+
message: result.message
|
|
3931
|
+
};
|
|
3932
|
+
}
|
|
3933
|
+
__name(mapGuardResult, "mapGuardResult");
|
|
3934
|
+
async function registerHttpHandlers(app, handlers, result) {
|
|
3935
|
+
for (const def of handlers?.http?.handlers ?? []) {
|
|
3936
|
+
const callback = result.createRouteCallback(def.method, def.path, def.name) ?? await result.createRouteCallbackById(def.handler, def.location, def.name);
|
|
2000
3937
|
if (callback) {
|
|
2001
3938
|
app.registerHttpHandler(def.path, def.method, def.timeout, callback);
|
|
2002
3939
|
}
|
|
2003
3940
|
}
|
|
3941
|
+
}
|
|
3942
|
+
__name(registerHttpHandlers, "registerHttpHandlers");
|
|
3943
|
+
async function registerGuardHandlers(app, guards, result) {
|
|
3944
|
+
for (const guardDef of guards?.handlers ?? []) {
|
|
3945
|
+
const coreCallback = result.createGuardCallback(guardDef.name);
|
|
3946
|
+
if (coreCallback) {
|
|
3947
|
+
await app.registerGuardHandler(guardDef.name, async (_err, input) => {
|
|
3948
|
+
const coreResult = await coreCallback({
|
|
3949
|
+
token: input.token,
|
|
3950
|
+
method: input.request.method,
|
|
3951
|
+
path: input.request.path,
|
|
3952
|
+
headers: input.request.headers,
|
|
3953
|
+
query: input.request.query,
|
|
3954
|
+
cookies: input.request.cookies,
|
|
3955
|
+
body: input.request.body ?? null,
|
|
3956
|
+
requestId: input.request.requestId,
|
|
3957
|
+
clientIp: input.request.clientIp,
|
|
3958
|
+
auth: input.auth ?? {},
|
|
3959
|
+
handlerName: input.handlerName
|
|
3960
|
+
});
|
|
3961
|
+
return mapGuardResult(coreResult);
|
|
3962
|
+
});
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
}
|
|
3966
|
+
__name(registerGuardHandlers, "registerGuardHandlers");
|
|
3967
|
+
async function registerWebSocketHandlers(app, websocket, result) {
|
|
3968
|
+
for (const def of websocket?.handlers ?? []) {
|
|
3969
|
+
const callback = result.createWebSocketCallback(def.route, def.name) ?? await result.createWebSocketCallbackById(def.handler, def.location, def.name);
|
|
3970
|
+
if (callback) {
|
|
3971
|
+
app.registerWebsocketHandler(def.route, callback);
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
__name(registerWebSocketHandlers, "registerWebSocketHandlers");
|
|
3976
|
+
async function registerConsumerHandlers(app, consumers, result) {
|
|
3977
|
+
for (const consumer of consumers?.consumers ?? []) {
|
|
3978
|
+
for (const def of consumer.handlers) {
|
|
3979
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3980
|
+
const lookupKey = `${consumer.consumerName}::${methodName}`;
|
|
3981
|
+
const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
|
|
3982
|
+
if (callback) {
|
|
3983
|
+
app.registerConsumerHandler(def.name, def.timeout, callback);
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
}
|
|
3988
|
+
__name(registerConsumerHandlers, "registerConsumerHandlers");
|
|
3989
|
+
async function registerEventHandlers(app, events, result) {
|
|
3990
|
+
for (const event of events?.events ?? []) {
|
|
3991
|
+
for (const def of event.handlers) {
|
|
3992
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
3993
|
+
const lookupKey = `${event.consumerName}::${methodName}`;
|
|
3994
|
+
const callback = result.createConsumerCallback(lookupKey, def.name) ?? await result.createConsumerCallbackById(def.handler, def.location, def.name);
|
|
3995
|
+
if (callback) {
|
|
3996
|
+
app.registerConsumerHandler(def.name, def.timeout, callback);
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
4000
|
+
}
|
|
4001
|
+
__name(registerEventHandlers, "registerEventHandlers");
|
|
4002
|
+
async function registerScheduleHandlers(app, schedules, result) {
|
|
4003
|
+
for (const schedule of schedules?.schedules ?? []) {
|
|
4004
|
+
for (const def of schedule.handlers) {
|
|
4005
|
+
const methodName = def.handler.split(".").pop() ?? def.name;
|
|
4006
|
+
const lookupKey = `${schedule.scheduleId}::${methodName}`;
|
|
4007
|
+
const callback = result.createScheduleCallback(lookupKey, def.name) ?? await result.createScheduleCallbackById(def.handler, def.location, def.name);
|
|
4008
|
+
if (callback) {
|
|
4009
|
+
app.registerScheduleHandler(def.name, def.timeout, callback);
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
}
|
|
4014
|
+
__name(registerScheduleHandlers, "registerScheduleHandlers");
|
|
4015
|
+
async function registerCustomHandlers(app, customHandlers, result) {
|
|
4016
|
+
for (const def of customHandlers?.handlers ?? []) {
|
|
4017
|
+
const callback = result.createCustomCallback(def.name) ?? await result.createCustomCallbackById(def.handler, def.location, def.name);
|
|
4018
|
+
if (callback) {
|
|
4019
|
+
app.registerCustomHandler(def.name, def.timeout, callback);
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
}
|
|
4023
|
+
__name(registerCustomHandlers, "registerCustomHandlers");
|
|
4024
|
+
async function startRuntime(options) {
|
|
4025
|
+
const { app, appConfig } = await loadRuntime();
|
|
4026
|
+
const result = await bootstrapForRuntime();
|
|
4027
|
+
await registerHttpHandlers(app, appConfig.api, result);
|
|
4028
|
+
await registerGuardHandlers(app, appConfig.api?.guards, result);
|
|
4029
|
+
await registerWebSocketHandlers(app, appConfig.api?.websocket, result);
|
|
4030
|
+
await registerConsumerHandlers(app, appConfig.consumers, result);
|
|
4031
|
+
await registerEventHandlers(app, appConfig.events, result);
|
|
4032
|
+
await registerScheduleHandlers(app, appConfig.schedules, result);
|
|
4033
|
+
await registerCustomHandlers(app, appConfig.customHandlers, result);
|
|
4034
|
+
if (appConfig.api?.websocket) {
|
|
4035
|
+
const sender = new RuntimeWebSocketSender(app.websocketRegistry());
|
|
4036
|
+
result.container.register(import_types7.WebSocketSender, {
|
|
4037
|
+
useValue: sender
|
|
4038
|
+
});
|
|
4039
|
+
}
|
|
2004
4040
|
await app.run(options?.block ?? true);
|
|
2005
4041
|
}
|
|
2006
4042
|
__name(startRuntime, "startRuntime");
|
|
4043
|
+
|
|
4044
|
+
// src/index.ts
|
|
4045
|
+
var import_types8 = require("@celerity-sdk/types");
|
|
4046
|
+
var import_types9 = require("@celerity-sdk/types");
|
|
2007
4047
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2008
4048
|
0 && (module.exports = {
|
|
2009
4049
|
APP_CONFIG,
|
|
@@ -2012,15 +4052,24 @@ __name(startRuntime, "startRuntime");
|
|
|
2012
4052
|
BadGatewayException,
|
|
2013
4053
|
BadRequestException,
|
|
2014
4054
|
Body,
|
|
4055
|
+
BucketEventType,
|
|
4056
|
+
CONSUMER_HANDLER_METADATA,
|
|
4057
|
+
CONSUMER_METADATA,
|
|
2015
4058
|
CONTROLLER_METADATA,
|
|
2016
4059
|
CUSTOM_METADATA,
|
|
2017
4060
|
CelerityApplication,
|
|
2018
4061
|
CelerityFactory,
|
|
2019
4062
|
ConflictException,
|
|
4063
|
+
ConnectionId,
|
|
4064
|
+
Consumer,
|
|
4065
|
+
ConsumerTraceContext,
|
|
2020
4066
|
Container,
|
|
2021
4067
|
Controller,
|
|
2022
4068
|
Cookies,
|
|
4069
|
+
DatastoreEventType,
|
|
2023
4070
|
Delete,
|
|
4071
|
+
EventInput,
|
|
4072
|
+
EventType,
|
|
2024
4073
|
ForbiddenException,
|
|
2025
4074
|
GUARD_CUSTOM_METADATA,
|
|
2026
4075
|
GUARD_PROTECTEDBY_METADATA,
|
|
@@ -2035,20 +4084,31 @@ __name(startRuntime, "startRuntime");
|
|
|
2035
4084
|
Headers,
|
|
2036
4085
|
HttpException,
|
|
2037
4086
|
INJECT_METADATA,
|
|
4087
|
+
INVOKE_METADATA,
|
|
2038
4088
|
Inject,
|
|
2039
4089
|
Injectable,
|
|
2040
4090
|
InternalServerErrorException,
|
|
4091
|
+
Invoke,
|
|
4092
|
+
InvokeContext,
|
|
2041
4093
|
LAYER_METADATA,
|
|
2042
4094
|
MODULE_METADATA,
|
|
4095
|
+
MessageBody,
|
|
4096
|
+
MessageHandler,
|
|
4097
|
+
MessageId,
|
|
4098
|
+
Messages,
|
|
2043
4099
|
MethodNotAllowedException,
|
|
2044
4100
|
Module,
|
|
2045
4101
|
NotAcceptableException,
|
|
2046
4102
|
NotFoundException,
|
|
2047
4103
|
NotImplementedException,
|
|
4104
|
+
OnConnect,
|
|
4105
|
+
OnDisconnect,
|
|
4106
|
+
OnMessage,
|
|
2048
4107
|
Options,
|
|
2049
4108
|
PUBLIC_METADATA,
|
|
2050
4109
|
Param,
|
|
2051
4110
|
Patch,
|
|
4111
|
+
Payload,
|
|
2052
4112
|
Post,
|
|
2053
4113
|
ProtectedBy,
|
|
2054
4114
|
Public,
|
|
@@ -2057,24 +4117,52 @@ __name(startRuntime, "startRuntime");
|
|
|
2057
4117
|
ROUTE_PATH_METADATA,
|
|
2058
4118
|
RUNTIME_APP,
|
|
2059
4119
|
Req,
|
|
4120
|
+
RequestContext,
|
|
2060
4121
|
RequestId,
|
|
4122
|
+
RuntimeWebSocketSender,
|
|
4123
|
+
SCHEDULE_HANDLER_METADATA,
|
|
4124
|
+
ScheduleEventInputParam,
|
|
4125
|
+
ScheduleExpression,
|
|
4126
|
+
ScheduleHandler,
|
|
4127
|
+
ScheduleId,
|
|
4128
|
+
ScheduleInput,
|
|
2061
4129
|
ServerlessApplication,
|
|
2062
4130
|
ServiceUnavailableException,
|
|
2063
4131
|
SetMetadata,
|
|
4132
|
+
SourceType,
|
|
2064
4133
|
TestingApplication,
|
|
4134
|
+
Token,
|
|
2065
4135
|
TooManyRequestsException,
|
|
4136
|
+
USE_RESOURCE_METADATA,
|
|
2066
4137
|
UnauthorizedException,
|
|
2067
4138
|
UnprocessableEntityException,
|
|
2068
4139
|
UseLayer,
|
|
2069
4140
|
UseLayers,
|
|
4141
|
+
UseResource,
|
|
4142
|
+
UseResources,
|
|
4143
|
+
Vendor,
|
|
4144
|
+
WEBSOCKET_CONTROLLER_METADATA,
|
|
4145
|
+
WEBSOCKET_EVENT_METADATA,
|
|
4146
|
+
WebSocketController,
|
|
4147
|
+
WebSocketSender,
|
|
2070
4148
|
bootstrap,
|
|
2071
4149
|
bootstrapForRuntime,
|
|
2072
4150
|
buildModuleGraph,
|
|
4151
|
+
createConsumerHandler,
|
|
4152
|
+
createCustomHandler,
|
|
2073
4153
|
createDefaultSystemLayers,
|
|
4154
|
+
createGuard,
|
|
2074
4155
|
createHttpHandler,
|
|
4156
|
+
createScheduleHandler,
|
|
4157
|
+
createWebSocketHandler,
|
|
2075
4158
|
discoverModule,
|
|
2076
4159
|
disposeLayers,
|
|
2077
|
-
|
|
4160
|
+
executeConsumerPipeline,
|
|
4161
|
+
executeCustomPipeline,
|
|
4162
|
+
executeGuardPipeline,
|
|
4163
|
+
executeHttpPipeline,
|
|
4164
|
+
executeSchedulePipeline,
|
|
4165
|
+
executeWebSocketPipeline,
|
|
2078
4166
|
flattenMultiValueRecord,
|
|
2079
4167
|
getClassDependencyTokens,
|
|
2080
4168
|
getProviderDependencyTokens,
|
|
@@ -2083,12 +4171,27 @@ __name(startRuntime, "startRuntime");
|
|
|
2083
4171
|
httpPatch,
|
|
2084
4172
|
httpPost,
|
|
2085
4173
|
httpPut,
|
|
4174
|
+
mapConsumerEventInput,
|
|
2086
4175
|
mapRuntimeRequest,
|
|
4176
|
+
mapScheduleEventInput,
|
|
4177
|
+
mapToNapiEventResult,
|
|
2087
4178
|
mapToRuntimeResponse,
|
|
4179
|
+
mapWebSocketMessage,
|
|
4180
|
+
mockConsumerEvent,
|
|
2088
4181
|
mockRequest,
|
|
4182
|
+
mockScheduleEvent,
|
|
4183
|
+
mockWebSocketMessage,
|
|
2089
4184
|
registerModuleGraph,
|
|
2090
4185
|
resolveHandlerByModuleRef,
|
|
4186
|
+
routingKeyOf,
|
|
2091
4187
|
runLayerPipeline,
|
|
4188
|
+
scanConsumerHandlers,
|
|
4189
|
+
scanCustomHandlers,
|
|
4190
|
+
scanHttpGuards,
|
|
4191
|
+
scanHttpHandlers,
|
|
4192
|
+
scanModule,
|
|
4193
|
+
scanScheduleHandlers,
|
|
4194
|
+
scanWebSocketHandlers,
|
|
2092
4195
|
startRuntime,
|
|
2093
4196
|
tokenToString,
|
|
2094
4197
|
validate
|