@takeshape/schema 8.170.0 → 8.173.1

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.
@@ -6,7 +6,17 @@ import { ProjectSchema, PropertySchema, Shape } from '../project-schema';
6
6
  * @param queryPath
7
7
  *
8
8
  * @example
9
- * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection, ['edges', 'node']) // finds Shopify_Product
9
+ * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds {'@ref': Shopify_Product}
10
10
  */
11
- export declare function findShapeAtPath(projectSchema: ProjectSchema, schema: PropertySchema, queryPath: string[]): Shape | undefined;
11
+ export declare function findSchemaAtPath(projectSchema: ProjectSchema, schema: PropertySchema, queryPath: string[]): PropertySchema | undefined;
12
+ /**
13
+ *
14
+ * @param projectSchema
15
+ * @param propSchema
16
+ * @param queryPath
17
+ *
18
+ * @example
19
+ * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds Shopify_Product
20
+ */
21
+ export declare function findShapeAtPath(projectSchema: ProjectSchema, propSchema: PropertySchema, queryPath: string[]): Shape | undefined;
12
22
  //# sourceMappingURL=find-shape-at-path.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-shape-at-path.d.ts","sourceRoot":"","sources":["../../../src/util/find-shape-at-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAIvE;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EAAE,GAClB,KAAK,GAAG,SAAS,CAuBnB"}
1
+ {"version":3,"file":"find-shape-at-path.d.ts","sourceRoot":"","sources":["../../../src/util/find-shape-at-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAIvE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,EAAE,GAClB,cAAc,GAAG,SAAS,CA8B5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,cAAc,EAC1B,SAAS,EAAE,MAAM,EAAE,GAClB,KAAK,GAAG,SAAS,CAMnB"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.findSchemaAtPath = findSchemaAtPath;
6
7
  exports.findShapeAtPath = findShapeAtPath;
7
8
 
8
9
  var _types = require("../types");
@@ -16,31 +17,59 @@ var _refs = require("../refs");
16
17
  * @param queryPath
17
18
  *
18
19
  * @example
19
- * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection, ['edges', 'node']) // finds Shopify_Product
20
+ * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds {'@ref': Shopify_Product}
20
21
  */
21
- function findShapeAtPath(projectSchema, schema, queryPath) {
22
+ function findSchemaAtPath(projectSchema, schema, queryPath) {
23
+ if (queryPath.length === 0) {
24
+ return schema;
25
+ }
26
+
22
27
  const [prop, ...rest] = queryPath;
23
28
 
24
29
  if ((0, _types.isRefSchema)(schema)) {
25
- if (queryPath.length === 0) {
26
- const refItem = (0, _refs.getRef)(projectSchema, schema);
27
- return refItem && (0, _refs.refItemToShape)(projectSchema, refItem);
30
+ const ref = (0, _refs.getRef)(projectSchema, schema);
31
+
32
+ if (ref) {
33
+ const shapeSchema = (0, _refs.refItemToShapeSchema)(projectSchema, ref);
34
+
35
+ if (shapeSchema) {
36
+ return findSchemaAtPath(projectSchema, shapeSchema, queryPath);
37
+ }
28
38
  }
29
39
 
30
- return findShapeAtPath(projectSchema, (0, _refs.followRef)(projectSchema, schema), queryPath);
40
+ return undefined;
31
41
  }
32
42
 
33
43
  if ((0, _types.isArraySchema)(schema)) {
34
- return findShapeAtPath(projectSchema, schema.items, queryPath);
44
+ return findSchemaAtPath(projectSchema, schema.items, queryPath);
35
45
  }
36
46
 
37
47
  if ((0, _types.isObjectSchema)(schema)) {
38
48
  const propSchema = schema.properties[prop];
39
49
 
40
50
  if (propSchema) {
41
- return findShapeAtPath(projectSchema, propSchema, rest);
51
+ return findSchemaAtPath(projectSchema, propSchema, rest);
42
52
  }
43
53
  }
44
54
 
45
55
  return undefined;
56
+ }
57
+ /**
58
+ *
59
+ * @param projectSchema
60
+ * @param propSchema
61
+ * @param queryPath
62
+ *
63
+ * @example
64
+ * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds Shopify_Product
65
+ */
66
+
67
+
68
+ function findShapeAtPath(projectSchema, propSchema, queryPath) {
69
+ const result = findSchemaAtPath(projectSchema, propSchema, queryPath);
70
+
71
+ if (result) {
72
+ const refItem = (0, _refs.getRef)(projectSchema, result.items ?? result);
73
+ return refItem && (0, _refs.refItemToShape)(projectSchema, refItem);
74
+ }
46
75
  }
@@ -1,3 +1,3 @@
1
1
  import { ProjectSchema, PropertySchema, Query } from '../project-schema';
2
- export declare function hasArg(projectSchema: ProjectSchema, prop: PropertySchema | Query, argName: string): boolean;
2
+ export declare function hasArg(projectSchema: ProjectSchema, prop: PropertySchema | Query, argPath: string | string[]): boolean;
3
3
  //# sourceMappingURL=has-arg.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"has-arg.d.ts","sourceRoot":"","sources":["../../../src/util/has-arg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAGvE,wBAAgB,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,IAAI,EAAE,cAAc,GAAG,KAAK,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAU3G"}
1
+ {"version":3,"file":"has-arg.d.ts","sourceRoot":"","sources":["../../../src/util/has-arg.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AAGvE,wBAAgB,MAAM,CACpB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,cAAc,GAAG,KAAK,EAC5B,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GACzB,OAAO,CAWT"}
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.hasArg = hasArg;
7
7
 
8
- var _schemaUtil = require("../schema-util");
8
+ var _findShapeAtPath = require("./find-shape-at-path");
9
9
 
10
- function hasArg(projectSchema, prop, argName) {
10
+ function hasArg(projectSchema, prop, argPath) {
11
11
  var _projectSchema$shapes;
12
12
 
13
13
  const args = 'args' in prop ? prop.args : prop['@args'];
@@ -17,6 +17,6 @@ function hasArg(projectSchema, prop, argName) {
17
17
  }
18
18
 
19
19
  const schema = typeof args === 'string' ? (_projectSchema$shapes = projectSchema.shapes[args]) === null || _projectSchema$shapes === void 0 ? void 0 : _projectSchema$shapes.schema : args;
20
- const schemaPropertyAccessor = (0, _schemaUtil.createSchemaPropertyAccessor)(projectSchema, schema);
21
- return Boolean(schemaPropertyAccessor.getValue(argName));
20
+ const pathArray = Array.isArray(argPath) ? argPath : argPath.split('.');
21
+ return Boolean((0, _findShapeAtPath.findSchemaAtPath)(projectSchema, schema, pathArray));
22
22
  }
@@ -1,5 +1,5 @@
1
1
  import { isArraySchema, isObjectSchema, isRefSchema } from '../types';
2
- import { followRef, getRef, refItemToShape } from '../refs';
2
+ import { getRef, refItemToShape, refItemToShapeSchema } from '../refs';
3
3
  /**
4
4
  *
5
5
  * @param projectSchema
@@ -7,32 +7,59 @@ import { followRef, getRef, refItemToShape } from '../refs';
7
7
  * @param queryPath
8
8
  *
9
9
  * @example
10
- * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection, ['edges', 'node']) // finds Shopify_Product
10
+ * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds {'@ref': Shopify_Product}
11
11
  */
12
12
 
13
- export function findShapeAtPath(projectSchema, schema, queryPath) {
13
+ export function findSchemaAtPath(projectSchema, schema, queryPath) {
14
+ if (queryPath.length === 0) {
15
+ return schema;
16
+ }
17
+
14
18
  const [prop, ...rest] = queryPath;
15
19
 
16
20
  if (isRefSchema(schema)) {
17
- if (queryPath.length === 0) {
18
- const refItem = getRef(projectSchema, schema);
19
- return refItem && refItemToShape(projectSchema, refItem);
21
+ const ref = getRef(projectSchema, schema);
22
+
23
+ if (ref) {
24
+ const shapeSchema = refItemToShapeSchema(projectSchema, ref);
25
+
26
+ if (shapeSchema) {
27
+ return findSchemaAtPath(projectSchema, shapeSchema, queryPath);
28
+ }
20
29
  }
21
30
 
22
- return findShapeAtPath(projectSchema, followRef(projectSchema, schema), queryPath);
31
+ return undefined;
23
32
  }
24
33
 
25
34
  if (isArraySchema(schema)) {
26
- return findShapeAtPath(projectSchema, schema.items, queryPath);
35
+ return findSchemaAtPath(projectSchema, schema.items, queryPath);
27
36
  }
28
37
 
29
38
  if (isObjectSchema(schema)) {
30
39
  const propSchema = schema.properties[prop];
31
40
 
32
41
  if (propSchema) {
33
- return findShapeAtPath(projectSchema, propSchema, rest);
42
+ return findSchemaAtPath(projectSchema, propSchema, rest);
34
43
  }
35
44
  }
36
45
 
37
46
  return undefined;
47
+ }
48
+ /**
49
+ *
50
+ * @param projectSchema
51
+ * @param propSchema
52
+ * @param queryPath
53
+ *
54
+ * @example
55
+ * findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection.shape, ['edges', 'node']) // finds Shopify_Product
56
+ */
57
+
58
+ export function findShapeAtPath(projectSchema, propSchema, queryPath) {
59
+ const result = findSchemaAtPath(projectSchema, propSchema, queryPath);
60
+
61
+ if (result) {
62
+ const refItem = getRef(projectSchema, result.items ?? result);
63
+ return refItem && refItemToShape(projectSchema, refItem);
64
+ }
38
65
  }
@@ -1,5 +1,5 @@
1
- import { createSchemaPropertyAccessor } from '../schema-util';
2
- export function hasArg(projectSchema, prop, argName) {
1
+ import { findSchemaAtPath } from './find-shape-at-path';
2
+ export function hasArg(projectSchema, prop, argPath) {
3
3
  var _projectSchema$shapes;
4
4
 
5
5
  const args = 'args' in prop ? prop.args : prop['@args'];
@@ -9,6 +9,6 @@ export function hasArg(projectSchema, prop, argName) {
9
9
  }
10
10
 
11
11
  const schema = typeof args === 'string' ? (_projectSchema$shapes = projectSchema.shapes[args]) === null || _projectSchema$shapes === void 0 ? void 0 : _projectSchema$shapes.schema : args;
12
- const schemaPropertyAccessor = createSchemaPropertyAccessor(projectSchema, schema);
13
- return Boolean(schemaPropertyAccessor.getValue(argName));
12
+ const pathArray = Array.isArray(argPath) ? argPath : argPath.split('.');
13
+ return Boolean(findSchemaAtPath(projectSchema, schema, pathArray));
14
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/schema",
3
- "version": "8.170.0",
3
+ "version": "8.173.1",
4
4
  "description": "TakeShape Schema",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -21,9 +21,9 @@
21
21
  "examples"
22
22
  ],
23
23
  "dependencies": {
24
- "@takeshape/errors": "8.170.0",
25
- "@takeshape/json-schema": "8.170.0",
26
- "@takeshape/util": "8.170.0",
24
+ "@takeshape/errors": "8.173.1",
25
+ "@takeshape/json-schema": "8.173.1",
26
+ "@takeshape/util": "8.173.1",
27
27
  "ajv": "^8.10.0",
28
28
  "ajv-formats": "^2.1.1",
29
29
  "blueimp-md5": "^2.10.0",