@instantdb/react 0.22.90-experimental.drewh-ssr.20312174628.1 → 0.22.90-experimental.drewh-ssr.20347747146.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/index.d.ts +2 -2
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +1 -2
- package/dist/commonjs/index.js.map +1 -1
- 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 +43 -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 +98 -0
- package/dist/commonjs/next-ssr/InstantSuspenseProvider.js.map +1 -0
- package/dist/commonjs/next-ssr/getUserOnServer.d.ts +2 -0
- package/dist/commonjs/next-ssr/getUserOnServer.d.ts.map +1 -0
- package/dist/commonjs/next-ssr/getUserOnServer.js +21 -0
- package/dist/commonjs/next-ssr/getUserOnServer.js.map +1 -0
- package/dist/commonjs/next-ssr/index.d.ts +6 -28
- package/dist/commonjs/next-ssr/index.d.ts.map +1 -1
- package/dist/commonjs/next-ssr/index.js +11 -126
- package/dist/commonjs/next-ssr/index.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- 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 +36 -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 +93 -0
- package/dist/esm/next-ssr/InstantSuspenseProvider.js.map +1 -0
- package/dist/esm/next-ssr/getUserOnServer.d.ts +2 -0
- package/dist/esm/next-ssr/getUserOnServer.d.ts.map +1 -0
- package/dist/esm/next-ssr/getUserOnServer.js +17 -0
- package/dist/esm/next-ssr/getUserOnServer.js.map +1 -0
- package/dist/esm/next-ssr/index.d.ts +6 -28
- package/dist/esm/next-ssr/index.d.ts.map +1 -1
- package/dist/esm/next-ssr/index.js +5 -121
- package/dist/esm/next-ssr/index.js.map +1 -1
- package/dist/standalone/index.js +1322 -1383
- package/dist/standalone/index.umd.cjs +13 -13
- package/package.json +4 -4
- package/src/index.ts +0 -2
- package/src/next-ssr/InstantNextDatabase.tsx +57 -0
- package/src/next-ssr/InstantSuspenseProvider.tsx +187 -0
- package/src/next-ssr/getUserOnServer.ts +8 -0
- package/src/next-ssr/index.tsx +6 -223
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -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,eAAe,EAGf,0BAA0B,EAG1B,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACT,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EAGf,KAAK,YAAY,EAGjB,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,WAAW,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AK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,GACzB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,12 +2,12 @@ import { id, tx, lookup, i,
|
|
|
2
2
|
// error
|
|
3
3
|
InstantAPIError,
|
|
4
4
|
// sync table enums
|
|
5
|
-
SyncTableCallbackEventType,
|
|
5
|
+
SyncTableCallbackEventType, } from '@instantdb/core';
|
|
6
6
|
import { InstantReactAbstractDatabase } from '@instantdb/react-common';
|
|
7
7
|
import InstantReactWebDatabase from "./InstantReactWebDatabase.js";
|
|
8
8
|
import { init, init_experimental } from "./init.js";
|
|
9
9
|
import { Cursors } from "./Cursors.js";
|
|
10
|
-
export { id, tx, lookup, init, init_experimental,
|
|
10
|
+
export { id, tx, lookup, init, init_experimental, InstantReactWebDatabase, Cursors, i,
|
|
11
11
|
// error
|
|
12
12
|
InstantAPIError,
|
|
13
13
|
// internal
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC;AAED,QAAQ;AACR,eAAe;AAEf,mBAAmB;AACnB,0BAA0B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,EAAE,EACF,EAAE,EACF,MAAM,EACN,CAAC;AAED,QAAQ;AACR,eAAe;AAEf,mBAAmB;AACnB,0BAA0B,GA2E3B,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,uBAAuB,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAe,CAAC;AAExC,OAAO,EACL,EAAE,EACF,EAAE,EACF,MAAM,EACN,IAAI,EACJ,iBAAiB,EACjB,uBAAuB,EACvB,OAAO,EACP,CAAC;AAED,QAAQ;AACR,eAAe;AAEf,WAAW;AACX,4BAA4B;AAE5B,mBAAmB;AACnB,0BAA0B,GA2E3B,CAAC","sourcesContent":["import {\n id,\n tx,\n lookup,\n i,\n\n // error\n InstantAPIError,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n type QueryResponse,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantObject,\n type InstantEntity,\n type InstantSchemaDatabase,\n type InstantUnknownSchemaDef,\n type IInstantDatabase,\n type User,\n type AuthState,\n type Query,\n type Config,\n type InstaQLParams,\n type ConnectionStatus,\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 InstantGraph,\n type InstantConfig,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type InstaQLEntity,\n type InstaQLFields,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type TransactionChunk,\n type InstantUnknownSchema,\n type InstantSchemaDef,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\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 // 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} from '@instantdb/core';\n\nimport { InstantReactAbstractDatabase } from '@instantdb/react-common';\nimport InstantReactWebDatabase from './InstantReactWebDatabase.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 InstantReactWebDatabase,\n Cursors,\n i,\n\n // error\n InstantAPIError,\n\n // internal\n InstantReactAbstractDatabase,\n\n // sync table enums\n SyncTableCallbackEventType,\n\n // types\n type Config,\n type InstantConfig,\n type InstantUnknownSchemaDef,\n type Query,\n type QueryResponse,\n type InstantObject,\n type User,\n type AuthState,\n type ConnectionStatus,\n type InstantQuery,\n type InstantQueryResult,\n type InstantSchema,\n type InstantEntity,\n type InstantSchemaDatabase,\n type IInstantDatabase,\n type InstaQLParams,\n type ValidQuery,\n type InstaQLFields,\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 InstantGraph,\n type LinkAttrDef,\n type LinkDef,\n type LinksDef,\n type ResolveAttrs,\n type ValueTypes,\n type InstaQLEntity,\n type InstaQLResult,\n type InstaQLEntitySubquery,\n type RoomsOf,\n type RoomsDef,\n type TransactionChunk,\n type PresenceOf,\n type TopicsOf,\n type TopicOf,\n type RoomHandle,\n type InstantUnknownSchema,\n type InstantSchemaDef,\n type BackwardsCompatibleSchema,\n type InstantRules,\n type UpdateParams,\n type LinkParams,\n type CreateParams,\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 // 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"]}
|
|
@@ -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":"AACA,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,36 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import InstantReactWebDatabase from "../InstantReactWebDatabase.js";
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
import { SuspsenseQueryContext } from "./InstantSuspenseProvider.js";
|
|
5
|
+
export class InstantNextDatabase extends InstantReactWebDatabase {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
this.useSuspenseQuery = (q, opts) => {
|
|
9
|
+
const ctx = useContext(SuspsenseQueryContext);
|
|
10
|
+
if (!ctx) {
|
|
11
|
+
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
12
|
+
}
|
|
13
|
+
return ctx.useSuspenseQuery(q, opts);
|
|
14
|
+
};
|
|
15
|
+
this.useAuth = () => {
|
|
16
|
+
const ctx = useContext(SuspsenseQueryContext);
|
|
17
|
+
const realAuthResult = this._useAuth();
|
|
18
|
+
if (!ctx) {
|
|
19
|
+
return realAuthResult;
|
|
20
|
+
}
|
|
21
|
+
const { ssrUser } = ctx;
|
|
22
|
+
if (ssrUser === undefined) {
|
|
23
|
+
return realAuthResult;
|
|
24
|
+
}
|
|
25
|
+
if (realAuthResult.isLoading) {
|
|
26
|
+
return {
|
|
27
|
+
error: undefined,
|
|
28
|
+
isLoading: false,
|
|
29
|
+
user: ssrUser !== null && ssrUser !== void 0 ? ssrUser : undefined, // null -> undefined for the response
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return realAuthResult;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=InstantNextDatabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InstantNextDatabase.js","sourceRoot":"","sources":["../../../src/next-ssr/InstantNextDatabase.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AASb,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;IAHnD;;QAIS,qBAAgB,GAAG,CACxB,CAAI,EACJ,IAEC,EAID,EAAE;YACF,MAAM,GAAG,GAAG,UAAU,CAAC,qBAAqB,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,UAAU,CAAC,qBAAqB,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","sourcesContent":["'use client';\nimport {\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":"AACA,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,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,EAAE,CAAC,EAAE,uBAAuB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1C,MAAM,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,GAAG;QACjD,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,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,gBAAgB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAC9C,QAAQ,SAAS,OAAO,EAExB,KAAK,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,KAC7C,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,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IACxD,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;CAChC,CAUA,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACvB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,OAAO,4BAA4B,CAAC,GAAG,CAAC,4CAkHzC,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { FrameworkClient, } from '@instantdb/core';
|
|
4
|
+
import { createHydrationStreamProvider, isServer, } from "./HydrationStreamProvider.js";
|
|
5
|
+
import { createContext, useContext, useRef, useState } from 'react';
|
|
6
|
+
const stream = createHydrationStreamProvider();
|
|
7
|
+
export const SuspsenseQueryContext = createContext(null);
|
|
8
|
+
// Creates a typed useSuspense hook
|
|
9
|
+
export const createUseSuspenseQuery = (_db) => {
|
|
10
|
+
return (q, opts) => {
|
|
11
|
+
const ctx = useContext(SuspsenseQueryContext);
|
|
12
|
+
if (!ctx) {
|
|
13
|
+
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
14
|
+
}
|
|
15
|
+
return ctx.useSuspenseQuery(q, opts);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const InstantSuspenseProvider = (props) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const clientRef = useRef(null);
|
|
21
|
+
if (!props.db) {
|
|
22
|
+
throw new Error('Must provide either a db or config to InstantSuspenseProvider');
|
|
23
|
+
}
|
|
24
|
+
const db = useRef(props.db);
|
|
25
|
+
const [trackedKeys] = useState(() => new Set());
|
|
26
|
+
if (!clientRef.current) {
|
|
27
|
+
if (props.user && !props.user.refresh_token) {
|
|
28
|
+
throw new Error('User must have a refresh_token field. Recieved: ' +
|
|
29
|
+
JSON.stringify(props.user, null, 2));
|
|
30
|
+
}
|
|
31
|
+
clientRef.current = new FrameworkClient({
|
|
32
|
+
token: (_a = props.user) === null || _a === void 0 ? void 0 : _a.refresh_token,
|
|
33
|
+
db: db.current.core,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (isServer) {
|
|
37
|
+
clientRef.current.subscribe((result) => {
|
|
38
|
+
const { queryHash } = result;
|
|
39
|
+
trackedKeys.add(queryHash);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const useSuspenseQuery = (query, opts) => {
|
|
43
|
+
const nonSuspenseResult = db.current.useQuery(query, Object.assign({}, opts));
|
|
44
|
+
if (nonSuspenseResult.data) {
|
|
45
|
+
return {
|
|
46
|
+
data: nonSuspenseResult.data,
|
|
47
|
+
pageInfo: nonSuspenseResult.pageInfo,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// should never happen (typeguard)
|
|
51
|
+
if (!clientRef.current) {
|
|
52
|
+
throw new Error('Client ref not set up');
|
|
53
|
+
}
|
|
54
|
+
let entry = clientRef.current.getExistingResultForQuery(query, {
|
|
55
|
+
ruleParams: opts === null || opts === void 0 ? void 0 : opts.ruleParams,
|
|
56
|
+
});
|
|
57
|
+
if (!entry) {
|
|
58
|
+
entry = clientRef.current.query(query, opts);
|
|
59
|
+
}
|
|
60
|
+
if (entry.status === 'pending') {
|
|
61
|
+
throw entry.promise;
|
|
62
|
+
}
|
|
63
|
+
if (entry.status === 'error') {
|
|
64
|
+
throw entry.error;
|
|
65
|
+
}
|
|
66
|
+
if (entry.status === 'success' && entry.type === 'session') {
|
|
67
|
+
return entry.data;
|
|
68
|
+
}
|
|
69
|
+
if (entry.status === 'success') {
|
|
70
|
+
const data = entry.data;
|
|
71
|
+
const result = clientRef.current.completeIsomorphic(query, data.triples, data.attrs, data.pageInfo);
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return (_jsx(SuspsenseQueryContext.Provider, { value: { useSuspenseQuery, ssrUser: props.user }, children: _jsx(stream.Provider, { nonce: props.nonce, onFlush: () => {
|
|
76
|
+
const toSend = [];
|
|
77
|
+
for (const [key, value] of clientRef.current.resultMap.entries()) {
|
|
78
|
+
if (trackedKeys.has(key) && value.status === 'success') {
|
|
79
|
+
toSend.push({
|
|
80
|
+
queryKey: key,
|
|
81
|
+
value: value.data,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
trackedKeys.clear();
|
|
86
|
+
return toSend;
|
|
87
|
+
}, onEntries: (entries) => {
|
|
88
|
+
entries.forEach((entry) => {
|
|
89
|
+
clientRef.current.addQueryResult(entry.queryKey, entry.value);
|
|
90
|
+
});
|
|
91
|
+
}, children: props.children }) }));
|
|
92
|
+
};
|
|
93
|
+
//# 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,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;;IACF,MAAM,SAAS,GAAG,MAAM,CAAyB,IAAI,CAAC,CAAC;IAEvD,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,GAAG,MAAM,CAAyC,KAAK,CAAC,EAAE,CAAC,CAAC;IAEpE,MAAM,CAAC,WA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AAC,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","sourcesContent":["'use client';\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":"getUserOnServer.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/getUserOnServer.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,oBAK3B,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
import { cookies } from 'next/headers.js';
|
|
11
|
+
export const getUserOnServer = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
|
+
const cookieStore = yield cookies();
|
|
13
|
+
const userJSON = cookieStore.get('instant_user');
|
|
14
|
+
const user = userJSON ? JSON.parse(userJSON.value) : null;
|
|
15
|
+
return user;
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=getUserOnServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getUserOnServer.js","sourceRoot":"","sources":["../../../src/next-ssr/getUserOnServer.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,GAAS,EAAE;IACxC,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAC;IACpC,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACjD,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","sourcesContent":["import { cookies } from 'next/headers.js';\n\nexport const getUserOnServer = async () => {\n const cookieStore = await cookies();\n const userJSON = cookieStore.get('instant_user');\n const user = userJSON ? JSON.parse(userJSON.value) : null;\n return user;\n};\n"]}
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
config?: Omit<InstantConfig<any, any>, 'schema'> & {
|
|
8
|
-
schema: string;
|
|
9
|
-
};
|
|
10
|
-
user?: User | null;
|
|
11
|
-
};
|
|
12
|
-
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?: {
|
|
13
|
-
ruleParams: RuleParams;
|
|
14
|
-
}) => {
|
|
15
|
-
data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;
|
|
16
|
-
pageInfo?: PageInfoResponse<Q>;
|
|
17
|
-
});
|
|
18
|
-
export declare const InstantSuspenseProvider: (props: InstantSuspenseProviderProps<any>) => import("react/jsx-runtime").JSX.Element;
|
|
1
|
+
import { InstantConfig, InstantSchemaDef, InstantUnknownSchema } from '@instantdb/core';
|
|
2
|
+
import { InstantNextDatabase } from './InstantNextDatabase.tsx';
|
|
3
|
+
export { getUserOnServer } from './getUserOnServer.ts';
|
|
4
|
+
export { InstantNextDatabase } from './InstantNextDatabase.tsx';
|
|
5
|
+
export { InstantSuspenseProvider } from './InstantSuspenseProvider.tsx';
|
|
6
|
+
export { createInstantRouteHandler } from '@instantdb/core';
|
|
19
7
|
/**
|
|
20
8
|
*
|
|
21
9
|
* The first step: init your application!
|
|
@@ -37,14 +25,4 @@ export declare const InstantSuspenseProvider: (props: InstantSuspenseProviderPro
|
|
|
37
25
|
* // To learn more: https://instantdb.com/docs/modeling-data
|
|
38
26
|
*/
|
|
39
27
|
export declare function init<Schema extends InstantSchemaDef<any, any, any> = InstantUnknownSchema, UseDates extends boolean = false>(config: InstantConfig<Schema, UseDates>): InstantNextDatabase<Schema, UseDates>;
|
|
40
|
-
export declare class InstantNextDatabase<Schema extends InstantSchemaDef<any, any, any>, UseDates extends boolean> extends InstantReactWebDatabase<Schema, UseDates> {
|
|
41
|
-
useSuspenseQuery: <Q extends ValidQuery<Q, Schema>>(q: Q, opts?: {
|
|
42
|
-
ruleParams: RuleParams;
|
|
43
|
-
}) => {
|
|
44
|
-
data: InstaQLResponse<Schema, Q, NonNullable<UseDates>>;
|
|
45
|
-
pageInfo?: PageInfoResponse<Q>;
|
|
46
|
-
};
|
|
47
|
-
useAuth: () => AuthState;
|
|
48
|
-
}
|
|
49
|
-
export {};
|
|
50
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/next-ssr/index.tsx"],"names":[],"mappings":"
|
|
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,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,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"}
|
|
@@ -1,94 +1,9 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { FrameworkClient, } from '@instantdb/core';
|
|
4
|
-
import { createContext, useContext, useRef, useState } from 'react';
|
|
5
|
-
import { createHydrationStreamProvider, isServer, } from "./HydrationStreamProvider.js";
|
|
6
1
|
import version from "../version.js";
|
|
7
|
-
import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
12
|
-
return (q, opts) => {
|
|
13
|
-
const ctx = useContext(SuspsenseQueryContext);
|
|
14
|
-
if (!ctx) {
|
|
15
|
-
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
16
|
-
}
|
|
17
|
-
return ctx.useSuspenseQuery(q, opts);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
export const InstantSuspenseProvider = (props) => {
|
|
21
|
-
var _a;
|
|
22
|
-
const clientRef = useRef(null);
|
|
23
|
-
if (!props.db) {
|
|
24
|
-
throw new Error('Must provide either a db or config to InstantSuspenseProvider');
|
|
25
|
-
}
|
|
26
|
-
const db = useRef(props.db);
|
|
27
|
-
const [trackedKeys] = useState(() => new Set());
|
|
28
|
-
if (!clientRef.current) {
|
|
29
|
-
if (props.user && !props.user.refresh_token) {
|
|
30
|
-
throw new Error('User must have a refresh_token field. Recieved: ' +
|
|
31
|
-
JSON.stringify(props.user, null, 2));
|
|
32
|
-
}
|
|
33
|
-
clientRef.current = new FrameworkClient({
|
|
34
|
-
token: (_a = props.user) === null || _a === void 0 ? void 0 : _a.refresh_token,
|
|
35
|
-
db: db.current.core,
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
if (isServer) {
|
|
39
|
-
clientRef.current.subscribe((result) => {
|
|
40
|
-
const { queryHash } = result;
|
|
41
|
-
trackedKeys.add(queryHash);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
const useSuspenseQuery = (query, opts) => {
|
|
45
|
-
const nonSuspenseResult = db.current.useQuery(query, Object.assign({}, opts));
|
|
46
|
-
if (nonSuspenseResult.data) {
|
|
47
|
-
return {
|
|
48
|
-
data: nonSuspenseResult.data,
|
|
49
|
-
pageInfo: nonSuspenseResult.pageInfo,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
// should never happen (typeguard)
|
|
53
|
-
if (!clientRef.current) {
|
|
54
|
-
throw new Error('Client ref not set up');
|
|
55
|
-
}
|
|
56
|
-
let entry = clientRef.current.getExistingResultForQuery(query, {
|
|
57
|
-
ruleParams: opts === null || opts === void 0 ? void 0 : opts.ruleParams,
|
|
58
|
-
});
|
|
59
|
-
if (!entry) {
|
|
60
|
-
entry = clientRef.current.query(query, opts);
|
|
61
|
-
}
|
|
62
|
-
if (entry.status === 'pending') {
|
|
63
|
-
throw entry.promise;
|
|
64
|
-
}
|
|
65
|
-
if (entry.status === 'error') {
|
|
66
|
-
throw entry.error;
|
|
67
|
-
}
|
|
68
|
-
if (entry.status === 'success') {
|
|
69
|
-
const data = entry.data;
|
|
70
|
-
const result = clientRef.current.completeIsomorphic(query, data.triples, data.attrs, data.pageInfo);
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return (_jsx(SuspsenseQueryContext.Provider, { value: { useSuspenseQuery, ssrUser: props.user }, children: _jsx(stream.Provider, { nonce: props.nonce, onFlush: () => {
|
|
75
|
-
const toSend = [];
|
|
76
|
-
for (const [key, value] of clientRef.current.resultMap.entries()) {
|
|
77
|
-
if (trackedKeys.has(key) && value.status === 'success') {
|
|
78
|
-
toSend.push({
|
|
79
|
-
queryKey: key,
|
|
80
|
-
value: value.data,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
trackedKeys.clear();
|
|
85
|
-
return toSend;
|
|
86
|
-
}, onEntries: (entries) => {
|
|
87
|
-
entries.forEach((entry) => {
|
|
88
|
-
clientRef.current.addQueryResult(entry.queryKey, entry.value);
|
|
89
|
-
});
|
|
90
|
-
}, children: props.children }) }));
|
|
91
|
-
};
|
|
2
|
+
import { InstantNextDatabase } from "./InstantNextDatabase.js";
|
|
3
|
+
export { getUserOnServer } from "./getUserOnServer.js";
|
|
4
|
+
export { InstantNextDatabase } from "./InstantNextDatabase.js";
|
|
5
|
+
export { InstantSuspenseProvider } from "./InstantSuspenseProvider.js";
|
|
6
|
+
export { createInstantRouteHandler } from '@instantdb/core';
|
|
92
7
|
/**
|
|
93
8
|
*
|
|
94
9
|
* The first step: init your application!
|
|
@@ -114,35 +29,4 @@ export function init(config) {
|
|
|
114
29
|
'@instantdb/react': version,
|
|
115
30
|
});
|
|
116
31
|
}
|
|
117
|
-
export class InstantNextDatabase extends InstantReactWebDatabase {
|
|
118
|
-
constructor() {
|
|
119
|
-
super(...arguments);
|
|
120
|
-
this.useSuspenseQuery = (q, opts) => {
|
|
121
|
-
const ctx = useContext(SuspsenseQueryContext);
|
|
122
|
-
if (!ctx) {
|
|
123
|
-
throw new Error('useSuspenseQuery must be used within a SuspenseQueryProvider');
|
|
124
|
-
}
|
|
125
|
-
return ctx.useSuspenseQuery(q, opts);
|
|
126
|
-
};
|
|
127
|
-
this.useAuth = () => {
|
|
128
|
-
const ctx = useContext(SuspsenseQueryContext);
|
|
129
|
-
const realAuthResult = this._useAuth();
|
|
130
|
-
if (!ctx) {
|
|
131
|
-
return realAuthResult;
|
|
132
|
-
}
|
|
133
|
-
const { ssrUser } = ctx;
|
|
134
|
-
if (ssrUser === undefined) {
|
|
135
|
-
return realAuthResult;
|
|
136
|
-
}
|
|
137
|
-
if (realAuthResult.isLoading) {
|
|
138
|
-
return {
|
|
139
|
-
error: undefined,
|
|
140
|
-
isLoading: false,
|
|
141
|
-
user: ssrUser !== null && ssrUser !== void 0 ? ssrUser : undefined, // null -> undefined for the response
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
return realAuthResult;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next-ssr/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb,OAAO,EAEL,eAAe,GAShB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,O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,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,SAAS,EAAE,qCAAqC;iBAClE,CAAC;YACJ,CAAC;YAED,OAAO,cAAc,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC;CAAA","sourcesContent":["'use client';\nimport {\n AuthState,\n FrameworkClient,\n InstantConfig,\n InstantSchemaDef,\n InstantUnknownSchema,\n InstaQLResponse,\n PageInfoResponse,\n RuleParams,\n User,\n ValidQuery,\n} from '@instantdb/core';\nimport { createContext, useContext, useRef, useState } from 'react';\nimport {\n createHydrationStreamProvider,\n isServer,\n} from './HydrationStreamProvider.tsx';\nimport version from '../version.ts';\n\nimport InstantReactWebDatabase from '../InstantReactWebDatabase.ts';\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\nconst SuspsenseQueryContext = createContext<SuspenseQueryContextValue | null>(\n null,\n);\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') {\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\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\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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/next-ssr/index.tsx"],"names":[],"mappings":"AAMA,OAAO,OAAO,MAAM,eAAe,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA2B,CAAC;AAEhE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA2B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA+B,CAAC;AAExE,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,IAAI,CAIlB,MAAuC;IAEvC,OAAO,IAAI,mBAAmB,CAAmB,MAAM,EAAE;QACvD,kBAAkB,EAAE,OAAO;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 { getUserOnServer } from './getUserOnServer.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"]}
|