@daytonaio/sdk 0.0.0-dev
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/README.md +146 -0
- package/package.json +39 -0
- package/src/Daytona.d.ts +331 -0
- package/src/Daytona.js +400 -0
- package/src/Daytona.js.map +1 -0
- package/src/FileSystem.d.ts +270 -0
- package/src/FileSystem.js +302 -0
- package/src/FileSystem.js.map +1 -0
- package/src/Git.d.ts +211 -0
- package/src/Git.js +275 -0
- package/src/Git.js.map +1 -0
- package/src/Image.d.ts +264 -0
- package/src/Image.js +565 -0
- package/src/Image.js.map +1 -0
- package/src/LspServer.d.ts +173 -0
- package/src/LspServer.js +209 -0
- package/src/LspServer.js.map +1 -0
- package/src/ObjectStorage.d.ts +85 -0
- package/src/ObjectStorage.js +231 -0
- package/src/ObjectStorage.js.map +1 -0
- package/src/Process.d.ts +246 -0
- package/src/Process.js +290 -0
- package/src/Process.js.map +1 -0
- package/src/Sandbox.d.ts +266 -0
- package/src/Sandbox.js +389 -0
- package/src/Sandbox.js.map +1 -0
- package/src/Snapshot.d.ts +116 -0
- package/src/Snapshot.js +187 -0
- package/src/Snapshot.js.map +1 -0
- package/src/Volume.d.ts +79 -0
- package/src/Volume.js +97 -0
- package/src/Volume.js.map +1 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.d.ts +11 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.js +358 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.d.ts +5 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.js +17 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
- package/src/errors/DaytonaError.d.ts +10 -0
- package/src/errors/DaytonaError.js +20 -0
- package/src/errors/DaytonaError.js.map +1 -0
- package/src/index.d.ts +15 -0
- package/src/index.js +32 -0
- package/src/index.js.map +1 -0
- package/src/types/Charts.d.ts +151 -0
- package/src/types/Charts.js +46 -0
- package/src/types/Charts.js.map +1 -0
- package/src/types/ExecuteResponse.d.ts +26 -0
- package/src/types/ExecuteResponse.js +7 -0
- package/src/types/ExecuteResponse.js.map +1 -0
- package/src/utils/ArtifactParser.d.ts +13 -0
- package/src/utils/ArtifactParser.js +55 -0
- package/src/utils/ArtifactParser.js.map +1 -0
- package/src/utils/Path.d.ts +1 -0
- package/src/utils/Path.js +61 -0
- package/src/utils/Path.js.map +1 -0
- package/src/utils/Stream.d.ts +13 -0
- package/src/utils/Stream.js +82 -0
- package/src/utils/Stream.js.map +1 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ChartType = void 0;
|
|
8
|
+
exports.parseChart = parseChart;
|
|
9
|
+
/**
|
|
10
|
+
* Chart types
|
|
11
|
+
*/
|
|
12
|
+
var ChartType;
|
|
13
|
+
(function (ChartType) {
|
|
14
|
+
ChartType["LINE"] = "line";
|
|
15
|
+
ChartType["SCATTER"] = "scatter";
|
|
16
|
+
ChartType["BAR"] = "bar";
|
|
17
|
+
ChartType["PIE"] = "pie";
|
|
18
|
+
ChartType["BOX_AND_WHISKER"] = "box_and_whisker";
|
|
19
|
+
ChartType["COMPOSITE_CHART"] = "composite_chart";
|
|
20
|
+
ChartType["UNKNOWN"] = "unknown";
|
|
21
|
+
})(ChartType || (exports.ChartType = ChartType = {}));
|
|
22
|
+
function parseChart(data) {
|
|
23
|
+
switch (data.type) {
|
|
24
|
+
case ChartType.LINE:
|
|
25
|
+
return { ...data };
|
|
26
|
+
case ChartType.SCATTER:
|
|
27
|
+
return { ...data };
|
|
28
|
+
case ChartType.BAR:
|
|
29
|
+
return { ...data };
|
|
30
|
+
case ChartType.PIE:
|
|
31
|
+
return { ...data };
|
|
32
|
+
case ChartType.BOX_AND_WHISKER:
|
|
33
|
+
return { ...data };
|
|
34
|
+
case ChartType.COMPOSITE_CHART:
|
|
35
|
+
// eslint-disable-next-line no-case-declarations
|
|
36
|
+
const charts = data.elements.map((g) => parseChart(g));
|
|
37
|
+
delete data.data;
|
|
38
|
+
return {
|
|
39
|
+
...data,
|
|
40
|
+
data: charts,
|
|
41
|
+
};
|
|
42
|
+
default:
|
|
43
|
+
return { ...data, type: ChartType.UNKNOWN };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=Charts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Charts.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/types/Charts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAsKH,gCAuBC;AA3LD;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,0BAAa,CAAA;IACb,gCAAmB,CAAA;IACnB,wBAAW,CAAA;IACX,wBAAW,CAAA;IACX,gDAAmC,CAAA;IACnC,gDAAmC,CAAA;IACnC,gCAAmB,CAAA;AACrB,CAAC,EARW,SAAS,yBAAT,SAAS,QAQpB;AAyJD,SAAgB,UAAU,CAAC,IAAS;IAClC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,SAAS,CAAC,IAAI;YACjB,OAAO,EAAE,GAAG,IAAI,EAAe,CAAA;QACjC,KAAK,SAAS,CAAC,OAAO;YACpB,OAAO,EAAE,GAAG,IAAI,EAAkB,CAAA;QACpC,KAAK,SAAS,CAAC,GAAG;YAChB,OAAO,EAAE,GAAG,IAAI,EAAc,CAAA;QAChC,KAAK,SAAS,CAAC,GAAG;YAChB,OAAO,EAAE,GAAG,IAAI,EAAc,CAAA;QAChC,KAAK,SAAS,CAAC,eAAe;YAC5B,OAAO,EAAE,GAAG,IAAI,EAAwB,CAAA;QAC1C,KAAK,SAAS,CAAC,eAAe;YAC5B,gDAAgD;YAChD,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;YAC3D,OAAO,IAAI,CAAC,IAAI,CAAA;YAChB,OAAO;gBACL,GAAG,IAAI;gBACP,IAAI,EAAE,MAAM;aACK,CAAA;QACrB;YACE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO,EAAW,CAAA;IACxD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ExecuteResponse as ClientExecuteResponse } from '@daytonaio/api-client';
|
|
2
|
+
import { Chart } from './Charts';
|
|
3
|
+
/**
|
|
4
|
+
* Artifacts from the command execution.
|
|
5
|
+
*
|
|
6
|
+
* @interface
|
|
7
|
+
* @property stdout - Standard output from the command, same as `result` in `ExecuteResponse`
|
|
8
|
+
* @property charts - List of chart metadata from matplotlib
|
|
9
|
+
*/
|
|
10
|
+
export interface ExecutionArtifacts {
|
|
11
|
+
stdout: string;
|
|
12
|
+
charts?: Chart[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Response from the command execution.
|
|
16
|
+
*
|
|
17
|
+
* @interface
|
|
18
|
+
* @property exitCode - The exit code from the command execution
|
|
19
|
+
* @property result - The output from the command execution
|
|
20
|
+
* @property artifacts - Artifacts from the command execution
|
|
21
|
+
*/
|
|
22
|
+
export interface ExecuteResponse extends ClientExecuteResponse {
|
|
23
|
+
exitCode: number;
|
|
24
|
+
result: string;
|
|
25
|
+
artifacts?: ExecutionArtifacts;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecuteResponse.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/types/ExecuteResponse.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ExecutionArtifacts } from '../types/ExecuteResponse';
|
|
2
|
+
/**
|
|
3
|
+
* Utility class for parsing artifacts from command output
|
|
4
|
+
*/
|
|
5
|
+
export declare class ArtifactParser {
|
|
6
|
+
/**
|
|
7
|
+
* Parses artifacts from command output text
|
|
8
|
+
*
|
|
9
|
+
* @param output - Raw output from command execution
|
|
10
|
+
* @returns Parsed artifacts including stdout and charts
|
|
11
|
+
*/
|
|
12
|
+
static parseArtifacts(output: string): ExecutionArtifacts;
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ArtifactParser = void 0;
|
|
8
|
+
const Charts_1 = require("../types/Charts");
|
|
9
|
+
/**
|
|
10
|
+
* Utility class for parsing artifacts from command output
|
|
11
|
+
*/
|
|
12
|
+
class ArtifactParser {
|
|
13
|
+
/**
|
|
14
|
+
* Parses artifacts from command output text
|
|
15
|
+
*
|
|
16
|
+
* @param output - Raw output from command execution
|
|
17
|
+
* @returns Parsed artifacts including stdout and charts
|
|
18
|
+
*/
|
|
19
|
+
static parseArtifacts(output) {
|
|
20
|
+
const charts = [];
|
|
21
|
+
let stdout = output;
|
|
22
|
+
// Split output by lines to find artifact markers
|
|
23
|
+
const lines = output.split('\n');
|
|
24
|
+
const artifactLines = [];
|
|
25
|
+
for (const line of lines) {
|
|
26
|
+
// Look for the artifact marker pattern
|
|
27
|
+
if (line.startsWith('dtn_artifact_k39fd2:')) {
|
|
28
|
+
artifactLines.push(line);
|
|
29
|
+
try {
|
|
30
|
+
const artifactJson = line.substring('dtn_artifact_k39fd2:'.length).trim();
|
|
31
|
+
const artifactData = JSON.parse(artifactJson);
|
|
32
|
+
if (artifactData.type === 'chart' && artifactData.value) {
|
|
33
|
+
const chartData = artifactData.value;
|
|
34
|
+
charts.push((0, Charts_1.parseChart)(chartData));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
// Skip invalid artifacts
|
|
39
|
+
console.warn('Failed to parse artifact:', error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Remove artifact lines from stdout along with their following newlines
|
|
44
|
+
for (const line of artifactLines) {
|
|
45
|
+
stdout = stdout.replace(line + '\n', '');
|
|
46
|
+
stdout = stdout.replace(line, '');
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
stdout,
|
|
50
|
+
charts: charts.length > 0 ? charts : undefined,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.ArtifactParser = ArtifactParser;
|
|
55
|
+
//# sourceMappingURL=ArtifactParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArtifactParser.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/utils/ArtifactParser.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAAmD;AAGnD;;GAEG;AACH,MAAa,cAAc;IACzB;;;;;OAKG;IACI,MAAM,CAAC,cAAc,CAAC,MAAc;QACzC,MAAM,MAAM,GAAY,EAAE,CAAA;QAC1B,IAAI,MAAM,GAAG,MAAM,CAAA;QAEnB,iDAAiD;QACjD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAChC,MAAM,aAAa,GAAa,EAAE,CAAA;QAElC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,uCAAuC;YACvC,IAAI,IAAI,CAAC,UAAU,CAAC,sBAAsB,CAAC,EAAE,CAAC;gBAC5C,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBAExB,IAAI,CAAC;oBACH,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAA;oBACzE,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;oBAE7C,IAAI,YAAY,CAAC,IAAI,KAAK,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,CAAC;wBACxD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAA;wBACpC,MAAM,CAAC,IAAI,CAAC,IAAA,mBAAU,EAAC,SAAS,CAAC,CAAC,CAAA;oBACpC,CAAC;gBACH,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,yBAAyB;oBACzB,OAAO,CAAC,IAAI,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAA;gBAClD,CAAC;YACH,CAAC;QACH,CAAC;QAED,wEAAwE;QACxE,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;YACjC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,EAAE,EAAE,CAAC,CAAA;YACxC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QACnC,CAAC;QAED,OAAO;YACL,MAAM;YACN,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC/C,CAAA;IACH,CAAC;CACF;AA9CD,wCA8CC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function prefixRelativePath(prefix: string, path?: string): string;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
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 () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.prefixRelativePath = prefixRelativePath;
|
|
41
|
+
const _path = __importStar(require("path"));
|
|
42
|
+
function prefixRelativePath(prefix, path) {
|
|
43
|
+
let result = prefix;
|
|
44
|
+
if (path) {
|
|
45
|
+
path = path.trim();
|
|
46
|
+
if (path === '~') {
|
|
47
|
+
result = prefix;
|
|
48
|
+
}
|
|
49
|
+
else if (path.startsWith('~/')) {
|
|
50
|
+
result = _path.join(prefix, path.slice(2));
|
|
51
|
+
}
|
|
52
|
+
else if (_path.isAbsolute(path)) {
|
|
53
|
+
result = path;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result = _path.join(prefix, path);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=Path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Path.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/utils/Path.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIH,gDAiBC;AAnBD,4CAA6B;AAE7B,SAAgB,kBAAkB,CAAC,MAAc,EAAE,IAAa;IAC9D,IAAI,MAAM,GAAG,MAAM,CAAA;IAEnB,IAAI,IAAI,EAAE,CAAC;QACT,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;QAClB,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,GAAG,MAAM,CAAA;QACjB,CAAC;aAAM,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5C,CAAC;aAAM,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,MAAM,GAAG,IAAI,CAAA;QACf,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACnC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process a streaming response from a URL. Stream will terminate if the server-side stream
|
|
3
|
+
* ends or if the shouldTerminate function returns True.
|
|
4
|
+
*
|
|
5
|
+
* @param getStream - A function that returns a promise of an AxiosResponse with .data being the stream
|
|
6
|
+
* @param onChunk - A function to process each chunk of the response
|
|
7
|
+
* @param shouldTerminate - A function to check if the response should be terminated
|
|
8
|
+
* @param chunkTimeout - The timeout for each chunk
|
|
9
|
+
* @param requireConsecutiveTermination - Whether to require two consecutive termination signals
|
|
10
|
+
* to terminate the stream.
|
|
11
|
+
*/
|
|
12
|
+
export declare function processStreamingResponse(getStream: () => Promise<any>, // can return AxiosResponse with .data being the stream
|
|
13
|
+
onChunk: (chunk: string) => void, shouldTerminate: () => Promise<boolean>, chunkTimeout?: number, requireConsecutiveTermination?: boolean): Promise<void>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.processStreamingResponse = processStreamingResponse;
|
|
8
|
+
/**
|
|
9
|
+
* Process a streaming response from a URL. Stream will terminate if the server-side stream
|
|
10
|
+
* ends or if the shouldTerminate function returns True.
|
|
11
|
+
*
|
|
12
|
+
* @param getStream - A function that returns a promise of an AxiosResponse with .data being the stream
|
|
13
|
+
* @param onChunk - A function to process each chunk of the response
|
|
14
|
+
* @param shouldTerminate - A function to check if the response should be terminated
|
|
15
|
+
* @param chunkTimeout - The timeout for each chunk
|
|
16
|
+
* @param requireConsecutiveTermination - Whether to require two consecutive termination signals
|
|
17
|
+
* to terminate the stream.
|
|
18
|
+
*/
|
|
19
|
+
async function processStreamingResponse(getStream, // can return AxiosResponse with .data being the stream
|
|
20
|
+
onChunk, shouldTerminate, chunkTimeout = 2000, requireConsecutiveTermination = true) {
|
|
21
|
+
const response = await getStream();
|
|
22
|
+
const stream = response.data;
|
|
23
|
+
let nextChunkPromise = null;
|
|
24
|
+
let exitCheckStreak = 0;
|
|
25
|
+
let terminated = false;
|
|
26
|
+
const readNext = () => {
|
|
27
|
+
return new Promise((resolve) => {
|
|
28
|
+
const onData = (data) => {
|
|
29
|
+
cleanup();
|
|
30
|
+
resolve(data);
|
|
31
|
+
};
|
|
32
|
+
const cleanup = () => {
|
|
33
|
+
stream.off('data', onData);
|
|
34
|
+
};
|
|
35
|
+
stream.once('data', onData);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const terminationPromise = new Promise((resolve, reject) => {
|
|
39
|
+
stream.on('end', () => {
|
|
40
|
+
terminated = true;
|
|
41
|
+
resolve();
|
|
42
|
+
});
|
|
43
|
+
stream.on('close', () => {
|
|
44
|
+
terminated = true;
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
stream.on('error', (err) => {
|
|
48
|
+
terminated = true;
|
|
49
|
+
reject(err);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
const processLoop = async () => {
|
|
53
|
+
while (!terminated) {
|
|
54
|
+
if (!nextChunkPromise) {
|
|
55
|
+
nextChunkPromise = readNext();
|
|
56
|
+
}
|
|
57
|
+
const timeoutPromise = new Promise((resolve) => setTimeout(() => resolve(null), chunkTimeout));
|
|
58
|
+
const result = await Promise.race([nextChunkPromise, timeoutPromise]);
|
|
59
|
+
if (result instanceof Buffer) {
|
|
60
|
+
onChunk(result.toString('utf8'));
|
|
61
|
+
nextChunkPromise = null;
|
|
62
|
+
exitCheckStreak = 0;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const shouldEnd = await shouldTerminate();
|
|
66
|
+
if (shouldEnd) {
|
|
67
|
+
exitCheckStreak += 1;
|
|
68
|
+
if (!requireConsecutiveTermination || exitCheckStreak > 1) {
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
exitCheckStreak = 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
stream.destroy();
|
|
78
|
+
stream.removeAllListeners();
|
|
79
|
+
};
|
|
80
|
+
await Promise.race([processLoop(), terminationPromise]);
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=Stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Stream.js","sourceRoot":"","sources":["../../../../../libs/sdk-typescript/src/utils/Stream.ts"],"names":[],"mappings":"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"}
|