@junobuild/core-peer 0.0.24 → 0.0.25

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.
@@ -230,8 +230,10 @@ export interface UploadChunkResult {
230
230
  export interface _SERVICE {
231
231
  build_version: ActorMethod<[], string>;
232
232
  commit_asset_upload: ActorMethod<[CommitBatch], undefined>;
233
- count_assets: ActorMethod<[string], bigint>;
234
- count_docs: ActorMethod<[string], bigint>;
233
+ count_assets: ActorMethod<[string, ListParams], bigint>;
234
+ count_collection_assets: ActorMethod<[string], bigint>;
235
+ count_collection_docs: ActorMethod<[string], bigint>;
236
+ count_docs: ActorMethod<[string, ListParams], bigint>;
235
237
  del_asset: ActorMethod<[string, string], undefined>;
236
238
  del_assets: ActorMethod<[string], undefined>;
237
239
  del_controllers: ActorMethod<[DeleteControllersArgs], Array<[Principal, Controller]>>;
@@ -5,6 +5,34 @@ export const idlFactory = ({IDL}) => {
5
5
  headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
6
6
  chunk_ids: IDL.Vec(IDL.Nat)
7
7
  });
8
+ const ListOrderField = IDL.Variant({
9
+ UpdatedAt: IDL.Null,
10
+ Keys: IDL.Null,
11
+ CreatedAt: IDL.Null
12
+ });
13
+ const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});
14
+ const TimestampMatcher = IDL.Variant({
15
+ Equal: IDL.Nat64,
16
+ Between: IDL.Tuple(IDL.Nat64, IDL.Nat64),
17
+ GreaterThan: IDL.Nat64,
18
+ LessThan: IDL.Nat64
19
+ });
20
+ const ListMatcher = IDL.Record({
21
+ key: IDL.Opt(IDL.Text),
22
+ updated_at: IDL.Opt(TimestampMatcher),
23
+ description: IDL.Opt(IDL.Text),
24
+ created_at: IDL.Opt(TimestampMatcher)
25
+ });
26
+ const ListPaginate = IDL.Record({
27
+ start_after: IDL.Opt(IDL.Text),
28
+ limit: IDL.Opt(IDL.Nat64)
29
+ });
30
+ const ListParams = IDL.Record({
31
+ order: IDL.Opt(ListOrder),
32
+ owner: IDL.Opt(IDL.Principal),
33
+ matcher: IDL.Opt(ListMatcher),
34
+ paginate: IDL.Opt(ListPaginate)
35
+ });
8
36
  const DeleteControllersArgs = IDL.Record({
9
37
  controllers: IDL.Vec(IDL.Principal)
10
38
  });
@@ -136,34 +164,6 @@ export const idlFactory = ({IDL}) => {
136
164
  full_path: IDL.Text
137
165
  });
138
166
  const InitUploadResult = IDL.Record({batch_id: IDL.Nat});
139
- const ListOrderField = IDL.Variant({
140
- UpdatedAt: IDL.Null,
141
- Keys: IDL.Null,
142
- CreatedAt: IDL.Null
143
- });
144
- const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});
145
- const TimestampMatcher = IDL.Variant({
146
- Equal: IDL.Nat64,
147
- Between: IDL.Tuple(IDL.Nat64, IDL.Nat64),
148
- GreaterThan: IDL.Nat64,
149
- LessThan: IDL.Nat64
150
- });
151
- const ListMatcher = IDL.Record({
152
- key: IDL.Opt(IDL.Text),
153
- updated_at: IDL.Opt(TimestampMatcher),
154
- description: IDL.Opt(IDL.Text),
155
- created_at: IDL.Opt(TimestampMatcher)
156
- });
157
- const ListPaginate = IDL.Record({
158
- start_after: IDL.Opt(IDL.Text),
159
- limit: IDL.Opt(IDL.Nat64)
160
- });
161
- const ListParams = IDL.Record({
162
- order: IDL.Opt(ListOrder),
163
- owner: IDL.Opt(IDL.Principal),
164
- matcher: IDL.Opt(ListMatcher),
165
- paginate: IDL.Opt(ListPaginate)
166
- });
167
167
  const ListResults = IDL.Record({
168
168
  matches_pages: IDL.Opt(IDL.Nat64),
169
169
  matches_length: IDL.Nat64,
@@ -234,8 +234,10 @@ export const idlFactory = ({IDL}) => {
234
234
  return IDL.Service({
235
235
  build_version: IDL.Func([], [IDL.Text], ['query']),
236
236
  commit_asset_upload: IDL.Func([CommitBatch], [], []),
237
- count_assets: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
238
- count_docs: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
237
+ count_assets: IDL.Func([IDL.Text, ListParams], [IDL.Nat64], ['query']),
238
+ count_collection_assets: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
239
+ count_collection_docs: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
240
+ count_docs: IDL.Func([IDL.Text, ListParams], [IDL.Nat64], ['query']),
239
241
  del_asset: IDL.Func([IDL.Text, IDL.Text], [], []),
240
242
  del_assets: IDL.Func([IDL.Text], [], []),
241
243
  del_controllers: IDL.Func(
@@ -5,6 +5,34 @@ export const idlFactory = ({IDL}) => {
5
5
  headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
6
6
  chunk_ids: IDL.Vec(IDL.Nat)
7
7
  });
8
+ const ListOrderField = IDL.Variant({
9
+ UpdatedAt: IDL.Null,
10
+ Keys: IDL.Null,
11
+ CreatedAt: IDL.Null
12
+ });
13
+ const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});
14
+ const TimestampMatcher = IDL.Variant({
15
+ Equal: IDL.Nat64,
16
+ Between: IDL.Tuple(IDL.Nat64, IDL.Nat64),
17
+ GreaterThan: IDL.Nat64,
18
+ LessThan: IDL.Nat64
19
+ });
20
+ const ListMatcher = IDL.Record({
21
+ key: IDL.Opt(IDL.Text),
22
+ updated_at: IDL.Opt(TimestampMatcher),
23
+ description: IDL.Opt(IDL.Text),
24
+ created_at: IDL.Opt(TimestampMatcher)
25
+ });
26
+ const ListPaginate = IDL.Record({
27
+ start_after: IDL.Opt(IDL.Text),
28
+ limit: IDL.Opt(IDL.Nat64)
29
+ });
30
+ const ListParams = IDL.Record({
31
+ order: IDL.Opt(ListOrder),
32
+ owner: IDL.Opt(IDL.Principal),
33
+ matcher: IDL.Opt(ListMatcher),
34
+ paginate: IDL.Opt(ListPaginate)
35
+ });
8
36
  const DeleteControllersArgs = IDL.Record({
9
37
  controllers: IDL.Vec(IDL.Principal)
10
38
  });
@@ -136,34 +164,6 @@ export const idlFactory = ({IDL}) => {
136
164
  full_path: IDL.Text
137
165
  });
138
166
  const InitUploadResult = IDL.Record({batch_id: IDL.Nat});
139
- const ListOrderField = IDL.Variant({
140
- UpdatedAt: IDL.Null,
141
- Keys: IDL.Null,
142
- CreatedAt: IDL.Null
143
- });
144
- const ListOrder = IDL.Record({field: ListOrderField, desc: IDL.Bool});
145
- const TimestampMatcher = IDL.Variant({
146
- Equal: IDL.Nat64,
147
- Between: IDL.Tuple(IDL.Nat64, IDL.Nat64),
148
- GreaterThan: IDL.Nat64,
149
- LessThan: IDL.Nat64
150
- });
151
- const ListMatcher = IDL.Record({
152
- key: IDL.Opt(IDL.Text),
153
- updated_at: IDL.Opt(TimestampMatcher),
154
- description: IDL.Opt(IDL.Text),
155
- created_at: IDL.Opt(TimestampMatcher)
156
- });
157
- const ListPaginate = IDL.Record({
158
- start_after: IDL.Opt(IDL.Text),
159
- limit: IDL.Opt(IDL.Nat64)
160
- });
161
- const ListParams = IDL.Record({
162
- order: IDL.Opt(ListOrder),
163
- owner: IDL.Opt(IDL.Principal),
164
- matcher: IDL.Opt(ListMatcher),
165
- paginate: IDL.Opt(ListPaginate)
166
- });
167
167
  const ListResults = IDL.Record({
168
168
  matches_pages: IDL.Opt(IDL.Nat64),
169
169
  matches_length: IDL.Nat64,
@@ -234,8 +234,10 @@ export const idlFactory = ({IDL}) => {
234
234
  return IDL.Service({
235
235
  build_version: IDL.Func([], [IDL.Text], ['query']),
236
236
  commit_asset_upload: IDL.Func([CommitBatch], [], []),
237
- count_assets: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
238
- count_docs: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
237
+ count_assets: IDL.Func([IDL.Text, ListParams], [IDL.Nat64], ['query']),
238
+ count_collection_assets: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
239
+ count_collection_docs: IDL.Func([IDL.Text], [IDL.Nat64], ['query']),
240
+ count_docs: IDL.Func([IDL.Text, ListParams], [IDL.Nat64], ['query']),
239
241
  del_asset: IDL.Func([IDL.Text, IDL.Text], [], []),
240
242
  del_assets: IDL.Func([IDL.Text], [], []),
241
243
  del_controllers: IDL.Func(
@@ -1,4 +1,4 @@
1
1
  import { createRequire as topLevelCreateRequire } from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
- import{Principal as it}from"@dfinity/principal";var c=t=>t==null,l=t=>!c(t),ce=class extends Error{},F=(t,e)=>{if(c(t))throw new ce(e)},W="__bigint__",G="__principal__",Y="__uint8array__",le=(t,e)=>typeof e=="bigint"?{[W]:`${e}`}:l(e)&&e instanceof it?{[G]:e.toText()}:l(e)&&e instanceof Uint8Array?{[Y]:Array.from(e)}:e,pe=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&W in e?BigInt(s(W)):l(e)&&typeof e=="object"&&G in e?it.fromText(s(G)):l(e)&&typeof e=="object"&&Y in e?Uint8Array.from(s(Y)):e},u=t=>l(t)?[t]:[],p=t=>t?.[0],nt=async t=>{let e=new Blob([JSON.stringify(t,le)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},V=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(),pe)},rt=()=>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 v=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 J=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var at=BigInt(144e11),ct=!1,lt={width:576,height:576},pt={width:505,height:705},dt="internetcomputer.org";var k="http://127.0.0.1:5987",ut="rdmx6-jaaaa-aaaaa-aaadq-cai";var N=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 X=({width:t,height:e})=>{if(!rt()||c(window)||c(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 M=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=N.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??dt}`;let i=N.getInstance().get(),n=l(i)&&l(i?.internetIdentityId)?i.internetIdentityId:ut,{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:X(lt)},identityProvider:s()}}},mt=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:X(pt)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as de}from"@dfinity/auth-client";var K=()=>de.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var yt=async({data:t})=>{try{return await V(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var Q=async t=>{let{data:e,version:s,description:o}=t;return{description:u(o),data:await nt(e),version:u(s)}},Z=t=>{let{version:e}=t;return{version:u(e)}},C=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:p(i),owner:s.toText(),data:await V(n),version:p(o),...r}};import{Principal as ue}from"@dfinity/principal";var ft=t=>{if(c(t))return u();switch(t.matcher){case"equal":return u({Equal:t.timestamp});case"greaterThan":return u({GreaterThan:t.timestamp});case"lessThan":return u({LessThan:t.timestamp});case"between":return u({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},q=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:u(t.key),description:u(t.description),created_at:ft(t.createdAt),updated_at:ft(t.updatedAt)}],paginate:u(c(e)?void 0:{start_after:u(e.startAfter),limit:u(c(e.limit)?void 0:BigInt(e.limit))}),order:u(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:u(c(o)?void 0:typeof o=="string"?ue.fromText(o):o)});var gt=({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({version:t.Opt(t.Nat64)}),r=t.Variant({Db:t.Null,Storage:t.Null}),a=t.Record({version:t.Opt(t.Nat64)}),d=t.Record({cycles:t.Nat,destination_id:t.Principal}),_=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}),f=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:_,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,f)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),T=t.Record({derivation_origin:t.Opt(t.Text)}),x=t.Record({internet_identity:t.Opt(T)}),w=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),A=t.Record({max_memory_size:t.Opt(w)}),O=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),h=t.Variant({Deny:t.Null,Allow:t.Null}),b=t.Record({status_code:t.Nat16,location:t.Text}),E=t.Record({iframe:t.Opt(O),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(w),raw_access:t.Opt(h),redirects:t.Opt(t.Vec(t.Tuple(t.Text,b)))}),j=t.Record({db:t.Opt(A),authentication:t.Opt(x),storage:E}),S=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),zt=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)}),z=t.Variant({Heap:t.Null,Stable:t.Null}),H=t.Record({memory:z,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}),Ht=t.Variant({Callback:t.Record({token:H,callback:t.Func([],[],["query"])})}),Wt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Ht),status_code:t.Nat16}),Gt=t.Record({token:t.Opt(H),body:t.Vec(t.Nat8)}),Yt=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}),Jt=t.Record({batch_id:t.Nat}),Xt=t.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),Qt=t.Record({field:Xt,desc:t.Bool}),et=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),Zt=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(et),description:t.Opt(t.Text),created_at:t.Opt(et)}),Dt=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),st=t.Record({order:t.Opt(Qt),owner:t.Opt(t.Principal),matcher:t.Opt(Zt),paginate:t.Opt(Dt)}),It=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,g)),items_length:t.Nat64}),Lt=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),te=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,S)),items_length:t.Nat64}),U=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),ee=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(z),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:U,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:U}),se=t.Record({stable:t.Nat64,heap:t.Nat64}),oe=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:o,expires_at:t.Opt(t.Nat64)}),ie=t.Record({controller:oe,controllers:t.Vec(t.Principal)}),ot=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),ne=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(z),max_size:t.Opt(t.Nat),read:U,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:U}),re=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),ae=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,a],[],[]),deposit_cycles:t.Func([d],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(x)],["query"]),get_config:t.Func([],[j],[]),get_db_config:t.Func([],[t.Opt(A)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(S)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(g)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(S)))],["query"]),get_storage_config:t.Func([],[E],["query"]),http_request:t.Func([zt],[Wt],["query"]),http_request_streaming_callback:t.Func([H],[Gt],["query"]),init_asset_upload:t.Func([Yt],[Jt],[]),list_assets:t.Func([t.Text,st],[It],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,i))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,Lt))],["query"]),list_docs:t.Func([t.Text,st],[te],["query"]),list_rules:t.Func([r],[t.Vec(t.Tuple(t.Text,ee))],["query"]),memory_size:t.Func([],[se],["query"]),set_auth_config:t.Func([x],[],[]),set_controllers:t.Func([ie],[t.Vec(t.Tuple(t.Principal,i))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([A],[],[]),set_doc:t.Func([t.Text,t.Text,ot],[S],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,ot))],[t.Vec(t.Tuple(t.Text,S))],[]),set_rule:t.Func([r,t.Text,ne],[],[]),set_storage_config:t.Func([E],[],[]),upload_asset_chunk:t.Func([re],[ae],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as me,HttpAgent as ye}from"@dfinity/agent";var ht=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=l(i)&&i!==!1?i===!0?k:i:"https://icp-api.io",a=new ye({identity:s,host:r,...o&&{fetch:o}});return l(i)&&await a.fetchRootKey(),me.createActor(e,{agent:a,canisterId:t})};var _t=({satelliteId:t,container:e})=>{let{satelliteId:s}=D({satelliteId:t}),{container:o}=I({container:e});if(l(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?k:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},D=({satelliteId:t})=>l(t)?{satelliteId:t}:N.getInstance().get()??{satelliteId:void 0},I=({container:t})=>l(t)?{container:t}:N.getInstance().get()??{container:void 0};var y=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=D({satelliteId:t});F(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=I({container:e});return ht({satelliteId:o,container:i,idlFactory:gt,...s})};var Tt=async({collection:t,key:e,satellite:s})=>{let o=await y(s),i=p(await o.get_doc(t,e));if(!c(i))return C({doc:i,key:e})},At=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await y(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let d=p(a);n.push(l(d)?await C({key:r,doc:d}):void 0)}return n},xt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await y(s),{key:i}=e,n=await Q(e),r=await o(t,i,n);return await C({key:i,doc:r})},Nt=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await y(e),o=[];for(let{collection:r,doc:a}of t){let{key:d}=a;o.push([r,d,await Q(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await C({key:r,doc:a}));return n},Pt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await y(s),{key:i}=e;return o(t,i,Z(e))},wt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await y(e),o=t.map(({collection:i,doc:n})=>[i,n.key,Z(n)]);await s(o)},vt=async({collection:t,filter:e,satellite:s})=>{let o=await y(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:d}=await o.list_docs(t,q(e)),_=[];for(let[f,g]of i){let{data:T,owner:x,description:w,version:A,...O}=g;_.push({key:f,description:p(w),owner:x.toText(),data:await yt({data:T}),version:p(A),...O})}return{items:_,items_length:r,items_page:p(n),matches_length:a,matches_pages:p(d)}};import{AnonymousIdentity as fe}from"@dfinity/agent";var m=t=>t!==void 0?t:B()??new fe;var Ot=async({satellite:t,...e})=>{let s=m(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},vs=async({satellite:t,...e})=>{let s=m(t?.identity);return At({...e,satellite:{...t,identity:s}})},St=async({satellite:t,...e})=>{let s=m(t?.identity);return xt({...e,satellite:{...t,identity:s}})},Os=async({satellite:t,...e})=>{let s=m(t?.identity);return Nt({...e,satellite:{...t,identity:s}})},Ss=async({satellite:t,...e})=>{let s=m(t?.identity);return Pt({...e,satellite:{...t,identity:s}})},bs=async({satellite:t,...e})=>{let s=m(t?.identity);return wt({...e,satellite:{...t,identity:s}})},Rs=async({satellite:t,filter:e,...s})=>{let o=m(t?.identity);return vt({...s,filter:e??{},satellite:{...t,identity:o}})};var bt=async t=>{let e=B();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await Ot({collection:"#user",key:s});return c(o)?await ge({userId:s,provider:t}):o},ge=async({userId:t,...e})=>St({collection:"#user",doc:{key:t,data:e}});var P,L=async t=>{if(P=P??await K(),!(await P?.isAuthenticated()??!1))return;let s=await bt(t);v.getInstance().set(s)},he=async t=>new Promise(async(e,s)=>{P=P??await K();let o=t?.provider??new M({});await P.login({onSuccess:async()=>{await L(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??at,allowPinAuthentication:t?.allowPin??ct,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),tt=async()=>{await P?.logout(),P=void 0,v.getInstance().reset()},B=()=>P?.getIdentity(),_e=async()=>(P??await K()).getIdentity();var Rt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{J({message:"junoSignOutAuthTimer"}),await tt()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":J({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},v.getInstance().subscribe(i=>{if(c(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var kt=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},Et=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};import"@dfinity/principal";var Te=t=>t==null,Ae=t=>!Te(t),$=t=>Ae(t)?[t]:[],xe=()=>typeof window<"u",Ct=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a},actor:d,init_asset_upload:_})=>{let{batch_id:f}=await _({collection:s,full_path:n,name:e,token:$(i),encoding_type:$(r),description:$(a)}),g=19e5,T=[],x=xe()?new Blob([await t.arrayBuffer()]):t,w=0n;for(let h=0;h<x.size;h+=g){let b=x.slice(h,h+g);T.push({batchId:f,chunk:b,actor:d,orderId:w}),w++}let A=[];for await(let h of Ne({uploadChunks:T}))A=[...A,...h];let O=o.find(([h,b])=>h.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await d.commit_asset_upload({batch_id:f,chunk_ids:A.map(({chunk_id:h})=>h),headers:[...o,...O||[]]})};async function*Ne({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(i=>Pe(i)))}}var Pe=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:$(o)});var Ut=async({satellite:t,...e})=>{let s=await y(t);await Ct({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},Ft=async({collection:t,satellite:e,filter:s})=>{let o=await y(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:d}=await o.list_assets(t,q(s));return{items:i.map(([_,f])=>f),items_length:n,items_page:p(r),matches_length:a,matches_pages:p(d)}},Vt=async({collection:t,fullPath:e,satellite:s})=>(await y(s)).del_asset(t,e),Mt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await y(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Kt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await y(s);return p(await o(t,e))},qt=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await y(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>p(r))};var Bt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var ao=async t=>$t(t),co=async t=>$t({filename:t.data.name,...t}),$t=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:d})=>{let _=m(r?.identity),f=decodeURI(t),g=i??`/${s}/${f}`,T={...r,identity:_};return await Ut({data:e,filename:f,collection:s,token:n,headers:o,fullPath:g,encoding:a,satellite:T,description:d}),{downloadUrl:jt({satellite:T,assetKey:{fullPath:g,token:n}}),fullPath:g,name:f}},lo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:m(e?.identity)},{items:i,...n}=await Ft({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:a,token:d,name:_,owner:f,description:g},headers:T,encodings:x,created_at:w,updated_at:A})=>{let O=p(d);return{fullPath:a,description:p(g),name:_,downloadUrl:jt({satellite:o,assetKey:{fullPath:a,token:O}}),token:O,headers:T,encodings:x.reduce((h,[b,{modified:E,sha256:j,total_length:S}])=>({...h,[b]:{modified:E,sha256:Bt(j),total_length:S}}),{}),owner:f.toText(),created_at:w,updated_at:A}});return{items:r,assets:r,...n}},po=async({collection:t,fullPath:e,satellite:s})=>Vt({collection:t,fullPath:e,satellite:{...s,identity:m(s?.identity)}}),uo=async({assets:t,satellite:e})=>Mt({assets:t,satellite:{...e,identity:m(e?.identity)}}),mo=async({satellite:t,...e})=>{let s=m(t?.identity);return Kt({...e,satellite:{...t,identity:s}})},yo=async({satellite:t,...e})=>{let s=m(t?.identity);return qt({...e,satellite:{...t,identity:s}})},jt=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:m(s?.identity)};return`${_t(o)}${t}${l(e)?`?token=${e}`:""}`};var we=t=>{let e=t?.satelliteId??kt();F(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Et();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},No=async t=>ve(t),ve=async t=>{let e=we(t);N.getInstance().set(e),await L();let s=e.workers?.auth!==void 0?Rt(e.workers.auth):void 0;return[...s?[s]:[]]},Po=t=>v.getInstance().subscribe(t);export{M as InternetIdentityProvider,mt as NFIDProvider,Po as authSubscribe,po as deleteAsset,Ss as deleteDoc,uo as deleteManyAssets,bs as deleteManyDocs,jt as downloadUrl,mo as getAsset,Ot as getDoc,yo as getManyAssets,vs as getManyDocs,No as initJuno,ve as initSatellite,lo as listAssets,Rs as listDocs,St as setDoc,Os as setManyDocs,he as signIn,tt as signOut,_e as unsafeIdentity,ao as uploadBlob,co as uploadFile};
3
+ import{Principal as it}from"@dfinity/principal";var c=t=>t==null,l=t=>!c(t),pe=class extends Error{},K=(t,e)=>{if(c(t))throw new pe(e)},Y="__bigint__",J="__principal__",X="__uint8array__",de=(t,e)=>typeof e=="bigint"?{[Y]:`${e}`}:l(e)&&e instanceof it?{[J]:e.toText()}:l(e)&&e instanceof Uint8Array?{[X]:Array.from(e)}:e,ue=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&Y in e?BigInt(s(Y)):l(e)&&typeof e=="object"&&J in e?it.fromText(s(J)):l(e)&&typeof e=="object"&&X in e?Uint8Array.from(s(X)):e},m=t=>l(t)?[t]:[],p=t=>t?.[0],nt=async t=>{let e=new Blob([JSON.stringify(t,de)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},q=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(),ue)},rt=()=>typeof window<"u";var b=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 P=class t extends b{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 Q=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var at=BigInt(144e11),ct=!1,lt={width:576,height:576},pt={width:505,height:705},dt="internetcomputer.org";var R="http://127.0.0.1:5987",ut="rdmx6-jaaaa-aaaaa-aaadq-cai";var x=class t extends b{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 Z=({width:t,height:e})=>{if(!rt()||c(window)||c(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 B=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=x.getInstance().get()?.container;if(c(o)||o===!1)return`https://identity.${this.#t??dt}`;let i=x.getInstance().get(),n=l(i)&&l(i?.internetIdentityId)?i.internetIdentityId:ut,{host:r,protocol:a}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:Z(lt)},identityProvider:s()}}},mt=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:Z(pt)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{AuthClient as me}from"@dfinity/auth-client";var $=()=>me.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var yt=async({data:t})=>{try{return await q(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var D=async t=>{let{data:e,version:s,description:o}=t;return{description:m(o),data:await nt(e),version:m(s)}},I=t=>{let{version:e}=t;return{version:m(e)}},F=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:p(i),owner:s.toText(),data:await q(n),version:p(o),...r}};import{Principal as ye}from"@dfinity/principal";var ft=t=>{if(c(t))return m();switch(t.matcher){case"equal":return m({Equal:t.timestamp});case"greaterThan":return m({GreaterThan:t.timestamp});case"lessThan":return m({LessThan:t.timestamp});case"between":return m({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},k=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:c(t)?[]:[{key:m(t.key),description:m(t.description),created_at:ft(t.createdAt),updated_at:ft(t.updatedAt)}],paginate:m(c(e)?void 0:{start_after:m(e.startAfter),limit:m(c(e.limit)?void 0:BigInt(e.limit))}),order:m(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:m(c(o)?void 0:typeof o=="string"?ye.fromText(o):o)});var gt=({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.Variant({UpdatedAt:t.Null,Keys:t.Null,CreatedAt:t.Null}),o=t.Record({field:s,desc:t.Bool}),i=t.Variant({Equal:t.Nat64,Between:t.Tuple(t.Nat64,t.Nat64),GreaterThan:t.Nat64,LessThan:t.Nat64}),n=t.Record({key:t.Opt(t.Text),updated_at:t.Opt(i),description:t.Opt(t.Text),created_at:t.Opt(i)}),r=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(o),owner:t.Opt(t.Principal),matcher:t.Opt(n),paginate:t.Opt(r)}),u=t.Record({controllers:t.Vec(t.Principal)}),T=t.Variant({Write:t.Null,Admin:t.Null}),f=t.Record({updated_at:t.Nat64,metadata:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,scope:T,expires_at:t.Opt(t.Nat64)}),h=t.Record({version:t.Opt(t.Nat64)}),_=t.Variant({Db:t.Null,Storage:t.Null}),w=t.Record({version:t.Opt(t.Nat64)}),v=t.Record({cycles:t.Nat,destination_id:t.Principal}),N=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}),O=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:N,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,O)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),S=t.Record({derivation_origin:t.Opt(t.Text)}),E=t.Record({internet_identity:t.Opt(S)}),V=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),U=t.Record({max_memory_size:t.Opt(V)}),Wt=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),Gt=t.Variant({Deny:t.Null,Allow:t.Null}),Yt=t.Record({status_code:t.Nat16,location:t.Text}),H=t.Record({iframe:t.Opt(Wt),rewrites:t.Vec(t.Tuple(t.Text,t.Text)),headers:t.Vec(t.Tuple(t.Text,t.Vec(t.Tuple(t.Text,t.Text)))),max_memory_size:t.Opt(V),raw_access:t.Opt(Gt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,Yt)))}),Jt=t.Record({db:t.Opt(U),authentication:t.Opt(E),storage:H}),C=t.Record({updated_at:t.Nat64,owner:t.Principal,data:t.Vec(t.Nat8),description:t.Opt(t.Text),created_at:t.Nat64,version:t.Opt(t.Nat64)}),Xt=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)}),W=t.Variant({Heap:t.Null,Stable:t.Null}),G=t.Record({memory:W,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}),Qt=t.Variant({Callback:t.Record({token:G,callback:t.Func([],[],["query"])})}),Zt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Qt),status_code:t.Nat16}),Dt=t.Record({token:t.Opt(G),body:t.Vec(t.Nat8)}),It=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}),Lt=t.Record({batch_id:t.Nat}),te=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,g)),items_length:t.Nat64}),ee=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),se=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,C)),items_length:t.Nat64}),M=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),oe=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(W),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:M,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:M}),ie=t.Record({stable:t.Nat64,heap:t.Nat64}),ne=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:T,expires_at:t.Opt(t.Nat64)}),re=t.Record({controller:ne,controllers:t.Vec(t.Principal)}),ot=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),ae=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(W),max_size:t.Opt(t.Nat),read:M,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:M}),ce=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),le=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,a],[t.Nat64],["query"]),count_collection_assets:t.Func([t.Text],[t.Nat64],["query"]),count_collection_docs:t.Func([t.Text],[t.Nat64],["query"]),count_docs:t.Func([t.Text,a],[t.Nat64],["query"]),del_asset:t.Func([t.Text,t.Text],[],[]),del_assets:t.Func([t.Text],[],[]),del_controllers:t.Func([u],[t.Vec(t.Tuple(t.Principal,f))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,h],[],[]),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,h))],[],[]),del_rule:t.Func([_,t.Text,w],[],[]),deposit_cycles:t.Func([v],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(E)],["query"]),get_config:t.Func([],[Jt],[]),get_db_config:t.Func([],[t.Opt(U)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(C)],["query"]),get_many_assets:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(g)))],["query"]),get_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text))],[t.Vec(t.Tuple(t.Text,t.Opt(C)))],["query"]),get_storage_config:t.Func([],[H],["query"]),http_request:t.Func([Xt],[Zt],["query"]),http_request_streaming_callback:t.Func([G],[Dt],["query"]),init_asset_upload:t.Func([It],[Lt],[]),list_assets:t.Func([t.Text,a],[te],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,f))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,ee))],["query"]),list_docs:t.Func([t.Text,a],[se],["query"]),list_rules:t.Func([_],[t.Vec(t.Tuple(t.Text,oe))],["query"]),memory_size:t.Func([],[ie],["query"]),set_auth_config:t.Func([E],[],[]),set_controllers:t.Func([re],[t.Vec(t.Tuple(t.Principal,f))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([U],[],[]),set_doc:t.Func([t.Text,t.Text,ot],[C],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,ot))],[t.Vec(t.Tuple(t.Text,C))],[]),set_rule:t.Func([_,t.Text,ae],[],[]),set_storage_config:t.Func([H],[],[]),upload_asset_chunk:t.Func([ce],[le],[]),version:t.Func([],[t.Text],["query"])})};import{Actor as fe,HttpAgent as ge}from"@dfinity/agent";var ht=async({satelliteId:t,idlFactory:e,identity:s,fetch:o,container:i})=>{let r=l(i)&&i!==!1?i===!0?R:i:"https://icp-api.io",a=new ge({identity:s,host:r,...o&&{fetch:o}});return l(i)&&await a.fetchRootKey(),fe.createActor(e,{agent:a,canisterId:t})};var _t=({satelliteId:t,container:e})=>{let{satelliteId:s}=L({satelliteId:t}),{container:o}=tt({container:e});if(l(o)&&o!==!1){let{host:i,protocol:n}=new URL(o===!0?R:o);return`${n}//${s??"unknown"}.${i.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},L=({satelliteId:t})=>l(t)?{satelliteId:t}:x.getInstance().get()??{satelliteId:void 0},tt=({container:t})=>l(t)?{container:t}:x.getInstance().get()??{container:void 0};var y=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=L({satelliteId:t});K(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=tt({container:e});return ht({satelliteId:o,container:i,idlFactory:gt,...s})};var Tt=async({collection:t,key:e,satellite:s})=>{let{get_doc:o}=await y(s),i=p(await o(t,e));if(!c(i))return F({doc:i,key:e})},xt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await y(e),o=t.map(({collection:r,key:a})=>[r,a]),i=await s(o),n=[];for(let[r,a]of i){let u=p(a);n.push(l(u)?await F({key:r,doc:u}):void 0)}return n},At=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await y(s),{key:i}=e,n=await D(e),r=await o(t,i,n);return await F({key:i,doc:r})},Nt=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await y(e),o=[];for(let{collection:r,doc:a}of t){let{key:u}=a;o.push([r,u,await D(a)])}let i=await s(o),n=[];for(let[r,a]of i)n.push(await F({key:r,doc:a}));return n},Pt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await y(s),{key:i}=e;return o(t,i,I(e))},wt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await y(e),o=t.map(({collection:i,doc:n})=>[i,n.key,I(n)]);await s(o)},vt=async({collection:t,filter:e,satellite:s})=>{let{list_docs:o}=await y(s),{items:i,items_page:n,items_length:r,matches_length:a,matches_pages:u}=await o(t,k(e)),T=[];for(let[f,h]of i){let{data:_,owner:w,description:v,version:N,...O}=h;T.push({key:f,description:p(v),owner:w.toText(),data:await yt({data:_}),version:p(N),...O})}return{items:T,items_length:r,items_page:p(n),matches_length:a,matches_pages:p(u)}},Ot=async({collection:t,filter:e,satellite:s})=>{let{count_docs:o}=await y(s);return o(t,k(e))};import{AnonymousIdentity as he}from"@dfinity/agent";var d=t=>t!==void 0?t:j()??new he;var St=async({satellite:t,...e})=>{let s=d(t?.identity);return Tt({...e,satellite:{...t,identity:s}})},Ss=async({satellite:t,...e})=>{let s=d(t?.identity);return xt({...e,satellite:{...t,identity:s}})},bt=async({satellite:t,...e})=>{let s=d(t?.identity);return At({...e,satellite:{...t,identity:s}})},bs=async({satellite:t,...e})=>{let s=d(t?.identity);return Nt({...e,satellite:{...t,identity:s}})},Rs=async({satellite:t,...e})=>{let s=d(t?.identity);return Pt({...e,satellite:{...t,identity:s}})},ks=async({satellite:t,...e})=>{let s=d(t?.identity);return wt({...e,satellite:{...t,identity:s}})},Es=async({satellite:t,filter:e,...s})=>{let o=d(t?.identity);return vt({...s,filter:e??{},satellite:{...t,identity:o}})},Us=async({satellite:t,filter:e,...s})=>{let o=d(t?.identity);return Ot({...s,filter:e??{},satellite:{...t,identity:o}})};var Rt=async t=>{let e=j();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await St({collection:"#user",key:s});return c(o)?await _e({userId:s,provider:t}):o},_e=async({userId:t,...e})=>bt({collection:"#user",doc:{key:t,data:e}});var A,et=async t=>{if(A=A??await $(),!(await A?.isAuthenticated()??!1))return;let s=await Rt(t);P.getInstance().set(s)},Te=async t=>new Promise(async(e,s)=>{A=A??await $();let o=t?.provider??new B({});await A.login({onSuccess:async()=>{await et(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??at,allowPinAuthentication:t?.allowPin??ct,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),st=async()=>{await A?.logout(),A=void 0,P.getInstance().reset()},j=()=>A?.getIdentity(),xe=async()=>(A??await $()).getIdentity();var kt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{Q({message:"junoSignOutAuthTimer"}),await st()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":Q({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},P.getInstance().subscribe(i=>{if(c(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Et=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_SATELLITE_ID??import.meta.env?.PUBLIC_SATELLITE_ID:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_SATELLITE_ID??t():t()},Ut=()=>{let t=()=>typeof import.meta<"u"&&typeof import.meta.env<"u"?import.meta.env?.VITE_CONTAINER??import.meta.env?.PUBLIC_CONTAINER:void 0;return typeof process<"u"?process.env?.NEXT_PUBLIC_CONTAINER??t():t()};import"@dfinity/principal";var Ae=t=>t==null,Ne=t=>!Ae(t),z=t=>Ne(t)?[t]:[],Pe=()=>typeof window<"u",Ct=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:a},actor:u,init_asset_upload:T})=>{let{batch_id:f}=await T({collection:s,full_path:n,name:e,token:z(i),encoding_type:z(r),description:z(a)}),h=19e5,_=[],w=Pe()?new Blob([await t.arrayBuffer()]):t,v=0n;for(let g=0;g<w.size;g+=h){let S=w.slice(g,g+h);_.push({batchId:f,chunk:S,actor:u,orderId:v}),v++}let N=[];for await(let g of we({uploadChunks:_}))N=[...N,...g];let O=o.find(([g,S])=>g.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await u.commit_asset_upload({batch_id:f,chunk_ids:N.map(({chunk_id:g})=>g),headers:[...o,...O||[]]})};async function*we({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(i=>ve(i)))}}var ve=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:z(o)});var Ft=async({satellite:t,...e})=>{let s=await y(t);await Ct({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},Vt=async({collection:t,satellite:e,filter:s})=>{let{list_assets:o}=await y(e),{items:i,items_length:n,items_page:r,matches_length:a,matches_pages:u}=await o(t,k(s));return{items:i.map(([T,f])=>f),items_length:n,items_page:p(r),matches_length:a,matches_pages:p(u)}},Mt=async({collection:t,satellite:e,filter:s})=>{let{count_assets:o}=await y(e);return o(t,k(s))},Kt=async({collection:t,fullPath:e,satellite:s})=>(await y(s)).del_asset(t,e),qt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await y(e),o=t.map(({collection:i,fullPath:n})=>[i,n]);await s(o)},Bt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await y(s);return p(await o(t,e))},$t=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await y(e),o=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(o)).map(([n,r])=>p(r))};var jt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var po=async t=>zt(t),uo=async t=>zt({filename:t.data.name,...t}),zt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:a,description:u})=>{let T=d(r?.identity),f=decodeURI(t),h=i??`/${s}/${f}`,_={...r,identity:T};return await Ft({data:e,filename:f,collection:s,token:n,headers:o,fullPath:h,encoding:a,satellite:_,description:u}),{downloadUrl:Ht({satellite:_,assetKey:{fullPath:h,token:n}}),fullPath:h,name:f}},mo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:d(e?.identity)},{items:i,...n}=await Vt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:a,token:u,name:T,owner:f,description:h},headers:_,encodings:w,created_at:v,updated_at:N})=>{let O=p(u);return{fullPath:a,description:p(h),name:T,downloadUrl:Ht({satellite:o,assetKey:{fullPath:a,token:O}}),token:O,headers:_,encodings:w.reduce((g,[S,{modified:E,sha256:V,total_length:U}])=>({...g,[S]:{modified:E,sha256:jt(V),total_length:U}}),{}),owner:f.toText(),created_at:v,updated_at:N}});return{items:r,assets:r,...n}},yo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:d(e?.identity)};return Mt({collection:t,satellite:o,filter:s??{}})},fo=async({collection:t,fullPath:e,satellite:s})=>Kt({collection:t,fullPath:e,satellite:{...s,identity:d(s?.identity)}}),go=async({assets:t,satellite:e})=>qt({assets:t,satellite:{...e,identity:d(e?.identity)}}),ho=async({satellite:t,...e})=>{let s=d(t?.identity);return Bt({...e,satellite:{...t,identity:s}})},_o=async({satellite:t,...e})=>{let s=d(t?.identity);return $t({...e,satellite:{...t,identity:s}})},Ht=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:d(s?.identity)};return`${_t(o)}${t}${l(e)?`?token=${e}`:""}`};var Oe=t=>{let e=t?.satelliteId??Et();K(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Ut();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},Oo=async t=>Se(t),Se=async t=>{let e=Oe(t);x.getInstance().set(e),await et();let s=e.workers?.auth!==void 0?kt(e.workers.auth):void 0;return[...s?[s]:[]]},So=t=>P.getInstance().subscribe(t);export{B as InternetIdentityProvider,mt as NFIDProvider,So as authSubscribe,yo as countAssets,Us as countDocs,fo as deleteAsset,Rs as deleteDoc,go as deleteManyAssets,ks as deleteManyDocs,Ht as downloadUrl,ho as getAsset,St as getDoc,_o as getManyAssets,Ss as getManyDocs,Oo as initJuno,Se as initSatellite,mo as listAssets,Es as listDocs,bt as setDoc,bs as setManyDocs,Te as signIn,st as signOut,xe as unsafeIdentity,po as uploadBlob,uo as uploadFile};
4
4
  //# sourceMappingURL=index.mjs.map