Skip to content

Commit b948692

Browse files
committed
adds support for nested properties of object/object[] data types
1 parent d817a47 commit b948692

File tree

2 files changed

+283
-12
lines changed

2 files changed

+283
-12
lines changed

src/data/journey.test.ts

Lines changed: 271 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2-
import { doc } from 'prettier';
32
import weaviate, { WeaviateClient } from '..';
43
import {
54
WeaviateObject,
@@ -30,7 +29,26 @@ describe('data', () => {
3029
});
3130

3231
it('validates a valid thing', () => {
33-
const properties = { stringProp: 'without-id' };
32+
const properties = {
33+
stringProp: 'without-id',
34+
objectProp: {
35+
nestedInt: 123,
36+
nestedNumber: 123.45,
37+
nestedText: 'some text',
38+
nestedObjects: [
39+
{
40+
nestedBoolLvl2: true,
41+
nestedDateLvl2: '2022-01-01T00:00:00+02:00',
42+
nestedNumbersLvl2: [11.1, 22.2],
43+
},
44+
{
45+
nestedBoolLvl2: false,
46+
nestedDateLvl2: '2023-01-01T00:00:00+02:00',
47+
nestedNumbersLvl2: [33.3, 44.4],
48+
},
49+
],
50+
},
51+
};
3452

3553
return client.data
3654
.validator()
@@ -65,7 +83,26 @@ describe('data', () => {
6583
let implicitThingId: string | undefined;
6684

6785
it('creates a new thing object without an explicit id', () => {
68-
const properties = { stringProp: 'without-id' };
86+
const properties = {
87+
stringProp: 'without-id',
88+
objectProp: {
89+
nestedInt: 123,
90+
nestedNumber: 123.45,
91+
nestedText: 'some text',
92+
nestedObjects: [
93+
{
94+
nestedBoolLvl2: true,
95+
nestedDateLvl2: '2022-01-01T00:00:00+02:00',
96+
nestedNumbersLvl2: [11.1, 22.2],
97+
},
98+
{
99+
nestedBoolLvl2: false,
100+
nestedDateLvl2: '2023-01-01T00:00:00+02:00',
101+
nestedNumbersLvl2: [33.3, 44.4],
102+
},
103+
],
104+
},
105+
};
69106

70107
return client.data
71108
.creator()
@@ -82,7 +119,26 @@ describe('data', () => {
82119
});
83120

84121
it('creates a new thing object with an explicit id', () => {
85-
const properties = { stringProp: 'with-id' };
122+
const properties = {
123+
stringProp: 'with-id',
124+
objectProp: {
125+
nestedInt: 999,
126+
nestedNumber: 88.8,
127+
nestedText: 'another text',
128+
nestedObjects: [
129+
{
130+
nestedBoolLvl2: false,
131+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
132+
nestedNumbersLvl2: [55.5, 66.6],
133+
},
134+
{
135+
nestedBoolLvl2: true,
136+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
137+
nestedNumbersLvl2: [77.7, 88.8],
138+
},
139+
],
140+
},
141+
};
86142
// explicitly make this an all-zero UUID. This way we can be sure that it's
87143
// the first to come up when using the cursor API. Since this test suite
88144
// also contains dynamicaly generated IDs, this is the only way to make
@@ -149,10 +205,48 @@ describe('data', () => {
149205
expect.arrayContaining([
150206
expect.objectContaining({
151207
id: '00000000-0000-0000-0000-000000000000',
152-
properties: { stringProp: 'with-id' },
208+
properties: {
209+
stringProp: 'with-id',
210+
objectProp: {
211+
nestedInt: 999,
212+
nestedNumber: 88.8,
213+
nestedText: 'another text',
214+
nestedObjects: [
215+
{
216+
nestedBoolLvl2: false,
217+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
218+
nestedNumbersLvl2: [55.5, 66.6],
219+
},
220+
{
221+
nestedBoolLvl2: true,
222+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
223+
nestedNumbersLvl2: [77.7, 88.8],
224+
},
225+
],
226+
},
227+
},
153228
}),
154229
expect.objectContaining({
155-
properties: { stringProp: 'without-id' },
230+
properties: {
231+
stringProp: 'without-id',
232+
objectProp: {
233+
nestedInt: 123,
234+
nestedNumber: 123.45,
235+
nestedText: 'some text',
236+
nestedObjects: [
237+
{
238+
nestedBoolLvl2: true,
239+
nestedDateLvl2: '2022-01-01T00:00:00+02:00',
240+
nestedNumbersLvl2: [11.1, 22.2],
241+
},
242+
{
243+
nestedBoolLvl2: false,
244+
nestedDateLvl2: '2023-01-01T00:00:00+02:00',
245+
nestedNumbersLvl2: [33.3, 44.4],
246+
},
247+
],
248+
},
249+
},
156250
}),
157251
])
158252
);
@@ -173,10 +267,48 @@ describe('data', () => {
173267
expect.arrayContaining([
174268
expect.objectContaining({
175269
id: '00000000-0000-0000-0000-000000000000',
176-
properties: { stringProp: 'with-id' },
270+
properties: {
271+
stringProp: 'with-id',
272+
objectProp: {
273+
nestedInt: 999,
274+
nestedNumber: 88.8,
275+
nestedText: 'another text',
276+
nestedObjects: [
277+
{
278+
nestedBoolLvl2: false,
279+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
280+
nestedNumbersLvl2: [55.5, 66.6],
281+
},
282+
{
283+
nestedBoolLvl2: true,
284+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
285+
nestedNumbersLvl2: [77.7, 88.8],
286+
},
287+
],
288+
},
289+
},
177290
}),
178291
expect.objectContaining({
179-
properties: { stringProp: 'without-id' },
292+
properties: {
293+
stringProp: 'without-id',
294+
objectProp: {
295+
nestedInt: 123,
296+
nestedNumber: 123.45,
297+
nestedText: 'some text',
298+
nestedObjects: [
299+
{
300+
nestedBoolLvl2: true,
301+
nestedDateLvl2: '2022-01-01T00:00:00+02:00',
302+
nestedNumbersLvl2: [11.1, 22.2],
303+
},
304+
{
305+
nestedBoolLvl2: false,
306+
nestedDateLvl2: '2023-01-01T00:00:00+02:00',
307+
nestedNumbersLvl2: [33.3, 44.4],
308+
},
309+
],
310+
},
311+
},
180312
}),
181313
])
182314
);
@@ -198,7 +330,26 @@ describe('data', () => {
198330
expect(res.objects).toEqual(
199331
expect.arrayContaining([
200332
expect.objectContaining({
201-
properties: { stringProp: 'without-id' },
333+
properties: {
334+
stringProp: 'without-id',
335+
objectProp: {
336+
nestedInt: 123,
337+
nestedNumber: 123.45,
338+
nestedText: 'some text',
339+
nestedObjects: [
340+
{
341+
nestedBoolLvl2: true,
342+
nestedDateLvl2: '2022-01-01T00:00:00+02:00',
343+
nestedNumbersLvl2: [11.1, 22.2],
344+
},
345+
{
346+
nestedBoolLvl2: false,
347+
nestedDateLvl2: '2023-01-01T00:00:00+02:00',
348+
nestedNumbersLvl2: [33.3, 44.4],
349+
},
350+
],
351+
},
352+
},
202353
}),
203354
])
204355
);
@@ -267,7 +418,26 @@ describe('data', () => {
267418
expect(res).toEqual(
268419
expect.objectContaining({
269420
id: '00000000-0000-0000-0000-000000000000',
270-
properties: { stringProp: 'with-id' },
421+
properties: {
422+
stringProp: 'with-id',
423+
objectProp: {
424+
nestedInt: 999,
425+
nestedNumber: 88.8,
426+
nestedText: 'another text',
427+
nestedObjects: [
428+
{
429+
nestedBoolLvl2: false,
430+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
431+
nestedNumbersLvl2: [55.5, 66.6],
432+
},
433+
{
434+
nestedBoolLvl2: true,
435+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
436+
nestedNumbersLvl2: [77.7, 88.8],
437+
},
438+
],
439+
},
440+
},
271441
})
272442
);
273443
})
@@ -286,7 +456,26 @@ describe('data', () => {
286456
expect(res).toEqual(
287457
expect.objectContaining({
288458
id: '00000000-0000-0000-0000-000000000000',
289-
properties: { stringProp: 'with-id' },
459+
properties: {
460+
stringProp: 'with-id',
461+
objectProp: {
462+
nestedInt: 999,
463+
nestedNumber: 88.8,
464+
nestedText: 'another text',
465+
nestedObjects: [
466+
{
467+
nestedBoolLvl2: false,
468+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
469+
nestedNumbersLvl2: [55.5, 66.6],
470+
},
471+
{
472+
nestedBoolLvl2: true,
473+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
474+
nestedNumbersLvl2: [77.7, 88.8],
475+
},
476+
],
477+
},
478+
},
290479
})
291480
);
292481
})
@@ -354,6 +543,23 @@ describe('data', () => {
354543
.then((res: WeaviateObject) => {
355544
expect(res.properties).toEqual({
356545
stringProp: 'thing-updated',
546+
objectProp: {
547+
nestedInt: 999,
548+
nestedNumber: 88.8,
549+
nestedText: 'another text',
550+
nestedObjects: [
551+
{
552+
nestedBoolLvl2: false,
553+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
554+
nestedNumbersLvl2: [55.5, 66.6],
555+
},
556+
{
557+
nestedBoolLvl2: true,
558+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
559+
nestedNumbersLvl2: [77.7, 88.8],
560+
},
561+
],
562+
},
357563
});
358564
})
359565
.catch((e: WeaviateError) => {
@@ -376,6 +582,23 @@ describe('data', () => {
376582
.then((res: WeaviateObject) => {
377583
expect(res.properties).toEqual({
378584
stringProp: 'thing-updated-with-class-name',
585+
objectProp: {
586+
nestedInt: 999,
587+
nestedNumber: 88.8,
588+
nestedText: 'another text',
589+
nestedObjects: [
590+
{
591+
nestedBoolLvl2: false,
592+
nestedDateLvl2: '2020-01-01T00:00:00+02:00',
593+
nestedNumbersLvl2: [55.5, 66.6],
594+
},
595+
{
596+
nestedBoolLvl2: true,
597+
nestedDateLvl2: '2021-01-01T00:00:00+02:00',
598+
nestedNumbersLvl2: [77.7, 88.8],
599+
},
600+
],
601+
},
379602
});
380603
})
381604
.catch((e: WeaviateError) => {
@@ -1497,7 +1720,7 @@ describe('multi tenancy', () => {
14971720
});
14981721

14991722
const setup = async (client: WeaviateClient) => {
1500-
const thing = {
1723+
const thing: WeaviateClass = {
15011724
class: thingClassName,
15021725
properties: [
15031726
{
@@ -1508,6 +1731,42 @@ const setup = async (client: WeaviateClient) => {
15081731
name: 'intProp',
15091732
dataType: ['int'],
15101733
},
1734+
{
1735+
name: 'objectProp',
1736+
dataType: ['object'],
1737+
nestedProperties: [
1738+
{
1739+
name: 'nestedInt',
1740+
dataType: ['int'],
1741+
},
1742+
{
1743+
name: 'nestedNumber',
1744+
dataType: ['number'],
1745+
},
1746+
{
1747+
name: 'nestedText',
1748+
dataType: ['text'],
1749+
},
1750+
{
1751+
name: 'nestedObjects',
1752+
dataType: ['object[]'],
1753+
nestedProperties: [
1754+
{
1755+
name: 'nestedBoolLvl2',
1756+
dataType: ['boolean'],
1757+
},
1758+
{
1759+
name: 'nestedDateLvl2',
1760+
dataType: ['date'],
1761+
},
1762+
{
1763+
name: 'nestedNumbersLvl2',
1764+
dataType: ['number[]'],
1765+
},
1766+
],
1767+
},
1768+
],
1769+
},
15111770
],
15121771
};
15131772

src/openapi/schema.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,18 @@ export interface definitions {
501501
* @enum {string}
502502
*/
503503
tokenization?: 'word' | 'lowercase' | 'whitespace' | 'field';
504+
/** @description The properties of the nested object(s). Applies to object and object[] data types. */
505+
nestedProperties?: definitions['NestedProperty'][];
506+
};
507+
NestedProperty: {
508+
dataType?: string[];
509+
description?: string;
510+
name?: string;
511+
indexFilterable?: boolean;
512+
indexSearchable?: boolean;
513+
/** @enum {string} */
514+
tokenization?: 'word' | 'lowercase' | 'whitespace' | 'field';
515+
nestedProperties?: definitions['NestedProperty'][];
504516
};
505517
/** @description The status of all the shards of a Class */
506518
ShardStatusList: definitions['ShardStatusGetResponse'][];

0 commit comments

Comments
 (0)