s3db.js 7.4.0 → 7.4.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/s3db.cjs.js +69 -4
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +69 -4
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +69 -4
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +1 -1
- package/src/client.class.js +41 -1
- package/src/database.class.js +22 -1
- package/src/resource.class.js +31 -2
package/dist/s3db.iife.js
CHANGED
|
@@ -9641,7 +9641,13 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
9641
9641
|
if (metadata) {
|
|
9642
9642
|
for (const [k, v] of Object.entries(metadata)) {
|
|
9643
9643
|
const validKey = String(k).replace(/[^a-zA-Z0-9\-_]/g, "_");
|
|
9644
|
-
|
|
9644
|
+
const stringValue = String(v);
|
|
9645
|
+
const hasSpecialChars = /[^\x00-\x7F]/.test(stringValue);
|
|
9646
|
+
if (hasSpecialChars) {
|
|
9647
|
+
stringMetadata[validKey] = Buffer.from(stringValue, "utf8").toString("base64");
|
|
9648
|
+
} else {
|
|
9649
|
+
stringMetadata[validKey] = stringValue;
|
|
9650
|
+
}
|
|
9645
9651
|
}
|
|
9646
9652
|
}
|
|
9647
9653
|
const options = {
|
|
@@ -9678,6 +9684,28 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
9678
9684
|
let response, error;
|
|
9679
9685
|
try {
|
|
9680
9686
|
response = await this.sendCommand(new clientS3.GetObjectCommand(options));
|
|
9687
|
+
if (response.Metadata) {
|
|
9688
|
+
const decodedMetadata = {};
|
|
9689
|
+
for (const [key2, value] of Object.entries(response.Metadata)) {
|
|
9690
|
+
if (typeof value === "string") {
|
|
9691
|
+
try {
|
|
9692
|
+
const decoded = Buffer.from(value, "base64").toString("utf8");
|
|
9693
|
+
const hasSpecialChars = /[^\x00-\x7F]/.test(decoded);
|
|
9694
|
+
const isValidBase64 = Buffer.from(decoded, "utf8").toString("base64") === value;
|
|
9695
|
+
if (isValidBase64 && hasSpecialChars && decoded !== value) {
|
|
9696
|
+
decodedMetadata[key2] = decoded;
|
|
9697
|
+
} else {
|
|
9698
|
+
decodedMetadata[key2] = value;
|
|
9699
|
+
}
|
|
9700
|
+
} catch (decodeError) {
|
|
9701
|
+
decodedMetadata[key2] = value;
|
|
9702
|
+
}
|
|
9703
|
+
} else {
|
|
9704
|
+
decodedMetadata[key2] = value;
|
|
9705
|
+
}
|
|
9706
|
+
}
|
|
9707
|
+
response.Metadata = decodedMetadata;
|
|
9708
|
+
}
|
|
9681
9709
|
return response;
|
|
9682
9710
|
} catch (err) {
|
|
9683
9711
|
error = err;
|
|
@@ -11155,6 +11183,14 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
11155
11183
|
this.passphrase = passphrase ?? "secret";
|
|
11156
11184
|
this.versioningEnabled = versioningEnabled;
|
|
11157
11185
|
this.idGenerator = this.configureIdGenerator(customIdGenerator, idSize);
|
|
11186
|
+
if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
|
|
11187
|
+
this.idSize = customIdGenerator;
|
|
11188
|
+
} else if (typeof idSize === "number" && idSize > 0) {
|
|
11189
|
+
this.idSize = idSize;
|
|
11190
|
+
} else {
|
|
11191
|
+
this.idSize = 22;
|
|
11192
|
+
}
|
|
11193
|
+
this.idGeneratorType = this.getIdGeneratorType(customIdGenerator, this.idSize);
|
|
11158
11194
|
this.config = {
|
|
11159
11195
|
cache,
|
|
11160
11196
|
hooks,
|
|
@@ -11210,7 +11246,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
11210
11246
|
*/
|
|
11211
11247
|
configureIdGenerator(customIdGenerator, idSize) {
|
|
11212
11248
|
if (typeof customIdGenerator === "function") {
|
|
11213
|
-
return customIdGenerator;
|
|
11249
|
+
return () => String(customIdGenerator());
|
|
11214
11250
|
}
|
|
11215
11251
|
if (typeof customIdGenerator === "number" && customIdGenerator > 0) {
|
|
11216
11252
|
return nanoid.customAlphabet(nanoid.urlAlphabet, customIdGenerator);
|
|
@@ -11220,6 +11256,19 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
11220
11256
|
}
|
|
11221
11257
|
return idGenerator;
|
|
11222
11258
|
}
|
|
11259
|
+
/**
|
|
11260
|
+
* Get a serializable representation of the ID generator type
|
|
11261
|
+
* @param {Function|number} customIdGenerator - Custom ID generator function or size
|
|
11262
|
+
* @param {number} idSize - Size for auto-generated IDs
|
|
11263
|
+
* @returns {string|number} Serializable ID generator type
|
|
11264
|
+
* @private
|
|
11265
|
+
*/
|
|
11266
|
+
getIdGeneratorType(customIdGenerator, idSize) {
|
|
11267
|
+
if (typeof customIdGenerator === "function") {
|
|
11268
|
+
return "custom_function";
|
|
11269
|
+
}
|
|
11270
|
+
return idSize;
|
|
11271
|
+
}
|
|
11223
11272
|
/**
|
|
11224
11273
|
* Get resource options (for backward compatibility with tests)
|
|
11225
11274
|
*/
|
|
@@ -13268,7 +13317,7 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
13268
13317
|
super();
|
|
13269
13318
|
this.version = "1";
|
|
13270
13319
|
this.s3dbVersion = (() => {
|
|
13271
|
-
const [ok, err, version] = try_fn_default(() => true ? "7.
|
|
13320
|
+
const [ok, err, version] = try_fn_default(() => true ? "7.4.1" : "latest");
|
|
13272
13321
|
return ok ? version : "latest";
|
|
13273
13322
|
})();
|
|
13274
13323
|
this.resources = {};
|
|
@@ -13339,6 +13388,18 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
13339
13388
|
const currentVersion = resourceMetadata.currentVersion || "v0";
|
|
13340
13389
|
const versionData = resourceMetadata.versions?.[currentVersion];
|
|
13341
13390
|
if (versionData) {
|
|
13391
|
+
let restoredIdGenerator, restoredIdSize;
|
|
13392
|
+
if (versionData.idGenerator !== void 0) {
|
|
13393
|
+
if (versionData.idGenerator === "custom_function") {
|
|
13394
|
+
restoredIdGenerator = void 0;
|
|
13395
|
+
restoredIdSize = versionData.idSize || 22;
|
|
13396
|
+
} else if (typeof versionData.idGenerator === "number") {
|
|
13397
|
+
restoredIdGenerator = versionData.idGenerator;
|
|
13398
|
+
restoredIdSize = versionData.idSize || versionData.idGenerator;
|
|
13399
|
+
}
|
|
13400
|
+
} else {
|
|
13401
|
+
restoredIdSize = versionData.idSize || 22;
|
|
13402
|
+
}
|
|
13342
13403
|
this.resources[name] = new resource_class_default({
|
|
13343
13404
|
name,
|
|
13344
13405
|
client: this.client,
|
|
@@ -13358,7 +13419,9 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
13358
13419
|
autoDecrypt: versionData.autoDecrypt !== void 0 ? versionData.autoDecrypt : true,
|
|
13359
13420
|
hooks: versionData.hooks || {},
|
|
13360
13421
|
versioningEnabled: this.versioningEnabled,
|
|
13361
|
-
map: versionData.map
|
|
13422
|
+
map: versionData.map,
|
|
13423
|
+
idGenerator: restoredIdGenerator,
|
|
13424
|
+
idSize: restoredIdSize
|
|
13362
13425
|
});
|
|
13363
13426
|
}
|
|
13364
13427
|
}
|
|
@@ -13519,6 +13582,8 @@ ${JSON.stringify(validation, null, 2)}`,
|
|
|
13519
13582
|
autoDecrypt: resource.config.autoDecrypt,
|
|
13520
13583
|
cache: resource.config.cache,
|
|
13521
13584
|
hooks: resource.config.hooks,
|
|
13585
|
+
idSize: resource.idSize,
|
|
13586
|
+
idGenerator: resource.idGeneratorType,
|
|
13522
13587
|
createdAt: isNewVersion ? (/* @__PURE__ */ new Date()).toISOString() : existingVersionData?.createdAt
|
|
13523
13588
|
}
|
|
13524
13589
|
}
|