@sylphx/lens-server 2.14.2 → 2.14.4

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.
Files changed (2) hide show
  1. package/README.md +27 -20
  2. package/package.json +2 -2
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.2",
3
+ "version": "2.14.4",
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.12.2"
33
+ "@sylphx/lens-core": "^3.0.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "typescript": "^5.9.3",