pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.57k stars 1.06k forks source link

Changing an array does not fire the replication primitive push handler. #6383

Closed isaiahdahl closed 4 weeks ago

isaiahdahl commented 1 month ago

Having an issue working with the replication primitives and making changes to array type properties. I have a schema like this:

export const SETLIST_SCHEMA_LITERAL = {
  // id: 'library catalog items schema',
  description: 'Setlist schema',
  version: 0,
  keyCompression: false,
  primaryKey: 'id',
  type: 'object',
  properties: {
    id: {
      type: 'string',
      maxLength: 100000
    },
    object: {
      type: 'string'
    },
    details: {
      type: 'object',
      properties: {
        name: {
          type: 'string'
        },
        location: {
          type: ['object', 'null'],
        },
        schedule: {
          type: ['object', 'null'],
          properties: {
            date: {
              type: 'string'
            },
            start_times: {
              type: 'array',
              items: {
                type: 'string'
              }
            }
          }
        },
        tags: {
          type: ['array', 'null'],
          items: {
            type: 'string'
          }
        }
      }
    },
    mode: {
      type: 'string'
    },
    status: {
      type: 'string'
    },
    leader: {
      type: ['string', 'null']
    },
    team: {
      type: ['array', 'null'],
      items: {
        type: 'object',
        properties: {
          object: {
            type: 'string'
          },
          name: {
            type: 'string'
          },
          occupant_id: {
            type: 'string'
          },
          avatar_url: {
            type: ['string', 'null']
          },
          instruments: {
            type: ['array', 'null'],
            items: {
              type: 'string'
            }
          }
        }
      }
    },
    items: {
      type: ['array', 'null'],
      items: {
        type: 'object',
        properties: {
          object: {
            type: 'string'
          },
          catalog_item_id: {
            type: 'integer'
          },
          title: {
            type: 'string'
          },
          duration: {
            type: 'integer'
          },
          key: {
            type: 'string'
          },
          parts: {
            type: 'object'
          }
        }
      }
    },
    updated_at: {
      type: 'string'
    },
    _deleted: {
      type: 'boolean'
    }
  },
  required: [
    'id'
  ],
  attachments: {
    encrypted: false
  }
} as const;

When I make changes to the "items" or "teams" using a "query".modify() the documents don't end up firing through the push handler, but I can see that the document has changed when I inspect the database.

Example snippet of what that looks like in my codebase:

async addToSetlist() {
    const selectedSetlistIds = this.setlists.map((setlist: any) => {
      if (setlist.selected) {
        return setlist.id
      }
    });
    const query = this.databaseService.db.library_setlists.find({
      selector: {
        id: {
          $in: selectedSetlistIds
        }
      }
    });
    this.querying = true;
    await query.modify((setlist: any) => {
      if (!setlist.items) {
        setlist.items = [];
      }
      setlist.items = [
        ...setlist.items,
        {
          object: this.catalogItem.object,
          catalog_item_id: parseInt(this.catalogItem.id),
          title: this.catalogItem.details.title,
          duration: 0,    // TODO: Change from hardcoded values
          key: this.catalogItem.details.keys,
          parts: JSON.parse(JSON.stringify(this.catalogItem.parts))
        }
      ];
      this.querying = false;
      return setlist;
    });
    await this.modalCtrl.dismiss({}, 'added-to-setlist');
  }

Is this expected behavior that arrays wouldn't fire that replication push handler?

Before I go and try and create a test case I'd like to know if this is like a known behaviour.

pubkey commented 1 month ago

Is this expected behavior that arrays wouldn't fire that replication push handler?

No. All changes should fire the push handler.

stale[bot] commented 1 month ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

stale[bot] commented 4 weeks ago

Issues are autoclosed after some time. If you still have a problem, make a PR with a test case or to prove that you have tried to fix the problem.