rpc4next 0.3.5 → 0.3.7
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/rpc/cli/index.js +6 -1
- package/dist/rpc/lib/constants.d.ts +2 -1
- package/dist/rpc/lib/constants.js +1 -1
- package/dist/rpc/lib/types.d.ts +2 -1
- package/package.json +2 -1
- package/dist/rpc/cli/cli-handler.js +0 -1
- package/dist/rpc/cli/cli.js +0 -1
- package/dist/rpc/cli/constants.js +0 -1
- package/dist/rpc/cli/core/alias.js +0 -1
- package/dist/rpc/cli/core/cache.js +0 -1
- package/dist/rpc/cli/core/constants.js +0 -2
- package/dist/rpc/cli/core/generate-path-structure.js +0 -1
- package/dist/rpc/cli/core/path-utils.js +0 -1
- package/dist/rpc/cli/core/route-scanner.js +0 -4
- package/dist/rpc/cli/core/scan-utils.js +0 -1
- package/dist/rpc/cli/core/type-utils.js +0 -1
- package/dist/rpc/cli/debounce.js +0 -1
- package/dist/rpc/cli/generator.js +0 -1
- package/dist/rpc/cli/logger.js +0 -1
- package/dist/rpc/cli/types.js +0 -0
- package/dist/rpc/cli/watcher.js +0 -1
package/dist/rpc/cli/index.js
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{
|
|
2
|
+
import{Command as Wt}from"commander";import $t from"path";var R=["page.tsx","route.ts"],w=0,$=1,Y=1,M=20,W="\u2192";import U from"path";var et=(t,r)=>{let e=_(U.relative(U.dirname(t),r)).replace(/\.tsx?$/,"");return e.startsWith("../")||(e="./"+e),e},_=t=>t.replace(/\\/g,"/"),C=t=>U.relative(process.cwd(),t);import Pt from"fs";import Yt from"path";var rt=["Query","OptionalQuery"],O=" ",E=`
|
|
3
|
+
`,S=";",H=";",j="Endpoint",X="QueryKey",K="OptionalQueryKey",Q="ParamsKey",ot=[j,K,Q,X],nt="rpc4next/client";import Tt from"fs";import b from"path";import G from"path";var h=new Map,N=new Map,st=(t,r)=>{let e=G.resolve(r);[...t.keys()].forEach(o=>{let n=G.resolve(o);(n===e||e.startsWith(n+G.sep))&&t.delete(o)})},it=t=>{st(h,t)},at=t=>{st(N,t)};import vt from"fs";import bt from"crypto";var pt=(t,r)=>{let e=bt.createHash("md5").update(`${t}::${r}`).digest("hex").slice(0,16);return`${r}_${e}`};var I=(t,r)=>!t||!r?"":`Record<${t}, ${r}>`,L=t=>t.length===0||t.some(({name:r,type:e})=>!r||!e)?"":`{ ${t.map(({name:r,type:e})=>`"${r}": ${e}`).join(`${H} `)}${t.length>1?H:""} }`,D=(t,r,e)=>!t||!r?"":e?`import type { ${t} as ${e} } from "${r}"${S}`:`import type { ${t} } from "${r}"${S}`;var ct=(t,r,e,o)=>{let n=vt.readFileSync(r,"utf8"),i=e(n);if(!i)return;let s=et(t,r),p=pt(s,i);return{importName:p,importPath:s,importStatement:D(i,s,p),type:o(i,p)}},mt=(t,r)=>ct(t,r,e=>rt.find(o=>new RegExp(`export (interface ${o} ?{|type ${o} ?=)`).test(e)),(e,o)=>e==="Query"?I(X,o):I(K,o)),lt=(t,r,e)=>ct(t,r,o=>[e].find(n=>new RegExp(`export (async )?(function ${n} ?\\(|const ${n} ?=|\\{[^}]*\\b${n}\\b[^}]*\\} ?=|const \\{[^}]*\\b${n}\\b[^}]*\\} ?=|\\{[^}]*\\b${n}\\b[^}]*\\} from)`).test(o)),(o,n)=>L([{name:`$${o.toLowerCase()}`,type:`typeof ${n}`}]));var Ft=["GET","HEAD","OPTIONS","POST","PUT","DELETE","PATCH"],ut="_____",ft="___",Et="_",k=Ft.filter(t=>t!=="OPTIONS"),oe=k.map(t=>`$${t.toLowerCase()}`);var gt=new Set(R),ht=t=>{if(h.has(t))return h.get(t);let r=Tt.readdirSync(t,{withFileTypes:!0});for(let e of r){let{name:o}=e,n=b.join(t,o);if(o==="node_modules"||o.startsWith("_")||o.startsWith("(.)")||o.startsWith("(..)")||o.startsWith("(...)"))return h.set(t,!1),!1;if(e.isFile()&>.has(o))return h.set(t,!0),!0;if(e.isDirectory()&&ht(n))return h.set(t,!0),!0}return h.set(t,!1),!1},wt=(t,{isDynamic:r,isCatchAll:e,isOptionalCatchAll:o})=>{let n=t;return r&&(n=n.replace(/^\[+|\]+$/g,"")),(e||o)&&(n=n.replace(/^\.{3}/,"")),{paramName:n,keyName:`${o?ut:e?ft:r?Et:""}${n}`}},V=(t,r,e="",o=[])=>{if(N.has(r))return N.get(r);let n=e,i=e+O,s=[],p=[],a=[],m=[],c=[...o],x=Tt.readdirSync(r,{withFileTypes:!0}).filter(y=>{if(y.isDirectory()){let P=b.join(r,y.name);return ht(P)}return gt.has(y.name)}).sort();for(let y of x){let P=_(b.join(r,y.name));if(y.isDirectory()){let l=y.name,T=l.startsWith("(")&&l.endsWith(")"),u=l.startsWith("@"),f=l.startsWith("[[...")&&l.endsWith("]]"),g=l.startsWith("[...")&&l.endsWith("]"),d=l.startsWith("[")&&l.endsWith("]"),{paramName:At,keyName:Rt}=wt(l,{isDynamic:d,isCatchAll:g,isOptionalCatchAll:f}),Ot=d||g||f?[...c,{paramName:At,routeType:{isDynamic:d,isCatchAll:g,isOptionalCatchAll:f,isGroup:T,isParallel:u}}]:c,J=T||u,{pathStructure:Z,imports:Lt,paramsTypes:Dt}=V(t,P,J?n:i,Ot);if(p.push(...Lt),m.push(...Dt),J){let tt=Z.match(/^\s*\{([\s\S]*)\}\s*$/);tt&&s.push(`${i}${tt[1].trim()}`)}else s.push(`${i}"${Rt}": ${Z}`)}else{let l=mt(t,P);if(l){let{importStatement:T,importPath:u,type:f}=l;p.push({statement:T,path:u}),a.push(f)}if(k.forEach(T=>{let u=lt(t,P,T);if(u){let{importStatement:f,importPath:g,type:d}=u;p.push({statement:f,path:g}),a.push(d)}}),a.push(j),c.length>0){let T=c.map(({paramName:f,routeType:g})=>{let d=g.isCatchAll?"string[]":g.isOptionalCatchAll?"string[] | undefined":"string";return{name:f,type:d}}),u=L(T);m.push({paramsType:u,dirPath:b.dirname(P)}),a.push(I(Q,u))}}}let A=a.join(" & "),F=s.length>0?`{${E}${s.join(`,${E}`)}${E}${n}}`:"",z={pathStructure:A&&F?`${A} & ${F}`:A||F,imports:p,paramsTypes:m};return N.set(r,z),z};var yt=(t,r)=>{let{pathStructure:e,imports:o,paramsTypes:n}=V(t,r),i=`export type PathStructure = ${e}${S}`,s=o.length?`${o.sort((c,x)=>c.path.localeCompare(x.path,void 0,{numeric:!0})).map(c=>c.statement).join(E)}`:"",p=ot.filter(c=>e.includes(c)),a=D(p.join(" ,"),nt),m=n.map(({paramsType:c,dirPath:x})=>({paramsType:`export type Params = ${c}${S}`,dirPath:x}));return{pathStructure:`${a}${E}${s}${E}${E}${i}`,paramsTypes:m}};import v from"chalk";var q=(t,r,e="\u2192",o=24)=>t.padEnd(o)+` ${e} ${r}`,B=(t=0)=>O.repeat(t),dt=()=>({info:(t,r={})=>{let{indentLevel:e=0,event:o}=r,n=o?`${v.cyan(`[${o}]`)} `:"";console.log(`${B(e)}${n}${t}`)},success:(t,r={})=>{let{indentLevel:e=0}=r;console.log(`${B(e)}${v.green("\u2713")} ${t}`)},error:(t,r={})=>{let{indentLevel:e=0}=r;console.error(`${B(e)}${v.red("\u2717")} ${v.red(t)}`)}});var _t=({baseDir:t,outputPath:r,paramsFileName:e,logger:o})=>{o.info("Generating types...",{event:"generate"});let{pathStructure:n,paramsTypes:i}=yt(r,t);Pt.writeFileSync(r,n),o.success(q("Path structure type",C(r),W,M),{indentLevel:Y}),e&&(i.forEach(({paramsType:s,dirPath:p})=>{let a=Yt.join(p,e);Pt.writeFileSync(a,s)}),o.success(q("Params types",e,W,M),{indentLevel:Y}))};import Mt from"chokidar";var St=(t,r)=>{let e=null,o=!1,n=null,i=async(...s)=>{o=!0;try{await t(...s)}finally{if(o=!1,n){let p=n;n=null,i(...p)}}};return(...s)=>{e&&clearTimeout(e),e=setTimeout(()=>{if(o){n=s;return}i(...s)},r)}};var xt=(t,r,e)=>{e.info(`${C(t)}`,{event:"watch"});let o=a=>R.some(m=>a.endsWith(m)),n=new Set,i=St(()=>{n.forEach(a=>{it(a),at(a)}),n.clear(),r()},300),s=Mt.watch(t,{ignoreInitial:!0,ignored:(a,m)=>!!m?.isFile()&&!o(a)});s.on("ready",()=>{i(),s.on("all",(a,m)=>{if(o(m)){let c=C(m);e.info(c,{event:a}),n.add(m),i()}})}),s.on("error",a=>{a instanceof Error?e.error(`Watcher error: ${a.message}`):e.error(`Unknown watcher error: ${String(a)}`)});let p=()=>{s.close().then(()=>{e.info("Watcher closed.",{event:"watch"})}).catch(a=>{e.error(`Failed to close watcher: ${a.message}`)})};process.on("SIGINT",p),process.on("SIGTERM",p)};var Ct=(t,r,e,o)=>{try{return _t({baseDir:t,outputPath:r,paramsFileName:e,logger:o}),w}catch(n){return n instanceof Error?o.error(`Failed to generate: ${n.message}`):o.error(`Unknown error occurred during generate: ${String(n)}`),$}},Nt=(t,r,e,o)=>{let n=_($t.resolve(t)),i=_($t.resolve(r)),s=typeof e.paramsFile=="string"?e.paramsFile:null;return e.paramsFile!==void 0&&!s?(o.error("Error: --params-file requires a filename."),$):e.watch?(xt(n,()=>{Ct(n,i,s,o)},o),w):Ct(n,i,s,o)};var It=(t,r=dt())=>{let e=new Wt;e.description("Generate RPC client type definitions based on the Next.js path structure.").argument("<baseDir>","Base directory containing Next.js paths for type generation").argument("<outputPath>","Output path for the generated type definitions").option("-w, --watch","Watch mode: regenerate on file changes").option("-p, --params-file [filename]","Generate params types file with specified filename").action(async(o,n,i)=>{try{let s=await Nt(o,n,i,r);i.watch||process.exit(s)}catch(s){r.error(`Unexpected error occurred:${s instanceof Error?s.message:String(s)}`),process.exit($)}}),e.parse(t)};It(process.argv);
|
|
4
|
+
/*!
|
|
5
|
+
* Inspired by pathpida (https://github.com/aspida/pathpida),
|
|
6
|
+
* especially the design and UX of its CLI.
|
|
7
|
+
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
export declare const HTTP_METHODS: readonly ["GET", "HEAD", "OPTIONS", "POST", "PUT", "DELETE", "PATCH"];
|
|
1
2
|
export declare const OPTIONAL_CATCH_ALL_PREFIX = "_____";
|
|
2
3
|
export declare const CATCH_ALL_PREFIX = "___";
|
|
3
4
|
export declare const DYNAMIC_PREFIX = "_";
|
|
4
5
|
export declare const HTTP_METHODS_EXCLUDE_OPTIONS: ("GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "PATCH")[];
|
|
5
|
-
export declare const HTTP_METHOD_FUNC_KEYS: ("$
|
|
6
|
+
export declare const HTTP_METHOD_FUNC_KEYS: ("$get" | "$head" | "$post" | "$put" | "$delete" | "$patch")[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const T=["GET","HEAD","OPTIONS","POST","PUT","DELETE","PATCH"],t="_____",E="___",e="_",o=T.filter(_=>_!=="OPTIONS"),P=o.map(_=>`$${_.toLowerCase()}`);export{E as CATCH_ALL_PREFIX,e as DYNAMIC_PREFIX,T as HTTP_METHODS,o as HTTP_METHODS_EXCLUDE_OPTIONS,P as HTTP_METHOD_FUNC_KEYS,t as OPTIONAL_CATCH_ALL_PREFIX};
|
package/dist/rpc/lib/types.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { HTTP_METHODS } from "./constants";
|
|
2
|
+
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rpc4next",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Inspired by Hono RPC and Pathpida, rpc4next brings a lightweight and intuitive RPC solution to Next.js, making server-client communication seamless",
|
|
5
5
|
"author": "watanabe-1",
|
|
6
6
|
"license": "MIT",
|
|
@@ -71,6 +71,7 @@
|
|
|
71
71
|
"lint:fix": "eslint \"**/*.ts\" --fix"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
+
"chalk": "^5.4.1",
|
|
74
75
|
"chokidar": "^4.0.3",
|
|
75
76
|
"commander": "^13.1.0"
|
|
76
77
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import s from"path";import{EXIT_FAILURE as m,EXIT_SUCCESS as l}from"./constants";import{toPosixPath as p}from"./core/path-utils";import{generate as u}from"./generator";import{setupWatcher as c}from"./watcher";const f=(i,n,t,r)=>{try{return u({baseDir:i,outputPath:n,paramsFileName:t,logger:r}),l}catch(e){return e instanceof Error?r.error(`Failed to generate: ${e.message}`):r.error(`Unknown error occurred during generate: ${String(e)}`),m}},F=(i,n,t,r)=>{const e=p(s.resolve(i)),a=p(s.resolve(n)),o=typeof t.paramsFile=="string"?t.paramsFile:null;return t.paramsFile!==void 0&&!o?(r.error("Error: --params-file requires a filename."),m):t.watch?(c(e,()=>{f(e,a,o,r)},r),l):f(e,a,o,r)};export{F as handleCli};
|
package/dist/rpc/cli/cli.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{Command as s}from"commander";import{handleCli as p}from"./cli-handler";import{EXIT_FAILURE as c}from"./constants";import{createLogger as m}from"./logger";const y=(o,t=m())=>{const r=new s;r.description("Generate RPC client type definitions based on the Next.js path structure.").argument("<baseDir>","Base directory containing Next.js paths for type generation").argument("<outputPath>","Output path for the generated type definitions").option("-w, --watch","Watch mode: regenerate on file changes").option("-p, --params-file [filename]","Generate params types file with specified filename").action(async(n,a,i)=>{try{const e=await p(n,a,i,t);i.watch||process.exit(e)}catch(e){t.error(`Unexpected error occurred:${e instanceof Error?e.message:String(e)}`),process.exit(c)}}),r.parse(o)};export{y as runCli};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const S=["page.tsx","route.ts"],r=0,e=1,s=1,C=20,c="\u2192";export{S as END_POINT_FILE_NAMES,e as EXIT_FAILURE,r as EXIT_SUCCESS,s as SUCCESS_INDENT_LEVEL,C as SUCCESS_PAD_LENGTH,c as SUCCESS_SEPARATOR};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import s from"crypto";const c=(r,t)=>{const e=s.createHash("md5").update(`${r}::${t}`).digest("hex").slice(0,16);return`${t}_${e}`};export{c as createImportAlias};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import r from"path";const a=new Map,p=new Map,n=(e,i)=>{const t=r.resolve(i);[...e.keys()].forEach(o=>{const s=r.resolve(o);(s===t||t.startsWith(s+r.sep))&&e.delete(o)})},v=e=>{n(a,e)},h=e=>{n(p,e)};export{h as clearScanAppDirCacheAbove,v as clearVisitedDirsCacheAbove,p as scanAppDirCache,a as visitedDirsCache};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const T=["Query","OptionalQuery"],n=" ",r=`
|
|
2
|
-
`,_=";",p=";",t="Endpoint",o="QueryKey",E="OptionalQueryKey",e="ParamsKey",P=[t,E,e,o],c="rpc4next/client";export{n as INDENT,r as NEWLINE,T as QUERY_TYPES,c as RPC4NEXT_CLIENT_IMPORT_PATH,_ as STATEMENT_TERMINATOR,t as TYPE_END_POINT,P as TYPE_KEYS,E as TYPE_KEY_OPTIONAL_QUERY,e as TYPE_KEY_PARAMS,o as TYPE_KEY_QUERY,p as TYPE_SEPARATOR};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{STATEMENT_TERMINATOR as s,NEWLINE as r,TYPE_KEYS as $,RPC4NEXT_CLIENT_IMPORT_PATH as E}from"./constants";import{scanAppDir as P}from"./route-scanner";import{createImport as S}from"./type-utils";const g=(o,m)=>{const{pathStructure:p,imports:a,paramsTypes:n}=P(o,m),c=`export type PathStructure = ${p}${s}`,T=a.length?`${a.sort((t,e)=>t.path.localeCompare(e.path,void 0,{numeric:!0})).map(t=>t.statement).join(r)}`:"",i=$.filter(t=>p.includes(t)),u=S(i.join(" ,"),E),y=n.map(({paramsType:t,dirPath:e})=>({paramsType:`export type Params = ${t}${s}`,dirPath:e}));return{pathStructure:`${u}${r}${T}${r}${r}${c}`,paramsTypes:y}};export{g as generatePages};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"path";const a=(t,i)=>{let r=o(e.relative(e.dirname(t),i)).replace(/\.tsx?$/,"");return r.startsWith("../")||(r="./"+r),r},o=t=>t.replace(/\\/g,"/"),n=t=>e.relative(process.cwd(),t);export{a as createRelativeImportPath,n as relativeFromRoot,o as toPosixPath};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* Inspired by pathpida (https://github.com/aspida/pathpida),
|
|
3
|
-
* especially the design and UX of its CLI.
|
|
4
|
-
*/import O from"fs";import N from"path";import{scanAppDirCache as I,visitedDirsCache as u}from"./cache";import{INDENT as H,TYPE_END_POINT as M,TYPE_KEY_PARAMS as X,NEWLINE as _}from"./constants";import{scanQuery as Y,scanRoute as w}from"./scan-utils";import{createObjectType as v,createRecodeType as G}from"./type-utils";import{OPTIONAL_CATCH_ALL_PREFIX as q,CATCH_ALL_PREFIX as B,DYNAMIC_PREFIX as K,HTTP_METHODS_EXCLUDE_OPTIONS as Q}from"../../lib/constants";import{END_POINT_FILE_NAMES as U}from"../constants";import{toPosixPath as z}from"./path-utils";const W=new Set(U),b=t=>{if(u.has(t))return u.get(t);const r=O.readdirSync(t,{withFileTypes:!0});for(const o of r){const{name:e}=o,a=N.join(t,e);if(e==="node_modules"||e.startsWith("_")||e.startsWith("(.)")||e.startsWith("(..)")||e.startsWith("(...)"))return u.set(t,!1),!1;if(o.isFile()&&W.has(e))return u.set(t,!0),!0;if(o.isDirectory()&&b(a))return u.set(t,!0),!0}return u.set(t,!1),!1},J=(t,{isDynamic:r,isCatchAll:o,isOptionalCatchAll:e})=>{let a=t;return r&&(a=a.replace(/^\[+|\]+$/g,"")),(o||e)&&(a=a.replace(/^\.{3}/,"")),{paramName:a,keyName:`${e?q:o?B:r?K:""}${a}`}},V=(t,r,o="",e=[])=>{if(I.has(r))return I.get(r);const a=o,y=o+H,T=[],P=[],f=[],d=[],g=[...e],F=O.readdirSync(r,{withFileTypes:!0}).filter(m=>{if(m.isDirectory()){const l=N.join(r,m.name);return b(l)}return W.has(m.name)}).sort();for(const m of F){const l=z(N.join(r,m.name));if(m.isDirectory()){const s=m.name,p=s.startsWith("(")&&s.endsWith(")"),n=s.startsWith("@"),i=s.startsWith("[[...")&&s.endsWith("]]"),c=s.startsWith("[...")&&s.endsWith("]"),h=s.startsWith("[")&&s.endsWith("]"),{paramName:j,keyName:L}=J(s,{isDynamic:h,isCatchAll:c,isOptionalCatchAll:i}),x=h||c||i?[...g,{paramName:j,routeType:{isDynamic:h,isCatchAll:c,isOptionalCatchAll:i,isGroup:p,isParallel:n}}]:g,D=p||n,{pathStructure:$,imports:R,paramsTypes:k}=V(t,l,D?a:y,x);if(P.push(...R),d.push(...k),D){const C=$.match(/^\s*\{([\s\S]*)\}\s*$/);C&&T.push(`${y}${C[1].trim()}`)}else T.push(`${y}"${L}": ${$}`)}else{const s=Y(t,l);if(s){const{importStatement:p,importPath:n,type:i}=s;P.push({statement:p,path:n}),f.push(i)}if(Q.forEach(p=>{const n=w(t,l,p);if(n){const{importStatement:i,importPath:c,type:h}=n;P.push({statement:i,path:c}),f.push(h)}}),f.push(M),g.length>0){const p=g.map(({paramName:i,routeType:c})=>{const h=c.isCatchAll?"string[]":c.isOptionalCatchAll?"string[] | undefined":"string";return{name:i,type:h}}),n=v(p);d.push({paramsType:n,dirPath:N.dirname(l)}),f.push(G(X,n))}}}const E=f.join(" & "),S=T.length>0?`{${_}${T.join(`,${_}`)}${_}${a}}`:"",A={pathStructure:E&&S?`${E} & ${S}`:E||S,imports:P,paramsTypes:d};return I.set(r,A),A};export{b as hasTargetFiles,V as scanAppDir};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import m from"fs";import{createImportAlias as f}from"./alias";import{QUERY_TYPES as g,TYPE_KEY_QUERY as u,TYPE_KEY_OPTIONAL_QUERY as y}from"./constants";import{createRelativeImportPath as l}from"./path-utils";import{createImport as E,createRecodeType as a,createObjectType as $}from"./type-utils";const c=(o,n,r,t)=>{const e=m.readFileSync(n,"utf8"),i=r(e);if(!i)return;const s=l(o,n),p=f(s,i);return{importName:p,importPath:s,importStatement:E(i,s,p),type:t(i,p)}},d=(o,n)=>c(o,n,r=>g.find(t=>new RegExp(`export (interface ${t} ?{|type ${t} ?=)`).test(r)),(r,t)=>r==="Query"?a(u,t):a(y,t)),I=(o,n,r)=>c(o,n,t=>[r].find(e=>new RegExp(`export (async )?(function ${e} ?\\(|const ${e} ?=|\\{[^}]*\\b${e}\\b[^}]*\\} ?=|const \\{[^}]*\\b${e}\\b[^}]*\\} ?=|\\{[^}]*\\b${e}\\b[^}]*\\} from)`).test(t)),(t,e)=>$([{name:`$${t.toLowerCase()}`,type:`typeof ${e}`}]));export{c as scanFile,d as scanQuery,I as scanRoute};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{TYPE_SEPARATOR as n,STATEMENT_TERMINATOR as o}from"./constants";const c=(r,t)=>!r||!t?"":`Record<${r}, ${t}>`,g=r=>r.length===0||r.some(({name:t,type:e})=>!t||!e)?"":`{ ${r.map(({name:t,type:e})=>`"${t}": ${e}`).join(`${n} `)}${r.length>1?n:""} }`,i=(r,t,e)=>!r||!t?"":e?`import type { ${r} as ${e} } from "${t}"${o}`:`import type { ${r} } from "${t}"${o}`;export{i as createImport,g as createObjectType,c as createRecodeType};
|
package/dist/rpc/cli/debounce.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const a=(l,u)=>{let t=null,r=!1,e=null;const i=async(...n)=>{r=!0;try{await l(...n)}finally{if(r=!1,e){const s=e;e=null,i(...s)}}};return(...n)=>{t&&clearTimeout(t),t=setTimeout(()=>{if(r){e=n;return}i(...n)},u)}};export{a as debounceOnceRunningWithTrailing};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import o from"fs";import E from"path";import{SUCCESS_SEPARATOR as s,SUCCESS_PAD_LENGTH as i,SUCCESS_INDENT_LEVEL as n}from"./constants";import{generatePages as y}from"./core/generate-path-structure";import{relativeFromRoot as L}from"./core/path-utils";import{padMessage as p}from"./logger";const v=({baseDir:m,outputPath:e,paramsFileName:t,logger:r})=>{r.info("Generating types...",{event:"generate"});const{pathStructure:a,paramsTypes:S}=y(e,m);o.writeFileSync(e,a),r.success(p("Path structure type",L(e),s,i),{indentLevel:n}),t&&(S.forEach(({paramsType:c,dirPath:f})=>{const g=E.join(f,t);o.writeFileSync(g,c)}),r.success(p("Params types",t,s,i),{indentLevel:n}))};export{v as generate};
|
package/dist/rpc/cli/logger.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import t from"chalk";import{INDENT as $}from"./core/constants";const i=(e,r,o="\u2192",n=24)=>e.padEnd(n)+` ${o} ${r}`,s=(e=0)=>$.repeat(e),d=()=>({info:(e,r={})=>{const{indentLevel:o=0,event:n}=r,c=n?`${t.cyan(`[${n}]`)} `:"";console.log(`${s(o)}${c}${e}`)},success:(e,r={})=>{const{indentLevel:o=0}=r;console.log(`${s(o)}${t.green("\u2713")} ${e}`)},error:(e,r={})=>{const{indentLevel:o=0}=r;console.error(`${s(o)}${t.red("\u2717")} ${t.red(e)}`)}});export{d as createLogger,i as padMessage};
|
package/dist/rpc/cli/types.js
DELETED
|
File without changes
|
package/dist/rpc/cli/watcher.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import p from"chokidar";import{END_POINT_FILE_NAMES as f}from"./constants";import{clearScanAppDirCacheAbove as l,clearVisitedDirsCacheAbove as w}from"./core/cache";import{relativeFromRoot as h}from"./core/path-utils";import{debounceOnceRunningWithTrailing as v}from"./debounce";const F=(c,m,r)=>{r.info(`${h(c)}`,{event:"watch"});const i=e=>f.some(o=>e.endsWith(o)),n=new Set,a=v(()=>{n.forEach(e=>{w(e),l(e)}),n.clear(),m()},300),t=p.watch(c,{ignoreInitial:!0,ignored:(e,o)=>!!o?.isFile()&&!i(e)});t.on("ready",()=>{a(),t.on("all",(e,o)=>{if(i(o)){const d=h(o);r.info(d,{event:e}),n.add(o),a()}})}),t.on("error",e=>{e instanceof Error?r.error(`Watcher error: ${e.message}`):r.error(`Unknown watcher error: ${String(e)}`)});const s=()=>{t.close().then(()=>{r.info("Watcher closed.",{event:"watch"})}).catch(e=>{r.error(`Failed to close watcher: ${e.message}`)})};process.on("SIGINT",s),process.on("SIGTERM",s)};export{F as setupWatcher};
|