Repository navigation
feat: add the storage adapter, record types, and legacy-name ratchet - #103
Merged
Merged
Conversation
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.
|
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 |
Reviewer's GuideThis 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 writessequenceDiagram
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
Flow diagram for the legacy-name ratchetflowchart 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
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements CHECKMATE-01.1 · adapter
Closes #29
What changed
src/lib/domain/storage.tsmaps each canonical name to what PocketBase holds: the nine collections (templatesisblueprints,templateStepsisitems,runsisinstances,runStepsisinstanceItems), theblueprint,instanceandsourceItemrelation fields, the notification types (template_updatedisblueprint_updated,run_reminderisinstance_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'spresentIn(pb_schema,setup-pocketbase,create-collections,schema-init,code-only).STORAGE_NAMESlists 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.Collectionsinpocketbase-types.tsis now the adapter's object, with every value unchanged. It gainsTEMPLATE_STEPS,RUNSandRUN_STEPS.ITEMS,CHECKLISTSandCHECKLIST_ITEMSstay, deprecated, for the services that use them.src/lib/domain/records.tshasTemplateRecord,TemplateStepRecord,RunRecord,RunStepRecord,NotificationRecordandActivityEntryRecord, read and written withfromStorageandtoStorage. None extendsRecordModelor has an index signature. An unknown select value reads asunknown, andtoStoragerefuses to write it back. A field set toundefinedcounts as absent.The ratchet parses every non-test file under
src/,.d.tsfiles included, and counts:blueprint,instanceandsourceItemas a property read, object key, shorthand, destructured name or type member;Collections.ITEMS,CHECKLISTSorCHECKLIST_ITEMS, or of aNotificationTypeorResourceTypemember named for a retired word.Comments don't count and
src/lib/domain/is allowlisted.legacy-name-baseline.tsholds the merge-time count, 229 uses in 39 files.scripts/ci/check-shrinking-lists.mjskeeps 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.mdsays 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,instanceItemsand 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/nextat 113a544, the merge of 01.2 envelope (#102):scripts/ci/lint-changed.mjs): 0 errors, 0 warnings, noeslint-disable.npm run lint: 38 errors, 48 warnings, same asorigin/next.npx tsc --noEmit: 0 errors, same asorigin/next.npx tsc --noEmit -p src/lib/domain/tsconfig.json: 0 errors.npm teston the fixture: 777 tests in 42 files pass, none skipped, 112 of them new.npm run buildwith PocketBase athttp://127.0.0.1:9: passes.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-errorlines whose wrong read compiled. Against a scanner that finds nothing, 16 of the 19 ratchet self-test cases fail.Decisions
import-parsers.tstoday and, once 16.2 deletes that file, the one module undersrc/lib/portable/that declaresexport function readLegacyExport. A second claimant fails the test. The other is 16.3's file form insrc/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.collaboratorsandactivityLogkeep their names because 03.1 turns collaborators into grants and 12.2 drops the log.instanceCount,itemType,questionsandisCompletedkeep theirs for the leaves that drop or map them, so 01.3's map can give each one a single class.access_request, thephaseitem type andinstanceItems.itemTypeexist only inpb_schema.json, and no variant declaresinstances.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..blueprintand.instancereads. The ratchet counts.sourceItemtoo, 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.'item'also matches thetype: 'item'realtime event names inrealtime.ts. They use the retired word, so they're in the baseline.No owner steps.