@shapeshift-labs/frontier-schema 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +191 -2
- package/benchmarks/package-bench.mjs +153 -0
- package/dist/event.d.ts +6 -0
- package/dist/event.d.ts.map +1 -0
- package/dist/event.js +125 -0
- package/dist/event.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +7 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +36 -0
- package/dist/internal.js.map +1 -0
- package/dist/json-schema.d.ts +10 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +397 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +2 -0
- package/dist/query.js.map +1 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +70 -10
- package/index.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shapeshift Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,192 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Frontier Schema
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
JSON Schema validation, Frontier profile generation, CloudEvent envelopes, and table-schema helpers.
|
|
4
|
+
|
|
5
|
+
This package is the authoring and conversion layer for schema-shaped Frontier workflows. It validates lightweight JSON Schema contracts, turns object and record-array schemas into `@shapeshift-labs/frontier-engine` diff profiles, exposes CloudEvent JSON envelopes, and re-exports query/table schema normalization from `@shapeshift-labs/frontier-query`.
|
|
6
|
+
|
|
7
|
+
- npm: [`@shapeshift-labs/frontier-schema`](https://www.npmjs.com/package/@shapeshift-labs/frontier-schema)
|
|
8
|
+
- source: [`siliconjungle/-shapeshift-labs-frontier-schema`](https://github.com/siliconjungle/-shapeshift-labs-frontier-schema)
|
|
9
|
+
- license: MIT
|
|
10
|
+
|
|
11
|
+
## Related Packages
|
|
12
|
+
|
|
13
|
+
- [`@shapeshift-labs/frontier`](https://www.npmjs.com/package/@shapeshift-labs/frontier): core JSON diff/apply primitives.
|
|
14
|
+
- [`@shapeshift-labs/frontier-query`](https://www.npmjs.com/package/@shapeshift-labs/frontier-query): shared query-key, selector path, condition, identity, and table-schema primitives.
|
|
15
|
+
- [`@shapeshift-labs/frontier-codec`](https://www.npmjs.com/package/@shapeshift-labs/frontier-codec): patch serialization, binary frames, canonical JSON, and patch-history codecs.
|
|
16
|
+
- [`@shapeshift-labs/frontier-engine`](https://www.npmjs.com/package/@shapeshift-labs/frontier-engine): planned diff engine that executes profiles produced by this package.
|
|
17
|
+
- [`@shapeshift-labs/frontier-state`](https://www.npmjs.com/package/@shapeshift-labs/frontier-state): patch-routed app-state subscriptions and maintained views.
|
|
18
|
+
- [`@shapeshift-labs/frontier-state-cache`](https://www.npmjs.com/package/@shapeshift-labs/frontier-state-cache): normalized query-result cache.
|
|
19
|
+
- [`@shapeshift-labs/frontier-mutation`](https://www.npmjs.com/package/@shapeshift-labs/frontier-mutation): explicit mutation and selector plans.
|
|
20
|
+
|
|
21
|
+
Package source repositories:
|
|
22
|
+
|
|
23
|
+
- [`siliconjungle/-shapeshift-labs-frontier`](https://github.com/siliconjungle/-shapeshift-labs-frontier)
|
|
24
|
+
- [`siliconjungle/-shapeshift-labs-frontier-query`](https://github.com/siliconjungle/-shapeshift-labs-frontier-query)
|
|
25
|
+
- [`siliconjungle/-shapeshift-labs-frontier-codec`](https://github.com/siliconjungle/-shapeshift-labs-frontier-codec)
|
|
26
|
+
- [`siliconjungle/-shapeshift-labs-frontier-engine`](https://github.com/siliconjungle/-shapeshift-labs-frontier-engine)
|
|
27
|
+
- [`siliconjungle/-shapeshift-labs-frontier-state`](https://github.com/siliconjungle/-shapeshift-labs-frontier-state)
|
|
28
|
+
- [`siliconjungle/-shapeshift-labs-frontier-state-cache`](https://github.com/siliconjungle/-shapeshift-labs-frontier-state-cache)
|
|
29
|
+
- [`siliconjungle/-shapeshift-labs-frontier-mutation`](https://github.com/siliconjungle/-shapeshift-labs-frontier-mutation)
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm install @shapeshift-labs/frontier @shapeshift-labs/frontier-query @shapeshift-labs/frontier-engine @shapeshift-labs/frontier-schema
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { applyPatchImmutable } from '@shapeshift-labs/frontier';
|
|
41
|
+
import { createDiffEngine } from '@shapeshift-labs/frontier-engine';
|
|
42
|
+
import {
|
|
43
|
+
createCloudEventEnvelope,
|
|
44
|
+
jsonSchemaToDiffProfile,
|
|
45
|
+
validateJsonSchemaContract
|
|
46
|
+
} from '@shapeshift-labs/frontier-schema';
|
|
47
|
+
|
|
48
|
+
const rowSchema = {
|
|
49
|
+
type: 'object',
|
|
50
|
+
required: ['id', 'done'],
|
|
51
|
+
properties: {
|
|
52
|
+
id: { type: 'string' },
|
|
53
|
+
done: { type: 'boolean' },
|
|
54
|
+
title: { type: 'string' }
|
|
55
|
+
}
|
|
56
|
+
} as const;
|
|
57
|
+
|
|
58
|
+
const result = validateJsonSchemaContract(
|
|
59
|
+
{ id: 't1', done: false, title: 'Draft' },
|
|
60
|
+
rowSchema
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const engine = createDiffEngine({
|
|
64
|
+
profile: jsonSchemaToDiffProfile(rowSchema)
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const before = { id: 't1', done: false, title: 'Draft' };
|
|
68
|
+
const after = { id: 't1', done: true, title: 'Draft' };
|
|
69
|
+
const patch = engine.diff(before, after);
|
|
70
|
+
const next = applyPatchImmutable(before, patch);
|
|
71
|
+
|
|
72
|
+
const event = createCloudEventEnvelope({
|
|
73
|
+
id: 'evt-1',
|
|
74
|
+
source: '/todos',
|
|
75
|
+
type: 'frontier.patch',
|
|
76
|
+
data: { patch }
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log(result.valid, next, event.type);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## API
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import {
|
|
86
|
+
assertCloudEventEnvelope,
|
|
87
|
+
assertJsonSchemaContract,
|
|
88
|
+
assertJsonSchemaDefinition,
|
|
89
|
+
compileJsonSchemaValidator,
|
|
90
|
+
createCloudEventEnvelope,
|
|
91
|
+
jsonSchemaToDiffProfile,
|
|
92
|
+
jsonSchemaToFrontierSchema,
|
|
93
|
+
normalizeQuerySchema,
|
|
94
|
+
validateCloudEventEnvelope,
|
|
95
|
+
validateJsonSchemaContract,
|
|
96
|
+
validateJsonSchemaDefinition,
|
|
97
|
+
type JsonSchemaContract
|
|
98
|
+
} from '@shapeshift-labs/frontier-schema';
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### JSON Schema
|
|
102
|
+
|
|
103
|
+
- `validateJsonSchemaDefinition(schema, options?)` validates the supported JSON Schema subset.
|
|
104
|
+
- `assertJsonSchemaDefinition(schema, options?)` throws on invalid schema definitions.
|
|
105
|
+
- `validateJsonSchemaContract(value, schema, options?)` validates a JSON value against a schema contract.
|
|
106
|
+
- `assertJsonSchemaContract(value, schema, options?)` throws on contract failures.
|
|
107
|
+
- `compileJsonSchemaValidator(schema, options?)` clones and reuses schema validation options.
|
|
108
|
+
|
|
109
|
+
Supported keywords: `type`, `properties`, `required`, `items`, `additionalProperties`, `enum`, `const`, `minItems`, `maxItems`, `minLength`, `maxLength`, `minimum`, `maximum`, and `pattern`.
|
|
110
|
+
|
|
111
|
+
### Frontier Profiles
|
|
112
|
+
|
|
113
|
+
- `jsonSchemaToFrontierSchema(schema, options?)` converts object and array-of-object JSON Schema contracts into Frontier engine schema hints.
|
|
114
|
+
- `jsonSchemaToDiffProfile(schema, options?)` returns a `DiffProfile` for `createDiffEngine({ profile })`.
|
|
115
|
+
|
|
116
|
+
Schema package output is declarative. Runtime diff planning and cache execution stay in `@shapeshift-labs/frontier-engine`.
|
|
117
|
+
|
|
118
|
+
### Query/Table Schemas
|
|
119
|
+
|
|
120
|
+
- `normalizeQuerySchema(schema, label?)` normalizes table/entity shape hints from `@shapeshift-labs/frontier-query`.
|
|
121
|
+
|
|
122
|
+
This keeps table/entity schema authoring visible from `frontier-schema`, while query-key hashing, condition matching, and selector vocabulary stay owned by `frontier-query`.
|
|
123
|
+
|
|
124
|
+
### CloudEvents
|
|
125
|
+
|
|
126
|
+
- `createCloudEventEnvelope(input)` creates a JSON CloudEvent 1.0 envelope.
|
|
127
|
+
- `validateCloudEventEnvelope(value)` validates a CloudEvent envelope.
|
|
128
|
+
- `assertCloudEventEnvelope(value)` throws on invalid CloudEvent envelopes.
|
|
129
|
+
|
|
130
|
+
## Subpath Imports
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
import { validateJsonSchemaContract } from '@shapeshift-labs/frontier-schema/json-schema';
|
|
134
|
+
import { createCloudEventEnvelope } from '@shapeshift-labs/frontier-schema/event';
|
|
135
|
+
import { normalizeQuerySchema } from '@shapeshift-labs/frontier-schema/query';
|
|
136
|
+
import type { JsonSchemaContract } from '@shapeshift-labs/frontier-schema/types';
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Package Scope
|
|
140
|
+
|
|
141
|
+
This package owns schema authoring and conversion:
|
|
142
|
+
|
|
143
|
+
- lightweight JSON Schema validation,
|
|
144
|
+
- JSON Schema to Frontier engine schema/profile conversion,
|
|
145
|
+
- query/table schema normalization re-exports,
|
|
146
|
+
- CloudEvent JSON envelope helpers.
|
|
147
|
+
|
|
148
|
+
It does not own:
|
|
149
|
+
|
|
150
|
+
- stateless diff/apply primitives,
|
|
151
|
+
- executing schema/profile plans,
|
|
152
|
+
- query-result cache storage,
|
|
153
|
+
- mutation planning,
|
|
154
|
+
- patch/history byte formats,
|
|
155
|
+
- CRDT actors, heads, branches, sync, awareness, or rich text.
|
|
156
|
+
|
|
157
|
+
## TypeScript
|
|
158
|
+
|
|
159
|
+
The package ships ESM JavaScript plus `.d.ts` declarations for the root export and public subpaths. The package-local TypeScript source lives in `src/` and compiles directly to `dist/`.
|
|
160
|
+
|
|
161
|
+
## Validation
|
|
162
|
+
|
|
163
|
+
```sh
|
|
164
|
+
npm test
|
|
165
|
+
npm run fuzz
|
|
166
|
+
npm run bench
|
|
167
|
+
npm run pack:dry
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Benchmarks
|
|
171
|
+
|
|
172
|
+
Run the package-local benchmark:
|
|
173
|
+
|
|
174
|
+
```sh
|
|
175
|
+
npm run bench
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Latest local package benchmark on Node v26.1.0, darwin arm64, 3 rounds:
|
|
179
|
+
|
|
180
|
+
| Fixture | Median | p95 |
|
|
181
|
+
| --- | ---: | ---: |
|
|
182
|
+
| JSON schema contract validate | 1.06 us | 1.24 us |
|
|
183
|
+
| Compiled schema validator | 1.07 us | 1.13 us |
|
|
184
|
+
| JSON schema to diff profile | 7.40 us | 7.55 us |
|
|
185
|
+
| Query table schema normalize | 0.87 us | 0.92 us |
|
|
186
|
+
| CloudEvent create and validate | 1.60 us | 1.90 us |
|
|
187
|
+
|
|
188
|
+
These are Frontier-only package measurements, not competitor comparisons.
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
MIT. See [LICENSE](./LICENSE).
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { performance } from 'node:perf_hooks';
|
|
2
|
+
import {
|
|
3
|
+
compileJsonSchemaValidator,
|
|
4
|
+
createCloudEventEnvelope,
|
|
5
|
+
jsonSchemaToDiffProfile,
|
|
6
|
+
normalizeQuerySchema,
|
|
7
|
+
validateCloudEventEnvelope,
|
|
8
|
+
validateJsonSchemaContract
|
|
9
|
+
} from '../dist/index.js';
|
|
10
|
+
|
|
11
|
+
const args = parseArgs(process.argv.slice(2));
|
|
12
|
+
const rounds = readPositiveInt(args.rounds, 3);
|
|
13
|
+
|
|
14
|
+
const rowSchema = {
|
|
15
|
+
type: 'object',
|
|
16
|
+
required: ['id', 'score', 'active'],
|
|
17
|
+
additionalProperties: false,
|
|
18
|
+
properties: {
|
|
19
|
+
id: { type: 'string', minLength: 1 },
|
|
20
|
+
score: { type: 'number', minimum: 0 },
|
|
21
|
+
active: { type: 'boolean' },
|
|
22
|
+
owner: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
id: { type: 'string' },
|
|
26
|
+
team: { type: 'string' }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const row = { id: 'row-1', score: 42, active: true, owner: { id: 'u1', team: 'core' } };
|
|
32
|
+
const compiled = compileJsonSchemaValidator(rowSchema);
|
|
33
|
+
const querySchema = {
|
|
34
|
+
tables: [{
|
|
35
|
+
path: '/rows',
|
|
36
|
+
key: 'id',
|
|
37
|
+
stableRowShape: true,
|
|
38
|
+
numericFields: ['score'],
|
|
39
|
+
textFields: ['owner.team'],
|
|
40
|
+
selectorFields: ['active', 'owner.id']
|
|
41
|
+
}]
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const fixtures = [
|
|
45
|
+
{
|
|
46
|
+
name: 'JSON schema contract validate',
|
|
47
|
+
iterations: 10000,
|
|
48
|
+
fn() {
|
|
49
|
+
validateJsonSchemaContract(row, rowSchema);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'Compiled schema validator',
|
|
54
|
+
iterations: 10000,
|
|
55
|
+
fn() {
|
|
56
|
+
compiled(row);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: 'JSON schema to diff profile',
|
|
61
|
+
iterations: 10000,
|
|
62
|
+
fn() {
|
|
63
|
+
jsonSchemaToDiffProfile(rowSchema, { path: ['rows'], arrayKey: 'id' });
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
name: 'Query table schema normalize',
|
|
68
|
+
iterations: 10000,
|
|
69
|
+
fn() {
|
|
70
|
+
normalizeQuerySchema(querySchema);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'CloudEvent create and validate',
|
|
75
|
+
iterations: 10000,
|
|
76
|
+
fn() {
|
|
77
|
+
const event = createCloudEventEnvelope({
|
|
78
|
+
id: 'evt-1',
|
|
79
|
+
source: '/frontier/schema',
|
|
80
|
+
type: 'frontier.schema.bench',
|
|
81
|
+
data: row,
|
|
82
|
+
extensions: { frontierseq: 1 }
|
|
83
|
+
});
|
|
84
|
+
validateCloudEventEnvelope(event);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const rows = fixtures.map((fixture) => measureFixture(fixture, rounds));
|
|
90
|
+
|
|
91
|
+
console.log('Frontier Schema package benchmark');
|
|
92
|
+
console.log('node=' + process.version + ' platform=' + process.platform + ' arch=' + process.arch + ' rounds=' + rounds);
|
|
93
|
+
console.log(padRight('fixture', 36) + padLeft('median', 12) + padLeft('p95', 12));
|
|
94
|
+
for (const row of rows) {
|
|
95
|
+
console.log(padRight(row.fixture, 36) + padLeft(formatUs(row.medianUs), 12) + padLeft(formatUs(row.p95Us), 12));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function measureFixture(fixture, rounds) {
|
|
99
|
+
const samples = [];
|
|
100
|
+
for (let i = 0; i < rounds; i++) {
|
|
101
|
+
fixture.fn();
|
|
102
|
+
const start = performance.now();
|
|
103
|
+
for (let j = 0; j < fixture.iterations; j++) fixture.fn();
|
|
104
|
+
const elapsed = performance.now() - start;
|
|
105
|
+
samples.push((elapsed * 1000) / fixture.iterations);
|
|
106
|
+
}
|
|
107
|
+
samples.sort((left, right) => left - right);
|
|
108
|
+
return {
|
|
109
|
+
fixture: fixture.name,
|
|
110
|
+
medianUs: percentile(samples, 0.5),
|
|
111
|
+
p95Us: percentile(samples, 0.95)
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function percentile(values, q) {
|
|
116
|
+
if (values.length === 0) return 0;
|
|
117
|
+
const index = Math.min(values.length - 1, Math.max(0, Math.ceil(values.length * q) - 1));
|
|
118
|
+
return values[index];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function formatUs(value) {
|
|
122
|
+
return value.toFixed(2) + ' us';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function padRight(value, width) {
|
|
126
|
+
const text = String(value);
|
|
127
|
+
return text.length >= width ? text.slice(0, width) : text + ' '.repeat(width - text.length);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function padLeft(value, width) {
|
|
131
|
+
const text = String(value);
|
|
132
|
+
return text.length >= width ? text : ' '.repeat(width - text.length) + text;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parseArgs(argv) {
|
|
136
|
+
const out = {};
|
|
137
|
+
for (let i = 0; i < argv.length; i++) {
|
|
138
|
+
const arg = argv[i];
|
|
139
|
+
if (arg === '--rounds') out.rounds = argv[++i];
|
|
140
|
+
else if (arg === '--help' || arg === '-h') {
|
|
141
|
+
console.log('Usage: node benchmarks/package-bench.mjs [--rounds 3]');
|
|
142
|
+
process.exit(0);
|
|
143
|
+
} else {
|
|
144
|
+
throw new Error('unknown argument: ' + arg);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function readPositiveInt(value, fallback) {
|
|
151
|
+
const number = Number(value);
|
|
152
|
+
return Number.isFinite(number) && number > 0 ? Math.floor(number) : fallback;
|
|
153
|
+
}
|
package/dist/event.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JsonObject } from '@shapeshift-labs/frontier/types';
|
|
2
|
+
import type { CloudEventEnvelope, CloudEventEnvelopeInput, JsonValue, SchemaValidationResult } from './types.js';
|
|
3
|
+
export declare function createCloudEventEnvelope<T extends JsonValue = JsonValue>(input: CloudEventEnvelopeInput<T>): CloudEventEnvelope<T>;
|
|
4
|
+
export declare function validateCloudEventEnvelope(value: unknown): SchemaValidationResult;
|
|
5
|
+
export declare function assertCloudEventEnvelope<T extends JsonObject = CloudEventEnvelope>(value: T): T & CloudEventEnvelope;
|
|
6
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,kBAAkB,EAClB,uBAAuB,EACvB,SAAS,EAET,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAgBpB,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,EACtE,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAChC,kBAAkB,CAAC,CAAC,CAAC,CA6BvB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,sBAAsB,CAqDjF;AAED,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,UAAU,GAAG,kBAAkB,EAChF,KAAK,EAAE,CAAC,GACP,CAAC,GAAG,kBAAkB,CAIxB"}
|
package/dist/event.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { cloneJson } from '@shapeshift-labs/frontier/clone';
|
|
2
|
+
import { assertJsonValue } from '@shapeshift-labs/frontier/validate';
|
|
3
|
+
import { addIssue, formatSchemaIssues, isPlainObject } from './internal.js';
|
|
4
|
+
const RESERVED_CLOUD_EVENT_ATTRIBUTES = new Set([
|
|
5
|
+
'specversion',
|
|
6
|
+
'id',
|
|
7
|
+
'source',
|
|
8
|
+
'type',
|
|
9
|
+
'subject',
|
|
10
|
+
'time',
|
|
11
|
+
'datacontenttype',
|
|
12
|
+
'dataschema',
|
|
13
|
+
'data',
|
|
14
|
+
'data_base64'
|
|
15
|
+
]);
|
|
16
|
+
export function createCloudEventEnvelope(input) {
|
|
17
|
+
if (input === null || typeof input !== 'object')
|
|
18
|
+
throw new TypeError('CloudEvent input must be an object');
|
|
19
|
+
const envelope = {
|
|
20
|
+
specversion: '1.0',
|
|
21
|
+
id: requireNonEmptyString(input.id, 'CloudEvent id'),
|
|
22
|
+
source: requireNonEmptyString(input.source, 'CloudEvent source'),
|
|
23
|
+
type: requireNonEmptyString(input.type, 'CloudEvent type')
|
|
24
|
+
};
|
|
25
|
+
if (input.subject !== undefined)
|
|
26
|
+
envelope.subject = requireNonEmptyString(input.subject, 'CloudEvent subject');
|
|
27
|
+
if (input.time !== undefined) {
|
|
28
|
+
envelope.time = input.time instanceof Date ? input.time.toISOString() : requireNonEmptyString(input.time, 'CloudEvent time');
|
|
29
|
+
}
|
|
30
|
+
if (input.datacontenttype !== undefined)
|
|
31
|
+
envelope.datacontenttype = requireNonEmptyString(input.datacontenttype, 'CloudEvent datacontenttype');
|
|
32
|
+
if (input.dataschema !== undefined)
|
|
33
|
+
envelope.dataschema = requireNonEmptyString(input.dataschema, 'CloudEvent dataschema');
|
|
34
|
+
if (input.data !== undefined)
|
|
35
|
+
envelope.data = cloneJson(input.data);
|
|
36
|
+
if (input.extensions !== undefined) {
|
|
37
|
+
const keys = Object.keys(input.extensions);
|
|
38
|
+
for (let i = 0; i < keys.length; i++) {
|
|
39
|
+
const key = keys[i];
|
|
40
|
+
validateCloudEventExtensionName(key);
|
|
41
|
+
if (RESERVED_CLOUD_EVENT_ATTRIBUTES.has(key))
|
|
42
|
+
throw new TypeError('CloudEvent extension must not overwrite ' + key);
|
|
43
|
+
envelope[key] = cloneJson(input.extensions[key]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
assertCloudEventEnvelope(envelope);
|
|
47
|
+
return envelope;
|
|
48
|
+
}
|
|
49
|
+
export function validateCloudEventEnvelope(value) {
|
|
50
|
+
const issues = [];
|
|
51
|
+
if (!isPlainObject(value)) {
|
|
52
|
+
addIssue(issues, [], 'type', 'CloudEvent envelope must be an object');
|
|
53
|
+
return { valid: false, issues };
|
|
54
|
+
}
|
|
55
|
+
requireStringField(value, 'specversion', issues);
|
|
56
|
+
requireStringField(value, 'id', issues);
|
|
57
|
+
requireStringField(value, 'source', issues);
|
|
58
|
+
requireStringField(value, 'type', issues);
|
|
59
|
+
if (value.specversion !== '1.0')
|
|
60
|
+
addIssue(issues, ['specversion'], 'const', 'CloudEvent specversion must be 1.0');
|
|
61
|
+
for (const name of ['id', 'source', 'type']) {
|
|
62
|
+
if (typeof value[name] === 'string' && value[name].length === 0)
|
|
63
|
+
addIssue(issues, [name], 'minLength', 'CloudEvent ' + name + ' must not be empty');
|
|
64
|
+
}
|
|
65
|
+
for (const name of ['subject', 'datacontenttype', 'dataschema']) {
|
|
66
|
+
if (value[name] !== undefined && typeof value[name] !== 'string')
|
|
67
|
+
addIssue(issues, [name], 'type', 'CloudEvent ' + name + ' must be a string');
|
|
68
|
+
}
|
|
69
|
+
if (value.time !== undefined) {
|
|
70
|
+
if (typeof value.time !== 'string') {
|
|
71
|
+
addIssue(issues, ['time'], 'type', 'CloudEvent time must be a string');
|
|
72
|
+
}
|
|
73
|
+
else if (Number.isNaN(Date.parse(value.time))) {
|
|
74
|
+
addIssue(issues, ['time'], 'format', 'CloudEvent time must be an RFC3339-compatible timestamp string');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (value.data !== undefined) {
|
|
78
|
+
try {
|
|
79
|
+
assertJsonValue(value.data, 'CloudEvent data');
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
addIssue(issues, ['data'], 'json', error instanceof Error ? error.message : 'CloudEvent data must be JSON');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (value.data_base64 !== undefined && typeof value.data_base64 !== 'string') {
|
|
86
|
+
addIssue(issues, ['data_base64'], 'type', 'CloudEvent data_base64 must be a string');
|
|
87
|
+
}
|
|
88
|
+
if (value.data !== undefined && value.data_base64 !== undefined) {
|
|
89
|
+
addIssue(issues, ['data_base64'], 'mutualExclusion', 'CloudEvent data and data_base64 must not both be present');
|
|
90
|
+
}
|
|
91
|
+
const keys = Object.keys(value);
|
|
92
|
+
for (let i = 0; i < keys.length; i++) {
|
|
93
|
+
const key = keys[i];
|
|
94
|
+
if (!RESERVED_CLOUD_EVENT_ATTRIBUTES.has(key)) {
|
|
95
|
+
try {
|
|
96
|
+
validateCloudEventExtensionName(key);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
addIssue(issues, [key], 'extension', error instanceof Error ? error.message : 'invalid CloudEvent extension name');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return { valid: issues.length === 0, issues };
|
|
104
|
+
}
|
|
105
|
+
export function assertCloudEventEnvelope(value) {
|
|
106
|
+
const result = validateCloudEventEnvelope(value);
|
|
107
|
+
if (!result.valid)
|
|
108
|
+
throw new TypeError(formatSchemaIssues(result.issues));
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
function requireStringField(value, key, issues) {
|
|
112
|
+
if (typeof value[key] !== 'string')
|
|
113
|
+
addIssue(issues, [key], 'required', 'CloudEvent ' + key + ' must be a string');
|
|
114
|
+
}
|
|
115
|
+
function requireNonEmptyString(value, label) {
|
|
116
|
+
if (typeof value !== 'string' || value.length === 0)
|
|
117
|
+
throw new TypeError(label + ' must be a non-empty string');
|
|
118
|
+
return value;
|
|
119
|
+
}
|
|
120
|
+
function validateCloudEventExtensionName(name) {
|
|
121
|
+
if (!/^[a-z][a-z0-9]{0,19}$/.test(name)) {
|
|
122
|
+
throw new TypeError('CloudEvent extension name must match ^[a-z][a-z0-9]{0,19}$');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../src/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AASrE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,+BAA+B,GAAG,IAAI,GAAG,CAAC;IAC9C,aA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AC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,mCAAmC,CAAC,CAAC;YACrH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;AAChD,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,KAAQ;IAER,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,CAAC,CAAC;IACjD,IAAI,CAAC,MAAM,CAAC,KAAK;QAAE,MAAM,IAAI,SAAS,CAAC,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,OAAO,KAA+B,CAAC;AACzC,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAiB,EAAE,GAAW,EAAE,MAA+B;IACzF,IAAI,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,QAAQ;QAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,aAAa,GAAG,GAAG,GAAG,mBAAmB,CAAC,CAAC;AACrH,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAc,EAAE,KAAa;IAC1D,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,KAAK,GAAG,6BAA6B,CAAC,CAAC;IAChH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,+BAA+B,CAAC,IAAY;IACnD,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,SAAS,CAAC,4DAA4D,CAAC,CAAC;IACpF,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { assertJsonSchemaContract, assertJsonSchemaDefinition, compileJsonSchemaValidator, jsonSchemaToDiffProfile, jsonSchemaToFrontierSchema, validateJsonSchemaContract, validateJsonSchemaDefinition } from './json-schema.js';
|
|
2
|
+
export { assertCloudEventEnvelope, createCloudEventEnvelope, validateCloudEventEnvelope } from './event.js';
|
|
3
|
+
export { normalizeQuerySchema } from './query.js';
|
|
4
|
+
export type { CloudEventEnvelope, CloudEventEnvelopeInput, CompiledSchemaValidator, DiffProfile, JsonObject, JsonPath, JsonSchemaContract, JsonSchemaDefinitionOptions, JsonSchemaProfileOptions, JsonSchemaTypeName, JsonValidationOptions, JsonValue, ObjectKey, Schema, SchemaField, SchemaValidationIssue, SchemaValidationOptions, SchemaValidationResult, SingleSchema } from './types.js';
|
|
5
|
+
export type { NormalizedQuerySchema, NormalizedQueryTableSchema, QuerySchemaInput, QueryShapeSchema, QueryTableSchema } from './query.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,EACxB,kBAAkB,EAClB,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,MAAM,EACN,WAAW,EACX,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,qBAAqB,EACrB,0BAA0B,EAC1B,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { assertJsonSchemaContract, assertJsonSchemaDefinition, compileJsonSchemaValidator, jsonSchemaToDiffProfile, jsonSchemaToFrontierSchema, validateJsonSchemaContract, validateJsonSchemaDefinition } from './json-schema.js';
|
|
2
|
+
export { assertCloudEventEnvelope, createCloudEventEnvelope, validateCloudEventEnvelope } from './event.js';
|
|
3
|
+
export { normalizeQuerySchema } from './query.js';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,0BAA0B,EAC1B,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,oBAAoB,EACrB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { JsonObject, JsonPath, JsonValue } from '@shapeshift-labs/frontier/types';
|
|
2
|
+
import type { SchemaValidationIssue } from './types.js';
|
|
3
|
+
export declare function addIssue(issues: SchemaValidationIssue[], path: JsonPath, keyword: string, message: string, expected?: JsonValue, actual?: string): void;
|
|
4
|
+
export declare function formatSchemaIssues(issues: SchemaValidationIssue[]): string;
|
|
5
|
+
export declare function isPlainObject(value: unknown): value is JsonObject;
|
|
6
|
+
export declare function normalizeMaxIssues(value: number | undefined): number;
|
|
7
|
+
//# sourceMappingURL=internal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,wBAAgB,QAAQ,CACtB,MAAM,EAAE,qBAAqB,EAAE,EAC/B,IAAI,EAAE,QAAQ,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,QAAQ,CAAC,EAAE,SAAS,EACpB,MAAM,CAAC,EAAE,MAAM,GACd,IAAI,CAKN;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,qBAAqB,EAAE,GAAG,MAAM,CAI1E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAIjE;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAIpE"}
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function addIssue(issues, path, keyword, message, expected, actual) {
|
|
2
|
+
const issue = { path, keyword, message };
|
|
3
|
+
if (expected !== undefined)
|
|
4
|
+
issue.expected = expected;
|
|
5
|
+
if (actual !== undefined)
|
|
6
|
+
issue.actual = actual;
|
|
7
|
+
issues[issues.length] = issue;
|
|
8
|
+
}
|
|
9
|
+
export function formatSchemaIssues(issues) {
|
|
10
|
+
if (issues.length === 0)
|
|
11
|
+
return 'schema validation failed';
|
|
12
|
+
const first = issues[0];
|
|
13
|
+
return 'schema validation failed at ' + formatPath(first.path) + ': ' + first.message;
|
|
14
|
+
}
|
|
15
|
+
export function isPlainObject(value) {
|
|
16
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
17
|
+
return false;
|
|
18
|
+
const proto = Object.getPrototypeOf(value);
|
|
19
|
+
return proto === Object.prototype || proto === null;
|
|
20
|
+
}
|
|
21
|
+
export function normalizeMaxIssues(value) {
|
|
22
|
+
if (value === undefined)
|
|
23
|
+
return Number.POSITIVE_INFINITY;
|
|
24
|
+
if (!Number.isSafeInteger(value) || value < 1)
|
|
25
|
+
throw new TypeError('maxIssues option must be a positive safe integer');
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
function formatPath(path) {
|
|
29
|
+
if (path.length === 0)
|
|
30
|
+
return '$';
|
|
31
|
+
let out = '$';
|
|
32
|
+
for (let i = 0; i < path.length; i++)
|
|
33
|
+
out += typeof path[i] === 'number' ? '[' + path[i] + ']' : '.' + path[i];
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,QAAQ,CACtB,MAA+B,EAC/B,IAAc,EACd,OAAe,EACf,OAAe,EACf,QAAoB,EACpB,MAAe;IAEf,MAAM,KAAK,GAA0B,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;IAChE,IAAI,QAAQ,KAAK,SAAS;QAAE,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAC;IACtD,IAAI,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IAChD,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAA+B;IAChE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,0BAA0B,CAAC;IAC3D,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,OAAO,8BAA8B,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtF,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,KAAyB;IAC1D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,iBAAiB,CAAC;IACzD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC;QAAE,MAAM,IAAI,SAAS,CAAC,kDAAkD,CAAC,CAAC;IACvH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,IAAc;IAChC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,GAAG,CAAC;IAClC,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAC/G,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DiffProfile, JsonValue, Schema } from './types.js';
|
|
2
|
+
import type { CompiledSchemaValidator, JsonSchemaContract, JsonSchemaDefinitionOptions, JsonSchemaProfileOptions, SchemaValidationOptions, SchemaValidationResult } from './types.js';
|
|
3
|
+
export declare function validateJsonSchemaContract(value: unknown, schema: JsonSchemaContract, options?: SchemaValidationOptions): SchemaValidationResult;
|
|
4
|
+
export declare function validateJsonSchemaDefinition(schema: unknown, options?: JsonSchemaDefinitionOptions): SchemaValidationResult;
|
|
5
|
+
export declare function assertJsonSchemaDefinition<T extends JsonSchemaContract>(schema: T, options?: JsonSchemaDefinitionOptions): T;
|
|
6
|
+
export declare function assertJsonSchemaContract<T = JsonValue>(value: T, schema: JsonSchemaContract, options?: SchemaValidationOptions): T;
|
|
7
|
+
export declare function compileJsonSchemaValidator(schema: JsonSchemaContract, options?: SchemaValidationOptions): CompiledSchemaValidator;
|
|
8
|
+
export declare function jsonSchemaToFrontierSchema(schema: JsonSchemaContract, options?: JsonSchemaProfileOptions): Schema;
|
|
9
|
+
export declare function jsonSchemaToDiffProfile(schema: JsonSchemaContract, options?: JsonSchemaProfileOptions): DiffProfile;
|
|
10
|
+
//# sourceMappingURL=json-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.d.ts","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAEX,SAAS,EACT,MAAM,EAGP,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,uBAAuB,EACvB,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,EAGxB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAsBpB,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,uBAA4B,GACpC,sBAAsB,CA2BxB;AAED,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,2BAAgC,GACxC,sBAAsB,CAIxB;AAED,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,kBAAkB,EACrE,MAAM,EAAE,CAAC,EACT,OAAO,CAAC,EAAE,2BAA2B,GACpC,CAAC,CAIH;AAED,wBAAgB,wBAAwB,CAAC,CAAC,GAAG,SAAS,EACpD,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,kBAAkB,EAC1B,OAAO,CAAC,EAAE,uBAAuB,GAChC,CAAC,CAIH;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,CAAC,EAAE,uBAAuB,GAChC,uBAAuB,CASzB;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,wBAA6B,GACrC,MAAM,CAuBR;AAED,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,kBAAkB,EAC1B,OAAO,GAAE,wBAA6B,GACrC,WAAW,CAgBb"}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { cloneJson } from '@shapeshift-labs/frontier/clone';
|
|
2
|
+
import { equalsJson } from '@shapeshift-labs/frontier/equal';
|
|
3
|
+
import { assertJsonValue } from '@shapeshift-labs/frontier/validate';
|
|
4
|
+
import { addIssue, formatSchemaIssues, isPlainObject, normalizeMaxIssues } from './internal.js';
|
|
5
|
+
const SUPPORTED_JSON_SCHEMA_KEYWORDS = new Set([
|
|
6
|
+
'type',
|
|
7
|
+
'properties',
|
|
8
|
+
'required',
|
|
9
|
+
'items',
|
|
10
|
+
'additionalProperties',
|
|
11
|
+
'enum',
|
|
12
|
+
'const',
|
|
13
|
+
'minItems',
|
|
14
|
+
'maxItems',
|
|
15
|
+
'minLength',
|
|
16
|
+
'maxLength',
|
|
17
|
+
'minimum',
|
|
18
|
+
'maximum',
|
|
19
|
+
'pattern'
|
|
20
|
+
]);
|
|
21
|
+
const JSON_SCHEMA_TYPE_NAMES = new Set(['null', 'boolean', 'number', 'integer', 'string', 'array', 'object']);
|
|
22
|
+
export function validateJsonSchemaContract(value, schema, options = {}) {
|
|
23
|
+
const maxIssues = normalizeMaxIssues(options.maxIssues);
|
|
24
|
+
const schemaOptions = readSchemaDefinitionOptions(options.strictSchema, options.maxIssues);
|
|
25
|
+
if (schemaOptions !== null) {
|
|
26
|
+
const schemaResult = validateJsonSchemaDefinition(schema, schemaOptions);
|
|
27
|
+
if (!schemaResult.valid)
|
|
28
|
+
return schemaResult;
|
|
29
|
+
}
|
|
30
|
+
if (options.validateJson) {
|
|
31
|
+
const jsonOptions = options.validateJson === true ? undefined : options.validateJson;
|
|
32
|
+
try {
|
|
33
|
+
assertJsonValue(value, 'value', jsonOptions);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return {
|
|
37
|
+
valid: false,
|
|
38
|
+
issues: [{
|
|
39
|
+
path: [],
|
|
40
|
+
keyword: 'json',
|
|
41
|
+
message: error instanceof Error ? error.message : 'value must be valid JSON'
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const issues = [];
|
|
47
|
+
validateAgainstSchema(value, schema, [], issues, maxIssues);
|
|
48
|
+
return { valid: issues.length === 0, issues };
|
|
49
|
+
}
|
|
50
|
+
export function validateJsonSchemaDefinition(schema, options = {}) {
|
|
51
|
+
const issues = [];
|
|
52
|
+
validateSchemaDefinition(schema, [], issues, normalizeMaxIssues(options.maxIssues), options.allowUnsupportedKeywords === true);
|
|
53
|
+
return { valid: issues.length === 0, issues };
|
|
54
|
+
}
|
|
55
|
+
export function assertJsonSchemaDefinition(schema, options) {
|
|
56
|
+
const result = validateJsonSchemaDefinition(schema, options);
|
|
57
|
+
if (!result.valid)
|
|
58
|
+
throw new TypeError(formatSchemaIssues(result.issues));
|
|
59
|
+
return schema;
|
|
60
|
+
}
|
|
61
|
+
export function assertJsonSchemaContract(value, schema, options) {
|
|
62
|
+
const result = validateJsonSchemaContract(value, schema, options);
|
|
63
|
+
if (!result.valid)
|
|
64
|
+
throw new TypeError(formatSchemaIssues(result.issues));
|
|
65
|
+
return value;
|
|
66
|
+
}
|
|
67
|
+
export function compileJsonSchemaValidator(schema, options) {
|
|
68
|
+
if (!options || options.strictSchema !== false) {
|
|
69
|
+
assertJsonSchemaDefinition(schema, options && typeof options.strictSchema === 'object' ? options.strictSchema : undefined);
|
|
70
|
+
}
|
|
71
|
+
const compiledOptions = options ? { ...options, strictSchema: false } : {};
|
|
72
|
+
const clonedSchema = cloneJson(schema);
|
|
73
|
+
const validator = ((value) => validateJsonSchemaContract(value, clonedSchema, compiledOptions));
|
|
74
|
+
Object.defineProperty(validator, 'schema', { value: clonedSchema, enumerable: true });
|
|
75
|
+
return validator;
|
|
76
|
+
}
|
|
77
|
+
export function jsonSchemaToFrontierSchema(schema, options = {}) {
|
|
78
|
+
assertJsonSchemaDefinition(schema);
|
|
79
|
+
const path = options.path ? options.path.slice() : undefined;
|
|
80
|
+
if (schema.type === 'array' && schema.items && schema.items.type === 'object') {
|
|
81
|
+
return {
|
|
82
|
+
type: 'array',
|
|
83
|
+
path,
|
|
84
|
+
key: options.arrayKey,
|
|
85
|
+
item: {
|
|
86
|
+
type: 'object',
|
|
87
|
+
key: options.arrayKey,
|
|
88
|
+
fields: readSchemaFields(schema.items)
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (schema.type === 'object' || schema.properties) {
|
|
93
|
+
return {
|
|
94
|
+
type: 'object',
|
|
95
|
+
path,
|
|
96
|
+
fields: readSchemaFields(schema)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
throw new TypeError('JSON schema profile conversion requires an object schema or an array schema with object items');
|
|
100
|
+
}
|
|
101
|
+
export function jsonSchemaToDiffProfile(schema, options = {}) {
|
|
102
|
+
const frontierSchema = jsonSchemaToFrontierSchema(schema, options);
|
|
103
|
+
const schemas = isMultiSchema(frontierSchema) ? frontierSchema.schemas : [frontierSchema];
|
|
104
|
+
return {
|
|
105
|
+
version: 1,
|
|
106
|
+
plans: {
|
|
107
|
+
diff: {
|
|
108
|
+
strategy: 'schema',
|
|
109
|
+
schemaCount: schemas.length,
|
|
110
|
+
paths: schemas.map((entry) => entry.path || [])
|
|
111
|
+
},
|
|
112
|
+
equality: { strategy: 'schema' }
|
|
113
|
+
},
|
|
114
|
+
schema: schemas.length === 1 ? schemas[0] : undefined,
|
|
115
|
+
schemas: schemas.length > 1 ? schemas : undefined
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function validateSchemaDefinition(value, path, issues, maxIssues, allowUnsupportedKeywords) {
|
|
119
|
+
if (issues.length >= maxIssues)
|
|
120
|
+
return;
|
|
121
|
+
if (!isPlainObject(value)) {
|
|
122
|
+
addIssue(issues, path, 'schema', 'schema must be an object');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const schema = value;
|
|
126
|
+
const record = value;
|
|
127
|
+
if (!allowUnsupportedKeywords) {
|
|
128
|
+
const keys = Object.keys(record);
|
|
129
|
+
for (let i = 0; i < keys.length && issues.length < maxIssues; i++) {
|
|
130
|
+
const key = keys[i];
|
|
131
|
+
if (!SUPPORTED_JSON_SCHEMA_KEYWORDS.has(key))
|
|
132
|
+
addIssue(issues, path.concat(key), 'unsupportedKeyword', 'unsupported JSON schema keyword');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (issues.length >= maxIssues)
|
|
136
|
+
return;
|
|
137
|
+
if (schema.type !== undefined) {
|
|
138
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
139
|
+
if (types.length === 0)
|
|
140
|
+
addIssue(issues, path.concat('type'), 'type', 'schema type array must not be empty');
|
|
141
|
+
for (let i = 0; i < types.length && issues.length < maxIssues; i++) {
|
|
142
|
+
if (typeof types[i] !== 'string' || !JSON_SCHEMA_TYPE_NAMES.has(types[i])) {
|
|
143
|
+
addIssue(issues, path.concat('type'), 'type', 'schema type must be a supported JSON schema type name');
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (issues.length >= maxIssues)
|
|
149
|
+
return;
|
|
150
|
+
if (schema.properties !== undefined) {
|
|
151
|
+
if (!isPlainObject(schema.properties)) {
|
|
152
|
+
addIssue(issues, path.concat('properties'), 'properties', 'schema properties must be an object');
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const keys = Object.keys(schema.properties);
|
|
156
|
+
for (let i = 0; i < keys.length && issues.length < maxIssues; i++) {
|
|
157
|
+
const key = keys[i];
|
|
158
|
+
validateSchemaDefinition(schema.properties[key], path.concat('properties', key), issues, maxIssues, allowUnsupportedKeywords);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
if (issues.length >= maxIssues)
|
|
163
|
+
return;
|
|
164
|
+
if (schema.required !== undefined) {
|
|
165
|
+
if (!Array.isArray(schema.required)) {
|
|
166
|
+
addIssue(issues, path.concat('required'), 'required', 'schema required must be an array of property names');
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
for (let i = 0; i < schema.required.length && issues.length < maxIssues; i++) {
|
|
170
|
+
const key = schema.required[i];
|
|
171
|
+
if (typeof key !== 'string') {
|
|
172
|
+
addIssue(issues, path.concat('required', i), 'required', 'required property name must be a string');
|
|
173
|
+
}
|
|
174
|
+
else if (schema.properties && !Object.prototype.hasOwnProperty.call(schema.properties, key)) {
|
|
175
|
+
addIssue(issues, path.concat('required', i), 'strictRequired', 'required property should be declared in schema properties');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (issues.length >= maxIssues)
|
|
181
|
+
return;
|
|
182
|
+
if (schema.items !== undefined)
|
|
183
|
+
validateSchemaDefinition(schema.items, path.concat('items'), issues, maxIssues, allowUnsupportedKeywords);
|
|
184
|
+
if (issues.length >= maxIssues)
|
|
185
|
+
return;
|
|
186
|
+
if (schema.additionalProperties !== undefined &&
|
|
187
|
+
typeof schema.additionalProperties !== 'boolean') {
|
|
188
|
+
validateSchemaDefinition(schema.additionalProperties, path.concat('additionalProperties'), issues, maxIssues, allowUnsupportedKeywords);
|
|
189
|
+
}
|
|
190
|
+
if (issues.length >= maxIssues)
|
|
191
|
+
return;
|
|
192
|
+
if (schema.enum !== undefined) {
|
|
193
|
+
if (!Array.isArray(schema.enum)) {
|
|
194
|
+
addIssue(issues, path.concat('enum'), 'enum', 'schema enum must be an array');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
for (let i = 0; i < schema.enum.length && issues.length < maxIssues; i++) {
|
|
198
|
+
validateSchemaJsonLiteral(schema.enum[i], path.concat('enum', i), issues);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (issues.length >= maxIssues)
|
|
203
|
+
return;
|
|
204
|
+
if (schema.const !== undefined)
|
|
205
|
+
validateSchemaJsonLiteral(schema.const, path.concat('const'), issues);
|
|
206
|
+
if (issues.length >= maxIssues)
|
|
207
|
+
return;
|
|
208
|
+
validateNonNegativeIntegerKeyword(schema.minItems, path.concat('minItems'), 'minItems', issues);
|
|
209
|
+
if (issues.length >= maxIssues)
|
|
210
|
+
return;
|
|
211
|
+
validateNonNegativeIntegerKeyword(schema.maxItems, path.concat('maxItems'), 'maxItems', issues);
|
|
212
|
+
if (issues.length >= maxIssues)
|
|
213
|
+
return;
|
|
214
|
+
validateNonNegativeIntegerKeyword(schema.minLength, path.concat('minLength'), 'minLength', issues);
|
|
215
|
+
if (issues.length >= maxIssues)
|
|
216
|
+
return;
|
|
217
|
+
validateNonNegativeIntegerKeyword(schema.maxLength, path.concat('maxLength'), 'maxLength', issues);
|
|
218
|
+
if (issues.length >= maxIssues)
|
|
219
|
+
return;
|
|
220
|
+
validateFiniteNumberKeyword(schema.minimum, path.concat('minimum'), 'minimum', issues);
|
|
221
|
+
if (issues.length >= maxIssues)
|
|
222
|
+
return;
|
|
223
|
+
validateFiniteNumberKeyword(schema.maximum, path.concat('maximum'), 'maximum', issues);
|
|
224
|
+
if (issues.length >= maxIssues)
|
|
225
|
+
return;
|
|
226
|
+
if (schema.pattern !== undefined) {
|
|
227
|
+
if (typeof schema.pattern !== 'string') {
|
|
228
|
+
addIssue(issues, path.concat('pattern'), 'pattern', 'schema pattern must be a string');
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
try {
|
|
232
|
+
new RegExp(schema.pattern);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
addIssue(issues, path.concat('pattern'), 'pattern', 'schema pattern must be a valid regular expression');
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function validateAgainstSchema(value, schema, path, issues, maxIssues) {
|
|
241
|
+
if (issues.length >= maxIssues)
|
|
242
|
+
return;
|
|
243
|
+
if (!schema || typeof schema !== 'object') {
|
|
244
|
+
addIssue(issues, path, 'schema', 'schema must be an object');
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (schema.const !== undefined && !equalsJson(value, schema.const)) {
|
|
248
|
+
addIssue(issues, path, 'const', 'value must equal schema const');
|
|
249
|
+
if (issues.length >= maxIssues)
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (schema.enum !== undefined && !schema.enum.some((entry) => equalsJson(value, entry))) {
|
|
253
|
+
addIssue(issues, path, 'enum', 'value must match one of the schema enum values');
|
|
254
|
+
if (issues.length >= maxIssues)
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (schema.type !== undefined && !matchesSchemaType(value, schema.type)) {
|
|
258
|
+
addIssue(issues, path, 'type', 'value must match schema type ' + schemaTypeLabel(schema.type), schema.type, typeOfJsonValue(value));
|
|
259
|
+
if (issues.length >= maxIssues)
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (typeof value === 'string') {
|
|
263
|
+
if (schema.minLength !== undefined && value.length < schema.minLength)
|
|
264
|
+
addIssue(issues, path, 'minLength', 'string is shorter than minLength');
|
|
265
|
+
if (schema.maxLength !== undefined && value.length > schema.maxLength)
|
|
266
|
+
addIssue(issues, path, 'maxLength', 'string is longer than maxLength');
|
|
267
|
+
if (schema.pattern !== undefined && !(new RegExp(schema.pattern)).test(value))
|
|
268
|
+
addIssue(issues, path, 'pattern', 'string does not match pattern');
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
if (typeof value === 'number') {
|
|
272
|
+
if (schema.minimum !== undefined && value < schema.minimum)
|
|
273
|
+
addIssue(issues, path, 'minimum', 'number is smaller than minimum');
|
|
274
|
+
if (schema.maximum !== undefined && value > schema.maximum)
|
|
275
|
+
addIssue(issues, path, 'maximum', 'number is greater than maximum');
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (Array.isArray(value)) {
|
|
279
|
+
if (schema.minItems !== undefined && value.length < schema.minItems)
|
|
280
|
+
addIssue(issues, path, 'minItems', 'array has fewer items than minItems');
|
|
281
|
+
if (schema.maxItems !== undefined && value.length > schema.maxItems)
|
|
282
|
+
addIssue(issues, path, 'maxItems', 'array has more items than maxItems');
|
|
283
|
+
if (schema.items !== undefined) {
|
|
284
|
+
for (let i = 0; i < value.length && issues.length < maxIssues; i++) {
|
|
285
|
+
validateAgainstSchema(value[i], schema.items, path.concat(i), issues, maxIssues);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
if (isPlainObject(value)) {
|
|
291
|
+
const properties = schema.properties || {};
|
|
292
|
+
if (schema.required !== undefined) {
|
|
293
|
+
for (let i = 0; i < schema.required.length && issues.length < maxIssues; i++) {
|
|
294
|
+
const key = schema.required[i];
|
|
295
|
+
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
296
|
+
addIssue(issues, path.concat(key), 'required', 'required property is missing');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const keys = Object.keys(properties);
|
|
300
|
+
for (let i = 0; i < keys.length && issues.length < maxIssues; i++) {
|
|
301
|
+
const key = keys[i];
|
|
302
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
303
|
+
validateAgainstSchema(value[key], properties[key], path.concat(key), issues, maxIssues);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (schema.additionalProperties === false) {
|
|
307
|
+
const valueKeys = Object.keys(value);
|
|
308
|
+
for (let i = 0; i < valueKeys.length && issues.length < maxIssues; i++) {
|
|
309
|
+
const key = valueKeys[i];
|
|
310
|
+
if (!Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
311
|
+
addIssue(issues, path.concat(key), 'additionalProperties', 'additional property is not allowed');
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
else if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
|
|
316
|
+
const valueKeys = Object.keys(value);
|
|
317
|
+
for (let i = 0; i < valueKeys.length && issues.length < maxIssues; i++) {
|
|
318
|
+
const key = valueKeys[i];
|
|
319
|
+
if (!Object.prototype.hasOwnProperty.call(properties, key)) {
|
|
320
|
+
validateAgainstSchema(value[key], schema.additionalProperties, path.concat(key), issues, maxIssues);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
function readSchemaFields(schema) {
|
|
327
|
+
const properties = schema.properties || {};
|
|
328
|
+
const keys = Object.keys(properties).sort();
|
|
329
|
+
const fields = [];
|
|
330
|
+
for (let i = 0; i < keys.length; i++) {
|
|
331
|
+
const key = keys[i];
|
|
332
|
+
const child = properties[key];
|
|
333
|
+
if ((child.type === 'object' || child.properties) && child.properties !== undefined) {
|
|
334
|
+
fields[fields.length] = { key, type: 'object', fields: readSchemaFields(child) };
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
fields[fields.length] = key;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return fields;
|
|
341
|
+
}
|
|
342
|
+
function isMultiSchema(schema) {
|
|
343
|
+
return Object.prototype.hasOwnProperty.call(schema, 'schemas');
|
|
344
|
+
}
|
|
345
|
+
function matchesSchemaType(value, type) {
|
|
346
|
+
if (Array.isArray(type)) {
|
|
347
|
+
for (let i = 0; i < type.length; i++)
|
|
348
|
+
if (matchesSchemaType(value, type[i]))
|
|
349
|
+
return true;
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
if (type === 'null')
|
|
353
|
+
return value === null;
|
|
354
|
+
if (type === 'array')
|
|
355
|
+
return Array.isArray(value);
|
|
356
|
+
if (type === 'object')
|
|
357
|
+
return isPlainObject(value);
|
|
358
|
+
if (type === 'integer')
|
|
359
|
+
return typeof value === 'number' && Number.isInteger(value);
|
|
360
|
+
return typeof value === type;
|
|
361
|
+
}
|
|
362
|
+
function schemaTypeLabel(type) {
|
|
363
|
+
return Array.isArray(type) ? type.join('|') : type;
|
|
364
|
+
}
|
|
365
|
+
function typeOfJsonValue(value) {
|
|
366
|
+
if (value === null)
|
|
367
|
+
return 'null';
|
|
368
|
+
if (Array.isArray(value))
|
|
369
|
+
return 'array';
|
|
370
|
+
return typeof value;
|
|
371
|
+
}
|
|
372
|
+
function validateSchemaJsonLiteral(value, path, issues) {
|
|
373
|
+
try {
|
|
374
|
+
assertJsonValue(value, 'schema literal');
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
addIssue(issues, path, 'json', error instanceof Error ? error.message : 'schema literal must be valid JSON');
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function validateNonNegativeIntegerKeyword(value, path, keyword, issues) {
|
|
381
|
+
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0)) {
|
|
382
|
+
addIssue(issues, path, keyword, 'schema ' + keyword + ' must be a non-negative safe integer');
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
function validateFiniteNumberKeyword(value, path, keyword, issues) {
|
|
386
|
+
if (value !== undefined && (typeof value !== 'number' || !Number.isFinite(value))) {
|
|
387
|
+
addIssue(issues, path, keyword, 'schema ' + keyword + ' must be a finite number');
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function readSchemaDefinitionOptions(value, fallbackMaxIssues) {
|
|
391
|
+
if (value === undefined || value === false)
|
|
392
|
+
return null;
|
|
393
|
+
if (value === true)
|
|
394
|
+
return { maxIssues: fallbackMaxIssues };
|
|
395
|
+
return { maxIssues: value.maxIssues ?? fallbackMaxIssues, allowUnsupportedKeywords: value.allowUnsupportedKeywords };
|
|
396
|
+
}
|
|
397
|
+
//# sourceMappingURL=json-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-schema.js","sourceRoot":"","sources":["../src/json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAmBrE,OAAO,EAAE,QAAQ,EAAE,kBAAkB,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEhG,MAAM,8BAA8B,GAAG,IAAI,GAAG,CAAC;IAC7C,MAAM;IACN,YAAY;IACZ,UAAU;IACV,OAAO;IACP,sBAAsB;IACtB,MAAM;IACN,OAAO;IACP,UAAU;IACV,UAAU;IACV,WAAW;IACX,WAAW;IACX,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;AAE9G,MAAM,UAAU,0BAA0B,CACxC,KAAc,EACd,MAA0B,EAC1B,UAAmC,EAAE;IAErC,MAAM,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACxD,MAAM,aAAa,GAAG,2BAA2B,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC3F,IAAI,aAAa,KAAK,IAAI,EAAE,CAAC;QAC3B,MAAM,YAAY,GAAG,4BAA4B,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QACzE,IAAI,CAAC,YAAY,CAAC,KAAK;YAAE,OAAO,YAAY,CAAC;IAC/C,CAAC;IAED,IAAI,OAAO,CAAC,Y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gB,GAAG,CAAC,CAAC,EAAE,CAAC;QACnF,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,GAAG,OAAO,GAAG,sCAAsC,CAAC,CAAC;IAChG,CAAC;AACH,CAAC;AAED,SAAS,2BAA2B,CAClC,KAAc,EACd,IAAc,EACd,OAAe,EACf,MAA+B;IAE/B,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAClF,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,GAAG,OAAO,GAAG,0BAA0B,CAAC,CAAC;IACpF,CAAC;AACH,CAAC;AAED,SAAS,2BAA2B,CAClC,KAAwD,EACxD,iBAAqC;IAErC,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IACxD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAC5D,OAAO,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,IAAI,iBAAiB,EAAE,wBAAwB,EAAE,KAAK,CAAC,wBAAwB,EAAE,CAAC;AACvH,CAAC"}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,KAAK,qBAAqB,EAC1B,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACtB,MAAM,iCAAiC,CAAC"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EAMrB,MAAM,iCAAiC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { JsonObject, JsonPath, JsonValidationOptions, JsonValue, ObjectKey } from '@shapeshift-labs/frontier/types';
|
|
2
|
+
import type { DiffProfile, Schema, SchemaField, SingleSchema } from '@shapeshift-labs/frontier-engine/types';
|
|
3
|
+
export type { DiffProfile, JsonObject, JsonPath, JsonValidationOptions, JsonValue, ObjectKey, Schema, SchemaField, SingleSchema };
|
|
4
|
+
export type JsonSchemaTypeName = 'null' | 'boolean' | 'number' | 'integer' | 'string' | 'array' | 'object';
|
|
5
|
+
export interface JsonSchemaContract {
|
|
6
|
+
type?: JsonSchemaTypeName | JsonSchemaTypeName[];
|
|
7
|
+
properties?: Record<string, JsonSchemaContract>;
|
|
8
|
+
required?: string[];
|
|
9
|
+
items?: JsonSchemaContract;
|
|
10
|
+
additionalProperties?: boolean | JsonSchemaContract;
|
|
11
|
+
enum?: JsonValue[];
|
|
12
|
+
const?: JsonValue;
|
|
13
|
+
minItems?: number;
|
|
14
|
+
maxItems?: number;
|
|
15
|
+
minLength?: number;
|
|
16
|
+
maxLength?: number;
|
|
17
|
+
minimum?: number;
|
|
18
|
+
maximum?: number;
|
|
19
|
+
pattern?: string;
|
|
20
|
+
}
|
|
21
|
+
export interface SchemaValidationIssue {
|
|
22
|
+
path: JsonPath;
|
|
23
|
+
keyword: string;
|
|
24
|
+
message: string;
|
|
25
|
+
expected?: JsonValue;
|
|
26
|
+
actual?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface SchemaValidationResult {
|
|
29
|
+
valid: boolean;
|
|
30
|
+
issues: SchemaValidationIssue[];
|
|
31
|
+
}
|
|
32
|
+
export interface JsonSchemaDefinitionOptions {
|
|
33
|
+
maxIssues?: number;
|
|
34
|
+
allowUnsupportedKeywords?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface SchemaValidationOptions {
|
|
37
|
+
maxIssues?: number;
|
|
38
|
+
validateJson?: boolean | JsonValidationOptions;
|
|
39
|
+
strictSchema?: boolean | JsonSchemaDefinitionOptions;
|
|
40
|
+
}
|
|
41
|
+
export type CompiledSchemaValidator<T = unknown> = {
|
|
42
|
+
(value: T): SchemaValidationResult;
|
|
43
|
+
readonly schema: JsonSchemaContract;
|
|
44
|
+
};
|
|
45
|
+
export interface JsonSchemaProfileOptions {
|
|
46
|
+
path?: JsonPath;
|
|
47
|
+
arrayKey?: ObjectKey;
|
|
48
|
+
}
|
|
49
|
+
export interface CloudEventEnvelope<T extends JsonValue = JsonValue> extends JsonObject {
|
|
50
|
+
specversion: '1.0';
|
|
51
|
+
id: string;
|
|
52
|
+
source: string;
|
|
53
|
+
type: string;
|
|
54
|
+
subject?: string;
|
|
55
|
+
time?: string;
|
|
56
|
+
datacontenttype?: string;
|
|
57
|
+
dataschema?: string;
|
|
58
|
+
data?: T;
|
|
59
|
+
}
|
|
60
|
+
export interface CloudEventEnvelopeInput<T extends JsonValue = JsonValue> {
|
|
61
|
+
id: string;
|
|
62
|
+
source: string;
|
|
63
|
+
type: string;
|
|
64
|
+
subject?: string;
|
|
65
|
+
time?: string | Date;
|
|
66
|
+
datacontenttype?: string;
|
|
67
|
+
dataschema?: string;
|
|
68
|
+
data?: T;
|
|
69
|
+
extensions?: JsonObject;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,QAAQ,EACR,qBAAqB,EACrB,SAAS,EACT,SAAS,EACV,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,WAAW,EACX,YAAY,EACb,MAAM,wCAAwC,CAAC;AAEhD,YAAY,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,MA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ourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,19 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapeshift-labs/frontier-schema",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "JSON Schema validation, Frontier profile generation, CloudEvent envelopes, and table-schema helpers.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+ssh://git@github.com/siliconjungle/-shapeshift-labs-frontier-schema.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/siliconjungle/-shapeshift-labs-frontier-schema#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/siliconjungle/-shapeshift-labs-frontier-schema/issues"
|
|
15
|
+
},
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
7
18
|
"exports": {
|
|
8
|
-
".":
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./json-schema": {
|
|
25
|
+
"types": "./dist/json-schema.d.ts",
|
|
26
|
+
"import": "./dist/json-schema.js",
|
|
27
|
+
"default": "./dist/json-schema.js"
|
|
28
|
+
},
|
|
29
|
+
"./event": {
|
|
30
|
+
"types": "./dist/event.d.ts",
|
|
31
|
+
"import": "./dist/event.js",
|
|
32
|
+
"default": "./dist/event.js"
|
|
33
|
+
},
|
|
34
|
+
"./query": {
|
|
35
|
+
"types": "./dist/query.d.ts",
|
|
36
|
+
"import": "./dist/query.js",
|
|
37
|
+
"default": "./dist/query.js"
|
|
38
|
+
},
|
|
39
|
+
"./types": {
|
|
40
|
+
"types": "./dist/types.d.ts",
|
|
41
|
+
"default": "./dist/types.d.ts"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
9
44
|
},
|
|
10
45
|
"files": [
|
|
11
|
-
"
|
|
12
|
-
"README.md"
|
|
46
|
+
"dist",
|
|
47
|
+
"README.md",
|
|
48
|
+
"LICENSE",
|
|
49
|
+
"benchmarks/package-bench.mjs"
|
|
13
50
|
],
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=18"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@shapeshift-labs/frontier": "^0.1.5",
|
|
56
|
+
"@shapeshift-labs/frontier-engine": "^0.1.0",
|
|
57
|
+
"@shapeshift-labs/frontier-query": "^0.1.0"
|
|
58
|
+
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "node build.mjs",
|
|
61
|
+
"test": "npm run build && npm run typecheck && node test/smoke.mjs && node test/fuzz.mjs --cases 500",
|
|
62
|
+
"prepack": "npm run test",
|
|
63
|
+
"typecheck": "tsc -p test/tsconfig.json --noEmit",
|
|
64
|
+
"fuzz": "npm run build && node test/fuzz.mjs",
|
|
65
|
+
"bench": "npm run build && node benchmarks/package-bench.mjs",
|
|
66
|
+
"pack:dry": "npm pack --dry-run"
|
|
67
|
+
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"frontier",
|
|
70
|
+
"schema",
|
|
71
|
+
"json-schema",
|
|
72
|
+
"validation",
|
|
73
|
+
"profile",
|
|
74
|
+
"cloudevents"
|
|
75
|
+
],
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"typescript": "^6.0.3"
|
|
18
78
|
}
|
|
19
79
|
}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|