@instantdb/react 0.22.99-experimental.add-user-perm-rules.20792844601.1 → 0.22.99-experimental.add-user-perm-rules.20792984656.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/Cursors.js +17 -5
- package/dist/commonjs/Cursors.js.map +1 -1
- package/dist/commonjs/InstantReactWebDatabase.js +1 -1
- package/dist/commonjs/InstantReactWebDatabase.js.map +1 -1
- package/dist/commonjs/__types__/typesTests.js +4 -4
- package/dist/commonjs/__types__/typesTests.js.map +1 -1
- package/dist/commonjs/init.js +4 -2
- package/dist/commonjs/init.js.map +1 -1
- package/dist/commonjs/next-ssr/HydrationStreamProvider.js +8 -13
- package/dist/commonjs/next-ssr/HydrationStreamProvider.js.map +1 -1
- package/dist/commonjs/next-ssr/InstantNextDatabase.js +25 -28
- package/dist/commonjs/next-ssr/InstantNextDatabase.js.map +1 -1
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.js +5 -4
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.js.map +1 -1
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.js +3 -12
- package/dist/commonjs/next-ssr/getUserFromInstantCookie.js.map +1 -1
- package/dist/esm/Cursors.js +17 -5
- package/dist/esm/Cursors.js.map +1 -1
- package/dist/esm/InstantReactWebDatabase.js +2 -3
- package/dist/esm/InstantReactWebDatabase.js.map +1 -1
- package/dist/esm/__types__/typesTests.js +4 -4
- package/dist/esm/__types__/typesTests.js.map +1 -1
- package/dist/esm/init.js +4 -2
- package/dist/esm/init.js.map +1 -1
- package/dist/esm/next-ssr/HydrationStreamProvider.js +8 -13
- package/dist/esm/next-ssr/HydrationStreamProvider.js.map +1 -1
- package/dist/esm/next-ssr/InstantNextDatabase.js +25 -28
- package/dist/esm/next-ssr/InstantNextDatabase.js.map +1 -1
- package/dist/esm/next-ssr/InstantSuspenseProvider.js +5 -4
- package/dist/esm/next-ssr/InstantSuspenseProvider.js.map +1 -1
- package/dist/esm/next-ssr/getUserFromInstantCookie.js +3 -12
- package/dist/esm/next-ssr/getUserFromInstantCookie.js.map +1 -1
- package/dist/standalone/index.js +4103 -3825
- package/dist/standalone/index.umd.cjs +16 -16
- package/package.json +4 -4
|
@@ -14,7 +14,7 @@ function _testUseDatesTest() {
|
|
|
14
14
|
useDateObjects: true,
|
|
15
15
|
});
|
|
16
16
|
const { data } = db.useQuery({ tbl: {} });
|
|
17
|
-
const item = data
|
|
17
|
+
const item = data?.tbl[0];
|
|
18
18
|
if (item) {
|
|
19
19
|
}
|
|
20
20
|
}
|
|
@@ -25,7 +25,7 @@ function _testUseDatesFalseTest() {
|
|
|
25
25
|
useDateObjects: false,
|
|
26
26
|
});
|
|
27
27
|
const { data } = db.useQuery({ tbl: {} });
|
|
28
|
-
const item = data
|
|
28
|
+
const item = data?.tbl[0];
|
|
29
29
|
if (item) {
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -35,7 +35,7 @@ function _testUseDatesUndefinedTest() {
|
|
|
35
35
|
appId: '123',
|
|
36
36
|
});
|
|
37
37
|
const { data } = db.useQuery({ tbl: {} });
|
|
38
|
-
const item = data
|
|
38
|
+
const item = data?.tbl[0];
|
|
39
39
|
if (item) {
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -44,7 +44,7 @@ function _testDataNoSchema() {
|
|
|
44
44
|
appId: '123',
|
|
45
45
|
});
|
|
46
46
|
const { data } = db.useQuery({ tbl: {} });
|
|
47
|
-
const item = data
|
|
47
|
+
const item = data?.tbl[0];
|
|
48
48
|
if (item) {
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typesTests.js","sourceRoot":"","sources":["../../../src/__types__/typesTests.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;IACtB,QAAQ,EA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;AAED,SAAS,sBAAsB;IAC7B,MAAM,EAAE,GAAG,IAAI,CAAC;QACd,MAAM;QACN,KAAK,EAAE,KAAK;QACZ,cAAc,EAAE,KAAK;KACtB,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,IAAI,EAAE,CAAC;IASX,CAAC;AACH,CAAC;AAED,SAAS,0BAA0B;IACjC,MAAM,EAAE,GAAG,IAAI,CAAC;QACd,MAAM;QACN,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,IAAI,EAAE,CAAC;IASX,CAAC;AACH,CAAC;AAED,SAAS,iBAAiB;IACxB,MAAM,EAAE,GAAG,IAAI,CAAC;QACd,KAAK,EAAE,KAAK;KACb,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,IAAI,EAAE,CAAC;IAGX,CAAC;AACH,CAAC","sourcesContent":["import type { Equal, Expect, IsAny, NotAny } from './typeUtils.ts';\nimport { i, init } from '../index.ts';\n\nconst schema = i.schema({\n entities: {\n tbl: i.entity({\n d: i.date().indexed(),\n dOptional: i.date().optional(),\n }),\n },\n});\n\nfunction _testUseDatesTest() {\n const db = init({\n schema,\n appId: '123',\n useDateObjects: true,\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<NotAny<t>>, Expect<Equal<t, Date>>];\n\n type tOpt = typeof item.dOptional;\n type _cases_2 = [\n Expect<NotAny<tOpt>>,\n Expect<Equal<tOpt, Date | undefined>>,\n ];\n }\n}\n\nfunction _testUseDatesFalseTest() {\n const db = init({\n schema,\n appId: '123',\n useDateObjects: false,\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];\n\n type tOpt = typeof item.dOptional;\n type _cases_2 = [\n Expect<NotAny<tOpt>>,\n Expect<Equal<tOpt, string | number | undefined>>,\n ];\n }\n}\n\nfunction _testUseDatesUndefinedTest() {\n const db = init({\n schema,\n appId: '123',\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<NotAny<t>>, Expect<Equal<t, string | number>>];\n\n type tOpt = typeof item.dOptional;\n type _cases_2 = [\n Expect<NotAny<tOpt>>,\n Expect<Equal<tOpt, string | number | undefined>>,\n ];\n }\n}\n\nfunction _testDataNoSchema() {\n const db = init({\n appId: '123',\n });\n\n const { data } = db.useQuery({ tbl: {} });\n const item = data?.tbl[0];\n if (item) {\n type t = typeof item.d;\n type _cases = [Expect<IsAny<t>>, Expect<Equal<typeof item.id, string>>];\n }\n}\n"]}
|
package/dist/esm/init.js
CHANGED
|
@@ -24,8 +24,10 @@ export function init(
|
|
|
24
24
|
// Allows config with missing `useDateObjects`, but keeps `UseDates`
|
|
25
25
|
// as a non-nullable in the InstantConfig type.
|
|
26
26
|
config) {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const configStrict = {
|
|
28
|
+
...config,
|
|
29
|
+
useDateObjects: (config.useDateObjects ?? false),
|
|
30
|
+
};
|
|
29
31
|
return new InstantReactWebDatabase(configStrict, {
|
|
30
32
|
'@instantdb/react': version,
|
|
31
33
|
});
|
package/dist/esm/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAMA,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,IAAI;AAIlB,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/init.ts"],"names":[],"mappings":"AAMA,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,OAAO,MAAM,cAAc,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,IAAI;AAIlB,oEAAoE;AACpE,+CAA+C;AAC/C,MAEC;IAED,MAAM,YAAY,GAAG;QACnB,GAAG,MAAM;QACT,cAAc,EAAE,CAAC,MAAM,CAAC,cAAc,IAAI,KAAK,CAAa;KAC7D,CAAC;IACF,OAAO,IAAI,uBAAuB,CAIhC,YAAY,EAAE;QACd,kBAAkB,EAAE,OAAO;KAC5B,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC","sourcesContent":["import type {\n InstantConfig,\n InstantSchemaDef,\n InstantUnknownSchema,\n} from '@instantdb/core';\n\nimport InstantReactWebDatabase from './InstantReactWebDatabase.ts';\nimport version from './version.ts';\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 // Allows config with missing `useDateObjects`, but keeps `UseDates`\n // as a non-nullable in the InstantConfig type.\n config: Omit<InstantConfig<Schema, UseDates>, 'useDateObjects'> & {\n useDateObjects?: UseDates;\n },\n): InstantReactWebDatabase<Schema, UseDates, InstantConfig<Schema, UseDates>> {\n const configStrict = {\n ...config,\n useDateObjects: (config.useDateObjects ?? false) as UseDates,\n };\n return new InstantReactWebDatabase<\n Schema,\n UseDates,\n InstantConfig<Schema, UseDates>\n >(configStrict, {\n '@instantdb/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 \"@instantdb/react\"\n * const db = init_experimental({ ... });\n *\n * // After\n * import { init } from \"@instantdb/react\"\n * const db = init({ ... });\n */\nexport const init_experimental = init;\n"]}
|
|
@@ -22,18 +22,14 @@ export function createHydrationStreamProvider() {
|
|
|
22
22
|
* - We replace `window[id]` with a `push()`-method that will be called whenever new entries are received
|
|
23
23
|
**/
|
|
24
24
|
function UseClientHydrationStreamProvider(props) {
|
|
25
|
-
var _a, _b;
|
|
26
25
|
// unique id for the cache provider
|
|
27
26
|
const id = `__RQ${React.useId()}`;
|
|
28
27
|
const idJSON = htmlEscapeJsonString(JSON.stringify(id));
|
|
29
|
-
const [transformer] = React.useState(() => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
deserialize: (obj) => obj,
|
|
35
|
-
});
|
|
36
|
-
});
|
|
28
|
+
const [transformer] = React.useState(() => (props.transformer ?? {
|
|
29
|
+
// noop
|
|
30
|
+
serialize: (obj) => obj,
|
|
31
|
+
deserialize: (obj) => obj,
|
|
32
|
+
}));
|
|
37
33
|
// <server stuff>
|
|
38
34
|
const [stream] = React.useState(() => {
|
|
39
35
|
if (!isServer) {
|
|
@@ -47,9 +43,8 @@ export function createHydrationStreamProvider() {
|
|
|
47
43
|
});
|
|
48
44
|
const count = React.useRef(0);
|
|
49
45
|
useServerInsertedHTML(() => {
|
|
50
|
-
var _a, _b;
|
|
51
46
|
// This only happens on the server
|
|
52
|
-
stream.push(...(
|
|
47
|
+
stream.push(...(props.onFlush?.() ?? []));
|
|
53
48
|
if (!stream.length) {
|
|
54
49
|
return null;
|
|
55
50
|
}
|
|
@@ -77,13 +72,13 @@ export function createHydrationStreamProvider() {
|
|
|
77
72
|
// if the data has not yet been hydrated.
|
|
78
73
|
if (!isServer) {
|
|
79
74
|
const win = window;
|
|
80
|
-
if (!
|
|
75
|
+
if (!win[id]?.initialized) {
|
|
81
76
|
// Client: consume cache:
|
|
82
77
|
const onEntries = (...serializedEntries) => {
|
|
83
78
|
const entries = serializedEntries.map((serialized) => transformer.deserialize(serialized));
|
|
84
79
|
props.onEntries(entries);
|
|
85
80
|
};
|
|
86
|
-
const winStream =
|
|
81
|
+
const winStream = win[id] ?? [];
|
|
87
82
|
onEntries(...winStream);
|
|
88
83
|
// eslint-disable-next-line react-hooks/immutability
|
|
89
84
|
win[id] = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationStreamProvider.js","sourceRoot":"","sources":["../../../src/next-ssr/HydrationStreamProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,qGAAqG;AACrG,6IAA6I;AAC7I,sCAAsC;AACtC,qIAAqI;AACrI,kIAAkI;AAElI,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,IAAI,UAAU,CAAC;AAE9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,gBAAgB,GAAG,MAAM,CAAC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,CAAC;QACH,kBAAkB;QAElB,iBAAiB;QACjB,2EAA2E;QAC3E,qEAAqE;QACrE,6EAA6E;QAC7E,yCAAyC;QACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,GAAG,GAAG,MAAa,CAAC;YAC1B,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,WAAW,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,GAAG,CAAC,EAAE,CAAC,IAAI,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,KAAC,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"]}
|
|
@@ -2,34 +2,31 @@ import InstantReactWebDatabase from "../InstantReactWebDatabase.js";
|
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { SuspsenseQueryContext } from "./InstantSuspenseProvider.js";
|
|
4
4
|
export class InstantNextDatabase extends InstantReactWebDatabase {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const realAuthResult = this._useAuth();
|
|
17
|
-
if (!ctx) {
|
|
18
|
-
return realAuthResult;
|
|
19
|
-
}
|
|
20
|
-
const { ssrUser } = ctx;
|
|
21
|
-
if (ssrUser === undefined) {
|
|
22
|
-
return realAuthResult;
|
|
23
|
-
}
|
|
24
|
-
if (realAuthResult.isLoading) {
|
|
25
|
-
return {
|
|
26
|
-
error: undefined,
|
|
27
|
-
isLoading: false,
|
|
28
|
-
user: ssrUser !== null && ssrUser !== void 0 ? ssrUser : undefined, // null -> undefined for the response
|
|
29
|
-
};
|
|
30
|
-
}
|
|
5
|
+
useSuspenseQuery = (q, opts) => {
|
|
6
|
+
const ctx = useContext(SuspsenseQueryContext);
|
|
7
|
+
if (!ctx) {
|
|
8
|
+
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
9
|
+
}
|
|
10
|
+
return ctx.useSuspenseQuery(q, opts);
|
|
11
|
+
};
|
|
12
|
+
useAuth = () => {
|
|
13
|
+
const ctx = useContext(SuspsenseQueryContext);
|
|
14
|
+
const realAuthResult = this._useAuth();
|
|
15
|
+
if (!ctx) {
|
|
31
16
|
return realAuthResult;
|
|
32
|
-
}
|
|
33
|
-
|
|
17
|
+
}
|
|
18
|
+
const { ssrUser } = ctx;
|
|
19
|
+
if (ssrUser === undefined) {
|
|
20
|
+
return realAuthResult;
|
|
21
|
+
}
|
|
22
|
+
if (realAuthResult.isLoading) {
|
|
23
|
+
return {
|
|
24
|
+
error: undefined,
|
|
25
|
+
isLoading: false,
|
|
26
|
+
user: ssrUser ?? undefined, // null -> undefined for the response
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return realAuthResult;
|
|
30
|
+
};
|
|
34
31
|
}
|
|
35
32
|
//# sourceMappingURL=InstantNextDatabase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstantNextDatabase.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":"AAQA,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA+B,CAAC;AAEtE,MAAM,OAAO,mBAGX,SAAQ,uBAAyC;
|
|
1
|
+
{"version":3,"file":"InstantNextDatabase.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":"AAQA,OAAO,uBAAuB,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA+B,CAAC;AAEtE,MAAM,OAAO,mBAGX,SAAQ,uBAAyC;IAC1C,gBAAgB,GAAG,CACxB,CAAI,EACJ,IAEC,EAID,EAAE;QACF,MAAM,GAAG,GAAG,UAAU,CAAC,qBAAqB,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,UAAU,CAAC,qBAAqB,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","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"]}
|
|
@@ -17,7 +17,6 @@ export const createUseSuspenseQuery = (_db) => {
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
export const InstantSuspenseProvider = (props) => {
|
|
20
|
-
var _a;
|
|
21
20
|
const clientRef = useRef(null);
|
|
22
21
|
if (!props.db) {
|
|
23
22
|
throw new Error('Must provide either a db or config to InstantSuspenseProvider');
|
|
@@ -30,7 +29,7 @@ export const InstantSuspenseProvider = (props) => {
|
|
|
30
29
|
JSON.stringify(props.user, null, 2));
|
|
31
30
|
}
|
|
32
31
|
clientRef.current = new FrameworkClient({
|
|
33
|
-
token:
|
|
32
|
+
token: props.user?.refresh_token,
|
|
34
33
|
db: db.current.core,
|
|
35
34
|
});
|
|
36
35
|
}
|
|
@@ -41,7 +40,9 @@ export const InstantSuspenseProvider = (props) => {
|
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
const useSuspenseQuery = (query, opts) => {
|
|
44
|
-
const nonSuspenseResult = db.current.useQuery(query,
|
|
43
|
+
const nonSuspenseResult = db.current.useQuery(query, {
|
|
44
|
+
...opts,
|
|
45
|
+
});
|
|
45
46
|
if (nonSuspenseResult.data) {
|
|
46
47
|
return {
|
|
47
48
|
data: nonSuspenseResult.data,
|
|
@@ -53,7 +54,7 @@ export const InstantSuspenseProvider = (props) => {
|
|
|
53
54
|
throw new Error('Client ref not set up');
|
|
54
55
|
}
|
|
55
56
|
let entry = clientRef.current.getExistingResultForQuery(query, {
|
|
56
|
-
ruleParams: opts
|
|
57
|
+
ruleParams: opts?.ruleParams,
|
|
57
58
|
});
|
|
58
59
|
if (!entry) {
|
|
59
60
|
entry = clientRef.current.query(query, opts);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InstantSuspenseProvider.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantSuspenseProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,oIAAoI;AAEpI,OAAO,EACL,eAAe,GAQhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,6BAA6B,EAC7B,QAAQ,GACT,MAAM,8BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAepE,MAAM,MAAM,GAAG,6BAA6B,EAAO,CAAC;AAOpD,MAAM,CAAC,MAAM,qBAAqB,GAChC,aAAa,CAAmC,IAAI,CAAC,CAAC;AAExD,mCAAmC;AACnC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAIpC,GAA8C,EAS7C,EAAE;IACH,OAAO,CAAkC,CAAM,EAAE,IAAS,EAAE,EAAE;QAC5D,MAAM,GAAG,GAAG,UAAU,CAAC,qBAAqB,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;AAMF,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,KAAwC,EACxC,EAAE
|
|
1
|
+
{"version":3,"file":"InstantSuspenseProvider.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantSuspenseProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,oIAAoI;AAEpI,OAAO,EACL,eAAe,GAQhB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,6BAA6B,EAC7B,QAAQ,GACT,MAAM,8BAA+B,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,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AO,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","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"]}
|
|
@@ -1,17 +1,8 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { cookies } from 'next/headers.js';
|
|
11
|
-
export const getUserFromInstantCookie = (appId) =>
|
|
12
|
-
const cookieStore =
|
|
2
|
+
export const getUserFromInstantCookie = async (appId) => {
|
|
3
|
+
const cookieStore = await cookies();
|
|
13
4
|
const userJSON = cookieStore.get('instant_user_' + appId);
|
|
14
5
|
const user = userJSON ? JSON.parse(userJSON.value) : null;
|
|
15
6
|
return user;
|
|
16
|
-
}
|
|
7
|
+
};
|
|
17
8
|
//# sourceMappingURL=getUserFromInstantCookie.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getUserFromInstantCookie.js","sourceRoot":"","sources":["../../../src/next-ssr/getUserFromInstantCookie.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getUserFromInstantCookie.js","sourceRoot":"","sources":["../../../src/next-ssr/getUserFromInstantCookie.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,KAAa,EACS,EAAE;IACxB,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,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,CAAC","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"]}
|