s3db.js 4.1.7 → 4.1.8
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/README.md +83 -16
- package/dist/s3db.cjs.js +82 -42
- package/dist/s3db.cjs.min.js +5 -5
- package/dist/s3db.es.js +82 -42
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +82 -42
- package/dist/s3db.iife.min.js +6 -6
- package/package.json +1 -1
package/dist/s3db.iife.js
CHANGED
|
@@ -9228,36 +9228,45 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
9228
9228
|
*/
|
|
9229
9229
|
async get(id) {
|
|
9230
9230
|
const key = this.getResourceKey(id);
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
9235
|
-
|
|
9236
|
-
|
|
9237
|
-
|
|
9238
|
-
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9231
|
+
try {
|
|
9232
|
+
const request = await this.client.headObject(key);
|
|
9233
|
+
const objectVersion = this.extractVersionFromKey(key) || this.version;
|
|
9234
|
+
const schema = await this.getSchemaForVersion(objectVersion);
|
|
9235
|
+
let metadata = await schema.unmapper(request.Metadata);
|
|
9236
|
+
const behaviorImpl = getBehavior(this.behavior);
|
|
9237
|
+
let body = "";
|
|
9238
|
+
if (request.ContentLength > 0) {
|
|
9239
|
+
try {
|
|
9240
|
+
const fullObject = await this.client.getObject(key);
|
|
9241
|
+
body = await streamToString(fullObject.Body);
|
|
9242
|
+
} catch (error) {
|
|
9243
|
+
console.warn(`Failed to read body for resource ${id}:`, error.message);
|
|
9244
|
+
body = "";
|
|
9245
|
+
}
|
|
9243
9246
|
}
|
|
9247
|
+
const { metadata: processedMetadata } = await behaviorImpl.handleGet({
|
|
9248
|
+
resource: this,
|
|
9249
|
+
metadata,
|
|
9250
|
+
body
|
|
9251
|
+
});
|
|
9252
|
+
let data = processedMetadata;
|
|
9253
|
+
data.id = id;
|
|
9254
|
+
data._contentLength = request.ContentLength;
|
|
9255
|
+
data._lastModified = request.LastModified;
|
|
9256
|
+
data._hasContent = request.ContentLength > 0;
|
|
9257
|
+
data._mimeType = request.ContentType || null;
|
|
9258
|
+
if (request.VersionId) data._versionId = request.VersionId;
|
|
9259
|
+
if (request.Expiration) data._expiresAt = request.Expiration;
|
|
9260
|
+
data._definitionHash = this.getDefinitionHash();
|
|
9261
|
+
this.emit("get", data);
|
|
9262
|
+
return data;
|
|
9263
|
+
} catch (error) {
|
|
9264
|
+
const enhancedError = new Error(`Failed to get resource with id '${id}': ${error.message}`);
|
|
9265
|
+
enhancedError.originalError = error;
|
|
9266
|
+
enhancedError.resourceId = id;
|
|
9267
|
+
enhancedError.resourceKey = key;
|
|
9268
|
+
throw enhancedError;
|
|
9244
9269
|
}
|
|
9245
|
-
const { metadata: processedMetadata } = await behaviorImpl.handleGet({
|
|
9246
|
-
resource: this,
|
|
9247
|
-
metadata,
|
|
9248
|
-
body
|
|
9249
|
-
});
|
|
9250
|
-
let data = processedMetadata;
|
|
9251
|
-
data.id = id;
|
|
9252
|
-
data._contentLength = request.ContentLength;
|
|
9253
|
-
data._lastModified = request.LastModified;
|
|
9254
|
-
data._hasContent = request.ContentLength > 0;
|
|
9255
|
-
data._mimeType = request.ContentType || null;
|
|
9256
|
-
if (request.VersionId) data._versionId = request.VersionId;
|
|
9257
|
-
if (request.Expiration) data._expiresAt = request.Expiration;
|
|
9258
|
-
data._definitionHash = this.getDefinitionHash();
|
|
9259
|
-
this.emit("get", data);
|
|
9260
|
-
return data;
|
|
9261
9270
|
}
|
|
9262
9271
|
/**
|
|
9263
9272
|
* Check if a resource exists by ID
|
|
@@ -9539,15 +9548,21 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
9539
9548
|
return { deletedCount, resource: this.name };
|
|
9540
9549
|
}
|
|
9541
9550
|
/**
|
|
9542
|
-
* List resource IDs with optional partition filtering
|
|
9551
|
+
* List resource IDs with optional partition filtering and pagination
|
|
9543
9552
|
* @param {Object} [params] - List parameters
|
|
9544
9553
|
* @param {string} [params.partition] - Partition name to list from
|
|
9545
9554
|
* @param {Object} [params.partitionValues] - Partition field values to filter by
|
|
9555
|
+
* @param {number} [params.limit] - Maximum number of results to return
|
|
9556
|
+
* @param {number} [params.offset=0] - Offset for pagination
|
|
9546
9557
|
* @returns {Promise<string[]>} Array of resource IDs (strings)
|
|
9547
9558
|
* @example
|
|
9548
9559
|
* // List all IDs
|
|
9549
9560
|
* const allIds = await resource.listIds();
|
|
9550
9561
|
*
|
|
9562
|
+
* // List IDs with pagination
|
|
9563
|
+
* const firstPageIds = await resource.listIds({ limit: 10, offset: 0 });
|
|
9564
|
+
* const secondPageIds = await resource.listIds({ limit: 10, offset: 10 });
|
|
9565
|
+
*
|
|
9551
9566
|
* // List IDs from specific partition
|
|
9552
9567
|
* const googleUserIds = await resource.listIds({
|
|
9553
9568
|
* partition: 'byUtmSource',
|
|
@@ -9560,7 +9575,7 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
9560
9575
|
* partitionValues: { category: 'electronics', region: 'US' }
|
|
9561
9576
|
* });
|
|
9562
9577
|
*/
|
|
9563
|
-
async listIds({ partition = null, partitionValues = {} } = {}) {
|
|
9578
|
+
async listIds({ partition = null, partitionValues = {}, limit, offset = 0 } = {}) {
|
|
9564
9579
|
let prefix;
|
|
9565
9580
|
if (partition && Object.keys(partitionValues).length > 0) {
|
|
9566
9581
|
const partitionDef = this.options.partitions[partition];
|
|
@@ -9584,8 +9599,11 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
9584
9599
|
} else {
|
|
9585
9600
|
prefix = `resource=${this.name}/v=${this.version}`;
|
|
9586
9601
|
}
|
|
9587
|
-
const keys = await this.client.
|
|
9588
|
-
prefix
|
|
9602
|
+
const keys = await this.client.getKeysPage({
|
|
9603
|
+
prefix,
|
|
9604
|
+
offset,
|
|
9605
|
+
amount: limit || 1e3
|
|
9606
|
+
// Default to 1000 if no limit specified
|
|
9589
9607
|
});
|
|
9590
9608
|
const ids = keys.map((key) => {
|
|
9591
9609
|
const parts = key.split("/");
|
|
@@ -9715,6 +9733,7 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
9715
9733
|
* @param {number} [params.size=100] - Page size
|
|
9716
9734
|
* @param {string} [params.partition] - Partition name to page from
|
|
9717
9735
|
* @param {Object} [params.partitionValues] - Partition field values to filter by
|
|
9736
|
+
* @param {boolean} [params.skipCount=false] - Skip total count for performance (useful for large collections)
|
|
9718
9737
|
* @returns {Promise<Object>} Page result with items and pagination info
|
|
9719
9738
|
* @example
|
|
9720
9739
|
* // Get first page of all resources
|
|
@@ -9729,22 +9748,43 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
9729
9748
|
* offset: 0,
|
|
9730
9749
|
* size: 5
|
|
9731
9750
|
* });
|
|
9751
|
+
*
|
|
9752
|
+
* // Skip count for performance in large collections
|
|
9753
|
+
* const fastPage = await resource.page({
|
|
9754
|
+
* offset: 0,
|
|
9755
|
+
* size: 100,
|
|
9756
|
+
* skipCount: true
|
|
9757
|
+
* });
|
|
9758
|
+
* console.log(`Got ${fastPage.items.length} items`); // totalItems will be null
|
|
9732
9759
|
*/
|
|
9733
|
-
async page({ offset = 0, size = 100, partition = null, partitionValues = {} } = {}) {
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9760
|
+
async page({ offset = 0, size = 100, partition = null, partitionValues = {}, skipCount = false } = {}) {
|
|
9761
|
+
let totalItems = null;
|
|
9762
|
+
let totalPages = null;
|
|
9763
|
+
if (!skipCount) {
|
|
9764
|
+
totalItems = await this.count({ partition, partitionValues });
|
|
9765
|
+
totalPages = Math.ceil(totalItems / size);
|
|
9766
|
+
}
|
|
9737
9767
|
const page = Math.floor(offset / size);
|
|
9738
|
-
const
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9768
|
+
const items = await this.list({
|
|
9769
|
+
partition,
|
|
9770
|
+
partitionValues,
|
|
9771
|
+
limit: size,
|
|
9772
|
+
offset
|
|
9773
|
+
});
|
|
9742
9774
|
const result = {
|
|
9743
9775
|
items,
|
|
9744
9776
|
totalItems,
|
|
9745
9777
|
page,
|
|
9746
9778
|
pageSize: size,
|
|
9747
|
-
totalPages
|
|
9779
|
+
totalPages,
|
|
9780
|
+
// Add additional metadata for debugging
|
|
9781
|
+
_debug: {
|
|
9782
|
+
requestedSize: size,
|
|
9783
|
+
requestedOffset: offset,
|
|
9784
|
+
actualItemsReturned: items.length,
|
|
9785
|
+
skipCount,
|
|
9786
|
+
hasTotalItems: totalItems !== null
|
|
9787
|
+
}
|
|
9748
9788
|
};
|
|
9749
9789
|
this.emit("page", result);
|
|
9750
9790
|
return result;
|
|
@@ -10140,7 +10180,7 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
10140
10180
|
this.version = "1";
|
|
10141
10181
|
this.s3dbVersion = (() => {
|
|
10142
10182
|
try {
|
|
10143
|
-
return true ? "4.1.
|
|
10183
|
+
return true ? "4.1.7" : "latest";
|
|
10144
10184
|
} catch (e) {
|
|
10145
10185
|
return "latest";
|
|
10146
10186
|
}
|