forked from tylerbutler/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
codeLoaderBundle.ts
62 lines (55 loc) · 2 KB
/
codeLoaderBundle.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
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import { ITelemetryBaseLogger } from "@fluidframework/common-definitions";
import { ICodeDetailsLoader, IContainer } from "@fluidframework/container-definitions";
import { FluidObject } from "@fluidframework/core-interfaces";
/**
* Contract that defines the necessary exports for the bundle provided at runtime
* For an example, see "src/test/sampleCodeLoaders/sampleCodeLoader.ts"
*/
export interface ICodeLoaderBundle {
/**
* Fluid export of all the required objects and functions
*/
fluidExport: Promise<IFluidFileConverter>;
}
/**
* Instance that holds all the details for Fluid file conversion
*/
export interface IFluidFileConverter {
/**
* Get code loader details to provide at Loader creation
* @param logger - created logger object to pass to code loader
*/
getCodeLoader(logger: ITelemetryBaseLogger): Promise<ICodeDetailsLoader>;
/**
* Get scope object to provide at Loader creation
* @param logger - created logger object to pass to scope object
*/
getScope?(logger: ITelemetryBaseLogger): Promise<FluidObject>;
/**
* Executes code on container and returns the result
* @param container - container created by this application
* @param options - additional options
*/
execute(container: IContainer, options?: string): Promise<string>;
}
/**
* Type cast to ensure necessary methods are present in the provided bundle
* @param bundle - bundle provided to this application
*/
export function isCodeLoaderBundle(bundle: any): bundle is ICodeLoaderBundle {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return bundle?.fluidExport && typeof bundle.fluidExport === "object";
}
export function isFluidFileConverter(obj: any): obj is IFluidFileConverter {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return (
obj?.getCodeLoader &&
typeof obj.getCodeLoader === "function" &&
obj.execute &&
typeof obj.execute === "function"
);
}