@redocly/replay 0.28.0-next.4 → 0.28.0-next.6
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/{replay-AiChatProvider-BIplPHOS.js → replay-AiChatProvider-Bj2P_hdU.js} +371 -369
- package/dist/replay-AiChatProvider-GeumgtIo.js +6 -0
- package/dist/{replay-AiChatSqliteDBStorage-Bay95FHW.js → replay-AiChatSqliteDBStorage-0M2Ejnzu.js} +1 -1
- package/dist/{replay-AiChatSqliteDBStorage-C-rkQ3jG.js → replay-AiChatSqliteDBStorage-BWJl1qdO.js} +1 -1
- package/dist/{replay-AiPanel-DU5aVA3q.js → replay-AiPanel-DfOpKMDQ.js} +709 -712
- package/dist/replay-AiPanel-ON_QfwBN.js +742 -0
- package/dist/replay-FileWatcher-04GlEkra.js +360 -0
- package/dist/replay-FileWatcher-B-T0jz_R.js +1 -0
- package/dist/{replay-SemanticSearchService-Dk4UTm2r.js → replay-SemanticSearchService-BQgdj2wy.js} +1 -1
- package/dist/{replay-SemanticSearchService-BWwCFW3F.js → replay-SemanticSearchService-CPIb_cUk.js} +7 -7
- package/dist/{replay-SqliteDBStorage-BFdjYsG7.js → replay-SqliteDBStorage-Bt2xXqei.js} +1 -1
- package/dist/{replay-SqliteDBStorage-DGQjzDy4.js → replay-SqliteDBStorage-vehgvWXZ.js} +1 -1
- package/dist/{replay-TauriFileSystemAdapter-CLzYSck7.js → replay-TauriFileSystemAdapter-D2yxrS6Q.js} +1 -1
- package/dist/{replay-TauriFileSystemAdapter-C8k9RvT1.js → replay-TauriFileSystemAdapter-YLdtT-Xp.js} +1 -1
- package/dist/{replay-TauriRootStorage-C1MIH5ji.js → replay-TauriRootStorage-BE6RmQfE.js} +162 -165
- package/dist/replay-TauriRootStorage-DcENVsBJ.js +1 -0
- package/dist/{replay-agent-loop-BoEw65rR.js → replay-agent-loop-CvopOugZ.js} +13 -13
- package/dist/{replay-agent-loop-Cm1iS9G2.js → replay-agent-loop-UwDSVh-4.js} +1 -1
- package/dist/{replay-ai-chat-mappers-IZNFNXug.js → replay-ai-chat-mappers-B7fm-v_w.js} +1 -1
- package/dist/{replay-ai-chat-mappers-Csm9vJrG.js → replay-ai-chat-mappers-yKBypIXh.js} +1 -1
- package/dist/{replay-create-model-BqvD-0wF.js → replay-create-model-CHahxEJy.js} +3 -3
- package/dist/{replay-create-model-Y9UJSztb.js → replay-create-model-CyBZMAWB.js} +4 -4
- package/dist/{replay-db-BImXgUGU.js → replay-db-CifZMdnr.js} +5 -5
- package/dist/{replay-db-C7FD3opa.js → replay-db-EWL-uAt-.js} +1 -1
- package/dist/{replay-external-resolver-CjM7Da6t.js → replay-external-resolver-D5fSfJEm.js} +1 -1
- package/dist/{replay-external-resolver-Bj3sLTnz.js → replay-external-resolver-G11iwLVZ.js} +2 -2
- package/dist/{replay-index-Dxk-kqkZ.js → replay-index-B2NUTBd8.js} +1 -1
- package/dist/{replay-index-CKRKzXMt.js → replay-index-B3MQaIS-.js} +1 -1
- package/dist/replay-index-Coy4kD_x.js +7009 -0
- package/dist/{replay-index-DJwfdo0s.js → replay-index-CqRiEj9e.js} +1 -1
- package/dist/{replay-index-DlTloE6S.js → replay-index-D0mbH_TN.js} +1 -1
- package/dist/{replay-index-Cp06WK82.js → replay-index-DDqKE6bs.js} +5 -5
- package/dist/{replay-index-xheWgsnj.js → replay-index-DrI9ZFwH.js} +2 -2
- package/dist/{replay-index-BH8cTSEK.js → replay-index-Dx8O3ZoA.js} +68783 -67874
- package/dist/{replay-lint-BIbkYU09.js → replay-lint-BiOcDIDr.js} +3 -3
- package/dist/{replay-lint--iBW-6Vj.js → replay-lint-CAo2fuiZ.js} +3 -3
- package/dist/{replay-lint-graphql-EXBI8I89.js → replay-lint-graphql-DAa8UNRg.js} +1 -1
- package/dist/{replay-lint-graphql-2b4GIER6.js → replay-lint-graphql-DzI2rUbR.js} +1 -1
- package/dist/replay-periodic-revalidation-D18ihfUc.js +1 -0
- package/dist/replay-periodic-revalidation-w7mrtjYg.js +22 -0
- package/dist/{replay-resolve-D9BUvjqv.js → replay-resolve-CojDRP37.js} +1 -1
- package/dist/{replay-resolve-B5yIfyuT.js → replay-resolve-DgAthAfi.js} +1 -1
- package/dist/{replay-respect-run-DNFoFnJU.js → replay-respect-run-3ukV7LMg.js} +1 -1
- package/dist/{replay-respect-run-Bx46aUHi.js → replay-respect-run-DNvB8rLX.js} +3 -3
- package/dist/replay-tauri-path-DM8PdMK8.js +22 -0
- package/dist/{replay-tauri-path-C8GiFO5s.js → replay-tauri-path-kr9DtxLs.js} +1 -1
- package/dist/{replay-useAiChatQueries-BTuu2xLG.js → replay-useAiChatQueries-BULoKr4E.js} +1564 -1395
- package/dist/replay-useAiChatQueries-BdjsFz1P.js +215 -0
- package/dist/{replay-validate-key-D4M7QvCw.js → replay-validate-key-CGmguj5X.js} +1 -1
- package/dist/{replay-validate-key-CjcIElmE.js → replay-validate-key-DzseOR5a.js} +2 -2
- package/dist/replay.cjs +1 -1
- package/dist/replay.d.ts +3 -3
- package/dist/replay.js +10 -10
- package/package.json +12 -5
- package/dist/replay-AiChatProvider-TF1u9E5L.js +0 -6
- package/dist/replay-AiPanel-DzGN1t86.js +0 -742
- package/dist/replay-FileWatcher-XMkIoDEA.js +0 -1
- package/dist/replay-FileWatcher-iYbHpwCv.js +0 -352
- package/dist/replay-TauriRootStorage-CiGY8MO6.js +0 -1
- package/dist/replay-index-BuYoH96w.js +0 -6982
- package/dist/replay-periodic-revalidation-BoyLQHtg.js +0 -1
- package/dist/replay-periodic-revalidation-Dsp-n7ui.js +0 -21
- package/dist/replay-tauri-path-BVoW6En0.js +0 -22
- package/dist/replay-useAiChatQueries-BDgjmzz-.js +0 -215
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./replay-index-BuYoH96w.js"),v=require("./replay-SemanticSearchService-Dk4UTm2r.js");require("react");var m;(function(r){r.WINDOW_RESIZED="tauri://resize",r.WINDOW_MOVED="tauri://move",r.WINDOW_CLOSE_REQUESTED="tauri://close-requested",r.WINDOW_DESTROYED="tauri://destroyed",r.WINDOW_FOCUS="tauri://focus",r.WINDOW_BLUR="tauri://blur",r.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",r.WINDOW_THEME_CHANGED="tauri://theme-changed",r.WINDOW_CREATED="tauri://window-created",r.WEBVIEW_CREATED="tauri://webview-created",r.DRAG_ENTER="tauri://drag-enter",r.DRAG_OVER="tauri://drag-over",r.DRAG_DROP="tauri://drag-drop",r.DRAG_LEAVE="tauri://drag-leave"})(m||(m={}));async function E(r,e){await l.invoke("plugin:event|unlisten",{event:r,eventId:e})}async function w(r,e,s){var t;const i=(t=void 0)!==null&&t!==void 0?t:{kind:"Any"};return l.invoke("plugin:event|listen",{event:r,target:i,handler:l.transformCallback(e)}).then(a=>async()=>E(r,a))}const p="replay-environments.yaml";class y{constructor(e,s,t,i){this.storage=e,this.state=s,this.projectDir=t,this.aiEnabled=i}storage;state;projectDir;aiEnabled;watchPath=null;unlistenEvent=null;get tauriStorage(){return this.storage}indexApis(e){!this.aiEnabled||e.length===0||v.getSemanticSearchService().indexApis(e).catch(s=>console.error("Semantic index (apis):",s))}indexCollections(e){!this.aiEnabled||e.length===0||v.getSemanticSearchService().indexCollections(e).catch(s=>console.error("Semantic index (collections):",s))}removeApis(e){if(!this.aiEnabled||e.length===0)return;const s=v.getSemanticSearchService();Promise.all(e.map(t=>s.removeApi(t))).catch(t=>console.error("Semantic remove (apis):",t))}removeCollections(e){if(!this.aiEnabled||e.length===0)return;const s=v.getSemanticSearchService();Promise.all(e.map(t=>s.removeCollection(t))).catch(t=>console.error("Semantic remove (collections):",t))}async start(){if(this.watchPath){console.warn("Watcher already started for:",this.watchPath);return}try{this.unlistenEvent=await w("fs-watch-event",async e=>{const s=e.payload;try{await this.handleEvent(s)}catch(t){console.error("Error handling file change:",t)}}),await l.invoke("fs_watch",{path:this.projectDir,options:{recursive:!0,delayMs:500}}),this.watchPath=this.projectDir}catch(e){throw console.error("Failed to start file watcher:",e),this.unlistenEvent&&(this.unlistenEvent(),this.unlistenEvent=null),e}}async stop(){if(this.watchPath)try{await l.invoke("fs_unwatch",{path:this.watchPath})}catch(e){console.error("Error stopping file watcher:",e)}finally{this.unlistenEvent&&(this.unlistenEvent(),this.unlistenEvent=null),this.watchPath=null}}async handleEvent(e){const{changeType:s,paths:t,pathTypes:i,type:a}=e;if(await this.isProjectFolderRemoved(t,s)){await this.handleProjectFolderRemoval();return}const o=this.filterSpecFiles(t,i);if(o.paths.length===0)return;const n=await this.toFileEntries(o.paths,o.pathTypes);switch(s){case"changed":(a.includes("Data")||a.includes("Name"))&&await this.handleModify(n);break;case"added":await this.handleCreate(n);break;case"deleted":await this.handleDelete(n);break;case"renamed":await this.handleRename(n);break;default:console.log("Unhandled change type:",s)}}filterSpecFiles(e,s){const t=[],i=[];for(let a=0;a<e.length;a++){const o=e[a],n=o.split(".").pop()?.toLowerCase();n&&["yaml","yml","json"].includes(n)&&(t.push(o),i.push(s[a]||"unknown"))}return{paths:t,pathTypes:i}}async toFileEntries(e,s){return Promise.all(e.map(async(t,i)=>({relative_path:await l.PathUtils.relative(this.projectDir,t),absolute_path:t,type:s[i]||"unknown"})))}hasEnvironmentsFileChange(e){return!this.storage.isWatchExcluded(p)&&e.some(s=>s.relative_path===p)}withoutEnvironmentsFile(e){return e.filter(s=>s.relative_path!==p)}consolidateFileEntries(e){const s=[],t=new Set;for(const i of e)t.has(i.relative_path)||(t.add(i.relative_path),this.storage.isWatchExcluded(i.relative_path)||s.push(i));return s}async handleModify(e){const s=this.hasEnvironmentsFileChange(e),t=this.withoutEnvironmentsFile(e),{newApiFiles:i,existingApiFiles:a}=this.categorizeApisFromFiles(t),{newCollectionFiles:o,existingCollectionFiles:n}=this.categorizeCollectionsFromFiles(t),d=await this.findApisToReload(e),h=await this.findCollectionsToReload(e),u=[...i,...o];u.length>0&&await this.handleCreate(u),s&&await this.reloadEnvironments();const g=this.consolidateFileEntries([...a,...d]),f=this.consolidateFileEntries([...n,...h]);await this.reloadApis(g),await this.reloadCollections(f)}async handleCreate(e){this.hasEnvironmentsFileChange(e)&&await this.reloadEnvironments();const s=this.withoutEnvironmentsFile(e),t=s.filter(h=>h.type==="api"),i=s.filter(h=>h.type==="collection"),{newApiFiles:a,existingApiFiles:o}=this.categorizeApisFromFiles(t),{newCollectionFiles:n,existingCollectionFiles:d}=this.categorizeCollectionsFromFiles(i);if(a.length>0||n.length>0){a.forEach(c=>this.storage.addPersistExcludedId(c.relative_path)),n.forEach(c=>this.storage.addPersistExcludedId(c.relative_path));const h=a.length>0?await this.tauriStorage.loadAndParseApis(a,void 0,!0):[],u=n.length>0?await this.tauriStorage.loadAndParseCollections(n,void 0):[],g=h.filter(c=>c!==null),f=u.filter(c=>c!==null);this.state.apis.merge(g),this.state.collections.merge(f),this.indexApis(g),this.indexCollections(f),setTimeout(()=>{a.forEach(c=>this.storage.removePersistExcludedId(c.relative_path)),n.forEach(c=>this.storage.removePersistExcludedId(c.relative_path))},500)}o.length>0&&await this.reloadApis(o),d.length>0&&await this.reloadCollections(d)}categorizeApisFromFiles(e){const s=new Set,t=[],i=[];for(const a of e){if(s.has(a.relative_path))continue;s.add(a.relative_path),this.state.apis.get({noproxy:!0}).some(n=>n.id===a.relative_path)?i.push(a):a.type==="api"&&t.push(a)}return{newApiFiles:t,existingApiFiles:i}}categorizeCollectionsFromFiles(e){const s=new Set,t=[],i=[];for(const a of e){if(s.has(a.relative_path))continue;s.add(a.relative_path),this.state.collections.get({noproxy:!0}).some(n=>n.id===a.relative_path)?i.push(a):a.type==="collection"&&t.push(a)}return{newCollectionFiles:t,existingCollectionFiles:i}}async handleDelete(e){this.hasEnvironmentsFileChange(e)&&await this.reloadEnvironments();const s=[],t=[];for(const i of this.withoutEnvironmentsFile(e)){this.storage.addPersistExcludedId(i.relative_path);const a=this.state.apis.get({noproxy:!0}).findIndex(n=>n.id===i.relative_path);a>=0&&(this.state.apis[a].set(l.none),this.tauriStorage.deleteApiFromCache(i.relative_path),s.push(i.relative_path));const o=this.state.collections.get({noproxy:!0}).findIndex(n=>n.id===i.relative_path);o>=0&&(this.state.collections[o].set(l.none),t.push(i.relative_path)),setTimeout(()=>{this.storage.removePersistExcludedId(i.relative_path)},500)}this.removeApis(s),this.removeCollections(t)}async handleRename(e){if(e.length>=2){const[s,t]=e;await this.handleDelete([s]),await this.handleCreate([t])}else await this.handleCreate(e)}async isProjectFolderRemoved(e,s){if(e.length===0)return!1;if(s==="deleted"||s==="renamed"){for(const i of e)if(i===this.projectDir)return!0}return e.filter(i=>!i.startsWith(this.projectDir+"/")&&i!==this.projectDir).length>0&&s==="renamed"}async handleProjectFolderRemoval(){const e=this.state.apis.get({noproxy:!0}),s=e.map(a=>a.id);e.forEach(a=>{this.storage.addPersistExcludedId(a.id),this.tauriStorage.deleteApiFromCache(a.id)}),this.state.apis.set([]);const t=this.state.collections.get({noproxy:!0}),i=t.map(a=>a.id);t.forEach(a=>{this.storage.addPersistExcludedId(a.id)}),this.state.collections.set([]),setTimeout(()=>{e.forEach(a=>this.storage.removePersistExcludedId(a.id)),t.forEach(a=>this.storage.removePersistExcludedId(a.id))},500),this.removeApis(s),this.removeCollections(i),await this.stop()}async findApisToReload(e){const s=[];return await Promise.all(this.state.apis.map(async t=>{const i=t.fileDependencies?.get({noproxy:!0})??new Set,a=t.get({noproxy:!0}).id,o=e.find(n=>i.has(n.absolute_path));if(!this.storage.isWatchExcluded(a)&&o){const n=await l.PathUtils.join(this.projectDir,a);s.push({relative_path:a,absolute_path:n,type:"api"})}})),s}async findCollectionsToReload(e){const s=[];return await Promise.all(this.state.collections.map(async t=>{const i=t.fileDependencies?.get({noproxy:!0})??new Set,a=t.get({noproxy:!0}).id,o=e.find(n=>i.has(n.absolute_path));if(!this.storage.isWatchExcluded(a)&&o){const n=await l.PathUtils.join(this.projectDir,a);s.push({relative_path:a,absolute_path:n,type:"collection"})}})),s}async reloadEnvironments(){const e=await this.tauriStorage.readEnviroments();this.storage.addPersistExcludedId(p),this.state.environments.set(e.length>0?e:l.cloneObject(l.DEFAULT_ENVIRONMENTS)),this.state.configFileError.set(this.storage.getEnvironmentsConfigError()),setTimeout(()=>{this.storage.removePersistExcludedId(p)},500)}async reloadApis(e){if(e.length===0)return;const s=await this.tauriStorage.loadAndParseApis(e,void 0,!0),t=[];await Promise.all(s.map(async(i,a)=>{if(!i){await this.handleDelete([e[a]]);return}const o=this.state.apis.get({noproxy:!0}).findIndex(n=>n.id===i.id);o>=0?(this.storage.addPersistExcludedId(i.id),this.state.apis[o].set(i),t.push(i),setTimeout(()=>this.storage.removePersistExcludedId(i.id),500)):console.warn("API not found in state after reload:",i.id)})),t.length>0&&this.indexApis(t)}async reloadCollections(e){if(e.length===0)return;const s=await this.tauriStorage.loadAndParseCollections(e,void 0),t=[];await Promise.all(s.map(async(i,a)=>{if(!i){await this.handleDelete([e[a]]);return}const o=this.state.collections.get({noproxy:!0}).findIndex(n=>n.id===i.id);o>=0?(this.storage.addPersistExcludedId(i.id),this.state.collections[o].set(i),t.push(i),setTimeout(()=>this.storage.removePersistExcludedId(i.id),500)):console.warn("Collection not found in state after reload:",i.id)})),t.length>0&&this.indexCollections(t)}}exports.FileWatcher=y;
|
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { i as m, t as x, P as E, n as v, c as F, D as y } from "./replay-index-BH8cTSEK.js";
|
|
2
|
-
import { g as f } from "./replay-SemanticSearchService-BWwCFW3F.js";
|
|
3
|
-
import "react";
|
|
4
|
-
var w;
|
|
5
|
-
(function(r) {
|
|
6
|
-
r.WINDOW_RESIZED = "tauri://resize", r.WINDOW_MOVED = "tauri://move", r.WINDOW_CLOSE_REQUESTED = "tauri://close-requested", r.WINDOW_DESTROYED = "tauri://destroyed", r.WINDOW_FOCUS = "tauri://focus", r.WINDOW_BLUR = "tauri://blur", r.WINDOW_SCALE_FACTOR_CHANGED = "tauri://scale-change", r.WINDOW_THEME_CHANGED = "tauri://theme-changed", r.WINDOW_CREATED = "tauri://window-created", r.WEBVIEW_CREATED = "tauri://webview-created", r.DRAG_ENTER = "tauri://drag-enter", r.DRAG_OVER = "tauri://drag-over", r.DRAG_DROP = "tauri://drag-drop", r.DRAG_LEAVE = "tauri://drag-leave";
|
|
7
|
-
})(w || (w = {}));
|
|
8
|
-
async function C(r, e) {
|
|
9
|
-
await m("plugin:event|unlisten", {
|
|
10
|
-
event: r,
|
|
11
|
-
eventId: e
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
async function _(r, e, s) {
|
|
15
|
-
var t;
|
|
16
|
-
const i = (t = void 0) !== null && t !== void 0 ? t : { kind: "Any" };
|
|
17
|
-
return m("plugin:event|listen", {
|
|
18
|
-
event: r,
|
|
19
|
-
target: i,
|
|
20
|
-
handler: x(e)
|
|
21
|
-
}).then((a) => async () => C(r, a));
|
|
22
|
-
}
|
|
23
|
-
const d = "replay-environments.yaml";
|
|
24
|
-
class I {
|
|
25
|
-
constructor(e, s, t, i) {
|
|
26
|
-
this.storage = e, this.state = s, this.projectDir = t, this.aiEnabled = i;
|
|
27
|
-
}
|
|
28
|
-
storage;
|
|
29
|
-
state;
|
|
30
|
-
projectDir;
|
|
31
|
-
aiEnabled;
|
|
32
|
-
watchPath = null;
|
|
33
|
-
unlistenEvent = null;
|
|
34
|
-
get tauriStorage() {
|
|
35
|
-
return this.storage;
|
|
36
|
-
}
|
|
37
|
-
indexApis(e) {
|
|
38
|
-
!this.aiEnabled || e.length === 0 || f().indexApis(e).catch((s) => console.error("Semantic index (apis):", s));
|
|
39
|
-
}
|
|
40
|
-
indexCollections(e) {
|
|
41
|
-
!this.aiEnabled || e.length === 0 || f().indexCollections(e).catch((s) => console.error("Semantic index (collections):", s));
|
|
42
|
-
}
|
|
43
|
-
removeApis(e) {
|
|
44
|
-
if (!this.aiEnabled || e.length === 0) return;
|
|
45
|
-
const s = f();
|
|
46
|
-
Promise.all(e.map((t) => s.removeApi(t))).catch(
|
|
47
|
-
(t) => console.error("Semantic remove (apis):", t)
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
removeCollections(e) {
|
|
51
|
-
if (!this.aiEnabled || e.length === 0) return;
|
|
52
|
-
const s = f();
|
|
53
|
-
Promise.all(e.map((t) => s.removeCollection(t))).catch(
|
|
54
|
-
(t) => console.error("Semantic remove (collections):", t)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Starts watching the directory for changes.
|
|
59
|
-
*/
|
|
60
|
-
async start() {
|
|
61
|
-
if (this.watchPath) {
|
|
62
|
-
console.warn("Watcher already started for:", this.watchPath);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
this.unlistenEvent = await _("fs-watch-event", async (e) => {
|
|
67
|
-
const s = e.payload;
|
|
68
|
-
try {
|
|
69
|
-
await this.handleEvent(s);
|
|
70
|
-
} catch (t) {
|
|
71
|
-
console.error("Error handling file change:", t);
|
|
72
|
-
}
|
|
73
|
-
}), await m("fs_watch", {
|
|
74
|
-
path: this.projectDir,
|
|
75
|
-
options: {
|
|
76
|
-
recursive: !0,
|
|
77
|
-
delayMs: 500
|
|
78
|
-
}
|
|
79
|
-
}), this.watchPath = this.projectDir;
|
|
80
|
-
} catch (e) {
|
|
81
|
-
throw console.error("Failed to start file watcher:", e), this.unlistenEvent && (this.unlistenEvent(), this.unlistenEvent = null), e;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Stops watching and cleans up resources.
|
|
86
|
-
*/
|
|
87
|
-
async stop() {
|
|
88
|
-
if (this.watchPath)
|
|
89
|
-
try {
|
|
90
|
-
await m("fs_unwatch", { path: this.watchPath });
|
|
91
|
-
} catch (e) {
|
|
92
|
-
console.error("Error stopping file watcher:", e);
|
|
93
|
-
} finally {
|
|
94
|
-
this.unlistenEvent && (this.unlistenEvent(), this.unlistenEvent = null), this.watchPath = null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Main event handler - dispatches to specific handlers based on event type.
|
|
99
|
-
*/
|
|
100
|
-
async handleEvent(e) {
|
|
101
|
-
const { changeType: s, paths: t, pathTypes: i, type: a } = e;
|
|
102
|
-
if (await this.isProjectFolderRemoved(t, s)) {
|
|
103
|
-
await this.handleProjectFolderRemoval();
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const o = this.filterSpecFiles(t, i);
|
|
107
|
-
if (o.paths.length === 0)
|
|
108
|
-
return;
|
|
109
|
-
const n = await this.toFileEntries(o.paths, o.pathTypes);
|
|
110
|
-
switch (s) {
|
|
111
|
-
case "changed":
|
|
112
|
-
(a.includes("Data") || a.includes("Name")) && await this.handleModify(n);
|
|
113
|
-
break;
|
|
114
|
-
case "added":
|
|
115
|
-
await this.handleCreate(n);
|
|
116
|
-
break;
|
|
117
|
-
case "deleted":
|
|
118
|
-
await this.handleDelete(n);
|
|
119
|
-
break;
|
|
120
|
-
case "renamed":
|
|
121
|
-
await this.handleRename(n);
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
console.log("Unhandled change type:", s);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Filter paths to only include yaml/json files.
|
|
129
|
-
* Returns filtered paths and their corresponding pathTypes.
|
|
130
|
-
*/
|
|
131
|
-
filterSpecFiles(e, s) {
|
|
132
|
-
const t = [], i = [];
|
|
133
|
-
for (let a = 0; a < e.length; a++) {
|
|
134
|
-
const o = e[a], n = o.split(".").pop()?.toLowerCase();
|
|
135
|
-
n && ["yaml", "yml", "json"].includes(n) && (t.push(o), i.push(s[a] || "unknown"));
|
|
136
|
-
}
|
|
137
|
-
return { paths: t, pathTypes: i };
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Convert absolute paths to file entry format with relative paths and types.
|
|
141
|
-
*/
|
|
142
|
-
async toFileEntries(e, s) {
|
|
143
|
-
return Promise.all(
|
|
144
|
-
e.map(async (t, i) => ({
|
|
145
|
-
relative_path: await E.relative(this.projectDir, t),
|
|
146
|
-
absolute_path: t,
|
|
147
|
-
type: s[i] || "unknown"
|
|
148
|
-
}))
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
hasEnvironmentsFileChange(e) {
|
|
152
|
-
return !this.storage.isWatchExcluded(d) && e.some((s) => s.relative_path === d);
|
|
153
|
-
}
|
|
154
|
-
withoutEnvironmentsFile(e) {
|
|
155
|
-
return e.filter((s) => s.relative_path !== d);
|
|
156
|
-
}
|
|
157
|
-
consolidateFileEntries(e) {
|
|
158
|
-
const s = [], t = /* @__PURE__ */ new Set();
|
|
159
|
-
for (const i of e)
|
|
160
|
-
t.has(i.relative_path) || (t.add(i.relative_path), this.storage.isWatchExcluded(i.relative_path) || s.push(i));
|
|
161
|
-
return s;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Handles file content modification events.
|
|
165
|
-
* If file doesn't exist in state yet, treat as creation.
|
|
166
|
-
*/
|
|
167
|
-
async handleModify(e) {
|
|
168
|
-
const s = this.hasEnvironmentsFileChange(e), t = this.withoutEnvironmentsFile(e), { newApiFiles: i, existingApiFiles: a } = this.categorizeApisFromFiles(t), { newCollectionFiles: o, existingCollectionFiles: n } = this.categorizeCollectionsFromFiles(t), h = await this.findApisToReload(e), c = await this.findCollectionsToReload(e), p = [...i, ...o];
|
|
169
|
-
p.length > 0 && await this.handleCreate(p), s && await this.reloadEnvironments();
|
|
170
|
-
const u = this.consolidateFileEntries([...a, ...h]), g = this.consolidateFileEntries([
|
|
171
|
-
...n,
|
|
172
|
-
...c
|
|
173
|
-
]);
|
|
174
|
-
await this.reloadApis(u), await this.reloadCollections(g);
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Handles file creation events.
|
|
178
|
-
* If file already exists in state, update it instead of creating duplicate.
|
|
179
|
-
*/
|
|
180
|
-
async handleCreate(e) {
|
|
181
|
-
this.hasEnvironmentsFileChange(e) && await this.reloadEnvironments();
|
|
182
|
-
const s = this.withoutEnvironmentsFile(e), t = s.filter((c) => c.type === "api"), i = s.filter((c) => c.type === "collection"), { newApiFiles: a, existingApiFiles: o } = this.categorizeApisFromFiles(t), { newCollectionFiles: n, existingCollectionFiles: h } = this.categorizeCollectionsFromFiles(i);
|
|
183
|
-
if (a.length > 0 || n.length > 0) {
|
|
184
|
-
a.forEach((l) => this.storage.addPersistExcludedId(l.relative_path)), n.forEach((l) => this.storage.addPersistExcludedId(l.relative_path));
|
|
185
|
-
const c = a.length > 0 ? await this.tauriStorage.loadAndParseApis(a, void 0, !0) : [], p = n.length > 0 ? await this.tauriStorage.loadAndParseCollections(n, void 0) : [], u = c.filter((l) => l !== null), g = p.filter((l) => l !== null);
|
|
186
|
-
this.state.apis.merge(u), this.state.collections.merge(g), this.indexApis(u), this.indexCollections(g), setTimeout(() => {
|
|
187
|
-
a.forEach((l) => this.storage.removePersistExcludedId(l.relative_path)), n.forEach(
|
|
188
|
-
(l) => this.storage.removePersistExcludedId(l.relative_path)
|
|
189
|
-
);
|
|
190
|
-
}, 500);
|
|
191
|
-
}
|
|
192
|
-
o.length > 0 && await this.reloadApis(o), h.length > 0 && await this.reloadCollections(h);
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Categorize API paths into new vs existing
|
|
196
|
-
*/
|
|
197
|
-
/**
|
|
198
|
-
* Categorize API files into new vs existing
|
|
199
|
-
*/
|
|
200
|
-
categorizeApisFromFiles(e) {
|
|
201
|
-
const s = /* @__PURE__ */ new Set(), t = [], i = [];
|
|
202
|
-
for (const a of e) {
|
|
203
|
-
if (s.has(a.relative_path))
|
|
204
|
-
continue;
|
|
205
|
-
s.add(a.relative_path), this.state.apis.get({ noproxy: !0 }).some((n) => n.id === a.relative_path) ? i.push(a) : a.type === "api" && t.push(a);
|
|
206
|
-
}
|
|
207
|
-
return { newApiFiles: t, existingApiFiles: i };
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Categorize collection files into new vs existing
|
|
211
|
-
*/
|
|
212
|
-
categorizeCollectionsFromFiles(e) {
|
|
213
|
-
const s = /* @__PURE__ */ new Set(), t = [], i = [];
|
|
214
|
-
for (const a of e) {
|
|
215
|
-
if (s.has(a.relative_path))
|
|
216
|
-
continue;
|
|
217
|
-
s.add(a.relative_path), this.state.collections.get({ noproxy: !0 }).some((n) => n.id === a.relative_path) ? i.push(a) : a.type === "collection" && t.push(a);
|
|
218
|
-
}
|
|
219
|
-
return { newCollectionFiles: t, existingCollectionFiles: i };
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Handles file deletion events.
|
|
223
|
-
*/
|
|
224
|
-
async handleDelete(e) {
|
|
225
|
-
this.hasEnvironmentsFileChange(e) && await this.reloadEnvironments();
|
|
226
|
-
const s = [], t = [];
|
|
227
|
-
for (const i of this.withoutEnvironmentsFile(e)) {
|
|
228
|
-
this.storage.addPersistExcludedId(i.relative_path);
|
|
229
|
-
const a = this.state.apis.get({ noproxy: !0 }).findIndex((n) => n.id === i.relative_path);
|
|
230
|
-
a >= 0 && (this.state.apis[a].set(v), this.tauriStorage.deleteApiFromCache(i.relative_path), s.push(i.relative_path));
|
|
231
|
-
const o = this.state.collections.get({ noproxy: !0 }).findIndex((n) => n.id === i.relative_path);
|
|
232
|
-
o >= 0 && (this.state.collections[o].set(v), t.push(i.relative_path)), setTimeout(() => {
|
|
233
|
-
this.storage.removePersistExcludedId(i.relative_path);
|
|
234
|
-
}, 500);
|
|
235
|
-
}
|
|
236
|
-
this.removeApis(s), this.removeCollections(t);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Handles file rename/move events.
|
|
240
|
-
* For rename events, files typically contains [oldFile, newFile]
|
|
241
|
-
*/
|
|
242
|
-
async handleRename(e) {
|
|
243
|
-
if (e.length >= 2) {
|
|
244
|
-
const [s, t] = e;
|
|
245
|
-
await this.handleDelete([s]), await this.handleCreate([t]);
|
|
246
|
-
} else
|
|
247
|
-
await this.handleCreate(e);
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* Checks if the project folder itself was renamed/moved/deleted.
|
|
251
|
-
* This happens when:
|
|
252
|
-
* - We get a rename/delete event for the project directory itself
|
|
253
|
-
* - Or when paths no longer match the watched directory structure
|
|
254
|
-
*/
|
|
255
|
-
async isProjectFolderRemoved(e, s) {
|
|
256
|
-
if (e.length === 0)
|
|
257
|
-
return !1;
|
|
258
|
-
if (s === "deleted" || s === "renamed") {
|
|
259
|
-
for (const i of e)
|
|
260
|
-
if (i === this.projectDir)
|
|
261
|
-
return !0;
|
|
262
|
-
}
|
|
263
|
-
return e.filter(
|
|
264
|
-
(i) => !i.startsWith(this.projectDir + "/") && i !== this.projectDir
|
|
265
|
-
).length > 0 && s === "renamed";
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Handles the case when the entire project folder is renamed or deleted.
|
|
269
|
-
* Clears all APIs and collections from state.
|
|
270
|
-
*/
|
|
271
|
-
async handleProjectFolderRemoval() {
|
|
272
|
-
const e = this.state.apis.get({ noproxy: !0 }), s = e.map((a) => a.id);
|
|
273
|
-
e.forEach((a) => {
|
|
274
|
-
this.storage.addPersistExcludedId(a.id), this.tauriStorage.deleteApiFromCache(a.id);
|
|
275
|
-
}), this.state.apis.set([]);
|
|
276
|
-
const t = this.state.collections.get({ noproxy: !0 }), i = t.map((a) => a.id);
|
|
277
|
-
t.forEach((a) => {
|
|
278
|
-
this.storage.addPersistExcludedId(a.id);
|
|
279
|
-
}), this.state.collections.set([]), setTimeout(() => {
|
|
280
|
-
e.forEach((a) => this.storage.removePersistExcludedId(a.id)), t.forEach((a) => this.storage.removePersistExcludedId(a.id));
|
|
281
|
-
}, 500), this.removeApis(s), this.removeCollections(i), await this.stop();
|
|
282
|
-
}
|
|
283
|
-
async findApisToReload(e) {
|
|
284
|
-
const s = [];
|
|
285
|
-
return await Promise.all(
|
|
286
|
-
this.state.apis.map(async (t) => {
|
|
287
|
-
const i = t.fileDependencies?.get({ noproxy: !0 }) ?? /* @__PURE__ */ new Set(), a = t.get({ noproxy: !0 }).id, o = e.find((n) => i.has(n.absolute_path));
|
|
288
|
-
if (!this.storage.isWatchExcluded(a) && o) {
|
|
289
|
-
const n = await E.join(this.projectDir, a);
|
|
290
|
-
s.push({
|
|
291
|
-
relative_path: a,
|
|
292
|
-
absolute_path: n,
|
|
293
|
-
type: "api"
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
})
|
|
297
|
-
), s;
|
|
298
|
-
}
|
|
299
|
-
async findCollectionsToReload(e) {
|
|
300
|
-
const s = [];
|
|
301
|
-
return await Promise.all(
|
|
302
|
-
this.state.collections.map(async (t) => {
|
|
303
|
-
const i = t.fileDependencies?.get({ noproxy: !0 }) ?? /* @__PURE__ */ new Set(), a = t.get({ noproxy: !0 }).id, o = e.find((n) => i.has(n.absolute_path));
|
|
304
|
-
if (!this.storage.isWatchExcluded(a) && o) {
|
|
305
|
-
const n = await E.join(this.projectDir, a);
|
|
306
|
-
s.push({
|
|
307
|
-
relative_path: a,
|
|
308
|
-
absolute_path: n,
|
|
309
|
-
type: "collection"
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
})
|
|
313
|
-
), s;
|
|
314
|
-
}
|
|
315
|
-
async reloadEnvironments() {
|
|
316
|
-
const e = await this.tauriStorage.readEnviroments();
|
|
317
|
-
this.storage.addPersistExcludedId(d), this.state.environments.set(e.length > 0 ? e : F(y)), this.state.configFileError.set(this.storage.getEnvironmentsConfigError()), setTimeout(() => {
|
|
318
|
-
this.storage.removePersistExcludedId(d);
|
|
319
|
-
}, 500);
|
|
320
|
-
}
|
|
321
|
-
async reloadApis(e) {
|
|
322
|
-
if (e.length === 0) return;
|
|
323
|
-
const s = await this.tauriStorage.loadAndParseApis(e, void 0, !0), t = [];
|
|
324
|
-
await Promise.all(
|
|
325
|
-
s.map(async (i, a) => {
|
|
326
|
-
if (!i) {
|
|
327
|
-
await this.handleDelete([e[a]]);
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
const o = this.state.apis.get({ noproxy: !0 }).findIndex((n) => n.id === i.id);
|
|
331
|
-
o >= 0 ? (this.storage.addPersistExcludedId(i.id), this.state.apis[o].set(i), t.push(i), setTimeout(() => this.storage.removePersistExcludedId(i.id), 500)) : console.warn("API not found in state after reload:", i.id);
|
|
332
|
-
})
|
|
333
|
-
), t.length > 0 && this.indexApis(t);
|
|
334
|
-
}
|
|
335
|
-
async reloadCollections(e) {
|
|
336
|
-
if (e.length === 0) return;
|
|
337
|
-
const s = await this.tauriStorage.loadAndParseCollections(e, void 0), t = [];
|
|
338
|
-
await Promise.all(
|
|
339
|
-
s.map(async (i, a) => {
|
|
340
|
-
if (!i) {
|
|
341
|
-
await this.handleDelete([e[a]]);
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
const o = this.state.collections.get({ noproxy: !0 }).findIndex((n) => n.id === i.id);
|
|
345
|
-
o >= 0 ? (this.storage.addPersistExcludedId(i.id), this.state.collections[o].set(i), t.push(i), setTimeout(() => this.storage.removePersistExcludedId(i.id), 500)) : console.warn("Collection not found in state after reload:", i.id);
|
|
346
|
-
})
|
|
347
|
-
), t.length > 0 && this.indexCollections(t);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
export {
|
|
351
|
-
I as FileWatcher
|
|
352
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./replay-index-BuYoH96w.js"),Y=require("./replay-promise-map-limit-DRDkHc-b.js"),G=require("./replay-TauriFileSystemAdapter-CLzYSck7.js");var U={exports:{}},V;function oe(){return V||(V=1,(function(s){var e=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function n(a,u,f){this.fn=a,this.context=u,this.once=f||!1}function o(a,u,f,l,g){if(typeof f!="function")throw new TypeError("The listener must be a function");var y=new n(f,l||a,g),m=t?t+u:u;return a._events[m]?a._events[m].fn?a._events[m]=[a._events[m],y]:a._events[m].push(y):(a._events[m]=y,a._eventsCount++),a}function d(a,u){--a._eventsCount===0?a._events=new r:delete a._events[u]}function h(){this._events=new r,this._eventsCount=0}h.prototype.eventNames=function(){var u=[],f,l;if(this._eventsCount===0)return u;for(l in f=this._events)e.call(f,l)&&u.push(t?l.slice(1):l);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(f)):u},h.prototype.listeners=function(u){var f=t?t+u:u,l=this._events[f];if(!l)return[];if(l.fn)return[l.fn];for(var g=0,y=l.length,m=new Array(y);g<y;g++)m[g]=l[g].fn;return m},h.prototype.listenerCount=function(u){var f=t?t+u:u,l=this._events[f];return l?l.fn?1:l.length:0},h.prototype.emit=function(u,f,l,g,y,m){var b=t?t+u:u;if(!this._events[b])return!1;var c=this._events[b],C=arguments.length,F,w;if(c.fn){switch(c.once&&this.removeListener(u,c.fn,void 0,!0),C){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,f),!0;case 3:return c.fn.call(c.context,f,l),!0;case 4:return c.fn.call(c.context,f,l,g),!0;case 5:return c.fn.call(c.context,f,l,g,y),!0;case 6:return c.fn.call(c.context,f,l,g,y,m),!0}for(w=1,F=new Array(C-1);w<C;w++)F[w-1]=arguments[w];c.fn.apply(c.context,F)}else{var ae=c.length,x;for(w=0;w<ae;w++)switch(c[w].once&&this.removeListener(u,c[w].fn,void 0,!0),C){case 1:c[w].fn.call(c[w].context);break;case 2:c[w].fn.call(c[w].context,f);break;case 3:c[w].fn.call(c[w].context,f,l);break;case 4:c[w].fn.call(c[w].context,f,l,g);break;default:if(!F)for(x=1,F=new Array(C-1);x<C;x++)F[x-1]=arguments[x];c[w].fn.apply(c[w].context,F)}}return!0},h.prototype.on=function(u,f,l){return o(this,u,f,l,!1)},h.prototype.once=function(u,f,l){return o(this,u,f,l,!0)},h.prototype.removeListener=function(u,f,l,g){var y=t?t+u:u;if(!this._events[y])return this;if(!f)return d(this,y),this;var m=this._events[y];if(m.fn)m.fn===f&&(!g||m.once)&&(!l||m.context===l)&&d(this,y);else{for(var b=0,c=[],C=m.length;b<C;b++)(m[b].fn!==f||g&&!m[b].once||l&&m[b].context!==l)&&c.push(m[b]);c.length?this._events[y]=c.length===1?c[0]:c:d(this,y)}return this},h.prototype.removeAllListeners=function(u){var f;return u?(f=t?t+u:u,this._events[f]&&d(this,f)):(this._events=new r,this._eventsCount=0),this},h.prototype.off=h.prototype.removeListener,h.prototype.addListener=h.prototype.on,h.prefixed=t,h.EventEmitter=h,s.exports=h})(U)),U.exports}var ue=oe();const le=p.getDefaultExportFromCjs(ue);class re extends Error{constructor(e){super(e),this.name="TimeoutError"}}let ce=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}};const J=s=>globalThis.DOMException===void 0?new ce(s):new DOMException(s),H=s=>{const e=s.reason===void 0?J("This operation was aborted."):s.reason;return e instanceof Error?e:J(e)};function he(s,e,t,r){let n;const o=new Promise((d,h)=>{if(typeof e!="number"||Math.sign(e)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${e}\``);if(e===Number.POSITIVE_INFINITY){d(s);return}if(r={customTimers:{setTimeout,clearTimeout},...r},r.signal){const{signal:a}=r;a.aborted&&h(H(a)),a.addEventListener("abort",()=>{h(H(a))})}n=r.customTimers.setTimeout.call(void 0,()=>{const a=`Promise timed out after ${e} milliseconds`,u=t instanceof Error?t:new re(a);typeof s.cancel=="function"&&s.cancel(),h(u)},e),(async()=>{try{d(await s)}catch(a){h(a)}finally{r.customTimers.clearTimeout.call(void 0,n)}})()});return o.clear=()=>{clearTimeout(n),n=void 0},o}function fe(s,e,t){let r=0,n=s.length;for(;n>0;){const o=Math.trunc(n/2);let d=r+o;t(s[d],e)<=0?(r=++d,n-=o+1):n=o}return r}var Q=function(s,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(s):r?r.value:e.get(s)},A;class de{constructor(){A.set(this,[])}enqueue(e,t){t={priority:0,...t};const r={priority:t.priority,run:e};if(this.size&&Q(this,A,"f")[this.size-1].priority>=t.priority){Q(this,A,"f").push(r);return}const n=fe(Q(this,A,"f"),r,(o,d)=>d.priority-o.priority);Q(this,A,"f").splice(n,0,r)}dequeue(){const e=Q(this,A,"f").shift();return e?.run}filter(e){return Q(this,A,"f").filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return Q(this,A,"f").length}}A=new WeakMap;var v=function(s,e,t,r,n){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!n)throw new TypeError("Private accessor was defined without a setter");if(typeof e=="function"?s!==e||!n:!e.has(s))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?n.call(s,t):n?n.value=t:e.set(s,t),t},i=function(s,e,t,r){if(t==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof e=="function"?s!==e||!r:!e.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t==="m"?r:t==="a"?r.call(s):r?r.value:e.get(s)},_,L,M,I,R,N,z,E,O,P,k,S,W,T,q,X,Z,ie,ee,te,D,B,K,$,se,j;class ne extends Error{}class pe extends le{constructor(e){var t,r,n,o;if(super(),_.add(this),L.set(this,void 0),M.set(this,void 0),I.set(this,0),R.set(this,void 0),N.set(this,void 0),z.set(this,0),E.set(this,void 0),O.set(this,void 0),P.set(this,void 0),k.set(this,void 0),S.set(this,0),W.set(this,void 0),T.set(this,void 0),q.set(this,void 0),Object.defineProperty(this,"timeout",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:de,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(r=(t=e.intervalCap)===null||t===void 0?void 0:t.toString())!==null&&r!==void 0?r:""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(o=(n=e.interval)===null||n===void 0?void 0:n.toString())!==null&&o!==void 0?o:""}\` (${typeof e.interval})`);v(this,L,e.carryoverConcurrencyCount,"f"),v(this,M,e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,"f"),v(this,R,e.intervalCap,"f"),v(this,N,e.interval,"f"),v(this,P,new e.queueClass,"f"),v(this,k,e.queueClass,"f"),this.concurrency=e.concurrency,this.timeout=e.timeout,v(this,q,e.throwOnTimeout===!0,"f"),v(this,T,e.autoStart===!1,"f")}get concurrency(){return i(this,W,"f")}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);v(this,W,e,"f"),i(this,_,"m",$).call(this)}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:i(this,q,"f"),...t},new Promise((r,n)=>{i(this,P,"f").enqueue(async()=>{var o,d,h;v(this,S,(d=i(this,S,"f"),d++,d),"f"),v(this,I,(h=i(this,I,"f"),h++,h),"f");try{if(!((o=t.signal)===null||o===void 0)&&o.aborted)throw new ne("The task was aborted.");let a=e({signal:t.signal});t.timeout&&(a=he(Promise.resolve(a),t.timeout)),t.signal&&(a=Promise.race([a,i(this,_,"m",se).call(this,t.signal)]));const u=await a;r(u),this.emit("completed",u)}catch(a){if(a instanceof re&&!t.throwOnTimeout){r();return}n(a),this.emit("error",a)}finally{i(this,_,"m",ie).call(this)}},t),this.emit("add"),i(this,_,"m",D).call(this)})}async addAll(e,t){return Promise.all(e.map(async r=>this.add(r,t)))}start(){return i(this,T,"f")?(v(this,T,!1,"f"),i(this,_,"m",$).call(this),this):this}pause(){v(this,T,!0,"f")}clear(){v(this,P,new(i(this,k,"f")),"f")}async onEmpty(){i(this,P,"f").size!==0&&await i(this,_,"m",j).call(this,"empty")}async onSizeLessThan(e){i(this,P,"f").size<e||await i(this,_,"m",j).call(this,"next",()=>i(this,P,"f").size<e)}async onIdle(){i(this,S,"f")===0&&i(this,P,"f").size===0||await i(this,_,"m",j).call(this,"idle")}get size(){return i(this,P,"f").size}sizeBy(e){return i(this,P,"f").filter(e).length}get pending(){return i(this,S,"f")}get isPaused(){return i(this,T,"f")}}L=new WeakMap,M=new WeakMap,I=new WeakMap,R=new WeakMap,N=new WeakMap,z=new WeakMap,E=new WeakMap,O=new WeakMap,P=new WeakMap,k=new WeakMap,S=new WeakMap,W=new WeakMap,T=new WeakMap,q=new WeakMap,_=new WeakSet,X=function(){return i(this,M,"f")||i(this,I,"f")<i(this,R,"f")},Z=function(){return i(this,S,"f")<i(this,W,"f")},ie=function(){var e;v(this,S,(e=i(this,S,"f"),e--,e),"f"),i(this,_,"m",D).call(this),this.emit("next")},ee=function(){i(this,_,"m",K).call(this),i(this,_,"m",B).call(this),v(this,O,void 0,"f")},te=function(){const e=Date.now();if(i(this,E,"f")===void 0){const t=i(this,z,"f")-e;if(t<0)v(this,I,i(this,L,"f")?i(this,S,"f"):0,"f");else return i(this,O,"f")===void 0&&v(this,O,setTimeout(()=>{i(this,_,"m",ee).call(this)},t),"f"),!0}return!1},D=function(){if(i(this,P,"f").size===0)return i(this,E,"f")&&clearInterval(i(this,E,"f")),v(this,E,void 0,"f"),this.emit("empty"),i(this,S,"f")===0&&this.emit("idle"),!1;if(!i(this,T,"f")){const e=!i(this,_,"a",te);if(i(this,_,"a",X)&&i(this,_,"a",Z)){const t=i(this,P,"f").dequeue();return t?(this.emit("active"),t(),e&&i(this,_,"m",B).call(this),!0):!1}}return!1},B=function(){i(this,M,"f")||i(this,E,"f")!==void 0||(v(this,E,setInterval(()=>{i(this,_,"m",K).call(this)},i(this,N,"f")),"f"),v(this,z,Date.now()+i(this,N,"f"),"f"))},K=function(){i(this,I,"f")===0&&i(this,S,"f")===0&&i(this,E,"f")&&(clearInterval(i(this,E,"f")),v(this,E,void 0,"f")),v(this,I,i(this,L,"f")?i(this,S,"f"):0,"f"),i(this,_,"m",$).call(this)},$=function(){for(;i(this,_,"m",D).call(this););},se=async function(e){return new Promise((t,r)=>{e.addEventListener("abort",()=>{r(new ne("The task was aborted."))},{once:!0})})},j=async function(e,t){return new Promise(r=>{const n=()=>{t&&!t()||(this.off(e,n),r())};this.on(e,n)})};class me{constructor(e){this.apisStorage=e}apisStorage;data=new Map;loading=new Set;pQueue=new pe({concurrency:20});async get(e){return this.data.has(e)?this.data.get(e)??null:(await this.loadAndParse(e),this.data.get(e)??null)}async load(e,t=!1){this.data.has(e)&&!t||await this.loadAndParse(e,t)}async loadAndParse(e,t=!1){if(this.loading.has(e)){await this.pQueue.add(()=>this.get(e));return}t&&this.data.delete(e),this.loading.add(e),await this.pQueue.add(async()=>{const r=p.isWebUrl(e)?p.SourceType.WEB:p.SourceType.FS,n=r===p.SourceType.WEB?e:await this.apisStorage.getAbsolutePath(e);try{const{definition:o,fileDependencies:d}=await p.loadAndBundleDefinition(n);if(!o){this.data.set(e,null),await p.clearNotificationsForSource(e);return}const h=this.apisStorage.parse({uri:e,type:r,content:o});this.data.set(e,{...h,fileDependencies:d}),await p.clearNotificationsForSource(e)}catch(o){if(this.data.set(e,null),o instanceof Error&&(o.message.includes("Unsupported specification")||o.message.includes("File not found"))){await p.clearNotificationsForSource(e);return}console.info("Error loading api "+e,o),await p.reportParseError(e,o);return}}),this.loading.delete(e)}get size(){return this.data.size}delete(e){this.data.delete(e)}getAll(){return Array.from(this.data.values()).filter(e=>e!==null)}clear(){this.data.clear(),this.loading.clear()}}class ve extends p.RootStorage{apiLoader;constructor(e,t,r){const n=new G.TauriFileSystemAdapter(e.systemFilesDir),o=new G.TauriFileSystemAdapter(e.userFilesDir);super(n,o,e,!0,!1,t,r),this.apiLoader=new me(this.apisStorage),this.setupWriteListeners(o)}setupWriteListeners(e){e.on("write-start",t=>{this.addWatchExcludedId(t)}),e.on("write-end",t=>{this.removeWatchExcludedId(t)})}async read(){const e=this.telemetry?.startSpan("com.redocly.storage.read",[p.createResource("storageOperation","read","storage")],void 0),t=this.telemetry?.startSpan("com.redocly.storage.loadUserState",[p.createResource("storageOperation","loadUserState","storage")],e?.parentCtx),[r,n,o]=await Promise.all([this.activeEnvironmentIdStorage.read(),this.tabsStateStorage.read(),this.environmentsStorage.read()]);t?.setAttribute("status","completed"),t?.setAttribute("environmentCount",o.length),t?.setStatus(p.SpanStatusCode.OK),t?.end();const{apiFiles:d,collectionFiles:h}=await this.detectProjectFiles(e);await this.loadAndParseApis(d,e);const u=(await this.loadAndParseCollections(h,e)).filter(l=>l!==null);this.collectionsStorage.setItemIds(u.map(l=>l.id));const f=this.apiLoader.getAll();return this.apisStorage.setItemIds(f.map(l=>l.id)),e?.setAttribute("status","completed"),e?.setStatus(p.SpanStatusCode.OK),e?.end(),{project:this.project,activeEnvironmentId:r,tabsState:n,environments:o,apis:f,collections:u,configFileError:this.getEnvironmentsConfigError()}}async detectProjectFiles(e){const t=this.telemetry?.startSpan("com.redocly.storage.detectFiles",[p.createResource("storageOperation","detectFiles","storage")],e?.parentCtx),{api_files:r,collection_files:n}=await p.invoke("fs_scan",{dir:this.project.userFilesDir});return t?.setAttribute("status","completed"),t?.setAttribute("filesCount",r.length+n.length),t?.setAttribute("apiFilesCount",r.length),t?.setAttribute("collectionFilesCount",n.length),t?.setStatus(p.SpanStatusCode.OK),t?.end(),{apiFiles:r,collectionFiles:n}}readEnviroments(){return this.environmentsStorage.read()}deleteApiFromCache(e){this.apiLoader.delete(e)}async loadAndParseApis(e,t,r=!1){const n=this.telemetry?.startSpan("com.redocly.storage.parseApis",[{...p.createResource("storageOperation","parseApis","storage"),apisCount:e.length}],t?.parentCtx),o=await Y.promiseMapLimit(e,20,async d=>{try{return await this.apiLoader.load(d.relative_path,r),this.apiLoader.get(d.relative_path)}catch(h){return console.info(`Error parsing YAML/JSON file ${d.absolute_path}:`,h),await p.reportParseError(d.relative_path,h),null}});return n?.setAttribute("status","completed"),n?.setAttribute("parsedApisCount",this.apiLoader.size),n?.setStatus(p.SpanStatusCode.OK),n?.end(),o}async loadAndParseCollections(e,t){const r=this.telemetry?.startSpan("com.redocly.storage.parseCollections",[{...p.createResource("storageOperation","parseCollections","storage"),collectionsCount:e.length}],t?.parentCtx),n=await Y.promiseMapLimit(e,20,async o=>{try{const d=await this.userFilesStorage.get(o.relative_path);if(!d)return null;const h=p.yaml.load(d);if(typeof h!="object"||h===null||typeof h.arazzo!="string")return await p.clearNotificationsForSource(o.relative_path),null;const a=[];await Promise.all(h.sourceDescriptions?.map(async l=>{const g=l.type,y=l.url,m=!g||g==="openapi",b=await p.apiUrlToApiId({projectPath:this.project.userFilesDir,apiUrl:y,collectionId:o.relative_path});if(m){const c=await this.apiLoader.get(b);c&&a.push(c)}}));const u=await p.PathUtils.join(this.project.userFilesDir,o.relative_path),f=await this.collectionsStorage.parse({uri:o.relative_path,type:p.SourceType.FS,content:h,fileDependencies:new Set([u])},a);return await p.clearNotificationsForSource(o.relative_path),f}catch(d){return console.info(`Error parsing Arazzo file ${o.relative_path}:`,d),await p.reportParseError(o.relative_path,d),null}});return r?.setAttribute("status","completed"),r?.setAttribute("parsedCollectionsCount",n.length),r?.setStatus(p.SpanStatusCode.OK),r?.end(),n}}exports.TauriRootStorage=ve;
|