check.ts
This file
Path
packages/sdk/src/check.ts
81 lines · 2.9 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 1–8why, one step back1import {2 CheckSpec,3 RatchetMeasure as Measure,4} from "@repo/protocol/domain/check";5import { Schema, Struct } from "effect";67type CheckSpecEncoded = typeof CheckSpec.Encoded;8Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 9why, one step back9/** `CheckSpecInput<"RedThenGreen">` narrows it to one check kind. */Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 10–36why, one step back10export type CheckSpecInput<11 Tag extends CheckSpecEncoded["_tag"] = CheckSpecEncoded["_tag"],12> = Extract<CheckSpecEncoded, { readonly _tag: Tag }>;1314export type RatchetMeasure = typeof Measure.Encoded;1516const { LintToZero, Migrate, Ratchet, RedThenGreen } = CheckSpec.cases;1718const { Count, Metric } = Measure.cases;1920const lintToZeroFields = Schema.Struct(21 Struct.omit(LintToZero.fields, ["_tag"])22);2324const migrateFields = Schema.Struct(Struct.omit(Migrate.fields, ["_tag"]));2526const ratchetFields = Schema.Struct(Struct.omit(Ratchet.fields, ["_tag"]));2728const redThenGreenFields = Schema.Struct(29 Struct.omit(RedThenGreen.fields, ["_tag"])30);3132const countFields = Schema.Struct(Struct.omit(Count.fields, ["_tag"]));3334const metricFields = Schema.Struct(Struct.omit(Metric.fields, ["_tag"]));3536export const check = {Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 37why, one step back37 /** A lint rule's count goes to zero: red while `command` (the project's lint, as JSON) reports `rule` on main. */Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 38–41why, one step back38 lintToZero: (rule: string, command: string): CheckSpecInput<"LintToZero"> =>39 Schema.encodeSync(LintToZero)(40 LintToZero.make(Schema.decodeSync(lintToZeroFields)({ command, rule }))41 ),Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 42why, one step back42 /** Every use of `from` moves to `to`; `count` prints `{"total": n, "byModule": {...}}`. */Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 43–52why, one step back43 migrate: (spec: {44 readonly count: string;45 readonly from: string;46 readonly to?: string;47 }): CheckSpecInput<"Migrate"> =>48 Schema.encodeSync(Migrate)(49 Migrate.make(Schema.decodeSync(migrateFields)(spec))50 ),51 /** Ratchets: a counted budget per territory that answers may lower and never raise. */52 ratchet: {Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 53why, one step back53 /** Counts findings in the project's own lint JSON output (oxlint or ESLint), for one rule or all. */Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 54–75why, one step back54 count: (55 command: string,56 options?: { readonly rule?: string }57 ): RatchetMeasure =>58 Schema.encodeSync(Count)(59 Count.make(Schema.decodeSync(countFields)({ command, ...options }))60 ),61 down: (ratchet: string): CheckSpecInput<"Ratchet"> =>62 Schema.encodeSync(Ratchet)(63 Ratchet.make(Schema.decodeSync(ratchetFields)({ ratchet }))64 ),65 /** Reads one number at `path` (a JSON pointer: `/total`) in the command's JSON output. */66 metric: (67 command: string,68 options: { readonly path: string }69 ): RatchetMeasure =>70 Schema.encodeSync(Metric)(71 Metric.make(72 Schema.decodeSync(metricFields)({ command, path: options.path })73 )74 ),75 },Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 76why, one step back76 /** One check file fails on main by an assertion and passes on the answer; `test` runs it with `path` for `{path}`. */Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8
lines 77–81why, one step back77 redThenGreen: (path: string): CheckSpecInput<"RedThenGreen"> =>78 Schema.encodeSync(RedThenGreen)(79 RedThenGreen.make(Schema.decodeSync(redThenGreenFields)({ path }))80 ),81};