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

Commit 5ba4cbf

Browse files
authored
Merge branch 'master' into refactor/introduce-tstyche-for-types-testing
2 parents fc1716a + 4697e8e commit 5ba4cbf

File tree

5 files changed

+187
-28
lines changed

5 files changed

+187
-28
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: Preview release
2+
3+
permissions:
4+
pull-requests: write
5+
6+
on:
7+
# Manual trigger with inputs for control
8+
workflow_dispatch:
9+
inputs:
10+
trigger_supabase_js:
11+
description: 'Trigger supabase-js tests'
12+
type: boolean
13+
default: true
14+
target_branch:
15+
description: 'Target branch for supabase-js tests'
16+
type: string
17+
default: 'master'
18+
19+
# Push to master - only when source code changes
20+
push:
21+
branches:
22+
- master
23+
paths:
24+
- 'src/**'
25+
- 'package.json'
26+
- 'package-lock.json'
27+
- 'tsconfig.json'
28+
29+
# PR triggers - only when labeled
30+
# Using pull_request_target to access secrets when PRs come from forks
31+
pull_request_target:
32+
types: [labeled, synchronize]
33+
34+
jobs:
35+
preview:
36+
# Run only for PRs with 'trigger: preview' label or pushes to master
37+
if: >
38+
github.repository == 'supabase/postgrest-js' &&
39+
(
40+
github.event_name == 'workflow_dispatch' ||
41+
github.event_name == 'push' ||
42+
(github.event_name == 'pull_request_target' && contains(github.event.pull_request.labels.*.name, 'trigger: preview'))
43+
)
44+
runs-on: ubuntu-latest
45+
outputs:
46+
preview-url: ${{ steps.preview.outputs.url }}
47+
package-name: ${{ steps.preview.outputs.package }}
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
with:
52+
# For pull_request_target, we need to explicitly checkout the PR's head
53+
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
54+
55+
- name: Setup Node.js
56+
uses: actions/setup-node@v4
57+
with:
58+
node-version: '20'
59+
cache: 'npm'
60+
61+
- name: Install dependencies
62+
run: npm ci
63+
64+
- name: Build
65+
run: npm run build
66+
67+
- name: Publish preview
68+
id: preview
69+
run: |
70+
OUTPUT=$(npx pkg-pr-new@latest publish --compact 2>&1)
71+
PREVIEW_URL=$(echo "$OUTPUT" | grep -o 'https://pkg\.pr\.new/@supabase/[^[:space:]]*' | head -1)
72+
REPO_NAME=$(echo "$GITHUB_REPOSITORY" | cut -d'/' -f2)
73+
74+
if [ -z "$PREVIEW_URL" ]; then
75+
echo "Error: Failed to extract preview URL from pkg-pr-new output"
76+
echo "Output was: $OUTPUT"
77+
exit 1
78+
fi
79+
80+
echo "Preview Release URL: $PREVIEW_URL"
81+
echo "url=$PREVIEW_URL" >> $GITHUB_OUTPUT
82+
echo "package=$REPO_NAME" >> $GITHUB_OUTPUT
83+
84+
trigger-supabase-js-tests:
85+
needs: preview
86+
# Only run if preview URL exists and either:
87+
# - Not workflow_dispatch, OR
88+
# - workflow_dispatch with trigger_supabase_js = true
89+
if: >
90+
needs.preview.outputs.preview-url != '' &&
91+
(
92+
github.event_name != 'workflow_dispatch' ||
93+
github.event.inputs.trigger_supabase_js == 'true'
94+
)
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Generate GitHub App token
98+
id: generate-token
99+
uses: actions/create-github-app-token@v1
100+
with:
101+
app-id: ${{ vars.CROSS_REPO_APP_ID }}
102+
private-key: ${{ secrets.CROSS_REPO_APP_PRIVATE_KEY }}
103+
owner: supabase
104+
repositories: postgrest-js,supabase-js
105+
106+
- name: Trigger supabase-js CI tests
107+
uses: actions/github-script@v7
108+
with:
109+
github-token: ${{ steps.generate-token.outputs.token }}
110+
script: |
111+
const prNumber = context.issue.number || 'push';
112+
const triggeringRepo = context.repo.repo;
113+
// Use input target_branch if workflow_dispatch, otherwise default to master
114+
const targetBranch = context.eventName === 'workflow_dispatch' && context.payload.inputs?.target_branch
115+
? context.payload.inputs.target_branch
116+
: 'master';
117+
118+
try {
119+
const response = await github.rest.actions.createWorkflowDispatch({
120+
owner: 'supabase',
121+
repo: 'supabase-js',
122+
workflow_id: 'external-test.yml',
123+
ref: targetBranch,
124+
inputs: {
125+
triggering_repo: triggeringRepo,
126+
triggering_pr: prNumber.toString(),
127+
preview_url: '${{ needs.preview.outputs.preview-url }}',
128+
package_name: '${{ needs.preview.outputs.package-name }}',
129+
triggering_sha: context.eventName === 'pull_request_target' ? context.payload.pull_request.head.sha : context.sha
130+
}
131+
});
132+
133+
console.log('Successfully triggered supabase-js tests');
134+
console.log('Response:', response.status);
135+
} catch (error) {
136+
console.error('Failed to trigger supabase-js tests:', error);
137+
throw error;
138+
}
139+
140+
- name: Find existing preview comment
141+
if: github.event_name == 'pull_request_target'
142+
uses: peter-evans/find-comment@v3
143+
id: find-comment
144+
with:
145+
token: ${{ secrets.GITHUB_TOKEN }}
146+
issue-number: ${{ github.event.pull_request.number }}
147+
comment-author: 'github-actions[bot]'
148+
body-includes: '<!-- postgrest-js-preview-status -->'
149+
150+
- name: Create or update preview comment
151+
if: github.event_name == 'pull_request_target'
152+
uses: peter-evans/create-or-update-comment@v4
153+
with:
154+
token: ${{ secrets.GITHUB_TOKEN }}
155+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
156+
issue-number: ${{ github.event.pull_request.number }}
157+
body: |
158+
<!-- postgrest-js-preview-status -->
159+
🚀 **Preview release created!**
160+
161+
supabase-js CI tests have been automatically triggered on feature branch to verify compatibility.
162+
163+
**Preview package:** `${{ needs.preview.outputs.preview-url }}`
164+
165+
Results will be posted here once testing is complete.
166+
167+
edit-mode: replace

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[![Build](https://github.com/supabase/postgrest-js/workflows/CI/badge.svg)](https://github.com/supabase/postgrest-js/actions?query=branch%3Amaster)
44
[![Package](https://img.shields.io/npm/v/@supabase/postgrest-js)](https://www.npmjs.com/package/@supabase/postgrest-js)
55
[![License: MIT](https://img.shields.io/npm/l/@supabase/postgrest-js)](#license)
6+
[![pkg.pr.new](https://pkg.pr.new/badge/supabase/postgrest-js)](https://pkg.pr.new/~/supabase/postgrest-js)
7+
68

79
Isomorphic JavaScript client for [PostgREST](https://postgrest.org). The goal of this library is to make an "ORM-like" restful interface.
810

src/PostgrestClient.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import PostgrestQueryBuilder from './PostgrestQueryBuilder'
22
import PostgrestFilterBuilder from './PostgrestFilterBuilder'
3-
import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOptions } from './types'
3+
import { Fetch, GenericSchema, ClientServerOptions } from './types'
44

55
/**
66
* PostgREST client.
@@ -14,16 +14,23 @@ import { Fetch, GenericSchema, ClientServerOptions, GetGenericDatabaseWithOption
1414
*/
1515
export default class PostgrestClient<
1616
Database = any,
17-
ClientOptions extends ClientServerOptions = GetGenericDatabaseWithOptions<
18-
Database,
19-
{ PostgrestVersion: '12' }
20-
>['options'],
17+
ClientOptions extends ClientServerOptions = Database extends {
18+
__InternalSupabase: infer I extends ClientServerOptions
19+
}
20+
? I
21+
: {},
2122
SchemaName extends string &
22-
keyof GetGenericDatabaseWithOptions<Database>['db'] = 'public' extends keyof GetGenericDatabaseWithOptions<Database>['db']
23+
keyof Omit<Database, '__InternalSupabase'> = 'public' extends keyof Omit<
24+
Database,
25+
'__InternalSupabase'
26+
>
2327
? 'public'
24-
: string & keyof GetGenericDatabaseWithOptions<Database>['db'],
25-
Schema extends GenericSchema = GetGenericDatabaseWithOptions<Database>['db'][SchemaName] extends GenericSchema
26-
? GetGenericDatabaseWithOptions<Database>['db'][SchemaName]
28+
: string & keyof Omit<Database, '__InternalSupabase'>,
29+
Schema extends GenericSchema = Omit<
30+
Database,
31+
'__InternalSupabase'
32+
>[SchemaName] extends GenericSchema
33+
? Omit<Database, '__InternalSupabase'>[SchemaName]
2734
: any
2835
> {
2936
url: string
@@ -86,7 +93,7 @@ export default class PostgrestClient<
8693
*
8794
* @param schema - The schema to query
8895
*/
89-
schema<DynamicSchema extends string & keyof GetGenericDatabaseWithOptions<Database>['db']>(
96+
schema<DynamicSchema extends string & keyof Omit<Database, '__InternalSupabase'>>(
9097
schema: DynamicSchema
9198
): PostgrestClient<
9299
Database,

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ export type {
2828
PostgrestResponseSuccess,
2929
PostgrestSingleResponse,
3030
PostgrestMaybeSingleResponse,
31-
ClientServerOptions,
32-
GetGenericDatabaseWithOptions,
31+
ClientServerOptions as PostgrestClientOptions,
3332
} from './types'
3433
// https://github.com/supabase/postgrest-js/issues/551
3534
// To be replaced with a helper type that only uses public types

src/types.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ export type DatabaseWithOptions<Database, Options extends ClientServerOptions> =
8080
options: Options
8181
}
8282

83-
const INTERNAL_SUPABASE_OPTIONS = '__InternalSupabase'
84-
85-
export type GetGenericDatabaseWithOptions<
86-
Database,
87-
Opts extends ClientServerOptions = { PostgrestVersion: '12' }
88-
> = IsAny<Database> extends true
89-
? DatabaseWithOptions<Database, Opts>
90-
: typeof INTERNAL_SUPABASE_OPTIONS extends keyof Database
91-
? Database[typeof INTERNAL_SUPABASE_OPTIONS] extends ClientServerOptions
92-
? DatabaseWithOptions<
93-
Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>,
94-
Database[typeof INTERNAL_SUPABASE_OPTIONS]
95-
>
96-
: DatabaseWithOptions<Omit<Database, typeof INTERNAL_SUPABASE_OPTIONS>, Opts>
97-
: DatabaseWithOptions<Database, Opts>
98-
9983
export type MaxAffectedEnabled<PostgrestVersion extends string | undefined> =
10084
PostgrestVersion extends `13${string}` ? true : false
10185

0 commit comments

Comments
 (0)