-
Notifications
You must be signed in to change notification settings - Fork 4
/
types.ts
108 lines (98 loc) · 3.39 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { SimpleTopicsAPI } from './core/topics-plugin/simple-topics/model';
/**
* Record of Services
*/
export type Services = Record<string, unknown>;
/**
* Record of Functions
*/
export type Functions = Record<string, CallableFunction>;
/**
* A context is described by a Description object. It can consist of three parts,
* describing the capabilities, behaviour and identity of an fragment.
*
* @property services - the services, provided by a fragment. Services can contain pure service functions,
* nested services and / or services mixed with topic services
* @property functions - the functions, provided from this fragment to its arrangement.
* @property config - allows an arrangement to overwrite a default configuration of its embe fragments
*/
export type FrontendDescription = {
services?: Services, // services we provide to the fragments
functions?: Functions, // functions we provide to the arrangement
fragmentsConfig?: Record<string, unknown>, // config we provide to our fragments
}
export type GenericPluginAPI = {
context: {
_plugins: Record<string, unknown>,
functions: Functions,
},
description: FrontendDescription,
frameId: string,
functions: Functions,
callback: CallableFunction,
}
/**
* Functions to enhance the expose and updateContext Functions by a plugin
*/
export type PluginFunctions<D, C, E> = {
enhanceExpose: (description: D, context: C) => Promise<E> | E | void,
enhanceUpdateContext?: (context: C) => Promise<E> | E | void,
reservedWords?: Array<string>,
enhanceExtractContextAsArrangement?: (data: GenericPluginAPI) => unknown,
enhanceExtractContextAsFragment?: (data: GenericPluginAPI) => unknown,
enhanceExtractFragmentDescription?: (data: GenericPluginAPI) => unknown,
}
/**
* Collage object returned by the bootstrap function
*
* extractContextAsArrangement: Extracts the important information from a context, needed by a fragment from its
* arrangement
*/
export type Collage<D, C> = {
expose: (description: D) => Promise<C>,
updateContext: (context: C) => Promise<C>,
reservedWords: Array<string>,
extractContextAsArrangement: (data: GenericPluginAPI) => unknown,
extractContextAsFragment: (data: GenericPluginAPI) => unknown,
extractFragmentDescription: (data: GenericPluginAPI) => unknown,
}
/**
* A Plugin is a function that enhances collage with additional features
*
* <D> stands for Description
* <C> stands for Context - before the enhancement
* <E> stands for Enhanced Context - after the enhancement
*/
export type Plugin<D, C, E> =
(previous: Collage<D, C>) => Collage<D, E>
/**
* Record of Fragments
*/
export type Fragments = Record<string, {
functions: Functions,
__fragmentId: string,
updateConfig: (config: object) => void
}>;
/**
* Represents the state of a Fragment at runtime
*/
export type Context = FrontendDescription & {
id?: string,
fragments?: Fragments,
_plugins?: Record<string, unknown>,
}
/**
* The ContextApi object is returned from the expose function.
* @property id - context id of the fragment
* @property services - services exposed by this context
* @property topics - topics exposed by this context
* @property fragments - all contained named fragments
* @property config - our own overwriten config
*/
export type ContextApi = {
id: string;
services: Services;
fragments: Fragments;
config: Record<string, unknown>;
topics: SimpleTopicsAPI & Record<string, unknown>;
}