@celljs/vite 4.3.0 → 4.4.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 +2 -1
- package/lib/builder/cell-builder.spec.js +27 -21
- package/lib/builder/cell-builder.spec.js.map +1 -1
- package/lib/builder/pages.spec.d.ts +2 -0
- package/lib/builder/pages.spec.d.ts.map +1 -0
- package/lib/builder/pages.spec.js +96 -0
- package/lib/builder/pages.spec.js.map +1 -0
- package/lib/constants.d.ts +0 -2
- package/lib/constants.d.ts.map +1 -1
- package/lib/constants.js +0 -2
- package/lib/constants.js.map +1 -1
- package/lib/dev/cell-dev-server.d.ts +4 -2
- package/lib/dev/cell-dev-server.d.ts.map +1 -1
- package/lib/dev/cell-dev-server.js +32 -2
- package/lib/dev/cell-dev-server.js.map +1 -1
- package/lib/dev/cell-dev-server.spec.js +23 -2
- package/lib/dev/cell-dev-server.spec.js.map +1 -1
- package/lib/expression/expression-evaluator.d.ts +11 -2
- package/lib/expression/expression-evaluator.d.ts.map +1 -1
- package/lib/expression/expression-evaluator.js +6 -2
- package/lib/expression/expression-evaluator.js.map +1 -1
- package/lib/expression/expression-evaluator.spec.js +3 -3
- package/lib/expression/expression-evaluator.spec.js.map +1 -1
- package/lib/generator/config-generator.d.ts +4 -3
- package/lib/generator/config-generator.d.ts.map +1 -1
- package/lib/generator/config-generator.js +7 -5
- package/lib/generator/config-generator.js.map +1 -1
- package/lib/generator/generator.spec.js +20 -5
- package/lib/generator/generator.spec.js.map +1 -1
- package/lib/generator/html-generator.js +3 -3
- package/lib/generator/html-generator.js.map +1 -1
- package/lib/generator/route-generator.d.ts +13 -0
- package/lib/generator/route-generator.d.ts.map +1 -0
- package/lib/generator/route-generator.js +34 -0
- package/lib/generator/route-generator.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/output/output-writer.d.ts +4 -0
- package/lib/output/output-writer.d.ts.map +1 -1
- package/lib/output/output-writer.js +10 -0
- package/lib/output/output-writer.js.map +1 -1
- package/lib/plugin/cell-plugin.d.ts +17 -2
- package/lib/plugin/cell-plugin.d.ts.map +1 -1
- package/lib/plugin/cell-plugin.js +63 -5
- package/lib/plugin/cell-plugin.js.map +1 -1
- package/lib/plugin/cell-plugin.spec.js +15 -0
- package/lib/plugin/cell-plugin.spec.js.map +1 -1
- package/lib/plugin/class-name-util.d.ts +14 -0
- package/lib/plugin/class-name-util.d.ts.map +1 -0
- package/lib/plugin/class-name-util.js +82 -0
- package/lib/plugin/class-name-util.js.map +1 -0
- package/lib/plugin/class-name-util.spec.d.ts +2 -0
- package/lib/plugin/class-name-util.spec.d.ts.map +1 -0
- package/lib/plugin/class-name-util.spec.js +37 -0
- package/lib/plugin/class-name-util.spec.js.map +1 -0
- package/lib/project/browser-dependency-scanner.d.ts +29 -0
- package/lib/project/browser-dependency-scanner.d.ts.map +1 -0
- package/lib/project/browser-dependency-scanner.js +96 -0
- package/lib/project/browser-dependency-scanner.js.map +1 -0
- package/lib/project/browser-dependency-scanner.spec.d.ts +2 -0
- package/lib/project/browser-dependency-scanner.spec.d.ts.map +1 -0
- package/lib/project/browser-dependency-scanner.spec.js +41 -0
- package/lib/project/browser-dependency-scanner.spec.js.map +1 -0
- package/lib/project/config-loader.d.ts +6 -6
- package/lib/project/config-loader.d.ts.map +1 -1
- package/lib/project/config-loader.js +16 -22
- package/lib/project/config-loader.js.map +1 -1
- package/lib/project/config-schema.d.ts +107 -0
- package/lib/project/config-schema.d.ts.map +1 -0
- package/lib/project/config-schema.js +522 -0
- package/lib/project/config-schema.js.map +1 -0
- package/lib/project/config-schema.spec.d.ts +2 -0
- package/lib/project/config-schema.spec.d.ts.map +1 -0
- package/lib/project/config-schema.spec.js +248 -0
- package/lib/project/config-schema.spec.js.map +1 -0
- package/lib/project/env-overrides.d.ts +14 -10
- package/lib/project/env-overrides.d.ts.map +1 -1
- package/lib/project/env-overrides.js +28 -19
- package/lib/project/env-overrides.js.map +1 -1
- package/lib/project/env-overrides.spec.js +23 -13
- package/lib/project/env-overrides.spec.js.map +1 -1
- package/lib/project/page-scanner.d.ts +26 -0
- package/lib/project/page-scanner.d.ts.map +1 -0
- package/lib/project/page-scanner.js +102 -0
- package/lib/project/page-scanner.js.map +1 -0
- package/lib/project/page-scanner.spec.d.ts +2 -0
- package/lib/project/page-scanner.spec.d.ts.map +1 -0
- package/lib/project/page-scanner.spec.js +68 -0
- package/lib/project/page-scanner.spec.js.map +1 -0
- package/lib/project/project-loader.d.ts +32 -3
- package/lib/project/project-loader.d.ts.map +1 -1
- package/lib/project/project-loader.js +70 -15
- package/lib/project/project-loader.js.map +1 -1
- package/lib/project/project-loader.spec.js +78 -56
- package/lib/project/project-loader.spec.js.map +1 -1
- package/lib/testing/test-app.spec.js +3 -3
- package/lib/testing/test-app.spec.js.map +1 -1
- package/package.json +7 -7
- package/src/constants.ts +0 -3
- package/src/dev/cell-dev-server.ts +39 -5
- package/src/expression/expression-evaluator.ts +16 -3
- package/src/generator/config-generator.ts +7 -5
- package/src/generator/html-generator.ts +3 -3
- package/src/generator/route-generator.ts +34 -0
- package/src/index.ts +1 -0
- package/src/output/output-writer.ts +12 -0
- package/src/plugin/cell-plugin.ts +68 -6
- package/src/plugin/class-name-util.ts +85 -0
- package/src/project/browser-dependency-scanner.ts +102 -0
- package/src/project/config-loader.ts +18 -23
- package/src/project/config-schema.ts +596 -0
- package/src/project/env-overrides.ts +33 -22
- package/src/project/page-scanner.ts +105 -0
- package/src/project/project-loader.ts +82 -17
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { afterAll, describe, expect, it } from 'bun:test';
|
|
2
|
+
import { FixtureProject } from '../test/fixture-project.js';
|
|
3
|
+
import { BrowserDependencyScanner } from './browser-dependency-scanner.js';
|
|
4
|
+
import { ProjectLoader } from './project-loader.js';
|
|
5
|
+
describe('BrowserDependencyScanner', () => {
|
|
6
|
+
const fixture = new FixtureProject('browser-deps')
|
|
7
|
+
.file('package.json', { name: 'app', version: '1.0.0', dependencies: { '@x/ui': '*', '@x/server': '*' } })
|
|
8
|
+
.dependency('@x/ui', {
|
|
9
|
+
dependencies: { '@x/base': '*', 'ui-lib': '*', '@types/ui-lib': '*' },
|
|
10
|
+
cell: { targets: ['frontend'], modules: { frontend: ['esm/browser/module'] } },
|
|
11
|
+
}, {
|
|
12
|
+
'esm/browser/module.js': [
|
|
13
|
+
"import { a } from 'ui-lib';",
|
|
14
|
+
"import 'ui-lib/style';",
|
|
15
|
+
'import {',
|
|
16
|
+
' b,',
|
|
17
|
+
"} from './local.js';",
|
|
18
|
+
"export * from '@x/base';",
|
|
19
|
+
"import fs from 'node:fs';",
|
|
20
|
+
"import { t } from '@types/ui-lib';",
|
|
21
|
+
"const lazy = () => import('ui-lib/lazy');",
|
|
22
|
+
'const url = import.meta.url;',
|
|
23
|
+
].join('\n'),
|
|
24
|
+
'esm/browser/module.spec.js': "import 'ui-lib/spec';",
|
|
25
|
+
'esm/node/server.js': "import 'ui-lib/node-only';",
|
|
26
|
+
'lib/browser/module.js': "require('ui-lib/cjs');",
|
|
27
|
+
})
|
|
28
|
+
.dependency('@x/base', { dependencies: { 'base-lib': '*' }, cell: {} }, { 'esm/common/index.js': 'import { c } from "base-lib";\nimport { d } from \'undeclared-lib\';' })
|
|
29
|
+
.dependency('@x/server', { dependencies: { 'server-lib': '*' }, cell: { modules: { backend: ['esm/node/module'] } } }, { 'esm/common/index.js': "import 'server-lib';" });
|
|
30
|
+
afterAll(() => fixture.dispose());
|
|
31
|
+
it('lists the third-party imports of frontend components and the components they depend on', () => {
|
|
32
|
+
const model = new ProjectLoader({ root: fixture.root }).load();
|
|
33
|
+
expect(new BrowserDependencyScanner(model).scan()).toEqual(['@x/base > base-lib', '@x/ui > ui-lib', '@x/ui > ui-lib/lazy', '@x/ui > ui-lib/style']);
|
|
34
|
+
});
|
|
35
|
+
it('takes the package name of a specifier', () => {
|
|
36
|
+
expect(BrowserDependencyScanner.packageName('react-dom/client')).toBe('react-dom');
|
|
37
|
+
expect(BrowserDependencyScanner.packageName('@scope/pkg/sub/path')).toBe('@scope/pkg');
|
|
38
|
+
expect(BrowserDependencyScanner.packageName('react')).toBe('react');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=browser-dependency-scanner.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-dependency-scanner.spec.js","sourceRoot":"","sources":["../../src/project/browser-dependency-scanner.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACtC,MAAM,OAAO,GAAG,IAAI,cAAc,CAAC,cAAc,CAAC;SAC7C,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,CAAC;SACzG,UAAU,CACP,OAAO,EACP;QACI,YAAY,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE;QACrE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,oBAAoB,CAAC,EAAE,EAAE;KACjF,EACD;QACI,uBAAuB,EAAE;YACrB,6BAA6B;YAC7B,wBAAwB;YACxB,UAAU;YACV,QAAQ;YACR,sBAAsB;YACtB,0BAA0B;YAC1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AC,CAAC;QACvF,MAAM,CAAC,wBAAwB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { type Target } from '@celljs/kit';
|
|
2
1
|
import type { Component } from './component-collector.js';
|
|
2
|
+
import type { ConfigLayerFile } from './config-schema.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Reads the configuration layers of all components: for each component in order, `cell.yml` then
|
|
5
5
|
* `cell.<mode>.yml` for every active mode. Records the files it read on each component.
|
|
6
6
|
*/
|
|
7
7
|
export declare class ConfigLoader {
|
|
8
8
|
protected readonly mode: string[];
|
|
9
9
|
constructor(mode: string[]);
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
|
|
10
|
+
read(components: Component[]): ConfigLayerFile[];
|
|
11
|
+
/** The layers merged in order: objects merge, arrays and scalars replace; `mode` is the active modes. */
|
|
12
|
+
merge(layers: ConfigLayerFile[]): Record<string, any>;
|
|
13
13
|
protected layerFiles(component: Component): string[];
|
|
14
|
-
protected
|
|
14
|
+
protected parse(file: string, text: string): Record<string, any>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=config-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/project/config-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config-loader.d.ts","sourceRoot":"","sources":["../../src/project/config-loader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE1D;;;GAGG;AACH,qBAAa,YAAY;IACT,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE;IAA7C,YAA+B,IAAI,EAAE,MAAM,EAAE,EAAI;IAEjD,IAAI,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,eAAe,EAAE,CAU/C;IAED,yGAAyG;IACzG,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAOpD;IAED,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,EAAE,CAEnD;IAED,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA6B/D;CACJ"}
|
|
@@ -2,10 +2,9 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { CellError } from '@celljs/kit';
|
|
4
4
|
import yaml from 'js-yaml';
|
|
5
|
-
import { TOOLING_KEYS } from '../constants.js';
|
|
6
5
|
import { ConfigUtil } from '../utils/config-util.js';
|
|
7
6
|
/**
|
|
8
|
-
*
|
|
7
|
+
* Reads the configuration layers of all components: for each component in order, `cell.yml` then
|
|
9
8
|
* `cell.<mode>.yml` for every active mode. Records the files it read on each component.
|
|
10
9
|
*/
|
|
11
10
|
export class ConfigLoader {
|
|
@@ -13,38 +12,33 @@ export class ConfigLoader {
|
|
|
13
12
|
constructor(mode) {
|
|
14
13
|
this.mode = mode;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
const
|
|
15
|
+
read(components) {
|
|
16
|
+
const layers = [];
|
|
18
17
|
for (const component of components) {
|
|
19
18
|
for (const file of this.layerFiles(component)) {
|
|
20
19
|
component.configFiles.push(file);
|
|
21
|
-
|
|
20
|
+
const text = readFileSync(file, 'utf8');
|
|
21
|
+
layers.push({ component: component.name, file, text, doc: this.parse(file, text) });
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
return
|
|
24
|
+
return layers;
|
|
25
25
|
}
|
|
26
|
-
/**
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
for (const
|
|
30
|
-
|
|
31
|
-
config[key] = structuredClone(value);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
ConfigUtil.merge(config, structuredClone(merged[target] ?? {}));
|
|
35
|
-
for (const key of TOOLING_KEYS) {
|
|
36
|
-
delete config[key];
|
|
26
|
+
/** The layers merged in order: objects merge, arrays and scalars replace; `mode` is the active modes. */
|
|
27
|
+
merge(layers) {
|
|
28
|
+
const merged = {};
|
|
29
|
+
for (const layer of layers) {
|
|
30
|
+
ConfigUtil.merge(merged, structuredClone(layer.doc));
|
|
37
31
|
}
|
|
38
|
-
|
|
39
|
-
return
|
|
32
|
+
merged.mode = [...this.mode];
|
|
33
|
+
return merged;
|
|
40
34
|
}
|
|
41
35
|
layerFiles(component) {
|
|
42
36
|
return ['cell.yml', ...this.mode.map(m => `cell.${m}.yml`)].map(name => join(component.dir, name)).filter(existsSync);
|
|
43
37
|
}
|
|
44
|
-
|
|
38
|
+
parse(file, text) {
|
|
45
39
|
let value;
|
|
46
40
|
try {
|
|
47
|
-
value = yaml.load(
|
|
41
|
+
value = yaml.load(text);
|
|
48
42
|
}
|
|
49
43
|
catch (cause) {
|
|
50
44
|
const mark = cause.mark;
|
|
@@ -67,7 +61,7 @@ export class ConfigLoader {
|
|
|
67
61
|
message: `${file} must contain a YAML mapping at the top level.`,
|
|
68
62
|
file,
|
|
69
63
|
line: 1,
|
|
70
|
-
hint: 'Start the file with keys such as `
|
|
64
|
+
hint: 'Start the file with configuration keys such as `server:` or `app:`.',
|
|
71
65
|
});
|
|
72
66
|
}
|
|
73
67
|
return value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config-loader.js","sourceRoot":"","sources":["../../src/project/config-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,O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,EAAE,GAAG,IAAI,gDAAgD;gBAChE,IAAI;gBACJ,IAAI,EAAE,CAAC;gBACP,IAAI,EAAE,qEAAqE;aAC9E,CAAC,CAAC;QACP,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { Component } from './component-collector.js';
|
|
2
|
+
/** A configuration file as ConfigLoader read it. */
|
|
3
|
+
export interface ConfigLayerFile {
|
|
4
|
+
component: string;
|
|
5
|
+
file: string;
|
|
6
|
+
text: string;
|
|
7
|
+
doc: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
/** The subset of JSON Schema a component's `cell.schema.json` may use (docs/design/config.md §3.2). */
|
|
10
|
+
export interface SchemaNode {
|
|
11
|
+
type?: SchemaType | SchemaType[];
|
|
12
|
+
description?: string;
|
|
13
|
+
default?: unknown;
|
|
14
|
+
properties?: Record<string, SchemaNode>;
|
|
15
|
+
/** Objects with `properties` are closed unless this is given. */
|
|
16
|
+
additionalProperties?: boolean | SchemaNode;
|
|
17
|
+
items?: SchemaNode;
|
|
18
|
+
enum?: unknown[];
|
|
19
|
+
anyOf?: SchemaNode[];
|
|
20
|
+
/** The value (the whole subtree) is part of the frontend configuration. */
|
|
21
|
+
'x-cell-public'?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export type SchemaType = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
|
|
24
|
+
/** A key of a configuration file that does not fit the schema. */
|
|
25
|
+
export interface ConfigProblem {
|
|
26
|
+
file: string;
|
|
27
|
+
/** Dotted key, e.g. `server.prot`. */
|
|
28
|
+
path: string;
|
|
29
|
+
line?: number;
|
|
30
|
+
message: string;
|
|
31
|
+
hint: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The configuration schema of a project: the `cell.schema.json` of every component merged into one
|
|
35
|
+
* tree. It says which component owns a key, validates configuration files, picks the keys that
|
|
36
|
+
* reach the browser (`x-cell-public`) and the types that expressions convert to.
|
|
37
|
+
*/
|
|
38
|
+
export declare class ConfigSchema {
|
|
39
|
+
static readonly FILE = "cell.schema.json";
|
|
40
|
+
/** Where the merged schema is written for editors (yaml-language-server) and agents. */
|
|
41
|
+
static readonly OUTPUT = ".cell/schema/cell.yml.json";
|
|
42
|
+
/** Kept for applications: no component may declare it (docs/design/config.md §3.2). */
|
|
43
|
+
static readonly APP_KEY = "app";
|
|
44
|
+
/** Owner of the keys the toolchain itself defines: `app`, `mode` and `paths`. */
|
|
45
|
+
static readonly TOOLCHAIN = "cell";
|
|
46
|
+
/** Keys every project has, whatever its components (docs/design/config.md §3.2). */
|
|
47
|
+
static builtin(): Record<string, SchemaNode>;
|
|
48
|
+
readonly root: SchemaNode & {
|
|
49
|
+
properties: Record<string, SchemaNode>;
|
|
50
|
+
};
|
|
51
|
+
protected readonly owners: Map<SchemaNode, string[]>;
|
|
52
|
+
constructor();
|
|
53
|
+
/**
|
|
54
|
+
* Merges the schemas of `components` in order. The project (the root component) may describe
|
|
55
|
+
* keys under `app` only; components without a schema own the top-level keys of their cell.yml
|
|
56
|
+
* that no schema claims, without checks below them.
|
|
57
|
+
*/
|
|
58
|
+
static load(components: Component[], layers: ConfigLayerFile[]): ConfigSchema;
|
|
59
|
+
static read(file: string): SchemaNode;
|
|
60
|
+
/** The first unsupported keyword or malformed value in `node`, if any. */
|
|
61
|
+
protected static checkNode(node: unknown, path: string): string | undefined;
|
|
62
|
+
protected add(source: SchemaNode, component: Component, file: string): void;
|
|
63
|
+
protected merge(parent: SchemaNode, key: string, node: SchemaNode, owner: string, file: string, path: string): void;
|
|
64
|
+
protected adopt(node: SchemaNode, owner: string): SchemaNode;
|
|
65
|
+
protected ownersOf(node: SchemaNode): string[];
|
|
66
|
+
/** An object schema that only describes properties, which other components may extend. */
|
|
67
|
+
protected static isObject(node: SchemaNode): boolean;
|
|
68
|
+
/** The schema of a child key, or `undefined` when `node` does not allow it; `null` when anything goes. */
|
|
69
|
+
protected static child(node: SchemaNode, key: string): SchemaNode | null | undefined;
|
|
70
|
+
/** The schema of a dotted key (array items by index), with the components that own it. */
|
|
71
|
+
describe(path: string[]): {
|
|
72
|
+
node?: SchemaNode;
|
|
73
|
+
owners: string[];
|
|
74
|
+
public: boolean;
|
|
75
|
+
};
|
|
76
|
+
/** Problems of one configuration file (a partial configuration). */
|
|
77
|
+
validate(doc: Record<string, unknown>, file: string, text: string): ConfigProblem[];
|
|
78
|
+
protected check(value: unknown, node: SchemaNode, path: string[], report: (path: string[], message: string, hint: string) => void): void;
|
|
79
|
+
protected static describeHint(node: SchemaNode): string;
|
|
80
|
+
protected static typeOf(value: unknown): string;
|
|
81
|
+
protected static isType(value: unknown, type: SchemaType): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* The frontend configuration: the values of keys marked `x-cell-public` (whole subtrees), and
|
|
84
|
+
* nothing else.
|
|
85
|
+
*/
|
|
86
|
+
project(config: Record<string, unknown>): Record<string, unknown>;
|
|
87
|
+
protected static pick(value: unknown, node: SchemaNode): unknown;
|
|
88
|
+
/** Whether the frontend sees the key `path` (dotted). */
|
|
89
|
+
isPublic(path: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Schema types of the keys whose value is a `${...}` expression and whose schema type is a
|
|
92
|
+
* number, an integer or a boolean: what evaluation converts the expression's text to.
|
|
93
|
+
*/
|
|
94
|
+
types(config: Record<string, unknown>): Record<string, 'number' | 'integer' | 'boolean'>;
|
|
95
|
+
protected static scalarType(node: SchemaNode): 'number' | 'integer' | 'boolean' | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* The merged schema as standard JSON Schema for editors: closed objects say so, and keys of
|
|
98
|
+
* other types also take a `${...}` expression.
|
|
99
|
+
*/
|
|
100
|
+
toJSON(): Record<string, unknown>;
|
|
101
|
+
/** Best-effort line of a dotted key in a YAML text (block mappings), for error messages. */
|
|
102
|
+
static lineOf(text: string, path: string[]): number | undefined;
|
|
103
|
+
/** The candidate within edit distance 2 (or a case-insensitive match), if one is clearly meant. */
|
|
104
|
+
static closest(word: string, candidates: string[]): string | undefined;
|
|
105
|
+
protected static distance(a: string, b: string): number;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=config-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-schema.d.ts","sourceRoot":"","sources":["../../src/project/config-schema.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D,oDAAoD;AACpD,MAAM,WAAW,eAAe;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,uGAAuG;AACvG,MAAM,WAAW,UAAU;IACvB,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,iEAAiE;IACjE,oBAAoB,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IAC5C,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,2EAA2E;IAC3E,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAEnG,kEAAkE;AAClE,MAAM,WAAW,aAAa;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,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