UNPKG

5.28 kBTypeScriptView Raw
1import { 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 */
18export 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 */
45export declare function extensions(extensionPointName?: string, metadata?: InjectionMetadata): (target: Object, member: string | undefined, methodDescriptorOrParameterIndex?: number | TypedPropertyDescriptor<any> | undefined) => void;
46export 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 */
107export 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 */
113export 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 */
121export declare function addExtension(context: Context, extensionPointName: string, extensionClass: Constructor<unknown>, options?: BindingFromClassOptions): Binding<unknown>;