@squiz/dx-json-schema-lib 1.82.3 → 1.82.5
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/CHANGELOG.md +14 -0
- package/README.md +132 -0
- package/lib/JsonSchemaService.allOf.spec.d.ts +1 -0
- package/lib/JsonSchemaService.allOf.spec.js +528 -0
- package/lib/JsonSchemaService.allOf.spec.js.map +1 -0
- package/lib/JsonSchemaService.d.ts +20 -0
- package/lib/JsonSchemaService.js +165 -1
- package/lib/JsonSchemaService.js.map +1 -1
- package/lib/resolvableTypes/MatrixAsset.d.ts +1 -0
- package/lib/resolvableTypes/MatrixAsset.js +3 -0
- package/lib/resolvableTypes/MatrixAsset.js.map +1 -1
- package/package.json +2 -2
- package/src/JsonSchemaService.allOf.spec.ts +573 -0
- package/src/JsonSchemaService.ts +187 -1
- package/src/resolvableTypes/MatrixAsset.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 1.82.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2d02c0c: Added support for squizlink to have custom text
|
|
8
|
+
|
|
9
|
+
## 1.82.4
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- b5c200d: SquizLink/Image Fixes
|
|
14
|
+
|
|
3
15
|
## 1.82.3
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -179,6 +191,7 @@
|
|
|
179
191
|
- 985e1a5: ### Updates to DAM asset resolver package
|
|
180
192
|
|
|
181
193
|
**Changes:**
|
|
194
|
+
|
|
182
195
|
- Updated DAM resolver package versions.
|
|
183
196
|
- Updated Json validation schema so multiple resolvers can be used for SquizImage type.
|
|
184
197
|
- Updated higher order node map so Dam images could be resolved to simple url.
|
|
@@ -191,6 +204,7 @@
|
|
|
191
204
|
- 4d4c053: ### Updates to DAM asset resolver package
|
|
192
205
|
|
|
193
206
|
**Changes:**
|
|
207
|
+
|
|
194
208
|
- Updated DAM resolver package versions.
|
|
195
209
|
- Updated Json validation schema so multiple resolvers can be used for SquizImage type.
|
|
196
210
|
- Updated higher order node map so Dam images could be resolved to simple url.
|
package/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# @squiz/dx-json-schema-lib
|
|
2
|
+
|
|
3
|
+
JSON Schema validation and resolution library for Squiz DX platform, with specialized support for primitive types like `SquizLink` and `SquizImage`.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ JSON Schema validation and resolution
|
|
8
|
+
- ✅ Support for custom primitive types (`SquizLink`, `SquizImage`, `FormattedText`)
|
|
9
|
+
- ✅ AllOf conditional schema support with data preservation
|
|
10
|
+
- ✅ Resolvable types integration (Matrix Assets, etc.)
|
|
11
|
+
- ✅ High performance with comprehensive test coverage
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { JSONSchemaService } from '@squiz/dx-json-schema-lib';
|
|
17
|
+
import { TypeResolverBuilder } from '@squiz/dx-json-schema-lib/jsonTypeResolution';
|
|
18
|
+
import { SquizLinkType, SquizImageType } from '@squiz/dx-json-schema-lib/primitiveTypes';
|
|
19
|
+
|
|
20
|
+
// Create service with primitive type support
|
|
21
|
+
const typeResolver = new TypeResolverBuilder()
|
|
22
|
+
.addPrimitive(SquizLinkType)
|
|
23
|
+
.addPrimitive(SquizImageType)
|
|
24
|
+
.build();
|
|
25
|
+
|
|
26
|
+
const service = new JSONSchemaService(typeResolver, schema);
|
|
27
|
+
|
|
28
|
+
// Resolve input data
|
|
29
|
+
const resolvedData = await service.resolveInput(inputData, inputSchema);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## AllOf Conditional Schema Support
|
|
33
|
+
|
|
34
|
+
This library provides robust support for `allOf` conditional schemas, including data preservation for `SquizLink` and `SquizImage` arrays within conditional structures:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
// ✅ FULLY SUPPORTED: Single-level allOf conditions
|
|
38
|
+
{
|
|
39
|
+
"type": "object",
|
|
40
|
+
"properties": {
|
|
41
|
+
"contentType": { "type": "string", "enum": ["basic", "advanced"] }
|
|
42
|
+
},
|
|
43
|
+
"allOf": [
|
|
44
|
+
{
|
|
45
|
+
"if": { "properties": { "contentType": { "const": "advanced" } } },
|
|
46
|
+
"then": {
|
|
47
|
+
"properties": {
|
|
48
|
+
"links": {
|
|
49
|
+
"type": "array",
|
|
50
|
+
"items": { "type": "SquizLink" }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Known Limitations
|
|
60
|
+
|
|
61
|
+
#### Complex Deeply Nested AllOf Structures
|
|
62
|
+
|
|
63
|
+
**Limitation**: The current implementation has a known edge case with deeply nested `allOf` conditional schemas within array structures.
|
|
64
|
+
|
|
65
|
+
**Example of unsupported pattern**:
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// ❌ COMPLEX EDGE CASE: Multi-level nested allOf in arrays
|
|
69
|
+
{
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"sections": {
|
|
73
|
+
"type": "array",
|
|
74
|
+
"items": {
|
|
75
|
+
"type": "object",
|
|
76
|
+
"properties": {
|
|
77
|
+
"sectionType": { "type": "string" }
|
|
78
|
+
},
|
|
79
|
+
"allOf": [ // ✅ Level 1 allOf - WORKS
|
|
80
|
+
{
|
|
81
|
+
"if": { "properties": { "sectionType": { "const": "content" } } },
|
|
82
|
+
"then": {
|
|
83
|
+
"properties": {
|
|
84
|
+
"contentGroups": {
|
|
85
|
+
"type": "array",
|
|
86
|
+
"items": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"properties": {
|
|
89
|
+
"groupType": { "type": "string" }
|
|
90
|
+
},
|
|
91
|
+
"allOf": [ // ❌ Level 2 allOf - EDGE CASE
|
|
92
|
+
{
|
|
93
|
+
"if": { "properties": { "groupType": { "const": "links" } } },
|
|
94
|
+
"then": {
|
|
95
|
+
"properties": {
|
|
96
|
+
"groupLinks": {
|
|
97
|
+
"type": "array",
|
|
98
|
+
"items": { "type": "SquizLink" }
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Impact**:
|
|
117
|
+
|
|
118
|
+
- This pattern represents a rare edge case in real-world schemas
|
|
119
|
+
- Known practical production use cases work perfectly
|
|
120
|
+
|
|
121
|
+
**Workaround**:
|
|
122
|
+
|
|
123
|
+
- Flatten deeply nested conditional structures where possible
|
|
124
|
+
- Use separate schema definitions for complex nested conditions
|
|
125
|
+
- Consider restructuring schemas to avoid multiple levels of array-embedded `allOf` patterns
|
|
126
|
+
|
|
127
|
+
**Future Enhancement**:
|
|
128
|
+
This limitation could be addressed in a future version by implementing:
|
|
129
|
+
|
|
130
|
+
- Recursive `allOf` detection across multiple nesting levels
|
|
131
|
+
- Enhanced pointer-based data preservation for deeply nested structures
|
|
132
|
+
- Advanced JSON Schema library processing overrides for complex recursive scenarios
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|