crelte 0.5.11 → 0.5.12
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/bodyClass/BodyClass.d.ts +39 -0
- package/dist/bodyClass/BodyClass.d.ts.map +1 -0
- package/dist/bodyClass/BodyClass.js +51 -0
- package/dist/bodyClass/ClientBodyClass.d.ts +12 -0
- package/dist/bodyClass/ClientBodyClass.d.ts.map +1 -0
- package/dist/bodyClass/ClientBodyClass.js +57 -0
- package/dist/bodyClass/ServerBodyClass.d.ts +12 -0
- package/dist/bodyClass/ServerBodyClass.d.ts.map +1 -0
- package/dist/bodyClass/ServerBodyClass.js +47 -0
- package/dist/bodyClass/index.d.ts +2 -0
- package/dist/bodyClass/index.d.ts.map +1 -0
- package/dist/bodyClass/index.js +1 -0
- package/dist/cookies/ClientCookies.d.ts +8 -3
- package/dist/cookies/ClientCookies.d.ts.map +1 -1
- package/dist/cookies/ClientCookies.js +31 -7
- package/dist/cookies/Cookies.d.ts +42 -0
- package/dist/cookies/Cookies.d.ts.map +1 -0
- package/dist/cookies/Cookies.js +44 -0
- package/dist/cookies/ServerCookies.d.ts +3 -2
- package/dist/cookies/ServerCookies.d.ts.map +1 -1
- package/dist/cookies/ServerCookies.js +6 -4
- package/dist/cookies/index.d.ts +1 -25
- package/dist/cookies/index.d.ts.map +1 -1
- package/dist/cookies/index.js +1 -1
- package/dist/crelte.d.ts +7 -1
- package/dist/crelte.d.ts.map +1 -1
- package/dist/crelte.js +2 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/init/client.d.ts.map +1 -1
- package/dist/init/client.js +23 -14
- package/dist/init/server.d.ts.map +1 -1
- package/dist/init/server.js +11 -3
- package/dist/init/shared.d.ts +1 -0
- package/dist/init/shared.d.ts.map +1 -1
- package/dist/init/shared.js +16 -5
- package/dist/loadData/Globals.d.ts.map +1 -1
- package/dist/node/index.js +1 -1
- package/dist/plugins/Events.d.ts +6 -1
- package/dist/plugins/Events.d.ts.map +1 -1
- package/dist/plugins/Plugins.d.ts +36 -1
- package/dist/plugins/Plugins.d.ts.map +1 -1
- package/dist/plugins/Plugins.js +32 -0
- package/dist/routing/route/Request.d.ts +1 -1
- package/dist/routing/route/Request.d.ts.map +1 -1
- package/dist/routing/route/Request.js +7 -3
- package/dist/routing/router/ClientRouter.d.ts.map +1 -1
- package/dist/routing/router/ClientRouter.js +18 -11
- package/dist/routing/router/Router.d.ts.map +1 -1
- package/dist/routing/router/Router.js +8 -12
- package/dist/server/CrelteServer.d.ts +1 -0
- package/dist/server/CrelteServer.d.ts.map +1 -1
- package/dist/server/CrelteServer.js +5 -2
- package/dist/std/stores/StagedWritable.d.ts +48 -0
- package/dist/std/stores/StagedWritable.d.ts.map +1 -0
- package/dist/std/stores/StagedWritable.js +84 -0
- package/dist/std/stores/index.d.ts +2 -1
- package/dist/std/stores/index.d.ts.map +1 -1
- package/dist/std/stores/index.js +2 -1
- package/dist/std/sync/Barrier.js +1 -1
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +11 -0
- package/package.json +5 -1
- package/src/bodyClass/BodyClass.ts +72 -0
- package/src/bodyClass/ClientBodyClass.ts +62 -0
- package/src/bodyClass/ServerBodyClass.ts +65 -0
- package/src/bodyClass/index.ts +1 -0
- package/src/cookies/ClientCookies.ts +41 -10
- package/src/cookies/Cookies.ts +70 -0
- package/src/cookies/ServerCookies.ts +9 -6
- package/src/cookies/index.ts +5 -29
- package/src/crelte.ts +9 -0
- package/src/index.ts +15 -1
- package/src/init/client.ts +26 -14
- package/src/init/server.ts +11 -3
- package/src/init/shared.ts +18 -6
- package/src/loadData/Globals.ts +1 -1
- package/src/node/index.ts +1 -1
- package/src/plugins/Events.ts +12 -1
- package/src/plugins/Plugins.ts +66 -1
- package/src/routing/route/Request.ts +11 -4
- package/src/routing/router/ClientRouter.ts +23 -14
- package/src/routing/router/Router.ts +8 -10
- package/src/server/CrelteServer.ts +4 -2
- package/src/std/stores/StagedWritable.ts +96 -0
- package/src/std/stores/index.ts +2 -1
- package/src/std/sync/Barrier.ts +1 -1
- package/src/utils.ts +15 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { CloneableOrPrimitive } from '../index.js';
|
|
2
|
+
import { Readable } from './index.js';
|
|
3
|
+
import Writable from './Writable.js';
|
|
4
|
+
|
|
5
|
+
export default class StagedWritable<T> {
|
|
6
|
+
private inner: Writable<T>;
|
|
7
|
+
// -1 = not staged, 0 = staged but no new value, 1 = staged
|
|
8
|
+
private mode: -1 | 0 | 1;
|
|
9
|
+
private staged: T | undefined;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new StagedWritable
|
|
13
|
+
*
|
|
14
|
+
* @param def A default value
|
|
15
|
+
*/
|
|
16
|
+
constructor(def: T) {
|
|
17
|
+
this.inner = new Writable(def);
|
|
18
|
+
this.mode = -1;
|
|
19
|
+
this.staged = undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns true if the store is currently staged
|
|
24
|
+
*/
|
|
25
|
+
isStaged(): boolean {
|
|
26
|
+
return this.mode >= 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns a new StagedWritable which is staged and has the same value as the current one
|
|
31
|
+
* To commit the staged value, call `commit` on the returned StagedWritable
|
|
32
|
+
*/
|
|
33
|
+
stage(): StagedWritable<T> {
|
|
34
|
+
const n = Object.create(this);
|
|
35
|
+
n.inner = this.inner;
|
|
36
|
+
n.mode = 0;
|
|
37
|
+
n.staged = undefined;
|
|
38
|
+
return n;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The function get's called once with the current value and then when the
|
|
43
|
+
* values changes
|
|
44
|
+
*
|
|
45
|
+
* #### Note
|
|
46
|
+
* This does not check for equality like svelte.
|
|
47
|
+
*
|
|
48
|
+
* @return a function which should be called to unsubscribe
|
|
49
|
+
*/
|
|
50
|
+
subscribe(fn: (val: T) => void, invalidate?: () => void): () => void {
|
|
51
|
+
return this.inner.subscribe(fn, invalidate);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Either updates the store and calls all subscribers with the value or
|
|
56
|
+
* updates the stateful value if previously toStateful was called
|
|
57
|
+
*/
|
|
58
|
+
set(inner: T) {
|
|
59
|
+
if (this.mode >= 0) {
|
|
60
|
+
this.mode = 1;
|
|
61
|
+
this.staged = inner;
|
|
62
|
+
} else {
|
|
63
|
+
this.inner.set(inner);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* If the value was staged, then update the store and call all subscribers with the value
|
|
69
|
+
*/
|
|
70
|
+
commit() {
|
|
71
|
+
if (this.mode < 0) throw new Error('not staged, call stage first');
|
|
72
|
+
|
|
73
|
+
if (this.mode === 1) this.inner.set(this.staged as T);
|
|
74
|
+
|
|
75
|
+
this.staged = undefined;
|
|
76
|
+
this.mode = -1;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the current value either staged or not
|
|
81
|
+
*/
|
|
82
|
+
get(): T {
|
|
83
|
+
if (this.mode === 1) return this.staged as T;
|
|
84
|
+
return this.inner.get();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
readonly(): Readable<T> {
|
|
88
|
+
return this.inner.readonly();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
readclone<U extends T & CloneableOrPrimitive>(
|
|
92
|
+
this: StagedWritable<U>,
|
|
93
|
+
): Readable<U> {
|
|
94
|
+
return this.inner.readclone();
|
|
95
|
+
}
|
|
96
|
+
}
|
package/src/std/stores/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Readable from './Readable.js';
|
|
2
2
|
import Writable from './Writable.js';
|
|
3
3
|
import Readclone from './Readclone.js';
|
|
4
|
+
import StagedWritable from './StagedWritable.js';
|
|
4
5
|
|
|
5
|
-
export { Writable, Readable, Readclone };
|
|
6
|
+
export { Writable, Readable, Readclone, StagedWritable };
|
package/src/std/sync/Barrier.ts
CHANGED
|
@@ -83,7 +83,7 @@ export default class Barrier<T> {
|
|
|
83
83
|
|
|
84
84
|
private _maybeTrigger(): boolean {
|
|
85
85
|
const ready = this.listeners.every(v => v === null || v.ready);
|
|
86
|
-
// if all are ready
|
|
86
|
+
// if not all are ready
|
|
87
87
|
if (!ready) return false;
|
|
88
88
|
|
|
89
89
|
// send the last value to all of them
|
package/src/utils.ts
CHANGED
|
@@ -13,6 +13,21 @@ export function isPromise<T>(p: Promise<T> | T): p is Promise<T> {
|
|
|
13
13
|
return typeof (p as any)?.then === 'function';
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* A helper to chain promises without needing a microtask if its not a promise
|
|
18
|
+
* Equivalent to:
|
|
19
|
+
* ```
|
|
20
|
+
* const val = await p;
|
|
21
|
+
* then(val);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function promiseThen<T, R = void>(
|
|
25
|
+
p: Promise<T> | T,
|
|
26
|
+
then: (val: T) => R,
|
|
27
|
+
): Promise<R> | R {
|
|
28
|
+
return isPromise(p) ? p.then(then) : then(p);
|
|
29
|
+
}
|
|
30
|
+
|
|
16
31
|
// the pathname is always replaced
|
|
17
32
|
export function urlWithPath(url: string, path?: string): URL {
|
|
18
33
|
const u = new URL(url);
|