@junobuild/core-peer 0.0.28 → 0.0.29

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.
@@ -146,6 +146,10 @@ export interface MemorySize {
146
146
  heap: bigint;
147
147
  }
148
148
  export type Permission = {Controllers: null} | {Private: null} | {Public: null} | {Managed: null};
149
+ export interface RateConfig {
150
+ max_tokens: bigint;
151
+ time_per_token_ns: bigint;
152
+ }
149
153
  export interface Rule {
150
154
  max_capacity: [] | [number];
151
155
  memory: [] | [Memory];
@@ -155,6 +159,7 @@ export interface Rule {
155
159
  created_at: bigint;
156
160
  version: [] | [bigint];
157
161
  mutable_permissions: [] | [boolean];
162
+ rate_config: [] | [RateConfig];
158
163
  write: Permission;
159
164
  }
160
165
  export type RulesType = {Db: null} | {Storage: null};
@@ -179,6 +184,7 @@ export interface SetRule {
179
184
  read: Permission;
180
185
  version: [] | [bigint];
181
186
  mutable_permissions: [] | [boolean];
187
+ rate_config: [] | [RateConfig];
182
188
  write: Permission;
183
189
  }
184
190
  export interface StorageConfig {
@@ -240,6 +246,8 @@ export interface _SERVICE {
240
246
  del_custom_domain: ActorMethod<[string], undefined>;
241
247
  del_doc: ActorMethod<[string, string, DelDoc], undefined>;
242
248
  del_docs: ActorMethod<[string], undefined>;
249
+ del_filtered_assets: ActorMethod<[string, ListParams], undefined>;
250
+ del_filtered_docs: ActorMethod<[string, ListParams], undefined>;
243
251
  del_many_assets: ActorMethod<[Array<[string, string]>], undefined>;
244
252
  del_many_docs: ActorMethod<[Array<[string, string, DelDoc]>], undefined>;
245
253
  del_rule: ActorMethod<[RulesType, string, DelRule], undefined>;
@@ -251,6 +259,7 @@ export interface _SERVICE {
251
259
  get_doc: ActorMethod<[string, string], [] | [Doc]>;
252
260
  get_many_assets: ActorMethod<[Array<[string, string]>], Array<[string, [] | [AssetNoContent]]>>;
253
261
  get_many_docs: ActorMethod<[Array<[string, string]>], Array<[string, [] | [Doc]]>>;
262
+ get_rule: ActorMethod<[RulesType, string], [] | [Rule]>;
254
263
  get_storage_config: ActorMethod<[], StorageConfig>;
255
264
  http_request: ActorMethod<[HttpRequest], HttpResponse>;
256
265
  http_request_streaming_callback: ActorMethod<
@@ -270,7 +279,7 @@ export interface _SERVICE {
270
279
  set_db_config: ActorMethod<[DbConfig], undefined>;
271
280
  set_doc: ActorMethod<[string, string, SetDoc], Doc>;
272
281
  set_many_docs: ActorMethod<[Array<[string, string, SetDoc]>], Array<[string, Doc]>>;
273
- set_rule: ActorMethod<[RulesType, string, SetRule], undefined>;
282
+ set_rule: ActorMethod<[RulesType, string, SetRule], Rule>;
274
283
  set_storage_config: ActorMethod<[StorageConfig], undefined>;
275
284
  upload_asset_chunk: ActorMethod<[UploadChunk], UploadChunkResult>;
276
285
  version: ActorMethod<[], string>;
@@ -122,6 +122,29 @@ export const idlFactory = ({IDL}) => {
122
122
  created_at: IDL.Nat64,
123
123
  version: IDL.Opt(IDL.Nat64)
124
124
  });
125
+ const Memory = IDL.Variant({Heap: IDL.Null, Stable: IDL.Null});
126
+ const Permission = IDL.Variant({
127
+ Controllers: IDL.Null,
128
+ Private: IDL.Null,
129
+ Public: IDL.Null,
130
+ Managed: IDL.Null
131
+ });
132
+ const RateConfig = IDL.Record({
133
+ max_tokens: IDL.Nat64,
134
+ time_per_token_ns: IDL.Nat64
135
+ });
136
+ const Rule = IDL.Record({
137
+ max_capacity: IDL.Opt(IDL.Nat32),
138
+ memory: IDL.Opt(Memory),
139
+ updated_at: IDL.Nat64,
140
+ max_size: IDL.Opt(IDL.Nat),
141
+ read: Permission,
142
+ created_at: IDL.Nat64,
143
+ version: IDL.Opt(IDL.Nat64),
144
+ mutable_permissions: IDL.Opt(IDL.Bool),
145
+ rate_config: IDL.Opt(RateConfig),
146
+ write: Permission
147
+ });
125
148
  const HttpRequest = IDL.Record({
126
149
  url: IDL.Text,
127
150
  method: IDL.Text,
@@ -129,7 +152,6 @@ export const idlFactory = ({IDL}) => {
129
152
  headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
130
153
  certificate_version: IDL.Opt(IDL.Nat16)
131
154
  });
132
- const Memory = IDL.Variant({Heap: IDL.Null, Stable: IDL.Null});
133
155
  const StreamingCallbackToken = IDL.Record({
134
156
  memory: Memory,
135
157
  token: IDL.Opt(IDL.Text),
@@ -184,23 +206,6 @@ export const idlFactory = ({IDL}) => {
184
206
  items: IDL.Vec(IDL.Tuple(IDL.Text, Doc)),
185
207
  items_length: IDL.Nat64
186
208
  });
187
- const Permission = IDL.Variant({
188
- Controllers: IDL.Null,
189
- Private: IDL.Null,
190
- Public: IDL.Null,
191
- Managed: IDL.Null
192
- });
193
- const Rule = IDL.Record({
194
- max_capacity: IDL.Opt(IDL.Nat32),
195
- memory: IDL.Opt(Memory),
196
- updated_at: IDL.Nat64,
197
- max_size: IDL.Opt(IDL.Nat),
198
- read: Permission,
199
- created_at: IDL.Nat64,
200
- version: IDL.Opt(IDL.Nat64),
201
- mutable_permissions: IDL.Opt(IDL.Bool),
202
- write: Permission
203
- });
204
209
  const MemorySize = IDL.Record({stable: IDL.Nat64, heap: IDL.Nat64});
205
210
  const SetController = IDL.Record({
206
211
  metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
@@ -223,6 +228,7 @@ export const idlFactory = ({IDL}) => {
223
228
  read: Permission,
224
229
  version: IDL.Opt(IDL.Nat64),
225
230
  mutable_permissions: IDL.Opt(IDL.Bool),
231
+ rate_config: IDL.Opt(RateConfig),
226
232
  write: Permission
227
233
  });
228
234
  const UploadChunk = IDL.Record({
@@ -248,6 +254,8 @@ export const idlFactory = ({IDL}) => {
248
254
  del_custom_domain: IDL.Func([IDL.Text], [], []),
249
255
  del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []),
250
256
  del_docs: IDL.Func([IDL.Text], [], []),
257
+ del_filtered_assets: IDL.Func([IDL.Text, ListParams], [], []),
258
+ del_filtered_docs: IDL.Func([IDL.Text, ListParams], [], []),
251
259
  del_many_assets: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [], []),
252
260
  del_many_docs: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, DelDoc))], [], []),
253
261
  del_rule: IDL.Func([RulesType, IDL.Text, DelRule], [], []),
@@ -267,6 +275,7 @@ export const idlFactory = ({IDL}) => {
267
275
  [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
268
276
  ['query']
269
277
  ),
278
+ get_rule: IDL.Func([RulesType, IDL.Text], [IDL.Opt(Rule)], ['query']),
270
279
  get_storage_config: IDL.Func([], [StorageConfig], ['query']),
271
280
  http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
272
281
  http_request_streaming_callback: IDL.Func(
@@ -295,7 +304,7 @@ export const idlFactory = ({IDL}) => {
295
304
  [IDL.Vec(IDL.Tuple(IDL.Text, Doc))],
296
305
  []
297
306
  ),
298
- set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []),
307
+ set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [Rule], []),
299
308
  set_storage_config: IDL.Func([StorageConfig], [], []),
300
309
  upload_asset_chunk: IDL.Func([UploadChunk], [UploadChunkResult], []),
301
310
  version: IDL.Func([], [IDL.Text], ['query'])
@@ -122,6 +122,29 @@ export const idlFactory = ({IDL}) => {
122
122
  created_at: IDL.Nat64,
123
123
  version: IDL.Opt(IDL.Nat64)
124
124
  });
125
+ const Memory = IDL.Variant({Heap: IDL.Null, Stable: IDL.Null});
126
+ const Permission = IDL.Variant({
127
+ Controllers: IDL.Null,
128
+ Private: IDL.Null,
129
+ Public: IDL.Null,
130
+ Managed: IDL.Null
131
+ });
132
+ const RateConfig = IDL.Record({
133
+ max_tokens: IDL.Nat64,
134
+ time_per_token_ns: IDL.Nat64
135
+ });
136
+ const Rule = IDL.Record({
137
+ max_capacity: IDL.Opt(IDL.Nat32),
138
+ memory: IDL.Opt(Memory),
139
+ updated_at: IDL.Nat64,
140
+ max_size: IDL.Opt(IDL.Nat),
141
+ read: Permission,
142
+ created_at: IDL.Nat64,
143
+ version: IDL.Opt(IDL.Nat64),
144
+ mutable_permissions: IDL.Opt(IDL.Bool),
145
+ rate_config: IDL.Opt(RateConfig),
146
+ write: Permission
147
+ });
125
148
  const HttpRequest = IDL.Record({
126
149
  url: IDL.Text,
127
150
  method: IDL.Text,
@@ -129,7 +152,6 @@ export const idlFactory = ({IDL}) => {
129
152
  headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
130
153
  certificate_version: IDL.Opt(IDL.Nat16)
131
154
  });
132
- const Memory = IDL.Variant({Heap: IDL.Null, Stable: IDL.Null});
133
155
  const StreamingCallbackToken = IDL.Record({
134
156
  memory: Memory,
135
157
  token: IDL.Opt(IDL.Text),
@@ -184,23 +206,6 @@ export const idlFactory = ({IDL}) => {
184
206
  items: IDL.Vec(IDL.Tuple(IDL.Text, Doc)),
185
207
  items_length: IDL.Nat64
186
208
  });
187
- const Permission = IDL.Variant({
188
- Controllers: IDL.Null,
189
- Private: IDL.Null,
190
- Public: IDL.Null,
191
- Managed: IDL.Null
192
- });
193
- const Rule = IDL.Record({
194
- max_capacity: IDL.Opt(IDL.Nat32),
195
- memory: IDL.Opt(Memory),
196
- updated_at: IDL.Nat64,
197
- max_size: IDL.Opt(IDL.Nat),
198
- read: Permission,
199
- created_at: IDL.Nat64,
200
- version: IDL.Opt(IDL.Nat64),
201
- mutable_permissions: IDL.Opt(IDL.Bool),
202
- write: Permission
203
- });
204
209
  const MemorySize = IDL.Record({stable: IDL.Nat64, heap: IDL.Nat64});
205
210
  const SetController = IDL.Record({
206
211
  metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)),
@@ -223,6 +228,7 @@ export const idlFactory = ({IDL}) => {
223
228
  read: Permission,
224
229
  version: IDL.Opt(IDL.Nat64),
225
230
  mutable_permissions: IDL.Opt(IDL.Bool),
231
+ rate_config: IDL.Opt(RateConfig),
226
232
  write: Permission
227
233
  });
228
234
  const UploadChunk = IDL.Record({
@@ -248,6 +254,8 @@ export const idlFactory = ({IDL}) => {
248
254
  del_custom_domain: IDL.Func([IDL.Text], [], []),
249
255
  del_doc: IDL.Func([IDL.Text, IDL.Text, DelDoc], [], []),
250
256
  del_docs: IDL.Func([IDL.Text], [], []),
257
+ del_filtered_assets: IDL.Func([IDL.Text, ListParams], [], []),
258
+ del_filtered_docs: IDL.Func([IDL.Text, ListParams], [], []),
251
259
  del_many_assets: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))], [], []),
252
260
  del_many_docs: IDL.Func([IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text, DelDoc))], [], []),
253
261
  del_rule: IDL.Func([RulesType, IDL.Text, DelRule], [], []),
@@ -267,6 +275,7 @@ export const idlFactory = ({IDL}) => {
267
275
  [IDL.Vec(IDL.Tuple(IDL.Text, IDL.Opt(Doc)))],
268
276
  ['query']
269
277
  ),
278
+ get_rule: IDL.Func([RulesType, IDL.Text], [IDL.Opt(Rule)], ['query']),
270
279
  get_storage_config: IDL.Func([], [StorageConfig], ['query']),
271
280
  http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']),
272
281
  http_request_streaming_callback: IDL.Func(
@@ -295,7 +304,7 @@ export const idlFactory = ({IDL}) => {
295
304
  [IDL.Vec(IDL.Tuple(IDL.Text, Doc))],
296
305
  []
297
306
  ),
298
- set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [], []),
307
+ set_rule: IDL.Func([RulesType, IDL.Text, SetRule], [Rule], []),
299
308
  set_storage_config: IDL.Func([StorageConfig], [], []),
300
309
  upload_asset_chunk: IDL.Func([UploadChunk], [UploadChunkResult], []),
301
310
  version: IDL.Func([], [IDL.Text], ['query'])
@@ -1,4 +1,4 @@
1
1
  import { createRequire as topLevelCreateRequire } from 'module';
2
2
  const require = topLevelCreateRequire(import.meta.url);
3
- import{Principal as rt}from"@dfinity/principal";var a=t=>t==null,l=t=>!a(t),me=class extends Error{},B=(t,e)=>{if(a(t))throw new me(e)},X="__bigint__",Q="__principal__",Z="__uint8array__",ye=(t,e)=>typeof e=="bigint"?{[X]:`${e}`}:l(e)&&e instanceof rt?{[Q]:e.toText()}:l(e)&&e instanceof Uint8Array?{[Z]:Array.from(e)}:e,fe=(t,e)=>{let s=o=>e[o];return l(e)&&typeof e=="object"&&X in e?BigInt(s(X)):l(e)&&typeof e=="object"&&Q in e?rt.fromText(s(Q)):l(e)&&typeof e=="object"&&Z in e?Uint8Array.from(s(Z)):e},m=t=>l(t)?[t]:[],d=t=>t?.[0],at=async t=>{let e=new Blob([JSON.stringify(t,ye)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},$=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(),fe)},ct=()=>typeof window<"u";var O=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 O{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 I=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var lt=BigInt(144e11),pt=!1,dt={width:576,height:576},ut={width:505,height:705},mt="internetcomputer.org";var R="http://127.0.0.1:5987",yt="rdmx6-jaaaa-aaaaa-aaadq-cai";var _=class t extends O{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 D=({width:t,height:e})=>{if(!ct()||a(window)||a(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 j=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let o=_.getInstance().get()?.container;if(a(o)||o===!1)return`https://identity.${this.#t??mt}`;let i=_.getInstance().get(),n=l(i)&&l(i?.internetIdentityId)?i.internetIdentityId:yt,{host:r,protocol:c}=new URL(o===!0?R:o);return/apple/i.test(navigator?.vendor)?`${c}//${r}?canisterId=${n}`:`${c}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:D(dt)},identityProvider:s()}}},ft=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:D(ut)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{Actor as he}from"@dfinity/agent";import{HttpAgent as ge}from"@dfinity/agent";var k=class t{static instance;#t=void 0;constructor(){}static getInstance(){return a(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...s}){let o=e.getPrincipal().toText();if(a(this.#t)||a(this.#t[o])){let i=await this.createAgent({identity:e,...s});return this.#t={...this.#t??{},[o]:i},i}return this.#t[o]}reset(){this.#t=null}async createAgent({identity:e,fetch:s,container:o}){let n=l(o)&&o!==!1?o===!0?R:o:"https://icp-api.io",r=l(o);return await ge.create({identity:e,shouldFetchRootKey:r,host:n,...s&&{fetch:s}})}};var E=class t{static instance;#t=void 0;constructor(){}static getInstance(){return a(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:s,buildType:o,...i}){let n=`${o}#${s.getPrincipal().toText()}#${e};`;if(a(this.#t)||a(this.#t[n])){let r=await this.createActor({satelliteId:e,identity:s,...i});return this.#t={...this.#t??{},[n]:r},r}return this.#t[n]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:s,...o}){let i=await k.getInstance().getAgent(o);return he.createActor(e,{agent:i,canisterId:s})}};import{AuthClient as Ae}from"@dfinity/auth-client";var H=()=>Ae.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var gt=async({data:t})=>{try{return await $(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var L=async t=>{let{data:e,version:s,description:o}=t;return{description:m(o),data:await at(e),version:m(s)}},tt=t=>{let{version:e}=t;return{version:m(e)}},V=async({doc:t,key:e})=>{let{owner:s,version:o,description:i,data:n,...r}=t;return{key:e,description:d(i),owner:s.toText(),data:await $(n),version:d(o),...r}};import{Principal as Te}from"@dfinity/principal";var ht=t=>{if(a(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)}},U=({matcher:t,paginate:e,order:s,owner:o})=>({matcher:a(t)?[]:[{key:m(t.key),description:m(t.description),created_at:ht(t.createdAt),updated_at:ht(t.updatedAt)}],paginate:m(a(e)?void 0:{start_after:m(e.startAfter),limit:m(a(e.limit)?void 0:BigInt(e.limit))}),order:m(a(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:m(a(o)?void 0:typeof o=="string"?Te.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.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)}),c=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)}),A=t.Variant({Db:t.Null,Storage:t.Null}),w=t.Record({version:t.Opt(t.Nat64)}),S=t.Record({cycles:t.Nat,destination_id:t.Principal}),P=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}),v=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:P,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,v)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),b=t.Record({derivation_origin:t.Opt(t.Text)}),C=t.Record({internet_identity:t.Opt(b)}),K=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),F=t.Record({max_memory_size:t.Opt(K)}),Jt=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),Xt=t.Variant({Deny:t.Null,Allow:t.Null}),Qt=t.Record({status_code:t.Nat16,location:t.Text}),G=t.Record({iframe:t.Opt(Jt),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(K),raw_access:t.Opt(Xt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,Qt)))}),Zt=t.Record({db:t.Opt(F),authentication:t.Opt(C),storage:G}),M=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)}),It=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)}),Y=t.Variant({Heap:t.Null,Stable:t.Null}),J=t.Record({memory:Y,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}),Dt=t.Variant({Callback:t.Record({token:J,callback:t.Func([],[],["query"])})}),Lt=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(Dt),status_code:t.Nat16}),te=t.Record({token:t.Opt(J),body:t.Vec(t.Nat8)}),ee=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}),se=t.Record({batch_id:t.Nat}),oe=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}),ie=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),ne=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,M)),items_length:t.Nat64}),q=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),re=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Y),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:q,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:q}),ae=t.Record({stable:t.Nat64,heap:t.Nat64}),ce=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:T,expires_at:t.Opt(t.Nat64)}),le=t.Record({controller:ce,controllers:t.Vec(t.Principal)}),nt=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),pe=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Y),max_size:t.Opt(t.Nat),read:q,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),write:q}),de=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),ue=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,c],[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,c],[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([A,t.Text,w],[],[]),deposit_cycles:t.Func([S],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(C)],["query"]),get_config:t.Func([],[Zt],[]),get_db_config:t.Func([],[t.Opt(F)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(M)],["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(M)))],["query"]),get_storage_config:t.Func([],[G],["query"]),http_request:t.Func([It],[Lt],["query"]),http_request_streaming_callback:t.Func([J],[te],["query"]),init_asset_upload:t.Func([ee],[se],[]),list_assets:t.Func([t.Text,c],[oe],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,f))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,ie))],["query"]),list_docs:t.Func([t.Text,c],[ne],["query"]),list_rules:t.Func([A],[t.Vec(t.Tuple(t.Text,re))],["query"]),memory_size:t.Func([],[ae],["query"]),set_auth_config:t.Func([C],[],[]),set_controllers:t.Func([le],[t.Vec(t.Tuple(t.Principal,f))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([F],[],[]),set_doc:t.Func([t.Text,t.Text,nt],[M],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,nt))],[t.Vec(t.Tuple(t.Text,M))],[]),set_rule:t.Func([A,t.Text,pe],[],[]),set_storage_config:t.Func([G],[],[]),upload_asset_chunk:t.Func([de],[ue],[]),version:t.Func([],[t.Text],["query"])})};var Tt=({satelliteId:t,container:e})=>{let{satelliteId:s}=et({satelliteId:t}),{container:o}=st({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`},et=({satelliteId:t})=>l(t)?{satelliteId:t}:_.getInstance().get()??{satelliteId:void 0},st=({container:t})=>l(t)?{container:t}:_.getInstance().get()??{container:void 0};var y=async t=>xt({idlFactory:At,buildType:"stock",...t}),_t=async({idlFactory:t,...e})=>xt({idlFactory:t,buildType:"extended",...e}),xt=async({satelliteId:t,container:e,...s})=>{let{satelliteId:o}=et({satelliteId:t});B(o,"No satellite ID defined. Did you initialize Juno?");let{container:i}=st({container:e});return await E.getInstance().getActor({satelliteId:o,container:i,...s})};var Pt=async({collection:t,key:e,satellite:s})=>{let{get_doc:o}=await y(s),i=d(await o(t,e));if(!a(i))return V({doc:i,key:e})},Nt=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await y(e),o=t.map(({collection:r,key:c})=>[r,c]),i=await s(o),n=[];for(let[r,c]of i){let u=d(c);n.push(l(u)?await V({key:r,doc:u}):void 0)}return n},wt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:o}=await y(s),{key:i}=e,n=await L(e),r=await o(t,i,n);return await V({key:i,doc:r})},St=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await y(e),o=[];for(let{collection:r,doc:c}of t){let{key:u}=c;o.push([r,u,await L(c)])}let i=await s(o),n=[];for(let[r,c]of i)n.push(await V({key:r,doc:c}));return n},vt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:o}=await y(s),{key:i}=e;return o(t,i,tt(e))},bt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await y(e),o=t.map(({collection:i,doc:n})=>[i,n.key,tt(n)]);await s(o)},Ot=async({collection:t,filter:e,satellite:s})=>{let{list_docs:o}=await y(s),{items:i,items_page:n,items_length:r,matches_length:c,matches_pages:u}=await o(t,U(e)),T=[];for(let[f,h]of i){let{data:A,owner:w,description:S,version:P,...v}=h;T.push({key:f,description:d(S),owner:w.toText(),data:await gt({data:A}),version:d(P),...v})}return{items:T,items_length:r,items_page:d(n),matches_length:c,matches_pages:d(u)}},Rt=async({collection:t,filter:e,satellite:s})=>{let{count_docs:o}=await y(s);return o(t,U(e))};import{AnonymousIdentity as _e}from"@dfinity/agent";var p=t=>t!==void 0?t:z()??new _e;var kt=async({satellite:t,...e})=>{let s=p(t?.identity);return Pt({...e,satellite:{...t,identity:s}})},Fs=async({satellite:t,...e})=>{let s=p(t?.identity);return Nt({...e,satellite:{...t,identity:s}})},Et=async({satellite:t,...e})=>{let s=p(t?.identity);return wt({...e,satellite:{...t,identity:s}})},Ms=async({satellite:t,...e})=>{let s=p(t?.identity);return St({...e,satellite:{...t,identity:s}})},Vs=async({satellite:t,...e})=>{let s=p(t?.identity);return vt({...e,satellite:{...t,identity:s}})},Ks=async({satellite:t,...e})=>{let s=p(t?.identity);return bt({...e,satellite:{...t,identity:s}})},qs=async({satellite:t,filter:e,...s})=>{let o=p(t?.identity);return Ot({...s,filter:e??{},satellite:{...t,identity:o}})},Bs=async({satellite:t,filter:e,...s})=>{let o=p(t?.identity);return Rt({...s,filter:e??{},satellite:{...t,identity:o}})};var Ut=async t=>{let e=z();if(a(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),o=await kt({collection:"#user",key:s});return a(o)?await xe({userId:s,provider:t}):o},xe=async({userId:t,...e})=>Et({collection:"#user",doc:{key:t,data:e}});var x,ot=async t=>{if(x=x??await H(),!(await x?.isAuthenticated()??!1))return;let s=await Ut(t);N.getInstance().set(s)},Pe=async t=>new Promise(async(e,s)=>{x=x??await H();let o=t?.provider??new j({});await x.login({onSuccess:async()=>{await ot(o.id),e()},onError:i=>s(i),maxTimeToLive:t?.maxTimeToLive??lt,allowPinAuthentication:t?.allowPin??pt,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...o.signInOptions({windowed:t?.windowed})})}),it=async()=>{await x?.logout(),x=void 0,N.getInstance().reset(),E.getInstance().reset(),k.getInstance().reset()},z=()=>x?.getIdentity(),Ne=async()=>(x??await H()).getIdentity();var Ct=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),o=async()=>{I({message:"junoSignOutAuthTimer"}),await it()};return s.onmessage=async({data:i})=>{let{msg:n,data:r}=i;switch(n){case"junoSignOutAuthTimer":await o();return;case"junoDelegationRemainingTime":I({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},N.getInstance().subscribe(i=>{if(a(i)){s.postMessage({msg:"junoStopAuthTimer"});return}s.postMessage({msg:"junoStartAuthTimer"})})};var Ft=()=>{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()},Mt=()=>{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()};var ao=async({idlFactory:t,satellite:e})=>{let s=p(e?.identity);return _t({idlFactory:t,...e,identity:s})};import"@dfinity/principal";var we=t=>t==null,Se=t=>!we(t),W=t=>Se(t)?[t]:[],ve=()=>typeof window<"u",Vt=async({asset:{data:t,filename:e,collection:s,headers:o,token:i,fullPath:n,encoding:r,description:c},actor:u,init_asset_upload:T})=>{let{batch_id:f}=await T({collection:s,full_path:n,name:e,token:W(i),encoding_type:W(r),description:W(c)}),h=19e5,A=[],w=ve()?new Blob([await t.arrayBuffer()]):t,S=0n;for(let g=0;g<w.size;g+=h){let b=w.slice(g,g+h);A.push({batchId:f,chunk:b,actor:u,orderId:S}),S++}let P=[];for await(let g of be({uploadChunks:A}))P=[...P,...g];let v=o.find(([g,b])=>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:P.map(({chunk_id:g})=>g),headers:[...o,...v||[]]})};async function*be({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=>Oe(i)))}}var Oe=async({batchId:t,chunk:e,actor:s,orderId:o})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:W(o)});var Kt=async({satellite:t,...e})=>{let s=await y(t);await Vt({actor:s,asset:e,init_asset_upload:async i=>await s.init_asset_upload(i)})},qt=async({collection:t,satellite:e,filter:s})=>{let{list_assets:o}=await y(e),{items:i,items_length:n,items_page:r,matches_length:c,matches_pages:u}=await o(t,U(s));return{items:i.map(([T,f])=>f),items_length:n,items_page:d(r),matches_length:c,matches_pages:d(u)}},Bt=async({collection:t,satellite:e,filter:s})=>{let{count_assets:o}=await y(e);return o(t,U(s))},$t=async({collection:t,fullPath:e,satellite:s})=>(await y(s)).del_asset(t,e),jt=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)},Ht=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:o}=await y(s);return d(await o(t,e))},zt=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])=>d(r))};var Wt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var wo=async t=>Gt(t),So=async t=>Gt({filename:t.data.name,...t}),Gt=async({filename:t,data:e,collection:s,headers:o=[],fullPath:i,token:n,satellite:r,encoding:c,description:u})=>{let T=p(r?.identity),f=decodeURI(t),h=i??`/${s}/${f}`,A={...r,identity:T};return await Kt({data:e,filename:f,collection:s,token:n,headers:o,fullPath:h,encoding:c,satellite:A,description:u}),{downloadUrl:Yt({satellite:A,assetKey:{fullPath:h,token:n}}),fullPath:h,name:f}},vo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:p(e?.identity)},{items:i,...n}=await qt({collection:t,satellite:o,filter:s??{}}),r=i.map(({key:{full_path:c,token:u,name:T,owner:f,description:h},headers:A,encodings:w,created_at:S,updated_at:P})=>{let v=d(u);return{fullPath:c,description:d(h),name:T,downloadUrl:Yt({satellite:o,assetKey:{fullPath:c,token:v}}),token:v,headers:A,encodings:w.reduce((g,[b,{modified:C,sha256:K,total_length:F}])=>({...g,[b]:{modified:C,sha256:Wt(K),total_length:F}}),{}),owner:f.toText(),created_at:S,updated_at:P}});return{items:r,assets:r,...n}},bo=async({collection:t,satellite:e,filter:s})=>{let o={...e,identity:p(e?.identity)};return Bt({collection:t,satellite:o,filter:s??{}})},Oo=async({collection:t,fullPath:e,satellite:s})=>$t({collection:t,fullPath:e,satellite:{...s,identity:p(s?.identity)}}),Ro=async({assets:t,satellite:e})=>jt({assets:t,satellite:{...e,identity:p(e?.identity)}}),ko=async({satellite:t,...e})=>{let s=p(t?.identity);return Ht({...e,satellite:{...t,identity:s}})},Eo=async({satellite:t,...e})=>{let s=p(t?.identity);return zt({...e,satellite:{...t,identity:s}})},Yt=({assetKey:{fullPath:t,token:e},satellite:s})=>{let o={...s,identity:p(s?.identity)};return`${Tt(o)}${t}${l(e)?`?token=${e}`:""}`};var Re=t=>{let e=t?.satelliteId??Ft();B(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??Mt();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},Bo=async t=>ke(t),ke=async t=>{let e=Re(t);_.getInstance().set(e),await ot();let s=e.workers?.auth!==void 0?Ct(e.workers.auth):void 0;return[...s?[s]:[]]},$o=t=>N.getInstance().subscribe(t);export{j as InternetIdentityProvider,ft as NFIDProvider,$o as authSubscribe,bo as countAssets,Bs as countDocs,Oo as deleteAsset,Vs as deleteDoc,Ro as deleteManyAssets,Ks as deleteManyDocs,Yt as downloadUrl,ko as getAsset,kt as getDoc,Eo as getManyAssets,Fs as getManyDocs,ao as getSatelliteExtendedActor,Bo as initJuno,ke as initSatellite,vo as listAssets,qs as listDocs,Et as setDoc,Ms as setManyDocs,Pe as signIn,it as signOut,Ne as unsafeIdentity,wo as uploadBlob,So as uploadFile};
3
+ import{Principal as ct}from"@dfinity/principal";var c=t=>t==null,p=t=>!c(t),ge=class extends Error{},B=(t,e)=>{if(c(t))throw new ge(e)},Q="__bigint__",Z="__principal__",I="__uint8array__",he=(t,e)=>typeof e=="bigint"?{[Q]:`${e}`}:p(e)&&e instanceof ct?{[Z]:e.toText()}:p(e)&&e instanceof Uint8Array?{[I]:Array.from(e)}:e,Ae=(t,e)=>{let s=i=>e[i];return p(e)&&typeof e=="object"&&Q in e?BigInt(s(Q)):p(e)&&typeof e=="object"&&Z in e?ct.fromText(s(Z)):p(e)&&typeof e=="object"&&I in e?Uint8Array.from(s(I)):e},y=t=>p(t)?[t]:[],u=t=>t?.[0],lt=async t=>{let e=new Blob([JSON.stringify(t,he)],{type:"application/json; charset=utf-8"});return new Uint8Array(await e.arrayBuffer())},$=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(),Ae)},pt=()=>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:i})=>i!==s)}};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 s=super.subscribe(e);return e(this.authUser),s}reset(){this.authUser=null,this.populate(this.authUser)}};var D=({message:t,detail:e})=>{let s=new CustomEvent(t,{detail:e,bubbles:!0});document.dispatchEvent(s)};var dt=BigInt(144e11),ut=!1,mt={width:576,height:576},yt={width:505,height:705},ft="internetcomputer.org";var k="http://127.0.0.1:5987",gt="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 s=super.subscribe(e);return e(this.env),s}};var L=({width:t,height:e})=>{if(!pt()||c(window)||c(window.top))return;let{top:{innerWidth:s,innerHeight:i}}=window,o=i/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=${o}, left=${n}`};var j=class{#t;constructor({domain:e}){this.#t=e}get id(){return"internet_identity"}signInOptions({windowed:e}){let s=()=>{let i=_.getInstance().get()?.container;if(c(i)||i===!1)return`https://identity.${this.#t??ft}`;let o=_.getInstance().get(),n=p(o)&&p(o?.internetIdentityId)?o.internetIdentityId:gt,{host:r,protocol:a}=new URL(i===!0?k:i);return/apple/i.test(navigator?.vendor)?`${a}//${r}?canisterId=${n}`:`${a}//${n}.${r.replace("127.0.0.1","localhost")}`};return{...e!==!1&&{windowOpenerFeatures:L(mt)},identityProvider:s()}}},ht=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:L(yt)},identityProvider:`https://nfid.one/authenticate/?applicationName=${encodeURI(this.#t)}&applicationLogo=${encodeURI(this.#e)}`}}};import{Actor as _e}from"@dfinity/agent";import{HttpAgent as Te}from"@dfinity/agent";var E=class t{static instance;#t=void 0;constructor(){}static getInstance(){return c(t.instance)&&(t.instance=new t),t.instance}async getAgent({identity:e,...s}){let i=e.getPrincipal().toText();if(c(this.#t)||c(this.#t[i])){let o=await this.createAgent({identity:e,...s});return this.#t={...this.#t??{},[i]:o},o}return this.#t[i]}reset(){this.#t=null}async createAgent({identity:e,fetch:s,container:i}){let n=p(i)&&i!==!1?i===!0?k:i:"https://icp-api.io",r=p(i);return await Te.create({identity:e,shouldFetchRootKey:r,host:n,...s&&{fetch:s}})}};var C=class t{static instance;#t=void 0;constructor(){}static getInstance(){return c(t.instance)&&(t.instance=new t),t.instance}async getActor({satelliteId:e,identity:s,buildType:i,...o}){let n=`${i}#${s.getPrincipal().toText()}#${e};`;if(c(this.#t)||c(this.#t[n])){let r=await this.createActor({satelliteId:e,identity:s,...o});return this.#t={...this.#t??{},[n]:r},r}return this.#t[n]}reset(){this.#t=null}async createActor({idlFactory:e,satelliteId:s,...i}){let o=await E.getInstance().getAgent(i);return _e.createActor(e,{agent:o,canisterId:s})}};import{AuthClient as xe}from"@dfinity/auth-client";var H=()=>xe.create({idleOptions:{disableIdle:!0,disableDefaultIdleCallback:!0}});var At=async({data:t})=>{try{return await $(t)}catch(e){console.error("The data parsing has failed, mapping to undefined as a fallback.",e);return}};var tt=async t=>{let{data:e,version:s,description:i}=t;return{description:y(i),data:await lt(e),version:y(s)}},et=t=>{let{version:e}=t;return{version:y(e)}},V=async({doc:t,key:e})=>{let{owner:s,version:i,description:o,data:n,...r}=t;return{key:e,description:u(o),owner:s.toText(),data:await $(n),version:u(i),...r}};import{Principal as Pe}from"@dfinity/principal";var Tt=t=>{if(c(t))return y();switch(t.matcher){case"equal":return y({Equal:t.timestamp});case"greaterThan":return y({GreaterThan:t.timestamp});case"lessThan":return y({LessThan:t.timestamp});case"between":return y({Between:[t.timestamps.start,t.timestamps.end]});default:throw new Error("Invalid list matcher for timestamp",t)}},O=({matcher:t,paginate:e,order:s,owner:i})=>({matcher:c(t)?[]:[{key:y(t.key),description:y(t.description),created_at:Tt(t.createdAt),updated_at:Tt(t.updatedAt)}],paginate:y(c(e)?void 0:{start_after:y(e.startAfter),limit:y(c(e.limit)?void 0:BigInt(e.limit))}),order:y(c(s)?void 0:{desc:s.desc,field:s.field==="created_at"?{CreatedAt:null}:s.field==="updated_at"?{UpdatedAt:null}:{Keys:null}}),owner:y(c(i)?void 0:typeof i=="string"?Pe.fromText(i):i)});var _t=({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}),i=t.Record({field:s,desc:t.Bool}),o=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(o),description:t.Opt(t.Text),created_at:t.Opt(o)}),r=t.Record({start_after:t.Opt(t.Text),limit:t.Opt(t.Nat64)}),a=t.Record({order:t.Opt(i),owner:t.Opt(t.Principal),matcher:t.Opt(n),paginate:t.Opt(r)}),m=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)}),A=t.Record({version:t.Opt(t.Nat64)}),h=t.Variant({Db:t.Null,Storage:t.Null}),N=t.Record({version:t.Opt(t.Nat64)}),S=t.Record({cycles:t.Nat,destination_id:t.Principal}),P=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}),v=t.Record({modified:t.Nat64,sha256:t.Vec(t.Nat8),total_length:t.Nat}),g=t.Record({key:P,updated_at:t.Nat64,encodings:t.Vec(t.Tuple(t.Text,v)),headers:t.Vec(t.Tuple(t.Text,t.Text)),created_at:t.Nat64,version:t.Opt(t.Nat64)}),b=t.Record({derivation_origin:t.Opt(t.Text)}),U=t.Record({internet_identity:t.Opt(b)}),K=t.Record({stable:t.Opt(t.Nat64),heap:t.Opt(t.Nat64)}),F=t.Record({max_memory_size:t.Opt(K)}),It=t.Variant({Deny:t.Null,AllowAny:t.Null,SameOrigin:t.Null}),Dt=t.Variant({Deny:t.Null,Allow:t.Null}),Lt=t.Record({status_code:t.Nat16,location:t.Text}),G=t.Record({iframe:t.Opt(It),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(K),raw_access:t.Opt(Dt),redirects:t.Opt(t.Vec(t.Tuple(t.Text,Lt)))}),te=t.Record({db:t.Opt(F),authentication:t.Opt(U),storage:G}),M=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)}),Y=t.Variant({Heap:t.Null,Stable:t.Null}),q=t.Variant({Controllers:t.Null,Private:t.Null,Public:t.Null,Managed:t.Null}),rt=t.Record({max_tokens:t.Nat64,time_per_token_ns:t.Nat64}),J=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Y),updated_at:t.Nat64,max_size:t.Opt(t.Nat),read:q,created_at:t.Nat64,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(rt),write:q}),ee=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)}),X=t.Record({memory:Y,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}),se=t.Variant({Callback:t.Record({token:X,callback:t.Func([],[],["query"])})}),ie=t.Record({body:t.Vec(t.Nat8),headers:t.Vec(t.Tuple(t.Text,t.Text)),streaming_strategy:t.Opt(se),status_code:t.Nat16}),oe=t.Record({token:t.Opt(X),body:t.Vec(t.Nat8)}),ne=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}),re=t.Record({batch_id:t.Nat}),ae=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}),ce=t.Record({updated_at:t.Nat64,created_at:t.Nat64,version:t.Opt(t.Nat64),bn_id:t.Opt(t.Text)}),le=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,M)),items_length:t.Nat64}),pe=t.Record({stable:t.Nat64,heap:t.Nat64}),de=t.Record({metadata:t.Vec(t.Tuple(t.Text,t.Text)),scope:T,expires_at:t.Opt(t.Nat64)}),ue=t.Record({controller:de,controllers:t.Vec(t.Principal)}),at=t.Record({data:t.Vec(t.Nat8),description:t.Opt(t.Text),version:t.Opt(t.Nat64)}),me=t.Record({max_capacity:t.Opt(t.Nat32),memory:t.Opt(Y),max_size:t.Opt(t.Nat),read:q,version:t.Opt(t.Nat64),mutable_permissions:t.Opt(t.Bool),rate_config:t.Opt(rt),write:q}),ye=t.Record({content:t.Vec(t.Nat8),batch_id:t.Nat,order_id:t.Opt(t.Nat)}),fe=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([m],[t.Vec(t.Tuple(t.Principal,f))],[]),del_custom_domain:t.Func([t.Text],[],[]),del_doc:t.Func([t.Text,t.Text,A],[],[]),del_docs:t.Func([t.Text],[],[]),del_filtered_assets:t.Func([t.Text,a],[],[]),del_filtered_docs:t.Func([t.Text,a],[],[]),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,A))],[],[]),del_rule:t.Func([h,t.Text,N],[],[]),deposit_cycles:t.Func([S],[],[]),get_asset:t.Func([t.Text,t.Text],[t.Opt(g)],["query"]),get_auth_config:t.Func([],[t.Opt(U)],["query"]),get_config:t.Func([],[te],[]),get_db_config:t.Func([],[t.Opt(F)],["query"]),get_doc:t.Func([t.Text,t.Text],[t.Opt(M)],["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(M)))],["query"]),get_rule:t.Func([h,t.Text],[t.Opt(J)],["query"]),get_storage_config:t.Func([],[G],["query"]),http_request:t.Func([ee],[ie],["query"]),http_request_streaming_callback:t.Func([X],[oe],["query"]),init_asset_upload:t.Func([ne],[re],[]),list_assets:t.Func([t.Text,a],[ae],["query"]),list_controllers:t.Func([],[t.Vec(t.Tuple(t.Principal,f))],["query"]),list_custom_domains:t.Func([],[t.Vec(t.Tuple(t.Text,ce))],["query"]),list_docs:t.Func([t.Text,a],[le],["query"]),list_rules:t.Func([h],[t.Vec(t.Tuple(t.Text,J))],["query"]),memory_size:t.Func([],[pe],["query"]),set_auth_config:t.Func([U],[],[]),set_controllers:t.Func([ue],[t.Vec(t.Tuple(t.Principal,f))],[]),set_custom_domain:t.Func([t.Text,t.Opt(t.Text)],[],[]),set_db_config:t.Func([F],[],[]),set_doc:t.Func([t.Text,t.Text,at],[M],[]),set_many_docs:t.Func([t.Vec(t.Tuple(t.Text,t.Text,at))],[t.Vec(t.Tuple(t.Text,M))],[]),set_rule:t.Func([h,t.Text,me],[J],[]),set_storage_config:t.Func([G],[],[]),upload_asset_chunk:t.Func([ye],[fe],[]),version:t.Func([],[t.Text],["query"])})};var xt=({satelliteId:t,container:e})=>{let{satelliteId:s}=st({satelliteId:t}),{container:i}=it({container:e});if(p(i)&&i!==!1){let{host:o,protocol:n}=new URL(i===!0?k:i);return`${n}//${s??"unknown"}.${o.replace("127.0.0.1","localhost")}`}return`https://${s??"unknown"}.icp0.io`},st=({satelliteId:t})=>p(t)?{satelliteId:t}:_.getInstance().get()??{satelliteId:void 0},it=({container:t})=>p(t)?{container:t}:_.getInstance().get()??{container:void 0};var d=t=>wt({idlFactory:_t,buildType:"stock",...t}),Pt=({idlFactory:t,...e})=>wt({idlFactory:t,buildType:"extended",...e}),wt=async({satelliteId:t,container:e,...s})=>{let{satelliteId:i}=st({satelliteId:t});B(i,"No satellite ID defined. Did you initialize Juno?");let{container:o}=it({container:e});return await C.getInstance().getActor({satelliteId:i,container:o,...s})};var Nt=async({collection:t,key:e,satellite:s})=>{let{get_doc:i}=await d(s),o=u(await i(t,e));if(!c(o))return V({doc:o,key:e})},St=async({docs:t,satellite:e})=>{let{get_many_docs:s}=await d(e),i=t.map(({collection:r,key:a})=>[r,a]),o=await s(i),n=[];for(let[r,a]of o){let m=u(a);n.push(p(m)?await V({key:r,doc:m}):void 0)}return n},vt=async({collection:t,doc:e,satellite:s})=>{let{set_doc:i}=await d(s),{key:o}=e,n=await tt(e),r=await i(t,o,n);return await V({key:o,doc:r})},Ot=async({docs:t,satellite:e})=>{let{set_many_docs:s}=await d(e),i=[];for(let{collection:r,doc:a}of t){let{key:m}=a;i.push([r,m,await tt(a)])}let o=await s(i),n=[];for(let[r,a]of o)n.push(await V({key:r,doc:a}));return n},bt=async({collection:t,doc:e,satellite:s})=>{let{del_doc:i}=await d(s),{key:o}=e;return i(t,o,et(e))},Rt=async({docs:t,satellite:e})=>{let{del_many_docs:s}=await d(e),i=t.map(({collection:o,doc:n})=>[o,n.key,et(n)]);await s(i)},kt=async({collection:t,filter:e,satellite:s})=>{let{del_filtered_docs:i}=await d(s);return i(t,O(e))},Et=async({collection:t,filter:e,satellite:s})=>{let{list_docs:i}=await d(s),{items:o,items_page:n,items_length:r,matches_length:a,matches_pages:m}=await i(t,O(e)),T=[];for(let[f,A]of o){let{data:h,owner:N,description:S,version:P,...v}=A;T.push({key:f,description:u(S),owner:N.toText(),data:await At({data:h}),version:u(P),...v})}return{items:T,items_length:r,items_page:u(n),matches_length:a,matches_pages:u(m)}},Ct=async({collection:t,filter:e,satellite:s})=>{let{count_docs:i}=await d(s);return i(t,O(e))};import{AnonymousIdentity as we}from"@dfinity/agent";var l=t=>t!==void 0?t:z()??new we;var Ut=async({satellite:t,...e})=>{let s=l(t?.identity);return await Nt({...e,satellite:{...t,identity:s}})},Ks=async({satellite:t,...e})=>{let s=l(t?.identity);return await St({...e,satellite:{...t,identity:s}})},Ft=async({satellite:t,...e})=>{let s=l(t?.identity);return await vt({...e,satellite:{...t,identity:s}})},qs=async({satellite:t,...e})=>{let s=l(t?.identity);return await Ot({...e,satellite:{...t,identity:s}})},Bs=async({satellite:t,...e})=>{let s=l(t?.identity);return await bt({...e,satellite:{...t,identity:s}})},$s=async({satellite:t,...e})=>{let s=l(t?.identity);return await Rt({...e,satellite:{...t,identity:s}})},js=async({satellite:t,filter:e,...s})=>{let i=l(t?.identity);return await kt({...s,filter:e??{},satellite:{...t,identity:i}})},Hs=async({satellite:t,filter:e,...s})=>{let i=l(t?.identity);return await Et({...s,filter:e??{},satellite:{...t,identity:i}})},zs=async({satellite:t,filter:e,...s})=>{let i=l(t?.identity);return await Ct({...s,filter:e??{},satellite:{...t,identity:i}})};var Mt=async t=>{let e=z();if(c(e))throw new Error("No identity to initialize the user. Have you initialized Juno?");let s=e.getPrincipal().toText(),i=await Ut({collection:"#user",key:s});return c(i)?await Ne({userId:s,provider:t}):i},Ne=({userId:t,...e})=>Ft({collection:"#user",doc:{key:t,data:e}});var x,ot=async t=>{if(x=x??await H(),!(await x?.isAuthenticated()??!1))return;let s=await Mt(t);w.getInstance().set(s)},Se=t=>new Promise(async(e,s)=>{x=x??await H();let i=t?.provider??new j({});await x.login({onSuccess:async()=>{await ot(i.id),e()},onError:o=>s(o),maxTimeToLive:t?.maxTimeToLive??dt,allowPinAuthentication:t?.allowPin??ut,...t?.derivationOrigin!==void 0&&{derivationOrigin:t.derivationOrigin},...i.signInOptions({windowed:t?.windowed})})}),nt=async()=>{await x?.logout(),x=void 0,w.getInstance().reset(),C.getInstance().reset(),E.getInstance().reset()},z=()=>x?.getIdentity(),ve=async()=>(x??await H()).getIdentity();var Vt=t=>{let e=t===!0?"./workers/auth.worker.js":t,s=new Worker(e),i=async()=>{D({message:"junoSignOutAuthTimer"}),await nt()};return s.onmessage=async({data:o})=>{let{msg:n,data:r}=o;switch(n){case"junoSignOutAuthTimer":await i();return;case"junoDelegationRemainingTime":D({message:"junoDelegationRemainingTime",detail:r?.authRemainingTime});return}},w.getInstance().subscribe(o=>{if(c(o)){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()},qt=()=>{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()};var di=async({idlFactory:t,satellite:e})=>{let s=l(e?.identity);return await Pt({idlFactory:t,...e,identity:s})};import"@dfinity/principal";var Oe=t=>t==null,be=t=>!Oe(t),W=t=>be(t)?[t]:[],Re=()=>typeof window<"u",Bt=async({asset:{data:t,filename:e,collection:s,headers:i,token:o,fullPath:n,encoding:r,description:a},actor:m,init_asset_upload:T})=>{let{batch_id:f}=await T({collection:s,full_path:n,name:e,token:W(o),encoding_type:W(r),description:W(a)}),A=19e5,h=[],N=Re()?new Blob([await t.arrayBuffer()]):t,S=0n;for(let g=0;g<N.size;g+=A){let b=N.slice(g,g+A);h.push({batchId:f,chunk:b,actor:m,orderId:S}),S++}let P=[];for await(let g of ke({uploadChunks:h}))P=[...P,...g];let v=i.find(([g,b])=>g.toLowerCase()==="content-type")===void 0&&t.type!==void 0&&t.type!==""?[["Content-Type",t.type]]:void 0;await m.commit_asset_upload({batch_id:f,chunk_ids:P.map(({chunk_id:g})=>g),headers:[...i,...v||[]]})};async function*ke({uploadChunks:t,limit:e=12}){for(let s=0;s<t.length;s=s+e){let i=t.slice(s,s+e);yield await Promise.all(i.map(o=>Ee(o)))}}var Ee=async({batchId:t,chunk:e,actor:s,orderId:i})=>s.upload_asset_chunk({batch_id:t,content:new Uint8Array(await e.arrayBuffer()),order_id:W(i)});var $t=async({satellite:t,...e})=>{let s=await d(t);await Bt({actor:s,asset:e,init_asset_upload:async o=>await s.init_asset_upload(o)})},jt=async({collection:t,satellite:e,filter:s})=>{let{list_assets:i}=await d(e),{items:o,items_length:n,items_page:r,matches_length:a,matches_pages:m}=await i(t,O(s));return{items:o.map(([T,f])=>f),items_length:n,items_page:u(r),matches_length:a,matches_pages:u(m)}},Ht=async({collection:t,satellite:e,filter:s})=>{let{count_assets:i}=await d(e);return i(t,O(s))},zt=async({collection:t,fullPath:e,satellite:s})=>(await d(s)).del_asset(t,e),Wt=async({assets:t,satellite:e})=>{let{del_many_assets:s}=await d(e),i=t.map(({collection:o,fullPath:n})=>[o,n]);await s(i)},Gt=async({collection:t,satellite:e,filter:s})=>{let{del_filtered_assets:i}=await d(e);return i(t,O(s))},Yt=async({collection:t,fullPath:e,satellite:s})=>{let{get_asset:i}=await d(s);return u(await i(t,e))},Jt=async({assets:t,satellite:e})=>{let{get_many_assets:s}=await d(e),i=t.map(({collection:n,fullPath:r})=>[n,r]);return(await s(i)).map(([n,r])=>u(r))};var Xt=t=>btoa([...t].map(e=>String.fromCharCode(e)).join(""));var Oi=t=>Qt(t),bi=t=>Qt({filename:t.data.name,...t}),Qt=async({filename:t,data:e,collection:s,headers:i=[],fullPath:o,token:n,satellite:r,encoding:a,description:m})=>{let T=l(r?.identity),f=decodeURI(t),A=o??`/${s}/${f}`,h={...r,identity:T};return await $t({data:e,filename:f,collection:s,token:n,headers:i,fullPath:A,encoding:a,satellite:h,description:m}),{downloadUrl:Zt({satellite:h,assetKey:{fullPath:A,token:n}}),fullPath:A,name:f}},Ri=async({collection:t,satellite:e,filter:s})=>{let i={...e,identity:l(e?.identity)},{items:o,...n}=await jt({collection:t,satellite:i,filter:s??{}}),r=o.map(({key:{full_path:a,token:m,name:T,owner:f,description:A},headers:h,encodings:N,created_at:S,updated_at:P})=>{let v=u(m);return{fullPath:a,description:u(A),name:T,downloadUrl:Zt({satellite:i,assetKey:{fullPath:a,token:v}}),token:v,headers:h,encodings:N.reduce((g,[b,{modified:U,sha256:K,total_length:F}])=>({...g,[b]:{modified:U,sha256:Xt(K),total_length:F}}),{}),owner:f.toText(),created_at:S,updated_at:P}});return{items:r,assets:r,...n}},ki=async({collection:t,satellite:e,filter:s})=>{let i={...e,identity:l(e?.identity)};return await Ht({collection:t,satellite:i,filter:s??{}})},Ei=({collection:t,fullPath:e,satellite:s})=>zt({collection:t,fullPath:e,satellite:{...s,identity:l(s?.identity)}}),Ci=({assets:t,satellite:e})=>Wt({assets:t,satellite:{...e,identity:l(e?.identity)}}),Ui=async({collection:t,satellite:e,filter:s})=>{let i={...e,identity:l(e?.identity)};return await Gt({collection:t,satellite:i,filter:s??{}})},Fi=async({satellite:t,...e})=>{let s=l(t?.identity);return await Yt({...e,satellite:{...t,identity:s}})},Mi=async({satellite:t,...e})=>{let s=l(t?.identity);return await Jt({...e,satellite:{...t,identity:s}})},Zt=({assetKey:{fullPath:t,token:e},satellite:s})=>{let i={...s,identity:l(s?.identity)};return`${xt(i)}${t}${p(e)?`?token=${e}`:""}`};var Ce=t=>{let e=t?.satelliteId??Kt();B(e,"Satellite ID is not configured. Juno cannot be initialized.");let s=t?.container??qt();return{satelliteId:e,internetIdentityId:t?.internetIdentityId,workers:t?.workers,container:s}},zi=t=>Ue(t),Ue=async t=>{let e=Ce(t);_.getInstance().set(e),await ot();let s=e.workers?.auth!==void 0?Vt(e.workers.auth):void 0;return[...s?[s]:[]]},Wi=t=>w.getInstance().subscribe(t);export{j as InternetIdentityProvider,ht as NFIDProvider,Wi as authSubscribe,ki as countAssets,zs as countDocs,Ei as deleteAsset,Bs as deleteDoc,Ui as deleteFilteredAssets,js as deleteFilteredDocs,Ci as deleteManyAssets,$s as deleteManyDocs,Zt as downloadUrl,Fi as getAsset,Ut as getDoc,Mi as getManyAssets,Ks as getManyDocs,di as getSatelliteExtendedActor,zi as initJuno,Ue as initSatellite,Ri as listAssets,Hs as listDocs,Ft as setDoc,qs as setManyDocs,Se as signIn,nt as signOut,ve as unsafeIdentity,Oi as uploadBlob,bi as uploadFile};
4
4
  //# sourceMappingURL=index.mjs.map