@vladimirdev635/gql-codegen 0.0.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.
@@ -0,0 +1,7 @@
1
+ import ts from "typescript";
2
+ import { Actor, ActorContext } from "../../config.js";
3
+ export interface ApolloActorConfig {
4
+ tsconfigCompilerOptions: ts.CompilerOptions;
5
+ outDir: string;
6
+ }
7
+ export declare function buildApolloActor(config: ApolloActorConfig): Actor<ActorContext>;
@@ -0,0 +1,18 @@
1
+ import ts from "typescript";
2
+ import { mkdirSync, writeFileSync } from "fs";
3
+ import { join } from "path";
4
+ function apolloActor(config, context) {
5
+ const printer = ts.createPrinter(config.tsconfigCompilerOptions);
6
+ const sourceFile = ts.createSourceFile('', '', config.tsconfigCompilerOptions.target || ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
7
+ const nodes = Object.entries(context.schema.server.objects).map(([key, value]) => {
8
+ return ts.factory.createVariableStatement([ts.factory.createToken(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
9
+ ts.factory.createVariableDeclaration(key, undefined, undefined, ts.factory.createStringLiteral(value.name))
10
+ ], ts.NodeFlags.Const));
11
+ });
12
+ const code = printer.printList(ts.ListFormat.MultiLine, ts.factory.createNodeArray(nodes), sourceFile);
13
+ mkdirSync(config.outDir, { recursive: true });
14
+ writeFileSync(join(config.outDir, "check.ts"), code);
15
+ }
16
+ export function buildApolloActor(config) {
17
+ return context => apolloActor(config, context);
18
+ }
@@ -0,0 +1,2 @@
1
+ export { buildApolloActor, ApolloActorConfig } from './actor.js';
2
+ export { loadTsConfigCompilerOptions } from './utils.js';
@@ -0,0 +1,2 @@
1
+ export { buildApolloActor } from './actor.js';
2
+ export { loadTsConfigCompilerOptions } from './utils.js';
@@ -0,0 +1,2 @@
1
+ import ts from "typescript";
2
+ export declare function loadTsConfigCompilerOptions(configPath?: string): ts.CompilerOptions;
@@ -0,0 +1,7 @@
1
+ import ts from "typescript";
2
+ import { readFileSync } from "fs";
3
+ export function loadTsConfigCompilerOptions(configPath = './tsconfig.json') {
4
+ const tsconfig = ts.readConfigFile(configPath, (p) => readFileSync(p).toString());
5
+ const config = ts.parseJsonConfigFileContent(tsconfig.config, ts.sys, configPath);
6
+ return config.options;
7
+ }
@@ -0,0 +1,11 @@
1
+ import { RootSchema } from "./schema.js";
2
+ import { Logger } from "pino";
3
+ export interface ActorContext {
4
+ readonly schema: RootSchema;
5
+ readonly logger: Logger;
6
+ }
7
+ export type Actor<T extends ActorContext> = (c: T) => Promise<void> | void;
8
+ export interface Config<T extends ActorContext> {
9
+ context: T;
10
+ actors: Actor<T>[];
11
+ }
package/dist/config.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export { Actor, ActorContext, Config } from './config.js';
2
+ export { run } from './main.js';
3
+ export { loadSchemaFromFile } from './schema.utils.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { run } from './main.js';
2
+ export { loadSchemaFromFile } from './schema.utils.js';
package/dist/main.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { ActorContext, Config } from "./config.js";
2
+ export declare function run<TContext extends ActorContext>(config: Config<TContext>): Promise<void>;
package/dist/main.js ADDED
@@ -0,0 +1,5 @@
1
+ export async function run(config) {
2
+ for (const actor of config.actors) {
3
+ await actor(config.context);
4
+ }
5
+ }