UNPKG

baasic-sdk-javascript

Version:

JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).

107 lines (106 loc) 6.21 kB
"use strict"; /** * @module dynamicResourceRoute * @description Baasic Dynamic Resource Route Definition provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use Baasic Dynamic Resource Route Definition to obtain needed routes while other routes will be obtained through HAL. By convention, all route services use the same function names as their corresponding services. */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var inversify_1 = require("inversify"); var common_1 = require("../../common"); ; var _1 = require("./"); var contracts_1 = require("../../core/contracts"); var DynamicResourceRoute = /** @class */ (function (_super) { tslib_1.__extends(DynamicResourceRoute, _super); function DynamicResourceRoute(appOptions, dynamicResourceACLRoute, dynamicSchemaRoute) { var _this = _super.call(this, appOptions) || this; _this.appOptions = appOptions; _this.dynamicResourceACLRoute = dynamicResourceACLRoute; _this.dynamicSchemaRoute = dynamicSchemaRoute; _this.findRoute = 'resources/{schemaName}/{?searchQuery,page,rpp,sort,embed,fields}'; _this.getRoute = 'resources/{schemaName}/{id}/{?embed,fields}'; _this.createRoute = 'resources/{schemaName}'; _this.updateRoute = 'resources/{schemaName}/{id}/{?embed,fields,query}'; _this.patchRoute = 'resources/{schemaName}/{id}/{?embed,fields,query}'; _this.deleteRoute = 'resources/{schemaName}/{id}/{?query}'; _this.purgeRoute = 'resources/{schemaName}/purge'; return _this; } Object.defineProperty(DynamicResourceRoute.prototype, "acl", { get: function () { return this.dynamicResourceACLRoute; }, enumerable: true, configurable: true }); Object.defineProperty(DynamicResourceRoute.prototype, "dynamicSchema", { get: function () { return this.dynamicSchemaRoute; }, enumerable: true, configurable: true }); /** * Parses find route which can be expanded with additional options. Supported items are: * - `schemaName` - Name of the dynamic resource schema. * - `searchQuery` - A string referencing dynamic resource properties using the phrase or BQL (Baasic Query Language) search. * - `page` - A value used to set the page number, i.e. to retrieve certain dynamic resource subset from the storage. * - `rpp` - A value used to limit the size of result set per page. * - `sort` - A string used to set the dynamic resource property to sort the result collection by. * - `embed` - Comma separated list of resources to be contained within the current representation. * @method * @param options query resource options object * @example dynamicResourceRoute.find(options); **/ DynamicResourceRoute.prototype.find = function (schemaName, options) { return _super.prototype.baseFind.call(this, this.findRoute, this.utility.extend({ schemaName: schemaName }, options)); }; /** * Parses get route which must be expanded with the name of the previously created dynamic resource schema in the system and the Id of the previously created dynamic resource. Additional expand supported items are: * - `embed` - Comma separated list of resources to be contained within the current representation. * @method * @param id Unique identifier of dynamic resources * @param schemaName schema name * @param options query resource options object * @example dynamicResourceRoute.get(id, schemaName, options); **/ DynamicResourceRoute.prototype.get = function (id, schemaName, options) { return _super.prototype.baseGet.call(this, this.getRoute, id, this.utility.extend({ schemaName: schemaName }, options)); }; DynamicResourceRoute.prototype.create = function (schemaName) { var params = this.modelMapper.getParams(schemaName, undefined, 'schemaName'); return _super.prototype.baseCreate.call(this, this.createRoute, params); }; DynamicResourceRoute.prototype.update = function (schemaName, data, options) { var opt = options || {}; return _super.prototype.baseUpdate.call(this, this.updateRoute, data, this.utility.extend({ schemaName: schemaName }, opt)); }; DynamicResourceRoute.prototype.patch = function (schemaName, data, options) { var opt = options || {}; return _super.prototype.baseUpdate.call(this, this.patchRoute, data, this.utility.extend({ schemaName: schemaName }, opt), 'patch'); }; DynamicResourceRoute.prototype.delete = function (schemaName, data, options) { var opt = options || {}; return _super.prototype.baseDelete.call(this, this.deleteRoute, data, this.utility.extend({ schemaName: schemaName }, opt)); }; DynamicResourceRoute.prototype.purge = function (schemaName) { return _super.prototype.baseCreate.call(this, this.purgeRoute, { schemaName: schemaName }); }; DynamicResourceRoute = tslib_1.__decorate([ inversify_1.injectable(), tslib_1.__param(0, inversify_1.inject(contracts_1.TYPES.IAppOptions)), tslib_1.__param(1, inversify_1.inject(_1.TYPES.DynamicResourceACLRoute)), tslib_1.__param(2, inversify_1.inject(_1.TYPES.DynamicSchemaRoute)), tslib_1.__metadata("design:paramtypes", [Object, _1.DynamicResourceACLRoute, _1.DynamicSchemaRoute]) ], DynamicResourceRoute); return DynamicResourceRoute; }(common_1.BaseRoute)); exports.DynamicResourceRoute = DynamicResourceRoute; /** * @overview ***Notes:** - Refer to the [Baasic REST API](http://dev.baasic.com/api/reference/home) for detailed information about available Baasic REST API end-points. - [URI Template](https://github.com/Baasic/uritemplate-js) syntax enables expanding the Baasic route templates to Baasic REST URIs providing it with an object that contains URI parameters. - All end-point objects are transformed by the associated route definition. */