jsonSchema.ts ×10

Frontier kind: Joint frontier

unlabeled · c_39fd5eecdb32

5 tests · 3686 LOC · 19 files · introduces 3 tests · 112 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
10 ranges112 lines · 1 files
Tests
3 tests

Contains — complete concept membership

All code (extent)
494 ranges3686 lines · 19 files · Browse complete extent
All tests (intent)
5 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Introduced files, introduced tests, and structurally relevant concept specializationjsonSchema.ts ×1 · 2 introduced LOCjsonSchema.ts ×1jsonSchema.ts ×1 · 6 introduced LOCjsonSchema.ts ×1uri.test|title=URI URI#file, win-speciale|occurrence=1, charCode.test|title=CharCode has good values|occurrence=1, +2 · 0 introduced LOCuri.test|title=URI URI#f…utils.ts ×3 · 9 introduced LOCutils.ts ×3jsonSchema.ts ×3 · 194 introduced LOCjsonSchema.ts ×3lifecycle.ts ×2 · 4 introduced LOClifecycle.ts ×2lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×4 · 8 introduced LOClifecycle.ts ×4lifecycle.ts ×6 · 16 introduced LOClifecycle.ts ×6lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 2 introduced LOClifecycle.ts ×1lifecycle.ts ×1 · 3 introduced LOClifecycle.ts ×1map.ts ×97 · 3334 introduced LOCmap.ts ×97src/vs/base/common/arrays.ts · 949 LOCcommon/arrays.tssrc/vs/base/common/arraysFind.ts · 226 LOCcommon/arraysFind.tssrc/vs/base/common/assert.ts · 91 LOCcommon/assert.tssrc/vs/base/common/charCode.ts · 450 LOCcommon/charCode.tssrc/vs/base/common/collections.ts · 176 LOCcommon/collections.tssrc/vs/base/common/errors.ts · 357 LOCcommon/errors.tssrc/vs/base/common/functional.ts · 32 LOCcommon/functional.tssrc/vs/base/common/iterator.ts · 194 LOCcommon/iterator.tssrc/vs/base/common/jsonSchema.ts · 330 LOCcommon/jsonSchema.tssrc/vs/base/common/lifecycle.ts · 974 LOCcommon/lifecycle.tssrc/vs/base/common/map.ts · 1016 LOCcommon/map.tssrc/vs/base/common/marshallingIds.ts · 33 LOCcommon/marshallingIds.tssrc/vs/base/common/path.ts · 1589 LOCcommon/path.tssrc/vs/base/common/platform.ts · 281 LOCcommon/platform.tssrc/vs/base/common/process.ts · 76 LOCcommon/process.tssrc/vs/base/common/types.ts · 410 LOCcommon/types.tssrc/vs/base/common/uri.ts · 754 LOCcommon/uri.tssrc/vs/base/test/common/utils.ts · 107 LOCcommon/utils.tssrc/vs/nls.ts · 244 LOCvs/nls.tscharCode.test|title=CharCode has good values|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/charCode.test|title=CharCode has good values|occurrence=1charCode.test|title=Char…jsonSchema.test|title=JSON Schema getCompressedContent 1|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/jsonSchema.test|title=JSON Schema getCompressedContent 1|occurrence=1jsonSchema.test|title=JS…jsonSchema.test|title=JSON Schema getCompressedContent 2|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/jsonSchema.test|title=JSON Schema getCompressedContent 2|occurrence=1jsonSchema.test|title=JS…jsonSchema.test|title=JSON Schema getCompressedContent 3|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/jsonSchema.test|title=JSON Schema getCompressedContent 3|occurrence=1jsonSchema.test|title=JS…jsonSchema.test|title=JSON Schema getCompressedContent 4|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/jsonSchema.test|title=JSON Schema getCompressedContent 4|occurrence=1jsonSchema.test|title=JS…jsonSchema.test|title=JSON Schema getCompressedContent 5|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/jsonSchema.test|title=JSON Schema getCompressedContent 5|occurrence=1jsonSchema.test|title=JS…path.test|title=Paths (Node Implementation) path|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/path.test|title=Paths (Node Implementation) path|occurrence=1path.test|title=Paths (N…uri.test|title=URI File paths containing apostrophes break URI parsing and cannot be opened #276075|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/uri.test|title=URI File paths containing apostrophes break URI parsing and cannot be opened #276075|occurrence=1uri.test|title=URI File …uri.test|title=URI URI#file, win-speciale|occurrence=1 · introduced test · mocha:v1|namespace=vscode@05c208e9e28d8c1c723fa08f85e2b7a96092e8e5|file=vs/base/test/common/uri.test|title=URI URI#file, win-speciale|occurrence=1uri.test|title=URI URI#f…Focused concept · jsonSchema.ts ×10 · 112 introduced LOCjsonSchema.ts ×10

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

3 tests introduced at this concept.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 112 introduced LOC across 10 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/base/common/jsonSchema.ts 112 introduced LOC · 10 ranges

Open complete file

186
187 export function getCompressedContent(schema: IJSONSchema): string {
188 > let hasDups = false; jsonSchema.ts
189 >
190 >
191 > // visit all schema nodes and collect the ones that are equal
192 > const equalsByString = new Map<string, Equals>();
193 > const nodeToEquals = new Map<IJSONSchema, Equals>();
194 > const visitSchemas = (next: IJSONSchema) => {
195 > if (schema === next) {
196 > return true;
197 > }
198 > const val = JSON.stringify(next);
199 > if (val.length < 30) {
200 > // the $ref takes around 25 chars, so we don't save anything
201 > return true;
202 > }
203 > const eq = equalsByString.get(val);
204 > if (!eq) {
205 > const newEq = { schemas: [next] };
206 > equalsByString.set(val, newEq);
207 > nodeToEquals.set(next, newEq);
208 > return true;
209 > }
210 > eq.schemas.push(next);
211 > nodeToEquals.set(next, eq);
212 > hasDups = true;
213 > return false;
214 > };
215 > traverseNodes(schema, visitSchemas);
216 > equalsByString.clear();
217 >
218 > if (!hasDups) {
219 return JSON.stringify(schema);
220 }
222 > let defNodeName = '$defs';
223 > while (schema.hasOwnProperty(defNodeName)) {
224 defNodeName += '_';
225 }
227 > // used to collect all schemas that are later put in `$defs`. The index in the array is the id of the schema.
228 > const definitions: IJSONSchema[] = [];
229 >
230 > function stringify(root: IJSONSchema): string {
231 > return JSON.stringify(root, (_key: string, value: any) => {
232 > if (value !== root) {
233 > const eq = nodeToEquals.get(value);
234 > if (eq && eq.schemas.length > 1) {
235 > if (!eq.id) {
236 > eq.id = `_${definitions.length}`;
237 > definitions.push(eq.schemas[0]);
238 > }
239 > return { $ref: `#/${defNodeName}/${eq.id}` };
240 > }
241 > }
242 > return value;
243 > });
244 > }
245 >
246 > // stringify the schema and replace duplicate subtrees with $ref
247 > // this will add new items to the definitions array
248 > const str = stringify(schema);
249 >
250 > // now stringify the definitions. Each invication of stringify cann add new items to the definitions array, so the length can grow while we iterate
251 > const defStrings: string[] = [];
252 > for (let i = 0; i < definitions.length; i++) {
253 > defStrings.push(`"_${i}":${stringify(definitions[i])}`);
254 > }
255 > if (defStrings.length) {
256 > return `${str.substring(0, str.length - 1)},"${defNodeName}":{${defStrings.join(',')}}}`;
257 > }
258 return str;
259 }
261 type IJSONSchemaRef = IJSONSchema | boolean;
262
263 > function isObject(thing: unknown): thing is object { jsonSchema.ts
264 > return typeof thing === 'object' && thing !== null;
265 > }
266
267 /*
268 * Traverse a JSON schema and visit each schema node
269 */
270 > function traverseNodes(root: IJSONSchema, visit: (schema: IJSONSchema) => boolean) { jsonSchema.ts
271 > if (!root || typeof root !== 'object') {
272 return;
273 }
274 > const collectEntries = (...entries: (IJSONSchemaRef | undefined)[]) => { jsonSchema.ts
275 > for (const entry of entries) {
276 > if (isObject(entry)) {
277 toWalk.push(entry);
278 }
279 > } jsonSchema.ts
280 > };
281 > const collectMapEntries = (...maps: (IJSONSchemaMap | undefined)[]) => {
282 > for (const map of maps) {
283 > if (isObject(map)) {
284 > for (const key in map) {
285 > const entry = map[key];
286 > if (isObject(entry)) {
287 > toWalk.push(entry);
288 > }
289 > }
290 > }
291 > }
292 > };
293 > const collectArrayEntries = (...arrays: (IJSONSchemaRef[] | undefined)[]) => {
294 > for (const array of arrays) {
295 > if (Array.isArray(array)) {
296 for (const entry of array) {
297 if (isObject(entry)) {
300 }
301 }
302 > } jsonSchema.ts
303 > };
304 > const collectEntryOrArrayEntries = (items: (IJSONSchemaRef[] | IJSONSchemaRef | undefined)) => {
305 > if (Array.isArray(items)) {
306 for (const entry of items) {
307 if (isObject(entry)) {
309 }
310 }
311 > } else if (isObject(items)) { jsonSchema.ts
312 toWalk.push(items);
313 }
314 > }; jsonSchema.ts
315 >
316 > const toWalk: IJSONSchema[] = [root];
317 >
318 > let next = toWalk.pop();
319 > while (next) {
320 > const visitChildern = visit(next);
321 > if (visitChildern) {
322 > collectEntries(next.additionalItems, next.additionalProperties, next.not, next.contains, next.propertyNames, next.if, next.then, next.else, next.unevaluatedItems, next.unevaluatedProperties);
323 > collectMapEntries(next.definitions, next.$defs, next.properties, next.patternProperties, <IJSONSchemaMap>next.dependencies, next.dependentSchemas);
324 > collectArrayEntries(next.anyOf, next.allOf, next.oneOf, next.prefixItems);
325 > collectEntryOrArrayEntries(next.items);
326 > }
327 > next = toWalk.pop();
328 > }
329 > }
330