@8ms/helpers 3.2.7 → 3.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/AGENTS.md +20 -0
  2. package/dist/aws/s3/{server → _shared}/awsS3File.cjs +1 -1
  3. package/dist/aws/s3/{server → _shared}/awsS3File.d.cts +1 -1
  4. package/dist/aws/s3/{server → _shared}/awsS3File.d.mts +1 -1
  5. package/dist/aws/s3/{server → _shared}/awsS3File.mjs +1 -1
  6. package/dist/aws/s3/_shared/index.cjs +3 -0
  7. package/dist/aws/s3/_shared/index.d.cts +3 -0
  8. package/dist/aws/s3/_shared/index.d.mts +3 -0
  9. package/dist/aws/s3/_shared/index.mjs +2 -0
  10. package/dist/aws/s3/_shared/types.cjs +0 -0
  11. package/dist/aws/s3/_shared/types.d.cts +35 -0
  12. package/dist/aws/s3/_shared/types.d.mts +35 -0
  13. package/dist/aws/s3/_shared/types.mjs +1 -0
  14. package/dist/aws/s3/server/AwsS3.cjs +82 -3
  15. package/dist/aws/s3/server/AwsS3.d.cts +19 -26
  16. package/dist/aws/s3/server/AwsS3.d.mts +19 -26
  17. package/dist/aws/s3/server/AwsS3.mjs +80 -1
  18. package/dist/aws/s3/server/index.cjs +3 -2
  19. package/dist/aws/s3/server/index.d.cts +4 -3
  20. package/dist/aws/s3/server/index.d.mts +4 -3
  21. package/dist/aws/s3/server/index.mjs +2 -1
  22. package/dist/file/_shared/dataFileType.cjs +2 -0
  23. package/dist/file/_shared/dataFileType.d.cts +2 -0
  24. package/dist/file/_shared/dataFileType.d.mts +2 -0
  25. package/dist/file/_shared/dataFileType.mjs +2 -0
  26. package/dist/file/_shared/fileMimeType.cjs +2 -0
  27. package/dist/file/_shared/fileMimeType.mjs +2 -0
  28. package/dist/file/_shared/fileType.d.cts +2 -0
  29. package/dist/file/_shared/fileType.d.mts +2 -0
  30. package/dist/googleCloud/bigquery/_shared/index.d.cts +2 -2
  31. package/dist/googleCloud/bigquery/_shared/index.d.mts +2 -2
  32. package/dist/googleCloud/bigquery/_shared/types.d.cts +43 -0
  33. package/dist/googleCloud/bigquery/_shared/types.d.mts +43 -0
  34. package/dist/googleCloud/bigquery/client/index.d.cts +2 -2
  35. package/dist/googleCloud/bigquery/client/index.d.mts +2 -2
  36. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.cjs +148 -7
  37. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.d.cts +47 -31
  38. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.d.mts +47 -31
  39. package/dist/googleCloud/bigquery/server/GoogleCloudBigquery.mjs +148 -7
  40. package/dist/googleCloud/bigquery/server/index.d.cts +3 -3
  41. package/dist/googleCloud/bigquery/server/index.d.mts +3 -3
  42. package/dist/googleCloud/drive/server/GoogleCloudDrive.cjs +85 -0
  43. package/dist/googleCloud/drive/server/GoogleCloudDrive.d.cts +34 -0
  44. package/dist/googleCloud/drive/server/GoogleCloudDrive.d.mts +34 -0
  45. package/dist/googleCloud/drive/server/GoogleCloudDrive.mjs +85 -0
  46. package/dist/stream/server/index.cjs +11 -0
  47. package/dist/stream/server/index.d.cts +4 -1
  48. package/dist/stream/server/index.d.mts +4 -1
  49. package/dist/stream/server/index.mjs +4 -1
  50. package/dist/stream/server/json/logic.cjs +18 -0
  51. package/dist/stream/server/json/logic.d.cts +27 -0
  52. package/dist/stream/server/json/logic.d.mts +27 -0
  53. package/dist/stream/server/json/logic.mjs +16 -0
  54. package/dist/stream/server/json/read.cjs +46 -0
  55. package/dist/stream/server/json/read.d.cts +7 -0
  56. package/dist/stream/server/json/read.d.mts +7 -0
  57. package/dist/stream/server/json/read.mjs +42 -0
  58. package/dist/stream/server/json/write.cjs +69 -0
  59. package/dist/stream/server/json/write.d.cts +14 -0
  60. package/dist/stream/server/json/write.d.mts +14 -0
  61. package/dist/stream/server/json/write.mjs +63 -0
  62. package/dist/stream/server/sort.cjs +12 -23
  63. package/dist/stream/server/sort.d.cts +10 -6
  64. package/dist/stream/server/sort.d.mts +10 -6
  65. package/dist/stream/server/sort.mjs +12 -23
  66. package/package.json +33 -5
@@ -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
- const batch = 15e3;
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
- a;
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
- _transform(data, _, callback) {
22
- if (data) {
23
- this.a[this.i++] = data;
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.sortedArray = this.a.slice(0, this.i).sort(this.comp);
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 a;
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
- _transform(data: T, _: BufferEncoding, callback: TransformCallback): void;
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 a;
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
- _transform(data: T, _: BufferEncoding, callback: TransformCallback): void;
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
- const batch = 15e3;
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
- a;
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
- _transform(data, _, callback) {
21
- if (data) {
22
- this.a[this.i++] = data;
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.sortedArray = this.a.slice(0, this.i).sort(this.comp);
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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "3.2.7",
4
+ "version": "3.2.9",
5
5
  "packageManager": "yarn@4.18.0",
6
6
  "repository": {
7
7
  "type": "git",
@@ -77,6 +77,7 @@
77
77
  "pg": "^8.0.0",
78
78
  "react": "^19.0.0",
79
79
  "react-intersection-observer": "^11.0.0",
80
+ "stream-json": "^3.7.0",
80
81
  "swr": "^2.0.0",
81
82
  "tailwind-merge": "^3.0.0"
82
83
  },
@@ -183,6 +184,9 @@
183
184
  "react": {
184
185
  "optional": true
185
186
  },
187
+ "stream-json": {
188
+ "optional": true
189
+ },
186
190
  "swr": {
187
191
  "optional": true
188
192
  },
@@ -238,6 +242,7 @@
238
242
  "pg": "^8.23.0",
239
243
  "react": "^19.3.0",
240
244
  "react-intersection-observer": "^11.0.1",
245
+ "stream-json": "^3.7.0",
241
246
  "swr": "^2.5.1",
242
247
  "tailwind-merge": "^3.7.0",
243
248
  "ts-node": "^10.9.2",
@@ -430,6 +435,18 @@
430
435
  "import": "./dist/aws/lambda/server/getHandlerPath.mjs",
431
436
  "require": "./dist/aws/lambda/server/getHandlerPath.cjs"
432
437
  },
438
+ "./aws/s3/_shared": {
439
+ "import": "./dist/aws/s3/_shared/index.mjs",
440
+ "require": "./dist/aws/s3/_shared/index.cjs"
441
+ },
442
+ "./aws/s3/_shared/awsS3File": {
443
+ "import": "./dist/aws/s3/_shared/awsS3File.mjs",
444
+ "require": "./dist/aws/s3/_shared/awsS3File.cjs"
445
+ },
446
+ "./aws/s3/_shared/types": {
447
+ "import": "./dist/aws/s3/_shared/types.mjs",
448
+ "require": "./dist/aws/s3/_shared/types.cjs"
449
+ },
433
450
  "./aws/s3/server": {
434
451
  "import": "./dist/aws/s3/server/index.mjs",
435
452
  "require": "./dist/aws/s3/server/index.cjs"
@@ -438,10 +455,6 @@
438
455
  "import": "./dist/aws/s3/server/AwsS3.mjs",
439
456
  "require": "./dist/aws/s3/server/AwsS3.cjs"
440
457
  },
441
- "./aws/s3/server/awsS3File": {
442
- "import": "./dist/aws/s3/server/awsS3File.mjs",
443
- "require": "./dist/aws/s3/server/awsS3File.cjs"
444
- },
445
458
  "./aws/s3/server/payload": {
446
459
  "import": "./dist/aws/s3/server/payload.mjs",
447
460
  "require": "./dist/aws/s3/server/payload.cjs"
@@ -1542,6 +1555,18 @@
1542
1555
  "import": "./dist/stream/server/index.mjs",
1543
1556
  "require": "./dist/stream/server/index.cjs"
1544
1557
  },
1558
+ "./stream/server/json/logic": {
1559
+ "import": "./dist/stream/server/json/logic.mjs",
1560
+ "require": "./dist/stream/server/json/logic.cjs"
1561
+ },
1562
+ "./stream/server/json/read": {
1563
+ "import": "./dist/stream/server/json/read.mjs",
1564
+ "require": "./dist/stream/server/json/read.cjs"
1565
+ },
1566
+ "./stream/server/json/write": {
1567
+ "import": "./dist/stream/server/json/write.mjs",
1568
+ "require": "./dist/stream/server/json/write.cjs"
1569
+ },
1545
1570
  "./stream/server/sort": {
1546
1571
  "import": "./dist/stream/server/sort.mjs",
1547
1572
  "require": "./dist/stream/server/sort.cjs"
@@ -1847,5 +1872,8 @@
1847
1872
  "require": "./dist/zip/server/index.cjs"
1848
1873
  },
1849
1874
  "./package.json": "./package.json"
1875
+ },
1876
+ "inlinedDependencies": {
1877
+ "@google-cloud/paginator": "7.1.0"
1850
1878
  }
1851
1879
  }