@junobuild/functions 0.7.2 → 0.8.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.
Files changed (120) hide show
  1. package/README.md +399 -223
  2. package/canisters/ckbtc/index.js +1 -1
  3. package/canisters/cketh/index.js +1 -1
  4. package/canisters/cmc/index.js +1 -1
  5. package/canisters/declarations/ckbtc/bitcoin.did.d.ts +1 -1
  6. package/canisters/declarations/ckbtc/minter.did.d.ts +1 -1
  7. package/canisters/declarations/cketh/minter.did.d.ts +1 -1
  8. package/canisters/declarations/cketh/orchestrator.did.d.ts +1 -1
  9. package/canisters/declarations/cmc/cmc.did.d.ts +1 -1
  10. package/canisters/declarations/ic-management/ic-management.did.d.ts +1 -1
  11. package/canisters/declarations/ledger-icp/index.did.d.ts +1 -1
  12. package/canisters/declarations/ledger-icp/ledger.did.d.ts +1 -1
  13. package/canisters/declarations/ledger-icrc/icrc_icrc-1.did.d.ts +1 -1
  14. package/canisters/declarations/ledger-icrc/icrc_icrc-10.did.d.ts +1 -1
  15. package/canisters/declarations/ledger-icrc/icrc_index.did.d.ts +1 -1
  16. package/canisters/declarations/ledger-icrc/icrc_ledger.did.d.ts +1 -1
  17. package/canisters/declarations/ledger-icrc/icrc_nft-ledger.did.d.ts +1 -1
  18. package/canisters/declarations/nns/genesis_token.did.d.ts +1 -1
  19. package/canisters/declarations/nns/governance.did.d.ts +1 -1
  20. package/canisters/declarations/nns/governance_test.did.d.ts +1 -1
  21. package/canisters/declarations/nns/sns_wasm.did.d.ts +1 -1
  22. package/canisters/declarations/sns/governance.did.d.ts +1 -1
  23. package/canisters/declarations/sns/governance_test.did.d.ts +1 -1
  24. package/canisters/declarations/sns/root.did.d.ts +1 -1
  25. package/canisters/declarations/sns/swap.did.d.ts +1 -1
  26. package/canisters/ic-management/index.js +1 -1
  27. package/canisters/index.js +1 -1
  28. package/canisters/ledger/icp/index.js +1 -1
  29. package/canisters/ledger/icrc/index.js +1 -1
  30. package/canisters/nns/index.js +1 -1
  31. package/canisters/sns/index.js +1 -1
  32. package/{chunk-CAQXR2VB.js → chunk-I4MVAQHI.js} +1 -1
  33. package/{chunk-CAQXR2VB.js.map → chunk-I4MVAQHI.js.map} +1 -1
  34. package/chunk-JU5CZHLY.js +2 -0
  35. package/chunk-JU5CZHLY.js.map +7 -0
  36. package/chunk-VIFVPVUD.js +2 -0
  37. package/chunk-VIFVPVUD.js.map +7 -0
  38. package/chunk-X3EF7OU6.js +2 -0
  39. package/chunk-X3EF7OU6.js.map +7 -0
  40. package/chunk-YHNBR22R.js +2 -0
  41. package/chunk-YHNBR22R.js.map +7 -0
  42. package/chunk-ZBCLFWQJ.js +2 -0
  43. package/chunk-ZBCLFWQJ.js.map +7 -0
  44. package/functions/query.d.ts +8 -0
  45. package/functions/schemas/function.d.ts +27 -0
  46. package/functions/update.d.ts +8 -0
  47. package/global.d.ts +15 -6
  48. package/ic-cdk/http-request.ic-cdk.d.ts +10 -0
  49. package/ic-cdk/schemas/call.d.ts +1 -1
  50. package/ic-cdk/schemas/http-request.d.ts +142 -0
  51. package/ic-cdk.d.ts +2 -0
  52. package/ic-cdk.js +1 -1
  53. package/ic-cdk.js.map +4 -4
  54. package/index.d.ts +1 -1
  55. package/index.js +1 -1
  56. package/index.js.map +3 -3
  57. package/package.json +3 -3
  58. package/schemas/principal.d.ts +8 -0
  59. package/schemas/satellite.d.ts +1 -1
  60. package/sdk/access-keys.sdk.d.ts +50 -0
  61. package/sdk/guards.sdk.d.ts +25 -0
  62. package/sdk/schemas/{controllers.d.ts → access-keys.d.ts} +39 -38
  63. package/sdk.d.ts +3 -2
  64. package/sdk.js +1 -1
  65. package/sdk.js.map +4 -4
  66. package/src/canisters/declarations/ckbtc/bitcoin.did.d.ts +1 -1
  67. package/src/canisters/declarations/ckbtc/bitcoin.did.idl.js +1 -1
  68. package/src/canisters/declarations/ckbtc/minter.did.d.ts +1 -1
  69. package/src/canisters/declarations/ckbtc/minter.did.idl.js +1 -1
  70. package/src/canisters/declarations/cketh/minter.did.d.ts +1 -1
  71. package/src/canisters/declarations/cketh/minter.did.idl.js +1 -1
  72. package/src/canisters/declarations/cketh/orchestrator.did.d.ts +1 -1
  73. package/src/canisters/declarations/cketh/orchestrator.did.idl.js +1 -1
  74. package/src/canisters/declarations/cmc/cmc.did.d.ts +1 -1
  75. package/src/canisters/declarations/cmc/cmc.did.idl.js +1 -1
  76. package/src/canisters/declarations/ic-management/ic-management.did.d.ts +1 -1
  77. package/src/canisters/declarations/ic-management/ic-management.did.idl.js +1 -1
  78. package/src/canisters/declarations/ledger-icp/index.did.d.ts +1 -1
  79. package/src/canisters/declarations/ledger-icp/index.did.idl.js +1 -1
  80. package/src/canisters/declarations/ledger-icp/ledger.did.d.ts +1 -1
  81. package/src/canisters/declarations/ledger-icp/ledger.did.idl.js +1 -1
  82. package/src/canisters/declarations/ledger-icrc/icrc_icrc-1.did.d.ts +1 -1
  83. package/src/canisters/declarations/ledger-icrc/icrc_icrc-1.did.idl.js +1 -1
  84. package/src/canisters/declarations/ledger-icrc/icrc_icrc-10.did.d.ts +1 -1
  85. package/src/canisters/declarations/ledger-icrc/icrc_icrc-10.did.idl.js +1 -1
  86. package/src/canisters/declarations/ledger-icrc/icrc_index.did.d.ts +1 -1
  87. package/src/canisters/declarations/ledger-icrc/icrc_index.did.idl.js +1 -1
  88. package/src/canisters/declarations/ledger-icrc/icrc_ledger.did.d.ts +1 -1
  89. package/src/canisters/declarations/ledger-icrc/icrc_ledger.did.idl.js +1 -1
  90. package/src/canisters/declarations/ledger-icrc/icrc_nft-ledger.did.d.ts +1 -1
  91. package/src/canisters/declarations/ledger-icrc/icrc_nft-ledger.did.idl.js +1 -1
  92. package/src/canisters/declarations/nns/genesis_token.did.d.ts +1 -1
  93. package/src/canisters/declarations/nns/genesis_token.did.idl.js +1 -1
  94. package/src/canisters/declarations/nns/governance.did.d.ts +1 -1
  95. package/src/canisters/declarations/nns/governance.did.idl.js +1 -1
  96. package/src/canisters/declarations/nns/governance_test.did.d.ts +1 -1
  97. package/src/canisters/declarations/nns/governance_test.did.idl.js +1 -1
  98. package/src/canisters/declarations/nns/sns_wasm.did.d.ts +1 -1
  99. package/src/canisters/declarations/nns/sns_wasm.did.idl.js +1 -1
  100. package/src/canisters/declarations/sns/governance.did.d.ts +1 -1
  101. package/src/canisters/declarations/sns/governance.did.idl.js +1 -1
  102. package/src/canisters/declarations/sns/governance_test.did.d.ts +1 -1
  103. package/src/canisters/declarations/sns/governance_test.did.idl.js +1 -1
  104. package/src/canisters/declarations/sns/root.did.d.ts +1 -1
  105. package/src/canisters/declarations/sns/root.did.idl.js +1 -1
  106. package/src/canisters/declarations/sns/swap.did.d.ts +1 -1
  107. package/src/canisters/declarations/sns/swap.did.idl.js +1 -1
  108. package/src/global.d.ts +15 -6
  109. package/chunk-3CCXJJ4Y.js +0 -2
  110. package/chunk-3CCXJJ4Y.js.map +0 -7
  111. package/chunk-5IWIJYKG.js +0 -2
  112. package/chunk-5IWIJYKG.js.map +0 -7
  113. package/chunk-6QTAU2M5.js +0 -2
  114. package/chunk-6QTAU2M5.js.map +0 -7
  115. package/chunk-BAYP4XBH.js +0 -2
  116. package/chunk-BAYP4XBH.js.map +0 -7
  117. package/chunk-EHQF2DOU.js +0 -2
  118. package/chunk-EHQF2DOU.js.map +0 -7
  119. package/schemas/candid.d.ts +0 -21
  120. package/sdk/controllers.sdk.d.ts +0 -39
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{A as Xe,B as $e,C as et,D as tt,E as W,F as Q,a as _e,b as ve,c as I,d as Ee,e as J,f as K,g as We,h as Qe,i as u,j as Ne,k as q,l as G,m as Me,n as Pe,o as Be,p as Ye,q as m,r as Ie,s as L,t as V,u as Je,v as Ke,w as qe,x as Ge,y as Le,z as Ve}from"./chunk-5IWIJYKG.js";import{a as je,b as we,c as He}from"./chunk-3CCXJJ4Y.js";import"./chunk-4C666HHU.js";import*as s from"zod";import*as O from"zod";var d=O.record(O.string(),O.string());import*as X from"zod";var n=e=>X.custom(o=>typeof o=="function"&&e.implement(o));var i={QUERY:"__juno_function_query",UPDATE:"__juno_function_update"};import*as t from"zod";var U=t.strictObject({type:t.enum([i.QUERY,i.UPDATE])}),C=t.strictObject({...U.shape,args:t.instanceof(t.ZodObject),result:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([t.unknown()]),output:t.union([t.unknown(),t.promise(t.unknown())])}))}),R=t.strictObject({...U.shape,args:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([t.unknown()]),output:t.union([t.void(),t.promise(t.void())])}))}),F=t.strictObject({...U.shape,result:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([]),output:t.union([t.unknown(),t.promise(t.unknown())])}))}),g=t.strictObject({...U.shape,handler:n(t.function({input:t.tuple([]),output:t.union([t.void(),t.promise(t.void())])}))}),ct=t.union([C,R,F,g]);var Z=s.strictObject({type:s.literal(i.QUERY)}),k=s.union([s.strictObject({...C.shape,...Z.shape}),s.strictObject({...R.shape,...Z.shape}),s.strictObject({...F.shape,...Z.shape}),s.strictObject({...g.shape,...Z.shape})]),he=e=>s.function({input:s.tuple([d]),output:e}),dt=e=>s.union([e,n(he(e))]);function xt(e){if(typeof e=="function")return a=>{let x={...e(a),type:i.QUERY};return k.parse(x),x};let o={...e,type:i.QUERY};return k.parse(o),o}import*as r from"zod";var b=r.strictObject({type:r.literal(i.UPDATE)}),j=r.union([r.strictObject({...C.shape,...b.shape}),r.strictObject({...R.shape,...b.shape}),r.strictObject({...F.shape,...b.shape}),r.strictObject({...g.shape,...b.shape})]),Te=e=>r.function({input:r.tuple([d]),output:e}),zt=e=>r.union([e,n(Te(e))]);function Dt(e){if(typeof e=="function")return a=>{let x={...e(a),type:i.UPDATE};return j.parse(x),x};let o={...e,type:i.UPDATE};return j.parse(o),o}import*as T from"zod";import*as z from"zod";var w=z.object({collections:z.array(z.string()).readonly()}).strict();import*as c from"zod";var p=e=>c.strictObject({caller:I,data:e}),$=e=>n(c.function({input:c.tuple([e]),output:c.void()})),ee=e=>n(c.function({input:c.tuple([e]),output:c.promise(c.void()).or(c.void())}));import*as D from"zod";import*as H from"zod";var N=H.object({before:u.optional(),after:u}).strict(),te=H.object({current:u.optional(),proposed:q}).strict(),oe=H.object({current:u.optional(),proposed:G}).strict();var h=e=>D.strictObject({collection:J,key:K,data:e}),ne=p(h(N)),se=p(D.array(h(N))),M=p(h(u.optional())),P=p(D.array(h(u.optional()))),B=p(D.array(h(u.optional()))),re=p(h(te)),pe=p(h(oe));import*as Y from"zod";import*as ce from"zod";var ae=ce.object({current:m.optional(),batch:L,commit_batch:V}).strict();var ie=p(m),ue=p(m.optional()),le=p(Y.array(m.optional())),me=p(Y.array(m.optional())),de=p(ae),xe=p(m);var _=e=>w.extend({assert:$(e)}).strict(),ye=_(re),Se=_(pe),ze=_(de),De=_(xe),Jt=T.union([ye,Se,ze,De]),fe=e=>T.function({input:T.tuple([d]),output:e}),Kt=e=>T.union([e,n(fe(e))]);function qt(e){return e}import*as y from"zod";var l=e=>w.extend({run:ee(e)}).strict(),Oe=l(ne),Ce=l(se),oo=l(M),no=l(P),so=l(B),Re=l(ie),Fe=l(ue),ge=l(le),Ue=l(me),ro=y.union([Oe,Ce,M,P,B,Re,Fe,ge,Ue]),Ze=e=>y.function({input:y.tuple([d]),output:e}),po=e=>y.union([e,n(Ze(e))]);function co(e){return e}import{nonNullish as f}from"@dfinity/utils";import*as S from"zod";var Ae=S.union([k,j]);globalThis.__juno_satellite_fn_invoke_sync=(e,o)=>{Ae.parse(e);let a="args"in e&&e.args instanceof S.ZodType?e.args?.parse(f(o)?W(o):void 0):void 0,E=f(a)?e.handler(a):e.handler(),A="result"in e&&e.result instanceof S.ZodType?e.result?.parse(E):void 0;globalThis.jsResult=f(A)?Q(A):A};globalThis.__juno_satellite_fn_invoke_async=async(e,o)=>{Ae.parse(e);let a="args"in e&&e.args instanceof S.ZodType?e.args?.parse(f(o)?W(o):void 0):void 0,E=await(async()=>f(a)?await e.handler(a):await e.handler())(),A="result"in e&&e.result instanceof S.ZodType?e.result?.parse(E):void 0;globalThis.jsResult=f(A)?Q(A):A};import{jsonReplacer as ke}from"@dfinity/utils";var v=e=>{let o=e.map(a=>typeof a=="object"?JSON.stringify(a,ke):a).join(" ");globalThis.__ic_cdk_print(o)};globalThis.console={info(...e){v(e)},log(...e){v(e)},warn(...e){v(e)},error(...e){v(e)}};var be=()=>(__juno_satellite_random()>>>0)/4294967296;globalThis.Math.random=be;export{xe as AssertDeleteAssetContextSchema,De as AssertDeleteAssetSchema,pe as AssertDeleteDocContextSchema,Se as AssertDeleteDocSchema,Kt as AssertFnOrObjectSchema,fe as AssertFnSchema,$ as AssertFunctionSchema,Jt as AssertSchema,re as AssertSetDocContextSchema,ye as AssertSetDocSchema,de as AssertUploadAssetContextSchema,ze as AssertUploadAssetSchema,Ke as AssetAccessTokenSchema,ae as AssetAssertUploadSchema,Ye as AssetEncodingSchema,Be as AssetKeySchema,Ie as AssetNoContentSchema,m as AssetSchema,L as BatchSchema,Pe as BlobSchema,J as CollectionSchema,w as CollectionsSchema,V as CommitBatchSchema,ct as CustomFunctionSchema,C as CustomFunctionWithArgsAndResultSchema,R as CustomFunctionWithArgsSchema,F as CustomFunctionWithResultSchema,g as CustomFunctionWithoutArgsAndResultSchema,G as DelDocSchema,We as DescriptionSchema,oe as DocAssertDeleteSchema,te as DocAssertSetSchema,h as DocContextSchema,u as DocSchema,N as DocUpsertSchema,Je as FullPathSchema,Me as HeaderFieldsSchema,p as HookContextSchema,po as HookFnOrObjectSchema,Ze as HookFnSchema,ro as HookSchema,K as KeySchema,Le as ListMatcherSchema,Xe as ListOrderFieldSchema,$e as ListOrderSchema,Ve as ListPaginateSchema,et as ListParamsSchema,ue as OnDeleteAssetContextSchema,Fe as OnDeleteAssetSchema,M as OnDeleteDocContextSchema,oo as OnDeleteDocSchema,me as OnDeleteFilteredAssetsContextSchema,Ue as OnDeleteFilteredAssetsSchema,B as OnDeleteFilteredDocsContextSchema,so as OnDeleteFilteredDocsSchema,le as OnDeleteManyAssetsContextSchema,ge as OnDeleteManyAssetsSchema,P as OnDeleteManyDocsContextSchema,no as OnDeleteManyDocsSchema,ne as OnSetDocContextSchema,Oe as OnSetDocSchema,se as OnSetManyDocsContextSchema,Ce as OnSetManyDocsSchema,ie as OnUploadAssetContextSchema,Re as OnUploadAssetSchema,qe as OptionAssetSchema,Ne as OptionDocSchema,He as PrincipalSchema,dt as QueryFnOrObjectSchema,he as QueryFnSchema,k as QuerySchema,Qe as RawDataSchema,we as RawPrincipalSchema,I as RawUserIdSchema,ee as RunFunctionSchema,d as SatelliteEnvSchema,q as SetDocSchema,Ge as TimestampMatcherSchema,_e as TimestampSchema,je as Uint8ArraySchema,zt as UpdateFnOrObjectSchema,Te as UpdateFnSchema,j as UpdateSchema,Ee as UserIdSchema,ve as VersionSchema,tt as createListResultsSchema,qt as defineAssert,co as defineHook,xt as defineQuery,Dt as defineUpdate};
1
+ import{A as $e,B as et,C as tt,D as ot,E as Q,F as N,a as ve,b as Ee,c as K,d as We,e as q,f as L,g as Qe,h as Ne,i as u,j as Me,k as V,l as X,m as Pe,n as Be,o as Ye,p as Ie,q as d,r as Je,s as $,t as ee,u as Ge,v as Ke,w as qe,x as Le,y as Ve,z as Xe}from"./chunk-VIFVPVUD.js";import{a as He}from"./chunk-JU5CZHLY.js";import"./chunk-4C666HHU.js";import*as s from"zod";import*as O from"zod";var x=O.record(O.string(),O.string());import*as te from"zod";var n=e=>te.custom(o=>typeof o=="function"&&e.implement(o));var i={QUERY:"__juno_function_query",UPDATE:"__juno_function_update"};import*as t from"zod";var U=t.strictObject({type:t.enum([i.QUERY,i.UPDATE])}),M=n(t.function({output:t.void()})),Z=t.strictObject({guard:M.optional(),hidden:t.boolean().optional()}),C=t.strictObject({...U.shape,...Z.shape,args:t.instanceof(t.ZodObject),result:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([t.unknown()]),output:t.union([t.unknown(),t.promise(t.unknown())])}))}),R=t.strictObject({...U.shape,...Z.shape,args:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([t.unknown()]),output:t.union([t.void(),t.promise(t.void())])}))}),F=t.strictObject({...U.shape,...Z.shape,result:t.instanceof(t.ZodObject),handler:n(t.function({input:t.tuple([]),output:t.union([t.unknown(),t.promise(t.unknown())])}))}),g=t.strictObject({...U.shape,...Z.shape,handler:n(t.function({input:t.tuple([]),output:t.union([t.void(),t.promise(t.void())])}))}),at=t.union([C,R,F,g]);var b=s.strictObject({type:s.literal(i.QUERY)}),k=s.union([s.strictObject({...C.shape,...b.shape}),s.strictObject({...R.shape,...b.shape}),s.strictObject({...F.shape,...b.shape}),s.strictObject({...g.shape,...b.shape})]),ye=e=>s.function({input:s.tuple([x]),output:e}),xt=e=>s.union([e,n(ye(e))]);function ht(e){if(typeof e=="function")return a=>{let h={...e(a),type:i.QUERY};return k.parse(h),h};let o={...e,type:i.QUERY};return k.parse(o),o}import*as r from"zod";var j=r.strictObject({type:r.literal(i.UPDATE)}),w=r.union([r.strictObject({...C.shape,...j.shape}),r.strictObject({...R.shape,...j.shape}),r.strictObject({...F.shape,...j.shape}),r.strictObject({...g.shape,...j.shape})]),Se=e=>r.function({input:r.tuple([x]),output:e}),ft=e=>r.union([e,n(Se(e))]);function Dt(e){if(typeof e=="function")return a=>{let h={...e(a),type:i.UPDATE};return w.parse(h),h};let o={...e,type:i.UPDATE};return w.parse(o),o}import*as y from"zod";import*as z from"zod";var _=z.object({collections:z.array(z.string()).readonly()}).strict();import*as p from"zod";var c=e=>p.strictObject({caller:K,data:e}),oe=e=>n(p.function({input:p.tuple([e]),output:p.void()})),ne=e=>n(p.function({input:p.tuple([e]),output:p.promise(p.void()).or(p.void())}));import*as f from"zod";import*as H from"zod";var P=H.object({before:u.optional(),after:u}).strict(),se=H.object({current:u.optional(),proposed:V}).strict(),re=H.object({current:u.optional(),proposed:X}).strict();var T=e=>f.strictObject({collection:q,key:L,data:e}),ce=c(T(P)),pe=c(f.array(T(P))),B=c(T(u.optional())),Y=c(f.array(T(u.optional()))),I=c(f.array(T(u.optional()))),ae=c(T(se)),ie=c(T(re));import*as J from"zod";import*as ue from"zod";var le=ue.object({current:d.optional(),batch:$,commit_batch:ee}).strict();var me=c(d),de=c(d.optional()),xe=c(J.array(d.optional())),he=c(J.array(d.optional())),Ae=c(le),Te=c(d);var v=e=>_.extend({assert:oe(e)}).strict(),ze=v(ae),fe=v(ie),De=v(Ae),Oe=v(Te),Gt=y.union([ze,fe,De,Oe]),Ce=e=>y.function({input:y.tuple([x]),output:e}),Kt=e=>y.union([e,n(Ce(e))]);function qt(e){return e}import*as S from"zod";var l=e=>_.extend({run:ne(e)}).strict(),Re=l(ce),Fe=l(pe),no=l(B),so=l(Y),ro=l(I),ge=l(me),Ue=l(de),Ze=l(xe),be=l(he),co=S.union([Re,Fe,B,Y,I,ge,Ue,Ze,be]),ke=e=>S.function({input:S.tuple([x]),output:e}),po=e=>S.union([e,n(ke(e))]);function ao(e){return e}import{nonNullish as D}from"@junobuild/utils";import*as m from"zod";var G=m.union([k,w]),je=G.and(m.strictObject({guard:M}));globalThis.__juno_satellite_fn_guard_sync=e=>{je.parse(e).guard()};globalThis.__juno_satellite_fn_invoke_sync=(e,o)=>{G.parse(e);let a="args"in e&&e.args instanceof m.ZodType?e.args?.parse(D(o)?Q(o):void 0):void 0,W=D(a)?e.handler(a):e.handler(),A="result"in e&&e.result instanceof m.ZodType?e.result?.parse(W):void 0;globalThis.jsResult=D(A)?N(A):A};globalThis.__juno_satellite_fn_invoke_async=async(e,o)=>{G.parse(e);let a="args"in e&&e.args instanceof m.ZodType?e.args?.parse(D(o)?Q(o):void 0):void 0,W=await(async()=>D(a)?await e.handler(a):await e.handler())(),A="result"in e&&e.result instanceof m.ZodType?e.result?.parse(W):void 0;globalThis.jsResult=D(A)?N(A):A};import{jsonReplacer as we}from"@junobuild/utils";var E=e=>{let o=e.map(a=>typeof a=="object"?JSON.stringify(a,we):a).join(" ");globalThis.__ic_cdk_print(o)};globalThis.console={info(...e){E(e)},log(...e){E(e)},warn(...e){E(e)},error(...e){E(e)}};var _e=()=>(__juno_satellite_random()>>>0)/4294967296;globalThis.Math.random=_e;export{Te as AssertDeleteAssetContextSchema,Oe as AssertDeleteAssetSchema,ie as AssertDeleteDocContextSchema,fe as AssertDeleteDocSchema,Kt as AssertFnOrObjectSchema,Ce as AssertFnSchema,oe as AssertFunctionSchema,Gt as AssertSchema,ae as AssertSetDocContextSchema,ze as AssertSetDocSchema,Ae as AssertUploadAssetContextSchema,De as AssertUploadAssetSchema,Ke as AssetAccessTokenSchema,le as AssetAssertUploadSchema,Ie as AssetEncodingSchema,Ye as AssetKeySchema,Je as AssetNoContentSchema,d as AssetSchema,$ as BatchSchema,Be as BlobSchema,q as CollectionSchema,_ as CollectionsSchema,ee as CommitBatchSchema,M as CustomFunctionGuardSchema,at as CustomFunctionSchema,C as CustomFunctionWithArgsAndResultSchema,R as CustomFunctionWithArgsSchema,F as CustomFunctionWithResultSchema,g as CustomFunctionWithoutArgsAndResultSchema,X as DelDocSchema,Qe as DescriptionSchema,re as DocAssertDeleteSchema,se as DocAssertSetSchema,T as DocContextSchema,u as DocSchema,P as DocUpsertSchema,Ge as FullPathSchema,Pe as HeaderFieldsSchema,c as HookContextSchema,po as HookFnOrObjectSchema,ke as HookFnSchema,co as HookSchema,L as KeySchema,Ve as ListMatcherSchema,$e as ListOrderFieldSchema,et as ListOrderSchema,Xe as ListPaginateSchema,tt as ListParamsSchema,de as OnDeleteAssetContextSchema,Ue as OnDeleteAssetSchema,B as OnDeleteDocContextSchema,no as OnDeleteDocSchema,he as OnDeleteFilteredAssetsContextSchema,be as OnDeleteFilteredAssetsSchema,I as OnDeleteFilteredDocsContextSchema,ro as OnDeleteFilteredDocsSchema,xe as OnDeleteManyAssetsContextSchema,Ze as OnDeleteManyAssetsSchema,Y as OnDeleteManyDocsContextSchema,so as OnDeleteManyDocsSchema,ce as OnSetDocContextSchema,Re as OnSetDocSchema,pe as OnSetManyDocsContextSchema,Fe as OnSetManyDocsSchema,me as OnUploadAssetContextSchema,ge as OnUploadAssetSchema,qe as OptionAssetSchema,Me as OptionDocSchema,xt as QueryFnOrObjectSchema,ye as QueryFnSchema,k as QuerySchema,Ne as RawDataSchema,He as RawPrincipalSchema,K as RawUserIdSchema,ne as RunFunctionSchema,x as SatelliteEnvSchema,V as SetDocSchema,Le as TimestampMatcherSchema,ve as TimestampSchema,ft as UpdateFnOrObjectSchema,Se as UpdateFnSchema,w as UpdateSchema,We as UserIdSchema,Ee as VersionSchema,ot as createListResultsSchema,qt as defineAssert,ao as defineHook,ht as defineQuery,Dt as defineUpdate};
2
2
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["src/functions/query.ts", "src/schemas/satellite.env.ts", "src/utils/zod.utils.ts", "src/functions/constants.ts", "src/functions/schemas/function.ts", "src/functions/update.ts", "src/hooks/assertions.ts", "src/hooks/schemas/collections.ts", "src/hooks/schemas/context.ts", "src/hooks/schemas/db/context.ts", "src/hooks/schemas/db/payload.ts", "src/hooks/schemas/storage/context.ts", "src/hooks/schemas/storage/payload.ts", "src/hooks/hooks.ts", "src/functions/wrappers.ts", "src/polyfills/console.polyfill.ts", "src/polyfills/random.polyfill.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst QueryBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.QUERY)\n});\n\n/**\n * @see Query\n */\nexport const QuerySchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining a query serverless function.\n * Does not include `type`, which is injected by `defineQuery`.\n */\nexport type Query<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A query function definition with `type` injected by `defineQuery`.\n * Queries are read-only functions that do not modify state.\n */\nexport type QueryDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Query<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.QUERY;\n};\n\nexport const QueryFnSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: querySchema});\n\n/**\n * A factory function that receives the satellite environment and returns a query definition.\n */\nexport type QueryFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Query<TArgs, TResult>;\n\nexport const QueryFnOrObjectSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.union([querySchema, createFunctionSchema(QueryFnSchema(querySchema))]);\n\n/**\n * A query definition or a factory function that returns one.\n */\nexport type QueryFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Query<TArgs, TResult>\n | QueryFn<TArgs, TResult>;\n\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult>\n): QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFn<TArgs, TResult>\n): (env: SatelliteEnv) => QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFnOrObject<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>);\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult> | QueryFn<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>) {\n if (typeof query === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...query(env), type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n };\n }\n\n const result = {...query, type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.string(), z.string());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\n\n/**\n * Wraps a Zod function schema so that parsing returns the **original function**\n * instead of Zod's wrapped validator.\n *\n * Why?\n * ----\n * In Zod v4, `z.function({...})` normally returns a wrapper that validates\n * both arguments and the return value **every time the function is called**.\n * If your function's return type is `void | Promise<void>`, Zod tries to\n * validate it synchronously, which can throw\n * \"Encountered Promise during synchronous parse\"\n * when the implementation is async.\n *\n * By using `.implement`, we tell Zod: \u201Cthis is the function that satisfies\n * the schema.\u201D That way the schema still validates the function shape at\n * parse time, but the returned value is the **original function** you passed\n * in \u2014 no runtime wrapper, no sync/async mismatch.\n *\n * Reference:\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-2845134912\n *\n * Note: We need the function for this library, see following comment\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-3335735535\n */\nexport const createFunctionSchema = <T extends z.ZodFunction>(schema: T) =>\n z.custom<Parameters<T['implement']>[0]>(\n (fn) => typeof fn === 'function' && schema.implement(fn as Parameters<T['implement']>[0])\n );\n", "/**\n * Internal constant used by Juno's tooling to discover serverless functions.\n * Not intended for direct use by developers.\n */\nexport const JUNO_FUNCTION_TYPE = {\n QUERY: '__juno_function_query',\n UPDATE: '__juno_function_update'\n} as const;\n", "import * as z from 'zod';\nimport {createFunctionSchema} from '../../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from '../constants';\n\n/**\n * The type of a serverless function. Not exposed to the developer. It allows the CLI\n * to discover the functions when parsing the code.\n */\nexport type CustomFunctionType = (typeof JUNO_FUNCTION_TYPE)[keyof typeof JUNO_FUNCTION_TYPE];\n\nconst CustomFunctionBaseSchema = z.strictObject({\n type: z.enum([JUNO_FUNCTION_TYPE.QUERY, JUNO_FUNCTION_TYPE.UPDATE])\n});\n\n/**\n * @see CustomFunctionWithArgsAndResult\n */\nexport const CustomFunctionWithArgsAndResultSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithArgs\n */\nexport const CustomFunctionWithArgsSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithResult\n */\nexport const CustomFunctionWithResultSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithoutArgsAndResult\n */\nexport const CustomFunctionWithoutArgsAndResultSchema = z.strictObject({\n ...CustomFunctionBaseSchema.shape,\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunction\n */\nexport const CustomFunctionSchema = z.union([\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithResultSchema,\n CustomFunctionWithoutArgsAndResultSchema\n]);\n\n/**\n * Base interface for all serverless function variants.\n */\ninterface CustomFunctionBase {\n /**\n * The type of the function, either a query or an update.\n */\n type: CustomFunctionType;\n}\n\n/**\n * A serverless function with both input arguments and an output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithArgsAndResult<\n TArgs extends z.ZodRawShape,\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {TResult | Promise<TResult>}\n */\n handler: (\n args: z.infer<z.ZodObject<TArgs>>\n ) => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with input arguments but no output result.\n *\n * @template TArgs - The type of the input arguments.\n */\nexport interface CustomFunctionWithArgs<TArgs extends z.ZodRawShape> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {void | Promise<void>}\n */\n handler: (args: z.infer<z.ZodObject<TArgs>>) => void | Promise<void>;\n}\n\n/**\n * A serverless function with an output result but no input arguments.\n *\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithResult<\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {TResult | Promise<TResult>}\n */\n handler: () => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with no input arguments and no output result.\n */\nexport interface CustomFunctionWithoutArgsAndResult extends CustomFunctionBase {\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {void | Promise<void>}\n */\n handler: () => void | Promise<void>;\n}\n\n/**\n * A serverless function definition. The four variants cover all combinations\n * of optional input arguments and output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport type CustomFunction<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | CustomFunctionWithArgsAndResult<TArgs, TResult>\n | CustomFunctionWithArgs<TArgs>\n | CustomFunctionWithResult<TResult>\n | CustomFunctionWithoutArgsAndResult;\n", "import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst UpdateBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.UPDATE)\n});\n\n/**\n * @see Update\n */\nexport const UpdateSchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining an update serverless function.\n * Does not include `type`, which is injected by `defineUpdate`.\n */\nexport type Update<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A update function definition with `type` injected by `defineUpdate`.\n * Queries are read-only functions that do not modify state.\n */\nexport type UpdateDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Update<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.UPDATE;\n};\n\nexport const UpdateFnSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: updateSchema});\n\n/**\n * A factory function that receives the satellite environment and returns an update definition.\n */\nexport type UpdateFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Update<TArgs, TResult>;\n\nexport const UpdateFnOrObjectSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.union([updateSchema, createFunctionSchema(UpdateFnSchema(updateSchema))]);\n\n/**\n * A update definition or a factory function that returns one.\n */\nexport type UpdateFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Update<TArgs, TResult>\n | UpdateFn<TArgs, TResult>;\n\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFn<TArgs, TResult>\n): (env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFnOrObject<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>);\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult> | UpdateFn<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>) {\n if (typeof update === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...update(env), type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n };\n }\n\n const result = {...update, type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type AssertFunction, AssertFunctionSchema} from './schemas/context';\nimport {\n type AssertDeleteDocContext,\n AssertDeleteDocContextSchema,\n type AssertSetDocContext,\n AssertSetDocContextSchema\n} from './schemas/db/context';\nimport {\n type AssertDeleteAssetContext,\n AssertDeleteAssetContextSchema,\n type AssertUploadAssetContext,\n AssertUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnAssert\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nexport type OnAssert<T> = Collections & {\n assert: AssertFunction<T>;\n};\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = OnAssert<AssertSetDocContext>;\n\n/**\n * @see AssertDeleteDoc\n */\nexport const AssertDeleteDocSchema = OnAssertSchema(AssertDeleteDocContextSchema);\n\n/**\n * An assertion that runs when a document is deleted.\n */\nexport type AssertDeleteDoc = OnAssert<AssertDeleteDocContext>;\n\n/**\n * @see AssertUploadAsset\n */\nexport const AssertUploadAssetSchema = OnAssertSchema(AssertUploadAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is uploaded.\n */\nexport type AssertUploadAsset = OnAssert<AssertUploadAssetContext>;\n\n/**\n * @see AssertDeleteAsset\n */\nexport const AssertDeleteAssetSchema = OnAssertSchema(AssertDeleteAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is deleted.\n */\nexport type AssertDeleteAsset = OnAssert<AssertDeleteAssetContext>;\n\n/**\n * @see Assert\n */\nexport const AssertSchema = z.union([\n AssertSetDocSchema,\n AssertDeleteDocSchema,\n AssertUploadAssetSchema,\n AssertDeleteAssetSchema\n]);\n\n/**\n * All assertions definitions.\n */\nexport type Assert = AssertSetDoc | AssertDeleteDoc | AssertUploadAsset | AssertDeleteAsset;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function({\n input: z.tuple([SatelliteEnvSchema]),\n output: assertSchema\n });\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, createFunctionSchema(AssertFnSchema(assertSchema))]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\nimport type {Collection} from '../../schemas/satellite';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n collections: z.array(z.string()).readonly()\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport interface Collections {\n /**\n * An array of collection names where the hook or assertion will run.\n * If empty, no hooks or assertions are triggered.\n */\n collections: readonly Collection[];\n}\n", "import * as z from 'zod';\nimport {type RawUserId, RawUserIdSchema} from '../../schemas/satellite';\nimport {createFunctionSchema} from '../../utils/zod.utils';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n caller: RawUserIdSchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport interface HookContext<T> {\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserId;\n\n /**\n * The data associated with the hook execution.\n */\n data: T;\n}\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(z.function({input: z.tuple([contextSchema]), output: z.void()}));\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = (context: T) => void;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(\n z.function({input: z.tuple([contextSchema]), output: z.promise(z.void()).or(z.void())})\n );\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns either a `Promise<void>` or `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = (context: T) => void | Promise<void>;\n", "import * as z from 'zod';\nimport {DocSchema, type OptionDoc} from '../../../schemas/db';\nimport {type Collection, CollectionSchema, type Key, KeySchema} from '../../../schemas/satellite';\nimport {type HookContext, HookContextSchema} from '../context';\nimport {\n type DocAssertDelete,\n DocAssertDeleteSchema,\n type DocAssertSet,\n DocAssertSetSchema,\n type DocUpsert,\n DocUpsertSchema\n} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n collection: CollectionSchema,\n key: KeySchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport interface DocContext<T> {\n /**\n * The name of the collection where the document is stored.\n */\n collection: Collection;\n\n /**\n * The key identifying the document within the collection.\n */\n key: Key;\n\n /**\n * The data associated with the document operation.\n */\n data: T;\n}\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = HookContext<DocContext<DocUpsert>>;\n\n/**\n * @see OnSetManyDocsContext\n */\nexport const OnSetManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocUpsertSchema))\n);\n\n/**\n * The context provided to the `onSetManyDocs` hook.\n *\n * This context contains information about multiple documents being created or updated\n * in a single operation, along with details about the user who triggered it.\n */\nexport type OnSetManyDocsContext = HookContext<DocContext<DocUpsert>[]>;\n\n/**\n * @see OnDeleteDocContext\n */\nexport const OnDeleteDocContextSchema = HookContextSchema(DocContextSchema(DocSchema.optional()));\n\n/**\n * The context provided to the `onDeleteDoc` hook.\n *\n * This context contains information about a single document being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteDocContext = HookContext<DocContext<OptionDoc>>;\n\n/**\n * @see OnDeleteManyDocsContext\n */\nexport const OnDeleteManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteManyDocs` hook.\n *\n * This context contains information about multiple documents being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see OnDeleteFilteredDocsContext\n */\nexport const OnDeleteFilteredDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteFilteredDocs` hook.\n *\n * This context contains information about documents deleted as a result of a filter,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = HookContext<DocContext<DocAssertSet>>;\n\n/**\n * @see AssertDeleteDocContext\n */\nexport const AssertDeleteDocContextSchema = HookContextSchema(\n DocContextSchema(DocAssertDeleteSchema)\n);\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteDocContext = HookContext<DocContext<DocAssertDelete>>;\n", "import * as z from 'zod';\nimport {\n type DelDoc,\n DelDocSchema,\n type Doc,\n DocSchema,\n type SetDoc,\n SetDocSchema\n} from '../../../schemas/db';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n before: DocSchema.optional(),\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport interface DocUpsert {\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before?: Doc;\n\n /**\n * The new version of the document after the update.\n */\n after: Doc;\n}\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: SetDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertSet {\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: SetDoc;\n}\n\n/**\n * @see DocAssertDelete\n */\nexport const DocAssertDeleteSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: DelDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before deleting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertDelete {\n /**\n * The current version of the document before the operation.\n * Undefined if the document does not exist.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: DelDoc;\n}\n", "import * as z from 'zod';\nimport {AssetSchema, type Asset} from '../../../schemas/storage';\nimport {HookContextSchema, type HookContext} from '../context';\nimport {AssetAssertUploadSchema, type AssetAssertUpload} from './payload';\n\n/**\n * @see OnUploadAssetContext\n */\nexport const OnUploadAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `onUploadAsset` hook.\n *\n * This context contains information about the asset that was uploaded.\n */\nexport type OnUploadAssetContext = HookContext<Asset>;\n\n/**\n * @see OnDeleteAssetContext\n */\nexport const OnDeleteAssetContextSchema = HookContextSchema(AssetSchema.optional());\n\n/**\n * Context for the `onDeleteAsset` hook.\n *\n * This context contains information about a single asset being deleted, along with details about the user who triggered the operation.\n *\n * If undefined, the asset did not exist.\n */\nexport type OnDeleteAssetContext = HookContext<Asset | undefined>;\n\n/**\n * @see OnDeleteManyAssetsContext\n */\nexport const OnDeleteManyAssetsContextSchema = HookContextSchema(z.array(AssetSchema.optional()));\n\n/**\n * Context for the `onDeleteManyAssets` hook.\n *\n * This context contains information about multiple assets being potentially deleted, along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see OnDeleteFilteredAssetsContext\n */\nexport const OnDeleteFilteredAssetsContextSchema = HookContextSchema(\n z.array(AssetSchema.optional())\n);\n\n/**\n * Context for the `onDeleteFilteredAssets` hook.\n *\n * This context contains information about documents deleted as a result of a filter, along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see AssertUploadAssetContext\n */\nexport const AssertUploadAssetContextSchema = HookContextSchema(AssetAssertUploadSchema);\n\n/**\n * Context for the `assertUploadAsset` hook.\n *\n * This context contains information about the asset being validated before it is uploaded. If validation fails, the developer should throw an error.\n */\nexport type AssertUploadAssetContext = HookContext<AssetAssertUpload>;\n\n/**\n * @see AssertDeleteAssetContext\n */\nexport const AssertDeleteAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `assertDeleteAsset` hook.\n *\n * This context contains information about the asset being validated before it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteAssetContext = HookContext<Asset>;\n", "import * as z from 'zod';\nimport {\n type Asset,\n AssetSchema,\n type Batch,\n BatchSchema,\n type CommitBatch,\n CommitBatchSchema\n} from '../../../schemas/storage';\n\n/**\n * @see AssetAssertUpload\n */\nexport const AssetAssertUploadSchema = z\n .object({\n current: AssetSchema.optional(),\n batch: BatchSchema,\n commit_batch: CommitBatchSchema\n })\n .strict();\n\n/**\n * Represents a validation context before uploading an asset.\n */\nexport interface AssetAssertUpload {\n /**\n * The current asset already stored (if any).\n */\n current?: Asset;\n\n /**\n * The batch metadata being uploaded.\n */\n batch: Batch;\n\n /**\n * The commit data describing headers and chunk ids.\n */\n commit_batch: CommitBatch;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type RunFunction, RunFunctionSchema} from './schemas/context';\nimport {\n type OnDeleteDocContext,\n OnDeleteDocContextSchema,\n type OnDeleteFilteredDocsContext,\n OnDeleteFilteredDocsContextSchema,\n type OnDeleteManyDocsContext,\n OnDeleteManyDocsContextSchema,\n type OnSetDocContext,\n OnSetDocContextSchema,\n type OnSetManyDocsContext,\n OnSetManyDocsContextSchema\n} from './schemas/db/context';\nimport {\n type OnDeleteAssetContext,\n OnDeleteAssetContextSchema,\n type OnDeleteFilteredAssetsContext,\n OnDeleteFilteredAssetsContextSchema,\n type OnDeleteManyAssetsContext,\n OnDeleteManyAssetsContextSchema,\n type OnUploadAssetContext,\n OnUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnHook\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nexport type OnHook<T> = Collections & {\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunction<T>;\n};\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = OnHook<OnSetDocContext>;\n\n/**\n * @see OnSetManyDocs\n */\nexport const OnSetManyDocsSchema = OnHookSchema(OnSetManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are created or updated.\n */\nexport type OnSetManyDocs = OnHook<OnSetManyDocsContext>;\n\n/**\n * @see OnDeleteDoc\n */\nexport const OnDeleteDocSchema = OnHookSchema(OnDeleteDocContextSchema);\n\n/**\n * A hook that runs when a single document is deleted.\n */\nexport type OnDeleteDoc = OnHook<OnDeleteDocContext>;\n\n/**\n * @see OnDeleteManyDocs\n */\nexport const OnDeleteManyDocsSchema = OnHookSchema(OnDeleteManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are deleted.\n */\nexport type OnDeleteManyDocs = OnHook<OnDeleteManyDocsContext>;\n\n/**\n * @see OnDeleteFilteredDocs\n */\nexport const OnDeleteFilteredDocsSchema = OnHookSchema(OnDeleteFilteredDocsContextSchema);\n\n/**\n * A hook that runs when a filtered set of documents is deleted based on query conditions.\n */\nexport type OnDeleteFilteredDocs = OnHook<OnDeleteFilteredDocsContext>;\n\n/**\n * @see OnUploadAsset\n */\nexport const OnUploadAssetSchema = OnHookSchema(OnUploadAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is uploaded.\n */\nexport type OnUploadAsset = OnHook<OnUploadAssetContext>;\n\n/**\n * @see OnDeleteAsset\n */\nexport const OnDeleteAssetSchema = OnHookSchema(OnDeleteAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is potentially deleted.\n */\nexport type OnDeleteAsset = OnHook<OnDeleteAssetContext>;\n\n/**\n * @see OnDeleteManyAssets\n */\nexport const OnDeleteManyAssetsSchema = OnHookSchema(OnDeleteManyAssetsContextSchema);\n\n/**\n * A hook that runs when multiple assets are potentially deleted.\n */\nexport type OnDeleteManyAssets = OnHook<OnDeleteManyAssetsContext>;\n\n/**\n * @see OnDeleteFilteredAssets\n */\nexport const OnDeleteFilteredAssetsSchema = OnHookSchema(OnDeleteFilteredAssetsContextSchema);\n\n/**\n * A hook that runs when a filtered set of assets is deleted based on query conditions.\n */\nexport type OnDeleteFilteredAssets = OnHook<OnDeleteFilteredAssetsContext>;\n\n/**\n * @see Hook\n */\nexport const HookSchema = z.union([\n OnSetDocSchema,\n OnSetManyDocsSchema,\n OnDeleteDocContextSchema,\n OnDeleteManyDocsContextSchema,\n OnDeleteFilteredDocsContextSchema,\n OnUploadAssetSchema,\n OnDeleteAssetSchema,\n OnDeleteManyAssetsSchema,\n OnDeleteFilteredAssetsSchema\n]);\n\n/**\n * All hooks definitions.\n */\nexport type Hook =\n | OnSetDoc\n | OnSetManyDocs\n | OnDeleteDoc\n | OnDeleteManyDocs\n | OnDeleteFilteredDocs\n | OnUploadAsset\n | OnDeleteAsset\n | OnDeleteManyAssets\n | OnDeleteFilteredAssets;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: hookSchema});\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, createFunctionSchema(HookFnSchema(hookSchema))]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {nonNullish} from '@dfinity/utils';\nimport * as z from 'zod';\nimport {decodeDocData, encodeDocData} from '../sdk/serializer.sdk';\nimport {QuerySchema} from './query';\nimport {UpdateSchema} from './update';\n\nconst ConfigSchema = z.union([QuerySchema, UpdateSchema]);\ntype Config = z.infer<typeof ConfigSchema>;\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_sync = (config: Config, raw?: Uint8Array<ArrayBuffer>) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = () => {\n if (nonNullish(args)) {\n return (config.handler as (args: unknown) => unknown)(args);\n }\n\n return (config.handler as () => unknown)();\n };\n\n const result = execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_async = async (\n config: Config,\n raw?: Uint8Array<ArrayBuffer>\n) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = async () => {\n if (nonNullish(args)) {\n return await (config.handler as (args: unknown) => unknown)(args);\n }\n\n return await (config.handler as () => unknown)();\n };\n\n const result = await execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n", "import {jsonReplacer} from '@dfinity/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n", "/**\n * @see Math.random\n */\nconst random = (): number => {\n // __juno_satellite_random() returns a signed 32-bit int (i32)\n const value = __juno_satellite_random();\n\n // >>> 0 converts it to unsigned\n return (value >>> 0) / 2 ** 32;\n};\n\n/**\n * Overwrites Math.random with a pseudo-random number using the Satellite's internal RNG.\n *\n * \u26A0\uFE0F This function is not suitable for use cases requiring cryptographically secure or perfectly unpredictable randomness,\n * such as lotteries or gambling dApps.\n *\n * @returns {number} A pseudo-random 32-bit integer.\n *\n * @throws {Error} If the RNG has not been initialized.\n */\nglobalThis.Math.random = random;\n"],
5
- "mappings": "2WAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EAAuB,SAAS,SAAO,EAAK,SAAO,CAAC,ECLjE,UAAYC,MAAO,MA0BZ,IAAMC,EAAiDC,GAC1D,SACCC,GAAO,OAAOA,GAAO,YAAcD,EAAO,UAAUC,CAAmC,CAC1F,ECzBK,IAAMC,EAAqB,CAChC,MAAO,wBACP,OAAQ,wBACV,ECPA,UAAYC,MAAO,MAUnB,IAAMC,EAA6B,eAAa,CAC9C,KAAQ,OAAK,CAACC,EAAmB,MAAOA,EAAmB,MAAM,CAAC,CACpE,CAAC,EAKYC,EAA0C,eAAa,CAClE,GAAGF,EAAyB,MAC5B,KAAQ,aAAa,WAAS,EAC9B,OAAU,aAAa,WAAS,EAChC,QAASG,EACL,WAAS,CACT,MAAS,QAAM,CAAG,UAAQ,CAAC,CAAC,EAC5B,OAAU,QAAM,CAAG,UAAQ,EAAK,UAAU,UAAQ,CAAC,CAAC,CAAC,CACvD,CAAC,CACH,CACF,CAAC,EAKYC,EAAiC,eAAa,CACzD,GAAGJ,EAAyB,MAC5B,KAAQ,aAAa,WAAS,EAC9B,QAASG,EACL,WAAS,CACT,MAAS,QAAM,CAAG,UAAQ,CAAC,CAAC,EAC5B,OAAU,QAAM,CAAG,OAAK,EAAK,UAAU,OAAK,CAAC,CAAC,CAAC,CACjD,CAAC,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AEX,WAAW,eAAeD,CAAG,CAC/B,EAGA,WAAW,QAAU,CAEnB,QAAQD,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,OAAOA,EAAU,CACfD,EAA6BC,CAAC,CAChC,EAEA,QAAQA,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,SAASA,EAAU,CACjBD,EAA6BC,CAAC,CAChC,CACF,EC1BA,IAAMG,GAAS,KAEC,wBAAwB,IAGpB,GAAK,WAazB,WAAW,KAAK,OAASA",
6
- "names": ["z", "z", "SatelliteEnvSchema", "z", "createFunctionSchema", "schema", "fn", "JUNO_FUNCTION_TYPE", "z", "CustomFunctionBaseSchema", "JUNO_FUNCTION_TYPE", "CustomFunctionWithArgsAndResultSchema", "createFunctionSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "CustomFunctionSchema", "QueryBaseSchema", "JUNO_FUNCTION_TYPE", "QuerySchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "QueryFnSchema", "querySchema", "SatelliteEnvSchema", "QueryFnOrObjectSchema", "createFunctionSchema", "defineQuery", "query", "env", "result", "z", "UpdateBaseSchema", "JUNO_FUNCTION_TYPE", "UpdateSchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "UpdateFnSchema", "updateSchema", "SatelliteEnvSchema", "UpdateFnOrObjectSchema", "createFunctionSchema", "defineUpdate", "update", "env", "result", "z", "CollectionsSchema", "z", "HookContextSchema", "dataSchema", "RawUserIdSchema", "AssertFunctionSchema", "contextSchema", "createFunctionSchema", "RunFunctionSchema", "z", "z", "DocUpsertSchema", "DocSchema", "DocAssertSetSchema", "SetDocSchema", "DocAssertDeleteSchema", "DelDocSchema", "DocContextSchema", "dataSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "HookContextSchema", "DocUpsertSchema", "OnSetManyDocsContextSchema", "OnDeleteDocContextSchema", "DocSchema", "OnDeleteManyDocsContextSchema", "OnDeleteFilteredDocsContextSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "AssertDeleteDocContextSchema", "DocAssertDeleteSchema", "z", "z", "AssetAssertUploadSchema", "AssetSchema", "BatchSchema", "CommitBatchSchema", "OnUploadAssetContextSchema", "HookContextSchema", "AssetSchema", "OnDeleteAssetContextSchema", "OnDeleteManyAssetsContextSchema", "OnDeleteFilteredAssetsContextSchema", "AssertUploadAssetContextSchema", "AssetAssertUploadSchema", "AssertDeleteAssetContextSchema", "OnAssertSchema", "contextSchema", "CollectionsSchema", "AssertFunctionSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertDeleteDocSchema", "AssertDeleteDocContextSchema", "AssertUploadAssetSchema", "AssertUploadAssetContextSchema", "AssertDeleteAssetSchema", "AssertDeleteAssetContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "createFunctionSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsSchema", "RunFunctionSchema", "OnSetDocSchema", "OnSetDocContextSchema", "OnSetManyDocsSchema", "OnSetManyDocsContextSchema", "OnDeleteDocSchema", "OnDeleteDocContextSchema", "OnDeleteManyDocsSchema", "OnDeleteManyDocsContextSchema", "OnDeleteFilteredDocsSchema", "OnDeleteFilteredDocsContextSchema", "OnUploadAssetSchema", "OnUploadAssetContextSchema", "OnDeleteAssetSchema", "OnDeleteAssetContextSchema", "OnDeleteManyAssetsSchema", "OnDeleteManyAssetsContextSchema", "OnDeleteFilteredAssetsSchema", "OnDeleteFilteredAssetsContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "createFunctionSchema", "defineHook", "hook", "nonNullish", "z", "ConfigSchema", "QuerySchema", "UpdateSchema", "config", "raw", "args", "nonNullish", "decodeDocData", "result", "parsed", "encodeDocData", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg", "random"]
4
+ "sourcesContent": ["import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst QueryBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.QUERY)\n});\n\n/**\n * @see Query\n */\nexport const QuerySchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...QueryBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...QueryBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining a query serverless function.\n * Does not include `type`, which is injected by `defineQuery`.\n */\nexport type Query<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A query function definition with `type` injected by `defineQuery`.\n * Queries are read-only functions that do not modify state.\n */\nexport type QueryDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Query<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.QUERY;\n};\n\nexport const QueryFnSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: querySchema});\n\n/**\n * A factory function that receives the satellite environment and returns a query definition.\n */\nexport type QueryFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Query<TArgs, TResult>;\n\nexport const QueryFnOrObjectSchema = <T extends z.ZodTypeAny>(querySchema: T) =>\n z.union([querySchema, createFunctionSchema(QueryFnSchema(querySchema))]);\n\n/**\n * A query definition or a factory function that returns one.\n */\nexport type QueryFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Query<TArgs, TResult>\n | QueryFn<TArgs, TResult>;\n\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult>\n): QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFn<TArgs, TResult>\n): (env: SatelliteEnv) => QueryDefinition<TArgs, TResult>;\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: QueryFnOrObject<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>);\nexport function defineQuery<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n query: Query<TArgs, TResult> | QueryFn<TArgs, TResult>\n): QueryDefinition<TArgs, TResult> | ((env: SatelliteEnv) => QueryDefinition<TArgs, TResult>) {\n if (typeof query === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...query(env), type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n };\n }\n\n const result = {...query, type: JUNO_FUNCTION_TYPE.QUERY};\n QuerySchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\n\n/**\n * @see SatelliteEnv\n */\nexport const SatelliteEnvSchema = z.record(z.string(), z.string());\n\n/**\n * Placeholder for future environment-specific configurations.\n *\n * Currently unused, but it may support features such as:\n * - Defining the execution mode (e.g., staging or production).\n * - Providing environment-specific values like `ckBtcLedgerId` for test or production.\n */\nexport type SatelliteEnv = z.infer<typeof SatelliteEnvSchema>;\n", "import * as z from 'zod';\n\n/**\n * Wraps a Zod function schema so that parsing returns the **original function**\n * instead of Zod's wrapped validator.\n *\n * Why?\n * ----\n * In Zod v4, `z.function({...})` normally returns a wrapper that validates\n * both arguments and the return value **every time the function is called**.\n * If your function's return type is `void | Promise<void>`, Zod tries to\n * validate it synchronously, which can throw\n * \"Encountered Promise during synchronous parse\"\n * when the implementation is async.\n *\n * By using `.implement`, we tell Zod: \u201Cthis is the function that satisfies\n * the schema.\u201D That way the schema still validates the function shape at\n * parse time, but the returned value is the **original function** you passed\n * in \u2014 no runtime wrapper, no sync/async mismatch.\n *\n * Reference:\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-2845134912\n *\n * Note: We need the function for this library, see following comment\n * https://github.com/colinhacks/zod/issues/4143#issuecomment-3335735535\n */\nexport const createFunctionSchema = <T extends z.ZodFunction>(schema: T) =>\n z.custom<Parameters<T['implement']>[0]>(\n (fn) => typeof fn === 'function' && schema.implement(fn as Parameters<T['implement']>[0])\n );\n", "/**\n * Internal constant used by Juno's tooling to discover serverless functions.\n * Not intended for direct use by developers.\n */\nexport const JUNO_FUNCTION_TYPE = {\n QUERY: '__juno_function_query',\n UPDATE: '__juno_function_update'\n} as const;\n", "import * as z from 'zod';\nimport {createFunctionSchema} from '../../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from '../constants';\n\n/**\n * The type of a serverless function. Not exposed to the developer. It allows the CLI\n * to discover the functions when parsing the code.\n */\nexport type CustomFunctionType = (typeof JUNO_FUNCTION_TYPE)[keyof typeof JUNO_FUNCTION_TYPE];\n\nconst CustomFunctionTypeSchema = z.strictObject({\n type: z.enum([JUNO_FUNCTION_TYPE.QUERY, JUNO_FUNCTION_TYPE.UPDATE])\n});\n\nexport const CustomFunctionGuardSchema = createFunctionSchema(\n z.function({\n output: z.void()\n })\n);\n\n/**\n * @see CustomFunctionBase\n */\nconst CustomFunctionBaseSchema = z.strictObject({\n guard: CustomFunctionGuardSchema.optional(),\n hidden: z.boolean().optional()\n});\n\n/**\n * @see CustomFunctionWithArgsAndResult\n */\nexport const CustomFunctionWithArgsAndResultSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithArgs\n */\nexport const CustomFunctionWithArgsSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n args: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([z.unknown()]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithResult\n */\nexport const CustomFunctionWithResultSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n result: z.instanceof(z.ZodObject),\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.unknown(), z.promise(z.unknown())])\n })\n )\n});\n\n/**\n * @see CustomFunctionWithoutArgsAndResult\n */\nexport const CustomFunctionWithoutArgsAndResultSchema = z.strictObject({\n ...CustomFunctionTypeSchema.shape,\n ...CustomFunctionBaseSchema.shape,\n handler: createFunctionSchema(\n z.function({\n input: z.tuple([]),\n output: z.union([z.void(), z.promise(z.void())])\n })\n )\n});\n\n/**\n * @see CustomFunction\n */\nexport const CustomFunctionSchema = z.union([\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithResultSchema,\n CustomFunctionWithoutArgsAndResultSchema\n]);\n\n/**\n * Base interface for all serverless function variants.\n */\ninterface CustomFunctionBase {\n /**\n * The type of the function, either a query or an update.\n */\n type: CustomFunctionType;\n\n /**\n * An optional function that runs before the function is executed.\n * If the guard throws, the function is not executed.\n */\n guard?: () => void;\n\n /**\n * If true, the function is not exposed in the public Candid interface.\n * Useful for internal functions such as HTTP response transform functions.\n */\n hidden?: boolean;\n}\n\n/**\n * A serverless function with both input arguments and an output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithArgsAndResult<\n TArgs extends z.ZodRawShape,\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {TResult | Promise<TResult>}\n */\n handler: (\n args: z.infer<z.ZodObject<TArgs>>\n ) => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with input arguments but no output result.\n *\n * @template TArgs - The type of the input arguments.\n */\nexport interface CustomFunctionWithArgs<TArgs extends z.ZodRawShape> extends CustomFunctionBase {\n /**\n * A Zod schema describing the input arguments.\n */\n args: z.ZodObject<TArgs>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @param {TArgs} args - The input arguments.\n * @returns {void | Promise<void>}\n */\n handler: (args: z.infer<z.ZodObject<TArgs>>) => void | Promise<void>;\n}\n\n/**\n * A serverless function with an output result but no input arguments.\n *\n * @template TResult - The type of the output result.\n */\nexport interface CustomFunctionWithResult<\n TResult extends z.ZodRawShape\n> extends CustomFunctionBase {\n /**\n * A Zod schema describing the output result.\n */\n result: z.ZodObject<TResult>;\n\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {TResult | Promise<TResult>}\n */\n handler: () => z.infer<z.ZodObject<TResult>> | Promise<z.infer<z.ZodObject<TResult>>>;\n}\n\n/**\n * A serverless function with no input arguments and no output result.\n */\nexport interface CustomFunctionWithoutArgsAndResult extends CustomFunctionBase {\n /**\n * The function handler. Can be synchronous or asynchronous.\n *\n * @returns {void | Promise<void>}\n */\n handler: () => void | Promise<void>;\n}\n\n/**\n * A serverless function definition. The four variants cover all combinations\n * of optional input arguments and output result.\n *\n * @template TArgs - The type of the input arguments.\n * @template TResult - The type of the output result.\n */\nexport type CustomFunction<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | CustomFunctionWithArgsAndResult<TArgs, TResult>\n | CustomFunctionWithArgs<TArgs>\n | CustomFunctionWithResult<TResult>\n | CustomFunctionWithoutArgsAndResult;\n", "import * as z from 'zod';\nimport {type SatelliteEnv, SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {JUNO_FUNCTION_TYPE} from './constants';\nimport {\n type CustomFunctionWithArgs,\n type CustomFunctionWithArgsAndResult,\n type CustomFunctionWithoutArgsAndResult,\n type CustomFunctionWithResult,\n CustomFunctionWithArgsAndResultSchema,\n CustomFunctionWithArgsSchema,\n CustomFunctionWithoutArgsAndResultSchema,\n CustomFunctionWithResultSchema\n} from './schemas/function';\n\nconst UpdateBaseSchema = z.strictObject({\n type: z.literal(JUNO_FUNCTION_TYPE.UPDATE)\n});\n\n/**\n * @see Update\n */\nexport const UpdateSchema = z.union([\n z.strictObject({\n ...CustomFunctionWithArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithArgsSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithResultSchema.shape,\n ...UpdateBaseSchema.shape\n }),\n z.strictObject({\n ...CustomFunctionWithoutArgsAndResultSchema.shape,\n ...UpdateBaseSchema.shape\n })\n]);\n\n/**\n * The input shape for defining an update serverless function.\n * Does not include `type`, which is injected by `defineUpdate`.\n */\nexport type Update<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> =\n | Omit<CustomFunctionWithArgsAndResult<TArgs, TResult>, 'type'>\n | Omit<CustomFunctionWithArgs<TArgs>, 'type'>\n | Omit<CustomFunctionWithResult<TResult>, 'type'>\n | Omit<CustomFunctionWithoutArgsAndResult, 'type'>;\n\n/**\n * A update function definition with `type` injected by `defineUpdate`.\n * Queries are read-only functions that do not modify state.\n */\nexport type UpdateDefinition<\n TArgs extends z.ZodRawShape = z.ZodRawShape,\n TResult extends z.ZodRawShape = z.ZodRawShape\n> = Update<TArgs, TResult> & {\n type: typeof JUNO_FUNCTION_TYPE.UPDATE;\n};\n\nexport const UpdateFnSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: updateSchema});\n\n/**\n * A factory function that receives the satellite environment and returns an update definition.\n */\nexport type UpdateFn<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> = (\n env: SatelliteEnv\n) => Update<TArgs, TResult>;\n\nexport const UpdateFnOrObjectSchema = <T extends z.ZodTypeAny>(updateSchema: T) =>\n z.union([updateSchema, createFunctionSchema(UpdateFnSchema(updateSchema))]);\n\n/**\n * A update definition or a factory function that returns one.\n */\nexport type UpdateFnOrObject<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape> =\n | Update<TArgs, TResult>\n | UpdateFn<TArgs, TResult>;\n\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFn<TArgs, TResult>\n): (env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>;\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: UpdateFnOrObject<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>);\nexport function defineUpdate<TArgs extends z.ZodRawShape, TResult extends z.ZodRawShape>(\n update: Update<TArgs, TResult> | UpdateFn<TArgs, TResult>\n): UpdateDefinition<TArgs, TResult> | ((env: SatelliteEnv) => UpdateDefinition<TArgs, TResult>) {\n if (typeof update === 'function') {\n return (env: SatelliteEnv) => {\n const result = {...update(env), type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n };\n }\n\n const result = {...update, type: JUNO_FUNCTION_TYPE.UPDATE};\n UpdateSchema.parse(result);\n return result;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type AssertFunction, AssertFunctionSchema} from './schemas/context';\nimport {\n type AssertDeleteDocContext,\n AssertDeleteDocContextSchema,\n type AssertSetDocContext,\n AssertSetDocContextSchema\n} from './schemas/db/context';\nimport {\n type AssertDeleteAssetContext,\n AssertDeleteAssetContextSchema,\n type AssertUploadAssetContext,\n AssertUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnAssert\n */\nconst OnAssertSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n /**\n * A function that runs when the assertion is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {void} Resolves when the assertion completes.\n */\n assert: AssertFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining assertions related to collections.\n *\n * @template T - The type of context passed to the assertions when triggered.\n */\nexport type OnAssert<T> = Collections & {\n assert: AssertFunction<T>;\n};\n\n/**\n * @see AssertSetDoc\n */\nexport const AssertSetDocSchema = OnAssertSchema(AssertSetDocContextSchema);\n\n/**\n * An assertion that runs when a document is created or updated.\n */\nexport type AssertSetDoc = OnAssert<AssertSetDocContext>;\n\n/**\n * @see AssertDeleteDoc\n */\nexport const AssertDeleteDocSchema = OnAssertSchema(AssertDeleteDocContextSchema);\n\n/**\n * An assertion that runs when a document is deleted.\n */\nexport type AssertDeleteDoc = OnAssert<AssertDeleteDocContext>;\n\n/**\n * @see AssertUploadAsset\n */\nexport const AssertUploadAssetSchema = OnAssertSchema(AssertUploadAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is uploaded.\n */\nexport type AssertUploadAsset = OnAssert<AssertUploadAssetContext>;\n\n/**\n * @see AssertDeleteAsset\n */\nexport const AssertDeleteAssetSchema = OnAssertSchema(AssertDeleteAssetContextSchema);\n\n/**\n * An assertion that runs before an asset is deleted.\n */\nexport type AssertDeleteAsset = OnAssert<AssertDeleteAssetContext>;\n\n/**\n * @see Assert\n */\nexport const AssertSchema = z.union([\n AssertSetDocSchema,\n AssertDeleteDocSchema,\n AssertUploadAssetSchema,\n AssertDeleteAssetSchema\n]);\n\n/**\n * All assertions definitions.\n */\nexport type Assert = AssertSetDoc | AssertDeleteDoc | AssertUploadAsset | AssertDeleteAsset;\n\nexport const AssertFnSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.function({\n input: z.tuple([SatelliteEnvSchema]),\n output: assertSchema\n });\nexport type AssertFn<T extends Assert> = (assert: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const AssertFnOrObjectSchema = <T extends z.ZodTypeAny>(assertSchema: T) =>\n z.union([assertSchema, createFunctionSchema(AssertFnSchema(assertSchema))]);\nexport type AssertFnOrObject<T extends Assert> = T | AssertFn<T>;\n\nexport function defineAssert<T extends Assert>(assert: T): T;\nexport function defineAssert<T extends Assert>(assert: AssertFn<T>): AssertFn<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T>;\nexport function defineAssert<T extends Assert>(assert: AssertFnOrObject<T>): AssertFnOrObject<T> {\n return assert;\n}\n", "import * as z from 'zod';\nimport type {Collection} from '../../schemas/satellite';\n\n/**\n * @see Collections\n */\nexport const CollectionsSchema = z\n .object({\n collections: z.array(z.string()).readonly()\n })\n .strict();\n\n/**\n * Defines the collections where a hook or assertion should run.\n */\nexport interface Collections {\n /**\n * An array of collection names where the hook or assertion will run.\n * If empty, no hooks or assertions are triggered.\n */\n collections: readonly Collection[];\n}\n", "import * as z from 'zod';\nimport {type RawUserId, RawUserIdSchema} from '../../schemas/satellite';\nimport {createFunctionSchema} from '../../utils/zod.utils';\n\n/**\n * @see HookContext\n */\nexport const HookContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n caller: RawUserIdSchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context provided to hooks, containing information about the caller and related data.\n *\n * @template T - The type of data associated with the hook.\n */\nexport interface HookContext<T> {\n /**\n * The user who originally triggered the function that in turn triggered the hook.\n */\n caller: RawUserId;\n\n /**\n * The data associated with the hook execution.\n */\n data: T;\n}\n\n/**\n * @see AssertFunction\n */\nexport const AssertFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(z.function({input: z.tuple([contextSchema]), output: z.void()}));\n\n/**\n * Defines the `assert` function schema for assertions.\n *\n * The function takes a context argument and returns `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type AssertFunction<T> = (context: T) => void;\n\n/**\n * @see RunFunction\n */\nexport const RunFunctionSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n createFunctionSchema(\n z.function({input: z.tuple([contextSchema]), output: z.promise(z.void()).or(z.void())})\n );\n\n/**\n * Defines the `run` function schema for hooks.\n *\n * The function takes a context argument and returns either a `Promise<void>` or `void`.\n *\n * @template T - The type of context passed to the function.\n */\nexport type RunFunction<T> = (context: T) => void | Promise<void>;\n", "import * as z from 'zod';\nimport {DocSchema, type OptionDoc} from '../../../schemas/db';\nimport {type Collection, CollectionSchema, type Key, KeySchema} from '../../../schemas/satellite';\nimport {type HookContext, HookContextSchema} from '../context';\nimport {\n type DocAssertDelete,\n DocAssertDeleteSchema,\n type DocAssertSet,\n DocAssertSetSchema,\n type DocUpsert,\n DocUpsertSchema\n} from './payload';\n\n/**\n * @see DocContext\n */\nexport const DocContextSchema = <T extends z.ZodTypeAny>(dataSchema: T) => {\n const schemaShape = {\n collection: CollectionSchema,\n key: KeySchema,\n data: dataSchema\n };\n\n return z.strictObject(schemaShape);\n};\n\n/**\n * Represents the context of a document operation within a collection.\n *\n * @template T - The type of data associated with the document.\n */\nexport interface DocContext<T> {\n /**\n * The name of the collection where the document is stored.\n */\n collection: Collection;\n\n /**\n * The key identifying the document within the collection.\n */\n key: Key;\n\n /**\n * The data associated with the document operation.\n */\n data: T;\n}\n\n/**\n * @see OnSetDocContext\n */\nexport const OnSetDocContextSchema = HookContextSchema(DocContextSchema(DocUpsertSchema));\n\n/**\n * The context provided to the `onSetDoc` hook.\n *\n * This context contains information about the document being created or updated,\n * along with details about the user who triggered the operation.\n */\nexport type OnSetDocContext = HookContext<DocContext<DocUpsert>>;\n\n/**\n * @see OnSetManyDocsContext\n */\nexport const OnSetManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocUpsertSchema))\n);\n\n/**\n * The context provided to the `onSetManyDocs` hook.\n *\n * This context contains information about multiple documents being created or updated\n * in a single operation, along with details about the user who triggered it.\n */\nexport type OnSetManyDocsContext = HookContext<DocContext<DocUpsert>[]>;\n\n/**\n * @see OnDeleteDocContext\n */\nexport const OnDeleteDocContextSchema = HookContextSchema(DocContextSchema(DocSchema.optional()));\n\n/**\n * The context provided to the `onDeleteDoc` hook.\n *\n * This context contains information about a single document being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteDocContext = HookContext<DocContext<OptionDoc>>;\n\n/**\n * @see OnDeleteManyDocsContext\n */\nexport const OnDeleteManyDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteManyDocs` hook.\n *\n * This context contains information about multiple documents being deleted,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see OnDeleteFilteredDocsContext\n */\nexport const OnDeleteFilteredDocsContextSchema = HookContextSchema(\n z.array(DocContextSchema(DocSchema.optional()))\n);\n\n/**\n * The context provided to the `onDeleteFilteredDocs` hook.\n *\n * This context contains information about documents deleted as a result of a filter,\n * along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredDocsContext = HookContext<DocContext<OptionDoc>[]>;\n\n/**\n * @see AssertSetDocContext\n */\nexport const AssertSetDocContextSchema = HookContextSchema(DocContextSchema(DocAssertSetSchema));\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is created or updated. If validation fails, the developer should throw an error.\n */\nexport type AssertSetDocContext = HookContext<DocContext<DocAssertSet>>;\n\n/**\n * @see AssertDeleteDocContext\n */\nexport const AssertDeleteDocContextSchema = HookContextSchema(\n DocContextSchema(DocAssertDeleteSchema)\n);\n\n/**\n * The context provided to the `assertDeleteDoc` hook.\n *\n * This context contains information about the document being validated before\n * it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteDocContext = HookContext<DocContext<DocAssertDelete>>;\n", "import * as z from 'zod';\nimport {\n type DelDoc,\n DelDocSchema,\n type Doc,\n DocSchema,\n type SetDoc,\n SetDocSchema\n} from '../../../schemas/db';\n\n/**\n * @see DocUpsert\n */\nexport const DocUpsertSchema = z\n .object({\n before: DocSchema.optional(),\n after: DocSchema\n })\n .strict();\n\n/**\n * Represents a document update operation.\n *\n * This is used in hooks where a document is either being created or updated.\n */\nexport interface DocUpsert {\n /**\n * The previous version of the document before the update.\n * Undefined if this is a new document.\n */\n before?: Doc;\n\n /**\n * The new version of the document after the update.\n */\n after: Doc;\n}\n/**\n * @see DocAssertSet\n */\nexport const DocAssertSetSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: SetDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before setting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertSet {\n /**\n * The current version of the document before the operation.\n * Undefined if this is a new document.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: SetDoc;\n}\n\n/**\n * @see DocAssertDelete\n */\nexport const DocAssertDeleteSchema = z\n .object({\n current: DocSchema.optional(),\n proposed: DelDocSchema\n })\n .strict();\n\n/**\n * Represents a validation check before deleting a document.\n *\n * The developer can compare the `current` and `proposed` versions and\n * throw an error if their validation fails.\n */\nexport interface DocAssertDelete {\n /**\n * The current version of the document before the operation.\n * Undefined if the document does not exist.\n */\n current?: Doc;\n\n /**\n * The proposed version of the document.\n * This can be validated before allowing the operation.\n */\n proposed: DelDoc;\n}\n", "import * as z from 'zod';\nimport {AssetSchema, type Asset} from '../../../schemas/storage';\nimport {HookContextSchema, type HookContext} from '../context';\nimport {AssetAssertUploadSchema, type AssetAssertUpload} from './payload';\n\n/**\n * @see OnUploadAssetContext\n */\nexport const OnUploadAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `onUploadAsset` hook.\n *\n * This context contains information about the asset that was uploaded.\n */\nexport type OnUploadAssetContext = HookContext<Asset>;\n\n/**\n * @see OnDeleteAssetContext\n */\nexport const OnDeleteAssetContextSchema = HookContextSchema(AssetSchema.optional());\n\n/**\n * Context for the `onDeleteAsset` hook.\n *\n * This context contains information about a single asset being deleted, along with details about the user who triggered the operation.\n *\n * If undefined, the asset did not exist.\n */\nexport type OnDeleteAssetContext = HookContext<Asset | undefined>;\n\n/**\n * @see OnDeleteManyAssetsContext\n */\nexport const OnDeleteManyAssetsContextSchema = HookContextSchema(z.array(AssetSchema.optional()));\n\n/**\n * Context for the `onDeleteManyAssets` hook.\n *\n * This context contains information about multiple assets being potentially deleted, along with details about the user who triggered the operation.\n */\nexport type OnDeleteManyAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see OnDeleteFilteredAssetsContext\n */\nexport const OnDeleteFilteredAssetsContextSchema = HookContextSchema(\n z.array(AssetSchema.optional())\n);\n\n/**\n * Context for the `onDeleteFilteredAssets` hook.\n *\n * This context contains information about documents deleted as a result of a filter, along with details about the user who triggered the operation.\n */\nexport type OnDeleteFilteredAssetsContext = HookContext<Array<Asset | undefined>>;\n\n/**\n * @see AssertUploadAssetContext\n */\nexport const AssertUploadAssetContextSchema = HookContextSchema(AssetAssertUploadSchema);\n\n/**\n * Context for the `assertUploadAsset` hook.\n *\n * This context contains information about the asset being validated before it is uploaded. If validation fails, the developer should throw an error.\n */\nexport type AssertUploadAssetContext = HookContext<AssetAssertUpload>;\n\n/**\n * @see AssertDeleteAssetContext\n */\nexport const AssertDeleteAssetContextSchema = HookContextSchema(AssetSchema);\n\n/**\n * Context for the `assertDeleteAsset` hook.\n *\n * This context contains information about the asset being validated before it is deleted. If validation fails, the developer should throw an error.\n */\nexport type AssertDeleteAssetContext = HookContext<Asset>;\n", "import * as z from 'zod';\nimport {\n type Asset,\n AssetSchema,\n type Batch,\n BatchSchema,\n type CommitBatch,\n CommitBatchSchema\n} from '../../../schemas/storage';\n\n/**\n * @see AssetAssertUpload\n */\nexport const AssetAssertUploadSchema = z\n .object({\n current: AssetSchema.optional(),\n batch: BatchSchema,\n commit_batch: CommitBatchSchema\n })\n .strict();\n\n/**\n * Represents a validation context before uploading an asset.\n */\nexport interface AssetAssertUpload {\n /**\n * The current asset already stored (if any).\n */\n current?: Asset;\n\n /**\n * The batch metadata being uploaded.\n */\n batch: Batch;\n\n /**\n * The commit data describing headers and chunk ids.\n */\n commit_batch: CommitBatch;\n}\n", "import * as z from 'zod';\nimport {SatelliteEnvSchema} from '../schemas/satellite.env';\nimport {createFunctionSchema} from '../utils/zod.utils';\nimport {type Collections, CollectionsSchema} from './schemas/collections';\nimport {type RunFunction, RunFunctionSchema} from './schemas/context';\nimport {\n type OnDeleteDocContext,\n OnDeleteDocContextSchema,\n type OnDeleteFilteredDocsContext,\n OnDeleteFilteredDocsContextSchema,\n type OnDeleteManyDocsContext,\n OnDeleteManyDocsContextSchema,\n type OnSetDocContext,\n OnSetDocContextSchema,\n type OnSetManyDocsContext,\n OnSetManyDocsContextSchema\n} from './schemas/db/context';\nimport {\n type OnDeleteAssetContext,\n OnDeleteAssetContextSchema,\n type OnDeleteFilteredAssetsContext,\n OnDeleteFilteredAssetsContextSchema,\n type OnDeleteManyAssetsContext,\n OnDeleteManyAssetsContextSchema,\n type OnUploadAssetContext,\n OnUploadAssetContextSchema\n} from './schemas/storage/context';\n\n/**\n * @see OnHook\n */\nconst OnHookSchema = <T extends z.ZodTypeAny>(contextSchema: T) =>\n CollectionsSchema.extend({\n run: RunFunctionSchema<T>(contextSchema)\n }).strict();\n\n/**\n * A generic schema for defining hooks related to collections.\n *\n * @template T - The type of context passed to the hook when triggered.\n */\nexport type OnHook<T> = Collections & {\n /**\n * A function that runs when the hook is triggered for the specified collections.\n *\n * @param {T} context - Contains information about the affected document(s).\n * @returns {Promise<void>} Resolves when the operation completes.\n */\n run: RunFunction<T>;\n};\n\n/**\n * @see OnSetDoc\n */\nexport const OnSetDocSchema = OnHookSchema(OnSetDocContextSchema);\n\n/**\n * A hook that runs when a document is created or updated.\n */\nexport type OnSetDoc = OnHook<OnSetDocContext>;\n\n/**\n * @see OnSetManyDocs\n */\nexport const OnSetManyDocsSchema = OnHookSchema(OnSetManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are created or updated.\n */\nexport type OnSetManyDocs = OnHook<OnSetManyDocsContext>;\n\n/**\n * @see OnDeleteDoc\n */\nexport const OnDeleteDocSchema = OnHookSchema(OnDeleteDocContextSchema);\n\n/**\n * A hook that runs when a single document is deleted.\n */\nexport type OnDeleteDoc = OnHook<OnDeleteDocContext>;\n\n/**\n * @see OnDeleteManyDocs\n */\nexport const OnDeleteManyDocsSchema = OnHookSchema(OnDeleteManyDocsContextSchema);\n\n/**\n * A hook that runs when multiple documents are deleted.\n */\nexport type OnDeleteManyDocs = OnHook<OnDeleteManyDocsContext>;\n\n/**\n * @see OnDeleteFilteredDocs\n */\nexport const OnDeleteFilteredDocsSchema = OnHookSchema(OnDeleteFilteredDocsContextSchema);\n\n/**\n * A hook that runs when a filtered set of documents is deleted based on query conditions.\n */\nexport type OnDeleteFilteredDocs = OnHook<OnDeleteFilteredDocsContext>;\n\n/**\n * @see OnUploadAsset\n */\nexport const OnUploadAssetSchema = OnHookSchema(OnUploadAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is uploaded.\n */\nexport type OnUploadAsset = OnHook<OnUploadAssetContext>;\n\n/**\n * @see OnDeleteAsset\n */\nexport const OnDeleteAssetSchema = OnHookSchema(OnDeleteAssetContextSchema);\n\n/**\n * A hook that runs when a single asset is potentially deleted.\n */\nexport type OnDeleteAsset = OnHook<OnDeleteAssetContext>;\n\n/**\n * @see OnDeleteManyAssets\n */\nexport const OnDeleteManyAssetsSchema = OnHookSchema(OnDeleteManyAssetsContextSchema);\n\n/**\n * A hook that runs when multiple assets are potentially deleted.\n */\nexport type OnDeleteManyAssets = OnHook<OnDeleteManyAssetsContext>;\n\n/**\n * @see OnDeleteFilteredAssets\n */\nexport const OnDeleteFilteredAssetsSchema = OnHookSchema(OnDeleteFilteredAssetsContextSchema);\n\n/**\n * A hook that runs when a filtered set of assets is deleted based on query conditions.\n */\nexport type OnDeleteFilteredAssets = OnHook<OnDeleteFilteredAssetsContext>;\n\n/**\n * @see Hook\n */\nexport const HookSchema = z.union([\n OnSetDocSchema,\n OnSetManyDocsSchema,\n OnDeleteDocContextSchema,\n OnDeleteManyDocsContextSchema,\n OnDeleteFilteredDocsContextSchema,\n OnUploadAssetSchema,\n OnDeleteAssetSchema,\n OnDeleteManyAssetsSchema,\n OnDeleteFilteredAssetsSchema\n]);\n\n/**\n * All hooks definitions.\n */\nexport type Hook =\n | OnSetDoc\n | OnSetManyDocs\n | OnDeleteDoc\n | OnDeleteManyDocs\n | OnDeleteFilteredDocs\n | OnUploadAsset\n | OnDeleteAsset\n | OnDeleteManyAssets\n | OnDeleteFilteredAssets;\n\nexport const HookFnSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.function({input: z.tuple([SatelliteEnvSchema]), output: hookSchema});\nexport type HookFn<T extends Hook> = (hook: z.infer<typeof SatelliteEnvSchema>) => T;\n\nexport const HookFnOrObjectSchema = <T extends z.ZodTypeAny>(hookSchema: T) =>\n z.union([hookSchema, createFunctionSchema(HookFnSchema(hookSchema))]);\nexport type HookFnOrObject<T extends Hook> = T | HookFn<T>;\n\nexport function defineHook<T extends Hook>(hook: T): T;\nexport function defineHook<T extends Hook>(hook: HookFn<T>): HookFn<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T>;\nexport function defineHook<T extends Hook>(hook: HookFnOrObject<T>): HookFnOrObject<T> {\n return hook;\n}\n", "import {nonNullish} from '@junobuild/utils';\nimport * as z from 'zod';\nimport {decodeDocData, encodeDocData} from '../sdk/serializer.sdk';\nimport {QuerySchema} from './query';\nimport {CustomFunctionGuardSchema} from './schemas/function';\nimport {UpdateSchema} from './update';\n\nconst ConfigSchema = z.union([QuerySchema, UpdateSchema]);\ntype Config = z.infer<typeof ConfigSchema>;\n\nconst ConfigWithGuardSchema = ConfigSchema.and(\n z.strictObject({\n guard: CustomFunctionGuardSchema\n })\n);\n\nglobalThis.__juno_satellite_fn_guard_sync = (config: Config) => {\n const configWithGuard = ConfigWithGuardSchema.parse(config);\n configWithGuard.guard();\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_sync = (config: Config, raw?: Uint8Array<ArrayBuffer>) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = () => {\n if (nonNullish(args)) {\n return (config.handler as (args: unknown) => unknown)(args);\n }\n\n return (config.handler as () => unknown)();\n };\n\n const result = execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n\n// eslint-disable-next-line local-rules/prefer-object-params\nglobalThis.__juno_satellite_fn_invoke_async = async (\n config: Config,\n raw?: Uint8Array<ArrayBuffer>\n) => {\n ConfigSchema.parse(config);\n\n const args =\n 'args' in config && config.args instanceof z.ZodType\n ? config.args?.parse(nonNullish(raw) ? decodeDocData(raw) : undefined)\n : undefined;\n\n const execute = async () => {\n if (nonNullish(args)) {\n return await (config.handler as (args: unknown) => unknown)(args);\n }\n\n return await (config.handler as () => unknown)();\n };\n\n const result = await execute();\n\n const parsed =\n 'result' in config && config.result instanceof z.ZodType\n ? config.result?.parse(result)\n : undefined;\n\n globalThis.jsResult = nonNullish(parsed) ? encodeDocData(parsed) : parsed;\n};\n", "import {jsonReplacer} from '@junobuild/utils';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst __juno_satellite_console_log = (v: any[]) => {\n const msg = v\n .map((arg) => (typeof arg === 'object' ? JSON.stringify(arg, jsonReplacer) : arg))\n .join(' ');\n\n globalThis.__ic_cdk_print(msg);\n};\n\n// @ts-expect-error We want to override the console\nglobalThis.console = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n info(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n log(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n warn(...v: any[]) {\n __juno_satellite_console_log(v);\n },\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n error(...v: any[]) {\n __juno_satellite_console_log(v);\n }\n};\n", "/**\n * @see Math.random\n */\nconst random = (): number => {\n // __juno_satellite_random() returns a signed 32-bit int (i32)\n const value = __juno_satellite_random();\n\n // >>> 0 converts it to unsigned\n return (value >>> 0) / 2 ** 32;\n};\n\n/**\n * Overwrites Math.random with a pseudo-random number using the Satellite's internal RNG.\n *\n * \u26A0\uFE0F This function is not suitable for use cases requiring cryptographically secure or perfectly unpredictable randomness,\n * such as lotteries or gambling dApps.\n *\n * @returns {number} A pseudo-random 32-bit integer.\n *\n * @throws {Error} If the RNG has not been initialized.\n */\nglobalThis.Math.random = random;\n"],
5
+ "mappings": "4VAAA,UAAYA,MAAO,MCAnB,UAAYC,MAAO,MAKZ,IAAMC,EAAuB,SAAS,SAAO,EAAK,SAAO,CAAC,ECLjE,UAAYC,OAAO,MA0BZ,IAAMC,EAAiDC,GAC1D,UACCC,GAAO,OAAOA,GAAO,YAAcD,EAAO,UAAUC,CAAmC,CAC1F,ECzBK,IAAMC,EAAqB,CAChC,MAAO,wBACP,OAAQ,wBACV,ECPA,UAAYC,MAAO,MAUnB,IAAMC,EAA6B,eAAa,CAC9C,KAAQ,OAAK,CAACC,EAAmB,MAAOA,EAAmB,MAAM,CAAC,CACpE,CAAC,EAEYC,EAA4BC,EACrC,WAAS,CACT,OAAU,OAAK,CACjB,CAAC,CACH,EAKMC,EAA6B,eAAa,CAC9C,MAAOF,EAA0B,SAAS,EAC1C,OAAU,UAAQ,EAAE,SAAS,CAC/B,CAAC,EAKYG,EAA0C,eAAa,CAClE,GAAGL,EAAyB,MAC5B,GAAGI,EAAyB,MAC5B,KAAQ,aAAa,WAAS,EAC9B,OAAU,aAAa,WAAS,EAChC,QAASD,EACL,WAAS,CACT,MAAS,QAAM,CAAG,UAAQ,CAAC,CAAC,EAC5B,OAAU,QAAM,CAAG,UAAQ,EAAK,UAAU,UAAQ,CAAC,CAAC,CAAC,CACvD,CAAC,CACH,CACF,CAAC,EAKYG,EAAiC,eAAa,CACzD,GAAGN,EAAyB,MAC5B,GAAGI,EAAyB,MAC5B,KAAQ,aAAa,WAAS,EAC9B,QAASD,EACL,WAAS,CACT,MAAS,QAAM,CAAG,UAAQ,CAAC,CAAC,EAC5B,OAAU,QAAM,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WAAW,SAAWF,EAAWG,CAAM,EAAIC,EAAcD,CAAM,EAAIA,CACrE,EC5EA,OAAQ,gBAAAE,OAAmB,mBAG3B,IAAMC,EAAgCC,GAAa,CACjD,IAAMC,EAAMD,EACT,IAAKE,GAAS,OAAOA,GAAQ,SAAW,KAAK,UAAUA,EAAKJ,EAAY,EAAII,CAAI,EAChF,KAAK,GAAG,EAEX,WAAW,eAAeD,CAAG,CAC/B,EAGA,WAAW,QAAU,CAEnB,QAAQD,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,OAAOA,EAAU,CACfD,EAA6BC,CAAC,CAChC,EAEA,QAAQA,EAAU,CAChBD,EAA6BC,CAAC,CAChC,EAEA,SAASA,EAAU,CACjBD,EAA6BC,CAAC,CAChC,CACF,EC1BA,IAAMG,GAAS,KAEC,wBAAwB,IAGpB,GAAK,WAazB,WAAW,KAAK,OAASA",
6
+ "names": ["z", "z", "SatelliteEnvSchema", "z", "createFunctionSchema", "schema", "fn", "JUNO_FUNCTION_TYPE", "z", "CustomFunctionTypeSchema", "JUNO_FUNCTION_TYPE", "CustomFunctionGuardSchema", "createFunctionSchema", "CustomFunctionBaseSchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "CustomFunctionSchema", "QueryBaseSchema", "JUNO_FUNCTION_TYPE", "QuerySchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "QueryFnSchema", "querySchema", "SatelliteEnvSchema", "QueryFnOrObjectSchema", "createFunctionSchema", "defineQuery", "query", "env", "result", "z", "UpdateBaseSchema", "JUNO_FUNCTION_TYPE", "UpdateSchema", "CustomFunctionWithArgsAndResultSchema", "CustomFunctionWithArgsSchema", "CustomFunctionWithResultSchema", "CustomFunctionWithoutArgsAndResultSchema", "UpdateFnSchema", "updateSchema", "SatelliteEnvSchema", "UpdateFnOrObjectSchema", "createFunctionSchema", "defineUpdate", "update", "env", "result", "z", "CollectionsSchema", "z", "HookContextSchema", "dataSchema", "RawUserIdSchema", "AssertFunctionSchema", "contextSchema", "createFunctionSchema", "RunFunctionSchema", "z", "z", "DocUpsertSchema", "DocSchema", "DocAssertSetSchema", "SetDocSchema", "DocAssertDeleteSchema", "DelDocSchema", "DocContextSchema", "dataSchema", "CollectionSchema", "KeySchema", "OnSetDocContextSchema", "HookContextSchema", "DocUpsertSchema", "OnSetManyDocsContextSchema", "OnDeleteDocContextSchema", "DocSchema", "OnDeleteManyDocsContextSchema", "OnDeleteFilteredDocsContextSchema", "AssertSetDocContextSchema", "DocAssertSetSchema", "AssertDeleteDocContextSchema", "DocAssertDeleteSchema", "z", "z", "AssetAssertUploadSchema", "AssetSchema", "BatchSchema", "CommitBatchSchema", "OnUploadAssetContextSchema", "HookContextSchema", "AssetSchema", "OnDeleteAssetContextSchema", "OnDeleteManyAssetsContextSchema", "OnDeleteFilteredAssetsContextSchema", "AssertUploadAssetContextSchema", "AssetAssertUploadSchema", "AssertDeleteAssetContextSchema", "OnAssertSchema", "contextSchema", "CollectionsSchema", "AssertFunctionSchema", "AssertSetDocSchema", "AssertSetDocContextSchema", "AssertDeleteDocSchema", "AssertDeleteDocContextSchema", "AssertUploadAssetSchema", "AssertUploadAssetContextSchema", "AssertDeleteAssetSchema", "AssertDeleteAssetContextSchema", "AssertSchema", "AssertFnSchema", "assertSchema", "SatelliteEnvSchema", "AssertFnOrObjectSchema", "createFunctionSchema", "defineAssert", "assert", "z", "OnHookSchema", "contextSchema", "CollectionsSchema", "RunFunctionSchema", "OnSetDocSchema", "OnSetDocContextSchema", "OnSetManyDocsSchema", "OnSetManyDocsContextSchema", "OnDeleteDocSchema", "OnDeleteDocContextSchema", "OnDeleteManyDocsSchema", "OnDeleteManyDocsContextSchema", "OnDeleteFilteredDocsSchema", "OnDeleteFilteredDocsContextSchema", "OnUploadAssetSchema", "OnUploadAssetContextSchema", "OnDeleteAssetSchema", "OnDeleteAssetContextSchema", "OnDeleteManyAssetsSchema", "OnDeleteManyAssetsContextSchema", "OnDeleteFilteredAssetsSchema", "OnDeleteFilteredAssetsContextSchema", "HookSchema", "HookFnSchema", "hookSchema", "SatelliteEnvSchema", "HookFnOrObjectSchema", "createFunctionSchema", "defineHook", "hook", "nonNullish", "z", "ConfigSchema", "QuerySchema", "UpdateSchema", "ConfigWithGuardSchema", "CustomFunctionGuardSchema", "config", "raw", "args", "nonNullish", "decodeDocData", "result", "parsed", "encodeDocData", "jsonReplacer", "__juno_satellite_console_log", "v", "msg", "arg", "random"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@junobuild/functions",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "JavaScript and TypeScript utilities for Juno Serverless Functions",
5
5
  "author": "David Dal Busco (https://daviddalbusco.com)",
6
6
  "license": "MIT",
@@ -94,9 +94,9 @@
94
94
  ],
95
95
  "homepage": "https://juno.build",
96
96
  "peerDependencies": {
97
- "@dfinity/utils": "^4.1",
98
97
  "@icp-sdk/core": "^5",
99
- "@junobuild/schema": "^1.1",
98
+ "@junobuild/schema": "^1.2",
99
+ "@junobuild/utils": "^1",
100
100
  "zod": "^4.3"
101
101
  }
102
102
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @see RawPrincipal
3
+ */
4
+ export declare const RawPrincipalSchema: import("zod").ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
5
+ /**
6
+ * Represents a raw principal - a Uint8Array representation of a Principal.
7
+ */
8
+ export type RawPrincipal = Uint8Array;
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import { type RawPrincipal } from './candid';
2
+ import { type RawPrincipal } from './principal';
3
3
  /**
4
4
  * @see Timestamp
5
5
  */
@@ -0,0 +1,50 @@
1
+ import { type AccessKeyCheckParams, type AccessKeys } from './schemas/access-keys';
2
+ /**
3
+ * Gets the list of admin access keys from the Satellite.
4
+ *
5
+ * @returns {AccessKeys} The list of admin acces keys.
6
+ *
7
+ * @throws {z.ZodError} If the returned value does not match the expected schema.
8
+ */
9
+ export declare const getAdminAccessKeys: () => AccessKeys;
10
+ /**
11
+ * Gets the list of access keys from the Satellite.
12
+ *
13
+ * @returns {AccessKeys} The list of all access keys.
14
+ *
15
+ * @throws {z.ZodError} If the returned value does not match the expected schema.
16
+ */
17
+ export declare const getAccessKeys: () => AccessKeys;
18
+ /**
19
+ * Checks if the given id exists among the provided access keys.
20
+ *
21
+ * @param {AccessKeyCheckParams} params - The parameters including the id
22
+ * and the list of access keys to verify against.
23
+ *
24
+ * @returns {boolean} Whether the id is an access key with write permission.
25
+ *
26
+ * @throws {z.ZodError} If any input does not match the expected schema.
27
+ */
28
+ export declare const isWriteAccessKey: (params: AccessKeyCheckParams) => boolean;
29
+ /**
30
+ * Checks if the given id exists among the provided access keys.
31
+ *
32
+ * @param {AccessKeyCheckParams} params - The parameters including the id
33
+ * and the list of access keys to verify against.
34
+ *
35
+ * @returns {boolean} Whether the id is an access key.
36
+ *
37
+ * @throws {z.ZodError} If any input does not match the expected schema.
38
+ */
39
+ export declare const isValidAccessKey: (params: AccessKeyCheckParams) => boolean;
40
+ /**
41
+ * Checks if the given id is an admin among the provided access keys and a controller as known on the Internet Computer.
42
+ *
43
+ * @param {AccessKeyCheckParams} params - The parameters including the id
44
+ * and the list of access keys to verify against.
45
+ *
46
+ * @returns {boolean} Whether the id is an admin and a controller of the Satellite on the Internet Computer.
47
+ *
48
+ * @throws {z.ZodError} If any input does not match the expected schema.
49
+ */
50
+ export declare const isAdminController: (params: AccessKeyCheckParams) => boolean;
@@ -0,0 +1,25 @@
1
+ import type { AccessKeys } from './schemas/access-keys';
2
+ /**
3
+ * Guard that succeeds if the caller is an admin access key of this satellite.
4
+ *
5
+ * @returns {void}
6
+ *
7
+ * @throws {z.ZodError} If the caller is not an admin access key.
8
+ */
9
+ export declare const callerIsAdmin: () => void;
10
+ /**
11
+ * Guard that succeeds if the caller is an access key with write permission.
12
+ *
13
+ * @returns {void}
14
+ *
15
+ * @throws {z.ZodError} If the caller does not have write permission.
16
+ */
17
+ export declare const callerHasWritePermission: () => AccessKeys;
18
+ /**
19
+ * Guard that succeeds if the caller is any recognized access key of this satellite.
20
+ *
21
+ * @returns {void}
22
+ *
23
+ * @throws {z.ZodError} If the caller is not a recognized access key.
24
+ */
25
+ export declare const callerIsAccessKey: () => AccessKeys;
@@ -1,28 +1,29 @@
1
1
  import * as z from 'zod';
2
+ import { type RawPrincipal } from '../../schemas/principal';
2
3
  import { type RawUserId, type Timestamp, type UserId } from '../../schemas/satellite';
3
4
  /**
4
- * @see ControllerScope
5
+ * @see AccessKeyScope
5
6
  */
6
- export declare const ControllerScopeSchema: z.ZodEnum<{
7
+ export declare const AccessKeyScopeSchema: z.ZodEnum<{
7
8
  write: "write";
8
9
  admin: "admin";
9
10
  submit: "submit";
10
11
  }>;
11
12
  /**
12
- * Represents the permission scope of a controller.
13
+ * Represents the permission scope of an access key.
13
14
  */
14
- export type ControllerScope = z.infer<typeof ControllerScopeSchema>;
15
+ export type AccessKeyScope = z.infer<typeof AccessKeyScopeSchema>;
15
16
  /**
16
- * @see ControllerKind
17
+ * @see AccessKeyKind
17
18
  */
18
- export declare const ControllerKindSchema: z.ZodEnum<{
19
+ export declare const AccessKeyKindSchema: z.ZodEnum<{
19
20
  automation: "automation";
20
21
  emulator: "emulator";
21
22
  }>;
22
23
  /**
23
- * Represents a specific kind of controller. Meant for informational purposes.
24
+ * Represents a specific kind of access key. Meant for informational purposes.
24
25
  */
25
- export type ControllerKind = z.infer<typeof ControllerKindSchema>;
26
+ export type AccessKeyKind = z.infer<typeof AccessKeyKindSchema>;
26
27
  /**
27
28
  * @see MetadataSchema
28
29
  */
@@ -32,9 +33,9 @@ export declare const MetadataSchema: z.ZodTuple<[z.ZodString, z.ZodString], null
32
33
  */
33
34
  export type Metadata = z.infer<typeof MetadataSchema>;
34
35
  /**
35
- * @see ControllerSchema
36
+ * @see AccessKeySchema
36
37
  */
37
- export declare const ControllerSchema: z.ZodObject<{
38
+ export declare const AccessKeySchema: z.ZodObject<{
38
39
  metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>;
39
40
  created_at: z.ZodBigInt;
40
41
  updated_at: z.ZodBigInt;
@@ -50,38 +51,38 @@ export declare const ControllerSchema: z.ZodObject<{
50
51
  }>>;
51
52
  }, z.core.$strict>;
52
53
  /**
53
- * Represents a controller with access scope and associated metadata.
54
+ * Represents an access key with access scope and associated metadata.
54
55
  */
55
- export interface Controller {
56
+ export interface AccessKey {
56
57
  /**
57
- * A list of key-value metadata pairs associated with the controller.
58
+ * A list of key-value metadata pairs associated with the access key.
58
59
  */
59
60
  metadata: Metadata[];
60
61
  /**
61
- * The timestamp when the controller was created.
62
+ * The timestamp when the access key was created.
62
63
  */
63
64
  created_at: Timestamp;
64
65
  /**
65
- * The timestamp when the controller was last updated.
66
+ * The timestamp when the access key was last updated.
66
67
  */
67
68
  updated_at: Timestamp;
68
69
  /**
69
- * Optional expiration timestamp for the controller.
70
+ * Optional expiration timestamp for the access key.
70
71
  */
71
72
  expires_at?: Timestamp;
72
73
  /**
73
- * The scope assigned to the controller.
74
+ * The scope assigned to the access key.
74
75
  */
75
- scope: ControllerScope;
76
+ scope: AccessKeyScope;
76
77
  /**
77
- * An optional kind identifier of the controller.
78
+ * An optional kind identifier of the access key.
78
79
  */
79
- kind?: ControllerKind;
80
+ kind?: AccessKeyKind;
80
81
  }
81
82
  /**
82
- * @see ControllerRecordSchema
83
+ * @see AccessKeyRecordSchema
83
84
  */
84
- export declare const ControllerRecordSchema: z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
85
+ export declare const AccessKeyRecordSchema: z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
85
86
  metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>;
86
87
  created_at: z.ZodBigInt;
87
88
  updated_at: z.ZodBigInt;
@@ -97,13 +98,13 @@ export declare const ControllerRecordSchema: z.ZodTuple<[z.ZodCustom<Uint8Array<
97
98
  }>>;
98
99
  }, z.core.$strict>], null>;
99
100
  /**
100
- * Represents a tuple containing the principal ID and associated controller data.
101
+ * Represents a tuple containing the principal ID and associated access key data.
101
102
  */
102
- export type ControllerRecord = z.infer<typeof ControllerRecordSchema>;
103
+ export type AccessKeyRecord = z.infer<typeof AccessKeyRecordSchema>;
103
104
  /**
104
- * @see ControllersSchema
105
+ * @see AccessKeysSchema
105
106
  */
106
- export declare const ControllersSchema: z.ZodArray<z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
107
+ export declare const AccessKeysSchema: z.ZodArray<z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
107
108
  metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>;
108
109
  created_at: z.ZodBigInt;
109
110
  updated_at: z.ZodBigInt;
@@ -119,15 +120,15 @@ export declare const ControllersSchema: z.ZodArray<z.ZodTuple<[z.ZodCustom<Uint8
119
120
  }>>;
120
121
  }, z.core.$strict>], null>>;
121
122
  /**
122
- * Represents a list of controllers.
123
+ * Represents a list of access keys.
123
124
  */
124
- export type Controllers = z.infer<typeof ControllersSchema>;
125
+ export type AccessKeys = [RawPrincipal, AccessKey][];
125
126
  /**
126
- * @see ControllerCheckParamsSchema
127
+ * @see AccessKeyCheckParamsSchema
127
128
  */
128
- export declare const ControllerCheckParamsSchema: z.ZodObject<{
129
- caller: z.ZodUnion<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodPipe<z.ZodCustom<import("@icp-sdk/core/principal").Principal, import("@icp-sdk/core/principal").Principal>, z.ZodTransform<import("@icp-sdk/core/principal").Principal, import("@icp-sdk/core/principal").Principal>>]>;
130
- controllers: z.ZodArray<z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
129
+ export declare const AccessKeyCheckParamsSchema: z.ZodObject<{
130
+ id: z.ZodUnion<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodPipe<z.ZodCustom<import("@icp-sdk/core/principal").Principal, import("@icp-sdk/core/principal").Principal>, z.ZodTransform<import("@icp-sdk/core/principal").Principal, import("@icp-sdk/core/principal").Principal>>]>;
131
+ accessKeys: z.ZodArray<z.ZodTuple<[z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>, z.ZodObject<{
131
132
  metadata: z.ZodArray<z.ZodTuple<[z.ZodString, z.ZodString], null>>;
132
133
  created_at: z.ZodBigInt;
133
134
  updated_at: z.ZodBigInt;
@@ -144,15 +145,15 @@ export declare const ControllerCheckParamsSchema: z.ZodObject<{
144
145
  }, z.core.$strict>], null>>;
145
146
  }, z.core.$strip>;
146
147
  /**
147
- * Represents the parameters required to perform controller checks.
148
+ * Represents the parameters required to perform an access key checks.
148
149
  */
149
- export interface ControllerCheckParams {
150
+ export interface AccessKeyCheckParams {
150
151
  /**
151
- * The identity of the caller to verify against the controller list.
152
+ * The identity to verify against the access keys.
152
153
  */
153
- caller: RawUserId | UserId;
154
+ id: RawUserId | UserId;
154
155
  /**
155
- * The list of controllers to check against.
156
+ * The list of access keys to check against.
156
157
  */
157
- controllers: Controllers;
158
+ accessKeys: AccessKeys;
158
159
  }
package/sdk.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export * from './sdk/controllers.sdk';
1
+ export * from './sdk/access-keys.sdk';
2
2
  export * from './sdk/db.sdk';
3
+ export * from './sdk/guards.sdk';
4
+ export * from './sdk/schemas/access-keys';
3
5
  export * from './sdk/schemas/collections';
4
- export * from './sdk/schemas/controllers';
5
6
  export * from './sdk/schemas/db';
6
7
  export * from './sdk/schemas/params';
7
8
  export * from './sdk/schemas/storage';