typesense
Version:
Javascript Library for Typesense
109 lines • 4.6 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Collections_1 = tslib_1.__importDefault(require("./Collections"));
var Documents_1 = tslib_1.__importDefault(require("./Documents"));
var Errors_1 = require("./Errors");
var Overrides_1 = tslib_1.__importDefault(require("./Overrides"));
var Override_1 = tslib_1.__importDefault(require("./Override"));
var Synonyms_1 = tslib_1.__importDefault(require("./Synonyms"));
var Synonym_1 = tslib_1.__importDefault(require("./Synonym"));
var Document_1 = require("./Document");
var Collection = /** @class */ (function () {
function Collection(name, apiCall, configuration) {
this.name = name;
this.apiCall = apiCall;
this.configuration = configuration;
this.individualDocuments = {};
this.individualOverrides = {};
this.individualSynonyms = {};
this.name = name;
this.apiCall = apiCall;
this.configuration = configuration;
this._documents = new Documents_1.default(this.name, this.apiCall, this.configuration);
this._overrides = new Overrides_1.default(this.name, this.apiCall);
this._synonyms = new Synonyms_1.default(this.name, this.apiCall);
}
Collection.prototype.retrieve = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.apiCall.get(this.endpointPath())];
});
});
};
Collection.prototype.update = function (schema) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.apiCall.patch(this.endpointPath(), schema)];
});
});
};
Collection.prototype.delete = function () {
return tslib_1.__awaiter(this, arguments, void 0, function (options) {
if (options === void 0) { options = {}; }
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/, this.apiCall.delete(this.endpointPath(), options)];
});
});
};
Collection.prototype.exists = function () {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var e_1;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, this.retrieve()];
case 1:
_a.sent();
return [2 /*return*/, true];
case 2:
e_1 = _a.sent();
if (e_1 instanceof Errors_1.ObjectNotFound)
return [2 /*return*/, false];
throw e_1;
case 3: return [2 /*return*/];
}
});
});
};
Collection.prototype.documents = function (documentId) {
if (!documentId) {
return this._documents;
}
else {
if (this.individualDocuments[documentId] === undefined) {
this.individualDocuments[documentId] = new Document_1.Document(this.name, documentId, this.apiCall);
}
return this.individualDocuments[documentId];
}
};
Collection.prototype.overrides = function (overrideId) {
if (overrideId === undefined) {
return this._overrides;
}
else {
if (this.individualOverrides[overrideId] === undefined) {
this.individualOverrides[overrideId] = new Override_1.default(this.name, overrideId, this.apiCall);
}
return this.individualOverrides[overrideId];
}
};
Collection.prototype.synonyms = function (synonymId) {
if (synonymId === undefined) {
return this._synonyms;
}
else {
if (this.individualSynonyms[synonymId] === undefined) {
this.individualSynonyms[synonymId] = new Synonym_1.default(this.name, synonymId, this.apiCall);
}
return this.individualSynonyms[synonymId];
}
};
Collection.prototype.endpointPath = function () {
return "".concat(Collections_1.default.RESOURCEPATH, "/").concat(encodeURIComponent(this.name));
};
return Collection;
}());
exports.default = Collection;
//# sourceMappingURL=Collection.js.map