@wtf/project-config 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/schema.d.ts +3 -2
- package/dist/schema.js +5 -3
- package/dist/schema.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,9 @@ not set throws an `EnvPlaceholderUnsetError`, which never shows a value.
|
|
|
65
65
|
`./schema` exports, or zod's), a JSON Schema or a Standard JSON Schema (checked by ajv), or a
|
|
66
66
|
function. What is wrong is an `InvalidSectionError` that names the file, or the variable, and the
|
|
67
67
|
path of each value. `namespaceSchema('wtf', { vite: viteSchema, … })` gives the JSON Schema of the
|
|
68
|
-
whole file, for `$schema` in `wtf.config.json`.
|
|
68
|
+
whole file, for `$schema` in `wtf.config.json`. A key that starts with `//` is a comment: the
|
|
69
|
+
JSON Schema of the whole takes one beside the sections, and each preset's schema in its section,
|
|
70
|
+
which it leaves out of the options it gives.
|
|
69
71
|
|
|
70
72
|
## Any platform
|
|
71
73
|
|
package/dist/schema.d.ts
CHANGED
|
@@ -15,8 +15,9 @@ export type NamespaceSchemaOptions = {
|
|
|
15
15
|
* The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema
|
|
16
16
|
* of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and
|
|
17
17
|
* the presets' do, of its input. It is an object with each section at its property, checked by its
|
|
18
|
-
* schema; the `$schema` key, by which a file names its schema;
|
|
19
|
-
*
|
|
18
|
+
* schema; the `$schema` key, by which a file names its schema; a key that starts with `//`, a
|
|
19
|
+
* comment, as each preset's options take one; and any other key as it is. A schema that gives no
|
|
20
|
+
* JSON Schema, as a function, takes any value.
|
|
20
21
|
*/
|
|
21
22
|
export declare function namespaceSchema(namespace: string, sections: Readonly<Record<string, SectionSchema>>, { title, description }?: NamespaceSchemaOptions): {
|
|
22
23
|
readonly [keyword: string]: unknown;
|
package/dist/schema.js
CHANGED
|
@@ -35,8 +35,9 @@ function sectionSchema(namespace, name, schema) {
|
|
|
35
35
|
* The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema
|
|
36
36
|
* of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and
|
|
37
37
|
* the presets' do, of its input. It is an object with each section at its property, checked by its
|
|
38
|
-
* schema; the `$schema` key, by which a file names its schema;
|
|
39
|
-
*
|
|
38
|
+
* schema; the `$schema` key, by which a file names its schema; a key that starts with `//`, a
|
|
39
|
+
* comment, as each preset's options take one; and any other key as it is. A schema that gives no
|
|
40
|
+
* JSON Schema, as a function, takes any value.
|
|
40
41
|
*/
|
|
41
42
|
export function namespaceSchema(namespace, sections, { title = `The ${namespace} configuration`, description = 'The configuration of the tools of a project: a section of each tool, by its name.' } = {}) {
|
|
42
43
|
return {
|
|
@@ -50,7 +51,8 @@ export function namespaceSchema(namespace, sections, { title = `The ${namespace}
|
|
|
50
51
|
name,
|
|
51
52
|
sectionSchema(namespace, name, schema)
|
|
52
53
|
]))
|
|
53
|
-
}
|
|
54
|
+
},
|
|
55
|
+
patternProperties: { '^//': { description: 'A comment, which the tools leave out.' } }
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
58
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAGvC,8FAA8F;AAC9F,MAAM,CAAC,MAAM,iBAAiB,GAAG,8CAA8C,CAAA;AAE/E;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAAiB,EAAE,IAAY,EAAU,EAAE,CAAC,OAAO,SAAS,IAAI,IAAI,EAAE,CAAA;AAQlG;kEACkE;AAClE,SAAS,aAAa,CAAC,SAAiB,EAAE,I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,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,CAAA;AAChG,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAC7B,SAAiB,EACjB,QAAiD,EACjD,EACE,KAAK,GAAG,OAAO,SAAS,gBAAgB,EACxC,WAAW,GAAG,mFAAmF,KACvE,EAAE;IAE9B,OAAO;QACL,OAAO,EAAE,iBAAiB;QAC1B,KAAK;QACL,WAAW;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,OAAO,EAAE,EAAE,WAAW,EAAE,+BAA+B,EAAE,IAAI,EAAE,QAAQ,EAAE;YACzE,GAAG,MAAM,CAAC,WAAW,CACnB,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;gBAC/C,IAAI;gBACJ,aAAa,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC;aACvC,CAAC,CACH;SACF;QACD,iBAAiB,EAAE,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,uCAAuC,EAAE,EAAE;KACvF,CAAA;AACH,CAAC","sourcesContent":["/**\n * The JSON Schema of a namespace's configuration, of the schemas of the sections of the tools a\n * project uses: {@link namespaceSchema}. Each tool's package exports the schema of its options, as\n * `viteSchema` of `@wtf/project-vite/schema`, a Standard Schema that gives its JSON Schema; the\n * schema of the whole has each at the property of its section, and takes any other section as it\n * is. An editor completes `wtf.config.json` by it.\n *\n * ```ts\n * import { namespaceSchema } from '@wtf/project-config/schema'\n * import { viteSchema } from '@wtf/project-vite/schema'\n *\n * const schema = namespaceSchema('wtf', { vite: viteSchema })\n * ```\n *\n * @packageDocumentation\n */\nimport { jsonSchemaOf } from './env.ts'\nimport type { JsonSchema, SectionSchema } from './index.ts'\n\n/** The draft of the JSON Schema {@link namespaceSchema} gives, and a section's is read as. */\nexport const JSON_SCHEMA_DRAFT = 'https://json-schema.org/draft/2020-12/schema'\n\n/**\n * The `$id` of a section's schema that has none: a `$ref` in it, as `#/$defs/x`, is then of the\n * section's own schema, and not of the whole.\n */\nexport const sectionIdOf = (namespace: string, name: string): string => `urn:${namespace}:${name}`\n\n/** What the schema of the whole says of itself. */\nexport type NamespaceSchemaOptions = {\n readonly title?: string\n readonly description?: string\n}\n\n/** A section's JSON Schema, with an `$id` of its own when it has none, and with no `$schema`; any\n * value, of a schema that gives no JSON Schema, as a function. */\nfunction sectionSchema(namespace: string, name: string, schema: SectionSchema): JsonSchema {\n const json = jsonSchemaOf(schema)\n if (json === undefined || typeof json === 'boolean') return json ?? true\n const { $schema: _draft, ...rest } = json\n return typeof rest['$id'] === 'string' ? rest : { $id: sectionIdOf(namespace, name), ...rest }\n}\n\n/**\n * The JSON Schema of the configuration of `namespace`, of draft 2020-12, of `sections`, the schema\n * of each section by its name: a JSON Schema, or a Standard Schema that gives one, as zod's and\n * the presets' do, of its input. It is an object with each section at its property, checked by its\n * schema; the `$schema` key, by which a file names its schema; a key that starts with `//`, a\n * comment, as each preset's options take one; and any other key as it is. A schema that gives no\n * JSON Schema, as a function, takes any value.\n */\nexport function namespaceSchema(\n namespace: string,\n sections: Readonly<Record<string, SectionSchema>>,\n {\n title = `The ${namespace} configuration`,\n description = 'The configuration of the tools of a project: a section of each tool, by its name.'\n }: NamespaceSchemaOptions = {}\n): { readonly [keyword: string]: unknown } {\n return {\n $schema: JSON_SCHEMA_DRAFT,\n title,\n description,\n type: 'object',\n properties: {\n $schema: { description: 'The JSON Schema of this file.', type: 'string' },\n ...Object.fromEntries(\n Object.entries(sections).map(([name, schema]) => [\n name,\n sectionSchema(namespace, name, schema)\n ])\n )\n },\n patternProperties: { '^//': { description: 'A comment, which the tools leave out.' } }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtf/project-config",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Read and write a project's configuration of its tools: one object under a namespace, wtf by default, with a section for each tool, in wtf.config.{mjs,js,ts,json} or the wtf key of package.json, the first found. Find it (./locate); load it, asynchronously with code, or synchronously of JSON and package.json alone (./load); read a tool's section, checked by its Standard Schema, a JSON Schema or a function, with WTF_<SECTION>_<KEY> variables over it (./section, ./env); replace ${env:NAME} placeholders (./placeholder); get a value by its path (./path); write a value (./write); the JSON Schema of the whole (./schema); a code config, typed (./define); Node's platform and loads (./node); and the errors (./errors).",
|
|
5
5
|
"homepage": "https://gitlab.com/wetryfun/project/project/-/tree/main/packages/project-config",
|
|
6
6
|
"bugs": {
|