@valbuild/react 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.
Files changed (27) hide show
  1. package/CHANGELOG.md +178 -0
  2. package/dist/declarations/src/internal/index.d.ts +1 -0
  3. package/dist/declarations/src/read/draft.d.ts +105 -0
  4. package/dist/declarations/src/read/index.d.ts +8 -0
  5. package/dist/declarations/src/read/jsonValues.d.ts +26 -0
  6. package/dist/declarations/src/read/layered.d.ts +45 -0
  7. package/dist/declarations/src/read/overlayStore.d.ts +113 -0
  8. package/dist/declarations/src/read/readers.d.ts +51 -0
  9. package/dist/declarations/src/read/refreshLoop.d.ts +61 -0
  10. package/dist/declarations/src/read/resolveVal.d.ts +93 -0
  11. package/dist/declarations/src/read/sources.d.ts +63 -0
  12. package/dist/{raw-be4b57fa.browser.esm.js → raw-15ce77ae.browser.esm.js} +1 -1
  13. package/dist/{raw-1b40484b.esm.js → raw-534fcde0.esm.js} +1 -1
  14. package/dist/{raw-43f9221a.worker.esm.js → raw-645a854a.worker.esm.js} +1 -1
  15. package/dist/{raw-ff060f24.cjs.dev.js → raw-67d24dd6.cjs.dev.js} +2 -0
  16. package/dist/{raw-b3745603.cjs.prod.js → raw-d504f4fd.cjs.prod.js} +2 -0
  17. package/internal/dist/valbuild-react-internal.browser.esm.js +1723 -6
  18. package/internal/dist/valbuild-react-internal.cjs.dev.js +1748 -4
  19. package/internal/dist/valbuild-react-internal.cjs.prod.js +1748 -4
  20. package/internal/dist/valbuild-react-internal.esm.js +1723 -6
  21. package/internal/dist/valbuild-react-internal.worker.esm.js +1723 -6
  22. package/package.json +4 -4
  23. package/stega/dist/valbuild-react-stega.browser.esm.js +2 -2
  24. package/stega/dist/valbuild-react-stega.cjs.dev.js +1 -1
  25. package/stega/dist/valbuild-react-stega.cjs.prod.js +1 -1
  26. package/stega/dist/valbuild-react-stega.esm.js +2 -2
  27. package/stega/dist/valbuild-react-stega.worker.esm.js +2 -2
@@ -0,0 +1,93 @@
1
+ import { type ModuleFilePath, type ResolvableModule, type SelectorSource, type ValModule } from "@valbuild/core";
2
+ import type { ContentSource, ModuleVersion } from "@valbuild/shared/internal";
3
+ import { type JsonEntryContentOf, type Resolvable, type ResolvedVal } from "../stega/stegaEncode.js";
4
+ import { type SchemaRule } from "./layered.js";
5
+ /**
6
+ * Everything a read needs that is not the selector: where content comes from
7
+ * and whether it carries edit tags. Built once per request on the server and
8
+ * once per render in a component; the only thing the readers differ in.
9
+ *
10
+ * `encode` is decided ONCE, from draft mode (and, on TanStack, hydration and
11
+ * analytics): there is no second encode on an error path to forget it.
12
+ */
13
+ export type ReadEnv = {
14
+ /** In order; the bundle is put after them by every read. */
15
+ readonly sources: readonly ContentSource[];
16
+ readonly encode: boolean;
17
+ /**
18
+ * The version of the schema the reader's own code has for a module, for
19
+ * {@link SchemaRule}. Absent: no source this env reads carries versions.
20
+ */
21
+ readonly schemaVersionOf?: (module: ValModule<SelectorSource>) => string | null;
22
+ readonly codeChanged?: SchemaRule["codeChanged"];
23
+ };
24
+ /** Which source a module was read from, and the version of what it read. */
25
+ export type ReadOf = {
26
+ path: ModuleFilePath;
27
+ /** `overlay`, `server-draft`, `snapshot` or `bundle`. */
28
+ from: string;
29
+ version: ModuleVersion | null;
30
+ };
31
+ /** What a read is: a value with the reads it was made of, or a wait. */
32
+ export type Resolution<T> = {
33
+ status: "ready";
34
+ value: T;
35
+ reads: readonly ReadOf[];
36
+ } | {
37
+ status: "pending";
38
+ /** What to wait on before reading again: the first wait. */
39
+ ready: Promise<void>;
40
+ /** Every wait this read met, all started: a server awaits them together. */
41
+ waits: readonly Promise<void>[];
42
+ };
43
+ /**
44
+ * What a read of `selector` reads: every module it names (`getModuleIds`),
45
+ * the module objects it carries -- whose `.jsonValues()` entries the bundle
46
+ * imports -- and the whole `.jsonValues()` record it is, if it is one.
47
+ */
48
+ export type ReadPlan = {
49
+ readonly modules: readonly ModuleFilePath[];
50
+ readonly own: ReadonlyMap<ModuleFilePath, ValModule<SelectorSource>>;
51
+ readonly record: ModuleFilePath | null;
52
+ };
53
+ export declare function planOf(selector: unknown): ReadPlan;
54
+ /**
55
+ * Counted work, for the scenarios' budgets (`read:resolve`, `read:encode`):
56
+ * how many times a reader resolved, and how many of those encoded a value.
57
+ * A render resolves once per selector unless something it waited on is in;
58
+ * a server read resolves once per wait, plus the one that is ready.
59
+ */
60
+ export declare function readWork(): {
61
+ resolve: number;
62
+ encode: number;
63
+ };
64
+ /** How a read is made, beyond its env. */
65
+ export type ResolveOptions = {
66
+ /**
67
+ * `false` leaves a `.jsonValues()` record's entries as they are: a reader
68
+ * that only needs the record's keys (`useValRouteUrl`) imports none.
69
+ */
70
+ entries?: boolean;
71
+ /** Waits already over: see `layered`. */
72
+ settled?: ReadonlySet<Promise<void>>;
73
+ };
74
+ /**
75
+ * Resolve `selector` against `env`: read the modules {@link planOf} names
76
+ * from the sources (the first that does not pass wins: `layered`), fill a
77
+ * whole `.jsonValues()` record's entries, and -- once nothing is pending --
78
+ * encode the value. Every reader of a value goes through this: `fetchVal`,
79
+ * `useVal`, and the route readers' modules.
80
+ */
81
+ export declare function resolveVal<T extends Resolvable>(selector: T, env: ReadEnv, opts?: ResolveOptions): Resolution<ResolvedVal<T>>;
82
+ /**
83
+ * Resolve ONE `.jsonValues()` entry of `selector` by key: the first source
84
+ * that has an answer, where "the entry is gone" is an answer (a draft that
85
+ * deleted it must not render the published one) and the bundle's import is
86
+ * the last. Loads that entry and no other. `undefined` for an entry that is
87
+ * not there. An entry whose import failed throws, as the import did.
88
+ */
89
+ export declare function resolveValEntry<T extends ResolvableModule>(selector: T, key: string, env: ReadEnv, opts?: Pick<ResolveOptions, "settled">): Resolution<JsonEntryContentOf<T> | undefined>;
90
+ /** {@link resolveValEntry}, for a module (a view resolved). */
91
+ export declare function resolveModuleEntry<V>(module: ValModule<SelectorSource>, key: string, env: ReadEnv, opts?: Pick<ResolveOptions, "settled">): Resolution<V | undefined>;
92
+ /** A resolution's value, mapped; a wait stays the same wait. */
93
+ export declare function mapResolution<T, U>(r: Resolution<T>, f: (value: T) => U): Resolution<U>;
@@ -0,0 +1,63 @@
1
+ import { type Json, type ModuleFilePath } from "@valbuild/core";
2
+ import type { ContentSource, EntryRead } from "@valbuild/shared/internal";
3
+ import type { ValExternalStore } from "./overlayStore.js";
4
+ /**
5
+ * What a module's source says about one of its `.jsonValues()` entries: the
6
+ * same rule for every source that holds a whole module (the overlay, a
7
+ * snapshot). A module that is `null` (a nullable record) has no entries; a
8
+ * key it does not have is GONE -- an answer, not "ask the next one"; an entry
9
+ * that is still a marker is one this source has not loaded, so it passes.
10
+ */
11
+ export declare function entryOfModuleSource(source: Json, key: string, from: string): EntryRead;
12
+ /**
13
+ * A content version's or a proposal's saved Source, for the modules it has
14
+ * (`ValDraft.snapshot`, `snapshotForReaders`): it stands in for the bundle's,
15
+ * draft mode or not. Its entries are content where the proposal saved them.
16
+ */
17
+ export declare function snapshotSource(snapshot: Readonly<Record<ModuleFilePath, Json>> | undefined): ContentSource;
18
+ /** What the page knows about draft mode and the Studio, for {@link overlaySource}. */
19
+ export type OverlayState = {
20
+ /** `null` until `/draft/stat` has answered. */
21
+ draftMode: boolean | null;
22
+ /**
23
+ * Whether a read may wait (`ValProvider`'s `suspend`, once the provider has
24
+ * switched it on). Without it every wait is a `pass`: the next source
25
+ * answers, which is what a page shows until the draft arrives.
26
+ */
27
+ suspend: boolean;
28
+ /** Resolves when `draftMode` stops being unknown. */
29
+ draftModeReady?: Promise<void>;
30
+ /** The Studio has said it sent everything it holds (`sources-synced`). */
31
+ synced: boolean;
32
+ };
33
+ /**
34
+ * What the Studio sent the page (`ValExternalStore`, fed by the relay), with
35
+ * the three waits `suspend` is made of (`architecture/quirks.md`, "`suspend`
36
+ * is three waits") as its states:
37
+ *
38
+ * 1. Draft mode unknown: wait for it to be known (`draftModeReady`), because
39
+ * a read that slips through then is a read of published content, and for
40
+ * a route that only exists in a patch that is a `notFound()` nothing later
41
+ * undoes.
42
+ * 2. Draft mode on, and the Studio has not yet said it sent everything: a
43
+ * module it has not sent may still be coming, so wait for it. After
44
+ * `sources-synced` a module it did not send has no draft: pass.
45
+ * 3. The render that decides is the provider's, which turns `suspend` on
46
+ * after hydrating; until then every wait is a pass.
47
+ *
48
+ * Draft mode off, or no store (a visitor): pass, always.
49
+ */
50
+ export declare function overlaySource(store: ValExternalStore | undefined, state: OverlayState): ContentSource;
51
+ /** How long a failed entry import answers "failed" before it is tried again. */
52
+ export declare const RETRY_FAILED_ENTRY_AFTER_MS = 5000;
53
+ /**
54
+ * The build's own modules: what the code a reader runs was built with. Always
55
+ * the last source, and the only one that never passes on an entry: its
56
+ * entries are its own `import()`s, started when one is first read (never
57
+ * before: a `.jsonValues()` record stays lazy) and kept by build.
58
+ *
59
+ * A module the bundle has passes here: the reader's own selector carries its
60
+ * source, and `stegaEncode` reads it there (and a gallery's from the schema
61
+ * that picks from it), so there is nothing to hand over.
62
+ */
63
+ export declare function bundleSource(modules: ReadonlyMap<ModuleFilePath, unknown>): ContentSource;
@@ -727,4 +727,4 @@ function raw(val) {
727
727
  return val;
728
728
  }
729
729
 
730
- export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, getModuleIds as g, raw as r, stegaDecodeStrings as s };
730
+ export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, _toPropertyKey as d, _defineProperty as e, getModuleIds as g, raw as r, stegaDecodeStrings as s };
@@ -727,4 +727,4 @@ function raw(val) {
727
727
  return val;
728
728
  }
729
729
 
730
- export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, getModuleIds as g, raw as r, stegaDecodeStrings as s };
730
+ export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, _toPropertyKey as d, _defineProperty as e, getModuleIds as g, raw as r, stegaDecodeStrings as s };
@@ -727,4 +727,4 @@ function raw(val) {
727
727
  return val;
728
728
  }
729
729
 
730
- export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, getModuleIds as g, raw as r, stegaDecodeStrings as s };
730
+ export { _objectSpread2 as _, stegaEncode as a, stegaClean as b, attrs as c, _toPropertyKey as d, _defineProperty as e, getModuleIds as g, raw as r, stegaDecodeStrings as s };
@@ -729,7 +729,9 @@ function raw(val) {
729
729
  return val;
730
730
  }
731
731
 
732
+ exports._defineProperty = _defineProperty;
732
733
  exports._objectSpread2 = _objectSpread2;
734
+ exports._toPropertyKey = _toPropertyKey;
733
735
  exports.attrs = attrs;
734
736
  exports.getModuleIds = getModuleIds;
735
737
  exports.raw = raw;
@@ -729,7 +729,9 @@ function raw(val) {
729
729
  return val;
730
730
  }
731
731
 
732
+ exports._defineProperty = _defineProperty;
732
733
  exports._objectSpread2 = _objectSpread2;
734
+ exports._toPropertyKey = _toPropertyKey;
733
735
  exports.attrs = attrs;
734
736
  exports.getModuleIds = getModuleIds;
735
737
  exports.raw = raw;