@eclipse-ditto/ditto-javascript-client-node
Version:
Node.js(r) implementation of Eclipse Ditto JavaScript API.
224 lines • 8.46 kB
JavaScript
;
/*!
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultFeaturesHandle = void 0;
const things_model_1 = require("../../model/things.model");
const request_options_1 = require("../../options/request.options");
const http_verb_1 = require("../constants/http-verb");
/**
* Handle to send Feature requests.
*/
class DefaultFeaturesHandle {
constructor(requestFactory, thingId) {
this.requestFactory = requestFactory;
this.thingId = thingId;
}
/**
* returns an instance of FeaturesHandle using the provided RequestSender.
*
* @param builder - The for the RequestSender to work with.
* @param thingId - The ThingId to use.
* @returns The FeaturesHandle
*/
static getInstance(builder, thingId) {
return new DefaultFeaturesHandle(builder.buildInstance('things'), thingId);
}
getFeatures(options) {
return this.requestFactory.fetchJsonRequest({
verb: http_verb_1.HttpVerb.GET,
parser: things_model_1.Features.fromObject,
id: this.thingId,
path: 'features',
requestOptions: options
});
}
getFeature(featureId, options) {
return this.requestFactory.fetchJsonRequest({
verb: http_verb_1.HttpVerb.GET,
parser: o => things_model_1.Feature.fromObject(o, featureId),
id: this.thingId,
path: `features/${featureId}`,
requestOptions: options
});
}
getDefinition(featureId, options) {
return this.requestFactory.fetchJsonRequest({
verb: http_verb_1.HttpVerb.GET,
parser: o => Object(o).map((obj) => String(obj)),
id: this.thingId,
path: `features/${featureId}/definition`,
requestOptions: options
});
}
getProperties(featureId, options) {
return this.requestFactory.fetchJsonRequest({
verb: http_verb_1.HttpVerb.GET,
parser: o => o,
id: this.thingId,
path: `features/${featureId}/properties`,
requestOptions: options
});
}
getProperty(featureId, propertyPath, options) {
return this.requestFactory.fetchJsonRequest({
verb: http_verb_1.HttpVerb.GET,
parser: o => o,
id: this.thingId,
path: `features/${featureId}/properties/${propertyPath}`,
requestOptions: options
});
}
deleteFeatures(options) {
return this.requestFactory.fetchRequest({
verb: http_verb_1.HttpVerb.DELETE,
id: this.thingId,
path: 'features',
requestOptions: options
});
}
deleteFeature(featureId, options) {
return this.requestFactory.fetchRequest({
verb: http_verb_1.HttpVerb.DELETE,
id: this.thingId,
path: `features/${featureId}`,
requestOptions: options
});
}
deleteDefinition(featureId, options) {
return this.requestFactory.fetchRequest({
verb: http_verb_1.HttpVerb.DELETE,
id: this.thingId,
path: `features/${featureId}/definition`,
requestOptions: options
});
}
deleteProperties(featureId, options) {
return this.requestFactory.fetchRequest({
verb: http_verb_1.HttpVerb.DELETE,
id: this.thingId,
path: `features/${featureId}/properties`,
requestOptions: options
});
}
deleteProperty(featureId, propertyPath, options) {
return this.requestFactory.fetchRequest({
verb: http_verb_1.HttpVerb.DELETE,
id: this.thingId,
path: `features/${featureId}/properties/${propertyPath}`,
requestOptions: options
});
}
putFeatures(features, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PUT,
parser: things_model_1.Features.fromObject,
id: this.thingId,
path: 'features',
requestOptions: options,
payload: things_model_1.Features.toObject(features)
});
}
putFeature(feature, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PUT,
parser: o => things_model_1.Feature.fromObject(o, feature.id),
id: this.thingId,
path: `features/${feature.id}`,
requestOptions: options,
payload: feature.toObject()
});
}
patchFeatures(features, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PATCH,
parser: things_model_1.Features.fromObject,
id: this.thingId,
path: 'features',
requestOptions: request_options_1.MatchOptionsHelper.getWithMergeHeader(options),
payload: things_model_1.Features.toObject(features)
});
}
patchFeature(feature, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PATCH,
parser: o => things_model_1.Feature.fromObject(o, feature.id),
id: this.thingId,
path: `features/${feature.id}`,
requestOptions: request_options_1.MatchOptionsHelper.getWithMergeHeader(options),
payload: feature.toObject()
});
}
putDefinition(featureId, definition, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PUT,
parser: o => o !== undefined ? Object.values(o).map((obj) => String(obj)) : [],
id: this.thingId,
path: `features/${featureId}/definition`,
requestOptions: options,
payload: definition
}); // `[${String(definition.map(s => `"${s}"`))}]`
}
patchDefinition(featureId, definition, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PATCH,
parser: o => o !== undefined ? Object.values(o).map((obj) => String(obj)) : [],
id: this.thingId,
path: `features/${featureId}/definition`,
requestOptions: request_options_1.MatchOptionsHelper.getWithMergeHeader(options),
payload: definition
});
}
putProperties(featureId, properties, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PUT,
parser: o => o,
id: this.thingId,
path: `features/${featureId}/properties`,
requestOptions: options,
payload: properties
});
}
putProperty(featureId, propertyPath, property, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PUT,
parser: o => o,
id: this.thingId,
path: `features/${featureId}/properties/${propertyPath}`,
requestOptions: options,
payload: property
});
}
patchProperties(featureId, properties, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PATCH,
parser: o => o,
id: this.thingId,
path: `features/${featureId}/properties`,
requestOptions: request_options_1.MatchOptionsHelper.getWithMergeHeader(options),
payload: properties
});
}
patchProperty(featureId, propertyPath, property, options) {
return this.requestFactory.fetchPutRequest({
verb: http_verb_1.HttpVerb.PATCH,
parser: o => o,
id: this.thingId,
path: `features/${featureId}/properties/${propertyPath}`,
requestOptions: request_options_1.MatchOptionsHelper.getWithMergeHeader(options),
payload: property
});
}
}
exports.DefaultFeaturesHandle = DefaultFeaturesHandle;
//# sourceMappingURL=features.js.map