UNPKG

4.53 kBTypeScriptView Raw
1/**
2 * Locator type that most often used in PipServices toolkit.
3 * It locates components using several fields:
4 * - Group: a package or just named group of components like "pip-services"
5 * - Type: logical component type that defines it's contract like "persistence"
6 * - Kind: physical implementation type like "mongodb"
7 * - Name: unique component name like "default"
8 * - Version: version of the component contract like "1.0"
9 *
10 * The locator matching can be done by all or only few selected fields.
11 * The fields that shall be excluded from the matching must be set to <code>"*"</code> or <code>null</code>.
12 * That approach allows to implement many interesting scenarios. For instance:
13 * - Locate all loggers (match by type and version)
14 * - Locate persistence components for a microservice (match by group and type)
15 * - Locate specific component by its name (match by name)
16 *
17 * ### Example ###
18 *
19 * let locator1 = new Descriptor("mygroup", "connector", "aws", "default", "1.0");
20 * let locator2 = Descriptor.fromString("mygroup:connector:*:*:1.0");
21 *
22 * locator1.match(locator2); // Result: true
23 * locator1.equal(locator2); // Result: true
24 * locator1.exactMatch(locator2); // Result: false
25 */
26export declare class Descriptor {
27 private _group;
28 private _type;
29 private _kind;
30 private _name;
31 private _version;
32 /**
33 * Creates a new instance of the descriptor.
34 *
35 * @param group a logical component group
36 * @param type a logical component type or contract
37 * @param kind a component implementation type
38 * @param name a unique component name
39 * @param version a component implementation version
40 */
41 constructor(group: string, type: string, kind: string, name: string, version: string);
42 /**
43 * Gets the component's logical group.
44 *
45 * @returns the component's logical group
46 */
47 getGroup(): string;
48 /**
49 * Gets the component's logical type.
50 *
51 * @returns the component's logical type.
52 */
53 getType(): string;
54 /**
55 * Gets the component's implementation type.
56 *
57 * @returns the component's implementation type.
58 */
59 getKind(): string;
60 /**
61 * Gets the unique component's name.
62 *
63 * @returns the unique component's name.
64 */
65 getName(): string;
66 /**
67 * Gets the component's implementation version.
68 *
69 * @returns the component's implementation version.
70 */
71 getVersion(): string;
72 private matchField;
73 /**
74 * Partially matches this descriptor to another descriptor.
75 * Fields that contain "*" or null are excluded from the match.
76 *
77 * @param descriptor the descriptor to match this one against.
78 * @returns true if descriptors match and false otherwise
79 *
80 * @see [[exactMatch]]
81 */
82 match(descriptor: Descriptor): boolean;
83 private exactMatchField;
84 /**
85 * Matches this descriptor to another descriptor by all fields.
86 * No exceptions are made.
87 *
88 * @param descriptor the descriptor to match this one against.
89 * @returns true if descriptors match and false otherwise.
90 *
91 * @see [[match]]
92 */
93 exactMatch(descriptor: Descriptor): boolean;
94 /**
95 * Checks whether all descriptor fields are set.
96 * If descriptor has at least one "*" or null field it is considered "incomplete",
97 *
98 * @returns true if all descriptor fields are defined and false otherwise.
99 */
100 isComplete(): boolean;
101 /**
102 * Compares this descriptor to a value.
103 * If value is a Descriptor it tries to match them,
104 * otherwise the method returns false.
105 *
106 * @param value the value to match against this descriptor.
107 * @returns true if the value is matching descriptor and false otherwise.
108 *
109 * @see [[match]]
110 */
111 equals(value: any): boolean;
112 /**
113 * Gets a string representation of the object.
114 * The result is a colon-separated list of descriptor fields as
115 * "mygroup:connector:aws:default:1.0"
116 *
117 * @returns a string representation of the object.
118 */
119 toString(): string;
120 /**
121 * Parses colon-separated list of descriptor fields and returns them as a Descriptor.
122 *
123 * @param value colon-separated descriptor fields to initialize Descriptor.
124 * @returns a newly created Descriptor.
125 * @throws a [[ConfigException]] if the descriptor string is of a wrong format.
126 */
127 static fromString(value: String): Descriptor;
128}