@mark1russell7/layout-contract 0.9.6 → 0.9.7
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/build/index.d.ts +9 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +40 -2
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/strategy-catalog.ts +50 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/layout-contract",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.7",
|
|
5
5
|
"description": "The shared contract of the packing and highways layout engines: the input and record formats, the turn rule, margins, tolerances and hard rules.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"layout",
|
package/src/strategy-catalog.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { canonicalJson } from "./hash.ts";
|
|
3
3
|
import type { Supports } from "./record.ts";
|
|
4
4
|
import { type AnyOption, declarationIssues, type ListItem, type NoDefaultReason, optionIssue, type OptionScale, type ValueOption } from "./strategy-space.ts";
|
|
5
|
-
import type { ParamValue, StrategySpace } from "./strategy-space.ts";
|
|
5
|
+
import type { ParamValue, SpaceParam, StageOption, StrategySpace } from "./strategy-space.ts";
|
|
6
6
|
|
|
7
7
|
/** The newest schema of a strategy catalog. A new field is a new version of the schema. */
|
|
8
8
|
export const STRATEGY_CATALOG_SCHEMA = "strategy-catalog/3";
|
|
@@ -167,16 +167,22 @@ export interface SupportProbe {
|
|
|
167
167
|
*
|
|
168
168
|
* - `spaceOnly` tells that the place sets no option, with one sentence that tells why. A stage option without an entry can also have this statement.
|
|
169
169
|
* - `option` names the option of the param, when the option has another name. `value` gives the option value of one param value, and `undefined` when the param value sets no option.
|
|
170
|
+
* - `strategy` is for a stage option that is one value of another strategy. The params of the stage option examine against the declarations of that strategy.
|
|
171
|
+
* `fixed` holds the options that the stage option sets, in the JSON form of their declarations. The params cannot have the name of a fixed option.
|
|
170
172
|
*/
|
|
171
173
|
export type ParamRoute =
|
|
172
174
|
| { readonly spaceOnly: string }
|
|
175
|
+
| { readonly strategy: string; readonly fixed?: Readonly<Record<string, unknown>> }
|
|
173
176
|
| { readonly option?: string; readonly value?: (value: ParamValue) => unknown };
|
|
174
177
|
|
|
175
178
|
/** The options of `checkCatalog`. */
|
|
176
179
|
export interface CatalogCheckOptions {
|
|
177
180
|
/** Each param of these spaces is examined against the declaration of its option. */
|
|
178
181
|
readonly spaces?: readonly StrategySpace[];
|
|
179
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* The routes of the params of `spaces`. The key is `<stage>/<option>.<param>`, or `<stage>/<option>` for a stage option. A route that matches nothing is a fault.
|
|
184
|
+
* Only a stage option can have a `strategy` route.
|
|
185
|
+
*/
|
|
180
186
|
readonly paramRoutes?: Readonly<Record<string, ParamRoute>>;
|
|
181
187
|
readonly probes?: readonly SupportProbe[];
|
|
182
188
|
/** This function runs `owner` with `choice` in its option `option`. It gives `true` for a refusal, or `undefined` if the input cannot go to `owner`. */
|
|
@@ -888,6 +894,41 @@ function checkParamValues(entry: CatalogEntry, engine: string, place: string, op
|
|
|
888
894
|
}
|
|
889
895
|
}
|
|
890
896
|
|
|
897
|
+
/** This function examines each option that a `strategy` route fixes. A fixed option is declared, its value is inside the declaration, and no param has its name. */
|
|
898
|
+
function checkFixed(entry: CatalogEntry, engine: string, name: string, fixed: Readonly<Record<string, unknown>>, params: readonly SpaceParam[], faults: string[]): void {
|
|
899
|
+
for (const [key, value] of Object.entries(fixed)) {
|
|
900
|
+
const declaration = entry.options[key];
|
|
901
|
+
if (declaration === undefined) faults.push(`${entry.key}: the route "${name}" fixes "${key}", and the strategy has no such option.`);
|
|
902
|
+
else {
|
|
903
|
+
const issue = optionIssue(key, value, declaration);
|
|
904
|
+
if (issue !== undefined) faults.push(`${entry.key}: the route "${name}" of the space ${engine} fixes a value outside the declaration. ${issue.message}`);
|
|
905
|
+
}
|
|
906
|
+
if (params.some((p) => p.name === key)) faults.push(`${entry.key}: the route "${name}" fixes "${key}", and the stage option also has the param "${key}".`);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/**
|
|
911
|
+
* This function gives the entry of a stage option: its own entry, or the strategy of its `strategy` route.
|
|
912
|
+
* It gives `null` for a stage option without an entry or a `strategy` route, and `undefined` after a fault.
|
|
913
|
+
*/
|
|
914
|
+
function stageEntry(space: StrategySpace, name: string, option: StageOption, entries: ReadonlyMap<string, CatalogEntry>, check: SpaceCheck): CatalogEntry | undefined | null {
|
|
915
|
+
const own = entries.get(name) ?? entries.get(option.id);
|
|
916
|
+
const route = check.routes[name];
|
|
917
|
+
if (route === undefined || !("strategy" in route)) return own ?? null;
|
|
918
|
+
check.used.add(name);
|
|
919
|
+
if (own !== undefined) {
|
|
920
|
+
check.faults.push(`${own.key}: the route "${name}" names the strategy "${route.strategy}", and the stage option has its own entry.`);
|
|
921
|
+
return undefined;
|
|
922
|
+
}
|
|
923
|
+
const entry = entries.get(route.strategy);
|
|
924
|
+
if (entry === undefined) {
|
|
925
|
+
check.faults.push(`The route "${name}" names the strategy "${route.strategy}", and the catalog has no such entry.`);
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
checkFixed(entry, space.engine, name, route.fixed ?? {}, option.params, check.faults);
|
|
929
|
+
return entry;
|
|
930
|
+
}
|
|
931
|
+
|
|
891
932
|
/** This function examines each param of a space against the declaration of its option, with the routes of the engine. */
|
|
892
933
|
function checkSpaceParams(space: StrategySpace, entries: ReadonlyMap<string, CatalogEntry>, check: SpaceCheck): void {
|
|
893
934
|
const { routes, used, faults, notMatched, spaceOnly } = check;
|
|
@@ -899,8 +940,9 @@ function checkSpaceParams(space: StrategySpace, entries: ReadonlyMap<string, Cat
|
|
|
899
940
|
for (const stage of space.stages) {
|
|
900
941
|
for (const option of stage.options) {
|
|
901
942
|
const name = `${stage.name}/${option.id}`;
|
|
902
|
-
const entry =
|
|
903
|
-
if (entry === undefined)
|
|
943
|
+
const entry = stageEntry(space, name, option, entries, check);
|
|
944
|
+
if (entry === undefined) continue;
|
|
945
|
+
if (entry === null) {
|
|
904
946
|
const reason = routes[name];
|
|
905
947
|
if (reason !== undefined && "spaceOnly" in reason) {
|
|
906
948
|
used.add(name);
|
|
@@ -918,6 +960,10 @@ function checkSpaceParams(space: StrategySpace, entries: ReadonlyMap<string, Cat
|
|
|
918
960
|
else faults.push(`${entry.key}: the route "${place}" says that the param is only in the space, and the strategy has this option.`);
|
|
919
961
|
continue;
|
|
920
962
|
}
|
|
963
|
+
if (route !== undefined && "strategy" in route) {
|
|
964
|
+
faults.push(`${entry.key}: the route "${place}" names a strategy, and only a stage option can have a strategy route.`);
|
|
965
|
+
continue;
|
|
966
|
+
}
|
|
921
967
|
const target = route?.option ?? param.name;
|
|
922
968
|
if (entry.options[target] === undefined) {
|
|
923
969
|
if (route === undefined) notMatched.push(place);
|