Apple CKTool JS client library runtime support
npm install @apple/cktool.coreThis package is part of the CKTool JS JavaScript client library suite
and is used to support other CKTool JS packages.
Don't use this package on its own. It is automatically pulled
in when you include @apple/cktool.database
in your package.json dependencies.
See Apple Developer Documentation
for more details on how to get started using CKTool JS.
There are several branded types used to mark validated values.
For example, the Int32 type is a branded numeric type that is
assignaable to number but number is not directly assignable to it.
``ts`
const a: number = toInt32(12); // OK
const b: Int32 = 12; // Error
This client library attempts to be as type-safe as possible.
There are several data types that must be validated in order to be
passed to an operation. For example, where an Int32 would be expected,toInt32
you must first pass your constant through the cast function.Int32
The cast function does the following:Int32
- Validates that the value is a numeric type.
- Validates that the number is an integer in range.Int32
- Returns an value that will pass type checking.
Do NOT use type assertions to cast a related type, such as number
to a branded type. Such an approach is not guaranteed to compile in
future and an invalid value may be type asserted, which can lead
to errors down the line.
Support for Int64, Float, and Double is achieved with the bignumber.jsBigNumber
library. Whenever one of those numeric types are returned from an operation, it will be a instance. In order to perform operations on those instances, suchBigNumber
as addition or subtraction, you'll need to use the methods.BigNumber
See the documentation for at https://github.com/MikeMcl/bignumber.js.
The toInt64 cast function will do the following:Int64
- Validates that the value is a numeric type.
- Validates that the number is an integer in range.BigNumber
- Returns a instance of type Int64.
The toFloat cast function will do the following:Float
- Validates that the value is a numeric type.
- Validates that the number is an integer in range.BigNumber
- Returns a instance of type Float.
The toDouble cast function will do the following:Double
- Validates that the value is a numeric type.
- Validates that the number is an integer in range.BigNumber
- Returns a instance of type Double.
To pass a Uuid to a function, use the toUuid cast function.Uuid
To create a object, use the createUuid` function.