s3db.js 7.3.10 → 7.4.1

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.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
- stringMetadata[validKey] = String(v);
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;
@@ -11061,6 +11089,7 @@ ${JSON.stringify(validation, null, 2)}`,
11061
11089
  * @param {Function} [config.idGenerator] - Custom ID generator function
11062
11090
  * @param {number} [config.idSize=22] - Size for auto-generated IDs
11063
11091
  * @param {boolean} [config.versioningEnabled=false] - Enable versioning for this resource
11092
+ * @param {Object} [config.events={}] - Event listeners to automatically add
11064
11093
  * @example
11065
11094
  * const users = new Resource({
11066
11095
  * name: 'users',
@@ -11082,6 +11111,14 @@ ${JSON.stringify(validation, null, 2)}`,
11082
11111
  * beforeInsert: [async (data) => {
11083
11112
  * return data;
11084
11113
  * }]
11114
+ * },
11115
+ * events: {
11116
+ * insert: (ev) => console.log('Inserted:', ev.id),
11117
+ * update: [
11118
+ * (ev) => console.warn('Update detected'),
11119
+ * (ev) => console.log('Updated:', ev.id)
11120
+ * ],
11121
+ * delete: (ev) => console.log('Deleted:', ev.id)
11085
11122
  * }
11086
11123
  * });
11087
11124
  *
@@ -11134,7 +11171,8 @@ ${JSON.stringify(validation, null, 2)}`,
11134
11171
  hooks = {},
11135
11172
  idGenerator: customIdGenerator,
11136
11173
  idSize = 22,
11137
- versioningEnabled = false
11174
+ versioningEnabled = false,
11175
+ events = {}
11138
11176
  } = config;
11139
11177
  this.name = name;
11140
11178
  this.client = client;
@@ -11176,6 +11214,19 @@ ${JSON.stringify(validation, null, 2)}`,
11176
11214
  }
11177
11215
  }
11178
11216
  }
11217
+ if (events && Object.keys(events).length > 0) {
11218
+ for (const [eventName, listeners] of Object.entries(events)) {
11219
+ if (Array.isArray(listeners)) {
11220
+ for (const listener of listeners) {
11221
+ if (typeof listener === "function") {
11222
+ this.on(eventName, listener);
11223
+ }
11224
+ }
11225
+ } else if (typeof listeners === "function") {
11226
+ this.on(eventName, listeners);
11227
+ }
11228
+ }
11229
+ }
11179
11230
  this._initMiddleware();
11180
11231
  }
11181
11232
  /**
@@ -13215,6 +13266,24 @@ ${JSON.stringify(validation, null, 2)}`,
13215
13266
  }
13216
13267
  }
13217
13268
  }
13269
+ if (config.events !== void 0) {
13270
+ if (typeof config.events !== "object" || Array.isArray(config.events)) {
13271
+ errors.push("Resource 'events' must be an object");
13272
+ } else {
13273
+ for (const [eventName, listeners] of Object.entries(config.events)) {
13274
+ if (Array.isArray(listeners)) {
13275
+ for (let i = 0; i < listeners.length; i++) {
13276
+ const listener = listeners[i];
13277
+ if (typeof listener !== "function") {
13278
+ errors.push(`Resource 'events.${eventName}[${i}]' must be a function`);
13279
+ }
13280
+ }
13281
+ } else if (typeof listeners !== "function") {
13282
+ errors.push(`Resource 'events.${eventName}' must be a function or array of functions`);
13283
+ }
13284
+ }
13285
+ }
13286
+ }
13218
13287
  return {
13219
13288
  isValid: errors.length === 0,
13220
13289
  errors
@@ -13227,7 +13296,7 @@ ${JSON.stringify(validation, null, 2)}`,
13227
13296
  super();
13228
13297
  this.version = "1";
13229
13298
  this.s3dbVersion = (() => {
13230
- const [ok, err, version] = try_fn_default(() => true ? "7.3.10" : "latest");
13299
+ const [ok, err, version] = try_fn_default(() => true ? "7.4.1" : "latest");
13231
13300
  return ok ? version : "latest";
13232
13301
  })();
13233
13302
  this.resources = {};
@@ -13598,7 +13667,8 @@ ${JSON.stringify(validation, null, 2)}`,
13598
13667
  versioningEnabled: this.versioningEnabled,
13599
13668
  map: config.map,
13600
13669
  idGenerator: config.idGenerator,
13601
- idSize: config.idSize
13670
+ idSize: config.idSize,
13671
+ events: config.events || {}
13602
13672
  });
13603
13673
  resource.database = this;
13604
13674
  this.resources[name] = resource;