ebely 0.0.3 → 0.0.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.
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "for-clone",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "client:generate": "tsx ebely/generate-client.ts",
8
+ "test": "vitest run"
9
+ },
10
+ "dependencies": {
11
+ "ebely": "workspace:*"
12
+ },
13
+ "devDependencies": {
14
+ "@types/node": "^25.8.0",
15
+ "tsx": "^4.22.1",
16
+ "typescript": "^6.0.3",
17
+ "vitest": "^4.1.6"
18
+ }
19
+ }
@@ -0,0 +1,426 @@
1
+ {
2
+ "info": {
3
+ "title": "Test Backend (oRPC)",
4
+ "version": "1.0.0",
5
+ "description": "CRUD-эндпоинты для постов. Данные хранятся в памяти."
6
+ },
7
+ "servers": [
8
+ {
9
+ "url": "/api"
10
+ }
11
+ ],
12
+ "openapi": "3.1.1",
13
+ "paths": {
14
+ "/posts": {
15
+ "get": {
16
+ "operationId": "posts.list",
17
+ "summary": "List all posts",
18
+ "tags": [
19
+ "Posts"
20
+ ],
21
+ "responses": {
22
+ "200": {
23
+ "description": "OK",
24
+ "content": {
25
+ "application/json": {
26
+ "schema": {
27
+ "type": "array",
28
+ "items": {
29
+ "type": "object",
30
+ "properties": {
31
+ "id": {
32
+ "type": "string"
33
+ },
34
+ "title": {
35
+ "type": "string"
36
+ },
37
+ "content": {
38
+ "type": "string"
39
+ },
40
+ "createdAt": {
41
+ "type": "string"
42
+ },
43
+ "updatedAt": {
44
+ "type": "string"
45
+ }
46
+ },
47
+ "required": [
48
+ "id",
49
+ "title",
50
+ "content",
51
+ "createdAt",
52
+ "updatedAt"
53
+ ]
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ },
61
+ "post": {
62
+ "operationId": "posts.create",
63
+ "summary": "Create a post",
64
+ "tags": [
65
+ "Posts"
66
+ ],
67
+ "requestBody": {
68
+ "required": true,
69
+ "content": {
70
+ "application/json": {
71
+ "schema": {
72
+ "type": "object",
73
+ "properties": {
74
+ "title": {
75
+ "type": "string",
76
+ "minLength": 1
77
+ },
78
+ "content": {
79
+ "type": "string",
80
+ "minLength": 1
81
+ }
82
+ },
83
+ "required": [
84
+ "title",
85
+ "content"
86
+ ]
87
+ }
88
+ }
89
+ }
90
+ },
91
+ "responses": {
92
+ "200": {
93
+ "description": "OK",
94
+ "content": {
95
+ "application/json": {
96
+ "schema": {
97
+ "type": "object",
98
+ "properties": {
99
+ "id": {
100
+ "type": "string"
101
+ },
102
+ "title": {
103
+ "type": "string"
104
+ },
105
+ "content": {
106
+ "type": "string"
107
+ },
108
+ "createdAt": {
109
+ "type": "string"
110
+ },
111
+ "updatedAt": {
112
+ "type": "string"
113
+ }
114
+ },
115
+ "required": [
116
+ "id",
117
+ "title",
118
+ "content",
119
+ "createdAt",
120
+ "updatedAt"
121
+ ]
122
+ }
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }
128
+ },
129
+ "/posts/{id}": {
130
+ "get": {
131
+ "operationId": "posts.get",
132
+ "summary": "Get a single post by id",
133
+ "tags": [
134
+ "Posts"
135
+ ],
136
+ "parameters": [
137
+ {
138
+ "name": "id",
139
+ "in": "path",
140
+ "required": true,
141
+ "schema": {
142
+ "type": "string"
143
+ }
144
+ }
145
+ ],
146
+ "responses": {
147
+ "200": {
148
+ "description": "OK",
149
+ "content": {
150
+ "application/json": {
151
+ "schema": {
152
+ "type": "object",
153
+ "properties": {
154
+ "id": {
155
+ "type": "string"
156
+ },
157
+ "title": {
158
+ "type": "string"
159
+ },
160
+ "content": {
161
+ "type": "string"
162
+ },
163
+ "createdAt": {
164
+ "type": "string"
165
+ },
166
+ "updatedAt": {
167
+ "type": "string"
168
+ }
169
+ },
170
+ "required": [
171
+ "id",
172
+ "title",
173
+ "content",
174
+ "createdAt",
175
+ "updatedAt"
176
+ ]
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ },
183
+ "patch": {
184
+ "operationId": "posts.update",
185
+ "summary": "Update a post",
186
+ "tags": [
187
+ "Posts"
188
+ ],
189
+ "parameters": [
190
+ {
191
+ "name": "id",
192
+ "in": "path",
193
+ "required": true,
194
+ "schema": {
195
+ "type": "string"
196
+ }
197
+ }
198
+ ],
199
+ "requestBody": {
200
+ "required": false,
201
+ "content": {
202
+ "application/json": {
203
+ "schema": {
204
+ "type": "object",
205
+ "properties": {
206
+ "title": {
207
+ "type": "string",
208
+ "minLength": 1
209
+ },
210
+ "content": {
211
+ "type": "string",
212
+ "minLength": 1
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }
218
+ },
219
+ "responses": {
220
+ "200": {
221
+ "description": "OK",
222
+ "content": {
223
+ "application/json": {
224
+ "schema": {
225
+ "type": "object",
226
+ "properties": {
227
+ "id": {
228
+ "type": "string"
229
+ },
230
+ "title": {
231
+ "type": "string"
232
+ },
233
+ "content": {
234
+ "type": "string"
235
+ },
236
+ "createdAt": {
237
+ "type": "string"
238
+ },
239
+ "updatedAt": {
240
+ "type": "string"
241
+ }
242
+ },
243
+ "required": [
244
+ "id",
245
+ "title",
246
+ "content",
247
+ "createdAt",
248
+ "updatedAt"
249
+ ]
250
+ }
251
+ }
252
+ }
253
+ }
254
+ }
255
+ },
256
+ "delete": {
257
+ "operationId": "posts.delete",
258
+ "summary": "Delete a post",
259
+ "tags": [
260
+ "Posts"
261
+ ],
262
+ "parameters": [
263
+ {
264
+ "name": "id",
265
+ "in": "path",
266
+ "required": true,
267
+ "schema": {
268
+ "type": "string"
269
+ }
270
+ }
271
+ ],
272
+ "responses": {
273
+ "200": {
274
+ "description": "OK",
275
+ "content": {
276
+ "application/json": {
277
+ "schema": {
278
+ "type": "object",
279
+ "properties": {
280
+ "success": {
281
+ "type": "boolean"
282
+ }
283
+ },
284
+ "required": [
285
+ "success"
286
+ ]
287
+ }
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+ },
294
+ "/auth/register": {
295
+ "post": {
296
+ "operationId": "auth.register",
297
+ "summary": "Register (stub: echoes input)",
298
+ "tags": [
299
+ "Auth"
300
+ ],
301
+ "requestBody": {
302
+ "required": true,
303
+ "content": {
304
+ "application/json": {
305
+ "schema": {
306
+ "type": "object",
307
+ "properties": {
308
+ "email": {
309
+ "type": "string"
310
+ },
311
+ "password": {
312
+ "type": "string"
313
+ }
314
+ },
315
+ "required": [
316
+ "email",
317
+ "password"
318
+ ]
319
+ }
320
+ }
321
+ }
322
+ },
323
+ "responses": {
324
+ "200": {
325
+ "description": "OK",
326
+ "content": {
327
+ "application/json": {
328
+ "schema": {
329
+ "type": "object",
330
+ "properties": {
331
+ "email": {
332
+ "type": "string"
333
+ },
334
+ "password": {
335
+ "type": "string"
336
+ }
337
+ },
338
+ "required": [
339
+ "email",
340
+ "password"
341
+ ]
342
+ }
343
+ }
344
+ }
345
+ }
346
+ }
347
+ }
348
+ },
349
+ "/auth/confirm": {
350
+ "post": {
351
+ "operationId": "auth.confirm",
352
+ "summary": "Confirm registration code (stub: echoes input)",
353
+ "tags": [
354
+ "Auth"
355
+ ],
356
+ "requestBody": {
357
+ "required": true,
358
+ "content": {
359
+ "application/json": {
360
+ "schema": {
361
+ "type": "object",
362
+ "properties": {
363
+ "code": {
364
+ "type": "string"
365
+ }
366
+ },
367
+ "required": [
368
+ "code"
369
+ ]
370
+ }
371
+ }
372
+ }
373
+ },
374
+ "responses": {
375
+ "200": {
376
+ "description": "OK",
377
+ "content": {
378
+ "application/json": {
379
+ "schema": {
380
+ "type": "object",
381
+ "properties": {
382
+ "code": {
383
+ "type": "string"
384
+ }
385
+ },
386
+ "required": [
387
+ "code"
388
+ ]
389
+ }
390
+ }
391
+ }
392
+ }
393
+ }
394
+ }
395
+ },
396
+ "/admin/clear-database": {
397
+ "post": {
398
+ "operationId": "admin.clearDatabase",
399
+ "summary": "Wipe all in-memory data",
400
+ "tags": [
401
+ "Admin"
402
+ ],
403
+ "responses": {
404
+ "200": {
405
+ "description": "OK",
406
+ "content": {
407
+ "application/json": {
408
+ "schema": {
409
+ "type": "object",
410
+ "properties": {
411
+ "success": {
412
+ "type": "boolean"
413
+ }
414
+ },
415
+ "required": [
416
+ "success"
417
+ ]
418
+ }
419
+ }
420
+ }
421
+ }
422
+ }
423
+ }
424
+ }
425
+ }
426
+ }
@@ -0,0 +1,62 @@
1
+ import { randomUUID } from "node:crypto"
2
+ import { beforeAll, describe, expect, test } from "vitest"
3
+ import { World } from "../ebely/generated"
4
+
5
+ describe("posts", () => {
6
+ const world = new World()
7
+ const user1 = world.createUser()
8
+ const user2 = world.createUser()
9
+
10
+ beforeAll(async () => {
11
+ await world.clearDatabase()
12
+ await user1.fullRegister({ email: "a@x.com", password: "password" })
13
+ await user1.fullRegister({ email: "b@x.com", password: "password" })
14
+ })
15
+
16
+ test("user1 создаёт пост", async () => {
17
+ const created = await user1.posts.create({
18
+ body: { title: "Hello", content: "World" },
19
+ })
20
+ created.assert(200)
21
+ })
22
+
23
+ test("user1 читает созданный пост", async () => {
24
+ const created = await user1.posts.create({
25
+ body: { title: "Hello", content: "World" },
26
+ })
27
+ created.assert(200)
28
+
29
+ const lastPostId = user1.get({ key: "lastPostId" })!
30
+ const res = await user1.posts.get({ path: { id: lastPostId } })
31
+ res.assert(200, { id: lastPostId, title: created.body.title })
32
+ })
33
+
34
+ test("несуществующий пост → 404", async () => {
35
+ const missing = await user1.posts.get({ path: { id: "does-not-exist" } })
36
+ missing.assert(404 as any)
37
+ })
38
+
39
+ test("изоляция: у каждого пользователя свой lastPostId", async () => {
40
+ const testContent = randomUUID()
41
+ const created2 = await user2.posts.create({
42
+ body: { title: "Hello", content: testContent },
43
+ })
44
+ created2.assert(200, { content: testContent })
45
+
46
+ const p1 = user1.get({ key: "lastPostId" })!
47
+ const p2 = user2.get({ key: "lastPostId" })!
48
+
49
+ // Тот же хук, но ctx = store user2 → у каждого свой lastPostId.
50
+ expect(p1).toBeTruthy()
51
+ expect(p2).toBeTruthy()
52
+ expect(p1).not.toBe(p2)
53
+ })
54
+ })
55
+
56
+ // // На будущее.
57
+ // const wsAnswer = await user1.ws.getAndClear({
58
+ // topic: 'created.post',
59
+ // // count: 2 // Если ожидаем два сообщения. Если ничего не указано, то по умолчанию ждем одно сообщение.
60
+ // // под капотом мы постоянно ожидаем ответы. Как только ответ дан, мы сразу же возвращаемся сюда.
61
+ // })
62
+ // wsAnswer.assert({ id: lastPostId, title: "Hello", })
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["ebely", "tests"]
4
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ebely",
3
3
  "license": "MIT",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
@@ -18,7 +18,10 @@
18
18
  "files": [
19
19
  "dist",
20
20
  "bin",
21
- "skills"
21
+ "skills",
22
+ "clone/tests/ebely",
23
+ "clone/tests/tests",
24
+ "clone/tests/*.json"
22
25
  ],
23
26
  "sideEffects": false,
24
27
  "devDependencies": {