nuxt-backend 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +744 -0
- package/dist/convex/auth.config.d.ts +9 -0
- package/dist/convex/auth.config.d.ts.map +1 -0
- package/dist/convex/auth.config.js +14 -0
- package/dist/convex/auth.config.js.map +1 -0
- package/dist/convex/client/index.d.ts +12784 -0
- package/dist/convex/client/index.d.ts.map +1 -0
- package/dist/convex/client/index.js +230 -0
- package/dist/convex/client/index.js.map +1 -0
- package/dist/convex/component/_generated/api.d.ts +36 -0
- package/dist/convex/component/_generated/api.d.ts.map +1 -0
- package/dist/convex/component/_generated/api.js +31 -0
- package/dist/convex/component/_generated/api.js.map +1 -0
- package/dist/convex/component/_generated/component.d.ts +549 -0
- package/dist/convex/component/_generated/component.d.ts.map +1 -0
- package/dist/convex/component/_generated/component.js +11 -0
- package/dist/convex/component/_generated/component.js.map +1 -0
- package/dist/convex/component/_generated/dataModel.d.ts +46 -0
- package/dist/convex/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/convex/component/_generated/dataModel.js +11 -0
- package/dist/convex/component/_generated/dataModel.js.map +1 -0
- package/dist/convex/component/_generated/server.d.ts +121 -0
- package/dist/convex/component/_generated/server.d.ts.map +1 -0
- package/dist/convex/component/_generated/server.js +78 -0
- package/dist/convex/component/_generated/server.js.map +1 -0
- package/dist/convex/component/adapter.d.ts +3 -0
- package/dist/convex/component/adapter.d.ts.map +1 -0
- package/dist/convex/component/adapter.js +23 -0
- package/dist/convex/component/adapter.js.map +1 -0
- package/dist/convex/component/constants.d.ts +3 -0
- package/dist/convex/component/constants.d.ts.map +1 -0
- package/dist/convex/component/constants.js +3 -0
- package/dist/convex/component/constants.js.map +1 -0
- package/dist/convex/component/convex.config.d.ts +14 -0
- package/dist/convex/component/convex.config.d.ts.map +1 -0
- package/dist/convex/component/convex.config.js +15 -0
- package/dist/convex/component/convex.config.js.map +1 -0
- package/dist/convex/component/schema.d.ts +278 -0
- package/dist/convex/component/schema.d.ts.map +1 -0
- package/dist/convex/component/schema.js +91 -0
- package/dist/convex/component/schema.js.map +1 -0
- package/dist/module.d.ts +47 -0
- package/dist/module.js +275 -0
- package/dist/module.json +9 -0
- package/dist/runtime/nuxt/auth/middleware.d.ts +12 -0
- package/dist/runtime/nuxt/auth/middleware.js +31 -0
- package/dist/runtime/nuxt/auth/proxy.d.ts +6 -0
- package/dist/runtime/nuxt/auth/proxy.js +11 -0
- package/dist/runtime/nuxt/auth/server.d.ts +86 -0
- package/dist/runtime/nuxt/auth/server.js +110 -0
- package/dist/runtime/nuxt/config.d.ts +7 -0
- package/dist/runtime/nuxt/config.js +12 -0
- package/dist/runtime/nuxt/index.d.ts +102 -0
- package/dist/runtime/nuxt/index.js +77 -0
- package/dist/runtime/vue/auth/client.d.ts +14 -0
- package/dist/runtime/vue/auth/client.js +7 -0
- package/dist/runtime/vue/auth/cross-domain.d.ts +8 -0
- package/dist/runtime/vue/auth/cross-domain.js +34 -0
- package/dist/runtime/vue/auth/helpers.d.ts +52 -0
- package/dist/runtime/vue/auth/helpers.js +35 -0
- package/dist/runtime/vue/auth/hydration.d.ts +14 -0
- package/dist/runtime/vue/auth/hydration.js +23 -0
- package/dist/runtime/vue/auth/index.d.ts +79 -0
- package/dist/runtime/vue/auth/index.js +81 -0
- package/dist/runtime/vue/auth/plugin.client.d.ts +6 -0
- package/dist/runtime/vue/auth/plugin.client.js +30 -0
- package/dist/runtime/vue/auth/plugin.server.d.ts +17 -0
- package/dist/runtime/vue/auth/plugin.server.js +29 -0
- package/dist/runtime/vue/auth/use-auth.d.ts +84 -0
- package/dist/runtime/vue/auth/use-auth.js +77 -0
- package/dist/runtime/vue/client.d.ts +245 -0
- package/dist/runtime/vue/client.js +341 -0
- package/dist/runtime/vue/composables/use-action.d.ts +45 -0
- package/dist/runtime/vue/composables/use-action.js +10 -0
- package/dist/runtime/vue/composables/use-connection-state.d.ts +25 -0
- package/dist/runtime/vue/composables/use-connection-state.js +13 -0
- package/dist/runtime/vue/composables/use-mutation.d.ts +60 -0
- package/dist/runtime/vue/composables/use-mutation.js +36 -0
- package/dist/runtime/vue/composables/use-paginated-query.d.ts +101 -0
- package/dist/runtime/vue/composables/use-paginated-query.js +508 -0
- package/dist/runtime/vue/composables/use-queries.d.ts +45 -0
- package/dist/runtime/vue/composables/use-queries.js +32 -0
- package/dist/runtime/vue/composables/use-query.d.ts +82 -0
- package/dist/runtime/vue/composables/use-query.js +63 -0
- package/dist/runtime/vue/composables/use-subscription.d.ts +14 -0
- package/dist/runtime/vue/composables/use-subscription.js +15 -0
- package/dist/runtime/vue/hydration.d.ts +42 -0
- package/dist/runtime/vue/hydration.js +18 -0
- package/dist/runtime/vue/index.d.ts +29 -0
- package/dist/runtime/vue/index.js +38 -0
- package/dist/runtime/vue/queries-observer.d.ts +38 -0
- package/dist/runtime/vue/queries-observer.js +127 -0
- package/dist/types.d.ts +3 -0
- package/package.json +157 -0
- package/src/convex/auth.config.ts +21 -0
- package/src/convex/client/index.ts +329 -0
- package/src/convex/component/_generated/api.ts +52 -0
- package/src/convex/component/_generated/component.ts +1338 -0
- package/src/convex/component/_generated/dataModel.ts +60 -0
- package/src/convex/component/_generated/server.ts +156 -0
- package/src/convex/component/adapter.ts +42 -0
- package/src/convex/component/constants.ts +2 -0
- package/src/convex/component/convex.config.ts +16 -0
- package/src/convex/component/schema.ts +93 -0
- package/src/convex/test.ts +34 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { makeFunctionReference } from "convex/server";
|
|
2
|
+
import { computed, shallowRef, toValue, watchEffect } from "vue";
|
|
3
|
+
import { useConvexQueries } from "./use-queries.js";
|
|
4
|
+
export function useQuery(query, ...args) {
|
|
5
|
+
const queryReference = typeof query === "string" ? makeFunctionReference(query) : query;
|
|
6
|
+
const argsGetter = args[0] ?? {};
|
|
7
|
+
const queriesInput = computed(() => {
|
|
8
|
+
const currentArgs = toValue(argsGetter);
|
|
9
|
+
if (currentArgs === "skip") {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
query: {
|
|
14
|
+
query: queryReference,
|
|
15
|
+
args: currentArgs
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
const allResults = useConvexQueries(queriesInput);
|
|
20
|
+
const result = shallowRef(void 0);
|
|
21
|
+
watchEffect(() => {
|
|
22
|
+
const r = allResults.value.query;
|
|
23
|
+
if (r instanceof Error) throw r;
|
|
24
|
+
result.value = r;
|
|
25
|
+
});
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export function useQuery_experimental(options) {
|
|
29
|
+
const throwOnError = options.throwOnError ?? false;
|
|
30
|
+
const queryReference = typeof options.query === "string" ? makeFunctionReference(options.query) : options.query;
|
|
31
|
+
const argsGetter = options.args;
|
|
32
|
+
const queriesInput = computed(() => {
|
|
33
|
+
const currentArgs = toValue(argsGetter);
|
|
34
|
+
if (currentArgs === "skip") {
|
|
35
|
+
return {};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
query: {
|
|
39
|
+
query: queryReference,
|
|
40
|
+
args: currentArgs
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
const allResults = useConvexQueries(queriesInput);
|
|
45
|
+
const result = shallowRef({
|
|
46
|
+
status: "pending"
|
|
47
|
+
});
|
|
48
|
+
watchEffect(() => {
|
|
49
|
+
const r = allResults.value.query;
|
|
50
|
+
if (r instanceof Error) {
|
|
51
|
+
if (throwOnError) throw r;
|
|
52
|
+
result.value = { error: r, status: "error" };
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (r === void 0) {
|
|
56
|
+
result.value = { status: "pending" };
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
result.value = { data: r, status: "success" };
|
|
60
|
+
});
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
export const useConvexQuery = useQuery;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ShallowRef } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Bridge an arbitrary subscription source into Vue reactivity.
|
|
4
|
+
*
|
|
5
|
+
* Useful when integrating external pub/sub APIs that follow the
|
|
6
|
+
* `{ getCurrentValue, subscribe }` pattern. The returned shallow ref updates
|
|
7
|
+
* whenever the subscription fires.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export declare function useSubscription<T>({ getCurrentValue, subscribe, }: {
|
|
12
|
+
getCurrentValue: () => T;
|
|
13
|
+
subscribe: (callback: () => void) => () => void;
|
|
14
|
+
}): ShallowRef<T>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { shallowRef, watchEffect } from "vue";
|
|
2
|
+
export function useSubscription({
|
|
3
|
+
getCurrentValue,
|
|
4
|
+
subscribe
|
|
5
|
+
}) {
|
|
6
|
+
const value = shallowRef(getCurrentValue());
|
|
7
|
+
watchEffect((onCleanup) => {
|
|
8
|
+
value.value = getCurrentValue();
|
|
9
|
+
const unsubscribe = subscribe(() => {
|
|
10
|
+
value.value = getCurrentValue();
|
|
11
|
+
});
|
|
12
|
+
onCleanup(unsubscribe);
|
|
13
|
+
});
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { FunctionReference, FunctionReturnType } from 'convex/server';
|
|
2
|
+
import { type ShallowRef } from 'vue';
|
|
3
|
+
/**
|
|
4
|
+
* The preloaded query payload, which should be passed to a client component
|
|
5
|
+
* and used with {@link usePreloadedQuery}.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export type Preloaded<Query extends FunctionReference<'query'>> = {
|
|
10
|
+
__type: Query;
|
|
11
|
+
_name: string;
|
|
12
|
+
_argsJSON: string;
|
|
13
|
+
_valueJSON: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Load a reactive query within a Vue component using a `Preloaded` payload
|
|
17
|
+
* from a server-side preload.
|
|
18
|
+
*
|
|
19
|
+
* This composable subscribes to the same query and reactively updates
|
|
20
|
+
* when the result changes. Initially returns the preloaded server result
|
|
21
|
+
* for instant display.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```vue
|
|
25
|
+
* <script setup lang="ts">
|
|
26
|
+
* import { usePreloadedQuery } from '#imports'
|
|
27
|
+
*
|
|
28
|
+
* const props = defineProps<{
|
|
29
|
+
* preloaded: Preloaded<typeof api.tasks.list>
|
|
30
|
+
* }>()
|
|
31
|
+
*
|
|
32
|
+
* const tasks = usePreloadedQuery(props.preloaded)
|
|
33
|
+
* </script>
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @param preloadedQuery - The `Preloaded` payload from server-side preloading.
|
|
37
|
+
* @returns A shallow ref that initially contains the preloaded data and
|
|
38
|
+
* subsequently updates with live query results.
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare function usePreloadedQuery<Query extends FunctionReference<'query'>>(preloadedQuery: Preloaded<Query>): ShallowRef<FunctionReturnType<Query>>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { makeFunctionReference } from "convex/server";
|
|
2
|
+
import { jsonToConvex } from "convex/values";
|
|
3
|
+
import { computed, shallowRef } from "vue";
|
|
4
|
+
import { useQuery } from "./composables/use-query.js";
|
|
5
|
+
export function usePreloadedQuery(preloadedQuery) {
|
|
6
|
+
const args = jsonToConvex(preloadedQuery._argsJSON);
|
|
7
|
+
const preloadedResult = jsonToConvex(preloadedQuery._valueJSON);
|
|
8
|
+
if (import.meta.server) {
|
|
9
|
+
return shallowRef(preloadedResult);
|
|
10
|
+
}
|
|
11
|
+
const result = useQuery(
|
|
12
|
+
makeFunctionReference(preloadedQuery._name),
|
|
13
|
+
args
|
|
14
|
+
);
|
|
15
|
+
return computed(() => {
|
|
16
|
+
return result.value === void 0 ? preloadedResult : result.value;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools to integrate Convex into Vue applications.
|
|
3
|
+
*
|
|
4
|
+
* This module contains:
|
|
5
|
+
* 1. {@link ConvexVueClient}, a client for using Convex in Vue.
|
|
6
|
+
* 2. {@link ConvexClientKey}, a Vue injection key for providing the client.
|
|
7
|
+
* 3. {@link Authenticated}, {@link Unauthenticated} and {@link AuthLoading} helper auth components.
|
|
8
|
+
* 4. Composables {@link useQuery}, {@link useMutation}, {@link useAction} and more.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
export { ConvexVueClient, ConvexClientKey, useConvex, type Watch, type PaginatedWatch, type WatchQueryOptions, type VueMutationOptions, type ConvexVueClientOptions, } from './client.js';
|
|
13
|
+
export type { AuthTokenFetcher, ConnectionState, OptimisticUpdate, QueryJournal, QueryOptions, } from 'convex/browser';
|
|
14
|
+
export type { FunctionReference, FunctionArgs, FunctionReturnType, OptionalRestArgs, ArgsAndOptions, } from 'convex/server';
|
|
15
|
+
export type { Value } from 'convex/values';
|
|
16
|
+
export { useConvexQueries, useQueries, type RequestForQueries, } from './composables/use-queries.js';
|
|
17
|
+
export { useQuery, useQuery_experimental, useConvexQuery, type UseQueryResult, type OptionalRestArgsOrSkip, } from './composables/use-query.js';
|
|
18
|
+
export { useMutation, useConvexMutation, type VueMutation, } from './composables/use-mutation.js';
|
|
19
|
+
export type { VueMutationOptions as MutationOptions } from './client.js';
|
|
20
|
+
export { useAction, useConvexAction, type VueAction, } from './composables/use-action.js';
|
|
21
|
+
export * from './composables/use-paginated-query.js';
|
|
22
|
+
export { useConvexConnectionState } from './composables/use-connection-state.js';
|
|
23
|
+
export { useConvexAuth, provideConvexAuth, createConvexAuthState, createScopedConvexAuthState, ConvexAuthStateKey, type ConvexAuthState, type ConvexAuthProviderOptions, } from './auth/index.js';
|
|
24
|
+
export { Authenticated, Unauthenticated, AuthLoading } from './auth/helpers.js';
|
|
25
|
+
export { useAuth, type UseAuthService, type AuthSession } from './auth/use-auth.js';
|
|
26
|
+
export type { AuthClient } from './auth/client.js';
|
|
27
|
+
export { usePreloadedQuery, type Preloaded, } from './hydration.js';
|
|
28
|
+
export { usePreloadedAuthQuery } from './auth/hydration.js';
|
|
29
|
+
export { useSubscription } from './composables/use-subscription.js';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ConvexVueClient,
|
|
3
|
+
ConvexClientKey,
|
|
4
|
+
useConvex
|
|
5
|
+
} from "./client.js";
|
|
6
|
+
export {
|
|
7
|
+
useConvexQueries,
|
|
8
|
+
useQueries
|
|
9
|
+
} from "./composables/use-queries.js";
|
|
10
|
+
export {
|
|
11
|
+
useQuery,
|
|
12
|
+
useQuery_experimental,
|
|
13
|
+
useConvexQuery
|
|
14
|
+
} from "./composables/use-query.js";
|
|
15
|
+
export {
|
|
16
|
+
useMutation,
|
|
17
|
+
useConvexMutation
|
|
18
|
+
} from "./composables/use-mutation.js";
|
|
19
|
+
export {
|
|
20
|
+
useAction,
|
|
21
|
+
useConvexAction
|
|
22
|
+
} from "./composables/use-action.js";
|
|
23
|
+
export * from "./composables/use-paginated-query.js";
|
|
24
|
+
export { useConvexConnectionState } from "./composables/use-connection-state.js";
|
|
25
|
+
export {
|
|
26
|
+
useConvexAuth,
|
|
27
|
+
provideConvexAuth,
|
|
28
|
+
createConvexAuthState,
|
|
29
|
+
createScopedConvexAuthState,
|
|
30
|
+
ConvexAuthStateKey
|
|
31
|
+
} from "./auth/index.js";
|
|
32
|
+
export { Authenticated, Unauthenticated, AuthLoading } from "./auth/helpers.js";
|
|
33
|
+
export { useAuth } from "./auth/use-auth.js";
|
|
34
|
+
export {
|
|
35
|
+
usePreloadedQuery
|
|
36
|
+
} from "./hydration.js";
|
|
37
|
+
export { usePreloadedAuthQuery } from "./auth/hydration.js";
|
|
38
|
+
export { useSubscription } from "./composables/use-subscription.js";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { QueryJournal } from 'convex/browser';
|
|
2
|
+
import type { FunctionReference } from 'convex/server';
|
|
3
|
+
import type { Value } from 'convex/values';
|
|
4
|
+
import type { Watch, PaginatedWatch } from './client.js';
|
|
5
|
+
import type { RequestForQueries } from 'convex/react';
|
|
6
|
+
type Identifier = string;
|
|
7
|
+
export interface CreateWatch {
|
|
8
|
+
(query: FunctionReference<'query'>, args: Record<string, Value>, options: {
|
|
9
|
+
journal?: QueryJournal;
|
|
10
|
+
paginationOptions?: unknown;
|
|
11
|
+
}): Watch<Value> | PaginatedWatch<Value>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Tracks subscriptions for a dynamic set of Convex queries and notifies
|
|
15
|
+
* listeners whenever any result changes.
|
|
16
|
+
*
|
|
17
|
+
* Framework-agnostic: the composables layer ({@link useConvexQueries}) wraps
|
|
18
|
+
* this class with Vue reactivity.
|
|
19
|
+
*/
|
|
20
|
+
export declare class QueriesObserver {
|
|
21
|
+
createWatch: CreateWatch;
|
|
22
|
+
private queries;
|
|
23
|
+
private listeners;
|
|
24
|
+
constructor(createWatch: CreateWatch);
|
|
25
|
+
setQueries(newQueries: Record<Identifier, {
|
|
26
|
+
query: FunctionReference<'query'>;
|
|
27
|
+
args: Record<string, Value>;
|
|
28
|
+
paginationOptions?: unknown;
|
|
29
|
+
}>): void;
|
|
30
|
+
subscribe(listener: () => void): () => void;
|
|
31
|
+
getLocalResults(queries: RequestForQueries): Record<Identifier, Value | undefined | Error | unknown>;
|
|
32
|
+
setCreateWatch(createWatch: CreateWatch): void;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
private addQuery;
|
|
35
|
+
private removeQuery;
|
|
36
|
+
private notifyListeners;
|
|
37
|
+
}
|
|
38
|
+
export type { RequestForQueries } from 'convex/react';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { getFunctionName } from "convex/server";
|
|
2
|
+
import { convexToJson } from "convex/values";
|
|
3
|
+
export class QueriesObserver {
|
|
4
|
+
createWatch;
|
|
5
|
+
queries;
|
|
6
|
+
listeners;
|
|
7
|
+
constructor(createWatch) {
|
|
8
|
+
this.createWatch = createWatch;
|
|
9
|
+
this.queries = {};
|
|
10
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
11
|
+
}
|
|
12
|
+
setQueries(newQueries) {
|
|
13
|
+
for (const identifier of Object.keys(newQueries)) {
|
|
14
|
+
const { query, args, paginationOptions } = newQueries[identifier];
|
|
15
|
+
getFunctionName(query);
|
|
16
|
+
if (this.queries[identifier] === void 0) {
|
|
17
|
+
this.addQuery(
|
|
18
|
+
identifier,
|
|
19
|
+
query,
|
|
20
|
+
args,
|
|
21
|
+
paginationOptions ? { paginationOptions } : {}
|
|
22
|
+
);
|
|
23
|
+
} else {
|
|
24
|
+
const existingInfo = this.queries[identifier];
|
|
25
|
+
if (getFunctionName(query) !== getFunctionName(existingInfo.query) || JSON.stringify(convexToJson(args)) !== JSON.stringify(convexToJson(existingInfo.args)) || JSON.stringify(paginationOptions) !== JSON.stringify(existingInfo.paginationOptions)) {
|
|
26
|
+
this.removeQuery(identifier);
|
|
27
|
+
this.addQuery(
|
|
28
|
+
identifier,
|
|
29
|
+
query,
|
|
30
|
+
args,
|
|
31
|
+
paginationOptions ? { paginationOptions } : {}
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
for (const identifier of Object.keys(this.queries)) {
|
|
37
|
+
if (newQueries[identifier] === void 0) {
|
|
38
|
+
this.removeQuery(identifier);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
subscribe(listener) {
|
|
43
|
+
this.listeners.add(listener);
|
|
44
|
+
return () => {
|
|
45
|
+
this.listeners.delete(listener);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
getLocalResults(queries) {
|
|
49
|
+
const result = {};
|
|
50
|
+
for (const identifier of Object.keys(queries)) {
|
|
51
|
+
const entry = queries[identifier];
|
|
52
|
+
const { query, args } = entry;
|
|
53
|
+
const paginationOptions = entry.paginationOptions;
|
|
54
|
+
getFunctionName(query);
|
|
55
|
+
const watch = this.createWatch(
|
|
56
|
+
query,
|
|
57
|
+
args,
|
|
58
|
+
paginationOptions ? { paginationOptions } : {}
|
|
59
|
+
);
|
|
60
|
+
let value;
|
|
61
|
+
try {
|
|
62
|
+
value = watch.localQueryResult();
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if (e instanceof Error) {
|
|
65
|
+
value = e;
|
|
66
|
+
} else {
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
result[identifier] = value;
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
setCreateWatch(createWatch) {
|
|
75
|
+
this.createWatch = createWatch;
|
|
76
|
+
for (const identifier of Object.keys(this.queries)) {
|
|
77
|
+
const { query, args, watch, paginationOptions } = this.queries[identifier];
|
|
78
|
+
const journal = "journal" in watch ? watch.journal() : void 0;
|
|
79
|
+
this.removeQuery(identifier);
|
|
80
|
+
this.addQuery(identifier, query, args, {
|
|
81
|
+
...journal ? { journal } : {},
|
|
82
|
+
...paginationOptions ? { paginationOptions } : {}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
destroy() {
|
|
87
|
+
for (const identifier of Object.keys(this.queries)) {
|
|
88
|
+
this.removeQuery(identifier);
|
|
89
|
+
}
|
|
90
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
91
|
+
}
|
|
92
|
+
addQuery(identifier, query, args, {
|
|
93
|
+
paginationOptions,
|
|
94
|
+
journal
|
|
95
|
+
}) {
|
|
96
|
+
if (this.queries[identifier] !== void 0) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`Tried to add a new query with identifier ${identifier} when it already exists.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const watch = this.createWatch(query, args, {
|
|
102
|
+
...journal ? { journal } : {},
|
|
103
|
+
...paginationOptions ? { paginationOptions } : {}
|
|
104
|
+
});
|
|
105
|
+
const unsubscribe = watch.onUpdate(() => this.notifyListeners());
|
|
106
|
+
this.queries[identifier] = {
|
|
107
|
+
query,
|
|
108
|
+
args,
|
|
109
|
+
watch,
|
|
110
|
+
unsubscribe,
|
|
111
|
+
...paginationOptions ? { paginationOptions } : {}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
removeQuery(identifier) {
|
|
115
|
+
const info = this.queries[identifier];
|
|
116
|
+
if (info === void 0) {
|
|
117
|
+
throw new Error(`No query found with identifier ${identifier}.`);
|
|
118
|
+
}
|
|
119
|
+
info.unsubscribe();
|
|
120
|
+
delete this.queries[identifier];
|
|
121
|
+
}
|
|
122
|
+
notifyListeners() {
|
|
123
|
+
for (const listener of this.listeners) {
|
|
124
|
+
listener();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
package/dist/types.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
+
"name": "nuxt-backend",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "Nuxt module and Convex component for a full-stack Convex backend with authentication",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/qruto/nuxt-backend.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "Slava Razum <razum@qruto.to>",
|
|
12
|
+
"homepage": "https://github.com/qruto/nuxt-backend#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/qruto/nuxt-backend/issues"
|
|
15
|
+
},
|
|
16
|
+
"funding": {
|
|
17
|
+
"type": "github",
|
|
18
|
+
"url": "https://github.com/sponsors/qruto"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"nuxt",
|
|
22
|
+
"nuxt-module",
|
|
23
|
+
"convex",
|
|
24
|
+
"authentication",
|
|
25
|
+
"auth",
|
|
26
|
+
"better-auth",
|
|
27
|
+
"backend",
|
|
28
|
+
"fullstack"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
"./package.json": "./package.json",
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/types.d.ts",
|
|
35
|
+
"import": "./dist/module.js"
|
|
36
|
+
},
|
|
37
|
+
"./convex": {
|
|
38
|
+
"types": "./dist/convex/client/index.d.ts",
|
|
39
|
+
"default": "./dist/convex/client/index.js"
|
|
40
|
+
},
|
|
41
|
+
"./convex/component/_generated/component": {
|
|
42
|
+
"types": "./dist/convex/component/_generated/component.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./convex/component/convex.config": {
|
|
45
|
+
"types": "./dist/convex/component/convex.config.d.ts",
|
|
46
|
+
"default": "./dist/convex/component/convex.config.js"
|
|
47
|
+
},
|
|
48
|
+
"./convex/component/schema": {
|
|
49
|
+
"types": "./dist/convex/component/schema.d.ts",
|
|
50
|
+
"default": "./dist/convex/component/schema.js"
|
|
51
|
+
},
|
|
52
|
+
"./convex/auth.config": {
|
|
53
|
+
"types": "./dist/convex/auth.config.d.ts",
|
|
54
|
+
"default": "./dist/convex/auth.config.js"
|
|
55
|
+
},
|
|
56
|
+
"./convex/test": "./src/convex/test.ts"
|
|
57
|
+
},
|
|
58
|
+
"main": "./dist/module.js",
|
|
59
|
+
"typesVersions": {
|
|
60
|
+
"*": {
|
|
61
|
+
".": [
|
|
62
|
+
"./dist/types.d.ts"
|
|
63
|
+
],
|
|
64
|
+
"convex": [
|
|
65
|
+
"./dist/convex/client/index.d.ts"
|
|
66
|
+
],
|
|
67
|
+
"convex/component/_generated/component": [
|
|
68
|
+
"./dist/convex/component/_generated/component.d.ts"
|
|
69
|
+
],
|
|
70
|
+
"convex/component/convex.config": [
|
|
71
|
+
"./dist/convex/component/convex.config.d.ts"
|
|
72
|
+
],
|
|
73
|
+
"convex/component/schema": [
|
|
74
|
+
"./dist/convex/component/schema.d.ts"
|
|
75
|
+
],
|
|
76
|
+
"convex/auth.config": [
|
|
77
|
+
"./dist/convex/auth.config.d.ts"
|
|
78
|
+
],
|
|
79
|
+
"convex/test": [
|
|
80
|
+
"./src/convex/test.ts"
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"files": [
|
|
85
|
+
"dist",
|
|
86
|
+
"src/convex"
|
|
87
|
+
],
|
|
88
|
+
"engines": {
|
|
89
|
+
"node": ">=20.19.0",
|
|
90
|
+
"pnpm": ">=11"
|
|
91
|
+
},
|
|
92
|
+
"dependencies": {
|
|
93
|
+
"@better-auth/passkey": "~1.6.11",
|
|
94
|
+
"@convex-dev/better-auth": "^0.12.2",
|
|
95
|
+
"@nuxt/kit": "^4.4.5",
|
|
96
|
+
"better-auth": "~1.6.11",
|
|
97
|
+
"convex": "^1.40.0",
|
|
98
|
+
"dedent": "^1.7.2"
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"@edge-runtime/vm": "^5.0.0",
|
|
102
|
+
"@nuxt/devtools": "^3.2.4",
|
|
103
|
+
"@nuxt/eslint": "^1.15.2",
|
|
104
|
+
"@nuxt/eslint-config": "^1.15.2",
|
|
105
|
+
"@nuxt/module-builder": "^1.0.2",
|
|
106
|
+
"@nuxt/schema": "^4.4.5",
|
|
107
|
+
"@nuxt/test-utils": "^4.0.3",
|
|
108
|
+
"@types/node": "latest",
|
|
109
|
+
"@unhead/vue": "^3.1.0",
|
|
110
|
+
"@vue/test-utils": "^2.4.10",
|
|
111
|
+
"changelogen": "^0.6.2",
|
|
112
|
+
"changelogithub": "^14.0.0",
|
|
113
|
+
"chokidar-cli": "^3.0.0",
|
|
114
|
+
"convex-test": "^0.0.52",
|
|
115
|
+
"eslint": "^10.4.0",
|
|
116
|
+
"fallow": "^2.80.0",
|
|
117
|
+
"happy-dom": "^20.9.0",
|
|
118
|
+
"npm-run-all2": "^8.0.4",
|
|
119
|
+
"nuxt": "^4.4.5",
|
|
120
|
+
"oxc-parser": "^0.131.0",
|
|
121
|
+
"portless": "^0.13.0",
|
|
122
|
+
"typescript": "~6.0.3",
|
|
123
|
+
"vitest": "^4.1.6",
|
|
124
|
+
"vue-tsc": "^3.2.9",
|
|
125
|
+
"ws": "^8.20.0"
|
|
126
|
+
},
|
|
127
|
+
"publishConfig": {
|
|
128
|
+
"access": "public"
|
|
129
|
+
},
|
|
130
|
+
"scripts": {
|
|
131
|
+
"preinstall": "npx -y only-allow pnpm",
|
|
132
|
+
"build": "pnpm run build:nuxt-module && pnpm run build:convex-component",
|
|
133
|
+
"build:nuxt-module": "nuxt-module-build build && node scripts/normalize-module-ext.js",
|
|
134
|
+
"build:convex-component": "tsc --project ./tsconfig.convex-component.build.json && node -e \"require('fs').utimesSync('playground/backend/convex.config.ts', new Date(), new Date())\"",
|
|
135
|
+
"dev": "pnpm run dev:prepare && pnpm run build:convex-component && run-p -r 'dev:convex-component' 'dev:nuxt-module'",
|
|
136
|
+
"dev:convex-component": "convex dev --typecheck-components --start 'pnpm run dev:convex-component:watch'",
|
|
137
|
+
"dev:convex-component:codegen": "convex codegen --component-dir ./src/convex/component",
|
|
138
|
+
"dev:convex-component:watch": "chokidar 'tsconfig*.json' 'src/convex/**/*.ts' -i '**/*.test.ts' -i 'src/convex/component/_generated/**' -c 'pnpm run dev:convex-component:codegen && pnpm run build:convex-component' --initial",
|
|
139
|
+
"dev:nuxt-module": "TMPDIR=/tmp portless nuxt-backend nuxt dev playground",
|
|
140
|
+
"dev:nuxt-module:build": "nuxt build playground",
|
|
141
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && node scripts/normalize-module-ext.js && nuxt prepare playground",
|
|
142
|
+
"dev:nuxt-module:prepare": "pnpm run dev:prepare",
|
|
143
|
+
"lint": "eslint .",
|
|
144
|
+
"lint:fix": "eslint . --fix",
|
|
145
|
+
"test": "vitest --run",
|
|
146
|
+
"test:watch": "vitest --watch",
|
|
147
|
+
"test:types": "pnpm run test:types:lib && cd playground && vue-tsc --noEmit",
|
|
148
|
+
"test:types:lib": "pnpm run dev:prepare && pnpm run build:convex-component && vue-tsc --noEmit && tsc --noEmit -p tsconfig.convex.json",
|
|
149
|
+
"test:unit": "vitest --project unit --run",
|
|
150
|
+
"test:nuxt": "vitest --project nuxt --run",
|
|
151
|
+
"test:e2e": "vitest --project e2e --run",
|
|
152
|
+
"test:convex-component": "vitest --project convex-component --run",
|
|
153
|
+
"test:quality": "fallow --summary",
|
|
154
|
+
"bump": "pnpm exec taze major -w",
|
|
155
|
+
"db:reset": "node scripts/db-reset.js"
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getAuthConfigProvider } from '@convex-dev/better-auth/auth-config'
|
|
2
|
+
import type { AuthConfig } from 'convex/server'
|
|
3
|
+
import { DEFAULT_AUTH_ROUTE } from './component/constants'
|
|
4
|
+
|
|
5
|
+
export interface DefineBackendAuthConfigOptions {
|
|
6
|
+
basePath?: string
|
|
7
|
+
jwks?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function defineBackendAuthConfig(options: DefineBackendAuthConfigOptions = {}): AuthConfig {
|
|
11
|
+
return {
|
|
12
|
+
providers: [
|
|
13
|
+
getAuthConfigProvider({
|
|
14
|
+
basePath: options.basePath ?? DEFAULT_AUTH_ROUTE,
|
|
15
|
+
jwks: options.jwks,
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default defineBackendAuthConfig()
|