@trebired/logger 2.0.0 → 2.1.1
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/CHANGELOG.md +19 -0
- package/README.md +15 -2
- package/dist/core/create_log.d.ts.map +1 -1
- package/dist/core/create_log.js +16 -0
- package/dist/core/create_log.js.map +1 -1
- package/dist/format/console.d.ts.map +1 -1
- package/dist/format/console.js +38 -4
- package/dist/format/console.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/storage/backend/index.d.ts +6 -0
- package/dist/storage/backend/index.d.ts.map +1 -0
- package/dist/storage/backend/index.js +19 -0
- package/dist/storage/backend/index.js.map +1 -0
- package/dist/storage/backend/js.d.ts +4 -0
- package/dist/storage/backend/js.d.ts.map +1 -0
- package/dist/storage/backend/js.js +179 -0
- package/dist/storage/backend/js.js.map +1 -0
- package/dist/storage/backend/native.d.ts +6 -0
- package/dist/storage/backend/native.d.ts.map +1 -0
- package/dist/storage/backend/native.js +89 -0
- package/dist/storage/backend/native.js.map +1 -0
- package/dist/storage/backend/types.d.ts +57 -0
- package/dist/storage/backend/types.d.ts.map +1 -0
- package/dist/storage/backend/types.js +2 -0
- package/dist/storage/backend/types.js.map +1 -0
- package/dist/storage/export.d.ts +5 -0
- package/dist/storage/export.d.ts.map +1 -0
- package/dist/storage/export.js +124 -0
- package/dist/storage/export.js.map +1 -0
- package/dist/storage/partitions/delete.d.ts +5 -0
- package/dist/storage/partitions/delete.d.ts.map +1 -0
- package/dist/storage/partitions/delete.js +121 -0
- package/dist/storage/partitions/delete.js.map +1 -0
- package/dist/storage/partitions/files.d.ts +12 -0
- package/dist/storage/partitions/files.d.ts.map +1 -0
- package/dist/storage/partitions/files.js +142 -0
- package/dist/storage/partitions/files.js.map +1 -0
- package/dist/storage/partitions/internal.d.ts +47 -0
- package/dist/storage/partitions/internal.d.ts.map +1 -0
- package/dist/storage/partitions/internal.js +35 -0
- package/dist/storage/partitions/internal.js.map +1 -0
- package/dist/storage/partitions/markers.d.ts +8 -0
- package/dist/storage/partitions/markers.d.ts.map +1 -0
- package/dist/storage/partitions/markers.js +88 -0
- package/dist/storage/partitions/markers.js.map +1 -0
- package/dist/storage/partitions/public.d.ts +11 -0
- package/dist/storage/partitions/public.d.ts.map +1 -0
- package/dist/storage/partitions/public.js +79 -0
- package/dist/storage/partitions/public.js.map +1 -0
- package/dist/storage/partitions/records.d.ts +9 -0
- package/dist/storage/partitions/records.d.ts.map +1 -0
- package/dist/storage/partitions/records.js +73 -0
- package/dist/storage/partitions/records.js.map +1 -0
- package/dist/storage/partitions/transforms.d.ts +6 -0
- package/dist/storage/partitions/transforms.d.ts.map +1 -0
- package/dist/storage/partitions/transforms.js +59 -0
- package/dist/storage/partitions/transforms.js.map +1 -0
- package/dist/storage/partitions.d.ts +3 -29
- package/dist/storage/partitions.d.ts.map +1 -1
- package/dist/storage/partitions.js +3 -563
- package/dist/storage/partitions.js.map +1 -1
- package/dist/types/browser.d.ts +54 -0
- package/dist/types/browser.d.ts.map +1 -0
- package/dist/types/browser.js +2 -0
- package/dist/types/browser.js.map +1 -0
- package/dist/types/common.d.ts +73 -0
- package/dist/types/common.d.ts.map +1 -0
- package/dist/types/common.js +2 -0
- package/dist/types/common.js.map +1 -0
- package/dist/types/export.d.ts +53 -0
- package/dist/types/export.d.ts.map +1 -0
- package/dist/types/export.js +2 -0
- package/dist/types/export.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/partitions.d.ts +92 -0
- package/dist/types/partitions.d.ts.map +1 -0
- package/dist/types/partitions.js +2 -0
- package/dist/types/partitions.js.map +1 -0
- package/dist/types/query.d.ts +49 -0
- package/dist/types/query.d.ts.map +1 -0
- package/dist/types/query.js +2 -0
- package/dist/types/query.js.map +1 -0
- package/dist/types/server.d.ts +79 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/server.js +2 -0
- package/dist/types/server.js.map +1 -0
- package/dist/types.d.ts +1 -326
- package/dist/types.d.ts.map +1 -1
- package/native/darwin-arm64.node +0 -0
- package/native/darwin-x64.node +0 -0
- package/native/linux-x64-gnu.node +0 -0
- package/package.json +16 -7
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ExportFormat } from "../../types.js";
|
|
2
|
+
type StorageBackendName = "native" | "js";
|
|
3
|
+
type StorageScanFile = {
|
|
4
|
+
absPath: string;
|
|
5
|
+
path: string;
|
|
6
|
+
partition: string;
|
|
7
|
+
groupKey: string;
|
|
8
|
+
day: string;
|
|
9
|
+
hour: string;
|
|
10
|
+
level: string;
|
|
11
|
+
compressed: boolean;
|
|
12
|
+
bytes: number;
|
|
13
|
+
rows: number;
|
|
14
|
+
};
|
|
15
|
+
type StorageScanPartition = {
|
|
16
|
+
name: string;
|
|
17
|
+
total: {
|
|
18
|
+
logs: number;
|
|
19
|
+
dirs: number;
|
|
20
|
+
files: number;
|
|
21
|
+
bytes: number;
|
|
22
|
+
};
|
|
23
|
+
lastActivityAt: string | null;
|
|
24
|
+
};
|
|
25
|
+
type StorageScanSnapshot = {
|
|
26
|
+
partitions: StorageScanPartition[];
|
|
27
|
+
files: StorageScanFile[];
|
|
28
|
+
total: {
|
|
29
|
+
partitions: number;
|
|
30
|
+
files: number;
|
|
31
|
+
logs: number;
|
|
32
|
+
bytes: number;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
type ArchiveGeneratedFile = {
|
|
36
|
+
archivePath: string;
|
|
37
|
+
content: string;
|
|
38
|
+
};
|
|
39
|
+
type ArchiveSourceFile = {
|
|
40
|
+
sourcePath: string;
|
|
41
|
+
archivePath: string;
|
|
42
|
+
};
|
|
43
|
+
type ArchiveCreateInput = {
|
|
44
|
+
outputPath: string;
|
|
45
|
+
format: ExportFormat;
|
|
46
|
+
rootName: string;
|
|
47
|
+
overwrite: boolean;
|
|
48
|
+
generatedFiles: ArchiveGeneratedFile[];
|
|
49
|
+
sourceFiles: ArchiveSourceFile[];
|
|
50
|
+
};
|
|
51
|
+
type StorageBackend = {
|
|
52
|
+
name: StorageBackendName;
|
|
53
|
+
scanPartitions(dir: string, partitions: string[]): Promise<StorageScanSnapshot>;
|
|
54
|
+
createArchive(input: ArchiveCreateInput): Promise<void>;
|
|
55
|
+
};
|
|
56
|
+
export type { ArchiveCreateInput, ArchiveGeneratedFile, ArchiveSourceFile, StorageBackend, StorageBackendName, StorageScanFile, StorageScanPartition, StorageScanSnapshot, };
|
|
57
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/storage/backend/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,KAAK,kBAAkB,GAAG,QAAQ,GAAG,IAAI,CAAC;AAE1C,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,UAAU,EAAE,oBAAoB,EAAE,CAAC;IACnC,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,KAAK,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,KAAK,oBAAoB,GAAG;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,EAAE,oBAAoB,EAAE,CAAC;IACvC,WAAW,EAAE,iBAAiB,EAAE,CAAC;CAClC,CAAC;AAEF,KAAK,cAAc,GAAG;IACpB,IAAI,EAAE,kBAAkB,CAAC;IACzB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAChF,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAEF,YAAY,EACV,kBAAkB,EAClB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,mBAAmB,GACpB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/storage/backend/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExportPartitionOptions, ExportPartitionsOptions, ExportResult } from "../types.js";
|
|
2
|
+
declare function exportPartitions(dir: string, options: ExportPartitionsOptions): Promise<ExportResult>;
|
|
3
|
+
declare function exportPartition(dir: string, partition: string, options: ExportPartitionOptions): Promise<ExportResult>;
|
|
4
|
+
export { exportPartition, exportPartitions };
|
|
5
|
+
//# sourceMappingURL=export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/storage/export.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAgC,sBAAsB,EAAE,uBAAuB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAoF/H,iBAAe,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,YAAY,CAAC,CA0CpG;AAED,iBAAe,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,YAAY,CAAC,CAKrH;AAED,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { toString } from "../utils/values.js";
|
|
4
|
+
import { getStorageBackend } from "./backend/index.js";
|
|
5
|
+
import { collectPartitionRecords } from "./partitions/records.js";
|
|
6
|
+
import { resolveDir } from "./partitions/internal.js";
|
|
7
|
+
import { sanitizePartitionName } from "./names.js";
|
|
8
|
+
function normalizeFormat(input) {
|
|
9
|
+
return input === "zip" ? "zip" : "tar.gz";
|
|
10
|
+
}
|
|
11
|
+
function stripArchiveExtension(fileName) {
|
|
12
|
+
if (fileName.endsWith(".tar.gz"))
|
|
13
|
+
return fileName.slice(0, -7);
|
|
14
|
+
if (fileName.endsWith(".zip"))
|
|
15
|
+
return fileName.slice(0, -4);
|
|
16
|
+
return fileName;
|
|
17
|
+
}
|
|
18
|
+
function normalizeOutputPath(options) {
|
|
19
|
+
const rawOutputPath = toString(options.outputPath).trim();
|
|
20
|
+
if (!rawOutputPath)
|
|
21
|
+
throw new Error("missing-export-output-path");
|
|
22
|
+
const format = normalizeFormat(options.format);
|
|
23
|
+
let outputPath = path.resolve(rawOutputPath);
|
|
24
|
+
if (!outputPath.endsWith(".tar.gz") && !outputPath.endsWith(".zip")) {
|
|
25
|
+
outputPath = `${outputPath}${format === "zip" ? ".zip" : ".tar.gz"}`;
|
|
26
|
+
}
|
|
27
|
+
if (format === "zip" && !outputPath.endsWith(".zip"))
|
|
28
|
+
throw new Error("export-format-output-extension-mismatch");
|
|
29
|
+
if (format === "tar.gz" && !outputPath.endsWith(".tar.gz"))
|
|
30
|
+
throw new Error("export-format-output-extension-mismatch");
|
|
31
|
+
return {
|
|
32
|
+
outputPath,
|
|
33
|
+
format,
|
|
34
|
+
overwrite: options.overwrite === true,
|
|
35
|
+
rootName: stripArchiveExtension(path.basename(outputPath)),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function buildManifest(dir, snapshot) {
|
|
39
|
+
return {
|
|
40
|
+
version: 1,
|
|
41
|
+
generated_at: new Date().toISOString(),
|
|
42
|
+
dir,
|
|
43
|
+
partitions: snapshot.partitions.map((item) => item.name),
|
|
44
|
+
partition_items: snapshot.partitions.map((item) => ({
|
|
45
|
+
name: item.name,
|
|
46
|
+
total: item.total,
|
|
47
|
+
last_activity_at: item.lastActivityAt,
|
|
48
|
+
})),
|
|
49
|
+
total: snapshot.total,
|
|
50
|
+
files: snapshot.files.map((file) => ({
|
|
51
|
+
path: file.path,
|
|
52
|
+
partition: file.partition,
|
|
53
|
+
groupKey: file.groupKey,
|
|
54
|
+
day: file.day,
|
|
55
|
+
hour: file.hour,
|
|
56
|
+
level: file.level,
|
|
57
|
+
compressed: file.compressed,
|
|
58
|
+
bytes: file.bytes,
|
|
59
|
+
rows: file.rows,
|
|
60
|
+
})),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async function resolvePartitions(dir, options) {
|
|
64
|
+
const records = await collectPartitionRecords(dir);
|
|
65
|
+
const allNames = records.map((item) => item.name).sort((a, b) => a.localeCompare(b));
|
|
66
|
+
if (!(options && Object.prototype.hasOwnProperty.call(options, "partitions")))
|
|
67
|
+
return allNames;
|
|
68
|
+
const requested = Array.from(new Set((options?.partitions || []).map((item) => sanitizePartitionName(item))));
|
|
69
|
+
if (!requested.length)
|
|
70
|
+
throw new Error("export-partitions-empty");
|
|
71
|
+
for (const name of requested) {
|
|
72
|
+
if (!allNames.includes(name))
|
|
73
|
+
throw new Error(`partition-not-found: ${name}`);
|
|
74
|
+
}
|
|
75
|
+
return requested.sort((a, b) => a.localeCompare(b));
|
|
76
|
+
}
|
|
77
|
+
async function exportPartitions(dir, options) {
|
|
78
|
+
const baseDir = resolveDir(dir);
|
|
79
|
+
if (!baseDir)
|
|
80
|
+
throw new Error("missing-log-dir");
|
|
81
|
+
const normalized = normalizeOutputPath(options);
|
|
82
|
+
const partitions = await resolvePartitions(baseDir, options);
|
|
83
|
+
const backend = getStorageBackend();
|
|
84
|
+
const snapshot = await backend.scanPartitions(baseDir, partitions);
|
|
85
|
+
const manifest = buildManifest(baseDir, snapshot);
|
|
86
|
+
if (fs.existsSync(normalized.outputPath) && !normalized.overwrite) {
|
|
87
|
+
throw new Error(`export-output-already-exists: ${normalized.outputPath}`);
|
|
88
|
+
}
|
|
89
|
+
const generatedFiles = [
|
|
90
|
+
{
|
|
91
|
+
archivePath: "manifest.json",
|
|
92
|
+
content: `${JSON.stringify(manifest, null, 2)}\n`,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
await backend.createArchive({
|
|
96
|
+
outputPath: normalized.outputPath,
|
|
97
|
+
format: normalized.format,
|
|
98
|
+
rootName: normalized.rootName,
|
|
99
|
+
overwrite: normalized.overwrite,
|
|
100
|
+
generatedFiles,
|
|
101
|
+
sourceFiles: snapshot.files.map((file) => ({
|
|
102
|
+
sourcePath: file.absPath,
|
|
103
|
+
archivePath: path.posix.join("logs", file.path),
|
|
104
|
+
})),
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
path: normalized.outputPath,
|
|
108
|
+
format: normalized.format,
|
|
109
|
+
backend: backend.name,
|
|
110
|
+
partitions: manifest.partitions,
|
|
111
|
+
files: manifest.total.files,
|
|
112
|
+
logs: manifest.total.logs,
|
|
113
|
+
bytes: manifest.total.bytes,
|
|
114
|
+
manifest,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
async function exportPartition(dir, partition, options) {
|
|
118
|
+
return exportPartitions(dir, {
|
|
119
|
+
...options,
|
|
120
|
+
partitions: [sanitizePartitionName(partition)],
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
export { exportPartition, exportPartitions };
|
|
124
|
+
//# sourceMappingURL=export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/storage/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AASnD,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC5C,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,IAAI,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC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,GAAW,EAAE,SAAiB,EAAE,OAA+B;IAC5F,OAAO,gBAAgB,CAAC,GAAG,EAAE;QAC3B,GAAG,OAAO;QACV,UAAU,EAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;KAC/C,CAAC,CAAC;AACL,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { DeleteLogsOptions, DeleteLogsResult, DeletePartitionResult, DeletePartitionsOptions } from "../../types.js";
|
|
2
|
+
declare function deletePartitions(dir: string, options?: DeletePartitionsOptions): Promise<DeletePartitionResult>;
|
|
3
|
+
declare function deleteLogs(dir: string, options?: DeleteLogsOptions): Promise<DeleteLogsResult>;
|
|
4
|
+
export { deleteLogs, deletePartitions };
|
|
5
|
+
//# sourceMappingURL=delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/storage/partitions/delete.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAyE1H,iBAAe,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,uBAA4B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAoBlH;AAED,iBAAe,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqBjG;AAED,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { sanitizePartitionName } from "../names.js";
|
|
3
|
+
import { fileMatchesDeleteFilters, listTopLevelFiles, readLogRows } from "./files.js";
|
|
4
|
+
import { collectPartitionRecords, partitionInfoFromRecord, partitionMarkerMap } from "./records.js";
|
|
5
|
+
import { cutoffMsForDays, partitionAgeReferenceMs, resolveDir } from "./internal.js";
|
|
6
|
+
function sortPartitionCandidates(items) {
|
|
7
|
+
return items.sort((a, b) => a.info.name.localeCompare(b.info.name));
|
|
8
|
+
}
|
|
9
|
+
async function collectPartitionDeleteCandidates(dir, options = {}) {
|
|
10
|
+
const wanted = new Set((options.partitions || []).map((item) => sanitizePartitionName(item)));
|
|
11
|
+
const cutoff = cutoffMsForDays(options.olderThanDays);
|
|
12
|
+
const records = await collectPartitionRecords(dir);
|
|
13
|
+
const items = await Promise.all(records.map(async (record) => ({
|
|
14
|
+
record,
|
|
15
|
+
info: await partitionInfoFromRecord(record),
|
|
16
|
+
})));
|
|
17
|
+
return sortPartitionCandidates(items.filter(({ info }) => {
|
|
18
|
+
if (wanted.size && !wanted.has(info.name))
|
|
19
|
+
return false;
|
|
20
|
+
if (options.temporaryOnly === true && info.temporary !== true)
|
|
21
|
+
return false;
|
|
22
|
+
if (cutoff != null && partitionAgeReferenceMs(info) >= cutoff)
|
|
23
|
+
return false;
|
|
24
|
+
return true;
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
async function fileDeleteCandidates(dir, options = {}) {
|
|
28
|
+
const baseDir = resolveDir(dir);
|
|
29
|
+
if (!baseDir)
|
|
30
|
+
return [];
|
|
31
|
+
const markers = await partitionMarkerMap(baseDir);
|
|
32
|
+
const files = await listTopLevelFiles(baseDir);
|
|
33
|
+
const cutoff = cutoffMsForDays(options.olderThanDays);
|
|
34
|
+
const hasExplicitPartition = Object.prototype.hasOwnProperty.call(options, "partition");
|
|
35
|
+
const explicitPartition = hasExplicitPartition && options.partition != null ? sanitizePartitionName(options.partition) : options.partition;
|
|
36
|
+
const acrossPartitions = options.acrossPartitions === true || !hasExplicitPartition;
|
|
37
|
+
const out = [];
|
|
38
|
+
for (const file of files) {
|
|
39
|
+
if (!fileMatchesDeleteFilters(file, options))
|
|
40
|
+
continue;
|
|
41
|
+
if (!acrossPartitions) {
|
|
42
|
+
if (explicitPartition == null) {
|
|
43
|
+
if (file.partition != null)
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
else if (file.partition !== explicitPartition)
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
else if (hasExplicitPartition) {
|
|
50
|
+
if (explicitPartition == null) {
|
|
51
|
+
if (file.partition != null)
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
else if (file.partition !== explicitPartition)
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (options.temporaryOnly === true) {
|
|
58
|
+
if (!file.partition)
|
|
59
|
+
continue;
|
|
60
|
+
if (markers.get(file.partition)?.temporary !== true)
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
let stat;
|
|
64
|
+
try {
|
|
65
|
+
stat = await fs.promises.stat(file.absPath);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (cutoff != null && stat.mtimeMs >= cutoff)
|
|
71
|
+
continue;
|
|
72
|
+
out.push({
|
|
73
|
+
file,
|
|
74
|
+
bytes: stat.size,
|
|
75
|
+
logs: (await readLogRows(file.absPath, file.compressed)).length,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
async function deletePartitions(dir, options = {}) {
|
|
81
|
+
const candidates = await collectPartitionDeleteCandidates(dir, options);
|
|
82
|
+
let files = 0;
|
|
83
|
+
let logs = 0;
|
|
84
|
+
let bytes = 0;
|
|
85
|
+
for (const item of candidates) {
|
|
86
|
+
files += item.info.total.files;
|
|
87
|
+
logs += item.info.total.logs;
|
|
88
|
+
bytes += item.info.total.bytes;
|
|
89
|
+
await fs.promises.rm(item.record.path, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
partitions: candidates.length,
|
|
93
|
+
files,
|
|
94
|
+
logs,
|
|
95
|
+
bytes,
|
|
96
|
+
items: candidates.map((item) => item.info.name),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
async function deleteLogs(dir, options = {}) {
|
|
100
|
+
const candidates = await fileDeleteCandidates(dir, options);
|
|
101
|
+
const partitions = new Set();
|
|
102
|
+
for (const item of candidates) {
|
|
103
|
+
if (item.file.partition)
|
|
104
|
+
partitions.add(item.file.partition);
|
|
105
|
+
await fs.promises.rm(item.file.absPath, { force: true });
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
partitions: partitions.size,
|
|
109
|
+
files: candidates.length,
|
|
110
|
+
logs: candidates.reduce((sum, item) => sum + item.logs, 0),
|
|
111
|
+
bytes: candidates.reduce((sum, item) => sum + item.bytes, 0),
|
|
112
|
+
items: candidates.map((item) => ({
|
|
113
|
+
path: item.file.absPath,
|
|
114
|
+
partition: item.file.partition,
|
|
115
|
+
logs: item.logs,
|
|
116
|
+
bytes: item.bytes,
|
|
117
|
+
})),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export { deleteLogs, deletePartitions };
|
|
121
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/storage/partitions/delete.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAE,UAAU,EAA0D,MAAM,eAAe,CAAC;AAE7I,SAAS,uBAAuB,CAAC,KAAiC;IAChE,OAAO,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC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AC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC/B,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO;YACvB,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YAC9B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { DeleteLogsOptions, LogEntry } from "../../types.js";
|
|
2
|
+
import { type WalkedLogFile } from "../names.js";
|
|
3
|
+
import { type PartitionRecord } from "./internal.js";
|
|
4
|
+
declare function readLogRows(filePath: string, compressed: boolean): Promise<LogEntry[]>;
|
|
5
|
+
declare function writeLogRows(filePath: string, rows: LogEntry[], compressed: boolean): Promise<void>;
|
|
6
|
+
declare function collectPartitionFiles(record: PartitionRecord): Promise<WalkedLogFile[]>;
|
|
7
|
+
declare function findAvailableTargetPath(dir: string, file: WalkedLogFile): Promise<string>;
|
|
8
|
+
declare function writePartitionFiles(source: PartitionRecord, targetRoot: string, targetName: string, merge: boolean): Promise<void>;
|
|
9
|
+
declare function fileMatchesDeleteFilters(file: WalkedLogFile, options: DeleteLogsOptions): boolean;
|
|
10
|
+
declare function listTopLevelFiles(baseDir: string): Promise<WalkedLogFile[]>;
|
|
11
|
+
export { collectPartitionFiles, fileMatchesDeleteFilters, findAvailableTargetPath, listTopLevelFiles, readLogRows, writeLogRows, writePartitionFiles, };
|
|
12
|
+
//# sourceMappingURL=files.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../../src/storage/partitions/files.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGlE,OAAO,EAAuC,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAA+C,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAGlG,iBAAe,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAkBrF;AAED,iBAAe,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAQlG;AAED,iBAAe,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CA2BtF;AAED,iBAAe,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAWxF;AAED,iBAAe,mBAAmB,CAAC,MAAM,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAajI;AAED,iBAAS,wBAAwB,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAW1F;AAED,iBAAe,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAgC1E;AAED,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,mBAAmB,GACpB,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import zlib from "node:zlib";
|
|
4
|
+
import { PARTITION_MARKER_FILE } from "../../constants.js";
|
|
5
|
+
import { normGroup } from "../../groups.js";
|
|
6
|
+
import { toString } from "../../utils/values.js";
|
|
7
|
+
import { makeLogFileName, walkedFileFromPath } from "../names.js";
|
|
8
|
+
import { fileStamp, pathExists } from "./internal.js";
|
|
9
|
+
import { partitionMarkerMap } from "./records.js";
|
|
10
|
+
async function readLogRows(filePath, compressed) {
|
|
11
|
+
try {
|
|
12
|
+
const data = await fs.promises.readFile(filePath);
|
|
13
|
+
const text = compressed ? zlib.gunzipSync(data).toString("utf8") : data.toString("utf8");
|
|
14
|
+
if (!text.trim())
|
|
15
|
+
return [];
|
|
16
|
+
const rows = [];
|
|
17
|
+
for (const line of text.trim().split("\n")) {
|
|
18
|
+
try {
|
|
19
|
+
const parsed = JSON.parse(line);
|
|
20
|
+
if (parsed && typeof parsed === "object")
|
|
21
|
+
rows.push(parsed);
|
|
22
|
+
}
|
|
23
|
+
catch { }
|
|
24
|
+
}
|
|
25
|
+
return rows;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function writeLogRows(filePath, rows, compressed) {
|
|
32
|
+
const payload = rows.length ? `${rows.map((row) => JSON.stringify(row)).join("\n")}\n` : "";
|
|
33
|
+
if (compressed) {
|
|
34
|
+
const zipped = zlib.gzipSync(Buffer.from(payload, "utf8"));
|
|
35
|
+
await fs.promises.writeFile(filePath, zipped);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await fs.promises.writeFile(filePath, payload, "utf8");
|
|
39
|
+
}
|
|
40
|
+
async function collectPartitionFiles(record) {
|
|
41
|
+
const out = [];
|
|
42
|
+
const stack = [record.path];
|
|
43
|
+
while (stack.length) {
|
|
44
|
+
const current = stack.pop() || "";
|
|
45
|
+
let entries = [];
|
|
46
|
+
try {
|
|
47
|
+
entries = await fs.promises.readdir(current, { withFileTypes: true });
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
for (const entry of entries) {
|
|
53
|
+
const absPath = path.join(current, entry.name);
|
|
54
|
+
if (entry.isDirectory()) {
|
|
55
|
+
stack.push(absPath);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (!entry.isFile() || entry.name === PARTITION_MARKER_FILE)
|
|
59
|
+
continue;
|
|
60
|
+
const walked = walkedFileFromPath(record.path, absPath, record.name, record.path);
|
|
61
|
+
if (walked)
|
|
62
|
+
out.push(walked);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
out.sort((a, b) => a.absPath.localeCompare(b.absPath));
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
async function findAvailableTargetPath(dir, file) {
|
|
69
|
+
let sequence = file.sequence;
|
|
70
|
+
for (;;) {
|
|
71
|
+
const fileName = makeLogFileName(fileStamp(file), sequence, file.level);
|
|
72
|
+
const plainTarget = path.join(dir, fileName);
|
|
73
|
+
const gzipTarget = path.join(dir, `${fileName}.gz`);
|
|
74
|
+
if (!(await pathExists(plainTarget)) && !(await pathExists(gzipTarget))) {
|
|
75
|
+
return file.compressed ? gzipTarget : plainTarget;
|
|
76
|
+
}
|
|
77
|
+
sequence += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
async function writePartitionFiles(source, targetRoot, targetName, merge) {
|
|
81
|
+
const files = await collectPartitionFiles(source);
|
|
82
|
+
for (const file of files) {
|
|
83
|
+
const rows = await readLogRows(file.absPath, file.compressed);
|
|
84
|
+
const nextRows = rows.map((row) => ({ ...row, partition: targetName }));
|
|
85
|
+
const targetDir = file.groupDir ? path.join(targetRoot, file.groupDir) : targetRoot;
|
|
86
|
+
await fs.promises.mkdir(targetDir, { recursive: true });
|
|
87
|
+
const targetPath = merge
|
|
88
|
+
? await findAvailableTargetPath(targetDir, file)
|
|
89
|
+
: path.join(targetDir, path.basename(file.absPath));
|
|
90
|
+
await writeLogRows(targetPath, nextRows, file.compressed);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function fileMatchesDeleteFilters(file, options) {
|
|
94
|
+
const level = toString(options.level || "all").toLowerCase() || "all";
|
|
95
|
+
const groupKey = toString(options.groupKey || "all") || "all";
|
|
96
|
+
const day = toString(options.day);
|
|
97
|
+
const hour = toString(options.hour);
|
|
98
|
+
if (day && file.day !== day)
|
|
99
|
+
return false;
|
|
100
|
+
if (hour && file.hour !== hour)
|
|
101
|
+
return false;
|
|
102
|
+
if (groupKey !== "all" && file.groupKey !== normGroup(groupKey).key)
|
|
103
|
+
return false;
|
|
104
|
+
if (level !== "all" && file.level !== level)
|
|
105
|
+
return false;
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
async function listTopLevelFiles(baseDir) {
|
|
109
|
+
const out = [];
|
|
110
|
+
const stack = [{ dir: baseDir, rootDir: baseDir, partition: null }];
|
|
111
|
+
const markers = await partitionMarkerMap(baseDir);
|
|
112
|
+
while (stack.length) {
|
|
113
|
+
const current = stack.pop();
|
|
114
|
+
let entries = [];
|
|
115
|
+
try {
|
|
116
|
+
entries = await fs.promises.readdir(current.dir, { withFileTypes: true });
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
for (const entry of entries) {
|
|
122
|
+
const absPath = path.join(current.dir, entry.name);
|
|
123
|
+
if (entry.isDirectory()) {
|
|
124
|
+
if (current.partition == null && markers.has(entry.name)) {
|
|
125
|
+
stack.push({ dir: absPath, rootDir: absPath, partition: entry.name });
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
stack.push({ dir: absPath, rootDir: current.rootDir, partition: current.partition });
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!entry.isFile() || entry.name === PARTITION_MARKER_FILE)
|
|
132
|
+
continue;
|
|
133
|
+
const walked = walkedFileFromPath(current.rootDir, absPath, current.partition, current.rootDir);
|
|
134
|
+
if (walked)
|
|
135
|
+
out.push(walked);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
out.sort((a, b) => a.absPath.localeCompare(b.absPath));
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
export { collectPartitionFiles, fileMatchesDeleteFilters, findAvailableTargetPath, listTopLevelFiles, readLogRows, writeLogRows, writePartitionFiles, };
|
|
142
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../../src/storage/partitions/files.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAsB,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,UAAU,EAA8C,MAAM,eAAe,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,KAAK,UAAU,WAAW,CAAC,QAAgB,EAAE,UAAmB;IAC9D,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACzF,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YAAE,OAAO,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAe,EAAE,CAAC;QAE5B,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAC3C,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,IAAI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;IACH,CAAC;IAED,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;IACvD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,mBAAmB,GACpB,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { PartitionInfo } from "../../types.js";
|
|
2
|
+
import type { WalkedLogFile } from "../names.js";
|
|
3
|
+
type PartitionMarker = {
|
|
4
|
+
name: string;
|
|
5
|
+
temporary: boolean;
|
|
6
|
+
created_at: string;
|
|
7
|
+
updated_at: string;
|
|
8
|
+
};
|
|
9
|
+
type PartitionRecord = {
|
|
10
|
+
dir: string;
|
|
11
|
+
name: string;
|
|
12
|
+
path: string;
|
|
13
|
+
marker: PartitionMarker;
|
|
14
|
+
};
|
|
15
|
+
type PartitionWriteOptions = {
|
|
16
|
+
temporary?: boolean;
|
|
17
|
+
preserveTemporary?: boolean;
|
|
18
|
+
createdAt?: string;
|
|
19
|
+
updatedAt?: string;
|
|
20
|
+
preserveCreatedAt?: boolean;
|
|
21
|
+
};
|
|
22
|
+
type PartitionTransformOptions = {
|
|
23
|
+
source: PartitionRecord;
|
|
24
|
+
targetDir: string;
|
|
25
|
+
targetName: string;
|
|
26
|
+
deleteSource: boolean;
|
|
27
|
+
targetTemporary: boolean;
|
|
28
|
+
preserveSourceCreatedAt: boolean;
|
|
29
|
+
};
|
|
30
|
+
type PartitionDeleteCandidate = {
|
|
31
|
+
info: PartitionInfo;
|
|
32
|
+
record: PartitionRecord;
|
|
33
|
+
};
|
|
34
|
+
type DeleteLogCandidate = {
|
|
35
|
+
file: WalkedLogFile;
|
|
36
|
+
bytes: number;
|
|
37
|
+
logs: number;
|
|
38
|
+
};
|
|
39
|
+
declare function resolveDir(input: string): string;
|
|
40
|
+
declare function partitionRootPath(dir: string, partition: string): string;
|
|
41
|
+
declare function pathExists(targetPath: string): Promise<boolean>;
|
|
42
|
+
declare function fileStamp(file: WalkedLogFile): string;
|
|
43
|
+
declare function partitionAgeReferenceMs(info: PartitionInfo): number;
|
|
44
|
+
declare function cutoffMsForDays(days: number | undefined): number | null;
|
|
45
|
+
export { cutoffMsForDays, fileStamp, partitionAgeReferenceMs, partitionRootPath, pathExists, resolveDir, };
|
|
46
|
+
export type { DeleteLogCandidate, PartitionDeleteCandidate, PartitionMarker, PartitionRecord, PartitionTransformOptions, PartitionWriteOptions, };
|
|
47
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/storage/partitions/internal.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,KAAK,qBAAqB,GAAG;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF,KAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,eAAe,EAAE,OAAO,CAAC;IACzB,uBAAuB,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,KAAK,wBAAwB,GAAG;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGzC;AAED,iBAAS,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,iBAAe,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAO9D;AAED,iBAAS,SAAS,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAE9C;AAED,iBAAS,uBAAuB,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAI5D;AAED,iBAAS,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAIhE;AAED,OAAO,EACL,eAAe,EACf,SAAS,EACT,uBAAuB,EACvB,iBAAiB,EACjB,UAAU,EACV,UAAU,GACX,CAAC;AACF,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,eAAe,EACf,yBAAyB,EACzB,qBAAqB,GACtB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { toString } from "../../utils/values.js";
|
|
4
|
+
function resolveDir(input) {
|
|
5
|
+
const raw = toString(input).trim();
|
|
6
|
+
return raw ? path.resolve(raw) : "";
|
|
7
|
+
}
|
|
8
|
+
function partitionRootPath(dir, partition) {
|
|
9
|
+
return path.join(dir, partition);
|
|
10
|
+
}
|
|
11
|
+
async function pathExists(targetPath) {
|
|
12
|
+
try {
|
|
13
|
+
await fs.promises.access(targetPath);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function fileStamp(file) {
|
|
21
|
+
return `${file.day}-${file.hour}`;
|
|
22
|
+
}
|
|
23
|
+
function partitionAgeReferenceMs(info) {
|
|
24
|
+
const reference = info.last_activity_at || info.updated_at || info.created_at;
|
|
25
|
+
const parsed = Date.parse(reference);
|
|
26
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
27
|
+
}
|
|
28
|
+
function cutoffMsForDays(days) {
|
|
29
|
+
const value = Number(days);
|
|
30
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
31
|
+
return null;
|
|
32
|
+
return Date.now() - value * 24 * 60 * 60 * 1000;
|
|
33
|
+
}
|
|
34
|
+
export { cutoffMsForDays, fileStamp, partitionAgeReferenceMs, partitionRootPath, pathExists, resolveDir, };
|
|
35
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/storage/partitions/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AA6CjD,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IACnC,OAAO,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACtC,C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itionWriteOptions } from "./internal.js";
|
|
2
|
+
declare function readPartitionMarkerFromRoot(rootDir: string, expectedName?: string): Promise<PartitionMarker | null>;
|
|
3
|
+
declare function readPartitionMarkerFromRootSync(rootDir: string, expectedName?: string): PartitionMarker | null;
|
|
4
|
+
declare function writePartitionMarker(rootDir: string, marker: PartitionMarker): Promise<void>;
|
|
5
|
+
declare function touchPartitionMarker(dir: string, partition: string, options?: PartitionWriteOptions): Promise<PartitionMarker>;
|
|
6
|
+
declare function touchPartitionMarkerSync(dir: string, partition: string, options?: PartitionWriteOptions): PartitionMarker;
|
|
7
|
+
export { readPartitionMarkerFromRoot, readPartitionMarkerFromRootSync, touchPartitionMarker, touchPartitionMarkerSync, writePartitionMarker, };
|
|
8
|
+
//# sourceMappingURL=markers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markers.d.ts","sourceRoot":"","sources":["../../../src/storage/partitions/markers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiC,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAgBhH,iBAAe,2BAA2B,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAQlH;AAED,iBAAS,+BAA+B,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAQvG;AAkBD,iBAAe,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAG3F;AAOD,iBAAe,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,OAAO,CAAC,eAAe,CAAC,CASjI;AAED,iBAAS,wBAAwB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,GAAG,eAAe,CAStH;AAED,OAAO,EACL,2BAA2B,EAC3B,+BAA+B,EAC/B,oBAAoB,EACpB,wBAAwB,EACxB,oBAAoB,GACrB,CAAC"}
|