@loadbare/app 0.5.6 → 0.6.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 (81) hide show
  1. package/README.md +3 -4
  2. package/dist/build/assemble.d.ts +1 -1
  3. package/dist/build/assemble.d.ts.map +1 -1
  4. package/dist/build/assemble.js +80 -7
  5. package/dist/build/cli.d.ts +2 -2
  6. package/dist/build/cli.js +2 -2
  7. package/dist/build/expand.d.ts.map +1 -1
  8. package/dist/build/expand.js +19 -32
  9. package/dist/build/locations.d.ts +3 -3
  10. package/dist/build/locations.d.ts.map +1 -1
  11. package/dist/build/locations.js +15 -3
  12. package/dist/build/origins.d.ts +0 -13
  13. package/dist/build/origins.d.ts.map +1 -1
  14. package/dist/build/origins.js +32 -8
  15. package/dist/build/pages.d.ts +3 -3
  16. package/dist/build/pages.d.ts.map +1 -1
  17. package/dist/build/pages.js +9 -7
  18. package/dist/core/lb-constants.d.ts +15 -13
  19. package/dist/core/lb-constants.d.ts.map +1 -1
  20. package/dist/core/lb-constants.js +103 -53
  21. package/dist/core/lb-types.d.ts +103 -62
  22. package/dist/core/lb-types.d.ts.map +1 -1
  23. package/dist/core/lb-types.js +11 -3
  24. package/dist/hub/lb-apply.d.ts +18 -4
  25. package/dist/hub/lb-apply.d.ts.map +1 -1
  26. package/dist/hub/lb-apply.js +184 -34
  27. package/dist/hub/lb-hub.browser.d.ts +1 -1
  28. package/dist/hub/lb-hub.browser.d.ts.map +1 -1
  29. package/dist/hub/lb-hub.browser.js +131 -84
  30. package/dist/server/lb-express.d.ts +7 -4
  31. package/dist/server/lb-express.d.ts.map +1 -1
  32. package/dist/server/lb-express.js +45 -33
  33. package/dist/server/lb-server.d.ts +67 -45
  34. package/dist/server/lb-server.d.ts.map +1 -1
  35. package/dist/server/lb-server.js +55 -18
  36. package/dist/tests/assemble.test.js +154 -2
  37. package/dist/tests/expand.test.js +6 -3
  38. package/dist/tests/helpers/hub.d.ts +73 -0
  39. package/dist/tests/helpers/hub.d.ts.map +1 -0
  40. package/dist/tests/helpers/hub.js +151 -0
  41. package/dist/tests/lb-apply.test.js +86 -62
  42. package/dist/tests/lb-express.test.d.ts +1 -1
  43. package/dist/tests/lb-express.test.js +43 -38
  44. package/dist/tests/lb-hub.test.d.ts +14 -0
  45. package/dist/tests/lb-hub.test.d.ts.map +1 -0
  46. package/dist/tests/lb-hub.test.js +319 -0
  47. package/dist/tests/{lb-rows.test.d.ts → lb-list.test.d.ts} +1 -1
  48. package/dist/tests/lb-list.test.d.ts.map +1 -0
  49. package/dist/tests/{lb-rows.test.js → lb-list.test.js} +109 -106
  50. package/dist/tests/lb-server.test.js +151 -100
  51. package/dist/tests/origins.test.js +19 -1
  52. package/dist/tests/pages.test.d.ts +1 -1
  53. package/dist/tests/pages.test.js +64 -14
  54. package/docs/TECHREF-1.0.md +1000 -0
  55. package/docs/reference/builder.md +4 -4
  56. package/docs/reference/chrome.md +10 -9
  57. package/docs/reference/custom-elements.md +51 -36
  58. package/docs/reference/data-binding.md +141 -88
  59. package/docs/reference/overview.md +1 -1
  60. package/docs/reference/page-files.md +64 -49
  61. package/docs/reference/server.md +7 -6
  62. package/docs/reference/widgets.md +22 -30
  63. package/docs/roadmap.md +68 -22
  64. package/docs/testing.md +47 -17
  65. package/docs/theory.md +2 -2
  66. package/docs/tutorials/010-pages-and-navigation.md +8 -8
  67. package/docs/tutorials/040-displaying-data.md +9 -9
  68. package/docs/tutorials/050-actions.md +5 -5
  69. package/docs/tutorials/060-custom-element-code.md +1 -1
  70. package/docs/tutorials/065-conditional-rendering.md +4 -4
  71. package/docs/tutorials/070-displaying-a-list.md +24 -47
  72. package/docs/tutorials/072-inserting-into-a-list.md +17 -17
  73. package/docs/tutorials/074-deleting-from-a-list.md +15 -17
  74. package/docs/tutorials/076-updating-a-list-item.md +20 -22
  75. package/docs/tutorials/080-widget-requests.md +27 -23
  76. package/docs/tutorials/090-using-widget-libraries.md +1 -1
  77. package/package.json +1 -2
  78. package/dist/hub/lb-rows.d.ts +0 -18
  79. package/dist/hub/lb-rows.d.ts.map +0 -1
  80. package/dist/hub/lb-rows.js +0 -106
  81. package/dist/tests/lb-rows.test.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Discovering `*.hooks.ts`/`*.queries.ts` pairs (build/locations.ts) and
2
+ * Discovering `*.requests.ts`/`*.queries.ts` pairs (build/locations.ts) and
3
3
  * generating the hub registry from them (build/pages.ts).
4
4
  */
5
5
  import assert from "node:assert/strict";
@@ -19,12 +19,12 @@ async function tree(files) {
19
19
  }
20
20
  return dir;
21
21
  }
22
- describe("discovering hooks and queries", () => {
23
- it("pairs a *.hooks.ts and *.queries.ts with the page sharing their basename", async () => {
22
+ describe("discovering requests and queries", () => {
23
+ it("pairs a *.requests.ts and *.queries.ts with the page sharing their basename", async () => {
24
24
  const src = await tree({
25
25
  "chrome.html": CHROME,
26
26
  "pages/hello.page.html": `<p>hi</p>`,
27
- "pages/hello.hooks.ts": `export const hooks = {};`,
27
+ "pages/hello.requests.ts": `export const requests = {};`,
28
28
  "pages/hello.queries.ts": `export const queries = {};`,
29
29
  });
30
30
  try {
@@ -33,7 +33,7 @@ describe("discovering hooks and queries", () => {
33
33
  out: `${src}/dist`,
34
34
  });
35
35
  const hello = pageSources.get("hello");
36
- assert.ok(hello?.hooks?.endsWith("hello.hooks"));
36
+ assert.ok(hello?.requests?.endsWith("hello.requests"));
37
37
  assert.ok(hello?.queries?.endsWith("hello.queries"));
38
38
  }
39
39
  finally {
@@ -52,17 +52,64 @@ describe("discovering hooks and queries", () => {
52
52
  out: `${src}/dist`,
53
53
  });
54
54
  const counter = pageSources.get("counter");
55
- assert.equal(counter?.hooks, undefined);
55
+ assert.equal(counter?.requests, undefined);
56
56
  assert.ok(counter?.queries?.endsWith("counter.queries"));
57
57
  }
58
58
  finally {
59
59
  await rm(src, { recursive: true, force: true });
60
60
  }
61
61
  });
62
- it("throws when a hooks or queries file has no matching page", async () => {
62
+ it("throws when no chrome file is found", async () => {
63
+ const src = await tree({ "pages/hello.page.html": `<p>hi</p>` });
64
+ try {
65
+ await assert.rejects(() => resolveLocations({ src, out: `${src}/dist` }), /no chrome\.html file found/);
66
+ }
67
+ finally {
68
+ await rm(src, { recursive: true, force: true });
69
+ }
70
+ });
71
+ it("throws when two chrome files are found", async () => {
72
+ const src = await tree({
73
+ "chrome.html": CHROME,
74
+ "other/chrome.html": CHROME,
75
+ });
76
+ try {
77
+ await assert.rejects(() => resolveLocations({ src, out: `${src}/dist` }), /more than one chrome\.html file found/);
78
+ }
79
+ finally {
80
+ await rm(src, { recursive: true, force: true });
81
+ }
82
+ });
83
+ it("throws when two imports.ts files are found", async () => {
84
+ const src = await tree({
85
+ "chrome.html": CHROME,
86
+ "imports.ts": `export default [];`,
87
+ "widgets/imports.ts": `export default [];`,
88
+ });
89
+ try {
90
+ await assert.rejects(() => resolveLocations({ src, out: `${src}/dist` }), /more than one imports\.ts found/);
91
+ }
92
+ finally {
93
+ await rm(src, { recursive: true, force: true });
94
+ }
95
+ });
96
+ it("throws when two page files in different directories share a stub", async () => {
97
+ const src = await tree({
98
+ "chrome.html": CHROME,
99
+ "pages/members.page.html": `<p>one</p>`,
100
+ "admin/members.page.html": `<p>two</p>`,
101
+ });
102
+ try {
103
+ await assert.rejects(() => resolveLocations({ src, out: `${src}/dist` }), /more than one 'members\.page\.html'/);
104
+ }
105
+ finally {
106
+ await rm(src, { recursive: true, force: true });
107
+ }
108
+ });
109
+ it("throws when a requests or queries file has no matching page", async () => {
63
110
  const src = await tree({
64
111
  "chrome.html": CHROME,
65
- "pages/orphan.hooks.ts": `export const hooks = {};`,
112
+ "pages/orphan.requests.ts": `export const requests = {};`,
66
113
  });
67
114
  try {
68
115
  await assert.rejects(() => resolveLocations({ src, out: `${src}/dist` }), /no 'orphan\.page\.html'/);
@@ -73,7 +120,7 @@ describe("discovering hooks and queries", () => {
73
120
  });
74
121
  });
75
122
  describe("pagesSource", () => {
76
- it("returns undefined when no page has hooks or queries", () => {
123
+ it("returns undefined when no page has requests or queries", () => {
77
124
  assert.equal(pagesSource([{ name: "hello", file: "/src/hello.page.html" }], new Map(), "/out", "@loadbare/app"), undefined);
78
125
  });
79
126
  it("generates one import per file found and one entry per page", () => {
@@ -82,17 +129,20 @@ describe("pagesSource", () => {
82
129
  { name: "counter", file: "/src/counter.page.html" },
83
130
  ];
84
131
  const pageSources = new Map([
85
- ["hello", { hooks: "/src/hello.hooks", queries: "/src/hello.queries" }],
132
+ [
133
+ "hello",
134
+ { requests: "/src/hello.requests", queries: "/src/hello.queries" },
135
+ ],
86
136
  ["counter", { queries: "/src/counter.queries" }],
87
137
  ]);
88
138
  const out = pagesSource(pages, pageSources, "/out", "@loadbare/app");
89
139
  assert.match(out, /import \{ createHub \} from "@loadbare\/app\/server";/);
90
- assert.match(out, /import \{ hooks as page_hello_Hooks \} from "\.\.\/src\/hello\.hooks";/);
140
+ assert.match(out, /import \{ requests as page_hello_Requests \} from "\.\.\/src\/hello\.requests";/);
91
141
  assert.match(out, /import \{ queries as page_hello_Queries \} from "\.\.\/src\/hello\.queries";/);
92
142
  assert.match(out, /import \{ queries as page_counter_Queries \} from "\.\.\/src\/counter\.queries";/);
93
- assert.doesNotMatch(out, /page_counter_Hooks/);
94
- assert.match(out, /"hello": \{ hooks: page_hello_Hooks, queries: page_hello_Queries \}/);
95
- assert.match(out, /"counter": \{ hooks: \{\}, queries: page_counter_Queries \}/);
143
+ assert.doesNotMatch(out, /page_counter_Requests/);
144
+ assert.match(out, /"hello": \{ requests: page_hello_Requests, queries: page_hello_Queries \}/);
145
+ assert.match(out, /"counter": \{ requests: \{\}, queries: page_counter_Queries \}/);
96
146
  assert.match(out, /export const hub = createHub\(\{/);
97
147
  });
98
148
  });