Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
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)
}
74 changes: 26 additions & 48 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 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 Down
Loading