@absolutejs/voice 0.0.22-beta.423 → 0.0.22-beta.425
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/dist/index.js +75 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -28751,6 +28751,57 @@ var listRecentJsonFiles = async (directory, limit) => {
|
|
|
28751
28751
|
if (limit === 0) {
|
|
28752
28752
|
return [];
|
|
28753
28753
|
}
|
|
28754
|
+
const indexedFiles = await readRecentJsonFileIndex(directory);
|
|
28755
|
+
if (indexedFiles.length >= limit) {
|
|
28756
|
+
const existingFiles = [];
|
|
28757
|
+
const missingPaths = new Set;
|
|
28758
|
+
for (const entry of indexedFiles) {
|
|
28759
|
+
try {
|
|
28760
|
+
await stat(entry.path);
|
|
28761
|
+
existingFiles.push(entry);
|
|
28762
|
+
if (existingFiles.length === limit) {
|
|
28763
|
+
break;
|
|
28764
|
+
}
|
|
28765
|
+
} catch (error) {
|
|
28766
|
+
if (error.code === "ENOENT") {
|
|
28767
|
+
missingPaths.add(entry.path);
|
|
28768
|
+
continue;
|
|
28769
|
+
}
|
|
28770
|
+
throw error;
|
|
28771
|
+
}
|
|
28772
|
+
}
|
|
28773
|
+
if (missingPaths.size > 0) {
|
|
28774
|
+
await writeRecentJsonFileIndex(directory, indexedFiles.filter((entry) => !missingPaths.has(entry.path)));
|
|
28775
|
+
}
|
|
28776
|
+
if (existingFiles.length === limit) {
|
|
28777
|
+
return existingFiles.map((entry) => entry.path);
|
|
28778
|
+
}
|
|
28779
|
+
}
|
|
28780
|
+
return (await rebuildRecentJsonFileIndex(directory)).slice(0, limit).map((entry) => entry.path);
|
|
28781
|
+
};
|
|
28782
|
+
var recentJsonFileIndexPath = (directory) => join2(directory, ".recent-index");
|
|
28783
|
+
var sortRecentJsonFileIndexEntries = (entries) => entries.sort((left, right) => right.updatedAt - left.updatedAt);
|
|
28784
|
+
var readRecentJsonFileIndex = async (directory) => {
|
|
28785
|
+
try {
|
|
28786
|
+
const payload = await readJsonFile(recentJsonFileIndexPath(directory)) ?? { files: [] };
|
|
28787
|
+
return sortRecentJsonFileIndexEntries(Array.isArray(payload.files) ? payload.files : []);
|
|
28788
|
+
} catch (error) {
|
|
28789
|
+
if (error.code === "ENOENT") {
|
|
28790
|
+
return [];
|
|
28791
|
+
}
|
|
28792
|
+
throw error;
|
|
28793
|
+
}
|
|
28794
|
+
};
|
|
28795
|
+
var writeRecentJsonFileIndex = async (directory, files) => {
|
|
28796
|
+
await mkdir3(directory, {
|
|
28797
|
+
recursive: true
|
|
28798
|
+
});
|
|
28799
|
+
await writeFile(recentJsonFileIndexPath(directory), JSON.stringify({
|
|
28800
|
+
files: sortRecentJsonFileIndexEntries(files).slice(0, 5000),
|
|
28801
|
+
version: 1
|
|
28802
|
+
}));
|
|
28803
|
+
};
|
|
28804
|
+
var rebuildRecentJsonFileIndex = async (directory) => {
|
|
28754
28805
|
const files = await listJsonFiles(directory);
|
|
28755
28806
|
const candidates = await Promise.all(files.map(async (path) => {
|
|
28756
28807
|
try {
|
|
@@ -28765,7 +28816,21 @@ var listRecentJsonFiles = async (directory, limit) => {
|
|
|
28765
28816
|
throw error;
|
|
28766
28817
|
}
|
|
28767
28818
|
}));
|
|
28768
|
-
|
|
28819
|
+
const entries = sortRecentJsonFileIndexEntries(candidates.filter((candidate) => Boolean(candidate)));
|
|
28820
|
+
await writeRecentJsonFileIndex(directory, entries);
|
|
28821
|
+
return entries;
|
|
28822
|
+
};
|
|
28823
|
+
var updateRecentJsonFileIndex = async (directory, path) => {
|
|
28824
|
+
const files = (await readRecentJsonFileIndex(directory)).filter((entry) => entry.path !== path);
|
|
28825
|
+
files.push({
|
|
28826
|
+
path,
|
|
28827
|
+
updatedAt: Date.now()
|
|
28828
|
+
});
|
|
28829
|
+
await writeRecentJsonFileIndex(directory, files);
|
|
28830
|
+
};
|
|
28831
|
+
var removeRecentJsonFileIndexEntry = async (directory, path) => {
|
|
28832
|
+
const files = (await readRecentJsonFileIndex(directory)).filter((entry) => entry.path !== path);
|
|
28833
|
+
await writeRecentJsonFileIndex(directory, files);
|
|
28769
28834
|
};
|
|
28770
28835
|
var shouldUseRecentReadWindow = (filter) => filter.readWindow === "recent" && typeof filter.limit === "number" && filter.limit >= 0;
|
|
28771
28836
|
var omitReadWindow = (filter) => {
|
|
@@ -28965,7 +29030,9 @@ var createVoiceFileExternalObjectMapStore = (options) => {
|
|
|
28965
29030
|
var createVoiceFileTraceEventStore = (options) => {
|
|
28966
29031
|
const append = async (event) => {
|
|
28967
29032
|
const stored = createVoiceTraceEvent(event);
|
|
28968
|
-
|
|
29033
|
+
const path = resolveFilePath(options.directory, stored.id);
|
|
29034
|
+
await writeJsonFile(path, stored, options);
|
|
29035
|
+
await updateRecentJsonFileIndex(options.directory, path);
|
|
28969
29036
|
return stored;
|
|
28970
29037
|
};
|
|
28971
29038
|
const get = async (id) => {
|
|
@@ -28985,9 +29052,11 @@ var createVoiceFileTraceEventStore = (options) => {
|
|
|
28985
29052
|
return filterVoiceTraceEvents(events, omitReadWindow(filter));
|
|
28986
29053
|
};
|
|
28987
29054
|
const remove = async (id) => {
|
|
28988
|
-
|
|
29055
|
+
const path = resolveFilePath(options.directory, id);
|
|
29056
|
+
await rm(path, {
|
|
28989
29057
|
force: true
|
|
28990
29058
|
});
|
|
29059
|
+
await removeRecentJsonFileIndexEntry(options.directory, path);
|
|
28991
29060
|
};
|
|
28992
29061
|
return { append, get, list, remove };
|
|
28993
29062
|
};
|
|
@@ -29035,7 +29104,9 @@ var createVoiceFileAuditEventStore = (options) => {
|
|
|
29035
29104
|
};
|
|
29036
29105
|
const append = async (event) => {
|
|
29037
29106
|
const stored = createVoiceAuditEvent(event);
|
|
29038
|
-
|
|
29107
|
+
const path = resolveFilePath(options.directory, stored.id);
|
|
29108
|
+
await writeJsonFile(path, stored, options);
|
|
29109
|
+
await updateRecentJsonFileIndex(options.directory, path);
|
|
29039
29110
|
return stored;
|
|
29040
29111
|
};
|
|
29041
29112
|
const list = async (filter) => {
|