repluggable-core 0.0.0-pr280.413 → 1.302.63

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/src/API.ts CHANGED
@@ -1,5 +1,3 @@
1
- import * as Redux from 'redux'
2
-
3
1
  export interface AnySlotKey {
4
2
  readonly name: string
5
3
  readonly public?: boolean // TODO: Move to new interface - APIKey
@@ -30,486 +28,4 @@ export interface SlotKey<T> extends AnySlotKey {
30
28
  * Version of the API that will be part of the API key unique identification
31
29
  */
32
30
  readonly version?: number // TODO: Move to new interface - APIKey
33
- }
34
-
35
- export type ReactComponentContributor<TProps = {}> = (props?: TProps) => React.ReactNode
36
- export type ReducersMapObjectContributor<TState = {}, TAction extends Redux.AnyAction = Redux.AnyAction> = () => Redux.ReducersMapObject<
37
- TState,
38
- TAction
39
- >
40
- export type ContributionPredicate = () => boolean
41
- export interface EntryPointTags {
42
- [name: string]: string
43
- }
44
- export type LazyEntryPointFactory = () => Promise<EntryPoint> //TODO: get rid of these
45
- export type ShellsChangedCallback = (shellNames: string[]) => void
46
- export type ShellBoundaryAspect = React.FunctionComponent<React.PropsWithChildren<unknown>>
47
-
48
- export interface LazyEntryPointDescriptor {
49
- readonly name: string
50
- readonly factory: LazyEntryPointFactory
51
- }
52
-
53
-
54
-
55
- /**
56
- * Application part that will receive a {Shell} when loaded into the {AppHost}
57
- * @export
58
- * @interface EntryPoint
59
- */
60
- export interface EntryPoint {
61
- /**
62
- * Unique name that will represent this entry point in the host
63
- */
64
- readonly name: string
65
- readonly tags?: EntryPointTags
66
- /**
67
- * Application layer / layers that will restrict usage of APIs contributed by this entry point.
68
- * Layers hierarchy is defined in the host options
69
- * See {AppHostOptions.layers}
70
- */
71
- readonly layer?: string | string[]
72
- /**
73
- * Define which API keys (a.k.a. contracts) are mandatory for this entry point to be executed
74
- * @return {SlotKey<any>[]} API keys to wait for implementation
75
- */
76
- getDependencyAPIs?(): SlotKey<any>[]
77
- /**
78
- * Define which API keys (a.k.a. contracts) this entry point is going to implement and contribute
79
- * @return {SlotKey<any>[]} API keys that will be contributed
80
- */
81
- declareAPIs?(): SlotKey<any>[]
82
- /**
83
- * Execute logic that is independent from other entry points
84
- * Most commonly - contribute APIs and state
85
- * @param {Shell} shell
86
- */
87
- attach?(shell: Shell): void
88
- /**
89
- * Execute logic that is dependent on other entry points
90
- * @param {Shell} shell
91
- */
92
- extend?(shell: Shell): void
93
- /**
94
- * Clean side effects
95
- * @param {Shell} shell
96
- */
97
- detach?(shell: Shell): void
98
- }
99
-
100
- export type AnyEntryPoint = EntryPoint | LazyEntryPointDescriptor
101
- export type EntryPointOrPackage = AnyEntryPoint | AnyEntryPoint[]
102
- export interface EntryPointOrPackagesMap {
103
- [name: string]: EntryPointOrPackage
104
- }
105
-
106
- export type ExtensionItemFilter<T> = (extensionItem: ExtensionItem<T>) => boolean
107
- /**
108
- * A slot/container for holding any contribution of shape T
109
- * Access to the slot is scoped to the {Shell}
110
- *
111
- * @export
112
- * @interface ExtensionSlot
113
- * @template T
114
- */
115
- export interface ExtensionSlot<T> {
116
- /**
117
- * a unique identifier for the slot
118
- */
119
- readonly name: string
120
- readonly host: AppHost
121
- /**
122
- * Which {Shell} owns this slot
123
- */
124
- readonly declaringShell?: Shell
125
- /**
126
- * Add an item to the slot
127
- *
128
- * @param {Shell} shell Who owns the contributed item
129
- * @param {T} item Extension item to be added to the slot
130
- * @param {ContributionPredicate} [condition] A predicate to condition the retrieval of the item when slot items are requested with {ExtensionSlot<T>.getItems}
131
- */
132
- contribute(shell: Shell, item: T, condition?: ContributionPredicate): void
133
- /**
134
- * Get all items contributed to the slot
135
- *
136
- * @param {boolean} [forceAll] Ignore items' contribution predicates and get all anyway
137
- * @return {ExtensionItem<T>[]} All items contributed to the slot
138
- */
139
- getItems(forceAll?: boolean): ExtensionItem<T>[]
140
- /**
141
- * Get the first item in the slot
142
- *
143
- * @return {ExtensionItem<T>} The first item in the slot
144
- */
145
- getSingleItem(): ExtensionItem<T> | undefined
146
- /**
147
- * Get a specific item in the slot
148
- *
149
- * @param {string} name Extension item name
150
- * @return {ExtensionItem<T> | undefined} Extension item
151
- */
152
- getItemByName(name: string): ExtensionItem<T> | undefined
153
- /**
154
- * Remove items from the slot by predicate
155
- *
156
- * @param {ExtensionItemFilter<T> | undefined} predicate Remove all items matching this predicate
157
- */
158
- discardBy(predicate: ExtensionItemFilter<T>): void
159
- }
160
-
161
- export interface PrivateExtensionSlot<T> extends ExtensionSlot<T> {
162
- subscribe(callback: () => void): () => void
163
- }
164
-
165
- export interface CustomExtensionSlotHandler<T> {
166
- contribute(fromShell: Shell, item: T, condition?: ContributionPredicate): void
167
- discardBy(predicate: ExtensionItemFilter<T>): void
168
- }
169
-
170
- export interface CustomExtensionSlot<T> extends CustomExtensionSlotHandler<T> {
171
- readonly name: string
172
- readonly host: AppHost
173
- readonly declaringShell?: Shell
174
- }
175
-
176
- /**
177
- * Item of shape T that is contributed to a slot of shape T
178
- *
179
- * @export
180
- * @interface ExtensionItem
181
- * @template T
182
- */
183
- export interface ExtensionItem<T> {
184
- readonly name?: string
185
- /**
186
- * Which {Shell} owns this item
187
- */
188
- readonly shell: Shell
189
- /**
190
- * Contribution content
191
- */
192
- readonly contribution: T
193
- /**
194
- * Condition for the retrieval of this item by {ExtensionSlot<T>.getItems}
195
- */
196
- readonly condition: ContributionPredicate
197
- readonly uniqueId: string
198
- }
199
-
200
- // addEntryPoints(entryPoints: EntryPoint[])
201
- // addPackages(packages: EntryPointOrPackage[])
202
- //
203
-
204
- /**
205
- * An application content container that will accept {EntryPoint} and provide registry for contracts
206
- *
207
- * @export
208
- * @interface AppHost
209
- */
210
- export interface AppHost {
211
- /**
212
- * Get an implementation of API previously contributed to the {AppHost}
213
- *
214
- * @template TAPI
215
- * @param {SlotKey<TAPI>} key API Key
216
- * @return {*} {TAPI}
217
- */
218
- getAPI<TAPI>(key: SlotKey<TAPI>): TAPI
219
- /**
220
- * Get an extension slot defined on the host
221
- *
222
- * @template TItem
223
- * @param {SlotKey<TItem>} key
224
- * @return {ExtensionSlot<TItem>}
225
- */
226
- getSlot<TItem>(key: SlotKey<TItem>): ExtensionSlot<TItem>
227
- /**
228
- * Get all the extension slots defined on the host
229
- *
230
- * @return {*} {AnySlotKey[]}
231
- */
232
- getAllSlotKeys(): AnySlotKey[]
233
- /**
234
- * Get all {EntryPoint}s addded to the {AppHost}
235
- *
236
- * @return {EntryPointsInfo[]}
237
- */
238
- getAllEntryPoints(): EntryPointsInfo[]
239
- /**
240
- * Does the {AppHost} contain a specific {Shell}
241
- *
242
- * @param {string} name
243
- * @return {boolean}
244
- */
245
- hasShell(name: string): boolean
246
- // TODO: Deprecate
247
- isLazyEntryPoint(name: string): boolean
248
- /**
249
- * Dynamically add {Shell}s after the host is created
250
- *
251
- * @param {EntryPointOrPackage[]} entryPointsOrPackages New packages or entry points to be added to the {AppHost}
252
- * @return {Promise<void>}
253
- */
254
- addShells(entryPointsOrPackages: EntryPointOrPackage[]): Promise<void>
255
- /**
256
- * Dynamically remove {Shell}s after the host is created
257
- *
258
- * @param {string[]} names {Shell} names to be removed
259
- * @return {Promise<void>}
260
- */
261
- removeShells(names: string[]): Promise<void>
262
- onShellsChanged(callback: ShellsChangedCallback): string
263
- removeShellsChangedCallback(callbackId: string): void
264
- readonly log: HostLogger
265
- readonly options: AppHostOptions
266
- }
267
-
268
- export interface PrivateAppHost extends AppHost {
269
- executeWhenFree(identifier: string, callback: () => void): void
270
- }
271
-
272
- export interface MonitoringOptions {
273
- enablePerformance?: boolean
274
- readonly disableMonitoring?: boolean
275
- readonly disableMemoization?: boolean
276
- readonly debugMemoization?: boolean
277
- }
278
-
279
- export interface Trace {
280
- name: string
281
- duration: number
282
- startTime: number
283
- res: any
284
- args: any[]
285
- }
286
-
287
- export interface APILayer {
288
- level: number
289
- name: string
290
- }
291
-
292
- export interface AppHostOptions {
293
- readonly logger?: HostLogger
294
- readonly monitoring: MonitoringOptions
295
- readonly layers?: APILayer[] | APILayer[][]
296
- readonly disableLayersValidation?: boolean
297
- readonly disableCheckCircularDependencies?: boolean
298
- readonly enableStickyErrorBoundaries?: boolean
299
- readonly enableReduxDevtoolsExtension?: boolean
300
- readonly experimentalCyclicMode?: boolean
301
- readonly shouldScopeReducers?: boolean
302
- }
303
-
304
- export interface MemoizeMissHit {
305
- miss: number
306
- calls: number
307
- hit: number
308
- printHitMiss(): void
309
- }
310
-
311
- export type enrichedMemoizationFunction = MemoizeMissHit & AnyFunction & _.MemoizedFunction
312
-
313
- export interface StatisticsMemoization {
314
- func: enrichedMemoizationFunction
315
- name: string
316
- }
317
-
318
- export interface ContributeAPIOptions<TAPI> {
319
- includesNamespaces?: boolean
320
- disableMonitoring?: boolean | (keyof TAPI)[]
321
- }
322
-
323
- export type StateObserverUnsubscribe = () => void
324
- export type StateObserver<TSelectorAPI> = (next: TSelectorAPI) => void
325
- export interface ObservableState<TSelectorAPI> {
326
- subscribe(fromShell: Shell, callback: StateObserver<TSelectorAPI>): StateObserverUnsubscribe
327
- current(allowUnsafeReading?: boolean): TSelectorAPI
328
- }
329
-
330
- export type AnyFunction = (...args: any[]) => any
331
- export type FunctionWithSameArgs<F extends AnyFunction> = (...args: Parameters<F>) => any
332
-
333
- export interface Lazy<T> {
334
- get(): T
335
- }
336
-
337
- /**
338
- * An scoped communication terminal provided for an {EntryPoint}
339
- * in order to contribute its application content to the {AppHost}
340
- *
341
- * @export
342
- * @interface Shell
343
- * @extends {(Pick<AppHost, Exclude<keyof AppHost, 'getStore' | 'log' | 'options'>>)}
344
- */
345
- export interface Shell extends Pick<AppHost, Exclude<keyof AppHost, 'getStore' | 'log' | 'options'>> {
346
- /**
347
- * Are APIs ready to be requested
348
- *
349
- * @return {*} {boolean}
350
- */
351
- canUseAPIs(): boolean
352
- /**
353
- * Is store ready to be requested
354
- *
355
- * @return {*} {boolean}
356
- */
357
- canUseStore(): boolean
358
- /**
359
- * Did the execution of {EntryPoint}s' lifecycle phases (attach, detach) are done
360
- *
361
- * @return {*} {boolean}
362
- */
363
- wasInitializationCompleted(): boolean
364
- runLateInitializer<T>(initializer: () => T): T
365
- /**
366
- * Create an {ExtensionSlot}
367
- *
368
- * @template TItem
369
- * @param {SlotKey<TItem>} key Key that will represent the slot (an will be used for retrieval)
370
- * @return {ExtensionSlot<TItem>} Actual slot
371
- */
372
- declareSlot<TItem>(key: SlotKey<TItem>): ExtensionSlot<TItem>
373
- declareCustomSlot<TItem>(key: SlotKey<TItem>, handler: CustomExtensionSlotHandler<TItem>): CustomExtensionSlot<TItem>
374
-
375
- // TODO: Fix contributeAPI factory type not to resort to lowest common
376
- /**
377
- * Contribute an implementation of an API (a.k.a contract)
378
- *
379
- * @template TAPI
380
- * @param {SlotKey<TAPI>} key API Key that represents an interface TAPI
381
- * @param {() => TAPI} factory Create an implementation of TAPI
382
- * @param {ContributeAPIOptions<TAPI>} [options] Contribution options {ContributeAPIOptions}
383
- * @return {TAPI} Result of the factory execution
384
- */
385
- contributeAPI<TAPI>(key: SlotKey<TAPI>, factory: () => TAPI, options?: ContributeAPIOptions<TAPI>): TAPI
386
- /**
387
- * Contribute a Redux reducer that will be added to the host store.
388
- * Use it for slowly changing state (e.g. not changing because of mouse movement)
389
- *
390
- * @template TState
391
- * @param {ReducersMapObjectContributor<TState>} contributor
392
- */
393
- contributeState<TState, TAction extends Redux.AnyAction = Redux.AnyAction>(
394
- contributor: ReducersMapObjectContributor<TState, TAction>
395
- ): void
396
-
397
- /**
398
- * Contribute a Redux reducer that will be added to the host store
399
- * Use it for rapidly changing state (e.g. changing on every mouse movement event)
400
- * Changes to this state won't trigger the usual subscribers.
401
- * In order to subscribe to changes in this state, use the observer object returned by this function.
402
- *
403
- * @template TState
404
- * @param {ReducersMapObjectContributor<TState>} contributor
405
- * @return {TAPI} Observer object for subscribing to state changes. The observer can also be passed to {connectWithShell}.
406
- */
407
- contributeObservableState<TState, TSelector, TAction extends Redux.AnyAction = Redux.AnyAction>(
408
- contributor: ReducersMapObjectContributor<TState, TAction>,
409
- selectorFactory: (state: TState) => TSelector
410
- ): ObservableState<TSelector>
411
-
412
- /**
413
- * Contribute the main view (root) of the application
414
- * Intended to be used by a single {Shell} in an application
415
- *
416
- * @param {Shell} fromShell Who owns the main view
417
- * @param {ReactComponentContributor} contributor Create the main view component
418
- */
419
- contributeMainView(fromShell: Shell, contributor: ReactComponentContributor): void
420
- contributeBoundaryAspect(component: ShellBoundaryAspect): void
421
- /**
422
- * Create a function with internal cache until any state change in the {AppHost} store
423
- *
424
- * @template T
425
- * @param {T} func Function to build cache for
426
- * @param {FunctionWithSameArgs<T>} resolver Key creator to index results by
427
- * @param {() => boolean} [shouldClear] Custom clear condition (if not provided, behaves like () => true)
428
- * @return {*} {(((...args: Parameters<T>) => ReturnType<T>) & Partial<_.MemoizedFunction> & Partial<MemoizeMissHit>)}
429
- */
430
- memoizeForState<T extends AnyFunction>(
431
- func: T,
432
- resolver: FunctionWithSameArgs<T>,
433
- shouldClear?: () => boolean
434
- ): ((...args: Parameters<T>) => ReturnType<T>) & Partial<_.MemoizedFunction> & Partial<MemoizeMissHit>
435
- /**
436
- * Manually trigger clear condition for function memoized with {Shell.memoizeForState}
437
- */
438
- flushMemoizedForState(): void
439
- /**
440
- * Create a function with internal cache
441
- *
442
- * @template T
443
- * @param {T} func Function to build cache for
444
- * @param {FunctionWithSameArgs<T>} resolver Key creator to index results by
445
- * @return {*} {(((...args: Parameters<T>) => ReturnType<T>) & Partial<_.MemoizedFunction> & Partial<MemoizeMissHit>)}
446
- */
447
- memoize<T extends AnyFunction>(
448
- func: T,
449
- resolver: FunctionWithSameArgs<T>
450
- ): ((...args: Parameters<T>) => ReturnType<T>) & Partial<_.MemoizedFunction> & Partial<MemoizeMissHit>
451
- /**
452
- * Clear cache of a memoized function
453
- *
454
- * @param {(Partial<_.MemoizedFunction> & Partial<MemoizeMissHit>)} memoizedFunction
455
- */
456
- clearCache(memoizedFunction: Partial<_.MemoizedFunction> & Partial<MemoizeMissHit>): void
457
- /**
458
- * Creates a lazy-evaluated value. The function `func` is only executed once when `get` is called for the first time,
459
- * and the result is cached for subsequent calls.
460
- *
461
- * @template T
462
- * @param {F} func - The function that will be lazily evaluated. It should not take any arguments.
463
- * @returns {Lazy<T>} An object with a `get` method that returns the lazily evaluated value of type `T`.
464
- */
465
- lazyEvaluator<F extends AnyFunction, T extends ReturnType<F>>(func: F): Lazy<T>
466
- }
467
-
468
- export interface PrivateShell extends Shell {
469
- readonly entryPoint: EntryPoint
470
- setDependencyAPIs(APIs: AnySlotKey[]): void
471
- setLifecycleState(enableStore: boolean, enableAPIs: boolean, initCompleted: boolean): void
472
- getBoundaryAspects(): ShellBoundaryAspect[]
473
- getHostOptions(): AppHostOptions
474
- wrapWithShellRenderer(component: JSX.Element): JSX.Element
475
- }
476
-
477
- export interface EntryPointsInfo {
478
- readonly name: string
479
- readonly lazy: boolean
480
- readonly attached: boolean
481
- }
482
-
483
- export interface EntryPointInterceptor {
484
- interceptName?(innerName: string): string
485
- interceptTags?(innerTags?: EntryPointTags): EntryPointTags
486
- interceptGetDependencyAPIs?(innerGetDependencyAPIs?: EntryPoint['getDependencyAPIs']): EntryPoint['getDependencyAPIs']
487
- interceptDeclareAPIs?(innerDeclareAPIs?: EntryPoint['declareAPIs']): EntryPoint['declareAPIs']
488
- interceptAttach?(innerAttach?: EntryPoint['attach']): EntryPoint['attach']
489
- interceptDetach?(innerDetach?: EntryPoint['detach']): EntryPoint['detach']
490
- interceptExtend?(innerExtend?: EntryPoint['extend']): EntryPoint['extend']
491
- }
492
-
493
- export type LogSeverity = 'debug' | 'info' | 'event' | 'warning' | 'error' | 'critical'
494
- export type LogSpanFlag = 'begin' | 'end' //TODO:deprecated-kept-for-backward-compat
495
-
496
- export interface HostLogger {
497
- log(severity: LogSeverity, id: string, error?: Error, keyValuePairs?: Object): void
498
- spanChild(messageId: string, keyValuePairs?: Object): ShellLoggerSpan
499
- spanRoot(messageId: string, keyValuePairs?: Object): ShellLoggerSpan
500
- }
501
-
502
- export interface ShellLogger extends HostLogger {
503
- debug(messageId: string, keyValuePairs?: Object): void
504
- info(messageId: string, keyValuePairs?: Object): void
505
- warning(messageId: string, keyValuePairs?: Object): void
506
- error(messageId: string, error?: Error, keyValuePairs?: Object): void
507
- critical(messageId: string, error?: Error, keyValuePairs?: Object): void
508
- spanChild(messageId: string, keyValuePairs?: Object): ShellLoggerSpan
509
- spanRoot(messageId: string, keyValuePairs?: Object): ShellLoggerSpan
510
- monitor<T>(messageId: string, keyValuePairs: Object, monitoredCode: () => T): T
511
- }
512
-
513
- export interface ShellLoggerSpan {
514
- end(success: boolean, error?: Error, keyValuePairs?: Object): void
515
- }
31
+ }