@hanzo/s3 0.6.3 → 8.0.7

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.
Files changed (119) hide show
  1. package/LICENSE +202 -0
  2. package/MAINTAINERS.md +62 -0
  3. package/README.md +262 -0
  4. package/README_zh_CN.md +192 -0
  5. package/dist/esm/AssumeRoleProvider.d.mts +86 -0
  6. package/dist/esm/AssumeRoleProvider.mjs +183 -0
  7. package/dist/esm/CredentialProvider.d.mts +22 -0
  8. package/dist/esm/CredentialProvider.mjs +48 -0
  9. package/dist/esm/Credentials.d.mts +22 -0
  10. package/dist/esm/Credentials.mjs +38 -0
  11. package/dist/esm/IamAwsProvider.d.mts +27 -0
  12. package/dist/esm/IamAwsProvider.mjs +189 -0
  13. package/dist/esm/errors.d.mts +82 -0
  14. package/dist/esm/errors.mjs +117 -0
  15. package/dist/esm/helpers.d.mts +156 -0
  16. package/dist/esm/helpers.mjs +218 -0
  17. package/dist/esm/internal/async.d.mts +9 -0
  18. package/dist/esm/internal/async.mjs +14 -0
  19. package/dist/esm/internal/callbackify.d.mts +1 -0
  20. package/dist/esm/internal/callbackify.mjs +15 -0
  21. package/dist/esm/internal/client.d.mts +394 -0
  22. package/dist/esm/internal/client.mjs +3007 -0
  23. package/dist/esm/internal/copy-conditions.d.mts +10 -0
  24. package/dist/esm/internal/copy-conditions.mjs +25 -0
  25. package/dist/esm/internal/extensions.d.mts +18 -0
  26. package/dist/esm/internal/extensions.mjs +114 -0
  27. package/dist/esm/internal/helper.d.mts +177 -0
  28. package/dist/esm/internal/helper.mjs +552 -0
  29. package/dist/esm/internal/join-host-port.d.mts +11 -0
  30. package/dist/esm/internal/join-host-port.mjs +23 -0
  31. package/dist/esm/internal/post-policy.d.mts +17 -0
  32. package/dist/esm/internal/post-policy.mjs +98 -0
  33. package/dist/esm/internal/request.d.mts +11 -0
  34. package/dist/esm/internal/request.mjs +75 -0
  35. package/dist/esm/internal/response.d.mts +8 -0
  36. package/dist/esm/internal/response.mjs +16 -0
  37. package/dist/esm/internal/s3-endpoints.d.mts +38 -0
  38. package/dist/esm/internal/s3-endpoints.mjs +68 -0
  39. package/dist/esm/internal/type.d.mts +482 -0
  40. package/dist/esm/internal/type.mjs +30 -0
  41. package/dist/esm/internal/xml-parser.d.mts +93 -0
  42. package/dist/esm/internal/xml-parser.mjs +819 -0
  43. package/dist/esm/notification.d.mts +58 -0
  44. package/dist/esm/notification.mjs +209 -0
  45. package/dist/esm/s3.d.mts +40 -0
  46. package/dist/esm/s3.mjs +86 -0
  47. package/dist/esm/signing.d.mts +5 -0
  48. package/dist/esm/signing.mjs +258 -0
  49. package/dist/main/AssumeRoleProvider.d.ts +86 -0
  50. package/dist/main/AssumeRoleProvider.js +191 -0
  51. package/dist/main/CredentialProvider.d.ts +22 -0
  52. package/dist/main/CredentialProvider.js +55 -0
  53. package/dist/main/Credentials.d.ts +22 -0
  54. package/dist/main/Credentials.js +45 -0
  55. package/dist/main/IamAwsProvider.d.ts +27 -0
  56. package/dist/main/IamAwsProvider.js +198 -0
  57. package/dist/main/errors.d.ts +82 -0
  58. package/dist/main/errors.js +138 -0
  59. package/dist/main/helpers.d.ts +156 -0
  60. package/dist/main/helpers.js +233 -0
  61. package/dist/main/internal/async.d.ts +9 -0
  62. package/dist/main/internal/async.js +24 -0
  63. package/dist/main/internal/callbackify.d.ts +1 -0
  64. package/dist/main/internal/callbackify.js +21 -0
  65. package/dist/main/internal/client.d.ts +394 -0
  66. package/dist/main/internal/client.js +3014 -0
  67. package/dist/main/internal/copy-conditions.d.ts +10 -0
  68. package/dist/main/internal/copy-conditions.js +31 -0
  69. package/dist/main/internal/extensions.d.ts +18 -0
  70. package/dist/main/internal/extensions.js +122 -0
  71. package/dist/main/internal/helper.d.ts +177 -0
  72. package/dist/main/internal/helper.js +608 -0
  73. package/dist/main/internal/join-host-port.d.ts +11 -0
  74. package/dist/main/internal/join-host-port.js +29 -0
  75. package/dist/main/internal/post-policy.d.ts +17 -0
  76. package/dist/main/internal/post-policy.js +107 -0
  77. package/dist/main/internal/request.d.ts +11 -0
  78. package/dist/main/internal/request.js +83 -0
  79. package/dist/main/internal/response.d.ts +8 -0
  80. package/dist/main/internal/response.js +24 -0
  81. package/dist/main/internal/s3-endpoints.d.ts +38 -0
  82. package/dist/main/internal/s3-endpoints.js +73 -0
  83. package/dist/main/internal/type.d.ts +482 -0
  84. package/dist/main/internal/type.js +42 -0
  85. package/dist/main/internal/xml-parser.d.ts +93 -0
  86. package/dist/main/internal/xml-parser.js +849 -0
  87. package/dist/main/notification.d.ts +58 -0
  88. package/dist/main/notification.js +230 -0
  89. package/dist/main/s3.d.ts +40 -0
  90. package/dist/main/s3.js +117 -0
  91. package/dist/main/signing.d.ts +5 -0
  92. package/dist/main/signing.js +269 -0
  93. package/package.json +146 -39
  94. package/src/AssumeRoleProvider.ts +262 -0
  95. package/src/CredentialProvider.ts +54 -0
  96. package/src/Credentials.ts +44 -0
  97. package/src/IamAwsProvider.ts +234 -0
  98. package/src/errors.ts +120 -0
  99. package/src/helpers.ts +354 -0
  100. package/src/internal/async.ts +14 -0
  101. package/src/internal/callbackify.ts +19 -0
  102. package/src/internal/client.ts +3412 -0
  103. package/src/internal/copy-conditions.ts +30 -0
  104. package/src/internal/extensions.ts +140 -0
  105. package/src/internal/helper.ts +606 -0
  106. package/src/internal/join-host-port.ts +23 -0
  107. package/src/internal/post-policy.ts +99 -0
  108. package/src/internal/request.ts +102 -0
  109. package/src/internal/response.ts +26 -0
  110. package/src/internal/s3-endpoints.ts +70 -0
  111. package/src/internal/type.ts +577 -0
  112. package/src/internal/xml-parser.ts +871 -0
  113. package/src/notification.ts +254 -0
  114. package/src/s3.ts +155 -0
  115. package/src/signing.ts +325 -0
  116. package/lib/index.js +0 -450
  117. package/lib/index.js.map +0 -7
  118. package/lib/perfTest.js +0 -91
  119. package/lib/perfTest.js.map +0 -7
@@ -0,0 +1,30 @@
1
+ export class CopyConditions {
2
+ public modified = ''
3
+ public unmodified = ''
4
+ public matchETag = ''
5
+ public matchETagExcept = ''
6
+
7
+ setModified(date: Date): void {
8
+ if (!(date instanceof Date)) {
9
+ throw new TypeError('date must be of type Date')
10
+ }
11
+
12
+ this.modified = date.toUTCString()
13
+ }
14
+
15
+ setUnmodified(date: Date): void {
16
+ if (!(date instanceof Date)) {
17
+ throw new TypeError('date must be of type Date')
18
+ }
19
+
20
+ this.unmodified = date.toUTCString()
21
+ }
22
+
23
+ setMatchETag(etag: string): void {
24
+ this.matchETag = etag
25
+ }
26
+
27
+ setMatchETagExcept(etag: string): void {
28
+ this.matchETagExcept = etag
29
+ }
30
+ }
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Hanzo S3 Javascript Library for Amazon S3 Compatible Cloud Storage, (C) 2020 Hanzo AI, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ import * as stream from 'node:stream'
18
+
19
+ import * as errors from '../errors.ts'
20
+ import type { TypedClient } from './client.ts'
21
+ import { isBoolean, isString, isValidBucketName, isValidPrefix, uriEscape } from './helper.ts'
22
+ import { readAsString } from './response.ts'
23
+ import type { BucketItemWithMetadata, BucketStream } from './type.ts'
24
+ import { parseListObjectsV2WithMetadata } from './xml-parser.ts'
25
+
26
+ export class Extensions {
27
+ private readonly client: TypedClient
28
+
29
+ constructor(client: TypedClient) {
30
+ this.client = client
31
+ }
32
+
33
+ /**
34
+ * List the objects in the bucket using S3 ListObjects V2 With Metadata
35
+ *
36
+ * @param bucketName - name of the bucket
37
+ * @param prefix - the prefix of the objects that should be listed (optional, default `''`)
38
+ * @param recursive - `true` indicates recursive style listing and `false` indicates directory style listing delimited by '/'. (optional, default `false`)
39
+ * @param startAfter - Specifies the key to start after when listing objects in a bucket. (optional, default `''`)
40
+ * @returns stream emitting the objects in the bucket, the object is of the format:
41
+ */
42
+ public listObjectsV2WithMetadata(
43
+ bucketName: string,
44
+ prefix?: string,
45
+ recursive?: boolean,
46
+ startAfter?: string,
47
+ ): BucketStream<BucketItemWithMetadata> {
48
+ if (prefix === undefined) {
49
+ prefix = ''
50
+ }
51
+ if (recursive === undefined) {
52
+ recursive = false
53
+ }
54
+ if (startAfter === undefined) {
55
+ startAfter = ''
56
+ }
57
+ if (!isValidBucketName(bucketName)) {
58
+ throw new errors.InvalidBucketNameError('Invalid bucket name: ' + bucketName)
59
+ }
60
+ if (!isValidPrefix(prefix)) {
61
+ throw new errors.InvalidPrefixError(`Invalid prefix : ${prefix}`)
62
+ }
63
+ if (!isString(prefix)) {
64
+ throw new TypeError('prefix should be of type "string"')
65
+ }
66
+ if (!isBoolean(recursive)) {
67
+ throw new TypeError('recursive should be of type "boolean"')
68
+ }
69
+ if (!isString(startAfter)) {
70
+ throw new TypeError('startAfter should be of type "string"')
71
+ }
72
+
73
+ // if recursive is false set delimiter to '/'
74
+ const delimiter = recursive ? '' : '/'
75
+ return stream.Readable.from(this.listObjectsV2WithMetadataGen(bucketName, prefix, delimiter, startAfter), {
76
+ objectMode: true,
77
+ })
78
+ }
79
+
80
+ private async *listObjectsV2WithMetadataGen(
81
+ bucketName: string,
82
+ prefix: string,
83
+ delimiter: string,
84
+ startAfter: string,
85
+ ): AsyncIterable<BucketItemWithMetadata> {
86
+ let ended = false
87
+ let continuationToken = ''
88
+ do {
89
+ const result = await this.listObjectsV2WithMetadataQuery(
90
+ bucketName,
91
+ prefix,
92
+ continuationToken,
93
+ delimiter,
94
+ startAfter,
95
+ )
96
+ ended = !result.isTruncated
97
+ continuationToken = result.nextContinuationToken
98
+ for (const obj of result.objects) {
99
+ yield obj
100
+ }
101
+ } while (!ended)
102
+ }
103
+
104
+ private async listObjectsV2WithMetadataQuery(
105
+ bucketName: string,
106
+ prefix: string,
107
+ continuationToken: string,
108
+ delimiter: string,
109
+ startAfter: string,
110
+ ) {
111
+ const queries = []
112
+
113
+ // Call for listing objects v2 API
114
+ queries.push(`list-type=2`)
115
+ queries.push(`encoding-type=url`)
116
+ // escape every value in query string, except maxKeys
117
+ queries.push(`prefix=${uriEscape(prefix)}`)
118
+ queries.push(`delimiter=${uriEscape(delimiter)}`)
119
+ queries.push(`metadata=true`)
120
+
121
+ if (continuationToken) {
122
+ continuationToken = uriEscape(continuationToken)
123
+ queries.push(`continuation-token=${continuationToken}`)
124
+ }
125
+ // Set start-after
126
+ if (startAfter) {
127
+ startAfter = uriEscape(startAfter)
128
+ queries.push(`start-after=${startAfter}`)
129
+ }
130
+ queries.push(`max-keys=1000`)
131
+ queries.sort()
132
+ let query = ''
133
+ if (queries.length > 0) {
134
+ query = `${queries.join('&')}`
135
+ }
136
+ const method = 'GET'
137
+ const res = await this.client.makeRequestAsync({ method, bucketName, query })
138
+ return parseListObjectsV2WithMetadata(await readAsString(res))
139
+ }
140
+ }