Replace Proxy-based DbRecord with plain objects for Comlink compatibility (v2.0.0) #51
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.
The Proxy-based DbRecord system doesn't serialize through Comlink for web worker scenarios. Replaced with plain objects using
xRecproperty for change tracking.This is a breaking change release (v2.0.0) with complete removal of the deprecated DbRecord API.
Changes
Record Structure
xRecproperty storing original database values__tableNametracks table association (non-enumerable)API Changes
db.save(record)- determines INSERT vs UPDATE by checkingxRec.system_iddb.deleteRecord(record)- deletes record using primary key.save()and.delete()methods from records themselvesdb.save(), not on property mutationChange Detection
_getChangedFields()compares current values againstxRec__hlctimestamps when values changeStreaming & Queries
StreamingQuery<T>returnsT[]instead of(T & DbRecord<T>)[]xRectrackingDeprecated Code Removal (v2.0.0)
DbRecordclass and entire Proxy-based implementationcomlink-transfermodule including all serialization helpers:registerDbRecordTransferHandler()serializeDbRecord(),deserializeDbRecord()serializeDbRecords(),deserializeDbRecords()isDbRecord(),isSerializableDbRecord()/src/recordsdirectory entirelyExample
Breaking Changes (v2.0.0)
Before (v1.x - REMOVED):
After (v2.0.0 - Current API):
Removed APIs
DbRecordclassrecord.save()andrecord.delete()methods on recordsDbRecord<T>[]toT[](plain objects withxRec)Migration Guide
All code using the old
DbRecordAPI must be updated to use database methods:record.save()withdb.save(record)record.delete()withdb.deleteRecord(record)Original prompt
This entire DbRecord design is giving me a headache with comlink. Can you redesign the way the developer interacts with the database and records? Probably best to just keep it simple with a copy of each column in a "xRec" property object for simple comparison of what has changed when we call db.save(rec), that way we can handle HLC timestamping and comparison correctly. we don't get the timestamp from when the property was set, but rather the timestamp from when the record was "saved", but that's fine I guess.
In reality then, we should have a simple stream for a query that returns pure objects and all the logic is contained in the database when calling save and the other functions. We still need the bulkLoad for when we load fresh data from the API, as it checks against HLC timestamps and doesn't overwrite fresher data from local vs server.
[Chronological Review: The conversation began with the user reporting an error related to the "opfs" not being available in a web worker when initializing the database. The user then expressed a desire not to preemptively dismiss a storage backend requested by developers. Following this, the user discussed issues with the serialization of WorkerDbRecord instances through Comlink, proposing a solution to avoid using queryRecords in the main thread and suggesting alternative hooks. The user then inquired about enabling DbRecord to work across Comlink. The conversation shifted towards redesigning the DbRecord interaction with the database, emphasizing simplicity and proper handling of HLC timestamps and comparisons. The user suggested a new approach to manage records and queries more effectively.][Intent Mapping:
[Technical Inventory:
[Code Archaeology:
[Progress Assessment:
[Context Validation: All critical information for continuation is captured, including user frustrations, proposed solutions, and the need for a redesign.]
[Recent Commands Analysis:
1. Conversation Overview: - Primary Objectives: - "i am getting an error stating that opfs is not available in this environment when i initialize the db in a web worker" - User seeks help with a specific error. - "we should not premetively test and dismiss a storage backend requested by the developer" - User wants to ensure flexibility in backend storage options. - "This entire DbRecord design is giving me a headache with comlink." - User expresses frustration and requests a redesign for simplicity and better functionality. - Session Context: The conversation flowed from error reporting to discussing technical limitations and proposing a redesign for better database interaction. - User Intent Evolution: The user transitioned from seeking immediate help with an error to expressing broader concerns about the design and usability of the databas...
Created from VS Code via the GitHub Pull Request extension.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.