@sylphx/lens-server 2.14.3 → 3.0.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 +27 -20
- package/package.json +2 -2
- package/src/server/create.test.ts +2 -4
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ bun add @sylphx/lens-server
|
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
16
|
import { createApp, createHandler } from "@sylphx/lens-server";
|
|
17
|
-
import {
|
|
17
|
+
import { lens, id, string, list, nullable, router } from "@sylphx/lens-core";
|
|
18
18
|
import { z } from "zod";
|
|
19
19
|
|
|
20
20
|
// Define context type
|
|
@@ -23,24 +23,25 @@ interface AppContext {
|
|
|
23
23
|
user: User | null;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
// Create typed builders
|
|
27
|
+
const { model, query, mutation } = lens<AppContext>();
|
|
28
|
+
|
|
26
29
|
// Define models with inline resolvers
|
|
27
|
-
const User = model
|
|
28
|
-
id:
|
|
29
|
-
name:
|
|
30
|
-
email:
|
|
31
|
-
posts:
|
|
32
|
-
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const Post = model<AppContext>("Post", (t) => ({
|
|
37
|
-
id: t.id(),
|
|
38
|
-
title: t.string(),
|
|
39
|
-
authorId: t.string(),
|
|
40
|
-
}));
|
|
30
|
+
const User = model("User", {
|
|
31
|
+
id: id(),
|
|
32
|
+
name: string(),
|
|
33
|
+
email: string(),
|
|
34
|
+
posts: list(() => Post),
|
|
35
|
+
}).resolve({
|
|
36
|
+
posts: ({ source, ctx }) =>
|
|
37
|
+
ctx.db.posts.filter(p => p.authorId === source.id)
|
|
38
|
+
});
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const Post = model("Post", {
|
|
41
|
+
id: id(),
|
|
42
|
+
title: string(),
|
|
43
|
+
authorId: string(),
|
|
44
|
+
});
|
|
44
45
|
|
|
45
46
|
// Define operations
|
|
46
47
|
const appRouter = router({
|
|
@@ -84,13 +85,19 @@ Bun.serve({ port: 3000, fetch: handler });
|
|
|
84
85
|
|
|
85
86
|
```typescript
|
|
86
87
|
import { createApp, optimisticPlugin } from "@sylphx/lens-server";
|
|
87
|
-
import {
|
|
88
|
+
import { lens, id, string, router } from "@sylphx/lens-core";
|
|
88
89
|
import { entity as e, temp, now } from "@sylphx/reify";
|
|
89
90
|
|
|
90
91
|
// Enable optimistic plugin
|
|
91
|
-
const { query, mutation, plugins } = lens<AppContext>()
|
|
92
|
+
const { model, query, mutation, plugins } = lens<AppContext>()
|
|
92
93
|
.withPlugins([optimisticPlugin()]);
|
|
93
94
|
|
|
95
|
+
const Message = model("Message", {
|
|
96
|
+
id: id(),
|
|
97
|
+
content: string(),
|
|
98
|
+
createdAt: string(),
|
|
99
|
+
});
|
|
100
|
+
|
|
94
101
|
const appRouter = router({
|
|
95
102
|
user: {
|
|
96
103
|
// Sugar syntax
|
|
@@ -126,7 +133,7 @@ const app = createApp({
|
|
|
126
133
|
### Live Queries
|
|
127
134
|
|
|
128
135
|
```typescript
|
|
129
|
-
|
|
136
|
+
// query comes from lens<AppContext>() above
|
|
130
137
|
|
|
131
138
|
// Live query with Publisher pattern
|
|
132
139
|
const watchUser = query()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sylphx/lens-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Server runtime for Lens API framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"author": "SylphxAI",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@sylphx/lens-core": "^
|
|
33
|
+
"@sylphx/lens-core": "^4.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"typescript": "^5.9.3",
|
|
@@ -1592,9 +1592,7 @@ describe("Unified Entity Definition", () => {
|
|
|
1592
1592
|
const Task = entity("Task", (t) => ({
|
|
1593
1593
|
id: t.id(),
|
|
1594
1594
|
title: t.string(),
|
|
1595
|
-
status: t.string().
|
|
1596
|
-
ctx.emit("pending");
|
|
1597
|
-
}),
|
|
1595
|
+
status: t.string().resolve(({ parent }) => parent.status),
|
|
1598
1596
|
}));
|
|
1599
1597
|
|
|
1600
1598
|
const server = createApp({
|
|
@@ -1606,7 +1604,7 @@ describe("Unified Entity Definition", () => {
|
|
|
1606
1604
|
expect(metadata.entities.Task).toBeDefined();
|
|
1607
1605
|
expect(metadata.entities.Task.id).toBe("exposed");
|
|
1608
1606
|
expect(metadata.entities.Task.title).toBe("exposed");
|
|
1609
|
-
expect(metadata.entities.Task.status).toBe("
|
|
1607
|
+
expect(metadata.entities.Task.status).toBe("resolve");
|
|
1610
1608
|
});
|
|
1611
1609
|
|
|
1612
1610
|
it("skips entities without inline resolvers", () => {
|