sfobjects-basic-client 1.1.8 → 1.1.10
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/dist/index.d.ts +5 -5
- package/dist/index.js +13 -4
- package/package.json +1 -1
- package/src/index.ts +22 -9
package/dist/index.d.ts
CHANGED
|
@@ -172,7 +172,7 @@ export interface SfOrderByAction<OI, N extends KeyOf<OI>, S extends SfRootSelect
|
|
|
172
172
|
orderBy: <R extends SfRootOrderBy<OI, N>>(orderBy: R) => (SfQueryActions<OI, N, S> & SfLimitAction<OI, N, S>);
|
|
173
173
|
}
|
|
174
174
|
export interface SfWhereActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
|
|
175
|
-
where: <W extends SfRootWhere<OI, N>>(where: W) => (SfQueryActions<OI, N, S> & SfOrderByAction<OI, N, S>);
|
|
175
|
+
where: <W extends SfRootWhere<OI, N>>(where: W) => (SfQueryActions<OI, N, S> & SfOrderByAction<OI, N, S> & SfLimitAction<OI, N, S>);
|
|
176
176
|
}
|
|
177
177
|
export interface SfQueryAditionalActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
|
|
178
178
|
find: (id: string, options?: SfQueryOptions) => Promise<SfRootSelectProjection<OI, N, S> | undefined>;
|
|
@@ -186,10 +186,10 @@ export interface SfObjActions<OI, N extends KeyOf<OI>> {
|
|
|
186
186
|
orderBy?: SfRootOrderBy<OI, N>;
|
|
187
187
|
limit?: number;
|
|
188
188
|
}) => SfQueryActions<OI, N, S>;
|
|
189
|
-
delete: (ids: string[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
190
|
-
update: (records: SfUpdate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
191
|
-
create: (records: SfCreate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
192
|
-
upsert: <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K>[], key: K, options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
189
|
+
delete: (ids: string | string[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
190
|
+
update: (records: SfUpdate<OI[N]> | SfUpdate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
191
|
+
create: (records: SfCreate<OI[N]> | SfCreate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
192
|
+
upsert: <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K> | SfUpsert<OI[N], K>[], key: K, options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
193
193
|
select: <S extends SfRootSelect<OI, N>>(select: S[]) => (SfQueryActions<OI, N, S> & SfWhereActions<OI, N, S> & SfQueryAditionalActions<OI, N, S>);
|
|
194
194
|
}
|
|
195
195
|
export declare class SfBasicClientSaveError extends Error {
|
package/dist/index.js
CHANGED
|
@@ -249,6 +249,15 @@ function processSaveResult(sr, breakOnError) {
|
|
|
249
249
|
}
|
|
250
250
|
return sr;
|
|
251
251
|
}
|
|
252
|
+
function pluralize(a) {
|
|
253
|
+
if (a === undefined) {
|
|
254
|
+
return [];
|
|
255
|
+
}
|
|
256
|
+
if (Array.isArray(a)) {
|
|
257
|
+
return a;
|
|
258
|
+
}
|
|
259
|
+
return [a];
|
|
260
|
+
}
|
|
252
261
|
function getSfObject(_cfg, o) {
|
|
253
262
|
function _query(conn, from, select, where, orderBy, limit) {
|
|
254
263
|
const soql = () => constructSoql(_cfg)(from, from, select, where, orderBy, limit);
|
|
@@ -271,10 +280,10 @@ function getSfObject(_cfg, o) {
|
|
|
271
280
|
const { select, where, orderBy, limit } = q;
|
|
272
281
|
return _query(_conn, from, select, where, orderBy, limit);
|
|
273
282
|
},
|
|
274
|
-
delete: (ids_1, ...args_1) => __awaiter(this, [ids_1, ...args_1], void 0, function* (ids, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.delete(from, ids, options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
275
|
-
update: (records_1, ...args_1) => __awaiter(this, [records_1, ...args_1], void 0, function* (records, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.update(from, records, options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
276
|
-
create: (records_1, ...args_1) => __awaiter(this, [records_1, ...args_1], void 0, function* (records, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.create(from, records, options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
277
|
-
upsert: (records_1, key_1, ...args_1) => __awaiter(this, [records_1, key_1, ...args_1], void 0, function* (records, key, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.upsert(from, records, key, options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
283
|
+
delete: (ids_1, ...args_1) => __awaiter(this, [ids_1, ...args_1], void 0, function* (ids, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.delete(from, pluralize(ids), options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
284
|
+
update: (records_1, ...args_1) => __awaiter(this, [records_1, ...args_1], void 0, function* (records, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.update(from, pluralize(records), options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
285
|
+
create: (records_1, ...args_1) => __awaiter(this, [records_1, ...args_1], void 0, function* (records, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.create(from, pluralize(records), options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
286
|
+
upsert: (records_1, key_1, ...args_1) => __awaiter(this, [records_1, key_1, ...args_1], void 0, function* (records, key, options = o === null || o === void 0 ? void 0 : o.dml) { return processSaveResult(yield _conn.upsert(from, pluralize(records), key, options), o === null || o === void 0 ? void 0 : o.breakOnError); }),
|
|
278
287
|
select: (select) => (Object.assign(Object.assign({}, _query(_conn, from, select)), { orderBy: (orderBy) => (Object.assign(Object.assign({}, _query(_conn, from, select, undefined, orderBy)), { limit: (limit) => _query(_conn, from, select, undefined, orderBy, limit) })), limit: (limit) => _query(_conn, from, select, undefined, undefined, limit), where: (where) => (Object.assign(Object.assign({}, _query(_conn, from, select, where)), { orderBy: (orderBy) => (Object.assign(Object.assign({}, _query(_conn, from, select, where, orderBy)), { limit: (limit) => _query(_conn, from, select, where, orderBy, limit) })), limit: (limit) => _query(_conn, from, select, where, undefined, limit) })), find: (id_1, ...args_1) => __awaiter(this, [id_1, ...args_1], void 0, function* (id, options = o === null || o === void 0 ? void 0 : o.query) {
|
|
279
288
|
return _queryOne(_conn, from, select, id, options);
|
|
280
289
|
}), retrieve: (id_1, ...args_1) => __awaiter(this, [id_1, ...args_1], void 0, function* (id, options = o === null || o === void 0 ? void 0 : o.query) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -274,7 +274,7 @@ export interface SfOrderByAction<OI, N extends KeyOf<OI>, S extends SfRootSelect
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
export interface SfWhereActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
|
|
277
|
-
where: <W extends SfRootWhere<OI, N>>(where: W) => (SfQueryActions<OI, N, S> & SfOrderByAction<OI, N, S>);
|
|
277
|
+
where: <W extends SfRootWhere<OI, N>>(where: W) => (SfQueryActions<OI, N, S> & SfOrderByAction<OI, N, S> & SfLimitAction<OI, N, S>);
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
export interface SfQueryAditionalActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
|
|
@@ -285,10 +285,10 @@ export interface SfQueryAditionalActions<OI, N extends KeyOf<OI>, S extends SfRo
|
|
|
285
285
|
|
|
286
286
|
export interface SfObjActions<OI, N extends KeyOf<OI>> {
|
|
287
287
|
query: <S extends SfRootSelect<OI, N>, W extends SfRootWhere<OI, N>>(q: { select: S[], where?: string | W, orderBy?: SfRootOrderBy<OI, N>, limit?: number }) => SfQueryActions<OI, N, S>;
|
|
288
|
-
delete: (ids: string[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
289
|
-
update: (records: SfUpdate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
290
|
-
create: (records: SfCreate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
291
|
-
upsert: <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K>[], key: K, options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
288
|
+
delete: (ids: string | string[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
289
|
+
update: (records: SfUpdate<OI[N]> | SfUpdate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
290
|
+
create: (records: SfCreate<OI[N]> | SfCreate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
291
|
+
upsert: <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K> | SfUpsert<OI[N], K>[], key: K, options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
|
|
292
292
|
select: <S extends SfRootSelect<OI, N>>(select: S[]) => (SfQueryActions<OI, N, S> & SfWhereActions<OI, N, S> & SfQueryAditionalActions<OI, N, S>);
|
|
293
293
|
}
|
|
294
294
|
|
|
@@ -558,6 +558,19 @@ function processSaveResult(sr: SfSaveResult[], breakOnError?: boolean): SfSaveRe
|
|
|
558
558
|
return sr;
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
+
function pluralize<T>(a: T | T[]) {
|
|
562
|
+
|
|
563
|
+
if (a === undefined) {
|
|
564
|
+
return [];
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (Array.isArray(a)) {
|
|
568
|
+
return a;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return [a];
|
|
572
|
+
}
|
|
573
|
+
|
|
561
574
|
export function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions) {
|
|
562
575
|
|
|
563
576
|
|
|
@@ -603,13 +616,13 @@ export function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions) {
|
|
|
603
616
|
return _query(_conn, from, select, where, orderBy, limit);
|
|
604
617
|
},
|
|
605
618
|
|
|
606
|
-
delete: async (ids: string[], options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.delete(from, ids, options), o?.breakOnError),
|
|
619
|
+
delete: async (ids: string | string[], options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.delete(from, pluralize(ids), options), o?.breakOnError),
|
|
607
620
|
|
|
608
|
-
update: async (records: SfUpdate<OI[N]>[], options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.update(from, records, options), o?.breakOnError),
|
|
621
|
+
update: async (records: SfUpdate<OI[N]> | SfUpdate<OI[N]>[], options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.update(from, pluralize(records), options), o?.breakOnError),
|
|
609
622
|
|
|
610
|
-
create: async (records: SfCreate<OI[N]>[], options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.create(from, records, options), o?.breakOnError),
|
|
623
|
+
create: async (records: SfCreate<OI[N]> | SfCreate<OI[N]>[], options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.create(from, pluralize(records), options), o?.breakOnError),
|
|
611
624
|
|
|
612
|
-
upsert: async <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K>[], key: K, options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.upsert(from, records, key, options), o?.breakOnError),
|
|
625
|
+
upsert: async <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K> | SfUpsert<OI[N], K>[], key: K, options: SfDmlOptions | undefined = o?.dml) => processSaveResult(await _conn.upsert(from, pluralize(records), key, options), o?.breakOnError),
|
|
613
626
|
|
|
614
627
|
select: <S extends SfRootSelect<OI, N>>(select: S[]) => ({
|
|
615
628
|
|