Skip to content

Commit

Permalink
[Breaking]: FCT-726 update exports for Reference and ReferenceDraft p…
Browse files Browse the repository at this point in the history
…resets to simplify call syntax (#601)

* fix: update exports for reference and referencedraft to simplify call syntax

* fix: lockfile
  • Loading branch information
tylermorrisford authored Jun 20, 2024
1 parent db45a66 commit 42e42c3
Show file tree
Hide file tree
Showing 80 changed files with 147 additions and 424 deletions.
16 changes: 16 additions & 0 deletions .changeset/chilled-dryers-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@commercetools-test-data/inventory-entry': major
'@commercetools-test-data/business-unit': major
'@commercetools-test-data/quote-request': major
'@commercetools-test-data/staged-quote': major
'@commercetools-test-data/commons': major
'@commercetools-test-data/payment': major
'@commercetools-test-data/quote': major
---

This breaking change updates the export method for Reference and ReferenceDraft presets to simplify the call syntax. Models that use these presets in their generators or transformers are also updated.

Updating this package will require changes in your codebase. To migrate:

- Replace any instance of `Reference.presets.<preset-name>.<preset-name>()` with `Reference.presets.<preset-name>()`
- Replace any instance of `ReferenceDraft.presets.<preset-name>.<preset-name>()` with `ReferenceDraft.presets.<preset-name>()`
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { TAssociateRoleAssignmentDraft } from '../types';

const generator = Generator<TAssociateRoleAssignmentDraft>({
fields: {
associateRole: fake(() =>
ReferenceDraft.presets.associateRoleReference.associateRoleReference()
),
associateRole: fake(() => ReferenceDraft.presets.associateRoleReference()),
inheritance: oneOf(...Object.values(associateRoleInheritanceMode)),
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const generator = Generator<TAssociateDraft>({
associateRoleAssignments: fake(() => [
AssociateRoleAssignmentDraft.random(),
]),
customer: fake(() =>
ReferenceDraft.presets.customerReference.customerReference()
),
customer: fake(() => ReferenceDraft.presets.customerReference()),
},
});

Expand Down
4 changes: 1 addition & 3 deletions models/business-unit/src/associate/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { TAssociateDefault } from './types';
const generator = Generator<TAssociateDefault>({
fields: {
associateRoleAssignments: fake(() => [AssociateRoleAssignment.random()]),
customer: fake(() =>
Reference.presets.customerReference.customerReference()
),
customer: fake(() => Reference.presets.customerReference()),
},
});

Expand Down
11 changes: 5 additions & 6 deletions models/business-unit/src/associate/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ const transformers = {
rest: Transformer<TAssociateDefault, TAssociateRest>('rest', {
buildFields: ['associateRoleAssignments', 'customer'],
replaceFields: ({ fields }) => {
const customer: TReference<'customer'> =
Reference.presets.customerReference
.customerReference()
.id(fields.customer.id)
.build();
const customer: TReference<'customer'> = Reference.presets
.customerReference()
.id(fields.customer.id)
.build();
return {
...fields,
customer,
Expand All @@ -31,7 +30,7 @@ const transformers = {
graphql: Transformer<TAssociateDefault, TAssociateGraphql>('graphql', {
buildFields: ['associateRoleAssignments', 'customer'],
replaceFields: ({ fields }) => {
const customerRef: TReferenceGraphql = Reference.presets.customerReference
const customerRef: TReferenceGraphql = Reference.presets
.customerReference()
.id(fields.customer.id)
.buildGraphql();
Expand Down
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/associate-role/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import associateRoleReference from './associate-role-reference';

const presets = { associateRoleReference };

export default presets;
export { default } from './associate-role-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import attributeGroupReference from './attribute-group-reference';

const presets = { attributeGroupReference };

export default presets;
export { default } from './attribute-group-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/business-unit/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import businessUnitReference from './business-unit-reference';

const presets = { businessUnitReference };

export default presets;
export { default } from './business-unit-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/cart-discount/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import cartDiscountReference from './cart-discount-reference';

const presets = { cartDiscountReference };

export default presets;
export { default } from './cart-discount-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/cart/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import cartReference from './cart-reference';

const presets = { cartReference };

export default presets;
export { default } from './cart-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/category/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import categoryReference from './category-reference';

const presets = { categoryReference };

export default presets;
export { default } from './category-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/channel/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import channelReference from './channel-reference';

const presets = { channelReference };

export default presets;
export { default } from './channel-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/customer-group/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import customerGroupReference from './customer-group-reference';

const presets = { customerGroupReference };

export default presets;
export { default } from './customer-group-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/customer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import customerReference from './customer-reference';

const presets = { customerReference };

export default presets;
export { default } from './customer-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import directDiscountReference from './direct-discount-reference';

const presets = { directDiscountReference };

export default presets;
export { default } from './direct-discount-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/discount-code/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import discountCodeReference from './discount-code-reference';

const presets = { discountCodeReference };

export default presets;
export { default } from './discount-code-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/extension/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import extensionReference from './extension-reference';

const presets = { extensionReference };

export default presets;
export { default } from './extension-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import inventoryEntryReference from './inventory-entry-reference';

const presets = { inventoryEntryReference };

export default presets;
export { default } from './inventory-entry-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import keyValueDocumentReference from './key-value-document-reference';

const presets = { keyValueDocumentReference };

export default presets;
export { default } from './key-value-document-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/order-edit/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import orderEditReference from './order-edit-reference';

const presets = { orderEditReference };

export default presets;
export { default } from './order-edit-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/order/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import orderReference from './order-reference';

const presets = { orderReference };

export default presets;
export { default } from './order-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/payment/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import paymentReference from './payment-reference';

const presets = { paymentReference };

export default presets;
export { default } from './payment-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import productDiscountReference from './product-discount-reference';

const presets = { productDiscountReference };

export default presets;
export { default } from './product-discount-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/product-price/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import productPriceReference from './product-price-reference';

const presets = { productPriceReference };

export default presets;
export { default } from './product-price-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import productSelectionReference from './product-selection-reference';

const presets = { productSelectionReference };

export default presets;
export { default } from './product-selection-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/product-type/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import productTypeReference from './product-type-reference';

const presets = { productTypeReference };

export default presets;
export { default } from './product-type-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/product/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import productReference from './product-reference';

const presets = { productReference };

export default presets;
export { default } from './product-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/quote-request/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import quoteRequestReference from './quote-request-reference';

const presets = { quoteRequestReference };

export default presets;
export { default } from './quote-request-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/quote/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import quoteReference from './quote-reference';

const presets = { quoteReference };

export default presets;
export { default } from './quote-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/review/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import reviewReference from './review-reference';

const presets = { reviewReference };

export default presets;
export { default } from './review-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import shippingMethodReference from './shipping-method-reference';

const presets = { shippingMethodReference };

export default presets;
export { default } from './shipping-method-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/shopping-list/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import shoppingListReference from './shopping-list-reference';

const presets = { shoppingListReference };

export default presets;
export { default } from './shopping-list-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/staged-quote/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import stagedQuoteReference from './staged-quote-reference';

const presets = { stagedQuoteReference };

export default presets;
export { default } from './staged-quote-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import standalonePriceReference from './standalone-price-reference';

const presets = { standalonePriceReference };

export default presets;
export { default } from './standalone-price-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import stateReference from './state-reference';

const presets = { stateReference };

export default presets;
export { default } from './state-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import storeReference from './store-reference';

const presets = { storeReference };

export default presets;
export { default } from './store-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/subscription/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import subscriptionReference from './subscription-reference';

const presets = { subscriptionReference };

export default presets;
export { default } from './subscription-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/tax-category/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import taxCategoryReference from './tax-category-reference';

const presets = { taxCategoryReference };

export default presets;
export { default } from './tax-category-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/type/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import typeReference from './type-reference';

const presets = { typeReference };

export default presets;
export { default } from './type-reference';
6 changes: 1 addition & 5 deletions models/commons/src/reference/presets/zone/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import zoneReference from './zone-reference';

const presets = { zoneReference };

export default presets;
export { default } from './zone-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import associateRoleReference from './associate-role-reference';

const presets = { associateRoleReference };

export default presets;
export { default } from './associate-role-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import attributeGroupReference from './attribute-group-reference';

const presets = { attributeGroupReference };

export default presets;
export { default } from './attribute-group-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import businessUnitReference from './business-unit-reference';

const presets = { businessUnitReference };

export default presets;
export { default } from './business-unit-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import cartDiscountReference from './cart-discount-reference';

const presets = { cartDiscountReference };

export default presets;
export { default } from './cart-discount-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import cartReference from './cart-reference';

const presets = { cartReference };

export default presets;
export { default } from './cart-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import categoryReference from './category-reference';

const presets = { categoryReference };

export default presets;
export { default } from './category-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import channelReference from './channel-reference';

const presets = { channelReference };

export default presets;
export { default } from './channel-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import customerGroupReference from './customer-group-reference';

const presets = { customerGroupReference };

export default presets;
export { default } from './customer-group-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import customerReference from './customer-reference';

const presets = { customerReference };

export default presets;
export { default } from './customer-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import directDiscountReference from './direct-discount-reference';

const presets = { directDiscountReference };

export default presets;
export { default } from './direct-discount-reference';
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
import discountCodeReference from './discount-code-reference';

const presets = { discountCodeReference };

export default presets;
export { default } from './discount-code-reference';
Loading

0 comments on commit 42e42c3

Please sign in to comment.