@voidhash/mimic-effect 1.0.0-beta.16 → 1.0.0-beta.18
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/ColdStorage.cjs +1 -1
- package/dist/ColdStorage.d.cts +2 -2
- package/dist/ColdStorage.d.cts.map +1 -1
- package/dist/ColdStorage.d.mts +2 -2
- package/dist/ColdStorage.d.mts.map +1 -1
- package/dist/ColdStorage.mjs +2 -2
- package/dist/ColdStorage.mjs.map +1 -1
- package/dist/DocumentInstance.cjs +13 -13
- package/dist/DocumentInstance.mjs +13 -13
- package/dist/DocumentInstance.mjs.map +1 -1
- package/dist/Errors.d.cts +8 -8
- package/dist/Errors.d.cts.map +1 -1
- package/dist/Errors.d.mts +8 -8
- package/dist/Errors.d.mts.map +1 -1
- package/dist/HotStorage.cjs +1 -1
- package/dist/HotStorage.d.cts +2 -2
- package/dist/HotStorage.d.mts +2 -2
- package/dist/HotStorage.mjs +2 -2
- package/dist/HotStorage.mjs.map +1 -1
- package/dist/Metrics.cjs +6 -6
- package/dist/Metrics.d.cts +21 -23
- package/dist/Metrics.d.cts.map +1 -1
- package/dist/Metrics.d.mts +21 -23
- package/dist/Metrics.d.mts.map +1 -1
- package/dist/Metrics.mjs +7 -7
- package/dist/Metrics.mjs.map +1 -1
- package/dist/MimicAuthService.cjs +1 -1
- package/dist/MimicAuthService.d.cts +2 -2
- package/dist/MimicAuthService.d.cts.map +1 -1
- package/dist/MimicAuthService.d.mts +2 -2
- package/dist/MimicAuthService.d.mts.map +1 -1
- package/dist/MimicAuthService.mjs +2 -2
- package/dist/MimicAuthService.mjs.map +1 -1
- package/dist/MimicClusterServerEngine.cjs +38 -41
- package/dist/MimicClusterServerEngine.d.cts +1 -1
- package/dist/MimicClusterServerEngine.d.mts +1 -1
- package/dist/MimicClusterServerEngine.mjs +31 -34
- package/dist/MimicClusterServerEngine.mjs.map +1 -1
- package/dist/MimicServer.cjs +23 -23
- package/dist/MimicServer.d.cts +3 -3
- package/dist/MimicServer.d.cts.map +1 -1
- package/dist/MimicServer.d.mts +3 -3
- package/dist/MimicServer.d.mts.map +1 -1
- package/dist/MimicServer.mjs +22 -22
- package/dist/MimicServer.mjs.map +1 -1
- package/dist/MimicServerEngine.cjs +13 -13
- package/dist/MimicServerEngine.d.cts +2 -2
- package/dist/MimicServerEngine.d.mts +2 -2
- package/dist/MimicServerEngine.mjs +14 -14
- package/dist/MimicServerEngine.mjs.map +1 -1
- package/dist/PresenceManager.cjs +4 -4
- package/dist/PresenceManager.d.cts +2 -2
- package/dist/PresenceManager.d.mts +2 -2
- package/dist/PresenceManager.mjs +5 -5
- package/dist/PresenceManager.mjs.map +1 -1
- package/dist/Types.d.cts +1 -1
- package/dist/Types.d.mts +1 -1
- package/dist/testing/ColdStorageTestSuite.cjs +3 -3
- package/dist/testing/ColdStorageTestSuite.mjs +3 -3
- package/dist/testing/ColdStorageTestSuite.mjs.map +1 -1
- package/dist/testing/HotStorageTestSuite.cjs +13 -13
- package/dist/testing/HotStorageTestSuite.mjs +13 -13
- package/dist/testing/HotStorageTestSuite.mjs.map +1 -1
- package/dist/testing/StorageIntegrationTestSuite.cjs +3 -3
- package/dist/testing/StorageIntegrationTestSuite.mjs +3 -3
- package/dist/testing/StorageIntegrationTestSuite.mjs.map +1 -1
- package/dist/testing/types.d.cts +3 -3
- package/dist/testing/types.d.cts.map +1 -1
- package/dist/testing/types.d.mts +1 -1
- package/dist/testing/types.d.mts.map +1 -1
- package/package.json +17 -21
- package/src/ColdStorage.ts +4 -5
- package/src/DocumentInstance.ts +13 -13
- package/src/HotStorage.ts +3 -3
- package/src/Metrics.ts +22 -16
- package/src/MimicAuthService.ts +3 -3
- package/src/MimicClusterServerEngine.ts +35 -35
- package/src/MimicServer.ts +26 -30
- package/src/MimicServerEngine.ts +15 -15
- package/src/PresenceManager.ts +6 -6
- package/src/Types.ts +1 -1
- package/src/testing/ColdStorageTestSuite.ts +3 -3
- package/src/testing/HotStorageTestSuite.ts +17 -17
- package/src/testing/StorageIntegrationTestSuite.ts +3 -3
- package/.turbo/turbo-build.log +0 -154
- package/tests/ColdStorage.test.ts +0 -24
- package/tests/DocumentInstance.test.ts +0 -669
- package/tests/HotStorage.test.ts +0 -24
- package/tests/MimicAuthService.test.ts +0 -153
- package/tests/MimicClusterServerEngine.test.ts +0 -587
- package/tests/MimicServer.test.ts +0 -142
- package/tests/MimicServerEngine.test.ts +0 -547
- package/tests/PresenceManager.test.ts +0 -380
- package/tests/Protocol.test.ts +0 -190
- package/tests/StorageIntegration.test.ts +0 -259
- package/tsconfig.build.json +0 -24
- package/tsconfig.json +0 -8
- package/tsdown.config.ts +0 -18
- package/vitest.mts +0 -11
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { Effect, Layer } from "effect";
|
|
3
|
-
import { StorageIntegrationTestSuite } from "../src/testing/StorageIntegrationTestSuite";
|
|
4
|
-
import { FailingStorage } from "../src/testing/FailingStorage";
|
|
5
|
-
import { ColdStorage, ColdStorageTag } from "../src/ColdStorage";
|
|
6
|
-
import { HotStorage, HotStorageTag } from "../src/HotStorage";
|
|
7
|
-
|
|
8
|
-
// =============================================================================
|
|
9
|
-
// Storage Integration Tests
|
|
10
|
-
// =============================================================================
|
|
11
|
-
|
|
12
|
-
describe("Storage Integration", () => {
|
|
13
|
-
const layer = Layer.mergeAll(
|
|
14
|
-
ColdStorage.InMemory.make(),
|
|
15
|
-
HotStorage.InMemory.make()
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
for (const test of StorageIntegrationTestSuite.makeTests()) {
|
|
19
|
-
it(test.name, () =>
|
|
20
|
-
Effect.runPromise(test.run.pipe(Effect.provide(layer)))
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// =============================================================================
|
|
26
|
-
// Failure Scenario Tests
|
|
27
|
-
// =============================================================================
|
|
28
|
-
|
|
29
|
-
describe("Storage Failure Scenarios", () => {
|
|
30
|
-
describe("ColdStorage Failures", () => {
|
|
31
|
-
it("load failure propagates error", async () => {
|
|
32
|
-
const failingLayer = Layer.mergeAll(
|
|
33
|
-
FailingStorage.makeColdStorage({ failLoad: true }),
|
|
34
|
-
HotStorage.InMemory.make()
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const result = await Effect.runPromise(
|
|
38
|
-
Effect.gen(function* () {
|
|
39
|
-
const cold = yield* ColdStorageTag;
|
|
40
|
-
return yield* Effect.either(cold.load("test-doc"));
|
|
41
|
-
}).pipe(Effect.provide(failingLayer))
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
expect(result._tag).toBe("Left");
|
|
45
|
-
if (result._tag === "Left") {
|
|
46
|
-
expect(result.left._tag).toBe("ColdStorageError");
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("save failure propagates error", async () => {
|
|
51
|
-
const failingLayer = Layer.mergeAll(
|
|
52
|
-
FailingStorage.makeColdStorage({ failSave: true }),
|
|
53
|
-
HotStorage.InMemory.make()
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const result = await Effect.runPromise(
|
|
57
|
-
Effect.gen(function* () {
|
|
58
|
-
const cold = yield* ColdStorageTag;
|
|
59
|
-
return yield* Effect.either(
|
|
60
|
-
cold.save("test-doc", {
|
|
61
|
-
state: { data: "test" },
|
|
62
|
-
version: 1,
|
|
63
|
-
schemaVersion: 1,
|
|
64
|
-
savedAt: Date.now(),
|
|
65
|
-
})
|
|
66
|
-
);
|
|
67
|
-
}).pipe(Effect.provide(failingLayer))
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
expect(result._tag).toBe("Left");
|
|
71
|
-
if (result._tag === "Left") {
|
|
72
|
-
expect(result.left._tag).toBe("ColdStorageError");
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("failAfterN allows first N operations then fails", async () => {
|
|
77
|
-
const failingLayer = Layer.mergeAll(
|
|
78
|
-
FailingStorage.makeColdStorage({ failAfterN: 2, failLoad: true }),
|
|
79
|
-
HotStorage.InMemory.make()
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const results = await Effect.runPromise(
|
|
83
|
-
Effect.gen(function* () {
|
|
84
|
-
const cold = yield* ColdStorageTag;
|
|
85
|
-
|
|
86
|
-
// First 2 operations succeed
|
|
87
|
-
const r1 = yield* Effect.either(cold.load("doc-1"));
|
|
88
|
-
const r2 = yield* Effect.either(cold.load("doc-2"));
|
|
89
|
-
|
|
90
|
-
// Third operation fails
|
|
91
|
-
const r3 = yield* Effect.either(cold.load("doc-3"));
|
|
92
|
-
|
|
93
|
-
return { r1, r2, r3 };
|
|
94
|
-
}).pipe(Effect.provide(failingLayer))
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
expect(results.r1._tag).toBe("Right");
|
|
98
|
-
expect(results.r2._tag).toBe("Right");
|
|
99
|
-
expect(results.r3._tag).toBe("Left");
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("HotStorage Failures", () => {
|
|
104
|
-
it("append failure propagates error", async () => {
|
|
105
|
-
const failingLayer = Layer.mergeAll(
|
|
106
|
-
ColdStorage.InMemory.make(),
|
|
107
|
-
FailingStorage.makeHotStorage({ failAppend: true })
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const result = await Effect.runPromise(
|
|
111
|
-
Effect.gen(function* () {
|
|
112
|
-
const hot = yield* HotStorageTag;
|
|
113
|
-
return yield* Effect.either(
|
|
114
|
-
hot.append("test-doc", {
|
|
115
|
-
transaction: { id: "tx-1", ops: [], timestamp: Date.now() },
|
|
116
|
-
version: 1,
|
|
117
|
-
timestamp: Date.now(),
|
|
118
|
-
})
|
|
119
|
-
);
|
|
120
|
-
}).pipe(Effect.provide(failingLayer))
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
expect(result._tag).toBe("Left");
|
|
124
|
-
if (result._tag === "Left") {
|
|
125
|
-
expect(result.left._tag).toBe("HotStorageError");
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("getEntries failure propagates error", async () => {
|
|
130
|
-
const failingLayer = Layer.mergeAll(
|
|
131
|
-
ColdStorage.InMemory.make(),
|
|
132
|
-
FailingStorage.makeHotStorage({ failGetEntries: true })
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
const result = await Effect.runPromise(
|
|
136
|
-
Effect.gen(function* () {
|
|
137
|
-
const hot = yield* HotStorageTag;
|
|
138
|
-
return yield* Effect.either(hot.getEntries("test-doc", 0));
|
|
139
|
-
}).pipe(Effect.provide(failingLayer))
|
|
140
|
-
);
|
|
141
|
-
|
|
142
|
-
expect(result._tag).toBe("Left");
|
|
143
|
-
if (result._tag === "Left") {
|
|
144
|
-
expect(result.left._tag).toBe("HotStorageError");
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("truncate failure propagates error", async () => {
|
|
149
|
-
const failingLayer = Layer.mergeAll(
|
|
150
|
-
ColdStorage.InMemory.make(),
|
|
151
|
-
FailingStorage.makeHotStorage({ failTruncate: true })
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
const result = await Effect.runPromise(
|
|
155
|
-
Effect.gen(function* () {
|
|
156
|
-
const hot = yield* HotStorageTag;
|
|
157
|
-
return yield* Effect.either(hot.truncate("test-doc", 5));
|
|
158
|
-
}).pipe(Effect.provide(failingLayer))
|
|
159
|
-
);
|
|
160
|
-
|
|
161
|
-
expect(result._tag).toBe("Left");
|
|
162
|
-
if (result._tag === "Left") {
|
|
163
|
-
expect(result.left._tag).toBe("HotStorageError");
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("failAfterN allows first N operations then fails", async () => {
|
|
168
|
-
const failingLayer = Layer.mergeAll(
|
|
169
|
-
ColdStorage.InMemory.make(),
|
|
170
|
-
FailingStorage.makeHotStorage({ failAfterN: 3, failAppend: true })
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const results = await Effect.runPromise(
|
|
174
|
-
Effect.gen(function* () {
|
|
175
|
-
const hot = yield* HotStorageTag;
|
|
176
|
-
|
|
177
|
-
const makeEntry = (v: number) => ({
|
|
178
|
-
transaction: { id: `tx-${v}`, ops: [], timestamp: Date.now() },
|
|
179
|
-
version: v,
|
|
180
|
-
timestamp: Date.now(),
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
// First 3 appends succeed
|
|
184
|
-
const r1 = yield* Effect.either(hot.append("doc", makeEntry(1)));
|
|
185
|
-
const r2 = yield* Effect.either(hot.append("doc", makeEntry(2)));
|
|
186
|
-
const r3 = yield* Effect.either(hot.append("doc", makeEntry(3)));
|
|
187
|
-
|
|
188
|
-
// Fourth append fails
|
|
189
|
-
const r4 = yield* Effect.either(hot.append("doc", makeEntry(4)));
|
|
190
|
-
|
|
191
|
-
return { r1, r2, r3, r4 };
|
|
192
|
-
}).pipe(Effect.provide(failingLayer))
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
expect(results.r1._tag).toBe("Right");
|
|
196
|
-
expect(results.r2._tag).toBe("Right");
|
|
197
|
-
expect(results.r3._tag).toBe("Right");
|
|
198
|
-
expect(results.r4._tag).toBe("Left");
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe("Custom Error Messages", () => {
|
|
203
|
-
it("ColdStorage uses custom error message", async () => {
|
|
204
|
-
const failingLayer = Layer.mergeAll(
|
|
205
|
-
FailingStorage.makeColdStorage({
|
|
206
|
-
failLoad: true,
|
|
207
|
-
errorMessage: "Database connection timeout",
|
|
208
|
-
}),
|
|
209
|
-
HotStorage.InMemory.make()
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
const result = await Effect.runPromise(
|
|
213
|
-
Effect.gen(function* () {
|
|
214
|
-
const cold = yield* ColdStorageTag;
|
|
215
|
-
return yield* Effect.either(cold.load("test-doc"));
|
|
216
|
-
}).pipe(Effect.provide(failingLayer))
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
expect(result._tag).toBe("Left");
|
|
220
|
-
if (result._tag === "Left") {
|
|
221
|
-
expect(result.left.cause).toBeInstanceOf(Error);
|
|
222
|
-
expect((result.left.cause as Error).message).toBe(
|
|
223
|
-
"Database connection timeout"
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("HotStorage uses custom error message", async () => {
|
|
229
|
-
const failingLayer = Layer.mergeAll(
|
|
230
|
-
ColdStorage.InMemory.make(),
|
|
231
|
-
FailingStorage.makeHotStorage({
|
|
232
|
-
failAppend: true,
|
|
233
|
-
errorMessage: "Redis cluster unavailable",
|
|
234
|
-
})
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
const result = await Effect.runPromise(
|
|
238
|
-
Effect.gen(function* () {
|
|
239
|
-
const hot = yield* HotStorageTag;
|
|
240
|
-
return yield* Effect.either(
|
|
241
|
-
hot.append("test-doc", {
|
|
242
|
-
transaction: { id: "tx", ops: [], timestamp: Date.now() },
|
|
243
|
-
version: 1,
|
|
244
|
-
timestamp: Date.now(),
|
|
245
|
-
})
|
|
246
|
-
);
|
|
247
|
-
}).pipe(Effect.provide(failingLayer))
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
expect(result._tag).toBe("Left");
|
|
251
|
-
if (result._tag === "Left") {
|
|
252
|
-
expect(result.left.cause).toBeInstanceOf(Error);
|
|
253
|
-
expect((result.left.cause as Error).message).toBe(
|
|
254
|
-
"Redis cluster unavailable"
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
});
|
package/tsconfig.build.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "Preserve",
|
|
4
|
-
"lib": ["es2022", "dom", "dom.iterable"],
|
|
5
|
-
"target": "es2022",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"declarationDir": "dist",
|
|
9
|
-
"outDir": "./dist",
|
|
10
|
-
"strict": true,
|
|
11
|
-
"strictNullChecks": true,
|
|
12
|
-
"noUnusedLocals": false,
|
|
13
|
-
"noUnusedParameters": true,
|
|
14
|
-
"noImplicitReturns": true,
|
|
15
|
-
"noFallthroughCasesInSwitch": true,
|
|
16
|
-
"noUncheckedIndexedAccess": true,
|
|
17
|
-
"esModuleInterop": true,
|
|
18
|
-
"skipLibCheck": true,
|
|
19
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
20
|
-
"noImplicitOverride": true
|
|
21
|
-
},
|
|
22
|
-
"include": ["src"],
|
|
23
|
-
"exclude": ["test", "**/*.test.ts", "**/*.test.tsx", "__tests__"]
|
|
24
|
-
}
|
package/tsconfig.json
DELETED
package/tsdown.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsdown";
|
|
2
|
-
|
|
3
|
-
export const input = ["./src/index.ts", "./src/testing/index.ts"];
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
target: ["es2017"],
|
|
7
|
-
entry: input,
|
|
8
|
-
dts: {
|
|
9
|
-
sourcemap: true,
|
|
10
|
-
tsconfig: "./tsconfig.build.json",
|
|
11
|
-
},
|
|
12
|
-
unbundle: true,
|
|
13
|
-
format: ["cjs", "esm"],
|
|
14
|
-
outExtensions: (ctx) => ({
|
|
15
|
-
dts: ctx.format === "cjs" ? ".d.cts" : ".d.mts",
|
|
16
|
-
js: ctx.format === "cjs" ? ".cjs" : ".mjs",
|
|
17
|
-
}),
|
|
18
|
-
});
|
package/vitest.mts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import tsconfigPaths from "vite-tsconfig-paths";
|
|
2
|
-
import { defineConfig } from "vitest/config";
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
plugins: [tsconfigPaths()],
|
|
6
|
-
test: {
|
|
7
|
-
include: ["./**/*.test.ts"],
|
|
8
|
-
exclude: ["./node_modules/**"],
|
|
9
|
-
reporters: ["verbose"],
|
|
10
|
-
},
|
|
11
|
-
});
|