sfobjects-basic-client 1.1.5 → 1.1.7

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 CHANGED
@@ -166,10 +166,10 @@ export interface SfSelectActions<OI, N extends KeyOf<OI>, S extends SfRootSelect
166
166
  limit: (limit: number) => SfSelectActions<OI, N, S>;
167
167
  }
168
168
  export interface SfOrderByAction<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
169
- orderBy: (orderBy: SfRootOrderBy<OI, N>) => SfSelectActions<OI, N, S>;
169
+ orderBy: <R extends SfRootOrderBy<OI, N>>(orderBy: R) => SfSelectActions<OI, N, S>;
170
170
  }
171
171
  export interface SfWhereActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
172
- where: (where: SfRootWhere<OI, N>) => (SfSelectActions<OI, N, S> & SfOrderByAction<OI, N, S>);
172
+ where: <W extends SfRootWhere<OI, N>>(where: W) => (SfSelectActions<OI, N, S> & SfOrderByAction<OI, N, S>);
173
173
  }
174
174
  export interface SfSelectAditionalActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
175
175
  find: (id: string, options?: SfQueryOptions) => Promise<SfRootSelectProjection<OI, N, S> | undefined>;
@@ -177,9 +177,9 @@ export interface SfSelectAditionalActions<OI, N extends KeyOf<OI>, S extends SfR
177
177
  selection: S[];
178
178
  }
179
179
  export interface SfObjActions<OI, N extends KeyOf<OI>> {
180
- query: <S extends SfRootSelect<OI, N>>(q: {
180
+ query: <S extends SfRootSelect<OI, N>, W extends SfRootWhere<OI, N>>(q: {
181
181
  select: S[];
182
- where?: SfRootWhere<OI, N>;
182
+ where?: string | W;
183
183
  orderBy?: SfRootOrderBy<OI, N>;
184
184
  limit?: number;
185
185
  }) => SfSelectActions<OI, N, S>;
@@ -189,14 +189,20 @@ export interface SfObjActions<OI, N extends KeyOf<OI>> {
189
189
  upsert: <K extends MandatoryCreateProps<OI[N]>>(records: SfUpsert<OI[N], K>[], key: K, options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
190
190
  select: <S extends SfRootSelect<OI, N>>(select: S[]) => (SfSelectActions<OI, N, S> & SfWhereActions<OI, N, S> & SfSelectAditionalActions<OI, N, S>);
191
191
  }
192
- export declare class SfBasicClientError extends Error {
192
+ export declare class SfBasicClientSaveError extends Error {
193
193
  errors: SfSaveError[];
194
194
  constructor(errors: SfSaveError[]);
195
195
  }
196
+ export declare class SfBasicClientReadError extends Error {
197
+ error: string;
198
+ constructor(error: string);
199
+ }
196
200
  export declare function isPlainObject(value: unknown): value is Record<string, any>;
197
201
  export declare function constructSoql<OI>(_cfg: SfObjCfgIndex<OI>): (objName: string, from: string, select: (string | {})[], where?: string | Record<string, any>, orderBy?: Record<string, any>, limit?: number) => string;
198
202
  export declare function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions): <N extends KeyOf<OI>>(from: N, _conn: ISfConnection) => SfObjActions<OI, N>;
199
- export declare const getSfObjects: <OI>(cfg: SfObjCfgIndex<OI>) => (conn: ISfConnection, options?: SfClientOptions) => { [N in KeyOf<OI>]: SfObjActions<OI, N>; };
203
+ export declare const getSfObjects: <OI>(cfg: SfObjCfgIndex<OI>) => (conn: ISfConnection, options?: SfClientOptions) => { [N in KeyOf<OI>]: SfObjActions<OI, N>; } & {
204
+ __getObject: <N_1 extends KeyOf<OI>>(from: N_1) => SfObjActions<OI, N_1>;
205
+ };
200
206
  export declare const sfObject: <OI, N extends KeyOf<OI>>(cfg: SfObjCfgIndex<OI>, n: N) => {
201
207
  info: SfObjCfgIndex<OI>[N];
202
208
  select: <S extends SfRootSelect<OI, N>>(s: S[]) => S[];
package/dist/index.js CHANGED
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.sfObject = exports.getSfObjects = exports.SfBasicClientError = void 0;
24
+ exports.sfObject = exports.getSfObjects = exports.SfBasicClientReadError = exports.SfBasicClientSaveError = void 0;
25
25
  exports.isPlainObject = isPlainObject;
26
26
  exports.constructSoql = constructSoql;
27
27
  exports.getSfObject = getSfObject;
@@ -70,15 +70,24 @@ const OP_RULES = [
70
70
  { ops: OP_KEYS_LIKE, soqlOp: 'like' },
71
71
  { ops: OP_KEYS_NLIKE, soqlOp: 'like', isNot: true },
72
72
  ];
73
- class SfBasicClientError extends Error {
73
+ class SfBasicClientSaveError extends Error {
74
74
  constructor(errors) {
75
75
  super('Salesforce error(s): ' + errors.map(e => { var _a; return `[${e.errorCode}] ${e.message}, field(s): ${(_a = e.fields) === null || _a === void 0 ? void 0 : _a.join(',')}`; }).join(';\r\n'));
76
76
  this.errors = errors;
77
- this.name = 'SfBasicClientError';
77
+ this.name = 'SfBasicClientSaveError';
78
78
  Object.setPrototypeOf(this, new.target.prototype);
79
79
  }
80
80
  }
81
- exports.SfBasicClientError = SfBasicClientError;
81
+ exports.SfBasicClientSaveError = SfBasicClientSaveError;
82
+ class SfBasicClientReadError extends Error {
83
+ constructor(error) {
84
+ super('Salesforce error: ' + error);
85
+ this.error = error;
86
+ this.name = 'SfBasicClientReadError';
87
+ Object.setPrototypeOf(this, new.target.prototype);
88
+ }
89
+ }
90
+ exports.SfBasicClientReadError = SfBasicClientReadError;
82
91
  // functions
83
92
  function isPlainObject(value) {
84
93
  if (typeof value !== 'object' || value === null)
@@ -235,7 +244,7 @@ function processSaveResult(sr, breakOnError) {
235
244
  if (breakOnError) {
236
245
  const _errors = sr.filter(r => (r.success !== true)).map(r => r.errors).flat();
237
246
  if (_errors.length) {
238
- throw new SfBasicClientError(_errors);
247
+ throw new SfBasicClientSaveError(_errors);
239
248
  }
240
249
  }
241
250
  return sr;
@@ -270,7 +279,7 @@ function getSfObject(_cfg, o) {
270
279
  }), 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) {
271
280
  const result = yield _queryOne(_conn, from, select, id, options);
272
281
  if (!result.records.length) {
273
- throw new Error(`Record with id '${id}' is not found in '${from}'.`);
282
+ throw new SfBasicClientReadError(`Record with id '${id}' is not found in '${from}'.`);
274
283
  }
275
284
  return result.records[0];
276
285
  }), selection: select }))
@@ -278,8 +287,8 @@ function getSfObject(_cfg, o) {
278
287
  };
279
288
  }
280
289
  const getSfObjects = (cfg) => (conn, options) => {
281
- const _func = getSfObject(cfg, options);
282
- return Object.keys(cfg).reduce((p, n) => (Object.assign(Object.assign({}, p), { [n]: _func(n, conn) })), {});
290
+ const __getObject = (from) => getSfObject(cfg, options)(from, conn);
291
+ return Object.assign(Object.assign({}, Object.keys(cfg).reduce((p, n) => (Object.assign(Object.assign({}, p), { [n]: __getObject(n) })), {})), { __getObject });
283
292
  };
284
293
  exports.getSfObjects = getSfObjects;
285
294
  const sfObject = (cfg, n) => ({ info: cfg[n], select: (s) => s });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sfobjects-basic-client",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "Basic Salesforce Client to use together with sfobjects-to-typescript lib",
5
5
  "license": "ISC",
6
6
  "author": "Murad Aliyev",
package/src/index.ts CHANGED
@@ -265,11 +265,11 @@ export interface SfSelectActions<OI, N extends KeyOf<OI>, S extends SfRootSelect
265
265
  }
266
266
 
267
267
  export interface SfOrderByAction<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
268
- orderBy: (orderBy: SfRootOrderBy<OI, N>) => SfSelectActions<OI, N, S>;
268
+ orderBy: <R extends SfRootOrderBy<OI, N>>(orderBy: R) => SfSelectActions<OI, N, S>;
269
269
  }
270
270
 
271
271
  export interface SfWhereActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
272
- where: (where: SfRootWhere<OI, N>) => (SfSelectActions<OI, N, S> & SfOrderByAction<OI, N, S>);
272
+ where: <W extends SfRootWhere<OI, N>>(where: W) => (SfSelectActions<OI, N, S> & SfOrderByAction<OI, N, S>);
273
273
  }
274
274
 
275
275
  export interface SfSelectAditionalActions<OI, N extends KeyOf<OI>, S extends SfRootSelect<OI, N>> {
@@ -280,7 +280,7 @@ export interface SfSelectAditionalActions<OI, N extends KeyOf<OI>, S extends SfR
280
280
  }
281
281
 
282
282
  export interface SfObjActions<OI, N extends KeyOf<OI>> {
283
- query: <S extends SfRootSelect<OI, N>>(q: { select: S[], where?: SfRootWhere<OI, N>, orderBy?: SfRootOrderBy<OI, N>, limit?: number }) => SfSelectActions<OI, N, S>;
283
+ query: <S extends SfRootSelect<OI, N>, W extends SfRootWhere<OI, N>>(q: { select: S[], where?: string | W, orderBy?: SfRootOrderBy<OI, N>, limit?: number }) => SfSelectActions<OI, N, S>;
284
284
  delete: (ids: string[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
285
285
  update: (records: SfUpdate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
286
286
  create: (records: SfCreate<OI[N]>[], options?: SfDmlOptions) => PromiseLike<SfSaveResult[]>;
@@ -557,12 +557,12 @@ function processSaveResult(sr: SfSaveResult[], breakOnError?: boolean): SfSaveRe
557
557
  export function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions) {
558
558
 
559
559
 
560
- function _query<S extends SfRootSelect<OI, N>, N extends KeyOf<OI>>(
560
+ function _query<S extends SfRootSelect<OI, N>, W extends SfRootWhere<OI, N>, R extends SfRootOrderBy<OI, N>, N extends KeyOf<OI>>(
561
561
  conn: ISfConnection,
562
562
  from: N,
563
563
  select: S[],
564
- where?: string | SfRootWhere<OI, N>,
565
- orderBy?: SfRootOrderBy<OI, N>,
564
+ where?: string | W,
565
+ orderBy?: R,
566
566
  limit?: number
567
567
  ): SfSelectActions<OI, N, S> {
568
568
 
@@ -589,7 +589,7 @@ export function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions) {
589
589
 
590
590
  return ({
591
591
 
592
- query: <S extends SfRootSelect<OI, N>>(q: { select: S[], where?: SfRootWhere<OI, N>, orderBy?: SfRootOrderBy<OI, N>, limit?: number }) => {
592
+ query: <S extends SfRootSelect<OI, N>, W extends SfRootWhere<OI, N>, R extends SfRootOrderBy<OI, N>>(q: { select: S[], where?: string | W, orderBy?: R, limit?: number }) => {
593
593
  const { select, where, orderBy, limit } = q;
594
594
  return _query(_conn, from, select, where, orderBy, limit);
595
595
  },
@@ -606,13 +606,13 @@ export function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions) {
606
606
 
607
607
  ..._query(_conn, from, select),
608
608
 
609
- orderBy: (orderBy: SfRootOrderBy<OI, N>) => _query(_conn, from, select, undefined, orderBy),
609
+ orderBy: <R extends SfRootOrderBy<OI, N>>(orderBy: R) => _query(_conn, from, select, undefined, orderBy),
610
610
 
611
- where: (where: SfRootWhere<OI, N>) => ({
611
+ where: <W extends SfRootWhere<OI, N>>(where: string | W) => ({
612
612
 
613
613
  ..._query(_conn, from, select, where),
614
614
 
615
- orderBy: (orderBy: SfRootOrderBy<OI, N>) => _query(_conn, from, select, where, orderBy),
615
+ orderBy: <R extends SfRootOrderBy<OI, N>>(orderBy: R) => _query(_conn, from, select, where, orderBy),
616
616
 
617
617
  }),
618
618
 
@@ -645,8 +645,13 @@ export function getSfObject<OI>(_cfg: SfObjCfgIndex<OI>, o?: SfClientOptions) {
645
645
 
646
646
 
647
647
  export const getSfObjects = <OI>(cfg: SfObjCfgIndex<OI>) => (conn: ISfConnection, options?: SfClientOptions) => {
648
- const _func = getSfObject<OI>(cfg, options);
649
- return (Object.keys(cfg) as KeyOf<OI>[]).reduce((p, n) => ({ ...p, [n]: _func(n, conn) }), {} as { [N in KeyOf<OI>]: SfObjActions<OI, N> });
648
+
649
+ const __getObject = <N extends KeyOf<OI>>(from: N) => getSfObject<OI>(cfg, options)(from, conn);
650
+
651
+ return {
652
+ ...(Object.keys(cfg) as KeyOf<OI>[]).reduce((p, n) => ({ ...p, [n]: __getObject(n) }), {} as { [N in KeyOf<OI>]: SfObjActions<OI, N> }),
653
+ __getObject
654
+ };
650
655
  }
651
656
 
652
657
  export const sfObject = <OI, N extends KeyOf<OI>>(cfg: SfObjCfgIndex<OI>, n: N) => ({ info: cfg[n], select: <S extends SfRootSelect<OI, N>>(s: S[]) => s });