@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.
- 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/dist/types/utils.js
CHANGED
|
@@ -55,27 +55,16 @@ exports.isShopifyServiceConfig = isShopifyServiceConfig;
|
|
|
55
55
|
exports.isTakeshapeResolver = isTakeshapeResolver;
|
|
56
56
|
exports.isUtilResolver = isUtilResolver;
|
|
57
57
|
exports.listCachedShapes = listCachedShapes;
|
|
58
|
-
|
|
59
58
|
var _util = require("@takeshape/util");
|
|
60
|
-
|
|
61
59
|
var _types = require("./types");
|
|
62
|
-
|
|
63
60
|
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
64
|
-
|
|
65
61
|
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
66
|
-
|
|
67
62
|
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
68
|
-
|
|
69
63
|
var _has = _interopRequireDefault(require("lodash/has"));
|
|
70
|
-
|
|
71
64
|
var _schemas = require("../schemas");
|
|
72
|
-
|
|
73
65
|
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
74
|
-
|
|
75
66
|
var _schemaUtil = require("../schema-util");
|
|
76
|
-
|
|
77
67
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
78
|
-
|
|
79
68
|
/** Resolver Type Utils **/
|
|
80
69
|
|
|
81
70
|
/**
|
|
@@ -84,15 +73,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
84
73
|
function isBasicResolver(resolver) {
|
|
85
74
|
return (0, _util.isRecord)(resolver) && (0, _isString.default)(resolver.name);
|
|
86
75
|
}
|
|
87
|
-
|
|
88
76
|
function isServiceResolver(resolver) {
|
|
89
77
|
return (0, _util.isRecord)(resolver) && (0, _isString.default)(resolver.name) && (0, _isString.default)(resolver.service);
|
|
90
78
|
}
|
|
91
|
-
|
|
92
79
|
function isComposeResolver(resolver) {
|
|
93
80
|
return Boolean((0, _isArray.default)(resolver === null || resolver === void 0 ? void 0 : resolver.compose) && resolver.compose.length && resolver.compose.every(isBasicResolver));
|
|
94
81
|
}
|
|
95
|
-
|
|
96
82
|
const {
|
|
97
83
|
definitions: {
|
|
98
84
|
takeshapeResolver,
|
|
@@ -103,252 +89,206 @@ const {
|
|
|
103
89
|
awsLambdaResolver
|
|
104
90
|
}
|
|
105
91
|
} = _schemas.latestSchemaJson;
|
|
106
|
-
|
|
107
92
|
function isTakeshapeResolver(resolver) {
|
|
108
93
|
return isBasicResolver(resolver) && takeshapeResolver.properties.name.enum.includes(resolver.name);
|
|
109
94
|
}
|
|
110
|
-
|
|
111
95
|
function isShapedbResolver(resolver) {
|
|
112
96
|
return isBasicResolver(resolver) && shapedbResolver.properties.name.enum.includes(resolver.name);
|
|
113
97
|
}
|
|
114
|
-
|
|
115
98
|
function isGraphqlResolver(resolver) {
|
|
116
99
|
return isBasicResolver(resolver) && graphqlResolver.properties.name.enum.includes(resolver.name);
|
|
117
100
|
}
|
|
118
|
-
|
|
119
101
|
function isRestResolver(resolver) {
|
|
120
102
|
return isBasicResolver(resolver) && restResolver.properties.name.enum.includes(resolver.name);
|
|
121
103
|
}
|
|
122
|
-
|
|
123
104
|
function isAwsLambdaResolver(resolver) {
|
|
124
105
|
return isBasicResolver(resolver) && awsLambdaResolver.properties.name.enum.includes(resolver.name);
|
|
125
106
|
}
|
|
126
|
-
|
|
127
107
|
function isUtilResolver(resolver) {
|
|
128
108
|
return isBasicResolver(resolver) && utilResolver.properties.name.enum.includes(resolver.name);
|
|
129
109
|
}
|
|
130
|
-
|
|
131
110
|
function isProjectSchemaWithServices(schema) {
|
|
132
111
|
return !(0, _isUndefined.default)(schema.services);
|
|
133
112
|
}
|
|
113
|
+
|
|
134
114
|
/** Directive Mapping Utils **/
|
|
135
115
|
|
|
136
116
|
/**
|
|
137
117
|
* Determine whether the ambiguous Directive structure is a DirectiveMappingMap
|
|
138
118
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
119
|
function isDirectiveMappingMap(maybeMap) {
|
|
142
120
|
return (0, _isPlainObject.default)(maybeMap) && Object.keys(maybeMap).length > 0;
|
|
143
121
|
}
|
|
122
|
+
|
|
144
123
|
/**
|
|
145
124
|
* Determine whether the ambiguous Directive structure is a DirectiveMappingArray
|
|
146
125
|
*/
|
|
147
|
-
|
|
148
|
-
|
|
149
126
|
function isDirectiveMappingArray(maybeArray) {
|
|
150
127
|
return (0, _isArray.default)(maybeArray) && (0, _isArray.default)(maybeArray[0]) && (0, _isString.default)(maybeArray[0][0]) && (0, _isArray.default)(maybeArray[0][1]);
|
|
151
128
|
}
|
|
129
|
+
|
|
152
130
|
/**
|
|
153
131
|
* Determine whether the ambiguous Directive structure is a DirectiveConfig array
|
|
154
132
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
133
|
function isDirectiveConfig(maybeConfig) {
|
|
158
134
|
return (0, _isArray.default)(maybeConfig) && (0, _isArray.default)(maybeConfig[0]) && (0, _isString.default)(maybeConfig[0][0]) && (0, _util.isRecord)(maybeConfig[0][1]);
|
|
159
135
|
}
|
|
136
|
+
|
|
160
137
|
/**
|
|
161
138
|
* Determine whether a ParameterSerializeOption is a content type serializer
|
|
162
139
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
140
|
function isParameterSerializeContentOptions(maybeContent) {
|
|
166
141
|
return Boolean(maybeContent.contentType);
|
|
167
142
|
}
|
|
143
|
+
|
|
168
144
|
/**
|
|
169
145
|
* Determine whether an unknown variable is a `ParameterOp`
|
|
170
146
|
*/
|
|
171
|
-
|
|
172
|
-
|
|
173
147
|
function isParameterOp(maybeOp) {
|
|
174
148
|
const op = maybeOp;
|
|
175
|
-
|
|
176
149
|
if (!op.path) {
|
|
177
150
|
return false;
|
|
178
151
|
}
|
|
179
|
-
|
|
180
152
|
return isParameterOpNested(op) || isParameterOpMapping(op) || isParameterOpValue(op) || isParameterOpOp(op);
|
|
181
153
|
}
|
|
154
|
+
|
|
182
155
|
/**
|
|
183
156
|
* Determine whether a `ParameterOp` is a `ParameterOpNested`
|
|
184
157
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
158
|
function isParameterOpNested(maybeOp) {
|
|
188
159
|
return Boolean(maybeOp.ops);
|
|
189
160
|
}
|
|
161
|
+
|
|
190
162
|
/**
|
|
191
163
|
* Determine whether a `ParameterOp` is a `ParameterOpMapping`
|
|
192
164
|
*/
|
|
193
|
-
|
|
194
|
-
|
|
195
165
|
function isParameterOpMapping(maybeOp) {
|
|
196
166
|
return Boolean(maybeOp.mapping);
|
|
197
167
|
}
|
|
168
|
+
|
|
198
169
|
/**
|
|
199
170
|
* Determine whether a `ParameterOp` is a `ParameterOpMapping`
|
|
200
171
|
*/
|
|
201
|
-
|
|
202
|
-
|
|
203
172
|
function isParameterOpValue(maybeOp) {
|
|
204
173
|
return Boolean(maybeOp.value);
|
|
205
174
|
}
|
|
175
|
+
|
|
206
176
|
/**
|
|
207
177
|
* Determine whether a `ParameterOp` is a `ParameterOpOp`
|
|
208
178
|
*/
|
|
209
|
-
|
|
210
|
-
|
|
211
179
|
function isParameterOpOp(maybeOp) {
|
|
212
180
|
const op = maybeOp;
|
|
213
|
-
|
|
214
181
|
if (!op.op) {
|
|
215
182
|
return false;
|
|
216
183
|
}
|
|
217
|
-
|
|
218
184
|
return !(isParameterOpNested(op) || isParameterOpMapping(op) || isParameterOpValue(op));
|
|
219
185
|
}
|
|
220
|
-
|
|
221
186
|
const {
|
|
222
187
|
definitions: {
|
|
223
188
|
parameterSerializeStyleOptionsForSearchParams,
|
|
224
189
|
parameterSerializeStyleOptionsForPathParams
|
|
225
190
|
}
|
|
226
191
|
} = _schemas.latestSchemaJson;
|
|
227
|
-
|
|
228
192
|
function isParameterSerializeStyleForSearchParams(maybeParam) {
|
|
229
193
|
return Boolean(maybeParam && parameterSerializeStyleOptionsForSearchParams.properties.style.enum.includes(maybeParam));
|
|
230
194
|
}
|
|
231
|
-
|
|
232
195
|
function isParameterSerializeStyleForPathParams(maybeParam) {
|
|
233
196
|
return Boolean(maybeParam && parameterSerializeStyleOptionsForPathParams.properties.style.enum.includes(maybeParam));
|
|
234
197
|
}
|
|
198
|
+
|
|
235
199
|
/**
|
|
236
200
|
* Determine whether a ParameterSerializeOption is a style serializer
|
|
237
201
|
*/
|
|
238
|
-
|
|
239
|
-
|
|
240
202
|
function isParameterSerializeStyleOptions(maybeStyle) {
|
|
241
203
|
return Boolean(maybeStyle.style);
|
|
242
204
|
}
|
|
243
|
-
/** Typeguards for different types of shape schemas **/
|
|
244
205
|
|
|
206
|
+
/** Typeguards for different types of shape schemas **/
|
|
245
207
|
|
|
246
208
|
function isRefSchema(propertySchema) {
|
|
247
209
|
return (0, _isString.default)(propertySchema['@ref']) || (0, _isString.default)(propertySchema.$ref);
|
|
248
210
|
}
|
|
249
|
-
|
|
250
211
|
function isRefSchemaLegacy(propertySchema) {
|
|
251
212
|
return (0, _isString.default)(propertySchema.$ref);
|
|
252
213
|
}
|
|
253
|
-
|
|
254
214
|
function isAllOfSchema(propertySchema) {
|
|
255
215
|
return (0, _isArray.default)(propertySchema.allOf);
|
|
256
216
|
}
|
|
257
|
-
|
|
258
217
|
function isExtendsSchema(propertySchema) {
|
|
259
218
|
return (0, _util.isRecord)(propertySchema) && (0, _isArray.default)(propertySchema.extends);
|
|
260
219
|
}
|
|
261
|
-
|
|
262
220
|
function isOneOfSchema(propertySchema) {
|
|
263
221
|
return (0, _isArray.default)(propertySchema.oneOf);
|
|
264
222
|
}
|
|
265
|
-
|
|
266
223
|
function isEnumSchema(obj) {
|
|
267
224
|
return (0, _isArray.default)(obj.enum);
|
|
268
225
|
}
|
|
269
|
-
|
|
270
226
|
function isArraySchema(propertySchema) {
|
|
271
227
|
return propertySchema.type === 'array' && (0, _util.isRecord)(propertySchema.items);
|
|
272
228
|
}
|
|
273
|
-
|
|
274
229
|
function isReturnShapeArraySchema(returnShape) {
|
|
275
230
|
return typeof returnShape === 'object' && returnShape.type === 'array';
|
|
276
231
|
}
|
|
277
|
-
|
|
278
232
|
function isObjectSchema(propertySchema) {
|
|
279
233
|
return (0, _util.isRecord)(propertySchema) && propertySchema.type === 'object' && (0, _util.isRecord)(propertySchema.properties);
|
|
280
234
|
}
|
|
235
|
+
|
|
281
236
|
/** Service Config Utils **/
|
|
282
237
|
|
|
283
238
|
/**
|
|
284
239
|
* Test all required props, currently:
|
|
285
240
|
* "name", "slug", "provider", "serviceType", "authenticationType"
|
|
286
241
|
*/
|
|
287
|
-
|
|
288
|
-
|
|
289
242
|
function isAnyServiceConfig(maybeConfig) {
|
|
290
243
|
return maybeConfig && (0, _isString.default)(maybeConfig.title) && (0, _isString.default)(maybeConfig.id) && (0, _isString.default)(maybeConfig.provider) && (0, _isString.default)(maybeConfig.serviceType) && (0, _isString.default)(maybeConfig.authenticationType);
|
|
291
244
|
}
|
|
292
|
-
|
|
293
245
|
function isGraphQLServiceConfig(maybeConfig) {
|
|
294
246
|
var _maybeConfig$options;
|
|
295
|
-
|
|
296
247
|
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && (0, _isString.default)((_maybeConfig$options = maybeConfig.options) === null || _maybeConfig$options === void 0 ? void 0 : _maybeConfig$options.endpoint);
|
|
297
248
|
}
|
|
298
|
-
|
|
299
249
|
function isRESTServiceConfig(maybeConfig) {
|
|
300
250
|
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'rest';
|
|
301
251
|
}
|
|
302
|
-
|
|
303
252
|
function isOpenAPIServiceConfig(maybeConfig) {
|
|
304
253
|
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'openapi';
|
|
305
254
|
}
|
|
306
|
-
|
|
307
255
|
function isShopifyServiceConfig(maybeShopify) {
|
|
308
256
|
return maybeShopify.provider === 'shopify';
|
|
309
257
|
}
|
|
310
|
-
|
|
311
258
|
function isEncryptedServiceConfig(maybeConfig) {
|
|
312
259
|
return isAnyServiceConfig(maybeConfig) && (0, _isString.default)(maybeConfig.authentication);
|
|
313
260
|
}
|
|
314
|
-
|
|
315
261
|
function isServiceConfigWithOAuth2Authentication(maybeServiceConfig) {
|
|
316
262
|
return isAnyServiceConfig(maybeServiceConfig) && isServiceAuthentication(maybeServiceConfig.authentication) && isOAuth2Authentication(maybeServiceConfig.authentication);
|
|
317
263
|
}
|
|
318
|
-
|
|
319
264
|
function isServiceConfigWithCustomAuthentication(maybeServiceConfig) {
|
|
320
265
|
return isAnyServiceConfig(maybeServiceConfig) && isServiceAuthentication(maybeServiceConfig.authentication) && isCustomAuthentication(maybeServiceConfig.authentication);
|
|
321
266
|
}
|
|
322
|
-
/** Authentication Utils **/
|
|
323
267
|
|
|
268
|
+
/** Authentication Utils **/
|
|
324
269
|
|
|
325
270
|
function isServiceAuthentication(maybeAuthentication) {
|
|
326
271
|
return maybeAuthentication === null || maybeAuthentication === void 0 ? void 0 : maybeAuthentication.type;
|
|
327
272
|
}
|
|
328
|
-
|
|
329
273
|
function isBearerAuthentication(authentication) {
|
|
330
274
|
return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'bearer';
|
|
331
275
|
}
|
|
332
|
-
|
|
333
276
|
function isBasicAuthentication(authentication) {
|
|
334
277
|
return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'basic';
|
|
335
278
|
}
|
|
336
|
-
|
|
337
279
|
function isSearchParamsAuthentication(authentication) {
|
|
338
280
|
return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'searchParams';
|
|
339
281
|
}
|
|
340
|
-
|
|
341
282
|
function isOAuth2Authentication(authentication) {
|
|
342
283
|
return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'oauth2';
|
|
343
284
|
}
|
|
344
|
-
|
|
345
285
|
function isOAuth2BearerAuthentication(authentication) {
|
|
346
286
|
return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'oauth2Bearer';
|
|
347
287
|
}
|
|
348
|
-
|
|
349
288
|
function isCustomAuthentication(authentication) {
|
|
350
289
|
return (authentication === null || authentication === void 0 ? void 0 : authentication.type) === 'custom';
|
|
351
290
|
}
|
|
291
|
+
|
|
352
292
|
/** Miscellaneous Utils **/
|
|
353
293
|
|
|
354
294
|
/**
|
|
@@ -356,60 +296,46 @@ function isCustomAuthentication(authentication) {
|
|
|
356
296
|
*
|
|
357
297
|
* @param argsSchema Any schema that may have an `args` property.
|
|
358
298
|
*/
|
|
359
|
-
|
|
360
|
-
|
|
361
299
|
const getArgsType = argsSchema => {
|
|
362
300
|
if ((0, _has.default)(argsSchema, '@args')) {
|
|
363
301
|
return _types.ArgsType['@args'];
|
|
364
302
|
}
|
|
365
|
-
|
|
366
303
|
if ((0, _has.default)(argsSchema, 'args')) {
|
|
367
304
|
return _types.ArgsType.args;
|
|
368
305
|
}
|
|
369
306
|
};
|
|
307
|
+
|
|
370
308
|
/**
|
|
371
309
|
* A utility to return the type of ref present on a schema.
|
|
372
310
|
*
|
|
373
311
|
* @param refSchema Any schema that may have a `ref` property.
|
|
374
312
|
*/
|
|
375
|
-
|
|
376
|
-
|
|
377
313
|
exports.getArgsType = getArgsType;
|
|
378
|
-
|
|
379
314
|
const getRefType = refSchema => {
|
|
380
315
|
if ((0, _has.default)(refSchema, '@ref')) {
|
|
381
316
|
return _types.RefType['@ref'];
|
|
382
317
|
}
|
|
383
|
-
|
|
384
318
|
if ((0, _has.default)(refSchema, '$ref')) {
|
|
385
319
|
return _types.RefType.$ref;
|
|
386
320
|
}
|
|
387
321
|
};
|
|
388
|
-
|
|
389
322
|
exports.getRefType = getRefType;
|
|
390
|
-
|
|
391
323
|
function isPropertySchemaWithRelationship(schema) {
|
|
392
324
|
var _schema$Resolver;
|
|
393
|
-
|
|
394
325
|
return ((_schema$Resolver = schema['@resolver']) === null || _schema$Resolver === void 0 ? void 0 : _schema$Resolver.name) === 'shapedb:getRelated';
|
|
395
326
|
}
|
|
396
|
-
|
|
397
327
|
function listCachedShapes(shapes) {
|
|
398
328
|
return Object.values(shapes).filter(_schemaUtil.isCachedShape);
|
|
399
329
|
}
|
|
400
|
-
|
|
401
330
|
function getCachedShapeMap(shapes) {
|
|
402
331
|
const results = {};
|
|
403
|
-
|
|
404
332
|
for (const shape of Object.values(shapes)) {
|
|
405
333
|
if ((0, _schemaUtil.isCachedShape)(shape)) {
|
|
406
334
|
results[shape.name] = shape;
|
|
407
335
|
}
|
|
408
336
|
}
|
|
409
|
-
|
|
410
337
|
return results;
|
|
411
338
|
}
|
|
412
|
-
|
|
413
339
|
function isMeshShape(shape) {
|
|
414
340
|
return Boolean(shape.joins);
|
|
415
341
|
}
|
package/dist/unions.js
CHANGED
|
@@ -9,34 +9,21 @@ exports.isUnionSchema = isUnionSchema;
|
|
|
9
9
|
exports.oneOfToObject = oneOfToObject;
|
|
10
10
|
exports.transformOneOf = transformOneOf;
|
|
11
11
|
exports.wrapOneOfObjects = exports.unwrapOneOfObjects = void 0;
|
|
12
|
-
|
|
13
12
|
var _refs = require("./refs");
|
|
14
|
-
|
|
15
13
|
var _util = require("@takeshape/util");
|
|
16
|
-
|
|
17
14
|
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
18
|
-
|
|
19
15
|
var _contentSchemaTransform = require("./content-schema-transform");
|
|
20
|
-
|
|
21
16
|
var _utils = require("./types/utils");
|
|
22
|
-
|
|
23
17
|
var _errors = require("@takeshape/errors");
|
|
24
|
-
|
|
25
18
|
var _schemaUtil = require("./schema-util");
|
|
26
|
-
|
|
27
19
|
var _templates = require("./template-shapes/templates");
|
|
28
|
-
|
|
29
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
-
|
|
31
21
|
function enumerateOneOfKeys(projectSchema, oneOf) {
|
|
32
22
|
const result = [];
|
|
33
|
-
|
|
34
23
|
for (const child of oneOf) {
|
|
35
24
|
const refItem = (0, _refs.getRef)(projectSchema, child);
|
|
36
|
-
|
|
37
25
|
if (refItem) {
|
|
38
26
|
const shapeName = (0, _refs.refItemToShapeName)(refItem);
|
|
39
|
-
|
|
40
27
|
if (projectSchema.shapes[shapeName]) {
|
|
41
28
|
const shapeId = projectSchema.shapes[shapeName].id;
|
|
42
29
|
result.push({
|
|
@@ -48,82 +35,68 @@ function enumerateOneOfKeys(projectSchema, oneOf) {
|
|
|
48
35
|
}
|
|
49
36
|
}
|
|
50
37
|
}
|
|
51
|
-
|
|
52
38
|
return result;
|
|
53
39
|
}
|
|
54
|
-
|
|
55
40
|
function getOneOf(schema) {
|
|
56
41
|
if (!schema.oneOf) {
|
|
57
42
|
throw new Error(`Expected ${JSON.stringify(schema)} to be a oneOf schema`);
|
|
58
43
|
}
|
|
59
|
-
|
|
60
44
|
return schema.oneOf;
|
|
61
45
|
}
|
|
62
|
-
|
|
63
46
|
function isUnionSchema(schema) {
|
|
64
47
|
var _schema$oneOf;
|
|
65
|
-
|
|
66
48
|
return Boolean((_schema$oneOf = schema.oneOf) === null || _schema$oneOf === void 0 ? void 0 : _schema$oneOf.every(_utils.isRefSchema));
|
|
67
49
|
}
|
|
68
|
-
|
|
69
50
|
function oneOfToObject(projectSchema, schema) {
|
|
70
51
|
const properties = {};
|
|
71
|
-
|
|
72
52
|
for (const {
|
|
73
53
|
propName,
|
|
74
54
|
propSchema: child
|
|
75
55
|
} of enumerateOneOfKeys(projectSchema, getOneOf(schema))) {
|
|
76
56
|
properties[propName] = child;
|
|
77
57
|
}
|
|
78
|
-
|
|
79
|
-
|
|
58
|
+
return {
|
|
59
|
+
...(0, _omit.default)(schema, 'oneOf'),
|
|
80
60
|
type: 'object',
|
|
81
61
|
properties
|
|
82
62
|
};
|
|
83
63
|
}
|
|
84
|
-
|
|
85
64
|
function formatKeys(keys) {
|
|
86
65
|
return keys.map(k => `"${k}"`).join(', ');
|
|
87
66
|
}
|
|
88
|
-
|
|
89
67
|
// eslint-disable-next-line max-params
|
|
90
68
|
const createUnwrapTransform = projectSchema => (obj, schema, name, shape, next) => {
|
|
91
69
|
if ((0, _util.isRecord)(obj)) {
|
|
92
70
|
const oneOfKeys = enumerateOneOfKeys(projectSchema, getOneOf(schema));
|
|
93
71
|
const objectKeys = Object.keys(obj);
|
|
94
|
-
|
|
95
72
|
if (objectKeys.length !== 1) {
|
|
96
73
|
const propNames = oneOfKeys.map(k => k.propName);
|
|
97
74
|
throw new _errors.BadDataError(`Object should only specify one of the following keys: ${formatKeys(propNames)}, but found keys: ${formatKeys(objectKeys)}`);
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
for (const {
|
|
101
77
|
propName,
|
|
102
78
|
shapeId,
|
|
103
79
|
propSchema
|
|
104
80
|
} of oneOfKeys) {
|
|
105
81
|
const propValue = obj[propName];
|
|
106
|
-
|
|
107
82
|
if ((0, _util.isRecord)(propValue)) {
|
|
108
83
|
const transformedPropValue = next(propValue, propSchema, name);
|
|
109
|
-
|
|
110
84
|
if ((0, _util.isRecord)(transformedPropValue)) {
|
|
111
|
-
return {
|
|
85
|
+
return {
|
|
86
|
+
...transformedPropValue,
|
|
112
87
|
_shapeId: shapeId
|
|
113
88
|
};
|
|
114
89
|
}
|
|
115
90
|
}
|
|
116
91
|
}
|
|
117
92
|
}
|
|
118
|
-
};
|
|
119
|
-
|
|
93
|
+
};
|
|
120
94
|
|
|
95
|
+
// eslint-disable-next-line max-params
|
|
121
96
|
exports.createUnwrapTransform = createUnwrapTransform;
|
|
122
|
-
|
|
123
97
|
const createWrapTransform = projectSchema => (obj, schema, name, shape, next) => {
|
|
124
98
|
if ((0, _util.isRecord)(obj) && typeof obj._shapeId === 'string') {
|
|
125
99
|
const shape = (0, _schemaUtil.getShapeById)(projectSchema, obj._shapeId);
|
|
126
|
-
|
|
127
100
|
if (shape) {
|
|
128
101
|
return {
|
|
129
102
|
[(0, _util.camelCase)(shape.name)]: next((0, _omit.default)(obj, '_shapeId'), shape.schema, name)
|
|
@@ -131,9 +104,7 @@ const createWrapTransform = projectSchema => (obj, schema, name, shape, next) =>
|
|
|
131
104
|
}
|
|
132
105
|
}
|
|
133
106
|
};
|
|
134
|
-
|
|
135
107
|
exports.createWrapTransform = createWrapTransform;
|
|
136
|
-
|
|
137
108
|
function transformOneOf(process) {
|
|
138
109
|
return (projectSchema, schema, obj) => {
|
|
139
110
|
const transform = (0, _contentSchemaTransform.getContentTransform)({
|
|
@@ -151,20 +122,19 @@ function transformOneOf(process) {
|
|
|
151
122
|
return transform(schema, obj);
|
|
152
123
|
};
|
|
153
124
|
}
|
|
125
|
+
|
|
154
126
|
/**
|
|
155
127
|
* Unwrap oneOf objects in "GraphQL oneOf" style wrapper objects
|
|
156
128
|
* See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
|
|
157
129
|
* Opposite of `wrapOneOfObjects`
|
|
158
130
|
*/
|
|
159
|
-
|
|
160
|
-
|
|
161
131
|
const unwrapOneOfObjects = transformOneOf(createUnwrapTransform);
|
|
132
|
+
|
|
162
133
|
/**
|
|
163
134
|
* Wrap oneOf objects in "GraphQL oneOf" style wrapper objects
|
|
164
135
|
* See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
|
|
165
136
|
* Opposite of `unwrapOneOfObjects`
|
|
166
137
|
*/
|
|
167
|
-
|
|
168
138
|
exports.unwrapOneOfObjects = unwrapOneOfObjects;
|
|
169
139
|
const wrapOneOfObjects = transformOneOf(createWrapTransform);
|
|
170
140
|
exports.wrapOneOfObjects = wrapOneOfObjects;
|
|
@@ -7,55 +7,43 @@ exports.getGetQueryIndexConfig = void 0;
|
|
|
7
7
|
exports.getIndexedServices = getIndexedServices;
|
|
8
8
|
exports.getListQueryIndexConfigs = void 0;
|
|
9
9
|
exports.serviceHasIndexedShapes = serviceHasIndexedShapes;
|
|
10
|
-
|
|
11
10
|
var _types = require("../types");
|
|
12
|
-
|
|
13
11
|
var _util = require("@takeshape/util");
|
|
14
|
-
|
|
15
12
|
var _services = require("../services");
|
|
16
|
-
|
|
17
13
|
var _schemaUtil = require("../schema-util");
|
|
18
|
-
|
|
19
14
|
var _refs = require("../refs");
|
|
20
|
-
|
|
21
15
|
function serviceHasIndexedShapes(schema, serviceId) {
|
|
22
16
|
for (const shape of Object.values(schema.shapes ?? {})) {
|
|
23
17
|
var _shape$loaders;
|
|
24
|
-
|
|
25
18
|
const indexingEnabled = (0, _schemaUtil.isCachedShape)(shape);
|
|
26
19
|
const listConfigs = (_shape$loaders = shape.loaders) === null || _shape$loaders === void 0 ? void 0 : _shape$loaders.list;
|
|
27
|
-
|
|
28
20
|
if (indexingEnabled && listConfigs) {
|
|
29
21
|
for (const {
|
|
30
22
|
query: queryRef
|
|
31
23
|
} of (0, _util.ensureArray)(listConfigs)) {
|
|
32
24
|
const resolved = (0, _refs.getQuery)(schema, queryRef);
|
|
33
|
-
|
|
34
25
|
if (resolved && (0, _types.isServiceResolver)(resolved.query.resolver) && resolved.query.resolver.service === serviceId) {
|
|
35
26
|
return true;
|
|
36
27
|
}
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
}
|
|
40
|
-
|
|
41
31
|
return false;
|
|
42
32
|
}
|
|
43
|
-
|
|
44
33
|
function getIndexedServices(projectSchema, configs) {
|
|
45
34
|
return (0, _util.ensureArray)(configs).reduce((services, queryConfig) => {
|
|
46
35
|
const resolved = queryConfig !== null && queryConfig !== void 0 && queryConfig.query ? (0, _refs.getQuery)(projectSchema, queryConfig.query) : undefined;
|
|
47
36
|
return resolved !== null && resolved !== void 0 && resolved.query ? [...services, ...(0, _services.getResolverServices)(resolved.query.resolver)] : services;
|
|
48
37
|
}, []);
|
|
49
38
|
}
|
|
50
|
-
|
|
51
39
|
function flattenListQueryConfigs(base, queryConfig, maybeConfigArray) {
|
|
52
|
-
return maybeConfigArray && (0, _util.ensureArray)(maybeConfigArray).flatMap(config => (0, _util.ensureArray)(config.args).map(args => ({
|
|
40
|
+
return maybeConfigArray && (0, _util.ensureArray)(maybeConfigArray).flatMap(config => (0, _util.ensureArray)(config.args).map(args => ({
|
|
41
|
+
...base,
|
|
53
42
|
...queryConfig,
|
|
54
43
|
...config,
|
|
55
44
|
args
|
|
56
45
|
})));
|
|
57
46
|
}
|
|
58
|
-
|
|
59
47
|
function getQueryIndexConfigHelper(op) {
|
|
60
48
|
return ({
|
|
61
49
|
shapes
|
|
@@ -64,19 +52,15 @@ function getQueryIndexConfigHelper(op) {
|
|
|
64
52
|
cache,
|
|
65
53
|
loaders
|
|
66
54
|
} = shapes[shapeName] ?? {};
|
|
67
|
-
|
|
68
55
|
if (cache && loaders) {
|
|
69
56
|
const idField = cache.idField ?? 'id';
|
|
70
|
-
|
|
71
57
|
if (op === 'list') {
|
|
72
58
|
return flattenListQueryConfigs({
|
|
73
59
|
shapeName,
|
|
74
60
|
idField
|
|
75
61
|
}, cache.fragment, loaders.list);
|
|
76
62
|
}
|
|
77
|
-
|
|
78
63
|
const queryConfig = loaders.get;
|
|
79
|
-
|
|
80
64
|
if (queryConfig) {
|
|
81
65
|
return {
|
|
82
66
|
idField,
|
|
@@ -88,7 +72,6 @@ function getQueryIndexConfigHelper(op) {
|
|
|
88
72
|
}
|
|
89
73
|
};
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
const getListQueryIndexConfigs = getQueryIndexConfigHelper('list');
|
|
93
76
|
exports.getListQueryIndexConfigs = getListQueryIndexConfigs;
|
|
94
77
|
const getGetQueryIndexConfig = getQueryIndexConfigHelper('get');
|
|
@@ -4,17 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.hasCycle = hasCycle;
|
|
7
|
-
|
|
8
7
|
var _refs = require("../refs");
|
|
9
|
-
|
|
10
8
|
var _util = require("@takeshape/util");
|
|
11
|
-
|
|
12
9
|
function immutableSetAdd(set, str) {
|
|
13
10
|
const result = new Set(set);
|
|
14
11
|
result.add(str);
|
|
15
12
|
return result;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
/**
|
|
19
15
|
* Use a basic depth-first search to determine whether a schema contains a cycle
|
|
20
16
|
*/
|
|
@@ -23,46 +19,36 @@ function hasCycle(projectSchema, schema, predicate = (0, _util.value)(true)) {
|
|
|
23
19
|
if (!predicate(projectSchema, schema, shapeName, propName)) {
|
|
24
20
|
return false;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
const refItem = (0, _refs.getRef)(projectSchema, schema);
|
|
28
|
-
|
|
29
23
|
if (refItem) {
|
|
30
|
-
const refShape = (0, _refs.refItemToShape)(projectSchema, refItem);
|
|
24
|
+
const refShape = (0, _refs.refItemToShape)(projectSchema, refItem);
|
|
31
25
|
|
|
26
|
+
// If we have a refItem, but no shape, this is a dangling ref and has no cycles
|
|
32
27
|
if (!refShape) {
|
|
33
28
|
return false;
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
if (shapesSeen.has(refShape.name)) {
|
|
37
31
|
return true;
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
return hasCycleHelper(refShape.schema, immutableSetAdd(shapesSeen, refShape.name), refShape.name);
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
const combo = schema.oneOf ?? schema.allOf ?? schema.extends;
|
|
44
|
-
|
|
45
36
|
if (combo) {
|
|
46
37
|
return combo.some(childSchema => hasCycleHelper(childSchema, shapesSeen, shapeName, propName));
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
if (schema.items) {
|
|
50
40
|
return hasCycleHelper(schema.items, shapesSeen, shapeName, propName);
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
const {
|
|
54
43
|
properties
|
|
55
44
|
} = schema;
|
|
56
|
-
|
|
57
45
|
if (properties) {
|
|
58
46
|
return Object.keys(properties).some(name => {
|
|
59
47
|
const propSchema = properties[name];
|
|
60
48
|
return hasCycleHelper(propSchema, shapesSeen, shapeName, name);
|
|
61
49
|
});
|
|
62
50
|
}
|
|
63
|
-
|
|
64
51
|
return false;
|
|
65
52
|
};
|
|
66
|
-
|
|
67
53
|
return hasCycleHelper(schema);
|
|
68
54
|
}
|