Skip to content

Commit

Permalink
RJS-1413: Add support for a logical counter as a presentation data ty…
Browse files Browse the repository at this point in the history
…pe (#6694)

* Group schema normalization tests into suites.

* Allow 'counter' in schema parser.

* Test schema parser with 'counter'.

* Add Counter class.

* Implement creating a counter on Realm object.

* Add implementation to Counter.

* Expose Core's 'add_int()'.

* Add object property getter.

* Export types.

* Test create and access via 'realm.create()' (input: nums and Counter).

* Test create and access via 'realm.create()' (input: collections).

* Test create and access via collection accessors.

* Test updating the counter value.

* Test updating the Realm object counter property.

* Move common logic to shared functions.

* Test updating the Realm object collection property.

* Test returning different reference for each access.

* Test throwing when updating by non-integer.

* Change how a counter should be defined in the schema.

We originally decided on using 'counter' as its own primitive type (defined e.g. "type: 'counter'"). We have updated this to now use a 'presentation' type (e.g. "type: 'int', presentation: 'counter'").

* Rename test property.

* Add 'skips' to tests that await implementation.

* Add 'presentations' to the stored sdk-specifc schema info.

* Add 'isCreating' argument to object property setters to disallow certain operations for counter.

* Test throwing when resetting via property setter.

* Test throwing outside transaction.

* Test throwing if setting regular int to counter.

* Test throwing if invalidated object.

* Extend 'Unmanaged' with Counter and allowing number.

* Throw custom message if getting value on invalid object.

* Implement 'Counter.set()'.

* Disallow counter as mixed.

* Test throwing if used as mixed.

* Test filtering.

* Fixing returning null if counter is null.

* Remove support for collections of counters.

* Test updating Realm object counter prop via UpdateMode.

* Fix Unmanaged type for Counter.

* Add Unmanaged RealmSet.

* Update API docs.

* Remove implicit coercion to number due to TS not supporting it.

For reference on lack of TS support, see: microsoft/TypeScript#2361

* Test 'Realm.schema'.

* Replace 'Object.defineProperty' with Symbols.

* Add CHANGELOG entry.

* Change default value in test to non-zero.

* Test throwing when setting 'Counter.value' directly.

* Make 'describe' test names lowercase.

* List what is not supported onto the 'Counter' API docs.

* Move 'expectCounter' to common file.

* Remove link to API ref docs in CHANGELOG if doing RC release.

* Refactor a test to use `map` instead of for-loop

Co-authored-by: Kræn Hansen <[email protected]>

* Update error message from 'floating point' to 'decimal'.

* [12.10.0-rc.0] Bump version (#6696)

Co-authored-by: elle-j <[email protected]>

* Prepare for vNext (#6697)

Co-authored-by: elle-j <[email protected]>

* Update formatting.

* Update test variable name.

* Add links in CHANGELOG.

Co-authored-by: Kenneth Geisshirt <[email protected]>

* Update API docs formatting.

* Update initial value in test from 0 to 10.

* Refactor similar tests into for-loop.

* Point to Core v14.10.0.

* Update Counter API docs.

* Remove redundant comment.

* Refactor logic allowing/disallowing setting a counter.

* Update type name w/o abbreviation

Co-authored-by: Kræn Hansen <[email protected]>

* Fix CHANGELOG after merge.

---------

Co-authored-by: Kræn Hansen <[email protected]>
Co-authored-by: Yavor Georgiev <[email protected]>
Co-authored-by: elle-j <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Kenneth Geisshirt <[email protected]>
  • Loading branch information
6 people authored Jun 12, 2024
1 parent 809dcbf commit f034f92
Show file tree
Hide file tree
Showing 29 changed files with 2,548 additions and 1,040 deletions.
44 changes: 42 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
* Reduce the size of the local transaction log produced by creating objects, improving the performance of insertion-heavy transactions. ([realm/realm-core#7734](https://github.com/realm/realm-core/pull/7734))

### Fixed
* A non-streaming progress notifier would not immediately call its callback after registration. Instead you would have to wait for a download message to be received to get your first update - if you were already caught up when you registered the notifier you could end up waiting a long time for the server to deliver a download that would call/expire your notifier. ([#7627](https://github.com/realm/realm-core/issues/7627), since v12.8.0)
* After compacting, a file upgrade would be triggered. This could cause loss of data for synced Realms. ([realm/realm-core#7747](https://github.com/realm/realm-core/issues/7747), since 12.7.0-rc.0)
* The function `immediatelyRunFileActions` was not added to the bindgen's opt-list. This could lead to the error `TypeError: app.internal.immediatelyRunFileActions is not a function`. ([#6708](https://github.com/realm/realm-js/issues/6708), since v12.8.0)
* Encrypted files on Windows had a maximum size of 2 GB even on x64 due to internal usage of `off_t`, which is a 32-bit type on 64-bit Windows. ([realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698), since the introduction of encryption support on Windows - likely in v1.11.0)
* Tokenizing strings for full-text search could lead to undefined behavior. ([realm/realm-core#7698](https://github.com/realm/realm-core/pull/7698), since v11.3.0-rc.0)


### Compatibility
* React Native >= v0.71.4
* Realm Studio v15.0.0.
Expand All @@ -23,6 +21,48 @@
### Internal
* Upgraded Realm Core from v14.7.0 to v14.10.0. ([#6701](https://github.com/realm/realm-js/issues/6701))

## 12.10.0-rc.0 (2024-05-31)

### Enhancements
* A `counter` presentation data type has been introduced. The `int` data type can now be used as a logical counter for performing numeric updates that need to be synchronized as sequentially consistent events rather than individual reassignments of the number. ([#6694](https://github.com/realm/realm-js/pull/6694))
* See the [API docs](https://www.mongodb.com/docs/realm-sdks/js/latest/classes/Realm.Types.Counter.html) for more information about the usage, or get a high-level introduction about counters in the [documentation](https://www.mongodb.com/docs/atlas/app-services/sync/details/conflict-resolution/#counters).
```typescript
class MyObject extends Realm.Object {
_id!: BSON.ObjectId;
counter!: Realm.Types.Counter;

static schema: ObjectSchema = {
name: "MyObject",
primaryKey: "_id",
properties: {
_id: { type: "objectId", default: () => new BSON.ObjectId() },
counter: "counter",
// or: counter: { type: "int", presentation: "counter" },
},
};
}

const realm = await Realm.open({ schema: [MyObject] });
const object = realm.write(() => {
return realm.create(MyObject, { counter: 0 });
});

realm.write(() => {
object.counter.increment();
object.counter.value; // 1
object.counter.decrement(2);
object.counter.value; // -1
});
```

### Fixed
* A non-streaming progress notifier would not immediately call its callback after registration. Instead you would have to wait for a download message to be received to get your first update - if you were already caught up when you registered the notifier you could end up waiting a long time for the server to deliver a download that would call/expire your notifier. ([#7627](https://github.com/realm/realm-core/issues/7627), since v12.8.0)

### Compatibility
* React Native >= v0.71.4
* Realm Studio v15.0.0.
* File format: generates Realms with format v24 (reads and upgrades file format v10).

## 12.9.0 (2024-05-23)

### Enhancements
Expand Down
1 change: 1 addition & 0 deletions integration-tests/tests/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import "./tests/alias";
import "./tests/array-buffer";
import "./tests/bson";
import "./tests/class-models";
import "./tests/counter";
import "./tests/dictionary";
import "./tests/dynamic-schema-updates";
import "./tests/enums";
Expand Down
Loading

0 comments on commit f034f92

Please sign in to comment.