@t-req/core 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -0
- package/dist/config/engine-options.d.ts +4 -2
- package/dist/config/engine-options.d.ts.map +1 -1
- package/dist/config/index.js +9 -5
- package/dist/config/index.js.map +18 -5
- package/dist/config/resolve.d.ts.map +1 -1
- package/dist/config/types.d.ts +14 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/cookies/persistence.js +2 -2
- package/dist/cookies/persistence.js.map +2 -2
- package/dist/cookies.js +5 -5
- package/dist/cookies.js.map +2 -2
- package/dist/engine/engine.d.ts +3 -0
- package/dist/engine/engine.d.ts.map +1 -1
- package/dist/engine/index.js +4 -4
- package/dist/engine/index.js.map +3 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +17 -5
- package/dist/plugin/define.d.ts +65 -0
- package/dist/plugin/define.d.ts.map +1 -0
- package/dist/plugin/index.d.ts +7 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +8 -0
- package/dist/plugin/index.js.map +22 -0
- package/dist/plugin/loader.d.ts +69 -0
- package/dist/plugin/loader.d.ts.map +1 -0
- package/dist/plugin/manager.d.ts +186 -0
- package/dist/plugin/manager.d.ts.map +1 -0
- package/dist/plugin/permissions.d.ts +33 -0
- package/dist/plugin/permissions.d.ts.map +1 -0
- package/dist/plugin/subprocess.d.ts +100 -0
- package/dist/plugin/subprocess.d.ts.map +1 -0
- package/dist/plugin/types.d.ts +668 -0
- package/dist/plugin/types.d.ts.map +1 -0
- package/dist/resolver/index.js +3 -3
- package/dist/resolver/index.js.map +2 -2
- package/dist/runtime/index.js +2 -2
- package/dist/runtime/index.js.map +2 -2
- package/dist/runtime/types.d.ts.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -7,6 +7,17 @@ HTTP request parsing, execution, and testing. Define requests in `.http` files,
|
|
|
7
7
|
[](https://opensource.org/licenses/MIT)
|
|
8
8
|
[](https://www.typescriptlang.org/)
|
|
9
9
|
|
|
10
|
+
## Part of the t-req Ecosystem
|
|
11
|
+
|
|
12
|
+
`@t-req/core` is the foundation of the t-req ecosystem. On top of the library, t-req provides:
|
|
13
|
+
|
|
14
|
+
- **CLI & TUI** ([`@t-req/app`](../app)) -- `treq open` launches an interactive terminal UI with a built-in server
|
|
15
|
+
- **Web dashboard** ([`@t-req/web`](../web)) -- Browser-based request explorer and response viewer
|
|
16
|
+
- **Multi-language server** -- `treq serve` exposes a REST API so any language can execute `.http` files
|
|
17
|
+
- **Observer mode** -- `createClient()` auto-detects the `TREQ_SERVER` env var and routes requests through the server for zero-config observability
|
|
18
|
+
|
|
19
|
+
See the [documentation](https://t-req.io) for the full overview.
|
|
20
|
+
|
|
10
21
|
## Features
|
|
11
22
|
|
|
12
23
|
- **Parse `.http` files** - Standard format used by VS Code REST Client, JetBrains HTTP Client
|
|
@@ -527,6 +538,42 @@ const client = createClient({
|
|
|
527
538
|
});
|
|
528
539
|
```
|
|
529
540
|
|
|
541
|
+
## Plugins
|
|
542
|
+
|
|
543
|
+
Extend t-req with custom resolvers, hooks, and middleware:
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { definePlugin } from '@t-req/core';
|
|
547
|
+
|
|
548
|
+
export default definePlugin({
|
|
549
|
+
name: 'my-plugin',
|
|
550
|
+
version: '1.0.0',
|
|
551
|
+
resolvers: {
|
|
552
|
+
$timestamp: () => String(Date.now()),
|
|
553
|
+
},
|
|
554
|
+
hooks: {
|
|
555
|
+
async 'response.after'(input, output) {
|
|
556
|
+
if (input.response.status === 429) {
|
|
557
|
+
output.retry = { delayMs: 1000 };
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
Add to your config:
|
|
565
|
+
|
|
566
|
+
```jsonc
|
|
567
|
+
// treq.jsonc
|
|
568
|
+
{
|
|
569
|
+
"plugins": ["file://./my-plugin.ts"]
|
|
570
|
+
}
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
Write plugins in any language using the subprocess protocol — see `examples/plugins/` for Python examples.
|
|
574
|
+
|
|
575
|
+
**Full documentation:** [t-req.io/docs/guides/plugins](https://t-req.io/docs/guides/plugins)
|
|
576
|
+
|
|
530
577
|
## Real-World Example: E-Commerce Checkout
|
|
531
578
|
|
|
532
579
|
Run the included demo flow (uses dummyjson.com) to see a realistic multi-step scenario:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EngineConfig } from '../engine/engine';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CombinedEvent } from '../plugin/types';
|
|
3
|
+
import type { CookieStore } from '../runtime/types';
|
|
3
4
|
import type { ResolvedConfig } from './types';
|
|
4
5
|
export type RequestDefaults = {
|
|
5
6
|
timeoutMs: number;
|
|
@@ -10,7 +11,8 @@ export type RequestDefaults = {
|
|
|
10
11
|
export type BuildEngineOptionsInput = {
|
|
11
12
|
config: ResolvedConfig;
|
|
12
13
|
cookieStore?: CookieStore;
|
|
13
|
-
|
|
14
|
+
/** Event handler for both engine and plugin events */
|
|
15
|
+
onEvent?: (event: CombinedEvent) => void;
|
|
14
16
|
};
|
|
15
17
|
export type BuildEngineOptionsResult = {
|
|
16
18
|
engineOptions: EngineConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine-options.d.ts","sourceRoot":"","sources":["../../src/config/engine-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"engine-options.d.ts","sourceRoot":"","sources":["../../src/config/engine-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,kBAAkB,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAM9C,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,cAAc,CAAC;IACvB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,sDAAsD;IACtD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,aAAa,EAAE,YAAY,CAAC;IAC5B,eAAe,EAAE,eAAe,CAAC;CAClC,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,wBAAwB,CA8C3F"}
|
package/dist/config/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import{createRequire as s}from"node:module";var jz=s(import.meta.url);function r(z){return z}function i(z){let{config:K,cookieStore:Q,onEvent:Z}=z,$={};if(K.cookies.enabled&&Q)$.cookieStore=Q;if($.headerDefaults=K.defaults.headers,$.resolvers=K.resolvers,Z)$.onEvent=Z;let X={timeoutMs:K.defaults.timeoutMs,followRedirects:K.defaults.followRedirects,validateSSL:K.defaults.validateSSL};if(K.defaults.proxy)X.proxy=K.defaults.proxy;return{engineOptions:$,requestDefaults:X}}function b(z){let K=[],Q="code",Z=0,$=()=>{while(K.length>0){let X=K[K.length-1];if(X===" "||X==="\t"){K.pop();continue}break}};while(Z<z.length){let X=z.charAt(Z),Y=z[Z+1];switch(Q){case"code":if(X==='"')K.push(X),Q="string",Z++;else if(X==="/"&&Y==="/")$(),Q="line-comment",Z+=2;else if(X==="/"&&Y==="*")Q="block-comment",Z+=2;else K.push(X),Z++;break;case"string":if(K.push(X),X==="\\"&&Y!==void 0)K.push(Y),Z+=2;else if(X==='"')Q="code",Z++;else Z++;break;case"line-comment":if(X===`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
`)
|
|
1
|
+
import{createRequire as lq}from"node:module";var gq=Object.defineProperty;var mq=($,q)=>{for(var Q in q)gq($,Q,{get:q[Q],enumerable:!0,configurable:!0,set:(G)=>q[Q]=()=>G})};var G$=lq(import.meta.url);var A$={};mq(A$,{void:()=>N3,util:()=>U,unknown:()=>D3,union:()=>C3,undefined:()=>K3,tuple:()=>T3,transformer:()=>c3,symbol:()=>A3,string:()=>Lq,strictObject:()=>v3,setErrorMap:()=>pq,set:()=>h3,record:()=>P3,quotelessJson:()=>cq,promise:()=>l3,preprocess:()=>n3,pipeline:()=>d3,ostring:()=>r3,optional:()=>u3,onumber:()=>i3,oboolean:()=>o3,objectUtil:()=>p$,object:()=>b3,number:()=>Uq,nullable:()=>p3,null:()=>O3,never:()=>j3,nativeEnum:()=>m3,nan:()=>E3,map:()=>f3,makeIssue:()=>R$,literal:()=>Z3,lazy:()=>y3,late:()=>w3,isValid:()=>d,isDirty:()=>f$,isAsync:()=>H$,isAborted:()=>P$,intersection:()=>k3,instanceof:()=>S3,getParsedType:()=>g,getErrorMap:()=>X$,function:()=>x3,enum:()=>g3,effect:()=>c3,discriminatedUnion:()=>I3,defaultErrorMap:()=>c,datetimeRegex:()=>wq,date:()=>U3,custom:()=>Eq,coerce:()=>a3,boolean:()=>Aq,bigint:()=>L3,array:()=>F3,any:()=>R3,addIssueToContext:()=>M,ZodVoid:()=>j$,ZodUnknown:()=>r,ZodUnion:()=>z$,ZodUndefined:()=>B$,ZodType:()=>L,ZodTuple:()=>l,ZodTransformer:()=>P,ZodSymbol:()=>D$,ZodString:()=>C,ZodSet:()=>q$,ZodSchema:()=>L,ZodRecord:()=>N$,ZodReadonly:()=>U$,ZodPromise:()=>Q$,ZodPipeline:()=>v$,ZodParsedType:()=>z,ZodOptional:()=>k,ZodObject:()=>O,ZodNumber:()=>i,ZodNullable:()=>p,ZodNull:()=>_$,ZodNever:()=>m,ZodNativeEnum:()=>S$,ZodNaN:()=>b$,ZodMap:()=>F$,ZodLiteral:()=>w$,ZodLazy:()=>V$,ZodIssueCode:()=>_,ZodIntersection:()=>M$,ZodFunction:()=>Y$,ZodFirstPartyTypeKind:()=>S,ZodError:()=>F,ZodEnum:()=>a,ZodEffects:()=>P,ZodDiscriminatedUnion:()=>h$,ZodDefault:()=>E$,ZodDate:()=>e,ZodCatch:()=>L$,ZodBranded:()=>x$,ZodBoolean:()=>W$,ZodBigInt:()=>o,ZodArray:()=>I,ZodAny:()=>$$,Schema:()=>L,ParseStatus:()=>R,OK:()=>D,NEVER:()=>s3,INVALID:()=>w,EMPTY_PATH:()=>nq,DIRTY:()=>t,BRAND:()=>V3});var U;(function($){$.assertEqual=(X)=>{};function q(X){}$.assertIs=q;function Q(X){throw Error()}$.assertNever=Q,$.arrayToEnum=(X)=>{let J={};for(let H of X)J[H]=H;return J},$.getValidEnumValues=(X)=>{let J=$.objectKeys(X).filter((Y)=>typeof X[X[Y]]!=="number"),H={};for(let Y of J)H[Y]=X[Y];return $.objectValues(H)},$.objectValues=(X)=>{return $.objectKeys(X).map(function(J){return X[J]})},$.objectKeys=typeof Object.keys==="function"?(X)=>Object.keys(X):(X)=>{let J=[];for(let H in X)if(Object.prototype.hasOwnProperty.call(X,H))J.push(H);return J},$.find=(X,J)=>{for(let H of X)if(J(H))return H;return},$.isInteger=typeof Number.isInteger==="function"?(X)=>Number.isInteger(X):(X)=>typeof X==="number"&&Number.isFinite(X)&&Math.floor(X)===X;function G(X,J=" | "){return X.map((H)=>typeof H==="string"?`'${H}'`:H).join(J)}$.joinValues=G,$.jsonStringifyReplacer=(X,J)=>{if(typeof J==="bigint")return J.toString();return J}})(U||(U={}));var p$;(function($){$.mergeShapes=(q,Q)=>{return{...q,...Q}}})(p$||(p$={}));var z=U.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),g=($)=>{switch(typeof $){case"undefined":return z.undefined;case"string":return z.string;case"number":return Number.isNaN($)?z.nan:z.number;case"boolean":return z.boolean;case"function":return z.function;case"bigint":return z.bigint;case"symbol":return z.symbol;case"object":if(Array.isArray($))return z.array;if($===null)return z.null;if($.then&&typeof $.then==="function"&&$.catch&&typeof $.catch==="function")return z.promise;if(typeof Map<"u"&&$ instanceof Map)return z.map;if(typeof Set<"u"&&$ instanceof Set)return z.set;if(typeof Date<"u"&&$ instanceof Date)return z.date;return z.object;default:return z.unknown}};var _=U.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),cq=($)=>{return JSON.stringify($,null,2).replace(/"([^"]+)":/g,"$1:")};class F extends Error{get errors(){return this.issues}constructor($){super();this.issues=[],this.addIssue=(Q)=>{this.issues=[...this.issues,Q]},this.addIssues=(Q=[])=>{this.issues=[...this.issues,...Q]};let q=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,q);else this.__proto__=q;this.name="ZodError",this.issues=$}format($){let q=$||function(X){return X.message},Q={_errors:[]},G=(X)=>{for(let J of X.issues)if(J.code==="invalid_union")J.unionErrors.map(G);else if(J.code==="invalid_return_type")G(J.returnTypeError);else if(J.code==="invalid_arguments")G(J.argumentsError);else if(J.path.length===0)Q._errors.push(q(J));else{let H=Q,Y=0;while(Y<J.path.length){let W=J.path[Y];if(Y!==J.path.length-1)H[W]=H[W]||{_errors:[]};else H[W]=H[W]||{_errors:[]},H[W]._errors.push(q(J));H=H[W],Y++}}};return G(this),Q}static assert($){if(!($ instanceof F))throw Error(`Not a ZodError: ${$}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,U.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten($=(q)=>q.message){let q={},Q=[];for(let G of this.issues)if(G.path.length>0){let X=G.path[0];q[X]=q[X]||[],q[X].push($(G))}else Q.push($(G));return{formErrors:Q,fieldErrors:q}}get formErrors(){return this.flatten()}}F.create=($)=>{return new F($)};var uq=($,q)=>{let Q;switch($.code){case _.invalid_type:if($.received===z.undefined)Q="Required";else Q=`Expected ${$.expected}, received ${$.received}`;break;case _.invalid_literal:Q=`Invalid literal value, expected ${JSON.stringify($.expected,U.jsonStringifyReplacer)}`;break;case _.unrecognized_keys:Q=`Unrecognized key(s) in object: ${U.joinValues($.keys,", ")}`;break;case _.invalid_union:Q="Invalid input";break;case _.invalid_union_discriminator:Q=`Invalid discriminator value. Expected ${U.joinValues($.options)}`;break;case _.invalid_enum_value:Q=`Invalid enum value. Expected ${U.joinValues($.options)}, received '${$.received}'`;break;case _.invalid_arguments:Q="Invalid function arguments";break;case _.invalid_return_type:Q="Invalid function return type";break;case _.invalid_date:Q="Invalid date";break;case _.invalid_string:if(typeof $.validation==="object")if("includes"in $.validation){if(Q=`Invalid input: must include "${$.validation.includes}"`,typeof $.validation.position==="number")Q=`${Q} at one or more positions greater than or equal to ${$.validation.position}`}else if("startsWith"in $.validation)Q=`Invalid input: must start with "${$.validation.startsWith}"`;else if("endsWith"in $.validation)Q=`Invalid input: must end with "${$.validation.endsWith}"`;else U.assertNever($.validation);else if($.validation!=="regex")Q=`Invalid ${$.validation}`;else Q="Invalid";break;case _.too_small:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at least":"more than"} ${$.minimum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at least":"over"} ${$.minimum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="bigint")Q=`Number must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${$.minimum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly equal to ":$.inclusive?"greater than or equal to ":"greater than "}${new Date(Number($.minimum))}`;else Q="Invalid input";break;case _.too_big:if($.type==="array")Q=`Array must contain ${$.exact?"exactly":$.inclusive?"at most":"less than"} ${$.maximum} element(s)`;else if($.type==="string")Q=`String must contain ${$.exact?"exactly":$.inclusive?"at most":"under"} ${$.maximum} character(s)`;else if($.type==="number")Q=`Number must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="bigint")Q=`BigInt must be ${$.exact?"exactly":$.inclusive?"less than or equal to":"less than"} ${$.maximum}`;else if($.type==="date")Q=`Date must be ${$.exact?"exactly":$.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number($.maximum))}`;else Q="Invalid input";break;case _.custom:Q="Invalid input";break;case _.invalid_intersection_types:Q="Intersection results could not be merged";break;case _.not_multiple_of:Q=`Number must be a multiple of ${$.multipleOf}`;break;case _.not_finite:Q="Number must be finite";break;default:Q=q.defaultError,U.assertNever($)}return{message:Q}},c=uq;var Bq=c;function pq($){Bq=$}function X$(){return Bq}var R$=($)=>{let{data:q,path:Q,errorMaps:G,issueData:X}=$,J=[...Q,...X.path||[]],H={...X,path:J};if(X.message!==void 0)return{...X,path:J,message:X.message};let Y="",W=G.filter((B)=>!!B).slice().reverse();for(let B of W)Y=B(H,{data:q,defaultError:Y}).message;return{...X,path:J,message:Y}},nq=[];function M($,q){let Q=X$(),G=R$({issueData:q,data:$.data,path:$.path,errorMaps:[$.common.contextualErrorMap,$.schemaErrorMap,Q,Q===c?void 0:c].filter((X)=>!!X)});$.common.issues.push(G)}class R{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray($,q){let Q=[];for(let G of q){if(G.status==="aborted")return w;if(G.status==="dirty")$.dirty();Q.push(G.value)}return{status:$.value,value:Q}}static async mergeObjectAsync($,q){let Q=[];for(let G of q){let X=await G.key,J=await G.value;Q.push({key:X,value:J})}return R.mergeObjectSync($,Q)}static mergeObjectSync($,q){let Q={};for(let G of q){let{key:X,value:J}=G;if(X.status==="aborted")return w;if(J.status==="aborted")return w;if(X.status==="dirty")$.dirty();if(J.status==="dirty")$.dirty();if(X.value!=="__proto__"&&(typeof J.value<"u"||G.alwaysSet))Q[X.value]=J.value}return{status:$.value,value:Q}}}var w=Object.freeze({status:"aborted"}),t=($)=>({status:"dirty",value:$}),D=($)=>({status:"valid",value:$}),P$=($)=>$.status==="aborted",f$=($)=>$.status==="dirty",d=($)=>$.status==="valid",H$=($)=>typeof Promise<"u"&&$ instanceof Promise;var V;(function($){$.errToObj=(q)=>typeof q==="string"?{message:q}:q||{},$.toString=(q)=>typeof q==="string"?q:q?.message})(V||(V={}));class T{constructor($,q,Q,G){this._cachedPath=[],this.parent=$,this.data=q,this._path=Q,this._key=G}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var _q=($,q)=>{if(d(q))return{success:!0,data:q.value};else{if(!$.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let Q=new F($.common.issues);return this._error=Q,this._error}}}};function E($){if(!$)return{};let{errorMap:q,invalid_type_error:Q,required_error:G,description:X}=$;if(q&&(Q||G))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(q)return{errorMap:q,description:X};return{errorMap:(H,Y)=>{let{message:W}=$;if(H.code==="invalid_enum_value")return{message:W??Y.defaultError};if(typeof Y.data>"u")return{message:W??G??Y.defaultError};if(H.code!=="invalid_type")return{message:Y.defaultError};return{message:W??Q??Y.defaultError}},description:X}}class L{get description(){return this._def.description}_getType($){return g($.data)}_getOrReturnCtx($,q){return q||{common:$.parent.common,data:$.data,parsedType:g($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}_processInputParams($){return{status:new R,ctx:{common:$.parent.common,data:$.data,parsedType:g($.data),schemaErrorMap:this._def.errorMap,path:$.path,parent:$.parent}}}_parseSync($){let q=this._parse($);if(H$(q))throw Error("Synchronous parse encountered promise.");return q}_parseAsync($){let q=this._parse($);return Promise.resolve(q)}parse($,q){let Q=this.safeParse($,q);if(Q.success)return Q.data;throw Q.error}safeParse($,q){let Q={common:{issues:[],async:q?.async??!1,contextualErrorMap:q?.errorMap},path:q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:g($)},G=this._parseSync({data:$,path:Q.path,parent:Q});return _q(Q,G)}"~validate"($){let q={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:g($)};if(!this["~standard"].async)try{let Q=this._parseSync({data:$,path:[],parent:q});return d(Q)?{value:Q.value}:{issues:q.common.issues}}catch(Q){if(Q?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;q.common={issues:[],async:!0}}return this._parseAsync({data:$,path:[],parent:q}).then((Q)=>d(Q)?{value:Q.value}:{issues:q.common.issues})}async parseAsync($,q){let Q=await this.safeParseAsync($,q);if(Q.success)return Q.data;throw Q.error}async safeParseAsync($,q){let Q={common:{issues:[],contextualErrorMap:q?.errorMap,async:!0},path:q?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:$,parsedType:g($)},G=this._parse({data:$,path:Q.path,parent:Q}),X=await(H$(G)?G:Promise.resolve(G));return _q(Q,X)}refine($,q){let Q=(G)=>{if(typeof q==="string"||typeof q>"u")return{message:q};else if(typeof q==="function")return q(G);else return q};return this._refinement((G,X)=>{let J=$(G),H=()=>X.addIssue({code:_.custom,...Q(G)});if(typeof Promise<"u"&&J instanceof Promise)return J.then((Y)=>{if(!Y)return H(),!1;else return!0});if(!J)return H(),!1;else return!0})}refinement($,q){return this._refinement((Q,G)=>{if(!$(Q))return G.addIssue(typeof q==="function"?q(Q,G):q),!1;else return!0})}_refinement($){return new P({schema:this,typeName:S.ZodEffects,effect:{type:"refinement",refinement:$}})}superRefine($){return this._refinement($)}constructor($){this.spa=this.safeParseAsync,this._def=$,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:(q)=>this["~validate"](q)}}optional(){return k.create(this,this._def)}nullable(){return p.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return I.create(this)}promise(){return Q$.create(this,this._def)}or($){return z$.create([this,$],this._def)}and($){return M$.create(this,$,this._def)}transform($){return new P({...E(this._def),schema:this,typeName:S.ZodEffects,effect:{type:"transform",transform:$}})}default($){let q=typeof $==="function"?$:()=>$;return new E$({...E(this._def),innerType:this,defaultValue:q,typeName:S.ZodDefault})}brand(){return new x$({typeName:S.ZodBranded,type:this,...E(this._def)})}catch($){let q=typeof $==="function"?$:()=>$;return new L$({...E(this._def),innerType:this,catchValue:q,typeName:S.ZodCatch})}describe($){return new this.constructor({...this._def,description:$})}pipe($){return v$.create(this,$)}readonly(){return U$.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var dq=/^c[^\s-]{8,}$/i,rq=/^[0-9a-z]+$/,iq=/^[0-9A-HJKMNP-TV-Z]{26}$/i,oq=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,aq=/^[a-z0-9_-]{21}$/i,sq=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,tq=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,eq=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,$3="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",n$,q3=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Q3=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,G3=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,X3=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,H3=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,J3=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Mq="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Y3=new RegExp(`^${Mq}$`);function Vq($){let q="[0-5]\\d";if($.precision)q=`${q}\\.\\d{${$.precision}}`;else if($.precision==null)q=`${q}(\\.\\d+)?`;let Q=$.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${q})${Q}`}function W3($){return new RegExp(`^${Vq($)}$`)}function wq($){let q=`${Mq}T${Vq($)}`,Q=[];if(Q.push($.local?"Z?":"Z"),$.offset)Q.push("([+-]\\d{2}:?\\d{2})");return q=`${q}(${Q.join("|")})`,new RegExp(`^${q}$`)}function B3($,q){if((q==="v4"||!q)&&q3.test($))return!0;if((q==="v6"||!q)&&G3.test($))return!0;return!1}function _3($,q){if(!sq.test($))return!1;try{let[Q]=$.split(".");if(!Q)return!1;let G=Q.replace(/-/g,"+").replace(/_/g,"/").padEnd(Q.length+(4-Q.length%4)%4,"="),X=JSON.parse(atob(G));if(typeof X!=="object"||X===null)return!1;if("typ"in X&&X?.typ!=="JWT")return!1;if(!X.alg)return!1;if(q&&X.alg!==q)return!1;return!0}catch{return!1}}function z3($,q){if((q==="v4"||!q)&&Q3.test($))return!0;if((q==="v6"||!q)&&X3.test($))return!0;return!1}class C extends L{_parse($){if(this._def.coerce)$.data=String($.data);if(this._getType($)!==z.string){let X=this._getOrReturnCtx($);return M(X,{code:_.invalid_type,expected:z.string,received:X.parsedType}),w}let Q=new R,G=void 0;for(let X of this._def.checks)if(X.kind==="min"){if($.data.length<X.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_small,minimum:X.value,type:"string",inclusive:!0,exact:!1,message:X.message}),Q.dirty()}else if(X.kind==="max"){if($.data.length>X.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_big,maximum:X.value,type:"string",inclusive:!0,exact:!1,message:X.message}),Q.dirty()}else if(X.kind==="length"){let J=$.data.length>X.value,H=$.data.length<X.value;if(J||H){if(G=this._getOrReturnCtx($,G),J)M(G,{code:_.too_big,maximum:X.value,type:"string",inclusive:!0,exact:!0,message:X.message});else if(H)M(G,{code:_.too_small,minimum:X.value,type:"string",inclusive:!0,exact:!0,message:X.message});Q.dirty()}}else if(X.kind==="email"){if(!eq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"email",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="emoji"){if(!n$)n$=new RegExp($3,"u");if(!n$.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"emoji",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="uuid"){if(!oq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"uuid",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="nanoid"){if(!aq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"nanoid",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="cuid"){if(!dq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"cuid",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="cuid2"){if(!rq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"cuid2",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="ulid"){if(!iq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"ulid",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="url")try{new URL($.data)}catch{G=this._getOrReturnCtx($,G),M(G,{validation:"url",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="regex"){if(X.regex.lastIndex=0,!X.regex.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"regex",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="trim")$.data=$.data.trim();else if(X.kind==="includes"){if(!$.data.includes(X.value,X.position))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{includes:X.value,position:X.position},message:X.message}),Q.dirty()}else if(X.kind==="toLowerCase")$.data=$.data.toLowerCase();else if(X.kind==="toUpperCase")$.data=$.data.toUpperCase();else if(X.kind==="startsWith"){if(!$.data.startsWith(X.value))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{startsWith:X.value},message:X.message}),Q.dirty()}else if(X.kind==="endsWith"){if(!$.data.endsWith(X.value))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:{endsWith:X.value},message:X.message}),Q.dirty()}else if(X.kind==="datetime"){if(!wq(X).test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"datetime",message:X.message}),Q.dirty()}else if(X.kind==="date"){if(!Y3.test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"date",message:X.message}),Q.dirty()}else if(X.kind==="time"){if(!W3(X).test($.data))G=this._getOrReturnCtx($,G),M(G,{code:_.invalid_string,validation:"time",message:X.message}),Q.dirty()}else if(X.kind==="duration"){if(!tq.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"duration",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="ip"){if(!B3($.data,X.version))G=this._getOrReturnCtx($,G),M(G,{validation:"ip",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="jwt"){if(!_3($.data,X.alg))G=this._getOrReturnCtx($,G),M(G,{validation:"jwt",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="cidr"){if(!z3($.data,X.version))G=this._getOrReturnCtx($,G),M(G,{validation:"cidr",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="base64"){if(!H3.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"base64",code:_.invalid_string,message:X.message}),Q.dirty()}else if(X.kind==="base64url"){if(!J3.test($.data))G=this._getOrReturnCtx($,G),M(G,{validation:"base64url",code:_.invalid_string,message:X.message}),Q.dirty()}else U.assertNever(X);return{status:Q.value,value:$.data}}_regex($,q,Q){return this.refinement((G)=>$.test(G),{validation:q,code:_.invalid_string,...V.errToObj(Q)})}_addCheck($){return new C({...this._def,checks:[...this._def.checks,$]})}email($){return this._addCheck({kind:"email",...V.errToObj($)})}url($){return this._addCheck({kind:"url",...V.errToObj($)})}emoji($){return this._addCheck({kind:"emoji",...V.errToObj($)})}uuid($){return this._addCheck({kind:"uuid",...V.errToObj($)})}nanoid($){return this._addCheck({kind:"nanoid",...V.errToObj($)})}cuid($){return this._addCheck({kind:"cuid",...V.errToObj($)})}cuid2($){return this._addCheck({kind:"cuid2",...V.errToObj($)})}ulid($){return this._addCheck({kind:"ulid",...V.errToObj($)})}base64($){return this._addCheck({kind:"base64",...V.errToObj($)})}base64url($){return this._addCheck({kind:"base64url",...V.errToObj($)})}jwt($){return this._addCheck({kind:"jwt",...V.errToObj($)})}ip($){return this._addCheck({kind:"ip",...V.errToObj($)})}cidr($){return this._addCheck({kind:"cidr",...V.errToObj($)})}datetime($){if(typeof $==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:$});return this._addCheck({kind:"datetime",precision:typeof $?.precision>"u"?null:$?.precision,offset:$?.offset??!1,local:$?.local??!1,...V.errToObj($?.message)})}date($){return this._addCheck({kind:"date",message:$})}time($){if(typeof $==="string")return this._addCheck({kind:"time",precision:null,message:$});return this._addCheck({kind:"time",precision:typeof $?.precision>"u"?null:$?.precision,...V.errToObj($?.message)})}duration($){return this._addCheck({kind:"duration",...V.errToObj($)})}regex($,q){return this._addCheck({kind:"regex",regex:$,...V.errToObj(q)})}includes($,q){return this._addCheck({kind:"includes",value:$,position:q?.position,...V.errToObj(q?.message)})}startsWith($,q){return this._addCheck({kind:"startsWith",value:$,...V.errToObj(q)})}endsWith($,q){return this._addCheck({kind:"endsWith",value:$,...V.errToObj(q)})}min($,q){return this._addCheck({kind:"min",value:$,...V.errToObj(q)})}max($,q){return this._addCheck({kind:"max",value:$,...V.errToObj(q)})}length($,q){return this._addCheck({kind:"length",value:$,...V.errToObj(q)})}nonempty($){return this.min(1,V.errToObj($))}trim(){return new C({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new C({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new C({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(($)=>$.kind==="datetime")}get isDate(){return!!this._def.checks.find(($)=>$.kind==="date")}get isTime(){return!!this._def.checks.find(($)=>$.kind==="time")}get isDuration(){return!!this._def.checks.find(($)=>$.kind==="duration")}get isEmail(){return!!this._def.checks.find(($)=>$.kind==="email")}get isURL(){return!!this._def.checks.find(($)=>$.kind==="url")}get isEmoji(){return!!this._def.checks.find(($)=>$.kind==="emoji")}get isUUID(){return!!this._def.checks.find(($)=>$.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(($)=>$.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(($)=>$.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(($)=>$.kind==="cuid2")}get isULID(){return!!this._def.checks.find(($)=>$.kind==="ulid")}get isIP(){return!!this._def.checks.find(($)=>$.kind==="ip")}get isCIDR(){return!!this._def.checks.find(($)=>$.kind==="cidr")}get isBase64(){return!!this._def.checks.find(($)=>$.kind==="base64")}get isBase64url(){return!!this._def.checks.find(($)=>$.kind==="base64url")}get minLength(){let $=null;for(let q of this._def.checks)if(q.kind==="min"){if($===null||q.value>$)$=q.value}return $}get maxLength(){let $=null;for(let q of this._def.checks)if(q.kind==="max"){if($===null||q.value<$)$=q.value}return $}}C.create=($)=>{return new C({checks:[],typeName:S.ZodString,coerce:$?.coerce??!1,...E($)})};function M3($,q){let Q=($.toString().split(".")[1]||"").length,G=(q.toString().split(".")[1]||"").length,X=Q>G?Q:G,J=Number.parseInt($.toFixed(X).replace(".","")),H=Number.parseInt(q.toFixed(X).replace(".",""));return J%H/10**X}class i extends L{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse($){if(this._def.coerce)$.data=Number($.data);if(this._getType($)!==z.number){let X=this._getOrReturnCtx($);return M(X,{code:_.invalid_type,expected:z.number,received:X.parsedType}),w}let Q=void 0,G=new R;for(let X of this._def.checks)if(X.kind==="int"){if(!U.isInteger($.data))Q=this._getOrReturnCtx($,Q),M(Q,{code:_.invalid_type,expected:"integer",received:"float",message:X.message}),G.dirty()}else if(X.kind==="min"){if(X.inclusive?$.data<X.value:$.data<=X.value)Q=this._getOrReturnCtx($,Q),M(Q,{code:_.too_small,minimum:X.value,type:"number",inclusive:X.inclusive,exact:!1,message:X.message}),G.dirty()}else if(X.kind==="max"){if(X.inclusive?$.data>X.value:$.data>=X.value)Q=this._getOrReturnCtx($,Q),M(Q,{code:_.too_big,maximum:X.value,type:"number",inclusive:X.inclusive,exact:!1,message:X.message}),G.dirty()}else if(X.kind==="multipleOf"){if(M3($.data,X.value)!==0)Q=this._getOrReturnCtx($,Q),M(Q,{code:_.not_multiple_of,multipleOf:X.value,message:X.message}),G.dirty()}else if(X.kind==="finite"){if(!Number.isFinite($.data))Q=this._getOrReturnCtx($,Q),M(Q,{code:_.not_finite,message:X.message}),G.dirty()}else U.assertNever(X);return{status:G.value,value:$.data}}gte($,q){return this.setLimit("min",$,!0,V.toString(q))}gt($,q){return this.setLimit("min",$,!1,V.toString(q))}lte($,q){return this.setLimit("max",$,!0,V.toString(q))}lt($,q){return this.setLimit("max",$,!1,V.toString(q))}setLimit($,q,Q,G){return new i({...this._def,checks:[...this._def.checks,{kind:$,value:q,inclusive:Q,message:V.toString(G)}]})}_addCheck($){return new i({...this._def,checks:[...this._def.checks,$]})}int($){return this._addCheck({kind:"int",message:V.toString($)})}positive($){return this._addCheck({kind:"min",value:0,inclusive:!1,message:V.toString($)})}negative($){return this._addCheck({kind:"max",value:0,inclusive:!1,message:V.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:0,inclusive:!0,message:V.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:0,inclusive:!0,message:V.toString($)})}multipleOf($,q){return this._addCheck({kind:"multipleOf",value:$,message:V.toString(q)})}finite($){return this._addCheck({kind:"finite",message:V.toString($)})}safe($){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:V.toString($)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:V.toString($)})}get minValue(){let $=null;for(let q of this._def.checks)if(q.kind==="min"){if($===null||q.value>$)$=q.value}return $}get maxValue(){let $=null;for(let q of this._def.checks)if(q.kind==="max"){if($===null||q.value<$)$=q.value}return $}get isInt(){return!!this._def.checks.find(($)=>$.kind==="int"||$.kind==="multipleOf"&&U.isInteger($.value))}get isFinite(){let $=null,q=null;for(let Q of this._def.checks)if(Q.kind==="finite"||Q.kind==="int"||Q.kind==="multipleOf")return!0;else if(Q.kind==="min"){if(q===null||Q.value>q)q=Q.value}else if(Q.kind==="max"){if($===null||Q.value<$)$=Q.value}return Number.isFinite(q)&&Number.isFinite($)}}i.create=($)=>{return new i({checks:[],typeName:S.ZodNumber,coerce:$?.coerce||!1,...E($)})};class o extends L{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse($){if(this._def.coerce)try{$.data=BigInt($.data)}catch{return this._getInvalidInput($)}if(this._getType($)!==z.bigint)return this._getInvalidInput($);let Q=void 0,G=new R;for(let X of this._def.checks)if(X.kind==="min"){if(X.inclusive?$.data<X.value:$.data<=X.value)Q=this._getOrReturnCtx($,Q),M(Q,{code:_.too_small,type:"bigint",minimum:X.value,inclusive:X.inclusive,message:X.message}),G.dirty()}else if(X.kind==="max"){if(X.inclusive?$.data>X.value:$.data>=X.value)Q=this._getOrReturnCtx($,Q),M(Q,{code:_.too_big,type:"bigint",maximum:X.value,inclusive:X.inclusive,message:X.message}),G.dirty()}else if(X.kind==="multipleOf"){if($.data%X.value!==BigInt(0))Q=this._getOrReturnCtx($,Q),M(Q,{code:_.not_multiple_of,multipleOf:X.value,message:X.message}),G.dirty()}else U.assertNever(X);return{status:G.value,value:$.data}}_getInvalidInput($){let q=this._getOrReturnCtx($);return M(q,{code:_.invalid_type,expected:z.bigint,received:q.parsedType}),w}gte($,q){return this.setLimit("min",$,!0,V.toString(q))}gt($,q){return this.setLimit("min",$,!1,V.toString(q))}lte($,q){return this.setLimit("max",$,!0,V.toString(q))}lt($,q){return this.setLimit("max",$,!1,V.toString(q))}setLimit($,q,Q,G){return new o({...this._def,checks:[...this._def.checks,{kind:$,value:q,inclusive:Q,message:V.toString(G)}]})}_addCheck($){return new o({...this._def,checks:[...this._def.checks,$]})}positive($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:V.toString($)})}negative($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:V.toString($)})}nonpositive($){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:V.toString($)})}nonnegative($){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:V.toString($)})}multipleOf($,q){return this._addCheck({kind:"multipleOf",value:$,message:V.toString(q)})}get minValue(){let $=null;for(let q of this._def.checks)if(q.kind==="min"){if($===null||q.value>$)$=q.value}return $}get maxValue(){let $=null;for(let q of this._def.checks)if(q.kind==="max"){if($===null||q.value<$)$=q.value}return $}}o.create=($)=>{return new o({checks:[],typeName:S.ZodBigInt,coerce:$?.coerce??!1,...E($)})};class W$ extends L{_parse($){if(this._def.coerce)$.data=Boolean($.data);if(this._getType($)!==z.boolean){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.boolean,received:Q.parsedType}),w}return D($.data)}}W$.create=($)=>{return new W$({typeName:S.ZodBoolean,coerce:$?.coerce||!1,...E($)})};class e extends L{_parse($){if(this._def.coerce)$.data=new Date($.data);if(this._getType($)!==z.date){let X=this._getOrReturnCtx($);return M(X,{code:_.invalid_type,expected:z.date,received:X.parsedType}),w}if(Number.isNaN($.data.getTime())){let X=this._getOrReturnCtx($);return M(X,{code:_.invalid_date}),w}let Q=new R,G=void 0;for(let X of this._def.checks)if(X.kind==="min"){if($.data.getTime()<X.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_small,message:X.message,inclusive:!0,exact:!1,minimum:X.value,type:"date"}),Q.dirty()}else if(X.kind==="max"){if($.data.getTime()>X.value)G=this._getOrReturnCtx($,G),M(G,{code:_.too_big,message:X.message,inclusive:!0,exact:!1,maximum:X.value,type:"date"}),Q.dirty()}else U.assertNever(X);return{status:Q.value,value:new Date($.data.getTime())}}_addCheck($){return new e({...this._def,checks:[...this._def.checks,$]})}min($,q){return this._addCheck({kind:"min",value:$.getTime(),message:V.toString(q)})}max($,q){return this._addCheck({kind:"max",value:$.getTime(),message:V.toString(q)})}get minDate(){let $=null;for(let q of this._def.checks)if(q.kind==="min"){if($===null||q.value>$)$=q.value}return $!=null?new Date($):null}get maxDate(){let $=null;for(let q of this._def.checks)if(q.kind==="max"){if($===null||q.value<$)$=q.value}return $!=null?new Date($):null}}e.create=($)=>{return new e({checks:[],coerce:$?.coerce||!1,typeName:S.ZodDate,...E($)})};class D$ extends L{_parse($){if(this._getType($)!==z.symbol){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.symbol,received:Q.parsedType}),w}return D($.data)}}D$.create=($)=>{return new D$({typeName:S.ZodSymbol,...E($)})};class B$ extends L{_parse($){if(this._getType($)!==z.undefined){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.undefined,received:Q.parsedType}),w}return D($.data)}}B$.create=($)=>{return new B$({typeName:S.ZodUndefined,...E($)})};class _$ extends L{_parse($){if(this._getType($)!==z.null){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.null,received:Q.parsedType}),w}return D($.data)}}_$.create=($)=>{return new _$({typeName:S.ZodNull,...E($)})};class $$ extends L{constructor(){super(...arguments);this._any=!0}_parse($){return D($.data)}}$$.create=($)=>{return new $$({typeName:S.ZodAny,...E($)})};class r extends L{constructor(){super(...arguments);this._unknown=!0}_parse($){return D($.data)}}r.create=($)=>{return new r({typeName:S.ZodUnknown,...E($)})};class m extends L{_parse($){let q=this._getOrReturnCtx($);return M(q,{code:_.invalid_type,expected:z.never,received:q.parsedType}),w}}m.create=($)=>{return new m({typeName:S.ZodNever,...E($)})};class j$ extends L{_parse($){if(this._getType($)!==z.undefined){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.void,received:Q.parsedType}),w}return D($.data)}}j$.create=($)=>{return new j$({typeName:S.ZodVoid,...E($)})};class I extends L{_parse($){let{ctx:q,status:Q}=this._processInputParams($),G=this._def;if(q.parsedType!==z.array)return M(q,{code:_.invalid_type,expected:z.array,received:q.parsedType}),w;if(G.exactLength!==null){let J=q.data.length>G.exactLength.value,H=q.data.length<G.exactLength.value;if(J||H)M(q,{code:J?_.too_big:_.too_small,minimum:H?G.exactLength.value:void 0,maximum:J?G.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:G.exactLength.message}),Q.dirty()}if(G.minLength!==null){if(q.data.length<G.minLength.value)M(q,{code:_.too_small,minimum:G.minLength.value,type:"array",inclusive:!0,exact:!1,message:G.minLength.message}),Q.dirty()}if(G.maxLength!==null){if(q.data.length>G.maxLength.value)M(q,{code:_.too_big,maximum:G.maxLength.value,type:"array",inclusive:!0,exact:!1,message:G.maxLength.message}),Q.dirty()}if(q.common.async)return Promise.all([...q.data].map((J,H)=>{return G.type._parseAsync(new T(q,J,q.path,H))})).then((J)=>{return R.mergeArray(Q,J)});let X=[...q.data].map((J,H)=>{return G.type._parseSync(new T(q,J,q.path,H))});return R.mergeArray(Q,X)}get element(){return this._def.type}min($,q){return new I({...this._def,minLength:{value:$,message:V.toString(q)}})}max($,q){return new I({...this._def,maxLength:{value:$,message:V.toString(q)}})}length($,q){return new I({...this._def,exactLength:{value:$,message:V.toString(q)}})}nonempty($){return this.min(1,$)}}I.create=($,q)=>{return new I({type:$,minLength:null,maxLength:null,exactLength:null,typeName:S.ZodArray,...E(q)})};function J$($){if($ instanceof O){let q={};for(let Q in $.shape){let G=$.shape[Q];q[Q]=k.create(J$(G))}return new O({...$._def,shape:()=>q})}else if($ instanceof I)return new I({...$._def,type:J$($.element)});else if($ instanceof k)return k.create(J$($.unwrap()));else if($ instanceof p)return p.create(J$($.unwrap()));else if($ instanceof l)return l.create($.items.map((q)=>J$(q)));else return $}class O extends L{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let $=this._def.shape(),q=U.objectKeys($);return this._cached={shape:$,keys:q},this._cached}_parse($){if(this._getType($)!==z.object){let W=this._getOrReturnCtx($);return M(W,{code:_.invalid_type,expected:z.object,received:W.parsedType}),w}let{status:Q,ctx:G}=this._processInputParams($),{shape:X,keys:J}=this._getCached(),H=[];if(!(this._def.catchall instanceof m&&this._def.unknownKeys==="strip")){for(let W in G.data)if(!J.includes(W))H.push(W)}let Y=[];for(let W of J){let B=X[W],A=G.data[W];Y.push({key:{status:"valid",value:W},value:B._parse(new T(G,A,G.path,W)),alwaysSet:W in G.data})}if(this._def.catchall instanceof m){let W=this._def.unknownKeys;if(W==="passthrough")for(let B of H)Y.push({key:{status:"valid",value:B},value:{status:"valid",value:G.data[B]}});else if(W==="strict"){if(H.length>0)M(G,{code:_.unrecognized_keys,keys:H}),Q.dirty()}else if(W==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let W=this._def.catchall;for(let B of H){let A=G.data[B];Y.push({key:{status:"valid",value:B},value:W._parse(new T(G,A,G.path,B)),alwaysSet:B in G.data})}}if(G.common.async)return Promise.resolve().then(async()=>{let W=[];for(let B of Y){let A=await B.key,K=await B.value;W.push({key:A,value:K,alwaysSet:B.alwaysSet})}return W}).then((W)=>{return R.mergeObjectSync(Q,W)});else return R.mergeObjectSync(Q,Y)}get shape(){return this._def.shape()}strict($){return V.errToObj,new O({...this._def,unknownKeys:"strict",...$!==void 0?{errorMap:(q,Q)=>{let G=this._def.errorMap?.(q,Q).message??Q.defaultError;if(q.code==="unrecognized_keys")return{message:V.errToObj($).message??G};return{message:G}}}:{}})}strip(){return new O({...this._def,unknownKeys:"strip"})}passthrough(){return new O({...this._def,unknownKeys:"passthrough"})}extend($){return new O({...this._def,shape:()=>({...this._def.shape(),...$})})}merge($){return new O({unknownKeys:$._def.unknownKeys,catchall:$._def.catchall,shape:()=>({...this._def.shape(),...$._def.shape()}),typeName:S.ZodObject})}setKey($,q){return this.augment({[$]:q})}catchall($){return new O({...this._def,catchall:$})}pick($){let q={};for(let Q of U.objectKeys($))if($[Q]&&this.shape[Q])q[Q]=this.shape[Q];return new O({...this._def,shape:()=>q})}omit($){let q={};for(let Q of U.objectKeys(this.shape))if(!$[Q])q[Q]=this.shape[Q];return new O({...this._def,shape:()=>q})}deepPartial(){return J$(this)}partial($){let q={};for(let Q of U.objectKeys(this.shape)){let G=this.shape[Q];if($&&!$[Q])q[Q]=G;else q[Q]=G.optional()}return new O({...this._def,shape:()=>q})}required($){let q={};for(let Q of U.objectKeys(this.shape))if($&&!$[Q])q[Q]=this.shape[Q];else{let X=this.shape[Q];while(X instanceof k)X=X._def.innerType;q[Q]=X}return new O({...this._def,shape:()=>q})}keyof(){return Sq(U.objectKeys(this.shape))}}O.create=($,q)=>{return new O({shape:()=>$,unknownKeys:"strip",catchall:m.create(),typeName:S.ZodObject,...E(q)})};O.strictCreate=($,q)=>{return new O({shape:()=>$,unknownKeys:"strict",catchall:m.create(),typeName:S.ZodObject,...E(q)})};O.lazycreate=($,q)=>{return new O({shape:$,unknownKeys:"strip",catchall:m.create(),typeName:S.ZodObject,...E(q)})};class z$ extends L{_parse($){let{ctx:q}=this._processInputParams($),Q=this._def.options;function G(X){for(let H of X)if(H.result.status==="valid")return H.result;for(let H of X)if(H.result.status==="dirty")return q.common.issues.push(...H.ctx.common.issues),H.result;let J=X.map((H)=>new F(H.ctx.common.issues));return M(q,{code:_.invalid_union,unionErrors:J}),w}if(q.common.async)return Promise.all(Q.map(async(X)=>{let J={...q,common:{...q.common,issues:[]},parent:null};return{result:await X._parseAsync({data:q.data,path:q.path,parent:J}),ctx:J}})).then(G);else{let X=void 0,J=[];for(let Y of Q){let W={...q,common:{...q.common,issues:[]},parent:null},B=Y._parseSync({data:q.data,path:q.path,parent:W});if(B.status==="valid")return B;else if(B.status==="dirty"&&!X)X={result:B,ctx:W};if(W.common.issues.length)J.push(W.common.issues)}if(X)return q.common.issues.push(...X.ctx.common.issues),X.result;let H=J.map((Y)=>new F(Y));return M(q,{code:_.invalid_union,unionErrors:H}),w}}get options(){return this._def.options}}z$.create=($,q)=>{return new z$({options:$,typeName:S.ZodUnion,...E(q)})};var u=($)=>{if($ instanceof V$)return u($.schema);else if($ instanceof P)return u($.innerType());else if($ instanceof w$)return[$.value];else if($ instanceof a)return $.options;else if($ instanceof S$)return U.objectValues($.enum);else if($ instanceof E$)return u($._def.innerType);else if($ instanceof B$)return[void 0];else if($ instanceof _$)return[null];else if($ instanceof k)return[void 0,...u($.unwrap())];else if($ instanceof p)return[null,...u($.unwrap())];else if($ instanceof x$)return u($.unwrap());else if($ instanceof U$)return u($.unwrap());else if($ instanceof L$)return u($._def.innerType);else return[]};class h$ extends L{_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.object)return M(q,{code:_.invalid_type,expected:z.object,received:q.parsedType}),w;let Q=this.discriminator,G=q.data[Q],X=this.optionsMap.get(G);if(!X)return M(q,{code:_.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[Q]}),w;if(q.common.async)return X._parseAsync({data:q.data,path:q.path,parent:q});else return X._parseSync({data:q.data,path:q.path,parent:q})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create($,q,Q){let G=new Map;for(let X of q){let J=u(X.shape[$]);if(!J.length)throw Error(`A discriminator value for key \`${$}\` could not be extracted from all schema options`);for(let H of J){if(G.has(H))throw Error(`Discriminator property ${String($)} has duplicate value ${String(H)}`);G.set(H,X)}}return new h$({typeName:S.ZodDiscriminatedUnion,discriminator:$,options:q,optionsMap:G,...E(Q)})}}function d$($,q){let Q=g($),G=g(q);if($===q)return{valid:!0,data:$};else if(Q===z.object&&G===z.object){let X=U.objectKeys(q),J=U.objectKeys($).filter((Y)=>X.indexOf(Y)!==-1),H={...$,...q};for(let Y of J){let W=d$($[Y],q[Y]);if(!W.valid)return{valid:!1};H[Y]=W.data}return{valid:!0,data:H}}else if(Q===z.array&&G===z.array){if($.length!==q.length)return{valid:!1};let X=[];for(let J=0;J<$.length;J++){let H=$[J],Y=q[J],W=d$(H,Y);if(!W.valid)return{valid:!1};X.push(W.data)}return{valid:!0,data:X}}else if(Q===z.date&&G===z.date&&+$===+q)return{valid:!0,data:$};else return{valid:!1}}class M$ extends L{_parse($){let{status:q,ctx:Q}=this._processInputParams($),G=(X,J)=>{if(P$(X)||P$(J))return w;let H=d$(X.value,J.value);if(!H.valid)return M(Q,{code:_.invalid_intersection_types}),w;if(f$(X)||f$(J))q.dirty();return{status:q.value,value:H.data}};if(Q.common.async)return Promise.all([this._def.left._parseAsync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseAsync({data:Q.data,path:Q.path,parent:Q})]).then(([X,J])=>G(X,J));else return G(this._def.left._parseSync({data:Q.data,path:Q.path,parent:Q}),this._def.right._parseSync({data:Q.data,path:Q.path,parent:Q}))}}M$.create=($,q,Q)=>{return new M$({left:$,right:q,typeName:S.ZodIntersection,...E(Q)})};class l extends L{_parse($){let{status:q,ctx:Q}=this._processInputParams($);if(Q.parsedType!==z.array)return M(Q,{code:_.invalid_type,expected:z.array,received:Q.parsedType}),w;if(Q.data.length<this._def.items.length)return M(Q,{code:_.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),w;if(!this._def.rest&&Q.data.length>this._def.items.length)M(Q,{code:_.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),q.dirty();let X=[...Q.data].map((J,H)=>{let Y=this._def.items[H]||this._def.rest;if(!Y)return null;return Y._parse(new T(Q,J,Q.path,H))}).filter((J)=>!!J);if(Q.common.async)return Promise.all(X).then((J)=>{return R.mergeArray(q,J)});else return R.mergeArray(q,X)}get items(){return this._def.items}rest($){return new l({...this._def,rest:$})}}l.create=($,q)=>{if(!Array.isArray($))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new l({items:$,typeName:S.ZodTuple,rest:null,...E(q)})};class N$ extends L{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:q,ctx:Q}=this._processInputParams($);if(Q.parsedType!==z.object)return M(Q,{code:_.invalid_type,expected:z.object,received:Q.parsedType}),w;let G=[],X=this._def.keyType,J=this._def.valueType;for(let H in Q.data)G.push({key:X._parse(new T(Q,H,Q.path,H)),value:J._parse(new T(Q,Q.data[H],Q.path,H)),alwaysSet:H in Q.data});if(Q.common.async)return R.mergeObjectAsync(q,G);else return R.mergeObjectSync(q,G)}get element(){return this._def.valueType}static create($,q,Q){if(q instanceof L)return new N$({keyType:$,valueType:q,typeName:S.ZodRecord,...E(Q)});return new N$({keyType:C.create(),valueType:$,typeName:S.ZodRecord,...E(q)})}}class F$ extends L{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse($){let{status:q,ctx:Q}=this._processInputParams($);if(Q.parsedType!==z.map)return M(Q,{code:_.invalid_type,expected:z.map,received:Q.parsedType}),w;let G=this._def.keyType,X=this._def.valueType,J=[...Q.data.entries()].map(([H,Y],W)=>{return{key:G._parse(new T(Q,H,Q.path,[W,"key"])),value:X._parse(new T(Q,Y,Q.path,[W,"value"]))}});if(Q.common.async){let H=new Map;return Promise.resolve().then(async()=>{for(let Y of J){let W=await Y.key,B=await Y.value;if(W.status==="aborted"||B.status==="aborted")return w;if(W.status==="dirty"||B.status==="dirty")q.dirty();H.set(W.value,B.value)}return{status:q.value,value:H}})}else{let H=new Map;for(let Y of J){let{key:W,value:B}=Y;if(W.status==="aborted"||B.status==="aborted")return w;if(W.status==="dirty"||B.status==="dirty")q.dirty();H.set(W.value,B.value)}return{status:q.value,value:H}}}}F$.create=($,q,Q)=>{return new F$({valueType:q,keyType:$,typeName:S.ZodMap,...E(Q)})};class q$ extends L{_parse($){let{status:q,ctx:Q}=this._processInputParams($);if(Q.parsedType!==z.set)return M(Q,{code:_.invalid_type,expected:z.set,received:Q.parsedType}),w;let G=this._def;if(G.minSize!==null){if(Q.data.size<G.minSize.value)M(Q,{code:_.too_small,minimum:G.minSize.value,type:"set",inclusive:!0,exact:!1,message:G.minSize.message}),q.dirty()}if(G.maxSize!==null){if(Q.data.size>G.maxSize.value)M(Q,{code:_.too_big,maximum:G.maxSize.value,type:"set",inclusive:!0,exact:!1,message:G.maxSize.message}),q.dirty()}let X=this._def.valueType;function J(Y){let W=new Set;for(let B of Y){if(B.status==="aborted")return w;if(B.status==="dirty")q.dirty();W.add(B.value)}return{status:q.value,value:W}}let H=[...Q.data.values()].map((Y,W)=>X._parse(new T(Q,Y,Q.path,W)));if(Q.common.async)return Promise.all(H).then((Y)=>J(Y));else return J(H)}min($,q){return new q$({...this._def,minSize:{value:$,message:V.toString(q)}})}max($,q){return new q$({...this._def,maxSize:{value:$,message:V.toString(q)}})}size($,q){return this.min($,q).max($,q)}nonempty($){return this.min(1,$)}}q$.create=($,q)=>{return new q$({valueType:$,minSize:null,maxSize:null,typeName:S.ZodSet,...E(q)})};class Y$ extends L{constructor(){super(...arguments);this.validate=this.implement}_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.function)return M(q,{code:_.invalid_type,expected:z.function,received:q.parsedType}),w;function Q(H,Y){return R$({data:H,path:q.path,errorMaps:[q.common.contextualErrorMap,q.schemaErrorMap,X$(),c].filter((W)=>!!W),issueData:{code:_.invalid_arguments,argumentsError:Y}})}function G(H,Y){return R$({data:H,path:q.path,errorMaps:[q.common.contextualErrorMap,q.schemaErrorMap,X$(),c].filter((W)=>!!W),issueData:{code:_.invalid_return_type,returnTypeError:Y}})}let X={errorMap:q.common.contextualErrorMap},J=q.data;if(this._def.returns instanceof Q$){let H=this;return D(async function(...Y){let W=new F([]),B=await H._def.args.parseAsync(Y,X).catch((N)=>{throw W.addIssue(Q(Y,N)),W}),A=await Reflect.apply(J,this,B);return await H._def.returns._def.type.parseAsync(A,X).catch((N)=>{throw W.addIssue(G(A,N)),W})})}else{let H=this;return D(function(...Y){let W=H._def.args.safeParse(Y,X);if(!W.success)throw new F([Q(Y,W.error)]);let B=Reflect.apply(J,this,W.data),A=H._def.returns.safeParse(B,X);if(!A.success)throw new F([G(B,A.error)]);return A.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...$){return new Y$({...this._def,args:l.create($).rest(r.create())})}returns($){return new Y$({...this._def,returns:$})}implement($){return this.parse($)}strictImplement($){return this.parse($)}static create($,q,Q){return new Y$({args:$?$:l.create([]).rest(r.create()),returns:q||r.create(),typeName:S.ZodFunction,...E(Q)})}}class V$ extends L{get schema(){return this._def.getter()}_parse($){let{ctx:q}=this._processInputParams($);return this._def.getter()._parse({data:q.data,path:q.path,parent:q})}}V$.create=($,q)=>{return new V$({getter:$,typeName:S.ZodLazy,...E(q)})};class w$ extends L{_parse($){if($.data!==this._def.value){let q=this._getOrReturnCtx($);return M(q,{received:q.data,code:_.invalid_literal,expected:this._def.value}),w}return{status:"valid",value:$.data}}get value(){return this._def.value}}w$.create=($,q)=>{return new w$({value:$,typeName:S.ZodLiteral,...E(q)})};function Sq($,q){return new a({values:$,typeName:S.ZodEnum,...E(q)})}class a extends L{_parse($){if(typeof $.data!=="string"){let q=this._getOrReturnCtx($),Q=this._def.values;return M(q,{expected:U.joinValues(Q),received:q.parsedType,code:_.invalid_type}),w}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has($.data)){let q=this._getOrReturnCtx($),Q=this._def.values;return M(q,{received:q.data,code:_.invalid_enum_value,options:Q}),w}return D($.data)}get options(){return this._def.values}get enum(){let $={};for(let q of this._def.values)$[q]=q;return $}get Values(){let $={};for(let q of this._def.values)$[q]=q;return $}get Enum(){let $={};for(let q of this._def.values)$[q]=q;return $}extract($,q=this._def){return a.create($,{...this._def,...q})}exclude($,q=this._def){return a.create(this.options.filter((Q)=>!$.includes(Q)),{...this._def,...q})}}a.create=Sq;class S$ extends L{_parse($){let q=U.getValidEnumValues(this._def.values),Q=this._getOrReturnCtx($);if(Q.parsedType!==z.string&&Q.parsedType!==z.number){let G=U.objectValues(q);return M(Q,{expected:U.joinValues(G),received:Q.parsedType,code:_.invalid_type}),w}if(!this._cache)this._cache=new Set(U.getValidEnumValues(this._def.values));if(!this._cache.has($.data)){let G=U.objectValues(q);return M(Q,{received:Q.data,code:_.invalid_enum_value,options:G}),w}return D($.data)}get enum(){return this._def.values}}S$.create=($,q)=>{return new S$({values:$,typeName:S.ZodNativeEnum,...E(q)})};class Q$ extends L{unwrap(){return this._def.type}_parse($){let{ctx:q}=this._processInputParams($);if(q.parsedType!==z.promise&&q.common.async===!1)return M(q,{code:_.invalid_type,expected:z.promise,received:q.parsedType}),w;let Q=q.parsedType===z.promise?q.data:Promise.resolve(q.data);return D(Q.then((G)=>{return this._def.type.parseAsync(G,{path:q.path,errorMap:q.common.contextualErrorMap})}))}}Q$.create=($,q)=>{return new Q$({type:$,typeName:S.ZodPromise,...E(q)})};class P extends L{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===S.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse($){let{status:q,ctx:Q}=this._processInputParams($),G=this._def.effect||null,X={addIssue:(J)=>{if(M(Q,J),J.fatal)q.abort();else q.dirty()},get path(){return Q.path}};if(X.addIssue=X.addIssue.bind(X),G.type==="preprocess"){let J=G.transform(Q.data,X);if(Q.common.async)return Promise.resolve(J).then(async(H)=>{if(q.value==="aborted")return w;let Y=await this._def.schema._parseAsync({data:H,path:Q.path,parent:Q});if(Y.status==="aborted")return w;if(Y.status==="dirty")return t(Y.value);if(q.value==="dirty")return t(Y.value);return Y});else{if(q.value==="aborted")return w;let H=this._def.schema._parseSync({data:J,path:Q.path,parent:Q});if(H.status==="aborted")return w;if(H.status==="dirty")return t(H.value);if(q.value==="dirty")return t(H.value);return H}}if(G.type==="refinement"){let J=(H)=>{let Y=G.refinement(H,X);if(Q.common.async)return Promise.resolve(Y);if(Y instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return H};if(Q.common.async===!1){let H=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(H.status==="aborted")return w;if(H.status==="dirty")q.dirty();return J(H.value),{status:q.value,value:H.value}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((H)=>{if(H.status==="aborted")return w;if(H.status==="dirty")q.dirty();return J(H.value).then(()=>{return{status:q.value,value:H.value}})})}if(G.type==="transform")if(Q.common.async===!1){let J=this._def.schema._parseSync({data:Q.data,path:Q.path,parent:Q});if(!d(J))return w;let H=G.transform(J.value,X);if(H instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:q.value,value:H}}else return this._def.schema._parseAsync({data:Q.data,path:Q.path,parent:Q}).then((J)=>{if(!d(J))return w;return Promise.resolve(G.transform(J.value,X)).then((H)=>({status:q.value,value:H}))});U.assertNever(G)}}P.create=($,q,Q)=>{return new P({schema:$,typeName:S.ZodEffects,effect:q,...E(Q)})};P.createWithPreprocess=($,q,Q)=>{return new P({schema:q,effect:{type:"preprocess",transform:$},typeName:S.ZodEffects,...E(Q)})};class k extends L{_parse($){if(this._getType($)===z.undefined)return D(void 0);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}k.create=($,q)=>{return new k({innerType:$,typeName:S.ZodOptional,...E(q)})};class p extends L{_parse($){if(this._getType($)===z.null)return D(null);return this._def.innerType._parse($)}unwrap(){return this._def.innerType}}p.create=($,q)=>{return new p({innerType:$,typeName:S.ZodNullable,...E(q)})};class E$ extends L{_parse($){let{ctx:q}=this._processInputParams($),Q=q.data;if(q.parsedType===z.undefined)Q=this._def.defaultValue();return this._def.innerType._parse({data:Q,path:q.path,parent:q})}removeDefault(){return this._def.innerType}}E$.create=($,q)=>{return new E$({innerType:$,typeName:S.ZodDefault,defaultValue:typeof q.default==="function"?q.default:()=>q.default,...E(q)})};class L$ extends L{_parse($){let{ctx:q}=this._processInputParams($),Q={...q,common:{...q.common,issues:[]}},G=this._def.innerType._parse({data:Q.data,path:Q.path,parent:{...Q}});if(H$(G))return G.then((X)=>{return{status:"valid",value:X.status==="valid"?X.value:this._def.catchValue({get error(){return new F(Q.common.issues)},input:Q.data})}});else return{status:"valid",value:G.status==="valid"?G.value:this._def.catchValue({get error(){return new F(Q.common.issues)},input:Q.data})}}removeCatch(){return this._def.innerType}}L$.create=($,q)=>{return new L$({innerType:$,typeName:S.ZodCatch,catchValue:typeof q.catch==="function"?q.catch:()=>q.catch,...E(q)})};class b$ extends L{_parse($){if(this._getType($)!==z.nan){let Q=this._getOrReturnCtx($);return M(Q,{code:_.invalid_type,expected:z.nan,received:Q.parsedType}),w}return{status:"valid",value:$.data}}}b$.create=($)=>{return new b$({typeName:S.ZodNaN,...E($)})};var V3=Symbol("zod_brand");class x$ extends L{_parse($){let{ctx:q}=this._processInputParams($),Q=q.data;return this._def.type._parse({data:Q,path:q.path,parent:q})}unwrap(){return this._def.type}}class v$ extends L{_parse($){let{status:q,ctx:Q}=this._processInputParams($);if(Q.common.async)return(async()=>{let X=await this._def.in._parseAsync({data:Q.data,path:Q.path,parent:Q});if(X.status==="aborted")return w;if(X.status==="dirty")return q.dirty(),t(X.value);else return this._def.out._parseAsync({data:X.value,path:Q.path,parent:Q})})();else{let G=this._def.in._parseSync({data:Q.data,path:Q.path,parent:Q});if(G.status==="aborted")return w;if(G.status==="dirty")return q.dirty(),{status:"dirty",value:G.value};else return this._def.out._parseSync({data:G.value,path:Q.path,parent:Q})}}static create($,q){return new v$({in:$,out:q,typeName:S.ZodPipeline})}}class U$ extends L{_parse($){let q=this._def.innerType._parse($),Q=(G)=>{if(d(G))G.value=Object.freeze(G.value);return G};return H$(q)?q.then((G)=>Q(G)):Q(q)}unwrap(){return this._def.innerType}}U$.create=($,q)=>{return new U$({innerType:$,typeName:S.ZodReadonly,...E(q)})};function zq($,q){let Q=typeof $==="function"?$(q):typeof $==="string"?{message:$}:$;return typeof Q==="string"?{message:Q}:Q}function Eq($,q={},Q){if($)return $$.create().superRefine((G,X)=>{let J=$(G);if(J instanceof Promise)return J.then((H)=>{if(!H){let Y=zq(q,G),W=Y.fatal??Q??!0;X.addIssue({code:"custom",...Y,fatal:W})}});if(!J){let H=zq(q,G),Y=H.fatal??Q??!0;X.addIssue({code:"custom",...H,fatal:Y})}return});return $$.create()}var w3={object:O.lazycreate},S;(function($){$.ZodString="ZodString",$.ZodNumber="ZodNumber",$.ZodNaN="ZodNaN",$.ZodBigInt="ZodBigInt",$.ZodBoolean="ZodBoolean",$.ZodDate="ZodDate",$.ZodSymbol="ZodSymbol",$.ZodUndefined="ZodUndefined",$.ZodNull="ZodNull",$.ZodAny="ZodAny",$.ZodUnknown="ZodUnknown",$.ZodNever="ZodNever",$.ZodVoid="ZodVoid",$.ZodArray="ZodArray",$.ZodObject="ZodObject",$.ZodUnion="ZodUnion",$.ZodDiscriminatedUnion="ZodDiscriminatedUnion",$.ZodIntersection="ZodIntersection",$.ZodTuple="ZodTuple",$.ZodRecord="ZodRecord",$.ZodMap="ZodMap",$.ZodSet="ZodSet",$.ZodFunction="ZodFunction",$.ZodLazy="ZodLazy",$.ZodLiteral="ZodLiteral",$.ZodEnum="ZodEnum",$.ZodEffects="ZodEffects",$.ZodNativeEnum="ZodNativeEnum",$.ZodOptional="ZodOptional",$.ZodNullable="ZodNullable",$.ZodDefault="ZodDefault",$.ZodCatch="ZodCatch",$.ZodPromise="ZodPromise",$.ZodBranded="ZodBranded",$.ZodPipeline="ZodPipeline",$.ZodReadonly="ZodReadonly"})(S||(S={}));var S3=($,q={message:`Input not instance of ${$.name}`})=>Eq((Q)=>Q instanceof $,q),Lq=C.create,Uq=i.create,E3=b$.create,L3=o.create,Aq=W$.create,U3=e.create,A3=D$.create,K3=B$.create,O3=_$.create,R3=$$.create,D3=r.create,j3=m.create,N3=j$.create,F3=I.create,b3=O.create,v3=O.strictCreate,C3=z$.create,I3=h$.create,k3=M$.create,T3=l.create,P3=N$.create,f3=F$.create,h3=q$.create,x3=Y$.create,y3=V$.create,Z3=w$.create,g3=a.create,m3=S$.create,l3=Q$.create,c3=P.create,u3=k.create,p3=p.create,n3=P.createWithPreprocess,d3=v$.create,r3=()=>Lq().optional(),i3=()=>Uq().optional(),o3=()=>Aq().optional(),a3={string:($)=>C.create({...$,coerce:!0}),number:($)=>i.create({...$,coerce:!0}),boolean:($)=>W$.create({...$,coerce:!0}),bigint:($)=>o.create({...$,coerce:!0}),date:($)=>e.create({...$,coerce:!0})};var s3=w;function t3($){if(!$.name)throw Error("Plugin must have a name");if(typeof $.name!=="string"||$.name.trim()==="")throw Error("Plugin name must be a non-empty string");if($.instanceId!==void 0&&typeof $.instanceId!=="string")throw Error("Plugin instanceId must be a string");if($.version!==void 0&&typeof $.version!=="string")throw Error("Plugin version must be a string");if($.permissions!==void 0){if(!Array.isArray($.permissions))throw Error("Plugin permissions must be an array");let q=["secrets","network","filesystem","env","subprocess","enterprise"];for(let Q of $.permissions)if(!q.includes(Q))throw Error(`Invalid permission: ${Q}. Valid permissions are: ${q.join(", ")}`)}if($.resolvers!==void 0){if(typeof $.resolvers!=="object"||$.resolvers===null)throw Error("Plugin resolvers must be an object");for(let[q,Q]of Object.entries($.resolvers)){if(!q.startsWith("$"))throw Error(`Resolver name "${q}" must start with $ (e.g., "$${q}")`);if(typeof Q!=="function")throw Error(`Resolver "${q}" must be a function`)}}if($.hooks!==void 0){if(typeof $.hooks!=="object"||$.hooks===null)throw Error("Plugin hooks must be an object");let q=["parse.after","request.before","request.compiled","request.after","response.after","error"];for(let[Q,G]of Object.entries($.hooks)){if(!q.includes(Q))throw Error(`Invalid hook: "${Q}". Valid hooks are: ${q.join(", ")}`);if(typeof G!=="function")throw Error(`Hook "${Q}" must be a function`)}}if($.commands!==void 0){if(typeof $.commands!=="object"||$.commands===null)throw Error("Plugin commands must be an object");for(let[q,Q]of Object.entries($.commands))if(typeof Q!=="function")throw Error(`Command "${q}" must be a function`)}if($.middleware!==void 0){if(!Array.isArray($.middleware))throw Error("Plugin middleware must be an array");for(let q=0;q<$.middleware.length;q++)if(typeof $.middleware[q]!=="function")throw Error(`Middleware at index ${q} must be a function`)}if($.tools!==void 0){if(typeof $.tools!=="object"||$.tools===null)throw Error("Plugin tools must be an object");for(let[q,Q]of Object.entries($.tools)){if(typeof Q.description!=="string")throw Error(`Tool "${q}" must have a description`);if(typeof Q.args!=="object"||Q.args===null)throw Error(`Tool "${q}" must have args schema`);if(typeof Q.execute!=="function")throw Error(`Tool "${q}" must have an execute function`)}}if($.event!==void 0&&typeof $.event!=="function")throw Error("Plugin event handler must be a function");if($.setup!==void 0&&typeof $.setup!=="function")throw Error("Plugin setup must be a function");if($.teardown!==void 0&&typeof $.teardown!=="function")throw Error("Plugin teardown must be a function");return{...$,instanceId:$.instanceId??"default"}}function e3($){let q=A$.object($.args);return{description:$.description,args:q,execute:async(Q,G)=>{let X=q.parse(Q);return await $.execute(X,G)}}}function C$($){return`${$.name}#${$.instanceId??"default"}`}function $0($){let q=$.indexOf("#");if(q===-1)return{name:$,instanceId:"default"};return{name:$.slice(0,q),instanceId:$.slice(q+1)}}function r$($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"command"in $&&Array.isArray($.command)}function Kq($){return typeof $==="object"&&$!==null&&!Array.isArray($)&&"name"in $&&typeof $.name==="string"&&!("command"in $)}function q0($){if(typeof $==="string")return $.startsWith("file://");if(Array.isArray($)&&typeof $[0]==="string")return $[0].startsWith("file://");return!1}function Q0($){if(typeof $==="string")return!$.startsWith("file://")&&!r$($);if(Array.isArray($)&&typeof $[0]==="string")return!$[0].startsWith("file://");return!1}function Oq($,q){let Q=G$("node:path"),G=Q.relative(q,$);return!G.startsWith("..")&&!Q.isAbsolute(G)}function Rq($,q,Q){if(!$.startsWith("file://"))throw Error(`Invalid file URL: ${$}`);let G=G$("node:path"),X=$.slice(7),J;if(X.startsWith("/"))J=G.normalize(X);else if(X.startsWith("./")||X.startsWith("../"))J=G.resolve(q,X);else throw Error(`Invalid file plugin path: ${$}. Use file://./relative/path.ts or file:///absolute/path.ts`);if(!Q&&!Oq(J,q))throw Error(`Plugin path "${$}" resolves outside project root. Set security.allowPluginsOutsideProject: true to allow.`);return J}async function G0($,q,Q){let G=G$("node:fs/promises");if(Q)return $;try{let X=await G.realpath($);if(!Oq(X,q))throw Error(`Plugin path "${$}" resolves to "${X}" which is outside project root. Symlinks pointing outside the project are not allowed. Set security.allowPluginsOutsideProject: true to allow.`);return X}catch(X){if(X.code==="ENOENT")return $;throw X}}function y$($,q,Q){let G=$.permissions??[],X=q?.[$.name];if(X!==void 0){for(let H of G)if(!X.includes(H))Q.push(`Plugin '${$.name}' requires '${H}' permission but it was denied. Some features may not work. Add to security.pluginPermissions to enable.`);return X}let J=q?.default;if(J!==void 0){let H=G.filter((Y)=>J.includes(Y));for(let Y of G)if(!J.includes(Y))Q.push(`Plugin '${$.name}' requires '${Y}' permission but it was denied by default. Some features may not work. Add to security.pluginPermissions to enable.`);return H}return G}async function i$($){let{projectRoot:q,plugins:Q,security:G,pluginPermissions:X}=$,J=$.warnings??[],H=[],Y=new Map;for(let W of Q)try{let B=await X0(W,{projectRoot:q,allowOutsideProject:G?.allowPluginsOutsideProject??!1,warnings:J,...X!==void 0?{pluginPermissions:X}:{}});if(!B)continue;let A=C$(B.plugin),K=Y.get(A);if(K!==void 0)H[K]=B;else Y.set(A,H.length),H.push(B)}catch(B){let A=B instanceof Error?B.message:String(B);J.push(`Failed to load plugin: ${A}`)}return{plugins:H,warnings:J}}async function X0($,q){let{projectRoot:Q,allowOutsideProject:G,pluginPermissions:X,warnings:J}=q;if(Kq($)){let W=y$($,X,J);return{plugin:{...$,instanceId:$.instanceId??"default"},id:C$($),source:"inline",permissions:W,initialized:!1}}if(r$($))return{plugin:{name:`subprocess:${$.command.join(" ")}`,instanceId:"default"},id:`subprocess:${$.command.join(" ")}#default`,source:"subprocess",permissions:[],initialized:!1,_subprocessConfig:$};let H,Y;if(Array.isArray($))H=$[0],Y=$[1];else H=$;if(H.startsWith("file://")){let W=Rq(H,Q,G);return await H0(W,Y,X,J,Q,G)}return await J0(H,Y,X,J)}async function H0($,q,Q,G,X,J){try{let H=$;if(X!==void 0)H=await G0($,X,J??!1);let Y=await import(H),W=Y.default??Y,B;if(typeof W==="function")B=q?W(q):W();else if(typeof W==="object"&&W!==null)B=W;else throw Error(`File "${$}" does not export a valid plugin`);if(B={...B,instanceId:B.instanceId??"default"},q&&typeof q.instanceId==="string")B={...B,instanceId:q.instanceId};let A=y$(B,Q,G);return{plugin:B,id:C$(B),source:"file",permissions:A,initialized:!1}}catch(H){throw Error(`Failed to load plugin from "${$}": ${H instanceof Error?H.message:String(H)}`)}}async function J0($,q,Q,G){try{let X=$,J=$.lastIndexOf("@");if(J>0)X=$.slice(0,J);let H=await import(X),Y=H.default??H,W;if(typeof Y==="function")W=q?Y(q):Y();else if(typeof Y==="object"&&Y!==null)W=Y;else throw Error(`Package "${X}" does not export a valid plugin`);if(W={...W,instanceId:W.instanceId??"default"},q&&typeof q.instanceId==="string")W={...W,instanceId:q.instanceId};let B=y$(W,Q,G);return{plugin:W,id:C$(W),source:"npm",permissions:B,initialized:!1}}catch(X){throw Error(`Failed to load plugin "${$}": ${X instanceof Error?X.message:String(X)}`)}}function o$($,q){return[...$,...q]}class a$ extends Error{permission;pluginName;constructor($,q){super(`Plugin "${q}" does not have "${$}" permission`);this.permission=$;this.pluginName=q;this.name="PermissionDeniedError"}}class Dq{secrets=new Map;constructor($){if($)for(let[q,Q]of Object.entries($))this.secrets.set(q,Q)}async get($){return this.secrets.get($)}set($,q){this.secrets.set($,q)}}function Z$($,q,Q){let G=Q.relative(q,$);return!G.startsWith("..")&&!Q.isAbsolute(G)}function Y0($,q){let Q=G$("node:fs/promises"),G=G$("node:path"),X=async(H)=>{let Y=G.resolve($,H);if(!q&&!Z$(Y,$,G))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!q)try{let W=await Q.realpath(Y);if(!Z$(W,$,G))throw Error(`Path "${H}" resolves to "${W}" which is outside project root. Symlinks pointing outside the project are not allowed.`);return W}catch(W){if(W.code==="ENOENT")return Y;throw W}return Y},J=async(H)=>{let Y=G.resolve($,H);if(!q&&!Z$(Y,$,G))throw Error(`Path "${H}" is outside project root. Plugins need "filesystem" permission to access files outside project.`);if(!q){let W=G.dirname(Y);try{let B=await Q.realpath(W);if(!Z$(B,$,G))throw Error(`Path "${H}" parent directory resolves to "${B}" which is outside project root. Symlinks pointing outside the project are not allowed.`)}catch(B){if(B.code!=="ENOENT")throw B}}return Y};return{async readFile(H){let Y=await X(H);return await Q.readFile(Y,"utf-8")},async writeFile(H,Y){let W=await J(H);await Q.writeFile(W,Y,"utf-8")}}}function W0($){let q=G$("node:child_process");return async(Q,G)=>{return new Promise((X,J)=>{let H=q.spawn(Q,G,{cwd:$,stdio:["pipe","pipe","pipe"]}),Y="",W="";H.stdout?.on("data",(B)=>{Y+=B.toString("utf-8")}),H.stderr?.on("data",(B)=>{W+=B.toString("utf-8")}),H.on("close",(B)=>{if(B===0)X({stdout:Y,stderr:W});else J(Error(`Command failed with code ${B}: ${W}`))}),H.on("error",(B)=>{J(B)})})}}function B0($){let q=`[plugin:${$}]`;return{debug:(Q)=>{if(process.env.DEBUG)console.debug(`${q} ${Q}`)},info:(Q)=>{console.info(`${q} ${Q}`)},warn:(Q)=>{console.warn(`${q} ${Q}`)},error:(Q)=>{console.error(`${q} ${Q}`)}}}function s$($){let{plugin:q,permissions:Q,config:G,enterprise:X,secrets:J}=$,H=q.name,Y={projectRoot:G.projectRoot,config:G,log:B0(H)};if(Q.includes("secrets"))Y.secrets=new Dq(J);if(Q.includes("network"))Y.fetch=globalThis.fetch;if(Q.includes("filesystem"))Y.fs=Y0(G.projectRoot,G.security.allowPluginsOutsideProject);if(Q.includes("env"))Y.env=process.env;if(Q.includes("subprocess"))Y.spawn=W0(G.projectRoot);if(Q.includes("enterprise")&&X)Y.enterprise=X;return Y}function _0($,q,Q){let G=[];for(let X of Q)if(!q.includes(X))G.push(`Plugin "${$.name}" requires "${X}" permission but it was denied.`);return G}function jq($,q){return $.includes(q)}function z0($,q,Q){if(!jq($,q))throw new a$(q,Q)}import{spawn as M0}from"node:child_process";function g$($){let q={...$},Q={when(G,X){if(G)q={...q,...X};return Q},ifDefined(G,X){if(X!==void 0)q={...q,[G]:X};return Q},build(){return q}};return Q}var t$=1,V0=5000,w0=1e4,Nq=3,S0=500,E0=10485760;class e${config;projectRoot;process=null;requestId=0;pendingRequests=new Map;buffer="";initialized=!1;restartCount=0;capabilities={hooks:[],resolvers:[],commands:[]};pluginInfo={name:"unknown"};constructor($,q){this.config=$;this.projectRoot=q}async start(){await this.spawn(),await this.initialize()}async spawn(){let[$,...q]=this.config.command;if(!$)throw Error("Subprocess plugin has empty command");this.process=M0($,q,{cwd:this.projectRoot,stdio:["pipe","pipe","pipe"],env:this.config.env??{}}),this.process.stdout?.on("data",(Q)=>{this.handleStdout(Q)}),this.process.stderr?.on("data",(Q)=>{let G=Q.toString("utf-8").trim();if(G)console.error(`[subprocess:${this.pluginInfo.name}] ${G}`)}),this.process.on("close",(Q,G)=>{this.handleClose(Q,G)}),this.process.on("error",(Q)=>{this.handleError(Q)})}async initialize(){let $=this.config.startupTimeoutMs??w0,q=await this.sendRequest({id:this.nextId(),type:"init",protocolVersion:t$,config:this.config.config??{},projectRoot:this.projectRoot},$);if(q.type==="error")throw Error(`Plugin init failed: ${q.error.message}`);let G=q.result;if(G.protocolVersion>t$)throw Error(`Plugin requires protocol version ${G.protocolVersion}, but t-req supports version ${t$}`);this.pluginInfo=g$({name:G.name}).ifDefined("version",G.version).ifDefined("permissions",G.permissions).build(),this.capabilities={hooks:G.hooks??[],resolvers:G.resolvers??[],commands:G.commands??[]},this.initialized=!0}handleStdout($){if(this.buffer.length+$.length>E0){this.buffer="",console.error(`[subprocess:${this.pluginInfo.name}] stdout buffer exceeded, clearing`);return}this.buffer+=$.toString("utf-8");let q=this.buffer.split(`
|
|
2
|
+
`);this.buffer=q.pop()??"";for(let Q of q){let G=Q.trim();if(!G)continue;try{let X=JSON.parse(G);this.handleResponse(X)}catch{console.error(`[subprocess:${this.pluginInfo.name}] Invalid JSON: ${G.slice(0,100)}`)}}}handleResponse($){let q=this.pendingRequests.get($.id);if(!q){console.error(`[subprocess:${this.pluginInfo.name}] Unknown response ID: ${$.id}`);return}clearTimeout(q.timeout),this.pendingRequests.delete($.id),q.resolve($)}handleClose($,q){this.process=null;for(let[Q,G]of this.pendingRequests)clearTimeout(G.timeout),G.reject(Error(`Plugin process exited with code ${$}, signal ${q}`));if(this.pendingRequests.clear(),this.initialized&&this.restartCount<(this.config.maxRestarts??Nq))this.restartCount++,console.warn(`[subprocess:${this.pluginInfo.name}] Process crashed, restarting (${this.restartCount}/${this.config.maxRestarts??Nq})`),this.spawn().then(()=>this.initialize()).catch((Q)=>{console.error(`[subprocess:${this.pluginInfo.name}] Restart failed: ${Q.message}`)})}handleError($){console.error(`[subprocess:${this.pluginInfo.name}] Process error: ${$.message}`);for(let[q,Q]of this.pendingRequests)clearTimeout(Q.timeout),Q.reject($);this.pendingRequests.clear()}nextId(){return String(++this.requestId)}async sendRequest($,q=this.config.timeoutMs??V0){if(!this.process?.stdin)throw Error("Plugin process not running");return new Promise((Q,G)=>{let X=setTimeout(()=>{this.pendingRequests.delete($.id),G(Error(`Request timed out after ${q}ms`))},q);this.pendingRequests.set($.id,{resolve:Q,reject:G,timeout:X});let J=`${JSON.stringify($)}
|
|
3
|
+
`;this.process?.stdin?.write(J)})}sendEvent($){if(!this.process?.stdin)return;let q=JSON.stringify({type:"event",event:$});this.process.stdin.write(`${q}
|
|
4
|
+
`)}async callResolver($,q){if(!this.capabilities.resolvers.includes($))throw Error(`Resolver "${$}" not supported by plugin`);let Q={id:this.nextId(),type:"resolver",name:$,args:q},G=await this.sendRequest(Q);if(G.type==="error")throw Error(G.error.message);return G.result.value}async callHook($,q,Q){if(!this.capabilities.hooks.includes($))return Q;let G={id:this.nextId(),type:"hook",name:$,input:q,output:Q},X=await this.sendRequest(G);if(X.type==="error")throw Error(X.error.message);return X.result.output}async shutdown(){if(!this.process)return;try{this.process.stdin?.write(`${JSON.stringify({type:"shutdown"})}
|
|
5
|
+
`)}catch{}let $=this.config.gracePeriodMs??S0;await new Promise((q)=>{let Q=setTimeout(()=>{if(this.process)this.process.kill("SIGKILL");q()},$);this.process?.on("close",()=>{clearTimeout(Q),q()})}),this.process=null}getPluginInfo(){return this.pluginInfo}getCapabilities(){return this.capabilities}isInitialized(){return this.initialized}}function Fq($){let q=$.getPluginInfo(),Q=$.getCapabilities(),G={};for(let H of Q.resolvers)G[H]=async(...Y)=>{return await $.callResolver(H,Y)};let X={};if(Q.hooks.includes("parse.after"))X["parse.after"]=async(H,Y)=>{let W=await $.callHook("parse.after",{file:H.file,path:H.path},{file:Y.file});if(W.file)Y.file=W.file};if(Q.hooks.includes("request.before"))X["request.before"]=async(H,Y)=>{let W=await $.callHook("request.before",{request:H.request,variables:H.variables,ctx:I$(H.ctx)},{request:Y.request});if(W.request)Y.request=W.request;let B=W.skip;if(typeof B==="boolean")Y.skip=B};if(Q.hooks.includes("request.compiled"))X["request.compiled"]=async(H,Y)=>{let W=await $.callHook("request.compiled",{request:H.request,variables:H.variables,ctx:I$(H.ctx)},{request:Y.request});if(W.request)Y.request=W.request};if(Q.hooks.includes("request.after"))X["request.after"]=async(H)=>{await $.callHook("request.after",{request:H.request,ctx:I$(H.ctx)},{})};if(Q.hooks.includes("response.after"))X["response.after"]=async(H,Y)=>{let W={status:H.response.status,statusText:H.response.statusText,headers:Object.fromEntries(H.response.headers.entries())},B=await $.callHook("response.after",{request:H.request,response:W,timing:H.timing,ctx:I$(H.ctx)},{}),A=B.status,K=B.statusText,N=B.headers,b=B.retry;if(typeof A==="number")Y.status=A;if(typeof K==="string")Y.statusText=K;if(N&&typeof N==="object")Y.headers=N;if(b&&typeof b==="object")Y.retry=b};if(Q.hooks.includes("error"))X.error=async(H,Y)=>{let W=await $.callHook("error",{request:H.request,error:{message:H.error.message,code:H.error.code},ctx:I$(H.ctx)},{}),B=W.error,A=W.retry,K=W.suppress;if(B&&typeof B==="object"&&"message"in B)Y.error=Error(B.message);if(A&&typeof A==="object")Y.retry=A;if(typeof K==="boolean")Y.suppress=K};let J=Q.hooks.length>0?async({event:H})=>{$.sendEvent(H)}:void 0;return g$({name:q.name,instanceId:"default",teardown:async()=>{await $.shutdown()}}).ifDefined("version",q.version).ifDefined("permissions",q.permissions).ifDefined("resolvers",Object.keys(G).length>0?G:void 0).ifDefined("hooks",Object.keys(X).length>0?X:void 0).ifDefined("event",J).build()}function I$($){return g$({retries:$.retries,maxRetries:$.maxRetries,session:{id:$.session.id,variables:$.session.variables},variables:$.variables,config:{projectRoot:$.config.projectRoot,variables:$.config.variables,security:$.config.security},projectRoot:$.projectRoot}).ifDefined("enterprise",$.enterprise?{org:$.enterprise.org,user:$.enterprise.user,team:$.enterprise.team,session:{id:$.enterprise.session.id,startedAt:$.enterprise.session.startedAt.toISOString(),source:$.enterprise.session.source,token:$.enterprise.session.token}}:void 0).build()}async function $q($,q){let Q=new e$($,q);await Q.start();let G=Q.getPluginInfo();return{plugin:Fq(Q),id:`${G.name}#default`,source:"subprocess",permissions:G.permissions??[],initialized:!0}}var m$=30000;async function bq($,q,Q){let G,X=new Promise((J,H)=>{G=setTimeout(()=>H(Error(Q)),q)});try{return await Promise.race([$,X])}finally{if(G!==void 0)clearTimeout(G)}}class qq{options;plugins=[];resolvers={};commands={};middleware=[];tools={};warnings=[];initialized=!1;config;onEvent;enterprise;secrets;session;constructor($){this.options=$;if(this.config={projectRoot:$.projectRoot,variables:{},security:{allowExternalFiles:!1,allowPluginsOutsideProject:$.security?.allowPluginsOutsideProject??!1}},$.onEvent!==void 0)this.onEvent=$.onEvent;if($.enterprise!==void 0)this.enterprise=$.enterprise;if($.secrets!==void 0)this.secrets=$.secrets;this.session={id:crypto.randomUUID(),variables:{}}}setEventSink($){this.onEvent=$}async initialize(){if(this.initialized)return;let $=this.options.plugins??[],q=await i$({projectRoot:this.options.projectRoot,plugins:$,warnings:this.warnings,...this.options.security!==void 0?{security:this.options.security}:{},...this.options.pluginPermissions!==void 0?{pluginPermissions:this.options.pluginPermissions}:{}});for(let Q of q.plugins)await this.initializePlugin(Q);this.initialized=!0}async initializePlugin($){let q=Date.now();try{if($.source==="subprocess"&&"_subprocessConfig"in $){let X=$._subprocessConfig,J=await $q(X,this.options.projectRoot);$.plugin=J.plugin,$.permissions=J.permissions,$.id=J.id}this.emitPluginEvent({type:"pluginLoaded",name:$.plugin.name,source:$.source,...$.plugin.version!==void 0?{version:$.plugin.version}:{}});let Q=s$({plugin:$.plugin,permissions:$.permissions,config:this.config,...this.enterprise!==void 0?{enterprise:this.enterprise}:{},...this.secrets!==void 0?{secrets:this.secrets}:{}});if($.plugin.setup)await $.plugin.setup(Q);$.initialized=!0,this.registerPluginContributions($);let G=Date.now()-q;this.emitPluginEvent({type:"pluginInitialized",name:$.plugin.name,durationMs:G}),this.plugins.push($)}catch(Q){let G=Q instanceof Error?Q.message:String(Q);this.warnings.push(`Plugin "${$.plugin.name}" setup failed: ${G}`),this.emitPluginEvent({type:"pluginError",name:$.plugin.name,stage:"setup",message:G,recoverable:!0})}}registerPluginContributions($){let q=$.plugin;if(q.resolvers)for(let[Q,G]of Object.entries(q.resolvers)){if(this.resolvers[Q])this.warnings.push(`Resolver "${Q}" from "${q.name}" shadows existing resolver`);this.resolvers[Q]=G}if(q.commands)for(let[Q,G]of Object.entries(q.commands)){if(this.commands[Q]){this.warnings.push(`Command "${Q}" from "${q.name}" shadows same command from "${this.commands[Q].pluginName}" (loaded first, takes precedence)`);continue}this.commands[Q]={handler:G,pluginName:q.name}}if(q.middleware)for(let Q of q.middleware)this.middleware.push({fn:Q,pluginName:q.name});if(q.tools)for(let[Q,G]of Object.entries(q.tools)){if(this.tools[Q])this.warnings.push(`Tool "${Q}" from "${q.name}" shadows existing tool`);this.tools[Q]={definition:G,pluginName:q.name}}}async teardown(){for(let $=this.plugins.length-1;$>=0;$--){let q=this.plugins[$];if(!q)continue;try{if(q.plugin.teardown)await q.plugin.teardown();this.emitPluginEvent({type:"pluginTeardown",name:q.plugin.name})}catch(Q){let G=Q instanceof Error?Q.message:String(Q);this.warnings.push(`Plugin "${q.plugin.name}" teardown failed: ${G}`),this.emitPluginEvent({type:"pluginError",name:q.plugin.name,stage:"teardown",message:G,recoverable:!0})}}this.plugins=[],this.initialized=!1}createHookContext($){return{retries:$.retries??0,maxRetries:$.maxRetries??3,session:this.session,variables:$.variables??{},config:this.config,projectRoot:this.options.projectRoot,...this.enterprise!==void 0?{enterprise:this.enterprise}:{}}}async triggerParseAfter($,q){return await this.executeHook("parse.after",$,q)}async triggerRequestBefore($,q){let Q=await this.executeHook("request.before",$,q);return{...Q,...Q.output.skip!==void 0?{skip:Q.output.skip}:{}}}async triggerRequestCompiled($,q){return await this.executeHook("request.compiled",$,q)}async triggerRequestAfter($){await this.executeReadOnlyHook("request.after",$)}async triggerResponseAfter($,q){let Q=await this.executeHook("response.after",$,q);return{...Q,...Q.output.retry!==void 0?{retry:Q.output.retry}:{}}}async triggerError($,q){let Q=await this.executeHook("error",$,q);return{...Q,...Q.output.retry!==void 0?{retry:Q.output.retry}:{}}}async executeHook($,q,Q){let G=!1,X="ctx"in q?q.ctx:this.createHookContext({});for(let J of this.plugins){let H=J.plugin.hooks?.[$];if(!H)continue;let Y=Date.now(),W=JSON.stringify(Q);this.emitPluginEvent({type:"pluginHookStarted",name:J.plugin.name,hook:$,ctx:X});try{let B=Promise.resolve(H(q,Q));await bq(B,m$,`Hook "${$}" in "${J.plugin.name}" timed out after ${m$}ms`);let A=JSON.stringify(Q),K=W!==A;if(K)G=!0;let N=Date.now()-Y;this.emitPluginEvent({type:"pluginHookFinished",name:J.plugin.name,hook:$,durationMs:N,modified:K,ctx:X})}catch(B){let A=B instanceof Error?B.message:String(B);this.warnings.push(`Hook "${$}" in "${J.plugin.name}" failed: ${A}`),this.emitPluginEvent({type:"pluginError",name:J.plugin.name,stage:"hook",hook:$,message:A,recoverable:!0})}}return{output:Q,modified:G}}async executeReadOnlyHook($,q){let Q="ctx"in q?q.ctx:this.createHookContext({});for(let G of this.plugins){let X=G.plugin.hooks?.[$];if(!X)continue;let J=Date.now();this.emitPluginEvent({type:"pluginHookStarted",name:G.plugin.name,hook:$,ctx:Q});try{let H=Promise.resolve(X(q));await bq(H,m$,`Hook "${$}" in "${G.plugin.name}" timed out after ${m$}ms`);let Y=Date.now()-J;this.emitPluginEvent({type:"pluginHookFinished",name:G.plugin.name,hook:$,durationMs:Y,modified:!1,ctx:Q})}catch(H){let Y=H instanceof Error?H.message:String(H);this.warnings.push(`Hook "${$}" in "${G.plugin.name}" failed: ${Y}`),this.emitPluginEvent({type:"pluginError",name:G.plugin.name,stage:"hook",hook:$,message:Y,recoverable:!0})}}}emitPluginEvent($){this.onEvent?.($);for(let q of this.plugins)if(q.plugin.event&&$.type!=="pluginLoaded");}emitEngineEvent($){this.onEvent?.($);for(let q of this.plugins)if(q.plugin.event)try{q.plugin.event({event:$})}catch{}}getResolvers(){return{...this.resolvers}}getResolver($){return this.resolvers[$]}async callResolver($,q){let Q=this.resolvers[$];if(!Q)return`{{${$}:ERROR}}`;let G=Date.now();try{let X=await Q(...q),J=Date.now()-G;return this.emitPluginEvent({type:"pluginResolverCalled",name:$,resolver:$,durationMs:J}),X}catch(X){let J=X instanceof Error?X.message:String(X);return this.warnings.push(`Resolver "${$}" failed: ${J}`),this.emitPluginEvent({type:"pluginError",name:"resolver",stage:"resolver",message:J,recoverable:!0}),`{{${$}:ERROR}}`}}getCommands(){let $={};for(let[q,{handler:Q}]of Object.entries(this.commands))$[q]=Q;return $}getCommand($){return this.commands[$]?.handler}getMiddleware(){return this.middleware.map(($)=>$.fn)}getTools(){let $={};for(let[q,{definition:Q}]of Object.entries(this.tools))$[q]=Q;return $}getPlugins(){return[...this.plugins]}getWarnings(){return[...this.warnings]}hasPlugins(){return this.plugins.length>0}getPlugin($){return this.plugins.find((q)=>q.plugin.name===$)}getPluginInfo(){return this.plugins.map(($)=>({name:$.plugin.name,source:$.source,permissions:$.permissions,...$.plugin.version!==void 0?{version:$.plugin.version}:{}}))}setSessionVariable($,q){this.session.variables[$]=q}getSessionVariables(){return{...this.session.variables}}}function Qq($){return new qq($)}function L0($){return $}function U0($){let{config:q,cookieStore:Q,onEvent:G}=$,X={};if(q.cookies.enabled&&Q)X.cookieStore=Q;if(X.headerDefaults=q.defaults.headers,X.resolvers=q.resolvers,G)X.onEvent=G;if(q.pluginManager){if(X.pluginManager=q.pluginManager,G)q.pluginManager.setEventSink(G)}let J={timeoutMs:q.defaults.timeoutMs,followRedirects:q.defaults.followRedirects,validateSSL:q.defaults.validateSSL};if(q.defaults.proxy)J.proxy=q.defaults.proxy;return{engineOptions:X,requestDefaults:J}}function vq($){let q=[],Q="code",G=0,X=()=>{while(q.length>0){let J=q[q.length-1];if(J===" "||J==="\t"){q.pop();continue}break}};while(G<$.length){let J=$.charAt(G),H=$[G+1];switch(Q){case"code":if(J==='"')q.push(J),Q="string",G++;else if(J==="/"&&H==="/")X(),Q="line-comment",G+=2;else if(J==="/"&&H==="*")Q="block-comment",G+=2;else q.push(J),G++;break;case"string":if(q.push(J),J==="\\"&&H!==void 0)q.push(H),G+=2;else if(J==='"')Q="code",G++;else G++;break;case"line-comment":if(J===`
|
|
6
|
+
`||J==="\r")q.push(J),Q="code";G++;break;case"block-comment":if(J==="*"&&H==="/")Q="code",G+=2;else{if(J===`
|
|
7
|
+
`||J==="\r")q.push(J);G++}break}}return q.join("")}function Gq($){let q=vq($);try{return JSON.parse(q)}catch(Q){if(Q instanceof SyntaxError)throw SyntaxError(`Invalid JSONC: ${Q.message}`);throw Q}}import{access as A0,readFile as Cq}from"node:fs/promises";import*as f from"node:path";import{pathToFileURL as K0}from"node:url";var O0=[{filename:"treq.jsonc",format:"jsonc"},{filename:"treq.json",format:"json"},{filename:"treq.config.ts",format:"ts"},{filename:"treq.config.js",format:"js"},{filename:"treq.config.mjs",format:"mjs"}];async function Xq($){try{return await A0($),!0}catch{return!1}}async function R0($,q,Q){let G=f.resolve($),X=Q?f.resolve(Q):void 0;while(!0){if(q){let H=f.join(G,q);if(await Xq(H)){let Y=Iq(q);return{path:H,format:Y}}}else for(let{filename:H,format:Y}of O0){let W=f.join(G,H);if(await Xq(W))return{path:W,format:Y}}if(X&&G===X)return;let J=f.dirname(G);if(J===G)return;G=J}}function Iq($){if($.endsWith(".jsonc"))return"jsonc";if($.endsWith(".json"))return"json";if($.endsWith(".ts"))return"ts";if($.endsWith(".mjs"))return"mjs";if($.endsWith(".js"))return"js";return"json"}function D0($){let q=f.basename($);return Iq(q)}async function j0($){let G=(await import(K0($).href)).default;if(!G||typeof G!=="object")throw Error(`Invalid config export from ${$}. Expected default object export.`);return G}async function N0($){let q=await Cq($,"utf-8"),Q=Gq(q);if(!Q||typeof Q!=="object")throw Error(`Invalid JSONC config at ${$}. Expected object.`);return Q}async function F0($){let q=await Cq($,"utf-8"),Q=JSON.parse(q);if(!Q||typeof Q!=="object")throw Error(`Invalid JSON config at ${$}. Expected object.`);return Q}async function b0($,q){switch(q){case"jsonc":return await N0($);case"json":return await F0($);case"ts":case"js":case"mjs":return await j0($);default:throw Error(`Unknown config format: ${q}`)}}async function Hq($){let q="filename"in $&&$.filename?$.filename:void 0,Q,G;if("path"in $){if(Q=f.resolve($.path),G=D0(Q),!await Xq(Q))return{config:{}}}else{let J=await R0($.startDir,q,$.stopDir);if(!J)return{config:{}};Q=J.path,G=J.format}let X=await b0(Q,G);return{path:Q,config:X,format:G}}function Jq($){return $==="ts"||$==="js"||$==="mjs"}function v0($,q){if(!$&&!q)return;if(!$)return q;if(!q)return $;return{...$,...q,headers:{...$.headers??{},...q.headers??{}}}}function l$($,q){let Q={},G={...$.variables??{},...q.variables??{}};if(Object.keys(G).length>0)Q.variables=G;let X={...$.resolvers??{},...q.resolvers??{}};if(Object.keys(X).length>0)Q.resolvers=X;let J=v0($.defaults,q.defaults);if(J)Q.defaults=J;let H={...$.cookies??{},...q.cookies??{}};if(Object.keys(H).length>0)Q.cookies=H;let Y={...$.security??{},...q.security??{}};if(Object.keys(Y).length>0)Q.security=Y;if($.profiles)Q.profiles=$.profiles;return Q}function c$($){let q={};if($.defaults)q=l$(q,$.defaults);if($.file)q=l$(q,$.file);if($.overrides)q=l$(q,$.overrides);return q}function Yq($,q){if(!q)return $;let Q=$.profiles??{},G=Q[q];if(!G){let J=Object.keys(Q),H=J.length>0?` Available profiles: ${J.join(", ")}`:"";throw Error(`Profile "${q}" not found.${H}`)}let X={};if($.variables)X.variables=$.variables;if($.defaults)X.defaults=$.defaults;if($.cookies)X.cookies=$.cookies;if($.resolvers)X.resolvers=$.resolvers;if($.security)X.security=$.security;return l$(X,G)}function C0($){let q=$.profiles??{};return Object.keys(q).sort()}import{existsSync as r0}from"node:fs";import*as j from"node:path";import{spawn as I0}from"node:child_process";var k0=2000,T0=500,P0=1048576,f0=65536;async function h0($,q,Q,G){let X=$.timeoutMs??k0;if($.command.length===0)throw Error(`Resolver "${q}" has empty command array`);let[J,...H]=$.command;if(!J)throw Error(`Resolver "${q}" has empty command`);return new Promise((Y,W)=>{let B=I0(J,H,{cwd:G,stdio:["pipe","pipe","pipe"],env:process.env}),A="",K="",N=0,b=0,K$=!1,n=!1,h=!1,O$=!1,T$=setTimeout(()=>{O$=!0,B.kill("SIGTERM"),setTimeout(()=>{if(!h)B.kill("SIGKILL")},T0)},X);B.stdout?.on("data",(x)=>{let y=P0-N;if(y>0){let Z=x.slice(0,y);if(A+=Z.toString("utf-8"),N+=Z.length,Z.length<x.length)K$=!0}else K$=!0}),B.stderr?.on("data",(x)=>{let y=f0-b;if(y>0){let Z=x.slice(0,y);if(K+=Z.toString("utf-8"),b+=Z.length,Z.length<x.length)n=!0}else n=!0}),B.on("close",(x,y)=>{if(clearTimeout(T$),h=!0,O$){W(Error(`Resolver "${q}" timed out after ${X}ms${K?`: ${K}`:""}`));return}if(x!==0){let s=y?`killed by signal ${y}`:`exit code ${x}`;W(Error(`Resolver "${q}" failed (${s})${K?`: ${K}`:""}`));return}let Z=A.trim();if(!Z){W(Error(`Resolver "${q}" returned no output`));return}let Wq=Z.split(/\r?\n/).map((s)=>s.trim()).find((s)=>s.length>0)??"",u$;try{u$=JSON.parse(Wq)}catch{let s=K$?" (stdout exceeded 1MB limit and was truncated)":"";W(Error(`Resolver "${q}" returned invalid JSON: ${Wq.slice(0,100)}${s}`));return}if(typeof u$.value!=="string"){W(Error(`Resolver "${q}" returned no value (expected { "value": "..." })`));return}Y(u$.value)}),B.on("error",(x)=>{clearTimeout(T$);let y=n?" (stderr exceeded 64KB limit and was truncated)":"";W(Error(`Resolver "${q}" failed to execute: ${x.message}${y}`))});let Zq={resolver:q,args:Q};B.stdin?.write(`${JSON.stringify(Zq)}
|
|
8
|
+
`),B.stdin?.end()})}function kq($,q,Q){let G=Q??"$command";return async(...X)=>{return await h0($,G,X,q)}}function Tq($){if(!$||typeof $!=="object")return!1;let q=$;return q.type==="command"&&Array.isArray(q.command)}import{accessSync as x0,readFileSync as y0,realpathSync as Z0}from"node:fs";import*as fq from"node:os";import*as v from"node:path";var g0=/\{env:([^}]+)\}/g,m0=/\{file:([^}]+)\}/g;function l0($){if($.startsWith("~/")||$==="~")return v.join(fq.homedir(),$.slice(1));return $}function c0($,q){let Q=v.resolve($),G=v.resolve(q),X=v.relative(G,Q);if(X==="")return!0;if(v.isAbsolute(X))return!1;if(X.startsWith(".."))return!1;return!0}function Pq($){try{return Z0($)}catch{return v.resolve($)}}function u0($){try{return x0($),!0}catch{return!1}}function p0($){return $.replace(g0,(q,Q)=>{return process.env[Q]??""})}function n0($,q){return $.replace(m0,(Q,G)=>{let X=l0(G.trim());if(!v.isAbsolute(X))X=v.resolve(q.configDir,X);if(!u0(X))throw Error(`Config substitution failed: {file:${G}} not found at ${X}`);let J=Pq(q.workspaceRoot),H=Pq(X);if(!q.allowExternalFiles){if(!c0(H,J))throw Error(`Config substitution failed: {file:${G}} outside workspace (use security.allowExternalFiles to allow)`)}try{return y0(H,"utf-8").trimEnd()}catch(Y){throw Error(`Config substitution failed: {file:${G}} could not be read: ${Y instanceof Error?Y.message:String(Y)}`)}})}function d0($,q){let Q=p0($);return Q=n0(Q,q),Q}function k$($,q){if($===null||$===void 0)return $;if(typeof $==="string")return d0($,q);if(Array.isArray($))return $.map((Q)=>k$(Q,q));if(typeof $==="object"){let Q={};for(let[G,X]of Object.entries($))Q[G]=k$(X,q);return Q}return $}var hq=30000,xq=!0,yq=!0;function i0($,q){let Q=j.resolve($),G=q?j.resolve(q):void 0,{root:X}=j.parse(Q);while(!0){let J=j.join(Q,".git");if(r0(J))return Q;if(G&&Q===G)return;if(Q===X)return;let H=j.dirname(Q);if(H===Q)return;Q=H}}function o0($,q,Q){if($)return j.dirname($);let G=Q?j.resolve(Q):void 0;return i0(q,G)??G??j.resolve(q)}function a0($){let q=$?.enabled!==!1,Q=$?.jarPath,G;if(!q)G="disabled";else if(Q)G="persistent";else G="memory";let X={enabled:q,mode:G};if(Q)X.jarPath=Q;return X}function s0($){let q={timeoutMs:$?.timeoutMs??hq,followRedirects:$?.followRedirects??xq,validateSSL:$?.validateSSL??yq,headers:$?.headers??{}};if($?.proxy)q.proxy=$.proxy;return q}function t0($,q){if(!$)return{};let Q={};for(let[G,X]of Object.entries($))if(typeof X==="function")Q[G]=X;else if(Tq(X))Q[G]=kq(X,q,G);else throw Error(`Unknown resolver type for "${G}". Expected function or { type: "command", command: [...] }`);return Q}async function e0($){let q=[],Q=[],G={startDir:$.startDir};if($.stopDir)G.stopDir=$.stopDir;let X=await Hq(G),J=$.stopDir?j.resolve($.stopDir):void 0,H=o0(X.path,$.startDir,J);if(X.path&&Jq(X.format))q.push(`${j.basename(X.path)} is deprecated; migrate to treq.jsonc`);let Y={};if(X.config&&Object.keys(X.config).length>0)Q.push("file"),Y=X.config;if($.profile)Y=Yq(Y,$.profile),Q.push(`profile:${$.profile}`);for(let h of $.overrideLayers??[]){if(!h||!h.overrides||Object.keys(h.overrides).length===0)continue;Y=c$({file:Y,overrides:h.overrides}),Q.push(h.name)}if($.overrides&&Object.keys($.overrides).length>0)Y=c$({file:Y,overrides:$.overrides}),Q.push($.overridesLayerName??"overrides");let W=J??H,B=X.path?j.dirname(X.path):H,A=Y.security?.allowExternalFiles??!1;Y=k$(Y,{configDir:B,workspaceRoot:W,allowExternalFiles:A});let K=t0(Y.resolvers,H),N=$1(X.config?.plugins,$.profile?X.config?.profiles?.[$.profile]?.plugins:void 0),b;if(N.length>0){b=Qq({projectRoot:H,plugins:N,security:{allowPluginsOutsideProject:Y.security?.allowPluginsOutsideProject??!1},...Y.security?.pluginPermissions!==void 0?{pluginPermissions:Y.security.pluginPermissions}:{}}),await b.initialize();let h=b.getResolvers();for(let[O$,T$]of Object.entries(h))if(!K[O$])K[O$]=T$;q.push(...b.getWarnings())}let K$={projectRoot:H,variables:Y.variables??{},defaults:s0(Y.defaults),cookies:a0(Y.cookies),resolvers:K,security:{allowExternalFiles:Y.security?.allowExternalFiles??!1,allowPluginsOutsideProject:Y.security?.allowPluginsOutsideProject??!1,...Y.security?.pluginPermissions!==void 0?{pluginPermissions:Y.security.pluginPermissions}:{}},...b!==void 0?{pluginManager:b}:{}},n={projectRoot:H,layersApplied:Q,warnings:q};if(X.path)n.configPath=X.path;if(X.format)n.format=X.format;if($.profile)n.profile=$.profile;return{config:K$,meta:n}}function $1($,q){if(!$&&!q)return[];if(!$)return q??[];if(!q)return $;return o$($,q)}export{vq as stripJsonComments,e0 as resolveProjectConfig,Gq as parseJsonc,c$ as mergeConfig,Hq as loadConfig,C0 as listProfiles,Jq as isLegacyFormat,L0 as defineConfig,U0 as buildEngineOptions,k$ as applySubstitutions,Yq as applyProfile,yq as DEFAULT_VALIDATE_SSL,hq as DEFAULT_TIMEOUT_MS,xq as DEFAULT_FOLLOW_REDIRECTS};
|
|
5
9
|
|
|
6
|
-
//# debugId=
|
|
10
|
+
//# debugId=2013DC71184054E564756E2164756E21
|
|
7
11
|
//# sourceMappingURL=index.js.map
|