@valbuild/tanstack 0.144.11 → 0.145.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.
@@ -1,4 +1,4 @@
1
- import { a as _slicedToArray, _ as _objectSpread2, b as _createForOfIteratorHelper } from './createForOfIteratorHelper-93a62170.esm.js';
1
+ import { _ as _objectSpread2, a as _slicedToArray, b as _createForOfIteratorHelper } from './createForOfIteratorHelper-93a62170.esm.js';
2
2
  import { RecordSchema, Internal } from '@valbuild/core';
3
3
  import { getTanStackRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern } from '@valbuild/shared/client';
4
4
 
@@ -21,6 +21,116 @@ function isJsonValuesRecordSchema(schema) {
21
21
  return schema instanceof RecordSchema && schema["executeSerialize"]().jsonValues === true;
22
22
  }
23
23
 
24
+ /**
25
+ * A whole `.jsonValues()` record, as `useVal` and `fetchVal` read it: with
26
+ * every entry's content. In the record's own source each entry is a lazy
27
+ * `c.json(() => import(...))` marker, so a reader that encodes that source
28
+ * renders every entry empty. (`useValKey` and `fetchValKey` read one entry,
29
+ * and load only that one.)
30
+ *
31
+ * `sourcesOf(modulePath)` are what the reader has before the bundle, the first
32
+ * that has the record winning: a draft view, then a snapshot (a proposal's saves, or the
33
+ * content version the site serves). An entry that is still a marker there is
34
+ * taken from a later source that has its content; the rest are named in
35
+ * `load`, for the reader to load from the bundle by key and hand to
36
+ * {@link fillJsonValuesRecord}.
37
+ *
38
+ * `null` when the selector is not a `.jsonValues()` module, or its record is
39
+ * not an object (a nullable record that is null): there is nothing to fill.
40
+ */
41
+ function jsonValuesRecordToFill(
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ selector, sourcesOf) {
44
+ // Untyped, as `getJsonEntryStegaRoot`'s selector is: a module or a view of
45
+ // one, whichever source type it was defined with.
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ var module = Internal.resolveViewedModule(selector);
48
+ if (!module || !isJsonValuesRecordSchema(Internal.getSchema(module))) {
49
+ return null;
50
+ }
51
+ var modulePath = Internal.getValPath(module);
52
+ if (!modulePath) {
53
+ return null;
54
+ }
55
+ var sources = sourcesOf(modulePath);
56
+ var isRecord = function isRecord(value) {
57
+ return _typeof(value) === "object" && value !== null && !Array.isArray(value);
58
+ };
59
+ var chosen = sources.find(function (source) {
60
+ return source !== undefined;
61
+ });
62
+ var base = chosen !== undefined ? chosen : Internal.getSource(module);
63
+ if (!isRecord(base)) {
64
+ return null;
65
+ }
66
+ var record = {};
67
+ var load = [];
68
+ var _loop = function _loop() {
69
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
70
+ key = _Object$entries$_i[0],
71
+ entry = _Object$entries$_i[1];
72
+ if (!Internal.isJson(entry)) {
73
+ record[key] = entry;
74
+ return 1; // continue
75
+ }
76
+ var later = sources.slice(sources.indexOf(chosen) + 1).map(function (source) {
77
+ return isRecord(source) && Object.prototype.hasOwnProperty.call(source, key) ? source[key] : undefined;
78
+ }).find(function (content) {
79
+ return content !== undefined && !Internal.isJson(content);
80
+ });
81
+ if (later !== undefined) {
82
+ record[key] = later;
83
+ } else {
84
+ // Left as the marker until it is loaded: see `fillJsonValuesRecord`.
85
+ record[key] = entry;
86
+ load.push(key);
87
+ }
88
+ };
89
+ for (var _i = 0, _Object$entries = Object.entries(base); _i < _Object$entries.length; _i++) {
90
+ if (_loop()) continue;
91
+ }
92
+ return {
93
+ modulePath: modulePath,
94
+ module: module,
95
+ record: record,
96
+ load: load
97
+ };
98
+ }
99
+
100
+ /**
101
+ * The record from {@link jsonValuesRecordToFill}, with the entries it named in
102
+ * `load` put in: `loaded[key]`, as the bundle's import of that entry gave it.
103
+ * An entry the bundle has no import for keeps its marker.
104
+ */
105
+ function fillJsonValuesRecord(record, loaded) {
106
+ var filled = _objectSpread2({}, record);
107
+ for (var _i2 = 0, _Object$entries2 = Object.entries(loaded); _i2 < _Object$entries2.length; _i2++) {
108
+ var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
109
+ key = _Object$entries2$_i[0],
110
+ content = _Object$entries2$_i[1];
111
+ if (content !== undefined) {
112
+ filled[key] = content;
113
+ }
114
+ }
115
+ return filled;
116
+ }
117
+
118
+ /**
119
+ * The bundle's import of one `.jsonValues()` entry, started: `undefined` when
120
+ * the module's own source has no marker for `key` to import from.
121
+ */
122
+ function bundledJsonEntryImport(
123
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
124
+ module, key) {
125
+ var _Internal$getJsonImpo;
126
+ var source = module && Internal.getSource(module);
127
+ var marker = _typeof(source) === "object" && source !== null && !Array.isArray(source) ? source[key] : undefined;
128
+ if (!Internal.isJson(marker)) {
129
+ return undefined;
130
+ }
131
+ return (_Internal$getJsonImpo = Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
132
+ }
133
+
24
134
  /**
25
135
  * Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
26
136
  * strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
@@ -209,4 +319,4 @@ val) {
209
319
  return actualRoute;
210
320
  }
211
321
 
212
- export { _typeof as _, getValRouteUrlFromVal as a, initValRouteFromVal as b, getJsonEntryStegaRoot as g, isJsonValuesRecordSchema as i };
322
+ export { _typeof as _, getValRouteUrlFromVal as a, bundledJsonEntryImport as b, initValRouteFromVal as c, fillJsonValuesRecord as f, getJsonEntryStegaRoot as g, isJsonValuesRecordSchema as i, jsonValuesRecordToFill as j };
@@ -23,6 +23,116 @@ function isJsonValuesRecordSchema(schema) {
23
23
  return schema instanceof core.RecordSchema && schema["executeSerialize"]().jsonValues === true;
24
24
  }
25
25
 
26
+ /**
27
+ * A whole `.jsonValues()` record, as `useVal` and `fetchVal` read it: with
28
+ * every entry's content. In the record's own source each entry is a lazy
29
+ * `c.json(() => import(...))` marker, so a reader that encodes that source
30
+ * renders every entry empty. (`useValKey` and `fetchValKey` read one entry,
31
+ * and load only that one.)
32
+ *
33
+ * `sourcesOf(modulePath)` are what the reader has before the bundle, the first
34
+ * that has the record winning: a draft view, then a snapshot (a proposal's saves, or the
35
+ * content version the site serves). An entry that is still a marker there is
36
+ * taken from a later source that has its content; the rest are named in
37
+ * `load`, for the reader to load from the bundle by key and hand to
38
+ * {@link fillJsonValuesRecord}.
39
+ *
40
+ * `null` when the selector is not a `.jsonValues()` module, or its record is
41
+ * not an object (a nullable record that is null): there is nothing to fill.
42
+ */
43
+ function jsonValuesRecordToFill(
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
+ selector, sourcesOf) {
46
+ // Untyped, as `getJsonEntryStegaRoot`'s selector is: a module or a view of
47
+ // one, whichever source type it was defined with.
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ var module = core.Internal.resolveViewedModule(selector);
50
+ if (!module || !isJsonValuesRecordSchema(core.Internal.getSchema(module))) {
51
+ return null;
52
+ }
53
+ var modulePath = core.Internal.getValPath(module);
54
+ if (!modulePath) {
55
+ return null;
56
+ }
57
+ var sources = sourcesOf(modulePath);
58
+ var isRecord = function isRecord(value) {
59
+ return _typeof(value) === "object" && value !== null && !Array.isArray(value);
60
+ };
61
+ var chosen = sources.find(function (source) {
62
+ return source !== undefined;
63
+ });
64
+ var base = chosen !== undefined ? chosen : core.Internal.getSource(module);
65
+ if (!isRecord(base)) {
66
+ return null;
67
+ }
68
+ var record = {};
69
+ var load = [];
70
+ var _loop = function _loop() {
71
+ var _Object$entries$_i = createForOfIteratorHelper._slicedToArray(_Object$entries[_i], 2),
72
+ key = _Object$entries$_i[0],
73
+ entry = _Object$entries$_i[1];
74
+ if (!core.Internal.isJson(entry)) {
75
+ record[key] = entry;
76
+ return 1; // continue
77
+ }
78
+ var later = sources.slice(sources.indexOf(chosen) + 1).map(function (source) {
79
+ return isRecord(source) && Object.prototype.hasOwnProperty.call(source, key) ? source[key] : undefined;
80
+ }).find(function (content) {
81
+ return content !== undefined && !core.Internal.isJson(content);
82
+ });
83
+ if (later !== undefined) {
84
+ record[key] = later;
85
+ } else {
86
+ // Left as the marker until it is loaded: see `fillJsonValuesRecord`.
87
+ record[key] = entry;
88
+ load.push(key);
89
+ }
90
+ };
91
+ for (var _i = 0, _Object$entries = Object.entries(base); _i < _Object$entries.length; _i++) {
92
+ if (_loop()) continue;
93
+ }
94
+ return {
95
+ modulePath: modulePath,
96
+ module: module,
97
+ record: record,
98
+ load: load
99
+ };
100
+ }
101
+
102
+ /**
103
+ * The record from {@link jsonValuesRecordToFill}, with the entries it named in
104
+ * `load` put in: `loaded[key]`, as the bundle's import of that entry gave it.
105
+ * An entry the bundle has no import for keeps its marker.
106
+ */
107
+ function fillJsonValuesRecord(record, loaded) {
108
+ var filled = createForOfIteratorHelper._objectSpread2({}, record);
109
+ for (var _i2 = 0, _Object$entries2 = Object.entries(loaded); _i2 < _Object$entries2.length; _i2++) {
110
+ var _Object$entries2$_i = createForOfIteratorHelper._slicedToArray(_Object$entries2[_i2], 2),
111
+ key = _Object$entries2$_i[0],
112
+ content = _Object$entries2$_i[1];
113
+ if (content !== undefined) {
114
+ filled[key] = content;
115
+ }
116
+ }
117
+ return filled;
118
+ }
119
+
120
+ /**
121
+ * The bundle's import of one `.jsonValues()` entry, started: `undefined` when
122
+ * the module's own source has no marker for `key` to import from.
123
+ */
124
+ function bundledJsonEntryImport(
125
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
126
+ module, key) {
127
+ var _Internal$getJsonImpo;
128
+ var source = module && core.Internal.getSource(module);
129
+ var marker = _typeof(source) === "object" && source !== null && !Array.isArray(source) ? source[key] : undefined;
130
+ if (!core.Internal.isJson(marker)) {
131
+ return undefined;
132
+ }
133
+ return (_Internal$getJsonImpo = core.Internal.getJsonImport(marker)) !== null && _Internal$getJsonImpo !== void 0 ? _Internal$getJsonImpo : undefined;
134
+ }
135
+
26
136
  /**
27
137
  * Builds the `stegaEncode` `root` seed for a single `.jsonValues()` entry, so its
28
138
  * strings get edit tags. Without a seed, `stegaEncode` on raw entry content is an
@@ -212,7 +322,10 @@ val) {
212
322
  }
213
323
 
214
324
  exports._typeof = _typeof;
325
+ exports.bundledJsonEntryImport = bundledJsonEntryImport;
326
+ exports.fillJsonValuesRecord = fillJsonValuesRecord;
215
327
  exports.getJsonEntryStegaRoot = getJsonEntryStegaRoot;
216
328
  exports.getValRouteUrlFromVal = getValRouteUrlFromVal;
217
329
  exports.initValRouteFromVal = initValRouteFromVal;
218
330
  exports.isJsonValuesRecordSchema = isJsonValuesRecordSchema;
331
+ exports.jsonValuesRecordToFill = jsonValuesRecordToFill;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('./version-c09cd870.cjs.dev.js');
5
+ var version = require('./version-a177607f.cjs.dev.js');
6
6
  var createForOfIteratorHelper = require('./createForOfIteratorHelper-4497beef.cjs.dev.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = require('./version-4c9ab17f.cjs.prod.js');
5
+ var version = require('./version-84946815.cjs.prod.js');
6
6
  var createForOfIteratorHelper = require('./createForOfIteratorHelper-9afd7d2d.cjs.prod.js');
7
7
  var core = require('@valbuild/core');
8
8
  var stega = require('@valbuild/react/stega');
@@ -1,4 +1,4 @@
1
- import { _ as _asyncToGenerator, a as _regenerator, r as readValEnableCookie, V as VERSION$1 } from './version-e2b90a42.esm.js';
1
+ import { _ as _asyncToGenerator, a as _regenerator, r as readValEnableCookie, V as VERSION$1 } from './version-763a3e86.esm.js';
2
2
  import { _ as _objectSpread2, a as _slicedToArray, b as _createForOfIteratorHelper } from './createForOfIteratorHelper-93a62170.esm.js';
3
3
  import { Internal as Internal$1, initVal as initVal$1, DEFAULT_CONTENT_HOST } from '@valbuild/core';
4
4
  import * as core from '@valbuild/core';
@@ -210,7 +210,7 @@ var packageJson = {
210
210
  "tanstack-router",
211
211
  "react"
212
212
  ],
213
- version: "0.144.11",
213
+ version: "0.145.0",
214
214
  scripts: {
215
215
  typecheck: "tsc --noEmit",
216
216
  test: "jest"
@@ -212,7 +212,7 @@ var packageJson = {
212
212
  "tanstack-router",
213
213
  "react"
214
214
  ],
215
- version: "0.144.11",
215
+ version: "0.145.0",
216
216
  scripts: {
217
217
  typecheck: "tsc --noEmit",
218
218
  test: "jest"
@@ -212,7 +212,7 @@ var packageJson = {
212
212
  "tanstack-router",
213
213
  "react"
214
214
  ],
215
- version: "0.144.11",
215
+ version: "0.145.0",
216
216
  scripts: {
217
217
  typecheck: "tsc --noEmit",
218
218
  test: "jest"
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "tanstack-router",
15
15
  "react"
16
16
  ],
17
- "version": "0.144.11",
17
+ "version": "0.145.0",
18
18
  "main": "dist/valbuild-tanstack.cjs.js",
19
19
  "module": "dist/valbuild-tanstack.esm.js",
20
20
  "exports": {
@@ -42,13 +42,13 @@
42
42
  "exports": true
43
43
  },
44
44
  "dependencies": {
45
- "@valbuild/core": "0.144.0",
46
- "@valbuild/language-server": "0.144.11",
47
- "@valbuild/mcp": "0.144.11",
48
- "@valbuild/react": "0.144.11",
49
- "@valbuild/server": "0.144.11",
50
- "@valbuild/shared": "0.144.9",
51
- "@valbuild/ui": "0.144.11"
45
+ "@valbuild/core": "0.145.0",
46
+ "@valbuild/language-server": "0.145.0",
47
+ "@valbuild/mcp": "0.145.0",
48
+ "@valbuild/react": "0.145.0",
49
+ "@valbuild/server": "0.145.0",
50
+ "@valbuild/shared": "0.145.0",
51
+ "@valbuild/ui": "0.145.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@tanstack/react-router": "^1.170.41",