@junobuild/core-peer 0.0.9 → 0.0.10-next-2024-02-17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 David Dal Busco
3
+ Copyright (c) 2024 David Dal Busco
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,4 +1,5 @@
1
1
  import type {ActorMethod} from '@dfinity/agent';
2
+ import type {IDL} from '@dfinity/candid';
2
3
  import type {Principal} from '@dfinity/principal';
3
4
 
4
5
  export interface AssetEncodingNoContent {
@@ -193,6 +194,7 @@ export interface UploadChunkResult {
193
194
  chunk_id: bigint;
194
195
  }
195
196
  export interface _SERVICE {
197
+ build_version: ActorMethod<[], string>;
196
198
  commit_asset_upload: ActorMethod<[CommitBatch], undefined>;
197
199
  count_assets: ActorMethod<[string], bigint>;
198
200
  count_docs: ActorMethod<[string], bigint>;
@@ -206,8 +208,10 @@ export interface _SERVICE {
206
208
  del_many_docs: ActorMethod<[Array<[string, string, DelDoc]>], undefined>;
207
209
  del_rule: ActorMethod<[RulesType, string, DelDoc], undefined>;
208
210
  deposit_cycles: ActorMethod<[DepositCyclesArgs], undefined>;
211
+ get_asset: ActorMethod<[string, string], [] | [AssetNoContent]>;
209
212
  get_config: ActorMethod<[], Config>;
210
213
  get_doc: ActorMethod<[string, string], [] | [Doc]>;
214
+ get_many_assets: ActorMethod<[Array<[string, string]>], Array<[string, [] | [AssetNoContent]]>>;
211
215
  get_many_docs: ActorMethod<[Array<[string, string]>], Array<[string, [] | [Doc]]>>;
212
216
  http_request: ActorMethod<[HttpRequest], HttpResponse>;
213
217
  http_request_streaming_callback: ActorMethod<
@@ -230,3 +234,4 @@ export interface _SERVICE {
230
234
  upload_asset_chunk: ActorMethod<[UploadChunk], UploadChunkResult>;
231
235
  version: ActorMethod<[], string>;
232
236
  }
237
+ export declare const idlFactory: IDL.InterfaceFactory;
@@ -25,6 +25,26 @@ export const idlFactory = ({IDL}) => {
25
25
  cycles: IDL.Nat,
26
26
  destination_id: IDL.Principal
27
27
  });
28
+ const AssetKey = IDL.Record({
29
+ token: IDL.Opt(IDL.Text),
30
+ collection: IDL.Text,
31
+ owner: IDL.Principal,
32
+ name: IDL.Text,
33
+ description: IDL.Opt(IDL.Text),
34
+ full_path: IDL.Text
35
+ });
36
+ const AssetEncodingNoContent = IDL.Record({
37
+ modified: IDL.Nat64,
38
+ sha256: IDL.Vec(IDL.Nat8),
39
+ total_length: IDL.Nat
40
+ });
41
+ const AssetNoContent = IDL.Record({
42
+ key: AssetKey,
43
+ updated_at: IDL.Nat64,
44
+ encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
45
+ headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
46
+ created_at: IDL.Nat64
47
+ });
28
48
  const StorageConfigIFrame = IDL.Variant({
29
49
  Deny: IDL.Null,
30
50
  AllowAny: IDL.Null,
@@ -110,26 +130,6 @@ export const idlFactory = ({IDL}) => {
110
130
  matcher: IDL.Opt(ListMatcher),
111
131
  paginate: IDL.Opt(ListPaginate)
112
132
  });
113
- const AssetKey = IDL.Record({
114
- token: IDL.Opt(IDL.Text),
115
- collection: IDL.Text,
116
- owner: IDL.Principal,
117
- name: IDL.Text,
118
- description: IDL.Opt(IDL.Text),
119
- full_path: IDL.Text
120
- });
121
- const AssetEncodingNoContent = IDL.Record({
122
- modified: IDL.Nat64,
123
- sha256: IDL.Vec(IDL.Nat8),
124
- total_length: IDL.Nat
125
- });
126
- const AssetNoContent = IDL.Record({
127
- key: AssetKey,
128
- updated_at: IDL.Nat64,
129
- encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
130
- headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
131
- created_at: IDL.Nat64
132
- });
133
133
  const ListResults = IDL.Record({
134
134
  matches_pages: IDL.Opt(IDL.Nat64),
135
135
  matches_length: IDL.Nat64,
@@ -194,6 +194,7 @@ export const idlFactory = ({IDL}) => {
194
194
  });
195
195
  const UploadChunkResult = IDL.Record({chunk_id: IDL.Nat});
196
196
  return IDL.Service({
197
+ build_version: IDL.Func([], [IDL.Text], ['query']),
197
198
  commit_asset_upload: IDL.Func([CommitBatch], [], []),
198
199
  count_assets: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
199
200
  count_docs: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
@@ -211,8 +212,14 @@ export const idlFactory = ({IDL}) => {
211
212
  del_many_docs: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, DelDoc))], [], []),
212
213
  del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
213
214
  deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
215
+ get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
214
216
  get_config: IDL.Func([], [Config], []),
215
217
  get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
218
+ get_many_assets: IDL.Func(
219
+ [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
220
+ [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(AssetNoContent)))],
221
+ ['query']
222
+ ),
216
223
  get_many_docs: IDL.Func(
217
224
  [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
218
225
  [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
@@ -25,6 +25,26 @@ export const idlFactory = ({IDL}) => {
25
25
  cycles: IDL.Nat,
26
26
  destination_id: IDL.Principal
27
27
  });
28
+ const AssetKey = IDL.Record({
29
+ token: IDL.Opt(IDL.Text),
30
+ collection: IDL.Text,
31
+ owner: IDL.Principal,
32
+ name: IDL.Text,
33
+ description: IDL.Opt(IDL.Text),
34
+ full_path: IDL.Text
35
+ });
36
+ const AssetEncodingNoContent = IDL.Record({
37
+ modified: IDL.Nat64,
38
+ sha256: IDL.Vec(IDL.Nat8),
39
+ total_length: IDL.Nat
40
+ });
41
+ const AssetNoContent = IDL.Record({
42
+ key: AssetKey,
43
+ updated_at: IDL.Nat64,
44
+ encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
45
+ headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
46
+ created_at: IDL.Nat64
47
+ });
28
48
  const StorageConfigIFrame = IDL.Variant({
29
49
  Deny: IDL.Null,
30
50
  AllowAny: IDL.Null,
@@ -110,26 +130,6 @@ export const idlFactory = ({IDL}) => {
110
130
  matcher: IDL.Opt(ListMatcher),
111
131
  paginate: IDL.Opt(ListPaginate)
112
132
  });
113
- const AssetKey = IDL.Record({
114
- token: IDL.Opt(IDL.Text),
115
- collection: IDL.Text,
116
- owner: IDL.Principal,
117
- name: IDL.Text,
118
- description: IDL.Opt(IDL.Text),
119
- full_path: IDL.Text
120
- });
121
- const AssetEncodingNoContent = IDL.Record({
122
- modified: IDL.Nat64,
123
- sha256: IDL.Vec(IDL.Nat8),
124
- total_length: IDL.Nat
125
- });
126
- const AssetNoContent = IDL.Record({
127
- key: AssetKey,
128
- updated_at: IDL.Nat64,
129
- encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)),
130
- headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
131
- created_at: IDL.Nat64
132
- });
133
133
  const ListResults = IDL.Record({
134
134
  matches_pages: IDL.Opt(IDL.Nat64),
135
135
  matches_length: IDL.Nat64,
@@ -194,6 +194,7 @@ export const idlFactory = ({IDL}) => {
194
194
  });
195
195
  const UploadChunkResult = IDL.Record({chunk_id: IDL.Nat});
196
196
  return IDL.Service({
197
+ build_version: IDL.Func([], [IDL.Text], ['query']),
197
198
  commit_asset_upload: IDL.Func([CommitBatch], [], []),
198
199
  count_assets: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
199
200
  count_docs: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
@@ -211,8 +212,14 @@ export const idlFactory = ({IDL}) => {
211
212
  del_many_docs: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, DelDoc))], [], []),
212
213
  del_rule: IDL.Func([RulesType, IDL.Text, DelDoc], [], []),
213
214
  deposit_cycles: IDL.Func([DepositCyclesArgs], [], []),
215
+ get_asset: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(AssetNoContent)], ['query']),
214
216
  get_config: IDL.Func([], [Config], []),
215
217
  get_doc: IDL.Func([IDL.Text, IDL.Text], [IDL.Opt(Doc)], ['query']),
218
+ get_many_assets: IDL.Func(
219
+ [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
220
+ [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(AssetNoContent)))],
221
+ ['query']
222
+ ),
216
223
  get_many_docs: IDL.Func(
217
224
  [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))],
218
225
  [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
@@ -1,2 +1,2 @@
1
- import{Principal as I}from"@dfinity/principal";var l=t=>t==null,c=t=>!l(t);var q="__bigint__",j="__principal__",H="__uint8array__",zt=(t,e)=>typeof e=="bigint"?{[q]:`${e}`}:c(e)&&e instanceof I?{[j]:e.toText()}:c(e)&&e instanceof Uint8Array?{[H]:Array.from(e)}:e,Gt=(t,e)=>{let o=s=>e[s];return c(e)&&typeof e=="object"&&q in e?BigInt(o(q)):c(e)&&typeof e=="object"&&j in e?I.fromText(o(j)):c(e)&&typeof e=="object"&&H in e?Uint8Array.from(o(H)):e},p=t=>c(t)?[t]:[],y=t=>t?.[0],L=async t=>{let e=new Blob([JSON.stringify(t,zt)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},C=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),Gt)},E=()=>typeof window<"u";var R=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:o})=>o(e))}subscribe(e){let o=Symbol();return this.callbacks.push({id:o,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:s})=>s!==o)}};var w=class t extends R{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let o=super.subscribe(e);return e(this.authUser),o}reset(){this.authUser=null,this.populate(this.authUser)}};var z=({message:t,detail:e})=>{let o=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(o)};var tt=BigInt(144e11),et={width:576,height:576},ot={width:505,height:705},st="internetcomputer.org";var k="http://127.0.0.1:5987",it="rdmx6-jaaaa-aaaaa-aaadq-cai";var _=class t extends R{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let o=super.subscribe(e);return e(this.env),o}};var G=({width:t,height:e})=>{if(!E()||l(window)||l(window.top))return;let{top:{innerWidth:o,innerHeight:s}}=window,i=s/2+screenY-e/2,n=o/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${n}`};var F=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let o=()=>{let s=_.getInstance().get()?.container;if(l(s)||s===!1)return`https://identity.${this.#t??st}`;let i=_.getInstance().get(),n=c(i)&&c(i?.internetIdentityId)?i.internetIdentityId:it,{host:r,protocol:a}=new URL(s===!0?k:s);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:G(et)},identityProvider:o()}}},nt=class{#t;#e;constructor({appName:e,logoUrl:o}){this.#t=e,this.#e=o}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:G(ot)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as Wt}from"@dfinity/auth-client";var V=()=>Wt.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var rt=async({data:t})=>{try{return await C(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var W=async t=>{let{data:e,updated_at:o,description:s}=t;return{description:p(s),data:await L(e),updated_at:p(o)}},Y=t=>{let{updated_at:e}=t;return{updated_at:p(e)}},v=async({doc:t,key:e})=>{let{owner:o,description:s,data:i,...n}=t;return{key:e,description:y(s),owner:o.toText(),data:await C(i),...n}};import{Principal as Yt}from"@dfinity/principal";var M=({matcher:t,paginate:e,order:o,owner:s})=>({matcher:l(t)?[]:[{key:p(t.key),description:p(t.description)}],paginate:p(l(e)?void 0:{start_after:p(e.startAfter),limit:p(l(e.limit)?void 0:BigInt(e.limit))}),order:p(l(o)?void 0:{desc:o.desc,field:o.field==="created_at"?{CreatedAt:null}:o.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:p(l(s)?void 0:typeof s=="string"?Yt.fromText(s):s)});var at=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),o=t.Record({controllers:t.Vec(t.Principal)}),s=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:s,expires_at:t.Opt(t.Nat64)}),n=t.Record({updated_at:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),d=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),f=t.Record({status_code:t.Nat16,location:t.Text}),u=t.Record({iframe:t.Opt(d),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),redirects:t.Opt(t.Vec(t.Tuple(t.Text,f)))}),g=t.Record({storage:u}),A=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),b=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),P=t.Variant({Heap:t.Null,Stable:t.Null}),h=t.Record({memory:P,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),O=t.Variant({Callback:t.Record({token:h,callback:t.Func([],[],["query"])})}),m=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(O),status_code:t.Nat16}),S=t.Record({token:t.Opt(h),body:t.Vec(t.Nat8)}),B=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),K=t.Record({batch_id:t.Nat}),Ot=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),St=t.Record({field:Ot,desc:t.Bool}),Rt=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),kt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),Z=t.Record({order:t.Opt(St),owner:t.Opt(t.Principal),matcher:t.Opt(Rt),paginate:t.Opt(kt)}),vt=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),Ut=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),Ct=t.Record({key:vt,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,Ut)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),Et=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,Ct)),items_length:t.Nat64}),Ft=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),Vt=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,A)),items_length:t.Nat64}),U=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Mt=t.Record({memory:t.Opt(P),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:U,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:U}),$t=t.Record({stable:t.Nat64,heap:t.Nat64}),Bt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:s,expires_at:t.Opt(t.Nat64)}),Kt=t.Record({controller:Bt,controllers:t.Vec(t.Principal)}),D=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),qt=t.Record({memory:t.Opt(P),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:U,mutable_permissions:t.Opt(t.Bool),write:U}),jt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Ht=t.Record({chunk_id:t.Nat});return t.Service({commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([o],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,n],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,n))],[],[]),del_rule:t.Func([r,t.Text,n],[],[]),deposit_cycles:t.Func([a],[],[]),get_config:t.Func([],[g],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(A)],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(A)))],["query"]),http_request:t.Func([b],[m],["query"]),http_request_streaming_callback:t.Func([h],[S],["query"]),init_asset_upload:t.Func([B],[K],[]),list_assets:t.Func([t.Text,Z],[Et],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Ft))],["query"]),list_docs:t.Func([t.Text,Z],[Vt],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Mt))],["query"]),memory_size:t.Func([],[$t],["query"]),set_config:t.Func([g],[],[]),set_controllers:t.Func([Kt],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,D],[A],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,D))],[t.Vec(t.Tuple(t.Text,A))],[]),set_rule:t.Func([r,t.Text,qt],[],[]),upload_asset_chunk:t.Func([jt],[Ht],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as Jt,HttpAgent as Xt}from"@dfinity/agent";var ct=async({satelliteId:t,idlFactory:e,identity:o,fetch:s,container:i})=>{let r=c(i)&&i!==!1?i===!0?k:i:"https://icp-api.io",a=new Xt({identity:o,host:r,...s&&{fetch:s}});return c(i)&&await a.fetchRootKey(),Jt.createActor(e,{agent:a,canisterId:t})};var T=async({satelliteId:t,container:e,...o})=>{let{satelliteId:s}=c(t)?{satelliteId:t}:_.getInstance().get()??{satelliteId:void 0},{container:i}=c(e)?{container:e}:_.getInstance().get()??{container:void 0};if(!s)throw new Error("No satellite principal defined.");return ct({satelliteId:s,container:i,idlFactory:at,...o})};var lt=async({collection:t,key:e,satellite:o})=>{let s=await T(o),i=y(await s.get_doc(t,e));if(!l(i))return v({doc:i,key:e})},pt=async({docs:t,satellite:e})=>{let{get_many_docs:o}=await T(e),s=t.map(({collection:r,key:a})=>[r,a]),i=await o(s),n=[];for(let[r,a]of i){let d=y(a);n.push(c(d)?await v({key:r,doc:d}):void 0)}return n},dt=async({collection:t,doc:e,satellite:o})=>{let{set_doc:s}=await T(o),{key:i}=e,n=await W(e),r=await s(t,i,n);return await v({key:i,doc:r})},ut=async({docs:t,satellite:e})=>{let{set_many_docs:o}=await T(e),s=[];for(let{collection:r,doc:a}of t){let{key:d}=a;s.push([r,d,await W(a)])}let i=await o(s),n=[];for(let[r,a]of i)n.push(await v({key:r,doc:a}));return n},mt=async({collection:t,doc:e,satellite:o})=>{let{del_doc:s}=await T(o),{key:i}=e;return s(t,i,Y(e))},yt=async({docs:t,satellite:e})=>{let{del_many_docs:o}=await T(e),s=t.map(({collection:i,doc:n})=>[i,n.key,Y(n)]);await o(s)},ft=async({collection:t,filter:e,satellite:o})=>{let s=await T(o),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:d}=await s.list_docs(t,M(e)),f=[];for(let[u,g]of i){let{data:A,owner:b,description:P,...h}=g;f.push({key:u,description:y(P),owner:b.toText(),data:await rt({data:A}),...h})}return{items:f,items_length:r,items_page:y(n),matches_length:a,matches_pages:y(d)}};import{AnonymousIdentity as Qt}from"@dfinity/agent";var x=t=>t!==void 0?t:$()??new Qt;var gt=async({satellite:t,...e})=>{let o=x(t?.identity);return lt({...e,satellite:{...t,identity:o}})},Qe=async({satellite:t,...e})=>{let o=x(t?.identity);return pt({...e,satellite:{...t,identity:o}})},ht=async({satellite:t,...e})=>{let o=x(t?.identity);return dt({...e,satellite:{...t,identity:o}})},Ze=async({satellite:t,...e})=>{let o=x(t?.identity);return ut({...e,satellite:{...t,identity:o}})},De=async({satellite:t,...e})=>{let o=x(t?.identity);return mt({...e,satellite:{...t,identity:o}})},Ie=async({satellite:t,...e})=>{let o=x(t?.identity);return yt({...e,satellite:{...t,identity:o}})},Le=async({satellite:t,filter:e,...o})=>{let s=x(t?.identity);return ft({...o,filter:e??{},satellite:{...t,identity:s}})};var _t=async t=>{let e=$();if(l(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let o=e.getPrincipal().toText(),s=await gt({collection:"#user",key:o});return l(s)?await Zt({userId:o,provider:t}):s},Zt=async({userId:t,...e})=>ht({collection:"#user",doc:{key:t,data:e}});var N,J=async t=>{if(N=N??await V(),!(await N?.isAuthenticated()??!1))return;let o=await _t(t);w.getInstance().set(o)},Dt=async t=>new Promise(async(e,o)=>{N=N??await V();let s=t?.provider??new F({});await N.login({onSuccess:async()=>{await J(s.id),e()},onError:i=>o(i),maxTimeToLive:t?.maxTimeToLive??tt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...s.signInOptions({windowed:t?.windowed})})}),X=async()=>{await N?.logout(),N=void 0,w.getInstance().reset()},$=()=>N?.getIdentity(),It=async()=>(N??await V()).getIdentity();var Tt=t=>{let e=t===!0?"./workers/auth.worker.js":t,o=new Worker(e),s=async()=>{z({message:"junoSignOutAuthTimer"}),await X()};return o.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await s();return;case"junoDelegationRemainingTime":z({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(i=>{if(l(i)){o.postMessage({msg:"junoStopAuthTimer"});return}o.postMessage({msg:"junoStartAuthTimer"})})};var xt=async({data:t,filename:e,collection:o,headers:s,token:i,fullPath:n,encoding:r,description:a,satellite:d})=>{let f=await T(d),{batch_id:u}=await f.init_asset_upload({collection:o,full_path:n,name:e,token:p(i),encoding_type:p(r),description:p(a)}),g=19e5,A=[],b=E()?new Blob([await t.arrayBuffer()]):t,P=0n;for(let m=0;m<b.size;m+=g){let S=b.slice(m,m+g);A.push({batchId:u,chunk:S,actor:f,orderId:P}),P++}let h=[];for await(let m of Lt({uploadChunks:A}))h=[...h,...m];let O=s.find(([m,S])=>m.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await f.commit_asset_upload({batch_id:u,chunk_ids:h.map(({chunk_id:m})=>m),headers:[...s,...O||[]]})};async function*Lt({uploadChunks:t,limit:e=12}){for(let o=0;o<t.length;o=o+e){let s=t.slice(o,o+e);yield await Promise.all(s.map(n=>te(n)))}}var te=async({batchId:t,chunk:e,actor:o,orderId:s})=>o.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:p(s)}),At=async({collection:t,satellite:e,filter:o})=>{let s=await T(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:d}=await s.list_assets(t,M(o));return{items:i.map(([f,u])=>u),items_length:n,items_page:y(r),matches_length:a,matches_pages:y(d)}},Pt=async({collection:t,fullPath:e,satellite:o})=>(await T(o)).del_asset(t,e),Nt=async({assets:t,satellite:e})=>{let{del_many_assets:o}=await T(e),s=t.map(({collection:i,fullPath:n})=>[i,n]);await o(s)};var wt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Q=()=>{let t=_.getInstance().get()?.satelliteId??"unknown",e=_.getInstance().get()?.container;if(c(e)&&e!==!1){let{host:o,protocol:s}=new URL(e===!0?k:e);return`${s}//${t}.${o.replace("127.0.0.1","localhost")}`}return`https://${t}.icp0.io`};var Uo=async t=>bt(t),Co=async t=>bt({filename:t.data.name,...t}),bt=async({filename:t,data:e,collection:o,headers:s=[],fullPath:i,token:n,satellite:r,encoding:a,description:d})=>{let f=x(r?.identity),u=decodeURI(t),g=i??`/${o}/${u}`;return await xt({data:e,filename:u,collection:o,token:n,headers:s,fullPath:g,encoding:a,satellite:{...r,identity:f},description:d}),{downloadUrl:`${Q()}${g}${n!==void 0?`?token=${n}`:""}`,fullPath:g,name:u}},Eo=async({collection:t,satellite:e,filter:o})=>{let{items:s,...i}=await At({collection:t,satellite:{...e,identity:x(e?.identity)},filter:o??{}}),n=Q();return{assets:s.map(({key:{full_path:r,token:a,name:d,owner:f,description:u},headers:g,encodings:A,created_at:b,updated_at:P})=>{let h=y(a);return{fullPath:r,description:y(u),name:d,downloadUrl:`${n}${r}${h!==void 0?`?token=${h}`:""}`,token:h,headers:g,encodings:A.reduce((O,[m,{modified:S,sha256:B,total_length:K}])=>({...O,[m]:{modified:S,sha256:wt(B),total_length:K}}),{}),owner:f.toText(),created_at:b,updated_at:P}}),...i}},Fo=async({collection:t,fullPath:e,satellite:o})=>Pt({collection:t,fullPath:e,satellite:{...o,identity:x(o?.identity)}}),Vo=async({assets:t,satellite:e})=>Nt({assets:t,satellite:{...e,identity:x(e?.identity)}});var jo=async t=>{_.getInstance().set(t),await J();let e=t.workers?.auth!==void 0?Tt(t.workers.auth):void 0;return[...e?[e]:[]]},Ho=t=>w.getInstance().subscribe(t);export{F as InternetIdentityProvider,nt as NFIDProvider,Ho as authSubscribe,Fo as deleteAsset,De as deleteDoc,Vo as deleteManyAssets,Ie as deleteManyDocs,gt as getDoc,Qe as getManyDocs,jo as initJuno,Eo as listAssets,Le as listDocs,ht as setDoc,Ze as setManyDocs,Dt as signIn,X as signOut,It as unsafeIdentity,Uo as uploadBlob,Co as uploadFile};
1
+ import{Principal as I}from"@dfinity/principal";var l=t=>t==null,c=t=>!l(t);var B="__bigint__",j="__principal__",H="__uint8array__",Wt=(t,e)=>typeof e=="bigint"?{[B]:`${e}`}:c(e)&&e instanceof I?{[j]:e.toText()}:c(e)&&e instanceof Uint8Array?{[H]:Array.from(e)}:e,Yt=(t,e)=>{let s=o=>e[o];return c(e)&&typeof e=="object"&&B in e?BigInt(s(B)):c(e)&&typeof e=="object"&&j in e?I.fromText(s(j)):c(e)&&typeof e=="object"&&H in e?Uint8Array.from(s(H)):e},p=t=>c(t)?[t]:[],y=t=>t?.[0],L=async t=>{let e=new Blob([JSON.stringify(t,Wt)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},C=async t=>{let e=new Blob([t instanceof Uint8Array?t:new Uint8Array(t)],{type:"application/json; charset=utf-8"});return JSON.parse(await e.text(),Yt)},E=()=>typeof window<"u";var R=class{callbacks=[];populate(e){this.callbacks.forEach(({callback:s})=>s(e))}subscribe(e){let s=Symbol();return this.callbacks.push({id:s,callback:e}),()=>this.callbacks=this.callbacks.filter(({id:o})=>o!==s)}};var N=class t extends R{static instance;authUser=null;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.authUser=e,this.populate(e)}get(){return this.authUser}subscribe(e){let s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var z=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var tt=BigInt(144e11),et={width:576,height:576},st={width:505,height:705},ot="internetcomputer.org";var k="http://127.0.0.1:5987",it="rdmx6-jaaaa-aaaaa-aaadq-cai";var T=class t extends R{static instance;env;constructor(){super()}static getInstance(){return t.instance||(t.instance=new t),t.instance}set(e){this.env=e,this.populate(e)}get(){return this.env}subscribe(e){let s=super.subscribe(e);return e(this.env),s}};var G=({width:t,height:e})=>{if(!E()||l(window)||l(window.top))return;let{top:{innerWidth:s,innerHeight:o}}=window,i=o/2+screenY-e/2,n=s/2+screenX-t/2;return`toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width=${t}, height=${e}, top=${i}, left=${n}`};var F=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=T.getInstance().get()?.container;if(l(o)||o===!1)return`https://identity.${this.#t??ot}`;let i=T.getInstance().get(),n=c(i)&&c(i?.internetIdentityId)?i.internetIdentityId:it,{host:r,protocol:a}=new URL(o===!0?k:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:G(et)},identityProvider:s()}}},nt=class{#t;#e;constructor({appName:e,logoUrl:s}){this.#t=e,this.#e=s}get id(){return"nfid"}signInOptions({windowed:e}){return{...e!==!1&&{windowOpenerFeatures:G(st)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as Jt}from"@dfinity/auth-client";var V=()=>Jt.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var rt=async({data:t})=>{try{return await C(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var W=async t=>{let{data:e,updated_at:s,description:o}=t;return{description:p(o),data:await L(e),updated_at:p(s)}},Y=t=>{let{updated_at:e}=t;return{updated_at:p(e)}},v=async({doc:t,key:e})=>{let{owner:s,description:o,data:i,...n}=t;return{key:e,description:y(o),owner:s.toText(),data:await C(i),...n}};import{Principal as Xt}from"@dfinity/principal";var M=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:l(t)?[]:[{key:p(t.key),description:p(t.description)}],paginate:p(l(e)?void 0:{start_after:p(e.startAfter),limit:p(l(e.limit)?void 0:BigInt(e.limit))}),order:p(l(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:p(l(o)?void 0:typeof o=="string"?Xt.fromText(o):o)});var at=({IDL:t})=>{let e=t.Record({batch_id:t.Nat,headers:t.Vec(t.Tuple(t.Text,t.Text)),chunk_ids:t.Vec(t.Nat)}),s=t.Record({controllers:t.Vec(t.Principal)}),o=t.Variant({Write:t.Null,Admin:t.Null}),i=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:o,expires_at:t.Opt(t.Nat64)}),n=t.Record({updated_at:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({cycles:t.Nat,destination_id:t.Principal}),d=t.Record({token:t.Opt(t.Text),collection:t.Text,owner:t.Principal,name:t.Text,description:t.Opt(t.Text),full_path:t.Text}),_=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),u=t.Record({key:d,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,_)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64}),x=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),w=t.Record({status_code:t.Nat16,location:t.Text}),b=t.Record({iframe:t.Opt(x),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),redirects:t.Opt(t.Vec(t.Tuple(t.Text,w)))}),P=t.Record({storage:b}),f=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64}),S=t.Record({url:t.Text,method:t.Text,body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),certificate_version:t.Opt(t.Nat16)}),m=t.Variant({Heap:t.Null,Stable:t.Null}),O=t.Record({memory:m,token:t.Opt(t.Text),sha256:t.Opt(t.Vec(t.Nat8)),headers:t.Vec(t.Tuple(t.Text,t.Text)),index:t.Nat64,encoding_type:t.Text,full_path:t.Text}),K=t.Variant({Callback:t.Record({token:O,callback:t.Func([],[],["query"])})}),q=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(K),status_code:t.Nat16}),Rt=t.Record({token:t.Opt(O),body:t.Vec(t.Nat8)}),kt=t.Record({token:t.Opt(t.Text),collection:t.Text,name:t.Text,description:t.Opt(t.Text),encoding_type:t.Opt(t.Text),full_path:t.Text}),vt=t.Record({batch_id:t.Nat}),Ut=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),Ct=t.Record({field:Ut,desc:t.Bool}),Et=t.Record({key:t.Opt(t.Text),description:t.Opt(t.Text)}),Ft=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),Z=t.Record({order:t.Opt(Ct),owner:t.Opt(t.Principal),matcher:t.Opt(Et),paginate:t.Opt(Ft)}),Vt=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,u)),items_length:t.Nat64}),Mt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,bn_id:t.Opt(t.Text)}),$t=t.Record({matches_pages:t.Opt(t.Nat64),matches_length:t.Nat64,items_page:t.Opt(t.Nat64),items:t.Vec(t.Tuple(t.Text,f)),items_length:t.Nat64}),U=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),Kt=t.Record({memory:t.Opt(m),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:U,created_at:t.Nat64,mutable_permissions:t.Opt(t.Bool),write:U}),qt=t.Record({stable:t.Nat64,heap:t.Nat64}),Bt=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),jt=t.Record({controller:Bt,controllers:t.Vec(t.Principal)}),D=t.Record({updated_at:t.Opt(t.Nat64),data:t.Vec(t.Nat8),description:t.Opt(t.Text)}),Ht=t.Record({memory:t.Opt(m),updated_at:t.Opt(t.Nat64),max_size:t.Opt(t.Nat),read:U,mutable_permissions:t.Opt(t.Bool),write:U}),zt=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),Gt=t.Record({chunk_id:t.Nat});return t.Service({build_version:t.Func([],[t.Text],["query"]),commit_asset_upload:t.Func([e],[],[]),count_assets:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([s],[t.Vec(t.Tuple(t.Principal,i))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,n],[],[]),del_docs:t.Func([t.Text],[],[]),del_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[],[]),del_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,n))],[],[]),del_rule:t.Func([r,t.Text,n],[],[]),deposit_cycles:t.Func([a],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(u)],["query"]),get_config:t.Func([],[P],[]),get_doc:t.Func([t.Text,t.Text],[t.Opt(f)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(u)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(f)))],["query"]),http_request:t.Func([S],[q],["query"]),http_request_streaming_callback:t.Func([O],[Rt],["query"]),init_asset_upload:t.Func([kt],[vt],[]),list_assets:t.Func([t.Text,Z],[Vt],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Mt))],["query"]),list_docs:t.Func([t.Text,Z],[$t],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,Kt))],["query"]),memory_size:t.Func([],[qt],["query"]),set_config:t.Func([P],[],[]),set_controllers:t.Func([jt],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_doc:t.Func([t.Text,t.Text,D],[f],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,D))],[t.Vec(t.Tuple(t.Text,f))],[]),set_rule:t.Func([r,t.Text,Ht],[],[]),upload_asset_chunk:t.Func([zt],[Gt],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as Qt,HttpAgent as Zt}from"@dfinity/agent";var ct=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=c(i)&&i!==!1?i===!0?k:i:"https://icp-api.io",a=new Zt({identity:s,host:r,...o&&{fetch:o}});return c(i)&&await a.fetchRootKey(),Qt.createActor(e,{agent:a,canisterId:t})};var g=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=c(t)?{satelliteId:t}:T.getInstance().get()??{satelliteId:void 0},{container:i}=c(e)?{container:e}:T.getInstance().get()??{container:void 0};if(!o)throw new Error("No satellite principal defined.");return ct({satelliteId:o,container:i,idlFactory:at,...s})};var lt=async({collection:t,key:e,satellite:s})=>{let o=await g(s),i=y(await o.get_doc(t,e));if(!l(i))return v({doc:i,key:e})},pt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await g(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let d=y(a);n.push(c(d)?await v({key:r,doc:d}):void 0)}return n},dt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await g(s),{key:i}=e,n=await W(e),r=await o(t,i,n);return await v({key:i,doc:r})},ut=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await g(e),o=[];for(let{collection:r,doc:a}of t){let{key:d}=a;o.push([r,d,await W(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await v({key:r,doc:a}));return n},mt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await g(s),{key:i}=e;return o(t,i,Y(e))},yt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await g(e),o=t.map(({collection:i,doc:n})=>[i,n.key,Y(n)]);await s(o)},ft=async({collection:t,filter:e,satellite:s})=>{let o=await g(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:d}=await o.list_docs(t,M(e)),_=[];for(let[u,x]of i){let{data:w,owner:b,description:P,...f}=x;_.push({key:u,description:y(P),owner:b.toText(),data:await rt({data:w}),...f})}return{items:_,items_length:r,items_page:y(n),matches_length:a,matches_pages:y(d)}};import{AnonymousIdentity as Dt}from"@dfinity/agent";var h=t=>t!==void 0?t:$()??new Dt;var gt=async({satellite:t,...e})=>{let s=h(t?.identity);return lt({...e,satellite:{...t,identity:s}})},De=async({satellite:t,...e})=>{let s=h(t?.identity);return pt({...e,satellite:{...t,identity:s}})},ht=async({satellite:t,...e})=>{let s=h(t?.identity);return dt({...e,satellite:{...t,identity:s}})},Ie=async({satellite:t,...e})=>{let s=h(t?.identity);return ut({...e,satellite:{...t,identity:s}})},Le=async({satellite:t,...e})=>{let s=h(t?.identity);return mt({...e,satellite:{...t,identity:s}})},ts=async({satellite:t,...e})=>{let s=h(t?.identity);return yt({...e,satellite:{...t,identity:s}})},es=async({satellite:t,filter:e,...s})=>{let o=h(t?.identity);return ft({...s,filter:e??{},satellite:{...t,identity:o}})};var _t=async t=>{let e=$();if(l(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await gt({collection:"#user",key:s});return l(o)?await It({userId:s,provider:t}):o},It=async({userId:t,...e})=>ht({collection:"#user",doc:{key:t,data:e}});var A,J=async t=>{if(A=A??await V(),!(await A?.isAuthenticated()??!1))return;let s=await _t(t);N.getInstance().set(s)},Lt=async t=>new Promise(async(e,s)=>{A=A??await V();let o=t?.provider??new F({});await A.login({onSuccess:async()=>{await J(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??tt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),X=async()=>{await A?.logout(),A=void 0,N.getInstance().reset()},$=()=>A?.getIdentity(),te=async()=>(A??await V()).getIdentity();var Tt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{z({message:"junoSignOutAuthTimer"}),await X()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":z({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},N.getInstance().subscribe(i=>{if(l(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var xt=async({data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a,satellite:d})=>{let _=await g(d),{batch_id:u}=await _.init_asset_upload({collection:s,full_path:n,name:e,token:p(i),encoding_type:p(r),description:p(a)}),x=19e5,w=[],b=E()?new Blob([await t.arrayBuffer()]):t,P=0n;for(let m=0;m<b.size;m+=x){let O=b.slice(m,m+x);w.push({batchId:u,chunk:O,actor:_,orderId:P}),P++}let f=[];for await(let m of ee({uploadChunks:w}))f=[...f,...m];let S=o.find(([m,O])=>m.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await _.commit_asset_upload({batch_id:u,chunk_ids:f.map(({chunk_id:m})=>m),headers:[...o,...S||[]]})};async function*ee({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let o=t.slice(s,s+e);yield await Promise.all(o.map(n=>se(n)))}}var se=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:p(o)}),At=async({collection:t,satellite:e,filter:s})=>{let o=await g(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:d}=await o.list_assets(t,M(s));return{items:i.map(([_,u])=>u),items_length:n,items_page:y(r),matches_length:a,matches_pages:y(d)}},Pt=async({collection:t,fullPath:e,satellite:s})=>(await g(s)).del_asset(t,e),Nt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await g(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},wt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await g(s);return y(await o(t,e))},bt=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await g(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>y(r))};var Ot=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Q=()=>{let t=T.getInstance().get()?.satelliteId??"unknown",e=T.getInstance().get()?.container;if(c(e)&&e!==!1){let{host:s,protocol:o}=new URL(e===!0?k:e);return`${o}//${t}.${s.replace("127.0.0.1","localhost")}`}return`https://${t}.icp0.io`};var Cs=async t=>St(t),Es=async t=>St({filename:t.data.name,...t}),St=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:d})=>{let _=h(r?.identity),u=decodeURI(t),x=i??`/${s}/${u}`;return await xt({data:e,filename:u,collection:s,token:n,headers:o,fullPath:x,encoding:a,satellite:{...r,identity:_},description:d}),{downloadUrl:`${Q()}${x}${n!==void 0?`?token=${n}`:""}`,fullPath:x,name:u}},Fs=async({collection:t,satellite:e,filter:s})=>{let{items:o,...i}=await At({collection:t,satellite:{...e,identity:h(e?.identity)},filter:s??{}}),n=Q();return{assets:o.map(({key:{full_path:r,token:a,name:d,owner:_,description:u},headers:x,encodings:w,created_at:b,updated_at:P})=>{let f=y(a);return{fullPath:r,description:y(u),name:d,downloadUrl:`${n}${r}${f!==void 0?`?token=${f}`:""}`,token:f,headers:x,encodings:w.reduce((S,[m,{modified:O,sha256:K,total_length:q}])=>({...S,[m]:{modified:O,sha256:Ot(K),total_length:q}}),{}),owner:_.toText(),created_at:b,updated_at:P}}),...i}},Vs=async({collection:t,fullPath:e,satellite:s})=>Pt({collection:t,fullPath:e,satellite:{...s,identity:h(s?.identity)}}),Ms=async({assets:t,satellite:e})=>Nt({assets:t,satellite:{...e,identity:h(e?.identity)}}),$s=async({satellite:t,...e})=>{let s=h(t?.identity);return wt({...e,satellite:{...t,identity:s}})},Ks=async({satellite:t,...e})=>{let s=h(t?.identity);return bt({...e,satellite:{...t,identity:s}})};var Gs=async t=>{T.getInstance().set(t),await J();let e=t.workers?.auth!==void 0?Tt(t.workers.auth):void 0;return[...e?[e]:[]]},Ws=t=>N.getInstance().subscribe(t);export{F as InternetIdentityProvider,nt as NFIDProvider,Ws as authSubscribe,Vs as deleteAsset,Le as deleteDoc,Ms as deleteManyAssets,ts as deleteManyDocs,$s as getAsset,gt as getDoc,Ks as getManyAssets,De as getManyDocs,Gs as initJuno,Fs as listAssets,es as listDocs,ht as setDoc,Ie as setManyDocs,Lt as signIn,X as signOut,te as unsafeIdentity,Cs as uploadBlob,Es as uploadFile};
2
2
  //# sourceMappingURL=index.js.map