s3db.js 3.0.1 → 3.1.0
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 +98 -40
- package/dist/s3db.cjs.min.js +5 -5
- package/dist/s3db.es.js +99 -41
- package/dist/s3db.es.min.js +5 -5
- package/dist/s3db.iife.js +98 -40
- package/dist/s3db.iife.min.js +5 -5
- package/package.json +1 -1
package/dist/s3db.iife.js
CHANGED
|
@@ -839,18 +839,18 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
839
839
|
this.client = AwsS3Client || this.createClient();
|
|
840
840
|
}
|
|
841
841
|
createClient() {
|
|
842
|
-
let
|
|
842
|
+
let options2 = {
|
|
843
843
|
region: this.config.region,
|
|
844
844
|
endpoint: this.config.endpoint
|
|
845
845
|
};
|
|
846
|
-
if (this.config.forcePathStyle)
|
|
846
|
+
if (this.config.forcePathStyle) options2.forcePathStyle = true;
|
|
847
847
|
if (this.config.accessKeyId) {
|
|
848
|
-
|
|
848
|
+
options2.credentials = {
|
|
849
849
|
accessKeyId: this.config.accessKeyId,
|
|
850
850
|
secretAccessKey: this.config.secretAccessKey
|
|
851
851
|
};
|
|
852
852
|
}
|
|
853
|
-
return new clientS3.S3Client(
|
|
853
|
+
return new clientS3.S3Client(options2);
|
|
854
854
|
}
|
|
855
855
|
async sendCommand(command) {
|
|
856
856
|
this.emit("command.request", command.constructor.name, command.input);
|
|
@@ -885,7 +885,7 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
885
885
|
return error;
|
|
886
886
|
}
|
|
887
887
|
async putObject({ key: key2, metadata, contentType, body, contentEncoding }) {
|
|
888
|
-
const
|
|
888
|
+
const options2 = {
|
|
889
889
|
Bucket: this.config.bucket,
|
|
890
890
|
Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key2) : key2,
|
|
891
891
|
Metadata: { ...metadata },
|
|
@@ -894,45 +894,63 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
894
894
|
ContentEncoding: contentEncoding
|
|
895
895
|
};
|
|
896
896
|
try {
|
|
897
|
-
const response = await this.sendCommand(new clientS3.PutObjectCommand(
|
|
898
|
-
this.emit("putObject", response,
|
|
897
|
+
const response = await this.sendCommand(new clientS3.PutObjectCommand(options2));
|
|
898
|
+
this.emit("putObject", response, options2);
|
|
899
899
|
return response;
|
|
900
900
|
} catch (error) {
|
|
901
901
|
throw this.errorProxy(error, {
|
|
902
902
|
key: key2,
|
|
903
|
-
command:
|
|
903
|
+
command: options2
|
|
904
904
|
});
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
async getObject(key2) {
|
|
908
|
-
const
|
|
908
|
+
const options2 = {
|
|
909
909
|
Bucket: this.config.bucket,
|
|
910
910
|
Key: path.join(this.config.keyPrefix, key2)
|
|
911
911
|
};
|
|
912
912
|
try {
|
|
913
|
-
const response = await this.sendCommand(new clientS3.GetObjectCommand(
|
|
914
|
-
this.emit("getObject", response,
|
|
913
|
+
const response = await this.sendCommand(new clientS3.GetObjectCommand(options2));
|
|
914
|
+
this.emit("getObject", response, options2);
|
|
915
915
|
return response;
|
|
916
916
|
} catch (error) {
|
|
917
917
|
throw this.errorProxy(error, {
|
|
918
918
|
key: key2,
|
|
919
|
-
command:
|
|
919
|
+
command: options2
|
|
920
920
|
});
|
|
921
921
|
}
|
|
922
922
|
}
|
|
923
923
|
async headObject(key2) {
|
|
924
|
-
const
|
|
924
|
+
const options2 = {
|
|
925
925
|
Bucket: this.config.bucket,
|
|
926
926
|
Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key2) : key2
|
|
927
927
|
};
|
|
928
928
|
try {
|
|
929
|
-
const response = await this.client.send(new clientS3.HeadObjectCommand(
|
|
930
|
-
this.emit("headObject", response,
|
|
929
|
+
const response = await this.client.send(new clientS3.HeadObjectCommand(options2));
|
|
930
|
+
this.emit("headObject", response, options2);
|
|
931
931
|
return response;
|
|
932
932
|
} catch (error) {
|
|
933
933
|
throw this.errorProxy(error, {
|
|
934
934
|
key: key2,
|
|
935
|
-
command:
|
|
935
|
+
command: options2
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
async copyObject({ from, to }) {
|
|
940
|
+
const options2 = {
|
|
941
|
+
Bucket: this.config.bucket,
|
|
942
|
+
Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, to) : to,
|
|
943
|
+
CopySource: path.join(this.config.bucket, this.config.keyPrefix ? path.join(this.config.keyPrefix, from) : from)
|
|
944
|
+
};
|
|
945
|
+
try {
|
|
946
|
+
const response = await this.client.send(new clientS3.CopyObjectCommand(options2));
|
|
947
|
+
this.emit("copyObject", response, options2);
|
|
948
|
+
return response;
|
|
949
|
+
} catch (error) {
|
|
950
|
+
throw this.errorProxy(error, {
|
|
951
|
+
from,
|
|
952
|
+
to,
|
|
953
|
+
command: options2
|
|
936
954
|
});
|
|
937
955
|
}
|
|
938
956
|
}
|
|
@@ -947,25 +965,25 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
947
965
|
}
|
|
948
966
|
}
|
|
949
967
|
async deleteObject(key2) {
|
|
950
|
-
const
|
|
968
|
+
const options2 = {
|
|
951
969
|
Bucket: this.config.bucket,
|
|
952
970
|
Key: this.config.keyPrefix ? path.join(this.config.keyPrefix, key2) : key2
|
|
953
971
|
};
|
|
954
972
|
try {
|
|
955
|
-
const response = await this.sendCommand(new clientS3.DeleteObjectCommand(
|
|
956
|
-
this.emit("deleteObject", response,
|
|
973
|
+
const response = await this.sendCommand(new clientS3.DeleteObjectCommand(options2));
|
|
974
|
+
this.emit("deleteObject", response, options2);
|
|
957
975
|
return response;
|
|
958
976
|
} catch (error) {
|
|
959
977
|
throw this.errorProxy(error, {
|
|
960
978
|
key: key2,
|
|
961
|
-
command:
|
|
979
|
+
command: options2
|
|
962
980
|
});
|
|
963
981
|
}
|
|
964
982
|
}
|
|
965
983
|
async deleteObjects(keys) {
|
|
966
984
|
const packages = lodashEs.chunk(keys, 1e3);
|
|
967
985
|
const { results, errors } = await promisePool.PromisePool.for(packages).withConcurrency(this.parallelism).process(async (keys2) => {
|
|
968
|
-
const
|
|
986
|
+
const options2 = {
|
|
969
987
|
Bucket: this.config.bucket,
|
|
970
988
|
Delete: {
|
|
971
989
|
Objects: keys2.map((key2) => ({
|
|
@@ -974,12 +992,12 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
974
992
|
}
|
|
975
993
|
};
|
|
976
994
|
try {
|
|
977
|
-
const response = await this.sendCommand(new clientS3.DeleteObjectsCommand(
|
|
995
|
+
const response = await this.sendCommand(new clientS3.DeleteObjectsCommand(options2));
|
|
978
996
|
return response;
|
|
979
997
|
} catch (error) {
|
|
980
998
|
throw this.errorProxy(error, {
|
|
981
999
|
key,
|
|
982
|
-
command:
|
|
1000
|
+
command: options2
|
|
983
1001
|
});
|
|
984
1002
|
}
|
|
985
1003
|
});
|
|
@@ -990,23 +1008,42 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
990
1008
|
this.emit("deleteObjects", report, keys);
|
|
991
1009
|
return report;
|
|
992
1010
|
}
|
|
1011
|
+
async deleteAll({ prefix } = {}) {
|
|
1012
|
+
const keys = await this.getAllKeys({ prefix });
|
|
1013
|
+
const report = await this.deleteObjects(keys);
|
|
1014
|
+
this.emit("deleteAll", { prefix, report });
|
|
1015
|
+
return report;
|
|
1016
|
+
}
|
|
1017
|
+
async moveObject({ from, to }) {
|
|
1018
|
+
try {
|
|
1019
|
+
await this.copyObject({ from, to });
|
|
1020
|
+
await this.deleteObject(from);
|
|
1021
|
+
return true;
|
|
1022
|
+
} catch (error) {
|
|
1023
|
+
throw this.errorProxy(error, {
|
|
1024
|
+
from,
|
|
1025
|
+
to,
|
|
1026
|
+
command: options
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
993
1030
|
async listObjects({
|
|
994
1031
|
prefix,
|
|
995
1032
|
maxKeys = 1e3,
|
|
996
1033
|
continuationToken
|
|
997
1034
|
} = {}) {
|
|
998
|
-
const
|
|
1035
|
+
const options2 = {
|
|
999
1036
|
Bucket: this.config.bucket,
|
|
1000
1037
|
MaxKeys: maxKeys,
|
|
1001
1038
|
ContinuationToken: continuationToken,
|
|
1002
1039
|
Prefix: this.config.keyPrefix ? path.join(this.config.keyPrefix, prefix || "") : prefix || ""
|
|
1003
1040
|
};
|
|
1004
1041
|
try {
|
|
1005
|
-
const response = await this.sendCommand(new clientS3.ListObjectsV2Command(
|
|
1006
|
-
this.emit("listObjects", response,
|
|
1042
|
+
const response = await this.sendCommand(new clientS3.ListObjectsV2Command(options2));
|
|
1043
|
+
this.emit("listObjects", response, options2);
|
|
1007
1044
|
return response;
|
|
1008
1045
|
} catch (error) {
|
|
1009
|
-
throw this.errorProxy(error, { command:
|
|
1046
|
+
throw this.errorProxy(error, { command: options2 });
|
|
1010
1047
|
}
|
|
1011
1048
|
}
|
|
1012
1049
|
async count({ prefix } = {}) {
|
|
@@ -1014,11 +1051,11 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1014
1051
|
let truncated = true;
|
|
1015
1052
|
let continuationToken;
|
|
1016
1053
|
while (truncated) {
|
|
1017
|
-
const
|
|
1054
|
+
const options2 = {
|
|
1018
1055
|
prefix,
|
|
1019
1056
|
continuationToken
|
|
1020
1057
|
};
|
|
1021
|
-
const response = await this.listObjects(
|
|
1058
|
+
const response = await this.listObjects(options2);
|
|
1022
1059
|
count += response.KeyCount || 0;
|
|
1023
1060
|
truncated = response.IsTruncated || false;
|
|
1024
1061
|
continuationToken = response.NextContinuationToken;
|
|
@@ -1031,11 +1068,11 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1031
1068
|
let truncated = true;
|
|
1032
1069
|
let continuationToken;
|
|
1033
1070
|
while (truncated) {
|
|
1034
|
-
const
|
|
1071
|
+
const options2 = {
|
|
1035
1072
|
prefix,
|
|
1036
1073
|
continuationToken
|
|
1037
1074
|
};
|
|
1038
|
-
const response = await this.listObjects(
|
|
1075
|
+
const response = await this.listObjects(options2);
|
|
1039
1076
|
if (response.Contents) {
|
|
1040
1077
|
keys = keys.concat(response.Contents.map((x) => x.Key));
|
|
1041
1078
|
}
|
|
@@ -1059,12 +1096,12 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1059
1096
|
let skipped = 0;
|
|
1060
1097
|
while (truncated) {
|
|
1061
1098
|
let maxKeys = offset < 1e3 ? offset : offset - skipped > 1e3 ? 1e3 : offset - skipped;
|
|
1062
|
-
const
|
|
1099
|
+
const options2 = {
|
|
1063
1100
|
prefix,
|
|
1064
1101
|
maxKeys,
|
|
1065
1102
|
continuationToken
|
|
1066
1103
|
};
|
|
1067
|
-
const res = await this.listObjects(
|
|
1104
|
+
const res = await this.listObjects(options2);
|
|
1068
1105
|
if (res.Contents) {
|
|
1069
1106
|
skipped += res.Contents.length;
|
|
1070
1107
|
}
|
|
@@ -1093,11 +1130,11 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1093
1130
|
});
|
|
1094
1131
|
}
|
|
1095
1132
|
while (truncated) {
|
|
1096
|
-
const
|
|
1133
|
+
const options2 = {
|
|
1097
1134
|
prefix,
|
|
1098
1135
|
continuationToken
|
|
1099
1136
|
};
|
|
1100
|
-
const res = await this.listObjects(
|
|
1137
|
+
const res = await this.listObjects(options2);
|
|
1101
1138
|
if (res.Contents) {
|
|
1102
1139
|
keys = keys.concat(res.Contents.map((x) => x.Key));
|
|
1103
1140
|
}
|
|
@@ -1114,6 +1151,30 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1114
1151
|
this.emit("getKeysPage", keys, params);
|
|
1115
1152
|
return keys;
|
|
1116
1153
|
}
|
|
1154
|
+
async moveAllObjects({ prefixFrom, prefixTo }) {
|
|
1155
|
+
const keys = await this.getAllKeys({ prefix: prefixFrom });
|
|
1156
|
+
const { results, errors } = await promisePool.PromisePool.for(keys).withConcurrency(this.parallelism).process(async (key2) => {
|
|
1157
|
+
const to = key2.replace(prefixFrom, prefixTo);
|
|
1158
|
+
try {
|
|
1159
|
+
await this.moveObject({
|
|
1160
|
+
from: key2,
|
|
1161
|
+
to
|
|
1162
|
+
});
|
|
1163
|
+
return to;
|
|
1164
|
+
} catch (error) {
|
|
1165
|
+
throw this.errorProxy(error, {
|
|
1166
|
+
from: key2,
|
|
1167
|
+
to
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
});
|
|
1171
|
+
this.emit("moveAllObjects", { results, errors }, { prefixFrom, prefixTo });
|
|
1172
|
+
if (errors.length > 0) {
|
|
1173
|
+
console.log({ errors });
|
|
1174
|
+
throw new Error("Some objects could not be moved");
|
|
1175
|
+
}
|
|
1176
|
+
return results;
|
|
1177
|
+
}
|
|
1117
1178
|
}
|
|
1118
1179
|
|
|
1119
1180
|
async function dynamicCrypto() {
|
|
@@ -1795,8 +1856,8 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
1795
1856
|
const file = { ...metadata };
|
|
1796
1857
|
if (lodashEs.isEmpty(file.resources)) return file;
|
|
1797
1858
|
for (const [name, structure] of Object.entries(file.resources)) {
|
|
1798
|
-
for (const [attr, value] of Object.entries(structure.
|
|
1799
|
-
file.resources[name].
|
|
1859
|
+
for (const [attr, value] of Object.entries(structure.attributes)) {
|
|
1860
|
+
file.resources[name].attributes[attr] = JSON.parse(value);
|
|
1800
1861
|
}
|
|
1801
1862
|
}
|
|
1802
1863
|
return file;
|
|
@@ -12859,7 +12920,6 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
12859
12920
|
const keys = await this.client.getAllKeys({
|
|
12860
12921
|
prefix: join(this.keyPrefix, dir)
|
|
12861
12922
|
});
|
|
12862
|
-
console.log({ keys });
|
|
12863
12923
|
await this.client.deleteObjects(keys);
|
|
12864
12924
|
}
|
|
12865
12925
|
}
|
|
@@ -12982,12 +13042,10 @@ ${JSON.stringify(validation, null, 2)}`
|
|
|
12982
13042
|
async stop() {
|
|
12983
13043
|
}
|
|
12984
13044
|
installDatabaseProxy() {
|
|
12985
|
-
const db = this;
|
|
12986
13045
|
const installResourcesProxies = this.installResourcesProxies.bind(this);
|
|
12987
13046
|
this.database._createResource = this.database.createResource;
|
|
12988
13047
|
this.database.createResource = async function(...args) {
|
|
12989
13048
|
const resource = await this._createResource(...args);
|
|
12990
|
-
console.log(db.driver);
|
|
12991
13049
|
installResourcesProxies(resource);
|
|
12992
13050
|
return resource;
|
|
12993
13051
|
};
|