@voidhash/mimic-effect 0.0.9 → 1.0.0-beta.2

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.
Files changed (227) hide show
  1. package/.turbo/turbo-build.log +136 -90
  2. package/README.md +385 -0
  3. package/dist/ColdStorage.cjs +60 -0
  4. package/dist/ColdStorage.d.cts +53 -0
  5. package/dist/ColdStorage.d.cts.map +1 -0
  6. package/dist/ColdStorage.d.mts +53 -0
  7. package/dist/ColdStorage.d.mts.map +1 -0
  8. package/dist/ColdStorage.mjs +60 -0
  9. package/dist/ColdStorage.mjs.map +1 -0
  10. package/dist/DocumentManager.cjs +263 -82
  11. package/dist/DocumentManager.d.cts +44 -22
  12. package/dist/DocumentManager.d.cts.map +1 -1
  13. package/dist/DocumentManager.d.mts +44 -22
  14. package/dist/DocumentManager.d.mts.map +1 -1
  15. package/dist/DocumentManager.mjs +259 -67
  16. package/dist/DocumentManager.mjs.map +1 -1
  17. package/dist/Errors.cjs +54 -0
  18. package/dist/Errors.d.cts +96 -0
  19. package/dist/Errors.d.cts.map +1 -0
  20. package/dist/Errors.d.mts +96 -0
  21. package/dist/Errors.d.mts.map +1 -0
  22. package/dist/Errors.mjs +48 -0
  23. package/dist/Errors.mjs.map +1 -0
  24. package/dist/HotStorage.cjs +100 -0
  25. package/dist/HotStorage.d.cts +70 -0
  26. package/dist/HotStorage.d.cts.map +1 -0
  27. package/dist/HotStorage.d.mts +70 -0
  28. package/dist/HotStorage.d.mts.map +1 -0
  29. package/dist/HotStorage.mjs +100 -0
  30. package/dist/HotStorage.mjs.map +1 -0
  31. package/dist/Metrics.cjs +143 -0
  32. package/dist/Metrics.d.cts +31 -0
  33. package/dist/Metrics.d.cts.map +1 -0
  34. package/dist/Metrics.d.mts +31 -0
  35. package/dist/Metrics.d.mts.map +1 -0
  36. package/dist/Metrics.mjs +126 -0
  37. package/dist/Metrics.mjs.map +1 -0
  38. package/dist/MimicAuthService.cjs +61 -45
  39. package/dist/MimicAuthService.d.cts +61 -48
  40. package/dist/MimicAuthService.d.cts.map +1 -1
  41. package/dist/MimicAuthService.d.mts +61 -48
  42. package/dist/MimicAuthService.d.mts.map +1 -1
  43. package/dist/MimicAuthService.mjs +60 -36
  44. package/dist/MimicAuthService.mjs.map +1 -1
  45. package/dist/MimicClusterServerEngine.cjs +521 -0
  46. package/dist/MimicClusterServerEngine.d.cts +17 -0
  47. package/dist/MimicClusterServerEngine.d.cts.map +1 -0
  48. package/dist/MimicClusterServerEngine.d.mts +17 -0
  49. package/dist/MimicClusterServerEngine.d.mts.map +1 -0
  50. package/dist/MimicClusterServerEngine.mjs +523 -0
  51. package/dist/MimicClusterServerEngine.mjs.map +1 -0
  52. package/dist/MimicServer.cjs +205 -96
  53. package/dist/MimicServer.d.cts +9 -110
  54. package/dist/MimicServer.d.cts.map +1 -1
  55. package/dist/MimicServer.d.mts +9 -110
  56. package/dist/MimicServer.d.mts.map +1 -1
  57. package/dist/MimicServer.mjs +206 -90
  58. package/dist/MimicServer.mjs.map +1 -1
  59. package/dist/MimicServerEngine.cjs +97 -0
  60. package/dist/MimicServerEngine.d.cts +78 -0
  61. package/dist/MimicServerEngine.d.cts.map +1 -0
  62. package/dist/MimicServerEngine.d.mts +78 -0
  63. package/dist/MimicServerEngine.d.mts.map +1 -0
  64. package/dist/MimicServerEngine.mjs +97 -0
  65. package/dist/MimicServerEngine.mjs.map +1 -0
  66. package/dist/PresenceManager.cjs +75 -91
  67. package/dist/PresenceManager.d.cts +17 -66
  68. package/dist/PresenceManager.d.cts.map +1 -1
  69. package/dist/PresenceManager.d.mts +17 -66
  70. package/dist/PresenceManager.d.mts.map +1 -1
  71. package/dist/PresenceManager.mjs +74 -78
  72. package/dist/PresenceManager.mjs.map +1 -1
  73. package/dist/Protocol.cjs +146 -0
  74. package/dist/Protocol.d.cts +203 -0
  75. package/dist/Protocol.d.cts.map +1 -0
  76. package/dist/Protocol.d.mts +203 -0
  77. package/dist/Protocol.d.mts.map +1 -0
  78. package/dist/Protocol.mjs +132 -0
  79. package/dist/Protocol.mjs.map +1 -0
  80. package/dist/Types.d.cts +172 -0
  81. package/dist/Types.d.cts.map +1 -0
  82. package/dist/Types.d.mts +172 -0
  83. package/dist/Types.d.mts.map +1 -0
  84. package/dist/_virtual/rolldown_runtime.cjs +1 -25
  85. package/dist/_virtual/rolldown_runtime.mjs +4 -1
  86. package/dist/index.cjs +37 -75
  87. package/dist/index.d.cts +13 -12
  88. package/dist/index.d.mts +13 -12
  89. package/dist/index.mjs +12 -12
  90. package/dist/testing/ColdStorageTestSuite.cjs +508 -0
  91. package/dist/testing/ColdStorageTestSuite.d.cts +36 -0
  92. package/dist/testing/ColdStorageTestSuite.d.cts.map +1 -0
  93. package/dist/testing/ColdStorageTestSuite.d.mts +36 -0
  94. package/dist/testing/ColdStorageTestSuite.d.mts.map +1 -0
  95. package/dist/testing/ColdStorageTestSuite.mjs +508 -0
  96. package/dist/testing/ColdStorageTestSuite.mjs.map +1 -0
  97. package/dist/testing/FailingStorage.cjs +135 -0
  98. package/dist/testing/FailingStorage.d.cts +43 -0
  99. package/dist/testing/FailingStorage.d.cts.map +1 -0
  100. package/dist/testing/FailingStorage.d.mts +43 -0
  101. package/dist/testing/FailingStorage.d.mts.map +1 -0
  102. package/dist/testing/FailingStorage.mjs +136 -0
  103. package/dist/testing/FailingStorage.mjs.map +1 -0
  104. package/dist/testing/HotStorageTestSuite.cjs +585 -0
  105. package/dist/testing/HotStorageTestSuite.d.cts +40 -0
  106. package/dist/testing/HotStorageTestSuite.d.cts.map +1 -0
  107. package/dist/testing/HotStorageTestSuite.d.mts +40 -0
  108. package/dist/testing/HotStorageTestSuite.d.mts.map +1 -0
  109. package/dist/testing/HotStorageTestSuite.mjs +585 -0
  110. package/dist/testing/HotStorageTestSuite.mjs.map +1 -0
  111. package/dist/testing/StorageIntegrationTestSuite.cjs +349 -0
  112. package/dist/testing/StorageIntegrationTestSuite.d.cts +35 -0
  113. package/dist/testing/StorageIntegrationTestSuite.d.cts.map +1 -0
  114. package/dist/testing/StorageIntegrationTestSuite.d.mts +35 -0
  115. package/dist/testing/StorageIntegrationTestSuite.d.mts.map +1 -0
  116. package/dist/testing/StorageIntegrationTestSuite.mjs +349 -0
  117. package/dist/testing/StorageIntegrationTestSuite.mjs.map +1 -0
  118. package/dist/testing/assertions.cjs +114 -0
  119. package/dist/testing/assertions.mjs +109 -0
  120. package/dist/testing/assertions.mjs.map +1 -0
  121. package/dist/testing/index.cjs +14 -0
  122. package/dist/testing/index.d.cts +6 -0
  123. package/dist/testing/index.d.mts +6 -0
  124. package/dist/testing/index.mjs +7 -0
  125. package/dist/testing/types.cjs +15 -0
  126. package/dist/testing/types.d.cts +90 -0
  127. package/dist/testing/types.d.cts.map +1 -0
  128. package/dist/testing/types.d.mts +90 -0
  129. package/dist/testing/types.d.mts.map +1 -0
  130. package/dist/testing/types.mjs +16 -0
  131. package/dist/testing/types.mjs.map +1 -0
  132. package/package.json +18 -3
  133. package/src/ColdStorage.ts +136 -0
  134. package/src/DocumentManager.ts +550 -190
  135. package/src/Errors.ts +114 -0
  136. package/src/HotStorage.ts +239 -0
  137. package/src/Metrics.ts +187 -0
  138. package/src/MimicAuthService.ts +126 -64
  139. package/src/MimicClusterServerEngine.ts +946 -0
  140. package/src/MimicServer.ts +448 -195
  141. package/src/MimicServerEngine.ts +276 -0
  142. package/src/PresenceManager.ts +169 -240
  143. package/src/Protocol.ts +350 -0
  144. package/src/Types.ts +231 -0
  145. package/src/index.ts +57 -23
  146. package/src/testing/ColdStorageTestSuite.ts +589 -0
  147. package/src/testing/FailingStorage.ts +286 -0
  148. package/src/testing/HotStorageTestSuite.ts +762 -0
  149. package/src/testing/StorageIntegrationTestSuite.ts +504 -0
  150. package/src/testing/assertions.ts +181 -0
  151. package/src/testing/index.ts +83 -0
  152. package/src/testing/types.ts +100 -0
  153. package/tests/ColdStorage.test.ts +24 -0
  154. package/tests/DocumentManager.test.ts +158 -287
  155. package/tests/HotStorage.test.ts +24 -0
  156. package/tests/MimicAuthService.test.ts +102 -134
  157. package/tests/MimicClusterServerEngine.test.ts +587 -0
  158. package/tests/MimicServer.test.ts +90 -226
  159. package/tests/MimicServerEngine.test.ts +521 -0
  160. package/tests/PresenceManager.test.ts +22 -63
  161. package/tests/Protocol.test.ts +190 -0
  162. package/tests/StorageIntegration.test.ts +259 -0
  163. package/tsconfig.json +1 -1
  164. package/tsdown.config.ts +1 -1
  165. package/dist/DocumentProtocol.cjs +0 -94
  166. package/dist/DocumentProtocol.d.cts +0 -113
  167. package/dist/DocumentProtocol.d.cts.map +0 -1
  168. package/dist/DocumentProtocol.d.mts +0 -113
  169. package/dist/DocumentProtocol.d.mts.map +0 -1
  170. package/dist/DocumentProtocol.mjs +0 -89
  171. package/dist/DocumentProtocol.mjs.map +0 -1
  172. package/dist/MimicConfig.cjs +0 -60
  173. package/dist/MimicConfig.d.cts +0 -141
  174. package/dist/MimicConfig.d.cts.map +0 -1
  175. package/dist/MimicConfig.d.mts +0 -141
  176. package/dist/MimicConfig.d.mts.map +0 -1
  177. package/dist/MimicConfig.mjs +0 -50
  178. package/dist/MimicConfig.mjs.map +0 -1
  179. package/dist/MimicDataStorage.cjs +0 -83
  180. package/dist/MimicDataStorage.d.cts +0 -113
  181. package/dist/MimicDataStorage.d.cts.map +0 -1
  182. package/dist/MimicDataStorage.d.mts +0 -113
  183. package/dist/MimicDataStorage.d.mts.map +0 -1
  184. package/dist/MimicDataStorage.mjs +0 -74
  185. package/dist/MimicDataStorage.mjs.map +0 -1
  186. package/dist/WebSocketHandler.cjs +0 -365
  187. package/dist/WebSocketHandler.d.cts +0 -34
  188. package/dist/WebSocketHandler.d.cts.map +0 -1
  189. package/dist/WebSocketHandler.d.mts +0 -34
  190. package/dist/WebSocketHandler.d.mts.map +0 -1
  191. package/dist/WebSocketHandler.mjs +0 -355
  192. package/dist/WebSocketHandler.mjs.map +0 -1
  193. package/dist/auth/NoAuth.cjs +0 -43
  194. package/dist/auth/NoAuth.d.cts +0 -22
  195. package/dist/auth/NoAuth.d.cts.map +0 -1
  196. package/dist/auth/NoAuth.d.mts +0 -22
  197. package/dist/auth/NoAuth.d.mts.map +0 -1
  198. package/dist/auth/NoAuth.mjs +0 -36
  199. package/dist/auth/NoAuth.mjs.map +0 -1
  200. package/dist/errors.cjs +0 -74
  201. package/dist/errors.d.cts +0 -89
  202. package/dist/errors.d.cts.map +0 -1
  203. package/dist/errors.d.mts +0 -89
  204. package/dist/errors.d.mts.map +0 -1
  205. package/dist/errors.mjs +0 -67
  206. package/dist/errors.mjs.map +0 -1
  207. package/dist/storage/InMemoryDataStorage.cjs +0 -57
  208. package/dist/storage/InMemoryDataStorage.d.cts +0 -19
  209. package/dist/storage/InMemoryDataStorage.d.cts.map +0 -1
  210. package/dist/storage/InMemoryDataStorage.d.mts +0 -19
  211. package/dist/storage/InMemoryDataStorage.d.mts.map +0 -1
  212. package/dist/storage/InMemoryDataStorage.mjs +0 -48
  213. package/dist/storage/InMemoryDataStorage.mjs.map +0 -1
  214. package/src/DocumentProtocol.ts +0 -112
  215. package/src/MimicConfig.ts +0 -211
  216. package/src/MimicDataStorage.ts +0 -157
  217. package/src/WebSocketHandler.ts +0 -735
  218. package/src/auth/NoAuth.ts +0 -46
  219. package/src/errors.ts +0 -113
  220. package/src/storage/InMemoryDataStorage.ts +0 -66
  221. package/tests/DocumentProtocol.test.ts +0 -113
  222. package/tests/InMemoryDataStorage.test.ts +0 -190
  223. package/tests/MimicConfig.test.ts +0 -290
  224. package/tests/MimicDataStorage.test.ts +0 -190
  225. package/tests/NoAuth.test.ts +0 -94
  226. package/tests/WebSocketHandler.test.ts +0 -321
  227. package/tests/errors.test.ts +0 -77
@@ -1,11 +1,12 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import * as Effect from "effect/Effect";
3
- import * as Layer from "effect/Layer";
4
- import * as Schema from "effect/Schema";
2
+ import { Effect, Layer } from "effect";
3
+ import { Schema } from "effect";
5
4
  import { Primitive, Presence } from "@voidhash/mimic";
6
- import * as MimicServer from "../src/MimicServer";
7
- import * as MimicAuthService from "../src/MimicAuthService";
8
- import * as InMemoryDataStorage from "../src/storage/InMemoryDataStorage";
5
+ import { MimicServer } from "../src/MimicServer";
6
+ import { MimicServerEngine } from "../src/MimicServerEngine";
7
+ import { ColdStorage } from "../src/ColdStorage";
8
+ import { HotStorage } from "../src/HotStorage";
9
+ import { MimicAuthService } from "../src/MimicAuthService";
9
10
 
10
11
  // =============================================================================
11
12
  // Test Schema
@@ -13,7 +14,15 @@ import * as InMemoryDataStorage from "../src/storage/InMemoryDataStorage";
13
14
 
14
15
  const TestSchema = Primitive.Struct({
15
16
  title: Primitive.String().default(""),
16
- completed: Primitive.Boolean().default(false),
17
+ count: Primitive.Number().default(0),
18
+ });
19
+
20
+ const CursorPresence = Presence.make({
21
+ schema: Schema.Struct({
22
+ x: Schema.Number,
23
+ y: Schema.Number,
24
+ name: Schema.optional(Schema.String),
25
+ }),
17
26
  });
18
27
 
19
28
  // =============================================================================
@@ -21,258 +30,113 @@ const TestSchema = Primitive.Struct({
21
30
  // =============================================================================
22
31
 
23
32
  describe("MimicServer", () => {
24
-
25
- describe("documentManagerLayer", () => {
26
- it("should create a layer that provides DocumentManager", async () => {
27
- const testLayer = MimicServer.documentManagerLayer({
28
- schema: TestSchema,
29
- });
30
-
31
- // Just verify the layer compiles and provides the service
32
- const result = await Effect.runPromise(
33
- Effect.gen(function* () {
34
- // DocumentManager is provided by the layer
35
- return true;
36
- }).pipe(Effect.provide(testLayer))
37
- );
38
-
39
- expect(result).toBe(true);
40
- });
41
- });
42
-
43
33
  describe("layerHttpLayerRouter", () => {
44
- it("should create a layer with default auth and storage", () => {
45
- // Verify the function returns a layer without throwing
46
- const routeLayer = MimicServer.layerHttpLayerRouter({
47
- basePath: "/mimic/test",
48
- schema: TestSchema,
49
- });
50
-
51
- expect(routeLayer).toBeDefined();
34
+ it("should create route layer with default config", () => {
35
+ const route = MimicServer.layerHttpLayerRouter();
36
+
37
+ // Should return a Layer
38
+ expect(route).toBeDefined();
39
+ // Layer should have the proper structure
40
+ expect(typeof route).toBe("object");
52
41
  });
53
42
 
54
- it("should accept custom authLayer option", () => {
55
- const customAuthLayer = MimicAuthService.layer({
56
- authHandler: (token) => ({ success: true, userId: token }),
43
+ it("should create route layer with custom path", () => {
44
+ const route = MimicServer.layerHttpLayerRouter({
45
+ path: "/custom-mimic",
57
46
  });
47
+
48
+ expect(route).toBeDefined();
49
+ });
58
50
 
59
- const routeLayer = MimicServer.layerHttpLayerRouter({
60
- basePath: "/mimic/test",
61
- schema: TestSchema,
62
- authLayer: customAuthLayer,
51
+ it("should create route layer with custom heartbeat config", () => {
52
+ const route = MimicServer.layerHttpLayerRouter({
53
+ path: "/mimic",
54
+ heartbeatInterval: "15 seconds",
55
+ heartbeatTimeout: "5 seconds",
63
56
  });
64
-
65
- expect(routeLayer).toBeDefined();
57
+
58
+ expect(route).toBeDefined();
66
59
  });
67
60
 
68
- it("should accept custom storageLayer option", () => {
69
- const routeLayer = MimicServer.layerHttpLayerRouter({
70
- basePath: "/mimic/test",
61
+ it("should compose with engine layer", () => {
62
+ // Create the engine
63
+ const Engine = MimicServerEngine.make({
71
64
  schema: TestSchema,
72
- storageLayer: InMemoryDataStorage.layer,
65
+ initial: { title: "Untitled" },
73
66
  });
74
67
 
75
- expect(routeLayer).toBeDefined();
76
- });
77
-
78
- it("should accept both custom authLayer and storageLayer", () => {
79
- const customAuthLayer = MimicAuthService.layer({
80
- authHandler: (token) => ({ success: true, userId: token }),
68
+ // Create the route layer
69
+ const MimicRoute = MimicServer.layerHttpLayerRouter({
70
+ path: "/mimic",
81
71
  });
82
72
 
83
- const routeLayer = MimicServer.layerHttpLayerRouter({
84
- basePath: "/mimic/test",
85
- schema: TestSchema,
86
- authLayer: customAuthLayer,
87
- storageLayer: InMemoryDataStorage.layer,
88
- });
73
+ // Wire together - this should type-check
74
+ const MimicLive = MimicRoute.pipe(
75
+ Layer.provide(Engine),
76
+ Layer.provide(ColdStorage.InMemory.make()),
77
+ Layer.provide(HotStorage.InMemory.make()),
78
+ Layer.provide(MimicAuthService.NoAuth.make())
79
+ );
89
80
 
90
- expect(routeLayer).toBeDefined();
81
+ expect(MimicLive).toBeDefined();
91
82
  });
92
83
 
93
- it("should use default basePath when not provided", () => {
94
- const routeLayer = MimicServer.layerHttpLayerRouter({
84
+ it("should compose with presence-enabled engine", () => {
85
+ // Create the engine with presence
86
+ const Engine = MimicServerEngine.make({
95
87
  schema: TestSchema,
88
+ initial: { title: "Untitled" },
89
+ presence: CursorPresence,
96
90
  });
97
91
 
98
- expect(routeLayer).toBeDefined();
99
- });
100
-
101
- it("should support maxTransactionHistory option", () => {
102
- const routeLayer = MimicServer.layerHttpLayerRouter({
103
- basePath: "/mimic/test",
104
- schema: TestSchema,
105
- maxTransactionHistory: 500,
92
+ // Create the route layer
93
+ const MimicRoute = MimicServer.layerHttpLayerRouter({
94
+ path: "/mimic",
106
95
  });
107
96
 
108
- expect(routeLayer).toBeDefined();
109
- });
110
- });
111
-
112
- describe("MimicLayerOptions", () => {
113
- it("should accept all optional properties", () => {
114
- // TypeScript compile-time check - if this compiles, the interface is correct
115
- const options: MimicServer.MimicLayerOptions<typeof TestSchema> = {
116
- schema: TestSchema,
117
- basePath: "/custom/path",
118
- maxTransactionHistory: 1000,
119
- };
97
+ // Wire together
98
+ const MimicLive = MimicRoute.pipe(
99
+ Layer.provide(Engine),
100
+ Layer.provide(ColdStorage.InMemory.make()),
101
+ Layer.provide(HotStorage.InMemory.make()),
102
+ Layer.provide(MimicAuthService.NoAuth.make())
103
+ );
120
104
 
121
- expect(options.schema).toBe(TestSchema);
122
- expect(options.basePath).toBe("/custom/path");
123
- expect(options.maxTransactionHistory).toBe(1000);
105
+ expect(MimicLive).toBeDefined();
124
106
  });
125
107
 
126
- it("should work with only required properties", () => {
127
- const options: MimicServer.MimicLayerOptions<typeof TestSchema> = {
108
+ it("should compose with static auth", () => {
109
+ // Create the engine
110
+ const Engine = MimicServerEngine.make({
128
111
  schema: TestSchema,
129
- };
130
-
131
- expect(options.schema).toBe(TestSchema);
132
- expect(options.basePath).toBeUndefined();
133
- expect(options.maxTransactionHistory).toBeUndefined();
134
- });
135
- });
136
-
137
- describe("presence support", () => {
138
- const CursorPresence = Presence.make({
139
- schema: Schema.Struct({
140
- x: Schema.Number,
141
- y: Schema.Number,
142
- name: Schema.optional(Schema.String),
143
- }),
144
- });
145
-
146
- describe("documentManagerLayer", () => {
147
- it("should accept presence option", async () => {
148
- const testLayer = MimicServer.documentManagerLayer({
149
- schema: TestSchema,
150
- presence: CursorPresence,
151
- });
152
-
153
- const result = await Effect.runPromise(
154
- Effect.gen(function* () {
155
- return true;
156
- }).pipe(Effect.provide(testLayer))
157
- );
158
-
159
- expect(result).toBe(true);
160
- });
161
- });
162
-
163
- describe("layerHttpLayerRouter", () => {
164
- it("should accept presence option", () => {
165
- const routeLayer = MimicServer.layerHttpLayerRouter({
166
- basePath: "/mimic/test",
167
- schema: TestSchema,
168
- presence: CursorPresence,
169
- });
170
-
171
- expect(routeLayer).toBeDefined();
172
- });
173
-
174
- it("should work with presence and custom authLayer", () => {
175
- const customAuthLayer = MimicAuthService.layer({
176
- authHandler: (token) => ({ success: true, userId: token }),
177
- });
178
-
179
- const routeLayer = MimicServer.layerHttpLayerRouter({
180
- basePath: "/mimic/test",
181
- schema: TestSchema,
182
- presence: CursorPresence,
183
- authLayer: customAuthLayer,
184
- });
185
-
186
- expect(routeLayer).toBeDefined();
112
+ initial: { title: "Untitled" },
187
113
  });
188
114
 
189
- it("should work with presence and all options", () => {
190
- const customAuthLayer = MimicAuthService.layer({
191
- authHandler: (token) => ({ success: true, userId: token }),
192
- });
193
-
194
- const routeLayer = MimicServer.layerHttpLayerRouter({
195
- basePath: "/mimic/test",
196
- schema: TestSchema,
197
- presence: CursorPresence,
198
- maxTransactionHistory: 500,
199
- authLayer: customAuthLayer,
200
- storageLayer: InMemoryDataStorage.layer,
201
- });
202
-
203
- expect(routeLayer).toBeDefined();
115
+ // Create the route layer
116
+ const MimicRoute = MimicServer.layerHttpLayerRouter({
117
+ path: "/mimic",
204
118
  });
205
- });
206
119
 
207
- describe("MimicLayerOptions with presence", () => {
208
- it("should accept presence in options", () => {
209
- const options: MimicServer.MimicLayerOptions<typeof TestSchema> = {
210
- schema: TestSchema,
211
- basePath: "/custom/path",
212
- maxTransactionHistory: 1000,
213
- presence: CursorPresence,
214
- };
120
+ // Wire together with static auth
121
+ const MimicLive = MimicRoute.pipe(
122
+ Layer.provide(Engine),
123
+ Layer.provide(ColdStorage.InMemory.make()),
124
+ Layer.provide(HotStorage.InMemory.make()),
125
+ Layer.provide(
126
+ MimicAuthService.Static.make({
127
+ permissions: { admin: "write", user: "read" },
128
+ defaultPermission: "read",
129
+ })
130
+ )
131
+ );
215
132
 
216
- expect(options.schema).toBe(TestSchema);
217
- expect(options.basePath).toBe("/custom/path");
218
- expect(options.maxTransactionHistory).toBe(1000);
219
- expect(options.presence).toBe(CursorPresence);
220
- });
133
+ expect(MimicLive).toBeDefined();
221
134
  });
222
135
  });
223
136
 
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
- });
137
+ describe("namespace", () => {
138
+ it("should export layerHttpLayerRouter function", () => {
139
+ expect(typeof MimicServer.layerHttpLayerRouter).toBe("function");
276
140
  });
277
141
  });
278
142
  });