@korajs/core 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @korajs/core
|
|
2
|
+
|
|
3
|
+
Schema definitions, operations, Hybrid Logical Clock, version vectors, and type inference for Kora.js. This is the foundation package -- all other packages depend on it.
|
|
4
|
+
|
|
5
|
+
> Most developers don't install this directly. Use [`korajs`](https://www.npmjs.com/package/korajs) instead.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @korajs/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Define a Schema
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { defineSchema, t } from '@korajs/core'
|
|
19
|
+
|
|
20
|
+
const schema = defineSchema({
|
|
21
|
+
version: 1,
|
|
22
|
+
collections: {
|
|
23
|
+
todos: {
|
|
24
|
+
fields: {
|
|
25
|
+
title: t.string(),
|
|
26
|
+
completed: t.boolean().default(false),
|
|
27
|
+
tags: t.array(t.string()).default([]),
|
|
28
|
+
notes: t.richtext(),
|
|
29
|
+
priority: t.enum(['low', 'medium', 'high']).default('medium'),
|
|
30
|
+
createdAt: t.timestamp().auto(),
|
|
31
|
+
},
|
|
32
|
+
indexes: ['completed'],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Hybrid Logical Clock
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { HybridLogicalClock } from '@korajs/core'
|
|
42
|
+
|
|
43
|
+
const clock = new HybridLogicalClock('node-1')
|
|
44
|
+
|
|
45
|
+
const ts1 = clock.now()
|
|
46
|
+
const ts2 = clock.now()
|
|
47
|
+
|
|
48
|
+
// Timestamps are always monotonically increasing
|
|
49
|
+
HybridLogicalClock.compare(ts1, ts2) // negative (ts1 < ts2)
|
|
50
|
+
|
|
51
|
+
// Merge with a remote timestamp
|
|
52
|
+
const ts3 = clock.receive(remoteTimestamp)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Version Vectors
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { mergeVectors, deltaOperations } from '@korajs/core'
|
|
59
|
+
|
|
60
|
+
const merged = mergeVectors(localVector, remoteVector)
|
|
61
|
+
const missing = deltaOperations(localVector, remoteVector, operationLog)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## What's Inside
|
|
65
|
+
|
|
66
|
+
- **Schema system** -- `defineSchema`, `t` field builders, full TypeScript type inference
|
|
67
|
+
- **Operation type** -- immutable, content-addressed mutation records
|
|
68
|
+
- **Hybrid Logical Clock** -- causal ordering without synchronized clocks
|
|
69
|
+
- **Version vectors** -- efficient delta sync computation
|
|
70
|
+
- **Error types** -- structured `KoraError` base class
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
75
|
+
|
|
76
|
+
See the [full documentation](https://github.com/ehoneahobed/kora) for guides, API reference, and examples.
|