@takeshape/schema 8.168.0 → 8.173.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 -2
- package/dist/util/find-shape-at-path.d.ts.map +1 -1
- package/dist/util/find-shape-at-path.js +37 -8
- package/dist/util/form-config.d.ts +4 -0
- package/dist/util/form-config.d.ts.map +1 -1
- package/dist/util/form-config.js +4 -0
- package/dist/util/has-arg.d.ts +1 -1
- package/dist/util/has-arg.d.ts.map +1 -1
- package/dist/util/has-arg.js +4 -4
- package/es/util/find-shape-at-path.js +36 -9
- package/es/util/form-config.js +5 -0
- package/es/util/has-arg.js +4 -4
- package/package.json +4 -4
|
@@ -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
|
|
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,
|
|
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
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
40
|
+
return undefined;
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
if ((0, _types.isArraySchema)(schema)) {
|
|
34
|
-
return
|
|
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
|
|
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,6 +1,10 @@
|
|
|
1
1
|
import type { FormConfig, FormMap } from '../project-schema';
|
|
2
2
|
import { Maybe } from '@takeshape/util';
|
|
3
3
|
import { ProjectSchema } from '../project-schema';
|
|
4
|
+
/**
|
|
5
|
+
* If there any non-normal (nested) forms in the schema, create forms for referenced shapes.
|
|
6
|
+
* The original forms are left intact.
|
|
7
|
+
*/
|
|
4
8
|
export declare function normalizeForms(projectSchema: ProjectSchema): FormMap;
|
|
5
9
|
/**
|
|
6
10
|
* Find the form config for a given shape name and the form key.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-config.d.ts","sourceRoot":"","sources":["../../../src/util/form-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAY,KAAK,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAIhD,wBAAgB,cAAc,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAmDpE;AAID;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,KAAK,CAAC,UAAU,CAAC,CAYnB"}
|
|
1
|
+
{"version":3,"file":"form-config.d.ts","sourceRoot":"","sources":["../../../src/util/form-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAY,KAAK,EAAC,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAIhD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAmDpE;AAID;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,KAAK,CAAC,UAAU,CAAC,CAYnB"}
|
package/dist/util/form-config.js
CHANGED
|
@@ -12,6 +12,10 @@ var _refs = require("../refs");
|
|
|
12
12
|
|
|
13
13
|
var _schemaUtil = require("../schema-util");
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* If there any non-normal (nested) forms in the schema, create forms for referenced shapes.
|
|
17
|
+
* The original forms are left intact.
|
|
18
|
+
*/
|
|
15
19
|
function normalizeForms(projectSchema) {
|
|
16
20
|
const normalizedForms = {};
|
|
17
21
|
const {
|
package/dist/util/has-arg.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ProjectSchema, PropertySchema, Query } from '../project-schema';
|
|
2
|
-
export declare function hasArg(projectSchema: ProjectSchema, prop: PropertySchema | Query,
|
|
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,
|
|
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"}
|
package/dist/util/has-arg.js
CHANGED
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.hasArg = hasArg;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _findShapeAtPath = require("./find-shape-at-path");
|
|
9
9
|
|
|
10
|
-
function hasArg(projectSchema, prop,
|
|
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
|
|
21
|
-
return Boolean(
|
|
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 {
|
|
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
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
31
|
+
return undefined;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
if (isArraySchema(schema)) {
|
|
26
|
-
return
|
|
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
|
|
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
|
}
|
package/es/util/form-config.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { deepClone } from '@takeshape/util';
|
|
2
2
|
import { getRefOrItemsRef, refItemToShapeName } from '../refs';
|
|
3
3
|
import { createSchemaPropertyAccessor } from '../schema-util';
|
|
4
|
+
/**
|
|
5
|
+
* If there any non-normal (nested) forms in the schema, create forms for referenced shapes.
|
|
6
|
+
* The original forms are left intact.
|
|
7
|
+
*/
|
|
8
|
+
|
|
4
9
|
export function normalizeForms(projectSchema) {
|
|
5
10
|
const normalizedForms = {};
|
|
6
11
|
const {
|
package/es/util/has-arg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function hasArg(projectSchema, prop,
|
|
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
|
|
13
|
-
return Boolean(
|
|
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.
|
|
3
|
+
"version": "8.173.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.173.0",
|
|
25
|
+
"@takeshape/json-schema": "8.173.0",
|
|
26
|
+
"@takeshape/util": "8.173.0",
|
|
27
27
|
"ajv": "^8.10.0",
|
|
28
28
|
"ajv-formats": "^2.1.1",
|
|
29
29
|
"blueimp-md5": "^2.10.0",
|