@supabase/postgrest-js 0.33.3 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -15
- package/dist/main/PostgrestClient.d.ts +7 -2
- package/dist/main/PostgrestClient.d.ts.map +1 -1
- package/dist/main/PostgrestClient.js +11 -4
- package/dist/main/PostgrestClient.js.map +1 -1
- package/dist/main/lib/PostgrestFilterBuilder.d.ts +1 -1
- package/dist/main/lib/PostgrestFilterBuilder.d.ts.map +1 -1
- package/dist/main/lib/PostgrestFilterBuilder.js.map +1 -1
- package/dist/main/lib/PostgrestQueryBuilder.d.ts +3 -2
- package/dist/main/lib/PostgrestQueryBuilder.d.ts.map +1 -1
- package/dist/main/lib/PostgrestQueryBuilder.js +2 -2
- package/dist/main/lib/PostgrestQueryBuilder.js.map +1 -1
- package/dist/main/lib/PostgrestRpcBuilder.d.ts +5 -3
- package/dist/main/lib/PostgrestRpcBuilder.d.ts.map +1 -1
- package/dist/main/lib/PostgrestRpcBuilder.js +15 -5
- package/dist/main/lib/PostgrestRpcBuilder.js.map +1 -1
- package/dist/main/lib/PostgrestTransformBuilder.d.ts +4 -0
- package/dist/main/lib/PostgrestTransformBuilder.d.ts.map +1 -1
- package/dist/main/lib/PostgrestTransformBuilder.js +7 -0
- package/dist/main/lib/PostgrestTransformBuilder.js.map +1 -1
- package/dist/main/lib/types.d.ts +4 -1
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js +31 -6
- package/dist/main/lib/types.js.map +1 -1
- package/dist/main/lib/version.d.ts +1 -1
- package/dist/main/lib/version.js +1 -1
- package/dist/module/PostgrestClient.d.ts +7 -2
- package/dist/module/PostgrestClient.d.ts.map +1 -1
- package/dist/module/PostgrestClient.js +11 -4
- package/dist/module/PostgrestClient.js.map +1 -1
- package/dist/module/lib/PostgrestFilterBuilder.d.ts +1 -1
- package/dist/module/lib/PostgrestFilterBuilder.d.ts.map +1 -1
- package/dist/module/lib/PostgrestFilterBuilder.js.map +1 -1
- package/dist/module/lib/PostgrestQueryBuilder.d.ts +3 -2
- package/dist/module/lib/PostgrestQueryBuilder.d.ts.map +1 -1
- package/dist/module/lib/PostgrestQueryBuilder.js +2 -2
- package/dist/module/lib/PostgrestQueryBuilder.js.map +1 -1
- package/dist/module/lib/PostgrestRpcBuilder.d.ts +5 -3
- package/dist/module/lib/PostgrestRpcBuilder.d.ts.map +1 -1
- package/dist/module/lib/PostgrestRpcBuilder.js +15 -5
- package/dist/module/lib/PostgrestRpcBuilder.js.map +1 -1
- package/dist/module/lib/PostgrestTransformBuilder.d.ts +4 -0
- package/dist/module/lib/PostgrestTransformBuilder.d.ts.map +1 -1
- package/dist/module/lib/PostgrestTransformBuilder.js +7 -0
- package/dist/module/lib/PostgrestTransformBuilder.js.map +1 -1
- package/dist/module/lib/types.d.ts +4 -1
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js +32 -7
- package/dist/module/lib/types.js.map +1 -1
- package/dist/module/lib/version.d.ts +1 -1
- package/dist/module/lib/version.js +1 -1
- package/package.json +2 -1
- package/src/PostgrestClient.ts +18 -3
- package/src/lib/PostgrestFilterBuilder.ts +22 -0
- package/src/lib/PostgrestQueryBuilder.ts +7 -3
- package/src/lib/PostgrestRpcBuilder.ts +21 -5
- package/src/lib/PostgrestTransformBuilder.ts +8 -0
- package/src/lib/types.ts +68 -39
- package/src/lib/version.ts +1 -1
|
@@ -85,6 +85,14 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
|
|
|
85
85
|
return this
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Sets the AbortSignal for the fetch request.
|
|
90
|
+
*/
|
|
91
|
+
abortSignal(signal: AbortSignal): this {
|
|
92
|
+
this.signal = signal
|
|
93
|
+
return this
|
|
94
|
+
}
|
|
95
|
+
|
|
88
96
|
/**
|
|
89
97
|
* Retrieves only one row from the result. Result must be one row (e.g. using
|
|
90
98
|
* `limit`), otherwise this will result in an error.
|
package/src/lib/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import crossFetch from 'cross-fetch'
|
|
2
|
+
|
|
3
|
+
export type Fetch = typeof fetch
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Error format
|
|
@@ -54,10 +56,13 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
54
56
|
protected headers!: { [key: string]: string }
|
|
55
57
|
protected schema?: string
|
|
56
58
|
protected body?: Partial<T> | Partial<T>[]
|
|
57
|
-
protected shouldThrowOnError
|
|
59
|
+
protected shouldThrowOnError = false
|
|
60
|
+
protected signal?: AbortSignal
|
|
61
|
+
protected fetch: Fetch
|
|
58
62
|
|
|
59
63
|
constructor(builder: PostgrestBuilder<T>) {
|
|
60
64
|
Object.assign(this, builder)
|
|
65
|
+
this.fetch = builder.fetch || crossFetch
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
/**
|
|
@@ -90,53 +95,77 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
90
95
|
this.headers['Content-Type'] = 'application/json'
|
|
91
96
|
}
|
|
92
97
|
|
|
93
|
-
|
|
98
|
+
let res = this.fetch(this.url.toString(), {
|
|
94
99
|
method: this.method,
|
|
95
100
|
headers: this.headers,
|
|
96
101
|
body: JSON.stringify(this.body),
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (res.ok) {
|
|
104
|
-
const isReturnMinimal = this.headers['Prefer']?.split(',').includes('return=minimal')
|
|
105
|
-
if (this.method !== 'HEAD' && !isReturnMinimal) {
|
|
106
|
-
const text = await res.text()
|
|
107
|
-
if (!text) {
|
|
108
|
-
// discard `text`
|
|
109
|
-
} else if (this.headers['Accept'] === 'text/csv') {
|
|
110
|
-
data = text
|
|
111
|
-
} else {
|
|
112
|
-
data = JSON.parse(text)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
102
|
+
signal: this.signal,
|
|
103
|
+
}).then(async (res) => {
|
|
104
|
+
let error = null
|
|
105
|
+
let data = null
|
|
106
|
+
let count = null
|
|
115
107
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
if (res.ok) {
|
|
109
|
+
const isReturnMinimal = this.headers['Prefer']?.split(',').includes('return=minimal')
|
|
110
|
+
if (this.method !== 'HEAD' && !isReturnMinimal) {
|
|
111
|
+
const text = await res.text()
|
|
112
|
+
if (!text) {
|
|
113
|
+
// discard `text`
|
|
114
|
+
} else if (this.headers['Accept'] === 'text/csv') {
|
|
115
|
+
data = text
|
|
116
|
+
} else {
|
|
117
|
+
data = JSON.parse(text)
|
|
120
118
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const countHeader = this.headers['Prefer']?.match(/count=(exact|planned|estimated)/)
|
|
122
|
+
const contentRange = res.headers.get('content-range')?.split('/')
|
|
123
|
+
if (countHeader && contentRange && contentRange.length > 1) {
|
|
124
|
+
count = parseInt(contentRange[1])
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
const body = await res.text()
|
|
123
128
|
|
|
124
|
-
|
|
125
|
-
|
|
129
|
+
try {
|
|
130
|
+
error = JSON.parse(body)
|
|
131
|
+
} catch {
|
|
132
|
+
error = {
|
|
133
|
+
message: body,
|
|
126
134
|
}
|
|
127
135
|
}
|
|
128
136
|
|
|
129
|
-
|
|
130
|
-
error
|
|
131
|
-
data,
|
|
132
|
-
count,
|
|
133
|
-
status: res.status,
|
|
134
|
-
statusText: res.statusText,
|
|
135
|
-
body: data,
|
|
137
|
+
if (error && this.shouldThrowOnError) {
|
|
138
|
+
throw error
|
|
136
139
|
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const postgrestResponse = {
|
|
143
|
+
error,
|
|
144
|
+
data,
|
|
145
|
+
count,
|
|
146
|
+
status: res.status,
|
|
147
|
+
statusText: res.statusText,
|
|
148
|
+
body: data,
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return postgrestResponse
|
|
152
|
+
})
|
|
153
|
+
if (!this.shouldThrowOnError) {
|
|
154
|
+
res = res.catch((fetchError) => ({
|
|
155
|
+
error: {
|
|
156
|
+
message: `FetchError: ${fetchError.message}`,
|
|
157
|
+
details: '',
|
|
158
|
+
hint: '',
|
|
159
|
+
code: fetchError.code || '',
|
|
160
|
+
},
|
|
161
|
+
data: null,
|
|
162
|
+
body: null,
|
|
163
|
+
count: null,
|
|
164
|
+
status: 400,
|
|
165
|
+
statusText: 'Bad Request',
|
|
166
|
+
}))
|
|
167
|
+
}
|
|
137
168
|
|
|
138
|
-
|
|
139
|
-
})
|
|
140
|
-
.then(onfulfilled, onrejected)
|
|
169
|
+
return res.then(onfulfilled, onrejected)
|
|
141
170
|
}
|
|
142
171
|
}
|
package/src/lib/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '0.
|
|
2
|
+
export const version = '0.35.1'
|