@backtickjs/hono 0.2.5 → 0.2.7

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/index.d.ts CHANGED
@@ -5,6 +5,19 @@ declare module "hono" {
5
5
  <T extends [T] extends [SplicesAs<T>] ? unknown : Spliceable>(input: T): Promise<Response>;
6
6
  }
7
7
  }
8
+ /** A web app manifest: what the phone uses of an app before and around it. */
9
+ export interface Manifest {
10
+ name?: string;
11
+ short_name?: string;
12
+ icons?: {
13
+ src: string;
14
+ sizes?: string;
15
+ type?: string;
16
+ }[];
17
+ theme_color?: string;
18
+ background_color?: string;
19
+ display?: "fullscreen" | "standalone" | "minimal-ui" | "browser";
20
+ }
8
21
  /**
9
22
  * Hono's renderer for Backtick screens: under it, `context.render(input)`
10
23
  * answers with `input` bundled for the modules the client sent in
@@ -13,7 +26,14 @@ declare module "hono" {
13
26
  * app.use(backtick());
14
27
  * app.get("/", (context) => context.render(<Home />));
15
28
  *
16
- * A client without a module the screen needs gets a 426, and any other
17
- * refusal of the bundler's a 400, each with `{ name, message }`.
29
+ * The status is the context's, so `context.status(404)` makes a not-found
30
+ * screen, and screens are `no-store`: each opens as its latest copy. A client
31
+ * without a module the screen needs gets a 426, and any other refusal of the
32
+ * bundler's a 400, each with `{ name, message }`.
33
+ *
34
+ * `manifest` is the app's web app manifest, at `/manifest.webmanifest` and in
35
+ * `x-backtick-manifest` on every screen, so it's as fresh as they are.
18
36
  */
19
- export declare function backtick(): MiddlewareHandler;
37
+ export declare function backtick(options?: {
38
+ manifest?: Manifest;
39
+ }): MiddlewareHandler;
package/dist/index.js CHANGED
@@ -7,11 +7,24 @@ import { bundler, BundlerError } from "@backtickjs/bundler";
7
7
  * app.use(backtick());
8
8
  * app.get("/", (context) => context.render(<Home />));
9
9
  *
10
- * A client without a module the screen needs gets a 426, and any other
11
- * refusal of the bundler's a 400, each with `{ name, message }`.
10
+ * The status is the context's, so `context.status(404)` makes a not-found
11
+ * screen, and screens are `no-store`: each opens as its latest copy. A client
12
+ * without a module the screen needs gets a 426, and any other refusal of the
13
+ * bundler's a 400, each with `{ name, message }`.
14
+ *
15
+ * `manifest` is the app's web app manifest, at `/manifest.webmanifest` and in
16
+ * `x-backtick-manifest` on every screen, so it's as fresh as they are.
12
17
  */
13
- export function backtick() {
18
+ export function backtick(options = {}) {
19
+ const { manifest } = options;
20
+ const json = JSON.stringify(manifest);
14
21
  return async (context, next) => {
22
+ if (manifest !== undefined &&
23
+ context.req.path === "/manifest.webmanifest") {
24
+ return context.body(json, 200, {
25
+ "content-type": "application/manifest+json",
26
+ });
27
+ }
15
28
  context.setRenderer(async (input) => {
16
29
  let modules;
17
30
  try {
@@ -24,7 +37,12 @@ export function backtick() {
24
37
  try {
25
38
  const build = await bundler.build({ input, modules });
26
39
  const { code } = build.generate({ format: "cjs" });
27
- return context.body(code, 200, { "content-type": "text/javascript" });
40
+ context.header("content-type", "text/javascript");
41
+ context.header("cache-control", "no-store");
42
+ if (manifest !== undefined) {
43
+ context.header("x-backtick-manifest", encodeURIComponent(json));
44
+ }
45
+ return context.body(code);
28
46
  }
29
47
  catch (error) {
30
48
  if (error instanceof BundlerError) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAC;AAc1E;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QAC7B,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;YAClC,IAAI,OAAgB,CAAC;YACrB,IAAI,CAAC;gBACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,IAAI,CAAC,CAAC;YACzE,CA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,CAAC,IAAI,CAAC,CAAC,CAAC;gBAClE,CAAC;gBACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;oBAClC,OAAO,OAAO,CAAC,IAAI,CACjB,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,EAC5C,KAAK,CAAC,IAAI,KAAK,uBAAuB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CACnD,CAAC;gBACJ,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,IAAI,EAAE,CAAC;IACf,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backtickjs/hono",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Hono routes as Backtick screens: a route's answer is its server components, bundled for the client that asked",
5
5
  "keywords": [
6
6
  "backtick",
@@ -37,8 +37,8 @@
37
37
  "access": "public"
38
38
  },
39
39
  "dependencies": {
40
- "@backtickjs/bundler": "^0.2.5",
41
- "@backtickjs/core": "^0.2.5"
40
+ "@backtickjs/bundler": "0.2.7",
41
+ "@backtickjs/core": "0.2.7"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "hono": "^4.13.13"
package/src/index.ts CHANGED
@@ -12,6 +12,16 @@ declare module "hono" {
12
12
  }
13
13
  }
14
14
 
15
+ /** A web app manifest: what the phone uses of an app before and around it. */
16
+ export interface Manifest {
17
+ name?: string;
18
+ short_name?: string;
19
+ icons?: { src: string; sizes?: string; type?: string }[];
20
+ theme_color?: string;
21
+ background_color?: string;
22
+ display?: "fullscreen" | "standalone" | "minimal-ui" | "browser";
23
+ }
24
+
15
25
  /**
16
26
  * Hono's renderer for Backtick screens: under it, `context.render(input)`
17
27
  * answers with `input` bundled for the modules the client sent in
@@ -20,11 +30,28 @@ declare module "hono" {
20
30
  * app.use(backtick());
21
31
  * app.get("/", (context) => context.render(<Home />));
22
32
  *
23
- * A client without a module the screen needs gets a 426, and any other
24
- * refusal of the bundler's a 400, each with `{ name, message }`.
33
+ * The status is the context's, so `context.status(404)` makes a not-found
34
+ * screen, and screens are `no-store`: each opens as its latest copy. A client
35
+ * without a module the screen needs gets a 426, and any other refusal of the
36
+ * bundler's a 400, each with `{ name, message }`.
37
+ *
38
+ * `manifest` is the app's web app manifest, at `/manifest.webmanifest` and in
39
+ * `x-backtick-manifest` on every screen, so it's as fresh as they are.
25
40
  */
26
- export function backtick(): MiddlewareHandler {
41
+ export function backtick(
42
+ options: { manifest?: Manifest } = {},
43
+ ): MiddlewareHandler {
44
+ const { manifest } = options;
45
+ const json = JSON.stringify(manifest);
27
46
  return async (context, next) => {
47
+ if (
48
+ manifest !== undefined &&
49
+ context.req.path === "/manifest.webmanifest"
50
+ ) {
51
+ return context.body(json, 200, {
52
+ "content-type": "application/manifest+json",
53
+ });
54
+ }
28
55
  context.setRenderer(async (input) => {
29
56
  let modules: Modules;
30
57
  try {
@@ -39,7 +66,12 @@ export function backtick(): MiddlewareHandler {
39
66
  try {
40
67
  const build = await bundler.build({ input, modules });
41
68
  const { code } = build.generate({ format: "cjs" });
42
- return context.body(code, 200, { "content-type": "text/javascript" });
69
+ context.header("content-type", "text/javascript");
70
+ context.header("cache-control", "no-store");
71
+ if (manifest !== undefined) {
72
+ context.header("x-backtick-manifest", encodeURIComponent(json));
73
+ }
74
+ return context.body(code);
43
75
  } catch (error) {
44
76
  if (error instanceof BundlerError) {
45
77
  return context.json(