@absolutejs/voice 0.0.22-beta.427 → 0.0.22-beta.429

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 (2) hide show
  1. package/dist/index.js +30 -27
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -28752,29 +28752,7 @@ var listRecentJsonFiles = async (directory, limit) => {
28752
28752
  }
28753
28753
  const indexedFiles = await readRecentJsonFileIndex(directory);
28754
28754
  if (indexedFiles.length >= limit) {
28755
- const existingFiles = [];
28756
- const missingPaths = new Set;
28757
- for (const entry of indexedFiles) {
28758
- try {
28759
- await stat(entry.path);
28760
- existingFiles.push(entry);
28761
- if (existingFiles.length === limit) {
28762
- break;
28763
- }
28764
- } catch (error) {
28765
- if (error.code === "ENOENT") {
28766
- missingPaths.add(entry.path);
28767
- continue;
28768
- }
28769
- throw error;
28770
- }
28771
- }
28772
- if (missingPaths.size > 0) {
28773
- await writeRecentJsonFileIndex(directory, indexedFiles.filter((entry) => !missingPaths.has(entry.path)));
28774
- }
28775
- if (existingFiles.length === limit) {
28776
- return existingFiles.map((entry) => entry.path);
28777
- }
28755
+ return indexedFiles.slice(0, limit).map((entry) => entry.path);
28778
28756
  }
28779
28757
  return (await rebuildRecentJsonFileIndex(directory)).slice(0, limit).map((entry) => entry.path);
28780
28758
  };
@@ -28834,6 +28812,33 @@ var removeRecentJsonFileIndexEntry = async (directory, path) => {
28834
28812
  const files = (await readRecentJsonFileIndex(directory)).filter((entry) => entry.path !== path);
28835
28813
  await writeRecentJsonFileIndex(directory, files);
28836
28814
  };
28815
+ var isDefined = (value) => value !== undefined;
28816
+ var readRecentJsonFiles = async (directory, limit) => {
28817
+ const files = await listRecentJsonFiles(directory, limit);
28818
+ const missingPaths = new Set;
28819
+ const readRecentFile = async (file) => {
28820
+ try {
28821
+ return await readJsonFile(file);
28822
+ } catch (error) {
28823
+ if (error.code === "ENOENT") {
28824
+ missingPaths.add(file);
28825
+ return;
28826
+ }
28827
+ throw error;
28828
+ }
28829
+ };
28830
+ const records = await Promise.all(files.map((file) => readRecentFile(file)));
28831
+ if (missingPaths.size > 0) {
28832
+ await writeRecentJsonFileIndex(directory, (await readRecentJsonFileIndex(directory)).filter((entry) => !missingPaths.has(entry.path)));
28833
+ }
28834
+ const existingRecords = records.filter(isDefined);
28835
+ if (existingRecords.length === limit || missingPaths.size === 0) {
28836
+ return existingRecords;
28837
+ }
28838
+ const rebuiltFiles = (await rebuildRecentJsonFileIndex(directory)).slice(0, limit).map((entry) => entry.path);
28839
+ const rebuiltRecords = await Promise.all(rebuiltFiles.map((file) => readRecentFile(file)));
28840
+ return rebuiltRecords.filter(isDefined);
28841
+ };
28837
28842
  var shouldUseRecentReadWindow = (filter) => filter.readWindow === "recent" && typeof filter.limit === "number" && filter.limit >= 0;
28838
28843
  var omitReadWindow = (filter) => {
28839
28844
  const { readWindow: _readWindow, ...next } = filter;
@@ -29049,8 +29054,7 @@ var createVoiceFileTraceEventStore = (options) => {
29049
29054
  }
29050
29055
  };
29051
29056
  const list = async (filter = {}) => {
29052
- const files = shouldUseRecentReadWindow(filter) ? await listRecentJsonFiles(options.directory, filter.limit) : await listJsonFiles(options.directory);
29053
- const events = await Promise.all(files.map((file) => readJsonFile(file)));
29057
+ const events = shouldUseRecentReadWindow(filter) ? await readRecentJsonFiles(options.directory, filter.limit) : await Promise.all((await listJsonFiles(options.directory)).map((file) => readJsonFile(file)));
29054
29058
  return filterVoiceTraceEvents(events, omitReadWindow(filter));
29055
29059
  };
29056
29060
  const remove = async (id) => {
@@ -29113,8 +29117,7 @@ var createVoiceFileAuditEventStore = (options) => {
29113
29117
  };
29114
29118
  const list = async (filter) => {
29115
29119
  const resolvedFilter = filter ?? {};
29116
- const files = shouldUseRecentReadWindow(resolvedFilter) ? await listRecentJsonFiles(options.directory, resolvedFilter.limit) : await listJsonFiles(options.directory);
29117
- const events = await Promise.all(files.map((file) => readJsonFile(file)));
29120
+ const events = shouldUseRecentReadWindow(resolvedFilter) ? await readRecentJsonFiles(options.directory, resolvedFilter.limit) : await Promise.all((await listJsonFiles(options.directory)).map((file) => readJsonFile(file)));
29118
29121
  return filterVoiceAuditEvents(events, omitReadWindow(resolvedFilter));
29119
29122
  };
29120
29123
  return { append, get, list };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@absolutejs/voice",
3
- "version": "0.0.22-beta.427",
3
+ "version": "0.0.22-beta.429",
4
4
  "description": "Voice primitives and Elysia plugin for AbsoluteJS",
5
5
  "repository": {
6
6
  "type": "git",