@soda-gql/config 0.1.0 → 0.2.0
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 +26 -60
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +37 -34
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +37 -34
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +27 -60
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -3
package/dist/index.cjs
CHANGED
|
@@ -48,7 +48,6 @@ let node_module = require("node:module");
|
|
|
48
48
|
let node_path_posix = require("node:path/posix");
|
|
49
49
|
let node_vm = require("node:vm");
|
|
50
50
|
let __swc_core = require("@swc/core");
|
|
51
|
-
let node_url = require("node:url");
|
|
52
51
|
|
|
53
52
|
//#region packages/config/src/errors.ts
|
|
54
53
|
const configError = ({ code, message, filePath, cause }) => ({
|
|
@@ -80,12 +79,13 @@ function defineConfig(config) {
|
|
|
80
79
|
}
|
|
81
80
|
return SodaGqlConfigContainer.create(validated.value);
|
|
82
81
|
}
|
|
82
|
+
const InjectConfigSchema = zod.default.union([zod.default.string().min(1), zod.default.object({
|
|
83
|
+
scalars: zod.default.string().min(1),
|
|
84
|
+
adapter: zod.default.string().min(1).optional()
|
|
85
|
+
})]);
|
|
83
86
|
const SchemaConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({
|
|
84
87
|
schema: zod.default.string().min(1),
|
|
85
|
-
|
|
86
|
-
scalars: zod.default.string().min(1),
|
|
87
|
-
metadataAdapter: zod.default.string().min(1).optional(),
|
|
88
|
-
helpers: zod.default.string().min(1).optional()
|
|
88
|
+
inject: InjectConfigSchema
|
|
89
89
|
});
|
|
90
90
|
const StylesConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({ importExtension: zod.default.boolean().optional() });
|
|
91
91
|
const SodaGqlConfigSchema = (0, __soda_gql_common.defineSchemaFor)()({
|
|
@@ -170,6 +170,23 @@ function executeConfigFile(configPath) {
|
|
|
170
170
|
//#endregion
|
|
171
171
|
//#region packages/config/src/normalize.ts
|
|
172
172
|
/**
|
|
173
|
+
* Normalize inject config to resolved object form.
|
|
174
|
+
* String form is converted to object with same path for all fields.
|
|
175
|
+
*/
|
|
176
|
+
function normalizeInject(inject, configDir) {
|
|
177
|
+
if (typeof inject === "string") {
|
|
178
|
+
const resolvedPath = (0, node_path.resolve)(configDir, inject);
|
|
179
|
+
return {
|
|
180
|
+
scalars: resolvedPath,
|
|
181
|
+
adapter: resolvedPath
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
scalars: (0, node_path.resolve)(configDir, inject.scalars),
|
|
186
|
+
...inject.adapter ? { adapter: (0, node_path.resolve)(configDir, inject.adapter) } : {}
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
173
190
|
* Resolve and normalize config with defaults.
|
|
174
191
|
* Paths in the config are resolved relative to the config file's directory.
|
|
175
192
|
*/
|
|
@@ -186,10 +203,7 @@ function normalizeConfig(config, configPath) {
|
|
|
186
203
|
exclude: exclude.map((pattern) => (0, node_path.resolve)(configDir, pattern)),
|
|
187
204
|
schemas: Object.fromEntries(Object.entries(config.schemas).map(([name, schemaConfig]) => [name, {
|
|
188
205
|
schema: (0, node_path.resolve)(configDir, schemaConfig.schema),
|
|
189
|
-
|
|
190
|
-
scalars: (0, node_path.resolve)(configDir, schemaConfig.scalars),
|
|
191
|
-
...schemaConfig.metadataAdapter ? { metadataAdapter: (0, node_path.resolve)(configDir, schemaConfig.metadataAdapter) } : {},
|
|
192
|
-
...schemaConfig.helpers ? { helpers: (0, node_path.resolve)(configDir, schemaConfig.helpers) } : {}
|
|
206
|
+
inject: normalizeInject(schemaConfig.inject, configDir)
|
|
193
207
|
}])),
|
|
194
208
|
styles: { importExtension: config.styles?.importExtension ?? false },
|
|
195
209
|
plugins: config.plugins ?? {}
|
|
@@ -241,7 +255,7 @@ function loadConfig(configPath) {
|
|
|
241
255
|
} catch (error) {
|
|
242
256
|
return (0, neverthrow.err)(configError({
|
|
243
257
|
code: "CONFIG_LOAD_FAILED",
|
|
244
|
-
message: `Failed to load config: ${error}`,
|
|
258
|
+
message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,
|
|
245
259
|
filePath: resolvedPath,
|
|
246
260
|
cause: error
|
|
247
261
|
}));
|
|
@@ -255,72 +269,24 @@ function loadConfigFrom(dir) {
|
|
|
255
269
|
return loadConfig(configPath ?? undefined);
|
|
256
270
|
}
|
|
257
271
|
|
|
258
|
-
//#endregion
|
|
259
|
-
//#region packages/config/src/test-utils.ts
|
|
260
|
-
/**
|
|
261
|
-
* Get project root from this package location.
|
|
262
|
-
* packages/config/src/test-utils.ts -> project root
|
|
263
|
-
*/
|
|
264
|
-
const getProjectRoot = () => {
|
|
265
|
-
return (0, node_url.fileURLToPath)(new URL("../../../", require("url").pathToFileURL(__filename).href));
|
|
266
|
-
};
|
|
267
|
-
/**
|
|
268
|
-
* Create temporary config file with proper formatting.
|
|
269
|
-
* Uses template literals to support functions, regex, etc.
|
|
270
|
-
*/
|
|
271
|
-
async function withTempConfig(config, fn) {
|
|
272
|
-
const projectRoot = getProjectRoot();
|
|
273
|
-
const tmpDir = (0, node_path.join)(projectRoot, "tests/.tmp/config-test", `${Date.now()}`);
|
|
274
|
-
(0, node_fs.mkdirSync)(tmpDir, { recursive: true });
|
|
275
|
-
const configPath = (0, node_path.join)(tmpDir, "soda-gql.config.ts");
|
|
276
|
-
const configContent = `
|
|
277
|
-
import { defineConfig } from "@soda-gql/config";
|
|
278
|
-
|
|
279
|
-
export default defineConfig(${JSON.stringify(config, null, 2)});
|
|
280
|
-
`.trim();
|
|
281
|
-
(0, node_fs.writeFileSync)(configPath, configContent);
|
|
282
|
-
return fn(configPath).finally(() => {
|
|
283
|
-
(0, node_fs.rmSync)(tmpDir, {
|
|
284
|
-
recursive: true,
|
|
285
|
-
force: true
|
|
286
|
-
});
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Simple temp config creation (without auto-cleanup).
|
|
291
|
-
*/
|
|
292
|
-
function createTempConfigFile(dir, config) {
|
|
293
|
-
const configPath = (0, node_path.join)(dir, "soda-gql.config.ts");
|
|
294
|
-
const configContent = `
|
|
295
|
-
import { defineConfig } from "@soda-gql/config";
|
|
296
|
-
|
|
297
|
-
export default defineConfig(${JSON.stringify(config, null, 2)});
|
|
298
|
-
`.trim();
|
|
299
|
-
(0, node_fs.writeFileSync)(configPath, configContent);
|
|
300
|
-
return configPath;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
272
|
//#endregion
|
|
304
273
|
//#region packages/config/src/index.ts
|
|
305
274
|
var src_exports = /* @__PURE__ */ __export({
|
|
306
275
|
configError: () => configError,
|
|
307
|
-
createTempConfigFile: () => createTempConfigFile,
|
|
308
276
|
defineConfig: () => defineConfig,
|
|
309
277
|
findConfigFile: () => findConfigFile,
|
|
310
278
|
loadConfig: () => loadConfig,
|
|
311
279
|
loadConfigFrom: () => loadConfigFrom,
|
|
312
280
|
normalizeConfig: () => normalizeConfig,
|
|
313
|
-
validateConfig: () => validateConfig
|
|
314
|
-
withTempConfig: () => withTempConfig
|
|
281
|
+
validateConfig: () => validateConfig
|
|
315
282
|
});
|
|
316
283
|
|
|
317
284
|
//#endregion
|
|
318
285
|
exports.configError = configError;
|
|
319
|
-
exports.createTempConfigFile = createTempConfigFile;
|
|
320
286
|
exports.defineConfig = defineConfig;
|
|
321
287
|
exports.findConfigFile = findConfigFile;
|
|
322
288
|
exports.loadConfig = loadConfig;
|
|
323
289
|
exports.loadConfigFrom = loadConfigFrom;
|
|
324
290
|
exports.normalizeConfig = normalizeConfig;
|
|
325
291
|
exports.validateConfig = validateConfig;
|
|
326
|
-
|
|
292
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["config: SodaGqlConfig","InjectConfigSchema: z.ZodType<InjectConfig>","z","mod: { exports: unknown }","require","configModule","Script","resolved: ResolvedSodaGqlConfig"],"sources":["../src/errors.ts","../src/helper.ts","../src/evaluation.ts","../src/normalize.ts","../src/loader.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 { InjectConfig, 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 with object inject\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 * inject: { scalars: \"./scalars.ts\" },\n * },\n * },\n * });\n * ```\n *\n * @example Static config with string inject (single file)\n * ```ts\n * export default defineConfig({\n * outdir: \"./graphql-system\",\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * inject: \"./inject.ts\", // exports scalar, adapter?\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\n// InjectConfig is a union type (string | object), so we define the schema directly\n// rather than using defineSchemaFor which requires object types\nconst InjectConfigSchema: z.ZodType<InjectConfig> = z.union([\n z.string().min(1),\n z.object({\n scalars: z.string().min(1),\n adapter: z.string().min(1).optional(),\n }),\n]);\n\nconst SchemaConfigSchema = defineSchemaFor<SchemaConfig>()({\n schema: z.string().min(1),\n inject: InjectConfigSchema,\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 { InjectConfig, ResolvedInjectConfig, ResolvedSodaGqlConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Normalize inject config to resolved object form.\n * String form is converted to object with same path for all fields.\n */\nfunction normalizeInject(inject: InjectConfig, configDir: string): ResolvedInjectConfig {\n if (typeof inject === \"string\") {\n const resolvedPath = resolve(configDir, inject);\n return {\n scalars: resolvedPath,\n adapter: resolvedPath,\n };\n }\n return {\n scalars: resolve(configDir, inject.scalars),\n ...(inject.adapter ? { adapter: resolve(configDir, inject.adapter) } : {}),\n };\n}\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 inject: normalizeInject(schemaConfig.inject, configDir),\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 instanceof Error ? error.message : String(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","export type { ConfigError, ConfigErrorCode } from \"./errors\";\nexport { configError } from \"./errors\";\nexport {\n defineConfig,\n type SodaGqlConfigContainer,\n validateConfig,\n} from \"./helper\";\nexport { findConfigFile, loadConfig, loadConfigFrom } from \"./loader\";\nexport { normalizeConfig } from \"./normalize\";\nexport type {\n PluginConfig,\n ResolvedSodaGqlConfig,\n SchemaConfig,\n SodaGqlConfig,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAuB,WAAW,EAAE;AACzC,OAAK,MAAM,YAAY,0BAA0B;GAC/C,MAAM,iCAAkB,YAAY,SAAS;AAC7C,+BAAe,WAAW,EAAE;AAC1B,WAAO;;;AAGX,sCAAqB,WAAW;;AAElC,QAAO;;;;;AAMT,SAAgB,WAAW,YAA4E;CACrG,MAAM,eAAe,cAAc,gBAAgB;AAEnD,KAAI,CAAC,cAAc;AACjB,6BAAW,YAAY;GAAE,MAAM;GAAoB,SAAS;GAAyB,CAAC,CAAC;;AAGzF,KAAI;EACF,MAAM,SAAS,kBAAkB,aAAa;AAC9C,MAAI,OAAO,OAAO,EAAE;AAClB,8BAAW,OAAO,MAAM;;AAE1B,SAAO,gBAAgB,OAAO,OAAO,aAAa;UAC3C,OAAO;AACd,6BACE,YAAY;GACV,MAAM;GACN,SAAS,0BAA0B,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM;GACzF,UAAU;GACV,OAAO;GACR,CAAC,CACH;;;;;;AAOL,SAAgB,eAAe,KAAyD;CACtF,MAAM,aAAa,eAAe,IAAI;AACtC,QAAO,WAAW,cAAc,UAAU"}
|
package/dist/index.d.cts
CHANGED
|
@@ -21,22 +21,30 @@ declare const configError: ({
|
|
|
21
21
|
}) => ConfigError;
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region packages/config/src/types.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* Injection configuration for a schema.
|
|
26
|
+
* Can be a string (single file) or an object with separate paths.
|
|
27
|
+
*
|
|
28
|
+
* When a string is provided, it should be a path to a file that exports:
|
|
29
|
+
* - `scalar` (required): Scalar type definitions
|
|
30
|
+
* - `adapter` (optional): Unified adapter with helpers and metadata
|
|
31
|
+
*
|
|
32
|
+
* When an object is provided, each property is a path to a separate file.
|
|
33
|
+
*/
|
|
34
|
+
type InjectConfig = string | {
|
|
35
|
+
readonly scalars: string;
|
|
36
|
+
readonly adapter?: string;
|
|
37
|
+
};
|
|
24
38
|
type SchemaConfig = {
|
|
25
39
|
readonly schema: string;
|
|
26
|
-
readonly runtimeAdapter: string;
|
|
27
|
-
readonly scalars: string;
|
|
28
|
-
/**
|
|
29
|
-
* Optional path to the metadata adapter module.
|
|
30
|
-
* The module should export a `metadataAdapter` created with `createMetadataAdapter()`.
|
|
31
|
-
* Used for setting HTTP headers, GraphQL extensions, and other operation metadata.
|
|
32
|
-
*/
|
|
33
|
-
readonly metadataAdapter?: string;
|
|
34
40
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
41
|
+
* Injection configuration for scalars and adapter.
|
|
42
|
+
* Can be a single file path or an object with separate paths.
|
|
43
|
+
*
|
|
44
|
+
* @example Single file: "./inject.ts" (exports scalar, adapter?)
|
|
45
|
+
* @example Object: { scalars: "./scalars.ts", adapter: "./adapter.ts" }
|
|
38
46
|
*/
|
|
39
|
-
readonly
|
|
47
|
+
readonly inject: InjectConfig;
|
|
40
48
|
};
|
|
41
49
|
type StylesConfig = {
|
|
42
50
|
/**
|
|
@@ -98,13 +106,21 @@ type SodaGqlConfig = {
|
|
|
98
106
|
*/
|
|
99
107
|
readonly plugins?: PluginConfig;
|
|
100
108
|
};
|
|
109
|
+
type ResolvedInjectConfig = {
|
|
110
|
+
readonly scalars: string;
|
|
111
|
+
readonly adapter?: string;
|
|
112
|
+
};
|
|
113
|
+
type ResolvedSchemaConfig = {
|
|
114
|
+
readonly schema: string;
|
|
115
|
+
readonly inject: ResolvedInjectConfig;
|
|
116
|
+
};
|
|
101
117
|
type ResolvedSodaGqlConfig = {
|
|
102
118
|
readonly analyzer: "ts" | "swc";
|
|
103
119
|
readonly outdir: string;
|
|
104
120
|
readonly graphqlSystemAliases: readonly string[];
|
|
105
121
|
readonly include: readonly string[];
|
|
106
122
|
readonly exclude: readonly string[];
|
|
107
|
-
readonly schemas: Readonly<Record<string,
|
|
123
|
+
readonly schemas: Readonly<Record<string, ResolvedSchemaConfig>>;
|
|
108
124
|
readonly styles: ResolvedStylesConfig;
|
|
109
125
|
readonly plugins: PluginConfig;
|
|
110
126
|
};
|
|
@@ -124,7 +140,7 @@ declare class SodaGqlConfigContainer {
|
|
|
124
140
|
* Type-safe helper for defining soda-gql configuration.
|
|
125
141
|
* Supports both static and dynamic (async) configs.
|
|
126
142
|
*
|
|
127
|
-
* @example Static config
|
|
143
|
+
* @example Static config with object inject
|
|
128
144
|
* ```ts
|
|
129
145
|
* import { defineConfig } from "@soda-gql/config";
|
|
130
146
|
*
|
|
@@ -134,26 +150,24 @@ declare class SodaGqlConfigContainer {
|
|
|
134
150
|
* schemas: {
|
|
135
151
|
* default: {
|
|
136
152
|
* schema: "./schema.graphql",
|
|
137
|
-
*
|
|
138
|
-
* scalars: "./scalars.ts",
|
|
153
|
+
* inject: { scalars: "./scalars.ts" },
|
|
139
154
|
* },
|
|
140
155
|
* },
|
|
141
156
|
* });
|
|
142
157
|
* ```
|
|
143
158
|
*
|
|
144
|
-
* @example
|
|
159
|
+
* @example Static config with string inject (single file)
|
|
145
160
|
* ```ts
|
|
146
|
-
* export default defineConfig(
|
|
147
|
-
* outdir:
|
|
161
|
+
* export default defineConfig({
|
|
162
|
+
* outdir: "./graphql-system",
|
|
148
163
|
* include: ["./src/**\/*.ts"],
|
|
149
164
|
* schemas: {
|
|
150
165
|
* default: {
|
|
151
166
|
* schema: "./schema.graphql",
|
|
152
|
-
*
|
|
153
|
-
* scalars: "./scalars.ts",
|
|
167
|
+
* inject: "./inject.ts", // exports scalar, adapter?
|
|
154
168
|
* },
|
|
155
169
|
* },
|
|
156
|
-
* })
|
|
170
|
+
* });
|
|
157
171
|
* ```
|
|
158
172
|
*/
|
|
159
173
|
declare function defineConfig(config: SodaGqlConfig): SodaGqlConfigContainer;
|
|
@@ -182,16 +196,5 @@ declare function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, Conf
|
|
|
182
196
|
*/
|
|
183
197
|
declare function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError>;
|
|
184
198
|
//#endregion
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Create temporary config file with proper formatting.
|
|
188
|
-
* Uses template literals to support functions, regex, etc.
|
|
189
|
-
*/
|
|
190
|
-
declare function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPath: string) => Promise<T>): Promise<T>;
|
|
191
|
-
/**
|
|
192
|
-
* Simple temp config creation (without auto-cleanup).
|
|
193
|
-
*/
|
|
194
|
-
declare function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string;
|
|
195
|
-
//#endregion
|
|
196
|
-
export { type ConfigError, type ConfigErrorCode, type PluginConfig, type ResolvedSodaGqlConfig, type SchemaConfig, type SodaGqlConfig, type SodaGqlConfigContainer, configError, createTempConfigFile, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig, withTempConfig };
|
|
199
|
+
export { type ConfigError, type ConfigErrorCode, type PluginConfig, type ResolvedSodaGqlConfig, type SchemaConfig, type SodaGqlConfig, type SodaGqlConfigContainer, configError, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig };
|
|
197
200
|
//# sourceMappingURL=index.d.cts.map
|
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"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.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,OAA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AA,EEL2C,sBFK3C;;;;;ACTJ;AAQA;AAaA;AAWA;AAKA;AAGA;;;;;;;AAiDA;AAMA;AAMA;;;;;;;;;;ACpGA;;;;;AA0CA;AACA;AAuCgB,iBAxCA,YAAA,CAwCc,MAAA,EAxCO,aAwCP,CAAA,EAxCuB,sBAwCvB;AAA0B,iBAvCxC,YAAA,CAuCwC,MAAA,EAAA,GAAA,GAvCb,aAuCa,CAAA,EAvCG,sBAuCH;AAAe,iBAAvD,cAAA,CAAuD,MAAA,EAAA,OAAA,CAAA,EAAtB,MAAsB,CAAf,aAAe,EAAA,WAAA,CAAA;;;AF7F3D,cGUC,wBHVc,EAAA,SAAA,CAAA,oBAAA,EAAA,qBAAA,EAAA,oBAAA,EAAA,qBAAA,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,iBImBZ,eAAA,CJnBY,MAAA,EImBY,aJnBZ,EAAA,UAAA,EAAA,MAAA,CAAA,EImBgD,MJnBhD,CImBuD,qBJnBvD,EImB8E,WJnB9E,CAAA"}
|
package/dist/index.d.mts
CHANGED
|
@@ -21,22 +21,30 @@ declare const configError: ({
|
|
|
21
21
|
}) => ConfigError;
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region packages/config/src/types.d.ts
|
|
24
|
+
/**
|
|
25
|
+
* Injection configuration for a schema.
|
|
26
|
+
* Can be a string (single file) or an object with separate paths.
|
|
27
|
+
*
|
|
28
|
+
* When a string is provided, it should be a path to a file that exports:
|
|
29
|
+
* - `scalar` (required): Scalar type definitions
|
|
30
|
+
* - `adapter` (optional): Unified adapter with helpers and metadata
|
|
31
|
+
*
|
|
32
|
+
* When an object is provided, each property is a path to a separate file.
|
|
33
|
+
*/
|
|
34
|
+
type InjectConfig = string | {
|
|
35
|
+
readonly scalars: string;
|
|
36
|
+
readonly adapter?: string;
|
|
37
|
+
};
|
|
24
38
|
type SchemaConfig = {
|
|
25
39
|
readonly schema: string;
|
|
26
|
-
readonly runtimeAdapter: string;
|
|
27
|
-
readonly scalars: string;
|
|
28
|
-
/**
|
|
29
|
-
* Optional path to the metadata adapter module.
|
|
30
|
-
* The module should export a `metadataAdapter` created with `createMetadataAdapter()`.
|
|
31
|
-
* Used for setting HTTP headers, GraphQL extensions, and other operation metadata.
|
|
32
|
-
*/
|
|
33
|
-
readonly metadataAdapter?: string;
|
|
34
40
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
41
|
+
* Injection configuration for scalars and adapter.
|
|
42
|
+
* Can be a single file path or an object with separate paths.
|
|
43
|
+
*
|
|
44
|
+
* @example Single file: "./inject.ts" (exports scalar, adapter?)
|
|
45
|
+
* @example Object: { scalars: "./scalars.ts", adapter: "./adapter.ts" }
|
|
38
46
|
*/
|
|
39
|
-
readonly
|
|
47
|
+
readonly inject: InjectConfig;
|
|
40
48
|
};
|
|
41
49
|
type StylesConfig = {
|
|
42
50
|
/**
|
|
@@ -98,13 +106,21 @@ type SodaGqlConfig = {
|
|
|
98
106
|
*/
|
|
99
107
|
readonly plugins?: PluginConfig;
|
|
100
108
|
};
|
|
109
|
+
type ResolvedInjectConfig = {
|
|
110
|
+
readonly scalars: string;
|
|
111
|
+
readonly adapter?: string;
|
|
112
|
+
};
|
|
113
|
+
type ResolvedSchemaConfig = {
|
|
114
|
+
readonly schema: string;
|
|
115
|
+
readonly inject: ResolvedInjectConfig;
|
|
116
|
+
};
|
|
101
117
|
type ResolvedSodaGqlConfig = {
|
|
102
118
|
readonly analyzer: "ts" | "swc";
|
|
103
119
|
readonly outdir: string;
|
|
104
120
|
readonly graphqlSystemAliases: readonly string[];
|
|
105
121
|
readonly include: readonly string[];
|
|
106
122
|
readonly exclude: readonly string[];
|
|
107
|
-
readonly schemas: Readonly<Record<string,
|
|
123
|
+
readonly schemas: Readonly<Record<string, ResolvedSchemaConfig>>;
|
|
108
124
|
readonly styles: ResolvedStylesConfig;
|
|
109
125
|
readonly plugins: PluginConfig;
|
|
110
126
|
};
|
|
@@ -124,7 +140,7 @@ declare class SodaGqlConfigContainer {
|
|
|
124
140
|
* Type-safe helper for defining soda-gql configuration.
|
|
125
141
|
* Supports both static and dynamic (async) configs.
|
|
126
142
|
*
|
|
127
|
-
* @example Static config
|
|
143
|
+
* @example Static config with object inject
|
|
128
144
|
* ```ts
|
|
129
145
|
* import { defineConfig } from "@soda-gql/config";
|
|
130
146
|
*
|
|
@@ -134,26 +150,24 @@ declare class SodaGqlConfigContainer {
|
|
|
134
150
|
* schemas: {
|
|
135
151
|
* default: {
|
|
136
152
|
* schema: "./schema.graphql",
|
|
137
|
-
*
|
|
138
|
-
* scalars: "./scalars.ts",
|
|
153
|
+
* inject: { scalars: "./scalars.ts" },
|
|
139
154
|
* },
|
|
140
155
|
* },
|
|
141
156
|
* });
|
|
142
157
|
* ```
|
|
143
158
|
*
|
|
144
|
-
* @example
|
|
159
|
+
* @example Static config with string inject (single file)
|
|
145
160
|
* ```ts
|
|
146
|
-
* export default defineConfig(
|
|
147
|
-
* outdir:
|
|
161
|
+
* export default defineConfig({
|
|
162
|
+
* outdir: "./graphql-system",
|
|
148
163
|
* include: ["./src/**\/*.ts"],
|
|
149
164
|
* schemas: {
|
|
150
165
|
* default: {
|
|
151
166
|
* schema: "./schema.graphql",
|
|
152
|
-
*
|
|
153
|
-
* scalars: "./scalars.ts",
|
|
167
|
+
* inject: "./inject.ts", // exports scalar, adapter?
|
|
154
168
|
* },
|
|
155
169
|
* },
|
|
156
|
-
* })
|
|
170
|
+
* });
|
|
157
171
|
* ```
|
|
158
172
|
*/
|
|
159
173
|
declare function defineConfig(config: SodaGqlConfig): SodaGqlConfigContainer;
|
|
@@ -182,16 +196,5 @@ declare function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, Conf
|
|
|
182
196
|
*/
|
|
183
197
|
declare function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError>;
|
|
184
198
|
//#endregion
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Create temporary config file with proper formatting.
|
|
188
|
-
* Uses template literals to support functions, regex, etc.
|
|
189
|
-
*/
|
|
190
|
-
declare function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPath: string) => Promise<T>): Promise<T>;
|
|
191
|
-
/**
|
|
192
|
-
* Simple temp config creation (without auto-cleanup).
|
|
193
|
-
*/
|
|
194
|
-
declare function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string;
|
|
195
|
-
//#endregion
|
|
196
|
-
export { type ConfigError, type ConfigErrorCode, type PluginConfig, type ResolvedSodaGqlConfig, type SchemaConfig, type SodaGqlConfig, type SodaGqlConfigContainer, configError, createTempConfigFile, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig, withTempConfig };
|
|
199
|
+
export { type ConfigError, type ConfigErrorCode, type PluginConfig, type ResolvedSodaGqlConfig, type SchemaConfig, type SodaGqlConfig, type SodaGqlConfigContainer, configError, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig };
|
|
197
200
|
//# sourceMappingURL=index.d.mts.map
|
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"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EA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|
|
3
3
|
import { err, ok } from "neverthrow";
|
|
4
4
|
import z from "zod";
|
|
5
|
-
import { existsSync,
|
|
5
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join, resolve } from "node:path";
|
|
7
7
|
import { dirname as dirname$1, resolve as resolve$1 } from "node:path/posix";
|
|
8
8
|
import { Script } from "node:vm";
|
|
9
9
|
import { transformSync } from "@swc/core";
|
|
10
|
-
import { fileURLToPath } from "node:url";
|
|
11
10
|
|
|
12
11
|
//#region rolldown:runtime
|
|
13
12
|
var __defProp = Object.defineProperty;
|
|
@@ -56,12 +55,13 @@ function defineConfig(config) {
|
|
|
56
55
|
}
|
|
57
56
|
return SodaGqlConfigContainer.create(validated.value);
|
|
58
57
|
}
|
|
58
|
+
const InjectConfigSchema = z.union([z.string().min(1), z.object({
|
|
59
|
+
scalars: z.string().min(1),
|
|
60
|
+
adapter: z.string().min(1).optional()
|
|
61
|
+
})]);
|
|
59
62
|
const SchemaConfigSchema = defineSchemaFor()({
|
|
60
63
|
schema: z.string().min(1),
|
|
61
|
-
|
|
62
|
-
scalars: z.string().min(1),
|
|
63
|
-
metadataAdapter: z.string().min(1).optional(),
|
|
64
|
-
helpers: z.string().min(1).optional()
|
|
64
|
+
inject: InjectConfigSchema
|
|
65
65
|
});
|
|
66
66
|
const StylesConfigSchema = defineSchemaFor()({ importExtension: z.boolean().optional() });
|
|
67
67
|
const SodaGqlConfigSchema = defineSchemaFor()({
|
|
@@ -146,6 +146,23 @@ function executeConfigFile(configPath) {
|
|
|
146
146
|
//#endregion
|
|
147
147
|
//#region packages/config/src/normalize.ts
|
|
148
148
|
/**
|
|
149
|
+
* Normalize inject config to resolved object form.
|
|
150
|
+
* String form is converted to object with same path for all fields.
|
|
151
|
+
*/
|
|
152
|
+
function normalizeInject(inject, configDir) {
|
|
153
|
+
if (typeof inject === "string") {
|
|
154
|
+
const resolvedPath = resolve(configDir, inject);
|
|
155
|
+
return {
|
|
156
|
+
scalars: resolvedPath,
|
|
157
|
+
adapter: resolvedPath
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
scalars: resolve(configDir, inject.scalars),
|
|
162
|
+
...inject.adapter ? { adapter: resolve(configDir, inject.adapter) } : {}
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
149
166
|
* Resolve and normalize config with defaults.
|
|
150
167
|
* Paths in the config are resolved relative to the config file's directory.
|
|
151
168
|
*/
|
|
@@ -162,10 +179,7 @@ function normalizeConfig(config, configPath) {
|
|
|
162
179
|
exclude: exclude.map((pattern) => resolve(configDir, pattern)),
|
|
163
180
|
schemas: Object.fromEntries(Object.entries(config.schemas).map(([name, schemaConfig]) => [name, {
|
|
164
181
|
schema: resolve(configDir, schemaConfig.schema),
|
|
165
|
-
|
|
166
|
-
scalars: resolve(configDir, schemaConfig.scalars),
|
|
167
|
-
...schemaConfig.metadataAdapter ? { metadataAdapter: resolve(configDir, schemaConfig.metadataAdapter) } : {},
|
|
168
|
-
...schemaConfig.helpers ? { helpers: resolve(configDir, schemaConfig.helpers) } : {}
|
|
182
|
+
inject: normalizeInject(schemaConfig.inject, configDir)
|
|
169
183
|
}])),
|
|
170
184
|
styles: { importExtension: config.styles?.importExtension ?? false },
|
|
171
185
|
plugins: config.plugins ?? {}
|
|
@@ -217,7 +231,7 @@ function loadConfig(configPath) {
|
|
|
217
231
|
} catch (error) {
|
|
218
232
|
return err(configError({
|
|
219
233
|
code: "CONFIG_LOAD_FAILED",
|
|
220
|
-
message: `Failed to load config: ${error}`,
|
|
234
|
+
message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,
|
|
221
235
|
filePath: resolvedPath,
|
|
222
236
|
cause: error
|
|
223
237
|
}));
|
|
@@ -231,65 +245,18 @@ function loadConfigFrom(dir) {
|
|
|
231
245
|
return loadConfig(configPath ?? undefined);
|
|
232
246
|
}
|
|
233
247
|
|
|
234
|
-
//#endregion
|
|
235
|
-
//#region packages/config/src/test-utils.ts
|
|
236
|
-
/**
|
|
237
|
-
* Get project root from this package location.
|
|
238
|
-
* packages/config/src/test-utils.ts -> project root
|
|
239
|
-
*/
|
|
240
|
-
const getProjectRoot = () => {
|
|
241
|
-
return fileURLToPath(new URL("../../../", import.meta.url));
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* Create temporary config file with proper formatting.
|
|
245
|
-
* Uses template literals to support functions, regex, etc.
|
|
246
|
-
*/
|
|
247
|
-
async function withTempConfig(config, fn) {
|
|
248
|
-
const projectRoot = getProjectRoot();
|
|
249
|
-
const tmpDir = join(projectRoot, "tests/.tmp/config-test", `${Date.now()}`);
|
|
250
|
-
mkdirSync(tmpDir, { recursive: true });
|
|
251
|
-
const configPath = join(tmpDir, "soda-gql.config.ts");
|
|
252
|
-
const configContent = `
|
|
253
|
-
import { defineConfig } from "@soda-gql/config";
|
|
254
|
-
|
|
255
|
-
export default defineConfig(${JSON.stringify(config, null, 2)});
|
|
256
|
-
`.trim();
|
|
257
|
-
writeFileSync(configPath, configContent);
|
|
258
|
-
return fn(configPath).finally(() => {
|
|
259
|
-
rmSync(tmpDir, {
|
|
260
|
-
recursive: true,
|
|
261
|
-
force: true
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Simple temp config creation (without auto-cleanup).
|
|
267
|
-
*/
|
|
268
|
-
function createTempConfigFile(dir, config) {
|
|
269
|
-
const configPath = join(dir, "soda-gql.config.ts");
|
|
270
|
-
const configContent = `
|
|
271
|
-
import { defineConfig } from "@soda-gql/config";
|
|
272
|
-
|
|
273
|
-
export default defineConfig(${JSON.stringify(config, null, 2)});
|
|
274
|
-
`.trim();
|
|
275
|
-
writeFileSync(configPath, configContent);
|
|
276
|
-
return configPath;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
248
|
//#endregion
|
|
280
249
|
//#region packages/config/src/index.ts
|
|
281
250
|
var src_exports = /* @__PURE__ */ __export({
|
|
282
251
|
configError: () => configError,
|
|
283
|
-
createTempConfigFile: () => createTempConfigFile,
|
|
284
252
|
defineConfig: () => defineConfig,
|
|
285
253
|
findConfigFile: () => findConfigFile,
|
|
286
254
|
loadConfig: () => loadConfig,
|
|
287
255
|
loadConfigFrom: () => loadConfigFrom,
|
|
288
256
|
normalizeConfig: () => normalizeConfig,
|
|
289
|
-
validateConfig: () => validateConfig
|
|
290
|
-
withTempConfig: () => withTempConfig
|
|
257
|
+
validateConfig: () => validateConfig
|
|
291
258
|
});
|
|
292
259
|
|
|
293
260
|
//#endregion
|
|
294
|
-
export { configError,
|
|
261
|
+
export { configError, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig };
|
|
295
262
|
//# sourceMappingURL=index.mjs.map
|
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, 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 metadataAdapter: z.string().min(1).optional(),\n helpers: z.string().min(1).optional(),\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 ...(schemaConfig.metadataAdapter ? { metadataAdapter: resolve(configDir, schemaConfig.metadataAdapter) } : {}),\n ...(schemaConfig.helpers ? { helpers: resolve(configDir, schemaConfig.helpers) } : {}),\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 {\n defineConfig,\n type SodaGqlConfigContainer,\n validateConfig,\n} from \"./helper\";\nexport { findConfigFile, loadConfig, loadConfigFrom } from \"./loader\";\nexport { normalizeConfig } from \"./normalize\";\nexport { createTempConfigFile, withTempConfig } from \"./test-utils\";\nexport type {\n PluginConfig,\n ResolvedSodaGqlConfig,\n SchemaConf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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"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["config: SodaGqlConfig","InjectConfigSchema: z.ZodType<InjectConfig>","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/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 { InjectConfig, 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 with object inject\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 * inject: { scalars: \"./scalars.ts\" },\n * },\n * },\n * });\n * ```\n *\n * @example Static config with string inject (single file)\n * ```ts\n * export default defineConfig({\n * outdir: \"./graphql-system\",\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * inject: \"./inject.ts\", // exports scalar, adapter?\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\n// InjectConfig is a union type (string | object), so we define the schema directly\n// rather than using defineSchemaFor which requires object types\nconst InjectConfigSchema: z.ZodType<InjectConfig> = z.union([\n z.string().min(1),\n z.object({\n scalars: z.string().min(1),\n adapter: z.string().min(1).optional(),\n }),\n]);\n\nconst SchemaConfigSchema = defineSchemaFor<SchemaConfig>()({\n schema: z.string().min(1),\n inject: InjectConfigSchema,\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 { InjectConfig, ResolvedInjectConfig, ResolvedSodaGqlConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Normalize inject config to resolved object form.\n * String form is converted to object with same path for all fields.\n */\nfunction normalizeInject(inject: InjectConfig, configDir: string): ResolvedInjectConfig {\n if (typeof inject === \"string\") {\n const resolvedPath = resolve(configDir, inject);\n return {\n scalars: resolvedPath,\n adapter: resolvedPath,\n };\n }\n return {\n scalars: resolve(configDir, inject.scalars),\n ...(inject.adapter ? { adapter: resolve(configDir, inject.adapter) } : {}),\n };\n}\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 inject: normalizeInject(schemaConfig.inject, configDir),\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 instanceof Error ? error.message : String(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","export type { ConfigError, ConfigErrorCode } from \"./errors\";\nexport { configError } from \"./errors\";\nexport {\n defineConfig,\n type SodaGqlConfigContainer,\n validateConfig,\n} from \"./helper\";\nexport { findConfigFile, loadConfig, loadConfigFrom } from \"./loader\";\nexport { normalizeConfig } from \"./normalize\";\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;;;AAwC7C,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;;AAKvD,MAAMC,qBAA8C,EAAE,MAAM,CAC1D,EAAE,QAAQ,CAAC,IAAI,EAAE,EACjB,EAAE,OAAO;CACP,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE;CAC1B,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,UAAU;CACtC,CAAC,CACH,CAAC;AAEF,MAAM,qBAAqB,iBAA+B,CAAC;CACzD,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE;CACzB,QAAQ;CACT,CAAC;AAEF,MAAM,qBAAqB,iBAA+B,CAAC,EACzD,iBAAiB,EAAE,SAAS,CAAC,UAAU,EACxC,CAAC;AAEF,MAAM,sBAAsB,iBAAgC,CAAC;CAC3D,UAAU,EAAE,KAAK,CAAC,MAAM,MAAM,CAAC,CAAC,UAAU;CAC1C,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE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"description": "Centralized configuration loader and helpers for soda-gql tooling.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -13,12 +13,34 @@
|
|
|
13
13
|
"email": "shota.hatada@whatasoda.me",
|
|
14
14
|
"url": "https://github.com/whatasoda"
|
|
15
15
|
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"graphql",
|
|
18
|
+
"codegen",
|
|
19
|
+
"zero-runtime",
|
|
20
|
+
"typescript",
|
|
21
|
+
"config"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/whatasoda/soda-gql.git",
|
|
26
|
+
"directory": "packages/config"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/whatasoda/soda-gql#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/whatasoda/soda-gql/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
16
35
|
"main": "./dist/index.mjs",
|
|
17
36
|
"module": "./dist/index.mjs",
|
|
18
37
|
"types": "./dist/index.d.mts",
|
|
19
38
|
"exports": {
|
|
39
|
+
"./test": {
|
|
40
|
+
"@soda-gql": "./@devx-test.ts"
|
|
41
|
+
},
|
|
20
42
|
".": {
|
|
21
|
-
"@soda-gql": "
|
|
43
|
+
"@soda-gql": "./@x-index.ts",
|
|
22
44
|
"types": "./dist/index.d.mts",
|
|
23
45
|
"import": "./dist/index.mjs",
|
|
24
46
|
"require": "./dist/index.cjs",
|
|
@@ -27,7 +49,7 @@
|
|
|
27
49
|
"./package.json": "./package.json"
|
|
28
50
|
},
|
|
29
51
|
"dependencies": {
|
|
30
|
-
"@soda-gql/common": "0.
|
|
52
|
+
"@soda-gql/common": "0.2.0",
|
|
31
53
|
"@swc/core": "^1.10.0",
|
|
32
54
|
"neverthrow": "^8.2.0",
|
|
33
55
|
"zod": "^4.1.11"
|