@mark1russell7/capacity 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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1110 -2
  3. package/build/index.d.ts +858 -0
  4. package/build/index.d.ts.map +1 -0
  5. package/build/index.js +1713 -0
  6. package/build/index.js.map +1 -0
  7. package/build/instance-check-Bt-SI8va.js +1732 -0
  8. package/build/instance-check-Bt-SI8va.js.map +1 -0
  9. package/build/instance-sZmVOOvz.d.ts +801 -0
  10. package/build/instance-sZmVOOvz.d.ts.map +1 -0
  11. package/build/schema.d.ts +69 -0
  12. package/build/schema.d.ts.map +1 -0
  13. package/build/schema.js +325 -0
  14. package/build/schema.js.map +1 -0
  15. package/limits/alerts-routes.line.json +78 -0
  16. package/limits/alerts-scale.limits.json +10 -0
  17. package/limits/alerts-start-gate.limits.json +1149 -0
  18. package/limits/alerts-start-routes-limit-home.bracket.json +543 -0
  19. package/limits/alerts-start-routes-limit-mid.bracket.json +464 -0
  20. package/limits/alerts-start-routes-limit.bracket.json +579 -0
  21. package/limits/alerts-tail-gate.limits.json +610 -0
  22. package/package.json +85 -3
  23. package/src/app-check.ts +477 -0
  24. package/src/app-metrics.ts +105 -0
  25. package/src/app.ts +239 -0
  26. package/src/check.ts +253 -0
  27. package/src/composition.ts +680 -0
  28. package/src/demand.ts +312 -0
  29. package/src/fit.ts +153 -0
  30. package/src/forms.ts +358 -0
  31. package/src/gate.ts +237 -0
  32. package/src/index.ts +143 -0
  33. package/src/instance-check.ts +122 -0
  34. package/src/instance.ts +84 -0
  35. package/src/knee.ts +606 -0
  36. package/src/law.ts +236 -0
  37. package/src/limit.ts +112 -0
  38. package/src/names.ts +19 -0
  39. package/src/observe.ts +74 -0
  40. package/src/program.ts +74 -0
  41. package/src/scale.ts +617 -0
  42. package/src/schema.ts +263 -0
  43. package/src/value.ts +206 -0
  44. package/src/workload-check.ts +130 -0
  45. package/src/workload.ts +88 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instance-check-Bt-SI8va.js","names":["problem"],"sources":["../src/law.ts","../src/names.ts","../src/program.ts","../src/check.ts","../src/value.ts","../src/workload.ts","../src/workload-check.ts","../src/app.ts","../src/app-check.ts","../src/demand.ts","../src/composition.ts","../src/instance.ts","../src/instance-check.ts"],"sourcesContent":["import type { Quantity } from \"@mark1russell7/quantity\";\nimport type { Expr } from \"@mark1russell7/vex\";\n\n/** This text is the format of a law file. */\nexport const LAW_FORMAT = \"capacity-law/1\";\n\n/** This number is the most variables that a law can have. The check reads each corner of their ranges. */\nexport const MAX_VARIABLES = 8;\n\n/** A scale tells how a variable moves through its range: in equal steps or in equal ratios. */\nexport type Scale = \"linear\" | \"log\";\n\n/**\n * A measure is the quantity that a law gives. Its unit is a canonical unit of\n * `@mark1russell7/quantity`, for example `{core}·ms/{request}` or `MiB`.\n *\n * CPU time is in core-seconds. Thus a request rate times a CPU cost of one request converts to\n * `{core}`. That unit is the unit of the CPU of an instance.\n */\nexport interface Measure {\n readonly id: string;\n readonly unit: string;\n}\n\n/**\n * A variable is one load variable of a law. The law holds from `min` to `max`, in the unit of the\n * variable. A value outside this range is an extrapolation.\n */\nexport interface Variable {\n readonly id: string;\n readonly unit: string;\n readonly min: number;\n readonly max: number;\n readonly scale: Scale;\n}\n\n/** A constant is one fitted number of a law. The program of the form reads it by its `id`. */\nexport interface Constant {\n readonly id: string;\n readonly value: number;\n}\n\n/**\n * A form is the math of a law. Its program is a Vex expression that reads each variable and each\n * constant by its id. Its `id` names the form, for example `hinge`.\n */\nexport interface Form {\n readonly id: string;\n readonly program: Expr;\n}\n\n/** A condition value is a fact that a law holds constant: a name, a number, a flag or an amount with a unit. */\nexport type ConditionValue = string | number | boolean | Quantity;\n\n/**\n * A residual kind tells how a fit compares a measured value with a law. An absolute residual is\n * their difference. A relative residual is their ratio less 1.\n */\nexport type ResidualKind = \"absolute\" | \"relative\";\n\n/** A fit error sums the residuals of a form: the mean of their sizes, and the root of the mean of their squares. */\nexport interface FitError {\n readonly mae: number;\n readonly rmse: number;\n}\n\n/** A loser is a form that the fit also tried and did not keep, with its error. */\nexport interface Loser {\n readonly form: string;\n readonly error: FitError;\n}\n\n/**\n * A fit tells how well a law agrees with its points. Each residual compares one measured point\n * with a fit that did not use that point. The list `losers` keeps each form that lost.\n */\nexport interface Fit {\n readonly method: string;\n readonly residual: ResidualKind;\n readonly residuals: readonly number[];\n readonly losers: readonly Loser[];\n}\n\n/** A run is one CI run that measured points of a law: its address, its commit and its time. */\nexport interface Run {\n readonly url: string;\n readonly commit: string;\n readonly date: string;\n}\n\n/**\n * A run point is one point of the fit of a law. Its load gives the value of each variable of the law, in the unit of the\n * variable. Its value is the value of the measure, in the unit of the measure.\n */\nexport interface RunPoint {\n readonly load: Readonly<Record<string, number>>;\n readonly value: number;\n /** This number is the index of the run of the point in `evidence.runs`. */\n readonly run: number;\n /** This text is the start time of the job of the point, as an ISO 8601 time. A run can have more than one job. */\n readonly job: string;\n}\n\n/** The evidence of a law is the list of the runs that measured its points. */\nexport interface Evidence {\n readonly runs: readonly Run[];\n}\n\n/**\n * The noise of a law is the noise floor of its measure on one CPU model. A difference of two\n * measurements below the floor is not a result. Thus a gate does not read it as a change.\n */\nexport interface Noise {\n /**\n * This amount is the noise floor, in the unit of the measure. It is two standard deviations of\n * the differences of A/A pairs: two equal cases, each in its own container.\n */\n readonly floor: number;\n /** This name is the CPU model of the runs that measured the floor. */\n readonly cpu: string;\n /** These runs measured the floor. They are not always the runs of the evidence. */\n readonly runs: readonly Run[];\n}\n\n/**\n * The idle base of a law is the base that its fit subtracted from each point. It is the median of each idle measure over\n * some idle bases of its subject. A gate run with no idle case reads the points of the law net of this base.\n */\nexport interface LawIdle {\n /** This text is the load of the bases: the canonical JSON of their instance and their connections. */\n readonly load: string;\n /** This name is the CPU model of the law, as its condition `cpu.model`. */\n readonly cpu: string;\n /** This count is the idle bases in the median. */\n readonly bases: number;\n /** This count is the runs of those bases. */\n readonly runs: number;\n /** These amounts are the median of each idle measure, by its name. */\n readonly measures: Readonly<Record<string, Quantity>>;\n}\n\n/**\n * A law gives one measure of a subject as a function of its load variables. It holds for the\n * ranges of its variables and for its conditions.\n *\n * Each row of `replicates` is one more fit of the constants, in the order of `constants`. The rows\n * come from resamples of the points. Thus the spread of the rows is the doubt of the constants\n * together, and each query gets its interval from them. `noise` is the noise of one measurement.\n *\n * The list `points` keeps each point that the fit used, in the order of `fit.residuals`. A law file from before the\n * points has no list.\n *\n * A law with the condition `idle` \"net\" keeps the idle base of its fit in `idle`. A law of gross values has no idle base.\n */\nexport interface Law {\n readonly format: typeof LAW_FORMAT;\n readonly id: string;\n readonly title: string;\n readonly subject: string;\n readonly measure: Measure;\n readonly variables: readonly Variable[];\n readonly conditions: Readonly<Record<string, ConditionValue>>;\n readonly form: Form;\n readonly constants: readonly Constant[];\n readonly replicates: readonly (readonly number[])[];\n readonly fit: Fit;\n readonly points?: readonly RunPoint[];\n readonly evidence: Evidence;\n readonly noise: Noise;\n readonly idle?: LawIdle;\n}\n\n/** A problem code names the part of a law, or of a query, that is not correct. */\nexport type ProblemCode =\n | \"shape\"\n | \"format\"\n | \"id\"\n | \"unit\"\n | \"range\"\n | \"condition\"\n | \"program\"\n | \"read\"\n | \"constant\"\n | \"replicates\"\n // The replicates of a constant have one value. This is a fault of the data of the fit, not of the law file.\n | \"flat\"\n | \"value\"\n | \"fit\"\n | \"evidence\"\n | \"noise\"\n | \"idle\"\n | \"point\"\n | \"level\"\n | \"knee\";\n\n/** A problem tells what is not correct, and where: `path` is the path of the field in the record. */\nexport interface Problem<Code extends string> {\n readonly code: Code;\n readonly path: string;\n readonly message: string;\n}\n\n/** A law problem tells what is not correct in a law, or in a query of a law. */\nexport type LawProblem = Problem<ProblemCode>;\n\n/** This number is the level of an interval when a query gives none. */\nexport const DEFAULT_LEVEL = 0.95;\n\n/**\n * This function gives the least count of values that can show an interval of a level. An end of\n * the interval needs one value beyond it. Thus the level 0.95 needs 40 values.\n */\nexport const leastCount = (level: number): number => Math.ceil(2 / (1 - level) - 1e-9);\n\n/**\n * This function gives the number of different draws of a bootstrap of `groups` whole groups. A run draws as many\n * groups as the data has, with replacement, and a fit does not see their order. Thus the number is `C(2g - 1, g)`.\n */\nexport const bootstrapDraws = (groups: number): number => {\n let draws = 1;\n for (let i = 1; i <= groups; i++) draws = (draws * (groups - 1 + i)) / i;\n return Math.round(draws);\n};\n\n/**\n * This function gives the least count of groups that a bootstrap of whole groups needs for an interval of a level.\n * A run draws `g` groups from `g` groups with replacement, and a fit does not see their order. Thus `g` groups give\n * `C(2g - 1, g)` different draws (`bootstrapDraws`). Each different draw gives at most one different value, and the\n * interval needs `leastCount(level)` values. Thus the level 0.95 needs 5 groups: 4 groups give only 35 different draws.\n */\nexport const leastGroups = (level: number): number => {\n const need = leastCount(level);\n let groups = 1;\n while (bootstrapDraws(groups) < need) groups += 1;\n return groups;\n};\n","// The rules of the names and the times that a law file and a workload file share.\n\n/** An id is lower-case words joined by `.`, `-` or `/`. A law, a subject, a measure, a form, a condition, a workload and a class each have an id. */\nexport const SLUG: RegExp = /^[a-z0-9]+(?:[./-][a-z0-9]+)*$/;\n\n/** A name that a program reads: a variable, a constant or a level. */\nexport const NAME: RegExp = /^[a-z][A-Za-z0-9]*$/;\n\nconst UTC = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?Z$/;\n\n/** This function tells if a text is a UTC time, for example `2026-11-18T14:00:00Z`. */\nexport const isUtc = (text: string): boolean => UTC.test(text) && Number.isFinite(Date.parse(text));\n\n/** This function tells if a value is a finite number. */\nexport const finite = (value: number): boolean => typeof value === \"number\" && Number.isFinite(value);\n\n/** This function gives the first value that a list has two times, or undefined. */\nexport const repeated = (values: readonly string[]): string | undefined =>\n values.find((value, index) => values.indexOf(value) !== index);\n","import { err, ok, type Result } from \"@mark1russell7/optional\";\nimport { space, type AnyDomain, type Expr, type Program } from \"@mark1russell7/vex\";\nimport { tiered } from \"@mark1russell7/vex-compiler\";\nimport { NumDomain } from \"@mark1russell7/vex-domains\";\n\n/** These domains give the ops of the program of a law: the ops of numbers. */\nexport const LAW_DOMAINS: readonly AnyDomain[] = [NumDomain];\n\n/**\n * These programs are the compiled form of each expression that a law reads. A law keeps its expression, thus each expression\n * compiles one time. Tier 2 of the compiler runs generated code, with the results of the interpreter. A page that does not\n * permit generated code runs tier 1.\n */\nconst compiled = new WeakMap<Expr, Program>();\n\n/** This function gives the compiled program of an expression: the program of the cache, or a new program that goes into the cache. */\nconst programFor = (expr: Expr): Program => {\n const known = compiled.get(expr);\n if (known !== undefined) return known;\n const made = tiered(expr, { domains: LAW_DOMAINS });\n compiled.set(expr, made);\n return made;\n};\n\n/** This function gives the result of a program at each record: a finite number, or the text of its error. */\nconst resultsOf = (expr: Expr, records: readonly Readonly<Record<string, number>>[]): readonly Result<number, string>[] => {\n const program = programFor(expr);\n const at = space.array(records);\n const results: Result<number, string>[] = [];\n for (const origin of at.keys) {\n const result = program.run({ space: at, origin });\n if (!result.ok) results.push(err(`${result.error.code} ${result.error.message}`));\n else if (typeof result.value !== \"number\" || !Number.isFinite(result.value)) {\n results.push(err(\"the program gave a value that is not a finite number\"));\n } else results.push(ok(result.value));\n }\n return results;\n};\n\n/**\n * This function gives the value of a program at each record, in the order of the records. It gives\n * the text of the first error when a record has no finite value.\n */\nexport const valuesOf = (\n program: Expr,\n records: readonly Readonly<Record<string, number>>[],\n): Result<readonly number[], string> => {\n const values: number[] = [];\n for (const result of resultsOf(program, records)) {\n if (result.tag === \"err\") return result;\n values.push(result.value);\n }\n return ok(values);\n};\n\n/**\n * This function gives the value of a program at each record, in the order of the records. A record\n * with no finite value gives undefined.\n */\nexport const valuesAt = (program: Expr, records: readonly Readonly<Record<string, number>>[]): readonly (number | undefined)[] =>\n resultsOf(program, records).map((result) => (result.tag === \"ok\" ? result.value : undefined));\n\n/** This function gives the record that a program reads: the values of the variables and the constants. */\nexport const recordOf = (\n names: readonly string[],\n values: readonly number[],\n base: Readonly<Record<string, number>> = {},\n): Readonly<Record<string, number>> => {\n const record: Record<string, number> = { ...base };\n names.forEach((name, index) => {\n record[name] = values[index] as number;\n });\n return record;\n};\n","import { isCanonicalUnit, isQuantity } from \"@mark1russell7/quantity\";\nimport { deps, parse } from \"@mark1russell7/vex\";\nimport { DEFAULT_LEVEL, LAW_FORMAT, MAX_VARIABLES, leastCount, type Law, type LawProblem, type Run, type Variable } from \"./law.ts\";\nimport { NAME, SLUG, finite, isUtc, repeated } from \"./names.ts\";\nimport { LAW_DOMAINS, recordOf, valuesOf } from \"./program.ts\";\n\nconst COMMIT = /^[0-9a-f]{40}$/;\n\n/**\n * A column of replicates is flat when its width is this share of its largest size or less. The search of a shape\n * stops at a bracket of `SEPARABLE_SEARCH_TOLERANCE` (1e-10) of its start width. Thus a shape at the same edge of its\n * search in each fit gives a flat column. A bootstrap of measured values gives a much wider column.\n */\nconst FLAT_SHARE = 1e-9;\n\n/** This function gives the middle of the range of a variable, on its scale. */\nconst middleOf = (variable: Variable): number =>\n variable.scale === \"log\" ? Math.sqrt(variable.min * variable.max) : (variable.min + variable.max) / 2;\n\n/** This function gives each corner of the ranges of some variables, and their middle. */\nconst cornersOf = (variables: readonly Variable[]): readonly (readonly number[])[] => {\n const corners: number[][] = [];\n for (let mask = 0; mask < 2 ** variables.length; mask += 1) {\n corners.push(variables.map((variable, index) => ((mask >> index) & 1) === 1 ? variable.max : variable.min));\n }\n return [...corners, variables.map(middleOf)];\n};\n\n/**\n * This function examines a law and gives each problem that it finds. A law with no problem gives\n * an empty list.\n *\n * It examines the ids, the units and the ranges. It examines that the program reads each variable\n * and each constant, and no other name. It examines that the law has a finite value at each corner\n * and at the middle of its ranges. It examines that the replicates and the residuals can show an\n * interval of the level 0.95, and that the evidence names its runs. It examines that the noise\n * has a floor of 0 or more, a CPU model and its runs.\n *\n * A law with points must have one point for each residual. Each point must be in the ranges of the\n * variables and name a run of the evidence.\n *\n * The interval of each constant must have a width above 0. A constant with the same value in each\n * replicate is a bound of a search, not a measured value. For example, a shape at the edge of its\n * search in each fit of the bootstrap gives this.\n */\nexport const checkLaw = (law: Law): readonly LawProblem[] => {\n const problems: LawProblem[] = [];\n const add = (code: LawProblem[\"code\"], path: string, message: string): void => {\n problems.push({ code, path, message });\n };\n const slug = (path: string, value: string): void => {\n if (!SLUG.test(value)) add(\"id\", path, `The id \"${value}\" is not lower-case words joined by \".\", \"-\" or \"/\".`);\n };\n\n if (law.format !== LAW_FORMAT) add(\"format\", \"format\", `The format is \"${String(law.format)}\", not \"${LAW_FORMAT}\".`);\n slug(\"id\", law.id);\n slug(\"subject\", law.subject);\n slug(\"measure.id\", law.measure.id);\n slug(\"form.id\", law.form.id);\n if (law.title.trim() === \"\") add(\"id\", \"title\", \"The title is empty.\");\n if (!isCanonicalUnit(law.measure.unit)) add(\"unit\", \"measure.unit\", `\"${law.measure.unit}\" is not a canonical unit.`);\n\n // The variables: a name, a unit and a range that moves.\n if (law.variables.length > MAX_VARIABLES) {\n add(\"range\", \"variables\", `The law has ${law.variables.length} variables. The most is ${MAX_VARIABLES}.`);\n }\n law.variables.forEach((variable, index) => {\n const path = `variables[${index}]`;\n if (!NAME.test(variable.id)) add(\"id\", `${path}.id`, `The name \"${variable.id}\" is not letters and digits that start with a lower-case letter.`);\n if (!isCanonicalUnit(variable.unit)) add(\"unit\", `${path}.unit`, `\"${variable.unit}\" is not a canonical unit.`);\n if (!finite(variable.min) || !finite(variable.max) || !(variable.min < variable.max)) {\n add(\"range\", path, `The range of \"${variable.id}\" does not go from a finite number to a larger finite number.`);\n } else if (variable.scale === \"log\" && !(variable.min > 0)) {\n add(\"range\", path, `The variable \"${variable.id}\" has the scale \"log\", thus its range starts above 0.`);\n }\n });\n const variables = law.variables.map((variable) => variable.id);\n const twoVariables = repeated(variables);\n if (twoVariables !== undefined) add(\"id\", \"variables\", `Two variables have the name \"${twoVariables}\".`);\n\n // The conditions: each is a name with a plain value or a quantity.\n for (const [name, value] of Object.entries(law.conditions)) {\n slug(`conditions.${name}`, name);\n if (typeof value === \"number\" && !finite(value)) add(\"condition\", `conditions.${name}`, `The condition \"${name}\" is not a finite number.`);\n if (typeof value === \"object\" && !isQuantity(value)) {\n add(\"condition\", `conditions.${name}`, `The condition \"${name}\" is not a finite amount in a canonical unit.`);\n }\n }\n\n // The constants and their replicates.\n const constants = law.constants.map((constant) => constant.id);\n if (constants.length === 0) add(\"constant\", \"constants\", \"The law has no constant.\");\n law.constants.forEach((constant, index) => {\n const path = `constants[${index}]`;\n if (!NAME.test(constant.id)) add(\"id\", `${path}.id`, `The name \"${constant.id}\" is not letters and digits that start with a lower-case letter.`);\n if (!finite(constant.value)) add(\"constant\", `${path}.value`, `The constant \"${constant.id}\" is not a finite number.`);\n if (variables.includes(constant.id)) add(\"id\", `${path}.id`, `\"${constant.id}\" names a variable and a constant.`);\n });\n const twoConstants = repeated(constants);\n if (twoConstants !== undefined) add(\"id\", \"constants\", `Two constants have the name \"${twoConstants}\".`);\n\n const least = leastCount(DEFAULT_LEVEL);\n if (law.replicates.length < least) {\n add(\"replicates\", \"replicates\", `The law has ${law.replicates.length} replicates. The level ${DEFAULT_LEVEL} needs ${least}.`);\n }\n const badRow = law.replicates.findIndex((row) => row.length !== constants.length || !row.every(finite));\n const rowsAreGood = badRow === -1;\n if (!rowsAreGood) {\n add(\"replicates\", `replicates[${badRow}]`, `The replicate ${badRow} does not have one finite number for each constant.`);\n } else if (law.replicates.length > 0) {\n law.constants.forEach((constant, index) => {\n const column = law.replicates.map((row) => row[index] as number);\n const low = Math.min(...column);\n const high = Math.max(...column);\n if (finite(constant.value) && (constant.value < low || constant.value > high)) {\n add(\"replicates\", `constants[${index}].value`, `The constant \"${constant.id}\" is outside each of its replicates.`);\n }\n if (high - low <= FLAT_SHARE * Math.max(Math.abs(low), Math.abs(high))) {\n add(\n \"flat\",\n `constants[${index}]`,\n `Each replicate of the constant \"${constant.id}\" has the value ${low}, thus its interval has a width of 0. ` +\n \"A shape at the edge of its search in each fit gives this.\",\n );\n }\n });\n }\n\n // The program: a Vex expression that reads each variable and each constant of this law, and no other name.\n const text = JSON.stringify(law.form.program);\n const parsed = text === undefined ? undefined : parse(text, LAW_DOMAINS);\n if (parsed === undefined || !parsed.ok) {\n add(\"program\", \"form.program\", \"The program is not a Vex expression.\");\n } else {\n const names = [...variables, ...constants];\n const reads = new Set<string>();\n for (const read of deps(parsed.value)) {\n const name = read.path.join(\".\");\n if (read.at.length > 0 || read.axes.length > 0) {\n add(\"read\", \"form.program\", `The program reads \"${name}\" at a different record. A law has one record.`);\n } else if (read.path.length !== 1 || !names.includes(name)) {\n add(\"read\", \"form.program\", `The program reads \"${name}\". The law has no variable and no constant with this name.`);\n } else {\n reads.add(name);\n }\n }\n for (const name of names) {\n if (!reads.has(name)) add(\"read\", \"form.program\", `The program does not read \"${name}\".`);\n }\n\n // The value: a finite number at each corner and at the middle of the ranges, and for each replicate at the middle.\n const rangesAreGood = !problems.some((found) => found.code === \"range\" || found.code === \"id\" || found.code === \"constant\");\n if (rangesAreGood && rowsAreGood && !problems.some((found) => found.code === \"read\")) {\n const estimate = law.constants.map((constant) => constant.value);\n const corners = cornersOf(law.variables).map((corner) => recordOf(constants, estimate, recordOf(variables, corner)));\n const atCorners = valuesOf(parsed.value, corners);\n if (atCorners.tag === \"err\") {\n add(\"value\", \"form.program\", `The law has no value at a corner or at the middle of its ranges: ${atCorners.error}.`);\n }\n const middle = recordOf(variables, law.variables.map(middleOf));\n const atMiddle = valuesOf(parsed.value, law.replicates.map((row) => recordOf(constants, row, middle)));\n if (atMiddle.tag === \"err\") {\n add(\"value\", \"replicates\", `A replicate has no value at the middle of the ranges: ${atMiddle.error}.`);\n }\n }\n }\n\n // The fit: its residuals and each form that lost.\n if (law.fit.method.trim() === \"\") add(\"fit\", \"fit.method\", \"The method of the fit is empty.\");\n if (law.fit.residuals.length < least) {\n add(\"fit\", \"fit.residuals\", `The fit has ${law.fit.residuals.length} residuals. The level ${DEFAULT_LEVEL} needs ${least}.`);\n }\n if (!law.fit.residuals.every(finite)) add(\"fit\", \"fit.residuals\", \"A residual is not a finite number.\");\n law.fit.losers.forEach((loser, index) => {\n const path = `fit.losers[${index}]`;\n slug(`${path}.form`, loser.form);\n if (loser.form === law.form.id) add(\"fit\", `${path}.form`, `The form \"${loser.form}\" is the form of the law, thus it did not lose.`);\n const { mae, rmse } = loser.error;\n if (!finite(mae) || !finite(rmse) || mae < 0 || rmse < mae) {\n add(\"fit\", `${path}.error`, `The error of the form \"${loser.form}\" is not correct: 0 <= mae <= rmse.`);\n }\n });\n const twoLosers = repeated(law.fit.losers.map((loser) => loser.form));\n if (twoLosers !== undefined) add(\"fit\", \"fit.losers\", `Two losers have the form \"${twoLosers}\".`);\n\n // The runs of the evidence and of the noise: each one names its address, its commit and its time.\n const runs = (code: \"evidence\" | \"noise\", path: string, list: readonly Run[]): void => {\n if (list.length === 0) add(code, path, \"The law names no run.\");\n list.forEach((run, index) => {\n const at = `${path}[${index}]`;\n if (!run.url.startsWith(\"https://\")) add(code, `${at}.url`, `The address \"${run.url}\" does not start with \"https://\".`);\n if (!COMMIT.test(run.commit)) add(code, `${at}.commit`, `The commit \"${run.commit}\" is not 40 hexadecimal digits.`);\n if (!isUtc(run.date)) add(code, `${at}.date`, `The date \"${run.date}\" is not a UTC time, for example \"2026-11-18T14:00:00Z\".`);\n });\n };\n // The evidence: the runs that measured the points.\n runs(\"evidence\", \"evidence.runs\", law.evidence.runs);\n\n // The points of the fit: one for each residual, each in the ranges of the variables, each from a run of the evidence.\n if (law.points !== undefined) {\n if (law.points.length !== law.fit.residuals.length) {\n add(\"point\", \"points\", `The law has ${law.points.length} points and ${law.fit.residuals.length} residuals. Each point has one residual.`);\n }\n law.points.forEach((point, index) => {\n const path = `points[${index}]`;\n const names = Object.keys(point.load);\n const other = names.find((name) => !variables.includes(name));\n if (other !== undefined) add(\"point\", `${path}.load.${other}`, `The law has no variable \"${other}\".`);\n for (const variable of law.variables) {\n const load = point.load[variable.id];\n if (load === undefined || !finite(load)) add(\"point\", `${path}.load.${variable.id}`, `The point gives no finite value for the variable \"${variable.id}\".`);\n else if (load < variable.min || load > variable.max) add(\"point\", `${path}.load.${variable.id}`, `The value ${load} is outside the range of \"${variable.id}\".`);\n }\n if (!finite(point.value)) add(\"point\", `${path}.value`, \"The value is not a finite number.\");\n if (!Number.isInteger(point.run) || point.run < 0 || point.run >= law.evidence.runs.length) {\n add(\"point\", `${path}.run`, `The run ${point.run} is not an index of the ${law.evidence.runs.length} runs of the evidence.`);\n }\n if (!Number.isFinite(Date.parse(point.job))) add(\"point\", `${path}.job`, `The job \"${point.job}\" is not a time.`);\n });\n }\n\n // The noise: the floor of the measure on one CPU model, and the runs that measured it.\n if (!finite(law.noise.floor) || law.noise.floor < 0) add(\"noise\", \"noise.floor\", \"The noise floor is not a finite number, 0 or more.\");\n if (law.noise.cpu.trim() === \"\") add(\"noise\", \"noise.cpu\", \"The noise names no CPU model.\");\n runs(\"noise\", \"noise.runs\", law.noise.runs);\n\n // The idle base: a law net of its idle base keeps it, and a law of gross values has none.\n const net = law.conditions[\"idle\"] === \"net\";\n const { idle } = law;\n if (idle === undefined) {\n if (net) add(\"idle\", \"idle\", 'The law has the condition idle \"net\", thus it must keep its idle base.');\n } else {\n if (!net) add(\"idle\", \"idle\", 'The law has an idle base, thus it must have the condition idle \"net\".');\n if (idle.load.trim() === \"\") add(\"idle\", \"idle.load\", \"The idle base names no load.\");\n if (idle.cpu.trim() === \"\") add(\"idle\", \"idle.cpu\", \"The idle base names no CPU model.\");\n const whole = (path: \"bases\" | \"runs\", value: number): void => {\n if (!Number.isInteger(value) || value < 1) add(\"idle\", `idle.${path}`, `The count of ${path} is ${value}, not a whole number of 1 or more.`);\n };\n whole(\"bases\", idle.bases);\n whole(\"runs\", idle.runs);\n if (Number.isInteger(idle.bases) && Number.isInteger(idle.runs) && idle.runs < idle.bases) {\n add(\"idle\", \"idle.runs\", `The idle base has ${idle.runs} runs and ${idle.bases} bases. Each base has 1 run or more.`);\n }\n const measures = Object.entries(idle.measures);\n if (measures.length === 0) add(\"idle\", \"idle.measures\", \"The idle base has no measure.\");\n for (const [name, amount] of measures) {\n slug(`idle.measures.${name}`, name);\n if (!isQuantity(amount)) add(\"idle\", `idle.measures.${name}`, `The idle measure \"${name}\" is not a finite amount in a canonical unit.`);\n }\n }\n\n return problems;\n};\n","import { err, ok, type Result } from \"@mark1russell7/optional\";\nimport { quantile } from \"@mark1russell7/rigor-statistics\";\nimport { DEFAULT_LEVEL, leastCount, type Law, type LawProblem } from \"./law.ts\";\nimport { recordOf, valuesAt, valuesOf } from \"./program.ts\";\n\n/** A load point gives one value for each variable of a law, in the unit of the variable. */\nexport type LoadPoint = Readonly<Record<string, number>>;\n\n/** A range goes from `low` to `high`. */\nexport interface Range {\n readonly low: number;\n readonly high: number;\n}\n\n/** These options set the level of the intervals of a query. The level is 0.95 when a query gives none. */\nexport interface LevelOptions {\n readonly level?: number;\n}\n\n/**\n * A law value is the answer of a law at one load point, in the unit of the measure.\n *\n * The `interval` is the doubt of the law: the spread of its replicates at the point. It always\n * holds the value. The range `run` is where one measured run falls: the interval, made wider by\n * the residuals of the fit. The list `outside` names each variable whose value is outside its\n * range. With a name in this list, the value is an extrapolation.\n */\nexport interface LawValue {\n readonly value: number;\n readonly unit: string;\n readonly level: number;\n readonly interval: Range;\n readonly run: Range;\n readonly outside: readonly string[];\n}\n\n/** A constant interval is the value of one constant of a law and the interval of its replicates. */\nexport interface ConstantInterval {\n readonly id: string;\n readonly value: number;\n readonly level: number;\n readonly interval: Range;\n}\n\nconst problem = (code: LawProblem[\"code\"], path: string, message: string): LawProblem => ({ code, path, message });\n\n/** This function gives the two ends of the share `level` of some values. */\nexport const rangeOf = (values: readonly number[], level: number): Range => ({\n low: quantile(values, (1 - level) / 2),\n high: quantile(values, (1 + level) / 2),\n});\n\n/** This function gives the problem of a level that the law cannot show, or undefined. */\nexport const levelProblem = (law: Law, level: number, residuals: boolean): LawProblem | undefined => {\n if (!(level > 0 && level < 1)) return problem(\"level\", \"level\", `The level ${level} is not between 0 and 1.`);\n const least = leastCount(level);\n if (law.replicates.length < least) {\n return problem(\"level\", \"replicates\", `The level ${level} needs ${least} replicates. The law has ${law.replicates.length}.`);\n }\n if (residuals && law.fit.residuals.length < least) {\n return problem(\"level\", \"fit.residuals\", `The level ${level} needs ${least} residuals. The law has ${law.fit.residuals.length}.`);\n }\n return undefined;\n};\n\n/** This function gives the range of one measured run: the interval of the law, made wider by the residuals. */\nexport const runOf = (law: Law, interval: Range, level: number): Range => {\n const band = rangeOf(law.fit.residuals, level);\n if (law.fit.residual === \"absolute\") return { low: interval.low + band.low, high: interval.high + band.high };\n const corners = [interval.low, interval.high].flatMap((end) => [end * (1 + band.low), end * (1 + band.high)]);\n return { low: Math.min(...corners), high: Math.max(...corners) };\n};\n\n/**\n * This function gives the nearest point of a load point in the ranges of the variables of a law. A point in each range\n * gives undefined. A name that is not a variable of the law, or a value that is not a number, does not change.\n */\nexport const edgePointOf = (law: Law, point: LoadPoint): LoadPoint | undefined => {\n let edge: Record<string, number> | undefined;\n for (const variable of law.variables) {\n const value = point[variable.id];\n if (typeof value !== \"number\" || Number.isNaN(value)) continue;\n const held = Math.min(variable.max, Math.max(variable.min, value));\n if (held !== value) (edge ??= { ...point })[variable.id] = held;\n }\n return edge;\n};\n\n/**\n * This function holds a value of a law past its measures. Each measure of a law is a cost, and no run measured the\n * cost past the edge. Thus the value is the higher of the value of the law and its value at the nearest edge. A\n * cost that falls with the load then stays flat past the edge, and a cost that rises keeps its law. A missing value\n * stays missing, and a missing value at the edge keeps the value of the law.\n */\nexport const heldValue = (value: number | undefined, edge: number | undefined): number | undefined =>\n value === undefined || edge === undefined || !Number.isFinite(edge) ? value : Math.max(value, edge);\n\n/** This count is the most edge points that the cache keeps for one law. A law with one variable has at most two. */\nconst EDGE_POINTS = 64;\n\n/** This cache keeps the values of each law at each edge point, one value for each row: the constants, then each replicate. */\nconst edges = new WeakMap<Law, Map<string, readonly (number | undefined)[]>>();\n\n/**\n * This function gives the values of a law at an edge point, one for each row: row 0 with the constants, then each\n * replicate. Each load past the top of a variable has the same edge point. Thus a search past the measures evaluates\n * the law at the edge one time, and the cache gives the values after that.\n */\nexport const edgeValuesOf = (law: Law, edge: LoadPoint): readonly (number | undefined)[] => {\n const key = law.variables.map((variable) => edge[variable.id]).join(\",\");\n let byPoint = edges.get(law);\n const known = byPoint?.get(key);\n if (known !== undefined) return known;\n const names = law.constants.map((constant) => constant.id);\n const rows = [law.constants.map((constant) => constant.value), ...law.replicates];\n const values = valuesAt(law.form.program, rows.map((row) => recordOf(names, row, edge)));\n if (byPoint === undefined || byPoint.size >= EDGE_POINTS) edges.set(law, (byPoint = new Map()));\n byPoint.set(key, values);\n return values;\n};\n\n/** These values are the value of a law at a point with its constants, then with each replicate, and the variables outside their ranges. */\nexport interface PointValues {\n readonly values: readonly [number, ...number[]];\n readonly outside: readonly string[];\n}\n\n/**\n * This function evaluates a law at a load point with its constants, then with each replicate. The\n * point gives each variable of the law, and no other name.\n *\n * Past the range of a variable, each value holds, as heldValue tells.\n * It gives a problem for a point that the law cannot read, and for a value that is not finite.\n */\nexport const pointValuesOf = (law: Law, point: LoadPoint): Result<PointValues, LawProblem> => {\n const variables = law.variables.map((variable) => variable.id);\n const unknown = Object.keys(point).find((name) => !variables.includes(name));\n if (unknown !== undefined) return err(problem(\"point\", unknown, `The law has no variable \"${unknown}\".`));\n const load: Record<string, number> = {};\n for (const name of variables) {\n const value = point[name];\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n return err(problem(\"point\", name, `The point gives no finite value for the variable \"${name}\".`));\n }\n load[name] = value;\n }\n\n const names = law.constants.map((constant) => constant.id);\n const constants = law.constants.map((constant) => constant.value);\n const values = valuesOf(law.form.program, [recordOf(names, constants, load), ...law.replicates.map((row) => recordOf(names, row, load))]);\n if (values.tag === \"err\") return err(problem(\"value\", \"form.program\", `The law has no value at this point: ${values.error}.`));\n const outside = law.variables\n .filter((variable) => (load[variable.id] as number) < variable.min || (load[variable.id] as number) > variable.max)\n .map((variable) => variable.id);\n const edge = outside.length === 0 ? undefined : edgePointOf(law, load);\n if (edge === undefined) return ok({ values: values.value as readonly [number, ...number[]], outside });\n const atEdge = edgeValuesOf(law, edge);\n const held = values.value.map((value, row) => heldValue(value, atEdge[row]) ?? value);\n return ok({ values: held as readonly number[] as readonly [number, ...number[]], outside });\n};\n\n/** This function gives the interval of some replicate values at the share `level`, made wider to hold `value`. */\nexport const intervalOf = (value: number, spread: readonly number[], level: number): Range => {\n // At a bend of a form, each replicate can be on one side of the value. The interval then starts at the value.\n const share = rangeOf(spread, level);\n return { low: Math.min(share.low, value), high: Math.max(share.high, value) };\n};\n\n/**\n * This function gives the value of a law at a load point, with its interval. The point gives each\n * variable of the law, and no other name.\n *\n * The function evaluates the program with the constants, then with each replicate. The interval is\n * the share `level` of the values of the replicates, made wider to hold the value.\n *\n * The function gives a problem for a point that the law cannot read. It also gives a problem for a\n * level that the law cannot show, and for a value that is not finite.\n */\nexport const lawValue = (law: Law, point: LoadPoint, options: LevelOptions = {}): Result<LawValue, LawProblem> => {\n const level = options.level ?? DEFAULT_LEVEL;\n const noLevel = levelProblem(law, level, true);\n if (noLevel !== undefined) return err(noLevel);\n const evaluated = pointValuesOf(law, point);\n if (evaluated.tag === \"err\") return evaluated;\n const [value, ...spread] = evaluated.value.values;\n const interval = intervalOf(value, spread, level);\n return ok({ value, unit: law.measure.unit, level, interval, run: runOf(law, interval, level), outside: evaluated.value.outside });\n};\n\n/**\n * This function gives each constant of a law with the interval of its replicates. It gives a\n * problem for a level that the law cannot show.\n */\nexport const constantIntervals = (law: Law, options: LevelOptions = {}): Result<readonly ConstantInterval[], LawProblem> => {\n const level = options.level ?? DEFAULT_LEVEL;\n const noLevel = levelProblem(law, level, false);\n if (noLevel !== undefined) return err(noLevel);\n return ok(\n law.constants.map((constant, index) => ({\n id: constant.id,\n value: constant.value,\n level,\n interval: rangeOf(law.replicates.map((row) => row[index] as number), level),\n })),\n );\n};\n","import type { Quantity } from \"@mark1russell7/quantity\";\nimport type { Problem } from \"./law.ts\";\n\n/** This text is the format of a workload file. */\nexport const WORKLOAD_FORMAT = \"capacity-workload/1\";\n\n/** This name is the variable that gives the rate of a class. A class and a level cannot use it for a different amount. */\nexport const RATE = \"rate\";\n\n/** Amounts are amounts with names. Each amount is in a canonical unit of `@mark1russell7/quantity`. */\nexport type Amounts = Readonly<Record<string, Quantity>>;\n\n/**\n * A workload class is one kind of request. Its `rate` tells how many requests arrive in a unit of\n * time, for example in `{request}/s`. Its `request` gives each variable of one request, for example\n * the size of its body and its duration.\n *\n * A class is one point. Requests of two sizes are two classes, each with its own rate.\n *\n * The field `of` names the class of the contract of the app that the class is a point of. A class\n * with no `of` is a point of the class of the app with its own id.\n */\nexport interface WorkloadClass {\n readonly id: string;\n readonly of?: string | undefined;\n readonly rate: Quantity;\n readonly request: Amounts;\n}\n\n/**\n * A demand is the load that clients put on a service: its classes and its levels. A level is an\n * amount that stays in the service and does not come with each request, for example the open\n * connections.\n *\n * A demand is extensive. The rates and the levels of two demands add, and they divide between the\n * instances of a service. The variables of one request do not.\n */\nexport interface Demand {\n readonly classes: readonly WorkloadClass[];\n readonly levels: Amounts;\n}\n\n/** A plan is a workload that a person wrote. Its `note` tells where its numbers come from. */\nexport interface PlanSource {\n readonly kind: \"plan\";\n readonly note: string;\n}\n\n/**\n * A metrics source is a workload from the live metrics of an app. Its `origin` names the place of\n * the metrics. The window goes from `from` to `to`, and each is a UTC time.\n */\nexport interface MetricsSource {\n readonly kind: \"metrics\";\n readonly origin: string;\n readonly from: string;\n readonly to: string;\n}\n\n/** A workload source tells where the numbers of a workload come from: a plan or the live metrics. */\nexport type WorkloadSource = PlanSource | MetricsSource;\n\n/** A workload is a demand with a name and a source. A workload file is this record as JSON. */\nexport interface Workload extends Demand {\n readonly format: typeof WORKLOAD_FORMAT;\n readonly id: string;\n readonly title: string;\n readonly source: WorkloadSource;\n}\n\n/** A workload problem code names the part of a workload, or of a query, that is not correct. */\nexport type WorkloadProblemCode =\n | \"shape\"\n | \"format\"\n | \"id\"\n | \"rate\"\n | \"amount\"\n | \"unit\"\n | \"class\"\n | \"source\"\n | \"factor\"\n | \"variable\";\n\n/** A workload problem tells what is not correct, and where: `path` is the path of the field in the workload. */\nexport type WorkloadProblem = Problem<WorkloadProblemCode>;\n\n/** This demand has no class and no level. It is the zero of the sum of demands. */\nexport const NO_DEMAND: Demand = { classes: [], levels: {} };\n","import { convertible, isQuantity, kindOf } from \"@mark1russell7/quantity\";\nimport { NAME, SLUG, isUtc } from \"./names.ts\";\nimport { RATE, WORKLOAD_FORMAT, type Amounts, type Demand, type Workload, type WorkloadProblem } from \"./workload.ts\";\n\n/** This function makes a problem of a workload. */\nexport const workloadProblem = (code: WorkloadProblem[\"code\"], path: string, message: string): WorkloadProblem => ({\n code,\n path,\n message,\n});\n\n/** This function gives the problems of some amounts: the name and the amount of each. */\nconst amountProblems = (amounts: Amounts, path: string, owner: string): readonly WorkloadProblem[] => {\n const problems: WorkloadProblem[] = [];\n for (const [name, amount] of Object.entries(amounts)) {\n const at = `${path}.${name}`;\n if (!NAME.test(name)) {\n problems.push(workloadProblem(\"id\", at, `The name \"${name}\" is not letters and digits that start with a lower-case letter.`));\n }\n if (name === RATE) problems.push(workloadProblem(\"id\", at, `The name \"${RATE}\" is the rate of a class. ${owner} cannot use it.`));\n if (!isQuantity(amount)) problems.push(workloadProblem(\"amount\", at, `\"${name}\" is not a finite amount in a canonical unit.`));\n }\n return problems;\n};\n\n/**\n * This function examines a demand and gives each problem that it finds. A demand with no problem\n * gives an empty list.\n *\n * It examines the id, the class of the app and the rate of each class. It examines the name and the amount of\n * each variable and each level. It examines that a variable has one kind of unit in each class, and that no name is\n * a level and a variable.\n */\nexport const demandProblems = (demand: Demand): readonly WorkloadProblem[] => {\n const problems: WorkloadProblem[] = [];\n /** The class that first gives each variable of a request, and the unit of the variable there. */\n const first = new Map<string, { readonly class: string; readonly unit: string | undefined }>();\n const ids = new Set<string>();\n let twice: string | undefined;\n\n demand.classes.forEach((entry, index) => {\n const path = `classes[${index}]`;\n if (ids.has(entry.id)) twice ??= entry.id;\n ids.add(entry.id);\n if (!SLUG.test(entry.id)) {\n problems.push(workloadProblem(\"id\", `${path}.id`, `The id \"${entry.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n }\n if (entry.of !== undefined && !SLUG.test(entry.of)) {\n problems.push(workloadProblem(\"class\", `${path}.of`, `The class \"${entry.of}\" of the app is not lower-case words joined by \".\", \"-\" or \"/\".`));\n }\n if (!isQuantity(entry.rate)) {\n problems.push(workloadProblem(\"rate\", `${path}.rate`, `The rate of the class \"${entry.id}\" is not a finite amount in a canonical unit.`));\n } else if (kindOf(entry.rate.unit) !== \"frequency\") {\n problems.push(\n workloadProblem(\n \"rate\",\n `${path}.rate`,\n `The rate of the class \"${entry.id}\" is in \"${entry.rate.unit}\". A rate is a count in a unit of time, for example in \"{request}/s\".`,\n ),\n );\n } else if (entry.rate.value < 0) {\n problems.push(workloadProblem(\"rate\", `${path}.rate`, `The rate of the class \"${entry.id}\" is below 0.`));\n }\n\n problems.push(...amountProblems(entry.request, `${path}.request`, \"A variable of a request\"));\n for (const [name, amount] of Object.entries(entry.request)) {\n const unit = isQuantity(amount) ? amount.unit : undefined;\n const before = first.get(name);\n if (before === undefined) {\n first.set(name, { class: entry.id, unit });\n } else if (unit !== undefined && before.unit !== undefined && !convertible(before.unit, unit)) {\n problems.push(\n workloadProblem(\n \"unit\",\n `${path}.request.${name}`,\n `The variable \"${name}\" is in \"${unit}\" here, and it is in \"${before.unit}\" in the class \"${before.class}\".`,\n ),\n );\n }\n }\n });\n if (twice !== undefined) problems.push(workloadProblem(\"id\", \"classes\", `Two classes have the id \"${twice}\".`));\n\n problems.push(...amountProblems(demand.levels, \"levels\", \"A level\"));\n for (const name of Object.keys(demand.levels)) {\n const before = first.get(name);\n if (before !== undefined) {\n problems.push(workloadProblem(\"id\", `levels.${name}`, `\"${name}\" names a level and a variable of the class \"${before.class}\".`));\n }\n }\n return problems;\n};\n\n/**\n * This function examines a workload and gives each problem that it finds. A workload with no\n * problem gives an empty list.\n *\n * It examines the format, the id and the title. It examines the demand with `demandProblems`. It\n * examines that a plan has a note. It examines that the window of a metrics source goes from a UTC\n * time to a later UTC time.\n */\nexport const checkWorkload = (workload: Workload): readonly WorkloadProblem[] => {\n const problems: WorkloadProblem[] = [];\n if (workload.format !== WORKLOAD_FORMAT) {\n problems.push(workloadProblem(\"format\", \"format\", `The format is \"${String(workload.format)}\", not \"${WORKLOAD_FORMAT}\".`));\n }\n if (!SLUG.test(workload.id)) {\n problems.push(workloadProblem(\"id\", \"id\", `The id \"${workload.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n }\n if (workload.title.trim() === \"\") problems.push(workloadProblem(\"id\", \"title\", \"The title is empty.\"));\n problems.push(...demandProblems(workload));\n\n const source = workload.source;\n if (source.kind === \"plan\") {\n if (source.note.trim() === \"\") problems.push(workloadProblem(\"source\", \"source.note\", \"The note of the plan is empty.\"));\n return problems;\n }\n if (source.origin.trim() === \"\") problems.push(workloadProblem(\"source\", \"source.origin\", \"The origin of the metrics is empty.\"));\n for (const end of [\"from\", \"to\"] as const) {\n if (!isUtc(source[end])) {\n problems.push(\n workloadProblem(\"source\", `source.${end}`, `The time \"${source[end]}\" is not a UTC time, for example \"2026-11-18T14:00:00Z\".`),\n );\n }\n }\n if (isUtc(source.from) && isUtc(source.to) && !(Date.parse(source.from) < Date.parse(source.to))) {\n problems.push(workloadProblem(\"source\", \"source\", \"The window of the metrics does not go from a time to a later time.\"));\n }\n return problems;\n};\n","// The contract of an app: the one record that tells the lab and the models how to load an app, how to\n// start it, and how to read its live metrics. Each app gives the same contract, from the bare subjects\n// of layer 1 to the apps of layer 3.\n\nimport type { Problem, Scale } from \"./law.ts\";\n\n/** This text is the format of the contract file of an app. */\nexport const APP_FORMAT = \"capacity-app/1\";\n\n/** This name is the contract file of an app, at the root of its repository. */\nexport const APP_FILE = \"capacity-app.json\";\n\n/**\n * The kind of a load variable tells where the amount is.\n *\n * - `request`: an amount of one request of a class, for example the bytes of its body.\n * - `level`: an amount that stays in the app and does not come with each request, for example the open incidents.\n * - `store`: an amount of a store at the start of the app, for example the bytes of its log.\n * - `run`: an amount that the run of the app gives in its line `amounts`, for example the routes that its configuration makes.\n * No workload and no start case sets it. A start law can read it as its variable.\n */\nexport type VariableKind = \"request\" | \"level\" | \"store\" | \"run\";\n\n/**\n * A range tells the amounts of a variable that the app accepts and that a run can measure. The unit\n * is a canonical unit of `@mark1russell7/quantity`. A range on the scale `log` starts above 0.\n */\nexport interface AppRange {\n readonly unit: string;\n readonly min: number;\n readonly max: number;\n readonly scale: Scale;\n}\n\n/** A load variable of an app is one amount that a workload or a start case sets, or that the run gives. A program of a law reads it by its id. */\nexport interface AppVariable extends AppRange {\n readonly id: string;\n readonly title: string;\n readonly kind: VariableKind;\n}\n\n/**\n * A request of HTTP comes from a client of the app. The path is a template: each `{id}` in it is a request\n * variable of the class. The variable `body`, when it is there, gives the bytes of the body of the request.\n */\nexport interface HttpEntry {\n readonly kind: \"http\";\n readonly method: \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n readonly path: string;\n readonly body?: string | undefined;\n}\n\n/**\n * A service entry tells that the load of a class comes from an outside service that the app calls. The\n * fake of the service reads the workload, and it gives the app the requests of the class at their rates.\n */\nexport interface ServiceEntry {\n readonly kind: \"service\";\n readonly service: string;\n}\n\n/** An entry tells how the requests of a class get to the app: from a client of HTTP, or from an outside service. */\nexport type AppEntry = HttpEntry | ServiceEntry;\n\n/**\n * A class of an app is one kind of request. `rate` is the range of its rate, in a count in a unit of\n * time. `request` names the request variables of one request, by their ids.\n */\nexport interface AppClass {\n readonly id: string;\n readonly title: string;\n readonly rate: AppRange;\n readonly request: readonly string[];\n readonly entry: AppEntry;\n}\n\n/**\n * A command is a program and its arguments, with no shell. `cwd` is the folder of the command, relative to\n * the root of the repository. `env` gives the environment variables that the command adds.\n *\n * Each text of `argv` and of `env` can hold placeholders. The lab puts in their values before the start:\n *\n * - `{port}`: the port of the listener of the process.\n * - `{store}`: the folder of the store of the app.\n * - `{workload}`: the path of the workload file of the run.\n * - `{service.<id>}`: the base URL of the fake of the service `<id>`.\n * - `{variable.<id>}`: the amount of the store or level variable `<id>` at the point, in the unit of the variable.\n *\n * The run holds `{port}` when a class comes from HTTP or the ready signal is `http`. The seed and the run hold\n * `{store}` when the app has a store variable. The seed can hold `{variable.<id>}` of a store or a level variable,\n * for example the routes of a configuration. The fake of each service holds `{port}`, and `{workload}` when a class comes from the service.\n */\nexport interface AppCommand {\n readonly argv: readonly string[];\n readonly cwd: string;\n readonly env: Readonly<Record<string, string>>;\n}\n\n/**\n * The ready signal tells that a process serves. `line` is a text in a line of the output of the process.\n * `http` is a path of the process that gives a status of 200.\n */\nexport type AppReady = { readonly kind: \"line\"; readonly text: string } | { readonly kind: \"http\"; readonly path: string };\n\n/** A process is a command that runs until the lab stops it, and its ready signal. */\nexport interface AppProcess extends AppCommand {\n readonly ready: AppReady;\n}\n\n/** The kinds of the lines of a run that the lab records. The lab knows the fields of each kind. */\nexport const APP_LINE_KINDS = [\"pass\", \"write\", \"readings\", \"amounts\"] as const;\n\n/**\n * The kind of a line of a run.\n *\n * - `pass`: the end of one pass of the loop of the app. The lab counts the passes in the watch after ready.\n * - `write`: one write of the snapshot of the start. The fields `longestMs`, `writeMs`, `rowsMs`, `wallMs` and `cpuMs`\n * give its times in milliseconds. The lab keeps the longest value of each time.\n * - `readings`: one collection of the live metrics of the app. The field `readings` is a list of `SeriesReading`. The\n * lab keeps each collection with its time, so the record of a start has the series of the metrics of the app.\n * - `amounts`: the amounts of the run variables. The field `amounts` gives the amount of each run variable by its id, in the\n * unit of the variable. The lab keeps the last line up to the end of the watch.\n */\nexport type AppLineKind = (typeof APP_LINE_KINDS)[number];\n\n/**\n * A line of a run is a JSON line of the output of the run that the lab records. The line is a JSON object, and its\n * field `ev` has the text `ev`. `kind` tells what the lab reads from it.\n */\nexport interface AppLine {\n readonly kind: AppLineKind;\n readonly ev: string;\n readonly title: string;\n}\n\n/** The run of an app is its process, and the lines of its output that the lab records. A run with no `lines` gives no pass and no write. */\nexport interface AppRun extends AppProcess {\n readonly lines?: readonly AppLine[] | undefined;\n}\n\n/**\n * The start of an app tells how to make it run in a tree of its repository.\n *\n * - `install` installs the dependencies of the tree. An app with no dependencies has no install.\n * - `check` examines the tree after the install, for example with a typecheck.\n * - `seed` writes the store of a start case at the amounts of the store variables. An app with no store variable has no seed.\n * The last line of the output of the seed is a JSON record. Its field `amounts` gives the amount of each store variable\n * that the seed wrote, by its id, in the unit of the variable.\n * - `run` is the process of the app, and the lines of its output that the lab records.\n */\nexport interface AppStart {\n readonly install?: AppCommand | undefined;\n readonly check?: AppCommand | undefined;\n readonly seed?: AppCommand | undefined;\n readonly run: AppRun;\n}\n\n/**\n * An outside service of an app is a service of others that the app calls, for example a feed or a channel\n * of messages. The lab starts the fake of the service in place of the service, and the app gets its URL.\n */\nexport interface AppService {\n readonly id: string;\n readonly title: string;\n readonly fake: AppProcess;\n}\n\n/**\n * The target of a series tells what the series measures.\n *\n * - `rate`: a counter of the requests of a class. Its rate is the rate of the class.\n * - `level`: a gauge of a level variable.\n * - `total`: a counter of the sum of a request variable over the requests of a class. Its increase over\n * the increase of the counter of the class is the mean of the variable.\n * - `measure`: a counter or a gauge of a measure of the laws of the app, for example its CPU time.\n */\nexport type SeriesTarget =\n | { readonly rate: string }\n | { readonly level: string }\n | { readonly total: string; readonly class: string }\n | { readonly measure: string };\n\n/**\n * A series is one live metric of an app. Its `id` is the name of the metric in the readings of the app.\n * A counter only goes up, until the process starts again. A gauge is an amount at the time of its reading.\n */\nexport interface AppSeries {\n readonly id: string;\n readonly kind: \"counter\" | \"gauge\";\n readonly unit: string;\n readonly of: SeriesTarget;\n}\n\n/**\n * The contract of an app is the record that each app gives to the lab and to the models. A contract file\n * is this record as JSON. The `id` is the subject of the laws of the app.\n */\nexport interface AppContract {\n readonly format: typeof APP_FORMAT;\n readonly id: string;\n readonly title: string;\n /** This URL is the public HTTPS URL of the repository of the app. */\n readonly repository: string;\n readonly variables: readonly AppVariable[];\n readonly classes: readonly AppClass[];\n readonly start: AppStart;\n readonly services: readonly AppService[];\n readonly metrics: readonly AppSeries[];\n}\n\n/** An app problem code names the part of a contract, or of a workload against a contract, that is not correct. */\nexport type AppProblemCode =\n | \"shape\"\n | \"format\"\n | \"id\"\n | \"range\"\n | \"unit\"\n | \"variable\"\n | \"class\"\n | \"entry\"\n | \"command\"\n | \"placeholder\"\n | \"service\"\n | \"series\"\n | \"workload\";\n\n/** An app problem tells what is not correct, and where: `path` is the path of the field in the contract or in the workload. */\nexport type AppProblem = Problem<AppProblemCode>;\n\n/**\n * A gap is one part of the demand of an app that its live metrics cannot give. `need` names the series that\n * is not there. It is the counter of a class, the gauge of a level, or the counter of a total.\n */\nexport interface MetricsGap {\n readonly need: \"rate\" | \"level\" | \"total\";\n readonly class?: string | undefined;\n readonly variable?: string | undefined;\n readonly message: string;\n}\n","import { convertible, divideUnits, isCanonicalUnit, isQuantity, kindOf, valueIn, type Quantity } from \"@mark1russell7/quantity\";\nimport {\n APP_FORMAT,\n type AppClass,\n type AppContract,\n type AppProblem,\n type AppSeries,\n type AppVariable,\n type AppCommand,\n type HttpEntry,\n type MetricsGap,\n type AppRange,\n type AppReady,\n type AppLine,\n} from \"./app.ts\";\nimport { NAME, SLUG, finite } from \"./names.ts\";\nimport { RATE, type Workload } from \"./workload.ts\";\n\n/** An HTTPS URL: the scheme `https`, a host, and then a path, a query or a fragment with no space. */\nconst HTTPS = /^https:\\/\\/[^\\s/?#@]+(?:[/?#]\\S*)?$/i;\n\n/** This function tells if a text is an HTTPS URL. The package uses no global of a browser or of Node.js. */\nexport const isHttps = (text: string): boolean => HTTPS.test(text);\n\n/** This function makes a problem of a contract or of a workload against a contract. */\nconst appProblem = (code: AppProblem[\"code\"], path: string, message: string): AppProblem => ({ code, path, message });\n\n/** The name of a series: letters, digits, `_`, `.`, `/` and `-`, that start with a letter. */\nconst METRIC = /^[A-Za-z][A-Za-z0-9_./-]*$/;\n\n/** The name of an environment variable: upper-case letters, digits and `_`, that start with a letter or `_`. */\nconst ENV = /^[A-Z_][A-Z0-9_]*$/;\n\nconst PLACEHOLDER = /\\{([^{}]*)\\}/g;\n\n/** A place is a command of the contract. Each place accepts its own placeholders. */\ntype Place = \"install\" | \"check\" | \"seed\" | \"run\" | \"fake\";\n\n/** These names are the plain placeholders that each place accepts. `service` and `variable` take an id after a `.`. */\nconst PLAIN: Readonly<Record<Place, readonly string[]>> = {\n install: [],\n check: [],\n seed: [\"store\"],\n run: [\"port\", \"store\"],\n fake: [\"port\", \"workload\"],\n};\n\n/** This function gives the names of the placeholders in a text, in their order. */\nexport const placeholdersOf = (text: string): readonly string[] => [...text.matchAll(PLACEHOLDER)].map((match) => match[1] ?? \"\");\n\n/**\n * This function puts the value of each placeholder into a text. It gives undefined when the text holds a\n * placeholder that `values` does not give.\n */\nexport const fillPlaceholders = (text: string, values: Readonly<Record<string, string>>): string | undefined => {\n if (placeholdersOf(text).some((name) => !Object.hasOwn(values, name))) return undefined;\n return text.replace(PLACEHOLDER, (_match, name: string) => values[name] ?? \"\");\n};\n\n/**\n * This function gives the path of a request of a class of HTTP at some amounts. Each amount is a number in\n * the unit of its variable. It gives undefined when `values` does not give each variable of the path.\n */\nexport const requestPath = (entry: HttpEntry, values: Readonly<Record<string, number>>): string | undefined =>\n fillPlaceholders(entry.path, Object.fromEntries(Object.entries(values).map(([name, value]) => [name, encodeURIComponent(String(value))])));\n\n/** This function gives the problems of a range: its unit, its two ends and its scale. */\nconst rangeProblems = (range: AppRange, path: string, owner: string): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n if (!isCanonicalUnit(range.unit)) problems.push(appProblem(\"unit\", `${path}.unit`, `The unit \"${range.unit}\" of ${owner} is not a canonical unit.`));\n if (!finite(range.min) || !finite(range.max) || range.min > range.max) {\n problems.push(appProblem(\"range\", path, `The range of ${owner} does not go from a finite amount to the same or a larger amount.`));\n } else if (range.scale === \"log\" && !(range.min > 0)) {\n problems.push(appProblem(\"range\", `${path}.min`, `The range of ${owner} is on the scale \"log\", thus it starts above 0.`));\n }\n return problems;\n};\n\n/** This function gives the problems of the variables: the id, the title and the range of each. */\nconst variableProblems = (variables: readonly AppVariable[]): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const ids = new Set<string>();\n variables.forEach((variable, index) => {\n const path = `variables[${index}]`;\n if (!NAME.test(variable.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `The id \"${variable.id}\" is not letters and digits that start with a lower-case letter.`));\n } else if (variable.id === RATE) {\n problems.push(appProblem(\"id\", `${path}.id`, `The id \"${RATE}\" is the rate of a class. A variable cannot use it.`));\n } else if (ids.has(variable.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `Two variables have the id \"${variable.id}\".`));\n }\n ids.add(variable.id);\n if (variable.title.trim() === \"\") problems.push(appProblem(\"id\", `${path}.title`, `The title of the variable \"${variable.id}\" is empty.`));\n problems.push(...rangeProblems(variable, path, `the variable \"${variable.id}\"`));\n });\n return problems;\n};\n\n/** This function gives the problems of the entry of a class. An entry of HTTP sets each request variable of the class. */\nconst entryProblems = (app: AppContract, entry: AppClass, path: string): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const at = `${path}.entry`;\n if (entry.entry.kind === \"service\") {\n const { service } = entry.entry;\n if (!app.services.some((each) => each.id === service)) {\n problems.push(appProblem(\"service\", `${at}.service`, `The class \"${entry.id}\" names the service \"${service}\", and the app has no service with that id.`));\n }\n return problems;\n }\n const { path: template, body } = entry.entry;\n if (!template.startsWith(\"/\")) problems.push(appProblem(\"entry\", `${at}.path`, `The path of the class \"${entry.id}\" does not start with \"/\".`));\n const named = placeholdersOf(template);\n for (const name of named) {\n if (!entry.request.includes(name)) {\n problems.push(appProblem(\"placeholder\", `${at}.path`, `The path of the class \"${entry.id}\" holds \"{${name}}\", and \"${name}\" is not a request variable of the class.`));\n }\n }\n if (body !== undefined) {\n const variable = app.variables.find((each) => each.id === body);\n if (!entry.request.includes(body)) {\n problems.push(appProblem(\"entry\", `${at}.body`, `The body of the class \"${entry.id}\" is the variable \"${body}\", and it is not a request variable of the class.`));\n } else if (variable !== undefined && isCanonicalUnit(variable.unit) && !convertible(variable.unit, \"B\")) {\n problems.push(appProblem(\"unit\", `${at}.body`, `The body of the class \"${entry.id}\" is the variable \"${body}\" in \"${variable.unit}\", not in bytes.`));\n }\n }\n for (const name of entry.request) {\n if (!named.includes(name) && name !== body) {\n problems.push(appProblem(\"entry\", at, `A request of the class \"${entry.id}\" cannot set the variable \"${name}\": neither the path nor the body holds it.`));\n }\n }\n return problems;\n};\n\n/** This function gives the problems of the classes: the id, the rate, the request variables and the entry of each. */\nconst classProblems = (app: AppContract): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const ids = new Set<string>();\n app.classes.forEach((entry, index) => {\n const path = `classes[${index}]`;\n if (!SLUG.test(entry.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `The id \"${entry.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n } else if (ids.has(entry.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `Two classes have the id \"${entry.id}\".`));\n }\n ids.add(entry.id);\n if (entry.title.trim() === \"\") problems.push(appProblem(\"id\", `${path}.title`, `The title of the class \"${entry.id}\" is empty.`));\n problems.push(...rangeProblems(entry.rate, `${path}.rate`, `the rate of the class \"${entry.id}\"`));\n if (isCanonicalUnit(entry.rate.unit) && kindOf(entry.rate.unit) !== \"frequency\") {\n problems.push(appProblem(\"unit\", `${path}.rate.unit`, `The rate of the class \"${entry.id}\" is in \"${entry.rate.unit}\". A rate is a count in a unit of time, for example \"{request}/s\".`));\n }\n entry.request.forEach((name, place) => {\n const variable = app.variables.find((each) => each.id === name);\n if (variable === undefined) {\n problems.push(appProblem(\"variable\", `${path}.request[${place}]`, `The class \"${entry.id}\" names the variable \"${name}\", and the app has no variable with that id.`));\n } else if (variable.kind !== \"request\") {\n problems.push(appProblem(\"variable\", `${path}.request[${place}]`, `The variable \"${name}\" is a ${variable.kind} variable, not a request variable.`));\n } else if (entry.request.indexOf(name) !== place) {\n problems.push(appProblem(\"variable\", `${path}.request[${place}]`, `The class \"${entry.id}\" names the variable \"${name}\" two times.`));\n }\n });\n problems.push(...entryProblems(app, entry, path));\n });\n app.variables.forEach((variable, index) => {\n if (variable.kind === \"request\" && !app.classes.some((entry) => entry.request.includes(variable.id))) {\n problems.push(appProblem(\"variable\", `variables[${index}]`, `No class has the request variable \"${variable.id}\".`));\n }\n });\n return problems;\n};\n\n/** This function gives the problems of the placeholders of a command at its place in the contract. */\nconst placeholderProblems = (app: AppContract, command: AppCommand, path: string, place: Place): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const texts: (readonly [string, string])[] = [\n ...command.argv.map((text, index) => [`${path}.argv[${index}]`, text] as const),\n ...Object.entries(command.env).map(([name, text]) => [`${path}.env.${name}`, text] as const),\n ];\n for (const [at, text] of texts) {\n for (const name of placeholdersOf(text)) {\n const [head, ...rest] = name.split(\".\");\n const id = rest.join(\".\");\n if (rest.length === 0 && PLAIN[place].includes(name)) continue;\n if (head === \"service\" && place === \"run\" && id !== \"\") {\n if (!app.services.some((each) => each.id === id)) {\n problems.push(appProblem(\"placeholder\", at, `The placeholder \"{${name}}\" names the service \"${id}\", and the app has no service with that id.`));\n }\n continue;\n }\n if (head === \"variable\" && place === \"seed\" && id !== \"\") {\n if (!app.variables.some((each) => each.id === id && (each.kind === \"store\" || each.kind === \"level\"))) {\n problems.push(appProblem(\"placeholder\", at, `The placeholder \"{${name}}\" names \"${id}\", and the app has no store or level variable with that id.`));\n }\n continue;\n }\n problems.push(appProblem(\"placeholder\", at, `The command ${place} cannot hold the placeholder \"{${name}}\".`));\n }\n }\n return problems;\n};\n\n/** This function gives the problems of a ready signal. */\nconst readyProblems = (ready: AppReady, path: string): readonly AppProblem[] => {\n if (ready.kind === \"line\") return ready.text.trim() === \"\" ? [appProblem(\"command\", `${path}.text`, \"The text of the ready line is empty.\")] : [];\n return ready.path.startsWith(\"/\") ? [] : [appProblem(\"command\", `${path}.path`, `The ready path \"${ready.path}\" does not start with \"/\".`)];\n};\n\n/**\n * This function gives the problems of the lines of a run. Each line has a text `ev` that is not empty, and no two lines\n * have the same kind or the same `ev`.\n */\nconst lineProblems = (lines: readonly AppLine[], path: string): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const kinds = new Set<string>();\n const evs = new Set<string>();\n lines.forEach((line, index) => {\n const at = `${path}[${index}]`;\n if (line.ev.trim() === \"\") problems.push(appProblem(\"command\", `${at}.ev`, \"The field ev of the line is empty.\"));\n if (kinds.has(line.kind)) problems.push(appProblem(\"command\", `${at}.kind`, `Two lines of the run have the kind \"${line.kind}\".`));\n if (evs.has(line.ev)) problems.push(appProblem(\"command\", `${at}.ev`, `Two lines of the run have the ev \"${line.ev}\".`));\n kinds.add(line.kind);\n evs.add(line.ev);\n });\n return problems;\n};\n\n/** This function gives the problems of a command: its program, its folder, the names of its variables and its placeholders. */\nconst commandProblems = (app: AppContract, command: AppCommand, path: string, place: Place): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n if (command.argv.length === 0 || (command.argv[0] ?? \"\").trim() === \"\") {\n problems.push(appProblem(\"command\", `${path}.argv`, `The command ${place} has no program.`));\n }\n const parts = command.cwd.split(\"/\");\n if (command.cwd.startsWith(\"/\") || command.cwd.includes(\"\\\\\") || parts.some((part) => part === \"..\") || command.cwd === \"\") {\n problems.push(appProblem(\"command\", `${path}.cwd`, `The folder \"${command.cwd}\" is not a path in the repository, with \"/\" and no \"..\". The root is \".\".`));\n }\n for (const name of Object.keys(command.env)) {\n if (!ENV.test(name)) problems.push(appProblem(\"command\", `${path}.env.${name}`, `The name \"${name}\" is not an environment variable: upper-case letters, digits and \"_\".`));\n }\n problems.push(...placeholderProblems(app, command, path, place));\n return problems;\n};\n\n/** This function tells if a command holds a placeholder. */\nconst holds = (command: AppCommand, placeholder: string): boolean =>\n [...command.argv, ...Object.values(command.env)].some((text) => placeholdersOf(text).includes(placeholder));\n\n/**\n * This function gives the problems of the start and of the outside services. Each process gets its port, the\n * seed and the run get the store, and the run gets the URL of each service. The seed sets each store variable.\n */\nconst startProblems = (app: AppContract): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const { install, check, seed, run } = app.start;\n if (install !== undefined) problems.push(...commandProblems(app, install, \"start.install\", \"install\"));\n if (check !== undefined) problems.push(...commandProblems(app, check, \"start.check\", \"check\"));\n problems.push(...commandProblems(app, run, \"start.run\", \"run\"), ...readyProblems(run.ready, \"start.run.ready\"), ...lineProblems(run.lines ?? [], \"start.run.lines\"));\n const listens = run.ready.kind === \"http\" || app.classes.some((entry) => entry.entry.kind === \"http\");\n if (listens && !holds(run, \"port\")) problems.push(appProblem(\"command\", \"start.run\", `The run does not get its port: it does not hold \"{port}\".`));\n\n const measured = app.variables.filter((variable) => variable.kind === \"run\");\n if (measured.length > 0 && !(run.lines ?? []).some((line) => line.kind === \"amounts\")) {\n problems.push(appProblem(\"command\", \"start.run.lines\", `The app has the run variable \"${measured[0]?.id}\", and the run has no line of the kind \"amounts\" that gives it.`));\n }\n const stores = app.variables.filter((variable) => variable.kind === \"store\");\n if (stores.length > 0 && !holds(run, \"store\")) {\n problems.push(appProblem(\"command\", \"start.run\", `The app has a store, and the run does not get its folder: the run does not hold \"{store}\".`));\n }\n if (seed === undefined) {\n if (stores.length > 0) problems.push(appProblem(\"command\", \"start\", `The app has the store variables ${stores.map((each) => `\"${each.id}\"`).join(\", \")}, and no seed.`));\n } else {\n problems.push(...commandProblems(app, seed, \"start.seed\", \"seed\"));\n if (stores.length === 0) problems.push(appProblem(\"command\", \"start.seed\", \"The app has a seed, and no store variable for it to set.\"));\n else if (!holds(seed, \"store\")) problems.push(appProblem(\"command\", \"start.seed\", `The seed does not get the folder of the store: it does not hold \"{store}\".`));\n for (const variable of stores) {\n if (!holds(seed, `variable.${variable.id}`)) {\n problems.push(appProblem(\"command\", \"start.seed\", `The seed cannot set the store variable \"${variable.id}\": it does not hold \"{variable.${variable.id}}\".`));\n }\n }\n }\n\n const ids = new Set<string>();\n app.services.forEach((service, index) => {\n const path = `services[${index}]`;\n if (!SLUG.test(service.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `The id \"${service.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n } else if (ids.has(service.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `Two services have the id \"${service.id}\".`));\n }\n ids.add(service.id);\n if (service.title.trim() === \"\") problems.push(appProblem(\"id\", `${path}.title`, `The title of the service \"${service.id}\" is empty.`));\n problems.push(...commandProblems(app, service.fake, `${path}.fake`, \"fake\"), ...readyProblems(service.fake.ready, `${path}.fake.ready`));\n if (!holds(service.fake, \"port\")) problems.push(appProblem(\"command\", `${path}.fake`, `The fake of \"${service.id}\" does not get its port: it does not hold \"{port}\".`));\n const feeds = app.classes.some((entry) => entry.entry.kind === \"service\" && entry.entry.service === service.id);\n if (feeds && !holds(service.fake, \"workload\")) {\n problems.push(appProblem(\"command\", `${path}.fake`, `A class comes from \"${service.id}\", and its fake does not get the rates: it does not hold \"{workload}\".`));\n }\n if (!holds(run, `service.${service.id}`)) {\n problems.push(appProblem(\"service\", path, `The app does not get the URL of the fake of \"${service.id}\": the run does not hold \"{service.${service.id}}\".`));\n }\n });\n return problems;\n};\n\n/** This function gives the key of the target of a series. Two series with one key measure the same thing. */\nconst targetKey = (series: AppSeries): string => JSON.stringify(Object.entries(series.of).sort(([a], [b]) => a.localeCompare(b)));\n\n/** This function gives the problems of one series: its target, its kind and its unit. */\nconst seriesProblems = (app: AppContract, series: AppSeries, path: string): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const at = `${path}.of`;\n const target = series.of;\n const kind = (wanted: AppSeries[\"kind\"], what: string): void => {\n if (series.kind !== wanted) problems.push(appProblem(\"series\", `${path}.kind`, `The series \"${series.id}\" gives ${what}, thus it is a ${wanted}.`));\n };\n const unit = (wanted: string, what: string): void => {\n if (isCanonicalUnit(series.unit) && isCanonicalUnit(wanted) && !convertible(series.unit, wanted)) {\n problems.push(appProblem(\"unit\", `${path}.unit`, `The series \"${series.id}\" is in \"${series.unit}\". ${what} is in \"${wanted}\".`));\n }\n };\n if (\"rate\" in target) {\n const entry = app.classes.find((each) => each.id === target.rate);\n kind(\"counter\", \"the rate of a class\");\n if (entry === undefined) return [...problems, appProblem(\"series\", at, `The series \"${series.id}\" names the class \"${target.rate}\", and the app has no class with that id.`)];\n const perSecond = isCanonicalUnit(series.unit) ? divideUnits(series.unit, \"s\") : undefined;\n if (perSecond !== undefined && isCanonicalUnit(entry.rate.unit) && kindOf(entry.rate.unit) === \"frequency\" && !convertible(perSecond, entry.rate.unit)) {\n problems.push(appProblem(\"unit\", `${path}.unit`, `The series \"${series.id}\" gives a rate in \"${perSecond}\". The rate of the class \"${entry.id}\" is in \"${entry.rate.unit}\".`));\n }\n return problems;\n }\n if (\"level\" in target) {\n const variable = app.variables.find((each) => each.id === target.level);\n kind(\"gauge\", \"a level\");\n if (variable === undefined || variable.kind !== \"level\") {\n return [...problems, appProblem(\"series\", at, `The series \"${series.id}\" names \"${target.level}\", and the app has no level variable with that id.`)];\n }\n unit(variable.unit, `The level \"${variable.id}\"`);\n return problems;\n }\n if (\"total\" in target) {\n const entry = app.classes.find((each) => each.id === target.class);\n const variable = app.variables.find((each) => each.id === target.total);\n kind(\"counter\", \"a total over the requests of a class\");\n if (entry === undefined) return [...problems, appProblem(\"series\", at, `The series \"${series.id}\" names the class \"${target.class}\", and the app has no class with that id.`)];\n if (variable === undefined || !entry.request.includes(variable.id)) {\n return [...problems, appProblem(\"series\", at, `The series \"${series.id}\" names \"${target.total}\", and it is not a request variable of the class \"${entry.id}\".`)];\n }\n unit(variable.unit, `The variable \"${variable.id}\"`);\n return problems;\n }\n if (!SLUG.test(target.measure)) problems.push(appProblem(\"series\", `${at}.measure`, `The measure \"${target.measure}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n return problems;\n};\n\n/** This function gives the problems of the live metrics: the id, the unit and the target of each series. */\nconst metricsProblems = (app: AppContract): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n const ids = new Set<string>();\n const targets = new Map<string, string>();\n app.metrics.forEach((series, index) => {\n const path = `metrics[${index}]`;\n if (!METRIC.test(series.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `The id \"${series.id}\" is not a name of a metric: letters, digits, \"_\", \".\", \"/\" and \"-\".`));\n } else if (ids.has(series.id)) {\n problems.push(appProblem(\"id\", `${path}.id`, `Two series have the id \"${series.id}\".`));\n }\n ids.add(series.id);\n if (!isCanonicalUnit(series.unit)) problems.push(appProblem(\"unit\", `${path}.unit`, `The unit \"${series.unit}\" of the series \"${series.id}\" is not a canonical unit.`));\n const key = targetKey(series);\n const before = targets.get(key);\n if (before !== undefined) problems.push(appProblem(\"series\", `${path}.of`, `The series \"${series.id}\" and \"${before}\" measure the same thing.`));\n else targets.set(key, series.id);\n problems.push(...seriesProblems(app, series, path));\n });\n return problems;\n};\n\n/**\n * This function examines the contract of an app and gives each problem that it finds. A contract with no\n * problem gives an empty list.\n *\n * It examines the format, the id, the title and the repository. It examines each variable, each class and\n * its entry, each command and its placeholders, each outside service and each series of the live metrics.\n */\nexport const checkApp = (app: AppContract): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n if (app.format !== APP_FORMAT) problems.push(appProblem(\"format\", \"format\", `The format is \"${String(app.format)}\", not \"${APP_FORMAT}\".`));\n if (!SLUG.test(app.id)) problems.push(appProblem(\"id\", \"id\", `The id \"${app.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n if (app.title.trim() === \"\") problems.push(appProblem(\"id\", \"title\", \"The title is empty.\"));\n if (!isHttps(app.repository)) {\n problems.push(appProblem(\"id\", \"repository\", `The repository \"${app.repository}\" is not an HTTPS URL.`));\n }\n return [...problems, ...variableProblems(app.variables), ...classProblems(app), ...startProblems(app), ...metricsProblems(app)];\n};\n\n/**\n * This function gives each part of the demand of an app that its live metrics cannot give. A contract whose\n * metrics give its whole demand gives an empty list. The live check of a law reads a demand with no gap.\n */\nexport const metricsGaps = (app: AppContract): readonly MetricsGap[] => {\n const has = (test: (series: AppSeries) => boolean): boolean => app.metrics.some(test);\n const gaps: MetricsGap[] = [];\n for (const entry of app.classes) {\n if (!has((series) => \"rate\" in series.of && series.of.rate === entry.id)) {\n gaps.push({ need: \"rate\", class: entry.id, message: `No counter gives the rate of the class \"${entry.id}\".` });\n }\n for (const name of entry.request) {\n if (!has((series) => \"total\" in series.of && series.of.total === name && series.of.class === entry.id)) {\n gaps.push({ need: \"total\", class: entry.id, variable: name, message: `No counter gives the total of \"${name}\" over the requests of the class \"${entry.id}\".` });\n }\n }\n }\n for (const variable of app.variables) {\n if (variable.kind === \"level\" && !has((series) => \"level\" in series.of && series.of.level === variable.id)) {\n gaps.push({ need: \"level\", variable: variable.id, message: `No gauge gives the level \"${variable.id}\".` });\n }\n }\n return gaps;\n};\n\n/** This function gives the problem of an amount against the range of its variable: its unit, then its value. */\nconst amountProblem = (amount: Quantity, range: AppRange, path: string, owner: string): AppProblem | undefined => {\n if (!isQuantity(amount)) return undefined;\n if (!convertible(amount.unit, range.unit)) return appProblem(\"unit\", path, `${owner} is in \"${amount.unit}\", and the app gives it in \"${range.unit}\".`);\n const value = valueIn(amount, range.unit);\n if (value < range.min || value > range.max) {\n return appProblem(\"range\", path, `${owner} is ${value} ${range.unit}. The app accepts ${range.min} to ${range.max} ${range.unit}.`);\n }\n return undefined;\n};\n\n/**\n * This function examines a workload against the contract of its app, and gives each problem that it finds.\n * The workload is a workload that `checkWorkload` accepts.\n *\n * Each class of the workload is a class of the app: the class that its field `of` names, or else its id. Its\n * rate and each variable of its request are in the range of the app, and it gives each request variable of\n * its class. Each level of the workload is a level variable of the app, in its range. A class or a level that\n * the workload does not give is 0.\n */\nexport const appWorkloadProblems = (app: AppContract, workload: Workload): readonly AppProblem[] => {\n const problems: AppProblem[] = [];\n workload.classes.forEach((entry, index) => {\n const path = `classes[${index}]`;\n const id = entry.of ?? entry.id;\n const known = app.classes.find((each) => each.id === id);\n if (known === undefined) {\n problems.push(appProblem(\"class\", entry.of === undefined ? `${path}.id` : `${path}.of`, `The app \"${app.id}\" has no class \"${id}\".`));\n return;\n }\n const rate = amountProblem(entry.rate, known.rate, `${path}.rate`, `The rate of the class \"${entry.id}\"`);\n if (rate !== undefined) problems.push(rate);\n for (const [name, amount] of Object.entries(entry.request)) {\n const variable = app.variables.find((each) => each.id === name);\n if (variable === undefined || !known.request.includes(name)) {\n problems.push(appProblem(\"variable\", `${path}.request.${name}`, `\"${name}\" is not a request variable of the class \"${known.id}\" of the app.`));\n continue;\n }\n const found = amountProblem(amount, variable, `${path}.request.${name}`, `The variable \"${name}\" of the class \"${entry.id}\"`);\n if (found !== undefined) problems.push(found);\n }\n for (const name of known.request) {\n if (!Object.hasOwn(entry.request, name)) {\n problems.push(appProblem(\"variable\", `${path}.request`, `The class \"${entry.id}\" does not give the request variable \"${name}\" of the class \"${known.id}\".`));\n }\n }\n });\n for (const [name, amount] of Object.entries(workload.levels)) {\n const variable = app.variables.find((each) => each.id === name);\n if (variable === undefined || variable.kind !== \"level\") {\n problems.push(appProblem(\"variable\", `levels.${name}`, `\"${name}\" is not a level variable of the app \"${app.id}\".`));\n continue;\n }\n const found = amountProblem(amount, variable, `levels.${name}`, `The level \"${name}\"`);\n if (found !== undefined) problems.push(found);\n }\n return problems;\n};\n","import { err, ok, type Result } from \"@mark1russell7/optional\";\nimport {\n add,\n compare,\n convertible,\n isCanonicalUnit,\n isQuantity,\n kindOf,\n factorOf,\n quantity,\n scale,\n whyNotConvertible,\n type Quantity,\n} from \"@mark1russell7/quantity\";\nimport type { Law, Variable } from \"./law.ts\";\nimport { finite } from \"./names.ts\";\nimport type { LoadPoint } from \"./value.ts\";\nimport { demandProblems, workloadProblem } from \"./workload-check.ts\";\nimport { RATE, type Amounts, type Demand, type WorkloadClass, type WorkloadProblem } from \"./workload.ts\";\n\n/** This function gives the first problem of a demand, or undefined. The text `owner` goes before the path of the problem. */\nconst firstProblem = (demand: Demand, owner = \"\"): WorkloadProblem | undefined => {\n const found = demandProblems(demand)[0];\n return found === undefined || owner === \"\" ? found : { ...found, path: `${owner}.${found.path}` };\n};\n\n/**\n * This function gives a demand with a change of each rate and each level. The variables of the\n * requests stay. The function `change` gets the name of a level, and no name for a rate. It gives\n * undefined for an amount that it cannot change.\n */\nconst changed = (\n demand: Demand,\n change: (amount: Quantity, level?: string) => Quantity | undefined,\n): Result<Demand, WorkloadProblem> => {\n const classes: WorkloadClass[] = [];\n for (const [index, entry] of demand.classes.entries()) {\n const rate = change(entry.rate);\n if (rate === undefined) {\n return err(workloadProblem(\"amount\", `classes[${index}].rate`, `The rate of the class \"${entry.id}\" is not finite after the change.`));\n }\n classes.push({ id: entry.id, rate, request: entry.request });\n }\n const levels: Record<string, Quantity> = {};\n for (const [name, amount] of Object.entries(demand.levels)) {\n const level = change(amount, name);\n if (level === undefined) return err(workloadProblem(\"amount\", `levels.${name}`, `The level \"${name}\" is not finite after the change.`));\n levels[name] = level;\n }\n return ok({ classes, levels });\n};\n\n/**\n * This function gives a demand that is `by` times as large: each rate and each level, times `by`.\n * The variables of the requests stay, because more clients do not make a request larger.\n *\n * It gives a problem for a demand that is not correct, and for a factor that is not a finite number\n * of 0 or more.\n */\nexport const scaleDemand = (demand: Demand, by: number): Result<Demand, WorkloadProblem> => {\n const bad = firstProblem(demand);\n if (bad !== undefined) return err(bad);\n if (!finite(by) || by < 0) return err(workloadProblem(\"factor\", \"by\", `The factor ${by} is not a finite number of 0 or more.`));\n return changed(demand, (amount) => {\n const product = scale(amount, by);\n return finite(product.value) ? product : undefined;\n });\n};\n\n/** These options name the levels that do not divide between instances. Each instance has the whole of such a level. */\nexport interface ShareOptions {\n readonly whole?: readonly string[];\n}\n\n/**\n * This function gives the demand on one instance when `instances` equal instances serve a demand:\n * each rate and each level, divided by the count. The variables of the requests stay.\n *\n * A level in `options.whole` does not divide. For example, each instance of an app that keeps all\n * open incidents in memory has the whole level.\n *\n * It gives a problem for a demand that is not correct. It gives a problem for a count that is not\n * a whole number of 1 or more. It gives a problem for a name in `options.whole` that is not a level.\n */\nexport const shareOf = (demand: Demand, instances: number, options: ShareOptions = {}): Result<Demand, WorkloadProblem> => {\n const bad = firstProblem(demand);\n if (bad !== undefined) return err(bad);\n if (!Number.isSafeInteger(instances) || instances < 1) {\n return err(workloadProblem(\"factor\", \"instances\", `The count of instances ${instances} is not a whole number of 1 or more.`));\n }\n const whole = options.whole ?? [];\n const unknown = whole.find((name) => !Object.hasOwn(demand.levels, name));\n if (unknown !== undefined) return err(workloadProblem(\"variable\", \"whole\", `The demand has no level \"${unknown}\".`));\n return changed(demand, (amount, level) =>\n level !== undefined && whole.includes(level) ? amount : quantity(amount.value / instances, amount.unit),\n );\n};\n\n/**\n * This function gives a portion of a demand for a search. Each rate and each level is times\n * `shared`, and each level in `whole` is times `kept`. It does not examine the demand or the names.\n *\n * The demand on one of `n` instances at `s` times the load is the portion with `shared` equal to\n * `s / n` and `kept` equal to `s`.\n */\nexport const portionOf = (demand: Demand, shared: number, kept: number, whole: readonly string[]): Result<Demand, WorkloadProblem> =>\n changed(demand, (amount, level) => {\n const product = scale(amount, level !== undefined && whole.includes(level) ? kept : shared);\n return finite(product.value) ? product : undefined;\n });\n\n/** This function gives the sum of two amounts, or the problem that stops it. */\nconst plus = (a: Quantity, b: Quantity, path: string, what: string): Result<Quantity, WorkloadProblem> => {\n if (!convertible(a.unit, b.unit)) {\n return err(workloadProblem(\"unit\", path, `${what} do not add: ${whyNotConvertible(a.unit, b.unit) ?? \"the units are different\"}.`));\n }\n const total = add(a, b);\n return finite(total.value) ? ok(total) : err(workloadProblem(\"amount\", path, `${what} do not have a finite sum.`));\n};\n\n/** This function tells if two sets of amounts have the same names and equal amounts. */\nconst sameAmounts = (a: Amounts, b: Amounts): boolean => {\n const names = Object.keys(a);\n return (\n names.length === Object.keys(b).length &&\n names.every((name) => {\n const other = b[name];\n const amount = a[name] as Quantity;\n return Object.hasOwn(b, name) && other !== undefined && convertible(amount.unit, other.unit) && compare(amount, other) === 0;\n })\n );\n};\n\nconst inOrder = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);\n\n/**\n * This function gives the sum of two demands. A class of one demand stays. A class of the two\n * demands has the sum of its rates, and its request must be equal in the two. The levels add, and a\n * level of one demand stays. The classes and the levels of the sum are in the order of their names.\n *\n * The sum has the laws of addition: the order of the demands does not change it, and `NO_DEMAND`\n * is its zero. An amount of the sum is in the unit of the first demand that gives it. Thus the\n * order can change the unit of an amount, and not the amount.\n *\n * It gives a problem for a demand that is not correct, and for amounts that do not add. A path of\n * a problem starts with `first` or `second`, or with neither for a problem of the sum.\n */\nexport const mergeDemands = (first: Demand, second: Demand): Result<Demand, WorkloadProblem> => {\n const bad = firstProblem(first, \"first\") ?? firstProblem(second, \"second\");\n if (bad !== undefined) return err(bad);\n\n const classes = new Map<string, WorkloadClass>(first.classes.map((entry) => [entry.id, entry]));\n for (const [index, entry] of second.classes.entries()) {\n const same = classes.get(entry.id);\n if (same === undefined) {\n classes.set(entry.id, entry);\n continue;\n }\n const path = `second.classes[${index}]`;\n if (!sameAmounts(same.request, entry.request)) {\n return err(workloadProblem(\"class\", `${path}.request`, `The class \"${entry.id}\" has a different request in the two demands.`));\n }\n const rate = plus(same.rate, entry.rate, `${path}.rate`, `The rates of the class \"${entry.id}\"`);\n if (rate.tag === \"err\") return rate;\n classes.set(entry.id, { id: same.id, rate: rate.value, request: same.request });\n }\n\n const levels = new Map<string, Quantity>(Object.entries(first.levels));\n for (const [name, amount] of Object.entries(second.levels)) {\n const same = levels.get(name);\n if (same === undefined) {\n levels.set(name, amount);\n continue;\n }\n const level = plus(same, amount, `second.levels.${name}`, `The levels \"${name}\"`);\n if (level.tag === \"err\") return level;\n levels.set(name, level.value);\n }\n\n const total: Demand = {\n classes: [...classes.values()].sort((a, b) => inOrder(a.id, b.id)),\n levels: Object.fromEntries([...levels].sort(([a], [b]) => inOrder(a, b))),\n };\n // The sum can have a problem that no part has: a level of one demand with the name of a variable of the other.\n const together = firstProblem(total);\n return together === undefined ? ok(total) : err(together);\n};\n\n/**\n * This function gives the sum of the rates of the classes of a demand, in `unit`. A demand with no\n * class has a rate of 0.\n *\n * It gives a problem for a demand that is not correct, and for a unit that is not a unit of a\n * rate. It gives a problem for a class whose rate counts a different thing, for example events.\n */\nexport const totalRate = (demand: Demand, unit: string): Result<Quantity, WorkloadProblem> => {\n const bad = firstProblem(demand);\n if (bad !== undefined) return err(bad);\n if (!isCanonicalUnit(unit) || kindOf(unit) !== \"frequency\") {\n return err(workloadProblem(\"unit\", \"unit\", `\"${unit}\" is not a canonical unit of a rate, for example \"{request}/s\".`));\n }\n for (const [index, entry] of demand.classes.entries()) {\n if (!convertible(entry.rate.unit, unit)) {\n const why = whyNotConvertible(entry.rate.unit, unit) ?? \"the units are different\";\n return err(workloadProblem(\"unit\", `classes[${index}].rate`, `The rate of the class \"${entry.id}\" is not in \"${unit}\": ${why}.`));\n }\n }\n // One cached factor for each pair of units: the search calls this function at each load.\n let value = 0;\n for (const entry of demand.classes) value += entry.rate.value * factorOf(entry.rate.unit, unit);\n const total = quantity(value, unit);\n return finite(total.value) ? ok(total) : err(workloadProblem(\"amount\", \"classes\", \"The rates do not have a finite sum.\"));\n};\n\n/**\n * A load tells which rate the variable `rate` of a law reads. The load `class` is the rate of one\n * class. The load `total` is the sum of the rates of all classes, the load of the whole instance.\n */\nexport type Load = \"class\" | \"total\";\n\n/** These options tell which rate the variable `rate` of a law reads. The load is `class` when the options give none. */\nexport interface PointOptions {\n readonly load?: Load;\n}\n\n/**\n * A point law is the part of a law that a load point reads: its id, and the id and the unit of each\n * variable. Thus a caller can get the points of a law before the fit of the law.\n */\nexport interface PointLaw extends Pick<Law, \"id\"> {\n readonly variables: readonly Pick<Variable, \"id\" | \"unit\">[];\n}\n\n/** This function gives the point of a law from a rate, the variables of one request, the levels of a demand and `given`. */\nconst pointOf = (demand: Demand, law: PointLaw, rate: Quantity | \"total\", request: Amounts, given: Amounts): Result<LoadPoint, WorkloadProblem> => {\n const point: Record<string, number> = {};\n for (const variable of law.variables) {\n const name = variable.id;\n const found: unknown[] = [];\n if (name === RATE) {\n if (rate === \"total\") {\n const total = totalRate(demand, variable.unit);\n if (total.tag === \"err\") return err({ ...total.error, path: name, message: `The variable \"${name}\" of the law \"${law.id}\" reads the total rate. ${total.error.message}` });\n found.push(total.value);\n } else found.push(rate);\n }\n for (const amounts of [request, demand.levels, given]) {\n if (Object.hasOwn(amounts, name)) found.push(amounts[name]);\n }\n const [amount] = found;\n if (found.length === 0) {\n return err(workloadProblem(\"variable\", name, `The demand gives no amount for the variable \"${name}\" of the law \"${law.id}\".`));\n }\n if (found.length > 1) {\n return err(workloadProblem(\"variable\", name, `The demand gives the variable \"${name}\", and the caller gives it also.`));\n }\n if (!isQuantity(amount)) {\n return err(workloadProblem(\"amount\", name, `The amount of \"${name}\" from the caller is not a finite amount in a canonical unit.`));\n }\n if (!isCanonicalUnit(variable.unit)) {\n return err(workloadProblem(\"unit\", name, `The unit \"${variable.unit}\" of the variable \"${name}\" of the law \"${law.id}\" is not canonical.`));\n }\n if (!convertible(amount.unit, variable.unit)) {\n const why = whyNotConvertible(amount.unit, variable.unit) ?? \"the units are different\";\n return err(\n workloadProblem(\"unit\", name, `The variable \"${name}\" of the law \"${law.id}\" is in \"${variable.unit}\", not in \"${amount.unit}\": ${why}.`),\n );\n }\n point[name] = amount.value * factorOf(amount.unit, variable.unit);\n }\n return ok(point);\n};\n\n/**\n * This function gives the load point of one class of a demand for a law. The point has one number\n * for each variable of the law, in the unit of that variable.\n *\n * The variable `rate` is the rate of the class, or the total rate with the load `total`. Each other\n * variable is a variable of the request of the class, a level of the demand, or an amount of\n * `given`. The amounts of `given` are the state of an instance, for example the size of its heap\n * and its age. No workload gives that state.\n *\n * It gives a problem for a demand that is not correct and for a class that the demand does not\n * have. It gives a problem for a variable with no amount or with two amounts. It gives a problem\n * for an amount that does not convert to the unit of the variable.\n */\nexport const loadPointOf = (\n demand: Demand,\n id: string,\n law: PointLaw,\n given: Amounts = {},\n options: PointOptions = {},\n): Result<LoadPoint, WorkloadProblem> => {\n const bad = firstProblem(demand);\n if (bad !== undefined) return err(bad);\n const entry = demand.classes.find((candidate) => candidate.id === id);\n if (entry === undefined) return err(workloadProblem(\"class\", \"classes\", `The demand has no class \"${id}\".`));\n return pointOf(demand, law, (options.load ?? \"class\") === \"class\" ? entry.rate : \"total\", entry.request, given);\n};\n\n/**\n * This function gives the load point of a whole instance for a law: a point with no class. The\n * variable `rate` is the total rate of the demand. Each other variable is a level of the demand or\n * an amount of `given`. A variable of a request has no amount here.\n *\n * It gives the problems of `loadPointOf`, with no problem of a class.\n */\nexport const instancePointOf = (demand: Demand, law: PointLaw, given: Amounts = {}): Result<LoadPoint, WorkloadProblem> => {\n const bad = firstProblem(demand);\n if (bad !== undefined) return err(bad);\n return pointOf(demand, law, \"total\", {}, given);\n};\n","import { err, ok, type Result } from \"@mark1russell7/optional\";\nimport {\n UnitError,\n convertible,\n divideUnits,\n isCanonicalUnit,\n kindOf,\n multiplyUnits,\n parseUnit,\n factorOf,\n isQuantity,\n whyNotConvertible,\n} from \"@mark1russell7/quantity\";\nimport { instancePointOf, loadPointOf, totalRate, type Load } from \"./demand.ts\";\nimport { DEFAULT_LEVEL, type Law, type Measure, type Problem, type ProblemCode } from \"./law.ts\";\nimport { NAME, SLUG, finite, repeated } from \"./names.ts\";\nimport { recordOf, valuesAt } from \"./program.ts\";\nimport { edgePointOf, edgeValuesOf, heldValue, intervalOf, levelProblem, pointValuesOf, runOf, type LevelOptions, type LoadPoint, type Range } from \"./value.ts\";\nimport { demandProblems } from \"./workload-check.ts\";\nimport { RATE, type Amounts, type Demand, type WorkloadClass, type WorkloadProblemCode } from \"./workload.ts\";\n\n/** This text is the format of a composition file. */\nexport const COMPOSITION_FORMAT = \"capacity-composition/1\";\n\n/**\n * The scope of a law term tells where the law applies. The scope `instance` gives one part with no\n * class. The scope `each` gives one part for each class of the demand. A list of class ids gives\n * one part for each class in the list.\n */\nexport type Over = \"instance\" | \"each\" | readonly string[];\n\n/**\n * A law term adds a law to a composition, times `factor` (1 when the term gives none). The field\n * `load` tells which rate the variable `rate` of the law reads. A term over the instance always\n * reads the total rate.\n *\n * A term with a `base` gives the change of its law from the base point. The change is the value at\n * the load point less the value at the base point. The base point is the load point, with the\n * amount of `base` for each variable that `base` names. Use it for a law of a ladder of one level.\n * That ladder holds the other levels at a base point. A demand with no amount for a variable of\n * `base` stays at the base point, thus the change is 0.\n */\nexport interface LawTerm {\n readonly law: string;\n readonly over: Over;\n readonly load?: Load | undefined;\n readonly factor?: number | undefined;\n readonly base?: Amounts | undefined;\n}\n\n/**\n * A nested term adds the value of a different composition over the same demand, times `factor`.\n * Thus layer 3 of an app names layer 2, and layer 2 names layer 1. No layer copies the terms of\n * an other layer.\n */\nexport interface NestedTerm {\n readonly composition: string;\n readonly factor?: number | undefined;\n}\n\n/** A composition term is a law term or a nested term. */\nexport type CompositionTerm = LawTerm | NestedTerm;\n\n/**\n * A composition gives one measure of a subject as a sum of laws over a demand. Each term gives\n * parts, and the value is the sum of the parts in the unit of the measure.\n *\n * The units of a law term tell if a part is the value of the law times a rate. A law of the CPU\n * time of one request, in `{core}·ms/{request}`, gives `{core}` times the rate of its class. A law\n * of the memory of an instance, in `MiB`, gives `MiB` with no rate.\n */\nexport interface Composition {\n readonly format: typeof COMPOSITION_FORMAT;\n readonly id: string;\n readonly title: string;\n readonly subject: string;\n readonly measure: Measure;\n readonly terms: readonly CompositionTerm[];\n}\n\n/** A catalog holds the laws and the compositions that the terms of a composition can name. */\nexport interface Catalog {\n readonly laws: readonly Law[];\n readonly compositions?: readonly Composition[];\n}\n\n/** These options set the level of the intervals and the state of the instance: its heap and its age, for example. */\nexport interface CompositionOptions extends LevelOptions {\n readonly given?: Amounts;\n}\n\n/** A composition problem code names the part of a composition, or of a query, that is not correct. */\nexport type CompositionProblemCode = ProblemCode | WorkloadProblemCode | \"term\" | \"law\" | \"composition\";\n\n/** A composition problem tells what is not correct, and where. */\nexport type CompositionProblem = Problem<CompositionProblemCode>;\n\n/**\n * A part value is one part of a composition value, in the unit of the composition. The `weight`\n * is the number that multiplies the value of the law or of the nested composition. The ends of a\n * range change places when the weight is less than 0.\n */\ninterface PartBase {\n readonly term: number;\n readonly weight: number;\n readonly value: number;\n readonly interval: Range;\n readonly run: Range;\n}\n\n/**\n * A law part is the value of a law at the point of one class. When `class` is null, it is the\n * value at the point of the instance. A term with a base gives two parts. The first part is at the load point.\n * The second part is at the base point, with `base` true and the weight times -1.\n */\nexport interface LawPart extends PartBase {\n readonly kind: \"law\";\n readonly law: string;\n readonly class: string | null;\n readonly base: boolean;\n readonly outside: readonly string[];\n}\n\n/** A nested part is the value of a nested composition, with its own parts. */\nexport interface NestedPart extends PartBase {\n readonly kind: \"composition\";\n readonly composition: string;\n readonly parts: readonly PartValue[];\n}\n\n/** A part value is a law part or a nested part. */\nexport type PartValue = LawPart | NestedPart;\n\n/**\n * A composition value is the answer of a composition over a demand, in the unit of its measure.\n *\n * Replicate `i` is the sum of row `i` of each law, each times its weight. The `interval` is the\n * share `level` of the replicates, made wider to hold the value. The range `run` is where one\n * measured run falls. The value is an extrapolation when `extrapolated` is true: a part reads a\n * variable outside its range.\n */\nexport interface CompositionValue {\n readonly value: number;\n readonly unit: string;\n readonly level: number;\n readonly interval: Range;\n readonly run: Range;\n readonly replicates: readonly number[];\n readonly parts: readonly PartValue[];\n readonly extrapolated: boolean;\n}\n\nconst problem = (code: CompositionProblemCode, path: string, message: string): CompositionProblem => ({ code, path, message });\n\n/** This function tells if a term names a law. */\nexport const isLawTerm = (term: CompositionTerm): term is LawTerm => Object.hasOwn(term, \"law\");\n\n/** This function gives the reason that the values of a unit do not add, or undefined when they add. */\nconst sumUnitProblem = (unit: string): string | undefined => {\n if (!isCanonicalUnit(unit)) return `\"${unit}\" is not a canonical unit.`;\n const parsed = parseUnit(unit);\n if (parsed.log) return `\"${unit}\" is a level, and levels do not add.`;\n if (parsed.offset !== undefined) return `\"${unit}\" is an absolute temperature, and absolute temperatures do not add.`;\n return undefined;\n};\n\nconst NOT_SLUG = 'is not lower-case words joined by \".\", \"-\" or \"/\".';\n\n/**\n * This function examines a composition and gives each problem that it finds. A composition with no\n * problem gives an empty list.\n *\n * It examines the format, the ids, the title and the unit of the measure. It examines that each\n * term names a law or a composition and has a correct scope. It examines that each factor is a\n * finite number other than 0. It does not look for the laws: `compositionValue` does that.\n */\nexport const checkComposition = (composition: Composition): readonly CompositionProblem[] => {\n const problems: CompositionProblem[] = [];\n const add = (code: CompositionProblemCode, path: string, message: string): void => {\n problems.push(problem(code, path, message));\n };\n if (composition.format !== COMPOSITION_FORMAT) add(\"format\", \"format\", `The format is not \"${COMPOSITION_FORMAT}\".`);\n for (const [path, id] of [\n [\"id\", composition.id],\n [\"subject\", composition.subject],\n [\"measure.id\", composition.measure.id],\n ] as const) {\n if (!SLUG.test(id)) add(\"id\", path, `\"${id}\" ${NOT_SLUG}`);\n }\n if (composition.title.trim() === \"\") add(\"id\", \"title\", \"The title is empty.\");\n const unit = sumUnitProblem(composition.measure.unit);\n if (unit !== undefined) add(\"unit\", \"measure.unit\", unit);\n if (composition.terms.length === 0) add(\"term\", \"terms\", \"The composition has no term.\");\n\n for (const [index, term] of composition.terms.entries()) {\n const path = `terms[${index}]`;\n if (term.factor !== undefined && (!finite(term.factor) || term.factor === 0)) {\n add(\"factor\", `${path}.factor`, `The factor ${term.factor} is not a finite number other than 0.`);\n }\n if (!isLawTerm(term)) {\n if (!SLUG.test(term.composition)) add(\"id\", `${path}.composition`, `\"${term.composition}\" ${NOT_SLUG}`);\n else if (term.composition === composition.id) add(\"composition\", `${path}.composition`, \"The composition names itself.\");\n continue;\n }\n if (!SLUG.test(term.law)) add(\"id\", `${path}.law`, `\"${term.law}\" ${NOT_SLUG}`);\n if (typeof term.over !== \"string\") {\n if (term.over.length === 0) add(\"class\", `${path}.over`, \"The list of classes is empty.\");\n for (const [at, id] of term.over.entries()) {\n if (!SLUG.test(id)) add(\"id\", `${path}.over[${at}]`, `\"${id}\" ${NOT_SLUG}`);\n }\n const twice = repeated(term.over);\n if (twice !== undefined) add(\"class\", `${path}.over`, `The list has the class \"${twice}\" two times.`);\n } else if (term.over !== \"instance\" && term.over !== \"each\") {\n add(\"term\", `${path}.over`, `The scope \"${String(term.over)}\" is not \"instance\", \"each\" or a list of classes.`);\n }\n if (term.over === \"instance\" && term.load === \"class\") {\n add(\"term\", `${path}.load`, \"A term over the instance has no class. Its law reads the total rate.\");\n }\n if (term.base !== undefined) {\n const names = Object.keys(term.base);\n if (names.length === 0) add(\"term\", `${path}.base`, \"The base names no variable.\");\n for (const name of names) {\n const where = `${path}.base.${name}`;\n if (!NAME.test(name)) add(\"variable\", where, `\"${name}\" is not a name: a lower-case letter, then letters and digits.`);\n else if (name === RATE) add(\"variable\", where, \"The rate comes from the demand. A base does not hold it.\");\n else if (!isQuantity(term.base[name])) add(\"amount\", where, `The amount of \"${name}\" is not a finite amount in a canonical unit.`);\n }\n }\n }\n return problems;\n};\n\n/**\n * A weight multiplies the value of the law of a term. It is the number `by`. When the units of the\n * law need a rate, it is also times the rate of the part in the unit `rate`.\n */\ninterface Weight {\n readonly by: number;\n readonly rate: string | undefined;\n}\n\n/**\n * This function gives the weight that changes a value in `from` to a value in `to`. The quotient\n * `to / from` decides. A quotient with no dimension needs no rate. A quotient that is a rate needs\n * the rate of the part, in the unit of the quotient.\n */\nconst weightOf = (from: string, to: string, factor: number, path: string): Result<Weight, CompositionProblem> => {\n try {\n const per = divideUnits(to, from);\n if (convertible(per, \"count\")) return ok({ by: factor * factorOf(from, to), rate: undefined });\n if (kindOf(per) === \"frequency\") return ok({ by: factor * factorOf(multiplyUnits(from, per), to), rate: per });\n return err(problem(\"unit\", path, `The law gives \"${from}\". That unit does not give \"${to}\", alone or times a rate.`));\n } catch (error) {\n if (error instanceof UnitError) return err(problem(\"unit\", path, `The law gives \"${from}\", and \"${to}\" does not come from it: ${error.message}`));\n throw error;\n }\n};\n\n/** This function gives the number that the rate of a class is in the unit of a weight, or the problem that stops it. */\nconst classRate = (demand: Demand, id: string, unit: string, path: string): Result<number, CompositionProblem> => {\n const rate = (demand.classes.find((entry) => entry.id === id) as WorkloadClass).rate;\n if (!convertible(rate.unit, unit)) {\n const why = whyNotConvertible(rate.unit, unit) ?? \"the units are different\";\n return err(problem(\"unit\", `${path}.rate`, `The rate of the class \"${id}\" is in \"${rate.unit}\". The law needs a rate in \"${unit}\": ${why}.`));\n }\n return ok(rate.value * factorOf(rate.unit, unit));\n};\n\n/** This function gives the number that the total rate of a demand is in the unit of a weight, or the problem that stops it. */\nconst instanceRate = (demand: Demand, unit: string, path: string): Result<number, CompositionProblem> => {\n const total = totalRate(demand, unit);\n return total.tag === \"err\" ? err(under(total.error, path)) : ok(total.value.value);\n};\n\n/**\n * This function gives the problem of the base of a term for its law, or undefined. Each name of the\n * base is a variable of the law, and its amount converts to the unit of that variable.\n */\nconst baseProblem = (law: Law, base: Amounts, path: string): CompositionProblem | undefined => {\n for (const [name, amount] of Object.entries(base)) {\n const variable = law.variables.find((each) => each.id === name);\n if (variable === undefined) return problem(\"variable\", `${path}.${name}`, `The law \"${law.id}\" has no variable \"${name}\".`);\n if (!convertible(amount.unit, variable.unit)) {\n const why = whyNotConvertible(amount.unit, variable.unit) ?? \"the units are different\";\n return problem(\"unit\", `${path}.${name}`, `The variable \"${name}\" of the law \"${law.id}\" is in \"${variable.unit}\", not in \"${amount.unit}\": ${why}.`);\n }\n }\n return undefined;\n};\n\n/** This function gives the amounts of a base that no list of amounts gives. The point holds them at the base. */\nconst heldOf = (base: Amounts, lists: readonly Amounts[]): Amounts =>\n Object.fromEntries(Object.entries(base).filter(([name]) => !lists.some((amounts) => Object.hasOwn(amounts, name))));\n\n/** This function gives the base point of a term: the load point, with the amount of the base for each variable that it names. */\nconst basePointOf = (law: Law, point: LoadPoint, base: Amounts): LoadPoint => {\n const next: Record<string, number> = { ...point };\n for (const [name, amount] of Object.entries(base)) {\n const variable = law.variables.find((each) => each.id === name) as Law[\"variables\"][number];\n next[name] = amount.value * factorOf(amount.unit, variable.unit);\n }\n return next;\n};\n\n/** The sum of the parts of one composition, with the change from its interval to its run. */\ninterface Sum {\n readonly unit: string;\n readonly value: number;\n readonly replicates: readonly number[];\n readonly widen: Range;\n readonly parts: readonly PartValue[];\n readonly extrapolated: boolean;\n}\n\n/** This function gives a range times a weight. The ends change places for a weight less than 0. */\nconst times = (range: Range, weight: number): Range =>\n weight >= 0 ? { low: weight * range.low, high: weight * range.high } : { low: weight * range.high, high: weight * range.low };\n\n/** This function gives a problem of a query with the path of its term in front. */\nconst under = (found: Problem<string>, path: string): CompositionProblem => ({\n code: found.code as CompositionProblemCode,\n path: `${path}.${found.path}`,\n message: found.message,\n});\n\n/** This function gives a map of records by id, or the problem of an id that the list has two times. */\nconst byId = <T extends { readonly id: string }>(records: readonly T[], what: string): Result<Map<string, T>, CompositionProblem> => {\n const map = new Map<string, T>();\n for (const [index, record] of records.entries()) {\n if (map.has(record.id)) return err(problem(what === \"laws\" ? \"law\" : \"composition\", `${what}[${index}].id`, `The catalog has two ${what} with the id \"${record.id}\".`));\n map.set(record.id, record);\n }\n return ok(map);\n};\n\n/** A prepared composition holds each law and each nested composition that a composition reads, and the count of its rows. */\nexport interface Prepared {\n readonly composition: Composition;\n readonly reads: ReadonlyMap<string, Law>;\n readonly nested: ReadonlyMap<string, Composition>;\n /** This count is the count of replicates of the composition: the least count of the laws that it reads. */\n readonly rows: number;\n readonly level: number;\n}\n\n/**\n * This function examines a composition and its catalog one time, for the queries over many demands.\n * It gives each problem of `compositionValue` that does not come from a demand.\n */\nexport const preparedOf = (composition: Composition, catalog: Catalog, level: number): Result<Prepared, CompositionProblem> => {\n const own = checkComposition(composition)[0];\n if (own !== undefined) return err(own);\n const laws = byId(catalog.laws, \"laws\");\n if (laws.tag === \"err\") return laws;\n const nested = byId(catalog.compositions ?? [], \"compositions\");\n if (nested.tag === \"err\") return nested;\n\n // The walk finds each law that the composition reads, and each problem of a name or a cycle.\n const reads = new Map<string, Law>();\n const walked = new Set<string>();\n const walk = (at: Composition, prefix: string, stack: readonly string[]): CompositionProblem | undefined => {\n for (const [index, term] of at.terms.entries()) {\n const path = `${prefix}terms[${index}]`;\n if (isLawTerm(term)) {\n const law = laws.value.get(term.law);\n if (law === undefined) return problem(\"law\", `${path}.law`, `The catalog has no law \"${term.law}\".`);\n const badBase = baseProblem(law, term.base ?? {}, `${path}.base`);\n if (badBase !== undefined) return badBase;\n reads.set(law.id, law);\n continue;\n }\n if (stack.includes(term.composition)) {\n return problem(\"composition\", `${path}.composition`, `The compositions make a cycle: ${[...stack, term.composition].join(\" → \")}.`);\n }\n const next = nested.value.get(term.composition);\n if (next === undefined) return problem(\"composition\", `${path}.composition`, `The catalog has no composition \"${term.composition}\".`);\n if (walked.has(next.id)) continue;\n const inner = `compositions.${next.id}.`;\n const bad = checkComposition(next)[0];\n if (bad !== undefined) return { ...bad, path: `${inner}${bad.path}` };\n const deeper = walk(next, inner, [...stack, next.id]);\n if (deeper !== undefined) return deeper;\n walked.add(next.id);\n }\n return undefined;\n };\n const broken = walk(composition, \"\", [composition.id]);\n if (broken !== undefined) return err(broken);\n\n for (const law of reads.values()) {\n const noLevel = levelProblem(law, level, true);\n if (noLevel !== undefined) return err(under(noLevel, `laws.${law.id}`));\n }\n const rows = Math.min(...[...reads.values()].map((law) => law.replicates.length));\n return ok({ composition, reads, nested: nested.value, rows, level });\n};\n\n/** A leaf is the law of one part at its load point, times its weight. The path names the part in a problem. */\ninterface Leaf {\n readonly kind: \"law\";\n readonly term: number;\n readonly law: Law;\n readonly class: string | null;\n readonly base: boolean;\n readonly weight: number;\n readonly point: LoadPoint;\n readonly path: string;\n}\n\n/** A branch is the tree of a nested composition, times its weight. */\ninterface Branch {\n readonly kind: \"composition\";\n readonly term: number;\n readonly composition: string;\n readonly weight: number;\n readonly tree: Tree;\n}\n\n/** A tree is the parts of one composition over one demand, before the laws give their values. */\ninterface Tree {\n readonly unit: string;\n readonly nodes: readonly (Leaf | Branch)[];\n}\n\n/** This function gives the tree of a prepared composition over a demand, or the problem that stops it. It does not examine the demand. */\nconst treeOf = (prepared: Prepared, demand: Demand, given: Amounts): Result<Tree, CompositionProblem> => {\n const trees = new Map<string, Tree>();\n const build = (at: Composition, prefix: string): Result<Tree, CompositionProblem> => {\n const unit = at.measure.unit;\n const nodes: (Leaf | Branch)[] = [];\n for (const [index, term] of at.terms.entries()) {\n const path = `${prefix}terms[${index}]`;\n const factor = term.factor ?? 1;\n if (!isLawTerm(term)) {\n const inner = prepared.nested.get(term.composition) as Composition;\n let tree = trees.get(inner.id);\n if (tree === undefined) {\n const found = build(inner, `compositions.${inner.id}.`);\n if (found.tag === \"err\") return found;\n tree = found.value;\n trees.set(inner.id, tree);\n }\n if (!convertible(tree.unit, unit)) {\n const why = whyNotConvertible(tree.unit, unit) ?? \"the units are different\";\n return err(problem(\"unit\", `${path}.composition`, `The composition \"${inner.id}\" gives \"${tree.unit}\", not \"${unit}\": ${why}.`));\n }\n nodes.push({ kind: \"composition\", term: index, composition: inner.id, weight: factor * factorOf(tree.unit, unit), tree });\n continue;\n }\n\n const law = prepared.reads.get(term.law) as Law;\n const weight = weightOf(law.measure.unit, unit, factor, `${path}.law`);\n if (weight.tag === \"err\") return weight;\n const targets: readonly (string | null)[] =\n term.over === \"instance\" ? [null] : term.over === \"each\" ? demand.classes.map((entry) => entry.id) : term.over;\n for (const id of targets) {\n const where = `${path}.${id ?? \"instance\"}`;\n const request = id === null ? {} : (demand.classes.find((entry) => entry.id === id)?.request ?? {});\n const state = term.base === undefined ? given : { ...heldOf(term.base, [request, demand.levels, given]), ...given };\n const point = id === null ? instancePointOf(demand, law, state) : loadPointOf(demand, id, law, state, { load: term.load ?? \"class\" });\n if (point.tag === \"err\") return err(under(point.error, where));\n let by = weight.value.by;\n const rateUnit = weight.value.rate;\n if (rateUnit !== undefined) {\n const rate = id === null ? instanceRate(demand, rateUnit, where) : classRate(demand, id, rateUnit, where);\n if (rate.tag === \"err\") return rate;\n by *= rate.value;\n }\n nodes.push({ kind: \"law\", term: index, law, class: id, base: false, weight: by, point: point.value, path: where });\n if (term.base !== undefined) {\n nodes.push({ kind: \"law\", term: index, law, class: id, base: true, weight: -by, point: basePointOf(law, point.value, term.base), path: `${where}.base` });\n }\n }\n }\n return ok({ unit, nodes });\n };\n return build(prepared.composition, \"\");\n};\n\n/** This function gives the sum of the parts of a tree, with the values of its laws. The map `sums` keeps the sum of each nested tree. */\nconst sumOf = (tree: Tree, rows: number, level: number, sums: Map<Tree, Sum>): Result<Sum, CompositionProblem> => {\n const known = sums.get(tree);\n if (known !== undefined) return ok(known);\n const replicates = new Array<number>(rows).fill(0);\n const widen = { low: 0, high: 0 };\n const parts: PartValue[] = [];\n let value = 0;\n let extrapolated = false;\n const keep = (part: PartValue, spread: readonly number[], change: Range): void => {\n parts.push(part);\n value += part.value;\n for (const [row, draw] of spread.entries()) replicates[row] = (replicates[row] as number) + part.weight * draw;\n const scaled = times(change, part.weight);\n widen.low += scaled.low;\n widen.high += scaled.high;\n };\n\n for (const node of tree.nodes) {\n if (node.kind === \"composition\") {\n const found = sumOf(node.tree, rows, level, sums);\n if (found.tag === \"err\") return found;\n const sum = found.value;\n const { weight } = node;\n const interval = intervalOf(sum.value, sum.replicates, level);\n const scaled = times(interval, weight);\n const change = times(sum.widen, weight);\n keep(\n {\n kind: \"composition\",\n term: node.term,\n composition: node.composition,\n weight,\n value: weight * sum.value,\n interval: scaled,\n run: { low: scaled.low + change.low, high: scaled.high + change.high },\n parts: sum.parts,\n },\n sum.replicates,\n sum.widen,\n );\n extrapolated ||= sum.extrapolated;\n continue;\n }\n\n const evaluated = pointValuesOf(node.law, node.point);\n if (evaluated.tag === \"err\") return err(under(evaluated.error, node.path));\n const by = node.weight;\n const [estimate, ...all] = evaluated.value.values;\n const spread = all.slice(0, rows);\n const interval = intervalOf(estimate, spread, level);\n const run = runOf(node.law, interval, level);\n const change = { low: run.low - interval.low, high: run.high - interval.high };\n const scaled = times(interval, by);\n const scaledChange = times(change, by);\n keep(\n {\n kind: \"law\",\n term: node.term,\n law: node.law.id,\n class: node.class,\n base: node.base,\n weight: by,\n value: by * estimate,\n interval: scaled,\n run: { low: scaled.low + scaledChange.low, high: scaled.high + scaledChange.high },\n outside: evaluated.value.outside,\n },\n spread,\n change,\n );\n extrapolated ||= evaluated.value.outside.length > 0;\n }\n const sum: Sum = { unit: tree.unit, value, replicates, widen, parts, extrapolated };\n sums.set(tree, sum);\n return ok(sum);\n};\n\n/**\n * This function gives the value of a composition over a demand, with its interval. The catalog\n * gives each law and each nested composition that a term names. It can hold more.\n *\n * Each part pairs its replicates by row. Row `i` of each law is one draw of the doubt of that law.\n * Laws from separate fits have independent rows. Two laws that share points share their doubt\n * only when their fits use the same resample for row `i`. The count of rows is the least count of\n * the laws that the composition reads.\n *\n * The range `run` adds the change from the interval to the run of each part. That sum is exact\n * when the noise of each part moves with the noise of each other part. For independent noise, the\n * sum is wider than the true range. Thus the range is on the safe side for a limit.\n *\n * The function gives a problem for a composition that is not correct, for a missing law or\n * composition, and for a cycle of compositions. It gives the problems of `loadPointOf` and of\n * `lawValue` for each part, with the path of the term in front.\n */\nexport const compositionValue = (\n composition: Composition,\n catalog: Catalog,\n demand: Demand,\n options: CompositionOptions = {},\n): Result<CompositionValue, CompositionProblem> => {\n const level = options.level ?? DEFAULT_LEVEL;\n const own = checkComposition(composition)[0];\n if (own !== undefined) return err(own);\n const badDemand = demandProblems(demand)[0];\n if (badDemand !== undefined) return err(under(badDemand, \"demand\"));\n const prepared = preparedOf(composition, catalog, level);\n if (prepared.tag === \"err\") return prepared;\n const tree = treeOf(prepared.value, demand, options.given ?? {});\n if (tree.tag === \"err\") return tree;\n const sum = sumOf(tree.value, prepared.value.rows, level, new Map());\n if (sum.tag === \"err\") return sum;\n const { value, replicates, widen, parts, extrapolated } = sum.value;\n const interval = intervalOf(value, replicates, level);\n return ok({\n value,\n unit: composition.measure.unit,\n level,\n interval,\n run: { low: interval.low + widen.low, high: interval.high + widen.high },\n replicates,\n parts,\n extrapolated,\n });\n};\n\n/** A flat part is the law of one part at its load point, times the product of the weights down to it. */\nexport interface FlatPart {\n readonly law: Law;\n readonly point: LoadPoint;\n readonly weight: number;\n}\n\n/** This function adds the leaves of a tree to `into`, each times `weight`. */\nconst flatten = (tree: Tree, weight: number, into: FlatPart[]): void => {\n for (const node of tree.nodes) {\n if (node.kind === \"composition\") flatten(node.tree, weight * node.weight, into);\n else into.push({ law: node.law, point: node.point, weight: weight * node.weight });\n }\n};\n\n/**\n * This function gives the flat parts of a prepared composition over a demand, or the problem that\n * stops them. The value of a row is the sum of the law of each part at its point, times its weight.\n * The function does not examine the demand.\n */\nexport const flatPartsOf = (prepared: Prepared, demand: Demand, given: Amounts = {}): Result<readonly FlatPart[], CompositionProblem> => {\n const tree = treeOf(prepared, demand, given);\n if (tree.tag === \"err\") return tree;\n const parts: FlatPart[] = [];\n flatten(tree.value, 1, parts);\n return ok(parts);\n};\n\n/**\n * This function gives the value of one row of some flat parts. Row 0 is the estimate, and row `i`\n * is replicate `i - 1` of each law. A part with no finite value gives undefined.\n */\nexport const rowValueOf = (parts: readonly FlatPart[], row: number): number | undefined => rowValuesOf(parts, row, row)[0];\n\n/** This function gives the record that the law of a part reads in one row, or undefined when the law has no such row. */\nconst rowRecordOf = (law: Law, point: LoadPoint, row: number): Readonly<Record<string, number>> | undefined => {\n const values = row === 0 ? law.constants.map((constant) => constant.value) : law.replicates[row - 1];\n return values === undefined ? undefined : recordOf(law.constants.map((constant) => constant.id), values, point);\n};\n\n/**\n * This function gives the value of each row from `first` to `last` of some flat parts, as `rowValueOf` gives it.\n * It evaluates the law of each part over all the rows in one call. Thus a search that reads each row at one load\n * evaluates each law one time for that load. Past the range of a variable, each value holds, as heldValue tells.\n */\nexport const rowValuesOf = (parts: readonly FlatPart[], first: number, last: number): readonly (number | undefined)[] => {\n const sums: (number | undefined)[] = [];\n for (let row = first; row <= last; row += 1) sums.push(0);\n for (const { law, point, weight } of parts) {\n const edge = edgePointOf(law, point);\n const atEdge = edge === undefined ? undefined : edgeValuesOf(law, edge);\n const records: Readonly<Record<string, number>>[] = [];\n const slots: number[] = [];\n for (let row = first; row <= last; row += 1) {\n const record = sums[row - first] === undefined ? undefined : rowRecordOf(law, point, row);\n if (record === undefined) sums[row - first] = undefined;\n else {\n records.push(record);\n slots.push(row - first);\n }\n }\n valuesAt(law.form.program, records).forEach((value, index) => {\n const slot = slots[index] as number;\n const found = atEdge === undefined ? value : heldValue(value, atEdge[slot + first]);\n sums[slot] = found === undefined ? undefined : (sums[slot] as number) + weight * found;\n });\n }\n return sums.map((value) => (value !== undefined && Number.isFinite(value) ? value : undefined));\n};\n\n/** This function tells if a flat part reads a variable of its law outside the range of that variable. */\nexport const partsOutside = (parts: readonly FlatPart[]): boolean =>\n parts.some(({ law, point }) =>\n law.variables.some((variable) => (point[variable.id] as number) < variable.min || (point[variable.id] as number) > variable.max),\n );\n","import type { Quantity } from \"@mark1russell7/quantity\";\nimport type { Problem } from \"./law.ts\";\nimport type { Amounts } from \"./workload.ts\";\n\n/** This text is the format of an instance file. */\nexport const INSTANCE_FORMAT = \"capacity-instance/1\";\n\n/** This text is the format of a limits file. */\nexport const LIMITS_FORMAT = \"capacity-limits/1\";\n\n/**\n * These units are the unit of each resource that has one meaning in each instance. A resource with\n * one of these names is in a unit that converts to the unit here.\n *\n * - `cpu` is the CPU time that the instance gives in a unit of time, in cores.\n * - `memory` is the memory of the instance.\n * - `network` is the rate of the network of the instance.\n */\nexport const RESOURCE_UNITS: Readonly<Record<string, string>> = { cpu: \"{core}\", memory: \"B\", network: \"bit/s\" };\n\n/**\n * An instance is the resources of one copy of a service: the amount of each resource, by its\n * name. Each amount is above 0. An instance that does not have a resource does not name it.\n */\nexport interface Instance {\n readonly resources: Amounts;\n}\n\n/**\n * An instance type is one size of a machine or a container, with a name. An instance file is this\n * record as JSON. Each copy of a service on one instance type has equal resources.\n */\nexport interface InstanceType extends Instance {\n readonly format: typeof INSTANCE_FORMAT;\n readonly id: string;\n readonly title: string;\n}\n\n/** An amount ceiling is a fixed amount, for example a latency of 200 ms. It is equal on each instance. */\nexport interface AmountCeiling {\n readonly kind: \"amount\";\n readonly amount: Quantity;\n}\n\n/** A resource ceiling is the whole of one resource of the instance, for example its memory. It grows with the instance. */\nexport interface ResourceCeiling {\n readonly kind: \"resource\";\n readonly resource: string;\n}\n\n/** A ceiling is the largest amount of a measure: a fixed amount, or a resource of the instance. */\nexport type Ceiling = AmountCeiling | ResourceCeiling;\n\n/**\n * A limit is a ceiling on one measure of an instance, with headroom. The `headroom` is the share of\n * the ceiling that stays free, from 0 to below 1. The measure stays at or below the remainder.\n */\nexport interface Limit {\n readonly id: string;\n /** This id is the measure that the limit holds, for example `cpu` or `latency.p99`. */\n readonly measure: string;\n readonly ceiling: Ceiling;\n readonly headroom: number;\n}\n\n/** A limit set is the limits of a service, with a name. A limits file is this record as JSON. */\nexport interface LimitSet {\n readonly format: typeof LIMITS_FORMAT;\n readonly id: string;\n readonly title: string;\n readonly limits: readonly Limit[];\n}\n\n/** An instance problem code names the part of an instance that is not correct. */\nexport type InstanceProblemCode = \"shape\" | \"format\" | \"id\" | \"amount\" | \"unit\" | \"resource\";\n\n/** An instance problem tells what is not correct, and where: `path` is the path of the field in the instance. */\nexport type InstanceProblem = Problem<InstanceProblemCode>;\n\n/** A limit problem code names the part of a limit, or of a query of a limit, that is not correct. */\nexport type LimitProblemCode = \"shape\" | \"format\" | \"id\" | \"measure\" | \"amount\" | \"unit\" | \"resource\" | \"headroom\";\n\n/** A limit problem tells what is not correct, and where: `path` is the path of the field in the limit or in the query. */\nexport type LimitProblem = Problem<LimitProblemCode>;\n","import { convertible, isQuantity } from \"@mark1russell7/quantity\";\nimport {\n INSTANCE_FORMAT,\n LIMITS_FORMAT,\n RESOURCE_UNITS,\n type Instance,\n type InstanceProblem,\n type InstanceType,\n type Limit,\n type LimitProblem,\n type LimitSet,\n} from \"./instance.ts\";\nimport { NAME, SLUG, finite, repeated } from \"./names.ts\";\n\n/** This function makes a problem of an instance. */\nexport const instanceProblem = (code: InstanceProblem[\"code\"], path: string, message: string): InstanceProblem => ({\n code,\n path,\n message,\n});\n\n/** This function makes a problem of a limit. */\nexport const limitProblem = (code: LimitProblem[\"code\"], path: string, message: string): LimitProblem => ({ code, path, message });\n\n/**\n * This function examines the resources of an instance and gives each problem that it finds. An\n * instance with no problem gives an empty list.\n *\n * It examines that the instance has a resource. It examines the name and the amount of each\n * resource. It examines the unit of each resource of `RESOURCE_UNITS`.\n */\nexport const instanceProblems = (instance: Instance): readonly InstanceProblem[] => {\n const problems: InstanceProblem[] = [];\n const entries = Object.entries(instance.resources);\n if (entries.length === 0) problems.push(instanceProblem(\"resource\", \"resources\", \"The instance has no resource.\"));\n for (const [name, amount] of entries) {\n const at = `resources.${name}`;\n if (!NAME.test(name)) {\n problems.push(instanceProblem(\"id\", at, `The name \"${name}\" is not letters and digits that start with a lower-case letter.`));\n }\n if (!isQuantity(amount)) {\n problems.push(instanceProblem(\"amount\", at, `\"${name}\" is not a finite amount in a canonical unit.`));\n continue;\n }\n if (!(amount.value > 0)) problems.push(instanceProblem(\"amount\", at, `The resource \"${name}\" is not above 0.`));\n const unit = Object.hasOwn(RESOURCE_UNITS, name) ? RESOURCE_UNITS[name] : undefined;\n if (unit !== undefined && !convertible(amount.unit, unit)) {\n problems.push(instanceProblem(\"unit\", at, `The resource \"${name}\" is in \"${amount.unit}\". Its unit converts to \"${unit}\".`));\n }\n }\n return problems;\n};\n\n/**\n * This function examines an instance type and gives each problem that it finds. An instance type\n * with no problem gives an empty list.\n *\n * It examines the format, the id and the title. It examines the resources with `instanceProblems`.\n */\nexport const checkInstance = (type: InstanceType): readonly InstanceProblem[] => {\n const problems: InstanceProblem[] = [];\n if (type.format !== INSTANCE_FORMAT) {\n problems.push(instanceProblem(\"format\", \"format\", `The format is \"${String(type.format)}\", not \"${INSTANCE_FORMAT}\".`));\n }\n if (!SLUG.test(type.id)) {\n problems.push(instanceProblem(\"id\", \"id\", `The id \"${type.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n }\n if (type.title.trim() === \"\") problems.push(instanceProblem(\"id\", \"title\", \"The title is empty.\"));\n problems.push(...instanceProblems(type));\n return problems;\n};\n\n/**\n * This function examines one limit and gives each problem that it finds. The text `path` is the\n * path of the limit, and it goes before the path of each problem.\n */\nexport const limitProblems = (limit: Limit, path = \"\"): readonly LimitProblem[] => {\n const problems: LimitProblem[] = [];\n const at = (field: string): string => (path === \"\" ? field : `${path}.${field}`);\n if (!SLUG.test(limit.id)) {\n problems.push(limitProblem(\"id\", at(\"id\"), `The id \"${limit.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n }\n if (!SLUG.test(limit.measure)) {\n problems.push(limitProblem(\"measure\", at(\"measure\"), `The measure \"${limit.measure}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n }\n if (!finite(limit.headroom) || limit.headroom < 0 || limit.headroom >= 1) {\n problems.push(limitProblem(\"headroom\", at(\"headroom\"), `The headroom ${limit.headroom} is not a number from 0 to below 1.`));\n }\n const ceiling = limit.ceiling;\n if (ceiling.kind === \"resource\") {\n if (!NAME.test(ceiling.resource)) {\n problems.push(\n limitProblem(\"resource\", at(\"ceiling.resource\"), `The name \"${ceiling.resource}\" is not letters and digits that start with a lower-case letter.`),\n );\n }\n } else if (!isQuantity(ceiling.amount)) {\n problems.push(limitProblem(\"amount\", at(\"ceiling.amount\"), \"The ceiling is not a finite amount in a canonical unit.\"));\n } else if (!(ceiling.amount.value > 0)) {\n problems.push(limitProblem(\"amount\", at(\"ceiling.amount\"), \"The ceiling is not above 0.\"));\n }\n return problems;\n};\n\n/**\n * This function examines a limit set and gives each problem that it finds. A limit set with no\n * problem gives an empty list.\n *\n * It examines the format, the id and the title. It examines each limit with `limitProblems`. It\n * examines that two limits do not have one id.\n */\nexport const checkLimits = (set: LimitSet): readonly LimitProblem[] => {\n const problems: LimitProblem[] = [];\n if (set.format !== LIMITS_FORMAT) {\n problems.push(limitProblem(\"format\", \"format\", `The format is \"${String(set.format)}\", not \"${LIMITS_FORMAT}\".`));\n }\n if (!SLUG.test(set.id)) problems.push(limitProblem(\"id\", \"id\", `The id \"${set.id}\" is not lower-case words joined by \".\", \"-\" or \"/\".`));\n if (set.title.trim() === \"\") problems.push(limitProblem(\"id\", \"title\", \"The title is empty.\"));\n set.limits.forEach((limit, index) => problems.push(...limitProblems(limit, `limits[${index}]`)));\n const twice = repeated(set.limits.map((limit) => limit.id));\n if (twice !== undefined) problems.push(limitProblem(\"id\", \"limits\", `Two limits have the id \"${twice}\".`));\n return problems;\n};\n"],"mappings":";;;;;;;;AAIA,MAAa,aAAa;;AAG1B,MAAa,gBAAgB;;AAuM7B,MAAa,gBAAgB;;;;;AAM7B,MAAa,cAAc,UAA0B,KAAK,KAAK,KAAK,IAAI,SAAS,IAAI;;;;;AAMrF,MAAa,kBAAkB,WAA2B;CACxD,IAAI,QAAQ;CACZ,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,KAAK,QAAS,SAAS,SAAS,IAAI,KAAM;CACvE,OAAO,KAAK,MAAM,KAAK;AACzB;;;;;;;AAQA,MAAa,eAAe,UAA0B;CACpD,MAAM,OAAO,WAAW,KAAK;CAC7B,IAAI,SAAS;CACb,OAAO,eAAe,MAAM,IAAI,MAAM,UAAU;CAChD,OAAO;AACT;;;ACxOA,MAAa,OAAe;;AAG5B,MAAa,OAAe;AAE5B,MAAM,MAAM;;AAGZ,MAAa,SAAS,SAA0B,IAAI,KAAK,IAAI,KAAK,OAAO,SAAS,KAAK,MAAM,IAAI,CAAC;;AAGlG,MAAa,UAAU,UAA2B,OA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