@authup/client-web-kit 1.0.0-beta.13 → 1.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var coreKit = require('@authup/core-kit');
6
6
  var vue = require('vue');
7
7
  var coreHttpKit = require('@authup/core-http-kit');
8
+ var pinia = require('pinia');
8
9
  var kit = require('@authup/kit');
9
10
  var smob = require('smob');
10
11
  var listControls = require('@vuecs/list-controls');
@@ -57,644 +58,6 @@ function injectHTTPClient(app) {
57
58
  return instance;
58
59
  }
59
60
 
60
- var isVue2 = false;
61
- function set(target, key, val) {
62
- if (Array.isArray(target)) {
63
- target.length = Math.max(target.length, key);
64
- target.splice(key, 1, val);
65
- return val;
66
- }
67
- target[key] = val;
68
- return val;
69
- }
70
- function del(target, key) {
71
- if (Array.isArray(target)) {
72
- target.splice(key, 1);
73
- return;
74
- }
75
- delete target[key];
76
- }
77
-
78
- /**
79
- * setActivePinia must be called to handle SSR at the top of functions like
80
- * `fetch`, `setup`, `serverPrefetch` and others
81
- */ let activePinia;
82
- /**
83
- * Sets or unsets the active pinia. Used in SSR and internally when calling
84
- * actions and getters
85
- *
86
- * @param pinia - Pinia instance
87
- */ // @ts-expect-error: cannot constrain the type of the return
88
- const setActivePinia = (pinia)=>activePinia = pinia;
89
- const piniaSymbol = process.env.NODE_ENV !== 'production' ? Symbol('pinia') : /* istanbul ignore next */ Symbol();
90
- function isPlainObject(// eslint-disable-next-line @typescript-eslint/no-explicit-any
91
- o) {
92
- return o && typeof o === 'object' && Object.prototype.toString.call(o) === '[object Object]' && typeof o.toJSON !== 'function';
93
- }
94
- // type DeepReadonly<T> = { readonly [P in keyof T]: DeepReadonly<T[P]> }
95
- // TODO: can we change these to numbers?
96
- /**
97
- * Possible types for SubscriptionCallback
98
- */ var MutationType;
99
- (function(MutationType) {
100
- /**
101
- * Direct mutation of the state:
102
- *
103
- * - `store.name = 'new name'`
104
- * - `store.$state.name = 'new name'`
105
- * - `store.list.push('new item')`
106
- */ MutationType["direct"] = "direct";
107
- /**
108
- * Mutated the state with `$patch` and an object
109
- *
110
- * - `store.$patch({ name: 'newName' })`
111
- */ MutationType["patchObject"] = "patch object";
112
- /**
113
- * Mutated the state with `$patch` and a function
114
- *
115
- * - `store.$patch(state => state.name = 'newName')`
116
- */ MutationType["patchFunction"] = "patch function";
117
- // maybe reset? for $state = {} and $reset
118
- })(MutationType || (MutationType = {}));
119
- const IS_CLIENT = typeof window !== 'undefined';
120
- /**
121
- * Should we add the devtools plugins.
122
- * - only if dev mode or forced through the prod devtools flag
123
- * - not in test
124
- * - only if window exists (could change in the future)
125
- */ const USE_DEVTOOLS = (process.env.NODE_ENV !== 'production' || typeof __VUE_PROD_DEVTOOLS__ !== 'undefined' && __VUE_PROD_DEVTOOLS__) && !(process.env.NODE_ENV === 'test') && IS_CLIENT;
126
- /**
127
- * Mutates in place `newState` with `oldState` to _hot update_ it. It will
128
- * remove any key not existing in `newState` and recursively merge plain
129
- * objects.
130
- *
131
- * @param newState - new state object to be patched
132
- * @param oldState - old state that should be used to patch newState
133
- * @returns - newState
134
- */ function patchObject(newState, oldState) {
135
- // no need to go through symbols because they cannot be serialized anyway
136
- for(const key in oldState){
137
- const subPatch = oldState[key];
138
- // skip the whole sub tree
139
- if (!(key in newState)) {
140
- continue;
141
- }
142
- const targetValue = newState[key];
143
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && !vue.isRef(subPatch) && !vue.isReactive(subPatch)) {
144
- newState[key] = patchObject(targetValue, subPatch);
145
- } else {
146
- // objects are either a bit more complex (e.g. refs) or primitives, so we
147
- // just set the whole thing
148
- {
149
- newState[key] = subPatch;
150
- }
151
- }
152
- }
153
- return newState;
154
- }
155
- const noop$1 = ()=>{};
156
- function addSubscription(subscriptions, callback, detached, onCleanup = noop$1) {
157
- subscriptions.push(callback);
158
- const removeSubscription = ()=>{
159
- const idx = subscriptions.indexOf(callback);
160
- if (idx > -1) {
161
- subscriptions.splice(idx, 1);
162
- onCleanup();
163
- }
164
- };
165
- if (!detached && vue.getCurrentScope()) {
166
- vue.onScopeDispose(removeSubscription);
167
- }
168
- return removeSubscription;
169
- }
170
- function triggerSubscriptions(subscriptions, ...args) {
171
- subscriptions.slice().forEach((callback)=>{
172
- callback(...args);
173
- });
174
- }
175
- const fallbackRunWithContext = (fn)=>fn();
176
- function mergeReactiveObjects(target, patchToApply) {
177
- // Handle Map instances
178
- if (target instanceof Map && patchToApply instanceof Map) {
179
- patchToApply.forEach((value, key)=>target.set(key, value));
180
- }
181
- // Handle Set instances
182
- if (target instanceof Set && patchToApply instanceof Set) {
183
- patchToApply.forEach(target.add, target);
184
- }
185
- // no need to go through symbols because they cannot be serialized anyway
186
- for(const key in patchToApply){
187
- if (!patchToApply.hasOwnProperty(key)) continue;
188
- const subPatch = patchToApply[key];
189
- const targetValue = target[key];
190
- if (isPlainObject(targetValue) && isPlainObject(subPatch) && target.hasOwnProperty(key) && !vue.isRef(subPatch) && !vue.isReactive(subPatch)) {
191
- // NOTE: here I wanted to warn about inconsistent types but it's not possible because in setup stores one might
192
- // start the value of a property as a certain type e.g. a Map, and then for some reason, during SSR, change that
193
- // to `undefined`. When trying to hydrate, we want to override the Map with `undefined`.
194
- target[key] = mergeReactiveObjects(targetValue, subPatch);
195
- } else {
196
- // @ts-expect-error: subPatch is a valid value
197
- target[key] = subPatch;
198
- }
199
- }
200
- return target;
201
- }
202
- const skipHydrateSymbol = process.env.NODE_ENV !== 'production' ? Symbol('pinia:skipHydration') : /* istanbul ignore next */ Symbol();
203
- /**
204
- * Returns whether a value should be hydrated
205
- *
206
- * @param obj - target variable
207
- * @returns true if `obj` should be hydrated
208
- */ function shouldHydrate(obj) {
209
- return !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol);
210
- }
211
- const { assign } = Object;
212
- function isComputed(o) {
213
- return !!(vue.isRef(o) && o.effect);
214
- }
215
- function createOptionsStore(id, options, pinia, hot) {
216
- const { state, actions, getters } = options;
217
- const initialState = pinia.state.value[id];
218
- let store;
219
- function setup() {
220
- if (!initialState && (!(process.env.NODE_ENV !== 'production') || !hot)) {
221
- /* istanbul ignore if */ {
222
- pinia.state.value[id] = state ? state() : {};
223
- }
224
- }
225
- // avoid creating a state in pinia.state.value
226
- const localState = process.env.NODE_ENV !== 'production' && hot ? vue.toRefs(vue.ref(state ? state() : {}).value) : vue.toRefs(pinia.state.value[id]);
227
- return assign(localState, actions, Object.keys(getters || {}).reduce((computedGetters, name)=>{
228
- if (process.env.NODE_ENV !== 'production' && name in localState) {
229
- console.warn(`[🍍]: A getter cannot have the same name as another state property. Rename one of them. Found with "${name}" in store "${id}".`);
230
- }
231
- computedGetters[name] = vue.markRaw(vue.computed(()=>{
232
- setActivePinia(pinia);
233
- // it was created just before
234
- const store = pinia._s.get(id);
235
- // @ts-expect-error
236
- // return getters![name].call(context, context)
237
- // TODO: avoid reading the getter while assigning with a global variable
238
- return getters[name].call(store, store);
239
- }));
240
- return computedGetters;
241
- }, {}));
242
- }
243
- store = createSetupStore(id, setup, options, pinia, hot, true);
244
- return store;
245
- }
246
- function createSetupStore($id, setup, options = {}, pinia, hot, isOptionsStore) {
247
- let scope;
248
- const optionsForPlugin = assign({
249
- actions: {}
250
- }, options);
251
- /* istanbul ignore if */ if (process.env.NODE_ENV !== 'production' && !pinia._e.active) {
252
- throw new Error('Pinia destroyed');
253
- }
254
- // watcher options for $subscribe
255
- const $subscribeOptions = {
256
- deep: true
257
- };
258
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production' && !isVue2) {
259
- $subscribeOptions.onTrigger = (event)=>{
260
- /* istanbul ignore else */ if (isListening) {
261
- debuggerEvents = event;
262
- // avoid triggering this while the store is being built and the state is being set in pinia
263
- } else if (isListening == false && !store._hotUpdating) {
264
- // let patch send all the events together later
265
- /* istanbul ignore else */ if (Array.isArray(debuggerEvents)) {
266
- debuggerEvents.push(event);
267
- } else {
268
- console.error('🍍 debuggerEvents should be an array. This is most likely an internal Pinia bug.');
269
- }
270
- }
271
- };
272
- }
273
- // internal state
274
- let isListening; // set to true at the end
275
- let isSyncListening; // set to true at the end
276
- let subscriptions = [];
277
- let actionSubscriptions = [];
278
- let debuggerEvents;
279
- const initialState = pinia.state.value[$id];
280
- // avoid setting the state for option stores if it is set
281
- // by the setup
282
- if (!isOptionsStore && !initialState && (!(process.env.NODE_ENV !== 'production') || !hot)) {
283
- /* istanbul ignore if */ {
284
- pinia.state.value[$id] = {};
285
- }
286
- }
287
- const hotState = vue.ref({});
288
- // avoid triggering too many listeners
289
- // https://github.com/vuejs/pinia/issues/1129
290
- let activeListener;
291
- function $patch(partialStateOrMutator) {
292
- let subscriptionMutation;
293
- isListening = isSyncListening = false;
294
- // reset the debugger events since patches are sync
295
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
296
- debuggerEvents = [];
297
- }
298
- if (typeof partialStateOrMutator === 'function') {
299
- partialStateOrMutator(pinia.state.value[$id]);
300
- subscriptionMutation = {
301
- type: MutationType.patchFunction,
302
- storeId: $id,
303
- events: debuggerEvents
304
- };
305
- } else {
306
- mergeReactiveObjects(pinia.state.value[$id], partialStateOrMutator);
307
- subscriptionMutation = {
308
- type: MutationType.patchObject,
309
- payload: partialStateOrMutator,
310
- storeId: $id,
311
- events: debuggerEvents
312
- };
313
- }
314
- const myListenerId = activeListener = Symbol();
315
- vue.nextTick().then(()=>{
316
- if (activeListener === myListenerId) {
317
- isListening = true;
318
- }
319
- });
320
- isSyncListening = true;
321
- // because we paused the watcher, we need to manually call the subscriptions
322
- triggerSubscriptions(subscriptions, subscriptionMutation, pinia.state.value[$id]);
323
- }
324
- const $reset = isOptionsStore ? function $reset() {
325
- const { state } = options;
326
- const newState = state ? state() : {};
327
- // we use a patch to group all changes into one single subscription
328
- this.$patch(($state)=>{
329
- assign($state, newState);
330
- });
331
- } : /* istanbul ignore next */ process.env.NODE_ENV !== 'production' ? ()=>{
332
- throw new Error(`🍍: Store "${$id}" is built using the setup syntax and does not implement $reset().`);
333
- } : noop$1;
334
- function $dispose() {
335
- scope.stop();
336
- subscriptions = [];
337
- actionSubscriptions = [];
338
- pinia._s.delete($id);
339
- }
340
- /**
341
- * Wraps an action to handle subscriptions.
342
- *
343
- * @param name - name of the action
344
- * @param action - action to wrap
345
- * @returns a wrapped action to handle subscriptions
346
- */ function wrapAction(name, action) {
347
- return function() {
348
- setActivePinia(pinia);
349
- const args = Array.from(arguments);
350
- const afterCallbackList = [];
351
- const onErrorCallbackList = [];
352
- function after(callback) {
353
- afterCallbackList.push(callback);
354
- }
355
- function onError(callback) {
356
- onErrorCallbackList.push(callback);
357
- }
358
- // @ts-expect-error
359
- triggerSubscriptions(actionSubscriptions, {
360
- args,
361
- name,
362
- store,
363
- after,
364
- onError
365
- });
366
- let ret;
367
- try {
368
- ret = action.apply(this && this.$id === $id ? this : store, args);
369
- // handle sync errors
370
- } catch (error) {
371
- triggerSubscriptions(onErrorCallbackList, error);
372
- throw error;
373
- }
374
- if (ret instanceof Promise) {
375
- return ret.then((value)=>{
376
- triggerSubscriptions(afterCallbackList, value);
377
- return value;
378
- }).catch((error)=>{
379
- triggerSubscriptions(onErrorCallbackList, error);
380
- return Promise.reject(error);
381
- });
382
- }
383
- // trigger after callbacks
384
- triggerSubscriptions(afterCallbackList, ret);
385
- return ret;
386
- };
387
- }
388
- const _hmrPayload = /*#__PURE__*/ vue.markRaw({
389
- actions: {},
390
- getters: {},
391
- state: [],
392
- hotState
393
- });
394
- const partialStore = {
395
- _p: pinia,
396
- // _s: scope,
397
- $id,
398
- $onAction: addSubscription.bind(null, actionSubscriptions),
399
- $patch,
400
- $reset,
401
- $subscribe (callback, options = {}) {
402
- const removeSubscription = addSubscription(subscriptions, callback, options.detached, ()=>stopWatcher());
403
- const stopWatcher = scope.run(()=>vue.watch(()=>pinia.state.value[$id], (state)=>{
404
- if (options.flush === 'sync' ? isSyncListening : isListening) {
405
- callback({
406
- storeId: $id,
407
- type: MutationType.direct,
408
- events: debuggerEvents
409
- }, state);
410
- }
411
- }, assign({}, $subscribeOptions, options)));
412
- return removeSubscription;
413
- },
414
- $dispose
415
- };
416
- const store = vue.reactive(process.env.NODE_ENV !== 'production' || USE_DEVTOOLS ? assign({
417
- _hmrPayload,
418
- _customProperties: vue.markRaw(new Set())
419
- }, partialStore) : partialStore);
420
- // store the partial store now so the setup of stores can instantiate each other before they are finished without
421
- // creating infinite loops.
422
- pinia._s.set($id, store);
423
- const runWithContext = pinia._a && pinia._a.runWithContext || fallbackRunWithContext;
424
- // TODO: idea create skipSerialize that marks properties as non serializable and they are skipped
425
- const setupStore = runWithContext(()=>pinia._e.run(()=>(scope = vue.effectScope()).run(setup)));
426
- // overwrite existing actions to support $onAction
427
- for(const key in setupStore){
428
- const prop = setupStore[key];
429
- if (vue.isRef(prop) && !isComputed(prop) || vue.isReactive(prop)) {
430
- // mark it as a piece of state to be serialized
431
- if (process.env.NODE_ENV !== 'production' && hot) {
432
- set(hotState.value, key, vue.toRef(setupStore, key));
433
- // createOptionStore directly sets the state in pinia.state.value so we
434
- // can just skip that
435
- } else if (!isOptionsStore) {
436
- // in setup stores we must hydrate the state and sync pinia state tree with the refs the user just created
437
- if (initialState && shouldHydrate(prop)) {
438
- if (vue.isRef(prop)) {
439
- prop.value = initialState[key];
440
- } else {
441
- // probably a reactive object, lets recursively assign
442
- // @ts-expect-error: prop is unknown
443
- mergeReactiveObjects(prop, initialState[key]);
444
- }
445
- }
446
- // transfer the ref to the pinia state to keep everything in sync
447
- /* istanbul ignore if */ {
448
- pinia.state.value[$id][key] = prop;
449
- }
450
- }
451
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
452
- _hmrPayload.state.push(key);
453
- }
454
- // action
455
- } else if (typeof prop === 'function') {
456
- // @ts-expect-error: we are overriding the function we avoid wrapping if
457
- const actionValue = process.env.NODE_ENV !== 'production' && hot ? prop : wrapAction(key, prop);
458
- // this a hot module replacement store because the hotUpdate method needs
459
- // to do it with the right context
460
- /* istanbul ignore if */ {
461
- // @ts-expect-error
462
- setupStore[key] = actionValue;
463
- }
464
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
465
- _hmrPayload.actions[key] = prop;
466
- }
467
- // list actions so they can be used in plugins
468
- // @ts-expect-error
469
- optionsForPlugin.actions[key] = prop;
470
- } else if (process.env.NODE_ENV !== 'production') {
471
- // add getters for devtools
472
- if (isComputed(prop)) {
473
- _hmrPayload.getters[key] = isOptionsStore ? options.getters[key] : prop;
474
- if (IS_CLIENT) {
475
- const getters = setupStore._getters || // @ts-expect-error: same
476
- (setupStore._getters = vue.markRaw([]));
477
- getters.push(key);
478
- }
479
- }
480
- }
481
- }
482
- // add the state, getters, and action properties
483
- /* istanbul ignore if */ {
484
- assign(store, setupStore);
485
- // allows retrieving reactive objects with `storeToRefs()`. Must be called after assigning to the reactive object.
486
- // Make `storeToRefs()` work with `reactive()` #799
487
- assign(vue.toRaw(store), setupStore);
488
- }
489
- // use this instead of a computed with setter to be able to create it anywhere
490
- // without linking the computed lifespan to wherever the store is first
491
- // created.
492
- Object.defineProperty(store, '$state', {
493
- get: ()=>process.env.NODE_ENV !== 'production' && hot ? hotState.value : pinia.state.value[$id],
494
- set: (state)=>{
495
- /* istanbul ignore if */ if (process.env.NODE_ENV !== 'production' && hot) {
496
- throw new Error('cannot set hotState');
497
- }
498
- $patch(($state)=>{
499
- assign($state, state);
500
- });
501
- }
502
- });
503
- // add the hotUpdate before plugins to allow them to override it
504
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
505
- store._hotUpdate = vue.markRaw((newStore)=>{
506
- store._hotUpdating = true;
507
- newStore._hmrPayload.state.forEach((stateKey)=>{
508
- if (stateKey in store.$state) {
509
- const newStateTarget = newStore.$state[stateKey];
510
- const oldStateSource = store.$state[stateKey];
511
- if (typeof newStateTarget === 'object' && isPlainObject(newStateTarget) && isPlainObject(oldStateSource)) {
512
- patchObject(newStateTarget, oldStateSource);
513
- } else {
514
- // transfer the ref
515
- newStore.$state[stateKey] = oldStateSource;
516
- }
517
- }
518
- // patch direct access properties to allow store.stateProperty to work as
519
- // store.$state.stateProperty
520
- set(store, stateKey, vue.toRef(newStore.$state, stateKey));
521
- });
522
- // remove deleted state properties
523
- Object.keys(store.$state).forEach((stateKey)=>{
524
- if (!(stateKey in newStore.$state)) {
525
- del(store, stateKey);
526
- }
527
- });
528
- // avoid devtools logging this as a mutation
529
- isListening = false;
530
- isSyncListening = false;
531
- pinia.state.value[$id] = vue.toRef(newStore._hmrPayload, 'hotState');
532
- isSyncListening = true;
533
- vue.nextTick().then(()=>{
534
- isListening = true;
535
- });
536
- for(const actionName in newStore._hmrPayload.actions){
537
- const action = newStore[actionName];
538
- set(store, actionName, wrapAction(actionName, action));
539
- }
540
- // TODO: does this work in both setup and option store?
541
- for(const getterName in newStore._hmrPayload.getters){
542
- const getter = newStore._hmrPayload.getters[getterName];
543
- const getterValue = isOptionsStore ? vue.computed(()=>{
544
- setActivePinia(pinia);
545
- return getter.call(store, store);
546
- }) : getter;
547
- set(store, getterName, getterValue);
548
- }
549
- // remove deleted getters
550
- Object.keys(store._hmrPayload.getters).forEach((key)=>{
551
- if (!(key in newStore._hmrPayload.getters)) {
552
- del(store, key);
553
- }
554
- });
555
- // remove old actions
556
- Object.keys(store._hmrPayload.actions).forEach((key)=>{
557
- if (!(key in newStore._hmrPayload.actions)) {
558
- del(store, key);
559
- }
560
- });
561
- // update the values used in devtools and to allow deleting new properties later on
562
- store._hmrPayload = newStore._hmrPayload;
563
- store._getters = newStore._getters;
564
- store._hotUpdating = false;
565
- });
566
- }
567
- if (USE_DEVTOOLS) {
568
- const nonEnumerable = {
569
- writable: true,
570
- configurable: true,
571
- // avoid warning on devtools trying to display this property
572
- enumerable: false
573
- };
574
- [
575
- '_p',
576
- '_hmrPayload',
577
- '_getters',
578
- '_customProperties'
579
- ].forEach((p)=>{
580
- Object.defineProperty(store, p, assign({
581
- value: store[p]
582
- }, nonEnumerable));
583
- });
584
- }
585
- // apply all plugins
586
- pinia._p.forEach((extender)=>{
587
- /* istanbul ignore else */ if (USE_DEVTOOLS) {
588
- const extensions = scope.run(()=>extender({
589
- store,
590
- app: pinia._a,
591
- pinia,
592
- options: optionsForPlugin
593
- }));
594
- Object.keys(extensions || {}).forEach((key)=>store._customProperties.add(key));
595
- assign(store, extensions);
596
- } else {
597
- assign(store, scope.run(()=>extender({
598
- store,
599
- app: pinia._a,
600
- pinia,
601
- options: optionsForPlugin
602
- })));
603
- }
604
- });
605
- if (process.env.NODE_ENV !== 'production' && store.$state && typeof store.$state === 'object' && typeof store.$state.constructor === 'function' && !store.$state.constructor.toString().includes('[native code]')) {
606
- console.warn(`[🍍]: The "state" must be a plain object. It cannot be\n` + `\tstate: () => new MyClass()\n` + `Found in store "${store.$id}".`);
607
- }
608
- // only apply hydrate to option stores with an initial state in pinia
609
- if (initialState && isOptionsStore && options.hydrate) {
610
- options.hydrate(store.$state, initialState);
611
- }
612
- isListening = true;
613
- isSyncListening = true;
614
- return store;
615
- }
616
- function defineStore(// TODO: add proper types from above
617
- idOrOptions, setup, setupOptions) {
618
- let id;
619
- let options;
620
- const isSetupStore = typeof setup === 'function';
621
- {
622
- id = idOrOptions;
623
- // the option store setup will contain the actual options in this case
624
- options = isSetupStore ? setupOptions : setup;
625
- }
626
- function useStore(pinia, hot) {
627
- const hasContext = vue.hasInjectionContext();
628
- pinia = // in test mode, ignore the argument provided as we can always retrieve a
629
- // pinia instance with getActivePinia()
630
- (process.env.NODE_ENV === 'test' && activePinia && activePinia._testing ? null : pinia) || (hasContext ? vue.inject(piniaSymbol, null) : null);
631
- if (pinia) setActivePinia(pinia);
632
- if (process.env.NODE_ENV !== 'production' && !activePinia) {
633
- throw new Error(`[🍍]: "getActivePinia()" was called but there was no active Pinia. Are you trying to use a store before calling "app.use(pinia)"?\n` + `See https://pinia.vuejs.org/core-concepts/outside-component-usage.html for help.\n` + `This will fail in production.`);
634
- }
635
- pinia = activePinia;
636
- if (!pinia._s.has(id)) {
637
- // creating the store registers it in `pinia._s`
638
- if (isSetupStore) {
639
- createSetupStore(id, setup, options, pinia);
640
- } else {
641
- createOptionsStore(id, options, pinia);
642
- }
643
- /* istanbul ignore else */ if (process.env.NODE_ENV !== 'production') {
644
- // @ts-expect-error: not the right inferred type
645
- useStore._pinia = pinia;
646
- }
647
- }
648
- const store = pinia._s.get(id);
649
- if (process.env.NODE_ENV !== 'production' && hot) {
650
- const hotId = '__hot:' + id;
651
- const newStore = isSetupStore ? createSetupStore(hotId, setup, options, pinia, true) : createOptionsStore(hotId, assign({}, options), pinia, true);
652
- hot._hotUpdate(newStore);
653
- // cleanup the state properties and the store from the cache
654
- delete pinia.state.value[hotId];
655
- pinia._s.delete(hotId);
656
- }
657
- if (process.env.NODE_ENV !== 'production' && IS_CLIENT) {
658
- const currentInstance = vue.getCurrentInstance();
659
- // save stores in instances to access them devtools
660
- if (currentInstance && currentInstance.proxy && // avoid adding stores that are just built for hot module replacement
661
- !hot) {
662
- const vm = currentInstance.proxy;
663
- const cache = '_pStores' in vm ? vm._pStores : vm._pStores = {};
664
- cache[id] = store;
665
- }
666
- }
667
- // StoreGeneric cannot be casted towards Store
668
- return store;
669
- }
670
- useStore.$id = id;
671
- return useStore;
672
- }
673
- /**
674
- * Creates an object of references with all the state, getters, and plugin-added
675
- * state properties of the store. Similar to `toRefs()` but specifically
676
- * designed for Pinia stores so methods and non reactive properties are
677
- * completely ignored.
678
- *
679
- * @param store - store to extract the refs from
680
- */ function storeToRefs$1(store) {
681
- // See https://github.com/vuejs/pinia/issues/852
682
- // It's easier to just use toRefs() even if it includes more stuff
683
- {
684
- store = vue.toRaw(store);
685
- const refs = {};
686
- for(const key in store){
687
- const value = store[key];
688
- if (vue.isRef(value) || vue.isReactive(value)) {
689
- // @ts-expect-error: the key is state or getter
690
- refs[key] = // ---
691
- vue.toRef(store, key);
692
- }
693
- }
694
- return refs;
695
- }
696
- }
697
-
698
61
  /*
699
62
  * Copyright (c) 2024.
700
63
  * Author Peter Placzek (tada5hi)
@@ -989,10 +352,10 @@ function installStore(app, options = {}) {
989
352
  if (hasStore(app)) {
990
353
  return;
991
354
  }
992
- const storeCreator = defineStore(STORE_ID, ()=>createStore({
355
+ const storeCreator = pinia.defineStore(STORE_ID, ()=>createStore({
993
356
  baseURL: options.baseURL
994
357
  }));
995
- const store = storeCreator();
358
+ const store = storeCreator(options.pinia);
996
359
  const cookies = useCookies();
997
360
  let cookieGet;
998
361
  if (options.cookieGet) {
@@ -1123,8 +486,8 @@ function installHTTPClient(app, options = {}) {
1123
486
  baseURL: options.baseURL
1124
487
  });
1125
488
  const storeCreator = injectStore(app);
1126
- const store = storeCreator();
1127
- const { refreshToken } = storeToRefs$1(store);
489
+ const store = storeCreator(options.pinia);
490
+ const { refreshToken } = pinia.storeToRefs(store);
1128
491
  const tokenHook = new coreHttpKit.ClientResponseErrorTokenHook(client, {
1129
492
  baseURL: options.baseURL,
1130
493
  tokenCreator: ()=>{
@@ -2644,7 +2007,7 @@ function useAbilityCheck(name) {
2644
2007
 
2645
2008
  function useRealmResourceWritableCheck(realmId) {
2646
2009
  const store = useStore();
2647
- const { realm } = storeToRefs$1(store);
2010
+ const { realm } = pinia.storeToRefs(store);
2648
2011
  return vue.computed(()=>{
2649
2012
  const realmIdRaw = vue.unref(realmId);
2650
2013
  return coreKit.isRealmResourceWritable(realm.value, realmIdRaw);
@@ -7336,10 +6699,12 @@ function install(app1, options) {
7336
6699
  baseURL: options.baseURL,
7337
6700
  cookieSet: options.cookieSet,
7338
6701
  cookieGet: options.cookieGet,
7339
- cookieUnset: options.cookieUnset
6702
+ cookieUnset: options.cookieUnset,
6703
+ pinia: options.pinia
7340
6704
  });
7341
6705
  installHTTPClient(app1, {
7342
- baseURL: options.baseURL
6706
+ baseURL: options.baseURL,
6707
+ pinia: options.pinia
7343
6708
  });
7344
6709
  installTranslator(app1, {
7345
6710
  locale: options.translatorLocale