s3db.js 7.3.3 → 7.3.4
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/s3db.cjs.js +31 -110
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +18 -97
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +32 -112
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/plugins/cache/filesystem-cache.class.js +1 -8
- package/src/plugins/cache/partition-aware-filesystem-cache.class.js +1 -8
package/dist/s3db.iife.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var S3DB = (function (exports, nanoid, zlib, promisePool, web, lodashEs, crypto, jsonStableStringify, clientS3, flat, FastestValidator) {
|
|
1
|
+
var S3DB = (function (exports, nanoid, zlib, promisePool, web, promises, lodashEs, crypto, jsonStableStringify, clientS3, flat, FastestValidator) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
@@ -2069,16 +2069,6 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
2069
2069
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
2070
2070
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
2071
2071
|
|
|
2072
|
-
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
|
|
2073
|
-
function getOwnPropertyDescriptors(obj) {
|
|
2074
|
-
var keys = Object.keys(obj);
|
|
2075
|
-
var descriptors = {};
|
|
2076
|
-
for (var i = 0; i < keys.length; i++) {
|
|
2077
|
-
descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
|
|
2078
|
-
}
|
|
2079
|
-
return descriptors;
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
2072
|
var formatRegExp = /%[sdj%]/g;
|
|
2083
2073
|
function format(f) {
|
|
2084
2074
|
if (!isString(f)) {
|
|
@@ -2564,64 +2554,6 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
2564
2554
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
2565
2555
|
}
|
|
2566
2556
|
|
|
2567
|
-
var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
|
|
2568
|
-
|
|
2569
|
-
function promisify(original) {
|
|
2570
|
-
if (typeof original !== 'function')
|
|
2571
|
-
throw new TypeError('The "original" argument must be of type Function');
|
|
2572
|
-
|
|
2573
|
-
if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
|
|
2574
|
-
var fn = original[kCustomPromisifiedSymbol];
|
|
2575
|
-
if (typeof fn !== 'function') {
|
|
2576
|
-
throw new TypeError('The "util.promisify.custom" argument must be of type Function');
|
|
2577
|
-
}
|
|
2578
|
-
Object.defineProperty(fn, kCustomPromisifiedSymbol, {
|
|
2579
|
-
value: fn, enumerable: false, writable: false, configurable: true
|
|
2580
|
-
});
|
|
2581
|
-
return fn;
|
|
2582
|
-
}
|
|
2583
|
-
|
|
2584
|
-
function fn() {
|
|
2585
|
-
var promiseResolve, promiseReject;
|
|
2586
|
-
var promise = new Promise(function (resolve, reject) {
|
|
2587
|
-
promiseResolve = resolve;
|
|
2588
|
-
promiseReject = reject;
|
|
2589
|
-
});
|
|
2590
|
-
|
|
2591
|
-
var args = [];
|
|
2592
|
-
for (var i = 0; i < arguments.length; i++) {
|
|
2593
|
-
args.push(arguments[i]);
|
|
2594
|
-
}
|
|
2595
|
-
args.push(function (err, value) {
|
|
2596
|
-
if (err) {
|
|
2597
|
-
promiseReject(err);
|
|
2598
|
-
} else {
|
|
2599
|
-
promiseResolve(value);
|
|
2600
|
-
}
|
|
2601
|
-
});
|
|
2602
|
-
|
|
2603
|
-
try {
|
|
2604
|
-
original.apply(this, args);
|
|
2605
|
-
} catch (err) {
|
|
2606
|
-
promiseReject(err);
|
|
2607
|
-
}
|
|
2608
|
-
|
|
2609
|
-
return promise;
|
|
2610
|
-
}
|
|
2611
|
-
|
|
2612
|
-
Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
|
|
2613
|
-
|
|
2614
|
-
if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
|
|
2615
|
-
value: fn, enumerable: false, writable: false, configurable: true
|
|
2616
|
-
});
|
|
2617
|
-
return Object.defineProperties(
|
|
2618
|
-
fn,
|
|
2619
|
-
getOwnPropertyDescriptors(original)
|
|
2620
|
-
);
|
|
2621
|
-
}
|
|
2622
|
-
|
|
2623
|
-
promisify.custom = kCustomPromisifiedSymbol;
|
|
2624
|
-
|
|
2625
2557
|
var lookup = [];
|
|
2626
2558
|
var revLookup = [];
|
|
2627
2559
|
var Arr = typeof Uint8Array !== 'undefined' ? Uint8Array : Array;
|
|
@@ -6874,12 +6806,6 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
6874
6806
|
|
|
6875
6807
|
var fs = {};
|
|
6876
6808
|
|
|
6877
|
-
const readFile$1 = promisify(fs.readFile);
|
|
6878
|
-
const writeFile$1 = promisify(fs.writeFile);
|
|
6879
|
-
const unlink = promisify(fs.unlink);
|
|
6880
|
-
const readdir$1 = promisify(fs.readdir);
|
|
6881
|
-
const stat$1 = promisify(fs.stat);
|
|
6882
|
-
const mkdir = promisify(fs.mkdir);
|
|
6883
6809
|
class FilesystemCache extends Cache {
|
|
6884
6810
|
constructor({
|
|
6885
6811
|
directory,
|
|
@@ -6956,7 +6882,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
6956
6882
|
}
|
|
6957
6883
|
async _ensureDirectory(dir) {
|
|
6958
6884
|
const [ok, err] = await try_fn_default(async () => {
|
|
6959
|
-
await mkdir(dir, { recursive: true });
|
|
6885
|
+
await promises.mkdir(dir, { recursive: true });
|
|
6960
6886
|
});
|
|
6961
6887
|
if (!ok && err.code !== "EEXIST") {
|
|
6962
6888
|
throw new Error(`Failed to create cache directory: ${err.message}`);
|
|
@@ -6993,7 +6919,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
6993
6919
|
await this._acquireLock(filePath);
|
|
6994
6920
|
}
|
|
6995
6921
|
try {
|
|
6996
|
-
await writeFile
|
|
6922
|
+
await promises.writeFile(filePath, finalData, {
|
|
6997
6923
|
encoding: compressed ? "utf8" : this.encoding,
|
|
6998
6924
|
mode: this.fileMode
|
|
6999
6925
|
});
|
|
@@ -7007,7 +6933,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7007
6933
|
compressedSize: compressed ? Buffer.byteLength(finalData, "utf8") : originalSize,
|
|
7008
6934
|
compressionRatio: compressed ? (Buffer.byteLength(finalData, "utf8") / originalSize).toFixed(2) : 1
|
|
7009
6935
|
};
|
|
7010
|
-
await writeFile
|
|
6936
|
+
await promises.writeFile(this._getMetadataPath(filePath), JSON.stringify(metadata), {
|
|
7011
6937
|
encoding: this.encoding,
|
|
7012
6938
|
mode: this.fileMode
|
|
7013
6939
|
});
|
|
@@ -7045,7 +6971,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7045
6971
|
const metadataPath = this._getMetadataPath(filePath);
|
|
7046
6972
|
if (await this._fileExists(metadataPath)) {
|
|
7047
6973
|
const [ok, err, metadata] = await try_fn_default(async () => {
|
|
7048
|
-
const metaContent = await readFile
|
|
6974
|
+
const metaContent = await promises.readFile(metadataPath, this.encoding);
|
|
7049
6975
|
return JSON.parse(metaContent);
|
|
7050
6976
|
});
|
|
7051
6977
|
if (ok && metadata.ttl > 0) {
|
|
@@ -7054,7 +6980,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7054
6980
|
}
|
|
7055
6981
|
}
|
|
7056
6982
|
} else if (this.ttl > 0) {
|
|
7057
|
-
const stats = await stat
|
|
6983
|
+
const stats = await promises.stat(filePath);
|
|
7058
6984
|
const age = Date.now() - stats.mtime.getTime();
|
|
7059
6985
|
isExpired = age > this.ttl;
|
|
7060
6986
|
}
|
|
@@ -7069,13 +6995,13 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7069
6995
|
await this._acquireLock(filePath);
|
|
7070
6996
|
}
|
|
7071
6997
|
try {
|
|
7072
|
-
const content = await readFile
|
|
6998
|
+
const content = await promises.readFile(filePath, this.encoding);
|
|
7073
6999
|
let isCompressed = false;
|
|
7074
7000
|
if (this.enableMetadata) {
|
|
7075
7001
|
const metadataPath = this._getMetadataPath(filePath);
|
|
7076
7002
|
if (await this._fileExists(metadataPath)) {
|
|
7077
7003
|
const [ok, err, metadata] = await try_fn_default(async () => {
|
|
7078
|
-
const metaContent = await readFile
|
|
7004
|
+
const metaContent = await promises.readFile(metadataPath, this.encoding);
|
|
7079
7005
|
return JSON.parse(metaContent);
|
|
7080
7006
|
});
|
|
7081
7007
|
if (ok) {
|
|
@@ -7114,18 +7040,18 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7114
7040
|
const filePath = this._getFilePath(key);
|
|
7115
7041
|
try {
|
|
7116
7042
|
if (await this._fileExists(filePath)) {
|
|
7117
|
-
await unlink(filePath);
|
|
7043
|
+
await promises.unlink(filePath);
|
|
7118
7044
|
}
|
|
7119
7045
|
if (this.enableMetadata) {
|
|
7120
7046
|
const metadataPath = this._getMetadataPath(filePath);
|
|
7121
7047
|
if (await this._fileExists(metadataPath)) {
|
|
7122
|
-
await unlink(metadataPath);
|
|
7048
|
+
await promises.unlink(metadataPath);
|
|
7123
7049
|
}
|
|
7124
7050
|
}
|
|
7125
7051
|
if (this.enableBackup) {
|
|
7126
7052
|
const backupPath = filePath + this.backupSuffix;
|
|
7127
7053
|
if (await this._fileExists(backupPath)) {
|
|
7128
|
-
await unlink(backupPath);
|
|
7054
|
+
await promises.unlink(backupPath);
|
|
7129
7055
|
}
|
|
7130
7056
|
}
|
|
7131
7057
|
if (this.enableStats) {
|
|
@@ -7144,7 +7070,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7144
7070
|
}
|
|
7145
7071
|
async _clear(prefix) {
|
|
7146
7072
|
try {
|
|
7147
|
-
const files = await readdir
|
|
7073
|
+
const files = await promises.readdir(this.directory);
|
|
7148
7074
|
const cacheFiles = files.filter((file) => {
|
|
7149
7075
|
if (!file.startsWith(this.prefix)) return false;
|
|
7150
7076
|
if (!file.endsWith(this.fileExtension)) return false;
|
|
@@ -7157,18 +7083,18 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7157
7083
|
for (const file of cacheFiles) {
|
|
7158
7084
|
const filePath = path.join(this.directory, file);
|
|
7159
7085
|
if (await this._fileExists(filePath)) {
|
|
7160
|
-
await unlink(filePath);
|
|
7086
|
+
await promises.unlink(filePath);
|
|
7161
7087
|
}
|
|
7162
7088
|
if (this.enableMetadata) {
|
|
7163
7089
|
const metadataPath = this._getMetadataPath(filePath);
|
|
7164
7090
|
if (await this._fileExists(metadataPath)) {
|
|
7165
|
-
await unlink(metadataPath);
|
|
7091
|
+
await promises.unlink(metadataPath);
|
|
7166
7092
|
}
|
|
7167
7093
|
}
|
|
7168
7094
|
if (this.enableBackup) {
|
|
7169
7095
|
const backupPath = filePath + this.backupSuffix;
|
|
7170
7096
|
if (await this._fileExists(backupPath)) {
|
|
7171
|
-
await unlink(backupPath);
|
|
7097
|
+
await promises.unlink(backupPath);
|
|
7172
7098
|
}
|
|
7173
7099
|
}
|
|
7174
7100
|
}
|
|
@@ -7192,7 +7118,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7192
7118
|
}
|
|
7193
7119
|
async keys() {
|
|
7194
7120
|
try {
|
|
7195
|
-
const files = await readdir
|
|
7121
|
+
const files = await promises.readdir(this.directory);
|
|
7196
7122
|
const cacheFiles = files.filter(
|
|
7197
7123
|
(file) => file.startsWith(this.prefix) && file.endsWith(this.fileExtension)
|
|
7198
7124
|
);
|
|
@@ -7209,14 +7135,14 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7209
7135
|
// Helper methods
|
|
7210
7136
|
async _fileExists(filePath) {
|
|
7211
7137
|
const [ok] = await try_fn_default(async () => {
|
|
7212
|
-
await stat
|
|
7138
|
+
await promises.stat(filePath);
|
|
7213
7139
|
});
|
|
7214
7140
|
return ok;
|
|
7215
7141
|
}
|
|
7216
7142
|
async _copyFile(src, dest) {
|
|
7217
7143
|
const [ok, err] = await try_fn_default(async () => {
|
|
7218
|
-
const content = await readFile
|
|
7219
|
-
await writeFile
|
|
7144
|
+
const content = await promises.readFile(src);
|
|
7145
|
+
await promises.writeFile(dest, content);
|
|
7220
7146
|
});
|
|
7221
7147
|
if (!ok) {
|
|
7222
7148
|
console.warn("FilesystemCache: Failed to create backup:", err.message);
|
|
@@ -7225,7 +7151,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7225
7151
|
async _cleanup() {
|
|
7226
7152
|
if (!this.ttl || this.ttl <= 0) return;
|
|
7227
7153
|
try {
|
|
7228
|
-
const files = await readdir
|
|
7154
|
+
const files = await promises.readdir(this.directory);
|
|
7229
7155
|
const now = Date.now();
|
|
7230
7156
|
for (const file of files) {
|
|
7231
7157
|
if (!file.startsWith(this.prefix) || !file.endsWith(this.fileExtension)) {
|
|
@@ -7237,7 +7163,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7237
7163
|
const metadataPath = this._getMetadataPath(filePath);
|
|
7238
7164
|
if (await this._fileExists(metadataPath)) {
|
|
7239
7165
|
const [ok, err, metadata] = await try_fn_default(async () => {
|
|
7240
|
-
const metaContent = await readFile
|
|
7166
|
+
const metaContent = await promises.readFile(metadataPath, this.encoding);
|
|
7241
7167
|
return JSON.parse(metaContent);
|
|
7242
7168
|
});
|
|
7243
7169
|
if (ok && metadata.ttl > 0) {
|
|
@@ -7247,7 +7173,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7247
7173
|
}
|
|
7248
7174
|
} else {
|
|
7249
7175
|
const [ok, err, stats] = await try_fn_default(async () => {
|
|
7250
|
-
return await stat
|
|
7176
|
+
return await promises.stat(filePath);
|
|
7251
7177
|
});
|
|
7252
7178
|
if (ok) {
|
|
7253
7179
|
const age = now - stats.mtime.getTime();
|
|
@@ -7317,12 +7243,6 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7317
7243
|
}
|
|
7318
7244
|
}
|
|
7319
7245
|
|
|
7320
|
-
promisify(fs.mkdir);
|
|
7321
|
-
const rmdir = promisify(fs.rm);
|
|
7322
|
-
const readdir = promisify(fs.readdir);
|
|
7323
|
-
const stat = promisify(fs.stat);
|
|
7324
|
-
const writeFile = promisify(fs.writeFile);
|
|
7325
|
-
const readFile = promisify(fs.readFile);
|
|
7326
7246
|
class PartitionAwareFilesystemCache extends FilesystemCache {
|
|
7327
7247
|
constructor({
|
|
7328
7248
|
partitionStrategy = "hierarchical",
|
|
@@ -7444,7 +7364,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7444
7364
|
const partitionDir = this._getPartitionDirectory(resource, partition, partitionValues);
|
|
7445
7365
|
const [ok, err] = await try_fn_default(async () => {
|
|
7446
7366
|
if (await this._fileExists(partitionDir)) {
|
|
7447
|
-
await
|
|
7367
|
+
await promises.rm(partitionDir, { recursive: true });
|
|
7448
7368
|
}
|
|
7449
7369
|
});
|
|
7450
7370
|
if (!ok) {
|
|
@@ -7462,7 +7382,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7462
7382
|
const resourceDir = path.join(this.directory, `resource=${resource}`);
|
|
7463
7383
|
const [ok, err] = await try_fn_default(async () => {
|
|
7464
7384
|
if (await this._fileExists(resourceDir)) {
|
|
7465
|
-
await
|
|
7385
|
+
await promises.rm(resourceDir, { recursive: true });
|
|
7466
7386
|
}
|
|
7467
7387
|
});
|
|
7468
7388
|
for (const [key] of this.partitionUsage.entries()) {
|
|
@@ -7594,11 +7514,11 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7594
7514
|
return filename.replace(/[<>:"/\\|?*]/g, "_");
|
|
7595
7515
|
}
|
|
7596
7516
|
async _calculateDirectoryStats(dir, stats) {
|
|
7597
|
-
const [ok, err, files] = await try_fn_default(() => readdir(dir));
|
|
7517
|
+
const [ok, err, files] = await try_fn_default(() => promises.readdir(dir));
|
|
7598
7518
|
if (!ok) return;
|
|
7599
7519
|
for (const file of files) {
|
|
7600
7520
|
const filePath = path.join(dir, file);
|
|
7601
|
-
const [statOk, statErr, fileStat] = await try_fn_default(() => stat(filePath));
|
|
7521
|
+
const [statOk, statErr, fileStat] = await try_fn_default(() => promises.stat(filePath));
|
|
7602
7522
|
if (statOk) {
|
|
7603
7523
|
if (fileStat.isDirectory()) {
|
|
7604
7524
|
await this._calculateDirectoryStats(filePath, stats);
|
|
@@ -7611,7 +7531,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7611
7531
|
}
|
|
7612
7532
|
async loadUsageStats() {
|
|
7613
7533
|
const [ok, err, content] = await try_fn_default(async () => {
|
|
7614
|
-
const data = await readFile(this.usageStatsFile, "utf8");
|
|
7534
|
+
const data = await promises.readFile(this.usageStatsFile, "utf8");
|
|
7615
7535
|
return JSON.parse(data);
|
|
7616
7536
|
});
|
|
7617
7537
|
if (ok && content) {
|
|
@@ -7621,7 +7541,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7621
7541
|
async _saveUsageStats() {
|
|
7622
7542
|
const statsObject = Object.fromEntries(this.partitionUsage);
|
|
7623
7543
|
await try_fn_default(async () => {
|
|
7624
|
-
await writeFile(
|
|
7544
|
+
await promises.writeFile(
|
|
7625
7545
|
this.usageStatsFile,
|
|
7626
7546
|
JSON.stringify(statsObject, null, 2),
|
|
7627
7547
|
"utf8"
|
|
@@ -7631,7 +7551,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7631
7551
|
async _writeFileWithMetadata(filePath, data) {
|
|
7632
7552
|
const content = JSON.stringify(data);
|
|
7633
7553
|
const [ok, err] = await try_fn_default(async () => {
|
|
7634
|
-
await writeFile(filePath, content, {
|
|
7554
|
+
await promises.writeFile(filePath, content, {
|
|
7635
7555
|
encoding: this.encoding,
|
|
7636
7556
|
mode: this.fileMode
|
|
7637
7557
|
});
|
|
@@ -7643,7 +7563,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
7643
7563
|
}
|
|
7644
7564
|
async _readFileWithMetadata(filePath) {
|
|
7645
7565
|
const [ok, err, content] = await try_fn_default(async () => {
|
|
7646
|
-
return await readFile(filePath, this.encoding);
|
|
7566
|
+
return await promises.readFile(filePath, this.encoding);
|
|
7647
7567
|
});
|
|
7648
7568
|
if (!ok || !content) return null;
|
|
7649
7569
|
try {
|
|
@@ -13196,7 +13116,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
13196
13116
|
super();
|
|
13197
13117
|
this.version = "1";
|
|
13198
13118
|
this.s3dbVersion = (() => {
|
|
13199
|
-
const [ok, err, version] = try_fn_default(() => true ? "7.3.
|
|
13119
|
+
const [ok, err, version] = try_fn_default(() => true ? "7.3.4" : "latest");
|
|
13200
13120
|
return ok ? version : "latest";
|
|
13201
13121
|
})();
|
|
13202
13122
|
this.resources = {};
|
|
@@ -14746,4 +14666,4 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
14746
14666
|
|
|
14747
14667
|
return exports;
|
|
14748
14668
|
|
|
14749
|
-
})({}, nanoid, zlib, PromisePool, streams, _, crypto, stringify, AWS, flat, FastestValidator);
|
|
14669
|
+
})({}, nanoid, zlib, PromisePool, streams, promises, _, crypto, stringify, AWS, flat, FastestValidator);
|