@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.
Files changed (99) hide show
  1. package/dist/ColdStorage.cjs +1 -1
  2. package/dist/ColdStorage.d.cts +2 -2
  3. package/dist/ColdStorage.d.cts.map +1 -1
  4. package/dist/ColdStorage.d.mts +2 -2
  5. package/dist/ColdStorage.d.mts.map +1 -1
  6. package/dist/ColdStorage.mjs +2 -2
  7. package/dist/ColdStorage.mjs.map +1 -1
  8. package/dist/DocumentInstance.cjs +13 -13
  9. package/dist/DocumentInstance.mjs +13 -13
  10. package/dist/DocumentInstance.mjs.map +1 -1
  11. package/dist/Errors.d.cts +8 -8
  12. package/dist/Errors.d.cts.map +1 -1
  13. package/dist/Errors.d.mts +8 -8
  14. package/dist/Errors.d.mts.map +1 -1
  15. package/dist/HotStorage.cjs +1 -1
  16. package/dist/HotStorage.d.cts +2 -2
  17. package/dist/HotStorage.d.mts +2 -2
  18. package/dist/HotStorage.mjs +2 -2
  19. package/dist/HotStorage.mjs.map +1 -1
  20. package/dist/Metrics.cjs +6 -6
  21. package/dist/Metrics.d.cts +21 -23
  22. package/dist/Metrics.d.cts.map +1 -1
  23. package/dist/Metrics.d.mts +21 -23
  24. package/dist/Metrics.d.mts.map +1 -1
  25. package/dist/Metrics.mjs +7 -7
  26. package/dist/Metrics.mjs.map +1 -1
  27. package/dist/MimicAuthService.cjs +1 -1
  28. package/dist/MimicAuthService.d.cts +2 -2
  29. package/dist/MimicAuthService.d.cts.map +1 -1
  30. package/dist/MimicAuthService.d.mts +2 -2
  31. package/dist/MimicAuthService.d.mts.map +1 -1
  32. package/dist/MimicAuthService.mjs +2 -2
  33. package/dist/MimicAuthService.mjs.map +1 -1
  34. package/dist/MimicClusterServerEngine.cjs +38 -41
  35. package/dist/MimicClusterServerEngine.d.cts +1 -1
  36. package/dist/MimicClusterServerEngine.d.mts +1 -1
  37. package/dist/MimicClusterServerEngine.mjs +31 -34
  38. package/dist/MimicClusterServerEngine.mjs.map +1 -1
  39. package/dist/MimicServer.cjs +23 -23
  40. package/dist/MimicServer.d.cts +3 -3
  41. package/dist/MimicServer.d.cts.map +1 -1
  42. package/dist/MimicServer.d.mts +3 -3
  43. package/dist/MimicServer.d.mts.map +1 -1
  44. package/dist/MimicServer.mjs +22 -22
  45. package/dist/MimicServer.mjs.map +1 -1
  46. package/dist/MimicServerEngine.cjs +13 -13
  47. package/dist/MimicServerEngine.d.cts +2 -2
  48. package/dist/MimicServerEngine.d.mts +2 -2
  49. package/dist/MimicServerEngine.mjs +14 -14
  50. package/dist/MimicServerEngine.mjs.map +1 -1
  51. package/dist/PresenceManager.cjs +4 -4
  52. package/dist/PresenceManager.d.cts +2 -2
  53. package/dist/PresenceManager.d.mts +2 -2
  54. package/dist/PresenceManager.mjs +5 -5
  55. package/dist/PresenceManager.mjs.map +1 -1
  56. package/dist/Types.d.cts +1 -1
  57. package/dist/Types.d.mts +1 -1
  58. package/dist/testing/ColdStorageTestSuite.cjs +3 -3
  59. package/dist/testing/ColdStorageTestSuite.mjs +3 -3
  60. package/dist/testing/ColdStorageTestSuite.mjs.map +1 -1
  61. package/dist/testing/HotStorageTestSuite.cjs +13 -13
  62. package/dist/testing/HotStorageTestSuite.mjs +13 -13
  63. package/dist/testing/HotStorageTestSuite.mjs.map +1 -1
  64. package/dist/testing/StorageIntegrationTestSuite.cjs +3 -3
  65. package/dist/testing/StorageIntegrationTestSuite.mjs +3 -3
  66. package/dist/testing/StorageIntegrationTestSuite.mjs.map +1 -1
  67. package/dist/testing/types.d.cts +3 -3
  68. package/dist/testing/types.d.cts.map +1 -1
  69. package/dist/testing/types.d.mts +1 -1
  70. package/dist/testing/types.d.mts.map +1 -1
  71. package/package.json +17 -21
  72. package/src/ColdStorage.ts +4 -5
  73. package/src/DocumentInstance.ts +13 -13
  74. package/src/HotStorage.ts +3 -3
  75. package/src/Metrics.ts +22 -16
  76. package/src/MimicAuthService.ts +3 -3
  77. package/src/MimicClusterServerEngine.ts +35 -35
  78. package/src/MimicServer.ts +26 -30
  79. package/src/MimicServerEngine.ts +15 -15
  80. package/src/PresenceManager.ts +6 -6
  81. package/src/Types.ts +1 -1
  82. package/src/testing/ColdStorageTestSuite.ts +3 -3
  83. package/src/testing/HotStorageTestSuite.ts +17 -17
  84. package/src/testing/StorageIntegrationTestSuite.ts +3 -3
  85. package/.turbo/turbo-build.log +0 -154
  86. package/tests/ColdStorage.test.ts +0 -24
  87. package/tests/DocumentInstance.test.ts +0 -669
  88. package/tests/HotStorage.test.ts +0 -24
  89. package/tests/MimicAuthService.test.ts +0 -153
  90. package/tests/MimicClusterServerEngine.test.ts +0 -587
  91. package/tests/MimicServer.test.ts +0 -142
  92. package/tests/MimicServerEngine.test.ts +0 -547
  93. package/tests/PresenceManager.test.ts +0 -380
  94. package/tests/Protocol.test.ts +0 -190
  95. package/tests/StorageIntegration.test.ts +0 -259
  96. package/tsconfig.build.json +0 -24
  97. package/tsconfig.json +0 -8
  98. package/tsdown.config.ts +0 -18
  99. package/vitest.mts +0 -11
@@ -1 +1 @@
1
- {"version":3,"file":"HotStorage.mjs","names":["result: CheckResult"],"sources":["../src/HotStorage.ts"],"sourcesContent":["/**\n * @voidhash/mimic-effect - HotStorage\n *\n * Interface and implementations for Write-Ahead Log (WAL) storage.\n */\nimport { Context, Effect, HashMap, Layer, Ref } from \"effect\";\nimport type { WalEntry } from \"./Types\";\nimport { HotStorageError, WalVersionGapError } from \"./Errors\";\n\n// =============================================================================\n// HotStorage Interface\n// =============================================================================\n\n/**\n * HotStorage interface for storing Write-Ahead Log entries.\n *\n * This is the \"hot\" tier of the two-tier storage system.\n * It stores every transaction as a WAL entry for durability between snapshots.\n * WAL entries are small (just the transaction) and writes are append-only.\n */\nexport interface HotStorage {\n /**\n * Append a WAL entry for a document.\n */\n readonly append: (\n documentId: string,\n entry: WalEntry\n ) => Effect.Effect<void, HotStorageError>;\n\n /**\n * Append a WAL entry with version gap checking.\n *\n * This is an atomic operation that:\n * 1. Verifies the previous entry has version = expectedVersion - 1\n * (or this is the first entry if expectedVersion === 1, accounting for baseVersion)\n * 2. Appends the entry if check passes\n *\n * Use this for two-phase commit to guarantee WAL ordering at write time.\n *\n * @param documentId - Document ID\n * @param entry - WAL entry to append\n * @param expectedVersion - The version this entry should have (entry.version)\n * @param baseVersion - Optional known snapshot version. When provided, an empty WAL\n * is treated as \"at this version\" rather than \"new document at version 0\".\n * This is necessary after truncation or restart to correctly validate\n * that the next entry is baseVersion + 1.\n * @returns Effect that fails with WalVersionGapError if gap detected\n */\n readonly appendWithCheck: (\n documentId: string,\n entry: WalEntry,\n expectedVersion: number,\n baseVersion?: number\n ) => Effect.Effect<void, HotStorageError | WalVersionGapError>;\n\n /**\n * Get all WAL entries for a document since a given version.\n * Returns entries with version > sinceVersion, ordered by version.\n */\n readonly getEntries: (\n documentId: string,\n sinceVersion: number\n ) => Effect.Effect<WalEntry[], HotStorageError>;\n\n /**\n * Truncate WAL entries up to (and including) a given version.\n * Called after a snapshot is saved to remove entries that are now in the snapshot.\n */\n readonly truncate: (\n documentId: string,\n upToVersion: number\n ) => Effect.Effect<void, HotStorageError>;\n}\n\n// =============================================================================\n// Context Tag\n// =============================================================================\n\n/**\n * Context tag for HotStorage service\n */\nexport class HotStorageTag extends Context.Tag(\"@voidhash/mimic-effect/HotStorage\")<\n HotStorageTag,\n HotStorage\n>() {}\n\n// =============================================================================\n// Factory\n// =============================================================================\n\n/**\n * Create a HotStorage layer from an Effect that produces a HotStorage service.\n *\n * This allows you to access other Effect services when implementing custom storage.\n *\n * @example\n * ```typescript\n * const Hot = HotStorage.make(\n * Effect.gen(function*() {\n * const redis = yield* RedisService\n *\n * return {\n * append: (documentId, entry) =>\n * redis.rpush(`wal:${documentId}`, JSON.stringify(entry)),\n * getEntries: (documentId, sinceVersion) =>\n * redis.lrange(`wal:${documentId}`, 0, -1).pipe(\n * Effect.map(entries =>\n * entries\n * .map(e => JSON.parse(e))\n * .filter(e => e.version > sinceVersion)\n * .sort((a, b) => a.version - b.version)\n * )\n * ),\n * truncate: (documentId, upToVersion) =>\n * // Implementation depends on Redis data structure\n * Effect.void,\n * }\n * })\n * )\n * ```\n */\nexport const make = <E, R>(\n effect: Effect.Effect<HotStorage, E, R>\n): Layer.Layer<HotStorageTag, E, R> =>\n Layer.effect(HotStorageTag, effect);\n\n// =============================================================================\n// InMemory Implementation\n// =============================================================================\n\n/**\n * In-memory HotStorage implementation.\n *\n * Useful for testing and development. Not suitable for production\n * as data is lost when the process restarts.\n */\nexport namespace InMemory {\n /**\n * Create an in-memory HotStorage layer.\n */\n export const make = (): Layer.Layer<HotStorageTag> =>\n Layer.effect(\n HotStorageTag,\n Effect.fn(\"hot-storage.in-memory.create\")(function* () {\n const store = yield* Ref.make(HashMap.empty<string, WalEntry[]>());\n\n return {\n append: Effect.fn(\"hot-storage.append\")(\n function* (documentId: string, entry: WalEntry) {\n yield* Ref.update(store, (map) => {\n const existing = HashMap.get(map, documentId);\n const entries =\n existing._tag === \"Some\" ? existing.value : [];\n return HashMap.set(map, documentId, [...entries, entry]);\n });\n }\n ),\n\n appendWithCheck: Effect.fn(\"hot-storage.append-with-check\")(\n function* (\n documentId: string,\n entry: WalEntry,\n expectedVersion: number,\n baseVersion?: number\n ) {\n type CheckResult =\n | { type: \"ok\" }\n | { type: \"gap\"; lastVersion: number | undefined };\n\n // Use Ref.modify for atomic check + update\n const result: CheckResult = yield* Ref.modify(\n store,\n (map): [CheckResult, HashMap.HashMap<string, WalEntry[]>] => {\n const existing = HashMap.get(map, documentId);\n const entries =\n existing._tag === \"Some\" ? existing.value : [];\n\n // Find the highest version in existing entries\n const lastEntryVersion =\n entries.length > 0\n ? Math.max(...entries.map((e) => e.version))\n : 0;\n\n // Effective \"last version\" is max of entries and baseVersion\n // This handles the case after truncation or restart where\n // WAL is empty but we know the snapshot version\n const effectiveLastVersion =\n baseVersion !== undefined\n ? Math.max(lastEntryVersion, baseVersion)\n : lastEntryVersion;\n\n // Gap check\n if (expectedVersion === 1) {\n // First entry: should have no entries with version >= 1\n // and baseVersion should be 0 or undefined\n if (effectiveLastVersion >= 1) {\n return [{ type: \"gap\", lastVersion: effectiveLastVersion }, map];\n }\n } else {\n // Not first: effective last version should be expectedVersion - 1\n if (effectiveLastVersion !== expectedVersion - 1) {\n return [\n {\n type: \"gap\",\n lastVersion: effectiveLastVersion > 0 ? effectiveLastVersion : undefined,\n },\n map,\n ];\n }\n }\n\n // No gap: append and return success\n return [\n { type: \"ok\" },\n HashMap.set(map, documentId, [...entries, entry]),\n ];\n }\n );\n\n if (result.type === \"gap\") {\n return yield* Effect.fail(\n new WalVersionGapError({\n documentId,\n expectedVersion,\n actualPreviousVersion: result.lastVersion,\n })\n );\n }\n }\n ),\n\n getEntries: Effect.fn(\"hot-storage.get-entries\")(\n function* (documentId: string, sinceVersion: number) {\n const current = yield* Ref.get(store);\n const existing = HashMap.get(current, documentId);\n const entries =\n existing._tag === \"Some\" ? existing.value : [];\n return entries\n .filter((e) => e.version > sinceVersion)\n .sort((a, b) => a.version - b.version);\n }\n ),\n\n truncate: Effect.fn(\"hot-storage.truncate\")(\n function* (documentId: string, upToVersion: number) {\n yield* Ref.update(store, (map) => {\n const existing = HashMap.get(map, documentId);\n if (existing._tag === \"None\") {\n return map;\n }\n const filtered = existing.value.filter(\n (e) => e.version > upToVersion\n );\n return HashMap.set(map, documentId, filtered);\n });\n }\n ),\n };\n })()\n );\n}\n\n// =============================================================================\n// Re-export namespace\n// =============================================================================\n\nexport const HotStorage = {\n Tag: HotStorageTag,\n make,\n InMemory,\n};\n"],"mappings":";;;;;;;;;;;;AAiFA,IAAa,gBAAb,cAAmC,QAAQ,IAAI,oCAAoC,EAGhF,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCJ,MAAa,QACX,WAEA,MAAM,OAAO,eAAe,OAAO;;;wBAiBjC,MAAM,OACJ,eACA,OAAO,GAAG,+BAA+B,CAAC,aAAa;EACrD,MAAM,QAAQ,OAAO,IAAI,KAAK,QAAQ,OAA2B,CAAC;AAElE,SAAO;GACL,QAAQ,OAAO,GAAG,qBAAqB,CACrC,WAAW,YAAoB,OAAiB;AAC9C,WAAO,IAAI,OAAO,QAAQ,QAAQ;KAChC,MAAM,WAAW,QAAQ,IAAI,KAAK,WAAW;KAC7C,MAAM,UACJ,SAAS,SAAS,SAAS,SAAS,QAAQ,EAAE;AAChD,YAAO,QAAQ,IAAI,KAAK,YAAY,CAAC,GAAG,SAAS,MAAM,CAAC;MACxD;KAEL;GAED,iBAAiB,OAAO,GAAG,gCAAgC,CACzD,WACE,YACA,OACA,iBACA,aACA;IAMA,MAAMA,SAAsB,OAAO,IAAI,OACrC,QACC,QAA4D;KAC3D,MAAM,WAAW,QAAQ,IAAI,KAAK,WAAW;KAC7C,MAAM,UACJ,SAAS,SAAS,SAAS,SAAS,QAAQ,EAAE;KAGhD,MAAM,mBACJ,QAAQ,SAAS,IACb,KAAK,IAAI,GAAG,QAAQ,KAAK,MAAM,EAAE,QAAQ,CAAC,GAC1C;KAKN,MAAM,uBACJ,gBAAgB,SACZ,KAAK,IAAI,kBAAkB,YAAY,GACvC;AAGN,SAAI,oBAAoB,GAGtB;UAAI,wBAAwB,EAC1B,QAAO,CAAC;OAAE,MAAM;OAAO,aAAa;OAAsB,EAAE,IAAI;gBAI9D,yBAAyB,kBAAkB,EAC7C,QAAO,CACL;MACE,MAAM;MACN,aAAa,uBAAuB,IAAI,uBAAuB;MAChE,EACD,IACD;AAKL,YAAO,CACL,EAAE,MAAM,MAAM,EACd,QAAQ,IAAI,KAAK,YAAY,CAAC,GAAG,SAAS,MAAM,CAAC,CAClD;MAEJ;AAED,QAAI,OAAO,SAAS,MAClB,QAAO,OAAO,OAAO,KACnB,IAAI,mBAAmB;KACrB;KACA;KACA,uBAAuB,OAAO;KAC/B,CAAC,CACH;KAGN;GAED,YAAY,OAAO,GAAG,0BAA0B,CAC9C,WAAW,YAAoB,cAAsB;IACnD,MAAM,UAAU,OAAO,IAAI,IAAI,MAAM;IACrC,MAAM,WAAW,QAAQ,IAAI,SAAS,WAAW;AAGjD,YADE,SAAS,SAAS,SAAS,SAAS,QAAQ,EAAE,EAE7C,QAAQ,MAAM,EAAE,UAAU,aAAa,CACvC,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ;KAE3C;GAED,UAAU,OAAO,GAAG,uBAAuB,CACzC,WAAW,YAAoB,aAAqB;AAClD,WAAO,IAAI,OAAO,QAAQ,QAAQ;KAChC,MAAM,WAAW,QAAQ,IAAI,KAAK,WAAW;AAC7C,SAAI,SAAS,SAAS,OACpB,QAAO;KAET,MAAM,WAAW,SAAS,MAAM,QAC7B,MAAM,EAAE,UAAU,YACpB;AACD,YAAO,QAAQ,IAAI,KAAK,YAAY,SAAS;MAC7C;KAEL;GACF;GACD,EAAE,CACL;;AAOL,MAAa,aAAa;CACxB,KAAK;CACL;CACA;CACD"}
1
+ {"version":3,"file":"HotStorage.mjs","names":["result: CheckResult"],"sources":["../src/HotStorage.ts"],"sourcesContent":["/**\n * @voidhash/mimic-effect - HotStorage\n *\n * Interface and implementations for Write-Ahead Log (WAL) storage.\n */\nimport { Effect, HashMap, Layer, Ref, ServiceMap } from \"effect\";\nimport type { WalEntry } from \"./Types\";\nimport { HotStorageError, WalVersionGapError } from \"./Errors\";\n\n// =============================================================================\n// HotStorage Interface\n// =============================================================================\n\n/**\n * HotStorage interface for storing Write-Ahead Log entries.\n *\n * This is the \"hot\" tier of the two-tier storage system.\n * It stores every transaction as a WAL entry for durability between snapshots.\n * WAL entries are small (just the transaction) and writes are append-only.\n */\nexport interface HotStorage {\n /**\n * Append a WAL entry for a document.\n */\n readonly append: (\n documentId: string,\n entry: WalEntry\n ) => Effect.Effect<void, HotStorageError>;\n\n /**\n * Append a WAL entry with version gap checking.\n *\n * This is an atomic operation that:\n * 1. Verifies the previous entry has version = expectedVersion - 1\n * (or this is the first entry if expectedVersion === 1, accounting for baseVersion)\n * 2. Appends the entry if check passes\n *\n * Use this for two-phase commit to guarantee WAL ordering at write time.\n *\n * @param documentId - Document ID\n * @param entry - WAL entry to append\n * @param expectedVersion - The version this entry should have (entry.version)\n * @param baseVersion - Optional known snapshot version. When provided, an empty WAL\n * is treated as \"at this version\" rather than \"new document at version 0\".\n * This is necessary after truncation or restart to correctly validate\n * that the next entry is baseVersion + 1.\n * @returns Effect that fails with WalVersionGapError if gap detected\n */\n readonly appendWithCheck: (\n documentId: string,\n entry: WalEntry,\n expectedVersion: number,\n baseVersion?: number\n ) => Effect.Effect<void, HotStorageError | WalVersionGapError>;\n\n /**\n * Get all WAL entries for a document since a given version.\n * Returns entries with version > sinceVersion, ordered by version.\n */\n readonly getEntries: (\n documentId: string,\n sinceVersion: number\n ) => Effect.Effect<WalEntry[], HotStorageError>;\n\n /**\n * Truncate WAL entries up to (and including) a given version.\n * Called after a snapshot is saved to remove entries that are now in the snapshot.\n */\n readonly truncate: (\n documentId: string,\n upToVersion: number\n ) => Effect.Effect<void, HotStorageError>;\n}\n\n// =============================================================================\n// Context Tag\n// =============================================================================\n\n/**\n * Context tag for HotStorage service\n */\nexport class HotStorageTag extends ServiceMap.Service<\n HotStorageTag,\n HotStorage\n>()(\"@voidhash/mimic-effect/HotStorage\") {}\n\n// =============================================================================\n// Factory\n// =============================================================================\n\n/**\n * Create a HotStorage layer from an Effect that produces a HotStorage service.\n *\n * This allows you to access other Effect services when implementing custom storage.\n *\n * @example\n * ```typescript\n * const Hot = HotStorage.make(\n * Effect.gen(function*() {\n * const redis = yield* RedisService\n *\n * return {\n * append: (documentId, entry) =>\n * redis.rpush(`wal:${documentId}`, JSON.stringify(entry)),\n * getEntries: (documentId, sinceVersion) =>\n * redis.lrange(`wal:${documentId}`, 0, -1).pipe(\n * Effect.map(entries =>\n * entries\n * .map(e => JSON.parse(e))\n * .filter(e => e.version > sinceVersion)\n * .sort((a, b) => a.version - b.version)\n * )\n * ),\n * truncate: (documentId, upToVersion) =>\n * // Implementation depends on Redis data structure\n * Effect.void,\n * }\n * })\n * )\n * ```\n */\nexport const make = <E, R>(\n effect: Effect.Effect<HotStorage, E, R>\n): Layer.Layer<HotStorageTag, E, R> =>\n Layer.effect(HotStorageTag, effect);\n\n// =============================================================================\n// InMemory Implementation\n// =============================================================================\n\n/**\n * In-memory HotStorage implementation.\n *\n * Useful for testing and development. Not suitable for production\n * as data is lost when the process restarts.\n */\nexport namespace InMemory {\n /**\n * Create an in-memory HotStorage layer.\n */\n export const make = (): Layer.Layer<HotStorageTag> =>\n Layer.effect(\n HotStorageTag,\n Effect.fn(\"hot-storage.in-memory.create\")(function* () {\n const store = yield* Ref.make(HashMap.empty<string, WalEntry[]>());\n\n return {\n append: Effect.fn(\"hot-storage.append\")(\n function* (documentId: string, entry: WalEntry) {\n yield* Ref.update(store, (map) => {\n const existing = HashMap.get(map, documentId);\n const entries =\n existing._tag === \"Some\" ? existing.value : [];\n return HashMap.set(map, documentId, [...entries, entry]);\n });\n }\n ),\n\n appendWithCheck: Effect.fn(\"hot-storage.append-with-check\")(\n function* (\n documentId: string,\n entry: WalEntry,\n expectedVersion: number,\n baseVersion?: number\n ) {\n type CheckResult =\n | { type: \"ok\" }\n | { type: \"gap\"; lastVersion: number | undefined };\n\n // Use Ref.modify for atomic check + update\n const result: CheckResult = yield* Ref.modify(\n store,\n (map): [CheckResult, HashMap.HashMap<string, WalEntry[]>] => {\n const existing = HashMap.get(map, documentId);\n const entries =\n existing._tag === \"Some\" ? existing.value : [];\n\n // Find the highest version in existing entries\n const lastEntryVersion =\n entries.length > 0\n ? Math.max(...entries.map((e) => e.version))\n : 0;\n\n // Effective \"last version\" is max of entries and baseVersion\n // This handles the case after truncation or restart where\n // WAL is empty but we know the snapshot version\n const effectiveLastVersion =\n baseVersion !== undefined\n ? Math.max(lastEntryVersion, baseVersion)\n : lastEntryVersion;\n\n // Gap check\n if (expectedVersion === 1) {\n // First entry: should have no entries with version >= 1\n // and baseVersion should be 0 or undefined\n if (effectiveLastVersion >= 1) {\n return [{ type: \"gap\", lastVersion: effectiveLastVersion }, map];\n }\n } else {\n // Not first: effective last version should be expectedVersion - 1\n if (effectiveLastVersion !== expectedVersion - 1) {\n return [\n {\n type: \"gap\",\n lastVersion: effectiveLastVersion > 0 ? effectiveLastVersion : undefined,\n },\n map,\n ];\n }\n }\n\n // No gap: append and return success\n return [\n { type: \"ok\" },\n HashMap.set(map, documentId, [...entries, entry]),\n ];\n }\n );\n\n if (result.type === \"gap\") {\n return yield* Effect.fail(\n new WalVersionGapError({\n documentId,\n expectedVersion,\n actualPreviousVersion: result.lastVersion,\n })\n );\n }\n }\n ),\n\n getEntries: Effect.fn(\"hot-storage.get-entries\")(\n function* (documentId: string, sinceVersion: number) {\n const current = yield* Ref.get(store);\n const existing = HashMap.get(current, documentId);\n const entries =\n existing._tag === \"Some\" ? existing.value : [];\n return entries\n .filter((e) => e.version > sinceVersion)\n .sort((a, b) => a.version - b.version);\n }\n ),\n\n truncate: Effect.fn(\"hot-storage.truncate\")(\n function* (documentId: string, upToVersion: number) {\n yield* Ref.update(store, (map) => {\n const existing = HashMap.get(map, documentId);\n if (existing._tag === \"None\") {\n return map;\n }\n const filtered = existing.value.filter(\n (e) => e.version > upToVersion\n );\n return HashMap.set(map, documentId, filtered);\n });\n }\n ),\n };\n })()\n );\n}\n\n// =============================================================================\n// Re-export namespace\n// =============================================================================\n\nexport const HotStorage = {\n Tag: HotStorageTag,\n make,\n InMemory,\n};\n"],"mappings":";;;;;;;;;;;;AAiFA,IAAa,gBAAb,cAAmC,WAAW,SAG3C,CAAC,oCAAoC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCzC,MAAa,QACX,WAEA,MAAM,OAAO,eAAe,OAAO;;;wBAiBjC,MAAM,OACJ,eACA,OAAO,GAAG,+BAA+B,CAAC,aAAa;EACrD,MAAM,QAAQ,OAAO,IAAI,KAAK,QAAQ,OAA2B,CAAC;AAElE,SAAO;GACL,QAAQ,OAAO,GAAG,qBAAqB,CACrC,WAAW,YAAoB,OAAiB;AAC9C,WAAO,IAAI,OAAO,QAAQ,QAAQ;KAChC,MAAM,WAAW,QAAQ,IAAI,KAAK,WAAW;KAC7C,MAAM,UACJ,SAAS,SAAS,SAAS,SAAS,QAAQ,EAAE;AAChD,YAAO,QAAQ,IAAI,KAAK,YAAY,CAAC,GAAG,SAAS,MAAM,CAAC;MACxD;KAEL;GAED,iBAAiB,OAAO,GAAG,gCAAgC,CACzD,WACE,YACA,OACA,iBACA,aACA;IAMA,MAAMA,SAAsB,OAAO,IAAI,OACrC,QACC,QAA4D;KAC3D,MAAM,WAAW,QAAQ,IAAI,KAAK,WAAW;KAC7C,MAAM,UACJ,SAAS,SAAS,SAAS,SAAS,QAAQ,EAAE;KAGhD,MAAM,mBACJ,QAAQ,SAAS,IACb,KAAK,IAAI,GAAG,QAAQ,KAAK,MAAM,EAAE,QAAQ,CAAC,GAC1C;KAKN,MAAM,uBACJ,gBAAgB,SACZ,KAAK,IAAI,kBAAkB,YAAY,GACvC;AAGN,SAAI,oBAAoB,GAGtB;UAAI,wBAAwB,EAC1B,QAAO,CAAC;OAAE,MAAM;OAAO,aAAa;OAAsB,EAAE,IAAI;gBAI9D,yBAAyB,kBAAkB,EAC7C,QAAO,CACL;MACE,MAAM;MACN,aAAa,uBAAuB,IAAI,uBAAuB;MAChE,EACD,IACD;AAKL,YAAO,CACL,EAAE,MAAM,MAAM,EACd,QAAQ,IAAI,KAAK,YAAY,CAAC,GAAG,SAAS,MAAM,CAAC,CAClD;MAEJ;AAED,QAAI,OAAO,SAAS,MAClB,QAAO,OAAO,OAAO,KACnB,IAAI,mBAAmB;KACrB;KACA;KACA,uBAAuB,OAAO;KAC/B,CAAC,CACH;KAGN;GAED,YAAY,OAAO,GAAG,0BAA0B,CAC9C,WAAW,YAAoB,cAAsB;IACnD,MAAM,UAAU,OAAO,IAAI,IAAI,MAAM;IACrC,MAAM,WAAW,QAAQ,IAAI,SAAS,WAAW;AAGjD,YADE,SAAS,SAAS,SAAS,SAAS,QAAQ,EAAE,EAE7C,QAAQ,MAAM,EAAE,UAAU,aAAa,CACvC,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ;KAE3C;GAED,UAAU,OAAO,GAAG,uBAAuB,CACzC,WAAW,YAAoB,aAAqB;AAClD,WAAO,IAAI,OAAO,QAAQ,QAAQ;KAChC,MAAM,WAAW,QAAQ,IAAI,KAAK,WAAW;AAC7C,SAAI,SAAS,SAAS,OACpB,QAAO;KAET,MAAM,WAAW,SAAS,MAAM,QAC7B,MAAM,EAAE,UAAU,YACpB;AACD,YAAO,QAAQ,IAAI,KAAK,YAAY,SAAS;MAC7C;KAEL;GACF;GACD,EAAE,CACL;;AAOL,MAAa,aAAa;CACxB,KAAK;CACL;CACA;CACD"}
package/dist/Metrics.cjs CHANGED
@@ -17,11 +17,11 @@ const connectionsTotal = effect.Metric.counter("mimic.connections.total");
17
17
  /**
18
18
  * Connection duration histogram (milliseconds)
19
19
  */
20
- const connectionsDuration = effect.Metric.histogram("mimic.connections.duration_ms", effect.MetricBoundaries.exponential({
20
+ const connectionsDuration = effect.Metric.histogram("mimic.connections.duration_ms", { boundaries: effect.Metric.exponentialBoundaries({
21
21
  start: 100,
22
22
  factor: 2,
23
23
  count: 15
24
- }));
24
+ }) });
25
25
  /**
26
26
  * Connection errors (auth failures, etc.)
27
27
  */
@@ -53,11 +53,11 @@ const transactionsRejected = effect.Metric.counter("mimic.transactions.rejected"
53
53
  /**
54
54
  * Transaction processing latency histogram (milliseconds)
55
55
  */
56
- const transactionsLatency = effect.Metric.histogram("mimic.transactions.latency_ms", effect.MetricBoundaries.exponential({
56
+ const transactionsLatency = effect.Metric.histogram("mimic.transactions.latency_ms", { boundaries: effect.Metric.exponentialBoundaries({
57
57
  start: .1,
58
58
  factor: 2,
59
59
  count: 15
60
- }));
60
+ }) });
61
61
  /**
62
62
  * Snapshots saved to ColdStorage
63
63
  */
@@ -69,11 +69,11 @@ const storageIdleSnapshots = effect.Metric.counter("mimic.storage.idle_snapshots
69
69
  /**
70
70
  * Snapshot save duration histogram (milliseconds)
71
71
  */
72
- const storageSnapshotLatency = effect.Metric.histogram("mimic.storage.snapshot_latency_ms", effect.MetricBoundaries.exponential({
72
+ const storageSnapshotLatency = effect.Metric.histogram("mimic.storage.snapshot_latency_ms", { boundaries: effect.Metric.exponentialBoundaries({
73
73
  start: 1,
74
74
  factor: 2,
75
75
  count: 12
76
- }));
76
+ }) });
77
77
  /**
78
78
  * WAL entries written to HotStorage
79
79
  */
@@ -1,31 +1,29 @@
1
1
  import { Metric } from "effect";
2
- import * as effect_MetricKeyType0 from "effect/MetricKeyType";
3
- import * as effect_MetricState0 from "effect/MetricState";
4
2
 
5
3
  //#region src/Metrics.d.ts
6
4
 
7
5
  declare const MimicMetrics: {
8
- connectionsActive: Metric.Metric.Gauge<number>;
9
- connectionsTotal: Metric.Metric.Counter<number>;
10
- connectionsDuration: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
11
- connectionsErrors: Metric.Metric.Counter<number>;
12
- documentsActive: Metric.Metric.Gauge<number>;
13
- documentsCreated: Metric.Metric.Counter<number>;
14
- documentsRestored: Metric.Metric.Counter<number>;
15
- documentsEvicted: Metric.Metric.Counter<number>;
16
- transactionsProcessed: Metric.Metric.Counter<number>;
17
- transactionsRejected: Metric.Metric.Counter<number>;
18
- transactionsLatency: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
19
- storageSnapshots: Metric.Metric.Counter<number>;
20
- storageIdleSnapshots: Metric.Metric.Counter<number>;
21
- storageSnapshotLatency: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
22
- storageWalAppends: Metric.Metric.Counter<number>;
23
- storageVersionGaps: Metric.Metric.Counter<number>;
24
- walAppendFailures: Metric.Metric.Counter<number>;
25
- coldStorageLoadFailures: Metric.Metric.Counter<number>;
26
- hotStorageLoadFailures: Metric.Metric.Counter<number>;
27
- presenceUpdates: Metric.Metric.Counter<number>;
28
- presenceActive: Metric.Metric.Gauge<number>;
6
+ connectionsActive: Metric.Gauge<number>;
7
+ connectionsTotal: Metric.Counter<number>;
8
+ connectionsDuration: Metric.Histogram<number>;
9
+ connectionsErrors: Metric.Counter<number>;
10
+ documentsActive: Metric.Gauge<number>;
11
+ documentsCreated: Metric.Counter<number>;
12
+ documentsRestored: Metric.Counter<number>;
13
+ documentsEvicted: Metric.Counter<number>;
14
+ transactionsProcessed: Metric.Counter<number>;
15
+ transactionsRejected: Metric.Counter<number>;
16
+ transactionsLatency: Metric.Histogram<number>;
17
+ storageSnapshots: Metric.Counter<number>;
18
+ storageIdleSnapshots: Metric.Counter<number>;
19
+ storageSnapshotLatency: Metric.Histogram<number>;
20
+ storageWalAppends: Metric.Counter<number>;
21
+ storageVersionGaps: Metric.Counter<number>;
22
+ walAppendFailures: Metric.Counter<number>;
23
+ coldStorageLoadFailures: Metric.Counter<number>;
24
+ hotStorageLoadFailures: Metric.Counter<number>;
25
+ presenceUpdates: Metric.Counter<number>;
26
+ presenceActive: Metric.Gauge<number>;
29
27
  };
30
28
  //#endregion
31
29
  export { MimicMetrics };
@@ -1 +1 @@
1
- {"version":3,"file":"Metrics.d.cts","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":[],"mappings":";;;;;;cAiKa"}
1
+ {"version":3,"file":"Metrics.d.cts","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":[],"mappings":";;;;cAuKa"}
@@ -1,31 +1,29 @@
1
1
  import { Metric } from "effect";
2
- import * as effect_MetricKeyType0 from "effect/MetricKeyType";
3
- import * as effect_MetricState0 from "effect/MetricState";
4
2
 
5
3
  //#region src/Metrics.d.ts
6
4
 
7
5
  declare const MimicMetrics: {
8
- connectionsActive: Metric.Metric.Gauge<number>;
9
- connectionsTotal: Metric.Metric.Counter<number>;
10
- connectionsDuration: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
11
- connectionsErrors: Metric.Metric.Counter<number>;
12
- documentsActive: Metric.Metric.Gauge<number>;
13
- documentsCreated: Metric.Metric.Counter<number>;
14
- documentsRestored: Metric.Metric.Counter<number>;
15
- documentsEvicted: Metric.Metric.Counter<number>;
16
- transactionsProcessed: Metric.Metric.Counter<number>;
17
- transactionsRejected: Metric.Metric.Counter<number>;
18
- transactionsLatency: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
19
- storageSnapshots: Metric.Metric.Counter<number>;
20
- storageIdleSnapshots: Metric.Metric.Counter<number>;
21
- storageSnapshotLatency: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
22
- storageWalAppends: Metric.Metric.Counter<number>;
23
- storageVersionGaps: Metric.Metric.Counter<number>;
24
- walAppendFailures: Metric.Metric.Counter<number>;
25
- coldStorageLoadFailures: Metric.Metric.Counter<number>;
26
- hotStorageLoadFailures: Metric.Metric.Counter<number>;
27
- presenceUpdates: Metric.Metric.Counter<number>;
28
- presenceActive: Metric.Metric.Gauge<number>;
6
+ connectionsActive: Metric.Gauge<number>;
7
+ connectionsTotal: Metric.Counter<number>;
8
+ connectionsDuration: Metric.Histogram<number>;
9
+ connectionsErrors: Metric.Counter<number>;
10
+ documentsActive: Metric.Gauge<number>;
11
+ documentsCreated: Metric.Counter<number>;
12
+ documentsRestored: Metric.Counter<number>;
13
+ documentsEvicted: Metric.Counter<number>;
14
+ transactionsProcessed: Metric.Counter<number>;
15
+ transactionsRejected: Metric.Counter<number>;
16
+ transactionsLatency: Metric.Histogram<number>;
17
+ storageSnapshots: Metric.Counter<number>;
18
+ storageIdleSnapshots: Metric.Counter<number>;
19
+ storageSnapshotLatency: Metric.Histogram<number>;
20
+ storageWalAppends: Metric.Counter<number>;
21
+ storageVersionGaps: Metric.Counter<number>;
22
+ walAppendFailures: Metric.Counter<number>;
23
+ coldStorageLoadFailures: Metric.Counter<number>;
24
+ hotStorageLoadFailures: Metric.Counter<number>;
25
+ presenceUpdates: Metric.Counter<number>;
26
+ presenceActive: Metric.Gauge<number>;
29
27
  };
30
28
  //#endregion
31
29
  export { MimicMetrics };
@@ -1 +1 @@
1
- {"version":3,"file":"Metrics.d.mts","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":[],"mappings":";;;;;;cAiKa"}
1
+ {"version":3,"file":"Metrics.d.mts","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":[],"mappings":";;;;cAuKa"}
package/dist/Metrics.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { Metric, MetricBoundaries } from "effect";
1
+ import { Metric } from "effect";
2
2
 
3
3
  //#region src/Metrics.ts
4
4
  /**
@@ -17,11 +17,11 @@ const connectionsTotal = Metric.counter("mimic.connections.total");
17
17
  /**
18
18
  * Connection duration histogram (milliseconds)
19
19
  */
20
- const connectionsDuration = Metric.histogram("mimic.connections.duration_ms", MetricBoundaries.exponential({
20
+ const connectionsDuration = Metric.histogram("mimic.connections.duration_ms", { boundaries: Metric.exponentialBoundaries({
21
21
  start: 100,
22
22
  factor: 2,
23
23
  count: 15
24
- }));
24
+ }) });
25
25
  /**
26
26
  * Connection errors (auth failures, etc.)
27
27
  */
@@ -53,11 +53,11 @@ const transactionsRejected = Metric.counter("mimic.transactions.rejected");
53
53
  /**
54
54
  * Transaction processing latency histogram (milliseconds)
55
55
  */
56
- const transactionsLatency = Metric.histogram("mimic.transactions.latency_ms", MetricBoundaries.exponential({
56
+ const transactionsLatency = Metric.histogram("mimic.transactions.latency_ms", { boundaries: Metric.exponentialBoundaries({
57
57
  start: .1,
58
58
  factor: 2,
59
59
  count: 15
60
- }));
60
+ }) });
61
61
  /**
62
62
  * Snapshots saved to ColdStorage
63
63
  */
@@ -69,11 +69,11 @@ const storageIdleSnapshots = Metric.counter("mimic.storage.idle_snapshots");
69
69
  /**
70
70
  * Snapshot save duration histogram (milliseconds)
71
71
  */
72
- const storageSnapshotLatency = Metric.histogram("mimic.storage.snapshot_latency_ms", MetricBoundaries.exponential({
72
+ const storageSnapshotLatency = Metric.histogram("mimic.storage.snapshot_latency_ms", { boundaries: Metric.exponentialBoundaries({
73
73
  start: 1,
74
74
  factor: 2,
75
75
  count: 12
76
- }));
76
+ }) });
77
77
  /**
78
78
  * WAL entries written to HotStorage
79
79
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Metrics.mjs","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":["/**\n * @voidhash/mimic-effect - Metrics\n *\n * Observability metrics using Effect's Metric API.\n */\nimport { Metric, MetricBoundaries } from \"effect\";\n\n// =============================================================================\n// Connection Metrics\n// =============================================================================\n\n/**\n * Current active WebSocket connections\n */\nexport const connectionsActive = Metric.gauge(\"mimic.connections.active\");\n\n/**\n * Total connections over lifetime\n */\nexport const connectionsTotal = Metric.counter(\"mimic.connections.total\");\n\n/**\n * Connection duration histogram (milliseconds)\n */\nexport const connectionsDuration = Metric.histogram(\n \"mimic.connections.duration_ms\",\n MetricBoundaries.exponential({\n start: 100,\n factor: 2,\n count: 15, // Up to ~3.2 million ms (~53 minutes)\n })\n);\n\n/**\n * Connection errors (auth failures, etc.)\n */\nexport const connectionsErrors = Metric.counter(\"mimic.connections.errors\");\n\n// =============================================================================\n// Document Metrics\n// =============================================================================\n\n/**\n * Documents currently in memory\n */\nexport const documentsActive = Metric.gauge(\"mimic.documents.active\");\n\n/**\n * New documents created\n */\nexport const documentsCreated = Metric.counter(\"mimic.documents.created\");\n\n/**\n * Documents restored from storage\n */\nexport const documentsRestored = Metric.counter(\"mimic.documents.restored\");\n\n/**\n * Documents garbage collected (evicted)\n */\nexport const documentsEvicted = Metric.counter(\"mimic.documents.evicted\");\n\n// =============================================================================\n// Transaction Metrics\n// =============================================================================\n\n/**\n * Successfully processed transactions\n */\nexport const transactionsProcessed = Metric.counter(\n \"mimic.transactions.processed\"\n);\n\n/**\n * Rejected transactions\n */\nexport const transactionsRejected = Metric.counter(\n \"mimic.transactions.rejected\"\n);\n\n/**\n * Transaction processing latency histogram (milliseconds)\n */\nexport const transactionsLatency = Metric.histogram(\n \"mimic.transactions.latency_ms\",\n MetricBoundaries.exponential({\n start: 0.1,\n factor: 2,\n count: 15, // Up to ~1638 ms\n })\n);\n\n// =============================================================================\n// Storage Metrics\n// =============================================================================\n\n/**\n * Snapshots saved to ColdStorage\n */\nexport const storageSnapshots = Metric.counter(\"mimic.storage.snapshots\");\n\n/**\n * Snapshots triggered by idle document detection\n */\nexport const storageIdleSnapshots = Metric.counter(\"mimic.storage.idle_snapshots\");\n\n/**\n * Snapshot save duration histogram (milliseconds)\n */\nexport const storageSnapshotLatency = Metric.histogram(\n \"mimic.storage.snapshot_latency_ms\",\n MetricBoundaries.exponential({\n start: 1,\n factor: 2,\n count: 12, // Up to ~4 seconds\n })\n);\n\n/**\n * WAL entries written to HotStorage\n */\nexport const storageWalAppends = Metric.counter(\"mimic.storage.wal_appends\");\n\n/**\n * Version gaps detected during WAL replay\n */\nexport const storageVersionGaps = Metric.counter(\"mimic.storage.version_gaps\");\n\n/**\n * Failed WAL appends causing transaction rollback\n */\nexport const walAppendFailures = Metric.counter(\"mimic.storage.wal_append_failures\");\n\n/**\n * ColdStorage load failures during document restore\n */\nexport const coldStorageLoadFailures = Metric.counter(\"mimic.storage.cold_load_failures\");\n\n/**\n * HotStorage getEntries failures during document restore\n */\nexport const hotStorageLoadFailures = Metric.counter(\"mimic.storage.hot_load_failures\");\n\n// =============================================================================\n// Presence Metrics\n// =============================================================================\n\n/**\n * Presence set operations\n */\nexport const presenceUpdates = Metric.counter(\"mimic.presence.updates\");\n\n/**\n * Active presence entries\n */\nexport const presenceActive = Metric.gauge(\"mimic.presence.active\");\n\n// =============================================================================\n// Export namespace\n// =============================================================================\n\nexport const MimicMetrics = {\n // Connection\n connectionsActive,\n connectionsTotal,\n connectionsDuration,\n connectionsErrors,\n\n // Document\n documentsActive,\n documentsCreated,\n documentsRestored,\n documentsEvicted,\n\n // Transaction\n transactionsProcessed,\n transactionsRejected,\n transactionsLatency,\n\n // Storage\n storageSnapshots,\n storageIdleSnapshots,\n storageSnapshotLatency,\n storageWalAppends,\n storageVersionGaps,\n walAppendFailures,\n coldStorageLoadFailures,\n hotStorageLoadFailures,\n\n // Presence\n presenceUpdates,\n presenceActive,\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,oBAAoB,OAAO,MAAM,2BAA2B;;;;AAKzE,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AAKzE,MAAa,sBAAsB,OAAO,UACxC,iCACA,iBAAiB,YAAY;CAC3B,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC,CACH;;;;AAKD,MAAa,oBAAoB,OAAO,QAAQ,2BAA2B;;;;AAS3E,MAAa,kBAAkB,OAAO,MAAM,yBAAyB;;;;AAKrE,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AAKzE,MAAa,oBAAoB,OAAO,QAAQ,2BAA2B;;;;AAK3E,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AASzE,MAAa,wBAAwB,OAAO,QAC1C,+BACD;;;;AAKD,MAAa,uBAAuB,OAAO,QACzC,8BACD;;;;AAKD,MAAa,sBAAsB,OAAO,UACxC,iCACA,iBAAiB,YAAY;CAC3B,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC,CACH;;;;AASD,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AAKzE,MAAa,uBAAuB,OAAO,QAAQ,+BAA+B;;;;AAKlF,MAAa,yBAAyB,OAAO,UAC3C,qCACA,iBAAiB,YAAY;CAC3B,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC,CACH;;;;AAKD,MAAa,oBAAoB,OAAO,QAAQ,4BAA4B;;;;AAK5E,MAAa,qBAAqB,OAAO,QAAQ,6BAA6B;;;;AAK9E,MAAa,oBAAoB,OAAO,QAAQ,oCAAoC;;;;AAKpF,MAAa,0BAA0B,OAAO,QAAQ,mCAAmC;;;;AAKzF,MAAa,yBAAyB,OAAO,QAAQ,kCAAkC;;;;AASvF,MAAa,kBAAkB,OAAO,QAAQ,yBAAyB;;;;AAKvE,MAAa,iBAAiB,OAAO,MAAM,wBAAwB;AAMnE,MAAa,eAAe;CAE1B;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CAGA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACD"}
1
+ {"version":3,"file":"Metrics.mjs","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":["/**\n * @voidhash/mimic-effect - Metrics\n *\n * Observability metrics using Effect's Metric API.\n */\nimport { Metric } from \"effect\";\n\n// =============================================================================\n// Connection Metrics\n// =============================================================================\n\n/**\n * Current active WebSocket connections\n */\nexport const connectionsActive = Metric.gauge(\"mimic.connections.active\");\n\n/**\n * Total connections over lifetime\n */\nexport const connectionsTotal = Metric.counter(\"mimic.connections.total\");\n\n/**\n * Connection duration histogram (milliseconds)\n */\nexport const connectionsDuration = Metric.histogram(\n \"mimic.connections.duration_ms\",\n {\n boundaries: Metric.exponentialBoundaries({\n start: 100,\n factor: 2,\n count: 15, // Up to ~3.2 million ms (~53 minutes)\n }),\n }\n);\n\n/**\n * Connection errors (auth failures, etc.)\n */\nexport const connectionsErrors = Metric.counter(\"mimic.connections.errors\");\n\n// =============================================================================\n// Document Metrics\n// =============================================================================\n\n/**\n * Documents currently in memory\n */\nexport const documentsActive = Metric.gauge(\"mimic.documents.active\");\n\n/**\n * New documents created\n */\nexport const documentsCreated = Metric.counter(\"mimic.documents.created\");\n\n/**\n * Documents restored from storage\n */\nexport const documentsRestored = Metric.counter(\"mimic.documents.restored\");\n\n/**\n * Documents garbage collected (evicted)\n */\nexport const documentsEvicted = Metric.counter(\"mimic.documents.evicted\");\n\n// =============================================================================\n// Transaction Metrics\n// =============================================================================\n\n/**\n * Successfully processed transactions\n */\nexport const transactionsProcessed = Metric.counter(\n \"mimic.transactions.processed\"\n);\n\n/**\n * Rejected transactions\n */\nexport const transactionsRejected = Metric.counter(\n \"mimic.transactions.rejected\"\n);\n\n/**\n * Transaction processing latency histogram (milliseconds)\n */\nexport const transactionsLatency = Metric.histogram(\n \"mimic.transactions.latency_ms\",\n {\n boundaries: Metric.exponentialBoundaries({\n start: 0.1,\n factor: 2,\n count: 15, // Up to ~1638 ms\n }),\n }\n);\n\n// =============================================================================\n// Storage Metrics\n// =============================================================================\n\n/**\n * Snapshots saved to ColdStorage\n */\nexport const storageSnapshots = Metric.counter(\"mimic.storage.snapshots\");\n\n/**\n * Snapshots triggered by idle document detection\n */\nexport const storageIdleSnapshots = Metric.counter(\"mimic.storage.idle_snapshots\");\n\n/**\n * Snapshot save duration histogram (milliseconds)\n */\nexport const storageSnapshotLatency = Metric.histogram(\n \"mimic.storage.snapshot_latency_ms\",\n {\n boundaries: Metric.exponentialBoundaries({\n start: 1,\n factor: 2,\n count: 12, // Up to ~4 seconds\n }),\n }\n);\n\n/**\n * WAL entries written to HotStorage\n */\nexport const storageWalAppends = Metric.counter(\"mimic.storage.wal_appends\");\n\n/**\n * Version gaps detected during WAL replay\n */\nexport const storageVersionGaps = Metric.counter(\"mimic.storage.version_gaps\");\n\n/**\n * Failed WAL appends causing transaction rollback\n */\nexport const walAppendFailures = Metric.counter(\"mimic.storage.wal_append_failures\");\n\n/**\n * ColdStorage load failures during document restore\n */\nexport const coldStorageLoadFailures = Metric.counter(\"mimic.storage.cold_load_failures\");\n\n/**\n * HotStorage getEntries failures during document restore\n */\nexport const hotStorageLoadFailures = Metric.counter(\"mimic.storage.hot_load_failures\");\n\n// =============================================================================\n// Presence Metrics\n// =============================================================================\n\n/**\n * Presence set operations\n */\nexport const presenceUpdates = Metric.counter(\"mimic.presence.updates\");\n\n/**\n * Active presence entries\n */\nexport const presenceActive = Metric.gauge(\"mimic.presence.active\");\n\n// =============================================================================\n// Export namespace\n// =============================================================================\n\nexport const MimicMetrics = {\n // Connection\n connectionsActive,\n connectionsTotal,\n connectionsDuration,\n connectionsErrors,\n\n // Document\n documentsActive,\n documentsCreated,\n documentsRestored,\n documentsEvicted,\n\n // Transaction\n transactionsProcessed,\n transactionsRejected,\n transactionsLatency,\n\n // Storage\n storageSnapshots,\n storageIdleSnapshots,\n storageSnapshotLatency,\n storageWalAppends,\n storageVersionGaps,\n walAppendFailures,\n coldStorageLoadFailures,\n hotStorageLoadFailures,\n\n // Presence\n presenceUpdates,\n presenceActive,\n};\n"],"mappings":";;;;;;;;;;;AAcA,MAAa,oBAAoB,OAAO,MAAM,2BAA2B;;;;AAKzE,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AAKzE,MAAa,sBAAsB,OAAO,UACxC,iCACA,EACE,YAAY,OAAO,sBAAsB;CACvC,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC,EACH,CACF;;;;AAKD,MAAa,oBAAoB,OAAO,QAAQ,2BAA2B;;;;AAS3E,MAAa,kBAAkB,OAAO,MAAM,yBAAyB;;;;AAKrE,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AAKzE,MAAa,oBAAoB,OAAO,QAAQ,2BAA2B;;;;AAK3E,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AASzE,MAAa,wBAAwB,OAAO,QAC1C,+BACD;;;;AAKD,MAAa,uBAAuB,OAAO,QACzC,8BACD;;;;AAKD,MAAa,sBAAsB,OAAO,UACxC,iCACA,EACE,YAAY,OAAO,sBAAsB;CACvC,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC,EACH,CACF;;;;AASD,MAAa,mBAAmB,OAAO,QAAQ,0BAA0B;;;;AAKzE,MAAa,uBAAuB,OAAO,QAAQ,+BAA+B;;;;AAKlF,MAAa,yBAAyB,OAAO,UAC3C,qCACA,EACE,YAAY,OAAO,sBAAsB;CACvC,OAAO;CACP,QAAQ;CACR,OAAO;CACR,CAAC,EACH,CACF;;;;AAKD,MAAa,oBAAoB,OAAO,QAAQ,4BAA4B;;;;AAK5E,MAAa,qBAAqB,OAAO,QAAQ,6BAA6B;;;;AAK9E,MAAa,oBAAoB,OAAO,QAAQ,oCAAoC;;;;AAKpF,MAAa,0BAA0B,OAAO,QAAQ,mCAAmC;;;;AAKzF,MAAa,yBAAyB,OAAO,QAAQ,kCAAkC;;;;AASvF,MAAa,kBAAkB,OAAO,QAAQ,yBAAyB;;;;AAKvE,MAAa,iBAAiB,OAAO,MAAM,wBAAwB;AAMnE,MAAa,eAAe;CAE1B;CACA;CACA;CACA;CAGA;CACA;CACA;CACA;CAGA;CACA;CACA;CAGA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CAGA;CACA;CACD"}
@@ -10,7 +10,7 @@ let effect = require("effect");
10
10
  /**
11
11
  * Context tag for MimicAuthService
12
12
  */
13
- var MimicAuthServiceTag = class extends effect.Context.Tag("@voidhash/mimic-effect/MimicAuthService")() {};
13
+ var MimicAuthServiceTag = class extends effect.ServiceMap.Service()("@voidhash/mimic-effect/MimicAuthService") {};
14
14
  /**
15
15
  * Create a MimicAuthService layer from an Effect that produces the service.
16
16
  *
@@ -1,6 +1,6 @@
1
1
  import { AuthContext, Permission } from "./Types.cjs";
2
2
  import { AuthenticationError } from "./Errors.cjs";
3
- import { Context, Effect, Layer } from "effect";
3
+ import { Effect, Layer, ServiceMap } from "effect";
4
4
 
5
5
  //#region src/MimicAuthService.d.ts
6
6
 
@@ -25,7 +25,7 @@ interface MimicAuthService {
25
25
  */
26
26
  readonly authenticate: (token: string, documentId: string) => Effect.Effect<AuthContext, AuthenticationError>;
27
27
  }
28
- declare const MimicAuthServiceTag_base: Context.TagClass<MimicAuthServiceTag, "@voidhash/mimic-effect/MimicAuthService", MimicAuthService>;
28
+ declare const MimicAuthServiceTag_base: ServiceMap.ServiceClass<MimicAuthServiceTag, "@voidhash/mimic-effect/MimicAuthService", MimicAuthService>;
29
29
  /**
30
30
  * Context tag for MimicAuthService
31
31
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MimicAuthService.d.cts","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAoCC;;;;;AASD;AAmDA;AAyBA;;AAK0B,UAtGT,gBAAA,CAsGS;EAKO;;;;;AA4BjC;;EA7EwB,SAAA,YAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,GA/CjB,MAAA,CAAO,MA+CU,CA/CH,WA+CG,EA/CU,mBA+CV,CAAA;;cA9CvB,wBA8C4C,kBAAA,oBAAA,EAAA,yCAAA,kBAAA,CAAA;;;;AACN,cAtC1B,mBAAA,SAA4B,wBAAA,CAsCF;;;;;;;kBAatB,MAAA;;;;;oBAKS,KAAA,CAAM,MAAM;;;;;;;;kBAoBrB,MAAA;;;;;0BAKS,eAAe;;;;;iCAKR;;;;;;wBAOD,YAAU,KAAA,CAAM,MAAM;;cAqBzC;;uBA7EH,MAAA,CAAO,OAAO,kBAAkB,GAAG,OAC1C,KAAA,CAAM,MAAM,qBAAqB,GAAG"}
1
+ {"version":3,"file":"MimicAuthService.d.cts","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAoCC;;;;;AASD;AAmDA;AAyBA;;AAK0B,UAtGT,gBAAA,CAsGS;EAKO;;;;;AA4BjC;;EA7EwB,SAAA,YAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,GA/CjB,MAAA,CAAO,MA+CU,CA/CH,WA+CG,EA/CU,mBA+CV,CAAA;;cA9CvB,wBA8C4C,yBAAA,oBAAA,EAAA,yCAAA,kBAAA,CAAA;;;;AACN,cAtC1B,mBAAA,SAA4B,wBAAA,CAsCF;;;;;;;kBAatB,MAAA;;;;;oBAKS,KAAA,CAAM,MAAM;;;;;;;;kBAoBrB,MAAA;;;;;0BAKS,eAAe;;;;;iCAKR;;;;;;wBAOD,YAAU,KAAA,CAAM,MAAM;;cAqBzC;;uBA7EH,MAAA,CAAO,OAAO,kBAAkB,GAAG,OAC1C,KAAA,CAAM,MAAM,qBAAqB,GAAG"}
@@ -1,6 +1,6 @@
1
1
  import { AuthContext, Permission } from "./Types.mjs";
2
2
  import { AuthenticationError } from "./Errors.mjs";
3
- import { Context, Effect, Layer } from "effect";
3
+ import { Effect, Layer, ServiceMap } from "effect";
4
4
 
5
5
  //#region src/MimicAuthService.d.ts
6
6
 
@@ -25,7 +25,7 @@ interface MimicAuthService {
25
25
  */
26
26
  readonly authenticate: (token: string, documentId: string) => Effect.Effect<AuthContext, AuthenticationError>;
27
27
  }
28
- declare const MimicAuthServiceTag_base: Context.TagClass<MimicAuthServiceTag, "@voidhash/mimic-effect/MimicAuthService", MimicAuthService>;
28
+ declare const MimicAuthServiceTag_base: ServiceMap.ServiceClass<MimicAuthServiceTag, "@voidhash/mimic-effect/MimicAuthService", MimicAuthService>;
29
29
  /**
30
30
  * Context tag for MimicAuthService
31
31
  */
@@ -1 +1 @@
1
- {"version":3,"file":"MimicAuthService.d.mts","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAoCC;;;;;AASD;AAmDA;AAyBA;;AAK0B,UAtGT,gBAAA,CAsGS;EAKO;;;;;AA4BjC;;EA7EwB,SAAA,YAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,GA/CjB,MAAA,CAAO,MA+CU,CA/CH,WA+CG,EA/CU,mBA+CV,CAAA;;cA9CvB,wBA8C4C,kBAAA,oBAAA,EAAA,yCAAA,kBAAA,CAAA;;;;AACN,cAtC1B,mBAAA,SAA4B,wBAAA,CAsCF;;;;;;;kBAatB,MAAA;;;;;oBAKS,KAAA,CAAM,MAAM;;;;;;;;kBAoBrB,MAAA;;;;;0BAKS,eAAe;;;;;iCAKR;;;;;;wBAOD,YAAU,KAAA,CAAM,MAAM;;cAqBzC;;uBA7EH,MAAA,CAAO,OAAO,kBAAkB,GAAG,OAC1C,KAAA,CAAM,MAAM,qBAAqB,GAAG"}
1
+ {"version":3,"file":"MimicAuthService.d.mts","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":[],"mappings":";;;;;;;;AAoCC;;;;;AASD;AAmDA;AAyBA;;AAK0B,UAtGT,gBAAA,CAsGS;EAKO;;;;;AA4BjC;;EA7EwB,SAAA,YAAA,EAAA,CAAA,KAAA,EAAA,MAAA,EAAA,UAAA,EAAA,MAAA,EAAA,GA/CjB,MAAA,CAAO,MA+CU,CA/CH,WA+CG,EA/CU,mBA+CV,CAAA;;cA9CvB,wBA8C4C,yBAAA,oBAAA,EAAA,yCAAA,kBAAA,CAAA;;;;AACN,cAtC1B,mBAAA,SAA4B,wBAAA,CAsCF;;;;;;;kBAatB,MAAA;;;;;oBAKS,KAAA,CAAM,MAAM;;;;;;;;kBAoBrB,MAAA;;;;;0BAKS,eAAe;;;;;iCAKR;;;;;;wBAOD,YAAU,KAAA,CAAM,MAAM;;cAqBzC;;uBA7EH,MAAA,CAAO,OAAO,kBAAkB,GAAG,OAC1C,KAAA,CAAM,MAAM,qBAAqB,GAAG"}
@@ -1,5 +1,5 @@
1
1
  import { AuthenticationError } from "./Errors.mjs";
2
- import { Context, Effect, Layer } from "effect";
2
+ import { Effect, Layer, ServiceMap } from "effect";
3
3
 
4
4
  //#region src/MimicAuthService.ts
5
5
  /**
@@ -10,7 +10,7 @@ import { Context, Effect, Layer } from "effect";
10
10
  /**
11
11
  * Context tag for MimicAuthService
12
12
  */
13
- var MimicAuthServiceTag = class extends Context.Tag("@voidhash/mimic-effect/MimicAuthService")() {};
13
+ var MimicAuthServiceTag = class extends ServiceMap.Service()("@voidhash/mimic-effect/MimicAuthService") {};
14
14
  /**
15
15
  * Create a MimicAuthService layer from an Effect that produces the service.
16
16
  *
@@ -1 +1 @@
1
- {"version":3,"file":"MimicAuthService.mjs","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":["/**\n * @voidhash/mimic-effect - MimicAuthService\n *\n * Authentication and authorization service interface and implementations.\n */\nimport { Context, Effect, Layer } from \"effect\";\nimport type { AuthContext, Permission } from \"./Types\";\nimport { AuthenticationError } from \"./Errors\";\n\n// =============================================================================\n// MimicAuthService Interface\n// =============================================================================\n\n/**\n * MimicAuthService interface for authentication and authorization.\n *\n * The `authenticate` method receives the token from the client's auth message\n * and the document ID being accessed. It should return an AuthContext on success\n * or fail with AuthenticationError on failure.\n *\n * The permission in AuthContext determines what the user can do:\n * - \"read\": Can subscribe, receive transactions, get snapshots\n * - \"write\": All of the above, plus can submit transactions and set presence\n */\nexport interface MimicAuthService {\n /**\n * Authenticate a connection and return authorization context.\n *\n * @param token - The token provided by the client\n * @param documentId - The document ID being accessed\n * @returns AuthContext with userId and permission level\n */\n readonly authenticate: (\n token: string,\n documentId: string\n ) => Effect.Effect<AuthContext, AuthenticationError>;\n}\n\n// =============================================================================\n// Context Tag\n// =============================================================================\n\n/**\n * Context tag for MimicAuthService\n */\nexport class MimicAuthServiceTag extends Context.Tag(\n \"@voidhash/mimic-effect/MimicAuthService\"\n)<MimicAuthServiceTag, MimicAuthService>() {}\n\n// =============================================================================\n// Factory\n// =============================================================================\n\n/**\n * Create a MimicAuthService layer from an Effect that produces the service.\n *\n * This allows you to access other Effect services when implementing authentication.\n *\n * @example\n * ```typescript\n * const Auth = MimicAuthService.make(\n * Effect.gen(function*() {\n * const db = yield* DatabaseService\n * const jwt = yield* JwtService\n *\n * return {\n * authenticate: (token, documentId) =>\n * Effect.gen(function*() {\n * const payload = yield* jwt.verify(token).pipe(\n * Effect.mapError(() => new AuthenticationError({ reason: \"Invalid token\" }))\n * )\n *\n * const permission = yield* db.getDocumentPermission(payload.userId, documentId)\n *\n * return { userId: payload.userId, permission }\n * })\n * }\n * })\n * )\n * ```\n */\nexport const make = <E, R>(\n effect: Effect.Effect<MimicAuthService, E, R>\n): Layer.Layer<MimicAuthServiceTag, E, R> =>\n Layer.effect(MimicAuthServiceTag, effect);\n\n// =============================================================================\n// NoAuth Implementation\n// =============================================================================\n\n/**\n * No-authentication implementation.\n *\n * Everyone gets write access with userId \"anonymous\".\n * ONLY USE FOR DEVELOPMENT/TESTING.\n */\nexport namespace NoAuth {\n /**\n * Create a NoAuth layer.\n * All connections are authenticated with write permission.\n */\n export const make = (): Layer.Layer<MimicAuthServiceTag> =>\n Layer.succeed(MimicAuthServiceTag, {\n authenticate: (_token, _documentId) =>\n Effect.succeed({\n userId: \"anonymous\",\n permission: \"write\" as const,\n }),\n });\n}\n\n// =============================================================================\n// Static Implementation\n// =============================================================================\n\n/**\n * Static permissions implementation.\n *\n * Permissions are defined at configuration time.\n * The token is treated as the userId.\n */\nexport namespace Static {\n export interface Options {\n /**\n * Map of userId (token) to permission level\n */\n readonly permissions: Record<string, Permission>;\n /**\n * Default permission for users not in the permissions map.\n * If undefined, unknown users will fail authentication.\n */\n readonly defaultPermission?: Permission;\n }\n\n /**\n * Create a Static auth layer.\n * The token is treated as the userId, and permissions are looked up from the config.\n */\n export const make = (options: Options): Layer.Layer<MimicAuthServiceTag> =>\n Layer.succeed(MimicAuthServiceTag, {\n authenticate: (token, _documentId) => {\n const permission = options.permissions[token] ?? options.defaultPermission;\n if (permission === undefined) {\n return Effect.fail(\n new AuthenticationError({ reason: \"Unknown user\" })\n );\n }\n return Effect.succeed({\n userId: token,\n permission,\n });\n },\n });\n}\n\n// =============================================================================\n// Re-export namespace\n// =============================================================================\n\nexport const MimicAuthService = {\n Tag: MimicAuthServiceTag,\n make,\n NoAuth,\n Static,\n};\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,sBAAb,cAAyC,QAAQ,IAC/C,0CACD,EAAyC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkC3C,MAAa,QACX,WAEA,MAAM,OAAO,qBAAqB,OAAO;;;sBAkBvC,MAAM,QAAQ,qBAAqB,EACjC,eAAe,QAAQ,gBACrB,OAAO,QAAQ;EACb,QAAQ;EACR,YAAY;EACb,CAAC,EACL,CAAC;;;;iBA8BiB,YACnB,MAAM,QAAQ,qBAAqB,EACjC,eAAe,OAAO,gBAAgB;;EACpC,MAAM,sCAAa,QAAQ,YAAY,+EAAU,QAAQ;AACzD,MAAI,eAAe,OACjB,QAAO,OAAO,KACZ,IAAI,oBAAoB,EAAE,QAAQ,gBAAgB,CAAC,CACpD;AAEH,SAAO,OAAO,QAAQ;GACpB,QAAQ;GACR;GACD,CAAC;IAEL,CAAC;;AAON,MAAa,mBAAmB;CAC9B,KAAK;CACL;CACA;CACA;CACD"}
1
+ {"version":3,"file":"MimicAuthService.mjs","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":["/**\n * @voidhash/mimic-effect - MimicAuthService\n *\n * Authentication and authorization service interface and implementations.\n */\nimport { Effect, Layer, ServiceMap } from \"effect\";\nimport type { AuthContext, Permission } from \"./Types\";\nimport { AuthenticationError } from \"./Errors\";\n\n// =============================================================================\n// MimicAuthService Interface\n// =============================================================================\n\n/**\n * MimicAuthService interface for authentication and authorization.\n *\n * The `authenticate` method receives the token from the client's auth message\n * and the document ID being accessed. It should return an AuthContext on success\n * or fail with AuthenticationError on failure.\n *\n * The permission in AuthContext determines what the user can do:\n * - \"read\": Can subscribe, receive transactions, get snapshots\n * - \"write\": All of the above, plus can submit transactions and set presence\n */\nexport interface MimicAuthService {\n /**\n * Authenticate a connection and return authorization context.\n *\n * @param token - The token provided by the client\n * @param documentId - The document ID being accessed\n * @returns AuthContext with userId and permission level\n */\n readonly authenticate: (\n token: string,\n documentId: string\n ) => Effect.Effect<AuthContext, AuthenticationError>;\n}\n\n// =============================================================================\n// Context Tag\n// =============================================================================\n\n/**\n * Context tag for MimicAuthService\n */\nexport class MimicAuthServiceTag extends ServiceMap.Service<MimicAuthServiceTag, MimicAuthService>()(\n \"@voidhash/mimic-effect/MimicAuthService\"\n) {}\n\n// =============================================================================\n// Factory\n// =============================================================================\n\n/**\n * Create a MimicAuthService layer from an Effect that produces the service.\n *\n * This allows you to access other Effect services when implementing authentication.\n *\n * @example\n * ```typescript\n * const Auth = MimicAuthService.make(\n * Effect.gen(function*() {\n * const db = yield* DatabaseService\n * const jwt = yield* JwtService\n *\n * return {\n * authenticate: (token, documentId) =>\n * Effect.gen(function*() {\n * const payload = yield* jwt.verify(token).pipe(\n * Effect.mapError(() => new AuthenticationError({ reason: \"Invalid token\" }))\n * )\n *\n * const permission = yield* db.getDocumentPermission(payload.userId, documentId)\n *\n * return { userId: payload.userId, permission }\n * })\n * }\n * })\n * )\n * ```\n */\nexport const make = <E, R>(\n effect: Effect.Effect<MimicAuthService, E, R>\n): Layer.Layer<MimicAuthServiceTag, E, R> =>\n Layer.effect(MimicAuthServiceTag, effect);\n\n// =============================================================================\n// NoAuth Implementation\n// =============================================================================\n\n/**\n * No-authentication implementation.\n *\n * Everyone gets write access with userId \"anonymous\".\n * ONLY USE FOR DEVELOPMENT/TESTING.\n */\nexport namespace NoAuth {\n /**\n * Create a NoAuth layer.\n * All connections are authenticated with write permission.\n */\n export const make = (): Layer.Layer<MimicAuthServiceTag> =>\n Layer.succeed(MimicAuthServiceTag, {\n authenticate: (_token, _documentId) =>\n Effect.succeed({\n userId: \"anonymous\",\n permission: \"write\" as const,\n }),\n });\n}\n\n// =============================================================================\n// Static Implementation\n// =============================================================================\n\n/**\n * Static permissions implementation.\n *\n * Permissions are defined at configuration time.\n * The token is treated as the userId.\n */\nexport namespace Static {\n export interface Options {\n /**\n * Map of userId (token) to permission level\n */\n readonly permissions: Record<string, Permission>;\n /**\n * Default permission for users not in the permissions map.\n * If undefined, unknown users will fail authentication.\n */\n readonly defaultPermission?: Permission;\n }\n\n /**\n * Create a Static auth layer.\n * The token is treated as the userId, and permissions are looked up from the config.\n */\n export const make = (options: Options): Layer.Layer<MimicAuthServiceTag> =>\n Layer.succeed(MimicAuthServiceTag, {\n authenticate: (token, _documentId) => {\n const permission = options.permissions[token] ?? options.defaultPermission;\n if (permission === undefined) {\n return Effect.fail(\n new AuthenticationError({ reason: \"Unknown user\" })\n );\n }\n return Effect.succeed({\n userId: token,\n permission,\n });\n },\n });\n}\n\n// =============================================================================\n// Re-export namespace\n// =============================================================================\n\nexport const MimicAuthService = {\n Tag: MimicAuthServiceTag,\n make,\n NoAuth,\n Static,\n};\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,sBAAb,cAAyC,WAAW,SAAgD,CAClG,0CACD,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCF,MAAa,QACX,WAEA,MAAM,OAAO,qBAAqB,OAAO;;;sBAkBvC,MAAM,QAAQ,qBAAqB,EACjC,eAAe,QAAQ,gBACrB,OAAO,QAAQ;EACb,QAAQ;EACR,YAAY;EACb,CAAC,EACL,CAAC;;;;iBA8BiB,YACnB,MAAM,QAAQ,qBAAqB,EACjC,eAAe,OAAO,gBAAgB;;EACpC,MAAM,sCAAa,QAAQ,YAAY,+EAAU,QAAQ;AACzD,MAAI,eAAe,OACjB,QAAO,OAAO,KACZ,IAAI,oBAAoB,EAAE,QAAQ,gBAAgB,CAAC,CACpD;AAEH,SAAO,OAAO,QAAQ;GACpB,QAAQ;GACR;GACD,CAAC;IAEL,CAAC;;AAON,MAAa,mBAAmB;CAC9B,KAAK;CACL;CACA;CACA;CACD"}