@wener/common 2.0.5 → 2.0.6
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/lib/ai/qwen3vl/index.js +1 -1
- package/lib/ai/qwen3vl/utils.js +15 -15
- package/lib/ai/vision/DocLayoutElementTypeSchema.js +22 -22
- package/lib/ai/vision/ImageAnnotationSchema.js +63 -47
- package/lib/ai/vision/index.js +2 -2
- package/lib/ai/vision/resolveImageAnnotation.js +81 -95
- package/lib/cn/ChineseResidentIdNo.js +55 -41
- package/lib/cn/ChineseResidentIdNo.mod.js +6 -1
- package/lib/cn/ChineseResidentIdNo.test.js +22 -21
- package/lib/cn/DivisionCode.js +220 -235
- package/lib/cn/DivisionCode.mod.js +6 -1
- package/lib/cn/DivisionCode.test.js +92 -121
- package/lib/cn/Mod11.js +18 -37
- package/lib/cn/Mod31.js +23 -41
- package/lib/cn/UnifiedSocialCreditCode.js +143 -137
- package/lib/cn/UnifiedSocialCreditCode.mod.js +6 -1
- package/lib/cn/UnifiedSocialCreditCode.test.js +21 -15
- package/lib/cn/formatChineseAmount.js +46 -71
- package/lib/cn/index.js +6 -6
- package/lib/cn/mod.js +5 -3
- package/lib/cn/parseChineseNumber.js +81 -85
- package/lib/cn/parseChineseNumber.test.js +183 -261
- package/lib/cn/pinyin/cartesianProduct.js +19 -19
- package/lib/cn/pinyin/cartesianProduct.test.js +78 -178
- package/lib/cn/pinyin/loader.js +13 -11
- package/lib/cn/pinyin/preload.js +2 -1
- package/lib/cn/pinyin/toPinyin.test.js +149 -161
- package/lib/cn/pinyin/toPinyinPure.js +28 -23
- package/lib/cn/pinyin/transform.js +11 -11
- package/lib/cn/types.d.js +2 -2
- package/lib/consola/createStandardConsolaReporter.js +14 -15
- package/lib/consola/formatLogObject.js +149 -133
- package/lib/consola/formatLogObject.test.js +167 -178
- package/lib/consola/index.js +2 -2
- package/lib/data/formatSort.js +14 -12
- package/lib/data/formatSort.test.js +33 -33
- package/lib/data/index.js +3 -3
- package/lib/data/maybeNumber.js +23 -23
- package/lib/data/parseSort.js +75 -68
- package/lib/data/parseSort.test.js +196 -187
- package/lib/data/resolvePagination.js +38 -39
- package/lib/data/resolvePagination.test.js +228 -218
- package/lib/data/types.d.js +2 -2
- package/lib/dayjs/dayjs.js +20 -20
- package/lib/dayjs/formatDuration.js +56 -56
- package/lib/dayjs/formatDuration.test.js +63 -77
- package/lib/dayjs/index.js +4 -4
- package/lib/dayjs/parseDuration.js +21 -26
- package/lib/dayjs/parseRelativeTime.js +65 -66
- package/lib/dayjs/parseRelativeTime.test.js +227 -243
- package/lib/dayjs/resolveRelativeTime.js +73 -72
- package/lib/dayjs/resolveRelativeTime.test.js +296 -307
- package/lib/decimal/index.js +1 -1
- package/lib/decimal/parseDecimal.js +12 -12
- package/lib/drain3/Drain.js +303 -338
- package/lib/drain3/LogCluster.js +25 -25
- package/lib/drain3/Node.js +24 -24
- package/lib/drain3/TemplateMiner.js +197 -196
- package/lib/drain3/index.js +5 -5
- package/lib/drain3/persistence/FilePersistence.js +19 -19
- package/lib/drain3/persistence/MemoryPersistence.js +8 -8
- package/lib/drain3/persistence/PersistenceHandler.js +2 -2
- package/lib/drain3/types.js +2 -2
- package/lib/emittery/emitter.js +7 -7
- package/lib/emittery/index.js +1 -1
- package/lib/foundation/schema/SexType.js +15 -12
- package/lib/foundation/schema/index.js +1 -1
- package/lib/foundation/schema/parseSexType.js +15 -16
- package/lib/foundation/schema/types.js +8 -6
- package/lib/fs/FileSystemError.js +18 -18
- package/lib/fs/IFileSystem.d.js +2 -2
- package/lib/fs/MemoryFileSystem.test.js +172 -181
- package/lib/fs/createBrowserFileSystem.js +222 -235
- package/lib/fs/createMemoryFileSystem.js +472 -510
- package/lib/fs/createSandboxFileSystem.js +102 -101
- package/lib/fs/createWebDavFileSystem.js +162 -149
- package/lib/fs/createWebFileSystem.js +197 -220
- package/lib/fs/findMimeType.js +14 -14
- package/lib/fs/index.js +7 -7
- package/lib/fs/minio/createMinioFileSystem.js +959 -956
- package/lib/fs/minio/index.js +1 -1
- package/lib/fs/orpc/FileSystemContract.js +57 -57
- package/lib/fs/orpc/createContractClientFileSystem.js +88 -88
- package/lib/fs/orpc/index.js +2 -2
- package/lib/fs/orpc/server/createFileSystemContractImpl.js +62 -60
- package/lib/fs/orpc/server/index.js +1 -1
- package/lib/fs/s3/createS3MiniFileSystem.js +756 -737
- package/lib/fs/s3/index.js +1 -1
- package/lib/fs/s3/s3mini.test.js +524 -553
- package/lib/fs/scandir.js +56 -56
- package/lib/fs/server/createDatabaseFileSystem.js +834 -741
- package/lib/fs/server/createNodeFileSystem.js +407 -405
- package/lib/fs/server/dbfs.test.js +201 -214
- package/lib/fs/server/index.js +1 -1
- package/lib/fs/server/loadTestDatabase.js +40 -43
- package/lib/fs/tests/runFileSystemTest.js +352 -316
- package/lib/fs/types.js +17 -20
- package/lib/fs/utils/getFileUrl.js +24 -30
- package/lib/fs/utils.js +17 -17
- package/lib/fs/webdav/index.js +1 -1
- package/lib/index.js +2 -2
- package/lib/jsonschema/JsonSchema.js +216 -155
- package/lib/jsonschema/JsonSchema.test.js +123 -124
- package/lib/jsonschema/forEachJsonSchema.js +41 -41
- package/lib/jsonschema/index.js +2 -2
- package/lib/jsonschema/types.d.js +2 -2
- package/lib/meta/defineFileType.js +32 -38
- package/lib/meta/defineInit.js +39 -35
- package/lib/meta/defineMetadata.js +37 -34
- package/lib/meta/defineMetadata.test.js +13 -12
- package/lib/meta/index.js +3 -3
- package/lib/orpc/createOpenApiContractClient.js +26 -24
- package/lib/orpc/createRpcContractClient.js +37 -31
- package/lib/orpc/index.js +2 -2
- package/lib/orpc/resolveLinkPlugins.js +25 -25
- package/lib/password/PHC.js +187 -189
- package/lib/password/PHC.test.js +517 -535
- package/lib/password/Password.js +85 -80
- package/lib/password/Password.test.js +330 -364
- package/lib/password/createArgon2PasswordAlgorithm.js +50 -51
- package/lib/password/createBase64PasswordAlgorithm.js +11 -11
- package/lib/password/createBcryptPasswordAlgorithm.js +20 -18
- package/lib/password/createPBKDF2PasswordAlgorithm.js +65 -52
- package/lib/password/createScryptPasswordAlgorithm.js +74 -63
- package/lib/password/index.js +5 -5
- package/lib/password/server/index.js +1 -1
- package/lib/resource/Identifiable.js +2 -2
- package/lib/resource/ListQuery.js +42 -42
- package/lib/resource/getTitleOfResource.js +5 -5
- package/lib/resource/index.js +2 -2
- package/lib/resource/schema/AnyResourceSchema.js +91 -89
- package/lib/resource/schema/BaseResourceSchema.js +26 -26
- package/lib/resource/schema/ResourceActionType.js +117 -115
- package/lib/resource/schema/ResourceStatus.js +94 -92
- package/lib/resource/schema/ResourceType.js +25 -23
- package/lib/resource/schema/index.js +5 -5
- package/lib/resource/schema/types.js +86 -55
- package/lib/resource/schema/types.test.js +16 -13
- package/lib/s3/formatS3Url.js +60 -60
- package/lib/s3/formatS3Url.test.js +238 -261
- package/lib/s3/index.js +2 -2
- package/lib/s3/parseS3Url.js +61 -60
- package/lib/s3/parseS3Url.test.js +270 -269
- package/lib/schema/SchemaRegistry.js +41 -42
- package/lib/schema/SchemaRegistry.mod.js +1 -1
- package/lib/schema/TypeSchema.d.js +2 -2
- package/lib/schema/createSchemaData.js +113 -67
- package/lib/schema/findJsonSchemaByPath.js +28 -23
- package/lib/schema/formatZodError.js +112 -131
- package/lib/schema/formatZodError.test.js +192 -195
- package/lib/schema/getSchemaCache.js +7 -7
- package/lib/schema/getSchemaOptions.js +17 -16
- package/lib/schema/index.js +6 -6
- package/lib/schema/toJsonSchema.js +195 -189
- package/lib/schema/toJsonSchema.test.js +34 -26
- package/lib/schema/validate.js +105 -96
- package/lib/tools/generateSchema.js +40 -40
- package/lib/tools/renderJsonSchemaToMarkdownDoc.js +74 -74
- package/lib/utils/buildBaseUrl.js +8 -8
- package/lib/utils/buildRedactorFormSchema.js +54 -53
- package/lib/utils/getEstimateProcessTime.js +24 -19
- package/lib/utils/index.js +3 -3
- package/lib/utils/resolveFeatureOptions.js +9 -9
- package/package.json +14 -14
- package/src/ai/vision/index.ts +2 -2
- package/src/cn/index.ts +1 -2
- package/src/consola/index.ts +1 -1
- package/src/data/index.ts +3 -4
- package/src/data/resolvePagination.ts +2 -2
- package/src/dayjs/formatDuration.ts +8 -9
- package/src/dayjs/index.ts +1 -1
- package/src/dayjs/parseRelativeTime.ts +1 -1
- package/src/dayjs/resolveRelativeTime.ts +1 -1
- package/src/drain3/Drain.test.ts +2 -2
- package/src/drain3/index.ts +2 -4
- package/src/fs/createWebDavFileSystem.ts +2 -7
- package/src/fs/createWebFileSystem.ts +1 -1
- package/src/fs/index.ts +4 -4
- package/src/fs/minio/createMinioFileSystem.ts +2 -2
- package/src/fs/minio/index.ts +1 -1
- package/src/fs/s3/createS3MiniFileSystem.ts +1 -1
- package/src/fs/server/createDatabaseFileSystem.ts +84 -120
- package/src/fs/server/dbfs.test.ts +14 -10
- package/src/fs/server/index.ts +1 -0
- package/src/fs/server/loadTestDatabase.ts +8 -119
- package/src/jsonschema/index.ts +1 -1
- package/src/meta/index.ts +2 -3
- package/src/orm/createSqliteDialect.ts +17 -0
- package/src/orm/index.ts +1 -0
- package/src/orpc/createOpenApiContractClient.ts +1 -1
- package/src/orpc/index.ts +1 -1
- package/src/password/createArgon2PasswordAlgorithm.ts +1 -1
- package/src/password/index.ts +2 -2
- package/src/resource/index.ts +3 -3
- package/src/resource/schema/index.ts +4 -4
- package/src/s3/index.ts +1 -1
- package/src/schema/SchemaRegistry.ts +1 -1
- package/src/schema/createSchemaData.ts +1 -1
- package/src/schema/findJsonSchemaByPath.ts +1 -1
- package/src/schema/index.ts +5 -5
- package/src/schema/validate.ts +1 -1
- package/src/utils/buildRedactorFormSchema.ts +1 -1
- package/src/utils/formatNumber.ts +18 -0
- package/src/utils/formatPercent.ts +17 -0
- package/src/utils/index.ts +3 -3
- package/src/utils/resolveFeatureOptions.ts +1 -1
|
@@ -1,262 +1,239 @@
|
|
|
1
|
-
import { describe, expect, it } from
|
|
2
|
-
import { formatS3Url } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
expect(function () {
|
|
240
|
-
return formatS3Url(options);
|
|
241
|
-
}).not.toThrow();
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
it("should handle pathname concatenation correctly in path style", function () {
|
|
245
|
-
var options = {
|
|
246
|
-
endpoint: "https://s3.amazonaws.com/path/to/something",
|
|
247
|
-
bucket: "my-bucket",
|
|
248
|
-
pathStyle: true
|
|
249
|
-
};
|
|
250
|
-
var result = formatS3Url(options);
|
|
251
|
-
expect(result).toBe("https://s3.amazonaws.com/my-bucket/path/to/something");
|
|
252
|
-
});
|
|
253
|
-
it("should handle URL with existing pathname in virtual hosted style", function () {
|
|
254
|
-
var options = {
|
|
255
|
-
endpoint: "https://s3.amazonaws.com/path/to/something",
|
|
256
|
-
bucket: "my-bucket",
|
|
257
|
-
pathStyle: false
|
|
258
|
-
};
|
|
259
|
-
var result = formatS3Url(options);
|
|
260
|
-
expect(result).toBe("https://my-bucket.s3.amazonaws.com/path/to/something");
|
|
261
|
-
});
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { formatS3Url } from './formatS3Url.js';
|
|
3
|
+
|
|
4
|
+
describe('formatS3Url', () => {
|
|
5
|
+
it('should format basic S3 URL with default endpoint', () => {
|
|
6
|
+
var options = {
|
|
7
|
+
endpoint: 's3.amazonaws.com',
|
|
8
|
+
};
|
|
9
|
+
var result = formatS3Url(options);
|
|
10
|
+
expect(result).toBe('https://s3.amazonaws.com/');
|
|
11
|
+
});
|
|
12
|
+
it('should format S3 URL with custom endpoint', () => {
|
|
13
|
+
var options = {
|
|
14
|
+
endpoint: 'custom-s3.com',
|
|
15
|
+
};
|
|
16
|
+
var result = formatS3Url(options);
|
|
17
|
+
expect(result).toBe('https://custom-s3.com/');
|
|
18
|
+
});
|
|
19
|
+
it('should format S3 URL with HTTP protocol', () => {
|
|
20
|
+
var options = {
|
|
21
|
+
endpoint: 's3.amazonaws.com',
|
|
22
|
+
useSsl: false,
|
|
23
|
+
};
|
|
24
|
+
var result = formatS3Url(options);
|
|
25
|
+
expect(result).toBe('http://s3.amazonaws.com/');
|
|
26
|
+
});
|
|
27
|
+
it('should format S3 URL with port', () => {
|
|
28
|
+
var options = {
|
|
29
|
+
endpoint: 's3.amazonaws.com',
|
|
30
|
+
port: 9000,
|
|
31
|
+
};
|
|
32
|
+
var result = formatS3Url(options);
|
|
33
|
+
expect(result).toBe('https://s3.amazonaws.com:9000/');
|
|
34
|
+
});
|
|
35
|
+
it('should format S3 URL with bucket in path style', () => {
|
|
36
|
+
var options = {
|
|
37
|
+
endpoint: 's3.amazonaws.com',
|
|
38
|
+
bucket: 'my-bucket',
|
|
39
|
+
pathStyle: true,
|
|
40
|
+
};
|
|
41
|
+
var result = formatS3Url(options);
|
|
42
|
+
expect(result).toBe('https://s3.amazonaws.com/my-bucket/');
|
|
43
|
+
});
|
|
44
|
+
it('should format S3 URL with bucket in virtual hosted style', () => {
|
|
45
|
+
var options = {
|
|
46
|
+
endpoint: 's3.amazonaws.com',
|
|
47
|
+
bucket: 'my-bucket',
|
|
48
|
+
pathStyle: false,
|
|
49
|
+
};
|
|
50
|
+
var result = formatS3Url(options);
|
|
51
|
+
expect(result).toBe('https://my-bucket.s3.amazonaws.com/');
|
|
52
|
+
});
|
|
53
|
+
it('should format S3 URL with credentials', () => {
|
|
54
|
+
var options = {
|
|
55
|
+
endpoint: 's3.amazonaws.com',
|
|
56
|
+
accessKeyId: 'user',
|
|
57
|
+
secretAccessKey: 'pass',
|
|
58
|
+
};
|
|
59
|
+
var result = formatS3Url(options, {
|
|
60
|
+
credentials: true,
|
|
61
|
+
});
|
|
62
|
+
expect(result).toBe('https://user:pass@s3.amazonaws.com/');
|
|
63
|
+
});
|
|
64
|
+
it('should format S3 URL with credentials and special characters', () => {
|
|
65
|
+
var options = {
|
|
66
|
+
endpoint: 's3.amazonaws.com',
|
|
67
|
+
accessKeyId: 'user@example.com',
|
|
68
|
+
secretAccessKey: 'pass/word',
|
|
69
|
+
};
|
|
70
|
+
var result = formatS3Url(options, {
|
|
71
|
+
credentials: true,
|
|
72
|
+
});
|
|
73
|
+
expect(result).toBe('https://user%40example.com:pass%2Fword@s3.amazonaws.com/');
|
|
74
|
+
});
|
|
75
|
+
it('should format S3 URL with region in query parameters', () => {
|
|
76
|
+
var options = {
|
|
77
|
+
endpoint: 's3.amazonaws.com',
|
|
78
|
+
region: 'us-east-1',
|
|
79
|
+
};
|
|
80
|
+
var result = formatS3Url(options, {
|
|
81
|
+
useParams: true,
|
|
82
|
+
});
|
|
83
|
+
expect(result).toBe('https://s3.amazonaws.com/?region=us-east-1');
|
|
84
|
+
});
|
|
85
|
+
it('should format S3 URL with pathStyle in query parameters', () => {
|
|
86
|
+
var options = {
|
|
87
|
+
endpoint: 's3.amazonaws.com',
|
|
88
|
+
pathStyle: true,
|
|
89
|
+
};
|
|
90
|
+
var result = formatS3Url(options, {
|
|
91
|
+
useParams: true,
|
|
92
|
+
});
|
|
93
|
+
expect(result).toBe('https://s3.amazonaws.com/?pathStyle=true');
|
|
94
|
+
});
|
|
95
|
+
it('should format S3 URL with all parameters', () => {
|
|
96
|
+
var options = {
|
|
97
|
+
endpoint: 's3.amazonaws.com',
|
|
98
|
+
accessKeyId: 'user',
|
|
99
|
+
secretAccessKey: 'pass',
|
|
100
|
+
region: 'us-east-1',
|
|
101
|
+
port: 9000,
|
|
102
|
+
bucket: 'my-bucket',
|
|
103
|
+
pathStyle: true,
|
|
104
|
+
useSsl: true,
|
|
105
|
+
};
|
|
106
|
+
var result = formatS3Url(options, {
|
|
107
|
+
credentials: true,
|
|
108
|
+
useParams: true,
|
|
109
|
+
});
|
|
110
|
+
expect(result).toBe('https://user:pass@s3.amazonaws.com:9000/my-bucket/?region=us-east-1&pathStyle=true');
|
|
111
|
+
});
|
|
112
|
+
it('should handle full URL as endpoint', () => {
|
|
113
|
+
var options = {
|
|
114
|
+
endpoint: 'https://custom-s3.com:9000',
|
|
115
|
+
bucket: 'my-bucket',
|
|
116
|
+
pathStyle: true,
|
|
117
|
+
};
|
|
118
|
+
var result = formatS3Url(options);
|
|
119
|
+
expect(result).toBe('https://custom-s3.com:9000/my-bucket/');
|
|
120
|
+
});
|
|
121
|
+
it('should handle complex virtual hosted style with existing bucket in hostname', () => {
|
|
122
|
+
var options = {
|
|
123
|
+
endpoint: 'my-bucket.s3.amazonaws.com',
|
|
124
|
+
bucket: 'my-bucket',
|
|
125
|
+
pathStyle: false,
|
|
126
|
+
};
|
|
127
|
+
var result = formatS3Url(options);
|
|
128
|
+
expect(result).toBe('https://my-bucket.s3.amazonaws.com/');
|
|
129
|
+
});
|
|
130
|
+
it('should throw error for missing endpoint', () => {
|
|
131
|
+
var options = {};
|
|
132
|
+
expect(() => formatS3Url(options)).toThrow('Endpoint is required');
|
|
133
|
+
});
|
|
134
|
+
it('should handle endpoint without protocol by adding https://', () => {
|
|
135
|
+
var options = {
|
|
136
|
+
endpoint: 'custom-s3.com',
|
|
137
|
+
};
|
|
138
|
+
var result = formatS3Url(options);
|
|
139
|
+
expect(result).toBe('https://custom-s3.com/');
|
|
140
|
+
});
|
|
141
|
+
it('should throw error for missing credentials when credentials=true', () => {
|
|
142
|
+
var options = {
|
|
143
|
+
endpoint: 's3.amazonaws.com',
|
|
144
|
+
accessKeyId: 'user',
|
|
145
|
+
};
|
|
146
|
+
expect(() =>
|
|
147
|
+
formatS3Url(options, {
|
|
148
|
+
credentials: true,
|
|
149
|
+
}),
|
|
150
|
+
).toThrow('Access Key ID and Secret Access Key are required for credentials');
|
|
151
|
+
});
|
|
152
|
+
it('should throw error for invalid port', () => {
|
|
153
|
+
var options = {
|
|
154
|
+
endpoint: 's3.amazonaws.com',
|
|
155
|
+
port: 99999,
|
|
156
|
+
};
|
|
157
|
+
expect(() => formatS3Url(options)).toThrow('Port must be a valid number between 1 and 65535');
|
|
158
|
+
});
|
|
159
|
+
it('should throw error for invalid bucket name', () => {
|
|
160
|
+
var options = {
|
|
161
|
+
endpoint: 's3.amazonaws.com',
|
|
162
|
+
bucket: 'Invalid Bucket Name',
|
|
163
|
+
};
|
|
164
|
+
expect(() => formatS3Url(options)).toThrow('Invalid bucket name: Invalid Bucket Name');
|
|
165
|
+
});
|
|
166
|
+
it('should throw error for bucket name with consecutive dots', () => {
|
|
167
|
+
var options = {
|
|
168
|
+
endpoint: 's3.amazonaws.com',
|
|
169
|
+
bucket: 'my..bucket',
|
|
170
|
+
};
|
|
171
|
+
expect(() => formatS3Url(options)).toThrow('Invalid bucket name: my..bucket');
|
|
172
|
+
});
|
|
173
|
+
it('should throw error for bucket name with hyphen at start', () => {
|
|
174
|
+
var options = {
|
|
175
|
+
endpoint: 's3.amazonaws.com',
|
|
176
|
+
bucket: '-mybucket',
|
|
177
|
+
};
|
|
178
|
+
expect(() => formatS3Url(options)).toThrow('Invalid bucket name: -mybucket');
|
|
179
|
+
});
|
|
180
|
+
it('should throw error for bucket name with hyphen at end', () => {
|
|
181
|
+
var options = {
|
|
182
|
+
endpoint: 's3.amazonaws.com',
|
|
183
|
+
bucket: 'mybucket-',
|
|
184
|
+
};
|
|
185
|
+
expect(() => formatS3Url(options)).toThrow('Invalid bucket name: mybucket-');
|
|
186
|
+
});
|
|
187
|
+
it('should handle bucket name with dot-hyphen (currently allowed)', () => {
|
|
188
|
+
var options = {
|
|
189
|
+
endpoint: 's3.amazonaws.com',
|
|
190
|
+
bucket: 'my.bucket-name',
|
|
191
|
+
pathStyle: true,
|
|
192
|
+
};
|
|
193
|
+
var result = formatS3Url(options);
|
|
194
|
+
expect(result).toBe('https://s3.amazonaws.com/my.bucket-name/');
|
|
195
|
+
});
|
|
196
|
+
it('should throw error for bucket name that is too short', () => {
|
|
197
|
+
var options = {
|
|
198
|
+
endpoint: 's3.amazonaws.com',
|
|
199
|
+
bucket: 'ab',
|
|
200
|
+
};
|
|
201
|
+
expect(() => formatS3Url(options)).toThrow('Invalid bucket name: ab');
|
|
202
|
+
});
|
|
203
|
+
it('should throw error for bucket name that is too long', () => {
|
|
204
|
+
var options = {
|
|
205
|
+
endpoint: 's3.amazonaws.com',
|
|
206
|
+
bucket: 'a'.repeat(64),
|
|
207
|
+
};
|
|
208
|
+
expect(() => formatS3Url(options)).toThrow('Invalid bucket name: ' + 'a'.repeat(64));
|
|
209
|
+
});
|
|
210
|
+
it('should handle valid bucket names with various formats', () => {
|
|
211
|
+
var validBuckets = ['my-bucket', 'my.bucket', 'mybucket123', '123bucket', 'test-bucket-123'];
|
|
212
|
+
validBuckets.forEach((bucket) => {
|
|
213
|
+
var options = {
|
|
214
|
+
endpoint: 's3.amazonaws.com',
|
|
215
|
+
bucket: bucket,
|
|
216
|
+
pathStyle: true,
|
|
217
|
+
};
|
|
218
|
+
expect(() => formatS3Url(options)).not.toThrow();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
it('should handle pathname concatenation correctly in path style', () => {
|
|
222
|
+
var options = {
|
|
223
|
+
endpoint: 'https://s3.amazonaws.com/path/to/something',
|
|
224
|
+
bucket: 'my-bucket',
|
|
225
|
+
pathStyle: true,
|
|
226
|
+
};
|
|
227
|
+
var result = formatS3Url(options);
|
|
228
|
+
expect(result).toBe('https://s3.amazonaws.com/my-bucket/path/to/something');
|
|
229
|
+
});
|
|
230
|
+
it('should handle URL with existing pathname in virtual hosted style', () => {
|
|
231
|
+
var options = {
|
|
232
|
+
endpoint: 'https://s3.amazonaws.com/path/to/something',
|
|
233
|
+
bucket: 'my-bucket',
|
|
234
|
+
pathStyle: false,
|
|
235
|
+
};
|
|
236
|
+
var result = formatS3Url(options);
|
|
237
|
+
expect(result).toBe('https://my-bucket.s3.amazonaws.com/path/to/something');
|
|
238
|
+
});
|
|
262
239
|
});
|
package/lib/s3/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { formatS3Url } from './formatS3Url.js';
|
|
2
|
+
export { parseS3Url } from './parseS3Url.js';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/lib/s3/parseS3Url.js
CHANGED
|
@@ -1,65 +1,66 @@
|
|
|
1
|
-
import { parseBoolean } from
|
|
1
|
+
import { parseBoolean } from '@wener/utils';
|
|
2
|
+
|
|
2
3
|
function isValidIpAddress(hostname) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
|
|
5
|
+
const ipv6Regex = /^\[([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}]$/;
|
|
6
|
+
return ipv4Regex.test(hostname) || ipv6Regex.test(hostname);
|
|
6
7
|
}
|
|
7
8
|
export function parseS3Url({ url = process.env.S3_URL, ...rest } = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
9
|
+
if (!url) return undefined;
|
|
10
|
+
const normalizedUrl = url.startsWith('s3://') ? url.replace(/^s3:\/\//, 'https://') : url;
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = new URL(normalizedUrl);
|
|
14
|
+
} catch (_error) {
|
|
15
|
+
throw new Error(`Invalid S3 URL: ${url}`);
|
|
16
|
+
}
|
|
17
|
+
const pathStyleParam = parsed.searchParams.get('pathStyle');
|
|
18
|
+
let pathStyle = rest.pathStyle;
|
|
19
|
+
pathStyle ??= parseBoolean(pathStyleParam, true);
|
|
20
|
+
// Auto-detect path style for IP addresses
|
|
21
|
+
if (pathStyle === undefined && isValidIpAddress(parsed.hostname)) {
|
|
22
|
+
pathStyle = true;
|
|
23
|
+
}
|
|
24
|
+
const result = {
|
|
25
|
+
accessKeyId: parsed.username || undefined,
|
|
26
|
+
secretAccessKey: parsed.password || undefined,
|
|
27
|
+
endpoint: parsed.hostname,
|
|
28
|
+
port: parsed.port ? Number(parsed.port) : undefined,
|
|
29
|
+
useSsl: parsed.protocol === 'https:',
|
|
30
|
+
region: parsed.searchParams.get('region') || undefined,
|
|
31
|
+
pathStyle,
|
|
32
|
+
};
|
|
33
|
+
if (!result.port) {
|
|
34
|
+
if (result.useSsl) {
|
|
35
|
+
result.port = 443;
|
|
36
|
+
} else {
|
|
37
|
+
result.port = 80;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const pathSegments = parsed.pathname.split('/').filter(Boolean);
|
|
41
|
+
const awsVirtualHostMatch = parsed.hostname.match(/^(.*?)\.s3[.-]([a-z0-9-]+)?\.?amazonaws\.com$/);
|
|
42
|
+
if (result.pathStyle) {
|
|
43
|
+
result.bucket = pathSegments[0];
|
|
44
|
+
} else if (awsVirtualHostMatch) {
|
|
45
|
+
result.bucket = awsVirtualHostMatch[1];
|
|
46
|
+
result.endpoint = parsed.hostname;
|
|
47
|
+
if (!result.region && awsVirtualHostMatch[2]) {
|
|
48
|
+
result.region = awsVirtualHostMatch[2];
|
|
49
|
+
}
|
|
50
|
+
result.pathStyle = false;
|
|
51
|
+
} else {
|
|
52
|
+
result.bucket = pathSegments[0];
|
|
53
|
+
if (result.pathStyle === undefined) {
|
|
54
|
+
result.pathStyle = true;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Type-safe property assignment
|
|
58
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
59
|
+
if (value !== undefined && value !== null && key in result) {
|
|
60
|
+
result[key] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
//# sourceMappingURL=parseS3Url.js.map
|
|
66
|
+
//# sourceMappingURL=parseS3Url.js.map
|