Custom Inspector for all SurrealDB Data Types#503
Conversation
e02c6be to
ce3add4
Compare
b329c8d to
b0f3da1
Compare
|
Can we change the approach to keep the SDK in a single bundle and only split the inspector logic to a separable importable bundle? e.g. // One time inspector import
import "surrealdb/inspector/node";
// Import from main bundle
import { ... } from "surrealdb"; |
@macjuul That's doable (already did locally), my only concern for being against this approach is that this is a side-effect module which patches the classess in the After doing those changes, you would not be able to test this PR by doing
// Compile sdk with these lines in src/inspect/node.ts
const req = createRequire(import.meta.url);
console.log("sdk surrealdb =", req.resolve("surrealdb"));
// And in a separate app with the sdk linked do
const req = createRequire(import.meta.url);
console.log("app surrealdb =", req.resolve("surrealdb"));For this to work we would have to do something like, which I am not very fond of: import setupInspectors from 'surrealdb/inspector/node';
import * as surreal from 'surrealdb';
setupInspectors(surreal);I think the current approach is best as we have the regular bundle which can be used in both clients and servers, and then we have the server bundle which includes the inspector goodies for better logging. Without having to do any extra steps or risks of something leaking, just letting the runtimes decide for themselves which bundle to use, server or default. |
b0f3da1 to
3e1e064
Compare
|
Makes sense! In that case, is it an option to re-export the main bundle from the node bundle, rather than embedding it? |
Done, works nicely |
c5e2a8a to
4d7ccd3
Compare
|
Awesome, LGTM! |
Thank you for submitting this pull request! We appreciate you spending the time to work on these changes.
What is the motivation?
It's hard to debug SurrealDB Results when logging any value just prints you the class name and all its properties with getters and all.
Currently you cannot see what's the table or id of a Record IDs without accessing table and id properties explicitly.
What does this change do?
Adds custom inspect to all of SurrealDB Value types are properly inspected when logged.
The print helper below is just a wrapper for the
console.logyou can find the full script in the gist: https://gist.github.com/msanchezdev/c45b1393084a4cbe68d556ea9d06b33dTable
RecordId
StringRecordId
RecordIdRange
DateTime
Uuid
Range
FileRef
Duration
Decimal
Query
Geometry
These are long and it's mostly showing how they react with different inspect depth, so please refer to the example gist: https://gist.github.com/msanchezdev/c45b1393084a4cbe68d556ea9d06b33d
What is your testing strategy?
Each case above has it's own snippet, snapshot testing can be added. There is also a gist that can be run with all these examples: https://gist.github.com/msanchezdev/c45b1393084a4cbe68d556ea9d06b33d
Is this related to any issues?
No
Have you read the Contributing Guidelines?