From f3c401b8d2d19f73a5bc8335f2400d2b6bc1fc41 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Tue, 18 Feb 2020 11:02:45 -0800 Subject: [PATCH] fix(sharedb): correct sharedb.DB.getOps so it has nullable arguments (#42331) * Update typings: getOps can have null from or to The docs for ShareDB clearly state that `from` and `to` arguments in `getOps` are nullable: > - `from` number: the first op version to fetch. If set to null, then ops will be fetched from the earliest version > - `to` number: The last op version. This version will not be fetched (ie to is non-inclusive). If set to null, then ops will be fetched up to the latest version * Add tests and name "Definitions by" Co-authored-by: petertravelchime <54869620+petertravelchime@users.noreply.github.com> --- types/sharedb/index.d.ts | 5 +++-- types/sharedb/sharedb-tests.ts | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/types/sharedb/index.d.ts b/types/sharedb/index.d.ts index 0fdd4b5584..9850ce4f3f 100644 --- a/types/sharedb/index.d.ts +++ b/types/sharedb/index.d.ts @@ -2,6 +2,7 @@ // Project: https://github.com/share/sharedb // Definitions by: Steve Oney // Eric Hwang +// Peter Xu // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 3.0 @@ -65,8 +66,8 @@ declare namespace sharedb { commit(collection: string, id: string, op: Op, snapshot: any, options: any, callback: (...args: any[]) => any): void; getSnapshot(collection: string, id: string, fields: any, options: any, callback: (...args: any[]) => any): void; getSnapshotBulk(collection: string, ids: string, fields: any, options: any, callback: (...args: any[]) => any): void; - getOps(collection: string, id: string, from: number, to: number, options: any, callback: (...args: any[]) => any): void; - getOpsToSnapshot(collection: string, id: string, from: number, snapshot: number, options: any, callback: (...args: any[]) => any): void; + getOps(collection: string, id: string, from: number | null, to: number | null, options: any, callback: (...args: any[]) => any): void; + getOpsToSnapshot(collection: string, id: string, from: number | null, snapshot: number, options: any, callback: (...args: any[]) => any): void; getOpsBulk(collection: string, fromMap: any, toMap: any, options: any, callback: (...args: any[]) => any): void; getCommittedOpVersion(collection: string, id: string, snapshot: any, op: any, options: any, callback: (...args: any[]) => any): void; query: DBQueryMethod; diff --git a/types/sharedb/sharedb-tests.ts b/types/sharedb/sharedb-tests.ts index 0f8c62c88c..0ff121b437 100644 --- a/types/sharedb/sharedb-tests.ts +++ b/types/sharedb/sharedb-tests.ts @@ -40,6 +40,11 @@ const backend = new ShareDB({ extraDbs: {myDb: new CustomExtraDb()} }); console.log(backend.db); + +// getOps allows for `from` and `to` to both be `null`: +// https://github.com/share/sharedb/blob/960f5d152f6a8051ed2dcb00a57681a3ebbd7dc2/README.md#getops +backend.db.getOps('someCollection', 'someId', null, null, {}, () => {}); + console.log(backend.pubsub); console.log(backend.extraDbs);