@junobuild/functions-tools 0.4.0-next-2026-03-12 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -91
- package/dist/node/index.mjs +36 -36
- package/dist/node/index.mjs.map +4 -4
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -10,97 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
Tools for generating [Juno] serverless functions code.
|
|
12
12
|
|
|
13
|
-
<!-- TSDOC_START -->
|
|
14
|
-
|
|
15
|
-
### :toolbox: Functions
|
|
16
|
-
|
|
17
|
-
- [zodToIdl](#gear-zodtoidl)
|
|
18
|
-
- [zodToRust](#gear-zodtorust)
|
|
19
|
-
- [zodToCandid](#gear-zodtocandid)
|
|
20
|
-
|
|
21
|
-
#### :gear: zodToIdl
|
|
22
|
-
|
|
23
|
-
Converts a Zod schema to a Candid IDL type for use with `IDL.encode` and `IDL.decode`.
|
|
24
|
-
|
|
25
|
-
| Function | Type |
|
|
26
|
-
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
27
|
-
| `zodToIdl` | `({ id, schema, suffix }: { id: string; schema: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; suffix: "Args" or "Result"; }) => IdlResult` |
|
|
28
|
-
|
|
29
|
-
Parameters:
|
|
30
|
-
|
|
31
|
-
- `id`: - The base name used to generate the IDL type name.
|
|
32
|
-
- `schema`: - The Zod schema to convert.
|
|
33
|
-
- `suffix`: - Whether this represents function arguments or a return type.
|
|
34
|
-
|
|
35
|
-
Returns:
|
|
36
|
-
|
|
37
|
-
An object containing the generated IDL type and the base type name.
|
|
38
|
-
|
|
39
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions-tools/src/converters/zod-to-idl.ts#L71)
|
|
40
|
-
|
|
41
|
-
#### :gear: zodToRust
|
|
42
|
-
|
|
43
|
-
Converts a Zod schema to a Rust type definition string.
|
|
44
|
-
|
|
45
|
-
| Function | Type |
|
|
46
|
-
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
47
|
-
| `zodToRust` | `({ id, schema, suffix }: { id: string; schema: ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; suffix: "Args" or "Result"; }) => RustResult` |
|
|
48
|
-
|
|
49
|
-
Parameters:
|
|
50
|
-
|
|
51
|
-
- `id`: - The base name used to generate the Rust struct or type alias name.
|
|
52
|
-
- `schema`: - The Zod schema to convert.
|
|
53
|
-
- `suffix`: - Whether this represents function arguments or a return type.
|
|
54
|
-
|
|
55
|
-
Returns:
|
|
56
|
-
|
|
57
|
-
An object containing the generated Rust code and the base type name.
|
|
58
|
-
|
|
59
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions-tools/src/converters/zod-to-rust.ts#L174)
|
|
60
|
-
|
|
61
|
-
#### :gear: zodToCandid
|
|
62
|
-
|
|
63
|
-
Converts a record of Zod schemas to a Candid type definition string.
|
|
64
|
-
|
|
65
|
-
| Function | Type |
|
|
66
|
-
| ------------- | ---------------------------------------------------------------------------------------------------- |
|
|
67
|
-
| `zodToCandid` | `(inputs: Record<string, ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>>) => string` |
|
|
68
|
-
|
|
69
|
-
Parameters:
|
|
70
|
-
|
|
71
|
-
- `inputs`: - A record mapping type names to Zod schemas.
|
|
72
|
-
|
|
73
|
-
Returns:
|
|
74
|
-
|
|
75
|
-
A Candid type definition string, one `type` declaration per entry.
|
|
76
|
-
|
|
77
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions-tools/src/converters/zod-to-candid.ts#L48)
|
|
78
|
-
|
|
79
|
-
### :tropical_drink: Interfaces
|
|
80
|
-
|
|
81
|
-
- [IdlResult](#gear-idlresult)
|
|
82
|
-
- [RustResult](#gear-rustresult)
|
|
83
|
-
|
|
84
|
-
#### :gear: IdlResult
|
|
85
|
-
|
|
86
|
-
| Property | Type | Description |
|
|
87
|
-
| ---------- | ---------- | ----------- |
|
|
88
|
-
| `baseName` | `string` | |
|
|
89
|
-
| `idl` | `IDL.Type` | |
|
|
90
|
-
|
|
91
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions-tools/src/converters/zod-to-idl.ts#L43)
|
|
92
|
-
|
|
93
|
-
#### :gear: RustResult
|
|
94
|
-
|
|
95
|
-
| Property | Type | Description |
|
|
96
|
-
| ---------- | -------- | ----------- |
|
|
97
|
-
| `baseName` | `string` | |
|
|
98
|
-
| `code` | `string` | |
|
|
99
|
-
|
|
100
|
-
[:link: Source](https://github.com/junobuild/juno-js/tree/main/packages/functions-tools/src/converters/zod-to-rust.ts#L143)
|
|
101
|
-
|
|
102
|
-
<!-- TSDOC_END -->
|
|
103
|
-
|
|
104
13
|
## License
|
|
105
14
|
|
|
106
15
|
MIT © [David Dal Busco](mailto:david.dalbusco@outlook.com)
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
var
|
|
3
|
+
var sr=Object.defineProperty;var or=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var ar=(r,e)=>{for(var t in e)sr(r,t,{get:e[t],enumerable:!0})};import{writeFile as Cr}from"node:fs/promises";import*as cr from"@babel/parser";import{isTSAnyKeyword as ur,isTSArrayType as fr,isTSBigIntKeyword as lr,isTSBooleanKeyword as dr,isTSNeverKeyword as pr,isTSNullKeyword as hr,isTSNumberKeyword as yr,isTSObjectKeyword as mr,isTSStringKeyword as br,isTSSymbolKeyword as xr,isTSTupleType as tt,isTSTypeReference as rt,isTSUndefinedKeyword as gr,isTSUnknownKeyword as wr,isTSVoidKeyword as _r}from"@babel/types";import{isNullish as _e,nonNullish as nt}from"@dfinity/utils";import{readFile as Tr}from"node:fs/promises";var{parse:Sr}=cr,vr={sourceType:"module",plugins:["typescript"]},it=async({inputFile:r})=>{let e=await Tr(r,"utf-8"),t=Sr(e,vr),n=[],i=[],s=[],{default:o}=or("@babel/traverse");return o(t,{TSInterfaceDeclaration(a){if(a.node.id.name==="_SERVICE"){let c=a.node.body.body;for(let u of c)if(u.type==="TSMethodSignature"||u.type==="TSPropertySignature"){let y=Ar(u);nt(y)&&n.push(y)}}else i.push(a.node.id.name)},TSTypeAliasDeclaration(a){s.push(a.node.id.name)}}),{methods:n,imports:[...i,...s]}},se=r=>{if(_e(r))return"unknown";if(rt(r)){let e=r.typeName?.name;if(_e(e))return"unknown";if(nt(r.typeParameters?.params?.length)){let t=r.typeParameters.params.map(se);return`${e}<${t.join(", ")}>`}return e??"unknown"}return br(r)?"string":yr(r)?"number":dr(r)?"boolean":lr(r)?"bigint":xr(r)?"symbol":hr(r)?"null":gr(r)?"undefined":_r(r)?"void":pr(r)?"never":wr(r)?"unknown":ur(r)?"any":mr(r)?"object":tt(r)?`[${r.elementTypes.map(se).join(", ")}]`:fr(r)?`${se(r.elementType)}[]`:"unknown"},Ar=r=>{let{type:e,key:t}=r,i=(()=>{if(t.type==="Identifier")return t.name;if(t.type==="StringLiteral")return t.value})();if(_e(i)||e!=="TSPropertySignature")return;let s=r.typeAnnotation?.typeAnnotation;if(!rt(s)||s.typeName?.name!=="ActorMethod"||_e(s.typeParameters))return;let[a,c]=s.typeParameters.params,u=tt(a)?a.elementTypes.map(se):[se(a)];return{name:i,paramsType:u,returnType:se(c)}};var Er=`// This file was automatically generated by the Juno CLI.
|
|
4
4
|
// Any modifications may be overwritten.
|
|
5
5
|
%IMPORT%
|
|
6
6
|
import {idlFactory} from './satellite.factory.did.js';
|
|
7
7
|
import {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';
|
|
8
8
|
|
|
9
9
|
%METHODS%
|
|
10
|
-
`,
|
|
10
|
+
`,Nr=`export const %METHOD_NAME% = async (%PARAMS%): Promise<%METHOD_RESULT%> => {
|
|
11
11
|
const {%DID_METHOD_NAME%} = await getSatelliteExtendedActor<SatelliteActor>({
|
|
12
12
|
idlFactory
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
return await %DID_METHOD_NAME%(%CALL_PARAMS%);
|
|
16
|
-
}`,
|
|
16
|
+
}`,Ir=`export const %METHOD_NAME% = async (%CALL_PARAMS%) => {
|
|
17
17
|
const {%DID_METHOD_NAME%} = await getSatelliteExtendedActor({
|
|
18
18
|
idlFactory
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
return await %DID_METHOD_NAME%(%CALL_PARAMS%);
|
|
22
|
-
}`,
|
|
22
|
+
}`,Ur=`
|
|
23
23
|
import type {_SERVICE as SatelliteActor%IMPORTS%} from './satellite.did';
|
|
24
|
-
import type { Principal } from '@icp-sdk/core/principal';`,
|
|
24
|
+
import type { Principal } from '@icp-sdk/core/principal';`,st=({methods:r,imports:e,transformerOptions:{coreLib:t,outputLanguage:n}})=>{let i=n==="js"?Ir:Nr,s=r.map(o=>{let a=$r(o),c=i;return Object.entries(a).map(([u,y])=>{c=c.replaceAll(`%${u}%`,y)}),c}).join(`
|
|
25
25
|
|
|
26
|
-
`);return Sr.replace("%CORE_LIB%",t??"core").replace("%METHODS%",s).replace("%IMPORT%",n==="js"?"":Ar.replace("%IMPORTS%",e.length===0?"":`, ${e.join(", ")}`)).trim()},Nr=({name:r,returnType:e,paramsType:t})=>{let i=(c=>c.replace(/_./g,u=>u[1].toUpperCase()))(r),s=t.map((c,u)=>({param:`value${u}`,type:c})),o=`${s.map(({param:c})=>c).join(", ")}`,a=s.map(({param:c,type:u})=>`${c}: ${u}`).join(", ");return{METHOD_NAME:i,DID_METHOD_NAME:r,METHOD_RESULT:e,PARAMS:a,CALL_PARAMS:o}};var bn=async({inputFile:r,outputFile:e,transformerOptions:t})=>{let n=await rt({inputFile:r}),i=nt({...n,transformerOptions:t});await Ir(e,i,"utf-8")};import{ZodSchemaId as it}from"@junobuild/zod";import*as st from"zod";var se=({id:r,zodSchema:e})=>{let t=e.toJSONSchema({unrepresentable:"any",override:s=>{s.zodSchema._zod.def.type==="bigint"&&(s.jsonSchema.type="integer",s.jsonSchema.format="bigint"),s.jsonSchema.id===it.Principal&&(s.jsonSchema.format="principal"),s.jsonSchema.id===it.Uint8Array&&(s.jsonSchema.format="uint8array")}}),n=U({schema:t,rootDefs:t.$defs??{}}),i=e._zod.def.type==="optional"&&!("innerType"in e._zod.def&&e._zod.def.innerType instanceof st.ZodNullable);return{id:r,schema:n,isTopLevelOptional:i}},U=({schema:r,rootDefs:e})=>{if(r.format==="principal")return{kind:"principal"};if(r.format==="uint8array")return{kind:"uint8array"};if("$ref"in r){let t=r.$ref.replace("#/$defs/",""),n=e[t];if(n===void 0)throw new Error(`Unresolved $ref: ${r.$ref}`);return U({schema:n,rootDefs:e})}switch(r.type){case"string":if(r.const!==void 0)return{kind:"variant",tags:[String(r.const)]};if(r.enum!==void 0){if(r.enum.some(t=>typeof t!="string"))throw new Error("Non-string enum values are not supported");return{kind:"variant",tags:r.enum}}return{kind:"text"};case"boolean":return{kind:"bool"};case"number":return{kind:"float64"};case"integer":return r.format==="bigint"?{kind:"nat"}:{kind:"int32"};case"null":throw new Error("null type is not supported");case"array":{if(r.prefixItems!==void 0){if(r.prefixItems.some(t=>typeof t=="boolean"))throw new Error("Boolean schema not supported.");return{kind:"indexedTuple",members:r.prefixItems.map(t=>U({schema:t,rootDefs:e}))}}if(r.items===void 0)throw new Error("Array schema must have items defined");if(Array.isArray(r.items))throw new Error("Tuple-style array items not supported");if(typeof r.items=="boolean")throw new Error("Boolean schema not supported for array items");return{kind:"vec",inner:U({schema:r.items,rootDefs:e})}}case"object":{if(r.properties===void 0&&r.additionalProperties!==void 0){if(typeof r.additionalProperties=="boolean")throw new Error("Boolean additionalProperties not supported");return{kind:"vec",inner:{kind:"tuple",members:[{kind:"text"},U({schema:r.additionalProperties,rootDefs:e})]}}}if(r.properties===void 0)return{kind:"record",fields:[]};if(Object.keys(r.properties).length===0)return{kind:"record",fields:[]};let t=new Set(r.required??[]),n=Object.entries(r.properties);if(n.some(([i,s])=>typeof s=="boolean"))throw new Error("Boolean schema not supported.");return{kind:"record",fields:n.map(([i,s])=>{let o=U({schema:s,rootDefs:e});return{name:i,type:t.has(i)?o:{kind:"opt",inner:o}}})}}}if(r.oneOf!==void 0){let t=r.oneOf.filter(({type:n})=>n!=="null");return t.length===1?{kind:"opt",inner:U({schema:t[0],rootDefs:e})}:{kind:"variantRecords",members:t.map(n=>U({schema:n,rootDefs:e}))}}if(r.anyOf!==void 0){let t=r.anyOf.filter(s=>typeof s!="boolean");if(t.filter(s=>Object.keys(s).length===0).length>0)throw new Error("Unrepresentable type in union");if(t.every(s=>s.const!==void 0))return{kind:"variant",tags:t.map(s=>String(s.const))};let i=t.filter(s=>s.type!=="null");return i.length===1?{kind:"opt",inner:U({schema:i[0],rootDefs:e})}:{kind:"variantRecords",members:i.map(s=>U({schema:s,rootDefs:e}))}}if(r.allOf!==void 0){if(r.allOf.some(n=>typeof n=="boolean"))throw new Error("Boolean schema not supported in allOf");if(r.allOf.some(n=>typeof n!="boolean"&&(n.type!=="object"||n.properties===void 0)))throw new Error("allOf only supported for object types");return{kind:"record",fields:r.allOf.flatMap(n=>{let i=new Set(n.required??[]);return Object.entries(n.properties??{}).map(([s,o])=>{let a=U({schema:o,rootDefs:e});return{name:s,type:i.has(s)?a:{kind:"opt",inner:a}}})})}}throw Object.keys(r).length===0?new Error("Unsupported type: unrepresentable schema (z.symbol, z.undefined, z.void, z.map, z.set, z.nan, z.custom are not supported)"):new Error(`Unsupported JSON Schema: ${JSON.stringify(r)}`)};var q=r=>{switch(r.kind){case"text":return"text";case"bool":return"bool";case"float64":return"float64";case"int32":return"int32";case"nat":return"nat";case"opt":return`opt ${q(r.inner)}`;case"vec":return`vec ${q(r.inner)}`;case"record":return r.fields.length===0?"record {}":`record { ${r.fields.map(e=>`${e.name} : ${q(e.type)}`).join("; ")} }`;case"tuple":return`record { ${r.members.map(q).join("; ")} }`;case"indexedTuple":return`record { ${r.members.map((e,t)=>`${t} : ${q(e)}`).join("; ")} }`;case"variant":return`variant { ${r.tags.join("; ")} }`;case"variantRecords":return`variant { ${r.members.map(q).join("; ")} }`;case"principal":return"principal";case"uint8array":return"blob"}},_n=r=>Object.entries(r).map(([e,t])=>se({id:e,zodSchema:t})).map(({schema:e,id:t,isTopLevelOptional:n})=>`type ${t} = ${n?`opt ${q(e)}`:q(e)};`).join(`
|
|
27
|
-
`);var S={};ir(S,{Bool:()=>Nt,BoolClass:()=>Ce,ConstructType:()=>R,Empty:()=>Et,EmptyClass:()=>be,FixedIntClass:()=>H,FixedNatClass:()=>C,Float32:()=>Rt,Float64:()=>Ot,FloatClass:()=>ge,Func:()=>Kt,FuncClass:()=>ee,Int:()=>$t,Int16:()=>kt,Int32:()=>Vt,Int64:()=>Lt,Int8:()=>Bt,IntClass:()=>me,Nat:()=>Ct,Nat16:()=>jt,Nat32:()=>Pt,Nat64:()=>Mt,Nat8:()=>Ft,NatClass:()=>xe,Null:()=>It,NullClass:()=>Z,Opt:()=>Gt,OptClass:()=>Q,PrimitiveType:()=>N,Principal:()=>Ht,PrincipalClass:()=>Be,Rec:()=>Wt,RecClass:()=>I,Record:()=>Jt,RecordClass:()=>X,Reserved:()=>At,ReservedClass:()=>O,Service:()=>Yt,ServiceClass:()=>fe,Text:()=>Ut,TextClass:()=>Re,Tuple:()=>Dt,TupleClass:()=>Oe,Type:()=>ae,Unknown:()=>Mr,UnknownClass:()=>$e,Variant:()=>qt,VariantClass:()=>ue,Vec:()=>zt,VecClass:()=>ce,Visitor:()=>Je,decode:()=>Pr,encode:()=>jr,resetSubtypeCache:()=>qe,subtype:()=>Ke});var _e="abcdefghijklmnopqrstuvwxyz234567",oe=Object.create(null);for(let r=0;r<_e.length;r++)oe[_e[r]]=r;oe[0]=oe.o;oe[1]=oe.i;function ot(r){let e=0,t=0,n="";function i(s){return e<0?t|=s>>-e:t=s<<e&248,e>3?(e-=8,1):(e<4&&(n+=_e[t>>3],e+=5),0)}for(let s=0;s<r.length;)s+=i(r[s]);return n+(e<0?_e[t>>3]:"")}function at(r){let e=0,t=0,n=new Uint8Array(r.length*4/3|0),i=0;function s(o){let a=oe[o.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(o)}`);a<<=3,t|=a>>>e,e+=5,e>=8&&(n[i++]=t,e-=8,e>0?t=a<<5-e&255:t=0)}for(let o of r)s(o);return n.slice(0,i)}var Ur=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function ct(r){let e=-1;for(let t=0;t<r.length;t++){let i=(r[t]^e)&255;e=Ur[i]^e>>>8}return(e^-1)>>>0}function $r(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function pe(r,...e){if(!$r(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Le(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function ft(r,e){pe(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function he(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function Se(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function $(r,e){return r<<32-e|r>>>e}var lt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Cr=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function dt(r){if(pe(r),lt)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=Cr[r[t]];return e}var V={_0:48,_9:57,A:65,F:70,a:97,f:102};function ut(r){if(r>=V._0&&r<=V._9)return r-V._0;if(r>=V.A&&r<=V.F)return r-(V.A-10);if(r>=V.a&&r<=V.f)return r-(V.a-10)}function pt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(lt)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,s=0;i<t;i++,s+=2){let o=ut(r.charCodeAt(s)),a=ut(r.charCodeAt(s+1));if(o===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function Rr(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function Fe(r){return typeof r=="string"&&(r=Rr(r)),pe(r),r}var Te=class{};function ht(r){let e=n=>r().update(Fe(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Or(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),s=BigInt(4294967295),o=Number(t>>i&s),a=Number(t&s),c=n?4:0,u=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+u,a,n)}function yt(r,e,t){return r&e^~r&t}function bt(r,e,t){return r&e^r&t^e&t}var ve=class extends Te{constructor(e,t,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Se(this.buffer)}update(e){Le(this),e=Fe(e),pe(e);let{view:t,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=Se(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Le(this),ft(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;t[o++]=128,he(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let p=o;p<i;p++)t[p]=0;Or(n,i-8,BigInt(this.length*8),s),this.process(n,0);let a=Se(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,y=this.get();if(u>y.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<u;p++)a.setUint32(4*p,y[p],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},L=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),F=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var Br=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),W=new Uint32Array(64),je=class extends ve{constructor(e=32){super(64,e,8,!1),this.A=L[0]|0,this.B=L[1]|0,this.C=L[2]|0,this.D=L[3]|0,this.E=L[4]|0,this.F=L[5]|0,this.G=L[6]|0,this.H=L[7]|0}get(){let{A:e,B:t,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,t,n,i,s,o,a,c]}set(e,t,n,i,s,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)W[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let f=W[p-15],d=W[p-2],m=$(f,7)^$(f,18)^f>>>3,_=$(d,17)^$(d,19)^d>>>10;W[p]=_+W[p-7]+m+W[p-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:y}=this;for(let p=0;p<64;p++){let f=$(a,6)^$(a,11)^$(a,25),d=y+f+yt(a,c,u)+Br[p]+W[p]|0,_=($(n,2)^$(n,13)^$(n,22))+bt(n,i,s)|0;y=u,u=c,c=a,a=o+d|0,o=s,s=i,i=n,n=d+_|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,y=y+this.H|0,this.set(n,i,s,o,a,c,u,y)}roundClean(){he(W)}destroy(){this.set(0,0,0,0,0,0,0,0),he(this.buffer)}},Pe=class extends je{constructor(){super(28),this.A=F[0]|0,this.B=F[1]|0,this.C=F[2]|0,this.D=F[3]|0,this.E=F[4]|0,this.F=F[5]|0,this.G=F[6]|0,this.H=F[7]|0}};var mt=ht(()=>new Pe);var Ee="__principal__",kr=2,xt=4,Vr="aaaaa-aa",Ae=class r{static anonymous(){return new this(new Uint8Array([xt]))}static managementCanister(){return this.fromText(Vr)}static selfAuthenticating(e){let t=mt(e);return new this(new Uint8Array([...t,kr]))}static from(e){if(typeof e=="string")return r.fromText(e);if(Object.getPrototypeOf(e)===Uint8Array.prototype)return new r(e);if(r.isPrincipal(e))return new r(e._arr);throw new Error(`Impossible to convert ${JSON.stringify(e)} to Principal.`)}static fromHex(e){return new this(pt(e))}static fromText(e){let t=e;if(e.includes(Ee)){let o=JSON.parse(e);Ee in o&&(t=o[Ee])}let n=t.toLowerCase().replace(/-/g,""),i=at(n);i=i.slice(4,i.length);let s=new this(i);if(s.toText()!==t)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${t}" may not be a valid Principal ID).`);return s}static fromUint8Array(e){return new this(e)}static isPrincipal(e){return e instanceof r||typeof e=="object"&&e!==null&&"_isPrincipal"in e&&e._isPrincipal===!0&&"_arr"in e&&e._arr instanceof Uint8Array}constructor(e){this._arr=e,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===xt}toUint8Array(){return this._arr}toHex(){return dt(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,ct(this._arr));let n=new Uint8Array(e),i=new Uint8Array([...n,...this._arr]),o=ot(i).match(/.{1,5}/g);if(!o)throw new Error;return o.join("-")}toString(){return this.toText()}toJSON(){return{[Ee]:this.toText()}}compareTo(e){for(let t=0;t<Math.min(this._arr.length,e._arr.length);t++){if(this._arr[t]<e._arr[t])return"lt";if(this._arr[t]>e._arr[t])return"gt"}return this._arr.length<e._arr.length?"lt":this._arr.length>e._arr.length?"gt":"eq"}ltEq(e){let t=this.compareTo(e);return t=="lt"||t=="eq"}gtEq(e){let t=this.compareTo(e);return t=="gt"||t=="eq"}};function h(...r){let e=new Uint8Array(r.reduce((n,i)=>n+i.byteLength,0)),t=0;for(let n of r)e.set(n,t),t+=n.byteLength;return e}var j=class{save(){return this._view}restore(e){if(!(e instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=e}constructor(e,t=e?.byteLength||0){if(e&&!(e instanceof Uint8Array))try{e=gt(e)}catch{throw new Error("Buffer must be a Uint8Array")}if(t<0||!Number.isInteger(t))throw new Error("Length must be a non-negative integer");if(e&&t>e.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=e||new Uint8Array(0),this._view=new Uint8Array(this._buffer.buffer,0,t)}get buffer(){return this._view.slice()}get byteLength(){return this._view.byteLength}read(e){let t=this._view.subarray(0,e);return this._view=this._view.subarray(e),t.slice()}readUint8(){if(this._view.byteLength===0)return;let e=this._view[0];return this._view=this._view.subarray(1),e}write(e){if(!(e instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");let t=this._view.byteLength;this._view.byteOffset+this._view.byteLength+e.byteLength>=this._buffer.byteLength?this.alloc(e.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+e.byteLength),this._view.set(e,t)}get end(){return this._view.byteLength===0}alloc(e){if(e<=0||!Number.isInteger(e))throw new Error("Amount must be a positive integer");let t=new Uint8Array((this._buffer.byteLength+e)*1.2|0),n=new Uint8Array(t.buffer,0,this._view.byteLength+e);n.set(this._view),this._buffer=t,this._view=n}};function gt(r){if(!r)throw new Error("Input cannot be null or undefined");return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):Array.isArray(r)?new Uint8Array(r):"buffer"in r?gt(r.buffer):new Uint8Array(r)}function wt(r){if(!(r instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Lr(r){let t=new TextEncoder().encode(r),n=0;for(let i of t)n=(n*223+i)%2**32;return n}function E(r){if(/^_\d+_$/.test(r)||/^_0x[0-9a-fA-F]+_$/.test(r)){let e=+r.slice(1,-1);if(Number.isSafeInteger(e)&&e>=0&&e<2**32)return e}return Lr(r)}function Me(r){let e=BigInt(r);if(r<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function Ne(r){let e=BigInt(r);if(r<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<e}function _t(){throw new Error("unexpected end of buffer")}function Y(r,e){return r.byteLength<e&&_t(),r.read(e)}function K(r){let e=r.readUint8();return e===void 0&&_t(),e}function g(r){if(typeof r=="number"&&(r=BigInt(r)),r<BigInt(0))throw new Error("Cannot leb encode negative values.");let e=(r===BigInt(0)?0:Me(r))+1,t=new j(new Uint8Array(e),0);for(;;){let n=Number(r&BigInt(127));if(r/=BigInt(128),r===BigInt(0)){t.write(new Uint8Array([n]));break}else t.write(new Uint8Array([n|128]))}return t.buffer}function T(r){let e=BigInt(1),t=BigInt(0),n;do n=K(r),t+=BigInt(n&127).valueOf()*e,e*=BigInt(128);while(n>=128);return t}function w(r){typeof r=="number"&&(r=BigInt(r));let e=r<BigInt(0);e&&(r=-r-BigInt(1));let t=(r===BigInt(0)?0:Me(r))+1,n=new j(new Uint8Array(t),0);for(;;){let s=i(r);if(r/=BigInt(128),e&&r===BigInt(0)&&(s&64)!==0||!e&&r===BigInt(0)&&(s&64)===0){n.write(new Uint8Array([s]));break}else n.write(new Uint8Array([s|128]))}function i(s){let o=s%BigInt(128);return Number(e?BigInt(128)-o-BigInt(1):o)}return n.buffer}function P(r){let e=new Uint8Array(r.buffer),t=0;for(;t<e.byteLength;t++)if(e[t]<128){if((e[t]&64)===0)return T(r);break}let n=new Uint8Array(Y(r,t+1)),i=BigInt(0);for(let s=n.byteLength-1;s>=0;s--)i=i*BigInt(128)+BigInt(128-(n[s]&127)-1);return-i-BigInt(1)}function Tt(r,e){if(BigInt(r)<BigInt(0))throw new Error("Cannot write negative values.");return He(r,e)}function He(r,e){r=BigInt(r);let t=new j(new Uint8Array(Math.min(1,e)),0),n=0,i=BigInt(256),s=BigInt(0),o=Number(r%i);for(t.write(new Uint8Array([o]));++n<e;)r<0&&s===BigInt(0)&&o!==0&&(s=BigInt(1)),o=Number((r/i-s)%BigInt(256)),t.write(new Uint8Array([o])),i*=BigInt(256);return t.buffer}function De(r,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let t=BigInt(K(r)),n=BigInt(1),i=0;for(;++i<e;){n*=BigInt(256);let s=BigInt(K(r));t=t+n*s}return t}function St(r,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let t=De(r,e),n=BigInt(2)**(BigInt(8)*BigInt(e-1)+BigInt(7));return t>=n&&(t-=n*BigInt(2)),t}var b;(function(r){r[r.Null=-1]="Null",r[r.Bool=-2]="Bool",r[r.Nat=-3]="Nat",r[r.Int=-4]="Int",r[r.Float32=-13]="Float32",r[r.Float64=-14]="Float64",r[r.Text=-15]="Text",r[r.Reserved=-16]="Reserved",r[r.Empty=-17]="Empty",r[r.Opt=-18]="Opt",r[r.Vector=-19]="Vector",r[r.Record=-20]="Record",r[r.Variant=-21]="Variant",r[r.Func=-22]="Func",r[r.Service=-23]="Service",r[r.Principal=-24]="Principal"})(b||(b={}));var Ie="DIDL",Fr=new TextEncoder().encode(Ie),vt=400;function ye(r,e,t){return r.map((n,i)=>t(n,e[i]))}var Ge=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(e){return this._idx.has(e.name)}add(e,t){let n=this._typs.length;this._idx.set(e.name,n),this._idxRefCount.set(n,1),this._typs.push(t)}merge(e,t){let n=this._idx.get(e.name),i=this._idx.get(t);if(n===void 0)throw new Error("Missing type index for "+e);if(i===void 0)throw new Error("Missing type index for "+t);this._typs[n]=this._typs[i];let s=this._getIdxRefCount(n),o=this._getIdxRefCount(i);this._idxRefCount.set(n,s+o),this._idx.set(t,n),this._idxRefCount.set(i,0),this._compactFromEnd()}_getIdxRefCount(e){return this._idxRefCount.get(e)||0}_compactFromEnd(){for(;this._typs.length>0;){let e=this._typs.length-1;if(this._getIdxRefCount(e)>0)break;this._typs.pop(),this._idxRefCount.delete(e)}}encode(){let e=g(this._typs.length),t=h(...this._typs);return h(e,t)}indexOf(e){if(!this._idx.has(e))throw new Error("Missing type index for "+e);return w(this._idx.get(e)||0)}},Je=class{visitType(e,t){throw new Error("Not implemented")}visitPrimitive(e,t){return this.visitType(e,t)}visitEmpty(e,t){return this.visitPrimitive(e,t)}visitBool(e,t){return this.visitPrimitive(e,t)}visitNull(e,t){return this.visitPrimitive(e,t)}visitReserved(e,t){return this.visitPrimitive(e,t)}visitText(e,t){return this.visitPrimitive(e,t)}visitNumber(e,t){return this.visitPrimitive(e,t)}visitInt(e,t){return this.visitNumber(e,t)}visitNat(e,t){return this.visitNumber(e,t)}visitFloat(e,t){return this.visitPrimitive(e,t)}visitFixedInt(e,t){return this.visitNumber(e,t)}visitFixedNat(e,t){return this.visitNumber(e,t)}visitPrincipal(e,t){return this.visitPrimitive(e,t)}visitConstruct(e,t){return this.visitType(e,t)}visitVec(e,t,n){return this.visitConstruct(e,n)}visitOpt(e,t,n){return this.visitConstruct(e,n)}visitRecord(e,t,n){return this.visitConstruct(e,n)}visitTuple(e,t,n){let i=t.map((s,o)=>[`_${o}_`,s]);return this.visitRecord(e,i,n)}visitVariant(e,t,n){return this.visitConstruct(e,n)}visitRec(e,t,n){return this.visitConstruct(t,n)}visitFunc(e,t){return this.visitConstruct(e,t)}visitService(e,t){return this.visitConstruct(e,t)}},l;(function(r){r.EmptyClass="__IDL_EmptyClass__",r.UnknownClass="__IDL_UnknownClass__",r.BoolClass="__IDL_BoolClass__",r.NullClass="__IDL_NullClass__",r.ReservedClass="__IDL_ReservedClass__",r.TextClass="__IDL_TextClass__",r.IntClass="__IDL_IntClass__",r.NatClass="__IDL_NatClass__",r.FloatClass="__IDL_FloatClass__",r.FixedIntClass="__IDL_FixedIntClass__",r.FixedNatClass="__IDL_FixedNatClass__",r.VecClass="__IDL_VecClass__",r.OptClass="__IDL_OptClass__",r.RecordClass="__IDL_RecordClass__",r.TupleClass="__IDL_TupleClass__",r.VariantClass="__IDL_VariantClass__",r.RecClass="__IDL_RecClass__",r.PrincipalClass="__IDL_PrincipalClass__",r.FuncClass="__IDL_FuncClass__",r.ServiceClass="__IDL_ServiceClass__"})(l||(l={}));var ae=class{display(){return this.name}valueToString(e){return x(e)}buildTypeTable(e){e.has(this)||this._buildTypeTableImpl(e)}},N=class extends ae{checkType(e){if(this.name!==e.name)throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);return e}_buildTypeTableImpl(e){}},R=class extends ae{checkType(e){if(e instanceof I){let t=e.getType();if(typeof t>"u")throw new Error("type mismatch with uninitialized type");return t}throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`)}encodeType(e){return e.indexOf(this.name)}},be=class extends N{get typeName(){return l.EmptyClass}static[Symbol.hasInstance](e){return e.typeName===l.EmptyClass}accept(e,t){return e.visitEmpty(this,t)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return w(b.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}},$e=class extends ae{get typeName(){return l.UnknownClass}static[Symbol.hasInstance](e){return e.typeName===l.UnknownClass}checkType(e){throw new Error("Method not implemented for unknown.")}accept(e,t){throw e.visitType(this,t)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(e,t){let n=t.decodeValue(e,t);Object(n)!==n&&(n=Object(n));let i;return t instanceof I?i=()=>t.getType():i=()=>t,Object.defineProperty(n,"type",{value:i,writable:!0,enumerable:!1,configurable:!0}),n}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}},Ce=class extends N{get typeName(){return l.BoolClass}static[Symbol.hasInstance](e){return e.typeName===l.BoolClass}accept(e,t){return e.visitBool(this,t)}covariant(e){if(typeof e=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return new Uint8Array([e?1:0])}encodeType(){return w(b.Bool)}decodeValue(e,t){switch(this.checkType(t),K(e)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}},Z=class extends N{get typeName(){return l.NullClass}static[Symbol.hasInstance](e){return e.typeName===l.NullClass}accept(e,t){return e.visitNull(this,t)}covariant(e){if(e===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return w(b.Null)}decodeValue(e,t){return this.checkType(t),null}get name(){return"null"}},O=class extends N{get typeName(){return l.ReservedClass}static[Symbol.hasInstance](e){return e.typeName===l.ReservedClass}accept(e,t){return e.visitReserved(this,t)}covariant(e){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return w(b.Reserved)}decodeValue(e,t){return t.name!==this.name&&t.decodeValue(e,t),null}get name(){return"reserved"}},Re=class extends N{get typeName(){return l.TextClass}static[Symbol.hasInstance](e){return e.typeName===l.TextClass}accept(e,t){return e.visitText(this,t)}covariant(e){if(typeof e=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=new TextEncoder().encode(e),n=g(t.byteLength);return h(n,t)}encodeType(){return w(b.Text)}decodeValue(e,t){this.checkType(t);let n=T(e),i=Y(e,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(i)}get name(){return"text"}valueToString(e){return'"'+e+'"'}},me=class extends N{get typeName(){return l.IntClass}static[Symbol.hasInstance](e){return e.typeName===l.IntClass}accept(e,t){return e.visitInt(this,t)}covariant(e){if(typeof e=="bigint"||Number.isInteger(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return w(e)}encodeType(){return w(b.Int)}decodeValue(e,t){return this.checkType(t),P(e)}get name(){return"int"}valueToString(e){return e.toString()}},xe=class extends N{get typeName(){return l.NatClass}static[Symbol.hasInstance](e){return e.typeName===l.NatClass}accept(e,t){return e.visitNat(this,t)}covariant(e){if(typeof e=="bigint"&&e>=BigInt(0)||Number.isInteger(e)&&e>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return g(e)}encodeType(){return w(b.Nat)}decodeValue(e,t){return this.checkType(t),T(e)}get name(){return"nat"}valueToString(e){return e.toString()}},ge=class extends N{get typeName(){return l.FloatClass}static[Symbol.hasInstance](e){return e.typeName===l.FloatClass}constructor(e){if(super(),this._bits=e,e!==32&&e!==64)throw new Error("not a valid float type")}accept(e,t){return e.visitFloat(this,t)}covariant(e){if(typeof e=="number"||e instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=new ArrayBuffer(this._bits/8),n=new DataView(t);return this._bits===32?n.setFloat32(0,e,!0):n.setFloat64(0,e,!0),new Uint8Array(t)}encodeType(){let e=this._bits===32?b.Float32:b.Float64;return w(e)}decodeValue(e,t){this.checkType(t);let n=Y(e,this._bits/8),i=wt(n);return this._bits===32?i.getFloat32(0,!0):i.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(e){return e.toString()}},H=class extends N{get typeName(){return l.FixedIntClass}static[Symbol.hasInstance](e){return e.typeName===l.FixedIntClass}constructor(e){super(),this._bits=e}accept(e,t){return e.visitFixedInt(this,t)}covariant(e){let t=Ne(this._bits-1)*BigInt(-1),n=Ne(this._bits-1)-BigInt(1),i=!1;if(typeof e=="bigint")i=e>=t&&e<=n;else if(Number.isInteger(e)){let s=BigInt(e);i=s>=t&&s<=n}else i=!1;if(i)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return He(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return w(-9-e)}decodeValue(e,t){this.checkType(t);let n=St(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(e){return e.toString()}},C=class extends N{get typeName(){return l.FixedNatClass}static[Symbol.hasInstance](e){return e.typeName===l.FixedNatClass}constructor(e){super(),this._bits=e}accept(e,t){return e.visitFixedNat(this,t)}covariant(e){let t=Ne(this._bits),n=!1;if(typeof e=="bigint"&&e>=BigInt(0)?n=e<t:Number.isInteger(e)&&e>=0?n=BigInt(e)<t:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return Tt(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return w(-5-e)}decodeValue(e,t){this.checkType(t);let n=De(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(e){return e.toString()}},ce=class r extends R{get typeName(){return l.VecClass}static[Symbol.hasInstance](e){return e.typeName===l.VecClass}constructor(e){super(),this._type=e,this._blobOptimization=!1,e instanceof C&&e._bits===8&&(this._blobOptimization=!0)}accept(e,t){return e.visitVec(this,this._type,t)}covariant(e){let t=this._type instanceof C?this._type._bits:this._type instanceof H?this._type._bits:0;if(ArrayBuffer.isView(e)&&t==e.BYTES_PER_ELEMENT*8||Array.isArray(e)&&e.every((n,i)=>{try{return this._type.covariant(n)}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
26
|
+
`);return Er.replace("%CORE_LIB%",t??"core").replace("%METHODS%",s).replace("%IMPORT%",n==="js"?"":Ur.replace("%IMPORTS%",e.length===0?"":`, ${e.join(", ")}`)).trim()},$r=({name:r,returnType:e,paramsType:t})=>{let i=(c=>c.replace(/_./g,u=>u[1].toUpperCase()))(r),s=t.map((c,u)=>({param:`value${u}`,type:c})),o=`${s.map(({param:c})=>c).join(", ")}`,a=s.map(({param:c,type:u})=>`${c}: ${u}`).join(", ");return{METHOD_NAME:i,DID_METHOD_NAME:r,METHOD_RESULT:e,PARAMS:a,CALL_PARAMS:o}};var wn=async({inputFile:r,outputFile:e,transformerOptions:t})=>{let n=await it({inputFile:r}),i=st({...n,transformerOptions:t});await Cr(e,i,"utf-8")};import*as gt from"zod";var Te="abcdefghijklmnopqrstuvwxyz234567",oe=Object.create(null);for(let r=0;r<Te.length;r++)oe[Te[r]]=r;oe[0]=oe.o;oe[1]=oe.i;function ot(r){let e=0,t=0,n="";function i(s){return e<0?t|=s>>-e:t=s<<e&248,e>3?(e-=8,1):(e<4&&(n+=Te[t>>3],e+=5),0)}for(let s=0;s<r.length;)s+=i(r[s]);return n+(e<0?Te[t>>3]:"")}function at(r){let e=0,t=0,n=new Uint8Array(r.length*4/3|0),i=0;function s(o){let a=oe[o.toLowerCase()];if(a===void 0)throw new Error(`Invalid character: ${JSON.stringify(o)}`);a<<=3,t|=a>>>e,e+=5,e>=8&&(n[i++]=t,e-=8,e>0?t=a<<5-e&255:t=0)}for(let o of r)s(o);return n.slice(0,i)}var Rr=new Uint32Array([0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117]);function ct(r){let e=-1;for(let t=0;t<r.length;t++){let i=(r[t]^e)&255;e=Rr[i]^e>>>8}return(e^-1)>>>0}function Or(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function he(r,...e){if(!Or(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error("Uint8Array expected of length "+e+", got length="+r.length)}function Pe(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function ft(r,e){he(r);let t=e.outputLen;if(r.length<t)throw new Error("digestInto() expects output buffer of length at least "+t)}function ye(...r){for(let e=0;e<r.length;e++)r[e].fill(0)}function ve(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function U(r,e){return r<<32-e|r>>>e}var lt=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Br=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function dt(r){if(he(r),lt)return r.toHex();let e="";for(let t=0;t<r.length;t++)e+=Br[r[t]];return e}var V={_0:48,_9:57,A:65,F:70,a:97,f:102};function ut(r){if(r>=V._0&&r<=V._9)return r-V._0;if(r>=V.A&&r<=V.F)return r-(V.A-10);if(r>=V.a&&r<=V.f)return r-(V.a-10)}function pt(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(lt)return Uint8Array.fromHex(r);let e=r.length,t=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,s=0;i<t;i++,s+=2){let o=ut(r.charCodeAt(s)),a=ut(r.charCodeAt(s+1));if(o===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function kr(r){if(typeof r!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(r))}function je(r){return typeof r=="string"&&(r=kr(r)),he(r),r}var Se=class{};function ht(r){let e=n=>r().update(je(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Vr(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),s=BigInt(4294967295),o=Number(t>>i&s),a=Number(t&s),c=n?4:0,u=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+u,a,n)}function yt(r,e,t){return r&e^~r&t}function mt(r,e,t){return r&e^r&t^e&t}var Ae=class extends Se{constructor(e,t,n,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=ve(this.buffer)}update(e){Pe(this),e=je(e),he(e);let{view:t,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=ve(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Pe(this),ft(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;t[o++]=128,ye(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let p=o;p<i;p++)t[p]=0;Vr(n,i-8,BigInt(this.length*8),s),this.process(n,0);let a=ve(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let u=c/4,y=this.get();if(u>y.length)throw new Error("_sha2: outputLen bigger than state");for(let p=0;p<u;p++)a.setUint32(4*p,y[p],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},L=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),F=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]);var Lr=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),q=new Uint32Array(64),Me=class extends Ae{constructor(e=32){super(64,e,8,!1),this.A=L[0]|0,this.B=L[1]|0,this.C=L[2]|0,this.D=L[3]|0,this.E=L[4]|0,this.F=L[5]|0,this.G=L[6]|0,this.H=L[7]|0}get(){let{A:e,B:t,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,t,n,i,s,o,a,c]}set(e,t,n,i,s,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let p=0;p<16;p++,t+=4)q[p]=e.getUint32(t,!1);for(let p=16;p<64;p++){let f=q[p-15],d=q[p-2],b=U(f,7)^U(f,18)^f>>>3,_=U(d,17)^U(d,19)^d>>>10;q[p]=_+q[p-7]+b+q[p-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:y}=this;for(let p=0;p<64;p++){let f=U(a,6)^U(a,11)^U(a,25),d=y+f+yt(a,c,u)+Lr[p]+q[p]|0,_=(U(n,2)^U(n,13)^U(n,22))+mt(n,i,s)|0;y=u,u=c,c=a,a=o+d|0,o=s,s=i,i=n,n=d+_|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,y=y+this.H|0,this.set(n,i,s,o,a,c,u,y)}roundClean(){ye(q)}destroy(){this.set(0,0,0,0,0,0,0,0),ye(this.buffer)}},He=class extends Me{constructor(){super(28),this.A=F[0]|0,this.B=F[1]|0,this.C=F[2]|0,this.D=F[3]|0,this.E=F[4]|0,this.F=F[5]|0,this.G=F[6]|0,this.H=F[7]|0}};var bt=ht(()=>new He);var Ee="__principal__",Fr=2,xt=4,Pr="aaaaa-aa",W=class r{static anonymous(){return new this(new Uint8Array([xt]))}static managementCanister(){return this.fromText(Pr)}static selfAuthenticating(e){let t=bt(e);return new this(new Uint8Array([...t,Fr]))}static from(e){if(typeof e=="string")return r.fromText(e);if(Object.getPrototypeOf(e)===Uint8Array.prototype)return new r(e);if(r.isPrincipal(e))return new r(e._arr);throw new Error(`Impossible to convert ${JSON.stringify(e)} to Principal.`)}static fromHex(e){return new this(pt(e))}static fromText(e){let t=e;if(e.includes(Ee)){let o=JSON.parse(e);Ee in o&&(t=o[Ee])}let n=t.toLowerCase().replace(/-/g,""),i=at(n);i=i.slice(4,i.length);let s=new this(i);if(s.toText()!==t)throw new Error(`Principal "${s.toText()}" does not have a valid checksum (original value "${t}" may not be a valid Principal ID).`);return s}static fromUint8Array(e){return new this(e)}static isPrincipal(e){return e instanceof r||typeof e=="object"&&e!==null&&"_isPrincipal"in e&&e._isPrincipal===!0&&"_arr"in e&&e._arr instanceof Uint8Array}constructor(e){this._arr=e,this._isPrincipal=!0}isAnonymous(){return this._arr.byteLength===1&&this._arr[0]===xt}toUint8Array(){return this._arr}toHex(){return dt(this._arr).toUpperCase()}toText(){let e=new ArrayBuffer(4);new DataView(e).setUint32(0,ct(this._arr));let n=new Uint8Array(e),i=new Uint8Array([...n,...this._arr]),o=ot(i).match(/.{1,5}/g);if(!o)throw new Error;return o.join("-")}toString(){return this.toText()}toJSON(){return{[Ee]:this.toText()}}compareTo(e){for(let t=0;t<Math.min(this._arr.length,e._arr.length);t++){if(this._arr[t]<e._arr[t])return"lt";if(this._arr[t]>e._arr[t])return"gt"}return this._arr.length<e._arr.length?"lt":this._arr.length>e._arr.length?"gt":"eq"}ltEq(e){let t=this.compareTo(e);return t=="lt"||t=="eq"}gtEq(e){let t=this.compareTo(e);return t=="gt"||t=="eq"}};import*as Ie from"zod";import*as wt from"zod";var Ne=(r=>(r.PrincipalText="PrincipalText",r.Principal="Principal",r.Uint8Array="Uint8Array",r.Url="Url",r))(Ne||{}),Ln=gt.instanceof(Uint8Array).meta({id:"Uint8Array"}),Pn=Ie.string().refine(r=>{try{return W.fromText(r),!0}catch{return!1}},{error:"Invalid textual representation of a Principal."}).meta({id:"PrincipalText"}),jn=Ie.custom().refine(r=>W.isPrincipal(r),{error:"Invalid Principal.",abort:!0}).transform(r=>W.from(r)).meta({id:"Principal"}),jr=({additionalProtocols:r=[],allowHttpLocally:e=!0})=>wt.url().refine(t=>{try{let n=[...new Set(["https:",...r])],{protocol:i,hostname:s}=new URL(t);return e&&["localhost","127.0.0.1"].includes(s)?["http:",...n].includes(i):n.includes(i)}catch{return!1}},{error:"Invalid URL."}),Mn=jr({}).meta({id:"Url"});import*as _t from"zod";var ae=({id:r,zodSchema:e})=>{let t=e.toJSONSchema({unrepresentable:"any",override:s=>{s.zodSchema._zod.def.type==="bigint"&&(s.jsonSchema.type="integer",s.jsonSchema.format="bigint"),s.jsonSchema.id===Ne.Principal&&(s.jsonSchema.format="principal"),s.jsonSchema.id===Ne.Uint8Array&&(s.jsonSchema.format="uint8array")}}),n=$({schema:t,rootDefs:t.$defs??{}}),i=e._zod.def.type==="optional"&&!("innerType"in e._zod.def&&e._zod.def.innerType instanceof _t.ZodNullable);return{id:r,schema:n,isTopLevelOptional:i}},$=({schema:r,rootDefs:e})=>{if(r.format==="principal")return{kind:"principal"};if(r.format==="uint8array")return{kind:"uint8array"};if("$ref"in r){let t=r.$ref.replace("#/$defs/",""),n=e[t];if(n===void 0)throw new Error(`Unresolved $ref: ${r.$ref}`);return $({schema:n,rootDefs:e})}switch(r.type){case"string":if(r.const!==void 0)return{kind:"variant",tags:[String(r.const)]};if(r.enum!==void 0){if(r.enum.some(t=>typeof t!="string"))throw new Error("Non-string enum values are not supported");return{kind:"variant",tags:r.enum}}return{kind:"text"};case"boolean":return{kind:"bool"};case"number":return{kind:"float64"};case"integer":return r.format==="bigint"?{kind:"nat"}:{kind:"int32"};case"null":throw new Error("null type is not supported");case"array":{if(r.prefixItems!==void 0){if(r.prefixItems.some(t=>typeof t=="boolean"))throw new Error("Boolean schema not supported.");return{kind:"indexedTuple",members:r.prefixItems.map(t=>$({schema:t,rootDefs:e}))}}if(r.items===void 0)throw new Error("Array schema must have items defined");if(Array.isArray(r.items))throw new Error("Tuple-style array items not supported");if(typeof r.items=="boolean")throw new Error("Boolean schema not supported for array items");return{kind:"vec",inner:$({schema:r.items,rootDefs:e})}}case"object":{if(r.properties===void 0&&r.additionalProperties!==void 0){if(typeof r.additionalProperties=="boolean")throw new Error("Boolean additionalProperties not supported");return{kind:"vec",inner:{kind:"tuple",members:[{kind:"text"},$({schema:r.additionalProperties,rootDefs:e})]}}}if(r.properties===void 0)return{kind:"record",fields:[]};if(Object.keys(r.properties).length===0)return{kind:"record",fields:[]};let t=new Set(r.required??[]),n=Object.entries(r.properties);if(n.some(([i,s])=>typeof s=="boolean"))throw new Error("Boolean schema not supported.");return{kind:"record",fields:n.map(([i,s])=>{let o=$({schema:s,rootDefs:e});return{name:i,type:t.has(i)?o:{kind:"opt",inner:o}}})}}}if(r.oneOf!==void 0){let t=r.oneOf.filter(({type:n})=>n!=="null");return t.length===1?{kind:"opt",inner:$({schema:t[0],rootDefs:e})}:{kind:"variantRecords",members:t.map(n=>$({schema:n,rootDefs:e}))}}if(r.anyOf!==void 0){let t=r.anyOf.filter(s=>typeof s!="boolean");if(t.filter(s=>Object.keys(s).length===0).length>0)throw new Error("Unrepresentable type in union");if(t.every(s=>s.const!==void 0))return{kind:"variant",tags:t.map(s=>String(s.const))};let i=t.filter(s=>s.type!=="null");return i.length===1?{kind:"opt",inner:$({schema:i[0],rootDefs:e})}:{kind:"variantRecords",members:i.map(s=>$({schema:s,rootDefs:e}))}}if(r.allOf!==void 0){if(r.allOf.some(n=>typeof n=="boolean"))throw new Error("Boolean schema not supported in allOf");if(r.allOf.some(n=>typeof n!="boolean"&&(n.type!=="object"||n.properties===void 0)))throw new Error("allOf only supported for object types");return{kind:"record",fields:r.allOf.flatMap(n=>{let i=new Set(n.required??[]);return Object.entries(n.properties??{}).map(([s,o])=>{let a=$({schema:o,rootDefs:e});return{name:s,type:i.has(s)?a:{kind:"opt",inner:a}}})})}}throw Object.keys(r).length===0?new Error("Unsupported type: unrepresentable schema (z.symbol, z.undefined, z.void, z.map, z.set, z.nan, z.custom are not supported)"):new Error(`Unsupported JSON Schema: ${JSON.stringify(r)}`)};var K=r=>{switch(r.kind){case"text":return"text";case"bool":return"bool";case"float64":return"float64";case"int32":return"int32";case"nat":return"nat";case"opt":return`opt ${K(r.inner)}`;case"vec":return`vec ${K(r.inner)}`;case"record":return r.fields.length===0?"record {}":`record { ${r.fields.map(e=>`${e.name} : ${K(e.type)}`).join("; ")} }`;case"tuple":return`record { ${r.members.map(K).join("; ")} }`;case"indexedTuple":return`record { ${r.members.map((e,t)=>`${t} : ${K(e)}`).join("; ")} }`;case"variant":return`variant { ${r.tags.join("; ")} }`;case"variantRecords":return`variant { ${r.members.map(K).join("; ")} }`;case"principal":return"principal";case"uint8array":return"blob"}},Jn=r=>Object.entries(r).map(([e,t])=>ae({id:e,zodSchema:t})).map(({schema:e,id:t,isTopLevelOptional:n})=>`type ${t} = ${n?`opt ${K(e)}`:K(e)};`).join(`
|
|
27
|
+
`);var S={};ar(S,{Bool:()=>$t,BoolClass:()=>Oe,ConstructType:()=>R,Empty:()=>It,EmptyClass:()=>be,FixedIntClass:()=>H,FixedNatClass:()=>C,Float32:()=>kt,Float64:()=>Vt,FloatClass:()=>we,Func:()=>Zt,FuncClass:()=>te,Int:()=>Ot,Int16:()=>Ft,Int32:()=>Pt,Int64:()=>jt,Int8:()=>Lt,IntClass:()=>xe,Nat:()=>Bt,Nat16:()=>Ht,Nat32:()=>Dt,Nat64:()=>zt,Nat8:()=>Mt,NatClass:()=>ge,Null:()=>Ct,NullClass:()=>X,Opt:()=>Wt,OptClass:()=>Z,PrimitiveType:()=>N,Principal:()=>Gt,PrincipalClass:()=>Ve,Rec:()=>Qt,RecClass:()=>I,Record:()=>Kt,RecordClass:()=>ee,Reserved:()=>Ut,ReservedClass:()=>O,Service:()=>Xt,ServiceClass:()=>le,Text:()=>Rt,TextClass:()=>Be,Tuple:()=>Jt,TupleClass:()=>ke,Type:()=>ce,Unknown:()=>Gr,UnknownClass:()=>Re,Variant:()=>Yt,VariantClass:()=>fe,Vec:()=>qt,VecClass:()=>ue,Visitor:()=>We,decode:()=>zr,encode:()=>Dr,resetSubtypeCache:()=>Ke,subtype:()=>Qe});function h(...r){let e=new Uint8Array(r.reduce((n,i)=>n+i.byteLength,0)),t=0;for(let n of r)e.set(n,t),t+=n.byteLength;return e}var P=class{save(){return this._view}restore(e){if(!(e instanceof Uint8Array))throw new Error("Checkpoint must be a Uint8Array");this._view=e}constructor(e,t=e?.byteLength||0){if(e&&!(e instanceof Uint8Array))try{e=Tt(e)}catch{throw new Error("Buffer must be a Uint8Array")}if(t<0||!Number.isInteger(t))throw new Error("Length must be a non-negative integer");if(e&&t>e.byteLength)throw new Error("Length cannot exceed buffer length");this._buffer=e||new Uint8Array(0),this._view=new Uint8Array(this._buffer.buffer,0,t)}get buffer(){return this._view.slice()}get byteLength(){return this._view.byteLength}read(e){let t=this._view.subarray(0,e);return this._view=this._view.subarray(e),t.slice()}readUint8(){if(this._view.byteLength===0)return;let e=this._view[0];return this._view=this._view.subarray(1),e}write(e){if(!(e instanceof Uint8Array))throw new Error("Buffer must be a Uint8Array");let t=this._view.byteLength;this._view.byteOffset+this._view.byteLength+e.byteLength>=this._buffer.byteLength?this.alloc(e.byteLength):this._view=new Uint8Array(this._buffer.buffer,this._view.byteOffset,this._view.byteLength+e.byteLength),this._view.set(e,t)}get end(){return this._view.byteLength===0}alloc(e){if(e<=0||!Number.isInteger(e))throw new Error("Amount must be a positive integer");let t=new Uint8Array((this._buffer.byteLength+e)*1.2|0),n=new Uint8Array(t.buffer,0,this._view.byteLength+e);n.set(this._view),this._buffer=t,this._view=n}};function Tt(r){if(!r)throw new Error("Input cannot be null or undefined");return r instanceof Uint8Array?r:r instanceof ArrayBuffer?new Uint8Array(r):Array.isArray(r)?new Uint8Array(r):"buffer"in r?Tt(r.buffer):new Uint8Array(r)}function St(r){if(!(r instanceof Uint8Array))throw new Error("Input must be a Uint8Array");return new DataView(r.buffer,r.byteOffset,r.byteLength)}function Mr(r){let t=new TextEncoder().encode(r),n=0;for(let i of t)n=(n*223+i)%2**32;return n}function A(r){if(/^_\d+_$/.test(r)||/^_0x[0-9a-fA-F]+_$/.test(r)){let e=+r.slice(1,-1);if(Number.isSafeInteger(e)&&e>=0&&e<2**32)return e}return Mr(r)}function De(r){let e=BigInt(r);if(r<=0)throw new RangeError("Input must be positive");return e.toString(2).length-1}function Ue(r){let e=BigInt(r);if(r<0)throw new RangeError("Input must be non-negative");return BigInt(1)<<e}function vt(){throw new Error("unexpected end of buffer")}function Q(r,e){return r.byteLength<e&&vt(),r.read(e)}function Y(r){let e=r.readUint8();return e===void 0&&vt(),e}function g(r){if(typeof r=="number"&&(r=BigInt(r)),r<BigInt(0))throw new Error("Cannot leb encode negative values.");let e=(r===BigInt(0)?0:De(r))+1,t=new P(new Uint8Array(e),0);for(;;){let n=Number(r&BigInt(127));if(r/=BigInt(128),r===BigInt(0)){t.write(new Uint8Array([n]));break}else t.write(new Uint8Array([n|128]))}return t.buffer}function T(r){let e=BigInt(1),t=BigInt(0),n;do n=Y(r),t+=BigInt(n&127).valueOf()*e,e*=BigInt(128);while(n>=128);return t}function w(r){typeof r=="number"&&(r=BigInt(r));let e=r<BigInt(0);e&&(r=-r-BigInt(1));let t=(r===BigInt(0)?0:De(r))+1,n=new P(new Uint8Array(t),0);for(;;){let s=i(r);if(r/=BigInt(128),e&&r===BigInt(0)&&(s&64)!==0||!e&&r===BigInt(0)&&(s&64)===0){n.write(new Uint8Array([s]));break}else n.write(new Uint8Array([s|128]))}function i(s){let o=s%BigInt(128);return Number(e?BigInt(128)-o-BigInt(1):o)}return n.buffer}function j(r){let e=new Uint8Array(r.buffer),t=0;for(;t<e.byteLength;t++)if(e[t]<128){if((e[t]&64)===0)return T(r);break}let n=new Uint8Array(Q(r,t+1)),i=BigInt(0);for(let s=n.byteLength-1;s>=0;s--)i=i*BigInt(128)+BigInt(128-(n[s]&127)-1);return-i-BigInt(1)}function At(r,e){if(BigInt(r)<BigInt(0))throw new Error("Cannot write negative values.");return ze(r,e)}function ze(r,e){r=BigInt(r);let t=new P(new Uint8Array(Math.min(1,e)),0),n=0,i=BigInt(256),s=BigInt(0),o=Number(r%i);for(t.write(new Uint8Array([o]));++n<e;)r<0&&s===BigInt(0)&&o!==0&&(s=BigInt(1)),o=Number((r/i-s)%BigInt(256)),t.write(new Uint8Array([o])),i*=BigInt(256);return t.buffer}function Ge(r,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let t=BigInt(Y(r)),n=BigInt(1),i=0;for(;++i<e;){n*=BigInt(256);let s=BigInt(Y(r));t=t+n*s}return t}function Et(r,e){if(e<=0||!Number.isInteger(e))throw new Error("Byte length must be a positive integer");let t=Ge(r,e),n=BigInt(2)**(BigInt(8)*BigInt(e-1)+BigInt(7));return t>=n&&(t-=n*BigInt(2)),t}var m;(function(r){r[r.Null=-1]="Null",r[r.Bool=-2]="Bool",r[r.Nat=-3]="Nat",r[r.Int=-4]="Int",r[r.Float32=-13]="Float32",r[r.Float64=-14]="Float64",r[r.Text=-15]="Text",r[r.Reserved=-16]="Reserved",r[r.Empty=-17]="Empty",r[r.Opt=-18]="Opt",r[r.Vector=-19]="Vector",r[r.Record=-20]="Record",r[r.Variant=-21]="Variant",r[r.Func=-22]="Func",r[r.Service=-23]="Service",r[r.Principal=-24]="Principal"})(m||(m={}));var $e="DIDL",Hr=new TextEncoder().encode($e),Nt=400;function me(r,e,t){return r.map((n,i)=>t(n,e[i]))}var qe=class{constructor(){this._typs=[],this._idx=new Map,this._idxRefCount=new Map}has(e){return this._idx.has(e.name)}add(e,t){let n=this._typs.length;this._idx.set(e.name,n),this._idxRefCount.set(n,1),this._typs.push(t)}merge(e,t){let n=this._idx.get(e.name),i=this._idx.get(t);if(n===void 0)throw new Error("Missing type index for "+e);if(i===void 0)throw new Error("Missing type index for "+t);this._typs[n]=this._typs[i];let s=this._getIdxRefCount(n),o=this._getIdxRefCount(i);this._idxRefCount.set(n,s+o),this._idx.set(t,n),this._idxRefCount.set(i,0),this._compactFromEnd()}_getIdxRefCount(e){return this._idxRefCount.get(e)||0}_compactFromEnd(){for(;this._typs.length>0;){let e=this._typs.length-1;if(this._getIdxRefCount(e)>0)break;this._typs.pop(),this._idxRefCount.delete(e)}}encode(){let e=g(this._typs.length),t=h(...this._typs);return h(e,t)}indexOf(e){if(!this._idx.has(e))throw new Error("Missing type index for "+e);return w(this._idx.get(e)||0)}},We=class{visitType(e,t){throw new Error("Not implemented")}visitPrimitive(e,t){return this.visitType(e,t)}visitEmpty(e,t){return this.visitPrimitive(e,t)}visitBool(e,t){return this.visitPrimitive(e,t)}visitNull(e,t){return this.visitPrimitive(e,t)}visitReserved(e,t){return this.visitPrimitive(e,t)}visitText(e,t){return this.visitPrimitive(e,t)}visitNumber(e,t){return this.visitPrimitive(e,t)}visitInt(e,t){return this.visitNumber(e,t)}visitNat(e,t){return this.visitNumber(e,t)}visitFloat(e,t){return this.visitPrimitive(e,t)}visitFixedInt(e,t){return this.visitNumber(e,t)}visitFixedNat(e,t){return this.visitNumber(e,t)}visitPrincipal(e,t){return this.visitPrimitive(e,t)}visitConstruct(e,t){return this.visitType(e,t)}visitVec(e,t,n){return this.visitConstruct(e,n)}visitOpt(e,t,n){return this.visitConstruct(e,n)}visitRecord(e,t,n){return this.visitConstruct(e,n)}visitTuple(e,t,n){let i=t.map((s,o)=>[`_${o}_`,s]);return this.visitRecord(e,i,n)}visitVariant(e,t,n){return this.visitConstruct(e,n)}visitRec(e,t,n){return this.visitConstruct(t,n)}visitFunc(e,t){return this.visitConstruct(e,t)}visitService(e,t){return this.visitConstruct(e,t)}},l;(function(r){r.EmptyClass="__IDL_EmptyClass__",r.UnknownClass="__IDL_UnknownClass__",r.BoolClass="__IDL_BoolClass__",r.NullClass="__IDL_NullClass__",r.ReservedClass="__IDL_ReservedClass__",r.TextClass="__IDL_TextClass__",r.IntClass="__IDL_IntClass__",r.NatClass="__IDL_NatClass__",r.FloatClass="__IDL_FloatClass__",r.FixedIntClass="__IDL_FixedIntClass__",r.FixedNatClass="__IDL_FixedNatClass__",r.VecClass="__IDL_VecClass__",r.OptClass="__IDL_OptClass__",r.RecordClass="__IDL_RecordClass__",r.TupleClass="__IDL_TupleClass__",r.VariantClass="__IDL_VariantClass__",r.RecClass="__IDL_RecClass__",r.PrincipalClass="__IDL_PrincipalClass__",r.FuncClass="__IDL_FuncClass__",r.ServiceClass="__IDL_ServiceClass__"})(l||(l={}));var ce=class{display(){return this.name}valueToString(e){return x(e)}buildTypeTable(e){e.has(this)||this._buildTypeTableImpl(e)}},N=class extends ce{checkType(e){if(this.name!==e.name)throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`);return e}_buildTypeTableImpl(e){}},R=class extends ce{checkType(e){if(e instanceof I){let t=e.getType();if(typeof t>"u")throw new Error("type mismatch with uninitialized type");return t}throw new Error(`type mismatch: type on the wire ${e.name}, expect type ${this.name}`)}encodeType(e){return e.indexOf(this.name)}},be=class extends N{get typeName(){return l.EmptyClass}static[Symbol.hasInstance](e){return e.typeName===l.EmptyClass}accept(e,t){return e.visitEmpty(this,t)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(){throw new Error("Empty cannot appear as a function argument")}valueToString(){throw new Error("Empty cannot appear as a value")}encodeType(){return w(m.Empty)}decodeValue(){throw new Error("Empty cannot appear as an output")}get name(){return"empty"}},Re=class extends ce{get typeName(){return l.UnknownClass}static[Symbol.hasInstance](e){return e.typeName===l.UnknownClass}checkType(e){throw new Error("Method not implemented for unknown.")}accept(e,t){throw e.visitType(this,t)}covariant(e){throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(){throw new Error("Unknown cannot appear as a function argument")}valueToString(){throw new Error("Unknown cannot appear as a value")}encodeType(){throw new Error("Unknown cannot be serialized")}decodeValue(e,t){let n=t.decodeValue(e,t);Object(n)!==n&&(n=Object(n));let i;return t instanceof I?i=()=>t.getType():i=()=>t,Object.defineProperty(n,"type",{value:i,writable:!0,enumerable:!1,configurable:!0}),n}_buildTypeTableImpl(){throw new Error("Unknown cannot be serialized")}get name(){return"Unknown"}},Oe=class extends N{get typeName(){return l.BoolClass}static[Symbol.hasInstance](e){return e.typeName===l.BoolClass}accept(e,t){return e.visitBool(this,t)}covariant(e){if(typeof e=="boolean")return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return new Uint8Array([e?1:0])}encodeType(){return w(m.Bool)}decodeValue(e,t){switch(this.checkType(t),Y(e)){case 0:return!1;case 1:return!0;default:throw new Error("Boolean value out of range")}}get name(){return"bool"}},X=class extends N{get typeName(){return l.NullClass}static[Symbol.hasInstance](e){return e.typeName===l.NullClass}accept(e,t){return e.visitNull(this,t)}covariant(e){if(e===null)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(){return new Uint8Array(0)}encodeType(){return w(m.Null)}decodeValue(e,t){return this.checkType(t),null}get name(){return"null"}},O=class extends N{get typeName(){return l.ReservedClass}static[Symbol.hasInstance](e){return e.typeName===l.ReservedClass}accept(e,t){return e.visitReserved(this,t)}covariant(e){return!0}encodeValue(){return new Uint8Array(0)}encodeType(){return w(m.Reserved)}decodeValue(e,t){return t.name!==this.name&&t.decodeValue(e,t),null}get name(){return"reserved"}},Be=class extends N{get typeName(){return l.TextClass}static[Symbol.hasInstance](e){return e.typeName===l.TextClass}accept(e,t){return e.visitText(this,t)}covariant(e){if(typeof e=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=new TextEncoder().encode(e),n=g(t.byteLength);return h(n,t)}encodeType(){return w(m.Text)}decodeValue(e,t){this.checkType(t);let n=T(e),i=Q(e,Number(n));return new TextDecoder("utf8",{fatal:!0}).decode(i)}get name(){return"text"}valueToString(e){return'"'+e+'"'}},xe=class extends N{get typeName(){return l.IntClass}static[Symbol.hasInstance](e){return e.typeName===l.IntClass}accept(e,t){return e.visitInt(this,t)}covariant(e){if(typeof e=="bigint"||Number.isInteger(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return w(e)}encodeType(){return w(m.Int)}decodeValue(e,t){return this.checkType(t),j(e)}get name(){return"int"}valueToString(e){return e.toString()}},ge=class extends N{get typeName(){return l.NatClass}static[Symbol.hasInstance](e){return e.typeName===l.NatClass}accept(e,t){return e.visitNat(this,t)}covariant(e){if(typeof e=="bigint"&&e>=BigInt(0)||Number.isInteger(e)&&e>=0)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return g(e)}encodeType(){return w(m.Nat)}decodeValue(e,t){return this.checkType(t),T(e)}get name(){return"nat"}valueToString(e){return e.toString()}},we=class extends N{get typeName(){return l.FloatClass}static[Symbol.hasInstance](e){return e.typeName===l.FloatClass}constructor(e){if(super(),this._bits=e,e!==32&&e!==64)throw new Error("not a valid float type")}accept(e,t){return e.visitFloat(this,t)}covariant(e){if(typeof e=="number"||e instanceof Number)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=new ArrayBuffer(this._bits/8),n=new DataView(t);return this._bits===32?n.setFloat32(0,e,!0):n.setFloat64(0,e,!0),new Uint8Array(t)}encodeType(){let e=this._bits===32?m.Float32:m.Float64;return w(e)}decodeValue(e,t){this.checkType(t);let n=Q(e,this._bits/8),i=St(n);return this._bits===32?i.getFloat32(0,!0):i.getFloat64(0,!0)}get name(){return"float"+this._bits}valueToString(e){return e.toString()}},H=class extends N{get typeName(){return l.FixedIntClass}static[Symbol.hasInstance](e){return e.typeName===l.FixedIntClass}constructor(e){super(),this._bits=e}accept(e,t){return e.visitFixedInt(this,t)}covariant(e){let t=Ue(this._bits-1)*BigInt(-1),n=Ue(this._bits-1)-BigInt(1),i=!1;if(typeof e=="bigint")i=e>=t&&e<=n;else if(Number.isInteger(e)){let s=BigInt(e);i=s>=t&&s<=n}else i=!1;if(i)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return ze(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return w(-9-e)}decodeValue(e,t){this.checkType(t);let n=Et(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`int${this._bits}`}valueToString(e){return e.toString()}},C=class extends N{get typeName(){return l.FixedNatClass}static[Symbol.hasInstance](e){return e.typeName===l.FixedNatClass}constructor(e){super(),this._bits=e}accept(e,t){return e.visitFixedNat(this,t)}covariant(e){let t=Ue(this._bits),n=!1;if(typeof e=="bigint"&&e>=BigInt(0)?n=e<t:Number.isInteger(e)&&e>=0?n=BigInt(e)<t:n=!1,n)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return At(e,this._bits/8)}encodeType(){let e=Math.log2(this._bits)-3;return w(-5-e)}decodeValue(e,t){this.checkType(t);let n=Ge(e,this._bits/8);return this._bits<=32?Number(n):n}get name(){return`nat${this._bits}`}valueToString(e){return e.toString()}},ue=class r extends R{get typeName(){return l.VecClass}static[Symbol.hasInstance](e){return e.typeName===l.VecClass}constructor(e){super(),this._type=e,this._blobOptimization=!1,e instanceof C&&e._bits===8&&(this._blobOptimization=!0)}accept(e,t){return e.visitVec(this,this._type,t)}covariant(e){let t=this._type instanceof C?this._type._bits:this._type instanceof H?this._type._bits:0;if(ArrayBuffer.isView(e)&&t==e.BYTES_PER_ELEMENT*8||Array.isArray(e)&&e.every((n,i)=>{try{return this._type.covariant(n)}catch(s){throw new Error(`Invalid ${this.display()} argument:
|
|
28
28
|
|
|
29
|
-
index ${i} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=g(e.length);if(this._blobOptimization)return h(t,new Uint8Array(e));if(ArrayBuffer.isView(e))if(e instanceof Int16Array||e instanceof Uint16Array){let i=new DataView(new ArrayBuffer(e.length*2));for(let s=0;s<e.length;s++)e instanceof Int16Array?i.setInt16(s*2,e[s],!0):i.setUint16(s*2,e[s],!0);return h(t,new Uint8Array(i.buffer))}else if(e instanceof Int32Array||e instanceof Uint32Array){let i=new DataView(new ArrayBuffer(e.length*4));for(let s=0;s<e.length;s++)e instanceof Int32Array?i.setInt32(s*4,e[s],!0):i.setUint32(s*4,e[s],!0);return h(t,new Uint8Array(i.buffer))}else if(e instanceof BigInt64Array||e instanceof BigUint64Array){let i=new DataView(new ArrayBuffer(e.length*8));for(let s=0;s<e.length;s++)e instanceof BigInt64Array?i.setBigInt64(s*8,e[s],!0):i.setBigUint64(s*8,e[s],!0);return h(t,new Uint8Array(i.buffer))}else return h(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));let n=new
|
|
29
|
+
index ${i} -> ${s.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=g(e.length);if(this._blobOptimization)return h(t,new Uint8Array(e));if(ArrayBuffer.isView(e))if(e instanceof Int16Array||e instanceof Uint16Array){let i=new DataView(new ArrayBuffer(e.length*2));for(let s=0;s<e.length;s++)e instanceof Int16Array?i.setInt16(s*2,e[s],!0):i.setUint16(s*2,e[s],!0);return h(t,new Uint8Array(i.buffer))}else if(e instanceof Int32Array||e instanceof Uint32Array){let i=new DataView(new ArrayBuffer(e.length*4));for(let s=0;s<e.length;s++)e instanceof Int32Array?i.setInt32(s*4,e[s],!0):i.setUint32(s*4,e[s],!0);return h(t,new Uint8Array(i.buffer))}else if(e instanceof BigInt64Array||e instanceof BigUint64Array){let i=new DataView(new ArrayBuffer(e.length*8));for(let s=0;s<e.length;s++)e instanceof BigInt64Array?i.setBigInt64(s*8,e[s],!0):i.setBigUint64(s*8,e[s],!0);return h(t,new Uint8Array(i.buffer))}else return h(t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength));let n=new P(new Uint8Array(t.byteLength+e.length),0);n.write(t);for(let i of e){let s=this._type.encodeValue(i);n.write(new Uint8Array(s))}return n.buffer}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let t=w(m.Vector),n=this._type.encodeType(e);e.add(this,h(t,n))}decodeValue(e,t){let n=this.checkType(t);if(!(n instanceof r))throw new Error("Not a vector type");let i=Number(T(e));if(this._type instanceof C){if(this._type._bits==8)return new Uint8Array(e.read(i));if(this._type._bits==16){let o=e.read(i*2);return new Uint16Array(o.buffer,o.byteOffset,i)}if(this._type._bits==32){let o=e.read(i*4);return new Uint32Array(o.buffer,o.byteOffset,i)}if(this._type._bits==64)return new BigUint64Array(e.read(i*8).buffer)}if(this._type instanceof H){if(this._type._bits==8)return new Int8Array(e.read(i));if(this._type._bits==16){let o=e.read(i*2),a=new DataView(o.buffer,o.byteOffset,o.byteLength),c=new Int16Array(i);for(let u=0;u<i;u++)c[u]=a.getInt16(u*2,!0);return c}if(this._type._bits==32){let o=e.read(i*4),a=new DataView(o.buffer,o.byteOffset,o.byteLength),c=new Int32Array(i);for(let u=0;u<i;u++)c[u]=a.getInt32(u*4,!0);return c}if(this._type._bits==64){let o=e.read(i*8),a=new DataView(o.buffer,o.byteOffset,o.byteLength),c=new BigInt64Array(i);for(let u=0;u<i;u++)c[u]=a.getBigInt64(u*8,!0);return c}}let s=[];for(let o=0;o<i;o++)s.push(this._type.decodeValue(e,n._type));return s}get name(){return`vec ${this._type.name}`}display(){return`vec ${this._type.display()}`}valueToString(e){return"vec {"+e.map(n=>this._type.valueToString(n)).join("; ")+"}"}},Z=class r extends R{get typeName(){return l.OptClass}static[Symbol.hasInstance](e){return e.typeName===l.OptClass}constructor(e){super(),this._type=e}accept(e,t){return e.visitOpt(this,this._type,t)}covariant(e){try{if(Array.isArray(e)&&(e.length===0||e.length===1&&this._type.covariant(e[0])))return!0}catch(t){throw new Error(`Invalid ${this.display()} argument: ${x(e)}
|
|
30
30
|
|
|
31
|
-
-> ${t.message}`)}throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return e.length===0?new Uint8Array([0]):h(new Uint8Array([1]),this._type.encodeValue(e[0]))}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let t=w(
|
|
31
|
+
-> ${t.message}`)}throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){return e.length===0?new Uint8Array([0]):h(new Uint8Array([1]),this._type.encodeValue(e[0]))}_buildTypeTableImpl(e){this._type.buildTypeTable(e);let t=w(m.Opt),n=this._type.encodeType(e);e.add(this,h(t,n))}decodeValue(e,t){if(t instanceof X)return[];if(t instanceof O)return[];let n=t;if(t instanceof I){let i=t.getType();if(typeof i>"u")throw new Error("type mismatch with uninitialized type");n=i}if(n instanceof r)switch(Y(e)){case 0:return[];case 1:{let i=e.save();try{return[this._type.decodeValue(e,n._type)]}catch{return e.restore(i),n._type.decodeValue(e,n._type),[]}}default:throw new Error("Not an option value")}else{if(this._type instanceof X||this._type instanceof r||this._type instanceof O)return n.decodeValue(e,n),[];{let i=e.save();try{return[this._type.decodeValue(e,t)]}catch{return e.restore(i),n.decodeValue(e,t),[]}}}}get name(){return`opt ${this._type.name}`}display(){return`opt ${this._type.display()}`}valueToString(e){return e.length===0?"null":`opt ${this._type.valueToString(e[0])}`}},ee=class r extends R{get typeName(){return l.RecordClass}static[Symbol.hasInstance](e){return e.typeName===l.RecordClass||e.typeName===l.TupleClass}constructor(e={}){super(),this._fields=Object.entries(e).sort((t,n)=>A(t[0])-A(n[0]))}accept(e,t){return e.visitRecord(this,this._fields,t)}tryAsTuple(){let e=[];for(let t=0;t<this._fields.length;t++){let[n,i]=this._fields[t];if(n!==`_${t}_`)return null;e.push(i)}return e}covariant(e){if(typeof e=="object"&&this._fields.every(([t,n])=>{if(!e.hasOwnProperty(t))throw new Error(`Record is missing key "${t}".`);try{return n.covariant(e[t])}catch(i){throw new Error(`Invalid ${this.display()} argument:
|
|
32
32
|
|
|
33
|
-
field ${t} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=this._fields.map(([i])=>e[i]),n=
|
|
33
|
+
field ${t} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=this._fields.map(([i])=>e[i]),n=me(this._fields,t,([,i],s)=>i.encodeValue(s));return h(...n)}_buildTypeTableImpl(e){this._fields.forEach(([s,o])=>o.buildTypeTable(e));let t=w(m.Record),n=g(this._fields.length),i=this._fields.map(([s,o])=>h(g(A(s)),o.encodeType(e)));e.add(this,h(t,n,h(...i)))}decodeValue(e,t){let n=this.checkType(t);if(!(n instanceof r))throw new Error("Not a record type");let i={},s=0,o=0;for(;o<n._fields.length;){let[a,c]=n._fields[o];if(s>=this._fields.length){c.decodeValue(e,c),o++;continue}let[u,y]=this._fields[s],p=A(this._fields[s][0]),f=A(a);if(p===f)i[u]=y.decodeValue(e,c),s++,o++;else if(f>p)if(y instanceof Z||y instanceof O)i[u]=[],s++;else throw new Error("Cannot find required field "+u);else c.decodeValue(e,c),o++}for(let[a,c]of this._fields.slice(s))if(c instanceof Z||c instanceof O)i[a]=[];else throw new Error("Cannot find required field "+a);return i}get fieldsAsObject(){let e={};for(let[t,n]of this._fields)e[A(t)]=n;return e}get name(){return`record {${this._fields.map(([t,n])=>t+":"+n.name).join("; ")}}`}display(){return`record {${this._fields.map(([t,n])=>t+":"+n.display()).join("; ")}}`}valueToString(e){let t=this._fields.map(([i])=>e[i]);return`record {${me(this._fields,t,([i,s],o)=>i+"="+s.valueToString(o)).join("; ")}}`}},ke=class r extends ee{get typeName(){return l.TupleClass}static[Symbol.hasInstance](e){return e.typeName===l.TupleClass}constructor(e){let t={};e.forEach((n,i)=>t["_"+i+"_"]=n),super(t),this._components=e}accept(e,t){return e.visitTuple(this,this._components,t)}covariant(e){if(Array.isArray(e)&&e.length>=this._fields.length&&this._components.every((t,n)=>{try{return t.covariant(e[n])}catch(i){throw new Error(`Invalid ${this.display()} argument:
|
|
34
34
|
|
|
35
|
-
index ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=
|
|
35
|
+
index ${n} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=me(this._components,e,(n,i)=>n.encodeValue(i));return h(...t)}decodeValue(e,t){let n=this.checkType(t);if(!(n instanceof r))throw new Error("not a tuple type");if(n._components.length<this._components.length)throw new Error("tuple mismatch");let i=[];for(let[s,o]of n._components.entries())s>=this._components.length?o.decodeValue(e,o):i.push(this._components[s].decodeValue(e,o));return i}display(){return`record {${this._components.map(t=>t.display()).join("; ")}}`}valueToString(e){return`record {${me(this._components,e,(n,i)=>n.valueToString(i)).join("; ")}}`}},fe=class r extends R{get typeName(){return l.VariantClass}static[Symbol.hasInstance](e){return e.typeName===l.VariantClass}constructor(e={}){super(),this._fields=Object.entries(e).sort((t,n)=>A(t[0])-A(n[0]))}accept(e,t){return e.visitVariant(this,this._fields,t)}covariant(e){if(typeof e=="object"&&Object.entries(e).length===1&&this._fields.every(([t,n])=>{try{return!e.hasOwnProperty(t)||n.covariant(e[t])}catch(i){throw new Error(`Invalid ${this.display()} argument:
|
|
36
36
|
|
|
37
|
-
variant ${t} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){for(let t=0;t<this._fields.length;t++){let[n,i]=this._fields[t];if(e.hasOwnProperty(n)){let s=g(t),o=i.encodeValue(e[n]);return h(s,o)}}throw Error("Variant has no data: "+e)}_buildTypeTableImpl(e){this._fields.forEach(([,s])=>{s.buildTypeTable(e)});let t=w(
|
|
37
|
+
variant ${t} -> ${i.message}`)}}))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){for(let t=0;t<this._fields.length;t++){let[n,i]=this._fields[t];if(e.hasOwnProperty(n)){let s=g(t),o=i.encodeValue(e[n]);return h(s,o)}}throw Error("Variant has no data: "+e)}_buildTypeTableImpl(e){this._fields.forEach(([,s])=>{s.buildTypeTable(e)});let t=w(m.Variant),n=g(this._fields.length),i=this._fields.map(([s,o])=>h(g(A(s)),o.encodeType(e)));e.add(this,h(t,n,...i))}decodeValue(e,t){let n=this.checkType(t);if(!(n instanceof r))throw new Error("Not a variant type");let i=Number(T(e));if(i>=n._fields.length)throw Error("Invalid variant index: "+i);let[s,o]=n._fields[i];for(let[a,c]of this._fields)if(A(s)===A(a)){let u=c.decodeValue(e,o);return{[a]:u}}throw new Error("Cannot find field hash "+s)}get name(){return`variant {${this._fields.map(([t,n])=>t+":"+n.name).join("; ")}}`}display(){return`variant {${this._fields.map(([t,n])=>t+(n.name==="null"?"":`:${n.display()}`)).join("; ")}}`}valueToString(e){for(let[t,n]of this._fields)if(e.hasOwnProperty(t)){let i=n.valueToString(e[t]);return i==="null"?`variant {${t}}`:`variant {${t}=${i}}`}throw new Error("Variant has no data: "+e)}get alternativesAsObject(){let e={};for(let[t,n]of this._fields)e[A(t)]=n;return e}},I=class r extends R{constructor(){super(...arguments),this._id=r._counter++}get typeName(){return l.RecClass}static{this._counter=0}static[Symbol.hasInstance](e){return e.typeName===l.RecClass}accept(e,t){if(!this._type)throw Error("Recursive type uninitialized.");return e.visitRec(this,this._type,t)}fill(e){this._type=e}getType(){return this._type}covariant(e){if(this._type&&this._type.covariant(e))return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.encodeValue(e)}_buildTypeTableImpl(e){if(!this._type)throw Error("Recursive type uninitialized.");e.add(this,new Uint8Array([])),this._type.buildTypeTable(e),e.merge(this,this._type.name)}decodeValue(e,t){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.decodeValue(e,t)}get name(){return`rec_${this._id}`}display(){if(!this._type)throw Error("Recursive type uninitialized.");return`\u03BC${this.name}.${this._type.name}`}valueToString(e){if(!this._type)throw Error("Recursive type uninitialized.");return this._type.valueToString(e)}};function Ye(r){if(Y(r)!==1)throw new Error("Cannot decode principal");let t=Number(T(r));return W.fromUint8Array(new Uint8Array(Q(r,t)))}var Ve=class extends N{get typeName(){return l.PrincipalClass}static[Symbol.hasInstance](e){return e.typeName===l.PrincipalClass}accept(e,t){return e.visitPrincipal(this,t)}covariant(e){if(e&&e._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=e.toUint8Array(),n=g(t.byteLength);return h(new Uint8Array([1]),n,t)}encodeType(){return w(m.Principal)}decodeValue(e,t){return this.checkType(t),Ye(e)}get name(){return"principal"}valueToString(e){return`${this.name} "${e.toText()}"`}},te=class extends R{get typeName(){return l.FuncClass}static[Symbol.hasInstance](e){return e.typeName===l.FuncClass}static argsToString(e,t){if(e.length!==t.length)throw new Error("arity mismatch");return"("+e.map((n,i)=>n.valueToString(t[i])).join(", ")+")"}constructor(e,t,n=[]){super(),this.argTypes=e,this.retTypes=t,this.annotations=n}accept(e,t){return e.visitFunc(this,t)}covariant(e){if(Array.isArray(e)&&e.length===2&&e[0]&&e[0]._isPrincipal&&typeof e[1]=="string")return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue([e,t]){let n=e.toUint8Array(),i=g(n.byteLength),s=h(new Uint8Array([1]),i,n),o=new TextEncoder().encode(t),a=g(o.byteLength);return h(new Uint8Array([1]),s,a,o)}_buildTypeTableImpl(e){this.argTypes.forEach(u=>u.buildTypeTable(e)),this.retTypes.forEach(u=>u.buildTypeTable(e));let t=w(m.Func),n=g(this.argTypes.length),i=h(...this.argTypes.map(u=>u.encodeType(e))),s=g(this.retTypes.length),o=h(...this.retTypes.map(u=>u.encodeType(e))),a=g(this.annotations.length),c=h(...this.annotations.map(u=>this.encodeAnnotation(u)));e.add(this,h(t,n,i,s,o,a,c))}decodeValue(e,t){let n=t instanceof I?t.getType()??t:t;if(!Qe(n,this))throw new Error(`Cannot decode function reference at type ${this.display()} from wire type ${n.display()}`);if(Y(e)!==1)throw new Error("Cannot decode function reference");let s=Ye(e),o=Number(T(e)),a=Q(e,o),u=new TextDecoder("utf8",{fatal:!0}).decode(a);return[s,u]}get name(){let e=this.argTypes.map(i=>i.name).join(", "),t=this.retTypes.map(i=>i.name).join(", "),n=" "+this.annotations.join(" ");return`(${e}) -> (${t})${n}`}valueToString([e,t]){return`func "${e.toText()}".${t}`}display(){let e=this.argTypes.map(i=>i.display()).join(", "),t=this.retTypes.map(i=>i.display()).join(", "),n=" "+this.annotations.join(" ");return`(${e}) \u2192 (${t})${n}`}encodeAnnotation(e){if(e==="query")return new Uint8Array([1]);if(e==="oneway")return new Uint8Array([2]);if(e==="composite_query")return new Uint8Array([3]);throw new Error("Illegal function annotation")}},le=class extends R{get typeName(){return l.ServiceClass}static[Symbol.hasInstance](e){return e.typeName===l.ServiceClass}constructor(e){super(),this._fields=Object.entries(e).sort((t,n)=>t[0]<n[0]?-1:t[0]>n[0]?1:0)}accept(e,t){return e.visitService(this,t)}covariant(e){if(e&&e._isPrincipal)return!0;throw new Error(`Invalid ${this.display()} argument: ${x(e)}`)}encodeValue(e){let t=e.toUint8Array(),n=g(t.length);return h(new Uint8Array([1]),n,t)}_buildTypeTableImpl(e){this._fields.forEach(([s,o])=>o.buildTypeTable(e));let t=w(m.Service),n=g(this._fields.length),i=this._fields.map(([s,o])=>{let a=new TextEncoder().encode(s),c=g(a.length);return h(c,a,o.encodeType(e))});e.add(this,h(t,n,...i))}decodeValue(e,t){let n=t instanceof I?t.getType()??t:t;if(!Qe(n,this))throw new Error(`Cannot decode service reference at type ${this.display()} from wire type ${n.display()}`);return Ye(e)}get name(){return`service {${this._fields.map(([t,n])=>t+":"+n.name).join("; ")}}`}valueToString(e){return`service "${e.toText()}"`}fieldsAsObject(){let e={};for(let[t,n]of this._fields)e[t]=n;return e}};function x(r){let e=JSON.stringify(r,(t,n)=>typeof n=="bigint"?`BigInt(${n})`:n);return e&&e.length>Nt?e.substring(0,Nt-3)+"...":e}function Dr(r,e){if(e.length<r.length)throw Error("Wrong number of message arguments");let t=new qe;r.forEach(a=>a.buildTypeTable(t));let n=t.encode(),i=g(e.length),s=h(...r.map(a=>a.encodeType(t))),o=h(...me(r,e,(a,c)=>{try{a.covariant(c)}catch(u){throw new Error(u.message+`
|
|
38
38
|
|
|
39
|
-
`)}return a.encodeValue(c)}));return h(
|
|
40
|
-
`;return e}addNames(e,t,n){let i=this.rels.get(e);if(i==null){let s=new Map;s.set(t,n),this.rels.set(e,s)}else i.set(t,n)}},
|
|
41
|
-
`);return
|
|
39
|
+
`)}return a.encodeValue(c)}));return h(Hr,n,i,s,o)}function zr(r,e){let t=new P(e);if(e.byteLength<$e.length)throw new Error("Message length smaller than magic number");let n=Q(t,$e.length),i=new TextDecoder().decode(n);if(i!==$e)throw new Error("Wrong magic number: "+JSON.stringify(i));function s(f){let d=[],b=Number(T(f));for(let v=0;v<b;v++){let D=Number(j(f));switch(D){case m.Opt:case m.Vector:{let k=Number(j(f));d.push([D,k]);break}case m.Record:case m.Variant:{let k=[],ie=Number(T(f)),z;for(;ie--;){let G=Number(T(f));if(G>=Math.pow(2,32))throw new Error("field id out of 32-bit range");if(typeof z=="number"&&z>=G)throw new Error("field id collision or not sorted");z=G;let J=Number(j(f));k.push([G,J])}d.push([D,k]);break}case m.Func:{let k=[],ie=Number(T(f));for(;ie--;)k.push(Number(j(f)));let z=[],G=Number(T(f));for(;G--;)z.push(Number(j(f)));let J=[],ir=Number(T(f));for(;ir--;)switch(Number(T(f))){case 1:{J.push("query");break}case 2:{J.push("oneway");break}case 3:{J.push("composite_query");break}default:throw new Error("unknown annotation")}d.push([D,[k,z,J]]);break}case m.Service:{let k=Number(T(f)),ie=[];for(;k--;){let z=Number(T(f)),G=new TextDecoder().decode(Q(f,z)),J=j(f);ie.push([G,J])}d.push([D,ie]);break}default:throw new Error("Illegal op_code: "+D)}}let _=[],E=Number(T(f));for(let v=0;v<E;v++)_.push(Number(j(f)));return[d,_]}let[o,a]=s(t);if(a.length<r.length)throw new Error("Wrong number of return values");let c=o.map(f=>Qt());function u(f){if(f<-24)throw new Error("future value not supported");if(f<0)switch(f){case-1:return Ct;case-2:return $t;case-3:return Bt;case-4:return Ot;case-5:return Mt;case-6:return Ht;case-7:return Dt;case-8:return zt;case-9:return Lt;case-10:return Ft;case-11:return Pt;case-12:return jt;case-13:return kt;case-14:return Vt;case-15:return Rt;case-16:return Ut;case-17:return It;case-24:return Gt;default:throw new Error("Illegal op_code: "+f)}if(f>=o.length)throw new Error("type index out of range");return c[f]}function y(f){switch(f[0]){case m.Vector:{let d=u(f[1]);return qt(d)}case m.Opt:{let d=u(f[1]);return Wt(d)}case m.Record:{let d={};for(let[E,v]of f[1]){let D=`_${E}_`;d[D]=u(v)}let b=Kt(d),_=b.tryAsTuple();return Array.isArray(_)?Jt(..._):b}case m.Variant:{let d={};for(let[b,_]of f[1]){let E=`_${b}_`;d[E]=u(_)}return Yt(d)}case m.Func:{let[d,b,_]=f[1];return Zt(d.map(E=>u(E)),b.map(E=>u(E)),_)}case m.Service:{let d={},b=f[1];for(let[_,E]of b){let v=u(E);if(v instanceof I&&(v=v.getType()),!(v instanceof te))throw new Error("Illegal service definition: services can only contain functions");d[_]=v}return Xt(d)}default:throw new Error("Illegal op_code: "+f[0])}}o.forEach((f,d)=>{if(f[0]===m.Func){let b=y(f);c[d].fill(b)}}),o.forEach((f,d)=>{if(f[0]!==m.Func){let b=y(f);c[d].fill(b)}}),Ke();let p=a.map(f=>u(f));try{let f=r.map((d,b)=>d.decodeValue(t,p[b]));for(let d=r.length;d<p.length;d++)p[d].decodeValue(t,p[d]);if(t.byteLength>0)throw new Error("decode: Left-over bytes");return f}finally{Ke()}}var It=new be,Ut=new O,Gr=new Re,$t=new Oe,Ct=new X,Rt=new Be,Ot=new xe,Bt=new ge,kt=new we(32),Vt=new we(64),Lt=new H(8),Ft=new H(16),Pt=new H(32),jt=new H(64),Mt=new C(8),Ht=new C(16),Dt=new C(32),zt=new C(64),Gt=new Ve;function Jt(...r){return new ke(r)}function qt(r){return new ue(r)}function Wt(r){return new Z(r)}function Kt(r){return new ee(r)}function Yt(r){return new fe(r)}function Qt(){return new I}function Zt(r,e,t=[]){return new te(r,e,t)}function Xt(r){return new le(r)}var Le=class r{constructor(e=new Map){this.rels=e}copy(){let e=new Map;for(let[t,n]of this.rels.entries()){let i=new Map(n);e.set(t,i)}return new r(e)}known(e,t){return this.rels.get(e.name)?.get(t.name)}addNegative(e,t){this.addNames(e.name,t.name,!1)}add(e,t){this.addNames(e.name,t.name,!0)}display(){let e="";for(let[t,n]of this.rels)for(let[i,s]of n)e+=`${t} ${s?":<":"!<:"} ${i}
|
|
40
|
+
`;return e}addNames(e,t,n){let i=this.rels.get(e);if(i==null){let s=new Map;s.set(t,n),this.rels.set(e,s)}else i.set(t,n)}},Ce=new Le;function Ke(){Ce=new Le}function Jr(r,e){let t=new Set(r.annotations),n=new Set(e.annotations);if(t.size!==n.size)return!1;for(let i of t)if(!n.has(i))return!1;return!0}function Je(r){return r instanceof Z||r instanceof X||r instanceof O}function Qe(r,e){let t=Ce.copy(),n=M(t,r,e);return n?Ce.add(r,e):Ce.addNegative(r,e),n}function M(r,e,t){if(e.name===t.name)return!0;let n=r.known(e,t);if(n!==void 0)return n;if(r.add(e,t),t instanceof O||e instanceof be||e instanceof ge&&t instanceof xe)return!0;if(e instanceof ue&&t instanceof ue)return M(r,e._type,t._type);if(t instanceof Z)return!0;if(e instanceof ee&&t instanceof ee){let i=e.fieldsAsObject;for(let[s,o]of t._fields){let a=i[A(s)];if(a){if(!M(r,a,o))return!1}else if(!Je(o))return!1}return!0}if(e instanceof te&&t instanceof te){if(!Jr(e,t))return!1;for(let i=0;i<e.argTypes.length;i++){let s=e.argTypes[i];if(i<t.argTypes.length){if(!M(r,t.argTypes[i],s))return!1}else if(!Je(s))return!1}for(let i=0;i<t.retTypes.length;i++){let s=t.retTypes[i];if(i<e.retTypes.length){if(!M(r,e.retTypes[i],s))return!1}else if(!Je(s))return!1}return!0}if(e instanceof fe&&t instanceof fe){let i=t.alternativesAsObject;for(let[s,o]of e._fields){let a=i[A(s)];if(!a||!M(r,o,a))return!1}return!0}if(e instanceof le&&t instanceof le){let i=e.fieldsAsObject();for(let[s,o]of t._fields){let a=i[s];if(!a||!M(r,a,o))return!1}return!0}return e instanceof I?M(r,e.getType(),t):t instanceof I?M(r,e,t.getType()):!1}import{capitalize as qr}from"@junobuild/utils";var de=r=>{switch(r.kind){case"text":return S.Text;case"bool":return S.Bool;case"float64":return S.Float64;case"int32":return S.Int32;case"nat":return S.Nat64;case"principal":return S.Principal;case"uint8array":return S.Vec(S.Nat8);case"opt":return S.Opt(de(r.inner));case"vec":return S.Vec(de(r.inner));case"tuple":case"indexedTuple":return S.Tuple(...r.members.map(de));case"record":return S.Record(Object.fromEntries(r.fields.map(e=>[e.name,de(e.type)])));case"variant":return S.Variant(Object.fromEntries(r.tags.map(e=>[e,S.Null])));case"variantRecords":return S.Variant(Object.fromEntries(r.members.map((e,t)=>[`Variant${t}`,de(e)])))}},Wr=({id:r,schema:e,isTopLevelOptional:t,suffix:n})=>{let s=de(t?{kind:"opt",inner:e}:e);return{baseName:`${qr(r)}${n}`,idl:s}},yi=({id:r,schema:e,suffix:t})=>{let n=ae({zodSchema:e,id:r});return Wr({...n,suffix:t})};import{capitalize as re}from"@junobuild/utils";var Ze="#[derive(CandidType, Serialize, Deserialize, Clone, JsonData)]",B=r=>({kind:"primitive",...r}),pe=r=>({kind:"composite",...r}),Xe=r=>r.flatMap(e=>e.kind==="composite"?e.structs:[]),ne=({schema:r,structName:e})=>{switch(r.kind){case"text":return B({fieldType:"String"});case"bool":return B({fieldType:"bool"});case"float64":return B({fieldType:"f64"});case"int32":return B({fieldType:"i32"});case"nat":return B({fieldType:"u64"});case"principal":return B({fieldType:"Principal"});case"uint8array":return B({fieldType:"Vec<u8>"});case"opt":{let t=ne({schema:r.inner,structName:e}),n=`Option<${t.fieldType}>`;return t.kind==="composite"?pe({fieldType:n,structs:t.structs}):B({fieldType:n})}case"vec":{let t=ne({schema:r.inner,structName:e}),n=`Vec<${t.fieldType}>`;return t.kind==="composite"?pe({fieldType:n,structs:t.structs}):B({fieldType:n})}case"tuple":case"indexedTuple":{let t=r.members.map((s,o)=>ne({schema:s,structName:`${e}${o}`})),n=`(${t.map(s=>s.fieldType).join(", ")})`,i=Xe(t);return i.length>0?pe({fieldType:n,structs:i}):B({fieldType:n})}case"variant":{let t=re(e),n=r.tags.map(i=>` ${re(i)},`).join(`
|
|
41
|
+
`);return pe({fieldType:t,structs:[`${Ze}
|
|
42
42
|
pub enum ${t} {
|
|
43
43
|
${n}
|
|
44
|
-
}`]})}case"variantRecords":{let t=
|
|
44
|
+
}`]})}case"variantRecords":{let t=re(e),n=r.members.map((s,o)=>{if(s.kind==="record"){let c=s.fields.map(y=>ne({schema:y.type,structName:`${e}${re(y.name)}`})),u=s.fields.map((y,p)=>` ${y.name}: ${c[p].fieldType},`).join(`
|
|
45
45
|
`);return{variantLine:` Variant${o} {
|
|
46
46
|
${u}
|
|
47
|
-
}`,structs:
|
|
48
|
-
`);return
|
|
47
|
+
}`,structs:Xe(c)}}let a=ne({schema:s,structName:`${e}Variant${o}`});return{variantLine:` Variant${o}(${a.fieldType})`,structs:a.kind==="composite"?a.structs:[]}}),i=n.map(s=>s.variantLine).join(`,
|
|
48
|
+
`);return pe({fieldType:t,structs:[...n.flatMap(s=>s.structs),`${Ze}
|
|
49
49
|
pub enum ${t} {
|
|
50
50
|
${i}
|
|
51
|
-
}`]})}case"record":{let t=
|
|
51
|
+
}`]})}case"record":{let t=re(e),n=r.fields.map(s=>ne({schema:s.type,structName:`${e}${re(s.name)}`})),i=r.fields.map((s,o)=>{let a=n[o];return`${a.kind==="composite"?` #[json_data(nested)]
|
|
52
52
|
`:""} pub ${s.name}: ${a.fieldType},`}).join(`
|
|
53
|
-
`);return
|
|
53
|
+
`);return pe({fieldType:t,structs:[...Xe(n),`${Ze}
|
|
54
54
|
pub struct ${t} {
|
|
55
55
|
${i}
|
|
56
|
-
}`]})}}},
|
|
56
|
+
}`]})}}},Kr=({id:r,schema:e,isTopLevelOptional:t,suffix:n})=>{let i=`${re(r)}${n}`,o=ne({schema:t?{kind:"opt",inner:e}:e,structName:i});return o.kind==="composite"?{baseName:i,code:o.structs.join(`
|
|
57
57
|
|
|
58
|
-
`)}:{baseName:i,code:`pub type ${i} = ${o.fieldType};`}},
|
|
58
|
+
`)}:{baseName:i,code:`pub type ${i} = ${o.fieldType};`}},et=({id:r,schema:e,suffix:t})=>{let n=ae({zodSchema:e,id:r});return Kr({...n,suffix:t})};import{writeFile as cn}from"node:fs/promises";import{relative as un}from"node:path";import{nonNullish as Fe,notEmptyString as tr}from"@dfinity/utils";import{capitalize as Yr,convertCamelToSnake as Qr}from"@junobuild/utils";var Zr=`// This file was automatically generated by the Juno CLI.
|
|
59
59
|
// Any modifications may be overwritten.
|
|
60
60
|
#![allow(unused)]
|
|
61
61
|
#![allow(non_camel_case_types)]
|
|
@@ -71,50 +71,50 @@ use junobuild_shared::ic::UnwrapOrTrapResult;
|
|
|
71
71
|
use serde::{Deserialize, Serialize};
|
|
72
72
|
|
|
73
73
|
%FUNCTIONS%
|
|
74
|
-
`,
|
|
74
|
+
`,Xr=`#[ic_cdk::%TYPE%]
|
|
75
75
|
fn %RS_FUNCTION%() {
|
|
76
76
|
execute_sync_function::<NoArgs, NoResult>("%JS_FUNCTION%", None).unwrap_or_trap();
|
|
77
|
-
}`,
|
|
77
|
+
}`,en=`#[ic_cdk::%TYPE%]
|
|
78
78
|
fn %RS_FUNCTION%() -> %RESULT% {
|
|
79
79
|
execute_sync_function::<NoArgs, %RESULT%>("%JS_FUNCTION%", None).unwrap_or_trap_result()
|
|
80
|
-
}`,
|
|
80
|
+
}`,tn=`#[ic_cdk::%TYPE%]
|
|
81
81
|
fn %RS_FUNCTION%(args: %ARGS%) {
|
|
82
82
|
execute_sync_function::<%ARGS%, NoResult>("%JS_FUNCTION%", Some(args)).unwrap_or_trap();
|
|
83
|
-
}`,
|
|
83
|
+
}`,rn=`#[ic_cdk::%TYPE%]
|
|
84
84
|
fn %RS_FUNCTION%(args: %ARGS%) -> %RESULT% {
|
|
85
85
|
execute_sync_function("%JS_FUNCTION%", Some(args)).unwrap_or_trap_result()
|
|
86
|
-
}`,
|
|
86
|
+
}`,nn=`#[ic_cdk::%TYPE%]
|
|
87
87
|
async fn %RS_FUNCTION%() {
|
|
88
88
|
execute_async_function::<NoArgs, NoResult>("%JS_FUNCTION%", None)
|
|
89
89
|
.await
|
|
90
90
|
.unwrap_or_trap();
|
|
91
|
-
}`,
|
|
91
|
+
}`,sn=`#[ic_cdk::%TYPE%]
|
|
92
92
|
async fn %RS_FUNCTION%() -> %RESULT% {
|
|
93
93
|
execute_async_function::<NoArgs, %RESULT%>("%JS_FUNCTION%", None)
|
|
94
94
|
.await
|
|
95
95
|
.unwrap_or_trap_result()
|
|
96
|
-
}`,
|
|
96
|
+
}`,on=`#[ic_cdk::%TYPE%]
|
|
97
97
|
async fn %RS_FUNCTION%(args: %ARGS%) {
|
|
98
98
|
execute_async_function::<%ARGS%, NoResult>("%JS_FUNCTION%", Some(args))
|
|
99
99
|
.await
|
|
100
100
|
.unwrap_or_trap();
|
|
101
|
-
}`,
|
|
101
|
+
}`,an=`#[ic_cdk::%TYPE%]
|
|
102
102
|
async fn %RS_FUNCTION%(args: %ARGS%) -> %RESULT% {
|
|
103
103
|
execute_async_function("%JS_FUNCTION%", Some(args))
|
|
104
104
|
.await
|
|
105
105
|
.unwrap_or_trap_result()
|
|
106
|
-
}`,
|
|
106
|
+
}`,nr=({queries:r,updates:e})=>{let t=r.map(([s,o])=>rr({jsFnName:s,fn:o,fnType:"query"})).join(`
|
|
107
107
|
|
|
108
|
-
`),n=e.map(([s,o])=>
|
|
108
|
+
`),n=e.map(([s,o])=>rr({jsFnName:s,fn:o,fnType:"update"})).join(`
|
|
109
109
|
|
|
110
110
|
`),i=`${t}
|
|
111
111
|
|
|
112
|
-
${n}`.trim();return
|
|
112
|
+
${n}`.trim();return Zr.replace("%FUNCTIONS%",i)},rr=({fn:r,fnType:e,jsFnName:t})=>{let n=`${"App"}${Yr(t)}`,i="args"in r?et({id:n,schema:r.args,suffix:"Args"}):void 0,s="result"in r?et({id:n,schema:r.result,suffix:"Result"}):void 0,o=r.handler.constructor.name==="AsyncFunction",c=Fe(i)&&Fe(s)?o?an:rn:Fe(i)?o?on:tn:Fe(s)?o?sn:en:o?nn:Xr,u=`${"App".toLowerCase()}_${Qr(t)}`,y=c.replace("%TYPE%",e).replace("%RS_FUNCTION%",u).replace("%JS_FUNCTION%",t).replaceAll("%ARGS%",i?.baseName??"").replaceAll("%RESULT%",s?.baseName??"").trim(),p=i?.code??"",f=s?.code??"";return`${p}${tr(p)?`
|
|
113
113
|
|
|
114
|
-
`:""}${f}${
|
|
114
|
+
`:""}${f}${tr(f)?`
|
|
115
115
|
|
|
116
|
-
`:""}${y}`};var
|
|
117
|
-
`);let i=await import(`data:text/javascript;base64,${Buffer.from(r).toString("base64")}`),{QuerySchema:s,UpdateSchema:o}=await import("@junobuild/functions"),[a,c]=Object.entries(i).reduce(([y,p],f)=>{let[d,
|
|
116
|
+
`:""}${y}`};var Oi=async({code:r,outputFile:e})=>{let t=globalThis.console,n=globalThis.Math.random;try{globalThis.__ic_cdk_print=y=>process.stdout.write(`${y}
|
|
117
|
+
`);let i=await import(`data:text/javascript;base64,${Buffer.from(r).toString("base64")}`),{QuerySchema:s,UpdateSchema:o}=await import("@junobuild/functions"),[a,c]=Object.entries(i).reduce(([y,p],f)=>{let[d,b]=f,_=typeof b=="function"?b({}):b,E=s.safeParse(_),v=o.safeParse(_);return[[...y,...E.success?[[d,E.data]]:[]],[...p,...v.success?[[d,v.data]]:[]]]},[[],[]]);if(a.length===0&&c.length===0)return null;let u=nr({queries:a,updates:c});return await cn(e,u,"utf-8"),{outputPath:un(process.cwd(),e),totalQueries:a.length,totalUpdates:c.length}}finally{globalThis.console=t,globalThis.Math.random=n}};export{wn as generateApi,Oi as generateFunctions,Jn as zodToCandid,yi as zodToIdl,et as zodToRust};
|
|
118
118
|
/*! Bundled license information:
|
|
119
119
|
|
|
120
120
|
@noble/hashes/esm/utils.js:
|