@leanbase-giangnd/js 0.0.0 → 0.0.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/LICENSE +37 -0
- package/dist/index.cjs +24 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +24 -1
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +29 -3
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +46 -47
- package/src/leanbase.ts +26 -0
- package/src/version.ts +1 -1
package/dist/leanbase.iife.js
CHANGED
|
@@ -966,7 +966,7 @@ var leanbase = (function () {
|
|
|
966
966
|
};
|
|
967
967
|
if (this.historicalMigration) data.historical_migration = true;
|
|
968
968
|
const payload = JSON.stringify(data);
|
|
969
|
-
const url = `${this.host}/batch/`;
|
|
969
|
+
const url = this.isSnapshotOnlyBatch(data.batch) ? `${this.host}/s/` : `${this.host}/batch/`;
|
|
970
970
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
971
971
|
const fetchOptions = {
|
|
972
972
|
method: 'POST',
|
|
@@ -1035,6 +1035,9 @@ var leanbase = (function () {
|
|
|
1035
1035
|
if (customUserAgent && '' !== customUserAgent) headers['User-Agent'] = customUserAgent;
|
|
1036
1036
|
return headers;
|
|
1037
1037
|
}
|
|
1038
|
+
isSnapshotOnlyBatch(batch) {
|
|
1039
|
+
return batch.length > 0 && batch.every((m)=>m && '$snapshot' === m.event);
|
|
1040
|
+
}
|
|
1038
1041
|
async _flush() {
|
|
1039
1042
|
this.clearFlushTimer();
|
|
1040
1043
|
await this._initPromise;
|
|
@@ -1058,7 +1061,7 @@ var leanbase = (function () {
|
|
|
1058
1061
|
};
|
|
1059
1062
|
if (this.historicalMigration) data.historical_migration = true;
|
|
1060
1063
|
const payload = JSON.stringify(data);
|
|
1061
|
-
const url = `${this.host}/batch/`;
|
|
1064
|
+
const url = this.isSnapshotOnlyBatch(batchMessages) ? `${this.host}/s/` : `${this.host}/batch/`;
|
|
1062
1065
|
const gzippedPayload = this.disableCompression ? null : await gzipCompress(payload, this.isDebug);
|
|
1063
1066
|
const fetchOptions = {
|
|
1064
1067
|
method: 'POST',
|
|
@@ -2860,7 +2863,7 @@ var leanbase = (function () {
|
|
|
2860
2863
|
}
|
|
2861
2864
|
};
|
|
2862
2865
|
|
|
2863
|
-
var version = "0.0.
|
|
2866
|
+
var version = "0.0.2";
|
|
2864
2867
|
var packageInfo = {
|
|
2865
2868
|
version: version};
|
|
2866
2869
|
|
|
@@ -13157,6 +13160,29 @@ var leanbase = (function () {
|
|
|
13157
13160
|
if (!fetchFn) {
|
|
13158
13161
|
return Promise.reject(new Error('Fetch API is not available in this environment.'));
|
|
13159
13162
|
}
|
|
13163
|
+
try {
|
|
13164
|
+
const isPost = !options.method || options.method.toUpperCase() === 'POST';
|
|
13165
|
+
const isBatchEndpoint = typeof url === 'string' && url.endsWith('/batch/');
|
|
13166
|
+
if (isPost && isBatchEndpoint && options && options.body) {
|
|
13167
|
+
let parsed = null;
|
|
13168
|
+
try {
|
|
13169
|
+
const bodyString = typeof options.body === 'string' ? options.body : String(options.body);
|
|
13170
|
+
parsed = JSON.parse(bodyString);
|
|
13171
|
+
} catch {
|
|
13172
|
+
parsed = null;
|
|
13173
|
+
}
|
|
13174
|
+
if (parsed && isArray(parsed.batch)) {
|
|
13175
|
+
const hasSnapshot = parsed.batch.some(item => item && item.event === '$snapshot');
|
|
13176
|
+
if (hasSnapshot) {
|
|
13177
|
+
const host = this.config && this.config.host || '';
|
|
13178
|
+
const newUrl = host ? `${host.replace(/\/$/, '')}/s/` : url;
|
|
13179
|
+
return fetchFn(newUrl, options);
|
|
13180
|
+
}
|
|
13181
|
+
}
|
|
13182
|
+
}
|
|
13183
|
+
} catch {
|
|
13184
|
+
return fetchFn(url, options);
|
|
13185
|
+
}
|
|
13160
13186
|
return fetchFn(url, options);
|
|
13161
13187
|
}
|
|
13162
13188
|
setConfig(config) {
|