Skip to content

feat: add the storage adapter, record types, and legacy-name ratchet - #103

Merged
keyurgolani merged 11 commits into
nextfrom
feat/01.1-adapter
Oct 20, 2026
Merged

keyurgolani merged 11 commits into
nextfrom
feat/01.1-adapter

Conversation

@keyurgolani

@keyurgolani keyurgolani commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Implements CHECKMATE-01.1 · adapter
Closes #29

What changed

  • src/lib/domain/storage.ts maps each canonical name to what PocketBase holds: the nine collections (templates is blueprints, templateSteps is items, runs is instances, runSteps is instanceItems), the blueprint, instance and sourceItem relation fields, the notification types (template_updated is blueprint_updated, run_reminder is instance_reminder) and the activity resource types. Where only some install variants have a name, its entry says where it's present, spelled like the 01.3 map's presentIn (pb_schema, setup-pocketbase, create-collections, schema-init, code-only). STORAGE_NAMES lists every mapped name with its map ID, which the 01.3 map ([CHECKMATE-01.3] Create the breaking migration map and transformation dependency graph #31) checks in its test 5.

  • Collections in pocketbase-types.ts is now the adapter's object, with every value unchanged. It gains TEMPLATE_STEPS, RUNS and RUN_STEPS. ITEMS, CHECKLISTS and CHECKLIST_ITEMS stay, deprecated, for the services that use them.

  • src/lib/domain/records.ts has TemplateRecord, TemplateStepRecord, RunRecord, RunStepRecord, NotificationRecord and ActivityEntryRecord, read and written with fromStorage and toStorage. None extends RecordModel or has an index signature. An unknown select value reads as unknown, and toStorage refuses to write it back. A field set to undefined counts as absent.

  • The ratchet parses every non-test file under src/, .d.ts files included, and counts:

    1. a legacy storage name as a whole literal or template chunk, or in a collection URL;
    2. blueprint, instance and sourceItem as a property read, object key, shorthand, destructured name or type member;
    3. a legacy name on either side of a filter comparison, in a back-relation or before a modifier, and in expand, sort and fields lists;
    4. an import or re-export of one of the 19 deprecated aliases, however it's written;
    5. a use of Collections.ITEMS, CHECKLISTS or CHECKLIST_ITEMS, or of a NotificationType or ResourceType member named for a retired word.

    Comments don't count and src/lib/domain/ is allowlisted. legacy-name-baseline.ts holds the merge-time count, 229 uses in 39 files.

  • scripts/ci/check-shrinking-lists.mjs keeps that baseline from growing. It reads each list with the TypeScript parser and fails on anything it can't read exactly. A file git sees moved keeps its count under the new path, and a list with entries can't be renamed past the check or deleted.

  • The unit job runs the type test, npx tsc --noEmit -p src/lib/domain/tsconfig.json. CONTRIBUTING.md says how to lower the baseline.

No service is rewired. 04.1 revision storage (#38), 05.2 built-in steps (#42) and 07.1 run creation (#47) read through these first.

Why

Services, routes and pages name blueprints, instances, instanceItems and their fields directly, in filter strings, object keys and property reads. 04.1, 05.2 and 07.1 need one adapter to build on, and new code shouldn't add uses in the meantime.

Verification

Against origin/next at 113a544, the merge of 01.2 envelope (#102):

  • eslint on the 16 changed source files (scripts/ci/lint-changed.mjs): 0 errors, 0 warnings, no eslint-disable.
  • npm run lint: 38 errors, 48 warnings, same as origin/next.
  • npx tsc --noEmit: 0 errors, same as origin/next.
  • npx tsc --noEmit -p src/lib/domain/tsconfig.json: 0 errors.
  • npm test on the fixture: 777 tests in 42 files pass, none skipped, 112 of them new.
  • npm run build with PocketBase at http://127.0.0.1:9: passes.
  • On a scratch branch, the shrink check passed a baselined file moved with its count, and failed the same move with the count raised, the baseline renamed with a count raised, and the baseline deleted.

Failing first: with the record types aliased to today's RecordModel-based types, the type test fails with 38 errors, 13 of them @ts-expect-error lines whose wrong read compiled. Against a scanner that finds nothing, 16 of the 19 ratchet self-test cases fail.

Decisions

  1. The permanent entries follow 16.1 ([CHECKMATE-16.1] Publish canonical versioned package, workflow, and proof schemas #74), 16.2 ([CHECKMATE-16.2] Add deterministic export, dry-run import, and migration reports #75) and 16.3 ([CHECKMATE-16.3] Add UI and YAML or JSON blueprints over one schema #76), not test plan item 8's list. One is the v1 export reader, which is import-parsers.ts today and, once 16.2 deletes that file, the one module under src/lib/portable/ that declares export function readLegacyExport. A second claimant fails the test. The other is 16.3's file form in src/lib/portable/blueprint/, with a self-test case for its 'blueprint' literal. 16.3's routes import the file-form constant from there instead of writing the word.
  2. The adapter renames the four collections, the three fields and the six stored values built on Blueprint, Instance and Item. collaborators and activityLog keep their names because 03.1 turns collaborators into grants and 12.2 drops the log. instanceCount, itemType, questions and isCompleted keep theirs for the leaves that drop or map them, so 01.3's map can give each one a single class.
  3. The three install variants disagree. access_request, the phase item type and instanceItems.itemType exist only in pb_schema.json, and no variant declares instances.workspace, which the app writes. A record field is optional exactly when some variant lacks it, and the tests read all three sources to check where each one is present.
  4. Test plan item 8 names .blueprint and .instance reads. The ratchet counts .sourceItem too, plus the keys, members and deprecated names above. Within a string it counts only query syntax and collection URLs, so copy like "Pick a blueprint" doesn't count.
  5. 'item' also matches the type: 'item' realtime event names in realtime.ts. They use the retired word, so they're in the baseline.

No owner steps.

storage.ts maps canonical names to the stored collections, the renamed
relation fields, notification types and activity resource types, and
records which install variant has each. Collections in
pocketbase-types.ts is now the adapter's object, with every value
unchanged.
TemplateRecord, TemplateStepRecord, RunRecord, RunStepRecord,
NotificationRecord and ActivityEntryRecord read and write through the
adapter. None extends RecordModel or has an index signature, unknown
select values read as unknown and never write back, and fields only
some install variants have are optional.
A TypeScript parser scan of non-test files under src/ counts legacy
storage names as whole literals, relation fields read as properties,
legacy names in filter, expand and sort strings, and imports of the 19
deprecated aliases. src/lib/domain/ is allowlisted, the v1 export
reader and the 16.3 file form are permanent entries, and the per-file
baseline may only shrink against the merge base.
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Sorry @keyurgolani, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 6 days and 15 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR establishes the storage boundary without rewiring services: canonical domain names are mapped through a centralized adapter, six record types convert safely to and from PocketBase rows, and a syntax-aware per-file ratchet prevents new legacy storage-name usage while CI enforces the compile-time contract.

Sequence diagram for record conversion and safe storage writes

sequenceDiagram
    participant Service
    participant Records as records.ts
    participant Adapter as storage.ts
    participant PocketBase

    Service->>Records: fromStorage(kind, row)
    Records->>Adapter: storageField(collection, field)
    Adapter-->>Records: canonical field mapping
    Records-->>Service: typed canonical record
    Service->>Records: toStorage(kind, record)
    Records->>Adapter: canonicalValue(select, stored)
    Adapter-->>Records: storage value mapping
    alt known select value
        Records->>PocketBase: write mapped stored row
    else unknown select value
        Records-->>Service: throw RangeError
    end
Loading

Flow diagram for the legacy-name ratchet

flowchart TD
    Sources[Non-test files under src/] --> Scanner[Syntax-aware legacy-name scan]
    Scanner --> Counts[Per-file legacy usage counts]
    Counts --> Baseline[legacy-name-baseline.ts]
    Baseline --> Compare[Compare against merge baseline]
    Compare -->|count unchanged or lower| Pass[CI passes]
    Compare -->|new or increased usage| Fail[CI fails]
    Domain[src/lib/domain/] -->|allowlisted| Pass
    Types[Domain type test] --> CI[CI unit job]
    Pass --> CI
    Fail --> CI
Loading

File-Level Changes

Change Details Files
Introduces a centralized storage-name adapter covering collections, renamed relation fields, select values, install-variant differences, and deterministic migration map identifiers.
  • Maps canonical collection and field names to PocketBase storage names.
  • Defines notification, activity-resource, visibility, and item-type value mappings.
  • Tracks variant-specific fields and select values across all installer schemas.
  • Re-exports adapter-owned collection constants while retaining deprecated compatibility aliases.
src/lib/domain/storage.ts
src/lib/domain/storage.test.ts
src/lib/pocketbase-types.ts
Adds strongly typed record conversion APIs that isolate PocketBase rows from canonical domain records.
  • Defines six record interfaces without SDK inheritance or index signatures.
  • Converts renamed fields and select values in both directions.
  • Preserves optional fields based on install variants and rejects unknown values on writes.
  • Validates collection identity and required fields at runtime.
  • Adds unit, property-based, and compile-time contract coverage.
src/lib/domain/records.ts
src/lib/domain/records.test.ts
src/lib/domain/records.typetest.ts
src/lib/domain/tsconfig.json
Adds a per-file legacy-name ratchet to prevent new code from using retired storage terminology.
  • Scans non-test source syntax for legacy literals, property reads, query-string usage, and deprecated aliases.
  • Exempts the adapter and explicitly owned legacy portability code.
  • Pins the current 134-use baseline and validates exact per-file counts.
  • Adds scanner self-tests, exemption checks, and shrinking-list CI enforcement.
src/lib/domain/legacy-names.ts
src/lib/domain/legacy-name-baseline.ts
src/lib/domain/legacy-name-scan.test.ts
src/lib/domain/legacy-names.test.ts
src/test/legacy-name-scan.ts
scripts/ci/check-shrinking-lists.mjs
Integrates the domain type test and legacy-name policy into contributor guidance and CI classification.
  • Runs the isolated domain TypeScript contract test in the unit job.
  • Propagates the type-test failure class through CI.
  • Documents adapter usage and baseline-lowering workflow.
  • Updates CI scope metadata.
.github/workflows/ci.yml
.github/ci-scope.json
CONTRIBUTING.md
Adds install-variant schema parsing support for adapter validation.
  • Reads JSON schema and parses TypeScript installer definitions without executing them.
  • Normalizes built-in row fields and collection field definitions.
  • Provides variant fixtures used to verify adapter mappings and optionality.
src/test/install-variants.ts

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

…he map

toStorage and fromStorage skip an optional field set to undefined instead
of throwing on it. Install variants use #31's presentIn spelling, with
schema-init and code-only as sources, and each optional record field says
where it is declared. ROW_FIELDS has one copy, the autodate comment is
corrected, and a test ties vocabulary, retention and aggregates to
STORAGE_COLLECTIONS.
The ratchet now counts object keys, shorthand, destructured names and
type members named for a legacy field; both sides of filter comparisons,
back-relations and modifiers; whole template chunks and collection URLs;
alias re-exports, barrels, type aliases and dynamic or require imports,
in .d.ts files too; and uses of the deprecated Collections keys and
retired-word enum members. The readLegacyExport entry exempts only the
one module that declares that function. The baseline is 229 uses in 39
files.
The check reads each list with the TypeScript parser and fails on
anything it can't read exactly. A file git sees renamed keeps its count
under the new path, a renamed list is compared with its old copy, and a
list with entries can't be deleted or dropped from SHRINKING_LISTS.
@keyurgolani
keyurgolani merged commit 41a1943 into next Oct 20, 2026
10 checks passed
@keyurgolani
keyurgolani deleted the feat/01.1-adapter branch October 20, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant