@wtf/project-config 2.0.0 → 3.0.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/load.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";;;;;;;;AA4BA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAA;AACrE,OAAO,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC3E,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,SAAS,EAET,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAA;AAUnB,OAAO,EACL,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAEjB,MAAM,aAAa,CAAA;AAqDpB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAC3B,CAAC,IAA+C,EAAgB,EAAE,CAClE,KAAK,EAAE,IAAI,EAAE,EAAE,CACb,MAAM,kCAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,EAAC,CAAA;AAErC,oGAAoG;AACpG,KAAK,UAAU,cAAc,CAC3B,MAAoB,EACpB,YAA0B;IAE1B,IAAI,MAAe,CAAA;IACnB,IAAI,CAAC;QACH,MAAM,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,sBAAsB,CAC9B,MAAM,CAAC,IAAI,EACX,mBAAmB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC3E,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAA;IACH,CAAC;IACD,MAAM,QAAQ,GAAY,QAAQ,CAAC,MAAM,CAAC,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CAAA;IACxF,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,MAAM;QAChC,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;IACpF,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;IAClE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAAA;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,SAAS,EACT,GAAG,EACH,MAAM,EACN,OAAO,EAC0D;IACjE,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CACrC,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAClE,CAAA;IACD,OAAO,OAAO,SAAS,+BAA+B,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,gCAAgC,CAAA;AAChK,CAAC","sourcesContent":["/**\n * A project's configuration, as a tool reads it: {@link loadConfig}, the object of the first file\n * of it found at the root of the project, of code or of JSON, the file it came from, and the\n * others found, which are ignored; {@link loadConfigSync}, the same of a JSON file or package.json\n * alone, for a tool that reads its config synchronously; {@link ignoredWarning}, what to say of\n * the files ignored; and {@link importFileModule}, which imports a configuration of code, as\n * `wtf.config.ts`, by its file URL, as Node imports a module.\n *\n * Each reads by the platform it is given, and nothing of the process: its files, its paths, the\n * folder it works in, which the project is looked for from, and its environment, whose variables\n * are over the configuration. The entry point builds it, as `nodePlatform()` of\n * `@wtf/platform-node/platform` makes Node's:\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfig } from '@wtf/project-config/load'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const resolved = await loadConfig({ platform })\n * ```\n *\n * @packageDocumentation\n */\nimport type { Platform } from '@wtf/platform'\nimport type { Dirs } from '@wtf/platform/dirs'\n\nimport { envPrefixOf, variablesOf, type Environment } from './env.ts'\nimport { InvalidConfigFileError, SyncConfigInCodeError } from './errors.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestOf,\n readAsync,\n type Reads,\n readSync,\n textOf\n} from './files.ts'\nimport type {\n ConfigDefaults,\n ConfigPlatform,\n ConfigSource,\n ConfigSyncPlatform,\n ImportModule,\n NamespaceConfig,\n ResolvedConfig\n} from './index.ts'\nimport {\n configNamesOf,\n jsonFilesOf,\n locateConfig,\n locateConfigSync,\n type LocateNames\n} from './locate.ts'\n\n/** How a configuration is read, apart from the platform: the folder of the project, its names, and\n * the defaults of the tool's package. */\nexport type LoadLayers = LocateNames & {\n /**\n * The folder of the project, which its root is looked for from: the working folder of the\n * platform, `dirs.cwd`, by default.\n */\n readonly folder?: string\n /**\n * The configuration under the project's, as the tool's package gives it: a section the project\n * gives none of is the one of the defaults, and one it gives is merged over it (`sectionOf` of\n * ./section).\n */\n readonly defaults?: ConfigDefaults\n}\n\n/**\n * What a configuration is read by asynchronously: the platform's files, its paths and its working\n * folder ({@link ConfigPlatform}), and its environment, `env`, of which the variables of the prefix\n * of the names, as `WTF_`, are kept, and a section is read with them over it, and its placeholders\n * `${env:NAME}` taken from the whole (`sectionOf` of ./section). A `Platform` of `@wtf/platform` is\n * one.\n */\nexport type LoadPlatform = ConfigPlatform & Pick<Platform, 'env'>\n\n/**\n * What a configuration is read by synchronously: the platform's paths and its files, read\n * synchronously ({@link ConfigSyncPlatform}), its working folder, and its environment, as\n * {@link LoadPlatform} has them. `nodeSyncPlatform()` of ./node adds Node's files to a platform.\n */\nexport type LoadSyncPlatform = ConfigSyncPlatform &\n Pick<Platform, 'env'> & { readonly dirs: Pick<Dirs, 'cwd'> }\n\n/** How a configuration is read asynchronously. */\nexport type LoadOptions = LoadLayers & {\n /** The platform it is read by ({@link LoadPlatform}). */\n readonly platform: LoadPlatform\n /**\n * What imports a file of code: by default `import()` of its file URL, as the platform's paths\n * give it ({@link importFileModule}). A caller of a file system of its own, not the one its\n * runtime imports from, gives one too.\n */\n readonly importModule?: ImportModule\n}\n\n/** How a configuration is read synchronously. */\nexport type LoadSyncOptions = LoadLayers & {\n /** The platform it is read by synchronously ({@link LoadSyncPlatform}). */\n readonly platform: LoadSyncPlatform\n}\n\n/**\n * What imports the module of the file at an absolute path, by its file URL, as the paths `path`\n * give it: what imports a configuration of code by default, `wtf.config.ts` among them, whose types\n * Node strips itself. The runtime imports it, of the file system it imports from, and not the one\n * a caller gives.\n */\nexport const importFileModule =\n (path: Pick<ConfigPlatform['path'], 'toFileUrl'>): ImportModule =>\n async (file) =>\n import(path.toFileUrl(file).href)\n\n/** The configuration of a module: its default export, an object, or a function that returns one. */\nasync function configOfModule(\n source: ConfigSource,\n importModule: ImportModule\n): Promise<NamespaceConfig> {\n let module: unknown\n try {\n module = await importModule(source.path)\n } catch (error) {\n throw new InvalidConfigFileError(\n source.path,\n `failed to load: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n const exported: unknown = isObject(module) ? module['default'] : undefined\n const config: unknown = typeof exported === 'function' ? await exported() : exported\n if (!isObject(config))\n throw new InvalidConfigFileError(\n source.path,\n 'exports no object by default: give `export default { … }`, or a function that returns one.'\n )\n return config\n}\n\n/** The configuration of a JSON file: its own object, or the `key` of package.json. */\nfunction* configOfJson(source: ConfigSource, key: string): Reads<NamespaceConfig> {\n const text = (yield* textOf(source.path)) ?? ''\n if (kindOf(source.file) === 'package') {\n const value = manifestOf(source.path, text)[key]\n if (!isObject(value))\n throw new InvalidConfigFileError(source.path, `its \"${key}\" key is no JSON object.`)\n return value\n }\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch (error) {\n throw new InvalidConfigFileError(source.path, 'is no JSON.', { cause: error })\n }\n if (!isObject(value)) throw new InvalidConfigFileError(source.path, 'is no JSON object.')\n return value\n}\n\n/** What a resolved configuration keeps beside the object: the defaults and the environment. */\nfunction layersOf({ defaults, folder: _folder, ...names }: LoadLayers, environment: Environment) {\n const prefix = envPrefixOf(configNamesOf(names).env)\n return {\n ...(defaults === undefined ? {} : { defaults }),\n environment: { prefix, variables: variablesOf(environment, prefix), values: environment }\n }\n}\n\n/** The options of the names alone, without what reads them. */\nconst locateNamesOf = ({ defaults: _d, folder: _f, ...names }: LoadLayers): LocateNames => names\n\n/**\n * The configuration of the project in `folder`, the working folder of the platform by default: the\n * object of the first file of it at the root of the project, in the order of the files of its\n * names — by default `wtf.config.mjs`, `wtf.config.js`, `wtf.config.ts` and `wtf.config.json`,\n * then the `wtf` key of package.json — and the file it came from; `{}`, of no file, when none is\n * there. Each other file found is in `ignored`. The `defaults` a tool gives are kept beside it, for\n * `sectionOf` of ./section to merge the project's sections over, and so are the variables of the\n * environment of the platform, its `env`, of the prefix of the names, `WTF_` by default, with the\n * whole environment, which placeholders are taken from. No placeholder is expanded here. A file of code is imported by `importModule`. A file that\n * holds no object, or a module that fails to load, is an {@link InvalidConfigFileError}.\n */\nexport async function loadConfig({\n importModule,\n platform,\n ...options\n}: LoadOptions): Promise<ResolvedConfig> {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = await locateConfig(options.folder ?? platform.dirs.cwd, {\n platform,\n ...locateNamesOf(options)\n })\n const [source, ...ignored] = sources\n const layers = layersOf(options, platform.env)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n const config =\n kindOf(source.file) === 'code'\n ? await configOfModule(source, importModule ?? importFileModule(platform.path))\n : await readAsync(configOfJson(source, key), filesOf(platform))\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * The configuration of the project in `folder`, the working folder of the platform by default, with\n * the environment of the platform over it, as {@link loadConfig} reads it, read synchronously:\n * of a JSON file of the names, `wtf.config.json` by default, or the key of package.json, `wtf` by\n * default, for a tool that loads its own config synchronously. A configuration of code in use, as\n * `wtf.config.ts`, is a {@link SyncConfigInCodeError}, as importing it is asynchronous.\n */\nexport function loadConfigSync({ platform, ...options }: LoadSyncOptions): ResolvedConfig {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = locateConfigSync(options.folder ?? platform.dirs.cwd, {\n platform,\n ...locateNamesOf(options)\n })\n const [source, ...ignored] = sources\n const layers = layersOf(options, platform.env)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n if (kindOf(source.file) === 'code')\n throw new SyncConfigInCodeError(source.path, { files: jsonFilesOf(options), key })\n const config = readSync(configOfJson(source, key), platform.files)\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * What to say of the files of the configuration that are ignored, as a tool warns: `undefined`\n * when none is.\n */\nexport function ignoredWarning({\n namespace,\n key,\n source,\n ignored\n}: Pick<ResolvedConfig, 'namespace' | 'key' | 'source' | 'ignored'>): string | undefined {\n if (source === undefined || ignored.length === 0) return undefined\n const names = ignored.map(({ file }) =>\n kindOf(file) === 'package' ? `the \"${key}\" key of ${file}` : file\n )\n return `The ${namespace} configuration is read from ${source.file}; ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} ignored. Keep it in one file.`\n}\n"]}
1
+ {"version":3,"file":"load.js","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":";;;;;;;;AA0BA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAoB,MAAM,UAAU,CAAA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E,CAAC,CAAC,MAAM,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;IACnE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,EAAE,CAAA;AACrE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,SAAS,EACT,GAAG,EACH,MAAM,EACN,OAAO,EAC0D;IACjE,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IAClE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CACrC,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG,YAAY,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAClE,CAAA;IACD,OAAO,OAAO,SAAS,+BAA+B,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,gCAAgC,CAAA;AAChK,CAAC","sourcesContent":["/**\n * A project's configuration, as a tool reads it: {@link loadConfig}, the object of the first file\n * of it found at the root of the project, of code or of JSON, the file it came from, and the\n * others found, which are ignored; {@link ignoredWarning}, what to say of the files ignored; and\n * {@link importFileModule}, which imports a configuration of code, as `wtf.config.ts`, by its file\n * URL, as Node imports a module.\n *\n * Each reads by the platform it is given, and nothing of the process: its files, its paths, the\n * folder it works in, which the project is looked for from, and its environment, whose variables\n * are over the configuration. The entry point builds it, as `nodePlatform()` of\n * `@wtf/platform-node/platform` makes Node's:\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfig } from '@wtf/project-config/load'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const resolved = await loadConfig({ platform })\n * ```\n *\n * @packageDocumentation\n */\nimport type { Platform } from '@wtf/platform'\n\nimport { envPrefixOf, variablesOf, type Environment } from './env.ts'\nimport { InvalidConfigFileError } from './errors.ts'\nimport { filesOf, isObject, kindOf, manifestOf, readAsync, type Reads, textOf } from './files.ts'\nimport type {\n ConfigDefaults,\n ConfigPlatform,\n ConfigSource,\n ImportModule,\n NamespaceConfig,\n ResolvedConfig\n} from './index.ts'\nimport { configNamesOf, locateConfig, type LocateNames } from './locate.ts'\n\n/** How a configuration is read, apart from the platform: the folder of the project, its names, and\n * the defaults of the tool's package. */\nexport type LoadLayers = LocateNames & {\n /**\n * The folder of the project, which its root is looked for from: the working folder of the\n * platform, `dirs.cwd`, by default.\n */\n readonly folder?: string\n /**\n * The configuration under the project's, as the tool's package gives it: a section the project\n * gives none of is the one of the defaults, and one it gives is merged over it (`sectionOf` of\n * ./section).\n */\n readonly defaults?: ConfigDefaults\n}\n\n/**\n * What a configuration is read by: the platform's files, its paths and its working\n * folder ({@link ConfigPlatform}), and its environment, `env`, of which the variables of the prefix\n * of the names, as `WTF_`, are kept, and a section is read with them over it, and its placeholders\n * `${env:NAME}` taken from the whole (`sectionOf` of ./section). A `Platform` of `@wtf/platform` is\n * one.\n */\nexport type LoadPlatform = ConfigPlatform & Pick<Platform, 'env'>\n\n/** How a configuration is read. */\nexport type LoadOptions = LoadLayers & {\n /** The platform it is read by ({@link LoadPlatform}). */\n readonly platform: LoadPlatform\n /**\n * What imports a file of code: by default `import()` of its file URL, as the platform's paths\n * give it ({@link importFileModule}). A caller of a file system of its own, not the one its\n * runtime imports from, gives one too.\n */\n readonly importModule?: ImportModule\n}\n\n/**\n * What imports the module of the file at an absolute path, by its file URL, as the paths `path`\n * give it: what imports a configuration of code by default, `wtf.config.ts` among them, whose types\n * Node strips itself. The runtime imports it, of the file system it imports from, and not the one\n * a caller gives.\n */\nexport const importFileModule =\n (path: Pick<ConfigPlatform['path'], 'toFileUrl'>): ImportModule =>\n async (file) =>\n import(path.toFileUrl(file).href)\n\n/** The configuration of a module: its default export, an object, or a function that returns one. */\nasync function configOfModule(\n source: ConfigSource,\n importModule: ImportModule\n): Promise<NamespaceConfig> {\n let module: unknown\n try {\n module = await importModule(source.path)\n } catch (error) {\n throw new InvalidConfigFileError(\n source.path,\n `failed to load: ${error instanceof Error ? error.message : String(error)}`,\n { cause: error }\n )\n }\n const exported: unknown = isObject(module) ? module['default'] : undefined\n const config: unknown = typeof exported === 'function' ? await exported() : exported\n if (!isObject(config))\n throw new InvalidConfigFileError(\n source.path,\n 'exports no object by default: give `export default { … }`, or a function that returns one.'\n )\n return config\n}\n\n/** The configuration of a JSON file: its own object, or the `key` of package.json. */\nfunction* configOfJson(source: ConfigSource, key: string): Reads<NamespaceConfig> {\n const text = (yield* textOf(source.path)) ?? ''\n if (kindOf(source.file) === 'package') {\n const value = manifestOf(source.path, text)[key]\n if (!isObject(value))\n throw new InvalidConfigFileError(source.path, `its \"${key}\" key is no JSON object.`)\n return value\n }\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch (error) {\n throw new InvalidConfigFileError(source.path, 'is no JSON.', { cause: error })\n }\n if (!isObject(value)) throw new InvalidConfigFileError(source.path, 'is no JSON object.')\n return value\n}\n\n/** What a resolved configuration keeps beside the object: the defaults and the environment. */\nfunction layersOf({ defaults, folder: _folder, ...names }: LoadLayers, environment: Environment) {\n const prefix = envPrefixOf(configNamesOf(names).env)\n return {\n ...(defaults === undefined ? {} : { defaults }),\n environment: { prefix, variables: variablesOf(environment, prefix), values: environment }\n }\n}\n\n/** The options of the names alone, without what reads them. */\nconst locateNamesOf = ({ defaults: _d, folder: _f, ...names }: LoadLayers): LocateNames => names\n\n/**\n * The configuration of the project in `folder`, the working folder of the platform by default: the\n * object of the first file of it at the root of the project, in the order of the files of its\n * names — by default `wtf.config.mjs`, `wtf.config.js`, `wtf.config.ts` and `wtf.config.json`,\n * then the `wtf` key of package.json — and the file it came from; `{}`, of no file, when none is\n * there. Each other file found is in `ignored`. The `defaults` a tool gives are kept beside it, for\n * `sectionOf` of ./section to merge the project's sections over, and so are the variables of the\n * environment of the platform, its `env`, of the prefix of the names, `WTF_` by default, with the\n * whole environment, which placeholders are taken from. No placeholder is expanded here. A file of code is imported by `importModule`. A file that\n * holds no object, or a module that fails to load, is an {@link InvalidConfigFileError}.\n */\nexport async function loadConfig({\n importModule,\n platform,\n ...options\n}: LoadOptions): Promise<ResolvedConfig> {\n const { namespace } = configNamesOf(options)\n const { root, key, sources } = await locateConfig(options.folder ?? platform.dirs.cwd, {\n platform,\n ...locateNamesOf(options)\n })\n const [source, ...ignored] = sources\n const layers = layersOf(options, platform.env)\n if (source === undefined)\n return { namespace, root, key, config: {}, source: undefined, ignored: [], ...layers }\n const config =\n kindOf(source.file) === 'code'\n ? await configOfModule(source, importModule ?? importFileModule(platform.path))\n : await readAsync(configOfJson(source, key), filesOf(platform))\n return { namespace, root, key, config, source, ignored, ...layers }\n}\n\n/**\n * What to say of the files of the configuration that are ignored, as a tool warns: `undefined`\n * when none is.\n */\nexport function ignoredWarning({\n namespace,\n key,\n source,\n ignored\n}: Pick<ResolvedConfig, 'namespace' | 'key' | 'source' | 'ignored'>): string | undefined {\n if (source === undefined || ignored.length === 0) return undefined\n const names = ignored.map(({ file }) =>\n kindOf(file) === 'package' ? `the \"${key}\" key of ${file}` : file\n )\n return `The ${namespace} configuration is read from ${source.file}; ${names.join(' and ')} ${names.length === 1 ? 'is' : 'are'} ignored. Keep it in one file.`\n}\n"]}
package/dist/locate.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ConfigNames, ConfigPlatform, ConfigSyncPlatform, LocatedConfig } from './index.ts';
1
+ import type { ConfigNames, ConfigPlatform, LocatedConfig } from './index.ts';
2
2
  /** The namespace a configuration is of when none is given: `wtf`, as `wtf.config.json`. */
3
3
  export declare const DEFAULT_NAMESPACE = "wtf";
4
4
  /**
@@ -22,8 +22,8 @@ export type NamespaceNames = ConfigNames & {
22
22
  export declare function configNamesOf({ namespace, files, key, env }?: NamespaceNames): Required<ConfigNames> & {
23
23
  readonly namespace: string;
24
24
  };
25
- /** The JSON files of the names of a namespace, which a write makes or changes, and a synchronous
26
- * load reads: those of its files that are no code, in their order. */
25
+ /** The JSON files of the names of a namespace, which a write makes or changes: those of its files
26
+ * that are no code, in their order. */
27
27
  export declare const jsonFilesOf: (names?: NamespaceNames) => readonly string[];
28
28
  /** Where the configuration is looked for, apart from the platform: the namespace and its names,
29
29
  * each its default when not given, and whether the root is looked for from the folder up. */
@@ -34,7 +34,7 @@ export type LocateNames = NamespaceNames & {
34
34
  */
35
35
  readonly up?: boolean;
36
36
  };
37
- /** Where the configuration is looked for, asynchronously, by the platform's files. */
37
+ /** Where the configuration is looked for, by the platform's files. */
38
38
  export type LocateOptions = LocateNames & {
39
39
  /**
40
40
  * The platform it is read by: its storage, whose `getDirectory()` is the root of its file
@@ -43,11 +43,6 @@ export type LocateOptions = LocateNames & {
43
43
  */
44
44
  readonly platform: ConfigPlatform;
45
45
  };
46
- /** Where the configuration is looked for, synchronously, by the platform's files. */
47
- export type LocateSyncOptions = LocateNames & {
48
- /** The platform it is read by synchronously, as `nodeSyncPlatform()` of ./node makes it. */
49
- readonly platform: ConfigSyncPlatform;
50
- };
51
46
  /**
52
47
  * The folder the configuration of the project in `folder` is looked for in: the root of the
53
48
  * workspace it is in, the nearest from `folder` up with a pnpm-workspace.yaml or a package.json of
@@ -55,9 +50,6 @@ export type LocateSyncOptions = LocateNames & {
55
50
  * else `folder`. One configuration then serves each package of a workspace.
56
51
  */
57
52
  export declare const projectRootOf: (folder: string, { platform }: Pick<LocateOptions, "platform">) => Promise<string>;
58
- /** The folder the configuration of the project in `folder` is looked for in, as
59
- * {@link projectRootOf} finds it, read synchronously. */
60
- export declare const projectRootOfSync: (folder: string, { platform }: Pick<LocateSyncOptions, "platform">) => string;
61
53
  /**
62
54
  * Each file of the configuration of the project in `folder`, at its root, in the order of the
63
55
  * files of its names (`wtf.config.mjs`, `.js`, `.ts` and `.json` by default), and package.json
@@ -67,6 +59,3 @@ export declare const projectRootOfSync: (folder: string, { platform }: Pick<Loca
67
59
  * a `TypeError`, as {@link configNamesOf} says.
68
60
  */
69
61
  export declare const locateConfig: (folder: string, { platform, ...names }: LocateOptions) => Promise<LocatedConfig>;
70
- /** Each file of the configuration of the project in `folder`, as {@link locateConfig} finds them,
71
- * read synchronously. */
72
- export declare const locateConfigSync: (folder: string, { platform, ...names }: LocateSyncOptions) => LocatedConfig;
package/dist/locate.js CHANGED
@@ -5,8 +5,7 @@
5
5
  * {@link configNamesOf}, those names: the files ({@link configFilesOf} of the namespace by
6
6
  * default), the key of package.json (the namespace) and the prefix of the environment's variables
7
7
  * (the key). The namespace is `wtf` by default ({@link DEFAULT_NAMESPACE}). Each reads by the
8
- * platform it is given, asynchronously; {@link projectRootOfSync} and {@link locateConfigSync} by
9
- * the files of a synchronous one.
8
+ * platform it is given.
10
9
  *
11
10
  * ```ts
12
11
  * import { nodeStorage } from '@wtf/platform-fs-node/storage'
@@ -21,7 +20,7 @@
21
20
  * @packageDocumentation
22
21
  */
23
22
  import { envNameOf } from "./env.js";
24
- import { filesOf, isObject, kindOf, manifestAt, namesOf, PACKAGE_JSON, readAsync, readSync, textOf } from "./files.js";
23
+ import { filesOf, isObject, kindOf, manifestAt, namesOf, PACKAGE_JSON, readAsync, textOf } from "./files.js";
25
24
  /** The namespace a configuration is of when none is given: `wtf`, as `wtf.config.json`. */
26
25
  export const DEFAULT_NAMESPACE = 'wtf';
27
26
  /**
@@ -58,8 +57,8 @@ export function configNamesOf({ namespace = DEFAULT_NAMESPACE, files, key, env }
58
57
  throw new TypeError(`The name of the variables of the environment is empty: name one, as ${names.key}.`);
59
58
  return names;
60
59
  }
61
- /** The JSON files of the names of a namespace, which a write makes or changes, and a synchronous
62
- * load reads: those of its files that are no code, in their order. */
60
+ /** The JSON files of the names of a namespace, which a write makes or changes: those of its files
61
+ * that are no code, in their order. */
63
62
  export const jsonFilesOf = (names = {}) => configNamesOf(names).files.filter((file) => kindOf(file) === 'json');
64
63
  /** Whether the folder is the root of a workspace: a pnpm-workspace.yaml, or npm's `workspaces`. */
65
64
  function* isWorkspaceRoot(folder, { join }) {
@@ -106,9 +105,6 @@ function* locate(folder, { up = true, ...names }, path) {
106
105
  * else `folder`. One configuration then serves each package of a workspace.
107
106
  */
108
107
  export const projectRootOf = (folder, { platform }) => readAsync(rootOf(folder, platform.path), filesOf(platform));
109
- /** The folder the configuration of the project in `folder` is looked for in, as
110
- * {@link projectRootOf} finds it, read synchronously. */
111
- export const projectRootOfSync = (folder, { platform }) => readSync(rootOf(folder, platform.path), platform.files);
112
108
  /**
113
109
  * Each file of the configuration of the project in `folder`, at its root, in the order of the
114
110
  * files of its names (`wtf.config.mjs`, `.js`, `.ts` and `.json` by default), and package.json
@@ -118,7 +114,4 @@ export const projectRootOfSync = (folder, { platform }) => readSync(rootOf(folde
118
114
  * a `TypeError`, as {@link configNamesOf} says.
119
115
  */
120
116
  export const locateConfig = (folder, { platform, ...names }) => readAsync(locate(folder, names, platform.path), filesOf(platform));
121
- /** Each file of the configuration of the project in `folder`, as {@link locateConfig} finds them,
122
- * read synchronously. */
123
- export const locateConfigSync = (folder, { platform, ...names }) => readSync(locate(folder, names, platform.path), platform.files);
124
117
  //# sourceMappingURL=locate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"locate.js","sourceRoot":"","sources":["../src/locate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,OAAO,EACP,YAAY,EACZ,SAAS,EAET,QAAQ,EACR,MAAM,EACP,MAAM,YAAY,CAAA;AASnB,2FAA2F;AAC3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CAAA;AAEjF;yDACyD;AACzD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,MAAc,EACd,EAAE,QAAQ,EAAuC,EACzC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA;AAEpE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAiB,EACb,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAE/F;yBACyB;AACzB,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAqB,EAC1B,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAA","sourcesContent":["/**\n * Where a project's configuration is: {@link projectRootOf}, the folder it is looked for in, the\n * root of the workspace the project is in, or the project's own folder; {@link locateConfig}, each\n * file of it there, in the order of the files of its names, of which the first is used; and\n * {@link configNamesOf}, those names: the files ({@link configFilesOf} of the namespace by\n * default), the key of package.json (the namespace) and the prefix of the environment's variables\n * (the key). The namespace is `wtf` by default ({@link DEFAULT_NAMESPACE}). Each reads by the\n * platform it is given, asynchronously; {@link projectRootOfSync} and {@link locateConfigSync} by\n * the files of a synchronous one.\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { locateConfig } from '@wtf/project-config/locate'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const { root, sources } = await locateConfig(platform.dirs.cwd, { platform })\n * ```\n *\n * @packageDocumentation\n */\nimport { envNameOf } from './env.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestAt,\n namesOf,\n PACKAGE_JSON,\n readAsync,\n type Reads,\n readSync,\n textOf\n} from './files.ts'\nimport type {\n ConfigNames,\n ConfigPlatform,\n ConfigSource,\n ConfigSyncPlatform,\n LocatedConfig\n} from './index.ts'\n\n/** The namespace a configuration is of when none is given: `wtf`, as `wtf.config.json`. */\nexport const DEFAULT_NAMESPACE = 'wtf'\n\n/**\n * The files the configuration of `namespace` can be in by default, in the order the first found is\n * used: code first, as a person who writes code means it to be read, then JSON. After them comes\n * the `namespace` key of package.json, where a write makes it when there is none.\n */\nexport const configFilesOf = (namespace: string = DEFAULT_NAMESPACE): readonly string[] => [\n `${namespace}.config.mjs`,\n `${namespace}.config.js`,\n `${namespace}.config.ts`,\n `${namespace}.config.json`\n]\n\n/** The names of a namespace's configuration: the namespace, `wtf` by default, and the names a\n * tool gives. */\nexport type NamespaceNames = ConfigNames & {\n /** The namespace of the tools: the name of its files and its key by default. `wtf` by default. */\n readonly namespace?: string\n}\n\n/**\n * The names of the configuration of the namespace, each as `names` gives it, else its default: the\n * files, {@link configFilesOf} the namespace; the key of package.json, the namespace; and the\n * prefix of the environment's variables, the key. A file that is neither code nor JSON,\n * package.json among the files, an empty key, or a prefix of no letter or digit, is a `TypeError`.\n */\nexport function configNamesOf({\n namespace = DEFAULT_NAMESPACE,\n files,\n key,\n env\n}: NamespaceNames = {}): Required<ConfigNames> & { readonly namespace: string } {\n const resolvedKey = key ?? namespace\n const names = {\n namespace,\n files: files ?? configFilesOf(namespace),\n key: resolvedKey,\n env: env ?? resolvedKey\n }\n for (const file of names.files)\n if (kindOf(file) === 'package')\n throw new TypeError(\n `${PACKAGE_JSON} is no file of the configuration: it holds it by its key, which \\`key\\` names.`\n )\n if (names.key === '')\n throw new TypeError(`The key of package.json is empty: name one, as ${namespace}.`)\n if (envNameOf(names.env) === '')\n throw new TypeError(\n `The name of the variables of the environment is empty: name one, as ${names.key}.`\n )\n return names\n}\n\n/** The JSON files of the names of a namespace, which a write makes or changes, and a synchronous\n * load reads: those of its files that are no code, in their order. */\nexport const jsonFilesOf = (names: NamespaceNames = {}): readonly string[] =>\n configNamesOf(names).files.filter((file) => kindOf(file) === 'json')\n\n/** Where the configuration is looked for, apart from the platform: the namespace and its names,\n * each its default when not given, and whether the root is looked for from the folder up. */\nexport type LocateNames = NamespaceNames & {\n /**\n * Whether the root is looked for from the folder up, as {@link projectRootOf} finds it: by\n * default. With `false`, the folder given is the root.\n */\n readonly up?: boolean\n}\n\n/** Where the configuration is looked for, asynchronously, by the platform's files. */\nexport type LocateOptions = LocateNames & {\n /**\n * The platform it is read by: its storage, whose `getDirectory()` is the root of its file\n * system, as a browser's or `nodePlatform()` of `@wtf/platform-node/platform` gives it, its\n * paths, and its working folder, which a relative folder is resolved against.\n */\n readonly platform: ConfigPlatform\n}\n\n/** Where the configuration is looked for, synchronously, by the platform's files. */\nexport type LocateSyncOptions = LocateNames & {\n /** The platform it is read by synchronously, as `nodeSyncPlatform()` of ./node makes it. */\n readonly platform: ConfigSyncPlatform\n}\n\n/** The paths the root is looked for by. */\ntype Paths = Pick<ConfigPlatform['path'], 'resolve' | 'join' | 'dirname'>\n\n/** Whether the folder is the root of a workspace: a pnpm-workspace.yaml, or npm's `workspaces`. */\nfunction* isWorkspaceRoot(folder: string, { join }: Paths): Reads<boolean> {\n if ((yield* textOf(join(folder, 'pnpm-workspace.yaml'))) !== undefined) return true\n let manifest: Record<string, unknown> | undefined\n try {\n manifest = yield* manifestAt(join(folder, PACKAGE_JSON))\n } catch {\n return false\n }\n return isObject(manifest) && manifest['workspaces'] !== undefined\n}\n\n/** The root of the project in `folder`, of the reads it asks for. */\nfunction* rootOf(folder: string, path: Paths): Reads<string> {\n const { dirname, join, resolve } = path\n let project: string | undefined\n for (let at = resolve(folder); ; at = dirname(at)) {\n if (yield* isWorkspaceRoot(at, path)) return at\n if (project === undefined && (yield* textOf(join(at, PACKAGE_JSON))) !== undefined) project = at\n if (dirname(at) === at) return project ?? resolve(folder)\n }\n}\n\n/** The configuration of the project in `folder`, located, of the reads it asks for. */\nfunction* locate(\n folder: string,\n { up = true, ...names }: LocateNames,\n path: Paths\n): Reads<LocatedConfig> {\n const { files, key } = configNamesOf(names)\n const root = up ? yield* rootOf(folder, path) : path.resolve(folder)\n const found = yield* namesOf(root)\n const manifest = yield* manifestAt(path.join(root, PACKAGE_JSON))\n const sources: ConfigSource[] = [\n ...files.filter((file) => found.has(file)),\n ...(manifest !== undefined && Object.hasOwn(manifest, key) ? [PACKAGE_JSON] : [])\n ].map((file) => ({ file, path: path.join(root, file) }))\n return { root, key, sources }\n}\n\n/**\n * The folder the configuration of the project in `folder` is looked for in: the root of the\n * workspace it is in, the nearest from `folder` up with a pnpm-workspace.yaml or a package.json of\n * `workspaces`; else the project's own folder, the nearest from `folder` up with a package.json;\n * else `folder`. One configuration then serves each package of a workspace.\n */\nexport const projectRootOf = (\n folder: string,\n { platform }: Pick<LocateOptions, 'platform'>\n): Promise<string> => readAsync(rootOf(folder, platform.path), filesOf(platform))\n\n/** The folder the configuration of the project in `folder` is looked for in, as\n * {@link projectRootOf} finds it, read synchronously. */\nexport const projectRootOfSync = (\n folder: string,\n { platform }: Pick<LocateSyncOptions, 'platform'>\n): string => readSync(rootOf(folder, platform.path), platform.files)\n\n/**\n * Each file of the configuration of the project in `folder`, at its root, in the order of the\n * files of its names (`wtf.config.mjs`, `.js`, `.ts` and `.json` by default), and package.json\n * when it has the key (`wtf` by default). The first is the one in use. The root is\n * {@link projectRootOf} `folder`, or `folder` itself with `up: false`. A package.json that is no\n * JSON object is an `InvalidConfigFileError` of ./errors; names that are not of the configuration,\n * a `TypeError`, as {@link configNamesOf} says.\n */\nexport const locateConfig = (\n folder: string,\n { platform, ...names }: LocateOptions\n): Promise<LocatedConfig> => readAsync(locate(folder, names, platform.path), filesOf(platform))\n\n/** Each file of the configuration of the project in `folder`, as {@link locateConfig} finds them,\n * read synchronously. */\nexport const locateConfigSync = (\n folder: string,\n { platform, ...names }: LocateSyncOptions\n): LocatedConfig => readSync(locate(folder, names, platform.path), platform.files)\n"]}
1
+ {"version":3,"file":"locate.js","sourceRoot":"","sources":["../src/locate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,UAAU,EACV,OAAO,EACP,YAAY,EACZ,SAAS,EAET,MAAM,EACP,MAAM,YAAY,CAAA;AAGnB,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,YAAoB,iBAAiB,EAAqB,EAAE,CAAC;IACzF,GAAG,SAAS,aAAa;IACzB,GAAG,SAAS,YAAY;IACxB,GAAG,SAAS,YAAY;IACxB,GAAG,SAAS,cAAc;CAC3B,CAAA;AASD;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,SAAS,GAAG,iBAAiB,EAC7B,KAAK,EACL,GAAG,EACH,GAAG,KACe,EAAE;IACpB,MAAM,WAAW,GAAG,GAAG,IAAI,SAAS,CAAA;IACpC,MAAM,KAAK,GAAG;QACZ,SAAS;QACT,KAAK,EAAE,KAAK,IAAI,aAAa,CAAC,SAAS,CAAC;QACxC,GAAG,EAAE,WAAW;QAChB,GAAG,EAAE,GAAG,IAAI,WAAW;KACxB,CAAA;IACD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK;QAC5B,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,SAAS;YAC5B,MAAM,IAAI,SAAS,CACjB,GAAG,YAAY,gFAAgF,CAChG,CAAA;IACL,IAAI,KAAK,CAAC,GAAG,KAAK,EAAE;QAClB,MAAM,IAAI,SAAS,CAAC,kDAAkD,SAAS,GAAG,CAAC,C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E,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;IACxD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAA;AAC/B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,MAAc,EACd,EAAE,QAAQ,EAAmC,EAC5B,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA;AAEjF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,MAAc,EACd,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAiB,EACb,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAA","sourcesContent":["/**\n * Where a project's configuration is: {@link projectRootOf}, the folder it is looked for in, the\n * root of the workspace the project is in, or the project's own folder; {@link locateConfig}, each\n * file of it there, in the order of the files of its names, of which the first is used; and\n * {@link configNamesOf}, those names: the files ({@link configFilesOf} of the namespace by\n * default), the key of package.json (the namespace) and the prefix of the environment's variables\n * (the key). The namespace is `wtf` by default ({@link DEFAULT_NAMESPACE}). Each reads by the\n * platform it is given.\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { locateConfig } from '@wtf/project-config/locate'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const { root, sources } = await locateConfig(platform.dirs.cwd, { platform })\n * ```\n *\n * @packageDocumentation\n */\nimport { envNameOf } from './env.ts'\nimport {\n filesOf,\n isObject,\n kindOf,\n manifestAt,\n namesOf,\n PACKAGE_JSON,\n readAsync,\n type Reads,\n textOf\n} from './files.ts'\nimport type { ConfigNames, ConfigPlatform, ConfigSource, LocatedConfig } from './index.ts'\n\n/** The namespace a configuration is of when none is given: `wtf`, as `wtf.config.json`. */\nexport const DEFAULT_NAMESPACE = 'wtf'\n\n/**\n * The files the configuration of `namespace` can be in by default, in the order the first found is\n * used: code first, as a person who writes code means it to be read, then JSON. After them comes\n * the `namespace` key of package.json, where a write makes it when there is none.\n */\nexport const configFilesOf = (namespace: string = DEFAULT_NAMESPACE): readonly string[] => [\n `${namespace}.config.mjs`,\n `${namespace}.config.js`,\n `${namespace}.config.ts`,\n `${namespace}.config.json`\n]\n\n/** The names of a namespace's configuration: the namespace, `wtf` by default, and the names a\n * tool gives. */\nexport type NamespaceNames = ConfigNames & {\n /** The namespace of the tools: the name of its files and its key by default. `wtf` by default. */\n readonly namespace?: string\n}\n\n/**\n * The names of the configuration of the namespace, each as `names` gives it, else its default: the\n * files, {@link configFilesOf} the namespace; the key of package.json, the namespace; and the\n * prefix of the environment's variables, the key. A file that is neither code nor JSON,\n * package.json among the files, an empty key, or a prefix of no letter or digit, is a `TypeError`.\n */\nexport function configNamesOf({\n namespace = DEFAULT_NAMESPACE,\n files,\n key,\n env\n}: NamespaceNames = {}): Required<ConfigNames> & { readonly namespace: string } {\n const resolvedKey = key ?? namespace\n const names = {\n namespace,\n files: files ?? configFilesOf(namespace),\n key: resolvedKey,\n env: env ?? resolvedKey\n }\n for (const file of names.files)\n if (kindOf(file) === 'package')\n throw new TypeError(\n `${PACKAGE_JSON} is no file of the configuration: it holds it by its key, which \\`key\\` names.`\n )\n if (names.key === '')\n throw new TypeError(`The key of package.json is empty: name one, as ${namespace}.`)\n if (envNameOf(names.env) === '')\n throw new TypeError(\n `The name of the variables of the environment is empty: name one, as ${names.key}.`\n )\n return names\n}\n\n/** The JSON files of the names of a namespace, which a write makes or changes: those of its files\n * that are no code, in their order. */\nexport const jsonFilesOf = (names: NamespaceNames = {}): readonly string[] =>\n configNamesOf(names).files.filter((file) => kindOf(file) === 'json')\n\n/** Where the configuration is looked for, apart from the platform: the namespace and its names,\n * each its default when not given, and whether the root is looked for from the folder up. */\nexport type LocateNames = NamespaceNames & {\n /**\n * Whether the root is looked for from the folder up, as {@link projectRootOf} finds it: by\n * default. With `false`, the folder given is the root.\n */\n readonly up?: boolean\n}\n\n/** Where the configuration is looked for, by the platform's files. */\nexport type LocateOptions = LocateNames & {\n /**\n * The platform it is read by: its storage, whose `getDirectory()` is the root of its file\n * system, as a browser's or `nodePlatform()` of `@wtf/platform-node/platform` gives it, its\n * paths, and its working folder, which a relative folder is resolved against.\n */\n readonly platform: ConfigPlatform\n}\n\n/** The paths the root is looked for by. */\ntype Paths = Pick<ConfigPlatform['path'], 'resolve' | 'join' | 'dirname'>\n\n/** Whether the folder is the root of a workspace: a pnpm-workspace.yaml, or npm's `workspaces`. */\nfunction* isWorkspaceRoot(folder: string, { join }: Paths): Reads<boolean> {\n if ((yield* textOf(join(folder, 'pnpm-workspace.yaml'))) !== undefined) return true\n let manifest: Record<string, unknown> | undefined\n try {\n manifest = yield* manifestAt(join(folder, PACKAGE_JSON))\n } catch {\n return false\n }\n return isObject(manifest) && manifest['workspaces'] !== undefined\n}\n\n/** The root of the project in `folder`, of the reads it asks for. */\nfunction* rootOf(folder: string, path: Paths): Reads<string> {\n const { dirname, join, resolve } = path\n let project: string | undefined\n for (let at = resolve(folder); ; at = dirname(at)) {\n if (yield* isWorkspaceRoot(at, path)) return at\n if (project === undefined && (yield* textOf(join(at, PACKAGE_JSON))) !== undefined) project = at\n if (dirname(at) === at) return project ?? resolve(folder)\n }\n}\n\n/** The configuration of the project in `folder`, located, of the reads it asks for. */\nfunction* locate(\n folder: string,\n { up = true, ...names }: LocateNames,\n path: Paths\n): Reads<LocatedConfig> {\n const { files, key } = configNamesOf(names)\n const root = up ? yield* rootOf(folder, path) : path.resolve(folder)\n const found = yield* namesOf(root)\n const manifest = yield* manifestAt(path.join(root, PACKAGE_JSON))\n const sources: ConfigSource[] = [\n ...files.filter((file) => found.has(file)),\n ...(manifest !== undefined && Object.hasOwn(manifest, key) ? [PACKAGE_JSON] : [])\n ].map((file) => ({ file, path: path.join(root, file) }))\n return { root, key, sources }\n}\n\n/**\n * The folder the configuration of the project in `folder` is looked for in: the root of the\n * workspace it is in, the nearest from `folder` up with a pnpm-workspace.yaml or a package.json of\n * `workspaces`; else the project's own folder, the nearest from `folder` up with a package.json;\n * else `folder`. One configuration then serves each package of a workspace.\n */\nexport const projectRootOf = (\n folder: string,\n { platform }: Pick<LocateOptions, 'platform'>\n): Promise<string> => readAsync(rootOf(folder, platform.path), filesOf(platform))\n\n/**\n * Each file of the configuration of the project in `folder`, at its root, in the order of the\n * files of its names (`wtf.config.mjs`, `.js`, `.ts` and `.json` by default), and package.json\n * when it has the key (`wtf` by default). The first is the one in use. The root is\n * {@link projectRootOf} `folder`, or `folder` itself with `up: false`. A package.json that is no\n * JSON object is an `InvalidConfigFileError` of ./errors; names that are not of the configuration,\n * a `TypeError`, as {@link configNamesOf} says.\n */\nexport const locateConfig = (\n folder: string,\n { platform, ...names }: LocateOptions\n): Promise<LocatedConfig> => readAsync(locate(folder, names, platform.path), filesOf(platform))\n"]}
package/dist/named.d.ts CHANGED
@@ -18,8 +18,8 @@
18
18
  * Each entry is a factory of the value, `(options) => value`: a function, which takes the options
19
19
  * as it chooses, or a plain value, whose options are merged over it ({@link factoryOf}). A set is
20
20
  * a map of entries by name, the export of a module that is one, or an array of those, a later set
21
- * over an earlier one by name. A module is loaded by what the caller gives, `nodeLoadModule` of
22
- * ./node of Node's, so this module runs on any platform. What fails is a `NamedError` of ./errors,
21
+ * over an earlier one by name. A module is loaded by what the caller gives, Node's
22
+ * `nodeLoadModule` of `@wtf/platform-node/module`, so this module runs on any platform. What fails is a `NamedError` of ./errors,
23
23
  * which names where: the path, from where the caller says the sets or the reference are, the index
24
24
  * of the set and the name of the entry, and the module and the export.
25
25
  *
@@ -84,6 +84,8 @@ export type NamedSets<T> = NamedSet<T> | readonly NamedSet<T>[];
84
84
  /**
85
85
  * What loads a module of a {@link ModuleReference}: the module of the text it names, as an object
86
86
  * of its exports, or a failure, which a `NamedError` of `UNLOADABLE_MODULE` holds as its cause.
87
+ * Node's is `nodeLoadModule(root, beside?)` of `@wtf/platform-node/module`, whose `LoadModule` of
88
+ * `@wtf/platform/module` is this one.
87
89
  */
88
90
  export type LoadModule = (module: string) => Promise<unknown>;
89
91
  /**
package/dist/named.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"named.js","sourceRoot":"","sources":["../src/named.ts"],"names":[],"mappings":"AA6CA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,UAAU,EAA+C,MAAM,aAAa,CAAA;AAErF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAoGtC,4FAA4F;AAC5F,MAAM,OAAO,GAAG,CAAC,KAAc,EAA8C,EAAE;IAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,SAAS,GAAY,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACvD,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAA;AAC7D,CAAC,CAAA;AAED,qFAAqF;AACrF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA4B,EAAE,CAC5D,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAA;AAEvD,4DAA4D;AAC5D,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC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AM,GAAG,GAAG;QACV,WAAW,EAAE,YAAY,IAAI,sEAAsE;QACnG,KAAK,EAAE;YACL,aAAa;YACb;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,EAAE,KAAK,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE;aACxE;SACF;KACF,CAAA;IACD,OAAO,QAAQ,CAAC;QACd,WAAW,EAAE,eAAe,IAAI,wEAAwE;QACxG,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;KAC5C,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/**\n * A value or a function a configuration of JSON names, where JSON cannot hold it, and the code\n * that finds it: a set of named entries, as a tool gives some and a project adds its own, and a\n * reference to one of them, or to the export of a module. {@link resolveNamed} gives the value a\n * reference is; {@link resolveNamedSet} the entries of one set or of sets merged in order;\n * {@link factoryOf} the entry of a plain value, the options of a reference merged over it; and\n * {@link namedSchema} and {@link namedSetSchema} the schema of a reference and of a set, a\n * Standard Schema that checks it and gives its JSON Schema, so an editor completes the names.\n *\n * A reference is one of three forms:\n *\n * - `\"short\"`: the entry of that name;\n * - `{ \"format\": \"short\", \"width\": 60 }`: the entry of that name, by a key the caller chooses,\n * with the options beside it, which the entry is given;\n * - `{ \"module\": \"./formatters.mjs\", \"export\": \"wide\" }`: the export of a module, `default` by\n * default, as it is.\n *\n * Each entry is a factory of the value, `(options) => value`: a function, which takes the options\n * as it chooses, or a plain value, whose options are merged over it ({@link factoryOf}). A set is\n * a map of entries by name, the export of a module that is one, or an array of those, a later set\n * over an earlier one by name. A module is loaded by what the caller gives, `nodeLoadModule` of\n * ./node of Node's, so this module runs on any platform. What fails is a `NamedError` of ./errors,\n * which names where: the path, from where the caller says the sets or the reference are, the index\n * of the set and the name of the entry, and the module and the export.\n *\n * ```ts\n * import { factoryOf, resolveNamed, resolveNamedSet } from '@wtf/project-config/named'\n *\n * type Format = { readonly width: number; readonly ellipsis: string }\n *\n * const formatters = await resolveNamedSet<Format>([\n * { short: factoryOf({ width: 40, ellipsis: '…' }) },\n * { wide: { width: 120, ellipsis: '' } }\n * ])\n * const format = await resolveNamed<Format>(\n * { format: 'short', width: 60 },\n * { key: 'format', names: formatters, kind: 'formatter' }\n * )\n * // { width: 60, ellipsis: '…' }\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { jsonSchemaOf } from './env.ts'\nimport { NamedError, type NamedErrorCode, type NamedErrorDetails } from './errors.ts'\nimport type { ConfigIssue, ConfigPath, JsonSchema, SectionSchema } from './index.ts'\nimport { issuesOf, issuesOfSync } from './section.ts'\nimport { textOfPath } from './text.ts'\n\n/**\n * The export of a module, as a configuration of JSON names it: the module, by what the loader\n * resolves, as a path from the root of the project or the name of a package, and the name of its\n * export, `default` by default.\n */\nexport type ModuleReference = {\n /** The module, as the loader resolves it: `./formatters.mjs`, or a package. */\n readonly module: string\n /** The name of its export: `default` by default. */\n readonly export?: string | undefined\n}\n\n/**\n * A reference to an entry by its name under the key `K`, with the options beside it, which the\n * entry is given: `{ \"format\": \"short\", \"width\": 60 }` of the key `format`. Of a key not known, as\n * `string`, any object of options.\n */\nexport type NamedUse<K extends string = string> = string extends K\n ? NamedOptions\n : { readonly [P in K]: string } & NamedOptions\n\n/**\n * A reference, as a configuration of JSON gives it: the name of an entry; the name under the key\n * `K`, with options; or the export of a module.\n */\nexport type NamedReference<K extends string = string> = string | NamedUse<K> | ModuleReference\n\n/** The options a reference gives an entry: each beside its name, but the key and any `undefined`. */\nexport type NamedOptions = Readonly<Record<string, unknown>>\n\n/** An entry of a set: what makes the value of the options a reference gives, none of a name alone. */\nexport type NamedFactory<T> = (options: NamedOptions) => T | Promise<T>\n\n/** The entries of a set, each a factory, by their names, as {@link resolveNamedSet} gives them. */\nexport type NamedEntries<T> = Readonly<Record<string, NamedFactory<T>>>\n\n/**\n * A set of entries, as a configuration gives it: a map of each by its name, a factory, a plain\n * value or the export of a module that is one of those; or the export of a module that is such a\n * map.\n */\nexport type NamedSet<T> =\n | ModuleReference\n | Readonly<Record<string, NamedFactory<T> | ModuleReference | T>>\n\n/** The sets of a configuration: one, or an array of them, merged in order, each over those before. */\nexport type NamedSets<T> = NamedSet<T> | readonly NamedSet<T>[]\n\n/**\n * What loads a module of a {@link ModuleReference}: the module of the text it names, as an object\n * of its exports, or a failure, which a `NamedError` of `UNLOADABLE_MODULE` holds as its cause.\n */\nexport type LoadModule = (module: string) => Promise<unknown>\n\n/**\n * What a set and a reference are resolved by alike: the loader of their modules, the check of\n * their values, their kind, and where they are in the configuration.\n */\nexport type NamedCheckOptions<T> = {\n /** What loads each module named: none by default, of which a module is unloadable. */\n readonly load?: LoadModule | undefined\n /**\n * What checks a value: a Standard Schema, a JSON Schema or a function, as `issuesOf` of\n * ./section takes it. Of a set, each value an entry is, of a map or of a module, but a function,\n * whose results it checks too of `checkResults`; of a reference, the value it resolves to.\n */\n readonly check?: SectionSchema<T> | undefined\n /** What the entries are, which an error names: `entry` by default, as `formatter`. */\n readonly kind?: string | undefined\n /**\n * Where the sets, or the reference, are in the configuration, which the `at` of an error starts\n * with, and its message names, as `['formatters']`: none by default.\n */\n readonly at?: ConfigPath | undefined\n}\n\n/** How a set is resolved: as {@link NamedCheckOptions} say, and whether `check` checks what a\n * function entry gives. */\nexport type NamedSetOptions<T> = NamedCheckOptions<T> & {\n /**\n * Whether `check` checks too what each function entry gives, each time it is called, as it\n * checks a value entry once: no by default, of which a function entry is used as it is.\n */\n readonly checkResults?: boolean | undefined\n}\n\n/** How a reference is resolved: the key of its names, its entries, and what\n * {@link NamedCheckOptions} say. */\nexport type NamedResolveOptions<T> = NamedCheckOptions<T> & {\n /** The key a reference of options names its entry by, as `format`: none takes a name alone. */\n readonly key?: string | undefined\n /** The entries a reference names, by their names: none by default. */\n readonly names?: NamedEntries<T> | undefined\n}\n\n/** The schema of a reference or a set: a Standard Schema that checks it, and gives its JSON Schema. */\nexport type NamedSchema<T> = StandardSchemaV1<unknown, T> & StandardJSONSchemaV1<unknown, T>\n\n/** Whether `value` is an object of keys, as JSON's: no list, and no instance of a class. */\nconst isPlain = (value: unknown): value is Readonly<Record<string, unknown>> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false\n const prototype: unknown = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\n/** Whether `value` is the export of a module: an object whose `module` is a text. */\nconst isModule = (value: unknown): value is ModuleReference =>\n isPlain(value) && typeof value['module'] === 'string'\n\n/** `word` after its article, `a` or `an`, as `an entry`. */\nconst article = (word: string): string => `${/^[aeiou]/i.test(word) ? 'an' : 'a'} ${word}`\n\n/** `text` of a capital first. */\nconst capital = (text: string): string => `${text.charAt(0).toUpperCase()}${text.slice(1)}`\n\n/** `value` as an error names it. */\nconst textOf = (value: unknown): string =>\n typeof value === 'function' ? 'a function' : (JSON.stringify(value) ?? String(value))\n\n/** The options of `options` that are given: each but those of `undefined`. */\nconst givenOf = (options: NamedOptions): NamedOptions =>\n Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))\n\n/**\n * The entry of `value`: of a plain object, `value` with the options a reference gives beside the\n * name merged over it, key by key, and those of `undefined` left out, so\n * `{ format: 'short', width: 60 }` gives `{ width: 60, ellipsis: '…' }` of\n * `{ width: 40, ellipsis: '…' }`; of any other value, the value, which takes no options, so options\n * given are a `NamedError` of `INVALID_NAMED_VALUE`. {@link resolveNamedSet} makes each value of a\n * set that is no function an entry so.\n */\nexport function factoryOf<T>(value: T): NamedFactory<T> {\n return (options) => {\n const given = givenOf(options)\n if (isPlain(value)) return { ...value, ...given } as T\n if (Object.keys(given).length === 0) return value\n throw new NamedError(\n 'INVALID_NAMED_VALUE',\n `${textOf(value)} takes no options, and is given ${Object.keys(given).join(', ')}.`\n )\n }\n}\n\n/** The text of the issues a check found. */\nconst issuesText = (issues: readonly ConfigIssue[]): string =>\n issues\n .map(({ path, message }) => (path.length === 0 ? message : `${path.join('.')}: ${message}`))\n .join('; ')\n\n/**\n * Where a value of the sets or a reference is, as a `NamedError` names it: its path; the path of\n * its set or its reference, which the message starts with, as the message names the entry itself;\n * the index of its set and the name of its entry; and what it is to be, as `the formatter wide`.\n */\ntype Place = {\n readonly at: ConfigPath\n readonly where: ConfigPath\n readonly set?: number | undefined\n readonly entry?: string | undefined\n readonly as?: string | undefined\n}\n\n/** The module and the export of `reference`, as a `NamedError` names them. */\nconst moduleDetails = (reference: ModuleReference): NamedErrorDetails => ({\n module: reference.module,\n export: reference.export ?? 'default'\n})\n\n/**\n * A `NamedError` of `code` at `place`: its message after the path of its set or its reference, of\n * one that is not empty, and the path, the set and the entry of the place beside `details`.\n */\nfunction namedError(\n code: NamedErrorCode,\n message: string,\n { at, where, set, entry }: Place,\n details: NamedErrorDetails = {},\n options?: ErrorOptions\n): NamedError {\n return new NamedError(\n code,\n where.length === 0 ? message : `${textOfPath(where)}: ${message}`,\n {\n ...details,\n at,\n ...(set === undefined ? {} : { set }),\n ...(entry === undefined ? {} : { entry })\n },\n options\n )\n}\n\n/**\n * `value`, checked by `check`, else a `NamedError` of `INVALID_NAMED_VALUE` at `place`, whose\n * message is `failing` and the issues, and `details` beside it.\n */\nasync function checked<T>(\n value: unknown,\n check: SectionSchema<T> | undefined,\n failing: string,\n place: Place,\n details: NamedErrorDetails = {}\n): Promise<T> {\n if (check === undefined) return value as T\n const { issues, value: read } = await issuesOf(value, check)\n if (issues.length === 0) return read\n throw namedError('INVALID_NAMED_VALUE', `${failing}: ${issuesText(issues)}.`, place, {\n ...details,\n issues\n })\n}\n\n/**\n * The export `reference.export`, `default` by default, of the module `reference.module`, loaded by\n * `load`: a `NamedError` at `place` of `UNLOADABLE_MODULE` of a module that fails to load, or of no\n * loader, and of `MISSING_EXPORT` of an export it has not, each of the module and the export.\n */\nasync function exportOf(\n reference: ModuleReference,\n load: LoadModule | undefined,\n place: Place\n): Promise<unknown> {\n const { module } = reference\n const name = reference.export ?? 'default'\n const details = moduleDetails(reference)\n const as = place.as === undefined ? '' : ` as ${place.as}`\n if (load === undefined)\n throw namedError(\n 'UNLOADABLE_MODULE',\n `The module ${module} cannot be loaded, for its export ${name}${as}: no loader of modules is given.`,\n place,\n details\n )\n let loaded: unknown\n try {\n loaded = await load(module)\n } catch (error) {\n throw namedError(\n 'UNLOADABLE_MODULE',\n `The module ${module} cannot be loaded, for its export ${name}${as}: ${error instanceof Error ? error.message : String(error)}`,\n place,\n details,\n { cause: error }\n )\n }\n const exports = loaded as Readonly<Record<string, unknown>> | null | undefined\n const found = typeof exports === 'object' && exports !== null ? exports[name] : undefined\n if (found === undefined)\n throw namedError(\n 'MISSING_EXPORT',\n `The module ${module} has no export ${name}${as}.`,\n place,\n details\n )\n return found\n}\n\n/** What a module's export is, as an error names it. */\nconst exportText = ({ module, export: name = 'default' }: ModuleReference): string =>\n `The export ${name} of ${module}`\n\n/**\n * The entry of `value` of the name `name`, at `place`: a function as it is, or, of `checkResults`,\n * one whose results `check` checks; else the value checked, of {@link factoryOf}.\n */\nasync function entryOf<T>(\n value: unknown,\n name: string,\n place: Place,\n { load, check, checkResults, kind = 'entry' }: NamedSetOptions<T>\n): Promise<NamedFactory<T>> {\n const reference = isModule(value) ? value : undefined\n const details = reference === undefined ? {} : moduleDetails(reference)\n const found =\n reference === undefined\n ? value\n : await exportOf(reference, load, { ...place, as: `the ${kind} ${name}` })\n const what =\n reference === undefined\n ? `The ${kind} ${name}`\n : `${exportText(reference)}, the ${kind} ${name},`\n if (typeof found === 'function') {\n const factory = found as NamedFactory<T>\n if (checkResults !== true || check === undefined) return factory\n return async (options) =>\n checked(\n await factory(options),\n check,\n `${what} gives a value that is not valid`,\n place,\n details\n )\n }\n return factoryOf(await checked(found, check, `${what} is not valid`, place, details))\n}\n\n/**\n * The entries of `sets`, each a factory, by their names: of each set in order, a map of entries by\n * name or the export of a module that is one, a later set over an earlier one by name, so a\n * project's own are over those of a package; none of `undefined`. Each entry is a function, a\n * factory as it is, or a plain value, checked by `check`, of {@link factoryOf}; or the export of\n * a module that is one of those, loaded by `load`. Of `checkResults`, `check` checks what each\n * function entry gives too, each time it is called. Each module is loaded at once, so a set that\n * fails does before any entry is used. Fails with a `NamedError` of `UNLOADABLE_MODULE` or\n * `MISSING_EXPORT` of a module, and of `INVALID_NAMED_VALUE` of a set that is no map, or a value\n * `check` refuses. The error names where it failed: its `at` is the path `at` gives, the index of\n * the set in an array of sets, its `set`, and the name of the entry, its `entry`, as\n * `['formatters', '1', 'wide']`, and its message starts with the path of the set; and its `module`\n * and `export` are those of a set or an entry a module exports.\n */\nexport async function resolveNamedSet<T>(\n sets: NamedSets<T> | undefined,\n options: NamedSetOptions<T> = {}\n): Promise<NamedEntries<T>> {\n const { at = [], kind = 'entry' } = options\n const many = Array.isArray(sets)\n const list: readonly unknown[] = sets === undefined ? [] : many ? sets : [sets]\n const resolved = await Promise.all(\n list.map(async (set, index) => {\n const of = many ? [...at, String(index)] : at\n const place: Place = { at: of, where: of, ...(many ? { set: index } : {}) }\n const reference = isModule(set) ? set : undefined\n const map =\n reference === undefined\n ? set\n : await exportOf(reference, options.load, { ...place, as: `a set of ${kind}s` })\n if (!isPlain(map))\n throw namedError(\n 'INVALID_NAMED_VALUE',\n `${reference === undefined ? textOf(set) : exportText(reference)} is no set: give an object of each ${kind} by its name.`,\n place,\n reference === undefined ? {} : moduleDetails(reference)\n )\n const entries = await Promise.all(\n Object.entries(map).map(async ([name, value]): Promise<[string, NamedFactory<T>]> => [\n name,\n await entryOf(value, name, { ...place, at: [...place.at, name], entry: name }, options)\n ])\n )\n return Object.fromEntries(entries)\n })\n )\n return Object.assign({}, ...resolved) as NamedEntries<T>\n}\n\n/** What `error` names but its place, as a `NamedError` that holds it gives it again. */\nconst detailsOf = (error: NamedError): NamedErrorDetails => ({\n ...(error.unknown === undefined ? {} : { name: error.unknown }),\n ...(error.module === undefined ? {} : { module: error.module }),\n ...(error.export === undefined ? {} : { export: error.export }),\n names: error.names,\n issues: error.issues\n})\n\n/**\n * The value `reference` is: of a name, the entry of that name of `names`, given no options; of an\n * object of the `key`, the entry of the name under it, given the options beside it but those of\n * `undefined`; of the export of a module, `{ module, export }`, the export as it is, loaded by\n * `load`. With a `check`, the value is checked by it. Fails with a `NamedError`: `UNKNOWN_NAME` of\n * a name of no entry, whose message lists the names there are; `UNLOADABLE_MODULE` and\n * `MISSING_EXPORT` of a module; and `INVALID_NAMED_VALUE` of a reference of none of the forms, or\n * a value `check` refuses. The error names where it failed: its `at` is the path `at` gives, which\n * its message starts with; its `entry` the name of the entry whose value fails, or which fails as\n * it is given its options; and its `module` and `export` those of a reference to a module.\n */\nexport async function resolveNamed<T>(\n reference: NamedReference,\n { key, names = {}, load, check, kind = 'entry', at = [] }: NamedResolveOptions<T> = {}\n): Promise<T> {\n const place: Place = { at, where: at }\n const use: unknown = reference\n if (isModule(use) && (key === undefined || !(key in use)))\n return checked(\n await exportOf(use, load, place),\n check,\n `${exportText(use)} is not valid`,\n place,\n moduleDetails(use)\n )\n const named =\n typeof use === 'string'\n ? { name: use, options: {} }\n : isPlain(use) && key !== undefined && typeof use[key] === 'string'\n ? (() => {\n const { [key]: name, ...options } = use\n return { name: name as string, options: givenOf(options) }\n })()\n : undefined\n if (named === undefined)\n throw namedError(\n 'INVALID_NAMED_VALUE',\n `${textOf(use)} is no reference of ${article(kind)}: give its name${key === undefined ? '' : `, { \"${key}\": name, … }`} or { \"module\": …, \"export\": … }.`,\n place\n )\n const { name, options } = named\n if (!Object.hasOwn(names, name)) {\n const known = Object.keys(names)\n throw namedError(\n 'UNKNOWN_NAME',\n `No ${kind} is named ${JSON.stringify(name)}: the names are ${known.length === 0 ? 'none' : known.join(', ')}.`,\n place,\n { name, names: known }\n )\n }\n const entry = names[name] as NamedFactory<T>\n const of: Place = { ...place, entry: name }\n let value: unknown\n try {\n value = await entry(options)\n } catch (error) {\n if (!(error instanceof NamedError) || error.entry !== undefined) throw error\n throw namedError(\n error.code,\n `The ${kind} ${name} fails: ${error.message}`,\n of,\n detailsOf(error),\n { cause: error }\n )\n }\n return checked(value, check, `The ${kind} ${name} is not valid`, of)\n}\n\n/** The JSON Schema of the export of a module. */\nconst MODULE_SCHEMA = {\n description: 'The export of a module: `default` by default.',\n type: 'object',\n properties: {\n module: {\n description: 'The module: a path from the root, or a package.',\n type: 'string',\n minLength: 1\n },\n export: {\n description: 'The name of its export: `default` by default.',\n type: 'string',\n minLength: 1\n }\n },\n required: ['module'],\n additionalProperties: false\n} as const\n\n/** The JSON Schema of a name: a text, of the `names` an editor completes. */\nconst nameSchema = (kind: string, names: readonly string[] | undefined): JsonSchema => ({\n description: `The name of ${article(kind)}.`,\n type: 'string',\n minLength: 1,\n ...(names === undefined || names.length === 0 ? {} : { examples: [...names] })\n})\n\n/** The JSON Schema of `schema`, as an object of its keywords: `{}`, any value, of none. */\nconst objectSchemaOf = (schema: SectionSchema | undefined): Readonly<Record<string, unknown>> => {\n const json = schema === undefined ? undefined : jsonSchemaOf(schema)\n if (json === undefined || json === true) return {}\n if (json === false) return { not: {} }\n const { $schema: _draft, $id: _id, ...rest } = json\n return rest\n}\n\n/**\n * The schema of `json`, of the type `T`: it checks a value by ajv, as `issuesOfSync` of ./section\n * checks a JSON Schema, and gives `json`, of draft 2020-12, as the JSON Schema of its input and\n * output alike.\n */\nfunction schemaOf<T>(json: Readonly<Record<string, unknown>>): NamedSchema<T> {\n const jsonSchema = (): Record<string, unknown> => ({ ...json })\n return {\n '~standard': {\n version: 1,\n vendor: '@wtf/project-config',\n validate: (value) => {\n const { issues } = issuesOfSync(value, json)\n return issues.length === 0\n ? { value: value as T }\n : { issues: issues.map(({ path, message }) => ({ path, message })) }\n },\n jsonSchema: { input: jsonSchema, output: jsonSchema }\n }\n }\n}\n\n/** What the schema of a reference says of it. */\nexport type NamedSchemaOptions = {\n /** The names an editor completes: those of the entries there are. */\n readonly names?: readonly string[] | undefined\n /**\n * The schema of the options beside a name, as each entry takes them: a JSON Schema, or a\n * Standard Schema that gives one, of an object, whose `properties` are each an option. Any by\n * default.\n */\n readonly options?: SectionSchema | undefined\n /** What the entries are, which the descriptions name: `entry` by default. */\n readonly kind?: string | undefined\n}\n\n/**\n * The schema of a reference of the key `key`: a name, of `names`, which an editor completes;\n * `{ [key]: name, … }`, with the options of `options` beside it, each optional, as they are over\n * the entry's own; or `{ module, export }`. Its JSON Schema, which `input()` of its\n * `~standard.jsonSchema` gives, holds no `$schema`, so it goes in a tool's own as it is.\n */\nexport function namedSchema<K extends string>(\n key: K,\n { names, options, kind = 'entry' }: NamedSchemaOptions = {}\n): NamedSchema<NamedReference<K>> {\n const name = nameSchema(kind, names)\n const { properties, required: _required, type: _type, ...rest } = objectSchemaOf(options)\n return schemaOf({\n description: `${capital(article(kind))}: its name, { \"${key}\": name, … } with options over its own, or the export of a module.`,\n anyOf: [\n name,\n {\n ...rest,\n description: `${capital(article(kind))} by its name, with options over its own.`,\n type: 'object',\n properties: { ...(isPlain(properties) ? properties : {}), [key]: name },\n required: [key]\n },\n MODULE_SCHEMA\n ]\n })\n}\n\n/** What the schema of a set says of it. */\nexport type NamedSetSchemaOptions = {\n /** The schema of the value of an entry: a JSON Schema, or a Standard Schema that gives one. Any by default. */\n readonly entry?: SectionSchema | undefined\n /** What the entries are, which the descriptions name: `entry` by default. */\n readonly kind?: string | undefined\n}\n\n/**\n * The schema of the sets of entries: a set, or an array of sets, merged in order; each set the\n * export of a module, or a map of each entry by its name, of `entry`, or the export of a module.\n * Its JSON Schema holds no `$schema`, as {@link namedSchema}'s.\n */\nexport function namedSetSchema({ entry, kind = 'entry' }: NamedSetSchemaOptions = {}): NamedSchema<\n NamedSets<unknown>\n> {\n const set = {\n description: `A set of ${kind}s: a map of each by its name, or the export of a module that is one.`,\n anyOf: [\n MODULE_SCHEMA,\n {\n type: 'object',\n additionalProperties: { anyOf: [MODULE_SCHEMA, objectSchemaOf(entry)] }\n }\n ]\n }\n return schemaOf({\n description: `The sets of ${kind}s: a set, or an array of sets merged in order, each over those before.`,\n anyOf: [set, { type: 'array', items: set }]\n })\n}\n"]}
1
+ {"version":3,"file":"named.js","sourceRoot":"","sources":["../src/named.ts"],"names":[],"mappings":"AA6CA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,OAAO,EAAE,UAAU,EAA+C,MAAM,aAAa,CAAA;AAErF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAsGtC,4FAA4F;AAC5F,MAAM,OAAO,GAAG,CAAC,KAAc,EAA8C,EAAE;IAC7E,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrF,MAAM,SAAS,GAAY,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IACvD,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAA;AAC7D,CAAC,CAAA;AAED,qFAAqF;AACrF,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA4B,EAAE,CAC5D,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,QAAQ,CAAA;AAEvD,4DAA4D;AAC5D,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,EAAE,CAAA;AAE1F,iCAAiC;AACjC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;AAE3F,oCAAoC;AACpC,MA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AQ,CAAC;QACd,WAAW,EAAE,eAAe,IAAI,wEAAwE;QACxG,KAAK,EAAE,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;KAC5C,CAAC,CAAA;AACJ,CAAC","sourcesContent":["/**\n * A value or a function a configuration of JSON names, where JSON cannot hold it, and the code\n * that finds it: a set of named entries, as a tool gives some and a project adds its own, and a\n * reference to one of them, or to the export of a module. {@link resolveNamed} gives the value a\n * reference is; {@link resolveNamedSet} the entries of one set or of sets merged in order;\n * {@link factoryOf} the entry of a plain value, the options of a reference merged over it; and\n * {@link namedSchema} and {@link namedSetSchema} the schema of a reference and of a set, a\n * Standard Schema that checks it and gives its JSON Schema, so an editor completes the names.\n *\n * A reference is one of three forms:\n *\n * - `\"short\"`: the entry of that name;\n * - `{ \"format\": \"short\", \"width\": 60 }`: the entry of that name, by a key the caller chooses,\n * with the options beside it, which the entry is given;\n * - `{ \"module\": \"./formatters.mjs\", \"export\": \"wide\" }`: the export of a module, `default` by\n * default, as it is.\n *\n * Each entry is a factory of the value, `(options) => value`: a function, which takes the options\n * as it chooses, or a plain value, whose options are merged over it ({@link factoryOf}). A set is\n * a map of entries by name, the export of a module that is one, or an array of those, a later set\n * over an earlier one by name. A module is loaded by what the caller gives, Node's\n * `nodeLoadModule` of `@wtf/platform-node/module`, so this module runs on any platform. What fails is a `NamedError` of ./errors,\n * which names where: the path, from where the caller says the sets or the reference are, the index\n * of the set and the name of the entry, and the module and the export.\n *\n * ```ts\n * import { factoryOf, resolveNamed, resolveNamedSet } from '@wtf/project-config/named'\n *\n * type Format = { readonly width: number; readonly ellipsis: string }\n *\n * const formatters = await resolveNamedSet<Format>([\n * { short: factoryOf({ width: 40, ellipsis: '…' }) },\n * { wide: { width: 120, ellipsis: '' } }\n * ])\n * const format = await resolveNamed<Format>(\n * { format: 'short', width: 60 },\n * { key: 'format', names: formatters, kind: 'formatter' }\n * )\n * // { width: 60, ellipsis: '…' }\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec'\n\nimport { jsonSchemaOf } from './env.ts'\nimport { NamedError, type NamedErrorCode, type NamedErrorDetails } from './errors.ts'\nimport type { ConfigIssue, ConfigPath, JsonSchema, SectionSchema } from './index.ts'\nimport { issuesOf, issuesOfSync } from './section.ts'\nimport { textOfPath } from './text.ts'\n\n/**\n * The export of a module, as a configuration of JSON names it: the module, by what the loader\n * resolves, as a path from the root of the project or the name of a package, and the name of its\n * export, `default` by default.\n */\nexport type ModuleReference = {\n /** The module, as the loader resolves it: `./formatters.mjs`, or a package. */\n readonly module: string\n /** The name of its export: `default` by default. */\n readonly export?: string | undefined\n}\n\n/**\n * A reference to an entry by its name under the key `K`, with the options beside it, which the\n * entry is given: `{ \"format\": \"short\", \"width\": 60 }` of the key `format`. Of a key not known, as\n * `string`, any object of options.\n */\nexport type NamedUse<K extends string = string> = string extends K\n ? NamedOptions\n : { readonly [P in K]: string } & NamedOptions\n\n/**\n * A reference, as a configuration of JSON gives it: the name of an entry; the name under the key\n * `K`, with options; or the export of a module.\n */\nexport type NamedReference<K extends string = string> = string | NamedUse<K> | ModuleReference\n\n/** The options a reference gives an entry: each beside its name, but the key and any `undefined`. */\nexport type NamedOptions = Readonly<Record<string, unknown>>\n\n/** An entry of a set: what makes the value of the options a reference gives, none of a name alone. */\nexport type NamedFactory<T> = (options: NamedOptions) => T | Promise<T>\n\n/** The entries of a set, each a factory, by their names, as {@link resolveNamedSet} gives them. */\nexport type NamedEntries<T> = Readonly<Record<string, NamedFactory<T>>>\n\n/**\n * A set of entries, as a configuration gives it: a map of each by its name, a factory, a plain\n * value or the export of a module that is one of those; or the export of a module that is such a\n * map.\n */\nexport type NamedSet<T> =\n | ModuleReference\n | Readonly<Record<string, NamedFactory<T> | ModuleReference | T>>\n\n/** The sets of a configuration: one, or an array of them, merged in order, each over those before. */\nexport type NamedSets<T> = NamedSet<T> | readonly NamedSet<T>[]\n\n/**\n * What loads a module of a {@link ModuleReference}: the module of the text it names, as an object\n * of its exports, or a failure, which a `NamedError` of `UNLOADABLE_MODULE` holds as its cause.\n * Node's is `nodeLoadModule(root, beside?)` of `@wtf/platform-node/module`, whose `LoadModule` of\n * `@wtf/platform/module` is this one.\n */\nexport type LoadModule = (module: string) => Promise<unknown>\n\n/**\n * What a set and a reference are resolved by alike: the loader of their modules, the check of\n * their values, their kind, and where they are in the configuration.\n */\nexport type NamedCheckOptions<T> = {\n /** What loads each module named: none by default, of which a module is unloadable. */\n readonly load?: LoadModule | undefined\n /**\n * What checks a value: a Standard Schema, a JSON Schema or a function, as `issuesOf` of\n * ./section takes it. Of a set, each value an entry is, of a map or of a module, but a function,\n * whose results it checks too of `checkResults`; of a reference, the value it resolves to.\n */\n readonly check?: SectionSchema<T> | undefined\n /** What the entries are, which an error names: `entry` by default, as `formatter`. */\n readonly kind?: string | undefined\n /**\n * Where the sets, or the reference, are in the configuration, which the `at` of an error starts\n * with, and its message names, as `['formatters']`: none by default.\n */\n readonly at?: ConfigPath | undefined\n}\n\n/** How a set is resolved: as {@link NamedCheckOptions} say, and whether `check` checks what a\n * function entry gives. */\nexport type NamedSetOptions<T> = NamedCheckOptions<T> & {\n /**\n * Whether `check` checks too what each function entry gives, each time it is called, as it\n * checks a value entry once: no by default, of which a function entry is used as it is.\n */\n readonly checkResults?: boolean | undefined\n}\n\n/** How a reference is resolved: the key of its names, its entries, and what\n * {@link NamedCheckOptions} say. */\nexport type NamedResolveOptions<T> = NamedCheckOptions<T> & {\n /** The key a reference of options names its entry by, as `format`: none takes a name alone. */\n readonly key?: string | undefined\n /** The entries a reference names, by their names: none by default. */\n readonly names?: NamedEntries<T> | undefined\n}\n\n/** The schema of a reference or a set: a Standard Schema that checks it, and gives its JSON Schema. */\nexport type NamedSchema<T> = StandardSchemaV1<unknown, T> & StandardJSONSchemaV1<unknown, T>\n\n/** Whether `value` is an object of keys, as JSON's: no list, and no instance of a class. */\nconst isPlain = (value: unknown): value is Readonly<Record<string, unknown>> => {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) return false\n const prototype: unknown = Object.getPrototypeOf(value)\n return prototype === Object.prototype || prototype === null\n}\n\n/** Whether `value` is the export of a module: an object whose `module` is a text. */\nconst isModule = (value: unknown): value is ModuleReference =>\n isPlain(value) && typeof value['module'] === 'string'\n\n/** `word` after its article, `a` or `an`, as `an entry`. */\nconst article = (word: string): string => `${/^[aeiou]/i.test(word) ? 'an' : 'a'} ${word}`\n\n/** `text` of a capital first. */\nconst capital = (text: string): string => `${text.charAt(0).toUpperCase()}${text.slice(1)}`\n\n/** `value` as an error names it. */\nconst textOf = (value: unknown): string =>\n typeof value === 'function' ? 'a function' : (JSON.stringify(value) ?? String(value))\n\n/** The options of `options` that are given: each but those of `undefined`. */\nconst givenOf = (options: NamedOptions): NamedOptions =>\n Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))\n\n/**\n * The entry of `value`: of a plain object, `value` with the options a reference gives beside the\n * name merged over it, key by key, and those of `undefined` left out, so\n * `{ format: 'short', width: 60 }` gives `{ width: 60, ellipsis: '…' }` of\n * `{ width: 40, ellipsis: '…' }`; of any other value, the value, which takes no options, so options\n * given are a `NamedError` of `INVALID_NAMED_VALUE`. {@link resolveNamedSet} makes each value of a\n * set that is no function an entry so.\n */\nexport function factoryOf<T>(value: T): NamedFactory<T> {\n return (options) => {\n const given = givenOf(options)\n if (isPlain(value)) return { ...value, ...given } as T\n if (Object.keys(given).length === 0) return value\n throw new NamedError(\n 'INVALID_NAMED_VALUE',\n `${textOf(value)} takes no options, and is given ${Object.keys(given).join(', ')}.`\n )\n }\n}\n\n/** The text of the issues a check found. */\nconst issuesText = (issues: readonly ConfigIssue[]): string =>\n issues\n .map(({ path, message }) => (path.length === 0 ? message : `${path.join('.')}: ${message}`))\n .join('; ')\n\n/**\n * Where a value of the sets or a reference is, as a `NamedError` names it: its path; the path of\n * its set or its reference, which the message starts with, as the message names the entry itself;\n * the index of its set and the name of its entry; and what it is to be, as `the formatter wide`.\n */\ntype Place = {\n readonly at: ConfigPath\n readonly where: ConfigPath\n readonly set?: number | undefined\n readonly entry?: string | undefined\n readonly as?: string | undefined\n}\n\n/** The module and the export of `reference`, as a `NamedError` names them. */\nconst moduleDetails = (reference: ModuleReference): NamedErrorDetails => ({\n module: reference.module,\n export: reference.export ?? 'default'\n})\n\n/**\n * A `NamedError` of `code` at `place`: its message after the path of its set or its reference, of\n * one that is not empty, and the path, the set and the entry of the place beside `details`.\n */\nfunction namedError(\n code: NamedErrorCode,\n message: string,\n { at, where, set, entry }: Place,\n details: NamedErrorDetails = {},\n options?: ErrorOptions\n): NamedError {\n return new NamedError(\n code,\n where.length === 0 ? message : `${textOfPath(where)}: ${message}`,\n {\n ...details,\n at,\n ...(set === undefined ? {} : { set }),\n ...(entry === undefined ? {} : { entry })\n },\n options\n )\n}\n\n/**\n * `value`, checked by `check`, else a `NamedError` of `INVALID_NAMED_VALUE` at `place`, whose\n * message is `failing` and the issues, and `details` beside it.\n */\nasync function checked<T>(\n value: unknown,\n check: SectionSchema<T> | undefined,\n failing: string,\n place: Place,\n details: NamedErrorDetails = {}\n): Promise<T> {\n if (check === undefined) return value as T\n const { issues, value: read } = await issuesOf(value, check)\n if (issues.length === 0) return read\n throw namedError('INVALID_NAMED_VALUE', `${failing}: ${issuesText(issues)}.`, place, {\n ...details,\n issues\n })\n}\n\n/**\n * The export `reference.export`, `default` by default, of the module `reference.module`, loaded by\n * `load`: a `NamedError` at `place` of `UNLOADABLE_MODULE` of a module that fails to load, or of no\n * loader, and of `MISSING_EXPORT` of an export it has not, each of the module and the export.\n */\nasync function exportOf(\n reference: ModuleReference,\n load: LoadModule | undefined,\n place: Place\n): Promise<unknown> {\n const { module } = reference\n const name = reference.export ?? 'default'\n const details = moduleDetails(reference)\n const as = place.as === undefined ? '' : ` as ${place.as}`\n if (load === undefined)\n throw namedError(\n 'UNLOADABLE_MODULE',\n `The module ${module} cannot be loaded, for its export ${name}${as}: no loader of modules is given.`,\n place,\n details\n )\n let loaded: unknown\n try {\n loaded = await load(module)\n } catch (error) {\n throw namedError(\n 'UNLOADABLE_MODULE',\n `The module ${module} cannot be loaded, for its export ${name}${as}: ${error instanceof Error ? error.message : String(error)}`,\n place,\n details,\n { cause: error }\n )\n }\n const exports = loaded as Readonly<Record<string, unknown>> | null | undefined\n const found = typeof exports === 'object' && exports !== null ? exports[name] : undefined\n if (found === undefined)\n throw namedError(\n 'MISSING_EXPORT',\n `The module ${module} has no export ${name}${as}.`,\n place,\n details\n )\n return found\n}\n\n/** What a module's export is, as an error names it. */\nconst exportText = ({ module, export: name = 'default' }: ModuleReference): string =>\n `The export ${name} of ${module}`\n\n/**\n * The entry of `value` of the name `name`, at `place`: a function as it is, or, of `checkResults`,\n * one whose results `check` checks; else the value checked, of {@link factoryOf}.\n */\nasync function entryOf<T>(\n value: unknown,\n name: string,\n place: Place,\n { load, check, checkResults, kind = 'entry' }: NamedSetOptions<T>\n): Promise<NamedFactory<T>> {\n const reference = isModule(value) ? value : undefined\n const details = reference === undefined ? {} : moduleDetails(reference)\n const found =\n reference === undefined\n ? value\n : await exportOf(reference, load, { ...place, as: `the ${kind} ${name}` })\n const what =\n reference === undefined\n ? `The ${kind} ${name}`\n : `${exportText(reference)}, the ${kind} ${name},`\n if (typeof found === 'function') {\n const factory = found as NamedFactory<T>\n if (checkResults !== true || check === undefined) return factory\n return async (options) =>\n checked(\n await factory(options),\n check,\n `${what} gives a value that is not valid`,\n place,\n details\n )\n }\n return factoryOf(await checked(found, check, `${what} is not valid`, place, details))\n}\n\n/**\n * The entries of `sets`, each a factory, by their names: of each set in order, a map of entries by\n * name or the export of a module that is one, a later set over an earlier one by name, so a\n * project's own are over those of a package; none of `undefined`. Each entry is a function, a\n * factory as it is, or a plain value, checked by `check`, of {@link factoryOf}; or the export of\n * a module that is one of those, loaded by `load`. Of `checkResults`, `check` checks what each\n * function entry gives too, each time it is called. Each module is loaded at once, so a set that\n * fails does before any entry is used. Fails with a `NamedError` of `UNLOADABLE_MODULE` or\n * `MISSING_EXPORT` of a module, and of `INVALID_NAMED_VALUE` of a set that is no map, or a value\n * `check` refuses. The error names where it failed: its `at` is the path `at` gives, the index of\n * the set in an array of sets, its `set`, and the name of the entry, its `entry`, as\n * `['formatters', '1', 'wide']`, and its message starts with the path of the set; and its `module`\n * and `export` are those of a set or an entry a module exports.\n */\nexport async function resolveNamedSet<T>(\n sets: NamedSets<T> | undefined,\n options: NamedSetOptions<T> = {}\n): Promise<NamedEntries<T>> {\n const { at = [], kind = 'entry' } = options\n const many = Array.isArray(sets)\n const list: readonly unknown[] = sets === undefined ? [] : many ? sets : [sets]\n const resolved = await Promise.all(\n list.map(async (set, index) => {\n const of = many ? [...at, String(index)] : at\n const place: Place = { at: of, where: of, ...(many ? { set: index } : {}) }\n const reference = isModule(set) ? set : undefined\n const map =\n reference === undefined\n ? set\n : await exportOf(reference, options.load, { ...place, as: `a set of ${kind}s` })\n if (!isPlain(map))\n throw namedError(\n 'INVALID_NAMED_VALUE',\n `${reference === undefined ? textOf(set) : exportText(reference)} is no set: give an object of each ${kind} by its name.`,\n place,\n reference === undefined ? {} : moduleDetails(reference)\n )\n const entries = await Promise.all(\n Object.entries(map).map(async ([name, value]): Promise<[string, NamedFactory<T>]> => [\n name,\n await entryOf(value, name, { ...place, at: [...place.at, name], entry: name }, options)\n ])\n )\n return Object.fromEntries(entries)\n })\n )\n return Object.assign({}, ...resolved) as NamedEntries<T>\n}\n\n/** What `error` names but its place, as a `NamedError` that holds it gives it again. */\nconst detailsOf = (error: NamedError): NamedErrorDetails => ({\n ...(error.unknown === undefined ? {} : { name: error.unknown }),\n ...(error.module === undefined ? {} : { module: error.module }),\n ...(error.export === undefined ? {} : { export: error.export }),\n names: error.names,\n issues: error.issues\n})\n\n/**\n * The value `reference` is: of a name, the entry of that name of `names`, given no options; of an\n * object of the `key`, the entry of the name under it, given the options beside it but those of\n * `undefined`; of the export of a module, `{ module, export }`, the export as it is, loaded by\n * `load`. With a `check`, the value is checked by it. Fails with a `NamedError`: `UNKNOWN_NAME` of\n * a name of no entry, whose message lists the names there are; `UNLOADABLE_MODULE` and\n * `MISSING_EXPORT` of a module; and `INVALID_NAMED_VALUE` of a reference of none of the forms, or\n * a value `check` refuses. The error names where it failed: its `at` is the path `at` gives, which\n * its message starts with; its `entry` the name of the entry whose value fails, or which fails as\n * it is given its options; and its `module` and `export` those of a reference to a module.\n */\nexport async function resolveNamed<T>(\n reference: NamedReference,\n { key, names = {}, load, check, kind = 'entry', at = [] }: NamedResolveOptions<T> = {}\n): Promise<T> {\n const place: Place = { at, where: at }\n const use: unknown = reference\n if (isModule(use) && (key === undefined || !(key in use)))\n return checked(\n await exportOf(use, load, place),\n check,\n `${exportText(use)} is not valid`,\n place,\n moduleDetails(use)\n )\n const named =\n typeof use === 'string'\n ? { name: use, options: {} }\n : isPlain(use) && key !== undefined && typeof use[key] === 'string'\n ? (() => {\n const { [key]: name, ...options } = use\n return { name: name as string, options: givenOf(options) }\n })()\n : undefined\n if (named === undefined)\n throw namedError(\n 'INVALID_NAMED_VALUE',\n `${textOf(use)} is no reference of ${article(kind)}: give its name${key === undefined ? '' : `, { \"${key}\": name, … }`} or { \"module\": …, \"export\": … }.`,\n place\n )\n const { name, options } = named\n if (!Object.hasOwn(names, name)) {\n const known = Object.keys(names)\n throw namedError(\n 'UNKNOWN_NAME',\n `No ${kind} is named ${JSON.stringify(name)}: the names are ${known.length === 0 ? 'none' : known.join(', ')}.`,\n place,\n { name, names: known }\n )\n }\n const entry = names[name] as NamedFactory<T>\n const of: Place = { ...place, entry: name }\n let value: unknown\n try {\n value = await entry(options)\n } catch (error) {\n if (!(error instanceof NamedError) || error.entry !== undefined) throw error\n throw namedError(\n error.code,\n `The ${kind} ${name} fails: ${error.message}`,\n of,\n detailsOf(error),\n { cause: error }\n )\n }\n return checked(value, check, `The ${kind} ${name} is not valid`, of)\n}\n\n/** The JSON Schema of the export of a module. */\nconst MODULE_SCHEMA = {\n description: 'The export of a module: `default` by default.',\n type: 'object',\n properties: {\n module: {\n description: 'The module: a path from the root, or a package.',\n type: 'string',\n minLength: 1\n },\n export: {\n description: 'The name of its export: `default` by default.',\n type: 'string',\n minLength: 1\n }\n },\n required: ['module'],\n additionalProperties: false\n} as const\n\n/** The JSON Schema of a name: a text, of the `names` an editor completes. */\nconst nameSchema = (kind: string, names: readonly string[] | undefined): JsonSchema => ({\n description: `The name of ${article(kind)}.`,\n type: 'string',\n minLength: 1,\n ...(names === undefined || names.length === 0 ? {} : { examples: [...names] })\n})\n\n/** The JSON Schema of `schema`, as an object of its keywords: `{}`, any value, of none. */\nconst objectSchemaOf = (schema: SectionSchema | undefined): Readonly<Record<string, unknown>> => {\n const json = schema === undefined ? undefined : jsonSchemaOf(schema)\n if (json === undefined || json === true) return {}\n if (json === false) return { not: {} }\n const { $schema: _draft, $id: _id, ...rest } = json\n return rest\n}\n\n/**\n * The schema of `json`, of the type `T`: it checks a value by ajv, as `issuesOfSync` of ./section\n * checks a JSON Schema, and gives `json`, of draft 2020-12, as the JSON Schema of its input and\n * output alike.\n */\nfunction schemaOf<T>(json: Readonly<Record<string, unknown>>): NamedSchema<T> {\n const jsonSchema = (): Record<string, unknown> => ({ ...json })\n return {\n '~standard': {\n version: 1,\n vendor: '@wtf/project-config',\n validate: (value) => {\n const { issues } = issuesOfSync(value, json)\n return issues.length === 0\n ? { value: value as T }\n : { issues: issues.map(({ path, message }) => ({ path, message })) }\n },\n jsonSchema: { input: jsonSchema, output: jsonSchema }\n }\n }\n}\n\n/** What the schema of a reference says of it. */\nexport type NamedSchemaOptions = {\n /** The names an editor completes: those of the entries there are. */\n readonly names?: readonly string[] | undefined\n /**\n * The schema of the options beside a name, as each entry takes them: a JSON Schema, or a\n * Standard Schema that gives one, of an object, whose `properties` are each an option. Any by\n * default.\n */\n readonly options?: SectionSchema | undefined\n /** What the entries are, which the descriptions name: `entry` by default. */\n readonly kind?: string | undefined\n}\n\n/**\n * The schema of a reference of the key `key`: a name, of `names`, which an editor completes;\n * `{ [key]: name, … }`, with the options of `options` beside it, each optional, as they are over\n * the entry's own; or `{ module, export }`. Its JSON Schema, which `input()` of its\n * `~standard.jsonSchema` gives, holds no `$schema`, so it goes in a tool's own as it is.\n */\nexport function namedSchema<K extends string>(\n key: K,\n { names, options, kind = 'entry' }: NamedSchemaOptions = {}\n): NamedSchema<NamedReference<K>> {\n const name = nameSchema(kind, names)\n const { properties, required: _required, type: _type, ...rest } = objectSchemaOf(options)\n return schemaOf({\n description: `${capital(article(kind))}: its name, { \"${key}\": name, … } with options over its own, or the export of a module.`,\n anyOf: [\n name,\n {\n ...rest,\n description: `${capital(article(kind))} by its name, with options over its own.`,\n type: 'object',\n properties: { ...(isPlain(properties) ? properties : {}), [key]: name },\n required: [key]\n },\n MODULE_SCHEMA\n ]\n })\n}\n\n/** What the schema of a set says of it. */\nexport type NamedSetSchemaOptions = {\n /** The schema of the value of an entry: a JSON Schema, or a Standard Schema that gives one. Any by default. */\n readonly entry?: SectionSchema | undefined\n /** What the entries are, which the descriptions name: `entry` by default. */\n readonly kind?: string | undefined\n}\n\n/**\n * The schema of the sets of entries: a set, or an array of sets, merged in order; each set the\n * export of a module, or a map of each entry by its name, of `entry`, or the export of a module.\n * Its JSON Schema holds no `$schema`, as {@link namedSchema}'s.\n */\nexport function namedSetSchema({ entry, kind = 'entry' }: NamedSetSchemaOptions = {}): NamedSchema<\n NamedSets<unknown>\n> {\n const set = {\n description: `A set of ${kind}s: a map of each by its name, or the export of a module that is one.`,\n anyOf: [\n MODULE_SCHEMA,\n {\n type: 'object',\n additionalProperties: { anyOf: [MODULE_SCHEMA, objectSchemaOf(entry)] }\n }\n ]\n }\n return schemaOf({\n description: `The sets of ${kind}s: a set, or an array of sets merged in order, each over those before.`,\n anyOf: [set, { type: 'array', items: set }]\n })\n}\n"]}
package/dist/section.d.ts CHANGED
@@ -25,15 +25,9 @@ export declare function issuesOfSync<T>(value: unknown, schema: SectionSchema<T>
25
25
  * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for
26
26
  * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of
27
27
  * ./placeholder); a variable not set, or of a configuration read of no environment, is an
28
- * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or
29
- * writes the configuration never holds a secret it points at. With a `schema` it is checked, and
30
- * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the
31
- * path of each value, as `wtf.vite.compress`.
28
+ * `EnvPlaceholderUnsetError`. Only this expands them, so what shows or writes the configuration
29
+ * never holds a secret it points at. With a `schema` it is checked, and what is wrong is an
30
+ * {@link InvalidSectionError}, which names where the value came from and the path of each value,
31
+ * as `wtf.vite.compress`.
32
32
  */
33
33
  export declare function sectionOf<T = unknown>(resolved: ResolvedConfig, name: string, schema?: SectionSchema<T>): Promise<T | undefined>;
34
- /**
35
- * The section `name` of the configuration, as {@link sectionOf} reads it, checked synchronously,
36
- * as a tool that reads its config synchronously reads it with `loadConfigSync` of ./load. A schema
37
- * that checks asynchronously is a {@link SyncSchemaError}.
38
- */
39
- export declare function sectionOfSync<T = unknown>(resolved: ResolvedConfig, name: string, schema?: SectionSchema<T>): T | undefined;
package/dist/section.js CHANGED
@@ -134,10 +134,10 @@ function invalidOf(resolved, name, { own, environment }, issues) {
134
134
  * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for
135
135
  * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of
136
136
  * ./placeholder); a variable not set, or of a configuration read of no environment, is an
137
- * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or
138
- * writes the configuration never holds a secret it points at. With a `schema` it is checked, and
139
- * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the
140
- * path of each value, as `wtf.vite.compress`.
137
+ * `EnvPlaceholderUnsetError`. Only this expands them, so what shows or writes the configuration
138
+ * never holds a secret it points at. With a `schema` it is checked, and what is wrong is an
139
+ * {@link InvalidSectionError}, which names where the value came from and the path of each value,
140
+ * as `wtf.vite.compress`.
141
141
  */
142
142
  export async function sectionOf(resolved, name, schema) {
143
143
  const layered = layeredOf(resolved, name, schema);
@@ -150,20 +150,4 @@ export async function sectionOf(resolved, name, schema) {
150
150
  return value;
151
151
  throw invalidOf(resolved, name, layered, issues);
152
152
  }
153
- /**
154
- * The section `name` of the configuration, as {@link sectionOf} reads it, checked synchronously,
155
- * as a tool that reads its config synchronously reads it with `loadConfigSync` of ./load. A schema
156
- * that checks asynchronously is a {@link SyncSchemaError}.
157
- */
158
- export function sectionOfSync(resolved, name, schema) {
159
- const layered = layeredOf(resolved, name, schema);
160
- if (!layered.given)
161
- return undefined;
162
- if (schema === undefined)
163
- return layered.section;
164
- const { issues, value } = issuesOfSync(layered.section, schema, name);
165
- if (issues.length === 0)
166
- return value;
167
- throw invalidOf(resolved, name, layered, issues);
168
- }
169
153
  //# sourceMappingURL=section.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"section.js","sourceRoot":"","sources":["../src/section.ts"],"names":[],"mappings":"AA2BA,OAAO,EAAE,OAAO,EAA2C,MAAM,kBAAkB,CAAA;AAEnF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,eAAe,EAAwB,MAAM,UAAU,CAAA;AACzF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AASlE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAMzC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAoC,EAAE,CAClE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAA;AAE7C,4FAA4F;AAC5F,MAAM,WAAW,GAAG,CAAC,MAAe,EAA6C,EAAE;IACjF,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,C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QAAwB,EACxB,IAAY,EACZ,MAAyB;IAEzB,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACjD,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAY,CAAA;IACrD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IACrE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC","sourcesContent":["/**\n * A tool's section of the configuration: {@link sectionOf}, the section of a name, the project's\n * merged over the defaults of the tool's package ({@link mergeSection}), with the environment's\n * variables the tool gives over both, each placeholder `${env:NAME}` in it replaced by the variable\n * it names, and checked by the schema the tool gives; {@link sectionOfSync}, the same, checked\n * synchronously; and {@link issuesOf} and {@link issuesOfSync}, what a schema finds wrong with a\n * value. A schema is a Standard Schema, as each preset's `./schema` exports one, a JSON Schema or a\n * Standard JSON Schema, which ajv checks, or a function. What is wrong is an\n * `InvalidSectionError` of ./errors, which names the file and the path of each value.\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfig } from '@wtf/project-config/load'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { baseConfig } from '@wtf/project-vite/config'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const config = await loadConfig({ platform })\n * export default baseConfig({ platform, ...(await sectionOf(config, 'vite', viteSchema)) })\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\nimport { Ajv2020, type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js'\n\nimport { envNameOf, jsonSchemaOf, withEnvironment, type WithEnvironment } from './env.ts'\nimport { InvalidSectionError, SyncSchemaError } from './errors.ts'\nimport type {\n ConfigIssue,\n ConfigPath,\n JsonSchema,\n ResolvedConfig,\n SectionSchema,\n ValidateSection\n} from './index.ts'\nimport { mergeSection } from './merge.ts'\nimport { expandPlaceholders } from './placeholder.ts'\n\nexport { mergeSection } from './merge.ts'\n\n/** What a schema found of a value: what is wrong with it, none when it is valid, and the value as\n * the schema reads it. */\nexport type Checked<T> = { readonly issues: readonly ConfigIssue[]; readonly value: T }\n\nconst isNode = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n\n/** Whether `schema` is a Standard Schema that validates: its `~standard` has `validate`. */\nconst validatorOf = (schema: unknown): StandardSchemaV1['~standard'] | undefined => {\n if (!isNode(schema) || !('~standard' in schema)) return undefined\n const standard = schema['~standard']\n return isNode(standard) && typeof standard['validate'] === 'function'\n ? (standard as unknown as StandardSchemaV1['~standard'])\n : undefined\n}\n\n/**\n * The JSON Schemas compiled, by ajv, for draft 2020-12: every fault and not the first, no check\n * of a `format`, and the keywords of an editor's own, as `markdownDescription`, taken.\n */\nlet ajv: Ajv2020 | undefined\nconst compiled = new WeakMap<object, ValidateFunction>()\n\nconst compile = (schema: JsonSchema): ValidateFunction => {\n ajv ??= new Ajv2020({ allErrors: true, strict: false, validateFormats: false, logger: false })\n if (typeof schema === 'boolean') return ajv.compile(schema)\n let validate = compiled.get(schema)\n if (validate === undefined) {\n validate = ajv.compile(schema)\n compiled.set(schema, validate)\n }\n return validate\n}\n\n/** The keys of a JSON Pointer, as ajv gives the place of a value: `/compress/threshold`. */\nconst keysOfPointer = (pointer: string): string[] =>\n pointer === ''\n ? []\n : pointer\n .slice(1)\n .split('/')\n .map((key) => key.replaceAll('~1', '/').replaceAll('~0', '~'))\n\n/** What ajv found wrong, as an issue: a key the schema does not take at its own path. */\nconst issueOfAjv = ({ instancePath, keyword, params, message }: ErrorObject): ConfigIssue => {\n const path = keysOfPointer(instancePath)\n const extra: unknown =\n keyword === 'additionalProperties' ? params['additionalProperty'] : undefined\n return typeof extra === 'string'\n ? { path: [...path, extra], message: 'is no key that the section takes' }\n : { path, message: message ?? keyword }\n}\n\n/** The keys of a Standard Schema's path, each as text. */\nconst pathOfStandard = (path: StandardSchemaV1.Issue['path']): ConfigPath =>\n (path ?? []).map((segment) =>\n String(typeof segment === 'object' && segment !== null ? segment.key : segment)\n )\n\n/** What a Standard Schema's result says, as issues. */\nconst checkedOfResult = <T>(result: StandardSchemaV1.Result<T>, value: unknown): Checked<T> =>\n result.issues === undefined\n ? { issues: [], value: result.value }\n : {\n issues: result.issues.map(({ path, message }) => ({ path: pathOfStandard(path), message })),\n value: value as T\n }\n\n/** What ajv finds wrong with `value` by the JSON Schema of `schema`; nothing of a schema that gives\n * none. */\nconst checkedOfJson = <T>(value: unknown, schema: unknown): Checked<T> => {\n const json = jsonSchemaOf(schema)\n if (json === undefined) return { issues: [], value: value as T }\n const validate = compile(json)\n validate(value)\n return { issues: (validate.errors ?? []).map(issueOfAjv), value: value as T }\n}\n\n/**\n * What `schema` finds wrong with `value`, none when it is valid, and the value as it reads it: a\n * Standard Schema's output, or `value` itself. A Standard Schema that validates is asked; a JSON\n * Schema, or a Standard JSON Schema of none, is checked by ajv; a function is called.\n */\nexport async function issuesOf<T>(value: unknown, schema: SectionSchema<T>): Promise<Checked<T>> {\n if (typeof schema === 'function')\n return { issues: await (schema as ValidateSection)(value), value: value as T }\n const standard = validatorOf(schema)\n if (standard !== undefined)\n return checkedOfResult((await standard.validate(value)) as StandardSchemaV1.Result<T>, value)\n return checkedOfJson(value, schema)\n}\n\n/**\n * What `schema` finds wrong with `value`, as {@link issuesOf} checks it, checked synchronously: a\n * schema that answers with a promise is a {@link SyncSchemaError} of the section `section`.\n */\nexport function issuesOfSync<T>(\n value: unknown,\n schema: SectionSchema<T>,\n section: string = 'configuration'\n): Checked<T> {\n if (typeof schema === 'function') {\n const issues = (schema as ValidateSection)(value)\n if (issues instanceof Promise) throw new SyncSchemaError(section)\n return { issues, value: value as T }\n }\n const standard = validatorOf(schema)\n if (standard !== undefined) {\n const result = standard.validate(value)\n if (result instanceof Promise) throw new SyncSchemaError(section)\n return checkedOfResult(result as StandardSchemaV1.Result<T>, value)\n }\n return checkedOfJson(value, schema)\n}\n\n/** Whether `path` is `under` or a path under it. */\nconst isUnder = (path: ConfigPath, under: ConfigPath): boolean =>\n under.every((key, index) => path[index] === key)\n\n/** The section of `name` as the layers give it, before it is checked, and whether any gave one. */\ntype Layered = {\n readonly section: unknown\n readonly given: boolean\n readonly own: boolean\n readonly environment: WithEnvironment\n}\n\n/** The section `name` of the layers of `resolved`, read for placeholders, before it is checked. */\nfunction layeredOf(resolved: ResolvedConfig, name: string, schema: unknown): Layered {\n const own = Object.hasOwn(resolved.config, name)\n const defaults = resolved.defaults?.config\n const layered = defaults !== undefined && Object.hasOwn(defaults, name)\n const filed = mergeSection(layered ? defaults[name] : undefined, resolved.config[name])\n const environment =\n resolved.environment === undefined\n ? { value: filed, set: [] }\n : withEnvironment(\n filed,\n resolved.environment.variables,\n `${resolved.environment.prefix}${envNameOf(name)}_`,\n jsonSchemaOf(schema)\n )\n const given = own || layered || environment.set.length > 0\n // No environment given is one of no variable: each placeholder is refused, never left as text.\n const section = given\n ? expandPlaceholders(\n environment.value,\n [resolved.key, name],\n resolved.environment?.values ?? {}\n )\n : undefined\n return { section, given, own, environment }\n}\n\n/** The error of what a schema found wrong with a section: of the variables that set a value it\n * refuses, else of the project's file, or the defaults', of a section the project gives none of. */\nfunction invalidOf(\n resolved: ResolvedConfig,\n name: string,\n { own, environment }: Layered,\n issues: readonly ConfigIssue[]\n): InvalidSectionError {\n const variables = environment.set.filter(({ path }) =>\n issues.some((issue) => isUnder(issue.path, path))\n )\n if (variables.length > 0)\n return new InvalidSectionError(\n variables.map(({ variable }) => variable).join(', '),\n resolved.namespace,\n name,\n issues.filter((issue) => variables.some(({ path }) => isUnder(issue.path, path))),\n resolved.key\n )\n return own || resolved.defaults === undefined\n ? new InvalidSectionError(\n resolved.source?.path ?? resolved.root,\n resolved.namespace,\n name,\n issues,\n resolved.key\n )\n : new InvalidSectionError(resolved.defaults.path, resolved.namespace, name, issues)\n}\n\n/**\n * The section `name` of the configuration, as its tool reads it: the project's, merged over the\n * section of the `defaults` of the tool's package when it gives some ({@link mergeSection}), with\n * the variables of the environment of the platform the tool gave `loadConfig` over both, each that\n * names a key of the section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of\n * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for\n * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of\n * ./placeholder); a variable not set, or of a configuration read of no environment, is an\n * `EnvPlaceholderUnsetError`. Only this, and {@link sectionOfSync}, expand them, so what shows or\n * writes the configuration never holds a secret it points at. With a `schema` it is checked, and\n * what is wrong is an {@link InvalidSectionError}, which names where the value came from and the\n * path of each value, as `wtf.vite.compress`.\n */\nexport async function sectionOf<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): Promise<T | undefined> {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = await issuesOf(layered.section, schema)\n if (issues.length === 0) return value\n throw invalidOf(resolved, name, layered, issues)\n}\n\n/**\n * The section `name` of the configuration, as {@link sectionOf} reads it, checked synchronously,\n * as a tool that reads its config synchronously reads it with `loadConfigSync` of ./load. A schema\n * that checks asynchronously is a {@link SyncSchemaError}.\n */\nexport function sectionOfSync<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): T | undefined {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = issuesOfSync(layered.section, schema, name)\n if (issues.length === 0) return value\n throw invalidOf(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IAAI,EAAE,MAAM,CAAC,CAAA;AACvF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAAwB,EACxB,IAAY,EACZ,MAAyB;IAEzB,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;IACjD,IAAI,CAAC,OAAO,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IACpC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC,OAAY,CAAA;IACrD,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACjE,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACrC,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAClD,CAAC","sourcesContent":["/**\n * A tool's section of the configuration: {@link sectionOf}, the section of a name, the project's\n * merged over the defaults of the tool's package ({@link mergeSection}), with the environment's\n * variables the tool gives over both, each placeholder `${env:NAME}` in it replaced by the variable\n * it names, and checked by the schema the tool gives; and {@link issuesOf} and\n * {@link issuesOfSync}, what a schema finds wrong with a value. A schema is a Standard Schema, as\n * each preset's `./schema` exports one, a JSON Schema or a Standard JSON Schema, which ajv checks,\n * or a function. What is wrong is an\n * `InvalidSectionError` of ./errors, which names the file and the path of each value.\n *\n * ```ts\n * import { nodeStorage } from '@wtf/platform-fs-node/storage'\n * import { nodePlatform } from '@wtf/platform-node/platform'\n *\n * import { loadConfig } from '@wtf/project-config/load'\n * import { sectionOf } from '@wtf/project-config/section'\n * import { baseConfig } from '@wtf/project-vite/config'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const platform = nodePlatform({ fetch, storage: nodeStorage() })\n * const config = await loadConfig({ platform })\n * export default baseConfig({ platform, ...(await sectionOf(config, 'vite', viteSchema)) })\n * ```\n *\n * @packageDocumentation\n */\nimport type { StandardSchemaV1 } from '@standard-schema/spec'\nimport { Ajv2020, type ErrorObject, type ValidateFunction } from 'ajv/dist/2020.js'\n\nimport { envNameOf, jsonSchemaOf, withEnvironment, type WithEnvironment } from './env.ts'\nimport { InvalidSectionError, SyncSchemaError } from './errors.ts'\nimport type {\n ConfigIssue,\n ConfigPath,\n JsonSchema,\n ResolvedConfig,\n SectionSchema,\n ValidateSection\n} from './index.ts'\nimport { mergeSection } from './merge.ts'\nimport { expandPlaceholders } from './placeholder.ts'\n\nexport { mergeSection } from './merge.ts'\n\n/** What a schema found of a value: what is wrong with it, none when it is valid, and the value as\n * the schema reads it. */\nexport type Checked<T> = { readonly issues: readonly ConfigIssue[]; readonly value: T }\n\nconst isNode = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null\n\n/** Whether `schema` is a Standard Schema that validates: its `~standard` has `validate`. */\nconst validatorOf = (schema: unknown): StandardSchemaV1['~standard'] | undefined => {\n if (!isNode(schema) || !('~standard' in schema)) return undefined\n const standard = schema['~standard']\n return isNode(standard) && typeof standard['validate'] === 'function'\n ? (standard as unknown as StandardSchemaV1['~standard'])\n : undefined\n}\n\n/**\n * The JSON Schemas compiled, by ajv, for draft 2020-12: every fault and not the first, no check\n * of a `format`, and the keywords of an editor's own, as `markdownDescription`, taken.\n */\nlet ajv: Ajv2020 | undefined\nconst compiled = new WeakMap<object, ValidateFunction>()\n\nconst compile = (schema: JsonSchema): ValidateFunction => {\n ajv ??= new Ajv2020({ allErrors: true, strict: false, validateFormats: false, logger: false })\n if (typeof schema === 'boolean') return ajv.compile(schema)\n let validate = compiled.get(schema)\n if (validate === undefined) {\n validate = ajv.compile(schema)\n compiled.set(schema, validate)\n }\n return validate\n}\n\n/** The keys of a JSON Pointer, as ajv gives the place of a value: `/compress/threshold`. */\nconst keysOfPointer = (pointer: string): string[] =>\n pointer === ''\n ? []\n : pointer\n .slice(1)\n .split('/')\n .map((key) => key.replaceAll('~1', '/').replaceAll('~0', '~'))\n\n/** What ajv found wrong, as an issue: a key the schema does not take at its own path. */\nconst issueOfAjv = ({ instancePath, keyword, params, message }: ErrorObject): ConfigIssue => {\n const path = keysOfPointer(instancePath)\n const extra: unknown =\n keyword === 'additionalProperties' ? params['additionalProperty'] : undefined\n return typeof extra === 'string'\n ? { path: [...path, extra], message: 'is no key that the section takes' }\n : { path, message: message ?? keyword }\n}\n\n/** The keys of a Standard Schema's path, each as text. */\nconst pathOfStandard = (path: StandardSchemaV1.Issue['path']): ConfigPath =>\n (path ?? []).map((segment) =>\n String(typeof segment === 'object' && segment !== null ? segment.key : segment)\n )\n\n/** What a Standard Schema's result says, as issues. */\nconst checkedOfResult = <T>(result: StandardSchemaV1.Result<T>, value: unknown): Checked<T> =>\n result.issues === undefined\n ? { issues: [], value: result.value }\n : {\n issues: result.issues.map(({ path, message }) => ({ path: pathOfStandard(path), message })),\n value: value as T\n }\n\n/** What ajv finds wrong with `value` by the JSON Schema of `schema`; nothing of a schema that gives\n * none. */\nconst checkedOfJson = <T>(value: unknown, schema: unknown): Checked<T> => {\n const json = jsonSchemaOf(schema)\n if (json === undefined) return { issues: [], value: value as T }\n const validate = compile(json)\n validate(value)\n return { issues: (validate.errors ?? []).map(issueOfAjv), value: value as T }\n}\n\n/**\n * What `schema` finds wrong with `value`, none when it is valid, and the value as it reads it: a\n * Standard Schema's output, or `value` itself. A Standard Schema that validates is asked; a JSON\n * Schema, or a Standard JSON Schema of none, is checked by ajv; a function is called.\n */\nexport async function issuesOf<T>(value: unknown, schema: SectionSchema<T>): Promise<Checked<T>> {\n if (typeof schema === 'function')\n return { issues: await (schema as ValidateSection)(value), value: value as T }\n const standard = validatorOf(schema)\n if (standard !== undefined)\n return checkedOfResult((await standard.validate(value)) as StandardSchemaV1.Result<T>, value)\n return checkedOfJson(value, schema)\n}\n\n/**\n * What `schema` finds wrong with `value`, as {@link issuesOf} checks it, checked synchronously: a\n * schema that answers with a promise is a {@link SyncSchemaError} of the section `section`.\n */\nexport function issuesOfSync<T>(\n value: unknown,\n schema: SectionSchema<T>,\n section: string = 'configuration'\n): Checked<T> {\n if (typeof schema === 'function') {\n const issues = (schema as ValidateSection)(value)\n if (issues instanceof Promise) throw new SyncSchemaError(section)\n return { issues, value: value as T }\n }\n const standard = validatorOf(schema)\n if (standard !== undefined) {\n const result = standard.validate(value)\n if (result instanceof Promise) throw new SyncSchemaError(section)\n return checkedOfResult(result as StandardSchemaV1.Result<T>, value)\n }\n return checkedOfJson(value, schema)\n}\n\n/** Whether `path` is `under` or a path under it. */\nconst isUnder = (path: ConfigPath, under: ConfigPath): boolean =>\n under.every((key, index) => path[index] === key)\n\n/** The section of `name` as the layers give it, before it is checked, and whether any gave one. */\ntype Layered = {\n readonly section: unknown\n readonly given: boolean\n readonly own: boolean\n readonly environment: WithEnvironment\n}\n\n/** The section `name` of the layers of `resolved`, read for placeholders, before it is checked. */\nfunction layeredOf(resolved: ResolvedConfig, name: string, schema: unknown): Layered {\n const own = Object.hasOwn(resolved.config, name)\n const defaults = resolved.defaults?.config\n const layered = defaults !== undefined && Object.hasOwn(defaults, name)\n const filed = mergeSection(layered ? defaults[name] : undefined, resolved.config[name])\n const environment =\n resolved.environment === undefined\n ? { value: filed, set: [] }\n : withEnvironment(\n filed,\n resolved.environment.variables,\n `${resolved.environment.prefix}${envNameOf(name)}_`,\n jsonSchemaOf(schema)\n )\n const given = own || layered || environment.set.length > 0\n // No environment given is one of no variable: each placeholder is refused, never left as text.\n const section = given\n ? expandPlaceholders(\n environment.value,\n [resolved.key, name],\n resolved.environment?.values ?? {}\n )\n : undefined\n return { section, given, own, environment }\n}\n\n/** The error of what a schema found wrong with a section: of the variables that set a value it\n * refuses, else of the project's file, or the defaults', of a section the project gives none of. */\nfunction invalidOf(\n resolved: ResolvedConfig,\n name: string,\n { own, environment }: Layered,\n issues: readonly ConfigIssue[]\n): InvalidSectionError {\n const variables = environment.set.filter(({ path }) =>\n issues.some((issue) => isUnder(issue.path, path))\n )\n if (variables.length > 0)\n return new InvalidSectionError(\n variables.map(({ variable }) => variable).join(', '),\n resolved.namespace,\n name,\n issues.filter((issue) => variables.some(({ path }) => isUnder(issue.path, path))),\n resolved.key\n )\n return own || resolved.defaults === undefined\n ? new InvalidSectionError(\n resolved.source?.path ?? resolved.root,\n resolved.namespace,\n name,\n issues,\n resolved.key\n )\n : new InvalidSectionError(resolved.defaults.path, resolved.namespace, name, issues)\n}\n\n/**\n * The section `name` of the configuration, as its tool reads it: the project's, merged over the\n * section of the `defaults` of the tool's package when it gives some ({@link mergeSection}), with\n * the variables of the environment of the platform the tool gave `loadConfig` over both, each that\n * names a key of the section or of its schema, as `WTF_VITE_COMPRESS` (`withEnvironment` of\n * ./env); `undefined` when none has one, which the tool takes as its own defaults. Each string in it is then read for\n * placeholders `${env:NAME}`, taken from that whole environment (`expandPlaceholders` of\n * ./placeholder); a variable not set, or of a configuration read of no environment, is an\n * `EnvPlaceholderUnsetError`. Only this expands them, so what shows or writes the configuration\n * never holds a secret it points at. With a `schema` it is checked, and what is wrong is an\n * {@link InvalidSectionError}, which names where the value came from and the path of each value,\n * as `wtf.vite.compress`.\n */\nexport async function sectionOf<T = unknown>(\n resolved: ResolvedConfig,\n name: string,\n schema?: SectionSchema<T>\n): Promise<T | undefined> {\n const layered = layeredOf(resolved, name, schema)\n if (!layered.given) return undefined\n if (schema === undefined) return layered.section as T\n const { issues, value } = await issuesOf(layered.section, schema)\n if (issues.length === 0) return value\n throw invalidOf(resolved, name, layered, issues)\n}\n"]}