json-machete 0.2.0-alpha-72c3f2bb5.0 → 0.2.1-alpha-044ef7368.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.
Files changed (3) hide show
  1. package/index.js +9 -8
  2. package/index.mjs +10 -9
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -10,7 +10,6 @@ const path = require('path');
10
10
  const util = require('util');
11
11
  const urlJoin = _interopDefault(require('url-join'));
12
12
  const crossUndiciFetch = require('cross-undici-fetch');
13
- const fs = require('fs');
14
13
 
15
14
  (function (OnCircularReference) {
16
15
  OnCircularReference["WARN"] = "WARN";
@@ -402,7 +401,7 @@ async function healJSONSchema(schema) {
402
401
  }
403
402
  }
404
403
  // Properties only exist in objects
405
- if (subSchema.properties) {
404
+ if (subSchema.properties || subSchema.patternProperties || 'additionalProperties' in subSchema) {
406
405
  subSchema.type = 'object';
407
406
  }
408
407
  // Items only exist in arrays
@@ -420,7 +419,6 @@ async function healJSONSchema(schema) {
420
419
  });
421
420
  }
422
421
 
423
- const { readFile } = fs.promises;
424
422
  const resolvePath = (path, root) => {
425
423
  return jsonPtr.JsonPointer.get(root, path);
426
424
  };
@@ -480,11 +478,14 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
480
478
  const newCwd = getCwd(externalFilePath);
481
479
  let externalFile = externalFileCache.get(externalFilePath);
482
480
  if (!externalFile) {
483
- externalFile = isURL(externalFilePath)
484
- ? await fetch(externalFilePath, {
485
- headers,
486
- }).then(res => res.json())
487
- : await JSON.parse(await readFile(externalFilePath, 'utf-8'));
481
+ externalFile = await utils.readFileOrUrl(externalFilePath, {
482
+ fetch,
483
+ headers,
484
+ cwd,
485
+ fallbackFormat: 'json',
486
+ }).catch(() => {
487
+ throw new Error(`Unable to load ${externalRelativeFilePath} from ${cwd}`);
488
+ });
488
489
  externalFile = await healJSONSchema(externalFile);
489
490
  externalFileCache.set(externalFilePath, externalFile);
490
491
  }
package/index.mjs CHANGED
@@ -1,10 +1,9 @@
1
1
  import { JsonPointer } from 'json-ptr';
2
- import { AggregateError } from '@graphql-mesh/utils';
2
+ import { AggregateError, readFileOrUrl } from '@graphql-mesh/utils';
3
3
  import { isAbsolute, join, dirname } from 'path';
4
4
  import { inspect } from 'util';
5
5
  import urlJoin from 'url-join';
6
6
  import { fetch } from 'cross-undici-fetch';
7
- import { promises } from 'fs';
8
7
 
9
8
  var OnCircularReference;
10
9
  (function (OnCircularReference) {
@@ -397,7 +396,7 @@ async function healJSONSchema(schema) {
397
396
  }
398
397
  }
399
398
  // Properties only exist in objects
400
- if (subSchema.properties) {
399
+ if (subSchema.properties || subSchema.patternProperties || 'additionalProperties' in subSchema) {
401
400
  subSchema.type = 'object';
402
401
  }
403
402
  // Items only exist in arrays
@@ -415,7 +414,6 @@ async function healJSONSchema(schema) {
415
414
  });
416
415
  }
417
416
 
418
- const { readFile } = promises;
419
417
  const resolvePath = (path, root) => {
420
418
  return JsonPointer.get(root, path);
421
419
  };
@@ -475,11 +473,14 @@ async function dereferenceObject(obj, { cwd = process.cwd(), externalFileCache =
475
473
  const newCwd = getCwd(externalFilePath);
476
474
  let externalFile = externalFileCache.get(externalFilePath);
477
475
  if (!externalFile) {
478
- externalFile = isURL(externalFilePath)
479
- ? await fetch$1(externalFilePath, {
480
- headers,
481
- }).then(res => res.json())
482
- : await JSON.parse(await readFile(externalFilePath, 'utf-8'));
476
+ externalFile = await readFileOrUrl(externalFilePath, {
477
+ fetch: fetch$1,
478
+ headers,
479
+ cwd,
480
+ fallbackFormat: 'json',
481
+ }).catch(() => {
482
+ throw new Error(`Unable to load ${externalRelativeFilePath} from ${cwd}`);
483
+ });
483
484
  externalFile = await healJSONSchema(externalFile);
484
485
  externalFileCache.set(externalFilePath, externalFile);
485
486
  }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "json-machete",
3
- "version": "0.2.0-alpha-72c3f2bb5.0",
3
+ "version": "0.2.1-alpha-044ef7368.0",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
- "@graphql-mesh/utils": "0.22.0",
6
+ "@graphql-mesh/utils": "0.22.2-alpha-044ef7368.0",
7
7
  "@json-schema-tools/meta-schema": "1.6.19",
8
8
  "cross-undici-fetch": "0.0.26",
9
9
  "json-ptr": "2.2.0",