@sidekickdb/react 0.0.0 → 2.0.1

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.
Files changed (134) hide show
  1. package/.tshy/build.json +8 -0
  2. package/.tshy/commonjs.json +16 -0
  3. package/.tshy/esm.json +15 -0
  4. package/LICENSE.md +202 -0
  5. package/NOTICE +27 -0
  6. package/README.md +43 -2
  7. package/__example__/standalone.esm.html +32 -0
  8. package/__example__/standalone.umd.html +27 -0
  9. package/dist/commonjs/Cursors.d.ts +19 -0
  10. package/dist/commonjs/Cursors.d.ts.map +1 -0
  11. package/dist/commonjs/Cursors.js +107 -0
  12. package/dist/commonjs/Cursors.js.map +1 -0
  13. package/dist/commonjs/InstantReactWebDatabase.d.ts +7 -0
  14. package/dist/commonjs/InstantReactWebDatabase.d.ts.map +1 -0
  15. package/dist/commonjs/InstantReactWebDatabase.js +9 -0
  16. package/dist/commonjs/InstantReactWebDatabase.js.map +1 -0
  17. package/dist/commonjs/__types__/typeUtils.d.ts +20 -0
  18. package/dist/commonjs/__types__/typeUtils.d.ts.map +1 -0
  19. package/dist/commonjs/__types__/typeUtils.js +5 -0
  20. package/dist/commonjs/__types__/typeUtils.js.map +1 -0
  21. package/dist/commonjs/__types__/typesTests.d.ts +2 -0
  22. package/dist/commonjs/__types__/typesTests.d.ts.map +1 -0
  23. package/dist/commonjs/__types__/typesTests.js +57 -0
  24. package/dist/commonjs/__types__/typesTests.js.map +1 -0
  25. package/dist/commonjs/index.d.ts +7 -0
  26. package/dist/commonjs/index.d.ts.map +1 -0
  27. package/dist/commonjs/index.js +30 -0
  28. package/dist/commonjs/index.js.map +1 -0
  29. package/dist/commonjs/init.d.ts +41 -0
  30. package/dist/commonjs/init.d.ts.map +1 -0
  31. package/dist/commonjs/init.js +57 -0
  32. package/dist/commonjs/init.js.map +1 -0
  33. package/dist/commonjs/next-ssr/HydrationStreamProvider.d.ts +66 -0
  34. package/dist/commonjs/next-ssr/HydrationStreamProvider.d.ts.map +1 -0
  35. package/dist/commonjs/next-ssr/HydrationStreamProvider.js +134 -0
  36. package/dist/commonjs/next-ssr/HydrationStreamProvider.js.map +1 -0
  37. package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts +12 -0
  38. package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts.map +1 -0
  39. package/dist/commonjs/next-ssr/InstantNextDatabase.js +39 -0
  40. package/dist/commonjs/next-ssr/InstantNextDatabase.js.map +1 -0
  41. package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts +25 -0
  42. package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts.map +1 -0
  43. package/dist/commonjs/next-ssr/InstantSuspenseProvider.js +168 -0
  44. package/dist/commonjs/next-ssr/InstantSuspenseProvider.js.map +1 -0
  45. package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts +10 -0
  46. package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts.map +1 -0
  47. package/dist/commonjs/next-ssr/getUserFromInstantCookie.js +22 -0
  48. package/dist/commonjs/next-ssr/getUserFromInstantCookie.js.map +1 -0
  49. package/dist/commonjs/next-ssr/htmlescape.d.ts +3 -0
  50. package/dist/commonjs/next-ssr/htmlescape.d.ts.map +1 -0
  51. package/dist/commonjs/next-ssr/htmlescape.js +25 -0
  52. package/dist/commonjs/next-ssr/htmlescape.js.map +1 -0
  53. package/dist/commonjs/next-ssr/index.d.ts +30 -0
  54. package/dist/commonjs/next-ssr/index.d.ts.map +1 -0
  55. package/dist/commonjs/next-ssr/index.js +47 -0
  56. package/dist/commonjs/next-ssr/index.js.map +1 -0
  57. package/dist/commonjs/package.json +3 -0
  58. package/dist/commonjs/version.d.ts +3 -0
  59. package/dist/commonjs/version.d.ts.map +1 -0
  60. package/dist/commonjs/version.js +5 -0
  61. package/dist/commonjs/version.js.map +1 -0
  62. package/dist/esm/Cursors.d.ts +19 -0
  63. package/dist/esm/Cursors.d.ts.map +1 -0
  64. package/dist/esm/Cursors.js +104 -0
  65. package/dist/esm/Cursors.js.map +1 -0
  66. package/dist/esm/InstantReactWebDatabase.d.ts +7 -0
  67. package/dist/esm/InstantReactWebDatabase.d.ts.map +1 -0
  68. package/dist/esm/InstantReactWebDatabase.js +6 -0
  69. package/dist/esm/InstantReactWebDatabase.js.map +1 -0
  70. package/dist/esm/__types__/typeUtils.d.ts +20 -0
  71. package/dist/esm/__types__/typeUtils.d.ts.map +1 -0
  72. package/dist/esm/__types__/typeUtils.js +4 -0
  73. package/dist/esm/__types__/typeUtils.js.map +1 -0
  74. package/dist/esm/__types__/typesTests.d.ts +2 -0
  75. package/dist/esm/__types__/typesTests.d.ts.map +1 -0
  76. package/dist/esm/__types__/typesTests.js +55 -0
  77. package/dist/esm/__types__/typesTests.js.map +1 -0
  78. package/dist/esm/index.d.ts +7 -0
  79. package/dist/esm/index.d.ts.map +1 -0
  80. package/dist/esm/index.js +23 -0
  81. package/dist/esm/index.js.map +1 -0
  82. package/dist/esm/init.d.ts +41 -0
  83. package/dist/esm/init.d.ts.map +1 -0
  84. package/dist/esm/init.js +50 -0
  85. package/dist/esm/init.js.map +1 -0
  86. package/dist/esm/next-ssr/HydrationStreamProvider.d.ts +66 -0
  87. package/dist/esm/next-ssr/HydrationStreamProvider.d.ts.map +1 -0
  88. package/dist/esm/next-ssr/HydrationStreamProvider.js +97 -0
  89. package/dist/esm/next-ssr/HydrationStreamProvider.js.map +1 -0
  90. package/dist/esm/next-ssr/InstantNextDatabase.d.ts +12 -0
  91. package/dist/esm/next-ssr/InstantNextDatabase.d.ts.map +1 -0
  92. package/dist/esm/next-ssr/InstantNextDatabase.js +32 -0
  93. package/dist/esm/next-ssr/InstantNextDatabase.js.map +1 -0
  94. package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +25 -0
  95. package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts.map +1 -0
  96. package/dist/esm/next-ssr/InstantSuspenseProvider.js +163 -0
  97. package/dist/esm/next-ssr/InstantSuspenseProvider.js.map +1 -0
  98. package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +10 -0
  99. package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts.map +1 -0
  100. package/dist/esm/next-ssr/getUserFromInstantCookie.js +17 -0
  101. package/dist/esm/next-ssr/getUserFromInstantCookie.js.map +1 -0
  102. package/dist/esm/next-ssr/htmlescape.d.ts +3 -0
  103. package/dist/esm/next-ssr/htmlescape.d.ts.map +1 -0
  104. package/dist/esm/next-ssr/htmlescape.js +21 -0
  105. package/dist/esm/next-ssr/htmlescape.js.map +1 -0
  106. package/dist/esm/next-ssr/index.d.ts +30 -0
  107. package/dist/esm/next-ssr/index.d.ts.map +1 -0
  108. package/dist/esm/next-ssr/index.js +35 -0
  109. package/dist/esm/next-ssr/index.js.map +1 -0
  110. package/dist/esm/package.json +3 -0
  111. package/dist/esm/version.d.ts +3 -0
  112. package/dist/esm/version.d.ts.map +1 -0
  113. package/dist/esm/version.js +3 -0
  114. package/dist/esm/version.js.map +1 -0
  115. package/dist/standalone/index.js +9664 -0
  116. package/dist/standalone/index.umd.cjs +40 -0
  117. package/package.json +81 -3
  118. package/src/Cursors.tsx +208 -0
  119. package/src/InstantReactWebDatabase.ts +14 -0
  120. package/src/__types__/typeUtils.ts +39 -0
  121. package/src/__types__/typesTests.ts +90 -0
  122. package/src/index.ts +227 -0
  123. package/src/init.ts +67 -0
  124. package/src/next-ssr/HydrationStreamProvider.tsx +200 -0
  125. package/src/next-ssr/InstantNextDatabase.tsx +56 -0
  126. package/src/next-ssr/InstantSuspenseProvider.tsx +290 -0
  127. package/src/next-ssr/getUserFromInstantCookie.ts +23 -0
  128. package/src/next-ssr/htmlescape.ts +24 -0
  129. package/src/next-ssr/index.tsx +54 -0
  130. package/src/version.ts +3 -0
  131. package/tsconfig.dev.json +14 -0
  132. package/tsconfig.json +13 -0
  133. package/tsconfig.test.json +5 -0
  134. package/vite.config.ts +35 -0
package/package.json CHANGED
@@ -1,11 +1,89 @@
1
1
  {
2
2
  "name": "@sidekickdb/react",
3
- "version": "0.0.0",
4
- "description": "Placeholder. The first real SidekickDB release replaces it.",
3
+ "version": "2.0.1",
4
+ "description": "SidekickDB for React",
5
5
  "license": "Apache-2.0",
6
+ "homepage": "https://sidekickdb.co/docs",
6
7
  "repository": {
7
8
  "type": "git",
8
9
  "url": "git+https://github.com/SidekickDB/sidekick.git",
9
10
  "directory": "client/packages/react"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/SidekickDB/sidekick/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/commonjs/index.js",
17
+ "types": "./dist/commonjs/index.d.ts",
18
+ "module": "./dist/esm/index.js",
19
+ "unpkg": "standalone/index.umd.js",
20
+ "exports": {
21
+ "./package.json": "./package.json",
22
+ ".": {
23
+ "import": {
24
+ "types": "./dist/esm/index.d.ts",
25
+ "default": "./dist/esm/index.js"
26
+ },
27
+ "require": {
28
+ "types": "./dist/commonjs/index.d.ts",
29
+ "default": "./dist/commonjs/index.js"
30
+ }
31
+ },
32
+ "./nextjs": {
33
+ "import": {
34
+ "types": "./dist/esm/next-ssr/index.d.ts",
35
+ "default": "./dist/esm/next-ssr/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/commonjs/next-ssr/index.d.ts",
39
+ "default": "./dist/commonjs/next-ssr/index.js"
40
+ }
41
+ }
42
+ },
43
+ "tshy": {
44
+ "selfLink": false,
45
+ "main": true,
46
+ "module": true,
47
+ "project": "./tsconfig.json",
48
+ "exports": {
49
+ "./package.json": "./package.json",
50
+ ".": "./src/index.ts",
51
+ "./nextjs": "./src/next-ssr/index.tsx"
52
+ }
53
+ },
54
+ "devDependencies": {
55
+ "@arethetypeswrong/cli": "^0.18.5",
56
+ "@babel/core": "^7.17.9",
57
+ "@babel/preset-env": "^7.16.11",
58
+ "@types/node": "^22.6.1",
59
+ "@types/react": ">=16",
60
+ "@vitejs/plugin-react": "^4.3.1",
61
+ "npm-run-all": "^4.1.5",
62
+ "tshy": "^3.0.2",
63
+ "typescript": "^5.9.3",
64
+ "next": "^15.5.6",
65
+ "vite": "^5.2.0",
66
+ "vitest": "^0.21.0"
67
+ },
68
+ "peerDependencies": {
69
+ "react": ">=16"
70
+ },
71
+ "dependencies": {
72
+ "eventsource": "^4.0.0",
73
+ "@sidekickdb/react-common": "2.0.1",
74
+ "@sidekickdb/core": "2.0.1",
75
+ "@sidekickdb/version": "2.0.1"
76
+ },
77
+ "scripts": {
78
+ "test": "vitest",
79
+ "test:types": "tsc -p tsconfig.test.json --noEmit",
80
+ "test:ci": "pnpm run test:types",
81
+ "check-exports": "attw --profile node16 --pack .",
82
+ "dev": "tsc --watch --preserveWatchOutput -p tsconfig.dev.json",
83
+ "clean": "rm -rf dist",
84
+ "build:tshy": "tshy",
85
+ "build:standalone": "vite build",
86
+ "build": "rm -rf dist; npm run build:tshy && npm run build:standalone && npm run check-exports",
87
+ "publish-package": "pnpm pack && npm publish *.tgz --access public"
10
88
  }
11
- }
89
+ }
@@ -0,0 +1,208 @@
1
+ import {
2
+ createElement,
3
+ type ReactNode,
4
+ type MouseEvent,
5
+ type TouchEvent,
6
+ type CSSProperties,
7
+ } from 'react';
8
+ import { type InstantReactRoom } from '@sidekickdb/react-common';
9
+ import type { RoomSchemaShape } from '@sidekickdb/core';
10
+
11
+ export function Cursors<
12
+ RoomSchema extends RoomSchemaShape,
13
+ RoomType extends string & keyof RoomSchema,
14
+ >({
15
+ as = 'div',
16
+ spaceId: _spaceId,
17
+ room,
18
+ className,
19
+ style,
20
+ userCursorColor,
21
+ children,
22
+ renderCursor,
23
+ propagate,
24
+ zIndex,
25
+ }: {
26
+ spaceId?: string;
27
+ room: InstantReactRoom<any, RoomSchema, RoomType>;
28
+ style?: React.CSSProperties;
29
+ userCursorColor?: string;
30
+ as?: any;
31
+ className?: string;
32
+ children?: ReactNode;
33
+ renderCursor?: (props: {
34
+ color: string;
35
+ presence: RoomSchema[RoomType]['presence'];
36
+ }) => ReactNode;
37
+ propagate?: boolean;
38
+ zIndex?: number;
39
+ }) {
40
+ const spaceId =
41
+ _spaceId || `cursors-space-default--${String(room.type)}-${room.id}`;
42
+
43
+ const cursorsPresence = room.usePresence({
44
+ keys: [spaceId] as (keyof RoomSchema[RoomType]['presence'])[],
45
+ });
46
+
47
+ const fullPresence = room._core._reactor.getPresence(room.type, room.id);
48
+
49
+ function publishCursor(
50
+ rect: DOMRect,
51
+ touch: { clientX: number; clientY: number },
52
+ ) {
53
+ const x = touch.clientX;
54
+ const y = touch.clientY;
55
+ const xPercent = ((x - rect.left) / rect.width) * 100;
56
+ const yPercent = ((y - rect.top) / rect.height) * 100;
57
+ cursorsPresence.publishPresence({
58
+ [spaceId]: {
59
+ x,
60
+ y,
61
+ xPercent,
62
+ yPercent,
63
+ color: userCursorColor,
64
+ },
65
+ } as RoomSchema[RoomType]['presence']);
66
+ }
67
+
68
+ function onMouseMove(e: MouseEvent) {
69
+ if (!propagate) {
70
+ e.stopPropagation();
71
+ }
72
+
73
+ const rect = e.currentTarget.getBoundingClientRect();
74
+ publishCursor(rect, e);
75
+ }
76
+
77
+ function onMouseOut(e: MouseEvent) {
78
+ cursorsPresence.publishPresence({
79
+ [spaceId]: undefined,
80
+ } as RoomSchema[RoomType]['presence']);
81
+ }
82
+
83
+ function onTouchMove(e: TouchEvent) {
84
+ if (e.touches.length !== 1) {
85
+ return;
86
+ }
87
+
88
+ const touch = e.touches[0];
89
+
90
+ if (touch.target instanceof Element) {
91
+ if (!propagate) {
92
+ e.stopPropagation();
93
+ }
94
+ const rect = touch.target.getBoundingClientRect();
95
+ publishCursor(rect, touch);
96
+ }
97
+ }
98
+
99
+ function onTouchEnd(e: TouchEvent) {
100
+ cursorsPresence.publishPresence({
101
+ [spaceId]: undefined,
102
+ } as RoomSchema[RoomType]['presence']);
103
+ }
104
+
105
+ return createElement(
106
+ as,
107
+ {
108
+ onMouseMove,
109
+ onMouseOut,
110
+ onTouchMove,
111
+ onTouchEnd,
112
+ className,
113
+ style: {
114
+ position: 'relative',
115
+ ...style,
116
+ },
117
+ },
118
+ [
119
+ children,
120
+ <div
121
+ key={spaceId}
122
+ style={{
123
+ ...absStyles,
124
+ ...inertStyles,
125
+ zIndex: zIndex !== undefined ? zIndex : defaultZ,
126
+ }}
127
+ >
128
+ {Object.entries(cursorsPresence.peers).map(([id, presence]) => {
129
+ const cursor = presence[spaceId];
130
+ if (!cursor) return null;
131
+
132
+ return (
133
+ <div
134
+ key={id}
135
+ style={{
136
+ ...absStyles,
137
+ transform: `translate(${cursor.xPercent}%, ${cursor.yPercent}%)`,
138
+ transformOrigin: '0 0',
139
+ transition: 'transform 100ms',
140
+ }}
141
+ >
142
+ {renderCursor ? (
143
+ renderCursor({
144
+ color: cursor.color,
145
+ presence: fullPresence?.peers[id],
146
+ })
147
+ ) : (
148
+ <Cursor {...cursor} />
149
+ )}
150
+ </div>
151
+ );
152
+ })}
153
+ </div>,
154
+ ],
155
+ );
156
+ }
157
+
158
+ function Cursor({ color }: { color: string }) {
159
+ const size = 35;
160
+ const fill = color || 'black';
161
+
162
+ return (
163
+ <svg
164
+ style={{ height: size, width: size }}
165
+ viewBox={`0 0 ${size} ${size}`}
166
+ fill="none"
167
+ xmlns="http://www.w3.org/2000/svg"
168
+ >
169
+ <g
170
+ fill="rgba(0,0,0,.2)"
171
+ transform="matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)"
172
+ >
173
+ <path d="m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z" />
174
+ <path d="m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z" />
175
+ </g>
176
+ <g
177
+ fill="white"
178
+ transform="matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)"
179
+ >
180
+ <path d="m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z" />
181
+ <path d="m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z" />
182
+ </g>
183
+ <g
184
+ fill={fill}
185
+ transform="matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)"
186
+ >
187
+ <path d="m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z" />
188
+ <path d="m13 10.814v11.188l2.969-2.866.428-.139h4.768z" />
189
+ </g>
190
+ </svg>
191
+ );
192
+ }
193
+
194
+ const absStyles: CSSProperties = {
195
+ position: 'absolute',
196
+ top: 0,
197
+ left: 0,
198
+ bottom: 0,
199
+ right: 0,
200
+ };
201
+
202
+ const inertStyles: CSSProperties = {
203
+ overflow: 'hidden',
204
+ pointerEvents: 'none',
205
+ userSelect: 'none',
206
+ };
207
+
208
+ const defaultZ = 99999;
@@ -0,0 +1,14 @@
1
+ import type { InstantConfig, InstantSchemaDef } from '@sidekickdb/core';
2
+ import { InstantReactAbstractDatabase } from '@sidekickdb/react-common';
3
+ import { EventSource } from 'eventsource';
4
+
5
+ export default class InstantReactWebDatabase<
6
+ Schema extends InstantSchemaDef<any, any, any>,
7
+ UseDates extends boolean = false,
8
+ Config extends InstantConfig<Schema, UseDates> = InstantConfig<
9
+ Schema,
10
+ UseDates
11
+ >,
12
+ > extends InstantReactAbstractDatabase<Schema, UseDates, Config> {
13
+ static EventSourceImpl = EventSource;
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,90 @@
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
+ apiURI: 'https://sidekick.example.com',
18
+ useDateObjects: true,
19
+ });
20
+
21
+ const { data } = db.useQuery({ tbl: {} });
22
+ const item = data?.tbl[0];
23
+ if (item) {
24
+ type t = typeof item.d;
25
+ type _cases = [Expect<NotAny<t>>, Expect<Equal<t, Date>>];
26
+
27
+ type tOpt = typeof item.dOptional;
28
+ type _cases_2 = [
29
+ Expect<NotAny<tOpt>>,
30
+ Expect<Equal<tOpt, Date | undefined>>,
31
+ ];
32
+ }
33
+ }
34
+
35
+ function _testUseDatesFalseTest() {
36
+ const db = init({
37
+ schema,
38
+ appId: '123',
39
+ apiURI: 'https://sidekick.example.com',
40
+ useDateObjects: false,
41
+ });
42
+
43
+ const { data } = db.useQuery({ tbl: {} });
44
+ const item = data?.tbl[0];
45
+ if (item) {
46
+ type t = typeof item.d;
47
+ type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];
48
+
49
+ type tOpt = typeof item.dOptional;
50
+ type _cases_2 = [
51
+ Expect<NotAny<tOpt>>,
52
+ Expect<Equal<tOpt, string | number | undefined>>,
53
+ ];
54
+ }
55
+ }
56
+
57
+ function _testUseDatesUndefinedTest() {
58
+ const db = init({
59
+ schema,
60
+ appId: '123',
61
+ apiURI: 'https://sidekick.example.com',
62
+ });
63
+
64
+ const { data } = db.useQuery({ tbl: {} });
65
+ const item = data?.tbl[0];
66
+ if (item) {
67
+ type t = typeof item.d;
68
+ type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];
69
+
70
+ type tOpt = typeof item.dOptional;
71
+ type _cases_2 = [
72
+ Expect<NotAny<tOpt>>,
73
+ Expect<Equal<tOpt, string | number | undefined>>,
74
+ ];
75
+ }
76
+ }
77
+
78
+ function _testDataNoSchema() {
79
+ const db = init({
80
+ appId: '123',
81
+ apiURI: 'https://sidekick.example.com',
82
+ });
83
+
84
+ const { data } = db.useQuery({ tbl: {} });
85
+ const item = data?.tbl[0];
86
+ if (item) {
87
+ type t = typeof item.d;
88
+ type _cases = [Expect<IsAny<t>>, Expect<Equal<typeof item.id, string>>];
89
+ }
90
+ }
package/src/index.ts ADDED
@@ -0,0 +1,227 @@
1
+ import {
2
+ id,
3
+ tx,
4
+ lookup,
5
+ i,
6
+
7
+ // error
8
+ InstantAPIError,
9
+
10
+ // sync table enums
11
+ SyncTableCallbackEventType,
12
+ setInstantWarningsEnabled,
13
+
14
+ // types
15
+ type QueryResponse,
16
+ type InstantQuery,
17
+ type InstantQueryResult,
18
+ type InstantSchema,
19
+ type InstantObject,
20
+ type InstantEntity,
21
+ type InstantSchemaDatabase,
22
+ type InstantUnknownSchemaDef,
23
+ type IInstantDatabase,
24
+ type User,
25
+ type AuthState,
26
+ type Query,
27
+ type Config,
28
+ type InstaQLParams,
29
+ type ConnectionStatus,
30
+ type AppStatusState,
31
+ type ValidQuery,
32
+
33
+ // presence types
34
+ type PresencePeer,
35
+
36
+ // schema types
37
+ type AttrsDefs,
38
+ type CardinalityKind,
39
+ type DataAttrDef,
40
+ type EntitiesDef,
41
+ type EntitiesWithLinks,
42
+ type EntityDef,
43
+ type InstantGraph,
44
+ type InstantConfig,
45
+ type LinkAttrDef,
46
+ type LinkDef,
47
+ type LinksDef,
48
+ type ResolveAttrs,
49
+ type ValueTypes,
50
+ type InstaQLEntity,
51
+ type InstaQLFields,
52
+ type InstaQLResult,
53
+ type InstaQLEntitySubquery,
54
+ type RoomsOf,
55
+ type RoomsDef,
56
+ type PresenceOf,
57
+ type TopicsOf,
58
+ type TopicOf,
59
+ type RoomHandle,
60
+ type TransactionChunk,
61
+ type InstantUnknownSchema,
62
+ type InstantSchemaDef,
63
+ type BackwardsCompatibleSchema,
64
+ type InstantRules,
65
+ type UpdateParams,
66
+ type LinkParams,
67
+ type CreateParams,
68
+ type CheckMagicCodeParams,
69
+ type CheckMagicCodeResponse,
70
+ type ExchangeCodeForTokenParams,
71
+ type SendMagicCodeParams,
72
+ type SendMagicCodeResponse,
73
+ type SignInWithIdTokenParams,
74
+ type VerifyMagicCodeParams,
75
+ type VerifyResponse,
76
+
77
+ // storage types
78
+ type FileOpts,
79
+ type UploadFileResponse,
80
+ type DeleteFileResponse,
81
+
82
+ // stream types
83
+ type CreateReadStreamOpts,
84
+ type CreateWriteStreamOpts,
85
+
86
+ // sync table types
87
+ type SyncTableCallback,
88
+ type SyncTableCallbackEvent,
89
+ type SyncTableInitialSyncBatch,
90
+ type SyncTableInitialSyncComplete,
91
+ type SyncTableSyncTransaction,
92
+ type SyncTableLoadFromStorage,
93
+ type SyncTableSetupError,
94
+ StoreInterface,
95
+ createInstantRouteHandler,
96
+ type InstantRouteHandlerPayloadByType,
97
+ type InstantRouteHandlerType,
98
+ type InstantRouteHandlerBody,
99
+ type StoreInterfaceStoreName,
100
+ InstantWritableStream,
101
+ InstantReadableStream,
102
+ type Logger,
103
+ } from '@sidekickdb/core';
104
+
105
+ import { InstantReactAbstractDatabase } from '@sidekickdb/react-common';
106
+ import InstantReactWebDatabase from './InstantReactWebDatabase.ts';
107
+ import { init, init_experimental } from './init.ts';
108
+ import { Cursors } from './Cursors.tsx';
109
+
110
+ export {
111
+ id,
112
+ tx,
113
+ lookup,
114
+ init,
115
+ init_experimental,
116
+ InstantReactWebDatabase,
117
+ Cursors,
118
+ i,
119
+
120
+ // error
121
+ InstantAPIError,
122
+
123
+ // internal
124
+ InstantReactAbstractDatabase,
125
+
126
+ // sync table enums
127
+ SyncTableCallbackEventType,
128
+
129
+ // warnings
130
+ setInstantWarningsEnabled,
131
+
132
+ // types
133
+ type Config,
134
+ type InstantConfig,
135
+ type InstantUnknownSchemaDef,
136
+ type Query,
137
+ type QueryResponse,
138
+ type InstantObject,
139
+ type User,
140
+ type AuthState,
141
+ type ConnectionStatus,
142
+ type AppStatusState,
143
+ type InstantQuery,
144
+ type InstantQueryResult,
145
+ type InstantSchema,
146
+ type InstantEntity,
147
+ type InstantSchemaDatabase,
148
+ type IInstantDatabase,
149
+ type InstaQLParams,
150
+ type ValidQuery,
151
+ type InstaQLFields,
152
+
153
+ // presence types
154
+ type PresencePeer,
155
+
156
+ // schema types
157
+ type AttrsDefs,
158
+ type CardinalityKind,
159
+ type DataAttrDef,
160
+ type EntitiesDef,
161
+ type EntitiesWithLinks,
162
+ type EntityDef,
163
+ type InstantGraph,
164
+ type LinkAttrDef,
165
+ type LinkDef,
166
+ type LinksDef,
167
+ type ResolveAttrs,
168
+ type ValueTypes,
169
+ type InstaQLEntity,
170
+ type InstaQLResult,
171
+ type InstaQLEntitySubquery,
172
+ type RoomsOf,
173
+ type RoomsDef,
174
+ type TransactionChunk,
175
+ type PresenceOf,
176
+ type TopicsOf,
177
+ type TopicOf,
178
+ type RoomHandle,
179
+ type InstantUnknownSchema,
180
+ type InstantSchemaDef,
181
+ type BackwardsCompatibleSchema,
182
+ type InstantRules,
183
+ type UpdateParams,
184
+ type LinkParams,
185
+ type CreateParams,
186
+ type CheckMagicCodeParams,
187
+ type CheckMagicCodeResponse,
188
+ type ExchangeCodeForTokenParams,
189
+ type SendMagicCodeParams,
190
+ type SendMagicCodeResponse,
191
+ type SignInWithIdTokenParams,
192
+ type VerifyMagicCodeParams,
193
+ type VerifyResponse,
194
+
195
+ // storage types
196
+ type FileOpts,
197
+ type UploadFileResponse,
198
+ type DeleteFileResponse,
199
+
200
+ // stream types
201
+ type CreateReadStreamOpts,
202
+ type CreateWriteStreamOpts,
203
+ type InstantWritableStream,
204
+ type InstantReadableStream,
205
+
206
+ // custom store
207
+ StoreInterface,
208
+ type StoreInterfaceStoreName,
209
+
210
+ // sync table types
211
+ type SyncTableCallback,
212
+ type SyncTableCallbackEvent,
213
+ type SyncTableInitialSyncBatch,
214
+ type SyncTableInitialSyncComplete,
215
+ type SyncTableSyncTransaction,
216
+ type SyncTableLoadFromStorage,
217
+ type SyncTableSetupError,
218
+
219
+ // Server helper
220
+ createInstantRouteHandler,
221
+ type InstantRouteHandlerPayloadByType,
222
+ type InstantRouteHandlerType,
223
+ type InstantRouteHandlerBody,
224
+
225
+ // logger
226
+ type Logger,
227
+ };