@celerity-sdk/core 0.2.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/LICENSE +201 -0
- package/README.md +122 -0
- package/dist/index.cjs +2002 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +433 -0
- package/dist/index.d.ts +433 -0
- package/dist/index.js +1885 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2002 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
APP_CONFIG: () => APP_CONFIG,
|
|
35
|
+
Action: () => Action,
|
|
36
|
+
Auth: () => Auth,
|
|
37
|
+
BadGatewayException: () => BadGatewayException,
|
|
38
|
+
BadRequestException: () => BadRequestException,
|
|
39
|
+
Body: () => Body,
|
|
40
|
+
CONTROLLER_METADATA: () => CONTROLLER_METADATA,
|
|
41
|
+
CUSTOM_METADATA: () => CUSTOM_METADATA,
|
|
42
|
+
CelerityApplication: () => CelerityApplication,
|
|
43
|
+
CelerityFactory: () => CelerityFactory,
|
|
44
|
+
ConflictException: () => ConflictException,
|
|
45
|
+
Container: () => Container,
|
|
46
|
+
Controller: () => Controller,
|
|
47
|
+
Cookies: () => Cookies,
|
|
48
|
+
Delete: () => Delete,
|
|
49
|
+
ForbiddenException: () => ForbiddenException,
|
|
50
|
+
GUARD_CUSTOM_METADATA: () => GUARD_CUSTOM_METADATA,
|
|
51
|
+
GUARD_PROTECTEDBY_METADATA: () => GUARD_PROTECTEDBY_METADATA,
|
|
52
|
+
GatewayTimeoutException: () => GatewayTimeoutException,
|
|
53
|
+
Get: () => Get,
|
|
54
|
+
GoneException: () => GoneException,
|
|
55
|
+
Guard: () => Guard,
|
|
56
|
+
HTTP_METHOD_METADATA: () => HTTP_METHOD_METADATA,
|
|
57
|
+
HandlerMetadataStore: () => HandlerMetadataStore,
|
|
58
|
+
HandlerRegistry: () => HandlerRegistry,
|
|
59
|
+
Head: () => Head,
|
|
60
|
+
Headers: () => Headers,
|
|
61
|
+
HttpException: () => HttpException,
|
|
62
|
+
INJECT_METADATA: () => INJECT_METADATA,
|
|
63
|
+
Inject: () => Inject,
|
|
64
|
+
Injectable: () => Injectable,
|
|
65
|
+
InternalServerErrorException: () => InternalServerErrorException,
|
|
66
|
+
LAYER_METADATA: () => LAYER_METADATA,
|
|
67
|
+
MODULE_METADATA: () => MODULE_METADATA,
|
|
68
|
+
MethodNotAllowedException: () => MethodNotAllowedException,
|
|
69
|
+
Module: () => Module,
|
|
70
|
+
NotAcceptableException: () => NotAcceptableException,
|
|
71
|
+
NotFoundException: () => NotFoundException,
|
|
72
|
+
NotImplementedException: () => NotImplementedException,
|
|
73
|
+
Options: () => Options,
|
|
74
|
+
PUBLIC_METADATA: () => PUBLIC_METADATA,
|
|
75
|
+
Param: () => Param,
|
|
76
|
+
Patch: () => Patch,
|
|
77
|
+
Post: () => Post,
|
|
78
|
+
ProtectedBy: () => ProtectedBy,
|
|
79
|
+
Public: () => Public,
|
|
80
|
+
Put: () => Put,
|
|
81
|
+
Query: () => Query,
|
|
82
|
+
ROUTE_PATH_METADATA: () => ROUTE_PATH_METADATA,
|
|
83
|
+
RUNTIME_APP: () => RUNTIME_APP,
|
|
84
|
+
Req: () => Req,
|
|
85
|
+
RequestId: () => RequestId,
|
|
86
|
+
ServerlessApplication: () => ServerlessApplication,
|
|
87
|
+
ServiceUnavailableException: () => ServiceUnavailableException,
|
|
88
|
+
SetMetadata: () => SetMetadata,
|
|
89
|
+
TestingApplication: () => TestingApplication,
|
|
90
|
+
TooManyRequestsException: () => TooManyRequestsException,
|
|
91
|
+
UnauthorizedException: () => UnauthorizedException,
|
|
92
|
+
UnprocessableEntityException: () => UnprocessableEntityException,
|
|
93
|
+
UseLayer: () => UseLayer,
|
|
94
|
+
UseLayers: () => UseLayers,
|
|
95
|
+
bootstrap: () => bootstrap,
|
|
96
|
+
bootstrapForRuntime: () => bootstrapForRuntime,
|
|
97
|
+
buildModuleGraph: () => buildModuleGraph,
|
|
98
|
+
createDefaultSystemLayers: () => createDefaultSystemLayers,
|
|
99
|
+
createHttpHandler: () => createHttpHandler,
|
|
100
|
+
discoverModule: () => discoverModule,
|
|
101
|
+
disposeLayers: () => disposeLayers,
|
|
102
|
+
executeHandlerPipeline: () => executeHandlerPipeline,
|
|
103
|
+
flattenMultiValueRecord: () => flattenMultiValueRecord,
|
|
104
|
+
getClassDependencyTokens: () => getClassDependencyTokens,
|
|
105
|
+
getProviderDependencyTokens: () => getProviderDependencyTokens,
|
|
106
|
+
httpDelete: () => httpDelete,
|
|
107
|
+
httpGet: () => httpGet,
|
|
108
|
+
httpPatch: () => httpPatch,
|
|
109
|
+
httpPost: () => httpPost,
|
|
110
|
+
httpPut: () => httpPut,
|
|
111
|
+
mapRuntimeRequest: () => mapRuntimeRequest,
|
|
112
|
+
mapToRuntimeResponse: () => mapToRuntimeResponse,
|
|
113
|
+
mockRequest: () => mockRequest,
|
|
114
|
+
registerModuleGraph: () => registerModuleGraph,
|
|
115
|
+
runLayerPipeline: () => runLayerPipeline,
|
|
116
|
+
startRuntime: () => startRuntime,
|
|
117
|
+
tokenToString: () => tokenToString,
|
|
118
|
+
validate: () => validate
|
|
119
|
+
});
|
|
120
|
+
module.exports = __toCommonJS(index_exports);
|
|
121
|
+
var import_reflect_metadata14 = require("reflect-metadata");
|
|
122
|
+
|
|
123
|
+
// src/decorators/controller.ts
|
|
124
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
125
|
+
|
|
126
|
+
// src/metadata/constants.ts
|
|
127
|
+
var CONTROLLER_METADATA = /* @__PURE__ */ Symbol("celerity:controller");
|
|
128
|
+
var HTTP_METHOD_METADATA = /* @__PURE__ */ Symbol("celerity:http-method");
|
|
129
|
+
var ROUTE_PATH_METADATA = /* @__PURE__ */ Symbol("celerity:route-path");
|
|
130
|
+
var PARAM_METADATA = /* @__PURE__ */ Symbol("celerity:param");
|
|
131
|
+
var GUARD_PROTECTEDBY_METADATA = /* @__PURE__ */ Symbol("celerity:guard:protectedBy");
|
|
132
|
+
var GUARD_CUSTOM_METADATA = /* @__PURE__ */ Symbol("celerity:guard:custom");
|
|
133
|
+
var LAYER_METADATA = /* @__PURE__ */ Symbol("celerity:layer");
|
|
134
|
+
var MODULE_METADATA = /* @__PURE__ */ Symbol("celerity:module");
|
|
135
|
+
var INJECTABLE_METADATA = /* @__PURE__ */ Symbol("celerity:injectable");
|
|
136
|
+
var INJECT_METADATA = /* @__PURE__ */ Symbol("celerity:inject");
|
|
137
|
+
var PUBLIC_METADATA = /* @__PURE__ */ Symbol("celerity:public");
|
|
138
|
+
var CUSTOM_METADATA = /* @__PURE__ */ Symbol("celerity:custom-metadata");
|
|
139
|
+
|
|
140
|
+
// src/decorators/controller.ts
|
|
141
|
+
function Controller(prefix) {
|
|
142
|
+
return (target) => {
|
|
143
|
+
const metadata = {};
|
|
144
|
+
if (prefix !== void 0) {
|
|
145
|
+
metadata.prefix = prefix;
|
|
146
|
+
}
|
|
147
|
+
Reflect.defineMetadata(CONTROLLER_METADATA, metadata, target);
|
|
148
|
+
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
__name(Controller, "Controller");
|
|
152
|
+
|
|
153
|
+
// src/decorators/http.ts
|
|
154
|
+
var import_reflect_metadata2 = require("reflect-metadata");
|
|
155
|
+
function createMethodDecorator(method, path = "/") {
|
|
156
|
+
return (target, propertyKey, descriptor) => {
|
|
157
|
+
Reflect.defineMetadata(HTTP_METHOD_METADATA, method, target, propertyKey);
|
|
158
|
+
Reflect.defineMetadata(ROUTE_PATH_METADATA, path, target, propertyKey);
|
|
159
|
+
return descriptor;
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
__name(createMethodDecorator, "createMethodDecorator");
|
|
163
|
+
function Get(path) {
|
|
164
|
+
return createMethodDecorator("GET", path);
|
|
165
|
+
}
|
|
166
|
+
__name(Get, "Get");
|
|
167
|
+
function Post(path) {
|
|
168
|
+
return createMethodDecorator("POST", path);
|
|
169
|
+
}
|
|
170
|
+
__name(Post, "Post");
|
|
171
|
+
function Put(path) {
|
|
172
|
+
return createMethodDecorator("PUT", path);
|
|
173
|
+
}
|
|
174
|
+
__name(Put, "Put");
|
|
175
|
+
function Patch(path) {
|
|
176
|
+
return createMethodDecorator("PATCH", path);
|
|
177
|
+
}
|
|
178
|
+
__name(Patch, "Patch");
|
|
179
|
+
function Delete(path) {
|
|
180
|
+
return createMethodDecorator("DELETE", path);
|
|
181
|
+
}
|
|
182
|
+
__name(Delete, "Delete");
|
|
183
|
+
function Head(path) {
|
|
184
|
+
return createMethodDecorator("HEAD", path);
|
|
185
|
+
}
|
|
186
|
+
__name(Head, "Head");
|
|
187
|
+
function Options(path) {
|
|
188
|
+
return createMethodDecorator("OPTIONS", path);
|
|
189
|
+
}
|
|
190
|
+
__name(Options, "Options");
|
|
191
|
+
|
|
192
|
+
// src/decorators/params.ts
|
|
193
|
+
var import_reflect_metadata3 = require("reflect-metadata");
|
|
194
|
+
function createParamDecorator(type, keyOrSchema, schema) {
|
|
195
|
+
return (target, propertyKey, parameterIndex) => {
|
|
196
|
+
if (!propertyKey) return;
|
|
197
|
+
const existing = Reflect.getOwnMetadata(PARAM_METADATA, target, propertyKey) ?? [];
|
|
198
|
+
const meta = {
|
|
199
|
+
index: parameterIndex,
|
|
200
|
+
type
|
|
201
|
+
};
|
|
202
|
+
if (typeof keyOrSchema === "string") {
|
|
203
|
+
meta.key = keyOrSchema;
|
|
204
|
+
if (schema) meta.schema = schema;
|
|
205
|
+
} else if (keyOrSchema && typeof keyOrSchema === "object") {
|
|
206
|
+
meta.schema = keyOrSchema;
|
|
207
|
+
}
|
|
208
|
+
existing.push(meta);
|
|
209
|
+
Reflect.defineMetadata(PARAM_METADATA, existing, target, propertyKey);
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
__name(createParamDecorator, "createParamDecorator");
|
|
213
|
+
function Body(schema) {
|
|
214
|
+
return createParamDecorator("body", schema);
|
|
215
|
+
}
|
|
216
|
+
__name(Body, "Body");
|
|
217
|
+
function Query(keyOrSchema, schema) {
|
|
218
|
+
return createParamDecorator("query", keyOrSchema, schema);
|
|
219
|
+
}
|
|
220
|
+
__name(Query, "Query");
|
|
221
|
+
function Param(keyOrSchema, schema) {
|
|
222
|
+
return createParamDecorator("param", keyOrSchema, schema);
|
|
223
|
+
}
|
|
224
|
+
__name(Param, "Param");
|
|
225
|
+
function Headers(keyOrSchema, schema) {
|
|
226
|
+
return createParamDecorator("headers", keyOrSchema, schema);
|
|
227
|
+
}
|
|
228
|
+
__name(Headers, "Headers");
|
|
229
|
+
function Auth() {
|
|
230
|
+
return createParamDecorator("auth");
|
|
231
|
+
}
|
|
232
|
+
__name(Auth, "Auth");
|
|
233
|
+
function Req() {
|
|
234
|
+
return createParamDecorator("request");
|
|
235
|
+
}
|
|
236
|
+
__name(Req, "Req");
|
|
237
|
+
function Cookies(key) {
|
|
238
|
+
return createParamDecorator("cookies", key);
|
|
239
|
+
}
|
|
240
|
+
__name(Cookies, "Cookies");
|
|
241
|
+
function RequestId() {
|
|
242
|
+
return createParamDecorator("requestId");
|
|
243
|
+
}
|
|
244
|
+
__name(RequestId, "RequestId");
|
|
245
|
+
function extractParam(type, key, request) {
|
|
246
|
+
switch (type) {
|
|
247
|
+
case "body":
|
|
248
|
+
return request.textBody ? JSON.parse(request.textBody) : null;
|
|
249
|
+
case "query":
|
|
250
|
+
return key ? request.query[key] : request.query;
|
|
251
|
+
case "param":
|
|
252
|
+
return key ? request.pathParams[key] : request.pathParams;
|
|
253
|
+
case "headers":
|
|
254
|
+
return key ? request.headers[key] : request.headers;
|
|
255
|
+
case "auth":
|
|
256
|
+
return request.auth;
|
|
257
|
+
case "request":
|
|
258
|
+
return request;
|
|
259
|
+
case "cookies":
|
|
260
|
+
return key ? request.cookies[key] : request.cookies;
|
|
261
|
+
case "requestId":
|
|
262
|
+
return request.requestId;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
__name(extractParam, "extractParam");
|
|
266
|
+
|
|
267
|
+
// src/decorators/guards.ts
|
|
268
|
+
var import_reflect_metadata4 = require("reflect-metadata");
|
|
269
|
+
function Guard(name) {
|
|
270
|
+
return (target) => {
|
|
271
|
+
Reflect.defineMetadata(GUARD_CUSTOM_METADATA, name, target);
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
__name(Guard, "Guard");
|
|
275
|
+
function ProtectedBy(name) {
|
|
276
|
+
return (target, propertyKey, _descriptor) => {
|
|
277
|
+
if (propertyKey) {
|
|
278
|
+
const existing = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, target, propertyKey) ?? [];
|
|
279
|
+
Reflect.defineMetadata(GUARD_PROTECTEDBY_METADATA, [
|
|
280
|
+
name,
|
|
281
|
+
...existing
|
|
282
|
+
], target, propertyKey);
|
|
283
|
+
} else {
|
|
284
|
+
const existing = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, target) ?? [];
|
|
285
|
+
Reflect.defineMetadata(GUARD_PROTECTEDBY_METADATA, [
|
|
286
|
+
name,
|
|
287
|
+
...existing
|
|
288
|
+
], target);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
__name(ProtectedBy, "ProtectedBy");
|
|
293
|
+
function Public() {
|
|
294
|
+
return (target, propertyKey, descriptor) => {
|
|
295
|
+
Reflect.defineMetadata(PUBLIC_METADATA, true, target, propertyKey);
|
|
296
|
+
return descriptor;
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
__name(Public, "Public");
|
|
300
|
+
|
|
301
|
+
// src/decorators/layer.ts
|
|
302
|
+
var import_reflect_metadata5 = require("reflect-metadata");
|
|
303
|
+
function UseLayer(...layers) {
|
|
304
|
+
return (target, propertyKey, _descriptor) => {
|
|
305
|
+
if (propertyKey) {
|
|
306
|
+
const existing = Reflect.getOwnMetadata(LAYER_METADATA, target, propertyKey) ?? [];
|
|
307
|
+
Reflect.defineMetadata(LAYER_METADATA, [
|
|
308
|
+
...layers,
|
|
309
|
+
...existing
|
|
310
|
+
], target, propertyKey);
|
|
311
|
+
} else {
|
|
312
|
+
const existing = Reflect.getOwnMetadata(LAYER_METADATA, target) ?? [];
|
|
313
|
+
Reflect.defineMetadata(LAYER_METADATA, [
|
|
314
|
+
...layers,
|
|
315
|
+
...existing
|
|
316
|
+
], target);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
__name(UseLayer, "UseLayer");
|
|
321
|
+
function UseLayers(layers) {
|
|
322
|
+
return UseLayer(...layers);
|
|
323
|
+
}
|
|
324
|
+
__name(UseLayers, "UseLayers");
|
|
325
|
+
|
|
326
|
+
// src/decorators/metadata.ts
|
|
327
|
+
var import_reflect_metadata6 = require("reflect-metadata");
|
|
328
|
+
function SetMetadata(key, value) {
|
|
329
|
+
return (target, propertyKey, _descriptor) => {
|
|
330
|
+
if (propertyKey) {
|
|
331
|
+
const existing = Reflect.getOwnMetadata(CUSTOM_METADATA, target, propertyKey) ?? {};
|
|
332
|
+
Reflect.defineMetadata(CUSTOM_METADATA, {
|
|
333
|
+
...existing,
|
|
334
|
+
[key]: value
|
|
335
|
+
}, target, propertyKey);
|
|
336
|
+
} else {
|
|
337
|
+
const existing = Reflect.getOwnMetadata(CUSTOM_METADATA, target) ?? {};
|
|
338
|
+
Reflect.defineMetadata(CUSTOM_METADATA, {
|
|
339
|
+
...existing,
|
|
340
|
+
[key]: value
|
|
341
|
+
}, target);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
__name(SetMetadata, "SetMetadata");
|
|
346
|
+
function Action(value) {
|
|
347
|
+
return SetMetadata("action", value);
|
|
348
|
+
}
|
|
349
|
+
__name(Action, "Action");
|
|
350
|
+
|
|
351
|
+
// src/decorators/injectable.ts
|
|
352
|
+
var import_reflect_metadata7 = require("reflect-metadata");
|
|
353
|
+
function Injectable() {
|
|
354
|
+
return (target) => {
|
|
355
|
+
Reflect.defineMetadata(INJECTABLE_METADATA, true, target);
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
__name(Injectable, "Injectable");
|
|
359
|
+
function Inject(token) {
|
|
360
|
+
return (target, _propertyKey, parameterIndex) => {
|
|
361
|
+
const existing = Reflect.getOwnMetadata(INJECT_METADATA, target) ?? /* @__PURE__ */ new Map();
|
|
362
|
+
existing.set(parameterIndex, token);
|
|
363
|
+
Reflect.defineMetadata(INJECT_METADATA, existing, target);
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
__name(Inject, "Inject");
|
|
367
|
+
|
|
368
|
+
// src/decorators/module.ts
|
|
369
|
+
var import_reflect_metadata8 = require("reflect-metadata");
|
|
370
|
+
function Module(metadata) {
|
|
371
|
+
return (target) => {
|
|
372
|
+
Reflect.defineMetadata(MODULE_METADATA, metadata, target);
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
__name(Module, "Module");
|
|
376
|
+
|
|
377
|
+
// src/errors/http-exception.ts
|
|
378
|
+
var HttpException = class extends Error {
|
|
379
|
+
static {
|
|
380
|
+
__name(this, "HttpException");
|
|
381
|
+
}
|
|
382
|
+
statusCode;
|
|
383
|
+
details;
|
|
384
|
+
constructor(statusCode, message, details) {
|
|
385
|
+
super(message), this.statusCode = statusCode, this.details = details;
|
|
386
|
+
this.name = "HttpException";
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var BadRequestException = class extends HttpException {
|
|
390
|
+
static {
|
|
391
|
+
__name(this, "BadRequestException");
|
|
392
|
+
}
|
|
393
|
+
constructor(message = "Bad Request", details) {
|
|
394
|
+
super(400, message, details);
|
|
395
|
+
this.name = "BadRequestException";
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
var UnauthorizedException = class extends HttpException {
|
|
399
|
+
static {
|
|
400
|
+
__name(this, "UnauthorizedException");
|
|
401
|
+
}
|
|
402
|
+
constructor(message = "Unauthorized", details) {
|
|
403
|
+
super(401, message, details);
|
|
404
|
+
this.name = "UnauthorizedException";
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
var ForbiddenException = class extends HttpException {
|
|
408
|
+
static {
|
|
409
|
+
__name(this, "ForbiddenException");
|
|
410
|
+
}
|
|
411
|
+
constructor(message = "Forbidden", details) {
|
|
412
|
+
super(403, message, details);
|
|
413
|
+
this.name = "ForbiddenException";
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
var NotFoundException = class extends HttpException {
|
|
417
|
+
static {
|
|
418
|
+
__name(this, "NotFoundException");
|
|
419
|
+
}
|
|
420
|
+
constructor(message = "Not Found", details) {
|
|
421
|
+
super(404, message, details);
|
|
422
|
+
this.name = "NotFoundException";
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
var MethodNotAllowedException = class extends HttpException {
|
|
426
|
+
static {
|
|
427
|
+
__name(this, "MethodNotAllowedException");
|
|
428
|
+
}
|
|
429
|
+
constructor(message = "Method Not Allowed", details) {
|
|
430
|
+
super(405, message, details);
|
|
431
|
+
this.name = "MethodNotAllowedException";
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
var NotAcceptableException = class extends HttpException {
|
|
435
|
+
static {
|
|
436
|
+
__name(this, "NotAcceptableException");
|
|
437
|
+
}
|
|
438
|
+
constructor(message = "Not Acceptable", details) {
|
|
439
|
+
super(406, message, details);
|
|
440
|
+
this.name = "NotAcceptableException";
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
var ConflictException = class extends HttpException {
|
|
444
|
+
static {
|
|
445
|
+
__name(this, "ConflictException");
|
|
446
|
+
}
|
|
447
|
+
constructor(message = "Conflict", details) {
|
|
448
|
+
super(409, message, details);
|
|
449
|
+
this.name = "ConflictException";
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
var GoneException = class extends HttpException {
|
|
453
|
+
static {
|
|
454
|
+
__name(this, "GoneException");
|
|
455
|
+
}
|
|
456
|
+
constructor(message = "Gone", details) {
|
|
457
|
+
super(410, message, details);
|
|
458
|
+
this.name = "GoneException";
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
var UnprocessableEntityException = class extends HttpException {
|
|
462
|
+
static {
|
|
463
|
+
__name(this, "UnprocessableEntityException");
|
|
464
|
+
}
|
|
465
|
+
constructor(message = "Unprocessable Entity", details) {
|
|
466
|
+
super(422, message, details);
|
|
467
|
+
this.name = "UnprocessableEntityException";
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
var TooManyRequestsException = class extends HttpException {
|
|
471
|
+
static {
|
|
472
|
+
__name(this, "TooManyRequestsException");
|
|
473
|
+
}
|
|
474
|
+
constructor(message = "Too Many Requests", details) {
|
|
475
|
+
super(429, message, details);
|
|
476
|
+
this.name = "TooManyRequestsException";
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
var InternalServerErrorException = class extends HttpException {
|
|
480
|
+
static {
|
|
481
|
+
__name(this, "InternalServerErrorException");
|
|
482
|
+
}
|
|
483
|
+
constructor(message = "Internal Server Error", details) {
|
|
484
|
+
super(500, message, details);
|
|
485
|
+
this.name = "InternalServerErrorException";
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
var NotImplementedException = class extends HttpException {
|
|
489
|
+
static {
|
|
490
|
+
__name(this, "NotImplementedException");
|
|
491
|
+
}
|
|
492
|
+
constructor(message = "Not Implemented", details) {
|
|
493
|
+
super(501, message, details);
|
|
494
|
+
this.name = "NotImplementedException";
|
|
495
|
+
}
|
|
496
|
+
};
|
|
497
|
+
var BadGatewayException = class extends HttpException {
|
|
498
|
+
static {
|
|
499
|
+
__name(this, "BadGatewayException");
|
|
500
|
+
}
|
|
501
|
+
constructor(message = "Bad Gateway", details) {
|
|
502
|
+
super(502, message, details);
|
|
503
|
+
this.name = "BadGatewayException";
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
var ServiceUnavailableException = class extends HttpException {
|
|
507
|
+
static {
|
|
508
|
+
__name(this, "ServiceUnavailableException");
|
|
509
|
+
}
|
|
510
|
+
constructor(message = "Service Unavailable", details) {
|
|
511
|
+
super(503, message, details);
|
|
512
|
+
this.name = "ServiceUnavailableException";
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var GatewayTimeoutException = class extends HttpException {
|
|
516
|
+
static {
|
|
517
|
+
__name(this, "GatewayTimeoutException");
|
|
518
|
+
}
|
|
519
|
+
constructor(message = "Gateway Timeout", details) {
|
|
520
|
+
super(504, message, details);
|
|
521
|
+
this.name = "GatewayTimeoutException";
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// src/layers/validate.ts
|
|
526
|
+
var ValidationLayer = class ValidationLayer2 {
|
|
527
|
+
static {
|
|
528
|
+
__name(this, "ValidationLayer");
|
|
529
|
+
}
|
|
530
|
+
schemas;
|
|
531
|
+
constructor(schemas) {
|
|
532
|
+
this.schemas = schemas;
|
|
533
|
+
}
|
|
534
|
+
async handle(context, next) {
|
|
535
|
+
const { request } = context;
|
|
536
|
+
if (this.schemas.body && request.textBody) {
|
|
537
|
+
try {
|
|
538
|
+
const raw = JSON.parse(request.textBody);
|
|
539
|
+
context.metadata.set("validatedBody", this.schemas.body.parse(raw));
|
|
540
|
+
} catch (error) {
|
|
541
|
+
throw new BadRequestException("Body validation failed", formatError(error));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
if (this.schemas.params) {
|
|
545
|
+
try {
|
|
546
|
+
context.metadata.set("validatedParams", this.schemas.params.parse(request.pathParams));
|
|
547
|
+
} catch (error) {
|
|
548
|
+
throw new BadRequestException("Path params validation failed", formatError(error));
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (this.schemas.query) {
|
|
552
|
+
try {
|
|
553
|
+
context.metadata.set("validatedQuery", this.schemas.query.parse(request.query));
|
|
554
|
+
} catch (error) {
|
|
555
|
+
throw new BadRequestException("Query validation failed", formatError(error));
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (this.schemas.headers) {
|
|
559
|
+
try {
|
|
560
|
+
context.metadata.set("validatedHeaders", this.schemas.headers.parse(request.headers));
|
|
561
|
+
} catch (error) {
|
|
562
|
+
throw new BadRequestException("Headers validation failed", formatError(error));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
return next();
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
function formatError(error) {
|
|
569
|
+
if (error instanceof Error && "issues" in error) {
|
|
570
|
+
return error.issues;
|
|
571
|
+
}
|
|
572
|
+
if (error instanceof Error) {
|
|
573
|
+
return error.message;
|
|
574
|
+
}
|
|
575
|
+
return error;
|
|
576
|
+
}
|
|
577
|
+
__name(formatError, "formatError");
|
|
578
|
+
function validate(schemas) {
|
|
579
|
+
return new ValidationLayer(schemas);
|
|
580
|
+
}
|
|
581
|
+
__name(validate, "validate");
|
|
582
|
+
|
|
583
|
+
// src/layers/pipeline.ts
|
|
584
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
585
|
+
var debug = (0, import_debug.default)("celerity:core:layers");
|
|
586
|
+
function runLayerPipeline(layers, context, handler) {
|
|
587
|
+
const resolved = layers.map((layer) => typeof layer === "function" ? new layer() : layer);
|
|
588
|
+
debug("runLayerPipeline: %d layers", resolved.length);
|
|
589
|
+
let index = -1;
|
|
590
|
+
function dispatch(i) {
|
|
591
|
+
if (i <= index) {
|
|
592
|
+
return Promise.reject(new Error("next() called multiple times"));
|
|
593
|
+
}
|
|
594
|
+
index = i;
|
|
595
|
+
if (i >= resolved.length) {
|
|
596
|
+
return handler();
|
|
597
|
+
}
|
|
598
|
+
const current = resolved[i];
|
|
599
|
+
debug("layer[%d] %s", i, current.constructor.name);
|
|
600
|
+
return current.handle(context, () => dispatch(i + 1));
|
|
601
|
+
}
|
|
602
|
+
__name(dispatch, "dispatch");
|
|
603
|
+
return dispatch(0);
|
|
604
|
+
}
|
|
605
|
+
__name(runLayerPipeline, "runLayerPipeline");
|
|
606
|
+
|
|
607
|
+
// src/layers/system.ts
|
|
608
|
+
var import_config = require("@celerity-sdk/config");
|
|
609
|
+
async function createDefaultSystemLayers() {
|
|
610
|
+
const layers = [];
|
|
611
|
+
try {
|
|
612
|
+
const pkg = "@celerity-sdk/telemetry";
|
|
613
|
+
const mod = await import(pkg);
|
|
614
|
+
const TelemetryLayerClass = mod.TelemetryLayer;
|
|
615
|
+
layers.push(new TelemetryLayerClass());
|
|
616
|
+
} catch {
|
|
617
|
+
}
|
|
618
|
+
layers.push(new import_config.ConfigLayer());
|
|
619
|
+
return layers;
|
|
620
|
+
}
|
|
621
|
+
__name(createDefaultSystemLayers, "createDefaultSystemLayers");
|
|
622
|
+
|
|
623
|
+
// src/layers/dispose.ts
|
|
624
|
+
async function disposeLayers(layers) {
|
|
625
|
+
for (const layer of [
|
|
626
|
+
...layers
|
|
627
|
+
].reverse()) {
|
|
628
|
+
if (typeof layer === "object" && "dispose" in layer) {
|
|
629
|
+
try {
|
|
630
|
+
await layer.dispose?.();
|
|
631
|
+
} catch {
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
__name(disposeLayers, "disposeLayers");
|
|
637
|
+
|
|
638
|
+
// src/metadata/handler-metadata.ts
|
|
639
|
+
var HandlerMetadataStore = class {
|
|
640
|
+
static {
|
|
641
|
+
__name(this, "HandlerMetadataStore");
|
|
642
|
+
}
|
|
643
|
+
decoratorData;
|
|
644
|
+
requestData = /* @__PURE__ */ new Map();
|
|
645
|
+
constructor(decoratorMetadata) {
|
|
646
|
+
this.decoratorData = new Map(Object.entries(decoratorMetadata));
|
|
647
|
+
}
|
|
648
|
+
get(key) {
|
|
649
|
+
if (this.requestData.has(key)) return this.requestData.get(key);
|
|
650
|
+
return this.decoratorData.get(key);
|
|
651
|
+
}
|
|
652
|
+
set(key, value) {
|
|
653
|
+
this.requestData.set(key, value);
|
|
654
|
+
}
|
|
655
|
+
has(key) {
|
|
656
|
+
return this.requestData.has(key) || this.decoratorData.has(key);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
// src/di/container.ts
|
|
661
|
+
var import_reflect_metadata10 = require("reflect-metadata");
|
|
662
|
+
var import_debug2 = __toESM(require("debug"), 1);
|
|
663
|
+
|
|
664
|
+
// src/di/dependency-tokens.ts
|
|
665
|
+
var import_reflect_metadata9 = require("reflect-metadata");
|
|
666
|
+
function isClassProvider(p) {
|
|
667
|
+
return "useClass" in p;
|
|
668
|
+
}
|
|
669
|
+
__name(isClassProvider, "isClassProvider");
|
|
670
|
+
function isFactoryProvider(p) {
|
|
671
|
+
return "useFactory" in p;
|
|
672
|
+
}
|
|
673
|
+
__name(isFactoryProvider, "isFactoryProvider");
|
|
674
|
+
function getClassDependencyTokens(target) {
|
|
675
|
+
const paramTypes = Reflect.getMetadata("design:paramtypes", target) ?? [];
|
|
676
|
+
const injectOverrides = Reflect.getMetadata(INJECT_METADATA, target) ?? /* @__PURE__ */ new Map();
|
|
677
|
+
return paramTypes.map((paramType, index) => injectOverrides.get(index) ?? paramType);
|
|
678
|
+
}
|
|
679
|
+
__name(getClassDependencyTokens, "getClassDependencyTokens");
|
|
680
|
+
function getProviderDependencyTokens(provider) {
|
|
681
|
+
if (isClassProvider(provider)) {
|
|
682
|
+
return getClassDependencyTokens(provider.useClass);
|
|
683
|
+
}
|
|
684
|
+
if (isFactoryProvider(provider) && provider.inject) {
|
|
685
|
+
return [
|
|
686
|
+
...provider.inject
|
|
687
|
+
];
|
|
688
|
+
}
|
|
689
|
+
return [];
|
|
690
|
+
}
|
|
691
|
+
__name(getProviderDependencyTokens, "getProviderDependencyTokens");
|
|
692
|
+
|
|
693
|
+
// src/di/container.ts
|
|
694
|
+
var debug2 = (0, import_debug2.default)("celerity:core:di");
|
|
695
|
+
var CLOSE_METHODS = [
|
|
696
|
+
"close",
|
|
697
|
+
"end",
|
|
698
|
+
"quit",
|
|
699
|
+
"disconnect",
|
|
700
|
+
"$disconnect",
|
|
701
|
+
"destroy"
|
|
702
|
+
];
|
|
703
|
+
function isClassProvider2(p) {
|
|
704
|
+
return "useClass" in p;
|
|
705
|
+
}
|
|
706
|
+
__name(isClassProvider2, "isClassProvider");
|
|
707
|
+
function isFactoryProvider2(p) {
|
|
708
|
+
return "useFactory" in p;
|
|
709
|
+
}
|
|
710
|
+
__name(isFactoryProvider2, "isFactoryProvider");
|
|
711
|
+
function isValueProvider(p) {
|
|
712
|
+
return "useValue" in p;
|
|
713
|
+
}
|
|
714
|
+
__name(isValueProvider, "isValueProvider");
|
|
715
|
+
function tokenToString(token) {
|
|
716
|
+
if (typeof token === "function") return token.name;
|
|
717
|
+
return String(token);
|
|
718
|
+
}
|
|
719
|
+
__name(tokenToString, "tokenToString");
|
|
720
|
+
function detectCloseMethod(value) {
|
|
721
|
+
if (typeof value !== "object" || value === null) return null;
|
|
722
|
+
const obj = value;
|
|
723
|
+
for (const method of CLOSE_METHODS) {
|
|
724
|
+
if (typeof obj[method] === "function") {
|
|
725
|
+
return () => obj[method]();
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return null;
|
|
729
|
+
}
|
|
730
|
+
__name(detectCloseMethod, "detectCloseMethod");
|
|
731
|
+
var Container = class {
|
|
732
|
+
static {
|
|
733
|
+
__name(this, "Container");
|
|
734
|
+
}
|
|
735
|
+
providers = /* @__PURE__ */ new Map();
|
|
736
|
+
instances = /* @__PURE__ */ new Map();
|
|
737
|
+
resolving = /* @__PURE__ */ new Set();
|
|
738
|
+
edges = /* @__PURE__ */ new Map();
|
|
739
|
+
closeStack = [];
|
|
740
|
+
trackedTokens = /* @__PURE__ */ new Set();
|
|
741
|
+
register(token, provider) {
|
|
742
|
+
const type = isClassProvider2(provider) ? "class" : isFactoryProvider2(provider) ? "factory" : "value";
|
|
743
|
+
debug2("register %s (%s)", tokenToString(token), type);
|
|
744
|
+
this.providers.set(token, provider);
|
|
745
|
+
if (isValueProvider(provider)) {
|
|
746
|
+
this.trackCloseable(token, provider.useValue, provider.onClose);
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
registerClass(target) {
|
|
750
|
+
debug2("register %s (class)", target.name);
|
|
751
|
+
this.providers.set(target, {
|
|
752
|
+
useClass: target
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
registerValue(token, value) {
|
|
756
|
+
debug2("registerValue %s", tokenToString(token));
|
|
757
|
+
this.instances.set(token, value);
|
|
758
|
+
this.trackCloseable(token, value);
|
|
759
|
+
}
|
|
760
|
+
async resolve(token) {
|
|
761
|
+
const name = tokenToString(token);
|
|
762
|
+
if (this.instances.has(token)) {
|
|
763
|
+
debug2("resolve %s \u2192 cached", name);
|
|
764
|
+
return this.instances.get(token);
|
|
765
|
+
}
|
|
766
|
+
if (this.resolving.has(token)) {
|
|
767
|
+
const path = [
|
|
768
|
+
...this.resolving,
|
|
769
|
+
token
|
|
770
|
+
].map(tokenToString).join(" \u2192 ");
|
|
771
|
+
throw new Error(`Circular dependency detected: ${path}`);
|
|
772
|
+
}
|
|
773
|
+
debug2("resolve %s \u2192 constructing", name);
|
|
774
|
+
this.resolving.add(token);
|
|
775
|
+
try {
|
|
776
|
+
const provider = this.providers.get(token);
|
|
777
|
+
if (!provider) {
|
|
778
|
+
if (typeof token === "function") {
|
|
779
|
+
return this.constructClass(token);
|
|
780
|
+
}
|
|
781
|
+
throw new Error(`No provider registered for ${tokenToString(token)}.
|
|
782
|
+
Ensure the module providing it is included in your module's "imports" array,
|
|
783
|
+
or register a provider for it directly.`);
|
|
784
|
+
}
|
|
785
|
+
if (isFactoryProvider2(provider) && provider.inject) {
|
|
786
|
+
this.recordEdges(token, provider.inject);
|
|
787
|
+
}
|
|
788
|
+
const instance = await this.createFromProvider(provider);
|
|
789
|
+
this.instances.set(token, instance);
|
|
790
|
+
if (!isValueProvider(provider)) {
|
|
791
|
+
this.trackCloseable(token, instance, provider.onClose);
|
|
792
|
+
}
|
|
793
|
+
return instance;
|
|
794
|
+
} finally {
|
|
795
|
+
this.resolving.delete(token);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
async resolveClass(target) {
|
|
799
|
+
if (this.instances.has(target)) {
|
|
800
|
+
return this.instances.get(target);
|
|
801
|
+
}
|
|
802
|
+
if (this.resolving.has(target)) {
|
|
803
|
+
const path = [
|
|
804
|
+
...this.resolving,
|
|
805
|
+
target
|
|
806
|
+
].map(tokenToString).join(" \u2192 ");
|
|
807
|
+
throw new Error(`Circular dependency detected: ${path}`);
|
|
808
|
+
}
|
|
809
|
+
this.resolving.add(target);
|
|
810
|
+
try {
|
|
811
|
+
return this.constructClass(target);
|
|
812
|
+
} finally {
|
|
813
|
+
this.resolving.delete(target);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
has(token) {
|
|
817
|
+
return this.instances.has(token) || this.providers.has(token);
|
|
818
|
+
}
|
|
819
|
+
getDependencies(token) {
|
|
820
|
+
return this.edges.get(token) ?? /* @__PURE__ */ new Set();
|
|
821
|
+
}
|
|
822
|
+
async closeAll() {
|
|
823
|
+
debug2("closeAll: %d resources", this.closeStack.length);
|
|
824
|
+
const entries = [
|
|
825
|
+
...this.closeStack
|
|
826
|
+
].reverse();
|
|
827
|
+
for (const entry of entries) {
|
|
828
|
+
try {
|
|
829
|
+
debug2("closing %s", tokenToString(entry.token));
|
|
830
|
+
await entry.close();
|
|
831
|
+
} catch {
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
this.closeStack = [];
|
|
835
|
+
this.trackedTokens.clear();
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Validates that all registered providers have resolvable dependencies.
|
|
839
|
+
* Call after all module providers are registered but before resolution.
|
|
840
|
+
* Throws a descriptive error listing ALL missing dependencies at once.
|
|
841
|
+
*/
|
|
842
|
+
validateDependencies() {
|
|
843
|
+
const missing = [];
|
|
844
|
+
const visited = /* @__PURE__ */ new Set();
|
|
845
|
+
const walk = /* @__PURE__ */ __name((token) => {
|
|
846
|
+
if (visited.has(token)) return;
|
|
847
|
+
visited.add(token);
|
|
848
|
+
let depTokens;
|
|
849
|
+
const provider = this.providers.get(token);
|
|
850
|
+
if (provider) {
|
|
851
|
+
depTokens = this.getProviderDependencyTokens(provider);
|
|
852
|
+
} else if (typeof token === "function") {
|
|
853
|
+
depTokens = this.getClassDependencyTokens(token);
|
|
854
|
+
} else {
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
for (const dep of depTokens) {
|
|
858
|
+
if (this.providers.has(dep) || this.instances.has(dep)) {
|
|
859
|
+
walk(dep);
|
|
860
|
+
} else if (typeof dep === "function") {
|
|
861
|
+
walk(dep);
|
|
862
|
+
} else {
|
|
863
|
+
missing.push({
|
|
864
|
+
consumer: tokenToString(token),
|
|
865
|
+
dependency: tokenToString(dep)
|
|
866
|
+
});
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}, "walk");
|
|
870
|
+
for (const token of this.providers.keys()) {
|
|
871
|
+
walk(token);
|
|
872
|
+
}
|
|
873
|
+
if (missing.length > 0) {
|
|
874
|
+
const details = missing.map(({ consumer, dependency }) => ` ${consumer} requires ${dependency} \u2014 no provider registered`).join("\n");
|
|
875
|
+
throw new Error(`Unresolvable dependencies detected during bootstrap:
|
|
876
|
+
|
|
877
|
+
${details}
|
|
878
|
+
|
|
879
|
+
For each unresolved dependency, check that the module providing it is included
|
|
880
|
+
in your root module's "imports" array, or register a provider for it directly.`);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
getClassDependencyTokens(target) {
|
|
884
|
+
return getClassDependencyTokens(target);
|
|
885
|
+
}
|
|
886
|
+
getProviderDependencyTokens(provider) {
|
|
887
|
+
return getProviderDependencyTokens(provider);
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Constructs a class by resolving constructor dependencies via design:paramtypes.
|
|
891
|
+
* Does NOT manage the resolving set — callers (resolve/resolveClass) own cycle detection.
|
|
892
|
+
*/
|
|
893
|
+
async constructClass(target) {
|
|
894
|
+
if (this.instances.has(target)) {
|
|
895
|
+
return this.instances.get(target);
|
|
896
|
+
}
|
|
897
|
+
const isInjectable = Reflect.getOwnMetadata(INJECTABLE_METADATA, target) === true;
|
|
898
|
+
if (!isInjectable && target.length > 0) {
|
|
899
|
+
throw new Error(`Class ${target.name} has constructor parameters but is not decorated with @Injectable(). Add @Injectable() to enable dependency injection, or use a factory provider.`);
|
|
900
|
+
}
|
|
901
|
+
const depTokens = this.getClassDependencyTokens(target);
|
|
902
|
+
debug2("construct %s deps=[%s]", target.name, depTokens.map(tokenToString).join(", "));
|
|
903
|
+
this.recordEdges(target, depTokens);
|
|
904
|
+
const deps = [];
|
|
905
|
+
for (const t of depTokens) {
|
|
906
|
+
deps.push(await this.resolve(t));
|
|
907
|
+
}
|
|
908
|
+
const instance = new target(...deps);
|
|
909
|
+
this.instances.set(target, instance);
|
|
910
|
+
this.trackCloseable(target, instance);
|
|
911
|
+
return instance;
|
|
912
|
+
}
|
|
913
|
+
recordEdges(from, to) {
|
|
914
|
+
let set = this.edges.get(from);
|
|
915
|
+
if (!set) {
|
|
916
|
+
set = /* @__PURE__ */ new Set();
|
|
917
|
+
this.edges.set(from, set);
|
|
918
|
+
}
|
|
919
|
+
for (const dep of to) {
|
|
920
|
+
set.add(dep);
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
trackCloseable(token, value, onClose) {
|
|
924
|
+
if (this.trackedTokens.has(token)) return;
|
|
925
|
+
if (onClose) {
|
|
926
|
+
this.closeStack.push({
|
|
927
|
+
token,
|
|
928
|
+
close: /* @__PURE__ */ __name(() => onClose(value), "close")
|
|
929
|
+
});
|
|
930
|
+
this.trackedTokens.add(token);
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
const closeFn = detectCloseMethod(value);
|
|
934
|
+
if (closeFn) {
|
|
935
|
+
this.closeStack.push({
|
|
936
|
+
token,
|
|
937
|
+
close: closeFn
|
|
938
|
+
});
|
|
939
|
+
this.trackedTokens.add(token);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
async createFromProvider(provider) {
|
|
943
|
+
if (isValueProvider(provider)) {
|
|
944
|
+
return provider.useValue;
|
|
945
|
+
}
|
|
946
|
+
if (isClassProvider2(provider)) {
|
|
947
|
+
return this.constructClass(provider.useClass);
|
|
948
|
+
}
|
|
949
|
+
if (isFactoryProvider2(provider)) {
|
|
950
|
+
const deps = provider.inject ? await Promise.all(provider.inject.map((t) => this.resolve(t))) : [];
|
|
951
|
+
return provider.useFactory(...deps);
|
|
952
|
+
}
|
|
953
|
+
throw new Error("Invalid provider configuration");
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
// src/di/tokens.ts
|
|
958
|
+
var APP_CONFIG = /* @__PURE__ */ Symbol("celerity:app-config");
|
|
959
|
+
var RUNTIME_APP = /* @__PURE__ */ Symbol("celerity:runtime-app");
|
|
960
|
+
|
|
961
|
+
// src/application/factory.ts
|
|
962
|
+
var import_debug8 = __toESM(require("debug"), 1);
|
|
963
|
+
|
|
964
|
+
// src/bootstrap/bootstrap.ts
|
|
965
|
+
var import_reflect_metadata13 = require("reflect-metadata");
|
|
966
|
+
var import_debug5 = __toESM(require("debug"), 1);
|
|
967
|
+
|
|
968
|
+
// src/handlers/registry.ts
|
|
969
|
+
var import_reflect_metadata12 = require("reflect-metadata");
|
|
970
|
+
var import_debug4 = __toESM(require("debug"), 1);
|
|
971
|
+
var import_common = require("@celerity-sdk/common");
|
|
972
|
+
|
|
973
|
+
// src/bootstrap/module-graph.ts
|
|
974
|
+
var import_reflect_metadata11 = require("reflect-metadata");
|
|
975
|
+
var import_debug3 = __toESM(require("debug"), 1);
|
|
976
|
+
var debug3 = (0, import_debug3.default)("celerity:core:bootstrap");
|
|
977
|
+
function buildModuleGraph(rootModule) {
|
|
978
|
+
const graph = /* @__PURE__ */ new Map();
|
|
979
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
980
|
+
function walk(moduleClass, importChain) {
|
|
981
|
+
if (graph.has(moduleClass)) {
|
|
982
|
+
debug3("walk %s \u2192 already visited", moduleClass.name);
|
|
983
|
+
return;
|
|
984
|
+
}
|
|
985
|
+
if (resolving.has(moduleClass)) {
|
|
986
|
+
const cyclePath = [
|
|
987
|
+
...importChain,
|
|
988
|
+
moduleClass
|
|
989
|
+
].map((m) => m.name).join(" \u2192 ");
|
|
990
|
+
throw new Error(`Circular module import detected: ${cyclePath}`);
|
|
991
|
+
}
|
|
992
|
+
resolving.add(moduleClass);
|
|
993
|
+
const metadata = Reflect.getOwnMetadata(MODULE_METADATA, moduleClass);
|
|
994
|
+
if (!metadata) {
|
|
995
|
+
resolving.delete(moduleClass);
|
|
996
|
+
graph.set(moduleClass, {
|
|
997
|
+
moduleClass,
|
|
998
|
+
ownTokens: /* @__PURE__ */ new Set(),
|
|
999
|
+
exports: /* @__PURE__ */ new Set(),
|
|
1000
|
+
imports: [],
|
|
1001
|
+
controllers: [],
|
|
1002
|
+
functionHandlers: [],
|
|
1003
|
+
providers: []
|
|
1004
|
+
});
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const imports = metadata.imports ?? [];
|
|
1008
|
+
for (const imported of imports) {
|
|
1009
|
+
walk(imported, [
|
|
1010
|
+
...importChain,
|
|
1011
|
+
moduleClass
|
|
1012
|
+
]);
|
|
1013
|
+
}
|
|
1014
|
+
const ownTokens = /* @__PURE__ */ new Set();
|
|
1015
|
+
const providers = metadata.providers ?? [];
|
|
1016
|
+
for (const provider of providers) {
|
|
1017
|
+
if (typeof provider === "function") {
|
|
1018
|
+
ownTokens.add(provider);
|
|
1019
|
+
} else {
|
|
1020
|
+
const typed = provider;
|
|
1021
|
+
ownTokens.add(typed.provide);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
const controllers = metadata.controllers ?? [];
|
|
1025
|
+
for (const controller of controllers) {
|
|
1026
|
+
ownTokens.add(controller);
|
|
1027
|
+
}
|
|
1028
|
+
const exportTokens = new Set(metadata.exports ?? []);
|
|
1029
|
+
resolving.delete(moduleClass);
|
|
1030
|
+
debug3("walk %s: %d providers, %d controllers, %d imports", moduleClass.name, providers.length, controllers.length, imports.length);
|
|
1031
|
+
graph.set(moduleClass, {
|
|
1032
|
+
moduleClass,
|
|
1033
|
+
ownTokens,
|
|
1034
|
+
exports: exportTokens,
|
|
1035
|
+
imports,
|
|
1036
|
+
controllers,
|
|
1037
|
+
functionHandlers: metadata.functionHandlers ?? [],
|
|
1038
|
+
providers
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
__name(walk, "walk");
|
|
1042
|
+
walk(rootModule, []);
|
|
1043
|
+
return graph;
|
|
1044
|
+
}
|
|
1045
|
+
__name(buildModuleGraph, "buildModuleGraph");
|
|
1046
|
+
function registerModuleGraph(graph, container) {
|
|
1047
|
+
for (const [, node] of graph) {
|
|
1048
|
+
for (const provider of node.providers) {
|
|
1049
|
+
if (typeof provider === "function") {
|
|
1050
|
+
container.registerClass(provider);
|
|
1051
|
+
} else {
|
|
1052
|
+
const typed = provider;
|
|
1053
|
+
container.register(typed.provide, typed);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
for (const controller of node.controllers) {
|
|
1057
|
+
if (!container.has(controller)) {
|
|
1058
|
+
container.registerClass(controller);
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
__name(registerModuleGraph, "registerModuleGraph");
|
|
1064
|
+
function walkModuleGraph(rootModule, container) {
|
|
1065
|
+
const graph = buildModuleGraph(rootModule);
|
|
1066
|
+
registerModuleGraph(graph, container);
|
|
1067
|
+
return graph;
|
|
1068
|
+
}
|
|
1069
|
+
__name(walkModuleGraph, "walkModuleGraph");
|
|
1070
|
+
function validateModuleGraph(graph, container) {
|
|
1071
|
+
const diagnostics = [];
|
|
1072
|
+
for (const [, node] of graph) {
|
|
1073
|
+
for (const exportToken of node.exports) {
|
|
1074
|
+
if (!node.ownTokens.has(exportToken)) {
|
|
1075
|
+
diagnostics.push({
|
|
1076
|
+
type: "invalid_export",
|
|
1077
|
+
message: `${node.moduleClass.name} exports ${tokenToString(exportToken)}, but that token is not provided by this module.`
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
const visibleTokens = new Set(node.ownTokens);
|
|
1082
|
+
for (const importedModule of node.imports) {
|
|
1083
|
+
const importedNode = graph.get(importedModule);
|
|
1084
|
+
if (importedNode) {
|
|
1085
|
+
for (const exportedToken of importedNode.exports) {
|
|
1086
|
+
visibleTokens.add(exportedToken);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
for (const provider of node.providers) {
|
|
1091
|
+
let depTokens;
|
|
1092
|
+
let consumerToken;
|
|
1093
|
+
if (typeof provider === "function") {
|
|
1094
|
+
consumerToken = provider;
|
|
1095
|
+
depTokens = getClassDependencyTokens(provider);
|
|
1096
|
+
} else {
|
|
1097
|
+
const typed = provider;
|
|
1098
|
+
consumerToken = typed.provide;
|
|
1099
|
+
depTokens = getProviderDependencyTokens(typed);
|
|
1100
|
+
}
|
|
1101
|
+
checkDependencies(consumerToken, depTokens, visibleTokens, node.moduleClass, graph, container, diagnostics);
|
|
1102
|
+
}
|
|
1103
|
+
for (const controller of node.controllers) {
|
|
1104
|
+
const depTokens = getClassDependencyTokens(controller);
|
|
1105
|
+
checkDependencies(controller, depTokens, visibleTokens, node.moduleClass, graph, container, diagnostics);
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
1108
|
+
debug3("validateModuleGraph: %d modules, %d diagnostics", graph.size, diagnostics.length);
|
|
1109
|
+
if (diagnostics.length > 0) {
|
|
1110
|
+
const details = diagnostics.map((d) => ` ${d.message}`).join("\n");
|
|
1111
|
+
throw new Error(`Module validation errors:
|
|
1112
|
+
|
|
1113
|
+
${details}`);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
__name(validateModuleGraph, "validateModuleGraph");
|
|
1117
|
+
function checkDependencies(consumer, depTokens, visibleTokens, moduleClass, graph, container, diagnostics) {
|
|
1118
|
+
for (const dep of depTokens) {
|
|
1119
|
+
if (visibleTokens.has(dep)) continue;
|
|
1120
|
+
const ownerModule = findTokenOwner(dep, graph);
|
|
1121
|
+
if (ownerModule) {
|
|
1122
|
+
const ownerNode = graph.get(ownerModule);
|
|
1123
|
+
if (ownerNode.exports.has(dep)) {
|
|
1124
|
+
diagnostics.push({
|
|
1125
|
+
type: "export_violation",
|
|
1126
|
+
message: `${tokenToString(consumer)} in ${moduleClass.name} depends on ${tokenToString(dep)}, which is exported from ${ownerModule.name} but ${moduleClass.name} does not import ${ownerModule.name}. Add ${ownerModule.name} to ${moduleClass.name}'s "imports" array.`
|
|
1127
|
+
});
|
|
1128
|
+
} else {
|
|
1129
|
+
diagnostics.push({
|
|
1130
|
+
type: "export_violation",
|
|
1131
|
+
message: `${tokenToString(consumer)} in ${moduleClass.name} depends on ${tokenToString(dep)}, but ${tokenToString(dep)} is not exported from ${ownerModule.name}. Add ${tokenToString(dep)} to ${ownerModule.name}'s "exports" array.`
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
continue;
|
|
1135
|
+
}
|
|
1136
|
+
if (typeof dep === "function") {
|
|
1137
|
+
if (!container.has(dep)) {
|
|
1138
|
+
container.registerClass(dep);
|
|
1139
|
+
}
|
|
1140
|
+
visibleTokens.add(dep);
|
|
1141
|
+
const adoptedDeps = getClassDependencyTokens(dep);
|
|
1142
|
+
checkDependencies(dep, adoptedDeps, visibleTokens, moduleClass, graph, container, diagnostics);
|
|
1143
|
+
continue;
|
|
1144
|
+
}
|
|
1145
|
+
diagnostics.push({
|
|
1146
|
+
type: "missing_dependency",
|
|
1147
|
+
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.`
|
|
1148
|
+
});
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
__name(checkDependencies, "checkDependencies");
|
|
1152
|
+
function findTokenOwner(token, graph) {
|
|
1153
|
+
for (const [, node] of graph) {
|
|
1154
|
+
if (node.ownTokens.has(token)) {
|
|
1155
|
+
return node.moduleClass;
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1160
|
+
__name(findTokenOwner, "findTokenOwner");
|
|
1161
|
+
|
|
1162
|
+
// src/handlers/registry.ts
|
|
1163
|
+
var debug4 = (0, import_debug4.default)("celerity:core:registry");
|
|
1164
|
+
var HandlerRegistry = class {
|
|
1165
|
+
static {
|
|
1166
|
+
__name(this, "HandlerRegistry");
|
|
1167
|
+
}
|
|
1168
|
+
handlers = [];
|
|
1169
|
+
getHandler(path, method) {
|
|
1170
|
+
const found = this.handlers.find((h) => h.path !== void 0 && h.method !== void 0 && matchRoute(h.path, path) && h.method === method);
|
|
1171
|
+
debug4("getHandler %s %s \u2192 %s", method, path, found ? "matched" : "not found");
|
|
1172
|
+
return found;
|
|
1173
|
+
}
|
|
1174
|
+
getAllHandlers() {
|
|
1175
|
+
return [
|
|
1176
|
+
...this.handlers
|
|
1177
|
+
];
|
|
1178
|
+
}
|
|
1179
|
+
async populateFromGraph(graph, container) {
|
|
1180
|
+
for (const [, node] of graph) {
|
|
1181
|
+
for (const controllerClass of node.controllers) {
|
|
1182
|
+
await this.registerClassHandler(controllerClass, container);
|
|
1183
|
+
}
|
|
1184
|
+
for (const fnHandler of node.functionHandlers) {
|
|
1185
|
+
this.registerFunctionHandler(fnHandler);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
async scanModule(moduleClass, container) {
|
|
1190
|
+
const graph = buildModuleGraph(moduleClass);
|
|
1191
|
+
registerModuleGraph(graph, container);
|
|
1192
|
+
await this.populateFromGraph(graph, container);
|
|
1193
|
+
}
|
|
1194
|
+
async registerClassHandler(controllerClass, container) {
|
|
1195
|
+
const controllerMeta = Reflect.getOwnMetadata(CONTROLLER_METADATA, controllerClass);
|
|
1196
|
+
if (!controllerMeta) return;
|
|
1197
|
+
const instance = await container.resolve(controllerClass);
|
|
1198
|
+
const prototype = Object.getPrototypeOf(instance);
|
|
1199
|
+
const methods = Object.getOwnPropertyNames(prototype).filter((name) => name !== "constructor");
|
|
1200
|
+
const classProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, controllerClass) ?? [];
|
|
1201
|
+
const classLayers = Reflect.getOwnMetadata(LAYER_METADATA, controllerClass) ?? [];
|
|
1202
|
+
const classCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, controllerClass) ?? {};
|
|
1203
|
+
for (const methodName of methods) {
|
|
1204
|
+
const method = Reflect.getOwnMetadata(HTTP_METHOD_METADATA, prototype, methodName);
|
|
1205
|
+
if (!method) continue;
|
|
1206
|
+
const routePath = Reflect.getOwnMetadata(ROUTE_PATH_METADATA, prototype, methodName) ?? "/";
|
|
1207
|
+
const fullPath = (0, import_common.joinHandlerPath)(controllerMeta.prefix ?? "", routePath);
|
|
1208
|
+
const methodProtectedBy = Reflect.getOwnMetadata(GUARD_PROTECTEDBY_METADATA, prototype, methodName) ?? [];
|
|
1209
|
+
const methodLayers = Reflect.getOwnMetadata(LAYER_METADATA, prototype, methodName) ?? [];
|
|
1210
|
+
const paramMetadata = Reflect.getOwnMetadata(PARAM_METADATA, prototype, methodName) ?? [];
|
|
1211
|
+
const isPublic = Reflect.getOwnMetadata(PUBLIC_METADATA, prototype, methodName) === true;
|
|
1212
|
+
const methodCustomMetadata = Reflect.getOwnMetadata(CUSTOM_METADATA, prototype, methodName) ?? {};
|
|
1213
|
+
const descriptor = Object.getOwnPropertyDescriptor(prototype, methodName);
|
|
1214
|
+
if (!descriptor?.value || typeof descriptor.value !== "function") continue;
|
|
1215
|
+
const layers = [
|
|
1216
|
+
...classLayers,
|
|
1217
|
+
...methodLayers
|
|
1218
|
+
];
|
|
1219
|
+
const validationSchemas = buildValidationSchemasFromParams(paramMetadata);
|
|
1220
|
+
if (validationSchemas) {
|
|
1221
|
+
layers.unshift(validate(validationSchemas));
|
|
1222
|
+
}
|
|
1223
|
+
debug4("registerClassHandler: %s %s (%s.%s)", method, fullPath, controllerClass.name, methodName);
|
|
1224
|
+
this.handlers.push({
|
|
1225
|
+
path: fullPath,
|
|
1226
|
+
method,
|
|
1227
|
+
protectedBy: [
|
|
1228
|
+
...classProtectedBy,
|
|
1229
|
+
...methodProtectedBy
|
|
1230
|
+
],
|
|
1231
|
+
layers,
|
|
1232
|
+
isPublic,
|
|
1233
|
+
paramMetadata,
|
|
1234
|
+
customMetadata: {
|
|
1235
|
+
...classCustomMetadata,
|
|
1236
|
+
...methodCustomMetadata
|
|
1237
|
+
},
|
|
1238
|
+
handlerFn: descriptor.value,
|
|
1239
|
+
handlerInstance: instance
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
registerFunctionHandler(definition) {
|
|
1244
|
+
if (definition.type !== "http") return;
|
|
1245
|
+
const meta = definition.metadata;
|
|
1246
|
+
const layers = [
|
|
1247
|
+
...meta.layers ?? []
|
|
1248
|
+
];
|
|
1249
|
+
if (meta.schema) {
|
|
1250
|
+
const schemas = {};
|
|
1251
|
+
if (meta.schema.body) schemas.body = meta.schema.body;
|
|
1252
|
+
if (meta.schema.query) schemas.query = meta.schema.query;
|
|
1253
|
+
if (meta.schema.params) schemas.params = meta.schema.params;
|
|
1254
|
+
if (meta.schema.headers) schemas.headers = meta.schema.headers;
|
|
1255
|
+
if (Object.keys(schemas).length > 0) {
|
|
1256
|
+
layers.unshift(validate(schemas));
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
debug4("registerFunctionHandler: %s", meta.method && meta.path ? `${meta.method} ${meta.path}` : "(no route)");
|
|
1260
|
+
this.handlers.push({
|
|
1261
|
+
path: meta.path,
|
|
1262
|
+
method: meta.method,
|
|
1263
|
+
protectedBy: [],
|
|
1264
|
+
layers,
|
|
1265
|
+
isPublic: false,
|
|
1266
|
+
paramMetadata: [],
|
|
1267
|
+
customMetadata: meta.customMetadata ?? {},
|
|
1268
|
+
handlerFn: definition.handler,
|
|
1269
|
+
isFunctionHandler: true,
|
|
1270
|
+
injectTokens: meta.inject ?? []
|
|
1271
|
+
});
|
|
1272
|
+
}
|
|
1273
|
+
};
|
|
1274
|
+
function matchRoute(pattern, actual) {
|
|
1275
|
+
const patternParts = pattern.split("/").filter(Boolean);
|
|
1276
|
+
const actualParts = actual.split("/").filter(Boolean);
|
|
1277
|
+
if (patternParts.length !== actualParts.length) return false;
|
|
1278
|
+
return patternParts.every((part, i) => part.startsWith("{") || part === actualParts[i]);
|
|
1279
|
+
}
|
|
1280
|
+
__name(matchRoute, "matchRoute");
|
|
1281
|
+
var PARAM_TYPE_TO_SCHEMA_KEY = {
|
|
1282
|
+
body: "body",
|
|
1283
|
+
query: "query",
|
|
1284
|
+
param: "params",
|
|
1285
|
+
headers: "headers"
|
|
1286
|
+
};
|
|
1287
|
+
function buildValidationSchemasFromParams(paramMetadata) {
|
|
1288
|
+
const wholeObjectSchemas = /* @__PURE__ */ new Map();
|
|
1289
|
+
const perKeySchemas = /* @__PURE__ */ new Map();
|
|
1290
|
+
for (const meta of paramMetadata) {
|
|
1291
|
+
if (!meta.schema) continue;
|
|
1292
|
+
const schemaKey = PARAM_TYPE_TO_SCHEMA_KEY[meta.type];
|
|
1293
|
+
if (!schemaKey) continue;
|
|
1294
|
+
if (meta.key) {
|
|
1295
|
+
let keyMap = perKeySchemas.get(schemaKey);
|
|
1296
|
+
if (!keyMap) {
|
|
1297
|
+
keyMap = /* @__PURE__ */ new Map();
|
|
1298
|
+
perKeySchemas.set(schemaKey, keyMap);
|
|
1299
|
+
}
|
|
1300
|
+
keyMap.set(meta.key, meta.schema);
|
|
1301
|
+
} else {
|
|
1302
|
+
wholeObjectSchemas.set(schemaKey, meta.schema);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
const schemas = {};
|
|
1306
|
+
let hasSchemas = false;
|
|
1307
|
+
for (const key of [
|
|
1308
|
+
"body",
|
|
1309
|
+
"query",
|
|
1310
|
+
"params",
|
|
1311
|
+
"headers"
|
|
1312
|
+
]) {
|
|
1313
|
+
if (wholeObjectSchemas.has(key)) {
|
|
1314
|
+
schemas[key] = wholeObjectSchemas.get(key);
|
|
1315
|
+
hasSchemas = true;
|
|
1316
|
+
} else if (perKeySchemas.has(key)) {
|
|
1317
|
+
schemas[key] = composeKeySchemas(perKeySchemas.get(key));
|
|
1318
|
+
hasSchemas = true;
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
return hasSchemas ? schemas : null;
|
|
1322
|
+
}
|
|
1323
|
+
__name(buildValidationSchemasFromParams, "buildValidationSchemasFromParams");
|
|
1324
|
+
function composeKeySchemas(keySchemas) {
|
|
1325
|
+
return {
|
|
1326
|
+
parse(data) {
|
|
1327
|
+
const record = data;
|
|
1328
|
+
const result = {
|
|
1329
|
+
...record
|
|
1330
|
+
};
|
|
1331
|
+
for (const [key, schema] of keySchemas) {
|
|
1332
|
+
if (key in result) {
|
|
1333
|
+
result[key] = schema.parse(result[key]);
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
return result;
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
}
|
|
1340
|
+
__name(composeKeySchemas, "composeKeySchemas");
|
|
1341
|
+
|
|
1342
|
+
// src/bootstrap/bootstrap.ts
|
|
1343
|
+
var debug5 = (0, import_debug5.default)("celerity:core:bootstrap");
|
|
1344
|
+
async function bootstrap(rootModule) {
|
|
1345
|
+
debug5("bootstrap: starting from %s", rootModule.name);
|
|
1346
|
+
const container = new Container();
|
|
1347
|
+
const registry = new HandlerRegistry();
|
|
1348
|
+
const graph = walkModuleGraph(rootModule, container);
|
|
1349
|
+
validateModuleGraph(graph, container);
|
|
1350
|
+
await registry.populateFromGraph(graph, container);
|
|
1351
|
+
debug5("bootstrap: complete \u2014 %d modules, %d handlers", graph.size, registry.getAllHandlers().length);
|
|
1352
|
+
return {
|
|
1353
|
+
container,
|
|
1354
|
+
registry
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
__name(bootstrap, "bootstrap");
|
|
1358
|
+
|
|
1359
|
+
// src/application/application.ts
|
|
1360
|
+
var import_debug6 = __toESM(require("debug"), 1);
|
|
1361
|
+
var debug6 = (0, import_debug6.default)("celerity:core:factory");
|
|
1362
|
+
var CelerityApplication = class {
|
|
1363
|
+
static {
|
|
1364
|
+
__name(this, "CelerityApplication");
|
|
1365
|
+
}
|
|
1366
|
+
registry;
|
|
1367
|
+
container;
|
|
1368
|
+
systemLayers;
|
|
1369
|
+
appLayers;
|
|
1370
|
+
runtimeApp;
|
|
1371
|
+
constructor(registry, container, systemLayers = [], appLayers = [], runtimeApp) {
|
|
1372
|
+
this.registry = registry;
|
|
1373
|
+
this.container = container;
|
|
1374
|
+
this.systemLayers = systemLayers;
|
|
1375
|
+
this.appLayers = appLayers;
|
|
1376
|
+
this.runtimeApp = runtimeApp;
|
|
1377
|
+
}
|
|
1378
|
+
async start() {
|
|
1379
|
+
if (this.runtimeApp && typeof this.runtimeApp === "object") {
|
|
1380
|
+
const app = this.runtimeApp;
|
|
1381
|
+
await app.run(false);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
async close() {
|
|
1385
|
+
debug6("close: shutting down application");
|
|
1386
|
+
if (this.runtimeApp && typeof this.runtimeApp === "object") {
|
|
1387
|
+
const app = this.runtimeApp;
|
|
1388
|
+
await app.shutdown();
|
|
1389
|
+
}
|
|
1390
|
+
await this.container.closeAll();
|
|
1391
|
+
await disposeLayers([
|
|
1392
|
+
...this.systemLayers,
|
|
1393
|
+
...this.appLayers
|
|
1394
|
+
]);
|
|
1395
|
+
}
|
|
1396
|
+
getContainer() {
|
|
1397
|
+
return this.container;
|
|
1398
|
+
}
|
|
1399
|
+
getRegistry() {
|
|
1400
|
+
return this.registry;
|
|
1401
|
+
}
|
|
1402
|
+
getSystemLayers() {
|
|
1403
|
+
return this.systemLayers;
|
|
1404
|
+
}
|
|
1405
|
+
getAppLayers() {
|
|
1406
|
+
return this.appLayers;
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
|
|
1410
|
+
// src/application/serverless.ts
|
|
1411
|
+
var ServerlessApplication = class {
|
|
1412
|
+
static {
|
|
1413
|
+
__name(this, "ServerlessApplication");
|
|
1414
|
+
}
|
|
1415
|
+
registry;
|
|
1416
|
+
container;
|
|
1417
|
+
adapter;
|
|
1418
|
+
systemLayers;
|
|
1419
|
+
appLayers;
|
|
1420
|
+
handler = null;
|
|
1421
|
+
constructor(registry, container, adapter, systemLayers = [], appLayers = []) {
|
|
1422
|
+
this.registry = registry;
|
|
1423
|
+
this.container = container;
|
|
1424
|
+
this.adapter = adapter;
|
|
1425
|
+
this.systemLayers = systemLayers;
|
|
1426
|
+
this.appLayers = appLayers;
|
|
1427
|
+
}
|
|
1428
|
+
async start() {
|
|
1429
|
+
this.handler = this.adapter.createHandler(this.registry, {
|
|
1430
|
+
container: this.container,
|
|
1431
|
+
systemLayers: this.systemLayers,
|
|
1432
|
+
appLayers: this.appLayers
|
|
1433
|
+
});
|
|
1434
|
+
return this.handler;
|
|
1435
|
+
}
|
|
1436
|
+
async close() {
|
|
1437
|
+
await this.container.closeAll();
|
|
1438
|
+
await disposeLayers([
|
|
1439
|
+
...this.systemLayers,
|
|
1440
|
+
...this.appLayers
|
|
1441
|
+
]);
|
|
1442
|
+
}
|
|
1443
|
+
getHandler() {
|
|
1444
|
+
if (!this.handler) {
|
|
1445
|
+
throw new Error("ServerlessApplication.start() must be called before getHandler()");
|
|
1446
|
+
}
|
|
1447
|
+
return this.handler;
|
|
1448
|
+
}
|
|
1449
|
+
getContainer() {
|
|
1450
|
+
return this.container;
|
|
1451
|
+
}
|
|
1452
|
+
getRegistry() {
|
|
1453
|
+
return this.registry;
|
|
1454
|
+
}
|
|
1455
|
+
};
|
|
1456
|
+
|
|
1457
|
+
// src/handlers/pipeline.ts
|
|
1458
|
+
var import_debug7 = __toESM(require("debug"), 1);
|
|
1459
|
+
|
|
1460
|
+
// src/functions/context.ts
|
|
1461
|
+
function buildHttpRequest(request, metadata) {
|
|
1462
|
+
const validatedBody = metadata.get("validatedBody");
|
|
1463
|
+
let body;
|
|
1464
|
+
if (validatedBody !== void 0) {
|
|
1465
|
+
body = validatedBody;
|
|
1466
|
+
} else if (request.binaryBody) {
|
|
1467
|
+
body = request.binaryBody;
|
|
1468
|
+
} else if (request.textBody) {
|
|
1469
|
+
body = JSON.parse(request.textBody);
|
|
1470
|
+
} else {
|
|
1471
|
+
body = null;
|
|
1472
|
+
}
|
|
1473
|
+
return {
|
|
1474
|
+
method: request.method,
|
|
1475
|
+
path: request.path,
|
|
1476
|
+
params: metadata.get("validatedParams") ?? request.pathParams,
|
|
1477
|
+
query: metadata.get("validatedQuery") ?? request.query,
|
|
1478
|
+
body,
|
|
1479
|
+
headers: metadata.get("validatedHeaders") ?? request.headers,
|
|
1480
|
+
cookies: request.cookies,
|
|
1481
|
+
auth: request.auth,
|
|
1482
|
+
clientIp: request.clientIp,
|
|
1483
|
+
userAgent: request.userAgent,
|
|
1484
|
+
contentType: request.contentType
|
|
1485
|
+
};
|
|
1486
|
+
}
|
|
1487
|
+
__name(buildHttpRequest, "buildHttpRequest");
|
|
1488
|
+
function buildHttpContext(request, metadata, container, logger) {
|
|
1489
|
+
return {
|
|
1490
|
+
requestId: request.requestId,
|
|
1491
|
+
requestTime: request.requestTime,
|
|
1492
|
+
metadata,
|
|
1493
|
+
container,
|
|
1494
|
+
logger,
|
|
1495
|
+
raw: request
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
__name(buildHttpContext, "buildHttpContext");
|
|
1499
|
+
|
|
1500
|
+
// src/handlers/pipeline.ts
|
|
1501
|
+
var debug7 = (0, import_debug7.default)("celerity:core:pipeline");
|
|
1502
|
+
async function executeHandlerPipeline(handler, request, options) {
|
|
1503
|
+
const context = {
|
|
1504
|
+
request,
|
|
1505
|
+
metadata: new HandlerMetadataStore(handler.customMetadata ?? {}),
|
|
1506
|
+
container: options.container
|
|
1507
|
+
};
|
|
1508
|
+
const allLayers = [
|
|
1509
|
+
...options.systemLayers ?? [],
|
|
1510
|
+
...options.appLayers ?? [],
|
|
1511
|
+
...handler.layers
|
|
1512
|
+
];
|
|
1513
|
+
debug7("%s %s \u2014 %d layers", request.method, request.path, allLayers.length);
|
|
1514
|
+
try {
|
|
1515
|
+
const response = await runLayerPipeline(allLayers, context, async () => {
|
|
1516
|
+
const handlerType = handler.isFunctionHandler ? "function" : "class";
|
|
1517
|
+
debug7("invoking %s handler", handlerType);
|
|
1518
|
+
const result = handler.isFunctionHandler ? await invokeFunctionHandler(handler, context) : await invokeClassHandler(handler, context);
|
|
1519
|
+
return normalizeResponse(result);
|
|
1520
|
+
});
|
|
1521
|
+
debug7("response %d", response.status);
|
|
1522
|
+
return response;
|
|
1523
|
+
} catch (error) {
|
|
1524
|
+
if (error instanceof HttpException) {
|
|
1525
|
+
debug7("HttpException %d: %s", error.statusCode, error.message);
|
|
1526
|
+
return {
|
|
1527
|
+
status: error.statusCode,
|
|
1528
|
+
headers: {
|
|
1529
|
+
"content-type": "application/json"
|
|
1530
|
+
},
|
|
1531
|
+
body: JSON.stringify({
|
|
1532
|
+
message: error.message,
|
|
1533
|
+
...error.details ? {
|
|
1534
|
+
details: error.details
|
|
1535
|
+
} : {}
|
|
1536
|
+
})
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1540
|
+
if (context.logger) {
|
|
1541
|
+
context.logger.error("Unhandled error in handler pipeline", {
|
|
1542
|
+
error: message,
|
|
1543
|
+
...error instanceof Error && error.stack ? {
|
|
1544
|
+
stack: error.stack
|
|
1545
|
+
} : {}
|
|
1546
|
+
});
|
|
1547
|
+
} else {
|
|
1548
|
+
console.error("Unhandled error in handler pipeline:", error);
|
|
1549
|
+
}
|
|
1550
|
+
return {
|
|
1551
|
+
status: 500,
|
|
1552
|
+
headers: {
|
|
1553
|
+
"content-type": "application/json"
|
|
1554
|
+
},
|
|
1555
|
+
body: JSON.stringify({
|
|
1556
|
+
message: "Internal Server Error"
|
|
1557
|
+
})
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
__name(executeHandlerPipeline, "executeHandlerPipeline");
|
|
1562
|
+
async function invokeClassHandler(handler, context) {
|
|
1563
|
+
const args = [];
|
|
1564
|
+
const sorted = [
|
|
1565
|
+
...handler.paramMetadata
|
|
1566
|
+
].sort((a, b) => a.index - b.index);
|
|
1567
|
+
for (const meta of sorted) {
|
|
1568
|
+
args[meta.index] = extractValidatedParam(meta.type, meta.key, context.request, context.metadata);
|
|
1569
|
+
}
|
|
1570
|
+
return handler.handlerFn.apply(handler.handlerInstance, args);
|
|
1571
|
+
}
|
|
1572
|
+
__name(invokeClassHandler, "invokeClassHandler");
|
|
1573
|
+
var VALIDATED_METADATA_KEYS = {
|
|
1574
|
+
body: "validatedBody",
|
|
1575
|
+
query: "validatedQuery",
|
|
1576
|
+
param: "validatedParams",
|
|
1577
|
+
headers: "validatedHeaders"
|
|
1578
|
+
};
|
|
1579
|
+
function extractValidatedParam(type, key, request, metadata) {
|
|
1580
|
+
const metaKey = VALIDATED_METADATA_KEYS[type];
|
|
1581
|
+
if (metaKey) {
|
|
1582
|
+
const validated = metadata.get(metaKey);
|
|
1583
|
+
if (validated !== void 0) {
|
|
1584
|
+
if (key && typeof validated === "object" && validated !== null) {
|
|
1585
|
+
return validated[key];
|
|
1586
|
+
}
|
|
1587
|
+
return validated;
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return extractParam(type, key, request);
|
|
1591
|
+
}
|
|
1592
|
+
__name(extractValidatedParam, "extractValidatedParam");
|
|
1593
|
+
async function invokeFunctionHandler(handler, context) {
|
|
1594
|
+
const req = buildHttpRequest(context.request, context.metadata);
|
|
1595
|
+
const ctx = buildHttpContext(context.request, context.metadata, context.container, context.logger);
|
|
1596
|
+
if (handler.injectTokens && handler.injectTokens.length > 0) {
|
|
1597
|
+
const deps = [];
|
|
1598
|
+
for (const token of handler.injectTokens) {
|
|
1599
|
+
deps.push(await context.container.resolve(token));
|
|
1600
|
+
}
|
|
1601
|
+
return handler.handlerFn(req, ctx, ...deps);
|
|
1602
|
+
}
|
|
1603
|
+
return handler.handlerFn(req, ctx);
|
|
1604
|
+
}
|
|
1605
|
+
__name(invokeFunctionHandler, "invokeFunctionHandler");
|
|
1606
|
+
function normalizeResponse(result) {
|
|
1607
|
+
if (isHttpResponse(result)) {
|
|
1608
|
+
return result;
|
|
1609
|
+
}
|
|
1610
|
+
if (result === void 0 || result === null) {
|
|
1611
|
+
return {
|
|
1612
|
+
status: 204
|
|
1613
|
+
};
|
|
1614
|
+
}
|
|
1615
|
+
const body = typeof result === "string" ? result : JSON.stringify(result);
|
|
1616
|
+
return {
|
|
1617
|
+
status: 200,
|
|
1618
|
+
headers: {
|
|
1619
|
+
"content-type": "application/json"
|
|
1620
|
+
},
|
|
1621
|
+
body
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
__name(normalizeResponse, "normalizeResponse");
|
|
1625
|
+
function isHttpResponse(value) {
|
|
1626
|
+
return typeof value === "object" && value !== null && "status" in value && typeof value.status === "number";
|
|
1627
|
+
}
|
|
1628
|
+
__name(isHttpResponse, "isHttpResponse");
|
|
1629
|
+
|
|
1630
|
+
// src/testing/test-app.ts
|
|
1631
|
+
var TestingApplication = class {
|
|
1632
|
+
static {
|
|
1633
|
+
__name(this, "TestingApplication");
|
|
1634
|
+
}
|
|
1635
|
+
registry;
|
|
1636
|
+
container;
|
|
1637
|
+
systemLayers;
|
|
1638
|
+
appLayers;
|
|
1639
|
+
constructor(registry, container, systemLayers = [], appLayers = []) {
|
|
1640
|
+
this.registry = registry;
|
|
1641
|
+
this.container = container;
|
|
1642
|
+
this.systemLayers = systemLayers;
|
|
1643
|
+
this.appLayers = appLayers;
|
|
1644
|
+
}
|
|
1645
|
+
async inject(request) {
|
|
1646
|
+
const handler = this.registry.getHandler(request.path, request.method);
|
|
1647
|
+
if (!handler) {
|
|
1648
|
+
throw new NotFoundException(`No handler found for ${request.method} ${request.path}`);
|
|
1649
|
+
}
|
|
1650
|
+
return executeHandlerPipeline(handler, request, {
|
|
1651
|
+
container: this.container,
|
|
1652
|
+
systemLayers: this.systemLayers,
|
|
1653
|
+
appLayers: this.appLayers
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
getContainer() {
|
|
1657
|
+
return this.container;
|
|
1658
|
+
}
|
|
1659
|
+
getRegistry() {
|
|
1660
|
+
return this.registry;
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
function mockRequest(method, path, options = {}) {
|
|
1664
|
+
return {
|
|
1665
|
+
method,
|
|
1666
|
+
path,
|
|
1667
|
+
pathParams: options.pathParams ?? {},
|
|
1668
|
+
query: options.query ?? {},
|
|
1669
|
+
headers: options.headers ?? {},
|
|
1670
|
+
cookies: options.cookies ?? {},
|
|
1671
|
+
textBody: options.body !== void 0 ? JSON.stringify(options.body) : null,
|
|
1672
|
+
binaryBody: null,
|
|
1673
|
+
contentType: options.body !== void 0 ? "application/json" : null,
|
|
1674
|
+
requestId: options.requestId ?? "test-request-id",
|
|
1675
|
+
requestTime: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1676
|
+
auth: options.auth ?? null,
|
|
1677
|
+
clientIp: options.clientIp ?? "127.0.0.1",
|
|
1678
|
+
traceContext: null,
|
|
1679
|
+
userAgent: "celerity-testing",
|
|
1680
|
+
matchedRoute: null
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
__name(mockRequest, "mockRequest");
|
|
1684
|
+
|
|
1685
|
+
// src/application/factory.ts
|
|
1686
|
+
var debug8 = (0, import_debug8.default)("celerity:core:factory");
|
|
1687
|
+
var CelerityFactory = class {
|
|
1688
|
+
static {
|
|
1689
|
+
__name(this, "CelerityFactory");
|
|
1690
|
+
}
|
|
1691
|
+
static async create(rootModule, options) {
|
|
1692
|
+
debug8("create: bootstrapping %s", rootModule.name);
|
|
1693
|
+
const systemLayers = options?.systemLayers ?? await createDefaultSystemLayers();
|
|
1694
|
+
const appLayers = options?.layers ?? [];
|
|
1695
|
+
debug8("create: %d system layers, %d app layers", systemLayers.length, appLayers.length);
|
|
1696
|
+
const { container, registry } = await bootstrap(rootModule);
|
|
1697
|
+
if (options?.adapter) {
|
|
1698
|
+
debug8("create: using adapter \u2192 ServerlessApplication");
|
|
1699
|
+
return new ServerlessApplication(registry, container, options.adapter, systemLayers, appLayers);
|
|
1700
|
+
}
|
|
1701
|
+
debug8("create: \u2192 CelerityApplication");
|
|
1702
|
+
return new CelerityApplication(registry, container, systemLayers, appLayers);
|
|
1703
|
+
}
|
|
1704
|
+
static async createTestingApp(rootModule, options) {
|
|
1705
|
+
debug8("createTestingApp: bootstrapping %s", rootModule.name);
|
|
1706
|
+
const { container, registry } = await bootstrap(rootModule);
|
|
1707
|
+
const systemLayers = options?.systemLayers ?? [];
|
|
1708
|
+
const appLayers = options?.layers ?? [];
|
|
1709
|
+
return new TestingApplication(registry, container, systemLayers, appLayers);
|
|
1710
|
+
}
|
|
1711
|
+
};
|
|
1712
|
+
|
|
1713
|
+
// src/functions/create-handler.ts
|
|
1714
|
+
function createHttpHandler(config, handler) {
|
|
1715
|
+
const metadata = {
|
|
1716
|
+
schema: config.schema,
|
|
1717
|
+
layers: config.layers ?? [],
|
|
1718
|
+
inject: config.inject ?? [],
|
|
1719
|
+
customMetadata: config.metadata ?? {}
|
|
1720
|
+
};
|
|
1721
|
+
if (config.path !== void 0) metadata.path = config.path;
|
|
1722
|
+
if (config.method !== void 0) metadata.method = config.method;
|
|
1723
|
+
return {
|
|
1724
|
+
__celerity_handler: true,
|
|
1725
|
+
type: "http",
|
|
1726
|
+
metadata,
|
|
1727
|
+
handler
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
__name(createHttpHandler, "createHttpHandler");
|
|
1731
|
+
function httpGet(path, handlerOrOptions, maybeHandler) {
|
|
1732
|
+
if (typeof handlerOrOptions === "function") {
|
|
1733
|
+
return createHttpHandler({
|
|
1734
|
+
path,
|
|
1735
|
+
method: "GET"
|
|
1736
|
+
}, handlerOrOptions);
|
|
1737
|
+
}
|
|
1738
|
+
return createHttpHandler({
|
|
1739
|
+
path,
|
|
1740
|
+
method: "GET",
|
|
1741
|
+
...handlerOrOptions
|
|
1742
|
+
}, maybeHandler);
|
|
1743
|
+
}
|
|
1744
|
+
__name(httpGet, "httpGet");
|
|
1745
|
+
function httpPost(path, handlerOrOptions, maybeHandler) {
|
|
1746
|
+
if (typeof handlerOrOptions === "function") {
|
|
1747
|
+
return createHttpHandler({
|
|
1748
|
+
path,
|
|
1749
|
+
method: "POST"
|
|
1750
|
+
}, handlerOrOptions);
|
|
1751
|
+
}
|
|
1752
|
+
return createHttpHandler({
|
|
1753
|
+
path,
|
|
1754
|
+
method: "POST",
|
|
1755
|
+
...handlerOrOptions
|
|
1756
|
+
}, maybeHandler);
|
|
1757
|
+
}
|
|
1758
|
+
__name(httpPost, "httpPost");
|
|
1759
|
+
function httpPut(path, handlerOrOptions, maybeHandler) {
|
|
1760
|
+
if (typeof handlerOrOptions === "function") {
|
|
1761
|
+
return createHttpHandler({
|
|
1762
|
+
path,
|
|
1763
|
+
method: "PUT"
|
|
1764
|
+
}, handlerOrOptions);
|
|
1765
|
+
}
|
|
1766
|
+
return createHttpHandler({
|
|
1767
|
+
path,
|
|
1768
|
+
method: "PUT",
|
|
1769
|
+
...handlerOrOptions
|
|
1770
|
+
}, maybeHandler);
|
|
1771
|
+
}
|
|
1772
|
+
__name(httpPut, "httpPut");
|
|
1773
|
+
function httpPatch(path, handlerOrOptions, maybeHandler) {
|
|
1774
|
+
if (typeof handlerOrOptions === "function") {
|
|
1775
|
+
return createHttpHandler({
|
|
1776
|
+
path,
|
|
1777
|
+
method: "PATCH"
|
|
1778
|
+
}, handlerOrOptions);
|
|
1779
|
+
}
|
|
1780
|
+
return createHttpHandler({
|
|
1781
|
+
path,
|
|
1782
|
+
method: "PATCH",
|
|
1783
|
+
...handlerOrOptions
|
|
1784
|
+
}, maybeHandler);
|
|
1785
|
+
}
|
|
1786
|
+
__name(httpPatch, "httpPatch");
|
|
1787
|
+
function httpDelete(path, handlerOrOptions, maybeHandler) {
|
|
1788
|
+
if (typeof handlerOrOptions === "function") {
|
|
1789
|
+
return createHttpHandler({
|
|
1790
|
+
path,
|
|
1791
|
+
method: "DELETE"
|
|
1792
|
+
}, handlerOrOptions);
|
|
1793
|
+
}
|
|
1794
|
+
return createHttpHandler({
|
|
1795
|
+
path,
|
|
1796
|
+
method: "DELETE",
|
|
1797
|
+
...handlerOrOptions
|
|
1798
|
+
}, maybeHandler);
|
|
1799
|
+
}
|
|
1800
|
+
__name(httpDelete, "httpDelete");
|
|
1801
|
+
|
|
1802
|
+
// src/bootstrap/discovery.ts
|
|
1803
|
+
var import_node_path = require("path");
|
|
1804
|
+
var import_debug9 = __toESM(require("debug"), 1);
|
|
1805
|
+
var debug9 = (0, import_debug9.default)("celerity:core:bootstrap");
|
|
1806
|
+
async function discoverModule(modulePath) {
|
|
1807
|
+
const resolved = modulePath ?? process.env.CELERITY_MODULE_PATH;
|
|
1808
|
+
if (!resolved) {
|
|
1809
|
+
throw new Error("Cannot discover module: set CELERITY_MODULE_PATH environment variable or pass modulePath");
|
|
1810
|
+
}
|
|
1811
|
+
const absolutePath = (0, import_node_path.resolve)(resolved);
|
|
1812
|
+
debug9("discoverModule: importing %s", absolutePath);
|
|
1813
|
+
const imported = await import(absolutePath);
|
|
1814
|
+
const rootModule = imported.default ?? findModuleExport(imported);
|
|
1815
|
+
if (!rootModule || typeof rootModule !== "function") {
|
|
1816
|
+
throw new Error(`No module class found in "${resolved}"`);
|
|
1817
|
+
}
|
|
1818
|
+
debug9("discoverModule: found %s", rootModule.name);
|
|
1819
|
+
return rootModule;
|
|
1820
|
+
}
|
|
1821
|
+
__name(discoverModule, "discoverModule");
|
|
1822
|
+
function findModuleExport(imported) {
|
|
1823
|
+
for (const key of Object.keys(imported)) {
|
|
1824
|
+
if (key === "default") continue;
|
|
1825
|
+
if (typeof imported[key] === "function") {
|
|
1826
|
+
return imported[key];
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
return void 0;
|
|
1830
|
+
}
|
|
1831
|
+
__name(findModuleExport, "findModuleExport");
|
|
1832
|
+
|
|
1833
|
+
// src/bootstrap/runtime-mapper.ts
|
|
1834
|
+
function flattenMultiValueRecord(record) {
|
|
1835
|
+
const result = {};
|
|
1836
|
+
for (const [key, values] of Object.entries(record)) {
|
|
1837
|
+
result[key] = values.length === 1 ? values[0] : values;
|
|
1838
|
+
}
|
|
1839
|
+
return result;
|
|
1840
|
+
}
|
|
1841
|
+
__name(flattenMultiValueRecord, "flattenMultiValueRecord");
|
|
1842
|
+
function mapRuntimeRequest(request) {
|
|
1843
|
+
return {
|
|
1844
|
+
method: request.method.toUpperCase(),
|
|
1845
|
+
path: request.path,
|
|
1846
|
+
pathParams: request.pathParams,
|
|
1847
|
+
query: flattenMultiValueRecord(request.query),
|
|
1848
|
+
headers: flattenMultiValueRecord(request.headers),
|
|
1849
|
+
cookies: request.cookies,
|
|
1850
|
+
textBody: request.textBody,
|
|
1851
|
+
binaryBody: request.binaryBody,
|
|
1852
|
+
contentType: request.contentType || null,
|
|
1853
|
+
requestId: request.requestId,
|
|
1854
|
+
requestTime: request.requestTime,
|
|
1855
|
+
auth: request.auth ?? null,
|
|
1856
|
+
clientIp: request.clientIp || null,
|
|
1857
|
+
traceContext: request.traceContext ?? null,
|
|
1858
|
+
userAgent: request.userAgent || null,
|
|
1859
|
+
matchedRoute: request.matchedRoute
|
|
1860
|
+
};
|
|
1861
|
+
}
|
|
1862
|
+
__name(mapRuntimeRequest, "mapRuntimeRequest");
|
|
1863
|
+
function mapToRuntimeResponse(response) {
|
|
1864
|
+
return {
|
|
1865
|
+
status: response.status,
|
|
1866
|
+
headers: response.headers,
|
|
1867
|
+
body: response.body,
|
|
1868
|
+
binaryBody: response.binaryBody
|
|
1869
|
+
};
|
|
1870
|
+
}
|
|
1871
|
+
__name(mapToRuntimeResponse, "mapToRuntimeResponse");
|
|
1872
|
+
|
|
1873
|
+
// src/bootstrap/runtime-entry.ts
|
|
1874
|
+
async function bootstrapForRuntime(modulePath, systemLayers) {
|
|
1875
|
+
const layers = systemLayers ?? await createDefaultSystemLayers();
|
|
1876
|
+
const rootModule = await discoverModule(modulePath);
|
|
1877
|
+
const { container, registry } = await bootstrap(rootModule);
|
|
1878
|
+
return {
|
|
1879
|
+
registry,
|
|
1880
|
+
container,
|
|
1881
|
+
createRouteCallback(path, method) {
|
|
1882
|
+
const handler = registry.getHandler(path, method);
|
|
1883
|
+
if (!handler) return null;
|
|
1884
|
+
return async (_err, request) => {
|
|
1885
|
+
const httpRequest = mapRuntimeRequest(request);
|
|
1886
|
+
const httpResponse = await executeHandlerPipeline(handler, httpRequest, {
|
|
1887
|
+
container,
|
|
1888
|
+
systemLayers: layers
|
|
1889
|
+
});
|
|
1890
|
+
return mapToRuntimeResponse(httpResponse);
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
};
|
|
1894
|
+
}
|
|
1895
|
+
__name(bootstrapForRuntime, "bootstrapForRuntime");
|
|
1896
|
+
|
|
1897
|
+
// src/bootstrap/runtime-orchestrator.ts
|
|
1898
|
+
async function startRuntime(options) {
|
|
1899
|
+
const pkg = "@celerity-sdk/runtime";
|
|
1900
|
+
const runtimeModule = await import(pkg);
|
|
1901
|
+
const config = runtimeModule.runtimeConfigFromEnv();
|
|
1902
|
+
const app = new runtimeModule.CoreRuntimeApplication(config);
|
|
1903
|
+
const appConfig = app.setup();
|
|
1904
|
+
const result = await bootstrapForRuntime();
|
|
1905
|
+
for (const def of appConfig.api?.http?.handlers ?? []) {
|
|
1906
|
+
const callback = result.createRouteCallback(def.path, def.method);
|
|
1907
|
+
if (callback) {
|
|
1908
|
+
app.registerHttpHandler(def.path, def.method, def.timeout, callback);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
await app.run(options?.block ?? true);
|
|
1912
|
+
}
|
|
1913
|
+
__name(startRuntime, "startRuntime");
|
|
1914
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1915
|
+
0 && (module.exports = {
|
|
1916
|
+
APP_CONFIG,
|
|
1917
|
+
Action,
|
|
1918
|
+
Auth,
|
|
1919
|
+
BadGatewayException,
|
|
1920
|
+
BadRequestException,
|
|
1921
|
+
Body,
|
|
1922
|
+
CONTROLLER_METADATA,
|
|
1923
|
+
CUSTOM_METADATA,
|
|
1924
|
+
CelerityApplication,
|
|
1925
|
+
CelerityFactory,
|
|
1926
|
+
ConflictException,
|
|
1927
|
+
Container,
|
|
1928
|
+
Controller,
|
|
1929
|
+
Cookies,
|
|
1930
|
+
Delete,
|
|
1931
|
+
ForbiddenException,
|
|
1932
|
+
GUARD_CUSTOM_METADATA,
|
|
1933
|
+
GUARD_PROTECTEDBY_METADATA,
|
|
1934
|
+
GatewayTimeoutException,
|
|
1935
|
+
Get,
|
|
1936
|
+
GoneException,
|
|
1937
|
+
Guard,
|
|
1938
|
+
HTTP_METHOD_METADATA,
|
|
1939
|
+
HandlerMetadataStore,
|
|
1940
|
+
HandlerRegistry,
|
|
1941
|
+
Head,
|
|
1942
|
+
Headers,
|
|
1943
|
+
HttpException,
|
|
1944
|
+
INJECT_METADATA,
|
|
1945
|
+
Inject,
|
|
1946
|
+
Injectable,
|
|
1947
|
+
InternalServerErrorException,
|
|
1948
|
+
LAYER_METADATA,
|
|
1949
|
+
MODULE_METADATA,
|
|
1950
|
+
MethodNotAllowedException,
|
|
1951
|
+
Module,
|
|
1952
|
+
NotAcceptableException,
|
|
1953
|
+
NotFoundException,
|
|
1954
|
+
NotImplementedException,
|
|
1955
|
+
Options,
|
|
1956
|
+
PUBLIC_METADATA,
|
|
1957
|
+
Param,
|
|
1958
|
+
Patch,
|
|
1959
|
+
Post,
|
|
1960
|
+
ProtectedBy,
|
|
1961
|
+
Public,
|
|
1962
|
+
Put,
|
|
1963
|
+
Query,
|
|
1964
|
+
ROUTE_PATH_METADATA,
|
|
1965
|
+
RUNTIME_APP,
|
|
1966
|
+
Req,
|
|
1967
|
+
RequestId,
|
|
1968
|
+
ServerlessApplication,
|
|
1969
|
+
ServiceUnavailableException,
|
|
1970
|
+
SetMetadata,
|
|
1971
|
+
TestingApplication,
|
|
1972
|
+
TooManyRequestsException,
|
|
1973
|
+
UnauthorizedException,
|
|
1974
|
+
UnprocessableEntityException,
|
|
1975
|
+
UseLayer,
|
|
1976
|
+
UseLayers,
|
|
1977
|
+
bootstrap,
|
|
1978
|
+
bootstrapForRuntime,
|
|
1979
|
+
buildModuleGraph,
|
|
1980
|
+
createDefaultSystemLayers,
|
|
1981
|
+
createHttpHandler,
|
|
1982
|
+
discoverModule,
|
|
1983
|
+
disposeLayers,
|
|
1984
|
+
executeHandlerPipeline,
|
|
1985
|
+
flattenMultiValueRecord,
|
|
1986
|
+
getClassDependencyTokens,
|
|
1987
|
+
getProviderDependencyTokens,
|
|
1988
|
+
httpDelete,
|
|
1989
|
+
httpGet,
|
|
1990
|
+
httpPatch,
|
|
1991
|
+
httpPost,
|
|
1992
|
+
httpPut,
|
|
1993
|
+
mapRuntimeRequest,
|
|
1994
|
+
mapToRuntimeResponse,
|
|
1995
|
+
mockRequest,
|
|
1996
|
+
registerModuleGraph,
|
|
1997
|
+
runLayerPipeline,
|
|
1998
|
+
startRuntime,
|
|
1999
|
+
tokenToString,
|
|
2000
|
+
validate
|
|
2001
|
+
});
|
|
2002
|
+
//# sourceMappingURL=index.cjs.map
|