@electric-sql/client 1.2.0 → 1.2.2
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/dist/cjs/index.cjs +26 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +34 -3
- package/dist/index.browser.mjs +2 -2
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.d.ts +34 -3
- package/dist/index.legacy-esm.js +26 -6
- package/dist/index.legacy-esm.js.map +1 -1
- package/dist/index.mjs +26 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +33 -4
- package/src/column-mapper.ts +25 -0
- package/src/types.ts +33 -2
package/dist/index.mjs
CHANGED
|
@@ -292,6 +292,10 @@ function makeNullableParser(parser, columnInfo, columnName) {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
// src/column-mapper.ts
|
|
295
|
+
function quoteIdentifier(identifier) {
|
|
296
|
+
const escaped = identifier.replace(/"/g, `""`);
|
|
297
|
+
return `"${escaped}"`;
|
|
298
|
+
}
|
|
295
299
|
function snakeToCamel(str) {
|
|
296
300
|
var _a, _b, _c, _d;
|
|
297
301
|
const leadingUnderscores = (_b = (_a = str.match(/^_+/)) == null ? void 0 : _a[0]) != null ? _b : ``;
|
|
@@ -1458,7 +1462,7 @@ requestShape_fn = function() {
|
|
|
1458
1462
|
};
|
|
1459
1463
|
constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
1460
1464
|
return __async(this, null, function* () {
|
|
1461
|
-
var _a, _b, _c;
|
|
1465
|
+
var _a, _b, _c, _d;
|
|
1462
1466
|
const [requestHeaders, params] = yield Promise.all([
|
|
1463
1467
|
resolveHeaders(this.options.headers),
|
|
1464
1468
|
this.options.params ? toInternalParams(convertWhereParamsToObj(this.options.params)) : void 0
|
|
@@ -1474,8 +1478,21 @@ constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
|
1474
1478
|
);
|
|
1475
1479
|
setQueryParam(fetchUrl, WHERE_QUERY_PARAM, encodedWhere);
|
|
1476
1480
|
}
|
|
1477
|
-
if (params.columns)
|
|
1478
|
-
|
|
1481
|
+
if (params.columns) {
|
|
1482
|
+
const originalColumns = yield resolveValue((_b = this.options.params) == null ? void 0 : _b.columns);
|
|
1483
|
+
if (Array.isArray(originalColumns)) {
|
|
1484
|
+
let encodedColumns = originalColumns.map(String);
|
|
1485
|
+
if (this.options.columnMapper) {
|
|
1486
|
+
encodedColumns = encodedColumns.map(
|
|
1487
|
+
this.options.columnMapper.encode
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
const serializedColumns = encodedColumns.map(quoteIdentifier).join(`,`);
|
|
1491
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, serializedColumns);
|
|
1492
|
+
} else {
|
|
1493
|
+
setQueryParam(fetchUrl, COLUMNS_QUERY_PARAM, params.columns);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1479
1496
|
if (params.replica) setQueryParam(fetchUrl, REPLICA_PARAM, params.replica);
|
|
1480
1497
|
if (params.params)
|
|
1481
1498
|
setQueryParam(fetchUrl, WHERE_PARAMS_PARAM, params.params);
|
|
@@ -1493,7 +1510,7 @@ constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
|
1493
1510
|
if (subsetParams.where && typeof subsetParams.where === `string`) {
|
|
1494
1511
|
const encodedWhere = encodeWhereClause(
|
|
1495
1512
|
subsetParams.where,
|
|
1496
|
-
(
|
|
1513
|
+
(_c = this.options.columnMapper) == null ? void 0 : _c.encode
|
|
1497
1514
|
);
|
|
1498
1515
|
setQueryParam(fetchUrl, SUBSET_PARAM_WHERE, encodedWhere);
|
|
1499
1516
|
}
|
|
@@ -1509,7 +1526,7 @@ constructUrl_fn = function(url, resumingFromPause, subsetParams) {
|
|
|
1509
1526
|
if (subsetParams.orderBy && typeof subsetParams.orderBy === `string`) {
|
|
1510
1527
|
const encodedOrderBy = encodeWhereClause(
|
|
1511
1528
|
subsetParams.orderBy,
|
|
1512
|
-
(
|
|
1529
|
+
(_d = this.options.columnMapper) == null ? void 0 : _d.encode
|
|
1513
1530
|
);
|
|
1514
1531
|
setQueryParam(fetchUrl, SUBSET_PARAM_ORDER_BY, encodedOrderBy);
|
|
1515
1532
|
}
|
|
@@ -1660,10 +1677,13 @@ requestShapeSSE_fn = function(opts) {
|
|
|
1660
1677
|
const { fetchUrl, requestAbortController, headers } = opts;
|
|
1661
1678
|
const fetch2 = __privateGet(this, _sseFetchClient);
|
|
1662
1679
|
__privateSet(this, _lastSseConnectionStartTime, Date.now());
|
|
1680
|
+
const sseHeaders = __spreadProps(__spreadValues({}, headers), {
|
|
1681
|
+
Accept: `text/event-stream`
|
|
1682
|
+
});
|
|
1663
1683
|
try {
|
|
1664
1684
|
let buffer = [];
|
|
1665
1685
|
yield fetchEventSource(fetchUrl.toString(), {
|
|
1666
|
-
headers,
|
|
1686
|
+
headers: sseHeaders,
|
|
1667
1687
|
fetch: fetch2,
|
|
1668
1688
|
onopen: (response) => __async(this, null, function* () {
|
|
1669
1689
|
__privateSet(this, _connected, true);
|