dino-express
Version:
DinO enabled REST framework based on express
49 lines • 1.95 kB
JavaScript
;
// Copyright 2025 Quirino Brizi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.decoratorMetadataRegistry = void 0;
class DecoratorMetadataRegistry {
paths = new Map();
addPath(handler, path) {
const pathMetadata = this.paths.get(handler);
if (pathMetadata === undefined) {
this.paths.set(handler, { name: path, handler, operations: [] });
}
else {
pathMetadata.name = path;
}
}
addOperation(handler, operation, fcn) {
const pathMetadata = this.paths.get(handler);
if (pathMetadata !== undefined) {
pathMetadata.operations.push({ operation, fcn });
}
else {
this.paths.set(handler, { name: '', handler, operations: [{ operation, fcn }] });
}
}
getDefinedPaths() {
return Array.from(this.paths.keys());
}
getDefinedPathMetadata(path) {
return Array.from(this.paths.values()).find((pathMetadata) => pathMetadata.name === path);
}
getDefinedOperationMetadata(path, operations) {
const pathMetadata = this.getDefinedPathMetadata(path);
return pathMetadata?.operations.find((operation) => operations.includes(operation.operation));
}
}
exports.decoratorMetadataRegistry = new DecoratorMetadataRegistry();
//# sourceMappingURL=DecoratorMetadataRegistry.js.map