@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.
Files changed (77) hide show
  1. package/.eslintrc.cjs +17 -0
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +120 -0
  4. package/LICENSE +21 -0
  5. package/README.md +101 -0
  6. package/api-extractor-lint.json +13 -0
  7. package/api-extractor.json +17 -0
  8. package/api-report/fluid-runner.api.md +89 -0
  9. package/bin/fluid-runner +2 -0
  10. package/dist/codeLoaderBundle.d.ts +46 -0
  11. package/dist/codeLoaderBundle.d.ts.map +1 -0
  12. package/dist/codeLoaderBundle.js +25 -0
  13. package/dist/codeLoaderBundle.js.map +1 -0
  14. package/dist/exportFile.d.ts +33 -0
  15. package/dist/exportFile.d.ts.map +1 -0
  16. package/dist/exportFile.js +120 -0
  17. package/dist/exportFile.js.map +1 -0
  18. package/dist/fakeUrlResolver.d.ts +15 -0
  19. package/dist/fakeUrlResolver.d.ts.map +1 -0
  20. package/dist/fakeUrlResolver.js +43 -0
  21. package/dist/fakeUrlResolver.js.map +1 -0
  22. package/dist/fluid-runner-alpha.d.ts +79 -0
  23. package/dist/fluid-runner-beta.d.ts +52 -0
  24. package/dist/fluid-runner-public.d.ts +52 -0
  25. package/dist/fluid-runner-untrimmed.d.ts +175 -0
  26. package/dist/fluidRunner.d.ts +11 -0
  27. package/dist/fluidRunner.d.ts.map +1 -0
  28. package/dist/fluidRunner.js +126 -0
  29. package/dist/fluidRunner.js.map +1 -0
  30. package/dist/index.d.ts +12 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +24 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/logger/baseFileLogger.d.ts +28 -0
  35. package/dist/logger/baseFileLogger.d.ts.map +1 -0
  36. package/dist/logger/baseFileLogger.js +76 -0
  37. package/dist/logger/baseFileLogger.js.map +1 -0
  38. package/dist/logger/csvFileLogger.d.ts +18 -0
  39. package/dist/logger/csvFileLogger.d.ts.map +1 -0
  40. package/dist/logger/csvFileLogger.js +64 -0
  41. package/dist/logger/csvFileLogger.js.map +1 -0
  42. package/dist/logger/fileLogger.d.ts +44 -0
  43. package/dist/logger/fileLogger.d.ts.map +1 -0
  44. package/dist/logger/fileLogger.js +18 -0
  45. package/dist/logger/fileLogger.js.map +1 -0
  46. package/dist/logger/jsonFileLogger.d.ts +14 -0
  47. package/dist/logger/jsonFileLogger.d.ts.map +1 -0
  48. package/dist/logger/jsonFileLogger.js +48 -0
  49. package/dist/logger/jsonFileLogger.js.map +1 -0
  50. package/dist/logger/loggerUtils.d.ts +44 -0
  51. package/dist/logger/loggerUtils.d.ts.map +1 -0
  52. package/dist/logger/loggerUtils.js +120 -0
  53. package/dist/logger/loggerUtils.js.map +1 -0
  54. package/dist/parseBundleAndExportFile.d.ts +13 -0
  55. package/dist/parseBundleAndExportFile.d.ts.map +1 -0
  56. package/dist/parseBundleAndExportFile.js +88 -0
  57. package/dist/parseBundleAndExportFile.js.map +1 -0
  58. package/dist/tsdoc-metadata.json +11 -0
  59. package/dist/utils.d.ts +33 -0
  60. package/dist/utils.d.ts.map +1 -0
  61. package/dist/utils.js +107 -0
  62. package/dist/utils.js.map +1 -0
  63. package/package.json +120 -0
  64. package/prettier.config.cjs +8 -0
  65. package/src/codeLoaderBundle.ts +63 -0
  66. package/src/exportFile.ts +148 -0
  67. package/src/fakeUrlResolver.ts +54 -0
  68. package/src/fluidRunner.ts +135 -0
  69. package/src/index.ts +18 -0
  70. package/src/logger/baseFileLogger.ts +58 -0
  71. package/src/logger/csvFileLogger.ts +40 -0
  72. package/src/logger/fileLogger.ts +51 -0
  73. package/src/logger/jsonFileLogger.ts +27 -0
  74. package/src/logger/loggerUtils.ts +108 -0
  75. package/src/parseBundleAndExportFile.ts +92 -0
  76. package/src/utils.ts +100 -0
  77. package/tsconfig.json +13 -0
@@ -0,0 +1,28 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryBaseEvent } from "@fluidframework/core-interfaces";
6
+ import { IFileLogger } from "./fileLogger";
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare abstract class BaseFileLogger implements IFileLogger {
11
+ protected readonly filePath: string;
12
+ protected readonly eventsPerFlush: number;
13
+ protected readonly defaultProps?: Record<string, string | number> | undefined;
14
+ supportsTags?: true | undefined;
15
+ /** Hold events in memory until flushed */
16
+ protected events: any[];
17
+ protected hasWrittenToFile: boolean;
18
+ /**
19
+ * @param filePath - file path to write logs to
20
+ * @param eventsPerFlush - number of events per flush
21
+ * @param defaultProps - default properties to add to every telemetry event
22
+ */
23
+ constructor(filePath: string, eventsPerFlush?: number, defaultProps?: Record<string, string | number> | undefined);
24
+ send(event: ITelemetryBaseEvent): void;
25
+ protected flush(): Promise<void>;
26
+ close(): Promise<void>;
27
+ }
28
+ //# sourceMappingURL=baseFileLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseFileLogger.d.ts","sourceRoot":"","sources":["../../src/logger/baseFileLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C;;GAEG;AACH,8BAAsB,cAAe,YAAW,WAAW;IAazD,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACnC,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,MAAM;IACzC,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC;IAd1B,YAAY,CAAC,EAAE,IAAI,GAAG,SAAS,CAAC;IAEvC,0CAA0C;IAC1C,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,CAAM;IAC7B,SAAS,CAAC,gBAAgB,UAAS;IAEnC;;;;OAIG;gBAEiB,QAAQ,EAAE,MAAM,EAChB,cAAc,GAAE,MAAW,EAC3B,YAAY,CAAC,6CAAiC;IAG3D,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;cAW7B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAazB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGnC"}
@@ -0,0 +1,76 @@
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.BaseFileLogger = void 0;
31
+ const fs = __importStar(require("fs"));
32
+ /**
33
+ * @internal
34
+ */
35
+ class BaseFileLogger {
36
+ /**
37
+ * @param filePath - file path to write logs to
38
+ * @param eventsPerFlush - number of events per flush
39
+ * @param defaultProps - default properties to add to every telemetry event
40
+ */
41
+ constructor(filePath, eventsPerFlush = 50, defaultProps) {
42
+ this.filePath = filePath;
43
+ this.eventsPerFlush = eventsPerFlush;
44
+ this.defaultProps = defaultProps;
45
+ /** Hold events in memory until flushed */
46
+ this.events = [];
47
+ this.hasWrittenToFile = false;
48
+ }
49
+ send(event) {
50
+ // eslint-disable-next-line no-param-reassign
51
+ event = { ...event, ...this.defaultProps };
52
+ this.events.push(event);
53
+ if (this.events.length >= this.eventsPerFlush || event.category === "error") {
54
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
55
+ this.flush();
56
+ }
57
+ }
58
+ async flush() {
59
+ if (this.events.length > 0) {
60
+ const contentToWrite = this.events.map((it) => JSON.stringify(it)).join(",");
61
+ if (this.hasWrittenToFile) {
62
+ fs.appendFileSync(this.filePath, `,${contentToWrite}`);
63
+ }
64
+ else {
65
+ fs.appendFileSync(this.filePath, contentToWrite);
66
+ }
67
+ this.events = [];
68
+ this.hasWrittenToFile = true;
69
+ }
70
+ }
71
+ async close() {
72
+ await this.flush();
73
+ }
74
+ }
75
+ exports.BaseFileLogger = BaseFileLogger;
76
+ //# sourceMappingURL=baseFileLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"baseFileLogger.js","sourceRoot":"","sources":["../../src/logger/baseFileLogger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AAIzB;;GAEG;AACH,MAAsB,cAAc;IAOnC;;;;OAIG;IACH,YACoB,QAAgB,EAChB,iBAAyB,EAAE,EAC3B,YAA8C;QAF9C,aAAQ,GAAR,QAAQ,CAAQ;QAChB,mBAAc,GAAd,cAAc,CAAa;QAC3B,iBAAY,GAAZ,YAAY,CAAkC;QAZlE,0CAA0C;QAChC,WAAM,GAAU,EAAE,CAAC;QACnB,qBAAgB,GAAG,KAAK,CAAC;IAWhC,CAAC;IAEG,IAAI,CAAC,KAA0B;QACrC,6CAA6C;QAC7C,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC3C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAExB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,cAAc,IAAI,KAAK,CAAC,QAAQ,KAAK,OAAO,EAAE;YAC5E,mEAAmE;YACnE,IAAI,CAAC,KAAK,EAAE,CAAC;SACb;IACF,CAAC;IAES,KAAK,CAAC,KAAK;QACpB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;YAC3B,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC7E,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBAC1B,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,cAAc,EAAE,CAAC,CAAC;aACvD;iBAAM;gBACN,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;aACjD;YACD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;YACjB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;SAC7B;IACF,CAAC;IAEM,KAAK,CAAC,KAAK;QACjB,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACD;AA7CD,wCA6CC","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 { ITelemetryBaseEvent } from \"@fluidframework/core-interfaces\";\nimport { IFileLogger } from \"./fileLogger\";\n\n/**\n * @internal\n */\nexport abstract class BaseFileLogger implements IFileLogger {\n\tpublic supportsTags?: true | undefined;\n\n\t/** Hold events in memory until flushed */\n\tprotected events: any[] = [];\n\tprotected hasWrittenToFile = false;\n\n\t/**\n\t * @param filePath - file path to write logs to\n\t * @param eventsPerFlush - number of events per flush\n\t * @param defaultProps - default properties to add to every telemetry event\n\t */\n\tpublic constructor(\n\t\tprotected readonly filePath: string,\n\t\tprotected readonly eventsPerFlush: number = 50,\n\t\tprotected readonly defaultProps?: Record<string, string | number>,\n\t) {}\n\n\tpublic send(event: ITelemetryBaseEvent): void {\n\t\t// eslint-disable-next-line no-param-reassign\n\t\tevent = { ...event, ...this.defaultProps };\n\t\tthis.events.push(event);\n\n\t\tif (this.events.length >= this.eventsPerFlush || event.category === \"error\") {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises\n\t\t\tthis.flush();\n\t\t}\n\t}\n\n\tprotected async flush(): Promise<void> {\n\t\tif (this.events.length > 0) {\n\t\t\tconst contentToWrite = this.events.map((it) => JSON.stringify(it)).join(\",\");\n\t\t\tif (this.hasWrittenToFile) {\n\t\t\t\tfs.appendFileSync(this.filePath, `,${contentToWrite}`);\n\t\t\t} else {\n\t\t\t\tfs.appendFileSync(this.filePath, contentToWrite);\n\t\t\t}\n\t\t\tthis.events = [];\n\t\t\tthis.hasWrittenToFile = true;\n\t\t}\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tawait this.flush();\n\t}\n}\n"]}
@@ -0,0 +1,18 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryBaseEvent } from "@fluidframework/core-interfaces";
6
+ import { BaseFileLogger } from "./baseFileLogger";
7
+ /**
8
+ * FileLogger that writes events into a defined CSV file
9
+ * @internal
10
+ */
11
+ export declare class CSVFileLogger extends BaseFileLogger {
12
+ /** Store the column names to write as the CSV header */
13
+ private readonly columns;
14
+ protected flush(): Promise<void>;
15
+ send(event: ITelemetryBaseEvent): void;
16
+ close(): Promise<void>;
17
+ }
18
+ //# sourceMappingURL=csvFileLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csvFileLogger.d.ts","sourceRoot":"","sources":["../../src/logger/csvFileLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;GAGG;AACH,qBAAa,aAAc,SAAQ,cAAc;IAChD,wDAAwD;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAa;cAErB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,IAAI,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI;IAQhC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CASnC"}
@@ -0,0 +1,64 @@
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.CSVFileLogger = void 0;
31
+ const fs = __importStar(require("fs"));
32
+ const json2csv_1 = require("json2csv");
33
+ const baseFileLogger_1 = require("./baseFileLogger");
34
+ /**
35
+ * FileLogger that writes events into a defined CSV file
36
+ * @internal
37
+ */
38
+ class CSVFileLogger extends baseFileLogger_1.BaseFileLogger {
39
+ constructor() {
40
+ super(...arguments);
41
+ /** Store the column names to write as the CSV header */
42
+ this.columns = new Set();
43
+ }
44
+ async flush() {
45
+ // No flushing is performed since we need all log entries to determine set of CSV columns
46
+ }
47
+ send(event) {
48
+ // eslint-disable-next-line guard-for-in, no-restricted-syntax
49
+ for (const prop in event) {
50
+ this.columns.add(prop);
51
+ }
52
+ super.send(event);
53
+ }
54
+ async close() {
55
+ await super.close();
56
+ // eslint-disable-next-line guard-for-in, no-restricted-syntax
57
+ for (const field in this.defaultProps) {
58
+ this.columns.add(field);
59
+ }
60
+ fs.writeFileSync(this.filePath, (0, json2csv_1.parse)(this.events, Array.from(this.columns)));
61
+ }
62
+ }
63
+ exports.CSVFileLogger = CSVFileLogger;
64
+ //# sourceMappingURL=csvFileLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csvFileLogger.js","sourceRoot":"","sources":["../../src/logger/csvFileLogger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,uCAAiC;AAEjC,qDAAkD;AAElD;;;GAGG;AACH,MAAa,aAAc,SAAQ,+BAAc;IAAjD;;QACC,wDAAwD;QACvC,YAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAuBtC,CAAC;IArBU,KAAK,CAAC,KAAK;QACpB,yFAAyF;IAC1F,CAAC;IAEM,IAAI,CAAC,KAA0B;QACrC,8DAA8D;QAC9D,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACzB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;SACvB;QACD,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;IAEM,KAAK,CAAC,KAAK;QACjB,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,8DAA8D;QAC9D,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,YAAY,EAAE;YACtC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACxB;QAED,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAA,gBAAK,EAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/E,CAAC;CACD;AAzBD,sCAyBC","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 { parse } from \"json2csv\";\nimport { ITelemetryBaseEvent } from \"@fluidframework/core-interfaces\";\nimport { BaseFileLogger } from \"./baseFileLogger\";\n\n/**\n * FileLogger that writes events into a defined CSV file\n * @internal\n */\nexport class CSVFileLogger extends BaseFileLogger {\n\t/** Store the column names to write as the CSV header */\n\tprivate readonly columns = new Set();\n\n\tprotected async flush(): Promise<void> {\n\t\t// No flushing is performed since we need all log entries to determine set of CSV columns\n\t}\n\n\tpublic send(event: ITelemetryBaseEvent): void {\n\t\t// eslint-disable-next-line guard-for-in, no-restricted-syntax\n\t\tfor (const prop in event) {\n\t\t\tthis.columns.add(prop);\n\t\t}\n\t\tsuper.send(event);\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tawait super.close();\n\t\t// eslint-disable-next-line guard-for-in, no-restricted-syntax\n\t\tfor (const field in this.defaultProps) {\n\t\t\tthis.columns.add(field);\n\t\t}\n\n\t\tfs.writeFileSync(this.filePath, parse(this.events, Array.from(this.columns)));\n\t}\n}\n"]}
@@ -0,0 +1,44 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
6
+ /**
7
+ * Contract for logger that writes telemetry to a file
8
+ * @internal
9
+ */
10
+ export interface IFileLogger extends ITelemetryBaseLogger {
11
+ /**
12
+ * This method acts as a "dispose" and should be explicitly called at the end of execution
13
+ */
14
+ close(): Promise<void>;
15
+ }
16
+ /**
17
+ * Desired output format for the telemetry
18
+ * @alpha
19
+ */
20
+ export declare enum OutputFormat {
21
+ JSON = 0,
22
+ CSV = 1
23
+ }
24
+ /**
25
+ * Options to provide upon creation of IFileLogger
26
+ * @internal
27
+ */
28
+ export interface ITelemetryOptions {
29
+ /** Desired output format used to create a specific IFileLogger implementation */
30
+ outputFormat?: OutputFormat;
31
+ /**
32
+ * Properties that should be added to every telemetry event
33
+ *
34
+ * @example
35
+ *
36
+ * ```JSON
37
+ * { "prop1": "value1", "prop2": 10.0 }
38
+ * ```
39
+ */
40
+ defaultProps?: Record<string, string | number>;
41
+ /** Number of telemetry events per flush to telemetry file */
42
+ eventsPerFlush?: number;
43
+ }
44
+ //# sourceMappingURL=fileLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileLogger.d.ts","sourceRoot":"","sources":["../../src/logger/fileLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,oBAAoB;IACxD;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB;AAED;;;GAGG;AACH,oBAAY,YAAY;IACvB,IAAI,IAAA;IACJ,GAAG,IAAA;CACH;AAGD;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IACjC,iFAAiF;IACjF,YAAY,CAAC,EAAE,YAAY,CAAC;IAE5B;;;;;;;;OAQG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IAE/C,6DAA6D;IAC7D,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB"}
@@ -0,0 +1,18 @@
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.OutputFormat = void 0;
8
+ /**
9
+ * Desired output format for the telemetry
10
+ * @alpha
11
+ */
12
+ var OutputFormat;
13
+ (function (OutputFormat) {
14
+ OutputFormat[OutputFormat["JSON"] = 0] = "JSON";
15
+ OutputFormat[OutputFormat["CSV"] = 1] = "CSV";
16
+ })(OutputFormat || (exports.OutputFormat = OutputFormat = {}));
17
+ /* eslint-enable tsdoc/syntax */
18
+ //# sourceMappingURL=fileLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileLogger.js","sourceRoot":"","sources":["../../src/logger/fileLogger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAeH;;;GAGG;AACH,IAAY,YAGX;AAHD,WAAY,YAAY;IACvB,+CAAI,CAAA;IACJ,6CAAG,CAAA;AACJ,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB;AAyBD,gCAAgC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ITelemetryBaseLogger } from \"@fluidframework/core-interfaces\";\n\n/**\n * Contract for logger that writes telemetry to a file\n * @internal\n */\nexport interface IFileLogger extends ITelemetryBaseLogger {\n\t/**\n\t * This method acts as a \"dispose\" and should be explicitly called at the end of execution\n\t */\n\tclose(): Promise<void>;\n}\n\n/**\n * Desired output format for the telemetry\n * @alpha\n */\nexport enum OutputFormat {\n\tJSON,\n\tCSV,\n}\n\n/* eslint-disable tsdoc/syntax */\n/**\n * Options to provide upon creation of IFileLogger\n * @internal\n */\nexport interface ITelemetryOptions {\n\t/** Desired output format used to create a specific IFileLogger implementation */\n\toutputFormat?: OutputFormat;\n\n\t/**\n\t * Properties that should be added to every telemetry event\n\t *\n\t * @example\n\t *\n\t * ```JSON\n\t * { \"prop1\": \"value1\", \"prop2\": 10.0 }\n\t * ```\n\t */\n\tdefaultProps?: Record<string, string | number>;\n\n\t/** Number of telemetry events per flush to telemetry file */\n\teventsPerFlush?: number;\n}\n/* eslint-enable tsdoc/syntax */\n"]}
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { BaseFileLogger } from "./baseFileLogger";
6
+ /**
7
+ * FileLogger that writes events into a defined CSV file
8
+ * @internal
9
+ */
10
+ export declare class JSONFileLogger extends BaseFileLogger {
11
+ constructor(filePath: string, eventsPerFlush?: number, defaultProps?: Record<string, string | number>);
12
+ close(): Promise<void>;
13
+ }
14
+ //# sourceMappingURL=jsonFileLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonFileLogger.d.ts","sourceRoot":"","sources":["../../src/logger/jsonFileLogger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;GAGG;AACH,qBAAa,cAAe,SAAQ,cAAc;gBAEhD,QAAQ,EAAE,MAAM,EAChB,cAAc,GAAE,MAAW,EAC3B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAMlC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAInC"}
@@ -0,0 +1,48 @@
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.JSONFileLogger = void 0;
31
+ const fs = __importStar(require("fs"));
32
+ const baseFileLogger_1 = require("./baseFileLogger");
33
+ /**
34
+ * FileLogger that writes events into a defined CSV file
35
+ * @internal
36
+ */
37
+ class JSONFileLogger extends baseFileLogger_1.BaseFileLogger {
38
+ constructor(filePath, eventsPerFlush = 50, defaultProps) {
39
+ super(filePath, eventsPerFlush, defaultProps);
40
+ fs.appendFileSync(this.filePath, "[");
41
+ }
42
+ async close() {
43
+ await super.close();
44
+ fs.appendFileSync(this.filePath, "]");
45
+ }
46
+ }
47
+ exports.JSONFileLogger = JSONFileLogger;
48
+ //# sourceMappingURL=jsonFileLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonFileLogger.js","sourceRoot":"","sources":["../../src/logger/jsonFileLogger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,qDAAkD;AAElD;;;GAGG;AACH,MAAa,cAAe,SAAQ,+BAAc;IACjD,YACC,QAAgB,EAChB,iBAAyB,EAAE,EAC3B,YAA8C;QAE9C,KAAK,CAAC,QAAQ,EAAE,cAAc,EAAE,YAAY,CAAC,CAAC;QAC9C,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IAEM,KAAK,CAAC,KAAK;QACjB,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QACpB,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;CACD;AAdD,wCAcC","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 { BaseFileLogger } from \"./baseFileLogger\";\n\n/**\n * FileLogger that writes events into a defined CSV file\n * @internal\n */\nexport class JSONFileLogger extends BaseFileLogger {\n\tconstructor(\n\t\tfilePath: string,\n\t\teventsPerFlush: number = 50,\n\t\tdefaultProps?: Record<string, string | number>,\n\t) {\n\t\tsuper(filePath, eventsPerFlush, defaultProps);\n\t\tfs.appendFileSync(this.filePath, \"[\");\n\t}\n\n\tpublic async close(): Promise<void> {\n\t\tawait super.close();\n\t\tfs.appendFileSync(this.filePath, \"]\");\n\t}\n}\n"]}
@@ -0,0 +1,44 @@
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 an {@link @fluidframework/telemetry-utils#ITelemetryLoggerExt} wrapped around provided {@link IFileLogger}.
9
+ *
10
+ * @remarks
11
+ *
12
+ * It is expected that all events be sent through the returned "logger" value.
13
+ *
14
+ * The "fileLogger" value should have its "close()" method called at the end of execution.
15
+ *
16
+ * Note: if an output format is not supplied, default is JSON.
17
+ *
18
+ * @returns Both the `IFileLogger` implementation and `ITelemetryLoggerExt` wrapper to be called.
19
+ * @internal
20
+ */
21
+ export declare function createLogger(filePath: string, options?: ITelemetryOptions): {
22
+ logger: ITelemetryLoggerExt;
23
+ fileLogger: IFileLogger;
24
+ };
25
+ /**
26
+ * Validate the telemetryFile command line argument
27
+ * @param telemetryFile - path where telemetry will be written
28
+ * @internal
29
+ */
30
+ export declare function getTelemetryFileValidationError(telemetryFile: string): string | undefined;
31
+ /**
32
+ * Validate the provided output format and default properties
33
+ * @param format - desired output format of the telemetry
34
+ * @param props - default properties to be added to every telemetry entry
35
+ * @internal
36
+ */
37
+ export declare function validateAndParseTelemetryOptions(format?: string, props?: (string | number)[], eventsPerFlush?: number): {
38
+ success: false;
39
+ error: string;
40
+ } | {
41
+ success: true;
42
+ telemetryOptions: ITelemetryOptions;
43
+ };
44
+ //# sourceMappingURL=loggerUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loggerUtils.d.ts","sourceRoot":"","sources":["../../src/logger/loggerUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,mBAAmB,EAAqB,MAAM,iCAAiC,CAAC;AAEzF,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAgB,MAAM,cAAc,CAAC;AAG5E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,iBAAiB,GACzB;IAAE,MAAM,EAAE,mBAAmB,CAAC;IAAC,UAAU,EAAE,WAAW,CAAA;CAAE,CAe1D;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQzF;AAED;;;;;GAKG;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"}
@@ -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.validateAndParseTelemetryOptions = exports.getTelemetryFileValidationError = exports.createLogger = void 0;
31
+ const fs = __importStar(require("fs"));
32
+ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
33
+ const csvFileLogger_1 = require("./csvFileLogger");
34
+ const fileLogger_1 = require("./fileLogger");
35
+ const jsonFileLogger_1 = require("./jsonFileLogger");
36
+ /**
37
+ * Create an {@link @fluidframework/telemetry-utils#ITelemetryLoggerExt} wrapped around provided {@link IFileLogger}.
38
+ *
39
+ * @remarks
40
+ *
41
+ * It is expected that all events be sent through the returned "logger" value.
42
+ *
43
+ * The "fileLogger" value should have its "close()" method called at the end of execution.
44
+ *
45
+ * Note: if an output format is not supplied, default is JSON.
46
+ *
47
+ * @returns Both the `IFileLogger` implementation and `ITelemetryLoggerExt` wrapper to be called.
48
+ * @internal
49
+ */
50
+ function createLogger(filePath, options) {
51
+ const fileLogger = options?.outputFormat === fileLogger_1.OutputFormat.CSV
52
+ ? new csvFileLogger_1.CSVFileLogger(filePath, options?.eventsPerFlush, options?.defaultProps)
53
+ : new jsonFileLogger_1.JSONFileLogger(filePath, options?.eventsPerFlush, options?.defaultProps);
54
+ const logger = (0, telemetry_utils_1.createChildLogger)({
55
+ logger: fileLogger,
56
+ namespace: "LocalSnapshotRunnerApp",
57
+ properties: {
58
+ all: { Event_Time: () => Date.now() },
59
+ },
60
+ });
61
+ return { logger, fileLogger };
62
+ }
63
+ exports.createLogger = createLogger;
64
+ /**
65
+ * Validate the telemetryFile command line argument
66
+ * @param telemetryFile - path where telemetry will be written
67
+ * @internal
68
+ */
69
+ function getTelemetryFileValidationError(telemetryFile) {
70
+ if (!telemetryFile) {
71
+ return "Telemetry file argument is missing.";
72
+ }
73
+ else if (fs.existsSync(telemetryFile)) {
74
+ return `Telemetry file already exists [${telemetryFile}].`;
75
+ }
76
+ return undefined;
77
+ }
78
+ exports.getTelemetryFileValidationError = getTelemetryFileValidationError;
79
+ /**
80
+ * Validate the provided output format and default properties
81
+ * @param format - desired output format of the telemetry
82
+ * @param props - default properties to be added to every telemetry entry
83
+ * @internal
84
+ */
85
+ function validateAndParseTelemetryOptions(format, props, eventsPerFlush) {
86
+ let outputFormat;
87
+ const defaultProps = {};
88
+ if (format) {
89
+ outputFormat = fileLogger_1.OutputFormat[format];
90
+ if (outputFormat === undefined) {
91
+ return { success: false, error: `Invalid telemetry format [${format}]` };
92
+ }
93
+ }
94
+ if (props && props.length > 0) {
95
+ if (props.length % 2 !== 0) {
96
+ return {
97
+ success: false,
98
+ error: `Invalid number of telemetry properties to add [${props.length}]`,
99
+ };
100
+ }
101
+ for (let i = 0; i < props.length; i += 2) {
102
+ if (typeof props[i] === "number") {
103
+ return {
104
+ success: false,
105
+ error: `Property name cannot be number at index [${i}] -> [${props[i]}]`,
106
+ };
107
+ }
108
+ defaultProps[props[i]] = props[i + 1];
109
+ }
110
+ }
111
+ if (eventsPerFlush !== undefined && isNaN(eventsPerFlush)) {
112
+ return {
113
+ success: false,
114
+ error: "Invalid eventsPerFlush",
115
+ };
116
+ }
117
+ return { success: true, telemetryOptions: { outputFormat, defaultProps, eventsPerFlush } };
118
+ }
119
+ exports.validateAndParseTelemetryOptions = validateAndParseTelemetryOptions;
120
+ //# sourceMappingURL=loggerUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loggerUtils.js","sourceRoot":"","sources":["../../src/logger/loggerUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,uCAAyB;AACzB,qEAAyF;AACzF,mDAAgD;AAChD,6CAA4E;AAC5E,qDAAkD;AAElD;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAC3B,QAAgB,EAChB,OAA2B;IAE3B,MAAM,UAAU,GACf,OAAO,EAAE,YAAY,KAAK,yBAAY,CAAC,GAAG;QACzC,CAAC,CAAC,IAAI,6BAAa,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,CAAC;QAC7E,CAAC,CAAC,IAAI,+BAAc,CAAC,QAAQ,EAAE,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;IAEjF,MAAM,MAAM,GAAG,IAAA,mCAAiB,EAAC;QAChC,MAAM,EAAE,UAAU;QAClB,SAAS,EAAE,wBAAwB;QACnC,UAAU,EAAE;YACX,GAAG,EAAE,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE;SACrC;KACD,CAAC,CAAC;IAEH,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC;AAC/B,CAAC;AAlBD,oCAkBC;AAED;;;;GAIG;AACH,SAAgB,+BAA+B,CAAC,aAAqB;IACpE,IAAI,CAAC,aAAa,EAAE;QACnB,OAAO,qCAAqC,CAAC;KAC7C;SAAM,IAAI,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;QACxC,OAAO,kCAAkC,aAAa,IAAI,CAAC;KAC3D;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AARD,0EAQC;AAED;;;;;GAKG;AACH,SAAgB,gCAAgC,CAC/C,MAAe,EACf,KAA2B,EAC3B,cAAuB;IAEvB,IAAI,YAAsC,CAAC;IAC3C,MAAM,YAAY,GAAoC,EAAE,CAAC;IAEzD,IAAI,MAAM,EAAE;QACX,YAAY,GAAG,yBAAY,CAAC,MAAM,CAAC,CAAC;QACpC,IAAI,YAAY,KAAK,SAAS,EAAE;YAC/B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,6BAA6B,MAAM,GAAG,EAAE,CAAC;SACzE;KACD;IAED,IAAI,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE;QAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,EAAE;YAC3B,OAAO;gBACN,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,kDAAkD,KAAK,CAAC,MAAM,GAAG;aACxE,CAAC;SACF;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;YACzC,IAAI,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;gBACjC,OAAO;oBACN,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,4CAA4C,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,GAAG;iBACxE,CAAC;aACF;YACD,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;SACtC;KACD;IAED,IAAI,cAAc,KAAK,SAAS,IAAI,KAAK,CAAC,cAAc,CAAC,EAAE;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;AAzCD,4EAyCC","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, createChildLogger } from \"@fluidframework/telemetry-utils\";\nimport { CSVFileLogger } from \"./csvFileLogger\";\nimport { IFileLogger, ITelemetryOptions, OutputFormat } from \"./fileLogger\";\nimport { JSONFileLogger } from \"./jsonFileLogger\";\n\n/**\n * Create an {@link @fluidframework/telemetry-utils#ITelemetryLoggerExt} wrapped around provided {@link IFileLogger}.\n *\n * @remarks\n *\n * It is expected that all events be sent through the returned \"logger\" value.\n *\n * The \"fileLogger\" value should have its \"close()\" method called at the end of execution.\n *\n * Note: if an output format is not supplied, default is JSON.\n *\n * @returns Both the `IFileLogger` implementation and `ITelemetryLoggerExt` wrapper to be called.\n * @internal\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 = createChildLogger({\n\t\tlogger: fileLogger,\n\t\tnamespace: \"LocalSnapshotRunnerApp\",\n\t\tproperties: {\n\t\t\tall: { Event_Time: () => Date.now() },\n\t\t},\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 * @internal\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 * @internal\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"]}
@@ -0,0 +1,13 @@
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
+ * @internal
11
+ */
12
+ export declare function parseBundleAndExportFile(codeLoader: string, inputFile: string, outputFile: string, telemetryFile: string, options?: string, telemetryOptions?: ITelemetryOptions, timeout?: number, disableNetworkFetch?: boolean): Promise<IExportFileResponse>;
13
+ //# sourceMappingURL=parseBundleAndExportFile.d.ts.map
@@ -0,0 +1 @@
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;;;;GAIG;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"}
@@ -0,0 +1,88 @@
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.parseBundleAndExportFile = void 0;
31
+ const fs = __importStar(require("fs"));
32
+ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
33
+ const codeLoaderBundle_1 = require("./codeLoaderBundle");
34
+ const exportFile_1 = require("./exportFile");
35
+ const loggerUtils_1 = require("./logger/loggerUtils");
36
+ /* eslint-enable import/no-internal-modules */
37
+ const utils_1 = require("./utils");
38
+ const clientArgsValidationError = "Client_ArgsValidationError";
39
+ /**
40
+ * Parse a provided JS bundle, execute code on Container based on ODSP snapshot, and write result to file
41
+ * @param codeLoader - path to provided JS bundle that implements ICodeLoaderBundle (see codeLoaderBundle.ts)
42
+ * @internal
43
+ */
44
+ async function parseBundleAndExportFile(codeLoader, 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: "ParseBundleAndExportFile" }, async () => {
53
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
54
+ const codeLoaderBundle = require(codeLoader);
55
+ if (!(0, codeLoaderBundle_1.isCodeLoaderBundle)(codeLoaderBundle)) {
56
+ const eventName = clientArgsValidationError;
57
+ const errorMessage = "Code loader bundle is not of type ICodeLoaderBundle";
58
+ logger.sendErrorEvent({ eventName, message: errorMessage });
59
+ return { success: false, eventName, errorMessage };
60
+ }
61
+ const fluidExport = await codeLoaderBundle.fluidExport;
62
+ if (!(0, codeLoaderBundle_1.isFluidFileConverter)(fluidExport)) {
63
+ const eventName = clientArgsValidationError;
64
+ const errorMessage = "Fluid export from CodeLoaderBundle is not of type IFluidFileConverter";
65
+ logger.sendErrorEvent({ eventName, message: errorMessage });
66
+ return { success: false, eventName, errorMessage };
67
+ }
68
+ const argsValidationError = (0, utils_1.getArgsValidationError)(inputFile, outputFile, timeout);
69
+ if (argsValidationError) {
70
+ const eventName = clientArgsValidationError;
71
+ logger.sendErrorEvent({ eventName, message: argsValidationError });
72
+ return { success: false, eventName, errorMessage: argsValidationError };
73
+ }
74
+ fs.writeFileSync(outputFile, await (0, exportFile_1.createContainerAndExecute)((0, utils_1.getSnapshotFileContent)(inputFile), fluidExport, logger, options, timeout, disableNetworkFetch));
75
+ return { success: true };
76
+ });
77
+ }
78
+ catch (error) {
79
+ const eventName = "Client_UnexpectedError";
80
+ logger.sendErrorEvent({ eventName }, error);
81
+ return { success: false, eventName, errorMessage: "Unexpected error", error };
82
+ }
83
+ finally {
84
+ await fileLogger.close();
85
+ }
86
+ }
87
+ exports.parseBundleAndExportFile = parseBundleAndExportFile;
88
+ //# sourceMappingURL=parseBundleAndExportFile.js.map