From 054e79d71f66579473b46ea5c7ba8555e87ccc65 Mon Sep 17 00:00:00 2001 From: aquapi Date: Thu, 30 Jan 2025 18:41:32 +0700 Subject: [PATCH 1/2] Add stnl: - 'composition' and 'just-in-time' mode --- bun.lock | 5 ++++- cases/index.ts | 1 + cases/stnl.ts | 41 +++++++++++++++++++++++++++++++++++++++++ package-lock.json | 12 ++++++++++++ package.json | 1 + test/benchmarks.test.ts | 1 + 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 cases/stnl.ts diff --git a/bun.lock b/bun.lock index 86b70493a..dfea41b86 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,5 @@ { - "lockfileVersion": 0, + "lockfileVersion": 1, "workspaces": { "": { "name": "typescript-runtime-type-benchmarks", @@ -54,6 +54,7 @@ "serve": "14.2.4", "simple-runtypes": "7.1.3", "spectypes": "2.1.11", + "stnl": "0.3.3", "succulent": "0.18.1", "superstruct": "2.0.2", "suretype": "2.4.1", @@ -1415,6 +1416,8 @@ "std-env": ["std-env@3.8.0", "", {}, "sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w=="], + "stnl": ["stnl@0.3.3", "", {}, "sha512-8uMWUCQcvWDE3CwbmNPj9QogtFUL2n+J+6XoDhDYT2EJ4fnHu1Xdvxs5WUnBseJQP7Nl/1YfIPT4BLrLC6AhJA=="], + "string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="], "string-width-cjs": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="], diff --git a/cases/index.ts b/cases/index.ts index 092152d40..25b181b3b 100644 --- a/cases/index.ts +++ b/cases/index.ts @@ -30,6 +30,7 @@ export const cases = [ 'sinclair-typebox-dynamic', 'sinclair-typebox-just-in-time', 'spectypes', + 'stnl', 'succulent', 'superstruct', 'suretype', diff --git a/cases/stnl.ts b/cases/stnl.ts new file mode 100644 index 000000000..bfe7562e2 --- /dev/null +++ b/cases/stnl.ts @@ -0,0 +1,41 @@ +import compose from 'stnl/compilers/validate-json/compose'; +import { build } from 'stnl/compilers/validate-json'; +import stnl from 'stnl'; + +import { createCase } from '../benchmarks'; + +const assertLoose = stnl({ + props: { + number: 'f64', + negNumber: 'f64', + maxNumber: 'f64', + string: 'string', + longString: 'string', + boolean: 'bool', + deeplyNested: { + props: { + foo: 'string', + num: 'f64', + bool: 'bool', + }, + }, + }, +}); + +createCase('stnl (composition)', 'assertLoose', () => { + const check = compose(assertLoose); + + return data => { + if (check(data)) return true; + throw null; + }; +}); + +createCase('stnl (just-in-time)', 'assertLoose', () => { + const check = build(assertLoose); + + return data => { + if (check(data)) return true; + throw null; + }; +}); diff --git a/package-lock.json b/package-lock.json index e75bf0421..8a0bc0143 100644 --- a/package-lock.json +++ b/package-lock.json @@ -59,6 +59,7 @@ "serve": "14.2.4", "simple-runtypes": "7.1.3", "spectypes": "2.1.11", + "stnl": "0.3.3", "succulent": "0.18.1", "superstruct": "2.0.2", "suretype": "2.4.1", @@ -8932,6 +8933,12 @@ "integrity": "sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w==", "dev": true }, + "node_modules/stnl": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/stnl/-/stnl-0.3.3.tgz", + "integrity": "sha512-8uMWUCQcvWDE3CwbmNPj9QogtFUL2n+J+6XoDhDYT2EJ4fnHu1Xdvxs5WUnBseJQP7Nl/1YfIPT4BLrLC6AhJA==", + "license": "MIT" + }, "node_modules/string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", @@ -17113,6 +17120,11 @@ "integrity": "sha512-Bc3YwwCB+OzldMxOXJIIvC6cPRWr/LxOp48CdQTOkPyk/t4JWWJbrilwBd7RJzKV8QW7tJkcgAmeuLLJugl5/w==", "dev": true }, + "stnl": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/stnl/-/stnl-0.3.3.tgz", + "integrity": "sha512-8uMWUCQcvWDE3CwbmNPj9QogtFUL2n+J+6XoDhDYT2EJ4fnHu1Xdvxs5WUnBseJQP7Nl/1YfIPT4BLrLC6AhJA==" + }, "string_decoder": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", diff --git a/package.json b/package.json index ff5fe1063..67ec60dfc 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "serve": "14.2.4", "simple-runtypes": "7.1.3", "spectypes": "2.1.11", + "stnl": "0.3.3", "succulent": "0.18.1", "superstruct": "2.0.2", "suretype": "2.4.1", diff --git a/test/benchmarks.test.ts b/test/benchmarks.test.ts index 9c34976de..55ad518ca 100644 --- a/test/benchmarks.test.ts +++ b/test/benchmarks.test.ts @@ -35,6 +35,7 @@ import '../cases/sinclair-typebox-ahead-of-time'; import '../cases/sinclair-typebox-dynamic'; import '../cases/sinclair-typebox-just-in-time'; import '../cases/spectypes'; +import '../cases/stnl'; import '../cases/succulent'; import '../cases/superstruct'; import '../cases/suretype'; From c1bbff4d5fb6499629f1b35d6cb866fc8d529244 Mon Sep 17 00:00:00 2001 From: aquapi Date: Thu, 30 Jan 2025 18:44:44 +0700 Subject: [PATCH 2/2] Add link to stnl in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index c9e94a64b..b1512fc36 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ * [@sinclair/typebox](https://github.com/sinclairzx81/typebox) * [simple-runtypes](https://github.com/hoeck/simple-runtypes) * [spectypes](https://github.com/iyegoroff/spectypes) +* [stnl](https://github.com/re-utils/stnl) * [succulent](https://github.com/aslilac/succulent) * [superstruct](https://github.com/ianstormtaylor/superstruct) * [suretype](https://github.com/grantila/suretype)