modelence 0.18.0-dev.1 → 0.18.0-dev.3
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/bin/modelence.js +1 -1
- package/dist/bin/modelence.js.map +1 -1
- package/dist/chunk-C26FT6MS.js +19 -0
- package/dist/chunk-C26FT6MS.js.map +1 -0
- package/dist/chunk-DRDY7GOT.js +2 -0
- package/dist/chunk-DRDY7GOT.js.map +1 -0
- package/dist/chunk-GZI4X3CV.js +3 -0
- package/dist/chunk-GZI4X3CV.js.map +1 -0
- package/dist/chunk-Q3SEQPTY.js +3 -0
- package/dist/chunk-Q3SEQPTY.js.map +1 -0
- package/dist/chunk-R6OOTUGO.js +2 -0
- package/dist/chunk-R6OOTUGO.js.map +1 -0
- package/dist/chunk-SABBG2XG.js +2 -0
- package/dist/chunk-SABBG2XG.js.map +1 -0
- package/dist/{chunk-S77LRZU6.js → chunk-X6CSJYLY.js} +2 -2
- package/dist/{chunk-S77LRZU6.js.map → chunk-X6CSJYLY.js.map} +1 -1
- package/dist/client.d.ts +34 -2
- package/dist/client.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{package-XQQF6NGT.js → package-2YZCMUAD.js} +2 -2
- package/dist/{package-XQQF6NGT.js.map → package-2YZCMUAD.js.map} +1 -1
- package/dist/render-DLVPZOA6.js +2 -0
- package/dist/render-DLVPZOA6.js.map +1 -0
- package/dist/renderApp-KKWGQKMM.js +2 -0
- package/dist/{renderApp-3FQ6KUQ2.js.map → renderApp-KKWGQKMM.js.map} +1 -1
- package/dist/server-GBPVLS3G.js +2 -0
- package/dist/{server-JB4DTGBT.js.map → server-GBPVLS3G.js.map} +1 -1
- package/dist/server.d.ts +137 -46
- package/dist/server.js +1 -1
- package/dist/transport-ZSBKZIXH.js +2 -0
- package/dist/{transport-BOPYDAVH.js.map → transport-ZSBKZIXH.js.map} +1 -1
- package/dist/{types-mkbhnQN2.d.ts → types-BT2k9L7Q.d.ts} +2 -2
- package/dist/{types-DV0J5rPI.d.ts → types-DANNMU1V.d.ts} +6 -1
- package/dist/types.d.ts +2 -2
- package/package.json +8 -8
- package/dist/chunk-IJ5BS7PM.js +0 -2
- package/dist/chunk-IJ5BS7PM.js.map +0 -1
- package/dist/chunk-JBTEZOY2.js +0 -2
- package/dist/chunk-JBTEZOY2.js.map +0 -1
- package/dist/chunk-KU4GANYW.js +0 -3
- package/dist/chunk-KU4GANYW.js.map +0 -1
- package/dist/chunk-LDVLXJLS.js +0 -3
- package/dist/chunk-LDVLXJLS.js.map +0 -1
- package/dist/chunk-S2E4OO6G.js +0 -19
- package/dist/chunk-S2E4OO6G.js.map +0 -1
- package/dist/chunk-VFOGVWJK.js +0 -2
- package/dist/chunk-VFOGVWJK.js.map +0 -1
- package/dist/render-57TPXKHI.js +0 -2
- package/dist/render-57TPXKHI.js.map +0 -1
- package/dist/renderApp-3FQ6KUQ2.js +0 -2
- package/dist/server-JB4DTGBT.js +0 -2
- package/dist/transport-BOPYDAVH.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/module.ts","../src/system/client.ts","../src/websocket/clientChannel.ts","../src/files/client.ts","../src/client.ts","../src/client/renderApp.tsx"],"names":["createClientModule","moduleName","key","getConfig","name","rest","args","callMethod","getArgs","pageParam","systemConfig","ClientChannel","category","onMessage","getWebsocketClientProvider","id","uploadFile","file","filePath","contentType","visibility","url","fields","resolvedFilePath","formData","value","uploadResponse","deleteFile","downloadFile","getFileUrl","AppProvider","React","SSR_STATE_SCRIPT_ID","readSsrState","node","e","SNAPSHOT_KEY","setSnapshot","snapshot","_getSsrSnapshot","renderApp","options","loadingElement","routesElement","favicon","errorHandler","router","setErrorHandler","ssrState","isHydrating","hydrateSession","startSessionHeartbeat","container","routedTree","tree","jsx","ModelenceQueryProvider","ReactDOM","link","newLink"],"mappings":"2LAuFO,SAASA,CAAAA,CAA8CC,CAAAA,CAAoB,CAChF,OAAO,CACL,SAAA,CACEC,C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A,CAAS,aAAA,CAAc,MAAM,CAAA,CAC7CA,CAAAA,CAAQ,GAAA,CAAM,MAAA,CACdA,CAAAA,CAAQ,IAAA,CAAOf,CAAAA,CACf,QAAA,CAAS,IAAA,CAAK,WAAA,CAAYe,CAAO,EACnC,CAGF,CACF","file":"chunk-S77LRZU6.js","sourcesContent":["'use client';\n\nimport type { ObjectId } from 'mongodb';\nimport type { ConfigParams, ConfigType, ValueType } from '../config/types';\nimport { callMethod, type MethodArgs } from './method';\nimport type { AnyMethodShape } from '../methods/types';\n\n// Pulls the config store value without importing server-side code\nimport { getConfig as _getClientConfig } from '../config/client';\n\n// ── type helpers ─────────────────────────────────────────────────────────────\n\n/**\n * Recursively maps ObjectId → string to match the sanitized runtime values\n * sent over the wire. Dates are preserved (revived via typeMap on the client).\n */\ntype Sanitized<T> = T extends ObjectId\n ? string\n : T extends Date\n ? Date\n : T extends (infer U)[]\n ? Sanitized<U>[]\n : T extends object\n ? { [K in keyof T]: Sanitized<T[K]> }\n : T;\n\ntype ExtractArgs<M> = M extends (args: infer A, ...rest: any[]) => any // eslint-disable-line @typescript-eslint/no-explicit-any\n ? A\n : M extends { handler: (args: infer A, ...rest: any[]) => any } // eslint-disable-line @typescript-eslint/no-explicit-any\n ? A\n : MethodArgs;\n\ntype ExtractResult<M> = M extends (...args: any[]) => Promise<infer R> // eslint-disable-line @typescript-eslint/no-explicit-any\n ? Sanitized<R>\n : M extends { handler: (...args: any[]) => Promise<infer R> } // eslint-disable-line @typescript-eslint/no-explicit-any\n ? Sanitized<R>\n : unknown;\n\ntype PublicKeyOf<TSchema extends Record<string, ConfigParams>> = {\n [K in keyof TSchema as TSchema[K] extends ConfigParams<ConfigType, true>\n ? string & K\n : never]: ValueType<TSchema[K]['type']>;\n};\n\ntype AnyModule = {\n name: string;\n configSchema: Record<string, ConfigParams>;\n queries: Record<string, AnyMethodShape>;\n mutations: Record<string, AnyMethodShape>;\n};\n\n// ── createClientModule ────────────────────────────────────────────────────────\n\n/**\n * Creates a typed client accessor for a module's public configs, queries, and mutations.\n *\n * Use `import type` to reference the module so no server code is bundled on the client.\n * Arg and return types for queries and mutations are inferred automatically from the\n * server-side handler signatures.\n *\n * @param moduleName - The module's name as passed to `new Module(name, ...)`.\n *\n * @example\n * ```ts\n * // src/client/payments.ts\n * import type paymentsModule from '../server/payments';\n * import { createClientModule } from 'modelence/client';\n *\n * export const payments = createClientModule<typeof paymentsModule>('payments');\n * ```\n *\n * ```ts\n * // src/components/Checkout.tsx\n * import { useQuery, useMutation } from '@tanstack/react-query';\n * import { payments } from '../client/payments';\n *\n * // Typed config — public keys only, private and secret keys excluded:\n * const currency = payments.getConfig('currency'); // string | undefined\n *\n * // Typed query — pass directly to useQuery:\n * const { data: products } = useQuery(payments.query('getProducts', { page: 1 }));\n *\n * // Typed mutation — pass directly to useMutation:\n * const { mutate: charge } = useMutation(payments.mutation('charge'));\n * charge({ amount: 100 }); // args typed from handler signature\n * ```\n */\nexport function createClientModule<TModule extends AnyModule>(moduleName: string) {\n return {\n getConfig<K extends keyof PublicKeyOf<TModule['configSchema']> & string>(\n key: K\n ): PublicKeyOf<TModule['configSchema']>[K] | undefined {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return _getClientConfig(`${moduleName}.${key}`) as any;\n },\n\n query<K extends keyof TModule['queries'] & string>(\n name: K,\n ...rest: {} extends ExtractArgs<TModule['queries'][K]>\n ? [args?: ExtractArgs<TModule['queries'][K]>]\n : [args: ExtractArgs<TModule['queries'][K]>]\n ) {\n const args = (rest[0] ?? {}) as ExtractArgs<TModule['queries'][K]>;\n return {\n queryKey: [moduleName, name, args] as const,\n queryFn: (): Promise<ExtractResult<TModule['queries'][K]>> =>\n callMethod<ExtractResult<TModule['queries'][K]>>(\n `${moduleName}.${name}`,\n args as MethodArgs\n ),\n };\n },\n\n mutation<K extends keyof TModule['mutations'] & string>(name: K) {\n return {\n mutationFn: (\n args: ExtractArgs<TModule['mutations'][K]>\n ): Promise<ExtractResult<TModule['mutations'][K]>> =>\n callMethod<ExtractResult<TModule['mutations'][K]>>(\n `${moduleName}.${name}`,\n args as MethodArgs\n ),\n };\n },\n\n /**\n * Returns options for `useInfiniteQuery`. The `getArgs` callback receives the\n * current `pageParam` and returns the args to pass to the query handler.\n * Spread the result into `useInfiniteQuery` alongside `getNextPageParam`.\n *\n * Annotate the `pageParam` type in the callback so TypeScript can infer the\n * page param type — no manual generic needed on `useInfiniteQuery`.\n */\n infiniteQuery<K extends keyof TModule['queries'] & string, TPageParam = unknown>(\n name: K,\n getArgs: (pageParam: TPageParam | undefined) => ExtractArgs<TModule['queries'][K]>\n ) {\n return {\n queryKey: [moduleName, name, 'infinite', getArgs(undefined)] as const,\n // Included so TanStack infers TPageParam from the callback type, not from a bare `undefined`.\n initialPageParam: undefined as TPageParam | undefined,\n queryFn: ({\n pageParam,\n }: {\n pageParam: TPageParam | undefined;\n }): Promise<ExtractResult<TModule['queries'][K]>> =>\n callMethod<ExtractResult<TModule['queries'][K]>>(\n `${moduleName}.${name}`,\n getArgs(pageParam) as MethodArgs\n ),\n };\n },\n };\n}\n","import type systemModule from './index';\nimport { createClientModule } from '../client/module';\n\nexport const systemConfig = createClientModule<typeof systemModule>('_system');\n","import { getWebsocketClientProvider } from './client';\n\nexport class ClientChannel<T = unknown> {\n public readonly category: string;\n private readonly onMessage: (data: T) => void;\n\n constructor(category: string, onMessage: (data: T) => void) {\n this.category = category;\n this.onMessage = onMessage;\n }\n\n init() {\n getWebsocketClientProvider()?.on({\n category: this.category,\n listener: this.onMessage,\n });\n }\n\n joinChannel(id: string) {\n getWebsocketClientProvider()?.joinChannel({\n category: this.category,\n id,\n });\n }\n\n leaveChannel(id: string) {\n getWebsocketClientProvider()?.leaveChannel({\n category: this.category,\n id,\n });\n }\n}\n","import { callMethod } from '../client/method';\nimport type { FileVisibility, GetUploadUrlResult } from './types';\n\ntype UploadFileParams = {\n filePath: string;\n contentType: string;\n visibility: FileVisibility;\n};\n\ntype UploadFileResult = {\n filePath: string;\n};\n\nexport async function uploadFile(\n file: File | Blob,\n { filePath, contentType, visibility }: UploadFileParams\n): Promise<UploadFileResult> {\n const {\n url,\n fields,\n filePath: resolvedFilePath,\n } = await callMethod<GetUploadUrlResult>('_system.files.getUploadUrl', {\n filePath,\n contentType,\n visibility,\n });\n\n const formData = new FormData();\n for (const [key, value] of Object.entries(fields)) {\n formData.append(key, value);\n }\n formData.append('file', file);\n\n const uploadResponse = await fetch(url, {\n method: 'POST',\n body: formData,\n });\n\n if (!uploadResponse.ok) {\n throw new Error(`Failed to upload file: HTTP status: ${uploadResponse.status}`);\n }\n\n return { filePath: resolvedFilePath };\n}\n\nexport async function deleteFile(filePath: string): Promise<void> {\n await callMethod('_system.files.deleteFile', { filePath });\n}\n\nexport async function downloadFile(filePath: string): Promise<{ downloadUrl: string }> {\n return callMethod('_system.files.downloadFile', { filePath });\n}\n\nexport async function getFileUrl(filePath: string): Promise<{ url: string }> {\n return callMethod('_system.files.getFileUrl', { filePath });\n}\n","import React from 'react';\n\nimport { AppProvider as OriginalAppProvider } from './client/AppProvider';\n\nexport { getConfig } from './config/client';\nexport { createClientModule } from './client/module';\nexport type { ValueType } from './config/types';\nexport { systemConfig } from './system/client';\n\nexport const AppProvider =\n 'useClient' in React\n ? // @ts-ignore: React.useClient only exists in Next.js\n React.useClient(OriginalAppProvider)\n : OriginalAppProvider;\n\nexport { renderApp } from './client/renderApp';\nexport { ModelenceQueryProvider } from './client/queryProvider';\nexport {\n modelenceQuery,\n modelenceLiveQuery,\n modelenceMutation,\n createQueryKey,\n connectModelenceQueryClient,\n disconnectModelenceQueryClient,\n ModelenceQueryClient,\n type ModelenceQueryKey,\n} from './client/query';\nexport { callMethod, MethodError, type MethodArgs } from './client/method';\nexport { useSession } from './client/session';\nexport {\n signupWithPassword,\n loginWithPassword,\n verifyEmail,\n updateProfile,\n resendEmailVerification,\n logout,\n sendResetPasswordToken,\n resetPassword,\n linkOAuthProvider,\n unlinkOAuthProvider,\n type UserInfo,\n} from './auth/client';\nexport {\n getWebsocketClientProvider,\n setWebsocketClientProvider,\n startWebsockets,\n subscribeLiveQuery,\n} from './websocket/client';\nexport { ClientChannel } from './websocket/clientChannel';\nexport { getLocalStorageSession } from './client/localStorage';\nexport { uploadFile, deleteFile, downloadFile, getFileUrl } from './files/client';\n","import React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport { AppProvider } from '../client';\nimport { setErrorHandler, ErrorHandler } from './errorHandler';\nimport { hydrateSession, startSessionHeartbeat, type SessionInitPayload } from './session';\nimport { ModelenceQueryProvider } from './queryProvider';\n\nconst SSR_STATE_SCRIPT_ID = '__MODELENCE_STATE__';\n\ntype SsrState = {\n session?: SessionInitPayload;\n};\n\nfunction readSsrState(): SsrState | null {\n if (typeof document === 'undefined') {\n return null;\n }\n\n const node = document.getElementById(SSR_STATE_SCRIPT_ID);\n if (!node) {\n return null;\n }\n\n try {\n return JSON.parse(node.textContent ?? '') as SsrState;\n } catch (e) {\n console.error('Modelence: failed to parse SSR state', e);\n return null;\n }\n}\n\nexport type SsrRouter = (props: {\n children: React.ReactNode;\n location?: string;\n}) => React.ReactElement;\n\nexport interface RenderAppOptions {\n loadingElement: React.ReactNode;\n routesElement: React.ReactNode;\n favicon?: string;\n errorHandler?: ErrorHandler;\n router?: SsrRouter;\n}\n\n// Shared on globalThis because Vite's ssrLoadModule loads the user's entry\n// in a separate module graph from the framework runtime.\nconst SNAPSHOT_KEY = '__modelence_ssr_snapshot__';\n\ntype GlobalWithSnapshot = typeof globalThis & {\n [SNAPSHOT_KEY]?: RenderAppOptions | null;\n};\n\nfunction setSnapshot(snapshot: RenderAppOptions | null) {\n (globalThis as GlobalWithSnapshot)[SNAPSHOT_KEY] = snapshot;\n}\n\n/** @internal Used by the SSR runtime after evaluating the user's entry. */\nexport function _getSsrSnapshot(): RenderAppOptions | null {\n return (globalThis as GlobalWithSnapshot)[SNAPSHOT_KEY] ?? null;\n}\n\nexport function renderApp(options: RenderAppOptions) {\n if (typeof window === 'undefined') {\n setSnapshot(options);\n return;\n }\n\n const { loadingElement, routesElement, favicon, errorHandler, router } = options;\n\n if (errorHandler) {\n setErrorHandler(errorHandler);\n }\n\n window.addEventListener('unload', () => {\n // Empty 'unload' handler prevents bfcache in most browsers.\n });\n\n // ORDER MATTERS: hydrate session BEFORE building the React tree / calling\n // hydrateRoot, so `isSessionInitialized()` is true on the first render and\n // AppProvider's initial `isLoading` matches the server-rendered output.\n const ssrState = readSsrState();\n const isHydrating = ssrState !== null;\n if (ssrState?.session) {\n hydrateSession(ssrState.session);\n startSessionHeartbeat();\n }\n\n const container = document.getElementById('root')!;\n const routedTree = router ? router({ children: routesElement }) : routesElement;\n const tree = (\n <React.StrictMode>\n <AppProvider loadingElement={loadingElement}>\n <ModelenceQueryProvider>{routedTree}</ModelenceQueryProvider>\n </AppProvider>\n </React.StrictMode>\n );\n\n if (isHydrating) {\n ReactDOM.hydrateRoot(container, tree);\n } else {\n ReactDOM.createRoot(container).render(tree);\n }\n\n if (favicon) {\n const link = document.querySelector(\"link[rel~='icon']\") as HTMLLinkElement;\n if (!link) {\n const newLink = document.createElement('link');\n newLink.rel = 'icon';\n newLink.href = favicon;\n document.head.appendChild(newLink);\n } else {\n link.href = favicon;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client/module.ts","../src/system/client.ts","../src/websocket/clientChannel.ts","../src/files/client.ts","../src/client.ts","../src/client/renderApp.tsx"],"names":["createClientModule","moduleName","key","getConfig","name","rest","args","callMethod","getArgs","pageParam","systemConfig","ClientChannel","category","onMessage","getWebsocketClientProvider","id","uploadFile","file","filePath","contentType","visibility","url","fields","resolvedFilePath","formData","value","uploadResponse","deleteFile","downloadFile","getFileUrl","AppProvider","React","SSR_STATE_SCRIPT_ID","readSsrState","node","e","SNAPSHOT_KEY","setSnapshot","snapshot","_getSsrSnapshot","renderApp","options","loadingElement","routesElement","favicon","errorHandler","router","setErrorHandler","ssrState","isHydrating","hydrateSession","startSessionHeartbeat","container","routedTree","t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Ac,mBAAmB,CAAA,CACvD,GAAKA,CAAAA,CAMHA,CAAAA,CAAK,IAAA,CAAOd,CAAAA,CAAAA,KANH,CACT,IAAMe,CAAAA,CAAU,QAAA,CAAS,aAAA,CAAc,MAAM,CAAA,CAC7CA,CAAAA,CAAQ,GAAA,CAAM,MAAA,CACdA,CAAAA,CAAQ,IAAA,CAAOf,CAAAA,CACf,QAAA,CAAS,IAAA,CAAK,WAAA,CAAYe,CAAO,EACnC,CAGF,CACF","file":"chunk-X6CSJYLY.js","sourcesContent":["'use client';\n\nimport type { ObjectId } from 'mongodb';\nimport type { ConfigParams, ConfigType, ValueType } from '../config/types';\nimport { callMethod, type MethodArgs } from './method';\nimport type { AnyMethodShape } from '../methods/types';\n\n// Pulls the config store value without importing server-side code\nimport { getConfig as _getClientConfig } from '../config/client';\n\n// ── type helpers ─────────────────────────────────────────────────────────────\n\n/**\n * Recursively maps ObjectId → string to match the sanitized runtime values\n * sent over the wire. Dates are preserved (revived via typeMap on the client).\n */\ntype Sanitized<T> = T extends ObjectId\n ? string\n : T extends Date\n ? Date\n : T extends (infer U)[]\n ? Sanitized<U>[]\n : T extends object\n ? { [K in keyof T]: Sanitized<T[K]> }\n : T;\n\ntype ExtractArgs<M> = M extends (args: infer A, ...rest: any[]) => any // eslint-disable-line @typescript-eslint/no-explicit-any\n ? A\n : M extends { handler: (args: infer A, ...rest: any[]) => any } // eslint-disable-line @typescript-eslint/no-explicit-any\n ? A\n : MethodArgs;\n\ntype ExtractResult<M> = M extends (...args: any[]) => Promise<infer R> // eslint-disable-line @typescript-eslint/no-explicit-any\n ? Sanitized<R>\n : M extends { handler: (...args: any[]) => Promise<infer R> } // eslint-disable-line @typescript-eslint/no-explicit-any\n ? Sanitized<R>\n : unknown;\n\ntype PublicKeyOf<TSchema extends Record<string, ConfigParams>> = {\n [K in keyof TSchema as TSchema[K] extends ConfigParams<ConfigType, true>\n ? string & K\n : never]: ValueType<TSchema[K]['type']>;\n};\n\ntype AnyModule = {\n name: string;\n configSchema: Record<string, ConfigParams>;\n queries: Record<string, AnyMethodShape>;\n mutations: Record<string, AnyMethodShape>;\n};\n\n// ── createClientModule ────────────────────────────────────────────────────────\n\n/**\n * Creates a typed client accessor for a module's public configs, queries, and mutations.\n *\n * Use `import type` to reference the module so no server code is bundled on the client.\n * Arg and return types for queries and mutations are inferred automatically from the\n * server-side handler signatures.\n *\n * @param moduleName - The module's name as passed to `new Module(name, ...)`.\n *\n * @example\n * ```ts\n * // src/client/payments.ts\n * import type paymentsModule from '../server/payments';\n * import { createClientModule } from 'modelence/client';\n *\n * export const payments = createClientModule<typeof paymentsModule>('payments');\n * ```\n *\n * ```ts\n * // src/components/Checkout.tsx\n * import { useQuery, useMutation } from '@tanstack/react-query';\n * import { payments } from '../client/payments';\n *\n * // Typed config — public keys only, private and secret keys excluded:\n * const currency = payments.getConfig('currency'); // string | undefined\n *\n * // Typed query — pass directly to useQuery:\n * const { data: products } = useQuery(payments.query('getProducts', { page: 1 }));\n *\n * // Typed mutation — pass directly to useMutation:\n * const { mutate: charge } = useMutation(payments.mutation('charge'));\n * charge({ amount: 100 }); // args typed from handler signature\n * ```\n */\nexport function createClientModule<TModule extends AnyModule>(moduleName: string) {\n return {\n getConfig<K extends keyof PublicKeyOf<TModule['configSchema']> & string>(\n key: K\n ): PublicKeyOf<TModule['configSchema']>[K] | undefined {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return _getClientConfig(`${moduleName}.${key}`) as any;\n },\n\n query<K extends keyof TModule['queries'] & string>(\n name: K,\n ...rest: {} extends ExtractArgs<TModule['queries'][K]>\n ? [args?: ExtractArgs<TModule['queries'][K]>]\n : [args: ExtractArgs<TModule['queries'][K]>]\n ) {\n const args = (rest[0] ?? {}) as ExtractArgs<TModule['queries'][K]>;\n return {\n queryKey: [moduleName, name, args] as const,\n queryFn: (): Promise<ExtractResult<TModule['queries'][K]>> =>\n callMethod<ExtractResult<TModule['queries'][K]>>(\n `${moduleName}.${name}`,\n args as MethodArgs\n ),\n };\n },\n\n mutation<K extends keyof TModule['mutations'] & string>(name: K) {\n return {\n mutationFn: (\n args: ExtractArgs<TModule['mutations'][K]>\n ): Promise<ExtractResult<TModule['mutations'][K]>> =>\n callMethod<ExtractResult<TModule['mutations'][K]>>(\n `${moduleName}.${name}`,\n args as MethodArgs\n ),\n };\n },\n\n /**\n * Returns options for `useInfiniteQuery`. The `getArgs` callback receives the\n * current `pageParam` and returns the args to pass to the query handler.\n * Spread the result into `useInfiniteQuery` alongside `getNextPageParam`.\n *\n * Annotate the `pageParam` type in the callback so TypeScript can infer the\n * page param type — no manual generic needed on `useInfiniteQuery`.\n */\n infiniteQuery<K extends keyof TModule['queries'] & string, TPageParam = unknown>(\n name: K,\n getArgs: (pageParam: TPageParam | undefined) => ExtractArgs<TModule['queries'][K]>\n ) {\n return {\n queryKey: [moduleName, name, 'infinite', getArgs(undefined)] as const,\n // Included so TanStack infers TPageParam from the callback type, not from a bare `undefined`.\n initialPageParam: undefined as TPageParam | undefined,\n queryFn: ({\n pageParam,\n }: {\n pageParam: TPageParam | undefined;\n }): Promise<ExtractResult<TModule['queries'][K]>> =>\n callMethod<ExtractResult<TModule['queries'][K]>>(\n `${moduleName}.${name}`,\n getArgs(pageParam) as MethodArgs\n ),\n };\n },\n };\n}\n","import type systemModule from './index';\nimport { createClientModule } from '../client/module';\n\nexport const systemConfig = createClientModule<typeof systemModule>('_system');\n","import { getWebsocketClientProvider } from './client';\n\nexport class ClientChannel<T = unknown> {\n public readonly category: string;\n private readonly onMessage: (data: T) => void;\n\n constructor(category: string, onMessage: (data: T) => void) {\n this.category = category;\n this.onMessage = onMessage;\n }\n\n init() {\n getWebsocketClientProvider()?.on({\n category: this.category,\n listener: this.onMessage,\n });\n }\n\n joinChannel(id: string) {\n getWebsocketClientProvider()?.joinChannel({\n category: this.category,\n id,\n });\n }\n\n leaveChannel(id: string) {\n getWebsocketClientProvider()?.leaveChannel({\n category: this.category,\n id,\n });\n }\n}\n","import { callMethod } from '../client/method';\nimport type { FileVisibility, GetUploadUrlResult } from './types';\n\ntype UploadFileParams = {\n filePath: string;\n contentType: string;\n visibility: FileVisibility;\n};\n\ntype UploadFileResult = {\n filePath: string;\n};\n\nexport async function uploadFile(\n file: File | Blob,\n { filePath, contentType, visibility }: UploadFileParams\n): Promise<UploadFileResult> {\n const {\n url,\n fields,\n filePath: resolvedFilePath,\n } = await callMethod<GetUploadUrlResult>('_system.files.getUploadUrl', {\n filePath,\n contentType,\n visibility,\n });\n\n const formData = new FormData();\n for (const [key, value] of Object.entries(fields)) {\n formData.append(key, value);\n }\n formData.append('file', file);\n\n const uploadResponse = await fetch(url, {\n method: 'POST',\n body: formData,\n });\n\n if (!uploadResponse.ok) {\n throw new Error(`Failed to upload file: HTTP status: ${uploadResponse.status}`);\n }\n\n return { filePath: resolvedFilePath };\n}\n\nexport async function deleteFile(filePath: string): Promise<void> {\n await callMethod('_system.files.deleteFile', { filePath });\n}\n\nexport async function downloadFile(filePath: string): Promise<{ downloadUrl: string }> {\n return callMethod('_system.files.downloadFile', { filePath });\n}\n\nexport async function getFileUrl(filePath: string): Promise<{ url: string }> {\n return callMethod('_system.files.getFileUrl', { filePath });\n}\n","import React from 'react';\n\nimport { AppProvider as OriginalAppProvider } from './client/AppProvider';\n\nexport { getConfig } from './config/client';\nexport { createClientModule } from './client/module';\nexport type { ValueType } from './config/types';\nexport { systemConfig } from './system/client';\n\nexport const AppProvider =\n 'useClient' in React\n ? // @ts-ignore: React.useClient only exists in Next.js\n React.useClient(OriginalAppProvider)\n : OriginalAppProvider;\n\nexport { renderApp } from './client/renderApp';\nexport { ModelenceQueryProvider } from './client/queryProvider';\nexport {\n modelenceQuery,\n modelenceLiveQuery,\n modelenceMutation,\n createQueryKey,\n connectModelenceQueryClient,\n disconnectModelenceQueryClient,\n ModelenceQueryClient,\n type ModelenceQueryKey,\n} from './client/query';\nexport { callMethod, MethodError, type MethodArgs, type CallMethodOptions } from './client/method';\nexport { useSession } from './client/session';\nexport {\n signupWithPassword,\n loginWithPassword,\n verifyEmail,\n updateProfile,\n resendEmailVerification,\n logout,\n sendResetPasswordToken,\n resetPassword,\n linkOAuthProvider,\n unlinkOAuthProvider,\n type UserInfo,\n} from './auth/client';\nexport {\n getWebsocketClientProvider,\n setWebsocketClientProvider,\n startWebsockets,\n subscribeLiveQuery,\n} from './websocket/client';\nexport { ClientChannel } from './websocket/clientChannel';\nexport { getLocalStorageSession } from './client/localStorage';\nexport { uploadFile, deleteFile, downloadFile, getFileUrl } from './files/client';\n","import React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport { AppProvider } from '../client';\nimport { setErrorHandler, ErrorHandler } from './errorHandler';\nimport { hydrateSession, startSessionHeartbeat, type SessionInitPayload } from './session';\nimport { ModelenceQueryProvider } from './queryProvider';\n\nconst SSR_STATE_SCRIPT_ID = '__MODELENCE_STATE__';\n\ntype SsrState = {\n session?: SessionInitPayload;\n};\n\nfunction readSsrState(): SsrState | null {\n if (typeof document === 'undefined') {\n return null;\n }\n\n const node = document.getElementById(SSR_STATE_SCRIPT_ID);\n if (!node) {\n return null;\n }\n\n try {\n return JSON.parse(node.textContent ?? '') as SsrState;\n } catch (e) {\n console.error('Modelence: failed to parse SSR state', e);\n return null;\n }\n}\n\nexport type SsrRouter = (props: {\n children: React.ReactNode;\n location?: string;\n}) => React.ReactElement;\n\nexport interface RenderAppOptions {\n loadingElement: React.ReactNode;\n routesElement: React.ReactNode;\n favicon?: string;\n errorHandler?: ErrorHandler;\n router?: SsrRouter;\n}\n\n// Shared on globalThis because Vite's ssrLoadModule loads the user's entry\n// in a separate module graph from the framework runtime.\nconst SNAPSHOT_KEY = '__modelence_ssr_snapshot__';\n\ntype GlobalWithSnapshot = typeof globalThis & {\n [SNAPSHOT_KEY]?: RenderAppOptions | null;\n};\n\nfunction setSnapshot(snapshot: RenderAppOptions | null) {\n (globalThis as GlobalWithSnapshot)[SNAPSHOT_KEY] = snapshot;\n}\n\n/** @internal Used by the SSR runtime after evaluating the user's entry. */\nexport function _getSsrSnapshot(): RenderAppOptions | null {\n return (globalThis as GlobalWithSnapshot)[SNAPSHOT_KEY] ?? null;\n}\n\nexport function renderApp(options: RenderAppOptions) {\n if (typeof window === 'undefined') {\n setSnapshot(options);\n return;\n }\n\n const { loadingElement, routesElement, favicon, errorHandler, router } = options;\n\n if (errorHandler) {\n setErrorHandler(errorHandler);\n }\n\n window.addEventListener('unload', () => {\n // Empty 'unload' handler prevents bfcache in most browsers.\n });\n\n // ORDER MATTERS: hydrate session BEFORE building the React tree / calling\n // hydrateRoot, so `isSessionInitialized()` is true on the first render and\n // AppProvider's initial `isLoading` matches the server-rendered output.\n const ssrState = readSsrState();\n const isHydrating = ssrState !== null;\n if (ssrState?.session) {\n hydrateSession(ssrState.session);\n startSessionHeartbeat();\n }\n\n const container = document.getElementById('root')!;\n const routedTree = router ? router({ children: routesElement }) : routesElement;\n const tree = (\n <React.StrictMode>\n <AppProvider loadingElement={loadingElement}>\n <ModelenceQueryProvider>{routedTree}</ModelenceQueryProvider>\n </AppProvider>\n </React.StrictMode>\n );\n\n if (isHydrating) {\n ReactDOM.hydrateRoot(container, tree);\n } else {\n ReactDOM.createRoot(container).render(tree);\n }\n\n if (favicon) {\n const link = document.querySelector(\"link[rel~='icon']\") as HTMLLinkElement;\n if (!link) {\n const newLink = document.createElement('link');\n newLink.rel = 'icon';\n newLink.href = favicon;\n document.head.appendChild(newLink);\n } else {\n link.href = favicon;\n }\n }\n}\n"]}
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { b as ConfigKey, c as ConfigParams, A as AnyMethodShape, V as ValueType, d as ConfigType, O as OAuthProvider, W as WebsocketClientProvider, e as ClientChannel } from './types-
|
|
1
|
+
import { b as ConfigKey, c as ConfigParams, A as AnyMethodShape, V as ValueType, d as ConfigType, O as OAuthProvider, W as WebsocketClientProvider, e as ClientChannel } from './types-DANNMU1V.js';
|
|
2
2
|
import { ObjectId } from 'mongodb';
|
|
3
3
|
import React, { ReactNode } from 'react';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
@@ -23,6 +23,34 @@ type MethodArgs = Record<string, unknown>;
|
|
|
23
23
|
type CallMethodOptions = {
|
|
24
24
|
errorHandler?: (error: Error, methodName: string) => void;
|
|
25
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Calls a server-side method (query or mutation) defined on a Modelence module.
|
|
28
|
+
*
|
|
29
|
+
* Both `args` and `options` are optional. Use the type parameter `T` to type the return value.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* import { callMethod } from 'modelence/client';
|
|
34
|
+
*
|
|
35
|
+
* // No arguments
|
|
36
|
+
* const todos = await callMethod<Todo[]>('todo.getAll');
|
|
37
|
+
*
|
|
38
|
+
* // With arguments
|
|
39
|
+
* const todo = await callMethod<Todo>('todo.getOne', { id: '123' });
|
|
40
|
+
*
|
|
41
|
+
* // With a custom error handler
|
|
42
|
+
* const created = await callMethod<Todo>(
|
|
43
|
+
* 'todo.create',
|
|
44
|
+
* { title: 'Buy groceries' },
|
|
45
|
+
* { errorHandler: (error, methodName) => console.error(methodName, error) }
|
|
46
|
+
* );
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param methodName - Fully qualified method name, e.g. `'todo.getAll'`.
|
|
50
|
+
* @param args - Arguments passed to the server-side method. Defaults to `{}`.
|
|
51
|
+
* @param options - Call-site options such as a custom {@link CallMethodOptions.errorHandler}. Defaults to `{}`.
|
|
52
|
+
* @returns A promise that resolves to the method's return value.
|
|
53
|
+
*/
|
|
26
54
|
declare function callMethod<T = unknown>(methodName: string, args?: MethodArgs, options?: CallMethodOptions): Promise<T>;
|
|
27
55
|
|
|
28
56
|
/**
|
|
@@ -155,6 +183,10 @@ type Args = Record<string, unknown>;
|
|
|
155
183
|
* Connects a `QueryClient` to Modelence's live-query layer. Auto-called by
|
|
156
184
|
* `<ModelenceQueryProvider>`; only call manually if you mount your own
|
|
157
185
|
* `<QueryClientProvider>`.
|
|
186
|
+
*
|
|
187
|
+
* Note: WebSocket setup is deferred until the first `modelenceLiveQuery`
|
|
188
|
+
* call, so apps that only use `modelenceQuery`/`modelenceMutation` never
|
|
189
|
+
* open a socket.
|
|
158
190
|
*/
|
|
159
191
|
declare function connectModelenceQueryClient(queryClient: QueryClient): void;
|
|
160
192
|
declare function disconnectModelenceQueryClient(): void;
|
|
@@ -407,4 +439,4 @@ declare function getFileUrl(filePath: string): Promise<{
|
|
|
407
439
|
|
|
408
440
|
declare const AppProvider: any;
|
|
409
441
|
|
|
410
|
-
export { AppProvider, ClientChannel, type MethodArgs, MethodError, ModelenceQueryClient, type ModelenceQueryKey, ModelenceQueryProvider, type UserInfo, ValueType, callMethod, connectModelenceQueryClient, createClientModule, createQueryKey, deleteFile, disconnectModelenceQueryClient, downloadFile, getConfig, getFileUrl, getLocalStorageSession, getWebsocketClientProvider, linkOAuthProvider, loginWithPassword, logout, modelenceLiveQuery, modelenceMutation, modelenceQuery, renderApp, resendEmailVerification, resetPassword, sendResetPasswordToken, setWebsocketClientProvider, signupWithPassword, startWebsockets, subscribeLiveQuery, systemConfig, unlinkOAuthProvider, updateProfile, uploadFile, useSession, verifyEmail };
|
|
442
|
+
export { AppProvider, type CallMethodOptions, ClientChannel, type MethodArgs, MethodError, ModelenceQueryClient, type ModelenceQueryKey, ModelenceQueryProvider, type UserInfo, ValueType, callMethod, connectModelenceQueryClient, createClientModule, createQueryKey, deleteFile, disconnectModelenceQueryClient, downloadFile, getConfig, getFileUrl, getLocalStorageSession, getWebsocketClientProvider, linkOAuthProvider, loginWithPassword, logout, modelenceLiveQuery, modelenceMutation, modelenceQuery, renderApp, resendEmailVerification, resetPassword, sendResetPasswordToken, setWebsocketClientProvider, signupWithPassword, startWebsockets, subscribeLiveQuery, systemConfig, unlinkOAuthProvider, updateProfile, uploadFile, useSession, verifyEmail };
|
package/dist/client.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{j as AppProvider,e as ClientChannel,a as createClientModule,g as deleteFile,h as downloadFile,i as getFileUrl,d as renderApp,b as systemConfig,f as uploadFile}from'./chunk-
|
|
1
|
+
export{j as AppProvider,e as ClientChannel,a as createClientModule,g as deleteFile,h as downloadFile,i as getFileUrl,d as renderApp,b as systemConfig,f as uploadFile}from'./chunk-X6CSJYLY.js';export{h as ModelenceQueryClient,m as ModelenceQueryProvider,f as connectModelenceQueryClient,l as createQueryKey,g as disconnectModelenceQueryClient,d as getWebsocketClientProvider,j as modelenceLiveQuery,k as modelenceMutation,i as modelenceQuery,c as setWebsocketClientProvider,e as startWebsockets,b as subscribeLiveQuery}from'./chunk-SABBG2XG.js';export{o as MethodError,q as callMethod,s as getConfig,a as getLocalStorageSession,j as linkOAuthProvider,c as loginWithPassword,g as logout,f as resendEmailVerification,i as resetPassword,h as sendResetPasswordToken,b as signupWithPassword,k as unlinkOAuthProvider,d as updateProfile,z as useSession,e as verifyEmail}from'./chunk-R6OOTUGO.js';import'./chunk-5M6FUMUK.js';import'./chunk-DO5TZLF5.js';//# sourceMappingURL=client.js.map
|
|
2
2
|
//# sourceMappingURL=client.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { C as ConfigSchema, W as WebsocketClientProvider, a as WebsocketServerProvider } from './types-
|
|
1
|
+
export { C as ConfigSchema, W as WebsocketClientProvider, a as WebsocketServerProvider } from './types-DANNMU1V.js';
|
|
2
2
|
export { M as ModelenceConfig } from './index-BBMsjrFN.js';
|
|
3
3
|
import 'http';
|
|
4
4
|
import 'mongodb';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{l as author,i as bin,n as bugs,s as default,q as dependencies,d as description,p as devDependencies,g as exports,h as files,o as homepage,m as license,e as main,b as name,r as peerDependencies,k as repository,j as scripts,a as type,f as types,c as version}from'./chunk-
|
|
2
|
-
//# sourceMappingURL=package-
|
|
1
|
+
export{l as author,i as bin,n as bugs,s as default,q as dependencies,d as description,p as devDependencies,g as exports,h as files,o as homepage,m as license,e as main,b as name,r as peerDependencies,k as repository,j as scripts,a as type,f as types,c as version}from'./chunk-Q3SEQPTY.js';//# sourceMappingURL=package-2YZCMUAD.js.map
|
|
2
|
+
//# sourceMappingURL=package-2YZCMUAD.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"package-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"package-2YZCMUAD.js"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a,b,c}from'./chunk-DRDY7GOT.js';import'./chunk-GZI4X3CV.js';import'./chunk-3SPXJEOR.js';import {a as a$1,m}from'./chunk-SABBG2XG.js';import {x,r,y}from'./chunk-R6OOTUGO.js';import'./chunk-5M6FUMUK.js';import'./chunk-DO5TZLF5.js';import {renderToPipeableStream}from'react-dom/server';import {Writable}from'stream';import {QueryClient,dehydrate}from'@tanstack/react-query';import {jsx}from'react/jsx-runtime';var J=()=>{let r=c();return r?y(r.session.user):null},M=r=>{let o=c();if(o)return o.session.configs[r]?.value};function D(){x(J),r(M);}async function X(r){let{callContext:o,loadingElement:C,routesElement:S,router:u,location:x,onShellReady:E,onError:b$1}=r;D();let i=await a("_system.session.init",{},o),n=new QueryClient({defaultOptions:{queries:{retry:false,gcTime:0}}}),O=u?u({children:S,location:x}):S,Q=jsx(a$1,{loadingElement:C,children:jsx(m,{client:n,children:O})}),l=null;await new Promise((s,d)=>{b({callContext:o,queryClient:n,session:{user:i.user,configs:i.configs??{}}},()=>{let e=renderToPipeableStream(Q,{onShellReady(){l=e,E?.(),s(e);},onShellError(t){d(t);},onError(t){b$1?.(t);}});return e});});let a$2=null,_=s=>new Promise((d,e)=>{if(!l){e(new Error("SSR stream was not initialized"));return}let t=new Writable({write(m,c,I){s.write(m,N=>I(N??void 0));},final(m){try{let c=dehydrate(n);a$2=JSON.stringify(c);}finally{n.clear();}m(),d();}});t.on("error",e),s.on("error",e),l.pipe(t);});return {sessionState:JSON.stringify({session:i}),pipe:_,getQueryState:()=>{if(a$2===null)throw new Error("getQueryState() called before stream finished");return a$2}}}export{X as renderSsrTreeStream};//# sourceMappingURL=render-DLVPZOA6.js.map
|
|
2
|
+
//# sourceMappingURL=render-DLVPZOA6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ssr/render.tsx"],"names":["sessionResolver","ctx","getSsrContext","_parseSessionUser","configResolver","key","ensureSsrResolversInstalled","_setSsrSessionResolver","_setSsrConfigResolver","renderSsrTreeStream","options","callContext","loadingElement","routesElement","router","location","onShellReady","onError","sessionPayload","callInProcessMethod","queryClient","QueryClient","routedTree","tree","jsx","AppProvider","ModelenceQueryProvider","streamRef","resolve","reject","runWithSsrContext","stream","renderToPipeableStream","error","queryStateJson","pipe","destination","passthrough","Writable","chunk","_encoding","callback","err","dehydratedState","dehydrate"],"mappings":"+ZAkBA,IAAMA,CAAAA,CAAkB,IAAM,CAC5B,IAAMC,CAAAA,CAAMC,CAAAA,EAAc,CAC1B,OAAKD,CAAAA,CAGEE,CAAAA,CAAkBF,CAAAA,CAAI,OAAA,CAAQ,IAAI,CAAA,CAFhC,IAGX,CAAA,CAEMG,CAAAA,CAAkBC,GAAmB,CACzC,IAAMJ,CAAAA,CAAMC,CAAAA,GACZ,GAAKD,CAAAA,CAGL,OAAOA,CAAAA,CAAI,QAAQ,OAAA,CAAQI,CAAG,CAAA,EAAG,KACnC,EAEA,SAASC,CAAAA,EAA8B,CAGrCC,CAAAA,CAAuBP,CAAe,CAAA,CACtCQ,CAAAA,CAAsBJ,CAAc,EACtC,CA+CA,eAAsBK,CAAAA,CAAoBC,CAAAA,CAAqD,CAC7F,GAAM,CAAE,WAAA,CAAAC,CAAAA,CAAa,cAAA,CAAAC,EAAgB,aAAA,CAAAC,CAAAA,CAAe,MAAA,CAAAC,CAAAA,CAAQ,SAAAC,CAAAA,CAAU,YAAA,CAAAC,C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AAAA,CAAgC,KAE9BC,CAAAA,CAAQC,CAAAA,EACL,IAAI,OAAA,CAAQ,CAACR,CAAAA,CAASC,CAAAA,GAAW,CACtC,GAAI,CAACF,CAAAA,CAAW,CACdE,CAAAA,CAAO,IAAI,MAAM,gCAAgC,CAAC,CAAA,CAClD,MACF,CAMA,IAAMQ,CAAAA,CAAc,IAAIC,QAAAA,CAAS,CAC/B,KAAA,CAAMC,CAAAA,CAAOC,CAAAA,CAAWC,CAAAA,CAAU,CAChCL,CAAAA,CAAY,KAAA,CAAMG,CAAAA,CAAQG,CAAAA,EAAQD,EAASC,CAAAA,EAAO,MAAS,CAAC,EAC9D,EACA,KAAA,CAAMD,CAAAA,CAAU,CAId,GAAI,CACF,IAAME,CAAAA,CAAmCC,SAAAA,CAAUxB,CAAW,EAC9Dc,GAAAA,CAAiB,IAAA,CAAK,SAAA,CAAUS,CAAe,EACjD,CAAA,OAAE,CACAvB,CAAAA,CAAY,KAAA,GACd,CACAqB,CAAAA,EAAS,CACTb,CAAAA,GACF,CACF,CAAC,CAAA,CAEDS,CAAAA,CAAY,GAAG,OAAA,CAASR,CAAM,CAAA,CAC9BO,CAAAA,CAAY,GAAG,OAAA,CAASP,CAAM,CAAA,CAE9BF,CAAAA,CAAU,KAAKU,CAAW,EAC5B,CAAC,CAAA,CAGH,OAAO,CACL,YAAA,CAAc,IAAA,CAAK,SAAA,CAAU,CAAE,OAAA,CAASnB,CAAe,CAAC,CAAA,CACxD,KAAAiB,CAAAA,CACA,aAAA,CAAe,IAAM,CACnB,GAAID,GAAAA,GAAmB,IAAA,CACrB,MAAM,IAAI,MAAM,+CAA+C,CAAA,CAEjE,OAAOA,GACT,CACF,CACF","file":"render-DLVPZOA6.js","sourcesContent":["import React from 'react';\nimport { renderToPipeableStream, type PipeableStream } from 'react-dom/server';\nimport { Writable } from 'node:stream';\nimport { QueryClient, dehydrate, type DehydratedState } from '@tanstack/react-query';\nimport { AppProvider } from '../client/AppProvider';\nimport { ModelenceQueryProvider } from '../client/queryProvider';\nimport { getSsrContext, runWithSsrContext } from './context';\nimport { callInProcessMethod } from './callInProcess';\nimport type { Context } from '../methods/types';\nimport {\n _parseSessionUser,\n _setSsrSessionResolver,\n type SessionInitPayload,\n} from '../client/session';\nimport { _setSsrConfigResolver } from '../config/client';\nimport type { ConfigKey, Configs } from '../config/types';\nimport type { SsrRouter } from '../client/renderApp';\n\nconst sessionResolver = () => {\n const ctx = getSsrContext();\n if (!ctx) {\n return null;\n }\n return _parseSessionUser(ctx.session.user);\n};\n\nconst configResolver = (key: ConfigKey) => {\n const ctx = getSsrContext();\n if (!ctx) {\n return undefined;\n }\n return ctx.session.configs[key]?.value;\n};\n\nfunction ensureSsrResolversInstalled() {\n // Idempotent — safe to call repeatedly. Re-installs the framework's own\n // resolvers if they were swapped out (tests, future reload code).\n _setSsrSessionResolver(sessionResolver);\n _setSsrConfigResolver(configResolver);\n}\n\nexport type SsrRenderOptions = {\n callContext: Context;\n loadingElement: React.ReactNode;\n routesElement: React.ReactNode;\n router?: SsrRouter;\n location?: string;\n};\n\nexport type SsrStreamHandle = {\n /** Session bootstrap payload — safe to inline before the React shell flushes. */\n sessionState: string;\n /**\n * Pipe React's HTML stream into the response. Resolves once every Suspense\n * boundary has settled and the stream has finished writing.\n */\n pipe: (destination: Writable) => Promise<void>;\n /**\n * Read the dehydrated query state. Only call AFTER `pipe()` resolves —\n * queries that resolve mid-stream populate the cache during render.\n */\n getQueryState: () => string;\n};\n\nexport type SsrStreamOptions = SsrRenderOptions & {\n /**\n * Called once React has flushed the shell (head + above-fallback content)\n * and the stream is ready to pipe. The framework uses this hook to write\n * the opening template + state scripts before piping React's HTML.\n */\n onShellReady?: () => void;\n /** Non-fatal SSR errors (Suspense fallbacks, etc.). */\n onError?: (error: unknown) => void;\n};\n\n/**\n * Renders the SSR tree as a stream. Returns a handle that lets the caller\n * flush a template prelude (head + opening shell) as soon as the React shell\n * is ready, pipe the React HTML stream into the response, then append the\n * dehydrated query state once streaming completes.\n *\n * This is what enables fast First Contentful Paint: the browser receives the\n * <head> (with CSS <link> tags) immediately, starts the stylesheet fetch in\n * parallel with the HTML stream, and paints the streamed shell with styles\n * applied — instead of the dev-mode FOUC caused by JS-injected CSS.\n */\nexport async function renderSsrTreeStream(options: SsrStreamOptions): Promise<SsrStreamHandle> {\n const { callContext, loadingElement, routesElement, router, location, onShellReady, onError } =\n options;\n\n ensureSsrResolversInstalled();\n\n const sessionPayload = await callInProcessMethod<SessionInitPayload>(\n '_system.session.init',\n {},\n callContext\n );\n\n const queryClient = new QueryClient({\n defaultOptions: {\n queries: {\n retry: false,\n gcTime: 0,\n },\n },\n });\n\n const routedTree = router ? router({ children: routesElement, location }) : routesElement;\n const tree = (\n <AppProvider loadingElement={loadingElement}>\n <ModelenceQueryProvider client={queryClient}>{routedTree}</ModelenceQueryProvider>\n </AppProvider>\n );\n\n let streamRef: PipeableStream | null = null;\n // The shell-ready promise resolves with the PipeableStream as soon as React\n // has rendered above-fallback content. Errors during the shell render\n // reject it so the caller can fall back to a static response.\n const shellReady = new Promise<PipeableStream>((resolve, reject) => {\n // Run the render inside the SSR context so server-rendered components\n // can resolve session/config/query state from the per-request scope.\n runWithSsrContext(\n {\n callContext,\n queryClient,\n session: {\n user: sessionPayload.user,\n configs: (sessionPayload.configs as Configs) ?? {},\n },\n },\n () => {\n const stream = renderToPipeableStream(tree, {\n onShellReady() {\n streamRef = stream;\n onShellReady?.();\n resolve(stream);\n },\n onShellError(error) {\n reject(error);\n },\n onError(error) {\n onError?.(error);\n },\n });\n return stream;\n }\n );\n });\n\n // Surface shell errors synchronously by awaiting before returning the handle.\n await shellReady;\n\n let queryStateJson: string | null = null;\n\n const pipe = (destination: Writable): Promise<void> => {\n return new Promise((resolve, reject) => {\n if (!streamRef) {\n reject(new Error('SSR stream was not initialized'));\n return;\n }\n\n // react-dom calls `.end()` on the destination it pipes into. We need to\n // keep writing AFTER React is done (epilogue + query state script), so\n // we wrap the real destination in a pass-through Writable whose `end()`\n // flushes pending data but does NOT close the underlying response.\n const passthrough = new Writable({\n write(chunk, _encoding, callback) {\n destination.write(chunk, (err) => callback(err ?? undefined));\n },\n final(callback) {\n // Triggered by react-dom's `destination.end()`. Resolve the pipe\n // promise so the caller can write the epilogue, but leave the real\n // response open.\n try {\n const dehydratedState: DehydratedState = dehydrate(queryClient);\n queryStateJson = JSON.stringify(dehydratedState);\n } finally {\n queryClient.clear();\n }\n callback();\n resolve();\n },\n });\n\n passthrough.on('error', reject);\n destination.on('error', reject);\n\n streamRef.pipe(passthrough);\n });\n };\n\n return {\n sessionState: JSON.stringify({ session: sessionPayload }),\n pipe,\n getQueryState: () => {\n if (queryStateJson === null) {\n throw new Error('getQueryState() called before stream finished');\n }\n return queryStateJson;\n },\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"renderApp-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"renderApp-KKWGQKMM.js"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export{g as getCallContext,f as startServer}from'./chunk-C26FT6MS.js';import'./chunk-Q3SEQPTY.js';import'./chunk-GZI4X3CV.js';import'./chunk-C3UESBRX.js';import'./chunk-3SPXJEOR.js';import'./chunk-5M6FUMUK.js';import'./chunk-DO5TZLF5.js';//# sourceMappingURL=server-GBPVLS3G.js.map
|
|
2
|
+
//# sourceMappingURL=server-GBPVLS3G.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"server-
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"server-GBPVLS3G.js"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { A as AppServer } from './index-BBMsjrFN.js';
|
|
2
|
-
import { c as ConfigParams, C as ConfigSchema, A as AnyMethodShape, S as ServerChannel, V as ValueType, f as SignupProps, U as UpdateProfileProps, g as AuthSuccessProps, h as AuthErrorProps, i as User, j as OAuthErrorInfo, a as WebsocketServerProvider, R as RoleDefinition, M as MethodDefinition, b as ConfigKey, k as AppConfig, l as Session, m as UserInfo, n as Role } from './types-
|
|
3
|
-
export { d as ConfigType } from './types-
|
|
4
|
-
import { S as Store, R as RouteDefinition, C as CronJobInputParams, a as RateLimitRule, E as EmailProvider,
|
|
5
|
-
export { H as HttpMethod, d as RouteHandler, e as RouteParams, f as RouteResponse, s as schema } from './types-
|
|
2
|
+
import { c as ConfigParams, C as ConfigSchema, A as AnyMethodShape, S as ServerChannel, V as ValueType, f as SignupProps, U as UpdateProfileProps, g as AuthSuccessProps, h as AuthErrorProps, i as User, j as OAuthErrorInfo, a as WebsocketServerProvider, R as RoleDefinition, M as MethodDefinition, b as ConfigKey, k as AppConfig, l as Session, m as UserInfo, n as Role } from './types-DANNMU1V.js';
|
|
3
|
+
export { d as ConfigType } from './types-DANNMU1V.js';
|
|
4
|
+
import { S as Store, R as RouteDefinition, C as CronJobInputParams, a as RateLimitRule, E as EmailProvider, b as RateLimitType, I as InferDocumentType, c as EmailPayload } from './types-BT2k9L7Q.js';
|
|
5
|
+
export { H as HttpMethod, d as RouteHandler, e as RouteParams, f as RouteResponse, s as schema } from './types-BT2k9L7Q.js';
|
|
6
6
|
import { ObjectId as ObjectId$1 } from 'mongodb';
|
|
7
7
|
export { ObjectId } from 'mongodb';
|
|
8
8
|
import * as zod from 'zod';
|
|
@@ -131,15 +131,66 @@ type EmailConfig = {
|
|
|
131
131
|
};
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
134
|
+
* A single rate-limit rule for an authentication bucket. The `bucket` is
|
|
135
|
+
* implied by which auth action you're configuring (e.g. `signup`), so callers
|
|
136
|
+
* only specify the actor type, window size, and limit.
|
|
136
137
|
*
|
|
137
138
|
* @example
|
|
138
139
|
* ```typescript
|
|
140
|
+
* import { time } from 'modelence/server';
|
|
141
|
+
*
|
|
142
|
+
* const rule: AuthRateLimitOverride = {
|
|
143
|
+
* type: 'ip',
|
|
144
|
+
* window: time.minutes(15),
|
|
145
|
+
* limit: 10,
|
|
146
|
+
* };
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
type AuthRateLimitOverride = {
|
|
150
|
+
/** Identifier type of the actor this rule applies to. */
|
|
151
|
+
type: RateLimitType;
|
|
152
|
+
/** Time window size in milliseconds. Use `time.minutes(15)` etc. */
|
|
153
|
+
window: number;
|
|
154
|
+
/** Maximum allowed hits within the window. */
|
|
155
|
+
limit: number;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Per-action rate limit overrides for authentication endpoints.
|
|
159
|
+
*
|
|
160
|
+
* Each bucket accepts an array of rules that are merged into the built-in
|
|
161
|
+
* defaults by `(type, window)` tuple:
|
|
162
|
+
* - A rule whose `(type, window)` matches a default replaces that default's
|
|
163
|
+
* `limit`.
|
|
164
|
+
* - A rule whose `(type, window)` does not match any default is added as
|
|
165
|
+
* an extra rule for the bucket.
|
|
166
|
+
* - Defaults whose `(type, window)` is not overridden are kept.
|
|
167
|
+
*
|
|
168
|
+
* This means you can tighten a single window without accidentally dropping
|
|
169
|
+
* the other built-in protections for that bucket.
|
|
170
|
+
*
|
|
171
|
+
* @example Tighten the 15-minute signup cap; per-day default is preserved.
|
|
172
|
+
* ```typescript
|
|
173
|
+
* import { startApp, time } from 'modelence/server';
|
|
174
|
+
*
|
|
175
|
+
* startApp({
|
|
176
|
+
* auth: {
|
|
177
|
+
* rateLimits: {
|
|
178
|
+
* signup: [
|
|
179
|
+
* { type: 'ip', window: time.minutes(15), limit: 5 },
|
|
180
|
+
* ],
|
|
181
|
+
* },
|
|
182
|
+
* },
|
|
183
|
+
* });
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example Add an extra window alongside the defaults.
|
|
187
|
+
* ```typescript
|
|
139
188
|
* startApp({
|
|
140
189
|
* auth: {
|
|
141
190
|
* rateLimits: {
|
|
142
|
-
* signup:
|
|
191
|
+
* signup: [
|
|
192
|
+
* { type: 'ip', window: time.minutes(1), limit: 2 },
|
|
193
|
+
* ],
|
|
143
194
|
* },
|
|
144
195
|
* },
|
|
145
196
|
* });
|
|
@@ -147,44 +198,15 @@ type EmailConfig = {
|
|
|
147
198
|
*/
|
|
148
199
|
type AuthRateLimitsConfig = {
|
|
149
200
|
/** Per-IP limits for the signup endpoint (successful signups only). */
|
|
150
|
-
signup?:
|
|
151
|
-
/** Max signups per IP in a 15-minute window. @default 20 */
|
|
152
|
-
perIp15Minutes?: number;
|
|
153
|
-
/** Max signups per IP per day. @default 200 */
|
|
154
|
-
perIpPerDay?: number;
|
|
155
|
-
};
|
|
201
|
+
signup?: AuthRateLimitOverride[];
|
|
156
202
|
/** Per-IP limits for signup attempts (checked before duplicate detection). */
|
|
157
|
-
signupAttempt?:
|
|
158
|
-
/** Max signup attempts per IP in a 15-minute window. @default 50 */
|
|
159
|
-
perIp15Minutes?: number;
|
|
160
|
-
/** Max signup attempts per IP per day. @default 500 */
|
|
161
|
-
perIpPerDay?: number;
|
|
162
|
-
};
|
|
203
|
+
signupAttempt?: AuthRateLimitOverride[];
|
|
163
204
|
/** Per-IP limits for login attempts. */
|
|
164
|
-
signin?:
|
|
165
|
-
/** Max login attempts per IP in a 15-minute window. @default 50 */
|
|
166
|
-
perIp15Minutes?: number;
|
|
167
|
-
/** Max login attempts per IP per day. @default 500 */
|
|
168
|
-
perIpPerDay?: number;
|
|
169
|
-
};
|
|
205
|
+
signin?: AuthRateLimitOverride[];
|
|
170
206
|
/** Per-user limits for email verification requests. */
|
|
171
|
-
verification?:
|
|
172
|
-
/** Max verification emails per user per minute. @default 1 */
|
|
173
|
-
perUserPerMinute?: number;
|
|
174
|
-
/** Max verification emails per user per day. @default 10 */
|
|
175
|
-
perUserPerDay?: number;
|
|
176
|
-
};
|
|
207
|
+
verification?: AuthRateLimitOverride[];
|
|
177
208
|
/** Rate limits for password reset requests. */
|
|
178
|
-
passwordReset?:
|
|
179
|
-
/** Max password reset requests per IP in a 15-minute window. @default 10 */
|
|
180
|
-
perIp15Minutes?: number;
|
|
181
|
-
/** Max password reset requests per IP per day. @default 100 */
|
|
182
|
-
perIpPerDay?: number;
|
|
183
|
-
/** Max password reset requests per email address per hour. @default 5 */
|
|
184
|
-
perEmailPerHour?: number;
|
|
185
|
-
/** Max password reset requests per email address per day. @default 10 */
|
|
186
|
-
perEmailPerDay?: number;
|
|
187
|
-
};
|
|
209
|
+
passwordReset?: AuthRateLimitOverride[];
|
|
188
210
|
};
|
|
189
211
|
type GenerateHandleProps = {
|
|
190
212
|
email: string;
|
|
@@ -240,20 +262,77 @@ type AuthOption = {
|
|
|
240
262
|
* ```
|
|
241
263
|
*/
|
|
242
264
|
type AuthConfig = {
|
|
265
|
+
/**
|
|
266
|
+
* Pre-signup validation hook. Runs before a new user is created during
|
|
267
|
+
* email/password signup, after format checks but before duplicate detection.
|
|
268
|
+
* Throw to reject the signup — the thrown message is surfaced to the client.
|
|
269
|
+
*
|
|
270
|
+
* Receives the raw signup payload (`email`, `password`, and optional
|
|
271
|
+
* `firstName`, `lastName`, `avatarUrl`, `handle`). May be async.
|
|
272
|
+
*/
|
|
243
273
|
validateSignup?: (props: SignupProps) => void | Promise<void>;
|
|
274
|
+
/**
|
|
275
|
+
* Pre-update validation hook. Runs before a user's profile fields
|
|
276
|
+
* (`firstName`, `lastName`, `avatarUrl`, `handle`) are written.
|
|
277
|
+
* Throw to reject the update — the thrown message is surfaced to the client.
|
|
278
|
+
* May be async.
|
|
279
|
+
*/
|
|
244
280
|
validateProfileUpdate?: (props: UpdateProfileProps) => void | Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Fires after a successful login (email/password or OAuth) once the session
|
|
283
|
+
* has been linked to the user. Receives `{ provider, user, session, connectionInfo }`.
|
|
284
|
+
* Use for analytics, audit logging, or post-login side effects.
|
|
285
|
+
*/
|
|
245
286
|
onAfterLogin?: (props: AuthSuccessProps) => void;
|
|
287
|
+
/**
|
|
288
|
+
* Fires when a login attempt fails. Receives `{ provider, error, session, connectionInfo }`.
|
|
289
|
+
* Use for failure analytics or alerting — does NOT change the response sent to the client.
|
|
290
|
+
*/
|
|
246
291
|
onLoginError?: (props: AuthErrorProps) => void;
|
|
292
|
+
/**
|
|
293
|
+
* Fires after a successful signup once the user record is created and the
|
|
294
|
+
* session is linked. Receives `{ provider, user, session, connectionInfo }`.
|
|
295
|
+
* Common uses: send welcome email, create default workspace, track activation.
|
|
296
|
+
*/
|
|
247
297
|
onAfterSignup?: (props: AuthSuccessProps) => void;
|
|
298
|
+
/**
|
|
299
|
+
* Fires when a signup attempt fails (validation, duplicate email, etc.).
|
|
300
|
+
* Receives `{ provider, error, session, connectionInfo }`.
|
|
301
|
+
* Use for failure analytics — does NOT change the response sent to the client.
|
|
302
|
+
*/
|
|
248
303
|
onSignupError?: (props: AuthErrorProps) => void;
|
|
304
|
+
/**
|
|
305
|
+
* Fires after a user's email is successfully verified (via the verification
|
|
306
|
+
* link or implicitly via password reset). Receives `{ provider, user, session, connectionInfo }`.
|
|
307
|
+
*/
|
|
249
308
|
onAfterEmailVerification?: (props: AuthSuccessProps) => void;
|
|
309
|
+
/**
|
|
310
|
+
* Fires when email verification fails (invalid or expired token).
|
|
311
|
+
* Receives `{ provider, error, session, connectionInfo }`.
|
|
312
|
+
*/
|
|
250
313
|
onEmailVerificationError?: (props: AuthErrorProps) => void;
|
|
314
|
+
/**
|
|
315
|
+
* Fires after an OAuth provider is linked to an existing account
|
|
316
|
+
* (either automatically when `oauthAccountLinking: 'auto'` or via an
|
|
317
|
+
* explicit link flow). Receives `{ provider, user, session, connectionInfo }`.
|
|
318
|
+
*/
|
|
251
319
|
onAfterOAuthLink?: (props: AuthSuccessProps) => void;
|
|
320
|
+
/**
|
|
321
|
+
* Fires when OAuth account linking fails. Receives
|
|
322
|
+
* `{ provider, error, session, connectionInfo }`.
|
|
323
|
+
*/
|
|
252
324
|
onOAuthLinkError?: (props: AuthErrorProps) => void;
|
|
325
|
+
/**
|
|
326
|
+
* Custom handle generator. If provided, overrides the default behavior
|
|
327
|
+
* (which derives the handle from the email local-part). Receives
|
|
328
|
+
* `{ email, firstName?, lastName? }` and returns the desired handle
|
|
329
|
+
* synchronously or as a `Promise<string>`. If the returned handle collides
|
|
330
|
+
* with an existing one, Modelence appends a numeric suffix automatically.
|
|
331
|
+
*/
|
|
253
332
|
generateHandle?: (props: GenerateHandleProps) => Promise<string> | string;
|
|
254
|
-
/** deprecated
|
|
333
|
+
/** @deprecated Use {@link AuthConfig.onAfterLogin} and {@link AuthConfig.onLoginError} instead. */
|
|
255
334
|
login?: AuthOption;
|
|
256
|
-
/** deprecated
|
|
335
|
+
/** @deprecated Use {@link AuthConfig.onAfterSignup} and {@link AuthConfig.onSignupError} instead. */
|
|
257
336
|
signup?: AuthOption;
|
|
258
337
|
/**
|
|
259
338
|
* Controls how OAuth providers handle existing accounts with matching email.
|
|
@@ -262,10 +341,22 @@ type AuthConfig = {
|
|
|
262
341
|
* if the provider email is verified.
|
|
263
342
|
*/
|
|
264
343
|
oauthAccountLinking?: 'auto' | 'manual';
|
|
344
|
+
/**
|
|
345
|
+
* Customizes how OAuth authentication errors are rendered. By default,
|
|
346
|
+
* OAuth errors are returned as JSON; providing this returns a custom HTML
|
|
347
|
+
* response instead, which is useful when the OAuth flow runs in a browser
|
|
348
|
+
* context. Receives `{ error, statusCode }` and returns an HTML string
|
|
349
|
+
* (or `null`/`undefined` to fall back to the default JSON response).
|
|
350
|
+
*
|
|
351
|
+
* Always escape interpolated values to prevent XSS.
|
|
352
|
+
*/
|
|
265
353
|
errorComponent?: (props: OAuthErrorInfo) => string | null | undefined;
|
|
266
354
|
/**
|
|
267
|
-
* Overrides the built-in rate limits for authentication endpoints.
|
|
268
|
-
*
|
|
355
|
+
* Overrides the built-in rate limits for authentication endpoints. Each rule
|
|
356
|
+
* you provide is merged into the defaults by `(bucket, type, window)`:
|
|
357
|
+
* matching tuples replace the default `limit`, new tuples are added, and
|
|
358
|
+
* unspecified defaults are preserved. See {@link AuthRateLimitsConfig} for
|
|
359
|
+
* full semantics and examples.
|
|
269
360
|
*/
|
|
270
361
|
rateLimits?: AuthRateLimitsConfig;
|
|
271
362
|
};
|
|
@@ -786,4 +877,4 @@ declare function deleteFile(filePath: string): Promise<void>;
|
|
|
786
877
|
declare function downloadFile(filePath: string): Promise<DownloadFileResult>;
|
|
787
878
|
declare function getFileUrl(filePath: string): Promise<GetFileUrlResult>;
|
|
788
879
|
|
|
789
|
-
export { type AppOptions, type AuthConfig, type AuthOption, type AuthRateLimitsConfig, type CloudBackendConnectResponse, ConfigSchema, CronJobInputParams, FileVisibility, LiveData, type LiveDataConfig, type LiveQueryCleanup, type LiveQueryPublish, type LiveQueryWatch, Module, RateLimitRule, RateLimitType, RoleDefinition, RouteDefinition, type SecurityConfig, ServerChannel, Store, UserInfo, ValueType, authenticate, consumeRateLimit, createQuery, usersCollection as dbUsers, deleteFile, deleteUser, disableUser, downloadFile, getConfig, getFileUrl, getUploadUrl, sendEmail, startApp };
|
|
880
|
+
export { type AppOptions, type AuthConfig, type AuthOption, type AuthRateLimitOverride, type AuthRateLimitsConfig, type CloudBackendConnectResponse, ConfigSchema, CronJobInputParams, FileVisibility, LiveData, type LiveDataConfig, type LiveQueryCleanup, type LiveQueryPublish, type LiveQueryWatch, Module, RateLimitRule, RateLimitType, RoleDefinition, RouteDefinition, type SecurityConfig, ServerChannel, Store, UserInfo, ValueType, authenticate, consumeRateLimit, createQuery, usersCollection as dbUsers, deleteFile, deleteUser, disableUser, downloadFile, getConfig, getFileUrl, getUploadUrl, sendEmail, startApp };
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{m as ObjectId,k as ServerChannel,a as consumeRateLimit,c as deleteFile,j as deleteUser,i as disableUser,d as downloadFile,e as getFileUrl,b as getUploadUrl,l as sendEmail,h as startApp}from'./chunk-
|
|
1
|
+
export{m as ObjectId,k as ServerChannel,a as consumeRateLimit,c as deleteFile,j as deleteUser,i as disableUser,d as downloadFile,e as getFileUrl,b as getUploadUrl,l as sendEmail,h as startApp}from'./chunk-C26FT6MS.js';import'./chunk-Q3SEQPTY.js';export{r as LiveData,a as Module,b as Store,q as authenticate,t as createQuery,k as dbUsers,c as schema}from'./chunk-GZI4X3CV.js';import'./chunk-C3UESBRX.js';export{a as getConfig}from'./chunk-3SPXJEOR.js';import'./chunk-5M6FUMUK.js';import'./chunk-DO5TZLF5.js';//# sourceMappingURL=server.js.map
|
|
2
2
|
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {c as c$1,a}from'./chunk-DRDY7GOT.js';import'./chunk-GZI4X3CV.js';import'./chunk-3SPXJEOR.js';import {p}from'./chunk-R6OOTUGO.js';import'./chunk-5M6FUMUK.js';import'./chunk-DO5TZLF5.js';function c(){return p(async(t,s)=>{let r=c$1();if(!r)throw new Error(`callMethod('${t}') was invoked during SSR but no request context is active. Wrap the render in runWithSsrContext().`);return a(t,s,r.callContext)})}export{c as installSsrCallMethodTransport};//# sourceMappingURL=transport-ZSBKZIXH.js.map
|
|
2
|
+
//# sourceMappingURL=transport-ZSBKZIXH.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ssr/transport.ts"],"names":["installSsrCallMethodTransport","_setCallMethodTransport","methodName","args","ssrCtx","getSsrContext","callInProcessMethod"],"mappings":"iMAKO,SAASA,CAAAA,EAA4C,CAC1D,OAAOC,CAAAA,CAAwB,MAAUC,CAAAA,CAAoBC,CAAAA,GAAqB,CAChF,IAAMC,CAAAA,CAASC,GAAAA,EAAc,CAC7B,GAAI,CAACD,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,CAAA,YAAA,EAAeF,CAAU,CAAA,mGAAA,CAE3B,CAAA,CAGF,OAAOI,CAAAA,CAAuBJ,CAAAA,CAAYC,CAAAA,CAAMC,CAAAA,CAAO,WAAW,CACpE,CAAC,CACH","file":"transport-
|
|
1
|
+
{"version":3,"sources":["../src/ssr/transport.ts"],"names":["installSsrCallMethodTransport","_setCallMethodTransport","methodName","args","ssrCtx","getSsrContext","callInProcessMethod"],"mappings":"iMAKO,SAASA,CAAAA,EAA4C,CAC1D,OAAOC,CAAAA,CAAwB,MAAUC,CAAAA,CAAoBC,CAAAA,GAAqB,CAChF,IAAMC,CAAAA,CAASC,GAAAA,EAAc,CAC7B,GAAI,CAACD,CAAAA,CACH,MAAM,IAAI,KAAA,CACR,CAAA,YAAA,EAAeF,CAAU,CAAA,mGAAA,CAE3B,CAAA,CAGF,OAAOI,CAAAA,CAAuBJ,CAAAA,CAAYC,CAAAA,CAAMC,CAAAA,CAAO,WAAW,CACpE,CAAC,CACH","file":"transport-ZSBKZIXH.js","sourcesContent":["import { _setCallMethodTransport, type MethodArgs } from '../client/method';\nimport { callInProcessMethod } from './callInProcess';\nimport { getSsrContext } from './context';\n\n/** Routes `callMethod` through `runMethod` in-process during SSR. */\nexport function installSsrCallMethodTransport(): () => void {\n return _setCallMethodTransport(async <T>(methodName: string, args: MethodArgs) => {\n const ssrCtx = getSsrContext();\n if (!ssrCtx) {\n throw new Error(\n `callMethod('${methodName}') was invoked during SSR but no request context is active. ` +\n `Wrap the render in runWithSsrContext().`\n );\n }\n\n return callInProcessMethod<T>(methodName, args, ssrCtx.callContext);\n });\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './index-BBMsjrFN.js';
|
|
2
|
-
import { o as Context } from './types-
|
|
2
|
+
import { o as Context } from './types-DANNMU1V.js';
|
|
3
3
|
import * as mongodb from 'mongodb';
|
|
4
4
|
import { WithId, IndexDescription, SearchIndexDescription, MongoClient, Collection, FilterOperators, Document, FindOptions, ObjectId, SortDirection, OptionalUnlessRequiredId, ClientSession, InsertOneResult, InsertManyResult, UpdateFilter, UpdateResult, DeleteResult, FindOneAndUpdateOptions, FindOneAndDeleteOptions, WithoutId, FindOneAndReplaceOptions, ReplaceOptions, DistinctOptions, ChangeStreamOptions, ChangeStream, AggregateOptions, AggregationCursor, AnyBulkWriteOperation, BulkWriteResult } from 'mongodb';
|
|
5
5
|
import { z, ZodNumber, ZodArray } from 'zod';
|
|
@@ -507,7 +507,7 @@ declare class Store<TSchema extends ModelSchema, TMethods extends Record<string,
|
|
|
507
507
|
* @param selector - The selector to find the document to delete
|
|
508
508
|
* @returns The result of the delete operation
|
|
509
509
|
*/
|
|
510
|
-
deleteOne(selector: TypedFilter<this['_type']
|
|
510
|
+
deleteOne(selector: TypedFilter<this['_type']> | string | ObjectId, options?: {
|
|
511
511
|
session?: ClientSession;
|
|
512
512
|
}): Promise<DeleteResult>;
|
|
513
513
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Server } from 'http';
|
|
2
2
|
import { Document, ObjectId } from 'mongodb';
|
|
3
|
-
import { Response } from 'express';
|
|
3
|
+
import { Request, Response } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The available types for module configuration values.
|
|
@@ -189,6 +189,11 @@ type Context = {
|
|
|
189
189
|
roles: string[];
|
|
190
190
|
clientInfo: ClientInfo;
|
|
191
191
|
connectionInfo: ConnectionInfo;
|
|
192
|
+
/**
|
|
193
|
+
* The Express request. `null` for in-process invocations that don't have
|
|
194
|
+
* an active HTTP request (e.g. background jobs).
|
|
195
|
+
*/
|
|
196
|
+
req?: Request | null;
|
|
192
197
|
/**
|
|
193
198
|
* The Express response. Used by auth handlers to set/clear cookies so
|
|
194
199
|
* server-rendered requests can read the auth token from the cookie jar.
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { A as AppServer, a as AppServerInitOptions, E as ExpressMiddleware, M as ModelenceConfig } from './index-BBMsjrFN.js';
|
|
2
|
-
export { A as AnyMethodShape, k as AppConfig, p as Args, h as AuthErrorProps, q as AuthProvider, g as AuthSuccessProps, r as ClientInfo, b as ConfigKey, c as ConfigParams, C as ConfigSchema, d as ConfigType, s as Configs, t as ConnectionInfo, o as Context, D as DefaultRoles, H as Handler, u as Method, M as MethodDefinition, v as MethodType, j as OAuthErrorInfo, O as OAuthProvider, P as Permission, n as Role, R as RoleDefinition, w as SUPPORTED_OAUTH_PROVIDERS, l as Session, f as SignupProps, U as UpdateProfileProps, i as User, x as UserEmail, m as UserInfo, V as ValueType, W as WebsocketClientProvider, a as WebsocketServerProvider } from './types-
|
|
3
|
-
export { B as BodyConfig, g as CronJob, C as CronJobInputParams, h as CronJobMetadata, i as EmailAttachment, c as EmailPayload, E as EmailProvider, j as ExpressHandler, H as HttpMethod, I as InferDocumentType, M as ModelSchema, a as RateLimitRule, b as RateLimitType, R as RouteDefinition, d as RouteHandler, k as RouteHandlers, e as RouteParams, f as RouteResponse, s as schema } from './types-
|
|
2
|
+
export { A as AnyMethodShape, k as AppConfig, p as Args, h as AuthErrorProps, q as AuthProvider, g as AuthSuccessProps, r as ClientInfo, b as ConfigKey, c as ConfigParams, C as ConfigSchema, d as ConfigType, s as Configs, t as ConnectionInfo, o as Context, D as DefaultRoles, H as Handler, u as Method, M as MethodDefinition, v as MethodType, j as OAuthErrorInfo, O as OAuthProvider, P as Permission, n as Role, R as RoleDefinition, w as SUPPORTED_OAUTH_PROVIDERS, l as Session, f as SignupProps, U as UpdateProfileProps, i as User, x as UserEmail, m as UserInfo, V as ValueType, W as WebsocketClientProvider, a as WebsocketServerProvider } from './types-DANNMU1V.js';
|
|
3
|
+
export { B as BodyConfig, g as CronJob, C as CronJobInputParams, h as CronJobMetadata, i as EmailAttachment, c as EmailPayload, E as EmailProvider, j as ExpressHandler, H as HttpMethod, I as InferDocumentType, M as ModelSchema, a as RateLimitRule, b as RateLimitType, R as RouteDefinition, d as RouteHandler, k as RouteHandlers, e as RouteParams, f as RouteResponse, s as schema } from './types-BT2k9L7Q.js';
|
|
4
4
|
import 'express';
|
|
5
5
|
import 'http';
|
|
6
6
|
import 'mongodb';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "modelence",
|
|
4
|
-
"version": "0.18.0-dev.
|
|
4
|
+
"version": "0.18.0-dev.3",
|
|
5
5
|
"description": "The Node.js Framework for Real-Time MongoDB Apps",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/global.d.ts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"lint:check": "eslint src --ext .ts,.tsx",
|
|
33
33
|
"prepublishOnly": "npm run build",
|
|
34
34
|
"bench": "tsx src/bench/index.ts",
|
|
35
|
-
"test": "
|
|
36
|
-
"test:watch": "
|
|
37
|
-
"test:coverage": "
|
|
35
|
+
"test": "vitest run",
|
|
36
|
+
"test:watch": "vitest",
|
|
37
|
+
"test:coverage": "vitest run --coverage",
|
|
38
38
|
"postversion": "git push && git push --tags",
|
|
39
39
|
"prepare": "cd ../.. && git config core.hooksPath .husky"
|
|
40
40
|
},
|
|
@@ -58,7 +58,6 @@
|
|
|
58
58
|
"@types/cookie-parser": "^1.4.9",
|
|
59
59
|
"@types/express": "^5.0.0",
|
|
60
60
|
"@types/fs-extra": "^11.0.4",
|
|
61
|
-
"@types/jest": "^30.0.0",
|
|
62
61
|
"@types/node": "^22.5.1",
|
|
63
62
|
"@types/react": "^19.0.0",
|
|
64
63
|
"@types/react-dom": "^19.0.1",
|
|
@@ -67,13 +66,14 @@
|
|
|
67
66
|
"@typescript-eslint/parser": "^8.17.0",
|
|
68
67
|
"eslint": "^9.37.0",
|
|
69
68
|
"husky": "^9.1.7",
|
|
70
|
-
"jest": "^30.2.0",
|
|
71
69
|
"lint-staged": "^16.2.7",
|
|
72
70
|
"prettier": "^3.6.2",
|
|
73
71
|
"react": "^19.0.0",
|
|
74
72
|
"react-dom": "^19.0.0",
|
|
75
|
-
"ts-
|
|
76
|
-
"
|
|
73
|
+
"ts-node": "^10.9.2",
|
|
74
|
+
"vitest": "^2.1.8",
|
|
75
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
76
|
+
"vite-tsconfig-paths": "^5.1.4"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@socket.io/mongo-adapter": "^0.4.0",
|