@ak--47/dungeon-master 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/storage.js +14 -4
- package/package.json +1 -1
package/lib/core/storage.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
/** @typedef {import('../../types.js').Storage} Storage */
|
|
9
9
|
/** @typedef {import('../../types.js').hookArrayOptions<any>} hookArrayOptions */
|
|
10
10
|
|
|
11
|
-
import { existsSync } from "fs";
|
|
11
|
+
import { existsSync, mkdirSync } from "fs";
|
|
12
12
|
import pLimit from 'p-limit';
|
|
13
13
|
import os from "os";
|
|
14
14
|
import path from "path";
|
|
@@ -60,8 +60,13 @@ export async function createHookArray(arr = [], opts) {
|
|
|
60
60
|
writeDir = path.resolve(os.tmpdir());
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
if (typeof config.writeToDisk === "string"
|
|
64
|
-
|
|
63
|
+
if (typeof config.writeToDisk === "string") {
|
|
64
|
+
if (config.writeToDisk.startsWith('gs://')) {
|
|
65
|
+
writeDir = config.writeToDisk;
|
|
66
|
+
} else {
|
|
67
|
+
writeDir = path.resolve(config.writeToDisk);
|
|
68
|
+
if (!existsSync(writeDir)) mkdirSync(writeDir, { recursive: true });
|
|
69
|
+
}
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
function getWritePath() {
|
|
@@ -213,7 +218,7 @@ export async function createHookArray(arr = [], opts) {
|
|
|
213
218
|
while (isWriting) {
|
|
214
219
|
await new Promise(resolve => setTimeout(resolve, 10));
|
|
215
220
|
}
|
|
216
|
-
|
|
221
|
+
|
|
217
222
|
isWriting = true;
|
|
218
223
|
try {
|
|
219
224
|
batch++;
|
|
@@ -221,6 +226,11 @@ export async function createHookArray(arr = [], opts) {
|
|
|
221
226
|
const dataToWrite = [...arr];
|
|
222
227
|
arr.length = 0; // Clear array after copying data
|
|
223
228
|
await FILE_CONN(() => writeToDisk(dataToWrite, { writePath }));
|
|
229
|
+
// Data now lives on disk, not in arr — mirror what transformThenPush
|
|
230
|
+
// does when crossing BATCH_SIZE so the Mixpanel sender knows to read
|
|
231
|
+
// from disk instead of from the (now empty) in-memory array.
|
|
232
|
+
isBatchMode = true;
|
|
233
|
+
runtime.isBatchMode = true;
|
|
224
234
|
} finally {
|
|
225
235
|
isWriting = false;
|
|
226
236
|
}
|