@luna-park/plugin 1.0.9 → 1.2.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/dist/extractor.cjs +2 -2
- package/dist/extractor.js +1 -1
- package/dist/index-CWrYVK_G.cjs +5 -0
- package/dist/{index-CxGB_fZK.js → index-Dv9uuje9.js} +54 -38
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +78 -41
- package/dist/index.js +31 -20
- package/package.json +10 -10
- package/dist/index-DmZsz62R.cjs +0 -5
package/dist/extractor.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("node:fs"),p=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("node:fs"),p=require("./index-CWrYVK_G.cjs"),f=require("typescript"),U=require("path"),q=require("fs");function j(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const o in t)if(o!=="default"){const n=Object.getOwnPropertyDescriptor(t,o);Object.defineProperty(e,o,n.get?n:{enumerable:!0,get:()=>t[o]})}}return e.default=t,Object.freeze(e)}const m=j(f),O=j(U),J=j(q);function T(t,e={}){if(typeof t!="object"||t===null)return JSON.stringify(t);const o={};for(const n of["default","description","name","target","promise","optional","example","enum"])t[n]&&(o[n]=t[n]);if(t.type===p.i.array)return S(`LogicType.${t.type}`,[T(t.items,e),d(o)]);if(t.type===p.i.interface)return S(`LogicType.${t.type}`,[JSON.stringify(t.className),d(o)]);if(t.type===p.i.union)return S(`LogicType.${t.type}`,[`[${t.elements.map(n=>T(n,e)).join(", ")}]`,d(o)]);if(t.type===p.i.function)return S(`LogicType.${t.type}`,[T(t.inputs,e),T(t.output,e),d(o)]);if(t.type===p.i.object)return S(`LogicType.${t.type}`,[d(p.ot(t.properties,({value:n})=>T(n,e)),!0),d(o)]);if(t.type===p.i.type){const n=t.target.at(-1),i=d(o);return i!=="{}"?n:`{ ...${n}, ${i.slice(1,-1)} }`}return S(`LogicType.${t.type}`,[d(o)])}function S(t,e){const o=e.findLastIndex(n=>n!=="{}");return`${t}(${e.slice(0,o+1).join(", ")})`}function d(t,e){return`{${Object.entries(t).map(([o,n])=>`${P(o)}: ${e?n:JSON.stringify(n)}`).join(", ")}}`}function P(t){return/^[a-zA-Z]+$/.test(t)?t:JSON.stringify(t)}function V(t,e){const o=[],n=t.components.default;Object.keys(t.types);for(const r of["properties","slots","models","emits"])n[r]&&Object.keys(n[r]).length&&o.push({key:r,value:Object.entries(n[r]).map(([l,s])=>`${P(l)}: ${T(s,{})}`).join(`,
|
|
2
2
|
`)});const i=Object.entries(t.types).map(([r,l])=>`const ${r} = ${T(l,{})};`).join(`
|
|
3
3
|
|
|
4
4
|
`);return`import { LogicType, type TComponent } from "@luna-park/plugin";
|
|
@@ -13,4 +13,4 @@ export const ${e.name.toLocaleLowerCase()}: TComponent = {
|
|
|
13
13
|
${l}
|
|
14
14
|
}`).join(`,
|
|
15
15
|
`)}
|
|
16
|
-
}`}function h(t,e){const o={description:x(t.getDocumentationComment(e))||void 0};for(const n of t.getJsDocTags()){if(n.name==="param"){o.params||(o.params={});let i=x(n.text?.slice(1)).trim();i.startsWith("- ")&&(i=i.slice(2));const r=n.text[0]?.text;o.params[r]=i;continue}o[n.name]=x(n.text)}return p.F(o)}function x(t=[]){return t.map(e=>e.text).join("")}function w(t,e){const o=e.checker.getPropertiesOfType(t),n={};return o.forEach(i=>{const r=A(e.checker.getTypeOfSymbol(i)).type,s=e.checker.getSignaturesOfType(r,m.SignatureKind.Call)[0]?.parameters?.[0];if(s){const c=e.checker.getTypeOfSymbol(s);n[i.name]={type:e.typeToString(c)},e.extractType(c)}else n[i.name]={type:"{}"}}),n}function N(t,e){const o=e.checker.getPropertiesOfType(t),n={},i={};return o.forEach(r=>{if(["onVnode","ref_"].some(s=>r.name.startsWith(s))||["ref","class","style","key"].includes(r.name))return;const l=e.checker.getTypeOfSymbol(r);if(e.extractType(l),W(r.name)){i[H(r.name)]=L(l,r,e);return}n[r.name]=L(l,r,e)}),{emits:i,props:n}}function v(t){return t.models=Object.keys(t.properties??{}).reduce((e,o)=>(t.emits?.[`update:${o}`]&&(e[o]=t.properties[o],delete t.properties[o],delete t.emits[`update:${o}`]),e),{}),t}function A(t){if(t.isUnion()){const e=t.types.filter(o=>o.flags!==m.TypeFlags.Undefined);if(e.length===1)return{optional:!0,type:e[0]}}return{type:t}}function L(t,e,o){const n=A(t);return p.F({description:h(e,o.checker).description,optional:n.optional,type:o.typeToString(n.type)})}function W(t){return/^on[A-Z]/.test(t)}function H(t){return t=t.slice(2),t.charAt(0).toLowerCase()+t.slice(1)}function K(t,e){return Object.fromEntries((t.getTypeParameters()??[]).map(o=>{let n="unknown";const i=o.getDefault();i&&(n=e.typeToString(i));const r=o.getConstraint();return r&&(n=e.typeToString(r)),[o.symbol.name,n]}))}function Q(t,e){const o=new Map,n=t.getExportsOfModule(e);for(const i of n){let r=i;for(;r.flags&m.SymbolFlags.Alias;)r=t.getAliasedSymbol(r);o.set(i.name,r)}return o}function k(t,e){let o=t.getFullyQualifiedName(e);return o.includes('".')&&(o=o.split('".').pop()),o.includes(").")&&(o=o.split(").").pop()),o}function F(t,e){for(const[o,n]of Object.entries(e))t=t.replace(new RegExp(`\\b${o}\\b`,"g"),n);return t}function R(t){const e=[];return t.members.forEach(n=>{const i=n.name.getText();if(n.initializer){let r;m.isStringLiteral(n.initializer)?r=`"${n.initializer.text}"`:m.isNumericLiteral(n.initializer)?r=n.initializer.text:r=n.initializer.getText(),e.push(`${i} = ${r}`)}else e.push(i)}),`{ ${e.join(", ")} }`}function $(t){if(t.getFlags()&(f.TypeFlags.StringLike|f.TypeFlags.NumberLike|f.TypeFlags.BooleanLike|f.TypeFlags.ESSymbolLike|f.TypeFlags.Void|f.TypeFlags.Undefined|f.TypeFlags.Null|f.TypeFlags.Any|f.TypeFlags.Unknown|f.TypeFlags.Never))return!1;const o=t.getSymbol();if(!o)return!0;const n=o.declarations?.[0];if(!n)return!0;const i=n.getSourceFile();return!(/lib\..*\.d\.ts$/.test(i.fileName)||i.fileName.startsWith("/@vue/"))}const E=f.TypeFormatFlags.WriteArrowStyleSignature|f.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType;class D{constructor(e){this.program=e,this.checker=e.getTypeChecker()}checker;index;cache=new Set;result;get(e){if(this.index=this.program.getSourceFile(e),!this.index)throw new Error(`Cannot find file ${e}`);const o=this.checker.getSymbolAtLocation(this.index);if(!o)throw new Error(`Cannot find module ${e}`);this.result={components:{},functions:{},types:{}};const n=this.index.statements.find(i=>f.isExportAssignment(i));if(n){const r=this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];r&&this.exportFunction("default",r)}return this.exportModule(o),this.result}exportModule(e){const o=Q(this.checker,e);for(const[n,i]of o.entries()){let r=this.checker.getTypeOfSymbol(i);if(r.symbol&&r.symbol.flags&f.SymbolFlags.Module){const s=r.symbol.exports?.get("default");s&&(r=this.checker.getTypeOfSymbol(s))}const l=r.symbol||r.aliasSymbol;if(l?.flags&f.SymbolFlags.Function){const s=this.checker.getTypeOfSymbol(l),c=this.checker.getSignaturesOfType(s,f.SignatureKind.Call)[0];if(c){const a=k(this.checker,l);this.exportFunction(a,c)}}else if(this.typeToString(r).includes("DefineComponent<"))try{this.exportComponent(n,r)}catch(c){console.error(`Fail to export component ${n}`),console.error(c)}}}exportComponent(e,o){const n=o.getConstructSignatures()[0];if(!n)return;const i=this.checker.getReturnTypeOfSignature(n),r={},l=this.checker.getPropertyOfType(i,"$props");if(l){const c=this.checker.getTypeOfSymbol(l),a=N(c,this);r.properties=a.props,r.emits=a.emits}const s=this.checker.getPropertyOfType(i,"$slots");if(s){const c=this.checker.getTypeOfSymbol(s);r.slots=w(c,this)}this.result.components[e]=v(r)}exportFunction(e,o){const n=h(o,this.checker),i=K(o,this),r=o.getParameters().map(s=>{const c=s.valueDeclaration??this.index,a=this.checker.getTypeOfSymbol(s);this.extractType(a,c);const u=s.valueDeclaration?.initializer?.getText();return p.F({default:u,description:n.params?.[s.name],name:s.name,optional:!!c.questionToken||u!==void 0||void 0,type:F(this.typeToString(a),i)})});if(r.some(s=>s.name?.startsWith("__VLS_"))){const s={},c=r.findIndex(y=>y.name==="__VLS_props"),a=o.getParameters()[c];if(a){const y=this.checker.getTypeOfSymbol(a),b=N(y,this);s.properties=b.props,s.emits=b.emits,Object.values(s.properties).forEach(C=>{C.type=F(C.type,i)})}const u=r.findIndex(y=>y.name==="__VLS_slots"),g=o.getParameters()[u];if(g){const y=this.checker.getTypeOfSymbol(g);s.slots=w(y,this),Object.values(s.slots).forEach(b=>{b.type=F(b.type,i)})}this.result.components[e]=v(s);return}const l=this.checker.getReturnTypeOfSignature(o);this.extractType(l),this.result.functions[e]=p.F({description:n.description,parameters:r,return:{description:n.returns,type:F(this.typeToString(l),i)}})}extractType(e,o=this.index){if(this.cache.has(e))return;this.cache.add(e);const n=e.symbol||e.aliasSymbol;if((e.isUnion()||e.isIntersection())&&!(n?.flags&f.SymbolFlags.Enum)&&e.types.forEach(i=>{this.extractType(i,o)}),n){if(this.checker.getFullyQualifiedName(n).includes("/@vue/"))return;const i=k(this.checker,n);if(n.flags&f.SymbolFlags.Enum){const r=n.valueDeclaration||n.declarations?.[0];if(r&&f.isEnumDeclaration(r)){const l=k(this.checker,n);this.result.types[l]=p.F({...h(n,this.checker),type:R(r)})}return}if(n.flags&f.SymbolFlags.Namespace){const r=n;this.exportModule(r)}if(n.flags&f.SymbolFlags.TypeAlias){const r=n.valueDeclaration||n.declarations?.[0];if(!r)return;const l=Object.fromEntries((r?.typeParameters??[]).map(s=>{let c="unknown";const a=s.default;if(a){const g=this.checker.getTypeFromTypeNode(a);c=this.typeToString(g)}const u=s.constraint;if(u){const g=this.checker.getTypeFromTypeNode(u);c=this.typeToString(g)}return[s.symbol.name,c]}));this.result.types[i]={...h(n,this.checker),type:F(this.typeToString(e,E|f.TypeFormatFlags.InTypeAlias),l)}}if(n.flags&f.SymbolFlags.Interface&&$(e)){const r=n.getDeclarations()[0];if(r){const l=this.checker.getPropertiesOfType(e),s={};l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);this.extractType(a,r),s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional)||void 0,type:this.typeToString(a)}}),this.result.types[i]={...h(n,this.checker),type:s}}}if(n.flags&f.SymbolFlags.TypeLiteral){const r=k(this.checker,e.aliasSymbol||e.symbol),l=this.checker.getPropertiesOfType(e),s={};if(["Promise","Partial","Pick","Omit","Required"].includes(r)){this.cache.delete(e),this.extractType(e.aliasTypeArguments[0]);return}if(e.aliasTypeArguments?.some(c=>!$(c)))return;l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional),type:this.typeToString(a)}}),r!=="__type"&&(this.result.types[r]={...h(n,this.checker),type:s})}}if(e.flags&f.TypeFlags.Object){const i=e;if($(e)&&this.checker.getPropertiesOfType(e).forEach(l=>{const s=this.checker.getTypeOfSymbol(l);this.extractType(s,o)}),i.objectFlags&f.ObjectFlags.Reference){const r=i;this.checker.getTypeArguments(r).forEach(s=>{this.extractType(s,o)})}}}typeToString(e,o=E){return this.checker.typeToString(e,void 0,o)}}function M(t,e="unknown"){const o={components:{},functions:{},types:{}};for(const[s,c]of Object.entries(t.types))o.types[s]=n(c,s);for(const[s,c]of Object.entries(t.functions))o.functions[s]=i(c,s);for(const[s,c]of Object.entries(t.components))o.components[s]=r(c,s);return o;function n(s,c=""){if(typeof s.type=="string"){if(s.type==="{}")return p.u.void();const a={...l(p.ot$1(s.type)),...p.F({description:s.description,name:c?.split(".").pop()||void 0,optional:s.optional})};if(s.default)switch(a.type){case p.i.boolean:a.default=s.default==="true";break;case p.i.number:a.default=Number(s.default);break;case p.i.string:a.default=s.default;break}return a.type===p.i.object&&!Object.keys(a.properties).length&&(a.customizable=!0),a}else{const a=p.u.object(p.ot(s.type,({key:u,value:g})=>n(g,u)),p.F({description:s.description,name:c?.split(".").pop(),optional:s.optional}));return Object.keys(a.properties).length||(a.customizable=!0),a}}function i(s,c=""){return{...p.F({description:s.description,name:c?.split(".").pop()}),parameters:(s.parameters??[]).map(a=>n(a,a.name)),return:n(s.return,"result")}}function r(s,c=""){return{...p.F({name:c?.split(".").pop()}),emits:p.ot(s.emits,({value:a})=>n(a)),models:p.ot(s.models,({value:a})=>n(a)),properties:p.ot(s.properties,({key:a,value:u})=>n(u,a)),slots:p.ot(s.slots,({value:a})=>n(a))}}function l(s,c=""){return p.d(s,u=>{if(u.type===p.i.interface)return{...a(u.className,c),description:u.description,name:u.name,optional:u.optional}});function a(u,g=""){let y=`${g}${u}`;for(;!t.types[y]&&y.indexOf(".")!==-1;)y=y.substring(y.indexOf(".")+1);return t.types[y]?p.u.type(["packages",e,...y.split(".")]):p.u.interface(u)}}}function Z(t){for(;;){const e=O.join(t,"tsconfig.json");if(J.existsSync(e))return e;const o=O.dirname(t);if(o===t)return;t=o}}function B(t){const e=m.readConfigFile(t,m.sys.readFile);if(e.error)throw new Error(`Failed to read tsconfig.json: ${e.error.messageText}`);return m.parseJsonConfigFileContent(e.config,m.sys,O.dirname(t))}function G(t,e){const o=O.join(process.cwd(),"__temp__.ts"),n=m.createCompilerHost(e),i=m.resolveModuleName(t,o,e,n);if(i.resolvedModule)return i.resolvedModule.resolvedFileName}function z(t){const e=Z(t);if(!e)throw new Error(`Could not find tsconfig.json for: ${t}`);const n=B(e).options,i=G(t,n);if(!i)throw new Error(`Could not resolve module: ${t}`);const r=m.createCompilerHost(n),l=m.createProgram({host:r,options:n,rootNames:[i]}),s=l.getSourceFile(i);if(!s)throw new Error(`Could not get source file for: ${i}`);return{program:l,sourceFile:s}}const _=I.promises;async function X(t,e){const o=t.split("/").pop().split(".")[0],{program:n,sourceFile:i}=z(t),l=new D(n).get(i.fileName),s=M(l,o);if(s.components.default){const c=V(s,{name:o,path:t});await _.mkdir(e.split("/").slice(0,-1).join("/"),{recursive:!0}),await _.writeFile(e,c)}}exports.CTypeExport=D;exports.extractFile=X;exports.generateNodes=M;exports.getSourceFile=z;
|
|
16
|
+
}`}function h(t,e){const o={description:x(t.getDocumentationComment(e))||void 0};for(const n of t.getJsDocTags()){if(n.name==="param"){o.params||(o.params={});let i=x(n.text?.slice(1)).trim();i.startsWith("- ")&&(i=i.slice(2));const r=n.text[0]?.text;o.params[r]=i;continue}o[n.name]=x(n.text)}return p.F(o)}function x(t=[]){return t.map(e=>e.text).join("")}function w(t,e){const o=e.checker.getPropertiesOfType(t),n={};return o.forEach(i=>{const r=A(e.checker.getTypeOfSymbol(i)).type,s=e.checker.getSignaturesOfType(r,m.SignatureKind.Call)[0]?.parameters?.[0];if(s){const c=e.checker.getTypeOfSymbol(s);n[i.name]={type:e.typeToString(c)},e.extractType(c)}else n[i.name]={type:"{}"}}),n}function N(t,e){const o=e.checker.getPropertiesOfType(t),n={},i={};return o.forEach(r=>{if(["onVnode","ref_"].some(s=>r.name.startsWith(s))||["ref","class","style","key"].includes(r.name))return;const l=e.checker.getTypeOfSymbol(r);if(e.extractType(l),W(r.name)){i[H(r.name)]=L(l,r,e);return}n[r.name]=L(l,r,e)}),{emits:i,props:n}}function v(t){return t.models=Object.keys(t.properties??{}).reduce((e,o)=>(t.emits?.[`update:${o}`]&&(e[o]=t.properties[o],delete t.properties[o],delete t.emits[`update:${o}`]),e),{}),t}function A(t){if(t.isUnion()){const e=t.types.filter(o=>o.flags!==m.TypeFlags.Undefined);if(e.length===1)return{optional:!0,type:e[0]}}return{type:t}}function L(t,e,o){const n=A(t);return p.F({description:h(e,o.checker).description,optional:n.optional,type:o.typeToString(n.type)})}function W(t){return/^on[A-Z]/.test(t)}function H(t){return t=t.slice(2),t.charAt(0).toLowerCase()+t.slice(1)}function K(t,e){return Object.fromEntries((t.getTypeParameters()??[]).map(o=>{let n="unknown";const i=o.getDefault();i&&(n=e.typeToString(i));const r=o.getConstraint();return r&&(n=e.typeToString(r)),[o.symbol.name,n]}))}function Q(t,e){const o=new Map,n=t.getExportsOfModule(e);for(const i of n){let r=i;for(;r.flags&m.SymbolFlags.Alias;)r=t.getAliasedSymbol(r);o.set(i.name,r)}return o}function k(t,e){let o=t.getFullyQualifiedName(e);return o.includes('".')&&(o=o.split('".').pop()),o.includes(").")&&(o=o.split(").").pop()),o}function F(t,e){for(const[o,n]of Object.entries(e))t=t.replace(new RegExp(`\\b${o}\\b`,"g"),n);return t}function R(t){const e=[];return t.members.forEach(n=>{const i=n.name.getText();if(n.initializer){let r;m.isStringLiteral(n.initializer)?r=`"${n.initializer.text}"`:m.isNumericLiteral(n.initializer)?r=n.initializer.text:r=n.initializer.getText(),e.push(`${i} = ${r}`)}else e.push(i)}),`{ ${e.join(", ")} }`}function $(t){if(t.getFlags()&(f.TypeFlags.StringLike|f.TypeFlags.NumberLike|f.TypeFlags.BooleanLike|f.TypeFlags.ESSymbolLike|f.TypeFlags.Void|f.TypeFlags.Undefined|f.TypeFlags.Null|f.TypeFlags.Any|f.TypeFlags.Unknown|f.TypeFlags.Never))return!1;const o=t.getSymbol();if(!o)return!0;const n=o.declarations?.[0];if(!n)return!0;const i=n.getSourceFile();return!(/lib\..*\.d\.ts$/.test(i.fileName)||i.fileName.startsWith("/@vue/"))}const E=f.TypeFormatFlags.WriteArrowStyleSignature|f.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope|f.TypeFormatFlags.NoTruncation|f.TypeFormatFlags.UseFullyQualifiedType;class D{constructor(e){this.program=e,this.checker=e.getTypeChecker()}checker;index;cache=new Set;result;get(e){if(this.index=this.program.getSourceFile(e),!this.index)throw new Error(`Cannot find file ${e}`);const o=this.checker.getSymbolAtLocation(this.index);if(!o)throw new Error(`Cannot find module ${e}`);this.result={components:{},functions:{},types:{}};const n=this.index.statements.find(i=>f.isExportAssignment(i));if(n){const r=this.checker.getTypeAtLocation(n.expression).getCallSignatures()[0];r&&this.exportFunction("default",r)}return this.exportModule(o),this.result}exportModule(e){const o=Q(this.checker,e);for(const[n,i]of o.entries()){let r=this.checker.getTypeOfSymbol(i);if(r.symbol&&r.symbol.flags&f.SymbolFlags.Module){const s=r.symbol.exports?.get("default");s&&(r=this.checker.getTypeOfSymbol(s))}const l=r.symbol||r.aliasSymbol;if(l?.flags&f.SymbolFlags.Function){const s=this.checker.getTypeOfSymbol(l),c=this.checker.getSignaturesOfType(s,f.SignatureKind.Call)[0];if(c){const a=k(this.checker,l);this.exportFunction(a,c)}}else if(this.typeToString(r).includes("DefineComponent<"))try{this.exportComponent(n,r)}catch(c){console.error(`Fail to export component ${n}`),console.error(c)}}}exportComponent(e,o){const n=o.getConstructSignatures()[0];if(!n)return;const i=this.checker.getReturnTypeOfSignature(n),r={},l=this.checker.getPropertyOfType(i,"$props");if(l){const c=this.checker.getTypeOfSymbol(l),a=N(c,this);r.properties=a.props,r.emits=a.emits}const s=this.checker.getPropertyOfType(i,"$slots");if(s){const c=this.checker.getTypeOfSymbol(s);r.slots=w(c,this)}this.result.components[e]=v(r)}exportFunction(e,o){const n=h(o,this.checker),i=K(o,this),r=o.getParameters().map(s=>{const c=s.valueDeclaration??this.index,a=this.checker.getTypeOfSymbol(s);this.extractType(a,c);const u=s.valueDeclaration?.initializer?.getText();return p.F({default:u,description:n.params?.[s.name],name:s.name,optional:!!c.questionToken||u!==void 0||void 0,type:F(this.typeToString(a),i)})});if(r.some(s=>s.name?.startsWith("__VLS_"))){const s={},c=r.findIndex(y=>y.name==="__VLS_props"),a=o.getParameters()[c];if(a){const y=this.checker.getTypeOfSymbol(a),b=N(y,this);s.properties=b.props,s.emits=b.emits,Object.values(s.properties).forEach(C=>{C.type=F(C.type,i)})}const u=r.findIndex(y=>y.name==="__VLS_slots"),g=o.getParameters()[u];if(g){const y=this.checker.getTypeOfSymbol(g);s.slots=w(y,this),Object.values(s.slots).forEach(b=>{b.type=F(b.type,i)})}this.result.components[e]=v(s);return}const l=this.checker.getReturnTypeOfSignature(o);this.extractType(l),this.result.functions[e]=p.F({description:n.description,parameters:r,return:{description:n.returns,type:F(this.typeToString(l),i)}})}extractType(e,o=this.index){if(this.cache.has(e))return;this.cache.add(e);const n=e.symbol||e.aliasSymbol;if((e.isUnion()||e.isIntersection())&&!(n?.flags&f.SymbolFlags.Enum)&&e.types.forEach(i=>{this.extractType(i,o)}),n){if(this.checker.getFullyQualifiedName(n).includes("/@vue/"))return;const i=k(this.checker,n);if(n.flags&f.SymbolFlags.Enum){const r=n.valueDeclaration||n.declarations?.[0];if(r&&f.isEnumDeclaration(r)){const l=k(this.checker,n);this.result.types[l]=p.F({...h(n,this.checker),type:R(r)})}return}if(n.flags&f.SymbolFlags.Namespace){const r=n;this.exportModule(r)}if(n.flags&f.SymbolFlags.TypeAlias){const r=n.valueDeclaration||n.declarations?.[0];if(!r)return;const l=Object.fromEntries((r?.typeParameters??[]).map(s=>{let c="unknown";const a=s.default;if(a){const g=this.checker.getTypeFromTypeNode(a);c=this.typeToString(g)}const u=s.constraint;if(u){const g=this.checker.getTypeFromTypeNode(u);c=this.typeToString(g)}return[s.symbol.name,c]}));this.result.types[i]={...h(n,this.checker),type:F(this.typeToString(e,E|f.TypeFormatFlags.InTypeAlias),l)}}if(n.flags&f.SymbolFlags.Interface&&$(e)){const r=n.getDeclarations()[0];if(r){const l=this.checker.getPropertiesOfType(e),s={};l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);this.extractType(a,r),s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional)||void 0,type:this.typeToString(a)}}),this.result.types[i]={...h(n,this.checker),type:s}}}if(n.flags&f.SymbolFlags.TypeLiteral){const r=k(this.checker,e.aliasSymbol||e.symbol),l=this.checker.getPropertiesOfType(e),s={};if(["Promise","Partial","Pick","Omit","Required"].includes(r)){this.cache.delete(e),this.extractType(e.aliasTypeArguments[0]);return}if(e.aliasTypeArguments?.some(c=>!$(c)))return;l.forEach(c=>{const a=this.checker.getTypeOfSymbol(c);s[c.name]={...h(c,this.checker),optional:!!(c.flags&f.SymbolFlags.Optional),type:this.typeToString(a)}}),r!=="__type"&&(this.result.types[r]={...h(n,this.checker),type:s})}}if(e.flags&f.TypeFlags.Object){const i=e;if($(e)&&this.checker.getPropertiesOfType(e).forEach(l=>{const s=this.checker.getTypeOfSymbol(l);this.extractType(s,o)}),i.objectFlags&f.ObjectFlags.Reference){const r=i;this.checker.getTypeArguments(r).forEach(s=>{this.extractType(s,o)})}}}typeToString(e,o=E){return this.checker.typeToString(e,void 0,o)}}function M(t,e="unknown"){const o={components:{},functions:{},types:{}};for(const[s,c]of Object.entries(t.types))o.types[s]=n(c,s);for(const[s,c]of Object.entries(t.functions))o.functions[s]=i(c,s);for(const[s,c]of Object.entries(t.components))o.components[s]=r(c,s);return o;function n(s,c=""){if(typeof s.type=="string"){if(s.type==="{}")return p.u.void();const a={...l(p.ot$1(s.type)),...p.F({description:s.description,name:c?.split(".").pop()||void 0,optional:s.optional})};if(s.default)switch(a.type){case p.i.boolean:a.default=s.default==="true";break;case p.i.number:a.default=Number(s.default);break;case p.i.string:a.default=s.default;break}return a.type===p.i.object&&!Object.keys(a.properties).length&&(a.customizable=!0),a}else{const a=p.u.object(p.ot(s.type,({key:u,value:g})=>n(g,u)),p.F({description:s.description,name:c?.split(".").pop(),optional:s.optional}));return Object.keys(a.properties).length||(a.customizable=!0),a}}function i(s,c=""){return{...p.F({description:s.description,name:c?.split(".").pop()}),parameters:(s.parameters??[]).map(a=>n(a,a.name)),return:n(s.return,"result")}}function r(s,c=""){return{...p.F({name:c?.split(".").pop()}),emits:p.ot(s.emits,({value:a})=>n(a)),models:p.ot(s.models,({value:a})=>n(a)),properties:p.ot(s.properties,({key:a,value:u})=>n(u,a)),slots:p.ot(s.slots,({value:a})=>n(a))}}function l(s,c=""){return p.m(s,u=>{if(u.type===p.i.interface)return{...a(u.className,c),description:u.description,name:u.name,optional:u.optional}});function a(u,g=""){let y=`${g}${u}`;for(;!t.types[y]&&y.indexOf(".")!==-1;)y=y.substring(y.indexOf(".")+1);return t.types[y]?p.u.type(["packages",e,...y.split(".")]):p.u.interface(u)}}}function Z(t){for(;;){const e=O.join(t,"tsconfig.json");if(J.existsSync(e))return e;const o=O.dirname(t);if(o===t)return;t=o}}function B(t){const e=m.readConfigFile(t,m.sys.readFile);if(e.error)throw new Error(`Failed to read tsconfig.json: ${e.error.messageText}`);return m.parseJsonConfigFileContent(e.config,m.sys,O.dirname(t))}function G(t,e){const o=O.join(process.cwd(),"__temp__.ts"),n=m.createCompilerHost(e),i=m.resolveModuleName(t,o,e,n);if(i.resolvedModule)return i.resolvedModule.resolvedFileName}function z(t){const e=Z(t);if(!e)throw new Error(`Could not find tsconfig.json for: ${t}`);const n=B(e).options,i=G(t,n);if(!i)throw new Error(`Could not resolve module: ${t}`);const r=m.createCompilerHost(n),l=m.createProgram({host:r,options:n,rootNames:[i]}),s=l.getSourceFile(i);if(!s)throw new Error(`Could not get source file for: ${i}`);return{program:l,sourceFile:s}}const _=I.promises;async function X(t,e){const o=t.split("/").pop().split(".")[0],{program:n,sourceFile:i}=z(t),l=new D(n).get(i.fileName),s=M(l,o);if(s.components.default){const c=V(s,{name:o,path:t});await _.mkdir(e.split("/").slice(0,-1).join("/"),{recursive:!0}),await _.writeFile(e,c)}}exports.CTypeExport=D;exports.extractFile=X;exports.generateNodes=M;exports.getSourceFile=z;
|
package/dist/extractor.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import M from "node:fs";
|
|
2
|
-
import { i as m, o as F, F as d, u as x, a as I,
|
|
2
|
+
import { i as m, o as F, F as d, u as x, a as I, m as U } from "./index-Dv9uuje9.js";
|
|
3
3
|
import * as y from "typescript";
|
|
4
4
|
import p from "typescript";
|
|
5
5
|
import * as j from "path";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";function E(e){if(typeof e!="object")return e;try{return JSON.parse(JSON.stringify(e))}catch{return structuredClone(e)}}function h(e){if(Array.isArray(e))return e.map(h);if(typeof e!="object")return e;const n={};for(const[r,o]of Object.entries(e)){if(typeof o=="function"){n[r]=o;continue}n[r]=h(o)}return n}function y(e,n){return e?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,n({key:r,value:o})])):{}}function g(e,n){return e?Object.fromEntries(Object.entries(e).filter(([r,o])=>n({key:r,value:o}))):{}}function J(e){e=E(e);for(const r in e)n(e,r);function n(r,o){if(typeof r[o]=="object"){for(const i in r[o])n(r[o],i);Object.keys(r[o]).length===0&&delete r[o]}}return e}var f=(e=>(e.exec="exec",e.number="number",e.string="string",e.boolean="boolean",e.object="object",e.record="record",e.array="array",e.interface="interface",e.type="type",e.function="function",e.union="union",e.unknown="unknown",e.undefined="undefined",e.void="void",e))(f||{});const t={type:(e,n={})=>({...n,type:"type",target:e}),array:(e,n={})=>({...n,type:"array",items:e}),boolean:(e={})=>({...e,type:"boolean"}),exec:(e={})=>({...e,type:"exec"}),function:(e={type:"object",properties:{}},n={type:"void"},r={})=>({...r,type:"function",inputs:e,output:n}),interface:(e,n={})=>({...n,type:"interface",className:typeof e=="string"?e:e.name}),number:(e={})=>({...e,type:"number"}),object:(e={},n={})=>({...n,type:"object",properties:e}),record:(e,n,r={})=>({...r,type:"record",key:e,value:n}),string:(e={})=>({...e,type:"string"}),undefined:(e={})=>({...e,type:"undefined"}),union:(e,n={})=>({...n,type:"union",elements:e}),unknown:(e={})=>({...e,type:"unknown"}),void:(e={})=>({...e,type:"void"})},d={omit(e,n){return{...e,properties:g(e.properties,({key:r})=>!n.includes(r))}},partial(e,n=!1){return{...e,properties:y(e.properties,({value:r})=>({...r,optional:!n||!r.required}))}},pick(e,n){return{...e,properties:g(e.properties,({key:r})=>n.includes(r))}},promise(e){return{...e,promise:!0}},required(e){return{...e,properties:y(e.properties,({value:n})=>({...n,optional:!1}))}}};var O=(e=>(e.function="function",e.macro="macro",e.operation="operation",e))(O||{}),N=(e=>(e.Frontend="frontend",e.Backend="backend",e.Desktop="desktop",e.Shared="shared",e))(N||{});function Z(e){return e}function j(e){const n=[];for(e=e.replaceAll(/ +/g," "),e=e.replaceAll(/\s*\n\s*/g,`
|
|
2
|
+
`);e.length;){if([" ",`
|
|
3
|
+
`].includes(e[0])){e=e.slice(1);continue}if(e.startsWith("/*")){const i=e.indexOf("*/");n.push(e.slice(0,i+2)),e=e.slice(i+2);continue}const r=e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];if(r){e=e.slice(r.length),n.push(r);continue}const o=e.match(/^([0-9]+)/)?.[0];if(o){e=e.slice(o.length),n.push(o);continue}if(e[0]===">"&&n.at(-1)==="="){n.pop(),n.push("=>"),e=e.slice(1);continue}n.push(e[0]),e=e.slice(1)}return n}const x=[["(",")"],["[","]"],["{","}"],["<",">"],["'","'"],['"','"']];function k(e){return m(a(e,";"))}function p(e,n,r=1){const o=[];for(x.find(i=>i[1]===n)?.[0];e.length&&(e[0],!(e[0]===n&&(r--,r<=0)));){const i=b(e);if(o.push(i),r===0&&typeof i=="object"&&i.type==="wrap"&&i.style.endsWith(n))break}return e.shift(),o}function q(e,n){for(;e.length;){if(e[0]===n){e.shift();break}e.shift()}}function a(e,n){const r=[[]];for(;e.length;){if(e[0]===n){r.push([]),e.shift();continue}r.at(-1).push(b(e))}return r.filter(o=>o.length)}function b(e){let n=e.shift(),r=!1;if(n==="export"){if(r=!0,n=e.shift(),n==="=")return{type:"export",content:e.shift()};if(n==="as")return q(e,";"),b(e)}if(n==="declare"&&(n=e.shift()),n==="namespace"){const o=e.shift();e.shift();const i=a(p(e,"}",0),";");return e.unshift(";"),{name:o,type:n,content:i,export:r}}if(n==="function"){const o=e.shift(),i=e.shift(),s={name:o,type:n};i==="<"&&(s.template=p(e,">"),e.shift());const u=a(p(e,")",0),",");return s.export=r,s.params=u,e[0]===":"&&(e.shift(),s.returns=p(e,";")),e.unshift(";"),s}if(n==="interface"){const o=e.shift();e.shift();const i=a(p(e,"}",0),";");return e.unshift(";"),{name:o,type:"interface",content:i}}if(n==="type"&&/^[A-Za-z0-9]*$/.test(e[0])){const o=e.shift(),i=e.shift(),s={name:o,type:n};return i==="<"&&(s.template=p(e,">"),e.shift()),s.content=p(e,";"),e.unshift(";"),s}if(n==="enum"){const o=e.shift();e.shift();const i=p(e,"}");e.unshift(";");const s=Object.fromEntries(i.join("").split(",").filter(u=>u.trim()).map(u=>{if(u.includes("=")){const[z,W]=u.split("=");return[JSON.parse(W),z]}return[o,o]}));return{name:o,type:"enum",options:s}}if(typeof n=="string"&&n.startsWith("/*"))return{type:"comment",content:F(n)};for(const o of x)if(n===o[0])return{type:"wrap",content:a(p(e,o[1]),";").map(i=>a(i,",")).map(i=>a(i,"|")),style:o.join("")};return n}function m(e){return Array.isArray(e)?e.length===1?m(e[0]):e.map(n=>m(n)):typeof e=="object"&&e!==null?y(e,({value:n})=>m(n)):e}function F(e){return e=e.trim(),e.startsWith("/**")&&e.endsWith("*/")?(e=e.slice(3,-2).split(`
|
|
4
|
+
`).map(n=>{const r=n.trim();return r.startsWith("* ")?r.slice(2):r}).join(`
|
|
5
|
+
`).trim(),e.trim()):e}function A(e){e.elements.find(i=>[f.undefined,f.void].includes(i.type))&&(e.optional=!0,e.elements=e.elements.filter(i=>![f.undefined,f.void].includes(i.type)));const n=e.elements.filter(i=>i.type===f.union);if(n.length>0){e.elements=e.elements.filter(i=>i.type!==f.union);for(const i of n)e.elements.push(...i.elements)}const r=e.elements.filter(i=>i.type===f.string);if(r.length>1){const i=[];let s=!1;for(const u of r)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.string),s?e.elements.push(t.string()):e.elements.push(t.string({enum:i}))}const o=e.elements.filter(i=>i.type===f.number);if(o.length>1){const i=[];let s=!1;for(const u of o)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.number),s?e.elements.push(t.number()):e.elements.push(t.number({enum:i}))}if(e.elements.length===1){const i=e.elements[0];return i.optional=e.optional,i}return e.elements.length===0?t.void():e}function w(e){return e.className==="Array"?t.array(e.options.template[0]):e.className==="keyof"?t.string():e.className==="Record"?t.object({}):e.className==="PropertyKey"?t.union([t.string(),t.number()]):["Promise","Partial","Required"].includes(e.className)?d[e.className.toLocaleLowerCase()](e.options.template[0]):["Omit","Pick"].includes(e.className)?d[e.className.toLocaleLowerCase()](e.options.template[0],e.options.template[1]?.enum):e}function c(e,n={}){if(typeof e=="string")return e==="string"?t.string(n):e==="number"?t.number(n):e==="boolean"?t.boolean(n):e==="undefined"?t.void(n):["unknown","any"].includes(e)?t.unknown(n):["undefined","null"].includes(e)?t.undefined(n):w(t.interface(e,n));if(Array.isArray(e)){if(e[0]==="readonly"&&e.shift(),e.length===1)return c(e[0],n);if(e.includes("|"))return A(t.union(v(e,r=>r==="|").map(r=>c(r)),n));if(e.includes("&"))return A(t.union(v(e,r=>r==="&").map(r=>c(r)),n));if(e.at(-1)?.type==="wrap"&&e.at(-1).style==="[]")return t.array(c(e.slice(0,-1)),n);if(e[0]==="import"&&e[2]===".")return c(e.slice(3),n);if(e.length===2&&e[1].type==="wrap"&&e[1].style==="<>"){let r=e[1].content;return Array.isArray(r)||(r=[r]),Array.isArray(r[0])||(r.some(o=>o.type==="wrap"&&o.style==="[]")||r.some(o=>o.type==="wrap"&&o.style==="<>")||r.includes("&")||r.includes("|")?r=[r]:r=r.map(o=>[o])),r=r.map(o=>c(o)),w(t.interface(e[0],{...n,options:{template:r}}))}if(e.length===3&&e[1]==="=>"){const r=!e[0].content.length||Array.isArray(e[0].content[0])?e[0].content:[e[0].content];return t.function(t.object(Object.fromEntries(r.map(o=>[o[0],c(o.slice(2))]))),c(e[2]))}return c(e[0],n)}if(typeof e=="object"&&e!==null&&e.type==="wrap"){if(["''",'""'].includes(e.style))return t.string({...n,enum:[e.content]});if(e.style==="{}"){const r=!e.content.length||Array.isArray(e.content[0])?e.content:[e.content];return t.object(Object.fromEntries(r.filter(o=>typeof o[0]=="string").map(o=>[o[0],o[1]==="?"?c(o.slice(3),{optional:!0}):c(o.slice(2))])),n)}if(e.style==="[]")return e.content[1]===":"?t.array(c(e.content.slice(2)),n):t.array(c(e.content),n);if(e.style==="()")return c(e.content,n)}return console.log("Unknown element"),console.log(e),t.unknown()}function v(e,n){const r=[[]];for(const o of e)n(o)?r.push([]):r[r.length-1].push(o);return r}function L(e){try{if(/^[A-Za-z]+\??:/.test(e)){const[,n,r,o]=e.match(/([A-Za-z]+)(\??):(.*)/),i=c(k(j(o)));return i.name=n,r==="?"&&(i.optional=!0),i}return c(k(j(e)))}catch(n){return console.error("Failed to parse type",e),console.error(n),t.unknown()}}function l(e,n){if(e=n(e)||e,e.type===f.object)for(const r in e.properties)e.properties[r]=l(e.properties[r],n);if(e.type===f.array&&(e.items=l(e.items,n)),e.type===f.function&&(e.inputs=l(e.inputs,n),e.output=l(e.output,n)),e.type===f.union)for(const r in e.elements)e.elements[r]=l(e.elements[r],n);return e}exports.F=J;exports.J=N;exports.T=Z;exports._=O;exports.i=f;exports.m=l;exports.ot=y;exports.ot$1=L;exports.u=t;exports.x=d;exports.y=h;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function
|
|
1
|
+
function z(e) {
|
|
2
2
|
if (typeof e != "object")
|
|
3
3
|
return e;
|
|
4
4
|
try {
|
|
@@ -7,18 +7,33 @@ function x(e) {
|
|
|
7
7
|
return structuredClone(e);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
+
function d(e) {
|
|
11
|
+
if (Array.isArray(e))
|
|
12
|
+
return e.map(d);
|
|
13
|
+
if (typeof e != "object")
|
|
14
|
+
return e;
|
|
15
|
+
const n = {};
|
|
16
|
+
for (const [r, o] of Object.entries(e)) {
|
|
17
|
+
if (typeof o == "function") {
|
|
18
|
+
n[r] = o;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
n[r] = d(o);
|
|
22
|
+
}
|
|
23
|
+
return n;
|
|
24
|
+
}
|
|
10
25
|
function y(e, n) {
|
|
11
26
|
return e ? Object.fromEntries(
|
|
12
27
|
Object.entries(e).map(([r, o]) => [r, n({ key: r, value: o })])
|
|
13
28
|
) : {};
|
|
14
29
|
}
|
|
15
|
-
function
|
|
30
|
+
function b(e, n) {
|
|
16
31
|
return e ? Object.fromEntries(
|
|
17
32
|
Object.entries(e).filter(([r, o]) => n({ key: r, value: o }))
|
|
18
33
|
) : {};
|
|
19
34
|
}
|
|
20
|
-
function
|
|
21
|
-
e =
|
|
35
|
+
function J(e) {
|
|
36
|
+
e = z(e);
|
|
22
37
|
for (const r in e)
|
|
23
38
|
n(e, r);
|
|
24
39
|
function n(r, o) {
|
|
@@ -85,7 +100,7 @@ const t = {
|
|
|
85
100
|
omit(e, n) {
|
|
86
101
|
return {
|
|
87
102
|
...e,
|
|
88
|
-
properties:
|
|
103
|
+
properties: b(
|
|
89
104
|
e.properties,
|
|
90
105
|
({ key: r }) => !n.includes(r)
|
|
91
106
|
)
|
|
@@ -103,7 +118,7 @@ const t = {
|
|
|
103
118
|
pick(e, n) {
|
|
104
119
|
return {
|
|
105
120
|
...e,
|
|
106
|
-
properties:
|
|
121
|
+
properties: b(
|
|
107
122
|
e.properties,
|
|
108
123
|
({ key: r }) => n.includes(r)
|
|
109
124
|
)
|
|
@@ -122,11 +137,11 @@ const t = {
|
|
|
122
137
|
};
|
|
123
138
|
}
|
|
124
139
|
};
|
|
125
|
-
var
|
|
126
|
-
function
|
|
140
|
+
var W = /* @__PURE__ */ ((e) => (e.function = "function", e.macro = "macro", e.operation = "operation", e))(W || {}), E = /* @__PURE__ */ ((e) => (e.Frontend = "frontend", e.Backend = "backend", e.Desktop = "desktop", e.Shared = "shared", e))(E || {});
|
|
141
|
+
function L(e) {
|
|
127
142
|
return e;
|
|
128
143
|
}
|
|
129
|
-
function
|
|
144
|
+
function j(e) {
|
|
130
145
|
const n = [];
|
|
131
146
|
for (e = e.replaceAll(/ +/g, " "), e = e.replaceAll(/\s*\n\s*/g, `
|
|
132
147
|
`); e.length; ) {
|
|
@@ -158,7 +173,7 @@ function b(e) {
|
|
|
158
173
|
}
|
|
159
174
|
return n;
|
|
160
175
|
}
|
|
161
|
-
const
|
|
176
|
+
const O = [
|
|
162
177
|
["(", ")"],
|
|
163
178
|
["[", "]"],
|
|
164
179
|
["{", "}"],
|
|
@@ -166,19 +181,19 @@ const v = [
|
|
|
166
181
|
["'", "'"],
|
|
167
182
|
['"', '"']
|
|
168
183
|
];
|
|
169
|
-
function
|
|
184
|
+
function k(e) {
|
|
170
185
|
return m(a(e, ";"));
|
|
171
186
|
}
|
|
172
187
|
function p(e, n, r = 1) {
|
|
173
188
|
const o = [];
|
|
174
|
-
for (
|
|
189
|
+
for (O.find((i) => i[1] === n)?.[0]; e.length && (e[0], !(e[0] === n && (r--, r <= 0))); ) {
|
|
175
190
|
const i = h(e);
|
|
176
191
|
if (o.push(i), r === 0 && typeof i == "object" && i.type === "wrap" && i.style.endsWith(n))
|
|
177
192
|
break;
|
|
178
193
|
}
|
|
179
194
|
return e.shift(), o;
|
|
180
195
|
}
|
|
181
|
-
function
|
|
196
|
+
function Z(e, n) {
|
|
182
197
|
for (; e.length; ) {
|
|
183
198
|
if (e[0] === n) {
|
|
184
199
|
e.shift();
|
|
@@ -204,7 +219,7 @@ function h(e) {
|
|
|
204
219
|
if (r = !0, n = e.shift(), n === "=")
|
|
205
220
|
return { type: "export", content: e.shift() };
|
|
206
221
|
if (n === "as")
|
|
207
|
-
return
|
|
222
|
+
return Z(e, ";"), h(e);
|
|
208
223
|
}
|
|
209
224
|
if (n === "declare" && (n = e.shift()), n === "namespace") {
|
|
210
225
|
const o = e.shift();
|
|
@@ -235,16 +250,16 @@ function h(e) {
|
|
|
235
250
|
e.unshift(";");
|
|
236
251
|
const s = Object.fromEntries(i.join("").split(",").filter((u) => u.trim()).map((u) => {
|
|
237
252
|
if (u.includes("=")) {
|
|
238
|
-
const [
|
|
239
|
-
return [JSON.parse(
|
|
253
|
+
const [N, x] = u.split("=");
|
|
254
|
+
return [JSON.parse(x), N];
|
|
240
255
|
}
|
|
241
256
|
return [o, o];
|
|
242
257
|
}));
|
|
243
258
|
return { name: o, type: "enum", options: s };
|
|
244
259
|
}
|
|
245
260
|
if (typeof n == "string" && n.startsWith("/*"))
|
|
246
|
-
return { type: "comment", content:
|
|
247
|
-
for (const o of
|
|
261
|
+
return { type: "comment", content: q(n) };
|
|
262
|
+
for (const o of O)
|
|
248
263
|
if (n === o[0])
|
|
249
264
|
return {
|
|
250
265
|
type: "wrap",
|
|
@@ -256,7 +271,7 @@ function h(e) {
|
|
|
256
271
|
function m(e) {
|
|
257
272
|
return Array.isArray(e) ? e.length === 1 ? m(e[0]) : e.map((n) => m(n)) : typeof e == "object" && e !== null ? y(e, ({ value: n }) => m(n)) : e;
|
|
258
273
|
}
|
|
259
|
-
function
|
|
274
|
+
function q(e) {
|
|
260
275
|
return e = e.trim(), e.startsWith("/**") && e.endsWith("*/") ? (e = e.slice(3, -2).split(`
|
|
261
276
|
`).map((n) => {
|
|
262
277
|
const r = n.trim();
|
|
@@ -264,7 +279,7 @@ function F(e) {
|
|
|
264
279
|
}).join(`
|
|
265
280
|
`).trim(), e.trim()) : e;
|
|
266
281
|
}
|
|
267
|
-
function
|
|
282
|
+
function A(e) {
|
|
268
283
|
e.elements.find((i) => [f.undefined, f.void].includes(i.type)) && (e.optional = !0, e.elements = e.elements.filter((i) => ![f.undefined, f.void].includes(i.type)));
|
|
269
284
|
const n = e.elements.filter((i) => i.type === f.union);
|
|
270
285
|
if (n.length > 0) {
|
|
@@ -294,7 +309,7 @@ function k(e) {
|
|
|
294
309
|
}
|
|
295
310
|
return e.elements.length === 0 ? t.void() : e;
|
|
296
311
|
}
|
|
297
|
-
function
|
|
312
|
+
function w(e) {
|
|
298
313
|
return e.className === "Array" ? t.array(e.options.template[0]) : e.className === "keyof" ? t.string() : e.className === "Record" ? t.object({}) : e.className === "PropertyKey" ? t.union([
|
|
299
314
|
t.string(),
|
|
300
315
|
t.number()
|
|
@@ -302,18 +317,18 @@ function A(e) {
|
|
|
302
317
|
}
|
|
303
318
|
function c(e, n = {}) {
|
|
304
319
|
if (typeof e == "string")
|
|
305
|
-
return e === "string" ? t.string(n) : e === "number" ? t.number(n) : e === "boolean" ? t.boolean(n) : e === "undefined" ? t.void(n) : ["unknown", "any"].includes(e) ? t.unknown(n) : ["undefined", "null"].includes(e) ? t.undefined(n) :
|
|
320
|
+
return e === "string" ? t.string(n) : e === "number" ? t.number(n) : e === "boolean" ? t.boolean(n) : e === "undefined" ? t.void(n) : ["unknown", "any"].includes(e) ? t.unknown(n) : ["undefined", "null"].includes(e) ? t.undefined(n) : w(t.interface(e, n));
|
|
306
321
|
if (Array.isArray(e)) {
|
|
307
322
|
if (e[0] === "readonly" && e.shift(), e.length === 1)
|
|
308
323
|
return c(e[0], n);
|
|
309
324
|
if (e.includes("|"))
|
|
310
|
-
return
|
|
311
|
-
|
|
325
|
+
return A(t.union(
|
|
326
|
+
v(e, (r) => r === "|").map((r) => c(r)),
|
|
312
327
|
n
|
|
313
328
|
));
|
|
314
329
|
if (e.includes("&"))
|
|
315
|
-
return
|
|
316
|
-
|
|
330
|
+
return A(t.union(
|
|
331
|
+
v(e, (r) => r === "&").map((r) => c(r)),
|
|
317
332
|
n
|
|
318
333
|
));
|
|
319
334
|
if (e.at(-1)?.type === "wrap" && e.at(-1).style === "[]")
|
|
@@ -322,7 +337,7 @@ function c(e, n = {}) {
|
|
|
322
337
|
return c(e.slice(3), n);
|
|
323
338
|
if (e.length === 2 && e[1].type === "wrap" && e[1].style === "<>") {
|
|
324
339
|
let r = e[1].content;
|
|
325
|
-
return Array.isArray(r) || (r = [r]), Array.isArray(r[0]) || (r.some((o) => o.type === "wrap" && o.style === "[]") || r.some((o) => o.type === "wrap" && o.style === "<>") || r.includes("&") || r.includes("|") ? r = [r] : r = r.map((o) => [o])), r = r.map((o) => c(o)),
|
|
340
|
+
return Array.isArray(r) || (r = [r]), Array.isArray(r[0]) || (r.some((o) => o.type === "wrap" && o.style === "[]") || r.some((o) => o.type === "wrap" && o.style === "<>") || r.includes("&") || r.includes("|") ? r = [r] : r = r.map((o) => [o])), r = r.map((o) => c(o)), w(t.interface(e[0], { ...n, options: { template: r } }));
|
|
326
341
|
}
|
|
327
342
|
if (e.length === 3 && e[1] === "=>") {
|
|
328
343
|
const r = !e[0].content.length || Array.isArray(e[0].content[0]) ? e[0].content : [e[0].content];
|
|
@@ -354,19 +369,19 @@ function c(e, n = {}) {
|
|
|
354
369
|
}
|
|
355
370
|
return console.log("Unknown element"), console.log(e), t.unknown();
|
|
356
371
|
}
|
|
357
|
-
function
|
|
372
|
+
function v(e, n) {
|
|
358
373
|
const r = [[]];
|
|
359
374
|
for (const o of e)
|
|
360
375
|
n(o) ? r.push([]) : r[r.length - 1].push(o);
|
|
361
376
|
return r;
|
|
362
377
|
}
|
|
363
|
-
function
|
|
378
|
+
function P(e) {
|
|
364
379
|
try {
|
|
365
380
|
if (/^[A-Za-z]+\??:/.test(e)) {
|
|
366
|
-
const [, n, r, o] = e.match(/([A-Za-z]+)(\??):(.*)/), i = c(j(
|
|
381
|
+
const [, n, r, o] = e.match(/([A-Za-z]+)(\??):(.*)/), i = c(k(j(o)));
|
|
367
382
|
return i.name = n, r === "?" && (i.optional = !0), i;
|
|
368
383
|
}
|
|
369
|
-
return c(j(
|
|
384
|
+
return c(k(j(e)));
|
|
370
385
|
} catch (n) {
|
|
371
386
|
return console.error("Failed to parse type", e), console.error(n), t.unknown();
|
|
372
387
|
}
|
|
@@ -381,14 +396,15 @@ function l(e, n) {
|
|
|
381
396
|
return e;
|
|
382
397
|
}
|
|
383
398
|
export {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
l as d,
|
|
399
|
+
J as F,
|
|
400
|
+
E as J,
|
|
401
|
+
L as T,
|
|
402
|
+
W as _,
|
|
403
|
+
P as a,
|
|
390
404
|
f as i,
|
|
405
|
+
l as m,
|
|
391
406
|
y as o,
|
|
392
407
|
t as u,
|
|
393
|
-
g as x
|
|
408
|
+
g as x,
|
|
409
|
+
d as y
|
|
394
410
|
};
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index-CWrYVK_G.cjs");var a=(i=>(i.ViteImport="viteImport",i.VitePlugin="vitePlugin",i.AppImport="appImport",i.AppBody="appBody",i.Style="style",i.ServerImport="serverImport",i.ServerBody="serverBody",i))(a||{}),g=(i=>(i.Color="color",i.FontSize="font-size",i.FontWeight="font-weight",i.FontFamily="font-family",i.Length="length",i.Time="time",i))(g||{});function c(i){return i}async function p(i,o){const r=t.y(i),u=o.app?.config?.plugins?.[i.id]?.config;for(const e of["build","editor","inject"])if(r[e])for(const n in r[e])r[e][n]=await l(r[e][n],{...o,config:u});return r}async function l(i,o){return typeof i=="function"?i({app:o.app,config:o.config,internal:o.internal,mode:o.mode||"editor"}):i}exports.ELogicScope=t.J;exports.ELogicType=t._;exports.EVarType=t.i;exports.LogicType=t.u;exports.LogicUtil=t.x;exports.makeLogicNode=t.T;exports.EInjectionKey=a;exports.ETokenType=g;exports.getPluginParam=l;exports.loadPlugin=p;exports.makePlugin=c;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Component } from 'vue';
|
|
2
2
|
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
|
|
3
|
-
import { PluginOption } from 'vite';
|
|
4
3
|
|
|
5
4
|
declare type Component_2 = {
|
|
6
5
|
name: string;
|
|
@@ -65,6 +64,16 @@ declare enum EHistoryMode {
|
|
|
65
64
|
Memory = "memory"
|
|
66
65
|
}
|
|
67
66
|
|
|
67
|
+
export declare enum EInjectionKey {
|
|
68
|
+
ViteImport = "viteImport",
|
|
69
|
+
VitePlugin = "vitePlugin",
|
|
70
|
+
AppImport = "appImport",
|
|
71
|
+
AppBody = "appBody",
|
|
72
|
+
Style = "style",
|
|
73
|
+
ServerImport = "serverImport",
|
|
74
|
+
ServerBody = "serverBody"
|
|
75
|
+
}
|
|
76
|
+
|
|
68
77
|
declare enum ELayoutElement {
|
|
69
78
|
input = "input",
|
|
70
79
|
div = "div",
|
|
@@ -150,6 +159,8 @@ export declare enum EVarType {
|
|
|
150
159
|
|
|
151
160
|
export declare function getPluginParam<T>(target: TOption<TEnv, T>, env: Partial<TEnv>): Promise<T>;
|
|
152
161
|
|
|
162
|
+
export declare function loadPlugin<TConfig extends TSchema, TInternal>(plugin: TPlugin<TConfig, TInternal>, env: Partial<TEnv>): Promise<TBasePlugin<TConfig, TInternal>>;
|
|
163
|
+
|
|
153
164
|
export declare const LogicType: {
|
|
154
165
|
type: <T extends TSchema>(target: Array<string>, args?: TArguments) => TType<T>;
|
|
155
166
|
array: <T extends TSchema, TArgs extends TArguments<Array<T>>>(items: T, args?: TArgs) => TArray<T> & TArgs;
|
|
@@ -339,6 +350,48 @@ declare interface TArray<T extends TSchema = TSchema> {
|
|
|
339
350
|
static: Array<Static<T>>;
|
|
340
351
|
}
|
|
341
352
|
|
|
353
|
+
export declare type TBasePlugin<TConfig extends TSchema = TSchema, TInternal = unknown> = {
|
|
354
|
+
build?: {
|
|
355
|
+
backImports?: Array<{
|
|
356
|
+
name: string;
|
|
357
|
+
version?: string;
|
|
358
|
+
}>;
|
|
359
|
+
frontImports?: Array<{
|
|
360
|
+
name: string;
|
|
361
|
+
version?: string;
|
|
362
|
+
}>;
|
|
363
|
+
injections?: Partial<Record<EInjectionKey, string>>;
|
|
364
|
+
};
|
|
365
|
+
config?: TConfig;
|
|
366
|
+
dependencies?: Array<{
|
|
367
|
+
id: string;
|
|
368
|
+
name: string;
|
|
369
|
+
target: string;
|
|
370
|
+
}>;
|
|
371
|
+
description?: string;
|
|
372
|
+
editor?: {
|
|
373
|
+
components?: Array<TComponent>;
|
|
374
|
+
nodes?: Array<TLogicNode>;
|
|
375
|
+
templates?: Array<TTemplate>;
|
|
376
|
+
tokens?: Array<TToken>;
|
|
377
|
+
wrapper?: TComponent;
|
|
378
|
+
};
|
|
379
|
+
icon: string;
|
|
380
|
+
id: string;
|
|
381
|
+
inject?: {
|
|
382
|
+
css?: string;
|
|
383
|
+
js?: string;
|
|
384
|
+
};
|
|
385
|
+
interface?: Component;
|
|
386
|
+
internal?: TInternal;
|
|
387
|
+
lifecycle?: {
|
|
388
|
+
mount?: (env: TEnv<TConfig, TInternal>) => Promise<void> | void;
|
|
389
|
+
unmount?: (env: TEnv<TConfig, TInternal>) => Promise<void> | void;
|
|
390
|
+
update?: (env: TEnv<TConfig, TInternal>) => Promise<void> | void;
|
|
391
|
+
};
|
|
392
|
+
name: string;
|
|
393
|
+
};
|
|
394
|
+
|
|
342
395
|
declare interface TBoolean {
|
|
343
396
|
type: EVarType.boolean;
|
|
344
397
|
static: boolean;
|
|
@@ -350,16 +403,19 @@ declare type TCanvasExport = {
|
|
|
350
403
|
};
|
|
351
404
|
|
|
352
405
|
export declare type TComponent<TProps extends Record<string, TSchema> = Record<string, TSchema>> = {
|
|
406
|
+
build?: {
|
|
407
|
+
import?: Array<{
|
|
408
|
+
name: string;
|
|
409
|
+
target: string;
|
|
410
|
+
}>;
|
|
411
|
+
name?: string;
|
|
412
|
+
};
|
|
353
413
|
component: Component;
|
|
354
414
|
documentation?: {
|
|
355
415
|
description?: string;
|
|
356
416
|
link?: string;
|
|
357
417
|
};
|
|
358
418
|
emits?: Record<string, TSchema>;
|
|
359
|
-
import?: Array<{
|
|
360
|
-
name: string;
|
|
361
|
-
target: string;
|
|
362
|
-
}>;
|
|
363
419
|
models?: Record<string, TSchema>;
|
|
364
420
|
name: string;
|
|
365
421
|
properties?: TProps;
|
|
@@ -477,7 +533,7 @@ declare type TExportNodeResult = {
|
|
|
477
533
|
types: Record<string, TSchema>;
|
|
478
534
|
};
|
|
479
535
|
|
|
480
|
-
declare type TFileExport = (TFolderExport | TComponentExport | TConfigExport | TCronExport | TDatabaseExport | TRouteExport | TScriptExport | TStoreExport | TTextExport | TTypeExport | TMediaExport) & {
|
|
536
|
+
export declare type TFileExport = (TFolderExport | TComponentExport | TConfigExport | TCronExport | TDatabaseExport | TRouteExport | TScriptExport | TStoreExport | TTextExport | TTypeExport | TMediaExport) & {
|
|
481
537
|
isEditing?: boolean;
|
|
482
538
|
};
|
|
483
539
|
|
|
@@ -752,47 +808,22 @@ declare type TOnlyVarsOf<TNodeInterfaceDescriptor> = {
|
|
|
752
808
|
[TAnchor in keyof TNodeInterfaceDescriptor as TNodeInterfaceDescriptor[TAnchor] extends TExec ? never : TAnchor]: TNodeInterfaceDescriptor[TAnchor];
|
|
753
809
|
};
|
|
754
810
|
|
|
755
|
-
declare type TOption<TParams = unknown, TResult = unknown> = TResult | ((env: TParams) => Promise<TResult> | TResult
|
|
811
|
+
declare type TOption<TParams = unknown, TResult = unknown> = TResult | ((env: TParams) => Promise<TResult> | TResult);
|
|
756
812
|
|
|
757
|
-
export declare type TPlugin<TConfig extends TSchema = TSchema, TInternal = unknown> = {
|
|
758
|
-
build?: {
|
|
759
|
-
|
|
760
|
-
name: string;
|
|
761
|
-
version?: string;
|
|
762
|
-
}>>;
|
|
763
|
-
plugins?: TOption<TEnv<TConfig, TInternal>, Array<PluginOption>>;
|
|
764
|
-
};
|
|
765
|
-
config?: TConfig;
|
|
766
|
-
dependencies?: Array<{
|
|
767
|
-
id: string;
|
|
768
|
-
name: string;
|
|
769
|
-
target: string;
|
|
770
|
-
}>;
|
|
771
|
-
description?: string;
|
|
772
|
-
editor?: {
|
|
773
|
-
components?: TOption<TEnv<TConfig, TInternal>, Array<TComponent>>;
|
|
774
|
-
nodes?: TOption<TEnv<TConfig, TInternal>, Array<TLogicNode>>;
|
|
775
|
-
tokens?: TOption<TEnv<TConfig, TInternal>, Array<TToken>>;
|
|
776
|
-
wrapper?: TOption<TEnv<TConfig, TInternal>, Component>;
|
|
813
|
+
export declare type TPlugin<TConfig extends TSchema = TSchema, TInternal = unknown, TBase extends TBasePlugin<TConfig, TInternal> = TBasePlugin<TConfig, TInternal>> = Omit<TBase, "build" | "editor" | "inject"> & {
|
|
814
|
+
[TCategory in "build" | "editor" | "inject"]?: {
|
|
815
|
+
[TKey in keyof NonNullable<TBase[TCategory]>]: TOption<TEnv<TConfig, TInternal>, NonNullable<TBase[TCategory]>[TKey]>;
|
|
777
816
|
};
|
|
778
|
-
icon: string;
|
|
779
|
-
id: string;
|
|
780
|
-
inject?: {
|
|
781
|
-
css?: TOption<TEnv<TConfig, TInternal>, string>;
|
|
782
|
-
js?: TOption<TEnv<TConfig, TInternal>, string>;
|
|
783
|
-
};
|
|
784
|
-
interface?: Component;
|
|
785
|
-
internal?: TInternal;
|
|
786
|
-
lifecycle?: {
|
|
787
|
-
mount?: (env: TEnv<TConfig, TInternal>) => Promise<void> | void;
|
|
788
|
-
unmount?: (env: TEnv<TConfig, TInternal>) => Promise<void> | void;
|
|
789
|
-
update?: (env: TEnv<TConfig, TInternal>) => Promise<void> | void;
|
|
790
|
-
};
|
|
791
|
-
name: string;
|
|
792
817
|
};
|
|
793
818
|
|
|
794
819
|
declare type TProperties = Record<string, TSchema>;
|
|
795
820
|
|
|
821
|
+
export declare type TProxyPlugin<TConfig extends TSchema = TSchema, TInternal = unknown, TBase extends TBasePlugin<TConfig, TInternal> = TBasePlugin<TConfig, TInternal>> = Omit<TBase, "build" | "editor" | "inject"> & {
|
|
822
|
+
[TCategory in "build" | "editor" | "inject"]?: {
|
|
823
|
+
[TKey in keyof NonNullable<TBase[TCategory]>]: Promise<NonNullable<TBase[TCategory]>[TKey]>;
|
|
824
|
+
};
|
|
825
|
+
};
|
|
826
|
+
|
|
796
827
|
declare interface TRecord<TKey extends TString | TNumber = TString, TValue extends TSchema = TSchema> {
|
|
797
828
|
type: EVarType.record;
|
|
798
829
|
key: TKey;
|
|
@@ -852,6 +883,12 @@ declare interface TString {
|
|
|
852
883
|
static: string;
|
|
853
884
|
}
|
|
854
885
|
|
|
886
|
+
export declare type TTemplate = {
|
|
887
|
+
name: string;
|
|
888
|
+
preview?: string;
|
|
889
|
+
template: TFileExport;
|
|
890
|
+
};
|
|
891
|
+
|
|
855
892
|
declare type TTextExport = {
|
|
856
893
|
name: string;
|
|
857
894
|
type: EElementType.Text;
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { y as p } from "./index-Dv9uuje9.js";
|
|
2
|
+
import { J as d, _ as y, i as L, u as P, x as S, T as h } from "./index-Dv9uuje9.js";
|
|
3
|
+
var e = /* @__PURE__ */ ((o) => (o.ViteImport = "viteImport", o.VitePlugin = "vitePlugin", o.AppImport = "appImport", o.AppBody = "appBody", o.Style = "style", o.ServerImport = "serverImport", o.ServerBody = "serverBody", o))(e || {}), f = /* @__PURE__ */ ((o) => (o.Color = "color", o.FontSize = "font-size", o.FontWeight = "font-weight", o.FontFamily = "font-family", o.Length = "length", o.Time = "time", o))(f || {});
|
|
4
|
+
function l(o) {
|
|
5
|
+
return o;
|
|
5
6
|
}
|
|
6
|
-
async function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
async function m(o, r) {
|
|
8
|
+
const t = p(o), n = r.app?.config?.plugins?.[o.id]?.config;
|
|
9
|
+
for (const i of ["build", "editor", "inject"])
|
|
10
|
+
if (t[i])
|
|
11
|
+
for (const a in t[i])
|
|
12
|
+
t[i][a] = await g(t[i][a], { ...r, config: n });
|
|
13
|
+
return t;
|
|
14
|
+
}
|
|
15
|
+
async function g(o, r) {
|
|
16
|
+
return typeof o == "function" ? o({
|
|
17
|
+
app: r.app,
|
|
18
|
+
config: r.config,
|
|
19
|
+
internal: r.internal,
|
|
20
|
+
mode: r.mode || "editor"
|
|
21
|
+
}) : o;
|
|
13
22
|
}
|
|
14
23
|
export {
|
|
15
|
-
e as
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
e as EInjectionKey,
|
|
25
|
+
d as ELogicScope,
|
|
26
|
+
y as ELogicType,
|
|
27
|
+
f as ETokenType,
|
|
28
|
+
L as EVarType,
|
|
29
|
+
P as LogicType,
|
|
30
|
+
S as LogicUtil,
|
|
31
|
+
g as getPluginParam,
|
|
32
|
+
m as loadPlugin,
|
|
33
|
+
h as makeLogicNode,
|
|
34
|
+
l as makePlugin
|
|
24
35
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luna-park/plugin",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Plugin helper for Luna Park.",
|
|
6
6
|
"homepage": "https://luna-park.app",
|
|
@@ -35,24 +35,24 @@
|
|
|
35
35
|
"dist/**"
|
|
36
36
|
],
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@fastify/cors": "^11.
|
|
38
|
+
"@fastify/cors": "^11.2.0",
|
|
39
39
|
"@fastify/static": "^8.3.0",
|
|
40
40
|
"@fortawesome/fontawesome-svg-core": "^7.1.0",
|
|
41
41
|
"@luna-park/eslint-config": "^1.0.2",
|
|
42
|
-
"@microsoft/api-extractor": "^7.55.
|
|
43
|
-
"@vitest/ui": "^4.0.
|
|
42
|
+
"@microsoft/api-extractor": "^7.55.2",
|
|
43
|
+
"@vitest/ui": "^4.0.15",
|
|
44
44
|
"eslint": "^9.39.1",
|
|
45
45
|
"fastify": "^5.6.2",
|
|
46
46
|
"rimraf": "^6.1.2",
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
|
-
"typescript-eslint": "^8.
|
|
48
|
+
"typescript-eslint": "^8.49.0",
|
|
49
49
|
"unplugin-dts": "1.0.0-beta.6",
|
|
50
|
-
"vite": "^7.2.
|
|
51
|
-
"vitest": "^4.0.
|
|
52
|
-
"vue": "^3.5.
|
|
53
|
-
"@luna-park/utils": "^2.0.0",
|
|
50
|
+
"vite": "^7.2.7",
|
|
51
|
+
"vitest": "^4.0.15",
|
|
52
|
+
"vue": "^3.5.25",
|
|
54
53
|
"@luna-park/logicnodes": "^2.0.0",
|
|
55
|
-
"@luna-park/shared": "^1.0.0"
|
|
54
|
+
"@luna-park/shared": "^1.0.0",
|
|
55
|
+
"@luna-park/utils": "^2.0.0"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@fastify/cors": "^11.1.0",
|
package/dist/index-DmZsz62R.cjs
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";function W(e){if(typeof e!="object")return e;try{return JSON.parse(JSON.stringify(e))}catch{return structuredClone(e)}}function y(e,n){return e?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,n({key:r,value:o})])):{}}function g(e,n){return e?Object.fromEntries(Object.entries(e).filter(([r,o])=>n({key:r,value:o}))):{}}function E(e){e=W(e);for(const r in e)n(e,r);function n(r,o){if(typeof r[o]=="object"){for(const i in r[o])n(r[o],i);Object.keys(r[o]).length===0&&delete r[o]}}return e}var f=(e=>(e.exec="exec",e.number="number",e.string="string",e.boolean="boolean",e.object="object",e.record="record",e.array="array",e.interface="interface",e.type="type",e.function="function",e.union="union",e.unknown="unknown",e.undefined="undefined",e.void="void",e))(f||{});const t={type:(e,n={})=>({...n,type:"type",target:e}),array:(e,n={})=>({...n,type:"array",items:e}),boolean:(e={})=>({...e,type:"boolean"}),exec:(e={})=>({...e,type:"exec"}),function:(e={type:"object",properties:{}},n={type:"void"},r={})=>({...r,type:"function",inputs:e,output:n}),interface:(e,n={})=>({...n,type:"interface",className:typeof e=="string"?e:e.name}),number:(e={})=>({...e,type:"number"}),object:(e={},n={})=>({...n,type:"object",properties:e}),record:(e,n,r={})=>({...r,type:"record",key:e,value:n}),string:(e={})=>({...e,type:"string"}),undefined:(e={})=>({...e,type:"undefined"}),union:(e,n={})=>({...n,type:"union",elements:e}),unknown:(e={})=>({...e,type:"unknown"}),void:(e={})=>({...e,type:"void"})},h={omit(e,n){return{...e,properties:g(e.properties,({key:r})=>!n.includes(r))}},partial(e,n=!1){return{...e,properties:y(e.properties,({value:r})=>({...r,optional:!n||!r.required}))}},pick(e,n){return{...e,properties:g(e.properties,({key:r})=>n.includes(r))}},promise(e){return{...e,promise:!0}},required(e){return{...e,properties:y(e.properties,({value:n})=>({...n,optional:!1}))}}};var v=(e=>(e.function="function",e.macro="macro",e.operation="operation",e))(v||{}),O=(e=>(e.Frontend="frontend",e.Backend="backend",e.Desktop="desktop",e.Shared="shared",e))(O||{});function F(e){return e}function b(e){const n=[];for(e=e.replaceAll(/ +/g," "),e=e.replaceAll(/\s*\n\s*/g,`
|
|
2
|
-
`);e.length;){if([" ",`
|
|
3
|
-
`].includes(e[0])){e=e.slice(1);continue}if(e.startsWith("/*")){const i=e.indexOf("*/");n.push(e.slice(0,i+2)),e=e.slice(i+2);continue}const r=e.match(/^([a-zA-Z_][a-zA-Z0-9_.]*)/)?.[0];if(r){e=e.slice(r.length),n.push(r);continue}const o=e.match(/^([0-9]+)/)?.[0];if(o){e=e.slice(o.length),n.push(o);continue}if(e[0]===">"&&n.at(-1)==="="){n.pop(),n.push("=>"),e=e.slice(1);continue}n.push(e[0]),e=e.slice(1)}return n}const N=[["(",")"],["[","]"],["{","}"],["<",">"],["'","'"],['"','"']];function j(e){return m(l(e,";"))}function p(e,n,r=1){const o=[];for(N.find(i=>i[1]===n)?.[0];e.length&&(e[0],!(e[0]===n&&(r--,r<=0)));){const i=d(e);if(o.push(i),r===0&&typeof i=="object"&&i.type==="wrap"&&i.style.endsWith(n))break}return e.shift(),o}function J(e,n){for(;e.length;){if(e[0]===n){e.shift();break}e.shift()}}function l(e,n){const r=[[]];for(;e.length;){if(e[0]===n){r.push([]),e.shift();continue}r.at(-1).push(d(e))}return r.filter(o=>o.length)}function d(e){let n=e.shift(),r=!1;if(n==="export"){if(r=!0,n=e.shift(),n==="=")return{type:"export",content:e.shift()};if(n==="as")return J(e,";"),d(e)}if(n==="declare"&&(n=e.shift()),n==="namespace"){const o=e.shift();e.shift();const i=l(p(e,"}",0),";");return e.unshift(";"),{name:o,type:n,content:i,export:r}}if(n==="function"){const o=e.shift(),i=e.shift(),s={name:o,type:n};i==="<"&&(s.template=p(e,">"),e.shift());const u=l(p(e,")",0),",");return s.export=r,s.params=u,e[0]===":"&&(e.shift(),s.returns=p(e,";")),e.unshift(";"),s}if(n==="interface"){const o=e.shift();e.shift();const i=l(p(e,"}",0),";");return e.unshift(";"),{name:o,type:"interface",content:i}}if(n==="type"&&/^[A-Za-z0-9]*$/.test(e[0])){const o=e.shift(),i=e.shift(),s={name:o,type:n};return i==="<"&&(s.template=p(e,">"),e.shift()),s.content=p(e,";"),e.unshift(";"),s}if(n==="enum"){const o=e.shift();e.shift();const i=p(e,"}");e.unshift(";");const s=Object.fromEntries(i.join("").split(",").filter(u=>u.trim()).map(u=>{if(u.includes("=")){const[x,z]=u.split("=");return[JSON.parse(z),x]}return[o,o]}));return{name:o,type:"enum",options:s}}if(typeof n=="string"&&n.startsWith("/*"))return{type:"comment",content:Z(n)};for(const o of N)if(n===o[0])return{type:"wrap",content:l(p(e,o[1]),";").map(i=>l(i,",")).map(i=>l(i,"|")),style:o.join("")};return n}function m(e){return Array.isArray(e)?e.length===1?m(e[0]):e.map(n=>m(n)):typeof e=="object"&&e!==null?y(e,({value:n})=>m(n)):e}function Z(e){return e=e.trim(),e.startsWith("/**")&&e.endsWith("*/")?(e=e.slice(3,-2).split(`
|
|
4
|
-
`).map(n=>{const r=n.trim();return r.startsWith("* ")?r.slice(2):r}).join(`
|
|
5
|
-
`).trim(),e.trim()):e}function k(e){e.elements.find(i=>[f.undefined,f.void].includes(i.type))&&(e.optional=!0,e.elements=e.elements.filter(i=>![f.undefined,f.void].includes(i.type)));const n=e.elements.filter(i=>i.type===f.union);if(n.length>0){e.elements=e.elements.filter(i=>i.type!==f.union);for(const i of n)e.elements.push(...i.elements)}const r=e.elements.filter(i=>i.type===f.string);if(r.length>1){const i=[];let s=!1;for(const u of r)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.string),s?e.elements.push(t.string()):e.elements.push(t.string({enum:i}))}const o=e.elements.filter(i=>i.type===f.number);if(o.length>1){const i=[];let s=!1;for(const u of o)u.enum?i.push(...u.enum):s=!0;e.elements=e.elements.filter(u=>u.type!==f.number),s?e.elements.push(t.number()):e.elements.push(t.number({enum:i}))}if(e.elements.length===1){const i=e.elements[0];return i.optional=e.optional,i}return e.elements.length===0?t.void():e}function A(e){return e.className==="Array"?t.array(e.options.template[0]):e.className==="keyof"?t.string():e.className==="Record"?t.object({}):e.className==="PropertyKey"?t.union([t.string(),t.number()]):["Promise","Partial","Required"].includes(e.className)?h[e.className.toLocaleLowerCase()](e.options.template[0]):["Omit","Pick"].includes(e.className)?h[e.className.toLocaleLowerCase()](e.options.template[0],e.options.template[1]?.enum):e}function c(e,n={}){if(typeof e=="string")return e==="string"?t.string(n):e==="number"?t.number(n):e==="boolean"?t.boolean(n):e==="undefined"?t.void(n):["unknown","any"].includes(e)?t.unknown(n):["undefined","null"].includes(e)?t.undefined(n):A(t.interface(e,n));if(Array.isArray(e)){if(e[0]==="readonly"&&e.shift(),e.length===1)return c(e[0],n);if(e.includes("|"))return k(t.union(w(e,r=>r==="|").map(r=>c(r)),n));if(e.includes("&"))return k(t.union(w(e,r=>r==="&").map(r=>c(r)),n));if(e.at(-1)?.type==="wrap"&&e.at(-1).style==="[]")return t.array(c(e.slice(0,-1)),n);if(e[0]==="import"&&e[2]===".")return c(e.slice(3),n);if(e.length===2&&e[1].type==="wrap"&&e[1].style==="<>"){let r=e[1].content;return Array.isArray(r)||(r=[r]),Array.isArray(r[0])||(r.some(o=>o.type==="wrap"&&o.style==="[]")||r.some(o=>o.type==="wrap"&&o.style==="<>")||r.includes("&")||r.includes("|")?r=[r]:r=r.map(o=>[o])),r=r.map(o=>c(o)),A(t.interface(e[0],{...n,options:{template:r}}))}if(e.length===3&&e[1]==="=>"){const r=!e[0].content.length||Array.isArray(e[0].content[0])?e[0].content:[e[0].content];return t.function(t.object(Object.fromEntries(r.map(o=>[o[0],c(o.slice(2))]))),c(e[2]))}return c(e[0],n)}if(typeof e=="object"&&e!==null&&e.type==="wrap"){if(["''",'""'].includes(e.style))return t.string({...n,enum:[e.content]});if(e.style==="{}"){const r=!e.content.length||Array.isArray(e.content[0])?e.content:[e.content];return t.object(Object.fromEntries(r.filter(o=>typeof o[0]=="string").map(o=>[o[0],o[1]==="?"?c(o.slice(3),{optional:!0}):c(o.slice(2))])),n)}if(e.style==="[]")return e.content[1]===":"?t.array(c(e.content.slice(2)),n):t.array(c(e.content),n);if(e.style==="()")return c(e.content,n)}return console.log("Unknown element"),console.log(e),t.unknown()}function w(e,n){const r=[[]];for(const o of e)n(o)?r.push([]):r[r.length-1].push(o);return r}function q(e){try{if(/^[A-Za-z]+\??:/.test(e)){const[,n,r,o]=e.match(/([A-Za-z]+)(\??):(.*)/),i=c(j(b(o)));return i.name=n,r==="?"&&(i.optional=!0),i}return c(j(b(e)))}catch(n){return console.error("Failed to parse type",e),console.error(n),t.unknown()}}function a(e,n){if(e=n(e)||e,e.type===f.object)for(const r in e.properties)e.properties[r]=a(e.properties[r],n);if(e.type===f.array&&(e.items=a(e.items,n)),e.type===f.function&&(e.inputs=a(e.inputs,n),e.output=a(e.output,n)),e.type===f.union)for(const r in e.elements)e.elements[r]=a(e.elements[r],n);return e}exports.F=E;exports.J=O;exports.T=F;exports._=v;exports.d=a;exports.i=f;exports.ot=y;exports.ot$1=q;exports.u=t;exports.x=h;
|