@takeshape/schema 9.80.3 → 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.
Files changed (189) hide show
  1. package/dist/api-version.js +0 -9
  2. package/dist/builtin-schema.js +0 -5
  3. package/dist/content-schema-transform.js +4 -52
  4. package/dist/create-input-schema.js +7 -19
  5. package/dist/enum.js +0 -3
  6. package/dist/flatten-templates.js +0 -11
  7. package/dist/get-is-leaf.js +8 -18
  8. package/dist/index.js +0 -58
  9. package/dist/interfaces.js +2 -26
  10. package/dist/layers/layers.js +23 -103
  11. package/dist/layers/refs.js +26 -69
  12. package/dist/layers/type-utils.js +11 -43
  13. package/dist/layers/visitor.js +0 -6
  14. package/dist/migration/index.js +0 -51
  15. package/dist/migration/to/v3.0.0.js +31 -45
  16. package/dist/migration/to/v3.1.0.js +15 -41
  17. package/dist/migration/to/v3.10.0.js +6 -20
  18. package/dist/migration/to/v3.11.0.js +8 -20
  19. package/dist/migration/to/v3.12.0.js +2 -3
  20. package/dist/migration/to/v3.12.1.js +2 -3
  21. package/dist/migration/to/v3.12.2.js +2 -3
  22. package/dist/migration/to/v3.12.3.js +16 -21
  23. package/dist/migration/to/v3.13.0.js +2 -7
  24. package/dist/migration/to/v3.14.0.js +2 -3
  25. package/dist/migration/to/v3.15.0.js +2 -3
  26. package/dist/migration/to/v3.16.0.js +2 -3
  27. package/dist/migration/to/v3.17.0.js +4 -9
  28. package/dist/migration/to/v3.17.1.js +2 -3
  29. package/dist/migration/to/v3.18.0.js +2 -15
  30. package/dist/migration/to/v3.18.1.js +2 -7
  31. package/dist/migration/to/v3.18.2.js +8 -10
  32. package/dist/migration/to/v3.19.0.js +2 -3
  33. package/dist/migration/to/v3.2.0.js +2 -3
  34. package/dist/migration/to/v3.20.0.js +10 -11
  35. package/dist/migration/to/v3.21.0.js +2 -3
  36. package/dist/migration/to/v3.22.0.js +4 -9
  37. package/dist/migration/to/v3.23.0.js +2 -3
  38. package/dist/migration/to/v3.24.0.js +2 -3
  39. package/dist/migration/to/v3.25.0.js +2 -3
  40. package/dist/migration/to/v3.26.0.js +2 -3
  41. package/dist/migration/to/v3.27.0.js +2 -3
  42. package/dist/migration/to/v3.28.0.js +2 -3
  43. package/dist/migration/to/v3.29.0.js +2 -3
  44. package/dist/migration/to/v3.3.0.js +3 -4
  45. package/dist/migration/to/v3.30.0.js +2 -3
  46. package/dist/migration/to/v3.31.0.js +2 -12
  47. package/dist/migration/to/v3.32.0.js +12 -22
  48. package/dist/migration/to/v3.33.0.js +2 -3
  49. package/dist/migration/to/v3.34.0.js +14 -43
  50. package/dist/migration/to/v3.35.0.js +2 -3
  51. package/dist/migration/to/v3.36.0.js +6 -10
  52. package/dist/migration/to/v3.37.0.js +2 -3
  53. package/dist/migration/to/v3.38.0.js +2 -3
  54. package/dist/migration/to/v3.39.0.js +6 -13
  55. package/dist/migration/to/v3.4.0.js +2 -3
  56. package/dist/migration/to/v3.5.0.js +2 -3
  57. package/dist/migration/to/v3.5.1.js +2 -3
  58. package/dist/migration/to/v3.6.0.js +2 -3
  59. package/dist/migration/to/v3.7.0.js +2 -3
  60. package/dist/migration/to/v3.8.0.js +2 -3
  61. package/dist/migration/to/v3.9.0.js +8 -24
  62. package/dist/migration/utils.js +0 -2
  63. package/dist/mocks.js +9 -12
  64. package/dist/models/project-schema.js +0 -34
  65. package/dist/models/query.js +0 -9
  66. package/dist/models/service.js +0 -8
  67. package/dist/models/shape.js +0 -29
  68. package/dist/project-schema/index.js +1 -105
  69. package/dist/project-schema/migrate.js +1 -54
  70. package/dist/refs.js +39 -159
  71. package/dist/relationships.js +13 -57
  72. package/dist/scalars.js +0 -1
  73. package/dist/schema-transform.js +0 -11
  74. package/dist/schema-util.js +75 -271
  75. package/dist/schemas/index.js +0 -64
  76. package/dist/services.js +24 -44
  77. package/dist/taxonomies.js +0 -13
  78. package/dist/template-shapes/index.js +1 -8
  79. package/dist/template-shapes/templates.js +9 -40
  80. package/dist/template-shapes/types.js +4 -5
  81. package/dist/template-shapes/where.js +14 -110
  82. package/dist/types/index.js +0 -4
  83. package/dist/types/types.js +41 -13
  84. package/dist/types/utils.js +15 -89
  85. package/dist/unions.js +8 -38
  86. package/dist/util/api-indexing.js +2 -19
  87. package/dist/util/detect-cycles.js +2 -16
  88. package/dist/util/find-shape-at-path.js +1 -15
  89. package/dist/util/form-config.js +6 -23
  90. package/dist/util/get-conflicting-properties.js +7 -17
  91. package/dist/util/get-return-shape.js +0 -11
  92. package/dist/util/has-arg.js +0 -6
  93. package/dist/util/index.js +0 -18
  94. package/dist/util/merge.js +28 -74
  95. package/dist/util/patch-schema.js +5 -13
  96. package/dist/validate.js +15 -234
  97. package/dist/versions.js +0 -2
  98. package/dist/workflows.js +0 -15
  99. package/es/api-version.js +0 -4
  100. package/es/content-schema-transform.js +4 -38
  101. package/es/create-input-schema.js +7 -14
  102. package/es/enum.js +0 -2
  103. package/es/flatten-templates.js +0 -4
  104. package/es/get-is-leaf.js +8 -13
  105. package/es/index.js +1 -0
  106. package/es/interfaces.js +2 -14
  107. package/es/layers/layers.js +23 -90
  108. package/es/layers/refs.js +22 -45
  109. package/es/layers/type-utils.js +11 -16
  110. package/es/layers/visitor.js +0 -3
  111. package/es/migration/to/v3.0.0.js +31 -38
  112. package/es/migration/to/v3.1.0.js +16 -34
  113. package/es/migration/to/v3.10.0.js +6 -17
  114. package/es/migration/to/v3.11.0.js +8 -18
  115. package/es/migration/to/v3.12.0.js +2 -2
  116. package/es/migration/to/v3.12.1.js +2 -2
  117. package/es/migration/to/v3.12.2.js +2 -2
  118. package/es/migration/to/v3.12.3.js +16 -19
  119. package/es/migration/to/v3.13.0.js +2 -4
  120. package/es/migration/to/v3.14.0.js +2 -2
  121. package/es/migration/to/v3.15.0.js +2 -2
  122. package/es/migration/to/v3.16.0.js +2 -2
  123. package/es/migration/to/v3.17.0.js +4 -4
  124. package/es/migration/to/v3.17.1.js +2 -2
  125. package/es/migration/to/v3.18.0.js +2 -10
  126. package/es/migration/to/v3.18.1.js +2 -3
  127. package/es/migration/to/v3.18.2.js +8 -8
  128. package/es/migration/to/v3.19.0.js +2 -2
  129. package/es/migration/to/v3.2.0.js +2 -2
  130. package/es/migration/to/v3.20.0.js +10 -9
  131. package/es/migration/to/v3.21.0.js +2 -2
  132. package/es/migration/to/v3.22.0.js +4 -6
  133. package/es/migration/to/v3.23.0.js +2 -2
  134. package/es/migration/to/v3.24.0.js +2 -2
  135. package/es/migration/to/v3.25.0.js +2 -2
  136. package/es/migration/to/v3.26.0.js +2 -2
  137. package/es/migration/to/v3.27.0.js +2 -2
  138. package/es/migration/to/v3.28.0.js +2 -2
  139. package/es/migration/to/v3.29.0.js +2 -2
  140. package/es/migration/to/v3.3.0.js +3 -3
  141. package/es/migration/to/v3.30.0.js +2 -2
  142. package/es/migration/to/v3.31.0.js +2 -5
  143. package/es/migration/to/v3.32.0.js +12 -21
  144. package/es/migration/to/v3.33.0.js +2 -2
  145. package/es/migration/to/v3.34.0.js +16 -32
  146. package/es/migration/to/v3.35.0.js +2 -2
  147. package/es/migration/to/v3.36.0.js +6 -8
  148. package/es/migration/to/v3.37.0.js +2 -2
  149. package/es/migration/to/v3.38.0.js +2 -2
  150. package/es/migration/to/v3.39.0.js +6 -12
  151. package/es/migration/to/v3.4.0.js +2 -2
  152. package/es/migration/to/v3.5.0.js +2 -2
  153. package/es/migration/to/v3.5.1.js +2 -2
  154. package/es/migration/to/v3.6.0.js +2 -2
  155. package/es/migration/to/v3.7.0.js +2 -2
  156. package/es/migration/to/v3.8.0.js +2 -2
  157. package/es/migration/to/v3.9.0.js +8 -20
  158. package/es/mocks.js +10 -6
  159. package/es/models/project-schema.js +0 -26
  160. package/es/models/query.js +0 -7
  161. package/es/models/service.js +0 -6
  162. package/es/models/shape.js +1 -25
  163. package/es/project-schema/index.js +0 -5
  164. package/es/project-schema/migrate.js +3 -51
  165. package/es/refs.js +40 -96
  166. package/es/relationships.js +14 -42
  167. package/es/schema-transform.js +0 -7
  168. package/es/schema-util.js +75 -180
  169. package/es/services.js +18 -27
  170. package/es/taxonomies.js +0 -9
  171. package/es/template-shapes/index.js +1 -4
  172. package/es/template-shapes/templates.js +9 -18
  173. package/es/template-shapes/types.js +3 -4
  174. package/es/template-shapes/where.js +14 -94
  175. package/es/types/types.js +43 -10
  176. package/es/types/utils.js +16 -24
  177. package/es/unions.js +8 -22
  178. package/es/util/api-indexing.js +2 -12
  179. package/es/util/detect-cycles.js +2 -14
  180. package/es/util/find-shape-at-path.js +2 -12
  181. package/es/util/form-config.js +7 -19
  182. package/es/util/get-conflicting-properties.js +8 -14
  183. package/es/util/get-return-shape.js +0 -8
  184. package/es/util/has-arg.js +0 -3
  185. package/es/util/merge.js +28 -55
  186. package/es/util/patch-schema.js +5 -7
  187. package/es/validate.js +15 -194
  188. package/es/workflows.js +0 -6
  189. package/package.json +5 -5
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.30.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -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 { ...projectSchema,
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 = { ...restConfig,
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 = { ...restPagination,
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 = { ...restGet,
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 { ...rest,
47
+ return {
48
+ ...rest,
52
49
  loader: query
53
50
  };
54
51
  }
55
-
56
52
  const migrate = async (_, projectSchema) => {
57
- const updatedShapes = { ...projectSchema.shapes
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
- return { ...rest,
87
+ return {
88
+ ...rest,
97
89
  shapes: updatedShapes,
98
90
  schemaVersion: '3.32.0'
99
91
  };
100
92
  };
101
-
102
93
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.33.0'
7
8
  };
8
9
  };
9
-
10
10
  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'; // Inline utilities for posterity
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
- } // Map of form studio widgets and their replacements in the shape editor
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); // copy forms with no changes
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
- } // Set the schema version to the current to appease type check this line will eventually break as the schema diverges
89
-
79
+ }
90
80
 
91
- const serviceObjectFields = getServiceObjectFields({ ...projectSchema,
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], { ...mutation,
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 = { ...projectSchema,
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
- return { ...normalized,
140
+ return {
141
+ ...normalized,
157
142
  schemaVersion: '3.34.0'
158
143
  };
159
144
  };
160
-
161
145
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.35.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -1,26 +1,24 @@
1
1
  import mapValues from 'lodash/mapValues';
2
-
3
2
  const migrate = async (_, projectSchema) => {
4
- const result = { ...projectSchema,
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 { ...config,
13
- options: { ...config.options,
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;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.37.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.38.0'
7
8
  };
8
9
  };
9
-
10
10
  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 = { ...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 = { ...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 { ...projectSchema,
43
+ return {
44
+ ...projectSchema,
50
45
  schemaVersion: '3.39.0'
51
46
  };
52
47
  };
53
-
54
48
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.4.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.5.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.5.1'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.6.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.7.0'
7
8
  };
8
9
  };
9
-
10
10
  export default migrate;
@@ -2,9 +2,9 @@ const migrate = async (_, projectSchema) => {
2
2
  /**
3
3
  * No migration needed all changes are backwards compatible.
4
4
  */
5
- return { ...projectSchema,
5
+ return {
6
+ ...projectSchema,
6
7
  schemaVersion: '3.8.0'
7
8
  };
8
9
  };
9
-
10
10
  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
- resolver.path = { ...resolver.pathParams,
56
- serialize: { ...resolver.pathParams.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 { ...projectSchema,
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 { ...emptySchema(projectId),
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({ ...emptySchema(projectId),
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 { ...createMockServiceConfig(serviceKey),
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 { ...shape,
51
+ return {
52
+ ...shape,
49
53
  loaders: {
50
54
  list: {
51
55
  query: `Query.get${shape.name}List`