@jsforce/jsforce-node 0.0.1 → 3.0.0-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +54 -0
- package/index.d.ts +4 -0
- package/index.js +1 -0
- package/lib/VERSION.d.ts +2 -0
- package/lib/VERSION.js +3 -0
- package/lib/api/analytics/types.d.ts +509 -0
- package/lib/api/analytics/types.js +2 -0
- package/lib/api/analytics.d.ts +163 -0
- package/lib/api/analytics.js +342 -0
- package/lib/api/apex.d.ts +44 -0
- package/lib/api/apex.js +86 -0
- package/lib/api/bulk.d.ts +253 -0
- package/lib/api/bulk.js +678 -0
- package/lib/api/bulk2.d.ts +324 -0
- package/lib/api/bulk2.js +800 -0
- package/lib/api/chatter.d.ts +133 -0
- package/lib/api/chatter.js +248 -0
- package/lib/api/metadata/schema.d.ts +16117 -0
- package/lib/api/metadata/schema.js +9094 -0
- package/lib/api/metadata.d.ts +189 -0
- package/lib/api/metadata.js +406 -0
- package/lib/api/soap/schema.d.ts +3167 -0
- package/lib/api/soap/schema.js +1787 -0
- package/lib/api/soap.d.ts +76 -0
- package/lib/api/soap.js +155 -0
- package/lib/api/streaming/extension.d.ts +94 -0
- package/lib/api/streaming/extension.js +151 -0
- package/lib/api/streaming.d.ts +160 -0
- package/lib/api/streaming.js +252 -0
- package/lib/api/tooling.d.ts +284 -0
- package/lib/api/tooling.js +202 -0
- package/lib/api/wsdl/wsdl2schema.d.ts +1 -0
- package/lib/api/wsdl/wsdl2schema.js +354 -0
- package/lib/browser/canvas.d.ts +12 -0
- package/lib/browser/canvas.js +77 -0
- package/lib/browser/client.d.ts +82 -0
- package/lib/browser/client.js +244 -0
- package/lib/browser/jsonp.d.ts +12 -0
- package/lib/browser/jsonp.js +69 -0
- package/lib/browser/registry.d.ts +3 -0
- package/lib/browser/registry.js +5 -0
- package/lib/browser/request.d.ts +10 -0
- package/lib/browser/request.js +202 -0
- package/lib/cache.d.ts +74 -0
- package/lib/cache.js +159 -0
- package/lib/connection.d.ts +356 -0
- package/lib/connection.js +1153 -0
- package/lib/core.d.ts +17 -0
- package/lib/core.js +55 -0
- package/lib/csv.d.ts +23 -0
- package/lib/csv.js +35 -0
- package/lib/date.d.ts +82 -0
- package/lib/date.js +201 -0
- package/lib/http-api.d.ts +75 -0
- package/lib/http-api.js +295 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +32 -0
- package/lib/jsforce.d.ts +26 -0
- package/lib/jsforce.js +67 -0
- package/lib/jwtOAuth2.d.ts +8 -0
- package/lib/jwtOAuth2.js +23 -0
- package/lib/oauth2.d.ts +92 -0
- package/lib/oauth2.js +245 -0
- package/lib/process.d.ts +157 -0
- package/lib/process.js +143 -0
- package/lib/query.d.ts +341 -0
- package/lib/query.js +817 -0
- package/lib/quick-action.d.ts +44 -0
- package/lib/quick-action.js +46 -0
- package/lib/record-reference.d.ts +46 -0
- package/lib/record-reference.js +65 -0
- package/lib/record-stream.d.ts +83 -0
- package/lib/record-stream.js +233 -0
- package/lib/registry/base.d.ts +43 -0
- package/lib/registry/base.js +96 -0
- package/lib/registry/empty.d.ts +7 -0
- package/lib/registry/empty.js +13 -0
- package/lib/registry/file.d.ts +11 -0
- package/lib/registry/file.js +51 -0
- package/lib/registry/index.d.ts +8 -0
- package/lib/registry/index.js +21 -0
- package/lib/registry/sfdx.d.ts +56 -0
- package/lib/registry/sfdx.js +133 -0
- package/lib/registry/types.d.ts +47 -0
- package/lib/registry/types.js +2 -0
- package/lib/request-helper.d.ts +23 -0
- package/lib/request-helper.js +102 -0
- package/lib/request.d.ts +11 -0
- package/lib/request.js +75 -0
- package/lib/session-refresh-delegate.d.ts +31 -0
- package/lib/session-refresh-delegate.js +69 -0
- package/lib/soap.d.ts +60 -0
- package/lib/soap.js +257 -0
- package/lib/sobject.d.ts +258 -0
- package/lib/sobject.js +376 -0
- package/lib/soql-builder.d.ts +25 -0
- package/lib/soql-builder.js +226 -0
- package/lib/transport.d.ts +63 -0
- package/lib/transport.js +175 -0
- package/lib/types/common.d.ts +560 -0
- package/lib/types/common.js +2 -0
- package/lib/types/index.d.ts +7 -0
- package/lib/types/index.js +23 -0
- package/lib/types/projection.d.ts +26 -0
- package/lib/types/projection.js +2 -0
- package/lib/types/record.d.ts +44 -0
- package/lib/types/record.js +2 -0
- package/lib/types/schema.d.ts +50 -0
- package/lib/types/schema.js +2 -0
- package/lib/types/soap.d.ts +43 -0
- package/lib/types/soap.js +2 -0
- package/lib/types/standard-schema.d.ts +16199 -0
- package/lib/types/standard-schema.js +2 -0
- package/lib/types/util.d.ts +7 -0
- package/lib/types/util.js +2 -0
- package/lib/util/formatter.d.ts +8 -0
- package/lib/util/formatter.js +24 -0
- package/lib/util/function.d.ts +32 -0
- package/lib/util/function.js +52 -0
- package/lib/util/get-body-size.d.ts +4 -0
- package/lib/util/get-body-size.js +39 -0
- package/lib/util/logger.d.ts +29 -0
- package/lib/util/logger.js +102 -0
- package/lib/util/promise.d.ts +19 -0
- package/lib/util/promise.js +25 -0
- package/lib/util/stream.d.ts +12 -0
- package/lib/util/stream.js +88 -0
- package/package.json +262 -6
- package/typings/faye/index.d.ts +16 -0
- package/typings/index.d.ts +1 -0
package/lib/sobject.js
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.SObject = void 0;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
const logger_1 = require("./util/logger");
|
|
34
|
+
const record_reference_1 = __importDefault(require("./record-reference"));
|
|
35
|
+
const query_1 = __importStar(require("./query"));
|
|
36
|
+
const quick_action_1 = __importDefault(require("./quick-action"));
|
|
37
|
+
/**
|
|
38
|
+
* A class for organizing all SObject access
|
|
39
|
+
*/
|
|
40
|
+
class SObject {
|
|
41
|
+
static _logger = (0, logger_1.getLogger)('sobject');
|
|
42
|
+
type;
|
|
43
|
+
_conn;
|
|
44
|
+
_logger;
|
|
45
|
+
// layouts: (ln?: string) => Promise<DescribeLayoutResult>;
|
|
46
|
+
layouts$;
|
|
47
|
+
layouts$$;
|
|
48
|
+
// compactLayouts: () => Promise<DescribeCompactLayoutsResult>;
|
|
49
|
+
compactLayouts$;
|
|
50
|
+
compactLayouts$$;
|
|
51
|
+
// approvalLayouts: () => Promise<DescribeApprovalLayoutsResult>;
|
|
52
|
+
approvalLayouts$;
|
|
53
|
+
approvalLayouts$$;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
*/
|
|
57
|
+
constructor(conn, type) {
|
|
58
|
+
this.type = type;
|
|
59
|
+
this._conn = conn;
|
|
60
|
+
this._logger = conn._logLevel
|
|
61
|
+
? SObject._logger.createInstance(conn._logLevel)
|
|
62
|
+
: SObject._logger;
|
|
63
|
+
const cache = this._conn.cache;
|
|
64
|
+
const layoutCacheKey = (layoutName) => layoutName
|
|
65
|
+
? `layouts.namedLayouts.${layoutName}`
|
|
66
|
+
: `layouts.${this.type}`;
|
|
67
|
+
const layouts = SObject.prototype.layouts;
|
|
68
|
+
this.layouts = cache.createCachedFunction(layouts, this, {
|
|
69
|
+
key: layoutCacheKey,
|
|
70
|
+
strategy: 'NOCACHE',
|
|
71
|
+
});
|
|
72
|
+
this.layouts$ = cache.createCachedFunction(layouts, this, {
|
|
73
|
+
key: layoutCacheKey,
|
|
74
|
+
strategy: 'HIT',
|
|
75
|
+
});
|
|
76
|
+
this.layouts$$ = cache.createCachedFunction(layouts, this, {
|
|
77
|
+
key: layoutCacheKey,
|
|
78
|
+
strategy: 'IMMEDIATE',
|
|
79
|
+
});
|
|
80
|
+
const compactLayoutCacheKey = `compactLayouts.${this.type}`;
|
|
81
|
+
const compactLayouts = SObject.prototype.compactLayouts;
|
|
82
|
+
this.compactLayouts = cache.createCachedFunction(compactLayouts, this, {
|
|
83
|
+
key: compactLayoutCacheKey,
|
|
84
|
+
strategy: 'NOCACHE',
|
|
85
|
+
});
|
|
86
|
+
this.compactLayouts$ = cache.createCachedFunction(compactLayouts, this, {
|
|
87
|
+
key: compactLayoutCacheKey,
|
|
88
|
+
strategy: 'HIT',
|
|
89
|
+
});
|
|
90
|
+
this.compactLayouts$$ = cache.createCachedFunction(compactLayouts, this, {
|
|
91
|
+
key: compactLayoutCacheKey,
|
|
92
|
+
strategy: 'IMMEDIATE',
|
|
93
|
+
});
|
|
94
|
+
const approvalLayoutCacheKey = `approvalLayouts.${this.type}`;
|
|
95
|
+
const approvalLayouts = SObject.prototype.approvalLayouts;
|
|
96
|
+
this.approvalLayouts = cache.createCachedFunction(approvalLayouts, this, {
|
|
97
|
+
key: approvalLayoutCacheKey,
|
|
98
|
+
strategy: 'NOCACHE',
|
|
99
|
+
});
|
|
100
|
+
this.approvalLayouts$ = cache.createCachedFunction(approvalLayouts, this, {
|
|
101
|
+
key: approvalLayoutCacheKey,
|
|
102
|
+
strategy: 'HIT',
|
|
103
|
+
});
|
|
104
|
+
this.approvalLayouts$$ = cache.createCachedFunction(approvalLayouts, this, {
|
|
105
|
+
key: approvalLayoutCacheKey,
|
|
106
|
+
strategy: 'IMMEDIATE',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
create(records, options) {
|
|
110
|
+
return this._conn.create(this.type, records, options);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Synonym of SObject#create()
|
|
114
|
+
*/
|
|
115
|
+
insert = this.create;
|
|
116
|
+
retrieve(ids, options) {
|
|
117
|
+
return this._conn.retrieve(this.type, ids, options);
|
|
118
|
+
}
|
|
119
|
+
update(records, options) {
|
|
120
|
+
return this._conn.update(this.type, records, options);
|
|
121
|
+
}
|
|
122
|
+
upsert(records, extIdField, options) {
|
|
123
|
+
return this._conn.upsert(this.type, records, extIdField, options);
|
|
124
|
+
}
|
|
125
|
+
destroy(ids, options) {
|
|
126
|
+
return this._conn.destroy(this.type, ids, options);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Synonym of SObject#destroy()
|
|
130
|
+
*/
|
|
131
|
+
delete = this.destroy;
|
|
132
|
+
/**
|
|
133
|
+
* Synonym of SObject#destroy()
|
|
134
|
+
*/
|
|
135
|
+
del = this.destroy;
|
|
136
|
+
/**
|
|
137
|
+
* Call Bulk#load() to execute bulkload, returning batch object
|
|
138
|
+
*/
|
|
139
|
+
bulkload(operation, optionsOrInput, input) {
|
|
140
|
+
return this._conn.bulk.load(this.type, operation, optionsOrInput, input);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Bulkly insert input data using bulk API
|
|
144
|
+
*/
|
|
145
|
+
createBulk(input) {
|
|
146
|
+
return this.bulkload('insert', input);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Synonym of SObject#createBulk()
|
|
150
|
+
*/
|
|
151
|
+
insertBulk = this.createBulk;
|
|
152
|
+
/**
|
|
153
|
+
* Bulkly update records by input data using bulk API
|
|
154
|
+
*/
|
|
155
|
+
updateBulk(input) {
|
|
156
|
+
return this.bulkload('update', input);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Bulkly upsert records by input data using bulk API
|
|
160
|
+
*/
|
|
161
|
+
upsertBulk(input, extIdField) {
|
|
162
|
+
return this.bulkload('upsert', { extIdField }, input);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Bulkly delete records specified by input data using bulk API
|
|
166
|
+
*/
|
|
167
|
+
destroyBulk(input) {
|
|
168
|
+
return this.bulkload('delete', input);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Synonym of SObject#destroyBulk()
|
|
172
|
+
*/
|
|
173
|
+
deleteBulk = this.destroyBulk;
|
|
174
|
+
/**
|
|
175
|
+
* Bulkly hard delete records specified in input data using bulk API
|
|
176
|
+
*/
|
|
177
|
+
destroyHardBulk(input) {
|
|
178
|
+
return this.bulkload('hardDelete', input);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Synonym of SObject#destroyHardBulk()
|
|
182
|
+
*/
|
|
183
|
+
deleteHardBulk = this.destroyHardBulk;
|
|
184
|
+
/**
|
|
185
|
+
* Describe SObject metadata
|
|
186
|
+
*/
|
|
187
|
+
describe() {
|
|
188
|
+
return this._conn.describe(this.type);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
*/
|
|
193
|
+
describe$() {
|
|
194
|
+
return this._conn.describe$(this.type);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
*/
|
|
199
|
+
describe$$() {
|
|
200
|
+
return this._conn.describe$$(this.type);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get record representation instance by given id
|
|
204
|
+
*/
|
|
205
|
+
record(id) {
|
|
206
|
+
return new record_reference_1.default(this._conn, this.type, id);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Retrieve recently accessed records
|
|
210
|
+
*/
|
|
211
|
+
recent() {
|
|
212
|
+
return this._conn.recent(this.type);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Retrieve the updated records
|
|
216
|
+
*/
|
|
217
|
+
updated(start, end) {
|
|
218
|
+
return this._conn.updated(this.type, start, end);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Retrieve the deleted records
|
|
222
|
+
*/
|
|
223
|
+
deleted(start, end) {
|
|
224
|
+
return this._conn.deleted(this.type, start, end);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Describe layout information for SObject
|
|
228
|
+
*/
|
|
229
|
+
async layouts(layoutName) {
|
|
230
|
+
const url = `/sobjects/${this.type}/describe/${layoutName ? `namedLayouts/${layoutName}` : 'layouts'}`;
|
|
231
|
+
const body = await this._conn.request(url);
|
|
232
|
+
return body;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* @typedef {Object} CompactLayoutInfo
|
|
236
|
+
* @prop {Array.<Object>} compactLayouts - Array of compact layouts
|
|
237
|
+
* @prop {String} defaultCompactLayoutId - ID of default compact layout
|
|
238
|
+
* @prop {Array.<Object>} recordTypeCompactLayoutMappings - Array of record type mappings
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Describe compact layout information defined for SObject
|
|
242
|
+
*
|
|
243
|
+
* @param {Callback.<CompactLayoutInfo>} [callback] - Callback function
|
|
244
|
+
* @returns {Promise.<CompactLayoutInfo>}
|
|
245
|
+
*/
|
|
246
|
+
async compactLayouts() {
|
|
247
|
+
const url = `/sobjects/${this.type}/describe/compactLayouts`;
|
|
248
|
+
const body = await this._conn.request(url);
|
|
249
|
+
return body;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Describe compact layout information defined for SObject
|
|
253
|
+
*
|
|
254
|
+
* @param {Callback.<ApprovalLayoutInfo>} [callback] - Callback function
|
|
255
|
+
* @returns {Promise.<ApprovalLayoutInfo>}
|
|
256
|
+
*/
|
|
257
|
+
async approvalLayouts() {
|
|
258
|
+
const url = `/sobjects/${this.type}/describe/approvalLayouts`;
|
|
259
|
+
const body = await this._conn.request(url);
|
|
260
|
+
return body;
|
|
261
|
+
}
|
|
262
|
+
find(conditions, fields, options = {}) {
|
|
263
|
+
const { sort, limit, offset, ...qoptions } = options;
|
|
264
|
+
const config = {
|
|
265
|
+
fields: fields == null ? undefined : fields,
|
|
266
|
+
includes: options.includes,
|
|
267
|
+
table: this.type,
|
|
268
|
+
conditions: conditions == null ? undefined : conditions,
|
|
269
|
+
sort,
|
|
270
|
+
limit,
|
|
271
|
+
offset,
|
|
272
|
+
};
|
|
273
|
+
const query = new query_1.default(this._conn, config, qoptions);
|
|
274
|
+
return query.setResponseTarget(query_1.ResponseTargets.Records);
|
|
275
|
+
}
|
|
276
|
+
findOne(conditions, fields, options = {}) {
|
|
277
|
+
const query = this.find(conditions, fields, { ...options, limit: 1 });
|
|
278
|
+
return query.setResponseTarget(query_1.ResponseTargets.SingleRecord);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Find and fetch records only by specifying fields to fetch.
|
|
282
|
+
*/
|
|
283
|
+
select(fields) {
|
|
284
|
+
return this.find(null, fields);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Count num of records which matches given conditions
|
|
288
|
+
*/
|
|
289
|
+
count(conditions) {
|
|
290
|
+
const query = this.find(conditions, 'count()');
|
|
291
|
+
return query.setResponseTarget(query_1.ResponseTargets.Count);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Returns the list of list views for the SObject
|
|
295
|
+
*
|
|
296
|
+
* @param {Callback.<ListViewsInfo>} [callback] - Callback function
|
|
297
|
+
* @returns {Promise.<ListViewsInfo>}
|
|
298
|
+
*/
|
|
299
|
+
listviews() {
|
|
300
|
+
const url = `${this._conn._baseUrl()}/sobjects/${this.type}/listviews`;
|
|
301
|
+
return this._conn.request(url);
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Returns the list view info in specifed view id
|
|
305
|
+
*
|
|
306
|
+
* @param {String} id - List view ID
|
|
307
|
+
* @returns {ListView}
|
|
308
|
+
*/
|
|
309
|
+
listview(id) {
|
|
310
|
+
return new ListView(this._conn, this.type, id); // eslint-disable-line no-use-before-define
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Returns all registered quick actions for the SObject
|
|
314
|
+
*
|
|
315
|
+
* @param {Callback.<Array.<QuickAction~QuickActionInfo>>} [callback] - Callback function
|
|
316
|
+
* @returns {Promise.<Array.<QuickAction~QuickActionInfo>>}
|
|
317
|
+
*/
|
|
318
|
+
quickActions() {
|
|
319
|
+
return this._conn.request(`/sobjects/${this.type}/quickActions`);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Get reference for specified quick aciton in the SObject
|
|
323
|
+
*
|
|
324
|
+
* @param {String} actionName - Name of the quick action
|
|
325
|
+
* @returns {QuickAction}
|
|
326
|
+
*/
|
|
327
|
+
quickAction(actionName) {
|
|
328
|
+
return new quick_action_1.default(this._conn, `/sobjects/${this.type}/quickActions/${actionName}`);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
exports.SObject = SObject;
|
|
332
|
+
/**
|
|
333
|
+
* A class for organizing list view information
|
|
334
|
+
*
|
|
335
|
+
* @protected
|
|
336
|
+
* @class ListView
|
|
337
|
+
* @param {Connection} conn - Connection instance
|
|
338
|
+
* @param {SObject} type - SObject type
|
|
339
|
+
* @param {String} id - List view ID
|
|
340
|
+
*/
|
|
341
|
+
class ListView {
|
|
342
|
+
_conn;
|
|
343
|
+
type;
|
|
344
|
+
id;
|
|
345
|
+
/**
|
|
346
|
+
*
|
|
347
|
+
*/
|
|
348
|
+
constructor(conn, type, id) {
|
|
349
|
+
this._conn = conn;
|
|
350
|
+
this.type = type;
|
|
351
|
+
this.id = id;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Executes query for the list view and returns the resulting data and presentation information.
|
|
355
|
+
*/
|
|
356
|
+
results() {
|
|
357
|
+
const url = `${this._conn._baseUrl()}/sobjects/${this.type}/listviews/${this.id}/results`;
|
|
358
|
+
return this._conn.request(url);
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Returns detailed information about a list view
|
|
362
|
+
*/
|
|
363
|
+
describe(options = {}) {
|
|
364
|
+
const url = `${this._conn._baseUrl()}/sobjects/${this.type}/listviews/${this.id}/describe`;
|
|
365
|
+
return this._conn.request({ method: 'GET', url, headers: options.headers });
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Explain plan for executing list view
|
|
369
|
+
*/
|
|
370
|
+
explain() {
|
|
371
|
+
const url = `/query/?explain=${this.id}`;
|
|
372
|
+
return this._conn.request(url);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.default = SObject;
|
|
376
|
+
// TODO Bulk
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type Condition = string | {
|
|
2
|
+
[field: string]: any;
|
|
3
|
+
} | Array<{
|
|
4
|
+
[field: string]: any;
|
|
5
|
+
}>;
|
|
6
|
+
export type SortDir = 'ASC' | 'DESC' | 'asc' | 'desc' | 1 | -1;
|
|
7
|
+
export type Sort = string | Array<[string, SortDir]> | {
|
|
8
|
+
[field: string]: SortDir;
|
|
9
|
+
};
|
|
10
|
+
export type QueryConfig = {
|
|
11
|
+
fields?: string[];
|
|
12
|
+
includes?: {
|
|
13
|
+
[field: string]: QueryConfig;
|
|
14
|
+
};
|
|
15
|
+
table?: string;
|
|
16
|
+
conditions?: Condition;
|
|
17
|
+
sort?: Sort;
|
|
18
|
+
limit?: number;
|
|
19
|
+
offset?: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Create SOQL
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
export declare function createSOQL(query: QueryConfig): string;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createSOQL = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* @file Create and build SOQL string from configuration
|
|
9
|
+
* @author Shinichi Tomita <shinichi.tomita@gmail.com>
|
|
10
|
+
*/
|
|
11
|
+
const date_1 = __importDefault(require("./date"));
|
|
12
|
+
/** @private **/
|
|
13
|
+
function escapeSOQLString(str) {
|
|
14
|
+
return String(str || '').replace(/'/g, "\\'");
|
|
15
|
+
}
|
|
16
|
+
/** @private **/
|
|
17
|
+
function createFieldsClause(fields, childQueries = {}) {
|
|
18
|
+
const cqueries = Object.values(childQueries);
|
|
19
|
+
// eslint-disable-next-line no-use-before-define
|
|
20
|
+
return [
|
|
21
|
+
...(fields || ['Id']),
|
|
22
|
+
...cqueries.map((cquery) => `(${createSOQL(cquery)})`),
|
|
23
|
+
].join(', ');
|
|
24
|
+
}
|
|
25
|
+
/** @private **/
|
|
26
|
+
function createValueExpression(value) {
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
return value.length > 0
|
|
29
|
+
? `(${value.map(createValueExpression).join(', ')})`
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
if (value instanceof date_1.default) {
|
|
33
|
+
return value.toString();
|
|
34
|
+
}
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
return `'${escapeSOQLString(value)}'`;
|
|
37
|
+
}
|
|
38
|
+
if (typeof value === 'number') {
|
|
39
|
+
return value.toString();
|
|
40
|
+
}
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return 'null';
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
const opMap = {
|
|
47
|
+
'=': '=',
|
|
48
|
+
$eq: '=',
|
|
49
|
+
'!=': '!=',
|
|
50
|
+
$ne: '!=',
|
|
51
|
+
'>': '>',
|
|
52
|
+
$gt: '>',
|
|
53
|
+
'<': '<',
|
|
54
|
+
$lt: '<',
|
|
55
|
+
'>=': '>=',
|
|
56
|
+
$gte: '>=',
|
|
57
|
+
'<=': '<=',
|
|
58
|
+
$lte: '<=',
|
|
59
|
+
$like: 'LIKE',
|
|
60
|
+
$nlike: 'NOT LIKE',
|
|
61
|
+
$in: 'IN',
|
|
62
|
+
$nin: 'NOT IN',
|
|
63
|
+
$includes: 'INCLUDES',
|
|
64
|
+
$excludes: 'EXCLUDES',
|
|
65
|
+
$exists: 'EXISTS',
|
|
66
|
+
};
|
|
67
|
+
/** @private **/
|
|
68
|
+
function createFieldExpression(field, value) {
|
|
69
|
+
let op = '$eq';
|
|
70
|
+
let _value = value;
|
|
71
|
+
// Assume the `$in` operator if value is an array and none was supplied.
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
op = '$in';
|
|
74
|
+
}
|
|
75
|
+
else if (typeof value === 'object' && value !== null) {
|
|
76
|
+
// Otherwise, if an object was passed then process the supplied ops.
|
|
77
|
+
for (const k of Object.keys(value)) {
|
|
78
|
+
if (k[0] === '$') {
|
|
79
|
+
op = k;
|
|
80
|
+
_value = value[k];
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const sfop = opMap[op];
|
|
86
|
+
if (!sfop || typeof _value === 'undefined') {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
const valueExpr = createValueExpression(_value);
|
|
90
|
+
if (typeof valueExpr === 'undefined') {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
switch (sfop) {
|
|
94
|
+
case 'NOT LIKE':
|
|
95
|
+
return `(${['NOT', field, 'LIKE', valueExpr].join(' ')})`;
|
|
96
|
+
case 'EXISTS':
|
|
97
|
+
return [field, _value ? '!=' : '=', 'null'].join(' ');
|
|
98
|
+
default:
|
|
99
|
+
return [field, sfop, valueExpr].join(' ');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
/** @private **/
|
|
103
|
+
function createOrderByClause(sort = []) {
|
|
104
|
+
let _sort = [];
|
|
105
|
+
if (typeof sort === 'string') {
|
|
106
|
+
if (/,|\s+(asc|desc)\s*$/.test(sort)) {
|
|
107
|
+
// must be specified in pure "order by" clause. Return raw config.
|
|
108
|
+
return sort;
|
|
109
|
+
}
|
|
110
|
+
// sort order in mongoose-style expression.
|
|
111
|
+
// e.g. "FieldA -FieldB" => "ORDER BY FieldA ASC, FieldB DESC"
|
|
112
|
+
_sort = sort.split(/\s+/).map((field) => {
|
|
113
|
+
let dir = 'ASC'; // ascending
|
|
114
|
+
const flag = field[0];
|
|
115
|
+
if (flag === '-') {
|
|
116
|
+
dir = 'DESC';
|
|
117
|
+
field = field.substring(1); // eslint-disable-line no-param-reassign
|
|
118
|
+
}
|
|
119
|
+
else if (flag === '+') {
|
|
120
|
+
field = field.substring(1); // eslint-disable-line no-param-reassign
|
|
121
|
+
}
|
|
122
|
+
return [field, dir];
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else if (Array.isArray(sort)) {
|
|
126
|
+
_sort = sort;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
_sort = Object.entries(sort).map(([field, dir]) => [field, dir]);
|
|
130
|
+
}
|
|
131
|
+
return _sort
|
|
132
|
+
.map(([field, dir]) => {
|
|
133
|
+
/* eslint-disable no-param-reassign */
|
|
134
|
+
switch (String(dir)) {
|
|
135
|
+
case 'DESC':
|
|
136
|
+
case 'desc':
|
|
137
|
+
case 'descending':
|
|
138
|
+
case '-':
|
|
139
|
+
case '-1':
|
|
140
|
+
dir = 'DESC';
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
dir = 'ASC';
|
|
144
|
+
}
|
|
145
|
+
return `${field} ${dir}`;
|
|
146
|
+
})
|
|
147
|
+
.join(', ');
|
|
148
|
+
}
|
|
149
|
+
/** @private **/
|
|
150
|
+
function createConditionClause(conditions = {}, operator = 'AND', depth = 0) {
|
|
151
|
+
if (typeof conditions === 'string') {
|
|
152
|
+
return conditions;
|
|
153
|
+
}
|
|
154
|
+
let conditionList = [];
|
|
155
|
+
if (!Array.isArray(conditions)) {
|
|
156
|
+
// if passed in hash object
|
|
157
|
+
const conditionsMap = conditions;
|
|
158
|
+
conditionList = Object.keys(conditionsMap).map((key) => ({
|
|
159
|
+
key,
|
|
160
|
+
value: conditionsMap[key],
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
conditionList = conditions.map((cond) => {
|
|
165
|
+
const conds = Object.keys(cond).map((key) => ({ key, value: cond[key] }));
|
|
166
|
+
return conds.length > 1
|
|
167
|
+
? { key: '$and', value: conds.map((c) => ({ [c.key]: c.value })) }
|
|
168
|
+
: conds[0];
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const conditionClauses = conditionList
|
|
172
|
+
.map((cond) => {
|
|
173
|
+
let d = depth + 1;
|
|
174
|
+
let op;
|
|
175
|
+
switch (cond.key) {
|
|
176
|
+
case '$or':
|
|
177
|
+
case '$and':
|
|
178
|
+
case '$not':
|
|
179
|
+
if (operator !== 'NOT' && conditionList.length === 1) {
|
|
180
|
+
d = depth; // not change tree depth
|
|
181
|
+
}
|
|
182
|
+
op = cond.key === '$or' ? 'OR' : cond.key === '$and' ? 'AND' : 'NOT';
|
|
183
|
+
return createConditionClause(cond.value, op, d);
|
|
184
|
+
default:
|
|
185
|
+
return createFieldExpression(cond.key, cond.value);
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
.filter((expr) => expr);
|
|
189
|
+
let hasParen;
|
|
190
|
+
if (operator === 'NOT') {
|
|
191
|
+
hasParen = depth > 0;
|
|
192
|
+
return `${hasParen ? '(' : ''}NOT ${conditionClauses[0]}${hasParen ? ')' : ''}`;
|
|
193
|
+
}
|
|
194
|
+
hasParen = depth > 0 && conditionClauses.length > 1;
|
|
195
|
+
return ((hasParen ? '(' : '') +
|
|
196
|
+
conditionClauses.join(` ${operator} `) +
|
|
197
|
+
(hasParen ? ')' : ''));
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Create SOQL
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
function createSOQL(query) {
|
|
204
|
+
let soql = [
|
|
205
|
+
'SELECT ',
|
|
206
|
+
createFieldsClause(query.fields, query.includes),
|
|
207
|
+
' FROM ',
|
|
208
|
+
query.table,
|
|
209
|
+
].join('');
|
|
210
|
+
const cond = createConditionClause(query.conditions);
|
|
211
|
+
if (cond) {
|
|
212
|
+
soql += ` WHERE ${cond}`;
|
|
213
|
+
}
|
|
214
|
+
const orderby = createOrderByClause(query.sort);
|
|
215
|
+
if (orderby) {
|
|
216
|
+
soql += ` ORDER BY ${orderby}`;
|
|
217
|
+
}
|
|
218
|
+
if (query.limit) {
|
|
219
|
+
soql += ` LIMIT ${query.limit}`;
|
|
220
|
+
}
|
|
221
|
+
if (query.offset) {
|
|
222
|
+
soql += ` OFFSET ${query.offset}`;
|
|
223
|
+
}
|
|
224
|
+
return soql;
|
|
225
|
+
}
|
|
226
|
+
exports.createSOQL = createSOQL;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
*/
|
|
5
|
+
import { Duplex } from 'stream';
|
|
6
|
+
import { HttpRequest, HttpRequestOptions, HttpResponse } from './types';
|
|
7
|
+
import { StreamPromise } from './util/promise';
|
|
8
|
+
/**
|
|
9
|
+
* Class for HTTP request transport
|
|
10
|
+
*
|
|
11
|
+
* @class
|
|
12
|
+
* @protected
|
|
13
|
+
*/
|
|
14
|
+
export declare class Transport {
|
|
15
|
+
/**
|
|
16
|
+
*/
|
|
17
|
+
httpRequest(req: HttpRequest, options?: HttpRequestOptions): StreamPromise<HttpResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
getRequestStreamCreator(): (req: HttpRequest, options: HttpRequestOptions) => Duplex;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Class for JSONP request transport
|
|
25
|
+
*/
|
|
26
|
+
export declare class JsonpTransport extends Transport {
|
|
27
|
+
static supprted: boolean;
|
|
28
|
+
_jsonpParam: string;
|
|
29
|
+
constructor(jsonpParam: string);
|
|
30
|
+
getRequestStreamCreator(): (req: HttpRequest, options: HttpRequestOptions) => Duplex;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Class for Sfdc Canvas request transport
|
|
34
|
+
*/
|
|
35
|
+
export declare class CanvasTransport extends Transport {
|
|
36
|
+
static supported: boolean;
|
|
37
|
+
_signedRequest: any;
|
|
38
|
+
constructor(signedRequest: any);
|
|
39
|
+
getRequestStreamCreator(): (req: HttpRequest, options: HttpRequestOptions) => Duplex;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Class for HTTP request transport using cross-domain AJAX proxy service
|
|
43
|
+
*/
|
|
44
|
+
export declare class XdProxyTransport extends Transport {
|
|
45
|
+
_xdProxyUrl: string;
|
|
46
|
+
constructor(xdProxyUrl: string);
|
|
47
|
+
/**
|
|
48
|
+
* Make HTTP request via AJAX proxy
|
|
49
|
+
*/
|
|
50
|
+
httpRequest(req: HttpRequest, _options?: HttpRequestOptions): StreamPromise<HttpResponse>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Class for HTTP request transport using a proxy server
|
|
54
|
+
*/
|
|
55
|
+
export declare class HttpProxyTransport extends Transport {
|
|
56
|
+
_httpProxy: string;
|
|
57
|
+
constructor(httpProxy: string);
|
|
58
|
+
/**
|
|
59
|
+
* Make HTTP request via proxy server
|
|
60
|
+
*/
|
|
61
|
+
httpRequest(req: HttpRequest, options_?: HttpRequestOptions): StreamPromise<HttpResponse>;
|
|
62
|
+
}
|
|
63
|
+
export default Transport;
|