json-model-compiler 2.0.52__tar.gz → 2.0.53__tar.gz
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.
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/API.md +35 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/BACKLOG.md +9 -3
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/BENCH.md +24 -12
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/HOWTO.md +33 -0
- {json_model_compiler-2.0.52/json_model_compiler.egg-info → json_model_compiler-2.0.53}/PKG-INFO +1 -1
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/TUTO.md +25 -1
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/VERSION.md +18 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/about.sh +1 -0
- json_model_compiler-2.0.53/json_model/data/VERSION +1 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/jmc.pod +6 -2
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/script.py +17 -2
- json_model_compiler-2.0.53/json_model/ts_export.py +229 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/utils.py +6 -6
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53/json_model_compiler.egg-info}/PKG-INFO +1 -1
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/SOURCES.txt +1 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/package.json +2 -1
- json_model_compiler-2.0.52/json_model/data/VERSION +0 -1
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/.github/workflows/sanity.yml +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/.gitignore +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/.gitmodules +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/DESIGN.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/DEV.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/DOC.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/INTEGRATION.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/MANIFEST.in +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/Makefile +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/PUBS.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/README.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/SPEC.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/README.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/__init__.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/analyze.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/clang.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/convert.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/clang_entry.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/clang_free.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/clang_init.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/clang_pcre2_fun.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/clang_re2_fun.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/java_free.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/java_init.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_exe.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_foot.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_free.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_head.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_init.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_main.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/perl_entry.pl +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/perl_exe.pl +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/perl_free.pl +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/perl_init.pl +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/perl_main.pl +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/perl_pkg.pl +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/plpgsql_entry.sql +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/python_entry.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/python_exe.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/python_free.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/python_init.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/python_main.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/export.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/irep.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/java.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/javascript.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/language.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/model.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/mtypes.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/objops.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/optim.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/perl.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/plpgsql.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/predefs.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/python.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/recurse.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/regex.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/resolver.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/Makefile +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/__init__.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/c/Makefile +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/c/json-model.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/c/json-model.h +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/c/main.c +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/.gitignore +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/Makefile +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/README.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/env.sh +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Checker.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/GSON.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/JSON.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/JSONP.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Jackson.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Main.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/ModelChecker.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Path.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Report.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Runtime.java +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/pom.xml +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/js/README.md +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/js/index.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/js/main.js +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/js/package.json +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/.gitignore +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/Changes +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/LICENSE +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/MANIFEST +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/Makefile.PL +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/README +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/env.sh +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/ignore.txt +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/lib/JSON/JsonModel.pm +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/00-load.t +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/manifest.t +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/pod-coverage.t +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/pod.t +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/xt/boilerplate.t +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/sql/META.json +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/sql/Makefile +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/sql/json_model--2.0.sql +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/sql/json_model.control +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/support.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/types.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/submodel.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/url_cache.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/xstatic.py +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/dependency_links.txt +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/entry_points.txt +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/not-zip-safe +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/requires.txt +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/top_level.txt +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/pyproject.toml +0 -0
- {json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/setup.cfg +0 -0
|
@@ -320,6 +320,41 @@ javac api_java.java
|
|
|
320
320
|
java api_java # yes!
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
+
## TypeScript Types
|
|
324
|
+
|
|
325
|
+
Model compilation to TypeScript generates a `.ts` file (`-F ts`) containing
|
|
326
|
+
`interface`/`type` declarations only - there is no generated runtime check
|
|
327
|
+
function, as TypeScript types are erased at compile time.
|
|
328
|
+
|
|
329
|
+
- each object model becomes an `export interface`, with optional properties (`?prefix`)
|
|
330
|
+
mapped to `?` and constant/reference definitions inlined as needed.
|
|
331
|
+
- each named definition becomes an `export type` alias (or `export const` for constants).
|
|
332
|
+
- the root model is exported as `export type RootModel = …`.
|
|
333
|
+
|
|
334
|
+
Since no runtime checking is generated, TypeScript export is meant to provide static
|
|
335
|
+
typing over data already validated by another means, e.g. a value checked at runtime
|
|
336
|
+
by the JS backend (see [JavaScript API](#javascript-api)) can be safely cast to the
|
|
337
|
+
corresponding generated TS type.
|
|
338
|
+
|
|
339
|
+
For instance, generate TypeScript declarations:
|
|
340
|
+
|
|
341
|
+
```sh
|
|
342
|
+
jmc -E -F ts -o Person.ts Person
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
This results in, e.g.:
|
|
346
|
+
```ts
|
|
347
|
+
export type Name = string
|
|
348
|
+
|
|
349
|
+
export interface Person {
|
|
350
|
+
name: Name
|
|
351
|
+
birth: string
|
|
352
|
+
friends?: Name[]
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export type RootModel = Person
|
|
356
|
+
```
|
|
357
|
+
|
|
323
358
|
## Web API
|
|
324
359
|
|
|
325
360
|
:warning: :construction_worker: :construction:
|
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Current Tasks
|
|
4
4
|
|
|
5
|
+
- [ ] bench: use local models instead of fetching urls
|
|
6
|
+
- [ ] bench: case failures handling needs some fixing
|
|
7
|
+
- [ ] front: allow to load `.errors.json` file to filter out expected errors
|
|
8
|
+
- [ ] tests: use `.errors.json` file to manage errors, instead of rough counts
|
|
9
|
+
- [ ] models: add model for `*.errors.json` files
|
|
10
|
+
- [ ] tests: run tests inside docker image
|
|
5
11
|
- [ ] tests: check more bad urls (eg bad %-escape)
|
|
12
|
+
- [ ] tests: check pydantic generated classes
|
|
6
13
|
- [ ] static: use combined type test and value extraction when available?
|
|
7
14
|
- [ ] irep: cleanup `propesc2.c` (and others) variable res set but not used
|
|
8
15
|
- [ ] c-backend: factor out str extraction in or-list in more cases
|
|
@@ -110,7 +117,6 @@
|
|
|
110
117
|
- [ ] service: minimal website with editor
|
|
111
118
|
- [ ] tests: fix test with generated json model meta schema
|
|
112
119
|
- [ ] java: joy/johnzon bugs `mv-16/or_0b` JSONP, 100E99 <> 10E100; other JSONP issues, maybe int/float
|
|
113
|
-
- [ ] tests: test generated JSON schema with test vectors.
|
|
114
120
|
- [ ] pr: write `optimizations.model.json` for illustration
|
|
115
121
|
- [ ] pr: write `transformation.model.json` for illustration
|
|
116
122
|
- [ ] pr: sync version number for **all** published parts for _2.0_ release
|
|
@@ -120,7 +126,7 @@
|
|
|
120
126
|
- [ ] predefs: implement `$I32 $I64 $U32 $U64`
|
|
121
127
|
- [ ] pr: tuto add perl and java environment directives? dependencies?
|
|
122
128
|
- [ ] export: improve pydantic, do not generate bad fields (dash and other chars)
|
|
123
|
-
- [ ]
|
|
129
|
+
- [ ] tests: some pydantic exports? imports?
|
|
124
130
|
- [ ] pr: submit jsonschema-benchmark java PR
|
|
125
131
|
- [ ] frontends: reject json with duplicated props
|
|
126
132
|
- [ ] c-backend: header file for generated code?
|
|
@@ -129,7 +135,7 @@
|
|
|
129
135
|
- [ ] tests: parallelize per-case instead of per-dir?
|
|
130
136
|
- [ ] static: shorten xor exit?
|
|
131
137
|
- [ ] c-backend: use vector instructions for larger strcmp?
|
|
132
|
-
- [ ] export: sqlalchemy
|
|
138
|
+
- [ ] export: sqlalchemy?
|
|
133
139
|
- [ ] predefs: add country codes, eg `$COUNTRY $COUNTRY2 $COUNTRY3 $COUNTRYN`
|
|
134
140
|
- [ ] spec: be precise about predefs standard references, eg `$DATE` and co.
|
|
135
141
|
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
# JSON Model Compiler Benchmark Artifacts
|
|
2
2
|
|
|
3
|
+
The purpose of this benchmark is to compare JSON value validation performance for
|
|
4
|
+
the exactly/roughly (see discussion below) the same constraints, independently
|
|
5
|
+
of the syntax used to express these constraints.
|
|
6
|
+
|
|
3
7
|
These artifacts compare
|
|
4
8
|
[JSON Model Compiler (jmc)](https://github.com/clairey-zx81/json-model) generated code using the
|
|
5
9
|
[JSON Schema Utils (jsu)](https://hub.docker.com/repository/docker/zx80/json-schema-utils)
|
|
6
10
|
schema to model converter in C, JS, Java (GSON, Jackson and JSONP using Johnzon) and Python with
|
|
7
|
-
[Sourcemeta Blaze CLI (sbc)](https://github.com/sourcemeta/jsonschema) using test cases
|
|
8
|
-
[JSON Schema Benchmark](https://github.com/sourcemeta-research/jsonschema-benchmark).
|
|
11
|
+
[Sourcemeta Blaze CLI (sbc)](https://github.com/sourcemeta/jsonschema) using test cases and values
|
|
12
|
+
from [JSON Schema Benchmark](https://github.com/sourcemeta-research/jsonschema-benchmark).
|
|
9
13
|
|
|
10
14
|
## Recent Artifacts
|
|
11
15
|
|
|
12
16
|
Overall, depending on the chosen metrics, the JSU converter and JMC C backend are 50 to 90%
|
|
13
17
|
faster than Blaze in these artifacts.
|
|
14
18
|
|
|
19
|
+
- [2026072900](benchmarks/2026072900.md) clang, predefs, jsu 0.9.15/jmc 2.0.52 vs sbc 16.3.0, 11 runs, 1000 iterations.
|
|
20
|
+
- [2026072600](benchmarks/2026072600.md) clang, predefs, jsu 0.9.13/jmc 2.0.52 vs sbc 16.3.0, 11 runs, 1000 iterations.
|
|
21
|
+
- [2026072200](benchmarks/2026072200.md) clang, predefs, jsu 0.9.13/jmc 2.0.52 vs sbc 16.2.1, 11 runs, 1000 iterations.
|
|
22
|
+
- [2026071700](benchmarks/2026071700.md) clang, predefs, jsu 0.9.13/jmc 2.0.52 vs sbc 16.2.0, 11 runs, 1000 iterations.
|
|
23
|
+
- [2026071302](benchmarks/2026071302.md) clang, predefs, jsu 0.9.13/jmc 2.0.52 vs sbc 16.1.0, 11 runs, 1000 iterations.
|
|
15
24
|
- [2026071000](benchmarks/2026071000.md) clang, no predefs, jsu 0.9.12/jmc 2.0.51 vs sbc 16.1.0, 11 runs, 1000 iterations.
|
|
16
25
|
- [2026070900](benchmarks/2026070900.md) clang, no predefs, jsu 0.9.11/jmc 2.0.51 vs sbc 16.1.0, 11 runs, 1000 iterations.
|
|
17
26
|
- [2026062200](benchmarks/2026062200.md) clang, no predefs, jsu 0.9.11/jmc 2.0.51 vs sbc 16.0.0, 11 runs, 1000 iterations.
|
|
@@ -24,16 +33,13 @@ faster than Blaze in these artifacts.
|
|
|
24
33
|
- [2026060300](benchmarks/2026060300.md) clang, no predefs, jsu 0.9.9/jmc 2.0.50 vs sbc 15.8.0, 11 runs, 1000 iterations.
|
|
25
34
|
- [2026060200](benchmarks/2026060200.md) clang, no predefs, jsu 0.9.9/jmc 2.0.50 vs sbc 15.7.0, 11 runs, 1000 iterations.
|
|
26
35
|
- [2026052105](benchmarks/2026052105.md) clang, no predefs, jsu 0.9.9/jmc 2.0.50 vs sbc 15.6.3, 11 runs, 1000 iterations.
|
|
27
|
-
- [2026051900](benchmarks/2026051900.md) clang, no predefs, jsu 0.9.9/jmc 2.0.49 vs sbc 15.6.3, 11 runs, 1000 iterations.
|
|
28
|
-
- [2026051701](benchmarks/2026051701.md) clang, no predefs, jsu 0.9.9/jmc 2.0.49 vs sbc 15.6.2, 11 runs, 1000 iterations.
|
|
29
|
-
- [2026051200](benchmarks/2026051200.md) clang, no predefs, jsu 0.9.9/jmc 2.0.49 vs sbc 15.6.1, 11 runs, 1000 iterations.
|
|
30
36
|
|
|
31
37
|
## Benchmarking Script
|
|
32
38
|
|
|
33
39
|
The [benchmarking script](https://github.com/clairey-zx81/json-model/blob/main/tests/perf/benchmark.sh)
|
|
34
40
|
is provided as docker [docker.io/zx80/jmc-bench-docker](https://hub.docker.com/repository/docker/zx80/jmc-bench-docker)
|
|
35
41
|
or podman [docker.io/zx80/jmc-bench-podman](https://hub.docker.com/repository/docker/zx80/jmc-bench-podman) image.
|
|
36
|
-
It downloads the benchmark
|
|
42
|
+
It downloads the benchmark, and runs through docker-in-docker or podman-in-podman
|
|
37
43
|
[docker.io/zx80/jmc](https://hub.docker.com/repository/docker/zx80/jmc) for JMC runs and
|
|
38
44
|
[ghcr.io/sourcemeta/jsonschema](https://github.com/sourcemeta/jsonschema/pkgs/container/jsonschema)
|
|
39
45
|
for comparison using the Blaze CLI.
|
|
@@ -44,7 +50,7 @@ which will spawn the necessary containers:
|
|
|
44
50
|
|
|
45
51
|
```sh
|
|
46
52
|
JMC=latest JMC_OPTS="--no-predef --cc=clang" \
|
|
47
|
-
nohup ./start_bench.sh latest -p 16 -l 1000 -r 5 &
|
|
53
|
+
nohup ./start_bench.sh latest -p 16 -l 1000 -r 5 -c &
|
|
48
54
|
# in the generated directory, look for the summary markdown and radar json files.
|
|
49
55
|
```
|
|
50
56
|
|
|
@@ -53,6 +59,7 @@ The main script options are:
|
|
|
53
59
|
- `-p PARA` parallelism (a little less that the number of available cores, default is _8_)
|
|
54
60
|
- `-l LOOP` loop iterations for performance average (at least _1000_, the default)
|
|
55
61
|
- `-r RUNS` number of runs (odd number, default is _3_)
|
|
62
|
+
- -c` validate contents (default is _not_)
|
|
56
63
|
|
|
57
64
|
## Benchmarking Conditions
|
|
58
65
|
|
|
@@ -60,6 +67,11 @@ JSON schemas for the benchmark are translated to models based on `jsu-compile`
|
|
|
60
67
|
from [JSON Schema Utils](https://github.com/zx80/json-schema-utils).
|
|
61
68
|
This is mostly an automatic conversion of the test schema to a model, but
|
|
62
69
|
for a few cases have a _native_ model which is used instead.
|
|
70
|
+
Depending on the selected options, the model may be stricter/more accurate than
|
|
71
|
+
the corresponding schema (eg automatic schema fixes such as missing types,
|
|
72
|
+
misplaced keywords or bad regex, or better native models), and induce small
|
|
73
|
+
differences in the validated results, in which case they are manually
|
|
74
|
+
validated and discussed.
|
|
63
75
|
|
|
64
76
|
Runs are performed in _fast_ mode: the rejection reasons are not collected, and
|
|
65
77
|
the run stops as soon as possible.
|
|
@@ -88,7 +100,7 @@ the following caveats, and others:
|
|
|
88
100
|
that retrieving a given property value will cost more than a library which uses
|
|
89
101
|
a hash table which is more costly to build.
|
|
90
102
|
- before version _16.0_, blaze does _not_ implement checking string values (eg dates, url…),
|
|
91
|
-
so these checks may be disactivated (see
|
|
103
|
+
so these checks may be disactivated (see _Contents_ in _Parameters_) for fairness,
|
|
92
104
|
reducing the results significance.
|
|
93
105
|
- blaze uses its own special-purpose JSON representation which include a precomputed
|
|
94
106
|
custom hash for string comparisons, aleviating the need to actually compare strings
|
|
@@ -114,7 +126,7 @@ the following caveats, and others:
|
|
|
114
126
|
also provides
|
|
115
127
|
[benchmark artifacts](https://github.com/sourcemeta-research/jsonschema-benchmark/actions)
|
|
116
128
|
which includes 16 JSON Schema validation tools including our compiler with
|
|
117
|
-
C, JS and Python backends, using the `jsu-compile` command.
|
|
129
|
+
C, JS and Python backends, using the `jsu-compile` command only.
|
|
118
130
|
|
|
119
131
|
It should be noted that benchmarking conditions are quite different compared to our own:
|
|
120
132
|
|
|
@@ -124,10 +136,10 @@ It should be noted that benchmarking conditions are quite different compared to
|
|
|
124
136
|
2. The benchmark focuses on schema conformance, including (buggy) schemas which
|
|
125
137
|
are mostly dead code: It rejects tools which do not validate all strictly conformant
|
|
126
138
|
values, even if these values would be rejected by the target application.
|
|
139
|
+
The model used are strictly converted from schemas, native models are not used
|
|
140
|
+
even if available and schemas are not fixed for typical errors (eg misplaced keywords).
|
|
127
141
|
3. Three schemas (`krakend`, `stale` and `yamllint`) in the test suites have been
|
|
128
142
|
[edited](https://github.com/sourcemeta-research/jsonschema-benchmark/commit/ad109eb210c0939bd8393da28d8212f75c1c2d92),
|
|
129
143
|
especially to deal corner cases issues with `$ref` under version 7 and prior,
|
|
130
144
|
thus do not conform to the initial official schemas.
|
|
131
|
-
4. The benchmark
|
|
132
|
-
5. The model used are strictly converted from schemas, native models are not used
|
|
133
|
-
even if available and schemas are not fixed for typical errors (eg misplaced keywords).
|
|
145
|
+
4. The benchmark _removes_ format assertions before testing schemas.
|
|
@@ -295,6 +295,39 @@ See
|
|
|
295
295
|
[main source code](https://github.com/clairey-zx81/json-model/blob/main/json_model/runtime/c/main.c)
|
|
296
296
|
for a working example involving parameter handling, reading JSON files, and so on.
|
|
297
297
|
|
|
298
|
+
## … export JSON model to Typescript interface?
|
|
299
|
+
|
|
300
|
+
Assuming that the jmc command is available:
|
|
301
|
+
|
|
302
|
+
1. Export the model as a .ts file containing interface/type declarations
|
|
303
|
+
|
|
304
|
+
```sh
|
|
305
|
+
jmc -E -F ts Person-0
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
2. for a model such as:
|
|
309
|
+
|
|
310
|
+
```json
|
|
311
|
+
{ "name": "/^\\w+$/", "born": "$DATE" }
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
The generated .ts file looks like:
|
|
315
|
+
|
|
316
|
+
```ts
|
|
317
|
+
// Typescript interface generated by JSON Model Compiler
|
|
318
|
+
// for Person.model.json
|
|
319
|
+
// see https://json-model.org/
|
|
320
|
+
|
|
321
|
+
export interface Person {
|
|
322
|
+
name: string
|
|
323
|
+
born: string
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
3. Nested definitions ($name), unions (|/^), intersections (&/+)
|
|
328
|
+
and array types are translated to their TypeScript equivalents
|
|
329
|
+
automatically.
|
|
330
|
+
|
|
298
331
|
## … get an Answer?
|
|
299
332
|
|
|
300
333
|
Feel free to [open an issue](https://github.com/clairey-zx81/json-model/issues) for any question.
|
|
@@ -723,7 +723,7 @@ classes very simply using type hints.
|
|
|
723
723
|
Let us export a model to pydantic with the `-E` export task:
|
|
724
724
|
|
|
725
725
|
```sh
|
|
726
|
-
jmc -E -F
|
|
726
|
+
jmc -E -F py -n Root Person-2
|
|
727
727
|
```
|
|
728
728
|
|
|
729
729
|
The generated file provide predeclared classes and types based on all named
|
|
@@ -747,6 +747,30 @@ type Root = Person
|
|
|
747
747
|
|
|
748
748
|
Note that not all constraints and types are implemented.
|
|
749
749
|
|
|
750
|
+
## Exporting as TypeScript interfaces
|
|
751
|
+
|
|
752
|
+
Let us export a model as a typescript interface:
|
|
753
|
+
|
|
754
|
+
```sh
|
|
755
|
+
jmc -E -F ts -n Root Person-2
|
|
756
|
+
```
|
|
757
|
+
|
|
758
|
+
This results in:
|
|
759
|
+
|
|
760
|
+
```ts
|
|
761
|
+
export type Name = string
|
|
762
|
+
|
|
763
|
+
export interface Person {
|
|
764
|
+
name: Name
|
|
765
|
+
birth: string
|
|
766
|
+
friends?: Name[]
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export const Pi = 3.141592653589793238462643
|
|
770
|
+
|
|
771
|
+
export type Root = Person
|
|
772
|
+
```
|
|
773
|
+
|
|
750
774
|
## Exporting to and Importing from JSON Schema
|
|
751
775
|
|
|
752
776
|
Because of its simple structure, most models can be mapped simply to equivalent schemas.
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# JSON Model Compiler Versions
|
|
2
2
|
|
|
3
|
+
## 2.0.53 on 2027-07-29
|
|
4
|
+
|
|
5
|
+
- models: add compatible models for some JSB buggy schemas
|
|
6
|
+
- perf: improve generated reports
|
|
7
|
+
- models: add example model for JMC benchmark radar data
|
|
8
|
+
- pr: check `json-model.org` SEO - listed on Google console but some pages are not indexed
|
|
9
|
+
- perf: keep track of failed tests
|
|
10
|
+
- models: add model for test vectors
|
|
11
|
+
- models: add compatible models for some JSB buggy schemas
|
|
12
|
+
- tests: validate test vectors
|
|
13
|
+
- front: always try to recompute the version
|
|
14
|
+
- export: generate ts interfaces
|
|
15
|
+
- ts-export: manage or error on regex and defs properties
|
|
16
|
+
- ts-export: keep definition order, do not reverse it!
|
|
17
|
+
- pr: add ts export howto section
|
|
18
|
+
- pr: add ts format to jmc pod documentation
|
|
19
|
+
- pr: add ts export to reference documentation
|
|
20
|
+
|
|
3
21
|
## 2.0.52 on 2027-07-13
|
|
4
22
|
|
|
5
23
|
- js-backend: remove useless semi-colons
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.0.53
|
|
@@ -13,7 +13,7 @@ B<jmc> - JSON Model Compiler
|
|
|
13
13
|
[--allow-duplicates] [-[-no]-extend] [--loose-int] [--strict-int] [--loose-float]
|
|
14
14
|
[--strict-float] [--loose-number] [--strict-number] [--loose] [--check]
|
|
15
15
|
[-[-no]-single-line-regex] [-[-no]-optimize] [-[-no]-reporting] [-[-no]-inline]
|
|
16
|
-
[--format {json,yaml,py,c,js,plpgsql,pl,java}] [-[-no]-sort] [--indent INDENT]
|
|
16
|
+
[--format {json,yaml,py,c,js,plpgsql,pl,java,ts}] [-[-no]-sort] [--indent INDENT]
|
|
17
17
|
[--gen {exec,module,code,none} | --executable | --module | --code | --no-gen]
|
|
18
18
|
[--cc CC] [--cflags CFLAGS] [--cppflags CPPFLAGS] [--ldflags LDFLAGS] [-[-no]-precompiled]
|
|
19
19
|
[--include [INCLUDE ...]] [--library [LIBRARY ...]] [--define [DEFINE ...]]
|
|
@@ -31,7 +31,7 @@ B<jmc> - JSON Model Compiler
|
|
|
31
31
|
|
|
32
32
|
The JSON Model Compiler command processes a L<JSON Model|https://json-model.org/> to
|
|
33
33
|
generate modules or scripts in C, JS, Python, PL/pgSQL, Perl, or a more-or-less equivalent
|
|
34
|
-
JSON Schema or
|
|
34
|
+
JSON Schema, pydantic, or TypeScript type declarations.
|
|
35
35
|
|
|
36
36
|
=head1 ARGUMENTS
|
|
37
37
|
|
|
@@ -420,6 +420,10 @@ Formatted in JSON (C<-E -o schema.json>) or yaml (C<-E -o schema.yaml>).
|
|
|
420
420
|
|
|
421
421
|
Generate classes and types with C<-E -o Models.py>).
|
|
422
422
|
|
|
423
|
+
=item B<TypeScript>
|
|
424
|
+
|
|
425
|
+
Generate TypeScript C<interface>/C<type> declarations with C<-E -F ts -o Model.ts>.
|
|
426
|
+
|
|
423
427
|
=back
|
|
424
428
|
|
|
425
429
|
=head1 AUTHORS
|
|
@@ -20,6 +20,7 @@ from . import optim, analyze, objops
|
|
|
20
20
|
from .runtime.types import EntryCheckFun, Report
|
|
21
21
|
from .runtime.support import _path as json_path
|
|
22
22
|
from .export import model2python
|
|
23
|
+
from .ts_export import model2tsinterface
|
|
23
24
|
|
|
24
25
|
# language short name to display name
|
|
25
26
|
LANG = {
|
|
@@ -379,7 +380,7 @@ def jmc_script(xargs: list[str]|None = None) -> int:
|
|
|
379
380
|
help="do not generate anything")
|
|
380
381
|
|
|
381
382
|
# TODO cpp ts rs go…
|
|
382
|
-
arg("--format", "-F", choices=["json", "yaml", "py", "c", "js", "plpgsql", "pl", "java"],
|
|
383
|
+
arg("--format", "-F", choices=["json", "yaml", "py", "c", "js", "plpgsql", "pl", "java", "ts"],
|
|
383
384
|
default=None, help="output language")
|
|
384
385
|
|
|
385
386
|
# C-specific options
|
|
@@ -548,6 +549,7 @@ def jmc_script(xargs: list[str]|None = None) -> int:
|
|
|
548
549
|
# set debug as early as possible
|
|
549
550
|
log.setLevel(logging.DEBUG if args.debug else logging.INFO if args.verbose else logging.WARNING)
|
|
550
551
|
|
|
552
|
+
# shortcut executions
|
|
551
553
|
if args.version:
|
|
552
554
|
print(jmc_version())
|
|
553
555
|
return 0
|
|
@@ -672,7 +674,7 @@ def jmc_script(xargs: list[str]|None = None) -> int:
|
|
|
672
674
|
return 1
|
|
673
675
|
elif args.op == "E":
|
|
674
676
|
args.format = args.format or "json"
|
|
675
|
-
if args.format not in ("json", "yaml", "py"):
|
|
677
|
+
if args.format not in ("json", "yaml", "py", "ts"):
|
|
676
678
|
log.error(f"unexpected format {args.format} for operation {args.op}")
|
|
677
679
|
return 1
|
|
678
680
|
elif args.op == "C":
|
|
@@ -874,6 +876,19 @@ def jmc_script(xargs: list[str]|None = None) -> int:
|
|
|
874
876
|
"# see https://json-model.org/",
|
|
875
877
|
] + model2python(model, root=args.name or "RootModel")
|
|
876
878
|
print("\n".join(code), file=output)
|
|
879
|
+
elif args.format == "ts":
|
|
880
|
+
try:
|
|
881
|
+
interface = model2tsinterface(model, root=args.name or "RootModel")
|
|
882
|
+
except Exception as e:
|
|
883
|
+
log.error(e, exc_info=args.debug)
|
|
884
|
+
return 1
|
|
885
|
+
code = [
|
|
886
|
+
"// Typescript interface generated by JSON Model Compiler",
|
|
887
|
+
f"// for {args.model}",
|
|
888
|
+
"// see https://json-model.org/",
|
|
889
|
+
""
|
|
890
|
+
] + model2tsinterface(model, root=args.name or "RootModel")
|
|
891
|
+
print("\n".join(code), file=output)
|
|
877
892
|
else:
|
|
878
893
|
raise Exception(f"operation not implemented yet: {args.op}")
|
|
879
894
|
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Generate typescript interface from model definitions
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections.abc import Collection
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
from .utils import constant_value
|
|
10
|
+
from .model import JsonModel
|
|
11
|
+
from .language import Block
|
|
12
|
+
from .mtypes import ModelType, ModelError, ModelPath
|
|
13
|
+
from .predefs import INT_MODEL_PREDEFS, FLOAT_MODEL_PREDEFS, BOOL_MODEL_PREDEFS
|
|
14
|
+
|
|
15
|
+
_IDENT = re.compile(r"[A-Za-z_$][\w$]*$")
|
|
16
|
+
_TS_RESERVED = [
|
|
17
|
+
# ECMAScript reserved words
|
|
18
|
+
"break", "case", "catch", "class", "const", "continue", "debugger",
|
|
19
|
+
"default", "delete", "do", "else", "enum", "export", "extends",
|
|
20
|
+
"false", "finally", "for", "function", "if", "import", "in",
|
|
21
|
+
"instanceof", "new", "null", "return", "super", "switch", "this",
|
|
22
|
+
"throw", "true", "try", "typeof", "var", "void", "while", "with",
|
|
23
|
+
# reserved in strict mode / modules
|
|
24
|
+
"await", "implements", "interface", "let", "package", "private",
|
|
25
|
+
"protected", "public", "static", "yield",
|
|
26
|
+
# TypeScript primitive type names — TS2457
|
|
27
|
+
"any", "bigint", "boolean", "never", "number", "object",
|
|
28
|
+
"string", "symbol", "undefined", "unknown",
|
|
29
|
+
]
|
|
30
|
+
_CONST_BASE = {
|
|
31
|
+
type(None): "null",
|
|
32
|
+
bool: "boolean",
|
|
33
|
+
int: "number",
|
|
34
|
+
float: "number",
|
|
35
|
+
str: "string"
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
def _const_base_type(model: ModelType, mpath: ModelPath) -> str:
|
|
39
|
+
_, val = constant_value(_unwrap(model), mpath)
|
|
40
|
+
return _CONST_BASE[type(val)]
|
|
41
|
+
|
|
42
|
+
def _check_name_collisions(names: Collection[str], context: str) -> None:
|
|
43
|
+
seen: dict[str, str] = {}
|
|
44
|
+
for name in names:
|
|
45
|
+
safe = ts_name(name)
|
|
46
|
+
if safe in seen and seen[safe] != name:
|
|
47
|
+
raise ModelError(
|
|
48
|
+
f"Typescript name collision in {context}: "
|
|
49
|
+
f"{seen[safe]!r} and {name!r} both map to identifier {safe!r}"
|
|
50
|
+
)
|
|
51
|
+
seen[safe] = name
|
|
52
|
+
|
|
53
|
+
def ts_name(name: str) -> str:
|
|
54
|
+
safe = re.sub(r"\W", "_", name)
|
|
55
|
+
if not _IDENT.match(safe) or safe in _TS_RESERVED:
|
|
56
|
+
safe = "JM_" + safe
|
|
57
|
+
return safe
|
|
58
|
+
|
|
59
|
+
def _unwrap(model: ModelType) -> ModelType:
|
|
60
|
+
while isinstance(model, dict) and "@" in model:
|
|
61
|
+
model = model["@"]
|
|
62
|
+
return model
|
|
63
|
+
|
|
64
|
+
def _is_const(m):
|
|
65
|
+
m = _unwrap(m)
|
|
66
|
+
return isinstance(m, str) and (m.startswith("=") or m.startswith("_"))
|
|
67
|
+
|
|
68
|
+
def _is_operator(model: ModelType) -> bool:
|
|
69
|
+
return isinstance(model, dict) and any(op in model for op in ("|", "^", "&", "+"))
|
|
70
|
+
|
|
71
|
+
def _combine(name: str, members: list, sep: str, empty: str,
|
|
72
|
+
def_keys: Collection[str]) -> tuple[str, Block]:
|
|
73
|
+
parts: list[str] = []
|
|
74
|
+
hoisted: Block = []
|
|
75
|
+
for i, alt in enumerate(members):
|
|
76
|
+
t, extra = field_type(f"{name}_{i}", alt, def_keys)
|
|
77
|
+
parts.append(t)
|
|
78
|
+
hoisted += extra
|
|
79
|
+
uniq = list(dict.fromkeys(parts))
|
|
80
|
+
if not uniq:
|
|
81
|
+
return empty, hoisted
|
|
82
|
+
if len(uniq) == 1:
|
|
83
|
+
return uniq[0], hoisted
|
|
84
|
+
return "(" + f" {sep} ".join(uniq) + ")", hoisted
|
|
85
|
+
|
|
86
|
+
def _comment(model: ModelType) -> str | None:
|
|
87
|
+
if isinstance(model, dict):
|
|
88
|
+
meta = model.get("#")
|
|
89
|
+
if isinstance(meta, str) and meta:
|
|
90
|
+
return meta
|
|
91
|
+
return None
|
|
92
|
+
|
|
93
|
+
def _comment_block(text: str, indent: str = "") -> Block:
|
|
94
|
+
text = text.replace("*/", "*\\/")
|
|
95
|
+
lines = text.split("\n")
|
|
96
|
+
if len(lines) == 1:
|
|
97
|
+
return [f"{indent}/* {lines[0]} */"]
|
|
98
|
+
return [f"{indent}/*"] + [f"{indent} * {ln}" for ln in lines] + [f"{indent} */"]
|
|
99
|
+
|
|
100
|
+
def m2type(model: ModelType, def_keys: Collection[str]) -> str | None:
|
|
101
|
+
if model is None:
|
|
102
|
+
return "null"
|
|
103
|
+
if isinstance(model, bool):
|
|
104
|
+
return "boolean"
|
|
105
|
+
if isinstance(model, (int, float)):
|
|
106
|
+
return "number"
|
|
107
|
+
if isinstance(model, str):
|
|
108
|
+
if len(model) > 0 and model[0] == "$":
|
|
109
|
+
if model == "$NULL":
|
|
110
|
+
return "null"
|
|
111
|
+
if model == "$ANY":
|
|
112
|
+
return "any"
|
|
113
|
+
if model == "$NONE":
|
|
114
|
+
return "never"
|
|
115
|
+
if model in BOOL_MODEL_PREDEFS:
|
|
116
|
+
return "boolean"
|
|
117
|
+
if model in INT_MODEL_PREDEFS | FLOAT_MODEL_PREDEFS:
|
|
118
|
+
return "number"
|
|
119
|
+
if model[1:] in def_keys:
|
|
120
|
+
return ts_name(model[1:])
|
|
121
|
+
return "string"
|
|
122
|
+
if model.startswith("="):
|
|
123
|
+
return model[1:]
|
|
124
|
+
if model.startswith("_"):
|
|
125
|
+
return json.dumps(model[1:])
|
|
126
|
+
return "string"
|
|
127
|
+
return None
|
|
128
|
+
|
|
129
|
+
def field_type(name: str, model: ModelType, def_keys: Collection[str]) -> tuple[str, Block]:
|
|
130
|
+
model = _unwrap(model)
|
|
131
|
+
if isinstance(model, dict):
|
|
132
|
+
if "|" in model or "^" in model:
|
|
133
|
+
return _combine(name, model.get("|", model.get("^")), "|", "never", def_keys)
|
|
134
|
+
if "&" in model or "+" in model:
|
|
135
|
+
return _combine(name, model.get("&", model.get("+")), "&", "any", def_keys)
|
|
136
|
+
|
|
137
|
+
return ts_name(name), m2ts(name, model, def_keys) + [""]
|
|
138
|
+
if isinstance(model, list):
|
|
139
|
+
cells = [c for c in model if not (isinstance(c, str) and c.startswith("#"))]
|
|
140
|
+
if len(cells) == 1:
|
|
141
|
+
|
|
142
|
+
t, extra = field_type(name, cells[0], def_keys)
|
|
143
|
+
return f"{t}[]", extra
|
|
144
|
+
|
|
145
|
+
parts: list[str] = []
|
|
146
|
+
hoisted: Block = []
|
|
147
|
+
for i, cell in enumerate(cells):
|
|
148
|
+
t, extra = field_type(f"{name}_{i}", cell, def_keys)
|
|
149
|
+
parts.append(t)
|
|
150
|
+
hoisted += extra
|
|
151
|
+
return "[" + ", ".join(parts) + "]", hoisted
|
|
152
|
+
return m2type(model, def_keys) or "any", []
|
|
153
|
+
|
|
154
|
+
def m2ts(name: str, model: ModelType, def_keys: Collection[str], is_def: bool = True) -> Block:
|
|
155
|
+
model = _unwrap(model)
|
|
156
|
+
code: Block = []
|
|
157
|
+
if isinstance(model, dict) and not _is_operator(model):
|
|
158
|
+
props = {k: v for k, v in model.items() if k != "#"}
|
|
159
|
+
fields = [key[1:] if key[:1] in "?!_" else key for key in props]
|
|
160
|
+
_check_name_collisions(fields, f"object {name!r}")
|
|
161
|
+
hoisted: Block = []
|
|
162
|
+
doc = _comment(model)
|
|
163
|
+
code += _comment_block(doc) if doc else []
|
|
164
|
+
code += [f"export interface {ts_name(name)} {{"]
|
|
165
|
+
catch_all_solo = list(props) == [""]
|
|
166
|
+
for key, jm in props.items():
|
|
167
|
+
if key[:1] in ("/", "$"):
|
|
168
|
+
kind = "regex" if key[:1] == "/" else "reference"
|
|
169
|
+
raise ModelError(
|
|
170
|
+
f"cannot export {kind} property name {key!r} in object {name!r} "
|
|
171
|
+
f"as a TypeScript interface: it matches a dynamic set of keys, "
|
|
172
|
+
f"which a TypeScript interface cannot represent"
|
|
173
|
+
)
|
|
174
|
+
optional = key.startswith("?")
|
|
175
|
+
field = key[1:] if key[:1] in "?!_" else key
|
|
176
|
+
safe = ts_name(field)
|
|
177
|
+
if key == "":
|
|
178
|
+
if catch_all_solo:
|
|
179
|
+
ftype, extra = field_type(f"{name}_{safe}", jm, def_keys)
|
|
180
|
+
hoisted += extra
|
|
181
|
+
else:
|
|
182
|
+
ftype = "any"
|
|
183
|
+
code += [f"\t[key: string]: {ftype}"]
|
|
184
|
+
continue
|
|
185
|
+
|
|
186
|
+
ftype, extra = field_type(f"{name}_{safe}", jm, def_keys)
|
|
187
|
+
hoisted += extra
|
|
188
|
+
if _is_const(jm):
|
|
189
|
+
code += _comment_block(f"constant value: {ftype}", "\t")
|
|
190
|
+
ftype = _const_base_type(jm, [name, key])
|
|
191
|
+
prop = field if _IDENT.match(field) else json.dumps(field)
|
|
192
|
+
code += [f"\t{prop}{'?' if optional else ''}: {ftype}"]
|
|
193
|
+
code += ["}"]
|
|
194
|
+
code = hoisted + code
|
|
195
|
+
else:
|
|
196
|
+
base = f"{name}_item" if isinstance(model, list) else name
|
|
197
|
+
ftype, extra = field_type(base, model, def_keys)
|
|
198
|
+
if is_def and _is_const(model):
|
|
199
|
+
code = extra + [f"export const {ts_name(name)} = {ftype}"]
|
|
200
|
+
else:
|
|
201
|
+
code = extra + [f"export type {ts_name(name)} = {ftype}"]
|
|
202
|
+
doc = _comment(model)
|
|
203
|
+
if doc:
|
|
204
|
+
code = _comment_block(doc) + code
|
|
205
|
+
|
|
206
|
+
return code
|
|
207
|
+
|
|
208
|
+
def model2tsinterface(model: JsonModel, root: str|None = "RootModel") -> Block:
|
|
209
|
+
def_keys = model._defs.keys()
|
|
210
|
+
consts = [n for n in def_keys if _is_const(model._defs[n]._model)]
|
|
211
|
+
_check_name_collisions([n for n in def_keys if n not in consts], "definitions ($)")
|
|
212
|
+
winner = {}
|
|
213
|
+
for n in consts:
|
|
214
|
+
ident = ts_name(n)
|
|
215
|
+
if ident in winner:
|
|
216
|
+
raise ModelError(f"const name collision: {winner[ident]!r} and {n!r} both map to {ident!r}")
|
|
217
|
+
winner[ident] = n
|
|
218
|
+
|
|
219
|
+
blocks: list[Block] = []
|
|
220
|
+
for name, jm in model._defs.items():
|
|
221
|
+
blocks.append(m2ts(name, jm._model, def_keys))
|
|
222
|
+
if root is not None:
|
|
223
|
+
blocks.append(m2ts(root, model._model, def_keys, is_def=False))
|
|
224
|
+
code: Block = []
|
|
225
|
+
for b in blocks:
|
|
226
|
+
if code and b:
|
|
227
|
+
code += [""]
|
|
228
|
+
code += b
|
|
229
|
+
return code
|
|
@@ -928,15 +928,15 @@ def simple_object(
|
|
|
928
928
|
return None
|
|
929
929
|
|
|
930
930
|
def jmc_version(dynamic: bool = True) -> str:
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
#
|
|
934
|
-
if dynamic
|
|
935
|
-
log.debug(f"recomputing version {
|
|
931
|
+
"""Get JMC version."""
|
|
932
|
+
version = load_data_file("VERSION").strip()
|
|
933
|
+
# try to recompute the version dynamically
|
|
934
|
+
if dynamic:
|
|
935
|
+
log.debug(f"recomputing version {version}...")
|
|
936
936
|
try:
|
|
937
937
|
from setuptools_git_versioning import get_version
|
|
938
938
|
version = str(get_version(root=pathlib.Path(__file__).parent.parent))
|
|
939
939
|
except Exception as e:
|
|
940
940
|
log.debug(f"error while computing version: {e}")
|
|
941
|
-
|
|
941
|
+
version = __version__
|
|
942
942
|
return version
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.0.52
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_foot.js
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_free.js
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_head.js
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_init.js
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/data/javascript_main.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/java/.gitignore
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/js/package.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/manifest.t
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/pod-coverage.t
RENAMED
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/pl/xt/boilerplate.t
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/sql/json_model--2.0.sql
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model/runtime/sql/json_model.control
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/requires.txt
RENAMED
|
File without changes
|
{json_model_compiler-2.0.52 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|