@takeshape/schema 11.73.0 → 11.76.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/builtin-schema.js +1 -0
- package/dist/models/runtime-schema.js +1 -0
- package/dist/project-schema/latest.d.ts +6 -1
- package/dist/project-schema/v3.48.0.d.ts +6 -1
- package/dist/project-schema/v3.49.0.d.ts +6 -1
- package/dist/project-schema/v3.50.0.d.ts +6 -1
- package/dist/project-schema/v3.51.0.d.ts +6 -1
- package/dist/project-schema/v3.52.0.d.ts +6 -1
- package/dist/project-schema/v3.53.0.d.ts +6 -1
- package/dist/project-schema/v3.54.0.d.ts +6 -1
- package/dist/schemas/project-schema/experimental.json +20 -0
- package/dist/util/expressions.js +2 -2
- package/package.json +6 -6
- package/dist/__tests__/_examples.test.d.ts +0 -1
- package/dist/__tests__/_examples.test.js +0 -77
- package/dist/__tests__/agents.test.d.ts +0 -1
- package/dist/__tests__/agents.test.js +0 -163
- package/dist/__tests__/api-version.test.d.ts +0 -1
- package/dist/__tests__/api-version.test.js +0 -24
- package/dist/__tests__/builtin-schema.test.d.ts +0 -1
- package/dist/__tests__/builtin-schema.test.js +0 -18
- package/dist/__tests__/content-schema-transform.test.d.ts +0 -1
- package/dist/__tests__/content-schema-transform.test.js +0 -522
- package/dist/__tests__/create-input-schema.test.d.ts +0 -1
- package/dist/__tests__/create-input-schema.test.js +0 -184
- package/dist/__tests__/enum.test.d.ts +0 -1
- package/dist/__tests__/enum.test.js +0 -36
- package/dist/__tests__/flatten-templates.test.d.ts +0 -1
- package/dist/__tests__/flatten-templates.test.js +0 -40
- package/dist/__tests__/get-is-leaf.test.d.ts +0 -1
- package/dist/__tests__/get-is-leaf.test.js +0 -50
- package/dist/__tests__/interfaces.test.d.ts +0 -1
- package/dist/__tests__/interfaces.test.js +0 -219
- package/dist/__tests__/migration.test.d.ts +0 -1
- package/dist/__tests__/migration.test.js +0 -34
- package/dist/__tests__/mocks.test.d.ts +0 -1
- package/dist/__tests__/mocks.test.js +0 -24
- package/dist/__tests__/refs.test.d.ts +0 -1
- package/dist/__tests__/refs.test.js +0 -813
- package/dist/__tests__/relationships.test.d.ts +0 -1
- package/dist/__tests__/relationships.test.js +0 -638
- package/dist/__tests__/schema-transform.test.d.ts +0 -1
- package/dist/__tests__/schema-transform.test.js +0 -205
- package/dist/__tests__/schema-util.test.d.ts +0 -1
- package/dist/__tests__/schema-util.test.js +0 -1731
- package/dist/__tests__/service-dependencies.test.d.ts +0 -1
- package/dist/__tests__/service-dependencies.test.js +0 -360
- package/dist/__tests__/unions.test.d.ts +0 -1
- package/dist/__tests__/unions.test.js +0 -44
- package/dist/__tests__/validate.test.d.ts +0 -1
- package/dist/__tests__/validate.test.js +0 -1980
- package/dist/__tests__/workflows.test.d.ts +0 -3
- package/dist/__tests__/workflows.test.js +0 -149
- package/dist/layers/__tests__/layers.test.d.ts +0 -1
- package/dist/layers/__tests__/layers.test.js +0 -38
- package/dist/migration/to/__tests__/v3.10.0.test.d.ts +0 -1
- package/dist/migration/to/__tests__/v3.10.0.test.js +0 -90
- package/dist/migration/to/__tests__/v3.12.3.test.d.ts +0 -1
- package/dist/migration/to/__tests__/v3.12.3.test.js +0 -103
- package/dist/migration/to/__tests__/v3.17.test.d.ts +0 -1
- package/dist/migration/to/__tests__/v3.17.test.js +0 -71
- package/dist/migration/to/__tests__/v3.34.0.test.d.ts +0 -1
- package/dist/migration/to/__tests__/v3.34.0.test.js +0 -240
- package/dist/migration/to/__tests__/v3.39.0.test.d.ts +0 -1
- package/dist/migration/to/__tests__/v3.39.0.test.js +0 -116
- package/dist/migration/to/__tests__/v3.46.0.test.d.ts +0 -1
- package/dist/migration/to/__tests__/v3.46.0.test.js +0 -59
- package/dist/models/__tests__/fixtures.d.ts +0 -15
- package/dist/models/__tests__/fixtures.js +0 -56
- package/dist/models/__tests__/query.test.d.ts +0 -1
- package/dist/models/__tests__/query.test.js +0 -19
- package/dist/models/__tests__/runtime-schema.test.d.ts +0 -1
- package/dist/models/__tests__/runtime-schema.test.js +0 -43
- package/dist/models/__tests__/shape.test.d.ts +0 -1
- package/dist/models/__tests__/shape.test.js +0 -24
- package/dist/resolvers/ai/__tests__/rag-query.test.d.ts +0 -1
- package/dist/resolvers/ai/__tests__/rag-query.test.js +0 -49
- package/dist/services/__tests__/services.test.d.ts +0 -1
- package/dist/services/__tests__/services.test.js +0 -113
- package/dist/template-shapes/__tests__/index.test.d.ts +0 -1
- package/dist/template-shapes/__tests__/index.test.js +0 -40
- package/dist/template-shapes/__tests__/names.test.d.ts +0 -1
- package/dist/template-shapes/__tests__/names.test.js +0 -19
- package/dist/template-shapes/__tests__/templates.test.d.ts +0 -1
- package/dist/template-shapes/__tests__/templates.test.js +0 -80
- package/dist/template-shapes/__tests__/where.test.d.ts +0 -1
- package/dist/template-shapes/__tests__/where.test.js +0 -218
- package/dist/types/__tests__/utils.test.d.ts +0 -1
- package/dist/types/__tests__/utils.test.js +0 -159
- package/dist/util/__tests__/api-indexing.test.d.ts +0 -1
- package/dist/util/__tests__/api-indexing.test.js +0 -129
- package/dist/util/__tests__/detect-cycles.test.d.ts +0 -1
- package/dist/util/__tests__/detect-cycles.test.js +0 -193
- package/dist/util/__tests__/expressions.test.d.ts +0 -1
- package/dist/util/__tests__/expressions.test.js +0 -172
- package/dist/util/__tests__/find-shape-at-path.test.d.ts +0 -1
- package/dist/util/__tests__/find-shape-at-path.test.js +0 -41
- package/dist/util/__tests__/form-config.test.d.ts +0 -1
- package/dist/util/__tests__/form-config.test.js +0 -196
- package/dist/util/__tests__/get-return-shape.test.d.ts +0 -1
- package/dist/util/__tests__/get-return-shape.test.js +0 -27
- package/dist/util/__tests__/has-args.test.d.ts +0 -1
- package/dist/util/__tests__/has-args.test.js +0 -46
- package/dist/util/__tests__/merge.test.d.ts +0 -1
- package/dist/util/__tests__/merge.test.js +0 -1074
- package/dist/util/__tests__/patch-schema.test.d.ts +0 -1
- package/dist/util/__tests__/patch-schema.test.js +0 -82
- package/dist/util/__tests__/shapes.test.d.ts +0 -1
- package/dist/util/__tests__/shapes.test.js +0 -30
|
@@ -1,522 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import shapeBooksJson from '@/examples/latest/shape-books.json';
|
|
3
|
-
import { getContentTransform, getPropertyInfo } from "../content-schema-transform.js";
|
|
4
|
-
import { createInputSchema } from "../create-input-schema.js";
|
|
5
|
-
import { createMockSchema } from "../mocks.js";
|
|
6
|
-
import { dereferenceObjectSchema } from "../refs.js";
|
|
7
|
-
import { toName } from "../schema-transform.js";
|
|
8
|
-
import { applyDefaultsToSchema } from "../schema-util.js";
|
|
9
|
-
const shapeBooksSchema = createInputSchema(applyDefaultsToSchema(shapeBooksJson), {
|
|
10
|
-
isUpdate: true
|
|
11
|
-
});
|
|
12
|
-
const identityTransform = {
|
|
13
|
-
filter: () => true,
|
|
14
|
-
process: (x) => x
|
|
15
|
-
};
|
|
16
|
-
const petStoreSchema = createMockSchema('project-id', {
|
|
17
|
-
shapes: {
|
|
18
|
-
Dog: {
|
|
19
|
-
id: 'SH7HPWJfn',
|
|
20
|
-
name: 'Dog',
|
|
21
|
-
title: 'Dog',
|
|
22
|
-
schema: {
|
|
23
|
-
type: 'object',
|
|
24
|
-
properties: {
|
|
25
|
-
name: {
|
|
26
|
-
type: 'string',
|
|
27
|
-
minLength: 1,
|
|
28
|
-
description: '',
|
|
29
|
-
title: 'Name',
|
|
30
|
-
'@mapping': 'shapedb:Dog.Bu4jsC6I4'
|
|
31
|
-
},
|
|
32
|
-
isBestFriend: {
|
|
33
|
-
type: 'boolean',
|
|
34
|
-
default: false,
|
|
35
|
-
'@l10n': false,
|
|
36
|
-
description: '',
|
|
37
|
-
title: 'Is Best Friend',
|
|
38
|
-
'@mapping': 'shapedb:Dog.SfsCYX0o5'
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
required: ['name']
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
Cat: {
|
|
45
|
-
id: 'j2VnVXELF',
|
|
46
|
-
name: 'Cat',
|
|
47
|
-
title: 'Cat',
|
|
48
|
-
schema: {
|
|
49
|
-
type: 'object',
|
|
50
|
-
properties: {
|
|
51
|
-
name: {
|
|
52
|
-
type: 'string',
|
|
53
|
-
minLength: 1,
|
|
54
|
-
description: '',
|
|
55
|
-
title: 'Name',
|
|
56
|
-
'@mapping': 'shapedb:Cat.0zU9ToscC'
|
|
57
|
-
},
|
|
58
|
-
lives: {
|
|
59
|
-
'@l10n': false,
|
|
60
|
-
minimum: 0,
|
|
61
|
-
type: 'integer',
|
|
62
|
-
description: '',
|
|
63
|
-
title: 'Lives',
|
|
64
|
-
'@mapping': 'shapedb:Cat.lnQIlRKUy'
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
required: ['name', 'lives']
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
Store: {
|
|
71
|
-
id: 'W15z-c33Q',
|
|
72
|
-
name: 'Store',
|
|
73
|
-
title: 'Store',
|
|
74
|
-
workflow: 'default',
|
|
75
|
-
model: { type: 'multiple' },
|
|
76
|
-
schema: {
|
|
77
|
-
type: 'object',
|
|
78
|
-
properties: {
|
|
79
|
-
pets: {
|
|
80
|
-
'@mapping': 'shapedb:Store.OmG666',
|
|
81
|
-
type: 'array',
|
|
82
|
-
items: { oneOf: [{ '@ref': 'local:Dog' }, { '@ref': 'local:Cat' }] }
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
describe('getContentTransform', () => {
|
|
90
|
-
test('it works', () => {
|
|
91
|
-
const transforms = {
|
|
92
|
-
string: [identityTransform]
|
|
93
|
-
};
|
|
94
|
-
const transform = getContentTransform({
|
|
95
|
-
transforms,
|
|
96
|
-
projectSchema: shapeBooksSchema,
|
|
97
|
-
keyTransform: toName,
|
|
98
|
-
passThrough: false
|
|
99
|
-
});
|
|
100
|
-
const content = {
|
|
101
|
-
_updatedBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
102
|
-
BJfmu0OIZ: 'Homepage',
|
|
103
|
-
_createdBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
104
|
-
_status: 'rkhRGs4WL',
|
|
105
|
-
r1xPx1OUW: {
|
|
106
|
-
shapeId: 'r166qcP8Z',
|
|
107
|
-
id: 'e1bc4031-783e-40e6-9881-d25d744ea6b3'
|
|
108
|
-
},
|
|
109
|
-
_createdAt: '2020-08-10T22:06:44.699Z',
|
|
110
|
-
_schemaVersion: 1,
|
|
111
|
-
_id: '64224dec8b5214586b9fd8aedd979ee7',
|
|
112
|
-
_shapeId: 'H1TFgJdIb',
|
|
113
|
-
_version: 1,
|
|
114
|
-
_updatedAt: '2020-08-10T22:06:44.699Z',
|
|
115
|
-
ry4VnCD8W: {
|
|
116
|
-
'H1vBnAv8-': {
|
|
117
|
-
shapeId: 'ASSET',
|
|
118
|
-
id: 'dff44109-3fcd-43cf-8503-f266f8d5ca3e'
|
|
119
|
-
},
|
|
120
|
-
SJ1Xo0v8b: {
|
|
121
|
-
shapeId: 'rJoobhv8W',
|
|
122
|
-
id: 'ff34e345-21a2-4a0d-946a-12be856effba'
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
const transformed = transform(shapeBooksSchema.shapes.Homepage.schema, content);
|
|
127
|
-
expect(transformed).toEqual({
|
|
128
|
-
_createdAt: '2020-08-10T22:06:44.699Z',
|
|
129
|
-
_createdBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
130
|
-
_id: '64224dec8b5214586b9fd8aedd979ee7',
|
|
131
|
-
_shapeId: 'H1TFgJdIb',
|
|
132
|
-
_status: 'rkhRGs4WL',
|
|
133
|
-
_updatedAt: '2020-08-10T22:06:44.699Z',
|
|
134
|
-
_updatedBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
135
|
-
featuredBook: {
|
|
136
|
-
id: 'e1bc4031-783e-40e6-9881-d25d744ea6b3',
|
|
137
|
-
shapeId: 'r166qcP8Z'
|
|
138
|
-
},
|
|
139
|
-
hero: {
|
|
140
|
-
featuredPost: {
|
|
141
|
-
id: 'ff34e345-21a2-4a0d-946a-12be856effba',
|
|
142
|
-
shapeId: 'rJoobhv8W'
|
|
143
|
-
},
|
|
144
|
-
image: {
|
|
145
|
-
id: 'dff44109-3fcd-43cf-8503-f266f8d5ca3e',
|
|
146
|
-
shapeId: 'ASSET'
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
title: 'Homepage'
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
test('localized fields', () => {
|
|
153
|
-
const transforms = {
|
|
154
|
-
string: [identityTransform]
|
|
155
|
-
};
|
|
156
|
-
const transform = getContentTransform({
|
|
157
|
-
transforms,
|
|
158
|
-
projectSchema: {
|
|
159
|
-
...shapeBooksSchema,
|
|
160
|
-
locales: [shapeBooksSchema.defaultLocale, 'fr-fr']
|
|
161
|
-
},
|
|
162
|
-
keyTransform: toName,
|
|
163
|
-
passThrough: false
|
|
164
|
-
});
|
|
165
|
-
const content = {
|
|
166
|
-
_updatedBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
167
|
-
_createdBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
168
|
-
_status: 'rkhRGs4WL',
|
|
169
|
-
r1xPx1OUW: {
|
|
170
|
-
shapeId: 'r166qcP8Z',
|
|
171
|
-
id: 'e1bc4031-783e-40e6-9881-d25d744ea6b3'
|
|
172
|
-
},
|
|
173
|
-
'r1xPx1OUW:fr-fr': {
|
|
174
|
-
shapeId: 'r166qcP8Z',
|
|
175
|
-
id: 'bf9b8b71-cf82-436a-90e2-8c1433533a2a"'
|
|
176
|
-
},
|
|
177
|
-
_createdAt: '2020-08-10T22:06:44.699Z',
|
|
178
|
-
_schemaVersion: 1,
|
|
179
|
-
_id: '64224dec8b5214586b9fd8aedd979ee7',
|
|
180
|
-
_shapeId: 'H1TFgJdIb',
|
|
181
|
-
_version: 1,
|
|
182
|
-
_updatedAt: '2020-08-10T22:06:44.699Z'
|
|
183
|
-
};
|
|
184
|
-
const transformed = transform(shapeBooksSchema.shapes.Homepage.schema, content);
|
|
185
|
-
expect(transformed).toEqual({
|
|
186
|
-
_createdAt: '2020-08-10T22:06:44.699Z',
|
|
187
|
-
_createdBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
188
|
-
_id: '64224dec8b5214586b9fd8aedd979ee7',
|
|
189
|
-
_shapeId: 'H1TFgJdIb',
|
|
190
|
-
_status: 'rkhRGs4WL',
|
|
191
|
-
_updatedAt: '2020-08-10T22:06:44.699Z',
|
|
192
|
-
_updatedBy: '1b499b01-bba7-4bc5-8ef5-08895a1d1322',
|
|
193
|
-
featuredBook: {
|
|
194
|
-
id: 'e1bc4031-783e-40e6-9881-d25d744ea6b3',
|
|
195
|
-
shapeId: 'r166qcP8Z'
|
|
196
|
-
},
|
|
197
|
-
'featuredBook:fr-fr': {
|
|
198
|
-
id: 'bf9b8b71-cf82-436a-90e2-8c1433533a2a"',
|
|
199
|
-
shapeId: 'r166qcP8Z'
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
test('allowNullObjects option', () => {
|
|
204
|
-
const projectSchema = {
|
|
205
|
-
...createMockSchema('projectId'),
|
|
206
|
-
shapes: {
|
|
207
|
-
RocketPort: {
|
|
208
|
-
name: 'RocketPort',
|
|
209
|
-
title: 'RocketPort',
|
|
210
|
-
id: 'RocketPort',
|
|
211
|
-
schema: {
|
|
212
|
-
type: 'object',
|
|
213
|
-
properties: {
|
|
214
|
-
lat: {
|
|
215
|
-
type: 'number'
|
|
216
|
-
},
|
|
217
|
-
lon: {
|
|
218
|
-
type: 'number'
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
Species: {
|
|
224
|
-
name: 'Species',
|
|
225
|
-
title: 'Species',
|
|
226
|
-
id: 'Species',
|
|
227
|
-
schema: {
|
|
228
|
-
type: 'object',
|
|
229
|
-
properties: {
|
|
230
|
-
hair: {
|
|
231
|
-
type: 'string'
|
|
232
|
-
},
|
|
233
|
-
head: {
|
|
234
|
-
type: 'string'
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
required: ['hair', 'head']
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
Planet: {
|
|
241
|
-
name: 'Planet',
|
|
242
|
-
title: 'Planet',
|
|
243
|
-
id: 'Planet',
|
|
244
|
-
schema: {
|
|
245
|
-
type: 'object',
|
|
246
|
-
properties: {
|
|
247
|
-
species: { '@ref': 'shapedb:Species' },
|
|
248
|
-
atmosphere: { type: 'string' },
|
|
249
|
-
landStyle: { type: 'string' },
|
|
250
|
-
rocketPorts: {
|
|
251
|
-
type: 'array',
|
|
252
|
-
items: { '@ref': 'shapedb:RocketPort' }
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
const transforms = {
|
|
260
|
-
string: [identityTransform],
|
|
261
|
-
number: [identityTransform]
|
|
262
|
-
};
|
|
263
|
-
const transformAllowNull = getContentTransform({
|
|
264
|
-
transforms,
|
|
265
|
-
projectSchema,
|
|
266
|
-
keyTransform: toName,
|
|
267
|
-
passThrough: false,
|
|
268
|
-
allowNullObjects: true
|
|
269
|
-
});
|
|
270
|
-
const transformNoNull = getContentTransform({
|
|
271
|
-
transforms,
|
|
272
|
-
projectSchema,
|
|
273
|
-
keyTransform: toName,
|
|
274
|
-
passThrough: false,
|
|
275
|
-
allowNullObjects: false
|
|
276
|
-
});
|
|
277
|
-
const content = {
|
|
278
|
-
species: null,
|
|
279
|
-
atmosphere: 'foggy',
|
|
280
|
-
landStyle: null,
|
|
281
|
-
rocketPorts: [null, { lat: 5, lon: 5 }]
|
|
282
|
-
};
|
|
283
|
-
const transformedAllowNull = transformAllowNull(projectSchema.shapes.Planet.schema, content);
|
|
284
|
-
expect(transformedAllowNull).toEqual({
|
|
285
|
-
species: null,
|
|
286
|
-
atmosphere: 'foggy',
|
|
287
|
-
landStyle: null,
|
|
288
|
-
rocketPorts: [null, { lat: 5, lon: 5 }]
|
|
289
|
-
});
|
|
290
|
-
const transformedNoNull = transformNoNull(projectSchema.shapes.Planet.schema, content);
|
|
291
|
-
expect(transformedNoNull).toEqual({
|
|
292
|
-
atmosphere: 'foggy',
|
|
293
|
-
landStyle: null,
|
|
294
|
-
rocketPorts: [undefined, { lat: 5, lon: 5 }]
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
test('recursive', () => {
|
|
298
|
-
const projectSchema = {
|
|
299
|
-
...createMockSchema('projectId'),
|
|
300
|
-
shapes: {
|
|
301
|
-
Node: {
|
|
302
|
-
name: 'Node',
|
|
303
|
-
title: 'Node',
|
|
304
|
-
id: 'node-id',
|
|
305
|
-
schema: {
|
|
306
|
-
type: 'object',
|
|
307
|
-
properties: {
|
|
308
|
-
value: { type: 'number' },
|
|
309
|
-
left: { $ref: '#/shapes/Node/schema' },
|
|
310
|
-
right: { $ref: '#/shapes/Node/schema' }
|
|
311
|
-
},
|
|
312
|
-
required: ['value']
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
const data = {
|
|
318
|
-
value: 50,
|
|
319
|
-
left: {
|
|
320
|
-
value: 25,
|
|
321
|
-
left: {
|
|
322
|
-
value: 10
|
|
323
|
-
},
|
|
324
|
-
right: {
|
|
325
|
-
value: 45
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
right: {
|
|
329
|
-
value: 75
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
const getAccumulator = () => {
|
|
333
|
-
let total = 0;
|
|
334
|
-
return {
|
|
335
|
-
accumulate(value) {
|
|
336
|
-
if (typeof value === 'number') {
|
|
337
|
-
total += value;
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
getResults() {
|
|
341
|
-
return total;
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
};
|
|
345
|
-
const totaler = getAccumulator();
|
|
346
|
-
const contentTransform = getContentTransform({
|
|
347
|
-
projectSchema,
|
|
348
|
-
accumulators: [totaler]
|
|
349
|
-
});
|
|
350
|
-
const notTransformed = contentTransform(projectSchema.shapes.Node.schema, data);
|
|
351
|
-
expect(notTransformed).toEqual(data);
|
|
352
|
-
expect(totaler.getResults()).toEqual(205);
|
|
353
|
-
});
|
|
354
|
-
test('oneOf', () => {
|
|
355
|
-
const data = {
|
|
356
|
-
OmG666: [
|
|
357
|
-
{
|
|
358
|
-
Bu4jsC6I4: 'fido',
|
|
359
|
-
SfsCYX0o5: true,
|
|
360
|
-
_shapeId: 'SH7HPWJfn'
|
|
361
|
-
},
|
|
362
|
-
{
|
|
363
|
-
'0zU9ToscC': 'fido',
|
|
364
|
-
lnQIlRKUy: 666,
|
|
365
|
-
_shapeId: 'j2VnVXELF'
|
|
366
|
-
}
|
|
367
|
-
]
|
|
368
|
-
};
|
|
369
|
-
const contentTransform = getContentTransform({
|
|
370
|
-
projectSchema: petStoreSchema,
|
|
371
|
-
keyTransform: toName,
|
|
372
|
-
passThrough: true
|
|
373
|
-
});
|
|
374
|
-
const transformed = contentTransform(petStoreSchema.shapes.Store.schema, data);
|
|
375
|
-
expect(transformed).toEqual({
|
|
376
|
-
pets: [
|
|
377
|
-
{
|
|
378
|
-
_shapeId: 'SH7HPWJfn',
|
|
379
|
-
isBestFriend: true,
|
|
380
|
-
name: 'fido'
|
|
381
|
-
},
|
|
382
|
-
{
|
|
383
|
-
_shapeId: 'j2VnVXELF',
|
|
384
|
-
lives: 666,
|
|
385
|
-
name: 'fido'
|
|
386
|
-
}
|
|
387
|
-
]
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
describe('getPropertyInfo', () => {
|
|
392
|
-
test('it works', () => {
|
|
393
|
-
const { schema } = shapeBooksSchema.shapes.Post;
|
|
394
|
-
const context = {
|
|
395
|
-
projectSchema: shapeBooksSchema,
|
|
396
|
-
transforms: {
|
|
397
|
-
string: [identityTransform]
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
const info = getPropertyInfo(context, schema, 'title');
|
|
401
|
-
expect(info).toEqual([
|
|
402
|
-
{
|
|
403
|
-
schema: dereferenceObjectSchema(shapeBooksSchema, shapeBooksSchema.shapes.Post.schema).properties.title,
|
|
404
|
-
key: 'BkJDGhw8W',
|
|
405
|
-
isRequired: false
|
|
406
|
-
}
|
|
407
|
-
]);
|
|
408
|
-
});
|
|
409
|
-
test('array', () => {
|
|
410
|
-
const { schema } = shapeBooksSchema.shapes.Post;
|
|
411
|
-
const context = {
|
|
412
|
-
projectSchema: shapeBooksSchema,
|
|
413
|
-
transforms: {
|
|
414
|
-
string: [identityTransform]
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
const info = getPropertyInfo(context, schema, 'tags');
|
|
418
|
-
expect(info).toEqual([
|
|
419
|
-
{
|
|
420
|
-
schema: dereferenceObjectSchema(shapeBooksSchema, shapeBooksSchema.shapes.Post.schema).properties.tags,
|
|
421
|
-
key: 'Hkb57EkOQ',
|
|
422
|
-
isRequired: false
|
|
423
|
-
}
|
|
424
|
-
]);
|
|
425
|
-
});
|
|
426
|
-
const millSchema = applyDefaultsToSchema({
|
|
427
|
-
...createMockSchema('project-id'),
|
|
428
|
-
shapes: {
|
|
429
|
-
Sidebar: {
|
|
430
|
-
id: 'rJuZjRtJS',
|
|
431
|
-
name: 'Sidebar',
|
|
432
|
-
title: 'Main - Sidebar',
|
|
433
|
-
model: {
|
|
434
|
-
type: 'multiple'
|
|
435
|
-
},
|
|
436
|
-
workflow: 'default',
|
|
437
|
-
schema: {
|
|
438
|
-
type: 'object',
|
|
439
|
-
properties: {
|
|
440
|
-
jurisdictions: {
|
|
441
|
-
title: 'Jurisdictions',
|
|
442
|
-
items: {
|
|
443
|
-
$ref: '#/shapes/SidebarJurisdictions/schema'
|
|
444
|
-
},
|
|
445
|
-
type: 'array',
|
|
446
|
-
'@mapping': 'shapedb:Sidebar.c81MqK71H'
|
|
447
|
-
}
|
|
448
|
-
},
|
|
449
|
-
required: ['usedFor']
|
|
450
|
-
}
|
|
451
|
-
},
|
|
452
|
-
SidebarJurisdictions: {
|
|
453
|
-
id: 'c81MqK71H',
|
|
454
|
-
name: 'SidebarJurisdictions',
|
|
455
|
-
title: 'Main - Sidebar Jurisdictions',
|
|
456
|
-
schema: {
|
|
457
|
-
type: 'object',
|
|
458
|
-
properties: {
|
|
459
|
-
value: {
|
|
460
|
-
minLength: 1,
|
|
461
|
-
type: 'string',
|
|
462
|
-
title: 'Value',
|
|
463
|
-
'@mapping': 'shapedb:SidebarJurisdictions.FMYr9BGAG'
|
|
464
|
-
}
|
|
465
|
-
},
|
|
466
|
-
required: ['value']
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
test('mill example', () => {
|
|
472
|
-
const { schema } = millSchema.shapes.Sidebar;
|
|
473
|
-
const context = {
|
|
474
|
-
projectSchema: millSchema,
|
|
475
|
-
transforms: {
|
|
476
|
-
string: [identityTransform]
|
|
477
|
-
}
|
|
478
|
-
};
|
|
479
|
-
const info = getPropertyInfo(context, schema, 'jurisdictions.value');
|
|
480
|
-
expect(info).toEqual([
|
|
481
|
-
{
|
|
482
|
-
schema: dereferenceObjectSchema(millSchema, millSchema.shapes.SidebarJurisdictions.schema).properties.value,
|
|
483
|
-
key: 'c81MqK71H.FMYr9BGAG',
|
|
484
|
-
isRequired: true
|
|
485
|
-
}
|
|
486
|
-
]);
|
|
487
|
-
});
|
|
488
|
-
test('oneOf', () => {
|
|
489
|
-
const { schema } = petStoreSchema.shapes.Store;
|
|
490
|
-
const context = {
|
|
491
|
-
projectSchema: petStoreSchema,
|
|
492
|
-
transforms: {
|
|
493
|
-
string: [identityTransform]
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
const info = getPropertyInfo(context, schema, 'pets.name');
|
|
497
|
-
expect(info).toEqual([
|
|
498
|
-
{
|
|
499
|
-
key: 'OmG666.Bu4jsC6I4',
|
|
500
|
-
schema: {
|
|
501
|
-
'@mapping': 'shapedb:Dog.Bu4jsC6I4',
|
|
502
|
-
description: '',
|
|
503
|
-
minLength: 1,
|
|
504
|
-
title: 'Name',
|
|
505
|
-
type: 'string'
|
|
506
|
-
},
|
|
507
|
-
isRequired: true
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
key: 'OmG666.0zU9ToscC',
|
|
511
|
-
schema: {
|
|
512
|
-
'@mapping': 'shapedb:Cat.0zU9ToscC',
|
|
513
|
-
description: '',
|
|
514
|
-
minLength: 1,
|
|
515
|
-
title: 'Name',
|
|
516
|
-
type: 'string'
|
|
517
|
-
},
|
|
518
|
-
isRequired: true
|
|
519
|
-
}
|
|
520
|
-
]);
|
|
521
|
-
});
|
|
522
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { expect, test, vi } from 'vitest';
|
|
2
|
-
import { createInputSchema } from "../create-input-schema.js";
|
|
3
|
-
test('rewriteSchema', () => {
|
|
4
|
-
const schema = {
|
|
5
|
-
type: 'object',
|
|
6
|
-
properties: {
|
|
7
|
-
title: { type: 'string' },
|
|
8
|
-
live: {
|
|
9
|
-
type: 'boolean',
|
|
10
|
-
default: false
|
|
11
|
-
},
|
|
12
|
-
rating: {
|
|
13
|
-
type: 'string',
|
|
14
|
-
'@mapping': 'foo.bar',
|
|
15
|
-
'@input': {
|
|
16
|
-
type: 'number'
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
required: ['title']
|
|
21
|
-
};
|
|
22
|
-
const jsonParse = JSON.parse;
|
|
23
|
-
JSON.parse = vi.fn().mockImplementation((text, reviver) => {
|
|
24
|
-
return jsonParse(text, reviver);
|
|
25
|
-
});
|
|
26
|
-
expect(createInputSchema(schema, { isUpdate: true })).toEqual({
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
title: { type: 'string' },
|
|
30
|
-
live: { type: 'boolean' },
|
|
31
|
-
rating: {
|
|
32
|
-
type: 'number',
|
|
33
|
-
'@output': {
|
|
34
|
-
type: 'string'
|
|
35
|
-
},
|
|
36
|
-
'@mapping': 'foo.bar'
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
test('rewriteSchema - removes @resolver', () => {
|
|
42
|
-
const schema = {
|
|
43
|
-
type: 'object',
|
|
44
|
-
properties: {
|
|
45
|
-
greeting: {
|
|
46
|
-
'@l10n': true,
|
|
47
|
-
minLength: 1,
|
|
48
|
-
type: 'string',
|
|
49
|
-
title: 'Greeting',
|
|
50
|
-
'@mapping': 'shapedb:Homie.Ulpa_mHb3'
|
|
51
|
-
},
|
|
52
|
-
splash: {
|
|
53
|
-
'@l10n': true,
|
|
54
|
-
'@args': 'TSRelationshipArgs',
|
|
55
|
-
'@resolver': {
|
|
56
|
-
name: 'shapedb:getRelated',
|
|
57
|
-
service: 'shapedb',
|
|
58
|
-
options: { nullable: true }
|
|
59
|
-
},
|
|
60
|
-
'@ref': 'local:Asset',
|
|
61
|
-
'@input': { '@ref': 'local:TSRelationship' },
|
|
62
|
-
title: 'Splash',
|
|
63
|
-
'@mapping': 'shapedb:Homie.0KGSDRXTC'
|
|
64
|
-
},
|
|
65
|
-
_references: {
|
|
66
|
-
'@args': 'AuthorReferenceTSListArgs',
|
|
67
|
-
'@ref': 'AuthorReferencePaginatedList',
|
|
68
|
-
'@resolver': {
|
|
69
|
-
args: {
|
|
70
|
-
ops: [
|
|
71
|
-
{
|
|
72
|
-
path: '$',
|
|
73
|
-
mapping: '$args'
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
path: 'baseWhere._references.eq',
|
|
77
|
-
mapping: '$source._id'
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
path: 'baseWhere._shapeId.in',
|
|
81
|
-
value: ['asset-id', 'post-id', 'book-id']
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
},
|
|
85
|
-
name: 'shapedb:list',
|
|
86
|
-
service: 'shapedb'
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
required: ['greeting', 'splash']
|
|
91
|
-
};
|
|
92
|
-
expect(createInputSchema(schema)).toEqual({
|
|
93
|
-
properties: {
|
|
94
|
-
greeting: {
|
|
95
|
-
'@l10n': true,
|
|
96
|
-
'@mapping': 'shapedb:Homie.Ulpa_mHb3',
|
|
97
|
-
minLength: 1,
|
|
98
|
-
title: 'Greeting',
|
|
99
|
-
type: 'string'
|
|
100
|
-
},
|
|
101
|
-
splash: {
|
|
102
|
-
'@l10n': true,
|
|
103
|
-
'@mapping': 'shapedb:Homie.0KGSDRXTC',
|
|
104
|
-
'@output': {
|
|
105
|
-
'@args': 'TSRelationshipArgs',
|
|
106
|
-
'@ref': 'local:Asset',
|
|
107
|
-
'@resolver': {
|
|
108
|
-
name: 'shapedb:getRelated',
|
|
109
|
-
options: {
|
|
110
|
-
nullable: true
|
|
111
|
-
},
|
|
112
|
-
service: 'shapedb'
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
'@ref': 'local:TSRelationship',
|
|
116
|
-
title: 'Splash'
|
|
117
|
-
}
|
|
118
|
-
},
|
|
119
|
-
required: ['greeting', 'splash'],
|
|
120
|
-
type: 'object'
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
test('rewriteSchema - l10n', () => {
|
|
124
|
-
const schema = {
|
|
125
|
-
type: 'object',
|
|
126
|
-
properties: {
|
|
127
|
-
greeting: {
|
|
128
|
-
'@l10n': true,
|
|
129
|
-
minLength: 1,
|
|
130
|
-
type: 'string',
|
|
131
|
-
title: 'Greeting',
|
|
132
|
-
'@mapping': 'shapedb:Homie.Ulpa_mHb3'
|
|
133
|
-
},
|
|
134
|
-
splash: {
|
|
135
|
-
'@l10n': true,
|
|
136
|
-
'@args': 'TSRelationshipArgs',
|
|
137
|
-
'@resolver': {
|
|
138
|
-
name: 'shapedb:getRelated',
|
|
139
|
-
service: 'shapedb',
|
|
140
|
-
options: { nullable: true }
|
|
141
|
-
},
|
|
142
|
-
'@ref': 'local:Asset',
|
|
143
|
-
'@input': { '@ref': 'local:TSRelationship' },
|
|
144
|
-
title: 'Splash',
|
|
145
|
-
'@mapping': 'shapedb:Homie.0KGSDRXTC'
|
|
146
|
-
}
|
|
147
|
-
},
|
|
148
|
-
required: ['greeting', 'splash']
|
|
149
|
-
};
|
|
150
|
-
expect(createInputSchema(schema)).toEqual({
|
|
151
|
-
properties: {
|
|
152
|
-
greeting: {
|
|
153
|
-
'@l10n': true,
|
|
154
|
-
'@mapping': 'shapedb:Homie.Ulpa_mHb3',
|
|
155
|
-
minLength: 1,
|
|
156
|
-
title: 'Greeting',
|
|
157
|
-
type: 'string'
|
|
158
|
-
},
|
|
159
|
-
splash: {
|
|
160
|
-
'@l10n': true,
|
|
161
|
-
'@mapping': 'shapedb:Homie.0KGSDRXTC',
|
|
162
|
-
'@output': {
|
|
163
|
-
'@args': 'TSRelationshipArgs',
|
|
164
|
-
'@ref': 'local:Asset',
|
|
165
|
-
'@resolver': {
|
|
166
|
-
name: 'shapedb:getRelated',
|
|
167
|
-
options: {
|
|
168
|
-
nullable: true
|
|
169
|
-
},
|
|
170
|
-
service: 'shapedb'
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
'@ref': 'local:TSRelationship',
|
|
174
|
-
title: 'Splash'
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
required: ['greeting', 'splash'],
|
|
178
|
-
type: 'object'
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
test('rewriteSchema - handles nulls', () => {
|
|
182
|
-
const bogus = { foo: null };
|
|
183
|
-
expect(createInputSchema(bogus)).toEqual(bogus);
|
|
184
|
-
});
|