@merkur/core 0.45.0 → 0.46.0-rc.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.
- package/package.json +2 -2
- package/types.d.ts +60 -19
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@merkur/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.0-rc.0",
|
|
4
4
|
"description": "Merkur is tiny and extensible library for creating front-end microservices.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"module": "lib/index",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://merkur.js.org/",
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "737814ec3ae39a32c8551196aed5be7925f1a1e1"
|
|
57
57
|
}
|
package/types.d.ts
CHANGED
|
@@ -13,34 +13,39 @@ export interface SourceAsset extends BaseWidgetAsset {
|
|
|
13
13
|
source: string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
16
17
|
export interface WidgetDependencies {}
|
|
17
18
|
|
|
18
|
-
export interface Widget {
|
|
19
|
-
name: string;
|
|
20
|
-
version: string;
|
|
21
|
-
containerSelector?: string;
|
|
22
|
-
$in: WidgetInternal;
|
|
23
|
-
$external: WidgetExternal;
|
|
24
|
-
$dependencies: WidgetDependencies;
|
|
25
|
-
$plugins: WidgetPlugin[];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
19
|
export interface WidgetProperties {
|
|
29
20
|
name: string;
|
|
30
21
|
version: string;
|
|
31
22
|
}
|
|
32
23
|
|
|
24
|
+
// Type for the widget config object passed to `defineWidget()`
|
|
33
25
|
export interface WidgetDefinition {
|
|
34
|
-
|
|
26
|
+
name: string;
|
|
27
|
+
version: string;
|
|
28
|
+
containerSelector?: string;
|
|
29
|
+
assets?: (WidgetAsset | SourceAsset)[];
|
|
30
|
+
$external?: WidgetExternal;
|
|
31
|
+
$dependencies?: WidgetDependencies;
|
|
35
32
|
$plugins?: Array<() => WidgetPlugin>;
|
|
36
|
-
$external: WidgetExternal;
|
|
37
|
-
$dependencies: WidgetDependencies;
|
|
38
33
|
create?: WidgetFunction;
|
|
39
34
|
setup?: WidgetFunction;
|
|
40
35
|
}
|
|
41
36
|
|
|
37
|
+
// Type used during initialization within `createMerkurWidget()`
|
|
38
|
+
// it initializes some properties (= they're not optional anymore)
|
|
39
|
+
|
|
40
|
+
export interface WidgetPartial extends WidgetDefinition, Required<Pick<WidgetDefinition, '$dependencies' | '$external' | 'create' | 'setup'>> {
|
|
41
|
+
$in: WidgetInternal;
|
|
42
|
+
slot: Record<any, any>; // @merkur/core knows (incorrectly?) about slot and initializes it to an empty object.
|
|
43
|
+
}
|
|
44
|
+
|
|
42
45
|
export interface WidgetParams {}
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
43
47
|
export interface WidgetInternal {}
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
44
49
|
export interface WidgetExternal {}
|
|
45
50
|
|
|
46
51
|
export interface WidgetPlugin {
|
|
@@ -49,13 +54,9 @@ export interface WidgetPlugin {
|
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
export type WidgetFunction = (
|
|
52
|
-
widget:
|
|
57
|
+
widget: WidgetPartial,
|
|
53
58
|
...rest: unknown[]
|
|
54
|
-
) => Promise<
|
|
55
|
-
|
|
56
|
-
export type MerkurCreate = (
|
|
57
|
-
widgetProperties: WidgetProperties,
|
|
58
|
-
) => Promise<Widget>;
|
|
59
|
+
) => Promise<WidgetPartial> | WidgetPartial;
|
|
59
60
|
|
|
60
61
|
export type WidgetCreate = (widgetParams: WidgetParams) => Promise<Widget>;
|
|
61
62
|
|
|
@@ -81,11 +82,26 @@ export interface Merkur {
|
|
|
81
82
|
/**
|
|
82
83
|
* Merkur API types
|
|
83
84
|
*/
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
|
|
84
86
|
export interface CreateMerkurWidgetArgs {}
|
|
85
87
|
export declare function createMerkurWidget<
|
|
86
88
|
T extends WidgetDefinition & CreateMerkurWidgetArgs,
|
|
87
89
|
>(widgetDefinition: T): Widget;
|
|
88
90
|
|
|
91
|
+
// `createMerkurWidget()` binds all WidgetFunctions to the widget instance using `bindWidgetToFunctions()`
|
|
92
|
+
// This series of types replicates that for the typing.
|
|
93
|
+
type TupleTail<T extends any[]> = T extends [any, ...infer Rest] ? Rest : never;
|
|
94
|
+
type FunctionLike = (...args: any[]) => any;
|
|
95
|
+
type BoundWidgetFunction<T extends FunctionLike> = (...args: TupleTail<Parameters<T>>) => ReturnType<T>;
|
|
96
|
+
type BoundWidget<T> = {
|
|
97
|
+
[K in keyof T]: T[K] extends FunctionLike ? BoundWidgetFunction<T[K]> : T[K];
|
|
98
|
+
}
|
|
99
|
+
export interface Widget extends BoundWidget<WidgetPartial> {}
|
|
100
|
+
|
|
101
|
+
export type MerkurCreate = (
|
|
102
|
+
widgetProperties: WidgetProperties,
|
|
103
|
+
) => Promise<Widget>;
|
|
104
|
+
|
|
89
105
|
export interface DefineWidgetArgs {}
|
|
90
106
|
export declare function defineWidget<
|
|
91
107
|
T extends WidgetDefinition & WidgetProperties & DefineWidgetArgs,
|
|
@@ -97,3 +113,28 @@ export declare function hookMethod(
|
|
|
97
113
|
path: string,
|
|
98
114
|
handler: (widget: Widget, originalFunction: any, ...args: any[]) => any,
|
|
99
115
|
): Promise<void>;
|
|
116
|
+
|
|
117
|
+
export declare function assignMissingKeys<T extends object>(
|
|
118
|
+
target: T,
|
|
119
|
+
...sources: Partial<T>[]
|
|
120
|
+
): T;
|
|
121
|
+
|
|
122
|
+
export declare function setDefaultValueForUndefined<T extends object>(
|
|
123
|
+
object: T,
|
|
124
|
+
keys: (keyof T)[],
|
|
125
|
+
value?: any,
|
|
126
|
+
): T;
|
|
127
|
+
|
|
128
|
+
export declare function bindWidgetToFunctions(
|
|
129
|
+
widget: Widget,
|
|
130
|
+
target?: any,
|
|
131
|
+
): void;
|
|
132
|
+
|
|
133
|
+
export declare function isFunction(
|
|
134
|
+
value: any,
|
|
135
|
+
): value is (...args: any[]) => any;
|
|
136
|
+
|
|
137
|
+
export declare function isUndefined(value: any): value is undefined;
|
|
138
|
+
|
|
139
|
+
export declare function getMerkur(): Merkur;
|
|
140
|
+
export declare function removeMerkur(): void;
|