naystack 1.4.9 → 1.4.11
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/README.md +7 -16
- package/dist/auth/email/client.cjs.js +6 -6
- package/dist/auth/email/client.d.mts +3 -3
- package/dist/auth/email/client.d.ts +3 -3
- package/dist/auth/email/client.esm.js +4 -4
- package/dist/graphql/utils.d.mts +13 -16
- package/dist/graphql/utils.d.ts +13 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,17 +59,15 @@ Wrap your application with `AuthWrapper` in your root layout or a client compone
|
|
|
59
59
|
```typescript
|
|
60
60
|
// gql/client.ts
|
|
61
61
|
"use client";
|
|
62
|
-
import {
|
|
62
|
+
import { AuthWrapper } from "naystack/auth/email/client";
|
|
63
63
|
|
|
64
|
-
export const AuthWrapper = getAuthWrapper("/api/email");
|
|
65
64
|
```
|
|
66
65
|
|
|
67
66
|
### Frontend Usage
|
|
68
67
|
|
|
69
68
|
```typescript
|
|
70
|
-
import {
|
|
69
|
+
import { useLogin, useSignUp, useLogout, useToken } from "naystack/auth/email/client";
|
|
71
70
|
|
|
72
|
-
const { useLogin, useSignUp, useLogout } = getEmailAuthUtils("/api/email");
|
|
73
71
|
|
|
74
72
|
function AuthComponent() {
|
|
75
73
|
const login = useLogin();
|
|
@@ -108,11 +106,7 @@ Call your GraphQL API from server components or actions:
|
|
|
108
106
|
|
|
109
107
|
```typescript
|
|
110
108
|
// gql/server.ts
|
|
111
|
-
import {
|
|
112
|
-
|
|
113
|
-
export const query = getGraphQLQuery({
|
|
114
|
-
uri: process.env.NEXT_PUBLIC_BACKEND_BASE_URL!,
|
|
115
|
-
});
|
|
109
|
+
import { query } from "naystack/graphql/server";
|
|
116
110
|
|
|
117
111
|
// Usage in Page
|
|
118
112
|
const data = await query(MyQueryDocument, { variables });
|
|
@@ -124,18 +118,17 @@ For client-side GraphQL with Apollo:
|
|
|
124
118
|
|
|
125
119
|
```typescript
|
|
126
120
|
// gql/client.ts
|
|
127
|
-
import {
|
|
121
|
+
import { ApolloWrapper } from "naystack/graphql/client";
|
|
128
122
|
|
|
129
|
-
export const ApolloWrapper = getApolloWrapper("/api");
|
|
130
123
|
```
|
|
131
124
|
|
|
132
125
|
### Frontend Usage
|
|
133
126
|
|
|
134
127
|
```typescript
|
|
135
|
-
import {
|
|
128
|
+
import { useAuthQuery, useAuthMutation } from "naystack/graphql/client";
|
|
136
129
|
|
|
137
130
|
function Profile() {
|
|
138
|
-
const {
|
|
131
|
+
const [getCurrentUser, { loading }] = useAuthMutation(GetCurrentUserDocument);
|
|
139
132
|
// ...
|
|
140
133
|
}
|
|
141
134
|
```
|
|
@@ -170,9 +163,7 @@ export const { PUT, uploadFile, getDownloadURL } = setupFileUpload({
|
|
|
170
163
|
### Client Setup & Usage
|
|
171
164
|
|
|
172
165
|
```typescript
|
|
173
|
-
import {
|
|
174
|
-
|
|
175
|
-
const useFileUpload = getUseFileUpload("/api/upload");
|
|
166
|
+
import { useFileUpload } from "naystack/file/client";
|
|
176
167
|
|
|
177
168
|
function UploadButton() {
|
|
178
169
|
const upload = useFileUpload();
|
|
@@ -33,10 +33,10 @@ var client_exports = {};
|
|
|
33
33
|
__export(client_exports, {
|
|
34
34
|
AuthWrapper: () => AuthWrapper,
|
|
35
35
|
TokenContext: () => TokenContext,
|
|
36
|
-
|
|
36
|
+
useLogin: () => useLogin,
|
|
37
37
|
useLogout: () => useLogout,
|
|
38
38
|
useSetToken: () => useSetToken,
|
|
39
|
-
|
|
39
|
+
useSignUp: () => useSignUp,
|
|
40
40
|
useToken: () => useToken
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(client_exports);
|
|
@@ -62,7 +62,7 @@ function useSetToken() {
|
|
|
62
62
|
const { setToken } = (0, import_react.useContext)(TokenContext);
|
|
63
63
|
return setToken;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function useSignUp() {
|
|
66
66
|
const setToken = useSetToken();
|
|
67
67
|
return (0, import_react.useCallback)(
|
|
68
68
|
async (data) => {
|
|
@@ -81,7 +81,7 @@ function useSignUpWithEmail(endpoint) {
|
|
|
81
81
|
[setToken]
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
|
-
function
|
|
84
|
+
function useLogin() {
|
|
85
85
|
const setToken = useSetToken();
|
|
86
86
|
return (0, import_react.useCallback)(
|
|
87
87
|
async (data) => {
|
|
@@ -118,9 +118,9 @@ function useLogout() {
|
|
|
118
118
|
0 && (module.exports = {
|
|
119
119
|
AuthWrapper,
|
|
120
120
|
TokenContext,
|
|
121
|
-
|
|
121
|
+
useLogin,
|
|
122
122
|
useLogout,
|
|
123
123
|
useSetToken,
|
|
124
|
-
|
|
124
|
+
useSignUp,
|
|
125
125
|
useToken
|
|
126
126
|
});
|
|
@@ -9,8 +9,8 @@ declare const AuthWrapper: ({ children }: {
|
|
|
9
9
|
}) => React__default.JSX.Element;
|
|
10
10
|
declare function useToken(): string | null;
|
|
11
11
|
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
|
|
12
|
-
declare function
|
|
13
|
-
declare function
|
|
12
|
+
declare function useSignUp(): (data: object) => Promise<string | null>;
|
|
13
|
+
declare function useLogin(): (data: object) => Promise<string | null>;
|
|
14
14
|
declare function useLogout(): (data?: object) => Promise<void>;
|
|
15
15
|
|
|
16
|
-
export { AuthWrapper, TokenContext,
|
|
16
|
+
export { AuthWrapper, TokenContext, useLogin, useLogout, useSetToken, useSignUp, useToken };
|
|
@@ -9,8 +9,8 @@ declare const AuthWrapper: ({ children }: {
|
|
|
9
9
|
}) => React__default.JSX.Element;
|
|
10
10
|
declare function useToken(): string | null;
|
|
11
11
|
declare function useSetToken(): React__default.Dispatch<React__default.SetStateAction<string | null>>;
|
|
12
|
-
declare function
|
|
13
|
-
declare function
|
|
12
|
+
declare function useSignUp(): (data: object) => Promise<string | null>;
|
|
13
|
+
declare function useLogin(): (data: object) => Promise<string | null>;
|
|
14
14
|
declare function useLogout(): (data?: object) => Promise<void>;
|
|
15
15
|
|
|
16
|
-
export { AuthWrapper, TokenContext,
|
|
16
|
+
export { AuthWrapper, TokenContext, useLogin, useLogout, useSetToken, useSignUp, useToken };
|
|
@@ -29,7 +29,7 @@ function useSetToken() {
|
|
|
29
29
|
const { setToken } = useContext(TokenContext);
|
|
30
30
|
return setToken;
|
|
31
31
|
}
|
|
32
|
-
function
|
|
32
|
+
function useSignUp() {
|
|
33
33
|
const setToken = useSetToken();
|
|
34
34
|
return useCallback(
|
|
35
35
|
async (data) => {
|
|
@@ -48,7 +48,7 @@ function useSignUpWithEmail(endpoint) {
|
|
|
48
48
|
[setToken]
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
|
-
function
|
|
51
|
+
function useLogin() {
|
|
52
52
|
const setToken = useSetToken();
|
|
53
53
|
return useCallback(
|
|
54
54
|
async (data) => {
|
|
@@ -84,9 +84,9 @@ function useLogout() {
|
|
|
84
84
|
export {
|
|
85
85
|
AuthWrapper,
|
|
86
86
|
TokenContext,
|
|
87
|
-
|
|
87
|
+
useLogin,
|
|
88
88
|
useLogout,
|
|
89
89
|
useSetToken,
|
|
90
|
-
|
|
90
|
+
useSignUp,
|
|
91
91
|
useToken
|
|
92
92
|
};
|
package/dist/graphql/utils.d.mts
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { GraphQLScalarType } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { Query, Arg, ClassType } from 'type-graphql';
|
|
3
3
|
import { AuthorizedContext, Context } from './types.mjs';
|
|
4
4
|
|
|
5
5
|
type ReturnOptions = Parameters<typeof Query>[1];
|
|
6
6
|
type ArgsOptions = Parameters<typeof Arg>[2];
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type OtherTypes<T> = GraphQLScalarType<T, T> | [GraphQLScalarType<T, T>] | NumberConstructor | [NumberConstructor] | StringConstructor | [StringConstructor] | BooleanConstructor | [BooleanConstructor];
|
|
12
|
-
interface BaseDefinition<T extends Values, U extends Values, IsAuth extends boolean> {
|
|
13
|
-
output: T extends object ? ClassType<DeepPartial<T>> | [ClassType<DeepPartial<T>>] : OtherTypes<T>;
|
|
7
|
+
type ParsedGQLType<T> = T extends ClassType<infer U> ? U : T extends GraphQLScalarType<infer U> ? U : T extends Record<infer K, string | number> ? T[K] : T;
|
|
8
|
+
type ParsedGQLTypeWithArray<T> = T extends Array<infer U> ? ParsedGQLType<U>[] : ParsedGQLType<T>;
|
|
9
|
+
interface BaseDefinition<T, U, IsAuth extends boolean = false> {
|
|
10
|
+
output: T;
|
|
14
11
|
outputOptions?: ReturnOptions;
|
|
15
|
-
input?: U
|
|
12
|
+
input?: U;
|
|
16
13
|
inputOptions?: ArgsOptions;
|
|
17
14
|
authorized?: IsAuth;
|
|
18
15
|
}
|
|
19
|
-
interface QueryDefinition<T
|
|
20
|
-
fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: U) => Promise<T | T
|
|
16
|
+
interface QueryDefinition<T, U, IsAuth extends boolean = false> extends BaseDefinition<T, U, IsAuth> {
|
|
17
|
+
fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithArray<U>) => Promise<ParsedGQLTypeWithArray<T>> | ParsedGQLTypeWithArray<T>;
|
|
21
18
|
mutation?: boolean;
|
|
22
19
|
}
|
|
23
|
-
interface FieldResolverDefinition<T
|
|
24
|
-
fn: (root: Root, ctx: IsAuth extends true ? AuthorizedContext : Context, data: U) => Promise<T | T
|
|
20
|
+
interface FieldResolverDefinition<T, U, Root, IsAuth extends boolean = false> extends BaseDefinition<T, U, IsAuth> {
|
|
21
|
+
fn: (root: Root, ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithArray<U>) => Promise<ParsedGQLTypeWithArray<T>> | ParsedGQLTypeWithArray<T>;
|
|
25
22
|
}
|
|
26
|
-
declare function query<T
|
|
27
|
-
declare function field<T
|
|
23
|
+
declare function query<T, U, IsAuth extends boolean = false>(fn: QueryDefinition<T, U, IsAuth>["fn"], options: Omit<QueryDefinition<T, U, IsAuth>, "fn">): QueryDefinition<T, U, IsAuth>;
|
|
24
|
+
declare function field<T, U, IsAuth extends boolean, Root>(fn: FieldResolverDefinition<T, U, Root, IsAuth>["fn"], options: Omit<FieldResolverDefinition<T, U, Root, IsAuth>, "fn">): FieldResolverDefinition<T, U, Root, IsAuth>;
|
|
28
25
|
declare function QueryLibrary<T extends Record<string, QueryDefinition<any, any, any>>>(queries: T): {
|
|
29
26
|
new (): {};
|
|
30
27
|
};
|
|
31
|
-
declare function FieldLibrary<X extends object, T extends Record<string, FieldResolverDefinition<any, any,
|
|
28
|
+
declare function FieldLibrary<X extends object, T extends Record<string, FieldResolverDefinition<any, any, X, any>> = Record<string, FieldResolverDefinition<any, any, X, any>>>(type: ClassType, queries: T): {
|
|
32
29
|
new (): {};
|
|
33
30
|
};
|
|
34
31
|
|
package/dist/graphql/utils.d.ts
CHANGED
|
@@ -1,34 +1,31 @@
|
|
|
1
1
|
import { GraphQLScalarType } from 'graphql';
|
|
2
|
-
import {
|
|
2
|
+
import { Query, Arg, ClassType } from 'type-graphql';
|
|
3
3
|
import { AuthorizedContext, Context } from './types.js';
|
|
4
4
|
|
|
5
5
|
type ReturnOptions = Parameters<typeof Query>[1];
|
|
6
6
|
type ArgsOptions = Parameters<typeof Arg>[2];
|
|
7
|
-
type
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type OtherTypes<T> = GraphQLScalarType<T, T> | [GraphQLScalarType<T, T>] | NumberConstructor | [NumberConstructor] | StringConstructor | [StringConstructor] | BooleanConstructor | [BooleanConstructor];
|
|
12
|
-
interface BaseDefinition<T extends Values, U extends Values, IsAuth extends boolean> {
|
|
13
|
-
output: T extends object ? ClassType<DeepPartial<T>> | [ClassType<DeepPartial<T>>] : OtherTypes<T>;
|
|
7
|
+
type ParsedGQLType<T> = T extends ClassType<infer U> ? U : T extends GraphQLScalarType<infer U> ? U : T extends Record<infer K, string | number> ? T[K] : T;
|
|
8
|
+
type ParsedGQLTypeWithArray<T> = T extends Array<infer U> ? ParsedGQLType<U>[] : ParsedGQLType<T>;
|
|
9
|
+
interface BaseDefinition<T, U, IsAuth extends boolean = false> {
|
|
10
|
+
output: T;
|
|
14
11
|
outputOptions?: ReturnOptions;
|
|
15
|
-
input?: U
|
|
12
|
+
input?: U;
|
|
16
13
|
inputOptions?: ArgsOptions;
|
|
17
14
|
authorized?: IsAuth;
|
|
18
15
|
}
|
|
19
|
-
interface QueryDefinition<T
|
|
20
|
-
fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: U) => Promise<T | T
|
|
16
|
+
interface QueryDefinition<T, U, IsAuth extends boolean = false> extends BaseDefinition<T, U, IsAuth> {
|
|
17
|
+
fn: (ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithArray<U>) => Promise<ParsedGQLTypeWithArray<T>> | ParsedGQLTypeWithArray<T>;
|
|
21
18
|
mutation?: boolean;
|
|
22
19
|
}
|
|
23
|
-
interface FieldResolverDefinition<T
|
|
24
|
-
fn: (root: Root, ctx: IsAuth extends true ? AuthorizedContext : Context, data: U) => Promise<T | T
|
|
20
|
+
interface FieldResolverDefinition<T, U, Root, IsAuth extends boolean = false> extends BaseDefinition<T, U, IsAuth> {
|
|
21
|
+
fn: (root: Root, ctx: IsAuth extends true ? AuthorizedContext : Context, data: ParsedGQLTypeWithArray<U>) => Promise<ParsedGQLTypeWithArray<T>> | ParsedGQLTypeWithArray<T>;
|
|
25
22
|
}
|
|
26
|
-
declare function query<T
|
|
27
|
-
declare function field<T
|
|
23
|
+
declare function query<T, U, IsAuth extends boolean = false>(fn: QueryDefinition<T, U, IsAuth>["fn"], options: Omit<QueryDefinition<T, U, IsAuth>, "fn">): QueryDefinition<T, U, IsAuth>;
|
|
24
|
+
declare function field<T, U, IsAuth extends boolean, Root>(fn: FieldResolverDefinition<T, U, Root, IsAuth>["fn"], options: Omit<FieldResolverDefinition<T, U, Root, IsAuth>, "fn">): FieldResolverDefinition<T, U, Root, IsAuth>;
|
|
28
25
|
declare function QueryLibrary<T extends Record<string, QueryDefinition<any, any, any>>>(queries: T): {
|
|
29
26
|
new (): {};
|
|
30
27
|
};
|
|
31
|
-
declare function FieldLibrary<X extends object, T extends Record<string, FieldResolverDefinition<any, any,
|
|
28
|
+
declare function FieldLibrary<X extends object, T extends Record<string, FieldResolverDefinition<any, any, X, any>> = Record<string, FieldResolverDefinition<any, any, X, any>>>(type: ClassType, queries: T): {
|
|
32
29
|
new (): {};
|
|
33
30
|
};
|
|
34
31
|
|