nitro-graphql 2.0.0-beta.72 → 2.0.0-beta.73
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 +1 -1
- package/dist/cli/adapter.d.mts +0 -3
- package/dist/cli/adapter.mjs +6 -29
- package/dist/cli/commands/generate.mjs +2 -2
- package/dist/cli/config.d.mts +4 -5
- package/dist/cli/config.mjs +3 -1
- package/dist/cli/index.d.mts +3 -6
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/server/graphql-handler.mjs +2 -1
- package/dist/cli/server/watcher.mjs +1 -1
- package/dist/core/codegen/client.d.mts +4 -27
- package/dist/core/codegen/client.mjs +26 -445
- package/dist/core/codegen/file-header.d.mts +7 -0
- package/dist/core/codegen/file-header.mjs +12 -0
- package/dist/core/codegen/index.d.mts +7 -5
- package/dist/core/codegen/index.mjs +7 -5
- package/dist/core/codegen/{runtime.d.mts → runtime-generator.d.mts} +1 -1
- package/dist/core/codegen/{runtime.mjs → runtime-generator.mjs} +1 -1
- package/dist/core/codegen/schema-loader.d.mts +2 -7
- package/dist/core/codegen/schema-loader.mjs +65 -70
- package/dist/core/codegen/server-type-helpers.d.mts +14 -0
- package/dist/core/codegen/server-type-helpers.mjs +76 -0
- package/dist/core/codegen/server.d.mts +1 -15
- package/dist/core/codegen/server.mjs +15 -105
- package/dist/core/codegen/subscription-extractor.d.mts +20 -0
- package/dist/core/codegen/subscription-extractor.mjs +30 -0
- package/dist/core/codegen/vue-subscription-builder.d.mts +10 -0
- package/dist/core/codegen/vue-subscription-builder.mjs +351 -0
- package/dist/core/constants.d.mts +5 -53
- package/dist/core/constants.mjs +13 -54
- package/dist/core/create-config.d.mts +31 -0
- package/dist/core/create-config.mjs +42 -0
- package/dist/core/debug/index.d.mts +2 -2
- package/dist/core/debug/index.mjs +2 -2
- package/dist/core/debug/template.d.mts +1 -5
- package/dist/core/debug/template.mjs +1 -1
- package/dist/core/extend/loader.d.mts +0 -1
- package/dist/core/extend/loader.mjs +59 -89
- package/dist/core/index.d.mts +22 -17
- package/dist/core/index.mjs +19 -15
- package/dist/core/manifest.mjs +3 -1
- package/dist/core/pubsub/index.d.mts +2 -109
- package/dist/core/pubsub/index.mjs +1 -145
- package/dist/core/pubsub/memory-pubsub.d.mts +109 -0
- package/dist/core/pubsub/memory-pubsub.mjs +146 -0
- package/dist/core/scanning/ast-scanner.mjs +4 -2
- package/dist/core/scanning/directives.mjs +2 -3
- package/dist/core/scanning/documents.d.mts +4 -3
- package/dist/core/scanning/documents.mjs +1 -1
- package/dist/core/scanning/{common.d.mts → file-scanner.d.mts} +1 -1
- package/dist/core/scanning/{common.mjs → file-scanner.mjs} +2 -10
- package/dist/core/scanning/index.d.mts +3 -3
- package/dist/core/scanning/index.mjs +3 -3
- package/dist/core/scanning/resolvers.mjs +8 -9
- package/dist/core/scanning/schemas.d.mts +1 -5
- package/dist/core/scanning/schemas.mjs +2 -24
- package/dist/core/schema/builder.d.mts +4 -2
- package/dist/core/schema/builder.mjs +4 -2
- package/dist/core/schema/index.d.mts +2 -2
- package/dist/core/schema/index.mjs +2 -2
- package/dist/core/server/apollo.d.mts +20 -0
- package/dist/core/server/apollo.mjs +54 -0
- package/dist/core/server/index.d.mts +4 -2
- package/dist/core/server/index.mjs +3 -2
- package/dist/core/server/types.d.mts +7 -14
- package/dist/core/server/types.mjs +15 -1
- package/dist/core/server/yoga.d.mts +1 -7
- package/dist/core/server/yoga.mjs +4 -13
- package/dist/core/types/adapter.d.mts +4 -39
- package/dist/core/types/codegen.d.mts +22 -45
- package/dist/core/types/config.d.mts +33 -121
- package/dist/core/types/define.d.mts +8 -5
- package/dist/core/types/index.d.mts +5 -4
- package/dist/core/types/scanning.d.mts +4 -1
- package/dist/core/types/standard-schema.d.mts +64 -0
- package/dist/core/utils/directive-parser.d.mts +8 -63
- package/dist/core/utils/directive-parser.mjs +114 -166
- package/dist/core/utils/file-io.d.mts +1 -5
- package/dist/core/utils/file-io.mjs +1 -11
- package/dist/core/utils/index.d.mts +5 -4
- package/dist/core/utils/index.mjs +6 -5
- package/dist/core/utils/logger.d.mts +1 -10
- package/dist/core/utils/logger.mjs +1 -19
- package/dist/core/utils/ofetch-templates.mjs +3 -4
- package/dist/core/utils/runtime.d.mts +1 -30
- package/dist/core/utils/runtime.mjs +2 -44
- package/dist/core/utils/string.d.mts +10 -0
- package/dist/core/utils/string.mjs +12 -0
- package/dist/core/watcher/create-watcher.d.mts +103 -0
- package/dist/core/watcher/create-watcher.mjs +143 -0
- package/dist/core/watcher/index.d.mts +2 -107
- package/dist/core/watcher/index.mjs +1 -139
- package/dist/define.d.mts +4 -2
- package/dist/define.mjs +7 -6
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +1 -1
- package/dist/nitro/adapter.d.mts +6 -10
- package/dist/nitro/adapter.mjs +12 -42
- package/dist/nitro/codegen/client-types.d.mts +12 -0
- package/dist/nitro/codegen/client-types.mjs +73 -0
- package/dist/nitro/codegen/external-types.d.mts +8 -0
- package/dist/nitro/codegen/external-types.mjs +47 -0
- package/dist/nitro/codegen/index.d.mts +4 -0
- package/dist/nitro/codegen/index.mjs +4 -0
- package/dist/nitro/codegen/server-types.d.mts +12 -0
- package/dist/nitro/codegen/server-types.mjs +81 -0
- package/dist/nitro/defaults.d.mts +28 -0
- package/dist/nitro/defaults.mjs +34 -0
- package/dist/nitro/index.d.mts +11 -3
- package/dist/nitro/index.mjs +1 -1
- package/dist/nitro/paths.d.mts +3 -2
- package/dist/nitro/paths.mjs +13 -9
- package/dist/nitro/rollup.mjs +4 -3
- package/dist/nitro/routes/_ws-handler.d.mts +6 -0
- package/dist/nitro/routes/_ws-handler.mjs +49 -0
- package/dist/nitro/routes/apollo-server-ws.d.mts +1 -1
- package/dist/nitro/routes/apollo-server-ws.mjs +9 -44
- package/dist/nitro/routes/apollo-server.d.mts +1 -1
- package/dist/nitro/routes/apollo-server.mjs +16 -55
- package/dist/nitro/routes/debug.d.mts +1 -1
- package/dist/nitro/routes/debug.mjs +1 -0
- package/dist/nitro/routes/graphql-yoga-ws.d.mts +1 -1
- package/dist/nitro/routes/graphql-yoga-ws.mjs +6 -44
- package/dist/nitro/routes/graphql-yoga.mjs +7 -5
- package/dist/nitro/routes/health.mjs +22 -24
- package/dist/nitro/setup/extend-loader.d.mts +6 -5
- package/dist/nitro/setup/extend-loader.mjs +30 -58
- package/dist/nitro/setup/file-watcher.mjs +6 -4
- package/dist/nitro/setup/logging.d.mts +1 -8
- package/dist/nitro/setup/logging.mjs +7 -22
- package/dist/nitro/setup/rollup-integration.mjs +32 -1
- package/dist/nitro/setup/scanner.d.mts +8 -43
- package/dist/nitro/setup/scanner.mjs +56 -58
- package/dist/nitro/setup/security.d.mts +10 -0
- package/dist/nitro/setup/security.mjs +17 -0
- package/dist/nitro/setup/type-generation.d.mts +13 -0
- package/dist/nitro/setup/type-generation.mjs +16 -0
- package/dist/nitro/setup.d.mts +4 -3
- package/dist/nitro/setup.mjs +87 -74
- package/dist/nitro/state.d.mts +32 -0
- package/dist/nitro/state.mjs +58 -0
- package/dist/nitro/types/augmentation.d.mts +59 -0
- package/dist/nitro/types/augmentation.mjs +1 -0
- package/dist/nitro/types/config.d.mts +327 -0
- package/dist/nitro/types/config.mjs +1 -0
- package/dist/nitro/types/define.d.mts +13 -0
- package/dist/nitro/types/define.mjs +1 -0
- package/dist/nitro/types/index.d.mts +10 -0
- package/dist/nitro/types/index.mjs +1 -0
- package/dist/nitro/virtual/debug-info.d.mts +9 -0
- package/dist/nitro/virtual/debug-info.mjs +35 -0
- package/dist/nitro/virtual/graphql-config.d.mts +9 -0
- package/dist/nitro/virtual/graphql-config.mjs +33 -0
- package/dist/nitro/virtual/index.d.mts +25 -0
- package/dist/nitro/virtual/index.mjs +45 -0
- package/dist/nitro/virtual/module-config.d.mts +9 -0
- package/dist/nitro/virtual/module-config.mjs +10 -0
- package/dist/nitro/virtual/pubsub.d.mts +9 -0
- package/dist/nitro/virtual/pubsub.mjs +17 -0
- package/dist/nitro/virtual/server-directives.d.mts +9 -0
- package/dist/nitro/virtual/server-directives.mjs +12 -0
- package/dist/nitro/virtual/server-resolvers.d.mts +9 -0
- package/dist/nitro/virtual/server-resolvers.mjs +17 -0
- package/dist/nitro/virtual/server-schemas.d.mts +9 -0
- package/dist/nitro/virtual/server-schemas.mjs +31 -0
- package/dist/nitro/virtual/stubs.d.mts +42 -10
- package/dist/nitro/virtual/stubs.mjs +0 -5
- package/dist/nitro/virtual/utils.d.mts +15 -0
- package/dist/nitro/virtual/utils.mjs +26 -0
- package/dist/nitro/virtual/validation-schemas.d.mts +9 -0
- package/dist/nitro/virtual/validation-schemas.mjs +33 -0
- package/native/index.js +52 -52
- package/package.json +15 -15
- package/dist/cli/commands/index.d.mts +0 -5
- package/dist/cli/commands/index.mjs +0 -5
- package/dist/core/codegen/plugin.d.mts +0 -19
- package/dist/core/codegen/plugin.mjs +0 -29
- package/dist/core/config.d.mts +0 -45
- package/dist/core/config.mjs +0 -76
- package/dist/nitro/codegen.d.mts +0 -18
- package/dist/nitro/codegen.mjs +0 -171
- package/dist/nitro/config.d.mts +0 -50
- package/dist/nitro/config.mjs +0 -55
- package/dist/nitro/types.d.mts +0 -549
- package/dist/nitro/virtual/generators.d.mts +0 -38
- package/dist/nitro/virtual/generators.mjs +0 -190
- /package/dist/{nitro/types.mjs → core/types/standard-schema.mjs} +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { generateDebugHtml } from "./template.mjs";
|
|
2
|
+
export { generateDebugHtml };
|
|
@@ -38,10 +38,6 @@ interface DebugInfo {
|
|
|
38
38
|
};
|
|
39
39
|
virtualModules: Record<string, string>;
|
|
40
40
|
}
|
|
41
|
-
/**
|
|
42
|
-
* Escape HTML special characters
|
|
43
|
-
*/
|
|
44
|
-
declare function escapeHtml(text: string): string;
|
|
45
41
|
/**
|
|
46
42
|
* Generate the HTML dashboard for the debug endpoint
|
|
47
43
|
*
|
|
@@ -49,4 +45,4 @@ declare function escapeHtml(text: string): string;
|
|
|
49
45
|
*/
|
|
50
46
|
declare function generateDebugHtml(debugInfo: DebugInfo): string;
|
|
51
47
|
//#endregion
|
|
52
|
-
export { DebugInfo,
|
|
48
|
+
export { DebugInfo, generateDebugHtml };
|
|
@@ -25,7 +25,6 @@ interface ExtendScanResult {
|
|
|
25
25
|
declare function isLocalDirSource(source: unknown): source is LocalDirExtendSource;
|
|
26
26
|
/**
|
|
27
27
|
* Resolve extend directories for file watching
|
|
28
|
-
* Returns directories that should be watched for changes
|
|
29
28
|
*/
|
|
30
29
|
declare function resolveExtendDirs(extend: Array<string | object> | undefined, rootDir: string): Promise<string[]>;
|
|
31
30
|
/**
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
import { GRAPHQL_GLOB_PATTERN, RESOLVER_GLOB_PATTERN } from "../constants.mjs";
|
|
1
|
+
import { DEFAULT_IGNORE_PATTERNS, GRAPHQL_GLOB_PATTERN, RESOLVER_GLOB_PATTERN } from "../constants.mjs";
|
|
2
2
|
import { isLocalPath, loadPackageConfig, resolvePackageFiles } from "../manifest.mjs";
|
|
3
3
|
import { parseSingleFile } from "../scanning/ast-scanner.mjs";
|
|
4
4
|
import { parseDirectiveCall } from "../scanning/directives.mjs";
|
|
5
5
|
import { parseResolverCall } from "../scanning/resolvers.mjs";
|
|
6
6
|
import { existsSync_ } from "../utils/runtime.mjs";
|
|
7
|
+
import consola from "consola";
|
|
7
8
|
import { dirname, resolve } from "pathe";
|
|
8
9
|
import { glob } from "tinyglobby";
|
|
9
10
|
//#region src/core/extend/loader.ts
|
|
11
|
+
function emptyResult() {
|
|
12
|
+
return {
|
|
13
|
+
schemas: [],
|
|
14
|
+
resolvers: [],
|
|
15
|
+
directives: [],
|
|
16
|
+
documents: []
|
|
17
|
+
};
|
|
18
|
+
}
|
|
10
19
|
/**
|
|
11
20
|
* Check if source is a LocalDirExtendSource
|
|
12
21
|
*/
|
|
@@ -15,7 +24,6 @@ function isLocalDirSource(source) {
|
|
|
15
24
|
}
|
|
16
25
|
/**
|
|
17
26
|
* Resolve extend directories for file watching
|
|
18
|
-
* Returns directories that should be watched for changes
|
|
19
27
|
*/
|
|
20
28
|
async function resolveExtendDirs(extend, rootDir) {
|
|
21
29
|
if (!extend || !Array.isArray(extend) || extend.length === 0) return [];
|
|
@@ -56,29 +64,14 @@ async function scanExtendSource(source, rootDir) {
|
|
|
56
64
|
if (typeof source === "string") return scanPackageSource(source, rootDir);
|
|
57
65
|
if (isLocalDirSource(source)) return scanLocalDirSource(source);
|
|
58
66
|
if (source && typeof source === "object") return scanExplicitPaths(source, rootDir);
|
|
59
|
-
return
|
|
60
|
-
schemas: [],
|
|
61
|
-
resolvers: [],
|
|
62
|
-
directives: [],
|
|
63
|
-
documents: []
|
|
64
|
-
};
|
|
67
|
+
return emptyResult();
|
|
65
68
|
}
|
|
66
69
|
/**
|
|
67
70
|
* Scan all extend sources and merge results
|
|
68
71
|
*/
|
|
69
72
|
async function scanAllExtendSources(extend, rootDir) {
|
|
70
|
-
if (!extend || !Array.isArray(extend) || extend.length === 0) return
|
|
71
|
-
|
|
72
|
-
resolvers: [],
|
|
73
|
-
directives: [],
|
|
74
|
-
documents: []
|
|
75
|
-
};
|
|
76
|
-
const merged = {
|
|
77
|
-
schemas: [],
|
|
78
|
-
resolvers: [],
|
|
79
|
-
directives: [],
|
|
80
|
-
documents: []
|
|
81
|
-
};
|
|
73
|
+
if (!extend || !Array.isArray(extend) || extend.length === 0) return emptyResult();
|
|
74
|
+
const merged = emptyResult();
|
|
82
75
|
for (const source of extend) {
|
|
83
76
|
const result = await scanExtendSource(source, rootDir);
|
|
84
77
|
merged.schemas.push(...result.schemas);
|
|
@@ -90,74 +83,62 @@ async function scanAllExtendSources(extend, rootDir) {
|
|
|
90
83
|
}
|
|
91
84
|
return merged;
|
|
92
85
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
86
|
+
async function parseResolverFiles(paths) {
|
|
87
|
+
const results = [];
|
|
88
|
+
for (const filePath of paths) {
|
|
89
|
+
const parsed = await parseSingleFile(filePath, parseResolverCall);
|
|
90
|
+
if (parsed?.imports.length) results.push(parsed);
|
|
91
|
+
}
|
|
92
|
+
return results;
|
|
93
|
+
}
|
|
94
|
+
async function parseDirectiveFiles(paths) {
|
|
95
|
+
const results = [];
|
|
96
|
+
for (const filePath of paths) {
|
|
97
|
+
const parsed = await parseSingleFile(filePath, parseDirectiveCall);
|
|
98
|
+
if (parsed?.imports.length) results.push(parsed);
|
|
99
|
+
}
|
|
100
|
+
return results;
|
|
101
|
+
}
|
|
96
102
|
async function scanPackageSource(packageName, rootDir) {
|
|
97
103
|
const pkg = await loadPackageConfig(packageName, rootDir);
|
|
98
|
-
if (!pkg)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const directives = [];
|
|
102
|
-
for (const resolverPath of files.resolvers) {
|
|
103
|
-
const parsed = await parseSingleFile(resolverPath, parseResolverCall);
|
|
104
|
-
if (parsed?.imports.length) resolvers.push(parsed);
|
|
105
|
-
}
|
|
106
|
-
for (const directivePath of files.directives) {
|
|
107
|
-
const parsed = await parseSingleFile(directivePath, parseDirectiveCall);
|
|
108
|
-
if (parsed?.imports.length) directives.push(parsed);
|
|
104
|
+
if (!pkg) {
|
|
105
|
+
consola.warn(`[nitro-graphql] Config not found for "${packageName}". Skipping. Create a nitro-graphql.config.ts file in the package root.`);
|
|
106
|
+
return emptyResult();
|
|
109
107
|
}
|
|
108
|
+
const files = await resolvePackageFiles(pkg);
|
|
110
109
|
return {
|
|
111
110
|
schemas: files.schemas,
|
|
112
|
-
resolvers,
|
|
113
|
-
directives,
|
|
111
|
+
resolvers: await parseResolverFiles(files.resolvers),
|
|
112
|
+
directives: await parseDirectiveFiles(files.directives),
|
|
114
113
|
documents: files.documents,
|
|
115
114
|
configPath: files.configPath,
|
|
116
115
|
schemaPath: files.schemaPath
|
|
117
116
|
};
|
|
118
117
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Scan a local directory for GraphQL files
|
|
121
|
-
*/
|
|
122
118
|
async function scanLocalDirSource(source) {
|
|
123
|
-
const result =
|
|
124
|
-
|
|
125
|
-
resolvers: [],
|
|
126
|
-
directives: [],
|
|
127
|
-
documents: []
|
|
128
|
-
};
|
|
129
|
-
const ignorePatterns = [
|
|
130
|
-
"**/node_modules/**",
|
|
131
|
-
"**/.git/**",
|
|
132
|
-
"**/.output/**",
|
|
133
|
-
"**/.nitro/**",
|
|
134
|
-
"**/.nuxt/**"
|
|
135
|
-
];
|
|
119
|
+
const result = emptyResult();
|
|
120
|
+
const ignorePatterns = [...DEFAULT_IGNORE_PATTERNS];
|
|
136
121
|
if (source.serverDir && existsSync_(source.serverDir)) {
|
|
137
|
-
const schemaFiles = await
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
122
|
+
const [schemaFiles, resolverFiles, directiveFiles] = await Promise.all([
|
|
123
|
+
glob(GRAPHQL_GLOB_PATTERN, {
|
|
124
|
+
cwd: source.serverDir,
|
|
125
|
+
absolute: true,
|
|
126
|
+
ignore: ignorePatterns
|
|
127
|
+
}),
|
|
128
|
+
glob(RESOLVER_GLOB_PATTERN, {
|
|
129
|
+
cwd: source.serverDir,
|
|
130
|
+
absolute: true,
|
|
131
|
+
ignore: ignorePatterns
|
|
132
|
+
}),
|
|
133
|
+
glob("**/*.directive.ts", {
|
|
134
|
+
cwd: source.serverDir,
|
|
135
|
+
absolute: true,
|
|
136
|
+
ignore: ignorePatterns
|
|
137
|
+
})
|
|
138
|
+
]);
|
|
142
139
|
result.schemas.push(...schemaFiles);
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
absolute: true,
|
|
146
|
-
ignore: ignorePatterns
|
|
147
|
-
});
|
|
148
|
-
for (const resolverPath of resolverFiles) {
|
|
149
|
-
const parsed = await parseSingleFile(resolverPath, parseResolverCall);
|
|
150
|
-
if (parsed?.imports.length) result.resolvers.push(parsed);
|
|
151
|
-
}
|
|
152
|
-
const directiveFiles = await glob("**/*.directive.ts", {
|
|
153
|
-
cwd: source.serverDir,
|
|
154
|
-
absolute: true,
|
|
155
|
-
ignore: ignorePatterns
|
|
156
|
-
});
|
|
157
|
-
for (const directivePath of directiveFiles) {
|
|
158
|
-
const parsed = await parseSingleFile(directivePath, parseDirectiveCall);
|
|
159
|
-
if (parsed?.imports.length) result.directives.push(parsed);
|
|
160
|
-
}
|
|
140
|
+
result.resolvers.push(...await parseResolverFiles(resolverFiles));
|
|
141
|
+
result.directives.push(...await parseDirectiveFiles(directiveFiles));
|
|
161
142
|
}
|
|
162
143
|
if (source.clientDir && existsSync_(source.clientDir)) {
|
|
163
144
|
const documentFiles = await glob(GRAPHQL_GLOB_PATTERN, {
|
|
@@ -169,26 +150,15 @@ async function scanLocalDirSource(source) {
|
|
|
169
150
|
}
|
|
170
151
|
return result;
|
|
171
152
|
}
|
|
172
|
-
/**
|
|
173
|
-
* Scan explicit paths (legacy format)
|
|
174
|
-
*/
|
|
175
153
|
async function scanExplicitPaths(source, rootDir) {
|
|
176
|
-
const result =
|
|
177
|
-
schemas: [],
|
|
178
|
-
resolvers: [],
|
|
179
|
-
directives: [],
|
|
180
|
-
documents: []
|
|
181
|
-
};
|
|
154
|
+
const result = emptyResult();
|
|
182
155
|
if (source.schemas) {
|
|
183
156
|
const schemas = Array.isArray(source.schemas) ? source.schemas : [source.schemas];
|
|
184
|
-
|
|
157
|
+
result.schemas.push(...schemas.map((s) => resolve(rootDir, s)));
|
|
185
158
|
}
|
|
186
159
|
if (source.resolvers) {
|
|
187
160
|
const resolvers = Array.isArray(source.resolvers) ? source.resolvers : [source.resolvers];
|
|
188
|
-
|
|
189
|
-
const parsed = await parseSingleFile(resolve(rootDir, resolverPath), parseResolverCall);
|
|
190
|
-
if (parsed?.imports.length) result.resolvers.push(parsed);
|
|
191
|
-
}
|
|
161
|
+
result.resolvers.push(...await parseResolverFiles(resolvers.map((r) => resolve(rootDir, r))));
|
|
192
162
|
}
|
|
193
163
|
return result;
|
|
194
164
|
}
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { DefineDirectiveConfig, DirectiveArgument, DirectiveDefinition, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType } from "./types/define.mjs";
|
|
1
|
+
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_CLIENT_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLFramework, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN } from "./constants.mjs";
|
|
2
|
+
import { ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, ExternalServiceCodegenConfig, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult } from "./types/codegen.mjs";
|
|
3
|
+
import { CoreCodegenConfig, CoreConfig, CoreExternalService, CoreFederationConfig, CoreLogger, CoreSecurityConfig } from "./types/config.mjs";
|
|
5
4
|
import { ResolverImport, ScanContext, ScanResult, ScannedFile, ScannedResolver } from "./types/scanning.mjs";
|
|
6
|
-
import {
|
|
5
|
+
import { DefineDirectiveConfig, DirectiveArg, DirectiveArgument, DirectiveDefinition, DirectiveLocationName, Flatten, GraphQLArgumentType, GraphQLBaseType, GraphQLScalarType } from "./types/define.mjs";
|
|
6
|
+
import { StandardSchemaV1 } from "./types/standard-schema.mjs";
|
|
7
|
+
import { BASE_SCHEMA, BASE_SCHEMA_DEF, CreateMergedSchemaOptions, DirectiveWrapper, ModuleConfig, ResolverDefinition, SchemaDefinition, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./schema/builder.mjs";
|
|
7
8
|
import { CoreServerInstance, CoreServerOptions, ServerFactory } from "./server/types.mjs";
|
|
9
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, generateClientTypesCore, generateExternalClientTypesCore } from "./codegen/client.mjs";
|
|
8
10
|
import { loadGraphQLDocuments } from "./codegen/document-loader.mjs";
|
|
11
|
+
import { GENERATED_FILE_HEADER } from "./codegen/file-header.mjs";
|
|
12
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime-generator.mjs";
|
|
9
13
|
import { GraphQLLoadSchemaOptions, GraphQLTypeDefPointer, downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./codegen/schema-loader.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime.mjs";
|
|
13
|
-
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore, generateTypes } from "./codegen/server.mjs";
|
|
14
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore } from "./codegen/server.mjs";
|
|
15
|
+
import { SubscriptionInfo, extractSubscriptions } from "./codegen/subscription-extractor.mjs";
|
|
14
16
|
import { validateNoDuplicateTypes, validateSchemaFiles } from "./codegen/validation.mjs";
|
|
15
|
-
import {
|
|
17
|
+
import { generateSubscriptionBuilder } from "./codegen/vue-subscription-builder.mjs";
|
|
18
|
+
import { CreateCoreConfigOptions, createCoreConfig, createScanContext } from "./create-config.mjs";
|
|
16
19
|
import { PackageConfig, ResolvedExtend, ResolvedPackage, isLocalPath, loadPackageConfig, resolvePackageFiles } from "./manifest.mjs";
|
|
17
20
|
import { ASTScanConfig, parseSingleFile, scanWithAST } from "./scanning/ast-scanner.mjs";
|
|
18
|
-
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/common.mjs";
|
|
19
21
|
import { parseDirectiveCall, scanDirectivesCore } from "./scanning/directives.mjs";
|
|
20
22
|
import { ScanDocumentsOptions, scanDocumentsCore } from "./scanning/documents.mjs";
|
|
23
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/file-scanner.mjs";
|
|
21
24
|
import { parseResolverCall, scanResolversCore } from "./scanning/resolvers.mjs";
|
|
22
|
-
import {
|
|
25
|
+
import { scanSchemasCore } from "./scanning/schemas.mjs";
|
|
23
26
|
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./schema/federation.mjs";
|
|
27
|
+
import { APOLLO_USER_FACING_ERROR_CODES, createApolloServerInstance } from "./server/apollo.mjs";
|
|
24
28
|
import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./server/sandbox.mjs";
|
|
25
|
-
import {
|
|
26
|
-
import { DirectiveFileRef,
|
|
29
|
+
import { apolloSandboxHtml, createYogaServer } from "./server/yoga.mjs";
|
|
30
|
+
import { DirectiveFileRef, ParsedDirective, generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile } from "./utils/directive-parser.mjs";
|
|
27
31
|
import { MaskErrorOptions, createDefaultMaskError } from "./utils/errors.mjs";
|
|
28
|
-
import { ensureDir,
|
|
32
|
+
import { ensureDir, writeFile, writeFileIfChanged } from "./utils/file-io.mjs";
|
|
29
33
|
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
30
|
-
import { createLogger
|
|
34
|
+
import { createLogger } from "./utils/logger.mjs";
|
|
31
35
|
import { OfetchTemplateOptions, generateOfetchTemplate } from "./utils/ofetch-templates.mjs";
|
|
36
|
+
import { capitalize } from "./utils/string.mjs";
|
|
32
37
|
import { validateExternalServices } from "./validation/external-services.mjs";
|
|
33
|
-
export { APOLLO_SANDBOX_CDN, ASTScanConfig, BASE_SCHEMA, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN,
|
|
38
|
+
export { APOLLO_SANDBOX_CDN, APOLLO_USER_FACING_ERROR_CODES, ASTScanConfig, BASE_SCHEMA, BASE_SCHEMA_DEF, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, ClientCodegenConfig, ClientCodegenInput, ClientCodegenResult, CoreCodegenConfig, CoreConfig, CoreExternalService, CoreFederationConfig, CoreLogger, CoreSecurityConfig, CoreServerInstance, CoreServerOptions, CreateCoreConfigOptions, CreateMergedSchemaOptions, DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SERVER_CODEGEN_CONFIG, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_CLIENT_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, DefineDirectiveConfig, DirectiveArg, DirectiveArgument, DirectiveDefinition, DirectiveFileRef, DirectiveLocationName, DirectiveWrapper, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, ExternalServiceCodegenConfig, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, Flatten, GENERATED_FILE_HEADER, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, GraphQLArgumentType, GraphQLBaseType, GraphQLFramework, GraphQLLoadSchemaOptions, GraphQLScalarType, GraphQLTypeDefPointer, LOG_TAG, MaskErrorOptions, ModuleConfig, OfetchTemplateOptions, PATTERN_CLIENT_EXTERNAL_TYPES, PackageConfig, ParsedDirective, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, ResolvedExtend, ResolvedPackage, ResolverDefinition, ResolverImport, ScanContext, ScanDocumentsOptions, ScanResult, ScannedFile, ScannedResolver, SchemaDefinition, SdkCodegenConfig, ServerCodegenConfig, ServerCodegenInput, ServerCodegenResult, ServerFactory, StandardSchemaV1, SubscriptionInfo, apolloSandboxHtml, buildGraphQLSchema, capitalize, createApolloServerInstance, createCoreConfig, createDefaultMaskError, createLogger, createMergedSchema, createSandboxResponse, createScanContext, createYogaServer, deduplicateFiles, downloadAndSaveSchema, ensureDir, extractPaths, extractSubscriptions, fetchSandboxScript, filterByExtension, generateClientTypesCore, generateDirectiveSchema, generateDirectiveSchemas, generateExternalClientTypesCore, generateOfetchTemplate, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateSubscriptionBuilder, getImportId, graphQLLoadSchemaSync, isLocalPath, loadExternalSchema, loadFederationSupport, loadGraphQLDocuments, loadPackageConfig, parse, parseDirectiveCall, parseDirectivesFromFile, parseResolverCall, parseSingleFile, relativeWithDot, resetFederationCache, resolvePackageFiles, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanResolversCore, scanSchemasCore, scanWithAST, subscribe, validate, validateExternalServices, validateNoDuplicateTypes, validateSchemaFiles, warnFederationUnavailable, writeFile, writeFileIfChanged };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
|
-
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN,
|
|
2
|
-
import { GENERATED_FILE_HEADER
|
|
1
|
+
import { BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_CLIENT_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN } from "./constants.mjs";
|
|
2
|
+
import { GENERATED_FILE_HEADER } from "./codegen/file-header.mjs";
|
|
3
|
+
import { DEFAULT_CLIENT_CODEGEN_CONFIG, generateClientTypesCore, generateExternalClientTypesCore } from "./codegen/client.mjs";
|
|
3
4
|
import { loadGraphQLDocuments } from "./codegen/document-loader.mjs";
|
|
4
|
-
import {
|
|
5
|
+
import { generateResolverModule, generateRuntimeIndex, generateSchemaModule } from "./codegen/runtime-generator.mjs";
|
|
6
|
+
import { ensureDir, writeFile, writeFileIfChanged } from "./utils/file-io.mjs";
|
|
5
7
|
import { downloadAndSaveSchema, graphQLLoadSchemaSync, loadExternalSchema } from "./codegen/schema-loader.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import { DEFAULT_SERVER_CODEGEN_CONFIG, generateServerTypesCore } from "./codegen/server.mjs";
|
|
9
|
+
import { capitalize } from "./utils/string.mjs";
|
|
10
|
+
import { extractSubscriptions } from "./codegen/subscription-extractor.mjs";
|
|
9
11
|
import { validateNoDuplicateTypes, validateSchemaFiles } from "./codegen/validation.mjs";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
+
import { generateSubscriptionBuilder } from "./codegen/vue-subscription-builder.mjs";
|
|
13
|
+
import { createLogger } from "./utils/logger.mjs";
|
|
14
|
+
import { createCoreConfig, createScanContext } from "./create-config.mjs";
|
|
12
15
|
import { isLocalPath, loadPackageConfig, resolvePackageFiles } from "./manifest.mjs";
|
|
13
|
-
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/
|
|
16
|
+
import { deduplicateFiles, extractPaths, filterByExtension, scanDirectory } from "./scanning/file-scanner.mjs";
|
|
14
17
|
import { parseSingleFile, scanWithAST } from "./scanning/ast-scanner.mjs";
|
|
18
|
+
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
15
19
|
import { parseDirectiveCall, scanDirectivesCore } from "./scanning/directives.mjs";
|
|
16
20
|
import { scanDocumentsCore } from "./scanning/documents.mjs";
|
|
17
21
|
import { parseResolverCall, scanResolversCore } from "./scanning/resolvers.mjs";
|
|
18
|
-
import {
|
|
22
|
+
import { scanSchemasCore } from "./scanning/schemas.mjs";
|
|
19
23
|
import { loadFederationSupport, resetFederationCache, warnFederationUnavailable } from "./schema/federation.mjs";
|
|
20
|
-
import { BASE_SCHEMA, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./schema/builder.mjs";
|
|
24
|
+
import { BASE_SCHEMA, BASE_SCHEMA_DEF, buildGraphQLSchema, createMergedSchema, parse, subscribe, validate } from "./schema/builder.mjs";
|
|
25
|
+
import { APOLLO_USER_FACING_ERROR_CODES, createApolloServerInstance } from "./server/apollo.mjs";
|
|
21
26
|
import { APOLLO_SANDBOX_CDN, createSandboxResponse, fetchSandboxScript } from "./server/sandbox.mjs";
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
27
|
+
import { apolloSandboxHtml, createYogaServer } from "./server/yoga.mjs";
|
|
28
|
+
import { generateDirectiveSchema, generateDirectiveSchemas, parseDirectivesFromFile } from "./utils/directive-parser.mjs";
|
|
24
29
|
import { createDefaultMaskError } from "./utils/errors.mjs";
|
|
25
|
-
import { getImportId, relativeWithDot } from "./utils/imports.mjs";
|
|
26
30
|
import { generateOfetchTemplate } from "./utils/ofetch-templates.mjs";
|
|
27
31
|
import { validateExternalServices } from "./validation/external-services.mjs";
|
|
28
|
-
export { APOLLO_SANDBOX_CDN, BASE_SCHEMA, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN,
|
|
32
|
+
export { APOLLO_SANDBOX_CDN, APOLLO_USER_FACING_ERROR_CODES, BASE_SCHEMA, BASE_SCHEMA_DEF, BUILTIN_SCALARS, CHUNK_NAME_RESOLVERS, CHUNK_NAME_SCHEMAS, CHUNK_PATH_GRAPHQL, CHUNK_PATH_UNKNOWN, DEFAULT_CLIENT_CODEGEN_CONFIG, DEFAULT_CLIENT_TYPES_PATH, DEFAULT_GRAPHQL_SCALARS, DEFAULT_IGNORE_PATTERNS, DEFAULT_SERVER_CODEGEN_CONFIG, DEFAULT_SERVER_TYPES_PATH, DEFINE_DIRECTIVE, DEFINE_FIELD, DEFINE_FUNCTIONS, DEFINE_MUTATION, DEFINE_QUERY, DEFINE_RESOLVER, DEFINE_SUBSCRIPTION, DIRECTIVE_EXTENSIONS, DIRECTIVE_GLOB_PATTERN, DIR_APP_GRAPHQL, DIR_CLIENT_GRAPHQL, DIR_SERVER_GRAPHQL, DIR_SERVER_GRAPHQL_WIN, ENDPOINT_DEBUG, ENDPOINT_GRAPHQL, ENDPOINT_HEALTH, FILE_CLIENT_TYPES, FILE_CONFIG_TS, FILE_CONTEXT_DTS, FILE_DIRECTIVES_GRAPHQL, FILE_GRAPHQL_CONFIG, FILE_INDEX_TS, FILE_OFETCH_TS, FILE_SCHEMA_TS, FILE_SDK_TS, FILE_SERVER_TYPES, FRAMEWORK_NITRO, FRAMEWORK_NUXT, GENERATED_FILE_HEADER, GLOB_SCAN_PATTERN, GRAPHQL_EXTENSIONS, GRAPHQL_FRAMEWORK_APOLLO, GRAPHQL_FRAMEWORK_YOGA, GRAPHQL_GLOB_PATTERN, GRAPHQL_HTTP_METHODS, LOG_TAG, PATTERN_CLIENT_EXTERNAL_TYPES, RESOLVER_EXTENSIONS, RESOLVER_GLOB_PATTERN, apolloSandboxHtml, buildGraphQLSchema, capitalize, createApolloServerInstance, createCoreConfig, createDefaultMaskError, createLogger, createMergedSchema, createSandboxResponse, createScanContext, createYogaServer, deduplicateFiles, downloadAndSaveSchema, ensureDir, extractPaths, extractSubscriptions, fetchSandboxScript, filterByExtension, generateClientTypesCore, generateDirectiveSchema, generateDirectiveSchemas, generateExternalClientTypesCore, generateOfetchTemplate, generateResolverModule, generateRuntimeIndex, generateSchemaModule, generateServerTypesCore, generateSubscriptionBuilder, getImportId, graphQLLoadSchemaSync, isLocalPath, loadExternalSchema, loadFederationSupport, loadGraphQLDocuments, loadPackageConfig, parse, parseDirectiveCall, parseDirectivesFromFile, parseResolverCall, parseSingleFile, relativeWithDot, resetFederationCache, resolvePackageFiles, scanDirectivesCore, scanDirectory, scanDocumentsCore, scanResolversCore, scanSchemasCore, scanWithAST, subscribe, validate, validateExternalServices, validateNoDuplicateTypes, validateSchemaFiles, warnFederationUnavailable, writeFile, writeFileIfChanged };
|
package/dist/core/manifest.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DIRECTIVE_EXTENSIONS, GRAPHQL_EXTENSIONS, RESOLVER_EXTENSIONS } from "./constants.mjs";
|
|
2
|
+
import consola from "consola";
|
|
2
3
|
import { dirname, isAbsolute, resolve } from "pathe";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import { loadConfig } from "c12";
|
|
@@ -47,7 +48,8 @@ async function loadPackageConfig(source, rootDir) {
|
|
|
47
48
|
config: resolvedConfig,
|
|
48
49
|
baseDir: pkgDir
|
|
49
50
|
};
|
|
50
|
-
} catch {
|
|
51
|
+
} catch (error) {
|
|
52
|
+
consola.debug(`[nitro-graphql] Failed to load config for "${source}":`, error);
|
|
51
53
|
return null;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -1,109 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Built-in PubSub implementation for GraphQL Subscriptions
|
|
4
|
-
* Simple EventEmitter-based implementation for single-instance deployments
|
|
5
|
-
*
|
|
6
|
-
* For multi-instance deployments, use external PubSub solutions like:
|
|
7
|
-
* - Redis (with ioredis)
|
|
8
|
-
* - Kafka
|
|
9
|
-
* - RabbitMQ
|
|
10
|
-
* - Cloud Pub/Sub services
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Generic PubSub engine interface
|
|
14
|
-
* Compatible with various PubSub implementations
|
|
15
|
-
*/
|
|
16
|
-
interface PubSubEngine<Topics extends Record<string, unknown> = Record<string, unknown>> {
|
|
17
|
-
/**
|
|
18
|
-
* Publish an event to a topic
|
|
19
|
-
* @param topic - Topic name to publish to
|
|
20
|
-
* @param payload - Event payload
|
|
21
|
-
*/
|
|
22
|
-
publish: <K extends keyof Topics>(topic: K, payload: Topics[K]) => Promise<void>;
|
|
23
|
-
/**
|
|
24
|
-
* Subscribe to a topic
|
|
25
|
-
* @param topic - Topic name to subscribe to
|
|
26
|
-
* @returns AsyncIterable that yields events
|
|
27
|
-
*/
|
|
28
|
-
subscribe: <K extends keyof Topics>(topic: K) => AsyncIterable<Topics[K]>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Type alias for typed PubSub instances
|
|
32
|
-
*/
|
|
33
|
-
type TypedPubSub<Topics extends Record<string, unknown>> = PubSubEngine<Topics>;
|
|
34
|
-
/**
|
|
35
|
-
* Create a simple in-memory PubSub instance
|
|
36
|
-
*
|
|
37
|
-
* This implementation uses EventEmitter for lightweight pub/sub functionality.
|
|
38
|
-
* Suitable for:
|
|
39
|
-
* - Development environments
|
|
40
|
-
* - Single-instance production deployments
|
|
41
|
-
* - Testing
|
|
42
|
-
*
|
|
43
|
-
* NOT suitable for:
|
|
44
|
-
* - Multi-instance/clustered deployments (events won't propagate across instances)
|
|
45
|
-
* - High-throughput scenarios (consider Redis-based PubSub)
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* // Define your topic types
|
|
50
|
-
* interface MyTopics {
|
|
51
|
-
* 'user:created': { id: string; name: string }
|
|
52
|
-
* 'message:sent': { channelId: string; content: string }
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* // Create typed PubSub instance
|
|
56
|
-
* const pubsub = createPubSub<MyTopics>()
|
|
57
|
-
*
|
|
58
|
-
* // Publish events
|
|
59
|
-
* await pubsub.publish('user:created', { id: '123', name: 'John' })
|
|
60
|
-
*
|
|
61
|
-
* // Subscribe to events (in a resolver)
|
|
62
|
-
* export const userSubscriptions = defineSubscription({
|
|
63
|
-
* userCreated: {
|
|
64
|
-
* subscribe: async function* () {
|
|
65
|
-
* yield* pubsub.subscribe('user:created')
|
|
66
|
-
* }
|
|
67
|
-
* }
|
|
68
|
-
* })
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
declare function createPubSub<Topics extends Record<string, unknown> = Record<string, unknown>>(): PubSubEngine<Topics>;
|
|
72
|
-
/**
|
|
73
|
-
* Filter subscription events based on a predicate
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* export const chatSubscriptions = defineSubscription({
|
|
78
|
-
* messageAdded: {
|
|
79
|
-
* subscribe: async function* (_, { channelId }) {
|
|
80
|
-
* yield* withFilter(
|
|
81
|
-
* pubsub.subscribe('message:added'),
|
|
82
|
-
* (message) => message.channelId === channelId
|
|
83
|
-
* )
|
|
84
|
-
* }
|
|
85
|
-
* }
|
|
86
|
-
* })
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
declare function withFilter<T>(asyncIterable: AsyncIterable<T>, filter: (value: T) => boolean | Promise<boolean>): AsyncIterable<T>;
|
|
90
|
-
/**
|
|
91
|
-
* Map subscription events to a different shape
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* export const chatSubscriptions = defineSubscription({
|
|
96
|
-
* messageAdded: {
|
|
97
|
-
* subscribe: async function* () {
|
|
98
|
-
* yield* mapAsyncIterator(
|
|
99
|
-
* pubsub.subscribe('message:added'),
|
|
100
|
-
* (event) => ({ messageAdded: event.message })
|
|
101
|
-
* )
|
|
102
|
-
* }
|
|
103
|
-
* }
|
|
104
|
-
* })
|
|
105
|
-
* ```
|
|
106
|
-
*/
|
|
107
|
-
declare function mapAsyncIterator<T, U>(asyncIterable: AsyncIterable<T>, mapper: (value: T) => U | Promise<U>): AsyncIterable<U>;
|
|
108
|
-
//#endregion
|
|
109
|
-
export { PubSubEngine, TypedPubSub, createPubSub, mapAsyncIterator, withFilter };
|
|
1
|
+
import { PubSubEngine, TypedPubSub, createPubSub, mapAsyncIterator, withFilter } from "./memory-pubsub.mjs";
|
|
2
|
+
export { type PubSubEngine, type TypedPubSub, createPubSub, mapAsyncIterator, withFilter };
|