@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.
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
@@ -4,31 +4,22 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.workflowsEnabled = exports.whereClauseEnabled = exports.createVersionPredicate = void 0;
7
-
8
7
  var _gte = _interopRequireDefault(require("semver/functions/gte"));
9
-
10
8
  var _coerce = _interopRequireDefault(require("semver/functions/coerce"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  const createVersionPredicate = (featureVersion, comparison) => {
15
11
  const coercedFeatureVersion = (0, _coerce.default)(featureVersion);
16
-
17
12
  if (!coercedFeatureVersion) {
18
13
  throw new Error(`Could not create predicate version "${featureVersion}" is not valid`);
19
14
  }
20
-
21
15
  return apiVersion => {
22
16
  const coercedApiVersion = (0, _coerce.default)(apiVersion);
23
-
24
17
  if (!coercedApiVersion) {
25
18
  throw new Error(`Version "${apiVersion}" is not valid and could not be coerced`);
26
19
  }
27
-
28
20
  return comparison(coercedApiVersion, coercedFeatureVersion);
29
21
  };
30
22
  };
31
-
32
23
  exports.createVersionPredicate = createVersionPredicate;
33
24
  const workflowsEnabled = createVersionPredicate('2.0.0', _gte.default);
34
25
  exports.workflowsEnabled = workflowsEnabled;
@@ -8,21 +8,16 @@ exports.getAssetS3Path = getAssetS3Path;
8
8
  exports.isAsset = isAsset;
9
9
  exports.jsonShape = void 0;
10
10
  exports.setAssetS3Path = setAssetS3Path;
11
-
12
11
  function isAsset(content) {
13
12
  return content._contentTypeId === 'ASSET' || content._shapeId === 'ASSET';
14
13
  }
15
-
16
14
  const ASSET_PATH = 'Hk6FQuz5';
17
-
18
15
  function getAssetS3Path(content) {
19
16
  return content[ASSET_PATH];
20
17
  }
21
-
22
18
  function setAssetS3Path(content, path) {
23
19
  content[ASSET_PATH] = path;
24
20
  }
25
-
26
21
  const jsonShape = {
27
22
  id: 'JSON',
28
23
  name: 'JSON',
@@ -10,76 +10,54 @@ exports.getType = getType;
10
10
  exports.preferKey = preferKey;
11
11
  exports.preferSourceKey = preferSourceKey;
12
12
  exports.toName = toName;
13
-
14
13
  var _forEach = _interopRequireDefault(require("lodash/forEach"));
15
-
16
14
  var _difference = _interopRequireDefault(require("lodash/difference"));
17
-
18
15
  var _pick = _interopRequireDefault(require("lodash/pick"));
19
-
20
16
  var _schemaUtil = require("./schema-util");
21
-
22
17
  var _utils = require("./types/utils");
23
-
24
18
  var _refs = require("./refs");
25
-
26
19
  var _unions = require("./unions");
27
-
28
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
21
  const typeCache = new WeakMap();
31
-
32
22
  function getType(schema) {
33
23
  let type = typeCache.get(schema);
34
-
35
24
  if (type) {
36
25
  return type;
37
26
  }
27
+ type = schema.type;
38
28
 
39
- type = schema.type; // Handle nullable types for example: ['object', 'null']
40
-
29
+ // Handle nullable types for example: ['object', 'null']
41
30
  if (Array.isArray(type)) {
42
31
  const filtered = type.filter(name => name !== 'null');
43
-
44
32
  if (!filtered.length) {
45
33
  throw new Error(`Invalid schema`);
46
34
  }
47
-
48
35
  type = filtered[0];
49
36
  }
50
-
51
37
  typeCache.set(schema, type);
52
38
  return type;
53
39
  }
54
-
55
40
  function toName(name) {
56
41
  return name;
57
42
  }
58
-
59
43
  function ensureArray(value) {
60
44
  return Array.isArray(value) ? value : [value];
61
45
  }
62
-
63
46
  function preferKey(name, schema) {
64
47
  return (0, _schemaUtil.getStorageKey)(schema) ?? name;
65
48
  }
66
-
67
49
  function preferSourceKey(name, schema) {
68
50
  const key = (0, _schemaUtil.getStorageKey)(schema);
69
51
  return key ? [key, name] : [name];
70
52
  }
71
-
72
53
  function findTransforms(pluginMap, schema, name, shape) {
73
54
  const type = getType(schema);
74
-
75
55
  if (pluginMap && (pluginMap[type] || pluginMap['*'])) {
76
56
  const plugins = (pluginMap[type] ?? []).concat(pluginMap['*'] ?? []);
77
57
  return plugins.find(plugin => plugin.filter(schema, name, shape));
78
58
  }
79
-
80
59
  return undefined;
81
60
  }
82
-
83
61
  function getContentTransform({
84
62
  transforms,
85
63
  accumulators,
@@ -92,22 +70,17 @@ function getContentTransform({
92
70
  const prepare = (schema, obj, name = '') => {
93
71
  const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
94
72
  schema = (0, _refs.dereferenceSchema)(projectSchema, schema);
95
-
96
73
  if (accumulators) {
97
74
  accumulators.forEach(accumulator => {
98
75
  accumulator.accumulate(obj, schema, name);
99
76
  });
100
77
  }
101
-
102
78
  const shape = shapeName ? projectSchema.shapes[shapeName] : undefined;
103
79
  const transform = findTransforms(transforms, schema, name, shape);
104
-
105
80
  if (transform) {
106
81
  const next = (value, schema, name) => prepare(schema, value, name);
107
-
108
82
  return transform.process(obj, schema, name, shape, next);
109
83
  }
110
-
111
84
  if (obj && (0, _unions.isUnionSchema)(schema)) {
112
85
  for (const {
113
86
  shapeId,
@@ -118,16 +91,13 @@ function getContentTransform({
118
91
  }
119
92
  }
120
93
  }
121
-
122
94
  if (obj && (0, _utils.isObjectSchema)(schema)) {
123
95
  const result = {};
124
96
  const assigned = new Set();
125
97
  (0, _forEach.default)(schema.properties, (fieldSchema, name) => {
126
98
  const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema, obj));
127
-
128
99
  for (const sourceKey of sourceKeys) {
129
100
  const value = prepare(fieldSchema, obj === null || obj === void 0 ? void 0 : obj[sourceKey], name);
130
-
131
101
  if (value !== undefined) {
132
102
  assigned.add(sourceKey);
133
103
  const transform = findTransforms(transforms, (0, _refs.dereferenceSchema)(projectSchema, fieldSchema), name);
@@ -136,51 +106,39 @@ function getContentTransform({
136
106
  }
137
107
  }
138
108
  });
139
-
140
109
  if (passThrough && obj) {
141
110
  const keys = (0, _difference.default)(Object.keys(obj), [...assigned]);
142
-
143
111
  if (keys.length) {
144
112
  Object.assign(result, (0, _pick.default)(obj, keys));
145
113
  }
146
114
  }
147
-
148
115
  return result;
149
116
  }
150
-
151
117
  if ((0, _utils.isArraySchema)(schema)) {
152
118
  const itemSchema = schema.items;
153
-
154
119
  if (Array.isArray(obj)) {
155
120
  return obj.map(item => prepare(itemSchema, item, name));
156
121
  }
157
-
158
122
  if (obj === undefined) {
159
123
  prepare(itemSchema, obj, name);
160
124
  }
161
125
  }
162
-
163
126
  if (allowNullObjects && (0, _utils.isObjectSchema)(schema) && obj === null) {
164
127
  return null;
165
- } // Allow properties that have not been transformed
166
-
128
+ }
167
129
 
130
+ // Allow properties that have not been transformed
168
131
  return passThrough ? obj : undefined;
169
132
  };
170
-
171
133
  return prepare;
172
134
  }
173
-
174
135
  function transformKey(transforms, propSchema, name, transform = preferKey) {
175
136
  const schemaTransform = findTransforms(transforms, propSchema, name);
176
-
177
137
  if (schemaTransform !== null && schemaTransform !== void 0 && schemaTransform.keyTransform) {
178
138
  transform = schemaTransform.keyTransform;
179
139
  }
180
-
181
140
  return transform(name, propSchema);
182
141
  }
183
-
184
142
  function getPropertyInfo(context, schema, path) {
185
143
  const {
186
144
  projectSchema,
@@ -188,21 +146,16 @@ function getPropertyInfo(context, schema, path) {
188
146
  keyTransform
189
147
  } = context;
190
148
  const result = [];
191
-
192
149
  const findProperty = (currentSchema, name, rest, path) => {
193
150
  if ((0, _utils.isObjectSchema)(currentSchema)) {
194
151
  var _currentSchema$requir;
195
-
196
152
  const propSchema = currentSchema.properties[name];
197
153
  const isRequired = ((_currentSchema$requir = currentSchema.required) === null || _currentSchema$requir === void 0 ? void 0 : _currentSchema$requir.includes(name)) ?? false;
198
-
199
154
  if (!propSchema) {
200
155
  return;
201
156
  }
202
-
203
157
  const refSchema = (0, _refs.dereferenceSchema)(projectSchema, propSchema);
204
158
  const nextPath = path.concat(transformKey(transforms, refSchema, name, keyTransform));
205
-
206
159
  if (rest.length) {
207
160
  const [nextName, ...nextRest] = rest;
208
161
  findProperty(refSchema, nextName, nextRest, nextPath);
@@ -221,7 +174,6 @@ function getPropertyInfo(context, schema, path) {
221
174
  findProperty((0, _refs.dereferenceSchema)(projectSchema, currentSchema.items), name, rest, path);
222
175
  }
223
176
  };
224
-
225
177
  const [first, ...rest] = path.split('.');
226
178
  findProperty((0, _refs.dereferenceSchema)(projectSchema, schema), first, rest, []);
227
179
  return result;
@@ -4,63 +4,51 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createInputSchema = createInputSchema;
7
-
8
7
  var _defaults = _interopRequireDefault(require("lodash/fp/defaults"));
9
-
10
8
  var _util = require("@takeshape/util");
11
-
12
9
  var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  const inputSchemaCache = new Map();
17
-
18
12
  function getInputSchemaCache(options) {
19
13
  // Ensure key order does not invalidate the cache
20
14
  const key = JSON.stringify(options, Object.keys(options).sort());
21
15
  let cache = inputSchemaCache.get(key);
22
-
23
16
  if (!cache) {
24
17
  cache = new WeakMap();
25
18
  inputSchemaCache.set(key, cache);
26
19
  }
27
-
28
20
  return cache;
29
21
  }
22
+
30
23
  /**
31
24
  * Convert all output properties in the schema to be input properties,
32
25
  * For an update, remove `required` and `default` fields as well.
33
26
  */
34
-
35
-
36
27
  function createInputSchema(schema, options = {}) {
37
28
  const inputSchemaCache = getInputSchemaCache((0, _defaults.default)({
38
29
  isUpdate: false
39
30
  }, options));
40
31
  let rewrittenSchema = inputSchemaCache.get(schema);
41
-
42
32
  if (rewrittenSchema) {
43
33
  return rewrittenSchema;
44
34
  }
45
-
46
35
  rewrittenSchema = JSON.parse(JSON.stringify(schema), (_key, value) => {
47
36
  if ((0, _util.isRecord)(value)) {
48
37
  // Remove required
49
38
  if (options.isUpdate && Array.isArray(value.required) && value.required.length) {
50
39
  delete value.required;
51
- } // Remove default
52
-
40
+ }
53
41
 
42
+ // Remove default
54
43
  if (options.isUpdate && value.type !== undefined && value.default !== undefined) {
55
44
  delete value.default;
56
45
  }
57
-
58
46
  if (value.type === 'object' && (0, _util.isRecord)(value.properties)) {
59
- return { ...value,
47
+ return {
48
+ ...value,
60
49
  properties: (0, _omitBy.default)(value.properties, prop => (0, _util.isRecord)(prop) && prop['@resolver'] && !prop['@input'])
61
50
  };
62
51
  }
63
-
64
52
  if ((0, _util.isRecord)(value['@input'])) {
65
53
  const {
66
54
  '@input': input,
@@ -70,7 +58,8 @@ function createInputSchema(schema, options = {}) {
70
58
  title,
71
59
  ...output
72
60
  } = value;
73
- return { ...input,
61
+ return {
62
+ ...input,
74
63
  title,
75
64
  '@l10n': l10n,
76
65
  '@syncLocaleStructure': syncLocaleStructure,
@@ -79,7 +68,6 @@ function createInputSchema(schema, options = {}) {
79
68
  };
80
69
  }
81
70
  }
82
-
83
71
  return value;
84
72
  });
85
73
  inputSchemaCache.set(schema, rewrittenSchema);
package/dist/enum.js CHANGED
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.isEnumLikeSchema = isEnumLikeSchema;
7
-
8
7
  function isEnumLikeSchema(schema) {
9
8
  if (schema.enum) {
10
9
  return true;
11
10
  }
12
-
13
11
  if (schema.oneOf) {
14
12
  return schema.oneOf.every(optionSchema => optionSchema.title !== undefined && (optionSchema.enum || optionSchema.const));
15
13
  }
16
-
17
14
  return false;
18
15
  }
@@ -4,28 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.flattenTemplates = flattenTemplates;
7
-
8
7
  var _templateShapes = require("./template-shapes");
9
-
10
8
  var _schemaUtil = require("./schema-util");
11
-
12
9
  var _set = _interopRequireDefault(require("lodash/set"));
13
-
14
10
  var _util = require("@takeshape/util");
15
-
16
11
  var _refs = require("./refs");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  function flattenTemplates(projectSchema) {
21
14
  const templateRefs = (0, _schemaUtil.getAllRefs)(projectSchema, ref => Boolean(ref.template));
22
-
23
15
  if (!templateRefs.length) {
24
16
  return projectSchema;
25
17
  }
26
-
27
18
  const newSchema = (0, _util.deepClone)(projectSchema);
28
-
29
19
  for (const ref of templateRefs) {
30
20
  if (ref.template && (0, _templateShapes.isValidTemplate)(ref.template)) {
31
21
  const {
@@ -36,6 +26,5 @@ function flattenTemplates(projectSchema) {
36
26
  Object.assign(newSchema.shapes, dependencies);
37
27
  }
38
28
  }
39
-
40
29
  return newSchema;
41
30
  }
@@ -4,50 +4,41 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getIsLeaf = getIsLeaf;
7
-
8
7
  var _contentSchemaTransform = require("./content-schema-transform");
9
-
10
8
  var _schemaUtil = require("./schema-util");
11
-
12
9
  var _refs = require("./refs");
13
-
14
10
  var _types = require("./types");
15
-
16
11
  const scalarTags = new Set(['draftjs']);
17
-
18
12
  function isLeafTypeV3(projectSchema, propertySchema) {
19
13
  const type = (0, _contentSchemaTransform.getType)(propertySchema);
20
- return Boolean( // Must have key
21
- (0, _schemaUtil.getStorageKey)(propertySchema) && ( // If is not a structure, then is a leaf
22
- !['object', 'array'].includes(type) || // If is relationship, then is a leaf
23
- (0, _types.isPropertySchemaWithRelationship)(propertySchema['@output'] ?? propertySchema) || propertySchema['@tag'] && scalarTags.has(propertySchema['@tag']) || // If is array, then should not be a synchronized structure
14
+ return Boolean(
15
+ // Must have key
16
+ (0, _schemaUtil.getStorageKey)(propertySchema) && (
17
+ // If is not a structure, then is a leaf
18
+ !['object', 'array'].includes(type) ||
19
+ // If is relationship, then is a leaf
20
+ (0, _types.isPropertySchemaWithRelationship)(propertySchema['@output'] ?? propertySchema) || propertySchema['@tag'] && scalarTags.has(propertySchema['@tag']) ||
21
+ // If is array, then should not be a synchronized structure
24
22
  type === 'array' && !propertySchema['@syncLocaleStructure'] || (0, _schemaUtil.isBuiltinType)(projectSchema, propertySchema)));
25
23
  }
26
-
27
24
  function getIsLeaf(projectSchema, shapeSchema) {
28
25
  const leafMap = new Set();
29
26
  const shapesSeen = new Set();
30
-
31
27
  const collectLeaves = schema => {
32
28
  const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
33
29
  schema = shapeName ? (0, _refs.followRef)(projectSchema, schema) : schema;
34
30
  const key = (0, _schemaUtil.getStorageKey)(schema);
35
-
36
31
  if (key && isLeafTypeV3(projectSchema, schema)) {
37
32
  leafMap.add(key);
38
33
  }
39
-
40
34
  if (shapeName) {
41
35
  // Skip shapes we have already seen to avoid cycles
42
36
  if (shapesSeen.has(shapeName)) {
43
37
  return;
44
38
  }
45
-
46
39
  shapesSeen.add(shapeName);
47
40
  }
48
-
49
41
  const combo = schema.oneOf ?? schema.allOf;
50
-
51
42
  if (combo) {
52
43
  combo.map(collectLeaves);
53
44
  } else if (schema.properties) {
@@ -58,7 +49,6 @@ function getIsLeaf(projectSchema, shapeSchema) {
58
49
  collectLeaves(schema.items);
59
50
  }
60
51
  };
61
-
62
52
  collectLeaves(shapeSchema);
63
53
  return key => {
64
54
  // Remove locale suffix