Skip to content

Commit 9c7fa60

Browse files
adespawnwprzytula
authored andcommitted
Types
1 parent 162894c commit 9c7fa60

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 allows calls to this library with arbitrary argument values.
4+
In general using this driver API with values of types different than described in the documentation
5+
(JS Docs) can be considered UB.
6+
7+
Within 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 aspects of the objects other than the field being present.
10+
11+
- Policies: In policies we expect objects with specified constructors. This means you have to use 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 built-in types.
15+
16+
In general, there is no specific policy on allowing duck-typing: in many places like configuration it's allowed, but there are exceptions,
17+
such as the above-mentioned policies.
18+
19+
## TS fixes something, but exposes you to other problems
20+
21+
When you call a 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 by the user, consider it the same as direct calls from the 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 (i.e. don't explicitly disallow it where it makes sense).

0 commit comments

Comments
 (0)