Merge pull request #16582 from dolanmiu/jsforce

New Typings: jsforce
This commit is contained in:
Arthur Ozga
2017-05-18 16:02:20 -07:00
committed by GitHub
13 changed files with 357 additions and 0 deletions

28
types/jsforce/connection.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
import { SObjectCreateOptions } from './create-options';
import { DescribeSObjectResult } from './describe-result';
import { Query } from './query';
import { RecordResult } from './record-result';
import { SObject } from './salesforce-object';
export interface ConnectionOptions {
instanceUrl?: string;
accessToken?: string;
refreshToken?: string;
oauth2?: {
clientId: string,
clientSecret: string,
redirectUri?: string,
};
sessionId?: string;
serverUrl?: string;
redirectUri?: string;
}
export type ConnectionEvent = "refresh";
export class Connection {
constructor(params: ConnectionOptions)
sobject(resource: string): SObject;
on(eventName: ConnectionEvent, callback: Function): void;
}

42
types/jsforce/create-options.d.ts vendored Normal file
View File

@@ -0,0 +1,42 @@
import { SalesforceId } from './salesforce-id';
import { SObjectOptions } from './salesforce-object-options';
export interface SObjectCreateOptions extends SObjectOptions {
IsDeleted?: boolean;
MasterRecordId?: SalesforceId;
Name?: string;
Type?: string;
ParentId?: SalesforceId;
BillingStreet?: string;
BillingCity?: string;
BillingState?: string;
BillingPostalCode?: string;
BillingCountry?: string;
BillingLatitude?: number;
BillingLongitude?: number;
ShippingStreet?: string;
ShippingCity?: string;
ShippingState?: string;
ShippingPostalCode?: string;
ShippingCountry?: string;
ShippingLatitude?: number;
ShippingLongitude?: number;
Phone?: string;
Website?: string;
Industry?: string;
NumberOfEmployees?: number;
Description?: string;
OwnerId?: SalesforceId;
CreatedDate?: Date;
CreatedById?: SalesforceId;
LastModifiedDate?: Date;
LastModifiedById?: SalesforceId;
SystemModstamp?: Date;
LastActivityDate?: Date;
LastViewedDate?: Date;
LastReferencedDate?: Date;
Jigsaw?: string;
JigsawCompanyId?: string;
AccountSource?: string;
SicDesc?: string;
}

39
types/jsforce/date-enum.d.ts vendored Normal file
View File

@@ -0,0 +1,39 @@
export enum Date {
YESTERDAY,
TODAY,
TOMORROW,
LAST_WEEK,
THIS_WEEK,
NEXT_WEEK,
LAST_MONTH,
THIS_MONTH,
NEXT_MONTH,
LAST_90_DAYS,
NEXT_90_DAYS,
LAST_N_DAYS,
NEXT_N_DAYS,
NEXT_N_WEEKS,
LAST_N_WEEKS,
NEXT_N_MONTHS,
LAST_N_MONTHS,
THIS_QUARTER,
LAST_QUARTER,
NEXT_QUARTER,
NEXT_N_QUARTERS,
LAST_N_QUARTERS,
THIS_YEAR,
LAST_YEAR,
NEXT_YEAR,
NEXT_N_YEARS,
LAST_N_YEARS,
THIS_FISCAL_QUARTER,
LAST_FISCAL_QUARTER,
NEXT_FISCAL_QUARTER,
NEXT_N_FISCAL_QUARTERS,
LAST_N_FISCAL_QUARTERS,
THIS_FISCAL_YEAR,
LAST_FISCAL_YEAR,
NEXT_FISCAL_YEAR,
NEXT_N_FISCAL_YEARS,
LAST_N_FISCAL_YEARS
}

4
types/jsforce/describe-result.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
export interface DescribeSObjectResult {
label: string;
fields: string[];
}

14
types/jsforce/index.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
// Type definitions for archiver 1.8
// Project: https://github.com/jsforce/jsforce
// Definitions by: Dolan Miu <https://github.com/dolanmiu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import * as fs from 'fs';
import * as stream from 'stream';
import * as express from 'express';
import * as glob from 'glob';
export { Date } from './date-enum';
export { RecordResult } from './record-result';
export { Connection } from './connection';
export { SObject } from './salesforce-object';

View File

@@ -0,0 +1,54 @@
import * as sf from 'jsforce';
const salesforceConnection: sf.Connection = new sf.Connection({
instanceUrl: '',
refreshToken: '',
oauth2: {
clientId: '',
clientSecret: '',
},
});
salesforceConnection.sobject("Account").create({
Name: "Test Acc 2",
BillingStreet: "Maplestory street",
BillingPostalCode: "ME4 666"
}, (err: Error, ret: sf.RecordResult) => {
if (err || !ret.success) {
return;
}
});
salesforceConnection.sobject("ContentVersion").create({
OwnerId: '',
Title: 'hello',
PathOnClient: './hello-world.jpg',
VersionData: '{ Test: Data }'
}, (err: Error, ret: sf.RecordResult) => {
if (err || !ret.success) {
return;
}
});
salesforceConnection.sobject("ContentVersion").retrieve("world", {
test: "test"
}, (err: Error, ret: sf.RecordResult) => {
if (err || !ret.success) {
return;
}
});
salesforceConnection.sobject("ContentVersion").findOne<any>({ Id: '' }, (err, contentVersion) => {
});
salesforceConnection.sobject("ContentDocumentLink").create({
ContentDocumentId: '',
LinkedEntityId: '',
ShareType: "I"
}, (err: Error, ret: sf.RecordResult) => {
if (err || !ret.success) {
return;
}
});
sf.Date.YESTERDAY;

34
types/jsforce/query.d.ts vendored Normal file
View File

@@ -0,0 +1,34 @@
import { SalesforceId } from './salesforce-id';
import { RecordResult } from './record-result';
export interface ExecuteOptions {
autoFetch?: boolean;
maxFetch?: number;
scanAll?: number;
}
export class Query<T> {
filter(filter: Object): Query<T>;
hint(hint: Object): Query<T>;
limit(value: number): Query<T>;
maxFetch(value: number): Query<T>;
offset(value: number): Query<T>;
skip(value: number): Query<T>;
sort(keyOrList: string | Object[] | Object, direction?: "ASC" | "DESC" | number): Query<T>;
run(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query<T>;
execute(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query<T>;
exec(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query<T>;
del(callback?: (err: Error, ret: RecordResult) => void): any;
delete(callback?: (err: Error, ret: RecordResult) => void): any;
destroy(callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult[]>;
explain(callback?: (err: Error, info: ExplainInfo) => void): Promise<ExplainInfo>;
scanAll(value: boolean): Query<T>;
select(fields: Object | string[] | string): Query<T>;
then(onSuccess?: Function, onRejected?: Function): Promise<any>;
thenCall(callback?: (err: Error, records: T) => void): Query<T>;
toSOQL(callback: (err: Error, soql: string) => void): Promise<string>;
update(mapping: any, type: string, callback: (err: Error, records: RecordResult[]) => void): Promise<RecordResult[]>;
where(conditions: Object | string): Query<T>;
}
export class ExplainInfo { }

7
types/jsforce/record-result.d.ts vendored Normal file
View File

@@ -0,0 +1,7 @@
import { SalesforceId } from './salesforce-id';
export interface RecordResult {
id: SalesforceId;
success: boolean;
anys: Object[];
}

2
types/jsforce/salesforce-id.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
export class SalesforceId extends String {
}

View File

@@ -0,0 +1,7 @@
import { SalesforceId } from './salesforce-id';
export interface SObjectOptions {
Id?: SalesforceId;
Name?: string;
ExtId__c?: string;
}

90
types/jsforce/salesforce-object.d.ts vendored Normal file
View File

@@ -0,0 +1,90 @@
import * as stream from 'stream';
import { SObjectCreateOptions } from './create-options';
import { DescribeSObjectResult } from './describe-result';
import { Query } from './query';
import { RecordResult } from './record-result';
import { Connection } from './connection';
import { SalesforceId } from './salesforce-id';
export class SObject {
record(options: any, callback?: (err: Error, ret: any) => void): void;
update(options: SObjectCreateOptions, callback?: (err: Error, ret: any) => void): void;
retrieve(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
retrieve(ids: string | string[], options?: Object, callback?: (err: Error, ret: any) => void): void;
// upsert(options: SObjectOptions): void;
describeGlobal(callback: (err: Error, res: any) => void): void;
describe$(callback: (err: Error, ret: DescribeSObjectResult) => void): void;
describeGlobal$(callback: (err: Error, res: any) => void): void;
find<T>(query?: any, callback?: (err: Error, ret: T[]) => void): Query<T>;
find<T>(query?: any, fields?: Object | string[] | string, callback?: (err: Error, ret: T[]) => void): Query<T>;
find<T>(query?: any, fields?: Object | string[] | string, options?: Object, callback?: (err: Error, ret: T[]) => void): Query<T>;
findOne<T>(query?: any, callback?: (err: Error, ret: T) => void): void;
findOne<T>(query?: any, fields?: Object | string[] | string, callback?: (err: Error, ret: T) => void): void;
findOne<T>(query?: any, fields?: Object | string[] | string, options?: Object, callback?: (err: Error, ret: T) => void): void;
approvalLayouts(callback?: (layoutInfo: ApprovalLayoutInfo) => void): Promise<ApprovalLayoutInfo>;
bulkload(operation: string, options?: { extIdField?: string }, input?: Record[] | stream.Stream[] | string[], callback?: (err: Error, ret: RecordResult) => void): Batch;
compactLayouts(callback?: CompactLayoutInfo): Promise<CompactLayoutInfo>;
count(conditions?: Object | string, callback?: (err: Error, num: number) => void): Promise<number>;
create(options: any | any[], callback?: (err: Error, ret: RecordResult | RecordResult[]) => void): Promise<RecordResult | RecordResult[]>;
createBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch;
del(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
destroy(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
delete(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
deleteBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch;
destroyBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch;
destroyHardBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch;
deleted(start: Date | string, end: Date | string, callback?: (info: DeletedRecordsInfo) => void): Promise<DeletedRecordsInfo>;
deleteHardBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch;
describe(callback?: (err: Error, ret: DescribeSObjectResult) => void): Promise<DescribeSObjectResult>;
insert(options: any | any[], callback?: (err: Error, ret: RecordResult | RecordResult[]) => void): Promise<RecordResult | RecordResult[]>;
insertBulk(input?: Record[] | stream.Stream | String, callback?: (err: Error, ret: RecordResult) => void): Batch;
layouts(layoutName?: string, callback?: (err: Error, info: LayoutInfo) => void): Promise<LayoutInfo>;
listview(id: string): ListView;
listviews(callback?: (err: Error, info: ListViewsInfo) => void): Promise<ListViewsInfo>;
quickAction(actionName: string): QuickAction;
quickActions(callback?: (err: Error, info: any) => void): Promise<any>;
recent(callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult>;
select<T>(field?: Object | string[] | string, callback?: (err: Error, ret: T[]) => void): Query<T[]>;
}
export interface ApprovalLayoutInfo {
approvalLayouts: Object[];
}
export class Record extends Object {
constructor(connection: Connection, type: SObject, id: SalesforceId)
}
export class Batch extends stream.Writable {
}
export interface CompactLayoutInfo {
compactLayouts: Object[];
defaultCompactLayoutId: string;
recordTypeCompactLayoutMappings: Object[];
}
export interface DeletedRecordsInfo {
earliestDateAvailable: string;
latestDateCovered: string;
deletedRecords: {
id: string,
deletedDate: string,
};
}
export interface LayoutInfo {
layouts: Object[];
recordTypeMappings: Object[];
}
export class ListView {
constructor(connection: Connection, type: SObject, id: SalesforceId)
}
export class ListViewsInfo { }
export class QuickAction { }

View File

@@ -0,0 +1,30 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"connection.d.ts",
"create-options.d.ts",
"date-enum.d.ts",
"salesforce-object-options.d.ts",
"salesforce-object.d.ts",
"salesforce-id.d.ts",
"query.d.ts",
"describe-result.d.ts",
"jsforce-tests.ts"
]
}

View File

@@ -0,0 +1,6 @@
{
"extends": "dtslint/dt.json",
"rules": {
"ban-types": false
}
}