@voidhash/mimic-effect 0.0.3 → 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.
@@ -21,84 +21,6 @@ const TestSchema = Primitive.Struct({
21
21
  // =============================================================================
22
22
 
23
23
  describe("MimicServer", () => {
24
- describe("layer", () => {
25
- it("should create a layer with default auth and storage", async () => {
26
- const testLayer = MimicServer.layer({
27
- basePath: "/mimic/test",
28
- schema: TestSchema,
29
- });
30
-
31
- // Verify the layer provides the expected services
32
- const result = await Effect.runPromise(
33
- Effect.gen(function* () {
34
- const handler = yield* MimicServer.MimicWebSocketHandler;
35
- return typeof handler === "function";
36
- }).pipe(Effect.provide(testLayer))
37
- );
38
-
39
- expect(result).toBe(true);
40
- });
41
-
42
- it("should allow custom auth layer to be provided", async () => {
43
- let authCalled = false;
44
-
45
- const customAuthLayer = MimicAuthService.layer({
46
- authHandler: (token) => {
47
- authCalled = true;
48
- return { success: true, userId: token };
49
- },
50
- });
51
-
52
- const testLayer = MimicServer.layer({
53
- basePath: "/mimic/test",
54
- schema: TestSchema,
55
- }).pipe(Layer.provideMerge(customAuthLayer));
56
-
57
- // Verify the layer compiles with custom auth
58
- const result = await Effect.runPromise(
59
- Effect.gen(function* () {
60
- const handler = yield* MimicServer.MimicWebSocketHandler;
61
- return typeof handler === "function";
62
- }).pipe(Effect.provide(testLayer))
63
- );
64
-
65
- expect(result).toBe(true);
66
- });
67
-
68
- it("should support maxTransactionHistory option", async () => {
69
- const testLayer = MimicServer.layer({
70
- basePath: "/mimic/test",
71
- schema: TestSchema,
72
- maxTransactionHistory: 500,
73
- });
74
-
75
- const result = await Effect.runPromise(
76
- Effect.gen(function* () {
77
- const handler = yield* MimicServer.MimicWebSocketHandler;
78
- return typeof handler === "function";
79
- }).pipe(Effect.provide(testLayer))
80
- );
81
-
82
- expect(result).toBe(true);
83
- });
84
- });
85
-
86
- describe("handlerLayer", () => {
87
- it("should create a layer that provides MimicWebSocketHandler", async () => {
88
- const testLayer = MimicServer.handlerLayer({
89
- schema: TestSchema,
90
- });
91
-
92
- const result = await Effect.runPromise(
93
- Effect.gen(function* () {
94
- const handler = yield* MimicServer.MimicWebSocketHandler;
95
- return typeof handler === "function";
96
- }).pipe(Effect.provide(testLayer))
97
- );
98
-
99
- expect(result).toBe(true);
100
- });
101
- });
102
24
 
103
25
  describe("documentManagerLayer", () => {
104
26
  it("should create a layer that provides DocumentManager", async () => {
@@ -187,14 +109,6 @@ describe("MimicServer", () => {
187
109
  });
188
110
  });
189
111
 
190
- describe("MimicWebSocketHandler tag", () => {
191
- it("should have the correct tag identifier", () => {
192
- expect(MimicServer.MimicWebSocketHandler.key).toBe(
193
- "@voidhash/mimic-server-effect/MimicWebSocketHandler"
194
- );
195
- });
196
- });
197
-
198
112
  describe("MimicLayerOptions", () => {
199
113
  it("should accept all optional properties", () => {
200
114
  // TypeScript compile-time check - if this compiles, the interface is correct
@@ -229,82 +143,6 @@ describe("MimicServer", () => {
229
143
  }),
230
144
  });
231
145
 
232
- describe("layer", () => {
233
- it("should accept presence option", async () => {
234
- const testLayer = MimicServer.layer({
235
- basePath: "/mimic/test",
236
- schema: TestSchema,
237
- presence: CursorPresence,
238
- });
239
-
240
- const result = await Effect.runPromise(
241
- Effect.gen(function* () {
242
- const handler = yield* MimicServer.MimicWebSocketHandler;
243
- return typeof handler === "function";
244
- }).pipe(Effect.provide(testLayer))
245
- );
246
-
247
- expect(result).toBe(true);
248
- });
249
-
250
- it("should work with presence and custom auth", async () => {
251
- const customAuthLayer = MimicAuthService.layer({
252
- authHandler: (token) => ({ success: true, userId: token }),
253
- });
254
-
255
- const testLayer = MimicServer.layer({
256
- basePath: "/mimic/test",
257
- schema: TestSchema,
258
- presence: CursorPresence,
259
- }).pipe(Layer.provideMerge(customAuthLayer));
260
-
261
- const result = await Effect.runPromise(
262
- Effect.gen(function* () {
263
- const handler = yield* MimicServer.MimicWebSocketHandler;
264
- return typeof handler === "function";
265
- }).pipe(Effect.provide(testLayer))
266
- );
267
-
268
- expect(result).toBe(true);
269
- });
270
-
271
- it("should work with presence and maxTransactionHistory", async () => {
272
- const testLayer = MimicServer.layer({
273
- basePath: "/mimic/test",
274
- schema: TestSchema,
275
- presence: CursorPresence,
276
- maxTransactionHistory: 500,
277
- });
278
-
279
- const result = await Effect.runPromise(
280
- Effect.gen(function* () {
281
- const handler = yield* MimicServer.MimicWebSocketHandler;
282
- return typeof handler === "function";
283
- }).pipe(Effect.provide(testLayer))
284
- );
285
-
286
- expect(result).toBe(true);
287
- });
288
- });
289
-
290
- describe("handlerLayer", () => {
291
- it("should accept presence option", async () => {
292
- const testLayer = MimicServer.handlerLayer({
293
- schema: TestSchema,
294
- presence: CursorPresence,
295
- });
296
-
297
- const result = await Effect.runPromise(
298
- Effect.gen(function* () {
299
- const handler = yield* MimicServer.MimicWebSocketHandler;
300
- return typeof handler === "function";
301
- }).pipe(Effect.provide(testLayer))
302
- );
303
-
304
- expect(result).toBe(true);
305
- });
306
- });
307
-
308
146
  describe("documentManagerLayer", () => {
309
147
  it("should accept presence option", async () => {
310
148
  const testLayer = MimicServer.documentManagerLayer({
@@ -382,4 +220,59 @@ describe("MimicServer", () => {
382
220
  });
383
221
  });
384
222
  });
223
+
224
+ describe("initial state support", () => {
225
+ describe("layerHttpLayerRouter", () => {
226
+ it("should accept initial option", () => {
227
+ const routeLayer = MimicServer.layerHttpLayerRouter({
228
+ basePath: "/mimic/test",
229
+ schema: TestSchema,
230
+ initial: { title: "My Document", completed: true },
231
+ });
232
+
233
+ expect(routeLayer).toBeDefined();
234
+ });
235
+
236
+ it("should work with initial and all other options", () => {
237
+ const customAuthLayer = MimicAuthService.layer({
238
+ authHandler: (token) => ({ success: true, userId: token }),
239
+ });
240
+
241
+ const routeLayer = MimicServer.layerHttpLayerRouter({
242
+ basePath: "/mimic/test",
243
+ schema: TestSchema,
244
+ initial: { title: "Full Options" },
245
+ maxTransactionHistory: 500,
246
+ authLayer: customAuthLayer,
247
+ storageLayer: InMemoryDataStorage.layer,
248
+ });
249
+
250
+ expect(routeLayer).toBeDefined();
251
+ });
252
+ });
253
+
254
+ describe("MimicLayerOptions with initial", () => {
255
+ it("should accept initial in options", () => {
256
+ const options: MimicServer.MimicLayerOptions<typeof TestSchema> = {
257
+ schema: TestSchema,
258
+ basePath: "/custom/path",
259
+ initial: { title: "Initial State", completed: true },
260
+ };
261
+
262
+ expect(options.schema).toBe(TestSchema);
263
+ expect(options.basePath).toBe("/custom/path");
264
+ expect(options.initial).toEqual({ title: "Initial State", completed: true });
265
+ });
266
+
267
+ it("should allow omitting optional fields in initial (type safety)", () => {
268
+ // This test verifies that TypeScript allows omitting fields with defaults
269
+ const options: MimicServer.MimicLayerOptions<typeof TestSchema> = {
270
+ schema: TestSchema,
271
+ initial: { title: "Only Title" }, // completed is optional because it has a default
272
+ };
273
+
274
+ expect(options.initial).toEqual({ title: "Only Title" });
275
+ });
276
+ });
277
+ });
385
278
  });