Skip to content

Commit

Permalink
release: 0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
186526 committed Jul 31, 2024
1 parent c216c0a commit 79b9fba
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 14 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "handlers.js",
"description": "Handlers.js is a unified and lightweight web application framework for multiple platforms.",
"version": "0.1.1-2",
"version": "0.1.2",
"main": "./dist/index.js",
"webpack": "./dist/index.js",
"browser": "./dist/main.serviceworker.js",
Expand Down Expand Up @@ -39,6 +39,7 @@
"ts-jest": "^28.0.5",
"ts-loader": "^9.3.1",
"ts-node": "^10.8.1",
"tsc-alias": "^1.8.10",
"typescript": "^4.7.4",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
Expand All @@ -55,7 +56,7 @@
"watch": "webpack --watch",
"clean": "rm -rf ./dist",
"demo": "env NODE_ENV=development yarn build:node && node ./dist/main.node.js",
"tsc": "tsc",
"tsc": "tsc && tsc-alias",
"test:node": "jest ./test/node.test.ts",
"test:deno": "BUILD_TARGET=deno:test webpack && jest ./test/deno.test.ts",
"coverage": "jest --collectCoverage --",
Expand Down
2 changes: 1 addition & 1 deletion src/platform/txiki-js/serveHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class HttpConn {

const [method, path, version] = firstLine.split(' ');

if (version in ['HTTP/1.1', 'HTTP/1.0', 'HTTP/0.9']) {
if (!(version in ['HTTP/1.1', 'HTTP/1.0', 'HTTP/0.9'])) {
this.conn.close();
}

Expand Down
21 changes: 21 additions & 0 deletions test/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,25 @@ describe('Test server', () => {
expect(status).toEqual(200);
expect(data).toEqual('hit');
});

test('dynamic handler', async () => {
expect.assertions(6);

const { status: firstStatus, data: firstData } = await Instance.get(
`/handler`,
);

const { data, status } = await Instance.get(`/handler/add`);

const { status: secondStatus, data: secondData } = await Instance.get(
`/handler`,
);

expect(firstStatus).toEqual(200);
expect(firstData).toEqual('miss');
expect(status).toEqual(200);
expect(data).toEqual('added');
expect(secondStatus).toEqual(200);
expect(secondData).toEqual('hit');
});
});
14 changes: 14 additions & 0 deletions test/test-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ App.binding(
App.create('GET', async () => '200 OK'),
);

const dynamicHandler = new handlersJS.handler('GET', [
async () => new handlersJS.response('miss'),
]);

App.binding('/handler', dynamicHandler);

App.binding(
'/handler/add',
App.create('GET', async () => {
dynamicHandler.add(async () => new handlersJS.response('hit'));
return 'added';
}),
);

App.binding(
'/post',
App.create(
Expand Down
21 changes: 17 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"lib": ["ESNext"],
"lib": [
"ESNext"
],
"types": [
"@cloudflare/workers-types",
"@types/node",
Expand Down Expand Up @@ -35,7 +37,18 @@
],
"declaration": true
},
"exclude": ["node_modules"],
"include": ["index.ts", "src/**/*.ts", "demo/**/*.ts", "types/*.d.ts"]
"exclude": [
"node_modules"
],
"include": [
"index.ts",
"src/**/*.ts",
"demo/**/*.ts",
"types/*.d.ts"
],
"tsc-alias": {
"resolveFullPaths": true,
"verbose": true
}
// "esm": true
}
}
96 changes: 89 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ ansi-styles@^5.0.0:
resolved "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-5.2.0.tgz#07449690ad45777d1924ac2abb2fc8895dba836b"
integrity sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==

anymatch@^3.0.3:
anymatch@^3.0.3, anymatch@~3.1.2:
version "3.1.3"
resolved "https://registry.npmmirror.com/anymatch/-/anymatch-3.1.3.tgz#790c58b19ba1720a84205b57c618d5ad8524973e"
integrity sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==
Expand Down Expand Up @@ -1473,6 +1473,11 @@ bin-links@^3.0.0:
rimraf "^3.0.0"
write-file-atomic "^4.0.0"

binary-extensions@^2.0.0:
version "2.3.0"
resolved "https://repo.186526.xyz/repository/npm/binary-extensions/-/binary-extensions-2.3.0.tgz#f6e14a97858d327252200242d4ccfe522c445522"
integrity sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==

binaryextensions@^2.1.2:
version "2.3.0"
resolved "https://registry.npmmirror.com/binaryextensions/-/binaryextensions-2.3.0.tgz#1d269cbf7e6243ea886aa41453c3651ccbe13c22"
Expand Down Expand Up @@ -1535,6 +1540,13 @@ braces@^3.0.2:
dependencies:
fill-range "^7.0.1"

braces@~3.0.2:
version "3.0.3"
resolved "https://repo.186526.xyz/repository/npm/braces/-/braces-3.0.3.tgz#490332f40919452272d55a8480adc0c441358789"
integrity sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==
dependencies:
fill-range "^7.1.1"

browserslist@^4.21.10, browserslist@^4.22.2:
version "4.23.0"
resolved "https://registry.npmmirror.com/browserslist/-/browserslist-4.23.0.tgz#8f3acc2bbe73af7213399430890f86c63a5674ab"
Expand Down Expand Up @@ -1710,6 +1722,21 @@ chardet@^0.7.0:
resolved "https://registry.npmmirror.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==

chokidar@^3.5.3:
version "3.6.0"
resolved "https://repo.186526.xyz/repository/npm/chokidar/-/chokidar-3.6.0.tgz#197c6cc669ef2a8dc5e7b4d97ee4e092c3eb0d5b"
integrity sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==
dependencies:
anymatch "~3.1.2"
braces "~3.0.2"
glob-parent "~5.1.2"
is-binary-path "~2.1.0"
is-glob "~4.0.1"
normalize-path "~3.0.0"
readdirp "~3.6.0"
optionalDependencies:
fsevents "~2.3.2"

chownr@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/chownr/-/chownr-2.0.0.tgz#15bfbe53d2eab4cf70f18a8cd68ebe5b3cb1dece"
Expand Down Expand Up @@ -1902,6 +1929,11 @@ commander@^7.0.0:
resolved "https://registry.npmmirror.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==

commander@^9.0.0:
version "9.5.0"
resolved "https://repo.186526.xyz/repository/npm/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30"
integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==

common-ancestor-path@^1.0.1:
version "1.0.1"
resolved "https://registry.npmmirror.com/common-ancestor-path/-/common-ancestor-path-1.0.1.tgz#4f7d2d1394d91b7abdf51871c62f71eadb0182a7"
Expand Down Expand Up @@ -2494,6 +2526,13 @@ fill-range@^7.0.1:
dependencies:
to-regex-range "^5.0.1"

fill-range@^7.1.1:
version "7.1.1"
resolved "https://repo.186526.xyz/repository/npm/fill-range/-/fill-range-7.1.1.tgz#44265d3cac07e3ea7dc247516380643754a05292"
integrity sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==
dependencies:
to-regex-range "^5.0.1"

find-up@^3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/find-up/-/find-up-3.0.0.tgz#49169f1d7993430646da61ecc5ae355c21c97b73"
Expand Down Expand Up @@ -2575,7 +2614,7 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmmirror.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2:
fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
Expand Down Expand Up @@ -2674,7 +2713,7 @@ glob-parent@^3.1.0:
is-glob "^3.1.0"
path-dirname "^1.0.0"

glob-parent@^5.1.2:
glob-parent@^5.1.2, glob-parent@~5.1.2:
version "5.1.2"
resolved "https://registry.npmmirror.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
integrity sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==
Expand Down Expand Up @@ -2719,7 +2758,7 @@ globals@^11.1.0:
resolved "https://registry.npmmirror.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==

globby@^11.0.1, globby@^11.1.0:
globby@^11.0.1, globby@^11.0.4, globby@^11.1.0:
version "11.1.0"
resolved "https://registry.npmmirror.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
Expand Down Expand Up @@ -3057,6 +3096,13 @@ is-arrayish@^0.2.1:
resolved "https://registry.npmmirror.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
integrity sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==

is-binary-path@~2.1.0:
version "2.1.0"
resolved "https://repo.186526.xyz/repository/npm/is-binary-path/-/is-binary-path-2.1.0.tgz#ea1f7f3b80f064236e83470f86c09c254fb45b09"
integrity sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==
dependencies:
binary-extensions "^2.0.0"

is-buffer@^1.1.5:
version "1.1.6"
resolved "https://registry.npmmirror.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
Expand Down Expand Up @@ -3126,7 +3172,7 @@ is-glob@^3.1.0:
dependencies:
is-extglob "^2.1.0"

is-glob@^4.0.0, is-glob@^4.0.1:
is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
version "4.0.3"
resolved "https://registry.npmmirror.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
Expand Down Expand Up @@ -4246,6 +4292,11 @@ [email protected]:
resolved "https://registry.npmmirror.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

mylas@^2.1.9:
version "2.1.13"
resolved "https://repo.186526.xyz/repository/npm/mylas/-/mylas-2.1.13.tgz#1e23b37d58fdcc76e15d8a5ed23f9ae9fc0cbdf4"
integrity sha512-+MrqnJRtxdF+xngFfUUkIMQrUUL0KsxbADUkn23Z/4ibGg192Q+z+CQyiYwvWTsYjJygmMR8+w3ZDa98Zh6ESg==

nanomatch@^1.2.9:
version "1.2.13"
resolved "https://registry.npmmirror.com/nanomatch/-/nanomatch-1.2.13.tgz#b87a8aa4fc0de8fe6be88895b38983ff265bd119"
Expand Down Expand Up @@ -4333,7 +4384,7 @@ normalize-package-data@^2.5.0:
semver "2 || 3 || 4 || 5"
validate-npm-package-license "^3.0.1"

normalize-path@^3.0.0:
normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==
Expand Down Expand Up @@ -4692,7 +4743,7 @@ picocolors@^1.0.0:
resolved "https://registry.npmmirror.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

picomatch@^2.0.4, picomatch@^2.2.3, picomatch@^2.3.1:
picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.2.3, picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.npmmirror.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
Expand Down Expand Up @@ -4724,6 +4775,13 @@ pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"

plimit-lit@^1.2.6:
version "1.6.1"
resolved "https://repo.186526.xyz/repository/npm/plimit-lit/-/plimit-lit-1.6.1.tgz#a34594671b31ee8e93c72d505dfb6852eb72374a"
integrity sha512-B7+VDyb8Tl6oMJT9oSO2CW8XC/T4UcJGrwOVoNGwOQsQYhlpfajmrMj5xeejqaASq3V/EqThyOeATEOMuSEXiA==
dependencies:
queue-lit "^1.5.1"

posix-character-classes@^0.1.0:
version "0.1.1"
resolved "https://registry.npmmirror.com/posix-character-classes/-/posix-character-classes-0.1.1.tgz#01eac0fe3b5af71a2a6c02feabb8c1fef7e00eab"
Expand Down Expand Up @@ -4823,6 +4881,11 @@ punycode@^2.1.0:
resolved "https://registry.npmmirror.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==

queue-lit@^1.5.1:
version "1.5.2"
resolved "https://repo.186526.xyz/repository/npm/queue-lit/-/queue-lit-1.5.2.tgz#83c24d4f4764802377b05a6e5c73017caf3f8747"
integrity sha512-tLc36IOPeMAubu8BkW8YDBV+WyIgKlYU7zUNs0J5Vk9skSZ4JfGlPOqplP0aHdfv7HL0B2Pg6nwiq60Qc6M2Hw==

queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.npmmirror.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
Expand Down Expand Up @@ -4922,6 +4985,13 @@ readdir-scoped-modules@^1.1.0:
graceful-fs "^4.1.2"
once "^1.3.0"

readdirp@~3.6.0:
version "3.6.0"
resolved "https://repo.186526.xyz/repository/npm/readdirp/-/readdirp-3.6.0.tgz#74a370bd857116e245b29cc97340cd431a02a6c7"
integrity sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==
dependencies:
picomatch "^2.2.1"

rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.npmmirror.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
Expand Down Expand Up @@ -5712,6 +5782,18 @@ ts-node@^10.8.1:
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

tsc-alias@^1.8.10:
version "1.8.10"
resolved "https://repo.186526.xyz/repository/npm/tsc-alias/-/tsc-alias-1.8.10.tgz#279f9bf0dd8bc10fb27820393d4881db5a303938"
integrity sha512-Ibv4KAWfFkFdKJxnWfVtdOmB0Zi1RJVxcbPGiCDsFpCQSsmpWyuzHG3rQyI5YkobWwxFPEyQfu1hdo4qLG2zPw==
dependencies:
chokidar "^3.5.3"
commander "^9.0.0"
globby "^11.0.4"
mylas "^2.1.9"
normalize-path "^3.0.0"
plimit-lit "^1.2.6"

tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.npmmirror.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
Expand Down

0 comments on commit 79b9fba

Please sign in to comment.