@backtickjs/hono 0.2.6 → 0.2.8

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,18 @@ 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
+ }
8
20
  /**
9
21
  * Hono's renderer for Backtick screens: under it, `context.render(input)`
10
22
  * answers with `input` bundled for the modules the client sent in
@@ -13,7 +25,14 @@ declare module "hono" {
13
25
  * app.use(backtick());
14
26
  * app.get("/", (context) => context.render(<Home />));
15
27
  *
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 }`.
28
+ * The status is the context's, so `context.status(404)` makes a not-found
29
+ * screen, and screens are `no-store`: each opens as its latest copy. A client
30
+ * without a module the screen needs gets a 426, and any other refusal of the
31
+ * bundler's a 400, each with `{ name, message }`.
32
+ *
33
+ * `manifest` is the app's web app manifest, sent in `x-backtick-manifest` on
34
+ * every screen, so it's as fresh as they are.
18
35
  */
19
- export declare function backtick(): MiddlewareHandler;
36
+ export declare function backtick(options?: {
37
+ manifest?: Manifest;
38
+ }): MiddlewareHandler;
package/dist/index.js CHANGED
@@ -7,10 +7,17 @@ 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, sent in `x-backtick-manifest` on
16
+ * 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) => {
15
22
  context.setRenderer(async (input) => {
16
23
  let modules;
@@ -24,7 +31,12 @@ export function backtick() {
24
31
  try {
25
32
  const build = await bundler.build({ input, modules });
26
33
  const { code } = build.generate({ format: "cjs" });
27
- return context.body(code, 200, { "content-type": "text/javascript" });
34
+ context.header("content-type", "text/javascript");
35
+ context.header("cache-control", "no-store");
36
+ if (manifest !== undefined) {
37
+ context.header("x-backtick-manifest", encodeURIComponent(json));
38
+ }
39
+ return context.body(code);
28
40
  }
29
41
  catch (error) {
30
42
  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,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,KAAoB,CAAC;gBAC/C,OAAO,OAAO,CAAC,IAAI,CACjB,EAAE,IAAI,EAAE,OAAO,EAAE,kCAAkC,OAAO,EAAE,EA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C;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.6",
3
+ "version": "0.2.8",
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.6",
41
- "@backtickjs/core": "^0.2.6"
40
+ "@backtickjs/bundler": "0.2.8",
41
+ "@backtickjs/core": "0.2.8"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "hono": "^4.13.13"
package/src/index.ts CHANGED
@@ -12,6 +12,15 @@ 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
+ }
23
+
15
24
  /**
16
25
  * Hono's renderer for Backtick screens: under it, `context.render(input)`
17
26
  * answers with `input` bundled for the modules the client sent in
@@ -20,10 +29,19 @@ declare module "hono" {
20
29
  * app.use(backtick());
21
30
  * app.get("/", (context) => context.render(<Home />));
22
31
  *
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 }`.
32
+ * The status is the context's, so `context.status(404)` makes a not-found
33
+ * screen, and screens are `no-store`: each opens as its latest copy. A client
34
+ * without a module the screen needs gets a 426, and any other refusal of the
35
+ * bundler's a 400, each with `{ name, message }`.
36
+ *
37
+ * `manifest` is the app's web app manifest, sent in `x-backtick-manifest` on
38
+ * every screen, so it's as fresh as they are.
25
39
  */
26
- export function backtick(): MiddlewareHandler {
40
+ export function backtick(
41
+ options: { manifest?: Manifest } = {},
42
+ ): MiddlewareHandler {
43
+ const { manifest } = options;
44
+ const json = JSON.stringify(manifest);
27
45
  return async (context, next) => {
28
46
  context.setRenderer(async (input) => {
29
47
  let modules: Modules;
@@ -39,7 +57,12 @@ export function backtick(): MiddlewareHandler {
39
57
  try {
40
58
  const build = await bundler.build({ input, modules });
41
59
  const { code } = build.generate({ format: "cjs" });
42
- return context.body(code, 200, { "content-type": "text/javascript" });
60
+ context.header("content-type", "text/javascript");
61
+ context.header("cache-control", "no-store");
62
+ if (manifest !== undefined) {
63
+ context.header("x-backtick-manifest", encodeURIComponent(json));
64
+ }
65
+ return context.body(code);
43
66
  } catch (error) {
44
67
  if (error instanceof BundlerError) {
45
68
  return context.json(