@mark1russell7/capacity 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bt as LawProblem, Z as AppProblem, _ as Composition, a as InstanceProblem, f as LimitSet, l as Limit, q as AppContract, s as InstanceType, u as LimitProblem, xt as WorkloadProblem, y as CompositionProblem, yt as Workload, zt as Law } from "./instance-0n6WhJzF.js";
1
+ import { Vt as LawProblem, Z as AppProblem, _ as Composition, a as InstanceProblem, f as LimitSet, l as Limit, q as AppContract, s as InstanceType, u as LimitProblem, xt as WorkloadProblem, y as CompositionProblem, yt as Workload, zt as Law } from "./instance-sZmVOOvz.js";
2
2
  import { Result } from "@mark1russell7/optional";
3
3
  import { z } from "zod";
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;;qBAmDa,WAAW,EAAE,QAAQ;;;;;qBA+BrB,UAAU,kBAAkB,OAAO,cAAc;;;;;qBAQjD,mBAAmB,EAAE,QAAQ;;;;;;qBAyB7B,kBAAkB,kBAAkB,OAAO,sBAAsB;;;;;qBAYjE,gBAAgB,EAAE,QAAQ;;;;;;qBAiB1B,eAAe,kBAAkB,OAAO,mBAAmB;;;;;qBAM3D,gBAAgB,EAAE,QAAQ;;;;;;qBAY1B,eAAe,kBAAkB,OAAO,uBAAuB;;qBAG/D,aAAa,EAAE,QAAQ;;;;;qBAcvB,cAAc,EAAE,QAAQ;;;;;qBAWxB,aAAa,kBAAkB,OAAO,mBAAmB;;;;;qBAkBzD,WAAW,EAAE,QAAQ;;;;;qBAmDrB,UAAU,kBAAkB,OAAO,sBAAsB"}
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../src/schema.ts"],"mappings":";;;;;;;qBAmDa,WAAW,EAAE,QAAQ;;;;;qBAkCrB,UAAU,kBAAkB,OAAO,cAAc;;;;;qBAQjD,mBAAmB,EAAE,QAAQ;;;;;;qBAyB7B,kBAAkB,kBAAkB,OAAO,sBAAsB;;;;;qBAYjE,gBAAgB,EAAE,QAAQ;;;;;;qBAiB1B,eAAe,kBAAkB,OAAO,mBAAmB;;;;;qBAM3D,gBAAgB,EAAE,QAAQ;;;;;;qBAY1B,eAAe,kBAAkB,OAAO,uBAAuB;;qBAG/D,aAAa,EAAE,QAAQ;;;;;qBAcvB,cAAc,EAAE,QAAQ;;;;;qBAWxB,aAAa,kBAAkB,OAAO,mBAAmB;;;;;qBAkBzD,WAAW,EAAE,QAAQ;;;;;qBAmDrB,UAAU,kBAAkB,OAAO,sBAAsB"}
package/build/schema.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B as WORKLOAD_FORMAT, E as checkApp, F as checkWorkload, G as checkLaw, K as LAW_DOMAINS, N as APP_FORMAT, P as APP_LINE_KINDS, l as COMPOSITION_FORMAT, n as checkLimits, nt as LAW_FORMAT, o as INSTANCE_FORMAT, s as LIMITS_FORMAT, t as checkInstance, u as checkComposition } from "./instance-check-CAuD9L4Z.js";
1
+ import { B as WORKLOAD_FORMAT, E as checkApp, F as checkWorkload, G as checkLaw, K as LAW_DOMAINS, N as APP_FORMAT, P as APP_LINE_KINDS, l as COMPOSITION_FORMAT, n as checkLimits, nt as LAW_FORMAT, o as INSTANCE_FORMAT, s as LIMITS_FORMAT, t as checkInstance, u as checkComposition } from "./instance-check-Bt-SI8va.js";
2
2
  import { parse } from "@mark1russell7/vex";
3
3
  import { err, ok } from "@mark1russell7/optional";
4
4
  import { z } from "zod";
@@ -89,7 +89,17 @@ const lawSchema = z.strictObject({
89
89
  floor: z.number(),
90
90
  cpu: z.string(),
91
91
  runs: z.array(runSchema)
92
- })
92
+ }),
93
+ idle: z.strictObject({
94
+ load: z.string(),
95
+ cpu: z.string(),
96
+ bases: z.number(),
97
+ runs: z.number(),
98
+ measures: z.record(z.string(), z.strictObject({
99
+ value: z.number(),
100
+ unit: z.string()
101
+ }))
102
+ }).exactOptional()
93
103
  });
94
104
  /**
95
105
  * This function reads a law from the data of a law file. It gives the law when the data has the
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { err, ok, type Result } from \"@mark1russell7/optional\";\nimport { parse, type Expr } from \"@mark1russell7/vex\";\nimport { z } from \"zod\";\nimport { checkApp } from \"./app-check.ts\";\nimport { APP_FORMAT, APP_LINE_KINDS, type AppContract, type AppProblem } from \"./app.ts\";\nimport { checkLaw } from \"./check.ts\";\nimport { COMPOSITION_FORMAT, checkComposition, type Composition, type CompositionProblem } from \"./composition.ts\";\nimport { checkInstance, checkLimits } from \"./instance-check.ts\";\nimport {\n INSTANCE_FORMAT,\n LIMITS_FORMAT,\n type InstanceProblem,\n type InstanceType,\n type Limit,\n type LimitProblem,\n type LimitSet,\n} from \"./instance.ts\";\nimport { LAW_FORMAT, type Law, type LawProblem, type Problem } from \"./law.ts\";\nimport { LAW_DOMAINS } from \"./program.ts\";\nimport { checkWorkload } from \"./workload-check.ts\";\nimport { WORKLOAD_FORMAT, type Workload, type WorkloadProblem } from \"./workload.ts\";\n\n/** This function tells if a value from JSON is a Vex expression. */\nconst isProgram = (value: unknown): boolean => {\n const text = JSON.stringify(value);\n return text !== undefined && parse(text, LAW_DOMAINS).ok;\n};\n\n/**\n * This function makes the reader of a record. The reader examines the shape of the data with the\n * schema, then it examines the meaning with `check`. It gives the record, or each problem.\n */\nconst reader =\n <T, Code extends string>(schema: z.ZodType<T>, check: (record: T) => readonly Problem<Code>[]) =>\n (data: unknown): Result<T, readonly Problem<Code | \"shape\">[]> => {\n const shape = schema.safeParse(data);\n if (!shape.success) {\n return err(shape.error.issues.map((issue) => ({ code: \"shape\", path: issue.path.join(\".\"), message: issue.message })));\n }\n const problems = check(shape.data);\n return problems.length > 0 ? err(problems) : ok(shape.data);\n };\n\nconst fitErrorSchema = z.strictObject({ mae: z.number(), rmse: z.number() });\n\nconst runSchema = z.strictObject({ url: z.string(), commit: z.string(), date: z.string() });\n\n/**\n * This schema accepts the shape of a law file: each field with its type, and no other field. It\n * does not examine what the fields mean. The function `checkLaw` does that.\n */\nexport const lawSchema: z.ZodType<Law> = z.strictObject({\n format: z.literal(LAW_FORMAT),\n id: z.string(),\n title: z.string(),\n subject: z.string(),\n measure: z.strictObject({ id: z.string(), unit: z.string() }),\n variables: z.array(\n z.strictObject({ id: z.string(), unit: z.string(), min: z.number(), max: z.number(), scale: z.enum([\"linear\", \"log\"]) }),\n ),\n conditions: z.record(\n z.string(),\n z.union([z.string(), z.number(), z.boolean(), z.strictObject({ value: z.number(), unit: z.string() })]),\n ),\n form: z.strictObject({ id: z.string(), program: z.custom<Expr>(isProgram, \"The program is not a Vex expression.\") }),\n constants: z.array(z.strictObject({ id: z.string(), value: z.number() })),\n replicates: z.array(z.array(z.number())),\n fit: z.strictObject({\n method: z.string(),\n residual: z.enum([\"absolute\", \"relative\"]),\n residuals: z.array(z.number()),\n losers: z.array(z.strictObject({ form: z.string(), error: fitErrorSchema })),\n }),\n points: z.array(z.strictObject({ load: z.record(z.string(), z.number()), value: z.number(), run: z.number(), job: z.string() })).exactOptional(),\n evidence: z.strictObject({ runs: z.array(runSchema) }),\n noise: z.strictObject({ floor: z.number(), cpu: z.string(), runs: z.array(runSchema) }),\n});\n\n/**\n * This function reads a law from the data of a law file. It gives the law when the data has the\n * shape of a law and `checkLaw` finds no problem. If not, it gives each problem.\n */\nexport const readLaw: (data: unknown) => Result<Law, readonly LawProblem[]> = reader(lawSchema, checkLaw);\n\nconst factorSchema = z.number().optional();\n\n/**\n * This schema accepts the shape of a composition file: each field with its type, and no other\n * field. It does not examine what the fields mean. The function `checkComposition` does that.\n */\nexport const compositionSchema: z.ZodType<Composition> = z.strictObject({\n format: z.literal(COMPOSITION_FORMAT),\n id: z.string(),\n title: z.string(),\n subject: z.string(),\n measure: z.strictObject({ id: z.string(), unit: z.string() }),\n terms: z.array(\n z.union([\n z.strictObject({\n law: z.string(),\n over: z.union([z.literal(\"instance\"), z.literal(\"each\"), z.array(z.string())]),\n load: z.enum([\"class\", \"total\"]).optional(),\n factor: factorSchema,\n base: z.lazy(() => amountsSchema).optional(),\n }),\n z.strictObject({ composition: z.string(), factor: factorSchema }),\n ]),\n ),\n});\n\n/**\n * This function reads a composition from the data of a composition file. It gives the composition\n * when the data has the shape of one and `checkComposition` finds no problem. If not, it gives each\n * problem.\n */\nexport const readComposition: (data: unknown) => Result<Composition, readonly CompositionProblem[]> = reader(\n compositionSchema,\n checkComposition,\n);\n\nconst amountSchema = z.strictObject({ value: z.number(), unit: z.string() });\nconst amountsSchema = z.record(z.string(), amountSchema);\n\n/**\n * This schema accepts the shape of a workload file: each field with its type, and no other field.\n * It does not examine what the fields mean. The function `checkWorkload` does that.\n */\nexport const workloadSchema: z.ZodType<Workload> = z.strictObject({\n format: z.literal(WORKLOAD_FORMAT),\n id: z.string(),\n title: z.string(),\n classes: z.array(z.strictObject({ id: z.string(), of: z.string().optional(), rate: amountSchema, request: amountsSchema })),\n levels: amountsSchema,\n source: z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"plan\"), note: z.string() }),\n z.strictObject({ kind: z.literal(\"metrics\"), origin: z.string(), from: z.string(), to: z.string() }),\n ]),\n});\n\n/**\n * This function reads a workload from the data of a workload file. It gives the workload when the\n * data has the shape of a workload and `checkWorkload` finds no problem. If not, it gives each\n * problem.\n */\nexport const readWorkload: (data: unknown) => Result<Workload, readonly WorkloadProblem[]> = reader(workloadSchema, checkWorkload);\n\n/**\n * This schema accepts the shape of an instance file: each field with its type, and no other field.\n * It does not examine what the fields mean. The function `checkInstance` does that.\n */\nexport const instanceSchema: z.ZodType<InstanceType> = z.strictObject({\n format: z.literal(INSTANCE_FORMAT),\n id: z.string(),\n title: z.string(),\n resources: amountsSchema,\n});\n\n/**\n * This function reads an instance type from the data of an instance file. It gives the instance\n * type when the data has the shape of one and `checkInstance` finds no problem. If not, it gives\n * each problem.\n */\nexport const readInstance: (data: unknown) => Result<InstanceType, readonly InstanceProblem[]> = reader(instanceSchema, checkInstance);\n\n/** This schema accepts the shape of one limit: each field with its type, and no other field. */\nexport const limitSchema: z.ZodType<Limit> = z.strictObject({\n id: z.string(),\n measure: z.string(),\n ceiling: z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"amount\"), amount: amountSchema }),\n z.strictObject({ kind: z.literal(\"resource\"), resource: z.string() }),\n ]),\n headroom: z.number(),\n});\n\n/**\n * This schema accepts the shape of a limits file: each field with its type, and no other field.\n * It does not examine what the fields mean. The function `checkLimits` does that.\n */\nexport const limitsSchema: z.ZodType<LimitSet> = z.strictObject({\n format: z.literal(LIMITS_FORMAT),\n id: z.string(),\n title: z.string(),\n limits: z.array(limitSchema),\n});\n\n/**\n * This function reads a limit set from the data of a limits file. It gives the limit set when the\n * data has the shape of one and `checkLimits` finds no problem. If not, it gives each problem.\n */\nexport const readLimits: (data: unknown) => Result<LimitSet, readonly LimitProblem[]> = reader(limitsSchema, checkLimits);\n\nconst scaleSchema = z.enum([\"linear\", \"log\"]);\nconst rangeFields = { unit: z.string(), min: z.number(), max: z.number(), scale: scaleSchema };\nconst commandFields = { argv: z.array(z.string()), cwd: z.string(), env: z.record(z.string(), z.string()) };\nconst commandSchema = z.strictObject(commandFields);\nconst processSchema = z.strictObject({\n ...commandFields,\n ready: z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"line\"), text: z.string() }),\n z.strictObject({ kind: z.literal(\"http\"), path: z.string() }),\n ]),\n});\n\n/**\n * This schema accepts the shape of the contract file of an app: each field with its type, and no other\n * field. It does not examine what the fields mean. The function `checkApp` does that.\n */\nexport const appSchema: z.ZodType<AppContract> = z.strictObject({\n format: z.literal(APP_FORMAT),\n id: z.string(),\n title: z.string(),\n repository: z.string(),\n variables: z.array(z.strictObject({ id: z.string(), title: z.string(), kind: z.enum([\"request\", \"level\", \"store\", \"run\"]), ...rangeFields })),\n classes: z.array(\n z.strictObject({\n id: z.string(),\n title: z.string(),\n rate: z.strictObject(rangeFields),\n request: z.array(z.string()),\n entry: z.discriminatedUnion(\"kind\", [\n z.strictObject({\n kind: z.literal(\"http\"),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n path: z.string(),\n body: z.string().optional(),\n }),\n z.strictObject({ kind: z.literal(\"service\"), service: z.string() }),\n ]),\n }),\n ),\n start: z.strictObject({\n install: commandSchema.optional(),\n check: commandSchema.optional(),\n seed: commandSchema.optional(),\n run: processSchema.extend({\n lines: z.array(z.strictObject({ kind: z.enum(APP_LINE_KINDS), ev: z.string(), title: z.string() })).optional(),\n }),\n }),\n services: z.array(z.strictObject({ id: z.string(), title: z.string(), fake: processSchema })),\n metrics: z.array(\n z.strictObject({\n id: z.string(),\n kind: z.enum([\"counter\", \"gauge\"]),\n unit: z.string(),\n of: z.union([\n z.strictObject({ rate: z.string() }),\n z.strictObject({ level: z.string() }),\n z.strictObject({ total: z.string(), class: z.string() }),\n z.strictObject({ measure: z.string() }),\n ]),\n }),\n ),\n});\n\n/**\n * This function reads the contract of an app from the data of a contract file. It gives the contract when\n * the data has the shape of one and `checkApp` finds no problem. If not, it gives each problem.\n */\nexport const readApp: (data: unknown) => Result<AppContract, readonly AppProblem[]> = reader(appSchema, checkApp);\n"],"mappings":";;;;;;AAuBA,MAAM,aAAa,UAA4B;CAC7C,MAAM,OAAO,KAAK,UAAU,KAAK;CACjC,OAAO,SAAS,KAAA,KAAa,MAAM,MAAM,WAAW,CAAC,CAAC;AACxD;;;;;AAMA,MAAM,UACqB,QAAsB,WAC9C,SAAiE;CAChE,MAAM,QAAQ,OAAO,UAAU,IAAI;CACnC,IAAI,CAAC,MAAM,SACT,OAAO,IAAI,MAAM,MAAM,OAAO,KAAK,WAAW;EAAE,MAAM;EAAS,MAAM,MAAM,KAAK,KAAK,GAAG;EAAG,SAAS,MAAM;CAAQ,EAAE,CAAC;CAEvH,MAAM,WAAW,MAAM,MAAM,IAAI;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AAO,EAAE,OAAO,EAAE,CAAC;GACpC,EAAE,aAAa;IAAE,OAAO,EAAE,OAAO;IAAG,OAAO,EAAE,OAAO;GAAE,CAAC;GACvD,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;EACxC,CAAC;CACH,CAAC,CACH;AACF,CAAC;;;;;AAMD,MAAa,UAAyE,OAAO,WAAW,QAAQ"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../src/schema.ts"],"sourcesContent":["import { err, ok, type Result } from \"@mark1russell7/optional\";\nimport { parse, type Expr } from \"@mark1russell7/vex\";\nimport { z } from \"zod\";\nimport { checkApp } from \"./app-check.ts\";\nimport { APP_FORMAT, APP_LINE_KINDS, type AppContract, type AppProblem } from \"./app.ts\";\nimport { checkLaw } from \"./check.ts\";\nimport { COMPOSITION_FORMAT, checkComposition, type Composition, type CompositionProblem } from \"./composition.ts\";\nimport { checkInstance, checkLimits } from \"./instance-check.ts\";\nimport {\n INSTANCE_FORMAT,\n LIMITS_FORMAT,\n type InstanceProblem,\n type InstanceType,\n type Limit,\n type LimitProblem,\n type LimitSet,\n} from \"./instance.ts\";\nimport { LAW_FORMAT, type Law, type LawProblem, type Problem } from \"./law.ts\";\nimport { LAW_DOMAINS } from \"./program.ts\";\nimport { checkWorkload } from \"./workload-check.ts\";\nimport { WORKLOAD_FORMAT, type Workload, type WorkloadProblem } from \"./workload.ts\";\n\n/** This function tells if a value from JSON is a Vex expression. */\nconst isProgram = (value: unknown): boolean => {\n const text = JSON.stringify(value);\n return text !== undefined && parse(text, LAW_DOMAINS).ok;\n};\n\n/**\n * This function makes the reader of a record. The reader examines the shape of the data with the\n * schema, then it examines the meaning with `check`. It gives the record, or each problem.\n */\nconst reader =\n <T, Code extends string>(schema: z.ZodType<T>, check: (record: T) => readonly Problem<Code>[]) =>\n (data: unknown): Result<T, readonly Problem<Code | \"shape\">[]> => {\n const shape = schema.safeParse(data);\n if (!shape.success) {\n return err(shape.error.issues.map((issue) => ({ code: \"shape\", path: issue.path.join(\".\"), message: issue.message })));\n }\n const problems = check(shape.data);\n return problems.length > 0 ? err(problems) : ok(shape.data);\n };\n\nconst fitErrorSchema = z.strictObject({ mae: z.number(), rmse: z.number() });\n\nconst runSchema = z.strictObject({ url: z.string(), commit: z.string(), date: z.string() });\n\n/**\n * This schema accepts the shape of a law file: each field with its type, and no other field. It\n * does not examine what the fields mean. The function `checkLaw` does that.\n */\nexport const lawSchema: z.ZodType<Law> = z.strictObject({\n format: z.literal(LAW_FORMAT),\n id: z.string(),\n title: z.string(),\n subject: z.string(),\n measure: z.strictObject({ id: z.string(), unit: z.string() }),\n variables: z.array(\n z.strictObject({ id: z.string(), unit: z.string(), min: z.number(), max: z.number(), scale: z.enum([\"linear\", \"log\"]) }),\n ),\n conditions: z.record(\n z.string(),\n z.union([z.string(), z.number(), z.boolean(), z.strictObject({ value: z.number(), unit: z.string() })]),\n ),\n form: z.strictObject({ id: z.string(), program: z.custom<Expr>(isProgram, \"The program is not a Vex expression.\") }),\n constants: z.array(z.strictObject({ id: z.string(), value: z.number() })),\n replicates: z.array(z.array(z.number())),\n fit: z.strictObject({\n method: z.string(),\n residual: z.enum([\"absolute\", \"relative\"]),\n residuals: z.array(z.number()),\n losers: z.array(z.strictObject({ form: z.string(), error: fitErrorSchema })),\n }),\n points: z.array(z.strictObject({ load: z.record(z.string(), z.number()), value: z.number(), run: z.number(), job: z.string() })).exactOptional(),\n evidence: z.strictObject({ runs: z.array(runSchema) }),\n noise: z.strictObject({ floor: z.number(), cpu: z.string(), runs: z.array(runSchema) }),\n idle: z\n .strictObject({ load: z.string(), cpu: z.string(), bases: z.number(), runs: z.number(), measures: z.record(z.string(), z.strictObject({ value: z.number(), unit: z.string() })) })\n .exactOptional(),\n});\n\n/**\n * This function reads a law from the data of a law file. It gives the law when the data has the\n * shape of a law and `checkLaw` finds no problem. If not, it gives each problem.\n */\nexport const readLaw: (data: unknown) => Result<Law, readonly LawProblem[]> = reader(lawSchema, checkLaw);\n\nconst factorSchema = z.number().optional();\n\n/**\n * This schema accepts the shape of a composition file: each field with its type, and no other\n * field. It does not examine what the fields mean. The function `checkComposition` does that.\n */\nexport const compositionSchema: z.ZodType<Composition> = z.strictObject({\n format: z.literal(COMPOSITION_FORMAT),\n id: z.string(),\n title: z.string(),\n subject: z.string(),\n measure: z.strictObject({ id: z.string(), unit: z.string() }),\n terms: z.array(\n z.union([\n z.strictObject({\n law: z.string(),\n over: z.union([z.literal(\"instance\"), z.literal(\"each\"), z.array(z.string())]),\n load: z.enum([\"class\", \"total\"]).optional(),\n factor: factorSchema,\n base: z.lazy(() => amountsSchema).optional(),\n }),\n z.strictObject({ composition: z.string(), factor: factorSchema }),\n ]),\n ),\n});\n\n/**\n * This function reads a composition from the data of a composition file. It gives the composition\n * when the data has the shape of one and `checkComposition` finds no problem. If not, it gives each\n * problem.\n */\nexport const readComposition: (data: unknown) => Result<Composition, readonly CompositionProblem[]> = reader(\n compositionSchema,\n checkComposition,\n);\n\nconst amountSchema = z.strictObject({ value: z.number(), unit: z.string() });\nconst amountsSchema = z.record(z.string(), amountSchema);\n\n/**\n * This schema accepts the shape of a workload file: each field with its type, and no other field.\n * It does not examine what the fields mean. The function `checkWorkload` does that.\n */\nexport const workloadSchema: z.ZodType<Workload> = z.strictObject({\n format: z.literal(WORKLOAD_FORMAT),\n id: z.string(),\n title: z.string(),\n classes: z.array(z.strictObject({ id: z.string(), of: z.string().optional(), rate: amountSchema, request: amountsSchema })),\n levels: amountsSchema,\n source: z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"plan\"), note: z.string() }),\n z.strictObject({ kind: z.literal(\"metrics\"), origin: z.string(), from: z.string(), to: z.string() }),\n ]),\n});\n\n/**\n * This function reads a workload from the data of a workload file. It gives the workload when the\n * data has the shape of a workload and `checkWorkload` finds no problem. If not, it gives each\n * problem.\n */\nexport const readWorkload: (data: unknown) => Result<Workload, readonly WorkloadProblem[]> = reader(workloadSchema, checkWorkload);\n\n/**\n * This schema accepts the shape of an instance file: each field with its type, and no other field.\n * It does not examine what the fields mean. The function `checkInstance` does that.\n */\nexport const instanceSchema: z.ZodType<InstanceType> = z.strictObject({\n format: z.literal(INSTANCE_FORMAT),\n id: z.string(),\n title: z.string(),\n resources: amountsSchema,\n});\n\n/**\n * This function reads an instance type from the data of an instance file. It gives the instance\n * type when the data has the shape of one and `checkInstance` finds no problem. If not, it gives\n * each problem.\n */\nexport const readInstance: (data: unknown) => Result<InstanceType, readonly InstanceProblem[]> = reader(instanceSchema, checkInstance);\n\n/** This schema accepts the shape of one limit: each field with its type, and no other field. */\nexport const limitSchema: z.ZodType<Limit> = z.strictObject({\n id: z.string(),\n measure: z.string(),\n ceiling: z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"amount\"), amount: amountSchema }),\n z.strictObject({ kind: z.literal(\"resource\"), resource: z.string() }),\n ]),\n headroom: z.number(),\n});\n\n/**\n * This schema accepts the shape of a limits file: each field with its type, and no other field.\n * It does not examine what the fields mean. The function `checkLimits` does that.\n */\nexport const limitsSchema: z.ZodType<LimitSet> = z.strictObject({\n format: z.literal(LIMITS_FORMAT),\n id: z.string(),\n title: z.string(),\n limits: z.array(limitSchema),\n});\n\n/**\n * This function reads a limit set from the data of a limits file. It gives the limit set when the\n * data has the shape of one and `checkLimits` finds no problem. If not, it gives each problem.\n */\nexport const readLimits: (data: unknown) => Result<LimitSet, readonly LimitProblem[]> = reader(limitsSchema, checkLimits);\n\nconst scaleSchema = z.enum([\"linear\", \"log\"]);\nconst rangeFields = { unit: z.string(), min: z.number(), max: z.number(), scale: scaleSchema };\nconst commandFields = { argv: z.array(z.string()), cwd: z.string(), env: z.record(z.string(), z.string()) };\nconst commandSchema = z.strictObject(commandFields);\nconst processSchema = z.strictObject({\n ...commandFields,\n ready: z.discriminatedUnion(\"kind\", [\n z.strictObject({ kind: z.literal(\"line\"), text: z.string() }),\n z.strictObject({ kind: z.literal(\"http\"), path: z.string() }),\n ]),\n});\n\n/**\n * This schema accepts the shape of the contract file of an app: each field with its type, and no other\n * field. It does not examine what the fields mean. The function `checkApp` does that.\n */\nexport const appSchema: z.ZodType<AppContract> = z.strictObject({\n format: z.literal(APP_FORMAT),\n id: z.string(),\n title: z.string(),\n repository: z.string(),\n variables: z.array(z.strictObject({ id: z.string(), title: z.string(), kind: z.enum([\"request\", \"level\", \"store\", \"run\"]), ...rangeFields })),\n classes: z.array(\n z.strictObject({\n id: z.string(),\n title: z.string(),\n rate: z.strictObject(rangeFields),\n request: z.array(z.string()),\n entry: z.discriminatedUnion(\"kind\", [\n z.strictObject({\n kind: z.literal(\"http\"),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n path: z.string(),\n body: z.string().optional(),\n }),\n z.strictObject({ kind: z.literal(\"service\"), service: z.string() }),\n ]),\n }),\n ),\n start: z.strictObject({\n install: commandSchema.optional(),\n check: commandSchema.optional(),\n seed: commandSchema.optional(),\n run: processSchema.extend({\n lines: z.array(z.strictObject({ kind: z.enum(APP_LINE_KINDS), ev: z.string(), title: z.string() })).optional(),\n }),\n }),\n services: z.array(z.strictObject({ id: z.string(), title: z.string(), fake: processSchema })),\n metrics: z.array(\n z.strictObject({\n id: z.string(),\n kind: z.enum([\"counter\", \"gauge\"]),\n unit: z.string(),\n of: z.union([\n z.strictObject({ rate: z.string() }),\n z.strictObject({ level: z.string() }),\n z.strictObject({ total: z.string(), class: z.string() }),\n z.strictObject({ measure: z.string() }),\n ]),\n }),\n ),\n});\n\n/**\n * This function reads the contract of an app from the data of a contract file. It gives the contract when\n * the data has the shape of one and `checkApp` finds no problem. If not, it gives each problem.\n */\nexport const readApp: (data: unknown) => Result<AppContract, readonly AppProblem[]> = reader(appSchema, checkApp);\n"],"mappings":";;;;;;AAuBA,MAAM,aAAa,UAA4B;CAC7C,MAAM,OAAO,KAAK,UAAU,KAAK;CACjC,OAAO,SAAS,KAAA,KAAa,MAAM,MAAM,WAAW,CAAC,CAAC;AACxD;;;;;A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B,KAAK,cAAc,OAAO,EACxB,OAAO,EAAE,MAAM,EAAE,aAAa;GAAE,MAAM,EAAE,KAAK,cAAc;GAAG,IAAI,EAAE,OAAO;GAAG,OAAO,EAAE,OAAO;EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,EAC/G,CAAC;CACH,CAAC;CACD,UAAU,EAAE,MAAM,EAAE,aAAa;EAAE,IAAI,EAAE,OAAO;EAAG,OAAO,EAAE,OAAO;EAAG,MAAM;CAAc,CAAC,CAAC;CAC5F,SAAS,EAAE,MACT,EAAE,aAAa;EACb,IAAI,EAAE,OAAO;EACb,MAAM,EAAE,KAAK,CAAC,WAAW,OAAO,CAAC;EACjC,MAAM,EAAE,OAAO;EACf,IAAI,EAAE,MAAM;GACV,EAAE,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;GACnC,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;GACpC,EAAE,aAAa;IAAE,OAAO,EAAE,OAAO;IAAG,OAAO,EAAE,OAAO;GAAE,CAAC;GACvD,EAAE,aAAa,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC;EACxC,CAAC;CACH,CAAC,CACH;AACF,CAAC;;;;;AAMD,MAAa,UAAyE,OAAO,WAAW,QAAQ"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/capacity",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "Performance and capacity models: the cost of one request as laws over each load variable, with intervals.",
6
6
  "keywords": [
7
7
  "performance",
package/src/check.ts CHANGED
@@ -224,5 +224,30 @@ export const checkLaw = (law: Law): readonly LawProblem[] => {
224
224
  if (law.noise.cpu.trim() === "") add("noise", "noise.cpu", "The noise names no CPU model.");
225
225
  runs("noise", "noise.runs", law.noise.runs);
226
226
 
227
+ // The idle base: a law net of its idle base keeps it, and a law of gross values has none.
228
+ const net = law.conditions["idle"] === "net";
229
+ const { idle } = law;
230
+ if (idle === undefined) {
231
+ if (net) add("idle", "idle", 'The law has the condition idle "net", thus it must keep its idle base.');
232
+ } else {
233
+ if (!net) add("idle", "idle", 'The law has an idle base, thus it must have the condition idle "net".');
234
+ if (idle.load.trim() === "") add("idle", "idle.load", "The idle base names no load.");
235
+ if (idle.cpu.trim() === "") add("idle", "idle.cpu", "The idle base names no CPU model.");
236
+ const whole = (path: "bases" | "runs", value: number): void => {
237
+ if (!Number.isInteger(value) || value < 1) add("idle", `idle.${path}`, `The count of ${path} is ${value}, not a whole number of 1 or more.`);
238
+ };
239
+ whole("bases", idle.bases);
240
+ whole("runs", idle.runs);
241
+ if (Number.isInteger(idle.bases) && Number.isInteger(idle.runs) && idle.runs < idle.bases) {
242
+ add("idle", "idle.runs", `The idle base has ${idle.runs} runs and ${idle.bases} bases. Each base has 1 run or more.`);
243
+ }
244
+ const measures = Object.entries(idle.measures);
245
+ if (measures.length === 0) add("idle", "idle.measures", "The idle base has no measure.");
246
+ for (const [name, amount] of measures) {
247
+ slug(`idle.measures.${name}`, name);
248
+ if (!isQuantity(amount)) add("idle", `idle.measures.${name}`, `The idle measure "${name}" is not a finite amount in a canonical unit.`);
249
+ }
250
+ }
251
+
227
252
  return problems;
228
253
  };
package/src/gate.ts CHANGED
@@ -235,3 +235,34 @@ export const lawGate = (cases: readonly GateCase[], options: LawGateOptions = {}
235
235
  });
236
236
  return { ...gateOf(outcomes), level, alpha, need, share, cases: outcomes };
237
237
  };
238
+
239
+ /** This count is the most reads in one job that `gateReadsFor` examines. */
240
+ const MAX_GATE_READS = 64;
241
+
242
+ /**
243
+ * This function gives the least count of reads in each job with which `lawGate` can decide a case. Let each job have r
244
+ * reads, each on one side. The count is the least r for which `jobs` jobs give a p of `alpha / (2 × laws)` or less. This
245
+ * bound is the first step of Holm when each of `laws` laws is a case of the gate.
246
+ *
247
+ * A job with fewer reads cannot reject a side, also when each of its reads is on that side. Thus a plan of a gate must
248
+ * give each job this count of points that each law reads. More jobs do not correct too few reads in each job.
249
+ *
250
+ * The function throws a `RangeError` in three cases. The first is `jobs` or `laws` that is not a whole number above 0.
251
+ * The second is `jobs` below the count of jobs of a side. The third is no count up to 64 reads that can decide.
252
+ */
253
+ export const gateReadsFor = (jobs: number, laws: number, options: LawGateOptions = {}): number => {
254
+ const level = options.level ?? DEFAULT_LEVEL;
255
+ const alpha = options.alpha ?? GATE_ALPHA;
256
+ const need = options.jobs ?? GATE_JOBS;
257
+ if (!(level > 0 && level < 1)) throw new RangeError(`The level ${level} is not between 0 and 1.`);
258
+ if (!(alpha > 0 && alpha < 1)) throw new RangeError(`The alpha ${alpha} is not between 0 and 1.`);
259
+ if (!Number.isInteger(need) || need < 1) throw new RangeError(`The count of jobs ${need} is not a whole number above 0.`);
260
+ if (!Number.isInteger(laws) || laws < 1) throw new RangeError(`The count of laws ${laws} is not a whole number above 0.`);
261
+ if (!Number.isInteger(jobs) || jobs < need) throw new RangeError(`The count of jobs ${jobs} is not a whole number of ${need} or more.`);
262
+ const share = (1 - level) / 2;
263
+ for (let reads = 1; reads <= MAX_GATE_READS; reads += 1) {
264
+ const best = partialConjunction(Array.from({ length: jobs }, () => binomialTest(reads, reads, share, "greater")), need);
265
+ if (best <= alpha / (2 * laws)) return reads;
266
+ }
267
+ throw new RangeError(`At ${jobs} jobs and ${laws} laws, ${MAX_GATE_READS} reads in each job cannot decide a case.`);
268
+ };
package/src/index.ts CHANGED
@@ -23,6 +23,7 @@ export type {
23
23
  FitError,
24
24
  Form,
25
25
  Law,
26
+ LawIdle,
26
27
  LawProblem,
27
28
  Loser,
28
29
  Measure,
@@ -60,7 +61,7 @@ export { constantIntervals, lawValue } from "./value.ts";
60
61
  export type { Crossing, Floor, Knee, KneeOptions, KneeRule, OpenRange, OpenValue, Reach } from "./knee.ts";
61
62
  export { KNEE_STEPS, kneeRuleProblem, lawKnee, lawReach } from "./knee.ts";
62
63
  export type { GateCase, GateJob, GateRead, JobCount, LawGate, LawGateCase, LawGateOptions, LawRead, NoReadJob, ReadSide, SideTest } from "./gate.ts";
63
- export { GATE_ALPHA, GATE_JOBS, lawGate, lawRead } from "./gate.ts";
64
+ export { GATE_ALPHA, GATE_JOBS, gateReadsFor, lawGate, lawRead } from "./gate.ts";
64
65
  export type {
65
66
  Amounts,
66
67
  Demand,
package/src/law.ts CHANGED
@@ -122,6 +122,23 @@ export interface Noise {
122
122
  readonly runs: readonly Run[];
123
123
  }
124
124
 
125
+ /**
126
+ * 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
127
+ * some idle bases of its subject. A gate run with no idle case reads the points of the law net of this base.
128
+ */
129
+ export interface LawIdle {
130
+ /** This text is the load of the bases: the canonical JSON of their instance and their connections. */
131
+ readonly load: string;
132
+ /** This name is the CPU model of the law, as its condition `cpu.model`. */
133
+ readonly cpu: string;
134
+ /** This count is the idle bases in the median. */
135
+ readonly bases: number;
136
+ /** This count is the runs of those bases. */
137
+ readonly runs: number;
138
+ /** These amounts are the median of each idle measure, by its name. */
139
+ readonly measures: Readonly<Record<string, Quantity>>;
140
+ }
141
+
125
142
  /**
126
143
  * A law gives one measure of a subject as a function of its load variables. It holds for the
127
144
  * ranges of its variables and for its conditions.
@@ -132,6 +149,8 @@ export interface Noise {
132
149
  *
133
150
  * The list `points` keeps each point that the fit used, in the order of `fit.residuals`. A law file from before the
134
151
  * points has no list.
152
+ *
153
+ * 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.
135
154
  */
136
155
  export interface Law {
137
156
  readonly format: typeof LAW_FORMAT;
@@ -148,6 +167,7 @@ export interface Law {
148
167
  readonly points?: readonly RunPoint[];
149
168
  readonly evidence: Evidence;
150
169
  readonly noise: Noise;
170
+ readonly idle?: LawIdle;
151
171
  }
152
172
 
153
173
  /** A problem code names the part of a law, or of a query, that is not correct. */
@@ -168,6 +188,7 @@ export type ProblemCode =
168
188
  | "fit"
169
189
  | "evidence"
170
190
  | "noise"
191
+ | "idle"
171
192
  | "point"
172
193
  | "level"
173
194
  | "knee";
package/src/schema.ts CHANGED
@@ -74,6 +74,9 @@ export const lawSchema: z.ZodType<Law> = z.strictObject({
74
74
  points: z.array(z.strictObject({ load: z.record(z.string(), z.number()), value: z.number(), run: z.number(), job: z.string() })).exactOptional(),
75
75
  evidence: z.strictObject({ runs: z.array(runSchema) }),
76
76
  noise: z.strictObject({ floor: z.number(), cpu: z.string(), runs: z.array(runSchema) }),
77
+ idle: z
78
+ .strictObject({ load: z.string(), cpu: z.string(), bases: z.number(), runs: z.number(), measures: z.record(z.string(), z.strictObject({ value: z.number(), unit: z.string() })) })
79
+ .exactOptional(),
77
80
  });
78
81
 
79
82
  /**
@@ -1 +0,0 @@
1
- {"version":3,"file":"instance-0n6WhJzF.d.ts","names":[],"sources":["../src/law.ts","../src/value.ts","../src/workload.ts","../src/app.ts","../src/demand.ts","../src/composition.ts","../src/instance.ts"],"mappings":";;;;cAIa;;cAGA;;KAGD;;;;;;;;UASK;WACN;WACA;;;;;;UAOM;WACN;WACA;WACA;WACA;WACA,OAAO;;;UAID;WACN;WACA;;;;;;UAOM;WACN;WACA,SAAS;;;KAIR,6CAA6C;;;;;KAM7C;;UAGK;WACN;WACA;;;UAIM;WACN;WACA,OAAO;;;;;;UAOD;WACN;WACA,UAAU;WACV;WACA,iBAAiB;;;UAIX;WACN;WACA;WACA;;;;;;UAOM;WACN,MAAM,SAAS;WACf;;WAEA;;WAEA;;;UAIM;WACN,eAAe;;;;;;UAOT;;;;;WAKN;;WAEA;;WAEA,eAAe;;;;;;;;;;;;;UAcT;WACN,eAAe;WACf;WACA;WACA;WACA,SAAS;WACT,oBAAoB;WACpB,YAAY,SAAS,eAAe;WACpC,MAAM;WACN,oBAAoB;WACpB;WACA,KAAK;WACL,kBAAkB;WAClB,UAAU;WACV,OAAO;;;KAIN;;UAsBK,QAAQ;WACd,MAAM;WACN;WACA;;;KAIC,aAAa,QAAQ;;cAGpB;;;;;cAMA,aAAc;;;;;cAMd,iBAAkB;;;;;;;cAYlB,cA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