@jsforce/jsforce-node 3.8.2 → 3.9.1

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/lib/VERSION.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "3.8.2";
1
+ declare const _default: "3.9.1";
2
2
  export default _default;
package/lib/VERSION.js CHANGED
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = '3.8.2';
3
+ exports.default = '3.9.1';
@@ -267,6 +267,10 @@ export declare class Connection<S extends Schema = Schema> extends EventEmitter
267
267
  upsert<N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, FieldNames extends SObjectFieldNames<S, N> = SObjectFieldNames<S, N>>(type: N, records: InputRecord[], extIdField: FieldNames, options?: DmlOptions): Promise<UpsertResult[]>;
268
268
  upsert<N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, FieldNames extends SObjectFieldNames<S, N> = SObjectFieldNames<S, N>>(type: N, record: InputRecord, extIdField: FieldNames, options?: DmlOptions): Promise<UpsertResult>;
269
269
  upsert<N extends SObjectNames<S>, InputRecord extends SObjectInputRecord<S, N> = SObjectInputRecord<S, N>, FieldNames extends SObjectFieldNames<S, N> = SObjectFieldNames<S, N>>(type: N, records: InputRecord | InputRecord[], extIdField: FieldNames, options?: DmlOptions): Promise<UpsertResult | UpsertResult[]>;
270
+ /** @private */
271
+ _upsertMany(type: string, records: Record | Record[], extIdField: string, options?: DmlOptions): Promise<SaveResult | SaveResult[]>;
272
+ /** @private */
273
+ _upsertParallel(type: string, records: Record | Record[], extIdField: string, options?: DmlOptions): Promise<SaveResult | SaveResult[]>;
270
274
  /**
271
275
  * Delete records
272
276
  */
package/lib/connection.js CHANGED
@@ -917,6 +917,51 @@ class Connection extends events_1.EventEmitter {
917
917
  * @param options
918
918
  */
919
919
  async upsert(type, records, extIdField, options = {}) {
920
+ return Array.isArray(records)
921
+ ? // check the version whether SObject collection API is supported (46.0)
922
+ this._ensureVersion(46)
923
+ ? this._upsertMany(type, records, extIdField, options)
924
+ : this._upsertParallel(type, records, extIdField, options)
925
+ : this._upsertParallel(type, records, extIdField, options);
926
+ }
927
+ /** @private */
928
+ async _upsertMany(type, records, extIdField, options = {}) {
929
+ if (records.length === 0) {
930
+ return [];
931
+ }
932
+ if (records.length > MAX_DML_COUNT && options.allowRecursive) {
933
+ return [
934
+ ...(await this._upsertMany(type, records.slice(0, MAX_DML_COUNT), extIdField, options)),
935
+ ...(await this._upsertMany(type, records.slice(MAX_DML_COUNT), extIdField, options)),
936
+ ];
937
+ }
938
+ const _records = records.map((recordItem) => {
939
+ const { [extIdField]: extId, type: recordType, attributes, ...rec } = recordItem;
940
+ const sobjectType = recordType || attributes?.type || type;
941
+ if (!extId) {
942
+ throw new Error('External ID is not found in record.');
943
+ }
944
+ if (!sobjectType) {
945
+ throw new Error('No SObject Type defined in record');
946
+ }
947
+ return { [extIdField]: extId, attributes: { type: sobjectType }, ...rec };
948
+ });
949
+ const url = [this._baseUrl(), 'composite', 'sobjects', type, extIdField].join('/');
950
+ return this.request({
951
+ method: 'PATCH',
952
+ url,
953
+ body: JSON.stringify({
954
+ allOrNone: options.allOrNone || false,
955
+ records: _records,
956
+ }),
957
+ headers: {
958
+ ...(options.headers || {}),
959
+ 'content-type': 'application/json',
960
+ }
961
+ });
962
+ }
963
+ /** @private */
964
+ async _upsertParallel(type, records, extIdField, options = {}) {
920
965
  const isArray = Array.isArray(records);
921
966
  const _records = Array.isArray(records) ? records : [records];
922
967
  if (_records.length > this._maxRequest) {
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "database.com"
11
11
  ],
12
12
  "homepage": "http://github.com/jsforce/jsforce",
13
- "version": "3.8.2",
13
+ "version": "3.9.1",
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "git://github.com/jsforce/jsforce.git"