@instantdb/react 0.22.75 → 0.22.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/Cursors.js +1 -1
- package/dist/commonjs/Cursors.js.map +1 -1
- package/dist/commonjs/InstantReactWebDatabase.d.ts +1 -1
- package/dist/commonjs/InstantReactWebDatabase.d.ts.map +1 -1
- package/dist/commonjs/InstantReactWebDatabase.js.map +1 -1
- package/dist/commonjs/__types__/typeUtils.d.ts +20 -0
- package/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
- package/dist/commonjs/__types__/typeUtils.js +5 -0
- package/dist/commonjs/__types__/typeUtils.js.map +1 -0
- package/dist/commonjs/__types__/typesTests.d.ts +2 -0
- package/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
- package/dist/commonjs/__types__/typesTests.js +53 -0
- package/dist/commonjs/__types__/typesTests.js.map +1 -0
- package/dist/commonjs/init.d.ts +3 -1
- package/dist/commonjs/init.d.ts.map +1 -1
- package/dist/commonjs/init.js +7 -2
- package/dist/commonjs/init.js.map +1 -1
- package/dist/esm/Cursors.js +1 -1
- package/dist/esm/Cursors.js.map +1 -1
- package/dist/esm/InstantReactWebDatabase.d.ts +1 -1
- package/dist/esm/InstantReactWebDatabase.d.ts.map +1 -1
- package/dist/esm/InstantReactWebDatabase.js.map +1 -1
- package/dist/esm/__types__/typeUtils.d.ts +20 -0
- package/dist/esm/__types__/typeUtils.d.ts.map +1 -0
- package/dist/esm/__types__/typeUtils.js +4 -0
- package/dist/esm/__types__/typeUtils.js.map +1 -0
- package/dist/esm/__types__/typesTests.d.ts +2 -0
- package/dist/esm/__types__/typesTests.d.ts.map +1 -0
- package/dist/esm/__types__/typesTests.js +51 -0
- package/dist/esm/__types__/typesTests.js.map +1 -0
- package/dist/esm/init.d.ts +3 -1
- package/dist/esm/init.d.ts.map +1 -1
- package/dist/esm/init.js +7 -2
- package/dist/esm/init.js.map +1 -1
- package/dist/standalone/index.js +50 -29
- package/dist/standalone/index.umd.cjs +10 -10
- package/package.json +6 -4
- package/src/Cursors.tsx +2 -2
- package/src/InstantReactWebDatabase.ts +4 -3
- package/src/__types__/typeUtils.ts +39 -0
- package/src/__types__/typesTests.ts +86 -0
- package/src/init.ts +17 -8
- package/tsconfig.json +3 -2
- package/tsconfig.test.json +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instantdb/react",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.76",
|
|
4
4
|
"description": "Instant DB for React",
|
|
5
5
|
"homepage": "https://github.com/instantdb/instant/tree/main/client/packages/react",
|
|
6
6
|
"repository": {
|
|
@@ -54,12 +54,14 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"eventsource": "^4.0.0",
|
|
57
|
-
"@instantdb/
|
|
58
|
-
"@instantdb/
|
|
59
|
-
"@instantdb/
|
|
57
|
+
"@instantdb/react-common": "0.22.76",
|
|
58
|
+
"@instantdb/version": "0.22.76",
|
|
59
|
+
"@instantdb/core": "0.22.76"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"test": "vitest",
|
|
63
|
+
"test:types": "tsc -p tsconfig.test.json --noEmit",
|
|
64
|
+
"test:ci": "pnpm run test:types",
|
|
63
65
|
"check-exports": "attw --pack .",
|
|
64
66
|
"dev": "tsc --watch --preserveWatchOutput -p tsconfig.dev.json",
|
|
65
67
|
"clean": "rm -rf dist",
|
package/src/Cursors.tsx
CHANGED
|
@@ -41,7 +41,7 @@ export function Cursors<
|
|
|
41
41
|
_spaceId || `cursors-space-default--${String(room.type)}-${room.id}`;
|
|
42
42
|
|
|
43
43
|
const cursorsPresence = room.usePresence({
|
|
44
|
-
keys: [spaceId],
|
|
44
|
+
keys: [spaceId] as (keyof RoomSchema[RoomType]['presence'])[],
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
const fullPresence = room._core._reactor.getPresence(room.type, room.id);
|
|
@@ -142,7 +142,7 @@ export function Cursors<
|
|
|
142
142
|
{renderCursor ? (
|
|
143
143
|
renderCursor({
|
|
144
144
|
color: cursor.color,
|
|
145
|
-
presence: fullPresence
|
|
145
|
+
presence: fullPresence?.peers[id],
|
|
146
146
|
})
|
|
147
147
|
) : (
|
|
148
148
|
<Cursor {...cursor} />
|
|
@@ -4,10 +4,11 @@ import { EventSource } from 'eventsource';
|
|
|
4
4
|
|
|
5
5
|
export default class InstantReactWebDatabase<
|
|
6
6
|
Schema extends InstantSchemaDef<any, any, any>,
|
|
7
|
-
|
|
7
|
+
UseDates extends boolean = false,
|
|
8
|
+
Config extends InstantConfig<Schema, UseDates> = InstantConfig<
|
|
8
9
|
Schema,
|
|
9
|
-
|
|
10
|
+
UseDates
|
|
10
11
|
>,
|
|
11
|
-
> extends InstantReactAbstractDatabase<Schema, Config> {
|
|
12
|
+
> extends InstantReactAbstractDatabase<Schema, UseDates, Config> {
|
|
12
13
|
static EventSourceImpl = EventSource;
|
|
13
14
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Type testing utils from
|
|
2
|
+
// https://github.com/type-challenges/type-challenges/blob/main/utils/index.d.ts
|
|
3
|
+
|
|
4
|
+
export type Expect<T extends true> = T;
|
|
5
|
+
export type ExpectTrue<T extends true> = T;
|
|
6
|
+
export type ExpectFalse<T extends false> = T;
|
|
7
|
+
export type IsTrue<T extends true> = T;
|
|
8
|
+
export type IsFalse<T extends false> = T;
|
|
9
|
+
|
|
10
|
+
export type Equal<X, Y> =
|
|
11
|
+
(<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2
|
|
12
|
+
? true
|
|
13
|
+
: false;
|
|
14
|
+
export type NotEqual<X, Y> = true extends Equal<X, Y> ? false : true;
|
|
15
|
+
|
|
16
|
+
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
|
17
|
+
export type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
18
|
+
export type NotAny<T> = true extends IsAny<T> ? false : true;
|
|
19
|
+
|
|
20
|
+
export type Debug<T> = { [K in keyof T]: T[K] };
|
|
21
|
+
export type MergeInsertions<T> = T extends object
|
|
22
|
+
? { [K in keyof T]: MergeInsertions<T[K]> }
|
|
23
|
+
: T;
|
|
24
|
+
|
|
25
|
+
export type Alike<X, Y> = Equal<MergeInsertions<X>, MergeInsertions<Y>>;
|
|
26
|
+
|
|
27
|
+
export type ExpectExtends<VALUE, EXPECTED> = EXPECTED extends VALUE
|
|
28
|
+
? true
|
|
29
|
+
: false;
|
|
30
|
+
export type ExpectValidArgs<
|
|
31
|
+
FUNC extends (...args: any[]) => any,
|
|
32
|
+
ARGS extends any[],
|
|
33
|
+
> = ARGS extends Parameters<FUNC> ? true : false;
|
|
34
|
+
|
|
35
|
+
export type UnionToIntersection<U> = (
|
|
36
|
+
U extends any ? (k: U) => void : never
|
|
37
|
+
) extends (k: infer I) => void
|
|
38
|
+
? I
|
|
39
|
+
: never;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Equal, Expect, IsAny, NotAny } from './typeUtils.ts';
|
|
2
|
+
import { i, init } from '../index.ts';
|
|
3
|
+
|
|
4
|
+
const schema = i.schema({
|
|
5
|
+
entities: {
|
|
6
|
+
tbl: i.entity({
|
|
7
|
+
d: i.date().indexed(),
|
|
8
|
+
dOptional: i.date().optional(),
|
|
9
|
+
}),
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function _testUseDatesTest() {
|
|
14
|
+
const db = init({
|
|
15
|
+
schema,
|
|
16
|
+
appId: '123',
|
|
17
|
+
useDateObjects: true,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
21
|
+
const item = data?.tbl[0];
|
|
22
|
+
if (item) {
|
|
23
|
+
type t = typeof item.d;
|
|
24
|
+
type _cases = [Expect<NotAny<t>>, Expect<Equal<t, Date>>];
|
|
25
|
+
|
|
26
|
+
type tOpt = typeof item.dOptional;
|
|
27
|
+
type _cases_2 = [
|
|
28
|
+
Expect<NotAny<tOpt>>,
|
|
29
|
+
Expect<Equal<tOpt, Date | undefined>>,
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function _testUseDatesFalseTest() {
|
|
35
|
+
const db = init({
|
|
36
|
+
schema,
|
|
37
|
+
appId: '123',
|
|
38
|
+
useDateObjects: false,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
42
|
+
const item = data?.tbl[0];
|
|
43
|
+
if (item) {
|
|
44
|
+
type t = typeof item.d;
|
|
45
|
+
type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];
|
|
46
|
+
|
|
47
|
+
type tOpt = typeof item.dOptional;
|
|
48
|
+
type _cases_2 = [
|
|
49
|
+
Expect<NotAny<tOpt>>,
|
|
50
|
+
Expect<Equal<tOpt, string | number | undefined>>,
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _testUseDatesUndefinedTest() {
|
|
56
|
+
const db = init({
|
|
57
|
+
schema,
|
|
58
|
+
appId: '123',
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
62
|
+
const item = data?.tbl[0];
|
|
63
|
+
if (item) {
|
|
64
|
+
type t = typeof item.d;
|
|
65
|
+
type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];
|
|
66
|
+
|
|
67
|
+
type tOpt = typeof item.dOptional;
|
|
68
|
+
type _cases_2 = [
|
|
69
|
+
Expect<NotAny<tOpt>>,
|
|
70
|
+
Expect<Equal<tOpt, string | number | undefined>>,
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _testDataNoSchema() {
|
|
76
|
+
const db = init({
|
|
77
|
+
appId: '123',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const { data } = db.useQuery({ tbl: {} });
|
|
81
|
+
const item = data?.tbl[0];
|
|
82
|
+
if (item) {
|
|
83
|
+
type t = typeof item.d;
|
|
84
|
+
type _cases = [Expect<IsAny<t>>, Expect<Equal<typeof item.id, string>>];
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/init.ts
CHANGED
|
@@ -31,14 +31,23 @@ export function init<
|
|
|
31
31
|
Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,
|
|
32
32
|
UseDates extends boolean = false,
|
|
33
33
|
>(
|
|
34
|
-
config
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
35
|
+
// as a non-nullable in the InstantConfig type.
|
|
36
|
+
config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {
|
|
37
|
+
useDateObjects?: UseDates;
|
|
38
|
+
},
|
|
39
|
+
): InstantReactWebDatabase<Schema, UseDates, InstantConfig<Schema, UseDates>> {
|
|
40
|
+
const configStrict = {
|
|
41
|
+
...config,
|
|
42
|
+
useDateObjects: (config.useDateObjects ?? false) as UseDates,
|
|
43
|
+
};
|
|
44
|
+
return new InstantReactWebDatabase<
|
|
45
|
+
Schema,
|
|
46
|
+
UseDates,
|
|
47
|
+
InstantConfig<Schema, UseDates>
|
|
48
|
+
>(configStrict, {
|
|
49
|
+
'@instantdb/react': version,
|
|
50
|
+
});
|
|
42
51
|
}
|
|
43
52
|
|
|
44
53
|
/**
|
package/tsconfig.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.base.json",
|
|
3
3
|
"include": ["src"],
|
|
4
|
-
"exclude": ["node_modules", "dist"],
|
|
4
|
+
"exclude": ["node_modules", "dist", "src/__types__"],
|
|
5
5
|
"compilerOptions": {
|
|
6
6
|
"outDir": "dist/tsc",
|
|
7
7
|
"rewriteRelativeImportExtensions": true,
|
|
8
8
|
"rootDir": "src",
|
|
9
|
-
"jsx": "react-jsx"
|
|
9
|
+
"jsx": "react-jsx",
|
|
10
|
+
"strictNullChecks": true
|
|
10
11
|
}
|
|
11
12
|
}
|