naystack 1.1.11 → 1.1.12-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/email/index.cjs.js +203 -0
- package/dist/auth/email/index.d.mts +18 -0
- package/dist/auth/email/index.d.ts +18 -0
- package/dist/auth/email/index.esm.js +176 -0
- package/dist/auth/email/routes/delete.cjs.js +58 -0
- package/dist/auth/email/routes/delete.d.mts +8 -0
- package/dist/auth/email/routes/delete.d.ts +8 -0
- package/dist/auth/email/routes/delete.esm.js +31 -0
- package/dist/auth/email/routes/get.cjs.js +83 -0
- package/dist/auth/email/routes/get.d.mts +11 -0
- package/dist/auth/email/routes/get.d.ts +11 -0
- package/dist/auth/email/routes/get.esm.js +56 -0
- package/dist/auth/email/routes/post.cjs.js +149 -0
- package/dist/auth/email/routes/post.d.mts +8 -0
- package/dist/auth/email/routes/post.d.ts +8 -0
- package/dist/auth/email/routes/post.esm.js +124 -0
- package/dist/auth/email/routes/put.cjs.js +135 -0
- package/dist/auth/email/routes/put.d.mts +8 -0
- package/dist/auth/email/routes/put.d.ts +8 -0
- package/dist/auth/email/routes/put.esm.js +108 -0
- package/dist/auth/email/token.cjs.js +85 -0
- package/dist/auth/email/token.d.mts +13 -0
- package/dist/auth/email/token.d.ts +13 -0
- package/dist/auth/email/token.esm.js +56 -0
- package/dist/auth/email/types.cjs.js +18 -0
- package/dist/auth/email/types.d.mts +14 -0
- package/dist/auth/email/types.d.ts +14 -0
- package/dist/auth/email/types.esm.js +0 -0
- package/dist/auth/email/utils.cjs.js +83 -0
- package/dist/auth/email/utils.d.mts +16 -0
- package/dist/auth/email/utils.d.ts +16 -0
- package/dist/auth/email/utils.esm.js +55 -0
- package/dist/auth/index.d.mts +4 -45
- package/dist/auth/index.d.ts +4 -45
- package/dist/auth/types.cjs.js +18 -0
- package/dist/auth/types.d.mts +21 -0
- package/dist/auth/types.d.ts +21 -0
- package/dist/auth/types.esm.js +0 -0
- package/dist/auth/utils/errors.cjs.js +35 -0
- package/dist/auth/utils/errors.d.mts +6 -0
- package/dist/auth/utils/errors.d.ts +6 -0
- package/dist/auth/utils/errors.esm.js +10 -0
- package/dist/graphql/context.cjs.js +76 -0
- package/dist/graphql/context.d.mts +6 -0
- package/dist/graphql/context.d.ts +6 -0
- package/dist/graphql/context.esm.js +51 -0
- package/dist/graphql/index.d.mts +7 -23
- package/dist/graphql/index.d.ts +7 -23
- package/dist/graphql/init.cjs.js +124 -0
- package/dist/graphql/init.d.mts +16 -0
- package/dist/graphql/init.d.ts +16 -0
- package/dist/graphql/init.esm.js +104 -0
- package/dist/graphql/types.cjs.js +18 -0
- package/dist/graphql/types.d.mts +8 -0
- package/dist/graphql/types.d.ts +8 -0
- package/dist/graphql/types.esm.js +0 -0
- package/dist/graphql/utils.cjs.js +134 -0
- package/dist/graphql/utils.d.mts +29 -0
- package/dist/graphql/utils.d.ts +29 -0
- package/dist/graphql/utils.esm.js +118 -0
- package/dist/socials/index.d.mts +9 -130
- package/dist/socials/index.d.ts +9 -130
- package/dist/socials/instagram/getters.cjs.js +119 -0
- package/dist/socials/instagram/getters.d.mts +39 -0
- package/dist/socials/instagram/getters.d.ts +39 -0
- package/dist/socials/instagram/getters.esm.js +86 -0
- package/dist/socials/instagram/setters.cjs.js +54 -0
- package/dist/socials/instagram/setters.d.mts +8 -0
- package/dist/socials/instagram/setters.d.ts +8 -0
- package/dist/socials/instagram/setters.esm.js +27 -0
- package/dist/socials/instagram/types.cjs.js +18 -0
- package/dist/socials/instagram/types.d.mts +57 -0
- package/dist/socials/instagram/types.d.ts +57 -0
- package/dist/socials/instagram/types.esm.js +0 -0
- package/dist/socials/instagram/utils.cjs.js +44 -0
- package/dist/socials/instagram/utils.d.mts +6 -0
- package/dist/socials/instagram/utils.d.ts +6 -0
- package/dist/socials/instagram/utils.esm.js +18 -0
- package/dist/socials/instagram/webhook.cjs.js +57 -0
- package/dist/socials/instagram/webhook.d.mts +12 -0
- package/dist/socials/instagram/webhook.d.ts +12 -0
- package/dist/socials/instagram/webhook.esm.js +30 -0
- package/dist/socials/meta-webhook.cjs.js +36 -0
- package/dist/socials/meta-webhook.d.mts +5 -0
- package/dist/socials/meta-webhook.d.ts +5 -0
- package/dist/socials/meta-webhook.esm.js +11 -0
- package/dist/socials/threads/getters.cjs.js +60 -0
- package/dist/socials/threads/getters.d.mts +7 -0
- package/dist/socials/threads/getters.d.ts +7 -0
- package/dist/socials/threads/getters.esm.js +31 -0
- package/dist/socials/threads/setters.cjs.js +87 -0
- package/dist/socials/threads/setters.d.mts +6 -0
- package/dist/socials/threads/setters.d.ts +6 -0
- package/dist/socials/threads/setters.esm.js +57 -0
- package/dist/socials/threads/types.cjs.js +18 -0
- package/dist/socials/threads/types.d.mts +7 -0
- package/dist/socials/threads/types.d.ts +7 -0
- package/dist/socials/threads/types.esm.js +0 -0
- package/dist/socials/threads/utils.cjs.js +39 -0
- package/dist/socials/threads/utils.d.mts +4 -0
- package/dist/socials/threads/utils.d.ts +4 -0
- package/dist/socials/threads/utils.esm.js +13 -0
- package/dist/socials/threads/webhook.cjs.js +54 -0
- package/dist/socials/threads/webhook.d.mts +12 -0
- package/dist/socials/threads/webhook.d.ts +12 -0
- package/dist/socials/threads/webhook.esm.js +27 -0
- package/package.json +1 -1
package/dist/graphql/index.d.mts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
plugins?: ApolloServerPlugin[];
|
|
9
|
-
refreshKey: string;
|
|
10
|
-
signingKey: string;
|
|
11
|
-
}): Promise<{
|
|
12
|
-
GET: (request: NextRequest) => Promise<Response>;
|
|
13
|
-
POST: (request: NextRequest) => Promise<Response>;
|
|
14
|
-
}>;
|
|
15
|
-
|
|
16
|
-
interface Context {
|
|
17
|
-
userId: number | null;
|
|
18
|
-
}
|
|
19
|
-
interface AuthorizedContext {
|
|
20
|
-
userId: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { type AuthorizedContext, type Context, initGraphQLServer };
|
|
1
|
+
export { initGraphQLServer } from './init.mjs';
|
|
2
|
+
export { AuthorizedContext, Context } from './types.mjs';
|
|
3
|
+
export { FieldLibrary, QueryLibrary, field, query } from './utils.mjs';
|
|
4
|
+
import '@apollo/server';
|
|
5
|
+
import 'next/server';
|
|
6
|
+
import 'type-graphql';
|
|
7
|
+
import 'node:vm';
|
package/dist/graphql/index.d.ts
CHANGED
|
@@ -1,23 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
plugins?: ApolloServerPlugin[];
|
|
9
|
-
refreshKey: string;
|
|
10
|
-
signingKey: string;
|
|
11
|
-
}): Promise<{
|
|
12
|
-
GET: (request: NextRequest) => Promise<Response>;
|
|
13
|
-
POST: (request: NextRequest) => Promise<Response>;
|
|
14
|
-
}>;
|
|
15
|
-
|
|
16
|
-
interface Context {
|
|
17
|
-
userId: number | null;
|
|
18
|
-
}
|
|
19
|
-
interface AuthorizedContext {
|
|
20
|
-
userId: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { type AuthorizedContext, type Context, initGraphQLServer };
|
|
1
|
+
export { initGraphQLServer } from './init.js';
|
|
2
|
+
export { AuthorizedContext, Context } from './types.js';
|
|
3
|
+
export { FieldLibrary, QueryLibrary, field, query } from './utils.js';
|
|
4
|
+
import '@apollo/server';
|
|
5
|
+
import 'next/server';
|
|
6
|
+
import 'type-graphql';
|
|
7
|
+
import 'node:vm';
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/graphql/init.ts
|
|
21
|
+
var init_exports = {};
|
|
22
|
+
__export(init_exports, {
|
|
23
|
+
initGraphQLServer: () => initGraphQLServer
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(init_exports);
|
|
26
|
+
var import_reflect_metadata = require("reflect-metadata");
|
|
27
|
+
var import_server3 = require("@apollo/server");
|
|
28
|
+
var import_default = require("@apollo/server/plugin/landingPage/default");
|
|
29
|
+
var import_next = require("@as-integrations/next");
|
|
30
|
+
var import_type_graphql = require("type-graphql");
|
|
31
|
+
|
|
32
|
+
// src/graphql/context.ts
|
|
33
|
+
var import_jsonwebtoken2 = require("jsonwebtoken");
|
|
34
|
+
|
|
35
|
+
// src/auth/email/token.ts
|
|
36
|
+
var import_bcryptjs = require("bcryptjs");
|
|
37
|
+
var import_jsonwebtoken = require("jsonwebtoken");
|
|
38
|
+
var import_server = require("next/server");
|
|
39
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
40
|
+
if (refreshToken)
|
|
41
|
+
try {
|
|
42
|
+
const decoded = (0, import_jsonwebtoken.verify)(refreshToken, refreshKey);
|
|
43
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
44
|
+
return decoded.id;
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (!(e instanceof import_jsonwebtoken.JsonWebTokenError)) console.error(e, "errors");
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/auth/utils/errors.ts
|
|
53
|
+
var import_server2 = require("next/server");
|
|
54
|
+
function handleError(status, message, onError) {
|
|
55
|
+
const res = onError?.({ status, message });
|
|
56
|
+
if (res) return res;
|
|
57
|
+
return new import_server2.NextResponse(message, { status });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// src/graphql/context.ts
|
|
61
|
+
var getContext = (refreshKey, signingKey) => async (req) => {
|
|
62
|
+
const bearer = req.headers.get("authorization");
|
|
63
|
+
const isMobile = req.headers.get("x-platform-is-mobile");
|
|
64
|
+
if (!bearer) {
|
|
65
|
+
if (isMobile) return { userId: null };
|
|
66
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
67
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
68
|
+
if (userId) return { userId, onlyQuery: true };
|
|
69
|
+
return { userId: null };
|
|
70
|
+
}
|
|
71
|
+
const token = bearer.slice(7);
|
|
72
|
+
try {
|
|
73
|
+
const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
|
|
74
|
+
return { userId: typeof res !== "string" ? res.id : null };
|
|
75
|
+
} catch {
|
|
76
|
+
if (isMobile) return handleError(401, "Refresh token is invalid.");
|
|
77
|
+
}
|
|
78
|
+
return { userId: null };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/graphql/init.ts
|
|
82
|
+
async function initGraphQLServer({
|
|
83
|
+
authChecker,
|
|
84
|
+
resolvers,
|
|
85
|
+
plugins,
|
|
86
|
+
refreshKey,
|
|
87
|
+
signingKey
|
|
88
|
+
}) {
|
|
89
|
+
const { typeDefs, resolvers: builtResolvers } = await (0, import_type_graphql.buildTypeDefsAndResolvers)({
|
|
90
|
+
validate: true,
|
|
91
|
+
authChecker,
|
|
92
|
+
resolvers
|
|
93
|
+
});
|
|
94
|
+
const server = new import_server3.ApolloServer({
|
|
95
|
+
typeDefs,
|
|
96
|
+
resolvers: builtResolvers,
|
|
97
|
+
plugins: [
|
|
98
|
+
process.env.NODE_ENV === "production" ? (0, import_default.ApolloServerPluginLandingPageProductionDefault)() : (0, import_default.ApolloServerPluginLandingPageLocalDefault)(),
|
|
99
|
+
{
|
|
100
|
+
async requestDidStart({ request, contextValue }) {
|
|
101
|
+
if (
|
|
102
|
+
// eslint-disable-next-line
|
|
103
|
+
contextValue.onlyQuery && !request.query?.startsWith("query")
|
|
104
|
+
)
|
|
105
|
+
contextValue.userId = null;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
...plugins || []
|
|
109
|
+
],
|
|
110
|
+
introspection: process.env.NODE_ENV !== "production",
|
|
111
|
+
status400ForVariableCoercionErrors: true
|
|
112
|
+
});
|
|
113
|
+
const handler = (0, import_next.startServerAndCreateNextHandler)(server, {
|
|
114
|
+
context: getContext(refreshKey, signingKey)
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
GET: (request) => handler(request),
|
|
118
|
+
POST: (request) => handler(request)
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
initGraphQLServer
|
|
124
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ApolloServerPlugin } from '@apollo/server';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
import { AuthChecker, NonEmptyArray } from 'type-graphql';
|
|
4
|
+
|
|
5
|
+
declare function initGraphQLServer({ authChecker, resolvers, plugins, refreshKey, signingKey, }: {
|
|
6
|
+
authChecker?: AuthChecker<any>;
|
|
7
|
+
resolvers: NonEmptyArray<Function>;
|
|
8
|
+
plugins?: ApolloServerPlugin[];
|
|
9
|
+
refreshKey: string;
|
|
10
|
+
signingKey: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
GET: (request: NextRequest) => Promise<Response>;
|
|
13
|
+
POST: (request: NextRequest) => Promise<Response>;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export { initGraphQLServer };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ApolloServerPlugin } from '@apollo/server';
|
|
2
|
+
import { NextRequest } from 'next/server';
|
|
3
|
+
import { AuthChecker, NonEmptyArray } from 'type-graphql';
|
|
4
|
+
|
|
5
|
+
declare function initGraphQLServer({ authChecker, resolvers, plugins, refreshKey, signingKey, }: {
|
|
6
|
+
authChecker?: AuthChecker<any>;
|
|
7
|
+
resolvers: NonEmptyArray<Function>;
|
|
8
|
+
plugins?: ApolloServerPlugin[];
|
|
9
|
+
refreshKey: string;
|
|
10
|
+
signingKey: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
GET: (request: NextRequest) => Promise<Response>;
|
|
13
|
+
POST: (request: NextRequest) => Promise<Response>;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
export { initGraphQLServer };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// src/graphql/init.ts
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
import { ApolloServer } from "@apollo/server";
|
|
4
|
+
import {
|
|
5
|
+
ApolloServerPluginLandingPageLocalDefault,
|
|
6
|
+
ApolloServerPluginLandingPageProductionDefault
|
|
7
|
+
} from "@apollo/server/plugin/landingPage/default";
|
|
8
|
+
import { startServerAndCreateNextHandler } from "@as-integrations/next";
|
|
9
|
+
import {
|
|
10
|
+
buildTypeDefsAndResolvers
|
|
11
|
+
} from "type-graphql";
|
|
12
|
+
|
|
13
|
+
// src/graphql/context.ts
|
|
14
|
+
import { verify as verify2 } from "jsonwebtoken";
|
|
15
|
+
|
|
16
|
+
// src/auth/email/token.ts
|
|
17
|
+
import { compare } from "bcryptjs";
|
|
18
|
+
import { JsonWebTokenError, sign, verify } from "jsonwebtoken";
|
|
19
|
+
import { NextResponse } from "next/server";
|
|
20
|
+
function getUserIdFromRefreshToken(refreshKey, refreshToken) {
|
|
21
|
+
if (refreshToken)
|
|
22
|
+
try {
|
|
23
|
+
const decoded = verify(refreshToken, refreshKey);
|
|
24
|
+
if (typeof decoded !== "string" && typeof decoded.id === "number")
|
|
25
|
+
return decoded.id;
|
|
26
|
+
} catch (e) {
|
|
27
|
+
if (!(e instanceof JsonWebTokenError)) console.error(e, "errors");
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/auth/utils/errors.ts
|
|
34
|
+
import { NextResponse as NextResponse2 } from "next/server";
|
|
35
|
+
function handleError(status, message, onError) {
|
|
36
|
+
const res = onError?.({ status, message });
|
|
37
|
+
if (res) return res;
|
|
38
|
+
return new NextResponse2(message, { status });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/graphql/context.ts
|
|
42
|
+
var getContext = (refreshKey, signingKey) => async (req) => {
|
|
43
|
+
const bearer = req.headers.get("authorization");
|
|
44
|
+
const isMobile = req.headers.get("x-platform-is-mobile");
|
|
45
|
+
if (!bearer) {
|
|
46
|
+
if (isMobile) return { userId: null };
|
|
47
|
+
const refresh = req.cookies.get("refresh")?.value;
|
|
48
|
+
const userId = getUserIdFromRefreshToken(refreshKey, refresh);
|
|
49
|
+
if (userId) return { userId, onlyQuery: true };
|
|
50
|
+
return { userId: null };
|
|
51
|
+
}
|
|
52
|
+
const token = bearer.slice(7);
|
|
53
|
+
try {
|
|
54
|
+
const res = verify2(token, signingKey);
|
|
55
|
+
return { userId: typeof res !== "string" ? res.id : null };
|
|
56
|
+
} catch {
|
|
57
|
+
if (isMobile) return handleError(401, "Refresh token is invalid.");
|
|
58
|
+
}
|
|
59
|
+
return { userId: null };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/graphql/init.ts
|
|
63
|
+
async function initGraphQLServer({
|
|
64
|
+
authChecker,
|
|
65
|
+
resolvers,
|
|
66
|
+
plugins,
|
|
67
|
+
refreshKey,
|
|
68
|
+
signingKey
|
|
69
|
+
}) {
|
|
70
|
+
const { typeDefs, resolvers: builtResolvers } = await buildTypeDefsAndResolvers({
|
|
71
|
+
validate: true,
|
|
72
|
+
authChecker,
|
|
73
|
+
resolvers
|
|
74
|
+
});
|
|
75
|
+
const server = new ApolloServer({
|
|
76
|
+
typeDefs,
|
|
77
|
+
resolvers: builtResolvers,
|
|
78
|
+
plugins: [
|
|
79
|
+
process.env.NODE_ENV === "production" ? ApolloServerPluginLandingPageProductionDefault() : ApolloServerPluginLandingPageLocalDefault(),
|
|
80
|
+
{
|
|
81
|
+
async requestDidStart({ request, contextValue }) {
|
|
82
|
+
if (
|
|
83
|
+
// eslint-disable-next-line
|
|
84
|
+
contextValue.onlyQuery && !request.query?.startsWith("query")
|
|
85
|
+
)
|
|
86
|
+
contextValue.userId = null;
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
...plugins || []
|
|
90
|
+
],
|
|
91
|
+
introspection: process.env.NODE_ENV !== "production",
|
|
92
|
+
status400ForVariableCoercionErrors: true
|
|
93
|
+
});
|
|
94
|
+
const handler = startServerAndCreateNextHandler(server, {
|
|
95
|
+
context: getContext(refreshKey, signingKey)
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
GET: (request) => handler(request),
|
|
99
|
+
POST: (request) => handler(request)
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export {
|
|
103
|
+
initGraphQLServer
|
|
104
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/graphql/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
File without changes
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/graphql/utils.ts
|
|
29
|
+
var utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
FieldLibrary: () => FieldLibrary,
|
|
32
|
+
QueryLibrary: () => QueryLibrary,
|
|
33
|
+
field: () => field,
|
|
34
|
+
query: () => query
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(utils_exports);
|
|
37
|
+
var import_type_graphql = require("type-graphql");
|
|
38
|
+
function query(fn, options) {
|
|
39
|
+
return { ...options, fn };
|
|
40
|
+
}
|
|
41
|
+
function field(fn, options) {
|
|
42
|
+
return { ...options, fn };
|
|
43
|
+
}
|
|
44
|
+
function QueryLibrary(queries) {
|
|
45
|
+
let GeneratedResolver = class {
|
|
46
|
+
};
|
|
47
|
+
GeneratedResolver = __decorateClass([
|
|
48
|
+
(0, import_type_graphql.Resolver)()
|
|
49
|
+
], GeneratedResolver);
|
|
50
|
+
for (const key in queries) {
|
|
51
|
+
const def = queries[key];
|
|
52
|
+
if (!def) continue;
|
|
53
|
+
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
54
|
+
// eslint-disable-next-line
|
|
55
|
+
value: async function(ctx, data) {
|
|
56
|
+
return def.fn(ctx, data);
|
|
57
|
+
},
|
|
58
|
+
writable: false
|
|
59
|
+
});
|
|
60
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
61
|
+
GeneratedResolver.prototype,
|
|
62
|
+
key
|
|
63
|
+
);
|
|
64
|
+
if (def.mutation) {
|
|
65
|
+
(0, import_type_graphql.Mutation)(() => def.output, def.outputOptions)(
|
|
66
|
+
GeneratedResolver.prototype,
|
|
67
|
+
key,
|
|
68
|
+
descriptor
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
(0, import_type_graphql.Query)(() => def.output, def.outputOptions)(
|
|
72
|
+
GeneratedResolver.prototype,
|
|
73
|
+
key,
|
|
74
|
+
descriptor
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
(0, import_type_graphql.Ctx)()(GeneratedResolver.prototype, key, 0);
|
|
78
|
+
if (def.input) {
|
|
79
|
+
(0, import_type_graphql.Arg)("input", () => def.input || String, def.inputOptions)(
|
|
80
|
+
GeneratedResolver.prototype,
|
|
81
|
+
key,
|
|
82
|
+
1
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return GeneratedResolver;
|
|
87
|
+
}
|
|
88
|
+
function FieldLibrary(type, queries) {
|
|
89
|
+
let GeneratedResolver = class {
|
|
90
|
+
};
|
|
91
|
+
GeneratedResolver = __decorateClass([
|
|
92
|
+
(0, import_type_graphql.Resolver)(() => type)
|
|
93
|
+
], GeneratedResolver);
|
|
94
|
+
for (const key in queries) {
|
|
95
|
+
const def = queries[key];
|
|
96
|
+
if (!def) continue;
|
|
97
|
+
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
98
|
+
// eslint-disable-next-line
|
|
99
|
+
value: async function(root, ctx, input) {
|
|
100
|
+
return def.fn(root, ctx, input);
|
|
101
|
+
},
|
|
102
|
+
writable: false
|
|
103
|
+
});
|
|
104
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
105
|
+
GeneratedResolver.prototype,
|
|
106
|
+
key
|
|
107
|
+
);
|
|
108
|
+
if (def.authorized) {
|
|
109
|
+
(0, import_type_graphql.Authorized)()(GeneratedResolver, key);
|
|
110
|
+
}
|
|
111
|
+
(0, import_type_graphql.Root)()(GeneratedResolver.prototype, key, 0);
|
|
112
|
+
(0, import_type_graphql.FieldResolver)(() => def.output, def.outputOptions)(
|
|
113
|
+
GeneratedResolver.prototype,
|
|
114
|
+
key,
|
|
115
|
+
descriptor
|
|
116
|
+
);
|
|
117
|
+
(0, import_type_graphql.Ctx)()(GeneratedResolver.prototype, key, 1);
|
|
118
|
+
if (def.input) {
|
|
119
|
+
(0, import_type_graphql.Arg)("input", () => def.input || String, def.inputOptions)(
|
|
120
|
+
GeneratedResolver.prototype,
|
|
121
|
+
key,
|
|
122
|
+
2
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return GeneratedResolver;
|
|
127
|
+
}
|
|
128
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
129
|
+
0 && (module.exports = {
|
|
130
|
+
FieldLibrary,
|
|
131
|
+
QueryLibrary,
|
|
132
|
+
field,
|
|
133
|
+
query
|
|
134
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Context } from 'node:vm';
|
|
2
|
+
import { ClassType, Query, Arg } from 'type-graphql';
|
|
3
|
+
|
|
4
|
+
type ReturnOptions = Parameters<typeof Query>[1];
|
|
5
|
+
type ArgsOptions = Parameters<typeof Arg>[2];
|
|
6
|
+
interface BaseDefinition<X extends object, Y extends object> {
|
|
7
|
+
output: ClassType<Y> | [ClassType<Y>];
|
|
8
|
+
outputOptions?: ReturnOptions;
|
|
9
|
+
input?: ClassType<X>;
|
|
10
|
+
inputOptions?: ArgsOptions;
|
|
11
|
+
authorized?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface QueryDefinition<X extends object, Y extends object> extends BaseDefinition<X, Y> {
|
|
14
|
+
fn: (ctx: Context, data?: X) => Promise<Y> | Y;
|
|
15
|
+
mutation?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface FieldResolverDefinition<X extends object, Y extends object, Root> extends BaseDefinition<X, Y> {
|
|
18
|
+
fn: (root: Root, ctx: Context, data?: X) => Promise<Y> | Y;
|
|
19
|
+
}
|
|
20
|
+
declare function query<ReturnType extends object, ArgType extends object>(fn: QueryDefinition<ReturnType, ArgType>["fn"], options: Omit<QueryDefinition<ReturnType, ArgType>, "fn">): QueryDefinition<ReturnType, NonNullable<ArgType>>;
|
|
21
|
+
declare function field<X extends object, Y extends object, Root>(fn: FieldResolverDefinition<X, Y, Root>["fn"], options: Omit<FieldResolverDefinition<X, Y, Root>, "fn">): FieldResolverDefinition<X, Y, Root>;
|
|
22
|
+
declare function QueryLibrary<T extends Record<string, QueryDefinition<any, any>>>(queries: T): {
|
|
23
|
+
new (): {};
|
|
24
|
+
};
|
|
25
|
+
declare function FieldLibrary<X extends object, T extends Record<string, FieldResolverDefinition<any, any, X>> = Record<string, FieldResolverDefinition<any, any, X>>>(type: ClassType, queries: T): {
|
|
26
|
+
new (): {};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { FieldLibrary, QueryLibrary, field, query };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Context } from 'node:vm';
|
|
2
|
+
import { ClassType, Query, Arg } from 'type-graphql';
|
|
3
|
+
|
|
4
|
+
type ReturnOptions = Parameters<typeof Query>[1];
|
|
5
|
+
type ArgsOptions = Parameters<typeof Arg>[2];
|
|
6
|
+
interface BaseDefinition<X extends object, Y extends object> {
|
|
7
|
+
output: ClassType<Y> | [ClassType<Y>];
|
|
8
|
+
outputOptions?: ReturnOptions;
|
|
9
|
+
input?: ClassType<X>;
|
|
10
|
+
inputOptions?: ArgsOptions;
|
|
11
|
+
authorized?: boolean;
|
|
12
|
+
}
|
|
13
|
+
interface QueryDefinition<X extends object, Y extends object> extends BaseDefinition<X, Y> {
|
|
14
|
+
fn: (ctx: Context, data?: X) => Promise<Y> | Y;
|
|
15
|
+
mutation?: boolean;
|
|
16
|
+
}
|
|
17
|
+
interface FieldResolverDefinition<X extends object, Y extends object, Root> extends BaseDefinition<X, Y> {
|
|
18
|
+
fn: (root: Root, ctx: Context, data?: X) => Promise<Y> | Y;
|
|
19
|
+
}
|
|
20
|
+
declare function query<ReturnType extends object, ArgType extends object>(fn: QueryDefinition<ReturnType, ArgType>["fn"], options: Omit<QueryDefinition<ReturnType, ArgType>, "fn">): QueryDefinition<ReturnType, NonNullable<ArgType>>;
|
|
21
|
+
declare function field<X extends object, Y extends object, Root>(fn: FieldResolverDefinition<X, Y, Root>["fn"], options: Omit<FieldResolverDefinition<X, Y, Root>, "fn">): FieldResolverDefinition<X, Y, Root>;
|
|
22
|
+
declare function QueryLibrary<T extends Record<string, QueryDefinition<any, any>>>(queries: T): {
|
|
23
|
+
new (): {};
|
|
24
|
+
};
|
|
25
|
+
declare function FieldLibrary<X extends object, T extends Record<string, FieldResolverDefinition<any, any, X>> = Record<string, FieldResolverDefinition<any, any, X>>>(type: ClassType, queries: T): {
|
|
26
|
+
new (): {};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { FieldLibrary, QueryLibrary, field, query };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/graphql/utils.ts
|
|
13
|
+
import {
|
|
14
|
+
Arg,
|
|
15
|
+
Authorized,
|
|
16
|
+
Ctx,
|
|
17
|
+
FieldResolver,
|
|
18
|
+
Mutation,
|
|
19
|
+
Query,
|
|
20
|
+
Resolver,
|
|
21
|
+
Root
|
|
22
|
+
} from "type-graphql";
|
|
23
|
+
function query(fn, options) {
|
|
24
|
+
return { ...options, fn };
|
|
25
|
+
}
|
|
26
|
+
function field(fn, options) {
|
|
27
|
+
return { ...options, fn };
|
|
28
|
+
}
|
|
29
|
+
function QueryLibrary(queries) {
|
|
30
|
+
let GeneratedResolver = class {
|
|
31
|
+
};
|
|
32
|
+
GeneratedResolver = __decorateClass([
|
|
33
|
+
Resolver()
|
|
34
|
+
], GeneratedResolver);
|
|
35
|
+
for (const key in queries) {
|
|
36
|
+
const def = queries[key];
|
|
37
|
+
if (!def) continue;
|
|
38
|
+
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
39
|
+
// eslint-disable-next-line
|
|
40
|
+
value: async function(ctx, data) {
|
|
41
|
+
return def.fn(ctx, data);
|
|
42
|
+
},
|
|
43
|
+
writable: false
|
|
44
|
+
});
|
|
45
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
46
|
+
GeneratedResolver.prototype,
|
|
47
|
+
key
|
|
48
|
+
);
|
|
49
|
+
if (def.mutation) {
|
|
50
|
+
Mutation(() => def.output, def.outputOptions)(
|
|
51
|
+
GeneratedResolver.prototype,
|
|
52
|
+
key,
|
|
53
|
+
descriptor
|
|
54
|
+
);
|
|
55
|
+
} else {
|
|
56
|
+
Query(() => def.output, def.outputOptions)(
|
|
57
|
+
GeneratedResolver.prototype,
|
|
58
|
+
key,
|
|
59
|
+
descriptor
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
Ctx()(GeneratedResolver.prototype, key, 0);
|
|
63
|
+
if (def.input) {
|
|
64
|
+
Arg("input", () => def.input || String, def.inputOptions)(
|
|
65
|
+
GeneratedResolver.prototype,
|
|
66
|
+
key,
|
|
67
|
+
1
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return GeneratedResolver;
|
|
72
|
+
}
|
|
73
|
+
function FieldLibrary(type, queries) {
|
|
74
|
+
let GeneratedResolver = class {
|
|
75
|
+
};
|
|
76
|
+
GeneratedResolver = __decorateClass([
|
|
77
|
+
Resolver(() => type)
|
|
78
|
+
], GeneratedResolver);
|
|
79
|
+
for (const key in queries) {
|
|
80
|
+
const def = queries[key];
|
|
81
|
+
if (!def) continue;
|
|
82
|
+
Object.defineProperty(GeneratedResolver.prototype, key, {
|
|
83
|
+
// eslint-disable-next-line
|
|
84
|
+
value: async function(root, ctx, input) {
|
|
85
|
+
return def.fn(root, ctx, input);
|
|
86
|
+
},
|
|
87
|
+
writable: false
|
|
88
|
+
});
|
|
89
|
+
const descriptor = Object.getOwnPropertyDescriptor(
|
|
90
|
+
GeneratedResolver.prototype,
|
|
91
|
+
key
|
|
92
|
+
);
|
|
93
|
+
if (def.authorized) {
|
|
94
|
+
Authorized()(GeneratedResolver, key);
|
|
95
|
+
}
|
|
96
|
+
Root()(GeneratedResolver.prototype, key, 0);
|
|
97
|
+
FieldResolver(() => def.output, def.outputOptions)(
|
|
98
|
+
GeneratedResolver.prototype,
|
|
99
|
+
key,
|
|
100
|
+
descriptor
|
|
101
|
+
);
|
|
102
|
+
Ctx()(GeneratedResolver.prototype, key, 1);
|
|
103
|
+
if (def.input) {
|
|
104
|
+
Arg("input", () => def.input || String, def.inputOptions)(
|
|
105
|
+
GeneratedResolver.prototype,
|
|
106
|
+
key,
|
|
107
|
+
2
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return GeneratedResolver;
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
FieldLibrary,
|
|
115
|
+
QueryLibrary,
|
|
116
|
+
field,
|
|
117
|
+
query
|
|
118
|
+
};
|