@loopback/context 4.0.0-alpha.9 → 4.0.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.
Files changed (165) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +116 -0
  3. package/dist/binding-config.d.ts +40 -0
  4. package/dist/binding-config.js +33 -0
  5. package/dist/binding-config.js.map +1 -0
  6. package/dist/binding-decorator.d.ts +45 -0
  7. package/dist/binding-decorator.js +118 -0
  8. package/dist/binding-decorator.js.map +1 -0
  9. package/dist/binding-filter.d.ts +108 -0
  10. package/dist/binding-filter.js +162 -0
  11. package/dist/binding-filter.js.map +1 -0
  12. package/dist/binding-inspector.d.ts +150 -0
  13. package/dist/binding-inspector.js +249 -0
  14. package/dist/binding-inspector.js.map +1 -0
  15. package/dist/binding-key.d.ts +66 -0
  16. package/dist/binding-key.js +121 -0
  17. package/dist/binding-key.js.map +1 -0
  18. package/dist/binding-sorter.d.ts +71 -0
  19. package/dist/binding-sorter.js +89 -0
  20. package/dist/binding-sorter.js.map +1 -0
  21. package/dist/binding.d.ts +577 -0
  22. package/dist/binding.js +788 -0
  23. package/dist/binding.js.map +1 -0
  24. package/dist/context-event.d.ts +23 -0
  25. package/dist/context-event.js +7 -0
  26. package/dist/context-event.js.map +1 -0
  27. package/dist/context-observer.d.ts +36 -0
  28. package/dist/context-observer.js +7 -0
  29. package/dist/context-observer.js.map +1 -0
  30. package/dist/context-subscription.d.ts +147 -0
  31. package/dist/context-subscription.js +317 -0
  32. package/dist/context-subscription.js.map +1 -0
  33. package/dist/context-tag-indexer.d.ts +42 -0
  34. package/dist/context-tag-indexer.js +135 -0
  35. package/dist/context-tag-indexer.js.map +1 -0
  36. package/dist/context-view.d.ts +209 -0
  37. package/dist/context-view.js +240 -0
  38. package/dist/context-view.js.map +1 -0
  39. package/dist/context.d.ts +513 -0
  40. package/dist/context.js +717 -0
  41. package/dist/context.js.map +1 -0
  42. package/dist/index.d.ts +52 -0
  43. package/dist/index.js +60 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/inject-config.d.ts +67 -0
  46. package/dist/inject-config.js +181 -0
  47. package/dist/inject-config.js.map +1 -0
  48. package/dist/inject.d.ts +250 -0
  49. package/dist/inject.js +535 -0
  50. package/dist/inject.js.map +1 -0
  51. package/dist/interception-proxy.d.ts +76 -0
  52. package/dist/interception-proxy.js +67 -0
  53. package/dist/interception-proxy.js.map +1 -0
  54. package/dist/interceptor-chain.d.ts +121 -0
  55. package/dist/interceptor-chain.js +148 -0
  56. package/dist/interceptor-chain.js.map +1 -0
  57. package/dist/interceptor.d.ts +138 -0
  58. package/dist/interceptor.js +299 -0
  59. package/dist/interceptor.js.map +1 -0
  60. package/dist/invocation.d.ts +101 -0
  61. package/dist/invocation.js +163 -0
  62. package/dist/invocation.js.map +1 -0
  63. package/dist/json-types.d.ts +28 -0
  64. package/{lib/src/provider.js → dist/json-types.js} +3 -3
  65. package/dist/json-types.js.map +1 -0
  66. package/dist/keys.d.ts +65 -0
  67. package/dist/keys.js +74 -0
  68. package/dist/keys.js.map +1 -0
  69. package/dist/provider.d.ts +31 -0
  70. package/{lib6/src → dist}/provider.js +2 -2
  71. package/dist/provider.js.map +1 -0
  72. package/dist/resolution-session.d.ts +180 -0
  73. package/dist/resolution-session.js +274 -0
  74. package/dist/resolution-session.js.map +1 -0
  75. package/dist/resolver.d.ts +46 -0
  76. package/dist/resolver.js +203 -0
  77. package/dist/resolver.js.map +1 -0
  78. package/dist/unique-id.d.ts +14 -0
  79. package/dist/unique-id.js +26 -0
  80. package/dist/unique-id.js.map +1 -0
  81. package/dist/value-promise.d.ts +134 -0
  82. package/dist/value-promise.js +277 -0
  83. package/dist/value-promise.js.map +1 -0
  84. package/package.json +49 -34
  85. package/src/binding-config.ts +73 -0
  86. package/src/binding-decorator.ts +136 -0
  87. package/src/binding-filter.ts +250 -0
  88. package/src/binding-inspector.ts +371 -0
  89. package/src/binding-key.ts +136 -0
  90. package/src/binding-sorter.ts +124 -0
  91. package/src/binding.ts +1107 -0
  92. package/src/context-event.ts +30 -0
  93. package/src/context-observer.ts +50 -0
  94. package/src/context-subscription.ts +402 -0
  95. package/src/context-tag-indexer.ts +147 -0
  96. package/src/context-view.ts +440 -0
  97. package/src/context.ts +1079 -0
  98. package/src/index.ts +58 -0
  99. package/src/inject-config.ts +239 -0
  100. package/src/inject.ts +796 -0
  101. package/src/interception-proxy.ts +127 -0
  102. package/src/interceptor-chain.ts +268 -0
  103. package/src/interceptor.ts +430 -0
  104. package/src/invocation.ts +269 -0
  105. package/src/json-types.ts +35 -0
  106. package/src/keys.ts +85 -0
  107. package/src/provider.ts +37 -0
  108. package/src/resolution-session.ts +414 -0
  109. package/src/resolver.ts +282 -0
  110. package/src/unique-id.ts +24 -0
  111. package/src/value-promise.ts +318 -0
  112. package/index.d.ts +0 -6
  113. package/index.js +0 -9
  114. package/lib/index.d.ts +0 -1
  115. package/lib/index.js +0 -12
  116. package/lib/index.js.map +0 -1
  117. package/lib/src/binding.d.ts +0 -98
  118. package/lib/src/binding.js +0 -169
  119. package/lib/src/binding.js.map +0 -1
  120. package/lib/src/context.d.ts +0 -14
  121. package/lib/src/context.js +0 -122
  122. package/lib/src/context.js.map +0 -1
  123. package/lib/src/index.d.ts +0 -10
  124. package/lib/src/index.js +0 -25
  125. package/lib/src/index.js.map +0 -1
  126. package/lib/src/inject.d.ts +0 -60
  127. package/lib/src/inject.js +0 -112
  128. package/lib/src/inject.js.map +0 -1
  129. package/lib/src/is-promise.d.ts +0 -1
  130. package/lib/src/is-promise.js +0 -15
  131. package/lib/src/is-promise.js.map +0 -1
  132. package/lib/src/provider.d.ts +0 -31
  133. package/lib/src/provider.js.map +0 -1
  134. package/lib/src/reflect.d.ts +0 -38
  135. package/lib/src/reflect.js +0 -143
  136. package/lib/src/reflect.js.map +0 -1
  137. package/lib/src/resolver.d.ts +0 -30
  138. package/lib/src/resolver.js +0 -141
  139. package/lib/src/resolver.js.map +0 -1
  140. package/lib6/index.d.ts +0 -1
  141. package/lib6/index.js +0 -12
  142. package/lib6/index.js.map +0 -1
  143. package/lib6/src/binding.d.ts +0 -98
  144. package/lib6/src/binding.js +0 -169
  145. package/lib6/src/binding.js.map +0 -1
  146. package/lib6/src/context.d.ts +0 -14
  147. package/lib6/src/context.js +0 -122
  148. package/lib6/src/context.js.map +0 -1
  149. package/lib6/src/index.d.ts +0 -10
  150. package/lib6/src/index.js +0 -25
  151. package/lib6/src/index.js.map +0 -1
  152. package/lib6/src/inject.d.ts +0 -60
  153. package/lib6/src/inject.js +0 -112
  154. package/lib6/src/inject.js.map +0 -1
  155. package/lib6/src/is-promise.d.ts +0 -1
  156. package/lib6/src/is-promise.js +0 -15
  157. package/lib6/src/is-promise.js.map +0 -1
  158. package/lib6/src/provider.d.ts +0 -31
  159. package/lib6/src/provider.js.map +0 -1
  160. package/lib6/src/reflect.d.ts +0 -38
  161. package/lib6/src/reflect.js +0 -143
  162. package/lib6/src/reflect.js.map +0 -1
  163. package/lib6/src/resolver.d.ts +0 -30
  164. package/lib6/src/resolver.js +0 -141
  165. package/lib6/src/resolver.js.map +0 -1
@@ -0,0 +1,46 @@
1
+ import { Context } from './context';
2
+ import { ResolutionSession } from './resolution-session';
3
+ import { BoundValue, Constructor, MapObject, ValueOrPromise } from './value-promise';
4
+ /**
5
+ * Create an instance of a class which constructor has arguments
6
+ * decorated with `@inject`.
7
+ *
8
+ * The function returns a class when all dependencies were
9
+ * resolved synchronously, or a Promise otherwise.
10
+ *
11
+ * @param ctor - The class constructor to call.
12
+ * @param ctx - The context containing values for `@inject` resolution
13
+ * @param session - Optional session for binding and dependency resolution
14
+ * @param nonInjectedArgs - Optional array of args for non-injected parameters
15
+ */
16
+ export declare function instantiateClass<T>(ctor: Constructor<T>, ctx: Context, session?: ResolutionSession, nonInjectedArgs?: any[]): ValueOrPromise<T>;
17
+ /**
18
+ * Given a function with arguments decorated with `@inject`,
19
+ * return the list of arguments resolved using the values
20
+ * bound in `ctx`.
21
+
22
+ * The function returns an argument array when all dependencies were
23
+ * resolved synchronously, or a Promise otherwise.
24
+ *
25
+ * @param target - The class for constructor injection or prototype for method
26
+ * injection
27
+ * @param method - The method name. If set to '', the constructor will
28
+ * be used.
29
+ * @param ctx - The context containing values for `@inject` resolution
30
+ * @param session - Optional session for binding and dependency resolution
31
+ * @param nonInjectedArgs - Optional array of args for non-injected parameters
32
+ */
33
+ export declare function resolveInjectedArguments(target: object, method: string, ctx: Context, session?: ResolutionSession, nonInjectedArgs?: any[]): ValueOrPromise<BoundValue[]>;
34
+ /**
35
+ * Given a class with properties decorated with `@inject`,
36
+ * return the map of properties resolved using the values
37
+ * bound in `ctx`.
38
+
39
+ * The function returns an argument array when all dependencies were
40
+ * resolved synchronously, or a Promise otherwise.
41
+ *
42
+ * @param constructor - The class for which properties should be resolved.
43
+ * @param ctx - The context containing values for `@inject` resolution
44
+ * @param session - Optional session for binding and dependency resolution
45
+ */
46
+ export declare function resolveInjectedProperties(constructor: Function, ctx: Context, session?: ResolutionSession): ValueOrPromise<MapObject<BoundValue>>;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2017,2019. All Rights Reserved.
3
+ // Node module: @loopback/context
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.resolveInjectedProperties = exports.resolveInjectedArguments = exports.instantiateClass = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const metadata_1 = require("@loopback/metadata");
10
+ const assert_1 = (0, tslib_1.__importDefault)(require("assert"));
11
+ const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
12
+ const binding_filter_1 = require("./binding-filter");
13
+ const inject_1 = require("./inject");
14
+ const resolution_session_1 = require("./resolution-session");
15
+ const value_promise_1 = require("./value-promise");
16
+ const debug = (0, debug_1.default)('loopback:context:resolver');
17
+ const getTargetName = metadata_1.DecoratorFactory.getTargetName;
18
+ /**
19
+ * Create an instance of a class which constructor has arguments
20
+ * decorated with `@inject`.
21
+ *
22
+ * The function returns a class when all dependencies were
23
+ * resolved synchronously, or a Promise otherwise.
24
+ *
25
+ * @param ctor - The class constructor to call.
26
+ * @param ctx - The context containing values for `@inject` resolution
27
+ * @param session - Optional session for binding and dependency resolution
28
+ * @param nonInjectedArgs - Optional array of args for non-injected parameters
29
+ */
30
+ function instantiateClass(ctor, ctx, session,
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
+ nonInjectedArgs) {
33
+ /* istanbul ignore if */
34
+ if (debug.enabled) {
35
+ debug('Instantiating %s', getTargetName(ctor));
36
+ if (nonInjectedArgs === null || nonInjectedArgs === void 0 ? void 0 : nonInjectedArgs.length) {
37
+ debug('Non-injected arguments:', nonInjectedArgs);
38
+ }
39
+ }
40
+ const argsOrPromise = resolveInjectedArguments(ctor, '', ctx, session, nonInjectedArgs);
41
+ const propertiesOrPromise = resolveInjectedProperties(ctor, ctx, session);
42
+ const inst = (0, value_promise_1.transformValueOrPromise)(argsOrPromise, args => {
43
+ /* istanbul ignore if */
44
+ if (debug.enabled) {
45
+ debug('Injected arguments for %s():', ctor.name, args);
46
+ }
47
+ return new ctor(...args);
48
+ });
49
+ return (0, value_promise_1.transformValueOrPromise)(propertiesOrPromise, props => {
50
+ /* istanbul ignore if */
51
+ if (debug.enabled) {
52
+ debug('Injected properties for %s:', ctor.name, props);
53
+ }
54
+ return (0, value_promise_1.transformValueOrPromise)(inst, obj => Object.assign(obj, props));
55
+ });
56
+ }
57
+ exports.instantiateClass = instantiateClass;
58
+ /**
59
+ * If the scope of current binding is `SINGLETON`, reset the context
60
+ * to be the one that owns the current binding to make sure a singleton
61
+ * does not have dependencies injected from child contexts unless the
62
+ * injection is for method (excluding constructor) parameters.
63
+ */
64
+ function resolveContext(ctx, injection, session) {
65
+ const currentBinding = session === null || session === void 0 ? void 0 : session.currentBinding;
66
+ if (currentBinding == null) {
67
+ // No current binding
68
+ return ctx;
69
+ }
70
+ const isConstructorOrPropertyInjection =
71
+ // constructor injection
72
+ !injection.member ||
73
+ // property injection
74
+ typeof injection.methodDescriptorOrParameterIndex !== 'number';
75
+ if (isConstructorOrPropertyInjection) {
76
+ // Set context to the resolution context of the current binding for
77
+ // constructor or property injections against a singleton
78
+ ctx = ctx.getResolutionContext(currentBinding);
79
+ }
80
+ return ctx;
81
+ }
82
+ /**
83
+ * Resolve the value or promise for a given injection
84
+ * @param ctx - Context
85
+ * @param injection - Descriptor of the injection
86
+ * @param session - Optional session for binding and dependency resolution
87
+ */
88
+ function resolve(ctx, injection, session) {
89
+ /* istanbul ignore if */
90
+ if (debug.enabled) {
91
+ debug('Resolving an injection:', resolution_session_1.ResolutionSession.describeInjection(injection));
92
+ }
93
+ ctx = resolveContext(ctx, injection, session);
94
+ const resolved = resolution_session_1.ResolutionSession.runWithInjection(s => {
95
+ if (injection.resolve) {
96
+ // A custom resolve function is provided
97
+ return injection.resolve(ctx, injection, s);
98
+ }
99
+ else {
100
+ // Default to resolve the value from the context by binding key
101
+ (0, assert_1.default)((0, binding_filter_1.isBindingAddress)(injection.bindingSelector), 'The binding selector must be an address (string or BindingKey)');
102
+ const key = injection.bindingSelector;
103
+ const options = {
104
+ session: s,
105
+ ...injection.metadata,
106
+ };
107
+ return ctx.getValueOrPromise(key, options);
108
+ }
109
+ }, injection, session);
110
+ return resolved;
111
+ }
112
+ /**
113
+ * Given a function with arguments decorated with `@inject`,
114
+ * return the list of arguments resolved using the values
115
+ * bound in `ctx`.
116
+
117
+ * The function returns an argument array when all dependencies were
118
+ * resolved synchronously, or a Promise otherwise.
119
+ *
120
+ * @param target - The class for constructor injection or prototype for method
121
+ * injection
122
+ * @param method - The method name. If set to '', the constructor will
123
+ * be used.
124
+ * @param ctx - The context containing values for `@inject` resolution
125
+ * @param session - Optional session for binding and dependency resolution
126
+ * @param nonInjectedArgs - Optional array of args for non-injected parameters
127
+ */
128
+ function resolveInjectedArguments(target, method, ctx, session,
129
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
+ nonInjectedArgs) {
131
+ /* istanbul ignore if */
132
+ if (debug.enabled) {
133
+ debug('Resolving injected arguments for %s', getTargetName(target, method));
134
+ }
135
+ const targetWithMethods = target;
136
+ if (method) {
137
+ (0, assert_1.default)(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
138
+ }
139
+ // NOTE: the array may be sparse, i.e.
140
+ // Object.keys(injectedArgs).length !== injectedArgs.length
141
+ // Example value:
142
+ // [ , 'key1', , 'key2']
143
+ const injectedArgs = (0, inject_1.describeInjectedArguments)(target, method);
144
+ const extraArgs = nonInjectedArgs !== null && nonInjectedArgs !== void 0 ? nonInjectedArgs : [];
145
+ let argLength = metadata_1.DecoratorFactory.getNumberOfParameters(target, method);
146
+ // Please note `injectedArgs` contains `undefined` for non-injected args
147
+ const numberOfInjected = injectedArgs.filter(i => i != null).length;
148
+ if (argLength < numberOfInjected + extraArgs.length) {
149
+ /**
150
+ * `Function.prototype.length` excludes the rest parameter and only includes
151
+ * parameters before the first one with a default value. For example,
152
+ * `hello(@inject('name') name: string = 'John')` gives 0 for argLength
153
+ */
154
+ argLength = numberOfInjected + extraArgs.length;
155
+ }
156
+ let nonInjectedIndex = 0;
157
+ return (0, value_promise_1.resolveList)(new Array(argLength), (val, ix) => {
158
+ // The `val` argument is not used as the resolver only uses `injectedArgs`
159
+ // and `extraArgs` to return the new value
160
+ const injection = ix < injectedArgs.length ? injectedArgs[ix] : undefined;
161
+ if (injection == null ||
162
+ (!injection.bindingSelector && !injection.resolve)) {
163
+ if (nonInjectedIndex < extraArgs.length) {
164
+ // Set the argument from the non-injected list
165
+ return extraArgs[nonInjectedIndex++];
166
+ }
167
+ else {
168
+ const name = getTargetName(target, method, ix);
169
+ throw new resolution_session_1.ResolutionError(`The argument '${name}' is not decorated for dependency injection ` +
170
+ 'but no value was supplied by the caller. Did you forget to apply ' +
171
+ '@inject() to the argument?', { context: ctx, options: { session } });
172
+ }
173
+ }
174
+ return resolve(ctx, injection,
175
+ // Clone the session so that multiple arguments can be resolved in parallel
176
+ resolution_session_1.ResolutionSession.fork(session));
177
+ });
178
+ }
179
+ exports.resolveInjectedArguments = resolveInjectedArguments;
180
+ /**
181
+ * Given a class with properties decorated with `@inject`,
182
+ * return the map of properties resolved using the values
183
+ * bound in `ctx`.
184
+
185
+ * The function returns an argument array when all dependencies were
186
+ * resolved synchronously, or a Promise otherwise.
187
+ *
188
+ * @param constructor - The class for which properties should be resolved.
189
+ * @param ctx - The context containing values for `@inject` resolution
190
+ * @param session - Optional session for binding and dependency resolution
191
+ */
192
+ function resolveInjectedProperties(constructor, ctx, session) {
193
+ /* istanbul ignore if */
194
+ if (debug.enabled) {
195
+ debug('Resolving injected properties for %s', getTargetName(constructor));
196
+ }
197
+ const injectedProperties = (0, inject_1.describeInjectedProperties)(constructor.prototype);
198
+ return (0, value_promise_1.resolveMap)(injectedProperties, injection => resolve(ctx, injection,
199
+ // Clone the session so that multiple properties can be resolved in parallel
200
+ resolution_session_1.ResolutionSession.fork(session)));
201
+ }
202
+ exports.resolveInjectedProperties = resolveInjectedProperties;
203
+ //# sourceMappingURL=resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,iDAAoD;AACpD,iEAA4B;AAC5B,+DAAgC;AAChC,qDAAkD;AAGlD,qCAIkB;AAClB,6DAI8B;AAC9B,mDAQyB;AAEzB,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,2BAA2B,CAAC,CAAC;AACvD,MAAM,aAAa,GAAG,2BAAgB,CAAC,aAAa,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAC9B,IAAoB,EACpB,GAAY,EACZ,OAA2B;AAC3B,8DAA8D;AAC9D,eAAuB;IAEvB,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAA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from 'hyperid';
2
+ /**
3
+ * Generate a (globally) unique identifier in a very fast way.
4
+ * Please note the ids ARE NOT formatted as UUID and have variable length.
5
+ * The format of generated values may change in the future.
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const generateUniqueId: hyperid.Instance;
10
+ /**
11
+ * A regular expression for testing values generated by generateUniqueId.
12
+ * @internal
13
+ */
14
+ export declare const UNIQUE_ID_PATTERN: RegExp;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. 2018,2020. All Rights Reserved.
3
+ // Node module: @loopback/context
4
+ // This file is licensed under the MIT License.
5
+ // License text available at https://opensource.org/licenses/MIT
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.UNIQUE_ID_PATTERN = exports.generateUniqueId = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const hyperid_1 = (0, tslib_1.__importDefault)(require("hyperid"));
10
+ /**
11
+ * Generate a (globally) unique identifier in a very fast way.
12
+ * Please note the ids ARE NOT formatted as UUID and have variable length.
13
+ * The format of generated values may change in the future.
14
+ *
15
+ * @internal
16
+ */
17
+ exports.generateUniqueId = (0, hyperid_1.default)({
18
+ fixedLength: false,
19
+ urlSafe: true,
20
+ });
21
+ /**
22
+ * A regular expression for testing values generated by generateUniqueId.
23
+ * @internal
24
+ */
25
+ exports.UNIQUE_ID_PATTERN = /[A-Za-z0-9-_]+-\d+/;
26
+ //# sourceMappingURL=unique-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-id.js","sourceRoot":"","sources":["../src/unique-id.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,mEAA8B;AAE9B;;;;;;GAMG;AACU,QAAA,gBAAgB,GAAG,IAAA,iBAAO,EAAC;IACtC,WAAW,EAAE,KAAK;IAClB,OAAO,EAAE,IAAI;CACd,CAAC,CAAC;AAEH;;;GAGG;AACU,QAAA,iBAAiB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,134 @@
1
+ /**
2
+ * A class constructor accepting arbitrary arguments.
3
+ */
4
+ export declare type Constructor<T> = new (...args: any[]) => T;
5
+ export declare type BoundValue = any;
6
+ /**
7
+ * Representing a value or promise. This type is used to represent results of
8
+ * synchronous/asynchronous resolution of values.
9
+ *
10
+ * Note that we are using PromiseLike instead of native Promise to describe
11
+ * the asynchronous variant. This allows producers of async values to use
12
+ * any Promise implementation (e.g. Bluebird) instead of native Promises
13
+ * provided by JavaScript runtime.
14
+ */
15
+ export declare type ValueOrPromise<T> = T | PromiseLike<T>;
16
+ export declare type MapObject<T> = Record<string, T>;
17
+ /**
18
+ * Check whether a value is a Promise-like instance.
19
+ * Recognizes both native promises and third-party promise libraries.
20
+ *
21
+ * @param value - The value to check.
22
+ */
23
+ export declare function isPromiseLike<T>(value: T | PromiseLike<T> | undefined): value is PromiseLike<T>;
24
+ /**
25
+ * Get nested properties of an object by path
26
+ * @param value - Value of the source object
27
+ * @param path - Path to the property
28
+ */
29
+ export declare function getDeepProperty<OUT = BoundValue, IN = BoundValue>(value: IN, path: string): OUT | undefined;
30
+ /**
31
+ * Resolve entries of an object into a new object with the same keys. If one or
32
+ * more entries of the source object are resolved to a promise by the `resolver`
33
+ * function, this method returns a promise which will be resolved to the new
34
+ * object with fully resolved entries.
35
+ *
36
+ * @example
37
+ *
38
+ * - Example 1: resolve all entries synchronously
39
+ * ```ts
40
+ * const result = resolveMap({a: 'x', b: 'y'}, v => v.toUpperCase());
41
+ * ```
42
+ * The `result` will be `{a: 'X', b: 'Y'}`.
43
+ *
44
+ * - Example 2: resolve one or more entries asynchronously
45
+ * ```ts
46
+ * const result = resolveMap({a: 'x', b: 'y'}, v =>
47
+ * Promise.resolve(v.toUpperCase()),
48
+ * );
49
+ * ```
50
+ * The `result` will be a promise of `{a: 'X', b: 'Y'}`.
51
+ *
52
+ * @param map - The original object containing the source entries
53
+ * @param resolver - A function resolves an entry to a value or promise. It will
54
+ * be invoked with the property value, the property name, and the source object.
55
+ */
56
+ export declare function resolveMap<T, V>(map: MapObject<T>, resolver: (val: T, key: string, values: MapObject<T>) => ValueOrPromise<V>): ValueOrPromise<MapObject<V>>;
57
+ /**
58
+ * Resolve entries of an array into a new array with the same indexes. If one or
59
+ * more entries of the source array are resolved to a promise by the `resolver`
60
+ * function, this method returns a promise which will be resolved to the new
61
+ * array with fully resolved entries.
62
+ *
63
+ * @example
64
+ *
65
+ * - Example 1: resolve all entries synchronously
66
+ * ```ts
67
+ * const result = resolveList(['a', 'b'], v => v.toUpperCase());
68
+ * ```
69
+ * The `result` will be `['A', 'B']`.
70
+ *
71
+ * - Example 2: resolve one or more entries asynchronously
72
+ * ```ts
73
+ * const result = resolveList(['a', 'b'], v =>
74
+ * Promise.resolve(v.toUpperCase()),
75
+ * );
76
+ * ```
77
+ * The `result` will be a promise of `['A', 'B']`.
78
+ *
79
+ * @param list - The original array containing the source entries
80
+ * @param resolver - A function resolves an entry to a value or promise. It will
81
+ * be invoked with the property value, the property index, and the source array.
82
+ */
83
+ export declare function resolveList<T, V>(list: T[], resolver: (val: T, index: number, values: T[]) => ValueOrPromise<V>): ValueOrPromise<V[]>;
84
+ /**
85
+ * Try to run an action that returns a promise or a value
86
+ * @param action - A function that returns a promise or a value
87
+ * @param finalAction - A function to be called once the action
88
+ * is fulfilled or rejected (synchronously or asynchronously)
89
+ *
90
+ * @typeParam T - Type for the return value
91
+ */
92
+ export declare function tryWithFinally<T>(action: () => ValueOrPromise<T>, finalAction: () => void): ValueOrPromise<T>;
93
+ /**
94
+ * Try to run an action that returns a promise or a value with error and final
95
+ * actions to mimic `try {} catch(err) {} finally {}` for a value or promise.
96
+ *
97
+ * @param action - A function that returns a promise or a value
98
+ * @param errorAction - A function to be called once the action
99
+ * is rejected (synchronously or asynchronously). It must either return a new
100
+ * value or throw an error.
101
+ * @param finalAction - A function to be called once the action
102
+ * is fulfilled or rejected (synchronously or asynchronously)
103
+ *
104
+ * @typeParam T - Type for the return value
105
+ */
106
+ export declare function tryCatchFinally<T>(action: () => ValueOrPromise<T>, errorAction?: (err: unknown) => T | never, finalAction?: () => void): ValueOrPromise<T>;
107
+ /**
108
+ * Resolve an iterator of source values into a result until the evaluator
109
+ * returns `true`
110
+ * @param source - The iterator of source values
111
+ * @param resolver - The resolve function that maps the source value to a result
112
+ * @param evaluator - The evaluate function that decides when to stop
113
+ */
114
+ export declare function resolveUntil<T, V>(source: Iterator<T>, resolver: (sourceVal: T) => ValueOrPromise<V | undefined>, evaluator: (sourceVal: T, targetVal: V | undefined) => boolean): ValueOrPromise<V | undefined>;
115
+ /**
116
+ * Transform a value or promise with a function that produces a new value or
117
+ * promise
118
+ * @param valueOrPromise - The value or promise
119
+ * @param transformer - A function that maps the source value to a value or promise
120
+ */
121
+ export declare function transformValueOrPromise<T, V>(valueOrPromise: ValueOrPromise<T>, transformer: (val: T) => ValueOrPromise<V>): ValueOrPromise<V>;
122
+ /**
123
+ * A utility to generate uuid v4
124
+ *
125
+ * @deprecated Use `generateUniqueId`, [uuid](https://www.npmjs.com/package/uuid)
126
+ * or [hyperid](https://www.npmjs.com/package/hyperid) instead.
127
+ */
128
+ export declare function uuid(): string;
129
+ /**
130
+ * A regular expression for testing uuid v4 PATTERN
131
+ * @deprecated This pattern is an internal helper used by unit-tests, we are no
132
+ * longer using it.
133
+ */
134
+ export declare const UUID_PATTERN: RegExp;