@valbuild/next 0.82.0 → 0.84.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 (30) hide show
  1. package/README.md +11 -4
  2. package/client/dist/valbuild-next-client.cjs.dev.js +1 -1
  3. package/client/dist/valbuild-next-client.cjs.prod.js +1 -1
  4. package/client/dist/valbuild-next-client.esm.js +1 -1
  5. package/dist/{ValNextProvider-5f8b7338.esm.js → ValNextProvider-25f1f5c9.esm.js} +2 -2
  6. package/dist/ValNextProvider-a618d775.cjs.js +7 -0
  7. package/dist/{ValNextProvider-9ff1bb92.cjs.prod.js → ValNextProvider-a618d775.cjs.prod.js} +2 -2
  8. package/dist/{ValNextProvider-99b4552f.cjs.dev.js → ValNextProvider-c7952bdc.cjs.dev.js} +2 -2
  9. package/dist/{ValOverlayContext-a2fdbce0.esm.js → ValOverlayContext-6635a4d7.esm.js} +2 -50
  10. package/dist/ValOverlayContext-942f1294.cjs.js +7 -0
  11. package/dist/{ValOverlayContext-811e9be9.cjs.prod.js → ValOverlayContext-942f1294.cjs.prod.js} +3 -51
  12. package/dist/{ValOverlayContext-55dae3ea.cjs.dev.js → ValOverlayContext-c82a4507.cjs.dev.js} +3 -51
  13. package/dist/createForOfIteratorHelper-0445603c.cjs.dev.js +54 -0
  14. package/dist/createForOfIteratorHelper-5758a730.esm.js +52 -0
  15. package/dist/createForOfIteratorHelper-d4afcad8.cjs.prod.js +54 -0
  16. package/dist/declarations/src/external_exempt_from_val_quickjs.d.ts +1 -0
  17. package/dist/declarations/src/initVal.d.ts +3 -1
  18. package/dist/declarations/src/rsc/initValRsc.d.ts +11 -1
  19. package/dist/typeof-16428c61.cjs.prod.js +13 -0
  20. package/dist/typeof-a1531d8f.esm.js +11 -0
  21. package/dist/typeof-b568f48f.cjs.dev.js +13 -0
  22. package/dist/valbuild-next.cjs.dev.js +6 -13
  23. package/dist/valbuild-next.cjs.prod.js +6 -13
  24. package/dist/valbuild-next.esm.js +5 -12
  25. package/package.json +6 -6
  26. package/rsc/dist/valbuild-next-rsc.cjs.dev.js +248 -36
  27. package/rsc/dist/valbuild-next-rsc.cjs.prod.js +248 -36
  28. package/rsc/dist/valbuild-next-rsc.esm.js +250 -38
  29. package/dist/ValNextProvider-9ff1bb92.cjs.js +0 -7
  30. package/dist/ValOverlayContext-811e9be9.cjs.js +0 -7
@@ -1,11 +1,15 @@
1
1
  import 'server-only';
2
+ import { _ as _createForOfIteratorHelper } from '../../dist/createForOfIteratorHelper-5758a730.esm.js';
2
3
  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';
3
6
  import { _ as _asyncToGenerator, a as _regeneratorRuntime } from '../../dist/asyncToGenerator-5f8c02f3.esm.js';
4
7
  import { SET_RSC, stegaEncode, SET_AUTO_TAG_JSX_ENABLED } from '@valbuild/react/stega';
5
- import { Internal } from '@valbuild/core';
6
- import { VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
8
+ import { Internal, RecordSchema } from '@valbuild/core';
9
+ import { getPatternFromModuleFilePath, parseRoutePattern, getNextAppRouterSourceFolder, VAL_SESSION_COOKIE } from '@valbuild/shared/internal';
7
10
  import { createValServer } from '@valbuild/server';
8
11
  import { V as VERSION } from '../../dist/version-98ec5c7a.esm.js';
12
+ import '../../dist/unsupportedIterableToArray-5baabfdc.esm.js';
9
13
 
10
14
  SET_RSC(true);
11
15
  var initFetchValStega = function initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
@@ -171,6 +175,174 @@ function getHost(headers) {
171
175
  // }
172
176
  // }
173
177
 
178
+ var initFetchValRouteStega = function initFetchValRouteStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies) {
179
+ return /*#__PURE__*/function () {
180
+ 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
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
183
+ while (1) switch (_context2.prev = _context2.next) {
184
+ case 0:
185
+ fetchVal = initFetchValStega(config, valApiEndpoints, valServerPromise, isEnabled, getHeaders, getCookies);
186
+ path = selector && Internal.getValPath(selector);
187
+ if (path) {
188
+ _context2.next = 5;
189
+ break;
190
+ }
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;
195
+ 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
+ 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:
336
+ case "end":
337
+ return _context2.stop();
338
+ }
339
+ }, _callee2);
340
+ }));
341
+ return function (_x, _x2) {
342
+ return _ref2.apply(this, arguments);
343
+ };
344
+ }();
345
+ };
174
346
  var valApiEndpoints = "/api/val";
175
347
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
176
348
  function initValRsc(config, valModules, rscNextConfig) {
@@ -189,22 +361,6 @@ function initValRsc(config, valModules, rscNextConfig) {
189
361
  }
190
362
  }, config), config, {
191
363
  isEnabled: function isEnabled() {
192
- return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
193
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
194
- while (1) switch (_context2.prev = _context2.next) {
195
- case 0:
196
- _context2.next = 2;
197
- return rscNextConfig.draftMode();
198
- case 2:
199
- return _context2.abrupt("return", _context2.sent.isEnabled);
200
- case 3:
201
- case "end":
202
- return _context2.stop();
203
- }
204
- }, _callee2);
205
- }))();
206
- },
207
- onEnable: function onEnable() {
208
364
  return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
209
365
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
210
366
  while (1) switch (_context3.prev = _context3.next) {
@@ -212,7 +368,7 @@ function initValRsc(config, valModules, rscNextConfig) {
212
368
  _context3.next = 2;
213
369
  return rscNextConfig.draftMode();
214
370
  case 2:
215
- _context3.sent.enable();
371
+ return _context3.abrupt("return", _context3.sent.isEnabled);
216
372
  case 3:
217
373
  case "end":
218
374
  return _context3.stop();
@@ -220,7 +376,7 @@ function initValRsc(config, valModules, rscNextConfig) {
220
376
  }, _callee3);
221
377
  }))();
222
378
  },
223
- onDisable: function onDisable() {
379
+ onEnable: function onEnable() {
224
380
  return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
225
381
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
226
382
  while (1) switch (_context4.prev = _context4.next) {
@@ -228,39 +384,42 @@ function initValRsc(config, valModules, rscNextConfig) {
228
384
  _context4.next = 2;
229
385
  return rscNextConfig.draftMode();
230
386
  case 2:
231
- _context4.sent.disable();
387
+ _context4.sent.enable();
232
388
  case 3:
233
389
  case "end":
234
390
  return _context4.stop();
235
391
  }
236
392
  }, _callee4);
237
393
  }))();
394
+ },
395
+ onDisable: function onDisable() {
396
+ return _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
397
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
398
+ while (1) switch (_context5.prev = _context5.next) {
399
+ case 0:
400
+ _context5.next = 2;
401
+ return rscNextConfig.draftMode();
402
+ case 2:
403
+ _context5.sent.disable();
404
+ case 3:
405
+ case "end":
406
+ return _context5.stop();
407
+ }
408
+ }, _callee5);
409
+ }))();
238
410
  }
239
411
  });
240
412
  return {
241
413
  fetchValStega: initFetchValStega(config, valApiEndpoints,
242
414
  // TODO: get from config
243
- valServerPromise, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
244
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
245
- while (1) switch (_context5.prev = _context5.next) {
246
- case 0:
247
- _context5.next = 2;
248
- return rscNextConfig.draftMode();
249
- case 2:
250
- return _context5.abrupt("return", _context5.sent.isEnabled);
251
- case 3:
252
- case "end":
253
- return _context5.stop();
254
- }
255
- }, _callee5);
256
- })), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
415
+ valServerPromise, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
257
416
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
258
417
  while (1) switch (_context6.prev = _context6.next) {
259
418
  case 0:
260
419
  _context6.next = 2;
261
- return rscNextConfig.headers();
420
+ return rscNextConfig.draftMode();
262
421
  case 2:
263
- return _context6.abrupt("return", _context6.sent);
422
+ return _context6.abrupt("return", _context6.sent.isEnabled);
264
423
  case 3:
265
424
  case "end":
266
425
  return _context6.stop();
@@ -271,7 +430,7 @@ function initValRsc(config, valModules, rscNextConfig) {
271
430
  while (1) switch (_context7.prev = _context7.next) {
272
431
  case 0:
273
432
  _context7.next = 2;
274
- return rscNextConfig.cookies();
433
+ return rscNextConfig.headers();
275
434
  case 2:
276
435
  return _context7.abrupt("return", _context7.sent);
277
436
  case 3:
@@ -279,6 +438,59 @@ function initValRsc(config, valModules, rscNextConfig) {
279
438
  return _context7.stop();
280
439
  }
281
440
  }, _callee7);
441
+ })), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
442
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
443
+ while (1) switch (_context8.prev = _context8.next) {
444
+ case 0:
445
+ _context8.next = 2;
446
+ return rscNextConfig.cookies();
447
+ case 2:
448
+ return _context8.abrupt("return", _context8.sent);
449
+ case 3:
450
+ case "end":
451
+ return _context8.stop();
452
+ }
453
+ }, _callee8);
454
+ }))),
455
+ fetchValRouteStega: initFetchValRouteStega(config, valApiEndpoints, valServerPromise, /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
456
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
457
+ while (1) switch (_context9.prev = _context9.next) {
458
+ case 0:
459
+ _context9.next = 2;
460
+ return rscNextConfig.draftMode();
461
+ case 2:
462
+ return _context9.abrupt("return", _context9.sent.isEnabled);
463
+ case 3:
464
+ case "end":
465
+ return _context9.stop();
466
+ }
467
+ }, _callee9);
468
+ })), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
469
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
470
+ while (1) switch (_context10.prev = _context10.next) {
471
+ case 0:
472
+ _context10.next = 2;
473
+ return rscNextConfig.headers();
474
+ case 2:
475
+ return _context10.abrupt("return", _context10.sent);
476
+ case 3:
477
+ case "end":
478
+ return _context10.stop();
479
+ }
480
+ }, _callee10);
481
+ })), /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
482
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
483
+ while (1) switch (_context11.prev = _context11.next) {
484
+ case 0:
485
+ _context11.next = 2;
486
+ return rscNextConfig.cookies();
487
+ case 2:
488
+ return _context11.abrupt("return", _context11.sent);
489
+ case 3:
490
+ case "end":
491
+ return _context11.stop();
492
+ }
493
+ }, _callee11);
282
494
  })))
283
495
  };
284
496
  }
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./ValNextProvider-9ff1bb92.cjs.prod.js");
5
- } else {
6
- module.exports = require("./ValNextProvider-9ff1bb92.cjs.dev.js");
7
- }
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./ValOverlayContext-811e9be9.cjs.prod.js");
5
- } else {
6
- module.exports = require("./ValOverlayContext-811e9be9.cjs.dev.js");
7
- }