subschema 0.0.1__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 (46) hide show
  1. subschema-0.0.1/.gitignore +28 -0
  2. subschema-0.0.1/LICENSE +177 -0
  3. subschema-0.0.1/PKG-INFO +102 -0
  4. subschema-0.0.1/README.md +85 -0
  5. subschema-0.0.1/pyproject.toml +76 -0
  6. subschema-0.0.1/src/subschema/__init__.py +19 -0
  7. subschema-0.0.1/src/subschema/api.py +172 -0
  8. subschema-0.0.1/src/subschema/cli.py +75 -0
  9. subschema-0.0.1/src/subschema/dialects.py +484 -0
  10. subschema-0.0.1/src/subschema/exceptions.py +100 -0
  11. subschema-0.0.1/src/subschema/kernel/__init__.py +33 -0
  12. subschema-0.0.1/src/subschema/kernel/applicators.py +1644 -0
  13. subschema-0.0.1/src/subschema/kernel/certificates.py +14 -0
  14. subschema-0.0.1/src/subschema/kernel/composition.py +188 -0
  15. subschema-0.0.1/src/subschema/kernel/constraints.py +93 -0
  16. subschema-0.0.1/src/subschema/kernel/context.py +131 -0
  17. subschema-0.0.1/src/subschema/kernel/contracts.py +243 -0
  18. subschema-0.0.1/src/subschema/kernel/difference.py +6252 -0
  19. subschema-0.0.1/src/subschema/kernel/disjointness.py +133 -0
  20. subschema-0.0.1/src/subschema/kernel/domains/__init__.py +3 -0
  21. subschema-0.0.1/src/subschema/kernel/domains/arrays.py +913 -0
  22. subschema-0.0.1/src/subschema/kernel/domains/numbers.py +731 -0
  23. subschema-0.0.1/src/subschema/kernel/domains/objects.py +2219 -0
  24. subschema-0.0.1/src/subschema/kernel/domains/strings.py +744 -0
  25. subschema-0.0.1/src/subschema/kernel/domains/types.py +543 -0
  26. subschema-0.0.1/src/subschema/kernel/driver.py +104 -0
  27. subschema-0.0.1/src/subschema/kernel/engine.py +63 -0
  28. subschema-0.0.1/src/subschema/kernel/evaluation.py +924 -0
  29. subschema-0.0.1/src/subschema/kernel/finite.py +715 -0
  30. subschema-0.0.1/src/subschema/kernel/formulas.py +668 -0
  31. subschema-0.0.1/src/subschema/kernel/ir.py +735 -0
  32. subschema-0.0.1/src/subschema/kernel/json_data.py +88 -0
  33. subschema-0.0.1/src/subschema/kernel/normalization.py +65 -0
  34. subschema-0.0.1/src/subschema/kernel/overlaps.py +152 -0
  35. subschema-0.0.1/src/subschema/kernel/projection.py +99 -0
  36. subschema-0.0.1/src/subschema/kernel/references.py +1047 -0
  37. subschema-0.0.1/src/subschema/kernel/regex.py +1006 -0
  38. subschema-0.0.1/src/subschema/kernel/sat.py +3153 -0
  39. subschema-0.0.1/src/subschema/kernel/scalars.py +651 -0
  40. subschema-0.0.1/src/subschema/kernel/schemas.py +206 -0
  41. subschema-0.0.1/src/subschema/kernel/semantic.py +833 -0
  42. subschema-0.0.1/src/subschema/kernel/symbolic.py +201 -0
  43. subschema-0.0.1/src/subschema/kernel/validation.py +422 -0
  44. subschema-0.0.1/src/subschema/kernel/values.py +56 -0
  45. subschema-0.0.1/src/subschema/kernel/witnesses.py +824 -0
  46. subschema-0.0.1/uv.lock +1121 -0
@@ -0,0 +1,28 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ .mypy_cache/
9
+ .coverage
10
+ htmlcov/
11
+
12
+ # Virtual environments
13
+ .venv/
14
+ .venv-*/
15
+
16
+ # Packaging
17
+ build/
18
+ dist/
19
+ *.egg-info/
20
+
21
+ # Local/editor files
22
+ .vscode/
23
+ .DS_Store
24
+
25
+ # Project-local generated files
26
+ PLAN.md
27
+ sbom.json
28
+ examples/
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: subschema
3
+ Version: 0.0.1
4
+ Summary: A conservative JSON Schema subschema prover
5
+ Project-URL: Homepage, https://github.com/ArakawaHenri/subschema
6
+ Project-URL: Repository, https://github.com/ArakawaHenri/subschema
7
+ Author-email: Henri <henri-zhang@outlook.com>
8
+ License-Expression: Apache-2.0
9
+ License-File: LICENSE
10
+ Requires-Python: >=3.12
11
+ Requires-Dist: greenery>=4.0.0
12
+ Requires-Dist: jsonschema
13
+ Requires-Dist: jsonschema-rs>=0.46.5
14
+ Requires-Dist: referencing
15
+ Requires-Dist: z3-solver
16
+ Description-Content-Type: text/markdown
17
+
18
+ # subschema
19
+
20
+ `subschema` is a conservative prover for JSON Schema subschema checks.
21
+
22
+ For JSON Schemas `lhs` and `rhs`, `lhs <: rhs` means every JSON instance that
23
+ validates against `lhs` also validates against `rhs`.
24
+
25
+ The PyPI package, Python import package, and CLI command are named `subschema`.
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ pip install subschema
31
+ ```
32
+
33
+ For local development:
34
+
35
+ ```bash
36
+ uv sync --locked --group dev
37
+ uv run pytest -q
38
+ uv run ruff check .
39
+ ```
40
+
41
+ ## CLI
42
+
43
+ ```bash
44
+ subschema lhs.json rhs.json
45
+ ```
46
+
47
+ The command prints whether `lhs.json <: rhs.json`.
48
+
49
+ Finite expensive proof products can be enabled explicitly:
50
+
51
+ ```bash
52
+ subschema --endeavor --max-work 20000 --timeout-ms 3000 lhs.json rhs.json
53
+ ```
54
+
55
+ `max_work` and `timeout_ms` are only accepted with `--endeavor`. A value of `-1`
56
+ means unlimited for that control.
57
+
58
+ ## Python API
59
+
60
+ ```python
61
+ from subschema import Dialect, is_subschema
62
+
63
+ lhs = {"type": "integer"}
64
+ rhs = {"type": "number"}
65
+
66
+ print(is_subschema(lhs, rhs, dialect=Dialect.DRAFT202012))
67
+ ```
68
+
69
+ Available public entrypoints:
70
+
71
+ - `is_subschema(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
72
+ - `is_equivalent(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
73
+ - `meet_schemas(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
74
+ - `join_schemas(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
75
+ - `canonicalize_schema(schema, *, dialect=None)`
76
+
77
+ ## Dialects
78
+
79
+ Draft 2020-12 is the default dialect for calls without an explicit dialect or
80
+ `$schema` declaration. Older dialects can be selected by passing `dialect=...`
81
+ or by using a `$schema` declaration.
82
+
83
+ Supported dialects:
84
+
85
+ - Draft 4
86
+ - Draft 6
87
+ - Draft 7
88
+ - Draft 2019-09
89
+ - Draft 2020-12
90
+
91
+ The prover is intentionally conservative. Unsupported, unbounded, recursive, or
92
+ exhausted proof fragments are reported instead of being silently approximated.
93
+
94
+ ## Acknowledgement
95
+
96
+ This project is a rewrite based on IBM's
97
+ [jsonsubschema](https://github.com/IBM/jsonsubschema) project and may retain
98
+ portions of its source code. Credit to IBM and contributors.
99
+
100
+ ## License
101
+
102
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,85 @@
1
+ # subschema
2
+
3
+ `subschema` is a conservative prover for JSON Schema subschema checks.
4
+
5
+ For JSON Schemas `lhs` and `rhs`, `lhs <: rhs` means every JSON instance that
6
+ validates against `lhs` also validates against `rhs`.
7
+
8
+ The PyPI package, Python import package, and CLI command are named `subschema`.
9
+
10
+ ## Install
11
+
12
+ ```bash
13
+ pip install subschema
14
+ ```
15
+
16
+ For local development:
17
+
18
+ ```bash
19
+ uv sync --locked --group dev
20
+ uv run pytest -q
21
+ uv run ruff check .
22
+ ```
23
+
24
+ ## CLI
25
+
26
+ ```bash
27
+ subschema lhs.json rhs.json
28
+ ```
29
+
30
+ The command prints whether `lhs.json <: rhs.json`.
31
+
32
+ Finite expensive proof products can be enabled explicitly:
33
+
34
+ ```bash
35
+ subschema --endeavor --max-work 20000 --timeout-ms 3000 lhs.json rhs.json
36
+ ```
37
+
38
+ `max_work` and `timeout_ms` are only accepted with `--endeavor`. A value of `-1`
39
+ means unlimited for that control.
40
+
41
+ ## Python API
42
+
43
+ ```python
44
+ from subschema import Dialect, is_subschema
45
+
46
+ lhs = {"type": "integer"}
47
+ rhs = {"type": "number"}
48
+
49
+ print(is_subschema(lhs, rhs, dialect=Dialect.DRAFT202012))
50
+ ```
51
+
52
+ Available public entrypoints:
53
+
54
+ - `is_subschema(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
55
+ - `is_equivalent(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
56
+ - `meet_schemas(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
57
+ - `join_schemas(lhs, rhs, *, dialect=None, proof_options=None, endeavor=False, max_work=None, timeout_ms=None)`
58
+ - `canonicalize_schema(schema, *, dialect=None)`
59
+
60
+ ## Dialects
61
+
62
+ Draft 2020-12 is the default dialect for calls without an explicit dialect or
63
+ `$schema` declaration. Older dialects can be selected by passing `dialect=...`
64
+ or by using a `$schema` declaration.
65
+
66
+ Supported dialects:
67
+
68
+ - Draft 4
69
+ - Draft 6
70
+ - Draft 7
71
+ - Draft 2019-09
72
+ - Draft 2020-12
73
+
74
+ The prover is intentionally conservative. Unsupported, unbounded, recursive, or
75
+ exhausted proof fragments are reported instead of being silently approximated.
76
+
77
+ ## Acknowledgement
78
+
79
+ This project is a rewrite based on IBM's
80
+ [jsonsubschema](https://github.com/IBM/jsonsubschema) project and may retain
81
+ portions of its source code. Credit to IBM and contributors.
82
+
83
+ ## License
84
+
85
+ Apache License 2.0. See [LICENSE](LICENSE).
@@ -0,0 +1,76 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.30.1"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "subschema"
7
+ version = "0.0.1"
8
+ description = "A conservative JSON Schema subschema prover"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "Apache-2.0"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "Henri", email = "henri-zhang@outlook.com" },
15
+ ]
16
+ dependencies = [
17
+ "greenery>=4.0.0",
18
+ "jsonschema",
19
+ "jsonschema-rs>=0.46.5",
20
+ "referencing",
21
+ "z3-solver",
22
+ ]
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/ArakawaHenri/subschema"
26
+ Repository = "https://github.com/ArakawaHenri/subschema"
27
+
28
+ [project.scripts]
29
+ subschema = "subschema.cli:main"
30
+
31
+ [tool.hatch.build.targets.wheel]
32
+ only-include = ["src"]
33
+ sources = ["src"]
34
+
35
+ [tool.hatch.build.targets.sdist]
36
+ include = [
37
+ "src",
38
+ "LICENSE",
39
+ "README.md",
40
+ "pyproject.toml",
41
+ "uv.lock",
42
+ ]
43
+
44
+ [dependency-groups]
45
+ dev = [
46
+ "coverage[toml]",
47
+ "pytest",
48
+ "ruff",
49
+ ]
50
+ security = [
51
+ "cyclonedx-bom>=4.1.0",
52
+ "pip-audit>=2.8.0",
53
+ ]
54
+
55
+ [tool.ruff]
56
+ target-version = "py312"
57
+ line-length = 88
58
+
59
+ [tool.ruff.lint]
60
+ select = [
61
+ "C4",
62
+ "E",
63
+ "F401",
64
+ "F841",
65
+ "I",
66
+ "N",
67
+ "PERF401",
68
+ "RET504",
69
+ "RET505",
70
+ "SIM118",
71
+ "UP",
72
+ "W605",
73
+ ]
74
+
75
+ [tool.ruff.lint.per-file-ignores]
76
+ "test/**/*.py" = ["E", "I", "N", "W"]
@@ -0,0 +1,19 @@
1
+ from subschema import api, exceptions
2
+ from subschema.dialects import Dialect
3
+
4
+ is_subschema = api.is_subschema
5
+ meet_schemas = api.meet_schemas
6
+ join_schemas = api.join_schemas
7
+ is_equivalent = api.is_equivalent
8
+
9
+ canonicalize_schema = api.canonicalize_schema
10
+
11
+ __all__ = [
12
+ "Dialect",
13
+ "canonicalize_schema",
14
+ "exceptions",
15
+ "is_equivalent",
16
+ "is_subschema",
17
+ "join_schemas",
18
+ "meet_schemas",
19
+ ]
@@ -0,0 +1,172 @@
1
+ """
2
+ Public API entrypoints.
3
+ """
4
+
5
+ from copy import deepcopy
6
+
7
+ from subschema.dialects import (
8
+ resolve_dialect,
9
+ strip_inactive_keywords_for_dialect,
10
+ validate_supported_keywords,
11
+ )
12
+ from subschema.kernel.contracts import ProofBudgets, ProofOptions
13
+ from subschema.kernel.engine import ProofEngine
14
+ from subschema.kernel.json_data import ensure_json_value
15
+ from subschema.kernel.normalization import normalize_boolean_schemas
16
+ from subschema.kernel.validation import validate_raw_schema_for_dialect
17
+
18
+
19
+ def canonicalize_schema(s, *, dialect=None):
20
+ """Return a modern normalized schema without embedding removed checker objects."""
21
+ ensure_json_value(s, label="schema")
22
+ resolved_dialect = resolve_dialect(s, dialect=dialect)
23
+ _validate_public_schema(s, resolved_dialect)
24
+ schema = strip_inactive_keywords_for_dialect(
25
+ normalize_boolean_schemas(deepcopy(s)), resolved_dialect
26
+ )
27
+ validate_supported_keywords(schema, resolved_dialect)
28
+ return schema
29
+
30
+
31
+ def _validate_public_schema(schema, dialect):
32
+ stripped = strip_inactive_keywords_for_dialect(schema, dialect)
33
+ validate_raw_schema_for_dialect(stripped, dialect)
34
+
35
+
36
+ def _resolve_proof_options(
37
+ proof_options=None,
38
+ *,
39
+ endeavor=False,
40
+ max_work=None,
41
+ timeout_ms=None,
42
+ ):
43
+ if not isinstance(endeavor, bool):
44
+ raise TypeError("endeavor must be a boolean")
45
+ if proof_options is not None:
46
+ if not isinstance(proof_options, ProofOptions):
47
+ raise TypeError("proof_options must be a ProofOptions instance")
48
+ if endeavor or max_work is not None or timeout_ms is not None:
49
+ raise ValueError(
50
+ "proof_options cannot be combined with endeavor, max_work, or "
51
+ "timeout_ms"
52
+ )
53
+ return proof_options
54
+ if (max_work is not None or timeout_ms is not None) and not endeavor:
55
+ raise ValueError("max_work and timeout_ms require endeavor=True")
56
+ if endeavor:
57
+ return ProofOptions(
58
+ endeavor=endeavor,
59
+ budgets=ProofBudgets(
60
+ max_work=4096 if max_work is None else max_work,
61
+ timeout_ms=1000 if timeout_ms is None else timeout_ms,
62
+ ),
63
+ )
64
+ return None
65
+
66
+
67
+ def is_subschema(
68
+ s1,
69
+ s2,
70
+ *,
71
+ dialect=None,
72
+ proof_options=None,
73
+ endeavor=False,
74
+ max_work=None,
75
+ timeout_ms=None,
76
+ ):
77
+ """Entry point for schema subtype checking."""
78
+ ensure_json_value(s1, label="lhs schema")
79
+ ensure_json_value(s2, label="rhs schema")
80
+ resolved_dialect = resolve_dialect(s1, s2, dialect=dialect)
81
+ _validate_public_schema(s1, resolved_dialect)
82
+ _validate_public_schema(s2, resolved_dialect)
83
+ options = _resolve_proof_options(
84
+ proof_options,
85
+ endeavor=endeavor,
86
+ max_work=max_work,
87
+ timeout_ms=timeout_ms,
88
+ )
89
+ return ProofEngine.for_schemas(
90
+ s1, s2, dialect=resolved_dialect, options=options
91
+ ).is_subschema_bool(s1, s2)
92
+
93
+
94
+ def meet_schemas(
95
+ s1,
96
+ s2,
97
+ *,
98
+ dialect=None,
99
+ proof_options=None,
100
+ endeavor=False,
101
+ max_work=None,
102
+ timeout_ms=None,
103
+ ):
104
+ """Entry point for schema meet operation."""
105
+ ensure_json_value(s1, label="lhs schema")
106
+ ensure_json_value(s2, label="rhs schema")
107
+ resolved_dialect = resolve_dialect(s1, s2, dialect=dialect)
108
+ _validate_public_schema(s1, resolved_dialect)
109
+ _validate_public_schema(s2, resolved_dialect)
110
+ options = _resolve_proof_options(
111
+ proof_options,
112
+ endeavor=endeavor,
113
+ max_work=max_work,
114
+ timeout_ms=timeout_ms,
115
+ )
116
+ return ProofEngine.for_schemas(
117
+ s1, s2, dialect=resolved_dialect, options=options
118
+ ).meet(s1, s2)
119
+
120
+
121
+ def join_schemas(
122
+ s1,
123
+ s2,
124
+ *,
125
+ dialect=None,
126
+ proof_options=None,
127
+ endeavor=False,
128
+ max_work=None,
129
+ timeout_ms=None,
130
+ ):
131
+ """Entry point for schema join operation."""
132
+ ensure_json_value(s1, label="lhs schema")
133
+ ensure_json_value(s2, label="rhs schema")
134
+ resolved_dialect = resolve_dialect(s1, s2, dialect=dialect)
135
+ _validate_public_schema(s1, resolved_dialect)
136
+ _validate_public_schema(s2, resolved_dialect)
137
+ options = _resolve_proof_options(
138
+ proof_options,
139
+ endeavor=endeavor,
140
+ max_work=max_work,
141
+ timeout_ms=timeout_ms,
142
+ )
143
+ return ProofEngine.for_schemas(
144
+ s1, s2, dialect=resolved_dialect, options=options
145
+ ).join(s1, s2)
146
+
147
+
148
+ def is_equivalent(
149
+ s1,
150
+ s2,
151
+ *,
152
+ dialect=None,
153
+ proof_options=None,
154
+ endeavor=False,
155
+ max_work=None,
156
+ timeout_ms=None,
157
+ ):
158
+ """Entry point for schema equivalence check operation."""
159
+ options = _resolve_proof_options(
160
+ proof_options,
161
+ endeavor=endeavor,
162
+ max_work=max_work,
163
+ timeout_ms=timeout_ms,
164
+ )
165
+ return is_subschema(
166
+ s1, s2, dialect=dialect, proof_options=options
167
+ ) and is_subschema(
168
+ s2,
169
+ s1,
170
+ dialect=dialect,
171
+ proof_options=options,
172
+ )