@gettersethya/mira 0.1.0-alpha.2 → 0.1.0-alpha.3
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 +103 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @gettersethya/mira
|
|
2
|
+
|
|
3
|
+
> **Early pre-alpha.** Breaking changes may occur without notice.
|
|
4
|
+
|
|
5
|
+
Self-hosted backend in TypeScript using [Effect](https://effect.website). Define collections, get a full REST API with auth, file storage, access rules, and schema migrations — all with zero config.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @gettersethya/mira @gettersethya/mira-collection effect
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @gettersethya/mira @gettersethya/mira-collection effect
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { LocalFileStorage, Mira, NodePlatform, SqliteDatabase } from "@gettersethya/mira"
|
|
19
|
+
import { Posts, Users } from "./collections.js"
|
|
20
|
+
|
|
21
|
+
const app = Mira.builder()
|
|
22
|
+
.platform(NodePlatform)
|
|
23
|
+
.database(SqliteDatabase({ filename: "mira.db" }))
|
|
24
|
+
.storage(LocalFileStorage({ directory: "./uploads" }))
|
|
25
|
+
.collections([Users, Posts])
|
|
26
|
+
.build()
|
|
27
|
+
|
|
28
|
+
app.serve({ port: 3000 })
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The builder uses phantom types to enforce step ordering — TypeScript will not let you call `.build()` until all four steps are complete.
|
|
32
|
+
|
|
33
|
+
On first boot, Mira auto-generates a `jwt_secret`, runs schema migrations, and creates SQL views for view collections. Everything is persisted in the database.
|
|
34
|
+
|
|
35
|
+
## Builder steps
|
|
36
|
+
|
|
37
|
+
| Step | Required | Description |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `.platform(p)` | Yes | Runtime environment (Node.js, etc.) |
|
|
40
|
+
| `.database(d)` | Yes | Database backend |
|
|
41
|
+
| `.storage(s)` | Yes | File storage backend |
|
|
42
|
+
| `.collections(c)` | Yes | Collection definitions |
|
|
43
|
+
| `.telemetry(layer)` | No | Custom Effect telemetry layer |
|
|
44
|
+
| `.extend(layer)` | No | Inject additional layers before serving |
|
|
45
|
+
|
|
46
|
+
## Platforms
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { NodePlatform } from "@gettersethya/mira"
|
|
50
|
+
|
|
51
|
+
// Provides: CryptoService, FileSystem, HttpServerFactory, AuthService
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Databases
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { SqliteDatabase } from "@gettersethya/mira"
|
|
58
|
+
|
|
59
|
+
SqliteDatabase({ filename: "mira.db" })
|
|
60
|
+
SqliteDatabase({ filename: ":memory:" }) // in-memory for tests
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Storage
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { LocalFileStorage } from "@gettersethya/mira"
|
|
67
|
+
|
|
68
|
+
LocalFileStorage({ directory: "./uploads" })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Auto-generated endpoints
|
|
72
|
+
|
|
73
|
+
Each collection gets a full set of REST endpoints:
|
|
74
|
+
|
|
75
|
+
| Method | Path | Description |
|
|
76
|
+
|---|---|---|
|
|
77
|
+
| `GET` | `/api/:collection` | List (filter, sort, cursor, expand, select) |
|
|
78
|
+
| `GET` | `/api/:collection/:id` | Get one |
|
|
79
|
+
| `POST` | `/api/:collection` | Create |
|
|
80
|
+
| `PATCH` | `/api/:collection/:id` | Update |
|
|
81
|
+
| `DELETE` | `/api/:collection/:id` | Delete |
|
|
82
|
+
| `POST` | `/api/:collection/authWithPassword` | Login (auth collections only) |
|
|
83
|
+
| `POST` | `/api/auth/logout` | Logout |
|
|
84
|
+
| `POST` | `/api/files/token` | Request protected file token |
|
|
85
|
+
| `GET` | `/api/files/:collection/:id/:filename` | Serve file |
|
|
86
|
+
|
|
87
|
+
## Testing with the service layer
|
|
88
|
+
|
|
89
|
+
Use `.buildServiceLayer()` to get an Effect `Layer` for all services without starting an HTTP server:
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { Effect, Layer } from "effect"
|
|
93
|
+
|
|
94
|
+
const serviceLayer = app.buildServiceLayer()
|
|
95
|
+
|
|
96
|
+
const test = Effect.gen(function* () {
|
|
97
|
+
// inject and use services directly
|
|
98
|
+
}).pipe(Effect.provide(serviceLayer))
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## More
|
|
102
|
+
|
|
103
|
+
See the [Mira root README](https://github.com/gettersethya/mira) for collection definitions, field types, rules, filter DSL, and client usage.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gettersethya/mira",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Self-hosted backend in TypeScript using Effect",
|
|
6
6
|
"author": "Getter Sethya",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"@effect/sql-sqlite-node": "^0.52.0",
|
|
23
23
|
"jose": "^6.2.3",
|
|
24
24
|
"mime": "^4.0.0",
|
|
25
|
-
"@gettersethya/mira-client": "0.1.0-alpha.
|
|
25
|
+
"@gettersethya/mira-client": "0.1.0-alpha.3"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"effect": ">=3.21"
|