elegance-js 1.11.25 → 1.11.27

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.
package/dist/build.mjs CHANGED
@@ -534,7 +534,7 @@ var generateClientPageData = async (pageLocation, state, objectAttributes, pageL
534
534
  fs.writeFileSync(pageDataPath, transformedResult.code, "utf-8");
535
535
  return { sendHardReloadInstruction };
536
536
  };
537
- var buildDynamicPage = async (filePath, DIST_DIR, req) => {
537
+ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
538
538
  let pageElements;
539
539
  let metadata;
540
540
  initializeState();
@@ -552,7 +552,17 @@ var buildDynamicPage = async (filePath, DIST_DIR, req) => {
552
552
  requestHook
553
553
  } = construct();
554
554
  if (typeof requestHook === "function") {
555
- requestHook(req);
555
+ if (requestHook.constructor.name === "AsyncFunction") {
556
+ const doProcessRequest = await requestHook(req, res);
557
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
558
+ return false;
559
+ }
560
+ } else {
561
+ const doProcessRequest = requestHook(req, res);
562
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
563
+ return false;
564
+ }
565
+ }
556
566
  }
557
567
  pageElements = page;
558
568
  metadata = pageMetadata;
@@ -752,7 +762,10 @@ async function handleStaticRequest(root, pathname, req, res, DIST_DIR) {
752
762
  }
753
763
  if (isDynamic) {
754
764
  try {
755
- const resultHTML = await buildDynamicPage(resolve(handlerPath), DIST_DIR, req2);
765
+ const resultHTML = await buildDynamicPage(resolve(handlerPath), DIST_DIR, req2, res2);
766
+ if (resultHTML === false) {
767
+ return;
768
+ }
756
769
  res2.writeHead(200, { "Content-Type": MIME_TYPES[".html"] });
757
770
  res2.end(resultHTML);
758
771
  } catch (err) {
@@ -325,8 +325,12 @@ var loadPage = (deprecatedKeys = [], newBreakpoints) => {
325
325
  }
326
326
  const loadHooks = pageData.lh;
327
327
  for (const loadHook of loadHooks || []) {
328
- const bind = loadHook.bind;
329
- if (bind !== void 0 && newBreakpoints && !newBreakpoints.includes(`${bind}`)) {
328
+ const bind = loadHook.bind ?? "";
329
+ if (
330
+ // generateClientPageData makes undefined binds into empty strings
331
+ // so that the page_data.js is *smaller*
332
+ bind !== "" && newBreakpoints && !newBreakpoints.includes(`${bind}`)
333
+ ) {
330
334
  continue;
331
335
  }
332
336
  const fn = loadHook.fn;
@@ -537,7 +537,7 @@ var generateClientPageData = async (pageLocation, state, objectAttributes, pageL
537
537
  fs.writeFileSync(pageDataPath, transformedResult.code, "utf-8");
538
538
  return { sendHardReloadInstruction };
539
539
  };
540
- var buildDynamicPage = async (filePath, DIST_DIR, req) => {
540
+ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
541
541
  let pageElements;
542
542
  let metadata;
543
543
  initializeState();
@@ -555,7 +555,17 @@ var buildDynamicPage = async (filePath, DIST_DIR, req) => {
555
555
  requestHook
556
556
  } = construct();
557
557
  if (typeof requestHook === "function") {
558
- requestHook(req);
558
+ if (requestHook.constructor.name === "AsyncFunction") {
559
+ const doProcessRequest = await requestHook(req, res);
560
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
561
+ return false;
562
+ }
563
+ } else {
564
+ const doProcessRequest = requestHook(req, res);
565
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
566
+ return false;
567
+ }
568
+ }
559
569
  }
560
570
  pageElements = page;
561
571
  metadata = pageMetadata;
@@ -755,7 +765,10 @@ async function handleStaticRequest(root, pathname, req, res, DIST_DIR) {
755
765
  }
756
766
  if (isDynamic) {
757
767
  try {
758
- const resultHTML = await buildDynamicPage(resolve(handlerPath), DIST_DIR, req2);
768
+ const resultHTML = await buildDynamicPage(resolve(handlerPath), DIST_DIR, req2, res2);
769
+ if (resultHTML === false) {
770
+ return;
771
+ }
759
772
  res2.writeHead(200, { "Content-Type": MIME_TYPES[".html"] });
760
773
  res2.end(resultHTML);
761
774
  } catch (err) {
@@ -1,2 +1,2 @@
1
1
  export declare const processPageElements: (element: Child, objectAttributes: Array<any>, parent: Child) => Child;
2
- export declare const buildDynamicPage: (filePath: string, DIST_DIR: string, req: any) => Promise<string>;
2
+ export declare const buildDynamicPage: (filePath: string, DIST_DIR: string, req: any, res: any) => Promise<string | false>;
@@ -490,7 +490,7 @@ var generateClientPageData = async (pageLocation, state, objectAttributes, pageL
490
490
  fs.writeFileSync(pageDataPath, transformedResult.code, "utf-8");
491
491
  return { sendHardReloadInstruction };
492
492
  };
493
- var buildDynamicPage = async (filePath, DIST_DIR, req) => {
493
+ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
494
494
  let pageElements;
495
495
  let metadata;
496
496
  initializeState();
@@ -508,7 +508,17 @@ var buildDynamicPage = async (filePath, DIST_DIR, req) => {
508
508
  requestHook
509
509
  } = construct();
510
510
  if (typeof requestHook === "function") {
511
- requestHook(req);
511
+ if (requestHook.constructor.name === "AsyncFunction") {
512
+ const doProcessRequest = await requestHook(req, res);
513
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
514
+ return false;
515
+ }
516
+ } else {
517
+ const doProcessRequest = requestHook(req, res);
518
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
519
+ return false;
520
+ }
521
+ }
512
522
  }
513
523
  pageElements = page;
514
524
  metadata = pageMetadata;
@@ -20,7 +20,7 @@ export type LoadHook = {
20
20
  bind: number | string;
21
21
  };
22
22
  export type ClientLoadHook = {
23
- bind: number;
23
+ bind: string;
24
24
  fn: (state: State) => (void | (() => void) | Promise<(void | (() => void))>);
25
25
  };
26
26
  export declare const resetLoadHooks: () => never[];
@@ -490,7 +490,7 @@ var generateClientPageData = async (pageLocation, state, objectAttributes, pageL
490
490
  fs.writeFileSync(pageDataPath, transformedResult.code, "utf-8");
491
491
  return { sendHardReloadInstruction };
492
492
  };
493
- var buildDynamicPage = async (filePath, DIST_DIR, req) => {
493
+ var buildDynamicPage = async (filePath, DIST_DIR, req, res) => {
494
494
  let pageElements;
495
495
  let metadata;
496
496
  initializeState();
@@ -508,7 +508,17 @@ var buildDynamicPage = async (filePath, DIST_DIR, req) => {
508
508
  requestHook
509
509
  } = construct();
510
510
  if (typeof requestHook === "function") {
511
- requestHook(req);
511
+ if (requestHook.constructor.name === "AsyncFunction") {
512
+ const doProcessRequest = await requestHook(req, res);
513
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
514
+ return false;
515
+ }
516
+ } else {
517
+ const doProcessRequest = requestHook(req, res);
518
+ if (doProcessRequest !== void 0 == doProcessRequest === false) {
519
+ return false;
520
+ }
521
+ }
512
522
  }
513
523
  pageElements = page;
514
524
  metadata = pageMetadata;
@@ -744,7 +754,10 @@ async function handleStaticRequest(root, pathname, req, res, DIST_DIR) {
744
754
  }
745
755
  if (isDynamic) {
746
756
  try {
747
- const resultHTML = await buildDynamicPage(resolve(handlerPath), DIST_DIR, req2);
757
+ const resultHTML = await buildDynamicPage(resolve(handlerPath), DIST_DIR, req2, res2);
758
+ if (resultHTML === false) {
759
+ return;
760
+ }
748
761
  res2.writeHead(200, { "Content-Type": MIME_TYPES[".html"] });
749
762
  res2.end(resultHTML);
750
763
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elegance-js",
3
- "version": "1.11.25",
3
+ "version": "1.11.27",
4
4
  "description": "Web-Framework",
5
5
  "type": "module",
6
6
  "bin": {