Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add block passing in serialize-list method implementations #516

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/node/spec/integration/apiIntegration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe("Integration tests", () => {
.calls.feedbackCallSummary("CR12345678123456781234567812345678")
.update(params);
expect(result.testArrayOfObjects[0].description).toEqual(
"issue description"
"issue description",
);
expect(result.testArrayOfObjects[0].count).toEqual(4);
});
Expand Down
2 changes: 1 addition & 1 deletion examples/node/spec/unit/account.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe("account", () => {
.page(params)
.then((accountPage) => {
expect(accountPage.getNextPageUrl()).toEqual(
"http://api.twilio.com/2010-04-01/Accounts.json?FriendlyName=friendly_name&Status=active&PageSize=50&Page=50"
"http://api.twilio.com/2010-04-01/Accounts.json?FriendlyName=friendly_name&Status=active&PageSize=50&Page=50",
);
expect(accountPage.instances[0].testObject.mms).toEqual(true);
expect(accountPage.instances[0].testObject.sms).toEqual(false);
Expand Down
81 changes: 42 additions & 39 deletions examples/node/src/rest/api/v2010/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface AccountContext {
* @returns Resolves to processed boolean
*/
remove(
callback?: (error: Error | null, item?: boolean) => any
callback?: (error: Error | null, item?: boolean) => any,
): Promise<boolean>;

/**
Expand All @@ -141,7 +141,7 @@ export interface AccountContext {
* @returns Resolves to processed AccountInstance
*/
fetch(
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance>;

/**
Expand All @@ -154,7 +154,7 @@ export interface AccountContext {
*/
update(
params: AccountContextUpdateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance>;

/**
Expand All @@ -174,7 +174,10 @@ export class AccountContextImpl implements AccountContext {

protected _calls?: CallListInstance;

constructor(protected _version: V2010, sid: string) {
constructor(
protected _version: V2010,
sid: string,
) {
if (!isValidPathParam(sid)) {
throw new Error("Parameter 'sid' is not valid.");
}
Expand All @@ -190,7 +193,7 @@ export class AccountContextImpl implements AccountContext {
}

remove(
callback?: (error: Error | null, item?: boolean) => any
callback?: (error: Error | null, item?: boolean) => any,
): Promise<boolean> {
const instance = this;
let operationVersion = instance._version,
Expand All @@ -201,13 +204,13 @@ export class AccountContextImpl implements AccountContext {

operationPromise = instance._version.setPromiseCallback(
operationPromise,
callback
callback,
);
return operationPromise;
}

fetch(
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance> {
const instance = this;
let operationVersion = instance._version,
Expand All @@ -218,19 +221,19 @@ export class AccountContextImpl implements AccountContext {

operationPromise = operationPromise.then(
(payload) =>
new AccountInstance(operationVersion, payload, instance._solution.sid)
new AccountInstance(operationVersion, payload, instance._solution.sid),
);

operationPromise = instance._version.setPromiseCallback(
operationPromise,
callback
callback,
);
return operationPromise;
}

update(
params: AccountContextUpdateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance> {
if (params === null || params === undefined) {
throw new Error('Required parameter "params" missing.');
Expand Down Expand Up @@ -261,12 +264,12 @@ export class AccountContextImpl implements AccountContext {

operationPromise = operationPromise.then(
(payload) =>
new AccountInstance(operationVersion, payload, instance._solution.sid)
new AccountInstance(operationVersion, payload, instance._solution.sid),
);

operationPromise = instance._version.setPromiseCallback(
operationPromise,
callback
callback,
);
return operationPromise;
}
Expand Down Expand Up @@ -316,7 +319,7 @@ export class AccountInstance {
constructor(
protected _version: V2010,
payload: AccountResource,
sid?: string
sid?: string,
) {
this.accountSid = payload.account_sid;
this.sid = payload.sid;
Expand Down Expand Up @@ -378,7 +381,7 @@ export class AccountInstance {
* @returns Resolves to processed boolean
*/
remove(
callback?: (error: Error | null, item?: boolean) => any
callback?: (error: Error | null, item?: boolean) => any,
): Promise<boolean> {
return this._proxy.remove(callback);
}
Expand All @@ -391,7 +394,7 @@ export class AccountInstance {
* @returns Resolves to processed AccountInstance
*/
fetch(
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance> {
return this._proxy.fetch(callback);
}
Expand All @@ -406,12 +409,12 @@ export class AccountInstance {
*/
update(
params: AccountContextUpdateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance>;

update(
params?: any,
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance> {
return this._proxy.update(params, callback);
}
Expand Down Expand Up @@ -473,7 +476,7 @@ export interface AccountListInstance {
* @returns Resolves to processed AccountInstance
*/
create(
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance>;
/**
* Create a AccountInstance
Expand All @@ -485,7 +488,7 @@ export interface AccountListInstance {
*/
create(
params: AccountListInstanceCreateOptions,
callback?: (error: Error | null, item?: AccountInstance) => any
callback?: (error: Error | null, item?: AccountInstance) => any,
): Promise<AccountInstance>;

/**
Expand All @@ -504,11 +507,11 @@ export interface AccountListInstance {
* @param { function } [callback] - Function to process each record
*/
each(
callback?: (item: AccountInstance, done: (err?: Error) => void) => void
callback?: (item: AccountInstance, done: (err?: Error) => void) => void,
): void;
each(
params: AccountListInstanceEachOptions,
callback?: (item: AccountInstance, done: (err?: Error) => void) => void
callback?: (item: AccountInstance, done: (err?: Error) => void) => void,
): void;
/**
* Retrieve a single target page of AccountInstance records from the API.
Expand All @@ -520,7 +523,7 @@ export interface AccountListInstance {
*/
getPage(
targetUrl: string,
callback?: (error: Error | null, items: AccountPage) => any
callback?: (error: Error | null, items: AccountPage) => any,
): Promise<AccountPage>;
/**
* Lists AccountInstance records from the API as a list.
Expand All @@ -532,11 +535,11 @@ export interface AccountListInstance {
* @param { function } [callback] - Callback to handle list of records
*/
list(
callback?: (error: Error | null, items: AccountInstance[]) => any
callback?: (error: Error | null, items: AccountInstance[]) => any,
): Promise<AccountInstance[]>;
list(
params: AccountListInstanceOptions,
callback?: (error: Error | null, items: AccountInstance[]) => any
callback?: (error: Error | null, items: AccountInstance[]) => any,
): Promise<AccountInstance[]>;
/**
* Retrieve a single page of AccountInstance records from the API.
Expand All @@ -550,11 +553,11 @@ export interface AccountListInstance {
* @param { function } [callback] - Callback to handle list of records
*/
page(
callback?: (error: Error | null, items: AccountPage) => any
callback?: (error: Error | null, items: AccountPage) => any,
): Promise<AccountPage>;
page(
params: AccountListInstancePageOptions,
callback?: (error: Error | null, items: AccountPage) => any
callback?: (error: Error | null, items: AccountPage) => any,
): Promise<AccountPage>;

/**
Expand All @@ -579,7 +582,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {
params?:
| AccountListInstanceCreateOptions
| ((error: Error | null, items: AccountInstance) => any),
callback?: (error: Error | null, items: AccountInstance) => any
callback?: (error: Error | null, items: AccountInstance) => any,
): Promise<AccountInstance> {
if (params instanceof Function) {
callback = params;
Expand All @@ -595,7 +598,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {
if (params["recordingStatusCallbackEvent"] !== undefined)
data["RecordingStatusCallbackEvent"] = serialize.map(
params["recordingStatusCallbackEvent"],
(e: string) => e
(e: string) => e,
);
if (params["twiml"] !== undefined)
data["Twiml"] = serialize.twiml(params["twiml"]);
Expand All @@ -614,12 +617,12 @@ export function AccountListInstance(version: V2010): AccountListInstance {
});

operationPromise = operationPromise.then(
(payload) => new AccountInstance(operationVersion, payload)
(payload) => new AccountInstance(operationVersion, payload),
);

operationPromise = instance._version.setPromiseCallback(
operationPromise,
callback
callback,
);
return operationPromise;
};
Expand All @@ -628,7 +631,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {
params?:
| AccountListInstancePageOptions
| ((error: Error | null, items: AccountPage) => any),
callback?: (error: Error | null, items: AccountPage) => any
callback?: (error: Error | null, items: AccountPage) => any,
): Promise<AccountPage> {
if (params instanceof Function) {
callback = params;
Expand All @@ -645,11 +648,11 @@ export function AccountListInstance(version: V2010): AccountListInstance {
data["Date.Test"] = serialize.iso8601Date(params["date.test"]);
if (params["dateCreatedBefore"] !== undefined)
data["DateCreated<"] = serialize.iso8601DateTime(
params["dateCreatedBefore"]
params["dateCreatedBefore"],
);
if (params["dateCreatedAfter"] !== undefined)
data["DateCreated>"] = serialize.iso8601DateTime(
params["dateCreatedAfter"]
params["dateCreatedAfter"],
);
if (params["pageSize"] !== undefined) data["PageSize"] = params["pageSize"];

Expand All @@ -668,12 +671,12 @@ export function AccountListInstance(version: V2010): AccountListInstance {

operationPromise = operationPromise.then(
(payload) =>
new AccountPage(operationVersion, payload, instance._solution)
new AccountPage(operationVersion, payload, instance._solution),
);

operationPromise = instance._version.setPromiseCallback(
operationPromise,
callback
callback,
);
return operationPromise;
};
Expand All @@ -682,7 +685,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {

instance.getPage = function getPage(
targetUrl: string,
callback?: (error: Error | null, items: AccountPage) => any
callback?: (error: Error | null, items: AccountPage) => any,
): Promise<AccountPage> {
const operationPromise = instance._version._domain.twilio.request({
method: "get",
Expand All @@ -691,7 +694,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {

let pagePromise = operationPromise.then(
(payload) =>
new AccountPage(instance._version, payload, instance._solution)
new AccountPage(instance._version, payload, instance._solution),
);
pagePromise = instance._version.setPromiseCallback(pagePromise, callback);
return pagePromise;
Expand All @@ -703,7 +706,7 @@ export function AccountListInstance(version: V2010): AccountListInstance {

instance[inspect.custom] = function inspectImpl(
_depth: any,
options: InspectOptions
options: InspectOptions,
) {
return inspect(instance.toJSON(), options);
};
Expand All @@ -727,7 +730,7 @@ export class AccountPage extends Page<
constructor(
version: V2010,
response: Response<string>,
solution: AccountSolution
solution: AccountSolution,
) {
super(version, response, solution);
}
Expand Down
Loading