@fluidframework/fluid-runner 2.0.0-dev-rc.1.0.0.224419
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/.eslintrc.cjs +17 -0
- package/.mocharc.js +12 -0
- package/CHANGELOG.md +120 -0
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/api-extractor-lint.json +13 -0
- package/api-extractor.json +17 -0
- package/api-report/fluid-runner.api.md +89 -0
- package/bin/fluid-runner +2 -0
- package/dist/codeLoaderBundle.d.ts +46 -0
- package/dist/codeLoaderBundle.d.ts.map +1 -0
- package/dist/codeLoaderBundle.js +25 -0
- package/dist/codeLoaderBundle.js.map +1 -0
- package/dist/exportFile.d.ts +33 -0
- package/dist/exportFile.d.ts.map +1 -0
- package/dist/exportFile.js +120 -0
- package/dist/exportFile.js.map +1 -0
- package/dist/fakeUrlResolver.d.ts +15 -0
- package/dist/fakeUrlResolver.d.ts.map +1 -0
- package/dist/fakeUrlResolver.js +43 -0
- package/dist/fakeUrlResolver.js.map +1 -0
- package/dist/fluid-runner-alpha.d.ts +79 -0
- package/dist/fluid-runner-beta.d.ts +52 -0
- package/dist/fluid-runner-public.d.ts +52 -0
- package/dist/fluid-runner-untrimmed.d.ts +175 -0
- package/dist/fluidRunner.d.ts +11 -0
- package/dist/fluidRunner.d.ts.map +1 -0
- package/dist/fluidRunner.js +126 -0
- package/dist/fluidRunner.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/logger/baseFileLogger.d.ts +28 -0
- package/dist/logger/baseFileLogger.d.ts.map +1 -0
- package/dist/logger/baseFileLogger.js +76 -0
- package/dist/logger/baseFileLogger.js.map +1 -0
- package/dist/logger/csvFileLogger.d.ts +18 -0
- package/dist/logger/csvFileLogger.d.ts.map +1 -0
- package/dist/logger/csvFileLogger.js +64 -0
- package/dist/logger/csvFileLogger.js.map +1 -0
- package/dist/logger/fileLogger.d.ts +44 -0
- package/dist/logger/fileLogger.d.ts.map +1 -0
- package/dist/logger/fileLogger.js +18 -0
- package/dist/logger/fileLogger.js.map +1 -0
- package/dist/logger/jsonFileLogger.d.ts +14 -0
- package/dist/logger/jsonFileLogger.d.ts.map +1 -0
- package/dist/logger/jsonFileLogger.js +48 -0
- package/dist/logger/jsonFileLogger.js.map +1 -0
- package/dist/logger/loggerUtils.d.ts +44 -0
- package/dist/logger/loggerUtils.d.ts.map +1 -0
- package/dist/logger/loggerUtils.js +120 -0
- package/dist/logger/loggerUtils.js.map +1 -0
- package/dist/parseBundleAndExportFile.d.ts +13 -0
- package/dist/parseBundleAndExportFile.d.ts.map +1 -0
- package/dist/parseBundleAndExportFile.js +88 -0
- package/dist/parseBundleAndExportFile.js.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/dist/utils.d.ts +33 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +107 -0
- package/dist/utils.js.map +1 -0
- package/package.json +120 -0
- package/prettier.config.cjs +8 -0
- package/src/codeLoaderBundle.ts +63 -0
- package/src/exportFile.ts +148 -0
- package/src/fakeUrlResolver.ts +54 -0
- package/src/fluidRunner.ts +135 -0
- package/src/index.ts +18 -0
- package/src/logger/baseFileLogger.ts +58 -0
- package/src/logger/csvFileLogger.ts +40 -0
- package/src/logger/fileLogger.ts +51 -0
- package/src/logger/jsonFileLogger.ts +27 -0
- package/src/logger/loggerUtils.ts +108 -0
- package/src/parseBundleAndExportFile.ts +92 -0
- package/src/utils.ts +100 -0
- package/tsconfig.json +13 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid/minimal"), "prettier"],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
10
|
+
},
|
|
11
|
+
rules: {
|
|
12
|
+
"@typescript-eslint/no-non-null-assertion": "off",
|
|
13
|
+
"@typescript-eslint/no-use-before-define": "off",
|
|
14
|
+
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
15
|
+
"import/no-nodejs-modules": "off",
|
|
16
|
+
},
|
|
17
|
+
};
|
package/.mocharc.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const getFluidTestMochaConfig = require("@fluidframework/mocha-test-setup/mocharc-common");
|
|
9
|
+
|
|
10
|
+
const packageDir = __dirname;
|
|
11
|
+
const config = getFluidTestMochaConfig(packageDir);
|
|
12
|
+
module.exports = config;
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @fluidframework/fluid-runner
|
|
2
|
+
|
|
3
|
+
## 2.0.0-internal.8.0.0
|
|
4
|
+
|
|
5
|
+
Dependency updates only.
|
|
6
|
+
|
|
7
|
+
## 2.0.0-internal.7.4.0
|
|
8
|
+
|
|
9
|
+
Dependency updates only.
|
|
10
|
+
|
|
11
|
+
## 2.0.0-internal.7.3.0
|
|
12
|
+
|
|
13
|
+
Dependency updates only.
|
|
14
|
+
|
|
15
|
+
## 2.0.0-internal.7.2.0
|
|
16
|
+
|
|
17
|
+
Dependency updates only.
|
|
18
|
+
|
|
19
|
+
## 2.0.0-internal.7.1.0
|
|
20
|
+
|
|
21
|
+
Dependency updates only.
|
|
22
|
+
|
|
23
|
+
## 2.0.0-internal.7.0.0
|
|
24
|
+
|
|
25
|
+
### Major Changes
|
|
26
|
+
|
|
27
|
+
- test-utils: provideEntryPoint is required [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
|
|
28
|
+
|
|
29
|
+
The optional `provideEntryPoint` method has become required on a number of constructors. A value will need to be provided to the following classes:
|
|
30
|
+
|
|
31
|
+
- `BaseContainerRuntimeFactory`
|
|
32
|
+
- `RuntimeFactory`
|
|
33
|
+
- `ContainerRuntime` (constructor and `loadRuntime`)
|
|
34
|
+
- `FluidDataStoreRuntime`
|
|
35
|
+
|
|
36
|
+
See [testContainerRuntimeFactoryWithDefaultDataStore.ts](https://github.com/microsoft/FluidFramework/tree/main/packages/test/test-utils/src/testContainerRuntimeFactoryWithDefaultDataStore.ts) for an example implemtation of `provideEntryPoint` for ContainerRuntime.
|
|
37
|
+
See [pureDataObjectFactory.ts](https://github.com/microsoft/FluidFramework/tree/main/packages/framework/aqueduct/src/data-object-factories/pureDataObjectFactory.ts#L83) for an example implementation of `provideEntryPoint` for DataStoreRuntime.
|
|
38
|
+
|
|
39
|
+
Subsequently, various `entryPoint` and `getEntryPoint()` endpoints have become required. Please see [containerRuntime.ts](https://github.com/microsoft/FluidFramework/tree/main/packages/runtime/container-runtime/src/containerRuntime.ts) for example implementations of these APIs.
|
|
40
|
+
|
|
41
|
+
For more details, see [Removing-IFluidRouter.md](https://github.com/microsoft/FluidFramework/blob/main/packages/common/core-interfaces/Removing-IFluidRouter.md)
|
|
42
|
+
|
|
43
|
+
- Minimum TypeScript version now 5.1.6 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
|
|
44
|
+
|
|
45
|
+
The minimum supported TypeScript version for Fluid 2.0 clients is now 5.1.6.
|
|
46
|
+
|
|
47
|
+
## 2.0.0-internal.6.4.0
|
|
48
|
+
|
|
49
|
+
Dependency updates only.
|
|
50
|
+
|
|
51
|
+
## 2.0.0-internal.6.3.0
|
|
52
|
+
|
|
53
|
+
Dependency updates only.
|
|
54
|
+
|
|
55
|
+
## 2.0.0-internal.6.2.0
|
|
56
|
+
|
|
57
|
+
### Minor Changes
|
|
58
|
+
|
|
59
|
+
- Remove use of @fluidframework/common-definitions ([#16638](https://github.com/microsoft/FluidFramework/issues/16638)) [a8c81509c9](https://github.com/microsoft/FluidFramework/commits/a8c81509c9bf09cfb2092ebcf7265205f9eb6dbf)
|
|
60
|
+
|
|
61
|
+
The **@fluidframework/common-definitions** package is being deprecated, so the following interfaces and types are now
|
|
62
|
+
imported from the **@fluidframework/core-interfaces** package:
|
|
63
|
+
|
|
64
|
+
- interface IDisposable
|
|
65
|
+
- interface IErrorEvent
|
|
66
|
+
- interface IErrorEvent
|
|
67
|
+
- interface IEvent
|
|
68
|
+
- interface IEventProvider
|
|
69
|
+
- interface ILoggingError
|
|
70
|
+
- interface ITaggedTelemetryPropertyType
|
|
71
|
+
- interface ITelemetryBaseEvent
|
|
72
|
+
- interface ITelemetryBaseLogger
|
|
73
|
+
- interface ITelemetryErrorEvent
|
|
74
|
+
- interface ITelemetryGenericEvent
|
|
75
|
+
- interface ITelemetryLogger
|
|
76
|
+
- interface ITelemetryPerformanceEvent
|
|
77
|
+
- interface ITelemetryProperties
|
|
78
|
+
- type ExtendEventProvider
|
|
79
|
+
- type IEventThisPlaceHolder
|
|
80
|
+
- type IEventTransformer
|
|
81
|
+
- type ReplaceIEventThisPlaceHolder
|
|
82
|
+
- type ReplaceIEventThisPlaceHolder
|
|
83
|
+
- type TelemetryEventCategory
|
|
84
|
+
- type TelemetryEventPropertyType
|
|
85
|
+
|
|
86
|
+
## 2.0.0-internal.6.1.0
|
|
87
|
+
|
|
88
|
+
Dependency updates only.
|
|
89
|
+
|
|
90
|
+
## 2.0.0-internal.6.0.0
|
|
91
|
+
|
|
92
|
+
Dependency updates only.
|
|
93
|
+
|
|
94
|
+
## 2.0.0-internal.5.4.0
|
|
95
|
+
|
|
96
|
+
Dependency updates only.
|
|
97
|
+
|
|
98
|
+
## 2.0.0-internal.5.3.0
|
|
99
|
+
|
|
100
|
+
Dependency updates only.
|
|
101
|
+
|
|
102
|
+
## 2.0.0-internal.5.2.0
|
|
103
|
+
|
|
104
|
+
Dependency updates only.
|
|
105
|
+
|
|
106
|
+
## 2.0.0-internal.5.1.0
|
|
107
|
+
|
|
108
|
+
Dependency updates only.
|
|
109
|
+
|
|
110
|
+
## 2.0.0-internal.5.0.0
|
|
111
|
+
|
|
112
|
+
Dependency updates only.
|
|
113
|
+
|
|
114
|
+
## 2.0.0-internal.4.4.0
|
|
115
|
+
|
|
116
|
+
Dependency updates only.
|
|
117
|
+
|
|
118
|
+
## 2.0.0-internal.4.1.0
|
|
119
|
+
|
|
120
|
+
Dependency updates only.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @fluidframework/fluid-runner
|
|
2
|
+
|
|
3
|
+
This package contains utility for running various functionality inside a Fluid Framework environment.
|
|
4
|
+
|
|
5
|
+
## Export File
|
|
6
|
+
|
|
7
|
+
Allows some execution to be made on a container given a provided ODSP snapshot.
|
|
8
|
+
|
|
9
|
+
### Sample command
|
|
10
|
+
|
|
11
|
+
If package is installed globally:
|
|
12
|
+
`node fluid-runner exportFile --codeLoader=compiledBundle.js --inputFile=inputFileName.fluid --outputFile=result.txt --telemetryFile=telemetryFile.txt`
|
|
13
|
+
|
|
14
|
+
If working directly on this package:
|
|
15
|
+
`node bin/fluid-runner exportFile --codeLoader=compiledBundle.js --inputFile=inputFileName.fluid --outputFile=result.txt --telemetryFile=telemetryFile.txt`
|
|
16
|
+
|
|
17
|
+
### Code Loader bundle format
|
|
18
|
+
|
|
19
|
+
The Code Loader bundle should provide defined exports required for this functionality.
|
|
20
|
+
For more details on what exports are needed, see [codeLoaderBundle.ts](./src/codeLoaderBundle.ts).
|
|
21
|
+
|
|
22
|
+
#### "codeLoader" vs "IFluidFileConverter" argument
|
|
23
|
+
|
|
24
|
+
You may notice the command line argument `codeLoader` is optional. If you choose not to provide a value for `codeLoader`, you must extend this library
|
|
25
|
+
and provide a [`IFluidFileConverter`](./src/codeLoaderBundle.ts) implementation to the [`fluidRunner(...)`](./src/fluidRunner.ts) method.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { fluidRunner } from "@fluidframework/fluid-runner";
|
|
29
|
+
|
|
30
|
+
fluidRunner({
|
|
31
|
+
/* IFluidFileConverter implementation here */
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
> **Note**: Only one of `codeLoader` or `fluidRunner(...)` argument is allowed. If both or none are provided, an error will be thrown at the start of execution.
|
|
36
|
+
|
|
37
|
+
### Input file format
|
|
38
|
+
|
|
39
|
+
The input file is expected to be an ODSP snapshot.
|
|
40
|
+
For some examples, see the files in the [localOdspSnapshots folder](./src/test/localOdspSnapshots).
|
|
41
|
+
|
|
42
|
+
### Telemetry format
|
|
43
|
+
|
|
44
|
+
There is an optional command line option `telemetryFormat` that allows you to specify the telemetry output format. The naming provided to this option is strict and must match an option in [OutputFormat](./src/logger/fileLogger.ts).
|
|
45
|
+
The default format is currently `JSON`
|
|
46
|
+
|
|
47
|
+
### Additional telemetry properties
|
|
48
|
+
|
|
49
|
+
There is an optional command line option `telemetryProp` that allows you to specify additional properties that will be added to every telemetry entry. The format follows these rules:
|
|
50
|
+
|
|
51
|
+
- every key must be a string
|
|
52
|
+
- values may be either a string or a number
|
|
53
|
+
- keys and values cannot be empty
|
|
54
|
+
|
|
55
|
+
Example of valid usages:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
--telemetryProp prop1 value1 --telemetryProp prop2 10.5
|
|
59
|
+
--telemetryProp " prop1 " " value1 " prop2 value2
|
|
60
|
+
--telemetryProp prop1 "aaa=bbb" prop2 "aaa\"bbb"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
> No trimming of white-space inside quotes
|
|
64
|
+
|
|
65
|
+
Example of invalid usages:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
--telemetryProp "10" value1
|
|
69
|
+
--telemetryProp prop1
|
|
70
|
+
--telemetryProp= // this will be treated as ['']
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Consumption
|
|
74
|
+
|
|
75
|
+
The code around `exportFile` can be consumed in multiple different layers. It is not necessary to run all this code fully as is, and the following are some interesting code bits involved in this workflow:
|
|
76
|
+
|
|
77
|
+
- [`createLogger(...)`](./src/logger/loggerUtils.ts)
|
|
78
|
+
- Creates and wraps an `IFileLogger` and adds some useful telemetry data to every entry
|
|
79
|
+
- [`createContainerAndExecute(...)`](./src/exportFile.ts)
|
|
80
|
+
- This is the core logic for running some action based on a local ODSP snapshot
|
|
81
|
+
- [`getSnapshotFileContent(...)`](./src/utils.ts)
|
|
82
|
+
- Reads a local ODSP snapshot from both JSON and binary formats for usage in `createContainerAndExecute(...)`
|
|
83
|
+
|
|
84
|
+
For an example of a consumption path that differs slightly to [`exportFile(...)`](./src/exportFile.ts), see [`parseBundleAndExportFile(...)`](./src/parseBundleAndExportFile.ts). In addition to running the same logic as [`exportFile`](./src/exportFile.ts) method, it implements the logic around parsing a dynamically provided bundle path into an `IFluidFileConverter` object.
|
|
85
|
+
|
|
86
|
+
<!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
|
|
87
|
+
|
|
88
|
+
<!-- prettier-ignore-start -->
|
|
89
|
+
<!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
|
|
90
|
+
|
|
91
|
+
## Trademark
|
|
92
|
+
|
|
93
|
+
This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
|
|
94
|
+
|
|
95
|
+
Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
|
|
96
|
+
|
|
97
|
+
Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
|
|
98
|
+
|
|
99
|
+
<!-- prettier-ignore-end -->
|
|
100
|
+
|
|
101
|
+
<!-- AUTO-GENERATED-CONTENT:END -->
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "../../../common/build/build-common/api-extractor-lint.json",
|
|
4
|
+
"messages": {
|
|
5
|
+
"extractorMessageReporting": {
|
|
6
|
+
// TODO: remove once base config has this enabled as an error
|
|
7
|
+
"ae-incompatible-release-tags": {
|
|
8
|
+
"logLevel": "error",
|
|
9
|
+
"addToApiReportFile": false
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
+
"extends": "../../../common/build/build-common/api-extractor-base.json",
|
|
4
|
+
"messages": {
|
|
5
|
+
"extractorMessageReporting": {
|
|
6
|
+
// TODO: fix violations and remove overrides
|
|
7
|
+
"ae-forgotten-export": {
|
|
8
|
+
"logLevel": "warning",
|
|
9
|
+
"addToApiReportFile": true
|
|
10
|
+
},
|
|
11
|
+
"ae-unresolved-link": {
|
|
12
|
+
"logLevel": "warning",
|
|
13
|
+
"addToApiReportFile": true
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
## API Report File for "@fluidframework/fluid-runner"
|
|
2
|
+
|
|
3
|
+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
|
|
9
|
+
import { FluidObject } from '@fluidframework/core-interfaces';
|
|
10
|
+
import { ICodeDetailsLoader } from '@fluidframework/container-definitions';
|
|
11
|
+
import { IContainer } from '@fluidframework/container-definitions';
|
|
12
|
+
import { ITelemetryBaseLogger } from '@fluidframework/core-interfaces';
|
|
13
|
+
import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
|
|
14
|
+
|
|
15
|
+
// @internal
|
|
16
|
+
export function createContainerAndExecute(localOdspSnapshot: string | Uint8Array, fluidFileConverter: IFluidFileConverter, logger: ITelemetryLoggerExt, options?: string, timeout?: number, disableNetworkFetch?: boolean): Promise<string>;
|
|
17
|
+
|
|
18
|
+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: The package "@fluidframework/fluid-runner" does not have an export "IFileLogger"
|
|
19
|
+
//
|
|
20
|
+
// @internal
|
|
21
|
+
export function createLogger(filePath: string, options?: ITelemetryOptions): {
|
|
22
|
+
logger: ITelemetryLoggerExt;
|
|
23
|
+
fileLogger: IFileLogger;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// @internal
|
|
27
|
+
export function exportFile(fluidFileConverter: IFluidFileConverter, inputFile: string, outputFile: string, telemetryFile: string, options?: string, telemetryOptions?: ITelemetryOptions, timeout?: number, disableNetworkFetch?: boolean): Promise<IExportFileResponse>;
|
|
28
|
+
|
|
29
|
+
// @internal (undocumented)
|
|
30
|
+
export function fluidRunner(fluidFileConverter?: IFluidFileConverter): void;
|
|
31
|
+
|
|
32
|
+
// @internal
|
|
33
|
+
export function getSnapshotFileContent(filePath: string): string | Buffer;
|
|
34
|
+
|
|
35
|
+
// @internal
|
|
36
|
+
export function getTelemetryFileValidationError(telemetryFile: string): string | undefined;
|
|
37
|
+
|
|
38
|
+
// @internal
|
|
39
|
+
export interface ICodeLoaderBundle {
|
|
40
|
+
fluidExport: Promise<IFluidFileConverter>;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Warning: (ae-forgotten-export) The symbol "IExportFileResponseSuccess" needs to be exported by the entry point index.d.ts
|
|
44
|
+
// Warning: (ae-forgotten-export) The symbol "IExportFileResponseFailure" needs to be exported by the entry point index.d.ts
|
|
45
|
+
//
|
|
46
|
+
// @alpha (undocumented)
|
|
47
|
+
export type IExportFileResponse = IExportFileResponseSuccess | IExportFileResponseFailure;
|
|
48
|
+
|
|
49
|
+
// @alpha
|
|
50
|
+
export interface IFluidFileConverter {
|
|
51
|
+
execute(container: IContainer, options?: string): Promise<string>;
|
|
52
|
+
getCodeLoader(logger: ITelemetryBaseLogger): Promise<ICodeDetailsLoader>;
|
|
53
|
+
getScope?(logger: ITelemetryBaseLogger): Promise<FluidObject>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// @internal
|
|
57
|
+
export interface ITelemetryOptions {
|
|
58
|
+
defaultProps?: Record<string, string | number>;
|
|
59
|
+
eventsPerFlush?: number;
|
|
60
|
+
outputFormat?: OutputFormat;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// @alpha
|
|
64
|
+
export enum OutputFormat {
|
|
65
|
+
// (undocumented)
|
|
66
|
+
CSV = 1,
|
|
67
|
+
// (undocumented)
|
|
68
|
+
JSON = 0
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// @internal
|
|
72
|
+
export function parseBundleAndExportFile(codeLoader: string, inputFile: string, outputFile: string, telemetryFile: string, options?: string, telemetryOptions?: ITelemetryOptions, timeout?: number, disableNetworkFetch?: boolean): Promise<IExportFileResponse>;
|
|
73
|
+
|
|
74
|
+
// @internal
|
|
75
|
+
export function validateAndParseTelemetryOptions(format?: string, props?: (string | number)[], eventsPerFlush?: number): {
|
|
76
|
+
success: false;
|
|
77
|
+
error: string;
|
|
78
|
+
} | {
|
|
79
|
+
success: true;
|
|
80
|
+
telemetryOptions: ITelemetryOptions;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Warnings were encountered during analysis:
|
|
84
|
+
//
|
|
85
|
+
// src/logger/loggerUtils.ts:29:35 - (ae-forgotten-export) The symbol "IFileLogger" needs to be exported by the entry point index.d.ts
|
|
86
|
+
|
|
87
|
+
// (No @packageDocumentation comment for this package)
|
|
88
|
+
|
|
89
|
+
```
|
package/bin/fluid-runner
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ICodeDetailsLoader, IContainer } from "@fluidframework/container-definitions";
|
|
6
|
+
import { ITelemetryBaseLogger, FluidObject } from "@fluidframework/core-interfaces";
|
|
7
|
+
/**
|
|
8
|
+
* Contract that defines the necessary exports for the bundle provided at runtime
|
|
9
|
+
* For an example, see "src/test/sampleCodeLoaders/sampleCodeLoader.ts"
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export interface ICodeLoaderBundle {
|
|
13
|
+
/**
|
|
14
|
+
* Fluid export of all the required objects and functions
|
|
15
|
+
*/
|
|
16
|
+
fluidExport: Promise<IFluidFileConverter>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Instance that holds all the details for Fluid file conversion
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export interface IFluidFileConverter {
|
|
23
|
+
/**
|
|
24
|
+
* Get code loader details to provide at Loader creation
|
|
25
|
+
* @param logger - created logger object to pass to code loader
|
|
26
|
+
*/
|
|
27
|
+
getCodeLoader(logger: ITelemetryBaseLogger): Promise<ICodeDetailsLoader>;
|
|
28
|
+
/**
|
|
29
|
+
* Get scope object to provide at Loader creation
|
|
30
|
+
* @param logger - created logger object to pass to scope object
|
|
31
|
+
*/
|
|
32
|
+
getScope?(logger: ITelemetryBaseLogger): Promise<FluidObject>;
|
|
33
|
+
/**
|
|
34
|
+
* Executes code on container and returns the result
|
|
35
|
+
* @param container - container created by this application
|
|
36
|
+
* @param options - additional options
|
|
37
|
+
*/
|
|
38
|
+
execute(container: IContainer, options?: string): Promise<string>;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Type cast to ensure necessary methods are present in the provided bundle
|
|
42
|
+
* @param bundle - bundle provided to this application
|
|
43
|
+
*/
|
|
44
|
+
export declare function isCodeLoaderBundle(bundle: any): bundle is ICodeLoaderBundle;
|
|
45
|
+
export declare function isFluidFileConverter(obj: any): obj is IFluidFileConverter;
|
|
46
|
+
//# sourceMappingURL=codeLoaderBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeLoaderBundle.d.ts","sourceRoot":"","sources":["../src/codeLoaderBundle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAEpF;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,WAAW,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEzE;;;OAGG;IACH,QAAQ,CAAC,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAE9D;;;;OAIG;IACH,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAClE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,iBAAiB,CAG3E;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,mBAAmB,CAQzE"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isFluidFileConverter = exports.isCodeLoaderBundle = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* Type cast to ensure necessary methods are present in the provided bundle
|
|
10
|
+
* @param bundle - bundle provided to this application
|
|
11
|
+
*/
|
|
12
|
+
function isCodeLoaderBundle(bundle) {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
14
|
+
return bundle?.fluidExport && typeof bundle.fluidExport === "object";
|
|
15
|
+
}
|
|
16
|
+
exports.isCodeLoaderBundle = isCodeLoaderBundle;
|
|
17
|
+
function isFluidFileConverter(obj) {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
19
|
+
return (obj?.getCodeLoader &&
|
|
20
|
+
typeof obj.getCodeLoader === "function" &&
|
|
21
|
+
obj.execute &&
|
|
22
|
+
typeof obj.execute === "function");
|
|
23
|
+
}
|
|
24
|
+
exports.isFluidFileConverter = isFluidFileConverter;
|
|
25
|
+
//# sourceMappingURL=codeLoaderBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeLoaderBundle.js","sourceRoot":"","sources":["../src/codeLoaderBundle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA0CH;;;GAGG;AACH,SAAgB,kBAAkB,CAAC,MAAW;IAC7C,+DAA+D;IAC/D,OAAO,MAAM,EAAE,WAAW,IAAI,OAAO,MAAM,CAAC,WAAW,KAAK,QAAQ,CAAC;AACtE,CAAC;AAHD,gDAGC;AAED,SAAgB,oBAAoB,CAAC,GAAQ;IAC5C,+DAA+D;IAC/D,OAAO,CACN,GAAG,EAAE,aAAa;QAClB,OAAO,GAAG,CAAC,aAAa,KAAK,UAAU;QACvC,GAAG,CAAC,OAAO;QACX,OAAO,GAAG,CAAC,OAAO,KAAK,UAAU,CACjC,CAAC;AACH,CAAC;AARD,oDAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ICodeDetailsLoader, IContainer } from \"@fluidframework/container-definitions\";\nimport { ITelemetryBaseLogger, FluidObject } from \"@fluidframework/core-interfaces\";\n\n/**\n * Contract that defines the necessary exports for the bundle provided at runtime\n * For an example, see \"src/test/sampleCodeLoaders/sampleCodeLoader.ts\"\n * @internal\n */\nexport interface ICodeLoaderBundle {\n\t/**\n\t * Fluid export of all the required objects and functions\n\t */\n\tfluidExport: Promise<IFluidFileConverter>;\n}\n\n/**\n * Instance that holds all the details for Fluid file conversion\n * @alpha\n */\nexport interface IFluidFileConverter {\n\t/**\n\t * Get code loader details to provide at Loader creation\n\t * @param logger - created logger object to pass to code loader\n\t */\n\tgetCodeLoader(logger: ITelemetryBaseLogger): Promise<ICodeDetailsLoader>;\n\n\t/**\n\t * Get scope object to provide at Loader creation\n\t * @param logger - created logger object to pass to scope object\n\t */\n\tgetScope?(logger: ITelemetryBaseLogger): Promise<FluidObject>;\n\n\t/**\n\t * Executes code on container and returns the result\n\t * @param container - container created by this application\n\t * @param options - additional options\n\t */\n\texecute(container: IContainer, options?: string): Promise<string>;\n}\n\n/**\n * Type cast to ensure necessary methods are present in the provided bundle\n * @param bundle - bundle provided to this application\n */\nexport function isCodeLoaderBundle(bundle: any): bundle is ICodeLoaderBundle {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\treturn bundle?.fluidExport && typeof bundle.fluidExport === \"object\";\n}\n\nexport function isFluidFileConverter(obj: any): obj is IFluidFileConverter {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\treturn (\n\t\tobj?.getCodeLoader &&\n\t\ttypeof obj.getCodeLoader === \"function\" &&\n\t\tobj.execute &&\n\t\ttypeof obj.execute === \"function\"\n\t);\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils";
|
|
6
|
+
import { IFluidFileConverter } from "./codeLoaderBundle";
|
|
7
|
+
import { ITelemetryOptions } from "./logger/fileLogger";
|
|
8
|
+
/**
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export type IExportFileResponse = IExportFileResponseSuccess | IExportFileResponseFailure;
|
|
12
|
+
interface IExportFileResponseSuccess {
|
|
13
|
+
success: true;
|
|
14
|
+
}
|
|
15
|
+
interface IExportFileResponseFailure {
|
|
16
|
+
success: false;
|
|
17
|
+
eventName: string;
|
|
18
|
+
errorMessage: string;
|
|
19
|
+
error?: any;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Execute code on Container based on ODSP snapshot and write result to file
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export declare function exportFile(fluidFileConverter: IFluidFileConverter, inputFile: string, outputFile: string, telemetryFile: string, options?: string, telemetryOptions?: ITelemetryOptions, timeout?: number, disableNetworkFetch?: boolean): Promise<IExportFileResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Create the container based on an ODSP snapshot and execute code on it
|
|
28
|
+
* @returns result of execution
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
31
|
+
export declare function createContainerAndExecute(localOdspSnapshot: string | Uint8Array, fluidFileConverter: IFluidFileConverter, logger: ITelemetryLoggerExt, options?: string, timeout?: number, disableNetworkFetch?: boolean): Promise<string>;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=exportFile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exportFile.d.ts","sourceRoot":"","sources":["../src/exportFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,mBAAmB,EAAoB,MAAM,iCAAiC,CAAC;AAIxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAIzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIxD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,0BAA0B,GAAG,0BAA0B,CAAC;AAE1F,UAAU,0BAA0B;IACnC,OAAO,EAAE,IAAI,CAAC;CACd;AAED,UAAU,0BAA0B;IACnC,OAAO,EAAE,KAAK,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,GAAG,CAAC;CACZ;AAID;;;GAGG;AACH,wBAAsB,UAAU,CAC/B,kBAAkB,EAAE,mBAAmB,EACvC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,aAAa,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,MAAM,EAChB,gBAAgB,CAAC,EAAE,iBAAiB,EACpC,OAAO,CAAC,EAAE,MAAM,EAChB,mBAAmB,CAAC,EAAE,OAAO,GAC3B,OAAO,CAAC,mBAAmB,CAAC,CA0C9B;AAED;;;;GAIG;AACH,wBAAsB,yBAAyB,CAC9C,iBAAiB,EAAE,MAAM,GAAG,UAAU,EACtC,kBAAkB,EAAE,mBAAmB,EACvC,MAAM,EAAE,mBAAmB,EAC3B,OAAO,CAAC,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,EAChB,mBAAmB,GAAE,OAAe,GAClC,OAAO,CAAC,MAAM,CAAC,CA0CjB"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.createContainerAndExecute = exports.exportFile = void 0;
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
33
|
+
const container_definitions_1 = require("@fluidframework/container-definitions");
|
|
34
|
+
const container_loader_1 = require("@fluidframework/container-loader");
|
|
35
|
+
const odsp_driver_1 = require("@fluidframework/odsp-driver");
|
|
36
|
+
const fakeUrlResolver_1 = require("./fakeUrlResolver");
|
|
37
|
+
const utils_1 = require("./utils");
|
|
38
|
+
const loggerUtils_1 = require("./logger/loggerUtils");
|
|
39
|
+
const clientArgsValidationError = "Client_ArgsValidationError";
|
|
40
|
+
/**
|
|
41
|
+
* Execute code on Container based on ODSP snapshot and write result to file
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
async function exportFile(fluidFileConverter, inputFile, outputFile, telemetryFile, options, telemetryOptions, timeout, disableNetworkFetch) {
|
|
45
|
+
const telemetryArgError = (0, loggerUtils_1.getTelemetryFileValidationError)(telemetryFile);
|
|
46
|
+
if (telemetryArgError) {
|
|
47
|
+
const eventName = clientArgsValidationError;
|
|
48
|
+
return { success: false, eventName, errorMessage: telemetryArgError };
|
|
49
|
+
}
|
|
50
|
+
const { fileLogger, logger } = (0, loggerUtils_1.createLogger)(telemetryFile, telemetryOptions);
|
|
51
|
+
try {
|
|
52
|
+
return await telemetry_utils_1.PerformanceEvent.timedExecAsync(logger, { eventName: "ExportFile" }, async () => {
|
|
53
|
+
const argsValidationError = (0, utils_1.getArgsValidationError)(inputFile, outputFile, timeout);
|
|
54
|
+
if (argsValidationError) {
|
|
55
|
+
const eventName = clientArgsValidationError;
|
|
56
|
+
logger.sendErrorEvent({ eventName, message: argsValidationError });
|
|
57
|
+
return { success: false, eventName, errorMessage: argsValidationError };
|
|
58
|
+
}
|
|
59
|
+
fs.writeFileSync(outputFile, await createContainerAndExecute((0, utils_1.getSnapshotFileContent)(inputFile), fluidFileConverter, logger, options, timeout, disableNetworkFetch));
|
|
60
|
+
return { success: true };
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
const eventName = "Client_UnexpectedError";
|
|
65
|
+
logger.sendErrorEvent({ eventName }, error);
|
|
66
|
+
return { success: false, eventName, errorMessage: "Unexpected error", error };
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
await fileLogger.close();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.exportFile = exportFile;
|
|
73
|
+
/**
|
|
74
|
+
* Create the container based on an ODSP snapshot and execute code on it
|
|
75
|
+
* @returns result of execution
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
async function createContainerAndExecute(localOdspSnapshot, fluidFileConverter, logger, options, timeout, disableNetworkFetch = false) {
|
|
79
|
+
const fn = async () => {
|
|
80
|
+
if (disableNetworkFetch) {
|
|
81
|
+
global.fetch = async () => {
|
|
82
|
+
throw new Error("Network fetch is not allowed");
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const loader = new container_loader_1.Loader({
|
|
86
|
+
urlResolver: new fakeUrlResolver_1.FakeUrlResolver(),
|
|
87
|
+
documentServiceFactory: (0, odsp_driver_1.createLocalOdspDocumentServiceFactory)(localOdspSnapshot),
|
|
88
|
+
codeLoader: await fluidFileConverter.getCodeLoader(logger),
|
|
89
|
+
scope: await fluidFileConverter.getScope?.(logger),
|
|
90
|
+
logger,
|
|
91
|
+
});
|
|
92
|
+
const container = await loader.resolve({
|
|
93
|
+
url: "/fakeUrl/",
|
|
94
|
+
headers: {
|
|
95
|
+
[container_definitions_1.LoaderHeader.loadMode]: { opsBeforeReturn: "cached" },
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
return telemetry_utils_1.PerformanceEvent.timedExecAsync(logger, { eventName: "ExportFile" }, async () => {
|
|
99
|
+
try {
|
|
100
|
+
return await fluidFileConverter.execute(container, options);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
container.dispose();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
// eslint-disable-next-line unicorn/prefer-ternary
|
|
108
|
+
if (timeout !== undefined) {
|
|
109
|
+
return (0, utils_1.timeoutPromise)((resolve, reject) => {
|
|
110
|
+
fn()
|
|
111
|
+
.then((value) => resolve(value))
|
|
112
|
+
.catch((error) => reject(error));
|
|
113
|
+
}, timeout);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
return fn();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.createContainerAndExecute = createContainerAndExecute;
|
|
120
|
+
//# sourceMappingURL=exportFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exportFile.js","sourceRoot":"","sources":["../src/exportFile.ts"],"names":[],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport * as fs from \"fs\";\nimport { ITelemetryLoggerExt, PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { LoaderHeader } from \"@fluidframework/container-definitions\";\nimport { Loader } from \"@fluidframework/container-loader\";\nimport { createLocalOdspDocumentServiceFactory } from \"@fluidframework/odsp-driver\";\nimport { IFluidFileConverter } from \"./codeLoaderBundle\";\nimport { FakeUrlResolver } from \"./fakeUrlResolver\";\nimport { getSnapshotFileContent, timeoutPromise, getArgsValidationError } from \"./utils\";\n/* eslint-disable import/no-internal-modules */\nimport { ITelemetryOptions } from \"./logger/fileLogger\";\nimport { createLogger, getTelemetryFileValidationError } from \"./logger/loggerUtils\";\n/* eslint-enable import/no-internal-modules */\n\n/**\n * @alpha\n */\nexport type IExportFileResponse = IExportFileResponseSuccess | IExportFileResponseFailure;\n\ninterface IExportFileResponseSuccess {\n\tsuccess: true;\n}\n\ninterface IExportFileResponseFailure {\n\tsuccess: false;\n\teventName: string;\n\terrorMessage: string;\n\terror?: any;\n}\n\nconst clientArgsValidationError = \"Client_ArgsValidationError\";\n\n/**\n * Execute code on Container based on ODSP snapshot and write result to file\n * @internal\n */\nexport async function exportFile(\n\tfluidFileConverter: IFluidFileConverter,\n\tinputFile: string,\n\toutputFile: string,\n\ttelemetryFile: string,\n\toptions?: string,\n\ttelemetryOptions?: ITelemetryOptions,\n\ttimeout?: number,\n\tdisableNetworkFetch?: boolean,\n): Promise<IExportFileResponse> {\n\tconst telemetryArgError = getTelemetryFileValidationError(telemetryFile);\n\tif (telemetryArgError) {\n\t\tconst eventName = clientArgsValidationError;\n\t\treturn { success: false, eventName, errorMessage: telemetryArgError };\n\t}\n\tconst { fileLogger, logger } = createLogger(telemetryFile, telemetryOptions);\n\n\ttry {\n\t\treturn await PerformanceEvent.timedExecAsync(\n\t\t\tlogger,\n\t\t\t{ eventName: \"ExportFile\" },\n\t\t\tasync () => {\n\t\t\t\tconst argsValidationError = getArgsValidationError(inputFile, outputFile, timeout);\n\t\t\t\tif (argsValidationError) {\n\t\t\t\t\tconst eventName = clientArgsValidationError;\n\t\t\t\t\tlogger.sendErrorEvent({ eventName, message: argsValidationError });\n\t\t\t\t\treturn { success: false, eventName, errorMessage: argsValidationError };\n\t\t\t\t}\n\n\t\t\t\tfs.writeFileSync(\n\t\t\t\t\toutputFile,\n\t\t\t\t\tawait createContainerAndExecute(\n\t\t\t\t\t\tgetSnapshotFileContent(inputFile),\n\t\t\t\t\t\tfluidFileConverter,\n\t\t\t\t\t\tlogger,\n\t\t\t\t\t\toptions,\n\t\t\t\t\t\ttimeout,\n\t\t\t\t\t\tdisableNetworkFetch,\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\t\treturn { success: true };\n\t\t\t},\n\t\t);\n\t} catch (error) {\n\t\tconst eventName = \"Client_UnexpectedError\";\n\t\tlogger.sendErrorEvent({ eventName }, error);\n\t\treturn { success: false, eventName, errorMessage: \"Unexpected error\", error };\n\t} finally {\n\t\tawait fileLogger.close();\n\t}\n}\n\n/**\n * Create the container based on an ODSP snapshot and execute code on it\n * @returns result of execution\n * @internal\n */\nexport async function createContainerAndExecute(\n\tlocalOdspSnapshot: string | Uint8Array,\n\tfluidFileConverter: IFluidFileConverter,\n\tlogger: ITelemetryLoggerExt,\n\toptions?: string,\n\ttimeout?: number,\n\tdisableNetworkFetch: boolean = false,\n): Promise<string> {\n\tconst fn = async () => {\n\t\tif (disableNetworkFetch) {\n\t\t\tglobal.fetch = async () => {\n\t\t\t\tthrow new Error(\"Network fetch is not allowed\");\n\t\t\t};\n\t\t}\n\n\t\tconst loader = new Loader({\n\t\t\turlResolver: new FakeUrlResolver(),\n\t\t\tdocumentServiceFactory: createLocalOdspDocumentServiceFactory(localOdspSnapshot),\n\t\t\tcodeLoader: await fluidFileConverter.getCodeLoader(logger),\n\t\t\tscope: await fluidFileConverter.getScope?.(logger),\n\t\t\tlogger,\n\t\t});\n\n\t\tconst container = await loader.resolve({\n\t\t\turl: \"/fakeUrl/\",\n\t\t\theaders: {\n\t\t\t\t[LoaderHeader.loadMode]: { opsBeforeReturn: \"cached\" },\n\t\t\t},\n\t\t});\n\n\t\treturn PerformanceEvent.timedExecAsync(logger, { eventName: \"ExportFile\" }, async () => {\n\t\t\ttry {\n\t\t\t\treturn await fluidFileConverter.execute(container, options);\n\t\t\t} finally {\n\t\t\t\tcontainer.dispose();\n\t\t\t}\n\t\t});\n\t};\n\n\t// eslint-disable-next-line unicorn/prefer-ternary\n\tif (timeout !== undefined) {\n\t\treturn timeoutPromise<string>((resolve, reject) => {\n\t\t\tfn()\n\t\t\t\t.then((value) => resolve(value))\n\t\t\t\t.catch((error) => reject(error));\n\t\t}, timeout);\n\t} else {\n\t\treturn fn();\n\t}\n}\n"]}
|