@valbuild/tanstack 0.150.23 → 0.152.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/CHANGELOG.md +199 -0
- package/README.md +11 -11
- package/client/dist/valbuild-tanstack-client.cjs.dev.js +100 -293
- package/client/dist/valbuild-tanstack-client.cjs.prod.js +100 -293
- package/client/dist/valbuild-tanstack-client.esm.js +99 -292
- package/dist/ValOverlayContext-1e50a557.cjs.prod.js +47 -0
- package/dist/ValOverlayContext-6826b4d9.esm.js +40 -0
- package/dist/ValOverlayContext-b18c2f18.cjs.dev.js +47 -0
- package/dist/declarations/src/ValDraft.d.ts +6 -50
- package/dist/declarations/src/ValModulesClient.d.ts +1 -3
- package/dist/declarations/src/ValProvider.d.ts +1 -1
- package/dist/declarations/src/client/initValClient.d.ts +25 -3
- package/dist/declarations/src/server/initValContent.d.ts +55 -169
- package/dist/{routeFromVal-06590f50.esm.js → routeFromVal-124235a5.esm.js} +3 -153
- package/dist/{routeFromVal-3c3915e2.cjs.dev.js → routeFromVal-2e834397.cjs.prod.js} +1 -156
- package/dist/{routeFromVal-b31a9e00.cjs.prod.js → routeFromVal-3d4d7c30.cjs.dev.js} +1 -156
- package/dist/{typeof-66e2d869.esm.js → typeof-3e1a1d11.esm.js} +1 -1
- package/dist/{typeof-8998e126.cjs.prod.js → typeof-56656438.cjs.prod.js} +0 -2
- package/dist/{typeof-dd0246a1.cjs.dev.js → typeof-bd6ec82c.cjs.dev.js} +0 -2
- package/dist/valbuild-tanstack.cjs.dev.js +162 -282
- package/dist/valbuild-tanstack.cjs.prod.js +162 -282
- package/dist/valbuild-tanstack.esm.js +162 -281
- package/dist/{version-30535975.cjs.prod.js → version-96339a5a.cjs.prod.js} +1 -19
- package/dist/{version-278a8d18.cjs.dev.js → version-c27a565d.cjs.dev.js} +1 -19
- package/dist/{version-3d755ee7.esm.js → version-f05a8296.esm.js} +2 -19
- package/package.json +8 -8
- package/server/dist/valbuild-tanstack-server.cjs.dev.js +278 -1140
- package/server/dist/valbuild-tanstack-server.cjs.prod.js +278 -1140
- package/server/dist/valbuild-tanstack-server.esm.js +279 -1141
- package/dist/ValOverlayContext-198b4bd1.cjs.dev.js +0 -301
- package/dist/ValOverlayContext-6411bbe3.esm.js +0 -293
- package/dist/ValOverlayContext-d9b22d1a.cjs.prod.js +0 -301
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
import { type ResolvableModule, SelectorSource } from "@valbuild/core";
|
|
1
|
+
import { type Json, type ModuleFilePath, type ResolvableModule, SelectorSource, type ValModule } from "@valbuild/core";
|
|
2
2
|
import { type JsonEntryContentOf, type Resolvable, type ResolvedVal, type RouteValueOf } from "@valbuild/react/stega";
|
|
3
|
+
import { type ReadEnv, type Resolution, type ValExternalStore } from "@valbuild/react/internal";
|
|
3
4
|
import { ValConfig } from "@valbuild/core";
|
|
5
|
+
/** What the provider tells the hooks: `ValOverlayContext`'s value. */
|
|
6
|
+
export type PageReadState = {
|
|
7
|
+
store?: ValExternalStore;
|
|
8
|
+
draftMode: boolean | null;
|
|
9
|
+
suspend: boolean;
|
|
10
|
+
draftModeReady?: Promise<void>;
|
|
11
|
+
draftSourcesSynced?: boolean;
|
|
12
|
+
snapshot?: Record<ModuleFilePath, Json>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Where this page's hooks read from, in order: what the Studio sent (the
|
|
16
|
+
* overlay, which starts from the server-read draft when the page has one),
|
|
17
|
+
* then a proposal's or a content version's snapshot, then -- added by every
|
|
18
|
+
* read -- the bundle. A plain function of the provider's state, so the
|
|
19
|
+
* scenario world (`scenarios/`) reads a page with what the hooks read.
|
|
20
|
+
*/
|
|
21
|
+
export declare function pageReadEnv(state: PageReadState, encode: boolean): ReadEnv;
|
|
4
22
|
/** What `useVal` gives back — see `ResolvedVal` in `@valbuild/react/stega`. */
|
|
5
23
|
export type UseValType<T extends SelectorSource> = ResolvedVal<T>;
|
|
6
24
|
declare function useValStega<T extends Resolvable>(selector: T): UseValType<T>;
|
|
@@ -11,10 +29,14 @@ declare function useValStega<T extends Resolvable>(selector: T): UseValType<T>;
|
|
|
11
29
|
* inside a `<Suspense>` boundary.
|
|
12
30
|
*
|
|
13
31
|
* In draft mode it renders the editor's unpublished content, taken from the
|
|
14
|
-
* overlay;
|
|
15
|
-
* entry's lazy import thunk from the local module.
|
|
32
|
+
* overlay; an entry the draft deleted is `undefined`, never the bundled one.
|
|
16
33
|
*/
|
|
17
34
|
declare function useValKeyStega<T extends ResolvableModule>(selector: T, key: string): JsonEntryContentOf<T> | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* {@link routeRead}, for a module (a view resolved). A plain function, so the
|
|
37
|
+
* scenario world (`scenarios/`) reads a route as the hook does.
|
|
38
|
+
*/
|
|
39
|
+
export declare function moduleRouteRead<V>(valModule: ValModule<SelectorSource>, params: Record<string, string | string[]>, env: ReadEnv, settled?: ReadonlySet<Promise<void>>): Resolution<V | null>;
|
|
18
40
|
declare function useValRouteStega<T extends ResolvableModule>(selector: T, params: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): RouteValueOf<T>;
|
|
19
41
|
declare function useValRouteUrl<T extends ResolvableModule>(selector: T, params?: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): string | null;
|
|
20
42
|
export declare function initValClient(config: ValConfig): {
|
|
@@ -1,66 +1,34 @@
|
|
|
1
1
|
import { type JsonEntryContentOf, type Resolvable, type ResolvedVal, type RouteValueOf } from "@valbuild/react/stega";
|
|
2
|
+
import { type Ready } from "@valbuild/react/internal";
|
|
2
3
|
import { ModuleFilePath, ValConfig, ValModules, type Json, type ResolvableModule } from "@valbuild/core";
|
|
3
|
-
import { type
|
|
4
|
-
import {
|
|
4
|
+
import { type ValPatchStore } from "@valbuild/server";
|
|
5
|
+
import { type ValRuntime } from "@valbuild/server/internal";
|
|
5
6
|
import { type ValDraftMode } from "./valDraftMode.js";
|
|
6
7
|
import type { ValDraft } from "../ValDraft.js";
|
|
7
8
|
import type { ValHttpMode } from "./initValServer.js";
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
* scope its cache to" is part of its contract and a test can supply a scope it
|
|
32
|
-
* controls — there is no TanStack request in jest.
|
|
33
|
-
*/
|
|
34
|
-
export type GetDraftSourcesScope = () => Promise<RequestScopedMemo<DraftSources | null> | null>;
|
|
35
|
-
/**
|
|
36
|
-
* A per-request memo box, keyed on the `Request` itself.
|
|
37
|
-
*
|
|
38
|
-
* That is what makes this safe: TanStack resolves one `Request` object per
|
|
39
|
-
* in-flight request out of async local storage, so two visitors cannot collide,
|
|
40
|
-
* and a `WeakMap` lets the entry go when the request does. This is the TanStack
|
|
41
|
-
* half of the Next package's `cache()` — there is no RSC here, so React's
|
|
42
|
-
* request memoisation does not exist (see the note at the top of this file).
|
|
43
|
-
*
|
|
44
|
-
* Outside a request there is nothing to scope to and `getRequest` throws;
|
|
45
|
-
* `null` then means "compute every time", which is what this did before the
|
|
46
|
-
* memo existed. See `memoizePerRequest`.
|
|
47
|
-
*
|
|
48
|
-
* Built PER `initValContent` rather than once for the module, because the box
|
|
49
|
-
* is only as specific as the map it came from: two Val servers in one process
|
|
50
|
-
* sharing one would answer each other's reads within a request, and they hold
|
|
51
|
-
* different content.
|
|
52
|
-
*/
|
|
53
|
-
export declare function createTanStackRequestScope(): GetDraftSourcesScope;
|
|
54
|
-
export declare const initFetchValStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<DraftSourcesValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
|
|
55
|
-
get(name: string): string | null;
|
|
56
|
-
}>, getCookies: () => Promise<{
|
|
57
|
-
get(name: string): {
|
|
58
|
-
name: string;
|
|
59
|
-
value: string;
|
|
60
|
-
} | undefined;
|
|
61
|
-
}>, getDraftSourcesScope: GetDraftSourcesScope,
|
|
62
|
-
/** A proposal's saved Source; see `ValDraft.snapshot`. */
|
|
63
|
-
snapshot?: Snapshot) => <T extends Resolvable>(selector: T) => Promise<ResolvedVal<T>>;
|
|
10
|
+
* What the readers read: this process's runtime for the app's `val.modules`
|
|
11
|
+
* (`createValRuntime`), the same one `initValServer`'s server is built on.
|
|
12
|
+
* Its head is the draft, read with the request's session.
|
|
13
|
+
*/
|
|
14
|
+
export type ReaderRuntime = Promise<ValRuntime>;
|
|
15
|
+
/** What a reader needs from the app and the request. */
|
|
16
|
+
export type ReaderDeps = {
|
|
17
|
+
runtime: ReaderRuntime;
|
|
18
|
+
isEnabled: () => Promise<boolean>;
|
|
19
|
+
getHeaders: () => Promise<{
|
|
20
|
+
get(name: string): string | null;
|
|
21
|
+
}>;
|
|
22
|
+
getCookies: () => Promise<{
|
|
23
|
+
get(name: string): {
|
|
24
|
+
name: string;
|
|
25
|
+
value: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
/** A proposal's saved Source; see `ValDraft.snapshot`. */
|
|
29
|
+
snapshot?: Snapshot;
|
|
30
|
+
};
|
|
31
|
+
export declare const initFetchValStega: (deps: ReaderDeps) => <T extends Resolvable>(selector: T) => Promise<ResolvedVal<T>>;
|
|
64
32
|
/** A proposal's saved Source, by module: see `ValProposal` in `@valbuild/server`. */
|
|
65
33
|
type Snapshot = Record<ModuleFilePath, Json>;
|
|
66
34
|
/**
|
|
@@ -69,13 +37,6 @@ type Snapshot = Record<ModuleFilePath, Json>;
|
|
|
69
37
|
* either alone, or nothing.
|
|
70
38
|
*/
|
|
71
39
|
export declare function snapshotForReaders(http: Pick<ValHttpMode, "proposal" | "contentVersion" | "projectSource"> | undefined): Snapshot | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* What the server's own draft starts from, where it is not the bundle's: the
|
|
74
|
-
* layers `ValOpsHttp` puts over it (`siteSnapshotSources`, then
|
|
75
|
-
* `snapshotSources`), in the same form, so the Studio that starts from it
|
|
76
|
-
* holds the base the server reports. See `ValDraft.base`.
|
|
77
|
-
*/
|
|
78
|
-
export declare function draftBase(http: Pick<ValHttpMode, "proposal" | "contentVersion"> | undefined): Snapshot | undefined;
|
|
79
40
|
/**
|
|
80
41
|
* Where an isolate says which content version it applied, for the platform
|
|
81
42
|
* serving it to read back after a render (valbuild/home: the loader answers it
|
|
@@ -89,126 +50,51 @@ export declare const CONTENT_APPLIED_GLOBAL = "__VAL_CONTENT_APPLIED";
|
|
|
89
50
|
* proposal's address too, where it is under the proposal's saves.
|
|
90
51
|
*/
|
|
91
52
|
export declare function markContentApplied(http: Pick<ValHttpMode, "proposal" | "contentVersion"> | undefined): void;
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
53
|
+
/**
|
|
54
|
+
* The runtime a set of readers reads through, by its `fetchValStega`: what
|
|
55
|
+
* the scenario world (`scenarios/`) asks the head's size of. Nothing in the
|
|
56
|
+
* product asks.
|
|
57
|
+
*/
|
|
58
|
+
export declare function runtimeOfReaders(fetchValStega: object): ReaderRuntime | null;
|
|
59
|
+
/**
|
|
60
|
+
* The read behind a `fetchValDraft`, with which modules it read and the
|
|
61
|
+
* version of each: what the scenario world (`scenarios/`) records beside the
|
|
62
|
+
* page it renders. Nothing in the product asks.
|
|
63
|
+
*/
|
|
64
|
+
export declare function readsOfFetchValDraft(fetchValDraft: object): (() => Promise<Ready<ValDraft | null>>) | null;
|
|
98
65
|
/**
|
|
99
66
|
* The draft a page in this request should start from, or `null` for none.
|
|
100
67
|
*
|
|
101
68
|
* `null` -- and no read at all -- unless draft mode is on: a visitor pays one
|
|
102
|
-
* cookie lookup. Otherwise the
|
|
103
|
-
*
|
|
104
|
-
*
|
|
69
|
+
* cookie lookup. Otherwise the runtime's head, which every `fetchVal` reads,
|
|
70
|
+
* cut down to the modules the draft changes, with the version of each. See
|
|
71
|
+
* `ValDraft`. The read is `readDraftChanges` in
|
|
72
|
+
* `@valbuild/server`, which `@valbuild/next/rsc`'s `fetchValDraft` is too;
|
|
73
|
+
* this adds a proposal's snapshot, which Next has not.
|
|
105
74
|
*
|
|
106
75
|
* Exists because the hooks render on the server too, and had no draft there:
|
|
107
76
|
* a draft page was rendered as the published site and only then replaced, in
|
|
108
77
|
* the browser, by what the editor holds -- old text first on every load.
|
|
109
78
|
*/
|
|
110
|
-
export declare const initFetchValDraft: (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}>, getDraftSourcesScope: GetDraftSourcesScope,
|
|
116
|
-
/** A proposal's saved Source; see `ValDraft.snapshot`. */
|
|
117
|
-
snapshot?: Snapshot,
|
|
118
|
-
/** What the server's draft starts from; see `ValDraft.base`. */
|
|
119
|
-
base?: Snapshot,
|
|
120
|
-
/** Whether this serves a proposal's address; see `ValDraft.atProposal`. */
|
|
121
|
-
atProposal?: boolean) => () => Promise<ValDraft | null>;
|
|
122
|
-
declare const initFetchValRouteStega: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<RouteReaderValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
|
|
123
|
-
get(name: string): string | null;
|
|
124
|
-
}>, getCookies: () => Promise<{
|
|
125
|
-
get(name: string): {
|
|
126
|
-
name: string;
|
|
127
|
-
value: string;
|
|
128
|
-
} | undefined;
|
|
129
|
-
}>, getDraftSourcesScope: GetDraftSourcesScope,
|
|
130
|
-
/** A proposal's saved Source; see `ValDraft.snapshot`. */
|
|
131
|
-
snapshot?: Snapshot) => <T extends ResolvableModule>(selector: T, params: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<RouteValueOf<T>>;
|
|
132
|
-
/**
|
|
133
|
-
* Loads a single `.jsonValues()` entry's DRAFT content via the in-process
|
|
134
|
-
* `/json` endpoint (which replays pending patches). Returns `undefined` when the
|
|
135
|
-
* entry has no draft content to serve — the caller then falls back to the
|
|
136
|
-
* locally-bundled committed content.
|
|
137
|
-
*/
|
|
138
|
-
/**
|
|
139
|
-
* What the draft state says about an entry.
|
|
140
|
-
*
|
|
141
|
-
* The three cases have to stay distinct: `absent` is an ANSWER — the entry is not
|
|
142
|
-
* there in the draft state, e.g. a pending patch removed it — while `unavailable`
|
|
143
|
-
* means we could not ask. Collapsing them into `undefined` is what made a
|
|
144
|
-
* draft-deleted entry keep rendering its committed content: the caller could not
|
|
145
|
-
* tell "it is gone" from "ask the committed source instead".
|
|
146
|
-
*/
|
|
147
|
-
/**
|
|
148
|
-
* The slice of `ValServer` the single-entry readers actually use. Narrower than
|
|
149
|
-
* `ValServer` on purpose: it says what the dependency IS, and it lets a test
|
|
150
|
-
* drive these readers with a one-route fake instead of casting a partial object
|
|
151
|
-
* to the whole server type.
|
|
152
|
-
*/
|
|
153
|
-
export type JsonEntryValServer = Pick<ValServer, "/json">;
|
|
154
|
-
export type DraftJsonEntry = {
|
|
155
|
-
status: "content";
|
|
156
|
-
content: unknown;
|
|
157
|
-
} | {
|
|
158
|
-
status: "absent";
|
|
159
|
-
} | {
|
|
160
|
-
status: "unavailable";
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Picks the content a draft-aware single-entry read should render.
|
|
164
|
-
*
|
|
165
|
-
* The rule the two callers share: the draft state WINS when it has an answer —
|
|
166
|
-
* including the answer "this entry is gone" — and the committed content is used
|
|
167
|
-
* only when there is no draft answer to be had (Val disabled, or we could not
|
|
168
|
-
* ask). Returning `undefined` means "render nothing"; both callers turn that into
|
|
169
|
-
* a null/undefined result.
|
|
170
|
-
*/
|
|
171
|
-
/**
|
|
172
|
-
* What a proposal's snapshot says about one `.jsonValues()` entry: its saved
|
|
173
|
-
* content, `absent` when the proposal removed it, or `unavailable` -- not at
|
|
174
|
-
* a proposal, or an entry the proposal did not save, which is the build's.
|
|
175
|
-
*
|
|
176
|
-
* The snapshot carries saved entries as content in place of their markers
|
|
177
|
-
* (`proposalSnapshotForReaders` in @valbuild/server). The same rule as the
|
|
178
|
-
* browser's `draftJsonEntry`, so the server's render and the hydrated page
|
|
179
|
-
* agree.
|
|
180
|
-
*/
|
|
181
|
-
export declare function snapshotJsonEntry(snapshot: Snapshot | undefined, moduleFilePath: ModuleFilePath, key: string): DraftJsonEntry;
|
|
182
|
-
export declare function resolveDraftOrCommittedEntry(draft: DraftJsonEntry, loadCommitted: () => Promise<unknown | undefined>): Promise<unknown | undefined>;
|
|
79
|
+
export declare const initFetchValDraft: (deps: Omit<ReaderDeps, "getHeaders"> & {
|
|
80
|
+
/** Whether this serves a proposal's address; see `ValDraft.atProposal`. */
|
|
81
|
+
atProposal?: boolean;
|
|
82
|
+
}) => () => Promise<ValDraft | null>;
|
|
83
|
+
declare const initFetchValRouteStega: (deps: ReaderDeps) => <T extends ResolvableModule>(selector: T, params: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<RouteValueOf<T>>;
|
|
183
84
|
/**
|
|
184
85
|
* Resolves ONE `.jsonValues()` entry by key, loading only that entry instead of
|
|
185
86
|
* the whole record — the runtime-scaling counterpart to the eager `fetchVal`.
|
|
186
87
|
*
|
|
187
|
-
* Production (Val disabled):
|
|
188
|
-
*
|
|
88
|
+
* Production (Val disabled): the entry's lazy import from the bundle (one
|
|
89
|
+
* dynamic import, no server round-trip), unless a proposal's snapshot has it.
|
|
189
90
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
91
|
+
* Draft mode: the entry from the runtime's head, with the pending patches the
|
|
92
|
+
* draft holds for it, so uncommitted Studio edits show up; an entry the draft
|
|
93
|
+
* deleted is not there. An entry of a record no patch touched is the bundle's
|
|
94
|
+
* (or the snapshot's).
|
|
193
95
|
*/
|
|
194
|
-
export declare const initFetchValKeyStega: (
|
|
195
|
-
|
|
196
|
-
name: string;
|
|
197
|
-
value: string;
|
|
198
|
-
} | undefined;
|
|
199
|
-
}>,
|
|
200
|
-
/** A proposal's saved Source; see `ValDraft.snapshot`. */
|
|
201
|
-
snapshot?: Snapshot) => <T extends ResolvableModule>(selector: T, key: string) => Promise<JsonEntryContentOf<T> | undefined>;
|
|
202
|
-
declare const initFetchValRouteUrl: (config: ValConfig, valApiEndpoints: string, valServerPromise: Promise<RouteReaderValServer>, isEnabled: () => Promise<boolean>, getHeaders: () => Promise<{
|
|
203
|
-
get(name: string): string | null;
|
|
204
|
-
}>, getCookies: () => Promise<{
|
|
205
|
-
get(name: string): {
|
|
206
|
-
name: string;
|
|
207
|
-
value: string;
|
|
208
|
-
} | undefined;
|
|
209
|
-
}>, getDraftSourcesScope: GetDraftSourcesScope,
|
|
210
|
-
/** A proposal's saved Source; see `ValDraft.snapshot`. */
|
|
211
|
-
snapshot?: Snapshot) => <T extends ResolvableModule>(selector: T, params?: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<string | null>;
|
|
96
|
+
export declare const initFetchValKeyStega: (deps: Omit<ReaderDeps, "getHeaders">) => <T extends ResolvableModule>(selector: T, key: string) => Promise<JsonEntryContentOf<T> | undefined>;
|
|
97
|
+
declare const initFetchValRouteUrl: (deps: ReaderDeps) => <T extends ResolvableModule>(selector: T, params?: Promise<Record<string, string | string[]>> | Record<string, string | string[]> | unknown) => Promise<string | null>;
|
|
212
98
|
/**
|
|
213
99
|
* Val's content readers for the server side of a TanStack Start app.
|
|
214
100
|
*
|
|
@@ -1,157 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { e as _typeof, a as _slicedToArray, _ as _objectSpread2, b as _createForOfIteratorHelper } from './typeof-3e1a1d11.esm.js';
|
|
2
|
+
import { Internal, RecordSchema } from '@valbuild/core';
|
|
3
3
|
import { getTanStackRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern } from '@valbuild/shared/client';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* True when the module's schema is a `.jsonValues()` record/router — i.e. each
|
|
7
|
-
* entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
|
|
8
|
-
* route helpers to load ONLY the matched entry instead of the whole record.
|
|
9
|
-
*/
|
|
10
|
-
function isJsonValuesRecordSchema(schema) {
|
|
11
|
-
return schema instanceof RecordSchema && schema["executeSerialize"]().jsonValues === true;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A whole `.jsonValues()` record, as `useVal` and `fetchVal` read it: with
|
|
16
|
-
* every entry's content. In the record's own source each entry is a lazy
|
|
17
|
-
* `c.json(() => import(...))` marker, so a reader that encodes that source
|
|
18
|
-
* renders every entry empty. (`useValKey` and `fetchValKey` read one entry,
|
|
19
|
-
* and load only that one.)
|
|
20
|
-
*
|
|
21
|
-
* `sourcesOf(modulePath)` are what the reader has before the bundle, the first
|
|
22
|
-
* that has the record winning: a draft view, then a snapshot (a proposal's saves, or the
|
|
23
|
-
* content version the site serves). An entry that is still a marker there is
|
|
24
|
-
* taken from a later source that has its content; the rest are named in
|
|
25
|
-
* `load`, for the reader to load from the bundle by key and hand to
|
|
26
|
-
* {@link fillJsonValuesRecord}.
|
|
27
|
-
*
|
|
28
|
-
* `null` when the selector is not a `.jsonValues()` module, or its record is
|
|
29
|
-
* not an object (a nullable record that is null): there is nothing to fill.
|
|
30
|
-
*/
|
|
31
|
-
function jsonValuesRecordToFill(
|
|
32
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
-
selector, sourcesOf) {
|
|
34
|
-
// Untyped, as `getJsonEntryStegaRoot`'s selector is: a module or a view of
|
|
35
|
-
// one, whichever source type it was defined with.
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
-
var module = Internal.resolveViewedModule(selector);
|
|
38
|
-
if (!module || !isJsonValuesRecordSchema(Internal.getSchema(module))) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
var modulePath = Internal.getValPath(module);
|
|
42
|
-
if (!modulePath) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
var sources = sourcesOf(modulePath);
|
|
46
|
-
var isRecord = function isRecord(value) {
|
|
47
|
-
return _typeof(value) === "object" && value !== null && !Array.isArray(value);
|
|
48
|
-
};
|
|
49
|
-
var chosen = sources.find(function (source) {
|
|
50
|
-
return source !== undefined;
|
|
51
|
-
});
|
|
52
|
-
var base = chosen !== undefined ? chosen : Internal.getSource(module);
|
|
53
|
-
if (!isRecord(base)) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
var record = {};
|
|
57
|
-
var load = [];
|
|
58
|
-
var _loop = function _loop() {
|
|
59
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
60
|
-
key = _Object$entries$_i[0],
|
|
61
|
-
entry = _Object$entries$_i[1];
|
|
62
|
-
if (!Internal.isJson(entry)) {
|
|
63
|
-
record[key] = entry;
|
|
64
|
-
return 1; // continue
|
|
65
|
-
}
|
|
66
|
-
var later = sources.slice(sources.indexOf(chosen) + 1).map(function (source) {
|
|
67
|
-
return isRecord(source) && Object.prototype.hasOwnProperty.call(source, key) ? source[key] : undefined;
|
|
68
|
-
}).find(function (content) {
|
|
69
|
-
return content !== undefined && !Internal.isJson(content);
|
|
70
|
-
});
|
|
71
|
-
if (later !== undefined) {
|
|
72
|
-
record[key] = later;
|
|
73
|
-
} else {
|
|
74
|
-
// Left as the marker until it is loaded: see `fillJsonValuesRecord`.
|
|
75
|
-
record[key] = entry;
|
|
76
|
-
load.push(key);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
for (var _i = 0, _Object$entries = Object.entries(base); _i < _Object$entries.length; _i++) {
|
|
80
|
-
if (_loop()) continue;
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
modulePath: modulePath,
|
|
84
|
-
module: module,
|
|
85
|
-
record: record,
|
|
86
|
-
load: load
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The record from {@link jsonValuesRecordToFill}, with the entries it named in
|
|
92
|
-
* `load` put in: `loaded[key]`, as the bundle's import of that entry gave it.
|
|
93
|
-
* An entry the bundle has no import for keeps its marker.
|
|
94
|
-
*/
|
|
95
|
-
function fillJsonValuesRecord(record, loaded) {
|
|
96
|
-
var filled = _objectSpread2({}, record);
|
|
97
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries(loaded); _i2 < _Object$entries2.length; _i2++) {
|
|
98
|
-
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
99
|
-
key = _Object$entries2$_i[0],
|
|
100
|
-
content = _Object$entries2$_i[1];
|
|
101
|
-
if (content !== undefined) {
|
|
102
|
-
filled[key] = content;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return filled;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* The bundle's import of one `.jsonValues()` entry, started: `undefined` when
|
|
110
|
-
* the module's own source has no marker for `key` to import from.
|
|
111
|
-
*/
|
|
112
|
-
function bundledJsonEntryImport(
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
114
|
-
module, key) {
|
|
115
|
-
var _Internal$getJsonImpo;
|
|
116
|
-
var source = module && Internal.getSource(module);
|
|
117
|
-
var marker = _typeof(source) === "object" && source !== null && !Array.isArray(source) ? source[key] : undefined;
|
|
118
|
-
if (!Internal.isJson(marker)) {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
return (_Internal$getJsonImpo = Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
|
|
126
|
-
* strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
|
|
127
|
-
* identity transform (the content carries no selector path/schema).
|
|
128
|
-
*
|
|
129
|
-
* Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
|
|
130
|
-
* field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
|
|
131
|
-
* `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
|
|
132
|
-
*/
|
|
133
|
-
function getJsonEntryStegaRoot(
|
|
134
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
-
selector, key
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
-
) {
|
|
138
|
-
var modulePath = selector && Internal.getValPath(selector);
|
|
139
|
-
if (!modulePath) {
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
var schema = selector && Internal.getSchema(selector);
|
|
143
|
-
if (!(schema instanceof RecordSchema)) {
|
|
144
|
-
return undefined;
|
|
145
|
-
}
|
|
146
|
-
var path = Internal.createValPathOfItem(modulePath, key);
|
|
147
|
-
if (!path) {
|
|
148
|
-
return undefined;
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
path: path,
|
|
152
|
-
schema: schema["executeSerialize"]().item
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
5
|
function getValRouteUrlFromVal(resolvedParams, methodName,
|
|
156
6
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
7
|
path,
|
|
@@ -321,4 +171,4 @@ val) {
|
|
|
321
171
|
return actualRoute;
|
|
322
172
|
}
|
|
323
173
|
|
|
324
|
-
export { getValRouteUrlFromVal as
|
|
174
|
+
export { getValRouteUrlFromVal as g, initValRouteFromVal as i };
|
|
@@ -1,159 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _typeof = require('./typeof-
|
|
3
|
+
var _typeof = require('./typeof-56656438.cjs.prod.js');
|
|
4
4
|
var core = require('@valbuild/core');
|
|
5
5
|
var client = require('@valbuild/shared/client');
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* True when the module's schema is a `.jsonValues()` record/router — i.e. each
|
|
9
|
-
* entry value is a lazily-loaded `c.json(() => import(...))` marker. Used by the
|
|
10
|
-
* route helpers to load ONLY the matched entry instead of the whole record.
|
|
11
|
-
*/
|
|
12
|
-
function isJsonValuesRecordSchema(schema) {
|
|
13
|
-
return schema instanceof core.RecordSchema && schema["executeSerialize"]().jsonValues === true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A whole `.jsonValues()` record, as `useVal` and `fetchVal` read it: with
|
|
18
|
-
* every entry's content. In the record's own source each entry is a lazy
|
|
19
|
-
* `c.json(() => import(...))` marker, so a reader that encodes that source
|
|
20
|
-
* renders every entry empty. (`useValKey` and `fetchValKey` read one entry,
|
|
21
|
-
* and load only that one.)
|
|
22
|
-
*
|
|
23
|
-
* `sourcesOf(modulePath)` are what the reader has before the bundle, the first
|
|
24
|
-
* that has the record winning: a draft view, then a snapshot (a proposal's saves, or the
|
|
25
|
-
* content version the site serves). An entry that is still a marker there is
|
|
26
|
-
* taken from a later source that has its content; the rest are named in
|
|
27
|
-
* `load`, for the reader to load from the bundle by key and hand to
|
|
28
|
-
* {@link fillJsonValuesRecord}.
|
|
29
|
-
*
|
|
30
|
-
* `null` when the selector is not a `.jsonValues()` module, or its record is
|
|
31
|
-
* not an object (a nullable record that is null): there is nothing to fill.
|
|
32
|
-
*/
|
|
33
|
-
function jsonValuesRecordToFill(
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
selector, sourcesOf) {
|
|
36
|
-
// Untyped, as `getJsonEntryStegaRoot`'s selector is: a module or a view of
|
|
37
|
-
// one, whichever source type it was defined with.
|
|
38
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
-
var module = core.Internal.resolveViewedModule(selector);
|
|
40
|
-
if (!module || !isJsonValuesRecordSchema(core.Internal.getSchema(module))) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
var modulePath = core.Internal.getValPath(module);
|
|
44
|
-
if (!modulePath) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
var sources = sourcesOf(modulePath);
|
|
48
|
-
var isRecord = function isRecord(value) {
|
|
49
|
-
return _typeof._typeof(value) === "object" && value !== null && !Array.isArray(value);
|
|
50
|
-
};
|
|
51
|
-
var chosen = sources.find(function (source) {
|
|
52
|
-
return source !== undefined;
|
|
53
|
-
});
|
|
54
|
-
var base = chosen !== undefined ? chosen : core.Internal.getSource(module);
|
|
55
|
-
if (!isRecord(base)) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
var record = {};
|
|
59
|
-
var load = [];
|
|
60
|
-
var _loop = function _loop() {
|
|
61
|
-
var _Object$entries$_i = _typeof._slicedToArray(_Object$entries[_i], 2),
|
|
62
|
-
key = _Object$entries$_i[0],
|
|
63
|
-
entry = _Object$entries$_i[1];
|
|
64
|
-
if (!core.Internal.isJson(entry)) {
|
|
65
|
-
record[key] = entry;
|
|
66
|
-
return 1; // continue
|
|
67
|
-
}
|
|
68
|
-
var later = sources.slice(sources.indexOf(chosen) + 1).map(function (source) {
|
|
69
|
-
return isRecord(source) && Object.prototype.hasOwnProperty.call(source, key) ? source[key] : undefined;
|
|
70
|
-
}).find(function (content) {
|
|
71
|
-
return content !== undefined && !core.Internal.isJson(content);
|
|
72
|
-
});
|
|
73
|
-
if (later !== undefined) {
|
|
74
|
-
record[key] = later;
|
|
75
|
-
} else {
|
|
76
|
-
// Left as the marker until it is loaded: see `fillJsonValuesRecord`.
|
|
77
|
-
record[key] = entry;
|
|
78
|
-
load.push(key);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
for (var _i = 0, _Object$entries = Object.entries(base); _i < _Object$entries.length; _i++) {
|
|
82
|
-
if (_loop()) continue;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
modulePath: modulePath,
|
|
86
|
-
module: module,
|
|
87
|
-
record: record,
|
|
88
|
-
load: load
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The record from {@link jsonValuesRecordToFill}, with the entries it named in
|
|
94
|
-
* `load` put in: `loaded[key]`, as the bundle's import of that entry gave it.
|
|
95
|
-
* An entry the bundle has no import for keeps its marker.
|
|
96
|
-
*/
|
|
97
|
-
function fillJsonValuesRecord(record, loaded) {
|
|
98
|
-
var filled = _typeof._objectSpread2({}, record);
|
|
99
|
-
for (var _i2 = 0, _Object$entries2 = Object.entries(loaded); _i2 < _Object$entries2.length; _i2++) {
|
|
100
|
-
var _Object$entries2$_i = _typeof._slicedToArray(_Object$entries2[_i2], 2),
|
|
101
|
-
key = _Object$entries2$_i[0],
|
|
102
|
-
content = _Object$entries2$_i[1];
|
|
103
|
-
if (content !== undefined) {
|
|
104
|
-
filled[key] = content;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return filled;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* The bundle's import of one `.jsonValues()` entry, started: `undefined` when
|
|
112
|
-
* the module's own source has no marker for `key` to import from.
|
|
113
|
-
*/
|
|
114
|
-
function bundledJsonEntryImport(
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
116
|
-
module, key) {
|
|
117
|
-
var _Internal$getJsonImpo;
|
|
118
|
-
var source = module && core.Internal.getSource(module);
|
|
119
|
-
var marker = _typeof._typeof(source) === "object" && source !== null && !Array.isArray(source) ? source[key] : undefined;
|
|
120
|
-
if (!core.Internal.isJson(marker)) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
return (_Internal$getJsonImpo = core.Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
|
|
128
|
-
* strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
|
|
129
|
-
* identity transform (the content carries no selector path/schema).
|
|
130
|
-
*
|
|
131
|
-
* Yields e.g. `/src/routes/support.$slug.val.ts?p="/support/faq"`, so a `title`
|
|
132
|
-
* field is tagged `…?p="/support/faq"."title"` — the shape the Studio's
|
|
133
|
-
* `findUnloadedJsonEntryKey` walks, so click-to-edit + lazy load line up.
|
|
134
|
-
*/
|
|
135
|
-
function getJsonEntryStegaRoot(
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
-
selector, key
|
|
138
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
|
-
) {
|
|
140
|
-
var modulePath = selector && core.Internal.getValPath(selector);
|
|
141
|
-
if (!modulePath) {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
var schema = selector && core.Internal.getSchema(selector);
|
|
145
|
-
if (!(schema instanceof core.RecordSchema)) {
|
|
146
|
-
return undefined;
|
|
147
|
-
}
|
|
148
|
-
var path = core.Internal.createValPathOfItem(modulePath, key);
|
|
149
|
-
if (!path) {
|
|
150
|
-
return undefined;
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
path: path,
|
|
154
|
-
schema: schema["executeSerialize"]().item
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
7
|
function getValRouteUrlFromVal(resolvedParams, methodName,
|
|
158
8
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
9
|
path,
|
|
@@ -323,10 +173,5 @@ val) {
|
|
|
323
173
|
return actualRoute;
|
|
324
174
|
}
|
|
325
175
|
|
|
326
|
-
exports.bundledJsonEntryImport = bundledJsonEntryImport;
|
|
327
|
-
exports.fillJsonValuesRecord = fillJsonValuesRecord;
|
|
328
|
-
exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
|
|
329
176
|
exports.getValRouteUrlFromVal = getValRouteUrlFromVal;
|
|
330
177
|
exports.initValRouteFromVal = initValRouteFromVal;
|
|
331
|
-
exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
|
|
332
|
-
exports.jsonValuesRecordToFill = jsonValuesRecordToFill;
|