@supabase/postgrest-js
Advanced tools
Comparing version 0.34.1 to 0.35.0
@@ -1,5 +0,5 @@ | ||
import { PostgrestBuilder } from './types'; | ||
import { Fetch, PostgrestBuilder } from './types'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> { | ||
constructor(url: string, { headers, schema }?: { | ||
constructor(url: string, { headers, schema, fetch, }?: { | ||
headers?: { | ||
@@ -9,2 +9,3 @@ [key: string]: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
}); | ||
@@ -11,0 +12,0 @@ /** |
@@ -9,4 +9,4 @@ "use strict"; | ||
class PostgrestQueryBuilder extends types_1.PostgrestBuilder { | ||
constructor(url, { headers = {}, schema } = {}) { | ||
super({}); | ||
constructor(url, { headers = {}, schema, fetch, } = {}) { | ||
super({ fetch }); | ||
this.url = new URL(url); | ||
@@ -13,0 +13,0 @@ this.headers = Object.assign({}, headers); |
@@ -1,5 +0,5 @@ | ||
import { PostgrestBuilder } from './types'; | ||
import { Fetch, PostgrestBuilder } from './types'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
export default class PostgrestRpcBuilder<T> extends PostgrestBuilder<T> { | ||
constructor(url: string, { headers, schema }?: { | ||
constructor(url: string, { headers, schema, fetch, }?: { | ||
headers?: { | ||
@@ -9,2 +9,3 @@ [key: string]: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
}); | ||
@@ -11,0 +12,0 @@ /** |
@@ -9,4 +9,4 @@ "use strict"; | ||
class PostgrestRpcBuilder extends types_1.PostgrestBuilder { | ||
constructor(url, { headers = {}, schema } = {}) { | ||
super({}); | ||
constructor(url, { headers = {}, schema, fetch, } = {}) { | ||
super({ fetch }); | ||
this.url = new URL(url); | ||
@@ -13,0 +13,0 @@ this.headers = Object.assign({}, headers); |
@@ -0,1 +1,2 @@ | ||
export declare type Fetch = typeof fetch; | ||
/** | ||
@@ -51,2 +52,3 @@ * Error format | ||
protected signal?: AbortSignal; | ||
protected fetch: Fetch; | ||
constructor(builder: PostgrestBuilder<T>); | ||
@@ -53,0 +55,0 @@ /** |
@@ -21,2 +21,3 @@ "use strict"; | ||
Object.assign(this, builder); | ||
this.fetch = builder.fetch || cross_fetch_1.default; | ||
} | ||
@@ -47,3 +48,3 @@ /** | ||
} | ||
let res = cross_fetch_1.default(this.url.toString(), { | ||
let res = this.fetch(this.url.toString(), { | ||
method: this.method, | ||
@@ -50,0 +51,0 @@ headers: this.headers, |
@@ -1,2 +0,2 @@ | ||
export declare const version = "0.34.1"; | ||
export declare const version = "0.35.0"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -5,3 +5,3 @@ "use strict"; | ||
// generated by genversion | ||
exports.version = '0.34.1'; | ||
exports.version = '0.35.0'; | ||
//# sourceMappingURL=version.js.map |
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import { Fetch } from './lib/types'; | ||
export default class PostgrestClient { | ||
@@ -9,2 +10,3 @@ url: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
/** | ||
@@ -17,3 +19,3 @@ * Creates a PostgREST client. | ||
*/ | ||
constructor(url: string, { headers, schema }?: { | ||
constructor(url: string, { headers, schema, fetch, }?: { | ||
headers?: { | ||
@@ -23,2 +25,3 @@ [key: string]: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
}); | ||
@@ -25,0 +28,0 @@ /** |
@@ -17,6 +17,7 @@ "use strict"; | ||
*/ | ||
constructor(url, { headers = {}, schema } = {}) { | ||
constructor(url, { headers = {}, schema, fetch, } = {}) { | ||
this.url = url; | ||
this.headers = Object.assign(Object.assign({}, constants_1.DEFAULT_HEADERS), headers); | ||
this.schema = schema; | ||
this.fetch = fetch; | ||
} | ||
@@ -39,3 +40,7 @@ /** | ||
const url = `${this.url}/${table}`; | ||
return new PostgrestQueryBuilder_1.default(url, { headers: this.headers, schema: this.schema }); | ||
return new PostgrestQueryBuilder_1.default(url, { | ||
headers: this.headers, | ||
schema: this.schema, | ||
fetch: this.fetch, | ||
}); | ||
} | ||
@@ -55,2 +60,3 @@ /** | ||
schema: this.schema, | ||
fetch: this.fetch, | ||
}).rpc(params, { head, count }); | ||
@@ -57,0 +63,0 @@ } |
@@ -1,5 +0,5 @@ | ||
import { PostgrestBuilder } from './types'; | ||
import { Fetch, PostgrestBuilder } from './types'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
export default class PostgrestQueryBuilder<T> extends PostgrestBuilder<T> { | ||
constructor(url: string, { headers, schema }?: { | ||
constructor(url: string, { headers, schema, fetch, }?: { | ||
headers?: { | ||
@@ -9,2 +9,3 @@ [key: string]: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
}); | ||
@@ -11,0 +12,0 @@ /** |
import { PostgrestBuilder } from './types'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
export default class PostgrestQueryBuilder extends PostgrestBuilder { | ||
constructor(url, { headers = {}, schema } = {}) { | ||
super({}); | ||
constructor(url, { headers = {}, schema, fetch, } = {}) { | ||
super({ fetch }); | ||
this.url = new URL(url); | ||
@@ -7,0 +7,0 @@ this.headers = Object.assign({}, headers); |
@@ -1,5 +0,5 @@ | ||
import { PostgrestBuilder } from './types'; | ||
import { Fetch, PostgrestBuilder } from './types'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
export default class PostgrestRpcBuilder<T> extends PostgrestBuilder<T> { | ||
constructor(url: string, { headers, schema }?: { | ||
constructor(url: string, { headers, schema, fetch, }?: { | ||
headers?: { | ||
@@ -9,2 +9,3 @@ [key: string]: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
}); | ||
@@ -11,0 +12,0 @@ /** |
import { PostgrestBuilder } from './types'; | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder'; | ||
export default class PostgrestRpcBuilder extends PostgrestBuilder { | ||
constructor(url, { headers = {}, schema } = {}) { | ||
super({}); | ||
constructor(url, { headers = {}, schema, fetch, } = {}) { | ||
super({ fetch }); | ||
this.url = new URL(url); | ||
@@ -7,0 +7,0 @@ this.headers = Object.assign({}, headers); |
@@ -0,1 +1,2 @@ | ||
export declare type Fetch = typeof fetch; | ||
/** | ||
@@ -51,2 +52,3 @@ * Error format | ||
protected signal?: AbortSignal; | ||
protected fetch: Fetch; | ||
constructor(builder: PostgrestBuilder<T>); | ||
@@ -53,0 +55,0 @@ /** |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import fetch from 'cross-fetch'; | ||
import crossFetch from 'cross-fetch'; | ||
export class PostgrestBuilder { | ||
@@ -16,2 +16,3 @@ constructor(builder) { | ||
Object.assign(this, builder); | ||
this.fetch = builder.fetch || crossFetch; | ||
} | ||
@@ -42,3 +43,3 @@ /** | ||
} | ||
let res = fetch(this.url.toString(), { | ||
let res = this.fetch(this.url.toString(), { | ||
method: this.method, | ||
@@ -45,0 +46,0 @@ headers: this.headers, |
@@ -1,2 +0,2 @@ | ||
export declare const version = "0.34.1"; | ||
export declare const version = "0.35.0"; | ||
//# sourceMappingURL=version.d.ts.map |
// generated by genversion | ||
export const version = '0.34.1'; | ||
export const version = '0.35.0'; | ||
//# sourceMappingURL=version.js.map |
import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
import PostgrestFilterBuilder from './lib/PostgrestFilterBuilder'; | ||
import { Fetch } from './lib/types'; | ||
export default class PostgrestClient { | ||
@@ -9,2 +10,3 @@ url: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
/** | ||
@@ -17,3 +19,3 @@ * Creates a PostgREST client. | ||
*/ | ||
constructor(url: string, { headers, schema }?: { | ||
constructor(url: string, { headers, schema, fetch, }?: { | ||
headers?: { | ||
@@ -23,2 +25,3 @@ [key: string]: string; | ||
schema?: string; | ||
fetch?: Fetch; | ||
}); | ||
@@ -25,0 +28,0 @@ /** |
@@ -12,6 +12,7 @@ import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder'; | ||
*/ | ||
constructor(url, { headers = {}, schema } = {}) { | ||
constructor(url, { headers = {}, schema, fetch, } = {}) { | ||
this.url = url; | ||
this.headers = Object.assign(Object.assign({}, DEFAULT_HEADERS), headers); | ||
this.schema = schema; | ||
this.fetch = fetch; | ||
} | ||
@@ -34,3 +35,7 @@ /** | ||
const url = `${this.url}/${table}`; | ||
return new PostgrestQueryBuilder(url, { headers: this.headers, schema: this.schema }); | ||
return new PostgrestQueryBuilder(url, { | ||
headers: this.headers, | ||
schema: this.schema, | ||
fetch: this.fetch, | ||
}); | ||
} | ||
@@ -50,2 +55,3 @@ /** | ||
schema: this.schema, | ||
fetch: this.fetch, | ||
}).rpc(params, { head, count }); | ||
@@ -52,0 +58,0 @@ } |
{ | ||
"name": "@supabase/postgrest-js", | ||
"version": "0.34.1", | ||
"version": "0.35.0", | ||
"description": "Isomorphic PostgREST client", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -7,3 +7,3 @@ # `postgrest-js` | ||
Isomorphic JavaScript client for [PostgREST](https://postgrest.org). The goal of this library is to make an "ORM-like" restful interface. | ||
Isomorphic JavaScript client for [PostgREST](https://postgrest.org). The goal of this library is to make an "ORM-like" restful interface. | ||
@@ -34,2 +34,13 @@ Full documentation can be found [here](https://supabase.github.io/postgrest-js/). | ||
#### Custom `fetch` implementation | ||
`postgrest-js` uses the [`cross-fetch`](https://www.npmjs.com/package/cross-fetch) library to make HTTP requests, but an alternative `fetch` implementation can be provided as an option. This is most useful in environments where `cross-fetch` is not compatible, for instance Cloudflare Workers: | ||
```js | ||
import { PostgrestClient } from '@supabase/postgrest-js' | ||
const REST_URL = 'http://localhost:3000' | ||
const postgrest = new PostgrestClient(REST_URL, { fetch: fetch }) | ||
``` | ||
## License | ||
@@ -36,0 +47,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { PostgrestBuilder } from './types' | ||
import { Fetch, PostgrestBuilder } from './types' | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder' | ||
@@ -7,5 +7,9 @@ | ||
url: string, | ||
{ headers = {}, schema }: { headers?: { [key: string]: string }; schema?: string } = {} | ||
{ | ||
headers = {}, | ||
schema, | ||
fetch, | ||
}: { headers?: { [key: string]: string }; schema?: string; fetch?: Fetch } = {} | ||
) { | ||
super({} as PostgrestBuilder<T>) | ||
super(({ fetch } as unknown) as PostgrestBuilder<T>) | ||
this.url = new URL(url) | ||
@@ -12,0 +16,0 @@ this.headers = { ...headers } |
@@ -1,2 +0,2 @@ | ||
import { PostgrestBuilder } from './types' | ||
import { Fetch, PostgrestBuilder } from './types' | ||
import PostgrestFilterBuilder from './PostgrestFilterBuilder' | ||
@@ -7,5 +7,9 @@ | ||
url: string, | ||
{ headers = {}, schema }: { headers?: { [key: string]: string }; schema?: string } = {} | ||
{ | ||
headers = {}, | ||
schema, | ||
fetch, | ||
}: { headers?: { [key: string]: string }; schema?: string; fetch?: Fetch } = {} | ||
) { | ||
super({} as PostgrestBuilder<T>) | ||
super(({ fetch } as unknown) as PostgrestBuilder<T>) | ||
this.url = new URL(url) | ||
@@ -12,0 +16,0 @@ this.headers = { ...headers } |
@@ -1,3 +0,5 @@ | ||
import fetch from 'cross-fetch' | ||
import crossFetch from 'cross-fetch' | ||
export type Fetch = typeof fetch | ||
/** | ||
@@ -59,5 +61,7 @@ * Error format | ||
protected signal?: AbortSignal | ||
protected fetch: Fetch | ||
constructor(builder: PostgrestBuilder<T>) { | ||
Object.assign(this, builder) | ||
this.fetch = builder.fetch || crossFetch | ||
} | ||
@@ -95,3 +99,3 @@ | ||
let res = fetch(this.url.toString(), { | ||
let res = this.fetch(this.url.toString(), { | ||
method: this.method, | ||
@@ -98,0 +102,0 @@ headers: this.headers, |
// generated by genversion | ||
export const version = '0.34.1' | ||
export const version = '0.35.0' |
@@ -5,2 +5,3 @@ import PostgrestQueryBuilder from './lib/PostgrestQueryBuilder' | ||
import { DEFAULT_HEADERS } from './lib/constants' | ||
import { Fetch } from './lib/types' | ||
@@ -11,2 +12,3 @@ export default class PostgrestClient { | ||
schema?: string | ||
fetch?: Fetch | ||
@@ -22,3 +24,7 @@ /** | ||
url: string, | ||
{ headers = {}, schema }: { headers?: { [key: string]: string }; schema?: string } = {} | ||
{ | ||
headers = {}, | ||
schema, | ||
fetch, | ||
}: { headers?: { [key: string]: string }; schema?: string; fetch?: Fetch } = {} | ||
) { | ||
@@ -28,2 +34,3 @@ this.url = url | ||
this.schema = schema | ||
this.fetch = fetch | ||
} | ||
@@ -48,3 +55,7 @@ | ||
const url = `${this.url}/${table}` | ||
return new PostgrestQueryBuilder<T>(url, { headers: this.headers, schema: this.schema }) | ||
return new PostgrestQueryBuilder<T>(url, { | ||
headers: this.headers, | ||
schema: this.schema, | ||
fetch: this.fetch, | ||
}) | ||
} | ||
@@ -75,4 +86,5 @@ | ||
schema: this.schema, | ||
fetch: this.fetch, | ||
}).rpc(params, { head, count }) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
208606
3848
53
6