feat(modifiers): add AutoDateModifier with CreationTime and UpdateTime decorators - #11
Merged
Conversation
…e decorators Move the automatic timestamp modifier from the CMS cms-base interface into the shared modifiers so any table definition can use it. Fields marked with CreationTime are set on insert and preserved on update, while UpdateTime fields are refreshed on every write.
Member
Author
|
@greptile review |
Address greptile review feedback: verify through toDatabase that update payloads omit CreationTime fields and refresh UpdateTime fields.
Member
Author
|
@greptile review |
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.
🔗 Linked issue
N/A
❓ Type of change
📚 Description
Moves the automatic timestamp modifier from the CMS
cms-baseinterface (AntelopeJS/cms) into the shared modifiers, so any table definition can use it without depending on the CMS.AutoDateModifier, an event-only modifier (noTable.with()mixin required) that populates timestamp fields through theinsert/updatemodifier events.CreationTimedecorator: field set to the current date on insert, removed from update payloads so the original creation date is preserved.UpdateTimedecorator: field refreshed with the current date on both insert and update../modifiers/autodatesubpath inpackage.jsonexports andtypesVersions.docs/3.table-modifiers.md.Follow-up PRs update the consumers (
cms,cms-api,cms-saas) to import these decorators from this package. Behavior is identical to the CMS implementation.📝 Checklist
Test plan
pnpm test— newModifiers - autodatesuite covers insert/update behavior for both decorator types, including the decorator-through-events integration path (101 tests passing).Greptile Summary
This PR extracts the automatic timestamp modifier from
cms-baseinto the sharedinterface-database-decoratorspackage, makingCreationTimeandUpdateTimedecorators available to any table definition without a CMS dependency. The implementation is clean, event-driven, and behaviorally identical to the original CMS implementation.AutoDateModifier(event-only, noTable.with()mixin required) withinsert/updatehandlers that set or remove timestamp fields.CreationTimeandUpdateTimedecorators via a new./modifiers/autodatesubpath inpackage.jsonexports andtypesVersions.toDatabasepayload verification that confirmscreatedAtis absent from update payloads.Confidence Score: 5/5
Safe to merge — the change is a straightforward extraction of well-understood CMS logic into a shared location with no behavioral changes.
The modifier is event-only with two simple methods. The package export wiring matches the existing pattern exactly. The test suite covers all paths including the toDatabase payload shape. No regressions are introduced.
No files require special attention.
Important Files Changed
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant Caller participant triggerEvent participant AutoDateModifier participant Object Note over Caller,Object: Insert flow Caller->>triggerEvent: triggerEvent(instance, "insert") triggerEvent->>AutoDateModifier: insert(object, "createdAt") AutoDateModifier->>Object: "object["createdAt"] = new Date()" triggerEvent->>AutoDateModifier: insert(object, "updatedAt") AutoDateModifier->>Object: "object["updatedAt"] = new Date()" Note over Caller,Object: Update flow Caller->>triggerEvent: triggerEvent(instance, "update") triggerEvent->>AutoDateModifier: "update(object, "createdAt") [type=created]" AutoDateModifier->>Object: delete object["createdAt"] triggerEvent->>AutoDateModifier: "update(object, "updatedAt") [type=updated]" AutoDateModifier->>Object: "object["updatedAt"] = new Date()" Note over Caller,Object: Serialize Caller->>Object: toDatabase(instance) Object-->>Caller: "{ updatedAt: Date } (no createdAt)"%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant Caller participant triggerEvent participant AutoDateModifier participant Object Note over Caller,Object: Insert flow Caller->>triggerEvent: triggerEvent(instance, "insert") triggerEvent->>AutoDateModifier: insert(object, "createdAt") AutoDateModifier->>Object: "object["createdAt"] = new Date()" triggerEvent->>AutoDateModifier: insert(object, "updatedAt") AutoDateModifier->>Object: "object["updatedAt"] = new Date()" Note over Caller,Object: Update flow Caller->>triggerEvent: triggerEvent(instance, "update") triggerEvent->>AutoDateModifier: "update(object, "createdAt") [type=created]" AutoDateModifier->>Object: delete object["createdAt"] triggerEvent->>AutoDateModifier: "update(object, "updatedAt") [type=updated]" AutoDateModifier->>Object: "object["updatedAt"] = new Date()" Note over Caller,Object: Serialize Caller->>Object: toDatabase(instance) Object-->>Caller: "{ updatedAt: Date } (no createdAt)"Reviews (3): Last reviewed commit: "test(modifiers): assert autodate behavio..." | Re-trigger Greptile