json-model-compiler 2.0.51__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.
Files changed (131) hide show
  1. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/.github/workflows/sanity.yml +1 -1
  2. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/API.md +36 -1
  3. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/BACKLOG.md +20 -13
  4. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/BENCH.md +28 -13
  5. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/DEV.md +79 -9
  6. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/HOWTO.md +33 -0
  7. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/Makefile +1 -1
  8. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/PKG-INFO +1 -1
  9. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/TUTO.md +33 -7
  10. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/VERSION.md +80 -40
  11. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/about.sh +1 -0
  12. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/clang.py +6 -2
  13. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/convert.py +1 -0
  14. json_model_compiler-2.0.53/json_model/data/VERSION +1 -0
  15. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/jmc.pod +6 -2
  16. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/irep.py +3 -3
  17. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/java.py +44 -1
  18. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/javascript.py +35 -1
  19. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/language.py +5 -3
  20. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/perl.py +24 -1
  21. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/plpgsql.py +1 -1
  22. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/predefs.py +18 -5
  23. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/c/Makefile +2 -2
  24. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/c/json-model.c +602 -17
  25. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/c/json-model.h +10 -0
  26. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/Makefile +8 -1
  27. json_model_compiler-2.0.53/json_model/runtime/java/env.sh +12 -0
  28. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Runtime.java +10 -0
  29. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/pom.xml +5 -4
  30. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/js/index.js +16 -4
  31. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/Makefile.PL +2 -1
  32. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/lib/JSON/JsonModel.pm +37 -3
  33. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/sql/META.json +3 -3
  34. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/sql/json_model--2.0.sql +2 -1
  35. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/support.py +17 -2
  36. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/script.py +28 -2
  37. json_model_compiler-2.0.53/json_model/ts_export.py +229 -0
  38. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/utils.py +6 -6
  39. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/xstatic.py +9 -11
  40. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/PKG-INFO +1 -1
  41. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/SOURCES.txt +1 -0
  42. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/package.json +2 -1
  43. json_model_compiler-2.0.51/json_model/data/VERSION +0 -1
  44. json_model_compiler-2.0.51/json_model/runtime/java/env.sh +0 -10
  45. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/.gitignore +0 -0
  46. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/.gitmodules +0 -0
  47. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/DESIGN.md +0 -0
  48. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/DOC.md +0 -0
  49. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/INTEGRATION.md +0 -0
  50. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/MANIFEST.in +0 -0
  51. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/PUBS.md +0 -0
  52. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/README.md +0 -0
  53. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/SPEC.md +0 -0
  54. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/README.md +0 -0
  55. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/__init__.py +0 -0
  56. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/analyze.py +0 -0
  57. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/clang_entry.c +0 -0
  58. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/clang_free.c +0 -0
  59. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/clang_init.c +0 -0
  60. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/clang_pcre2_fun.c +0 -0
  61. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/clang_re2_fun.c +0 -0
  62. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/java_free.java +0 -0
  63. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/java_init.java +0 -0
  64. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/javascript_exe.js +0 -0
  65. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/javascript_foot.js +0 -0
  66. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/javascript_free.js +0 -0
  67. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/javascript_head.js +0 -0
  68. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/javascript_init.js +0 -0
  69. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/javascript_main.js +0 -0
  70. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/perl_entry.pl +0 -0
  71. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/perl_exe.pl +0 -0
  72. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/perl_free.pl +0 -0
  73. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/perl_init.pl +0 -0
  74. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/perl_main.pl +0 -0
  75. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/perl_pkg.pl +0 -0
  76. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/plpgsql_entry.sql +0 -0
  77. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/python_entry.py +0 -0
  78. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/python_exe.py +0 -0
  79. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/python_free.py +0 -0
  80. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/python_init.py +0 -0
  81. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/data/python_main.py +0 -0
  82. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/export.py +0 -0
  83. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/model.py +0 -0
  84. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/mtypes.py +0 -0
  85. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/objops.py +0 -0
  86. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/optim.py +0 -0
  87. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/python.py +0 -0
  88. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/recurse.py +0 -0
  89. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/regex.py +0 -0
  90. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/resolver.py +0 -0
  91. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/Makefile +0 -0
  92. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/__init__.py +0 -0
  93. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/c/main.c +0 -0
  94. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/.gitignore +0 -0
  95. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/README.md +0 -0
  96. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Checker.java +0 -0
  97. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/GSON.java +0 -0
  98. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/JSON.java +0 -0
  99. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/JSONP.java +0 -0
  100. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Jackson.java +0 -0
  101. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Main.java +0 -0
  102. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/ModelChecker.java +0 -0
  103. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Path.java +0 -0
  104. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/java/json_model/Report.java +0 -0
  105. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/js/README.md +0 -0
  106. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/js/main.js +0 -0
  107. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/js/package.json +0 -0
  108. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/.gitignore +0 -0
  109. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/Changes +0 -0
  110. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/LICENSE +0 -0
  111. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/MANIFEST +0 -0
  112. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/README +0 -0
  113. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/env.sh +0 -0
  114. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/ignore.txt +0 -0
  115. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/00-load.t +0 -0
  116. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/manifest.t +0 -0
  117. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/pod-coverage.t +0 -0
  118. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/t/pod.t +0 -0
  119. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/pl/xt/boilerplate.t +0 -0
  120. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/sql/Makefile +0 -0
  121. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/sql/json_model.control +0 -0
  122. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/runtime/types.py +0 -0
  123. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/submodel.py +0 -0
  124. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model/url_cache.py +0 -0
  125. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/dependency_links.txt +0 -0
  126. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/entry_points.txt +0 -0
  127. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/not-zip-safe +0 -0
  128. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/requires.txt +0 -0
  129. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/json_model_compiler.egg-info/top_level.txt +0 -0
  130. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/pyproject.toml +0 -0
  131. {json_model_compiler-2.0.51 → json_model_compiler-2.0.53}/setup.cfg +0 -0
@@ -9,7 +9,7 @@ jobs:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
11
  - name: Checkout project
12
- uses: actions/checkout@v6
12
+ uses: actions/checkout@v7
13
13
  - name: Set up Python
14
14
  uses: actions/setup-python@v6
15
15
  - name: Install Package Stuff
@@ -249,7 +249,7 @@ This generated code exports 4 useful functions:
249
249
  plus two parameters which must be `undef` for now.
250
250
 
251
251
  The generated functions and runtime depends in `JSON::JsonModel`, `re::engine::RE2`,
252
- `JSON::MaybeXS` for JSON.
252
+ `JSON::MaybeXS` and `Algorithm::LUHN`.
253
253
 
254
254
  For instance, generate a Perl module:
255
255
 
@@ -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,16 +2,22 @@
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
11
+ - [ ] tests: check more bad urls (eg bad %-escape)
12
+ - [ ] tests: check pydantic generated classes
13
+ - [ ] static: use combined type test and value extraction when available?
14
+ - [ ] irep: cleanup `propesc2.c` (and others) variable res set but not used
5
15
  - [ ] c-backend: factor out str extraction in or-list in more cases
6
- - [ ] pl-backend: use short post-if where possible (filtering)
7
- - [ ] pl-backend: use `unless` where appropriate (filtering?)
8
- - [ ] js-backend: remove useless braces and semi-colons
9
- - [ ] java-backend: remove useless braces
10
16
  - [ ] export: generate a [katydid](https://katydid.github.io/) expression, for a compatible subset
17
+ - [ ] static: factor out common checks on `&` with shared constraints?
11
18
  - [ ] front: generate valid minimal, maximal and random values from a model
12
19
  - [ ] front: generate invalid minimal values from a model
13
20
  - [ ] optim: simplify some '!=' cases
14
- - [ ] perf: run benchmark for formats/predefs enabled
15
21
  - [ ] spec: allow to _remove_ definitions, eg `{ "$stuff": {"/": "$foo"}}`
16
22
  - [ ] static: check for common object part
17
23
  - [ ] perf: add another loop over performance collection?
@@ -57,7 +63,6 @@
57
63
  - [ ] predefs: improve `$URI` and `$URL`
58
64
  - [ ] backend: check leap-second support on `$DATETIME` and `$TIME`
59
65
  - [ ] doc: add _known limitations_ stuff
60
- - [ ] doc: improve developer documentation
61
66
  - [ ] spec: restrict regex syntax to a smaller subset
62
67
  - [ ] predefs: add `$SIMPLE_REGEX` for regex syntax subset?
63
68
  - [ ] docker: enable user remap
@@ -112,7 +117,6 @@
112
117
  - [ ] service: minimal website with editor
113
118
  - [ ] tests: fix test with generated json model meta schema
114
119
  - [ ] java: joy/johnzon bugs `mv-16/or_0b` JSONP, 100E99 <> 10E100; other JSONP issues, maybe int/float
115
- - [ ] tests: test generated JSON schema with test vectors.
116
120
  - [ ] pr: write `optimizations.model.json` for illustration
117
121
  - [ ] pr: write `transformation.model.json` for illustration
118
122
  - [ ] pr: sync version number for **all** published parts for _2.0_ release
@@ -122,7 +126,7 @@
122
126
  - [ ] predefs: implement `$I32 $I64 $U32 $U64`
123
127
  - [ ] pr: tuto add perl and java environment directives? dependencies?
124
128
  - [ ] export: improve pydantic, do not generate bad fields (dash and other chars)
125
- - [ ] test: some pydantic exports? imports?
129
+ - [ ] tests: some pydantic exports? imports?
126
130
  - [ ] pr: submit jsonschema-benchmark java PR
127
131
  - [ ] frontends: reject json with duplicated props
128
132
  - [ ] c-backend: header file for generated code?
@@ -131,7 +135,7 @@
131
135
  - [ ] tests: parallelize per-case instead of per-dir?
132
136
  - [ ] static: shorten xor exit?
133
137
  - [ ] c-backend: use vector instructions for larger strcmp?
134
- - [ ] export: sqlalchemy
138
+ - [ ] export: sqlalchemy?
135
139
  - [ ] predefs: add country codes, eg `$COUNTRY $COUNTRY2 $COUNTRY3 $COUNTRYN`
136
140
  - [ ] spec: be precise about predefs standard references, eg `$DATE` and co.
137
141
 
@@ -142,22 +146,24 @@
142
146
  - [ ] tests: add a few tests for jsonrpc model
143
147
  - [ ] model: write a model for MCP
144
148
  - [ ] tests: add a few tests for MCP model
149
+ - [ ] model: add a clean model for SAP UI5 tools?
145
150
  - [ ] model: update and test `ri.model.json`
146
151
  - [ ] export: generate ts interfaces
147
- - [ ] export: katydid?
148
- - [ ] backend: improve generated code with filters for js, java, pl
149
152
  - [ ] tests: improve predef validators cross-language consistency
150
153
  - [ ] tests: generate invalid minimal, maximal, random values
151
154
  - [ ] tests: generate invalid values on each constraint
152
- - [ ] backend: C and runtime with other json lib
155
+ - [ ] backend: C and runtime with json-c
153
156
  - [ ] backend: C++
154
157
  - [ ] backend: go
155
158
  - [ ] backend: php
156
159
  - [ ] backend: ruby
157
160
  - [ ] backend: rust
161
+ - [ ] backend: test and fix existing dart backend MR
158
162
  - [ ] export: generate annotated java interfaces/classes?
159
163
  - [ ] tool: jmc api in flask
160
164
  - [ ] front: allow IR re-entrance?
165
+ - [ ] export: katydid?
166
+ - [ ] api: json model as a service backend with flask
161
167
 
162
168
  ## Re Do
163
169
 
@@ -342,7 +348,8 @@
342
348
  - [ ] design: documentation use case, with added _markdown description_
343
349
  - [ ] pr: validation must be optimized for the valid case, as it is the most likely.
344
350
  - [ ] case: use trafo in geo to have either 2 or 3 vectors, no mix.
351
+ - [ ] c-backend: consider [json-c](https://github.com/json-c/json-c)
345
352
  - [ ] c-backend: consider [yyjson](https://github.com/ibireme/yyjson)
346
353
  - [ ] c-backend: consider [cJSON](https://github.com/davegamble/cjson) (linked lists? no ints?…)
347
- - [ ] c-backend: consider [json-c](https://github.com/json-c/json-c)
354
+ - [ ] ~c-backend: consider [Parson](https://github.com/kgabis/parson) (unmaintained?)~
348
355
  - [ ] ~c-backend: consider [json.h](https://github.com/sheredom/json.h) (hmmm, linked lists)~
@@ -1,17 +1,29 @@
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 from
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.
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.
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.
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.
15
27
  - [2026062102](benchmarks/2026062102.md) clang, no predefs, jsu 0.9.10/jmc 2.0.50 vs sbc 16.0.0, 11 runs, 1000 iterations.
16
28
  - [2026061700](benchmarks/2026061700.md) clang, no predefs, jsu 0.9.9/jmc 2.0.50 vs sbc 16.0.0, 11 runs, 1000 iterations.
17
29
  - [2026061300](benchmarks/2026061300.md) clang, no predefs, jsu 0.9.9/jmc 2.0.50 vs sbc 15.11.0, 11 runs, 1000 iterations.
@@ -21,16 +33,13 @@ faster than Blaze in these artifacts.
21
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.
22
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.
23
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.
24
- - [2026051900](benchmarks/2026051900.md) clang, no predefs, jsu 0.9.9/jmc 2.0.49 vs sbc 15.6.3, 11 runs, 1000 iterations.
25
- - [2026051701](benchmarks/2026051701.md) clang, no predefs, jsu 0.9.9/jmc 2.0.49 vs sbc 15.6.2, 11 runs, 1000 iterations.
26
- - [2026051200](benchmarks/2026051200.md) clang, no predefs, jsu 0.9.9/jmc 2.0.49 vs sbc 15.6.1, 11 runs, 1000 iterations.
27
36
 
28
37
  ## Benchmarking Script
29
38
 
30
39
  The [benchmarking script](https://github.com/clairey-zx81/json-model/blob/main/tests/perf/benchmark.sh)
31
40
  is provided as docker [docker.io/zx80/jmc-bench-docker](https://hub.docker.com/repository/docker/zx80/jmc-bench-docker)
32
41
  or podman [docker.io/zx80/jmc-bench-podman](https://hub.docker.com/repository/docker/zx80/jmc-bench-podman) image.
33
- It downloads the benchmark schemas and test values, and runs through docker-in-docker or podman-in-podman
42
+ It downloads the benchmark, and runs through docker-in-docker or podman-in-podman
34
43
  [docker.io/zx80/jmc](https://hub.docker.com/repository/docker/zx80/jmc) for JMC runs and
35
44
  [ghcr.io/sourcemeta/jsonschema](https://github.com/sourcemeta/jsonschema/pkgs/container/jsonschema)
36
45
  for comparison using the Blaze CLI.
@@ -41,7 +50,7 @@ which will spawn the necessary containers:
41
50
 
42
51
  ```sh
43
52
  JMC=latest JMC_OPTS="--no-predef --cc=clang" \
44
- nohup ./start_bench.sh latest -p 16 -l 1000 -r 5 &
53
+ nohup ./start_bench.sh latest -p 16 -l 1000 -r 5 -c &
45
54
  # in the generated directory, look for the summary markdown and radar json files.
46
55
  ```
47
56
 
@@ -50,6 +59,7 @@ The main script options are:
50
59
  - `-p PARA` parallelism (a little less that the number of available cores, default is _8_)
51
60
  - `-l LOOP` loop iterations for performance average (at least _1000_, the default)
52
61
  - `-r RUNS` number of runs (odd number, default is _3_)
62
+ - -c` validate contents (default is _not_)
53
63
 
54
64
  ## Benchmarking Conditions
55
65
 
@@ -57,6 +67,11 @@ JSON schemas for the benchmark are translated to models based on `jsu-compile`
57
67
  from [JSON Schema Utils](https://github.com/zx80/json-schema-utils).
58
68
  This is mostly an automatic conversion of the test schema to a model, but
59
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.
60
75
 
61
76
  Runs are performed in _fast_ mode: the rejection reasons are not collected, and
62
77
  the run stops as soon as possible.
@@ -84,8 +99,8 @@ the following caveats, and others:
84
99
  for faster parsing, a library may use linked-list for properties, which means
85
100
  that retrieving a given property value will cost more than a library which uses
86
101
  a hash table which is more costly to build.
87
- - blaze does _not_ implement checking string values (eg dates, url…),
88
- so these checks may be disactivated (see `JMC_OPTS`) for fairness,
102
+ - before version _16.0_, blaze does _not_ implement checking string values (eg dates, url…),
103
+ so these checks may be disactivated (see _Contents_ in _Parameters_) for fairness,
89
104
  reducing the results significance.
90
105
  - blaze uses its own special-purpose JSON representation which include a precomputed
91
106
  custom hash for string comparisons, aleviating the need to actually compare strings
@@ -111,7 +126,7 @@ the following caveats, and others:
111
126
  also provides
112
127
  [benchmark artifacts](https://github.com/sourcemeta-research/jsonschema-benchmark/actions)
113
128
  which includes 16 JSON Schema validation tools including our compiler with
114
- C, JS and Python backends, using the `jsu-compile` command.
129
+ C, JS and Python backends, using the `jsu-compile` command only.
115
130
 
116
131
  It should be noted that benchmarking conditions are quite different compared to our own:
117
132
 
@@ -121,10 +136,10 @@ It should be noted that benchmarking conditions are quite different compared to
121
136
  2. The benchmark focuses on schema conformance, including (buggy) schemas which
122
137
  are mostly dead code: It rejects tools which do not validate all strictly conformant
123
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).
124
141
  3. Three schemas (`krakend`, `stale` and `yamllint`) in the test suites have been
125
142
  [edited](https://github.com/sourcemeta-research/jsonschema-benchmark/commit/ad109eb210c0939bd8393da28d8212f75c1c2d92),
126
143
  especially to deal corner cases issues with `$ref` under version 7 and prior,
127
144
  thus do not conform to the initial official schemas.
128
- 4. The benchmark _removes_ format assertions before testing schemas.
129
- 5. The model used are strictly converted from schemas, native models are not used
130
- even if available and schemas are not fixed for typical errors (eg misplaced keywords).
145
+ 4. The benchmark _removes_ format assertions before testing schemas.
@@ -6,7 +6,7 @@ Beware that the developer documentation is scarce. PR are always welcome, eg:
6
6
 
7
7
  - new language or library support implementations
8
8
  - new exporters
9
- - possibly new models
9
+ - new native models
10
10
  - generated code optimizations
11
11
 
12
12
  ## Publication Accounts
@@ -41,26 +41,95 @@ git clone --recursive-submodules git@github.com:clairey-zx81/json-model.git
41
41
  cd json-model
42
42
  ```
43
43
 
44
- If you intend to develop and submit a PR, fork the repos before cloning.
44
+ If you intend to develop and submit a PR, fork the repos before cloning, and create a branch.
45
+ Use `pull` with `rebase` to ensure a linear commit history.
45
46
 
46
- To setup a local developer environment, run at the root of the project:
47
+ There are 3 branches:
48
+
49
+ - `main` for releases
50
+ - `post` for post-release changes
51
+ - `dev` for fixes and features
52
+
53
+ New things happen on `dev`, the are merged into `main` for release from time to time.
54
+ Branch `post` is used to add new benchmark artifacts out of the release cycle.
55
+
56
+ The `post`/`main` branches and `main` tags are needed so that automatic versioning works.
57
+
58
+ To setup a local developer environment, run at the root of the project, try `make dev`.
47
59
 
48
60
  ```sh
49
61
  # for Python
50
- make dev
62
+ make dev.py
51
63
  source venv/bin/activate
52
64
  # for JS
53
65
  npm install
54
- # for Perl
66
+ # for Perl, install dependencies, see "PREREQ_PM" in Makefile.PL, then:
55
67
  source $PWD/json_model/runtime/pl/env.bash
56
68
  # for Java
57
- # get needed dependency jars (see pom.xml), then
58
- make -C json_model/runtime/java jar
69
+ # get needed dependencies and compile jar
70
+ make -C json_model/runtime/java mvn.jar mvn.deps
59
71
  source $PWD/json_model/runtime/java/env.bash
60
72
  # for C
61
- # install pcre2, cre2, gnu getopt, jansson
73
+ # install pcre2, cre2, gnu getopt, jansson, compile runtime
74
+ make -C json_model/runtime/c compile
62
75
  # for SQL
63
- # have psql ready to connect to a local Postgres
76
+ # have psql ready to connect to a local Postgres, and the permissions to
77
+ # create databases and install the `json_model` extension (for running tests).
78
+ ```
79
+
80
+ It can be convenient to have a local `env.sh` (or similar) file at the root
81
+ of the project to setup the needed environment:
82
+
83
+ ```bash
84
+ # File env.sh
85
+ source venv/bin/activate
86
+ source $PWD/json_model/runtime/pl/env.sh
87
+ source $PWD/json_model/runtime/java/env.sh
88
+ ```
89
+
90
+ ## Tests
91
+
92
+ Tests use `pytest`, possibly through `make`.
93
+
94
+ ### Root directory
95
+
96
+ Python linting (not well maintained) and non regression tests
97
+
98
+ ```bash
99
+ make check
100
+ make check.src # linting
101
+ make check.tests # tests
102
+ ```
103
+
104
+ ### Tests directory
105
+
106
+ Pytests tests inside `tests`
107
+
108
+ ```bash
109
+ make check # run pytest tests in parallel
110
+ make check.check # regenerate all reference files
111
+ make clean.js js # regenerate javascript stuff
112
+ make clean.java java # regenerate java stuff
113
+ make clean.pl pl # regenerate pl stuff
114
+ make clean # remove intermediate files
115
+ ```
116
+
117
+ Example manual command:
118
+
119
+ ```bash
120
+ pytest -n auto -k mv-22 tests.py
121
+ ```
122
+
123
+ ### Tests subdirectories
124
+
125
+ Subdirectories provide a parallel work unit:
126
+
127
+ ```bash
128
+ make gen # generate reference files
129
+ make check # regenerate reference files
130
+ make clean # remove intermediate files
131
+ make clean.js js # regenerate js stuff (and other languages)
132
+ make foo.CLEAN foo.ALL # clean/regenerate all stuff for case "foo"
64
133
  ```
65
134
 
66
135
  ## Code Doc
@@ -74,6 +143,7 @@ Section _The jmc Compiler_ is not too bad for an initial understanding.
74
143
  Procedure for releasing a new python package version:
75
144
 
76
145
  - consider releasing both JSU and JMC at the same time!
146
+ - consider testing bowtie and jsonschema-benchmark dockers with the dev branch
77
147
  - merge `dev` changes into the `main` branch
78
148
  - update `json_model/data/VERSION`, `BACKLOG.md` and `VERSION.md`
79
149
  - `git commit` and `git tag` as new version
@@ -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.
@@ -48,7 +48,7 @@ node_modules:
48
48
  # FIXME get jar dependencies? rely on mvn?
49
49
  .PHONY: dev.java
50
50
  dev.java:
51
- $(MAKE) -C json_model/runtime/java jar
51
+ $(MAKE) -C json_model/runtime/java mvn.jar mvn.deps
52
52
 
53
53
  #
54
54
  # CLEANUP
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: json_model_compiler
3
- Version: 2.0.51
3
+ Version: 2.0.53
4
4
  Summary: JSON Model Tools
5
5
  Author: Fabien Coelho, Claire Yannou-Medrala
6
6
  License-Expression: CC0-1.0
@@ -249,7 +249,7 @@ jmc --name Pi Person-2 pi.json # PASS
249
249
  A common use case is to define some data structure and to reuse them in other
250
250
  related settings, much like one would _import_ a module or _include_ a header file.
251
251
  JSON Model allows definitions to be local or remote URLs so as to fetch and reuse
252
- external models easily.
252
+ external models easily. Here the `#` keyword is not a comment but a definition selector.
253
253
 
254
254
  Let us write file `Class.model.json` which reuses `Person-2.model.json` by loading
255
255
  it as a file (`$./Person-2`) for defining the class name and array of students:
@@ -320,7 +320,8 @@ jmc Loose moe.json # PASS
320
320
  A common pattern is to allow several kind of object as some point in the data structure,
321
321
  aka a _union_.
322
322
  This can be expressed with a model involving either the special `^` (xor, one-of) or `|`
323
- (or, any-of) property with an array of possible models.
323
+ (or, any-of) property with an array of possible models. A sample value stands for its whole type,
324
+ and its sign selects the range: -1.0 means any float, 0.0 non-negative, 1.0 strictly positive — likewise -1, 0, 1 for integers.
324
325
 
325
326
  Let us consider the model in file `Geom.model.json`, which defines a coordinate (`coord`) as
326
327
  a pair of numbers, and use it for point and segment objects:
@@ -328,15 +329,15 @@ a pair of numbers, and use it for point and segment objects:
328
329
  ```json
329
330
  {
330
331
  "#": "Geometrical Model",
331
- "$": { "coord": [ -1.0, -1.0 ] },
332
+ "$": { "Coord": [ -1.0, -1.0 ] },
332
333
  "^": [
333
334
  {
334
335
  "type": "_Point",
335
- "data": "$coord"
336
+ "data": "$Coord"
336
337
  },
337
338
  {
338
339
  "type": "_Segment",
339
- "data": [ "$coord", "$coord" ]
340
+ "data": [ "$Coord", "$Coord" ]
340
341
  }
341
342
  ]
342
343
  }
@@ -678,11 +679,12 @@ jmc -o Person.java Person-2 # Java class
678
679
  jmc -o person.sql Person-2 # PL/pgSQL functions
679
680
  ```
680
681
 
682
+ If you have postgresql instance installed then:
681
683
  Here is an example of checking JSONB values inside Postgres, by importing
682
684
  JSON Model runtime and generated code:
683
685
 
684
686
  ```sh
685
- sudo make -C json_model/runtime install # install runtime
687
+ sudo make -C json_model/runtime/sql install # install runtime
686
688
  # OR: sudo pgxn install json_model
687
689
  psql -f person.sql # load runtime and model checking functions
688
690
  ```
@@ -721,7 +723,7 @@ classes very simply using type hints.
721
723
  Let us export a model to pydantic with the `-E` export task:
722
724
 
723
725
  ```sh
724
- jmc -E -F PersonModels.py -n Root Person-2
726
+ jmc -E -F py -n Root Person-2
725
727
  ```
726
728
 
727
729
  The generated file provide predeclared classes and types based on all named
@@ -745,6 +747,30 @@ type Root = Person
745
747
 
746
748
  Note that not all constraints and types are implemented.
747
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
+
748
774
  ## Exporting to and Importing from JSON Schema
749
775
 
750
776
  Because of its simple structure, most models can be mapped simply to equivalent schemas.