Skip to content
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
3 changes: 3 additions & 0 deletions .github/workflows/ci-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ jobs:
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
# - run: npx nx-cloud record -- echo Hello World
# When you enable task distribution, run the e2e-ci task instead of e2e
- name: Check generated types are in sync
run: npm run codegen:check

- name: Build affected packages
run: npx nx affected --target=build

Expand Down
12 changes: 12 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Check if postgrest-js common types were modified
if git diff --cached --name-only | grep -q "packages/core/postgrest-js/src/types/common/"; then
echo "📝 Detected changes in postgrest-js common types..."
echo "🔄 Running codegen to sync types..."

npm run codegen

# Add the generated files to the commit
git add packages/core/supabase-js/src/lib/rest/types/common/

echo "✅ Generated types have been updated and staged"
fi
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"scripts": {
"commit": "cz",
"prepare": "husky",
"codegen": "node scripts/sync-common-types.js",
"codegen:check": "node scripts/sync-common-types.js && git diff --exit-code packages/core/supabase-js/src/lib/rest/types/common && echo '\n✅ Generated types are in sync!' || (echo '\n❌ Generated types are out of sync.\n Run: npm run codegen\n Then commit the changes.\n' && exit 1)",
"release-canary": "npx tsx scripts/release-canary.ts",
"release-stable": "npx tsx scripts/release-stable.ts"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/core/auth-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"clean": "rimraf dist docs",
"coverage": "echo \"run npm test\"",
"build:node18": "npm run clean && npm run build:main && npm run build:module",
"build": "npm run clean && npx nx build:main auth-js && npx nx build:module auth-js",
"build": "npm run clean && npm run build:main && npm run build:module",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"test:auth": "npm run test:clean && npm run test:infra && npm run test:suite && npm run test:clean",
Expand Down
1 change: 0 additions & 1 deletion packages/core/postgrest-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"format": "node scripts/format.js",
"format:check": "node scripts/format.js check",
"build": "npm run clean && npm run build:cjs && npm run build:esm",
"postbuild": "cp -rf ./src/types/common ../supabase-js/src/lib/rest/types/common",
"build:cjs": "tsc -p tsconfig.json",
"build:esm": "cpy wrapper.mjs dist/esm/",
"docs": "typedoc src/index.ts --out docs/v2",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/storage-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"scripts": {
"clean": "rimraf dist docs/v2",
"build": "npx nx clean storage-js && npx nx build:main storage-js && npx nx build:module storage-js && npx nx build:umd storage-js",
"build": "npm run clean && npm run build:main && npm run build:module && npm run build:umd",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"build:umd": "webpack",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/supabase-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
},
"scripts": {
"clean": "rimraf dist docs/v2",
"build": "npm run clean && npx nx build:main supabase-js && npx nx build:module supabase-js && npx nx build:umd supabase-js",
"build": "npm run clean && npm run build:main && npm run build:module && npm run build:umd",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",
"build:umd": "webpack --env mode=production",
"test": "npx nx test:types supabase-js && npx nx test:run supabase-js",
"test:all": "npx nx test:types supabase-js && npx nx test:run supabase-js && npx nx test:integration supabase-js && npx nx test:integration:browser supabase-js",
"test": "npm run test:types && npm run test:run",
"test:all": "npm run test:types && npm run test:run && npm run test:integration && npm run test:integration:browser",
"test:run": "jest --runInBand --detectOpenHandles",
"test:unit": "jest --runInBand --detectOpenHandles test/unit",
"test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration|test/deno\"",
Expand All @@ -41,7 +41,7 @@
"test:watch": "jest --watch --verbose false --silent false",
"test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test",
"test:bun": "cd test/integration/bun && bun install && bun test",
"test:types": "npx nx build:module supabase-js && tsd --files test/types/*.test-d.ts && jsr publish --dry-run --allow-dirty",
"test:types": "npm run build:module && tsd --files test/types/*.test-d.ts && jsr publish --dry-run --allow-dirty",
"docs": "typedoc --entryPoints src/index.ts --out docs/v2",
"docs:json": "typedoc --entryPoints src/index.ts --json docs/v2/spec.json --excludeExternals",
"serve:coverage": "npx nx test:coverage supabase-js && serve test/coverage",
Expand Down
10 changes: 10 additions & 0 deletions packages/core/supabase-js/src/lib/rest/types/common/common.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* AUTO-GENERATED FILE - DO NOT EDIT
*
* This file is automatically synchronized from @supabase/postgrest-js
* Source: packages/core/postgrest-js/src/types/common/
*
* To update this file, modify the source in postgrest-js and run:
* npm run codegen
*/

// Types that are shared between supabase-js and postgrest-js

export type Fetch = typeof fetch
Expand Down
10 changes: 10 additions & 0 deletions packages/core/supabase-js/src/lib/rest/types/common/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* AUTO-GENERATED FILE - DO NOT EDIT
*
* This file is automatically synchronized from @supabase/postgrest-js
* Source: packages/core/postgrest-js/src/types/common/
*
* To update this file, modify the source in postgrest-js and run:
* npm run codegen
*/

import type { GenericFunction, GenericSchema, GenericSetofOption } from './common'

// Functions matching utils
Expand Down
97 changes: 97 additions & 0 deletions scripts/sync-common-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/usr/bin/env node

/**
* Sync common type definitions from postgrest-js to supabase-js
*
* This script copies shared type definitions from @supabase/postgrest-js
* to @supabase/supabase-js to ensure type compatibility across complex
* generic types and conditional types.
*
* Source of truth: packages/core/postgrest-js/src/types/common/
* Destination: packages/core/supabase-js/src/lib/rest/types/common/
*/

const fs = require('fs')
const path = require('path')

const SOURCE_DIR = path.join(__dirname, '../packages/core/postgrest-js/src/types/common')
const DEST_DIR = path.join(__dirname, '../packages/core/supabase-js/src/lib/rest/types/common')

const HEADER_COMMENT = `/**
* AUTO-GENERATED FILE - DO NOT EDIT
*
* This file is automatically synchronized from @supabase/postgrest-js
* Source: packages/core/postgrest-js/src/types/common/
*
* To update this file, modify the source in postgrest-js and run:
* npm run codegen
*/

`

function syncFile(fileName) {
const sourcePath = path.join(SOURCE_DIR, fileName)
const destPath = path.join(DEST_DIR, fileName)

if (!fs.existsSync(sourcePath)) {
console.error(`❌ Source file not found: ${sourcePath}`)
process.exit(1)
}

const sourceContent = fs.readFileSync(sourcePath, 'utf8')
const expectedContent = HEADER_COMMENT + sourceContent

// Check if destination exists and compare with what we would generate
let needsUpdate = true
if (fs.existsSync(destPath)) {
const destContent = fs.readFileSync(destPath, 'utf8')

// Compare the full expected output with the current file
if (destContent === expectedContent) {
needsUpdate = false
}
}

if (needsUpdate) {
fs.writeFileSync(destPath, expectedContent, 'utf8')
console.log(`✅ Synced: ${fileName}`)
return true
} else {
console.log(`⏭️ Unchanged: ${fileName}`)
return false
}
}

function main() {
console.log('🔄 Syncing common types from postgrest-js to supabase-js...\n')

// Ensure destination directory exists
if (!fs.existsSync(DEST_DIR)) {
fs.mkdirSync(DEST_DIR, { recursive: true })
console.log(`📁 Created directory: ${DEST_DIR}\n`)
}

// Get all .ts files from source directory
const sourceFiles = fs.readdirSync(SOURCE_DIR).filter((file) => file.endsWith('.ts'))

if (sourceFiles.length === 0) {
console.error(`❌ No TypeScript files found in ${SOURCE_DIR}`)
process.exit(1)
}

let changedCount = 0
for (const file of sourceFiles) {
const changed = syncFile(file)
if (changed) changedCount++
}

console.log(
`\n✨ Sync complete: ${changedCount} file(s) updated, ${sourceFiles.length - changedCount} unchanged`
)

if (changedCount > 0) {
console.log('\n⚠️ Generated files were updated. Please commit these changes.')
}
}

main()