@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 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 { model, lens, router, list, nullable } from "@sylphx/lens-core";
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<AppContext>("User", (t) => ({
28
- id: t.id(),
29
- name: t.string(),
30
- email: t.string(),
31
- posts: t.many(() => Post).resolve(({ parent, ctx }) =>
32
- ctx.db.posts.filter(p => p.authorId === parent.id)
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
- // Create typed builders
43
- const { query, mutation } = lens<AppContext>();
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 { model, lens, router } from "@sylphx/lens-core";
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
- const { query } = lens<AppContext>();
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": "2.14.3",
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": "^2.13.0"
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().subscribe(({ ctx }) => {
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("subscribe");
1607
+ expect(metadata.entities.Task.status).toBe("resolve");
1610
1608
  });
1611
1609
 
1612
1610
  it("skips entities without inline resolvers", () => {