@fluidframework/fluid-runner 2.0.0-dev.5.3.2.178189 → 2.0.0-dev.6.4.0.191457
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/CHANGELOG.md +47 -0
- package/README.md +5 -3
- package/dist/codeLoaderBundle.js +2 -2
- package/dist/codeLoaderBundle.js.map +1 -1
- package/dist/exportFile.js +1 -2
- package/dist/exportFile.js.map +1 -1
- package/dist/logger/baseFileLogger.js +1 -1
- package/dist/logger/baseFileLogger.js.map +1 -1
- package/dist/logger/loggerUtils.d.ts +11 -5
- package/dist/logger/loggerUtils.d.ts.map +1 -1
- package/dist/logger/loggerUtils.js +20 -10
- package/dist/logger/loggerUtils.js.map +1 -1
- package/package.json +21 -25
- package/src/logger/loggerUtils.ts +18 -8
- package/lib/codeLoaderBundle.d.ts +0 -44
- package/lib/codeLoaderBundle.d.ts.map +0 -1
- package/lib/codeLoaderBundle.js +0 -20
- package/lib/codeLoaderBundle.js.map +0 -1
- package/lib/exportFile.d.ts +0 -28
- package/lib/exportFile.d.ts.map +0 -1
- package/lib/exportFile.js +0 -91
- package/lib/exportFile.js.map +0 -1
- package/lib/fakeUrlResolver.d.ts +0 -15
- package/lib/fakeUrlResolver.d.ts.map +0 -1
- package/lib/fakeUrlResolver.js +0 -39
- package/lib/fakeUrlResolver.js.map +0 -1
- package/lib/fluidRunner.d.ts +0 -10
- package/lib/fluidRunner.d.ts.map +0 -1
- package/lib/fluidRunner.js +0 -98
- package/lib/fluidRunner.js.map +0 -1
- package/lib/index.d.ts +0 -12
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -12
- package/lib/index.js.map +0 -1
- package/lib/logger/baseFileLogger.d.ts +0 -28
- package/lib/logger/baseFileLogger.d.ts.map +0 -1
- package/lib/logger/baseFileLogger.js +0 -49
- package/lib/logger/baseFileLogger.js.map +0 -1
- package/lib/logger/csvFileLogger.d.ts +0 -18
- package/lib/logger/csvFileLogger.d.ts.map +0 -1
- package/lib/logger/csvFileLogger.js +0 -37
- package/lib/logger/csvFileLogger.js.map +0 -1
- package/lib/logger/fileLogger.d.ts +0 -37
- package/lib/logger/fileLogger.d.ts.map +0 -1
- package/lib/logger/fileLogger.js +0 -14
- package/lib/logger/fileLogger.js.map +0 -1
- package/lib/logger/jsonFileLogger.d.ts +0 -14
- package/lib/logger/jsonFileLogger.d.ts.map +0 -1
- package/lib/logger/jsonFileLogger.js +0 -21
- package/lib/logger/jsonFileLogger.js.map +0 -1
- package/lib/logger/loggerUtils.d.ts +0 -35
- package/lib/logger/loggerUtils.d.ts.map +0 -1
- package/lib/logger/loggerUtils.js +0 -78
- package/lib/logger/loggerUtils.js.map +0 -1
- package/lib/parseBundleAndExportFile.d.ts +0 -12
- package/lib/parseBundleAndExportFile.d.ts.map +0 -1
- package/lib/parseBundleAndExportFile.js +0 -60
- package/lib/parseBundleAndExportFile.js.map +0 -1
- package/lib/utils.d.ts +0 -32
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js +0 -75
- package/lib/utils.js.map +0 -1
- package/tsconfig.esnext.json +0 -7
|
@@ -1,35 +0,0 @@
|
|
|
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 { IFileLogger, ITelemetryOptions } from "./fileLogger";
|
|
7
|
-
/**
|
|
8
|
-
* Create a ITelemetryLoggerExt wrapped around provided IFileLogger
|
|
9
|
-
* ! It is expected that all events be sent through the returned "logger" value
|
|
10
|
-
* ! The "fileLogger" value should have its "close()" method called at the end of execution
|
|
11
|
-
* Note: if an output format is not supplied, default is JSON
|
|
12
|
-
* @returns - both the IFileLogger implementation and ITelemetryLoggerExt wrapper to be called
|
|
13
|
-
*/
|
|
14
|
-
export declare function createLogger(filePath: string, options?: ITelemetryOptions): {
|
|
15
|
-
logger: ITelemetryLoggerExt;
|
|
16
|
-
fileLogger: IFileLogger;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Validate the telemetryFile command line argument
|
|
20
|
-
* @param telemetryFile - path where telemetry will be written
|
|
21
|
-
*/
|
|
22
|
-
export declare function getTelemetryFileValidationError(telemetryFile: string): string | undefined;
|
|
23
|
-
/**
|
|
24
|
-
* Validate the provided output format and default properties
|
|
25
|
-
* @param format - desired output format of the telemetry
|
|
26
|
-
* @param props - default properties to be added to every telemetry entry
|
|
27
|
-
*/
|
|
28
|
-
export declare function validateAndParseTelemetryOptions(format?: string, props?: (string | number)[], eventsPerFlush?: number): {
|
|
29
|
-
success: false;
|
|
30
|
-
error: string;
|
|
31
|
-
} | {
|
|
32
|
-
success: true;
|
|
33
|
-
telemetryOptions: ITelemetryOptions;
|
|
34
|
-
};
|
|
35
|
-
//# sourceMappingURL=loggerUtils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loggerUtils.d.ts","sourceRoot":"","sources":["../../src/logger/loggerUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,mBAAmB,EAAe,MAAM,iCAAiC,CAAC;AAEnF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAgB,MAAM,cAAc,CAAC;AAG5E;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,GACzB;IAAE,MAAM,EAAE,mBAAmB,CAAC;IAAC,UAAU,EAAE,WAAW,CAAA;CAAE,CAW1D;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQzF;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC/C,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAC3B,cAAc,CAAC,EAAE,MAAM,GACrB;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,gBAAgB,EAAE,iBAAiB,CAAA;CAAE,CAqC5F"}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
import { ChildLogger } from "@fluidframework/telemetry-utils";
|
|
7
|
-
import { CSVFileLogger } from "./csvFileLogger";
|
|
8
|
-
import { OutputFormat } from "./fileLogger";
|
|
9
|
-
import { JSONFileLogger } from "./jsonFileLogger";
|
|
10
|
-
/**
|
|
11
|
-
* Create a ITelemetryLoggerExt wrapped around provided IFileLogger
|
|
12
|
-
* ! It is expected that all events be sent through the returned "logger" value
|
|
13
|
-
* ! The "fileLogger" value should have its "close()" method called at the end of execution
|
|
14
|
-
* Note: if an output format is not supplied, default is JSON
|
|
15
|
-
* @returns - both the IFileLogger implementation and ITelemetryLoggerExt wrapper to be called
|
|
16
|
-
*/
|
|
17
|
-
export function createLogger(filePath, options) {
|
|
18
|
-
const fileLogger = (options === null || options === void 0 ? void 0 : options.outputFormat) === OutputFormat.CSV
|
|
19
|
-
? new CSVFileLogger(filePath, options === null || options === void 0 ? void 0 : options.eventsPerFlush, options === null || options === void 0 ? void 0 : options.defaultProps)
|
|
20
|
-
: new JSONFileLogger(filePath, options === null || options === void 0 ? void 0 : options.eventsPerFlush, options === null || options === void 0 ? void 0 : options.defaultProps);
|
|
21
|
-
const logger = ChildLogger.create(fileLogger, "LocalSnapshotRunnerApp", {
|
|
22
|
-
all: { Event_Time: () => Date.now() },
|
|
23
|
-
});
|
|
24
|
-
return { logger, fileLogger };
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Validate the telemetryFile command line argument
|
|
28
|
-
* @param telemetryFile - path where telemetry will be written
|
|
29
|
-
*/
|
|
30
|
-
export function getTelemetryFileValidationError(telemetryFile) {
|
|
31
|
-
if (!telemetryFile) {
|
|
32
|
-
return "Telemetry file argument is missing.";
|
|
33
|
-
}
|
|
34
|
-
else if (fs.existsSync(telemetryFile)) {
|
|
35
|
-
return `Telemetry file already exists [${telemetryFile}].`;
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Validate the provided output format and default properties
|
|
41
|
-
* @param format - desired output format of the telemetry
|
|
42
|
-
* @param props - default properties to be added to every telemetry entry
|
|
43
|
-
*/
|
|
44
|
-
export function validateAndParseTelemetryOptions(format, props, eventsPerFlush) {
|
|
45
|
-
let outputFormat;
|
|
46
|
-
const defaultProps = {};
|
|
47
|
-
if (format) {
|
|
48
|
-
outputFormat = OutputFormat[format];
|
|
49
|
-
if (outputFormat === undefined) {
|
|
50
|
-
return { success: false, error: `Invalid telemetry format [${format}]` };
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
if (props && props.length > 0) {
|
|
54
|
-
if (props.length % 2 !== 0) {
|
|
55
|
-
return {
|
|
56
|
-
success: false,
|
|
57
|
-
error: `Invalid number of telemetry properties to add [${props.length}]`,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
for (let i = 0; i < props.length; i += 2) {
|
|
61
|
-
if (typeof props[i] === "number") {
|
|
62
|
-
return {
|
|
63
|
-
success: false,
|
|
64
|
-
error: `Property name cannot be number at index [${i}] -> [${props[i]}]`,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
defaultProps[props[i]] = props[i + 1];
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (eventsPerFlush !== undefined && isNaN(eventsPerFlush)) {
|
|
71
|
-
return {
|
|
72
|
-
success: false,
|
|
73
|
-
error: "Invalid eventsPerFlush",
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
return { success: true, telemetryOptions: { outputFormat, defaultProps, eventsPerFlush } };
|
|
77
|
-
}
|
|
78
|
-
//# sourceMappingURL=loggerUtils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"loggerUtils.js","sourceRoot":"","sources":["../../src/logger/loggerUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAuB,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAkC,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAC3B,QAAgB,EAChB,OAA2B;IAE3B,MAAM,UAAU,GACf,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,MAAK,YAAY,CAAC,GAAG;QACzC,CAAC,CAAC,IAAI,aAAa,CAAC,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAC;QAC7E,CAAC,CAAC,IAAI,cAAc,CAAC,QAAQ,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAC,CAAC;IAEjF,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,UAAU,EAAE,wBAAwB,EAAE;QACvE,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE;KACrC,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,+BAA+B,CAAC,aAA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AE;QAC1D,OAAO;YACN,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,wBAAwB;SAC/B,CAAC;KACF;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,EAAE,CAAC;AAC5F,CAAC","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, ChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { CSVFileLogger } from \"./csvFileLogger\";\nimport { IFileLogger, ITelemetryOptions, OutputFormat } from \"./fileLogger\";\nimport { JSONFileLogger } from \"./jsonFileLogger\";\n\n/**\n * Create a ITelemetryLoggerExt wrapped around provided IFileLogger\n * ! It is expected that all events be sent through the returned \"logger\" value\n * ! The \"fileLogger\" value should have its \"close()\" method called at the end of execution\n * Note: if an output format is not supplied, default is JSON\n * @returns - both the IFileLogger implementation and ITelemetryLoggerExt wrapper to be called\n */\nexport function createLogger(\n\tfilePath: string,\n\toptions?: ITelemetryOptions,\n): { logger: ITelemetryLoggerExt; fileLogger: IFileLogger } {\n\tconst fileLogger =\n\t\toptions?.outputFormat === OutputFormat.CSV\n\t\t\t? new CSVFileLogger(filePath, options?.eventsPerFlush, options?.defaultProps)\n\t\t\t: new JSONFileLogger(filePath, options?.eventsPerFlush, options?.defaultProps);\n\n\tconst logger = ChildLogger.create(fileLogger, \"LocalSnapshotRunnerApp\", {\n\t\tall: { Event_Time: () => Date.now() },\n\t});\n\n\treturn { logger, fileLogger };\n}\n\n/**\n * Validate the telemetryFile command line argument\n * @param telemetryFile - path where telemetry will be written\n */\nexport function getTelemetryFileValidationError(telemetryFile: string): string | undefined {\n\tif (!telemetryFile) {\n\t\treturn \"Telemetry file argument is missing.\";\n\t} else if (fs.existsSync(telemetryFile)) {\n\t\treturn `Telemetry file already exists [${telemetryFile}].`;\n\t}\n\n\treturn undefined;\n}\n\n/**\n * Validate the provided output format and default properties\n * @param format - desired output format of the telemetry\n * @param props - default properties to be added to every telemetry entry\n */\nexport function validateAndParseTelemetryOptions(\n\tformat?: string,\n\tprops?: (string | number)[],\n\teventsPerFlush?: number,\n): { success: false; error: string } | { success: true; telemetryOptions: ITelemetryOptions } {\n\tlet outputFormat: OutputFormat | undefined;\n\tconst defaultProps: Record<string, string | number> = {};\n\n\tif (format) {\n\t\toutputFormat = OutputFormat[format];\n\t\tif (outputFormat === undefined) {\n\t\t\treturn { success: false, error: `Invalid telemetry format [${format}]` };\n\t\t}\n\t}\n\n\tif (props && props.length > 0) {\n\t\tif (props.length % 2 !== 0) {\n\t\t\treturn {\n\t\t\t\tsuccess: false,\n\t\t\t\terror: `Invalid number of telemetry properties to add [${props.length}]`,\n\t\t\t};\n\t\t}\n\t\tfor (let i = 0; i < props.length; i += 2) {\n\t\t\tif (typeof props[i] === \"number\") {\n\t\t\t\treturn {\n\t\t\t\t\tsuccess: false,\n\t\t\t\t\terror: `Property name cannot be number at index [${i}] -> [${props[i]}]`,\n\t\t\t\t};\n\t\t\t}\n\t\t\tdefaultProps[props[i]] = props[i + 1];\n\t\t}\n\t}\n\n\tif (eventsPerFlush !== undefined && isNaN(eventsPerFlush)) {\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: \"Invalid eventsPerFlush\",\n\t\t};\n\t}\n\n\treturn { success: true, telemetryOptions: { outputFormat, defaultProps, eventsPerFlush } };\n}\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import { IExportFileResponse } from "./exportFile";
|
|
6
|
-
import { ITelemetryOptions } from "./logger/fileLogger";
|
|
7
|
-
/**
|
|
8
|
-
* Parse a provided JS bundle, execute code on Container based on ODSP snapshot, and write result to file
|
|
9
|
-
* @param codeLoader - path to provided JS bundle that implements ICodeLoaderBundle (see codeLoaderBundle.ts)
|
|
10
|
-
*/
|
|
11
|
-
export declare function parseBundleAndExportFile(codeLoader: string, inputFile: string, outputFile: string, telemetryFile: string, options?: string, telemetryOptions?: ITelemetryOptions, timeout?: number, disableNetworkFetch?: boolean): Promise<IExportFileResponse>;
|
|
12
|
-
//# sourceMappingURL=parseBundleAndExportFile.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseBundleAndExportFile.d.ts","sourceRoot":"","sources":["../src/parseBundleAndExportFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAA6B,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAE9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAOxD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC7C,UAAU,EAAE,MAAM,EAClB,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,CA4D9B"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
import { PerformanceEvent } from "@fluidframework/telemetry-utils";
|
|
7
|
-
import { isCodeLoaderBundle, isFluidFileConverter } from "./codeLoaderBundle";
|
|
8
|
-
import { createContainerAndExecute } from "./exportFile";
|
|
9
|
-
import { createLogger, getTelemetryFileValidationError } from "./logger/loggerUtils";
|
|
10
|
-
/* eslint-enable import/no-internal-modules */
|
|
11
|
-
import { getSnapshotFileContent, getArgsValidationError } from "./utils";
|
|
12
|
-
const clientArgsValidationError = "Client_ArgsValidationError";
|
|
13
|
-
/**
|
|
14
|
-
* Parse a provided JS bundle, execute code on Container based on ODSP snapshot, and write result to file
|
|
15
|
-
* @param codeLoader - path to provided JS bundle that implements ICodeLoaderBundle (see codeLoaderBundle.ts)
|
|
16
|
-
*/
|
|
17
|
-
export async function parseBundleAndExportFile(codeLoader, inputFile, outputFile, telemetryFile, options, telemetryOptions, timeout, disableNetworkFetch) {
|
|
18
|
-
const telemetryArgError = getTelemetryFileValidationError(telemetryFile);
|
|
19
|
-
if (telemetryArgError) {
|
|
20
|
-
const eventName = clientArgsValidationError;
|
|
21
|
-
return { success: false, eventName, errorMessage: telemetryArgError };
|
|
22
|
-
}
|
|
23
|
-
const { fileLogger, logger } = createLogger(telemetryFile, telemetryOptions);
|
|
24
|
-
try {
|
|
25
|
-
return await PerformanceEvent.timedExecAsync(logger, { eventName: "ParseBundleAndExportFile" }, async () => {
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
27
|
-
const codeLoaderBundle = require(codeLoader);
|
|
28
|
-
if (!isCodeLoaderBundle(codeLoaderBundle)) {
|
|
29
|
-
const eventName = clientArgsValidationError;
|
|
30
|
-
const errorMessage = "Code loader bundle is not of type ICodeLoaderBundle";
|
|
31
|
-
logger.sendErrorEvent({ eventName, message: errorMessage });
|
|
32
|
-
return { success: false, eventName, errorMessage };
|
|
33
|
-
}
|
|
34
|
-
const fluidExport = await codeLoaderBundle.fluidExport;
|
|
35
|
-
if (!isFluidFileConverter(fluidExport)) {
|
|
36
|
-
const eventName = clientArgsValidationError;
|
|
37
|
-
const errorMessage = "Fluid export from CodeLoaderBundle is not of type IFluidFileConverter";
|
|
38
|
-
logger.sendErrorEvent({ eventName, message: errorMessage });
|
|
39
|
-
return { success: false, eventName, errorMessage };
|
|
40
|
-
}
|
|
41
|
-
const argsValidationError = getArgsValidationError(inputFile, outputFile, timeout);
|
|
42
|
-
if (argsValidationError) {
|
|
43
|
-
const eventName = clientArgsValidationError;
|
|
44
|
-
logger.sendErrorEvent({ eventName, message: argsValidationError });
|
|
45
|
-
return { success: false, eventName, errorMessage: argsValidationError };
|
|
46
|
-
}
|
|
47
|
-
fs.writeFileSync(outputFile, await createContainerAndExecute(getSnapshotFileContent(inputFile), fluidExport, logger, options, timeout, disableNetworkFetch));
|
|
48
|
-
return { success: true };
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
catch (error) {
|
|
52
|
-
const eventName = "Client_UnexpectedError";
|
|
53
|
-
logger.sendErrorEvent({ eventName }, error);
|
|
54
|
-
return { success: false, eventName, errorMessage: "Unexpected error", error };
|
|
55
|
-
}
|
|
56
|
-
finally {
|
|
57
|
-
await fileLogger.close();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=parseBundleAndExportFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseBundleAndExportFile.js","sourceRoot":"","sources":["../src/parseBundleAndExportFile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAuB,MAAM,cAAc,CAAC;AAG9E,OAAO,EAAE,YAAY,EAAE,+BAA+B,EAAE,MAAM,sBAAsB,CAAC;AACrF,8CAA8C;AAC9C,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEzE,MAAM,yBAAyB,GAAG,4BAA4B,CAAC;AAE/D;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAC7C,UAAkB,EAClB,SAAiB,EACjB,UAAkB,EAClB,aAAqB,EACrB,OAAgB,EAChB,gBAAoC,EACpC,OAAg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AU,EAAE,OAAO,CAAC,CAAC;YACnF,IAAI,mBAAmB,EAAE;gBACxB,MAAM,SAAS,GAAG,yBAAyB,CAAC;gBAC5C,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,mBAAmB,EAAE,CAAC,CAAC;gBACnE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,mBAAmB,EAAE,CAAC;aACxE;YAED,EAAE,CAAC,aAAa,CACf,UAAU,EACV,MAAM,yBAAyB,CAC9B,sBAAsB,CAAC,SAAS,CAAC,EACjC,WAAW,EACX,MAAM,EACN,OAAO,EACP,OAAO,EACP,mBAAmB,CACnB,CACD,CAAC;YAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC1B,CAAC,CACD,CAAC;KACF;IAAC,OAAO,KAAK,EAAE;QACf,MAAM,SAAS,GAAG,wBAAwB,CAAC;QAC3C,MAAM,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC;QAC5C,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,kBAAkB,EAAE,KAAK,EAAE,CAAC;KAC9E;YAAS;QACT,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;KACzB;AACF,CAAC","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 { PerformanceEvent } from \"@fluidframework/telemetry-utils\";\nimport { isCodeLoaderBundle, isFluidFileConverter } from \"./codeLoaderBundle\";\nimport { createContainerAndExecute, IExportFileResponse } from \"./exportFile\";\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 */\nimport { getSnapshotFileContent, getArgsValidationError } from \"./utils\";\n\nconst clientArgsValidationError = \"Client_ArgsValidationError\";\n\n/**\n * Parse a provided JS bundle, execute code on Container based on ODSP snapshot, and write result to file\n * @param codeLoader - path to provided JS bundle that implements ICodeLoaderBundle (see codeLoaderBundle.ts)\n */\nexport async function parseBundleAndExportFile(\n\tcodeLoader: string,\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: \"ParseBundleAndExportFile\" },\n\t\t\tasync () => {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires\n\t\t\t\tconst codeLoaderBundle = require(codeLoader);\n\t\t\t\tif (!isCodeLoaderBundle(codeLoaderBundle)) {\n\t\t\t\t\tconst eventName = clientArgsValidationError;\n\t\t\t\t\tconst errorMessage = \"Code loader bundle is not of type ICodeLoaderBundle\";\n\t\t\t\t\tlogger.sendErrorEvent({ eventName, message: errorMessage });\n\t\t\t\t\treturn { success: false, eventName, errorMessage };\n\t\t\t\t}\n\n\t\t\t\tconst fluidExport = await codeLoaderBundle.fluidExport;\n\t\t\t\tif (!isFluidFileConverter(fluidExport)) {\n\t\t\t\t\tconst eventName = clientArgsValidationError;\n\t\t\t\t\tconst errorMessage =\n\t\t\t\t\t\t\"Fluid export from CodeLoaderBundle is not of type IFluidFileConverter\";\n\t\t\t\t\tlogger.sendErrorEvent({ eventName, message: errorMessage });\n\t\t\t\t\treturn { success: false, eventName, errorMessage };\n\t\t\t\t}\n\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\tfluidExport,\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"]}
|
package/lib/utils.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
import { IFluidFileConverter } from "./codeLoaderBundle";
|
|
7
|
-
/**
|
|
8
|
-
* Is the given snapshot in JSON format
|
|
9
|
-
* @param content - snapshot file content
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export declare function isJsonSnapshot(content: Buffer): boolean;
|
|
13
|
-
/**
|
|
14
|
-
* Get the ODSP snapshot file content
|
|
15
|
-
* Works on both JSON and binary snapshot formats
|
|
16
|
-
* @param filePath - path to the ODSP snapshot file
|
|
17
|
-
*/
|
|
18
|
-
export declare function getSnapshotFileContent(filePath: string): string | Buffer;
|
|
19
|
-
/**
|
|
20
|
-
* Validate provided command line arguments
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export declare function validateCommandLineArgs(codeLoader?: string, fluidFileConverter?: IFluidFileConverter): string | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* @internal
|
|
26
|
-
*/
|
|
27
|
-
export declare function getArgsValidationError(inputFile: string, outputFile: string, timeout?: number): string | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* @internal
|
|
30
|
-
*/
|
|
31
|
-
export declare function timeoutPromise<T = void>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void, timeout: number): Promise<T>;
|
|
32
|
-
//# sourceMappingURL=utils.d.ts.map
|
package/lib/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIxE;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACtC,UAAU,CAAC,EAAE,MAAM,EACnB,kBAAkB,CAAC,EAAE,mBAAmB,GACtC,MAAM,GAAG,SAAS,CAQpB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,MAAM,GACd,MAAM,GAAG,SAAS,CAoBpB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAAC,CAAC,GAAG,IAAI,EAC5C,QAAQ,EAAE,CACT,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,EAC5C,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,KAC1B,IAAI,EACT,OAAO,EAAE,MAAM,GACb,OAAO,CAAC,CAAC,CAAC,CAeZ"}
|
package/lib/utils.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
-
* Licensed under the MIT License.
|
|
4
|
-
*/
|
|
5
|
-
import * as fs from "fs";
|
|
6
|
-
/**
|
|
7
|
-
* Is the given snapshot in JSON format
|
|
8
|
-
* @param content - snapshot file content
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export function isJsonSnapshot(content) {
|
|
12
|
-
return content.toString(undefined, 0, 1) === "{";
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Get the ODSP snapshot file content
|
|
16
|
-
* Works on both JSON and binary snapshot formats
|
|
17
|
-
* @param filePath - path to the ODSP snapshot file
|
|
18
|
-
*/
|
|
19
|
-
export function getSnapshotFileContent(filePath) {
|
|
20
|
-
// TODO: read file stream
|
|
21
|
-
const content = fs.readFileSync(filePath);
|
|
22
|
-
return isJsonSnapshot(content) ? content.toString() : content;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Validate provided command line arguments
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
export function validateCommandLineArgs(codeLoader, fluidFileConverter) {
|
|
29
|
-
if (codeLoader && fluidFileConverter !== undefined) {
|
|
30
|
-
return '"codeLoader" and "fluidFileConverter" cannot both be provided. See README for details.';
|
|
31
|
-
}
|
|
32
|
-
if (!codeLoader && fluidFileConverter === undefined) {
|
|
33
|
-
return '"codeLoader" must be provided if there is no explicit "fluidFileConverter". See README for details.';
|
|
34
|
-
}
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
export function getArgsValidationError(inputFile, outputFile, timeout) {
|
|
41
|
-
// Validate input file
|
|
42
|
-
if (!inputFile) {
|
|
43
|
-
return "Input file name argument is missing.";
|
|
44
|
-
}
|
|
45
|
-
else if (!fs.existsSync(inputFile)) {
|
|
46
|
-
return "Input file does not exist.";
|
|
47
|
-
}
|
|
48
|
-
// Validate output file
|
|
49
|
-
if (!outputFile) {
|
|
50
|
-
return "Output file argument is missing.";
|
|
51
|
-
}
|
|
52
|
-
else if (fs.existsSync(outputFile)) {
|
|
53
|
-
return `Output file already exists [${outputFile}].`;
|
|
54
|
-
}
|
|
55
|
-
if (timeout !== undefined && (isNaN(timeout) || timeout < 0)) {
|
|
56
|
-
return "Invalid timeout";
|
|
57
|
-
}
|
|
58
|
-
return undefined;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* @internal
|
|
62
|
-
*/
|
|
63
|
-
export async function timeoutPromise(executor, timeout) {
|
|
64
|
-
return new Promise((resolve, reject) => {
|
|
65
|
-
const timer = setTimeout(() => reject(new Error(`Timed out (${timeout}ms)`)), timeout);
|
|
66
|
-
executor((value) => {
|
|
67
|
-
clearTimeout(timer);
|
|
68
|
-
resolve(value);
|
|
69
|
-
}, (reason) => {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
reject(reason);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAGzB;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC7C,OAAO,OAAO,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,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,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,OAAO,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAEvF,QAAQ,CACP,CAAC,KAAK,EAAE,EAAE;YACT,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,OAAO,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,EACD,CAAC,MAAM,EAAE,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,MAAM,CAAC,CAAC;QAChB,CAAC,CACD,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC","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 { IFluidFileConverter } from \"./codeLoaderBundle\";\n\n/**\n * Is the given snapshot in JSON format\n * @param content - snapshot file content\n * @internal\n */\nexport function isJsonSnapshot(content: Buffer): boolean {\n\treturn content.toString(undefined, 0, 1) === \"{\";\n}\n\n/**\n * Get the ODSP snapshot file content\n * Works on both JSON and binary snapshot formats\n * @param filePath - path to the ODSP snapshot file\n */\nexport function getSnapshotFileContent(filePath: string): string | Buffer {\n\t// TODO: read file stream\n\tconst content = fs.readFileSync(filePath);\n\treturn isJsonSnapshot(content) ? content.toString() : content;\n}\n\n/**\n * Validate provided command line arguments\n * @internal\n */\nexport function validateCommandLineArgs(\n\tcodeLoader?: string,\n\tfluidFileConverter?: IFluidFileConverter,\n): string | undefined {\n\tif (codeLoader && fluidFileConverter !== undefined) {\n\t\treturn '\"codeLoader\" and \"fluidFileConverter\" cannot both be provided. See README for details.';\n\t}\n\tif (!codeLoader && fluidFileConverter === undefined) {\n\t\treturn '\"codeLoader\" must be provided if there is no explicit \"fluidFileConverter\". See README for details.';\n\t}\n\treturn undefined;\n}\n\n/**\n * @internal\n */\nexport function getArgsValidationError(\n\tinputFile: string,\n\toutputFile: string,\n\ttimeout?: number,\n): string | undefined {\n\t// Validate input file\n\tif (!inputFile) {\n\t\treturn \"Input file name argument is missing.\";\n\t} else if (!fs.existsSync(inputFile)) {\n\t\treturn \"Input file does not exist.\";\n\t}\n\n\t// Validate output file\n\tif (!outputFile) {\n\t\treturn \"Output file argument is missing.\";\n\t} else if (fs.existsSync(outputFile)) {\n\t\treturn `Output file already exists [${outputFile}].`;\n\t}\n\n\tif (timeout !== undefined && (isNaN(timeout) || timeout < 0)) {\n\t\treturn \"Invalid timeout\";\n\t}\n\n\treturn undefined;\n}\n\n/**\n * @internal\n */\nexport async function timeoutPromise<T = void>(\n\texecutor: (\n\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\treject: (reason?: any) => void,\n\t) => void,\n\ttimeout: number,\n): Promise<T> {\n\treturn new Promise<T>((resolve, reject) => {\n\t\tconst timer = setTimeout(() => reject(new Error(`Timed out (${timeout}ms)`)), timeout);\n\n\t\texecutor(\n\t\t\t(value) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tresolve(value);\n\t\t\t},\n\t\t\t(reason) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\treject(reason);\n\t\t\t},\n\t\t);\n\t});\n}\n"]}
|