Skip to content

Commit 13c7fbd

Browse files
committed
delete runtime mapping, normalizations, revalidations
1 parent 822000f commit 13c7fbd

19 files changed

Lines changed: 71 additions & 229 deletions

File tree

apps/visualizer/src/lib/pglite.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313

1414
import { PGlite } from '@electric-sql/pglite'
1515
import { useEffect, useState, useCallback, useRef } from 'react'
16-
import {
17-
SpecParser,
18-
OPENAPI_RESOURCE_TABLE_ALIASES,
19-
type ParsedResourceTable,
20-
} from '@stripe/sync-source-stripe/browser'
16+
import { SpecParser, type ParsedResourceTable } from '@stripe/sync-source-stripe/browser'
2117

2218
type PGliteInstance = InstanceType<typeof PGlite>
2319
type QueryResult = Awaited<ReturnType<PGliteInstance['query']>>
@@ -154,13 +150,8 @@ function generateSchema(spec: Record<string, unknown>): {
154150
for (const schemaDef of Object.values(schemas)) {
155151
const resourceId = (schemaDef as Record<string, unknown>)['x-resourceId']
156152
if (!resourceId || typeof resourceId !== 'string') continue
157-
const alias = OPENAPI_RESOURCE_TABLE_ALIASES[resourceId]
158-
if (alias) {
159-
allTableNames.add(alias)
160-
} else {
161-
const normalized = resourceId.toLowerCase().replace(/\./g, '_')
162-
allTableNames.add(normalized.endsWith('s') ? normalized : `${normalized}s`)
163-
}
153+
const normalized = resourceId.toLowerCase().replace(/\./g, '_')
154+
allTableNames.add(normalized.endsWith('s') ? normalized : `${normalized}s`)
164155
}
165156

166157
const parser = new SpecParser()

packages/openapi/__tests__/listFnResolver.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('SpecParser.discoverListEndpoints', () => {
2828
supportsStartingAfter: true,
2929
supportsEndingBefore: true,
3030
})
31-
expect(endpoints.get('early_fraud_warning')).toEqual({
32-
tableName: 'early_fraud_warning',
31+
expect(endpoints.get('radar_early_fraud_warning')).toEqual({
32+
tableName: 'radar_early_fraud_warning',
3333
resourceId: 'radar.early_fraud_warning',
3434
apiPath: '/v1/radar/early_fraud_warnings',
3535
supportsCreatedFilter: true,

packages/openapi/__tests__/specParser.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import { minimalStripeOpenApiSpec } from './fixtures/minimalSpec'
44
import type { OpenApiSpec } from '../../types'
55

66
describe('SpecParser', () => {
7-
it('parses aliased resources into deterministic tables and column types', () => {
7+
it('parses resources into deterministic tables and column types', () => {
88
const parser = new SpecParser()
99
const parsed = parser.parse(minimalStripeOpenApiSpec, {
10-
allowedTables: ['checkout_session', 'customer', 'early_fraud_warning'],
10+
allowedTables: ['checkout_session', 'customer', 'radar_early_fraud_warning'],
1111
})
1212

1313
expect(parsed.tables.map((table) => table.tableName)).toEqual([
1414
'checkout_session',
1515
'customer',
16-
'early_fraud_warning',
16+
'radar_early_fraud_warning',
1717
])
1818

1919
const customers = parsed.tables.find((table) => table.tableName === 'customer')
@@ -593,14 +593,14 @@ describe('SpecParser', () => {
593593

594594
const tableNames = parsed.tables.map((t) => t.tableName)
595595
expect(tableNames).toEqual([
596-
'active_entitlement',
597596
'checkout_session',
598597
'customer',
599-
'early_fraud_warning',
600-
'feature',
598+
'entitlements_active_entitlement',
599+
'entitlements_feature',
601600
'plan',
602601
'price',
603602
'product',
603+
'radar_early_fraud_warning',
604604
'subscription_item',
605605
'v2_core_account',
606606
'v2_core_event_destination',
@@ -712,11 +712,11 @@ describe('SpecParser', () => {
712712
expect(tableNames).toContain('customer')
713713
})
714714

715-
it('resolves table name aliases from x-resourceId during discovery', () => {
715+
it('derives table names from x-resourceId via dot-to-underscore', () => {
716716
const parser = new SpecParser()
717717
const parsed = parser.parse(minimalStripeOpenApiSpec)
718718

719-
const earlyFraud = parsed.tables.find((t) => t.tableName === 'early_fraud_warning')
719+
const earlyFraud = parsed.tables.find((t) => t.tableName === 'radar_early_fraud_warning')
720720
expect(earlyFraud).toBeDefined()
721721
expect(earlyFraud?.resourceId).toBe('radar.early_fraud_warning')
722722

@@ -737,7 +737,7 @@ describe('SpecParser.discoverSyncableTables', () => {
737737
expect(tables).toContain('product')
738738
expect(tables).toContain('plan')
739739
expect(tables).toContain('checkout_session')
740-
expect(tables).toContain('early_fraud_warning')
740+
expect(tables).toContain('radar_early_fraud_warning')
741741
})
742742

743743
it('excludes resources that are listable but have no webhook events', () => {

packages/openapi/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Browser-safe entry. Excludes specFetchHelper (which imports node:fs / node:path)
22
// so consumers in webpack/Next.js client bundles can import SpecParser without errors.
33

4-
export { SpecParser, OPENAPI_RESOURCE_TABLE_ALIASES, resolveTableName } from './specParser.js'
4+
export { SpecParser, resolveTableName } from './specParser.js'
55
export type { ListEndpoint, NestedEndpoint } from './specParser.js'
66
export { parsedTableToJsonSchema } from './jsonSchemaConverter.js'
77
export type {

packages/openapi/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type * from './types.js'
2-
export { SpecParser, OPENAPI_RESOURCE_TABLE_ALIASES, resolveTableName } from './specParser.js'
2+
export { SpecParser, resolveTableName } from './specParser.js'
33
export type { ListEndpoint, NestedEndpoint } from './specParser.js'
44

55
export {

packages/openapi/runtimeMappings.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/openapi/specParser.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import type {
77
ParsedOpenApiSpec,
88
ScalarType,
99
} from './types.js'
10-
import { OPENAPI_RESOURCE_TABLE_ALIASES } from './runtimeMappings.js'
1110

1211
const SCHEMA_REF_PREFIX = '#/components/schemas/'
1312
const CRUD_SUFFIXES = ['.created', '.updated', '.deleted'] as const
@@ -22,16 +21,12 @@ const RESERVED_COLUMNS = new Set([
2221
'deleted',
2322
])
2423

25-
export { OPENAPI_RESOURCE_TABLE_ALIASES }
26-
2724
/**
2825
* Resolve a Stripe x-resourceId to a canonical table name.
2926
* Singular, snake_cased, with version namespace dots converted to underscores.
27+
* Optional `aliases` map allows callers to override specific resourceIds.
3028
*/
31-
export function resolveTableName(
32-
resourceId: string,
33-
aliases: Record<string, string> = OPENAPI_RESOURCE_TABLE_ALIASES
34-
): string {
29+
export function resolveTableName(resourceId: string, aliases: Record<string, string> = {}): string {
3530
const alias = aliases[resourceId]
3631
if (alias) return alias
3732
return resourceId.toLowerCase().replace(/[.]/g, '_')
@@ -97,7 +92,7 @@ export class SpecParser {
9792
throw new Error('OpenAPI spec is missing components.schemas')
9893
}
9994

100-
const aliases = { ...OPENAPI_RESOURCE_TABLE_ALIASES, ...(options.resourceAliases ?? {}) }
95+
const aliases = options.resourceAliases ?? {}
10196
const excluded = new Set(options.excludedTables ?? [])
10297
const allowedTables = options.allowedTables
10398
? new Set(options.allowedTables.filter((t) => !excluded.has(t)))
@@ -190,7 +185,7 @@ export class SpecParser {
190185
excluded?: ReadonlySet<string>
191186
} = {}
192187
): ParsedOpenApiSpec {
193-
const aliases = { ...OPENAPI_RESOURCE_TABLE_ALIASES, ...(options.aliases ?? {}) }
188+
const aliases = options.aliases ?? {}
194189
const syncableTables = this.discoverSyncableTables(spec, {
195190
aliases,
196191
excluded: options.excluded,
@@ -212,7 +207,7 @@ export class SpecParser {
212207
excluded?: ReadonlySet<string>
213208
} = {}
214209
): Set<string> {
215-
const aliases = { ...OPENAPI_RESOURCE_TABLE_ALIASES, ...(options.aliases ?? {}) }
210+
const aliases = options.aliases ?? {}
216211
const excluded = options.excluded ?? new Set<string>()
217212
const listableIds = this.discoverListableResourceIds(spec, { includeNested: true })
218213
const webhookIds = this.discoverWebhookUpdatableResourceIds(spec, listableIds)
@@ -232,7 +227,7 @@ export class SpecParser {
232227
*/
233228
discoverListEndpoints(
234229
spec: OpenApiSpec,
235-
aliases: Record<string, string> = OPENAPI_RESOURCE_TABLE_ALIASES
230+
aliases: Record<string, string> = {}
236231
): Map<string, ListEndpoint> {
237232
const endpoints = new Map<string, ListEndpoint>()
238233
for (const raw of this.iterListPaths(spec)) {
@@ -262,7 +257,7 @@ export class SpecParser {
262257
discoverNestedEndpoints(
263258
spec: OpenApiSpec,
264259
topLevelEndpoints: Map<string, ListEndpoint>,
265-
aliases: Record<string, string> = OPENAPI_RESOURCE_TABLE_ALIASES
260+
aliases: Record<string, string> = {}
266261
): NestedEndpoint[] {
267262
const topLevelByPath = new Map<string, ListEndpoint>()
268263
for (const endpoint of topLevelEndpoints.values()) {

packages/source-stripe/.env.sample

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ BACKFILL_RELATED_ENTITIES=true
3838
# Max number of connections for the Postgres connection pool, higher value lead to more concurrent queries, but also more load on the database (connections are expensive)
3939
MAX_POSTGRES_CONNECTIONS=20
4040

41-
# If true, the webhook data is not used and instead the webhook is just a trigger to fetch the entity from Stripe again. This ensures that a race condition with failed webhooks can never accidentally overwrite the data with an older state.
42-
# Default:
43-
REVALIDATE_OBJECTS_VIA_STRIPE_API=payment_intent,invoice,customer,subscription
44-
4541
# optional
4642
# Disable the automated database migrations on app startup
4743
# Default: false

packages/source-stripe/src/__snapshots__/catalog.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ exports[`catalogFromOpenApi stream list > all listable tables (no webhook filter
2020
"credit_note",
2121
"customer",
2222
"dispute",
23-
"early_fraud_warning",
23+
"entitlements_feature",
2424
"event",
25-
"feature",
2625
"file",
2726
"file_link",
2827
"financial_connections_account",
@@ -51,6 +50,7 @@ exports[`catalogFromOpenApi stream list > all listable tables (no webhook filter
5150
"product",
5251
"promotion_code",
5352
"quote",
53+
"radar_early_fraud_warning",
5454
"radar_value_list",
5555
"refund",
5656
"reporting_report_run",
@@ -95,7 +95,6 @@ exports[`catalogFromOpenApi stream list > default: only tables with webhook even
9595
"credit_note",
9696
"customer",
9797
"dispute",
98-
"early_fraud_warning",
9998
"file",
10099
"financial_connections_account",
101100
"identity_verification_session",
@@ -117,6 +116,7 @@ exports[`catalogFromOpenApi stream list > default: only tables with webhook even
117116
"product",
118117
"promotion_code",
119118
"quote",
119+
"radar_early_fraud_warning",
120120
"refund",
121121
"reporting_report_run",
122122
"reporting_report_type",

packages/source-stripe/src/catalog.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect } from 'vitest'
2-
import { SpecParser, OPENAPI_RESOURCE_TABLE_ALIASES } from '@stripe/sync-openapi'
2+
import { SpecParser } from '@stripe/sync-openapi'
33
import { buildResourceRegistry } from './resourceRegistry.js'
44
import { catalogFromOpenApi } from './catalog.js'
55
import { resolveOpenApiSpec, BUNDLED_API_VERSION } from '@stripe/sync-openapi'
@@ -10,9 +10,7 @@ describe('catalogFromOpenApi stream list', () => {
1010

1111
it('default: only tables with webhook events', async () => {
1212
const { spec, apiVersion } = await resolved
13-
const parsed = parser.parse(spec, {
14-
resourceAliases: OPENAPI_RESOURCE_TABLE_ALIASES,
15-
})
13+
const parsed = parser.parse(spec)
1614
const allowedTables = new Set(parsed.tables.map((t) => t.tableName))
1715
const registry = buildResourceRegistry(
1816
spec,
@@ -31,9 +29,7 @@ describe('catalogFromOpenApi stream list', () => {
3129

3230
it('every stream in the catalog has supports_realtime_sync = true', async () => {
3331
const { spec, apiVersion } = await resolved
34-
const parsed = parser.parse(spec, {
35-
resourceAliases: OPENAPI_RESOURCE_TABLE_ALIASES,
36-
})
32+
const parsed = parser.parse(spec)
3733
const allowedTables = new Set(parsed.tables.map((t) => t.tableName))
3834
const registry = buildResourceRegistry(
3935
spec,
@@ -54,7 +50,6 @@ describe('catalogFromOpenApi stream list', () => {
5450
const { spec, apiVersion } = await resolved
5551
const allRegistry = buildResourceRegistry(spec, 'sk_test_fake', apiVersion)
5652
const parsed = parser.parse(spec, {
57-
resourceAliases: OPENAPI_RESOURCE_TABLE_ALIASES,
5853
allowedTables: Object.values(allRegistry).map((r) => r.tableName),
5954
})
6055
const registry = buildResourceRegistry(
@@ -74,9 +69,7 @@ describe('catalogFromOpenApi stream list', () => {
7469

7570
it('every stream has json_schema (no ghost tables)', async () => {
7671
const { spec, apiVersion } = await resolved
77-
const parsed = parser.parse(spec, {
78-
resourceAliases: OPENAPI_RESOURCE_TABLE_ALIASES,
79-
})
72+
const parsed = parser.parse(spec)
8073
const allowedTables = new Set(parsed.tables.map((t) => t.tableName))
8174
const registry = buildResourceRegistry(
8275
spec,

0 commit comments

Comments
 (0)