jitar 0.11.3 → 0.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jitar",
3
- "version": "0.11.3",
3
+ "version": "0.12.1",
4
4
  "description": "Distributed runtime for JavaScript and TypeScript to chop monolithic applications into micros.",
5
5
  "author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
6
6
  "license": "MIT",
@@ -23,15 +23,15 @@
23
23
  "lint": "eslint",
24
24
  "validate": "tsc -p tsconfig.json --noEmit",
25
25
  "build": "npm run clean && npm run bundle && npm run copy && npm run finalize",
26
- "clean": "rimraf dist",
26
+ "clean": "shx rm -rf dist",
27
27
  "bundle": "rollup -c",
28
- "copy": "cp -R ../init/templates dist/templates",
29
- "finalize": "chmod +x dist/cli.js",
28
+ "copy": "shx cp -R ../init/templates dist/templates",
29
+ "finalize": "shx chmod +x dist/cli.js",
30
30
  "prepublishOnly": "npm run clean && npm run build"
31
31
  },
32
32
  "dependencies": {
33
- "dotenv": "17.4.2",
34
- "express": "5.2.1",
33
+ "dotenv": "18.0.8",
34
+ "express": "5.3.0",
35
35
  "glob": "13.0.6",
36
36
  "mime-types": "3.0.2"
37
37
  },
@@ -44,15 +44,15 @@
44
44
  "@jitar/logging": "*",
45
45
  "@jitar/middleware": "*",
46
46
  "@jitar/runtime": "*",
47
- "@rollup/plugin-node-resolve": "16.0.3",
48
- "@rollup/plugin-replace": "6.0.3",
49
- "@rollup/plugin-terser": "1.0.0",
50
- "@rollup/plugin-typescript": "12.3.0",
51
- "rollup": "4.62.2",
52
- "rollup-plugin-dts": "6.4.1"
47
+ "@rollup/plugin-node-resolve": "^16.0.3",
48
+ "@rollup/plugin-replace": "^6.0.3",
49
+ "@rollup/plugin-terser": "^1.0.0",
50
+ "@rollup/plugin-typescript": "^12.3.0",
51
+ "rollup": "^4.64.10",
52
+ "rollup-plugin-dts": "^6.5.1"
53
53
  },
54
54
  "engines": {
55
- "node": ">=20.0"
55
+ "node": ">=22"
56
56
  },
57
57
  "repository": {
58
58
  "type": "git",
@@ -1 +0,0 @@
1
- import e,{promises as t}from"node:fs";import s from"node:path";import{glob as r}from"glob";import i from"mime-types";import n from"dotenv";const o={MODULE_PATTERN:"**/*.js",RESOURCE_PATTERN:"**/*.json",SEGMENT_PATTERN:"**/*.json"};class a extends Error{constructor(e){super(`Invalid location '${e}'`)}}class c extends Error{constructor(e){super(`File could not be found from '${e}'`)}}class u{#e;#t;#s;constructor(e,t,s){this.#e=e,this.#t=t,this.#s=s}get location(){return this.#e}get type(){return this.#t}get content(){return this.#s}get size(){return this.#s.length}}class l{#e;#r;#i;constructor(e,t){const s=t.resolve(e);this.#e=t.normalize(e),this.#r=t.normalize(s),this.#i=t}getAbsoluteLocation(e){const t=this.#i.isAbsolute(e)?e:this.#i.join(this.#e,e),s=this.#i.resolve(t),r=this.#i.normalize(s);return this.#n(r,e),r}getRelativeLocation(e){const t=this.#i.relative(this.#e,e);return this.#i.normalize(t)}normalizeLocation(e){return this.#i.normalize(e)}async getType(e){const t=this.getAbsoluteLocation(e);return await this.#i.mimeType(t)??"application/octet-stream"}async getContent(e){const t=this.getAbsoluteLocation(e);if(!1===await this.#i.exists(t))throw new c(e);return this.#i.read(t)}async exists(e){const t=this.getAbsoluteLocation(e);return this.#i.exists(t)}isDirectory(e){const t=this.getAbsoluteLocation(e);return this.#i.isDirectory(t)}async read(e){const t=this.getAbsoluteLocation(e),s=await this.getType(t),r=await this.getContent(t);return new u(e,s,r)}async write(e,t){const s=this.getAbsoluteLocation(e);return this.#i.write(s,t)}async copy(e,t){const s=this.getAbsoluteLocation(e),r=this.getAbsoluteLocation(t);return this.#i.copy(s,r)}async delete(e){const t=this.getAbsoluteLocation(e);return this.#i.delete(t)}async filter(e){const t=this.getAbsoluteLocation("./"),s=this.#i.normalize(e);return(await this.#i.filter(t,s)).map(e=>this.#i.normalize(e))}async filterWithIgnores(e,t){const s=await this.filter(e),r=t.map(e=>this.filter(e)),i=await Promise.all(r),n=new Set(i.flat());return s.filter(e=>!1===n.has(e))}#n(e,t){if(!1===e.startsWith(this.#r))throw new a(t)}}class h{copy(e,s){return t.cp(e,s,{recursive:!0,force:!0})}delete(e){return t.rm(e,{recursive:!0,force:!0})}async exists(e){try{return await t.stat(e),!0}catch{return!1}}isAbsolute(e){return s.isAbsolute(e)}isDirectory(t){try{return e.statSync(t).isDirectory()}catch{return!1}}filter(e,t){return r(`${e}/${t}`)}join(...e){return s.join(...e)}read(e){return t.readFile(e)}resolve(e){return s.resolve(e)}relative(e,t){return s.relative(e,t)}normalize(e){return e.replaceAll(s.win32.sep,s.posix.sep)}async mimeType(e){const t=i.lookup(e);if(!1!==t)return t}async write(r,i){const n=s.dirname(r);return e.mkdirSync(n,{recursive:!0}),t.writeFile(r,i)}}class p extends l{constructor(e){super(e,new h)}}class m{#o;#a;#c;constructor(e,t,s){this.#o=e,this.#a=t,this.#c=s}get resources(){return this.#a}get repository(){return this.#o}get segmentation(){return this.#c}}class d{#a;constructor(e){this.#a=e}isResourceModule(e){return this.#a.includes(e)}}const f="private",g="0.0.0",E="index.js",w=".json",y="default";class b{#u=0;next(){return"$"+ ++this.#u}}const S="js",I=/\.js$/,A=[".","/","http:","https:"];class T{translatePath(e){const t=e.split("/"),s=[];for(const e of t){switch(e.trim()){case"":case".":continue;case"..":s.pop();continue}s.push(e)}return s.join("/")}makePathRelative(e,t){if(""===t)return`./${e}`;const s=e.split("/"),r=t.split("/");for(;s[0]===r[0];)s.shift(),r.shift();const i=r.map(()=>"..").join("/");return`${r.length>0?i:"."}/${s.join("/")}`}makePathAbsolute(e,t,s="/"){const r=""!==t?`${t}/${e}`:e;return`${s}${this.translatePath(r)}`}extractPath(e){return e.split("/").slice(0,-1).join("/")}extractFilename(e){return e.split("/").pop()}assureExtension(e){return e.endsWith(`.${S}`)?e:`${e}.${S}`}addSubExtension(e,t){return e.replace(I,`.${t}.${S}`)}isApplicationModule(e){return A.some(t=>e.startsWith(t))}}class v extends Error{constructor(e,t){super(`Failed reading resources from '${e}'`,{cause:t})}}class O{#l;#h;#p=new T;constructor(e,t){this.#l=e,this.#h=t}async readAll(e){const t=await Promise.all(e.map(e=>this.#m(e)));return new d(t.flat())}async#m(e){try{const t=await this.#l.getContent(e);return JSON.parse(t.toString()).map(e=>this.#d(e))}catch(t){throw new v(e,t)}}#d(e){const t=this.#h.normalizeLocation(e),s=this.#h.isDirectory(t)?`${t}/${E}`:this.#p.assureExtension(t);return s.startsWith("./")?s.substring(2):s.startsWith("/")?s.substring(1):s}}let N=class{#f;#g;constructor(e,t){this.#f=e,this.#g=t}get filename(){return this.#f}get model(){return this.#g}};class R{#E;constructor(e){this.#E=e}get modules(){return this.#E}get(e){return this.#E.find(t=>t.filename===e)}}class x{}class M extends x{elements;constructor(e){super(),this.elements=e}clone(){const e=this.elements.map(e=>e.clone());return new M(e)}toString(){return`[${this.elements.map(e=>e.toString()).join(",")}]`}}class ${}class C extends ${identifier;constructor(e){super(),this.identifier=e}is(e){return this.identifier===e}}class P extends C{parameters;body;isAsync;constructor(e,t,s,r=!1){super(e),this.parameters=t,this.body=s,this.isAsync=r}clone(){const e=this.parameters.map(e=>e.clone()),t=this.body.clone();return new P(this.identifier,e,t,this.isAsync)}toString(){const e=this.isAsync?"async ":"",t=this.identifier?` ${this.identifier}`:"",s=this.parameters.map(e=>e.toString()),r=this.body.toString();return`${e}function${t}(${s.join(",")})${r}`}}class L extends P{constructor(e,t,s=!1){super(void 0,e,t,s)}clone(){const e=this.parameters.map(e=>e.clone()),t=this.body.clone();return new L(e,t,this.isAsync)}toString(){const e=this.isAsync?"async ":"",t=this.parameters.map(e=>e.toString()),s=this.body.toString();return`${e}(${t.join(", ")})=>${s}`}}class F{binding;initializer;constructor(e,t){this.binding=e,this.initializer=t}clone(){const e=this.binding.clone(),t=this.initializer?.clone();return new F(e,t)}toString(){return`${this.binding.toString()}${void 0!==this.initializer?`=${this.initializer.toString(!1)}`:""}`}}class V extends ${code;constructor(e){super(),this.code=e}clone(){return new V(this.code)}toString(){return this.code}}class D{identifier;visibility;location;constructor(e,t,s){this.identifier=e,this.visibility=t,this.location=s}is(e){return this.identifier===e}}class j extends D{parameters;body;constructor(e,t){super("constructor","public","instance"),this.parameters=e,this.body=t}clone(){const e=this.parameters.map(e=>e.clone()),t=this.body.clone();return new j(e,t)}toString(){const e=this.parameters.map(e=>e.toString()),t=this.body.toString();return`${this.identifier}(${e.join(",")}) ${t}`}}class k extends D{body;constructor(e,t,s,r){super(e,t,s),this.body=r}clone(){const e=this.body.clone();return new k(this.identifier,this.visibility,this.location,e)}toString(){const e="static"===this.location?"static ":"",t="private"===this.visibility?"#":"",s=this.body.toString();return`${e}get ${t}${this.identifier}()${s}`}}class B extends D{parameter;body;constructor(e,t,s,r,i){super(e,t,s),this.parameter=r,this.body=i}clone(){const e=this.parameter.clone(),t=this.body.clone();return new B(this.identifier,this.visibility,this.location,e,t)}toString(){const e="static"===this.location?"static ":"",t="private"===this.visibility?"#":"",s=this.parameter.toString(),r=this.body.toString();return`${e}set ${t}${this.identifier}(${s})${r}`}}class q extends D{parameters;body;isAsync;constructor(e,t,s,r,i,n=!1){super(e,t,s),this.parameters=r,this.body=i,this.isAsync=n}clone(){const e=this.parameters.map(e=>e.clone()),t=this.body.clone();return new q(this.identifier,this.visibility,this.location,e,t,this.isAsync)}toString(){const e="static"===this.location?"static ":"",t="private"===this.visibility?"#":"",s=this.isAsync?"async ":"",r=this.parameters.map(e=>e.toString()),i=this.body.toString();return`${e}${s}${t}${this.identifier}(${r.join(",")})${i}`}}class U extends D{initializer;constructor(e,t,s,r){super(e,t,s),this.initializer=r}clone(){const e=this.initializer?.clone();return new U(this.identifier,this.visibility,this.location,e)}toString(){const e="static"===this.location?"static ":"",t="private"===this.visibility?"#":"",s=void 0!==this.initializer?`=${this.initializer.toString(!0)}`:";";return`${e}${t}${this.identifier}${s}`}}class G extends C{parent;members;constructor(e,t,s){super(e),this.parent=t,this.members=s}get construct(){return this.members.find(e=>e instanceof j)}get fields(){return this.members.filter(e=>e instanceof U)}get getters(){return this.members.filter(e=>e instanceof k)}get setters(){return this.members.filter(e=>e instanceof B)}get methods(){return this.members.filter(e=>e instanceof q)}get publicFields(){return this.fields.filter(e=>"public"===e.visibility)}get publicGetters(){return this.getters.filter(e=>"public"===e.visibility)}get publicSetters(){return this.setters.filter(e=>"public"===e.visibility)}get publicMethods(){return this.methods.filter(e=>"public"===e.visibility)}get readable(){return[...this.publicFields,...this.publicGetters]}get writable(){return[...this.publicFields,...this.publicSetters]}getMember(e){return this.members.find(t=>t.is(e))}hasMember(e){return this.members.some(t=>t.is(e))}getField(e){return this.fields.find(t=>t.is(e))}hasField(e){return this.fields.some(t=>t.is(e))}getGetter(e){return this.getters.find(t=>t.is(e))}hasGetter(e){return this.getters.some(t=>t.is(e))}getSetter(e){return this.setters.find(t=>t.is(e))}hasSetter(e){return this.setters.some(t=>t.is(e))}getMethod(e){return this.methods.find(t=>t.is(e))}hasMethod(e){return this.methods.some(t=>t.is(e))}canRead(e){return this.readable.some(t=>t.is(e))}canWrite(e){return this.writable.some(t=>t.is(e))}clone(){const e=this.members.map(e=>e.clone());return new G(this.identifier,this.parent,e)}toString(){return`class ${this.identifier??""}${void 0!==this.parent?` extends ${this.parent}`:""}{${this.members.map(e=>e.toString()).join("")}}`}}class K extends ${members;from;constructor(e,t){super(),this.members=e,this.from=t}hasMember(e){return this.members.some(t=>t.is(e))}getMember(e){return this.members.find(t=>t.is(e))}clone(){const e=this.members.map(e=>e.clone());return new K(e,this.from)}toString(){const e=this.members.map(e=>e.toString()),t=this.from?` from '${this.from}'`:"";return`export {${e.join(",")}}${t};`}}class H extends ${code;constructor(e){super(),this.code=e}clone(){return new H(this.code)}toString(e=!0){const t=!1===e||this.code.endsWith("}")?"":";";return`${this.code}${t}`}}class _ extends P{clone(){const e=this.parameters.map(e=>e.clone()),t=this.body.clone();return new _(this.identifier,e,t,this.isAsync)}toString(){const e=this.isAsync?"async ":"",t=this.identifier??"",s=this.parameters.map(e=>e.toString()),r=this.body.toString();return`${e}function* ${t}(${s.join(",")})${r}`}}class W extends q{clone(){const e=this.parameters.map(e=>e.clone()),t=this.body.clone();return new W(this.identifier,this.visibility,this.location,e,t,this.isAsync)}toString(){const e=this.isAsync?"async ":"",t=this.identifier,s=this.parameters.map(e=>e.toString()),r=this.body.toString();return`${e}*${t}(${s.join(",")})${r}`}}class z extends x{identifier;isRest;constructor(e,t=!1){super(),this.identifier=e,this.isRest=t}clone(){return new z(this.identifier,this.isRest)}toString(){return`${this.isRest?"...":""}${this.identifier}`}}class Y extends ${members;from;constructor(e,t){super(),this.members=e,this.from=t}hasMember(e){return this.members.some(t=>t.is(e))}getMember(e){return this.members.find(t=>t.is(e))}clone(){const e=this.members.map(e=>e.clone());return new Y(e,this.from)}toString(){if(0===this.members.length)return`import '${this.from}';`;return`import {${this.members.map(e=>e.toString()).join(",")}} from '${this.from}';`}}class X extends C{type;binding;initializer;constructor(e,t,s){super(t.toString()),this.type=e,this.binding=t,this.initializer=s}clone(){const e=this.binding.clone(),t=this.initializer?.clone();return new X(this.type,e,t)}toString(){const e=void 0!==this.initializer?`=${this.initializer.toString(!0)}`:"",t=e.endsWith(";")?"":";";return`${this.type} ${this.identifier}${e}${t}`}}class Q{statements;constructor(e){this.statements=e}get exports(){return this.statements.filter(e=>e instanceof K)}get imports(){return this.statements.filter(e=>e instanceof Y)}get expressions(){return this.statements.filter(e=>e instanceof H)}get declarations(){return this.statements.filter(e=>e instanceof C)}get variables(){return this.statements.filter(e=>e instanceof X)}get functions(){return this.statements.filter(e=>e instanceof P)}get classes(){return this.statements.filter(e=>e instanceof G)}get exported(){const e=[];for(const t of this.exports)for(const s of t.members){const t=this.getDeclaration(s.identifier);void 0!==t&&e.push(t)}return e}get exportedVariables(){return this.exported.filter(e=>e instanceof X)}get exportedFunctions(){return this.exported.filter(e=>e instanceof P)}get exportedClasses(){return this.exported.filter(e=>e instanceof G)}getExport(e){return this.exports.find(t=>t.hasMember(e))}getImport(e){return this.imports.find(t=>t.hasMember(e))}hasDeclaration(e){return this.declarations.some(t=>t.is(e))}getDeclaration(e){return this.declarations.find(t=>t.is(e))}hasVariable(e){return this.variables.some(t=>t.is(e))}getVariable(e){return this.variables.find(t=>t.is(e))}hasFunction(e){return this.functions.some(t=>t.is(e))}getFunction(e){return this.functions.find(t=>t.is(e))}hasClass(e){return this.classes.some(t=>t.is(e))}getClass(e){return this.classes.find(t=>t.is(e))}clone(){const e=this.statements.map(e=>e.clone());return new Q(e)}toString(){return this.statements.map(e=>e.toString(!0)).join("\n")}}class J{identifier;alias;constructor(e,t){this.identifier=e,this.alias=t}is(e){return this.alias===e||void 0===this.alias&&this.identifier===e}clone(){return new J(this.identifier,this.alias)}toString(){return void 0===this.alias?this.identifier:`${this.identifier} as ${this.alias}`}}class Z extends x{elements;constructor(e){super(),this.elements=e}clone(){const e=this.elements.map(e=>e.clone());return new Z(e)}toString(){return`{${this.elements.map(e=>e.toString()).join(",")}}`}}const ee={SINGLE:"//",MULTI_START:"/*",MULTI_END:"*/"},te=Object.values(ee);const se=".",re="(",ie=")",ne="[",oe="]",ae="{",ce="}",ue="_",le={SCOPE:":",SEPARATOR:",",TERMINATOR:";"},he=Object.values(le);function pe(e){return he.includes(e)}const me={UNDEFINED:void 0,NULL:null,STRING:""},de=["null","undefined"],fe=Object.values(me);function ge(e){return fe.includes(e)}const Ee={OPEN:re,CLOSE:ie};function we(e){return e===Ee.OPEN||e===Ee.CLOSE}const ye={IMPORT:"import",EXPORT:"export",AS:"as",FROM:"from",DEFAULT:"default",ASYNC:"async",AWAIT:"await",USING:"using",CONST:"const",LET:"let",VAR:"var",FUNCTION:"function",RETURN:"return",YIELD:"yield",CLASS:"class",CONSTRUCTOR:"constructor",GET:"get",SET:"set",EXTENDS:"extends",STATIC:"static",NEW:"new",THIS:"this",DO:"do",WHILE:"while",FOR:"for",OF:"of",IN:"in",BREAK:"break",CONTINUE:"continue",IF:"if",ELSE:"else",SWITCH:"switch",CASE:"case",THROW:"throw",TRY:"try",CATCH:"catch",FINALLY:"finally",TYPEOF:"typeof",INSTANCEOF:"instanceof"},be=Object.values(ye),Se=[ye.IMPORT,ye.EXPORT,ye.VAR,ye.LET,ye.CONST,ye.FUNCTION,ye.CLASS,ye.ASYNC],Ie=[ye.VAR,ye.LET,ye.CONST,ye.FUNCTION,ye.CLASS,ye.USING],Ae=[ye.AS,ye.ASYNC,ye.GET,ye.SET,ye.OF,ye.YIELD,ye.FROM,ye.STATIC];function Te(e){return Se.includes(e)}function ve(e){return Ae.includes(e)}const Oe={OPEN:ne,CLOSE:oe};function Ne(e){return e===Oe.OPEN||e===Oe.CLOSE}const Re=Object.values({SINGLE:"'",DOUBLE:'"',BACKTICK:"`"});function xe(e){return Re.includes(e)}const Me={ADD:"+",ARROW:"=>",ASSIGN:"=",ASSIGN_ADD:"+=",ASSIGN_BITWISE_AND:"&=",ASSIGN_BITWISE_OR:"|=",ASSIGN_BITWISE_XOR:"^=",ASSIGN_DIVIDE:"/=",ASSIGN_EXPONENTIAL:"**=",ASSIGN_LEFT_SHIFT:"<<=",ASSIGN_LOGICAL_AND:"&&=",ASSIGN_LOGICAL_OR:"||=",ASSIGN_REMAINDER:"%=",ASSIGN_MULTIPLY:"*=",ASSIGN_NULLISH:"??=",ASSIGN_RIGHT_SHIFT:">>=",ASSIGN_SUBTRACT:"-=",BITWISE_AND:"&",BITWISE_OR:"|",BITWISE_NOT:"~",BITWISE_XOR:"^",DECREMENT:"--",DIVIDE:"/",EQUAL:"==",EQUAL_STRICT:"===",EXPONENTIAL:"**",GREATER:">",GREATER_EQUAL:">=",INCREMENT:"++",LEFT_SHIFT:"<<",LESS:"<",LESS_EQUAL:"<=",LOGICAL_AND:"&&",LOGICAL_OR:"||",REMAINDER:"%",MULTIPLY:"*",NULLISH:"??",CHAINING:".",OPTIONAL_CHAINING:"?.",SPREAD:"...",NOT:"!",NOT_EQUAL:"!=",NOT_EQUAL_STRICT:"!==",RIGHT_SHIFT:">>",SUBTRACT:"-",TERNARY:"?",$BRIDGE_CHAINING_SPREAD:".."},$e=Object.values(Me);function Ce(e){return $e.includes(e)}const Pe={OPEN:ae,CLOSE:ce};function Le(e){return e===Pe.OPEN||e===Pe.CLOSE}const Fe={BOOLEAN:"boolean",COMMENT:"comment",DIVIDER:"divider",GROUP:"group",IDENTIFIER:"identifier",KEYWORD:"keyword",LIST:"list",LITERAL:"literal",NOTHING:"nothing",NUMBER:"number",OPERATOR:"operator",INDICATOR:"indicator",REGEX:"regex",SCOPE:"scope",WHITESPACE:"whitespace",NONE:"none"},Ve={SPACE:" ",TAB:"\t",NEWLINE:"\n",CARRIAGE_RETURN:"\r"},De=Object.values(Ve);function je(e){return De.includes(e)}class ke{#w;#y;constructor(e){this.#w=e,this.#y=0}get items(){return this.#w}get position(){return this.#y}get size(){return this.#w.length}get eol(){return this.#y>=this.#w.length}get current(){return this.#w[this.#y]}get next(){return this.#w[this.#y+1]}get previous(){return this.#w[this.#y-1]}notAtEnd(){return!1===this.eol}get(e){return this.#w[e]}step(e=1){return this.#y+=e,this.current}stepBack(e=1){return this.#y-=e,this.current}hasNext(){return this.#y+1<this.#w.length}insert(...e){this.#w.splice(this.#y,0,...e)}}class Be extends ke{constructor(e){super(e.split(""))}}class qe{#t;#b;#S;#I;constructor(e,t,s,r){this.#t=e,this.#b=t,this.#S=s,this.#I=r}get type(){return this.#t}get value(){return this.#b}get start(){return this.#S}get end(){return this.#I}isType(e){return this.#t===e}hasValue(e){return this.#b===e}toString(){return`${this.#b}`}}class Ue extends ke{}const Ge=["true","false"];const Ke=["0","1","2","3","4","5","6","7","8","9"],He=[...Ke,"a","b","c","d","e","f","A","B","C","D","E","F"],_e=["0","1"];function We(e){return Ke.includes(e)}const ze={GENERATOR:"*",PRIVATE:"#"},Ye=Object.values(ze);class Xe{tokenize(e){const t=new Be(e),s=[];let r;for(;t.notAtEnd();){const e=this.#A(t,r);if(void 0===e)break;e.isType(Fe.WHITESPACE)||e.isType(Fe.COMMENT)?t.step():(s.push(e),this.#T(e)&&(r=e),t.step())}return new Ue(s)}#T(e){return!1===[Fe.WHITESPACE,Fe.COMMENT].includes(e.type)}#A(e,t){const s=e.current,r=e.position;if(je(s)){const t=e.position;return new qe(Fe.WHITESPACE,s,r,t)}if(function(e){return te.includes(e)}(s+e.next)){const t=this.#v(e),s=e.position;return new qe(Fe.COMMENT,t,r,s)}if(this.#O(s,t)){const t=this.#N(e),s=e.position;return new qe(Fe.REGEX,t,r,s)}if(this.#R(e,t)){const t=this.#x(e),s=e.position;return new qe(Fe.NUMBER,t,r,s)}if(xe(s)){const t=this.#M(e),s=e.position;return new qe(Fe.LITERAL,t,r,s)}if(Ce(s)){const t=this.#$(e),s=e.position;return new qe(Fe.OPERATOR,t,r,s)}if(function(e){return Ye.includes(e)}(s)){const t=this.#$(e),s=e.position;return new qe(Fe.INDICATOR,t,r,s)}if(pe(s)){const t=e.position;return new qe(Fe.DIVIDER,s,r,t)}if(we(s)){const t=e.position;return new qe(Fe.GROUP,s,r,t)}if(Le(s)){const t=e.position;return new qe(Fe.SCOPE,s,r,t)}if(Ne(s)){const t=e.position;return new qe(Fe.LIST,s,r,t)}if(ge(s))return;const i=this.#C(e),n=e.position;return function(e){return be.includes(e)}(i)?new qe(Fe.KEYWORD,i,r,n):function(e){return Ge.includes(e)}(i)?new qe(Fe.BOOLEAN,i,r,n):function(e){return de.includes(e)}(i)?new qe(Fe.NOTHING,i,r,n):new qe(Fe.IDENTIFIER,i,r,n)}#v(e){const t=e.current+e.next===ee.MULTI_START,s=t?ee.MULTI_END:Ve.NEWLINE;let r=t?ee.MULTI_START:ee.SINGLE;for(e.step(2);e.notAtEnd();){const i=e.current;if((t?i+e.next:i)===s){e.step(s.length-1);break}r+=i,e.step()}return t?r+ee.MULTI_END:r.trim()}#O(e,t){return e===Me.DIVIDE&&(void 0===t||([Fe.OPERATOR,Fe.DIVIDER,Fe.KEYWORD].includes(t.type)||[Ee.OPEN,Oe.OPEN].includes(t.value)))}#P(e){return je(e)||e==se||!1===this.#L(e)}#N(e){let t=e.current,s=!1;for(e.step();e.notAtEnd();){const r=e.current,i=e.previous;if(r===Me.DIVIDE&&"\\"!==i)s=!0;else if(!0===s&&this.#P(r)){e.stepBack();break}t+=r,e.step()}return t}#R(e,t){const s=e.current,r=e.next;return!!We(s)||s===Me.SUBTRACT&&(!t?.isType(Fe.NUMBER)&&We(r))}#F(e,t,s){return t?!1===(r=e,He.includes(r))&&e!==ue:s?!1===function(e){return _e.includes(e)}(e)&&e!==ue:!1===We(e)&&e!==se&&e!==ue&&"e"!==e;var r}#x(e){let t=e.current;t===Me.SUBTRACT&&(t+=e.step()),e.step();const s="x"===e.current,r="b"===e.current;for((s||r)&&(t+=e.current,e.step());e.notAtEnd();){const i=e.current;if(this.#F(i,s,r)){e.stepBack();break}t+=i,e.step()}return t}#M(e){const t=e.current;let s=t,r=!1;for(e.step();e.notAtEnd();){const i=e.current;if(!1===r){if(i===t){s+=i;break}"\\"===i&&(r=!0)}else r=!1;s+=i,e.step()}return s}#L(e){return!1===(ge(e)||je(e)||Ce(e)||xe(e)||pe(e)||we(e)||Le(e)||Ne(e))}#C(e){let t="";for(;e.notAtEnd();){const s=e.current;if(!1===this.#L(s)){e.stepBack();break}t+=s,e.step()}return t}#$(e){let t=e.current;for(e.step();e.notAtEnd();){const s=e.current;if(!1===Ce(s)||!1===Ce(t+s)){e.stepBack();break}t+=s,e.step()}return t}}class Qe extends Error{constructor(e,t){super(`Expected keyword '${e}' at position ${t}`)}}class Je extends Error{constructor(e,t){super(`Expected token '${e}' at position ${t}`)}}class Ze extends Error{constructor(e,t){super(`Unexpected keyword '${e}' at position ${t}`)}}class et extends Error{constructor(e){super(`The given code does not contain ${e}`)}}class tt extends Error{constructor(e,t){super(`Unexpected token '${e}' at position ${t}`)}}const st=new qe(Fe.NONE,"",-1,0);class rt{#V;constructor(e=[]){this.#V=e}get tokens(){return this.#V}append(...e){this.#V.push(...e)}merge(e){this.append(...e.tokens)}generate(){let e="";for(let t=0;t<this.#V.length;t++){const s=this.#V[t-1]??st,r=this.#V[t],i=this.#V[t+1]??st,n=this.#D(s,r)?" ":"",o=this.#j(r,i)?" ":"";e+=`${n}${r.value}${o}`}return e}#D(e,t){return!(!t.isType(Fe.KEYWORD)||!this.#k(e))||!(!t.isType(Fe.OPERATOR)||!e.isType(Fe.OPERATOR))}#j(e,t){return e.isType(Fe.KEYWORD)&&(t.isType(Fe.KEYWORD)||this.#k(t))}#k(e){return e.isType(Fe.IDENTIFIER)||e.isType(Fe.BOOLEAN)||e.isType(Fe.NOTHING)||e.isType(Fe.NUMBER)}}const it="default",nt="$_EXPORT";class ot{#B;constructor(e=new Xe){this.#B=e}parse(e){const t=this.#B.tokenize(e),s=this.#q(t);return new Q(s)}parseStatement(e){const t=this.#B.tokenize(e),s=this.#U(t);if(void 0===s)throw new et("a statement");return s}parseImport(e){const t=this.#B.tokenize(e),s=this.#G(t);if(s instanceof Y==!1)throw new et("an import definition");return s}parseExport(e){const t=this.#B.tokenize(e),s=this.#G(t);if(s instanceof K==!1)throw new et("an export definition");return s}parseVariable(e){const t=this.#B.tokenize(e),s=this.#G(t);if(s instanceof X==!1)throw new et("a variable definition");return s}parseFunction(e){const t=this.#B.tokenize(e),s=this.#G(t);if(s instanceof P==!1)throw new et("a function definition");return s}parseClass(e){const t=this.#B.tokenize(e),s=this.#G(t);if(s instanceof G==!1)throw new et("a class definition");return s}#q(e){const t=[];for(;e.notAtEnd();){const s=this.#U(e);void 0!==s&&t.push(s)}return t}#U(e,t=!1){const s=e.current;if(this.#K(s))return this.#H(e);if(s.isType(Fe.IDENTIFIER)){const s=e.next;return s?.hasValue(Me.ARROW)?this.#_(e,t):this.#H(e)}if(s.isType(Fe.KEYWORD)){if(ve(s.value)){const t=e.next,r=void 0!==t&&(t.hasValue(ye.FUNCTION)||t.hasValue(Ee.OPEN));if(s.hasValue(ye.ASYNC)&&r)return e.step(),this.#U(e,!0);if(void 0===t||this.#W(t))return this.#H(e)}return s.hasValue(ye.RETURN)?this.#H(e):!1===Te(s.value)?this.#H(e):this.#G(e,t)}if(s.isType(Fe.REGEX))return this.#H(e);if(s.hasValue(Ee.OPEN)){const s=this.#z(e,Ee.OPEN,Ee.CLOSE);return s?.hasValue(Me.ARROW)?this.#_(e,t):this.#H(e)}if(s.hasValue(Pe.OPEN))return this.#H(e);if(s.hasValue(Oe.OPEN))return this.#H(e);if(s.hasValue(Me.NOT)||s.hasValue(Me.SUBTRACT))return this.#H(e);if(!pe(s.value))throw new tt(s.value,s.start);e.step()}#K(e){return e.isType(Fe.LITERAL)||e.isType(Fe.NUMBER)||e.isType(Fe.BOOLEAN)||e.isType(Fe.NOTHING)||e.hasValue(ye.NEW)}#G(e,t=!1){const s=e.current;switch(e.step(),s.value){case ye.IMPORT:return this.#Y(e);case ye.EXPORT:return this.#X(e);case ye.CLASS:return this.#Q(e);case ye.FUNCTION:return this.#J(e,t);case ye.VAR:return this.#Z(e,"var");case ye.LET:return this.#Z(e,"let");case ye.CONST:return this.#Z(e,"const");case ye.ASYNC:return this.#U(e,!0);default:throw new Ze(s.value,s.start)}}#Y(e){const t=[];let s=e.current;if(s.isType(Fe.LITERAL)){const e=this.#ee(s.value);return new Y(t,e)}if(s.hasValue(Ee.OPEN)){s=e.step();const r=this.#ee(s.value);return e.step(2),new Y(t,r)}if(!1===s.hasValue(Pe.OPEN)){const r=s.hasValue(Me.MULTIPLY)?Me.MULTIPLY:it;let i=s.value;s=e.step(),s.hasValue(ye.AS)&&(s=e.step(),i=s.value,s=e.step()),t.push(new J(r,i))}if(s.hasValue(le.SEPARATOR)&&(s=e.step()),s.hasValue(Pe.OPEN)){const r=this.#te(e);t.push(...r),s=e.current}if(!1===s.hasValue(ye.FROM))throw new Qe(ye.FROM,s.start);s=e.step();const r=this.#ee(s.value);return e.step(),new Y(t,r)}#X(e){switch(e.current.value){case ye.DEFAULT:return e.step(),this.#se(e,!0);case Pe.OPEN:return this.#re(e);default:return this.#se(e,!1)}}#se(e,t){let s=e.current,r=0;if(t&&this.#ie(e)){const t=`${nt}_${s.start}_${s.end}`;e.insert(new qe(Fe.KEYWORD,ye.CONST,0,0),new qe(Fe.IDENTIFIER,t,0,0),new qe(Fe.OPERATOR,Me.ASSIGN,0,0)),s=e.current}var i;if(s.hasValue(ye.ASYNC)&&(s=e.step(),r++),i=s.value,Ie.includes(i)&&(s=e.step(),r++,s.hasValue(ze.GENERATOR)&&(s=e.step(),r++)),s.hasValue(ye.EXTENDS)||s.hasValue(Ee.OPEN)||s.hasValue(Pe.OPEN)){const t=`${nt}_${s.start}_${s.end}`;e.insert(new qe(Fe.IDENTIFIER,t,0,0)),s=e.current}const n=this.#L(s)?s.value:"",o=t?it:void 0;let a;s=e.step(),s?.hasValue(ye.FROM)&&(s=e.step(),a=this.#ee(s.value)),r>0&&(r++,e.stepBack(r));const c=new J(n,o);return new K([c],a)}#ie(e){const t=e.current;if(this.#K(t))return!0;const s=e.next;return this.#L(t)&&s?.hasValue(Ee.OPEN)}#re(e){const t=this.#te(e);let s,r=e.current;return r?.hasValue(ye.FROM)&&(r=e.step(),s=this.#ee(r.value)),e.step(),new K(t,s)}#ee(e){return e.slice(1,-1)}#te(e){const t=[];let s=e.step();for(;e.notAtEnd();){if(s.hasValue(Pe.CLOSE)){e.step();break}if(s.hasValue(le.SEPARATOR)){s=e.step();continue}const r=this.#ne(e);t.push(r),s=e.step()}return t}#ne(e){let t=e.current;const s=t.value;let r;return e.next.hasValue(ye.AS)&&(t=e.step(2),r=t.value),new J(s,r)}#Z(e,t){const s=this.#oe(e),r=this.#ae(e);return e.notAtEnd()&&e.current.hasValue(le.SEPARATOR)&&(e.step(),e.insert(new qe(Fe.KEYWORD,t,0,0))),new X(t,s,r)}#oe(e){const t=e.current;return t.hasValue(Oe.OPEN)?this.#ce(e):t.hasValue(Pe.OPEN)?this.#ue(e):this.#le(e)}#ce(e){const t=this.#he(e,Oe.CLOSE);return new M(t)}#ue(e){const t=this.#he(e,Pe.CLOSE);return new Z(t)}#he(e,t){const s=[];for(e.step();e.notAtEnd();){const r=e.current;if(r.hasValue(t)){e.step();break}if(r.hasValue(le.SEPARATOR)){e.step();continue}const i=this.#oe(e),n=this.#ae(e),o=new F(i,n);s.push(o)}return s}#le(e){let t=e.current,s=!1;t.hasValue(Me.SPREAD)&&(s=!0,t=e.step());const r=t.value;return e.step(),new z(r,s)}#ae(e){const t=e.current;if(!1!==t.hasValue(Me.ASSIGN))return e.step(),this.#U(e,!1);t.hasValue(le.TERMINATOR)&&e.step()}#J(e,t){let s,r=e.current,i=!1;r.hasValue(ze.GENERATOR)&&(i=!0,r=e.step()),this.#L(r)&&(s=r.value,e.step());const n=this.#he(e,Ee.CLOSE);if(r=e.current,!1===r.hasValue(Pe.OPEN))throw new Je(Pe.OPEN,r.start);const o=this.#pe(e);return i?new _(s,n,o,t):new P(s,n,o,t)}#_(e,t){let s,r,i=e.current;if(i.hasValue(Ee.OPEN))s=this.#he(e,Ee.CLOSE);else{const t=this.#le(e);s=[new F(t,void 0)]}if(i=e.current,!1===i.hasValue(Me.ARROW))throw new Je(Me.ARROW,i.start);if(i=e.step(),i.hasValue(Pe.OPEN))r=this.#pe(e);else{const t=this.#H(e);r=new V(t.code)}return new L(s,r,t)}#Q(e){let t,s,r=e.current;if(this.#L(r)&&(t=r.value,r=e.step()),r.hasValue(ye.EXTENDS)&&(r=e.step(),s=r.value,r=e.step()),!1===r.hasValue(Pe.OPEN))throw new Je(Pe.OPEN,r.start);const i=this.#me(e);return new G(t,s,i)}#me(e){let t=e.step();const s=[];for(;e.notAtEnd();){if(t.hasValue(Pe.CLOSE)){e.step();break}const r=this.#de(e);s.push(r),t=e.current}return s}#de(e){let t=e.current,s="public",r="instance",i=!1;for(;e.notAtEnd();){if(t.hasValue(ze.PRIVATE))s="private";else if(t.hasValue(ye.STATIC))r="static";else{if(!t.hasValue(ye.ASYNC)){if(t.hasValue(ye.CONSTRUCTOR))return this.#fe(e);if(t.hasValue(ye.GET))return this.#ge(e,r);if(t.hasValue(ye.SET))return this.#Ee(e,r);if(t.hasValue(ze.GENERATOR))return e.step(),this.#we(e,s,r,i,!0);break}i=!0}t=e.step()}return e.next.hasValue(Ee.OPEN)?this.#we(e,s,r,i,!1):this.#ye(e,s,r)}#fe(e){e.step();const t=this.#he(e,Ee.CLOSE),s=e.current;if(!1===s.hasValue(Pe.OPEN))throw new Je(Pe.OPEN,s.start);const r=this.#pe(e);return new j(t,r)}#ge(e,t){let s="public",r=e.step();r.hasValue(ze.PRIVATE)&&(s="private",r=e.step());const i=r.value;e.step();if(0!==this.#he(e,Ee.CLOSE).length)throw new et("an empty parameter list");if(r=e.current,!1===r.hasValue(Pe.OPEN))throw new Je(Pe.OPEN,r.start);const n=this.#pe(e);return new k(i,s,t,n)}#Ee(e,t){let s="public",r=e.step();r.hasValue(ze.PRIVATE)&&(s="private",r=e.step());const i=r.value;e.step();const n=this.#he(e,Ee.CLOSE);if(r=e.current,1!==n.length)throw new et("exactly one setter parameter");if(!1===r.hasValue(Pe.OPEN))throw new Je(Pe.OPEN,r.start);const o=this.#pe(e);return new B(i,s,t,n[0],o)}#we(e,t,s,r,i){let n=e.current;const o=n.value;e.step();const a=this.#he(e,Ee.CLOSE);if(n=e.current,!1===n.hasValue(Pe.OPEN))throw new Je(Pe.OPEN,n.start);const c=this.#pe(e);return i?new W(o,t,s,a,c,r):new q(o,t,s,a,c,r)}#ye(e,t,s){const r=e.current.value;e.step();const i=this.#ae(e);return new U(r,t,s,i)}#pe(e){const t=this.#be(e,Pe.OPEN,Pe.CLOSE).generate();return new V(t)}#H(e){const t=new rt;let s=e.current;for(;e.notAtEnd();){if(s.hasValue(Oe.OPEN)){const r=this.#be(e,Oe.OPEN,Oe.CLOSE);t.merge(r),s=e.current}else if(s.hasValue(Ee.OPEN)){const r=this.#be(e,Ee.OPEN,Ee.CLOSE);t.merge(r),s=e.current}else if(s.hasValue(Pe.OPEN)){const r=this.#be(e,Pe.OPEN,Pe.CLOSE);t.merge(r),s=e.current}else t.append(s),s=e.step();if(void 0===s)break;if(this.#W(s)){s.hasValue(le.TERMINATOR)&&e.step();break}}const r=t.generate();return new H(r)}#be(e,t,s){let r=e.current;const i=new rt([r]);for(r=e.step();e.notAtEnd();){if(r.hasValue(t)){const n=this.#be(e,t,s);i.merge(n),r=e.current;continue}if(r.hasValue(s))return e.step(),i.append(r),i;i.append(r),r=e.step()}return i}#z(e,t,s){const r=e.position;this.#be(e,t,s);const i=e.current,n=e.position;return e.stepBack(n-r),i}#W(e){return[le.TERMINATOR,le.SEPARATOR].includes(e.value)||[Oe.CLOSE,Ee.CLOSE,Pe.CLOSE].includes(e.value)||Te(e.value)}#L(e){return e.isType(Fe.IDENTIFIER)||e.isType(Fe.KEYWORD)&&ve(e.value)}}class at extends Error{constructor(e,t){super(`Failed reading module from '${e}'`,{cause:t})}}class ct{#h;#p=new T;constructor(e){this.#h=e}rewrite(e,t){e.imports.forEach(e=>this.#Se(e,t)),e.exports.forEach(e=>this.#Ie(e,t))}#Se(e,t){const s=this.#h.normalizeLocation(e.from);!1!==this.#p.isApplicationModule(s)&&(e.from=this.#Ae(t,s))}#Ie(e,t){if(void 0===e.from)return;const s=this.#h.normalizeLocation(e.from);!1!==this.#p.isApplicationModule(s)&&(e.from=this.#Ae(t,s))}#Ae(e,t){const s=this.#p.extractPath(e),r=this.#p.makePathAbsolute(t,s,"");return this.#h.isDirectory(r)?`${t}/${E}`:this.#p.assureExtension(t)}}let ut=class{#h;#Te;#ve;constructor(e,t=new ot){this.#h=e,this.#Te=t,this.#ve=new ct(e)}async readAll(e){const t=await Promise.all(e.map(e=>this.read(e)));return new R(t)}async read(e){try{const t=this.#h.getRelativeLocation(e),s=await this.#Oe(e),r=this.#Te.parse(s);return this.#ve.rewrite(r,t),new N(t,r)}catch(t){throw new at(e,t)}}async#Oe(e){return(await this.#h.getContent(e)).toString()}},lt=class{#Ne;#E=new Map;#Re=new Map;#xe=new Map;constructor(e){this.#Ne=e}get name(){return this.#Ne}get modules(){return[...this.#E.values()]}get classes(){return[...this.#Re.values()]}get procedures(){return[...this.#xe.values()]}hasModule(e){return this.#E.has(e)}getModule(e){return this.#E.get(e)}getSegmentedModules(){return this.modules.filter(e=>e.segmented)}setModule(e){this.#E.set(e.filename,e)}hasProcedure(e){return this.#xe.has(e)}getProcedure(e){return this.#xe.get(e)}setProcedure(e){this.#xe.set(e.fqn,e)}setClass(e){this.#Re.set(e.fqn,e)}};class ht{#u;#Me;#$e;constructor(e,t,s){this.#u=e,this.#Me=t,this.#$e=s}get id(){return this.#u}get importKey(){return this.#Me}get fqn(){return this.#$e}}class pt extends ht{#g;constructor(e,t,s,r){super(e,t,s),this.#g=r}get model(){return this.#g}}class mt extends ht{#Ce;#Pe;#g;constructor(e,t,s,r,i,n){super(e,t,s),this.#Ce=r,this.#Pe=i,this.#g=n}get access(){return this.#Ce}get version(){return this.#Pe}get model(){return this.#g}}class dt{#f;#e;#Le;#Fe=[];#Ve;constructor(e,t,s,r){this.#f=e,this.#e=t,this.#Le=s,this.#Ve=r}get filename(){return this.#f}get location(){return this.#e}get imports(){return this.#Le}get members(){return this.#Fe}get classes(){return this.#Fe.filter(e=>e instanceof pt)}get implementations(){return this.#Fe.filter(e=>e instanceof mt)}get segmented(){return this.#Ve}hasClasses(){return this.#Fe.some(e=>e instanceof pt)}hasImplementations(){return this.#Fe.some(e=>e instanceof mt)}importsImplementation(e){return void 0!==this.implementations.find(t=>t.importKey===e)}addMember(e){this.#Fe.push(e)}addImports(e){const t=Object.keys(e);for(const s of t){const t=s.trim();this.#Le[t]=e[s]}}}class ft{#$e;#De=[];constructor(e,t=[]){this.#$e=e,this.#De=t}get fqn(){return this.#$e}get implementations(){return this.#De}addImplementation(e){this.#De.push(e)}}class gt{#je;constructor(e){this.#je=e}get segments(){return this.#je}getSegment(e){return this.#je.find(t=>t.name===e)}isSegmentedModule(e){return this.#je.some(t=>t.hasModule(e))}getSegments(e){return this.#je.filter(t=>t.hasModule(e))}}class Et extends Error{constructor(e,t){super(`Function '${t}' from file '${e}' is not async`)}}class wt extends Error{constructor(e){super(`Segment filename '${e}' is invalid`)}}class yt extends Error{constructor(e,t){super(`Failed to load segment file '${e}' because of: ${t}`)}}class bt extends Error{constructor(e,t){super(`The export '${t}' from file '${e}' is not a function or a class.`)}}class St extends Error{constructor(e,t){super(`Failed reading segment from '${e}'`,{cause:t})}}class It extends Error{constructor(e,t){super(`Module '${e}' does not export '${t}'`)}}class At extends Error{constructor(e){super(`Segmented module not found '${e}'`)}}class Tt{#o;#p=new T;constructor(e){this.#o=e}locate(e,t){const s=[];return{trace:s,model:this.#ke(e,t,s)}}#ke(e,t,s){s.push({filename:e,importKey:t});const r=this.#Be(e);return this.#qe(r,t)?this.#Ue(r,t,s):this.#Ge(r,t)}#Be(e){const t=this.#o.get(e);if(void 0===t)throw new At(e);return t}#qe(e,t){const s=e.model.getImport(t),r=e.model.getExport(t);return void 0!==s||void 0!==r?.from}#Ue(e,t,s){const r=this.#Ke(e,t)??this.#He(e,t),i=r?.from,n=r?.name,o=this.#p.extractPath(e.filename),a=i,c=this.#p.makePathAbsolute(a,o,"");return this.#ke(c,n,s)}#Ge(e,t){const s=this.#He(e,t);if(void 0===s)throw new It(e.filename,t);const r=e.model.getDeclaration(s.name);if(void 0===r)throw new It(e.filename,s.name);return r}#He(e,t){const s=e.model.getExport(t),r=s?.getMember(t);if(void 0!==r)return{from:s?.from,name:r.identifier}}#Ke(e,t){const s=e.model.getImport(t),r=s?.getMember(t);if(void 0!==s&&void 0!==r)return{from:s.from,name:r.identifier}}}class vt{#_e;#h;#We;#p=new T;constructor(e,t,s){this.#_e=e,this.#h=t,this.#We=new Tt(s)}async readAll(e){const t=await Promise.all(e.map(e=>this.#ze(e)));return new gt(t)}async#ze(e){try{const t=await this.#Ye(e),s=this.#Xe(e),r=new lt(s);return this.#Qe(r,t),this.#Je(r),r}catch(t){throw new St(e,t)}}#Xe(e){const t=e.split("/").pop();if(void 0===t||""===t)throw new wt(e);return t.replace(w,"")}async#Ye(e){try{const t=await this.#_e.getContent(e);return JSON.parse(t.toString())}catch(t){const s=t instanceof Error?t.message:String(t);throw new yt(e,s)}}#Qe(e,t){for(const[s,r]of Object.entries(t))this.#Ze(e,s,r,!0)}#Ze(e,t,s,r){const i=this.#et(t),n=this.#p.extractPath(i),o=e.hasModule(i)?e.getModule(i):new dt(i,n,{},r);o.addImports(s),e.setModule(o)}#et(e){const t=e.trim(),s=this.#h.normalizeLocation(t),r=this.#h.isDirectory(s)?`${s}/${E}`:this.#p.assureExtension(s);return r.startsWith("./")?r.substring(2):r.startsWith("/")?r.substring(1):r}#Je(e){const t=new b;for(const s of e.modules)for(const r in s.imports)this.#tt(e,s,r,t)}#tt(e,t,s,r){const{model:i,trace:n}=this.#We.locate(t.filename,s),o=this.#st(t,i,s,r);this.#rt(e,t,i,o),n.shift();for(const t of n){const s={[t.importKey]:{access:o.access}};this.#Ze(e,t.filename,s,!1)}}#st(e,t,s,r){const i=e.imports[s],n=r.next(),o=i.as??t.identifier;return{id:n,importKey:s,name:o,access:i.access??f,version:i.version??g,fqn:this.#it(e,o,s)}}#it(e,t,s){return this.#nt(e)?t:this.#ot(e)&&this.#at(s)?e.location:`${e.location}/${t}`}#nt(e){return""===e.location}#ot(e){return e.filename.endsWith(E)}#at(e){return e===y}#rt(e,t,s,r){if(s instanceof G)return this.#ct(e,t,s,r);if(s instanceof P)return this.#ut(e,t,s,r);throw new bt(t.filename,r.importKey)}#ct(e,t,s,r){const i=new pt(r.id,r.importKey,r.fqn,s);t.addMember(i),e.setClass(i)}#ut(e,t,s,r){if(!1===s.isAsync)throw new Et(t.filename,r.name);const i=new mt(r.id,r.importKey,r.fqn,r.access,r.version,s);this.#lt(e,t,i)}#lt(e,t,s){const r=e.hasProcedure(s.fqn)?e.getProcedure(s.fqn):new ft(s.fqn);r.addImplementation(s),t.addMember(s),e.setProcedure(r)}}class Ot{#ht;constructor(e){this.#ht=e}async read(e,t,s){const r=this.#ht.source,i=this.#ht.resource,n=this.#ht.segment,o=new ut(r),a=await o.readAll(e),c=new O(i,r),u=await c.readAll(t),l=new vt(n,r,a),h=await l.readAll(s);return new m(a,u,h)}}class Nt extends Error{constructor(e){super(`Could not find the rewrite item: ${e}`)}}class Rt{#pt;#a;#c;#mt;#p=new T;constructor(e,t,s,r){this.#pt=e,this.#a=t,this.#c=s,this.#mt=r}generate(){const e=this.#pt.model.clone();return this.#dt(e,e.imports),this.#dt(e,e.exports),e.toString()}#dt(e,t){for(const s of t){const t=this.#ft(s);if(0===t.length)continue;const r=e.statements.indexOf(s);if(-1===r)throw new Nt(s.toString());e.statements.splice(r,1,...t)}}#ft(e){if(this.#gt(e))return[];const t=this.#Et(e);return this.#a.isResourceModule(t)?this.#wt(e,t):this.#yt(e,t)}#gt(e){return void 0===e.from||this.#bt(e)}#bt(e){return!1===this.#p.isApplicationModule(e.from)}#Et(e){const t=e.from,s=this.#p.extractPath(this.#pt.filename);return this.#p.makePathAbsolute(t,s,"")}#wt(e,t){const s=e.clone();return s.from=this.#St(t),[s]}#yt(e,t){if(0===e.members.length)return[this.#It(t,e,[])];const{segmentKeys:s,remoteKeys:r,commonKeys:i}=this.#At(t,e),n=[];return s.length>0&&n.push(this.#Tt(t,e,s)),r.length>0&&n.push(this.#vt(t,e,r)),i.length>0&&n.push(this.#It(t,e,i)),n}#At(e,t){const s=this.#Ot(e,this.#mt),r=this.#Nt(e,s),i=this.#Rt(t,s),n=this.#Rt(t,r);return{segmentKeys:i,remoteKeys:n,commonKeys:this.#xt(t,[...i,...n])}}#Ot(e,t){if(void 0===t)return[];const s=t.getModule(e);if(void 0===s)return[];return Object.keys(s.imports).filter(e=>s.importsImplementation(e))}#Nt(e,t){const s=this.#c.getSegments(e).filter(e=>e!==this.#mt).flatMap(t=>this.#Ot(e,t));return[...new Set(s)].filter(e=>!1===t.includes(e))}#Rt(e,t){return e.members.filter(e=>t.includes(e.identifier)).map(e=>e.identifier)}#xt(e,t){return e.members.filter(e=>!1===t.includes(e.identifier)).map(e=>e.identifier)}#Tt(e,t,s){const r=t.clone();return r.from=this.#St(e,this.#mt?.name),r.members=this.#Mt(t.members,s),r}#vt(e,t,s){const r=t.clone();return r.from=this.#St(e,"remote"),r.members=this.#Mt(t.members,s),r}#It(e,t,s){const r=t.clone();return r.from=this.#St(e),r.members=this.#Mt(t.members,s),r}#Mt(e,t){const s=[];for(const r of t){const t=e.find(e=>e.identifier===r);void 0!==t&&s.push(t)}return s}#St(e,t){const s=this.#p.extractPath(this.#pt.filename),r=this.#p.makePathRelative(e,s);return void 0!==t?this.#p.addSubExtension(r,t):r}}const xt={PRIVATE:"private",PROTECTED:"protected",PUBLIC:"public"};class Mt extends Error{constructor(e="Invalid request"){super(e)}}class $t extends Error{constructor(e="Forbidden"){super(e)}}class Ct extends Error{constructor(e="Not found"){super(e)}}class Pt extends Error{constructor(e="Not implemented"){super(e)}}class Lt extends Error{constructor(e="Payment required"){super(e)}}class Ft extends Error{constructor(e="Server error"){super(e)}}class Vt extends Error{constructor(e="I'm a teapot"){super(e)}}class Dt extends Error{constructor(e="Unauthorized"){super(e)}}class jt extends Mt{#$t;constructor(e){super(`Invalid version number '${e}'`),this.#$t=e}get number(){return this.#$t}}class kt{#u;#Re=new Map;#xe=new Map;constructor(e){this.#u=e}get id(){return this.#u}addClass(e){return this.#Re.set(e.fqn,e),this}hasClass(e){return void 0!==this.getClass(e)}getClass(e){return this.#Re.get(e)}getClassByImplementation(e){return this.getClasses().find(t=>t.implementation===e)}getClasses(){return[...this.#Re.values()]}addProcedure(e){return this.#xe.set(e.fqn,e),this}hasProcedure(e){return this.#xe.has(e)}getProcedure(e){return this.#xe.get(e)}getExposedProcedures(){return[...this.#xe.values()].filter(e=>e.public||e.protected)}}class Bt{static get DEFAULT(){return new Bt(0,0,0)}#Ct;#Pt;#Lt;constructor(e=0,t=0,s=0){this.#Ct=e,this.#Pt=t,this.#Lt=s}get major(){return this.#Ct}get minor(){return this.#Pt}get patch(){return this.#Lt}equals(e){return this.#Ct===e.major&&this.#Pt===e.minor&&this.#Lt===e.patch}greater(e){return this.#Ct!==e.major?this.#Ct>e.major:this.#Pt!==e.minor?this.#Pt>e.minor:this.#Lt!==e.patch&&this.#Lt>e.patch}less(e){return this.#Ct!==e.major?this.#Ct<e.major:this.#Pt!==e.minor?this.#Pt<e.minor:this.#Lt!==e.patch&&this.#Lt<e.patch}toString(){return`${this.#Ct}.${this.#Pt}.${this.#Lt}`}}class qt{#Ne;#Ft;constructor(e,t=!1){this.#Ne=e,this.#Ft=t}get name(){return this.#Ne}get isOptional(){return this.#Ft}}class Ut extends qt{}class Gt extends qt{#Vt;constructor(e,t,s){super(t??"(anonymous)",s),this.#Vt=e}get variables(){return this.#Vt}}class Kt extends Gt{}class Ht extends Gt{}class _t{#$e;#Pe;#Dt;#jt=new Map;#kt;constructor(e,t,s,r,i){this.#$e=e,this.#Pe=t,this.#Dt=s,this.#jt=r,this.#kt=i}get fqn(){return this.#$e}get version(){return this.#Pe}get args(){return this.#Dt}get headers(){return this.#jt}get mode(){return this.#kt}clearArguments(){this.#Dt.clear()}setArgument(e,t){this.#Dt.set(e,t)}getArgument(e){return this.#Dt.get(e)}hasArgument(e){return this.#Dt.has(e)}removeArgument(e){this.#Dt.delete(e)}clearHeaders(){this.#jt.clear()}setHeader(e,t){this.#jt.set(e.toLowerCase(),t)}getHeader(e){return this.#jt.get(e.toLowerCase())}hasHeader(e){return this.#jt.has(e.toLowerCase())}removeHeader(e){this.#jt.delete(e.toLowerCase())}}class Wt{#Bt;#qt;#jt;constructor(e,t=void 0,s=new Map){this.#Bt=e,this.#qt=t,this.#jt=s}get status(){return this.#Bt}get result(){return this.#qt}set result(e){this.#qt=e}get headers(){return this.#jt}clearHeaders(){this.#jt.clear()}setHeader(e,t){this.#jt.set(e.toLowerCase(),t)}getHeader(e){return this.#jt.get(e.toLowerCase())}hasHeader(e){return this.#jt.has(e.toLowerCase())}removeHeader(e){this.#jt.delete(e.toLowerCase())}}const zt=/^\d+(?:\.\d+){0,2}$/;class Yt{parse(e){if(0===e.trim().length)return Bt.DEFAULT;if(!1===zt.test(e))throw new jt(e);const t=e.split(".");switch(t.length){case 1:return new Bt(Number.parseInt(t[0]));case 2:return new Bt(Number.parseInt(t[0]),Number.parseInt(t[1]));default:return new Bt(Number.parseInt(t[0]),Number.parseInt(t[1]),Number.parseInt(t[2]))}}}class Xt{#pt;#je;constructor(e,t){this.#pt=e,this.#je=t}generate(){const e=[],t=this.#Ut();for(const s of t){const t=s.access===xt.PRIVATE?this.#Gt(s):this.#Kt(s);e.push(...t)}return new Q(e).toString()}#Ut(){const e=this.#je.map(e=>e.getModule(this.#pt.filename)).flatMap(e=>e.implementations),t=new Map;for(const s of e){const e=`${s.fqn}:${s.version.toString()}`;t.set(e,s)}return[...t.values()]}#Gt(e){const t=`throw new ProcedureNotAccessible('${e.fqn}','${e.version}');`;return[this.#Ht(e),this.#_t(e,t)]}#Kt(e){const t=`return __run('${e.fqn}','${e.version}',{${this.#Wt(e.model.parameters)}},this);`;return[this.#Ht(e),this.#_t(e,t)]}#Ht(e){const t=e.model.identifier,s=e.importKey===y?y:void 0,r=new J(t,s);return new K([r],void 0)}#_t(e,t){const s=e.model.identifier,r=e.model.parameters,i=new V(`{${t}}`),n=e.model.isAsync;return new P(s,r,i,n)}#Wt(e){return this.#zt(e).join(",")}#zt(e){const t=[];for(const s of e)if(s.binding instanceof z){const e=this.#Yt(s.binding);t.push(e)}else if(s.binding instanceof M){const e=this.#zt(s.binding.elements);t.push(...e)}else if(s.binding instanceof Z){const e=this.#zt(s.binding.elements);t.push(...e)}return t}#Yt(e){return`'${e.identifier}':${e.toString()}`}}const Qt=["Segment","Class","Procedure","Implementation","Version","NamedParameter","ArrayParameter","ObjectParameter"];class Jt{#mt;#p=new T;#Xt=new Yt;constructor(e){this.#mt=e}generate(){const e=this.#Qt(),t=this.#Ht(),s=this.#Jt();return new Q([...e,t,s]).toString()}#Qt(){return[this.#Zt(),...this.#es()]}#Zt(){const e=Qt.map(e=>new J(e));return new Y(e,"jitar")}#es(){const e=this.#mt.name,t=this.#mt.getSegmentedModules(),s=[];for(const r of t){const t=`./${this.#p.addSubExtension(r.filename,e)}`;if(0===r.members.length){const e=new Y([],t);s.push(e);continue}const i=r.classes,n=r.implementations;if(i.length>0){const e=`./${r.filename}`,t=this.#ts(i,e);s.push(t)}if(n.length>0){const e=this.#ts(n,t);s.push(e)}}return s}#ts(e,t){if(0===e.length)return new Y([],t);const s=e.map(e=>new J(e.importKey,e.id));return new Y(s,t)}#Ht(){const e=new J("segment","default");return new K([e],void 0)}#Jt(){const e=[],t=this.#mt.name,s=this.#mt.classes,r=this.#mt.procedures;e.push(`new Segment("${t}")`);for(const t of s)e.push(`\t.addClass(new Class("${t.fqn}", ${t.id}))`);for(const t of r){e.push(`\t.addProcedure(new Procedure("${t.fqn}")`);for(const s of t.implementations){const t=this.#ss(s.version),r=this.#rs(s.model);e.push(`\t\t.addImplementation(new Implementation(${t}, "${s.access}", ${r}, ${s.id}))`)}e.push("\t)")}const i=e.join("\n"),n=new H(i),o=new z("segment");return new X("const",o,n)}#ss(e){const t=this.#Xt.parse(e);return`new Version(${t.major}, ${t.minor}, ${t.patch})`}#rs(e){return`[${this.#is(e.parameters).join(", ")}]`}#is(e){const t=[];for(const s of e)t.push(this.#ns(s));return t}#ns(e){return e.binding instanceof M?this.#os(e):e.binding instanceof Z?this.#as(e):this.#cs(e)}#cs(e){return`new NamedParameter("${e.binding}", ${void 0!==e.initializer})`}#os(e){const t=e.binding;return`new ArrayParameter([${this.#is(t.elements).join(", ")}])`}#as(e){const t=e.binding;return`new ObjectParameter([${this.#is(t.elements).join(", ")}])`}}class Zt{#us;#ls;#hs;#mt;#ps;constructor(e,t,s,r,i){this.#us=e,this.#ls=t,this.#hs=s,this.#mt=r,this.#ps=i}get source(){return this.#us}get target(){return this.#ls}get resource(){return this.#hs}get segment(){return this.#mt}get sourceIgnores(){return this.#ps}}class es{#ms;constructor(e=!0){this.#ms=e}validate(e,t){const s=[];this.#ds("",e,t,s);return{valid:0===s.length,errors:s}}#ds(e,t,s,r){this.#ms&&this.#fs(e,t,s,r),this.#gs(e,t,s,r)}#fs(e,t,s,r){const i=Object.keys(t),n=Object.keys(s);for(const t of i)if(!1===n.includes(t)){const s=this.#Es(e,t);r.push(`Unknown field '${s}'`)}}#gs(e,t,s,r){const i=Object.keys(s);for(const n of i){const i=this.#Es(e,n),o=s[n],a=t[n];this.#ws(i,a,o,r)}}#ws(e,t,s,r){if(void 0!==t)switch(s.type){case"string":return this.#ys(e,t,s,r);case"integer":return this.#bs(e,t,s,r);case"real":return this.#Ss(e,t,s,r);case"boolean":return this.#Is(e,t,s,r);case"url":return this.#As(e,t,s,r);case"group":return this.#Ts(e,t,s,r);case"list":return this.#vs(e,t,s,r);case"enum":return this.#Os(e,t,s,r)}else!0===s.required&&r.push(`Field '${e}' is required`)}#ys(e,t,s,r){"string"!=typeof t&&r.push(`Field '${e}' is not a string`)}#bs(e,t,s,r){"number"==typeof t&&!1!==Number.isInteger(t)||r.push(`Field '${e}' is not an integer`)}#Ss(e,t,s,r){"number"!=typeof t&&r.push(`Field '${e}' is not a real number`)}#Is(e,t,s,r){"boolean"!=typeof t&&r.push(`Field '${e}' is not a boolean`)}#As(e,t,s,r){"string"==typeof t&&!1!==t.startsWith("http")||r.push(`Field '${e}' is not a valid URL`)}#Ts(e,t,s,r){"object"==typeof t?this.#ds(e,t,s.fields,r):r.push(`Field '${e}' is not an object`)}#vs(e,t,s,r){if(!Array.isArray(t))return void r.push(`Field '${e}' is not a list`);const i=t;for(const t in i){const n=this.#Es(e,t),o=i[t];this.#ws(n,o,s.items,r)}}#Os(e,t,s,r){if(!1===s.options.includes(t)){const t=s.options.map(e=>String(e));r.push(`Field '${e}' is not one of: ${t.join(", ")}`)}}#Es(e,t){return""===e?t:`${e}.${t}`}}class ts{#Ns;constructor(e){this.#Ns=e}async configure(e){const t=this.#Ns.getAbsoluteLocation(e);n.config({path:t})}}class ss extends Error{constructor(e,t){super(`Invalid runtime configuration '${e}'\n${t.errors.join("\n")}`)}}const rs="./jitar.json",is="./src",ns="./dist",os="./segments",as="./resources",cs={ignore:[]},us=[],ls={source:{type:"string",required:!1},target:{type:"string",required:!1},segments:{type:"string",required:!1},resources:{type:"string",required:!1},build:{type:"group",fields:{ignore:{type:"list",items:{type:"string"},required:!1}},required:!1}};let hs=class{#Rs;#xs;constructor(e,t){this.#Rs=e,this.#xs=t}async build(e=rs){const t=await this.#Rs.read(e),s=this.#xs.validate(t,ls);if(!1===s.valid)throw new ss(e,s);return t.source??=is,t.target??=ns,t.segments??=os,t.resources??=as,t.build??=cs,t.build.ignore??=us,t.meta={root:this.#Rs.getRootLocation(),configFile:e},t}};const ps="\n => ";class ms extends Error{constructor(e,t){const s=t.errors.join(ps);super(`Invalid server configuration '${e}'${ps}${s}`)}}const ds={indexFilename:{type:"string",required:!1},serveIndexOnNotFound:{type:"boolean",required:!1},assetRoot:{type:"string",required:!1},assets:{type:"list",required:!1,items:{type:"string"}}},fs={gateway:{type:"url",required:!1},segments:{type:"list",required:!0,items:{type:"string"}},trustKey:{type:"string",required:!1},reportInterval:{type:"integer",required:!1}},gs={url:{type:"url",required:!0},setUp:{type:"list",required:!1,items:{type:"string"}},tearDown:{type:"list",required:!1,items:{type:"string"}},middleware:{type:"list",required:!1,items:{type:"string"}},healthChecks:{type:"list",required:!1,items:{type:"string"}},gateway:{type:"group",required:!1,fields:{monitorInterval:{type:"integer",required:!1},trustKey:{type:"string",required:!1}}},proxy:{type:"group",required:!1,fields:{gateway:{type:"url",required:!0},repository:{type:"url",required:!0}}},repository:{type:"group",required:!1,fields:ds},standalone:{type:"group",required:!1,fields:{...ds,segments:fs.segments}},worker:{type:"group",required:!1,fields:fs},remoteWorker:{type:"group",required:!1,fields:{unavailableThreshold:{type:"integer",required:!1},stoppedThreshold:{type:"integer",required:!1}}}};class Es{#Rs;#xs;constructor(e,t){this.#Rs=e,this.#xs=t}async build(e){const t=await this.#Rs.read(e),s=this.#xs.validate(t,gs);if(!1===s.valid)throw new ms(e,s);return t.meta={root:this.#Rs.getRootLocation(),configFile:e},t}}class ws extends Error{constructor(e){super(`${e} is not a valid configuration file.`)}}const ys=/\${([^}]*)}/g;class bs{#Ns;constructor(e){this.#Ns=e}getRootLocation(){return this.#Ns.getAbsoluteLocation(".")}async read(e){if(!1===await this.#Ns.exists(e))return{};const t=await this.#Ns.read(e);if(!1===t.type.includes("json"))throw new ws(e);const s=t.content.toString(),r=this.#Ms(s);return this.#$s(r)}#Ms(e){return e.replace(ys,(e,t)=>process.env[t]??"null")}#$s(e){return JSON.parse(e)}}class Ss{#Cs;#Ps;#Ls;constructor(e="./"){const t=new p(e),s=new bs(t),r=new es;this.#Cs=new ts(t),this.#Ps=new hs(s,r),this.#Ls=new Es(s,r)}configureEnvironment(e=".env"){return this.#Cs.configure(e)}getRuntimeConfiguration(e){return this.#Ps.build(e)}getServerConfiguration(e){return this.#Ls.build(e)}}export{Kt as A,Mt as B,Ss as C,G as E,$t as F,Jt as G,p as L,Ct as N,Ht as O,ot as P,Wt as R,Ft as S,Vt as T,Dt as U,es as V,z as a,H as b,X as c,Q as d,U as e,j as f,k as g,B as h,q as i,Ut as j,Pt as k,Lt as l,kt as m,T as n,Rt as o,Xt as p,Zt as q,Ot as r,o as s,u as t,c as u,_t as v,Yt as w,Bt as x,xt as y};