@supabase/postgrest-js 0.37.2 → 0.38.0
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 +4 -4
- package/dist/main/lib/PostgrestTransformBuilder.d.ts +21 -1
- package/dist/main/lib/PostgrestTransformBuilder.d.ts.map +1 -1
- package/dist/main/lib/PostgrestTransformBuilder.js +33 -16
- package/dist/main/lib/PostgrestTransformBuilder.js.map +1 -1
- package/dist/main/lib/types.d.ts +1 -0
- package/dist/main/lib/types.d.ts.map +1 -1
- package/dist/main/lib/types.js +32 -9
- 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/lib/PostgrestTransformBuilder.d.ts +21 -1
- package/dist/module/lib/PostgrestTransformBuilder.d.ts.map +1 -1
- package/dist/module/lib/PostgrestTransformBuilder.js +34 -17
- package/dist/module/lib/PostgrestTransformBuilder.js.map +1 -1
- package/dist/module/lib/types.d.ts +1 -0
- package/dist/module/lib/types.d.ts.map +1 -1
- package/dist/module/lib/types.js +13 -6
- 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 +3 -3
- package/src/lib/PostgrestTransformBuilder.ts +55 -18
- package/src/lib/types.ts +13 -5
- package/src/lib/version.ts +1 -1
package/README.md
CHANGED
|
@@ -25,10 +25,10 @@ const REST_URL = 'http://localhost:3000'
|
|
|
25
25
|
const postgrest = new PostgrestClient(REST_URL)
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
- select(): https://supabase.
|
|
29
|
-
- insert(): https://supabase.
|
|
30
|
-
- update(): https://supabase.
|
|
31
|
-
- delete(): https://supabase.
|
|
28
|
+
- select(): https://supabase.com/docs/reference/javascript/select
|
|
29
|
+
- insert(): https://supabase.com/docs/reference/javascript/insert
|
|
30
|
+
- update(): https://supabase.com/docs/reference/javascript/update
|
|
31
|
+
- delete(): https://supabase.com/docs/reference/javascript/delete
|
|
32
32
|
|
|
33
33
|
#### Custom `fetch` implementation
|
|
34
34
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostgrestBuilder, PostgrestMaybeSingleResponse, PostgrestSingleResponse } from './types';
|
|
1
|
+
import { PostgrestBuilder, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Post-filters (transforms)
|
|
4
4
|
*/
|
|
@@ -60,5 +60,25 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
|
|
|
60
60
|
* Set the response type to CSV.
|
|
61
61
|
*/
|
|
62
62
|
csv(): PromiseLike<PostgrestSingleResponse<string>>;
|
|
63
|
+
/**
|
|
64
|
+
* Set the response type to GeoJSON.
|
|
65
|
+
*/
|
|
66
|
+
geojson(): PromiseLike<PostgrestSingleResponse<Record<string, unknown>>>;
|
|
67
|
+
/**
|
|
68
|
+
* Obtains the EXPLAIN plan for this request.
|
|
69
|
+
*
|
|
70
|
+
* @param analyze If `true`, the query will be executed and the actual run time will be displayed.
|
|
71
|
+
* @param verbose If `true`, the query identifier will be displayed and the result will include the output columns of the query.
|
|
72
|
+
* @param settings If `true`, include information on configuration parameters that affect query planning.
|
|
73
|
+
* @param buffers If `true`, include information on buffer usage.
|
|
74
|
+
* @param wal If `true`, include information on WAL record generation
|
|
75
|
+
*/
|
|
76
|
+
explain({ analyze, verbose, settings, buffers, wal, }?: {
|
|
77
|
+
analyze?: boolean;
|
|
78
|
+
verbose?: boolean;
|
|
79
|
+
settings?: boolean;
|
|
80
|
+
buffers?: boolean;
|
|
81
|
+
wal?: boolean;
|
|
82
|
+
}): PromiseLike<PostgrestResponse<Record<string, unknown>>>;
|
|
63
83
|
}
|
|
64
84
|
//# sourceMappingURL=PostgrestTransformBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgrestTransformBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PostgrestTransformBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAAyB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC3E;;;;OAIG;IACH,MAAM,CAAC,OAAO,SAAM,GAAG,IAAI;IAmB3B;;;;;;;OAOG;IACH,KAAK,CACH,MAAM,EAAE,MAAM,CAAC,EACf,EACE,SAAgB,EAChB,UAAkB,EAClB,YAAY,GACb,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAC3E,IAAI;IAaP;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IAM5E;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IASvF;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAKtC;;;OAGG;IACH,MAAM,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAKjD;;;;OAIG;IACH,WAAW,IAAI,WAAW,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC;IAM3D;;OAEG;IACH,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAKnD;;OAEG;IACH,OAAO,IAAI,WAAW,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAKxE;;;;;;;;OAQG;IACH,OAAO,CAAC,EACN,OAAe,EACf,OAAe,EACf,QAAgB,EAChB,OAAe,EACf,GAAW,GACZ,GAAE;QACD,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,GAAG,CAAC,EAAE,OAAO,CAAA;KACT,GAAG,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAiBjE"}
|
|
@@ -90,22 +90,8 @@ class PostgrestTransformBuilder extends types_1.PostgrestBuilder {
|
|
|
90
90
|
*/
|
|
91
91
|
maybeSingle() {
|
|
92
92
|
this.headers['Accept'] = 'application/vnd.pgrst.object+json';
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var _a, _b;
|
|
96
|
-
if ((_b = (_a = res.error) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.includes('Results contain 0 rows')) {
|
|
97
|
-
return onfulfilled({
|
|
98
|
-
error: null,
|
|
99
|
-
data: null,
|
|
100
|
-
count: res.count,
|
|
101
|
-
status: 200,
|
|
102
|
-
statusText: 'OK',
|
|
103
|
-
body: null,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return onfulfilled(res);
|
|
107
|
-
}, onrejected));
|
|
108
|
-
return _this;
|
|
93
|
+
this.allowEmpty = true;
|
|
94
|
+
return this;
|
|
109
95
|
}
|
|
110
96
|
/**
|
|
111
97
|
* Set the response type to CSV.
|
|
@@ -114,6 +100,37 @@ class PostgrestTransformBuilder extends types_1.PostgrestBuilder {
|
|
|
114
100
|
this.headers['Accept'] = 'text/csv';
|
|
115
101
|
return this;
|
|
116
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Set the response type to GeoJSON.
|
|
105
|
+
*/
|
|
106
|
+
geojson() {
|
|
107
|
+
this.headers['Accept'] = 'application/geo+json';
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Obtains the EXPLAIN plan for this request.
|
|
112
|
+
*
|
|
113
|
+
* @param analyze If `true`, the query will be executed and the actual run time will be displayed.
|
|
114
|
+
* @param verbose If `true`, the query identifier will be displayed and the result will include the output columns of the query.
|
|
115
|
+
* @param settings If `true`, include information on configuration parameters that affect query planning.
|
|
116
|
+
* @param buffers If `true`, include information on buffer usage.
|
|
117
|
+
* @param wal If `true`, include information on WAL record generation
|
|
118
|
+
*/
|
|
119
|
+
explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, } = {}) {
|
|
120
|
+
const options = [
|
|
121
|
+
analyze ? 'analyze' : null,
|
|
122
|
+
verbose ? 'verbose' : null,
|
|
123
|
+
settings ? 'settings' : null,
|
|
124
|
+
buffers ? 'buffers' : null,
|
|
125
|
+
wal ? 'wal' : null,
|
|
126
|
+
]
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.join('|');
|
|
129
|
+
// An Accept header can carry multiple media types but postgrest-js always sends one
|
|
130
|
+
const forMediatype = this.headers['Accept'];
|
|
131
|
+
this.headers['Accept'] = `application/vnd.pgrst.plan+json; for="${forMediatype}"; options=${options};`;
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
117
134
|
}
|
|
118
135
|
exports.default = PostgrestTransformBuilder;
|
|
119
136
|
//# sourceMappingURL=PostgrestTransformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgrestTransformBuilder.js","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"file":"PostgrestTransformBuilder.js","sourceRoot":"","sources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dist/main/lib/types.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
|
|
|
50
50
|
protected shouldThrowOnError: boolean;
|
|
51
51
|
protected signal?: AbortSignal;
|
|
52
52
|
protected fetch: Fetch;
|
|
53
|
+
protected allowEmpty: boolean;
|
|
53
54
|
constructor(builder: PostgrestBuilder<T>);
|
|
54
55
|
/**
|
|
55
56
|
* If there's an error with the query, throwOnError will reject the promise by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;;GAIG;AACH,oBAAY,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;GAIG;AACH,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,UAAU,wBAAwB,CAAC,CAAC,CAAE,SAAQ,qBAAqB;IACjE,KAAK,EAAE,IAAI,CAAA;IACX,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,IAAI,EAAE,CAAC,EAAE,CAAA;IACT,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CACrB;AACD,UAAU,wBAAyB,SAAQ,qBAAqB;IAC9D,KAAK,EAAE,cAAc,CAAA;IACrB,IAAI,EAAE,IAAI,CAAA;IAEV,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,EAAE,IAAI,CAAA;CACZ;AACD,oBAAY,iBAAiB,CAAC,CAAC,IAAI,wBAAwB,CAAC,CAAC,CAAC,GAAG,wBAAwB,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CAAC,CAAC,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GACnE,SAAS,GACT,IAAI,EACR,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAClF,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;CA8FpC"}
|
package/dist/main/lib/types.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,12 +27,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
27
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
28
|
});
|
|
10
29
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
31
|
exports.PostgrestBuilder = void 0;
|
|
16
|
-
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
17
32
|
class PostgrestBuilder {
|
|
18
33
|
constructor(builder) {
|
|
19
34
|
Object.assign(this, builder);
|
|
@@ -22,13 +37,14 @@ class PostgrestBuilder {
|
|
|
22
37
|
_fetch = builder.fetch;
|
|
23
38
|
}
|
|
24
39
|
else if (typeof fetch === 'undefined') {
|
|
25
|
-
_fetch =
|
|
40
|
+
_fetch = (...args) => __awaiter(this, void 0, void 0, function* () { return yield (yield Promise.resolve().then(() => __importStar(require('cross-fetch')))).fetch(...args); });
|
|
26
41
|
}
|
|
27
42
|
else {
|
|
28
43
|
_fetch = fetch;
|
|
29
44
|
}
|
|
30
45
|
this.fetch = (...args) => _fetch(...args);
|
|
31
46
|
this.shouldThrowOnError = builder.shouldThrowOnError || false;
|
|
47
|
+
this.allowEmpty = builder.allowEmpty || false;
|
|
32
48
|
}
|
|
33
49
|
/**
|
|
34
50
|
* If there's an error with the query, throwOnError will reject the promise by
|
|
@@ -63,10 +79,12 @@ class PostgrestBuilder {
|
|
|
63
79
|
body: JSON.stringify(this.body),
|
|
64
80
|
signal: this.signal,
|
|
65
81
|
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
var _a, _b, _c;
|
|
82
|
+
var _a, _b, _c, _d;
|
|
67
83
|
let error = null;
|
|
68
84
|
let data = null;
|
|
69
85
|
let count = null;
|
|
86
|
+
let status = res.status;
|
|
87
|
+
let statusText = res.statusText;
|
|
70
88
|
if (res.ok) {
|
|
71
89
|
const isReturnMinimal = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.split(',').includes('return=minimal');
|
|
72
90
|
if (this.method !== 'HEAD' && !isReturnMinimal) {
|
|
@@ -92,11 +110,16 @@ class PostgrestBuilder {
|
|
|
92
110
|
try {
|
|
93
111
|
error = JSON.parse(body);
|
|
94
112
|
}
|
|
95
|
-
catch (
|
|
113
|
+
catch (_e) {
|
|
96
114
|
error = {
|
|
97
115
|
message: body,
|
|
98
116
|
};
|
|
99
117
|
}
|
|
118
|
+
if (error && this.allowEmpty && ((_d = error === null || error === void 0 ? void 0 : error.details) === null || _d === void 0 ? void 0 : _d.includes('Results contain 0 rows'))) {
|
|
119
|
+
error = null;
|
|
120
|
+
status = 200;
|
|
121
|
+
statusText = 'OK';
|
|
122
|
+
}
|
|
100
123
|
if (error && this.shouldThrowOnError) {
|
|
101
124
|
throw error;
|
|
102
125
|
}
|
|
@@ -105,8 +128,8 @@ class PostgrestBuilder {
|
|
|
105
128
|
error,
|
|
106
129
|
data,
|
|
107
130
|
count,
|
|
108
|
-
status
|
|
109
|
-
statusText
|
|
131
|
+
status,
|
|
132
|
+
statusText,
|
|
110
133
|
body: data,
|
|
111
134
|
};
|
|
112
135
|
return postgrestResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAsB,gBAAgB;IAWpC,YAAY,OAA4B;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC5B,IAAI,MAAa,CAAA;QACjB,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,MAAM,GAAG,OAAO,CAAC,KAAK,CAAA;SACvB;aAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YACvC,MAAM,GAAG,CAAO,GAA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ACX,MAAM,EAAE,GAAG;gBACX,UAAU,EAAE,aAAa;aAC1B,CAAC,CAAC,CAAA;SACJ;QAED,OAAO,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;IAC1C,CAAC;CACF;AA5ID,4CA4IC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.38.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/main/lib/version.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostgrestBuilder, PostgrestMaybeSingleResponse, PostgrestSingleResponse } from './types';
|
|
1
|
+
import { PostgrestBuilder, PostgrestMaybeSingleResponse, PostgrestResponse, PostgrestSingleResponse } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Post-filters (transforms)
|
|
4
4
|
*/
|
|
@@ -60,5 +60,25 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
|
|
|
60
60
|
* Set the response type to CSV.
|
|
61
61
|
*/
|
|
62
62
|
csv(): PromiseLike<PostgrestSingleResponse<string>>;
|
|
63
|
+
/**
|
|
64
|
+
* Set the response type to GeoJSON.
|
|
65
|
+
*/
|
|
66
|
+
geojson(): PromiseLike<PostgrestSingleResponse<Record<string, unknown>>>;
|
|
67
|
+
/**
|
|
68
|
+
* Obtains the EXPLAIN plan for this request.
|
|
69
|
+
*
|
|
70
|
+
* @param analyze If `true`, the query will be executed and the actual run time will be displayed.
|
|
71
|
+
* @param verbose If `true`, the query identifier will be displayed and the result will include the output columns of the query.
|
|
72
|
+
* @param settings If `true`, include information on configuration parameters that affect query planning.
|
|
73
|
+
* @param buffers If `true`, include information on buffer usage.
|
|
74
|
+
* @param wal If `true`, include information on WAL record generation
|
|
75
|
+
*/
|
|
76
|
+
explain({ analyze, verbose, settings, buffers, wal, }?: {
|
|
77
|
+
analyze?: boolean;
|
|
78
|
+
verbose?: boolean;
|
|
79
|
+
settings?: boolean;
|
|
80
|
+
buffers?: boolean;
|
|
81
|
+
wal?: boolean;
|
|
82
|
+
}): PromiseLike<PostgrestResponse<Record<string, unknown>>>;
|
|
63
83
|
}
|
|
64
84
|
//# sourceMappingURL=PostgrestTransformBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgrestTransformBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PostgrestTransformBuilder.d.ts","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,4BAA4B,EAC5B,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAAyB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IAC3E;;;;OAIG;IACH,MAAM,CAAC,OAAO,SAAM,GAAG,IAAI;IAmB3B;;;;;;;OAOG;IACH,KAAK,CACH,MAAM,EAAE,MAAM,CAAC,EACf,EACE,SAAgB,EAChB,UAAkB,EAClB,YAAY,GACb,GAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAC3E,IAAI;IAaP;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IAM5E;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,GAAE;QAAE,YAAY,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,IAAI;IASvF;;OAEG;IACH,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI;IAKtC;;;OAGG;IACH,MAAM,IAAI,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC;IAKjD;;;;OAIG;IACH,WAAW,IAAI,WAAW,CAAC,4BAA4B,CAAC,CAAC,CAAC,CAAC;IAM3D;;OAEG;IACH,GAAG,IAAI,WAAW,CAAC,uBAAuB,CAAC,MAAM,CAAC,CAAC;IAKnD;;OAEG;IACH,OAAO,IAAI,WAAW,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAKxE;;;;;;;;OAQG;IACH,OAAO,CAAC,EACN,OAAe,EACf,OAAe,EACf,QAAgB,EAChB,OAAe,EACf,GAAW,GACZ,GAAE;QACD,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;QAClB,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,GAAG,CAAC,EAAE,OAAO,CAAA;KACT,GAAG,WAAW,CAAC,iBAAiB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAiBjE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostgrestBuilder } from './types';
|
|
1
|
+
import { PostgrestBuilder, } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Post-filters (transforms)
|
|
4
4
|
*/
|
|
@@ -88,22 +88,8 @@ export default class PostgrestTransformBuilder extends PostgrestBuilder {
|
|
|
88
88
|
*/
|
|
89
89
|
maybeSingle() {
|
|
90
90
|
this.headers['Accept'] = 'application/vnd.pgrst.object+json';
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
var _a, _b;
|
|
94
|
-
if ((_b = (_a = res.error) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.includes('Results contain 0 rows')) {
|
|
95
|
-
return onfulfilled({
|
|
96
|
-
error: null,
|
|
97
|
-
data: null,
|
|
98
|
-
count: res.count,
|
|
99
|
-
status: 200,
|
|
100
|
-
statusText: 'OK',
|
|
101
|
-
body: null,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return onfulfilled(res);
|
|
105
|
-
}, onrejected));
|
|
106
|
-
return _this;
|
|
91
|
+
this.allowEmpty = true;
|
|
92
|
+
return this;
|
|
107
93
|
}
|
|
108
94
|
/**
|
|
109
95
|
* Set the response type to CSV.
|
|
@@ -112,5 +98,36 @@ export default class PostgrestTransformBuilder extends PostgrestBuilder {
|
|
|
112
98
|
this.headers['Accept'] = 'text/csv';
|
|
113
99
|
return this;
|
|
114
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Set the response type to GeoJSON.
|
|
103
|
+
*/
|
|
104
|
+
geojson() {
|
|
105
|
+
this.headers['Accept'] = 'application/geo+json';
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Obtains the EXPLAIN plan for this request.
|
|
110
|
+
*
|
|
111
|
+
* @param analyze If `true`, the query will be executed and the actual run time will be displayed.
|
|
112
|
+
* @param verbose If `true`, the query identifier will be displayed and the result will include the output columns of the query.
|
|
113
|
+
* @param settings If `true`, include information on configuration parameters that affect query planning.
|
|
114
|
+
* @param buffers If `true`, include information on buffer usage.
|
|
115
|
+
* @param wal If `true`, include information on WAL record generation
|
|
116
|
+
*/
|
|
117
|
+
explain({ analyze = false, verbose = false, settings = false, buffers = false, wal = false, } = {}) {
|
|
118
|
+
const options = [
|
|
119
|
+
analyze ? 'analyze' : null,
|
|
120
|
+
verbose ? 'verbose' : null,
|
|
121
|
+
settings ? 'settings' : null,
|
|
122
|
+
buffers ? 'buffers' : null,
|
|
123
|
+
wal ? 'wal' : null,
|
|
124
|
+
]
|
|
125
|
+
.filter(Boolean)
|
|
126
|
+
.join('|');
|
|
127
|
+
// An Accept header can carry multiple media types but postgrest-js always sends one
|
|
128
|
+
const forMediatype = this.headers['Accept'];
|
|
129
|
+
this.headers['Accept'] = `application/vnd.pgrst.plan+json; for="${forMediatype}"; options=${options};`;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
115
132
|
}
|
|
116
133
|
//# sourceMappingURL=PostgrestTransformBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PostgrestTransformBuilder.js","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PostgrestTransformBuilder.js","sourceRoot":"","sources":["../../../src/lib/PostgrestTransformBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,GAIjB,MAAM,SAAS,CAAA;AAEhB;;GAEG;AAEH,MAAM,CAAC,OAAO,OAAO,yBAA6B,SAAQ,gBAAmB;IAC3E;;;;OAIG;IACH,MAAM,CAAC,OAAO,GAAG,GAAG;QAClB,wCAAwC;QACxC,IAAI,MAAM,GAAG,KAAK,CAAA;QAClB,MAAM,cAAc,GAAG,OAAO;aAC3B,KAAK,CAAC,EAAE,CAAC;aACT,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC3B,OAAO,EAAE,CAAA;aACV;YACD,IAAI,CAAC,KAAK,GAAG,EAAE;gBACb,MAAM,GAAG,CAAC,MAAM,CAAA;aACjB;YACD,OAAO,CAAC,CAAA;QACV,CAAC,CAAC;aACD,IAAI,CAAC,EAAE,CAAC,CAAA;QACX,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;QACnD,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CACH,MAAe,EACf,EACE,SAAS,GAAG,IAAI,EAChB,UAAU,GAAG,KAAK,EAClB,YAAY,MAC4D,EAAE;QAE5E,MAAM,GAAG,GAA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,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;YAC1B,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;SACnB;aACE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,GAAG,CAAC,CAAA;QACZ,oFAAoF;QACpF,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QAC3C,IAAI,CAAC,OAAO,CACV,QAAQ,CACT,GAAG,yCAAyC,YAAY,cAAc,OAAO,GAAG,CAAA;QACjF,OAAO,IAA+D,CAAA;IACxE,CAAC;CACF"}
|
|
@@ -50,6 +50,7 @@ export declare abstract class PostgrestBuilder<T> implements PromiseLike<Postgre
|
|
|
50
50
|
protected shouldThrowOnError: boolean;
|
|
51
51
|
protected signal?: AbortSignal;
|
|
52
52
|
protected fetch: Fetch;
|
|
53
|
+
protected allowEmpty: boolean;
|
|
53
54
|
constructor(builder: PostgrestBuilder<T>);
|
|
54
55
|
/**
|
|
55
56
|
* If there's an error with the query, throwOnError will reject the promise by
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA,oBAAY,KAAK,GAAG,OAAO,KAAK,CAAA;AAEhC;;;;GAIG;AACH,oBAAY,cAAc,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;GAIG;AACH,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,UAAU,wBAAwB,CAAC,CAAC,CAAE,SAAQ,qBAAqB;IACjE,KAAK,EAAE,IAAI,CAAA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AE,WAAW,CAAA;IAC9B,SAAS,CAAC,KAAK,EAAE,KAAK,CAAA;IACtB,SAAS,CAAC,UAAU,EAAE,OAAO,CAAA;gBAEjB,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAexC;;;;;OAKG;IACH,YAAY,CAAC,YAAY,CAAC,EAAE,OAAO,GAAG,IAAI;IAQ1C,IAAI,CAAC,QAAQ,GAAG,iBAAiB,CAAC,CAAC,CAAC,EAAE,QAAQ,GAAG,KAAK,EACpD,WAAW,CAAC,EACR,CAAC,CAAC,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GACnE,SAAS,GACT,IAAI,EACR,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,GAAG,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,GAClF,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;CA8FpC"}
|
package/dist/module/lib/types.js
CHANGED
|
@@ -7,7 +7,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import crossFetch from 'cross-fetch';
|
|
11
10
|
export class PostgrestBuilder {
|
|
12
11
|
constructor(builder) {
|
|
13
12
|
Object.assign(this, builder);
|
|
@@ -16,13 +15,14 @@ export class PostgrestBuilder {
|
|
|
16
15
|
_fetch = builder.fetch;
|
|
17
16
|
}
|
|
18
17
|
else if (typeof fetch === 'undefined') {
|
|
19
|
-
_fetch =
|
|
18
|
+
_fetch = (...args) => __awaiter(this, void 0, void 0, function* () { return yield (yield import('cross-fetch')).fetch(...args); });
|
|
20
19
|
}
|
|
21
20
|
else {
|
|
22
21
|
_fetch = fetch;
|
|
23
22
|
}
|
|
24
23
|
this.fetch = (...args) => _fetch(...args);
|
|
25
24
|
this.shouldThrowOnError = builder.shouldThrowOnError || false;
|
|
25
|
+
this.allowEmpty = builder.allowEmpty || false;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* If there's an error with the query, throwOnError will reject the promise by
|
|
@@ -57,10 +57,12 @@ export class PostgrestBuilder {
|
|
|
57
57
|
body: JSON.stringify(this.body),
|
|
58
58
|
signal: this.signal,
|
|
59
59
|
}).then((res) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
var _a, _b, _c;
|
|
60
|
+
var _a, _b, _c, _d;
|
|
61
61
|
let error = null;
|
|
62
62
|
let data = null;
|
|
63
63
|
let count = null;
|
|
64
|
+
let status = res.status;
|
|
65
|
+
let statusText = res.statusText;
|
|
64
66
|
if (res.ok) {
|
|
65
67
|
const isReturnMinimal = (_a = this.headers['Prefer']) === null || _a === void 0 ? void 0 : _a.split(',').includes('return=minimal');
|
|
66
68
|
if (this.method !== 'HEAD' && !isReturnMinimal) {
|
|
@@ -86,11 +88,16 @@ export class PostgrestBuilder {
|
|
|
86
88
|
try {
|
|
87
89
|
error = JSON.parse(body);
|
|
88
90
|
}
|
|
89
|
-
catch (
|
|
91
|
+
catch (_e) {
|
|
90
92
|
error = {
|
|
91
93
|
message: body,
|
|
92
94
|
};
|
|
93
95
|
}
|
|
96
|
+
if (error && this.allowEmpty && ((_d = error === null || error === void 0 ? void 0 : error.details) === null || _d === void 0 ? void 0 : _d.includes('Results contain 0 rows'))) {
|
|
97
|
+
error = null;
|
|
98
|
+
status = 200;
|
|
99
|
+
statusText = 'OK';
|
|
100
|
+
}
|
|
94
101
|
if (error && this.shouldThrowOnError) {
|
|
95
102
|
throw error;
|
|
96
103
|
}
|
|
@@ -99,8 +106,8 @@ export class PostgrestBuilder {
|
|
|
99
106
|
error,
|
|
100
107
|
data,
|
|
101
108
|
count,
|
|
102
|
-
status
|
|
103
|
-
statusText
|
|
109
|
+
status,
|
|
110
|
+
statusText,
|
|
104
111
|
body: data,
|
|
105
112
|
};
|
|
106
113
|
return postgrestResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":";;;;;;;;;AAkDA,MAAM,OAAgB,gBAAgB;IAWpC,YAAY,OAA4B;QACtC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;QAC5B,IAAI,MAAa,CAAA;QACjB,IAAI,OAAO,CAAC,KAAK,EAAE;YACjB,MAAM,GAAG,OAAO,CAAC,KAAK,CAAA;SACvB;aAAM,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YACvC,MAAM,GAAG,CAAO,GAAG,IAAI,EAAE,EAAE,gDAAC,OAAA,MAAM,CAAC,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA,GAAA,CAAA;SAC/E;aAAM;YACL,MAAM,GAAG,KAAK,CAAA;SACf;QACD,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;QACzC,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,KAAK,CAAA;QAC7D,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAA;IAC/C,CAAC;IAED;;;;;OAKG;IACH,YAAY,CAAC,YAAsB;QACjC,IAAI,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,SAAS,EAAE;YACvD,YAAY,GAAG,IAAI,CAAA;SACpB;QACD,IAAI,CAAC,kBAAkB,GAAG,YAAY,CAAA;QACtC,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,CACF,WAGQ,EACR,UAAmF;QAEnF,6DAA6D;QAC7D,IAAI,OAAO,IAAI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AAK;gBACL,IAAI;gBACJ,KAAK;gBACL,MAAM;gBACN,UAAU;gBACV,IAAI,EAAE,IAAI;aACX,CAAA;YAED,OAAO,iBAAiB,CAAA;QAC1B,CAAC,CAAA,CAAC,CAAA;QACF,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;gBAC/B,KAAK,EAAE;oBACL,OAAO,EAAE,eAAe,UAAU,CAAC,OAAO,EAAE;oBAC5C,OAAO,EAAE,EAAE;oBACX,IAAI,EAAE,EAAE;oBACR,IAAI,EAAE,UAAU,CAAC,IAAI,IAAI,EAAE;iBAC5B;gBACD,IAAI,EAAE,IAAI;gBACV,IAAI,EAAE,IAAI;gBACV,KAAK,EAAE,IAAI;gBACX,MAAM,EAAE,GAAG;gBACX,UAAU,EAAE,aAAa;aAC1B,CAAC,CAAC,CAAA;SACJ;QAED,OAAO,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;IAC1C,CAAC;CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.38.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/postgrest-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"description": "Isomorphic PostgREST client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postgrest",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"docs:json": "typedoc --json docs/spec.json --mode modules --includeDeclarations --excludeExternals"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"cross-fetch": "^3.
|
|
34
|
+
"cross-fetch": "^3.1.5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/jest": "^26.0.13",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"rimraf": "^3.0.2",
|
|
45
45
|
"semantic-release-plugin-update-version-in-files": "^1.1.0",
|
|
46
46
|
"ts-jest": "^26.3.0",
|
|
47
|
-
"typedoc": "^0.
|
|
47
|
+
"typedoc": "^0.22.15",
|
|
48
48
|
"typescript": "^4.0.2",
|
|
49
49
|
"wait-for-localhost-cli": "^2.0.0"
|
|
50
50
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
PostgrestBuilder,
|
|
3
|
+
PostgrestMaybeSingleResponse,
|
|
4
|
+
PostgrestResponse,
|
|
5
|
+
PostgrestSingleResponse,
|
|
6
|
+
} from './types'
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Post-filters (transforms)
|
|
@@ -109,23 +114,8 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
|
|
|
109
114
|
*/
|
|
110
115
|
maybeSingle(): PromiseLike<PostgrestMaybeSingleResponse<T>> {
|
|
111
116
|
this.headers['Accept'] = 'application/vnd.pgrst.object+json'
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
this.then((res: any): any => {
|
|
115
|
-
if (res.error?.details?.includes('Results contain 0 rows')) {
|
|
116
|
-
return onfulfilled({
|
|
117
|
-
error: null,
|
|
118
|
-
data: null,
|
|
119
|
-
count: res.count,
|
|
120
|
-
status: 200,
|
|
121
|
-
statusText: 'OK',
|
|
122
|
-
body: null,
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return onfulfilled(res)
|
|
127
|
-
}, onrejected)) as any
|
|
128
|
-
return _this as PromiseLike<PostgrestMaybeSingleResponse<T>>
|
|
117
|
+
this.allowEmpty = true
|
|
118
|
+
return this as PromiseLike<PostgrestMaybeSingleResponse<T>>
|
|
129
119
|
}
|
|
130
120
|
|
|
131
121
|
/**
|
|
@@ -135,4 +125,51 @@ export default class PostgrestTransformBuilder<T> extends PostgrestBuilder<T> {
|
|
|
135
125
|
this.headers['Accept'] = 'text/csv'
|
|
136
126
|
return this as PromiseLike<PostgrestSingleResponse<string>>
|
|
137
127
|
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Set the response type to GeoJSON.
|
|
131
|
+
*/
|
|
132
|
+
geojson(): PromiseLike<PostgrestSingleResponse<Record<string, unknown>>> {
|
|
133
|
+
this.headers['Accept'] = 'application/geo+json'
|
|
134
|
+
return this as PromiseLike<PostgrestSingleResponse<Record<string, unknown>>>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Obtains the EXPLAIN plan for this request.
|
|
139
|
+
*
|
|
140
|
+
* @param analyze If `true`, the query will be executed and the actual run time will be displayed.
|
|
141
|
+
* @param verbose If `true`, the query identifier will be displayed and the result will include the output columns of the query.
|
|
142
|
+
* @param settings If `true`, include information on configuration parameters that affect query planning.
|
|
143
|
+
* @param buffers If `true`, include information on buffer usage.
|
|
144
|
+
* @param wal If `true`, include information on WAL record generation
|
|
145
|
+
*/
|
|
146
|
+
explain({
|
|
147
|
+
analyze = false,
|
|
148
|
+
verbose = false,
|
|
149
|
+
settings = false,
|
|
150
|
+
buffers = false,
|
|
151
|
+
wal = false,
|
|
152
|
+
}: {
|
|
153
|
+
analyze?: boolean
|
|
154
|
+
verbose?: boolean
|
|
155
|
+
settings?: boolean
|
|
156
|
+
buffers?: boolean
|
|
157
|
+
wal?: boolean
|
|
158
|
+
} = {}): PromiseLike<PostgrestResponse<Record<string, unknown>>> {
|
|
159
|
+
const options = [
|
|
160
|
+
analyze ? 'analyze' : null,
|
|
161
|
+
verbose ? 'verbose' : null,
|
|
162
|
+
settings ? 'settings' : null,
|
|
163
|
+
buffers ? 'buffers' : null,
|
|
164
|
+
wal ? 'wal' : null,
|
|
165
|
+
]
|
|
166
|
+
.filter(Boolean)
|
|
167
|
+
.join('|')
|
|
168
|
+
// An Accept header can carry multiple media types but postgrest-js always sends one
|
|
169
|
+
const forMediatype = this.headers['Accept']
|
|
170
|
+
this.headers[
|
|
171
|
+
'Accept'
|
|
172
|
+
] = `application/vnd.pgrst.plan+json; for="${forMediatype}"; options=${options};`
|
|
173
|
+
return this as PromiseLike<PostgrestResponse<Record<string, unknown>>>
|
|
174
|
+
}
|
|
138
175
|
}
|
package/src/lib/types.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import crossFetch from 'cross-fetch'
|
|
2
|
-
|
|
3
1
|
export type Fetch = typeof fetch
|
|
4
2
|
|
|
5
3
|
/**
|
|
@@ -59,6 +57,7 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
59
57
|
protected shouldThrowOnError: boolean
|
|
60
58
|
protected signal?: AbortSignal
|
|
61
59
|
protected fetch: Fetch
|
|
60
|
+
protected allowEmpty: boolean
|
|
62
61
|
|
|
63
62
|
constructor(builder: PostgrestBuilder<T>) {
|
|
64
63
|
Object.assign(this, builder)
|
|
@@ -66,12 +65,13 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
66
65
|
if (builder.fetch) {
|
|
67
66
|
_fetch = builder.fetch
|
|
68
67
|
} else if (typeof fetch === 'undefined') {
|
|
69
|
-
_fetch =
|
|
68
|
+
_fetch = async (...args) => await (await import('cross-fetch')).fetch(...args)
|
|
70
69
|
} else {
|
|
71
70
|
_fetch = fetch
|
|
72
71
|
}
|
|
73
72
|
this.fetch = (...args) => _fetch(...args)
|
|
74
73
|
this.shouldThrowOnError = builder.shouldThrowOnError || false
|
|
74
|
+
this.allowEmpty = builder.allowEmpty || false
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -116,6 +116,8 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
116
116
|
let error = null
|
|
117
117
|
let data = null
|
|
118
118
|
let count = null
|
|
119
|
+
let status = res.status
|
|
120
|
+
let statusText = res.statusText
|
|
119
121
|
|
|
120
122
|
if (res.ok) {
|
|
121
123
|
const isReturnMinimal = this.headers['Prefer']?.split(',').includes('return=minimal')
|
|
@@ -146,6 +148,12 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
150
|
|
|
151
|
+
if (error && this.allowEmpty && error?.details?.includes('Results contain 0 rows')) {
|
|
152
|
+
error = null
|
|
153
|
+
status = 200
|
|
154
|
+
statusText = 'OK'
|
|
155
|
+
}
|
|
156
|
+
|
|
149
157
|
if (error && this.shouldThrowOnError) {
|
|
150
158
|
throw error
|
|
151
159
|
}
|
|
@@ -155,8 +163,8 @@ export abstract class PostgrestBuilder<T> implements PromiseLike<PostgrestRespon
|
|
|
155
163
|
error,
|
|
156
164
|
data,
|
|
157
165
|
count,
|
|
158
|
-
status
|
|
159
|
-
statusText
|
|
166
|
+
status,
|
|
167
|
+
statusText,
|
|
160
168
|
body: data,
|
|
161
169
|
}
|
|
162
170
|
|
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.38.0'
|