@takeshape/schema 8.159.10 → 8.164.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/dist/util/find-shape-at-path.d.ts +12 -0
- package/dist/util/find-shape-at-path.d.ts.map +1 -0
- package/dist/util/find-shape-at-path.js +46 -0
- package/dist/util/get-conflicting-properties.d.ts +7 -0
- package/dist/util/get-conflicting-properties.d.ts.map +1 -0
- package/dist/util/get-conflicting-properties.js +69 -0
- package/dist/util/get-return-shape.d.ts +3 -0
- package/dist/util/get-return-shape.d.ts.map +1 -0
- package/dist/util/get-return-shape.js +48 -0
- package/dist/util/has-arg.d.ts +3 -0
- package/dist/util/has-arg.d.ts.map +1 -0
- package/dist/util/has-arg.js +22 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +52 -0
- package/es/util/find-shape-at-path.js +38 -0
- package/es/util/get-conflicting-properties.js +60 -0
- package/es/util/get-return-shape.js +40 -0
- package/es/util/has-arg.js +14 -0
- package/es/util/index.js +4 -0
- package/package.json +4 -4
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ProjectSchema, PropertySchema, Shape } from '../project-schema';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param projectSchema
|
|
5
|
+
* @param schema
|
|
6
|
+
* @param queryPath
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection, ['edges', 'node']) // finds Shopify_Product
|
|
10
|
+
*/
|
|
11
|
+
export declare function findShapeAtPath(projectSchema: ProjectSchema, schema: PropertySchema, queryPath: string[]): Shape | undefined;
|
|
12
|
+
//# sourceMappingURL=find-shape-at-path.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.findShapeAtPath = findShapeAtPath;
|
|
7
|
+
|
|
8
|
+
var _types = require("../types");
|
|
9
|
+
|
|
10
|
+
var _refs = require("../refs");
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param projectSchema
|
|
15
|
+
* @param schema
|
|
16
|
+
* @param queryPath
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection, ['edges', 'node']) // finds Shopify_Product
|
|
20
|
+
*/
|
|
21
|
+
function findShapeAtPath(projectSchema, schema, queryPath) {
|
|
22
|
+
const [prop, ...rest] = queryPath;
|
|
23
|
+
|
|
24
|
+
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);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return findShapeAtPath(projectSchema, (0, _refs.followRef)(projectSchema, schema), queryPath);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ((0, _types.isArraySchema)(schema)) {
|
|
34
|
+
return findShapeAtPath(projectSchema, schema.items, queryPath);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ((0, _types.isObjectSchema)(schema)) {
|
|
38
|
+
const propSchema = schema.properties[prop];
|
|
39
|
+
|
|
40
|
+
if (propSchema) {
|
|
41
|
+
return findShapeAtPath(projectSchema, propSchema, rest);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Shape } from '../project-schema';
|
|
2
|
+
import { ServicesShapesContext } from '../refs';
|
|
3
|
+
/**
|
|
4
|
+
* Given a list of shapes find the conflicting props
|
|
5
|
+
*/
|
|
6
|
+
export declare function getConflictingProperties(context: ServicesShapesContext, shapes: Shape[]): Set<string>;
|
|
7
|
+
//# sourceMappingURL=get-conflicting-properties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-conflicting-properties.d.ts","sourceRoot":"","sources":["../../../src/util/get-conflicting-properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,KAAK,EAAC,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAA6D,qBAAqB,EAAC,MAAM,SAAS,CAAC;AAsB1G;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAoCrG"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getConflictingProperties = getConflictingProperties;
|
|
7
|
+
|
|
8
|
+
var _refs = require("../refs");
|
|
9
|
+
|
|
10
|
+
var _util = require("@takeshape/util");
|
|
11
|
+
|
|
12
|
+
var _types = require("../types");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Normalize ref, oneOf and array schemas and get a list of @ref expressions
|
|
16
|
+
*/
|
|
17
|
+
function getRefStrings(context, propertySchema) {
|
|
18
|
+
const schema = propertySchema.items ?? propertySchema;
|
|
19
|
+
const schemas = schema.oneOf ? schema.oneOf : [schema];
|
|
20
|
+
return schemas.map(propertySchema => {
|
|
21
|
+
const ref = (0, _refs.getRef)(context, propertySchema);
|
|
22
|
+
return ref ? (0, _refs.refItemToAtRef)(ref) : undefined;
|
|
23
|
+
}).filter(_util.isDefined);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isRefEqual(context, a, b) {
|
|
27
|
+
return (0, _util.setIsEqual)(getRefStrings(context, a), getRefStrings(context, b));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Given a list of shapes find the conflicting props
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function getConflictingProperties(context, shapes) {
|
|
35
|
+
const conflicts = new Set();
|
|
36
|
+
const allProps = {};
|
|
37
|
+
|
|
38
|
+
for (const shape of Object.values(shapes)) {
|
|
39
|
+
const schema = (0, _refs.dereferenceSchema)(context, shape.schema, ['shapes', shape.name]);
|
|
40
|
+
|
|
41
|
+
if (!(0, _types.isObjectSchema)(schema)) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const required = new Set(schema.required ?? []);
|
|
46
|
+
|
|
47
|
+
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
48
|
+
// skip props that we know already have conflict
|
|
49
|
+
if (conflicts.has(name)) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const isRequired = required.has(name);
|
|
54
|
+
|
|
55
|
+
if (allProps[name]) {
|
|
56
|
+
if ( // same type
|
|
57
|
+
allProps[name][0].type !== prop.type || // same refs
|
|
58
|
+
!isRefEqual(context, allProps[name][0], prop) || // same nullability
|
|
59
|
+
isRequired !== allProps[name][1]) {
|
|
60
|
+
conflicts.add(name);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
allProps[name] = [prop, isRequired];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return conflicts;
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-return-shape.d.ts","sourceRoot":"","sources":["../../../src/util/get-return-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAC,MAAM,mBAAmB,CAAC;AA2B9E,wBAAgB,cAAc,CAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,GAAG,KAAK,GAAG,KAAK,CAQvG"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getReturnShape = getReturnShape;
|
|
7
|
+
|
|
8
|
+
var _refs = require("../refs");
|
|
9
|
+
|
|
10
|
+
function isQuery(propOrQuery) {
|
|
11
|
+
return 'shape' in propOrQuery && 'resolver' in propOrQuery;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getReturnShapeHelper(projectSchema, propOrQuery) {
|
|
15
|
+
let shape;
|
|
16
|
+
|
|
17
|
+
if (isQuery(propOrQuery)) {
|
|
18
|
+
const {
|
|
19
|
+
shapeName
|
|
20
|
+
} = (0, _refs.parseReturnShape)(projectSchema, propOrQuery.shape);
|
|
21
|
+
shape = projectSchema.shapes[shapeName];
|
|
22
|
+
} else {
|
|
23
|
+
const ref = (0, _refs.getRef)(projectSchema, propOrQuery);
|
|
24
|
+
|
|
25
|
+
if (ref) {
|
|
26
|
+
shape = (0, _refs.refItemToShape)(projectSchema, ref);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!shape) {
|
|
31
|
+
throw new Error(`Unable to find return shape for ${JSON.stringify(propOrQuery)}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return shape;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const cache = new WeakMap();
|
|
38
|
+
|
|
39
|
+
function getReturnShape(projectSchema, propOrQuery) {
|
|
40
|
+
let result = cache.get(propOrQuery);
|
|
41
|
+
|
|
42
|
+
if (!result) {
|
|
43
|
+
result = getReturnShapeHelper(projectSchema, propOrQuery);
|
|
44
|
+
cache.set(propOrQuery, result);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasArg = hasArg;
|
|
7
|
+
|
|
8
|
+
var _schemaUtil = require("../schema-util");
|
|
9
|
+
|
|
10
|
+
function hasArg(projectSchema, prop, argName) {
|
|
11
|
+
var _projectSchema$shapes;
|
|
12
|
+
|
|
13
|
+
const args = 'args' in prop ? prop.args : prop['@args'];
|
|
14
|
+
|
|
15
|
+
if (!args) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
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));
|
|
22
|
+
}
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export * from './api-indexing';
|
|
2
2
|
export * from './detect-cycles';
|
|
3
|
+
export * from './find-shape-at-path';
|
|
4
|
+
export * from './get-conflicting-properties';
|
|
5
|
+
export * from './get-return-shape';
|
|
6
|
+
export * from './has-arg';
|
|
3
7
|
export * from './merge';
|
|
4
8
|
export * from './form-config';
|
|
5
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
|
package/dist/util/index.js
CHANGED
|
@@ -30,6 +30,58 @@ Object.keys(_detectCycles).forEach(function (key) {
|
|
|
30
30
|
});
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
var _findShapeAtPath = require("./find-shape-at-path");
|
|
34
|
+
|
|
35
|
+
Object.keys(_findShapeAtPath).forEach(function (key) {
|
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
|
37
|
+
if (key in exports && exports[key] === _findShapeAtPath[key]) return;
|
|
38
|
+
Object.defineProperty(exports, key, {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function () {
|
|
41
|
+
return _findShapeAtPath[key];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
var _getConflictingProperties = require("./get-conflicting-properties");
|
|
47
|
+
|
|
48
|
+
Object.keys(_getConflictingProperties).forEach(function (key) {
|
|
49
|
+
if (key === "default" || key === "__esModule") return;
|
|
50
|
+
if (key in exports && exports[key] === _getConflictingProperties[key]) return;
|
|
51
|
+
Object.defineProperty(exports, key, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () {
|
|
54
|
+
return _getConflictingProperties[key];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
var _getReturnShape = require("./get-return-shape");
|
|
60
|
+
|
|
61
|
+
Object.keys(_getReturnShape).forEach(function (key) {
|
|
62
|
+
if (key === "default" || key === "__esModule") return;
|
|
63
|
+
if (key in exports && exports[key] === _getReturnShape[key]) return;
|
|
64
|
+
Object.defineProperty(exports, key, {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () {
|
|
67
|
+
return _getReturnShape[key];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
var _hasArg = require("./has-arg");
|
|
73
|
+
|
|
74
|
+
Object.keys(_hasArg).forEach(function (key) {
|
|
75
|
+
if (key === "default" || key === "__esModule") return;
|
|
76
|
+
if (key in exports && exports[key] === _hasArg[key]) return;
|
|
77
|
+
Object.defineProperty(exports, key, {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () {
|
|
80
|
+
return _hasArg[key];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
33
85
|
var _merge = require("./merge");
|
|
34
86
|
|
|
35
87
|
Object.keys(_merge).forEach(function (key) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isArraySchema, isObjectSchema, isRefSchema } from '../types';
|
|
2
|
+
import { followRef, getRef, refItemToShape } from '../refs';
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param projectSchema
|
|
6
|
+
* @param schema
|
|
7
|
+
* @param queryPath
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* findShapeAtPath(projectSchema, projectSchema.shapes.Shopify_ProductConnection, ['edges', 'node']) // finds Shopify_Product
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export function findShapeAtPath(projectSchema, schema, queryPath) {
|
|
14
|
+
const [prop, ...rest] = queryPath;
|
|
15
|
+
|
|
16
|
+
if (isRefSchema(schema)) {
|
|
17
|
+
if (queryPath.length === 0) {
|
|
18
|
+
const refItem = getRef(projectSchema, schema);
|
|
19
|
+
return refItem && refItemToShape(projectSchema, refItem);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return findShapeAtPath(projectSchema, followRef(projectSchema, schema), queryPath);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isArraySchema(schema)) {
|
|
26
|
+
return findShapeAtPath(projectSchema, schema.items, queryPath);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (isObjectSchema(schema)) {
|
|
30
|
+
const propSchema = schema.properties[prop];
|
|
31
|
+
|
|
32
|
+
if (propSchema) {
|
|
33
|
+
return findShapeAtPath(projectSchema, propSchema, rest);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { dereferenceSchema, getRef, refItemToAtRef } from '../refs';
|
|
2
|
+
import { isDefined, setIsEqual } from '@takeshape/util';
|
|
3
|
+
import { isObjectSchema } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Normalize ref, oneOf and array schemas and get a list of @ref expressions
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function getRefStrings(context, propertySchema) {
|
|
9
|
+
const schema = propertySchema.items ?? propertySchema;
|
|
10
|
+
const schemas = schema.oneOf ? schema.oneOf : [schema];
|
|
11
|
+
return schemas.map(propertySchema => {
|
|
12
|
+
const ref = getRef(context, propertySchema);
|
|
13
|
+
return ref ? refItemToAtRef(ref) : undefined;
|
|
14
|
+
}).filter(isDefined);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isRefEqual(context, a, b) {
|
|
18
|
+
return setIsEqual(getRefStrings(context, a), getRefStrings(context, b));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Given a list of shapes find the conflicting props
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
export function getConflictingProperties(context, shapes) {
|
|
26
|
+
const conflicts = new Set();
|
|
27
|
+
const allProps = {};
|
|
28
|
+
|
|
29
|
+
for (const shape of Object.values(shapes)) {
|
|
30
|
+
const schema = dereferenceSchema(context, shape.schema, ['shapes', shape.name]);
|
|
31
|
+
|
|
32
|
+
if (!isObjectSchema(schema)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const required = new Set(schema.required ?? []);
|
|
37
|
+
|
|
38
|
+
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
39
|
+
// skip props that we know already have conflict
|
|
40
|
+
if (conflicts.has(name)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const isRequired = required.has(name);
|
|
45
|
+
|
|
46
|
+
if (allProps[name]) {
|
|
47
|
+
if ( // same type
|
|
48
|
+
allProps[name][0].type !== prop.type || // same refs
|
|
49
|
+
!isRefEqual(context, allProps[name][0], prop) || // same nullability
|
|
50
|
+
isRequired !== allProps[name][1]) {
|
|
51
|
+
conflicts.add(name);
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
allProps[name] = [prop, isRequired];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return conflicts;
|
|
60
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getRef, parseReturnShape, refItemToShape } from '../refs';
|
|
2
|
+
|
|
3
|
+
function isQuery(propOrQuery) {
|
|
4
|
+
return 'shape' in propOrQuery && 'resolver' in propOrQuery;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function getReturnShapeHelper(projectSchema, propOrQuery) {
|
|
8
|
+
let shape;
|
|
9
|
+
|
|
10
|
+
if (isQuery(propOrQuery)) {
|
|
11
|
+
const {
|
|
12
|
+
shapeName
|
|
13
|
+
} = parseReturnShape(projectSchema, propOrQuery.shape);
|
|
14
|
+
shape = projectSchema.shapes[shapeName];
|
|
15
|
+
} else {
|
|
16
|
+
const ref = getRef(projectSchema, propOrQuery);
|
|
17
|
+
|
|
18
|
+
if (ref) {
|
|
19
|
+
shape = refItemToShape(projectSchema, ref);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!shape) {
|
|
24
|
+
throw new Error(`Unable to find return shape for ${JSON.stringify(propOrQuery)}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return shape;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const cache = new WeakMap();
|
|
31
|
+
export function getReturnShape(projectSchema, propOrQuery) {
|
|
32
|
+
let result = cache.get(propOrQuery);
|
|
33
|
+
|
|
34
|
+
if (!result) {
|
|
35
|
+
result = getReturnShapeHelper(projectSchema, propOrQuery);
|
|
36
|
+
cache.set(propOrQuery, result);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createSchemaPropertyAccessor } from '../schema-util';
|
|
2
|
+
export function hasArg(projectSchema, prop, argName) {
|
|
3
|
+
var _projectSchema$shapes;
|
|
4
|
+
|
|
5
|
+
const args = 'args' in prop ? prop.args : prop['@args'];
|
|
6
|
+
|
|
7
|
+
if (!args) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
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));
|
|
14
|
+
}
|
package/es/util/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export * from './api-indexing';
|
|
2
2
|
export * from './detect-cycles';
|
|
3
|
+
export * from './find-shape-at-path';
|
|
4
|
+
export * from './get-conflicting-properties';
|
|
5
|
+
export * from './get-return-shape';
|
|
6
|
+
export * from './has-arg';
|
|
3
7
|
export * from './merge';
|
|
4
8
|
export * from './form-config';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/schema",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.164.0",
|
|
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.
|
|
25
|
-
"@takeshape/json-schema": "8.
|
|
26
|
-
"@takeshape/util": "8.
|
|
24
|
+
"@takeshape/errors": "8.164.0",
|
|
25
|
+
"@takeshape/json-schema": "8.164.0",
|
|
26
|
+
"@takeshape/util": "8.164.0",
|
|
27
27
|
"ajv": "^8.10.0",
|
|
28
28
|
"ajv-formats": "^2.1.1",
|
|
29
29
|
"blueimp-md5": "^2.10.0",
|