@flattype/models 1.8.0 → 1.9.0
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/README.md +13 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://github.
|
|
2
|
+
<a href="https://karammm.github.io/flattype/docs/">
|
|
3
3
|
<picture>
|
|
4
4
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/karammm/flattype/main/docs/assets/logo-dark.svg">
|
|
5
5
|
<img src="https://raw.githubusercontent.com/karammm/flattype/main/docs/assets/logo-light.svg" alt="FlatType.js" width="300">
|
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
</p>
|
|
30
30
|
|
|
31
31
|
<p align="center">
|
|
32
|
+
<a href="https://karammm.github.io/flattype/docs/"><b>Documentation</b></a> ·
|
|
33
|
+
<a href="https://karammm.github.io/flattype/"><b>Playground</b></a> ·
|
|
32
34
|
<a href="#quick-start"><b>Quick start</b></a> ·
|
|
33
35
|
<a href="#the-format"><b>Format</b></a> ·
|
|
34
36
|
<a href="#typed-models"><b>Models</b></a> ·
|
|
@@ -148,7 +150,7 @@ const [users] = createFlatResource(() => "/api/users", { model: User, list: true
|
|
|
148
150
|
| [`@flattype/cli`](https://github.com/karammm/flattype/blob/main/packages/cli) | The `flattype` command: `encode`, `decode`, `stats`, and `gen` (models from samples or OpenAPI) | Node tool |
|
|
149
151
|
| [`@flattype/shared`](https://github.com/karammm/flattype/blob/main/packages/shared) | Shared TypeScript types | types only |
|
|
150
152
|
|
|
151
|
-
|
|
153
|
+
Everything is documented at [karammm.github.io/flattype/docs](https://karammm.github.io/flattype/docs/), and you can try the format on your own data in the [playground](https://karammm.github.io/flattype/). See the [roadmap](https://github.com/karammm/flattype/blob/main/ROADMAP.md).
|
|
152
154
|
|
|
153
155
|
## The format
|
|
154
156
|
|
|
@@ -565,7 +567,7 @@ It handles `$ref` between schemas, `allOf`, `required` (other fields become opti
|
|
|
565
567
|
| **FlatType `decode`** | **0.73 ms** |
|
|
566
568
|
| TOON `decode` | 5.9 ms |
|
|
567
569
|
|
|
568
|
-
Some honest notes on
|
|
570
|
+
Numbers measured on every docs build are on the [benchmarks page](https://karammm.github.io/flattype/docs/guide/benchmarks). Some honest notes on them:
|
|
569
571
|
|
|
570
572
|
- **The savings come from lists.** A single small object is about the same size as JSON.
|
|
571
573
|
- **Gzip already removes most of JSON's repeated keys,** so gzipped network sizes come out close. FlatType makes the biggest difference where text isn't compressed: LLM prompts and tool results, logs, caches and local storage.
|
|
@@ -579,11 +581,19 @@ pnpm build && pnpm typecheck && pnpm test
|
|
|
579
581
|
pnpm bench # encode/decode vs JSON
|
|
580
582
|
pnpm compare # size and parse time vs JSON and TOON
|
|
581
583
|
pnpm check:size # bundle budgets
|
|
584
|
+
pnpm --filter @flattype/core test:perf # linear-time checks on hostile input
|
|
585
|
+
FUZZ_RUNS=50000 pnpm --filter @flattype/core exec vitest run # deep fuzzing, as in CI
|
|
586
|
+
pnpm --filter @flattype/docs dev # docs site (VitePress)
|
|
587
|
+
pnpm --filter @flattype/playground dev # playground
|
|
582
588
|
pnpm video # re-render docs/assets/flattype-intro.{mp4,gif} (needs ffmpeg and the Angular example built)
|
|
583
589
|
```
|
|
584
590
|
|
|
585
591
|
This is a pnpm + Turborepo monorepo built with tsup and tested with Vitest and fast-check. Releases use Changesets, and all `@flattype/*` packages share one version number. Every release follows the checklist in [ROADMAP.md](https://github.com/karammm/flattype/blob/main/ROADMAP.md).
|
|
586
592
|
|
|
593
|
+
## Security
|
|
594
|
+
|
|
595
|
+
The decoder is prototype-safe, runs in linear time on hostile input, and only ever throws `FlatDecodeError`. Deep fuzzing and timing tests check this on every push, as described on the [security page](https://karammm.github.io/flattype/docs/guide/security). Please report vulnerabilities privately, following [SECURITY.md](https://github.com/karammm/flattype/blob/main/SECURITY.md).
|
|
596
|
+
|
|
587
597
|
## Contributing
|
|
588
598
|
|
|
589
599
|
Issues and pull requests are welcome. If you have a payload that FlatType handles badly, please [open an issue](https://github.com/karammm/flattype/issues) with a sample; it becomes a test fixture.
|
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var ModelError = class extends Error {
|
|
|
55
55
|
// src/model.ts
|
|
56
56
|
var PRIMITIVES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean", "date", "any"]);
|
|
57
57
|
var FAIL = /* @__PURE__ */ Symbol("fail");
|
|
58
|
-
var NUMERIC = /^\s*[-+]?(?:\d
|
|
58
|
+
var NUMERIC = /^\s*[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?\s*$/;
|
|
59
59
|
var ISO_DATE = /^\d{4}-\d{2}-\d{2}/;
|
|
60
60
|
function isModel(v) {
|
|
61
61
|
return typeof v === "object" && v !== null && v.__model === true;
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var ModelError = class extends Error {
|
|
|
23
23
|
// src/model.ts
|
|
24
24
|
var PRIMITIVES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean", "date", "any"]);
|
|
25
25
|
var FAIL = /* @__PURE__ */ Symbol("fail");
|
|
26
|
-
var NUMERIC = /^\s*[-+]?(?:\d
|
|
26
|
+
var NUMERIC = /^\s*[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?\s*$/;
|
|
27
27
|
var ISO_DATE = /^\d{4}-\d{2}-\d{2}/;
|
|
28
28
|
function isModel(v) {
|
|
29
29
|
return typeof v === "object" && v !== null && v.__model === true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flattype/models",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Typed models for API data: key mapping, coercion and defaults, from JSON or Flat Notation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"flattype"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@flattype/core": "1.
|
|
37
|
-
"@flattype/shared": "1.
|
|
36
|
+
"@flattype/core": "1.9.0",
|
|
37
|
+
"@flattype/shared": "1.9.0"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
@@ -55,6 +55,7 @@
|
|
|
55
55
|
"build": "tsup",
|
|
56
56
|
"typecheck": "tsc --noEmit",
|
|
57
57
|
"clean": "rm -rf dist .turbo",
|
|
58
|
-
"test": "vitest run"
|
|
58
|
+
"test": "vitest run",
|
|
59
|
+
"test:perf": "vitest run --config vitest.perf.config.ts"
|
|
59
60
|
}
|
|
60
61
|
}
|