@gencow/core 0.1.24 → 0.1.25
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/dist/crud.d.ts +2 -2
- package/dist/crud.js +225 -208
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/reactive.js +10 -3
- package/dist/retry.js +1 -1
- package/dist/rls-db.d.ts +2 -2
- package/dist/rls-db.js +1 -5
- package/dist/scheduler.d.ts +2 -0
- package/dist/scheduler.js +16 -6
- package/dist/server.d.ts +0 -1
- package/dist/server.js +0 -1
- package/dist/storage.js +29 -22
- package/dist/v.d.ts +2 -2
- package/dist/workflow.js +4 -11
- package/dist/workflows-api.js +5 -12
- package/package.json +46 -42
- package/src/__tests__/auth.test.ts +90 -86
- package/src/__tests__/crons.test.ts +69 -67
- package/src/__tests__/crud-codegen-integration.test.ts +164 -170
- package/src/__tests__/crud-owner-rls.test.ts +308 -301
- package/src/__tests__/crud.test.ts +694 -711
- package/src/__tests__/dist-exports.test.ts +120 -120
- package/src/__tests__/fixtures/basic/auth.ts +16 -16
- package/src/__tests__/fixtures/basic/drizzle.config.ts +1 -4
- package/src/__tests__/fixtures/basic/index.ts +1 -1
- package/src/__tests__/fixtures/basic/schema.ts +1 -1
- package/src/__tests__/fixtures/basic/tasks.ts +4 -4
- package/src/__tests__/fixtures/common/auth-schema.ts +38 -34
- package/src/__tests__/helpers/basic-rls-fixture.ts +80 -78
- package/src/__tests__/helpers/pglite-migrations.ts +2 -5
- package/src/__tests__/helpers/pglite-rls-session.ts +13 -16
- package/src/__tests__/helpers/seed-like-fill.ts +50 -44
- package/src/__tests__/helpers/test-gencow-ctx-rls.ts +4 -7
- package/src/__tests__/httpaction.test.ts +91 -91
- package/src/__tests__/image-optimization.test.ts +570 -574
- package/src/__tests__/load.test.ts +321 -308
- package/src/__tests__/network-sim.test.ts +238 -215
- package/src/__tests__/reactive.test.ts +380 -358
- package/src/__tests__/retry.test.ts +99 -84
- package/src/__tests__/rls-crud-basic.test.ts +172 -245
- package/src/__tests__/rls-crud-no-owner-rls-pglite.test.ts +81 -81
- package/src/__tests__/rls-custom-mutation-handlers.test.ts +47 -94
- package/src/__tests__/rls-custom-query-handlers.test.ts +92 -92
- package/src/__tests__/rls-db-leased-connection.test.ts +2 -6
- package/src/__tests__/rls-session-and-policies.test.ts +181 -199
- package/src/__tests__/scheduler-durable-v2.test.ts +199 -181
- package/src/__tests__/scheduler-durable.test.ts +117 -117
- package/src/__tests__/scheduler-exec.test.ts +258 -246
- package/src/__tests__/scheduler.test.ts +129 -111
- package/src/__tests__/storage.test.ts +282 -269
- package/src/__tests__/tsconfig.json +6 -6
- package/src/__tests__/validator.test.ts +236 -232
- package/src/__tests__/workflow.test.ts +309 -286
- package/src/__tests__/ws-integration.test.ts +223 -218
- package/src/__tests__/ws-scale.test.ts +168 -159
- package/src/auth-config.ts +18 -18
- package/src/auth.ts +106 -106
- package/src/crons.ts +77 -77
- package/src/crud.ts +523 -479
- package/src/index.ts +69 -5
- package/src/reactive.ts +357 -331
- package/src/retry.ts +51 -54
- package/src/rls-db.ts +195 -205
- package/src/rls.ts +33 -36
- package/src/scheduler.ts +237 -211
- package/src/server.ts +0 -1
- package/src/storage.ts +632 -593
- package/src/v.ts +119 -114
- package/src/workflow-types.ts +67 -70
- package/src/workflow.ts +99 -116
- package/src/workflows-api.ts +231 -241
- package/src/db.ts +0 -18
|
@@ -1,98 +1,113 @@
|
|
|
1
1
|
import { describe, test, expect, mock } from "bun:test";
|
|
2
|
-
import { withRetry } from "../retry";
|
|
2
|
+
import { withRetry } from "../retry.js";
|
|
3
3
|
|
|
4
4
|
describe("withRetry", () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
test("성공 시 즉시 반환", async () => {
|
|
6
|
+
const result = await withRetry(async () => "success");
|
|
7
|
+
expect(result).toBe("success");
|
|
8
|
+
});
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
test("첫 시도 실패 후 재시도 성공", async () => {
|
|
11
|
+
let attempt = 0;
|
|
12
|
+
const result = await withRetry(
|
|
13
|
+
async () => {
|
|
14
|
+
attempt++;
|
|
15
|
+
if (attempt < 2) throw new Error("fail");
|
|
16
|
+
return "recovered";
|
|
17
|
+
},
|
|
18
|
+
{ initialBackoffMs: 10 },
|
|
19
|
+
);
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
expect(result).toBe("recovered");
|
|
22
|
+
expect(attempt).toBe(2);
|
|
23
|
+
});
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
test("maxAttempts 초과 시 마지막 에러 throw", async () => {
|
|
26
|
+
let attempt = 0;
|
|
27
|
+
try {
|
|
28
|
+
await withRetry(
|
|
29
|
+
async () => {
|
|
30
|
+
attempt++;
|
|
31
|
+
throw new Error(`fail-${attempt}`);
|
|
32
|
+
},
|
|
33
|
+
{ maxAttempts: 3, initialBackoffMs: 10 },
|
|
34
|
+
);
|
|
35
|
+
expect(true).toBe(false); // 여기에 도달하면 안됨
|
|
36
|
+
} catch (err: unknown) {
|
|
37
|
+
expect((err as Error).message).toBe("fail-3");
|
|
38
|
+
expect(attempt).toBe(3);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
test("shouldRetry가 false 반환 시 즉시 throw", async () => {
|
|
43
|
+
let attempt = 0;
|
|
44
|
+
try {
|
|
45
|
+
await withRetry(
|
|
46
|
+
async () => {
|
|
47
|
+
attempt++;
|
|
48
|
+
throw new Error("non-retryable");
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
maxAttempts: 5,
|
|
52
|
+
initialBackoffMs: 10,
|
|
53
|
+
shouldRetry: (err) => (err as Error).message !== "non-retryable",
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
} catch (err: unknown) {
|
|
57
|
+
expect((err as Error).message).toBe("non-retryable");
|
|
58
|
+
expect(attempt).toBe(1); // 재시도 없이 즉시 실패
|
|
59
|
+
}
|
|
60
|
+
});
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
test("onRetry 콜백 호출", async () => {
|
|
63
|
+
let attempt = 0;
|
|
64
|
+
const retries: number[] = [];
|
|
56
65
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
await withRetry(
|
|
67
|
+
async () => {
|
|
68
|
+
attempt++;
|
|
69
|
+
if (attempt < 3) throw new Error("fail");
|
|
70
|
+
return "ok";
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
initialBackoffMs: 10,
|
|
74
|
+
onRetry: (_err, attemptNum, _delay) => {
|
|
75
|
+
retries.push(attemptNum);
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
);
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
|
|
80
|
+
expect(retries).toEqual([1, 2]);
|
|
81
|
+
});
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
test("maxAttempts < 1이면 에러", async () => {
|
|
84
|
+
try {
|
|
85
|
+
await withRetry(async () => "ok", { maxAttempts: 0 });
|
|
86
|
+
expect(true).toBe(false);
|
|
87
|
+
} catch (err: unknown) {
|
|
88
|
+
expect((err as Error).message).toContain("maxAttempts must be >= 1");
|
|
89
|
+
}
|
|
90
|
+
});
|
|
79
91
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
test("maxAttempts = 1이면 재시도 없이 즉시 throw", async () => {
|
|
93
|
+
let attempt = 0;
|
|
94
|
+
try {
|
|
95
|
+
await withRetry(
|
|
96
|
+
async () => {
|
|
97
|
+
attempt++;
|
|
98
|
+
throw new Error("once");
|
|
99
|
+
},
|
|
100
|
+
{ maxAttempts: 1 },
|
|
101
|
+
);
|
|
102
|
+
} catch (err: unknown) {
|
|
103
|
+
expect((err as Error).message).toBe("once");
|
|
104
|
+
expect(attempt).toBe(1);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
92
107
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
108
|
+
test("비동기 함수 결과 타입 보존", async () => {
|
|
109
|
+
const result = await withRetry(async () => ({ id: 1, name: "test" }));
|
|
110
|
+
expect(result.id).toBe(1);
|
|
111
|
+
expect(result.name).toBe("test");
|
|
112
|
+
});
|
|
98
113
|
});
|