@8ms/helpers 3.2.6 → 3.2.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/AGENTS.md +20 -0
- package/dist/aws/s3/{server → _shared}/awsS3File.cjs +1 -1
- package/dist/aws/s3/{server → _shared}/awsS3File.d.cts +1 -1
- package/dist/aws/s3/{server → _shared}/awsS3File.d.mts +1 -1
- package/dist/aws/s3/{server → _shared}/awsS3File.mjs +1 -1
- package/dist/aws/s3/_shared/index.cjs +3 -0
- package/dist/aws/s3/_shared/index.d.cts +3 -0
- package/dist/aws/s3/_shared/index.d.mts +3 -0
- package/dist/aws/s3/_shared/index.mjs +2 -0
- package/dist/aws/s3/_shared/types.cjs +0 -0
- package/dist/aws/s3/_shared/types.d.cts +35 -0
- package/dist/aws/s3/_shared/types.d.mts +35 -0
- package/dist/aws/s3/_shared/types.mjs +1 -0
- package/dist/aws/s3/server/AwsS3.cjs +83 -4
- package/dist/aws/s3/server/AwsS3.d.cts +19 -26
- package/dist/aws/s3/server/AwsS3.d.mts +19 -26
- package/dist/aws/s3/server/AwsS3.mjs +81 -2
- package/dist/aws/s3/server/index.cjs +3 -2
- package/dist/aws/s3/server/index.d.cts +4 -3
- package/dist/aws/s3/server/index.d.mts +4 -3
- package/dist/aws/s3/server/index.mjs +2 -1
- package/dist/file/_shared/dataFileType.cjs +2 -0
- package/dist/file/_shared/dataFileType.d.cts +2 -0
- package/dist/file/_shared/dataFileType.d.mts +2 -0
- package/dist/file/_shared/dataFileType.mjs +2 -0
- package/dist/file/_shared/fileMimeType.cjs +2 -0
- package/dist/file/_shared/fileMimeType.mjs +2 -0
- package/dist/file/_shared/fileType.d.cts +2 -0
- package/dist/file/_shared/fileType.d.mts +2 -0
- package/dist/googleCloud/bigquery/_shared/index.d.cts +2 -2
- package/dist/googleCloud/bigquery/_shared/index.d.mts +2 -2
- package/dist/googleCloud/bigquery/_shared/types.d.cts +54 -0
- package/dist/googleCloud/bigquery/_shared/types.d.mts +54 -0
- package/dist/googleCloud/bigquery/client/index.d.cts +2 -2
- package/dist/googleCloud/bigquery/client/index.d.mts +2 -2
- package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.cjs +158 -7
- package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.d.cts +47 -31
- package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.d.mts +47 -31
- package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.mjs +158 -7
- package/dist/googleCloud/bigquery/server/index.d.cts +3 -3
- package/dist/googleCloud/bigquery/server/index.d.mts +3 -3
- package/dist/googleCloud/drive/server/GoogleCloudDrive.cjs +85 -0
- package/dist/googleCloud/drive/server/GoogleCloudDrive.d.cts +34 -0
- package/dist/googleCloud/drive/server/GoogleCloudDrive.d.mts +34 -0
- package/dist/googleCloud/drive/server/GoogleCloudDrive.mjs +85 -0
- package/dist/stream/server/index.cjs +11 -0
- package/dist/stream/server/index.d.cts +4 -1
- package/dist/stream/server/index.d.mts +4 -1
- package/dist/stream/server/index.mjs +4 -1
- package/dist/stream/server/json/logic.cjs +18 -0
- package/dist/stream/server/json/logic.d.cts +27 -0
- package/dist/stream/server/json/logic.d.mts +27 -0
- package/dist/stream/server/json/logic.mjs +16 -0
- package/dist/stream/server/json/read.cjs +46 -0
- package/dist/stream/server/json/read.d.cts +7 -0
- package/dist/stream/server/json/read.d.mts +7 -0
- package/dist/stream/server/json/read.mjs +42 -0
- package/dist/stream/server/json/write.cjs +69 -0
- package/dist/stream/server/json/write.d.cts +14 -0
- package/dist/stream/server/json/write.d.mts +14 -0
- package/dist/stream/server/json/write.mjs +63 -0
- package/dist/stream/server/sort.cjs +12 -23
- package/dist/stream/server/sort.d.cts +10 -6
- package/dist/stream/server/sort.d.mts +10 -6
- package/dist/stream/server/sort.mjs +12 -23
- package/dist/xlsx/_shared/createXlsx.cjs +12 -22
- package/dist/xlsx/_shared/createXlsx.mjs +12 -22
- package/dist/xlsx/_shared/modifyXlsx.cjs +32 -44
- package/dist/xlsx/_shared/modifyXlsx.mjs +32 -44
- package/dist/xlsx/client/index.cjs +0 -1
- package/dist/xlsx/client/index.mjs +0 -1
- package/dist/xlsx/server/index.cjs +0 -1
- package/dist/xlsx/server/index.mjs +0 -1
- package/dist/zip/_shared/ZipArchive.cjs +49 -0
- package/dist/zip/_shared/ZipArchive.d.cts +24 -0
- package/dist/zip/_shared/ZipArchive.d.mts +24 -0
- package/dist/zip/_shared/ZipArchive.mjs +48 -0
- package/dist/zip/_shared/crc32.cjs +24 -0
- package/dist/zip/_shared/crc32.d.cts +4 -0
- package/dist/zip/_shared/crc32.d.mts +4 -0
- package/dist/zip/_shared/crc32.mjs +23 -0
- package/dist/zip/_shared/deflate.cjs +21 -0
- package/dist/zip/_shared/deflate.d.cts +10 -0
- package/dist/zip/_shared/deflate.d.mts +10 -0
- package/dist/zip/_shared/deflate.mjs +19 -0
- package/dist/zip/_shared/index.cjs +12 -0
- package/dist/zip/_shared/index.d.cts +6 -0
- package/dist/zip/_shared/index.d.mts +6 -0
- package/dist/zip/_shared/index.mjs +6 -0
- package/dist/zip/_shared/readZip.cjs +63 -0
- package/dist/zip/_shared/readZip.d.cts +9 -0
- package/dist/zip/_shared/readZip.d.mts +9 -0
- package/dist/zip/_shared/readZip.mjs +62 -0
- package/dist/zip/_shared/writeZip.cjs +105 -0
- package/dist/zip/_shared/writeZip.d.cts +7 -0
- package/dist/zip/_shared/writeZip.d.mts +7 -0
- package/dist/zip/_shared/writeZip.mjs +104 -0
- package/dist/zip/client/index.cjs +12 -0
- package/dist/zip/client/index.d.cts +6 -0
- package/dist/zip/client/index.d.mts +6 -0
- package/dist/zip/client/index.mjs +6 -0
- package/dist/zip/server/index.cjs +12 -0
- package/dist/zip/server/index.d.cts +6 -0
- package/dist/zip/server/index.d.mts +6 -0
- package/dist/zip/server/index.mjs +6 -0
- package/package.json +65 -10
package/AGENTS.md
CHANGED
|
@@ -64,12 +64,32 @@ Server-only code lives in `<module>/server/`, client-only in `<module>/client/`.
|
|
|
64
64
|
|
|
65
65
|
**No bundling.** `tsdown` outputs unbundled files. Every source file maps to a dist file. Do not introduce barrel re-exports that would force consumers to load unrelated code.
|
|
66
66
|
|
|
67
|
+
**One `index.ts` per module boundary, not per subfolder.** A folder gets its own `index.ts` only when it's a public module boundary — what `tsdown`'s per-folder export generation turns into a `@8ms/helpers/<path>` subpath (`server/`, `client/`, `_shared/` folders). A subfolder created purely to split a large file into smaller ones for readability (e.g. `stream/server/json/`) is internal organisation, not a module boundary, and should not have its own `index.ts` — the nearest module-boundary `index.ts` above it imports directly from its files instead.
|
|
68
|
+
|
|
67
69
|
**Peer dependencies.** AWS SDK, Google Cloud SDK, Prisma, Drizzle, Next.js, React — all are peer deps. Never add them as direct dependencies. Import them only inside `init()` or behind a dynamic import so consumers who don't use that module pay no cost.
|
|
68
70
|
|
|
69
71
|
**TypeScript target is ES2024, module resolution is `bundler`.** Use native ES features freely. No CommonJS patterns in source files.
|
|
70
72
|
|
|
71
73
|
**No comments by default.** Only add a comment when the *why* is non-obvious (a workaround, a hidden constraint). Do not document what the code does — naming should do that.
|
|
72
74
|
|
|
75
|
+
**No single-line implicit-return function bodies.** A function or arrow function body is always a brace block with an explicit `return`, never a bare expression after `=>`. Write:
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
const toRowReadable = <T>(source: RowSource<T>): Readable =>
|
|
79
|
+
{
|
|
80
|
+
return source instanceof Readable ? source : Readable.from(source, {objectMode: true});
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
not:
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
const toRowReadable = <T>(source: RowSource<T>): Readable =>
|
|
88
|
+
source instanceof Readable ? source : Readable.from(source, {objectMode: true});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This matches the brace-on-its-own-line style already used for `if`/`for`/class bodies throughout the codebase. It applies to a function's own body, not to every inline arrow passed as a callback argument (e.g. `.then(result => callback(null, result))` is unaffected).
|
|
92
|
+
|
|
73
93
|
## Adding a new module
|
|
74
94
|
|
|
75
95
|
1. Create `src/<name>/` with an `index.ts` re-exporting the public surface.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_date__shared_date = require("../../../date/_shared/date.cjs");
|
|
3
3
|
require("../../../date/_shared/index.cjs");
|
|
4
|
-
//#region src/aws/s3/
|
|
4
|
+
//#region src/aws/s3/_shared/awsS3File.ts
|
|
5
5
|
const readFileDefault = {
|
|
6
6
|
body: void 0,
|
|
7
7
|
now: void 0,
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Modified, ReadFileResponse, readFileDefault } from "./awsS3File.cjs";
|
|
2
|
+
import { FileHeadResponse, JsonStreamOptions, Options, ReadBufferResponse, WritePresignedPostProps } from "./types.cjs";
|
|
3
|
+
export { FileHeadResponse, JsonStreamOptions, Modified, Options, ReadBufferResponse, ReadFileResponse, WritePresignedPostProps, readFileDefault };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Modified, ReadFileResponse, readFileDefault } from "./awsS3File.mjs";
|
|
2
|
+
import { FileHeadResponse, JsonStreamOptions, Options, ReadBufferResponse, WritePresignedPostProps } from "./types.mjs";
|
|
3
|
+
export { FileHeadResponse, JsonStreamOptions, Modified, Options, ReadBufferResponse, ReadFileResponse, WritePresignedPostProps, readFileDefault };
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Modified } from "./awsS3File.cjs";
|
|
2
|
+
import { RowCallback, SortCallback } from "../../../stream/server/json/logic.cjs";
|
|
3
|
+
//#region src/aws/s3/_shared/types.d.ts
|
|
4
|
+
export type Options = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export type ReadBufferResponse = Modified & {
|
|
8
|
+
buffer: any;
|
|
9
|
+
};
|
|
10
|
+
export type FileHeadResponse = {
|
|
11
|
+
exists: boolean;
|
|
12
|
+
fileType: string | null;
|
|
13
|
+
size: number;
|
|
14
|
+
modified: string;
|
|
15
|
+
etag: string | null;
|
|
16
|
+
versionId: string | null;
|
|
17
|
+
encoding: string | null;
|
|
18
|
+
cacheControl: string | null;
|
|
19
|
+
meta: Record<string, string>;
|
|
20
|
+
expires: string | null;
|
|
21
|
+
};
|
|
22
|
+
export type WritePresignedPostProps = {
|
|
23
|
+
bucket: string;
|
|
24
|
+
fields: Record<string, string>;
|
|
25
|
+
file: File | Blob;
|
|
26
|
+
key: string;
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
/** Shared options for writeJson(Gzip)Stream/readJson(Gzip)Stream. */
|
|
30
|
+
export type JsonStreamOptions<T = any> = {
|
|
31
|
+
rowCallback?: RowCallback<T>;
|
|
32
|
+
sortCallback?: SortCallback<T>;
|
|
33
|
+
awsS3Options?: Options;
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Modified } from "./awsS3File.mjs";
|
|
2
|
+
import { RowCallback, SortCallback } from "../../../stream/server/json/logic.mjs";
|
|
3
|
+
//#region src/aws/s3/_shared/types.d.ts
|
|
4
|
+
export type Options = {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export type ReadBufferResponse = Modified & {
|
|
8
|
+
buffer: any;
|
|
9
|
+
};
|
|
10
|
+
export type FileHeadResponse = {
|
|
11
|
+
exists: boolean;
|
|
12
|
+
fileType: string | null;
|
|
13
|
+
size: number;
|
|
14
|
+
modified: string;
|
|
15
|
+
etag: string | null;
|
|
16
|
+
versionId: string | null;
|
|
17
|
+
encoding: string | null;
|
|
18
|
+
cacheControl: string | null;
|
|
19
|
+
meta: Record<string, string>;
|
|
20
|
+
expires: string | null;
|
|
21
|
+
};
|
|
22
|
+
export type WritePresignedPostProps = {
|
|
23
|
+
bucket: string;
|
|
24
|
+
fields: Record<string, string>;
|
|
25
|
+
file: File | Blob;
|
|
26
|
+
key: string;
|
|
27
|
+
url: string;
|
|
28
|
+
};
|
|
29
|
+
/** Shared options for writeJson(Gzip)Stream/readJson(Gzip)Stream. */
|
|
30
|
+
export type JsonStreamOptions<T = any> = {
|
|
31
|
+
rowCallback?: RowCallback<T>;
|
|
32
|
+
sortCallback?: SortCallback<T>;
|
|
33
|
+
awsS3Options?: Options;
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,9 +3,12 @@ const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
|
3
3
|
const require__class__shared_BaseNamespace = require("../../../_class/_shared/BaseNamespace.cjs");
|
|
4
4
|
const require_date__shared_calculation = require("../../../date/_shared/calculation.cjs");
|
|
5
5
|
const require_date__shared_format = require("../../../date/_shared/format.cjs");
|
|
6
|
-
const require_aws_server_isResponse200 = require("../../server/isResponse200.cjs");
|
|
7
6
|
const require_date__shared_date = require("../../../date/_shared/date.cjs");
|
|
8
7
|
require("../../../date/_shared/index.cjs");
|
|
8
|
+
const require_aws_server_isResponse200 = require("../../server/isResponse200.cjs");
|
|
9
|
+
const require_stream_server_json_read = require("../../../stream/server/json/read.cjs");
|
|
10
|
+
const require_stream_server_json_write = require("../../../stream/server/json/write.cjs");
|
|
11
|
+
require("../../../stream/server/index.cjs");
|
|
9
12
|
const require_string__shared_getFolder = require("../../../string/_shared/getFolder.cjs");
|
|
10
13
|
const require_string__shared_getStringFromStream = require("../../../string/_shared/getStringFromStream.cjs");
|
|
11
14
|
require("../../../string/_shared/index.cjs");
|
|
@@ -16,10 +19,11 @@ require("../../../string/server/index.cjs");
|
|
|
16
19
|
const require_util_server_getBrotliCompressed = require("../../../util/server/getBrotliCompressed.cjs");
|
|
17
20
|
const require_util_server_getGzipCompressed = require("../../../util/server/getGzipCompressed.cjs");
|
|
18
21
|
require("../../../util/server/index.cjs");
|
|
19
|
-
const
|
|
22
|
+
const require_aws_s3__shared_awsS3File = require("../_shared/awsS3File.cjs");
|
|
20
23
|
require("./index.cjs");
|
|
21
24
|
let ky = require("ky");
|
|
22
25
|
ky = require_runtime.__toESM(ky);
|
|
26
|
+
let stream = require("stream");
|
|
23
27
|
//#region src/aws/s3/server/AwsS3.ts
|
|
24
28
|
var AwsS3 = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
25
29
|
init = async (config, region) => {
|
|
@@ -171,7 +175,7 @@ var AwsS3 = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
171
175
|
readBuffer = async (bucket, key) => {
|
|
172
176
|
const { GetObjectCommand } = await import("@aws-sdk/client-s3");
|
|
173
177
|
let response = {
|
|
174
|
-
...
|
|
178
|
+
...require_aws_s3__shared_awsS3File.readFileDefault,
|
|
175
179
|
buffer: void 0
|
|
176
180
|
};
|
|
177
181
|
const apiResponse = await this.client.send(new GetObjectCommand({
|
|
@@ -238,7 +242,7 @@ var AwsS3 = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
238
242
|
return response;
|
|
239
243
|
};
|
|
240
244
|
readFile = async (bucket, key, options = {}) => {
|
|
241
|
-
let response = structuredClone(
|
|
245
|
+
let response = structuredClone(require_aws_s3__shared_awsS3File.readFileDefault);
|
|
242
246
|
const today = require_date__shared_calculation.getToday();
|
|
243
247
|
try {
|
|
244
248
|
response.now = today.toUnixInteger();
|
|
@@ -258,6 +262,17 @@ var AwsS3 = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
258
262
|
}
|
|
259
263
|
return response;
|
|
260
264
|
};
|
|
265
|
+
/**
|
|
266
|
+
* Return the raw object body as a stream, without buffering it into memory.
|
|
267
|
+
*/
|
|
268
|
+
readStream = async (bucket, key, options = {}) => {
|
|
269
|
+
const { GetObjectCommand } = await import("@aws-sdk/client-s3");
|
|
270
|
+
return (await this.client.send(new GetObjectCommand({
|
|
271
|
+
Bucket: bucket,
|
|
272
|
+
Key: key,
|
|
273
|
+
...options
|
|
274
|
+
}))).Body;
|
|
275
|
+
};
|
|
261
276
|
readJson = async (bucket, key) => {
|
|
262
277
|
const apiResponse = await this.readFile(bucket, key);
|
|
263
278
|
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
@@ -271,6 +286,25 @@ var AwsS3 = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
271
286
|
}
|
|
272
287
|
return apiResponse;
|
|
273
288
|
};
|
|
289
|
+
/**
|
|
290
|
+
* Read a JSON array object back, parsing it incrementally without buffering the full document.
|
|
291
|
+
*/
|
|
292
|
+
readJsonStream = async (bucket, key, options = {}) => {
|
|
293
|
+
const source = await this.readStream(bucket, key, options.awsS3Options);
|
|
294
|
+
return require_stream_server_json_read.readJsonStream({
|
|
295
|
+
source,
|
|
296
|
+
rowCallback: options.rowCallback,
|
|
297
|
+
sortCallback: options.sortCallback
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
readJsonGzipStream = async (bucket, key, options = {}) => {
|
|
301
|
+
const source = await this.readStream(bucket, key, options.awsS3Options);
|
|
302
|
+
return require_stream_server_json_read.readJsonGzipStream({
|
|
303
|
+
source,
|
|
304
|
+
rowCallback: options.rowCallback,
|
|
305
|
+
sortCallback: options.sortCallback
|
|
306
|
+
});
|
|
307
|
+
};
|
|
274
308
|
readGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
275
309
|
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
276
310
|
if (void 0 !== apiResponse.body) apiResponse.body = await require_util_server_getGzipDecompressed.getGzipDecompressed(apiResponse.body, gzipOptions);
|
|
@@ -300,6 +334,51 @@ var AwsS3 = class extends require__class__shared_BaseNamespace.BaseNamespace {
|
|
|
300
334
|
finalData = await require_util_server_getGzipCompressed.getGzipCompressed(finalData, gzipOptions);
|
|
301
335
|
return await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
302
336
|
};
|
|
337
|
+
/**
|
|
338
|
+
* Write a row source (stream, array, or async iterable) as a JSON array to S3,
|
|
339
|
+
* without buffering the full payload in memory.
|
|
340
|
+
*/
|
|
341
|
+
writeJsonStream = async (bucket, key, source, options = {}) => {
|
|
342
|
+
const { Upload } = await import("@aws-sdk/lib-storage");
|
|
343
|
+
const destination = new stream.PassThrough();
|
|
344
|
+
const upload = new Upload({
|
|
345
|
+
client: this.client,
|
|
346
|
+
params: {
|
|
347
|
+
Bucket: bucket,
|
|
348
|
+
Key: key,
|
|
349
|
+
Body: destination,
|
|
350
|
+
ContentType: "application/json",
|
|
351
|
+
...options.awsS3Options
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
await Promise.all([require_stream_server_json_write.writeJsonStream({
|
|
355
|
+
source,
|
|
356
|
+
destination,
|
|
357
|
+
rowCallback: options.rowCallback,
|
|
358
|
+
sortCallback: options.sortCallback
|
|
359
|
+
}), upload.done()]);
|
|
360
|
+
};
|
|
361
|
+
writeJsonGzipStream = async (bucket, key, source, options = {}) => {
|
|
362
|
+
const { Upload } = await import("@aws-sdk/lib-storage");
|
|
363
|
+
const destination = new stream.PassThrough();
|
|
364
|
+
const upload = new Upload({
|
|
365
|
+
client: this.client,
|
|
366
|
+
params: {
|
|
367
|
+
Bucket: bucket,
|
|
368
|
+
Key: key,
|
|
369
|
+
Body: destination,
|
|
370
|
+
ContentType: "application/json",
|
|
371
|
+
ContentEncoding: "gzip",
|
|
372
|
+
...options.awsS3Options
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
await Promise.all([require_stream_server_json_write.writeJsonGzipStream({
|
|
376
|
+
source,
|
|
377
|
+
destination,
|
|
378
|
+
rowCallback: options.rowCallback,
|
|
379
|
+
sortCallback: options.sortCallback
|
|
380
|
+
}), upload.done()]);
|
|
381
|
+
};
|
|
303
382
|
writeGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
304
383
|
if (await this.isNullOrEmptyData(data)) return null;
|
|
305
384
|
let finalData = data;
|
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
import { BaseNamespace } from "../../../_class/_shared/BaseNamespace.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { ReadFileResponse } from "../_shared/awsS3File.cjs";
|
|
3
|
+
import { RowSource } from "../../../stream/server/json/logic.cjs";
|
|
4
|
+
import { FileHeadResponse, JsonStreamOptions, Options, ReadBufferResponse, WritePresignedPostProps } from "../_shared/types.cjs";
|
|
3
5
|
import "./index.cjs";
|
|
6
|
+
import { Readable } from "stream";
|
|
4
7
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
5
8
|
//#region src/aws/s3/server/AwsS3.d.ts
|
|
6
|
-
export type ReadBufferResponse = Modified & {
|
|
7
|
-
buffer: any;
|
|
8
|
-
};
|
|
9
|
-
export type FileHeadResponse = {
|
|
10
|
-
exists: boolean;
|
|
11
|
-
fileType: string | null;
|
|
12
|
-
size: number;
|
|
13
|
-
modified: string;
|
|
14
|
-
etag: string | null;
|
|
15
|
-
versionId: string | null;
|
|
16
|
-
encoding: string | null;
|
|
17
|
-
cacheControl: string | null;
|
|
18
|
-
meta: Record<string, string>;
|
|
19
|
-
expires: string | null;
|
|
20
|
-
};
|
|
21
|
-
type Options = {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
};
|
|
24
|
-
type WritePresignedPostProps = {
|
|
25
|
-
bucket: string;
|
|
26
|
-
fields: Record<string, string>;
|
|
27
|
-
file: File | Blob;
|
|
28
|
-
key: string;
|
|
29
|
-
url: string;
|
|
30
|
-
};
|
|
31
9
|
export declare class AwsS3 extends BaseNamespace {
|
|
32
10
|
client: S3Client;
|
|
33
11
|
config: any;
|
|
@@ -65,13 +43,28 @@ export declare class AwsS3 extends BaseNamespace {
|
|
|
65
43
|
fileExists: (bucket: string, key: string) => Promise<boolean>;
|
|
66
44
|
getFileHead: (bucket: string, key: string) => Promise<FileHeadResponse>;
|
|
67
45
|
readFile: (bucket: string, key: string, options?: Options) => Promise<ReadFileResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Return the raw object body as a stream, without buffering it into memory.
|
|
48
|
+
*/
|
|
49
|
+
readStream: (bucket: string, key: string, options?: Options) => Promise<Readable>;
|
|
68
50
|
readJson: (bucket: string, key: string) => Promise<ReadFileResponse>;
|
|
69
51
|
readJsonGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Read a JSON array object back, parsing it incrementally without buffering the full document.
|
|
54
|
+
*/
|
|
55
|
+
readJsonStream: <T = any>(bucket: string, key: string, options?: JsonStreamOptions<T>) => Promise<T[]>;
|
|
56
|
+
readJsonGzipStream: <T = any>(bucket: string, key: string, options?: JsonStreamOptions<T>) => Promise<T[]>;
|
|
70
57
|
readGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
71
58
|
writeBrotli: (bucket: string, key: string, data: any, brotliOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
72
59
|
writeFile: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
73
60
|
writeJson: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
74
61
|
writeJsonGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Write a row source (stream, array, or async iterable) as a JSON array to S3,
|
|
64
|
+
* without buffering the full payload in memory.
|
|
65
|
+
*/
|
|
66
|
+
writeJsonStream: <T = any>(bucket: string, key: string, source: RowSource<T>, options?: JsonStreamOptions<T>) => Promise<void>;
|
|
67
|
+
writeJsonGzipStream: <T = any>(bucket: string, key: string, source: RowSource<T>, options?: JsonStreamOptions<T>) => Promise<void>;
|
|
75
68
|
writeGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
76
69
|
/**
|
|
77
70
|
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
import { BaseNamespace } from "../../../_class/_shared/BaseNamespace.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { ReadFileResponse } from "../_shared/awsS3File.mjs";
|
|
3
|
+
import { RowSource } from "../../../stream/server/json/logic.mjs";
|
|
4
|
+
import { FileHeadResponse, JsonStreamOptions, Options, ReadBufferResponse, WritePresignedPostProps } from "../_shared/types.mjs";
|
|
3
5
|
import "./index.mjs";
|
|
6
|
+
import { Readable } from "stream";
|
|
4
7
|
import { S3Client } from "@aws-sdk/client-s3";
|
|
5
8
|
//#region src/aws/s3/server/AwsS3.d.ts
|
|
6
|
-
export type ReadBufferResponse = Modified & {
|
|
7
|
-
buffer: any;
|
|
8
|
-
};
|
|
9
|
-
export type FileHeadResponse = {
|
|
10
|
-
exists: boolean;
|
|
11
|
-
fileType: string | null;
|
|
12
|
-
size: number;
|
|
13
|
-
modified: string;
|
|
14
|
-
etag: string | null;
|
|
15
|
-
versionId: string | null;
|
|
16
|
-
encoding: string | null;
|
|
17
|
-
cacheControl: string | null;
|
|
18
|
-
meta: Record<string, string>;
|
|
19
|
-
expires: string | null;
|
|
20
|
-
};
|
|
21
|
-
type Options = {
|
|
22
|
-
[key: string]: any;
|
|
23
|
-
};
|
|
24
|
-
type WritePresignedPostProps = {
|
|
25
|
-
bucket: string;
|
|
26
|
-
fields: Record<string, string>;
|
|
27
|
-
file: File | Blob;
|
|
28
|
-
key: string;
|
|
29
|
-
url: string;
|
|
30
|
-
};
|
|
31
9
|
export declare class AwsS3 extends BaseNamespace {
|
|
32
10
|
client: S3Client;
|
|
33
11
|
config: any;
|
|
@@ -65,13 +43,28 @@ export declare class AwsS3 extends BaseNamespace {
|
|
|
65
43
|
fileExists: (bucket: string, key: string) => Promise<boolean>;
|
|
66
44
|
getFileHead: (bucket: string, key: string) => Promise<FileHeadResponse>;
|
|
67
45
|
readFile: (bucket: string, key: string, options?: Options) => Promise<ReadFileResponse>;
|
|
46
|
+
/**
|
|
47
|
+
* Return the raw object body as a stream, without buffering it into memory.
|
|
48
|
+
*/
|
|
49
|
+
readStream: (bucket: string, key: string, options?: Options) => Promise<Readable>;
|
|
68
50
|
readJson: (bucket: string, key: string) => Promise<ReadFileResponse>;
|
|
69
51
|
readJsonGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
52
|
+
/**
|
|
53
|
+
* Read a JSON array object back, parsing it incrementally without buffering the full document.
|
|
54
|
+
*/
|
|
55
|
+
readJsonStream: <T = any>(bucket: string, key: string, options?: JsonStreamOptions<T>) => Promise<T[]>;
|
|
56
|
+
readJsonGzipStream: <T = any>(bucket: string, key: string, options?: JsonStreamOptions<T>) => Promise<T[]>;
|
|
70
57
|
readGzip: (bucket: string, key: string, gzipOptions?: object, awsS3Options?: Options) => Promise<ReadFileResponse>;
|
|
71
58
|
writeBrotli: (bucket: string, key: string, data: any, brotliOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
72
59
|
writeFile: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
73
60
|
writeJson: (bucket: string, key: string, data: any, options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
74
61
|
writeJsonGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
62
|
+
/**
|
|
63
|
+
* Write a row source (stream, array, or async iterable) as a JSON array to S3,
|
|
64
|
+
* without buffering the full payload in memory.
|
|
65
|
+
*/
|
|
66
|
+
writeJsonStream: <T = any>(bucket: string, key: string, source: RowSource<T>, options?: JsonStreamOptions<T>) => Promise<void>;
|
|
67
|
+
writeJsonGzipStream: <T = any>(bucket: string, key: string, source: RowSource<T>, options?: JsonStreamOptions<T>) => Promise<void>;
|
|
75
68
|
writeGzip: (bucket: string, key: string, data: any, gzipOptions?: object, awsS3Options?: Options) => Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput | null>;
|
|
76
69
|
/**
|
|
77
70
|
* Get a presigned post URL so we can upload directly to S3 via frontend.
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { BaseNamespace } from "../../../_class/_shared/BaseNamespace.mjs";
|
|
2
2
|
import { getToday } from "../../../date/_shared/calculation.mjs";
|
|
3
3
|
import { getYmdHisString } from "../../../date/_shared/format.mjs";
|
|
4
|
-
import { isResponse200 } from "../../server/isResponse200.mjs";
|
|
5
4
|
import { defaultDateTime } from "../../../date/_shared/date.mjs";
|
|
6
5
|
import "../../../date/_shared/index.mjs";
|
|
6
|
+
import { isResponse200 } from "../../server/isResponse200.mjs";
|
|
7
|
+
import { readJsonGzipStream, readJsonStream } from "../../../stream/server/json/read.mjs";
|
|
8
|
+
import { writeJsonGzipStream, writeJsonStream } from "../../../stream/server/json/write.mjs";
|
|
9
|
+
import "../../../stream/server/index.mjs";
|
|
7
10
|
import { getFolder } from "../../../string/_shared/getFolder.mjs";
|
|
8
11
|
import { getStringFromStream } from "../../../string/_shared/getStringFromStream.mjs";
|
|
9
12
|
import "../../../string/_shared/index.mjs";
|
|
@@ -14,9 +17,10 @@ import "../../../string/server/index.mjs";
|
|
|
14
17
|
import { getBrotliCompressed } from "../../../util/server/getBrotliCompressed.mjs";
|
|
15
18
|
import { getGzipCompressed } from "../../../util/server/getGzipCompressed.mjs";
|
|
16
19
|
import "../../../util/server/index.mjs";
|
|
17
|
-
import { readFileDefault } from "
|
|
20
|
+
import { readFileDefault } from "../_shared/awsS3File.mjs";
|
|
18
21
|
import "./index.mjs";
|
|
19
22
|
import ky from "ky";
|
|
23
|
+
import { PassThrough } from "stream";
|
|
20
24
|
//#region src/aws/s3/server/AwsS3.ts
|
|
21
25
|
var AwsS3 = class extends BaseNamespace {
|
|
22
26
|
init = async (config, region) => {
|
|
@@ -255,6 +259,17 @@ var AwsS3 = class extends BaseNamespace {
|
|
|
255
259
|
}
|
|
256
260
|
return response;
|
|
257
261
|
};
|
|
262
|
+
/**
|
|
263
|
+
* Return the raw object body as a stream, without buffering it into memory.
|
|
264
|
+
*/
|
|
265
|
+
readStream = async (bucket, key, options = {}) => {
|
|
266
|
+
const { GetObjectCommand } = await import("@aws-sdk/client-s3");
|
|
267
|
+
return (await this.client.send(new GetObjectCommand({
|
|
268
|
+
Bucket: bucket,
|
|
269
|
+
Key: key,
|
|
270
|
+
...options
|
|
271
|
+
}))).Body;
|
|
272
|
+
};
|
|
258
273
|
readJson = async (bucket, key) => {
|
|
259
274
|
const apiResponse = await this.readFile(bucket, key);
|
|
260
275
|
apiResponse.body = JSON.parse(apiResponse.body) || null;
|
|
@@ -268,6 +283,25 @@ var AwsS3 = class extends BaseNamespace {
|
|
|
268
283
|
}
|
|
269
284
|
return apiResponse;
|
|
270
285
|
};
|
|
286
|
+
/**
|
|
287
|
+
* Read a JSON array object back, parsing it incrementally without buffering the full document.
|
|
288
|
+
*/
|
|
289
|
+
readJsonStream = async (bucket, key, options = {}) => {
|
|
290
|
+
const source = await this.readStream(bucket, key, options.awsS3Options);
|
|
291
|
+
return readJsonStream({
|
|
292
|
+
source,
|
|
293
|
+
rowCallback: options.rowCallback,
|
|
294
|
+
sortCallback: options.sortCallback
|
|
295
|
+
});
|
|
296
|
+
};
|
|
297
|
+
readJsonGzipStream = async (bucket, key, options = {}) => {
|
|
298
|
+
const source = await this.readStream(bucket, key, options.awsS3Options);
|
|
299
|
+
return readJsonGzipStream({
|
|
300
|
+
source,
|
|
301
|
+
rowCallback: options.rowCallback,
|
|
302
|
+
sortCallback: options.sortCallback
|
|
303
|
+
});
|
|
304
|
+
};
|
|
271
305
|
readGzip = async (bucket, key, gzipOptions = {}, awsS3Options = {}) => {
|
|
272
306
|
const apiResponse = await this.readFile(bucket, key, awsS3Options);
|
|
273
307
|
if (void 0 !== apiResponse.body) apiResponse.body = await getGzipDecompressed(apiResponse.body, gzipOptions);
|
|
@@ -297,6 +331,51 @@ var AwsS3 = class extends BaseNamespace {
|
|
|
297
331
|
finalData = await getGzipCompressed(finalData, gzipOptions);
|
|
298
332
|
return await this.writeFile(bucket, key, finalData, awsS3Options);
|
|
299
333
|
};
|
|
334
|
+
/**
|
|
335
|
+
* Write a row source (stream, array, or async iterable) as a JSON array to S3,
|
|
336
|
+
* without buffering the full payload in memory.
|
|
337
|
+
*/
|
|
338
|
+
writeJsonStream = async (bucket, key, source, options = {}) => {
|
|
339
|
+
const { Upload } = await import("@aws-sdk/lib-storage");
|
|
340
|
+
const destination = new PassThrough();
|
|
341
|
+
const upload = new Upload({
|
|
342
|
+
client: this.client,
|
|
343
|
+
params: {
|
|
344
|
+
Bucket: bucket,
|
|
345
|
+
Key: key,
|
|
346
|
+
Body: destination,
|
|
347
|
+
ContentType: "application/json",
|
|
348
|
+
...options.awsS3Options
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
await Promise.all([writeJsonStream({
|
|
352
|
+
source,
|
|
353
|
+
destination,
|
|
354
|
+
rowCallback: options.rowCallback,
|
|
355
|
+
sortCallback: options.sortCallback
|
|
356
|
+
}), upload.done()]);
|
|
357
|
+
};
|
|
358
|
+
writeJsonGzipStream = async (bucket, key, source, options = {}) => {
|
|
359
|
+
const { Upload } = await import("@aws-sdk/lib-storage");
|
|
360
|
+
const destination = new PassThrough();
|
|
361
|
+
const upload = new Upload({
|
|
362
|
+
client: this.client,
|
|
363
|
+
params: {
|
|
364
|
+
Bucket: bucket,
|
|
365
|
+
Key: key,
|
|
366
|
+
Body: destination,
|
|
367
|
+
ContentType: "application/json",
|
|
368
|
+
ContentEncoding: "gzip",
|
|
369
|
+
...options.awsS3Options
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
await Promise.all([writeJsonGzipStream({
|
|
373
|
+
source,
|
|
374
|
+
destination,
|
|
375
|
+
rowCallback: options.rowCallback,
|
|
376
|
+
sortCallback: options.sortCallback
|
|
377
|
+
}), upload.done()]);
|
|
378
|
+
};
|
|
300
379
|
writeGzip = async (bucket, key, data, gzipOptions = {}, awsS3Options = {}) => {
|
|
301
380
|
if (await this.isNullOrEmptyData(data)) return null;
|
|
302
381
|
let finalData = data;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const
|
|
2
|
+
const require_aws_s3__shared_awsS3File = require("../_shared/awsS3File.cjs");
|
|
3
|
+
require("../_shared/index.cjs");
|
|
3
4
|
const require_aws_s3_server_payload = require("./payload.cjs");
|
|
4
5
|
const require_aws_s3_server_AwsS3 = require("./AwsS3.cjs");
|
|
5
6
|
exports.AwsS3 = require_aws_s3_server_AwsS3.AwsS3;
|
|
6
7
|
exports.payloadSchema = require_aws_s3_server_payload.payloadSchema;
|
|
7
|
-
exports.readFileDefault =
|
|
8
|
+
exports.readFileDefault = require_aws_s3__shared_awsS3File.readFileDefault;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Modified, ReadFileResponse, readFileDefault } from "
|
|
1
|
+
import { Modified, ReadFileResponse, readFileDefault } from "../_shared/awsS3File.cjs";
|
|
2
|
+
import { FileHeadResponse, JsonStreamOptions, Options, ReadBufferResponse, WritePresignedPostProps } from "../_shared/types.cjs";
|
|
2
3
|
import { PayloadSchemaType, payloadSchema } from "./payload.cjs";
|
|
3
|
-
import { AwsS3
|
|
4
|
-
export { AwsS3, FileHeadResponse, Modified, PayloadSchemaType, ReadBufferResponse, ReadFileResponse, payloadSchema, readFileDefault };
|
|
4
|
+
import { AwsS3 } from "./AwsS3.cjs";
|
|
5
|
+
export { AwsS3, FileHeadResponse, JsonStreamOptions, Modified, Options, PayloadSchemaType, ReadBufferResponse, ReadFileResponse, WritePresignedPostProps, payloadSchema, readFileDefault };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Modified, ReadFileResponse, readFileDefault } from "
|
|
1
|
+
import { Modified, ReadFileResponse, readFileDefault } from "../_shared/awsS3File.mjs";
|
|
2
|
+
import { FileHeadResponse, JsonStreamOptions, Options, ReadBufferResponse, WritePresignedPostProps } from "../_shared/types.mjs";
|
|
2
3
|
import { PayloadSchemaType, payloadSchema } from "./payload.mjs";
|
|
3
|
-
import { AwsS3
|
|
4
|
-
export { AwsS3, FileHeadResponse, Modified, PayloadSchemaType, ReadBufferResponse, ReadFileResponse, payloadSchema, readFileDefault };
|
|
4
|
+
import { AwsS3 } from "./AwsS3.mjs";
|
|
5
|
+
export { AwsS3, FileHeadResponse, JsonStreamOptions, Modified, Options, PayloadSchemaType, ReadBufferResponse, ReadFileResponse, WritePresignedPostProps, payloadSchema, readFileDefault };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readFileDefault } from "
|
|
1
|
+
import { readFileDefault } from "../_shared/awsS3File.mjs";
|
|
2
|
+
import "../_shared/index.mjs";
|
|
2
3
|
import { payloadSchema } from "./payload.mjs";
|
|
3
4
|
import { AwsS3 } from "./AwsS3.mjs";
|
|
4
5
|
export { AwsS3, payloadSchema, readFileDefault };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//#region src/file/_shared/dataFileType.d.ts
|
|
2
2
|
export declare const dataFileType: {
|
|
3
3
|
readonly JSON: "json";
|
|
4
|
+
readonly JSON_NEWLINE: "jsonl";
|
|
5
|
+
readonly PARQUET: "parquet";
|
|
4
6
|
readonly XML: "xml";
|
|
5
7
|
};
|
|
6
8
|
export type DataFileType = typeof dataFileType[keyof typeof dataFileType];
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
//#region src/file/_shared/dataFileType.d.ts
|
|
2
2
|
export declare const dataFileType: {
|
|
3
3
|
readonly JSON: "json";
|
|
4
|
+
readonly JSON_NEWLINE: "jsonl";
|
|
5
|
+
readonly PARQUET: "parquet";
|
|
4
6
|
readonly XML: "xml";
|
|
5
7
|
};
|
|
6
8
|
export type DataFileType = typeof dataFileType[keyof typeof dataFileType];
|
|
@@ -10,9 +10,11 @@ const fileMimeType = {
|
|
|
10
10
|
[require_file__shared_fileType.fileType.JPEG]: "image/jpeg",
|
|
11
11
|
[require_file__shared_fileType.fileType.JPG]: "image/jpeg",
|
|
12
12
|
[require_file__shared_fileType.fileType.JSON]: "application/json",
|
|
13
|
+
[require_file__shared_fileType.fileType.JSON_NEWLINE]: "application/x-ndjson",
|
|
13
14
|
[require_file__shared_fileType.fileType.MKV]: "video/x-matroska",
|
|
14
15
|
[require_file__shared_fileType.fileType.MOV]: "video/quicktime",
|
|
15
16
|
[require_file__shared_fileType.fileType.MP4]: "video/mp4",
|
|
17
|
+
[require_file__shared_fileType.fileType.PARQUET]: "application/vnd.apache.parquet",
|
|
16
18
|
[require_file__shared_fileType.fileType.PDF]: "application/pdf",
|
|
17
19
|
[require_file__shared_fileType.fileType.PNG]: "image/png",
|
|
18
20
|
[require_file__shared_fileType.fileType.PPT]: "application/vnd.ms-powerpoint",
|