@lumi.new/sdk 0.0.4 → 0.0.5
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 +57 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,10 +22,10 @@ First, initialize the Lumi client. You can get your `projectId` from your Lumi p
|
|
|
22
22
|
```typescript
|
|
23
23
|
import { createClient } from '@lumi.new/sdk'
|
|
24
24
|
|
|
25
|
-
const lumi = createClient({
|
|
25
|
+
export const lumi = createClient({
|
|
26
26
|
projectId: 'YOUR_PROJECT_ID',
|
|
27
|
-
apiBaseUrl: '
|
|
28
|
-
authOrigin: '
|
|
27
|
+
apiBaseUrl: 'YOUR_API_BASE_URL',
|
|
28
|
+
authOrigin: 'YOUR_AUTH_ORIGIN',
|
|
29
29
|
})
|
|
30
30
|
```
|
|
31
31
|
|
|
@@ -116,6 +116,16 @@ async function getPosts() {
|
|
|
116
116
|
console.log('Posts:', list)
|
|
117
117
|
console.log('Total records:', total)
|
|
118
118
|
}
|
|
119
|
+
|
|
120
|
+
// Example Request:
|
|
121
|
+
getPosts();
|
|
122
|
+
|
|
123
|
+
// Example Response:
|
|
124
|
+
// Posts: [
|
|
125
|
+
// { id: 'post-id-1', title: 'First Post', content: '...', published: true, createdAt: '...' },
|
|
126
|
+
// { id: 'post-id-2', title: 'Second Post', content: '...', published: true, createdAt: '...' }
|
|
127
|
+
// ]
|
|
128
|
+
// Total records: 2
|
|
119
129
|
```
|
|
120
130
|
|
|
121
131
|
### Get a Single Record
|
|
@@ -127,6 +137,12 @@ async function getPost(id: string) {
|
|
|
127
137
|
const post = await lumi.entities.Posts.get(id)
|
|
128
138
|
console.log('Post:', post)
|
|
129
139
|
}
|
|
140
|
+
|
|
141
|
+
// Example Request:
|
|
142
|
+
getPost('your-post-id');
|
|
143
|
+
|
|
144
|
+
// Example Response:
|
|
145
|
+
// Post: { id: 'post-id-1', title: 'My Post', content: '...', published: true, createdAt: '...' }
|
|
130
146
|
```
|
|
131
147
|
|
|
132
148
|
### Create a Record
|
|
@@ -142,6 +158,12 @@ async function createPost(title: string, content: string) {
|
|
|
142
158
|
})
|
|
143
159
|
console.log('Created post:', newPost)
|
|
144
160
|
}
|
|
161
|
+
|
|
162
|
+
// Example Request:
|
|
163
|
+
createPost('My Awesome Post', 'This is the content of my new post.');
|
|
164
|
+
|
|
165
|
+
// Example Response:
|
|
166
|
+
// Created post: { id: 'new-post-id', title: 'My Awesome Post', content: 'This is the content of my new post.', published: false, creator: 'user-id-123', createdAt: '2024-01-16T10:30:00Z', updatedAt: '2024-01-16T10:30:00Z' }
|
|
145
167
|
```
|
|
146
168
|
|
|
147
169
|
### Create Multiple Records
|
|
@@ -149,10 +171,23 @@ async function createPost(title: string, content: string) {
|
|
|
149
171
|
Create multiple records in a single request.
|
|
150
172
|
|
|
151
173
|
```typescript
|
|
152
|
-
async function createMultiplePosts(newPostsData) {
|
|
174
|
+
async function createMultiplePosts(newPostsData: any[]) {
|
|
153
175
|
const newPosts = await lumi.entities.Posts.createMany(newPostsData)
|
|
154
176
|
console.log('Created posts:', newPosts)
|
|
155
177
|
}
|
|
178
|
+
|
|
179
|
+
// Example Request:
|
|
180
|
+
const postsToCreate = [
|
|
181
|
+
{ title: 'First Awesome Post', content: 'Content for the first post.' },
|
|
182
|
+
{ title: 'Second Awesome Post', content: 'Content for the second post.' }
|
|
183
|
+
];
|
|
184
|
+
createMultiplePosts(postsToCreate);
|
|
185
|
+
|
|
186
|
+
// Example Response:
|
|
187
|
+
// Created posts: [
|
|
188
|
+
// { id: 'post-1', title: 'Post 1', content: '...', published: false, creator: 'user-id-123', createdAt: '...', updatedAt: '...' },
|
|
189
|
+
// { id: 'post-2', title: 'Post 2', content: '...', published: false, creator: 'user-id-123', createdAt: '...', updatedAt: '...' }
|
|
190
|
+
// ]
|
|
156
191
|
```
|
|
157
192
|
|
|
158
193
|
### Update a Record
|
|
@@ -164,6 +199,12 @@ async function updatePost(id: string, updates: Record<string, any>) {
|
|
|
164
199
|
const updatedPost = await lumi.entities.Posts.update(id, updates)
|
|
165
200
|
console.log('Updated post:', updatedPost)
|
|
166
201
|
}
|
|
202
|
+
|
|
203
|
+
// Example Request:
|
|
204
|
+
updatePost('your-post-id', { published: true, title: 'My Updated Post' });
|
|
205
|
+
|
|
206
|
+
// Example Response:
|
|
207
|
+
// Updated post: { id: 'post-id-1', title: 'My Updated Post', content: '...', published: true, creator: 'user-id-123', createdAt: '...', updatedAt: '...' }
|
|
167
208
|
```
|
|
168
209
|
|
|
169
210
|
### Delete a Record
|
|
@@ -175,6 +216,12 @@ async function deletePost(id: string) {
|
|
|
175
216
|
await lumi.entities.Posts.delete(id)
|
|
176
217
|
console.log('Post deleted.')
|
|
177
218
|
}
|
|
219
|
+
|
|
220
|
+
// Example Request:
|
|
221
|
+
deletePost('your-post-id');
|
|
222
|
+
|
|
223
|
+
// The console will output:
|
|
224
|
+
// Post deleted.
|
|
178
225
|
```
|
|
179
226
|
|
|
180
227
|
### Delete Multiple Records
|
|
@@ -186,4 +233,10 @@ async function deleteMultiplePosts(ids: string[]) {
|
|
|
186
233
|
await lumi.entities.Posts.deleteMany(ids)
|
|
187
234
|
console.log('Posts deleted.')
|
|
188
235
|
}
|
|
236
|
+
|
|
237
|
+
// Example Request:
|
|
238
|
+
deleteMultiplePosts(['post-id-1', 'post-id-2']);
|
|
239
|
+
|
|
240
|
+
// The console will output:
|
|
241
|
+
// Posts deleted.
|
|
189
242
|
```
|