Skip to content

Commit

Permalink
Merge branch 'master' into support-yjs
Browse files Browse the repository at this point in the history
  • Loading branch information
dfahlander committed Jul 1, 2024
2 parents 7742ebb + df2f963 commit 1200a19
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/functions/propmods/add.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PropModification } from "../../helpers/prop-modification";

export function add(value: number | BigInt | Array<string | number>) {
export function add(value: number | bigint | Array<string | number>) {
return new PropModification({add: value});
}
2 changes: 1 addition & 1 deletion src/functions/propmods/remove.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PropModification } from "../../helpers/prop-modification";

export function remove(value: number | BigInt | Array<string | number>) {
export function remove(value: number | bigint | Array<string | number>) {
return new PropModification({remove: value});
}
4 changes: 2 additions & 2 deletions src/helpers/prop-modification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export const PropModSymbol: unique symbol = Symbol();
export class PropModification implements PropModSpec {
[PropModSymbol]?: true;
replacePrefix?: [string, string];
add?: number | BigInt | Array<string | number>;
remove?: number | BigInt | Array<string | number>;
add?: number | bigint | Array<string | number>;
remove?: number | bigint | Array<string | number>;

execute(value: any): any {
// add (mathematical or set-wise)
Expand Down
31 changes: 16 additions & 15 deletions src/public/types/keypaths.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { DucktypedYDoc } from "./yjs-related";

export type KeyPaths<T> = {
[P in keyof T]:
P extends string
? T[P] extends Array<infer K>
? K extends object // only drill into the array element if it's an object
? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}`
: P | `${P}.${number}`
: T[P] extends (...args: any[]) => any // Method
? never
: T[P] extends DucktypedYDoc // circular reference + not valid in update spec or where clause
? never
: T[P] extends object
? P | `${P}.${KeyPaths<T[P]>}`
: P
: never;
[P in keyof T]: P extends string
? T[P] extends Array<infer K>
? K extends any[] // Array of arrays (issue #2026)
? P | `${P}.${number}` | `${P}.${number}.${number}`
: K extends object // only drill into the array element if it's an object
? P | `${P}.${number}` | `${P}.${number}.${KeyPaths<K>}`
: P | `${P}.${number}`
: T[P] extends (...args: any[]) => any // Method
? never
: T[P] extends DucktypedYDoc // Not valid in update spec or where clause (+ avoid circular reference)
? never
: T[P] extends object
? P | `${P}.${KeyPaths<T[P]>}`
: P
: never;
}[keyof T];

export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}`
Expand All @@ -31,4 +32,4 @@ export type KeyPathValue<T, PATH> = PATH extends `${infer R}.${infer S}`
: void
: PATH extends keyof T
? T[PATH]
: void;
: any;
8 changes: 4 additions & 4 deletions src/public/types/prop-modification.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ export declare const PropModSymbol: unique symbol;

export type PropModSpec = {
replacePrefix?: [string, string];
add?: number | BigInt | Array<string | number>;
remove?: number | BigInt | Array<string | number>;
add?: number | bigint | Array<string | number>;
remove?: number | bigint | Array<string | number>;
}

export class PropModification implements PropModSpec {
[PropModSymbol]?: true;
replacePrefix?: [string, string];
add?: number | BigInt | Array<string | number>;
remove?: number | BigInt | Array<string | number>;
add?: number | bigint | Array<string | number>;
remove?: number | bigint | Array<string | number>;

execute<T>(value: T): T;

Expand Down
7 changes: 6 additions & 1 deletion test/typings-test/test-typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,17 @@ import * as Y from 'yjs';
isGoodFriend: boolean;
address: {
city: string;
}
},
matrix: number[][]; // Trigger issue #2026
}

let db = new Dexie('dbname') as Dexie & {friends: Table<Friend, number>};

db.friends.where({name: 'Kalle'}).modify({name: replacePrefix('K', 'C')});

// Issue #2026
db.friends.update(1, {"address.city": "New York"});
db.friends.update(2, {matrix: [[1,2]]});
}


Expand Down

0 comments on commit 1200a19

Please sign in to comment.