From 193729ffd9f843aaea80f8d4b6f988d1a1fd73b3 Mon Sep 17 00:00:00 2001 From: Andrew Valleteau Date: Wed, 29 Oct 2025 17:21:41 +0200 Subject: [PATCH 1/6] chore(postgrest): setup prettier for jest snapshot update (#1627) --- package-lock.json | 17 +++++++++++++++++ packages/core/postgrest-js/package.json | 7 +++++-- packages/core/postgrest-js/scripts/format.js | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100755 packages/core/postgrest-js/scripts/format.js diff --git a/package-lock.json b/package-lock.json index 04597999f..d007b8cb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35108,6 +35108,7 @@ "cpy-cli": "^5.0.0", "jest": "^28.1.0", "node-abort-controller": "^3.0.1", + "prettier": "^2.6.2", "ts-jest": "^28.0.3", "tstyche": "^4.3.0", "type-fest": "^4.32.0", @@ -36224,6 +36225,22 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "packages/core/postgrest-js/node_modules/prettier": { + "version": "2.8.8", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", + "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "packages/core/postgrest-js/node_modules/pretty-format": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.1.3.tgz", diff --git a/packages/core/postgrest-js/package.json b/packages/core/postgrest-js/package.json index 5017ba874..2733ec7c7 100644 --- a/packages/core/postgrest-js/package.json +++ b/packages/core/postgrest-js/package.json @@ -34,6 +34,8 @@ }, "scripts": { "build": "npm run build:cjs && npm run build:esm", + "format": "node scripts/format.js", + "format:check": "node scripts/format.js check", "build:cjs": "tsc -p tsconfig.json", "build:esm": "cpy wrapper.mjs dist/esm/", "build:module": "npm run build:cjs", @@ -50,7 +52,7 @@ "type-check:test": "tsc --noEmit --project tsconfig.test.json", "db:clean": "cd test/db && docker compose down --volumes", "db:run": "cd test/db && docker compose up --detach && wait-for-localhost 3000", - "db:generate-test-types": "cd test/db && docker compose up --detach && wait-for-localhost 8080 && wait-for-localhost 3000 && curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ../types.generated.ts && node ../../scripts/update-json-type.js && cd ../../" + "db:generate-test-types": "cd test/db && docker compose up --detach && wait-for-localhost 8080 && wait-for-localhost 3000 && curl --location 'http://0.0.0.0:8080/generators/typescript?included_schemas=public,personal&detect_one_to_one_relationships=true' > ../types.generated.ts && node ../scripts/update-json-type.js && cd ../../ && npm run format" }, "dependencies": { "@supabase/node-fetch": "2.6.15", @@ -65,6 +67,7 @@ "tstyche": "^4.3.0", "type-fest": "^4.32.0", "wait-for-localhost-cli": "^3.0.0", - "zod": "^3.25.76" + "zod": "^3.25.76", + "prettier": "^2.6.2" } } diff --git a/packages/core/postgrest-js/scripts/format.js b/packages/core/postgrest-js/scripts/format.js new file mode 100755 index 000000000..282b65365 --- /dev/null +++ b/packages/core/postgrest-js/scripts/format.js @@ -0,0 +1,19 @@ +#!/usr/bin/env node + +const { execSync } = require('child_process') +const path = require('path') + +// Get the monorepo root directory (go up from scripts/ to postgrest-js/ to core/ to packages/ to root) +const monorepoRoot = path.resolve(__dirname, '../../../../') + +// Run prettier from the monorepo root +const command = + process.argv[2] === 'check' + ? 'npx prettier --ignore-path packages/core/postgrest-js/.gitignore --check "packages/core/postgrest-js/**/*{ts,js,mjs,json,yml,yaml}"' + : 'npx prettier --ignore-path packages/core/postgrest-js/.gitignore --write "packages/core/postgrest-js/**/*{ts,js,mjs,json,yml,yaml}"' + +try { + execSync(command, { cwd: monorepoRoot, stdio: 'inherit' }) +} catch (error) { + process.exit(error.status || 1) +} From c9cc345b380af2bec42867b1d58d39216a394304 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Wed, 29 Oct 2025 17:29:27 +0200 Subject: [PATCH 2/6] fix(postgrest): stabilize time-based inline snapshots --- .../test/embeded_functions_join.test.ts | 74 +++++++------------ 1 file changed, 26 insertions(+), 48 deletions(-) diff --git a/packages/core/postgrest-js/test/embeded_functions_join.test.ts b/packages/core/postgrest-js/test/embeded_functions_join.test.ts index 465fe3514..38d71e311 100644 --- a/packages/core/postgrest-js/test/embeded_functions_join.test.ts +++ b/packages/core/postgrest-js/test/embeded_functions_join.test.ts @@ -1229,36 +1229,19 @@ describe('embeded functions select', () => { // test select the created_ago embeded function test('select the created_ago embeded function', async () => { const res = await postgrest.from('users_audit').select('id, created_ago') - expect(res).toMatchInlineSnapshot(` - Object { - "count": null, - "data": Array [ - Object { - "created_ago": 7, - "id": 1, - }, - Object { - "created_ago": 7, - "id": 2, - }, - Object { - "created_ago": 7, - "id": 3, - }, - Object { - "created_ago": 7, - "id": 4, - }, - Object { - "created_ago": 7, - "id": 5, - }, - ], - "error": null, - "status": 200, - "statusText": "OK", - } - `) + // Don't snapshot time-based values - they change daily and cause flaky tests + expect(res.error).toBeNull() + expect(res.status).toBe(200) + expect(res.statusText).toBe('OK') + expect(res.count).toBeNull() + expect(res.data).toHaveLength(5) + // Verify structure of each record + expect(res.data?.[0]).toMatchObject({ + id: expect.any(Number), + created_ago: expect.any(Number), + }) + // Verify time-based value is reasonable + expect(res.data?.[0].created_ago).toBeGreaterThanOrEqual(0) let result: Exclude const ExpectedSchema = z.array( z.object({ @@ -1301,24 +1284,19 @@ describe('embeded functions select', () => { // Test the days_since_event embeded function over partitioned table test('select the days_since_event embeded function over partitioned table', async () => { const res = await postgrest.from('events').select('id, days_since_event') - expect(res).toMatchInlineSnapshot(` - Object { - "count": null, - "data": Array [ - Object { - "days_since_event": 500, - "id": 1, - }, - Object { - "days_since_event": 222, - "id": 2, - }, - ], - "error": null, - "status": 200, - "statusText": "OK", - } - `) + // Don't snapshot time-based values - they change daily and cause flaky tests + expect(res.error).toBeNull() + expect(res.status).toBe(200) + expect(res.statusText).toBe('OK') + expect(res.count).toBeNull() + expect(res.data).toHaveLength(2) + // Verify structure of each record + expect(res.data?.[0]).toMatchObject({ + id: expect.any(Number), + days_since_event: expect.any(Number), + }) + // Verify time-based value is reasonable + expect(res.data?.[0].days_since_event).toBeGreaterThanOrEqual(0) let result: Exclude const ExpectedSchema = z.array( z.object({ From bdf68904b1474fe5103cc1ad98617145953f0d0f Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Wed, 29 Oct 2025 17:42:52 +0200 Subject: [PATCH 3/6] test(postgrest): update ts-expect-error message --- packages/core/postgrest-js/test/advanced_rpc.test.ts | 2 +- .../core/postgrest-js/test/embeded_functions_join.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/postgrest-js/test/advanced_rpc.test.ts b/packages/core/postgrest-js/test/advanced_rpc.test.ts index 73942b131..c8af11ef1 100644 --- a/packages/core/postgrest-js/test/advanced_rpc.test.ts +++ b/packages/core/postgrest-js/test/advanced_rpc.test.ts @@ -782,7 +782,7 @@ describe('advanced rpc', () => { test('polymorphic function with unnamed int param', async () => { const res = await postgrest.rpc( - // @ts-expect-error Argument of type '"polymorphic_function_with_unnamed_integer"' is not assignable to parameter of type '"blurb_message" | "function_returning_row" | "function_returning_set_of_rows" + // @ts-expect-error Argument of type '"polymorphic_function_with_unnamed_integer"' is not assignable to parameter of type '"blurb_message" | "created_ago" | "days_since_event" | "function_returning_row" | "function_returning_set_of_rows" | "function_returning_single_row" | "function_using_setof_rows_one" | ... 25 more ... | "void_func"'. 'polymorphic_function_with_unnamed_integer', { '': 1, diff --git a/packages/core/postgrest-js/test/embeded_functions_join.test.ts b/packages/core/postgrest-js/test/embeded_functions_join.test.ts index 38d71e311..f2b27b1bf 100644 --- a/packages/core/postgrest-js/test/embeded_functions_join.test.ts +++ b/packages/core/postgrest-js/test/embeded_functions_join.test.ts @@ -1254,7 +1254,7 @@ describe('embeded functions select', () => { expectType>(true) ExpectedSchema.parse(res.data) const use_rpc_call = await postgrest.rpc('created_ago', { - // @ts-expect-error - id is not a parameter of the created_ago function + // @ts-expect-error Object literal may only specify known properties, and 'id' does not exist in type '{ '': { created_at: string | null; id: number; previous_value: number | null; created_ago: number | null; }; }'. id: 1, }) expect(use_rpc_call).toMatchInlineSnapshot(` @@ -1309,7 +1309,7 @@ describe('embeded functions select', () => { expectType>(true) ExpectedSchema.parse(res.data) const use_rpc_call = await postgrest.rpc('days_since_event', { - // @ts-expect-error - id is not a parameter of the days_since_event function + // @ts-expect-error Object literal may only specify known properties, and 'id' does not exist in type '{ '': { created_at: string; data: unknown; event_type: string | null; id: number; days_since_event: number | null; }; }'. id: 1, }) expect(use_rpc_call).toMatchInlineSnapshot(` From 9d0cd49c50a0bc9bc088b18e85a97037be481545 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Wed, 29 Oct 2025 17:54:04 +0200 Subject: [PATCH 4/6] Update packages/core/postgrest-js/test/advanced_rpc.test.ts Co-authored-by: Andrew Valleteau --- packages/core/postgrest-js/test/advanced_rpc.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/postgrest-js/test/advanced_rpc.test.ts b/packages/core/postgrest-js/test/advanced_rpc.test.ts index c8af11ef1..bf7397e1d 100644 --- a/packages/core/postgrest-js/test/advanced_rpc.test.ts +++ b/packages/core/postgrest-js/test/advanced_rpc.test.ts @@ -782,7 +782,7 @@ describe('advanced rpc', () => { test('polymorphic function with unnamed int param', async () => { const res = await postgrest.rpc( - // @ts-expect-error Argument of type '"polymorphic_function_with_unnamed_integer"' is not assignable to parameter of type '"blurb_message" | "created_ago" | "days_since_event" | "function_returning_row" | "function_returning_set_of_rows" | "function_returning_single_row" | "function_using_setof_rows_one" | ... 25 more ... | "void_func"'. + // @ts-expect-error Argument of type '"polymorphic_function_with_unnamed_integer"' is not assignable to parameter of type 'polymorphic_function_with_unnamed_integer', { '': 1, From cafa78ab89a427fb28ffe3a1c61f885af695e68b Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Wed, 29 Oct 2025 17:54:11 +0200 Subject: [PATCH 5/6] Update packages/core/postgrest-js/test/embeded_functions_join.test.ts Co-authored-by: Andrew Valleteau --- packages/core/postgrest-js/test/embeded_functions_join.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/postgrest-js/test/embeded_functions_join.test.ts b/packages/core/postgrest-js/test/embeded_functions_join.test.ts index f2b27b1bf..4a4cdebed 100644 --- a/packages/core/postgrest-js/test/embeded_functions_join.test.ts +++ b/packages/core/postgrest-js/test/embeded_functions_join.test.ts @@ -1254,7 +1254,7 @@ describe('embeded functions select', () => { expectType>(true) ExpectedSchema.parse(res.data) const use_rpc_call = await postgrest.rpc('created_ago', { - // @ts-expect-error Object literal may only specify known properties, and 'id' does not exist in type '{ '': { created_at: string | null; id: number; previous_value: number | null; created_ago: number | null; }; }'. + // @ts-expect-error Object literal may only specify known properties id: 1, }) expect(use_rpc_call).toMatchInlineSnapshot(` From 823e071c19c30f51902899dd380482897fbc68dc Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Wed, 29 Oct 2025 17:54:18 +0200 Subject: [PATCH 6/6] Update packages/core/postgrest-js/test/embeded_functions_join.test.ts Co-authored-by: Andrew Valleteau --- packages/core/postgrest-js/test/embeded_functions_join.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/postgrest-js/test/embeded_functions_join.test.ts b/packages/core/postgrest-js/test/embeded_functions_join.test.ts index 4a4cdebed..0f15e9886 100644 --- a/packages/core/postgrest-js/test/embeded_functions_join.test.ts +++ b/packages/core/postgrest-js/test/embeded_functions_join.test.ts @@ -1309,7 +1309,7 @@ describe('embeded functions select', () => { expectType>(true) ExpectedSchema.parse(res.data) const use_rpc_call = await postgrest.rpc('days_since_event', { - // @ts-expect-error Object literal may only specify known properties, and 'id' does not exist in type '{ '': { created_at: string; data: unknown; event_type: string | null; id: number; days_since_event: number | null; }; }'. + // @ts-expect-error Object literal may only specify known properties id: 1, }) expect(use_rpc_call).toMatchInlineSnapshot(`