@valbuild/next 0.84.0 → 0.84.1

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.
@@ -3,9 +3,17 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('client-only');
6
+ var core = require('@valbuild/core');
6
7
  var stega = require('@valbuild/react/stega');
7
8
  var React = require('react');
8
9
  var ValOverlayContext = require('../../dist/ValOverlayContext-c82a4507.cjs.dev.js');
10
+ var initValRouteFromVal = require('../../dist/initValRouteFromVal-12bdc5f5.cjs.dev.js');
11
+ require('../../dist/createForOfIteratorHelper-0445603c.cjs.dev.js');
12
+ require('../../dist/unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
13
+ require('../../dist/objectSpread2-792eb2c2.cjs.dev.js');
14
+ require('../../dist/slicedToArray-44036a76.cjs.dev.js');
15
+ require('../../dist/typeof-b568f48f.cjs.dev.js');
16
+ require('@valbuild/shared/internal');
9
17
 
10
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
11
19
 
@@ -33,11 +41,27 @@ function useValStega(selector) {
33
41
  }
34
42
  });
35
43
  }
44
+ function useValRouteStega(selector, params) {
45
+ var val = useValStega(selector);
46
+ var resolvedParams = "then" in params ? undefined : params;
47
+ if ("then" in params) {
48
+ if ("use" in React__default["default"]) {
49
+ // This feels fairly safe: use should be possible to use inside if (?) and the if should most likely
50
+ resolvedParams = React__default["default"].use(params);
51
+ } else {
52
+ console.error("Val: useValRoute params argument was promise, but the React.use hook is available. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
53
+ return null;
54
+ }
55
+ }
56
+ var route = initValRouteFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
57
+ return route;
58
+ }
36
59
 
37
60
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
61
  function initValClient(config) {
39
62
  return {
40
- useValStega: useValStega
63
+ useValStega: useValStega,
64
+ useValRouteStega: useValRouteStega
41
65
  };
42
66
  }
43
67
 
@@ -3,9 +3,17 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('client-only');
6
+ var core = require('@valbuild/core');
6
7
  var stega = require('@valbuild/react/stega');
7
8
  var React = require('react');
8
9
  var ValOverlayContext = require('../../dist/ValOverlayContext-942f1294.cjs.prod.js');
10
+ var initValRouteFromVal = require('../../dist/initValRouteFromVal-b9806908.cjs.prod.js');
11
+ require('../../dist/createForOfIteratorHelper-d4afcad8.cjs.prod.js');
12
+ require('../../dist/unsupportedIterableToArray-0d2087a2.cjs.prod.js');
13
+ require('../../dist/objectSpread2-3c87fb4f.cjs.prod.js');
14
+ require('../../dist/slicedToArray-ce613de6.cjs.prod.js');
15
+ require('../../dist/typeof-16428c61.cjs.prod.js');
16
+ require('@valbuild/shared/internal');
9
17
 
10
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
11
19
 
@@ -33,11 +41,27 @@ function useValStega(selector) {
33
41
  }
34
42
  });
35
43
  }
44
+ function useValRouteStega(selector, params) {
45
+ var val = useValStega(selector);
46
+ var resolvedParams = "then" in params ? undefined : params;
47
+ if ("then" in params) {
48
+ if ("use" in React__default["default"]) {
49
+ // This feels fairly safe: use should be possible to use inside if (?) and the if should most likely
50
+ resolvedParams = React__default["default"].use(params);
51
+ } else {
52
+ console.error("Val: useValRoute params argument was promise, but the React.use hook is available. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
53
+ return null;
54
+ }
55
+ }
56
+ var route = initValRouteFromVal.initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && core.Internal.getValPath(selector), selector && core.Internal.getSchema(selector), val);
57
+ return route;
58
+ }
36
59
 
37
60
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
38
61
  function initValClient(config) {
39
62
  return {
40
- useValStega: useValStega
63
+ useValStega: useValStega,
64
+ useValRouteStega: useValRouteStega
41
65
  };
42
66
  }
43
67
 
@@ -1,7 +1,15 @@
1
1
  import 'client-only';
2
+ import { Internal } from '@valbuild/core';
2
3
  import { getModuleIds, stegaEncode } from '@valbuild/react/stega';
3
4
  import React from 'react';
4
5
  import { useValOverlayContext } from '../../dist/ValOverlayContext-6635a4d7.esm.js';
6
+ import { i as initValRouteFromVal } from '../../dist/initValRouteFromVal-d84b3563.esm.js';
7
+ import '../../dist/createForOfIteratorHelper-5758a730.esm.js';
8
+ import '../../dist/unsupportedIterableToArray-5baabfdc.esm.js';
9
+ import '../../dist/objectSpread2-c1340c1c.esm.js';
10
+ import '../../dist/slicedToArray-aa291011.esm.js';
11
+ import '../../dist/typeof-a1531d8f.esm.js';
12
+ import '@valbuild/shared/internal';
5
13
 
6
14
  function useValStega(selector) {
7
15
  var valOverlayContext = useValOverlayContext();
@@ -25,11 +33,27 @@ function useValStega(selector) {
25
33
  }
26
34
  });
27
35
  }
36
+ function useValRouteStega(selector, params) {
37
+ var val = useValStega(selector);
38
+ var resolvedParams = "then" in params ? undefined : params;
39
+ if ("then" in params) {
40
+ if ("use" in React) {
41
+ // This feels fairly safe: use should be possible to use inside if (?) and the if should most likely
42
+ resolvedParams = React.use(params);
43
+ } else {
44
+ console.error("Val: useValRoute params argument was promise, but the React.use hook is available. Please resolve the promise before passing it to useValRoute (or upgrade to React 19+).");
45
+ return null;
46
+ }
47
+ }
48
+ var route = initValRouteFromVal(resolvedParams || {}, "useValRoute", selector && Internal.getValPath(selector), selector && Internal.getSchema(selector), val);
49
+ return route;
50
+ }
28
51
 
29
52
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
53
  function initValClient(config) {
31
54
  return {
32
- useValStega: useValStega
55
+ useValStega: useValStega,
56
+ useValRouteStega: useValRouteStega
33
57
  };
34
58
  }
35
59
 
@@ -1,9 +1,12 @@
1
- import { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
1
+ import { GenericSelector, SelectorOf, SelectorSource, SourceObject, ValModule } from "@valbuild/core";
2
2
  import { StegaOfSource } from "@valbuild/react/stega";
3
3
  import { ValConfig } from "@valbuild/core";
4
4
  export type UseValType<T extends SelectorSource> = SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never;
5
5
  declare function useValStega<T extends SelectorSource>(selector: T): UseValType<T>;
6
+ type UseValRouteReturnType<T extends ValModule<GenericSelector<SourceObject>>> = T extends ValModule<infer S> ? S extends SourceObject ? StegaOfSource<NonNullable<S>[string]> | null : never : never;
7
+ declare function useValRouteStega<T extends ValModule<GenericSelector<SourceObject>>>(selector: T, params: Record<string, string | string[]> | Promise<Record<string, string | string[]>>): UseValRouteReturnType<T>;
6
8
  export declare function initValClient(config: ValConfig): {
7
9
  useValStega: typeof useValStega;
10
+ useValRouteStega: typeof useValRouteStega;
8
11
  };
9
12
  export {};
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ var createForOfIteratorHelper = require('./createForOfIteratorHelper-0445603c.cjs.dev.js');
4
+ var objectSpread2 = require('./objectSpread2-792eb2c2.cjs.dev.js');
5
+ var slicedToArray = require('./slicedToArray-44036a76.cjs.dev.js');
6
+ var _typeof = require('./typeof-b568f48f.cjs.dev.js');
7
+ var core = require('@valbuild/core');
8
+ var internal = require('@valbuild/shared/internal');
9
+
10
+ function initValRouteFromVal(resolvedParams, methodName,
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ path,
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ schema,
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ val) {
17
+ if (!path) {
18
+ console.error("Val: ".concat(methodName, " can only be used with a Val module (details: no Val path found)."));
19
+ return null;
20
+ }
21
+ if (val === null) {
22
+ return null;
23
+ }
24
+ if (_typeof._typeof(val) !== "object") {
25
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ").concat(_typeof._typeof(val), " instead)."));
26
+ return null;
27
+ }
28
+ if (Array.isArray(val)) {
29
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead)."));
30
+ return null;
31
+ }
32
+ if (!schema) {
33
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: no schema found)."));
34
+ return null;
35
+ }
36
+ if (!(schema instanceof core.RecordSchema)) {
37
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: schema is not a record)."));
38
+ } else if (!schema["currentRouter"]) {
39
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not set)."));
40
+ } else if (schema["currentRouter"].getRouterId() !== core.Internal.nextAppRouter.getRouterId()) {
41
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not the Next.js App Router)."));
42
+ return null;
43
+ }
44
+ if (_typeof._typeof(resolvedParams) !== "object") {
45
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: params is not an object)."));
46
+ return null;
47
+ }
48
+ var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(path),
49
+ _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 1),
50
+ moduleFilePath = _Internal$splitModule2[0];
51
+ if (!(moduleFilePath.endsWith("page.val.ts") || moduleFilePath.endsWith("page.val.js"))) {
52
+ console.error("Val: ".concat(methodName, " is used with a Val module that does not have a page.val.ts or page.val.js file. Make sure the Val module is in the same directory as your page.tsx or page.js file."));
53
+ return null;
54
+ }
55
+ var srcFolder = internal.getNextAppRouterSourceFolder(moduleFilePath);
56
+ if (!srcFolder) {
57
+ console.error("Val: ".concat(methodName, " was used with a Val module that is not in the /app or /src/app folder"));
58
+ return null;
59
+ }
60
+ var pattern = internal.getPatternFromModuleFilePath(moduleFilePath, srcFolder);
61
+ var parsedPattern = internal.parseRoutePattern(pattern);
62
+ var missingPatterns = [];
63
+ var fullPathParts = [];
64
+ var missingParamKeys = objectSpread2._objectSpread2({}, resolvedParams);
65
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []),
66
+ _step;
67
+ try {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
+ var part = _step.value;
70
+ if (part.type === "literal") {
71
+ fullPathParts.push(part.name);
72
+ } else if (part.type === "array-param" || part.type === "string-param") {
73
+ var value = resolvedParams[part.paramName];
74
+ if (typeof value !== "string" && !Array.isArray(value)) {
75
+ missingPatterns.push(part);
76
+ } else if (Array.isArray(value)) {
77
+ delete missingParamKeys[part.paramName];
78
+ fullPathParts.push(value.join("/"));
79
+ } else {
80
+ delete missingParamKeys[part.paramName];
81
+ fullPathParts.push(value);
82
+ }
83
+ }
84
+ }
85
+ } catch (err) {
86
+ _iterator.e(err);
87
+ } finally {
88
+ _iterator.f();
89
+ }
90
+ if (missingPatterns.length > 0) {
91
+ var errorMessageParams = missingPatterns.map(function (part) {
92
+ if (part.type === "literal") {
93
+ return part.name;
94
+ } else if (part.type === "string-param") {
95
+ return "[".concat(part.paramName, "]");
96
+ } else if (part.type === "array-param") {
97
+ return "[...".concat(part.paramName, "]");
98
+ }
99
+ });
100
+ console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is in the same directory as your page.tsx or page.js file and that the Val module filename is called page.val.ts or page.val.js."));
101
+ return null;
102
+ }
103
+ if (Object.keys(missingParamKeys).length > 0) {
104
+ console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " in the same directory as your page.tsx or page.js file."));
105
+ // We do not return null here since we found a route that matches the path
106
+ // though chances are that there's something wrong in the way ${methodName} is used
107
+ }
108
+ var fullPath = fullPathParts.join("/");
109
+ var actualRoute = val["/".concat(fullPath)];
110
+ if (!actualRoute) {
111
+ return null;
112
+ }
113
+ return actualRoute;
114
+ }
115
+
116
+ exports.initValRouteFromVal = initValRouteFromVal;
@@ -0,0 +1,116 @@
1
+ 'use strict';
2
+
3
+ var createForOfIteratorHelper = require('./createForOfIteratorHelper-d4afcad8.cjs.prod.js');
4
+ var objectSpread2 = require('./objectSpread2-3c87fb4f.cjs.prod.js');
5
+ var slicedToArray = require('./slicedToArray-ce613de6.cjs.prod.js');
6
+ var _typeof = require('./typeof-16428c61.cjs.prod.js');
7
+ var core = require('@valbuild/core');
8
+ var internal = require('@valbuild/shared/internal');
9
+
10
+ function initValRouteFromVal(resolvedParams, methodName,
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ path,
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ schema,
15
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
+ val) {
17
+ if (!path) {
18
+ console.error("Val: ".concat(methodName, " can only be used with a Val module (details: no Val path found)."));
19
+ return null;
20
+ }
21
+ if (val === null) {
22
+ return null;
23
+ }
24
+ if (_typeof._typeof(val) !== "object") {
25
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ").concat(_typeof._typeof(val), " instead)."));
26
+ return null;
27
+ }
28
+ if (Array.isArray(val)) {
29
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead)."));
30
+ return null;
31
+ }
32
+ if (!schema) {
33
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: no schema found)."));
34
+ return null;
35
+ }
36
+ if (!(schema instanceof core.RecordSchema)) {
37
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: schema is not a record)."));
38
+ } else if (!schema["currentRouter"]) {
39
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not set)."));
40
+ } else if (schema["currentRouter"].getRouterId() !== core.Internal.nextAppRouter.getRouterId()) {
41
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not the Next.js App Router)."));
42
+ return null;
43
+ }
44
+ if (_typeof._typeof(resolvedParams) !== "object") {
45
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: params is not an object)."));
46
+ return null;
47
+ }
48
+ var _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(path),
49
+ _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 1),
50
+ moduleFilePath = _Internal$splitModule2[0];
51
+ if (!(moduleFilePath.endsWith("page.val.ts") || moduleFilePath.endsWith("page.val.js"))) {
52
+ console.error("Val: ".concat(methodName, " is used with a Val module that does not have a page.val.ts or page.val.js file. Make sure the Val module is in the same directory as your page.tsx or page.js file."));
53
+ return null;
54
+ }
55
+ var srcFolder = internal.getNextAppRouterSourceFolder(moduleFilePath);
56
+ if (!srcFolder) {
57
+ console.error("Val: ".concat(methodName, " was used with a Val module that is not in the /app or /src/app folder"));
58
+ return null;
59
+ }
60
+ var pattern = internal.getPatternFromModuleFilePath(moduleFilePath, srcFolder);
61
+ var parsedPattern = internal.parseRoutePattern(pattern);
62
+ var missingPatterns = [];
63
+ var fullPathParts = [];
64
+ var missingParamKeys = objectSpread2._objectSpread2({}, resolvedParams);
65
+ var _iterator = createForOfIteratorHelper._createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []),
66
+ _step;
67
+ try {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
+ var part = _step.value;
70
+ if (part.type === "literal") {
71
+ fullPathParts.push(part.name);
72
+ } else if (part.type === "array-param" || part.type === "string-param") {
73
+ var value = resolvedParams[part.paramName];
74
+ if (typeof value !== "string" && !Array.isArray(value)) {
75
+ missingPatterns.push(part);
76
+ } else if (Array.isArray(value)) {
77
+ delete missingParamKeys[part.paramName];
78
+ fullPathParts.push(value.join("/"));
79
+ } else {
80
+ delete missingParamKeys[part.paramName];
81
+ fullPathParts.push(value);
82
+ }
83
+ }
84
+ }
85
+ } catch (err) {
86
+ _iterator.e(err);
87
+ } finally {
88
+ _iterator.f();
89
+ }
90
+ if (missingPatterns.length > 0) {
91
+ var errorMessageParams = missingPatterns.map(function (part) {
92
+ if (part.type === "literal") {
93
+ return part.name;
94
+ } else if (part.type === "string-param") {
95
+ return "[".concat(part.paramName, "]");
96
+ } else if (part.type === "array-param") {
97
+ return "[...".concat(part.paramName, "]");
98
+ }
99
+ });
100
+ console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is in the same directory as your page.tsx or page.js file and that the Val module filename is called page.val.ts or page.val.js."));
101
+ return null;
102
+ }
103
+ if (Object.keys(missingParamKeys).length > 0) {
104
+ console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " in the same directory as your page.tsx or page.js file."));
105
+ // We do not return null here since we found a route that matches the path
106
+ // though chances are that there's something wrong in the way ${methodName} is used
107
+ }
108
+ var fullPath = fullPathParts.join("/");
109
+ var actualRoute = val["/".concat(fullPath)];
110
+ if (!actualRoute) {
111
+ return null;
112
+ }
113
+ return actualRoute;
114
+ }
115
+
116
+ exports.initValRouteFromVal = initValRouteFromVal;
@@ -0,0 +1,114 @@
1
+ import { _ as _createForOfIteratorHelper } from './createForOfIteratorHelper-5758a730.esm.js';
2
+ import { _ as _objectSpread2 } from './objectSpread2-c1340c1c.esm.js';
3
+ import { _ as _slicedToArray } from './slicedToArray-aa291011.esm.js';
4
+ import { _ as _typeof } from './typeof-a1531d8f.esm.js';
5
+ import { RecordSchema, Internal } from '@valbuild/core';
6
+ import { getNextAppRouterSourceFolder, getPatternFromModuleFilePath, parseRoutePattern } from '@valbuild/shared/internal';
7
+
8
+ function initValRouteFromVal(resolvedParams, methodName,
9
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
10
+ path,
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ schema,
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ val) {
15
+ if (!path) {
16
+ console.error("Val: ".concat(methodName, " can only be used with a Val module (details: no Val path found)."));
17
+ return null;
18
+ }
19
+ if (val === null) {
20
+ return null;
21
+ }
22
+ if (_typeof(val) !== "object") {
23
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ").concat(_typeof(val), " instead)."));
24
+ return null;
25
+ }
26
+ if (Array.isArray(val)) {
27
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead)."));
28
+ return null;
29
+ }
30
+ if (!schema) {
31
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: no schema found)."));
32
+ return null;
33
+ }
34
+ if (!(schema instanceof RecordSchema)) {
35
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: schema is not a record)."));
36
+ } else if (!schema["currentRouter"]) {
37
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not set)."));
38
+ } else if (schema["currentRouter"].getRouterId() !== Internal.nextAppRouter.getRouterId()) {
39
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: router is not the Next.js App Router)."));
40
+ return null;
41
+ }
42
+ if (_typeof(resolvedParams) !== "object") {
43
+ console.error("Val: ".concat(methodName, " must be used with a Val Module that is a s.record().router(...) (details: params is not an object)."));
44
+ return null;
45
+ }
46
+ var _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(path),
47
+ _Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 1),
48
+ moduleFilePath = _Internal$splitModule2[0];
49
+ if (!(moduleFilePath.endsWith("page.val.ts") || moduleFilePath.endsWith("page.val.js"))) {
50
+ console.error("Val: ".concat(methodName, " is used with a Val module that does not have a page.val.ts or page.val.js file. Make sure the Val module is in the same directory as your page.tsx or page.js file."));
51
+ return null;
52
+ }
53
+ var srcFolder = getNextAppRouterSourceFolder(moduleFilePath);
54
+ if (!srcFolder) {
55
+ console.error("Val: ".concat(methodName, " was used with a Val module that is not in the /app or /src/app folder"));
56
+ return null;
57
+ }
58
+ var pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
59
+ var parsedPattern = parseRoutePattern(pattern);
60
+ var missingPatterns = [];
61
+ var fullPathParts = [];
62
+ var missingParamKeys = _objectSpread2({}, resolvedParams);
63
+ var _iterator = _createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []),
64
+ _step;
65
+ try {
66
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
67
+ var part = _step.value;
68
+ if (part.type === "literal") {
69
+ fullPathParts.push(part.name);
70
+ } else if (part.type === "array-param" || part.type === "string-param") {
71
+ var value = resolvedParams[part.paramName];
72
+ if (typeof value !== "string" && !Array.isArray(value)) {
73
+ missingPatterns.push(part);
74
+ } else if (Array.isArray(value)) {
75
+ delete missingParamKeys[part.paramName];
76
+ fullPathParts.push(value.join("/"));
77
+ } else {
78
+ delete missingParamKeys[part.paramName];
79
+ fullPathParts.push(value);
80
+ }
81
+ }
82
+ }
83
+ } catch (err) {
84
+ _iterator.e(err);
85
+ } finally {
86
+ _iterator.f();
87
+ }
88
+ if (missingPatterns.length > 0) {
89
+ var errorMessageParams = missingPatterns.map(function (part) {
90
+ if (part.type === "literal") {
91
+ return part.name;
92
+ } else if (part.type === "string-param") {
93
+ return "[".concat(part.paramName, "]");
94
+ } else if (part.type === "array-param") {
95
+ return "[...".concat(part.paramName, "]");
96
+ }
97
+ });
98
+ console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is in the same directory as your page.tsx or page.js file and that the Val module filename is called page.val.ts or page.val.js."));
99
+ return null;
100
+ }
101
+ if (Object.keys(missingParamKeys).length > 0) {
102
+ console.error("Val: ".concat(methodName, " could not find route since parameters: ").concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " in the same directory as your page.tsx or page.js file."));
103
+ // We do not return null here since we found a route that matches the path
104
+ // though chances are that there's something wrong in the way ${methodName} is used
105
+ }
106
+ var fullPath = fullPathParts.join("/");
107
+ var actualRoute = val["/".concat(fullPath)];
108
+ if (!actualRoute) {
109
+ return null;
110
+ }
111
+ return actualRoute;
112
+ }
113
+
114
+ export { initValRouteFromVal as i };
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "next",
9
9
  "react"
10
10
  ],
11
- "version": "0.84.0",
11
+ "version": "0.84.1",
12
12
  "scripts": {
13
13
  "typecheck": "tsc --noEmit",
14
14
  "test": "jest"
@@ -45,11 +45,11 @@
45
45
  "exports": true
46
46
  },
47
47
  "dependencies": {
48
- "@valbuild/core": "~0.84.0",
49
- "@valbuild/react": "~0.84.0",
50
- "@valbuild/server": "~0.84.0",
51
- "@valbuild/shared": "~0.84.0",
52
- "@valbuild/ui": "~0.84.0",
48
+ "@valbuild/core": "~0.84.1",
49
+ "@valbuild/react": "~0.84.1",
50
+ "@valbuild/server": "~0.84.1",
51
+ "@valbuild/shared": "~0.84.1",
52
+ "@valbuild/ui": "~0.84.1",
53
53
  "client-only": "^0.0.1",
54
54
  "server-only": "^0.0.1"
55
55
  },
@@ -3,17 +3,18 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('server-only');
6
- var createForOfIteratorHelper = require('../../dist/createForOfIteratorHelper-0445603c.cjs.dev.js');
7
6
  var objectSpread2 = require('../../dist/objectSpread2-792eb2c2.cjs.dev.js');
8
- var slicedToArray = require('../../dist/slicedToArray-44036a76.cjs.dev.js');
9
- var _typeof = require('../../dist/typeof-b568f48f.cjs.dev.js');
10
7
  var asyncToGenerator = require('../../dist/asyncToGenerator-6ba61221.cjs.dev.js');
11
8
  var stega = require('@valbuild/react/stega');
12
9
  var core = require('@valbuild/core');
13
10
  var internal = require('@valbuild/shared/internal');
14
11
  var server = require('@valbuild/server');
15
12
  var version = require('../../dist/version-82faa1d0.cjs.dev.js');
13
+ var initValRouteFromVal = require('../../dist/initValRouteFromVal-12bdc5f5.cjs.dev.js');
14
+ require('../../dist/createForOfIteratorHelper-0445603c.cjs.dev.js');
16
15
  require('../../dist/unsupportedIterableToArray-c8ab77c9.cjs.dev.js');
16
+ require('../../dist/slicedToArray-44036a76.cjs.dev.js');
17
+ require('../../dist/typeof-b568f48f.cjs.dev.js');
17
18
 
18
19
  stega.SET_RSC(true);
19
20
  var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
@@ -182,161 +183,31 @@ function getHost(headers) {
182
183
  var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
183
184
  return /*#__PURE__*/function () {
184
185
  var _ref2 = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee2(selector, params) {
185
- var fetchVal, path, val, schema, resolvedParams, _Internal$splitModule, _Internal$splitModule2, moduleFilePath, srcFolder, pattern, parsedPattern, missingPatterns, fullPathParts, missingParamKeys, _iterator, _step, part, value, errorMessageParams, fullPath, actualRoute;
186
+ var fetchVal, resolvedParams, path, schema, val, route;
186
187
  return asyncToGenerator._regeneratorRuntime().wrap(function _callee2$(_context2) {
187
188
  while (1) switch (_context2.prev = _context2.next) {
188
189
  case 0:
189
190
  fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies);
191
+ _context2.next = 3;
192
+ return Promise.resolve(params);
193
+ case 3:
194
+ resolvedParams = _context2.sent;
190
195
  path = selector && core.Internal.getValPath(selector);
191
- if (path) {
192
- _context2.next = 5;
196
+ schema = selector && core.Internal.getSchema(selector);
197
+ _context2.t0 = selector;
198
+ if (!_context2.t0) {
199
+ _context2.next = 11;
193
200
  break;
194
201
  }
195
- console.error("Val: fetchValRoute can only be used with a Val module (details: no Val path found).");
196
- return _context2.abrupt("return", null);
197
- case 5:
198
- _context2.next = 7;
202
+ _context2.next = 10;
199
203
  return fetchVal(selector);
200
- case 7:
201
- val = _context2.sent;
202
- if (!(val === null)) {
203
- _context2.next = 10;
204
- break;
205
- }
206
- return _context2.abrupt("return", null);
207
204
  case 10:
208
- if (!(_typeof._typeof(val) !== "object")) {
209
- _context2.next = 13;
210
- break;
211
- }
212
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ".concat(_typeof._typeof(val), " instead)."));
213
- return _context2.abrupt("return", null);
214
- case 13:
215
- if (!Array.isArray(val)) {
216
- _context2.next = 16;
217
- break;
218
- }
219
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead).");
220
- return _context2.abrupt("return", null);
221
- case 16:
222
- schema = core.Internal.getSchema(selector);
223
- if (schema) {
224
- _context2.next = 20;
225
- break;
226
- }
227
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: no schema found).");
228
- return _context2.abrupt("return", null);
229
- case 20:
230
- if (schema instanceof core.RecordSchema) {
231
- _context2.next = 24;
232
- break;
233
- }
234
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: schema is not a record).");
235
- _context2.next = 31;
236
- break;
237
- case 24:
238
- if (schema["currentRouter"]) {
239
- _context2.next = 28;
240
- break;
241
- }
242
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: router is not set).");
243
- _context2.next = 31;
244
- break;
245
- case 28:
246
- if (!(schema["currentRouter"].getRouterId() !== core.Internal.nextAppRouter.getRouterId())) {
247
- _context2.next = 31;
248
- break;
249
- }
250
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: router is not the Next.js App Router).");
251
- return _context2.abrupt("return", null);
252
- case 31:
253
- _context2.next = 33;
254
- return Promise.resolve(params);
255
- case 33:
256
- resolvedParams = _context2.sent;
257
- if (!(_typeof._typeof(resolvedParams) !== "object")) {
258
- _context2.next = 37;
259
- break;
260
- }
261
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: params is not an object).");
262
- return _context2.abrupt("return", null);
263
- case 37:
264
- _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(path), _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 1), moduleFilePath = _Internal$splitModule2[0];
265
- if (moduleFilePath.endsWith("page.val.ts") || moduleFilePath.endsWith("page.val.js")) {
266
- _context2.next = 41;
267
- break;
268
- }
269
- console.error("Val: fetchValRoute is used with a Val module that does not have a page.val.ts or page.val.js file. Make sure the Val module is in the same directory as your page.tsx or page.js file.");
270
- return _context2.abrupt("return", null);
271
- case 41:
272
- srcFolder = internal.getNextAppRouterSourceFolder(moduleFilePath);
273
- if (srcFolder) {
274
- _context2.next = 45;
275
- break;
276
- }
277
- console.error("Val: fetchValRoute was used with a Val module that is not in the /app or /src/app folder");
278
- return _context2.abrupt("return", null);
279
- case 45:
280
- pattern = internal.getPatternFromModuleFilePath(moduleFilePath, srcFolder);
281
- parsedPattern = internal.parseRoutePattern(pattern);
282
- missingPatterns = [];
283
- fullPathParts = [];
284
- missingParamKeys = objectSpread2._objectSpread2({}, resolvedParams);
285
- _iterator = createForOfIteratorHelper._createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []);
286
- try {
287
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
288
- part = _step.value;
289
- if (part.type === "literal") {
290
- fullPathParts.push(part.name);
291
- } else if (part.type === "array-param" || part.type === "string-param") {
292
- value = resolvedParams[part.paramName];
293
- if (typeof value !== "string" && !Array.isArray(value)) {
294
- missingPatterns.push(part);
295
- } else if (Array.isArray(value)) {
296
- delete missingParamKeys[part.paramName];
297
- fullPathParts.push(value.join("/"));
298
- } else {
299
- delete missingParamKeys[part.paramName];
300
- fullPathParts.push(value);
301
- }
302
- }
303
- }
304
- } catch (err) {
305
- _iterator.e(err);
306
- } finally {
307
- _iterator.f();
308
- }
309
- if (!(missingPatterns.length > 0)) {
310
- _context2.next = 56;
311
- break;
312
- }
313
- errorMessageParams = missingPatterns.map(function (part) {
314
- if (part.type === "literal") {
315
- return part.name;
316
- } else if (part.type === "string-param") {
317
- return "[".concat(part.paramName, "]");
318
- } else if (part.type === "array-param") {
319
- return "[...".concat(part.paramName, "]");
320
- }
321
- });
322
- console.error("Val: fetchValRoute could not find route since parameters: ".concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is in the same directory as your page.tsx or page.js file and that the Val module filename is called page.val.ts or page.val.js."));
323
- return _context2.abrupt("return", null);
324
- case 56:
325
- if (Object.keys(missingParamKeys).length > 0) {
326
- console.error("Val: fetchValRoute could not find route since parameters: ".concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " in the same directory as your page.tsx or page.js file."));
327
- // We do not return null here since we found a route that matches the path
328
- // though chances are that there's something wrong in the way fetchValRoute is used
329
- }
330
- fullPath = fullPathParts.join("/");
331
- actualRoute = val["/".concat(fullPath)];
332
- if (actualRoute) {
333
- _context2.next = 61;
334
- break;
335
- }
336
- return _context2.abrupt("return", null);
337
- case 61:
338
- return _context2.abrupt("return", actualRoute);
339
- case 62:
205
+ _context2.t0 = _context2.sent;
206
+ case 11:
207
+ val = _context2.t0;
208
+ route = initValRouteFromVal.initValRouteFromVal(resolvedParams, "fetchValRoute", path, schema, val);
209
+ return _context2.abrupt("return", route);
210
+ case 14:
340
211
  case "end":
341
212
  return _context2.stop();
342
213
  }
@@ -3,17 +3,18 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('server-only');
6
- var createForOfIteratorHelper = require('../../dist/createForOfIteratorHelper-d4afcad8.cjs.prod.js');
7
6
  var objectSpread2 = require('../../dist/objectSpread2-3c87fb4f.cjs.prod.js');
8
- var slicedToArray = require('../../dist/slicedToArray-ce613de6.cjs.prod.js');
9
- var _typeof = require('../../dist/typeof-16428c61.cjs.prod.js');
10
7
  var asyncToGenerator = require('../../dist/asyncToGenerator-67a5ff70.cjs.prod.js');
11
8
  var stega = require('@valbuild/react/stega');
12
9
  var core = require('@valbuild/core');
13
10
  var internal = require('@valbuild/shared/internal');
14
11
  var server = require('@valbuild/server');
15
12
  var version = require('../../dist/version-a9a6a619.cjs.prod.js');
13
+ var initValRouteFromVal = require('../../dist/initValRouteFromVal-b9806908.cjs.prod.js');
14
+ require('../../dist/createForOfIteratorHelper-d4afcad8.cjs.prod.js');
16
15
  require('../../dist/unsupportedIterableToArray-0d2087a2.cjs.prod.js');
16
+ require('../../dist/slicedToArray-ce613de6.cjs.prod.js');
17
+ require('../../dist/typeof-16428c61.cjs.prod.js');
17
18
 
18
19
  stega.SET_RSC(true);
19
20
  var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
@@ -182,161 +183,31 @@ function getHost(headers) {
182
183
  var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
183
184
  return /*#__PURE__*/function () {
184
185
  var _ref2 = asyncToGenerator._asyncToGenerator(/*#__PURE__*/asyncToGenerator._regeneratorRuntime().mark(function _callee2(selector, params) {
185
- var fetchVal, path, val, schema, resolvedParams, _Internal$splitModule, _Internal$splitModule2, moduleFilePath, srcFolder, pattern, parsedPattern, missingPatterns, fullPathParts, missingParamKeys, _iterator, _step, part, value, errorMessageParams, fullPath, actualRoute;
186
+ var fetchVal, resolvedParams, path, schema, val, route;
186
187
  return asyncToGenerator._regeneratorRuntime().wrap(function _callee2$(_context2) {
187
188
  while (1) switch (_context2.prev = _context2.next) {
188
189
  case 0:
189
190
  fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies);
191
+ _context2.next = 3;
192
+ return Promise.resolve(params);
193
+ case 3:
194
+ resolvedParams = _context2.sent;
190
195
  path = selector && core.Internal.getValPath(selector);
191
- if (path) {
192
- _context2.next = 5;
196
+ schema = selector && core.Internal.getSchema(selector);
197
+ _context2.t0 = selector;
198
+ if (!_context2.t0) {
199
+ _context2.next = 11;
193
200
  break;
194
201
  }
195
- console.error("Val: fetchValRoute can only be used with a Val module (details: no Val path found).");
196
- return _context2.abrupt("return", null);
197
- case 5:
198
- _context2.next = 7;
202
+ _context2.next = 10;
199
203
  return fetchVal(selector);
200
- case 7:
201
- val = _context2.sent;
202
- if (!(val === null)) {
203
- _context2.next = 10;
204
- break;
205
- }
206
- return _context2.abrupt("return", null);
207
204
  case 10:
208
- if (!(_typeof._typeof(val) !== "object")) {
209
- _context2.next = 13;
210
- break;
211
- }
212
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ".concat(_typeof._typeof(val), " instead)."));
213
- return _context2.abrupt("return", null);
214
- case 13:
215
- if (!Array.isArray(val)) {
216
- _context2.next = 16;
217
- break;
218
- }
219
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead).");
220
- return _context2.abrupt("return", null);
221
- case 16:
222
- schema = core.Internal.getSchema(selector);
223
- if (schema) {
224
- _context2.next = 20;
225
- break;
226
- }
227
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: no schema found).");
228
- return _context2.abrupt("return", null);
229
- case 20:
230
- if (schema instanceof core.RecordSchema) {
231
- _context2.next = 24;
232
- break;
233
- }
234
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: schema is not a record).");
235
- _context2.next = 31;
236
- break;
237
- case 24:
238
- if (schema["currentRouter"]) {
239
- _context2.next = 28;
240
- break;
241
- }
242
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: router is not set).");
243
- _context2.next = 31;
244
- break;
245
- case 28:
246
- if (!(schema["currentRouter"].getRouterId() !== core.Internal.nextAppRouter.getRouterId())) {
247
- _context2.next = 31;
248
- break;
249
- }
250
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: router is not the Next.js App Router).");
251
- return _context2.abrupt("return", null);
252
- case 31:
253
- _context2.next = 33;
254
- return Promise.resolve(params);
255
- case 33:
256
- resolvedParams = _context2.sent;
257
- if (!(_typeof._typeof(resolvedParams) !== "object")) {
258
- _context2.next = 37;
259
- break;
260
- }
261
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: params is not an object).");
262
- return _context2.abrupt("return", null);
263
- case 37:
264
- _Internal$splitModule = core.Internal.splitModuleFilePathAndModulePath(path), _Internal$splitModule2 = slicedToArray._slicedToArray(_Internal$splitModule, 1), moduleFilePath = _Internal$splitModule2[0];
265
- if (moduleFilePath.endsWith("page.val.ts") || moduleFilePath.endsWith("page.val.js")) {
266
- _context2.next = 41;
267
- break;
268
- }
269
- console.error("Val: fetchValRoute is used with a Val module that does not have a page.val.ts or page.val.js file. Make sure the Val module is in the same directory as your page.tsx or page.js file.");
270
- return _context2.abrupt("return", null);
271
- case 41:
272
- srcFolder = internal.getNextAppRouterSourceFolder(moduleFilePath);
273
- if (srcFolder) {
274
- _context2.next = 45;
275
- break;
276
- }
277
- console.error("Val: fetchValRoute was used with a Val module that is not in the /app or /src/app folder");
278
- return _context2.abrupt("return", null);
279
- case 45:
280
- pattern = internal.getPatternFromModuleFilePath(moduleFilePath, srcFolder);
281
- parsedPattern = internal.parseRoutePattern(pattern);
282
- missingPatterns = [];
283
- fullPathParts = [];
284
- missingParamKeys = objectSpread2._objectSpread2({}, resolvedParams);
285
- _iterator = createForOfIteratorHelper._createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []);
286
- try {
287
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
288
- part = _step.value;
289
- if (part.type === "literal") {
290
- fullPathParts.push(part.name);
291
- } else if (part.type === "array-param" || part.type === "string-param") {
292
- value = resolvedParams[part.paramName];
293
- if (typeof value !== "string" && !Array.isArray(value)) {
294
- missingPatterns.push(part);
295
- } else if (Array.isArray(value)) {
296
- delete missingParamKeys[part.paramName];
297
- fullPathParts.push(value.join("/"));
298
- } else {
299
- delete missingParamKeys[part.paramName];
300
- fullPathParts.push(value);
301
- }
302
- }
303
- }
304
- } catch (err) {
305
- _iterator.e(err);
306
- } finally {
307
- _iterator.f();
308
- }
309
- if (!(missingPatterns.length > 0)) {
310
- _context2.next = 56;
311
- break;
312
- }
313
- errorMessageParams = missingPatterns.map(function (part) {
314
- if (part.type === "literal") {
315
- return part.name;
316
- } else if (part.type === "string-param") {
317
- return "[".concat(part.paramName, "]");
318
- } else if (part.type === "array-param") {
319
- return "[...".concat(part.paramName, "]");
320
- }
321
- });
322
- console.error("Val: fetchValRoute could not find route since parameters: ".concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is in the same directory as your page.tsx or page.js file and that the Val module filename is called page.val.ts or page.val.js."));
323
- return _context2.abrupt("return", null);
324
- case 56:
325
- if (Object.keys(missingParamKeys).length > 0) {
326
- console.error("Val: fetchValRoute could not find route since parameters: ".concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " in the same directory as your page.tsx or page.js file."));
327
- // We do not return null here since we found a route that matches the path
328
- // though chances are that there's something wrong in the way fetchValRoute is used
329
- }
330
- fullPath = fullPathParts.join("/");
331
- actualRoute = val["/".concat(fullPath)];
332
- if (actualRoute) {
333
- _context2.next = 61;
334
- break;
335
- }
336
- return _context2.abrupt("return", null);
337
- case 61:
338
- return _context2.abrupt("return", actualRoute);
339
- case 62:
205
+ _context2.t0 = _context2.sent;
206
+ case 11:
207
+ val = _context2.t0;
208
+ route = initValRouteFromVal.initValRouteFromVal(resolvedParams, "fetchValRoute", path, schema, val);
209
+ return _context2.abrupt("return", route);
210
+ case 14:
340
211
  case "end":
341
212
  return _context2.stop();
342
213
  }
@@ -1,15 +1,16 @@
1
1
  import 'server-only';
2
- import { _ as _createForOfIteratorHelper } from '../../dist/createForOfIteratorHelper-5758a730.esm.js';
3
2
  import { _ as _objectSpread2, a as _defineProperty } from '../../dist/objectSpread2-c1340c1c.esm.js';
4
- import { _ as _slicedToArray } from '../../dist/slicedToArray-aa291011.esm.js';
5
- import { _ as _typeof } from '../../dist/typeof-a1531d8f.esm.js';
6
3
  import { _ as _asyncToGenerator, a as _regeneratorRuntime } from '../../dist/asyncToGenerator-5f8c02f3.esm.js';
7
4
  import { SET_RSC, stegaEncode, SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
8
- import { Internal, RecordSchema } from '@valbuild/core';
9
- import { getPatternFromModuleFilePath, parseRoutePattern, getNextAppRouterSourceFolder, VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
5
+ import { Internal } from '@valbuild/core';
6
+ import { VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
10
7
  import { createValServer } from '@valbuild/server';
11
8
  import { V as VERSION } from '../../dist/version-98ec5c7a.esm.js';
9
+ import { i as initValRouteFromVal } from '../../dist/initValRouteFromVal-d84b3563.esm.js';
10
+ import '../../dist/createForOfIteratorHelper-5758a730.esm.js';
12
11
  import '../../dist/unsupportedIterableToArray-5baabfdc.esm.js';
12
+ import '../../dist/slicedToArray-aa291011.esm.js';
13
+ import '../../dist/typeof-a1531d8f.esm.js';
13
14
 
14
15
  SET_RSC(true);
15
16
  var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
@@ -178,161 +179,31 @@ function getHost(headers) {
178
179
  var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
179
180
  return /*#__PURE__*/function () {
180
181
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(selector, params) {
181
- var fetchVal, path, val, schema, resolvedParams, _Internal$splitModule, _Internal$splitModule2, moduleFilePath, srcFolder, pattern, parsedPattern, missingPatterns, fullPathParts, missingParamKeys, _iterator, _step, part, value, errorMessageParams, fullPath, actualRoute;
182
+ var fetchVal, resolvedParams, path, schema, val, route;
182
183
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
183
184
  while (1) switch (_context2.prev = _context2.next) {
184
185
  case 0:
185
186
  fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies);
187
+ _context2.next = 3;
188
+ return Promise.resolve(params);
189
+ case 3:
190
+ resolvedParams = _context2.sent;
186
191
  path = selector && Internal.getValPath(selector);
187
- if (path) {
188
- _context2.next = 5;
192
+ schema = selector && Internal.getSchema(selector);
193
+ _context2.t0 = selector;
194
+ if (!_context2.t0) {
195
+ _context2.next = 11;
189
196
  break;
190
197
  }
191
- console.error("Val: fetchValRoute can only be used with a Val module (details: no Val path found).");
192
- return _context2.abrupt("return", null);
193
- case 5:
194
- _context2.next = 7;
198
+ _context2.next = 10;
195
199
  return fetchVal(selector);
196
- case 7:
197
- val = _context2.sent;
198
- if (!(val === null)) {
199
- _context2.next = 10;
200
- break;
201
- }
202
- return _context2.abrupt("return", null);
203
200
  case 10:
204
- if (!(_typeof(val) !== "object")) {
205
- _context2.next = 13;
206
- break;
207
- }
208
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: expected type object, found ".concat(_typeof(val), " instead)."));
209
- return _context2.abrupt("return", null);
210
- case 13:
211
- if (!Array.isArray(val)) {
212
- _context2.next = 16;
213
- break;
214
- }
215
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: expected type object, found array instead).");
216
- return _context2.abrupt("return", null);
217
- case 16:
218
- schema = Internal.getSchema(selector);
219
- if (schema) {
220
- _context2.next = 20;
221
- break;
222
- }
223
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: no schema found).");
224
- return _context2.abrupt("return", null);
225
- case 20:
226
- if (schema instanceof RecordSchema) {
227
- _context2.next = 24;
228
- break;
229
- }
230
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: schema is not a record).");
231
- _context2.next = 31;
232
- break;
233
- case 24:
234
- if (schema["currentRouter"]) {
235
- _context2.next = 28;
236
- break;
237
- }
238
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: router is not set).");
239
- _context2.next = 31;
240
- break;
241
- case 28:
242
- if (!(schema["currentRouter"].getRouterId() !== Internal.nextAppRouter.getRouterId())) {
243
- _context2.next = 31;
244
- break;
245
- }
246
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: router is not the Next.js App Router).");
247
- return _context2.abrupt("return", null);
248
- case 31:
249
- _context2.next = 33;
250
- return Promise.resolve(params);
251
- case 33:
252
- resolvedParams = _context2.sent;
253
- if (!(_typeof(resolvedParams) !== "object")) {
254
- _context2.next = 37;
255
- break;
256
- }
257
- console.error("Val: fetchValRoute must be used with a Val Module that is a s.record().router(...) (details: params is not an object).");
258
- return _context2.abrupt("return", null);
259
- case 37:
260
- _Internal$splitModule = Internal.splitModuleFilePathAndModulePath(path), _Internal$splitModule2 = _slicedToArray(_Internal$splitModule, 1), moduleFilePath = _Internal$splitModule2[0];
261
- if (moduleFilePath.endsWith("page.val.ts") || moduleFilePath.endsWith("page.val.js")) {
262
- _context2.next = 41;
263
- break;
264
- }
265
- console.error("Val: fetchValRoute is used with a Val module that does not have a page.val.ts or page.val.js file. Make sure the Val module is in the same directory as your page.tsx or page.js file.");
266
- return _context2.abrupt("return", null);
267
- case 41:
268
- srcFolder = getNextAppRouterSourceFolder(moduleFilePath);
269
- if (srcFolder) {
270
- _context2.next = 45;
271
- break;
272
- }
273
- console.error("Val: fetchValRoute was used with a Val module that is not in the /app or /src/app folder");
274
- return _context2.abrupt("return", null);
275
- case 45:
276
- pattern = getPatternFromModuleFilePath(moduleFilePath, srcFolder);
277
- parsedPattern = parseRoutePattern(pattern);
278
- missingPatterns = [];
279
- fullPathParts = [];
280
- missingParamKeys = _objectSpread2({}, resolvedParams);
281
- _iterator = _createForOfIteratorHelper(parsedPattern !== null && parsedPattern !== void 0 ? parsedPattern : []);
282
- try {
283
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
284
- part = _step.value;
285
- if (part.type === "literal") {
286
- fullPathParts.push(part.name);
287
- } else if (part.type === "array-param" || part.type === "string-param") {
288
- value = resolvedParams[part.paramName];
289
- if (typeof value !== "string" && !Array.isArray(value)) {
290
- missingPatterns.push(part);
291
- } else if (Array.isArray(value)) {
292
- delete missingParamKeys[part.paramName];
293
- fullPathParts.push(value.join("/"));
294
- } else {
295
- delete missingParamKeys[part.paramName];
296
- fullPathParts.push(value);
297
- }
298
- }
299
- }
300
- } catch (err) {
301
- _iterator.e(err);
302
- } finally {
303
- _iterator.f();
304
- }
305
- if (!(missingPatterns.length > 0)) {
306
- _context2.next = 56;
307
- break;
308
- }
309
- errorMessageParams = missingPatterns.map(function (part) {
310
- if (part.type === "literal") {
311
- return part.name;
312
- } else if (part.type === "string-param") {
313
- return "[".concat(part.paramName, "]");
314
- } else if (part.type === "array-param") {
315
- return "[...".concat(part.paramName, "]");
316
- }
317
- });
318
- console.error("Val: fetchValRoute could not find route since parameters: ".concat(errorMessageParams.join(", "), " where not provided. Make sure the Val module is in the same directory as your page.tsx or page.js file and that the Val module filename is called page.val.ts or page.val.js."));
319
- return _context2.abrupt("return", null);
320
- case 56:
321
- if (Object.keys(missingParamKeys).length > 0) {
322
- console.error("Val: fetchValRoute could not find route since parameters: ".concat(Object.keys(missingParamKeys).join(", "), " where not found in the path of: ").concat(moduleFilePath, ". Make sure ").concat(moduleFilePath, " in the same directory as your page.tsx or page.js file."));
323
- // We do not return null here since we found a route that matches the path
324
- // though chances are that there's something wrong in the way fetchValRoute is used
325
- }
326
- fullPath = fullPathParts.join("/");
327
- actualRoute = val["/".concat(fullPath)];
328
- if (actualRoute) {
329
- _context2.next = 61;
330
- break;
331
- }
332
- return _context2.abrupt("return", null);
333
- case 61:
334
- return _context2.abrupt("return", actualRoute);
335
- case 62:
201
+ _context2.t0 = _context2.sent;
202
+ case 11:
203
+ val = _context2.t0;
204
+ route = initValRouteFromVal(resolvedParams, "fetchValRoute", path, schema, val);
205
+ return _context2.abrupt("return", route);
206
+ case 14:
336
207
  case "end":
337
208
  return _context2.stop();
338
209
  }