@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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Readable, Transform } from "stream";
|
|
2
|
+
//#region src/stream/server/json/logic.ts
|
|
3
|
+
const toRowReadable = (source) => {
|
|
4
|
+
return source instanceof Readable ? source : Readable.from(source, { objectMode: true });
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Applies the optional per-row callback, dropping rows for which it resolves null/undefined.
|
|
8
|
+
*/
|
|
9
|
+
const rowCallbackTransform = (rowCallback) => new Transform({
|
|
10
|
+
objectMode: true,
|
|
11
|
+
transform(row, _encoding, callback) {
|
|
12
|
+
Promise.resolve(rowCallback(row)).then((result) => callback(null, null === result || void 0 === result ? void 0 : result)).catch((error) => callback(error));
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
//#endregion
|
|
16
|
+
export { rowCallbackTransform, toRowReadable };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_stream_server_sort = require("../sort.cjs");
|
|
4
|
+
const require_stream_server_json_logic = require("./logic.cjs");
|
|
5
|
+
let stream = require("stream");
|
|
6
|
+
let zlib = require("zlib");
|
|
7
|
+
zlib = require_runtime.__toESM(zlib);
|
|
8
|
+
let stream_promises = require("stream/promises");
|
|
9
|
+
//#region src/stream/server/json/read.ts
|
|
10
|
+
const unwrapStreamArrayValue = () => new stream.Transform({
|
|
11
|
+
objectMode: true,
|
|
12
|
+
transform({ value }, _encoding, callback) {
|
|
13
|
+
callback(null, value);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const collectJsonArray = async (source, rowCallback, sortCallback) => {
|
|
17
|
+
const { streamArray } = await import("stream-json/streamers/stream-array.js");
|
|
18
|
+
const rows = [];
|
|
19
|
+
const steps = [
|
|
20
|
+
source,
|
|
21
|
+
streamArray.withParserAsStream(),
|
|
22
|
+
unwrapStreamArrayValue()
|
|
23
|
+
];
|
|
24
|
+
if (rowCallback) steps.push(require_stream_server_json_logic.rowCallbackTransform(rowCallback));
|
|
25
|
+
if (sortCallback) steps.push(require_stream_server_sort.sort(sortCallback));
|
|
26
|
+
steps.push(new stream.Transform({
|
|
27
|
+
objectMode: true,
|
|
28
|
+
transform(row, _encoding, callback) {
|
|
29
|
+
rows.push(row);
|
|
30
|
+
callback();
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
33
|
+
await (0, stream_promises.pipeline)(steps);
|
|
34
|
+
return rows;
|
|
35
|
+
};
|
|
36
|
+
/** Parses a JSON array source incrementally, row by row, without buffering the whole document first. */
|
|
37
|
+
const readJsonStream = async (props) => {
|
|
38
|
+
return collectJsonArray(props.source, props.rowCallback, props.sortCallback);
|
|
39
|
+
};
|
|
40
|
+
/** Same as readJsonStream, but gunzips `source` before parsing it as a JSON array. */
|
|
41
|
+
const readJsonGzipStream = async (props) => {
|
|
42
|
+
return collectJsonArray(props.source.pipe(zlib.default.createGunzip()), props.rowCallback, props.sortCallback);
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
exports.readJsonGzipStream = readJsonGzipStream;
|
|
46
|
+
exports.readJsonStream = readJsonStream;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReadJsonStreamProps } from "./logic.cjs";
|
|
2
|
+
//#region src/stream/server/json/read.d.ts
|
|
3
|
+
/** Parses a JSON array source incrementally, row by row, without buffering the whole document first. */
|
|
4
|
+
export declare const readJsonStream: <T = any>(props: ReadJsonStreamProps<T>) => Promise<T[]>;
|
|
5
|
+
/** Same as readJsonStream, but gunzips `source` before parsing it as a JSON array. */
|
|
6
|
+
export declare const readJsonGzipStream: <T = any>(props: ReadJsonStreamProps<T>) => Promise<T[]>;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReadJsonStreamProps } from "./logic.mjs";
|
|
2
|
+
//#region src/stream/server/json/read.d.ts
|
|
3
|
+
/** Parses a JSON array source incrementally, row by row, without buffering the whole document first. */
|
|
4
|
+
export declare const readJsonStream: <T = any>(props: ReadJsonStreamProps<T>) => Promise<T[]>;
|
|
5
|
+
/** Same as readJsonStream, but gunzips `source` before parsing it as a JSON array. */
|
|
6
|
+
export declare const readJsonGzipStream: <T = any>(props: ReadJsonStreamProps<T>) => Promise<T[]>;
|
|
7
|
+
//#endregion
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { sort } from "../sort.mjs";
|
|
2
|
+
import { rowCallbackTransform } from "./logic.mjs";
|
|
3
|
+
import { Transform } from "stream";
|
|
4
|
+
import zlib from "zlib";
|
|
5
|
+
import { pipeline } from "stream/promises";
|
|
6
|
+
//#region src/stream/server/json/read.ts
|
|
7
|
+
const unwrapStreamArrayValue = () => new Transform({
|
|
8
|
+
objectMode: true,
|
|
9
|
+
transform({ value }, _encoding, callback) {
|
|
10
|
+
callback(null, value);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const collectJsonArray = async (source, rowCallback, sortCallback) => {
|
|
14
|
+
const { streamArray } = await import("stream-json/streamers/stream-array.js");
|
|
15
|
+
const rows = [];
|
|
16
|
+
const steps = [
|
|
17
|
+
source,
|
|
18
|
+
streamArray.withParserAsStream(),
|
|
19
|
+
unwrapStreamArrayValue()
|
|
20
|
+
];
|
|
21
|
+
if (rowCallback) steps.push(rowCallbackTransform(rowCallback));
|
|
22
|
+
if (sortCallback) steps.push(sort(sortCallback));
|
|
23
|
+
steps.push(new Transform({
|
|
24
|
+
objectMode: true,
|
|
25
|
+
transform(row, _encoding, callback) {
|
|
26
|
+
rows.push(row);
|
|
27
|
+
callback();
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
30
|
+
await pipeline(steps);
|
|
31
|
+
return rows;
|
|
32
|
+
};
|
|
33
|
+
/** Parses a JSON array source incrementally, row by row, without buffering the whole document first. */
|
|
34
|
+
const readJsonStream = async (props) => {
|
|
35
|
+
return collectJsonArray(props.source, props.rowCallback, props.sortCallback);
|
|
36
|
+
};
|
|
37
|
+
/** Same as readJsonStream, but gunzips `source` before parsing it as a JSON array. */
|
|
38
|
+
const readJsonGzipStream = async (props) => {
|
|
39
|
+
return collectJsonArray(props.source.pipe(zlib.createGunzip()), props.rowCallback, props.sortCallback);
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { readJsonGzipStream, readJsonStream };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_runtime = require("../../../_virtual/_rolldown/runtime.cjs");
|
|
3
|
+
const require_stream_server_sort = require("../sort.cjs");
|
|
4
|
+
const require_stream_server_json_logic = require("./logic.cjs");
|
|
5
|
+
let stream = require("stream");
|
|
6
|
+
let zlib = require("zlib");
|
|
7
|
+
zlib = require_runtime.__toESM(zlib);
|
|
8
|
+
let stream_promises = require("stream/promises");
|
|
9
|
+
//#region src/stream/server/json/write.ts
|
|
10
|
+
/**
|
|
11
|
+
* Serialises a stream of row objects into a single JSON array without ever holding
|
|
12
|
+
* the full collection in memory - one stringified row at a time.
|
|
13
|
+
*/
|
|
14
|
+
var JsonArrayStringifier = class extends stream.Transform {
|
|
15
|
+
isFirstRow = true;
|
|
16
|
+
constructor() {
|
|
17
|
+
super({
|
|
18
|
+
writableObjectMode: true,
|
|
19
|
+
readableObjectMode: false
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
_transform(row, _encoding, callback) {
|
|
23
|
+
this.push((this.isFirstRow ? "[" : ",") + JSON.stringify(row));
|
|
24
|
+
this.isFirstRow = false;
|
|
25
|
+
callback();
|
|
26
|
+
}
|
|
27
|
+
_flush(callback) {
|
|
28
|
+
this.push(this.isFirstRow ? "[]" : "]");
|
|
29
|
+
callback();
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/** Serialises a stream of row objects into newline-delimited JSON, one stringified row at a time. */
|
|
33
|
+
var JsonNewLineStringifier = class extends stream.Transform {
|
|
34
|
+
constructor() {
|
|
35
|
+
super({
|
|
36
|
+
writableObjectMode: true,
|
|
37
|
+
readableObjectMode: false
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
_transform(row, _encoding, callback) {
|
|
41
|
+
this.push(JSON.stringify(row) + "\n");
|
|
42
|
+
callback();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const jsonNewLineStringifier = () => new JsonNewLineStringifier();
|
|
46
|
+
const buildWriteSteps = ({ source, rowCallback, sortCallback }) => {
|
|
47
|
+
const steps = [require_stream_server_json_logic.toRowReadable(source)];
|
|
48
|
+
if (rowCallback) steps.push(require_stream_server_json_logic.rowCallbackTransform(rowCallback));
|
|
49
|
+
if (sortCallback) steps.push(require_stream_server_sort.sort(sortCallback));
|
|
50
|
+
steps.push(new JsonArrayStringifier());
|
|
51
|
+
return steps;
|
|
52
|
+
};
|
|
53
|
+
/** Streams a row source into a single JSON array on `destination`, never buffering the full collection in memory. */
|
|
54
|
+
const writeJsonStream = async (props) => {
|
|
55
|
+
await (0, stream_promises.pipeline)([...buildWriteSteps(props), props.destination]);
|
|
56
|
+
};
|
|
57
|
+
/** Same as writeJsonStream, but gzip-compresses the JSON array before it reaches `destination`. */
|
|
58
|
+
const writeJsonGzipStream = async (props) => {
|
|
59
|
+
await (0, stream_promises.pipeline)([
|
|
60
|
+
...buildWriteSteps(props),
|
|
61
|
+
zlib.default.createGzip(),
|
|
62
|
+
props.destination
|
|
63
|
+
]);
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
exports.JsonNewLineStringifier = JsonNewLineStringifier;
|
|
67
|
+
exports.jsonNewLineStringifier = jsonNewLineStringifier;
|
|
68
|
+
exports.writeJsonGzipStream = writeJsonGzipStream;
|
|
69
|
+
exports.writeJsonStream = writeJsonStream;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WriteJsonStreamProps } from "./logic.cjs";
|
|
2
|
+
import { Transform } from "stream";
|
|
3
|
+
//#region src/stream/server/json/write.d.ts
|
|
4
|
+
/** Serialises a stream of row objects into newline-delimited JSON, one stringified row at a time. */
|
|
5
|
+
export declare class JsonNewLineStringifier extends Transform {
|
|
6
|
+
constructor();
|
|
7
|
+
_transform(row: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const jsonNewLineStringifier: () => JsonNewLineStringifier;
|
|
10
|
+
/** Streams a row source into a single JSON array on `destination`, never buffering the full collection in memory. */
|
|
11
|
+
export declare const writeJsonStream: <T = any>(props: WriteJsonStreamProps<T>) => Promise<void>;
|
|
12
|
+
/** Same as writeJsonStream, but gzip-compresses the JSON array before it reaches `destination`. */
|
|
13
|
+
export declare const writeJsonGzipStream: <T = any>(props: WriteJsonStreamProps<T>) => Promise<void>;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WriteJsonStreamProps } from "./logic.mjs";
|
|
2
|
+
import { Transform } from "stream";
|
|
3
|
+
//#region src/stream/server/json/write.d.ts
|
|
4
|
+
/** Serialises a stream of row objects into newline-delimited JSON, one stringified row at a time. */
|
|
5
|
+
export declare class JsonNewLineStringifier extends Transform {
|
|
6
|
+
constructor();
|
|
7
|
+
_transform(row: any, _encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const jsonNewLineStringifier: () => JsonNewLineStringifier;
|
|
10
|
+
/** Streams a row source into a single JSON array on `destination`, never buffering the full collection in memory. */
|
|
11
|
+
export declare const writeJsonStream: <T = any>(props: WriteJsonStreamProps<T>) => Promise<void>;
|
|
12
|
+
/** Same as writeJsonStream, but gzip-compresses the JSON array before it reaches `destination`. */
|
|
13
|
+
export declare const writeJsonGzipStream: <T = any>(props: WriteJsonStreamProps<T>) => Promise<void>;
|
|
14
|
+
//#endregion
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { sort } from "../sort.mjs";
|
|
2
|
+
import { rowCallbackTransform, toRowReadable } from "./logic.mjs";
|
|
3
|
+
import { Transform } from "stream";
|
|
4
|
+
import zlib from "zlib";
|
|
5
|
+
import { pipeline } from "stream/promises";
|
|
6
|
+
//#region src/stream/server/json/write.ts
|
|
7
|
+
/**
|
|
8
|
+
* Serialises a stream of row objects into a single JSON array without ever holding
|
|
9
|
+
* the full collection in memory - one stringified row at a time.
|
|
10
|
+
*/
|
|
11
|
+
var JsonArrayStringifier = class extends Transform {
|
|
12
|
+
isFirstRow = true;
|
|
13
|
+
constructor() {
|
|
14
|
+
super({
|
|
15
|
+
writableObjectMode: true,
|
|
16
|
+
readableObjectMode: false
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
_transform(row, _encoding, callback) {
|
|
20
|
+
this.push((this.isFirstRow ? "[" : ",") + JSON.stringify(row));
|
|
21
|
+
this.isFirstRow = false;
|
|
22
|
+
callback();
|
|
23
|
+
}
|
|
24
|
+
_flush(callback) {
|
|
25
|
+
this.push(this.isFirstRow ? "[]" : "]");
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/** Serialises a stream of row objects into newline-delimited JSON, one stringified row at a time. */
|
|
30
|
+
var JsonNewLineStringifier = class extends Transform {
|
|
31
|
+
constructor() {
|
|
32
|
+
super({
|
|
33
|
+
writableObjectMode: true,
|
|
34
|
+
readableObjectMode: false
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
_transform(row, _encoding, callback) {
|
|
38
|
+
this.push(JSON.stringify(row) + "\n");
|
|
39
|
+
callback();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const jsonNewLineStringifier = () => new JsonNewLineStringifier();
|
|
43
|
+
const buildWriteSteps = ({ source, rowCallback, sortCallback }) => {
|
|
44
|
+
const steps = [toRowReadable(source)];
|
|
45
|
+
if (rowCallback) steps.push(rowCallbackTransform(rowCallback));
|
|
46
|
+
if (sortCallback) steps.push(sort(sortCallback));
|
|
47
|
+
steps.push(new JsonArrayStringifier());
|
|
48
|
+
return steps;
|
|
49
|
+
};
|
|
50
|
+
/** Streams a row source into a single JSON array on `destination`, never buffering the full collection in memory. */
|
|
51
|
+
const writeJsonStream = async (props) => {
|
|
52
|
+
await pipeline([...buildWriteSteps(props), props.destination]);
|
|
53
|
+
};
|
|
54
|
+
/** Same as writeJsonStream, but gzip-compresses the JSON array before it reaches `destination`. */
|
|
55
|
+
const writeJsonGzipStream = async (props) => {
|
|
56
|
+
await pipeline([
|
|
57
|
+
...buildWriteSteps(props),
|
|
58
|
+
zlib.createGzip(),
|
|
59
|
+
props.destination
|
|
60
|
+
]);
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { JsonNewLineStringifier, jsonNewLineStringifier, writeJsonGzipStream, writeJsonStream };
|
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
let node_stream = require("node:stream");
|
|
3
3
|
//#region src/stream/server/sort.ts
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Buffers every row that passes through, then emits them all sorted by `comp` once the source ends.
|
|
6
|
+
* Sorting requires seeing the whole collection first, so this is a full in-memory buffer - not a
|
|
7
|
+
* bounded or windowed sort - and should only be used where the full stream fits comfortably in memory.
|
|
8
|
+
*/
|
|
5
9
|
var SortStreamer = class extends node_stream.Transform {
|
|
6
|
-
|
|
7
|
-
i;
|
|
8
|
-
k;
|
|
9
|
-
currentSize;
|
|
10
|
-
sortedArray;
|
|
10
|
+
rows = [];
|
|
11
11
|
comp;
|
|
12
12
|
constructor(options, comp) {
|
|
13
13
|
super(options);
|
|
14
|
-
this.a = new Array(batch);
|
|
15
|
-
this.i = 0;
|
|
16
|
-
this.k = 0;
|
|
17
|
-
this.currentSize = batch;
|
|
18
|
-
this.sortedArray = void 0;
|
|
19
14
|
this.comp = comp;
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (this.i === this.currentSize) {
|
|
25
|
-
this.currentSize *= 2;
|
|
26
|
-
const tmp = new Array(this.currentSize);
|
|
27
|
-
for (let j = 0; j < this.i; j++) tmp[j] = this.a[j];
|
|
28
|
-
this.a = tmp;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
16
|
+
/** Collects each row as it arrives; nothing is emitted downstream yet. */
|
|
17
|
+
_transform(data, _encoding, callback) {
|
|
18
|
+
this.rows.push(data);
|
|
31
19
|
callback();
|
|
32
20
|
}
|
|
21
|
+
/** The source has ended - sort everything collected so far, then emit it all in order. */
|
|
33
22
|
_flush(callback) {
|
|
34
|
-
this.
|
|
35
|
-
while (this.k < this.i) this.push(this.sortedArray[this.k++]);
|
|
23
|
+
this.rows.sort(this.comp).forEach((row) => this.push(row));
|
|
36
24
|
callback();
|
|
37
25
|
}
|
|
38
26
|
};
|
|
27
|
+
/** Creates a sorting Transform: buffers every row, sorts by `comp`, and emits the result once the source ends. */
|
|
39
28
|
const sort = (comp, options) => {
|
|
40
29
|
return new SortStreamer(options ?? { objectMode: true }, comp);
|
|
41
30
|
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Transform, TransformCallback, TransformOptions } from "node:stream";
|
|
2
2
|
//#region src/stream/server/sort.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Buffers every row that passes through, then emits them all sorted by `comp` once the source ends.
|
|
5
|
+
* Sorting requires seeing the whole collection first, so this is a full in-memory buffer - not a
|
|
6
|
+
* bounded or windowed sort - and should only be used where the full stream fits comfortably in memory.
|
|
7
|
+
*/
|
|
3
8
|
declare class SortStreamer<T> extends Transform {
|
|
4
|
-
private
|
|
5
|
-
private i;
|
|
6
|
-
private k;
|
|
7
|
-
private currentSize;
|
|
8
|
-
private sortedArray;
|
|
9
|
+
private readonly rows;
|
|
9
10
|
private readonly comp;
|
|
10
11
|
constructor(options: TransformOptions, comp: (a: T, b: T) => number);
|
|
11
|
-
|
|
12
|
+
/** Collects each row as it arrives; nothing is emitted downstream yet. */
|
|
13
|
+
_transform(data: T, _encoding: BufferEncoding, callback: TransformCallback): void;
|
|
14
|
+
/** The source has ended - sort everything collected so far, then emit it all in order. */
|
|
12
15
|
_flush(callback: TransformCallback): void;
|
|
13
16
|
}
|
|
17
|
+
/** Creates a sorting Transform: buffers every row, sorts by `comp`, and emits the result once the source ends. */
|
|
14
18
|
export declare const sort: <T>(comp: (a: T, b: T) => number, options?: TransformOptions) => SortStreamer<T>;
|
|
15
19
|
//#endregion
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { Transform, TransformCallback, TransformOptions } from "node:stream";
|
|
2
2
|
//#region src/stream/server/sort.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Buffers every row that passes through, then emits them all sorted by `comp` once the source ends.
|
|
5
|
+
* Sorting requires seeing the whole collection first, so this is a full in-memory buffer - not a
|
|
6
|
+
* bounded or windowed sort - and should only be used where the full stream fits comfortably in memory.
|
|
7
|
+
*/
|
|
3
8
|
declare class SortStreamer<T> extends Transform {
|
|
4
|
-
private
|
|
5
|
-
private i;
|
|
6
|
-
private k;
|
|
7
|
-
private currentSize;
|
|
8
|
-
private sortedArray;
|
|
9
|
+
private readonly rows;
|
|
9
10
|
private readonly comp;
|
|
10
11
|
constructor(options: TransformOptions, comp: (a: T, b: T) => number);
|
|
11
|
-
|
|
12
|
+
/** Collects each row as it arrives; nothing is emitted downstream yet. */
|
|
13
|
+
_transform(data: T, _encoding: BufferEncoding, callback: TransformCallback): void;
|
|
14
|
+
/** The source has ended - sort everything collected so far, then emit it all in order. */
|
|
12
15
|
_flush(callback: TransformCallback): void;
|
|
13
16
|
}
|
|
17
|
+
/** Creates a sorting Transform: buffers every row, sorts by `comp`, and emits the result once the source ends. */
|
|
14
18
|
export declare const sort: <T>(comp: (a: T, b: T) => number, options?: TransformOptions) => SortStreamer<T>;
|
|
15
19
|
//#endregion
|
|
@@ -1,40 +1,29 @@
|
|
|
1
1
|
import { Transform } from "node:stream";
|
|
2
2
|
//#region src/stream/server/sort.ts
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Buffers every row that passes through, then emits them all sorted by `comp` once the source ends.
|
|
5
|
+
* Sorting requires seeing the whole collection first, so this is a full in-memory buffer - not a
|
|
6
|
+
* bounded or windowed sort - and should only be used where the full stream fits comfortably in memory.
|
|
7
|
+
*/
|
|
4
8
|
var SortStreamer = class extends Transform {
|
|
5
|
-
|
|
6
|
-
i;
|
|
7
|
-
k;
|
|
8
|
-
currentSize;
|
|
9
|
-
sortedArray;
|
|
9
|
+
rows = [];
|
|
10
10
|
comp;
|
|
11
11
|
constructor(options, comp) {
|
|
12
12
|
super(options);
|
|
13
|
-
this.a = new Array(batch);
|
|
14
|
-
this.i = 0;
|
|
15
|
-
this.k = 0;
|
|
16
|
-
this.currentSize = batch;
|
|
17
|
-
this.sortedArray = void 0;
|
|
18
13
|
this.comp = comp;
|
|
19
14
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (this.i === this.currentSize) {
|
|
24
|
-
this.currentSize *= 2;
|
|
25
|
-
const tmp = new Array(this.currentSize);
|
|
26
|
-
for (let j = 0; j < this.i; j++) tmp[j] = this.a[j];
|
|
27
|
-
this.a = tmp;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
15
|
+
/** Collects each row as it arrives; nothing is emitted downstream yet. */
|
|
16
|
+
_transform(data, _encoding, callback) {
|
|
17
|
+
this.rows.push(data);
|
|
30
18
|
callback();
|
|
31
19
|
}
|
|
20
|
+
/** The source has ended - sort everything collected so far, then emit it all in order. */
|
|
32
21
|
_flush(callback) {
|
|
33
|
-
this.
|
|
34
|
-
while (this.k < this.i) this.push(this.sortedArray[this.k++]);
|
|
22
|
+
this.rows.sort(this.comp).forEach((row) => this.push(row));
|
|
35
23
|
callback();
|
|
36
24
|
}
|
|
37
25
|
};
|
|
26
|
+
/** Creates a sorting Transform: buffers every row, sorts by `comp`, and emits the result once the source ends. */
|
|
38
27
|
const sort = (comp, options) => {
|
|
39
28
|
return new SortStreamer(options ?? { objectMode: true }, comp);
|
|
40
29
|
};
|
|
@@ -2,16 +2,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
const require_xlsx__shared_column = require("./column.cjs");
|
|
3
3
|
const require_xlsx__shared_cell = require("./cell.cjs");
|
|
4
4
|
const require_xlsx__shared_sheet = require("./sheet.cjs");
|
|
5
|
+
const require_zip__shared_ZipArchive = require("../../zip/_shared/ZipArchive.cjs");
|
|
5
6
|
//#region src/xlsx/_shared/createXlsx.ts
|
|
6
7
|
/**
|
|
7
|
-
* Builds a complete .xlsx workbook from scratch, using
|
|
8
|
-
*
|
|
8
|
+
* Builds a complete .xlsx workbook from scratch, using hand-written OOXML rather
|
|
9
|
+
* than a spreadsheet library.
|
|
9
10
|
*
|
|
10
11
|
* Nothing here touches `fs`, so it runs in the browser as happily as on the
|
|
11
12
|
* server — a page can turn data it has already loaded straight into a download.
|
|
12
|
-
*
|
|
13
|
-
* jszip is an optional peer dependency imported dynamically, so consumers that
|
|
14
|
-
* never build a workbook neither install it nor pay for it in their bundle.
|
|
15
13
|
*/
|
|
16
14
|
/** Style index of the bold row within the cellXfs list built by buildStylesXml. */
|
|
17
15
|
const HEADER_STYLE_INDEX = 1;
|
|
@@ -95,16 +93,15 @@ const buildPackageRelsXml = () => {
|
|
|
95
93
|
*/
|
|
96
94
|
const buildWorkbook = async (sheets) => {
|
|
97
95
|
if (0 === sheets.length) throw new Error("createXlsx requires at least one sheet.");
|
|
98
|
-
const
|
|
99
|
-
const zip = new JSZip();
|
|
96
|
+
const zip = new require_zip__shared_ZipArchive.ZipArchive();
|
|
100
97
|
const names = require_xlsx__shared_sheet.getUniqueSheetNames(sheets);
|
|
101
|
-
zip.
|
|
102
|
-
zip.
|
|
103
|
-
zip.
|
|
104
|
-
zip.
|
|
105
|
-
zip.
|
|
98
|
+
zip.set("[Content_Types].xml", buildContentTypesXml(sheets.length));
|
|
99
|
+
zip.set("_rels/.rels", buildPackageRelsXml());
|
|
100
|
+
zip.set("xl/workbook.xml", buildWorkbookXml(names));
|
|
101
|
+
zip.set("xl/_rels/workbook.xml.rels", buildWorkbookRelsXml(sheets.length));
|
|
102
|
+
zip.set("xl/styles.xml", buildStylesXml());
|
|
106
103
|
sheets.forEach((sheet, index) => {
|
|
107
|
-
zip.
|
|
104
|
+
zip.set(`xl/worksheets/sheet${index + 1}.xml`, buildWorksheetXml(sheet));
|
|
108
105
|
});
|
|
109
106
|
return zip;
|
|
110
107
|
};
|
|
@@ -117,21 +114,14 @@ const buildWorkbook = async (sheets) => {
|
|
|
117
114
|
* matter and a missing key becomes an empty cell.
|
|
118
115
|
*/
|
|
119
116
|
const createXlsx = async (sheets) => {
|
|
120
|
-
return (await buildWorkbook(sheets)).
|
|
121
|
-
type: "blob",
|
|
122
|
-
compression: "DEFLATE",
|
|
123
|
-
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
124
|
-
});
|
|
117
|
+
return (await buildWorkbook(sheets)).toBlob("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
125
118
|
};
|
|
126
119
|
/**
|
|
127
120
|
* As createXlsx, but returns raw bytes instead of a Blob — for server-side
|
|
128
121
|
* callers that need to stream or write the workbook rather than download it.
|
|
129
122
|
*/
|
|
130
123
|
const createXlsxBytes = async (sheets) => {
|
|
131
|
-
return (await buildWorkbook(sheets)).
|
|
132
|
-
type: "uint8array",
|
|
133
|
-
compression: "DEFLATE"
|
|
134
|
-
});
|
|
124
|
+
return (await buildWorkbook(sheets)).toBytes();
|
|
135
125
|
};
|
|
136
126
|
//#endregion
|
|
137
127
|
exports.createXlsx = createXlsx;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { getColumLetter, getColumnWidth } from "./column.mjs";
|
|
2
2
|
import { buildCellXml, getCellValue, getEscapedXml } from "./cell.mjs";
|
|
3
3
|
import { getUniqueSheetNames } from "./sheet.mjs";
|
|
4
|
+
import { ZipArchive } from "../../zip/_shared/ZipArchive.mjs";
|
|
4
5
|
//#region src/xlsx/_shared/createXlsx.ts
|
|
5
6
|
/**
|
|
6
|
-
* Builds a complete .xlsx workbook from scratch, using
|
|
7
|
-
*
|
|
7
|
+
* Builds a complete .xlsx workbook from scratch, using hand-written OOXML rather
|
|
8
|
+
* than a spreadsheet library.
|
|
8
9
|
*
|
|
9
10
|
* Nothing here touches `fs`, so it runs in the browser as happily as on the
|
|
10
11
|
* server — a page can turn data it has already loaded straight into a download.
|
|
11
|
-
*
|
|
12
|
-
* jszip is an optional peer dependency imported dynamically, so consumers that
|
|
13
|
-
* never build a workbook neither install it nor pay for it in their bundle.
|
|
14
12
|
*/
|
|
15
13
|
/** Style index of the bold row within the cellXfs list built by buildStylesXml. */
|
|
16
14
|
const HEADER_STYLE_INDEX = 1;
|
|
@@ -94,16 +92,15 @@ const buildPackageRelsXml = () => {
|
|
|
94
92
|
*/
|
|
95
93
|
const buildWorkbook = async (sheets) => {
|
|
96
94
|
if (0 === sheets.length) throw new Error("createXlsx requires at least one sheet.");
|
|
97
|
-
const
|
|
98
|
-
const zip = new JSZip();
|
|
95
|
+
const zip = new ZipArchive();
|
|
99
96
|
const names = getUniqueSheetNames(sheets);
|
|
100
|
-
zip.
|
|
101
|
-
zip.
|
|
102
|
-
zip.
|
|
103
|
-
zip.
|
|
104
|
-
zip.
|
|
97
|
+
zip.set("[Content_Types].xml", buildContentTypesXml(sheets.length));
|
|
98
|
+
zip.set("_rels/.rels", buildPackageRelsXml());
|
|
99
|
+
zip.set("xl/workbook.xml", buildWorkbookXml(names));
|
|
100
|
+
zip.set("xl/_rels/workbook.xml.rels", buildWorkbookRelsXml(sheets.length));
|
|
101
|
+
zip.set("xl/styles.xml", buildStylesXml());
|
|
105
102
|
sheets.forEach((sheet, index) => {
|
|
106
|
-
zip.
|
|
103
|
+
zip.set(`xl/worksheets/sheet${index + 1}.xml`, buildWorksheetXml(sheet));
|
|
107
104
|
});
|
|
108
105
|
return zip;
|
|
109
106
|
};
|
|
@@ -116,21 +113,14 @@ const buildWorkbook = async (sheets) => {
|
|
|
116
113
|
* matter and a missing key becomes an empty cell.
|
|
117
114
|
*/
|
|
118
115
|
const createXlsx = async (sheets) => {
|
|
119
|
-
return (await buildWorkbook(sheets)).
|
|
120
|
-
type: "blob",
|
|
121
|
-
compression: "DEFLATE",
|
|
122
|
-
mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
123
|
-
});
|
|
116
|
+
return (await buildWorkbook(sheets)).toBlob("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
124
117
|
};
|
|
125
118
|
/**
|
|
126
119
|
* As createXlsx, but returns raw bytes instead of a Blob — for server-side
|
|
127
120
|
* callers that need to stream or write the workbook rather than download it.
|
|
128
121
|
*/
|
|
129
122
|
const createXlsxBytes = async (sheets) => {
|
|
130
|
-
return (await buildWorkbook(sheets)).
|
|
131
|
-
type: "uint8array",
|
|
132
|
-
compression: "DEFLATE"
|
|
133
|
-
});
|
|
123
|
+
return (await buildWorkbook(sheets)).toBytes();
|
|
134
124
|
};
|
|
135
125
|
//#endregion
|
|
136
126
|
export { createXlsx, createXlsxBytes };
|