@chartguard/schema-generator 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/index.d.mts +6 -0
- package/dist/lib/chartjs-effects.d.mts +5 -0
- package/dist/lib/chartjs-plugins.d.mts +23 -0
- package/dist/lib/chartjs-scopes.d.mts +30 -0
- package/dist/lib/chartjs.d.mts +32 -0
- package/dist/lib/deprecation.d.mts +9 -0
- package/dist/lib/digest.d.mts +12 -0
- package/dist/lib/echarts-components.d.mts +2 -0
- package/dist/lib/echarts-deprecations.d.mts +5 -0
- package/dist/lib/echarts-handlers.d.mts +2 -0
- package/dist/lib/echarts-runtime.d.mts +2 -0
- package/dist/lib/echarts.d.mts +26 -0
- package/dist/lib/emitter.d.mts +173 -0
- package/dist/lib/generate.d.mts +14 -0
- package/dist/lib/highcharts-runtime.d.mts +2 -0
- package/dist/lib/highcharts.d.mts +26 -0
- package/dist/lib/local.d.mts +14 -0
- package/dist/lib/lock.d.mts +31 -0
- package/dist/lib/nodes.d.mts +4 -0
- package/dist/lib/paths.d.mts +22 -0
- package/dist/lib/program.d.mts +13 -0
- package/dist/lib/provenance.d.mts +46 -0
- package/dist/lib/runtime.d.mts +24 -0
- package/dist/lib/scriptable.d.mts +13 -0
- package/dist/lib/trace.d.mts +8 -0
- package/dist/lib/types.d.mts +52 -0
- package/index.mjs +20 -0
- package/lib/chartjs-effects.mjs +36 -0
- package/lib/chartjs-plugins.mjs +41 -0
- package/lib/chartjs-scopes.mjs +96 -0
- package/lib/chartjs.mjs +275 -0
- package/lib/deprecation.mjs +21 -0
- package/lib/digest.mjs +33 -0
- package/lib/echarts-components.mjs +176 -0
- package/lib/echarts-deprecations.mjs +206 -0
- package/lib/echarts-handlers.mjs +31 -0
- package/lib/echarts-runtime.mjs +311 -0
- package/lib/echarts.mjs +89 -0
- package/lib/emitter.mjs +333 -0
- package/lib/generate.mjs +35 -0
- package/lib/highcharts-runtime.mjs +198 -0
- package/lib/highcharts.mjs +105 -0
- package/lib/local.mjs +33 -0
- package/lib/lock.mjs +123 -0
- package/lib/nodes.mjs +17 -0
- package/lib/paths.mjs +50 -0
- package/lib/program.mjs +46 -0
- package/lib/provenance.mjs +100 -0
- package/lib/runtime.mjs +38 -0
- package/lib/scriptable.mjs +57 -0
- package/lib/trace.mjs +124 -0
- package/lib/types.mjs +74 -0
- package/package.json +47 -5
- package/upstream-sources.json +102 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ChartGuard contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @chartguard/schema-generator
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Generates ChartGuard schema artifacts from a chart library's own published TypeScript declarations and runtime code. Every fact in an artifact cites the line of the installed package it was read from, and a build fails if a fact does not trace to that line; nothing from the package is executed. An artifact names everything it was built from: the library (exact version and integrity), the TypeScript compiler that read it (its lib files give the members of DOM and built-in types; the generator depends on one exact TypeScript and refuses another), and the generator's version, so the same inputs build the same bytes.
|
|
4
|
+
|
|
5
|
+
**Status:** pre-release (0.x). Coverage is partial, and the API and settings may still change between minor versions.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install --save-dev @chartguard/schema-generator
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
ChartGuard's Chart.js and ECharts adapters ship their schemas. The Highcharts schema cannot ship: the Highcharts license does not clear redistributing option metadata derived from it. Build it on your machine, from your own installed `highcharts`, under your own license:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npx chartguard schema build --library highcharts
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
The schema is written to `node_modules/.cache/chartguard/highcharts-<version>.json` and used by `chartguard validate --library highcharts` for that installed version. A version of the same major as the one the generator was verified against (see `upstream-sources.json`) is read the same way; if any declaration shape or runtime fact the generator relies on is missing, the build fails and names it rather than writing a different schema.
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
import { buildLocalSchema } from "@chartguard/schema-generator";
|
|
21
|
+
const { path, version, digest } = buildLocalSchema(process.cwd(), "highcharts");
|
|
22
|
+
```
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { buildLocalSchema } from "./lib/local.mjs";
|
|
2
|
+
export { untracedFacts } from "./lib/trace.mjs";
|
|
3
|
+
export { digestOf, omit, serialize, withDigest } from "./lib/digest.mjs";
|
|
4
|
+
export { generateArtifact, isRedistributable, LIBRARIES } from "./lib/generate.mjs";
|
|
5
|
+
export { compilerPin, contentIntegrity, installedUpstream, pinOf, sourceDirectory, UpstreamError, verifiedCompiler, verifiedUpstream } from "./lib/lock.mjs";
|
|
6
|
+
export { LOCAL_ARTIFACTS, localSchemaPath } from "./lib/paths.mjs";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chart options of every configuration (`config.options`) with the effect of a mismatched value
|
|
3
|
+
* on each option `EFFECTS` names, its runtime line added to the option's provenance.
|
|
4
|
+
*/
|
|
5
|
+
export function withMismatchEffects(root: any, definitions: any, configNames: any): any;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `options.plugins` definitions of the given configurations. `PluginOptionsByType` is the
|
|
3
|
+
* declaration-merging point of plugin options (dist/types/index.d.ts), so each is the
|
|
4
|
+
* `chartjs.plugins` extension point (CG-02-05): a plugin's options are added there by name.
|
|
5
|
+
*/
|
|
6
|
+
export function pluginDefinitions(definitions: any, configNames: any): any[];
|
|
7
|
+
/**
|
|
8
|
+
* Every built-in plugin namespace under `options.plugins` of the given configurations, with the
|
|
9
|
+
* handler to set and the runtime lines that make it a plugin id. The generator applies the plan.
|
|
10
|
+
*/
|
|
11
|
+
export function planPluginHandlers(root: any, definitions: any, configNames: any): {
|
|
12
|
+
definition: any;
|
|
13
|
+
property: string;
|
|
14
|
+
handledBy: {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
enforced: boolean;
|
|
18
|
+
};
|
|
19
|
+
sources: {
|
|
20
|
+
source: string;
|
|
21
|
+
pointer: string;
|
|
22
|
+
}[];
|
|
23
|
+
}[];
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What to add for the option scopes of the given configurations: the shared element-options
|
|
3
|
+
* definition, the definitions that include it (every `options` and every dataset variant), and the
|
|
4
|
+
* animation spec definitions that become open.
|
|
5
|
+
*/
|
|
6
|
+
export function planOptionScopes(root: any, definitions: any, configNames: any): {
|
|
7
|
+
scope: {
|
|
8
|
+
kind: string;
|
|
9
|
+
additional: string;
|
|
10
|
+
properties: any;
|
|
11
|
+
};
|
|
12
|
+
includedBy: any[];
|
|
13
|
+
openAnimations: any[];
|
|
14
|
+
animationProvenance: {
|
|
15
|
+
confidence: string;
|
|
16
|
+
sources: {
|
|
17
|
+
source: string;
|
|
18
|
+
pointer: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Chart.js resolves element options through a scope chain that ends at the options root, and
|
|
24
|
+
* with element and hover prefixes (dist/chart.js `datasetElementScopeKeys`, `_resolveElementOptions`),
|
|
25
|
+
* so `options.radius`, `options.pointBackgroundColor` and `datasets[].radius` all reach the
|
|
26
|
+
* point elements. Per-property animations live under `options.animation`, which `animations`
|
|
27
|
+
* falls back to. The declarations describe none of this; `planOptionScopes` works out what to
|
|
28
|
+
* add, citing the runtime, and the generator applies the plan to the definitions it owns.
|
|
29
|
+
*/
|
|
30
|
+
export const ELEMENT_SCOPE: "ElementOptionsInScope";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The declaration a plugin's option is widened at. `widened` is keyed by declaration: a symbol without
|
|
3
|
+
* one (a key a mapped type synthesizes) would key `undefined`, which every other declaration-less
|
|
4
|
+
* property also looks up, so it would widen them all.
|
|
5
|
+
*/
|
|
6
|
+
export function declarationOf(symbol: any): any;
|
|
7
|
+
export function generateChartjs(root: any, pin: any): {
|
|
8
|
+
irVersion: number;
|
|
9
|
+
library: any;
|
|
10
|
+
libraryVersion: any;
|
|
11
|
+
coverage: string;
|
|
12
|
+
generator: {
|
|
13
|
+
name: any;
|
|
14
|
+
version: any;
|
|
15
|
+
};
|
|
16
|
+
sources: {
|
|
17
|
+
[x: number]: {
|
|
18
|
+
kind: string;
|
|
19
|
+
locator: string;
|
|
20
|
+
integrity: any;
|
|
21
|
+
license: any;
|
|
22
|
+
};
|
|
23
|
+
typescript: {
|
|
24
|
+
kind: string;
|
|
25
|
+
locator: string;
|
|
26
|
+
integrity: any;
|
|
27
|
+
license: any;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
definitions: any;
|
|
31
|
+
root: any;
|
|
32
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `@deprecated` tag of a property, as the upstream declaration states it: its first sentence,
|
|
3
|
+
* and the replacement it names. Never a rename: a notice does not say the runtime reads the old
|
|
4
|
+
* option under the new name, so renaming could change what is drawn.
|
|
5
|
+
*/
|
|
6
|
+
export function deprecationOf(symbol: any): {
|
|
7
|
+
replacement?: string;
|
|
8
|
+
message?: string;
|
|
9
|
+
} | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The committed artifact text: tab-indented JSON with a final newline. */
|
|
2
|
+
export function serialize(artifact: any): string;
|
|
3
|
+
/** The object without the named keys, key order kept. */
|
|
4
|
+
export function omit(object: any, keys: any): {
|
|
5
|
+
[k: string]: any;
|
|
6
|
+
};
|
|
7
|
+
/** `sha256-<hex>` of the canonical text with the `digest` field left out. */
|
|
8
|
+
export function digestOf(artifact: any): string;
|
|
9
|
+
/** The artifact with its digest placed in the header, right after `generator`. */
|
|
10
|
+
export function withDigest(artifact: any): {
|
|
11
|
+
[k: string]: any;
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* New definitions with the runtime's renames as deprecated aliases. An alias inside a nested
|
|
3
|
+
* option (`itemStyle`) goes into a copy owned by that series type: the runtime renames it there only.
|
|
4
|
+
*/
|
|
5
|
+
export function withDeprecatedAliases(root: any, definitions: any, optionName: any): any;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function generateEcharts(root: any, pin: any): {
|
|
2
|
+
irVersion: number;
|
|
3
|
+
library: any;
|
|
4
|
+
libraryVersion: any;
|
|
5
|
+
coverage: string;
|
|
6
|
+
generator: {
|
|
7
|
+
name: any;
|
|
8
|
+
version: any;
|
|
9
|
+
};
|
|
10
|
+
sources: {
|
|
11
|
+
[x: number]: {
|
|
12
|
+
kind: string;
|
|
13
|
+
locator: string;
|
|
14
|
+
integrity: any;
|
|
15
|
+
license: any;
|
|
16
|
+
};
|
|
17
|
+
typescript: {
|
|
18
|
+
kind: string;
|
|
19
|
+
locator: string;
|
|
20
|
+
integrity: any;
|
|
21
|
+
license: any;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
definitions: any;
|
|
25
|
+
root: any;
|
|
26
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts TypeScript types into SchemaIR nodes. Object types become shared
|
|
3
|
+
* definitions so recursive and repeated types stay finite.
|
|
4
|
+
*/
|
|
5
|
+
export class TypeEmitter {
|
|
6
|
+
constructor({ program, checker, sourceId, packageName, opaque, open, registries, runtimeOptional, widened, wrappers }: {
|
|
7
|
+
program: any;
|
|
8
|
+
checker: any;
|
|
9
|
+
sourceId: any;
|
|
10
|
+
packageName: any;
|
|
11
|
+
opaque?: Set<any> | undefined;
|
|
12
|
+
open?: Set<any> | undefined;
|
|
13
|
+
registries?: Map<any, any> | undefined;
|
|
14
|
+
runtimeOptional?: Set<any> | undefined;
|
|
15
|
+
widened?: Map<any, any> | undefined;
|
|
16
|
+
wrappers?: Set<any> | undefined;
|
|
17
|
+
});
|
|
18
|
+
program: any;
|
|
19
|
+
checker: any;
|
|
20
|
+
provenance: Provenance;
|
|
21
|
+
/** Types whose contents the declarations do not describe (caller-chosen data). */
|
|
22
|
+
opaque: Set<any>;
|
|
23
|
+
/** Object types that are documented extension points. */
|
|
24
|
+
open: Set<any>;
|
|
25
|
+
/**
|
|
26
|
+
* Union type → `{ registry, provenance }`: the runtime registry its variants are looked up in,
|
|
27
|
+
* which plugins extend, so the union is extensible and checked against the caller's registry.
|
|
28
|
+
*/
|
|
29
|
+
registries: Map<any, any>;
|
|
30
|
+
/** Property symbols the declarations require but the runtime defaults. */
|
|
31
|
+
runtimeOptional: Set<any>;
|
|
32
|
+
widened: Map<any, any>;
|
|
33
|
+
/** Alias names of homomorphic mapped wrappers (`DeepPartial`) that pass primitives through unchanged. */
|
|
34
|
+
wrappers: Set<any>;
|
|
35
|
+
/** Type → builder of a replacement node, for positions the declarations do not describe faithfully. */
|
|
36
|
+
overrides: Map<any, any>;
|
|
37
|
+
definitions: {};
|
|
38
|
+
names: Map<any, any>;
|
|
39
|
+
usedNames: Set<any>;
|
|
40
|
+
sharedUnions: Map<any, any>;
|
|
41
|
+
emit(type: any): any;
|
|
42
|
+
emitPrimitive(type: any): {
|
|
43
|
+
kind: string;
|
|
44
|
+
value?: never;
|
|
45
|
+
} | {
|
|
46
|
+
kind: string;
|
|
47
|
+
value: any;
|
|
48
|
+
} | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Distinct TypeScript types can emit the same node (`string[]` twice via different wrappers); keep one.
|
|
51
|
+
* A large union the package names (`AnimationEasing`) is emitted once as a definition and referenced.
|
|
52
|
+
*/
|
|
53
|
+
emitUnion(type: any): any;
|
|
54
|
+
/**
|
|
55
|
+
* Large unions recur under many properties (an easing name list, a color union). Keyed by
|
|
56
|
+
* their emitted content, so the same union reached through `T` or an optional `T | undefined`
|
|
57
|
+
* is stored once; the first type that produced it names the definition.
|
|
58
|
+
*/
|
|
59
|
+
share(node: any, type: any): any;
|
|
60
|
+
buildUnion(type: any): any;
|
|
61
|
+
/** Callers may name either `T` or the `T | undefined` of an optional property. */
|
|
62
|
+
registryOf(type: any): any;
|
|
63
|
+
withDiscriminator(union: any, members: any, registered: any): any;
|
|
64
|
+
/**
|
|
65
|
+
* A property present in every object member whose literal values are disjoint. Array members
|
|
66
|
+
* are left out: the engine tells arrays from objects by runtime kind, so `T | T[]` (which
|
|
67
|
+
* TypeScript flattens into one union) still discriminates its object members.
|
|
68
|
+
*/
|
|
69
|
+
discriminatorOf(members: any): any;
|
|
70
|
+
isDiscriminator(members: any, name: any): boolean;
|
|
71
|
+
/**
|
|
72
|
+
* What TypeScript's default library declares a type to be, also when wrapped in a generic such as
|
|
73
|
+
* `DeepPartial<T>`: `{ host: name }` for a platform class (an interface with a global constructor:
|
|
74
|
+
* `Date`, `CanvasGradient`, `HTMLElement`), `{}` for an options dictionary it declares (`Intl.
|
|
75
|
+
* NumberFormatOptions`), opaque either way since the library's own types are no pinned source (D5);
|
|
76
|
+
* undefined for anything else. A mapped type (`Partial<T>`, `Pick`, `Omit`, `Record`) is declared
|
|
77
|
+
* there too, as an anonymous type literal, but it is an object with the properties it maps (D3, D6).
|
|
78
|
+
*/
|
|
79
|
+
libraryType(type: any): any;
|
|
80
|
+
emitObjectLike(type: any): any;
|
|
81
|
+
isLibraryDeclared(symbol: any): any;
|
|
82
|
+
/**
|
|
83
|
+
* Homomorphic wrappers such as `DeepPartial<T>` also map over primitives and arrays. A wrapped
|
|
84
|
+
* array is recognized by its numeric index plus the built-in `length`, and keeps its
|
|
85
|
+
* (partial) element type; a wrapped primitive is still that primitive. Only the wrappers
|
|
86
|
+
* named in `wrappers` qualify: `Wrap<T> = { v: T }` is an object, whatever `T` is.
|
|
87
|
+
*/
|
|
88
|
+
emitUnwrapped(type: any): any;
|
|
89
|
+
emitWrappedArray(type: any): any;
|
|
90
|
+
emitArray(type: any): any;
|
|
91
|
+
/** One shared definition per type, so repeated and recursive types stay finite. */
|
|
92
|
+
reference(type: any, build?: () => {
|
|
93
|
+
kind: string;
|
|
94
|
+
values: any;
|
|
95
|
+
additional?: never;
|
|
96
|
+
provenance?: never;
|
|
97
|
+
properties?: never;
|
|
98
|
+
} | {
|
|
99
|
+
kind: string;
|
|
100
|
+
additional: string;
|
|
101
|
+
provenance: {
|
|
102
|
+
confidence: string;
|
|
103
|
+
sources: {
|
|
104
|
+
source: any;
|
|
105
|
+
pointer: string;
|
|
106
|
+
}[];
|
|
107
|
+
} | {
|
|
108
|
+
confidence: string;
|
|
109
|
+
sources: {
|
|
110
|
+
source: any;
|
|
111
|
+
}[];
|
|
112
|
+
};
|
|
113
|
+
properties: {
|
|
114
|
+
[k: string]: any;
|
|
115
|
+
};
|
|
116
|
+
values?: never;
|
|
117
|
+
}): {
|
|
118
|
+
kind: string;
|
|
119
|
+
ref: any;
|
|
120
|
+
} | {
|
|
121
|
+
kind: string;
|
|
122
|
+
ref?: never;
|
|
123
|
+
};
|
|
124
|
+
uniqueName(base: any): any;
|
|
125
|
+
emitObject(type: any): {
|
|
126
|
+
kind: string;
|
|
127
|
+
values: any;
|
|
128
|
+
additional?: never;
|
|
129
|
+
provenance?: never;
|
|
130
|
+
properties?: never;
|
|
131
|
+
} | {
|
|
132
|
+
kind: string;
|
|
133
|
+
additional: string;
|
|
134
|
+
provenance: {
|
|
135
|
+
confidence: string;
|
|
136
|
+
sources: {
|
|
137
|
+
source: any;
|
|
138
|
+
pointer: string;
|
|
139
|
+
}[];
|
|
140
|
+
} | {
|
|
141
|
+
confidence: string;
|
|
142
|
+
sources: {
|
|
143
|
+
source: any;
|
|
144
|
+
}[];
|
|
145
|
+
};
|
|
146
|
+
properties: {
|
|
147
|
+
[k: string]: any;
|
|
148
|
+
};
|
|
149
|
+
values?: never;
|
|
150
|
+
};
|
|
151
|
+
/** Keys synthesized by mapped types have no declaration of their own; they cite their owner type. */
|
|
152
|
+
emitProperty(symbol: any, owner: any): {
|
|
153
|
+
deprecated?: {
|
|
154
|
+
replacement?: string;
|
|
155
|
+
message?: string;
|
|
156
|
+
};
|
|
157
|
+
required?: boolean;
|
|
158
|
+
node: any;
|
|
159
|
+
provenance: {
|
|
160
|
+
confidence: string;
|
|
161
|
+
sources: {
|
|
162
|
+
source: any;
|
|
163
|
+
pointer: string;
|
|
164
|
+
}[];
|
|
165
|
+
} | {
|
|
166
|
+
confidence: string;
|
|
167
|
+
sources: {
|
|
168
|
+
source: any;
|
|
169
|
+
}[];
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
import { Provenance } from './provenance.mjs';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Whether the pin's upstream license lets an artifact derived from it be committed and published. */
|
|
2
|
+
export function isRedistributable(pin: any): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* The artifact for `library` from the install under `root`, as deterministic text carrying the
|
|
5
|
+
* digest of its own content; never a malformed one, nor one with a fact that does not trace to its source.
|
|
6
|
+
*/
|
|
7
|
+
export function generateArtifact(root: any, library: any, pin: any): {
|
|
8
|
+
artifact: {
|
|
9
|
+
[k: string]: any;
|
|
10
|
+
};
|
|
11
|
+
text: string;
|
|
12
|
+
};
|
|
13
|
+
/** The libraries this generator builds schema artifacts for: `chartjs`, `echarts`, `highcharts`. */
|
|
14
|
+
export const LIBRARIES: string[];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function generateHighcharts(root: any, pin: any): {
|
|
2
|
+
irVersion: number;
|
|
3
|
+
library: any;
|
|
4
|
+
libraryVersion: any;
|
|
5
|
+
coverage: string;
|
|
6
|
+
generator: {
|
|
7
|
+
name: any;
|
|
8
|
+
version: any;
|
|
9
|
+
};
|
|
10
|
+
sources: {
|
|
11
|
+
[x: number]: {
|
|
12
|
+
kind: string;
|
|
13
|
+
locator: string;
|
|
14
|
+
integrity: any;
|
|
15
|
+
license: any;
|
|
16
|
+
};
|
|
17
|
+
typescript: {
|
|
18
|
+
kind: string;
|
|
19
|
+
locator: string;
|
|
20
|
+
integrity: any;
|
|
21
|
+
license: any;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
definitions: any;
|
|
25
|
+
root: any;
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the schema of `library` from the project's own install and writes it next to it. Only for
|
|
3
|
+
* libraries whose schema cannot ship with their adapter; the generator must find every declaration
|
|
4
|
+
* shape and runtime fact it relies on in that install, or nothing is written.
|
|
5
|
+
* @param {string} root
|
|
6
|
+
* @param {string} library
|
|
7
|
+
* @returns {{ path: string, version: string, digest: string, integrity: string }}
|
|
8
|
+
*/
|
|
9
|
+
export function buildLocalSchema(root: string, library: string): {
|
|
10
|
+
path: string;
|
|
11
|
+
version: string;
|
|
12
|
+
digest: string;
|
|
13
|
+
integrity: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The upstream pin for `library` from upstream-sources.json; throws `UpstreamError` when there is none. */
|
|
2
|
+
export function pinOf(library: any): any;
|
|
3
|
+
/**
|
|
4
|
+
* The TypeScript this generator was verified with. Its lib files decide the members of the DOM and
|
|
5
|
+
* built-in types the declarations name, so another version builds another artifact (CG-07-06).
|
|
6
|
+
*/
|
|
7
|
+
export function compilerPin(): any;
|
|
8
|
+
/** Throws `UpstreamError` unless `version` (the TypeScript the generator loaded) is the pinned compiler. */
|
|
9
|
+
export function verifiedCompiler(version: any): any;
|
|
10
|
+
/**
|
|
11
|
+
* The directory of a package an artifact names as a source: the pinned compiler is the TypeScript
|
|
12
|
+
* this generator loads (its own exact dependency); a library is the project's install under `root`.
|
|
13
|
+
*/
|
|
14
|
+
export function sourceDirectory(root: any, packageName: any): string;
|
|
15
|
+
/** Upstream pin from upstream-sources.json, verified against what npm installed in this repository. */
|
|
16
|
+
export function verifiedUpstream(root: any, library: any): any;
|
|
17
|
+
/** `sha256-<base64>` over every file of an installed package, path and content: what the schema was derived from. */
|
|
18
|
+
export function contentIntegrity(directory: any): string;
|
|
19
|
+
/**
|
|
20
|
+
* The pin for the version a project actually installed: the same major as this generator's pin,
|
|
21
|
+
* with the integrity of that install (its npm lockfile entry, or a hash of its files), so the
|
|
22
|
+
* facts derived from it stay traceable to exactly what was read.
|
|
23
|
+
*/
|
|
24
|
+
export function installedUpstream(root: any, library: any): any;
|
|
25
|
+
/**
|
|
26
|
+
* The project's install cannot be used: not installed, another major than the generator supports,
|
|
27
|
+
* a library whose schema ships with its adapter, or declarations and runtime the generator cannot
|
|
28
|
+
* read. A situation for the user to resolve, not a defect of the generator.
|
|
29
|
+
*/
|
|
30
|
+
export class UpstreamError extends Error {
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema built for `library` at `version` in the project at `root`.
|
|
3
|
+
* @param {string} root
|
|
4
|
+
* @param {string} library
|
|
5
|
+
* @param {string} version
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function localSchemaPath(root: string, library: string, version: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Why a schema built on the user's machine cannot be used by this ChartGuard, or `undefined` when its
|
|
11
|
+
* own generator built it with its own compiler: another generator or TypeScript reads the same install
|
|
12
|
+
* differently, so its schema is rebuilt, never used as if it were this one's (CG-07-06).
|
|
13
|
+
* @param {unknown} artifact the parsed schema file
|
|
14
|
+
* @returns {string | undefined}
|
|
15
|
+
*/
|
|
16
|
+
export function otherBuild(artifact: unknown): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Where schemas that may not be redistributed (Highcharts) are written: under the project's own
|
|
19
|
+
* node_modules, so never tracked by git and never inside a package's `files`. A module of its own,
|
|
20
|
+
* so tools that only look a schema up (the CLI) do not load the generator and the TypeScript compiler.
|
|
21
|
+
*/
|
|
22
|
+
export const LOCAL_ARTIFACTS: "node_modules/.cache/chartguard";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-checks a generated in-memory entry file against installed declarations.
|
|
3
|
+
* Declarations are only parsed and type-checked; nothing is executed.
|
|
4
|
+
* A previous program for the same root lets TypeScript reuse its parsed declaration files.
|
|
5
|
+
*/
|
|
6
|
+
export function createEntryProgram(root: any, entryText: any, previous: any): {
|
|
7
|
+
program: ts.Program;
|
|
8
|
+
checker: ts.TypeChecker;
|
|
9
|
+
entry: ts.SourceFile | undefined;
|
|
10
|
+
};
|
|
11
|
+
/** The type named by each `export type Name = ...` alias in the entry file. */
|
|
12
|
+
export function exportedAliasTypes(checker: any, entry: any): Map<any, any>;
|
|
13
|
+
import ts from 'typescript';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which published declaration a fact cites, and how that becomes a provenance record.
|
|
3
|
+
* Pointers are package-relative (`chart.js/dist/types/index.d.ts:12`); local paths never leak.
|
|
4
|
+
* Only declarations inside the pinned package count: TypeScript's own lib (`Pick`, `Partial`)
|
|
5
|
+
* and other installed packages are not evidence for the pinned source. A fact TypeScript's lib
|
|
6
|
+
* declares (the members of `Array` or of the DOM's event map) cites that lib, as `derived` (CG-07-06).
|
|
7
|
+
*/
|
|
8
|
+
export class Provenance {
|
|
9
|
+
constructor(checker: any, { sourceId, packageName }: {
|
|
10
|
+
sourceId: any;
|
|
11
|
+
packageName: any;
|
|
12
|
+
});
|
|
13
|
+
checker: any;
|
|
14
|
+
sourceId: any;
|
|
15
|
+
prefix: string;
|
|
16
|
+
/** The pinned-package-relative path of a symbol's declaration, if it is declared there. */
|
|
17
|
+
pinnedPath(symbol: any): any;
|
|
18
|
+
isPublished: (symbol: any) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The published symbol an object type should cite: its alias when published, else its own
|
|
21
|
+
* symbol, else what it is composed from, else the published type its (generator-local) alias names.
|
|
22
|
+
*/
|
|
23
|
+
ownerOf(type: any): any;
|
|
24
|
+
/**
|
|
25
|
+
* `A & { … }` cites its first published member; a lib mapped type over a package type
|
|
26
|
+
* (`Pick<LabelOption, …>`, `Omit<…>`) cites that type. Each property still cites its own declaration.
|
|
27
|
+
*/
|
|
28
|
+
ownerOfComposite(type: any): any;
|
|
29
|
+
/** `export type Dataset_bar = ChartDataset<'bar'>` in the entry file names `ChartDataset`. */
|
|
30
|
+
aliasTarget(type: any): any;
|
|
31
|
+
/** The `typescript/lib/…` path of a symbol declared in TypeScript's own lib files. */
|
|
32
|
+
libPath(symbol: any): any;
|
|
33
|
+
/** A fact without a declaration in the pinned package cannot claim authority: it is `derived`. */
|
|
34
|
+
of(symbol: any): {
|
|
35
|
+
confidence: string;
|
|
36
|
+
sources: {
|
|
37
|
+
source: any;
|
|
38
|
+
pointer: string;
|
|
39
|
+
}[];
|
|
40
|
+
} | {
|
|
41
|
+
confidence: string;
|
|
42
|
+
sources: {
|
|
43
|
+
source: any;
|
|
44
|
+
}[];
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export function runtimePointer(root: any, packageName: any, fact: any): string;
|
|
2
|
+
/**
|
|
3
|
+
* The lines after the one matching `pattern`, up to (not including) the first that starts with
|
|
4
|
+
* `end`, and `pointerAt(i)` citing the i-th of them.
|
|
5
|
+
*/
|
|
6
|
+
export function runtimeSection(root: any, packageName: any, { end, ...fact }: {
|
|
7
|
+
[x: string]: any;
|
|
8
|
+
end: any;
|
|
9
|
+
}): {
|
|
10
|
+
pointer: string;
|
|
11
|
+
lines: string[];
|
|
12
|
+
pointerAt: (offset: any) => string;
|
|
13
|
+
};
|
|
14
|
+
/** An authoritative provenance record citing one runtime line of the pinned package. */
|
|
15
|
+
export function runtimeProvenance(root: any, { sourceId, packageName }: {
|
|
16
|
+
sourceId: any;
|
|
17
|
+
packageName: any;
|
|
18
|
+
}, fact: any): {
|
|
19
|
+
confidence: string;
|
|
20
|
+
sources: {
|
|
21
|
+
source: any;
|
|
22
|
+
pointer: string;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chart.js resolves every option through its scriptable resolver (`_descriptors` in
|
|
3
|
+
* helpers.dataset.js defaults to `scriptable: true`; the root descriptor is
|
|
4
|
+
* `_scriptable: (name) => !name.startsWith('on')`), so a function is accepted wherever an option
|
|
5
|
+
* value is, whether or not the declarations say `Scriptable<…>`. The few options a plugin marks
|
|
6
|
+
* non-scriptable (`spacing`, callbacks that are functions anyway) are over-accepted: a false
|
|
7
|
+
* negative, never a false rejection.
|
|
8
|
+
*
|
|
9
|
+
* This pass rewrites the IR reachable from each configuration's `options`: every property whose
|
|
10
|
+
* node does not already accept a function becomes `scriptable`. Union discriminators (`type`)
|
|
11
|
+
* stay literal so variants can still be selected.
|
|
12
|
+
*/
|
|
13
|
+
export function makeOptionsScriptable(definitions: any, configRefs: any): void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The provenance problems of `artifact`, built from the install under `root` (CG-07-06). Each pointer
|
|
3
|
+
* must name a file of the package its source records (the library under `root`, the compiler this
|
|
4
|
+
* generator loads) and a line in it; the declaration an authoritative property cites first must
|
|
5
|
+
* declare that property. A generated artifact is never written with one (D19).
|
|
6
|
+
* @returns {string[]}
|
|
7
|
+
*/
|
|
8
|
+
export function untracedFacts(root: any, artifact: any): string[];
|