@jsforce/jsforce-node 0.0.1 → 3.0.0-next.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.
Files changed (127) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +54 -0
  3. package/index.d.ts +4 -0
  4. package/index.js +1 -0
  5. package/lib/VERSION.d.ts +2 -0
  6. package/lib/VERSION.js +3 -0
  7. package/lib/api/analytics/types.d.ts +509 -0
  8. package/lib/api/analytics/types.js +2 -0
  9. package/lib/api/analytics.d.ts +163 -0
  10. package/lib/api/analytics.js +342 -0
  11. package/lib/api/apex.d.ts +44 -0
  12. package/lib/api/apex.js +86 -0
  13. package/lib/api/bulk.d.ts +444 -0
  14. package/lib/api/bulk.js +1372 -0
  15. package/lib/api/chatter.d.ts +133 -0
  16. package/lib/api/chatter.js +248 -0
  17. package/lib/api/metadata/schema.d.ts +16117 -0
  18. package/lib/api/metadata/schema.js +9094 -0
  19. package/lib/api/metadata.d.ts +189 -0
  20. package/lib/api/metadata.js +406 -0
  21. package/lib/api/soap/schema.d.ts +3167 -0
  22. package/lib/api/soap/schema.js +1787 -0
  23. package/lib/api/soap.d.ts +76 -0
  24. package/lib/api/soap.js +155 -0
  25. package/lib/api/streaming/extension.d.ts +94 -0
  26. package/lib/api/streaming/extension.js +151 -0
  27. package/lib/api/streaming.d.ts +160 -0
  28. package/lib/api/streaming.js +252 -0
  29. package/lib/api/tooling.d.ts +284 -0
  30. package/lib/api/tooling.js +202 -0
  31. package/lib/api/wsdl/wsdl2schema.d.ts +1 -0
  32. package/lib/api/wsdl/wsdl2schema.js +354 -0
  33. package/lib/browser/canvas.d.ts +12 -0
  34. package/lib/browser/canvas.js +77 -0
  35. package/lib/browser/client.d.ts +82 -0
  36. package/lib/browser/client.js +244 -0
  37. package/lib/browser/jsonp.d.ts +12 -0
  38. package/lib/browser/jsonp.js +69 -0
  39. package/lib/browser/registry.d.ts +3 -0
  40. package/lib/browser/registry.js +5 -0
  41. package/lib/browser/request.d.ts +10 -0
  42. package/lib/browser/request.js +202 -0
  43. package/lib/cache.d.ts +74 -0
  44. package/lib/cache.js +159 -0
  45. package/lib/connection.d.ts +355 -0
  46. package/lib/connection.js +1153 -0
  47. package/lib/core.d.ts +17 -0
  48. package/lib/core.js +55 -0
  49. package/lib/csv.d.ts +23 -0
  50. package/lib/csv.js +35 -0
  51. package/lib/date.d.ts +82 -0
  52. package/lib/date.js +201 -0
  53. package/lib/http-api.d.ts +75 -0
  54. package/lib/http-api.js +257 -0
  55. package/lib/index.d.ts +12 -0
  56. package/lib/index.js +31 -0
  57. package/lib/jsforce.d.ts +26 -0
  58. package/lib/jsforce.js +67 -0
  59. package/lib/jwtOAuth2.d.ts +8 -0
  60. package/lib/jwtOAuth2.js +23 -0
  61. package/lib/oauth2.d.ts +92 -0
  62. package/lib/oauth2.js +245 -0
  63. package/lib/process.d.ts +157 -0
  64. package/lib/process.js +143 -0
  65. package/lib/query.d.ts +341 -0
  66. package/lib/query.js +817 -0
  67. package/lib/quick-action.d.ts +44 -0
  68. package/lib/quick-action.js +46 -0
  69. package/lib/record-reference.d.ts +46 -0
  70. package/lib/record-reference.js +65 -0
  71. package/lib/record-stream.d.ts +83 -0
  72. package/lib/record-stream.js +233 -0
  73. package/lib/registry/base.d.ts +43 -0
  74. package/lib/registry/base.js +96 -0
  75. package/lib/registry/empty.d.ts +7 -0
  76. package/lib/registry/empty.js +13 -0
  77. package/lib/registry/file.d.ts +11 -0
  78. package/lib/registry/file.js +51 -0
  79. package/lib/registry/index.d.ts +8 -0
  80. package/lib/registry/index.js +21 -0
  81. package/lib/registry/sfdx.d.ts +56 -0
  82. package/lib/registry/sfdx.js +133 -0
  83. package/lib/registry/types.d.ts +47 -0
  84. package/lib/registry/types.js +2 -0
  85. package/lib/request-helper.d.ts +23 -0
  86. package/lib/request-helper.js +102 -0
  87. package/lib/request.d.ts +11 -0
  88. package/lib/request.js +75 -0
  89. package/lib/session-refresh-delegate.d.ts +31 -0
  90. package/lib/session-refresh-delegate.js +69 -0
  91. package/lib/soap.d.ts +60 -0
  92. package/lib/soap.js +246 -0
  93. package/lib/sobject.d.ts +258 -0
  94. package/lib/sobject.js +376 -0
  95. package/lib/soql-builder.d.ts +25 -0
  96. package/lib/soql-builder.js +226 -0
  97. package/lib/transport.d.ts +63 -0
  98. package/lib/transport.js +175 -0
  99. package/lib/types/common.d.ts +560 -0
  100. package/lib/types/common.js +2 -0
  101. package/lib/types/index.d.ts +7 -0
  102. package/lib/types/index.js +23 -0
  103. package/lib/types/projection.d.ts +26 -0
  104. package/lib/types/projection.js +2 -0
  105. package/lib/types/record.d.ts +44 -0
  106. package/lib/types/record.js +2 -0
  107. package/lib/types/schema.d.ts +50 -0
  108. package/lib/types/schema.js +2 -0
  109. package/lib/types/soap.d.ts +43 -0
  110. package/lib/types/soap.js +2 -0
  111. package/lib/types/standard-schema.d.ts +16199 -0
  112. package/lib/types/standard-schema.js +2 -0
  113. package/lib/types/util.d.ts +7 -0
  114. package/lib/types/util.js +2 -0
  115. package/lib/util/formatter.d.ts +8 -0
  116. package/lib/util/formatter.js +24 -0
  117. package/lib/util/function.d.ts +32 -0
  118. package/lib/util/function.js +52 -0
  119. package/lib/util/logger.d.ts +29 -0
  120. package/lib/util/logger.js +102 -0
  121. package/lib/util/promise.d.ts +19 -0
  122. package/lib/util/promise.js +25 -0
  123. package/lib/util/stream.d.ts +12 -0
  124. package/lib/util/stream.js +88 -0
  125. package/package.json +260 -6
  126. package/typings/faye/index.d.ts +16 -0
  127. package/typings/index.d.ts +1 -0
package/lib/query.d.ts ADDED
@@ -0,0 +1,341 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /**
5
+ * @file Manages query for records in Salesforce
6
+ * @author Shinichi Tomita <shinichi.tomita@gmail.com>
7
+ */
8
+ import { EventEmitter } from 'events';
9
+ import { Logger } from './util/logger';
10
+ import { Serializable } from './record-stream';
11
+ import Connection from './connection';
12
+ import { QueryConfig as SOQLQueryConfig, SortDir } from './soql-builder';
13
+ import { Record, Optional, Schema, SObjectNames, ChildRelationshipNames, ChildRelationshipSObjectName, FieldProjectionConfig, FieldPathSpecifier, FieldPathScopedProjection, SObjectRecord, SObjectInputRecord, SaveResult, DateString, SObjectChildRelationshipProp, SObjectFieldNames } from './types';
14
+ import { Readable } from 'stream';
15
+ import SfDate from './date';
16
+ /**
17
+ *
18
+ */
19
+ export type QueryField<S extends Schema, N extends SObjectNames<S>, FP extends FieldPathSpecifier<S, N> = FieldPathSpecifier<S, N>> = FP | FP[] | string | string[] | {
20
+ [field: string]: number | boolean;
21
+ };
22
+ /**
23
+ *
24
+ */
25
+ type CValue<T> = T extends DateString ? SfDate : T extends string | number | boolean ? T : never;
26
+ type CondOp<T> = ['$eq', CValue<T> | null] | ['$ne', CValue<T> | null] | ['$gt', CValue<T>] | ['$gte', CValue<T>] | ['$lt', CValue<T>] | ['$lte', CValue<T>] | ['$like', T extends string ? T : never] | ['$nlike', T extends string ? T : never] | ['$in', Array<CValue<T>>] | ['$nin', Array<CValue<T>>] | ['$includes', T extends string ? T[] : never] | ['$excludes', T extends string ? T[] : never] | ['$exists', boolean];
27
+ type CondValueObj<T, Op = CondOp<T>[0]> = Op extends CondOp<T>[0] ? Op extends string ? {
28
+ [K in Op]: Extract<CondOp<T>, [Op, any]>[1];
29
+ } : never : never;
30
+ type CondValue<T> = CValue<T> | Array<CValue<T>> | null | CondValueObj<T>;
31
+ type ConditionSet<R extends Record> = {
32
+ [K in keyof R]?: CondValue<R[K]>;
33
+ };
34
+ export type QueryCondition<S extends Schema, N extends SObjectNames<S>> = {
35
+ $or: QueryCondition<S, N>[];
36
+ } | {
37
+ $and: QueryCondition<S, N>[];
38
+ } | ConditionSet<SObjectRecord<S, N>>;
39
+ export type QuerySort<S extends Schema, N extends SObjectNames<S>, R extends SObjectRecord<S, N> = SObjectRecord<S, N>> = {
40
+ [K in keyof R]?: SortDir;
41
+ } | Array<[keyof R, SortDir]>;
42
+ /**
43
+ *
44
+ */
45
+ export type QueryConfig<S extends Schema, N extends SObjectNames<S>, FP extends FieldPathSpecifier<S, N> = FieldPathSpecifier<S, N>> = {
46
+ fields?: QueryField<S, N, FP>;
47
+ includes?: {
48
+ [CRN in ChildRelationshipNames<S, N>]?: QueryConfig<S, ChildRelationshipSObjectName<S, N, CRN>>;
49
+ };
50
+ table?: string;
51
+ conditions?: QueryCondition<S, N>;
52
+ sort?: QuerySort<S, N>;
53
+ limit?: number;
54
+ offset?: number;
55
+ };
56
+ export type QueryOptions = {
57
+ headers: {
58
+ [name: string]: string;
59
+ };
60
+ maxFetch: number;
61
+ autoFetch: boolean;
62
+ scanAll: boolean;
63
+ responseTarget: QueryResponseTarget;
64
+ };
65
+ export type QueryResult<R extends Record> = {
66
+ done: boolean;
67
+ totalSize: number;
68
+ records: R[];
69
+ nextRecordsUrl?: string;
70
+ };
71
+ export type QueryExplainResult = {
72
+ plans: Array<{
73
+ cardinality: number;
74
+ fields: string[];
75
+ leadingOperationType: 'Index' | 'Other' | 'Sharing' | 'TableScan';
76
+ notes: Array<{
77
+ description: string;
78
+ fields: string[];
79
+ tableEnumOrId: string;
80
+ }>;
81
+ relativeCost: number;
82
+ sobjectCardinality: number;
83
+ sobjectType: string;
84
+ }>;
85
+ };
86
+ declare const ResponseTargetValues: readonly ["QueryResult", "Records", "SingleRecord", "Count"];
87
+ export type QueryResponseTarget = typeof ResponseTargetValues[number];
88
+ export declare const ResponseTargets: {
89
+ [K in QueryResponseTarget]: K;
90
+ };
91
+ export type QueryResponse<R extends Record, QRT extends QueryResponseTarget = QueryResponseTarget> = QRT extends 'QueryResult' ? QueryResult<R> : QRT extends 'Records' ? R[] : QRT extends 'SingleRecord' ? R | null : number;
92
+ export type BulkApiVersion = 1 | 2;
93
+ export type QueryDestroyOptions = {
94
+ allowBulk?: boolean;
95
+ bulkThreshold?: number;
96
+ bulkApiVersion?: BulkApiVersion;
97
+ };
98
+ export type QueryUpdateOptions = {
99
+ allowBulk?: boolean;
100
+ bulkThreshold?: number;
101
+ bulkApiVersion?: BulkApiVersion;
102
+ };
103
+ /**
104
+ * Query
105
+ */
106
+ export declare class Query<S extends Schema, N extends SObjectNames<S>, R extends Record = Record, QRT extends QueryResponseTarget = QueryResponseTarget> extends EventEmitter {
107
+ static _logger: Logger;
108
+ _conn: Connection<S>;
109
+ _logger: Logger;
110
+ _soql: Optional<string>;
111
+ _locator: Optional<string>;
112
+ _config: SOQLQueryConfig;
113
+ _children: SubQuery<S, N, R, QRT, any, any, any>[];
114
+ _options: QueryOptions;
115
+ _executed: boolean;
116
+ _finished: boolean;
117
+ _chaining: boolean;
118
+ _promise: Promise<QueryResponse<R, QRT>>;
119
+ _stream: Serializable<R>;
120
+ totalSize: number;
121
+ totalFetched: number;
122
+ records: R[];
123
+ /**
124
+ *
125
+ */
126
+ constructor(conn: Connection<S>, config: string | QueryConfig<S, N> | {
127
+ locator: string;
128
+ }, options?: Partial<QueryOptions>);
129
+ /**
130
+ * Select fields to include in the returning result
131
+ */
132
+ select<R extends Record = Record, FP extends FieldPathSpecifier<S, N> = FieldPathSpecifier<S, N>, FPC extends FieldProjectionConfig = FieldPathScopedProjection<S, N, FP>, R2 extends SObjectRecord<S, N, FPC, R> = SObjectRecord<S, N, FPC, R>>(fields?: QueryField<S, N, FP>): Query<S, N, R2, QRT>;
133
+ /**
134
+ * Set query conditions to filter the result records
135
+ */
136
+ where(conditions: QueryCondition<S, N> | string): this;
137
+ /**
138
+ * Limit the returning result
139
+ */
140
+ limit(limit: number): this;
141
+ /**
142
+ * Skip records
143
+ */
144
+ skip(offset: number): this;
145
+ /**
146
+ * Synonym of Query#skip()
147
+ */
148
+ offset: (offset: number) => this;
149
+ /**
150
+ * Set query sort with direction
151
+ */
152
+ sort(sort: QuerySort<S, N>): this;
153
+ sort(sort: string): this;
154
+ sort(sort: SObjectFieldNames<S, N>, dir: SortDir): this;
155
+ sort(sort: string, dir: SortDir): this;
156
+ /**
157
+ * Synonym of Query#sort()
158
+ */
159
+ orderby: typeof Query.prototype.sort;
160
+ /**
161
+ * Include child relationship query and move down to the child query context
162
+ */
163
+ include<CRN extends ChildRelationshipNames<S, N>, CN extends ChildRelationshipSObjectName<S, N, CRN>, CFP extends FieldPathSpecifier<S, CN> = FieldPathSpecifier<S, CN>, CFPC extends FieldProjectionConfig = FieldPathScopedProjection<S, CN, CFP>, CR extends Record = SObjectRecord<S, CN, CFPC>>(childRelName: CRN, conditions?: Optional<QueryCondition<S, CN>>, fields?: Optional<QueryField<S, CN, CFP>>, options?: {
164
+ limit?: number;
165
+ offset?: number;
166
+ sort?: QuerySort<S, CN>;
167
+ }): SubQuery<S, N, R, QRT, CRN, CN, CR>;
168
+ include<CRN extends ChildRelationshipNames<S, N>, CN extends SObjectNames<S>, CR extends Record = SObjectRecord<S, CN>>(childRelName: string, conditions?: Optional<QueryCondition<S, CN>>, fields?: Optional<QueryField<S, CN>>, options?: {
169
+ limit?: number;
170
+ offset?: number;
171
+ sort?: QuerySort<S, CN>;
172
+ }): SubQuery<S, N, R, QRT, CRN, CN, CR>;
173
+ /**
174
+ * Include child relationship queries, but not moving down to the children context
175
+ */
176
+ includeChildren(includes: {
177
+ [CRN in ChildRelationshipNames<S, N>]?: QueryConfig<S, ChildRelationshipSObjectName<S, N, CRN>>;
178
+ }): this;
179
+ /**
180
+ * Setting maxFetch query option
181
+ */
182
+ maxFetch(maxFetch: number): this;
183
+ /**
184
+ * Switching auto fetch mode
185
+ */
186
+ autoFetch(autoFetch: boolean): this;
187
+ /**
188
+ * Set flag to scan all records including deleted and archived.
189
+ */
190
+ scanAll(scanAll: boolean): this;
191
+ /**
192
+ *
193
+ */
194
+ setResponseTarget<QRT1 extends QueryResponseTarget>(responseTarget: QRT1): Query<S, N, R, QRT1>;
195
+ /**
196
+ * Execute query and fetch records from server.
197
+ */
198
+ execute<QRT1 extends QueryResponseTarget = QRT>(options_?: Partial<QueryOptions> & {
199
+ responseTarget?: QRT1;
200
+ }): Query<S, N, R, QRT1>;
201
+ /**
202
+ * Synonym of Query#execute()
203
+ */
204
+ exec: <QRT1 extends "Records" | "QueryResult" | "SingleRecord" | "Count" = QRT>(options_?: Partial<QueryOptions> & {
205
+ responseTarget?: QRT1 | undefined;
206
+ }) => Query<S, N, R, QRT1>;
207
+ /**
208
+ * Synonym of Query#execute()
209
+ */
210
+ run: <QRT1 extends "Records" | "QueryResult" | "SingleRecord" | "Count" = QRT>(options_?: Partial<QueryOptions> & {
211
+ responseTarget?: QRT1 | undefined;
212
+ }) => Query<S, N, R, QRT1>;
213
+ private locatorToUrl;
214
+ private urlToLocator;
215
+ private constructResponse;
216
+ /**
217
+ * @private
218
+ */
219
+ _execute(options: QueryOptions): Promise<QueryResponse<R>>;
220
+ /**
221
+ * Obtain readable stream instance
222
+ */
223
+ stream(type: 'record'): Serializable<R>;
224
+ stream(type: 'csv'): Readable;
225
+ /**
226
+ * Pipe the queried records to another stream
227
+ * This is for backward compatibility; Query is not a record stream instance anymore in 2.0.
228
+ * If you want a record stream instance, use `Query#stream('record')`.
229
+ */
230
+ pipe(stream: NodeJS.WritableStream): NodeJS.WritableStream;
231
+ /**
232
+ * @protected
233
+ */
234
+ _expandFields(sobject_?: string): Promise<void>;
235
+ /**
236
+ *
237
+ */
238
+ _findRelationObject(relName: string): Promise<string>;
239
+ /**
240
+ *
241
+ */
242
+ _expandAsteriskFields(sobject: string, fields: string[]): Promise<string[]>;
243
+ /**
244
+ *
245
+ */
246
+ _expandAsteriskField(sobject: string, field: string): Promise<string[]>;
247
+ /**
248
+ * Explain plan for executing query
249
+ */
250
+ explain(): Promise<QueryExplainResult>;
251
+ /**
252
+ * Return SOQL expression for the query
253
+ */
254
+ toSOQL(): Promise<string>;
255
+ /**
256
+ * Promise/A+ interface
257
+ * http://promises-aplus.github.io/promises-spec/
258
+ *
259
+ * Delegate to deferred promise, return promise instance for query result
260
+ */
261
+ then<U, V>(onResolve?: ((qr: QueryResponse<R, QRT>) => U | Promise<U>) | null | undefined, onReject?: ((err: Error) => V | Promise<V>) | null | undefined): Promise<U | V>;
262
+ catch(onReject: (err: Error) => QueryResponse<R, QRT> | Promise<QueryResponse<R, QRT>>): Promise<QueryResponse<R, QRT>>;
263
+ promise(): Promise<QueryResponse<R, QRT>>;
264
+ /**
265
+ * Bulk delete queried records
266
+ */
267
+ destroy(options?: QueryDestroyOptions): Promise<SaveResult[]>;
268
+ destroy(type: N, options?: QueryDestroyOptions): Promise<SaveResult[]>;
269
+ /**
270
+ * Synonym of Query#destroy()
271
+ */
272
+ delete: {
273
+ (options?: QueryDestroyOptions | undefined): Promise<SaveResult[]>;
274
+ (type: N, options?: QueryDestroyOptions | undefined): Promise<SaveResult[]>;
275
+ };
276
+ /**
277
+ * Synonym of Query#destroy()
278
+ */
279
+ del: {
280
+ (options?: QueryDestroyOptions | undefined): Promise<SaveResult[]>;
281
+ (type: N, options?: QueryDestroyOptions | undefined): Promise<SaveResult[]>;
282
+ };
283
+ /**
284
+ * Bulk update queried records, using given mapping function/object
285
+ */
286
+ update<UR extends SObjectInputRecord<S, N>>(mapping: ((rec: R) => UR) | UR, type: N, options?: QueryUpdateOptions): Promise<SaveResult[]>;
287
+ update<UR extends SObjectInputRecord<S, N>>(mapping: ((rec: R) => UR) | UR, options?: QueryUpdateOptions): Promise<SaveResult[]>;
288
+ private mapBulkV2ResultsToSaveResults;
289
+ }
290
+ /**
291
+ * SubQuery object for representing child relationship query
292
+ */
293
+ export declare class SubQuery<S extends Schema, PN extends SObjectNames<S>, PR extends Record, PQRT extends QueryResponseTarget, CRN extends ChildRelationshipNames<S, PN> = ChildRelationshipNames<S, PN>, CN extends SObjectNames<S> = ChildRelationshipSObjectName<S, PN, CRN>, CR extends Record = Record> {
294
+ _relName: CRN;
295
+ _query: Query<S, CN, CR>;
296
+ _parent: Query<S, PN, PR, PQRT>;
297
+ /**
298
+ *
299
+ */
300
+ constructor(conn: Connection<S>, relName: CRN, config: QueryConfig<S, CN>, parent: Query<S, PN, PR, PQRT>);
301
+ /**
302
+ *
303
+ */
304
+ select<R extends Record = Record, FP extends FieldPathSpecifier<S, CN> = FieldPathSpecifier<S, CN>, FPC extends FieldProjectionConfig = FieldPathScopedProjection<S, CN, FP>>(fields: QueryField<S, CN, FP>): SubQuery<S, PN, PR, PQRT, CRN, CN, SObjectRecord<S, CN, FPC, R>>;
305
+ /**
306
+ *
307
+ */
308
+ where(conditions: QueryCondition<S, CN> | string): this;
309
+ /**
310
+ * Limit the returning result
311
+ */
312
+ limit(limit: number): this;
313
+ /**
314
+ * Skip records
315
+ */
316
+ skip(offset: number): this;
317
+ /**
318
+ * Synonym of SubQuery#skip()
319
+ */
320
+ offset: (offset: number) => this;
321
+ /**
322
+ * Set query sort with direction
323
+ */
324
+ sort(sort: QuerySort<S, CN>): this;
325
+ sort(sort: string): this;
326
+ sort(sort: SObjectFieldNames<S, CN>, dir: SortDir): this;
327
+ sort(sort: string, dir: SortDir): this;
328
+ /**
329
+ * Synonym of SubQuery#sort()
330
+ */
331
+ orderby: typeof SubQuery.prototype.sort;
332
+ /**
333
+ *
334
+ */
335
+ _expandFields(): Promise<void>;
336
+ /**
337
+ * Back the context to parent query object
338
+ */
339
+ end<CRP extends SObjectChildRelationshipProp<CRN, CR> = SObjectChildRelationshipProp<CRN, CR>, PR1 extends Record = PR & CRP>(): Query<S, PN, PR1, PQRT>;
340
+ }
341
+ export default Query;