Skip to content
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions packages/core/postgrest-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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"
}
}
19 changes: 19 additions & 0 deletions packages/core/postgrest-js/scripts/format.js
Original file line number Diff line number Diff line change
@@ -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)
}
2 changes: 1 addition & 1 deletion packages/core/postgrest-js/test/advanced_rpc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
'polymorphic_function_with_unnamed_integer',
{
'': 1,
Expand Down
78 changes: 28 additions & 50 deletions packages/core/postgrest-js/test/embeded_functions_join.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof res.data, null>
const ExpectedSchema = z.array(
z.object({
Expand All @@ -1271,7 +1254,7 @@ describe('embeded functions select', () => {
expectType<TypeEqual<typeof result, typeof expected>>(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
id: 1,
})
expect(use_rpc_call).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -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<typeof res.data, null>
const ExpectedSchema = z.array(
z.object({
Expand All @@ -1331,7 +1309,7 @@ describe('embeded functions select', () => {
expectType<TypeEqual<typeof result, typeof expected>>(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
id: 1,
})
expect(use_rpc_call).toMatchInlineSnapshot(`
Expand Down