UNPKG

@salesforce/sobject-metadata

Version:

Retrieve Salesforce object metadata from connected org

47 lines 1.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SObjectService = exports.SObjectType = void 0; const sobjectApi_1 = require("./sobjectApi"); var SObjectType; (function (SObjectType) { SObjectType[SObjectType["ALL"] = 0] = "ALL"; SObjectType[SObjectType["STANDARD"] = 1] = "STANDARD"; SObjectType[SObjectType["CUSTOM"] = 2] = "CUSTOM"; })(SObjectType = exports.SObjectType || (exports.SObjectType = {})); class SObjectService { constructor(connection) { this.connection = connection; } async describeSObject(name) { const result = await new sobjectApi_1.SObjectDescribeAPI(this.connection).describeSObject(name); return result.result ? Promise.resolve(result.result) : Promise.reject(); } async describeSObjects(names) { // TODO: make cancellable? const describeAPI = new sobjectApi_1.SObjectDescribeAPI(this.connection); let fetchedResults = []; let j = 0; while (j < names.length) { try { fetchedResults = fetchedResults.concat(await describeAPI.describeSObjectBatch(names, j)); j = fetchedResults.length; } catch (error) { return Promise.reject(error); } } return fetchedResults .map((result) => result.result) .filter((sobject) => !!sobject); } async retrieveSObjectNames(type = SObjectType.ALL) { const describeResult = await this.connection.describeGlobal(); return describeResult.sobjects .filter((sobject) => type === SObjectType.ALL || (type === SObjectType.CUSTOM && sobject.custom === true) || (type === SObjectType.STANDARD && sobject.custom !== true)) .map((sobject) => sobject.name); } } exports.SObjectService = SObjectService; //# sourceMappingURL=sobjectService.js.map