From 849b6266efca0929dcc7613b074d23a0bdc8a2ac Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 5 May 2021 20:55:22 -0400 Subject: [PATCH 01/29] New data types node rn (#1040) * new data types for node * added data types to TOC Co-authored-by: Mohammad Hunan Chughtai --- source/sdk/node.txt | 1 + source/sdk/node/data-types.txt | 29 +++++++++++++++++++ source/sdk/node/data-types/collections.txt | 16 ++++++++++ source/sdk/node/data-types/dictionaries.txt | 18 ++++++++++++ .../sdk/node/data-types/embedded-objects.txt | 13 +++++++++ source/sdk/node/data-types/field-types.txt | 16 ++++++++++ source/sdk/node/data-types/mixed.txt | 17 +++++++++++ source/sdk/node/data-types/sets.txt | 18 ++++++++++++ source/sdk/node/data-types/uuid.txt | 17 +++++++++++ 9 files changed, 145 insertions(+) create mode 100644 source/sdk/node/data-types/collections.txt create mode 100644 source/sdk/node/data-types/dictionaries.txt create mode 100644 source/sdk/node/data-types/embedded-objects.txt create mode 100644 source/sdk/node/data-types/field-types.txt create mode 100644 source/sdk/node/data-types/mixed.txt create mode 100644 source/sdk/node/data-types/sets.txt create mode 100644 source/sdk/node/data-types/uuid.txt diff --git a/source/sdk/node.txt b/source/sdk/node.txt index 71100930c5..c205fa7d31 100644 --- a/source/sdk/node.txt +++ b/source/sdk/node.txt @@ -12,6 +12,7 @@ MongoDB Realm Node.js SDK Quick Start Quick Start with Sync Fundamentals + Data Types Usage Examples Integration Guides Advanced Guides diff --git a/source/sdk/node/data-types.txt b/source/sdk/node/data-types.txt index 983cc3d950..af7774d7af 100644 --- a/source/sdk/node/data-types.txt +++ b/source/sdk/node/data-types.txt @@ -1,3 +1,32 @@ +.. _node-data-types: + ============================== Realm Data Types - Node.js SDK ============================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. toctree:: + :titlesonly: + :hidden: + + Field Types + Collections + Dictionaries + Sets + Mixed + UUID + Embedded Objects + +- :doc:`Field Types ` +- :doc:`Collections ` +- :doc:`Dictionaries ` +- :doc:`Sets ` +- :doc:`Mixed ` +- :doc:`UUID ` +- :doc:`Embedded Objects ` \ No newline at end of file diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt new file mode 100644 index 0000000000..bf8be9eead --- /dev/null +++ b/source/sdk/node/data-types/collections.txt @@ -0,0 +1,16 @@ +.. _node-collections: + +========================= +Collections - Node.js SDK +========================= + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- \ No newline at end of file diff --git a/source/sdk/node/data-types/dictionaries.txt b/source/sdk/node/data-types/dictionaries.txt new file mode 100644 index 0000000000..de4a5419d3 --- /dev/null +++ b/source/sdk/node/data-types/dictionaries.txt @@ -0,0 +1,18 @@ +.. _node-dictionaries: + +========================== +Dictionaries - Node.js SDK +========================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- \ No newline at end of file diff --git a/source/sdk/node/data-types/embedded-objects.txt b/source/sdk/node/data-types/embedded-objects.txt new file mode 100644 index 0000000000..53d6e002b7 --- /dev/null +++ b/source/sdk/node/data-types/embedded-objects.txt @@ -0,0 +1,13 @@ +.. _node-embedded-objects: + +============================== +Embedded Objects - Node.js SDK +============================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt new file mode 100644 index 0000000000..e3685b3eb4 --- /dev/null +++ b/source/sdk/node/data-types/field-types.txt @@ -0,0 +1,16 @@ +.. _node-field-types: + +========================= +Field Types - Node.js SDK +========================= + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + + +{+client-database+} supports the following field data types: diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt new file mode 100644 index 0000000000..4c2748f733 --- /dev/null +++ b/source/sdk/node/data-types/mixed.txt @@ -0,0 +1,17 @@ +.. _node-mixed: + +=================== +Mixed - Node.js SDK +=================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- \ No newline at end of file diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt new file mode 100644 index 0000000000..513981ba76 --- /dev/null +++ b/source/sdk/node/data-types/sets.txt @@ -0,0 +1,18 @@ +.. _node-sets: + +================== +Sets - Node.js SDK +================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- \ No newline at end of file diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt new file mode 100644 index 0000000000..739a842f36 --- /dev/null +++ b/source/sdk/node/data-types/uuid.txt @@ -0,0 +1,17 @@ +.. _node-uuid: + +================== +UUID - Node.js SDK +================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- \ No newline at end of file From d9d42cd4b5ba3af04ba74ffb34b6f23a9ee34a6e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 5 May 2021 23:13:45 -0400 Subject: [PATCH 02/29] fixed refs for node.js data types --- source/sdk/node/data-types/collections.txt | 2 +- source/sdk/node/data-types/dictionaries.txt | 2 +- source/sdk/node/data-types/embedded-objects.txt | 2 +- source/sdk/node/data-types/field-types.txt | 2 +- source/sdk/node/data-types/mixed.txt | 2 +- source/sdk/node/data-types/sets.txt | 2 +- source/sdk/node/data-types/uuid.txt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index bf8be9eead..d754879064 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -1,4 +1,4 @@ -.. _node-collections: +.. _node-data-types-collections: ========================= Collections - Node.js SDK diff --git a/source/sdk/node/data-types/dictionaries.txt b/source/sdk/node/data-types/dictionaries.txt index de4a5419d3..b0dc026ce2 100644 --- a/source/sdk/node/data-types/dictionaries.txt +++ b/source/sdk/node/data-types/dictionaries.txt @@ -1,4 +1,4 @@ -.. _node-dictionaries: +.. _node-data-types-dictionaries: ========================== Dictionaries - Node.js SDK diff --git a/source/sdk/node/data-types/embedded-objects.txt b/source/sdk/node/data-types/embedded-objects.txt index 53d6e002b7..c1ff8fd4cb 100644 --- a/source/sdk/node/data-types/embedded-objects.txt +++ b/source/sdk/node/data-types/embedded-objects.txt @@ -1,4 +1,4 @@ -.. _node-embedded-objects: +.. _node-data-types-embedded-objects: ============================== Embedded Objects - Node.js SDK diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index e3685b3eb4..f9b36305cc 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -1,4 +1,4 @@ -.. _node-field-types: +.. _node-data-types-field-types: ========================= Field Types - Node.js SDK diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 4c2748f733..06a5d9b3fa 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -1,4 +1,4 @@ -.. _node-mixed: +.. _node-data-types-mixed: =================== Mixed - Node.js SDK diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 513981ba76..5dc7b5b845 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -1,4 +1,4 @@ -.. _node-sets: +.. _node-data-types-sets: ================== Sets - Node.js SDK diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index 739a842f36..b0a3a597ab 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -1,4 +1,4 @@ -.. _node-uuid: +.. _node-data-types-uuid: ================== UUID - Node.js SDK From 765c5113f60d67b1f8b9b27a6ea9d1998a671c84 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 6 May 2021 10:21:40 -0400 Subject: [PATCH 03/29] update doc --- source/sdk/node/data-types/collections.txt | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index d754879064..d6072bd327 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -13,4 +13,32 @@ Collections - Node.js SDK :class: singlecol Overview --------- \ No newline at end of file +-------- + +{+service-short+} has several types to represent groups of objects, +which we call **collections**. A collection is an object that contains +zero or more instances of one :ref:`{+service-short+} type +`. {+service-short+} collections are **homogenous**: +all objects in a collection are of the same type. + +You can filter and sort any collection using {+client-database+}'s +:ref:`query engine `. Collections are +:ref:`live `, so they always reflect the current state +of the :term:`{+realm+} instance` on the current thread. You can also +listen for changes in the collection by subscribing to :ref:`collection +notifications `. + +Lists +----- + + +Overview +Lists & LinkingObjects +Results Collection +Results are Lazily Evaluated +Collections are Live +Working With Collections + Iteration + Limiting Query Results + Pagination +Summary \ No newline at end of file From bbc78176af7129eb220440eb698fe5ff2e7082b7 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 6 May 2021 10:22:41 -0400 Subject: [PATCH 04/29] Remove accidental changes --- source/sdk/node/data-types/collections.txt | 28 ---------------------- 1 file changed, 28 deletions(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index d6072bd327..f0675fafbd 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -14,31 +14,3 @@ Collections - Node.js SDK Overview -------- - -{+service-short+} has several types to represent groups of objects, -which we call **collections**. A collection is an object that contains -zero or more instances of one :ref:`{+service-short+} type -`. {+service-short+} collections are **homogenous**: -all objects in a collection are of the same type. - -You can filter and sort any collection using {+client-database+}'s -:ref:`query engine `. Collections are -:ref:`live `, so they always reflect the current state -of the :term:`{+realm+} instance` on the current thread. You can also -listen for changes in the collection by subscribing to :ref:`collection -notifications `. - -Lists ------ - - -Overview -Lists & LinkingObjects -Results Collection -Results are Lazily Evaluated -Collections are Live -Working With Collections - Iteration - Limiting Query Results - Pagination -Summary \ No newline at end of file From 905430875e97ff6a2204ae3222a3bb5200694c91 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 6 May 2021 15:48:44 -0400 Subject: [PATCH 05/29] added empty test file --- examples/node/Examples/data-types.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/node/Examples/data-types.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js new file mode 100644 index 0000000000..dd899119fe --- /dev/null +++ b/examples/node/Examples/data-types.js @@ -0,0 +1,4 @@ +import Realm from "realm"; + +describe("Node.js Data Types", () => { +}) \ No newline at end of file From c894f77f0f025d03dcb3f6ec77f548ee93f48a00 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 10:47:54 -0400 Subject: [PATCH 06/29] (DOCSP-15613): Added Node.js field types (#1041) * Added node.js field types * fixed wording * fixed typo * fix typo in mdn urls * added additional data types * fix monospace err Co-authored-by: Mohammad Hunan Chughtai --- source/sdk/node/data-types/field-types.txt | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index f9b36305cc..9037883fa7 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -1,16 +1,24 @@ .. _node-data-types-field-types: -========================= -Field Types - Node.js SDK -========================= - +======================== +Field Types -Node.js SDK +======================== .. default-domain:: mongodb - .. contents:: On this page :local: :backlinks: none :depth: 2 :class: singlecol - {+client-database+} supports the following field data types: + +- ``bool`` maps to the JavaScript :mdn:`Boolean ` type +- ``int`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``int`` with 64 bits. +- ``float`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``float`` with 32 bits. +- ``double`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``double`` with 64 bits. +- ``string`` maps to the JavaScript :mdn:`String ` type. +- ``decimal128`` for high precision numbers. +- ``objectId`` maps to BSON :manual:`ObjectId ` type. +- ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. +- ``date`` maps to the JavaScript :mdn:`Date ` type. +- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. \ No newline at end of file From 27552068b28effe1060b55243efb11c765d3f92c Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 11:14:27 -0400 Subject: [PATCH 07/29] (DOCSP-15613): Node.js collections type (#1044) * Add content to Node.js > Data Types > Collections.txt * Removed unneeded spacing * clean up collections page + add headers * Filled out collections page * fix refs * fix typo * Update source/sdk/node/data-types/collections.txt * Update source/sdk/node/data-types/collections.txt * Update source/sdk/node/data-types/collections.txt Co-authored-by: Dachary * fix rst * fix woridng * added ref * removed unneeded word * removed unneeded word * added period Co-authored-by: Mohammad Hunan Chughtai Co-authored-by: Dachary --- source/sdk/node/data-types/collections.txt | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index f0675fafbd..22faee6f5c 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -14,3 +14,125 @@ Collections - Node.js SDK Overview -------- + +{+service-short+} has several types to represent groups of objects, +which we call **collections**. A collection is an object that contains +zero or more instances of one :ref:`{+service-short+} type +`. {+service-short+} collections are **homogenous**: +all objects in a collection are of the same type. + +You can filter and sort any collection using {+client-database+}'s +:ref:`query engine `. Collections are +:ref:`live `, so they always reflect the current state +of the :term:`{+realm+} instance` on the current thread. You can also +listen for changes in the collection by subscribing to :ref:`collection +notifications `. + +.. _node-realm-results: + +Results +------- +A :js-sdk:`Results ` collection represents the +lazily-evaluated results of a query operation. Results are immutable: +you cannot add or remove elements to or from the results collection. +Results have an associated query that determines their contents. + +.. seealso:: + + :ref:`Reads ` + +.. _node-realm-list: + +Lists +----- +A :js-sdk:`List ` represents a :ref:`to-many +relationship ` between two {+service-short+} +types. Lists are mutable: within a write transaction, you can add and +remove elements to and from a list. Lists are not associated with a +query and are declared as a property of an :ref:`object model +`. + +.. seealso:: + + :ref:`To-Many Relationships ` + +.. _node-lazy-evaluated-results: + +Results are Lazily Evaluated +---------------------------- +{+client-database+} only runs a query when you request the +results of that query. This lazy evaluation enables you to write +elegant, highly-performant code for handling large data sets and complex +queries. + +.. _node-live-collections: + +Collections are Live +-------------------- +Like :ref:`live objects `, {+service-short+} collections +are usually **live**: + +- Live results collections always reflect the current results of the associated query. +- Live lists always reflect the current state of the relationship on the {+realm+} instance. + +A collection is **not** live when: + +- it is a :ref:`results collection ` that you are iterating through using a :mdn:`for..in ` or :mdn:`for..of ` statement. Both statements will continue to iterate through objects in the collection even if you have deleted or modified the collection's objects to exclude them from the filter that produced the results collection. +- the collection is a frozen :js-sdk:`Results.snapshot() `. + +Combined with :ref:`collection notifications +`, live collections enable +reactive code. For example, suppose your view displays the +results of a query. You can keep a reference to the results +collection in your view class, then read the results +collection as needed without having to refresh it or +validate that it is up-to-date. + +.. important:: Indexes may change + + Since results update themselves automatically, do not + store the positional index of an object in the collection + or the count of objects in a collection. The stored index + or count value could be outdated by the time you use + it. + +.. _node-working-with-collections: + +Working With Collections +------------------------ + +.. _node-limiting-query-results: + +Limiting Query Results +~~~~~~~~~~~~~~~~~~~~~~ +As a result of lazy evaluation, you do not need any special +mechanism to limit query results with {+client-database+}. For example, if +your query matches thousands of objects, but you only want +to load the first ten, access only the first ten +elements of the results collection. + +.. _node-realm-result-pagination: + +Pagination +~~~~~~~~~~ +Thanks to lazy evaluation, the common task of pagination +becomes quite simple. For example, suppose you have a +results collection associated with a query that matches +thousands of objects in your {+realm+}. You display one hundred +objects per page. To advance to any page, simply access the +elements of the results collection starting at the index +that corresponds to the target page. + +Summary +------- +- A {+service-short+} **collection** is a homogenous container of zero + or more instances of one + :ref:`{+service-short+} type `. +- There are two main kinds of collection: **lists** and **results**. + Lists define the :ref:`to-many relationships ` + of your {+service-short+} types, while results represent the + lazily-loaded output of a :ref:`read operation `. +- Lazy evaluation of results collections means there is no need to + design a special query to get limited or paginated results. Perform + the query and read from the results collection as needed. +- Data in {+service-short+} is *live*, which means that an object always reflects its most recent saved state. From b79ffbc1a4c7afad89b51580e2654cd1b44bcbd7 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 11:20:22 -0400 Subject: [PATCH 08/29] (DOCSP-15613): Node.js embedded objects type (#1047) * Added documentation of Node.js embedded objects under data types * clean up relationships and embedded objects * added CRUD examples for embedded obj * added bluehawked examples * fix rst syntax highlight + add description for deletes * Update source/sdk/node/data-types/embedded-objects.txt * Update source/sdk/node/data-types/embedded-objects.txt * Update source/sdk/node/data-types/embedded-objects.txt * Update source/sdk/node/data-types/embedded-objects.txt * Update source/sdk/node/data-types/embedded-objects.txt Co-authored-by: Mohammad Hunan Chughtai --- examples/node/Examples/data-types.js | 126 +++++++++++++++++- ...pes.codeblock.create-an-embedded-object.js | 15 +++ ...types.codeblock.define-embedded-objects.js | 30 +++++ ...pes.codeblock.delete-an-embedded-object.js | 6 + ....codeblock.overwrite-an-embedded-object.js | 11 ++ ...ypes.codeblock.query-an-embedded-object.js | 4 + ...pes.codeblock.update-an-embedded-object.js | 9 ++ .../sdk/node/data-types/embedded-objects.txt | 107 +++++++++++++++ .../relationships-and-embedded-objects.txt | 62 +-------- 9 files changed, 310 insertions(+), 60 deletions(-) create mode 100644 source/examples/generated/node/data-types.codeblock.create-an-embedded-object.js create mode 100644 source/examples/generated/node/data-types.codeblock.define-embedded-objects.js create mode 100644 source/examples/generated/node/data-types.codeblock.delete-an-embedded-object.js create mode 100644 source/examples/generated/node/data-types.codeblock.overwrite-an-embedded-object.js create mode 100644 source/examples/generated/node/data-types.codeblock.query-an-embedded-object.js create mode 100644 source/examples/generated/node/data-types.codeblock.update-an-embedded-object.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index dd899119fe..da25932bb6 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -1,4 +1,128 @@ import Realm from "realm"; +import BSON from "bson"; +// :code-block-start: define-embedded-objects +const AddressSchema = { + name: "Address", + embedded: true, // default: false + properties: { + street: "string?", + city: "string?", + country: "string?", + postalCode: "string?", + }, +}; + +const ContactSchema = { + name: "Contact", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + address: "Address", // Embed a single object + }, +}; + +const BusinessSchema = { + name: "Business", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + addresses: { type: "list", objectType: "Address" }, // Embed an array of objects + }, +}; +// :code-block-end: describe("Node.js Data Types", () => { -}) \ No newline at end of file + test("should create and read and delete an embedded object", async () => { + const realm = await Realm.open({ + schema: [AddressSchema, ContactSchema], + }); + + // :code-block-start: create-an-embedded-object + // create an embedded address object + const sydneyOrthodontics = { + street: "42 Wallaby Way", + city: "Sydney", + country: "Australia", + postalCode: "2774", + }; + realm.write(() => { + // create a contact object + realm.create("Contact", { + _id: new BSON.ObjectId(), + name: "Philip Sherman", + address: sydneyOrthodontics, // embed the address in the contact object + }); + }); + // :code-block-end: + + // :code-block-start: query-an-embedded-object + const philipShermanAddress = realm + .objects("Contact") + .filtered("name = 'Philip Sherman'")[0].address.street; + console.log(`Philip Sherman's address is ${philipShermanAddress}`); + // :code-block-end: + expect(philipShermanAddress).toBe("42 Wallaby Way"); // this assertion tests both the 'query-an-embedded-object' and 'create-an-embedded-object' code blocks + + // // :code-block-start: delete-an-embedded-object + realm.write(() => { + // Deleting the contact will delete the embedded address of that contact + realm.delete( + realm.objects("Contact").filtered("name = 'Philip Sherman'") + ); + }); + // :code-block-end: + + // close the realm + realm.close(); + }); + // update and delete an embedded object + test("should update and overwrite an embedded object", async () => { + const realm = await Realm.open({ + schema: [AddressSchema, ContactSchema], + }); + const harryAddress = { + street: "4 Privet Drive", + city: "Little Whinging, Surrey", + country: "UK", + postalCode: "WD4 8PN", + }; + realm.write(() => { + realm.create("Contact", { + _id: new BSON.ObjectId(), + name: "Harry Potter", + address: harryAddress, + }); + }); + + // :code-block-start: update-an-embedded-object + // Find the contact with the address you want to update + const harryPotter = realm + .objects("Contact") + .filtered("name = 'Harry Potter'")[0]; + // modify the property of the embedded object in a write transaction + realm.write(() => { + // update the embedded object directly through the contact + harryPotter.address.street = "1 Hogwarts Ave"; + }); + // :code-block-end: + expect(harryPotter.address.street).toBe("1 Hogwarts Ave"); + + // :code-block-start: overwrite-an-embedded-object + // create a new address + const harryNewAddress = { + street: "12 Grimmauld Place", + city: "London", + country: "UK", + postalCode: "E1 7AA", + }; + realm.write(() => { + // overwrite the embedded object with the new address within a write transaction + harryPotter.address = harryNewAddress; + }); + // :code-block-end: + + expect(harryPotter.address.city).toBe("London"); + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.create-an-embedded-object.js b/source/examples/generated/node/data-types.codeblock.create-an-embedded-object.js new file mode 100644 index 0000000000..90e3da5afa --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.create-an-embedded-object.js @@ -0,0 +1,15 @@ +// create an embedded address object +const sydneyOrthodontics = { + street: "42 Wallaby Way", + city: "Sydney", + country: "Australia", + postalCode: "2774", +}; +realm.write(() => { + // create a contact object + realm.create("Contact", { + _id: new BSON.ObjectId(), + name: "Philip Sherman", + address: sydneyOrthodontics, // embed the address in the contact object + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.define-embedded-objects.js b/source/examples/generated/node/data-types.codeblock.define-embedded-objects.js new file mode 100644 index 0000000000..7e5cc09651 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.define-embedded-objects.js @@ -0,0 +1,30 @@ +const AddressSchema = { + name: "Address", + embedded: true, // default: false + properties: { + street: "string?", + city: "string?", + country: "string?", + postalCode: "string?", + }, +}; + +const ContactSchema = { + name: "Contact", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + address: "Address", // Embed a single object + }, +}; + +const BusinessSchema = { + name: "Business", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + addresses: { type: "list", objectType: "Address" }, // Embed an array of objects + }, +}; diff --git a/source/examples/generated/node/data-types.codeblock.delete-an-embedded-object.js b/source/examples/generated/node/data-types.codeblock.delete-an-embedded-object.js new file mode 100644 index 0000000000..48f719d4f8 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.delete-an-embedded-object.js @@ -0,0 +1,6 @@ +realm.write(() => { + // Deleting the contact will delete the embedded address of that contact + realm.delete( + realm.objects("Contact").filtered("name = 'Philip Sherman'") + ); +}); diff --git a/source/examples/generated/node/data-types.codeblock.overwrite-an-embedded-object.js b/source/examples/generated/node/data-types.codeblock.overwrite-an-embedded-object.js new file mode 100644 index 0000000000..50960d315b --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.overwrite-an-embedded-object.js @@ -0,0 +1,11 @@ +// create a new address +const harryNewAddress = { + street: "12 Grimmauld Place", + city: "London", + country: "UK", + postalCode: "E1 7AA", +}; +realm.write(() => { + // overwrite the embedded object with the new address within a write transaction + harryPotter.address = harryNewAddress; +}); diff --git a/source/examples/generated/node/data-types.codeblock.query-an-embedded-object.js b/source/examples/generated/node/data-types.codeblock.query-an-embedded-object.js new file mode 100644 index 0000000000..14657f0bcc --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.query-an-embedded-object.js @@ -0,0 +1,4 @@ +const philipShermanAddress = realm + .objects("Contact") + .filtered("name = 'Philip Sherman'")[0].address.street; +console.log(`Philip Sherman's address is ${philipShermanAddress}`); diff --git a/source/examples/generated/node/data-types.codeblock.update-an-embedded-object.js b/source/examples/generated/node/data-types.codeblock.update-an-embedded-object.js new file mode 100644 index 0000000000..02680cc8dd --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.update-an-embedded-object.js @@ -0,0 +1,9 @@ +// Find the contact with the address you want to update +const harryPotter = realm + .objects("Contact") + .filtered("name = 'Harry Potter'")[0]; +// modify the property of the embedded object in a write transaction +realm.write(() => { + // update the embedded object directly through the contact + harryPotter.address.street = "1 Hogwarts Ave"; +}); diff --git a/source/sdk/node/data-types/embedded-objects.txt b/source/sdk/node/data-types/embedded-objects.txt index c1ff8fd4cb..f807b0f465 100644 --- a/source/sdk/node/data-types/embedded-objects.txt +++ b/source/sdk/node/data-types/embedded-objects.txt @@ -11,3 +11,110 @@ Embedded Objects - Node.js SDK :backlinks: none :depth: 2 :class: singlecol + +Overview +-------- + +An embedded object is a special type of :ref:`Realm object ` +that models complex data about a specific object. Embedded objects are similar +to :ref:`relationships `, but they provide additional +constraints and map more naturally to the denormalized :manual:`MongoDB document +model `. + +Realm enforces unique ownership constraints that treat each embedded object as +nested data inside a single, specific parent object. An embedded object +inherits the lifecycle of its parent object and cannot exist as an independent +Realm object. This means that embedded objects cannot have a primary key and +that Realm automatically deletes embedded objects if their parent object is +deleted. + +.. tip:: Embedded object types are reusable and composable + + You can use the same embedded object type in multiple parent object types, and + you can embed objects inside other embedded objects. You can even + recursively reference an embedded object type as an optional property in its + own definition. + +.. note:: Realm Uses Cascading Deletes for Embedded Objects + + When you delete a Realm object, Realm automatically deletes any + embedded objects referenced by that object. Any objects that your + application must persist after the deletion of their parent object + should use :ref:`relationships ` + instead. + +Realm Object Models +~~~~~~~~~~~~~~~~~~~ + +To define an embedded object, set ``embedded`` +to ``true``. You can reference an embedded object type from parent object types +in the same way as you would define a relationship: + +.. important:: + + Embedded objects cannot have a :ref:`primary key `. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-embedded-objects.js + :language: javascript + :emphasize-lines: 3, 18, 28 + + +JSON Schema +~~~~~~~~~~~ + +.. include:: /includes/embedded-object-json-schema.rst + + +Read and Write Embedded Objects +------------------------------- + +Create an Embedded Object +~~~~~~~~~~~~~~~~~~~~~~~~~ + +To create an embedded object, assign an instance of the embedded object +to a parent object's property: + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-an-embedded-object.js + :language: javascript + +Update an Embedded Object Property +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To update a property in an embedded object, modify the property in a +write transaction: + +.. literalinclude:: /examples/generated/node/data-types.codeblock.update-an-embedded-object.js + :language: javascript + + +Overwrite an Embedded Object +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To overwrite an embedded object, reassign the embedded object property +of a party to a new instance in a write transaction: + +.. literalinclude:: /examples/generated/node/data-types.codeblock.overwrite-an-embedded-object.js + :language: javascript + + +Query a Collection on Embedded Object Properties +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Use dot notation to filter or sort a :ref:`collection +` of objects based on an embedded object +property value: + +.. include:: /includes/directly-query-embedded-objects-note.rst + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-an-embedded-object.js + :language: javascript + + + +Delete an Embedded Object +~~~~~~~~~~~~~~~~~~~~~~~~~ +Realm Uses Cascading Deletes for Embedded Objects. To delete an embedded object, +delete the embedded object's parent. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.delete-an-embedded-object.js + :language: javascript diff --git a/source/sdk/node/fundamentals/relationships-and-embedded-objects.txt b/source/sdk/node/fundamentals/relationships-and-embedded-objects.txt index 6307b993a0..b3017716fb 100644 --- a/source/sdk/node/fundamentals/relationships-and-embedded-objects.txt +++ b/source/sdk/node/fundamentals/relationships-and-embedded-objects.txt @@ -175,62 +175,6 @@ to :ref:`relationships `, but they provide additional constraints and map more naturally to the denormalized :manual:`MongoDB document model `. -Realm enforces unique ownership constraints that treat each embedded object as -nested data inside of a single, specific parent object. An embedded object -inherits the lifecycle of its parent object and cannot exist as an independent -Realm object. This means that embedded objects cannot have a primary key and -that Realm automatically deletes embedded objects if their parent object is -deleted. - -.. tip:: Embedded object types are reusable and composable - - You can use the same embedded object type in multiple parent object types and - you can embed objects inside of other embedded objects. You can even - recursively reference an embedded object type as an optional property in its - own definition. - -Realm Object Models -~~~~~~~~~~~~~~~~~~~ - -To specify that a Realm object model define an embedded object, set ``embedded`` -to ``true``. You can reference an embedded object type from parent object types -in the same way as you would define a relationship: - -.. code-block:: javascript - :emphasize-lines: 3, 18, 28 - - const AddressSchema = { - name: "Address", - embedded: true, // default: false - properties: { - street: "string?", - city: "string?", - country: "string?", - postalCode: "string?", - }, - }; - - const ContactSchema = { - name: "Contact", - primaryKey: "_id", - properties: { - _id: "objectId", - name: "string", - address: "Address", // Embed a single object - }, - }; - - const BusinessSchema = { - name: "Business", - primaryKey: "_id", - properties: { - _id: "objectId", - name: "string", - addresses: { type: "list", objectType: "Address" }, // Embed an array of objects - }, - }; - -JSON Schema -~~~~~~~~~~~ - -.. include:: /includes/embedded-object-json-schema.rst +Learn more about :doc:`Embedded objects +`, including how to read and write +embedded objects. \ No newline at end of file From 24759744e8e34f26d8cd62b4872261ad8fcd9a02 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 11:57:17 -0400 Subject: [PATCH 09/29] Docsp 14569 mixed data type (#1064) * attempt to add bluehawked mixed example snippets * fixed wording * Update source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js * Update examples/node/Examples/data-types.js Co-authored-by: Mohammad Hunan Chughtai --- examples/node/Examples/data-types.js | 58 +++++++++++++++++++ ...eblock.create-objects-with-mixed-values.js | 20 +++++++ ...-types.codeblock.define-mixed-in-schema.js | 7 +++ ...deblock.query-objects-with-mixed-values.js | 4 ++ source/sdk/node/data-types/mixed.txt | 50 +++++++++++++++- 5 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js create mode 100644 source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js create mode 100644 source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index da25932bb6..78132c055f 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -34,6 +34,64 @@ const BusinessSchema = { }; // :code-block-end: describe("Node.js Data Types", () => { + test("should work with Mixed Type", async () => { + // :code-block-start: define-mixed-in-schema + const DogSchema = { + name: "Dog", + properties: { + name: "string", + birthDate: "mixed", + }, + }; + // :code-block-end: + + const realm = await Realm.open({ + schema: [DogSchema], + }); + + // :code-block-start: create-objects-with-mixed-values + realm.write(() => { + // create a Dog with a birthDate value of type string + realm.create("Dog", { name: "Euler", birthDate: "December 25th, 2017" }); + + // create a Dog with a birthDate value of type date + realm.create("Dog", { + name: "Blaise", + birthDate: new Date("August 17, 2020"), + }); + // create a Dog with a birthDate value of type int + realm.create("Dog", { + name: "Euclid", + birthDate: 10152021, + }); + // create a Dog with a birthDate value of type null + realm.create("Dog", { + name: "Pythagoras", + birthDate: null, + }); + }); + // :code-block-end: + + // :code-block-start: query-objects-with-mixed-values + // To query for Blaise's birthDate, filter for his name to retrieve the realm object. + // Use dot notation to access the birthDate property. + let blaiseBirthDate = realm.objects("Dog").filtered(`name = 'Blaise'`)[0] + .birthDate; + console.log(`Blaise's birth date is ${blaiseBirthDate}`); + // :code-block-end: + expect(blaiseBirthDate).toEqual(new Date("August 17, 2020")); + + // delete the objects specifically created in this test to keep tests idempotent + const Euler = realm.objects("Dog").filtered(`name = 'Euler'`)[0]; + const Blaise = realm.objects("Dog").filtered(`name = 'Blaise'`)[0]; + const Euclid = realm.objects("Dog").filtered(`name = 'Euclid'`)[0]; + const Pythagoras = realm.objects("Dog").filtered(`name = 'Pythagoras'`)[0]; + realm.write(() => { + realm.delete(Euler); + realm.delete(Blaise); + realm.delete(Euclid); + realm.delete(Pythagoras); + }); test("should create and read and delete an embedded object", async () => { const realm = await Realm.open({ schema: [AddressSchema, ContactSchema], diff --git a/source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js b/source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js new file mode 100644 index 0000000000..ab8b0517f0 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js @@ -0,0 +1,20 @@ +realm.write(() => { + // create a Dog with a birthDate value of type string + realm.create("Dog", { name: "Euler", birthDate: "December 25th, 2017" }); + + // create a Dog with a birthDate value of type date + realm.create("Dog", { + name: "Blaise", + birthDate: new Date("August 17, 2020"), + }); + // create a Dog with a birthDate value of type int + realm.create("Dog", { + name: "Euclid", + birthDate: 10152021, + }); + // create a Dog with a birthDate value of type null + realm.create("Dog", { + name: "Pythagoras", + birthDate: null, + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js b/source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js new file mode 100644 index 0000000000..50f8ee7229 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js @@ -0,0 +1,7 @@ +const DogSchema = { + name: "Dog", + properties: { + name: "string", + birthDate: "mixed", + }, +}; diff --git a/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js b/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js new file mode 100644 index 0000000000..cd3ea34e2f --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js @@ -0,0 +1,4 @@ +// To query for Blaise's birthDate, filter for his name to retrieve the realm object. +// Use dot notation to access the birthDate property. +let blaiseBirthDate = realm.objects("Dog").filtered(`name = 'Blaise'`)[0].birthDate; +console.log(`Blaise's birth date is ${blaiseBirthDate}`); diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 06a5d9b3fa..4b3e280228 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -14,4 +14,52 @@ Mixed - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- +The mixed data type is a {+realm+} property type that can hold different data types. +Supported data types include: + +- bool +- int +- float +- double +- string +- Date +- Data +- UUID +- Set +- null + +.. note:: + + The mixed data type is indexable, but you can't use it as a primary key. + Because null is a permitted value, you can't declare a Mixed property as + optional. + +Realm Object Models +------------------- +To :ref:`set a property of your object model +` as mixed, set the property's type to +``"mixed"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js + :language: javascript + +Create an Object With a Mixed Value +----------------------------------- +Create an object with a mixed value by running the :js-sdk:`realm.create() +` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js + :language: javascript + +Query for Objects with a Mixed Value +------------------------------------ +Query for objects with a mixed value by running the +:js-sdk:`Collection.filtered() ` method and +passing in a :ref:`filter ` for a non-mixed field. You can +then print the value of the mixed property or the entire object itself. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js + :language: javascript + + From efae8d09e60736e7724276a5a74122c5496b53d2 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 13 May 2021 01:50:56 -0400 Subject: [PATCH 10/29] (DOCSP-14565): Dictionary data type (#1058) * (DOCSP-14565): Dictionary Data Type - Node.js * added unit tested + bluehawked dictionary examples * Update examples/node/package.json * removed unneeded file * Added new examples for dictionaries * update dictionary examples * fix capitalization * moved addlistener down * fix comment * update wording to be clearer on type usage in dict * fix wording * fix wording Co-authored-by: Mohammad Hunan Chughtai --- examples/node/Examples/data-types.js | 118 +++- examples/node/package-lock.json | 605 ++++++++++-------- examples/node/package.json | 2 +- ...odeblock.add-a-listener-to-a-dictionary.js | 3 + ...eblock.create-realm-obj-with-dictionary.js | 21 + ...s.codeblock.define-dictionary-in-schema.js | 7 + ...data-types.codeblock.query-a-dictionary.js | 14 + ...deblock.remove-fields-of-the-dictionary.js | 4 + ...ng-new-dictionaries-to-existing-objects.js | 14 + ...ata-types.codeblock.update-a-dictionary.js | 8 + source/sdk/node/data-types/dictionaries.txt | 71 +- 11 files changed, 614 insertions(+), 253 deletions(-) create mode 100644 source/examples/generated/node/data-types.codeblock.add-a-listener-to-a-dictionary.js create mode 100644 source/examples/generated/node/data-types.codeblock.create-realm-obj-with-dictionary.js create mode 100644 source/examples/generated/node/data-types.codeblock.define-dictionary-in-schema.js create mode 100644 source/examples/generated/node/data-types.codeblock.query-a-dictionary.js create mode 100644 source/examples/generated/node/data-types.codeblock.remove-fields-of-the-dictionary.js create mode 100644 source/examples/generated/node/data-types.codeblock.setting-new-dictionaries-to-existing-objects.js create mode 100644 source/examples/generated/node/data-types.codeblock.update-a-dictionary.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 78132c055f..285ee631f6 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -33,7 +33,115 @@ const BusinessSchema = { }, }; // :code-block-end: + describe("Node.js Data Types", () => { + test("should create, update and query Realm dictionaries", async () => { + // :code-block-start: define-dictionary-in-schema + const PersonSchema = { + name: "Person", + properties: { + name: "string", + home: "{}", + }, + }; + // :code-block-end: + + const realm = await Realm.open({ + schema: [PersonSchema], + }); + + // :code-block-start: create-realm-obj-with-dictionary + let johnDoe; + let janeSmith; + realm.write(() => { + johnDoe = realm.create("Person", { + name: "John Doe", + home: { + windows: 5, + doors: 3, + color: "red", + address: "Summerhill St.", + price: 400123, + }, + }); + janeSmith = realm.create("Person", { + name: "Jane Smith", + home: { + address: "100 northroad st.", + yearBuilt: 1990, + }, + }); + }); + // :code-block-end: + + // :code-block-start: query-a-dictionary + // query for all Person objects + const persons = realm.objects("Person"); + + // run the `.filtered()` method on all the returned persons to find the house with the address "Summerhill St." + const summerHillHouse = persons.filtered( + `home['address'] = "Summerhill St."` + )[0].home; + + // Find all people that have a house with a listed price + const peopleWithHousesWithAListedPrice = persons.filtered( + `home.@keys = "price" ` + ); + // find a house that has any field with a value of 'red' + const redHouse = persons.filtered(`home.@values = "red" `)[0].home; + // :code-block-end: + + // the following assertion tests both creation of a dictionary + querying a dictionary + expect(peopleWithHousesWithAListedPrice.length).toBe(1); // there should only be one house with a listed price + expect(redHouse.doors).toBe(3); // the red house should have 3 doors + + let dictionaryListenerHasBeenCalled = false; + // :code-block-start: add-a-listener-to-a-dictionary + summerHillHouse.addListener((changedHouse, changes) => { + // :hide-start: + dictionaryListenerHasBeenCalled = true; + // :hide-end: + console.log("A change has occurred to the Summer Hill House object"); + }); + // :code-block-end: + + // :code-block-start: update-a-dictionary + realm.write(() => { + // use the `put()` method to update a field of a dictionary + summerHillHouse.put({ price: 400100 }); + // alternatively, update a field of a dictionary through dot notation + summerHillHouse.color = "brown"; + // update a dictionary by adding a field + summerHillHouse.yearBuilt = 2004; + }); + // :code-block-end: + + expect(dictionaryListenerHasBeenCalled).toBe(true); // a home (dictionary inside a realm object) should be able to have a change listener + expect(summerHillHouse.price).toBe(400100); // the summerHillHouse should be $400,100 now + expect(summerHillHouse.color).toBe("brown"); // the summerHillHouse should be brown now + expect(summerHillHouse.yearBuilt).toBe(2004); // the summerHillHouse should've been built in 2004 + + console.log(summerHillHouse); + // :code-block-start: remove-fields-of-the-dictionary + realm.write(() => { + // remove the 'windows' and 'doors' field of the Summerhill House. + // :uncomment-start: + // summerHillHouse.remove(["windows", "doors"]); + // :uncomment-end: + }); + // :code-block-end: + + // expect(summerHillHouse.windows).toBe(undefined); // since windows has been removed as a field, it should be undefined + // expect(summerHillHouse.doors).toBe(undefined); // since doors has been removed as a field, it should be undefined + + // delete the objects to keep the test idempotent + realm.write(() => { + realm.delete(johnDoe); + realm.delete(janeSmith); + }); + // close the realm to avoid memory leaks + realm.close(); + }); test("should work with Mixed Type", async () => { // :code-block-start: define-mixed-in-schema const DogSchema = { @@ -92,6 +200,9 @@ describe("Node.js Data Types", () => { realm.delete(Euclid); realm.delete(Pythagoras); }); + // close the realm + realm.close(); + }); test("should create and read and delete an embedded object", async () => { const realm = await Realm.open({ schema: [AddressSchema, ContactSchema], @@ -131,7 +242,6 @@ describe("Node.js Data Types", () => { ); }); // :code-block-end: - // close the realm realm.close(); }); @@ -182,5 +292,11 @@ describe("Node.js Data Types", () => { // :code-block-end: expect(harryPotter.address.city).toBe("London"); + // delete the object specifically created in this test to keep tests idempotent + realm.write(() => { + realm.delete(harryPotter); + }); + // close the realm + realm.close(); }); }); diff --git a/examples/node/package-lock.json b/examples/node/package-lock.json index 5442131d9d..b95a30bfe2 100644 --- a/examples/node/package-lock.json +++ b/examples/node/package-lock.json @@ -1513,11 +1513,6 @@ "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.5.tgz", "integrity": "sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q==" }, - "abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" - }, "abort-controller": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", @@ -1921,6 +1916,36 @@ "tweetnacl": "^0.14.3" } }, + "bindings": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz", + "integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ==", + "requires": { + "file-uri-to-path": "1.0.0" + } + }, + "bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "requires": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -2009,6 +2034,15 @@ "unset-value": "^1.0.0" } }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2192,6 +2226,11 @@ "safe-buffer": "~5.1.1" } }, + "cookiejar": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.2.tgz", + "integrity": "sha512-Mw+adcfzPxcPeI+0WlvRrr/3lGVO0bD75SxX6811cxSh1Wbxx7xZBGK1eVtDf6si8rg2lhnUjsVLMFMfbRIuwA==" + }, "copy-descriptor": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/copy-descriptor/-/copy-descriptor-0.1.1.tgz", @@ -2228,18 +2267,11 @@ } }, "cross-fetch": { - "version": "3.0.6", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.0.6.tgz", - "integrity": "sha512-KBPUbqgFjzWlVcURG+Svp9TlhA5uliYtiNx/0r8nv0pdypeQCRJ9IaSIc3q/x3q8t3F75cHuwxVql1HFGHCNJQ==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz", + "integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==", "requires": { "node-fetch": "2.6.1" - }, - "dependencies": { - "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" - } } }, "cross-spawn": { @@ -2315,6 +2347,14 @@ "resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz", "integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=" }, + "decompress-response": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-4.2.1.tgz", + "integrity": "sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==", + "requires": { + "mimic-response": "^2.0.0" + } + }, "deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", @@ -2467,24 +2507,6 @@ "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" }, - "encoding": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", - "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "requires": { - "iconv-lite": "^0.6.2" - }, - "dependencies": { - "iconv-lite": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.2.tgz", - "integrity": "sha512-2y91h5OpQlolefMPmUlivelittSWy0rP+oYVpn6A7GwVHNE8AWzoYOBNmlwks3LobaJxgHCYZAnyNo2GgpNRNQ==", - "requires": { - "safer-buffer": ">= 2.1.2 < 3.0.0" - } - } - } - }, "end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", @@ -3160,6 +3182,11 @@ } } }, + "expand-template": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-2.0.3.tgz", + "integrity": "sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==" + }, "expect": { "version": "26.5.3", "resolved": "https://registry.npmjs.org/expect/-/expect-26.5.3.tgz", @@ -3301,6 +3328,11 @@ "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, + "fast-safe-stringify": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz", + "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==" + }, "fastq": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.8.0.tgz", @@ -3345,6 +3377,11 @@ "flat-cache": "^2.0.1" } }, + "file-uri-to-path": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", + "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -3429,6 +3466,11 @@ "mime-types": "^2.1.12" } }, + "formidable": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.2.tgz", + "integrity": "sha512-V8gLm+41I/8kguQ4/o1D3RIHRmhYFG4pnNyonvua+40rqcEmT4+V71yaZ3B457xbbgCsCfjSPi65u/W6vK1U5Q==" + }, "fragment-cache": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz", @@ -3437,6 +3479,11 @@ "map-cache": "^0.2.2" } }, + "fs-constants": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", + "integrity": "sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==" + }, "fs-extra": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz", @@ -3448,11 +3495,11 @@ } }, "fs-minipass": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.7.tgz", - "integrity": "sha512-GWSSJGFy4e9GUeCcbIkED+bgAoFyj7XF1mV8rma3QW4NIqX9Kyx79N/PF61H5udOV3aY1IaMLs6pGbH71nlCTA==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", "requires": { - "minipass": "^2.6.0" + "minipass": "^3.0.0" } }, "fs.realpath": { @@ -3535,6 +3582,16 @@ "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" }, + "get-intrinsic": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", + "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1" + } + }, "get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", @@ -3566,6 +3623,11 @@ "assert-plus": "^1.0.0" } }, + "github-from-package": { + "version": "0.0.0", + "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", + "integrity": "sha1-l/tdlr/eiXMxPyDoKI75oWf6ZM4=" + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", @@ -3613,7 +3675,8 @@ "growly": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/growly/-/growly-1.3.0.tgz", - "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=" + "integrity": "sha1-8QdIy+dq+WS3yWyTxrzCivEgwIE=", + "optional": true }, "har-schema": { "version": "2.0.0", @@ -3759,9 +3822,9 @@ }, "dependencies": { "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", "requires": { "ms": "^2.1.1" } @@ -3791,14 +3854,6 @@ "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.8.tgz", "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==" }, - "ignore-walk": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.3.tgz", - "integrity": "sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw==", - "requires": { - "minimatch": "^3.0.4" - } - }, "import-fresh": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", @@ -3846,9 +3901,9 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "ini": { - "version": "1.3.7", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.7.tgz", - "integrity": "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==" + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", + "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==" }, "invariant": { "version": "2.2.4", @@ -4077,6 +4132,7 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "optional": true, "requires": { "is-docker": "^2.0.0" } @@ -5087,6 +5143,11 @@ "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==" }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, "micromatch": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.2.tgz", @@ -5096,6 +5157,11 @@ "picomatch": "^2.0.5" } }, + "mime": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.5.2.tgz", + "integrity": "sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg==" + }, "mime-db": { "version": "1.44.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", @@ -5114,6 +5180,11 @@ "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==" }, + "mimic-response": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-2.1.0.tgz", + "integrity": "sha512-wXqjST+SLt7R009ySCglWBCFpjUygmCIfD790/kVbiGmUgfYGuB14PiTd5DwVxSV4NcYHjzMkoj5LjQZwTQLEA==" + }, "minimatch": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", @@ -5128,20 +5199,20 @@ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "minipass": { - "version": "2.9.0", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.9.0.tgz", - "integrity": "sha512-wxfUjg9WebH+CUDX/CdbRlh5SmfZiy/hpkxaRI16Y9W56Pa75sWgd/rvFilSgrauD9NyFymP/+JFV3KwzIsJeg==", + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", + "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", "requires": { - "safe-buffer": "^5.1.2", - "yallist": "^3.0.0" + "yallist": "^4.0.0" } }, "minizlib": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.3.3.tgz", - "integrity": "sha512-6ZYMOEnmVsdCeTJVE0W9ZD+pVnE8h9Hma/iOwwRDsdQoePpoX56/8B6z3P9VNwppJuBKNRuFDRNRqRWexT9G9Q==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", "requires": { - "minipass": "^2.9.0" + "minipass": "^3.0.0", + "yallist": "^4.0.0" } }, "mixin-deep": { @@ -5167,10 +5238,16 @@ "version": "0.5.5", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "dev": true, "requires": { "minimist": "^1.2.5" } }, + "mkdirp-classic": { + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/mkdirp-classic/-/mkdirp-classic-0.5.3.tgz", + "integrity": "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==" + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -5194,49 +5271,38 @@ "to-regex": "^3.0.1" } }, + "napi-build-utils": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/napi-build-utils/-/napi-build-utils-1.0.2.tgz", + "integrity": "sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==" + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=" }, - "needle": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/needle/-/needle-2.5.2.tgz", - "integrity": "sha512-LbRIwS9BfkPvNwNHlsA41Q29kL2L/6VaOJ0qisM5lLWsTV3nP15abO5ITL6L81zqFhzjRKDAYjpcBcwM0AVvLQ==", - "requires": { - "debug": "^3.2.6", - "iconv-lite": "^0.4.4", - "sax": "^1.2.4" - }, - "dependencies": { - "debug": { - "version": "3.2.6", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", - "requires": { - "ms": "^2.1.1" - } - } - } - }, "nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" }, + "node-abi": { + "version": "2.26.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-2.26.0.tgz", + "integrity": "sha512-ag/Vos/mXXpWLLAYWsAoQdgS+gW7IwvgMLOgqopm/DbzAjazLltzgzpVMsFlgmo9TzG5hGXeaBZx2AI731RIsQ==", + "requires": { + "semver": "^5.4.1" + } + }, "node-addon-api": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.0.2.tgz", - "integrity": "sha512-+D4s2HCnxPd5PjjI0STKwncjXTUKKqm74MDMz9OPXavjsGmjkvwgLtA5yoxJUdmpj52+2u+RrXgPipahKczMKg==" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.1.0.tgz", + "integrity": "sha512-flmrDNB06LIl5lywUz7YlNGZH/5p0M7W28k8hzd9Lshtdh1wshD2Y+U4h9LD6KObOy1f+fEVdgprPrEymjM5uw==" }, "node-fetch": { - "version": "1.7.3", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", - "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", - "requires": { - "encoding": "^0.1.11", - "is-stream": "^1.0.1" - } + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" }, "node-int64": { "version": "0.4.0", @@ -5257,6 +5323,7 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", "integrity": "sha512-BvEXF+UmsnAfYfoapKM9nGxnP+Wn7P91YfXmrKnfcYCx6VBeoN5Ez5Ogck6I8Bi5k4RlpqRYaw75pAwzX9OphA==", + "optional": true, "requires": { "growly": "^1.3.0", "is-wsl": "^2.2.0", @@ -5270,6 +5337,7 @@ "version": "7.3.4", "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.4.tgz", "integrity": "sha512-tCfb2WLjqFAtXn4KEdxIhalnRtoKFN7nAwj0B3ZXCbQloV2tq5eDbcTmT68JJD3nRJq24/XgxtQKFIpQdtvmVw==", + "optional": true, "requires": { "lru-cache": "^6.0.0" } @@ -5278,66 +5346,22 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "optional": true, "requires": { "isexe": "^2.0.0" } } } }, - "node-pre-gyp": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.15.0.tgz", - "integrity": "sha512-7QcZa8/fpaU/BKenjcaeFF9hLz2+7S9AqyXFhlH/rilsQ/hPZKK32RtR5EQHJElgu+q5RfbJ34KriI79UWaorA==", - "requires": { - "detect-libc": "^1.0.2", - "mkdirp": "^0.5.3", - "needle": "^2.5.0", - "nopt": "^4.0.1", - "npm-packlist": "^1.1.6", - "npmlog": "^4.0.2", - "rc": "^1.2.7", - "rimraf": "^2.6.1", - "semver": "^5.3.0", - "tar": "^4.4.2" - }, - "dependencies": { - "rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "requires": { - "glob": "^7.1.3" - } - }, - "tar": { - "version": "4.4.13", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz", - "integrity": "sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==", - "requires": { - "chownr": "^1.1.1", - "fs-minipass": "^1.2.5", - "minipass": "^2.8.6", - "minizlib": "^1.2.1", - "mkdirp": "^0.5.0", - "safe-buffer": "^5.1.2", - "yallist": "^3.0.3" - } - } - } - }, "node-releases": { "version": "1.1.61", "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.61.tgz", "integrity": "sha512-DD5vebQLg8jLCOzwupn954fbIiZht05DAZs0k2u8NStSe6h9XdsuIQL8hSRKYiU8WUQRznmSDrKGbv3ObOmC7g==" }, - "nopt": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.3.tgz", - "integrity": "sha512-CvaGwVMztSMJLOeXPrez7fyfObdZqNUK1cPAEzLHrTybIua9pMdmmPR5YwtfNftIOMv3DPUhFaxsZMNTQO20Kg==", - "requires": { - "abbrev": "1", - "osenv": "^0.1.4" - } + "noop-logger": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/noop-logger/-/noop-logger-0.1.1.tgz", + "integrity": "sha1-lKKxYzxPExdVMAfYlm/Q6EG2pMI=" }, "normalize-package-data": { "version": "2.5.0", @@ -5355,29 +5379,6 @@ "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==" }, - "npm-bundled": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.1.1.tgz", - "integrity": "sha512-gqkfgGePhTpAEgUsGEgcq1rqPXA+tv/aVBlgEzfXwA1yiUJF7xtEt3CtVwOjNYQOVknDk0F20w58Fnm3EtG0fA==", - "requires": { - "npm-normalize-package-bin": "^1.0.1" - } - }, - "npm-normalize-package-bin": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz", - "integrity": "sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==" - }, - "npm-packlist": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz", - "integrity": "sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==", - "requires": { - "ignore-walk": "^3.0.1", - "npm-bundled": "^1.0.1", - "npm-normalize-package-bin": "^1.0.1" - } - }, "npm-run-path": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz", @@ -5544,25 +5545,6 @@ "word-wrap": "~1.2.3" } }, - "os-homedir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=" - }, - "os-tmpdir": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=" - }, - "osenv": { - "version": "0.1.5", - "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", - "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", - "requires": { - "os-homedir": "^1.0.0", - "os-tmpdir": "^1.0.0" - } - }, "p-each-series": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/p-each-series/-/p-each-series-2.1.0.tgz", @@ -5695,6 +5677,28 @@ "resolved": "https://registry.npmjs.org/posix-character-classes/-/posix-character-classes-0.1.1.tgz", "integrity": "sha1-AerA/jta9xoqbAL+q7jB/vfgDqs=" }, + "prebuild-install": { + "version": "5.3.6", + "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-5.3.6.tgz", + "integrity": "sha512-s8Aai8++QQGi4sSbs/M1Qku62PFK49Jm1CbgXklGz4nmHveDq0wzJkg7Na5QbnO1uNH8K7iqx2EQ/mV0MZEmOg==", + "requires": { + "detect-libc": "^1.0.3", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp-classic": "^0.5.3", + "napi-build-utils": "^1.0.1", + "node-abi": "^2.7.0", + "noop-logger": "^0.1.1", + "npmlog": "^4.0.1", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^3.0.3", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0", + "which-pm-runs": "^1.0.0" + } + }, "prelude-ls": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", @@ -5926,9 +5930,9 @@ } }, "react-clone-referenced-element": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/react-clone-referenced-element/-/react-clone-referenced-element-1.1.0.tgz", - "integrity": "sha512-FKOsfKbBkPxYE8576EM6uAfHC4rnMpLyH6/TJUL4WcHUEB3EUn8AxPjnnV/IiwSSzsClvHYK+sDELKN/EJ0WYg==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/react-clone-referenced-element/-/react-clone-referenced-element-1.1.1.tgz", + "integrity": "sha512-LZBPvQV8W0B5dFzXFu+D3Tpil8YHS8tO00iFsfXcTLdtpuH7XyvaHqHcoz4hd4uNPQCZ30fceh+s7mLznzMXvg==" }, "react-is": { "version": "16.13.1", @@ -5978,21 +5982,22 @@ } }, "realm": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/realm/-/realm-10.0.1.tgz", - "integrity": "sha512-o3dUNZgydUcAIKsXd2QkoRuM1awmx0i56QUy9xbmpOB2CdvgbpX7fPb9cmusjVYml2tNbhu2EGF8jB0Tem8M6A==", + "version": "10.5.0-beta.1", + "resolved": "https://registry.npmjs.org/realm/-/realm-10.5.0-beta.1.tgz", + "integrity": "sha512-7uK4h1mnZ/GCEVWo+b3TumcC76lKvg7O6qEbHtmMsrlVlySDBbDf5riAzYzvwRNCjGn+GnT+lIESODQ1f1ZG9w==", "requires": { - "bson": "^4.0.3", + "bindings": "^1.5.0", + "bson": "^4.3.0", "command-line-args": "^4.0.6", "deepmerge": "2.1.0", "deprecated-react-native-listview": "0.0.6", "fs-extra": "^4.0.3", "https-proxy-agent": "^2.2.4", - "ini": "^1.3.5", - "node-addon-api": "^3.0.0", - "node-fetch": "^1.7.3", + "ini": "^1.3.7", + "node-addon-api": "^3.1.0", + "node-fetch": "^2.6.1", "node-machine-id": "^1.1.10", - "node-pre-gyp": "^0.15.0", + "prebuild-install": "^5.3.5", "progress": "^2.0.3", "prop-types": "^15.6.2", "realm-network-transport": "^0.7.0", @@ -6003,6 +6008,14 @@ "url-parse": "^1.4.4" }, "dependencies": { + "bson": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-4.3.0.tgz", + "integrity": "sha512-LkKKeFJx5D6RRCRvLE+fDs40M2ZQNuk7W7tFXmKd7OOcQQ+BHdzCgRdL4XEGjc1UEGtiYuMvIVk91Bv8qsI50A==", + "requires": { + "buffer": "^5.6.0" + } + }, "deepmerge": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-2.1.0.tgz", @@ -6017,13 +6030,6 @@ "requires": { "abort-controller": "^3.0.0", "node-fetch": "^2.6.0" - }, - "dependencies": { - "node-fetch": { - "version": "2.6.1", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", - "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" - } } }, "regenerate": { @@ -6404,11 +6410,6 @@ } } }, - "sax": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==" - }, "saxes": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz", @@ -6469,13 +6470,46 @@ "shellwords": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/shellwords/-/shellwords-0.1.1.tgz", - "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==" + "integrity": "sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==", + "optional": true + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "dependencies": { + "object-inspect": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.10.3.tgz", + "integrity": "sha512-e5mCJlSH7poANfC8z8S9s9S2IN5/4Zb3aZ33f5s8YqoazCFzNLloLU8r5VCG+G7WoqLvAAZoVMcy3tp/3X0Plw==" + } + } }, "signal-exit": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.3.tgz", "integrity": "sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA==" }, + "simple-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz", + "integrity": "sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==" + }, + "simple-get": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/simple-get/-/simple-get-3.1.0.tgz", + "integrity": "sha512-bCR6cP+aTdScaQCnQKbPKtJOKDp/hj9EDLJo3Nw4y1QksqaovlW/bnptB6/c1e+qmNIDHRK+oXFDdEqBT8WzUA==", + "requires": { + "decompress-response": "^4.2.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, "sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -6889,6 +6923,62 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=" }, + "superagent": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-6.1.0.tgz", + "integrity": "sha512-OUDHEssirmplo3F+1HWKUrUjvnQuA+nZI6i/JJBdXb5eq9IyEQwPyPpqND+SSsxf6TygpBEkUjISVRN4/VOpeg==", + "requires": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.2", + "debug": "^4.1.1", + "fast-safe-stringify": "^2.0.7", + "form-data": "^3.0.0", + "formidable": "^1.2.2", + "methods": "^1.1.2", + "mime": "^2.4.6", + "qs": "^6.9.4", + "readable-stream": "^3.6.0", + "semver": "^7.3.2" + }, + "dependencies": { + "form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "qs": { + "version": "6.10.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.10.1.tgz", + "integrity": "sha512-M528Hph6wsSVOBiYUnGf+K/7w0hNshs/duGsNXPUCLH5XAqjEtiPGwNONLV0tBH8NoGb0mvD5JubnUTrujKDTg==", + "requires": { + "side-channel": "^1.0.4" + } + }, + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "semver": { + "version": "7.3.5", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz", + "integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==", + "requires": { + "lru-cache": "^6.0.0" + } + } + } + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -6974,9 +7064,9 @@ } }, "tar": { - "version": "6.0.5", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.0.5.tgz", - "integrity": "sha512-0b4HOimQHj9nXNEAA7zWwMM91Zhhba3pspja6sQbgTpynOJf+bkjBnfybNYzbpLbnwXnbyB4LOREvlyXLkCHSg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz", + "integrity": "sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA==", "requires": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", @@ -6991,40 +7081,45 @@ "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==" }, - "fs-minipass": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", - "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", - "requires": { - "minipass": "^3.0.0" - } - }, - "minipass": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.1.3.tgz", - "integrity": "sha512-Mgd2GdMVzY+x3IJ+oHnVM+KG3lA5c8tnabyJKmHSaG2kAGpudxuOf8ToDkhumF7UzME7DecbQE9uOZhNm7PuJg==", - "requires": { - "yallist": "^4.0.0" - } - }, - "minizlib": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", - "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", - "requires": { - "minipass": "^3.0.0", - "yallist": "^4.0.0" - } - }, "mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==" - }, - "yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + } + } + }, + "tar-fs": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/tar-fs/-/tar-fs-2.1.1.tgz", + "integrity": "sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==", + "requires": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "tar-stream": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tar-stream/-/tar-stream-2.2.0.tgz", + "integrity": "sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==", + "requires": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "dependencies": { + "readable-stream": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", + "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } } } }, @@ -7100,7 +7195,11 @@ "tld-list": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/tld-list/-/tld-list-1.0.0.tgz", - "integrity": "sha1-cXPudZKysBs83KF1jVShJymSiis=" + "integrity": "sha1-cXPudZKysBs83KF1jVShJymSiis=", + "requires": { + "punycode": "^2.1.1", + "superagent": "^6.1.0" + } }, "tmpl": { "version": "1.0.4", @@ -7329,9 +7428,9 @@ "integrity": "sha1-XAgOXWYcu+OCWdLnCjxyU+hziB0=" }, "ua-parser-js": { - "version": "0.7.22", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.22.tgz", - "integrity": "sha512-YUxzMjJ5T71w6a8WWVcMGM6YWOTX27rCoIQgLXiWaxqXSx9D7DNjiGWn1aJIRSQ5qr0xuhra77bSIh6voR/46Q==" + "version": "0.7.28", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.28.tgz", + "integrity": "sha512-6Gurc1n//gjp9eQNXjD9O3M/sMwVtN5S8Lv9bvOYBfKfDNiIIhqiyi01vMBO45u4zkDE420w/e0se7Vs+sIg+g==" }, "unicode-canonical-property-names-ecmascript": { "version": "1.0.4", @@ -7423,9 +7522,9 @@ "integrity": "sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI=" }, "url-parse": { - "version": "1.4.7", - "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.4.7.tgz", - "integrity": "sha512-d3uaVyzDB9tQoSXFvuSUNFibTd9zxd2bkVrDRvF5TmvWWQwqE4lgYJ5m+x1DbecWkw+LK4RNl2CU1hHuOKPVlg==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.1.tgz", + "integrity": "sha512-HOfCOUJt7iSYzEx/UqgtwKRMC6EU91NFhsCHMv9oM03VJcVo2Qrp8T8kI9D7amFf1cu+/3CEhgb3rF9zL7k85Q==", "requires": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" @@ -7444,7 +7543,8 @@ "uuid": { "version": "8.3.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.1.tgz", - "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==" + "integrity": "sha512-FOmRr+FmWEIG8uhZv6C2bTgEVXsHk08kE7mPlrBbEe+c3r9pjceVPgupIfNIhc4yx55H69OXANrUaSuu9eInKg==", + "optional": true }, "v8-compile-cache": { "version": "2.1.1", @@ -7553,6 +7653,11 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, + "which-pm-runs": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/which-pm-runs/-/which-pm-runs-1.0.0.tgz", + "integrity": "sha1-Zws6+8VS4LVd9rd4DKdGFfI60cs=" + }, "wide-align": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", @@ -7651,9 +7756,9 @@ "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" }, "yallist": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", - "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yargs": { "version": "15.4.1", diff --git a/examples/node/package.json b/examples/node/package.json index d65139f6e3..a338c12a4d 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -25,7 +25,7 @@ "jest": "^26.5.3", "prettier": "^2.1.2", "random-email": "^1.0.3", - "realm": "^10.0.1", + "realm": "^10.5.0-beta.1", "ts-jest": "^26.4.1", "typescript": "^4.0.3" }, diff --git a/source/examples/generated/node/data-types.codeblock.add-a-listener-to-a-dictionary.js b/source/examples/generated/node/data-types.codeblock.add-a-listener-to-a-dictionary.js new file mode 100644 index 0000000000..ae502f1252 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.add-a-listener-to-a-dictionary.js @@ -0,0 +1,3 @@ +summerHillHouse.addListener((changedHouse, changes) => { + console.log("A change has occurred to the Summer Hill House object"); +}); diff --git a/source/examples/generated/node/data-types.codeblock.create-realm-obj-with-dictionary.js b/source/examples/generated/node/data-types.codeblock.create-realm-obj-with-dictionary.js new file mode 100644 index 0000000000..f2d78b2f33 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.create-realm-obj-with-dictionary.js @@ -0,0 +1,21 @@ +let johnDoe; +let janeSmith; +realm.write(() => { + johnDoe = realm.create("Person", { + name: "John Doe", + home: { + windows: 5, + doors: 3, + color: "red", + address: "Summerhill St.", + price: 400123, + }, + }); + janeSmith = realm.create("Person", { + name: "Jane Smith", + home: { + address: "100 northroad st.", + yearBuilt: 1990, + }, + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.define-dictionary-in-schema.js b/source/examples/generated/node/data-types.codeblock.define-dictionary-in-schema.js new file mode 100644 index 0000000000..da81df7a04 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.define-dictionary-in-schema.js @@ -0,0 +1,7 @@ +const PersonSchema = { + name: "Person", + properties: { + name: "string", + home: "{}", + }, +}; diff --git a/source/examples/generated/node/data-types.codeblock.query-a-dictionary.js b/source/examples/generated/node/data-types.codeblock.query-a-dictionary.js new file mode 100644 index 0000000000..bbd91ad4b9 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.query-a-dictionary.js @@ -0,0 +1,14 @@ +// query for all Person objects +const persons = realm.objects("Person"); + +// run the `.filtered()` method on all the returned persons to find the house with the address "Summerhill St." +const summerHillHouse = persons.filtered( + `home['address'] = "Summerhill St."` +)[0].home; + +// Find all people that have a house with a listed price +const peopleWithHousesWithAListedPrice = persons.filtered( + `home.@keys = "price" ` +); +// find a house that has any field with a value of 'red' +const redHouse = persons.filtered(`home.@values = "red" `)[0].home; diff --git a/source/examples/generated/node/data-types.codeblock.remove-fields-of-the-dictionary.js b/source/examples/generated/node/data-types.codeblock.remove-fields-of-the-dictionary.js new file mode 100644 index 0000000000..3f51202fe2 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.remove-fields-of-the-dictionary.js @@ -0,0 +1,4 @@ +realm.write(() => { + // remove the 'windows' and 'doors' field of the Summerhill House. + summerHillHouse.remove(["windows", "doors"]); +}); diff --git a/source/examples/generated/node/data-types.codeblock.setting-new-dictionaries-to-existing-objects.js b/source/examples/generated/node/data-types.codeblock.setting-new-dictionaries-to-existing-objects.js new file mode 100644 index 0000000000..b33e02b6cf --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.setting-new-dictionaries-to-existing-objects.js @@ -0,0 +1,14 @@ +let newVictorianHome; +realm.write(() => { + newVictorianHome = { + doors: 4, + floor: 3, + color: "white", + address: "Trailwoods Rd.", + }; + // use the `put()` method to add a dictionary to a pre-existing city in the database + summerHillHouse.home.put(newVictorianHome); + + // alternatively, use dot notation to add a dictionary to a pre-existing city + yakimaCity.home = newVictorianHome; +}); diff --git a/source/examples/generated/node/data-types.codeblock.update-a-dictionary.js b/source/examples/generated/node/data-types.codeblock.update-a-dictionary.js new file mode 100644 index 0000000000..e042ed69dc --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.update-a-dictionary.js @@ -0,0 +1,8 @@ +realm.write(() => { + // use the `put()` method to update a field of a dictionary + summerHillHouse.put({ price: 400100 }); + // alternatively, update a field of a dictionary through dot notation + summerHillHouse.color = "brown"; + // update a dictionary by adding a field + summerHillHouse.yearBuilt = 2004; +}); diff --git a/source/sdk/node/data-types/dictionaries.txt b/source/sdk/node/data-types/dictionaries.txt index b0dc026ce2..d53619cd8b 100644 --- a/source/sdk/node/data-types/dictionaries.txt +++ b/source/sdk/node/data-types/dictionaries.txt @@ -15,4 +15,73 @@ Dictionaries - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- +You can use the ``dictionary`` data type to manage a collection of unique String +keys paired with values. The ``dictionary`` data maps to the Javascript +:mdn:`Object ` type. + +Realm Object Models +------------------- + +To define a dictionary of mixed values in your schema, set the data type +of your field to an empty object, ``"{}"``. Alternatively, to create a +dictionary with values of a specific type, add the data type before the +brackets. For instance, ``"int{}"`` to specify that dictionary values must be +integers or ``"string{}"`` to specify that dictionary values must be strings. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-dictionary-in-schema.js + :language: javascript + +Create an Object with a Dictionary Value +----------------------------------------- +Create an object with a dictionary value by running the :js-sdk:`realm.create() +` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-realm-obj-with-dictionary.js + :language: javascript + +Query for Objects with a Dictionary Property +-------------------------------------------- +To filter a query, run :js-sdk:`collection.filtered() +` to specify a subset of results based on the +value(s) of one or more object properties. You can specify results based on the value of a +dictionary's properties by using :mdn:`bracket-notation `. + +You can also determine whether a results collection has a certain key or value +by using ``.@keys`` or ``.@values``. For instance, if +you had a ``Person`` collection with a nested ``home`` dictionary, you could +determine return all ``Person`` objects with a ``home`` with a ``"price"`` +property by running the query: ``home.@keys = "price"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-a-dictionary.js + :language: javascript + +Add a Listener to a Dictionary +------------------------------ +You can add a listener to a dictionary by running the +:js-sdk:`dictionary.addListener() ` method. The +``addListener`` method's callback function has two parameters, the changed +dictionary and an array of changes describing how the dictionary was changed. + +.. note:: + + Learn more about :ref:`change notifications `. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.add-a-listener-to-a-dictionary.js + :language: javascript + +Update a Dictionary +------------------- +To update a dictionary's properties, use dot notation or the ``dictionary.put()`` method. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.update-a-dictionary.js + :language: javascript + +Delete Members of a Dictionary +------------------------------ +To delete members of a dictionary, use the ``dictionary.remove()`` method with an array of properties to remove from the dictionary. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-fields-of-the-dictionary.js + :language: javascript + + From 5f43200dd279c5cad51ee5a5c131c83796201217 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 18 May 2021 14:02:12 -0400 Subject: [PATCH 11/29] (DOCSP-14577): UUID (#1067) * bump realmjs to 10.5.0-beta-1 * removed uuid as it's own page and added a subsection on it * added uuid bluehawked snippet + readded uuid to toc * added uuid examples * removed uuid from field types as a paragraph * update wording * update wording * fix passive voice * add specific uuid example * removed innacurate collections are homogenous (per mixed) --- examples/node/Examples/data-types.js | 41 +++++++++++++++++++ .../data-types.codeblock.work-with-uuid.js | 22 ++++++++++ source/sdk/node/data-types/collections.txt | 3 +- source/sdk/node/data-types/field-types.txt | 5 ++- source/sdk/node/data-types/uuid.txt | 25 ++++++++++- 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 source/examples/generated/node/data-types.codeblock.work-with-uuid.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 285ee631f6..cc1209df70 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -194,6 +194,7 @@ describe("Node.js Data Types", () => { const Blaise = realm.objects("Dog").filtered(`name = 'Blaise'`)[0]; const Euclid = realm.objects("Dog").filtered(`name = 'Euclid'`)[0]; const Pythagoras = realm.objects("Dog").filtered(`name = 'Pythagoras'`)[0]; + // delete the objects to keep the tests idempotent realm.write(() => { realm.delete(Euler); realm.delete(Blaise); @@ -299,4 +300,44 @@ describe("Node.js Data Types", () => { // close the realm realm.close(); }); + test("should work with UUID", async () => { + // :code-block-start: work-with-uuid + const { UUID } = Realm.BSON; + const ProfileSchema = { + name: "Profile", + primaryKey: "_id", + properties: { + _id: "uuid", + name: "string", + }, + }; + const realm = await Realm.open({ + schema: [ProfileSchema], + }); + realm.write(() => { + realm.create("Profile", { + name: "John Doe.", + _id: new UUID(), // create a _id with a randomly generated UUID + }); + realm.create("Profile", { + name: "Tim Doe.", + _id: new UUID("882dd631-bc6e-4e0e-a9e8-f07b685fec8c"), // create a _id with a specific UUID value + }); + }); + // :code-block-end: + + const johnDoeProfile = realm + .objects("Profile") + .filtered("name = 'John Doe.'")[0]; + + // test if johnDoeProfile's _id is a valid UUID field + expect(UUID.isValid(johnDoeProfile._id)).toBe(true); + + // delete the objects to keep the tests idempotent + realm.write(() => { + realm.delete(johnDoeProfile); + }); + // close the realm + realm.close(); + }); }); diff --git a/source/examples/generated/node/data-types.codeblock.work-with-uuid.js b/source/examples/generated/node/data-types.codeblock.work-with-uuid.js new file mode 100644 index 0000000000..cea1351927 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.work-with-uuid.js @@ -0,0 +1,22 @@ +const { UUID } = Realm.BSON; +const ProfileSchema = { + name: "Profile", + primaryKey: "_id", + properties: { + _id: "uuid", + name: "string", + }, +}; +const realm = await Realm.open({ + schema: [ProfileSchema], +}); +realm.write(() => { + realm.create("Profile", { + name: "John Doe.", + _id: new UUID(), // create a _id with a randomly generated UUID + }); + realm.create("Profile", { + name: "Tim Doe.", + _id: new UUID("882dd631-bc6e-4e0e-a9e8-f07b685fec8c"), // create a _id with a specific UUID value + }); +}); diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index 22faee6f5c..07955f3244 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -18,8 +18,7 @@ Overview {+service-short+} has several types to represent groups of objects, which we call **collections**. A collection is an object that contains zero or more instances of one :ref:`{+service-short+} type -`. {+service-short+} collections are **homogenous**: -all objects in a collection are of the same type. +`. You can filter and sort any collection using {+client-database+}'s :ref:`query engine `. Collections are diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 9037883fa7..5dead1e9bf 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -21,4 +21,7 @@ Field Types -Node.js SDK - ``objectId`` maps to BSON :manual:`ObjectId ` type. - ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. - ``date`` maps to the JavaScript :mdn:`Date ` type. -- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. \ No newline at end of file +- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. +- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. + + diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index b0a3a597ab..ef0cfaafd3 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -14,4 +14,27 @@ UUID - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- + +``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value +`. You can use ``UUID`` as an identifier for +objects. ``UUID`` is :ref:`indexable ` and you can use it as a +:ref:`primary key `. + +.. note:: Using UUID Instead of ObjectId + + In general, you can use ``UUID`` in any field that you need a unique + identifier. Using ``UUID`` might be particularly useful if you are migrating + data not stored in MongoDB since it is likely that your object's unique + identifiers are already of a ``UUID`` type. + +Usage +----- +To define a property as a ``UUID``, set its type to the string ``"uuid"`` in +your :ref:`object model `. Create a {+service-short+} +object within a write transaction. To set any unique identifier properties of +your object to a random value, call ``new UUID()``. Alternatively, set a string +to ``new UUID()`` to set the unique identifier property to a specific value. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js + :language: javascript \ No newline at end of file From c0039742b979fdb1181242d33b27718476c1da59 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:13:08 -0400 Subject: [PATCH 12/29] (DOCSP-14573): set data type (#1079) * added set examples + bluehawked * literal included set exampkes * added delete one set item example * fix typo * added descriptions to set * fix grammar * changed link + hunter to generic names * added capitalization to clearly define Realm Set as a term * fix wording + formatting" * clarified wording * fix literalincldue indentation * fix typo * more wording fixes * clean up realm object model for set wording * fix character names for examples * clarified traversal order wording * rst typo in * changed set to mySet * fix overview wording * updated overview to be more clear on differences between array * updated create wording * Update source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js Co-authored-by: Kenneth Geisshirt * Update source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js Co-authored-by: Kenneth Geisshirt * Update source/sdk/node/data-types/sets.txt Co-authored-by: Kenneth Geisshirt * fix grammar + wording + changed Set to Realm.Set in js snippets * Fix woridng Co-authored-by: Kenneth Geisshirt --- examples/node/Examples/data-types.js | 88 +++++++++++++++++ .../data-types.codeblock.add-items-to-set.js | 4 + ...-types.codeblock.check-if-set-has-items.js | 5 + .../data-types.codeblock.check-set-size.js | 3 + ...data-types.codeblock.create-set-objects.js | 15 +++ ...data-types.codeblock.define-set-objects.js | 10 ++ ...pes.codeblock.remove-all-items-from-set.js | 4 + ...codeblock.remove-specific-item-from-set.js | 4 + source/sdk/node/data-types/sets.txt | 96 ++++++++++++++++++- 9 files changed, 228 insertions(+), 1 deletion(-) create mode 100644 source/examples/generated/node/data-types.codeblock.add-items-to-set.js create mode 100644 source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js create mode 100644 source/examples/generated/node/data-types.codeblock.check-set-size.js create mode 100644 source/examples/generated/node/data-types.codeblock.create-set-objects.js create mode 100644 source/examples/generated/node/data-types.codeblock.define-set-objects.js create mode 100644 source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js create mode 100644 source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index cc1209df70..b80b0824c2 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -340,4 +340,92 @@ describe("Node.js Data Types", () => { // close the realm realm.close(); }); + test("should work with the Set data type", async () => { + // :code-block-start: define-set-objects + const characterSchema = { + name: "Character", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + levelsCompleted: "int<>", + inventory: "string<>", + }, + }; + // :code-block-end: + const realm = await Realm.open({ + schema: [characterSchema], + }); + + // :code-block-start: create-set-objects + let playerOne, playerTwo; + realm.write(() => { + playerOne = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "PlayerOne", + inventory: ["elixir", "compass", "glowing shield"], + levelsCompleted: [4, 9], + }); + playerTwo = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "PlayerTwo", + inventory: ["estus flask", "gloves", "rune"], + levelsCompleted: [1, 2, 5, 24], + }); + }); + // :code-block-end: + + expect(playerOne.inventory.has("elixir")).toBe(true); + expect(playerTwo.inventory.has("gloves")).toBe(true); + + // :code-block-start: add-items-to-set + realm.write(() => { + playerOne.inventory.add("hammer"); + playerOne.levelsCompleted.add(32); + }); + // :code-block-end: + + expect(playerOne.inventory.size).toBe(4); + expect(playerOne.levelsCompleted.size).toBe(3); + + // :code-block-start: check-if-set-has-items + // check if the playerTwo has completed level 3 by calling the `set.has()` method + const playerTwoHasCompletedLevelThree = playerTwo.levelsCompleted.has(3); + console.log( + `Is level three completed by the playerTwo: ${playerTwoHasCompletedLevelThree}` + ); + // :code-block-end: + expect(playerTwoHasCompletedLevelThree).toBe(false); + + // :code-block-start: remove-specific-item-from-set + realm.write(() => { + // remove the compass from playerOne's inventory by calling `set.delete()` within a write transaction + playerOne.inventory.delete("compass"); + }); + + // :code-block-end: + expect(playerOne.inventory.has("compass")).toBe(false); + + // :code-block-start: remove-all-items-from-set + realm.write(() => { + // clear all data from the inventory slot of the playerTwo by calling `set.clear()` in a write transaction + playerTwo.inventory.clear(); + }); + // :code-block-end: + + // :code-block-start: check-set-size + // check how many items the playerTwo has in his inventory through the `set.size` property + const playerTwoInventorySize = playerTwo.inventory.size; + console.log(`The playerTwo has ${playerTwoInventorySize} inventory items`); + // :code-block-end: + expect(playerTwo.inventory.size).toBe(0); + + // delete the object specifically created in this test to keep tests idempotent + realm.write(() => { + realm.delete(playerOne); + realm.delete(playerTwo); + }); + // close the realm + realm.close(); + }); }); diff --git a/source/examples/generated/node/data-types.codeblock.add-items-to-set.js b/source/examples/generated/node/data-types.codeblock.add-items-to-set.js new file mode 100644 index 0000000000..988cd8c26b --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.add-items-to-set.js @@ -0,0 +1,4 @@ +realm.write(() => { + characterOne.inventory.add("hammer"); + characterOne.levelsCompleted.add(32); +}); diff --git a/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js new file mode 100644 index 0000000000..0e09ea622d --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.check-if-set-has-items.js @@ -0,0 +1,5 @@ +// check if the characterTwo has completed level 3 by calling the `Realm.Set.has()` method +const characterTwoHasCompletedLevelThree = characterTwo.levelsCompleted.has(3); +console.log( + `Is level three completed by the characterTwo: ${characterTwoHasCompletedLevelThree}` +); diff --git a/source/examples/generated/node/data-types.codeblock.check-set-size.js b/source/examples/generated/node/data-types.codeblock.check-set-size.js new file mode 100644 index 0000000000..d864c79192 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.check-set-size.js @@ -0,0 +1,3 @@ +// check how many items the characterTwo has in his inventory through the `Realm.Set.size` property +const characterTwoInventorySize = characterTwo.inventory.size; +console.log(`The characterTwo has ${characterTwoInventorySize} inventory items`); diff --git a/source/examples/generated/node/data-types.codeblock.create-set-objects.js b/source/examples/generated/node/data-types.codeblock.create-set-objects.js new file mode 100644 index 0000000000..dd47653332 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.create-set-objects.js @@ -0,0 +1,15 @@ +let characterOne, characterTwo; +realm.write(() => { + characterOne = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "CharacterOne", + inventory: ["elixir", "compass", "glowing shield"], + levelsCompleted: [4, 9], + }); + characterTwo = realm.create("Character", { + _id: new BSON.ObjectId(), + name: "CharacterTwo", + inventory: ["estus flask", "gloves", "rune"], + levelsCompleted: [1, 2, 5, 24], + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.define-set-objects.js b/source/examples/generated/node/data-types.codeblock.define-set-objects.js new file mode 100644 index 0000000000..e0bb37bf64 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.define-set-objects.js @@ -0,0 +1,10 @@ +const characterSchema = { + name: "Character", + primaryKey: "_id", + properties: { + _id: "objectId", + name: "string", + levelsCompleted: "int<>", + inventory: "string<>", + }, +}; diff --git a/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js new file mode 100644 index 0000000000..4e4a5d0792 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.remove-all-items-from-set.js @@ -0,0 +1,4 @@ +realm.write(() => { + // clear all data from the inventory slot of the characterTwo by calling `Realm.Set.clear()` in a write transaction + characterTwo.inventory.clear(); +}); diff --git a/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js new file mode 100644 index 0000000000..cec2514e5b --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js @@ -0,0 +1,4 @@ +realm.write(() => { + // remove the compass from characterOne's inventory by calling `Realm.Set.delete()` within a write transaction + characterOne.inventory.delete("compass"); +}); diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 5dc7b5b845..17ab6b948c 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -15,4 +15,98 @@ Sets - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- +A ``{+service-short+} Set`` is a special object that allows you to store a +collection of unique values. ``{+service-short+} Sets`` are based on JavaScript +:mdn:`sets `, but can only contain +values of a single type and can only be modified within a write transaction. +Sets allow you to perform math operations such as finding the union, +intersection, or difference between two sets. To learn more about performing +these operations, see the MDN docs for :mdn:`Implementing basic set operations +`. + +.. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order + + When using a ``forEach()`` loop or alternative :mdn:`iteration method + ` to traverse + the set in a loop, the content of the ``{+service-short+} Set`` may be in a + different order than originally written to. If you require an ordered version + of your set, you must implement that ordering yourself. If you require an + ordered version of your set, you must implement that order yourself. You can + do this by creating an array from the set, using :mdn:`Array.from(mySet) + ` or the :mdn:`spread + operator `. You can keep + that array updated by using a :ref:`change listener ` + to react to changes to the set. + + +.. _node-define-set-objects: + +Realm Object Models +------------------- +To define a property type as a ``{+service-short+} Set``, specify the data type +you want in the set, followed by ``<>``. For instance, for a set made of integer +values, specify ``"int<>"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js + :language: javascript + +.. _node-create-set-objects: + +Create an Object With a Set +--------------------------- +To create an object with a ``{+service-short+} Set`` property, you must create +the object within a write transaction. When defining your {+service-short+} +object, initialize the ``{+service-short+} Set`` by passing an empty array or an +array with your initial values. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js + :language: javascript + + +.. _node-add-items-to-set: + +Add Items to a Set +------------------ +To add an item to a set, pass the new value to the ``.add()`` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js + :language: javascript + +.. _node-check-if-set-has-items: + +Check if a Set has Specific Items +--------------------------------- +To determine if a set contains a particular value, pass the value to the ``.has()`` method. The +``set.has()`` method will return true if the set contains the value specified. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js + :language: javascript + +.. _node-check-set-size: + +Check the Size of a Set +----------------------- +To discover how many items are in a set, you can check the set's ``size`` property. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.check-set-size.js + :language: javascript + +.. _node-remove-specific-item-from-set: + +Remove an Item from a Set +------------------------- +To remove a specific value from a set, pass the value to the ``.delete()`` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js + :language: javascript + + +.. _node-remove-all-items-from-set: + +Remove all Items from a Set +--------------------------- +To clear the set, run the ``.clear()`` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js + :language: javascript From 2202f420b5779182a4b14d56febc9565d80fb22e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:30:04 -0400 Subject: [PATCH 13/29] fill out field types --- source/sdk/node/data-types/field-types.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 5dead1e9bf..98e87edf04 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -22,6 +22,8 @@ Field Types -Node.js SDK - ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. - ``date`` maps to the JavaScript :mdn:`Date ` type. - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. -- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. - - +- ``linkingObjects`` is a special type used to define an inverse relationship. +- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in 'realm-js@10.5.0-beta.1'. +- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in 'realm-js@10.5.0-beta.1'. +- ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in 'realm-js@10.5.0-beta.1'. +- ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in 'realm-js@10.5.0-beta.1'. From 43e9e3755c8b6f51a43b862860c68b3f965dad19 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:37:27 -0400 Subject: [PATCH 14/29] add react native data types as a copy of node data types --- source/sdk/node/data-types/field-types.txt | 6 +- source/sdk/react-native/data-types.txt | 29 ++++ .../react-native/data-types/collections.txt | 137 ++++++++++++++++++ .../react-native/data-types/dictionaries.txt | 87 +++++++++++ .../data-types/embedded-objects.txt | 120 +++++++++++++++ .../react-native/data-types/field-types.txt | 29 ++++ source/sdk/react-native/data-types/mixed.txt | 65 +++++++++ source/sdk/react-native/data-types/sets.txt | 112 ++++++++++++++ source/sdk/react-native/data-types/uuid.txt | 40 +++++ 9 files changed, 622 insertions(+), 3 deletions(-) create mode 100644 source/sdk/react-native/data-types/collections.txt create mode 100644 source/sdk/react-native/data-types/dictionaries.txt create mode 100644 source/sdk/react-native/data-types/embedded-objects.txt create mode 100644 source/sdk/react-native/data-types/field-types.txt create mode 100644 source/sdk/react-native/data-types/mixed.txt create mode 100644 source/sdk/react-native/data-types/sets.txt create mode 100644 source/sdk/react-native/data-types/uuid.txt diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 98e87edf04..53812eece2 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -1,8 +1,8 @@ .. _node-data-types-field-types: -======================== -Field Types -Node.js SDK -======================== +========================= +Field Types - Node.js SDK +========================= .. default-domain:: mongodb .. contents:: On this page :local: diff --git a/source/sdk/react-native/data-types.txt b/source/sdk/react-native/data-types.txt index f8dd1dbf36..a998fe9695 100644 --- a/source/sdk/react-native/data-types.txt +++ b/source/sdk/react-native/data-types.txt @@ -1,3 +1,32 @@ +.. _react-native-data-types: + =================================== Realm Data Types - React Native SDK =================================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. toctree:: + :titlesonly: + :hidden: + + Field Types + Collections + Dictionaries + Sets + Mixed + UUID + Embedded Objects + +- :doc:`Field Types ` +- :doc:`Collections ` +- :doc:`Dictionaries ` +- :doc:`Sets ` +- :doc:`Mixed ` +- :doc:`UUID ` +- :doc:`Embedded Objects ` \ No newline at end of file diff --git a/source/sdk/react-native/data-types/collections.txt b/source/sdk/react-native/data-types/collections.txt new file mode 100644 index 0000000000..07ecc55dc9 --- /dev/null +++ b/source/sdk/react-native/data-types/collections.txt @@ -0,0 +1,137 @@ +.. _react-native-data-types-collections: + +============================== +Collections - React Native SDK +============================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- + +{+service-short+} has several types to represent groups of objects, +which we call **collections**. A collection is an object that contains +zero or more instances of one :ref:`{+service-short+} type +`. + +You can filter and sort any collection using {+client-database+}'s +:ref:`query engine `. Collections are +:ref:`live `, so they always reflect the current state +of the :term:`{+realm+} instance` on the current thread. You can also +listen for changes in the collection by subscribing to :ref:`collection +notifications `. + +.. _react-native-realm-results: + +Results +------- +A :js-sdk:`Results ` collection represents the +lazily-evaluated results of a query operation. Results are immutable: +you cannot add or remove elements to or from the results collection. +Results have an associated query that determines their contents. + +.. seealso:: + + :ref:`Reads ` + +.. _react-native-realm-list: + +Lists +----- +A :js-sdk:`List ` represents a :ref:`to-many +relationship ` between two {+service-short+} +types. Lists are mutable: within a write transaction, you can add and +remove elements to and from a list. Lists are not associated with a +query and are declared as a property of an :ref:`object model +`. + +.. seealso:: + + :ref:`To-Many Relationships ` + +.. _react-native-lazy-evaluated-results: + +Results are Lazily Evaluated +---------------------------- +{+client-database+} only runs a query when you request the +results of that query. This lazy evaluation enables you to write +elegant, highly-performant code for handling large data sets and complex +queries. + +.. _react-native-live-collections: + +Collections are Live +-------------------- +Like :ref:`live objects `, {+service-short+} collections +are usually **live**: + +- Live results collections always reflect the current results of the associated query. +- Live lists always reflect the current state of the relationship on the {+realm+} instance. + +A collection is **not** live when: + +- it is a :ref:`results collection ` that you are iterating through using a :mdn:`for..in ` or :mdn:`for..of ` statement. Both statements will continue to iterate through objects in the collection even if you have deleted or modified the collection's objects to exclude them from the filter that produced the results collection. +- the collection is a frozen :js-sdk:`Results.snapshot() `. + +Combined with :ref:`collection notifications +`, live collections enable +reactive code. For example, suppose your view displays the +results of a query. You can keep a reference to the results +collection in your view class, then read the results +collection as needed without having to refresh it or +validate that it is up-to-date. + +.. important:: Indexes may change + + Since results update themselves automatically, do not + store the positional index of an object in the collection + or the count of objects in a collection. The stored index + or count value could be outdated by the time you use + it. + +.. _react-native-working-with-collections: + +Working With Collections +------------------------ + +.. _react-native-limiting-query-results: + +Limiting Query Results +~~~~~~~~~~~~~~~~~~~~~~ +As a result of lazy evaluation, you do not need any special +mechanism to limit query results with {+client-database+}. For example, if +your query matches thousands of objects, but you only want +to load the first ten, access only the first ten +elements of the results collection. + +.. _react-native-realm-result-pagination: + +Pagination +~~~~~~~~~~ +Thanks to lazy evaluation, the common task of pagination +becomes quite simple. For example, suppose you have a +results collection associated with a query that matches +thousands of objects in your {+realm+}. You display one hundred +objects per page. To advance to any page, simply access the +elements of the results collection starting at the index +that corresponds to the target page. + +Summary +------- +- A {+service-short+} **collection** is a homogenous container of zero + or more instances of one + :ref:`{+service-short+} type `. +- There are two main kinds of collection: **lists** and **results**. + Lists define the :ref:`to-many relationships ` + of your {+service-short+} types, while results represent the + lazily-loaded output of a :ref:`read operation `. +- Lazy evaluation of results collections means there is no need to + design a special query to get limited or paginated results. Perform + the query and read from the results collection as needed. +- Data in {+service-short+} is *live*, which means that an object always reflects its most recent saved state. diff --git a/source/sdk/react-native/data-types/dictionaries.txt b/source/sdk/react-native/data-types/dictionaries.txt new file mode 100644 index 0000000000..95cc0c15dc --- /dev/null +++ b/source/sdk/react-native/data-types/dictionaries.txt @@ -0,0 +1,87 @@ +.. _react-native-data-types-dictionaries: + +=============================== +Dictionaries - React Native SDK +=============================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- +You can use the ``dictionary`` data type to manage a collection of unique String +keys paired with values. The ``dictionary`` data maps to the Javascript +:mdn:`Object ` type. + +Realm Object Models +------------------- + +To define a dictionary of mixed values in your schema, set the data type +of your field to an empty object, ``"{}"``. Alternatively, to create a +dictionary with values of a specific type, add the data type before the +brackets. For instance, ``"int{}"`` to specify that dictionary values must be +integers or ``"string{}"`` to specify that dictionary values must be strings. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-dictionary-in-schema.js + :language: javascript + +Create an Object with a Dictionary Value +----------------------------------------- +Create an object with a dictionary value by running the :js-sdk:`realm.create() +` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-realm-obj-with-dictionary.js + :language: javascript + +Query for Objects with a Dictionary Property +-------------------------------------------- +To filter a query, run :js-sdk:`collection.filtered() +` to specify a subset of results based on the +value(s) of one or more object properties. You can specify results based on the value of a +dictionary's properties by using :mdn:`bracket-notation `. + +You can also determine whether a results collection has a certain key or value +by using ``.@keys`` or ``.@values``. For instance, if +you had a ``Person`` collection with a nested ``home`` dictionary, you could +determine return all ``Person`` objects with a ``home`` with a ``"price"`` +property by running the query: ``home.@keys = "price"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-a-dictionary.js + :language: javascript + +Add a Listener to a Dictionary +------------------------------ +You can add a listener to a dictionary by running the +:js-sdk:`dictionary.addListener() ` method. The +``addListener`` method's callback function has two parameters, the changed +dictionary and an array of changes describing how the dictionary was changed. + +.. note:: + + Learn more about :ref:`change notifications `. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.add-a-listener-to-a-dictionary.js + :language: javascript + +Update a Dictionary +------------------- +To update a dictionary's properties, use dot notation or the ``dictionary.put()`` method. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.update-a-dictionary.js + :language: javascript + +Delete Members of a Dictionary +------------------------------ +To delete members of a dictionary, use the ``dictionary.remove()`` method with an array of properties to remove from the dictionary. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-fields-of-the-dictionary.js + :language: javascript + + diff --git a/source/sdk/react-native/data-types/embedded-objects.txt b/source/sdk/react-native/data-types/embedded-objects.txt new file mode 100644 index 0000000000..4e33e667e2 --- /dev/null +++ b/source/sdk/react-native/data-types/embedded-objects.txt @@ -0,0 +1,120 @@ +.. _react-native-data-types-embedded-objects: + +=================================== +Embedded Objects - React Native SDK +=================================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- + +An embedded object is a special type of :ref:`Realm object ` +that models complex data about a specific object. Embedded objects are similar +to :ref:`relationships `, but they provide additional +constraints and map more naturally to the denormalized :manual:`MongoDB document +model `. + +Realm enforces unique ownership constraints that treat each embedded object as +nested data inside a single, specific parent object. An embedded object +inherits the lifecycle of its parent object and cannot exist as an independent +Realm object. This means that embedded objects cannot have a primary key and +that Realm automatically deletes embedded objects if their parent object is +deleted. + +.. tip:: Embedded object types are reusable and composable + + You can use the same embedded object type in multiple parent object types, and + you can embed objects inside other embedded objects. You can even + recursively reference an embedded object type as an optional property in its + own definition. + +.. note:: Realm Uses Cascading Deletes for Embedded Objects + + When you delete a Realm object, Realm automatically deletes any + embedded objects referenced by that object. Any objects that your + application must persist after the deletion of their parent object + should use :ref:`relationships ` + instead. + +Realm Object Models +~~~~~~~~~~~~~~~~~~~ + +To define an embedded object, set ``embedded`` +to ``true``. You can reference an embedded object type from parent object types +in the same way as you would define a relationship: + +.. important:: + + Embedded objects cannot have a :ref:`primary key `. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-embedded-objects.js + :language: javascript + :emphasize-lines: 3, 18, 28 + + +JSON Schema +~~~~~~~~~~~ + +.. include:: /includes/embedded-object-json-schema.rst + + +Read and Write Embedded Objects +------------------------------- + +Create an Embedded Object +~~~~~~~~~~~~~~~~~~~~~~~~~ + +To create an embedded object, assign an instance of the embedded object +to a parent object's property: + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-an-embedded-object.js + :language: javascript + +Update an Embedded Object Property +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To update a property in an embedded object, modify the property in a +write transaction: + +.. literalinclude:: /examples/generated/node/data-types.codeblock.update-an-embedded-object.js + :language: javascript + + +Overwrite an Embedded Object +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To overwrite an embedded object, reassign the embedded object property +of a party to a new instance in a write transaction: + +.. literalinclude:: /examples/generated/node/data-types.codeblock.overwrite-an-embedded-object.js + :language: javascript + + +Query a Collection on Embedded Object Properties +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Use dot notation to filter or sort a :ref:`collection +` of objects based on an embedded object +property value: + +.. include:: /includes/directly-query-embedded-objects-note.rst + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-an-embedded-object.js + :language: javascript + + + +Delete an Embedded Object +~~~~~~~~~~~~~~~~~~~~~~~~~ +Realm Uses Cascading Deletes for Embedded Objects. To delete an embedded object, +delete the embedded object's parent. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.delete-an-embedded-object.js + :language: javascript diff --git a/source/sdk/react-native/data-types/field-types.txt b/source/sdk/react-native/data-types/field-types.txt new file mode 100644 index 0000000000..afa2d38e62 --- /dev/null +++ b/source/sdk/react-native/data-types/field-types.txt @@ -0,0 +1,29 @@ +.. _react-nativedata-types-field-types: + +============================== +Field Types - React Native SDK +============================== +.. default-domain:: mongodb +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +{+client-database+} supports the following field data types: + +- ``bool`` maps to the JavaScript :mdn:`Boolean ` type +- ``int`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``int`` with 64 bits. +- ``float`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``float`` with 32 bits. +- ``double`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``double`` with 64 bits. +- ``string`` maps to the JavaScript :mdn:`String ` type. +- ``decimal128`` for high precision numbers. +- ``objectId`` maps to BSON :manual:`ObjectId ` type. +- ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. +- ``date`` maps to the JavaScript :mdn:`Date ` type. +- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. +- ``linkingObjects`` is a special type used to define an inverse relationship. +- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in 'realm-js@10.5.0-beta.1'. +- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in 'realm-js@10.5.0-beta.1'. +- ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in 'realm-js@10.5.0-beta.1'. +- ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in 'realm-js@10.5.0-beta.1'. diff --git a/source/sdk/react-native/data-types/mixed.txt b/source/sdk/react-native/data-types/mixed.txt new file mode 100644 index 0000000000..59de0bb797 --- /dev/null +++ b/source/sdk/react-native/data-types/mixed.txt @@ -0,0 +1,65 @@ +.. _react-nativedata-types-mixed: + +======================== +Mixed - React Native SDK +======================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- +The mixed data type is a {+realm+} property type that can hold different data types. +Supported data types include: + +- bool +- int +- float +- double +- string +- Date +- Data +- UUID +- Set +- null + +.. note:: + + The mixed data type is indexable, but you can't use it as a primary key. + Because null is a permitted value, you can't declare a Mixed property as + optional. + +Realm Object Models +------------------- +To :ref:`set a property of your object model +` as mixed, set the property's type to +``"mixed"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js + :language: javascript + +Create an Object With a Mixed Value +----------------------------------- +Create an object with a mixed value by running the :js-sdk:`realm.create() +` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js + :language: javascript + +Query for Objects with a Mixed Value +------------------------------------ +Query for objects with a mixed value by running the +:js-sdk:`Collection.filtered() ` method and +passing in a :ref:`filter ` for a non-mixed field. You can +then print the value of the mixed property or the entire object itself. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js + :language: javascript + + diff --git a/source/sdk/react-native/data-types/sets.txt b/source/sdk/react-native/data-types/sets.txt new file mode 100644 index 0000000000..9d4eed7d73 --- /dev/null +++ b/source/sdk/react-native/data-types/sets.txt @@ -0,0 +1,112 @@ +.. _react-native-data-types-sets: + +======================= +Sets - React Native SDK +======================= + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- +A ``{+service-short+} Set`` is a special object that allows you to store a +collection of unique values. ``{+service-short+} Sets`` are based on JavaScript +:mdn:`sets `, but can only contain +values of a single type and can only be modified within a write transaction. +Sets allow you to perform math operations such as finding the union, +intersection, or difference between two sets. To learn more about performing +these operations, see the MDN docs for :mdn:`Implementing basic set operations +`. + +.. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order + + When using a ``forEach()`` loop or alternative :mdn:`iteration method + ` to traverse + the set in a loop, the content of the ``{+service-short+} Set`` may be in a + different order than originally written to. If you require an ordered version + of your set, you must implement that ordering yourself. If you require an + ordered version of your set, you must implement that order yourself. You can + do this by creating an array from the set, using :mdn:`Array.from(mySet) + ` or the :mdn:`spread + operator `. You can keep + that array updated by using a :ref:`change listener ` + to react to changes to the set. + + +.. _react-native-define-set-objects: + +Realm Object Models +------------------- +To define a property type as a ``{+service-short+} Set``, specify the data type +you want in the set, followed by ``<>``. For instance, for a set made of integer +values, specify ``"int<>"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-set-objects.js + :language: javascript + +.. _react-native-create-set-objects: + +Create an Object With a Set +--------------------------- +To create an object with a ``{+service-short+} Set`` property, you must create +the object within a write transaction. When defining your {+service-short+} +object, initialize the ``{+service-short+} Set`` by passing an empty array or an +array with your initial values. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js + :language: javascript + + +.. _react-native-add-items-to-set: + +Add Items to a Set +------------------ +To add an item to a set, pass the new value to the ``.add()`` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.add-items-to-set.js + :language: javascript + +.. _react-native-check-if-set-has-items: + +Check if a Set has Specific Items +--------------------------------- +To determine if a set contains a particular value, pass the value to the ``.has()`` method. The +``set.has()`` method will return true if the set contains the value specified. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.check-if-set-has-items.js + :language: javascript + +.. _react-native-check-set-size: + +Check the Size of a Set +----------------------- +To discover how many items are in a set, you can check the set's ``size`` property. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.check-set-size.js + :language: javascript + +.. _react-native-remove-specific-item-from-set: + +Remove an Item from a Set +------------------------- +To remove a specific value from a set, pass the value to the ``.delete()`` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-specific-item-from-set.js + :language: javascript + + +.. _react-native-remove-all-items-from-set: + +Remove all Items from a Set +--------------------------- +To clear the set, run the ``.clear()`` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.remove-all-items-from-set.js + :language: javascript diff --git a/source/sdk/react-native/data-types/uuid.txt b/source/sdk/react-native/data-types/uuid.txt new file mode 100644 index 0000000000..6abefb73bb --- /dev/null +++ b/source/sdk/react-native/data-types/uuid.txt @@ -0,0 +1,40 @@ +.. _react-native-data-types-uuid: + +======================= +UUID - React Native SDK +======================= +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- + +``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value +`. You can use ``UUID`` as an identifier for +objects. ``UUID`` is :ref:`indexable ` and you can use it as a +:ref:`primary key `. + +.. note:: Using UUID Instead of ObjectId + + In general, you can use ``UUID`` in any field that you need a unique + identifier. Using ``UUID`` might be particularly useful if you are migrating + data not stored in MongoDB since it is likely that your object's unique + identifiers are already of a ``UUID`` type. + +Usage +----- +To define a property as a ``UUID``, set its type to the string ``"uuid"`` in +your :ref:`object model `. Create a {+service-short+} +object within a write transaction. To set any unique identifier properties of +your object to a random value, call ``new UUID()``. Alternatively, set a string +to ``new UUID()`` to set the unique identifier property to a specific value. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js + :language: javascript \ No newline at end of file From 6b5aaefee67190f3bc5dd23fb05361b787430554 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:42:14 -0400 Subject: [PATCH 15/29] add data types to toc --- source/sdk/react-native.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/sdk/react-native.txt b/source/sdk/react-native.txt index c19e7db22b..4fdaeefd0a 100644 --- a/source/sdk/react-native.txt +++ b/source/sdk/react-native.txt @@ -12,6 +12,7 @@ MongoDB Realm React Native SDK Quick Start Quick Start with Sync Fundamentals + Data Types Usage Examples Advanced Guides From 63a342ece6ade6c089e7cae73b9a1aa5f94d279b Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:43:33 -0400 Subject: [PATCH 16/29] fix rn mixed links --- source/sdk/react-native/data-types/mixed.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/sdk/react-native/data-types/mixed.txt b/source/sdk/react-native/data-types/mixed.txt index 59de0bb797..ce5596b188 100644 --- a/source/sdk/react-native/data-types/mixed.txt +++ b/source/sdk/react-native/data-types/mixed.txt @@ -38,7 +38,7 @@ Supported data types include: Realm Object Models ------------------- To :ref:`set a property of your object model -` as mixed, set the property's type to +` as mixed, set the property's type to ``"mixed"``. .. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js @@ -56,7 +56,7 @@ Query for Objects with a Mixed Value ------------------------------------ Query for objects with a mixed value by running the :js-sdk:`Collection.filtered() ` method and -passing in a :ref:`filter ` for a non-mixed field. You can +passing in a :ref:`filter ` for a non-mixed field. You can then print the value of the mixed property or the entire object itself. .. literalinclude:: /examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js From 33d63bec9ea521033213a5147b4bdabf5ce208f1 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:47:52 -0400 Subject: [PATCH 17/29] attempt to add realm-js links --- source/sdk/node/data-types/field-types.txt | 8 ++++---- source/sdk/react-native/data-types/field-types.txt | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 53812eece2..549954db42 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -23,7 +23,7 @@ Field Types - Node.js SDK - ``date`` maps to the JavaScript :mdn:`Date ` type. - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. - ``linkingObjects`` is a special type used to define an inverse relationship. -- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in 'realm-js@10.5.0-beta.1'. -- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in 'realm-js@10.5.0-beta.1'. -- ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in 'realm-js@10.5.0-beta.1'. -- ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in 'realm-js@10.5.0-beta.1'. +- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. \ No newline at end of file diff --git a/source/sdk/react-native/data-types/field-types.txt b/source/sdk/react-native/data-types/field-types.txt index afa2d38e62..85a597a24b 100644 --- a/source/sdk/react-native/data-types/field-types.txt +++ b/source/sdk/react-native/data-types/field-types.txt @@ -23,7 +23,7 @@ Field Types - React Native SDK - ``date`` maps to the JavaScript :mdn:`Date ` type. - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. - ``linkingObjects`` is a special type used to define an inverse relationship. -- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in 'realm-js@10.5.0-beta.1'. -- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in 'realm-js@10.5.0-beta.1'. -- ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in 'realm-js@10.5.0-beta.1'. -- ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in 'realm-js@10.5.0-beta.1'. +- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. \ No newline at end of file From b2587f181cc2a6195491e0579b07eb5f1e9752d3 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 09:52:27 -0400 Subject: [PATCH 18/29] more grammar and woridng fixes --- source/sdk/node/data-types/dictionaries.txt | 4 ++-- source/sdk/node/data-types/field-types.txt | 8 ++++---- source/sdk/react-native/data-types/dictionaries.txt | 4 ++-- source/sdk/react-native/data-types/field-types.txt | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/sdk/node/data-types/dictionaries.txt b/source/sdk/node/data-types/dictionaries.txt index d53619cd8b..69973081b1 100644 --- a/source/sdk/node/data-types/dictionaries.txt +++ b/source/sdk/node/data-types/dictionaries.txt @@ -50,8 +50,8 @@ dictionary's properties by using :mdn:`bracket-notation .@keys`` or ``.@values``. For instance, if you had a ``Person`` collection with a nested ``home`` dictionary, you could -determine return all ``Person`` objects with a ``home`` with a ``"price"`` -property by running the query: ``home.@keys = "price"``. +return all ``Person`` objects with a ``home`` with a ``"price"`` property by +running the query: ``home.@keys = "price"``. .. literalinclude:: /examples/generated/node/data-types.codeblock.query-a-dictionary.js :language: javascript diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 549954db42..9cbe9bef05 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -13,9 +13,9 @@ Field Types - Node.js SDK {+client-database+} supports the following field data types: - ``bool`` maps to the JavaScript :mdn:`Boolean ` type -- ``int`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``int`` with 64 bits. -- ``float`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``float`` with 32 bits. -- ``double`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``double`` with 64 bits. +- ``int`` maps to the JavaScript :mdn:`Number ` type. Internally, {+client-database+} stores ``int`` with 64 bits. +- ``float`` maps to the JavaScript :mdn:`Number ` type. Internally, {+client-database+} stores ``float`` with 32 bits. +- ``double`` maps to the JavaScript :mdn:`Number ` type. Internally, {+client-database+} stores ``double`` with 64 bits. - ``string`` maps to the JavaScript :mdn:`String ` type. - ``decimal128`` for high precision numbers. - ``objectId`` maps to BSON :manual:`ObjectId ` type. @@ -24,6 +24,6 @@ Field Types - Node.js SDK - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. - ``linkingObjects`` is a special type used to define an inverse relationship. - ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. -- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. - ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. - ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. \ No newline at end of file diff --git a/source/sdk/react-native/data-types/dictionaries.txt b/source/sdk/react-native/data-types/dictionaries.txt index 95cc0c15dc..857ff1b86c 100644 --- a/source/sdk/react-native/data-types/dictionaries.txt +++ b/source/sdk/react-native/data-types/dictionaries.txt @@ -50,8 +50,8 @@ dictionary's properties by using :mdn:`bracket-notation .@keys`` or ``.@values``. For instance, if you had a ``Person`` collection with a nested ``home`` dictionary, you could -determine return all ``Person`` objects with a ``home`` with a ``"price"`` -property by running the query: ``home.@keys = "price"``. +return all ``Person`` objects with a ``home`` with a ``"price"`` property by +running the query: ``home.@keys = "price"``. .. literalinclude:: /examples/generated/node/data-types.codeblock.query-a-dictionary.js :language: javascript diff --git a/source/sdk/react-native/data-types/field-types.txt b/source/sdk/react-native/data-types/field-types.txt index 85a597a24b..3536040697 100644 --- a/source/sdk/react-native/data-types/field-types.txt +++ b/source/sdk/react-native/data-types/field-types.txt @@ -13,9 +13,9 @@ Field Types - React Native SDK {+client-database+} supports the following field data types: - ``bool`` maps to the JavaScript :mdn:`Boolean ` type -- ``int`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``int`` with 64 bits. -- ``float`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``float`` with 32 bits. -- ``double`` maps to the JavaScript :mdn:`Number ` type. Internally {+client-database+} stores ``double`` with 64 bits. +- ``int`` maps to the JavaScript :mdn:`Number ` type. Internally, {+client-database+} stores ``int`` with 64 bits. +- ``float`` maps to the JavaScript :mdn:`Number ` type. Internally, {+client-database+} stores ``float`` with 32 bits. +- ``double`` maps to the JavaScript :mdn:`Number ` type. Internally, {+client-database+} stores ``double`` with 64 bits. - ``string`` maps to the JavaScript :mdn:`String ` type. - ``decimal128`` for high precision numbers. - ``objectId`` maps to BSON :manual:`ObjectId ` type. @@ -24,6 +24,6 @@ Field Types - React Native SDK - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. - ``linkingObjects`` is a special type used to define an inverse relationship. - ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. -- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. +- ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. - ``dictionary`` used to manage a collection of unique String keys paired with values. The ``Dictionary`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. - ``mixed`` is a property type that can hold different data types. The ``Mixed`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. \ No newline at end of file From d7dbb9e57e48e28fbac41efb782a1afbba328873 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:21:10 -0400 Subject: [PATCH 19/29] wording fixes --- source/sdk/node/data-types/field-types.txt | 2 +- source/sdk/node/data-types/mixed.txt | 26 +++++++++++-------- .../react-native/data-types/field-types.txt | 2 +- source/sdk/react-native/data-types/mixed.txt | 26 +++++++++++-------- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 9cbe9bef05..fcf0fd3e4c 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -21,7 +21,7 @@ Field Types - Node.js SDK - ``objectId`` maps to BSON :manual:`ObjectId ` type. - ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. - ``date`` maps to the JavaScript :mdn:`Date ` type. -- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. +- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of primitive value types by appending ``[]`` to the type name. - ``linkingObjects`` is a special type used to define an inverse relationship. - ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. - ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 4b3e280228..adbfce4008 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -18,16 +18,20 @@ Overview The mixed data type is a {+realm+} property type that can hold different data types. Supported data types include: -- bool -- int -- float -- double -- string -- Date -- Data -- UUID -- Set -- null +- ``bool`` +- ``int`` +- ``float`` +- ``double`` +- ``string`` +- ``decimal128`` +- ``objectId`` +- ``Date`` +- ``Data`` +- ``list`` +- ``UUID`` +- ``Set`` +- ``Dictionary`` +- ``null`` .. note:: @@ -39,7 +43,7 @@ Realm Object Models ------------------- To :ref:`set a property of your object model ` as mixed, set the property's type to -``"mixed"``. +"``mixed``". .. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js :language: javascript diff --git a/source/sdk/react-native/data-types/field-types.txt b/source/sdk/react-native/data-types/field-types.txt index 3536040697..380214fd42 100644 --- a/source/sdk/react-native/data-types/field-types.txt +++ b/source/sdk/react-native/data-types/field-types.txt @@ -21,7 +21,7 @@ Field Types - React Native SDK - ``objectId`` maps to BSON :manual:`ObjectId ` type. - ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. - ``date`` maps to the JavaScript :mdn:`Date ` type. -- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. +- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of primitive value type by appending ``[]`` to the type name. - ``linkingObjects`` is a special type used to define an inverse relationship. - ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. The ``UUID`` data type is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. - ``set`` is based on the JavaScript :mdn:`Set ` type. ``{+service-short+} Set`` is available in the :js-sdk:`realm-js@10.5.0-beta.1 release `. diff --git a/source/sdk/react-native/data-types/mixed.txt b/source/sdk/react-native/data-types/mixed.txt index ce5596b188..6d3728bed0 100644 --- a/source/sdk/react-native/data-types/mixed.txt +++ b/source/sdk/react-native/data-types/mixed.txt @@ -18,16 +18,20 @@ Overview The mixed data type is a {+realm+} property type that can hold different data types. Supported data types include: -- bool -- int -- float -- double -- string -- Date -- Data -- UUID -- Set -- null +- ``bool`` +- ``int`` +- ``float`` +- ``double`` +- ``string`` +- ``decimal128`` +- ``objectId`` +- ``Date`` +- ``Data`` +- ``list`` +- ``UUID`` +- ``Set`` +- ``Dictionary`` +- ``null`` .. note:: @@ -39,7 +43,7 @@ Realm Object Models ------------------- To :ref:`set a property of your object model ` as mixed, set the property's type to -``"mixed"``. +"``mixed``". .. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js :language: javascript From 96870bab0cba3765bd5b2aa53a811815f89e7c45 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:21:52 -0400 Subject: [PATCH 20/29] Update source/sdk/node/data-types/uuid.txt Co-authored-by: nate contino --- source/sdk/node/data-types/uuid.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index ef0cfaafd3..c79231b897 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -23,7 +23,7 @@ objects. ``UUID`` is :ref:`indexable ` and you can use it as a .. note:: Using UUID Instead of ObjectId - In general, you can use ``UUID`` in any field that you need a unique + In general, you can use ``UUID`` for any fields that function as a unique identifier. Using ``UUID`` might be particularly useful if you are migrating data not stored in MongoDB since it is likely that your object's unique identifiers are already of a ``UUID`` type. @@ -37,4 +37,4 @@ your object to a random value, call ``new UUID()``. Alternatively, set a string to ``new UUID()`` to set the unique identifier property to a specific value. .. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js - :language: javascript \ No newline at end of file + :language: javascript From efb91b994c6e4aa424d4a53139b3540ee0fdc70f Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:22:49 -0400 Subject: [PATCH 21/29] change uuid note on rn to match node --- source/sdk/react-native/data-types/uuid.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/react-native/data-types/uuid.txt b/source/sdk/react-native/data-types/uuid.txt index 6abefb73bb..931e005024 100644 --- a/source/sdk/react-native/data-types/uuid.txt +++ b/source/sdk/react-native/data-types/uuid.txt @@ -23,7 +23,7 @@ objects. ``UUID`` is :ref:`indexable ` and you can use it .. note:: Using UUID Instead of ObjectId - In general, you can use ``UUID`` in any field that you need a unique + In general, you can use ``UUID`` for any fields that function as a unique identifier. Using ``UUID`` might be particularly useful if you are migrating data not stored in MongoDB since it is likely that your object's unique identifiers are already of a ``UUID`` type. From 375093fecde8603b2530fe9b3ec75763319aadd2 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:24:13 -0400 Subject: [PATCH 22/29] added note about obj id to both rn and node --- source/sdk/node/data-types/uuid.txt | 3 ++- source/sdk/react-native/data-types/uuid.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index c79231b897..3669223435 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -26,7 +26,8 @@ objects. ``UUID`` is :ref:`indexable ` and you can use it as a In general, you can use ``UUID`` for any fields that function as a unique identifier. Using ``UUID`` might be particularly useful if you are migrating data not stored in MongoDB since it is likely that your object's unique - identifiers are already of a ``UUID`` type. + identifiers are already of a ``UUID`` type. Alternatively, using ``ObjectId`` + might be useful for a collection of data that already exists in MongoDB. Usage ----- diff --git a/source/sdk/react-native/data-types/uuid.txt b/source/sdk/react-native/data-types/uuid.txt index 931e005024..0978ff5b71 100644 --- a/source/sdk/react-native/data-types/uuid.txt +++ b/source/sdk/react-native/data-types/uuid.txt @@ -26,7 +26,8 @@ objects. ``UUID`` is :ref:`indexable ` and you can use it In general, you can use ``UUID`` for any fields that function as a unique identifier. Using ``UUID`` might be particularly useful if you are migrating data not stored in MongoDB since it is likely that your object's unique - identifiers are already of a ``UUID`` type. + identifiers are already of a ``UUID`` type. Alternatively, using ``ObjectId`` + might be useful for a collection of data that already exists in MongoDB. Usage ----- From f2035ae88e9007ccafdd55848098015ef12bf613 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:24:46 -0400 Subject: [PATCH 23/29] Update source/sdk/node/data-types/mixed.txt Co-authored-by: nate contino --- source/sdk/node/data-types/mixed.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index adbfce4008..609303aacd 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -42,7 +42,7 @@ Supported data types include: Realm Object Models ------------------- To :ref:`set a property of your object model -` as mixed, set the property's type to +` as ``Mixed``, set the property's type to "``mixed``". .. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js @@ -66,4 +66,3 @@ then print the value of the mixed property or the entire object itself. .. literalinclude:: /examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js :language: javascript - From 897704a83c16ebad7a4061d04a6f8da1f9042b2e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:25:49 -0400 Subject: [PATCH 24/29] fix 'mixed' formatting on rn to match node --- source/sdk/react-native/data-types/mixed.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/react-native/data-types/mixed.txt b/source/sdk/react-native/data-types/mixed.txt index 6d3728bed0..af83f37b64 100644 --- a/source/sdk/react-native/data-types/mixed.txt +++ b/source/sdk/react-native/data-types/mixed.txt @@ -42,7 +42,7 @@ Supported data types include: Realm Object Models ------------------- To :ref:`set a property of your object model -` as mixed, set the property's type to +` as ``Mixed``, set the property's type to "``mixed``". .. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js From c44908b4f66e832ff405414a2a22af875f897902 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:33:25 -0400 Subject: [PATCH 25/29] change monospace to bold --- source/sdk/node/data-types/sets.txt | 14 +++++++------- source/sdk/react-native/data-types/sets.txt | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 17ab6b948c..91a4b91d31 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -16,8 +16,8 @@ Sets - Node.js SDK Overview -------- -A ``{+service-short+} Set`` is a special object that allows you to store a -collection of unique values. ``{+service-short+} Sets`` are based on JavaScript +A **{+service-short+} Set** is a special object that allows you to store a +collection of unique values. **{+service-short+} Sets** are based on JavaScript :mdn:`sets `, but can only contain values of a single type and can only be modified within a write transaction. Sets allow you to perform math operations such as finding the union, @@ -25,11 +25,11 @@ intersection, or difference between two sets. To learn more about performing these operations, see the MDN docs for :mdn:`Implementing basic set operations `. -.. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order +.. note:: **{+service-short+} Sets** Do Not Guarantee Traversal Order When using a ``forEach()`` loop or alternative :mdn:`iteration method ` to traverse - the set in a loop, the content of the ``{+service-short+} Set`` may be in a + the set in a loop, the content of the **{+service-short+} Set** may be in a different order than originally written to. If you require an ordered version of your set, you must implement that ordering yourself. If you require an ordered version of your set, you must implement that order yourself. You can @@ -44,7 +44,7 @@ these operations, see the MDN docs for :mdn:`Implementing basic set operations Realm Object Models ------------------- -To define a property type as a ``{+service-short+} Set``, specify the data type +To define a property type as a **{+service-short+} Set**, specify the data type you want in the set, followed by ``<>``. For instance, for a set made of integer values, specify ``"int<>"``. @@ -55,9 +55,9 @@ values, specify ``"int<>"``. Create an Object With a Set --------------------------- -To create an object with a ``{+service-short+} Set`` property, you must create +To create an object with a **{+service-short+} Set** property, you must create the object within a write transaction. When defining your {+service-short+} -object, initialize the ``{+service-short+} Set`` by passing an empty array or an +object, initialize the **{+service-short+} Set** by passing an empty array or an array with your initial values. .. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js diff --git a/source/sdk/react-native/data-types/sets.txt b/source/sdk/react-native/data-types/sets.txt index 9d4eed7d73..d1d2d83bb6 100644 --- a/source/sdk/react-native/data-types/sets.txt +++ b/source/sdk/react-native/data-types/sets.txt @@ -16,8 +16,8 @@ Sets - React Native SDK Overview -------- -A ``{+service-short+} Set`` is a special object that allows you to store a -collection of unique values. ``{+service-short+} Sets`` are based on JavaScript +A **{+service-short+} Set**is a special object that allows you to store a +collection of unique values. **{+service-short+} Sets**are based on JavaScript :mdn:`sets `, but can only contain values of a single type and can only be modified within a write transaction. Sets allow you to perform math operations such as finding the union, @@ -25,11 +25,11 @@ intersection, or difference between two sets. To learn more about performing these operations, see the MDN docs for :mdn:`Implementing basic set operations `. -.. note:: ``{+service-short+} Sets`` Do Not Guarantee Traversal Order +.. note:: **{+service-short+} Sets**Do Not Guarantee Traversal Order When using a ``forEach()`` loop or alternative :mdn:`iteration method ` to traverse - the set in a loop, the content of the ``{+service-short+} Set`` may be in a + the set in a loop, the content of the **{+service-short+} Set**may be in a different order than originally written to. If you require an ordered version of your set, you must implement that ordering yourself. If you require an ordered version of your set, you must implement that order yourself. You can @@ -55,9 +55,9 @@ values, specify ``"int<>"``. Create an Object With a Set --------------------------- -To create an object with a ``{+service-short+} Set`` property, you must create +To create an object with a **{+service-short+} Set**property, you must create the object within a write transaction. When defining your {+service-short+} -object, initialize the ``{+service-short+} Set`` by passing an empty array or an +object, initialize the **{+service-short+} Set**by passing an empty array or an array with your initial values. .. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js From e0ea0fc1fdc7085b6072e6587205221b10c10863 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:38:13 -0400 Subject: [PATCH 26/29] fix spacing errors --- source/sdk/react-native/data-types/sets.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/sdk/react-native/data-types/sets.txt b/source/sdk/react-native/data-types/sets.txt index d1d2d83bb6..f99b2f35fd 100644 --- a/source/sdk/react-native/data-types/sets.txt +++ b/source/sdk/react-native/data-types/sets.txt @@ -16,8 +16,8 @@ Sets - React Native SDK Overview -------- -A **{+service-short+} Set**is a special object that allows you to store a -collection of unique values. **{+service-short+} Sets**are based on JavaScript +A **{+service-short+} Set** is a special object that allows you to store a +collection of unique values. **{+service-short+} Sets** are based on JavaScript :mdn:`sets `, but can only contain values of a single type and can only be modified within a write transaction. Sets allow you to perform math operations such as finding the union, @@ -25,11 +25,11 @@ intersection, or difference between two sets. To learn more about performing these operations, see the MDN docs for :mdn:`Implementing basic set operations `. -.. note:: **{+service-short+} Sets**Do Not Guarantee Traversal Order +.. note:: **{+service-short+} Sets** Do Not Guarantee Traversal Order When using a ``forEach()`` loop or alternative :mdn:`iteration method ` to traverse - the set in a loop, the content of the **{+service-short+} Set**may be in a + the set in a loop, the content of the **{+service-short+} Set** may be in a different order than originally written to. If you require an ordered version of your set, you must implement that ordering yourself. If you require an ordered version of your set, you must implement that order yourself. You can @@ -55,9 +55,9 @@ values, specify ``"int<>"``. Create an Object With a Set --------------------------- -To create an object with a **{+service-short+} Set**property, you must create +To create an object with a **{+service-short+} Set** property, you must create the object within a write transaction. When defining your {+service-short+} -object, initialize the **{+service-short+} Set**by passing an empty array or an +object, initialize the **{+service-short+} Set** by passing an empty array or an array with your initial values. .. literalinclude:: /examples/generated/node/data-types.codeblock.create-set-objects.js From 97a53502a7d7bcb7876ae9c6b849b877e16a42ae Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 11:52:40 -0400 Subject: [PATCH 27/29] fix wording --- source/sdk/node/data-types/uuid.txt | 2 +- source/sdk/react-native/data-types/uuid.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index 3669223435..2859b9363c 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -34,7 +34,7 @@ Usage To define a property as a ``UUID``, set its type to the string ``"uuid"`` in your :ref:`object model `. Create a {+service-short+} object within a write transaction. To set any unique identifier properties of -your object to a random value, call ``new UUID()``. Alternatively, set a string +your object to a random value, call ``new UUID()``. Alternatively, pass a string to ``new UUID()`` to set the unique identifier property to a specific value. .. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js diff --git a/source/sdk/react-native/data-types/uuid.txt b/source/sdk/react-native/data-types/uuid.txt index 0978ff5b71..c3b93ad73d 100644 --- a/source/sdk/react-native/data-types/uuid.txt +++ b/source/sdk/react-native/data-types/uuid.txt @@ -34,7 +34,7 @@ Usage To define a property as a ``UUID``, set its type to the string ``"uuid"`` in your :ref:`object model `. Create a {+service-short+} object within a write transaction. To set any unique identifier properties of -your object to a random value, call ``new UUID()``. Alternatively, set a string +your object to a random value, call ``new UUID()``. Alternatively, pass a string to ``new UUID()`` to set the unique identifier property to a specific value. .. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js From 99078cc0591796ca31c51bb6d340243e2d956333 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 15:57:32 -0400 Subject: [PATCH 28/29] correct supported types for mixed --- source/sdk/node/data-types/mixed.txt | 22 ++++---------------- source/sdk/react-native/data-types/mixed.txt | 20 +++--------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 609303aacd..1d584d49be 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -15,25 +15,11 @@ Mixed - Node.js SDK Overview -------- -The mixed data type is a {+realm+} property type that can hold different data types. -Supported data types include: +The mixed data type is a {+realm+} property type that can hold any valid Realm data type except a collection. +You can create collections (lists, sets and dictionaries) of type ``mixed``, but a ``mixed`` itself +cannot be a collection. Properties using the mixed property type can also hold null values. -- ``bool`` -- ``int`` -- ``float`` -- ``double`` -- ``string`` -- ``decimal128`` -- ``objectId`` -- ``Date`` -- ``Data`` -- ``list`` -- ``UUID`` -- ``Set`` -- ``Dictionary`` -- ``null`` - -.. note:: +.. note:: The mixed data type is indexable, but you can't use it as a primary key. Because null is a permitted value, you can't declare a Mixed property as diff --git a/source/sdk/react-native/data-types/mixed.txt b/source/sdk/react-native/data-types/mixed.txt index af83f37b64..81478fdd5d 100644 --- a/source/sdk/react-native/data-types/mixed.txt +++ b/source/sdk/react-native/data-types/mixed.txt @@ -15,23 +15,9 @@ Mixed - React Native SDK Overview -------- -The mixed data type is a {+realm+} property type that can hold different data types. -Supported data types include: - -- ``bool`` -- ``int`` -- ``float`` -- ``double`` -- ``string`` -- ``decimal128`` -- ``objectId`` -- ``Date`` -- ``Data`` -- ``list`` -- ``UUID`` -- ``Set`` -- ``Dictionary`` -- ``null`` +The mixed data type is a {+realm+} property type that can hold any valid Realm data type except a collection. +You can create collections (lists, sets and dictionaries) of type ``mixed``, but a ``mixed`` itself +cannot be a collection. Properties using the mixed property type can also hold null values. .. note:: From e0cc203544259c9a8890b92964fc726a4fc959bf Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 19 May 2021 16:31:15 -0400 Subject: [PATCH 29/29] wording update --- source/sdk/node/data-types/mixed.txt | 4 ++-- source/sdk/react-native/data-types/mixed.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 1d584d49be..6b9b92491a 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -16,8 +16,8 @@ Mixed - Node.js SDK Overview -------- The mixed data type is a {+realm+} property type that can hold any valid Realm data type except a collection. -You can create collections (lists, sets and dictionaries) of type ``mixed``, but a ``mixed`` itself -cannot be a collection. Properties using the mixed property type can also hold null values. +You can create collections (lists, sets, and dictionaries) of type ``mixed``, but a ``mixed`` itself +cannot be a collection. Properties using the mixed data type can also hold null values. .. note:: diff --git a/source/sdk/react-native/data-types/mixed.txt b/source/sdk/react-native/data-types/mixed.txt index 81478fdd5d..7e3a4c4daa 100644 --- a/source/sdk/react-native/data-types/mixed.txt +++ b/source/sdk/react-native/data-types/mixed.txt @@ -16,8 +16,8 @@ Mixed - React Native SDK Overview -------- The mixed data type is a {+realm+} property type that can hold any valid Realm data type except a collection. -You can create collections (lists, sets and dictionaries) of type ``mixed``, but a ``mixed`` itself -cannot be a collection. Properties using the mixed property type can also hold null values. +You can create collections (lists, sets, and dictionaries) of type ``mixed``, but a ``mixed`` itself +cannot be a collection. Properties using the mixed data type can also hold null values. .. note::