@sidekickdb/react 2.0.0 → 3.0.0
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/README.md +3 -3
- package/__example__/standalone.esm.html +3 -3
- package/__example__/standalone.umd.html +2 -2
- package/__tests__/getUserFromSidekickCookie.test.ts +24 -0
- package/dist/commonjs/Cursors.d.ts +2 -2
- package/dist/commonjs/Cursors.d.ts.map +1 -1
- package/dist/commonjs/Cursors.js.map +1 -1
- package/dist/commonjs/SidekickReactWebDatabase.d.ts +7 -0
- package/dist/commonjs/SidekickReactWebDatabase.d.ts.map +1 -0
- package/dist/commonjs/{InstantReactWebDatabase.js → SidekickReactWebDatabase.js} +3 -3
- package/dist/commonjs/SidekickReactWebDatabase.js.map +1 -0
- package/dist/commonjs/index.d.ts +4 -4
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +8 -8
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/init.d.ts +5 -5
- package/dist/commonjs/init.d.ts.map +1 -1
- package/dist/commonjs/init.js +5 -5
- package/dist/commonjs/init.js.map +1 -1
- package/dist/commonjs/next-ssr/SidekickNextDatabase.d.ts +12 -0
- package/dist/commonjs/next-ssr/SidekickNextDatabase.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/{InstantNextDatabase.js → SidekickNextDatabase.js} +8 -8
- package/dist/commonjs/next-ssr/SidekickNextDatabase.js.map +1 -0
- package/dist/commonjs/next-ssr/SidekickSuspenseProvider.d.ts +25 -0
- package/dist/commonjs/next-ssr/SidekickSuspenseProvider.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/{InstantSuspenseProvider.js → SidekickSuspenseProvider.js} +6 -6
- package/dist/commonjs/next-ssr/SidekickSuspenseProvider.js.map +1 -0
- package/dist/commonjs/next-ssr/getUserFromSidekickCookie.d.ts +10 -0
- package/dist/commonjs/next-ssr/getUserFromSidekickCookie.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/getUserFromSidekickCookie.js +22 -0
- package/dist/commonjs/next-ssr/getUserFromSidekickCookie.js.map +1 -0
- package/dist/commonjs/next-ssr/index.d.ts +9 -9
- package/dist/commonjs/next-ssr/index.d.ts.map +1 -1
- package/dist/commonjs/next-ssr/index.js +14 -14
- package/dist/commonjs/next-ssr/index.js.map +1 -1
- package/dist/esm/Cursors.d.ts +2 -2
- package/dist/esm/Cursors.d.ts.map +1 -1
- package/dist/esm/Cursors.js.map +1 -1
- package/dist/esm/SidekickReactWebDatabase.d.ts +7 -0
- package/dist/esm/SidekickReactWebDatabase.d.ts.map +1 -0
- package/dist/esm/SidekickReactWebDatabase.js +6 -0
- package/dist/esm/SidekickReactWebDatabase.js.map +1 -0
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -9
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/init.d.ts +5 -5
- package/dist/esm/init.d.ts.map +1 -1
- package/dist/esm/init.js +5 -5
- package/dist/esm/init.js.map +1 -1
- package/dist/esm/next-ssr/SidekickNextDatabase.d.ts +12 -0
- package/dist/esm/next-ssr/SidekickNextDatabase.d.ts.map +1 -0
- package/dist/esm/next-ssr/{InstantNextDatabase.js → SidekickNextDatabase.js} +4 -4
- package/dist/esm/next-ssr/SidekickNextDatabase.js.map +1 -0
- package/dist/esm/next-ssr/SidekickSuspenseProvider.d.ts +25 -0
- package/dist/esm/next-ssr/SidekickSuspenseProvider.d.ts.map +1 -0
- package/dist/esm/next-ssr/{InstantSuspenseProvider.js → SidekickSuspenseProvider.js} +4 -4
- package/dist/esm/next-ssr/SidekickSuspenseProvider.js.map +1 -0
- package/dist/esm/next-ssr/getUserFromSidekickCookie.d.ts +10 -0
- package/dist/esm/next-ssr/getUserFromSidekickCookie.d.ts.map +1 -0
- package/dist/esm/next-ssr/getUserFromSidekickCookie.js +17 -0
- package/dist/esm/next-ssr/getUserFromSidekickCookie.js.map +1 -0
- package/dist/esm/next-ssr/index.d.ts +9 -9
- package/dist/esm/next-ssr/index.d.ts.map +1 -1
- package/dist/esm/next-ssr/index.js +9 -9
- package/dist/esm/next-ssr/index.js.map +1 -1
- package/dist/standalone/index.js +1526 -1626
- package/dist/standalone/index.umd.cjs +20 -17
- package/package.json +6 -6
- package/src/Cursors.tsx +2 -2
- package/src/SidekickReactWebDatabase.ts +14 -0
- package/src/index.ts +56 -56
- package/src/init.ts +16 -12
- package/src/next-ssr/{InstantNextDatabase.tsx → SidekickNextDatabase.tsx} +8 -8
- package/src/next-ssr/{InstantSuspenseProvider.tsx → SidekickSuspenseProvider.tsx} +17 -17
- package/src/next-ssr/{getUserFromInstantCookie.ts → getUserFromSidekickCookie.ts} +5 -5
- package/src/next-ssr/index.tsx +17 -17
- package/vite.config.ts +1 -1
- package/dist/commonjs/InstantReactWebDatabase.d.ts +0 -7
- package/dist/commonjs/InstantReactWebDatabase.d.ts.map +0 -1
- package/dist/commonjs/InstantReactWebDatabase.js.map +0 -1
- package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts +0 -12
- package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts.map +0 -1
- package/dist/commonjs/next-ssr/InstantNextDatabase.js.map +0 -1
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts +0 -25
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts.map +0 -1
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.js.map +0 -1
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts +0 -10
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts.map +0 -1
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.js +0 -22
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.js.map +0 -1
- package/dist/esm/InstantReactWebDatabase.d.ts +0 -7
- package/dist/esm/InstantReactWebDatabase.d.ts.map +0 -1
- package/dist/esm/InstantReactWebDatabase.js +0 -6
- package/dist/esm/InstantReactWebDatabase.js.map +0 -1
- package/dist/esm/next-ssr/InstantNextDatabase.d.ts +0 -12
- package/dist/esm/next-ssr/InstantNextDatabase.d.ts.map +0 -1
- package/dist/esm/next-ssr/InstantNextDatabase.js.map +0 -1
- package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +0 -25
- package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts.map +0 -1
- package/dist/esm/next-ssr/InstantSuspenseProvider.js.map +0 -1
- package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +0 -10
- package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts.map +0 -1
- package/dist/esm/next-ssr/getUserFromInstantCookie.js +0 -17
- package/dist/esm/next-ssr/getUserFromInstantCookie.js.map +0 -1
- package/src/InstantReactWebDatabase.ts +0 -14
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Welcome to SidekickDB's React SDK.
|
|
|
9
9
|
```javascript
|
|
10
10
|
// ༼ つ ◕_◕ ༽つ Real-time Chat
|
|
11
11
|
// ----------------------------------
|
|
12
|
-
// * Updates
|
|
12
|
+
// * Updates in real time
|
|
13
13
|
// * Multiplayer
|
|
14
14
|
// * Works offline
|
|
15
15
|
|
|
@@ -17,7 +17,7 @@ import { init, id } from '@sidekickdb/react';
|
|
|
17
17
|
|
|
18
18
|
const db = init({
|
|
19
19
|
appId: process.env.NEXT_PUBLIC_APP_ID,
|
|
20
|
-
apiURI: process.env.
|
|
20
|
+
apiURI: process.env.NEXT_PUBLIC_SIDEKICK_API_URI,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
function Chat() {
|
|
@@ -38,7 +38,7 @@ function Chat() {
|
|
|
38
38
|
|
|
39
39
|
# Get Started
|
|
40
40
|
|
|
41
|
-
Follow the [getting started](https://
|
|
41
|
+
Follow the [getting started](https://sidekickdb.co/docs) tutorial to set up a live React app in under 5 minutes!
|
|
42
42
|
|
|
43
43
|
# Questions?
|
|
44
44
|
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>
|
|
6
|
+
<title>SidekickDB React ESM standalone example/test</title>
|
|
7
7
|
</head>
|
|
8
8
|
<body>
|
|
9
9
|
<script type="importmap">
|
|
10
10
|
{
|
|
11
11
|
"imports": {
|
|
12
|
-
"@
|
|
12
|
+
"@sidekickdb/react": "/dist/standalone/index.mjs",
|
|
13
13
|
"react": "https://esm.sh/react",
|
|
14
14
|
"react-dom": "https://esm.sh/react-dom"
|
|
15
15
|
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<!-- make sure to run `build:standalone` first! -->
|
|
19
19
|
<!-- easiest way to test this is with `python3 -m http.server` in the root directory of this project -->
|
|
20
20
|
<script type="module">
|
|
21
|
-
import { init } from "@
|
|
21
|
+
import { init } from "@sidekickdb/react";
|
|
22
22
|
|
|
23
23
|
const query = {};
|
|
24
24
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>
|
|
6
|
+
<title>SidekickDB React UMD standalone example/test</title>
|
|
7
7
|
</head>
|
|
8
8
|
<body>
|
|
9
9
|
<script
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
<script>
|
|
20
20
|
const query = {};
|
|
21
21
|
|
|
22
|
-
const db =
|
|
22
|
+
const db = sidekickReact.init({
|
|
23
23
|
appId: new URL(location.href).searchParams.get("app_id"),
|
|
24
24
|
});
|
|
25
25
|
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// SidekickDB: the auth cookie read for server rendering.
|
|
2
|
+
import { beforeEach, expect, test, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
const jar = new Map<string, string>();
|
|
5
|
+
|
|
6
|
+
vi.mock('next/headers.js', () => ({
|
|
7
|
+
cookies: async () => ({
|
|
8
|
+
get: (name: string) =>
|
|
9
|
+
jar.has(name) ? { name, value: jar.get(name)! } : undefined,
|
|
10
|
+
}),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
import { getUnverifiedUserFromSidekickCookie } from '../src/next-ssr/getUserFromSidekickCookie';
|
|
14
|
+
|
|
15
|
+
const user = { id: 'u1', refresh_token: 't1' };
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jar.clear();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('reads the cookie under the new name', async () => {
|
|
22
|
+
jar.set('sidekick_user_a', JSON.stringify(user));
|
|
23
|
+
expect(await getUnverifiedUserFromSidekickCookie('a')).toEqual(user);
|
|
24
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type SidekickReactRoom } from '@sidekickdb/react-common';
|
|
3
3
|
import type { RoomSchemaShape } from '@sidekickdb/core';
|
|
4
4
|
export declare function Cursors<RoomSchema extends RoomSchemaShape, RoomType extends string & keyof RoomSchema>({ as, spaceId: _spaceId, room, className, style, userCursorColor, children, renderCursor, propagate, zIndex, }: {
|
|
5
5
|
spaceId?: string;
|
|
6
|
-
room:
|
|
6
|
+
room: SidekickReactRoom<any, RoomSchema, RoomType>;
|
|
7
7
|
style?: React.CSSProperties;
|
|
8
8
|
userCursorColor?: string;
|
|
9
9
|
as?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cursors.d.ts","sourceRoot":"","sources":["../../src/Cursors.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"Cursors.d.ts","sourceRoot":"","sources":["../../src/Cursors.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAIf,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,KAAK,iBAAiB,EAAE,MA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B,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,WAAW,GAAkB;IACjC,QAAQ,EAAE,QAAQ;IAClB,aAAa,EAAE,MAAM;IACrB,UAAU,EAAE,MAAM;CACnB,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,CAAC","sourcesContent":["import {\n createElement,\n type ReactNode,\n type MouseEvent,\n type TouchEvent,\n type CSSProperties,\n} from 'react';\nimport { type
|
|
1
|
+
{"version":3,"file":"Cursors.js","sourceRoot":"","sources":["../../src/Cursors.tsx"],"names":[],"mappings":";;AAUA,0BAiJC;;AA3JD,iCAMe;AAIf,SAAgB,OAAO,CAGrB,EACA,EAAE,GAAG,KAAK,EACV,OAAO,EAAE,QAAQ,EACjB,IAAI,EACJ,SAAS,EACT,KAAK,EACL,eAAe,EACf,QAAQ,EACR,YAAY,EACZ,SAAS,EACT,MAAM,GAeP;IACC,MAAM,OAAO,GACX,QAAQ,IAAI,0BAA0B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IAEvE,MAAM,eAAe,GAAG,IAAI,CAAC,WAAW,CAAC;QACvC,IAAI,EAAE,CAAC,OAAO,CAA+C;KAC9D,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAEzE,SAAS,aAAa,CACpB,IAAa,EACb,KAA2C;QAE3C,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;QACxB,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;QACtD,M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KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,EACpC,OAAO,EAAE,OAAO,IAAI,IAAI,IAAI,EAAE,EAC9B,IAAI,EAAC,MAAM,EACX,KAAK,EAAC,4BAA4B,aAElC,+BACE,IAAI,EAAC,gBAAgB,EACrB,SAAS,EAAC,6DAA6D,aAEvE,iCAAM,CAAC,EAAC,qDAAqD,GAAG,EAChE,iCAAM,CAAC,EAAC,wDAAwD,GAAG,IACjE,EACJ,+BACE,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,6DAA6D,aAEvE,iCAAM,CAAC,EAAC,qDAAqD,GAAG,EAChE,iCAAM,CAAC,EAAC,wDAAwD,GAAG,IACjE,EACJ,+BACE,IAAI,EAAE,IAAI,EACV,SAAS,EAAC,6DAA6D,aAEvE,iCAAM,CAAC,EAAC,iDAAiD,GAAG,EAC5D,iCAAM,CAAC,EAAC,+CAA+C,GAAG,IACxD,IACA,CACP,CAAC;AACJ,CAAC;AAED,MAAM,SAAS,GAAkB;IAC/B,QAAQ,EAAE,UAAU;IACpB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,WAAW,GAAkB;IACjC,QAAQ,EAAE,QAAQ;IAClB,aAAa,EAAE,MAAM;IACrB,UAAU,EAAE,MAAM;CACnB,CAAC;AAEF,MAAM,QAAQ,GAAG,KAAK,CAAC","sourcesContent":["import {\n createElement,\n type ReactNode,\n type MouseEvent,\n type TouchEvent,\n type CSSProperties,\n} from 'react';\nimport { type SidekickReactRoom } from '@sidekickdb/react-common';\nimport type { RoomSchemaShape } from '@sidekickdb/core';\n\nexport function Cursors<\n RoomSchema extends RoomSchemaShape,\n RoomType extends string & keyof RoomSchema,\n>({\n as = 'div',\n spaceId: _spaceId,\n room,\n className,\n style,\n userCursorColor,\n children,\n renderCursor,\n propagate,\n zIndex,\n}: {\n spaceId?: string;\n room: SidekickReactRoom<any, RoomSchema, RoomType>;\n style?: React.CSSProperties;\n userCursorColor?: string;\n as?: any;\n className?: string;\n children?: ReactNode;\n renderCursor?: (props: {\n color: string;\n presence: RoomSchema[RoomType]['presence'];\n }) => ReactNode;\n propagate?: boolean;\n zIndex?: number;\n}) {\n const spaceId =\n _spaceId || `cursors-space-default--${String(room.type)}-${room.id}`;\n\n const cursorsPresence = room.usePresence({\n keys: [spaceId] as (keyof RoomSchema[RoomType]['presence'])[],\n });\n\n const fullPresence = room._core._reactor.getPresence(room.type, room.id);\n\n function publishCursor(\n rect: DOMRect,\n touch: { clientX: number; clientY: number },\n ) {\n const x = touch.clientX;\n const y = touch.clientY;\n const xPercent = ((x - rect.left) / rect.width) * 100;\n const yPercent = ((y - rect.top) / rect.height) * 100;\n cursorsPresence.publishPresence({\n [spaceId]: {\n x,\n y,\n xPercent,\n yPercent,\n color: userCursorColor,\n },\n } as RoomSchema[RoomType]['presence']);\n }\n\n function onMouseMove(e: MouseEvent) {\n if (!propagate) {\n e.stopPropagation();\n }\n\n const rect = e.currentTarget.getBoundingClientRect();\n publishCursor(rect, e);\n }\n\n function onMouseOut(e: MouseEvent) {\n cursorsPresence.publishPresence({\n [spaceId]: undefined,\n } as RoomSchema[RoomType]['presence']);\n }\n\n function onTouchMove(e: TouchEvent) {\n if (e.touches.length !== 1) {\n return;\n }\n\n const touch = e.touches[0];\n\n if (touch.target instanceof Element) {\n if (!propagate) {\n e.stopPropagation();\n }\n const rect = touch.target.getBoundingClientRect();\n publishCursor(rect, touch);\n }\n }\n\n function onTouchEnd(e: TouchEvent) {\n cursorsPresence.publishPresence({\n [spaceId]: undefined,\n } as RoomSchema[RoomType]['presence']);\n }\n\n return createElement(\n as,\n {\n onMouseMove,\n onMouseOut,\n onTouchMove,\n onTouchEnd,\n className,\n style: {\n position: 'relative',\n ...style,\n },\n },\n [\n children,\n <div\n key={spaceId}\n style={{\n ...absStyles,\n ...inertStyles,\n zIndex: zIndex !== undefined ? zIndex : defaultZ,\n }}\n >\n {Object.entries(cursorsPresence.peers).map(([id, presence]) => {\n const cursor = presence[spaceId];\n if (!cursor) return null;\n\n return (\n <div\n key={id}\n style={{\n ...absStyles,\n transform: `translate(${cursor.xPercent}%, ${cursor.yPercent}%)`,\n transformOrigin: '0 0',\n transition: 'transform 100ms',\n }}\n >\n {renderCursor ? (\n renderCursor({\n color: cursor.color,\n presence: fullPresence?.peers[id],\n })\n ) : (\n <Cursor {...cursor} />\n )}\n </div>\n );\n })}\n </div>,\n ],\n );\n}\n\nfunction Cursor({ color }: { color: string }) {\n const size = 35;\n const fill = color || 'black';\n\n return (\n <svg\n style={{ height: size, width: size }}\n viewBox={`0 0 ${size} ${size}`}\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <g\n fill=\"rgba(0,0,0,.2)\"\n transform=\"matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)\"\n >\n <path d=\"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z\" />\n <path d=\"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z\" />\n </g>\n <g\n fill=\"white\"\n transform=\"matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)\"\n >\n <path d=\"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z\" />\n <path d=\"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z\" />\n </g>\n <g\n fill={fill}\n transform=\"matrix(1, 0, 0, 1, -11.999999046325684, -8.406899452209473)\"\n >\n <path d=\"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z\" />\n <path d=\"m13 10.814v11.188l2.969-2.866.428-.139h4.768z\" />\n </g>\n </svg>\n );\n}\n\nconst absStyles: CSSProperties = {\n position: 'absolute',\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n};\n\nconst inertStyles: CSSProperties = {\n overflow: 'hidden',\n pointerEvents: 'none',\n userSelect: 'none',\n};\n\nconst defaultZ = 99999;\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SidekickConfig, SidekickSchemaDef } from '@sidekickdb/core';
|
|
2
|
+
import { SidekickReactAbstractDatabase } from '@sidekickdb/react-common';
|
|
3
|
+
import { EventSource } from 'eventsource';
|
|
4
|
+
export default class SidekickReactWebDatabase<Schema extends SidekickSchemaDef<any, any, any>, UseDates extends boolean = false, Config extends SidekickConfig<Schema, UseDates> = SidekickConfig<Schema, UseDates>> extends SidekickReactAbstractDatabase<Schema, UseDates, Config> {
|
|
5
|
+
static EventSourceImpl: typeof EventSource;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=SidekickReactWebDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidekickReactWebDatabase.d.ts","sourceRoot":"","sources":["../../src/SidekickReactWebDatabase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,OAAO,OAAO,wBAAwB,CAC3C,MAAM,SAAS,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC/C,QAAQ,SAAS,OAAO,GAAG,KAAK,EAChC,MAAM,SAAS,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,cAAc,CAC9D,MAAM,EACN,QAAQ,CACT,CACD,SAAQ,6BAA6B,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC;IAC/D,MAAM,CAAC,eAAe,qBAAe;CACtC"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const react_common_1 = require("@sidekickdb/react-common");
|
|
4
4
|
const eventsource_1 = require("eventsource");
|
|
5
|
-
class
|
|
5
|
+
class SidekickReactWebDatabase extends react_common_1.SidekickReactAbstractDatabase {
|
|
6
6
|
static EventSourceImpl = eventsource_1.EventSource;
|
|
7
7
|
}
|
|
8
|
-
exports.default =
|
|
9
|
-
//# sourceMappingURL=
|
|
8
|
+
exports.default = SidekickReactWebDatabase;
|
|
9
|
+
//# sourceMappingURL=SidekickReactWebDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidekickReactWebDatabase.js","sourceRoot":"","sources":["../../src/SidekickReactWebDatabase.ts"],"names":[],"mappings":";;AACA,2DAAyE;AACzE,6CAA0C;AAE1C,MAAqB,wBAOnB,SAAQ,4CAAuD;IAC/D,MAAM,CAAC,eAAe,GAAG,yBAAW,CAAC;;AARvC,2CASC","sourcesContent":["import type { SidekickConfig, SidekickSchemaDef } from '@sidekickdb/core';\nimport { SidekickReactAbstractDatabase } from '@sidekickdb/react-common';\nimport { EventSource } from 'eventsource';\n\nexport default class SidekickReactWebDatabase<\n Schema extends SidekickSchemaDef<any, any, any>,\n UseDates extends boolean = false,\n Config extends SidekickConfig<Schema, UseDates> = SidekickConfig<\n Schema,\n UseDates\n >,\n> extends SidekickReactAbstractDatabase<Schema, UseDates, Config> {\n static EventSourceImpl = EventSource;\n}\n"]}
|
package/dist/commonjs/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { id, tx, lookup, i,
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { id, tx, lookup, i, SidekickAPIError, SyncTableCallbackEventType, setSidekickWarningsEnabled, type QueryResponse, type SidekickQuery, type SidekickQueryResult, type SidekickSchema, type SidekickObject, type SidekickEntity, type SidekickSchemaDatabase, type SidekickUnknownSchemaDef, type ISidekickDatabase, type User, type AuthState, type Query, type Config, type SideQLParams, type ConnectionStatus, type AppStatusState, type ValidQuery, type PresencePeer, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type SidekickGraph, type SidekickConfig, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type SideQLEntity, type SideQLFields, type SideQLResult, type SideQLEntitySubquery, type RoomsOf, type RoomsDef, type PresenceOf, type TopicsOf, type TopicOf, type RoomHandle, type TransactionChunk, type SidekickUnknownSchema, type SidekickSchemaDef, type BackwardsCompatibleSchema, type SidekickRules, type UpdateParams, type LinkParams, type CreateParams, type CheckMagicCodeParams, type CheckMagicCodeResponse, type ExchangeCodeForTokenParams, type SendMagicCodeParams, type SendMagicCodeResponse, type SignInWithIdTokenParams, type VerifyMagicCodeParams, type VerifyResponse, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type SyncTableCallback, type SyncTableCallbackEvent, type SyncTableInitialSyncBatch, type SyncTableInitialSyncComplete, type SyncTableSyncTransaction, type SyncTableLoadFromStorage, type SyncTableSetupError, StoreInterface, createSidekickRouteHandler, type SidekickRouteHandlerPayloadByType, type SidekickRouteHandlerType, type SidekickRouteHandlerBody, type StoreInterfaceStoreName, SidekickWritableStream, SidekickReadableStream, type Logger } from '@sidekickdb/core';
|
|
2
|
+
import { SidekickReactAbstractDatabase } from '@sidekickdb/react-common';
|
|
3
|
+
import SidekickReactWebDatabase from './SidekickReactWebDatabase.ts';
|
|
4
4
|
import { init, init_experimental } from './init.ts';
|
|
5
5
|
import { Cursors } from './Cursors.tsx';
|
|
6
|
-
export { id, tx, lookup, init, init_experimental,
|
|
6
|
+
export { id, tx, lookup, init, init_experimental, SidekickReactWebDatabase, Cursors, i, SidekickAPIError, SidekickReactAbstractDatabase, SyncTableCallbackEventType, setSidekickWarningsEnabled, type Config, type SidekickConfig, type SidekickUnknownSchemaDef, type Query, type QueryResponse, type SidekickObject, type User, type AuthState, type ConnectionStatus, type AppStatusState, type SidekickQuery, type SidekickQueryResult, type SidekickSchema, type SidekickEntity, type SidekickSchemaDatabase, type ISidekickDatabase, type SideQLParams, type ValidQuery, type SideQLFields, type PresencePeer, type AttrsDefs, type CardinalityKind, type DataAttrDef, type EntitiesDef, type EntitiesWithLinks, type EntityDef, type SidekickGraph, type LinkAttrDef, type LinkDef, type LinksDef, type ResolveAttrs, type ValueTypes, type SideQLEntity, type SideQLResult, type SideQLEntitySubquery, type RoomsOf, type RoomsDef, type TransactionChunk, type PresenceOf, type TopicsOf, type TopicOf, type RoomHandle, type SidekickUnknownSchema, type SidekickSchemaDef, type BackwardsCompatibleSchema, type SidekickRules, type UpdateParams, type LinkParams, type CreateParams, type CheckMagicCodeParams, type CheckMagicCodeResponse, type ExchangeCodeForTokenParams, type SendMagicCodeParams, type SendMagicCodeResponse, type SignInWithIdTokenParams, type VerifyMagicCodeParams, type VerifyResponse, type FileOpts, type UploadFileResponse, type DeleteFileResponse, type CreateReadStreamOpts, type CreateWriteStreamOpts, type SidekickWritableStream, type SidekickReadableStream, StoreInterface, type StoreInterfaceStoreName, type SyncTableCallback, type SyncTableCallbackEvent, type SyncTableInitialSyncBatch, type SyncTableInitialSyncComplete, type SyncTableSyncTransaction, type SyncTableLoadFromStorage, type SyncTableSetupError, createSidekickRouteHandler, type SidekickRouteHandlerPayloadByType, type SidekickRouteHandlerType, type SidekickRouteHandlerBody, type Logger, };
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC,EAGD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC,EAGD,gBAAgB,EAGhB,0BAA0B,EAC1B,0BAA0B,EAG1B,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,cAAc,EACnB,KAAK,cAA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AK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EAGnB,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EAGvB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAG3B,cAAc,EACd,KAAK,uBAAuB,EAG5B,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EAGxB,0BAA0B,EAC1B,KAAK,iCAAiC,EACtC,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAG7B,KAAK,MAAM,GACZ,CAAC"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -3,25 +3,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.createSidekickRouteHandler = exports.StoreInterface = exports.setSidekickWarningsEnabled = exports.SyncTableCallbackEventType = exports.SidekickReactAbstractDatabase = exports.SidekickAPIError = exports.i = exports.Cursors = exports.SidekickReactWebDatabase = exports.init_experimental = exports.init = exports.lookup = exports.tx = exports.id = void 0;
|
|
7
7
|
const core_1 = require("@sidekickdb/core");
|
|
8
8
|
Object.defineProperty(exports, "id", { enumerable: true, get: function () { return core_1.id; } });
|
|
9
9
|
Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return core_1.tx; } });
|
|
10
10
|
Object.defineProperty(exports, "lookup", { enumerable: true, get: function () { return core_1.lookup; } });
|
|
11
11
|
Object.defineProperty(exports, "i", { enumerable: true, get: function () { return core_1.i; } });
|
|
12
|
-
Object.defineProperty(exports, "
|
|
12
|
+
Object.defineProperty(exports, "SidekickAPIError", { enumerable: true, get: function () { return
|
|
13
13
|
// error
|
|
14
|
-
core_1.
|
|
14
|
+
core_1.SidekickAPIError; } });
|
|
15
15
|
Object.defineProperty(exports, "SyncTableCallbackEventType", { enumerable: true, get: function () { return
|
|
16
16
|
// sync table enums
|
|
17
17
|
core_1.SyncTableCallbackEventType; } });
|
|
18
|
-
Object.defineProperty(exports, "
|
|
18
|
+
Object.defineProperty(exports, "setSidekickWarningsEnabled", { enumerable: true, get: function () { return core_1.setSidekickWarningsEnabled; } });
|
|
19
19
|
Object.defineProperty(exports, "StoreInterface", { enumerable: true, get: function () { return core_1.StoreInterface; } });
|
|
20
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "createSidekickRouteHandler", { enumerable: true, get: function () { return core_1.createSidekickRouteHandler; } });
|
|
21
21
|
const react_common_1 = require("@sidekickdb/react-common");
|
|
22
|
-
Object.defineProperty(exports, "
|
|
23
|
-
const
|
|
24
|
-
exports.
|
|
22
|
+
Object.defineProperty(exports, "SidekickReactAbstractDatabase", { enumerable: true, get: function () { return react_common_1.SidekickReactAbstractDatabase; } });
|
|
23
|
+
const SidekickReactWebDatabase_ts_1 = __importDefault(require("./SidekickReactWebDatabase.js"));
|
|
24
|
+
exports.SidekickReactWebDatabase = SidekickReactWebDatabase_ts_1.default;
|
|
25
25
|
const init_ts_1 = require("./init.js");
|
|
26
26
|
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_ts_1.init; } });
|
|
27
27
|
Object.defineProperty(exports, "init_experimental", { enumerable: true, get: function () { return init_ts_1.init_experimental; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAsG0B;AAQxB,mFA7GA,SAAE,OA6GA;AACF,mFA7GA,SAAE,OA6GA;AACF,uFA7GA,aAAM,OA6GA;AAKN,kFAjHA,QAAC,OAiHA;AAGD;IAlHA,QAAQ;IACR,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,2CAsG0B;AAQxB,mFA7GA,SAAE,OA6GA;AACF,mFA7GA,SAAE,OA6GA;AACF,uFA7GA,aAAM,OA6GA;AAKN,kFAjHA,QAAC,OAiHA;AAGD;IAlHA,QAAQ;IACR,uBAAgB,OAiHA;AAMhB;IArHA,mBAAmB;IACnB,iCAA0B,OAoHA;AAG1B,2GAtHA,iCAA0B,OAsHA;AA6E1B,+FAjHA,qBAAc,OAiHA;AAad,2GA7HA,iCAA0B,OA6HA;AAnH5B,2DAAyE;AAmBvE,8GAnBO,4CAA6B,OAmBP;AAlB/B,gGAAqE;AAUnE,mCAVK,qCAAwB,CAUL;AAT1B,uCAAoD;AAOlD,qFAPO,cAAI,OAOP;AACJ,kGARa,2BAAiB,OAQb;AAPnB,8CAAwC;AAStC,wFATO,qBAAO,OASP","sourcesContent":["import {\n id,\n tx,\n lookup,\n i,\n\n // error\n SidekickAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n setSidekickWarningsEnabled,\n\n // types\n type QueryResponse,\n type SidekickQuery,\n type SidekickQueryResult,\n type SidekickSchema,\n type SidekickObject,\n type SidekickEntity,\n type SidekickSchemaDatabase,\n type SidekickUnknownSchemaDef,\n type ISidekickDatabase,\n type User,\n type AuthState,\n type Query,\n type Config,\n type SideQLParams,\n type ConnectionStatus,\n type AppStatusState,\n type ValidQuery,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type SidekickGraph,\n type SidekickConfig,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type SideQLEntity,\n type SideQLFields,\n type SideQLResult,\n type SideQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type TransactionChunk,\n type SidekickUnknownSchema,\n type SidekickSchemaDef,\n type BackwardsCompatibleSchema,\n type SidekickRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\n type CheckMagicCodeParams,\n type CheckMagicCodeResponse,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // stream types\n type CreateReadStreamOpts,\n type CreateWriteStreamOpts,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n StoreInterface,\n createSidekickRouteHandler,\n type SidekickRouteHandlerPayloadByType,\n type SidekickRouteHandlerType,\n type SidekickRouteHandlerBody,\n type StoreInterfaceStoreName,\n SidekickWritableStream,\n SidekickReadableStream,\n type Logger,\n} from '@sidekickdb/core';\n\nimport { SidekickReactAbstractDatabase } from '@sidekickdb/react-common';\nimport SidekickReactWebDatabase from './SidekickReactWebDatabase.ts';\nimport { init, init_experimental } from './init.ts';\nimport { Cursors } from './Cursors.tsx';\n\nexport {\n id,\n tx,\n lookup,\n init,\n init_experimental,\n SidekickReactWebDatabase,\n Cursors,\n i,\n\n // error\n SidekickAPIError,\n\n // internal\n SidekickReactAbstractDatabase,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // warnings\n setSidekickWarningsEnabled,\n\n // types\n type Config,\n type SidekickConfig,\n type SidekickUnknownSchemaDef,\n type Query,\n type QueryResponse,\n type SidekickObject,\n type User,\n type AuthState,\n type ConnectionStatus,\n type AppStatusState,\n type SidekickQuery,\n type SidekickQueryResult,\n type SidekickSchema,\n type SidekickEntity,\n type SidekickSchemaDatabase,\n type ISidekickDatabase,\n type SideQLParams,\n type ValidQuery,\n type SideQLFields,\n\n // presence types\n type PresencePeer,\n\n // schema types\n type AttrsDefs,\n type CardinalityKind,\n type DataAttrDef,\n type EntitiesDef,\n type EntitiesWithLinks,\n type EntityDef,\n type SidekickGraph,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type SideQLEntity,\n type SideQLResult,\n type SideQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type TransactionChunk,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type SidekickUnknownSchema,\n type SidekickSchemaDef,\n type BackwardsCompatibleSchema,\n type SidekickRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\n type CheckMagicCodeParams,\n type CheckMagicCodeResponse,\n type ExchangeCodeForTokenParams,\n type SendMagicCodeParams,\n type SendMagicCodeResponse,\n type SignInWithIdTokenParams,\n type VerifyMagicCodeParams,\n type VerifyResponse,\n\n // storage types\n type FileOpts,\n type UploadFileResponse,\n type DeleteFileResponse,\n\n // stream types\n type CreateReadStreamOpts,\n type CreateWriteStreamOpts,\n type SidekickWritableStream,\n type SidekickReadableStream,\n\n // custom store\n StoreInterface,\n type StoreInterfaceStoreName,\n\n // sync table types\n type SyncTableCallback,\n type SyncTableCallbackEvent,\n type SyncTableInitialSyncBatch,\n type SyncTableInitialSyncComplete,\n type SyncTableSyncTransaction,\n type SyncTableLoadFromStorage,\n type SyncTableSetupError,\n\n // Server helper\n createSidekickRouteHandler,\n type SidekickRouteHandlerPayloadByType,\n type SidekickRouteHandlerType,\n type SidekickRouteHandlerBody,\n\n // logger\n type Logger,\n};\n"]}
|
package/dist/commonjs/init.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { SidekickConfig, SidekickSchemaDef, SidekickUnknownSchema } from '@sidekickdb/core';
|
|
2
|
+
import SidekickReactWebDatabase from './SidekickReactWebDatabase.ts';
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
5
|
* The first step: init your application!
|
|
@@ -14,15 +14,15 @@ import InstantReactWebDatabase from './InstantReactWebDatabase.ts';
|
|
|
14
14
|
* // You can also provide a schema for type safety and editor autocomplete!
|
|
15
15
|
*
|
|
16
16
|
* import { init } from "@sidekickdb/react"
|
|
17
|
-
* import schema from ""../
|
|
17
|
+
* import schema from ""../sidekick.schema.ts";
|
|
18
18
|
*
|
|
19
19
|
* const db = init({ appId: "my-app-id", apiURI: "https://sidekick.example.com", schema })
|
|
20
20
|
*
|
|
21
21
|
* // To learn more: https://sidekickdb.co/docs/modeling-data
|
|
22
22
|
*/
|
|
23
|
-
export declare function init<Schema extends
|
|
23
|
+
export declare function init<Schema extends SidekickSchemaDef<any, any, any> = SidekickUnknownSchema, UseDates extends boolean = false>(config: Omit<SidekickConfig<Schema, UseDates>, 'useDateObjects'> & {
|
|
24
24
|
useDateObjects?: UseDates;
|
|
25
|
-
}):
|
|
25
|
+
}): SidekickReactWebDatabase<Schema, UseDates, SidekickConfig<Schema, UseDates>>;
|
|
26
26
|
/**
|
|
27
27
|
* @deprecated
|
|
28
28
|
* `init_experimental` is deprecated. You can replace it with `init`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,wBAAwB,MAAM,+BAA+B,CAAC;AAGrE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAClB,MAAM,SAAS,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,qBAAqB,EACvE,QAAQ,SAAS,OAAO,GAAG,KAAK,EAIhC,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,gBAAgB,CAAC,GAAG;IACjE,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC3B,GACA,wBAAwB,CACzB,MAAM,EACN,QAAQ,EACR,cAAc,CAAC,MAAM,EAAE,QAAQ,CAAC,CACjC,CAYA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,iBAAiB,aAAO,CAAC"}
|
package/dist/commonjs/init.js
CHANGED
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init_experimental = void 0;
|
|
7
7
|
exports.init = init;
|
|
8
|
-
const
|
|
8
|
+
const SidekickReactWebDatabase_ts_1 = __importDefault(require("./SidekickReactWebDatabase.js"));
|
|
9
9
|
const version_ts_1 = __importDefault(require("./version.js"));
|
|
10
10
|
/**
|
|
11
11
|
*
|
|
@@ -21,7 +21,7 @@ const version_ts_1 = __importDefault(require("./version.js"));
|
|
|
21
21
|
* // You can also provide a schema for type safety and editor autocomplete!
|
|
22
22
|
*
|
|
23
23
|
* import { init } from "@sidekickdb/react"
|
|
24
|
-
* import schema from ""../
|
|
24
|
+
* import schema from ""../sidekick.schema.ts";
|
|
25
25
|
*
|
|
26
26
|
* const db = init({ appId: "my-app-id", apiURI: "https://sidekick.example.com", schema })
|
|
27
27
|
*
|
|
@@ -29,14 +29,14 @@ const version_ts_1 = __importDefault(require("./version.js"));
|
|
|
29
29
|
*/
|
|
30
30
|
function init(
|
|
31
31
|
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
32
|
-
// as a non-nullable in the
|
|
32
|
+
// as a non-nullable in the SidekickConfig type.
|
|
33
33
|
config) {
|
|
34
34
|
const configStrict = {
|
|
35
35
|
...config,
|
|
36
36
|
useDateObjects: (config.useDateObjects ?? false),
|
|
37
37
|
};
|
|
38
|
-
return new
|
|
39
|
-
'@
|
|
38
|
+
return new SidekickReactWebDatabase_ts_1.default(configStrict, {
|
|
39
|
+
'@sidekickdb/react': version_ts_1.default,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":";;;;;;AA6BA,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":";;;;;;AA6BA,oBAyBC;AAhDD,gGAAqE;AACrE,8DAAmC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,IAAI;AAIlB,oEAAoE;AACpE,gDAAgD;AAChD,MAEC;IAMD,MAAM,YAAY,GAAG;QACnB,GAAG,MAAM;QACT,cAAc,EAAE,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK,CAAa;KAC7D,CAAC;IACF,OAAO,IAAI,qCAAwB,CAIjC,YAAY,EAAE;QACd,mBAAmB,EAAE,oBAAO;KAC7B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACU,QAAA,iBAAiB,GAAG,IAAI,CAAC","sourcesContent":["import type {\n SidekickConfig,\n SidekickSchemaDef,\n SidekickUnknownSchema,\n} from '@sidekickdb/core';\n\nimport SidekickReactWebDatabase from './SidekickReactWebDatabase.ts';\nimport version from './version.ts';\n\n/**\n *\n * The first step: init your application!\n *\n * Find your `appId` in your SidekickDB dashboard.\n *\n * @example\n * import { init } from \"@sidekickdb/react\"\n *\n * const db = init({ appId: \"my-app-id\", apiURI: \"https://sidekick.example.com\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@sidekickdb/react\"\n * import schema from \"\"../sidekick.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", apiURI: \"https://sidekick.example.com\", schema })\n *\n * // To learn more: https://sidekickdb.co/docs/modeling-data\n */\nexport function init<\n Schema extends SidekickSchemaDef<any, any, any> = SidekickUnknownSchema,\n UseDates extends boolean = false,\n>(\n // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the SidekickConfig type.\n config: Omit<SidekickConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n): SidekickReactWebDatabase<\n Schema,\n UseDates,\n SidekickConfig<Schema, UseDates>\n> {\n const configStrict = {\n ...config,\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n return new SidekickReactWebDatabase<\n Schema,\n UseDates,\n SidekickConfig<Schema, UseDates>\n >(configStrict, {\n '@sidekickdb/react': version,\n });\n}\n\n/**\n * @deprecated\n * `init_experimental` is deprecated. You can replace it with `init`.\n *\n * @example\n *\n * // Before\n * import { init_experimental } from \"@sidekickdb/react\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@sidekickdb/react\"\n * const db = init({ ... });\n */\nexport const init_experimental = init;\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthState, SidekickSchemaDef, SideQLResponse, PageInfoResponse, RuleParams, ValidQuery } from '@sidekickdb/core';
|
|
2
|
+
import SidekickReactWebDatabase from '../SidekickReactWebDatabase.ts';
|
|
3
|
+
export declare class SidekickNextDatabase<Schema extends SidekickSchemaDef<any, any, any>, UseDates extends boolean> extends SidekickReactWebDatabase<Schema, UseDates> {
|
|
4
|
+
useSuspenseQuery: <Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
|
|
5
|
+
ruleParams: RuleParams;
|
|
6
|
+
}) => {
|
|
7
|
+
data: SideQLResponse<Schema, Q, NonNullable<UseDates>>;
|
|
8
|
+
pageInfo?: PageInfoResponse<Q>;
|
|
9
|
+
};
|
|
10
|
+
useAuth: () => AuthState;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=SidekickNextDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidekickNextDatabase.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/SidekickNextDatabase.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,wBAAwB,MAAM,gCAAgC,CAAC;AAItE,qBAAa,oBAAoB,CAC/B,MAAM,SAAS,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC/C,QAAQ,SAAS,OAAO,CACxB,SAAQ,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC3C,gBAAgB,GAAI,CAAC,SAAS,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EACxD,GAAG,CAAC,EACJ,OAAO;QACL,UAAU,EAAE,UAAU,CAAC;KACxB,KACA;QACD,IAAI,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;QACvD,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;KAChC,CAQC;IAEF,OAAO,QAAO,SAAS,CAoBrB;CACH"}
|
|
@@ -3,20 +3,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
6
|
+
exports.SidekickNextDatabase = void 0;
|
|
7
|
+
const SidekickReactWebDatabase_ts_1 = __importDefault(require("../SidekickReactWebDatabase.js"));
|
|
8
8
|
const react_1 = require("react");
|
|
9
|
-
const
|
|
10
|
-
class
|
|
9
|
+
const SidekickSuspenseProvider_tsx_1 = require("./SidekickSuspenseProvider.js");
|
|
10
|
+
class SidekickNextDatabase extends SidekickReactWebDatabase_ts_1.default {
|
|
11
11
|
useSuspenseQuery = (q, opts) => {
|
|
12
|
-
const ctx = (0, react_1.useContext)(
|
|
12
|
+
const ctx = (0, react_1.useContext)(SidekickSuspenseProvider_tsx_1.SuspsenseQueryContext);
|
|
13
13
|
if (!ctx) {
|
|
14
14
|
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
15
15
|
}
|
|
16
16
|
return ctx.useSuspenseQuery(q, opts);
|
|
17
17
|
};
|
|
18
18
|
useAuth = () => {
|
|
19
|
-
const ctx = (0, react_1.useContext)(
|
|
19
|
+
const ctx = (0, react_1.useContext)(SidekickSuspenseProvider_tsx_1.SuspsenseQueryContext);
|
|
20
20
|
const realAuthResult = this._useAuth();
|
|
21
21
|
if (!ctx) {
|
|
22
22
|
return realAuthResult;
|
|
@@ -35,5 +35,5 @@ class InstantNextDatabase extends InstantReactWebDatabase_ts_1.default {
|
|
|
35
35
|
return realAuthResult;
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
exports.
|
|
39
|
-
//# sourceMappingURL=
|
|
38
|
+
exports.SidekickNextDatabase = SidekickNextDatabase;
|
|
39
|
+
//# sourceMappingURL=SidekickNextDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidekickNextDatabase.js","sourceRoot":"","sources":["../../../src/next-ssr/SidekickNextDatabase.tsx"],"names":[],"mappings":";;;;;;AAQA,iGAAsE;AACtE,iCAAmC;AACnC,gFAAuE;AAEvE,MAAa,oBAGX,SAAQ,qCAA0C;IAC3C,gBAAgB,GAAG,CACxB,CAAI,EACJ,IAEC,EAID,EAAE;QACF,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,oDAAqB,CAAC,CAAC;QAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAQ,CAAC;IAC9C,CAAC,CAAC;IAEF,OAAO,GAAG,GAAc,EAAE;QACxB,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,oDAAqB,CAAC,CAAC;QAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QACvC,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;QACxB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO,cAAc,CAAC;QACxB,CAAC;QACD,IAAI,cAAc,CAAC,SAAS,EAAE,CAAC;YAC7B,OAAO;gBACL,KAAK,EAAE,SAAS;gBAChB,SAAS,EAAE,KAAK;gBAChB,IAAI,EAAE,OAAO,IAAI,SAAS,EAAE,qCAAqC;aAClE,CAAC;QACJ,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC,CAAC;CACH;AA3CD,oDA2CC","sourcesContent":["import {\n AuthState,\n SidekickSchemaDef,\n SideQLResponse,\n PageInfoResponse,\n RuleParams,\n ValidQuery,\n} from '@sidekickdb/core';\nimport SidekickReactWebDatabase from '../SidekickReactWebDatabase.ts';\nimport { useContext } from 'react';\nimport { SuspsenseQueryContext } from './SidekickSuspenseProvider.tsx';\n\nexport class SidekickNextDatabase<\n Schema extends SidekickSchemaDef<any, any, any>,\n UseDates extends boolean,\n> extends SidekickReactWebDatabase<Schema, UseDates> {\n public useSuspenseQuery = <Q extends ValidQuery<Q, Schema>>(\n q: Q,\n opts?: {\n ruleParams: RuleParams;\n },\n ): {\n data: SideQLResponse<Schema, Q, NonNullable<UseDates>>;\n pageInfo?: PageInfoResponse<Q>;\n } => {\n const ctx = useContext(SuspsenseQueryContext);\n if (!ctx) {\n throw new Error(\n 'useSuspenseQuery must be used within a SuspenseQueryProvider',\n );\n }\n return ctx.useSuspenseQuery(q, opts) as any;\n };\n\n useAuth = (): AuthState => {\n const ctx = useContext(SuspsenseQueryContext);\n const realAuthResult = this._useAuth();\n if (!ctx) {\n return realAuthResult;\n }\n\n const { ssrUser } = ctx;\n if (ssrUser === undefined) {\n return realAuthResult;\n }\n if (realAuthResult.isLoading) {\n return {\n error: undefined,\n isLoading: false,\n user: ssrUser ?? undefined, // null -> undefined for the response\n };\n }\n\n return realAuthResult;\n };\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SidekickSchemaDef, SideQLResponse, PageInfoResponse, RuleParams, User, ValidQuery } from '@sidekickdb/core';
|
|
2
|
+
import SidekickReactWebDatabase from '../SidekickReactWebDatabase.ts';
|
|
3
|
+
type SidekickSuspenseProviderProps<Schema extends SidekickSchemaDef<any, any, any>> = {
|
|
4
|
+
nonce?: string;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
db: SidekickReactWebDatabase<Schema, any>;
|
|
7
|
+
user?: User | null;
|
|
8
|
+
};
|
|
9
|
+
type SuspenseQueryContextValue = {
|
|
10
|
+
useSuspenseQuery: (query: any, opts?: SuspenseQueryOpts) => any;
|
|
11
|
+
ssrUser: User | null | undefined;
|
|
12
|
+
};
|
|
13
|
+
export declare const SuspsenseQueryContext: import("react").Context<SuspenseQueryContextValue | null>;
|
|
14
|
+
export declare const createUseSuspenseQuery: <Schema extends SidekickSchemaDef<any, any, any>, UseDates extends boolean>(_db: SidekickReactWebDatabase<Schema, UseDates>) => (<Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
|
|
15
|
+
ruleParams: RuleParams;
|
|
16
|
+
}) => {
|
|
17
|
+
data: SideQLResponse<Schema, Q, NonNullable<UseDates>>;
|
|
18
|
+
pageInfo?: PageInfoResponse<Q>;
|
|
19
|
+
});
|
|
20
|
+
type SuspenseQueryOpts = {
|
|
21
|
+
ruleParams: RuleParams;
|
|
22
|
+
};
|
|
23
|
+
export declare const SidekickSuspenseProvider: (props: SidekickSuspenseProviderProps<any>) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=SidekickSuspenseProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidekickSuspenseProvider.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/SidekickSuspenseProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,EAGL,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,UAAU,EACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,wBAAwB,MAAM,gCAAgC,CAAC;AAmBtE,KAAK,6BAA6B,CAChC,MAAM,SAAS,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAC7C;IACF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,EAAE,EAAE,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACpB,CAAC;AAIF,KAAK,yBAAyB,GAAG;IAC/B,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,GAAG,CAAC;IAChE,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF,eAAO,MAAM,qBAAqB,2DACqB,CAAC;AAGxD,eAAO,MAAM,sBAAsB,GACjC,MAAM,SAAS,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC/C,QAAQ,SAAS,OAAO,EAExB,KAAK,wBAAwB,CAAC,MAAM,EAAE,QAAQ,CAAC,KAC9C,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EAClC,CAAC,EAAE,CAAC,EACJ,IAAI,CAAC,EAAE;IACL,UAAU,EAAE,UAAU,CAAC;CACxB,KACE;IACH,IAAI,EAAE,cAAc,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAChC,CAUA,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAqJF,eAAO,MAAM,wBAAwB,GACnC,OAAO,6BAA6B,CAAC,GAAG,CAAC,4CA4D1C,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.SidekickSuspenseProvider = exports.createUseSuspenseQuery = exports.SuspsenseQueryContext = void 0;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
-
//
|
|
6
|
+
// SidekickSuspenseProvider can only be used in a client context so this prevents errors from trying to use it in a server component.
|
|
7
7
|
const core_1 = require("@sidekickdb/core");
|
|
8
8
|
const HydrationStreamProvider_tsx_1 = require("./HydrationStreamProvider.js");
|
|
9
9
|
const react_1 = require("react");
|
|
@@ -127,9 +127,9 @@ function createFrameworkClient(db, user) {
|
|
|
127
127
|
db.core._reactor.setFrameworkClient(client);
|
|
128
128
|
return client;
|
|
129
129
|
}
|
|
130
|
-
const
|
|
130
|
+
const SidekickSuspenseProvider = (props) => {
|
|
131
131
|
if (!props.db) {
|
|
132
|
-
throw new Error('Must provide db to
|
|
132
|
+
throw new Error('Must provide db to SidekickSuspenseProvider');
|
|
133
133
|
}
|
|
134
134
|
const db = props.db;
|
|
135
135
|
const [trackedKeys] = (0, react_1.useState)(() => new Set());
|
|
@@ -164,5 +164,5 @@ const InstantSuspenseProvider = (props) => {
|
|
|
164
164
|
});
|
|
165
165
|
}, children: props.children }) }));
|
|
166
166
|
};
|
|
167
|
-
exports.
|
|
168
|
-
//# sourceMappingURL=
|
|
167
|
+
exports.SidekickSuspenseProvider = SidekickSuspenseProvider;
|
|
168
|
+
//# sourceMappingURL=SidekickSuspenseProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SidekickSuspenseProvider.js","sourceRoot":"","sources":["../../../src/next-ssr/SidekickSuspenseProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AACb,qIAAqI;AAErI,2CAS0B;AAE1B,8EAGuC;AACvC,iCAQe;AACf,2DAGkC;AAWlC,MAAM,MAAM,GAAG,IAAA,2DAA6B,GAAO,CAAC;AAOvC,QAAA,qBAAqB,GAChC,IAAA,qBAAa,EAAmC,IAAI,CAAC,CAAC;AAExD,mCAAmC;AAC5B,MAAM,sBAAsB,GAAG,CAIpC,GAA+C,EAS9C,EAAE;IACH,OAAO,CAAkC,CAAM,EAAE,IAAS,EAAE,EAAE;QAC5D,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,6BAAqB,CAAC,CAAC;QAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;YACT,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAQ,CAAC;IAC9C,CAAC,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,sBAAsB,0BAuBjC;AAMF,SAAS,0BAA0B,CAAC,MAAuB;IACzD,OAAO,SAAS,sBAAsB,CAAC,KAAU,EAAE,IAAuB;QACxE,IAAI,KAAK,GAAG,MAAM,CAAC,yBAAyB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAE1D,IA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M,CAAC,QAAQ,IACd,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,OAAO,EAAE,GAAG,EAAE;gBACZ,MAAM,MAAM,GAAuC,EAAE,CAAC;gBACtD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,SAAS,CAAC,OAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,CAAC;oBAClE,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;wBACvD,MAAM,CAAC,IAAI,CAAC;4BACV,QAAQ,EAAE,GAAG;4BACb,KAAK,EAAE,KAAK,CAAC,IAAI;yBAClB,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;gBAED,WAAW,CAAC,KAAK,EAAE,CAAC;gBACpB,OAAO,MAAM,CAAC;YAChB,CAAC,EACD,SAAS,EAAE,CAAC,OAAO,EAAE,EAAE;gBACrB,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;oBACxB,SAAS,CAAC,OAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBACjE,CAAC,CAAC,CAAC;YACL,CAAC,YAEA,KAAK,CAAC,QAAQ,GACC,GACa,CAClC,CAAC;AACJ,CAAC,CAAC;AA7DW,QAAA,wBAAwB,4BA6DnC","sourcesContent":["'use client';\n// SidekickSuspenseProvider can only be used in a client context so this prevents errors from trying to use it in a server component.\n\nimport {\n FrameworkClient,\n SidekickConfig,\n SidekickSchemaDef,\n SideQLResponse,\n PageInfoResponse,\n RuleParams,\n User,\n ValidQuery,\n} from '@sidekickdb/core';\nimport SidekickReactWebDatabase from '../SidekickReactWebDatabase.ts';\nimport {\n createHydrationStreamProvider,\n isServer,\n} from './HydrationStreamProvider.tsx';\nimport {\n createContext,\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n useEffect,\n} from 'react';\nimport {\n SidekickReactAbstractDatabase,\n useQueryInternal,\n} from '@sidekickdb/react-common';\n\ntype SidekickSuspenseProviderProps<\n Schema extends SidekickSchemaDef<any, any, any>,\n> = {\n nonce?: string;\n children: React.ReactNode;\n db: SidekickReactWebDatabase<Schema, any>;\n user?: User | null;\n};\n\nconst stream = createHydrationStreamProvider<any>();\n\ntype SuspenseQueryContextValue = {\n useSuspenseQuery: (query: any, opts?: SuspenseQueryOpts) => any;\n ssrUser: User | null | undefined;\n};\n\nexport const SuspsenseQueryContext =\n createContext<SuspenseQueryContextValue | null>(null);\n\n// Creates a typed useSuspense hook\nexport const createUseSuspenseQuery = <\n Schema extends SidekickSchemaDef<any, any, any>,\n UseDates extends boolean,\n>(\n _db: SidekickReactWebDatabase<Schema, UseDates>,\n): (<Q extends ValidQuery<Q, Schema>>(\n q: Q,\n opts?: {\n ruleParams: RuleParams;\n },\n) => {\n data: SideQLResponse<Schema, Q, NonNullable<UseDates>>;\n pageInfo?: PageInfoResponse<Q>;\n}) => {\n return <Q extends ValidQuery<Q, Schema>>(q: any, opts: any) => {\n const ctx = useContext(SuspsenseQueryContext);\n if (!ctx) {\n throw new Error(\n 'useSuspenseQuery must be used within a SuspenseQueryProvider',\n );\n }\n return ctx.useSuspenseQuery(q, opts) as any;\n };\n};\n\ntype SuspenseQueryOpts = {\n ruleParams: RuleParams;\n};\n\nfunction makeUseSuspenseQueryServer(client: FrameworkClient) {\n return function useSuspenseQueryServer(query: any, opts: SuspenseQueryOpts) {\n let entry = client.getExistingResultForQuery(query, opts);\n\n if (!entry) {\n entry = client.query(query, opts);\n }\n\n if (entry.status === 'pending') {\n throw entry.promise;\n }\n\n if (entry.status === 'error') {\n throw entry.error;\n }\n\n if (entry.status === 'success') {\n switch (entry.type) {\n case 'session': {\n return entry.data;\n }\n case 'http': {\n const data = entry.data;\n const result = client.completeIsomorphic(\n query,\n data.triples,\n data.attrs,\n data.pageInfo,\n );\n\n return result;\n }\n }\n }\n };\n}\n\nfunction makeUseSuspenseQueryClient(\n db: SidekickReactAbstractDatabase<any, any>,\n client: FrameworkClient,\n) {\n function getEntry(query: any, opts: SuspenseQueryOpts, allowFetch: boolean) {\n const entry = client.getExistingResultForQuery(query, opts);\n\n if (entry?.status === 'pending') {\n throw entry.promise;\n }\n\n if (entry?.status === 'error') {\n throw entry.error;\n }\n\n if (entry?.status === 'success') {\n switch (entry.type) {\n case 'session': {\n return entry.data;\n }\n case 'http': {\n const data = entry.data;\n const result = client.completeIsomorphic(\n query,\n data.triples,\n data.attrs,\n data.pageInfo,\n );\n\n return result;\n }\n }\n }\n\n if (allowFetch) {\n const promise = client.queryClient(query, opts);\n throw promise;\n }\n }\n\n return function useSuspenseQueryClient(query: any, opts: SuspenseQueryOpts) {\n const useQueryResult = useQueryInternal(\n db.core,\n query,\n opts,\n // Returns the server result for useSyncExternalStore\n () => {\n try {\n const res = getEntry(query, opts, false);\n return res;\n } catch (throwable) {\n return { error: throwable };\n }\n },\n );\n\n const hasData = !!useQueryResult.state.data;\n const queryHash = useQueryResult.queryHash;\n\n useEffect(() => {\n if (hasData) {\n // We have a newer result, so remove the cached SSR or suspended\n // result from the framework client cache\n client.removeCachedQueryResult(queryHash);\n }\n }, [hasData, queryHash]);\n\n if (useQueryResult.state.data) {\n return {\n data: useQueryResult.state.data,\n pageInfo: useQueryResult.state.pageInfo,\n };\n }\n\n if (useQueryResult.state.error) {\n throw useQueryResult.state.error;\n }\n\n return getEntry(query, opts, true);\n };\n}\n\nfunction createFrameworkClient(\n db: SidekickReactAbstractDatabase<any, any>,\n user: User | null | undefined,\n) {\n if (isServer) {\n if (user && !user.refresh_token) {\n throw new Error(\n 'User must have a refresh_token field. Recieved: ' +\n JSON.stringify(user, null, 2),\n );\n }\n return new FrameworkClient({\n token: user?.refresh_token,\n db: db.core,\n });\n }\n\n // On the client, make sure we only have a single framework\n // in case our suspense provider gets unmounted\n const existing = db.core._reactor._frameworkClient;\n if (existing) {\n return existing;\n }\n const client = new FrameworkClient({ db: db.core });\n db.core._reactor.setFrameworkClient(client);\n return client;\n}\n\nexport const SidekickSuspenseProvider = (\n props: SidekickSuspenseProviderProps<any>,\n) => {\n if (!props.db) {\n throw new Error('Must provide db to SidekickSuspenseProvider');\n }\n\n const db = props.db;\n\n const [trackedKeys] = useState(() => new Set<string>());\n\n const clientRef = useRef<FrameworkClient>(\n createFrameworkClient(props.db, props.user),\n );\n\n if (isServer) {\n clientRef.current.subscribe((result) => {\n const { queryHash } = result;\n trackedKeys.add(queryHash);\n });\n }\n\n const useSuspenseQuery = useCallback(\n isServer\n ? makeUseSuspenseQueryServer(clientRef.current)\n : makeUseSuspenseQueryClient(db, clientRef.current),\n [],\n );\n\n const contextValue = useMemo(() => {\n return { useSuspenseQuery, ssrUser: props.user };\n }, [useSuspenseQuery, props.user]);\n\n return (\n <SuspsenseQueryContext.Provider value={contextValue}>\n <stream.Provider\n nonce={props.nonce}\n onFlush={() => {\n const toSend: { queryKey: string; value: any }[] = [];\n for (const [key, value] of clientRef.current!.resultMap.entries()) {\n if (trackedKeys.has(key) && value.status === 'success') {\n toSend.push({\n queryKey: key,\n value: value.data,\n });\n }\n }\n\n trackedKeys.clear();\n return toSend;\n }}\n onEntries={(entries) => {\n entries.forEach((entry) => {\n clientRef.current!.addQueryResult(entry.queryKey, entry.value);\n });\n }}\n >\n {props.children}\n </stream.Provider>\n </SuspsenseQueryContext.Provider>\n );\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { User } from '@sidekickdb/core';
|
|
2
|
+
/**
|
|
3
|
+
* @deprecated Please use `getUnverifiedUserFromSidekickCookie` instead
|
|
4
|
+
*/
|
|
5
|
+
export declare const getUserFromSidekickCookie: (appId: string) => Promise<User | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Parses a user object from current Next.JS request context's cookies.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getUnverifiedUserFromSidekickCookie: (appId: string) => Promise<User | null>;
|
|
10
|
+
//# sourceMappingURL=getUserFromSidekickCookie.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserFromSidekickCookie.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/getUserFromSidekickCookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,OAAO,MAAM,KACZ,OAAO,CAAC,IAAI,GAAG,IAAI,CAErB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mCAAmC,GAC9C,OAAO,MAAM,KACZ,OAAO,CAAC,IAAI,GAAG,IAAI,CAKrB,CAAC"}
|