UNPKG

baasic-sdk-angular

Version:

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

456 lines (454 loc) 27.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var core_1 = require("@angular/core"); var index_1 = require("../index"); var DynamicResourceService = /** @class */ (function () { function DynamicResourceService(baasicApp) { this.baasicApp = baasicApp; } /** * Returns a promise that is resolved once the find action has been performed. Success response returns a list of dynamic resources matching the given criteria. * @method * @param schemaName Name of dynamic resource schema whose dynamic resources need to be retrieved. * @param options Query resource options object. * @returns Promise that is resolved once the find action has been performed. * @example DynamicResourceService.find('<schema-name>', { pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.find = function (schemaName, options) { return this.baasicApp.dynamicResourceModule.find(schemaName, options); }; /** * Returns a promise that is resolved once the get action has been performed. Success response returns the specified dynamic resource. * @method * @example DynamicResourceService.get('<schema-name>', '<dynamic-resource-id>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.get = function (schemaName, id, options) { return this.baasicApp.dynamicResourceModule.get(schemaName, id, options); }; /** * Returns a promise that is resolved once the create dynamic resource action has been performed; this action creates a new dynamic resource item. * @method * @param schemaName Name of dynamic resource schema that needs to be updated with new dynamic resource. * @param data A JSON object that needs to be inserted into the system as dynamic resource. JSON object is an unordered collection of zero or more key/value pairs structured using the standard JSON syntax rules. * @example DynamicModuleService.create('<schema-name>', { id : '', description : '<description>' }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.create = function (schemaName, data) { return this.baasicApp.dynamicResourceModule.create(schemaName, data); }; /** * Returns a promise that is resolved once the update action has been performed; this action updates a dynamic resource item. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicDynamicResourceRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * @method * @param data A JSON object used to update specified dynamic resource. JSON object is an unordered collection of zero or more key/value pairs structured using the standard JSON syntax rules. * @param options Options object. * @example // dynamicResource is a resource previously fetched using get action. dynamicResource.description = '<description>'; baasicDynamicResourceClient.update(dynamicResource, { query: "where field = 'value' " }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.update = function (schemaName, data, options) { return this.baasicApp.dynamicResourceModule.update(schemaName, data, options); }; /** * Returns a promise that is resolved once the patch action has been performed; this action patches an existing dynamic resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicDynamicResourceRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * @method * @param data JSON object used for partial update of specified dynamic resource. JSON object is an unordered collection of zero or more key/value pairs structured using the standard JSON syntax rules. * @param options Options object. * @example // dynamicResource is a resource previously fetched using get action. dynamicResource.description = '<new-description>'; dynamicResource.newField = '<newfield-value>'; DynamicResourceService.patch(dynamicResource, { query: "where field = 'value' " }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.patch = function (schemaName, data, options) { return this.baasicApp.dynamicResourceModule.patch(schemaName, data, options); }; /** * Returns a promise that is resolved once the remove action has been performed. This action will remove a dynamic resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicDynamicResourceRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * @method * @param data JSON object used to delete specified dynamic resource. JSON object is an unordered collection of zero or more key/value pairs structured using the standard JSON syntax rules. * @example // dynamicResource is a resource previously fetched using get action. DynamicResourceService.remove(dynamicResource, { query: "where field = 'value' " }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.remove = function (schemaName, data, options) { return this.baasicApp.dynamicResourceModule.remove(schemaName, data, options); }; /** * Returns a promise that is resolved once the purge action has been performed. This action will remove all dynamic resources from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `dynamicResourceRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects: * @method * @param data JSON object used to purge dynamic resources. * @example // dynamicResource is a resource previously fetched using get action. DynamicResourceService.purge('<schema-name>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ DynamicResourceService.prototype.purge = function (schemaName) { return this.baasicApp.dynamicResourceModule.purge(schemaName); }; Object.defineProperty(DynamicResourceService.prototype, "batch", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the create JSON object action has been performed; this action creates new JSON object resources. * @method * @param data JSON object objects that need to be inserted into the system. * @returns A promise that is resolved once the create JSON object action has been performed. * @example dynamicResourceBatchClient.create([{ name: '<name>' }]) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); */ create: function (data) { return baasicApp.dynamicResourceModule.batch.create(data); }, /** * Returns a promise that is resolved once the update JSON object action has been performed; this action updates JSON object resources. * @method * @param data JSON object objects used to update specified JSON object resources. * @returns A promise that is resolved once the update JSON object action has been performed. * @example JSON object are resources previously fetched using get action. dynamicResourceBatchClient.update([{ id: '<id>', name: '<name>' }]) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); */ update: function (data) { return baasicApp.dynamicResourceModule.batch.update(data); }, /** * Returns a promise that is resolved once the patch JSON object action has been performed; this action patches JSON object resources. * @method * @param data JSON object objects used to patch specified JSON object resources. * @returns A promise that is resolved once the patch JSON object action has been performed. * @example JSON object are resources previously fetched using get action. dynamicResourceBatchClient.patch([{ id: '<id>', name: '<name>' }]) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); */ patch: function (data) { return baasicApp.dynamicResourceModule.batch.patch(data); }, /** * Returns a promise that is resolved once the remove action has been performed. This action will remove JSON object resources from the system if successfully completed. * @method * @param data JSON object Ids which uniquely identify JSON object resources to be deleted. * @returns A promise that is resolved once the remove action has been performed. * @example JSON object Ids are identifiers which uniquely identify JSON object resources. dynamicResourceBatchClient.remove(['<id1>', '<id2>']]) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); */ remove: function (data) { return baasicApp.dynamicResourceModule.batch.remove(data); } }; }, enumerable: true, configurable: true }); Object.defineProperty(DynamicResourceService.prototype, "schema", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the find action has been performed. Success response returns a list of dynamic resource schemas matching the given criteria. * @method * @param options Options object. * @example DynamicResourceService.scema.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>' }) .then(function (collection) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ find: function (options) { return baasicApp.dynamicResourceModule.schema.find(options); }, /** * Returns a promise that is resolved once the get action has been performed. Success response returns the specified dynamic resource schema. * @method * @param name Name of dynamic resource schema which need to be retrieved. * @param options Options object. * @example DynamicResourceService.schema.get('<schema-name>') .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ get: function (name, options) { return baasicApp.dynamicResourceModule.schema.get(name, options); }, /** * Returns a promise that is resolved once the create action has been performed; this action creates a new dynamic resource schema item. * @method * @param data A dynamic resource schema object that needs to be inserted into the system. * @example DynamicResourceService.schema.create({ schema : { type : 'object', properties : { id : { title : '<unique-identifier-field>', readonly : true, hidden : true, type : 'string' }, description : { type: string } } }, name : '<schema-name>', description : '<description>', enforceSchemaValidation : true }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ create: function (data) { return baasicApp.dynamicResourceModule.schema.create(data); }, /** * Returns a promise that is resolved once the update dynamic resource schema action has been performed; this action updates a dynamic resource schema item. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicDynamicSchemaRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(dynamicResourceSchema); * let uri = params['model'].links('put').href; * ``` * @method * @param data A dynamic schema object used to update specified dynamic resource schema. * @example // dynamicResourceSchema is a resource previously fetched using get action. dynamicResourceSchema.description = '<description>'; DynamicResourceService.schema.update(dynamicResourceSchema) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (data) { return baasicApp.dynamicResourceModule.schema.update(data); }, /** * Returns a promise that is resolved once the remove action has been performed. This action will remove a dynamic resource schema item from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicDynamicSchemaRouteDefinition` route template. Here is an example of how a route can be obtained from HAL enabled objects: * ``` * let params = modelMapper.removeParams(dynamicResourceSchema); * let uri = params['model'].links('delete').href; * ``` * @method * @param data A dynamic schema object used to delete specified dynamic resource schema. * @example // dynamicResourceSchema is a resource previously fetched using get action. DynamicResourceService.schema.remove(dynamicResourceSchema) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ remove: function (data) { return baasicApp.dynamicResourceModule.schema.remove(data); }, /** * Returns a promise that is resolved once the generate schema action has been performed. Success response returns a schema generated based on the json input. * @method * @param data Unordered collection of key value pairs used to specify dynamic schema definition. * @example DynamicResourceService.schema.generate({ id : '<schema-Id>', description : '<description>' }) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ generate: function (data) { return baasicApp.dynamicResourceModule.schema.generate(data); } }; }, enumerable: true, configurable: true }); Object.defineProperty(DynamicResourceService.prototype, "acl", { get: function () { var baasicApp = this.baasicApp; return { /** * Returns a promise that is resolved once the get action has been performed. Success response returns a list of ACL policies established for the specified dynamic resource. * @method * @param options Options object. * @example DynamicResourceService.acl.get({id: '<dynamic-resource-id>', schemaName: '<schema-name>'}) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ get: function (options) { return baasicApp.dynamicResourceModule.acl.get(options); }, /** * Returns a promise that is resolved once the update acl action has been performed; this action creates new ACL policy for the specified dynamic resource. * @method * @param options Options object. * @example DynamicResourceService.acl.update({id: '<dynamic-resource-id>', schemaName: '<schema-name>'}) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ update: function (options) { return baasicApp.dynamicResourceModule.acl.update(options); }, /** * Returns a promise that is resolved once the removeByUser action has been performed. This action deletes ACL policy assigned to the specified user and dynamic resource. * @method * @param action Action abbreviation which identifies ACL policy assigned to the specified user and dynamic resource. * Supported Values: * "Create" * "Delete" * "Read" * "Update" * @param user Username which uniquely identifies user for which ACL policy needs to be removed. * @param data ACL Policy whose security privileges need to be retrieved and updated. * @example // dynamicResource is a resource previously fetched using get action. DynamicResourceService.acl.removeByUser('<access-action>', '<username>', dynamicResource) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ removeByUser: function (action, user, data) { return baasicApp.dynamicResourceModule.acl.removeByUser(action, user, data); }, /** * Returns a promise that is resolved once the removeByRole action has been performed. This action deletes ACL policy assigned to the specified role and dynamic resource. * @method * @param action Action abbreviation which identifies ACL policy assigned to the specified role and dynamic resource. * Supported Values: * "Create" * "Delete" * "Read" * "Update" * @param role Role's name which uniquely identifies role for which ACL policy needs to be removed. * @param data ACL Policy whose security privileges need to be retrieved and updated. * @example // dynamicResource is a resource previously fetched using get action. DynamicResourceService.acl.removeByRole('<access-action>', '<role-name>', dynamicResource) .then(function (data) { // perform success action here }, function (response, status, headers, config) { // perform error handling here }); **/ removeByRole: function (action, role, data) { return baasicApp.dynamicResourceModule.acl.removeByRole(action, role, data); } }; }, enumerable: true, configurable: true }); DynamicResourceService = tslib_1.__decorate([ core_1.Injectable(), tslib_1.__metadata("design:paramtypes", [index_1.BaasicAppService]) ], DynamicResourceService); return DynamicResourceService; }()); exports.DynamicResourceService = DynamicResourceService;