@junobuild/functions-tools 0.5.1 → 0.5.2

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.
@@ -8,6 +8,7 @@ var Tr=Object.defineProperty;var Ar=(r=>typeof require<"u"?require:typeof Proxy<
8
8
  /* eslint-disable */
9
9
  /* prettier-ignore */
10
10
  %IMPORT%
11
+ // @ts-expect-error - generated JS file without type declarations
11
12
  import {idlFactory} from './satellite.factory.did.js';
12
13
  import {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';
13
14
 
@@ -31,7 +32,8 @@ import type {_SERVICE as SatelliteActor%IMPORTS%} from './satellite.did';
31
32
  import type { Principal } from '@icp-sdk/core/principal';`,lt=({methods:r,imports:e,transformerOptions:{coreLib:t,outputLanguage:n}})=>{let s=n==="js"?Gr:Jr,i=r.map(qr),o=i.map(c=>{let u=s;return Object.entries(c).map(([h,d])=>{u=u.replaceAll(`%${h}%`,d)}),u}).join(`
32
33
 
33
34
  `),a=Ae.replace("%FUNCTION_NAMESPACE%",Te).replace("%JS_FUNCTIONS%",i.map(({METHOD_NAME:c})=>c).join(`,
34
- `));return zr.replace("%CORE_LIB%",t??"core").replace("%METHODS%",o).replace("%NAMESPACE%",a).replace("%IMPORT%",n==="js"?"":Wr.replace("%IMPORTS%",e.length===0?"":`, ${e.join(", ")}`)).trim()},qr=({name:r,returnType:e,paramsType:t})=>{let s=(c=>c.replace(/_./g,u=>u[1].toUpperCase()))(r),i=t.map((c,u)=>({param:`value${u}`,type:c})),o=`${i.map(({param:c})=>c).join(", ")}`,a=i.map(({param:c,type:u})=>`${c}: ${u}`).join(", ");return{METHOD_NAME:s,DID_METHOD_NAME:r,METHOD_RESULT:e,PARAMS:a,CALL_PARAMS:o}};var ns=async({inputFile:r,outputFile:e,transformerOptions:t})=>{let n=await ut({inputFile:r}),s=lt({...n,transformerOptions:t});await Kr(e,s,"utf-8")};import{writeFile as nn}from"node:fs/promises";import{nonNullish as Ne}from"@dfinity/utils";import{capitalize as Xr,convertCamelToSnake as en}from"@junobuild/utils";import{capitalize as Zr}from"@junobuild/utils";import{ZodSchemaId as dt}from"@junobuild/schema";import*as ft from"zod";var Qr=r=>{if(r.some(i=>i.type!=="object"||i.properties===void 0))return null;let[e,...t]=r,n=e.properties;if(n===void 0)return null;let s=Object.entries(n).find(([i,o])=>typeof o!="boolean"&&o.const!==void 0)?.[0];return s===void 0?null:t.every(i=>i.properties?.[s]!==void 0&&typeof i.properties[s]!="boolean"&&i.properties[s].const!==void 0)?s:null},W=({id:r,zodSchema:e})=>{let t=e.toJSONSchema({unrepresentable:"any",override:i=>{i.zodSchema._zod.def.type==="bigint"&&(i.jsonSchema.type="integer",i.jsonSchema.format="bigint"),i.jsonSchema.id===dt.Principal&&(i.jsonSchema.format="principal"),i.jsonSchema.id===dt.Uint8Array&&(i.jsonSchema.format="uint8array")}}),n=U({schema:t,rootDefs:t.$defs??{}}),s=e._zod.def.type==="optional"&&!("innerType"in e._zod.def&&e._zod.def.innerType instanceof ft.ZodNullable);return{id:r,schema:n,isTopLevelOptional:s}},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(([s,i])=>typeof i=="boolean"))throw new Error("Boolean schema not supported.");return{kind:"record",fields:n.map(([s,i])=>{let o=U({schema:i,rootDefs:e});return{name:s,type:t.has(s)?o:{kind:"opt",inner:o}}})}}}if(r.oneOf!==void 0){let t=r.oneOf.filter(({type:s})=>s!=="null");if(t.length===1)return{kind:"opt",inner:U({schema:t[0],rootDefs:e})};let n=Qr(t);if(n!==null)return{kind:"discriminatedUnion",discriminator:n,members:t.map(s=>U({schema:s,rootDefs:e}))};throw new Error("z.union of objects is not supported. Use z.discriminatedUnion instead.")}if(r.anyOf!==void 0){let t=r.anyOf.filter(i=>typeof i!="boolean");if(t.filter(i=>Object.keys(i).length===0).length>0)throw new Error("Unrepresentable type in union");if(t.every(i=>i.const!==void 0))return{kind:"variant",tags:t.map(i=>String(i.const))};let s=t.filter(i=>i.type!=="null");if(s.length===1)return{kind:"opt",inner:U({schema:s[0],rootDefs:e})};throw new Error("z.union of objects is not supported. Use z.discriminatedUnion instead.")}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 s=new Set(n.required??[]);return Object.entries(n.properties??{}).map(([i,o])=>{let a=U({schema:o,rootDefs:e});return{name:i,type:s.has(i)?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 ae=r=>{switch(r.kind){case"text":return"j.string()";case"bool":return"j.boolean()";case"float64":return"j.number()";case"int32":return"j.int()";case"nat":return"j.bigint()";case"principal":return"j.principal()";case"uint8array":return"j.uint8Array()";case"opt":return`j.optional(${ae(r.inner)})`;case"vec":return`j.array(${ae(r.inner)})`;case"tuple":case"indexedTuple":return`j.tuple([${r.members.map(ae).join(", ")}])`;case"record":return`j.strictObject({${r.fields.map(e=>`${e.name}: ${ae(e.type)}`).join(", ")}})`;case"variant":return`j.enum([${r.tags.map(e=>`'${e}'`).join(", ")}])`;case"discriminatedUnion":return`j.discriminatedUnion('${r.discriminator}', [${r.members.map(ae).join(", ")}])`}},Yr=({id:r,schema:e,isTopLevelOptional:t,suffix:n})=>{let s=`${Zr(r)}${n}`,o=ae(t?{kind:"opt",inner:e}:e);return{baseName:s,code:`const ${s}Schema = ${o};`}},He=({id:r,schema:e,suffix:t})=>{let n=W({zodSchema:e,id:r});return Yr({...n,suffix:t})};var pt=`import {idlFactory} from './satellite.factory.did.js';
35
+ `));return zr.replace("%CORE_LIB%",t??"core").replace("%METHODS%",o).replace("%NAMESPACE%",a).replace("%IMPORT%",n==="js"?"":Wr.replace("%IMPORTS%",e.length===0?"":`, ${e.join(", ")}`)).trim()},qr=({name:r,returnType:e,paramsType:t})=>{let s=(c=>c.replace(/_./g,u=>u[1].toUpperCase()))(r),i=t.map((c,u)=>({param:`value${u}`,type:c})),o=`${i.map(({param:c})=>c).join(", ")}`,a=i.map(({param:c,type:u})=>`${c}: ${u}`).join(", ");return{METHOD_NAME:s,DID_METHOD_NAME:r,METHOD_RESULT:e,PARAMS:a,CALL_PARAMS:o}};var ns=async({inputFile:r,outputFile:e,transformerOptions:t})=>{let n=await ut({inputFile:r}),s=lt({...n,transformerOptions:t});await Kr(e,s,"utf-8")};import{writeFile as nn}from"node:fs/promises";import{nonNullish as Ne}from"@dfinity/utils";import{capitalize as Xr,convertCamelToSnake as en}from"@junobuild/utils";import{capitalize as Zr}from"@junobuild/utils";import{ZodSchemaId as dt}from"@junobuild/schema";import*as ft from"zod";var Qr=r=>{if(r.some(i=>i.type!=="object"||i.properties===void 0))return null;let[e,...t]=r,n=e.properties;if(n===void 0)return null;let s=Object.entries(n).find(([i,o])=>typeof o!="boolean"&&o.const!==void 0)?.[0];return s===void 0?null:t.every(i=>i.properties?.[s]!==void 0&&typeof i.properties[s]!="boolean"&&i.properties[s].const!==void 0)?s:null},W=({id:r,zodSchema:e})=>{let t=e.toJSONSchema({unrepresentable:"any",override:i=>{i.zodSchema._zod.def.type==="bigint"&&(i.jsonSchema.type="integer",i.jsonSchema.format="bigint"),i.jsonSchema.id===dt.Principal&&(i.jsonSchema.format="principal"),i.jsonSchema.id===dt.Uint8Array&&(i.jsonSchema.format="uint8array")}}),n=U({schema:t,rootDefs:t.$defs??{}}),s=e._zod.def.type==="optional"&&!("innerType"in e._zod.def&&e._zod.def.innerType instanceof ft.ZodNullable);return{id:r,schema:n,isTopLevelOptional:s}},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(([s,i])=>typeof i=="boolean"))throw new Error("Boolean schema not supported.");return{kind:"record",fields:n.map(([s,i])=>{let o=U({schema:i,rootDefs:e});return{name:s,type:t.has(s)?o:{kind:"opt",inner:o}}})}}}if(r.oneOf!==void 0){let t=r.oneOf.filter(({type:s})=>s!=="null");if(t.length===1)return{kind:"opt",inner:U({schema:t[0],rootDefs:e})};let n=Qr(t);if(n!==null)return{kind:"discriminatedUnion",discriminator:n,members:t.map(s=>U({schema:s,rootDefs:e}))};throw new Error("z.union of objects is not supported. Use z.discriminatedUnion instead.")}if(r.anyOf!==void 0){let t=r.anyOf.filter(i=>typeof i!="boolean");if(t.filter(i=>Object.keys(i).length===0).length>0)throw new Error("Unrepresentable type in union");if(t.every(i=>i.const!==void 0))return{kind:"variant",tags:t.map(i=>String(i.const))};let s=t.filter(i=>i.type!=="null");if(s.length===1)return{kind:"opt",inner:U({schema:s[0],rootDefs:e})};throw new Error("z.union of objects is not supported. Use z.discriminatedUnion instead.")}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 s=new Set(n.required??[]);return Object.entries(n.properties??{}).map(([i,o])=>{let a=U({schema:o,rootDefs:e});return{name:i,type:s.has(i)?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 ae=r=>{switch(r.kind){case"text":return"j.string()";case"bool":return"j.boolean()";case"float64":return"j.number()";case"int32":return"j.int()";case"nat":return"j.bigint()";case"principal":return"j.principal()";case"uint8array":return"j.uint8Array()";case"opt":return`j.optional(${ae(r.inner)})`;case"vec":return`j.array(${ae(r.inner)})`;case"tuple":case"indexedTuple":return`j.tuple([${r.members.map(ae).join(", ")}])`;case"record":return`j.strictObject({${r.fields.map(e=>`${e.name}: ${ae(e.type)}`).join(", ")}})`;case"variant":return`j.enum([${r.tags.map(e=>`'${e}'`).join(", ")}])`;case"discriminatedUnion":return`j.discriminatedUnion('${r.discriminator}', [${r.members.map(ae).join(", ")}])`}},Yr=({id:r,schema:e,isTopLevelOptional:t,suffix:n})=>{let s=`${Zr(r)}${n}`,o=ae(t?{kind:"opt",inner:e}:e);return{baseName:s,code:`const ${s}Schema = ${o};`}},He=({id:r,schema:e,suffix:t})=>{let n=W({zodSchema:e,id:r});return Yr({...n,suffix:t})};var pt=`// @ts-expect-error - generated JS file without type declarations
36
+ import {idlFactory} from './satellite.factory.did.js';
35
37
  import {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';
36
38
  import {schemaToIdl, schemaFromIdl} from '@junobuild/schema/utils';
37
39
  import {j} from '@junobuild/schema';`,ht=`
@@ -70,6 +72,7 @@ const %JS_FUNCTION% = async () => {
70
72
  const {%RS_FUNCTION%} = await getSatelliteExtendedActor({idlFactory});
71
73
  await %RS_FUNCTION%();
72
74
  };`;var xt=`import type {_SERVICE as SatelliteActor} from './satellite.did';
75
+ // @ts-expect-error - generated JS file without type declarations
73
76
  import {idlFactory} from './satellite.factory.did.js';
74
77
  import {getSatelliteExtendedActor} from '@junobuild/%CORE_LIB%';
75
78
  import {schemaToIdl, schemaFromIdl} from '@junobuild/schema/utils';