@cognite/sdk-beta
Advanced tools
Comparing version 5.9.0 to 5.10.0
@@ -124,4 +124,126 @@ 'use strict'; | ||
var version="5.9.0"; | ||
var UploadAlreadyFinishedError = /** @class */ (function (_super) { | ||
__extends(UploadAlreadyFinishedError, _super); | ||
function UploadAlreadyFinishedError() { | ||
return _super.call(this, 'Upload has already finished') || this; | ||
} | ||
return UploadAlreadyFinishedError; | ||
}(Error)); | ||
var FilesMultipartUploadSessionAPI = /** @class */ (function (_super) { | ||
__extends(FilesMultipartUploadSessionAPI, _super); | ||
function FilesMultipartUploadSessionAPI() { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var _this = _super.call(this, args[0], args[1], args[2]) || this; | ||
_a = __read(args, 4), _this.multiPartFileUploadResponse = _a[3]; | ||
_this.uploadedUrls = _this.multiPartFileUploadResponse.uploadUrls.map(function (_) { return false; }); | ||
_this.finished = false; | ||
return _this; | ||
} | ||
FilesMultipartUploadSessionAPI.prototype.uploadPart = function (partNumber, fileContent) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var hasFileContent, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
hasFileContent = fileContent != null; | ||
if (!hasFileContent) { | ||
throw Error('you are uploading an empty content'); | ||
} | ||
if (partNumber < 0 || | ||
partNumber >= this.multiPartFileUploadResponse.uploadUrls.length) { | ||
throw Error('part number is greater than the number of parts'); | ||
} | ||
if (!this.canCompleteUpload()) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.completeMultiPartUpload()]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
case 2: | ||
if (this.alreadyUploadedPart(partNumber)) { | ||
return [2 /*return*/]; | ||
} | ||
if (this.multiPartFileUploadResponse.uploadUrls[partNumber] === null) { | ||
throw Error('part number is not valid'); | ||
} | ||
if (!(fileContent != null)) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, this.put(this.multiPartFileUploadResponse.uploadUrls[partNumber], { | ||
data: fileContent, | ||
})]; | ||
case 3: | ||
response = _a.sent(); | ||
if (!(response.status === 200 || response.status === 201)) return [3 /*break*/, 6]; | ||
this.uploadedUrls[partNumber] = true; | ||
if (!this.canCompleteUpload()) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, this.completeMultiPartUpload()]; | ||
case 4: | ||
_a.sent(); | ||
_a.label = 5; | ||
case 5: return [2 /*return*/, { partNumber: partNumber, status: response.status }]; | ||
case 6: return [2 /*return*/, { partNumber: partNumber, status: response.status }]; | ||
case 7: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
FilesMultipartUploadSessionAPI.prototype.alreadyUploadedPart = function (partNumber) { | ||
return this.uploadedUrls[partNumber]; | ||
}; | ||
FilesMultipartUploadSessionAPI.prototype.canCompleteUpload = function () { | ||
return (this.uploadedUrls.length !== 0 && this.getNotCompletedParts().length === 0); | ||
}; | ||
FilesMultipartUploadSessionAPI.prototype.completeMultiPartUpload = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var path, requestBody, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (this.finished) { | ||
throw new UploadAlreadyFinishedError(); | ||
} | ||
if (!this.canCompleteUpload()) { | ||
return [2 /*return*/]; | ||
} | ||
path = this.url('completemultipartupload'); | ||
requestBody = { | ||
id: this.multiPartFileUploadResponse.id, | ||
uploadId: this.multiPartFileUploadResponse.uploadId, | ||
}; | ||
return [4 /*yield*/, this.post(path, { | ||
data: requestBody, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.status !== 200) { | ||
throw Error('upload cannot be completed'); | ||
} | ||
this.finished = true; | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
FilesMultipartUploadSessionAPI.prototype.getNotCompletedParts = function () { | ||
return this.uploadedUrls.reduce(function (acc, curr, index) { | ||
if (curr === false) { | ||
acc.push(index); | ||
} | ||
return acc; | ||
}, []); | ||
}; | ||
FilesMultipartUploadSessionAPI.prototype.getMultiPartFileUploadId = function () { | ||
return this.multiPartFileUploadResponse.uploadId; | ||
}; | ||
FilesMultipartUploadSessionAPI.prototype.getFinished = function () { | ||
return this.finished; | ||
}; | ||
return FilesMultipartUploadSessionAPI; | ||
}(sdkCore.BaseResourceAPI)); | ||
var version="5.10.0"; | ||
// Copyright 2022 Cognite AS | ||
@@ -312,2 +434,84 @@ var ChannelsAPI = /** @class */ (function (_super) { | ||
// Copyright 2020 Cognite AS | ||
var MonitoringTaskModelExternalId = { | ||
THRESHOLD: 'threshold', | ||
DOUBLE_THRESHOLD: 'double_threshold', | ||
}; | ||
var AlertStatus = { | ||
FIRING: 'FIRING', | ||
PENDING: 'PENDING', | ||
}; | ||
var AlertSortProperty = { | ||
CREATED_TIME: 'createdTime', | ||
LAST_TRIGGERED_TIME: 'lastTriggeredTime', | ||
}; | ||
// Copyright 2020 Cognite AS | ||
var FilesAPI = /** @class */ (function (_super) { | ||
__extends(FilesAPI, _super); | ||
function FilesAPI() { | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var _this = _super.apply(this, __spread(args)) || this; | ||
_this.limits = { | ||
minimumNumberOfParts: 1, | ||
maxNumberOfParts: 250, | ||
}; | ||
_a = __read(args, 3), _this._baseUrl = _a[0], _this._client = _a[1], _this._map = _a[2]; | ||
return _this; | ||
} | ||
/** | ||
* [Init a multipart file upload](https://api-docs.cognite.com/20230101/tag/Files/operation/initMultiPartUpload) | ||
* | ||
* ```js | ||
* const numberOfParts = 5; | ||
* // automatic upload: | ||
* const multiPartUploadApi = await client.files.upload({name: 'examplefile.jpg', mimeType: 'image/jpeg'}, numberOfParts); | ||
* ``` | ||
*/ | ||
FilesAPI.prototype.multipartUploadSession = function (fileInfo, parts, overwrite) { | ||
if (overwrite === void 0) { overwrite = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var response, multipartUploadSession; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.getMultipartUploadSession(fileInfo, parts, overwrite)]; | ||
case 1: | ||
response = _a.sent(); | ||
multipartUploadSession = new FilesMultipartUploadSessionAPI(this._baseUrl, this._client, this._map, response.data); | ||
return [2 /*return*/, this.addToMapAndReturn(multipartUploadSession, response)]; | ||
} | ||
}); | ||
}); | ||
}; | ||
FilesAPI.prototype.getMultipartUploadSession = function (fileInfo, parts, overwrite) { | ||
if (overwrite === void 0) { overwrite = false; } | ||
return __awaiter(this, void 0, void 0, function () { | ||
var path, params, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
if (parts < this.limits.minimumNumberOfParts || | ||
parts > this.limits.maxNumberOfParts) { | ||
throw Error('parts must be greater than 0 and less than 250'); | ||
} | ||
path = this.url('initmultipartupload'); | ||
params = { overwrite: overwrite, parts: parts }; | ||
return [4 /*yield*/, this.post(path, { | ||
params: params, | ||
data: fileInfo, | ||
})]; | ||
case 1: | ||
response = _a.sent(); | ||
return [2 /*return*/, response]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return FilesAPI; | ||
}(sdk.FilesAPI)); | ||
// Copyright 2023 Cognite AS | ||
@@ -494,2 +698,9 @@ var MonitoringTasksAPI = /** @class */ (function (_super) { | ||
}); | ||
Object.defineProperty(CogniteClient.prototype, "files", { | ||
get: function () { | ||
return sdkCore.accessApi(this.filesApi); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(CogniteClient.prototype, "monitoringTasks", { | ||
@@ -520,2 +731,3 @@ get: function () { | ||
this.alertsApi = this.apiFactory(AlertsAPI, 'alerts'); | ||
this.filesApi = this.apiFactory(FilesAPI, 'files'); | ||
this.monitoringTasksApi = this.apiFactory(MonitoringTasksAPI, 'monitoringtasks'); | ||
@@ -527,16 +739,2 @@ this.dataPointsApi = this.apiFactory(DataPointsAPI, 'timeseries/data'); | ||
// Copyright 2020 Cognite AS | ||
var MonitoringTaskModelExternalId = { | ||
THRESHOLD: 'threshold', | ||
DOUBLE_THRESHOLD: 'double_threshold', | ||
}; | ||
var AlertStatus = { | ||
FIRING: 'FIRING', | ||
PENDING: 'PENDING', | ||
}; | ||
var AlertSortProperty = { | ||
CREATED_TIME: 'createdTime', | ||
LAST_TRIGGERED_TIME: 'lastTriggeredTime', | ||
}; | ||
Object.keys(sdk).forEach(function (k) { | ||
@@ -548,3 +746,4 @@ if (k !== 'default') exports[k] = sdk[k]; | ||
exports.CogniteClient = CogniteClient; | ||
exports.FilesMultipartUploadSessionAPI = FilesMultipartUploadSessionAPI; | ||
exports.MonitoringTaskModelExternalId = MonitoringTaskModelExternalId; | ||
//# sourceMappingURL=index.js.map |
import { ClientOptions, CogniteClient as CogniteClientStable } from '@cognite/sdk'; | ||
import { AlertsAPI } from './api/alerts/alertsApi'; | ||
import { FilesAPI } from './api/files/filesApi'; | ||
import { MonitoringTasksAPI } from './api/monitoringTasks/monitoringTasksApi'; | ||
@@ -9,2 +10,3 @@ import { DataPointsAPI } from './api/dataPoints/dataPointsApi'; | ||
private alertsApi?; | ||
protected filesApi?: FilesAPI; | ||
private monitoringTasksApi?; | ||
@@ -30,2 +32,3 @@ /** | ||
get alerts(): AlertsAPI; | ||
get files(): FilesAPI; | ||
get monitoringTasks(): MonitoringTasksAPI; | ||
@@ -32,0 +35,0 @@ get datapoints(): DataPointsAPI; |
export * from '@cognite/sdk'; | ||
export { FilesMultipartUploadSessionAPI } from './api/files/filesMultipartUploadSessionApi'; | ||
export { default as CogniteClient } from './cogniteClient'; | ||
export * from './types'; | ||
export { Aggregate, DatapointAggregate, DatapointAggregates, Datapoints, DatapointsMonthlyGranularityMultiQuery, DatapointsMultiQuery, DatapointsMultiQueryBase, DatapointsQuery, DatapointsQueryExternalId, DatapointsQueryId, DatapointsQueryProperties, DoubleDatapoint, DoubleDatapoints, StringDatapoint, StringDatapoints, } from './types'; |
@@ -1,2 +0,2 @@ | ||
import { Aggregate as AggregateStable, DatapointAggregate as DatapointAggregateStable, DatapointAggregates as DatapointAggregatesStable, DatapointsMultiQueryBase as DataPointsMultiQueryBaseStable, DatapointsQueryProperties as DatapointsQueryPropertiesStable, DateRange, DoubleDatapoint as DoubleDatapointStable, DoubleDatapoints as DoubleDatapointsStable, Metadata, MetadataPatch, SinglePatchRequired, SinglePatchRequiredString, SinglePatchString, StringDatapoint as StringDatapointStable, StringDatapoints as StringDatapointsStable, Timestamp, SortOrder } from '@cognite/sdk'; | ||
import { Aggregate as AggregateStable, DatapointAggregate as DatapointAggregateStable, DatapointAggregates as DatapointAggregatesStable, DatapointsMultiQueryBase as DataPointsMultiQueryBaseStable, DatapointsQueryProperties as DatapointsQueryPropertiesStable, DateRange, DoubleDatapoint as DoubleDatapointStable, DoubleDatapoints as DoubleDatapointsStable, Metadata, MetadataPatch, SinglePatchRequired, SinglePatchRequiredString, SinglePatchString, StringDatapoint as StringDatapointStable, StringDatapoints as StringDatapointsStable, Timestamp, SortOrder, FileInfo } from '@cognite/sdk'; | ||
import { CogniteExternalId, CogniteInternalId, ExternalId, FilterQuery, InternalId } from '@cognite/sdk-core'; | ||
@@ -266,2 +266,10 @@ export * from '@cognite/sdk'; | ||
} | ||
export interface MultiPartFileUploadResponse extends FileInfo { | ||
uploadUrls: string[]; | ||
uploadId: string; | ||
} | ||
export interface MultiPartFileChunkResponse { | ||
partNumber: number; | ||
status: number; | ||
} | ||
export interface DatapointsMultiQuery extends DatapointsMultiQueryBase { | ||
@@ -268,0 +276,0 @@ items: DatapointsQuery[]; |
@@ -9,3 +9,3 @@ { | ||
"types": "dist/src/index.d.ts", | ||
"version": "5.9.0", | ||
"version": "5.10.0", | ||
"scripts": { | ||
@@ -26,3 +26,3 @@ "clean": "rm -rf dist/ docs/ codeSnippets/", | ||
"dependencies": { | ||
"@cognite/sdk": "^9.13.0", | ||
"@cognite/sdk": "^9.14.0", | ||
"@cognite/sdk-core": "^4.10.1" | ||
@@ -36,3 +36,3 @@ }, | ||
}, | ||
"gitHead": "ee8ccf0d586117f09ab1c72f58cfc7dc52cd1abb" | ||
"gitHead": "ca401b22c9c476e15b1e789d7b16f039b82cb977" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
99831
17
1214
+ Added@cognite/sdk@9.16.1(transitive)
- Removed@cognite/sdk@9.17.0(transitive)
Updated@cognite/sdk@^9.14.0