@soda-gql/config 0.0.7 → 0.0.9
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/index.cjs +3 -0
- package/dist/index.d.cts +17 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +17 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -85,6 +85,7 @@ const SchemaConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({
|
|
|
85
85
|
runtimeAdapter: zod.default.string().min(1),
|
|
86
86
|
scalars: zod.default.string().min(1)
|
|
87
87
|
});
|
|
88
|
+
const StylesConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({ importExtension: zod.default.boolean().optional() });
|
|
88
89
|
const SodaGqlConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({
|
|
89
90
|
analyzer: zod.default.enum(["ts", "swc"]).optional(),
|
|
90
91
|
outdir: zod.default.string().min(1),
|
|
@@ -92,6 +93,7 @@ const SodaGqlConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({
|
|
|
92
93
|
include: zod.default.array(zod.default.string().min(1)),
|
|
93
94
|
exclude: zod.default.array(zod.default.string().min(1)).optional(),
|
|
94
95
|
schemas: zod.default.record(zod.default.string(), SchemaConfigSchema),
|
|
96
|
+
styles: StylesConfigSchema.optional(),
|
|
95
97
|
plugins: zod.default.record(zod.default.string(), zod.default.unknown()).optional()
|
|
96
98
|
});
|
|
97
99
|
function validateConfig(config) {
|
|
@@ -185,6 +187,7 @@ function normalizeConfig(config, configPath) {
|
|
|
185
187
|
runtimeAdapter: (0, node_path.resolve)(configDir, schemaConfig.runtimeAdapter),
|
|
186
188
|
scalars: (0, node_path.resolve)(configDir, schemaConfig.scalars)
|
|
187
189
|
}])),
|
|
190
|
+
styles: { importExtension: config.styles?.importExtension ?? false },
|
|
188
191
|
plugins: config.plugins ?? {}
|
|
189
192
|
};
|
|
190
193
|
return (0, neverthrow.ok)(resolved);
|
package/dist/index.d.cts
CHANGED
|
@@ -26,6 +26,18 @@ type SchemaConfig = {
|
|
|
26
26
|
readonly runtimeAdapter: string;
|
|
27
27
|
readonly scalars: string;
|
|
28
28
|
};
|
|
29
|
+
type StylesConfig = {
|
|
30
|
+
/**
|
|
31
|
+
* Whether to include file extensions in import paths.
|
|
32
|
+
* When true, imports will have extensions like `.js`.
|
|
33
|
+
* When false (default), imports will have no extension.
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
readonly importExtension?: boolean;
|
|
37
|
+
};
|
|
38
|
+
type ResolvedStylesConfig = {
|
|
39
|
+
readonly importExtension: boolean;
|
|
40
|
+
};
|
|
29
41
|
type PluginConfig = Record<string, unknown>;
|
|
30
42
|
type SodaGqlConfig = {
|
|
31
43
|
/**
|
|
@@ -65,6 +77,10 @@ type SodaGqlConfig = {
|
|
|
65
77
|
* The schemas to generate for the project.
|
|
66
78
|
*/
|
|
67
79
|
readonly schemas: Readonly<Record<string, SchemaConfig>>;
|
|
80
|
+
/**
|
|
81
|
+
* Output styles configuration for generated code.
|
|
82
|
+
*/
|
|
83
|
+
readonly styles?: StylesConfig;
|
|
68
84
|
/**
|
|
69
85
|
* The plugins to use for the project.
|
|
70
86
|
*/
|
|
@@ -77,6 +93,7 @@ type ResolvedSodaGqlConfig = {
|
|
|
77
93
|
readonly include: readonly string[];
|
|
78
94
|
readonly exclude: readonly string[];
|
|
79
95
|
readonly schemas: Readonly<Record<string, SchemaConfig>>;
|
|
96
|
+
readonly styles: ResolvedStylesConfig;
|
|
80
97
|
readonly plugins: PluginConfig;
|
|
81
98
|
};
|
|
82
99
|
//#endregion
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EAAe,MAAA;EAEf,SAAA,QAAW,CAAA,EAAA,MACN;EAMJ,SAAA,KAeX,CAAA,EAAA,OAAA;CAf0B;AAAA,cAAf,WAAe,EAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAAA,IAAA,EAMpB,eANoB;EAAA,OAAA,EAAA,MAAA;EAMpB,QAAA,CAAA,EAAA,MAAA;EAIJ,KAAA,CAAA,EAAA,OAAA;CAKF,EAAA,GALE,WAKF;;;KCvBU,YAAA;;;EDDA,SAAA,OAAA,EAAe,MAAA;AAE3B,CAAA;AAOa,KCDD,YAAA,GAAe,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EAAe,MAAA;EAEf,SAAA,QAAW,CAAA,EAAA,MACN;EAMJ,SAAA,KAeX,CAAA,EAAA,OAAA;CAf0B;AAAA,cAAf,WAAe,EAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAAA,IAAA,EAMpB,eANoB;EAAA,OAAA,EAAA,MAAA;EAMpB,QAAA,CAAA,EAAA,MAAA;EAIJ,KAAA,CAAA,EAAA,OAAA;CAKF,EAAA,GALE,WAKF;;;KCvBU,YAAA;;;EDDA,SAAA,OAAA,EAAe,MAAA;AAE3B,CAAA;AAOa,KCDD,YAAA,GDgBV;EAf0B;;;;;;EAe1B,SAAA,eAAA,CAAA,EAAA,OAAA;;KCLU,oBAAA;;AAlBZ,CAAA;AAOY,KAgBA,YAAA,GAAe,MAhBH,CAAA,MAAA,EAAA,OAAA,CAAA;AAWZ,KAQA,aAAA,GARoB;EAKpB;AAGZ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AA,CAAA;AAE3B;AAOA;;AAA4B,iBGWZ,cAAA,CHXY,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,IAAA;;;;AAUxB,iBGkBY,UAAA,CHlBZ,UAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EGkBwD,MHlBxD,CGkB+D,qBHlB/D,EGkBsF,WHlBtF,CAAA;;;;iBG8CY,cAAA,eAA6B,OAAO,uBAAuB;;;AHjE3E;AAEA;AAOA;;AAA4B,iBICZ,eAAA,CJDY,MAAA,EICY,aJDZ,EAAA,UAAA,EAAA,MAAA,CAAA,EICgD,MJDhD,CICuD,qBJDvD,EIC8E,WJD9E,CAAA;;;;;AAT5B;AAEA;AAOa,iBKQS,cLOpB,CAAA,CAAA,CAAA,CAAA,MAAA,EKP8C,OLO9C,CKPsD,aLOtD,CAAA,EAAA,EAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GKPkG,OLOlG,CKP0G,CLO1G,CAAA,CAAA,EKP+G,OLO/G,CKPuH,CLOvH,CAAA;;;;AAf0B,iBK+BZ,oBAAA,CL/BY,GAAA,EAAA,MAAA,EAAA,MAAA,EK+B8B,OL/B9B,CK+BsC,aL/BtC,CAAA,CAAA,EAAA,MAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -26,6 +26,18 @@ type SchemaConfig = {
|
|
|
26
26
|
readonly runtimeAdapter: string;
|
|
27
27
|
readonly scalars: string;
|
|
28
28
|
};
|
|
29
|
+
type StylesConfig = {
|
|
30
|
+
/**
|
|
31
|
+
* Whether to include file extensions in import paths.
|
|
32
|
+
* When true, imports will have extensions like `.js`.
|
|
33
|
+
* When false (default), imports will have no extension.
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
readonly importExtension?: boolean;
|
|
37
|
+
};
|
|
38
|
+
type ResolvedStylesConfig = {
|
|
39
|
+
readonly importExtension: boolean;
|
|
40
|
+
};
|
|
29
41
|
type PluginConfig = Record<string, unknown>;
|
|
30
42
|
type SodaGqlConfig = {
|
|
31
43
|
/**
|
|
@@ -65,6 +77,10 @@ type SodaGqlConfig = {
|
|
|
65
77
|
* The schemas to generate for the project.
|
|
66
78
|
*/
|
|
67
79
|
readonly schemas: Readonly<Record<string, SchemaConfig>>;
|
|
80
|
+
/**
|
|
81
|
+
* Output styles configuration for generated code.
|
|
82
|
+
*/
|
|
83
|
+
readonly styles?: StylesConfig;
|
|
68
84
|
/**
|
|
69
85
|
* The plugins to use for the project.
|
|
70
86
|
*/
|
|
@@ -77,6 +93,7 @@ type ResolvedSodaGqlConfig = {
|
|
|
77
93
|
readonly include: readonly string[];
|
|
78
94
|
readonly exclude: readonly string[];
|
|
79
95
|
readonly schemas: Readonly<Record<string, SchemaConfig>>;
|
|
96
|
+
readonly styles: ResolvedStylesConfig;
|
|
80
97
|
readonly plugins: PluginConfig;
|
|
81
98
|
};
|
|
82
99
|
//#endregion
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EAAe,MAAA;EAEf,SAAA,QAAW,CAAA,EAAA,MACN;EAMJ,SAAA,KAeX,CAAA,EAAA,OAAA;CAf0B;AAAA,cAAf,WAAe,EAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAAA,IAAA,EAMpB,eANoB;EAAA,OAAA,EAAA,MAAA;EAMpB,QAAA,CAAA,EAAA,MAAA;EAIJ,KAAA,CAAA,EAAA,OAAA;CAKF,EAAA,GALE,WAKF;;;KCvBU,YAAA;;;EDDA,SAAA,OAAA,EAAe,MAAA;AAE3B,CAAA;AAOa,KCDD,YAAA,GAAe,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/err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AA,EAAA,EAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GKPkG,OLOlG,CKP0G,CLO1G,CAAA,CAAA,EKP+G,OLO/G,CKPuH,CLOvH,CAAA;;;;AAf0B,iBK+BZ,oBAAA,CL/BY,GAAA,EAAA,MAAA,EAAA,MAAA,EK+B8B,OL/B9B,CK+BsC,aL/BtC,CAAA,CAAA,EAAA,MAAA"}
|
package/dist/index.mjs
CHANGED
|
@@ -61,6 +61,7 @@ const SchemaConfigSchema = defineSchemaFor()({
|
|
|
61
61
|
runtimeAdapter: z.string().min(1),
|
|
62
62
|
scalars: z.string().min(1)
|
|
63
63
|
});
|
|
64
|
+
const StylesConfigSchema = defineSchemaFor()({ importExtension: z.boolean().optional() });
|
|
64
65
|
const SodaGqlConfigSchema = defineSchemaFor()({
|
|
65
66
|
analyzer: z.enum(["ts", "swc"]).optional(),
|
|
66
67
|
outdir: z.string().min(1),
|
|
@@ -68,6 +69,7 @@ const SodaGqlConfigSchema = defineSchemaFor()({
|
|
|
68
69
|
include: z.array(z.string().min(1)),
|
|
69
70
|
exclude: z.array(z.string().min(1)).optional(),
|
|
70
71
|
schemas: z.record(z.string(), SchemaConfigSchema),
|
|
72
|
+
styles: StylesConfigSchema.optional(),
|
|
71
73
|
plugins: z.record(z.string(), z.unknown()).optional()
|
|
72
74
|
});
|
|
73
75
|
function validateConfig(config) {
|
|
@@ -161,6 +163,7 @@ function normalizeConfig(config, configPath) {
|
|
|
161
163
|
runtimeAdapter: resolve(configDir, schemaConfig.runtimeAdapter),
|
|
162
164
|
scalars: resolve(configDir, schemaConfig.scalars)
|
|
163
165
|
}])),
|
|
166
|
+
styles: { importExtension: config.styles?.importExtension ?? false },
|
|
164
167
|
plugins: config.plugins ?? {}
|
|
165
168
|
};
|
|
166
169
|
return ok(resolved);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["config: SodaGqlConfig","resolve","mod: { exports: unknown }","configModule","dirname","resolved: ResolvedSodaGqlConfig"],"sources":["../src/errors.ts","../src/helper.ts","../src/evaluation.ts","../src/normalize.ts","../src/loader.ts","../src/test-utils.ts","../src/index.ts"],"sourcesContent":["export type ConfigErrorCode = \"CONFIG_NOT_FOUND\" | \"CONFIG_LOAD_FAILED\" | \"CONFIG_VALIDATION_FAILED\" | \"CONFIG_INVALID_PATH\";\n\nexport type ConfigError = {\n readonly code: ConfigErrorCode;\n readonly message: string;\n readonly filePath?: string;\n readonly cause?: unknown;\n};\n\nexport const configError = ({\n code,\n message,\n filePath,\n cause,\n}: {\n code: ConfigErrorCode;\n message: string;\n filePath?: string;\n cause?: unknown;\n}): ConfigError => ({\n code,\n message,\n filePath,\n cause,\n});\n","import { defineSchemaFor } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport z from \"zod\";\nimport { type ConfigError, configError } from \"./errors\";\nimport type { SchemaConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Thin wrapper class to simplify the validation of exported value from config file.\n * As we use SWC + VM to execute the config file, the exported value is not typed.\n * This wrapper class ensures the exported value is a valid soda-gql config object.\n */\nexport class SodaGqlConfigContainer {\n private constructor(public readonly config: SodaGqlConfig) {}\n\n public static create(config: SodaGqlConfig): SodaGqlConfigContainer {\n return new SodaGqlConfigContainer(config);\n }\n}\n\n/**\n * Type-safe helper for defining soda-gql configuration.\n * Supports both static and dynamic (async) configs.\n *\n * @example Static config\n * ```ts\n * import { defineConfig } from \"@soda-gql/config\";\n *\n * export default defineConfig({\n * outdir: \"./graphql-system\",\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * });\n * ```\n *\n * @example Async config\n * ```ts\n * export default defineConfig(async () => ({\n * outdir: await resolveOutputDir(),\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * }));\n * ```\n */\nexport function defineConfig(config: SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: () => SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: SodaGqlConfig | (() => SodaGqlConfig)): SodaGqlConfigContainer {\n const validated = validateConfig(typeof config === \"function\" ? config() : config);\n if (validated.isErr()) {\n throw validated.error;\n }\n return SodaGqlConfigContainer.create(validated.value);\n}\n\nconst SchemaConfigSchema = defineSchemaFor<SchemaConfig>()({\n schema: z.string().min(1),\n runtimeAdapter: z.string().min(1),\n scalars: z.string().min(1),\n});\n\nconst SodaGqlConfigSchema = defineSchemaFor<SodaGqlConfig>()({\n analyzer: z.enum([\"ts\", \"swc\"]).optional(),\n outdir: z.string().min(1),\n graphqlSystemAliases: z.array(z.string()).optional(),\n include: z.array(z.string().min(1)),\n exclude: z.array(z.string().min(1)).optional(),\n schemas: z.record(z.string(), SchemaConfigSchema),\n plugins: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport function validateConfig(config: unknown): Result<SodaGqlConfig, ConfigError> {\n const result = SodaGqlConfigSchema.safeParse(config);\n\n if (!result.success) {\n return err(\n configError({\n code: \"CONFIG_VALIDATION_FAILED\",\n message: `Invalid config: ${result.error.message}`,\n }),\n );\n }\n\n return ok(result.data satisfies SodaGqlConfig);\n}\n","import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path/posix\";\nimport { Script } from \"node:vm\";\nimport { resolveRelativeImportWithExistenceCheck } from \"@soda-gql/common\";\nimport { transformSync } from \"@swc/core\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport { type ConfigError, configError } from \"./errors\";\nimport { SodaGqlConfigContainer } from \"./helper\";\n// TODO: split config package into definition and evaluation parts\nimport * as configModule from \"./index\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Load and execute TypeScript config file synchronously using SWC + VM.\n */\nexport function executeConfigFile(configPath: string): Result<SodaGqlConfig, ConfigError> {\n const filePath = resolve(configPath);\n try {\n // Read the config file\n const source = readFileSync(filePath, \"utf-8\");\n\n // Transform TypeScript to CommonJS using SWC\n const result = transformSync(source, {\n filename: filePath,\n jsc: {\n parser: {\n syntax: \"typescript\",\n },\n },\n module: {\n type: \"commonjs\",\n },\n sourceMaps: false,\n minify: false,\n });\n\n // Create CommonJS context\n const mod: { exports: unknown } = { exports: {} };\n\n const requireInner = createRequire(filePath);\n const require = (specifier: string) => {\n if (specifier === \"@soda-gql/config\") {\n return configModule;\n }\n\n // Handle external modules normally\n if (!specifier.startsWith(\".\")) {\n return requireInner(specifier);\n }\n\n // Resolve relative imports with existence check\n const resolvedPath = resolveRelativeImportWithExistenceCheck({ filePath, specifier });\n if (!resolvedPath) {\n throw new Error(`Module not found: ${specifier}`);\n }\n return requireInner(resolvedPath);\n };\n\n // Execute in VM context\n new Script(result.code, { filename: filePath }).runInNewContext({\n require,\n module: mod,\n exports: mod.exports,\n __dirname: dirname(filePath),\n __filename: filePath,\n console,\n process,\n });\n\n const config =\n mod.exports &&\n typeof mod.exports === \"object\" &&\n \"default\" in mod.exports &&\n mod.exports.default instanceof SodaGqlConfigContainer\n ? mod.exports.default.config\n : null;\n\n if (!config) {\n throw new Error(\"Invalid config module\");\n }\n\n return ok(config);\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,\n filePath: filePath,\n cause: error,\n }),\n );\n }\n}\n","import { dirname, resolve } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { ok } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport type { ResolvedSodaGqlConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Resolve and normalize config with defaults.\n * Paths in the config are resolved relative to the config file's directory.\n */\nexport function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configDir = dirname(configPath);\n // Default analyzer to \"ts\"\n const analyzer = config.analyzer ?? \"ts\";\n\n // Default graphqlSystemAliases to [\"@/graphql-system\"]\n const graphqlSystemAliases = config.graphqlSystemAliases ?? [\"@/graphql-system\"];\n\n // Default exclude to empty array\n const exclude = config.exclude ?? [];\n\n const resolved: ResolvedSodaGqlConfig = {\n analyzer,\n outdir: resolve(configDir, config.outdir),\n graphqlSystemAliases,\n include: config.include.map((pattern) => resolve(configDir, pattern)),\n exclude: exclude.map((pattern) => resolve(configDir, pattern)),\n schemas: Object.fromEntries(\n Object.entries(config.schemas).map(([name, schemaConfig]) => [\n name,\n {\n schema: resolve(configDir, schemaConfig.schema),\n runtimeAdapter: resolve(configDir, schemaConfig.runtimeAdapter),\n scalars: resolve(configDir, schemaConfig.scalars),\n },\n ]),\n ),\n plugins: config.plugins ?? {},\n };\n\n return ok(resolved);\n}\n","import { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { err } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport { configError } from \"./errors\";\nimport { executeConfigFile } from \"./evaluation\";\nimport { normalizeConfig } from \"./normalize\";\nimport type { ResolvedSodaGqlConfig } from \"./types\";\n\nexport const DEFAULT_CONFIG_FILENAMES = [\n \"soda-gql.config.ts\",\n \"soda-gql.config.mts\",\n \"soda-gql.config.js\",\n \"soda-gql.config.mjs\",\n] as const;\n\n/**\n * Find config file by walking up directory tree.\n */\nexport function findConfigFile(startDir: string = process.cwd()): string | null {\n let currentDir = startDir;\n while (currentDir !== dirname(currentDir)) {\n for (const filename of DEFAULT_CONFIG_FILENAMES) {\n const configPath = join(currentDir, filename);\n if (existsSync(configPath)) {\n return configPath;\n }\n }\n currentDir = dirname(currentDir);\n }\n return null;\n}\n\n/**\n * Load config with Result type (for library use).\n */\nexport function loadConfig(configPath: string | undefined): Result<ResolvedSodaGqlConfig, ConfigError> {\n const resolvedPath = configPath ?? findConfigFile();\n\n if (!resolvedPath) {\n return err(configError({ code: \"CONFIG_NOT_FOUND\", message: \"Config file not found\" }));\n }\n\n try {\n const result = executeConfigFile(resolvedPath);\n if (result.isErr()) {\n return err(result.error);\n }\n return normalizeConfig(result.value, resolvedPath);\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error}`,\n filePath: resolvedPath,\n cause: error,\n }),\n );\n }\n}\n\n/**\n * Load config from specific directory.\n */\nexport function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configPath = findConfigFile(dir);\n return loadConfig(configPath ?? undefined);\n}\n","import { mkdirSync, rmSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Get project root from this package location.\n * packages/config/src/test-utils.ts -> project root\n */\nconst getProjectRoot = (): string => {\n return fileURLToPath(new URL(\"../../../\", import.meta.url));\n};\n\n/**\n * Create temporary config file with proper formatting.\n * Uses template literals to support functions, regex, etc.\n */\nexport async function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPath: string) => Promise<T>): Promise<T> {\n const projectRoot = getProjectRoot();\n const tmpDir = join(projectRoot, \"tests/.tmp/config-test\", `${Date.now()}`);\n mkdirSync(tmpDir, { recursive: true });\n const configPath = join(tmpDir, \"soda-gql.config.ts\");\n\n // Generate config file using template\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n\n return fn(configPath).finally(() => {\n rmSync(tmpDir, { recursive: true, force: true });\n });\n}\n\n/**\n * Simple temp config creation (without auto-cleanup).\n */\nexport function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string {\n const configPath = join(dir, \"soda-gql.config.ts\");\n\n // Write config as TypeScript module\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n return configPath;\n}\n","export type { ConfigError, ConfigErrorCode } from \"./errors\";\nexport { configError } from \"./errors\";\nexport { defineConfig, validateConfig } from \"./helper\";\nexport {\n findConfigFile,\n loadConfig,\n loadConfigFrom,\n} from \"./loader\";\nexport { normalizeConfig } from \"./normalize\";\nexport { createTempConfigFile, withTempConfig } from \"./test-utils\";\nexport type {\n PluginConfig,\n ResolvedSodaGqlConfig,\n SchemaConfig,\n SodaGqlConfig,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,eAAe,EAC1B,MACA,SACA,UACA,aAMkB;CAClB;CACA;CACA;CACA;CACD;;;;;;;;;ACbD,IAAa,yBAAb,MAAa,uBAAuB;CAClC,AAAQ,YAAY,AAAgBA,QAAuB;EAAvB;;CAEpC,OAAc,OAAO,QAA+C;AAClE,SAAO,IAAI,uBAAuB,OAAO;;;AA0C7C,SAAgB,aAAa,QAAuE;CAClG,MAAM,YAAY,eAAe,OAAO,WAAW,aAAa,QAAQ,GAAG,OAAO;AAClF,KAAI,UAAU,OAAO,EAAE;AACrB,QAAM,UAAU;;AAElB,QAAO,uBAAuB,OAAO,UAAU,MAAM;;AAGvD,MAAM,qBAAqB,iBAA+B,CAAC;CACzD,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE;CACzB,gBAAgB,EAAE,QAAQ,CAAC,IAAI,EAAE;CACjC,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC3B,CAAC;AAEF,MAAM,sBAAsB,iBAAgC,CAAC;CAC3D,UAAU,EAAE,KAAK,CAAC,MAAM,MAAM,CAAC,CAAC,UAAU;CAC1C,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE;CACzB,sBAAsB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,UAAU;CACpD,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,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8BAGM,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC;EAC5D,MAAM;AAEN,eAAc,YAAY,cAAc;AACxC,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["config: SodaGqlConfig","resolve","mod: { exports: unknown }","configModule","dirname","resolved: ResolvedSodaGqlConfig"],"sources":["../src/errors.ts","../src/helper.ts","../src/evaluation.ts","../src/normalize.ts","../src/loader.ts","../src/test-utils.ts","../src/index.ts"],"sourcesContent":["export type ConfigErrorCode = \"CONFIG_NOT_FOUND\" | \"CONFIG_LOAD_FAILED\" | \"CONFIG_VALIDATION_FAILED\" | \"CONFIG_INVALID_PATH\";\n\nexport type ConfigError = {\n readonly code: ConfigErrorCode;\n readonly message: string;\n readonly filePath?: string;\n readonly cause?: unknown;\n};\n\nexport const configError = ({\n code,\n message,\n filePath,\n cause,\n}: {\n code: ConfigErrorCode;\n message: string;\n filePath?: string;\n cause?: unknown;\n}): ConfigError => ({\n code,\n message,\n filePath,\n cause,\n});\n","import { defineSchemaFor } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport z from \"zod\";\nimport { type ConfigError, configError } from \"./errors\";\nimport type { SchemaConfig, SodaGqlConfig, StylesConfig } from \"./types\";\n\n/**\n * Thin wrapper class to simplify the validation of exported value from config file.\n * As we use SWC + VM to execute the config file, the exported value is not typed.\n * This wrapper class ensures the exported value is a valid soda-gql config object.\n */\nexport class SodaGqlConfigContainer {\n private constructor(public readonly config: SodaGqlConfig) {}\n\n public static create(config: SodaGqlConfig): SodaGqlConfigContainer {\n return new SodaGqlConfigContainer(config);\n }\n}\n\n/**\n * Type-safe helper for defining soda-gql configuration.\n * Supports both static and dynamic (async) configs.\n *\n * @example Static config\n * ```ts\n * import { defineConfig } from \"@soda-gql/config\";\n *\n * export default defineConfig({\n * outdir: \"./graphql-system\",\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * });\n * ```\n *\n * @example Async config\n * ```ts\n * export default defineConfig(async () => ({\n * outdir: await resolveOutputDir(),\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * }));\n * ```\n */\nexport function defineConfig(config: SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: () => SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: SodaGqlConfig | (() => SodaGqlConfig)): SodaGqlConfigContainer {\n const validated = validateConfig(typeof config === \"function\" ? config() : config);\n if (validated.isErr()) {\n throw validated.error;\n }\n return SodaGqlConfigContainer.create(validated.value);\n}\n\nconst SchemaConfigSchema = defineSchemaFor<SchemaConfig>()({\n schema: z.string().min(1),\n runtimeAdapter: z.string().min(1),\n scalars: z.string().min(1),\n});\n\nconst StylesConfigSchema = defineSchemaFor<StylesConfig>()({\n importExtension: z.boolean().optional(),\n});\n\nconst SodaGqlConfigSchema = defineSchemaFor<SodaGqlConfig>()({\n analyzer: z.enum([\"ts\", \"swc\"]).optional(),\n outdir: z.string().min(1),\n graphqlSystemAliases: z.array(z.string()).optional(),\n include: z.array(z.string().min(1)),\n exclude: z.array(z.string().min(1)).optional(),\n schemas: z.record(z.string(), SchemaConfigSchema),\n styles: StylesConfigSchema.optional(),\n plugins: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport function validateConfig(config: unknown): Result<SodaGqlConfig, ConfigError> {\n const result = SodaGqlConfigSchema.safeParse(config);\n\n if (!result.success) {\n return err(\n configError({\n code: \"CONFIG_VALIDATION_FAILED\",\n message: `Invalid config: ${result.error.message}`,\n }),\n );\n }\n\n return ok(result.data satisfies SodaGqlConfig);\n}\n","import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path/posix\";\nimport { Script } from \"node:vm\";\nimport { resolveRelativeImportWithExistenceCheck } from \"@soda-gql/common\";\nimport { transformSync } from \"@swc/core\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport { type ConfigError, configError } from \"./errors\";\nimport { SodaGqlConfigContainer } from \"./helper\";\n// TODO: split config package into definition and evaluation parts\nimport * as configModule from \"./index\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Load and execute TypeScript config file synchronously using SWC + VM.\n */\nexport function executeConfigFile(configPath: string): Result<SodaGqlConfig, ConfigError> {\n const filePath = resolve(configPath);\n try {\n // Read the config file\n const source = readFileSync(filePath, \"utf-8\");\n\n // Transform TypeScript to CommonJS using SWC\n const result = transformSync(source, {\n filename: filePath,\n jsc: {\n parser: {\n syntax: \"typescript\",\n },\n },\n module: {\n type: \"commonjs\",\n },\n sourceMaps: false,\n minify: false,\n });\n\n // Create CommonJS context\n const mod: { exports: unknown } = { exports: {} };\n\n const requireInner = createRequire(filePath);\n const require = (specifier: string) => {\n if (specifier === \"@soda-gql/config\") {\n return configModule;\n }\n\n // Handle external modules normally\n if (!specifier.startsWith(\".\")) {\n return requireInner(specifier);\n }\n\n // Resolve relative imports with existence check\n const resolvedPath = resolveRelativeImportWithExistenceCheck({ filePath, specifier });\n if (!resolvedPath) {\n throw new Error(`Module not found: ${specifier}`);\n }\n return requireInner(resolvedPath);\n };\n\n // Execute in VM context\n new Script(result.code, { filename: filePath }).runInNewContext({\n require,\n module: mod,\n exports: mod.exports,\n __dirname: dirname(filePath),\n __filename: filePath,\n console,\n process,\n });\n\n const config =\n mod.exports &&\n typeof mod.exports === \"object\" &&\n \"default\" in mod.exports &&\n mod.exports.default instanceof SodaGqlConfigContainer\n ? mod.exports.default.config\n : null;\n\n if (!config) {\n throw new Error(\"Invalid config module\");\n }\n\n return ok(config);\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,\n filePath: filePath,\n cause: error,\n }),\n );\n }\n}\n","import { dirname, resolve } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { ok } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport type { ResolvedSodaGqlConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Resolve and normalize config with defaults.\n * Paths in the config are resolved relative to the config file's directory.\n */\nexport function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configDir = dirname(configPath);\n // Default analyzer to \"ts\"\n const analyzer = config.analyzer ?? \"ts\";\n\n // Default graphqlSystemAliases to [\"@/graphql-system\"]\n const graphqlSystemAliases = config.graphqlSystemAliases ?? [\"@/graphql-system\"];\n\n // Default exclude to empty array\n const exclude = config.exclude ?? [];\n\n const resolved: ResolvedSodaGqlConfig = {\n analyzer,\n outdir: resolve(configDir, config.outdir),\n graphqlSystemAliases,\n include: config.include.map((pattern) => resolve(configDir, pattern)),\n exclude: exclude.map((pattern) => resolve(configDir, pattern)),\n schemas: Object.fromEntries(\n Object.entries(config.schemas).map(([name, schemaConfig]) => [\n name,\n {\n schema: resolve(configDir, schemaConfig.schema),\n runtimeAdapter: resolve(configDir, schemaConfig.runtimeAdapter),\n scalars: resolve(configDir, schemaConfig.scalars),\n },\n ]),\n ),\n styles: {\n importExtension: config.styles?.importExtension ?? false,\n },\n plugins: config.plugins ?? {},\n };\n\n return ok(resolved);\n}\n","import { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { err } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport { configError } from \"./errors\";\nimport { executeConfigFile } from \"./evaluation\";\nimport { normalizeConfig } from \"./normalize\";\nimport type { ResolvedSodaGqlConfig } from \"./types\";\n\nexport const DEFAULT_CONFIG_FILENAMES = [\n \"soda-gql.config.ts\",\n \"soda-gql.config.mts\",\n \"soda-gql.config.js\",\n \"soda-gql.config.mjs\",\n] as const;\n\n/**\n * Find config file by walking up directory tree.\n */\nexport function findConfigFile(startDir: string = process.cwd()): string | null {\n let currentDir = startDir;\n while (currentDir !== dirname(currentDir)) {\n for (const filename of DEFAULT_CONFIG_FILENAMES) {\n const configPath = join(currentDir, filename);\n if (existsSync(configPath)) {\n return configPath;\n }\n }\n currentDir = dirname(currentDir);\n }\n return null;\n}\n\n/**\n * Load config with Result type (for library use).\n */\nexport function loadConfig(configPath: string | undefined): Result<ResolvedSodaGqlConfig, ConfigError> {\n const resolvedPath = configPath ?? findConfigFile();\n\n if (!resolvedPath) {\n return err(configError({ code: \"CONFIG_NOT_FOUND\", message: \"Config file not found\" }));\n }\n\n try {\n const result = executeConfigFile(resolvedPath);\n if (result.isErr()) {\n return err(result.error);\n }\n return normalizeConfig(result.value, resolvedPath);\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error}`,\n filePath: resolvedPath,\n cause: error,\n }),\n );\n }\n}\n\n/**\n * Load config from specific directory.\n */\nexport function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configPath = findConfigFile(dir);\n return loadConfig(configPath ?? undefined);\n}\n","import { mkdirSync, rmSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Get project root from this package location.\n * packages/config/src/test-utils.ts -> project root\n */\nconst getProjectRoot = (): string => {\n return fileURLToPath(new URL(\"../../../\", import.meta.url));\n};\n\n/**\n * Create temporary config file with proper formatting.\n * Uses template literals to support functions, regex, etc.\n */\nexport async function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPath: string) => Promise<T>): Promise<T> {\n const projectRoot = getProjectRoot();\n const tmpDir = join(projectRoot, \"tests/.tmp/config-test\", `${Date.now()}`);\n mkdirSync(tmpDir, { recursive: true });\n const configPath = join(tmpDir, \"soda-gql.config.ts\");\n\n // Generate config file using template\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n\n return fn(configPath).finally(() => {\n rmSync(tmpDir, { recursive: true, force: true });\n });\n}\n\n/**\n * Simple temp config creation (without auto-cleanup).\n */\nexport function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string {\n const configPath = join(dir, \"soda-gql.config.ts\");\n\n // Write config as TypeScript module\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n return configPath;\n}\n","export type { ConfigError, ConfigErrorCode } from \"./errors\";\nexport { configError } from \"./errors\";\nexport { defineConfig, validateConfig } from \"./helper\";\nexport {\n findConfigFile,\n loadConfig,\n loadConfigFrom,\n} from \"./loader\";\nexport { normalizeConfig } from \"./normalize\";\nexport { createTempConfigFile, withTempConfig } from \"./test-utils\";\nexport type {\n PluginConfig,\n ResolvedSodaGqlConfig,\n SchemaConfig,\n SodaGqlConfig,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,eAAe,EAC1B,MACA,SACA,UACA,aAMkB;CAClB;CACA;CACA;CACA;CACD;;;;;;;;;ACbD,IAAa,yBAAb,MAAa,uBAAuB;CAClC,AAAQ,YAAY,AAAgBA,QAAuB;EAAvB;;CAEpC,OAAc,OAAO,QAA+C;AAClE,SAAO,IAAI,uBAAuB,OAAO;;;AA0C7C,SAAgB,aAAa,QAAuE;CAClG,MAAM,YAAY,eAAe,OAAO,WAAW,aAAa,QAAQ,GAAG,OAAO;AAClF,KAAI,UAAU,OAAO,EAAE;AACrB,QAAM,UAAU;;AAElB,QAAO,uBAAuB,OAAO,UAAU,MAAM;;AAGvD,MAAM,qBAAqB,iBAA+B,CAAC;CACzD,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE;CACzB,gBAAgB,EAAE,QAAQ,CAAC,IAAI,EAAE;CACjC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AAgB;CACpC,MAAM,SAAS,KAAK,aAAa,0BAA0B,GAAG,KAAK,KAAK,GAAG;AAC3E,WAAU,QAAQ,EAAE,WAAW,MAAM,CAAC;CACtC,MAAM,aAAa,KAAK,QAAQ,qBAAqB;CAGrD,MAAM,gBAAgB;;;8BAGM,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC;EAC5D,MAAM;AAEN,eAAc,YAAY,cAAc;AAExC,QAAO,GAAG,WAAW,CAAC,cAAc;AAClC,SAAO,QAAQ;GAAE,WAAW;GAAM,OAAO;GAAM,CAAC;GAChD;;;;;AAMJ,SAAgB,qBAAqB,KAAa,QAAwC;CACxF,MAAM,aAAa,KAAK,KAAK,qBAAqB;CAGlD,MAAM,gBAAgB;;;8BAGM,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC;EAC5D,MAAM;AAEN,eAAc,YAAY,cAAc;AACxC,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/config",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "Centralized configuration loader and helpers for soda-gql tooling.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"types": "./dist/index.d.mts",
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"
|
|
21
|
+
"@soda-gql": "./src/index.ts",
|
|
22
22
|
"types": "./dist/index.d.mts",
|
|
23
23
|
"import": "./dist/index.mjs",
|
|
24
24
|
"require": "./dist/index.cjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"./package.json": "./package.json"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@soda-gql/common": "0.0.
|
|
30
|
+
"@soda-gql/common": "0.0.9",
|
|
31
31
|
"@swc/core": "^1.10.0",
|
|
32
32
|
"neverthrow": "^8.2.0",
|
|
33
33
|
"zod": "^4.1.11"
|