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

Replace checkId with assertWellFormedId #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 4 additions & 11 deletions src/binders/customers/CustomersBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../communication/TransformingNetw
import type Customer from '../../data/customers/Customer';
import { type CustomerData } from '../../data/customers/Customer';
import type Page from '../../data/page/Page';
import ApiError from '../../errors/ApiError';
import alias from '../../plumbing/alias';
import checkId from '../../plumbing/checkId';
import assertWellFormedId from '../../plumbing/assertWellFormedId';
import renege from '../../plumbing/renege';
import type Callback from '../../types/Callback';
import Binder from '../Binder';
Expand Down Expand Up @@ -42,9 +41,7 @@ export default class CustomersBinder extends Binder<CustomerData, Customer> {
public get(id: string, parameters: GetParameters, callback: Callback<Customer>): void;
public get(id: string, parameters?: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(id, 'customer');
return this.networkClient.get<CustomerData, Customer>(`${pathSegment}/${id}`, parameters);
}

Expand Down Expand Up @@ -86,9 +83,7 @@ export default class CustomersBinder extends Binder<CustomerData, Customer> {
public update(id: string, parameters: UpdateParameters, callback: Callback<Customer>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(id, 'customer');
return this.networkClient.patch<CustomerData, Customer>(`${pathSegment}/${id}`, parameters);
}

Expand All @@ -102,9 +97,7 @@ export default class CustomersBinder extends Binder<CustomerData, Customer> {
public delete(id: string, parameters: DeleteParameters, callback: Callback<true>): void;
public delete(id: string, parameters?: DeleteParameters) {
if (renege(this, this.delete, ...arguments)) return;
if (!checkId(id, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(id, 'customer');
return this.networkClient.delete<CustomerData, true>(`${pathSegment}/${id}`, parameters);
}
}
31 changes: 8 additions & 23 deletions src/binders/customers/mandates/CustomerMandatesBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../../communication/TransformingN
import { type MandateData } from '../../../data/customers/mandates/data';
import type Mandate from '../../../data/customers/mandates/Mandate';
import type Page from '../../../data/page/Page';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -34,9 +33,7 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.post<MandateData, Mandate>(getPathSegments(customerId), data);
}

Expand All @@ -50,13 +47,9 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public get(id: string, parameters: GetParameters, callback: Callback<Mandate>): void;
public get(id: string, parameters: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'mandate')) {
throw new ApiError('The customers_mandate id is invalid');
}
assertWellFormedId(id, 'mandate');
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.get<MandateData, Mandate>(`${getPathSegments(customerId)}/${id}`, query);
}

Expand All @@ -73,9 +66,7 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.page<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

Expand All @@ -89,9 +80,7 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
*/
public iterate(parameters: IterateParameters) {
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.iterate<MandateData, Mandate>(getPathSegments(customerId), 'mandates', query, valuesPerMinute);
}

Expand All @@ -105,13 +94,9 @@ export default class CustomerMandatesBinder extends Binder<MandateData, Mandate>
public revoke(id: string, parameters: RevokeParameters, callback: Callback<true>): void;
public revoke(id: string, parameters: RevokeParameters) {
if (renege(this, this.revoke, ...arguments)) return;
if (!checkId(id, 'mandate')) {
throw new ApiError('The customers_mandate id is invalid');
}
assertWellFormedId(id, 'mandate');
const { customerId, ...context } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.delete<MandateData, true>(`${getPathSegments(customerId)}/${id}`, context);
}
}
15 changes: 4 additions & 11 deletions src/binders/customers/payments/CustomerPaymentsBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../../communication/TransformingN
import type Page from '../../../data/page/Page';
import { type PaymentData } from '../../../data/payments/data';
import type Payment from '../../../data/payments/Payment';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -38,9 +37,7 @@ export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment>
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.post<PaymentData, Payment>(getPathSegments(customerId), data);
}

Expand All @@ -55,9 +52,7 @@ export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment>
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.page<PaymentData, Payment>(getPathSegments(customerId), 'payments', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

Expand All @@ -69,9 +64,7 @@ export default class CustomerPaymentsBinder extends Binder<PaymentData, Payment>
*/
public iterate(parameters: IterateParameters) {
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.iterate<PaymentData, Payment>(getPathSegments(customerId), 'payments', query, valuesPerMinute);
}
}
39 changes: 10 additions & 29 deletions src/binders/customers/subscriptions/CustomerSubscriptionsBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import type TransformingNetworkClient from '../../../communication/TransformingN
import type Page from '../../../data/page/Page';
import { type SubscriptionData } from '../../../data/subscriptions/data';
import type Subscription from '../../../data/subscriptions/Subscription';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -41,9 +40,7 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public create(parameters: CreateParameters) {
if (renege(this, this.create, ...arguments)) return;
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.post<SubscriptionData, Subscription>(getPathSegments(customerId), data);
}

Expand All @@ -57,13 +54,9 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public get(id: string, parameters: GetParameters, callback: Callback<Subscription>): void;
public get(id: string, parameters: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
assertWellFormedId(id, 'subscription');
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.get<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, query);
}

Expand All @@ -78,9 +71,7 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public page(parameters: PageParameters) {
if (renege(this, this.page, ...arguments)) return;
const { customerId, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.page<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query).then(result => this.injectPaginationHelpers(result, this.page, parameters));
}

Expand All @@ -92,9 +83,7 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
*/
public iterate(parameters: IterateParameters) {
const { customerId, valuesPerMinute, ...query } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer id is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.iterate<SubscriptionData, Subscription>(getPathSegments(customerId), 'subscriptions', query, valuesPerMinute);
}

Expand All @@ -110,13 +99,9 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public update(id: string, parameters: UpdateParameters, callback: Callback<Subscription>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
assertWellFormedId(id, 'subscription');
const { customerId, ...data } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.patch<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, data);
}

Expand All @@ -130,13 +115,9 @@ export default class CustomerSubscriptionsBinder extends Binder<SubscriptionData
public cancel(id: string, parameters: CancelParameters, callback: Callback<Subscription>): void;
public cancel(id: string, parameters: CancelParameters) {
if (renege(this, this.cancel, ...arguments)) return;
if (!checkId(id, 'subscription')) {
throw new ApiError('The subscription id is invalid');
}
assertWellFormedId(id, 'subscription');
const { customerId, ...context } = parameters;
if (!checkId(customerId, 'customer')) {
throw new ApiError('The customer is invalid');
}
assertWellFormedId(customerId, 'customer');
return this.networkClient.delete<SubscriptionData, Subscription>(`${getPathSegments(customerId)}/${id}`, context);
}
}
15 changes: 4 additions & 11 deletions src/binders/orders/OrdersBinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import type TransformingNetworkClient from '../../communication/TransformingNetw
import type Page from '../../data/page/Page';
import { type OrderData } from '../../data/orders/data';
import type Order from '../../data/orders/Order';
import ApiError from '../../errors/ApiError';
import checkId from '../../plumbing/checkId';
import assertWellFormedId from '../../plumbing/assertWellFormedId';
import renege from '../../plumbing/renege';
import type Callback from '../../types/Callback';
import Binder from '../Binder';
Expand Down Expand Up @@ -73,9 +72,7 @@ export default class OrdersBinder extends Binder<OrderData, Order> {
public get(id: string, parameters: GetParameters, callback: Callback<Order>): void;
public get(id: string, parameters?: GetParameters) {
if (renege(this, this.get, ...arguments)) return;
if (!checkId(id, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(id, 'order');
return this.networkClient.get<OrderData, Order>(`${pathSegment}/${id}`, parameters);
}

Expand Down Expand Up @@ -120,9 +117,7 @@ export default class OrdersBinder extends Binder<OrderData, Order> {
public update(id: string, parameters: UpdateParameters, callback: Callback<Order>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(id, 'order');
return this.networkClient.patch<OrderData, Order>(`${pathSegment}/${id}`, parameters);
}

Expand All @@ -148,9 +143,7 @@ export default class OrdersBinder extends Binder<OrderData, Order> {
public cancel(id: string, parameters: CancelParameters, callback: Callback<Order>): void;
public cancel(id: string, parameters?: CancelParameters) {
if (renege(this, this.cancel, ...arguments)) return;
if (!checkId(id, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(id, 'order');
return this.networkClient.delete<OrderData, Order>(`${pathSegment}/${id}`, parameters);
}
}
15 changes: 4 additions & 11 deletions src/binders/orders/orderlines/OrderLinesBinder.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import type TransformingNetworkClient from '../../../communication/TransformingNetworkClient';
import { type OrderData } from '../../../data/orders/data';
import type Order from '../../../data/orders/Order';
import ApiError from '../../../errors/ApiError';
import alias from '../../../plumbing/alias';
import checkId from '../../../plumbing/checkId';
import assertWellFormedId from '../../../plumbing/assertWellFormedId';
import renege from '../../../plumbing/renege';
import type Callback from '../../../types/Callback';
import Binder from '../../Binder';
Expand Down Expand Up @@ -39,13 +38,9 @@ export default class OrderLinesBinder extends Binder<OrderData, Order> {
public update(id: string, parameters: UpdateParameters, callback: Callback<Order>): void;
public update(id: string, parameters: UpdateParameters) {
if (renege(this, this.update, ...arguments)) return;
if (!checkId(id, 'orderline')) {
throw new ApiError('The orders_lines id is invalid');
}
assertWellFormedId(id, 'orderline');
const { orderId, ...data } = parameters;
if (!checkId(orderId, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(orderId, 'order');
return this.networkClient.patch<OrderData, Order>(`${getPathSegments(orderId)}/${id}`, data);
}

Expand Down Expand Up @@ -73,9 +68,7 @@ export default class OrderLinesBinder extends Binder<OrderData, Order> {
public cancel(parameters: CancelParameters) {
if (renege(this, this.cancel, ...arguments)) return;
const { orderId, ...data } = parameters;
if (!checkId(orderId, 'order')) {
throw new ApiError('The order id is invalid');
}
assertWellFormedId(orderId, 'order');
return this.networkClient.delete<OrderData, true>(getPathSegments(orderId), data);
}
}
Loading
Loading