mdeval 1.5.0 → 2.0.0
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 +97 -181
- package/dist/cli.mjs +12 -2
- package/dist/content-mapper.mjs +13 -0
- package/dist/loader-D40biTy7.mjs +8 -0
- package/dist/loader.mjs +1 -2
- package/dist/node-modules-Bw1ALrxb.mjs +20 -0
- package/dist/runtime.d.mts +5 -0
- package/dist/runtime.mjs +0 -1
- package/docs/node.md +50 -0
- package/docs/type-checking.md +76 -0
- package/package.json +35 -8
- package/skills/mdeval/SKILL.md +97 -188
- package/skills/mdeval/references/node-loader.md +25 -0
- package/skills/mdeval/references/type-checking.md +70 -0
- package/dist/md-loader.mjs +0 -12
- package/dist/parse-markdown-wnFVEAED.mjs +0 -6
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
var cr=Object.defineProperty;var t=(e,l)=>cr(e,"name",{value:l,configurable:!0});import ur from"node:fs";import{pathToFileURL as lr}from"node:url";import{Buffer as yt}from"node:buffer";import{stdin as fr,stdout as dr}from"node:process";import hr from"util";import _t from"crypto";import pr from"path";import gr from"os";import mr from"fs";import vr from"net";import{n as yr,g as _r,d as br,C as wr}from"./node-modules-Bw1ALrxb.mjs";import"micromark";import"micromark-extension-gfm-table";var H={},Je={},Ie={},E={},x={},bt;function We(){if(bt)return x;bt=1,Object.defineProperty(x,"__esModule",{value:!0}),x.boolean=e,x.string=l,x.number=g,x.error=P,x.func=a,x.array=c,x.stringArray=o;function e(i){return i===!0||i===!1}t(e,"boolean");function l(i){return typeof i=="string"||i instanceof String}t(l,"string");function g(i){return typeof i=="number"||i instanceof Number}t(g,"number");function P(i){return i instanceof Error}t(P,"error");function a(i){return typeof i=="function"}t(a,"func");function c(i){return Array.isArray(i)}t(c,"array");function o(i){return c(i)&&i.every(R=>l(R))}return t(o,"stringArray"),x}t(We,"requireIs");var wt;function Rt(){if(wt)return E;wt=1;var e=E&&E.__createBinding||(Object.create?(function(d,s,n,h){h===void 0&&(h=n);var v=Object.getOwnPropertyDescriptor(s,n);(!v||("get"in v?!s.__esModule:v.writable||v.configurable))&&(v={enumerable:!0,get:t(function(){return s[n]},"get")}),Object.defineProperty(d,h,v)}):(function(d,s,n,h){h===void 0&&(h=n),d[h]=s[n]})),l=E&&E.__setModuleDefault||(Object.create?(function(d,s){Object.defineProperty(d,"default",{enumerable:!0,value:s})}):function(d,s){d.default=s}),g=E&&E.__importStar||(function(){var d=t(function(s){return d=Object.getOwnPropertyNames||function(n){var h=[];for(var v in n)Object.prototype.hasOwnProperty.call(n,v)&&(h[h.length]=v);return h},d(s)},"ownKeys");return function(s){if(s&&s.__esModule)return s;var n={};if(s!=null)for(var h=d(s),v=0;v<h.length;v++)h[v]!=="default"&&e(n,s,h[v]);return l(n,s),n}})();Object.defineProperty(E,"__esModule",{value:!0}),E.Message=E.NotificationType9=E.NotificationType8=E.NotificationType7=E.NotificationType6=E.NotificationType5=E.NotificationType4=E.NotificationType3=E.NotificationType2=E.NotificationType1=E.NotificationType0=E.NotificationType=E.RequestType9=E.RequestType8=E.RequestType7=E.RequestType6=E.RequestType5=E.RequestType4=E.RequestType3=E.RequestType2=E.RequestType1=E.RequestType=E.RequestType0=E.AbstractMessageSignature=E.ParameterStructures=E.ResponseError=E.ErrorCodes=void 0;const P=g(We());var a;(function(d){d.ParseError=-32700,d.InvalidRequest=-32600,d.MethodNotFound=-32601,d.InvalidParams=-32602,d.InternalError=-32603,d.jsonrpcReservedErrorRangeStart=-32099,d.serverErrorStart=-32099,d.MessageWriteError=-32099,d.MessageReadError=-32098,d.PendingResponseRejected=-32097,d.ConnectionInactive=-32096,d.ServerNotInitialized=-32002,d.UnknownErrorCode=-32001,d.jsonrpcReservedErrorRangeEnd=-32e3,d.serverErrorEnd=-32e3})(a||(E.ErrorCodes=a={}));class c extends Error{static{t(this,"ResponseError")}code;data;constructor(s,n,h){super(n),this.code=P.number(s)?s:a.UnknownErrorCode,this.data=h,Object.setPrototypeOf(this,c.prototype)}toJson(){const s={code:this.code,message:this.message};return this.data!==void 0&&(s.data=this.data),s}}E.ResponseError=c;class o{static{t(this,"ParameterStructures")}kind;static auto=new o("auto");static byPosition=new o("byPosition");static byName=new o("byName");constructor(s){this.kind=s}static is(s){return s===o.auto||s===o.byName||s===o.byPosition}toString(){return this.kind}}E.ParameterStructures=o;class i{static{t(this,"AbstractMessageSignature")}method;numberOfParams;constructor(s,n){this.method=s,this.numberOfParams=n}get parameterStructures(){return o.auto}}E.AbstractMessageSignature=i;class R extends i{static{t(this,"RequestType0")}_;constructor(s){super(s,0)}}E.RequestType0=R;class u extends i{static{t(this,"RequestType")}_parameterStructures;_;constructor(s,n=o.auto){super(s,1),this._parameterStructures=n}get parameterStructures(){return this._parameterStructures}}E.RequestType=u;class M extends i{static{t(this,"RequestType1")}_parameterStructures;_;constructor(s,n=o.auto){super(s,1),this._parameterStructures=n}get parameterStructures(){return this._parameterStructures}}E.RequestType1=M;class S extends i{static{t(this,"RequestType2")}_;constructor(s){super(s,2)}}E.RequestType2=S;class w extends i{static{t(this,"RequestType3")}_;constructor(s){super(s,3)}}E.RequestType3=w;class _ extends i{static{t(this,"RequestType4")}_;constructor(s){super(s,4)}}E.RequestType4=_;class m extends i{static{t(this,"RequestType5")}_;constructor(s){super(s,5)}}E.RequestType5=m;class p extends i{static{t(this,"RequestType6")}_;constructor(s){super(s,6)}}E.RequestType6=p;class y extends i{static{t(this,"RequestType7")}_;constructor(s){super(s,7)}}E.RequestType7=y;class C extends i{static{t(this,"RequestType8")}_;constructor(s){super(s,8)}}E.RequestType8=C;class N extends i{static{t(this,"RequestType9")}_;constructor(s){super(s,9)}}E.RequestType9=N;class J extends i{static{t(this,"NotificationType")}_parameterStructures;_;constructor(s,n=o.auto){super(s,1),this._parameterStructures=n}get parameterStructures(){return this._parameterStructures}}E.NotificationType=J;class U extends i{static{t(this,"NotificationType0")}_;constructor(s){super(s,0)}}E.NotificationType0=U;class ee extends i{static{t(this,"NotificationType1")}_parameterStructures;_;constructor(s,n=o.auto){super(s,1),this._parameterStructures=n}get parameterStructures(){return this._parameterStructures}}E.NotificationType1=ee;class Z extends i{static{t(this,"NotificationType2")}_;constructor(s){super(s,2)}}E.NotificationType2=Z;class ge extends i{static{t(this,"NotificationType3")}_;constructor(s){super(s,3)}}E.NotificationType3=ge;class oe extends i{static{t(this,"NotificationType4")}_;constructor(s){super(s,4)}}E.NotificationType4=oe;class me extends i{static{t(this,"NotificationType5")}_;constructor(s){super(s,5)}}E.NotificationType5=me;class ae extends i{static{t(this,"NotificationType6")}_;constructor(s){super(s,6)}}E.NotificationType6=ae;class ce extends i{static{t(this,"NotificationType7")}_;constructor(s){super(s,7)}}E.NotificationType7=ce;class ue extends i{static{t(this,"NotificationType8")}_;constructor(s){super(s,8)}}E.NotificationType8=ue;class le extends i{static{t(this,"NotificationType9")}_;constructor(s){super(s,9)}}E.NotificationType9=le;var ve;return(function(d){function s(v){const b=v;return b&&P.string(b.method)&&(P.string(b.id)||P.number(b.id))}t(s,"isRequest"),d.isRequest=s;function n(v){const b=v;return b&&P.string(b.method)&&v.id===void 0}t(n,"isNotification"),d.isNotification=n;function h(v){const b=v;return b&&(b.result!==void 0||!!b.error)&&(P.string(b.id)||P.number(b.id)||b.id===null)}t(h,"isResponse"),d.isResponse=h})(ve||(E.Message=ve={})),E}t(Rt,"requireMessages");var ne={},St;function Tt(){if(St)return ne;St=1,Object.defineProperty(ne,"__esModule",{value:!0}),ne.LRUCache=ne.LinkedMap=ne.Touch=void 0;var e;(function(P){P.None=0,P.First=1,P.AsOld=P.First,P.Last=2,P.AsNew=P.Last})(e||(ne.Touch=e={}));class l{static{t(this,"LinkedMap")}[Symbol.toStringTag]="LinkedMap";_map;_head;_tail;_size;_state;constructor(){this._map=new Map,this._head=void 0,this._tail=void 0,this._size=0,this._state=0}clear(){this._map.clear(),this._head=void 0,this._tail=void 0,this._size=0,this._state++}isEmpty(){return!this._head&&!this._tail}get size(){return this._size}get first(){return this._head?.value}get last(){return this._tail?.value}before(a){const c=this._map.get(a);return c?c.previous?.value:void 0}after(a){const c=this._map.get(a);return c?c.next?.value:void 0}has(a){return this._map.has(a)}get(a,c=e.None){const o=this._map.get(a);if(o)return c!==e.None&&this.touch(o,c),o.value}set(a,c,o=e.None){let i=this._map.get(a);if(i)i.value=c,o!==e.None&&this.touch(i,o);else{switch(i={key:a,value:c,next:void 0,previous:void 0},o){case e.None:this.addItemLast(i);break;case e.First:this.addItemFirst(i);break;case e.Last:this.addItemLast(i);break;default:this.addItemLast(i);break}this._map.set(a,i),this._size++}return this}delete(a){return!!this.remove(a)}remove(a){const c=this._map.get(a);if(c)return this._map.delete(a),this.removeItem(c),this._size--,c.value}shift(){if(!this._head&&!this._tail)return;if(!this._head||!this._tail)throw new Error("Invalid list");const a=this._head;return this._map.delete(a.key),this.removeItem(a),this._size--,a.value}forEach(a,c){const o=this._state;let i=this._head;for(;i;){if(c?a.bind(c)(i.value,i.key,this):a(i.value,i.key,this),this._state!==o)throw new Error("LinkedMap got modified during iteration.");i=i.next}}keys(){const a=this._state;let c=this._head;const o={[Symbol.iterator]:()=>o,next:t(()=>{if(this._state!==a)throw new Error("LinkedMap got modified during iteration.");if(c){const i={value:c.key,done:!1};return c=c.next,i}else return{value:void 0,done:!0}},"next")};return o}values(){const a=this._state;let c=this._head;const o={[Symbol.iterator]:()=>o,next:t(()=>{if(this._state!==a)throw new Error("LinkedMap got modified during iteration.");if(c){const i={value:c.value,done:!1};return c=c.next,i}else return{value:void 0,done:!0}},"next")};return o}entries(){const a=this._state;let c=this._head;const o={[Symbol.iterator]:()=>o,next:t(()=>{if(this._state!==a)throw new Error("LinkedMap got modified during iteration.");if(c){const i={value:[c.key,c.value],done:!1};return c=c.next,i}else return{value:void 0,done:!0}},"next")};return o}[Symbol.iterator](){return this.entries()}trimOld(a){if(a>=this.size)return;if(a===0){this.clear();return}let c=this._head,o=this.size;for(;c&&o>a;)this._map.delete(c.key),c=c.next,o--;this._head=c,this._size=o,c&&(c.previous=void 0),this._state++}addItemFirst(a){if(!this._head&&!this._tail)this._tail=a;else if(this._head)a.next=this._head,this._head.previous=a;else throw new Error("Invalid list");this._head=a,this._state++}addItemLast(a){if(!this._head&&!this._tail)this._head=a;else if(this._tail)a.previous=this._tail,this._tail.next=a;else throw new Error("Invalid list");this._tail=a,this._state++}removeItem(a){if(a===this._head&&a===this._tail)this._head=void 0,this._tail=void 0;else if(a===this._head){if(!a.next)throw new Error("Invalid list");a.next.previous=void 0,this._head=a.next}else if(a===this._tail){if(!a.previous)throw new Error("Invalid list");a.previous.next=void 0,this._tail=a.previous}else{const c=a.next,o=a.previous;if(!c||!o)throw new Error("Invalid list");c.previous=o,o.next=c}a.next=void 0,a.previous=void 0,this._state++}touch(a,c){if(!this._head||!this._tail)throw new Error("Invalid list");if(!(c!==e.First&&c!==e.Last)){if(c===e.First){if(a===this._head)return;const o=a.next,i=a.previous;a===this._tail?(i.next=void 0,this._tail=i):(o.previous=i,i.next=o),a.previous=void 0,a.next=this._head,this._head.previous=a,this._head=a,this._state++}else if(c===e.Last){if(a===this._tail)return;const o=a.next,i=a.previous;a===this._head?(o.previous=void 0,this._head=o):(o.previous=i,i.next=o),a.next=void 0,a.previous=this._tail,this._tail.next=a,this._tail=a,this._state++}}}toJSON(){const a=[];return this.forEach((c,o)=>{a.push([o,c])}),a}fromJSON(a){this.clear();for(const[c,o]of a)this.set(c,o)}}ne.LinkedMap=l;class g extends l{static{t(this,"LRUCache")}_limit;_ratio;constructor(a,c=1){super(),this._limit=a,this._ratio=Math.min(Math.max(0,c),1)}get limit(){return this._limit}set limit(a){this._limit=a,this.checkTrim()}get ratio(){return this._ratio}set ratio(a){this._ratio=Math.min(Math.max(0,a),1),this.checkTrim()}get(a,c=e.AsNew){return super.get(a,c)}peek(a){return super.get(a,e.None)}set(a,c){return super.set(a,c,e.Last),this.checkTrim(),this}checkTrim(){this.size>this._limit&&this.trimOld(Math.round(this._limit*this._ratio))}}return ne.LRUCache=g,ne}t(Tt,"requireLinkedMap");var Be={},Pt;function Rr(){if(Pt)return Be;Pt=1,Object.defineProperty(Be,"__esModule",{value:!0}),Be.Disposable=void 0;var e;return(function(l){function g(P){return{dispose:P}}t(g,"create"),l.create=g})(e||(Be.Disposable=e={})),Be}t(Rr,"requireDisposable");var ie={},He={},Mt;function Re(){if(Mt)return He;Mt=1,Object.defineProperty(He,"__esModule",{value:!0});let e;function l(){if(e===void 0)throw new Error("No runtime abstraction layer installed");return e}return t(l,"RAL"),(function(g){function P(a){if(a===void 0)throw new Error("No runtime abstraction layer provided");e=a}t(P,"install"),g.install=P})(l||(l={})),He.default=l,He}t(Re,"requireRal");var Et;function ze(){if(Et)return ie;Et=1;var e=ie&&ie.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(ie,"__esModule",{value:!0}),ie.Emitter=ie.Event=void 0;const l=e(Re());var g;(function(c){const o={dispose(){}};c.None=function(){return o}})(g||(ie.Event=g={}));class P{static{t(this,"CallbackList")}_callbacks;_contexts;add(o,i=null,R){this._callbacks||(this._callbacks=[],this._contexts=[]),this._callbacks.push(o),this._contexts.push(i),Array.isArray(R)&&R.push({dispose:t(()=>this.remove(o,i),"dispose")})}remove(o,i=null){if(!this._callbacks)return;let R=!1;for(let u=0,M=this._callbacks.length;u<M;u++)if(this._callbacks[u]===o)if(this._contexts[u]===i){this._callbacks.splice(u,1),this._contexts.splice(u,1);return}else R=!0;if(R)throw new Error("When adding a listener with a context, you should remove it with the same context")}invoke(...o){if(!this._callbacks)return[];const i=[],R=this._callbacks.slice(0),u=this._contexts.slice(0);for(let M=0,S=R.length;M<S;M++)try{i.push(R[M].apply(u[M],o))}catch(w){(0,l.default)().console.error(w)}return i}isEmpty(){return!this._callbacks||this._callbacks.length===0}dispose(){this._callbacks=void 0,this._contexts=void 0}}class a{static{t(this,"Emitter")}_options;static _noop=t(function(){},"_noop");_event;_callbacks;constructor(o){this._options=o}get event(){return this._event||(this._event=(o,i,R)=>{this._callbacks||(this._callbacks=new P),this._options&&this._options.onFirstListenerAdd&&this._callbacks.isEmpty()&&this._options.onFirstListenerAdd(this),this._callbacks.add(o,i);const u={dispose:t(()=>{this._callbacks&&(this._callbacks.remove(o,i),u.dispose=a._noop,this._options&&this._options.onLastListenerRemove&&this._callbacks.isEmpty()&&this._options.onLastListenerRemove(this))},"dispose")};return Array.isArray(R)&&R.push(u),u}),this._event}fire(o){this._callbacks&&this._callbacks.invoke.call(this._callbacks,o)}dispose(){this._callbacks&&(this._callbacks.dispose(),this._callbacks=void 0)}}return ie.Emitter=a,ie}t(ze,"requireEvents");var F={},Ot;function et(){if(Ot)return F;Ot=1;var e=F&&F.__createBinding||(Object.create?(function(S,w,_,m){m===void 0&&(m=_);var p=Object.getOwnPropertyDescriptor(w,_);(!p||("get"in p?!w.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:t(function(){return w[_]},"get")}),Object.defineProperty(S,m,p)}):(function(S,w,_,m){m===void 0&&(m=_),S[m]=w[_]})),l=F&&F.__setModuleDefault||(Object.create?(function(S,w){Object.defineProperty(S,"default",{enumerable:!0,value:w})}):function(S,w){S.default=w}),g=F&&F.__importStar||(function(){var S=t(function(w){return S=Object.getOwnPropertyNames||function(_){var m=[];for(var p in _)Object.prototype.hasOwnProperty.call(_,p)&&(m[m.length]=p);return m},S(w)},"ownKeys");return function(w){if(w&&w.__esModule)return w;var _={};if(w!=null)for(var m=S(w),p=0;p<m.length;p++)m[p]!=="default"&&e(_,w,m[p]);return l(_,w),_}})(),P=F&&F.__importDefault||function(S){return S&&S.__esModule?S:{default:S}};Object.defineProperty(F,"__esModule",{value:!0}),F.CancellationTokenSource=F.CancellationToken=void 0;const a=P(Re()),c=g(We()),o=ze();var i;(function(S){S.None=Object.freeze({isCancellationRequested:!1,onCancellationRequested:o.Event.None}),S.Cancelled=Object.freeze({isCancellationRequested:!0,onCancellationRequested:o.Event.None});function w(_){const m=_;return m&&(m===S.None||m===S.Cancelled||c.boolean(m.isCancellationRequested)&&!!m.onCancellationRequested)}t(w,"is"),S.is=w})(i||(F.CancellationToken=i={}));const R=Object.freeze(function(S,w){const _=(0,a.default)().timer.setTimeout(S.bind(w),0);return{dispose(){_.dispose()}}});class u{static{t(this,"MutableToken")}_isCancelled=!1;_emitter;cancel(){this._isCancelled||(this._isCancelled=!0,this._emitter&&(this._emitter.fire(void 0),this.dispose()))}get isCancellationRequested(){return this._isCancelled}get onCancellationRequested(){return this._isCancelled?R:(this._emitter||(this._emitter=new o.Emitter),this._emitter.event)}dispose(){this._emitter&&(this._emitter.dispose(),this._emitter=void 0)}}class M{static{t(this,"CancellationTokenSource")}_token;get token(){return this._token||(this._token=new u),this._token}cancel(){this._token?this._token.cancel():this._token=i.Cancelled}dispose(){this._token?this._token instanceof u&&this._token.dispose():this._token=i.None}}return F.CancellationTokenSource=M,F}t(et,"requireCancellation");var Se={},Ct;function Sr(){if(Ct)return Se;Ct=1,Object.defineProperty(Se,"__esModule",{value:!0}),Se.SharedArrayReceiverStrategy=Se.SharedArraySenderStrategy=void 0;const e=et();var l;(function(o){o.Continue=0,o.Cancelled=1})(l||(l={}));class g{static{t(this,"SharedArraySenderStrategy")}buffers;constructor(){this.buffers=new Map}enableCancellation(i){if(i.id===null)return;const R=new SharedArrayBuffer(4),u=new Int32Array(R,0,1);u[0]=l.Continue,this.buffers.set(i.id,R),i.$cancellationData=R}async sendCancellation(i,R){const u=this.buffers.get(R);if(u===void 0)return;const M=new Int32Array(u,0,1);Atomics.store(M,0,l.Cancelled)}cleanup(i){this.buffers.delete(i)}dispose(){this.buffers.clear()}}Se.SharedArraySenderStrategy=g;class P{static{t(this,"SharedArrayBufferCancellationToken")}data;constructor(i){this.data=new Int32Array(i,0,1)}get isCancellationRequested(){return Atomics.load(this.data,0)===l.Cancelled}get onCancellationRequested(){throw new Error("Cancellation over SharedArrayBuffer doesn't support cancellation events")}}class a{static{t(this,"SharedArrayBufferCancellationTokenSource")}token;constructor(i){this.token=new P(i)}cancel(){}dispose(){}}class c{static{t(this,"SharedArrayReceiverStrategy")}kind="request";createCancellationTokenSource(i){const R=i.$cancellationData;return R===void 0?new e.CancellationTokenSource:new a(R)}}return Se.SharedArrayReceiverStrategy=c,Se}t(Sr,"requireSharedArrayCancellation");var B={},Te={},Nt;function jt(){if(Nt)return Te;Nt=1;var e=Te&&Te.__importDefault||function(P){return P&&P.__esModule?P:{default:P}};Object.defineProperty(Te,"__esModule",{value:!0}),Te.Semaphore=void 0;const l=e(Re());class g{static{t(this,"Semaphore")}_capacity;_active;_waiting;constructor(a=1){if(a<=0)throw new Error("Capacity must be greater than 0");this._capacity=a,this._active=0,this._waiting=[]}lock(a){return new Promise((c,o)=>{this._waiting.push({thunk:a,resolve:c,reject:o}),this.runNext()})}get active(){return this._active}runNext(){this._waiting.length===0||this._active===this._capacity||(0,l.default)().timer.setImmediate(()=>this.doRunNext())}doRunNext(){if(this._waiting.length===0||this._active===this._capacity)return;const a=this._waiting.shift();if(this._active++,this._active>this._capacity)throw new Error("Too many thunks active");try{const c=a.thunk();c instanceof Promise?c.then(o=>{this._active--,a.resolve(o),this.runNext()},o=>{this._active--,a.reject(o),this.runNext()}):(this._active--,a.resolve(c),this.runNext())}catch(c){this._active--,a.reject(c),this.runNext()}}}return Te.Semaphore=g,Te}t(jt,"requireSemaphore");var qt;function Tr(){if(qt)return B;qt=1;var e=B&&B.__createBinding||(Object.create?(function(w,_,m,p){p===void 0&&(p=m);var y=Object.getOwnPropertyDescriptor(_,m);(!y||("get"in y?!_.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:t(function(){return _[m]},"get")}),Object.defineProperty(w,p,y)}):(function(w,_,m,p){p===void 0&&(p=m),w[p]=_[m]})),l=B&&B.__setModuleDefault||(Object.create?(function(w,_){Object.defineProperty(w,"default",{enumerable:!0,value:_})}):function(w,_){w.default=_}),g=B&&B.__importStar||(function(){var w=t(function(_){return w=Object.getOwnPropertyNames||function(m){var p=[];for(var y in m)Object.prototype.hasOwnProperty.call(m,y)&&(p[p.length]=y);return p},w(_)},"ownKeys");return function(_){if(_&&_.__esModule)return _;var m={};if(_!=null)for(var p=w(_),y=0;y<p.length;y++)p[y]!=="default"&&e(m,_,p[y]);return l(m,_),m}})(),P=B&&B.__importDefault||function(w){return w&&w.__esModule?w:{default:w}};Object.defineProperty(B,"__esModule",{value:!0}),B.ReadableStreamMessageReader=B.AbstractMessageReader=B.MessageReader=void 0;const a=P(Re()),c=g(We()),o=ze(),i=jt();var R;(function(w){function _(m){const p=m;return p&&c.func(p.listen)&&c.func(p.dispose)&&c.func(p.onError)&&c.func(p.onClose)&&c.func(p.onPartialMessage)}t(_,"is"),w.is=_})(R||(B.MessageReader=R={}));class u{static{t(this,"AbstractMessageReader")}errorEmitter;closeEmitter;partialMessageEmitter;constructor(){this.errorEmitter=new o.Emitter,this.closeEmitter=new o.Emitter,this.partialMessageEmitter=new o.Emitter}dispose(){this.errorEmitter.dispose(),this.closeEmitter.dispose(),this.partialMessageEmitter.dispose()}get onError(){return this.errorEmitter.event}fireError(_){this.errorEmitter.fire(this.asError(_))}get onClose(){return this.closeEmitter.event}fireClose(){this.closeEmitter.fire(void 0)}get onPartialMessage(){return this.partialMessageEmitter.event}firePartialMessage(_){this.partialMessageEmitter.fire(_)}asError(_){return _ instanceof Error?_:new Error(`Reader received error. Reason: ${c.string(_.message)?_.message:"unknown"}`)}}B.AbstractMessageReader=u;var M;(function(w){function _(m){let p,y;const C=new Map;let N;const J=new Map;if(m===void 0||typeof m=="string")p=m??"utf-8";else{if(p=m.charset??"utf-8",m.contentDecoder!==void 0&&(y=m.contentDecoder,C.set(y.name,y)),m.contentDecoders!==void 0)for(const U of m.contentDecoders)C.set(U.name,U);if(m.contentTypeDecoder!==void 0&&(N=m.contentTypeDecoder,J.set(N.name,N)),m.contentTypeDecoders!==void 0)for(const U of m.contentTypeDecoders)J.set(U.name,U)}return N===void 0&&(N=(0,a.default)().applicationJson.decoder,J.set(N.name,N)),{charset:p,contentDecoder:y,contentDecoders:C,contentTypeDecoder:N,contentTypeDecoders:J}}t(_,"fromOptions"),w.fromOptions=_})(M||(M={}));class S extends u{static{t(this,"ReadableStreamMessageReader")}readable;options;callback;nextMessageLength;messageToken;buffer;partialMessageTimer;_partialMessageTimeout;readSemaphore;constructor(_,m){super(),this.readable=_,this.options=M.fromOptions(m),this.buffer=(0,a.default)().messageBuffer.create(this.options.charset),this._partialMessageTimeout=1e4,this.nextMessageLength=-1,this.messageToken=0,this.readSemaphore=new i.Semaphore(1)}set partialMessageTimeout(_){this._partialMessageTimeout=_}get partialMessageTimeout(){return this._partialMessageTimeout}listen(_){this.nextMessageLength=-1,this.messageToken=0,this.partialMessageTimer=void 0,this.callback=_;const m=this.readable.onData(p=>{this.onData(p)});return this.readable.onError(p=>this.fireError(p)),this.readable.onClose(()=>this.fireClose()),m}onData(_){try{for(this.buffer.append(_);;){if(this.nextMessageLength===-1){const p=this.buffer.tryReadHeaders(!0);if(!p)return;const y=p.get("content-length");if(!y){this.fireError(new Error(`Header must provide a Content-Length property.
|
|
2
|
+
${JSON.stringify(Object.fromEntries(p))}`));return}const C=parseInt(y);if(isNaN(C)){this.fireError(new Error(`Content-Length value must be a number. Got ${y}`));return}this.nextMessageLength=C}const m=this.buffer.tryReadBody(this.nextMessageLength);if(m===void 0){this.setPartialMessageTimer();return}this.clearPartialMessageTimer(),this.nextMessageLength=-1,this.readSemaphore.lock(async()=>{const p=this.options.contentDecoder!==void 0?await this.options.contentDecoder.decode(m):m,y=await this.options.contentTypeDecoder.decode(p,this.options);this.callback(y)}).catch(p=>{this.fireError(p)})}}catch(m){this.fireError(m)}}clearPartialMessageTimer(){this.partialMessageTimer&&(this.partialMessageTimer.dispose(),this.partialMessageTimer=void 0)}setPartialMessageTimer(){this.clearPartialMessageTimer(),!(this._partialMessageTimeout<=0)&&(this.partialMessageTimer=(0,a.default)().timer.setTimeout((_,m)=>{this.partialMessageTimer=void 0,_===this.messageToken&&(this.firePartialMessage({messageToken:_,waitingTime:m}),this.setPartialMessageTimer())},this._partialMessageTimeout,this.messageToken,this._partialMessageTimeout))}}return B.ReadableStreamMessageReader=S,B}t(Tr,"requireMessageReader");var z={},kt;function Pr(){if(kt)return z;kt=1;var e=z&&z.__createBinding||(Object.create?(function(m,p,y,C){C===void 0&&(C=y);var N=Object.getOwnPropertyDescriptor(p,y);(!N||("get"in N?!p.__esModule:N.writable||N.configurable))&&(N={enumerable:!0,get:t(function(){return p[y]},"get")}),Object.defineProperty(m,C,N)}):(function(m,p,y,C){C===void 0&&(C=y),m[C]=p[y]})),l=z&&z.__setModuleDefault||(Object.create?(function(m,p){Object.defineProperty(m,"default",{enumerable:!0,value:p})}):function(m,p){m.default=p}),g=z&&z.__importStar||(function(){var m=t(function(p){return m=Object.getOwnPropertyNames||function(y){var C=[];for(var N in y)Object.prototype.hasOwnProperty.call(y,N)&&(C[C.length]=N);return C},m(p)},"ownKeys");return function(p){if(p&&p.__esModule)return p;var y={};if(p!=null)for(var C=m(p),N=0;N<C.length;N++)C[N]!=="default"&&e(y,p,C[N]);return l(y,p),y}})(),P=z&&z.__importDefault||function(m){return m&&m.__esModule?m:{default:m}};Object.defineProperty(z,"__esModule",{value:!0}),z.WriteableStreamMessageWriter=z.AbstractMessageWriter=z.MessageWriter=void 0;const a=P(Re()),c=g(We()),o=jt(),i=ze(),R="Content-Length: ",u=`\r
|
|
3
|
+
`;var M;(function(m){function p(y){const C=y;return C&&c.func(C.dispose)&&c.func(C.onClose)&&c.func(C.onError)&&c.func(C.write)}t(p,"is"),m.is=p})(M||(z.MessageWriter=M={}));class S{static{t(this,"AbstractMessageWriter")}errorEmitter;closeEmitter;constructor(){this.errorEmitter=new i.Emitter,this.closeEmitter=new i.Emitter}dispose(){this.errorEmitter.dispose(),this.closeEmitter.dispose()}get onError(){return this.errorEmitter.event}fireError(p,y,C){this.errorEmitter.fire([this.asError(p),y,C])}get onClose(){return this.closeEmitter.event}fireClose(){this.closeEmitter.fire(void 0)}asError(p){return p instanceof Error?p:new Error(`Writer received error. Reason: ${c.string(p.message)?p.message:"unknown"}`)}}z.AbstractMessageWriter=S;var w;(function(m){function p(y){return y===void 0||typeof y=="string"?{charset:y??"utf-8",contentTypeEncoder:(0,a.default)().applicationJson.encoder}:{charset:y.charset??"utf-8",contentEncoder:y.contentEncoder,contentTypeEncoder:y.contentTypeEncoder??(0,a.default)().applicationJson.encoder}}t(p,"fromOptions"),m.fromOptions=p})(w||(w={}));class _ extends S{static{t(this,"WriteableStreamMessageWriter")}writable;options;errorCount;writeSemaphore;constructor(p,y){super(),this.writable=p,this.options=w.fromOptions(y),this.errorCount=0,this.writeSemaphore=new o.Semaphore(1),this.writable.onError(C=>this.fireError(C)),this.writable.onClose(()=>this.fireClose())}async write(p){return this.writeSemaphore.lock(async()=>this.options.contentTypeEncoder.encode(p,this.options).then(C=>this.options.contentEncoder!==void 0?this.options.contentEncoder.encode(C):C).then(C=>{const N=[];return N.push(R,C.byteLength.toString(),u),N.push(u),this.doWrite(p,N,C)},C=>{throw this.fireError(C),C}))}async doWrite(p,y,C){try{return await this.writable.write(y.join(""),"ascii"),this.writable.write(C)}catch(N){return this.handleError(N,p),Promise.reject(N)}}handleError(p,y){this.errorCount++,this.fireError(p,y,this.errorCount)}end(){this.writable.end()}}return z.WriteableStreamMessageWriter=_,z}t(Pr,"requireMessageWriter");var Ve={},Lt;function Mr(){if(Lt)return Ve;Lt=1,Object.defineProperty(Ve,"__esModule",{value:!0}),Ve.AbstractMessageBuffer=void 0;const e=13,l=10,g=`\r
|
|
4
|
+
`;class P{static{t(this,"AbstractMessageBuffer")}_encoding;_chunks;_totalLength;constructor(c="utf-8"){this._encoding=c,this._chunks=[],this._totalLength=0}get encoding(){return this._encoding}append(c){const o=typeof c=="string"?this.fromString(c,this._encoding):c;this._chunks.push(o),this._totalLength+=o.byteLength}tryReadHeaders(c=!1){if(this._chunks.length===0)return;let o=0,i=0,R=0,u=0;e:for(;i<this._chunks.length;){const _=this._chunks[i];for(R=0;R<_.length;){switch(_[R]){case e:switch(o){case 0:o=1;break;case 2:o=3;break;default:o=0}break;case l:switch(o){case 1:o=2;break;case 3:o=4,R++;break e;default:o=0}break;default:o=0}R++}u+=_.byteLength,i++}if(o!==4)return;const M=this._read(u+R),S=new Map,w=this.toString(M,"ascii").split(g);if(w.length<2)return S;for(let _=0;_<w.length-2;_++){const m=w[_],p=m.indexOf(":");if(p===-1)throw new Error(`Message header must separate key and value using ':'
|
|
5
|
+
${m}`);const y=m.substr(0,p),C=m.substr(p+1).trim();S.set(c?y.toLowerCase():y,C)}return S}tryReadBody(c){if(!(this._totalLength<c))return this._read(c)}get numberOfBytes(){return this._totalLength}_read(c){if(c===0)return this.emptyBuffer();if(c>this._totalLength)throw new Error("Cannot read so many bytes!");if(this._chunks[0].byteLength===c){const u=this._chunks[0];return this._chunks.shift(),this._totalLength-=c,this.asNative(u)}if(this._chunks[0].byteLength>c){const u=this._chunks[0],M=this.asNative(u,c);return this._chunks[0]=u.slice(c),this._totalLength-=c,M}const o=this.allocNative(c);let i=0;const R=0;for(;c>0;){const u=this._chunks[R];if(u.byteLength>c){const M=u.slice(0,c);o.set(M,i),i+=c,this._chunks[R]=u.slice(c),this._totalLength-=c,c-=c}else o.set(u,i),i+=u.byteLength,this._chunks.shift(),this._totalLength-=u.byteLength,c-=u.byteLength}return o}}return Ve.AbstractMessageBuffer=P,Ve}t(Mr,"requireMessageBuffer");var X={},Dt;function Er(){return Dt||(Dt=1,(function(e){var l=X&&X.__createBinding||(Object.create?(function(n,h,v,b){b===void 0&&(b=v);var j=Object.getOwnPropertyDescriptor(h,v);(!j||("get"in j?!h.__esModule:j.writable||j.configurable))&&(j={enumerable:!0,get:t(function(){return h[v]},"get")}),Object.defineProperty(n,b,j)}):(function(n,h,v,b){b===void 0&&(b=v),n[b]=h[v]})),g=X&&X.__setModuleDefault||(Object.create?(function(n,h){Object.defineProperty(n,"default",{enumerable:!0,value:h})}):function(n,h){n.default=h}),P=X&&X.__importStar||(function(){var n=t(function(h){return n=Object.getOwnPropertyNames||function(v){var b=[];for(var j in v)Object.prototype.hasOwnProperty.call(v,j)&&(b[b.length]=j);return b},n(h)},"ownKeys");return function(h){if(h&&h.__esModule)return h;var v={};if(h!=null)for(var b=n(h),j=0;j<b.length;j++)b[j]!=="default"&&l(v,h,b[j]);return g(v,h),v}})(),a=X&&X.__importDefault||function(n){return n&&n.__esModule?n:{default:n}};Object.defineProperty(e,"__esModule",{value:!0}),e.ConnectionOptions=e.MessageStrategy=e.CancellationStrategy=e.CancellationSenderStrategy=e.CancellationReceiverStrategy=e.RequestCancellationReceiverStrategy=e.IdCancellationReceiverStrategy=e.ConnectionStrategy=e.ConnectionError=e.ConnectionErrors=e.LogTraceNotification=e.SetTraceNotification=e.TraceFormat=e.TraceValues=e.TraceValue=e.Trace=e.NullLogger=e.ProgressType=e.ProgressToken=void 0,e.createMessageConnection=s;const c=a(Re()),o=P(We()),i=Rt(),R=Tt(),u=ze(),M=et();var S;(function(n){n.type=new i.NotificationType("$/cancelRequest")})(S||(S={}));var w;(function(n){function h(v){return typeof v=="string"||typeof v=="number"}t(h,"is"),n.is=h})(w||(e.ProgressToken=w={}));var _;(function(n){n.type=new i.NotificationType("$/progress")})(_||(_={}));class m{static{t(this,"ProgressType")}__;_pr;constructor(){}}e.ProgressType=m;var p;(function(n){function h(v){return o.func(v)}t(h,"is"),n.is=h})(p||(p={})),e.NullLogger=Object.freeze({error:t(()=>{},"error"),warn:t(()=>{},"warn"),info:t(()=>{},"info"),log:t(()=>{},"log")});var y;(function(n){n[n.Off=0]="Off",n[n.Messages=1]="Messages",n[n.Compact=2]="Compact",n[n.Verbose=3]="Verbose"})(y||(e.Trace=y={}));var C;(function(n){n.Off="off",n.Messages="messages",n.Compact="compact",n.Verbose="verbose"})(C||(e.TraceValue=C={})),e.TraceValues=C,(function(n){function h(b){if(!o.string(b))return n.Off;switch(b=b.toLowerCase(),b){case"off":return n.Off;case"messages":return n.Messages;case"compact":return n.Compact;case"verbose":return n.Verbose;default:return n.Off}}t(h,"fromString"),n.fromString=h;function v(b){switch(b){case n.Off:return"off";case n.Messages:return"messages";case n.Compact:return"compact";case n.Verbose:return"verbose";default:return"off"}}t(v,"toString"),n.toString=v})(y||(e.Trace=y={}));var N;(function(n){n.Text="text",n.JSON="json"})(N||(e.TraceFormat=N={})),(function(n){function h(v){return o.string(v)?(v=v.toLowerCase(),v==="json"?n.JSON:n.Text):n.Text}t(h,"fromString"),n.fromString=h})(N||(e.TraceFormat=N={}));var J;(function(n){n.type=new i.NotificationType("$/setTrace")})(J||(e.SetTraceNotification=J={}));var U;(function(n){n.type=new i.NotificationType("$/logTrace")})(U||(e.LogTraceNotification=U={}));var ee;(function(n){n[n.Closed=1]="Closed",n[n.Disposed=2]="Disposed",n[n.AlreadyListening=3]="AlreadyListening"})(ee||(e.ConnectionErrors=ee={}));class Z extends Error{static{t(this,"ConnectionError")}code;constructor(h,v){super(v),this.code=h,Object.setPrototypeOf(this,Z.prototype)}}e.ConnectionError=Z;var ge;(function(n){function h(v){const b=v;return b&&o.func(b.cancelUndispatched)}t(h,"is"),n.is=h})(ge||(e.ConnectionStrategy=ge={}));var oe;(function(n){function h(v){const b=v;return b&&(b.kind===void 0||b.kind==="id")&&o.func(b.createCancellationTokenSource)&&(b.dispose===void 0||o.func(b.dispose))}t(h,"is"),n.is=h})(oe||(e.IdCancellationReceiverStrategy=oe={}));var me;(function(n){function h(v){const b=v;return b&&b.kind==="request"&&o.func(b.createCancellationTokenSource)&&(b.dispose===void 0||o.func(b.dispose))}t(h,"is"),n.is=h})(me||(e.RequestCancellationReceiverStrategy=me={}));var ae;(function(n){n.Message=Object.freeze({createCancellationTokenSource(v){return new M.CancellationTokenSource}});function h(v){return oe.is(v)||me.is(v)}t(h,"is"),n.is=h})(ae||(e.CancellationReceiverStrategy=ae={}));var ce;(function(n){n.Message=Object.freeze({sendCancellation(v,b){return v.sendNotification(S.type,{id:b})},cleanup(v){}});function h(v){const b=v;return b&&o.func(b.sendCancellation)&&o.func(b.cleanup)}t(h,"is"),n.is=h})(ce||(e.CancellationSenderStrategy=ce={}));var ue;(function(n){n.Message=Object.freeze({receiver:ae.Message,sender:ce.Message});function h(v){const b=v;return b&&ae.is(b.receiver)&&ce.is(b.sender)}t(h,"is"),n.is=h})(ue||(e.CancellationStrategy=ue={}));var le;(function(n){function h(v){const b=v;return b&&o.func(b.handleMessage)}t(h,"is"),n.is=h})(le||(e.MessageStrategy=le={}));var ve;(function(n){function h(v){const b=v;return b&&(ue.is(b.cancellationStrategy)||ge.is(b.connectionStrategy)||le.is(b.messageStrategy)||o.number(b.maxParallelism))}t(h,"is"),n.is=h})(ve||(e.ConnectionOptions=ve={}));var d;(function(n){n[n.New=1]="New",n[n.Listening=2]="Listening",n[n.Closed=3]="Closed",n[n.Disposed=4]="Disposed"})(d||(d={}));function s(n,h,v,b){const j=v!==void 0?v:e.NullLogger;let Q=0,Ke=0,Ft=0;const Ue="2.0",Ce=b?.maxParallelism??-1;let Ne=0,Pe;const je=new Map;let Me;const qe=new Map,ke=new Map;let Qe,ye=new R.LinkedMap,fe=new Map,Fe=new Set,Le=new Map,L=y.Off,_e=N.Text,I,de=d.New;const Ge=new u.Emitter,st=new u.Emitter,ot=new u.Emitter,at=new u.Emitter,ct=new u.Emitter,he=b&&b.cancellationStrategy?b.cancellationStrategy:ue.Message;function Jt(r){}t(Jt,"cancelUndispatched");function ut(){return de===d.Listening}t(ut,"isListening");function lt(){return de===d.Closed}t(lt,"isClosed");function Ee(){return de===d.Disposed}t(Ee,"isDisposed");function ft(){(de===d.New||de===d.Listening)&&(de=d.Closed,st.fire(void 0))}t(ft,"closeHandler");function Ht(r){Ge.fire([r,void 0,void 0])}t(Ht,"readErrorHandler");function Kt(r){Ge.fire(r)}t(Kt,"writeErrorHandler"),n.onClose(ft),n.onError(Ht),h.onClose(ft),h.onError(Kt);function dt(r){if(r===null)throw new Error("Can't send requests with id null since the response can't be correlated.");return"req-"+r.toString()}t(dt,"createRequestQueueKey");function Qt(r){return r===null?"res-unknown-"+(++Ft).toString():"res-"+r.toString()}t(Qt,"createResponseQueueKey");function Gt(){return"not-"+(++Ke).toString()}t(Gt,"createNotificationQueueKey");function Xt(r,f){i.Message.isRequest(f)?r.set(dt(f.id),f):i.Message.isResponse(f)?Ce===-1?r.set(Qt(f.id),f):pt(f):r.set(Gt(),f)}t(Xt,"addMessageToQueue");function Xe(){Qe||ye.size===0||Ce!==-1&&Ne>=Ce||(Qe=(0,c.default)().timer.setImmediate(async()=>{if(Qe=void 0,ye.size===0||Ce!==-1&&Ne>=Ce)return;const r=ye.shift();let f;try{Ne++;const T=b?.messageStrategy;le.is(T)?f=T.handleMessage(r,ht):f=ht(r)}catch(T){j.error(`Processing message queue failed: ${T.toString()}`)}finally{f instanceof Promise?f.then(()=>{}).catch(T=>{j.error(`Processing message queue failed: ${T.toString()}`)}).finally(()=>{Ne--,Xe()}):Ne--,Xe()}}))}t(Xe,"triggerMessageQueue");async function ht(r){return i.Message.isRequest(r)?Zt(r):i.Message.isNotification(r)?xt(r):i.Message.isResponse(r)?pt(r):er(r)}t(ht,"handleMessage");const Yt=t(r=>{try{if(i.Message.isNotification(r)&&r.method===S.type.method){const f=r.params.id,T=dt(f),O=ye.get(T);if(i.Message.isRequest(O)){const D=b?.connectionStrategy,k=D&&D.cancelUndispatched?D.cancelUndispatched(O,Jt):void 0;if(k&&(k.error!==void 0||k.result!==void 0)){ye.delete(T),Le.delete(f),k.id=O.id,Ye(k,r.method,Date.now()),h.write(k).catch(()=>j.error("Sending response for canceled message failed."));return}}const q=Le.get(f);if(q!==void 0){q.cancel(),Ze(r);return}else Fe.add(f)}Xt(ye,r)}finally{Xe()}},"callback");async function Zt(r){if(Ee())return Promise.resolve();function f(W,V,A){const $={jsonrpc:Ue,id:r.id};return W instanceof i.ResponseError?$.error=W.toJson():$.result=W===void 0?null:W,Ye($,V,A),h.write($)}t(f,"reply");function T(W,V,A){const $={jsonrpc:Ue,id:r.id,error:W.toJson()};return Ye($,V,A),h.write($)}t(T,"replyError"),nr(r);const O=je.get(r.method);let q,D;O&&(q=O.type,D=O.handler);const k=Date.now();if(D||Pe){const W=r.id??String(Date.now()),V=oe.is(he.receiver)?he.receiver.createCancellationTokenSource(W):he.receiver.createCancellationTokenSource(r);r.id!==null&&Fe.has(r.id)&&V.cancel(),r.id!==null&&Le.set(W,V);try{let A;if(D)if(r.params===void 0){if(q!==void 0&&q.numberOfParams!==0)return T(new i.ResponseError(i.ErrorCodes.InvalidParams,`Request ${r.method} defines ${q.numberOfParams} params but received none.`),r.method,k);A=D(V.token)}else if(Array.isArray(r.params)){if(q!==void 0&&q.parameterStructures===i.ParameterStructures.byName)return T(new i.ResponseError(i.ErrorCodes.InvalidParams,`Request ${r.method} defines parameters by name but received parameters by position`),r.method,k);A=D(...r.params,V.token)}else{if(q!==void 0&&q.parameterStructures===i.ParameterStructures.byPosition)return T(new i.ResponseError(i.ErrorCodes.InvalidParams,`Request ${r.method} defines parameters by position but received parameters by name`),r.method,k);A=D(r.params,V.token)}else Pe&&(A=Pe(r.method,r.params,V.token));const $=await A;await f($,r.method,k)}catch(A){A instanceof i.ResponseError?await f(A,r.method,k):A&&o.string(A.message)?await T(new i.ResponseError(i.ErrorCodes.InternalError,`Request ${r.method} failed with message: ${A.message}`),r.method,k):await T(new i.ResponseError(i.ErrorCodes.InternalError,`Request ${r.method} failed unexpectedly without providing any details.`),r.method,k)}finally{Le.delete(W)}}else await T(new i.ResponseError(i.ErrorCodes.MethodNotFound,`Unhandled method ${r.method}`),r.method,k)}t(Zt,"handleRequest");function pt(r){if(!Ee())if(r.id===null)r.error?j.error(`Received response message without id: Error is:
|
|
6
|
+
${JSON.stringify(r.error,void 0,4)}`):j.error("Received response message without id. No further error information provided.");else{const f=r.id,T=fe.get(f);if(ir(r,T),T!==void 0){fe.delete(f);try{if(r.error){const O=r.error;T.reject(new i.ResponseError(O.code,O.message,O.data))}else if(r.result!==void 0)T.resolve(r.result);else throw new Error("Should never happen.")}catch(O){O.message?j.error(`Response handler '${T.method}' failed with message: ${O.message}`):j.error(`Response handler '${T.method}' failed unexpectedly.`)}}}}t(pt,"handleResponse");async function xt(r){if(Ee())return;let f,T;if(r.method===S.type.method){const O=r.params.id;Fe.delete(O),Ze(r);return}else{const O=qe.get(r.method);O&&(T=O.handler,f=O.type)}if(T||Me)try{if(Ze(r),T)if(r.params===void 0)f!==void 0&&f.numberOfParams!==0&&f.parameterStructures!==i.ParameterStructures.byName&&j.error(`Notification ${r.method} defines ${f.numberOfParams} params but received none.`),await T();else if(Array.isArray(r.params)){const O=r.params;r.method===_.type.method&&O.length===2&&w.is(O[0])?await T({token:O[0],value:O[1]}):(f!==void 0&&(f.parameterStructures===i.ParameterStructures.byName&&j.error(`Notification ${r.method} defines parameters by name but received parameters by position`),f.numberOfParams!==r.params.length&&j.error(`Notification ${r.method} defines ${f.numberOfParams} params but received ${O.length} arguments`)),await T(...O))}else f!==void 0&&f.parameterStructures===i.ParameterStructures.byPosition&&j.error(`Notification ${r.method} defines parameters by position but received parameters by name`),await T(r.params);else Me&&await Me(r.method,r.params)}catch(O){O.message?j.error(`Notification handler '${r.method}' failed with message: ${O.message}`):j.error(`Notification handler '${r.method}' failed unexpectedly.`)}else ot.fire(r)}t(xt,"handleNotification");function er(r){if(!r){j.error("Received empty message.");return}j.error(`Received message which is neither a response nor a notification message:
|
|
7
|
+
${JSON.stringify(r,null,4)}`);const f=r;if(o.string(f.id)||o.number(f.id)){const T=f.id,O=fe.get(T);O&&O.reject(new Error("The received response has neither a result nor an error property."))}}t(er,"handleInvalidMessage");function pe(r){if(r!=null)switch(L){case y.Verbose:return JSON.stringify(r,null,4);case y.Compact:return JSON.stringify(r);default:return}}t(pe,"stringifyTrace");function tr(r){if(!(L===y.Off||!I))if(_e===N.Text){let f;(L===y.Verbose||L===y.Compact)&&r.params&&(f=`Params: ${pe(r.params)}`),I.log(`Sending request '${r.method} - (${r.id})'.`,f)}else Oe("send-request",r)}t(tr,"traceSendingRequest");function rr(r){if(!(L===y.Off||!I))if(_e===N.Text){let f;(L===y.Verbose||L===y.Compact)&&(r.params?f=`Params: ${pe(r.params)}`:f="No parameters provided."),I.log(`Sending notification '${r.method}'.`,f)}else Oe("send-notification",r)}t(rr,"traceSendingNotification");function Ye(r,f,T){if(!(L===y.Off||!I))if(_e===N.Text){let O;(L===y.Verbose||L===y.Compact)&&(r.error&&r.error.data?O=`Error data: ${pe(r.error.data)}`:r.result?O=`Result: ${pe(r.result)}`:r.error===void 0&&(O="No result returned."));const q=r.error?` Request failed: ${r.error.message} (${r.error.code}).`:"";I.log(`Sending response '${f} - (${r.id})'. Processing request took ${Date.now()-T}ms.${q}`,O)}else Oe("send-response",r)}t(Ye,"traceSendingResponse");function nr(r){if(!(L===y.Off||!I))if(_e===N.Text){let f;(L===y.Verbose||L===y.Compact)&&r.params&&(f=`Params: ${pe(r.params)}`),I.log(`Received request '${r.method} - (${r.id})'.`,f)}else Oe("receive-request",r)}t(nr,"traceReceivedRequest");function Ze(r){if(!(L===y.Off||!I||r.method===U.type.method))if(_e===N.Text){let f;(L===y.Verbose||L===y.Compact)&&(r.params?f=`Params: ${pe(r.params)}`:f="No parameters provided."),I.log(`Received notification '${r.method}'.`,f)}else Oe("receive-notification",r)}t(Ze,"traceReceivedNotification");function ir(r,f){if(!(L===y.Off||!I))if(_e===N.Text){let T;if((L===y.Verbose||L===y.Compact)&&(r.error&&r.error.data?T=`Error data: ${pe(r.error.data)}`:r.result?T=`Result: ${pe(r.result)}`:r.error===void 0&&(T="No result returned.")),f){const O=r.error?` Request failed: ${r.error.message} (${r.error.code}).`:"";I.log(`Received response '${f.method} - (${r.id})' in ${Date.now()-f.timerStart}ms.${O}`,T)}else I.log(`Received response ${r.id} without active response promise.`,T)}else Oe("receive-response",r)}t(ir,"traceReceivedResponse");function Oe(r,f){if(!I||L===y.Off)return;const T={isLSPMessage:!0,type:r,message:f,timestamp:Date.now()};I.log(T)}t(Oe,"logLSPMessage");function De(){if(lt())throw new Z(ee.Closed,"Connection is closed.");if(Ee())throw new Z(ee.Disposed,"Connection is disposed.")}t(De,"throwIfClosedOrDisposed");function sr(){if(ut())throw new Z(ee.AlreadyListening,"Connection is already listening")}t(sr,"throwIfListening");function or(){if(!ut())throw new Error("Call listen() first.")}t(or,"throwIfNotListening");function Ae(r){return r===void 0?null:r}t(Ae,"undefinedToNull");function gt(r){if(r!==null)return r}t(gt,"nullToUndefined");function mt(r){return r!=null&&!Array.isArray(r)&&typeof r=="object"}t(mt,"isNamedParam");function xe(r,f){switch(r){case i.ParameterStructures.auto:return mt(f)?gt(f):[Ae(f)];case i.ParameterStructures.byName:if(!mt(f))throw new Error("Received parameters by name but param is not an object literal.");return gt(f);case i.ParameterStructures.byPosition:return[Ae(f)];default:throw new Error(`Unknown parameter structure ${r.toString()}`)}}t(xe,"computeSingleParam");function vt(r,f){let T;const O=r.numberOfParams;switch(O){case 0:T=void 0;break;case 1:T=xe(r.parameterStructures,f[0]);break;default:T=[];for(let q=0;q<f.length&&q<O;q++)T.push(Ae(f[q]));if(f.length<O)for(let q=f.length;q<O;q++)T.push(null);break}return T}t(vt,"computeMessageParams");const be={sendNotification:t((r,...f)=>{De();let T,O;if(o.string(r)){T=r;const D=f[0];let k=0,W=i.ParameterStructures.auto;i.ParameterStructures.is(D)&&(k=1,W=D);const V=f.length,A=V-k;switch(A){case 0:O=void 0;break;case 1:O=xe(W,f[k]);break;default:if(W===i.ParameterStructures.byName)throw new Error(`Received ${A} parameters for 'by Name' notification parameter structure.`);O=f.slice(k,V).map($=>Ae($));break}}else{const D=f;T=r.method,O=vt(r,D)}const q={jsonrpc:Ue,method:T,params:O};return rr(q),h.write(q).catch(D=>{throw j.error("Sending notification failed."),D})},"sendNotification"),onNotification:t((r,f)=>{De();let T;return o.func(r)?Me=r:f&&(o.string(r)?(T=r,qe.set(r,{type:void 0,handler:f})):(T=r.method,qe.set(r.method,{type:r,handler:f}))),{dispose:t(()=>{T!==void 0?qe.get(T)?.handler===f&&qe.delete(T):Me===r&&(Me=void 0)},"dispose")}},"onNotification"),onProgress:t((r,f,T)=>{if(ke.has(f))throw new Error(`Progress handler for token ${f} already registered`);return ke.set(f,T),{dispose:t(()=>{ke.get(f)===T&&ke.delete(f)},"dispose")}},"onProgress"),sendProgress:t((r,f,T)=>be.sendNotification(_.type,{token:f,value:T}),"sendProgress"),onUnhandledProgress:at.event,sendRequest:t((r,...f)=>{De(),or();function T($,G){const te=he.sender.sendCancellation($,G);te===void 0?j.log(`Received no promise from cancellation strategy when cancelling id ${G}`):te.catch(()=>{j.log(`Sending cancellation messages for id ${G} failed.`)})}t(T,"sendCancellation");let O,q,D;if(o.string(r)){O=r;const $=f[0],G=f[f.length-1];let te=0,$e=i.ParameterStructures.auto;i.ParameterStructures.is($)&&(te=1,$e=$);let we=f.length;M.CancellationToken.is(G)&&(we=we-1,D=G);const re=we-te;switch(re){case 0:q=void 0;break;case 1:q=xe($e,f[te]);break;default:if($e===i.ParameterStructures.byName)throw new Error(`Received ${re} parameters for 'by Name' request parameter structure.`);q=f.slice(te,we).map(ar=>Ae(ar));break}}else{const $=f;O=r.method,q=vt(r,$);const G=r.numberOfParams;D=M.CancellationToken.is($[G])?$[G]:void 0}const k=Q++;let W,V=!1;D!==void 0&&(D.isCancellationRequested?V=!0:W=D.onCancellationRequested(()=>{T(be,k)}));const A={jsonrpc:Ue,id:k,method:O,params:q};return tr(A),typeof he.sender.enableCancellation=="function"&&he.sender.enableCancellation(A),new Promise(async($,G)=>{const te=t(re=>{$(re),he.sender.cleanup(k),W?.dispose()},"resolveWithCleanup"),$e=t(re=>{G(re),he.sender.cleanup(k),W?.dispose()},"rejectWithCleanup"),we={method:O,timerStart:Date.now(),resolve:te,reject:$e};try{fe.set(k,we),await h.write(A),V&&T(be,k)}catch(re){fe.delete(k),we.reject(new i.ResponseError(i.ErrorCodes.MessageWriteError,re.message?re.message:"Unknown reason")),j.error("Sending request failed.")}})},"sendRequest"),onRequest:t((r,f)=>{De();let T=null;return p.is(r)?(T=void 0,Pe=r):o.string(r)?(T=null,f!==void 0&&(T=r,je.set(r,{handler:f,type:void 0}))):f!==void 0&&(T=r.method,je.set(r.method,{type:r,handler:f})),{dispose:t(()=>{T!==null&&(T!==void 0?je.get(T)?.handler===f&&je.delete(T):Pe===r&&(Pe=void 0))},"dispose")}},"onRequest"),hasPendingResponse:t(()=>fe.size>0,"hasPendingResponse"),trace:t(async(r,f,T)=>{let O=!1,q=N.Text;T!==void 0&&(o.boolean(T)?O=T:(O=T.sendNotification||!1,q=T.traceFormat||N.Text)),L=r,_e=q,L===y.Off?I=void 0:I=f,O&&!lt()&&!Ee()&&await be.sendNotification(J.type,{value:y.toString(r)})},"trace"),onError:Ge.event,onClose:st.event,onUnhandledNotification:ot.event,onDispose:ct.event,end:t(()=>{h.end()},"end"),dispose:t(()=>{if(Ee())return;de=d.Disposed,ct.fire(void 0);const r=new i.ResponseError(i.ErrorCodes.PendingResponseRejected,"Pending response rejected since connection got disposed");for(const f of fe.values())f.reject(r);fe=new Map,Le=new Map,Fe=new Set,ye=new R.LinkedMap,o.func(h.dispose)&&h.dispose(),o.func(n.dispose)&&n.dispose()},"dispose"),listen:t(()=>{De(),sr(),de=d.Listening,n.listen(Yt)},"listen"),inspect:t(()=>{(0,c.default)().console.log("inspect")},"inspect")};return be.onNotification(U.type,r=>{if(L===y.Off||!I)return;const f=L===y.Verbose||L===y.Compact;I.log(r.message,f?r.verbose:void 0)}),be.onNotification(_.type,async r=>{const f=ke.get(r.token);f?await f(r.value):at.fire(r)}),be}t(s,"createMessageConnection")})(X)),X}t(Er,"requireConnection");var At;function tt(){return At||(At=1,(function(e){var l=Ie&&Ie.__importDefault||function(_){return _&&_.__esModule?_:{default:_}};Object.defineProperty(e,"__esModule",{value:!0}),e.ProgressType=e.ProgressToken=e.createMessageConnection=e.NullLogger=e.ConnectionOptions=e.ConnectionStrategy=e.AbstractMessageBuffer=e.WriteableStreamMessageWriter=e.AbstractMessageWriter=e.MessageWriter=e.ReadableStreamMessageReader=e.AbstractMessageReader=e.MessageReader=e.SharedArrayReceiverStrategy=e.SharedArraySenderStrategy=e.CancellationToken=e.CancellationTokenSource=e.Emitter=e.Event=e.Disposable=e.LRUCache=e.Touch=e.LinkedMap=e.ParameterStructures=e.NotificationType9=e.NotificationType8=e.NotificationType7=e.NotificationType6=e.NotificationType5=e.NotificationType4=e.NotificationType3=e.NotificationType2=e.NotificationType1=e.NotificationType0=e.NotificationType=e.ErrorCodes=e.ResponseError=e.RequestType9=e.RequestType8=e.RequestType7=e.RequestType6=e.RequestType5=e.RequestType4=e.RequestType3=e.RequestType2=e.RequestType1=e.RequestType0=e.RequestType=e.Message=e.RAL=void 0,e.MessageStrategy=e.CancellationStrategy=e.CancellationSenderStrategy=e.RequestCancellationReceiverStrategy=e.IdCancellationReceiverStrategy=e.CancellationReceiverStrategy=e.ConnectionError=e.ConnectionErrors=e.LogTraceNotification=e.SetTraceNotification=e.TraceFormat=e.TraceValues=e.TraceValue=e.Trace=void 0;const g=Rt();Object.defineProperty(e,"Message",{enumerable:!0,get:t(function(){return g.Message},"get")}),Object.defineProperty(e,"RequestType",{enumerable:!0,get:t(function(){return g.RequestType},"get")}),Object.defineProperty(e,"RequestType0",{enumerable:!0,get:t(function(){return g.RequestType0},"get")}),Object.defineProperty(e,"RequestType1",{enumerable:!0,get:t(function(){return g.RequestType1},"get")}),Object.defineProperty(e,"RequestType2",{enumerable:!0,get:t(function(){return g.RequestType2},"get")}),Object.defineProperty(e,"RequestType3",{enumerable:!0,get:t(function(){return g.RequestType3},"get")}),Object.defineProperty(e,"RequestType4",{enumerable:!0,get:t(function(){return g.RequestType4},"get")}),Object.defineProperty(e,"RequestType5",{enumerable:!0,get:t(function(){return g.RequestType5},"get")}),Object.defineProperty(e,"RequestType6",{enumerable:!0,get:t(function(){return g.RequestType6},"get")}),Object.defineProperty(e,"RequestType7",{enumerable:!0,get:t(function(){return g.RequestType7},"get")}),Object.defineProperty(e,"RequestType8",{enumerable:!0,get:t(function(){return g.RequestType8},"get")}),Object.defineProperty(e,"RequestType9",{enumerable:!0,get:t(function(){return g.RequestType9},"get")}),Object.defineProperty(e,"ResponseError",{enumerable:!0,get:t(function(){return g.ResponseError},"get")}),Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:t(function(){return g.ErrorCodes},"get")}),Object.defineProperty(e,"NotificationType",{enumerable:!0,get:t(function(){return g.NotificationType},"get")}),Object.defineProperty(e,"NotificationType0",{enumerable:!0,get:t(function(){return g.NotificationType0},"get")}),Object.defineProperty(e,"NotificationType1",{enumerable:!0,get:t(function(){return g.NotificationType1},"get")}),Object.defineProperty(e,"NotificationType2",{enumerable:!0,get:t(function(){return g.NotificationType2},"get")}),Object.defineProperty(e,"NotificationType3",{enumerable:!0,get:t(function(){return g.NotificationType3},"get")}),Object.defineProperty(e,"NotificationType4",{enumerable:!0,get:t(function(){return g.NotificationType4},"get")}),Object.defineProperty(e,"NotificationType5",{enumerable:!0,get:t(function(){return g.NotificationType5},"get")}),Object.defineProperty(e,"NotificationType6",{enumerable:!0,get:t(function(){return g.NotificationType6},"get")}),Object.defineProperty(e,"NotificationType7",{enumerable:!0,get:t(function(){return g.NotificationType7},"get")}),Object.defineProperty(e,"NotificationType8",{enumerable:!0,get:t(function(){return g.NotificationType8},"get")}),Object.defineProperty(e,"NotificationType9",{enumerable:!0,get:t(function(){return g.NotificationType9},"get")}),Object.defineProperty(e,"ParameterStructures",{enumerable:!0,get:t(function(){return g.ParameterStructures},"get")});const P=Tt();Object.defineProperty(e,"LinkedMap",{enumerable:!0,get:t(function(){return P.LinkedMap},"get")}),Object.defineProperty(e,"LRUCache",{enumerable:!0,get:t(function(){return P.LRUCache},"get")}),Object.defineProperty(e,"Touch",{enumerable:!0,get:t(function(){return P.Touch},"get")});const a=Rr();Object.defineProperty(e,"Disposable",{enumerable:!0,get:t(function(){return a.Disposable},"get")});const c=ze();Object.defineProperty(e,"Event",{enumerable:!0,get:t(function(){return c.Event},"get")}),Object.defineProperty(e,"Emitter",{enumerable:!0,get:t(function(){return c.Emitter},"get")});const o=et();Object.defineProperty(e,"CancellationTokenSource",{enumerable:!0,get:t(function(){return o.CancellationTokenSource},"get")}),Object.defineProperty(e,"CancellationToken",{enumerable:!0,get:t(function(){return o.CancellationToken},"get")});const i=Sr();Object.defineProperty(e,"SharedArraySenderStrategy",{enumerable:!0,get:t(function(){return i.SharedArraySenderStrategy},"get")}),Object.defineProperty(e,"SharedArrayReceiverStrategy",{enumerable:!0,get:t(function(){return i.SharedArrayReceiverStrategy},"get")});const R=Tr();Object.defineProperty(e,"MessageReader",{enumerable:!0,get:t(function(){return R.MessageReader},"get")}),Object.defineProperty(e,"AbstractMessageReader",{enumerable:!0,get:t(function(){return R.AbstractMessageReader},"get")}),Object.defineProperty(e,"ReadableStreamMessageReader",{enumerable:!0,get:t(function(){return R.ReadableStreamMessageReader},"get")});const u=Pr();Object.defineProperty(e,"MessageWriter",{enumerable:!0,get:t(function(){return u.MessageWriter},"get")}),Object.defineProperty(e,"AbstractMessageWriter",{enumerable:!0,get:t(function(){return u.AbstractMessageWriter},"get")}),Object.defineProperty(e,"WriteableStreamMessageWriter",{enumerable:!0,get:t(function(){return u.WriteableStreamMessageWriter},"get")});const M=Mr();Object.defineProperty(e,"AbstractMessageBuffer",{enumerable:!0,get:t(function(){return M.AbstractMessageBuffer},"get")});const S=Er();Object.defineProperty(e,"ConnectionStrategy",{enumerable:!0,get:t(function(){return S.ConnectionStrategy},"get")}),Object.defineProperty(e,"ConnectionOptions",{enumerable:!0,get:t(function(){return S.ConnectionOptions},"get")}),Object.defineProperty(e,"NullLogger",{enumerable:!0,get:t(function(){return S.NullLogger},"get")}),Object.defineProperty(e,"createMessageConnection",{enumerable:!0,get:t(function(){return S.createMessageConnection},"get")}),Object.defineProperty(e,"ProgressToken",{enumerable:!0,get:t(function(){return S.ProgressToken},"get")}),Object.defineProperty(e,"ProgressType",{enumerable:!0,get:t(function(){return S.ProgressType},"get")}),Object.defineProperty(e,"Trace",{enumerable:!0,get:t(function(){return S.Trace},"get")}),Object.defineProperty(e,"TraceValue",{enumerable:!0,get:t(function(){return S.TraceValue},"get")}),Object.defineProperty(e,"TraceFormat",{enumerable:!0,get:t(function(){return S.TraceFormat},"get")}),Object.defineProperty(e,"SetTraceNotification",{enumerable:!0,get:t(function(){return S.SetTraceNotification},"get")}),Object.defineProperty(e,"LogTraceNotification",{enumerable:!0,get:t(function(){return S.LogTraceNotification},"get")}),Object.defineProperty(e,"ConnectionErrors",{enumerable:!0,get:t(function(){return S.ConnectionErrors},"get")}),Object.defineProperty(e,"ConnectionError",{enumerable:!0,get:t(function(){return S.ConnectionError},"get")}),Object.defineProperty(e,"CancellationReceiverStrategy",{enumerable:!0,get:t(function(){return S.CancellationReceiverStrategy},"get")}),Object.defineProperty(e,"IdCancellationReceiverStrategy",{enumerable:!0,get:t(function(){return S.IdCancellationReceiverStrategy},"get")}),Object.defineProperty(e,"RequestCancellationReceiverStrategy",{enumerable:!0,get:t(function(){return S.RequestCancellationReceiverStrategy},"get")}),Object.defineProperty(e,"CancellationSenderStrategy",{enumerable:!0,get:t(function(){return S.CancellationSenderStrategy},"get")}),Object.defineProperty(e,"CancellationStrategy",{enumerable:!0,get:t(function(){return S.CancellationStrategy},"get")}),Object.defineProperty(e,"MessageStrategy",{enumerable:!0,get:t(function(){return S.MessageStrategy},"get")}),Object.defineProperty(e,"TraceValues",{enumerable:!0,get:t(function(){return S.TraceValues},"get")});const w=l(Re());e.RAL=w.default})(Ie)),Ie}t(tt,"requireApi");var $t;function Or(){if($t)return Je;$t=1,Object.defineProperty(Je,"__esModule",{value:!0});const e=hr,l=_t,g=tt();class P extends g.AbstractMessageBuffer{static{t(this,"MessageBuffer")}static emptyBuffer=Buffer.allocUnsafe(0);constructor(u="utf-8"){super(u)}emptyBuffer(){return P.emptyBuffer}fromString(u,M){return Buffer.from(u,M)}toString(u,M){return u instanceof Buffer?u.toString(M):new e.TextDecoder(M).decode(u)}asNative(u,M){return M===void 0?u instanceof Buffer?u:Buffer.from(u):u instanceof Buffer?u.slice(0,M):Buffer.from(u.subarray(0,M))}allocNative(u){return Buffer.allocUnsafe(u)}}class a{static{t(this,"ReadableStreamWrapper")}stream;constructor(u){this.stream=u}onClose(u){return this.stream.on("close",u),g.Disposable.create(()=>this.stream.off("close",u))}onError(u){return this.stream.on("error",u),g.Disposable.create(()=>this.stream.off("error",u))}onEnd(u){return this.stream.on("end",u),g.Disposable.create(()=>this.stream.off("end",u))}onData(u){return this.stream.on("data",u),g.Disposable.create(()=>this.stream.off("data",u))}}class c{static{t(this,"WritableStreamWrapper")}stream;constructor(u){this.stream=u}onClose(u){return this.stream.on("close",u),g.Disposable.create(()=>this.stream.off("close",u))}onError(u){return this.stream.on("error",u),g.Disposable.create(()=>this.stream.off("error",u))}onEnd(u){return this.stream.on("end",u),g.Disposable.create(()=>this.stream.off("end",u))}write(u,M){return new Promise((S,w)=>{const _=t(m=>{m==null?S():w(m)},"callback");typeof u=="string"?this.stream.write(u,M,_):this.stream.write(u,_)})}end(){this.stream.end()}}const o=Object.freeze({crypto:Object.freeze({randomUUID:t(()=>(0,l.randomUUID)(),"randomUUID")}),messageBuffer:Object.freeze({create:t(R=>new P(R),"create")}),applicationJson:Object.freeze({encoder:Object.freeze({name:"application/json",encode:t((R,u)=>{try{return Promise.resolve(Buffer.from(JSON.stringify(R,void 0,0),u.charset))}catch(M){return Promise.reject(M)}},"encode")}),decoder:Object.freeze({name:"application/json",decode:t((R,u)=>{try{return R instanceof Buffer?Promise.resolve(JSON.parse(R.toString(u.charset))):Promise.resolve(JSON.parse(new e.TextDecoder(u.charset).decode(R)))}catch(M){return Promise.reject(M)}},"decode")})}),stream:Object.freeze({asReadableStream:t(R=>new a(R),"asReadableStream"),asWritableStream:t(R=>new c(R),"asWritableStream")}),console,timer:Object.freeze({setTimeout(R,u,...M){const S=setTimeout(R,u,...M);return{dispose:t(()=>clearTimeout(S),"dispose")}},setImmediate(R,...u){const M=setImmediate(R,...u);return{dispose:t(()=>clearImmediate(M),"dispose")}},setInterval(R,u,...M){const S=setInterval(R,u,...M);return{dispose:t(()=>clearInterval(S),"dispose")}}})});function i(){return o}return t(i,"RIL"),(function(R){function u(){g.RAL.install(o)}t(u,"install"),R.install=u})(i||(i={})),Je.default=i,Je}t(Or,"requireRil");var It;function Cr(){return It||(It=1,(function(e){var l=H&&H.__createBinding||(Object.create?(function(d,s,n,h){h===void 0&&(h=n);var v=Object.getOwnPropertyDescriptor(s,n);(!v||("get"in v?!s.__esModule:v.writable||v.configurable))&&(v={enumerable:!0,get:t(function(){return s[n]},"get")}),Object.defineProperty(d,h,v)}):(function(d,s,n,h){h===void 0&&(h=n),d[h]=s[n]})),g=H&&H.__setModuleDefault||(Object.create?(function(d,s){Object.defineProperty(d,"default",{enumerable:!0,value:s})}):function(d,s){d.default=s}),P=H&&H.__importStar||(function(){var d=t(function(s){return d=Object.getOwnPropertyNames||function(n){var h=[];for(var v in n)Object.prototype.hasOwnProperty.call(n,v)&&(h[h.length]=v);return h},d(s)},"ownKeys");return function(s){if(s&&s.__esModule)return s;var n={};if(s!=null)for(var h=d(s),v=0;v<h.length;v++)h[v]!=="default"&&l(n,s,h[v]);return g(n,s),n}})(),a=H&&H.__exportStar||function(d,s){for(var n in d)n!=="default"&&!Object.prototype.hasOwnProperty.call(s,n)&&l(s,d,n)},c=H&&H.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(e,"__esModule",{value:!0}),e.StreamMessageWriter=e.StreamMessageReader=e.SocketMessageWriter=e.SocketMessageReader=e.PortMessageWriter=e.PortMessageReader=e.IPCMessageWriter=e.IPCMessageReader=void 0,e.generateRandomPipeName=ge,e.createClientPipeTransport=oe,e.createServerPipeTransport=me,e.createClientSocketTransport=ae,e.createServerSocketTransport=ce,e.createMessageConnection=ve;const o=c(Or());o.default.install();const i=P(pr),R=P(gr),u=P(mr),M=_t,S=vr,w=tt();a(tt(),e);class _ extends w.AbstractMessageReader{static{t(this,"IPCMessageReader")}process;constructor(s){super(),this.process=s;const n=this.process;n.on("error",h=>this.fireError(h)),n.on("close",()=>this.fireClose())}listen(s){return this.process.on("message",s),w.Disposable.create(()=>this.process.off("message",s))}}e.IPCMessageReader=_;class m extends w.AbstractMessageWriter{static{t(this,"IPCMessageWriter")}process;errorCount;constructor(s){super(),this.process=s,this.errorCount=0;const n=this.process;n.on("error",h=>this.fireError(h)),n.on("close",()=>this.fireClose())}write(s){try{return typeof this.process.send=="function"&&this.process.send(s,void 0,void 0,n=>{n?(this.errorCount++,this.handleError(n,s)):this.errorCount=0}),Promise.resolve()}catch(n){return this.handleError(n,s),Promise.reject(n)}}handleError(s,n){this.errorCount++,this.fireError(s,n,this.errorCount)}end(){}}e.IPCMessageWriter=m;class p extends w.AbstractMessageReader{static{t(this,"PortMessageReader")}onData;constructor(s){super(),this.onData=new w.Emitter,s.on("close",()=>this.fireClose()),s.on("error",n=>this.fireError(n)),s.on("message",n=>{this.onData.fire(n)})}listen(s){return this.onData.event(s)}}e.PortMessageReader=p;class y extends w.AbstractMessageWriter{static{t(this,"PortMessageWriter")}port;errorCount;constructor(s){super(),this.port=s,this.errorCount=0,s.on("close",()=>this.fireClose()),s.on("error",n=>this.fireError(n))}write(s){try{return this.port.postMessage(s),Promise.resolve()}catch(n){return this.handleError(n,s),Promise.reject(n)}}handleError(s,n){this.errorCount++,this.fireError(s,n,this.errorCount)}end(){}}e.PortMessageWriter=y;class C extends w.ReadableStreamMessageReader{static{t(this,"SocketMessageReader")}constructor(s,n="utf-8"){super((0,o.default)().stream.asReadableStream(s),n)}}e.SocketMessageReader=C;class N extends w.WriteableStreamMessageWriter{static{t(this,"SocketMessageWriter")}socket;constructor(s,n){super((0,o.default)().stream.asWritableStream(s),n),this.socket=s}dispose(){super.dispose(),this.socket.destroy()}}e.SocketMessageWriter=N;class J extends w.ReadableStreamMessageReader{static{t(this,"StreamMessageReader")}constructor(s,n){super((0,o.default)().stream.asReadableStream(s),n)}}e.StreamMessageReader=J;class U extends w.WriteableStreamMessageWriter{static{t(this,"StreamMessageWriter")}constructor(s,n){super((0,o.default)().stream.asWritableStream(s),n)}}e.StreamMessageWriter=U;const ee=process.env.XDG_RUNTIME_DIR,Z=new Map([["linux",107],["darwin",102]]);function ge(){if(process.platform==="win32")return`\\\\.\\pipe\\lsp-${(0,M.randomBytes)(16).toString("hex")}-sock`;let d=32;const s=10,n=u.realpathSync(ee??R.tmpdir()),h=Z.get(process.platform);if(h!==void 0&&(d=Math.min(h-n.length-s,d)),d<16)throw new Error(`Unable to generate a random pipe name with ${d} characters.`);const v=(0,M.randomBytes)(Math.floor(d/2)).toString("hex");return i.join(n,`lsp-${v}.sock`)}t(ge,"generateRandomPipeName");function oe(d,s="utf-8"){let n;const h=new Promise((v,b)=>{n=v});return new Promise((v,b)=>{const j=(0,S.createServer)(Q=>{j.close(),n([new C(Q,s),new N(Q,s)])});j.on("error",b),j.listen(d,()=>{j.removeListener("error",b),v({onConnected:t(()=>h,"onConnected"),close:t(()=>{j.close()},"close")})})})}t(oe,"createClientPipeTransport");function me(d,s="utf-8"){const n=(0,S.createConnection)(d);return[new C(n,s),new N(n,s)]}t(me,"createServerPipeTransport");function ae(d,s="utf-8"){let n;const h=new Promise((v,b)=>{n=v});return new Promise((v,b)=>{const j=(0,S.createServer)(Q=>{j.close(),n([new C(Q,s),new N(Q,s)])});j.on("error",b),j.listen(d,"127.0.0.1",()=>{j.removeListener("error",b);const Q=j.address();if(Q===null||typeof Q=="string"){b(new Error(`Unexpected server address: ${Q}`));return}const Ke=Q.port;v({port:t(()=>Ke,"port"),onConnected:t(()=>h,"onConnected"),close:t(()=>{j.close()},"close")})})})}t(ae,"createClientSocketTransport");function ce(d,s="utf-8"){const n=(0,S.createConnection)(d,"127.0.0.1");return[new C(n,s),new N(n,s)]}t(ce,"createServerSocketTransport");function ue(d){const s=d;return s.read!==void 0&&s.addListener!==void 0}t(ue,"isReadableStream");function le(d){const s=d;return s.write!==void 0&&s.addListener!==void 0}t(le,"isWritableStream");function ve(d,s,n,h){n||(n=w.NullLogger);const v=ue(d)?new J(d):d,b=le(s)?new U(s):s;return w.ConnectionStrategy.is(h)&&(h={connectionStrategy:h}),(0,w.createMessageConnection)(v,b,n,h)}t(ve,"createMessageConnection")})(H)),H}t(Cr,"requireMain");var K=Cr();const se={Verbatim:0,Atom:1,Alias:2},Y={Definition:8,References:64,All:1048575};function Wt(e,l){return l==="utf-8"?yt.byteLength(e,"utf8"):e.length}t(Wt,"encodedLength");function Bt(e,l,g){return rt(e,l),g==="utf-8"?yt.byteLength(e.slice(0,l),"utf8"):l}t(Bt,"stringIndexToPosition");var Nr=class{static{t(this,"MappedCodeBuilder")}originalText;positionEncoding;#r=[];#e=[];#t=0;constructor(e,l={}){this.originalText=e,this.positionEncoding=l.positionEncoding??"utf-16"}get length(){return this.#t}get text(){return this.#r.join("")}append(e){return this.#n(e),this}appendVerbatim(e,l,g=Y.All){return this.appendMapped(this.originalText.slice(e,l),e,l,{kind:se.Verbatim,features:g})}appendAtom(e,l,g,P=Y.All){return this.appendMapped(e,l,g,{kind:se.Atom,features:P})}appendAlias(e,l,g,P=Y.All){return this.appendMapped(e,l,g,{kind:se.Alias,features:P})}appendAnchored(e,l,g=Y.Definition|Y.References){return this.appendAtom(e,l,l,g)}appendMapped(e,l,g,P={}){qr(this.originalText,l,g);const a=P.kind??se.Atom,c=P.features??Y.All,o=this.#t,i=Wt(e,this.positionEncoding),R=Bt(this.originalText,l,this.positionEncoding),u=Bt(this.originalText,g,this.positionEncoding);if(a===se.Verbatim&&e!==this.originalText.slice(l,g))throw new TypeError("Verbatim text must match the original source");return this.#n(e),this.#i(c===Y.All?[o,i,R,u-R,a]:[o,i,R,u-R,a,c]),this}build(e,l={}){return{text:this.text,extension:e,...this.#e.length===0?{}:{mappings:[...this.#e]},...l.diagnosticDirectives===void 0?{}:{diagnosticDirectives:l.diagnosticDirectives}}}#n(e){this.#r.push(e),this.#t+=Wt(e,this.positionEncoding)}#i(e){const l=this.#e.at(-1);if(l===void 0||!jr(l,e)){this.#e.push(e);return}const g=e[5]??Y.All;this.#e[this.#e.length-1]=g===Y.All?[l[0],l[1]+e[1],l[2],l[3]+e[3],se.Verbatim]:[l[0],l[1]+e[1],l[2],l[3]+e[3],se.Verbatim,g]}};function jr(e,l){return e[4]===se.Verbatim&&l[4]===se.Verbatim&&(e[5]??Y.All)===(l[5]??Y.All)&&e[0]+e[1]===l[0]&&e[2]+e[3]===l[2]}t(jr,"canMergeVerbatim");function qr(e,l,g){if(rt(e,l),rt(e,g),g<l)throw new RangeError("Source range end is before its start")}t(qr,"assertSourceRange");function rt(e,l){if(!Number.isSafeInteger(l)||l<0||l>e.length)throw new RangeError(`String index ${l} is out of bounds`);if(l>0&&l<e.length&&kr(e[l-1].codePointAt(0))&&Lr(e[l].codePointAt(0)))throw new RangeError(`String index ${l} splits a surrogate pair`)}t(rt,"assertStringIndex");function kr(e){return e>=55296&&e<=56319}t(kr,"isHighSurrogate");function Lr(e){return e>=56320&&e<=57343}t(Lr,"isLowSurrogate");function Dr(e,l={}){const g=K.createMessageConnection(l.input??fr,l.output??dr),P=new Map;let a;const c=new K.RequestType("initialize"),o=new K.RequestType("openProject"),i=new K.RequestType("transform"),R=new K.RequestType("closeProject");return g.onRequest(c,u=>{const M=Ar(u.positionEncodings,e.positionEncoding);return a={positionEncoding:M,locale:u.locale},{positionEncoding:M,diagnosticSource:e.diagnosticSource}}),g.onRequest(o,(u,M)=>it(M,async S=>{const w=$r(nt(a),S),{project:_,...m}=e.openProject?await e.openProject(u,w):{};return P.set(u.projectHandle,{project:_,params:u}),m})),g.onRequest(i,(u,M)=>it(M,S=>{const w=zt(P,u.projectHandle);return e.transform(u,Vt(nt(a),w,S))})),g.onRequest(R,(u,M)=>it(M,async S=>{const w=zt(P,u.projectHandle);try{await e.closeProject?.(u,Vt(nt(a),w,S))}finally{P.delete(u.projectHandle)}return null})),g.listen(),{dispose(){P.clear(),g.dispose()}}}t(Dr,"runContentMapper");function Ar(e,l){if(l!==void 0){if(e.includes(l))return l;throw new K.ResponseError(K.ErrorCodes.InvalidParams,`The host did not offer ${JSON.stringify(l)} position encoding`)}if(e.includes("utf-16"))return"utf-16";if(e.includes("utf-8"))return"utf-8";throw new K.ResponseError(K.ErrorCodes.InvalidParams,"The host did not offer a supported position encoding")}t(Ar,"selectPositionEncoding");function nt(e){if(e===void 0)throw new K.ResponseError(K.ErrorCodes.InvalidRequest,"The content mapper has not been initialized");return e}t(nt,"requireSession");function zt(e,l){const g=e.get(l);if(g===void 0)throw new K.ResponseError(K.ErrorCodes.InvalidParams,`Unknown project handle ${JSON.stringify(l)}`);return g}t(zt,"requireProject");function $r(e,l){return{...e,signal:l}}t($r,"createContext");function Vt(e,l,g){return{...e,signal:g,project:l.project,openProjectParams:l.params}}t(Vt,"createProjectContext");async function it(e,l){const g=new AbortController;e.isCancellationRequested&&g.abort();const P=e.onCancellationRequested(()=>g.abort());try{return await l(g.signal)}finally{P.dispose()}}t(it,"withCancellation");const Ut=["declare global {"," var block: typeof import('mdeval').block;"," var $: typeof import('mdeval').$;","}"].join(`
|
|
8
|
+
`),Ir={extension:".mts",preamble:"",declarations:[Ut,"declare const __mdeval_guard: <T>(value: T) => T;"],supplemental:void 0},Wr={extension:".mjs",preamble:`// @ts-check
|
|
9
|
+
`,declarations:["/** @type {<T>(value: T) => T} */ const __mdeval_guard = value => value;"],supplemental:[{text:`export {};
|
|
10
|
+
${Ut}
|
|
11
|
+
`,extension:".mts"}]},Br=t(e=>{try{return ur.realpathSync(e)}catch{return e}},"resolveRealPath");Dr({diagnosticSource:"mdeval",positionEncoding:"utf-16",openProject:t(({compilerOptions:e})=>({project:e.preserveSymlinks===!0}),"openProject"),transform:t(({content:e,fileName:l},{project:g})=>{const P=g?l:Br(l),a=yr.test(lr(P).href)?Wr:Ir;let c;try{c=_r(e)}catch(i){if(!(i instanceof br))throw i;return{text:`${a.preamble}export {};
|
|
12
|
+
`,extension:a.extension,diagnostics:[{messageText:i.message,start:i.offset,length:wr.length,code:1}]}}const o=new Nr(e);o.append(a.preamble);for(const{text:i,sourceOffset:R}of c)R===void 0?o.append(i):o.appendVerbatim(R,R+i.length);return o.append(["","export {};",...a.declarations,""].join(`
|
|
13
|
+
`)),{...o.build(a.extension),supplemental:a.supplemental}},"transform")});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var R=Object.defineProperty;var n=(t,u)=>R(t,"name",{value:u,configurable:!0});import k from"node:module";import{block as B}from"./runtime.mjs";import F,{realpathSync as j}from"node:fs";import{pathToFileURL as E,fileURLToPath as U}from"node:url";import{g as W,n as _}from"./node-modules-Bw1ALrxb.mjs";import{GenMapping as D,toEncodedMap as H,addSegment as N}from"@jridgewell/gen-mapping";import{types as x}from"node:util";import{$ as z}from"zx";const $=10,A=13,G=n(t=>t>=48&&t<=57||t>=65&&t<=90||t===95||t>=97&&t<=122||t===36,"isIdentifierCode"),J=n((t,u)=>{const M=E(t).href,m=new D({file:t}),c=[];let l="";const s=[];for(let e=u.indexOf(`
|
|
2
|
+
`);e!==-1;e=u.indexOf(`
|
|
3
|
+
`,e+1))s.push(e);const S=n(e=>{let o=0,r=s.length;for(;o<r;){const d=Math.floor((o+r)/2);s[d]<e?o=d+1:r=d}const h=o>0?s[o-1]:-1;return{line:o,column:e-h-1}},"positionFromOffset"),a=n(e=>{l+=e},"appendLineChunk"),f=n(()=>{c.push(l),l=""},"flushLine"),p=n((e,o)=>{const r=S(o);let h=r.line,d=r.column,L=!1,w=!1,y=0;const P=n(i=>l.length+i-y,"generatedColumn");for(let i=0;i<e.length;i+=1){const g=e.codePointAt(i),O=g===32||g>=9&&g<=A,T=G(g);!O&&(i===0||w||!L||!T)&&N(m,c.length,P(i),M,h,d),g===$?(h+=1,d=0):d+=1,L=T,w=O,g===$&&(a(e.slice(y,i)),f(),y=i+1)}y<e.length&&a(e.slice(y))},"appendSourceText"),I=n(e=>{let o=0;for(let r=e.indexOf(`
|
|
4
|
+
`);r!==-1;r=e.indexOf(`
|
|
5
|
+
`,o))a(e.slice(o,r)),f(),o=r+1;o<e.length&&a(e.slice(o))},"appendSyntheticText");return{appendSource:n((e,o)=>{p(e,o)},"appendSource"),appendSynthetic:n(e=>{I(e)},"appendSynthetic"),toModuleSource:n(()=>{const o=`${(l===""?c:[...c,l]).join(`
|
|
6
|
+
`)}
|
|
7
|
+
`,r=H(m),h=`//# sourceMappingURL=data:application/json;base64,${Buffer.from(JSON.stringify(r)).toString("base64")}`;return`${o}${h}
|
|
8
|
+
`},"toModuleSource")}},"createSourceBuilder"),b=new Map,v=n(t=>{try{return j.native(U(t))}catch{return t}},"handoffKey"),K=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),q=n((t,u,M)=>{const m=new URL(t);if(m.protocol!=="file:"||!m.pathname.endsWith(".md"))return M(t,u);const c=U(m),l=F.readFileSync(c);let s;try{s=K.decode(l)}catch{throw new Error(`${c}: not valid UTF-8`)}let S;if(b.size>0){const f=v(t),p=b.get(f);b.delete(f),p?.source===s&&(S=p.parsed)}const a=J(c,s);for(const{text:f,sourceOffset:p}of W(s,S))p===void 0?a.appendSynthetic(f):a.appendSource(f,p);return{format:_.test(t)?"module":"module-typescript",source:a.toModuleSource(),shortCircuit:!0}},"load"),{then:Q}=Promise.prototype,C=n(()=>{},"noop"),V=n(t=>(x.isPromise(t)&&Q.call(t,C,C),t),"guardMarker");Object.assign(globalThis,{block:B,$:z}),Object.defineProperty(globalThis,"__mdeval_guard",{value:V,writable:!0,configurable:!0}),process.setSourceMapsEnabled(!0),k.registerHooks({load:q});export{v as h,b as p};
|
package/dist/loader.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import{register as r}from"node:module";import{block as o}from"./runtime.mjs";import{$ as e}from"zx";Object.assign(globalThis,{block:o,$:e}),process.setSourceMapsEnabled(!0),r("#md-loader",import.meta.url);
|
|
1
|
+
import"node:module";import"./runtime.mjs";import"./loader-D40biTy7.mjs";import"zx";import"node:fs";import"node:url";import"./node-modules-Bw1ALrxb.mjs";import"micromark";import"micromark-extension-gfm-table";import"@jridgewell/gen-mapping";import"node:util";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var S=Object.defineProperty;var p=(e,s)=>S(e,"name",{value:s,configurable:!0});import{postprocess as y,parse as _,preprocess as I}from"micromark";import{gfmTable as T}from"micromark-extension-gfm-table";class b extends Error{static{p(this,"MarkdownParseError")}offset;constructor(s,c){super(s),this.offset=c}}const O="mdeval",u=`<!--${O}`,M=`${u} `,E=`<!--/${O}-->`,d=`__${O}_`,k="-->",R=p(e=>{const s=new Map;for(const{expression:c}of e)s.has(c)||s.set(c,s.size);return s},"buildExpressionMap"),A=new Set(["codeFenced","codeIndented","codeText"]),P=p(e=>{const s=e.codePointAt(0)===65279?1:0,c=y(_({extensions:[T()]}).document().write(I()(e,void 0,!0))),o=[],a=[];let i=0,t=0,n=!1;for(const[r,l]of c){if(n){r==="exit"&&l.type==="tableData"&&(n=!1);continue}if(r==="enter"){switch((l.type==="tableHeader"||l.type==="tableData")&&a.push([l.start.offset+s,l.end.offset+s]),l.type){case"table":{i=0;break}case"tableRow":{t=0;break}case"tableHeader":{i+=1;break}case"tableData":{if(t+=1,t>i){o.push([l.start.offset+s,l.end.offset+s]),n=!0;continue}break}}(A.has(l.type)||l.type==="characterEscape"&&e[l.end.offset+s-1]==="<")&&o.push([l.start.offset+s,l.end.offset+s])}}return{ranges:o,cells:a}},"findCodeRanges"),N=p(e=>{let s=null,c=0,o=0;return{context:p(t=>{s===null&&(s=P(e));const{ranges:n,cells:r}=s;for(;c<n.length&&n[c][1]<=t;)c+=1;if(c<n.length&&t>=n[c][0])return{literal:!0,cellEnd:void 0};for(;o<r.length&&r[o][1]<=t;)o+=1;return{literal:!1,cellEnd:o<r.length&&t>=r[o][0]?r[o][1]:void 0}},"context"),isInCode:p(t=>{const{ranges:n}=s;let r=0,l=n.length;for(;r<l;){const $=Math.floor((r+l)/2);n[$][1]<=t?r=$+1:l=$}return r<n.length&&n[r][0]<=t},"isInCode")}},"createIsInCode"),w=p((e,s)=>{let c=s;for(;c<e.length;){const o=e.indexOf(u,c);if(o===-1)return-1;const a=e[o+u.length];if(a===" "||a===`
|
|
2
|
+
`||a==="\r"&&e[o+u.length+1]===`
|
|
3
|
+
`)return o;c=o+u.length}return-1},"findNextMdevalOpening"),C=p(e=>{if(!e.includes(u))return{scriptBlocks:[],markers:[]};const{context:s,isInCode:c}=N(e),o=[],a=[];let i=0;for(;i<e.length;){const t=w(e,i);if(t===-1)break;const n=t+u.length,r=e[n],{literal:l,cellEnd:$}=s(t);if(l){i=n;continue}if($!==void 0){const h=e.slice(t,$),f=h.indexOf(k,u.length),g=f===-1?-1:h.indexOf(E,f+k.length);if(r!==" "||g===-1||c(t+g)){i=n;continue}const m=w(h,f+k.length);if(m!==-1&&m<g)throw new b(`mdeval: unclosed marker open at offset ${t} (missing \`<!--/mdeval-->\`)`,t);const x=t+g+E.length;a.push({expression:h.slice(u.length+1,f),start:t,end:x}),i=x;continue}if(r===`
|
|
4
|
+
`||r==="\r"&&e[n+1]===`
|
|
5
|
+
`){const h=r===`
|
|
6
|
+
`?n+1:n+2,f=e.indexOf(k,h),g=w(e,h),m=g!==-1&&(f===-1||g<f);if(f===-1||m)throw new b(m?`mdeval: unclosed script block at offset ${t} (another mdeval opening found before \`-->\`)`:`mdeval: unclosed script block at offset ${t} (missing \`-->\`)`,t);const x=f+k.length;o.push({content:e.slice(h,f),contentStart:h,start:t,end:x}),i=x;continue}if(r===" "){const h=n+1,f=e.indexOf(k,h);if(f===-1)throw new b(`mdeval: unclosed marker open at offset ${t} (missing \`-->\` on the marker open)`,t);const g=f+k.length,m=e.indexOf(E,g),x=w(e,g);if(m===-1||x!==-1&&x<m)throw new b(`mdeval: unclosed marker open at offset ${t} (missing \`<!--/mdeval-->\`)`,t);const v=m+E.length;a.push({expression:e.slice(h,f),start:t,end:v}),i=v;continue}}return{scriptBlocks:o,markers:a}},"parseMarkdown"),D=p((e,{scriptBlocks:s,markers:c})=>{if(s.length===0||c.length>0)return!1;let o=0;for(const a of s){if(e.slice(o,a.start).trim()!=="")return!1;o=a.end}return e.slice(o).trim()===""},"isOnlyMdeval"),F=p((e,s=C(e))=>{const{scriptBlocks:c,markers:o}=s,a=[];for(const n of c)a.push({text:n.content,sourceOffset:n.contentStart}),n.content.endsWith(`
|
|
7
|
+
`)||a.push({text:`
|
|
8
|
+
`});if(o.length===0)return a;const i=new Set;a.push({text:`const ${d}run = async () => {
|
|
9
|
+
`});for(const n of o){if(i.has(n.expression))continue;const r=`${d}${i.size}`;a.push({text:`const ${r} = ${d}guard((void 0,
|
|
10
|
+
`},{text:n.expression,sourceOffset:n.start+M.length},{text:`
|
|
11
|
+
));
|
|
12
|
+
`}),i.add(n.expression)}const t=Array.from(i,(n,r)=>`${d}${r}`);return a.push({text:`return [${t.join(", ")}];
|
|
13
|
+
};
|
|
14
|
+
let ${d}get = ${d}run;
|
|
15
|
+
export const ${d}markers = () => {
|
|
16
|
+
const ${d}promise = ${d}get();
|
|
17
|
+
${d}get = () => ${d}promise;
|
|
18
|
+
return ${d}promise;
|
|
19
|
+
};
|
|
20
|
+
`}),a},"generateModule"),z=/[\\/]node_modules[\\/]/;export{u as C,d as E,M,E as a,R as b,k as c,b as d,F as g,D as i,z as n,C as p};
|
package/dist/runtime.mjs
CHANGED
package/docs/node.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Node.js usage
|
|
2
|
+
|
|
3
|
+
`.md` files with mdeval script blocks are ES modules. A Node.js script can import their exports, which is useful for validation tools, migrations, or any code that reads data from a Markdown knowledge base.
|
|
4
|
+
|
|
5
|
+
## Import `.md` files
|
|
6
|
+
|
|
7
|
+
Run the script with the mdeval loader:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
node --import mdeval/loader ./script.js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The script can then use ordinary static imports of `.md` files:
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
// script.js
|
|
17
|
+
import { contacts } from './CONTACTS.md'
|
|
18
|
+
|
|
19
|
+
console.log(contacts)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`--import mdeval/loader` registers the loader before the script's imports are resolved, so static imports of `.md` files work. Without it, Node.js cannot load `.md` files. The loader also defines the `block` and `$` helpers as globals, which mdeval code in `.md` files expects.
|
|
23
|
+
|
|
24
|
+
Importing a `.md` file runs only its script blocks, not its markers, and does not change the file.
|
|
25
|
+
|
|
26
|
+
## TypeScript scripts
|
|
27
|
+
|
|
28
|
+
The script can be TypeScript, because Node.js strips types from `.ts` files:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
node --import mdeval/loader ./script.ts
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
With [type checking](./type-checking.md) set up and the script in `include`, `tsc` checks the script against the types of the `.md` exports.
|
|
35
|
+
|
|
36
|
+
## Run a `.md` file directly
|
|
37
|
+
|
|
38
|
+
The loader can also run a `.md` file's script blocks:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
node --import mdeval/loader ./TODOS.md
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Helpers without the loader
|
|
45
|
+
|
|
46
|
+
`import { block, $ } from 'mdeval'` returns the helpers without side effects: it neither defines globals nor registers the loader. In `.js` and `.ts` files, prefer this import over the globals, which exist only when the loader or the CLI defined them.
|
|
47
|
+
|
|
48
|
+
## Stack traces
|
|
49
|
+
|
|
50
|
+
The loader enables source maps, so runtime errors from a `.md` file report its original lines and columns.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Type checking
|
|
2
|
+
|
|
3
|
+
TypeScript 7.1 can check the code inside mdeval comments and report errors at their original Markdown lines. Checking does not run the code.
|
|
4
|
+
|
|
5
|
+
- Script blocks in a file share one module scope, and imports resolve relative to the Markdown file.
|
|
6
|
+
- A marker expression that appears more than once is checked once, and its errors point to the first occurrence.
|
|
7
|
+
- The `block` and `$` helpers are available without imports. Explicit imports also work.
|
|
8
|
+
- Fenced code blocks, inline code, and the rendered values between markers are not checked.
|
|
9
|
+
|
|
10
|
+
## Setup
|
|
11
|
+
|
|
12
|
+
Install the TypeScript 7.1 beta:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install --save-dev typescript@7.1.0-beta
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Register mdeval as the content mapper for `.md` files in `tsconfig.json`, and include the Markdown files to check:
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"compilerOptions": {
|
|
23
|
+
"module": "nodenext",
|
|
24
|
+
"target": "esnext",
|
|
25
|
+
"strict": true,
|
|
26
|
+
"erasableSyntaxOnly": true,
|
|
27
|
+
"noEmit": true
|
|
28
|
+
},
|
|
29
|
+
"contentMappers": [
|
|
30
|
+
{
|
|
31
|
+
"package": "mdeval",
|
|
32
|
+
"extensions": [
|
|
33
|
+
".md"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"include": [
|
|
38
|
+
"README.md",
|
|
39
|
+
"docs/**/*.md"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Run the compiler. `--runExternalCode` allows `tsc` to start mdeval's mapper:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
npx tsc --noEmit --runExternalCode
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For example, this reports an error on `toUpperCase`, because `count` is a number:
|
|
51
|
+
|
|
52
|
+
```markdown
|
|
53
|
+
<!--mdeval
|
|
54
|
+
const count: number = 42;
|
|
55
|
+
-->
|
|
56
|
+
|
|
57
|
+
Count: <!--mdeval count.toUpperCase()-->42<!--/mdeval-->
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## TypeScript rules
|
|
61
|
+
|
|
62
|
+
mdeval checks Markdown outside `node_modules` as a TypeScript module, so JSDoc type annotations there are not checked. Markdown under `node_modules` is checked as JavaScript because Node runs it as JavaScript. `erasableSyntaxOnly` reports syntax that fails at runtime, such as `enum`, at its Markdown line.
|
|
63
|
+
|
|
64
|
+
Marker expressions are checked inside a function, so TypeScript does not narrow a script-block `let` reassigned by another function. For example, after `let x: string | number = 0; const set = () => { x = "a"; };`, a marker containing `(set(), x.toFixed())` is still checked against `string | number`. Names beginning with `__mdeval_` are reserved for generated code.
|
|
65
|
+
|
|
66
|
+
A `.ts` file that imports a `.md` file is checked against the types of its exports when the `.ts` file is in `include`. See [Node.js usage](./node.md).
|
|
67
|
+
|
|
68
|
+
A namespace import of a `.md` file without exports, such as `import * as data from './stub.md'`, reports `data.version` as missing, even though it is `undefined` at runtime. Cast the namespace to the shape you expect: `const data = stub as { version?: string }`.
|
|
69
|
+
|
|
70
|
+
## Limitations
|
|
71
|
+
|
|
72
|
+
Set TypeScript's `preserveSymlinks` to match Node's `--preserve-symlinks` when checking symlinked Markdown. This only helps when TypeScript and Node reach the file through the same path; a `paths` alias that points at a workspace package's real folder, while Node loads it through `node_modules`, still disagrees. In a pnpm layout, preserving symlinks can break dependency resolution for both Node and TypeScript, depending on where dependencies are placed, so the option mostly suits npm and Yarn workspaces. This is only a partial fix: Node's `--preserve-symlinks-main` controls the entry point separately, while TypeScript has one project-wide setting that cannot represent both independently.
|
|
73
|
+
|
|
74
|
+
The helper types are visible throughout the TypeScript program, including `.ts` and `.js` files outside Markdown. This matches runtime: the CLI and `mdeval/loader` assign the helpers to `globalThis`, so every module in that process can use them, including `.ts` files your Markdown imports. The types are too permissive only for code that also runs without the loader, where `block` and `$` are `undefined`. Import the helpers in such code, or check Markdown under its own tsconfig so the rest of the project does not see these globals. A conflicting global `block` or `$`, including full zx's globals, can cause TS2403. With `skipLibCheck`, the first declaration TypeScript checks determines the type, and a conflicting later `.d.ts` declaration can be skipped. For example, with `a.md`, `globals.d.ts`, and `b.md` in that order, the first Markdown declaration establishes the type and no TS2403 is reported for the skipped `.d.ts` conflict. Check Markdown with a separate `tsconfig.json` that excludes the conflicting declaration from all loaded files, including root files, the import graph, and `compilerOptions.types`, even when inherited through `extends` (for example, `zx/globals`).
|
|
75
|
+
|
|
76
|
+
The content mapper API in TypeScript 7.1 is experimental. This integration is tested with `typescript@7.1.0-beta`. Whether an editor checks Markdown depends on its TypeScript integration; the configuration above enables command-line checking.
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdeval",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Evaluate JavaScript in markdown HTML comments and interpolate results in-place",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Evaluate JavaScript or TypeScript in markdown HTML comments and interpolate results in-place",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
7
7
|
"eval",
|
|
8
8
|
"interpolation",
|
|
9
9
|
"dynamic",
|
|
10
|
-
"readme"
|
|
10
|
+
"readme",
|
|
11
|
+
"typescript"
|
|
11
12
|
],
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"repository": "privatenumber/mdeval",
|
|
@@ -17,25 +18,51 @@
|
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
21
|
+
"docs",
|
|
20
22
|
"skills"
|
|
21
23
|
],
|
|
22
24
|
"type": "module",
|
|
23
25
|
"bin": "./dist/cli.mjs",
|
|
24
26
|
"exports": {
|
|
25
|
-
".":
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/runtime.d.mts",
|
|
29
|
+
"default": "./dist/runtime.mjs"
|
|
30
|
+
},
|
|
26
31
|
"./loader": "./dist/loader.mjs"
|
|
27
32
|
},
|
|
28
33
|
"imports": {
|
|
29
|
-
"#
|
|
34
|
+
"#content-mapper": "./dist/content-mapper.mjs"
|
|
30
35
|
},
|
|
31
36
|
"engines": {
|
|
32
|
-
"node": ">=
|
|
37
|
+
"node": "^22.21.1 || >=24.11.0"
|
|
33
38
|
},
|
|
34
39
|
"dependencies": {
|
|
35
40
|
"@jridgewell/gen-mapping": "^0.3.13",
|
|
41
|
+
"@types/fs-extra": "^11.0.4",
|
|
36
42
|
"cleye": "^2.3.0",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
43
|
+
"mdast-util-from-markdown": "^2.1.0",
|
|
44
|
+
"mdast-util-gfm-footnote": "^2.1.0",
|
|
45
|
+
"mdast-util-gfm-table": "^2.0.1",
|
|
46
|
+
"mdast-util-to-hast": "^13.2.1",
|
|
47
|
+
"micromark": "^4.0.3",
|
|
48
|
+
"micromark-extension-gfm-footnote": "^2.1.0",
|
|
49
|
+
"micromark-extension-gfm-table": "^2.1.2",
|
|
50
|
+
"parse5": "^8.1.0",
|
|
51
|
+
"picomatch": "^4.0.4",
|
|
52
|
+
"tinyglobby": "^0.2.17",
|
|
53
|
+
"unist-util-visit-parents": "^6.1.0",
|
|
39
54
|
"zx": "8.8.5-lite"
|
|
55
|
+
},
|
|
56
|
+
"typescript": {
|
|
57
|
+
"contentMapper": {
|
|
58
|
+
"compilerOptions": [
|
|
59
|
+
"preserveSymlinks"
|
|
60
|
+
],
|
|
61
|
+
"exec": [
|
|
62
|
+
"node",
|
|
63
|
+
"--no-preserve-symlinks",
|
|
64
|
+
"dist/content-mapper.mjs"
|
|
65
|
+
]
|
|
66
|
+
}
|
|
40
67
|
}
|
|
41
68
|
}
|