Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit 6c7201d

Browse files
committed
fix(codegen): preserve ios type casing in ts output
1 parent 3ac6b7e commit 6c7201d

File tree

2 files changed

+81
-51
lines changed

2 files changed

+81
-51
lines changed

scripts/fix-generated-types.mjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { readFileSync, writeFileSync } from 'node:fs';
22
import { fileURLToPath } from 'node:url';
33
import { dirname, resolve } from 'node:path';
4+
import { parse } from 'graphql';
45

56
const __filename = fileURLToPath(import.meta.url);
67
const __dirname = dirname(__filename);
@@ -10,6 +11,17 @@ const schemaFiles = [
1011
resolve(__dirname, '../src/api-ios.graphql'),
1112
resolve(__dirname, '../src/api-android.graphql'),
1213
];
14+
const schemaDefinitionFiles = [
15+
'../src/schema.graphql',
16+
'../src/type.graphql',
17+
'../src/type-ios.graphql',
18+
'../src/type-android.graphql',
19+
'../src/api.graphql',
20+
'../src/api-ios.graphql',
21+
'../src/api-android.graphql',
22+
'../src/error.graphql',
23+
'../src/event.graphql',
24+
].map((relativePath) => resolve(__dirname, relativePath));
1325

1426
let content = readFileSync(targetPath, 'utf8');
1527

@@ -34,6 +46,24 @@ for (const [from, to] of scalarReplacements) {
3446
content = content.replace(pattern, to);
3547
}
3648

49+
const iosTypeMap = new Map();
50+
for (const schemaPath of schemaDefinitionFiles) {
51+
const sdl = readFileSync(schemaPath, 'utf8');
52+
const document = parse(sdl, { noLocation: true });
53+
for (const definition of document.definitions) {
54+
if (!definition.name) continue;
55+
const name = definition.name.value;
56+
if (!name.includes('IOS')) continue;
57+
const tsName = name.replace(/IOS/g, 'Ios');
58+
iosTypeMap.set(tsName, name);
59+
}
60+
}
61+
62+
for (const [tsName, iosName] of iosTypeMap) {
63+
const pattern = new RegExp(`\\b${tsName}\\b`, 'g');
64+
content = content.replace(pattern, iosName);
65+
}
66+
3767
const removeDefinition = (keyword) => {
3868
const pattern = new RegExp(`^export type ${keyword}[^]*?;\n`, 'm');
3969
if (pattern.test(content)) {

src/generated/types.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ export interface DeepLinkOptions {
4646
skuAndroid?: (string | null);
4747
}
4848

49-
export interface DiscountIos {
49+
export interface DiscountIOS {
5050
identifier: string;
5151
localizedPrice?: (string | null);
5252
numberOfPeriods: number;
53-
paymentMode: PaymentModeIos;
53+
paymentMode: PaymentModeIOS;
5454
price: string;
5555
priceAmount: number;
5656
subscriptionPeriod: string;
5757
type: string;
5858
}
5959

60-
export interface DiscountOfferIos {
60+
export interface DiscountOfferIOS {
6161
/** Discount identifier */
6262
identifier: string;
6363
/** Key identifier for validation */
@@ -70,7 +70,7 @@ export interface DiscountOfferIos {
7070
timestamp: number;
7171
}
7272

73-
export interface DiscountOfferInputIos {
73+
export interface DiscountOfferInputIOS {
7474
/** Discount identifier */
7575
identifier: string;
7676
/** Key identifier for validation */
@@ -83,7 +83,7 @@ export interface DiscountOfferInputIos {
8383
timestamp: number;
8484
}
8585

86-
export interface EntitlementIos {
86+
export interface EntitlementIOS {
8787
jsonRepresentation: string;
8888
sku: string;
8989
transactionId: string;
@@ -141,7 +141,7 @@ export interface Mutation {
141141
/** Acknowledge a non-consumable purchase or subscription */
142142
acknowledgePurchaseAndroid: Promise<VoidResult>;
143143
/** Initiate a refund request for a product (iOS 15+) */
144-
beginRefundRequestIOS: Promise<RefundResultIos>;
144+
beginRefundRequestIOS: Promise<RefundResultIOS>;
145145
/** Clear pending transactions from the StoreKit payment queue */
146146
clearTransactionIOS: Promise<VoidResult>;
147147
/** Consume a purchase token so it can be repurchased */
@@ -159,11 +159,11 @@ export interface Mutation {
159159
/** Initiate a purchase flow; rely on events for final state */
160160
requestPurchase?: Promise<(RequestPurchaseResult | null)>;
161161
/** Purchase the promoted product surfaced by the App Store */
162-
requestPurchaseOnPromotedProductIOS: Promise<PurchaseIos>;
162+
requestPurchaseOnPromotedProductIOS: Promise<PurchaseIOS>;
163163
/** Restore completed purchases across platforms */
164164
restorePurchases: Promise<VoidResult>;
165165
/** Open subscription management UI and return changed purchases (iOS 15+) */
166-
showManageSubscriptionsIOS: Promise<PurchaseIos[]>;
166+
showManageSubscriptionsIOS: Promise<PurchaseIOS[]>;
167167
/** Force a StoreKit sync for transactions (iOS 15+) */
168168
syncIOS: Promise<VoidResult>;
169169
/** Validate purchase receipts with the configured providers */
@@ -206,7 +206,7 @@ export interface MutationValidateReceiptArgs {
206206
options: ReceiptValidationProps;
207207
}
208208

209-
export enum PaymentModeIos {
209+
export enum PaymentModeIOS {
210210
Empty = 'EMPTY',
211211
FreeTrial = 'FREE_TRIAL',
212212
PayAsYouGo = 'PAY_AS_YOU_GO',
@@ -231,7 +231,7 @@ export interface PricingPhasesAndroid {
231231
pricingPhaseList: PricingPhaseAndroid[];
232232
}
233233

234-
export type Product = ProductAndroid | ProductIos;
234+
export type Product = ProductAndroid | ProductIOS;
235235

236236
export interface ProductAndroid extends ProductCommon {
237237
currency: string;
@@ -268,7 +268,7 @@ export interface ProductCommon {
268268
type: ProductType;
269269
}
270270

271-
export interface ProductIos extends ProductCommon {
271+
export interface ProductIOS extends ProductCommon {
272272
currency: string;
273273
debugDescription?: (string | null);
274274
description: string;
@@ -280,10 +280,10 @@ export interface ProductIos extends ProductCommon {
280280
jsonRepresentationIOS: string;
281281
platform: Platform;
282282
price?: (number | null);
283-
subscriptionInfoIOS?: (SubscriptionInfoIos | null);
283+
subscriptionInfoIOS?: (SubscriptionInfoIOS | null);
284284
title: string;
285285
type: ProductType;
286-
typeIOS: ProductTypeIos;
286+
typeIOS: ProductTypeIOS;
287287
}
288288

289289
export enum ProductQueryType {
@@ -297,7 +297,7 @@ export interface ProductRequest {
297297
type?: (ProductQueryType | null);
298298
}
299299

300-
export type ProductSubscription = ProductSubscriptionAndroid | ProductSubscriptionIos;
300+
export type ProductSubscription = ProductSubscriptionAndroid | ProductSubscriptionIOS;
301301

302302
export interface ProductSubscriptionAndroid extends ProductCommon {
303303
currency: string;
@@ -323,45 +323,45 @@ export interface ProductSubscriptionAndroidOfferDetails {
323323
pricingPhases: PricingPhasesAndroid;
324324
}
325325

326-
export interface ProductSubscriptionIos extends ProductCommon {
326+
export interface ProductSubscriptionIOS extends ProductCommon {
327327
currency: string;
328328
debugDescription?: (string | null);
329329
description: string;
330-
discountsIOS?: (DiscountIos[] | null);
330+
discountsIOS?: (DiscountIOS[] | null);
331331
displayName?: (string | null);
332332
displayNameIOS: string;
333333
displayPrice: string;
334334
id: string;
335335
introductoryPriceAsAmountIOS?: (string | null);
336336
introductoryPriceIOS?: (string | null);
337337
introductoryPriceNumberOfPeriodsIOS?: (string | null);
338-
introductoryPricePaymentModeIOS?: (PaymentModeIos | null);
339-
introductoryPriceSubscriptionPeriodIOS?: (SubscriptionPeriodIos | null);
338+
introductoryPricePaymentModeIOS?: (PaymentModeIOS | null);
339+
introductoryPriceSubscriptionPeriodIOS?: (SubscriptionPeriodIOS | null);
340340
isFamilyShareableIOS: boolean;
341341
jsonRepresentationIOS: string;
342342
platform: Platform;
343343
price?: (number | null);
344-
subscriptionInfoIOS?: (SubscriptionInfoIos | null);
344+
subscriptionInfoIOS?: (SubscriptionInfoIOS | null);
345345
subscriptionPeriodNumberIOS?: (string | null);
346-
subscriptionPeriodUnitIOS?: (SubscriptionPeriodIos | null);
346+
subscriptionPeriodUnitIOS?: (SubscriptionPeriodIOS | null);
347347
title: string;
348348
type: ProductType;
349-
typeIOS: ProductTypeIos;
349+
typeIOS: ProductTypeIOS;
350350
}
351351

352352
export enum ProductType {
353353
InApp = 'IN_APP',
354354
Subs = 'SUBS'
355355
}
356356

357-
export enum ProductTypeIos {
357+
export enum ProductTypeIOS {
358358
AutoRenewableSubscription = 'AUTO_RENEWABLE_SUBSCRIPTION',
359359
Consumable = 'CONSUMABLE',
360360
NonConsumable = 'NON_CONSUMABLE',
361361
NonRenewingSubscription = 'NON_RENEWING_SUBSCRIPTION'
362362
}
363363

364-
export type Purchase = PurchaseAndroid | PurchaseIos;
364+
export type Purchase = PurchaseAndroid | PurchaseIOS;
365365

366366
export interface PurchaseAndroid extends PurchaseCommon {
367367
autoRenewingAndroid?: (boolean | null);
@@ -402,7 +402,7 @@ export interface PurchaseError {
402402
productId?: (string | null);
403403
}
404404

405-
export interface PurchaseIos extends PurchaseCommon {
405+
export interface PurchaseIOS extends PurchaseCommon {
406406
appAccountToken?: (string | null);
407407
appBundleIdIOS?: (string | null);
408408
countryCodeIOS?: (string | null);
@@ -414,7 +414,7 @@ export interface PurchaseIos extends PurchaseCommon {
414414
ids?: (string[] | null);
415415
isAutoRenewing: boolean;
416416
isUpgradedIOS?: (boolean | null);
417-
offerIOS?: (PurchaseOfferIos | null);
417+
offerIOS?: (PurchaseOfferIOS | null);
418418
originalTransactionDateIOS?: (number | null);
419419
originalTransactionIdentifierIOS?: (string | null);
420420
ownershipTypeIOS?: (string | null);
@@ -447,7 +447,7 @@ export interface PurchaseInput {
447447
transactionDate: number;
448448
}
449449

450-
export interface PurchaseOfferIos {
450+
export interface PurchaseOfferIOS {
451451
id: string;
452452
paymentMode: string;
453453
type: string;
@@ -480,7 +480,7 @@ export enum PurchaseState {
480480

481481
export interface Query {
482482
/** Get current StoreKit 2 entitlements (iOS 15+) */
483-
currentEntitlementIOS: Promise<EntitlementIos[]>;
483+
currentEntitlementIOS: Promise<EntitlementIOS[]>;
484484
/** Retrieve products or subscriptions from the store */
485485
fetchProducts: Promise<FetchProductsResult>;
486486
/** Get active subscriptions (filters by subscriptionIds when provided) */
@@ -490,9 +490,9 @@ export interface Query {
490490
/** Get all available purchases for the current user */
491491
getAvailablePurchases: Promise<Purchase[]>;
492492
/** Retrieve all pending transactions in the StoreKit queue */
493-
getPendingTransactionsIOS: Promise<PurchaseIos[]>;
493+
getPendingTransactionsIOS: Promise<PurchaseIOS[]>;
494494
/** Get the currently promoted product (iOS 11+) */
495-
getPromotedProductIOS?: Promise<(ProductIos | null)>;
495+
getPromotedProductIOS?: Promise<(ProductIOS | null)>;
496496
/** Get base64-encoded receipt data for validation */
497497
getReceiptDataIOS: Promise<string>;
498498
/** Get the current App Store storefront country code */
@@ -506,9 +506,9 @@ export interface Query {
506506
/** Verify a StoreKit 2 transaction signature */
507507
isTransactionVerifiedIOS: Promise<boolean>;
508508
/** Get the latest transaction for a product using StoreKit 2 */
509-
latestTransactionIOS?: Promise<(PurchaseIos | null)>;
509+
latestTransactionIOS?: Promise<(PurchaseIOS | null)>;
510510
/** Get StoreKit 2 subscription status details (iOS 15+) */
511-
subscriptionStatusIOS: Promise<SubscriptionStatusIos[]>;
511+
subscriptionStatusIOS: Promise<SubscriptionStatusIOS[]>;
512512
}
513513

514514

@@ -575,7 +575,7 @@ export interface ReceiptValidationProps {
575575
sku: string;
576576
}
577577

578-
export type ReceiptValidationResult = ReceiptValidationResultAndroid | ReceiptValidationResultIos;
578+
export type ReceiptValidationResult = ReceiptValidationResultAndroid | ReceiptValidationResultIOS;
579579

580580
export interface ReceiptValidationResultAndroid {
581581
autoRenewing: boolean;
@@ -598,7 +598,7 @@ export interface ReceiptValidationResultAndroid {
598598
testTransaction: boolean;
599599
}
600600

601-
export interface ReceiptValidationResultIos {
601+
export interface ReceiptValidationResultIOS {
602602
/** Whether the receipt is valid */
603603
isValid: boolean;
604604
/** JWS representation */
@@ -609,12 +609,12 @@ export interface ReceiptValidationResultIos {
609609
receiptData: string;
610610
}
611611

612-
export interface RefundResultIos {
612+
export interface RefundResultIOS {
613613
message?: (string | null);
614614
status: string;
615615
}
616616

617-
export interface RenewalInfoIos {
617+
export interface RenewalInfoIOS {
618618
autoRenewPreference?: (string | null);
619619
jsonRepresentation?: (string | null);
620620
willAutoRenew: boolean;
@@ -641,7 +641,7 @@ export interface RequestPurchaseIosProps {
641641
/** Product SKU */
642642
sku: string;
643643
/** Discount offer to apply */
644-
withOffer?: (DiscountOfferInputIos | null);
644+
withOffer?: (DiscountOfferInputIOS | null);
645645
}
646646

647647
export interface RequestPurchaseProps {
@@ -685,7 +685,7 @@ export interface RequestSubscriptionIosProps {
685685
appAccountToken?: (string | null);
686686
quantity?: (number | null);
687687
sku: string;
688-
withOffer?: (DiscountOfferInputIos | null);
688+
withOffer?: (DiscountOfferInputIOS | null);
689689
}
690690

691691
export interface RequestSubscriptionPropsByPlatforms {
@@ -704,43 +704,43 @@ export interface Subscription {
704704
purchaseUpdated: Purchase;
705705
}
706706

707-
export interface SubscriptionInfoIos {
708-
introductoryOffer?: (SubscriptionOfferIos | null);
709-
promotionalOffers?: (SubscriptionOfferIos[] | null);
707+
export interface SubscriptionInfoIOS {
708+
introductoryOffer?: (SubscriptionOfferIOS | null);
709+
promotionalOffers?: (SubscriptionOfferIOS[] | null);
710710
subscriptionGroupId: string;
711-
subscriptionPeriod: SubscriptionPeriodValueIos;
711+
subscriptionPeriod: SubscriptionPeriodValueIOS;
712712
}
713713

714-
export interface SubscriptionOfferIos {
714+
export interface SubscriptionOfferIOS {
715715
displayPrice: string;
716716
id: string;
717-
paymentMode: PaymentModeIos;
718-
period: SubscriptionPeriodValueIos;
717+
paymentMode: PaymentModeIOS;
718+
period: SubscriptionPeriodValueIOS;
719719
periodCount: number;
720720
price: number;
721-
type: SubscriptionOfferTypeIos;
721+
type: SubscriptionOfferTypeIOS;
722722
}
723723

724-
export enum SubscriptionOfferTypeIos {
724+
export enum SubscriptionOfferTypeIOS {
725725
Introductory = 'INTRODUCTORY',
726726
Promotional = 'PROMOTIONAL'
727727
}
728728

729-
export enum SubscriptionPeriodIos {
729+
export enum SubscriptionPeriodIOS {
730730
Day = 'DAY',
731731
Empty = 'EMPTY',
732732
Month = 'MONTH',
733733
Week = 'WEEK',
734734
Year = 'YEAR'
735735
}
736736

737-
export interface SubscriptionPeriodValueIos {
738-
unit: SubscriptionPeriodIos;
737+
export interface SubscriptionPeriodValueIOS {
738+
unit: SubscriptionPeriodIOS;
739739
value: number;
740740
}
741741

742-
export interface SubscriptionStatusIos {
743-
renewalInfo?: (RenewalInfoIos | null);
742+
export interface SubscriptionStatusIOS {
743+
renewalInfo?: (RenewalInfoIOS | null);
744744
state: string;
745745
}
746746

0 commit comments

Comments
 (0)