@takeshape/schema 9.80.4 → 9.81.3
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/api-version.js +0 -9
- package/dist/builtin-schema.js +0 -5
- package/dist/content-schema-transform.js +4 -52
- package/dist/create-input-schema.js +7 -19
- package/dist/enum.js +0 -3
- package/dist/flatten-templates.js +0 -11
- package/dist/get-is-leaf.js +8 -18
- package/dist/index.js +0 -58
- package/dist/interfaces.js +2 -26
- package/dist/layers/layers.js +23 -103
- package/dist/layers/refs.js +26 -69
- package/dist/layers/type-utils.js +11 -43
- package/dist/layers/visitor.js +0 -6
- package/dist/migration/index.js +0 -51
- package/dist/migration/to/v3.0.0.js +31 -45
- package/dist/migration/to/v3.1.0.js +15 -41
- package/dist/migration/to/v3.10.0.js +6 -20
- package/dist/migration/to/v3.11.0.js +8 -20
- package/dist/migration/to/v3.12.0.js +2 -3
- package/dist/migration/to/v3.12.1.js +2 -3
- package/dist/migration/to/v3.12.2.js +2 -3
- package/dist/migration/to/v3.12.3.js +16 -21
- package/dist/migration/to/v3.13.0.js +2 -7
- package/dist/migration/to/v3.14.0.js +2 -3
- package/dist/migration/to/v3.15.0.js +2 -3
- package/dist/migration/to/v3.16.0.js +2 -3
- package/dist/migration/to/v3.17.0.js +4 -9
- package/dist/migration/to/v3.17.1.js +2 -3
- package/dist/migration/to/v3.18.0.js +2 -15
- package/dist/migration/to/v3.18.1.js +2 -7
- package/dist/migration/to/v3.18.2.js +8 -10
- package/dist/migration/to/v3.19.0.js +2 -3
- package/dist/migration/to/v3.2.0.js +2 -3
- package/dist/migration/to/v3.20.0.js +10 -11
- package/dist/migration/to/v3.21.0.js +2 -3
- package/dist/migration/to/v3.22.0.js +4 -9
- package/dist/migration/to/v3.23.0.js +2 -3
- package/dist/migration/to/v3.24.0.js +2 -3
- package/dist/migration/to/v3.25.0.js +2 -3
- package/dist/migration/to/v3.26.0.js +2 -3
- package/dist/migration/to/v3.27.0.js +2 -3
- package/dist/migration/to/v3.28.0.js +2 -3
- package/dist/migration/to/v3.29.0.js +2 -3
- package/dist/migration/to/v3.3.0.js +3 -4
- package/dist/migration/to/v3.30.0.js +2 -3
- package/dist/migration/to/v3.31.0.js +2 -12
- package/dist/migration/to/v3.32.0.js +12 -22
- package/dist/migration/to/v3.33.0.js +2 -3
- package/dist/migration/to/v3.34.0.js +14 -43
- package/dist/migration/to/v3.35.0.js +2 -3
- package/dist/migration/to/v3.36.0.js +6 -10
- package/dist/migration/to/v3.37.0.js +2 -3
- package/dist/migration/to/v3.38.0.js +2 -3
- package/dist/migration/to/v3.39.0.js +6 -13
- package/dist/migration/to/v3.4.0.js +2 -3
- package/dist/migration/to/v3.5.0.js +2 -3
- package/dist/migration/to/v3.5.1.js +2 -3
- package/dist/migration/to/v3.6.0.js +2 -3
- package/dist/migration/to/v3.7.0.js +2 -3
- package/dist/migration/to/v3.8.0.js +2 -3
- package/dist/migration/to/v3.9.0.js +8 -24
- package/dist/migration/utils.js +0 -2
- package/dist/mocks.js +9 -12
- package/dist/models/project-schema.js +0 -34
- package/dist/models/query.js +0 -9
- package/dist/models/service.js +0 -8
- package/dist/models/shape.js +0 -29
- package/dist/project-schema/index.js +1 -105
- package/dist/project-schema/migrate.js +1 -54
- package/dist/refs.js +39 -159
- package/dist/relationships.js +13 -57
- package/dist/scalars.js +0 -1
- package/dist/schema-transform.js +0 -11
- package/dist/schema-util.js +75 -271
- package/dist/schemas/index.js +0 -64
- package/dist/services.js +24 -44
- package/dist/taxonomies.js +0 -13
- package/dist/template-shapes/index.js +1 -8
- package/dist/template-shapes/templates.js +9 -40
- package/dist/template-shapes/types.js +4 -5
- package/dist/template-shapes/where.js +14 -110
- package/dist/types/index.js +0 -4
- package/dist/types/types.js +41 -13
- package/dist/types/utils.js +15 -89
- package/dist/unions.js +8 -38
- package/dist/util/api-indexing.js +2 -19
- package/dist/util/detect-cycles.js +2 -16
- package/dist/util/find-shape-at-path.js +1 -15
- package/dist/util/form-config.js +6 -23
- package/dist/util/get-conflicting-properties.js +7 -17
- package/dist/util/get-return-shape.js +0 -11
- package/dist/util/has-arg.js +0 -6
- package/dist/util/index.js +0 -18
- package/dist/util/merge.js +28 -74
- package/dist/util/patch-schema.js +5 -13
- package/dist/validate.js +15 -234
- package/dist/versions.js +0 -2
- package/dist/workflows.js +0 -15
- package/es/api-version.js +0 -4
- package/es/content-schema-transform.js +4 -38
- package/es/create-input-schema.js +7 -14
- package/es/enum.js +0 -2
- package/es/flatten-templates.js +0 -4
- package/es/get-is-leaf.js +8 -13
- package/es/index.js +1 -0
- package/es/interfaces.js +2 -14
- package/es/layers/layers.js +23 -90
- package/es/layers/refs.js +22 -45
- package/es/layers/type-utils.js +11 -16
- package/es/layers/visitor.js +0 -3
- package/es/migration/to/v3.0.0.js +31 -38
- package/es/migration/to/v3.1.0.js +16 -34
- package/es/migration/to/v3.10.0.js +6 -17
- package/es/migration/to/v3.11.0.js +8 -18
- package/es/migration/to/v3.12.0.js +2 -2
- package/es/migration/to/v3.12.1.js +2 -2
- package/es/migration/to/v3.12.2.js +2 -2
- package/es/migration/to/v3.12.3.js +16 -19
- package/es/migration/to/v3.13.0.js +2 -4
- package/es/migration/to/v3.14.0.js +2 -2
- package/es/migration/to/v3.15.0.js +2 -2
- package/es/migration/to/v3.16.0.js +2 -2
- package/es/migration/to/v3.17.0.js +4 -4
- package/es/migration/to/v3.17.1.js +2 -2
- package/es/migration/to/v3.18.0.js +2 -10
- package/es/migration/to/v3.18.1.js +2 -3
- package/es/migration/to/v3.18.2.js +8 -8
- package/es/migration/to/v3.19.0.js +2 -2
- package/es/migration/to/v3.2.0.js +2 -2
- package/es/migration/to/v3.20.0.js +10 -9
- package/es/migration/to/v3.21.0.js +2 -2
- package/es/migration/to/v3.22.0.js +4 -6
- package/es/migration/to/v3.23.0.js +2 -2
- package/es/migration/to/v3.24.0.js +2 -2
- package/es/migration/to/v3.25.0.js +2 -2
- package/es/migration/to/v3.26.0.js +2 -2
- package/es/migration/to/v3.27.0.js +2 -2
- package/es/migration/to/v3.28.0.js +2 -2
- package/es/migration/to/v3.29.0.js +2 -2
- package/es/migration/to/v3.3.0.js +3 -3
- package/es/migration/to/v3.30.0.js +2 -2
- package/es/migration/to/v3.31.0.js +2 -5
- package/es/migration/to/v3.32.0.js +12 -21
- package/es/migration/to/v3.33.0.js +2 -2
- package/es/migration/to/v3.34.0.js +16 -32
- package/es/migration/to/v3.35.0.js +2 -2
- package/es/migration/to/v3.36.0.js +6 -8
- package/es/migration/to/v3.37.0.js +2 -2
- package/es/migration/to/v3.38.0.js +2 -2
- package/es/migration/to/v3.39.0.js +6 -12
- package/es/migration/to/v3.4.0.js +2 -2
- package/es/migration/to/v3.5.0.js +2 -2
- package/es/migration/to/v3.5.1.js +2 -2
- package/es/migration/to/v3.6.0.js +2 -2
- package/es/migration/to/v3.7.0.js +2 -2
- package/es/migration/to/v3.8.0.js +2 -2
- package/es/migration/to/v3.9.0.js +8 -20
- package/es/mocks.js +10 -6
- package/es/models/project-schema.js +0 -26
- package/es/models/query.js +0 -7
- package/es/models/service.js +0 -6
- package/es/models/shape.js +1 -25
- package/es/project-schema/index.js +0 -5
- package/es/project-schema/migrate.js +3 -51
- package/es/refs.js +40 -96
- package/es/relationships.js +14 -42
- package/es/schema-transform.js +0 -7
- package/es/schema-util.js +75 -180
- package/es/services.js +18 -27
- package/es/taxonomies.js +0 -9
- package/es/template-shapes/index.js +1 -4
- package/es/template-shapes/templates.js +9 -18
- package/es/template-shapes/types.js +3 -4
- package/es/template-shapes/where.js +14 -94
- package/es/types/types.js +43 -10
- package/es/types/utils.js +16 -24
- package/es/unions.js +8 -22
- package/es/util/api-indexing.js +2 -12
- package/es/util/detect-cycles.js +2 -14
- package/es/util/find-shape-at-path.js +2 -12
- package/es/util/form-config.js +7 -19
- package/es/util/get-conflicting-properties.js +8 -14
- package/es/util/get-return-shape.js +0 -8
- package/es/util/has-arg.js +0 -3
- package/es/util/merge.js +28 -55
- package/es/util/patch-schema.js +5 -7
- package/es/validate.js +15 -194
- package/es/workflows.js +0 -6
- package/package.json +5 -5
package/es/layers/type-utils.js
CHANGED
|
@@ -3,9 +3,7 @@ import isPlainObject from 'lodash/isPlainObject';
|
|
|
3
3
|
import isString from 'lodash/isString';
|
|
4
4
|
import isArray from 'lodash/isArray';
|
|
5
5
|
import { latestSchemaJson } from '../schemas';
|
|
6
|
-
|
|
7
6
|
/** Resolver Type Utils **/
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* Only tests that the shape is right, not that the name is correct. That's a job for the validator.
|
|
11
9
|
*/
|
|
@@ -39,90 +37,87 @@ export function isAwsLambdaResolver(resolver) {
|
|
|
39
37
|
export function isUtilResolver(resolver) {
|
|
40
38
|
return utilResolver.properties.name.enum.includes(resolver.name);
|
|
41
39
|
}
|
|
40
|
+
|
|
42
41
|
/** Directive Mapping Utils **/
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* Determine whether the ambiguous Directive structure is a DirectiveMappingMap
|
|
46
45
|
*/
|
|
47
|
-
|
|
48
46
|
export function isDirectiveMappingMap(maybeMap) {
|
|
49
47
|
return isPlainObject(maybeMap) && Object.keys(maybeMap).length > 0;
|
|
50
48
|
}
|
|
49
|
+
|
|
51
50
|
/**
|
|
52
51
|
* Determine whether the ambiguous Directive structure is a DirectiveMappingArray
|
|
53
52
|
*/
|
|
54
|
-
|
|
55
53
|
export function isDirectiveMappingArray(maybeArray) {
|
|
56
54
|
return isArray(maybeArray) && isArray(maybeArray[0]) && isString(maybeArray[0][0]) && isArray(maybeArray[0][1]);
|
|
57
55
|
}
|
|
56
|
+
|
|
58
57
|
/**
|
|
59
58
|
* Determine whether the ambiguous Directive structure is a DirectiveConfig array
|
|
60
59
|
*/
|
|
61
|
-
|
|
62
60
|
export function isDirectiveConfig(maybeConfig) {
|
|
63
61
|
return isArray(maybeConfig) && isArray(maybeConfig[0]) && isString(maybeConfig[0][0]) && isRecord(maybeConfig[0][1]);
|
|
64
62
|
}
|
|
63
|
+
|
|
65
64
|
/**
|
|
66
65
|
* Determine whether a ParameterSerializeOption is a content type serializer
|
|
67
66
|
*/
|
|
68
|
-
|
|
69
67
|
export function isParameterSerializeContentOptions(maybeContent) {
|
|
70
68
|
return Boolean('contentType' in maybeContent && maybeContent.contentType);
|
|
71
69
|
}
|
|
70
|
+
|
|
72
71
|
/**
|
|
73
72
|
* Determine whether an unknown variable is a `ParameterOp`
|
|
74
73
|
*/
|
|
75
|
-
|
|
76
74
|
export function isParameterOp(maybeOp) {
|
|
77
75
|
const op = maybeOp;
|
|
78
|
-
|
|
79
76
|
if (!op.path) {
|
|
80
77
|
return false;
|
|
81
78
|
}
|
|
82
|
-
|
|
83
79
|
return isParameterOpNested(op) || isParameterOpMapping(op) || isParameterOpValue(op) || isParameterOpOp(op);
|
|
84
80
|
}
|
|
81
|
+
|
|
85
82
|
/**
|
|
86
83
|
* Determine whether a `ParameterOp` is a `ParameterOpNested`
|
|
87
84
|
*/
|
|
88
|
-
|
|
89
85
|
export function isParameterOpNested(maybeOp) {
|
|
90
86
|
return Boolean('ops' in maybeOp && maybeOp.ops);
|
|
91
87
|
}
|
|
88
|
+
|
|
92
89
|
/**
|
|
93
90
|
* Determine whether a `ParameterOp` is a `ParameterOpMapping`
|
|
94
91
|
*/
|
|
95
|
-
|
|
96
92
|
export function isParameterOpMapping(maybeOp) {
|
|
97
93
|
return Boolean('mapping' in maybeOp && maybeOp.mapping);
|
|
98
94
|
}
|
|
95
|
+
|
|
99
96
|
/**
|
|
100
97
|
* Determine whether a `ParameterOp` is a `ParameterOpMapping`
|
|
101
98
|
*/
|
|
102
|
-
|
|
103
99
|
export function isParameterOpValue(maybeOp) {
|
|
104
100
|
return Boolean('value' in maybeOp && maybeOp.value);
|
|
105
101
|
}
|
|
102
|
+
|
|
106
103
|
/**
|
|
107
104
|
* Determine whether a `ParameterOp` is a `ParameterOpOp`
|
|
108
105
|
*/
|
|
109
|
-
|
|
110
106
|
export function isParameterOpOp(maybeOp) {
|
|
111
107
|
const op = maybeOp;
|
|
112
|
-
|
|
113
108
|
if (!op.op) {
|
|
114
109
|
return false;
|
|
115
110
|
}
|
|
116
|
-
|
|
117
111
|
return !(isParameterOpNested(op) || isParameterOpMapping(op) || isParameterOpValue(op));
|
|
118
112
|
}
|
|
113
|
+
|
|
119
114
|
/**
|
|
120
115
|
* Determine whether a ParameterSerializeOption is a style serializer
|
|
121
116
|
*/
|
|
122
|
-
|
|
123
117
|
export function isParameterSerializeStyleOptions(maybeStyle) {
|
|
124
118
|
return Boolean('style' in maybeStyle && maybeStyle.style);
|
|
125
119
|
}
|
|
120
|
+
|
|
126
121
|
/** Typeguards for different types of shape schemas **/
|
|
127
122
|
|
|
128
123
|
export function isRefSchema(maybeRefSchema) {
|
package/es/layers/visitor.js
CHANGED
|
@@ -4,7 +4,6 @@ export function visitSchemaProperties(schema, path, callback) {
|
|
|
4
4
|
for (const [name, propSchema] of Object.entries(schema.properties)) {
|
|
5
5
|
const newPath = [...path, 'properties', name];
|
|
6
6
|
callback(propSchema, newPath);
|
|
7
|
-
|
|
8
7
|
if (isObjectSchema(propSchema) || isAllOfSchema(propSchema) || isOneOfSchema(propSchema)) {
|
|
9
8
|
visitSchemaProperties(propSchema, newPath, callback);
|
|
10
9
|
}
|
|
@@ -13,7 +12,6 @@ export function visitSchemaProperties(schema, path, callback) {
|
|
|
13
12
|
for (const [index, propSchema] of Object.entries(schema.allOf)) {
|
|
14
13
|
const newPath = [...path, 'allOf', index];
|
|
15
14
|
callback(propSchema, newPath);
|
|
16
|
-
|
|
17
15
|
if (isObjectSchema(propSchema) || isAllOfSchema(propSchema) || isOneOfSchema(propSchema)) {
|
|
18
16
|
visitSchemaProperties(propSchema, newPath, callback);
|
|
19
17
|
}
|
|
@@ -22,7 +20,6 @@ export function visitSchemaProperties(schema, path, callback) {
|
|
|
22
20
|
for (const [index, propSchema] of Object.entries(schema.oneOf)) {
|
|
23
21
|
const newPath = [...path, 'oneOf', index];
|
|
24
22
|
callback(propSchema, newPath);
|
|
25
|
-
|
|
26
23
|
if (isObjectSchema(propSchema) || isAllOfSchema(propSchema) || isOneOfSchema(propSchema)) {
|
|
27
24
|
visitSchemaProperties(propSchema, newPath, callback);
|
|
28
25
|
}
|
|
@@ -8,7 +8,6 @@ const annotationMap = {
|
|
|
8
8
|
sensitive: '@sensitive',
|
|
9
9
|
syncLocaleStructure: '@syncLocaleStructure'
|
|
10
10
|
};
|
|
11
|
-
|
|
12
11
|
function isColor(schema) {
|
|
13
12
|
const {
|
|
14
13
|
type,
|
|
@@ -16,24 +15,19 @@ function isColor(schema) {
|
|
|
16
15
|
} = schema;
|
|
17
16
|
return Boolean(type === 'object' && properties && properties.hsl && properties.hsv && properties.rgb && properties.hex);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
function getModelType(contentType) {
|
|
21
19
|
if (contentType.single) {
|
|
22
20
|
return 'single';
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
if (contentType.taxonomy) {
|
|
26
23
|
return 'taxonomy';
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
return 'multiple';
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
function getRelationshipSchema(relationship) {
|
|
33
28
|
const itemSchema = {
|
|
34
29
|
$ref: '#/shapes/TSRelationship/schema'
|
|
35
30
|
};
|
|
36
|
-
|
|
37
31
|
if (relationship.type === 'multiple') {
|
|
38
32
|
return {
|
|
39
33
|
type: 'array',
|
|
@@ -41,13 +35,13 @@ function getRelationshipSchema(relationship) {
|
|
|
41
35
|
'@relationship': relationship
|
|
42
36
|
};
|
|
43
37
|
}
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
return {
|
|
39
|
+
...itemSchema,
|
|
46
40
|
'@relationship': relationship
|
|
47
41
|
};
|
|
48
|
-
}
|
|
49
|
-
|
|
42
|
+
}
|
|
50
43
|
|
|
44
|
+
// eslint-disable-next-line complexity
|
|
51
45
|
function migrateToContentSchemaV3(params) {
|
|
52
46
|
const {
|
|
53
47
|
schema,
|
|
@@ -64,24 +58,22 @@ function migrateToContentSchemaV3(params) {
|
|
|
64
58
|
forEach(schema, (value, key) => {
|
|
65
59
|
if (annotationMap[key]) {
|
|
66
60
|
const newAnnotation = annotationMap[key];
|
|
67
|
-
schema[newAnnotation] = value;
|
|
68
|
-
|
|
61
|
+
schema[newAnnotation] = value;
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
69
63
|
delete schema[key];
|
|
70
64
|
}
|
|
71
65
|
});
|
|
72
|
-
|
|
73
66
|
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'integer') {
|
|
74
67
|
return {
|
|
75
|
-
schema: {
|
|
68
|
+
schema: {
|
|
69
|
+
...pick(schema, scalarSchemaKeys),
|
|
76
70
|
'@mapping': mapping
|
|
77
71
|
}
|
|
78
72
|
};
|
|
79
73
|
}
|
|
80
|
-
|
|
81
74
|
const {
|
|
82
75
|
relationship
|
|
83
76
|
} = schema;
|
|
84
|
-
|
|
85
77
|
if (relationship) {
|
|
86
78
|
const {
|
|
87
79
|
contentTypeIds,
|
|
@@ -89,7 +81,8 @@ function migrateToContentSchemaV3(params) {
|
|
|
89
81
|
relatedName
|
|
90
82
|
} = relationship;
|
|
91
83
|
return {
|
|
92
|
-
schema: {
|
|
84
|
+
schema: {
|
|
85
|
+
...pick(schema, relationshipType === 'multiple' ? multipleRelationshipSchemaKeys : schemaMetadataKeys),
|
|
93
86
|
'@mapping': mapping,
|
|
94
87
|
...getRelationshipSchema({
|
|
95
88
|
shapeIds: contentTypeIds,
|
|
@@ -100,25 +93,24 @@ function migrateToContentSchemaV3(params) {
|
|
|
100
93
|
}
|
|
101
94
|
};
|
|
102
95
|
}
|
|
103
|
-
|
|
104
96
|
if (type === 'object' && schema.draftjs) {
|
|
105
97
|
return {
|
|
106
|
-
schema: {
|
|
98
|
+
schema: {
|
|
99
|
+
...pick(schema, scalarSchemaKeys),
|
|
107
100
|
'@mapping': mapping,
|
|
108
101
|
'@tag': 'draftjs'
|
|
109
102
|
}
|
|
110
103
|
};
|
|
111
104
|
}
|
|
112
|
-
|
|
113
105
|
if (isColor(schema)) {
|
|
114
106
|
return {
|
|
115
|
-
schema: {
|
|
107
|
+
schema: {
|
|
108
|
+
...pick(schema, scalarSchemaKeys),
|
|
116
109
|
$ref: '#/shapes/TSColor/schema',
|
|
117
110
|
'@mapping': mapping
|
|
118
111
|
}
|
|
119
112
|
};
|
|
120
113
|
}
|
|
121
|
-
|
|
122
114
|
if (type === 'object' && schema.properties) {
|
|
123
115
|
const properties = {};
|
|
124
116
|
const shapes = {};
|
|
@@ -129,7 +121,8 @@ function migrateToContentSchemaV3(params) {
|
|
|
129
121
|
const {
|
|
130
122
|
schema: migratedPropSchema,
|
|
131
123
|
hoistedShapes
|
|
132
|
-
} = migrateToContentSchemaV3({
|
|
124
|
+
} = migrateToContentSchemaV3({
|
|
125
|
+
...params,
|
|
133
126
|
shapeName,
|
|
134
127
|
shapeTitle,
|
|
135
128
|
depth: params.depth + 1,
|
|
@@ -143,7 +136,6 @@ function migrateToContentSchemaV3(params) {
|
|
|
143
136
|
properties[name] = migratedPropSchema;
|
|
144
137
|
Object.assign(shapes, hoistedShapes);
|
|
145
138
|
});
|
|
146
|
-
|
|
147
139
|
if (params.depth > 0) {
|
|
148
140
|
const {
|
|
149
141
|
title,
|
|
@@ -157,12 +149,14 @@ function migrateToContentSchemaV3(params) {
|
|
|
157
149
|
'@mapping': mapping,
|
|
158
150
|
$ref: `#/shapes/${shapeName}/schema`
|
|
159
151
|
},
|
|
160
|
-
hoistedShapes: {
|
|
152
|
+
hoistedShapes: {
|
|
153
|
+
...shapes,
|
|
161
154
|
[shapeName]: {
|
|
162
155
|
id: name === key ? shapeName : key,
|
|
163
156
|
name: shapeName,
|
|
164
157
|
title: shapeTitle,
|
|
165
|
-
schema: {
|
|
158
|
+
schema: {
|
|
159
|
+
...pick(rest, objectSchemaKeys),
|
|
166
160
|
type: 'object',
|
|
167
161
|
properties
|
|
168
162
|
}
|
|
@@ -170,38 +164,37 @@ function migrateToContentSchemaV3(params) {
|
|
|
170
164
|
}
|
|
171
165
|
};
|
|
172
166
|
}
|
|
173
|
-
|
|
174
167
|
return {
|
|
175
|
-
schema: {
|
|
168
|
+
schema: {
|
|
169
|
+
...pick(schema, objectSchemaKeys),
|
|
176
170
|
properties,
|
|
177
171
|
'@mapping': mapping
|
|
178
172
|
},
|
|
179
173
|
hoistedShapes: shapes
|
|
180
174
|
};
|
|
181
175
|
}
|
|
182
|
-
|
|
183
176
|
if (schema.type === 'array' && schema.items) {
|
|
184
177
|
const {
|
|
185
178
|
schema: itemSchema,
|
|
186
179
|
hoistedShapes
|
|
187
|
-
} = migrateToContentSchemaV3({
|
|
180
|
+
} = migrateToContentSchemaV3({
|
|
181
|
+
...params,
|
|
188
182
|
schema: schema.items,
|
|
189
183
|
parentSchema: schema,
|
|
190
184
|
service: 'parent',
|
|
191
185
|
setSource: false
|
|
192
186
|
});
|
|
193
187
|
return {
|
|
194
|
-
schema: {
|
|
188
|
+
schema: {
|
|
189
|
+
...pick(schema, arraySchemaKeys),
|
|
195
190
|
items: itemSchema,
|
|
196
191
|
'@mapping': mapping
|
|
197
192
|
},
|
|
198
193
|
hoistedShapes
|
|
199
194
|
};
|
|
200
195
|
}
|
|
201
|
-
|
|
202
196
|
throw new Error(`Unknown schema type "${type}"`);
|
|
203
197
|
}
|
|
204
|
-
|
|
205
198
|
function contentTypeToShape(contentType, contentTypeId) {
|
|
206
199
|
const title = contentType.title ?? contentType.name;
|
|
207
200
|
const name = pascalCase(contentType.name);
|
|
@@ -232,7 +225,6 @@ function contentTypeToShape(contentType, contentTypeId) {
|
|
|
232
225
|
...hoistedShapes
|
|
233
226
|
};
|
|
234
227
|
}
|
|
235
|
-
|
|
236
228
|
const migrate = async (_, projectSchema) => {
|
|
237
229
|
const {
|
|
238
230
|
contentTypes,
|
|
@@ -246,11 +238,13 @@ const migrate = async (_, projectSchema) => {
|
|
|
246
238
|
const contentType = contentTypes[contentTypeId];
|
|
247
239
|
Object.assign(shapes, contentTypeToShape(contentType, contentTypeId));
|
|
248
240
|
forms[pascalCase(contentType.name)] = contentType.forms;
|
|
249
|
-
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// Use deepClone to drop undefined values, this improves compatibility with validation and testing
|
|
250
244
|
// Schemas are typically saved in Dynamo or JSON files which also remove undefined values
|
|
251
245
|
// Dropping them here is done for consistency's sake
|
|
252
|
-
|
|
253
|
-
|
|
246
|
+
return deepClone({
|
|
247
|
+
...rest,
|
|
254
248
|
...getShapeQueriesAndMutations(Object.values(shapes)),
|
|
255
249
|
schemaVersion: '3',
|
|
256
250
|
created: formatDate(created),
|
|
@@ -259,5 +253,4 @@ const migrate = async (_, projectSchema) => {
|
|
|
259
253
|
forms
|
|
260
254
|
});
|
|
261
255
|
};
|
|
262
|
-
|
|
263
256
|
export default migrate;
|
|
@@ -4,10 +4,10 @@ import isString from 'lodash/isString';
|
|
|
4
4
|
import isUndefined from 'lodash/isUndefined';
|
|
5
5
|
import { deepClone, pascalCase } from '@takeshape/util';
|
|
6
6
|
import { isAnyServiceConfig } from '../../types/utils';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* `graphql:my-key` `my-key`
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
function parseV3ServiceStr(service) {
|
|
12
12
|
const parts = service.split(':');
|
|
13
13
|
return {
|
|
@@ -15,22 +15,19 @@ function parseV3ServiceStr(service) {
|
|
|
15
15
|
id: parts.length > 1 ? parts[1] : parts[0]
|
|
16
16
|
};
|
|
17
17
|
}
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* Ensures a consistent service config, inluding updating the service
|
|
20
21
|
* authentication object.
|
|
21
22
|
*/
|
|
22
23
|
// eslint-disable-next-line complexity
|
|
23
|
-
|
|
24
|
-
|
|
25
24
|
function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
|
|
26
25
|
if (isAnyServiceConfig(serviceConfig)) {
|
|
27
26
|
if (isString(serviceConfig.authentication) || isUndefined(serviceConfig.authentication)) {
|
|
28
27
|
return serviceConfig;
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
return serviceConfig;
|
|
32
30
|
}
|
|
33
|
-
|
|
34
31
|
const {
|
|
35
32
|
auth
|
|
36
33
|
} = serviceConfig;
|
|
@@ -41,25 +38,22 @@ function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
|
|
|
41
38
|
} = parseV3ServiceStr(serviceKey);
|
|
42
39
|
const authType = serviceParams.authType || undefined;
|
|
43
40
|
const title = serviceParams.name || serviceKeyId;
|
|
44
|
-
|
|
45
41
|
if (serviceKeyId === 'vercel') {
|
|
46
42
|
serviceKeyProvider = 'vercel';
|
|
47
43
|
} else if (serviceKeyId === 'netlify') {
|
|
48
44
|
serviceKeyProvider = 'netlify';
|
|
49
|
-
}
|
|
50
|
-
|
|
45
|
+
}
|
|
51
46
|
|
|
47
|
+
// Example schemas had this in params, which are untyped, so adding here just in case
|
|
52
48
|
if (serviceParams.type === 'rest') {
|
|
53
49
|
serviceKeyProvider = 'rest';
|
|
54
50
|
} else if (serviceParams.type === 'graphql' && serviceKeyProvider !== 'shopify') {
|
|
55
51
|
serviceKeyProvider = 'graphql';
|
|
56
52
|
}
|
|
57
|
-
|
|
58
53
|
let provider;
|
|
59
54
|
let authenticationType;
|
|
60
55
|
let serviceType;
|
|
61
56
|
let namespace;
|
|
62
|
-
|
|
63
57
|
if (serviceKeyProvider === 'shopify') {
|
|
64
58
|
provider = 'shopify';
|
|
65
59
|
authenticationType = 'oauth2Bearer';
|
|
@@ -99,7 +93,6 @@ function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
|
|
|
99
93
|
serviceType = 'unknown';
|
|
100
94
|
namespace = serviceParams.namespace ?? pascalCase(title);
|
|
101
95
|
}
|
|
102
|
-
|
|
103
96
|
const updatedServiceConfig = {
|
|
104
97
|
title,
|
|
105
98
|
id: serviceKey,
|
|
@@ -107,24 +100,23 @@ function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
|
|
|
107
100
|
namespace,
|
|
108
101
|
serviceType,
|
|
109
102
|
authenticationType,
|
|
110
|
-
options: {
|
|
103
|
+
options: {
|
|
104
|
+
...serviceParams
|
|
111
105
|
}
|
|
112
106
|
};
|
|
113
|
-
|
|
114
107
|
if (serviceConfig.auth && isObject(serviceConfig.auth)) {
|
|
115
108
|
const authentication = updateServiceAuthentication(updatedServiceConfig.authenticationType, serviceConfig.auth, serviceParams);
|
|
116
|
-
return {
|
|
109
|
+
return {
|
|
110
|
+
...updatedServiceConfig,
|
|
117
111
|
authentication
|
|
118
112
|
};
|
|
119
113
|
}
|
|
120
|
-
|
|
121
114
|
return updatedServiceConfig;
|
|
122
115
|
}
|
|
116
|
+
|
|
123
117
|
/**
|
|
124
118
|
* V1/V3 unencrypted `auth` -> V3.1 `authentication
|
|
125
119
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
120
|
function updateServiceAuthentication(authenticationType, legacyAuth, legacyParams) {
|
|
129
121
|
if (authenticationType === 'oauth2Bearer') {
|
|
130
122
|
return {
|
|
@@ -133,14 +125,12 @@ function updateServiceAuthentication(authenticationType, legacyAuth, legacyParam
|
|
|
133
125
|
header: legacyParams.authHeader
|
|
134
126
|
};
|
|
135
127
|
}
|
|
136
|
-
|
|
137
128
|
if (authenticationType === 'searchParams' && legacyParams.authProp) {
|
|
138
129
|
return [{
|
|
139
130
|
name: legacyParams.authProp,
|
|
140
131
|
value: legacyAuth.accessToken
|
|
141
132
|
}];
|
|
142
133
|
}
|
|
143
|
-
|
|
144
134
|
if (authenticationType === 'basic') {
|
|
145
135
|
const [username, password] = Buffer.from(legacyAuth.accessToken, 'base64').toString('utf-8').split(':');
|
|
146
136
|
return {
|
|
@@ -148,7 +138,6 @@ function updateServiceAuthentication(authenticationType, legacyAuth, legacyParam
|
|
|
148
138
|
password
|
|
149
139
|
};
|
|
150
140
|
}
|
|
151
|
-
|
|
152
141
|
if (authenticationType === 'bearer') {
|
|
153
142
|
return {
|
|
154
143
|
token: legacyAuth.accessToken,
|
|
@@ -156,63 +145,56 @@ function updateServiceAuthentication(authenticationType, legacyAuth, legacyParam
|
|
|
156
145
|
};
|
|
157
146
|
}
|
|
158
147
|
}
|
|
159
|
-
|
|
160
148
|
function mapAuthType(authType, auth) {
|
|
161
149
|
if (authType === 'none') {
|
|
162
150
|
return 'none';
|
|
163
151
|
}
|
|
164
|
-
|
|
165
152
|
if (authType === 'searchParams') {
|
|
166
153
|
return 'searchParams';
|
|
167
154
|
}
|
|
168
|
-
|
|
169
155
|
if (authType === 'bearer') {
|
|
170
156
|
return 'bearer';
|
|
171
157
|
}
|
|
172
|
-
|
|
173
158
|
if (authType === 'bearer') {
|
|
174
159
|
return 'basic';
|
|
175
160
|
}
|
|
176
|
-
|
|
177
161
|
if (!auth) {
|
|
178
162
|
return 'none';
|
|
179
163
|
}
|
|
180
|
-
|
|
181
164
|
if (auth) {
|
|
182
165
|
return 'bearer';
|
|
183
166
|
}
|
|
184
|
-
|
|
185
167
|
return 'unknown';
|
|
186
168
|
}
|
|
187
|
-
|
|
188
169
|
const migrate = async (context, projectSchema) => {
|
|
189
170
|
const {
|
|
190
171
|
encryptFn,
|
|
191
172
|
decryptFn
|
|
192
173
|
} = context;
|
|
193
174
|
let services;
|
|
175
|
+
|
|
194
176
|
/**
|
|
195
177
|
* Services can only be migrated if a dataKey is present, otherwise they will need to be discarded.
|
|
196
178
|
*/
|
|
197
|
-
|
|
198
179
|
if (projectSchema.services) {
|
|
199
180
|
services = await pReduce(Object.entries(projectSchema.services), async (serviceMap, [serviceKey, serviceConfig]) => {
|
|
200
181
|
const auth = serviceConfig.auth && decryptFn(serviceConfig.auth);
|
|
201
|
-
const updatedServiceConfig = updateServiceConfigV3ToV3_1({
|
|
182
|
+
const updatedServiceConfig = updateServiceConfigV3ToV3_1({
|
|
183
|
+
...serviceConfig,
|
|
202
184
|
auth
|
|
203
185
|
}, serviceKey);
|
|
204
186
|
const authentication = updatedServiceConfig === null || updatedServiceConfig === void 0 ? void 0 : updatedServiceConfig.authentication;
|
|
205
|
-
serviceMap[serviceKey] = {
|
|
187
|
+
serviceMap[serviceKey] = {
|
|
188
|
+
...updatedServiceConfig,
|
|
206
189
|
authentication: authentication && isObject(authentication) ? encryptFn(authentication) : authentication
|
|
207
190
|
};
|
|
208
191
|
return serviceMap;
|
|
209
192
|
}, {});
|
|
210
193
|
}
|
|
211
|
-
|
|
212
|
-
|
|
194
|
+
return deepClone({
|
|
195
|
+
...projectSchema,
|
|
213
196
|
services,
|
|
214
197
|
schemaVersion: '3.1.0'
|
|
215
198
|
});
|
|
216
199
|
};
|
|
217
|
-
|
|
218
200
|
export default migrate;
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import mapValues from 'lodash/mapValues';
|
|
2
2
|
import set from 'lodash/fp/set';
|
|
3
|
-
|
|
4
3
|
function $refToPath(ref) {
|
|
5
4
|
return ref.substr(2).split('/');
|
|
6
5
|
}
|
|
7
|
-
|
|
8
6
|
function $refToShapeName(ref) {
|
|
9
7
|
return $refToPath(ref)[1];
|
|
10
8
|
}
|
|
11
|
-
|
|
12
9
|
function findServiceIdForNamespace(projectSchema, namespace) {
|
|
13
10
|
if (projectSchema.services) {
|
|
14
11
|
for (const [serviceId, service] of Object.entries(projectSchema.services)) {
|
|
@@ -17,64 +14,56 @@ function findServiceIdForNamespace(projectSchema, namespace) {
|
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
return 'local';
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
function updateRefSyntax(projectSchema, $ref) {
|
|
25
20
|
const shapeName = $refToShapeName($ref);
|
|
26
21
|
const parts = shapeName.split('_');
|
|
27
22
|
const serviceId = parts.length === 1 ? 'local' : findServiceIdForNamespace(projectSchema, parts[0]);
|
|
28
23
|
return `${serviceId}:${parts[parts.length - 1]}`;
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
function migrateQueryToV3_10(projectSchema) {
|
|
32
26
|
return (query, queryName) => {
|
|
33
27
|
const {
|
|
34
28
|
args,
|
|
35
29
|
shape
|
|
36
30
|
} = query;
|
|
37
|
-
|
|
38
31
|
if (typeof args === 'object' && ('oneOf' in args || 'allOf' in args || '$ref' in args || '@ref' in args)) {
|
|
39
32
|
// As of 11/15/2021 no production schemas contained queries with these args
|
|
40
33
|
throw new Error(`Query "${queryName}" contains an unsupported arg schema ${JSON.stringify(args)}. Please contact support`);
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
if (typeof shape === 'object') {
|
|
44
36
|
if (shape.items.$ref) {
|
|
45
37
|
return set('shape.items', {
|
|
46
38
|
'@ref': updateRefSyntax(projectSchema, shape.items.$ref)
|
|
47
39
|
}, query);
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
if (!shape.items['@ref']) {
|
|
51
42
|
// As of 11/15/2021 no production schemas contained queries with array return shapes that are not @refs
|
|
52
43
|
throw new Error(`Query "${queryName}" contains an unsupported shape schema ${JSON.stringify(shape)}. Please contact support`);
|
|
53
44
|
}
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
return query;
|
|
57
47
|
};
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
function migrateShapeToV3_10(shape) {
|
|
61
50
|
const {
|
|
62
51
|
schema,
|
|
63
52
|
...rest
|
|
64
|
-
} = shape;
|
|
53
|
+
} = shape;
|
|
65
54
|
|
|
55
|
+
// As of 11/15/2021 no production schemas contained shapes with array schemas
|
|
66
56
|
if ('type' in schema && schema.type === 'array') {
|
|
67
57
|
throw new Error(`Shape ${shape.name} uses an unsupported array schema. Please contact support`);
|
|
68
58
|
}
|
|
69
|
-
|
|
70
59
|
const newSchema = '$ref' in schema || '@ref' in schema ? {
|
|
71
60
|
allOf: [schema]
|
|
72
61
|
} : schema;
|
|
73
|
-
return {
|
|
62
|
+
return {
|
|
63
|
+
...rest,
|
|
74
64
|
schema: newSchema
|
|
75
65
|
};
|
|
76
66
|
}
|
|
77
|
-
|
|
78
67
|
const migrate = async (_, projectSchema) => {
|
|
79
68
|
const {
|
|
80
69
|
queries,
|
|
@@ -84,12 +73,12 @@ const migrate = async (_, projectSchema) => {
|
|
|
84
73
|
...rest
|
|
85
74
|
} = projectSchema;
|
|
86
75
|
const migrate = migrateQueryToV3_10(projectSchema);
|
|
87
|
-
return {
|
|
76
|
+
return {
|
|
77
|
+
...rest,
|
|
88
78
|
queries: mapValues(queries, migrate),
|
|
89
79
|
mutations: mapValues(mutations, migrate),
|
|
90
80
|
shapes: mapValues(shapes, migrateShapeToV3_10),
|
|
91
81
|
schemaVersion: '3.10.0'
|
|
92
82
|
};
|
|
93
83
|
};
|
|
94
|
-
|
|
95
84
|
export default migrate;
|