UNPKG

3.61 kBJavaScriptView Raw
1"use strict";
2var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5}) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
7 o[k2] = m[k];
8}));
9var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
11}) : function(o, v) {
12 o["default"] = v;
13});
14var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
16 var result = {};
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
19 return result;
20};
21Object.defineProperty(exports, "__esModule", { value: true });
22exports.Target = void 0;
23const METADATA_KEY = __importStar(require("../constants/metadata_keys"));
24const id_1 = require("../utils/id");
25const serialization_1 = require("../utils/serialization");
26const metadata_1 = require("./metadata");
27const queryable_string_1 = require("./queryable_string");
28class Target {
29 constructor(type, identifier, serviceIdentifier, namedOrTagged) {
30 this.id = (0, id_1.id)();
31 this.type = type;
32 this.serviceIdentifier = serviceIdentifier;
33 const queryableName = typeof identifier === 'symbol' ? (0, serialization_1.getSymbolDescription)(identifier) : identifier;
34 this.name = new queryable_string_1.QueryableString(queryableName || "");
35 this.identifier = identifier;
36 this.metadata = new Array();
37 let metadataItem = null;
38 if (typeof namedOrTagged === 'string') {
39 metadataItem = new metadata_1.Metadata(METADATA_KEY.NAMED_TAG, namedOrTagged);
40 }
41 else if (namedOrTagged instanceof metadata_1.Metadata) {
42 metadataItem = namedOrTagged;
43 }
44 if (metadataItem !== null) {
45 this.metadata.push(metadataItem);
46 }
47 }
48 hasTag(key) {
49 for (const m of this.metadata) {
50 if (m.key === key) {
51 return true;
52 }
53 }
54 return false;
55 }
56 isArray() {
57 return this.hasTag(METADATA_KEY.MULTI_INJECT_TAG);
58 }
59 matchesArray(name) {
60 return this.matchesTag(METADATA_KEY.MULTI_INJECT_TAG)(name);
61 }
62 isNamed() {
63 return this.hasTag(METADATA_KEY.NAMED_TAG);
64 }
65 isTagged() {
66 return this.metadata.some((metadata) => METADATA_KEY.NON_CUSTOM_TAG_KEYS.every((key) => metadata.key !== key));
67 }
68 isOptional() {
69 return this.matchesTag(METADATA_KEY.OPTIONAL_TAG)(true);
70 }
71 getNamedTag() {
72 if (this.isNamed()) {
73 return this.metadata.filter((m) => m.key === METADATA_KEY.NAMED_TAG)[0];
74 }
75 return null;
76 }
77 getCustomTags() {
78 if (this.isTagged()) {
79 return this.metadata.filter((metadata) => METADATA_KEY.NON_CUSTOM_TAG_KEYS.every((key) => metadata.key !== key));
80 }
81 else {
82 return null;
83 }
84 }
85 matchesNamedTag(name) {
86 return this.matchesTag(METADATA_KEY.NAMED_TAG)(name);
87 }
88 matchesTag(key) {
89 return (value) => {
90 for (const m of this.metadata) {
91 if (m.key === key && m.value === value) {
92 return true;
93 }
94 }
95 return false;
96 };
97 }
98}
99exports.Target = Target;
100//# sourceMappingURL=target.js.map
\No newline at end of file