Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RJS-2680: Implement support for Mixed data type with nested collections #6513

Merged
merged 82 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
89524f0
Move geospatial helper functions to related file.
elle-j Jan 23, 2024
ec46260
Implement setting nested lists in Mixed.
elle-j Jan 24, 2024
25fa99e
Implement setting nested dictionaries in Mixed.
elle-j Jan 24, 2024
cfb1e4a
Implement getting nested lists in Mixed.
elle-j Jan 24, 2024
5358296
Implement getting nested dictionaries in Mixed.
elle-j Feb 1, 2024
a9feab9
Test creating and accessing nested lists and dicts.
elle-j Feb 2, 2024
7087d64
Make previous flat collections tests use the new 'expect' function.
elle-j Feb 2, 2024
ce6ca84
Test that max nesting level throws.
elle-j Feb 2, 2024
8f718b4
Delegate throwing when using a Set to 'mixedToBinding()'.
elle-j Feb 2, 2024
df384fb
Implement setting nested collections on a dictionary via setter.
elle-j Feb 6, 2024
4edd774
Test nested collections on dictionary via setter.
elle-j Feb 6, 2024
ebd2451
Minor update to names of tests.
elle-j Feb 6, 2024
92a60af
Combine nested and flat collections tests into same suite.
elle-j Feb 6, 2024
e05e917
Implement setting nested collections on a list via setter.
elle-j Feb 7, 2024
ee6c4b7
Test nested collections on list via setter.
elle-j Feb 7, 2024
1477968
Refactor common test logic to helper functions.
elle-j Feb 7, 2024
e894737
Optimize property setter for hot-path and use friendlier err msg.
elle-j Feb 7, 2024
aafac61
Refactor test helper function to build collections of any depth.
elle-j Feb 8, 2024
fc10c57
Implement inserting nested collections on a list via 'push()'.
elle-j Feb 8, 2024
1918cac
Test nested collections on a list via 'push()'.
elle-j Feb 8, 2024
17cea6a
Test updating dictionary entry to nested collections via setter.
elle-j Feb 8, 2024
c0788f4
Test updating nested list/dictionary item via setter.
elle-j Feb 8, 2024
d0c82dc
Test removing items from collections via 'remove()'.
elle-j Feb 8, 2024
73819bf
Test object notifications when modifying nested collections.
elle-j Feb 8, 2024
91416ef
Group previous notification tests into one test.
elle-j Feb 8, 2024
3bb8e1c
Group collection notifications tests into 'List' and 'Dictionary'.
elle-j Feb 12, 2024
66a3926
Test collection notifications when modifying nested collections.
elle-j Feb 12, 2024
39dd930
Remove collections from test context.
elle-j Feb 13, 2024
30190a5
Test filtering by query path on nested collections.
elle-j Feb 14, 2024
f490f4a
Align object schema property names in tests.
elle-j Feb 14, 2024
eeded46
Test filtering with int at_type.
elle-j Feb 15, 2024
8337dc9
Implement setting nested collections on a dictionary via 'set()' over…
elle-j Feb 15, 2024
ede5d6a
Test JS Array method 'values()'.
elle-j Feb 15, 2024
9800bce
Test JS Array method 'entries()'.
elle-j Feb 15, 2024
7b5e22f
Implement getting nested collections on dictionary 'values()' and 'en…
elle-j Feb 16, 2024
c52e112
Test 'values()' and 'entries()' on dictionary with nested collections.
elle-j Feb 16, 2024
538818a
Remove unnecessary 'fromBinding()' calls.
elle-j Feb 19, 2024
5b7fa1e
Refactor collection helpers from 'PropertyHelpers' into the respectiv…
elle-j Feb 26, 2024
7680f53
Introduce list/dict sentinels to circumvent extra Core access.
elle-j Feb 26, 2024
8fd542e
Rename getter to default.
elle-j Feb 26, 2024
d82f51b
Remove redundant 'snapshotGet'.
elle-j Feb 27, 2024
728af69
Add abstract 'get' and 'set' to 'OrderedCollection'.
elle-j Feb 27, 2024
bdcd31d
Rename the collection helpers to 'accessor'.
elle-j Feb 27, 2024
3e44f9c
Move tests into subsuites.
elle-j Feb 27, 2024
faaf2a7
Fix 'Results.update()'.
elle-j Feb 27, 2024
974b3c8
Support nested collections in 'pop()', 'shift()', 'unshift()', 'splic…
elle-j Feb 27, 2024
c2a6bdf
Test list 'pop()'.
elle-j Feb 27, 2024
255b81d
Test list 'shift()'.
elle-j Feb 27, 2024
5c71222
Test list 'unshift()'.
elle-j Feb 27, 2024
16a4f99
Test list 'splice()'.
elle-j Feb 27, 2024
3c62bc3
Return 'not found' for collections searched for in 'indexOf()'.
elle-j Feb 27, 2024
3f15037
Test ordered collection 'indexOf()'.
elle-j Feb 27, 2024
f105a23
Support list/dict sentinels in JSI.
elle-j Feb 27, 2024
4bed4f9
Test references per access.
elle-j Feb 27, 2024
a656c7e
Enable skipped tests after Core bug fix.
elle-j Feb 28, 2024
80d5122
Point to updated Core.
elle-j Feb 28, 2024
c50c6d6
Fix accessor for non-Mixed top-level collection with Mixed items.
elle-j Feb 28, 2024
6bf2eb8
Enable and fix previously skipped test.
elle-j Feb 28, 2024
e533b6d
Update 'mixed{}'.
elle-j Feb 29, 2024
e43a600
Update 'mixed<>'.
elle-j Feb 29, 2024
433cf4f
Remove now-invalidated test.
elle-j Feb 29, 2024
7f31ebc
Remove unused injectable from Node bindgen template.
elle-j Mar 2, 2024
5c2d7bb
Replace if-statements with switch.
elle-j Mar 2, 2024
b5f5f04
Add explicit Results and Set accessors for Mixed.
elle-j Mar 2, 2024
2d0ef39
Adapt to change in Core treating missing keys as null in queries.
elle-j Mar 3, 2024
ce65744
Rename insertion function.
elle-j Mar 3, 2024
d54b938
Include tests of Dictionary property type with Mixed.
elle-j Mar 3, 2024
70b7574
Test reassigning to new collection and self-assignment.
elle-j Mar 3, 2024
e895bef
Test mixed
elle-j Mar 6, 2024
e4d7f1b
Update 'mixed[]'.
elle-j Mar 6, 2024
f454095
Test results accessor.
elle-j Mar 7, 2024
ee9fcfe
Update error messages.
elle-j Mar 7, 2024
b706172
Make accessor helpers an object field rather than spread.
elle-j Mar 18, 2024
2a6c9ba
Suggestions for "nested collections in mixed" (#6566)
kraenhansen Mar 21, 2024
e6dedf2
Remove leftover 'Symbol_for' in node-wrapper template.
elle-j Mar 21, 2024
75ee5b4
Test not invalidating new collection.
elle-j Mar 22, 2024
b82028f
Remove test for max nesting level.
elle-j Mar 22, 2024
c030cf4
Remove reliance on issue-fix in certain tests.
elle-j Mar 22, 2024
5c1efc5
Add key path test for object listener on mixed field.
elle-j Mar 22, 2024
b3d730a
Use '.values()' and '.entries()' in iteration.
elle-j Mar 22, 2024
46e5488
Update comments.
elle-j Mar 22, 2024
07136e7
Add CHANGELOG entry.
elle-j Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 7 additions & 30 deletions integration-tests/tests/src/tests/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { expect } from "chai";
import Realm, { PropertySchema } from "realm";

import { openRealmBefore, openRealmBeforeEach } from "../hooks";
import { sleep } from "../utils/sleep";

type Item<ValueType = Realm.Mixed> = {
dict: Realm.Dictionary<ValueType>;
Expand Down Expand Up @@ -60,17 +59,6 @@ const DictTypedSchema: Realm.ObjectSchema = {
},
};

const DictMixedSchema = {
name: "MixedDictionary",
properties: {
dict1: "mixed{}",
dict2: "mixed{}",
},
};

type IDictSchema = {
fields: Record<any, any>;
};
type ITwoDictSchema = {
dict1: Record<any, any>;
dict2: Record<any, any>;
Expand Down Expand Up @@ -307,17 +295,17 @@ describe("Dictionary", () => {
});
});

// This is currently not supported
it.skip("can store dictionary values using string keys", function (this: RealmContext) {
it("can store dictionary values using string keys", function (this: RealmContext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand the test description - it seems to suggest that we'll be storing dictionaries as the values, but we store an object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a preexisting test that was skipped unnecessarily. Haven't changed those tests (except this one as the test itself was incorrect). I think the description refers to storing dictionary (item.dict) values using string keys (key1).

const item = this.realm.write(() => {
const item = this.realm.create<Item>("Item", {});
const item2 = this.realm.create<Item>("Item", {});
item2.dict.key1 = "Hello";
item.dict.key1 = item2.dict;
item2.dict.key1 = "hello";
item.dict.key1 = item2;
return item;
});
// @ts-expect-error We expect a dictionary inside dictionary
expect(item.dict.key1.dict.key1).equals("hello");
const innerObject = item.dict.key1 as Realm.Object<Item> & Item;
expect(innerObject).instanceOf(Realm.Object);
expect(innerObject.dict).deep.equals({ key1: "hello" });
});

it("can store a reference to itself using string keys", function (this: RealmContext) {
Expand Down Expand Up @@ -599,7 +587,7 @@ describe("Dictionary", () => {
});

describe("embedded models", () => {
openRealmBeforeEach({ schema: [DictTypedSchema, DictMixedSchema, EmbeddedChild] });
openRealmBeforeEach({ schema: [DictTypedSchema, EmbeddedChild] });
it("inserts correctly", function (this: RealmContext) {
this.realm.write(() => {
this.realm.create(DictTypedSchema.name, {
Expand All @@ -615,16 +603,5 @@ describe("Dictionary", () => {
expect(dict_2.children1?.num).equal(4, "We expect children1#4");
expect(dict_2.children2?.num).equal(5, "We expect children2#5");
});

it("throws on invalid input", function (this: RealmContext) {
this.realm.write(() => {
expect(() => {
this.realm.create(DictMixedSchema.name, {
dict1: { children1: { num: 2 }, children2: { num: 3 } },
dict2: { children1: { num: 4 }, children2: { num: 5 } },
});
}).throws("Unable to convert an object with ctor 'Object' to a Mixed");
});
});
});
});
13 changes: 9 additions & 4 deletions integration-tests/tests/src/tests/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ describe("Lists", () => {
Error,
"Requested index 2 calling set() on list 'LinkTypesObject.arrayCol' when max is 1",
);
expect(() => (array[-1] = { doubleCol: 1 })).throws(Error, "Index -1 cannot be less than zero.");
expect(() => (array[-1] = { doubleCol: 1 })).throws(Error, "Cannot set item at negative index -1");

//@ts-expect-error TYPEBUG: our List type-definition expects index accesses to be done with a number , should probably be extended.
array["foo"] = "bar";
Expand Down Expand Up @@ -792,8 +792,10 @@ describe("Lists", () => {
//@ts-expect-error TYPEBUG: type missmatch, forcecasting shouldn't be done
obj.arrayCol = [this.realm.create<ITestObjectSchema>(TestObjectSchema.name, { doubleCol: 1.0 })];
expect(obj.arrayCol[0].doubleCol).equals(1.0);
obj.arrayCol = obj.arrayCol; // eslint-disable-line no-self-assign
expect(obj.arrayCol[0].doubleCol).equals(1.0);

// TODO: Solve the "removeAll()" case for self-assignment.
// obj.arrayCol = obj.arrayCol; // eslint-disable-line no-self-assign
// expect(obj.arrayCol[0].doubleCol).equals(1.0);

//@ts-expect-error Person is not assignable to boolean.
expect(() => (prim.bool = [person])).throws(
Expand Down Expand Up @@ -871,8 +873,11 @@ describe("Lists", () => {
function testAssignNull(name: string, expected: string) {
//@ts-expect-error TYPEBUG: our List type-definition expects index accesses to be done with a number , should probably be extended.
expect(() => (prim[name] = [null])).throws(Error, `Expected '${name}[0]' to be ${expected}, got null`);
// TODO: Length should equal 1 when this is fixed: https://github.com/realm/realm-js/issues/6359
// (This is due to catching the above error within this write transaction.)
//@ts-expect-error TYPEBUG: our List type-definition expects index accesses to be done with a number , should probably be extended.
expect(prim[name].length).equals(1);
elle-j marked this conversation as resolved.
Show resolved Hide resolved
expect(prim[name].length).equals(0);
// expect(prim[name].length).equals(1);
}

testAssignNull("bool", "a boolean");
Expand Down
Loading
Loading