hono 0.2.2 → 0.2.3

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.
@@ -1,41 +1,24 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
2
  Object.defineProperty(exports, "__esModule", { value: true });
22
3
  exports.mustache = void 0;
23
4
  const cloudflare_1 = require("../../utils/cloudflare");
24
5
  const EXTENSION = '.mustache';
25
6
  const mustache = () => {
7
+ let Mustache;
8
+ try {
9
+ Mustache = require('mustache');
10
+ }
11
+ catch (_a) {
12
+ // Do nothing.
13
+ }
26
14
  return async (c, next) => {
27
- let Mustache;
28
- try {
29
- Mustache = await Promise.resolve().then(() => __importStar(require('mustache')));
30
- }
31
- catch (e) {
32
- console.error(`Mustache is not found! ${e}`);
33
- throw new Error(`${e}`);
15
+ if (!Mustache) {
16
+ throw new Error('If you want to use Mustache Middleware, install mustache module.');
34
17
  }
35
18
  c.render = async (filename, view = {}, options) => {
36
19
  const content = await (0, cloudflare_1.getContentFromKVAsset)(`${filename}${EXTENSION}`);
37
20
  if (!content) {
38
- throw new Error(`Template "${filename}${EXTENSION}" is not found`);
21
+ throw new Error(`Template "${filename}${EXTENSION}" is not found or blank.`);
39
22
  }
40
23
  const partialArgs = {};
41
24
  if (options) {
@@ -43,7 +26,7 @@ const mustache = () => {
43
26
  for (const key of Object.keys(partials)) {
44
27
  const partialContent = await (0, cloudflare_1.getContentFromKVAsset)(`${partials[key]}${EXTENSION}`);
45
28
  if (!partialContent) {
46
- throw new Error(`Partial Template "${partials[key]}${EXTENSION}" is not found`);
29
+ throw new Error(`Partial Template "${partials[key]}${EXTENSION}" is not found or blank.`);
47
30
  }
48
31
  partialArgs[key] = partialContent;
49
32
  }
@@ -21,4 +21,5 @@ export declare class Middleware {
21
21
  exposeHeaders?: string[];
22
22
  }) => (c: import("./context").Context, next: Function) => Promise<void>;
23
23
  static cookie: () => (c: import("./context").Context, next: Function) => Promise<void>;
24
+ static mustache: () => (c: import("./context").Context, next: Function) => Promise<void>;
24
25
  }
@@ -8,7 +8,7 @@ const basic_auth_1 = require("./middleware/basic-auth/basic-auth");
8
8
  const body_parse_1 = require("./middleware/body-parse/body-parse");
9
9
  const cors_1 = require("./middleware/cors/cors");
10
10
  const cookie_1 = require("./middleware/cookie/cookie");
11
- //import { mustache } from './middleware/mustache/mustache'
11
+ const mustache_1 = require("./middleware/mustache/mustache");
12
12
  class Middleware {
13
13
  }
14
14
  exports.Middleware = Middleware;
@@ -19,3 +19,4 @@ Middleware.basicAuth = basic_auth_1.basicAuth;
19
19
  Middleware.bodyParse = body_parse_1.bodyParse;
20
20
  Middleware.cors = cors_1.cors;
21
21
  Middleware.cookie = cookie_1.cookie;
22
+ Middleware.mustache = mustache_1.mustache;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hono",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "[炎] Ultrafast web framework for Cloudflare Workers.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",