svelte-websocket-store 1.1.34 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,23 +1,12 @@
1
- Copyright (c) 2019-2023 by arlac77
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
-
7
- * Redistributions of source code must retain the above copyright notice, this
8
- list of conditions and the following disclaimer.
9
-
10
- * Redistributions in binary form must reproduce the above copyright notice,
11
- this list of conditions and the following disclaimer in the documentation
12
- and/or other materials provided with the distribution.
13
-
14
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ Copyright (C) 2019-2025 by arlac77
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted.
5
+
6
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
7
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
8
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
9
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
10
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
11
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
12
+ PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- [![Svelte v3](https://img.shields.io/badge/svelte-v3-orange.svg)](https://svelte.dev)
1
+ [![Svelte v5](https://img.shields.io/badge/svelte-v5-orange.svg)](https://svelte.dev)
2
2
  [![npm](https://img.shields.io/npm/v/svelte-websocket-store.svg)](https://www.npmjs.com/package/svelte-websocket-store)
3
- [![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
3
+ [![License](https://img.shields.io/badge/License-0BSD-blue.svg)](https://spdx.org/licenses/0BSD.html)
4
4
  [![bundlejs](https://deno.bundlejs.com/?q=svelte-websocket-store\&badge=detailed)](https://bundlejs.com/?q=svelte-websocket-store)
5
5
  [![downloads](http://img.shields.io/npm/dm/svelte-websocket-store.svg?style=flat-square)](https://npmjs.org/package/svelte-websocket-store)
6
6
  [![GitHub Issues](https://img.shields.io/github/issues/arlac77/svelte-websocket-store.svg?style=flat-square)](https://github.com/arlac77/svelte-websocket-store/issues)
@@ -8,8 +8,7 @@
8
8
  [![Styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
9
9
  [![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
10
10
  [![Known Vulnerabilities](https://snyk.io/test/github/arlac77/svelte-websocket-store/badge.svg)](https://snyk.io/test/github/arlac77/svelte-websocket-store)
11
- [![Coverage Status](https://coveralls.io/repos/arlac77/svelte-websocket-store/badge.svg)](https://coveralls.io/github/arlac77/svelte-websocket-store)
12
- [![Tested with TestCafe](https://img.shields.io/badge/tested%20with-TestCafe-2fa4cf.svg)](https://github.com/DevExpress/testcafe)
11
+ [![Tested with playwright](https://img.shields.io/badge/tested%20with-playwright-2fa4cf.svg)](https://playwright.dev)
13
12
 
14
13
  # svelte-websocket-store
15
14
 
@@ -36,8 +35,448 @@ let response = $myStore;
36
35
 
37
36
  ### Table of Contents
38
37
 
39
- * [websocketStore](#websocketstore)
38
+ * [active](#active)
40
39
  * [Parameters](#parameters)
40
+ * [Key](#key)
41
+ * [Properties](#properties)
42
+ * [BaseRouter](#baserouter)
43
+ * [Parameters](#parameters-1)
44
+ * [Properties](#properties-1)
45
+ * [component](#component)
46
+ * [value](#value)
47
+ * [path](#path)
48
+ * [path](#path-1)
49
+ * [Parameters](#parameters-2)
50
+ * [replace](#replace)
51
+ * [Parameters](#parameters-3)
52
+ * [push](#push)
53
+ * [Parameters](#parameters-4)
54
+ * [finalizePush](#finalizepush)
55
+ * [Parameters](#parameters-5)
56
+ * [continue](#continue)
57
+ * [Parameters](#parameters-6)
58
+ * [abort](#abort)
59
+ * [Parameters](#parameters-7)
60
+ * [subscribe](#subscribe)
61
+ * [Parameters](#parameters-8)
62
+ * [updateActive](#updateactive)
63
+ * [Parameters](#parameters-9)
64
+ * [addRoute](#addroute)
65
+ * [Parameters](#parameters-10)
66
+ * [routeFor](#routefor)
67
+ * [Parameters](#parameters-11)
68
+ * [pathFor](#pathfor)
69
+ * [Parameters](#parameters-12)
70
+ * [BaseTransition](#basetransition)
71
+ * [searchParams](#searchparams)
72
+ * [searchParams](#searchparams-1)
73
+ * [Parameters](#parameters-13)
74
+ * [nest](#nest)
75
+ * [Parameters](#parameters-14)
76
+ * [continue](#continue-1)
77
+ * [abort](#abort-1)
78
+ * [Parameters](#parameters-15)
79
+ * [DetailRoute](#detailroute)
80
+ * [Properties](#properties-2)
81
+ * [master](#master)
82
+ * [first](#first)
83
+ * [last](#last)
84
+ * [previous](#previous)
85
+ * [next](#next)
86
+ * [Entitlement](#entitlement)
87
+ * [Parameters](#parameters-16)
88
+ * [Guard](#guard)
89
+ * [enter](#enter)
90
+ * [Parameters](#parameters-17)
91
+ * [leave](#leave)
92
+ * [Parameters](#parameters-18)
93
+ * [redirectGuard](#redirectguard)
94
+ * [Parameters](#parameters-19)
95
+ * [sequenceGuard](#sequenceguard)
96
+ * [Parameters](#parameters-20)
97
+ * [parallelGuard](#parallelguard)
98
+ * [Parameters](#parameters-21)
99
+ * [websocketStore](#websocketstore)
100
+ * [Parameters](#parameters-22)
101
+ * [login](#login)
102
+ * [Parameters](#parameters-23)
103
+ * [handleFailedResponse](#handlefailedresponse)
104
+ * [Parameters](#parameters-24)
105
+ * [MasterRoute](#masterroute)
106
+ * [Parameters](#parameters-25)
107
+ * [Properties](#properties-3)
108
+ * [nullGuard](#nullguard)
109
+ * [RootRoute](#rootroute)
110
+ * [hasParams](#hasparams)
111
+ * [path](#path-2)
112
+ * [propertyMapping](#propertymapping)
113
+ * [guard](#guard-1)
114
+ * [SkeletonRoute](#skeletonroute)
115
+ * [Parameters](#parameters-26)
116
+ * [Properties](#properties-4)
117
+ * [enter](#enter-1)
118
+ * [Parameters](#parameters-27)
119
+ * [leave](#leave-1)
120
+ * [Parameters](#parameters-28)
121
+ * [isAcceptable](#isacceptable)
122
+ * [Parameters](#parameters-29)
123
+ * [propertiesFor](#propertiesfor)
124
+ * [Parameters](#parameters-30)
125
+ * [commonAncestor](#commonancestor)
126
+ * [Parameters](#parameters-31)
127
+ * [valueFor](#valuefor)
128
+ * [Parameters](#parameters-32)
129
+ * [value](#value-1)
130
+ * [propertyMapping](#propertymapping-1)
131
+ * [objectInstance](#objectinstance)
132
+ * [ValueStoreRoute](#valuestoreroute)
133
+ * [SessionData](#sessiondata)
134
+ * [Properties](#properties-5)
135
+ * [msecsRequiredForRefresh](#msecsrequiredforrefresh)
136
+ * [supportedTokenTypes](#supportedtokentypes)
137
+ * [Session](#session)
138
+ * [Parameters](#parameters-33)
139
+ * [Properties](#properties-6)
140
+ * [update](#update)
141
+ * [Parameters](#parameters-34)
142
+ * [refresh](#refresh)
143
+ * [authorizationHeader](#authorizationheader)
144
+ * [isValid](#isvalid)
145
+ * [invalidate](#invalidate)
146
+ * [hasEntitlement](#hasentitlement)
147
+ * [Parameters](#parameters-35)
148
+ * [subscribe](#subscribe-1)
149
+ * [Parameters](#parameters-36)
150
+ * [decode](#decode)
151
+ * [Parameters](#parameters-37)
152
+ * [Transition](#transition)
153
+ * [Parameters](#parameters-38)
154
+ * [Properties](#properties-7)
155
+ * [start](#start)
156
+ * [end](#end)
157
+ * [redirect](#redirect)
158
+ * [Parameters](#parameters-39)
159
+ * [abort](#abort-2)
160
+ * [Parameters](#parameters-40)
161
+ * [findClosestAttribute](#findclosestattribute)
162
+ * [Parameters](#parameters-41)
163
+ * [dispatchNavigationEvent](#dispatchnavigationevent)
164
+ * [Parameters](#parameters-42)
165
+ * [nameValueStore](#namevaluestore)
166
+ * [Parameters](#parameters-43)
167
+ * [Properties](#properties-8)
168
+ * [WaitingGuard](#waitingguard)
169
+ * [Parameters](#parameters-44)
170
+
171
+ ## active
172
+
173
+ * **See**: {Router.updateActive}
174
+
175
+ Keeps the node active state in sync.
176
+
177
+ ### Parameters
178
+
179
+ * `node` **[Element](https://developer.mozilla.org/docs/Web/API/Element)** 
180
+ * `router` **Router** 
181
+
182
+ ## Key
183
+
184
+ Keys also act as svelte stores and can be subscribed.
185
+
186
+ ```js
187
+ export const article = derived(
188
+ [articles, router.keys.article],
189
+ ([$articles, $id], set) => {
190
+ set($articles.find(a => a.id === $id));
191
+ return () => {};
192
+ }
193
+ );
194
+ ```
195
+
196
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
197
+
198
+ ### Properties
199
+
200
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 
201
+ * `value` **any** 
202
+ * `subscriptions` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)** 
203
+
204
+ ## BaseRouter
205
+
206
+ **Extends BaseTransition**
207
+
208
+ key subscriptions:
209
+
210
+ ```js
211
+ const aKey = router.keys.aKey;
212
+ $aKey // fired if value of aKey changes
213
+ ```
214
+
215
+ ### Parameters
216
+
217
+ * `routes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Route>** all managed routes
218
+ * `base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** url (optional, default `new URL("../",import.meta.url).pathname`)
219
+
220
+ ### Properties
221
+
222
+ * `linkNodes` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[Node](https://developer.mozilla.org/docs/Web/API/Node/nextSibling)>** nodes having their active state updated
223
+ * `routes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<Route>**&#x20;
224
+ * `keys` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** collected keys of all routes
225
+ * `params` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** value mapping from keys (from current route)
226
+ * `route` **Route** current
227
+ * `nested` **[Transition](#transition)** ongoing nested transition
228
+ * `base` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** url
229
+
230
+ ### component
231
+
232
+ Current component.
233
+ Either from a nested transition or from the current route
234
+
235
+ Returns **SvelteComponent**&#x20;
236
+
237
+ ### value
238
+
239
+ Value if the current route
240
+
241
+ Returns **any**&#x20;
242
+
243
+ ### path
244
+
245
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** url path with fragment & query
246
+
247
+ ### path
248
+
249
+ Replace current route.
250
+
251
+ #### Parameters
252
+
253
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
254
+
255
+ ### replace
256
+
257
+ Replace current route without updating the state.
258
+
259
+ #### Parameters
260
+
261
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
262
+
263
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** former state
264
+
265
+ ### push
266
+
267
+ Leave current route and enter route for given path.
268
+ The work is done by a Transition.
269
+
270
+ #### Parameters
271
+
272
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** where to go
273
+
274
+ Returns **[Transition](#transition)** running transition
275
+
276
+ ### finalizePush
277
+
278
+ Called from a Transition to manifest the new destination.
279
+ If path is undefined the Transition has been aborderd.
280
+
281
+ #### Parameters
282
+
283
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
284
+
285
+ ### continue
286
+
287
+ Continue a transition to its original destination.
288
+ Shortcut for this.transition.continue().
289
+ If there is no transition ongoing and a fallbackPath is
290
+ present, it will be entered.
291
+ Otherwise does nothing.
292
+
293
+ #### Parameters
294
+
295
+ * `fallbackPath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
296
+
297
+ ### abort
298
+
299
+ Abort a transition.
300
+ Shortcut for this.transition.abort()
301
+ If there is no transition ongoing and a fallbackPath is
302
+ present it will be entered.
303
+ Otherwise does nothing.
304
+
305
+ #### Parameters
306
+
307
+ * `fallbackPath` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
308
+
309
+ ### subscribe
310
+
311
+ Router subscription.
312
+ Changes in the current route will trigger a update
313
+
314
+ #### Parameters
315
+
316
+ * `subscription` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;
317
+
318
+ ### updateActive
319
+
320
+ Update the active state of a node.
321
+ A node is considered active if it shared the path prefix with the current route.
322
+
323
+ #### Parameters
324
+
325
+ * `node` **[Element](https://developer.mozilla.org/docs/Web/API/Element)**&#x20;
326
+
327
+ ### addRoute
328
+
329
+ Add a new Route.
330
+
331
+ #### Parameters
332
+
333
+ * `route` **Route**&#x20;
334
+
335
+ ### routeFor
336
+
337
+ Find Route for a given value.
338
+
339
+ #### Parameters
340
+
341
+ * `value` **any**&#x20;
342
+
343
+ Returns **Route** able to support given value
344
+
345
+ ### pathFor
346
+
347
+ Find path for a given value.
348
+
349
+ #### Parameters
350
+
351
+ * `value` **any**&#x20;
352
+ * `suffix` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** to be appended
353
+
354
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** path + suffix
355
+
356
+ ## BaseTransition
357
+
358
+ ### searchParams
359
+
360
+ Deliver url search params form the current location.
361
+
362
+ Returns **URLSearchParams** as extracted from the path
363
+
364
+ ### searchParams
365
+
366
+ Replaces the search part of the path with the given searchParams.
367
+
368
+ #### Parameters
369
+
370
+ * `searchParams` **(URLSearchParams | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))**&#x20;
371
+
372
+ ### nest
373
+
374
+ Add another transition nesting level.
375
+ Starts a transition from the given factory.
376
+
377
+ #### Parameters
378
+
379
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
380
+ * `factory` **[Transition](#transition)**&#x20;
381
+
382
+ ### continue
383
+
384
+ Continue a nested route to its original destination.
385
+ Does nothing if the transition has not been nested.
386
+
387
+ ### abort
388
+
389
+ Abort the transition.
390
+
391
+ #### Parameters
392
+
393
+ * `error` &#x20;
394
+
395
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** truen in case there was a nesten transition
396
+
397
+ ## DetailRoute
398
+
399
+ **Extends ValueStoreRoute**
400
+
401
+ Route to represent a slice of the masters list of values.
402
+
403
+ ### Properties
404
+
405
+ * `master` **Route** route holding the master records
406
+
407
+ ### master
408
+
409
+ Route holding the list ov values
410
+
411
+ Returns **Route** our master
412
+
413
+ ### first
414
+
415
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** 1st. entry
416
+
417
+ ### last
418
+
419
+ Returns **any** last entry
420
+
421
+ ### previous
422
+
423
+ Returns **any** previous value
424
+
425
+ ### next
426
+
427
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** next value
428
+
429
+ ## Entitlement
430
+
431
+ ### Parameters
432
+
433
+ * `data` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))**&#x20;
434
+
435
+ ## Guard
436
+
437
+ Enforces conditions of routes
438
+ Like the presents of values in the context
439
+
440
+ ### enter
441
+
442
+ Called while entering a route (current outlet is not yet set)
443
+
444
+ #### Parameters
445
+
446
+ * `transition` **[Transition](#transition)**&#x20;
447
+
448
+ ### leave
449
+
450
+ Called before leaving a route
451
+
452
+ #### Parameters
453
+
454
+ * `transition` **[Transition](#transition)**&#x20;
455
+
456
+ ## redirectGuard
457
+
458
+ Redirects to a given path if condition is met.
459
+
460
+ ### Parameters
461
+
462
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
463
+ * `condition` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** redirects when returning true
464
+
465
+ ## sequenceGuard
466
+
467
+ Execute guards in a sequence.
468
+
469
+ ### Parameters
470
+
471
+ * `children` **Iterable<[Guard](#guard)>**&#x20;
472
+
473
+ ## parallelGuard
474
+
475
+ Execute guards in a parallel.
476
+
477
+ ### Parameters
478
+
479
+ * `children` **Iterable<[Guard](#guard)>**&#x20;
41
480
 
42
481
  ## websocketStore
43
482
 
@@ -53,6 +492,390 @@ Keeps socket open (reopens if closed) as long as there are subscriptions.
53
492
 
54
493
  Returns **Store**&#x20;
55
494
 
495
+ ## login
496
+
497
+ Bring session into the valid state by calling the authorization endpoint
498
+ and asking for a access\_token.
499
+ Executes a POST on the endpoint url expecting username, and password as json
500
+
501
+ ### Parameters
502
+
503
+ * `session` **[Session](#session)** to be opened
504
+ * `endpoint` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** authorization url
505
+ * `username` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** id of the user
506
+ * `password` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** user credentials
507
+ * `tokenmap` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** token names in response to internal known values (optional, default `defaultTokenMap`)
508
+
509
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))>** error message in case of failure or undefined on success
510
+
511
+ ## handleFailedResponse
512
+
513
+ Extract error description from response.
514
+
515
+ ### Parameters
516
+
517
+ * `response` **[Response](https://developer.mozilla.org/docs/Web/Guide/HTML/HTML5)**&#x20;
518
+
519
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20;
520
+
521
+ ## MasterRoute
522
+
523
+ **Extends SkeletonRoute**
524
+
525
+ Route holding a ordered collection of values.
526
+
527
+ ### Parameters
528
+
529
+ * `path` &#x20;
530
+ * `options` &#x20;
531
+
532
+ ### Properties
533
+
534
+ * `value` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>**&#x20;
535
+
536
+ ## nullGuard
537
+
538
+ Default empty guard does nothing.
539
+
540
+ ## RootRoute
541
+
542
+ Route at the root of the tree.
543
+ This route has no parent.
544
+ All other routes are below of this one.
545
+
546
+ ### hasParams
547
+
548
+ Are there parameters in the path.
549
+
550
+ Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if route has parameters (:key)
551
+
552
+ ### path
553
+
554
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** empty as we are the root
555
+
556
+ ### propertyMapping
557
+
558
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** empty object
559
+
560
+ ### guard
561
+
562
+ Returns **[Guard](#guard)** empty guard which does nothing
563
+
564
+ ## SkeletonRoute
565
+
566
+ **Extends RootRoute**
567
+
568
+ Route
569
+ Subscriptions on Routes fire when the route value changes.
570
+
571
+ ### Parameters
572
+
573
+ * `path` &#x20;
574
+ * `options` (optional, default `{}`)
575
+
576
+ ### Properties
577
+
578
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** full path of the Route including all parents
579
+ * `component` **SvelteComponent** target to show
580
+ * `linkComponent` **SvelteComponent** content for [ObjectLink](ObjectLink)
581
+ * `propertyMapping` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Map properties to object attributes
582
+ Keys are the property names and values are the keys in the resulting object.
583
+ * `priority` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**&#x20;
584
+ * `keys` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** as found in the path
585
+ * `regex` **RegEx**&#x20;
586
+ * `value` **any**&#x20;
587
+
588
+ ### enter
589
+
590
+ Enter the route from a former one.
591
+ All parent routes up to the common ancestor are entered first.
592
+
593
+ #### Parameters
594
+
595
+ * `transition` **[Transition](#transition)**&#x20;
596
+ * `untilRoute` **Route** the common ancestor with the former route
597
+
598
+ ### leave
599
+
600
+ Leave the route to a new one.
601
+ All parent routes up to the common ancestor are left.
602
+
603
+ #### Parameters
604
+
605
+ * `transition` **[Transition](#transition)**&#x20;
606
+ * `untilRoute` **Route** the common ancestor with the future route
607
+
608
+ ### isAcceptable
609
+
610
+ Check if value and properties are acceptable for the route.
611
+
612
+ #### Parameters
613
+
614
+ * `value` **any** to be placed into route
615
+ * `properties` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** as presented in the route
616
+
617
+ Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if value can be accepted
618
+
619
+ ### propertiesFor
620
+
621
+ Extract properties from a value.
622
+ All property values must be strings.
623
+
624
+ #### Parameters
625
+
626
+ * `value` **any** source of the properties
627
+
628
+ Returns **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** properties extracted from given value
629
+
630
+ ### commonAncestor
631
+
632
+ Find common ancestor with an other Route.
633
+
634
+ #### Parameters
635
+
636
+ * `other` **Route**&#x20;
637
+
638
+ Returns **(Route | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** common ancestor Route between receiver and other
639
+
640
+ ### valueFor
641
+
642
+ Deliver value for a given set of properties of the transition.
643
+ Default implemantation asks the parent route.
644
+
645
+ #### Parameters
646
+
647
+ * `transition` **[Transition](#transition)**&#x20;
648
+
649
+ Returns **any** for matching properties
650
+
651
+ ### value
652
+
653
+ Deliver route value.
654
+ Default implemantation asks the parent route.
655
+
656
+ Returns **any**&#x20;
657
+
658
+ ### propertyMapping
659
+
660
+ Deliver property mapping.
661
+ Default implemantation asks the parent route.
662
+
663
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** for matching properties
664
+
665
+ ### objectInstance
666
+
667
+ Default implemantation asks the parent route.
668
+
669
+ ## ValueStoreRoute
670
+
671
+ **Extends SkeletonRoute**
672
+
673
+ Route holding a single value
674
+
675
+ ## SessionData
676
+
677
+ Data as preserved in the backing store.
678
+
679
+ Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
680
+
681
+ ### Properties
682
+
683
+ * `username` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** user name (id)
684
+ * `access_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** JWT token
685
+ * `refresh_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** JWT token
686
+
687
+ ## msecsRequiredForRefresh
688
+
689
+ Time required to execute a refresh
690
+
691
+ Type: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)
692
+
693
+ ## supportedTokenTypes
694
+
695
+ ## Session
696
+
697
+ User session.
698
+ To create as session backed by browser local storage.
699
+
700
+ ```js
701
+ let session = new Session(localStorage);
702
+ ```
703
+
704
+ or by browser session storage
705
+
706
+ ```js
707
+ let session = new Session(sessionStorage);
708
+ ```
709
+
710
+ ### Parameters
711
+
712
+ * `store` **[SessionData](#sessiondata)** (optional, default `localStorage`)
713
+
714
+ ### Properties
715
+
716
+ * `entitlements` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**&#x20;
717
+ * `subscriptions` **[Set](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Set)<[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** store subscriptions
718
+ * `expirationDate` **[Date](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)** when the access token expires
719
+ * `access_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** token itself
720
+ * `refresh_token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** refresh token
721
+
722
+ ### update
723
+
724
+ Consume auth response data and reflect internal state.
725
+
726
+ #### Parameters
727
+
728
+ * `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**&#x20;
729
+
730
+ ### refresh
731
+
732
+ Refresh with refresh\_token.
733
+
734
+ Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** true if refresh was succcessfull false otherwise
735
+
736
+ ### authorizationHeader
737
+
738
+ Http header suitable for fetch.
739
+
740
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** header The http header.
741
+
742
+ Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** header.Authorization The Bearer access token.
743
+
744
+ ### isValid
745
+
746
+ As long as the expirationTimer is running we must be valid.
747
+
748
+ Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if session is valid (not expired)
749
+
750
+ ### invalidate
751
+
752
+ Remove all tokens from the session and the backing store.
753
+
754
+ ### hasEntitlement
755
+
756
+ Check presence of an entitlement.
757
+
758
+ #### Parameters
759
+
760
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** of the entitlement
761
+
762
+ Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true if the named entitlement is present
763
+
764
+ ### subscribe
765
+
766
+ Fired when the session changes.
767
+
768
+ #### Parameters
769
+
770
+ * `subscription` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**&#x20;
771
+
772
+ ## decode
773
+
774
+ Extract and decode the payload.
775
+
776
+ ### Parameters
777
+
778
+ * `token` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
779
+
780
+ Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** payload object
781
+
782
+ ## Transition
783
+
784
+ **Extends BaseTransition**
785
+
786
+ Transition between routes.
787
+
788
+ ### Parameters
789
+
790
+ * `router` **Router**&#x20;
791
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new destination
792
+
793
+ ### Properties
794
+
795
+ * `router` **Router**&#x20;
796
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new destination
797
+
798
+ ### start
799
+
800
+ Start the transition
801
+
802
+ * leave old route
803
+ * find matching target route @see matcher()
804
+ * enter new route
805
+ * set params
806
+ * set current route
807
+
808
+ ### end
809
+
810
+ * **See**: Router.finalizePush
811
+
812
+ Cleanup transition.
813
+ Update Nodes active state
814
+
815
+ ### redirect
816
+
817
+ Halt current transition and go to another route.
818
+ To proceed with the original route call [continue()](continue\(\))
819
+ The original transition will keept in place and can be continued afterwards.
820
+
821
+ #### Parameters
822
+
823
+ * `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** new route to enter temporary
824
+
825
+ ### abort
826
+
827
+ Bring back the router into the state before the transition has started.
828
+ All nested transitions also will be termniated.
829
+
830
+ #### Parameters
831
+
832
+ * `e` **(Exception | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**&#x20;
833
+
834
+ ## findClosestAttribute
835
+
836
+ Walks up the dom tree parents unti a node with a given attribute is found or the root node is reached.
837
+
838
+ ### Parameters
839
+
840
+ * `element` **[Element](https://developer.mozilla.org/docs/Web/API/Element)**&#x20;
841
+ * `attributeName` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
842
+
843
+ Returns **([Element](https://developer.mozilla.org/docs/Web/API/Element) | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**&#x20;
844
+
845
+ ## dispatchNavigationEvent
846
+
847
+ Dispatches a NAVIGATION\_EVENT with pathname and hash
848
+
849
+ ### Parameters
850
+
851
+ * `event` **[Event](https://developer.mozilla.org/docs/Web/API/Event)**&#x20;
852
+
853
+ ## nameValueStore
854
+
855
+ Create a named object which also acts as a store.
856
+
857
+ ### Parameters
858
+
859
+ * `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**&#x20;
860
+ * `value` **any** initial value
861
+
862
+ ### Properties
863
+
864
+ * `value` **any**&#x20;
865
+
866
+ Returns **Store**&#x20;
867
+
868
+ ## WaitingGuard
869
+
870
+ **Extends Guard**
871
+
872
+ Shows a component during transition.
873
+
874
+ ### Parameters
875
+
876
+ * `component` **SvelteComponent** to show up during th transition
877
+ * `rampUpTime` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** initial delay for the componnt to show up (optional, default `300`)
878
+
56
879
  # install
57
880
 
58
881
  With [npm](http://npmjs.org) do:
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "svelte-websocket-store",
3
- "version": "1.1.34",
3
+ "version": "1.2.0",
4
4
  "publishConfig": {
5
- "access": "public"
5
+ "access": "public",
6
+ "provenance": true
6
7
  },
8
+ "packageManager": "npm@11.6.4+sha512.1118cab46a05a50aee6bff5b1b4fa1df18afff89d57465620a3518035026955db87c5bdf9d207b07b7487d99f2490d450cb774655ad63ec2cba7bf1d0ad25d45",
7
9
  "exports": {
8
- ".": "./src/index.mjs",
10
+ ".": {
11
+ "default": "./src/index.mjs"
12
+ },
9
13
  "./package.json": "./package.json"
10
14
  },
11
15
  "description": "svelte store with a websocket backend",
12
16
  "keywords": [
17
+ "JWT",
13
18
  "component",
14
- "store",
15
19
  "svelte",
16
20
  "vite",
17
21
  "web",
@@ -23,41 +27,50 @@
23
27
  "email": "markus.felten@gmx.de"
24
28
  }
25
29
  ],
26
- "license": "BSD-2-Clause",
30
+ "license": "0BSD",
27
31
  "scripts": {
28
- "prepare": "vite build",
32
+ "prepare": "node --run prepare:vite",
33
+ "prepare:vite": "vite build",
29
34
  "start": "vite",
30
- "test": "npm run test:ava && npm run test:cafe",
31
- "test:cafe": "testcafe $BROWSER:headless tests/cafe/*-cafe.mjs -s build/test --page-request-timeout 5000 --app-init-delay 8000 --app vite",
35
+ "test": "node --run test:ava && node --run test:playwright",
32
36
  "test:ava": "ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs",
37
+ "test:playwright": "npx playwright test",
33
38
  "cover": "c8 -x 'tests/**/*' --temp-directory build/tmp ava --timeout 4m tests/*-ava.mjs tests/*-ava-node.mjs && c8 report -r lcov -o build/coverage --temp-directory build/tmp",
34
- "docs": "documentation readme --section=API ./src/**/*.mjs",
35
- "lint": "npm run lint:docs",
36
- "lint:docs": "documentation lint ./src/**/*.mjs",
39
+ "docs": "documentation readme --section=API ./src**/*.mjs",
40
+ "lint": "node --run lint:docs",
41
+ "lint:docs": "documentation lint ./src**/*.mjs",
37
42
  "preview": "vite preview"
38
43
  },
39
44
  "devDependencies": {
40
- "@semantic-release/commit-analyzer": "^11.1.0",
41
- "@semantic-release/exec": "^6.0.3",
42
- "@semantic-release/release-notes-generator": "^12.1.0",
43
- "@sveltejs/vite-plugin-svelte": "^2.5.2",
44
- "ava": "^5.3.1",
45
- "c8": "^8.0.1",
46
- "documentation": "^14.0.2",
47
- "npm-pkgbuild": "^13.0.4",
48
- "semantic-release": "^22.0.7",
49
- "svelte": "^4.2.3",
50
- "testcafe": "^3.4.0",
51
- "vite": "^4.5.0",
52
- "ws": "^8.14.2"
45
+ "@playwright/test": "^1.57.0",
46
+ "@semantic-release/commit-analyzer": "^13.0.1",
47
+ "@semantic-release/exec": "^7.1.0",
48
+ "@semantic-release/github": "^12.0.2",
49
+ "@semantic-release/release-notes-generator": "^14.1.0",
50
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
51
+ "ava": "^6.4.1",
52
+ "c8": "^10.1.3",
53
+ "documentation": "^14.0.3",
54
+ "mf-styling": "^3.2.20",
55
+ "npm-pkgbuild": "^19.1.0",
56
+ "playwright": "^1.57.0",
57
+ "semantic-release": "^25.0.2",
58
+ "svelte": "^5.45.8",
59
+ "svelte-common": "^6.19.34",
60
+ "vite": "^7.2.7",
61
+ "vite-plugin-compression2": "^2.4.0",
62
+ "ws": "^8.18.3"
63
+ },
64
+ "peerDependencies": {
65
+ "svelte": "^5.45.8"
53
66
  },
54
67
  "optionalDependencies": {
55
- "mf-hosting-cloudflare": "^1.0.6",
56
- "mf-hosting-frontend": "^2.2.5"
68
+ "mf-hosting-cloudflare": "^1.0.9",
69
+ "mf-hosting-frontend": "^3.9.11"
57
70
  },
58
71
  "repository": {
59
72
  "type": "git",
60
- "url": "https://github.com/arlac77/svelte-websocket-store"
73
+ "url": "git+https://github.com/arlac77/svelte-websocket-store.git"
61
74
  },
62
75
  "bugs": {
63
76
  "url": "https://github.com/arlac77/svelte-websocket-store/issues"
@@ -67,6 +80,7 @@
67
80
  "content": {
68
81
  "${install.dir}": "build/"
69
82
  },
83
+ "api": "api/login",
70
84
  "example": true,
71
85
  "frontend": true
72
86
  },
@@ -78,7 +92,7 @@
78
92
  [
79
93
  "@semantic-release/exec",
80
94
  {
81
- "publishCmd": "npx npm-pkgbuild --available --continue --publish dist"
95
+ "publishCmd": "npx npm-pkgbuild --publish dist"
82
96
  }
83
97
  ],
84
98
  [
@@ -122,11 +136,11 @@
122
136
  "inheritFrom": [
123
137
  "arlac77/template-arlac77-github",
124
138
  "arlac77/template-ava-coverage",
139
+ "arlac77/template-cloudflare",
125
140
  "arlac77/template-documentation",
126
- "arlac77/template-svelte",
127
- "arlac77/template-testcafe",
128
141
  "arlac77/template-npm-pkgbuild",
129
- "arlac77/template-cloudflare",
142
+ "arlac77/template-playwright",
143
+ "arlac77/template-svelte",
130
144
  "arlac77/template-web-component"
131
145
  ]
132
146
  }
Binary file
package/vite.config.mts DELETED
@@ -1,108 +0,0 @@
1
- import { svelte } from "@sveltejs/vite-plugin-svelte";
2
- import { defineConfig } from "vite";
3
- import { extractFromPackage } from "npm-pkgbuild";
4
- import { WebSocketServer, WebSocket } from "ws";
5
-
6
- const wsPort = 5001;
7
-
8
- export default defineConfig(async ({ command, mode }) => {
9
- const res = extractFromPackage(
10
- {
11
- dir: new URL("./", import.meta.url).pathname,
12
- mode
13
- },
14
- process.env
15
- );
16
- const first = await res.next();
17
- const pkg = first.value;
18
- const properties = pkg.properties;
19
- const base = properties["http.path"];
20
- const production = mode === "production";
21
-
22
- process.env["VITE_NAME"] = properties.name;
23
- process.env["VITE_DESCRIPTION"] = properties.description;
24
- process.env["VITE_VERSION"] = properties.version;
25
-
26
- if(!production) {
27
- MyWebSocketServer();
28
- }
29
-
30
- return {
31
- base,
32
- root: "tests/app/src",
33
- plugins: [
34
- svelte({
35
- compilerOptions: {
36
- dev: !production
37
- }
38
- })
39
- ],
40
- server: { host: true },
41
- build: {
42
- outDir: "../../../build",
43
- target: "esnext",
44
- emptyOutDir: true,
45
- minify: production,
46
- sourcemap: true
47
- }
48
- };
49
- });
50
-
51
- function MyWebSocketServer() {
52
- const wss = new WebSocketServer({ port: wsPort });
53
-
54
- let timer;
55
-
56
- let n = 0;
57
-
58
- wss.on("connection", ws => {
59
- ws.on("message", message => {
60
- message = message.toString();
61
- try {
62
- const m = message.match(/(\w+)\((\w+)\)/);
63
- if (m) {
64
- switch (m[1]) {
65
- case "disconnect":
66
- {
67
- wss.close();
68
- console.log(`close and reopen after ${parseInt(m[2])}ms`);
69
- setTimeout(
70
- () => MyWebSocketServer(),
71
- parseInt(m[2])
72
- );
73
- }
74
- break;
75
- case "timer": {
76
- if (timer) {
77
- clearInterval(timer);
78
- }
79
-
80
- if (m[2] === "on") {
81
- timer = setInterval(() => {
82
- n++;
83
- wss.clients.forEach(client => {
84
- if (client.readyState === WebSocket.OPEN) {
85
- client.send(JSON.stringify(`timer ${n}`));
86
- }
87
- });
88
- }, 1000);
89
- }
90
- }
91
- }
92
-
93
- return;
94
- }
95
-
96
- wss.clients.forEach(client => {
97
- if (client.readyState === WebSocket.OPEN) {
98
- client.send(JSON.stringify(">" + JSON.parse(message)));
99
- }
100
- });
101
- } catch (e) {
102
- console.log(e);
103
- }
104
- });
105
-
106
- ws.send(JSON.stringify("x"));
107
- });
108
- }