@dbt-tools/web 0.3.2 → 0.3.4

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/README.md CHANGED
@@ -1,43 +1,208 @@
1
1
  # @dbt-tools/web
2
2
 
3
- Web application for visual dbt artifact analysis.
3
+ React web application for visual dbt artifact analysis. Provides interactive dependency graph exploration and execution timeline visualization.
4
4
 
5
- ## Development
5
+ ---
6
+
7
+ ## Prerequisites
8
+
9
+ - **Node.js** ≥ 18
10
+ - **pnpm** ≥ 8 (the monorepo uses pnpm workspaces)
11
+ - A dbt project with a `./target/` directory containing `manifest.json` and/or `run_results.json`
12
+
13
+ ---
14
+
15
+ ## Tech Stack
16
+
17
+ | Layer | Technology |
18
+ | --------------- | ---------------------------------------------------------------- |
19
+ | UI framework | [React 18](https://react.dev/) |
20
+ | Build tool | [Vite 6](https://vitejs.dev/) |
21
+ | Charts | [Recharts](https://recharts.org/) |
22
+ | Virtualization | [@tanstack/react-virtual](https://tanstack.com/virtual) |
23
+ | Analysis engine | `@dbt-tools/core` (web worker, `@dbt-tools/core/browser` export) |
24
+ | E2E tests | [Playwright](https://playwright.dev/) |
25
+ | Language | TypeScript 5 |
26
+
27
+ ---
28
+
29
+ ## Features
30
+
31
+ - **Dependency graph visualization** — explore model relationships as an interactive graph
32
+ - **Execution timeline** — Gantt-style view of `run_results.json` with critical path highlighting
33
+ - **Auto-reload** — automatically re-analyzes artifacts when `dbt run` completes
34
+ - **Large project support** — virtualized lists and web workers keep the UI responsive at 100k+ nodes
35
+
36
+ ---
37
+
38
+ ## Architecture
39
+
40
+ ```mermaid
41
+ graph TD
42
+ FS["./target/\nmanifest.json\nrun_results.json"]
43
+ VDS[Vite Dev Server\nDBT_TARGET middleware]
44
+ APP[React App]
45
+ WW[Web Worker]
46
+ CORE["@dbt-tools/core/browser\nManifestGraph · ExecutionAnalyzer"]
47
+
48
+ FS -->|file watch| VDS
49
+ VDS -->|GET /api/manifest.json\nGET /api/run_results.json| APP
50
+ APP -->|postMessage| WW
51
+ WW --> CORE
52
+ CORE -->|graph · analysis results| WW
53
+ WW -->|postMessage| APP
54
+ APP -->|renders| UI[Dependency Graph\nExecution Timeline\nSummary Stats]
55
+ ```
56
+
57
+ Heavy analysis runs in a web worker to keep the main thread free. The worker imports from `@dbt-tools/core/browser` (the Node.js-free export) so it works without any server-side code.
6
58
 
7
- ### Preloading artifacts from a local target directory
59
+ ---
8
60
 
9
- Set `DBT_TARGET` to serve `manifest.json` and `run_results.json` from that directory at `/api/manifest.json` and `/api/run_results.json`:
61
+ ## Running Locally
62
+
63
+ The web app is not published to npm. Run it from the monorepo:
10
64
 
11
65
  ```bash
12
- DBT_TARGET=./target pnpm dev
13
- # or
14
- pnpm dev:target
66
+ # From repo root
67
+ pnpm dev:web
68
+
69
+ # Or from the package directory
70
+ cd packages/dbt-tools/web
71
+ pnpm dev
15
72
  ```
16
73
 
17
- Open the URL Vite prints (e.g. `http://localhost:5173/`). If the port changes (e.g. 5174), use that URL so requests hit the server with `DBT_TARGET` configured.
74
+ ### Preloading artifacts from a local dbt project
75
+
76
+ Set `DBT_TARGET` to serve `manifest.json` and `run_results.json` from that directory:
77
+
78
+ ```bash
79
+ DBT_TARGET=./target pnpm dev
80
+ # or use the dev:target convenience script from the package directory:
81
+ pnpm dev:target # shorthand for DBT_TARGET=./target vite
82
+ ```
18
83
 
19
- ### Debug logging
84
+ Then open the URL Vite prints (e.g. `http://localhost:5173/`).
20
85
 
21
- - **Server**: `DBT_DEBUG=1` when starting dev to see dbt-target middleware logs in the terminal.
22
- - **Client**: Add `?debug=1` to the URL to see preload logs in the browser console.
86
+ ### Debug Logging
23
87
 
24
- Example:
88
+ - **Server-side** (Vite middleware): set `DBT_DEBUG=1` when starting dev
89
+ - **Client-side** (browser console): add `?debug=1` to the URL
25
90
 
26
91
  ```bash
27
92
  DBT_DEBUG=1 DBT_TARGET=~/path/to/target pnpm dev
93
+ # then open: http://localhost:5173/?debug=1
94
+ ```
95
+
96
+ ### Auto-reload When Artifacts Change
97
+
98
+ When `DBT_TARGET` is set, the app automatically reloads and re-analyzes when `manifest.json` or `run_results.json` change on disk (e.g. after `dbt run`):
99
+
100
+ | Variable | Default | Description |
101
+ | ------------------------ | ------- | ----------------------------------------------------------- |
102
+ | `DBT_WATCH` | `1` | Enable (`1`) or disable (`0`) file watching and auto-reload |
103
+ | `DBT_RELOAD_DEBOUNCE_MS` | `300` | Debounce in ms for rapid file writes |
104
+
105
+ ```bash
106
+ # Disable auto-reload
107
+ DBT_WATCH=0 DBT_TARGET=./target pnpm dev
28
108
  ```
29
109
 
30
- Then open `http://localhost:5173/?debug=1` (or the port Vite prints).
110
+ ---
111
+
112
+ ## Configuration
31
113
 
32
- ### Auto-reload when artifacts change
114
+ All configuration is via environment variables passed to the Vite dev server or build:
33
115
 
34
- When `DBT_TARGET` is set, the app automatically reloads and re-analyzes when `manifest.json` or `run_results.json` change on disk (e.g. after running `dbt run`). Configuration:
116
+ | Variable | Default | Description |
117
+ | ------------------------ | ------- | -------------------------------------------------------------------------------------------------- |
118
+ | `DBT_TARGET` | — | Directory containing `manifest.json` and `run_results.json`; enables the `/api/*` proxy middleware |
119
+ | `DBT_DEBUG` | `0` | Set to `1` to enable server-side debug logging in the Vite middleware |
120
+ | `DBT_WATCH` | `1` | Enable (`1`) or disable (`0`) file watching and auto-reload when artifacts change |
121
+ | `DBT_RELOAD_DEBOUNCE_MS` | `300` | Debounce delay in ms before triggering a reload on rapid file writes |
35
122
 
36
- - **`DBT_WATCH`**: `1` (default) = enable file watch and auto-reload; `0` = disable.
37
- - **`DBT_RELOAD_DEBOUNCE_MS`**: Debounce in ms for rapid file writes (default: 300).
123
+ Add `?debug=1` to the browser URL to enable client-side debug logging.
38
124
 
39
- Example:
125
+ ---
126
+
127
+ ## Building for Production
40
128
 
41
129
  ```bash
42
- DBT_WATCH=0 DBT_TARGET=./target pnpm dev
130
+ pnpm build
131
+ # Output in dist/
132
+ pnpm preview # serve the production build locally
43
133
  ```
134
+
135
+ ---
136
+
137
+ ## Project Structure
138
+
139
+ ```text
140
+ packages/dbt-tools/web/
141
+ ├── src/
142
+ │ ├── components/ # React UI components
143
+ │ │ ├── AnalysisWorkspace/ # Gantt timeline and execution view
144
+ │ │ ├── AppShell/ # Top-level layout shell
145
+ │ │ └── ui/ # Shared primitive components
146
+ │ ├── hooks/ # Custom React hooks
147
+ │ ├── services/ # Data-fetching and artifact API services
148
+ │ ├── workers/ # Web worker for off-thread analysis
149
+ │ ├── constants/ # Theme colors and shared constants
150
+ │ ├── lib/ # Analysis workspace helpers
151
+ │ ├── styles/ # CSS tokens, base, and component styles
152
+ │ ├── App.tsx # Root application component
153
+ │ └── main.tsx # Entry point
154
+ ├── e2e/ # Playwright end-to-end test specs
155
+ ├── vite.config.ts # Vite + Vite middleware (DBT_TARGET proxy)
156
+ └── package.json
157
+ ```
158
+
159
+ ---
160
+
161
+ ## E2E Tests
162
+
163
+ The web app has Playwright end-to-end tests:
164
+
165
+ ```bash
166
+ pnpm test:e2e
167
+ ```
168
+
169
+ See `e2e/` for test specs.
170
+
171
+ ---
172
+
173
+ ## Troubleshooting
174
+
175
+ | Symptom | Fix |
176
+ | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
177
+ | Blank page / "No artifacts found" | Ensure `DBT_TARGET` points to a directory that contains `manifest.json` |
178
+ | Auto-reload not triggering | Check `DBT_WATCH` is not set to `0`; verify the file watcher has read access to the target directory |
179
+ | Slow UI with large manifests | The web worker and virtualized lists should handle 100k+ nodes; if performance still degrades, open the browser profiler and check for main-thread analysis code paths |
180
+ | `GET /api/manifest.json` returns 404 | `DBT_TARGET` is not set or the Vite dev server was started without it |
181
+ | Debug logs not appearing | Server-side: restart dev with `DBT_DEBUG=1`; client-side: add `?debug=1` to the URL |
182
+
183
+ ---
184
+
185
+ ## Development
186
+
187
+ ```bash
188
+ pnpm build # TypeScript + Vite build
189
+ pnpm dev # Vite dev server with HMR
190
+ ```
191
+
192
+ See [CONTRIBUTING.md](../../../CONTRIBUTING.md) for the full developer guide, including how to set up the monorepo and run all tests.
193
+
194
+ ---
195
+
196
+ ## Related Packages
197
+
198
+ | Package | Description |
199
+ | -------------------------------------------------------------- | ---------------------------------------------------------------------------- |
200
+ | [`@dbt-tools/core`](../core/README.md) | Analysis engine used by this web app (dependency graphs, execution analysis) |
201
+ | [`@dbt-tools/cli`](../cli/README.md) | Command-line interface for the same analysis, optimized for AI agents |
202
+ | [`dbt-artifacts-parser`](../../dbt-artifacts-parser/README.md) | Standalone library for parsing and typing dbt JSON artifacts |
203
+
204
+ ---
205
+
206
+ ## License
207
+
208
+ Apache License 2.0.
@@ -0,0 +1 @@
1
+ (function(){var e=(e,t)=>()=>(e&&(t=e(e=0)),t),t=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),n=e((()=>{}));function r(e){if(!e)return null;let t=e.match(/\/manifest\/v(\d+)\.json$/);return t?parseInt(t[1],10):null}function i(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v1`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v1.json`))throw Error(`Not a manifest.json v1`);return e}function a(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v2`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v2.json`))throw Error(`Not a manifest.json v2`);return e}function o(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v3`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v3.json`))throw Error(`Not a manifest.json v3`);return e}function s(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v4`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v4.json`))throw Error(`Not a manifest.json v4`);return e}function c(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v5`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v5.json`))throw Error(`Not a manifest.json v5`);return e}function l(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v6`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v6.json`))throw Error(`Not a manifest.json v6`);return e}function u(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v7`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v7.json`))throw Error(`Not a manifest.json v7`);return e}function d(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v8`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v8.json`))throw Error(`Not a manifest.json v8`);return e}function f(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v9`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v9.json`))throw Error(`Not a manifest.json v9`);return e}function p(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v10`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v10.json`))throw Error(`Not a manifest.json v10`);return e}function m(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v11`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v11.json`))throw Error(`Not a manifest.json v11`);return e}function h(e){let t=e.metadata;if(!t)throw Error(`Not a manifest.json v12`);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v12.json`))throw Error(`Not a manifest.json v12`);return e}function g(e){let t=e.metadata;if(!t)throw Error(_);let n=t.dbt_schema_version;if(!n||!n.includes(`/manifest/v`))throw Error(_);let i=r(n);if(i===null)throw Error(_);let a=v[i-1];if(!a)throw Error(`Unsupported manifest version: ${i}`);return a(e)}var _,v,ee=e((()=>{n(),_=`Not a manifest.json`,v=[i,a,o,s,c,l,u,d,f,p,m,h]})),y=e((()=>{}));function b(e){if(!e)return null;let t=e.match(/\/run-results\/v(\d+)\.json$/);return t?parseInt(t[1],10):null}function x(e){let t=e.metadata;if(!t)throw Error(`Not a run-results.json v1`);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v1.json`))throw Error(`Not a run-results.json v1`);return e}function S(e){let t=e.metadata;if(!t)throw Error(`Not a run-results.json v2`);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v2.json`))throw Error(`Not a run-results.json v2`);return e}function te(e){let t=e.metadata;if(!t)throw Error(`Not a run-results.json v3`);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v3.json`))throw Error(`Not a run-results.json v3`);return e}function ne(e){let t=e.metadata;if(!t)throw Error(`Not a run-results.json v4`);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v4.json`))throw Error(`Not a run-results.json v4`);return e}function re(e){let t=e.metadata;if(!t)throw Error(`Not a run-results.json v5`);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v5.json`))throw Error(`Not a run-results.json v5`);return e}function ie(e){let t=e.metadata;if(!t)throw Error(`Not a run-results.json v6`);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v6.json`))throw Error(`Not a run-results.json v6`);return e}function ae(e){let t=e.metadata;if(!t)throw Error(C);let n=t.dbt_schema_version;if(!n||!n.includes(`/run-results/v`))throw Error(C);let r=b(n);if(r===null)throw Error(C);let i=oe[r-1];if(!i)throw Error(`Unsupported run-results version: ${r}`);return i(e)}var C,oe,se=e((()=>{y(),C=`Not a run-results.json`,oe=[x,S,te,ne,re,ie]}));ee(),se();let w={accent:`#635BFF`,text:`#171C28`,textSoft:`#6B7385`,bg:`#F6F7FB`,bgSoft:`#FFFFFF`,borderDefault:`#D7DCE7`,borderSubtle:`#E6E9F0`,slate:`#64748B`,rose:`#C0352B`,mint:`#0F8A4B`,amber:`#A56315`},T={accent:`#8A7CFF`,text:`#F3F6FC`,textSoft:`#98A3BC`,bg:`#0D1120`,bgSoft:`#151A2E`,borderDefault:`#313A58`,borderSubtle:`#262E47`,slate:`#8690AA`,rose:`#FF8D86`,mint:`#59D38C`,amber:`#F5B95C`};function ce(e){return e===`dark`?T:w}w.mint,w.rose,w.slate,w.rose,w.mint,w.rose,w.amber,w.slate,T.mint,T.rose,T.slate,T.rose,T.mint,T.rose,T.amber,T.slate,w.text,w.textSoft,w.slate,w.accent,T.text,T.textSoft,T.slate,T.accent;function le(e){let t=ce(e);return{positive:t.mint,warning:t.amber,danger:t.rose,neutral:t.slate}}le(`light`);function ue(e,t){if(!t)return!0;let n=t.trim().toLowerCase();return n?[e.name,e.resourceType,e.packageName,e.path??``,e.originalFilePath??``,e.patchPath??``,e.uniqueId].some(e=>e.toLowerCase().includes(n)):!0}var de=t(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=ee,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,`defaultMaxListeners`,{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function ee(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}b(e,t,a,{once:!0}),t!==`error`&&y(e,i,{once:!0})})}function y(e,t,n){typeof e.on==`function`&&b(e,`error`,t,n)}function b(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}}))();function fe(){let e=arguments[0];for(let t=1,n=arguments.length;t<n;t++)if(arguments[t])for(let n in arguments[t])e[n]=arguments[t][n];return e}let E=fe;typeof Object.assign==`function`&&(E=Object.assign);function D(e,t,n,r){let i=e._nodes.get(t),a=null;return i&&(a=r===`mixed`?i.out&&i.out[n]||i.undirected&&i.undirected[n]:r===`directed`?i.out&&i.out[n]:i.undirected&&i.undirected[n]),a}function O(e){return typeof e==`object`&&!!e}function pe(e){let t;for(t in e)return!1;return!0}function k(e,t,n){Object.defineProperty(e,t,{enumerable:!1,configurable:!1,writable:!0,value:n})}function A(e,t,n){let r={enumerable:!0,configurable:!0};typeof n==`function`?r.get=n:(r.value=n,r.writable=!1),Object.defineProperty(e,t,r)}function me(e){return!(!O(e)||e.attributes&&!Array.isArray(e.attributes))}function he(){let e=Math.floor(Math.random()*256)&255;return()=>e++}function j(){let e=arguments,t=null,n=-1;return{[Symbol.iterator](){return this},next(){let r=null;do{if(t===null){if(n++,n>=e.length)return{done:!0};t=e[n][Symbol.iterator]()}if(r=t.next(),r.done){t=null;continue}break}while(!0);return r}}}function M(){return{[Symbol.iterator](){return this},next(){return{done:!0}}}}var ge=class extends Error{constructor(e){super(),this.name=`GraphError`,this.message=e}},N=class e extends ge{constructor(t){super(t),this.name=`InvalidArgumentsGraphError`,typeof Error.captureStackTrace==`function`&&Error.captureStackTrace(this,e.prototype.constructor)}},P=class e extends ge{constructor(t){super(t),this.name=`NotFoundGraphError`,typeof Error.captureStackTrace==`function`&&Error.captureStackTrace(this,e.prototype.constructor)}},F=class e extends ge{constructor(t){super(t),this.name=`UsageGraphError`,typeof Error.captureStackTrace==`function`&&Error.captureStackTrace(this,e.prototype.constructor)}};function _e(e,t){this.key=e,this.attributes=t,this.clear()}_e.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.undirectedLoops=0,this.directedLoops=0,this.in={},this.out={},this.undirected={}};function ve(e,t){this.key=e,this.attributes=t,this.clear()}ve.prototype.clear=function(){this.inDegree=0,this.outDegree=0,this.directedLoops=0,this.in={},this.out={}};function ye(e,t){this.key=e,this.attributes=t,this.clear()}ye.prototype.clear=function(){this.undirectedDegree=0,this.undirectedLoops=0,this.undirected={}};function I(e,t,n,r,i){this.key=t,this.attributes=i,this.undirected=e,this.source=n,this.target=r}I.prototype.attach=function(){let e=`out`,t=`in`;this.undirected&&(e=t=`undirected`);let n=this.source.key,r=this.target.key;this.source[e][r]=this,!(this.undirected&&n===r)&&(this.target[t][n]=this)},I.prototype.attachMulti=function(){let e=`out`,t=`in`,n=this.source.key,r=this.target.key;this.undirected&&(e=t=`undirected`);let i=this.source[e],a=i[r];if(a===void 0){i[r]=this,this.undirected&&n===r||(this.target[t][n]=this);return}a.previous=this,this.next=a,i[r]=this,this.target[t][n]=this},I.prototype.detach=function(){let e=this.source.key,t=this.target.key,n=`out`,r=`in`;this.undirected&&(n=r=`undirected`),delete this.source[n][t],delete this.target[r][e]},I.prototype.detachMulti=function(){let e=this.source.key,t=this.target.key,n=`out`,r=`in`;this.undirected&&(n=r=`undirected`),this.previous===void 0?this.next===void 0?(delete this.source[n][t],delete this.target[r][e]):(this.next.previous=void 0,this.source[n][t]=this.next,this.target[r][e]=this.next):(this.previous.next=this.next,this.next!==void 0&&(this.next.previous=this.previous))};function L(e,t,n,r,i,a,o){let s,c,l,u;if(r=``+r,n===0){if(s=e._nodes.get(r),!s)throw new P(`Graph.${t}: could not find the "${r}" node in the graph.`);l=i,u=a}else if(n===3){if(i=``+i,c=e._edges.get(i),!c)throw new P(`Graph.${t}: could not find the "${i}" edge in the graph.`);let n=c.source.key,d=c.target.key;if(r===n)s=c.target;else if(r===d)s=c.source;else throw new P(`Graph.${t}: the "${r}" node is not attached to the "${i}" edge (${n}, ${d}).`);l=a,u=o}else{if(c=e._edges.get(r),!c)throw new P(`Graph.${t}: could not find the "${r}" edge in the graph.`);s=n===1?c.source:c.target,l=i,u=a}return[s,l,u]}function be(e,t,n){e.prototype[t]=function(e,r,i){let[a,o]=L(this,t,n,e,r,i);return a.attributes[o]}}function xe(e,t,n){e.prototype[t]=function(e,r){let[i]=L(this,t,n,e,r);return i.attributes}}function Se(e,t,n){e.prototype[t]=function(e,r,i){let[a,o]=L(this,t,n,e,r,i);return a.attributes.hasOwnProperty(o)}}function Ce(e,t,n){e.prototype[t]=function(e,r,i,a){let[o,s,c]=L(this,t,n,e,r,i,a);return o.attributes[s]=c,this.emit(`nodeAttributesUpdated`,{key:o.key,type:`set`,attributes:o.attributes,name:s}),this}}function we(e,t,n){e.prototype[t]=function(e,r,i,a){let[o,s,c]=L(this,t,n,e,r,i,a);if(typeof c!=`function`)throw new N(`Graph.${t}: updater should be a function.`);let l=o.attributes;return l[s]=c(l[s]),this.emit(`nodeAttributesUpdated`,{key:o.key,type:`set`,attributes:o.attributes,name:s}),this}}function Te(e,t,n){e.prototype[t]=function(e,r,i){let[a,o]=L(this,t,n,e,r,i);return delete a.attributes[o],this.emit(`nodeAttributesUpdated`,{key:a.key,type:`remove`,attributes:a.attributes,name:o}),this}}function Ee(e,t,n){e.prototype[t]=function(e,r,i){let[a,o]=L(this,t,n,e,r,i);if(!O(o))throw new N(`Graph.${t}: provided attributes are not a plain object.`);return a.attributes=o,this.emit(`nodeAttributesUpdated`,{key:a.key,type:`replace`,attributes:a.attributes}),this}}function De(e,t,n){e.prototype[t]=function(e,r,i){let[a,o]=L(this,t,n,e,r,i);if(!O(o))throw new N(`Graph.${t}: provided attributes are not a plain object.`);return E(a.attributes,o),this.emit(`nodeAttributesUpdated`,{key:a.key,type:`merge`,attributes:a.attributes,data:o}),this}}function Oe(e,t,n){e.prototype[t]=function(e,r,i){let[a,o]=L(this,t,n,e,r,i);if(typeof o!=`function`)throw new N(`Graph.${t}: provided updater is not a function.`);return a.attributes=o(a.attributes),this.emit(`nodeAttributesUpdated`,{key:a.key,type:`update`,attributes:a.attributes}),this}}let ke=[{name:e=>`get${e}Attribute`,attacher:be},{name:e=>`get${e}Attributes`,attacher:xe},{name:e=>`has${e}Attribute`,attacher:Se},{name:e=>`set${e}Attribute`,attacher:Ce},{name:e=>`update${e}Attribute`,attacher:we},{name:e=>`remove${e}Attribute`,attacher:Te},{name:e=>`replace${e}Attributes`,attacher:Ee},{name:e=>`merge${e}Attributes`,attacher:De},{name:e=>`update${e}Attributes`,attacher:Oe}];function Ae(e){ke.forEach(function({name:t,attacher:n}){n(e,t(`Node`),0),n(e,t(`Source`),1),n(e,t(`Target`),2),n(e,t(`Opposite`),3)})}function je(e,t,n){e.prototype[t]=function(e,r){let i;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=``+e,o=``+r;if(r=arguments[2],i=D(this,a,o,n),!i)throw new P(`Graph.${t}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,i=this._edges.get(e),!i)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}return i.attributes[r]}}function Me(e,t,n){e.prototype[t]=function(e){let r;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>1){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let i=``+e,a=``+arguments[1];if(r=D(this,i,a,n),!r)throw new P(`Graph.${t}: could not find an edge for the given path ("${i}" - "${a}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,r=this._edges.get(e),!r)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}return r.attributes}}function Ne(e,t,n){e.prototype[t]=function(e,r){let i;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=``+e,o=``+r;if(r=arguments[2],i=D(this,a,o,n),!i)throw new P(`Graph.${t}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,i=this._edges.get(e),!i)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}return i.attributes.hasOwnProperty(r)}}function Pe(e,t,n){e.prototype[t]=function(e,r,i){let a;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=``+e,s=``+r;if(r=arguments[2],i=arguments[3],a=D(this,o,s,n),!a)throw new P(`Graph.${t}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,a=this._edges.get(e),!a)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}return a.attributes[r]=i,this.emit(`edgeAttributesUpdated`,{key:a.key,type:`set`,attributes:a.attributes,name:r}),this}}function Fe(e,t,n){e.prototype[t]=function(e,r,i){let a;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>3){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let o=``+e,s=``+r;if(r=arguments[2],i=arguments[3],a=D(this,o,s,n),!a)throw new P(`Graph.${t}: could not find an edge for the given path ("${o}" - "${s}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,a=this._edges.get(e),!a)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}if(typeof i!=`function`)throw new N(`Graph.${t}: updater should be a function.`);return a.attributes[r]=i(a.attributes[r]),this.emit(`edgeAttributesUpdated`,{key:a.key,type:`set`,attributes:a.attributes,name:r}),this}}function Ie(e,t,n){e.prototype[t]=function(e,r){let i;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=``+e,o=``+r;if(r=arguments[2],i=D(this,a,o,n),!i)throw new P(`Graph.${t}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,i=this._edges.get(e),!i)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}return delete i.attributes[r],this.emit(`edgeAttributesUpdated`,{key:i.key,type:`remove`,attributes:i.attributes,name:r}),this}}function Le(e,t,n){e.prototype[t]=function(e,r){let i;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=``+e,o=``+r;if(r=arguments[2],i=D(this,a,o,n),!i)throw new P(`Graph.${t}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,i=this._edges.get(e),!i)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}if(!O(r))throw new N(`Graph.${t}: provided attributes are not a plain object.`);return i.attributes=r,this.emit(`edgeAttributesUpdated`,{key:i.key,type:`replace`,attributes:i.attributes}),this}}function Re(e,t,n){e.prototype[t]=function(e,r){let i;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=``+e,o=``+r;if(r=arguments[2],i=D(this,a,o,n),!i)throw new P(`Graph.${t}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,i=this._edges.get(e),!i)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}if(!O(r))throw new N(`Graph.${t}: provided attributes are not a plain object.`);return E(i.attributes,r),this.emit(`edgeAttributesUpdated`,{key:i.key,type:`merge`,attributes:i.attributes,data:r}),this}}function ze(e,t,n){e.prototype[t]=function(e,r){let i;if(this.type!==`mixed`&&n!==`mixed`&&n!==this.type)throw new F(`Graph.${t}: cannot find this type of edges in your ${this.type} graph.`);if(arguments.length>2){if(this.multi)throw new F(`Graph.${t}: cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.`);let a=``+e,o=``+r;if(r=arguments[2],i=D(this,a,o,n),!i)throw new P(`Graph.${t}: could not find an edge for the given path ("${a}" - "${o}").`)}else{if(n!==`mixed`)throw new F(`Graph.${t}: calling this method with only a key (vs. a source and target) does not make sense since an edge with this key could have the other type.`);if(e=``+e,i=this._edges.get(e),!i)throw new P(`Graph.${t}: could not find the "${e}" edge in the graph.`)}if(typeof r!=`function`)throw new N(`Graph.${t}: provided updater is not a function.`);return i.attributes=r(i.attributes),this.emit(`edgeAttributesUpdated`,{key:i.key,type:`update`,attributes:i.attributes}),this}}let Be=[{name:e=>`get${e}Attribute`,attacher:je},{name:e=>`get${e}Attributes`,attacher:Me},{name:e=>`has${e}Attribute`,attacher:Ne},{name:e=>`set${e}Attribute`,attacher:Pe},{name:e=>`update${e}Attribute`,attacher:Fe},{name:e=>`remove${e}Attribute`,attacher:Ie},{name:e=>`replace${e}Attributes`,attacher:Le},{name:e=>`merge${e}Attributes`,attacher:Re},{name:e=>`update${e}Attributes`,attacher:ze}];function Ve(e){Be.forEach(function({name:t,attacher:n}){n(e,t(`Edge`),`mixed`),n(e,t(`DirectedEdge`),`directed`),n(e,t(`UndirectedEdge`),`undirected`)})}let He=[{name:`edges`,type:`mixed`},{name:`inEdges`,type:`directed`,direction:`in`},{name:`outEdges`,type:`directed`,direction:`out`},{name:`inboundEdges`,type:`mixed`,direction:`in`},{name:`outboundEdges`,type:`mixed`,direction:`out`},{name:`directedEdges`,type:`directed`},{name:`undirectedEdges`,type:`undirected`}];function Ue(e,t,n,r){let i=!1;for(let a in t){if(a===r)continue;let o=t[a];if(i=n(o.key,o.attributes,o.source.key,o.target.key,o.source.attributes,o.target.attributes,o.undirected),e&&i)return o.key}}function We(e,t,n,r){let i,a,o,s=!1;for(let c in t)if(c!==r){i=t[c];do{if(a=i.source,o=i.target,s=n(i.key,i.attributes,a.key,o.key,a.attributes,o.attributes,i.undirected),e&&s)return i.key;i=i.next}while(i!==void 0)}}function R(e,t){let n=Object.keys(e),r=n.length,i,a=0;return{[Symbol.iterator](){return this},next(){do if(i)i=i.next;else{if(a>=r)return{done:!0};let o=n[a++];if(o===t){i=void 0;continue}i=e[o]}while(!i);return{done:!1,value:{edge:i.key,attributes:i.attributes,source:i.source.key,target:i.target.key,sourceAttributes:i.source.attributes,targetAttributes:i.target.attributes,undirected:i.undirected}}}}}function Ge(e,t,n,r){let i=t[n];if(!i)return;let a=i.source,o=i.target;if(r(i.key,i.attributes,a.key,o.key,a.attributes,o.attributes,i.undirected)&&e)return i.key}function Ke(e,t,n,r){let i=t[n];if(!i)return;let a=!1;do{if(a=r(i.key,i.attributes,i.source.key,i.target.key,i.source.attributes,i.target.attributes,i.undirected),e&&a)return i.key;i=i.next}while(i!==void 0)}function z(e,t){let n=e[t];if(n.next!==void 0)return{[Symbol.iterator](){return this},next(){if(!n)return{done:!0};let e={edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected};return n=n.next,{done:!1,value:e}}};let r=!1;return{[Symbol.iterator](){return this},next(){return r===!0?{done:!0}:(r=!0,{done:!1,value:{edge:n.key,attributes:n.attributes,source:n.source.key,target:n.target.key,sourceAttributes:n.source.attributes,targetAttributes:n.target.attributes,undirected:n.undirected}})}}}function qe(e,t){if(e.size===0)return[];if(t===`mixed`||t===e.type)return Array.from(e._edges.keys());let n=t===`undirected`?e.undirectedSize:e.directedSize,r=Array(n),i=t===`undirected`,a=e._edges.values(),o=0,s,c;for(;s=a.next(),s.done!==!0;)c=s.value,c.undirected===i&&(r[o++]=c.key);return r}function Je(e,t,n,r){if(t.size===0)return;let i=n!==`mixed`&&n!==t.type,a=n===`undirected`,o,s,c=!1,l=t._edges.values();for(;o=l.next(),o.done!==!0;){if(s=o.value,i&&s.undirected!==a)continue;let{key:t,attributes:n,source:l,target:u}=s;if(c=r(t,n,l.key,u.key,l.attributes,u.attributes,s.undirected),e&&c)return t}}function Ye(e,t){if(e.size===0)return M();let n=t!==`mixed`&&t!==e.type,r=t===`undirected`,i=e._edges.values();return{[Symbol.iterator](){return this},next(){let e,t;for(;;){if(e=i.next(),e.done)return e;if(t=e.value,!(n&&t.undirected!==r))break}return{value:{edge:t.key,attributes:t.attributes,source:t.source.key,target:t.target.key,sourceAttributes:t.source.attributes,targetAttributes:t.target.attributes,undirected:t.undirected},done:!1}}}}function Xe(e,t,n,r,i,a){let o=t?We:Ue,s;if(n!==`undirected`&&(r!==`out`&&(s=o(e,i.in,a),e&&s)||r!==`in`&&(s=o(e,i.out,a,r?void 0:i.key),e&&s))||n!==`directed`&&(s=o(e,i.undirected,a),e&&s))return s}function Ze(e,t,n,r){let i=[];return Xe(!1,e,t,n,r,function(e){i.push(e)}),i}function Qe(e,t,n){let r=M();return e!==`undirected`&&(t!==`out`&&n.in!==void 0&&(r=j(r,R(n.in))),t!==`in`&&n.out!==void 0&&(r=j(r,R(n.out,t?void 0:n.key)))),e!==`directed`&&n.undirected!==void 0&&(r=j(r,R(n.undirected))),r}function $e(e,t,n,r,i,a,o){let s=n?Ke:Ge,c;if(t!==`undirected`&&(i.in!==void 0&&r!==`out`&&(c=s(e,i.in,a,o),e&&c)||i.out!==void 0&&r!==`in`&&(r||i.key!==a)&&(c=s(e,i.out,a,o),e&&c))||t!==`directed`&&i.undirected!==void 0&&(c=s(e,i.undirected,a,o),e&&c))return c}function et(e,t,n,r,i){let a=[];return $e(!1,e,t,n,r,i,function(e){a.push(e)}),a}function tt(e,t,n,r){let i=M();return e!==`undirected`&&(n.in!==void 0&&t!==`out`&&r in n.in&&(i=j(i,z(n.in,r))),n.out!==void 0&&t!==`in`&&r in n.out&&(t||n.key!==r)&&(i=j(i,z(n.out,r)))),e!==`directed`&&n.undirected!==void 0&&r in n.undirected&&(i=j(i,z(n.undirected,r))),i}function nt(e,t){let{name:n,type:r,direction:i}=t;e.prototype[n]=function(e,t){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return[];if(!arguments.length)return qe(this,r);if(arguments.length===1){e=``+e;let t=this._nodes.get(e);if(t===void 0)throw new P(`Graph.${n}: could not find the "${e}" node in the graph.`);return Ze(this.multi,r===`mixed`?this.type:r,i,t)}if(arguments.length===2){e=``+e,t=``+t;let a=this._nodes.get(e);if(!a)throw new P(`Graph.${n}: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.${n}: could not find the "${t}" target node in the graph.`);return et(r,this.multi,i,a,t)}throw new N(`Graph.${n}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function rt(e,t){let{name:n,type:r,direction:i}=t,a=`forEach`+n[0].toUpperCase()+n.slice(1,-1);e.prototype[a]=function(e,t,n){if(!(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)){if(arguments.length===1)return n=e,Je(!1,this,r,n);if(arguments.length===2){e=``+e,n=t;let o=this._nodes.get(e);if(o===void 0)throw new P(`Graph.${a}: could not find the "${e}" node in the graph.`);return Xe(!1,this.multi,r===`mixed`?this.type:r,i,o,n)}if(arguments.length===3){e=``+e,t=``+t;let o=this._nodes.get(e);if(!o)throw new P(`Graph.${a}: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.${a}: could not find the "${t}" target node in the graph.`);return $e(!1,r,this.multi,i,o,t,n)}throw new N(`Graph.${a}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)}};let o=`map`+n[0].toUpperCase()+n.slice(1);e.prototype[o]=function(){let e=Array.prototype.slice.call(arguments),t=e.pop(),n;if(e.length===0){let i=0;r!==`directed`&&(i+=this.undirectedSize),r!==`undirected`&&(i+=this.directedSize),n=Array(i);let a=0;e.push((e,r,i,o,s,c,l)=>{n[a++]=t(e,r,i,o,s,c,l)})}else n=[],e.push((e,r,i,a,o,s,c)=>{n.push(t(e,r,i,a,o,s,c))});return this[a].apply(this,e),n};let s=`filter`+n[0].toUpperCase()+n.slice(1);e.prototype[s]=function(){let e=Array.prototype.slice.call(arguments),t=e.pop(),n=[];return e.push((e,r,i,a,o,s,c)=>{t(e,r,i,a,o,s,c)&&n.push(e)}),this[a].apply(this,e),n};let c=`reduce`+n[0].toUpperCase()+n.slice(1);e.prototype[c]=function(){let e=Array.prototype.slice.call(arguments);if(e.length<2||e.length>4)throw new N(`Graph.${c}: invalid number of arguments (expecting 2, 3 or 4 and got ${e.length}).`);if(typeof e[e.length-1]==`function`&&typeof e[e.length-2]!=`function`)throw new N(`Graph.${c}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let t,n;e.length===2?(t=e[0],n=e[1],e=[]):e.length===3?(t=e[1],n=e[2],e=[e[0]]):e.length===4&&(t=e[2],n=e[3],e=[e[0],e[1]]);let r=n;return e.push((e,n,i,a,o,s,c)=>{r=t(r,e,n,i,a,o,s,c)}),this[a].apply(this,e),r}}function it(e,t){let{name:n,type:r,direction:i}=t,a=`find`+n[0].toUpperCase()+n.slice(1,-1);e.prototype[a]=function(e,t,n){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return!1;if(arguments.length===1)return n=e,Je(!0,this,r,n);if(arguments.length===2){e=``+e,n=t;let o=this._nodes.get(e);if(o===void 0)throw new P(`Graph.${a}: could not find the "${e}" node in the graph.`);return Xe(!0,this.multi,r===`mixed`?this.type:r,i,o,n)}if(arguments.length===3){e=``+e,t=``+t;let o=this._nodes.get(e);if(!o)throw new P(`Graph.${a}: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.${a}: could not find the "${t}" target node in the graph.`);return $e(!0,r,this.multi,i,o,t,n)}throw new N(`Graph.${a}: too many arguments (expecting 1, 2 or 3 and got ${arguments.length}).`)};let o=`some`+n[0].toUpperCase()+n.slice(1,-1);e.prototype[o]=function(){let e=Array.prototype.slice.call(arguments),t=e.pop();return e.push((e,n,r,i,a,o,s)=>t(e,n,r,i,a,o,s)),!!this[a].apply(this,e)};let s=`every`+n[0].toUpperCase()+n.slice(1,-1);e.prototype[s]=function(){let e=Array.prototype.slice.call(arguments),t=e.pop();return e.push((e,n,r,i,a,o,s)=>!t(e,n,r,i,a,o,s)),!this[a].apply(this,e)}}function at(e,t){let{name:n,type:r,direction:i}=t,a=n.slice(0,-1)+`Entries`;e.prototype[a]=function(e,t){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return M();if(!arguments.length)return Ye(this,r);if(arguments.length===1){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.${a}: could not find the "${e}" node in the graph.`);return Qe(r,i,t)}if(arguments.length===2){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.${a}: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.${a}: could not find the "${t}" target node in the graph.`);return tt(r,i,n,t)}throw new N(`Graph.${a}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`)}}function ot(e){He.forEach(t=>{nt(e,t),rt(e,t),it(e,t),at(e,t)})}let st=[{name:`neighbors`,type:`mixed`},{name:`inNeighbors`,type:`directed`,direction:`in`},{name:`outNeighbors`,type:`directed`,direction:`out`},{name:`inboundNeighbors`,type:`mixed`,direction:`in`},{name:`outboundNeighbors`,type:`mixed`,direction:`out`},{name:`directedNeighbors`,type:`directed`},{name:`undirectedNeighbors`,type:`undirected`}];function B(){this.A=null,this.B=null}B.prototype.wrap=function(e){this.A===null?this.A=e:this.B===null&&(this.B=e)},B.prototype.has=function(e){return this.A!==null&&e in this.A||this.B!==null&&e in this.B};function V(e,t,n,r,i){for(let a in r){let o=r[a],s=o.source,c=o.target,l=s===n?c:s;if(t&&t.has(l.key))continue;let u=i(l.key,l.attributes);if(e&&u)return l.key}}function ct(e,t,n,r,i){if(t!==`mixed`){if(t===`undirected`)return V(e,null,r,r.undirected,i);if(typeof n==`string`)return V(e,null,r,r[n],i)}let a=new B,o;if(t!==`undirected`){if(n!==`out`){if(o=V(e,null,r,r.in,i),e&&o)return o;a.wrap(r.in)}if(n!==`in`){if(o=V(e,a,r,r.out,i),e&&o)return o;a.wrap(r.out)}}if(t!==`directed`&&(o=V(e,a,r,r.undirected,i),e&&o))return o}function lt(e,t,n){if(e!==`mixed`){if(e===`undirected`)return Object.keys(n.undirected);if(typeof t==`string`)return Object.keys(n[t])}let r=[];return ct(!1,e,t,n,function(e){r.push(e)}),r}function H(e,t,n){let r=Object.keys(n),i=r.length,a=0;return{[Symbol.iterator](){return this},next(){let o=null;do{if(a>=i)return e&&e.wrap(n),{done:!0};let s=n[r[a++]],c=s.source,l=s.target;if(o=c===t?l:c,e&&e.has(o.key)){o=null;continue}}while(o===null);return{done:!1,value:{neighbor:o.key,attributes:o.attributes}}}}}function ut(e,t,n){if(e!==`mixed`){if(e===`undirected`)return H(null,n,n.undirected);if(typeof t==`string`)return H(null,n,n[t])}let r=M(),i=new B;return e!==`undirected`&&(t!==`out`&&(r=j(r,H(i,n,n.in))),t!==`in`&&(r=j(r,H(i,n,n.out)))),e!==`directed`&&(r=j(r,H(i,n,n.undirected))),r}function dt(e,t){let{name:n,type:r,direction:i}=t;e.prototype[n]=function(e){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return[];e=``+e;let t=this._nodes.get(e);if(t===void 0)throw new P(`Graph.${n}: could not find the "${e}" node in the graph.`);return lt(r===`mixed`?this.type:r,i,t)}}function ft(e,t){let{name:n,type:r,direction:i}=t,a=`forEach`+n[0].toUpperCase()+n.slice(1,-1);e.prototype[a]=function(e,t){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return;e=``+e;let n=this._nodes.get(e);if(n===void 0)throw new P(`Graph.${a}: could not find the "${e}" node in the graph.`);ct(!1,r===`mixed`?this.type:r,i,n,t)};let o=`map`+n[0].toUpperCase()+n.slice(1);e.prototype[o]=function(e,t){let n=[];return this[a](e,(e,r)=>{n.push(t(e,r))}),n};let s=`filter`+n[0].toUpperCase()+n.slice(1);e.prototype[s]=function(e,t){let n=[];return this[a](e,(e,r)=>{t(e,r)&&n.push(e)}),n};let c=`reduce`+n[0].toUpperCase()+n.slice(1);e.prototype[c]=function(e,t,n){if(arguments.length<3)throw new N(`Graph.${c}: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let r=n;return this[a](e,(e,n)=>{r=t(r,e,n)}),r}}function pt(e,t){let{name:n,type:r,direction:i}=t,a=n[0].toUpperCase()+n.slice(1,-1),o=`find`+a;e.prototype[o]=function(e,t){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return;e=``+e;let n=this._nodes.get(e);if(n===void 0)throw new P(`Graph.${o}: could not find the "${e}" node in the graph.`);return ct(!0,r===`mixed`?this.type:r,i,n,t)};let s=`some`+a;e.prototype[s]=function(e,t){return!!this[o](e,t)};let c=`every`+a;e.prototype[c]=function(e,t){return!this[o](e,(e,n)=>!t(e,n))}}function mt(e,t){let{name:n,type:r,direction:i}=t,a=n.slice(0,-1)+`Entries`;e.prototype[a]=function(e){if(r!==`mixed`&&this.type!==`mixed`&&r!==this.type)return M();e=``+e;let t=this._nodes.get(e);if(t===void 0)throw new P(`Graph.${a}: could not find the "${e}" node in the graph.`);return ut(r===`mixed`?this.type:r,i,t)}}function ht(e){st.forEach(t=>{dt(e,t),ft(e,t),pt(e,t),mt(e,t)})}function U(e,t,n,r,i){let a=r._nodes.values(),o=r.type,s,c,l,u,d,f,p;for(;s=a.next(),s.done!==!0;){let r=!1;if(c=s.value,o!==`undirected`)for(l in u=c.out,u){d=u[l];do{if(f=d.target,r=!0,p=i(c.key,f.key,c.attributes,f.attributes,d.key,d.attributes,d.undirected),e&&p)return d;d=d.next}while(d)}if(o!==`directed`){for(l in u=c.undirected,u)if(!(t&&c.key>l)){d=u[l];do{if(f=d.target,f.key!==l&&(f=d.source),r=!0,p=i(c.key,f.key,c.attributes,f.attributes,d.key,d.attributes,d.undirected),e&&p)return d;d=d.next}while(d)}}if(n&&!r&&(p=i(c.key,null,c.attributes,null,null,null,null),e&&p))return null}}function gt(e,t){let n={key:e};return pe(t.attributes)||(n.attributes=E({},t.attributes)),n}function _t(e,t,n){let r={key:t,source:n.source.key,target:n.target.key};return pe(n.attributes)||(r.attributes=E({},n.attributes)),e===`mixed`&&n.undirected&&(r.undirected=!0),r}function vt(e){if(!O(e))throw new N(`Graph.import: invalid serialized node. A serialized node should be a plain object with at least a "key" property.`);if(!(`key`in e))throw new N(`Graph.import: serialized node is missing its key.`);if(`attributes`in e&&(!O(e.attributes)||e.attributes===null))throw new N(`Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.`)}function yt(e){if(!O(e))throw new N(`Graph.import: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.`);if(!(`source`in e))throw new N(`Graph.import: serialized edge is missing its source.`);if(!(`target`in e))throw new N(`Graph.import: serialized edge is missing its target.`);if(`attributes`in e&&(!O(e.attributes)||e.attributes===null))throw new N(`Graph.import: invalid attributes. Attributes should be a plain object, null or omitted.`);if(`undirected`in e&&typeof e.undirected!=`boolean`)throw new N(`Graph.import: invalid undirectedness information. Undirected should be boolean or omitted.`)}let bt=he(),xt=new Set([`directed`,`undirected`,`mixed`]),St=new Set([`domain`,`_events`,`_eventsCount`,`_maxListeners`]),Ct=[{name:e=>`${e}Edge`,generateKey:!0},{name:e=>`${e}DirectedEdge`,generateKey:!0,type:`directed`},{name:e=>`${e}UndirectedEdge`,generateKey:!0,type:`undirected`},{name:e=>`${e}EdgeWithKey`},{name:e=>`${e}DirectedEdgeWithKey`,type:`directed`},{name:e=>`${e}UndirectedEdgeWithKey`,type:`undirected`}],wt={allowSelfLoops:!0,multi:!1,type:`mixed`};function Tt(e,t,n){if(n&&!O(n))throw new N(`Graph.addNode: invalid attributes. Expecting an object but got "${n}"`);if(t=``+t,n||={},e._nodes.has(t))throw new F(`Graph.addNode: the "${t}" node already exist in the graph.`);let r=new e.NodeDataClass(t,n);return e._nodes.set(t,r),e.emit(`nodeAdded`,{key:t,attributes:n}),r}function Et(e,t,n){let r=new e.NodeDataClass(t,n);return e._nodes.set(t,r),e.emit(`nodeAdded`,{key:t,attributes:n}),r}function Dt(e,t,n,r,i,a,o,s){if(!r&&e.type===`undirected`)throw new F(`Graph.${t}: you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.`);if(r&&e.type===`directed`)throw new F(`Graph.${t}: you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.`);if(s&&!O(s))throw new N(`Graph.${t}: invalid attributes. Expecting an object but got "${s}"`);if(a=``+a,o=``+o,s||={},!e.allowSelfLoops&&a===o)throw new F(`Graph.${t}: source & target are the same ("${a}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let c=e._nodes.get(a),l=e._nodes.get(o);if(!c)throw new P(`Graph.${t}: source node "${a}" not found.`);if(!l)throw new P(`Graph.${t}: target node "${o}" not found.`);let u={key:null,undirected:r,source:a,target:o,attributes:s};if(n)i=e._edgeKeyGenerator();else if(i=``+i,e._edges.has(i))throw new F(`Graph.${t}: the "${i}" edge already exists in the graph.`);if(!e.multi&&(r?c.undirected[o]!==void 0:c.out[o]!==void 0))throw new F(`Graph.${t}: an edge linking "${a}" to "${o}" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.`);let d=new I(r,i,c,l,s);e._edges.set(i,d);let f=a===o;return r?(c.undirectedDegree++,l.undirectedDegree++,f&&(c.undirectedLoops++,e._undirectedSelfLoopCount++)):(c.outDegree++,l.inDegree++,f&&(c.directedLoops++,e._directedSelfLoopCount++)),e.multi?d.attachMulti():d.attach(),r?e._undirectedSize++:e._directedSize++,u.key=i,e.emit(`edgeAdded`,u),i}function Ot(e,t,n,r,i,a,o,s,c){if(!r&&e.type===`undirected`)throw new F(`Graph.${t}: you cannot merge/update a directed edge to an undirected graph. Use the #.mergeEdge/#.updateEdge or #.addUndirectedEdge instead.`);if(r&&e.type===`directed`)throw new F(`Graph.${t}: you cannot merge/update an undirected edge to a directed graph. Use the #.mergeEdge/#.updateEdge or #.addDirectedEdge instead.`);if(s){if(c){if(typeof s!=`function`)throw new N(`Graph.${t}: invalid updater function. Expecting a function but got "${s}"`)}else if(!O(s))throw new N(`Graph.${t}: invalid attributes. Expecting an object but got "${s}"`)}a=``+a,o=``+o;let l;if(c&&(l=s,s=void 0),!e.allowSelfLoops&&a===o)throw new F(`Graph.${t}: source & target are the same ("${a}"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.`);let u=e._nodes.get(a),d=e._nodes.get(o),f,p;if(!n&&(f=e._edges.get(i),f)){if((f.source.key!==a||f.target.key!==o)&&(!r||f.source.key!==o||f.target.key!==a))throw new F(`Graph.${t}: inconsistency detected when attempting to merge the "${i}" edge with "${a}" source & "${o}" target vs. ("${f.source.key}", "${f.target.key}").`);p=f}if(!p&&!e.multi&&u&&(p=r?u.undirected[o]:u.out[o]),p){let t=[p.key,!1,!1,!1];if(c?!l:!s)return t;if(c){let t=p.attributes;p.attributes=l(t),e.emit(`edgeAttributesUpdated`,{type:`replace`,key:p.key,attributes:p.attributes})}else E(p.attributes,s),e.emit(`edgeAttributesUpdated`,{type:`merge`,key:p.key,attributes:p.attributes,data:s});return t}s||={},c&&l&&(s=l(s));let m={key:null,undirected:r,source:a,target:o,attributes:s};if(n)i=e._edgeKeyGenerator();else if(i=``+i,e._edges.has(i))throw new F(`Graph.${t}: the "${i}" edge already exists in the graph.`);let h=!1,g=!1;u||(u=Et(e,a,{}),h=!0,a===o&&(d=u,g=!0)),d||(d=Et(e,o,{}),g=!0),f=new I(r,i,u,d,s),e._edges.set(i,f);let _=a===o;return r?(u.undirectedDegree++,d.undirectedDegree++,_&&(u.undirectedLoops++,e._undirectedSelfLoopCount++)):(u.outDegree++,d.inDegree++,_&&(u.directedLoops++,e._directedSelfLoopCount++)),e.multi?f.attachMulti():f.attach(),r?e._undirectedSize++:e._directedSize++,m.key=i,e.emit(`edgeAdded`,m),[i,!0,h,g]}function W(e,t){e._edges.delete(t.key);let{source:n,target:r,attributes:i}=t,a=t.undirected,o=n===r;a?(n.undirectedDegree--,r.undirectedDegree--,o&&(n.undirectedLoops--,e._undirectedSelfLoopCount--)):(n.outDegree--,r.inDegree--,o&&(n.directedLoops--,e._directedSelfLoopCount--)),e.multi?t.detachMulti():t.detach(),a?e._undirectedSize--:e._directedSize--,e.emit(`edgeDropped`,{key:t.key,attributes:i,source:n.key,target:r.key,undirected:a})}var G=class e extends de.EventEmitter{constructor(e){if(super(),e=E({},wt,e),typeof e.multi!=`boolean`)throw new N(`Graph.constructor: invalid 'multi' option. Expecting a boolean but got "${e.multi}".`);if(!xt.has(e.type))throw new N(`Graph.constructor: invalid 'type' option. Should be one of "mixed", "directed" or "undirected" but got "${e.type}".`);if(typeof e.allowSelfLoops!=`boolean`)throw new N(`Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got "${e.allowSelfLoops}".`);let t=e.type===`mixed`?_e:e.type===`directed`?ve:ye;k(this,`NodeDataClass`,t);let n=`geid_`+bt()+`_`,r=0;k(this,`_attributes`,{}),k(this,`_nodes`,new Map),k(this,`_edges`,new Map),k(this,`_directedSize`,0),k(this,`_undirectedSize`,0),k(this,`_directedSelfLoopCount`,0),k(this,`_undirectedSelfLoopCount`,0),k(this,`_edgeKeyGenerator`,()=>{let e;do e=n+ r++;while(this._edges.has(e));return e}),k(this,`_options`,e),St.forEach(e=>k(this,e,this[e])),A(this,`order`,()=>this._nodes.size),A(this,`size`,()=>this._edges.size),A(this,`directedSize`,()=>this._directedSize),A(this,`undirectedSize`,()=>this._undirectedSize),A(this,`selfLoopCount`,()=>this._directedSelfLoopCount+this._undirectedSelfLoopCount),A(this,`directedSelfLoopCount`,()=>this._directedSelfLoopCount),A(this,`undirectedSelfLoopCount`,()=>this._undirectedSelfLoopCount),A(this,`multi`,this._options.multi),A(this,`type`,this._options.type),A(this,`allowSelfLoops`,this._options.allowSelfLoops),A(this,`implementation`,()=>`graphology`)}_resetInstanceCounters(){this._directedSize=0,this._undirectedSize=0,this._directedSelfLoopCount=0,this._undirectedSelfLoopCount=0}hasNode(e){return this._nodes.has(``+e)}hasDirectedEdge(e,t){if(this.type===`undirected`)return!1;if(arguments.length===1){let t=``+e,n=this._edges.get(t);return!!n&&!n.undirected}else if(arguments.length===2){e=``+e,t=``+t;let n=this._nodes.get(e);return n?n.out.hasOwnProperty(t):!1}throw new N(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasUndirectedEdge(e,t){if(this.type===`directed`)return!1;if(arguments.length===1){let t=``+e,n=this._edges.get(t);return!!n&&n.undirected}else if(arguments.length===2){e=``+e,t=``+t;let n=this._nodes.get(e);return n?n.undirected.hasOwnProperty(t):!1}throw new N(`Graph.hasDirectedEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}hasEdge(e,t){if(arguments.length===1){let t=``+e;return this._edges.has(t)}else if(arguments.length===2){e=``+e,t=``+t;let n=this._nodes.get(e);return n?n.out!==void 0&&n.out.hasOwnProperty(t)||n.undirected!==void 0&&n.undirected.hasOwnProperty(t):!1}throw new N(`Graph.hasEdge: invalid arity (${arguments.length}, instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.`)}directedEdge(e,t){if(this.type===`undirected`)return;if(e=``+e,t=``+t,this.multi)throw new F(`Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.`);let n=this._nodes.get(e);if(!n)throw new P(`Graph.directedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.directedEdge: could not find the "${t}" target node in the graph.`);let r=n.out&&n.out[t]||void 0;if(r)return r.key}undirectedEdge(e,t){if(this.type===`directed`)return;if(e=``+e,t=``+t,this.multi)throw new F(`Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.`);let n=this._nodes.get(e);if(!n)throw new P(`Graph.undirectedEdge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.undirectedEdge: could not find the "${t}" target node in the graph.`);let r=n.undirected&&n.undirected[t]||void 0;if(r)return r.key}edge(e,t){if(this.multi)throw new F(`Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.`);e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.edge: could not find the "${e}" source node in the graph.`);if(!this._nodes.has(t))throw new P(`Graph.edge: could not find the "${t}" target node in the graph.`);let r=n.out&&n.out[t]||n.undirected&&n.undirected[t]||void 0;if(r)return r.key}areDirectedNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areDirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type===`undirected`?!1:t in n.in||t in n.out}areOutNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areOutNeighbors: could not find the "${e}" node in the graph.`);return this.type===`undirected`?!1:t in n.out}areInNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areInNeighbors: could not find the "${e}" node in the graph.`);return this.type===`undirected`?!1:t in n.in}areUndirectedNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areUndirectedNeighbors: could not find the "${e}" node in the graph.`);return this.type===`directed`?!1:t in n.undirected}areNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areNeighbors: could not find the "${e}" node in the graph.`);return this.type!==`undirected`&&(t in n.in||t in n.out)||this.type!==`directed`&&t in n.undirected}areInboundNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areInboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!==`undirected`&&t in n.in||this.type!==`directed`&&t in n.undirected}areOutboundNeighbors(e,t){e=``+e,t=``+t;let n=this._nodes.get(e);if(!n)throw new P(`Graph.areOutboundNeighbors: could not find the "${e}" node in the graph.`);return this.type!==`undirected`&&t in n.out||this.type!==`directed`&&t in n.undirected}inDegree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.inDegree: could not find the "${e}" node in the graph.`);return this.type===`undirected`?0:t.inDegree}outDegree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.outDegree: could not find the "${e}" node in the graph.`);return this.type===`undirected`?0:t.outDegree}directedDegree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.directedDegree: could not find the "${e}" node in the graph.`);return this.type===`undirected`?0:t.inDegree+t.outDegree}undirectedDegree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.undirectedDegree: could not find the "${e}" node in the graph.`);return this.type===`directed`?0:t.undirectedDegree}inboundDegree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.inboundDegree: could not find the "${e}" node in the graph.`);let n=0;return this.type!==`directed`&&(n+=t.undirectedDegree),this.type!==`undirected`&&(n+=t.inDegree),n}outboundDegree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.outboundDegree: could not find the "${e}" node in the graph.`);let n=0;return this.type!==`directed`&&(n+=t.undirectedDegree),this.type!==`undirected`&&(n+=t.outDegree),n}degree(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.degree: could not find the "${e}" node in the graph.`);let n=0;return this.type!==`directed`&&(n+=t.undirectedDegree),this.type!==`undirected`&&(n+=t.inDegree+t.outDegree),n}inDegreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.inDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type===`undirected`?0:t.inDegree-t.directedLoops}outDegreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.outDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type===`undirected`?0:t.outDegree-t.directedLoops}directedDegreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.directedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type===`undirected`?0:t.inDegree+t.outDegree-t.directedLoops*2}undirectedDegreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.undirectedDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);return this.type===`directed`?0:t.undirectedDegree-t.undirectedLoops*2}inboundDegreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.inboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,r=0;return this.type!==`directed`&&(n+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!==`undirected`&&(n+=t.inDegree,r+=t.directedLoops),n-r}outboundDegreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.outboundDegreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,r=0;return this.type!==`directed`&&(n+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!==`undirected`&&(n+=t.outDegree,r+=t.directedLoops),n-r}degreeWithoutSelfLoops(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.degreeWithoutSelfLoops: could not find the "${e}" node in the graph.`);let n=0,r=0;return this.type!==`directed`&&(n+=t.undirectedDegree,r+=t.undirectedLoops*2),this.type!==`undirected`&&(n+=t.inDegree+t.outDegree,r+=t.directedLoops*2),n-r}source(e){e=``+e;let t=this._edges.get(e);if(!t)throw new P(`Graph.source: could not find the "${e}" edge in the graph.`);return t.source.key}target(e){e=``+e;let t=this._edges.get(e);if(!t)throw new P(`Graph.target: could not find the "${e}" edge in the graph.`);return t.target.key}extremities(e){e=``+e;let t=this._edges.get(e);if(!t)throw new P(`Graph.extremities: could not find the "${e}" edge in the graph.`);return[t.source.key,t.target.key]}opposite(e,t){e=``+e,t=``+t;let n=this._edges.get(t);if(!n)throw new P(`Graph.opposite: could not find the "${t}" edge in the graph.`);let r=n.source.key,i=n.target.key;if(e===r)return i;if(e===i)return r;throw new P(`Graph.opposite: the "${e}" node is not attached to the "${t}" edge (${r}, ${i}).`)}hasExtremity(e,t){e=``+e,t=``+t;let n=this._edges.get(e);if(!n)throw new P(`Graph.hasExtremity: could not find the "${e}" edge in the graph.`);return n.source.key===t||n.target.key===t}isUndirected(e){e=``+e;let t=this._edges.get(e);if(!t)throw new P(`Graph.isUndirected: could not find the "${e}" edge in the graph.`);return t.undirected}isDirected(e){e=``+e;let t=this._edges.get(e);if(!t)throw new P(`Graph.isDirected: could not find the "${e}" edge in the graph.`);return!t.undirected}isSelfLoop(e){e=``+e;let t=this._edges.get(e);if(!t)throw new P(`Graph.isSelfLoop: could not find the "${e}" edge in the graph.`);return t.source===t.target}addNode(e,t){return Tt(this,e,t).key}mergeNode(e,t){if(t&&!O(t))throw new N(`Graph.mergeNode: invalid attributes. Expecting an object but got "${t}"`);e=``+e,t||={};let n=this._nodes.get(e);return n?(t&&(E(n.attributes,t),this.emit(`nodeAttributesUpdated`,{type:`merge`,key:e,attributes:n.attributes,data:t})),[e,!1]):(n=new this.NodeDataClass(e,t),this._nodes.set(e,n),this.emit(`nodeAdded`,{key:e,attributes:t}),[e,!0])}updateNode(e,t){if(t&&typeof t!=`function`)throw new N(`Graph.updateNode: invalid updater function. Expecting a function but got "${t}"`);e=``+e;let n=this._nodes.get(e);if(n){if(t){let r=n.attributes;n.attributes=t(r),this.emit(`nodeAttributesUpdated`,{type:`replace`,key:e,attributes:n.attributes})}return[e,!1]}let r=t?t({}):{};return n=new this.NodeDataClass(e,r),this._nodes.set(e,n),this.emit(`nodeAdded`,{key:e,attributes:r}),[e,!0]}dropNode(e){e=``+e;let t=this._nodes.get(e);if(!t)throw new P(`Graph.dropNode: could not find the "${e}" node in the graph.`);let n;if(this.type!==`undirected`){for(let e in t.out){n=t.out[e];do W(this,n),n=n.next;while(n)}for(let e in t.in){n=t.in[e];do W(this,n),n=n.next;while(n)}}if(this.type!==`directed`)for(let e in t.undirected){n=t.undirected[e];do W(this,n),n=n.next;while(n)}this._nodes.delete(e),this.emit(`nodeDropped`,{key:e,attributes:t.attributes})}dropEdge(e){let t;if(arguments.length>1){let e=``+arguments[0],n=``+arguments[1];if(t=D(this,e,n,this.type),!t)throw new P(`Graph.dropEdge: could not find the "${e}" -> "${n}" edge in the graph.`)}else if(e=``+e,t=this._edges.get(e),!t)throw new P(`Graph.dropEdge: could not find the "${e}" edge in the graph.`);return W(this,t),this}dropDirectedEdge(e,t){if(arguments.length<2)throw new F(`Graph.dropDirectedEdge: it does not make sense to try and drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.`);if(this.multi)throw new F(`Graph.dropDirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.`);e=``+e,t=``+t;let n=D(this,e,t,`directed`);if(!n)throw new P(`Graph.dropDirectedEdge: could not find a "${e}" -> "${t}" edge in the graph.`);return W(this,n),this}dropUndirectedEdge(e,t){if(arguments.length<2)throw new F(`Graph.dropUndirectedEdge: it does not make sense to drop a directed edge by key. What if the edge with this key is undirected? Use #.dropEdge for this purpose instead.`);if(this.multi)throw new F(`Graph.dropUndirectedEdge: cannot use a {source,target} combo when dropping an edge in a MultiGraph since we cannot infer the one you want to delete as there could be multiple ones.`);let n=D(this,e,t,`undirected`);if(!n)throw new P(`Graph.dropUndirectedEdge: could not find a "${e}" -> "${t}" edge in the graph.`);return W(this,n),this}clear(){this._edges.clear(),this._nodes.clear(),this._resetInstanceCounters(),this.emit(`cleared`)}clearEdges(){let e=this._nodes.values(),t;for(;t=e.next(),t.done!==!0;)t.value.clear();this._edges.clear(),this._resetInstanceCounters(),this.emit(`edgesCleared`)}getAttribute(e){return this._attributes[e]}getAttributes(){return this._attributes}hasAttribute(e){return this._attributes.hasOwnProperty(e)}setAttribute(e,t){return this._attributes[e]=t,this.emit(`attributesUpdated`,{type:`set`,attributes:this._attributes,name:e}),this}updateAttribute(e,t){if(typeof t!=`function`)throw new N(`Graph.updateAttribute: updater should be a function.`);let n=this._attributes[e];return this._attributes[e]=t(n),this.emit(`attributesUpdated`,{type:`set`,attributes:this._attributes,name:e}),this}removeAttribute(e){return delete this._attributes[e],this.emit(`attributesUpdated`,{type:`remove`,attributes:this._attributes,name:e}),this}replaceAttributes(e){if(!O(e))throw new N(`Graph.replaceAttributes: provided attributes are not a plain object.`);return this._attributes=e,this.emit(`attributesUpdated`,{type:`replace`,attributes:this._attributes}),this}mergeAttributes(e){if(!O(e))throw new N(`Graph.mergeAttributes: provided attributes are not a plain object.`);return E(this._attributes,e),this.emit(`attributesUpdated`,{type:`merge`,attributes:this._attributes,data:e}),this}updateAttributes(e){if(typeof e!=`function`)throw new N(`Graph.updateAttributes: provided updater is not a function.`);return this._attributes=e(this._attributes),this.emit(`attributesUpdated`,{type:`update`,attributes:this._attributes}),this}updateEachNodeAttributes(e,t){if(typeof e!=`function`)throw new N(`Graph.updateEachNodeAttributes: expecting an updater function.`);if(t&&!me(t))throw new N(`Graph.updateEachNodeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}`);let n=this._nodes.values(),r,i;for(;r=n.next(),r.done!==!0;)i=r.value,i.attributes=e(i.key,i.attributes);this.emit(`eachNodeAttributesUpdated`,{hints:t||null})}updateEachEdgeAttributes(e,t){if(typeof e!=`function`)throw new N(`Graph.updateEachEdgeAttributes: expecting an updater function.`);if(t&&!me(t))throw new N(`Graph.updateEachEdgeAttributes: invalid hints. Expecting an object having the following shape: {attributes?: [string]}`);let n=this._edges.values(),r,i,a,o;for(;r=n.next(),r.done!==!0;)i=r.value,a=i.source,o=i.target,i.attributes=e(i.key,i.attributes,a.key,o.key,a.attributes,o.attributes,i.undirected);this.emit(`eachEdgeAttributesUpdated`,{hints:t||null})}forEachAdjacencyEntry(e){if(typeof e!=`function`)throw new N(`Graph.forEachAdjacencyEntry: expecting a callback.`);U(!1,!1,!1,this,e)}forEachAdjacencyEntryWithOrphans(e){if(typeof e!=`function`)throw new N(`Graph.forEachAdjacencyEntryWithOrphans: expecting a callback.`);U(!1,!1,!0,this,e)}forEachAssymetricAdjacencyEntry(e){if(typeof e!=`function`)throw new N(`Graph.forEachAssymetricAdjacencyEntry: expecting a callback.`);U(!1,!0,!1,this,e)}forEachAssymetricAdjacencyEntryWithOrphans(e){if(typeof e!=`function`)throw new N(`Graph.forEachAssymetricAdjacencyEntryWithOrphans: expecting a callback.`);U(!1,!0,!0,this,e)}nodes(){return Array.from(this._nodes.keys())}forEachNode(e){if(typeof e!=`function`)throw new N(`Graph.forEachNode: expecting a callback.`);let t=this._nodes.values(),n,r;for(;n=t.next(),n.done!==!0;)r=n.value,e(r.key,r.attributes)}findNode(e){if(typeof e!=`function`)throw new N(`Graph.findNode: expecting a callback.`);let t=this._nodes.values(),n,r;for(;n=t.next(),n.done!==!0;)if(r=n.value,e(r.key,r.attributes))return r.key}mapNodes(e){if(typeof e!=`function`)throw new N(`Graph.mapNode: expecting a callback.`);let t=this._nodes.values(),n,r,i=Array(this.order),a=0;for(;n=t.next(),n.done!==!0;)r=n.value,i[a++]=e(r.key,r.attributes);return i}someNode(e){if(typeof e!=`function`)throw new N(`Graph.someNode: expecting a callback.`);let t=this._nodes.values(),n,r;for(;n=t.next(),n.done!==!0;)if(r=n.value,e(r.key,r.attributes))return!0;return!1}everyNode(e){if(typeof e!=`function`)throw new N(`Graph.everyNode: expecting a callback.`);let t=this._nodes.values(),n,r;for(;n=t.next(),n.done!==!0;)if(r=n.value,!e(r.key,r.attributes))return!1;return!0}filterNodes(e){if(typeof e!=`function`)throw new N(`Graph.filterNodes: expecting a callback.`);let t=this._nodes.values(),n,r,i=[];for(;n=t.next(),n.done!==!0;)r=n.value,e(r.key,r.attributes)&&i.push(r.key);return i}reduceNodes(e,t){if(typeof e!=`function`)throw new N(`Graph.reduceNodes: expecting a callback.`);if(arguments.length<2)throw new N(`Graph.reduceNodes: missing initial value. You must provide it because the callback takes more than one argument and we cannot infer the initial value from the first iteration, as you could with a simple array.`);let n=t,r=this._nodes.values(),i,a;for(;i=r.next(),i.done!==!0;)a=i.value,n=e(n,a.key,a.attributes);return n}nodeEntries(){let e=this._nodes.values();return{[Symbol.iterator](){return this},next(){let t=e.next();if(t.done)return t;let n=t.value;return{value:{node:n.key,attributes:n.attributes},done:!1}}}}export(){let e=Array(this._nodes.size),t=0;this._nodes.forEach((n,r)=>{e[t++]=gt(r,n)});let n=Array(this._edges.size);return t=0,this._edges.forEach((e,r)=>{n[t++]=_t(this.type,r,e)}),{options:{type:this.type,multi:this.multi,allowSelfLoops:this.allowSelfLoops},attributes:this.getAttributes(),nodes:e,edges:n}}import(t,n=!1){if(t instanceof e)return t.forEachNode((e,t)=>{n?this.mergeNode(e,t):this.addNode(e,t)}),t.forEachEdge((e,t,r,i,a,o,s)=>{n?s?this.mergeUndirectedEdgeWithKey(e,r,i,t):this.mergeDirectedEdgeWithKey(e,r,i,t):s?this.addUndirectedEdgeWithKey(e,r,i,t):this.addDirectedEdgeWithKey(e,r,i,t)}),this;if(!O(t))throw new N(`Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.`);if(t.attributes){if(!O(t.attributes))throw new N(`Graph.import: invalid attributes. Expecting a plain object.`);n?this.mergeAttributes(t.attributes):this.replaceAttributes(t.attributes)}let r,i,a,o,s;if(t.nodes){if(a=t.nodes,!Array.isArray(a))throw new N(`Graph.import: invalid nodes. Expecting an array.`);for(r=0,i=a.length;r<i;r++){o=a[r],vt(o);let{key:e,attributes:t}=o;n?this.mergeNode(e,t):this.addNode(e,t)}}if(t.edges){let e=!1;if(this.type===`undirected`&&(e=!0),a=t.edges,!Array.isArray(a))throw new N(`Graph.import: invalid edges. Expecting an array.`);for(r=0,i=a.length;r<i;r++){s=a[r],yt(s);let{source:t,target:i,attributes:o,undirected:c=e}=s,l;`key`in s?(l=n?c?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:c?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,l.call(this,s.key,t,i,o)):(l=n?c?this.mergeUndirectedEdge:this.mergeDirectedEdge:c?this.addUndirectedEdge:this.addDirectedEdge,l.call(this,t,i,o))}}return this}nullCopy(t){let n=new e(E({},this._options,t));return n.replaceAttributes(E({},this.getAttributes())),n}emptyCopy(e){let t=this.nullCopy(e);return this._nodes.forEach((e,n)=>{let r=E({},e.attributes);e=new t.NodeDataClass(n,r),t._nodes.set(n,e)}),t}copy(e){if(e||={},typeof e.type==`string`&&e.type!==this.type&&e.type!==`mixed`)throw new F(`Graph.copy: cannot create an incompatible copy from "${this.type}" type to "${e.type}" because this would mean losing information about the current graph.`);if(typeof e.multi==`boolean`&&e.multi!==this.multi&&e.multi!==!0)throw new F(`Graph.copy: cannot create an incompatible copy by downgrading a multi graph to a simple one because this would mean losing information about the current graph.`);if(typeof e.allowSelfLoops==`boolean`&&e.allowSelfLoops!==this.allowSelfLoops&&e.allowSelfLoops!==!0)throw new F(`Graph.copy: cannot create an incompatible copy from a graph allowing self loops to one that does not because this would mean losing information about the current graph.`);let t=this.emptyCopy(e),n=this._edges.values(),r,i;for(;r=n.next(),r.done!==!0;)i=r.value,Dt(t,`copy`,!1,i.undirected,i.key,i.source.key,i.target.key,E({},i.attributes));return t}toJSON(){return this.export()}toString(){return`[object Graph]`}inspect(){let e={};this._nodes.forEach((t,n)=>{e[n]=t.attributes});let t={},n={};this._edges.forEach((e,r)=>{let i=e.undirected?`--`:`->`,a=``,o=e.source.key,s=e.target.key,c;e.undirected&&o>s&&(c=o,o=s,s=c);let l=`(${o})${i}(${s})`;r.startsWith(`geid_`)?this.multi&&(n[l]===void 0?n[l]=0:n[l]++,a+=`${n[l]}. `):a+=`[${r}]: `,a+=l,t[a]=e.attributes});let r={};for(let e in this)this.hasOwnProperty(e)&&!St.has(e)&&typeof this[e]!=`function`&&typeof e!=`symbol`&&(r[e]=this[e]);return r.attributes=this._attributes,r.nodes=e,r.edges=t,k(r,`constructor`,this.constructor),r}};typeof Symbol<`u`&&(G.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=G.prototype.inspect),Ct.forEach(e=>{[`add`,`merge`,`update`].forEach(t=>{let n=e.name(t),r=t===`add`?Dt:Ot;e.generateKey?G.prototype[n]=function(i,a,o){return r(this,n,!0,(e.type||this.type)===`undirected`,null,i,a,o,t===`update`)}:G.prototype[n]=function(i,a,o,s){return r(this,n,!1,(e.type||this.type)===`undirected`,i,a,o,s,t===`update`)}})}),Ae(G),Ve(G),ot(G),ht(G);var K=class extends G{constructor(e){let t=E({type:`directed`},e);if(`multi`in t&&t.multi!==!1)throw new N(`DirectedGraph.from: inconsistent indication that the graph should be multi in given options!`);if(t.type!==`directed`)throw new N(`DirectedGraph.from: inconsistent "`+t.type+`" type in given options!`);super(t)}},kt=class extends G{constructor(e){let t=E({type:`undirected`},e);if(`multi`in t&&t.multi!==!1)throw new N(`UndirectedGraph.from: inconsistent indication that the graph should be multi in given options!`);if(t.type!==`undirected`)throw new N(`UndirectedGraph.from: inconsistent "`+t.type+`" type in given options!`);super(t)}},At=class extends G{constructor(e){let t=E({multi:!0},e);if(`multi`in t&&t.multi!==!0)throw new N(`MultiGraph.from: inconsistent indication that the graph should be simple in given options!`);super(t)}},jt=class extends G{constructor(e){let t=E({type:`directed`,multi:!0},e);if(`multi`in t&&t.multi!==!0)throw new N(`MultiDirectedGraph.from: inconsistent indication that the graph should be simple in given options!`);if(t.type!==`directed`)throw new N(`MultiDirectedGraph.from: inconsistent "`+t.type+`" type in given options!`);super(t)}},Mt=class extends G{constructor(e){let t=E({type:`undirected`,multi:!0},e);if(`multi`in t&&t.multi!==!0)throw new N(`MultiUndirectedGraph.from: inconsistent indication that the graph should be simple in given options!`);if(t.type!==`undirected`)throw new N(`MultiUndirectedGraph.from: inconsistent "`+t.type+`" type in given options!`);super(t)}};function q(e){e.from=function(t,n){let r=new e(E({},t.options,n));return r.import(t),r}}q(G),q(K),q(kt),q(At),q(jt),q(Mt),G.Graph=G,G.DirectedGraph=K,G.UndirectedGraph=kt,G.MultiGraph=At,G.MultiDirectedGraph=jt,G.MultiUndirectedGraph=Mt,G.InvalidArgumentsGraphError=N,G.NotFoundGraphError=P,G.UsageGraphError=F;var Nt=t(((e,t)=>{t.exports=function(e){return typeof e==`object`&&!!e&&typeof e.addUndirectedEdgeWithKey==`function`&&typeof e.dropNode==`function`&&typeof e.multi==`boolean`}})),Pt=t(((e,t)=>{let n=Nt();t.exports=function(e){if(!n(e))throw Error(`graphology-dag/has-cycle: the given graph is not a valid graphology instance.`);if(e.size===0)return!1;if(e.selfLoopCount!==0)return!0;let t={},r=[];function i(e){let n=t[e];if(n===void 0)r.push(e);else if(n===0)return!0;return!1}return e.someNode(n=>{if(t[n]===1)return!1;for(r.push(n);r.length!==0;){let n=r[r.length-1],a=t[n];if(a!==0){if(t[n]=0,e.someOutboundNeighbor(n,i))return!0}else a===0&&(r.pop(),t[n]=1)}return!1})}})),Ft=t(((e,t)=>{let n=Nt();t.exports=function(e,t,r){if(!n(e))throw Error(`graphology-dag/will-create-cycle: the given graph is not a valid graphology instance.`);if(t=``+t,r=``+r,t===r)return!0;if(!e.hasNode(t)||!e.hasNode(r)||e.hasDirectedEdge(t,r))return!1;if(e.hasDirectedEdge(r,t))return!0;let i=e.outNeighbors(r);function a(e){i.push(e)}for(;i.length!==0;){let n=i.pop();if(n===t)return!0;e.forEachOutNeighbor(n,a)}return!1}})),It=t((e=>{e.ARRAY_BUFFER_SUPPORT=typeof ArrayBuffer<`u`,e.SYMBOL_SUPPORT=typeof Symbol<`u`})),Lt=t(((e,t)=>{var n=It(),r=n.ARRAY_BUFFER_SUPPORT,i=n.SYMBOL_SUPPORT;t.exports=function(e,t){var n,a,o,s,c;if(!e)throw Error(`obliterator/forEach: invalid iterable.`);if(typeof t!=`function`)throw Error(`obliterator/forEach: expecting a callback.`);if(Array.isArray(e)||r&&ArrayBuffer.isView(e)||typeof e==`string`||e.toString()===`[object Arguments]`){for(o=0,s=e.length;o<s;o++)t(e[o],o);return}if(typeof e.forEach==`function`){e.forEach(t);return}if(i&&Symbol.iterator in e&&typeof e.next!=`function`&&(e=e[Symbol.iterator]()),typeof e.next==`function`){for(n=e,o=0;c=n.next(),c.done!==!0;)t(c.value,o),o++;return}for(a in e)e.hasOwnProperty(a)&&t(e[a],a)}})),Rt=t((e=>{var t=2**8-1,n=2**16-1,r=2**32-1,i=2**7-1,a=2**15-1,o=2**31-1;e.getPointerArray=function(e){var i=e-1;if(i<=t)return Uint8Array;if(i<=n)return Uint16Array;if(i<=r)return Uint32Array;throw Error(`mnemonist: Pointer Array of size > 4294967295 is not supported.`)},e.getSignedPointerArray=function(e){var t=e-1;return t<=i?Int8Array:t<=a?Int16Array:t<=o?Int32Array:Float64Array},e.getNumberType=function(e){return e===(e|0)?Math.sign(e)===-1?e<=127&&e>=-128?Int8Array:e<=32767&&e>=-32768?Int16Array:Int32Array:e<=255?Uint8Array:e<=65535?Uint16Array:Uint32Array:Float64Array};var s={Uint8Array:1,Int8Array:2,Uint16Array:3,Int16Array:4,Uint32Array:5,Int32Array:6,Float32Array:7,Float64Array:8};e.getMinimalRepresentation=function(t,n){var r=null,i=0,a,o,c,l,u;for(l=0,u=t.length;l<u;l++)c=n?n(t[l]):t[l],o=e.getNumberType(c),a=s[o.name],a>i&&(i=a,r=o);return r},e.isTypedArray=function(e){return typeof ArrayBuffer<`u`&&ArrayBuffer.isView(e)},e.concat=function(){var e=0,t,n,r;for(t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var i=new arguments[0].constructor(e);for(t=0,n=0;t<r;t++)i.set(arguments[t],n),n+=arguments[t].length;return i},e.indices=function(t){for(var n=new(e.getPointerArray(t))(t),r=0;r<t;r++)n[r]=r;return n}})),zt=t((e=>{var t=Lt(),n=Rt();function r(e){return Array.isArray(e)||n.isTypedArray(e)}function i(e){if(typeof e.length==`number`)return e.length;if(typeof e.size==`number`)return e.size}function a(e){var n=i(e),r=typeof n==`number`?Array(n):[],a=0;return t(e,function(e){r[a++]=e}),r}function o(e){var r=i(e),a=typeof r==`number`?n.getPointerArray(r):Array,o=typeof r==`number`?Array(r):[],s=typeof r==`number`?new a(r):[],c=0;return t(e,function(e){o[c]=e,s[c]=c++}),[o,s]}e.isArrayLike=r,e.guessLength=i,e.toArray=a,e.toArrayWithIndices=o})),Bt=t(((e,t)=>{function n(e){if(typeof e!=`function`)throw Error(`obliterator/iterator: expecting a function!`);this.next=e}typeof Symbol<`u`&&(n.prototype[Symbol.iterator]=function(){return this}),n.of=function(){var e=arguments,t=e.length,r=0;return new n(function(){return r>=t?{done:!0}:{done:!1,value:e[r++]}})},n.empty=function(){return new n(function(){return{done:!0}})},n.fromSequence=function(e){var t=0,r=e.length;return new n(function(){return t>=r?{done:!0}:{done:!1,value:e[t++]}})},n.is=function(e){return e instanceof n?!0:typeof e==`object`&&!!e&&typeof e.next==`function`},t.exports=n})),Vt=t(((e,t)=>{var n=zt(),r=Bt();function i(e,t){if(arguments.length<2)throw Error(`mnemonist/fixed-deque: expecting an Array class and a capacity.`);if(typeof t!=`number`||t<=0)throw Error("mnemonist/fixed-deque: `capacity` should be a positive number.");this.ArrayClass=e,this.capacity=t,this.items=new e(this.capacity),this.clear()}i.prototype.clear=function(){this.start=0,this.size=0},i.prototype.push=function(e){if(this.size===this.capacity)throw Error(`mnemonist/fixed-deque.push: deque capacity (`+this.capacity+`) exceeded!`);var t=this.start+this.size;return t>=this.capacity&&(t-=this.capacity),this.items[t]=e,++this.size},i.prototype.unshift=function(e){if(this.size===this.capacity)throw Error(`mnemonist/fixed-deque.unshift: deque capacity (`+this.capacity+`) exceeded!`);var t=this.start-1;return this.start===0&&(t=this.capacity-1),this.items[t]=e,this.start=t,++this.size},i.prototype.pop=function(){if(this.size!==0){this.size--;var e=this.start+this.size;return e>=this.capacity&&(e-=this.capacity),this.items[e]}},i.prototype.shift=function(){if(this.size!==0){var e=this.start;return this.size--,this.start++,this.start===this.capacity&&(this.start=0),this.items[e]}},i.prototype.peekFirst=function(){if(this.size!==0)return this.items[this.start]},i.prototype.peekLast=function(){if(this.size!==0){var e=this.start+this.size-1;return e>=this.capacity&&(e-=this.capacity),this.items[e]}},i.prototype.get=function(e){if(!(this.size===0||e>=this.capacity))return e=this.start+e,e>=this.capacity&&(e-=this.capacity),this.items[e]},i.prototype.forEach=function(e,t){t=arguments.length>1?t:this;for(var n=this.capacity,r=this.size,i=this.start,a=0;a<r;)e.call(t,this.items[i],a,this),i++,a++,i===n&&(i=0)},i.prototype.toArray=function(){var e=this.start+this.size;if(e<this.capacity)return this.items.slice(this.start,e);for(var t=new this.ArrayClass(this.size),n=this.capacity,r=this.size,i=this.start,a=0;a<r;)t[a]=this.items[i],i++,a++,i===n&&(i=0);return t},i.prototype.values=function(){var e=this.items,t=this.capacity,n=this.size,i=this.start,a=0;return new r(function(){if(a>=n)return{done:!0};var r=e[i];return i++,a++,i===t&&(i=0),{value:r,done:!1}})},i.prototype.entries=function(){var e=this.items,t=this.capacity,n=this.size,i=this.start,a=0;return new r(function(){if(a>=n)return{done:!0};var r=e[i];return i++,i===t&&(i=0),{value:[a++,r],done:!1}})},typeof Symbol<`u`&&(i.prototype[Symbol.iterator]=i.prototype.values),i.prototype.inspect=function(){var e=this.toArray();return e.type=this.ArrayClass.name,e.capacity=this.capacity,Object.defineProperty(e,`constructor`,{value:i,enumerable:!1}),e},typeof Symbol<`u`&&(i.prototype[Symbol.for(`nodejs.util.inspect.custom`)]=i.prototype.inspect),i.from=function(e,t,r){if(arguments.length<3&&(r=n.guessLength(e),typeof r!=`number`))throw Error(`mnemonist/fixed-deque.from: could not guess iterable length. Please provide desired capacity as last argument.`);var a=new i(t,r);if(n.isArrayLike(e)){var o,s;for(o=0,s=e.length;o<s;o++)a.items[o]=e[o];return a.size=s,a}return n.forEach(e,function(e){a.push(e)}),a},t.exports=i})),Ht=t((e=>{let t=Nt(),n=Vt();function r(e,t){let n=0;return e.forEachInNeighbor(t,()=>{n++}),n}function i(e,i){if(!t(e))throw Error(`graphology-dag/topological-sort: the given graph is not a valid graphology instance.`);if(e.type===`undirected`||e.undirectedSize!==0)throw Error(`graphology-dag/topological-sort: cannot work if graph is not directed.`);if(e.order===0)return;let a=new n(Array,e.order),o={},s=0;e.forEachNode((t,n)=>{let i=e.multi?r(e,t):e.inDegree(t);i===0?a.push([t,n,0]):(o[t]=i,s+=i)});let c=0;function l(e,t){let n=--o[e];s--,n===0&&a.push([e,t,c+1]),o[e]=n}for(;a.size!==0;){let[t,n,r]=a.shift();c=r,i(t,n,r),e.forEachOutNeighbor(t,l)}if(s!==0)throw Error(`graphology-dag/topological-sort: given graph is not acyclic.`)}function a(e){if(!t(e))throw Error(`graphology-dag/topological-sort: the given graph is not a valid graphology instance.`);let n=Array(e.order),r=0;return i(e,e=>{n[r++]=e}),n}function o(e,n){if(!t(e))throw Error(`graphology-dag/topological-generations: the given graph is not a valid graphology instance.`);if(e.order===0)return;let r=0,a=[];i(e,(e,t,i)=>{i>r&&(n(a),r=i,a=[]),a.push(e)}),n(a)}function s(e){if(!t(e))throw Error(`graphology-dag/topological-generations: the given graph is not a valid graphology instance.`);let n=[];return o(e,e=>{n.push(e)}),n}e.topologicalSort=a,e.forEachNodeInTopologicalOrder=i,e.topologicalGenerations=s,e.forEachTopologicalGeneration=o})),Ut=t((e=>{e.hasCycle=Pt(),e.willCreateCycle=Ft();let t=Ht();e.forEachNodeInTopologicalOrder=t.forEachNodeInTopologicalOrder,e.topologicalSort=t.topologicalSort,e.topologicalGenerations=t.topologicalGenerations,e.forEachTopologicalGeneration=t.forEachTopologicalGeneration}))();function Wt(e){let t=e.metadata;if(!t||!t.dbt_schema_version)return null;let n=t.dbt_schema_version.match(/\/manifest\/v(\d+)\.json$/);return n?parseInt(n[1],10):null}function Gt(e){return e.metadata?.dbt_version||null}function Kt(e){let t=Wt(e);return t===null?!1:t>=10}function qt(e){return{schema_version:Wt(e),dbt_version:Gt(e),is_supported:Kt(e)}}function Jt(e){return e.metrics}function Yt(e){return e.semantic_models}function Xt(e){return e.unit_tests}var Zt=class{constructor(e){if(this.relationMap=new Map,!Kt(e)){let t=qt(e);throw Error(`Unsupported dbt version. Schema version: ${t.schema_version||`unknown`}, dbt version: ${t.dbt_version||`unknown`}. Requires dbt 1.10+ (manifest schema v10+)`)}this.graph=new K,this.buildGraph(e)}buildGraph(e){this.addNodes(e),this.addEdges(e)}registerRelationName(e,t){t&&this.relationMap.set(t.toLowerCase(),e)}addNodes(e){this.addNodeEntries(e.nodes),this.addSourceEntries(e.sources),this.addMacroEntries(e.macros),this.addExposureEntries(e.exposures),this.addMetricEntries(Jt(e)),this.addSemanticModelEntries(Yt(e)),this.addUnitTestEntries(Xt(e))}addNodeEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n,r=this.extractResourceType(e.resource_type||`model`),i=e.config?.materialized,a=typeof i==`string`&&i.trim()!==``?i:void 0;this.graph.addNode(t,{unique_id:t,resource_type:r,name:e.name||t,package_name:e.package_name||``,path:e.path||void 0,original_file_path:e.original_file_path||void 0,patch_path:e.patch_path||void 0,database:e.database||void 0,schema:e.schema||void 0,tags:e.tags||void 0,description:e.description||void 0,compiled_code:e.compiled_code||void 0,raw_code:e.raw_code||e.raw_sql||void 0,...a==null?{}:{materialized:a}}),this.registerRelationName(t,e.relation_name)}}addSourceEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n;this.graph.addNode(t,{unique_id:t,resource_type:`source`,name:e.name||t,package_name:e.package_name||``,path:e.path||void 0,original_file_path:e.original_file_path||void 0,tags:e.tags||void 0,description:e.description||void 0}),this.registerRelationName(t,e.relation_name)}}addMacroEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n;this.graph.addNode(t,{unique_id:t,resource_type:`macro`,name:e.name||t,package_name:e.package_name||``,path:e.path||void 0,original_file_path:e.original_file_path||void 0,description:e.description||void 0,raw_code:e.macro_sql||void 0})}}addExposureEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n;this.graph.addNode(t,{unique_id:t,resource_type:`exposure`,name:e.name||t,package_name:e.package_name||``,tags:e.tags||void 0,description:e.description||void 0})}}addMetricEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n,r=e.tags,i=Array.isArray(r)?r:typeof r==`string`?[r]:void 0;this.graph.addNode(t,{unique_id:t,resource_type:`metric`,name:e.name||t,package_name:e.package_name||``,path:e.path||void 0,original_file_path:e.original_file_path||void 0,description:e.description||void 0,label:e.label||void 0,metric_type:e.type||void 0,metric_expression:e.type_params?.expr||void 0,metric_measure:e.type_params?.measure?.name||void 0,metric_input_measures:Array.isArray(e.type_params?.input_measures)?e.type_params.input_measures.map(e=>e.name).filter(e=>typeof e==`string`):void 0,metric_input_metrics:Array.isArray(e.type_params?.metrics)?e.type_params.metrics.map(e=>e.name).filter(e=>typeof e==`string`):void 0,metric_time_granularity:e.time_granularity||void 0,metric_filters:Array.isArray(e.filter?.where_filters)?e.filter.where_filters.map(e=>e.where_sql_template).filter(e=>typeof e==`string`):void 0,metric_source_reference:e.depends_on?.nodes?.[0]||void 0,tags:i})}}addSemanticModelEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n;this.graph.addNode(t,{unique_id:t,resource_type:`semantic_model`,name:e.name||t,package_name:e.package_name||``,path:e.path||void 0,original_file_path:e.original_file_path||void 0,description:e.description||void 0,label:e.label||void 0,semantic_model_reference:e.model||void 0,semantic_model_default_time_dimension:e.defaults?.agg_time_dimension||void 0,semantic_model_entities:Array.isArray(e.entities)?e.entities.map(e=>e.name).filter(e=>typeof e==`string`):void 0,semantic_model_measures:Array.isArray(e.measures)?e.measures.map(e=>e.name).filter(e=>typeof e==`string`):void 0,semantic_model_dimensions:Array.isArray(e.dimensions)?e.dimensions.map(e=>e.name).filter(e=>typeof e==`string`):void 0})}}addUnitTestEntries(e){if(e)for(let[t,n]of Object.entries(e)){let e=n;this.graph.addNode(t,{unique_id:t,resource_type:`unit_test`,name:e.name||t,package_name:e.package_name||``})}}addEdges(e){e.parent_map&&this.addEdgesFromParentMap(e.parent_map),this.addEdgesFromNodeDependsOn(e.nodes),this.addEdgesFromExposureDependsOn(e.exposures),this.addEdgesFromMetricDependsOn(Jt(e))}addEdgesFromParentMap(e){for(let[t,n]of Object.entries(e))if(this.graph.hasNode(t))for(let e of n)this.graph.hasNode(e)&&!this.graph.hasEdge(e,t)&&this.graph.addEdge(e,t,{dependency_type:this.inferDependencyType(e)})}addEdgesFromDependsOn(e,t){if(t.nodes)for(let n of t.nodes)this.graph.hasNode(n)&&!this.graph.hasEdge(n,e)&&this.graph.addEdge(n,e,{dependency_type:`node`});if(t.macros)for(let n of t.macros)this.graph.hasNode(n)&&!this.graph.hasEdge(n,e)&&this.graph.addEdge(n,e,{dependency_type:`macro`})}addEdgesFromNodeDependsOn(e){if(e)for(let[t,n]of Object.entries(e)){let e=n.depends_on;e&&this.addEdgesFromDependsOn(t,e)}}addEdgesFromExposureDependsOn(e){if(e)for(let[t,n]of Object.entries(e)){let e=n.depends_on;e?.nodes&&this.addEdgesFromDependsOn(t,e)}}addEdgesFromMetricDependsOn(e){if(e)for(let[t,n]of Object.entries(e)){let e=n.depends_on;e?.nodes&&this.addEdgesFromDependsOn(t,e)}}extractResourceType(e){let t=e.toLowerCase();return[`model`,`source`,`seed`,`snapshot`,`test`,`analysis`,`macro`,`exposure`,`metric`,`semantic_model`,`unit_test`,`function`].includes(t)?t:`model`}inferDependencyType(e){return e.startsWith(`macro.`)?`macro`:e.startsWith(`source.`)?`source`:`node`}getGraph(){return this.graph}getSummary(){let e={},t=0;this.graph.forEachNode((n,r)=>{t++;let i=r.resource_type||`unknown`;e[i]=(e[i]||0)+1});let n=(0,Ut.hasCycle)(this.graph);return{total_nodes:t,nodes_by_type:e,total_edges:this.graph.size,has_cycles:n}}getUpstream(e,t){if(!this.graph.hasNode(e))return[];let n=[],r=new Set,i=[],a=0;for(let a of this.graph.inboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:1}),(t===void 0||1<t)&&i.push({id:a,depth:1}));for(;a<i.length;){let{id:e,depth:o}=i[a++],s=o+1;for(let a of this.graph.inboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:s}),(t===void 0||s<t)&&i.push({id:a,depth:s}))}return n}getDownstream(e,t){if(!this.graph.hasNode(e))return[];let n=[],r=new Set,i=[],a=0;for(let a of this.graph.outboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:1}),(t===void 0||1<t)&&i.push({id:a,depth:1}));for(;a<i.length;){let{id:e,depth:o}=i[a++],s=o+1;for(let a of this.graph.outboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:s}),(t===void 0||s<t)&&i.push({id:a,depth:s}))}return n}getUpstreamWithParents(e,t){if(!this.graph.hasNode(e))return[];let n=[],r=new Set,i=[];for(let a of this.graph.inboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:1,parentId:e}),(t===void 0||1<t)&&i.push({id:a,depth:1,parentId:e}));for(;i.length>0;){let{id:e,depth:a}=i.shift(),o=a+1;for(let a of this.graph.inboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:o,parentId:e}),(t===void 0||o<t)&&i.push({id:a,depth:o,parentId:e}))}return n}getUpstreamBuildOrder(e,t){let n=this.getUpstream(e,t);if(n.length===0)return[];let r=new Set(n.map(e=>e.nodeId)),i=new Map(n.map(e=>[e.nodeId,e.depth])),a=new K;for(let e of r)a.addNode(e,this.graph.getNodeAttributes(e));return this.graph.forEachEdge((e,t,n,i)=>{r.has(n)&&r.has(i)&&(a.hasEdge(n,i)||a.addEdge(n,i,t))}),(0,Ut.topologicalSort)(a).map(e=>({nodeId:e,depth:i.get(e)??0}))}getDownstreamWithParents(e,t){if(!this.graph.hasNode(e))return[];let n=[],r=new Set,i=[];for(let a of this.graph.outboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:1,parentId:e}),(t===void 0||1<t)&&i.push({id:a,depth:1,parentId:e}));for(;i.length>0;){let{id:e,depth:a}=i.shift(),o=a+1;for(let a of this.graph.outboundNeighbors(e))r.has(a)||(r.add(a),n.push({nodeId:a,depth:o,parentId:e}),(t===void 0||o<t)&&i.push({id:a,depth:o,parentId:e}))}return n}addFieldNodes(e){if(e.nodes){for(let[t,n]of Object.entries(e.nodes))if(this.graph.hasNode(t)){let e=n.columns;this.processCatalogColumns(t,e)}}if(e.sources){for(let[t,n]of Object.entries(e.sources))if(this.graph.hasNode(t)){let e=n.columns;this.processCatalogColumns(t,e)}}}processCatalogColumns(e,t){if(!t)return;let n=this.graph.getNodeAttributes(e);for(let[r,i]of Object.entries(t)){let t=`${e}#${r}`,a=i,o=a?.comment??a?.description;this.graph.hasNode(t)||(this.graph.addNode(t,{unique_id:t,resource_type:`field`,name:r,package_name:n.package_name,parent_id:e,description:o}),this.graph.addEdge(e,t,{dependency_type:`internal`}))}}addFieldEdges(e,t){if(this.graph.hasNode(e))for(let[n,r]of Object.entries(t)){let t=`${e}#${n}`;this.ensureFieldNode(e,n);for(let e of r){let n=this.resolveRelationToUniqueId(e.sourceTable);if(!n)continue;let r=`${n}#${e.sourceColumn}`;this.ensureFieldNode(n,e.sourceColumn),this.graph.hasEdge(r,t)||this.graph.addEdge(r,t,{dependency_type:`field`})}}}ensureFieldNode(e,t){let n=`${e}#${t}`;if(!this.graph.hasNode(n)){let r=this.graph.getNodeAttributes(e);this.graph.addNode(n,{unique_id:n,resource_type:`field`,name:t,package_name:r.package_name,parent_id:e}),this.graph.addEdge(e,n,{dependency_type:`internal`})}return n}resolveRelationToUniqueId(e){let t=e.toLowerCase();if(this.relationMap.has(t))return this.relationMap.get(t);let n=t.replace(/["`]/g,``);if(this.relationMap.has(n))return this.relationMap.get(n);for(let[e,t]of this.relationMap.entries()){let r=e.replace(/["`]/g,``);if(r.endsWith(`.${n}`)||r===n)return t}}},Qt=class{constructor(e,t){this.runResults=e,this.graph=t}getSummary(){let e=this.getNodeExecutions(),t={},n=0;for(let r of e){let e=r.status||`unknown`;t[e]=(t[e]||0)+1,n+=r.execution_time||0}let r=this.calculateCriticalPath(e);return{total_execution_time:n,total_nodes:e.length,nodes_by_status:t,critical_path:r,node_executions:e}}getNodeExecutions(){return!this.runResults.results||!Array.isArray(this.runResults.results)?[]:this.runResults.results.map(e=>{let t=e.timing||[],n=t.find(e=>e.name===`execute`),r=t.find(e=>e.name===`compile`),i=n||r||t[0];return{unique_id:e.unique_id||``,status:e.status||`unknown`,execution_time:e.execution_time||0,started_at:i?.started_at??void 0,completed_at:i?.completed_at??void 0,thread_id:e.thread_id??void 0}})}calculateCriticalPath(e){let t=new Map;for(let n of e)t.set(n.unique_id,n);let n=[],r=this.graph.getGraph();if(r.forEachNode(e=>{r.outboundNeighbors(e).length===0&&t.has(e)&&n.push(e)}),n.length===0)return;let i=[],a=0;for(let e of n){let n=this.findLongestPathToRoot(e,t),r=this.calculatePathTime(n,t);r>a&&(a=r,i=n)}if(i.length!==0)return{path:i,total_time:a}}findLongestPathToRoot(e,t){let n=this.graph.getGraph(),r=new Set,i=[],a=(e,o)=>{if(r.has(e))return;r.add(e);let s=[...o,e];s.length>i.length&&(i=s);let c=n.inboundNeighbors(e);for(let e of c)t.has(e)&&a(e,s);r.delete(e)};return a(e,[]),i.reverse()}calculatePathTime(e,t){let n=0;for(let r of e){let e=t.get(r);e&&(n+=e.execution_time||0)}return n}getRunStartedAt(){let e=this.getNodeExecutions().map(e=>e.started_at?new Date(e.started_at).getTime():null).filter(e=>e!==null);return e.length===0?null:Math.min(...e)}parseTimingInterval(e){if(!e)return null;let t=e.started_at,n=e.completed_at;if(!t||!n)return null;let r=new Date(t).getTime(),i=new Date(n).getTime();return Number.isNaN(r)||Number.isNaN(i)?null:{start:r,end:i}}wallClockFromResult(e){let t=e.timing||[],n=t.find(e=>e.name===`execute`),r=t.find(e=>e.name===`compile`),i=this.parseTimingInterval(r),a=this.parseTimingInterval(n),o=[],s=[];return i&&(o.push(i.start),s.push(i.end)),a&&(o.push(a.start),s.push(a.end)),o.length===0?null:{wallStart:Math.min(...o),wallEnd:Math.max(...s),compile:i,execute:a}}getGanttData(){if(!this.runResults.results||!Array.isArray(this.runResults.results))return[];let e=this.graph.getGraph(),t=[];for(let n of this.runResults.results){let r=n.unique_id||``;if(!r)continue;let i=this.wallClockFromResult(n);if(!i)continue;let a=(e.hasNode(r)?e.getNodeAttributes(r):void 0)?.name||r,o=n.status||`unknown`;t.push({unique_id:r,name:a,status:o,wall:i})}if(t.length===0)return[];let n=Math.min(...t.map(e=>e.wall.wallStart));return t.map(e=>{let{wall:t}=e,r=e=>e-n;return{unique_id:e.unique_id,name:e.name,start:r(t.wallStart),end:r(t.wallEnd),duration:t.wallEnd-t.wallStart,status:e.status,compileStart:t.compile?r(t.compile.start):null,compileEnd:t.compile?r(t.compile.end):null,executeStart:t.execute?r(t.execute.start):null,executeEnd:t.execute?r(t.execute.end):null}})}};function $t(e,t){let n=t.split(`*`);if(n.length===1)return e===t;let r=0;for(let t=0;t<n.length;t++){let i=n[t],a=e.indexOf(i,r);if(a===-1||t===0&&a!==0)return!1;r=a+i.length}return n[n.length-1]===``||e.endsWith(n[n.length-1])}function en(e,t){return t instanceof RegExp?t.test(e):$t(e,t)}function tn(e,t){let n=[...e];if(t.status!==void 0){let e=typeof t.status==`string`?[t.status]:t.status,r=new Set(e.map(e=>e.toLowerCase()));n=n.filter(e=>r.has((e.status||`unknown`).toLowerCase()))}return t.min_execution_time!==void 0&&(n=n.filter(e=>(e.execution_time??0)>=t.min_execution_time)),t.max_execution_time!==void 0&&(n=n.filter(e=>(e.execution_time??0)<=t.max_execution_time)),t.unique_id_pattern!==void 0&&(n=n.filter(e=>en(e.unique_id,t.unique_id_pattern))),t.sort&&(n=[...n].sort((e,n)=>{switch(t.sort){case`execution_time_asc`:return(e.execution_time??0)-(n.execution_time??0);case`execution_time_desc`:return(n.execution_time??0)-(e.execution_time??0);case`unique_id`:return e.unique_id.localeCompare(n.unique_id);default:return 0}})),t.limit!==void 0&&t.limit>=0&&(n=n.slice(0,t.limit)),n}function nn(e,t){if(!t)return;let n=t.getGraph();if(n.hasNode(e))return n.getNodeAttributes(e)?.name||void 0}function rn(e,t){let n=e.reduce((e,t)=>e+(t.execution_time??0),0),r;return r=t.mode===`top_n`?tn(e,{sort:`execution_time_desc`,limit:t.top}):tn(e,{min_execution_time:t.min_seconds,sort:`execution_time_desc`}),{nodes:r.map((e,r)=>{let i=e.execution_time??0,a=n>0?i/n*100:0;return{unique_id:e.unique_id,name:nn(e.unique_id,t.graph),execution_time:i,rank:r+1,pct_of_total:Math.round(a*10)/10,status:e.status||`unknown`}}),total_execution_time:n,criteria_used:t.mode===`top_n`?`top_n`:`threshold`}}let an=[`model`,`source`,`test`,`metric`,`semantic_model`,`exposure`,`seed`,`snapshot`,`unit_test`,`analysis`,`macro`];function J(){return performance.now()}function on(e){let t=e?.trim().toLowerCase();return t?[`success`,`pass`,`passed`].includes(t)?`positive`:[`warn`,`warning`].includes(t)?`warning`:[`error`,`fail`,`failed`,`run error`].includes(t)?`danger`:`neutral`:`neutral`}function Y(e){return e?e.split(/[\s_-]+/).filter(Boolean).map(e=>e[0].toUpperCase()+e.slice(1).toLowerCase()).join(` `):`Unknown`}function sn(e){let t=e.split(`.`);return t.length<2?``:t[1]??``}function cn(e){let t=e.split(`.`)[0]??``;return new Set([`model`,`test`,`unit_test`,`seed`,`snapshot`,`source`,`source_freshness`,`exposure`,`metric`,`semantic_model`,`analysis`,`macro`]).has(t)?t:`operation`}function ln(e){return e.split(`_`).map(e=>e[0].toUpperCase()+e.slice(1)).join(` `)}function X(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function un(e){let t=typeof e.metric_measure==`string`?e.metric_measure:null,n=X(e.metric_input_measures);return{kind:`metric`,label:typeof e.label==`string`?e.label:null,description:typeof e.description==`string`?e.description:null,metricType:typeof e.metric_type==`string`?e.metric_type:null,expression:typeof e.metric_expression==`string`?e.metric_expression:null,sourceReference:typeof e.metric_source_reference==`string`?e.metric_source_reference:typeof e.metric_measure==`string`?e.metric_measure:null,filters:X(e.metric_filters),timeGranularity:typeof e.metric_time_granularity==`string`?e.metric_time_granularity:null,measures:n.length>0?n:t==null?[]:[t],metrics:X(e.metric_input_metrics)}}function dn(e){return{kind:`semantic_model`,label:typeof e.label==`string`?e.label:null,description:typeof e.description==`string`?e.description:null,sourceReference:typeof e.semantic_model_reference==`string`?e.semantic_model_reference:null,defaultTimeDimension:typeof e.semantic_model_default_time_dimension==`string`?e.semantic_model_default_time_dimension:null,entities:X(e.semantic_model_entities),measures:X(e.semantic_model_measures),dimensions:X(e.semantic_model_dimensions)}}function fn(e,t){return e===`metric`?un(t):e===`semantic_model`?dn(t):null}function pn(e,t){let n=an.indexOf(e),r=an.indexOf(t);return n===-1&&r===-1?e.localeCompare(t):n===-1?1:r===-1?-1:n-r}function mn(e,t){let n=pn(e.resourceType,t.resourceType);return n===0?e.name.localeCompare(t.name):n}function hn(e,t){let n=[],r={},i=e.getGraph();return i.forEachNode((a,o)=>{let s=t.get(a);n.push({uniqueId:a,name:String(o.name||a),resourceType:String(o.resource_type||`unknown`),packageName:String(o.package_name||``),path:typeof o.path==`string`?o.path:null,originalFilePath:typeof o.original_file_path==`string`?o.original_file_path:null,patchPath:typeof o.patch_path==`string`?o.patch_path:null,database:typeof o.database==`string`?o.database:null,schema:typeof o.schema==`string`?o.schema:null,description:typeof o.description==`string`?o.description:null,compiledCode:null,rawCode:null,definition:fn(String(o.resource_type||`unknown`),o),status:s?.status?Y(s.status):null,statusTone:on(s?.status),executionTime:typeof s?.execution_time==`number`?s.execution_time:null,threadId:typeof s?.thread_id==`string`?s.thread_id:null});let c=e.getUpstream(a,1),l=e.getDownstream(a,1);r[a]={upstreamCount:c.length,downstreamCount:l.length,upstream:c.slice(0,8).map(e=>{let t=i.getNodeAttributes(e.nodeId);return{uniqueId:e.nodeId,name:String(t?.name||e.nodeId),resourceType:String(t?.resource_type||`unknown`),depth:e.depth}}),downstream:l.slice(0,8).map(e=>{let t=i.getNodeAttributes(e.nodeId);return{uniqueId:e.nodeId,name:String(t?.name||e.nodeId),resourceType:String(t?.resource_type||`unknown`),depth:e.depth}})}}),n.sort(mn),{resources:n,dependencyIndex:r}}function gn(e){let t=new Map;for(let n of e){let e=t.get(n.resourceType)??[];e.push(n),t.set(n.resourceType,e)}return[...t.entries()].sort(([e],[t])=>pn(e,t)).map(([e,t])=>({resourceType:e,label:ln(e),count:t.length,attentionCount:t.filter(e=>e.statusTone===`danger`||e.statusTone===`warning`).length,resources:t}))}function _n(e){let t=new Map,n=e=>{if(!(typeof e!=`object`||!e))for(let[n,r]of Object.entries(e))typeof r==`object`&&r&&t.set(n,r)};if(n(e.nodes),n(e.sources),n(e.unit_tests),e.disabled!=null&&typeof e.disabled==`object`){for(let[n,r]of Object.entries(e.disabled))if(Array.isArray(r))for(let e of r)typeof e==`object`&&e&&t.set(n,e)}return t}function vn(e,t,n){return t.hasNode(e)?t.getNodeAttributes(e):n.get(e)}function yn(e,t,n,r){let i=e.getUpstream(r),a=i.filter(e=>e.depth===1),o=a.length>0?a:i;for(let e of o){let r=vn(e.nodeId,t,n),i=String(r?.resource_type??``);if(i!==`test`&&i!==`unit_test`&&i!==``)return e.nodeId}let s=n.get(r),c=typeof s?.attached_node==`string`?s.attached_node:null;if(c!=null)return c;let l=s?.depends_on;if(Array.isArray(l?.nodes))for(let e of l.nodes){if(typeof e!=`string`)continue;let r=vn(e,t,n),i=String(r?.resource_type??cn(e));if(i!==`test`&&i!==`unit_test`)return e}return null}function bn(e){return typeof e?.original_file_path==`string`?e.original_file_path:typeof e?.path==`string`?e.path:null}function xn(e,t,n,r){let i=vn(e.unique_id,n,r),a=i?.resource_type,o=typeof a==`string`&&a?a:cn(e.unique_id),s=o===`test`||o===`unit_test`?yn(t,n,r,e.unique_id):null,c=typeof i?.package_name==`string`&&i.package_name.length>0?i.package_name:sn(e.unique_id),l=i?.materialized,u=typeof l==`string`&&l.trim()!==``?l:null;return{...e,resourceType:o,packageName:c,path:bn(i),parentId:s,materialized:u}}function Sn(e){let t=e?.trim().toLowerCase();return t?[`error`,`fail`,`failed`,`run error`].includes(t)?3:[`warn`,`warning`].includes(t)?2:[`success`,`pass`,`passed`].includes(t)?1:0:0}function Cn(e){let t=e[0]?.status??`unknown`,n=Sn(t);for(let r of e.slice(1)){let e=Sn(r.status);e>n&&(n=e,t=r.status)}return t}function wn(e,t){let n=e.start-t.start;if(n!==0)return n;let r=t.duration-e.duration;return r===0?e.name.localeCompare(t.name):r}function Tn(e,t){let n=new Set(e.map(e=>e.unique_id)),r=new Map;for(let n of e){if(n.resourceType!==`test`&&n.resourceType!==`unit_test`||n.parentId==null||!t.hasNode(n.parentId))continue;let e=t.getNodeAttributes(n.parentId);if(String(e?.resource_type??``)!==`source`)continue;let i=r.get(n.parentId)??[];i.push(n),r.set(n.parentId,i)}let i=[];for(let[e,a]of r.entries()){if(n.has(e)||a.length===0)continue;let r=t.getNodeAttributes(e),o=[...a].sort(wn),s=Math.min(...o.map(e=>e.start)),c=Math.max(...o.map(e=>e.end));i.push({unique_id:e,name:typeof r?.name==`string`&&r.name.length>0?r.name:e,start:s,end:c,duration:Math.max(0,c-s),status:Cn(o),resourceType:`source`,packageName:typeof r?.package_name==`string`&&r.package_name.length>0?r.package_name:sn(e),path:bn(r),parentId:null,compileStart:null,compileEnd:null,executeStart:null,executeEnd:null,materialized:null})}return i.sort(wn)}function En(e,t){let n=new Map;for(let e of t){let t=Y(e.status);n.set(t,(n.get(t)??0)+(e.execution_time??0))}return Object.entries(e.nodes_by_status).map(([t,r])=>({status:Y(t),count:r,duration:n.get(Y(t))??0,share:e.total_nodes>0?r/e.total_nodes:0,tone:on(t)})).sort((e,t)=>t.count-e.count)}function Dn(e,t){let n={};for(let r of t)n[r]=e.hasNode(r)?{inbound:[...e.inboundNeighbors(r)],outbound:[...e.outboundNeighbors(r)]}:{inbound:[],outbound:[]};return n}function On(e){let t=new Map;for(let n of e){let e=n.threadId??`unknown`,r=t.get(e)??{count:0,totalExecutionTime:0};r.count+=1,r.totalExecutionTime+=n.executionTime,t.set(e,r)}return[...t.entries()].map(([e,t])=>({threadId:e,count:t.count,totalExecutionTime:t.totalExecutionTime})).sort((e,t)=>t.totalExecutionTime-e.totalExecutionTime)}function kn(e){let t=e.metadata;return typeof t==`object`&&t&&`project_name`in t&&typeof t.project_name==`string`&&t.project_name!==``?t.project_name:null}function An(e){let t=e.metadata!=null&&typeof e.metadata==`object`?e.metadata:null;return typeof t?.invocation_id==`string`?t.invocation_id:null}function jn(e){let t=e.metadata;return typeof t==`object`&&t&&`adapter_type`in t&&typeof t.adapter_type==`string`&&t.adapter_type!==``?t.adapter_type:null}function Mn(e,t,n,r){let i=J(),a=new Zt(n),o=new Qt(r,a),s=J()-i,c=J(),l=kn(e),u=jn(e),d=o.getSummary(),f=_n(e),p=o.getGanttData(),m=o.getNodeExecutions(),h=m.map(e=>e.started_at?new Date(e.started_at).getTime():null).filter(e=>e!==null),g=h.length>0?Math.min(...h):null,_=rn(d.node_executions,{mode:`top_n`,top:5,graph:a}),v=a.getSummary(),ee=new Map(p.map(e=>[e.unique_id,e])),{resources:y,dependencyIndex:b}=hn(a,new Map(m.map(e=>[e.unique_id,e]))),x=a.getGraph(),S=p.map(e=>xn(e,a,x,f)),te=Tn(S,x),ne=[...S,...te].sort(wn),re=Dn(x,ne.map(e=>e.unique_id)),ie=m.map(e=>{let t=x.hasNode(e.unique_id)?x.getNodeAttributes(e.unique_id):void 0,n=ee.get(e.unique_id);return{uniqueId:e.unique_id,name:String(t?.name||e.unique_id),resourceType:String(t?.resource_type||cn(e.unique_id)),packageName:(()=>{let n=t?.package_name;return typeof n==`string`&&n.length>0?n:sn(e.unique_id)})(),path:typeof t?.original_file_path==`string`?t.original_file_path:typeof t?.path==`string`?t.path:null,status:Y(e.status),statusTone:on(e.status),executionTime:e.execution_time??0,threadId:typeof e.thread_id==`string`?e.thread_id:null,start:n?.start??null,end:n?.end??null}}).sort((e,t)=>t.executionTime-e.executionTime),ae=gn(y),C=En(d,m),oe=On(ie),se=y.find(e=>e.resourceType===`model`)?.uniqueId??y[0]?.uniqueId??null;return{analysis:{summary:d,projectName:l,warehouseType:u,runStartedAt:g,ganttData:ne,bottlenecks:_,graphSummary:{totalNodes:v.total_nodes,totalEdges:v.total_edges,hasCycles:v.has_cycles,nodesByType:v.nodes_by_type},resources:y,resourceGroups:ae,executions:ie,statusBreakdown:C,threadStats:oe,dependencyIndex:b,timelineAdjacency:re,selectedResourceId:se,invocationId:An(t)},timings:{graphBuildMs:s,snapshotBuildMs:J()-c},graph:a}}function Z(){return performance.now()}let Q=null,$=null;function Nn(e,t){return{type:`analysis-error`,protocolVersion:2,requestId:e,message:t}}function Pn(e,t){return{type:`resource-code-error`,protocolVersion:2,requestId:e,message:t}}function Fn(e,t){return{type:`search-resources-error`,protocolVersion:2,requestId:e,message:t}}function In(e){let t=new TextDecoder().decode(e);return JSON.parse(t)}function Ln(e,t){let n=e.getGraph();if(!n.hasNode(t))return{compiledCode:null,rawCode:null};let r=n.getNodeAttributes(t);return{compiledCode:typeof r.compiled_code==`string`?r.compiled_code:null,rawCode:typeof r.raw_code==`string`?r.raw_code:typeof r.raw_sql==`string`?r.raw_sql:null}}function Rn(e){if(e.protocolVersion!==2)return Fn(e.requestId,`Unsupported protocol version: ${e.protocolVersion}`);if(!$)return Fn(e.requestId,`No analysis loaded`);let t=$.filter(t=>ue(t,e.query)).slice(0,8);return{type:`search-resources-ready`,protocolVersion:2,requestId:e.requestId,resources:t}}function zn(e){if(e.protocolVersion!==2)return Pn(e.requestId,`Unsupported protocol version: ${e.protocolVersion}`);if(!Q)return Pn(e.requestId,`No analysis loaded`);let{compiledCode:t,rawCode:n}=Ln(Q,e.uniqueId);return{type:`resource-code-ready`,protocolVersion:2,requestId:e.requestId,compiledCode:t,rawCode:n}}async function Bn(e){if(e.protocolVersion!==2)return Nn(e.requestId,`Unsupported protocol version: ${e.protocolVersion}`);try{Q=null,$=null;let t=Z(),n=Z(),r=In(e.manifestBytes),i=In(e.runResultsBytes),a=Z()-n,o=Z(),s=g(r),c=ae(i),l=Z()-o,{analysis:u,timings:d,graph:f}=Mn(r,i,s,c);Q=f,$=u.resources;let p={decodeMs:a,parseMs:l,graphBuildMs:d.graphBuildMs,snapshotBuildMs:d.snapshotBuildMs,totalWorkerMs:Z()-t};return{type:`analysis-ready`,protocolVersion:2,requestId:e.requestId,analysis:u,timings:p}}catch(t){return Nn(e.requestId,t instanceof Error?t.message:`Failed to analyze artifacts`)}}function Vn(e){return e.type===`get-resource-code`?Promise.resolve(zn(e)):e.type===`search-resources`?Promise.resolve(Rn(e)):Bn(e)}typeof self<`u`&&(self.onmessage=e=>{Vn(e.data).then(e=>{self.postMessage(e)})})})();