Skip to content

Commit 8ab52c6

Browse files
committed
Types
1 parent 2bb5080 commit 8ab52c6

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

docs/source/internal/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ this driver, new driver, scylladb-driver, scylladb-driver-alpha. Official: Scyll
3232
- [Logging](./logging.md)
3333
- [Napi](./napi.md)
3434
- [Miscellaneous](./miscellaneous.md)
35+
- [On types](./on-types.md)

docs/source/internal/on-types.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Some rambling on JS types
2+
3+
JavaScript does allow you to ignore ignore the call this library with arbitrary values as arguments.
4+
In general using this driver API with values of types different than provided than described in the documentation
5+
(JS Docs) can be considered UB.
6+
7+
Withing JavaScript Objects we allow for some duck-typing - this applies to all of the config options and named parameters.
8+
Any object passed there that has required fields is considered valid.
9+
There are some exceptions, where we rely on some other aspects of the objects, that the field present.
10+
11+
- Policies: In policies we expect objects with specified constructors. This means you have to used objects as provided through the driver.
12+
- Type guessing & encoding: Parts of type guessing and encoding depend on receiving values of specified types.
13+
14+
When it comes to built-in types, we may perform some explicit checks to ensure you have provided expected builtin type.
15+
16+
In general, lacks specific policy on allowing duck-typing: in many places like configuration it's allowed, but there are exceptions
17+
as above mentioned policies.
18+
19+
## TS fixes something, but exposes you to other problems
20+
21+
When you call TS function from JS code you can NOT assume that someone will call it with the types as specified in TS.
22+
You can only assume this is what the function should accept and correctly handle.
23+
When calling internally with wrong types, consider it a bug.
24+
When calling it internally, but with wrong types provided from user, consider it the same as direct calls from user with different types: undefined behavior.
25+
Either way try to gracefully handle those cases. Clear errors (remember, napi will complain when receiving invalid types: [#251](https://github.com/scylladb/nodejs-rs-driver/issues/251)),
26+
or where possible allow for duck-typing (ie. don't explicitly disallow it where it makes sens)

0 commit comments

Comments
 (0)