@loopback/core 4.0.0-alpha.9 → 4.0.2

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 (121) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +77 -2
  3. package/dist/application.d.ts +341 -0
  4. package/dist/application.js +554 -0
  5. package/dist/application.js.map +1 -0
  6. package/dist/component.d.ts +80 -0
  7. package/dist/component.js +59 -0
  8. package/dist/component.js.map +1 -0
  9. package/dist/extension-point.d.ts +121 -0
  10. package/dist/extension-point.js +227 -0
  11. package/dist/extension-point.js.map +1 -0
  12. package/dist/index.d.ts +21 -0
  13. package/dist/index.js +31 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/keys.d.ts +97 -0
  16. package/dist/keys.js +109 -0
  17. package/dist/keys.js.map +1 -0
  18. package/dist/lifecycle-registry.d.ts +91 -0
  19. package/dist/lifecycle-registry.js +191 -0
  20. package/dist/lifecycle-registry.js.map +1 -0
  21. package/dist/lifecycle.d.ts +47 -0
  22. package/dist/lifecycle.js +56 -0
  23. package/dist/lifecycle.js.map +1 -0
  24. package/dist/mixin-target.d.ts +60 -0
  25. package/{lib6/internal-types.js → dist/mixin-target.js} +2 -3
  26. package/dist/mixin-target.js.map +1 -0
  27. package/dist/server.d.ts +16 -0
  28. package/{lib6/component.js → dist/server.js} +2 -2
  29. package/dist/server.js.map +1 -0
  30. package/dist/service.d.ts +63 -0
  31. package/dist/service.js +151 -0
  32. package/dist/service.js.map +1 -0
  33. package/package.json +39 -37
  34. package/src/application.ts +719 -0
  35. package/src/component.ts +155 -0
  36. package/src/extension-point.ts +312 -0
  37. package/src/index.ts +29 -0
  38. package/src/keys.ts +144 -0
  39. package/src/lifecycle-registry.ts +268 -0
  40. package/src/lifecycle.ts +90 -0
  41. package/src/mixin-target.ts +69 -0
  42. package/src/server.ts +22 -0
  43. package/src/service.ts +211 -0
  44. package/index.d.ts +0 -6
  45. package/index.js +0 -9
  46. package/lib/application.d.ts +0 -54
  47. package/lib/application.js +0 -81
  48. package/lib/application.js.map +0 -1
  49. package/lib/component.d.ts +0 -2
  50. package/lib/component.js +0 -7
  51. package/lib/component.js.map +0 -1
  52. package/lib/http-handler.d.ts +0 -16
  53. package/lib/http-handler.js +0 -62
  54. package/lib/http-handler.js.map +0 -1
  55. package/lib/index.d.ts +0 -17
  56. package/lib/index.js +0 -37
  57. package/lib/index.js.map +0 -1
  58. package/lib/internal-types.d.ts +0 -29
  59. package/lib/internal-types.js +0 -8
  60. package/lib/internal-types.js.map +0 -1
  61. package/lib/keys.d.ts +0 -7
  62. package/lib/keys.js +0 -16
  63. package/lib/keys.js.map +0 -1
  64. package/lib/parser.d.ts +0 -11
  65. package/lib/parser.js +0 -96
  66. package/lib/parser.js.map +0 -1
  67. package/lib/promisify.d.ts +0 -3
  68. package/lib/promisify.js +0 -34
  69. package/lib/promisify.js.map +0 -1
  70. package/lib/router/metadata.d.ts +0 -12
  71. package/lib/router/metadata.js +0 -30
  72. package/lib/router/metadata.js.map +0 -1
  73. package/lib/router/routing-table.d.ts +0 -16
  74. package/lib/router/routing-table.js +0 -97
  75. package/lib/router/routing-table.js.map +0 -1
  76. package/lib/sequence.d.ts +0 -55
  77. package/lib/sequence.js +0 -99
  78. package/lib/sequence.js.map +0 -1
  79. package/lib/server.d.ts +0 -23
  80. package/lib/server.js +0 -64
  81. package/lib/server.js.map +0 -1
  82. package/lib/writer.d.ts +0 -11
  83. package/lib/writer.js +0 -34
  84. package/lib/writer.js.map +0 -1
  85. package/lib6/application.d.ts +0 -54
  86. package/lib6/application.js +0 -81
  87. package/lib6/application.js.map +0 -1
  88. package/lib6/component.d.ts +0 -2
  89. package/lib6/component.js.map +0 -1
  90. package/lib6/http-handler.d.ts +0 -16
  91. package/lib6/http-handler.js +0 -72
  92. package/lib6/http-handler.js.map +0 -1
  93. package/lib6/index.d.ts +0 -17
  94. package/lib6/index.js +0 -37
  95. package/lib6/index.js.map +0 -1
  96. package/lib6/internal-types.d.ts +0 -29
  97. package/lib6/internal-types.js.map +0 -1
  98. package/lib6/keys.d.ts +0 -7
  99. package/lib6/keys.js +0 -16
  100. package/lib6/keys.js.map +0 -1
  101. package/lib6/parser.d.ts +0 -11
  102. package/lib6/parser.js +0 -106
  103. package/lib6/parser.js.map +0 -1
  104. package/lib6/promisify.d.ts +0 -3
  105. package/lib6/promisify.js +0 -34
  106. package/lib6/promisify.js.map +0 -1
  107. package/lib6/router/metadata.d.ts +0 -12
  108. package/lib6/router/metadata.js +0 -30
  109. package/lib6/router/metadata.js.map +0 -1
  110. package/lib6/router/routing-table.d.ts +0 -16
  111. package/lib6/router/routing-table.js +0 -97
  112. package/lib6/router/routing-table.js.map +0 -1
  113. package/lib6/sequence.d.ts +0 -55
  114. package/lib6/sequence.js +0 -109
  115. package/lib6/sequence.js.map +0 -1
  116. package/lib6/server.d.ts +0 -23
  117. package/lib6/server.js +0 -74
  118. package/lib6/server.js.map +0 -1
  119. package/lib6/writer.d.ts +0 -11
  120. package/lib6/writer.js +0 -34
  121. package/lib6/writer.js.map +0 -1
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. and LoopBack contributors 2017,2019. All Rights Reserved.
3
+ // Node module: @loopback/core
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.mountComponent = void 0;
8
+ const context_1 = require("@loopback/context");
9
+ /**
10
+ * Mount a component to an Application.
11
+ *
12
+ * @param app - Application
13
+ * @param component - Component instance
14
+ */
15
+ function mountComponent(app, component) {
16
+ if (component.classes) {
17
+ for (const classKey in component.classes) {
18
+ const binding = (0, context_1.createBindingFromClass)(component.classes[classKey], {
19
+ key: classKey,
20
+ });
21
+ app.add(binding);
22
+ }
23
+ }
24
+ if (component.providers) {
25
+ for (const providerKey in component.providers) {
26
+ const binding = (0, context_1.createBindingFromClass)(component.providers[providerKey], {
27
+ key: providerKey,
28
+ });
29
+ app.add(binding);
30
+ }
31
+ }
32
+ if (component.bindings) {
33
+ for (const binding of component.bindings) {
34
+ app.add(binding);
35
+ }
36
+ }
37
+ if (component.controllers) {
38
+ for (const controllerCtor of component.controllers) {
39
+ app.controller(controllerCtor);
40
+ }
41
+ }
42
+ if (component.servers) {
43
+ for (const serverKey in component.servers) {
44
+ app.server(component.servers[serverKey], serverKey);
45
+ }
46
+ }
47
+ if (component.lifeCycleObservers) {
48
+ for (const observer of component.lifeCycleObservers) {
49
+ app.lifeCycleObserver(observer);
50
+ }
51
+ }
52
+ if (component.services) {
53
+ for (const service of component.services) {
54
+ app.service(service);
55
+ }
56
+ }
57
+ }
58
+ exports.mountComponent = mountComponent;
59
+ //# sourceMappingURL=component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component.js","sourceRoot":"","sources":["../src/component.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAM2B;AAyF3B;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,GAAgB,EAAE,SAAoB;IACnE,IAAI,SAAS,CAAC,OAAO,EAAE;QACrB,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,OAAO,EAAE;YACxC,MAAM,OAAO,GAAG,IAAA,gCAAsB,EAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAClE,GAAG,EAAE,QAAQ;aACd,CAAC,CAAC;YACH,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAClB;KACF;IAED,IAAI,SAAS,CAAC,SAAS,EAAE;QACvB,KAAK,MAAM,WAAW,IAAI,SAAS,CAAC,SAAS,EAAE;YAC7C,MAAM,OAAO,GAAG,IAAA,gCAAsB,EAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE;gBACvE,GAAG,EAAE,WAAW;aACjB,CAAC,CAAC;YACH,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAClB;KACF;IAED,IAAI,SAAS,CAAC,QAAQ,EAAE;QACtB,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE;YACxC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;SAClB;KACF;IAED,IAAI,SAAS,CAAC,WAAW,EAAE;QACzB,KAAK,MAAM,cAAc,IAAI,SAAS,CAAC,WAAW,EAAE;YAClD,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;SAChC;KACF;IAED,IAAI,SAAS,CAAC,OAAO,EAAE;QACrB,KAAK,MAAM,SAAS,IAAI,SAAS,CAAC,OAAO,EAAE;YACzC,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;SACrD;KACF;IAED,IAAI,SAAS,CAAC,kBAAkB,EAAE;QAChC,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,kBAAkB,EAAE;YACnD,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;SACjC;KACF;IAED,IAAI,SAAS,CAAC,QAAQ,EAAE;QACtB,KAAK,MAAM,OAAO,IAAI,SAAS,CAAC,QAAQ,EAAE;YACxC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;SACtB;KACF;AACH,CAAC;AAhDD,wCAgDC"}
@@ -0,0 +1,121 @@
1
+ import { Binding, BindingFilter, BindingFromClassOptions, BindingSpec, BindingTemplate, Constructor, Context, InjectionMetadata } from '@loopback/context';
2
+ /**
3
+ * Decorate a class as a named extension point. If the decoration is not
4
+ * present, the name of the class will be used.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import {extensionPoint} from '@loopback/core';
9
+ *
10
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
11
+ * export class GreetingService {
12
+ * // ...
13
+ * }
14
+ * ```
15
+ *
16
+ * @param name - Name of the extension point
17
+ */
18
+ export declare function extensionPoint(name: string, ...specs: BindingSpec[]): ClassDecorator;
19
+ /**
20
+ * Shortcut to inject extensions for the given extension point.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import {Getter} from '@loopback/context';
25
+ * import {extensionPoint, extensions} from '@loopback/core';
26
+ *
27
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
28
+ * export class GreetingService {
29
+ * constructor(
30
+ * @extensions() // Inject extensions for the extension point
31
+ * private getGreeters: Getter<Greeter[]>,
32
+ * // ...
33
+ * ) {
34
+ * // ...
35
+ * }
36
+ * ```
37
+ *
38
+ * @param extensionPointName - Name of the extension point. If not supplied, we
39
+ * use the `name` tag from the extension point binding or the class name of the
40
+ * extension point class. If a class needs to inject extensions from multiple
41
+ * extension points, use different `extensionPointName` for different types of
42
+ * extensions.
43
+ * @param metadata - Optional injection metadata
44
+ */
45
+ export declare function extensions(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
46
+ export declare namespace extensions {
47
+ /**
48
+ * Inject a `ContextView` for extensions of the extension point. The view can
49
+ * then be listened on events such as `bind`, `unbind`, or `refresh` to react
50
+ * on changes of extensions.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import {extensionPoint, extensions} from '@loopback/core';
55
+ *
56
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
57
+ * export class GreetingService {
58
+ * constructor(
59
+ * @extensions.view() // Inject a context view for extensions of the extension point
60
+ * private greetersView: ContextView<Greeter>,
61
+ * // ...
62
+ * ) {
63
+ * // ...
64
+ * }
65
+ * ```
66
+ * @param extensionPointName - Name of the extension point. If not supplied, we
67
+ * use the `name` tag from the extension point binding or the class name of the
68
+ * extension point class. If a class needs to inject extensions from multiple
69
+ * extension points, use different `extensionPointName` for different types of
70
+ * extensions.
71
+ * @param metadata - Optional injection metadata
72
+ */
73
+ function view(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
74
+ /**
75
+ * Inject an array of resolved extension instances for the extension point.
76
+ * The list is a snapshot of registered extensions when the injection is
77
+ * fulfilled. Extensions added or removed afterward won't impact the list.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import {extensionPoint, extensions} from '@loopback/core';
82
+ *
83
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
84
+ * export class GreetingService {
85
+ * constructor(
86
+ * @extensions.list() // Inject an array of extensions for the extension point
87
+ * private greeters: Greeter[],
88
+ * // ...
89
+ * ) {
90
+ * // ...
91
+ * }
92
+ * ```
93
+ * @param extensionPointName - Name of the extension point. If not supplied, we
94
+ * use the `name` tag from the extension point binding or the class name of the
95
+ * extension point class. If a class needs to inject extensions from multiple
96
+ * extension points, use different `extensionPointName` for different types of
97
+ * extensions.
98
+ * @param metadata - Optional injection metadata
99
+ */
100
+ function list(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
101
+ }
102
+ /**
103
+ * A factory function to create binding filter for extensions of a named
104
+ * extension point
105
+ * @param extensionPointNames - A list of names of extension points
106
+ */
107
+ export declare function extensionFilter(...extensionPointNames: string[]): BindingFilter;
108
+ /**
109
+ * A factory function to create binding template for extensions of the given
110
+ * extension point
111
+ * @param extensionPointNames - Names of the extension point
112
+ */
113
+ export declare function extensionFor(...extensionPointNames: string[]): BindingTemplate;
114
+ /**
115
+ * Register an extension for the given extension point to the context
116
+ * @param context - Context object
117
+ * @param extensionPointName - Name of the extension point
118
+ * @param extensionClass - Class or a provider for an extension
119
+ * @param options - Options Options for the creation of binding from class
120
+ */
121
+ export declare function addExtension(context: Context, extensionPointName: string, extensionClass: Constructor<unknown>, options?: BindingFromClassOptions): Binding<unknown>;
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
3
+ // Node module: @loopback/core
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.addExtension = exports.extensionFor = exports.extensionFilter = exports.extensions = exports.extensionPoint = void 0;
8
+ const context_1 = require("@loopback/context");
9
+ const keys_1 = require("./keys");
10
+ /**
11
+ * Decorate a class as a named extension point. If the decoration is not
12
+ * present, the name of the class will be used.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import {extensionPoint} from '@loopback/core';
17
+ *
18
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
19
+ * export class GreetingService {
20
+ * // ...
21
+ * }
22
+ * ```
23
+ *
24
+ * @param name - Name of the extension point
25
+ */
26
+ function extensionPoint(name, ...specs) {
27
+ return (0, context_1.injectable)({ tags: { [keys_1.CoreTags.EXTENSION_POINT]: name } }, ...specs);
28
+ }
29
+ exports.extensionPoint = extensionPoint;
30
+ /**
31
+ * Shortcut to inject extensions for the given extension point.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import {Getter} from '@loopback/context';
36
+ * import {extensionPoint, extensions} from '@loopback/core';
37
+ *
38
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
39
+ * export class GreetingService {
40
+ * constructor(
41
+ * @extensions() // Inject extensions for the extension point
42
+ * private getGreeters: Getter<Greeter[]>,
43
+ * // ...
44
+ * ) {
45
+ * // ...
46
+ * }
47
+ * ```
48
+ *
49
+ * @param extensionPointName - Name of the extension point. If not supplied, we
50
+ * use the `name` tag from the extension point binding or the class name of the
51
+ * extension point class. If a class needs to inject extensions from multiple
52
+ * extension points, use different `extensionPointName` for different types of
53
+ * extensions.
54
+ * @param metadata - Optional injection metadata
55
+ */
56
+ function extensions(extensionPointName, metadata) {
57
+ return (0, context_1.inject)('', { ...metadata, decorator: '@extensions' }, (ctx, injection, session) => {
58
+ (0, context_1.assertTargetType)(injection, Function, 'Getter function');
59
+ const bindingFilter = filterByExtensionPoint(injection, session, extensionPointName);
60
+ return (0, context_1.createViewGetter)(ctx, bindingFilter, injection.metadata.bindingComparator, { ...metadata, ...(0, context_1.asResolutionOptions)(session) });
61
+ });
62
+ }
63
+ exports.extensions = extensions;
64
+ (function (extensions) {
65
+ /**
66
+ * Inject a `ContextView` for extensions of the extension point. The view can
67
+ * then be listened on events such as `bind`, `unbind`, or `refresh` to react
68
+ * on changes of extensions.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import {extensionPoint, extensions} from '@loopback/core';
73
+ *
74
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
75
+ * export class GreetingService {
76
+ * constructor(
77
+ * @extensions.view() // Inject a context view for extensions of the extension point
78
+ * private greetersView: ContextView<Greeter>,
79
+ * // ...
80
+ * ) {
81
+ * // ...
82
+ * }
83
+ * ```
84
+ * @param extensionPointName - Name of the extension point. If not supplied, we
85
+ * use the `name` tag from the extension point binding or the class name of the
86
+ * extension point class. If a class needs to inject extensions from multiple
87
+ * extension points, use different `extensionPointName` for different types of
88
+ * extensions.
89
+ * @param metadata - Optional injection metadata
90
+ */
91
+ function view(extensionPointName, metadata) {
92
+ return (0, context_1.inject)('', { ...metadata, decorator: '@extensions.view' }, (ctx, injection, session) => {
93
+ (0, context_1.assertTargetType)(injection, context_1.ContextView);
94
+ const bindingFilter = filterByExtensionPoint(injection, session, extensionPointName);
95
+ return ctx.createView(bindingFilter, injection.metadata.bindingComparator, metadata);
96
+ });
97
+ }
98
+ extensions.view = view;
99
+ /**
100
+ * Inject an array of resolved extension instances for the extension point.
101
+ * The list is a snapshot of registered extensions when the injection is
102
+ * fulfilled. Extensions added or removed afterward won't impact the list.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * import {extensionPoint, extensions} from '@loopback/core';
107
+ *
108
+ * @extensionPoint(GREETER_EXTENSION_POINT_NAME)
109
+ * export class GreetingService {
110
+ * constructor(
111
+ * @extensions.list() // Inject an array of extensions for the extension point
112
+ * private greeters: Greeter[],
113
+ * // ...
114
+ * ) {
115
+ * // ...
116
+ * }
117
+ * ```
118
+ * @param extensionPointName - Name of the extension point. If not supplied, we
119
+ * use the `name` tag from the extension point binding or the class name of the
120
+ * extension point class. If a class needs to inject extensions from multiple
121
+ * extension points, use different `extensionPointName` for different types of
122
+ * extensions.
123
+ * @param metadata - Optional injection metadata
124
+ */
125
+ function list(extensionPointName, metadata) {
126
+ return (0, context_1.inject)('', { ...metadata, decorator: '@extensions.instances' }, (ctx, injection, session) => {
127
+ (0, context_1.assertTargetType)(injection, Array);
128
+ const bindingFilter = filterByExtensionPoint(injection, session, extensionPointName);
129
+ const viewForExtensions = new context_1.ContextView(ctx, bindingFilter, injection.metadata.bindingComparator);
130
+ return viewForExtensions.resolve({
131
+ ...metadata,
132
+ ...(0, context_1.asResolutionOptions)(session),
133
+ });
134
+ });
135
+ }
136
+ extensions.list = list;
137
+ })(extensions = exports.extensions || (exports.extensions = {}));
138
+ /**
139
+ * Create a binding filter for `@extensions.*`
140
+ * @param injection - Injection object
141
+ * @param session - Resolution session
142
+ * @param extensionPointName - Extension point name
143
+ */
144
+ function filterByExtensionPoint(injection, session, extensionPointName) {
145
+ extensionPointName =
146
+ extensionPointName !== null && extensionPointName !== void 0 ? extensionPointName : inferExtensionPointName(injection.target, session.currentBinding);
147
+ return extensionFilter(extensionPointName);
148
+ }
149
+ /**
150
+ * Infer the extension point name from binding tags/class name
151
+ * @param injectionTarget - Target class or prototype
152
+ * @param currentBinding - Current binding
153
+ */
154
+ function inferExtensionPointName(injectionTarget, currentBinding) {
155
+ if (currentBinding) {
156
+ const name = currentBinding.tagMap[keys_1.CoreTags.EXTENSION_POINT] ||
157
+ currentBinding.tagMap[context_1.ContextTags.NAME];
158
+ if (name)
159
+ return name;
160
+ }
161
+ let target;
162
+ if (typeof injectionTarget === 'function') {
163
+ // Constructor injection
164
+ target = injectionTarget;
165
+ }
166
+ else {
167
+ // Injection on the prototype
168
+ target = injectionTarget.constructor;
169
+ }
170
+ return target.name;
171
+ }
172
+ /**
173
+ * A factory function to create binding filter for extensions of a named
174
+ * extension point
175
+ * @param extensionPointNames - A list of names of extension points
176
+ */
177
+ function extensionFilter(...extensionPointNames) {
178
+ return (0, context_1.filterByTag)({
179
+ [keys_1.CoreTags.EXTENSION_FOR]: (0, context_1.includesTagValue)(...extensionPointNames),
180
+ });
181
+ }
182
+ exports.extensionFilter = extensionFilter;
183
+ /**
184
+ * A factory function to create binding template for extensions of the given
185
+ * extension point
186
+ * @param extensionPointNames - Names of the extension point
187
+ */
188
+ function extensionFor(...extensionPointNames) {
189
+ return binding => {
190
+ if (extensionPointNames.length === 0)
191
+ return;
192
+ let extensionPoints = binding.tagMap[keys_1.CoreTags.EXTENSION_FOR];
193
+ // Normalize extensionPoints to string[]
194
+ if (extensionPoints == null) {
195
+ extensionPoints = [];
196
+ }
197
+ else if (typeof extensionPoints === 'string') {
198
+ extensionPoints = [extensionPoints];
199
+ }
200
+ // Add extension points
201
+ for (const extensionPointName of extensionPointNames) {
202
+ if (!extensionPoints.includes(extensionPointName)) {
203
+ extensionPoints.push(extensionPointName);
204
+ }
205
+ }
206
+ if (extensionPoints.length === 1) {
207
+ // Keep the value as string for backward compatibility
208
+ extensionPoints = extensionPoints[0];
209
+ }
210
+ binding.tag({ [keys_1.CoreTags.EXTENSION_FOR]: extensionPoints });
211
+ };
212
+ }
213
+ exports.extensionFor = extensionFor;
214
+ /**
215
+ * Register an extension for the given extension point to the context
216
+ * @param context - Context object
217
+ * @param extensionPointName - Name of the extension point
218
+ * @param extensionClass - Class or a provider for an extension
219
+ * @param options - Options Options for the creation of binding from class
220
+ */
221
+ function addExtension(context, extensionPointName, extensionClass, options) {
222
+ const binding = (0, context_1.createBindingFromClass)(extensionClass, options).apply(extensionFor(extensionPointName));
223
+ context.add(binding);
224
+ return binding;
225
+ }
226
+ exports.addExtension = addExtension;
227
+ //# sourceMappingURL=extension-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-point.js","sourceRoot":"","sources":["../src/extension-point.ts"],"names":[],"mappings":";AAAA,gFAAgF;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,CAAC,eAAe,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE;gBACjD,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;aAC1C;SACF;QACD,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE;YAChC,sDAAsD;YACtD,eAAe,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;SACtC;QACD,OAAO,CAAC,GAAG,CAAC,EAAC,CAAC,eAAQ,CAAC,aAAa,CAAC,EAAE,eAAe,EAAC,CAAC,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAzBD,oCAyBC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAC1B,OAAgB,EAChB,kBAA0B,EAC1B,cAAoC,EACpC,OAAiC;IAEjC,MAAM,OAAO,GAAG,IAAA,gCAAsB,EAAC,cAAc,EAAE,OAAO,CAAC,CAAC,KAAK,CACnE,YAAY,CAAC,kBAAkB,CAAC,CACjC,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,OAAO,OAAO,CAAC;AACjB,CAAC;AAXD,oCAWC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The core foundation for LoopBack 4. It can also serve as the platform to
3
+ * build large-scale Node.js applications and frameworks.
4
+ *
5
+ * @remarks
6
+ * For examples of how to leverage `@loopback/core` to build composable and
7
+ * extensible projects, check out the
8
+ * {@link https://loopback.io/doc/en/lb4/core-tutorial.html | core tutorial}.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ export * from '@loopback/context';
13
+ export * from './application';
14
+ export * from './component';
15
+ export * from './extension-point';
16
+ export * from './keys';
17
+ export * from './lifecycle';
18
+ export * from './lifecycle-registry';
19
+ export * from './mixin-target';
20
+ export * from './server';
21
+ export * from './service';
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ // Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
3
+ // Node module: @loopback/core
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
+ const tslib_1 = require("tslib");
8
+ /**
9
+ * The core foundation for LoopBack 4. It can also serve as the platform to
10
+ * build large-scale Node.js applications and frameworks.
11
+ *
12
+ * @remarks
13
+ * For examples of how to leverage `@loopback/core` to build composable and
14
+ * extensible projects, check out the
15
+ * {@link https://loopback.io/doc/en/lb4/core-tutorial.html | core tutorial}.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ // Re-export public Core API coming from dependencies
20
+ tslib_1.__exportStar(require("@loopback/context"), exports);
21
+ // Export APIs
22
+ tslib_1.__exportStar(require("./application"), exports);
23
+ tslib_1.__exportStar(require("./component"), exports);
24
+ tslib_1.__exportStar(require("./extension-point"), exports);
25
+ tslib_1.__exportStar(require("./keys"), exports);
26
+ tslib_1.__exportStar(require("./lifecycle"), exports);
27
+ tslib_1.__exportStar(require("./lifecycle-registry"), exports);
28
+ tslib_1.__exportStar(require("./mixin-target"), exports);
29
+ tslib_1.__exportStar(require("./server"), exports);
30
+ tslib_1.__exportStar(require("./service"), exports);
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE;;;;;;;;;;GAUG;AAEH,qDAAqD;AACrD,4DAAkC;AAClC,cAAc;AACd,wDAA8B;AAC9B,sDAA4B;AAC5B,4DAAkC;AAClC,iDAAuB;AACvB,sDAA4B;AAC5B,+DAAqC;AACrC,yDAA+B;AAC/B,mDAAyB;AACzB,oDAA0B"}
package/dist/keys.d.ts ADDED
@@ -0,0 +1,97 @@
1
+ import { BindingKey } from '@loopback/context';
2
+ import { Application, ApplicationConfig, ApplicationMetadata, ControllerClass } from './application';
3
+ import { LifeCycleObserverOptions, LifeCycleObserverRegistry } from './lifecycle-registry';
4
+ /**
5
+ * Namespace for core binding keys
6
+ */
7
+ export declare namespace CoreBindings {
8
+ /**
9
+ * Binding key for application instance itself
10
+ */
11
+ const APPLICATION_INSTANCE: BindingKey<Application>;
12
+ /**
13
+ * Binding key for application configuration
14
+ */
15
+ const APPLICATION_CONFIG: BindingKey<ApplicationConfig>;
16
+ /**
17
+ * Binding key for the content of `package.json`
18
+ */
19
+ const APPLICATION_METADATA: BindingKey<ApplicationMetadata>;
20
+ /**
21
+ * Binding key for servers
22
+ */
23
+ const SERVERS = "servers";
24
+ /**
25
+ * Binding key for components
26
+ */
27
+ const COMPONENTS = "components";
28
+ const CONTROLLERS = "controllers";
29
+ /**
30
+ * Binding key for the controller class resolved in the current request
31
+ * context
32
+ */
33
+ const CONTROLLER_CLASS: BindingKey<ControllerClass>;
34
+ /**
35
+ * Binding key for the controller method resolved in the current request
36
+ * context
37
+ */
38
+ const CONTROLLER_METHOD_NAME: BindingKey<string>;
39
+ /**
40
+ * Binding key for the controller method metadata resolved in the current
41
+ * request context
42
+ */
43
+ const CONTROLLER_METHOD_META = "controller.method.meta";
44
+ /**
45
+ * Binding key for the controller instance resolved in the current request
46
+ * context
47
+ */
48
+ const CONTROLLER_CURRENT: BindingKey<unknown>;
49
+ const LIFE_CYCLE_OBSERVERS = "lifeCycleObservers";
50
+ /**
51
+ * Binding key for life cycle observer options
52
+ */
53
+ const LIFE_CYCLE_OBSERVER_REGISTRY: BindingKey<LifeCycleObserverRegistry>;
54
+ /**
55
+ * Binding key for life cycle observer options
56
+ */
57
+ const LIFE_CYCLE_OBSERVER_OPTIONS: BindingKey<LifeCycleObserverOptions>;
58
+ }
59
+ export declare namespace CoreTags {
60
+ /**
61
+ * Binding tag for components
62
+ */
63
+ const COMPONENT = "component";
64
+ /**
65
+ * Binding tag for servers
66
+ */
67
+ const SERVER = "server";
68
+ /**
69
+ * Binding tag for controllers
70
+ */
71
+ const CONTROLLER = "controller";
72
+ /**
73
+ * Binding tag for services
74
+ */
75
+ const SERVICE = "service";
76
+ /**
77
+ * Binding tag for the service interface
78
+ */
79
+ const SERVICE_INTERFACE = "serviceInterface";
80
+ /**
81
+ * Binding tag for life cycle observers
82
+ */
83
+ const LIFE_CYCLE_OBSERVER = "lifeCycleObserver";
84
+ /**
85
+ * Binding tag for group name of life cycle observers
86
+ */
87
+ const LIFE_CYCLE_OBSERVER_GROUP = "lifeCycleObserverGroup";
88
+ /**
89
+ * Binding tag for extensions to specify name of the extension point that an
90
+ * extension contributes to.
91
+ */
92
+ const EXTENSION_FOR = "extensionFor";
93
+ /**
94
+ * Binding tag for an extension point to specify name of the extension point
95
+ */
96
+ const EXTENSION_POINT = "extensionPoint";
97
+ }