@panproto/core 0.1.0
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 +70 -0
- package/dist/index.cjs +945 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +944 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @panproto/core
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for panproto -- protocol-aware schema migration via [generalized algebraic theories](https://ncatlab.org/nlab/show/generalized+algebraic+theory).
|
|
4
|
+
|
|
5
|
+
This package wraps the panproto [WASM](https://webassembly.org/) module, providing a typed, ergonomic API for defining protocols, building schemas, computing migrations, and applying [lens](https://ncatlab.org/nlab/show/lens+%28in+computer+science%29)-based transformations from JavaScript and TypeScript.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @panproto/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js >= 20.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Panproto } from '@panproto/core';
|
|
19
|
+
|
|
20
|
+
const panproto = await Panproto.init();
|
|
21
|
+
const atproto = panproto.protocol('atproto');
|
|
22
|
+
|
|
23
|
+
// Build a schema
|
|
24
|
+
const schema = atproto.schema()
|
|
25
|
+
.vertex('post', 'record', { nsid: 'app.bsky.feed.post' })
|
|
26
|
+
.vertex('post:body', 'object')
|
|
27
|
+
.edge('post', 'post:body', 'record-schema')
|
|
28
|
+
.build();
|
|
29
|
+
|
|
30
|
+
// Diff two schemas
|
|
31
|
+
const diff = panproto.diff(oldSchema, newSchema);
|
|
32
|
+
|
|
33
|
+
// Compile and apply a migration
|
|
34
|
+
const migration = panproto.migration(srcSchema, tgtSchema)
|
|
35
|
+
.mapVertex('old_id', 'new_id')
|
|
36
|
+
.compile();
|
|
37
|
+
|
|
38
|
+
const lifted = migration.lift(record);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## API
|
|
42
|
+
|
|
43
|
+
### Core
|
|
44
|
+
|
|
45
|
+
| Export | Description |
|
|
46
|
+
|--------|-------------|
|
|
47
|
+
| `Panproto` | Main entry point; call `Panproto.init()` to load the WASM module |
|
|
48
|
+
| `Protocol` | Protocol handle with schema builder factory |
|
|
49
|
+
| `SchemaBuilder` / `BuiltSchema` | Fluent schema construction |
|
|
50
|
+
| `MigrationBuilder` / `CompiledMigration` | Migration construction and compilation |
|
|
51
|
+
|
|
52
|
+
### Lens Combinators
|
|
53
|
+
|
|
54
|
+
| Export | Description |
|
|
55
|
+
|--------|-------------|
|
|
56
|
+
| `renameField` / `addField` / `removeField` | Field-level transformations |
|
|
57
|
+
| `wrapInObject` / `hoistField` / `coerceType` | Structural transformations |
|
|
58
|
+
| `compose` / `pipeline` | [Cambria](https://www.inkandswitch.com/cambria/)-style combinator composition |
|
|
59
|
+
|
|
60
|
+
### Built-in Protocol Specs
|
|
61
|
+
|
|
62
|
+
`ATPROTO_SPEC`, `SQL_SPEC`, `PROTOBUF_SPEC`, `GRAPHQL_SPEC`, `JSON_SCHEMA_SPEC`, `BUILTIN_PROTOCOLS`
|
|
63
|
+
|
|
64
|
+
### Error Classes
|
|
65
|
+
|
|
66
|
+
`PanprotoError`, `WasmError`, `SchemaValidationError`, `MigrationError`, `ExistenceCheckError`
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
[MIT](../../LICENSE)
|