@instantdb/react 0.22.96-experimental.add-posthog-frontend.20386914944.1 → 0.22.96
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/next-ssr/HydrationStreamProvider.d.ts +66 -0
- package/dist/commonjs/next-ssr/HydrationStreamProvider.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/HydrationStreamProvider.js +140 -0
- package/dist/commonjs/next-ssr/HydrationStreamProvider.js.map +1 -0
- package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts +12 -0
- package/dist/commonjs/next-ssr/InstantNextDatabase.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/InstantNextDatabase.js +42 -0
- package/dist/commonjs/next-ssr/InstantNextDatabase.js.map +1 -0
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts +28 -0
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.js +99 -0
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.js.map +1 -0
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts +3 -0
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.js +21 -0
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.js.map +1 -0
- package/dist/commonjs/next-ssr/htmlescape.d.ts +3 -0
- package/dist/commonjs/next-ssr/htmlescape.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/htmlescape.js +25 -0
- package/dist/commonjs/next-ssr/htmlescape.js.map +1 -0
- package/dist/commonjs/next-ssr/index.d.ts +28 -0
- package/dist/commonjs/next-ssr/index.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/index.js +43 -0
- package/dist/commonjs/next-ssr/index.js.map +1 -0
- package/dist/esm/next-ssr/HydrationStreamProvider.d.ts +66 -0
- package/dist/esm/next-ssr/HydrationStreamProvider.d.ts.map +1 -0
- package/dist/esm/next-ssr/HydrationStreamProvider.js +103 -0
- package/dist/esm/next-ssr/HydrationStreamProvider.js.map +1 -0
- package/dist/esm/next-ssr/InstantNextDatabase.d.ts +12 -0
- package/dist/esm/next-ssr/InstantNextDatabase.d.ts.map +1 -0
- package/dist/esm/next-ssr/InstantNextDatabase.js +35 -0
- package/dist/esm/next-ssr/InstantNextDatabase.js.map +1 -0
- package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts +28 -0
- package/dist/esm/next-ssr/InstantSuspenseProvider.d.ts.map +1 -0
- package/dist/esm/next-ssr/InstantSuspenseProvider.js +94 -0
- package/dist/esm/next-ssr/InstantSuspenseProvider.js.map +1 -0
- package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts +3 -0
- package/dist/esm/next-ssr/getUserFromInstantCookie.d.ts.map +1 -0
- package/dist/esm/next-ssr/getUserFromInstantCookie.js +17 -0
- package/dist/esm/next-ssr/getUserFromInstantCookie.js.map +1 -0
- package/dist/esm/next-ssr/htmlescape.d.ts +3 -0
- package/dist/esm/next-ssr/htmlescape.d.ts.map +1 -0
- package/dist/esm/next-ssr/htmlescape.js +21 -0
- package/dist/esm/next-ssr/htmlescape.js.map +1 -0
- package/dist/esm/next-ssr/index.d.ts +28 -0
- package/dist/esm/next-ssr/index.d.ts.map +1 -0
- package/dist/esm/next-ssr/index.js +32 -0
- package/dist/esm/next-ssr/index.js.map +1 -0
- package/dist/standalone/index.js +1563 -1507
- package/dist/standalone/index.umd.cjs +14 -14
- package/package.json +18 -6
- package/src/next-ssr/HydrationStreamProvider.tsx +200 -0
- package/src/next-ssr/InstantNextDatabase.tsx +56 -0
- package/src/next-ssr/InstantSuspenseProvider.tsx +189 -0
- package/src/next-ssr/getUserFromInstantCookie.ts +11 -0
- package/src/next-ssr/htmlescape.ts +24 -0
- package/src/next-ssr/index.tsx +47 -0
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export declare const isServer: boolean;
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
interface DataTransformer {
|
|
4
|
+
serialize: (object: any) => any;
|
|
5
|
+
deserialize: (object: any) => any;
|
|
6
|
+
}
|
|
7
|
+
interface HydrationStreamContext<TShape> {
|
|
8
|
+
id: string;
|
|
9
|
+
stream: {
|
|
10
|
+
/**
|
|
11
|
+
* **Server method**
|
|
12
|
+
* Push a new entry to the stream
|
|
13
|
+
* Will be ignored on the client
|
|
14
|
+
*/
|
|
15
|
+
push: (...shape: Array<TShape>) => void;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export interface HydrationStreamProviderProps<TShape> {
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
/**
|
|
21
|
+
* Optional transformer to serialize/deserialize the data
|
|
22
|
+
* Example devalue, superjson et al
|
|
23
|
+
*/
|
|
24
|
+
transformer?: DataTransformer;
|
|
25
|
+
/**
|
|
26
|
+
* **Client method**
|
|
27
|
+
* Called in the browser when new entries are received
|
|
28
|
+
*/
|
|
29
|
+
onEntries: (entries: Array<TShape>) => void;
|
|
30
|
+
/**
|
|
31
|
+
* **Server method**
|
|
32
|
+
* onFlush is called on the server when the cache is flushed
|
|
33
|
+
*/
|
|
34
|
+
onFlush?: () => Array<TShape>;
|
|
35
|
+
/**
|
|
36
|
+
* A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
|
|
37
|
+
*/
|
|
38
|
+
nonce?: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function createHydrationStreamProvider<TShape>(): {
|
|
41
|
+
Provider: (props: {
|
|
42
|
+
children: React.ReactNode;
|
|
43
|
+
/**
|
|
44
|
+
* Optional transformer to serialize/deserialize the data
|
|
45
|
+
* Example devalue, superjson et al
|
|
46
|
+
*/
|
|
47
|
+
transformer?: DataTransformer;
|
|
48
|
+
/**
|
|
49
|
+
* **Client method**
|
|
50
|
+
* Called in the browser when new entries are received
|
|
51
|
+
*/
|
|
52
|
+
onEntries: (entries: Array<TShape>) => void;
|
|
53
|
+
/**
|
|
54
|
+
* **Server method**
|
|
55
|
+
* onFlush is called on the server when the cache is flushed
|
|
56
|
+
*/
|
|
57
|
+
onFlush?: () => Array<TShape>;
|
|
58
|
+
/**
|
|
59
|
+
* A nonce that'll allow the inline script to be executed when Content Security Policy is enforced
|
|
60
|
+
*/
|
|
61
|
+
nonce?: string;
|
|
62
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
context: React.Context<HydrationStreamContext<TShape>>;
|
|
64
|
+
};
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=HydrationStreamProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydrationStreamProvider.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/HydrationStreamProvider.tsx"],"names":[],"mappings":"AAQA,eAAO,MAAM,QAAQ,SAAwD,CAAC;AAI9E,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAK/B,UAAU,eAAe;IACvB,SAAS,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAChC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;CACnC;AAWD,UAAU,sBAAsB,CAAC,MAAM;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE;QACN;;;;WAIG;QACH,IAAI,EAAE,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;KACzC,CAAC;CACH;AAED,MAAM,WAAW,4BAA4B,CAAC,MAAM;IAClD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACH,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAC5C;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAgB,6BAA6B,CAAC,MAAM;sBAaD;QAC/C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B;;;WAGG;QACH,WAAW,CAAC,EAAE,eAAe,CAAC;QAC9B;;;WAGG;QACH,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;QAC5C;;;WAGG;QACH,OAAO,CAAC,EAAE,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC;QAC9B;;WAEG;QACH,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB;;EAmGF"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.isServer = void 0;
|
|
38
|
+
exports.createHydrationStreamProvider = createHydrationStreamProvider;
|
|
39
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
40
|
+
// This allows us to send serialized json from the server to the client using 'useServerInsertedHTML'
|
|
41
|
+
// We are allowed to send whatever json we want, however it must be triggered at the same time as the client is recieving new html to display
|
|
42
|
+
// after a suspsense boundary resolves
|
|
43
|
+
// We do this to send a list of triples and attrs for each query that the server made so they can be pre-filled on the client render.
|
|
44
|
+
// useServerInsertedHTML is called whenever a suspense boundary resolves, resulting in new html being streamed down to the client.
|
|
45
|
+
exports.isServer = typeof window === 'undefined' || 'Deno' in globalThis;
|
|
46
|
+
const navigation_js_1 = require("next/navigation.js");
|
|
47
|
+
const React = __importStar(require("react"));
|
|
48
|
+
const htmlescape_js_1 = require("./htmlescape.js");
|
|
49
|
+
const serializedSymbol = Symbol('serialized');
|
|
50
|
+
function createHydrationStreamProvider() {
|
|
51
|
+
const context = React.createContext(null);
|
|
52
|
+
/**
|
|
53
|
+
|
|
54
|
+
* 1. (Happens on server): `useServerInsertedHTML()` is called **on the server** whenever a `Suspense`-boundary completes
|
|
55
|
+
* - This means that we might have some new entries in the cache that needs to be flushed
|
|
56
|
+
* - We pass these to the client by inserting a `<script>`-tag where we do `window[id].push(serializedVersionOfCache)`
|
|
57
|
+
* 2. (Happens in browser) In `useEffect()`:
|
|
58
|
+
* - We check if `window[id]` is set to an array and call `push()` on all the entries which will call `onEntries()` with the new entries
|
|
59
|
+
* - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received
|
|
60
|
+
**/
|
|
61
|
+
function UseClientHydrationStreamProvider(props) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
// unique id for the cache provider
|
|
64
|
+
const id = `__RQ${React.useId()}`;
|
|
65
|
+
const idJSON = (0, htmlescape_js_1.htmlEscapeJsonString)(JSON.stringify(id));
|
|
66
|
+
const [transformer] = React.useState(() => {
|
|
67
|
+
var _a;
|
|
68
|
+
return ((_a = props.transformer) !== null && _a !== void 0 ? _a : {
|
|
69
|
+
// noop
|
|
70
|
+
serialize: (obj) => obj,
|
|
71
|
+
deserialize: (obj) => obj,
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
// <server stuff>
|
|
75
|
+
const [stream] = React.useState(() => {
|
|
76
|
+
if (!exports.isServer) {
|
|
77
|
+
return {
|
|
78
|
+
push() {
|
|
79
|
+
// no-op on the client
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
});
|
|
85
|
+
const count = React.useRef(0);
|
|
86
|
+
(0, navigation_js_1.useServerInsertedHTML)(() => {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
// This only happens on the server
|
|
89
|
+
stream.push(...((_b = (_a = props.onFlush) === null || _a === void 0 ? void 0 : _a.call(props)) !== null && _b !== void 0 ? _b : []));
|
|
90
|
+
if (!stream.length) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
// console.log(`pushing ${stream.length} entries`)
|
|
94
|
+
const serializedCacheArgs = stream
|
|
95
|
+
.map((entry) => transformer.serialize(entry))
|
|
96
|
+
.map((entry) => JSON.stringify(entry))
|
|
97
|
+
.join(',');
|
|
98
|
+
// Flush stream
|
|
99
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
100
|
+
stream.length = 0;
|
|
101
|
+
const html = [
|
|
102
|
+
`window[${idJSON}] = window[${idJSON}] || [];`,
|
|
103
|
+
`window[${idJSON}].push(${(0, htmlescape_js_1.htmlEscapeJsonString)(serializedCacheArgs)});`,
|
|
104
|
+
];
|
|
105
|
+
return ((0, jsx_runtime_1.jsx)("script", { nonce: props.nonce, dangerouslySetInnerHTML: {
|
|
106
|
+
__html: html.join(''),
|
|
107
|
+
} }, count.current++));
|
|
108
|
+
});
|
|
109
|
+
// </server stuff>
|
|
110
|
+
// <client stuff>
|
|
111
|
+
// Setup and run the onEntries handler on the client only, but do it during
|
|
112
|
+
// the initial render so children have access to the data immediately
|
|
113
|
+
// This is important to avoid the client suspending during the initial render
|
|
114
|
+
// if the data has not yet been hydrated.
|
|
115
|
+
if (!exports.isServer) {
|
|
116
|
+
const win = window;
|
|
117
|
+
if (!((_a = win[id]) === null || _a === void 0 ? void 0 : _a.initialized)) {
|
|
118
|
+
// Client: consume cache:
|
|
119
|
+
const onEntries = (...serializedEntries) => {
|
|
120
|
+
const entries = serializedEntries.map((serialized) => transformer.deserialize(serialized));
|
|
121
|
+
props.onEntries(entries);
|
|
122
|
+
};
|
|
123
|
+
const winStream = (_b = win[id]) !== null && _b !== void 0 ? _b : [];
|
|
124
|
+
onEntries(...winStream);
|
|
125
|
+
// eslint-disable-next-line react-hooks/immutability
|
|
126
|
+
win[id] = {
|
|
127
|
+
initialized: true,
|
|
128
|
+
push: onEntries,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// </client stuff>
|
|
133
|
+
return ((0, jsx_runtime_1.jsx)(context.Provider, { value: { stream, id }, children: props.children }));
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
Provider: UseClientHydrationStreamProvider,
|
|
137
|
+
context,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=HydrationStreamProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HydrationStreamProvider.js","sourceRoot":"","sources":["../../../src/next-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,CAAA,EAAE,CAAC;gBAC1B,yBAAyB;gBACzB,MAAM,SAAS,GAAG,CAAC,GAAG,iBAA4C,EAAE,EAAE;oBACpE,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACnD,WAAW,CAAC,WAAW,CAAC,UAAU,CAAC,CACpC,CAAC;oBACF,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;gBAC3B,CAAC,CAAC;gBAEF,MAAM,SAAS,GAA8B,MAAA,GAAG,CAAC,EAAE,CAAC,mCAAI,EAAE,CAAC;gBAE3D,SAAS,CAAC,GAAG,SAAS,CAAC,CAAC;gBAExB,oDAAoD;gBACpD,GAAG,CAAC,EAAE,CAAC,GAAG;oBACR,WAAW,EAAE,IAAI;oBACjB,IAAI,EAAE,SAAS;iBAChB,CAAC;YACJ,CAAC;QACH,CAAC;QACD,kBAAkB;QAElB,OAAO,CACL,uBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,YACpC,KAAK,CAAC,QAAQ,GACE,CACpB,CAAC;IACJ,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,gCAAgC;QAC1C,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\n// This allows us to send serialized json from the server to the client using 'useServerInsertedHTML'\n// We are allowed to send whatever json we want, however it must be triggered at the same time as the client is recieving new html to display\n// after a suspsense boundary resolves\n// We do this to send a list of triples and attrs for each query that the server made so they can be pre-filled on the client render.\n// useServerInsertedHTML is called whenever a suspense boundary resolves, resulting in new html being streamed down to the client.\n\nexport const isServer = typeof window === 'undefined' || 'Deno' in globalThis;\n\nimport { useServerInsertedHTML } from 'next/navigation.js';\n\nimport * as React from 'react';\nimport { htmlEscapeJsonString } from './htmlescape.js';\n\nconst serializedSymbol = Symbol('serialized');\n\ninterface DataTransformer {\n serialize: (object: any) => any;\n deserialize: (object: any) => any;\n}\n\ntype Serialized<TData> = unknown & {\n [serializedSymbol]: TData;\n};\n\ninterface TypedDataTransformer<TData> {\n serialize: (obj: TData) => Serialized<TData>;\n deserialize: (obj: Serialized<TData>) => TData;\n}\n\ninterface HydrationStreamContext<TShape> {\n id: string;\n stream: {\n /**\n * **Server method**\n * Push a new entry to the stream\n * Will be ignored on the client\n */\n push: (...shape: Array<TShape>) => void;\n };\n}\n\nexport interface HydrationStreamProviderProps<TShape> {\n children: React.ReactNode;\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer;\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void;\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>;\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string;\n}\n\nexport function createHydrationStreamProvider<TShape>() {\n const context = React.createContext<HydrationStreamContext<TShape>>(\n null as any,\n );\n /**\n\n * 1. (Happens on server): `useServerInsertedHTML()` is called **on the server** whenever a `Suspense`-boundary completes\n * - This means that we might have some new entries in the cache that needs to be flushed\n * - We pass these to the client by inserting a `<script>`-tag where we do `window[id].push(serializedVersionOfCache)`\n * 2. (Happens in browser) In `useEffect()`:\n * - We check if `window[id]` is set to an array and call `push()` on all the entries which will call `onEntries()` with the new entries\n * - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received\n **/\n function UseClientHydrationStreamProvider(props: {\n children: React.ReactNode;\n /**\n * Optional transformer to serialize/deserialize the data\n * Example devalue, superjson et al\n */\n transformer?: DataTransformer;\n /**\n * **Client method**\n * Called in the browser when new entries are received\n */\n onEntries: (entries: Array<TShape>) => void;\n /**\n * **Server method**\n * onFlush is called on the server when the cache is flushed\n */\n onFlush?: () => Array<TShape>;\n /**\n * A nonce that'll allow the inline script to be executed when Content Security Policy is enforced\n */\n nonce?: string;\n }) {\n // unique id for the cache provider\n const id = `__RQ${React.useId()}`;\n const idJSON = htmlEscapeJsonString(JSON.stringify(id));\n\n const [transformer] = React.useState(\n () =>\n (props.transformer ?? {\n // noop\n serialize: (obj: any) => obj,\n deserialize: (obj: any) => obj,\n }) as unknown as TypedDataTransformer<TShape>,\n );\n\n // <server stuff>\n const [stream] = React.useState<Array<TShape>>(() => {\n if (!isServer) {\n return {\n push() {\n // no-op on the client\n },\n } as unknown as Array<TShape>;\n }\n return [];\n });\n const count = React.useRef(0);\n useServerInsertedHTML(() => {\n // This only happens on the server\n stream.push(...(props.onFlush?.() ?? []));\n\n if (!stream.length) {\n return null;\n }\n // console.log(`pushing ${stream.length} entries`)\n const serializedCacheArgs = stream\n .map((entry) => transformer.serialize(entry))\n .map((entry) => JSON.stringify(entry))\n .join(',');\n\n // Flush stream\n // eslint-disable-next-line react-hooks/immutability\n stream.length = 0;\n\n const html: Array<string> = [\n `window[${idJSON}] = window[${idJSON}] || [];`,\n `window[${idJSON}].push(${htmlEscapeJsonString(serializedCacheArgs)});`,\n ];\n return (\n <script\n key={count.current++}\n nonce={props.nonce}\n dangerouslySetInnerHTML={{\n __html: html.join(''),\n }}\n />\n );\n });\n // </server stuff>\n\n // <client stuff>\n // Setup and run the onEntries handler on the client only, but do it during\n // the initial render so children have access to the data immediately\n // This is important to avoid the client suspending during the initial render\n // if the data has not yet been hydrated.\n if (!isServer) {\n const win = window as any;\n if (!win[id]?.initialized) {\n // Client: consume cache:\n const onEntries = (...serializedEntries: Array<Serialized<TShape>>) => {\n const entries = serializedEntries.map((serialized) =>\n transformer.deserialize(serialized),\n );\n props.onEntries(entries);\n };\n\n const winStream: Array<Serialized<TShape>> = win[id] ?? [];\n\n onEntries(...winStream);\n\n // eslint-disable-next-line react-hooks/immutability\n win[id] = {\n initialized: true,\n push: onEntries,\n };\n }\n }\n // </client stuff>\n\n return (\n <context.Provider value={{ stream, id }}>\n {props.children}\n </context.Provider>\n );\n }\n\n return {\n Provider: UseClientHydrationStreamProvider,\n context,\n };\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AuthState, InstantSchemaDef, InstaQLResponse, PageInfoResponse, RuleParams, ValidQuery } from '@instantdb/core';
|
|
2
|
+
import InstantReactWebDatabase from '../InstantReactWebDatabase.ts';
|
|
3
|
+
export declare class InstantNextDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean> extends InstantReactWebDatabase<Schema, UseDates> {
|
|
4
|
+
useSuspenseQuery: <Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
|
|
5
|
+
ruleParams: RuleParams;
|
|
6
|
+
}) => {
|
|
7
|
+
data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;
|
|
8
|
+
pageInfo?: PageInfoResponse<Q>;
|
|
9
|
+
};
|
|
10
|
+
useAuth: () => AuthState;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=InstantNextDatabase.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantNextDatabase.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AAIpE,qBAAa,mBAAmB,CAC9B,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,QAAQ,SAAS,OAAO,CACxB,SAAQ,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1C,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,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;QACxD,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;KAChC,CAQC;IAEF,OAAO,QAAO,SAAS,CAoBrB;CACH"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InstantNextDatabase = void 0;
|
|
7
|
+
const InstantReactWebDatabase_ts_1 = __importDefault(require("../InstantReactWebDatabase.js"));
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const InstantSuspenseProvider_tsx_1 = require("./InstantSuspenseProvider.js");
|
|
10
|
+
class InstantNextDatabase extends InstantReactWebDatabase_ts_1.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.useSuspenseQuery = (q, opts) => {
|
|
14
|
+
const ctx = (0, react_1.useContext)(InstantSuspenseProvider_tsx_1.SuspsenseQueryContext);
|
|
15
|
+
if (!ctx) {
|
|
16
|
+
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
17
|
+
}
|
|
18
|
+
return ctx.useSuspenseQuery(q, opts);
|
|
19
|
+
};
|
|
20
|
+
this.useAuth = () => {
|
|
21
|
+
const ctx = (0, react_1.useContext)(InstantSuspenseProvider_tsx_1.SuspsenseQueryContext);
|
|
22
|
+
const realAuthResult = this._useAuth();
|
|
23
|
+
if (!ctx) {
|
|
24
|
+
return realAuthResult;
|
|
25
|
+
}
|
|
26
|
+
const { ssrUser } = ctx;
|
|
27
|
+
if (ssrUser === undefined) {
|
|
28
|
+
return realAuthResult;
|
|
29
|
+
}
|
|
30
|
+
if (realAuthResult.isLoading) {
|
|
31
|
+
return {
|
|
32
|
+
error: undefined,
|
|
33
|
+
isLoading: false,
|
|
34
|
+
user: ssrUser !== null && ssrUser !== void 0 ? ssrUser : undefined, // null -> undefined for the response
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return realAuthResult;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.InstantNextDatabase = InstantNextDatabase;
|
|
42
|
+
//# sourceMappingURL=InstantNextDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantNextDatabase.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":";;;;;;AAQA,+FAAoE;AACpE,iCAAmC;AACnC,8EAAsE;AAEtE,MAAa,mBAGX,SAAQ,oCAAyC;IAHnD;;QAIS,qBAAgB,GAAG,CACxB,CAAI,EACJ,IAEC,EAID,EAAE;YACF,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,mDAAqB,CAAC,CAAC;YAC9C,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,MAAM,IAAI,KAAK,CACb,8DAA8D,CAC/D,CAAC;YACJ,CAAC;YACD,OAAO,GAAG,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAQ,CAAC;QAC9C,CAAC,CAAC;QAEF,YAAO,GAAG,GAAc,EAAE;YACxB,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,mDAAqB,CAAC,CAAC;YAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvC,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,OAAO,cAAc,CAAC;YACxB,CAAC;YAED,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,CAAC;YACxB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC1B,OAAO,cAAc,CAAC;YACxB,CAAC;YACD,IAAI,cAAc,CAAC,SAAS,EAAE,CAAC;gBAC7B,OAAO;oBACL,KAAK,EAAE,SAAS;oBAChB,SAAS,EAAE,KAAK;oBAChB,IAAI,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,SAAS,EAAE,qCAAqC;iBAClE,CAAC;YACJ,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC;CAAA;AA3CD,kDA2CC","sourcesContent":["import {\n AuthState,\n InstantSchemaDef,\n InstaQLResponse,\n PageInfoResponse,\n RuleParams,\n ValidQuery,\n} from '@instantdb/core';\nimport InstantReactWebDatabase from '../InstantReactWebDatabase.ts';\nimport { useContext } from 'react';\nimport { SuspsenseQueryContext } from './InstantSuspenseProvider.tsx';\n\nexport class InstantNextDatabase<\n Schema extends InstantSchemaDef<any, any, any>,\n UseDates extends boolean,\n> extends InstantReactWebDatabase<Schema, UseDates> {\n public useSuspenseQuery = <Q extends ValidQuery<Q, Schema>>(\n q: Q,\n opts?: {\n ruleParams: RuleParams;\n },\n ): {\n data: InstaQLResponse<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,28 @@
|
|
|
1
|
+
import { InstantConfig, InstantSchemaDef, InstaQLResponse, PageInfoResponse, RuleParams, User, ValidQuery } from '@instantdb/core';
|
|
2
|
+
import InstantReactWebDatabase from '../InstantReactWebDatabase.ts';
|
|
3
|
+
type InstantSuspenseProviderProps<Schema extends InstantSchemaDef<any, any, any>> = {
|
|
4
|
+
nonce?: string;
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
db?: InstantReactWebDatabase<Schema, any>;
|
|
7
|
+
config?: Omit<InstantConfig<any, any>, 'schema'> & {
|
|
8
|
+
schema: string;
|
|
9
|
+
};
|
|
10
|
+
user?: User | null;
|
|
11
|
+
};
|
|
12
|
+
type SuspenseQueryContextValue = {
|
|
13
|
+
useSuspenseQuery: (query: any, opts?: SuspenseQueryOpts) => any;
|
|
14
|
+
ssrUser: User | null | undefined;
|
|
15
|
+
};
|
|
16
|
+
export declare const SuspsenseQueryContext: import("react").Context<SuspenseQueryContextValue | null>;
|
|
17
|
+
export declare const createUseSuspenseQuery: <Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean>(_db: InstantReactWebDatabase<Schema, UseDates>) => (<Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
|
|
18
|
+
ruleParams: RuleParams;
|
|
19
|
+
}) => {
|
|
20
|
+
data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;
|
|
21
|
+
pageInfo?: PageInfoResponse<Q>;
|
|
22
|
+
});
|
|
23
|
+
type SuspenseQueryOpts = {
|
|
24
|
+
ruleParams: RuleParams;
|
|
25
|
+
};
|
|
26
|
+
export declare const InstantSuspenseProvider: (props: InstantSuspenseProviderProps<any>) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=InstantSuspenseProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantSuspenseProvider.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/InstantSuspenseProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,UAAU,EACV,IAAI,EACJ,UAAU,EACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AAQpE,KAAK,4BAA4B,CAC/B,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,IAC5C;IACF,K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1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InstantSuspenseProvider = exports.createUseSuspenseQuery = exports.SuspsenseQueryContext = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
// InstantSuspenseProvider can only be used in a client context so this prevents errors from trying to use it in a server component.
|
|
7
|
+
const core_1 = require("@instantdb/core");
|
|
8
|
+
const HydrationStreamProvider_tsx_1 = require("./HydrationStreamProvider.js");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const stream = (0, HydrationStreamProvider_tsx_1.createHydrationStreamProvider)();
|
|
11
|
+
exports.SuspsenseQueryContext = (0, react_1.createContext)(null);
|
|
12
|
+
// Creates a typed useSuspense hook
|
|
13
|
+
const createUseSuspenseQuery = (_db) => {
|
|
14
|
+
return (q, opts) => {
|
|
15
|
+
const ctx = (0, react_1.useContext)(exports.SuspsenseQueryContext);
|
|
16
|
+
if (!ctx) {
|
|
17
|
+
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
18
|
+
}
|
|
19
|
+
return ctx.useSuspenseQuery(q, opts);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.createUseSuspenseQuery = createUseSuspenseQuery;
|
|
23
|
+
const InstantSuspenseProvider = (props) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const clientRef = (0, react_1.useRef)(null);
|
|
26
|
+
if (!props.db) {
|
|
27
|
+
throw new Error('Must provide either a db or config to InstantSuspenseProvider');
|
|
28
|
+
}
|
|
29
|
+
const db = (0, react_1.useRef)(props.db);
|
|
30
|
+
const [trackedKeys] = (0, react_1.useState)(() => new Set());
|
|
31
|
+
if (!clientRef.current) {
|
|
32
|
+
if (props.user && !props.user.refresh_token) {
|
|
33
|
+
throw new Error('User must have a refresh_token field. Recieved: ' +
|
|
34
|
+
JSON.stringify(props.user, null, 2));
|
|
35
|
+
}
|
|
36
|
+
clientRef.current = new core_1.FrameworkClient({
|
|
37
|
+
token: (_a = props.user) === null || _a === void 0 ? void 0 : _a.refresh_token,
|
|
38
|
+
db: db.current.core,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (HydrationStreamProvider_tsx_1.isServer) {
|
|
42
|
+
clientRef.current.subscribe((result) => {
|
|
43
|
+
const { queryHash } = result;
|
|
44
|
+
trackedKeys.add(queryHash);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const useSuspenseQuery = (query, opts) => {
|
|
48
|
+
const nonSuspenseResult = db.current.useQuery(query, Object.assign({}, opts));
|
|
49
|
+
if (nonSuspenseResult.data) {
|
|
50
|
+
return {
|
|
51
|
+
data: nonSuspenseResult.data,
|
|
52
|
+
pageInfo: nonSuspenseResult.pageInfo,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// should never happen (typeguard)
|
|
56
|
+
if (!clientRef.current) {
|
|
57
|
+
throw new Error('Client ref not set up');
|
|
58
|
+
}
|
|
59
|
+
let entry = clientRef.current.getExistingResultForQuery(query, {
|
|
60
|
+
ruleParams: opts === null || opts === void 0 ? void 0 : opts.ruleParams,
|
|
61
|
+
});
|
|
62
|
+
if (!entry) {
|
|
63
|
+
entry = clientRef.current.query(query, opts);
|
|
64
|
+
}
|
|
65
|
+
if (entry.status === 'pending') {
|
|
66
|
+
throw entry.promise;
|
|
67
|
+
}
|
|
68
|
+
if (entry.status === 'error') {
|
|
69
|
+
throw entry.error;
|
|
70
|
+
}
|
|
71
|
+
if (entry.status === 'success' && entry.type === 'session') {
|
|
72
|
+
return entry.data;
|
|
73
|
+
}
|
|
74
|
+
if (entry.status === 'success') {
|
|
75
|
+
const data = entry.data;
|
|
76
|
+
const result = clientRef.current.completeIsomorphic(query, data.triples, data.attrs, data.pageInfo);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return ((0, jsx_runtime_1.jsx)(exports.SuspsenseQueryContext.Provider, { value: { useSuspenseQuery, ssrUser: props.user }, children: (0, jsx_runtime_1.jsx)(stream.Provider, { nonce: props.nonce, onFlush: () => {
|
|
81
|
+
const toSend = [];
|
|
82
|
+
for (const [key, value] of clientRef.current.resultMap.entries()) {
|
|
83
|
+
if (trackedKeys.has(key) && value.status === 'success') {
|
|
84
|
+
toSend.push({
|
|
85
|
+
queryKey: key,
|
|
86
|
+
value: value.data,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
trackedKeys.clear();
|
|
91
|
+
return toSend;
|
|
92
|
+
}, onEntries: (entries) => {
|
|
93
|
+
entries.forEach((entry) => {
|
|
94
|
+
clientRef.current.addQueryResult(entry.queryKey, entry.value);
|
|
95
|
+
});
|
|
96
|
+
}, children: props.children }) }));
|
|
97
|
+
};
|
|
98
|
+
exports.InstantSuspenseProvider = InstantSuspenseProvider;
|
|
99
|
+
//# sourceMappingURL=InstantSuspenseProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantSuspenseProvider.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantSuspenseProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;AACb,oIAAoI;AAEpI,0CASyB;AAEzB,8EAGuC;AACvC,iCAAoE;AAepE,MAAM,MAAM,GAAG,IAAA,2DAA6B,GAAO,CAAC;AAOvC,QAAA,qBAAqB,GAChC,IAAA,qBAAa,EAAmC,IAAI,CAAC,CAAC;AAExD,mCAAmC;AAC5B,MAAM,sBAAsB,GAAG,CAIpC,GAA8C,EAS7C,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,gB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,OAAO,EACZ,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,QAAQ,CACd,CAAC;YAEF,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,CACL,uBAAC,6BAAqB,CAAC,QAAQ,IAC7B,KAAK,EAAE,EAAE,gBAAgB,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,YAEhD,uBAAC,MAAM,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;AAnHW,QAAA,uBAAuB,2BAmHlC","sourcesContent":["'use client';\n// InstantSuspenseProvider 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 InstantConfig,\n InstantSchemaDef,\n InstaQLResponse,\n PageInfoResponse,\n RuleParams,\n User,\n ValidQuery,\n} from '@instantdb/core';\nimport InstantReactWebDatabase from '../InstantReactWebDatabase.ts';\nimport {\n createHydrationStreamProvider,\n isServer,\n} from './HydrationStreamProvider.tsx';\nimport { createContext, useContext, useRef, useState } from 'react';\nimport { InstantReactAbstractDatabase } from '@instantdb/react-common';\n\ntype InstantSuspenseProviderProps<\n Schema extends InstantSchemaDef<any, any, any>,\n> = {\n nonce?: string;\n children: React.ReactNode;\n db?: InstantReactWebDatabase<Schema, any>;\n config?: Omit<InstantConfig<any, any>, 'schema'> & {\n schema: string;\n };\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 InstantSchemaDef<any, any, any>,\n UseDates extends boolean,\n>(\n _db: InstantReactWebDatabase<Schema, UseDates>,\n): (<Q extends ValidQuery<Q, Schema>>(\n q: Q,\n opts?: {\n ruleParams: RuleParams;\n },\n) => {\n data: InstaQLResponse<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\nexport const InstantSuspenseProvider = (\n props: InstantSuspenseProviderProps<any>,\n) => {\n const clientRef = useRef<FrameworkClient | null>(null);\n\n if (!props.db) {\n throw new Error(\n 'Must provide either a db or config to InstantSuspenseProvider',\n );\n }\n\n const db = useRef<InstantReactAbstractDatabase<any, any>>(props.db);\n\n const [trackedKeys] = useState(() => new Set<string>());\n\n if (!clientRef.current) {\n if (props.user && !props.user.refresh_token) {\n throw new Error(\n 'User must have a refresh_token field. Recieved: ' +\n JSON.stringify(props.user, null, 2),\n );\n }\n clientRef.current = new FrameworkClient({\n token: props.user?.refresh_token,\n db: db.current.core,\n });\n }\n\n if (isServer) {\n clientRef.current.subscribe((result) => {\n const { queryHash } = result;\n trackedKeys.add(queryHash);\n });\n }\n\n const useSuspenseQuery = (query: any, opts: SuspenseQueryOpts) => {\n const nonSuspenseResult = db.current.useQuery(query, {\n ...opts,\n });\n\n if (nonSuspenseResult.data) {\n return {\n data: nonSuspenseResult.data,\n pageInfo: nonSuspenseResult.pageInfo,\n };\n }\n\n // should never happen (typeguard)\n if (!clientRef.current) {\n throw new Error('Client ref not set up');\n }\n\n let entry = clientRef.current.getExistingResultForQuery(query, {\n ruleParams: opts?.ruleParams,\n });\n\n if (!entry) {\n entry = clientRef.current!.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' && entry.type === 'session') {\n return entry.data;\n }\n\n if (entry.status === 'success') {\n const data = entry.data;\n const result = clientRef.current.completeIsomorphic(\n query,\n data.triples,\n data.attrs,\n data.pageInfo,\n );\n\n return result;\n }\n };\n\n return (\n <SuspsenseQueryContext.Provider\n value={{ useSuspenseQuery, ssrUser: props.user }}\n >\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 @@
|
|
|
1
|
+
{"version":3,"file":"getUserFromInstantCookie.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/getUserFromInstantCookie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAGvC,eAAO,MAAM,wBAAwB,GACnC,OAAO,MAAM,KACZ,OAAO,CAAC,IAAI,GAAG,IAAI,CAKrB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getUserFromInstantCookie = void 0;
|
|
13
|
+
const headers_js_1 = require("next/headers.js");
|
|
14
|
+
const getUserFromInstantCookie = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
const cookieStore = yield (0, headers_js_1.cookies)();
|
|
16
|
+
const userJSON = cookieStore.get('instant_user_' + appId);
|
|
17
|
+
const user = userJSON ? JSON.parse(userJSON.value) : null;
|
|
18
|
+
return user;
|
|
19
|
+
});
|
|
20
|
+
exports.getUserFromInstantCookie = getUserFromInstantCookie;
|
|
21
|
+
//# sourceMappingURL=getUserFromInstantCookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserFromInstantCookie.js","sourceRoot":"","sources":["../../../src/next-ssr/getUserFromInstantCookie.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,gDAA0C;AAEnC,MAAM,wBAAwB,GAAG,CACtC,KAAa,EACS,EAAE;IACxB,MAAM,WAAW,GAAG,MAAM,IAAA,oBAAO,GAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;IAC1D,MAAM,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC,CAAA,CAAC;AAPW,QAAA,wBAAwB,4BAOnC","sourcesContent":["import { User } from '@instantdb/core';\nimport { cookies } from 'next/headers.js';\n\nexport const getUserFromInstantCookie = async (\n appId: string,\n): Promise<User | null> => {\n const cookieStore = await cookies();\n const userJSON = cookieStore.get('instant_user_' + appId);\n const user = userJSON ? JSON.parse(userJSON.value) : null;\n return user;\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlescape.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/htmlescape.ts"],"names":[],"mappings":"AAmBA,eAAO,MAAM,YAAY,QAAuB,CAAC;AAEjD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// --------------------------------------------------------------------------------
|
|
3
|
+
//
|
|
4
|
+
// copied from
|
|
5
|
+
// https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/src/server/htmlescape.ts
|
|
6
|
+
// License: https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/license.md
|
|
7
|
+
//
|
|
8
|
+
// --------------------------------------------------------------------------------
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ESCAPE_REGEX = void 0;
|
|
11
|
+
exports.htmlEscapeJsonString = htmlEscapeJsonString;
|
|
12
|
+
// This utility is based on https://github.com/zertosh/htmlescape
|
|
13
|
+
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
|
14
|
+
const ESCAPE_LOOKUP = {
|
|
15
|
+
'&': '\\u0026',
|
|
16
|
+
'>': '\\u003e',
|
|
17
|
+
'<': '\\u003c',
|
|
18
|
+
'\u2028': '\\u2028',
|
|
19
|
+
'\u2029': '\\u2029',
|
|
20
|
+
};
|
|
21
|
+
exports.ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
22
|
+
function htmlEscapeJsonString(str) {
|
|
23
|
+
return str.replace(exports.ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=htmlescape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlescape.js","sourceRoot":"","sources":["../../../src/next-ssr/htmlescape.ts"],"names":[],"mappings":";AAAA,mFAAmF;AACnF,EAAE;AACF,cAAc;AACd,yHAAyH;AACzH,oHAAoH;AACpH,EAAE;AACF,mFAAmF;;;AAenF,oDAEC;AAfD,iEAAiE;AACjE,uGAAuG;AAEvG,MAAM,aAAa,GAA2B;IAC5C,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,GAAG,EAAE,SAAS;IACd,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,SAAS;CACpB,CAAC;AAEW,QAAA,YAAY,GAAG,oBAAoB,CAAC;AAEjD,SAAgB,oBAAoB,CAAC,GAAW;IAC9C,OAAO,GAAG,CAAC,OAAO,CAAC,oBAAY,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAE,CAAC,CAAC;AACrE,CAAC","sourcesContent":["// --------------------------------------------------------------------------------\n//\n// copied from\n// https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/src/server/htmlescape.ts\n// License: https://github.com/vercel/next.js/blob/6bc07792a4462a4bf921a72ab30dc4ab2c4e1bda/packages/next/license.md\n//\n// --------------------------------------------------------------------------------\n\n// This utility is based on https://github.com/zertosh/htmlescape\n// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE\n\nconst ESCAPE_LOOKUP: Record<string, string> = {\n '&': '\\\\u0026',\n '>': '\\\\u003e',\n '<': '\\\\u003c',\n '\\u2028': '\\\\u2028',\n '\\u2029': '\\\\u2029',\n};\n\nexport const ESCAPE_REGEX = /[&><\\u2028\\u2029]/g;\n\nexport function htmlEscapeJsonString(str: string): string {\n return str.replace(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]!);\n}\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InstantConfig, InstantSchemaDef, InstantUnknownSchema } from '@instantdb/core';
|
|
2
|
+
import { InstantNextDatabase } from './InstantNextDatabase.tsx';
|
|
3
|
+
export { getUserFromInstantCookie } from './getUserFromInstantCookie.ts';
|
|
4
|
+
export { InstantNextDatabase } from './InstantNextDatabase.tsx';
|
|
5
|
+
export { InstantSuspenseProvider } from './InstantSuspenseProvider.tsx';
|
|
6
|
+
export { createInstantRouteHandler } from '@instantdb/core';
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* The first step: init your application!
|
|
10
|
+
*
|
|
11
|
+
* Visit https://instantdb.com/dash to get your `appId` :)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { init } from "@instantdb/react"
|
|
15
|
+
*
|
|
16
|
+
* const db = init({ appId: "my-app-id" })
|
|
17
|
+
*
|
|
18
|
+
* // You can also provide a schema for type safety and editor autocomplete!
|
|
19
|
+
*
|
|
20
|
+
* import { init } from "@instantdb/react"
|
|
21
|
+
* import schema from ""../instant.schema.ts";
|
|
22
|
+
*
|
|
23
|
+
* const db = init({ appId: "my-app-id", schema })
|
|
24
|
+
*
|
|
25
|
+
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
26
|
+
*/
|
|
27
|
+
export declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: InstantConfig<Schema, UseDates>): InstantNextDatabase<Schema, UseDates>;
|
|
28
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,IAAI,CAClB,MAAM,SAAS,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,oBAAoB,EACrE,QAAQ,SAAS,OAAO,GAAG,KAAK,EAEhC,MAAM,EAAE,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,GACtC,mBAAmB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAIvC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createInstantRouteHandler = exports.InstantSuspenseProvider = exports.InstantNextDatabase = exports.getUserFromInstantCookie = void 0;
|
|
7
|
+
exports.init = init;
|
|
8
|
+
const version_ts_1 = __importDefault(require("../version.js"));
|
|
9
|
+
const InstantNextDatabase_tsx_1 = require("./InstantNextDatabase.js");
|
|
10
|
+
var getUserFromInstantCookie_ts_1 = require("./getUserFromInstantCookie.js");
|
|
11
|
+
Object.defineProperty(exports, "getUserFromInstantCookie", { enumerable: true, get: function () { return getUserFromInstantCookie_ts_1.getUserFromInstantCookie; } });
|
|
12
|
+
var InstantNextDatabase_tsx_2 = require("./InstantNextDatabase.js");
|
|
13
|
+
Object.defineProperty(exports, "InstantNextDatabase", { enumerable: true, get: function () { return InstantNextDatabase_tsx_2.InstantNextDatabase; } });
|
|
14
|
+
var InstantSuspenseProvider_tsx_1 = require("./InstantSuspenseProvider.js");
|
|
15
|
+
Object.defineProperty(exports, "InstantSuspenseProvider", { enumerable: true, get: function () { return InstantSuspenseProvider_tsx_1.InstantSuspenseProvider; } });
|
|
16
|
+
var core_1 = require("@instantdb/core");
|
|
17
|
+
Object.defineProperty(exports, "createInstantRouteHandler", { enumerable: true, get: function () { return core_1.createInstantRouteHandler; } });
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* The first step: init your application!
|
|
21
|
+
*
|
|
22
|
+
* Visit https://instantdb.com/dash to get your `appId` :)
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* import { init } from "@instantdb/react"
|
|
26
|
+
*
|
|
27
|
+
* const db = init({ appId: "my-app-id" })
|
|
28
|
+
*
|
|
29
|
+
* // You can also provide a schema for type safety and editor autocomplete!
|
|
30
|
+
*
|
|
31
|
+
* import { init } from "@instantdb/react"
|
|
32
|
+
* import schema from ""../instant.schema.ts";
|
|
33
|
+
*
|
|
34
|
+
* const db = init({ appId: "my-app-id", schema })
|
|
35
|
+
*
|
|
36
|
+
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
37
|
+
*/
|
|
38
|
+
function init(config) {
|
|
39
|
+
return new InstantNextDatabase_tsx_1.InstantNextDatabase(config, {
|
|
40
|
+
'@instantdb/react': version_ts_1.default,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next-ssr/index.tsx"],"names":[],"mappings":";;;;;;AAqCA,oBASC;AAxCD,+DAAoC;AAEpC,sEAAgE;AAEhE,6EAAyE;AAAhE,uIAAA,wBAAwB,OAAA;AAEjC,oEAAgE;AAAvD,8HAAA,mBAAmB,OAAA;AAC5B,4EAAwE;AAA/D,sIAAA,uBAAuB,OAAA;AAEhC,wCAA4D;AAAnD,iHAAA,yBAAyB,OAAA;AAElC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,IAAI,CAIlB,MAAuC;IAEvC,OAAO,IAAI,6CAAmB,CAAmB,MAAM,EAAE;QACvD,kBAAkB,EAAE,oBAAO;KAC5B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n InstantConfig,\n InstantSchemaDef,\n InstantUnknownSchema,\n} from '@instantdb/core';\n\nimport version from '../version.ts';\n\nimport { InstantNextDatabase } from './InstantNextDatabase.tsx';\n\nexport { getUserFromInstantCookie } from './getUserFromInstantCookie.ts';\n\nexport { InstantNextDatabase } from './InstantNextDatabase.tsx';\nexport { InstantSuspenseProvider } from './InstantSuspenseProvider.tsx';\n\nexport { createInstantRouteHandler } from '@instantdb/core';\n\n/**\n *\n * The first step: init your application!\n *\n * Visit https://instantdb.com/dash to get your `appId` :)\n *\n * @example\n * import { init } from \"@instantdb/react\"\n *\n * const db = init({ appId: \"my-app-id\" })\n *\n * // You can also provide a schema for type safety and editor autocomplete!\n *\n * import { init } from \"@instantdb/react\"\n * import schema from \"\"../instant.schema.ts\";\n *\n * const db = init({ appId: \"my-app-id\", schema })\n *\n * // To learn more: https://instantdb.com/docs/modeling-data\n */\nexport function init<\n Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema,\n UseDates extends boolean = false,\n>(\n config: InstantConfig<Schema, UseDates>,\n): InstantNextDatabase<Schema, UseDates> {\n return new InstantNextDatabase<Schema, UseDates>(config, {\n '@instantdb/react': version,\n });\n}\n"]}
|