@takeshape/schema 8.36.2 → 8.38.2

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 (43) hide show
  1. package/es/flatten-templates.js +26 -0
  2. package/es/index.js +2 -1
  3. package/es/layers/layers.js +1 -1
  4. package/es/layers/refs.js +1 -1
  5. package/es/refs.js +74 -2
  6. package/es/schema-util.js +28 -17
  7. package/es/template-shapes/index.js +35 -0
  8. package/es/template-shapes/templates.js +379 -0
  9. package/es/template-shapes/types.js +1 -0
  10. package/es/template-shapes/where.js +501 -0
  11. package/es/validate.js +2 -2
  12. package/lib/flatten-templates.d.ts +3 -0
  13. package/lib/flatten-templates.d.ts.map +1 -0
  14. package/lib/flatten-templates.js +39 -0
  15. package/lib/index.d.ts +1 -0
  16. package/lib/index.d.ts.map +1 -1
  17. package/lib/index.js +14 -0
  18. package/lib/layers/layers.js +3 -3
  19. package/lib/layers/refs.js +2 -2
  20. package/lib/refs.d.ts +26 -1
  21. package/lib/refs.d.ts.map +1 -1
  22. package/lib/refs.js +94 -11
  23. package/lib/schema-util.d.ts +7 -6
  24. package/lib/schema-util.d.ts.map +1 -1
  25. package/lib/schema-util.js +41 -29
  26. package/lib/template-shapes/index.d.ts +8 -0
  27. package/lib/template-shapes/index.d.ts.map +1 -0
  28. package/lib/template-shapes/index.js +46 -0
  29. package/lib/template-shapes/templates.d.ts +29 -0
  30. package/lib/template-shapes/templates.d.ts.map +1 -0
  31. package/lib/template-shapes/templates.js +427 -0
  32. package/lib/template-shapes/types.d.ts +10 -0
  33. package/lib/template-shapes/types.d.ts.map +1 -0
  34. package/lib/template-shapes/types.js +5 -0
  35. package/lib/template-shapes/where.d.ts +39 -0
  36. package/lib/template-shapes/where.d.ts.map +1 -0
  37. package/lib/template-shapes/where.js +534 -0
  38. package/lib/validate.js +1 -1
  39. package/package.json +4 -4
  40. package/es/template-shapes.js +0 -79
  41. package/lib/template-shapes.d.ts +0 -32
  42. package/lib/template-shapes.d.ts.map +0 -1
  43. package/lib/template-shapes.js +0 -101
@@ -0,0 +1,26 @@
1
+ import { resolveTemplate, isValidTemplate } from './template-shapes';
2
+ import { getAllRefs } from './schema-util';
3
+ import set from 'lodash/set';
4
+ import { deepClone } from '@takeshape/util';
5
+ export function flattenTemplates(projectSchema) {
6
+ const templateRefs = getAllRefs(projectSchema, ref => Boolean(ref.template));
7
+
8
+ if (!templateRefs.length) {
9
+ return projectSchema;
10
+ }
11
+
12
+ const newSchema = deepClone(projectSchema);
13
+
14
+ for (const ref of templateRefs) {
15
+ if (ref.template && isValidTemplate(ref.template)) {
16
+ const {
17
+ shapeName,
18
+ dependencies
19
+ } = resolveTemplate(projectSchema, ref.template, ref.typeName);
20
+ set(newSchema, ref.path, shapeName);
21
+ Object.assign(newSchema.shapes, dependencies);
22
+ }
23
+ }
24
+
25
+ return newSchema;
26
+ }
package/es/index.js CHANGED
@@ -22,4 +22,5 @@ export * from './unions';
22
22
  export * from './enum';
23
23
  export * from './patterns';
24
24
  export * from './types/types';
25
- export * from './types/utils';
25
+ export * from './types/utils';
26
+ export * from './flatten-templates';
@@ -5,7 +5,7 @@ import { getArgsReferenceWithPath, getRefOrItemsRef, dereferenceSchema, parseRet
5
5
  import { isAllOfSchema, isObjectSchema, isOneOfSchema, isRefSchema } from './type-utils';
6
6
  import { visitSchemaProperties } from './visitor';
7
7
  import set from 'lodash/set';
8
- import { parseTemplateShape } from '../template-shapes';
8
+ import { parseTemplateShape } from '../refs';
9
9
  const layerDefaults = {
10
10
  namespace: '',
11
11
  visibility: []
package/es/layers/refs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { isAllOfSchema, isOneOfSchema, isRefSchema } from './type-utils';
2
- import { parseTemplateShape } from '../template-shapes';
2
+ import { parseTemplateShape } from '../refs';
3
3
  import assign from 'lodash/fp/assign';
4
4
  import omit from 'lodash/fp/omit';
5
5
  import { mergeWithArrayConcat } from '@takeshape/util';
package/es/refs.js CHANGED
@@ -1,9 +1,81 @@
1
- import { getRefType, isAllOfSchema, isOneOfSchema, isRefSchema, isRefSchemaLegacy } from './types/utils';
2
- import { parseTemplateShape } from './template-shapes';
1
+ import { getRefType, isAllOfSchema, isOneOfSchema, isRefSchema, isRefSchemaLegacy } from './types';
3
2
  import get from 'lodash/get';
4
3
  import assign from 'lodash/fp/assign';
5
4
  import omit from 'lodash/fp/omit';
6
5
  import { getServiceNamespace, getServiceNamespaces } from './services';
6
+ const templateShapeRegex = /^(\w+)<([\w:-]+)>$/;
7
+ /**
8
+ * Parse a template like `PaginatedList<Post>` and return both the template and the shape name.
9
+ */
10
+
11
+ export function parseTemplateShape(shapeExpression) {
12
+ const matches = templateShapeRegex.exec(shapeExpression);
13
+
14
+ if (matches) {
15
+ return {
16
+ shapeName: matches[2],
17
+ template: matches[1]
18
+ };
19
+ }
20
+
21
+ return {
22
+ shapeName: shapeExpression,
23
+ template: undefined
24
+ };
25
+ }
26
+ export function parseReturnShape(projectSchema, shape) {
27
+ if (typeof shape === 'object') {
28
+ if (isRefSchema(shape.items)) {
29
+ const ref = getRef(projectSchema, shape.items);
30
+
31
+ if (!ref) {
32
+ throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid ref`);
33
+ }
34
+
35
+ return {
36
+ isArray: true,
37
+ ref,
38
+ shapeName: refItemToShapeName(ref)
39
+ };
40
+ }
41
+
42
+ if (typeof shape.items.type !== 'string') {
43
+ throw new Error(`Could not parse ${JSON.stringify(shape.items)}: invalid type`);
44
+ }
45
+
46
+ return {
47
+ isArray: true,
48
+ shapeName: shape.items.type
49
+ };
50
+ }
51
+
52
+ const ref = refExpressionToRefItem(projectSchema, shape);
53
+ const shapeName = refItemToShapeName(ref);
54
+ return {
55
+ isArray: false,
56
+ shapeName,
57
+ ref,
58
+ template: ref.template
59
+ };
60
+ }
61
+ /**
62
+ * Create a template string like `PaginatedList<Post>` from a template and shape name.
63
+ */
64
+
65
+ export function createTemplateShapeName(template, shapeName) {
66
+ return `${template}<${shapeName}>`;
67
+ }
68
+ /**
69
+ * If the string is a template like `PaginatedList<Post>`, return the shape name,
70
+ * in this case `Post`. Otherwise return the input.
71
+ */
72
+
73
+ export const untemplate = input => {
74
+ return parseTemplateShape(input).shapeName;
75
+ };
76
+ export function getFlattenedTemplateShapeName(shapeName, template) {
77
+ return `${shapeName}${template ?? ''}`;
78
+ }
7
79
 
8
80
  function $refToPath(ref) {
9
81
  return ref.substr(2).split('/');
package/es/schema-util.js CHANGED
@@ -17,10 +17,9 @@ import { defaultWorkflow, getStatusField } from './workflows';
17
17
  import { CURRENT_API_VERSION, CURRENT_SCHEMA_VERSION } from './versions';
18
18
  import { workflowsEnabled } from './api-version';
19
19
  import { builtInShapes, builtInForms } from './builtin-schema';
20
- import { createTemplateShapeName, parseReturnShape } from './template-shapes';
21
20
  import { getArgsType, isBasicResolver, isObjectSchema, isAllOfSchema, isRefSchema, isOneOfSchema } from './types/utils';
22
21
  import { getStoredServiceConfig } from './services';
23
- import { followRef, getRef, getRefOrItemsRef, getRefShapeName, getRefWithPath, omitRefAndExtend, refExpressionToRefItem, refItemToShape, refItemToShapeName, refItemToShapeSchema } from './refs';
22
+ import { createTemplateShapeName, followRef, getRef, getRefOrItemsRef, getRefShapeName, getRefWithPath, omitRefAndExtend, parseReturnShape, refExpressionToRefItem, refItemToShape, refItemToShapeName, refItemToShapeSchema } from './refs';
24
23
  import isEqual from 'lodash/isEqual';
25
24
  import { isUnionSchema } from './unions';
26
25
  export const SERVICE_OBJECT_PATTERN_NAME = 'pattern:service-object';
@@ -521,8 +520,8 @@ export function getArgsReference(projectSchema, argsSchema) {
521
520
  return refExpressionToRefItem(projectSchema, args);
522
521
  }
523
522
  }
524
- export function getArgsReferenceWithPath(projectSchema, argsSchema, schemaPath = []) {
525
- const refItem = getArgsReference(projectSchema, argsSchema);
523
+ export function getArgsReferenceWithPath(context, argsSchema, schemaPath = []) {
524
+ const refItem = getArgsReference(context, argsSchema);
526
525
 
527
526
  if (refItem) {
528
527
  const argsType = getArgsType(argsSchema);
@@ -531,14 +530,14 @@ export function getArgsReferenceWithPath(projectSchema, argsSchema, schemaPath =
531
530
  };
532
531
  }
533
532
  }
534
- export function getArgsShapeSchema(projectSchema, argsSchema) {
533
+ export function getArgsShapeSchema(context, argsSchema) {
535
534
  const args = argsSchema['@args'] ?? argsSchema.args;
536
535
 
537
536
  if (args && typeof args === 'string') {
538
- const refItem = getArgsReference(projectSchema, argsSchema);
537
+ const refItem = getArgsReference(context, argsSchema);
539
538
 
540
539
  if (refItem) {
541
- return refItemToShapeSchema(projectSchema, refItem);
540
+ return refItemToShapeSchema(context, refItem);
542
541
  }
543
542
  } else if (args) {
544
543
  return args;
@@ -648,22 +647,25 @@ export function projectSchemaToJSONSchema(projectSchema) {
648
647
  definitions
649
648
  };
650
649
  }
651
- export function getShapeDependencies(projectSchema, shape) {
650
+ export function getShapeDependencies(projectSchema, shape, predicate) {
652
651
  const shapeNames = new Set();
653
652
 
654
653
  const findDependencies = schema => {
655
654
  schema = schema.items ?? schema;
656
- const refItem = getRef(projectSchema, schema);
657
655
 
658
- if (refItem) {
659
- const refShape = refItemToShape(projectSchema, refItem);
656
+ if (!predicate || predicate(schema)) {
657
+ const refItem = getRef(projectSchema, schema);
658
+
659
+ if (refItem) {
660
+ const refShape = refItemToShape(projectSchema, refItem);
660
661
 
661
- if (refShape && !shapeNames.has(refShape.name)) {
662
- shapeNames.add(refShape.name);
663
- findDependencies(dereferenceSchema(projectSchema, refShape.schema));
662
+ if (refShape && !shapeNames.has(refShape.name)) {
663
+ shapeNames.add(refShape.name);
664
+ findDependencies(dereferenceSchema(projectSchema, refShape.schema));
665
+ }
666
+ } else if (isObjectSchema(schema) || isAllOfSchema(schema) || isOneOfSchema(schema)) {
667
+ visitSchemaProperties(schema, [], findDependencies);
664
668
  }
665
- } else if (isObjectSchema(schema) || isAllOfSchema(schema) || isOneOfSchema(schema)) {
666
- visitSchemaProperties(schema, [], findDependencies);
667
669
  }
668
670
  };
669
671
 
@@ -1222,4 +1224,13 @@ export function findShapeFormConfig(projectSchema, shapeName, formName) {
1222
1224
  export const getDefaultMutationName = (shapeName, resolver) => {
1223
1225
  const action = resolver.substring(resolver.indexOf(':') + 1);
1224
1226
  return `${action}${shapeName}`;
1225
- };
1227
+ };
1228
+ export function createShape(name, schema, rest) {
1229
+ return {
1230
+ name,
1231
+ id: name,
1232
+ title: name,
1233
+ schema,
1234
+ ...rest
1235
+ };
1236
+ }
@@ -0,0 +1,35 @@
1
+ import { CreateArgs, CreateResult, DeleteArgs, DeleteResult, DuplicateArgs, DuplicateResult, PaginatedList, SearchResults, TSGetArgs, TSGetSingletonArgs, TSListArgs, TSSearchArgs, UpdateArgs, UpdateResult } from './templates';
2
+ const templateMappings = {
3
+ TSGetArgs,
4
+ TSGetSingletonArgs,
5
+ TSListArgs,
6
+ TSSearchArgs,
7
+ CreateArgs,
8
+ UpdateArgs,
9
+ DuplicateArgs,
10
+ DeleteArgs,
11
+ PaginatedList,
12
+ SearchResults,
13
+ CreateResult,
14
+ UpdateResult,
15
+ DuplicateResult,
16
+ DeleteResult
17
+ };
18
+ export function resolveTemplate(projectSchema, templateName, shapeName) {
19
+ const mapping = templateMappings[templateName];
20
+
21
+ if (!mapping) {
22
+ throw new Error(`Invalid shape template ${templateName}`);
23
+ }
24
+
25
+ return mapping({
26
+ projectSchema
27
+ }, projectSchema.shapes[shapeName]);
28
+ }
29
+ /**
30
+ * Check if a string is a known template such as `PaginatedList`
31
+ */
32
+
33
+ export function isValidTemplate(template) {
34
+ return Boolean(templateMappings[template]);
35
+ }
@@ -0,0 +1,379 @@
1
+ import { listTypePrefix } from '../migration';
2
+ import { isDefined, pascalCase } from '@takeshape/util';
3
+ import keyBy from 'lodash/keyBy';
4
+ import { createShape, getShapeDependencies, mergeSchemaProperties } from '../schema-util';
5
+ import { getFlattenedTemplateShapeName, getRefShapeName } from '../refs';
6
+ import { getWhereSearchArg } from './where';
7
+ const CREATE = 'create';
8
+ const UPDATE = 'update';
9
+ const DELETE = 'delete';
10
+ const DUPLICATE = 'duplicate';
11
+ export const TSGetArgs = getIDQueryArgs('TSGetArgs');
12
+ export const TSGetSingletonArgs = getIDQueryArgs('TSGetSingletonArgs');
13
+ export const TSListArgs = getShapeListQueryArgs('TSListArgs', true);
14
+ export const TSSearchArgs = getShapeListQueryArgs('TSSearchArgs', false);
15
+ export const CreateArgs = getMutationArgs('CreateArgs', CREATE);
16
+ export const UpdateArgs = getMutationArgs('UpdateArgs', UPDATE);
17
+ export const DuplicateArgs = getMutationArgs('DuplicateArgs', DUPLICATE);
18
+ export const DeleteArgs = getMutationArgs('DeleteArgs', DELETE);
19
+ export const PaginatedList = getPaginatedListShape;
20
+ export const SearchResults = getSearchResultsShape;
21
+ export const CreateResult = getMutationResultType(CREATE);
22
+ export const UpdateResult = getMutationResultType(UPDATE);
23
+ export const DuplicateResult = getMutationResultType(DUPLICATE);
24
+ export const DeleteResult = getMutationResultType(DELETE);
25
+ export const TSSearchSortInput = createShape('TSSearchSortInput', {
26
+ type: 'object',
27
+ properties: {
28
+ field: {
29
+ type: 'string'
30
+ },
31
+ order: {
32
+ type: 'string',
33
+ description: '"asc" for ascending or "desc" for descending'
34
+ }
35
+ },
36
+ required: ['field', 'order']
37
+ });
38
+ export const commonSearchProps = {
39
+ terms: {
40
+ type: 'string'
41
+ },
42
+ from: {
43
+ type: 'integer',
44
+ description: 'The offset from the first result you want to fetch.'
45
+ },
46
+ size: {
47
+ type: 'integer',
48
+ description: 'The maximum number of items to return.'
49
+ },
50
+ filter: {
51
+ type: 'object',
52
+ description: 'An elasticsearch style filter. Overrides onlyEnabled.'
53
+ },
54
+ sort: {
55
+ type: 'array',
56
+ description: 'An list of fields to sort by.',
57
+ items: {
58
+ '@ref': `local:${TSSearchSortInput.name}`
59
+ }
60
+ }
61
+ };
62
+ export const localeProps = {
63
+ type: 'object',
64
+ properties: {
65
+ locale: {
66
+ type: 'string'
67
+ },
68
+ enableLocaleFallback: {
69
+ type: 'boolean',
70
+ default: true
71
+ }
72
+ }
73
+ };
74
+ export const termsProps = {
75
+ type: 'object',
76
+ properties: {
77
+ terms: {
78
+ type: 'string'
79
+ }
80
+ }
81
+ };
82
+ export const ContentStructureInput = createShape('ContentStructureInput', {
83
+ type: 'object',
84
+ properties: {
85
+ path: {
86
+ type: 'string',
87
+ description: 'A deep path to the array being updated (e.g. a.b[1].c).'
88
+ },
89
+ structure: {
90
+ type: 'array',
91
+ description: 'An array where the indices represent the to index, and the values represent the from index.' + 'For example to transform ["a","b","c","d"] into ["c","a"], this value would be [2,0].',
92
+ items: {
93
+ type: 'integer'
94
+ }
95
+ }
96
+ },
97
+ required: ['path']
98
+ }, {
99
+ description: 'Describes a structural update to an array of data.'
100
+ });
101
+ export function getPaginatedListShape(context, shape) {
102
+ const shapeName = `${shape.name}${listTypePrefix}`;
103
+ return {
104
+ shapeName,
105
+ dependencies: {
106
+ [shapeName]: createShape(shapeName, {
107
+ type: 'object',
108
+ properties: {
109
+ items: {
110
+ type: 'array',
111
+ items: {
112
+ '@ref': `local:${shape.name}`
113
+ }
114
+ },
115
+ total: {
116
+ type: 'integer'
117
+ }
118
+ },
119
+ required: ['items', 'total']
120
+ })
121
+ }
122
+ };
123
+ }
124
+ export function getSearchResultsShape(context, shape) {
125
+ const shapeName = `${shape.name}SearchResults`;
126
+ return {
127
+ shapeName,
128
+ dependencies: {
129
+ [shapeName]: createShape(shapeName, {
130
+ type: 'object',
131
+ properties: {
132
+ results: {
133
+ type: 'array',
134
+ items: {
135
+ '@ref': `local:${shape.name}`
136
+ }
137
+ },
138
+ total: {
139
+ type: 'integer'
140
+ }
141
+ },
142
+ required: ['results', 'total']
143
+ }, {
144
+ description: `${shape.name} search results`
145
+ })
146
+ }
147
+ };
148
+ }
149
+ const contentStructureFields = {
150
+ type: 'object',
151
+ properties: {
152
+ structure: {
153
+ type: 'array',
154
+ items: {
155
+ '@ref': 'local:ContentStructureInput'
156
+ }
157
+ }
158
+ }
159
+ };
160
+ const idSchema = {
161
+ type: 'object',
162
+ properties: {
163
+ _id: {
164
+ type: 'string'
165
+ }
166
+ },
167
+ required: ['_id']
168
+ };
169
+
170
+ function rewriteSchema(shapeSchema) {
171
+ return JSON.parse(JSON.stringify(shapeSchema), (key, value) => {
172
+ var _value$required;
173
+
174
+ // Remove required
175
+ if (typeof value === 'object' && value.type === 'object' && (_value$required = value.required) !== null && _value$required !== void 0 && _value$required.length) {
176
+ delete value.required;
177
+ } // Remove default
178
+
179
+
180
+ if (typeof value === 'object' && value.type && value.default) {
181
+ delete value.default;
182
+ }
183
+
184
+ return value;
185
+ });
186
+ }
187
+
188
+ export function getIDQueryArgs(templateName) {
189
+ return (context, shape) => {
190
+ var _shape$model;
191
+
192
+ const schema = ((_shape$model = shape.model) === null || _shape$model === void 0 ? void 0 : _shape$model.type) !== 'single' ? mergeSchemaProperties(idSchema, localeProps) : localeProps;
193
+ const shapeName = getFlattenedTemplateShapeName(shape.name, templateName);
194
+ return {
195
+ shapeName,
196
+ dependencies: {
197
+ [shapeName]: createShape(shapeName, schema)
198
+ }
199
+ };
200
+ };
201
+ }
202
+
203
+ function mergeObjectSchemas(...args) {
204
+ return args.filter(isDefined).reduce(mergeSchemaProperties, {
205
+ type: 'object',
206
+ properties: {}
207
+ });
208
+ }
209
+
210
+ export function getMutationArgs(templateName, verb) {
211
+ return ({
212
+ projectSchema
213
+ }, shape) => {
214
+ const addLocale = verb === UPDATE || verb === DUPLICATE;
215
+ const addStructure = verb === UPDATE;
216
+ const inputName = pascalCase([verb, shape.name, 'input']);
217
+ const isSingleton = shape.model && shape.model.type === 'single';
218
+ const requireId = !isSingleton && (verb === UPDATE || verb === DELETE || verb === DUPLICATE);
219
+ const isUpdate = verb === UPDATE || verb === DUPLICATE;
220
+ const inputShape = createShape(inputName, mergeObjectSchemas(requireId ? idSchema : undefined, verb !== DELETE ? isUpdate ? rewriteSchema(shape.schema) : shape.schema : undefined), {
221
+ description: `${verb} ${shape.name} input`
222
+ });
223
+ const argsShapeName = getFlattenedTemplateShapeName(shape.name, templateName);
224
+ const argsShape = createShape(argsShapeName, mergeObjectSchemas({
225
+ type: 'object',
226
+ properties: {
227
+ input: {
228
+ '@ref': `local:${inputShape.name}`
229
+ },
230
+ clientMutationId: {
231
+ type: 'string'
232
+ }
233
+ },
234
+ required: ['input']
235
+ }, addStructure ? contentStructureFields : undefined, addLocale ? localeProps : undefined));
236
+
237
+ const getInputShapeName = shapeName => isUpdate ? `${shapeName}PartialInput` : `${shapeName}Input`;
238
+
239
+ return {
240
+ shapeName: argsShapeName,
241
+ dependencies: {
242
+ [inputName]: inputShape,
243
+ [argsShapeName]: argsShape,
244
+ ...(verb !== DELETE && keyBy(getShapeDependencies(projectSchema, shape, propSchema => {
245
+ if (!propSchema['@resolver']) {
246
+ return false;
247
+ }
248
+
249
+ const shapeName = getRefShapeName(projectSchema, propSchema);
250
+
251
+ if (shapeName) {
252
+ return !projectSchema.shapes[getInputShapeName(shapeName)];
253
+ }
254
+
255
+ return true;
256
+ }).map(shapeName => {
257
+ const shape = projectSchema.shapes[shapeName];
258
+ const name = getInputShapeName(shapeName);
259
+ return { ...shape,
260
+ name,
261
+ id: name,
262
+ schema: isUpdate ? rewriteSchema(shape.schema) : shape.schema
263
+ };
264
+ }), 'name')),
265
+ ...(addStructure ? {
266
+ ContentStructureInput
267
+ } : {})
268
+ }
269
+ };
270
+ };
271
+ }
272
+ export function getMutationResultType(verb) {
273
+ return (context, shape) => {
274
+ const shapeName = pascalCase([verb, shape.name, 'result']);
275
+ const result = verb === DELETE ? {
276
+ type: 'boolean'
277
+ } : {
278
+ '@ref': `local:${shape.name}`
279
+ };
280
+ return {
281
+ shapeName,
282
+ dependencies: {
283
+ [shapeName]: createShape(shapeName, {
284
+ type: 'object',
285
+ properties: {
286
+ clientMutationId: {
287
+ type: 'string'
288
+ },
289
+ result
290
+ }
291
+ })
292
+ }
293
+ };
294
+ };
295
+ }
296
+ export const commonSearchArgs = {
297
+ type: 'object',
298
+ properties: {
299
+ terms: {
300
+ type: 'string'
301
+ },
302
+ from: {
303
+ type: 'integer',
304
+ description: 'The offset from the first result you want to fetch.'
305
+ },
306
+ size: {
307
+ type: 'integer',
308
+ description: 'The maximum number of items to return.'
309
+ },
310
+ filter: {
311
+ type: 'object',
312
+ description: 'An elasticsearch style filter. Overrides onlyEnabled.'
313
+ },
314
+ sort: {
315
+ type: 'array',
316
+ description: 'An list of fields to sort by.',
317
+ items: {
318
+ '@ref': `local:${TSSearchSortInput.name}`
319
+ }
320
+ }
321
+ }
322
+ };
323
+ const legacyListArgs = {
324
+ type: 'object',
325
+ properties: {
326
+ onlyEnabled: {
327
+ type: 'boolean',
328
+ default: true,
329
+ description: 'Filter out content that is not enabled. Defaults to true.'
330
+ }
331
+ }
332
+ };
333
+ const shapeFilterProps = {
334
+ type: 'object',
335
+ properties: {
336
+ shapeNames: {
337
+ type: 'array',
338
+ items: {
339
+ type: 'string'
340
+ }
341
+ },
342
+ shapeIds: {
343
+ type: 'array',
344
+ items: {
345
+ type: 'string'
346
+ }
347
+ },
348
+ contentTypeNames: {
349
+ type: 'array',
350
+ items: {
351
+ type: 'string'
352
+ }
353
+ },
354
+ contentTypeIds: {
355
+ type: 'array',
356
+ items: {
357
+ type: 'string'
358
+ }
359
+ }
360
+ }
361
+ };
362
+ export function getShapeListQueryArgs(templateName, legacyArgs) {
363
+ return (context, shape) => {
364
+ const isAllShapes = shape.name === 'TSSearchable';
365
+ const shapeName = isAllShapes ? templateName : getFlattenedTemplateShapeName(shape.name, templateName);
366
+ const shapes = isAllShapes ? Object.values(context.projectSchema.shapes) : [shape];
367
+ const {
368
+ schema,
369
+ dependencies
370
+ } = getWhereSearchArg(context.projectSchema, shapes);
371
+ return {
372
+ shapeName,
373
+ dependencies: { ...dependencies,
374
+ TSSearchSortInput,
375
+ [shapeName]: createShape(shapeName, mergeObjectSchemas(commonSearchArgs, localeProps, legacyArgs ? legacyListArgs : undefined, isAllShapes ? shapeFilterProps : undefined, schema))
376
+ }
377
+ };
378
+ };
379
+ }
@@ -0,0 +1 @@
1
+ export {};