@takeshape/schema 9.80.4 → 9.81.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/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
|
@@ -4,18 +4,15 @@ import last from 'lodash/last';
|
|
|
4
4
|
import isString from 'lodash/isString';
|
|
5
5
|
import unset from 'lodash/unset';
|
|
6
6
|
const TAKESHAPE_RESOLVERS = ['takeshape:getUser', 'takeshape:search', 'takeshape:queryApiIndex', 'util:wrap'];
|
|
7
|
-
|
|
8
7
|
function getServicePath(path) {
|
|
9
8
|
const servicePath = [...path];
|
|
10
9
|
servicePath.splice(-1, 1, 'service');
|
|
11
10
|
return servicePath;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
const migrate = async (_, projectSchema) => {
|
|
15
13
|
visit(projectSchema, ['@ref', '@mapping', 'name'], (value, path) => {
|
|
16
14
|
if (isString(value)) {
|
|
17
15
|
const name = last(path);
|
|
18
|
-
|
|
19
16
|
if (name === 'name' && value === 'debug:noop') {
|
|
20
17
|
set(projectSchema, path, 'util:noop');
|
|
21
18
|
unset(projectSchema, getServicePath(path));
|
|
@@ -30,9 +27,9 @@ const migrate = async (_, projectSchema) => {
|
|
|
30
27
|
}
|
|
31
28
|
}
|
|
32
29
|
});
|
|
33
|
-
return {
|
|
30
|
+
return {
|
|
31
|
+
...projectSchema,
|
|
34
32
|
schemaVersion: '3.31.0'
|
|
35
33
|
};
|
|
36
34
|
};
|
|
37
|
-
|
|
38
35
|
export default migrate;
|
|
@@ -1,70 +1,65 @@
|
|
|
1
1
|
import { shapeNameToRef } from '../../refs';
|
|
2
|
-
|
|
3
2
|
function migrateListQuery(listConfig) {
|
|
4
3
|
const {
|
|
5
4
|
pagination,
|
|
6
5
|
name,
|
|
7
6
|
...restConfig
|
|
8
7
|
} = listConfig;
|
|
9
|
-
const result = {
|
|
8
|
+
const result = {
|
|
9
|
+
...restConfig,
|
|
10
10
|
query: name
|
|
11
11
|
};
|
|
12
|
-
|
|
13
12
|
if (pagination) {
|
|
14
13
|
const {
|
|
15
14
|
itemsToIndexPath,
|
|
16
15
|
...restPagination
|
|
17
16
|
} = pagination;
|
|
18
|
-
result.pagination = {
|
|
17
|
+
result.pagination = {
|
|
18
|
+
...restPagination,
|
|
19
19
|
itemsPath: itemsToIndexPath
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
return result;
|
|
24
23
|
}
|
|
25
|
-
|
|
26
24
|
function queriesToLoaders(queries) {
|
|
27
25
|
if (queries.list) {
|
|
28
26
|
const loaders = {
|
|
29
27
|
list: Array.isArray(queries.list) ? queries.list.map(migrateListQuery) : migrateListQuery(queries.list)
|
|
30
28
|
};
|
|
31
|
-
|
|
32
29
|
if (queries.get) {
|
|
33
30
|
const {
|
|
34
31
|
name,
|
|
35
32
|
...restGet
|
|
36
33
|
} = queries.get;
|
|
37
|
-
loaders.get = {
|
|
34
|
+
loaders.get = {
|
|
35
|
+
...restGet,
|
|
38
36
|
query: name
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
return loaders;
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
|
-
|
|
46
42
|
function migrateTrigger(trigger) {
|
|
47
43
|
const {
|
|
48
44
|
query,
|
|
49
45
|
...rest
|
|
50
46
|
} = trigger;
|
|
51
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
...rest,
|
|
52
49
|
loader: query
|
|
53
50
|
};
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
const migrate = async (_, projectSchema) => {
|
|
57
|
-
const updatedShapes = {
|
|
53
|
+
const updatedShapes = {
|
|
54
|
+
...projectSchema.shapes
|
|
58
55
|
};
|
|
59
56
|
const {
|
|
60
57
|
indexedShapes,
|
|
61
58
|
...rest
|
|
62
59
|
} = projectSchema;
|
|
63
|
-
|
|
64
60
|
if (indexedShapes) {
|
|
65
61
|
for (const [name, config] of Object.entries(indexedShapes)) {
|
|
66
62
|
let shape = updatedShapes[name];
|
|
67
|
-
|
|
68
63
|
if (!shape) {
|
|
69
64
|
shape = {
|
|
70
65
|
name,
|
|
@@ -77,13 +72,10 @@ const migrate = async (_, projectSchema) => {
|
|
|
77
72
|
}
|
|
78
73
|
};
|
|
79
74
|
}
|
|
80
|
-
|
|
81
75
|
const loaders = queriesToLoaders(config.queries);
|
|
82
|
-
|
|
83
76
|
if (loaders) {
|
|
84
77
|
shape.loaders = loaders;
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
shape.cache = {
|
|
88
80
|
enabled: true,
|
|
89
81
|
fragment: config.query,
|
|
@@ -92,11 +84,10 @@ const migrate = async (_, projectSchema) => {
|
|
|
92
84
|
updatedShapes[name] = shape;
|
|
93
85
|
}
|
|
94
86
|
}
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
return {
|
|
88
|
+
...rest,
|
|
97
89
|
shapes: updatedShapes,
|
|
98
90
|
schemaVersion: '3.32.0'
|
|
99
91
|
};
|
|
100
92
|
};
|
|
101
|
-
|
|
102
93
|
export default migrate;
|
|
@@ -5,17 +5,18 @@ import upperFirst from 'lodash/upperFirst';
|
|
|
5
5
|
import set from 'lodash/fp/set';
|
|
6
6
|
import unset from 'lodash/fp/unset';
|
|
7
7
|
import { getServiceObjectFields } from '../../services';
|
|
8
|
-
import { CURRENT_SCHEMA_VERSION } from '../../schemas';
|
|
8
|
+
import { CURRENT_SCHEMA_VERSION } from '../../schemas';
|
|
9
9
|
|
|
10
|
+
// Inline utilities for posterity
|
|
10
11
|
function refItemToShapeName(refItem) {
|
|
11
12
|
const {
|
|
12
13
|
serviceNamespace,
|
|
13
14
|
typeName
|
|
14
15
|
} = refItem;
|
|
15
16
|
return serviceNamespace ? `${serviceNamespace}_${typeName}` : typeName;
|
|
16
|
-
}
|
|
17
|
-
|
|
17
|
+
}
|
|
18
18
|
|
|
19
|
+
// Map of form studio widgets and their replacements in the shape editor
|
|
19
20
|
const widgetMigrations = {
|
|
20
21
|
object: 'shapeObject',
|
|
21
22
|
repeater: 'shapeArray'
|
|
@@ -25,36 +26,28 @@ export function normalizeForms(projectSchema) {
|
|
|
25
26
|
const {
|
|
26
27
|
forms = {}
|
|
27
28
|
} = projectSchema;
|
|
28
|
-
|
|
29
29
|
const storeSourceForm = (shapeName, formConfig, propName) => {
|
|
30
30
|
if (!normalizedForms[shapeName]) {
|
|
31
31
|
normalizedForms[shapeName] = {
|
|
32
32
|
default: deepClone(formConfig)
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
|
|
36
35
|
const propConfig = normalizedForms[shapeName].default.properties[propName];
|
|
37
36
|
delete propConfig.properties;
|
|
38
37
|
delete propConfig.order;
|
|
39
38
|
propConfig.widget = widgetMigrations[propConfig.widget] ?? propConfig.widget;
|
|
40
39
|
};
|
|
41
|
-
|
|
42
40
|
const normalizeNested = (shapeName, formConfig) => {
|
|
43
41
|
const shape = projectSchema.shapes[shapeName];
|
|
44
|
-
|
|
45
42
|
if (!shape || !formConfig.properties) {
|
|
46
43
|
return;
|
|
47
44
|
}
|
|
48
|
-
|
|
49
45
|
const propertyAccessor = createSchemaPropertyAccessor(projectSchema, shape);
|
|
50
|
-
|
|
51
46
|
for (const propName of Object.keys(formConfig.properties)) {
|
|
52
47
|
const propConfig = formConfig.properties[propName];
|
|
53
48
|
const propSchema = propertyAccessor.getValue(propName);
|
|
54
|
-
|
|
55
49
|
if (propSchema) {
|
|
56
50
|
const ref = getRefOrItemsRef(projectSchema, propSchema);
|
|
57
|
-
|
|
58
51
|
if (ref && propConfig.properties && propConfig.widget !== 'shopify') {
|
|
59
52
|
const nestedShapeName = refItemToShapeName(ref);
|
|
60
53
|
normalizedForms[nestedShapeName] = {
|
|
@@ -66,32 +59,30 @@ export function normalizeForms(projectSchema) {
|
|
|
66
59
|
}
|
|
67
60
|
}
|
|
68
61
|
};
|
|
69
|
-
|
|
70
62
|
if (forms) {
|
|
71
63
|
for (const shapeName of Object.keys(forms)) {
|
|
72
|
-
normalizeNested(shapeName, forms[shapeName].default);
|
|
64
|
+
normalizeNested(shapeName, forms[shapeName].default);
|
|
73
65
|
|
|
66
|
+
// copy forms with no changes
|
|
74
67
|
if (!normalizedForms[shapeName]) {
|
|
75
68
|
normalizedForms[shapeName] = forms[shapeName];
|
|
76
69
|
}
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
return normalizedForms;
|
|
81
73
|
}
|
|
82
74
|
export function migrateInterfaceShapes(projectSchema) {
|
|
83
75
|
let updatedProjectSchema = projectSchema;
|
|
84
|
-
|
|
85
76
|
for (const shape of Object.values(projectSchema.shapes)) {
|
|
86
77
|
if (!shape.model) {
|
|
87
78
|
continue;
|
|
88
|
-
}
|
|
89
|
-
|
|
79
|
+
}
|
|
90
80
|
|
|
91
|
-
|
|
81
|
+
// Set the schema version to the current to appease type check this line will eventually break as the schema diverges
|
|
82
|
+
const serviceObjectFields = getServiceObjectFields({
|
|
83
|
+
...projectSchema,
|
|
92
84
|
schemaVersion: CURRENT_SCHEMA_VERSION
|
|
93
85
|
}, shape, 'shopify');
|
|
94
|
-
|
|
95
86
|
for (const field of serviceObjectFields) {
|
|
96
87
|
const {
|
|
97
88
|
fieldName,
|
|
@@ -103,25 +94,22 @@ export function migrateInterfaceShapes(projectSchema) {
|
|
|
103
94
|
const serviceShapeName = upperFirst(serviceObjectType);
|
|
104
95
|
const interfaceShapeName = `${serviceShapeName}Interface`;
|
|
105
96
|
updatedProjectSchema = unset(['shapes', interfaceShapeName], updatedProjectSchema);
|
|
106
|
-
|
|
107
97
|
if ('type' in shape.schema && shape.schema.type === 'object') {
|
|
108
98
|
const prop = shape.schema.properties[fieldName];
|
|
109
|
-
|
|
110
99
|
if (prop) {
|
|
111
100
|
updatedProjectSchema = set(['shapes', shape.name, 'schema', 'properties', fieldName, '@input'], {
|
|
112
101
|
'@ref': `${service}:${serviceShapeName}Input`
|
|
113
102
|
}, updatedProjectSchema);
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
|
-
|
|
117
105
|
for (const [mutationName, mutation] of Object.entries(projectSchema.mutations)) {
|
|
118
106
|
if (!mutation || typeof mutation.args !== 'string') {
|
|
119
107
|
continue;
|
|
120
108
|
}
|
|
121
|
-
|
|
122
109
|
for (const template of ['CreateArgs', 'UpdateArgs']) {
|
|
123
110
|
if (mutation.args === `${template}<${interfaceShapeName}>`) {
|
|
124
|
-
updatedProjectSchema = set(['mutations', mutationName], {
|
|
111
|
+
updatedProjectSchema = set(['mutations', mutationName], {
|
|
112
|
+
...mutation,
|
|
125
113
|
args: `${template}<${serviceShapeName}>`
|
|
126
114
|
}, updatedProjectSchema);
|
|
127
115
|
}
|
|
@@ -129,15 +117,13 @@ export function migrateInterfaceShapes(projectSchema) {
|
|
|
129
117
|
}
|
|
130
118
|
}
|
|
131
119
|
}
|
|
132
|
-
|
|
133
120
|
return updatedProjectSchema;
|
|
134
121
|
}
|
|
135
|
-
|
|
136
122
|
const migrate = async (_, projectSchema) => {
|
|
137
123
|
let normalized = projectSchema;
|
|
138
|
-
|
|
139
124
|
try {
|
|
140
|
-
normalized = {
|
|
125
|
+
normalized = {
|
|
126
|
+
...projectSchema,
|
|
141
127
|
forms: normalizeForms(projectSchema)
|
|
142
128
|
};
|
|
143
129
|
} catch (e) {
|
|
@@ -145,17 +131,15 @@ const migrate = async (_, projectSchema) => {
|
|
|
145
131
|
// eslint-disable-next-line no-console
|
|
146
132
|
console.log(`v3.34.0 migration warning: Failed to normalize forms`, e.message);
|
|
147
133
|
}
|
|
148
|
-
|
|
149
134
|
try {
|
|
150
135
|
normalized = migrateInterfaceShapes(normalized);
|
|
151
136
|
} catch (e) {
|
|
152
137
|
// eslint-disable-next-line no-console
|
|
153
138
|
console.log(`v3.34.0 migration warning: Failed to migrate interface shapes`, e.message);
|
|
154
139
|
}
|
|
155
|
-
|
|
156
|
-
|
|
140
|
+
return {
|
|
141
|
+
...normalized,
|
|
157
142
|
schemaVersion: '3.34.0'
|
|
158
143
|
};
|
|
159
144
|
};
|
|
160
|
-
|
|
161
145
|
export default migrate;
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import mapValues from 'lodash/mapValues';
|
|
2
|
-
|
|
3
2
|
const migrate = async (_, projectSchema) => {
|
|
4
|
-
const result = {
|
|
3
|
+
const result = {
|
|
4
|
+
...projectSchema,
|
|
5
5
|
schemaVersion: '3.36.0'
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
if (result.services) {
|
|
9
8
|
result.services = mapValues(result.services, config => {
|
|
10
9
|
// Add transformVersion to OpenAPI services so we can preserve the legacy behavior
|
|
11
10
|
if (config.serviceType === 'openapi') {
|
|
12
|
-
return {
|
|
13
|
-
|
|
11
|
+
return {
|
|
12
|
+
...config,
|
|
13
|
+
options: {
|
|
14
|
+
...config.options,
|
|
14
15
|
transformVersion: '1.0.0'
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
|
|
19
19
|
return config;
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
|
|
23
22
|
return result;
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
export default migrate;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isSearchParamsAuthentication, isServiceAuthentication } from '../../types';
|
|
2
|
-
|
|
3
2
|
const migrate = async ({
|
|
4
3
|
decryptFn,
|
|
5
4
|
encryptFn
|
|
@@ -10,45 +9,40 @@ const migrate = async ({
|
|
|
10
9
|
Object.values(projectSchema.services ?? {}).forEach(serviceConfig => {
|
|
11
10
|
if (serviceConfig.authentication) {
|
|
12
11
|
const authentication = decryptFn(serviceConfig.authentication);
|
|
13
|
-
|
|
14
12
|
if (isServiceAuthentication(authentication) && isSearchParamsAuthentication(authentication)) {
|
|
15
13
|
if (serviceConfig.provider === 'judgeMe') {
|
|
16
14
|
const shopDomain = authentication.params.find(param => param.name === 'shop_domain');
|
|
17
|
-
|
|
18
15
|
if (shopDomain) {
|
|
19
|
-
serviceConfig.options = {
|
|
16
|
+
serviceConfig.options = {
|
|
17
|
+
...serviceConfig.options,
|
|
20
18
|
searchParams: {
|
|
21
19
|
shop_domain: shopDomain.value
|
|
22
20
|
}
|
|
23
21
|
};
|
|
24
22
|
delete serviceConfig.options.shopDomain;
|
|
25
23
|
}
|
|
26
|
-
|
|
27
24
|
authentication.params = authentication.params.filter(param => param.name !== 'shop_domain');
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
if (serviceConfig.provider === 'reviewsIo') {
|
|
31
27
|
const storeId = authentication.params.find(param => param.name === 'store');
|
|
32
|
-
|
|
33
28
|
if (storeId) {
|
|
34
|
-
serviceConfig.options = {
|
|
29
|
+
serviceConfig.options = {
|
|
30
|
+
...serviceConfig.options,
|
|
35
31
|
searchParams: {
|
|
36
32
|
store: storeId.value
|
|
37
33
|
}
|
|
38
34
|
};
|
|
39
35
|
delete serviceConfig.options.storeId;
|
|
40
36
|
}
|
|
41
|
-
|
|
42
37
|
authentication.params = authentication.params.filter(param => param.name !== 'store');
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
serviceConfig.authentication = encryptFn(authentication);
|
|
46
40
|
}
|
|
47
41
|
}
|
|
48
42
|
});
|
|
49
|
-
return {
|
|
43
|
+
return {
|
|
44
|
+
...projectSchema,
|
|
50
45
|
schemaVersion: '3.39.0'
|
|
51
46
|
};
|
|
52
47
|
};
|
|
53
|
-
|
|
54
48
|
export default migrate;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { visit } from '@takeshape/util';
|
|
2
2
|
import omit from 'lodash/omit';
|
|
3
3
|
import isEmpty from 'lodash/isEmpty';
|
|
4
|
-
|
|
5
4
|
function omitOptions(resolver, names) {
|
|
6
5
|
if (resolver.options) {
|
|
7
6
|
const newOptions = omit(resolver.options, names);
|
|
8
|
-
|
|
9
7
|
if (isEmpty(newOptions)) {
|
|
10
8
|
delete resolver.options;
|
|
11
9
|
} else {
|
|
@@ -13,7 +11,6 @@ function omitOptions(resolver, names) {
|
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
const migrate = async (_, projectSchema) => {
|
|
18
15
|
/**
|
|
19
16
|
* Resolver props that are guaranteed in this version, and dependent on the
|
|
@@ -23,62 +20,53 @@ const migrate = async (_, projectSchema) => {
|
|
|
23
20
|
if (resolver.name.startsWith('takeshape')) {
|
|
24
21
|
if (!resolver.shapeName) {
|
|
25
22
|
var _resolver$options, _resolver$options2;
|
|
26
|
-
|
|
27
23
|
resolver.shapeName = ((_resolver$options = resolver.options) === null || _resolver$options === void 0 ? void 0 : _resolver$options.model) ?? ((_resolver$options2 = resolver.options) === null || _resolver$options2 === void 0 ? void 0 : _resolver$options2.indexedShape) ?? '';
|
|
28
24
|
omitOptions(resolver, ['model', 'indexedShape']);
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
|
|
32
27
|
if (resolver.name.startsWith('graphql')) {
|
|
33
28
|
if (!resolver.fieldName) {
|
|
34
29
|
var _resolver$options3;
|
|
35
|
-
|
|
36
30
|
resolver.fieldName = ((_resolver$options3 = resolver.options) === null || _resolver$options3 === void 0 ? void 0 : _resolver$options3.fieldName) ?? '';
|
|
37
31
|
omitOptions(resolver, ['fieldName']);
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
|
|
41
34
|
if (resolver.name.startsWith('awsLambda')) {
|
|
42
35
|
if (!resolver.functionName) {
|
|
43
36
|
var _resolver$options4;
|
|
44
|
-
|
|
45
37
|
resolver.functionName = ((_resolver$options4 = resolver.options) === null || _resolver$options4 === void 0 ? void 0 : _resolver$options4.functionName) ?? '';
|
|
46
38
|
omitOptions(resolver, ['functionName']);
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
if (resolver.name.startsWith('rest')) {
|
|
51
42
|
if (!resolver.path) {
|
|
52
43
|
if (resolver.pathParams) {
|
|
53
44
|
var _resolver$options5;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
serialize: {
|
|
45
|
+
resolver.path = {
|
|
46
|
+
...resolver.pathParams,
|
|
47
|
+
serialize: {
|
|
48
|
+
...resolver.pathParams.serialize,
|
|
57
49
|
template: (_resolver$options5 = resolver.options) === null || _resolver$options5 === void 0 ? void 0 : _resolver$options5.path
|
|
58
50
|
}
|
|
59
51
|
};
|
|
60
52
|
} else {
|
|
61
53
|
var _resolver$options6;
|
|
62
|
-
|
|
63
54
|
resolver.path = ((_resolver$options6 = resolver.options) === null || _resolver$options6 === void 0 ? void 0 : _resolver$options6.path) ?? '';
|
|
64
55
|
}
|
|
65
|
-
|
|
66
56
|
omitOptions(resolver, ['path']);
|
|
67
57
|
}
|
|
68
58
|
}
|
|
59
|
+
|
|
69
60
|
/**
|
|
70
61
|
* `resolver.name` was previously validated with app code and v3.9.0
|
|
71
62
|
* enumerates the previous validation, making this assertion safe.
|
|
72
63
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
75
64
|
return resolver;
|
|
76
65
|
};
|
|
66
|
+
|
|
77
67
|
/**
|
|
78
68
|
* Function will visit each resolver in the schema and mutate them.
|
|
79
69
|
*/
|
|
80
|
-
|
|
81
|
-
|
|
82
70
|
visit(projectSchema, ['resolver', '@resolver'], resolver => {
|
|
83
71
|
if (resolver.compose) {
|
|
84
72
|
resolver.compose.forEach(ensureResolverOptions);
|
|
@@ -86,9 +74,9 @@ const migrate = async (_, projectSchema) => {
|
|
|
86
74
|
ensureResolverOptions(resolver);
|
|
87
75
|
}
|
|
88
76
|
});
|
|
89
|
-
return {
|
|
77
|
+
return {
|
|
78
|
+
...projectSchema,
|
|
90
79
|
schemaVersion: '3.9.0'
|
|
91
80
|
};
|
|
92
81
|
};
|
|
93
|
-
|
|
94
82
|
export default migrate;
|
package/es/mocks.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
import { emptySchema, applyDefaultsToSchema } from './schema-util';
|
|
2
2
|
import { pascalCase } from '@takeshape/util';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Like emptySchema, but for tests.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export function createMockSchema(projectId, schema = {}) {
|
|
8
|
-
return {
|
|
8
|
+
return {
|
|
9
|
+
...emptySchema(projectId),
|
|
9
10
|
...schema,
|
|
10
11
|
projectId
|
|
11
12
|
};
|
|
12
13
|
}
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Capturing a common pattern used in tests. Creates an empty schema, with defaults.
|
|
15
17
|
*/
|
|
16
|
-
|
|
17
18
|
export function createMockSchemaWithDefaults(projectId, schema = {}) {
|
|
18
|
-
return applyDefaultsToSchema({
|
|
19
|
+
return applyDefaultsToSchema({
|
|
20
|
+
...emptySchema(projectId),
|
|
19
21
|
...schema,
|
|
20
22
|
projectId
|
|
21
23
|
});
|
|
@@ -39,13 +41,15 @@ export function createMockServiceConfig(serviceKey, serviceConfig) {
|
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
43
|
export function createMockStoredServiceConfig(serviceKey, serviceConfig) {
|
|
42
|
-
return {
|
|
44
|
+
return {
|
|
45
|
+
...createMockServiceConfig(serviceKey),
|
|
43
46
|
authentication: 'encrypted-abc123',
|
|
44
47
|
...serviceConfig
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
50
|
export function addMockIndexingConfig(shape) {
|
|
48
|
-
return {
|
|
51
|
+
return {
|
|
52
|
+
...shape,
|
|
49
53
|
loaders: {
|
|
50
54
|
list: {
|
|
51
55
|
query: `Query.get${shape.name}List`
|