@ooneex/routing 0.0.2 → 0.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/README.md +402 -333
- package/dist/index.d.ts +15 -14
- package/dist/index.js +56 -49
- package/dist/index.js.map +7 -6
- package/package.json +12 -12
- package/dist/ooneex-routing-0.0.1.tgz +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
+
import { ControllerClassType as ControllerClassType2 } from "@ooneex/controller";
|
|
1
2
|
import { AssertType as AssertType2 } from "@ooneex/validation";
|
|
2
3
|
import { Environment } from "@ooneex/app-env";
|
|
3
4
|
import { ControllerClassType } from "@ooneex/controller";
|
|
5
|
+
import { PermissionClassType } from "@ooneex/permission";
|
|
4
6
|
import { ERole } from "@ooneex/role";
|
|
5
7
|
import { HttpMethodType } from "@ooneex/types";
|
|
6
8
|
import { AssertType, IAssert } from "@ooneex/validation";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type RouteAction = "list" | "show" | "read" | "create" | "update" | "delete" | "store" | "edit" | "index" | "search" | "filter" | "sort" | "export" | "import" | "upload" | "download" | "duplicate" | "clone" | "archive" | "restore" | "activate" | "deactivate" | "enable" | "disable" | "publish" | "unpublish" | "approve" | "reject" | "cancel" | "confirm" | "validate" | "verify" | "reset" | "refresh" | "sync" | "backup" | "migrate" | "seed" | "truncate" | "count" | "exists" | "find" | "aggregate" | "bulk" | "batch" | "preview" | "template" | "history" | "audit" | "log" | "track" | "monitor" | "health" | "status" | "ping" | "test" | "debug" | "info" | "stats" | "report" | "analytics" | "metrics" | "summary" | "detail" | "config" | "settings" | "preferences" | "profile" | "avatar" | "password" | "login" | "logout" | "register" | "unregister" | "subscribe" | "unsubscribe" | "follow" | "unfollow" | "like" | "unlike" | "share" | "comment" | "reply" | "rate" | "review" | "bookmark" | "favorite" | "tag" | "untag" | "assign" | "unassign" | "invite" | "revoke" | "grant" | "deny" | "lock" | "unlock" | "move" | "copy" | "rename" | "reorder" | "merge" | "split" | "convert" | "transform" | "process" | "queue" | "retry" | "skip" | "pause" | "resume" | "stop" | "start" | "restart" | "reload" | "clear" | "flush" | "purge" | "cleanup" | "optimize" | "compress" | "decompress" | "manage" | "administer" | "supervise" | "oversee" | "govern" | "control" | "execute" | "perform" | "run" | "operate" | "handle" | "maintain" | "service" | "support" | "assist" | "help" | "guide" | "instruct" | "teach" | "train" | "educate" | "inform" | "notify" | "alert" | "warn" | "remind" | "schedule" | "plan" | "organize" | "arrange" | "coordinate" | "integrate" | "connect" | "link" | "bind" | "attach" | "detach" | "separate" | "isolate" | "quarantine" | "protect" | "secure" | "encrypt" | "decrypt" | "encode" | "decode" | "format" | "parse" | "serialize" | "deserialize" | "marshal" | "unmarshal" | "package" | "unpack" | "bundle" | "unbundle" | "group" | "ungroup" | "categorize" | "classify" | "sort" | "order" | "rank" | "prioritize" | "weight" | "score" | "evaluate" | "assess" | "measure" | "calculate" | "compute" | "analyze" | "examine" | "inspect" | "check" | "scan" | "detect" | "discover" | "explore" | "browse" | "navigate" | "travel" | "visit" | "access" | "enter" | "exit" | "leave" | "join" | "connect" | "disconnect" | "reconnect" | "establish" | "initialize" | "setup" | "configure" | "customize" | "personalize" | "adapt" | "adjust" | "modify" | "change" | "alter" | "revise" | "amend" | "correct" | "fix" | "repair" | "restore" | "recover" | "retrieve" | "fetch" | "get" | "obtain" | "acquire" | "receive" | "accept" | "take" | "capture" | "record" | "save" | "store" | "preserve" | "keep" | "retain" | "hold" | "maintain" | "sustain" | "continue" | "proceed" | "advance" | "progress" | "develop" | "evolve" | "grow" | "expand" | "extend" | "stretch" | "scale" | "resize" | "adjust" | "tune" | "calibrate" | "balance" | "stabilize" | "normalize" | "standardize" | "regulate" | "moderate" | "mediate" | "negotiate" | "compromise" | "resolve" | "solve" | "address" | "tackle" | "approach" | "handle" | "deal" | "cope" | "manage" | "oversee" | "supervise" | "direct" | "lead" | "command" | "instruct" | "order" | "request" | "ask" | "query" | "question" | "inquire" | "investigate" | "research" | "study" | "learn" | "understand" | "comprehend" | "grasp" | "realize" | "recognize" | "identify" | "determine" | "decide" | "choose" | "select" | "pick" | "opt" | "prefer" | "favor" | "recommend" | "suggest" | "propose" | "offer" | "provide" | "supply" | "deliver" | "send" | "transmit" | "transfer" | "forward" | "relay" | "redirect" | "route" | "dispatch" | "distribute" | "allocate" | "assign" | "designate" | "appoint" | "nominate" | "elect" | "vote" | "poll" | "survey" | "interview" | "question" | "examine" | "test" | "trial" | "experiment" | "try" | "attempt" | "endeavor" | "strive" | "effort" | "work" | "labor" | "toil" | "struggle" | "fight" | "battle" | "compete" | "contest" | "challenge" | "oppose" | "resist" | "defend" | "protect" | "guard" | "shield" | "cover" | "hide" | "conceal" | "mask" | "disguise" | "camouflage" | "cloak" | "wrap" | "enclose" | "contain" | "include" | "encompass" | "comprise" | "consist" | "compose" | "constitute" | "form" | "shape" | "mold" | "craft" | "build" | "construct" | "assemble" | "compile" | "gather" | "collect" | "accumulate" | "amass" | "pile" | "stack" | "heap" | "load" | "fill" | "populate" | "occupy" | "inhabit" | "reside" | "dwell" | "live" | "exist" | "become" | "turn" | "transform" | "metamorphose" | "evolve" | "mutate" | "adapt" | "adjust" | "accommodate" | "conform" | "comply" | "obey" | "follow" | "adhere" | "stick" | "attach" | "fasten" | "secure" | "tie" | "bind" | "connect" | "join" | "unite" | "merge" | "combine" | "mix" | "blend" | "fuse" | "integrate" | "incorporate" | "embed" | "insert" | "inject" | "introduce" | "import" | "bring" | "carry" | "transport" | "convey" | "deliver" | "distribute" | "spread" | "scatter" | "disperse" | "disseminate" | "broadcast" | "publish" | "announce" | "declare" | "proclaim" | "state" | "express" | "voice" | "speak" | "say" | "tell" | "communicate" | "convey" | "relay" | "transmit" | "send" | "deliver" | "transfer" | "move" | "shift" | "relocate" | "migrate" | "travel" | "journey" | "voyage" | "trip" | "visit" | "tour" | "explore" | "discover" | "find" | "locate" | "position" | "place" | "put" | "set" | "lay" | "rest" | "sit" | "stand" | "rise" | "lift" | "raise" | "elevate" | "boost" | "enhance" | "improve" | "upgrade" | "update" | "refresh" | "renew" | "revive" | "restore" | "repair" | "fix" | "mend" | "heal" | "cure" | "treat" | "remedy" | "solve" | "resolve" | "settle" | "conclude" | "finish" | "complete" | "end" | "terminate" | "stop" | "halt" | "pause" | "break" | "interrupt" | "suspend" | "delay" | "postpone" | "defer" | "wait" | "hold" | "keep" | "retain" | "preserve" | "maintain" | "sustain" | "support" | "uphold" | "defend" | "protect" | "safeguard" | "secure" | "ensure" | "guarantee" | "warrant" | "promise" | "pledge" | "commit" | "dedicate" | "devote" | "consecrate" | "sacrifice" | "offer" | "give" | "donate" | "contribute" | "provide" | "supply" | "furnish" | "equip" | "outfit" | "prepare" | "ready" | "arrange" | "organize" | "plan" | "design" | "create" | "make" | "produce" | "manufacture" | "fabricate" | "construct" | "build" | "erect" | "establish" | "found" | "institute" | "inaugurate" | "launch" | "start" | "begin" | "commence" | "initiate" | "trigger" | "activate" | "enable" | "turn-on" | "switch-on" | "power-on" | "boot" | "startup" | "load" | "run" | "execute" | "perform" | "operate" | "function" | "work" | "act" | "behave" | "conduct" | "direct" | "guide" | "lead" | "steer" | "navigate" | "pilot" | "drive" | "control" | "command" | "rule" | "govern" | "regulate" | "manage" | "administer" | "handle" | "deal" | "process" | "treat" | "handle" | "manipulate" | "operate" | "use" | "utilize" | "employ" | "apply" | "implement" | "deploy" | "install" | "setup" | "configure" | "adjust" | "tune" | "optimize" | "improve" | "enhance" | "refine" | "polish" | "perfect" | "complete" | "finalize" | "conclude" | "close" | "shut" | "seal" | "lock" | "secure" | "protect" | "defend" | "guard" | "watch" | "monitor" | "observe" | "supervise" | "oversee" | "manage";
|
|
12
|
-
/**
|
|
13
|
-
* Valid route name segment - alphanumeric with optional hyphens/underscores
|
|
14
|
-
*/
|
|
9
|
+
declare const VALID_NAMESPACES: readonly ["api", "client", "admin", "public", "auth", "webhook", "internal", "external", "system", "health", "metrics", "docs"];
|
|
10
|
+
declare const VALID_ACTIONS: readonly ["list", "show", "read", "create", "update", "delete", "store", "edit", "index", "search", "filter", "sort", "export", "import", "upload", "download", "duplicate", "clone", "archive", "restore", "activate", "deactivate", "enable", "disable", "publish", "unpublish", "approve", "reject", "cancel", "confirm", "validate", "verify", "reset", "refresh", "sync", "backup", "migrate", "seed", "truncate", "count", "exists", "find", "aggregate", "bulk", "batch", "preview", "template", "history", "audit", "log", "track", "monitor", "health", "status", "ping", "test", "debug", "info", "stats", "report", "analytics", "metrics", "summary", "detail", "config", "settings", "preferences", "profile", "avatar", "password", "login", "logout", "register", "unregister", "subscribe", "unsubscribe", "follow", "unfollow", "like", "unlike", "share", "comment", "reply", "rate", "review", "bookmark", "favorite", "tag", "untag", "assign", "unassign", "invite", "revoke", "grant", "deny", "lock", "unlock", "move", "copy", "rename", "reorder", "merge", "split", "convert", "transform", "process", "queue", "retry", "skip", "pause", "resume", "stop", "start", "restart", "reload", "clear", "flush", "purge", "cleanup", "optimize", "compress", "decompress", "manage", "administer", "supervise", "oversee", "govern", "control", "execute", "perform", "run", "operate", "handle", "maintain", "service", "support", "assist", "help", "guide", "instruct", "teach", "train", "educate", "inform", "notify", "alert", "warn", "remind", "schedule", "plan", "organize", "arrange", "coordinate", "integrate", "connect", "link", "bind", "attach", "detach", "separate", "isolate", "quarantine", "protect", "secure", "encrypt", "decrypt", "encode", "decode", "format", "parse", "serialize", "deserialize", "marshal", "unmarshal", "package", "unpack", "bundle", "unbundle", "group", "ungroup", "categorize", "classify", "order", "rank", "prioritize", "weight", "score", "evaluate", "assess", "measure", "calculate", "compute", "analyze", "examine", "inspect", "check", "scan", "detect", "discover", "explore", "browse", "navigate", "travel", "visit", "access", "enter", "exit", "leave", "join", "disconnect", "reconnect", "establish", "initialize", "setup", "configure", "customize", "personalize", "adapt", "adjust", "modify", "change", "alter", "revise", "amend", "correct", "fix", "repair", "recover", "retrieve", "fetch", "get", "obtain", "acquire", "receive", "accept", "take", "capture", "record", "save", "preserve", "keep", "retain", "hold", "sustain", "continue", "proceed", "advance", "progress", "develop", "evolve", "grow", "expand", "extend", "stretch", "scale", "resize", "tune", "calibrate", "balance", "stabilize", "normalize", "standardize", "regulate", "moderate", "mediate", "negotiate", "compromise", "resolve", "solve", "address", "tackle", "approach", "deal", "cope", "direct", "lead", "command", "instruct", "order", "request", "ask", "query", "question", "inquire", "investigate", "research", "study", "learn", "understand", "comprehend", "grasp", "realize", "recognize", "identify", "determine", "decide", "choose", "select", "pick", "opt", "prefer", "favor", "recommend", "suggest", "propose", "offer", "provide", "supply", "deliver", "send", "transmit", "transfer", "forward", "relay", "redirect", "route", "dispatch", "distribute", "allocate", "designate", "appoint", "nominate", "elect", "vote", "poll", "survey", "interview", "examine", "trial", "experiment", "try", "attempt", "endeavor", "strive", "effort", "work", "labor", "toil", "struggle", "fight", "battle", "compete", "contest", "challenge", "oppose", "resist", "defend", "guard", "shield", "cover", "hide", "conceal", "mask", "disguise", "camouflage", "cloak", "wrap", "enclose", "contain", "include", "encompass", "comprise", "consist", "compose", "constitute", "form", "shape", "mold", "craft", "build", "construct", "assemble", "compile", "gather", "collect", "accumulate", "amass", "pile", "stack", "heap", "load", "fill", "populate", "occupy", "inhabit", "reside", "dwell", "live", "exist", "become", "turn", "metamorphose", "mutate", "accommodate", "conform", "comply", "obey", "follow", "adhere", "stick", "fasten", "tie", "unite", "combine", "mix", "blend", "fuse", "incorporate", "embed", "insert", "inject", "introduce", "bring", "carry", "transport", "convey", "spread", "scatter", "disperse", "disseminate", "broadcast", "announce", "declare", "proclaim", "state", "express", "voice", "speak", "say", "tell", "communicate", "shift", "relocate", "journey", "voyage", "trip", "tour", "locate", "position", "place", "put", "set", "lay", "rest", "sit", "stand", "rise", "lift", "raise", "elevate", "boost", "enhance", "improve", "upgrade", "renew", "revive", "mend", "heal", "cure", "treat", "remedy", "settle", "conclude", "finish", "complete", "end", "terminate", "halt", "break", "interrupt", "suspend", "delay", "postpone", "defer", "wait", "uphold", "safeguard", "ensure", "guarantee", "warrant", "promise", "pledge", "commit", "dedicate", "devote", "consecrate", "sacrifice", "give", "donate", "contribute", "furnish", "equip", "outfit", "prepare", "ready", "design", "make", "produce", "manufacture", "fabricate", "erect", "found", "institute", "inaugurate", "launch", "begin", "commence", "initiate", "trigger", "turn-on", "switch-on", "power-on", "boot", "startup", "function", "act", "behave", "conduct", "steer", "pilot", "drive", "rule", "manipulate", "use", "utilize", "employ", "apply", "implement", "deploy", "install", "refine", "polish", "perfect", "finalize", "close", "shut", "seal", "watch", "observe"];
|
|
11
|
+
type RouteNamespace = (typeof VALID_NAMESPACES)[number];
|
|
12
|
+
type RouteAction = (typeof VALID_ACTIONS)[number];
|
|
15
13
|
type RouteNameSegment = string;
|
|
16
14
|
/**
|
|
17
15
|
* Route name type that enforces 'api.users.list' format
|
|
@@ -33,11 +31,13 @@ type RouteConfigType = {
|
|
|
33
31
|
ip?: string[];
|
|
34
32
|
host?: string[];
|
|
35
33
|
roles?: ERole[];
|
|
34
|
+
permission?: PermissionClassType;
|
|
35
|
+
cache?: boolean;
|
|
36
36
|
isSocket: boolean;
|
|
37
37
|
generate?: {
|
|
38
38
|
doc?: boolean;
|
|
39
39
|
fetcher?: boolean;
|
|
40
|
-
|
|
40
|
+
queryHook?: boolean;
|
|
41
41
|
};
|
|
42
42
|
};
|
|
43
43
|
interface IRouter {
|
|
@@ -45,7 +45,7 @@ interface IRouter {
|
|
|
45
45
|
findRouteByPath: (path: string) => RouteConfigType[] | null;
|
|
46
46
|
findRouteByName: (name: RouteNameType) => RouteConfigType | null;
|
|
47
47
|
getRoutes: () => Map<string, RouteConfigType[]>;
|
|
48
|
-
getSocketRoutes: () => Map<string, RouteConfigType
|
|
48
|
+
getSocketRoutes: () => Map<string, RouteConfigType>;
|
|
49
49
|
getHttpRoutes: () => Map<string, RouteConfigType[]>;
|
|
50
50
|
generate: <P extends Record<string, string | number> = Record<string, string | number>>(name: RouteNameType, params?: P) => string;
|
|
51
51
|
}
|
|
@@ -110,7 +110,7 @@ type ValidRoutePath = RoutePathType<string>;
|
|
|
110
110
|
type TypedRouteConfig<T extends string> = Omit<RouteConfigType, "method" | "path" | "isSocket" | "controller" | "params"> & {
|
|
111
111
|
params?: ExtractParameters<T> extends never ? never : Record<ExtractParameters<T>, AssertType2>;
|
|
112
112
|
};
|
|
113
|
-
type InferredRouteDecorator = (target:
|
|
113
|
+
type InferredRouteDecorator = (target: ControllerClassType2) => void;
|
|
114
114
|
type RouteDecoratorFunction = <T extends string>(path: RoutePathType<T>, config: TypedRouteConfig<T>) => InferredRouteDecorator;
|
|
115
115
|
declare const Route: {
|
|
116
116
|
get: RouteDecoratorFunction;
|
|
@@ -128,10 +128,11 @@ declare class Router implements IRouter {
|
|
|
128
128
|
findRouteByPath(path: string): RouteConfigType[] | null;
|
|
129
129
|
findRouteByName(name: string): RouteConfigType | null;
|
|
130
130
|
getRoutes(): Map<string, RouteConfigType[]>;
|
|
131
|
-
getSocketRoutes(): Map<string, RouteConfigType
|
|
131
|
+
getSocketRoutes(): Map<string, RouteConfigType>;
|
|
132
132
|
getHttpRoutes(): Map<string, RouteConfigType[]>;
|
|
133
133
|
generate<P extends Record<string, string | number> = Record<string, string | number>>(name: string, params?: P): string;
|
|
134
134
|
}
|
|
135
|
+
declare const router: Router;
|
|
135
136
|
import { Exception } from "@ooneex/exception";
|
|
136
137
|
declare class RouterException extends Exception {
|
|
137
138
|
constructor(message: string, data?: Record<string, unknown>);
|
|
@@ -222,5 +223,5 @@ declare const routeConfigToTypeString: (config: Pick<RouteConfigType, "params" |
|
|
|
222
223
|
declare const routeConfigToJsonDoc: (config: RouteConfigType) => Record<string, unknown>;
|
|
223
224
|
declare const routeConfigToFetcherString: (config: RouteConfigType) => string;
|
|
224
225
|
declare const routeConfigToSocketString: (config: RouteConfigType) => string;
|
|
225
|
-
declare const
|
|
226
|
-
export {
|
|
226
|
+
declare const routeConfigToHookString: (config: RouteConfigType) => string;
|
|
227
|
+
export { router, routeConfigToTypeString, routeConfigToSocketString, routeConfigToJsonDoc, routeConfigToHookString, routeConfigToFetcherString, isValidRoutePath, extractParameterNames, ValidateRoutePath, ValidRoutePath, VALID_NAMESPACES, VALID_ACTIONS, RouterException, Router, RoutePathType, RouteParameters, RouteNamespace, RouteNameType, RouteNameSegment, RouteConfigType, RouteAction, Route, ParameterCount, IsParameter, IRouter, HasParameters, ExtractParameters, CountParameters };
|
package/dist/index.js
CHANGED
|
@@ -1,94 +1,101 @@
|
|
|
1
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
import{container as s,EContainerScope as f}from"@ooneex/container";import{Exception as p}from"@ooneex/exception";import{HttpStatus as n}from"@ooneex/http-status";class T extends p{constructor(t,w={}){super(t,{status:n.Code.InternalServerError,data:w});this.name="RouterException"}}class j{routes=new Map;addRoute(t){let w=t.name;for(let x of this.routes[Symbol.iterator]())if(x[1].find((M)=>M.name===w))throw new T(`Route with name '${w}' already exists`,t);let u=this.routes.get(t.path)??[];if(t.isSocket&&u.find((x)=>x.isSocket))throw new T(`Socket route with path '${t.path}' already exists`,t);if(!t.isSocket&&u.find((x)=>!x.isSocket&&x.method===t.method))throw new T(`Route with path '${t.path}' and method '${t.method}' already exists`,t);return u.push(t),this.routes.set(t.path,u),s.add(t.controller,f.Singleton),this}findRouteByPath(t){return this.routes.get(t)??null}findRouteByName(t){for(let w of this.routes[Symbol.iterator]()){let u=w[1].find((x)=>x.name===t);if(u)return u}return null}getRoutes(){return this.routes}getSocketRoutes(){let t=new Map;for(let[w,u]of this.routes){let x=u.find((R)=>R.isSocket);if(x)t.set(w,x)}return t}getHttpRoutes(){let t=new Map;for(let[w,u]of this.routes){let x=u.filter((R)=>!R.isSocket);if(x.length>0)t.set(w,x)}return t}generate(t,w){let u=this.findRouteByName(t);if(!u)throw new T(`Route with name '${t}' not found`);let x=u.path,R=x.match(/:[a-zA-Z0-9_]+/g)||[];if(R.length>0){if(!w||typeof w!=="object"||w===null)throw new T(`Route '${t}' requires parameters, but none were provided`);for(let M of R){let C=M.substring(1);if(!(C in w))throw new T(`Missing required parameter '${C}' for route '${t}'`);x=x.replace(M,String(w[C]))}}return x}}var _=new j;var k=(t)=>{return(w,u)=>{return(x)=>{let R={...u,path:w,method:t,isSocket:!1,controller:x};_.addRoute(R)}}},a=()=>{return(t,w)=>{return(u)=>{let x={...w,path:t,method:"GET",isSocket:!0,controller:u};_.addRoute(x)}}},g={get:k("GET"),post:k("POST"),put:k("PUT"),delete:k("DELETE"),patch:k("PATCH"),options:k("OPTIONS"),head:k("HEAD"),socket:a()};var dt=["api","client","admin","public","auth","webhook","internal","external","system","health","metrics","docs"],It=["list","show","read","create","update","delete","store","edit","index","search","filter","sort","export","import","upload","download","duplicate","clone","archive","restore","activate","deactivate","enable","disable","publish","unpublish","approve","reject","cancel","confirm","validate","verify","reset","refresh","sync","backup","migrate","seed","truncate","count","exists","find","aggregate","bulk","batch","preview","template","history","audit","log","track","monitor","health","status","ping","test","debug","info","stats","report","analytics","metrics","summary","detail","config","settings","preferences","profile","avatar","password","login","logout","register","unregister","subscribe","unsubscribe","follow","unfollow","like","unlike","share","comment","reply","rate","review","bookmark","favorite","tag","untag","assign","unassign","invite","revoke","grant","deny","lock","unlock","move","copy","rename","reorder","merge","split","convert","transform","process","queue","retry","skip","pause","resume","stop","start","restart","reload","clear","flush","purge","cleanup","optimize","compress","decompress","manage","administer","supervise","oversee","govern","control","execute","perform","run","operate","handle","maintain","service","support","assist","help","guide","instruct","teach","train","educate","inform","notify","alert","warn","remind","schedule","plan","organize","arrange","coordinate","integrate","connect","link","bind","attach","detach","separate","isolate","quarantine","protect","secure","encrypt","decrypt","encode","decode","format","parse","serialize","deserialize","marshal","unmarshal","package","unpack","bundle","unbundle","group","ungroup","categorize","classify","order","rank","prioritize","weight","score","evaluate","assess","measure","calculate","compute","analyze","examine","inspect","check","scan","detect","discover","explore","browse","navigate","travel","visit","access","enter","exit","leave","join","disconnect","reconnect","establish","initialize","setup","configure","customize","personalize","adapt","adjust","modify","change","alter","revise","amend","correct","fix","repair","recover","retrieve","fetch","get","obtain","acquire","receive","accept","take","capture","record","save","preserve","keep","retain","hold","sustain","continue","proceed","advance","progress","develop","evolve","grow","expand","extend","stretch","scale","resize","tune","calibrate","balance","stabilize","normalize","standardize","regulate","moderate","mediate","negotiate","compromise","resolve","solve","address","tackle","approach","deal","cope","direct","lead","command","instruct","order","request","ask","query","question","inquire","investigate","research","study","learn","understand","comprehend","grasp","realize","recognize","identify","determine","decide","choose","select","pick","opt","prefer","favor","recommend","suggest","propose","offer","provide","supply","deliver","send","transmit","transfer","forward","relay","redirect","route","dispatch","distribute","allocate","designate","appoint","nominate","elect","vote","poll","survey","interview","examine","trial","experiment","try","attempt","endeavor","strive","effort","work","labor","toil","struggle","fight","battle","compete","contest","challenge","oppose","resist","defend","guard","shield","cover","hide","conceal","mask","disguise","camouflage","cloak","wrap","enclose","contain","include","encompass","comprise","consist","compose","constitute","form","shape","mold","craft","build","construct","assemble","compile","gather","collect","accumulate","amass","pile","stack","heap","load","fill","populate","occupy","inhabit","reside","dwell","live","exist","become","turn","metamorphose","mutate","accommodate","conform","comply","obey","follow","adhere","stick","fasten","tie","unite","combine","mix","blend","fuse","incorporate","embed","insert","inject","introduce","bring","carry","transport","convey","spread","scatter","disperse","disseminate","broadcast","announce","declare","proclaim","state","express","voice","speak","say","tell","communicate","shift","relocate","journey","voyage","trip","tour","locate","position","place","put","set","lay","rest","sit","stand","rise","lift","raise","elevate","boost","enhance","improve","upgrade","renew","revive","mend","heal","cure","treat","remedy","settle","conclude","finish","complete","end","terminate","halt","break","interrupt","suspend","delay","postpone","defer","wait","uphold","safeguard","ensure","guarantee","warrant","promise","pledge","commit","dedicate","devote","consecrate","sacrifice","give","donate","contribute","furnish","equip","outfit","prepare","ready","design","make","produce","manufacture","fabricate","erect","found","institute","inaugurate","launch","begin","commence","initiate","trigger","turn-on","switch-on","power-on","boot","startup","function","act","behave","conduct","steer","pilot","drive","rule","manipulate","use","utilize","employ","apply","implement","deploy","install","refine","polish","perfect","finalize","close","shut","seal","watch","observe"];import{toPascalCase as W}from"@ooneex/utils";import{jsonSchemaToTypeString as v}from"@ooneex/validation";var Tt=(t)=>{if(!t.startsWith("/"))return!1;if(t.includes("//"))return!1;if(t.includes("::"))return!1;if(t.endsWith(":"))return!1;if(t.includes("/:")){let w=t.split("/");for(let u of w){if(u.startsWith(":")&&u.length===1)return!1;if(u.includes(":")&&!u.startsWith(":"))return!1}}return!0},c=(t)=>{let w=t.match(/:([^/]+)/g);return w?w.map((u)=>u.slice(1)):[]},K=(t)=>{if(!t.response&&!t.params&&!t.payload&&!t.queries)return"never";let w=[];if(t.response)try{let x=("getConstraint"in t.response?t.response.getConstraint():t.response).toJsonSchema(),R=v(x);if(R==="unknown"||R==="{ }"||R==="Record<string, unknown>")R="never";w.push(`response: ${R}`)}catch{w.push("response: never")}if(t.params){let u=[];for(let[x,R]of Object.entries(t.params))try{let C=("getConstraint"in R?R.getConstraint():R).toJsonSchema(),E=v(C);if(E==="unknown"||E==="{ }"||E==="Record<string, unknown>")E="never";u.push(`${x}: ${E}`)}catch{u.push(`${x}: never`)}if(u.length>0){let x=`{ ${u.join("; ")} }`;w.push(`params: ${x}`)}else w.push("params: never")}if(t.payload)try{let x=("getConstraint"in t.payload?t.payload.getConstraint():t.payload).toJsonSchema(),R=v(x);if(R==="unknown"||R==="{ }"||R==="Record<string, unknown>")R="never";w.push(`payload: ${R}`)}catch{w.push("payload: never")}if(t.queries)try{let x=("getConstraint"in t.queries?t.queries.getConstraint():t.queries).toJsonSchema(),R=v(x);if(R==="unknown"||R==="{ }"||R==="Record<string, unknown>")R="never";w.push(`queries: ${R}`)}catch{w.push("queries: never")}return`{
|
|
2
3
|
${w.join(`;
|
|
3
4
|
`)};
|
|
4
|
-
}`},
|
|
5
|
-
${
|
|
5
|
+
}`},X=(t)=>{try{return(t&&typeof t==="object"&&"getConstraint"in t?t.getConstraint():t).toJsonSchema()}catch{return{type:"unknown"}}},Ot=(t)=>{let w={name:t.name,path:t.path,method:t.method,description:t.description,controller:t.controller.name,isSocket:t.isSocket,parameters:c(t.path)},u={};if(t.params){let R={type:"object",properties:{}};for(let[M,C]of Object.entries(t.params)){let E=X(C);delete E.$schema,E.required=!0,R.properties[M]=E}u.params=R}if(t.queries){let R=X(t.queries);if(delete R.$schema,R.type==="object"&&R.properties){let M=R.required||[],C=R.properties;for(let E of Object.keys(C)){let $=C[E];$.required=M.includes(E)}delete R.required}u.queries=R}if(t.payload){let R=X(t.payload);if(delete R.$schema,R.type==="object"&&R.properties){let M=R.required||[],C=R.properties;for(let E of Object.keys(C)){let $=C[E];$.required=M.includes(E)}delete R.required}u.payload=R}if(t.response){let R=X(t.response);if(delete R.$schema,R.type==="object"&&R.properties){let M=R.required||[],C=R.properties;for(let E of Object.keys(C)){let $=C[E];$.required=M.includes(E)}delete R.required}u.response=R}if(Object.keys(u).length>0)w.schemas=u;let x={};if(t.env&&t.env.length>0)x.environments=t.env;if(t.roles&&t.roles.length>0)x.roles=t.roles;if(t.ip&&t.ip.length>0)x.allowedIPs=t.ip;if(t.host&&t.host.length>0)x.allowedHosts=t.host;if(Object.keys(x).length>0)w.security=x;return w},l=(t)=>{let w=t.split(".");return w[w.length-1]||""},Y=(t,w=!0)=>{let u=w?"config.params":"params";return t.replace(/:(\w+)/g,(x,R)=>`\${${u}.${R}}`)},J=(t)=>{return`Object.entries(${t} || {}).reduce((params, [key, value]) => { params.append(key, String(value)); return params; }, new URLSearchParams()).toString()`},Gt=(t)=>{let w=l(t.name),u=`${w.charAt(0).toUpperCase()+w.slice(1)}RouteConfigType`,x=`${W(t.name)}Fetcher`,R=t.method.toLowerCase(),M=K(t),C=M==="never",E=C?"":`export type ${u} = ${M}`,$=[],A=t.params&&Object.keys(t.params).length>0,O=t.payload!==void 0,z=t.queries!==void 0,d=t.response?`${u}["response"]`:"never";if(A)$.push(`params: ${u}["params"]`);if(O)$.push(`payload: ${u}["payload"]`);if(z)$.push(`queries: ${u}["queries"]`);let I=$.length>0?`config: {
|
|
6
|
+
${$.join(`;
|
|
6
7
|
`)};
|
|
7
|
-
}`:"",
|
|
8
|
-
${
|
|
8
|
+
}`:"",H=Y(t.path),b=`\`${H}\``;if(z)b=`\`${H}?\${${J("config.queries")}}\``;let G=["post","put","patch"],F="";if(G.includes(R)&&O)F=`return await fetcher.${R}<${d}>(
|
|
9
|
+
${b},
|
|
9
10
|
config.payload,
|
|
10
|
-
);`;else
|
|
11
|
-
${
|
|
12
|
-
);`;let
|
|
13
|
-
|
|
11
|
+
);`;else F=`return await fetcher.${R}<${d}>(
|
|
12
|
+
${b},
|
|
13
|
+
);`;let U=`export class ${x} {
|
|
14
|
+
public async ${w}(${I}): Promise<ResponseDataType<${d}>> {
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
const fetcher = new Fetcher(this.baseURL);
|
|
16
|
+
const fetcher = new Fetcher();
|
|
17
17
|
|
|
18
|
-
${
|
|
18
|
+
${F}
|
|
19
19
|
}
|
|
20
|
-
}
|
|
21
|
-
import {
|
|
20
|
+
}`,B=`import { Fetcher } from "@ooneex/fetcher";
|
|
21
|
+
import type { ResponseDataType } from "@ooneex/http-response";`;return C?`${B}
|
|
22
22
|
|
|
23
|
-
${
|
|
23
|
+
${U}`:`${B}
|
|
24
24
|
|
|
25
|
-
${
|
|
26
|
-
constructor(private baseURL: string) {}
|
|
25
|
+
${E}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
27
|
+
${U}`},kt=(t)=>{let w=l(t.name),u=`${w.charAt(0).toUpperCase()+w.slice(1)}RouteConfigType`,x=`${W(t.name)}Socket`,R=K(t),M=R==="never",C=M?"":`export type ${u} = ${R}`,E=t.params&&Object.keys(t.params).length>0,$=t.payload&&Object.keys(t.payload).length>0,A=t.queries&&Object.keys(t.queries).length>0,O=E?`params: ${u}["params"]`:"",d=`\`${Y(t.path,!1)}\``,I=[];if($)I.push(`payload: ${u}["payload"]`);if(A)I.push(`queries: ${u}["queries"]`);I.push("language?: LocaleInfoType");let H=I.length>0?`{ ${I.join("; ")} }`:"Record<string, unknown>",b=t.response?`${u}["response"]`:"never",G=`export class ${x} {
|
|
28
|
+
public ${w}(${O}): ISocket<${H}, ${b}> {
|
|
29
|
+
const url = ${d};
|
|
30
|
+
const socket = new Socket<${H}, ${b}>(url);
|
|
31
31
|
|
|
32
|
-
socket.onMessage((response) => {
|
|
32
|
+
socket.onMessage((response: ResponseDataType<${b}>) => {
|
|
33
33
|
// TODO: Handle socket message event
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
socket.onOpen((event) => {
|
|
36
|
+
socket.onOpen((event: Event) => {
|
|
37
37
|
// TODO: Handle socket open event
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
socket.onClose((event) => {
|
|
40
|
+
socket.onClose((event: CloseEvent) => {
|
|
41
41
|
// TODO: Handle socket close event
|
|
42
42
|
});
|
|
43
43
|
|
|
44
|
-
socket.onError((event, response) => {
|
|
44
|
+
socket.onError((event: Event, response?: ResponseDataType<${b}>) => {
|
|
45
45
|
// TODO: Handle socket error event
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
return socket;
|
|
49
49
|
}
|
|
50
|
-
}
|
|
51
|
-
import { type ISocket, Socket } from "@ooneex/socket/client"
|
|
50
|
+
}`,F=`import type { ResponseDataType } from "@ooneex/http-response";
|
|
51
|
+
import { type ISocket, Socket } from "@ooneex/socket/client";
|
|
52
|
+
import type { LocaleInfoType } from "@ooneex/translation";`;return M?`${F}
|
|
52
53
|
|
|
53
|
-
${
|
|
54
|
+
${G}`:`${F}
|
|
54
55
|
|
|
55
|
-
${C}
|
|
56
|
-
|
|
56
|
+
${C}
|
|
57
|
+
|
|
58
|
+
${G}`},zt=(t)=>{let w=l(t.name),u=`${w.charAt(0).toUpperCase()+w.slice(1)}RouteConfigType`,x=`use${W(t.name)}`,R=t.method.toUpperCase(),M=K(t),C=M==="never",E=C?"":`export type ${u} = ${M}`,A=["GET","HEAD","OPTIONS"].includes(R),O=t.params&&Object.keys(t.params).length>0,z=t.payload!==void 0,d=t.queries!==void 0,I=t.response?`${u}["response"]`:"never";if(A){let L=[];if(O)L.push(`params: ${u}["params"]`);if(d)L.push(`queries?: ${u}["queries"]`);let m=L.length>0?`config: {
|
|
59
|
+
${L.join(`;
|
|
57
60
|
`)};
|
|
58
|
-
}`:"",
|
|
59
|
-
const url = ${
|
|
61
|
+
}`:"",Z=`[${t.name.split(".").map((D)=>`'${D}'`).join(", ")}`;if(O&&t.params){let D=Object.keys(t.params);for(let e of D)Z+=`, config.params.${e}`}if(d)Z+=", config.queries";Z+="]";let N=Y(t.path),S=`\`${N}\``;if(d)S=`\`${N}?\${${J("config.queries")}}\``;let h=R.toLowerCase(),y=`const fetcher = new Fetcher();
|
|
62
|
+
const url = ${S};
|
|
60
63
|
|
|
61
|
-
return await fetcher.${
|
|
64
|
+
return await fetcher.${h}<${I}>(url);`,P=`export const ${x} = (${m}) => {
|
|
62
65
|
return useQuery({
|
|
63
|
-
queryKey: ${
|
|
66
|
+
queryKey: ${Z},
|
|
64
67
|
queryFn: async () => {
|
|
65
|
-
${
|
|
68
|
+
${y}
|
|
66
69
|
},
|
|
67
70
|
});
|
|
68
|
-
}
|
|
69
|
-
import { Fetcher } from '@ooneex/fetcher'
|
|
71
|
+
};`,o=`import { useQuery } from '@tanstack/react-query';
|
|
72
|
+
import { Fetcher } from '@ooneex/fetcher';`;return C?`${o}
|
|
73
|
+
|
|
74
|
+
${P}`:`${o}
|
|
70
75
|
|
|
71
|
-
${
|
|
76
|
+
${E}
|
|
72
77
|
|
|
73
|
-
${
|
|
74
|
-
${
|
|
78
|
+
${P}`}let H=[];if(O)H.push(`params: ${u}["params"]`);if(z)H.push(`payload: ${u}["payload"]`);if(d)H.push(`queries?: ${u}["queries"]`);let b=H.length>0?`config: {
|
|
79
|
+
${H.join(`;
|
|
75
80
|
`)};
|
|
76
|
-
}`:"config?: Record<string, never>",
|
|
77
|
-
const url = ${
|
|
81
|
+
}`:"config?: Record<string, never>",G=Y(t.path),F=`\`${G}\``;if(d)F=`\`${G}\${config.queries ? \`?\${${J("config.queries")}}\` : ''}\``;let B=["POST","PUT","PATCH"].includes(R)&&z,q=R.toLowerCase(),V=`const fetcher = new Fetcher();
|
|
82
|
+
const url = ${F};
|
|
78
83
|
|
|
79
|
-
`;if(
|
|
84
|
+
`;if(B)V+=`return await fetcher.${q}<${I}>(url, config.payload);`;else V+=`return await fetcher.${q}<${I}>(url);`;let r=`export const ${x} = () => {
|
|
80
85
|
const mutation = useMutation({
|
|
81
|
-
mutationFn: async (${
|
|
82
|
-
${
|
|
86
|
+
mutationFn: async (${b}) => {
|
|
87
|
+
${V}
|
|
83
88
|
},
|
|
84
89
|
});
|
|
85
90
|
|
|
86
91
|
return mutation;
|
|
87
|
-
}
|
|
88
|
-
import { Fetcher } from '@ooneex/fetcher'
|
|
92
|
+
};`,Q=`import { useMutation } from '@tanstack/react-query';
|
|
93
|
+
import { Fetcher } from '@ooneex/fetcher';`;return C?`${Q}
|
|
94
|
+
|
|
95
|
+
${r}`:`${Q}
|
|
89
96
|
|
|
90
|
-
${
|
|
97
|
+
${E}
|
|
91
98
|
|
|
92
|
-
${
|
|
99
|
+
${r}`};export{_ as router,K as routeConfigToTypeString,kt as routeConfigToSocketString,Ot as routeConfigToJsonDoc,zt as routeConfigToHookString,Gt as routeConfigToFetcherString,Tt as isValidRoutePath,c as extractParameterNames,dt as VALID_NAMESPACES,It as VALID_ACTIONS,T as RouterException,j as Router,g as Route};
|
|
93
100
|
|
|
94
|
-
//# debugId=
|
|
101
|
+
//# debugId=71957B2AF18D3E1B64756E2164756E21
|