@plitzi/sdk-shared 0.38.6 → 0.38.7
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/CHANGELOG.md +197 -0
- package/dist/dataSource/globalSources.d.ts +34 -1
- package/dist/dataSource/globalSources.mjs +22 -2
- package/dist/dataSource/hooks/index.d.ts +2 -1
- package/dist/dataSource/hooks/index.mjs +2 -1
- package/dist/dataSource/hooks/useResolvedVariables.d.ts +12 -0
- package/dist/dataSource/hooks/useResolvedVariables.mjs +28 -0
- package/dist/dataSource/index.mjs +2 -1
- package/dist/dataSource/resolveVariables.d.ts +2 -2
- package/dist/flags/useFlagResolution.mjs +6 -6
- package/dist/index.mjs +62 -58
- package/dist/network/spaceEvents.d.ts +30 -0
- package/dist/network/spaceEvents.mjs +150 -147
- package/dist/project/layout.d.ts +197 -0
- package/dist/project/layout.mjs +394 -0
- package/dist/project/paths.d.ts +84 -0
- package/dist/project/paths.mjs +4 -0
- package/dist/project/root.d.ts +24 -0
- package/dist/project/root.mjs +26 -0
- package/dist/queries/index.d.ts +12 -2
- package/dist/queries/index.mjs +27 -17
- package/dist/queries/serverQueries.d.ts +22 -0
- package/dist/queries/serverQueries.mjs +9 -0
- package/dist/queries/useServerQuery.d.ts +19 -0
- package/dist/queries/useServerQuery.mjs +21 -0
- package/dist/server/rsc/refreshRsc.d.ts +22 -10
- package/dist/server/rsc/refreshRsc.mjs +65 -53
- package/dist/server/rsc/useRscRefresh.d.ts +2 -1
- package/dist/server/rsc/useRscRefresh.mjs +1 -1
- package/dist/store/index.d.ts +45 -45
- package/dist/style/index.d.ts +3 -0
- package/dist/style/index.mjs +5 -2
- package/dist/style/keyframes.d.ts +39 -0
- package/dist/style/keyframes.mjs +41 -0
- package/dist/style/notifications.d.ts +34 -12
- package/dist/style/notifications.mjs +69 -32
- package/dist/style/styleConditions.d.ts +43 -0
- package/dist/style/styleConditions.mjs +29 -0
- package/dist/style/styleConstants.d.ts +3 -2
- package/dist/style/styleConstants.mjs +2 -0
- package/dist/style/stylePseudos.d.ts +40 -0
- package/dist/style/stylePseudos.mjs +109 -0
- package/dist/style/styleStates.d.ts +35 -8
- package/dist/style/styleStates.mjs +38 -15
- package/dist/style/styleTarget.d.ts +23 -0
- package/dist/style/styleTarget.mjs +35 -0
- package/dist/types/AuthTypes.d.ts +5 -0
- package/dist/types/CommonTypes.d.ts +12 -0
- package/dist/types/SchemaTypes.d.ts +2 -0
- package/dist/types/ServerTypes.d.ts +11 -4
- package/dist/types/StoreTypes.d.ts +5 -1
- package/dist/types/StyleTypes.d.ts +20 -2
- package/package.json +42 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A query the page server answers for a provider (`runtime: 'server'`), as the invalidations see it.
|
|
3
|
+
*
|
|
4
|
+
* Its answer arrives in the RSC payload, never through the {@link QueryCache}, so an invalidation that only reached
|
|
5
|
+
* the cache left every server-driven list showing what it held before the write.
|
|
6
|
+
*/
|
|
7
|
+
export type ServerQuery = {
|
|
8
|
+
/** The provider's element id: what an invalidation naming containers names. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** The URL the server reads for it — only a provider that has nothing but a `query`; a connector or action has none. */
|
|
11
|
+
url?: string;
|
|
12
|
+
/** Asks the server again for this provider's slice, around every cache. */
|
|
13
|
+
refresh: () => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
/** Makes `query` reachable by the invalidations until the returned function is called. */
|
|
16
|
+
export declare const registerServerQuery: (query: ServerQuery) => (() => void);
|
|
17
|
+
/**
|
|
18
|
+
* Asks again for every server query `matches` accepts — all of them without one.
|
|
19
|
+
*
|
|
20
|
+
* Settled, not all-or-nothing: one provider that could not ask again is its own to report, and the rest still refresh.
|
|
21
|
+
*/
|
|
22
|
+
export declare const refreshServerQueries: (matches?: (query: ServerQuery) => boolean) => Promise<void>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/queries/serverQueries.ts
|
|
2
|
+
var e = /* @__PURE__ */ new Set(), t = (t) => {
|
|
3
|
+
let n = { ...t };
|
|
4
|
+
return e.add(n), () => {
|
|
5
|
+
e.delete(n);
|
|
6
|
+
};
|
|
7
|
+
}, n = (t) => Promise.allSettled([...e].filter((e) => !t || t(e)).map((e) => e.refresh())).then(() => void 0);
|
|
8
|
+
//#endregion
|
|
9
|
+
export { n as refreshServerQueries, t as registerServerQuery };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type UseServerQueryOptions = {
|
|
2
|
+
id: string;
|
|
3
|
+
/** The URL the server reads for a provider that has nothing but a `query`. */
|
|
4
|
+
url?: string;
|
|
5
|
+
/** Whether the provider has a live answer to refresh at all — never in the builder, which has no page server. */
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
/** Whether it is on screen: an invalidation of a hidden one waits until it is shown, as a cached query does. */
|
|
8
|
+
active: boolean;
|
|
9
|
+
refresh: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Keeps a server-driven provider reachable by the invalidations — `invalidateQueries`, and the refresh a write step
|
|
13
|
+
* asks for — for as long as it is mounted and `enabled`.
|
|
14
|
+
*
|
|
15
|
+
* The same saving the cache makes for a hidden query: a provider in a tab nobody is looking at is only marked, and
|
|
16
|
+
* asks when it is shown, so a write does not turn into a request for every section the visitor cannot see.
|
|
17
|
+
*/
|
|
18
|
+
declare const useServerQuery: ({ id, url, enabled, active, refresh }: UseServerQueryOptions) => void;
|
|
19
|
+
export default useServerQuery;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { registerServerQuery as e } from "./serverQueries.mjs";
|
|
2
|
+
import { useEffect as t, useRef as n } from "react";
|
|
3
|
+
//#region src/queries/useServerQuery.ts
|
|
4
|
+
var r = ({ id: r, url: i, enabled: a, active: o, refresh: s }) => {
|
|
5
|
+
let c = n(!1);
|
|
6
|
+
t(() => {
|
|
7
|
+
if (a) return o && c.current && (c.current = !1, s()), e({
|
|
8
|
+
id: r,
|
|
9
|
+
url: i,
|
|
10
|
+
refresh: () => o ? s() : (c.current = !0, Promise.resolve())
|
|
11
|
+
});
|
|
12
|
+
}, [
|
|
13
|
+
a,
|
|
14
|
+
o,
|
|
15
|
+
r,
|
|
16
|
+
i,
|
|
17
|
+
s
|
|
18
|
+
]);
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { r as default };
|
|
@@ -13,6 +13,25 @@ export declare const currentRscLocation: () => string;
|
|
|
13
13
|
export declare const cancelRsc: (store: StoreApi<CommonState>, ids?: readonly string[]) => void;
|
|
14
14
|
/** Every refresh of this root aborted and forgotten — the SDK root that owned them is going away. */
|
|
15
15
|
export declare const releaseRscRequests: (instance: string) => void;
|
|
16
|
+
export type RscRefreshOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Resolve for somewhere the visitor is not yet.
|
|
19
|
+
*
|
|
20
|
+
* A route change that renders first and fetches after paints a page whose sections have no answer, so the
|
|
21
|
+
* navigation asks for the destination BEFORE it commits. Absent means where the visitor already is, which is
|
|
22
|
+
* every other caller: the initial load, a pager, an element refreshing itself.
|
|
23
|
+
*/
|
|
24
|
+
location?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Ask the server itself, around the browser's cache and the page server's.
|
|
27
|
+
*
|
|
28
|
+
* Outside `main` an answer is kept for a while on both — the same question from many visitors is resolved once —
|
|
29
|
+
* which is right for a page window and wrong for a refresh that exists because something changed: a write, an
|
|
30
|
+
* explicit reload. Asked through either cache, that refresh is answered with the slice from before the write. A
|
|
31
|
+
* header rather than a query parameter, because every parameter of the request is input to what it resolves.
|
|
32
|
+
*/
|
|
33
|
+
fresh?: boolean;
|
|
34
|
+
};
|
|
16
35
|
/**
|
|
17
36
|
* Re-fetches RSC data into the store.
|
|
18
37
|
*
|
|
@@ -20,7 +39,8 @@ export declare const releaseRscRequests: (instance: string) => void;
|
|
|
20
39
|
* has what it needs through the store it can reach, and an element buried under any number of scopes writes to the
|
|
21
40
|
* root by delegation (nothing but the root owns `rsc`).
|
|
22
41
|
*
|
|
23
|
-
* Pass `
|
|
42
|
+
* Pass `requestedIds` to refresh only those elements — the response is merged over the existing payload; of them,
|
|
43
|
+
* only the ones the server resolves at that location are asked for, and none is no request. Omit them for a full
|
|
24
44
|
* refresh, which replaces it. `params` ride along on the query string; that is how a provider asks for a different
|
|
25
45
|
* page window.
|
|
26
46
|
*
|
|
@@ -29,13 +49,5 @@ export declare const releaseRscRequests: (instance: string) => void;
|
|
|
29
49
|
* again, an element asked for again — is aborted, here and on the server. Before this a click on a link asked twice
|
|
30
50
|
* (its prefetch, then the route change), and a slow answer could land over a newer one.
|
|
31
51
|
*/
|
|
32
|
-
export declare const refreshRsc: (store: StoreApi<CommonState>,
|
|
33
|
-
/**
|
|
34
|
-
* Resolve for somewhere the visitor is not yet.
|
|
35
|
-
*
|
|
36
|
-
* A route change that renders first and fetches after paints a page whose sections have no answer, so the
|
|
37
|
-
* navigation asks for the destination BEFORE it commits. Absent means where the visitor already is, which is
|
|
38
|
-
* every other caller: the initial load, a pager, an element refreshing itself.
|
|
39
|
-
*/
|
|
40
|
-
location?: string) => Promise<void>;
|
|
52
|
+
export declare const refreshRsc: (store: StoreApi<CommonState>, requestedIds?: string[], params?: Record<string, string>, { location, fresh }?: RscRefreshOptions) => Promise<void>;
|
|
41
53
|
export default refreshRsc;
|
|
@@ -1,96 +1,108 @@
|
|
|
1
1
|
import { authFailureFromResponse as e, reportAuthFailure as t } from "../../auth/failureChannel.mjs";
|
|
2
2
|
import { recordRenderActionRuns as n } from "../../store/actionRuns/actionRunsRecorder.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { getPaths as
|
|
3
|
+
import { collectServerElements as r, hasServerElements as i } from "../../schema/serverElements.mjs";
|
|
4
|
+
import { getPaths as a, matchRoutePath as o } from "../../navigation/routes.mjs";
|
|
5
5
|
//#region src/server/rsc/refreshRsc.ts
|
|
6
|
-
var
|
|
6
|
+
var s = (e, t, n) => {
|
|
7
7
|
if (!e) return;
|
|
8
8
|
let r = e.pages.reduce((t, n) => (n in e.flat && (t[n] = e.flat[n]), t), {});
|
|
9
|
-
return a(
|
|
10
|
-
},
|
|
9
|
+
return o(a(r, e.pageFolders, n), t.split("?")[0], n).pageId;
|
|
10
|
+
}, c = (e, t, n, i) => {
|
|
11
|
+
let a = new Set(r(e, t, [...n], i).map(({ id: e }) => e));
|
|
12
|
+
return n.filter((e) => a.has(e));
|
|
13
|
+
}, l = (e) => `rsc.data.${e}`, u = () => typeof window > "u" ? "" : `${window.location.pathname}${window.location.search}`, d = "*", f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new WeakMap(), m = () => ({
|
|
11
14
|
seq: 0,
|
|
12
15
|
inFlight: /* @__PURE__ */ new Set(),
|
|
13
16
|
asked: /* @__PURE__ */ new Map()
|
|
14
|
-
}),
|
|
17
|
+
}), h = (e) => {
|
|
15
18
|
let t = e.get("rsc.instance");
|
|
16
19
|
if (typeof t == "string" && t) {
|
|
17
|
-
let e =
|
|
20
|
+
let e = f.get(t);
|
|
18
21
|
if (e) return e;
|
|
19
|
-
let n =
|
|
20
|
-
return
|
|
22
|
+
let n = m();
|
|
23
|
+
return f.set(t, n), n;
|
|
21
24
|
}
|
|
22
|
-
let n =
|
|
25
|
+
let n = p.get(e);
|
|
23
26
|
if (n) return n;
|
|
24
|
-
let r =
|
|
25
|
-
return
|
|
26
|
-
},
|
|
27
|
+
let r = m();
|
|
28
|
+
return p.set(e, r), r;
|
|
29
|
+
}, g = (e, t) => {
|
|
27
30
|
let n = {};
|
|
28
31
|
t.inFlight.forEach((e) => {
|
|
29
|
-
e.here && (e.ids ?? [
|
|
32
|
+
e.here && (e.ids ?? [d]).forEach((e) => {
|
|
30
33
|
n[e] = !0;
|
|
31
34
|
});
|
|
32
35
|
}), e.set("rsc.refreshing", n);
|
|
33
|
-
},
|
|
34
|
-
|
|
36
|
+
}, _ = (e, t) => !e || !!t && t.every((t) => e.includes(t)), v = (e, t) => {
|
|
37
|
+
h(e).inFlight.forEach((e) => {
|
|
35
38
|
(!t || e.ids?.some((e) => t.includes(e))) && e.controller.abort();
|
|
36
39
|
});
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
+
}, y = (e) => {
|
|
41
|
+
f.get(e)?.inFlight.forEach((e) => e.controller.abort()), f.delete(e);
|
|
42
|
+
}, b = (e, t, n, r, i) => {
|
|
40
43
|
let { ids: a, seq: o } = n;
|
|
41
44
|
e.batch(() => {
|
|
42
45
|
if (a?.length) Object.entries(r).forEach(([n, r]) => {
|
|
43
|
-
(t.asked.get(n) ?? 0) <= o && (t.asked.get(
|
|
46
|
+
(t.asked.get(n) ?? 0) <= o && (t.asked.get(d) ?? 0) <= o && e.set(l(n), r);
|
|
44
47
|
});
|
|
45
48
|
else {
|
|
46
|
-
let n = e.get("rsc.data") ?? {}, i = (e) => e !==
|
|
49
|
+
let n = e.get("rsc.data") ?? {}, i = (e) => e !== d && (t.asked.get(e) ?? 0) > o, a = Object.fromEntries([...Object.entries(r).filter(([e]) => !i(e)), ...Object.entries(n).filter(([e]) => i(e))]);
|
|
47
50
|
e.set("rsc.data", a);
|
|
48
51
|
}
|
|
49
52
|
e.set("rsc.loaded", !0), e.set("rsc.stale", !1), e.set("rsc.location", i);
|
|
50
53
|
});
|
|
51
|
-
},
|
|
52
|
-
let { enabled:
|
|
53
|
-
if (!
|
|
54
|
-
let
|
|
55
|
-
if (!
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
let
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
}, x = async (r, a, o, { location: l, fresh: f = !1 } = {}) => {
|
|
55
|
+
let { enabled: p, endpoint: m } = r.get("rsc") ?? {};
|
|
56
|
+
if (!p || !m || typeof window > "u") return;
|
|
57
|
+
let v = l ?? u(), y = r.get("schema"), x = r.get("runtime.sources.auth"), S = l ? s(y, l, !!x?.details) : r.get("navigation.currentPageId"), C = l ? void 0 : r.get("runtime.sources.flags");
|
|
58
|
+
if (!y) return;
|
|
59
|
+
let w = a?.length ? c(y, S, a, C) : void 0;
|
|
60
|
+
if (w ? !w.length : !i(y, S, C)) return;
|
|
61
|
+
let T = new URLSearchParams({ location: v });
|
|
62
|
+
w?.length && T.set("ids", w.join(",")), Object.entries(o ?? {}).forEach(([e, t]) => T.set(e, t));
|
|
63
|
+
let E = `${m}?${T.toString()}`, D = h(r), O = [...D.inFlight].find((e) => e.url === E && (e.fresh || !f));
|
|
64
|
+
if (O) return O.promise;
|
|
65
|
+
D.inFlight.forEach((e) => {
|
|
66
|
+
_(w, e.ids) && e.controller.abort();
|
|
62
67
|
});
|
|
63
|
-
let
|
|
64
|
-
|
|
65
|
-
let
|
|
66
|
-
url:
|
|
67
|
-
...
|
|
68
|
-
here:
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
let k = ++D.seq;
|
|
69
|
+
w?.length ? w.forEach((e) => D.asked.set(e, k)) : (D.asked.clear(), D.asked.set(d, k));
|
|
70
|
+
let A = new AbortController(), j = {
|
|
71
|
+
url: E,
|
|
72
|
+
...w?.length ? { ids: w } : {},
|
|
73
|
+
here: v === u(),
|
|
74
|
+
fresh: f,
|
|
75
|
+
seq: k,
|
|
76
|
+
controller: A,
|
|
71
77
|
promise: Promise.resolve()
|
|
72
|
-
},
|
|
73
|
-
let a = await fetch(
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
}, M = async (i) => {
|
|
79
|
+
let a = await fetch(E, {
|
|
80
|
+
...f ? {
|
|
81
|
+
cache: "no-cache",
|
|
82
|
+
headers: {
|
|
83
|
+
Accept: "application/json",
|
|
84
|
+
"Cache-Control": "no-cache"
|
|
85
|
+
}
|
|
86
|
+
} : { headers: { Accept: "application/json" } },
|
|
87
|
+
signal: A.signal
|
|
76
88
|
});
|
|
77
89
|
if (!a.ok) {
|
|
78
90
|
let n = e(a.status, await a.json().catch(() => void 0));
|
|
79
91
|
if (n && await t({
|
|
80
92
|
reason: n,
|
|
81
|
-
url:
|
|
82
|
-
}) && !
|
|
83
|
-
|
|
93
|
+
url: m
|
|
94
|
+
}) && !i) return M(!0);
|
|
95
|
+
r.set("rsc.stale", !0);
|
|
84
96
|
return;
|
|
85
97
|
}
|
|
86
98
|
let { serverData: o, actionRuns: s } = await a.json();
|
|
87
|
-
s?.length && n(s),
|
|
99
|
+
s?.length && n(s), b(r, D, j, o ?? {}, v);
|
|
88
100
|
};
|
|
89
|
-
return
|
|
90
|
-
|
|
101
|
+
return j.promise = M(!1).catch(() => {
|
|
102
|
+
A.signal.aborted || r.set("rsc.stale", !0);
|
|
91
103
|
}).finally(() => {
|
|
92
|
-
|
|
93
|
-
}),
|
|
104
|
+
D.inFlight.delete(j), g(r, D);
|
|
105
|
+
}), D.inFlight.add(j), g(r, D), j.promise;
|
|
94
106
|
};
|
|
95
107
|
//#endregion
|
|
96
|
-
export {
|
|
108
|
+
export { v as cancelRsc, u as currentRscLocation, x as default, x as refreshRsc, y as releaseRscRequests, l as rscDataPath };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { RscRefreshOptions } from './refreshRsc';
|
|
2
|
+
declare const useRscRefresh: () => (ids?: string[], params?: Record<string, string>, { fresh }?: Pick<RscRefreshOptions, "fresh">) => Promise<void>;
|
|
2
3
|
export default useRscRefresh;
|
|
@@ -4,7 +4,7 @@ import { useStoreById as n } from "@plitzi/nexus/react";
|
|
|
4
4
|
//#region src/server/rsc/useRscRefresh.ts
|
|
5
5
|
var r = () => {
|
|
6
6
|
let r = n();
|
|
7
|
-
return t((t, n) => e(r, t, n), [r]);
|
|
7
|
+
return t((t, n, { fresh: i } = {}) => e(r, t, n, { fresh: i }), [r]);
|
|
8
8
|
};
|
|
9
9
|
//#endregion
|
|
10
10
|
export { r as default };
|