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