@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.
- package/.turbo/turbo-build.log +136 -90
- package/README.md +385 -0
- package/dist/ColdStorage.cjs +60 -0
- package/dist/ColdStorage.d.cts +53 -0
- package/dist/ColdStorage.d.cts.map +1 -0
- package/dist/ColdStorage.d.mts +53 -0
- package/dist/ColdStorage.d.mts.map +1 -0
- package/dist/ColdStorage.mjs +60 -0
- package/dist/ColdStorage.mjs.map +1 -0
- package/dist/DocumentManager.cjs +263 -82
- package/dist/DocumentManager.d.cts +44 -22
- package/dist/DocumentManager.d.cts.map +1 -1
- package/dist/DocumentManager.d.mts +44 -22
- package/dist/DocumentManager.d.mts.map +1 -1
- package/dist/DocumentManager.mjs +259 -67
- package/dist/DocumentManager.mjs.map +1 -1
- package/dist/Errors.cjs +54 -0
- package/dist/Errors.d.cts +96 -0
- package/dist/Errors.d.cts.map +1 -0
- package/dist/Errors.d.mts +96 -0
- package/dist/Errors.d.mts.map +1 -0
- package/dist/Errors.mjs +48 -0
- package/dist/Errors.mjs.map +1 -0
- package/dist/HotStorage.cjs +100 -0
- package/dist/HotStorage.d.cts +70 -0
- package/dist/HotStorage.d.cts.map +1 -0
- package/dist/HotStorage.d.mts +70 -0
- package/dist/HotStorage.d.mts.map +1 -0
- package/dist/HotStorage.mjs +100 -0
- package/dist/HotStorage.mjs.map +1 -0
- package/dist/Metrics.cjs +143 -0
- package/dist/Metrics.d.cts +31 -0
- package/dist/Metrics.d.cts.map +1 -0
- package/dist/Metrics.d.mts +31 -0
- package/dist/Metrics.d.mts.map +1 -0
- package/dist/Metrics.mjs +126 -0
- package/dist/Metrics.mjs.map +1 -0
- package/dist/MimicAuthService.cjs +61 -45
- package/dist/MimicAuthService.d.cts +61 -48
- package/dist/MimicAuthService.d.cts.map +1 -1
- package/dist/MimicAuthService.d.mts +61 -48
- package/dist/MimicAuthService.d.mts.map +1 -1
- package/dist/MimicAuthService.mjs +60 -36
- package/dist/MimicAuthService.mjs.map +1 -1
- package/dist/MimicClusterServerEngine.cjs +521 -0
- package/dist/MimicClusterServerEngine.d.cts +17 -0
- package/dist/MimicClusterServerEngine.d.cts.map +1 -0
- package/dist/MimicClusterServerEngine.d.mts +17 -0
- package/dist/MimicClusterServerEngine.d.mts.map +1 -0
- package/dist/MimicClusterServerEngine.mjs +523 -0
- package/dist/MimicClusterServerEngine.mjs.map +1 -0
- package/dist/MimicServer.cjs +205 -96
- package/dist/MimicServer.d.cts +9 -110
- package/dist/MimicServer.d.cts.map +1 -1
- package/dist/MimicServer.d.mts +9 -110
- package/dist/MimicServer.d.mts.map +1 -1
- package/dist/MimicServer.mjs +206 -90
- package/dist/MimicServer.mjs.map +1 -1
- package/dist/MimicServerEngine.cjs +97 -0
- package/dist/MimicServerEngine.d.cts +78 -0
- package/dist/MimicServerEngine.d.cts.map +1 -0
- package/dist/MimicServerEngine.d.mts +78 -0
- package/dist/MimicServerEngine.d.mts.map +1 -0
- package/dist/MimicServerEngine.mjs +97 -0
- package/dist/MimicServerEngine.mjs.map +1 -0
- package/dist/PresenceManager.cjs +75 -91
- package/dist/PresenceManager.d.cts +17 -66
- package/dist/PresenceManager.d.cts.map +1 -1
- package/dist/PresenceManager.d.mts +17 -66
- package/dist/PresenceManager.d.mts.map +1 -1
- package/dist/PresenceManager.mjs +74 -78
- package/dist/PresenceManager.mjs.map +1 -1
- package/dist/Protocol.cjs +146 -0
- package/dist/Protocol.d.cts +203 -0
- package/dist/Protocol.d.cts.map +1 -0
- package/dist/Protocol.d.mts +203 -0
- package/dist/Protocol.d.mts.map +1 -0
- package/dist/Protocol.mjs +132 -0
- package/dist/Protocol.mjs.map +1 -0
- package/dist/Types.d.cts +172 -0
- package/dist/Types.d.cts.map +1 -0
- package/dist/Types.d.mts +172 -0
- package/dist/Types.d.mts.map +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -25
- package/dist/_virtual/rolldown_runtime.mjs +4 -1
- package/dist/index.cjs +37 -75
- package/dist/index.d.cts +13 -12
- package/dist/index.d.mts +13 -12
- package/dist/index.mjs +12 -12
- package/dist/testing/ColdStorageTestSuite.cjs +508 -0
- package/dist/testing/ColdStorageTestSuite.d.cts +36 -0
- package/dist/testing/ColdStorageTestSuite.d.cts.map +1 -0
- package/dist/testing/ColdStorageTestSuite.d.mts +36 -0
- package/dist/testing/ColdStorageTestSuite.d.mts.map +1 -0
- package/dist/testing/ColdStorageTestSuite.mjs +508 -0
- package/dist/testing/ColdStorageTestSuite.mjs.map +1 -0
- package/dist/testing/FailingStorage.cjs +135 -0
- package/dist/testing/FailingStorage.d.cts +43 -0
- package/dist/testing/FailingStorage.d.cts.map +1 -0
- package/dist/testing/FailingStorage.d.mts +43 -0
- package/dist/testing/FailingStorage.d.mts.map +1 -0
- package/dist/testing/FailingStorage.mjs +136 -0
- package/dist/testing/FailingStorage.mjs.map +1 -0
- package/dist/testing/HotStorageTestSuite.cjs +585 -0
- package/dist/testing/HotStorageTestSuite.d.cts +40 -0
- package/dist/testing/HotStorageTestSuite.d.cts.map +1 -0
- package/dist/testing/HotStorageTestSuite.d.mts +40 -0
- package/dist/testing/HotStorageTestSuite.d.mts.map +1 -0
- package/dist/testing/HotStorageTestSuite.mjs +585 -0
- package/dist/testing/HotStorageTestSuite.mjs.map +1 -0
- package/dist/testing/StorageIntegrationTestSuite.cjs +349 -0
- package/dist/testing/StorageIntegrationTestSuite.d.cts +35 -0
- package/dist/testing/StorageIntegrationTestSuite.d.cts.map +1 -0
- package/dist/testing/StorageIntegrationTestSuite.d.mts +35 -0
- package/dist/testing/StorageIntegrationTestSuite.d.mts.map +1 -0
- package/dist/testing/StorageIntegrationTestSuite.mjs +349 -0
- package/dist/testing/StorageIntegrationTestSuite.mjs.map +1 -0
- package/dist/testing/assertions.cjs +114 -0
- package/dist/testing/assertions.mjs +109 -0
- package/dist/testing/assertions.mjs.map +1 -0
- package/dist/testing/index.cjs +14 -0
- package/dist/testing/index.d.cts +6 -0
- package/dist/testing/index.d.mts +6 -0
- package/dist/testing/index.mjs +7 -0
- package/dist/testing/types.cjs +15 -0
- package/dist/testing/types.d.cts +90 -0
- package/dist/testing/types.d.cts.map +1 -0
- package/dist/testing/types.d.mts +90 -0
- package/dist/testing/types.d.mts.map +1 -0
- package/dist/testing/types.mjs +16 -0
- package/dist/testing/types.mjs.map +1 -0
- package/package.json +18 -3
- package/src/ColdStorage.ts +136 -0
- package/src/DocumentManager.ts +550 -190
- package/src/Errors.ts +114 -0
- package/src/HotStorage.ts +239 -0
- package/src/Metrics.ts +187 -0
- package/src/MimicAuthService.ts +126 -64
- package/src/MimicClusterServerEngine.ts +946 -0
- package/src/MimicServer.ts +448 -195
- package/src/MimicServerEngine.ts +276 -0
- package/src/PresenceManager.ts +169 -240
- package/src/Protocol.ts +350 -0
- package/src/Types.ts +231 -0
- package/src/index.ts +57 -23
- package/src/testing/ColdStorageTestSuite.ts +589 -0
- package/src/testing/FailingStorage.ts +286 -0
- package/src/testing/HotStorageTestSuite.ts +762 -0
- package/src/testing/StorageIntegrationTestSuite.ts +504 -0
- package/src/testing/assertions.ts +181 -0
- package/src/testing/index.ts +83 -0
- package/src/testing/types.ts +100 -0
- package/tests/ColdStorage.test.ts +24 -0
- package/tests/DocumentManager.test.ts +158 -287
- package/tests/HotStorage.test.ts +24 -0
- package/tests/MimicAuthService.test.ts +102 -134
- package/tests/MimicClusterServerEngine.test.ts +587 -0
- package/tests/MimicServer.test.ts +90 -226
- package/tests/MimicServerEngine.test.ts +521 -0
- package/tests/PresenceManager.test.ts +22 -63
- package/tests/Protocol.test.ts +190 -0
- package/tests/StorageIntegration.test.ts +259 -0
- package/tsconfig.json +1 -1
- package/tsdown.config.ts +1 -1
- package/dist/DocumentProtocol.cjs +0 -94
- package/dist/DocumentProtocol.d.cts +0 -113
- package/dist/DocumentProtocol.d.cts.map +0 -1
- package/dist/DocumentProtocol.d.mts +0 -113
- package/dist/DocumentProtocol.d.mts.map +0 -1
- package/dist/DocumentProtocol.mjs +0 -89
- package/dist/DocumentProtocol.mjs.map +0 -1
- package/dist/MimicConfig.cjs +0 -60
- package/dist/MimicConfig.d.cts +0 -141
- package/dist/MimicConfig.d.cts.map +0 -1
- package/dist/MimicConfig.d.mts +0 -141
- package/dist/MimicConfig.d.mts.map +0 -1
- package/dist/MimicConfig.mjs +0 -50
- package/dist/MimicConfig.mjs.map +0 -1
- package/dist/MimicDataStorage.cjs +0 -83
- package/dist/MimicDataStorage.d.cts +0 -113
- package/dist/MimicDataStorage.d.cts.map +0 -1
- package/dist/MimicDataStorage.d.mts +0 -113
- package/dist/MimicDataStorage.d.mts.map +0 -1
- package/dist/MimicDataStorage.mjs +0 -74
- package/dist/MimicDataStorage.mjs.map +0 -1
- package/dist/WebSocketHandler.cjs +0 -365
- package/dist/WebSocketHandler.d.cts +0 -34
- package/dist/WebSocketHandler.d.cts.map +0 -1
- package/dist/WebSocketHandler.d.mts +0 -34
- package/dist/WebSocketHandler.d.mts.map +0 -1
- package/dist/WebSocketHandler.mjs +0 -355
- package/dist/WebSocketHandler.mjs.map +0 -1
- package/dist/auth/NoAuth.cjs +0 -43
- package/dist/auth/NoAuth.d.cts +0 -22
- package/dist/auth/NoAuth.d.cts.map +0 -1
- package/dist/auth/NoAuth.d.mts +0 -22
- package/dist/auth/NoAuth.d.mts.map +0 -1
- package/dist/auth/NoAuth.mjs +0 -36
- package/dist/auth/NoAuth.mjs.map +0 -1
- package/dist/errors.cjs +0 -74
- package/dist/errors.d.cts +0 -89
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts +0 -89
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs +0 -67
- package/dist/errors.mjs.map +0 -1
- package/dist/storage/InMemoryDataStorage.cjs +0 -57
- package/dist/storage/InMemoryDataStorage.d.cts +0 -19
- package/dist/storage/InMemoryDataStorage.d.cts.map +0 -1
- package/dist/storage/InMemoryDataStorage.d.mts +0 -19
- package/dist/storage/InMemoryDataStorage.d.mts.map +0 -1
- package/dist/storage/InMemoryDataStorage.mjs +0 -48
- package/dist/storage/InMemoryDataStorage.mjs.map +0 -1
- package/src/DocumentProtocol.ts +0 -112
- package/src/MimicConfig.ts +0 -211
- package/src/MimicDataStorage.ts +0 -157
- package/src/WebSocketHandler.ts +0 -735
- package/src/auth/NoAuth.ts +0 -46
- package/src/errors.ts +0 -113
- package/src/storage/InMemoryDataStorage.ts +0 -66
- package/tests/DocumentProtocol.test.ts +0 -113
- package/tests/InMemoryDataStorage.test.ts +0 -190
- package/tests/MimicConfig.test.ts +0 -290
- package/tests/MimicDataStorage.test.ts +0 -190
- package/tests/NoAuth.test.ts +0 -94
- package/tests/WebSocketHandler.test.ts +0 -321
- package/tests/errors.test.ts +0 -77
package/dist/Metrics.cjs
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
let effect = require("effect");
|
|
2
|
+
|
|
3
|
+
//#region src/Metrics.ts
|
|
4
|
+
/**
|
|
5
|
+
* @voidhash/mimic-effect - Metrics
|
|
6
|
+
*
|
|
7
|
+
* Observability metrics using Effect's Metric API.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Current active WebSocket connections
|
|
11
|
+
*/
|
|
12
|
+
const connectionsActive = effect.Metric.gauge("mimic.connections.active");
|
|
13
|
+
/**
|
|
14
|
+
* Total connections over lifetime
|
|
15
|
+
*/
|
|
16
|
+
const connectionsTotal = effect.Metric.counter("mimic.connections.total");
|
|
17
|
+
/**
|
|
18
|
+
* Connection duration histogram (milliseconds)
|
|
19
|
+
*/
|
|
20
|
+
const connectionsDuration = effect.Metric.histogram("mimic.connections.duration_ms", effect.MetricBoundaries.exponential({
|
|
21
|
+
start: 100,
|
|
22
|
+
factor: 2,
|
|
23
|
+
count: 15
|
|
24
|
+
}));
|
|
25
|
+
/**
|
|
26
|
+
* Connection errors (auth failures, etc.)
|
|
27
|
+
*/
|
|
28
|
+
const connectionsErrors = effect.Metric.counter("mimic.connections.errors");
|
|
29
|
+
/**
|
|
30
|
+
* Documents currently in memory
|
|
31
|
+
*/
|
|
32
|
+
const documentsActive = effect.Metric.gauge("mimic.documents.active");
|
|
33
|
+
/**
|
|
34
|
+
* New documents created
|
|
35
|
+
*/
|
|
36
|
+
const documentsCreated = effect.Metric.counter("mimic.documents.created");
|
|
37
|
+
/**
|
|
38
|
+
* Documents restored from storage
|
|
39
|
+
*/
|
|
40
|
+
const documentsRestored = effect.Metric.counter("mimic.documents.restored");
|
|
41
|
+
/**
|
|
42
|
+
* Documents garbage collected (evicted)
|
|
43
|
+
*/
|
|
44
|
+
const documentsEvicted = effect.Metric.counter("mimic.documents.evicted");
|
|
45
|
+
/**
|
|
46
|
+
* Successfully processed transactions
|
|
47
|
+
*/
|
|
48
|
+
const transactionsProcessed = effect.Metric.counter("mimic.transactions.processed");
|
|
49
|
+
/**
|
|
50
|
+
* Rejected transactions
|
|
51
|
+
*/
|
|
52
|
+
const transactionsRejected = effect.Metric.counter("mimic.transactions.rejected");
|
|
53
|
+
/**
|
|
54
|
+
* Transaction processing latency histogram (milliseconds)
|
|
55
|
+
*/
|
|
56
|
+
const transactionsLatency = effect.Metric.histogram("mimic.transactions.latency_ms", effect.MetricBoundaries.exponential({
|
|
57
|
+
start: .1,
|
|
58
|
+
factor: 2,
|
|
59
|
+
count: 15
|
|
60
|
+
}));
|
|
61
|
+
/**
|
|
62
|
+
* Snapshots saved to ColdStorage
|
|
63
|
+
*/
|
|
64
|
+
const storageSnapshots = effect.Metric.counter("mimic.storage.snapshots");
|
|
65
|
+
/**
|
|
66
|
+
* Snapshot save duration histogram (milliseconds)
|
|
67
|
+
*/
|
|
68
|
+
const storageSnapshotLatency = effect.Metric.histogram("mimic.storage.snapshot_latency_ms", effect.MetricBoundaries.exponential({
|
|
69
|
+
start: 1,
|
|
70
|
+
factor: 2,
|
|
71
|
+
count: 12
|
|
72
|
+
}));
|
|
73
|
+
/**
|
|
74
|
+
* WAL entries written to HotStorage
|
|
75
|
+
*/
|
|
76
|
+
const storageWalAppends = effect.Metric.counter("mimic.storage.wal_appends");
|
|
77
|
+
/**
|
|
78
|
+
* Version gaps detected during WAL replay
|
|
79
|
+
*/
|
|
80
|
+
const storageVersionGaps = effect.Metric.counter("mimic.storage.version_gaps");
|
|
81
|
+
/**
|
|
82
|
+
* Failed WAL appends causing transaction rollback
|
|
83
|
+
*/
|
|
84
|
+
const walAppendFailures = effect.Metric.counter("mimic.storage.wal_append_failures");
|
|
85
|
+
/**
|
|
86
|
+
* ColdStorage load failures during document restore
|
|
87
|
+
*/
|
|
88
|
+
const coldStorageLoadFailures = effect.Metric.counter("mimic.storage.cold_load_failures");
|
|
89
|
+
/**
|
|
90
|
+
* HotStorage getEntries failures during document restore
|
|
91
|
+
*/
|
|
92
|
+
const hotStorageLoadFailures = effect.Metric.counter("mimic.storage.hot_load_failures");
|
|
93
|
+
/**
|
|
94
|
+
* Presence set operations
|
|
95
|
+
*/
|
|
96
|
+
const presenceUpdates = effect.Metric.counter("mimic.presence.updates");
|
|
97
|
+
/**
|
|
98
|
+
* Active presence entries
|
|
99
|
+
*/
|
|
100
|
+
const presenceActive = effect.Metric.gauge("mimic.presence.active");
|
|
101
|
+
const MimicMetrics = {
|
|
102
|
+
connectionsActive,
|
|
103
|
+
connectionsTotal,
|
|
104
|
+
connectionsDuration,
|
|
105
|
+
connectionsErrors,
|
|
106
|
+
documentsActive,
|
|
107
|
+
documentsCreated,
|
|
108
|
+
documentsRestored,
|
|
109
|
+
documentsEvicted,
|
|
110
|
+
transactionsProcessed,
|
|
111
|
+
transactionsRejected,
|
|
112
|
+
transactionsLatency,
|
|
113
|
+
storageSnapshots,
|
|
114
|
+
storageSnapshotLatency,
|
|
115
|
+
storageWalAppends,
|
|
116
|
+
storageVersionGaps,
|
|
117
|
+
walAppendFailures,
|
|
118
|
+
coldStorageLoadFailures,
|
|
119
|
+
hotStorageLoadFailures,
|
|
120
|
+
presenceUpdates,
|
|
121
|
+
presenceActive
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
exports.MimicMetrics = MimicMetrics;
|
|
126
|
+
exports.connectionsActive = connectionsActive;
|
|
127
|
+
exports.connectionsDuration = connectionsDuration;
|
|
128
|
+
exports.connectionsErrors = connectionsErrors;
|
|
129
|
+
exports.connectionsTotal = connectionsTotal;
|
|
130
|
+
exports.documentsActive = documentsActive;
|
|
131
|
+
exports.documentsCreated = documentsCreated;
|
|
132
|
+
exports.documentsEvicted = documentsEvicted;
|
|
133
|
+
exports.documentsRestored = documentsRestored;
|
|
134
|
+
exports.presenceActive = presenceActive;
|
|
135
|
+
exports.presenceUpdates = presenceUpdates;
|
|
136
|
+
exports.storageSnapshotLatency = storageSnapshotLatency;
|
|
137
|
+
exports.storageSnapshots = storageSnapshots;
|
|
138
|
+
exports.storageVersionGaps = storageVersionGaps;
|
|
139
|
+
exports.storageWalAppends = storageWalAppends;
|
|
140
|
+
exports.transactionsLatency = transactionsLatency;
|
|
141
|
+
exports.transactionsProcessed = transactionsProcessed;
|
|
142
|
+
exports.transactionsRejected = transactionsRejected;
|
|
143
|
+
exports.walAppendFailures = walAppendFailures;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Metric } from "effect";
|
|
2
|
+
import * as effect_MetricKeyType0 from "effect/MetricKeyType";
|
|
3
|
+
import * as effect_MetricState0 from "effect/MetricState";
|
|
4
|
+
|
|
5
|
+
//#region src/Metrics.d.ts
|
|
6
|
+
|
|
7
|
+
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
|
+
storageSnapshotLatency: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
|
|
21
|
+
storageWalAppends: Metric.Metric.Counter<number>;
|
|
22
|
+
storageVersionGaps: Metric.Metric.Counter<number>;
|
|
23
|
+
walAppendFailures: Metric.Metric.Counter<number>;
|
|
24
|
+
coldStorageLoadFailures: Metric.Metric.Counter<number>;
|
|
25
|
+
hotStorageLoadFailures: Metric.Metric.Counter<number>;
|
|
26
|
+
presenceUpdates: Metric.Metric.Counter<number>;
|
|
27
|
+
presenceActive: Metric.Metric.Gauge<number>;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { MimicMetrics };
|
|
31
|
+
//# sourceMappingURL=Metrics.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metrics.d.cts","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":[],"mappings":";;;;;;cA4Ja"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Metric } from "effect";
|
|
2
|
+
import * as effect_MetricKeyType0 from "effect/MetricKeyType";
|
|
3
|
+
import * as effect_MetricState0 from "effect/MetricState";
|
|
4
|
+
|
|
5
|
+
//#region src/Metrics.d.ts
|
|
6
|
+
|
|
7
|
+
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
|
+
storageSnapshotLatency: Metric.Metric<effect_MetricKeyType0.MetricKeyType.Histogram, number, effect_MetricState0.MetricState.Histogram>;
|
|
21
|
+
storageWalAppends: Metric.Metric.Counter<number>;
|
|
22
|
+
storageVersionGaps: Metric.Metric.Counter<number>;
|
|
23
|
+
walAppendFailures: Metric.Metric.Counter<number>;
|
|
24
|
+
coldStorageLoadFailures: Metric.Metric.Counter<number>;
|
|
25
|
+
hotStorageLoadFailures: Metric.Metric.Counter<number>;
|
|
26
|
+
presenceUpdates: Metric.Metric.Counter<number>;
|
|
27
|
+
presenceActive: Metric.Metric.Gauge<number>;
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|
|
30
|
+
export { MimicMetrics };
|
|
31
|
+
//# sourceMappingURL=Metrics.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metrics.d.mts","names":[],"sources":["../src/Metrics.ts"],"sourcesContent":[],"mappings":";;;;;;cA4Ja"}
|
package/dist/Metrics.mjs
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Metric, MetricBoundaries } from "effect";
|
|
2
|
+
|
|
3
|
+
//#region src/Metrics.ts
|
|
4
|
+
/**
|
|
5
|
+
* @voidhash/mimic-effect - Metrics
|
|
6
|
+
*
|
|
7
|
+
* Observability metrics using Effect's Metric API.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Current active WebSocket connections
|
|
11
|
+
*/
|
|
12
|
+
const connectionsActive = Metric.gauge("mimic.connections.active");
|
|
13
|
+
/**
|
|
14
|
+
* Total connections over lifetime
|
|
15
|
+
*/
|
|
16
|
+
const connectionsTotal = Metric.counter("mimic.connections.total");
|
|
17
|
+
/**
|
|
18
|
+
* Connection duration histogram (milliseconds)
|
|
19
|
+
*/
|
|
20
|
+
const connectionsDuration = Metric.histogram("mimic.connections.duration_ms", MetricBoundaries.exponential({
|
|
21
|
+
start: 100,
|
|
22
|
+
factor: 2,
|
|
23
|
+
count: 15
|
|
24
|
+
}));
|
|
25
|
+
/**
|
|
26
|
+
* Connection errors (auth failures, etc.)
|
|
27
|
+
*/
|
|
28
|
+
const connectionsErrors = Metric.counter("mimic.connections.errors");
|
|
29
|
+
/**
|
|
30
|
+
* Documents currently in memory
|
|
31
|
+
*/
|
|
32
|
+
const documentsActive = Metric.gauge("mimic.documents.active");
|
|
33
|
+
/**
|
|
34
|
+
* New documents created
|
|
35
|
+
*/
|
|
36
|
+
const documentsCreated = Metric.counter("mimic.documents.created");
|
|
37
|
+
/**
|
|
38
|
+
* Documents restored from storage
|
|
39
|
+
*/
|
|
40
|
+
const documentsRestored = Metric.counter("mimic.documents.restored");
|
|
41
|
+
/**
|
|
42
|
+
* Documents garbage collected (evicted)
|
|
43
|
+
*/
|
|
44
|
+
const documentsEvicted = Metric.counter("mimic.documents.evicted");
|
|
45
|
+
/**
|
|
46
|
+
* Successfully processed transactions
|
|
47
|
+
*/
|
|
48
|
+
const transactionsProcessed = Metric.counter("mimic.transactions.processed");
|
|
49
|
+
/**
|
|
50
|
+
* Rejected transactions
|
|
51
|
+
*/
|
|
52
|
+
const transactionsRejected = Metric.counter("mimic.transactions.rejected");
|
|
53
|
+
/**
|
|
54
|
+
* Transaction processing latency histogram (milliseconds)
|
|
55
|
+
*/
|
|
56
|
+
const transactionsLatency = Metric.histogram("mimic.transactions.latency_ms", MetricBoundaries.exponential({
|
|
57
|
+
start: .1,
|
|
58
|
+
factor: 2,
|
|
59
|
+
count: 15
|
|
60
|
+
}));
|
|
61
|
+
/**
|
|
62
|
+
* Snapshots saved to ColdStorage
|
|
63
|
+
*/
|
|
64
|
+
const storageSnapshots = Metric.counter("mimic.storage.snapshots");
|
|
65
|
+
/**
|
|
66
|
+
* Snapshot save duration histogram (milliseconds)
|
|
67
|
+
*/
|
|
68
|
+
const storageSnapshotLatency = Metric.histogram("mimic.storage.snapshot_latency_ms", MetricBoundaries.exponential({
|
|
69
|
+
start: 1,
|
|
70
|
+
factor: 2,
|
|
71
|
+
count: 12
|
|
72
|
+
}));
|
|
73
|
+
/**
|
|
74
|
+
* WAL entries written to HotStorage
|
|
75
|
+
*/
|
|
76
|
+
const storageWalAppends = Metric.counter("mimic.storage.wal_appends");
|
|
77
|
+
/**
|
|
78
|
+
* Version gaps detected during WAL replay
|
|
79
|
+
*/
|
|
80
|
+
const storageVersionGaps = Metric.counter("mimic.storage.version_gaps");
|
|
81
|
+
/**
|
|
82
|
+
* Failed WAL appends causing transaction rollback
|
|
83
|
+
*/
|
|
84
|
+
const walAppendFailures = Metric.counter("mimic.storage.wal_append_failures");
|
|
85
|
+
/**
|
|
86
|
+
* ColdStorage load failures during document restore
|
|
87
|
+
*/
|
|
88
|
+
const coldStorageLoadFailures = Metric.counter("mimic.storage.cold_load_failures");
|
|
89
|
+
/**
|
|
90
|
+
* HotStorage getEntries failures during document restore
|
|
91
|
+
*/
|
|
92
|
+
const hotStorageLoadFailures = Metric.counter("mimic.storage.hot_load_failures");
|
|
93
|
+
/**
|
|
94
|
+
* Presence set operations
|
|
95
|
+
*/
|
|
96
|
+
const presenceUpdates = Metric.counter("mimic.presence.updates");
|
|
97
|
+
/**
|
|
98
|
+
* Active presence entries
|
|
99
|
+
*/
|
|
100
|
+
const presenceActive = Metric.gauge("mimic.presence.active");
|
|
101
|
+
const MimicMetrics = {
|
|
102
|
+
connectionsActive,
|
|
103
|
+
connectionsTotal,
|
|
104
|
+
connectionsDuration,
|
|
105
|
+
connectionsErrors,
|
|
106
|
+
documentsActive,
|
|
107
|
+
documentsCreated,
|
|
108
|
+
documentsRestored,
|
|
109
|
+
documentsEvicted,
|
|
110
|
+
transactionsProcessed,
|
|
111
|
+
transactionsRejected,
|
|
112
|
+
transactionsLatency,
|
|
113
|
+
storageSnapshots,
|
|
114
|
+
storageSnapshotLatency,
|
|
115
|
+
storageWalAppends,
|
|
116
|
+
storageVersionGaps,
|
|
117
|
+
walAppendFailures,
|
|
118
|
+
coldStorageLoadFailures,
|
|
119
|
+
hotStorageLoadFailures,
|
|
120
|
+
presenceUpdates,
|
|
121
|
+
presenceActive
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
export { MimicMetrics, connectionsActive, connectionsDuration, connectionsErrors, connectionsTotal, documentsActive, documentsCreated, documentsEvicted, documentsRestored, presenceActive, presenceUpdates, storageSnapshotLatency, storageSnapshots, storageVersionGaps, storageWalAppends, transactionsLatency, transactionsProcessed, transactionsRejected, walAppendFailures };
|
|
126
|
+
//# sourceMappingURL=Metrics.mjs.map
|
|
@@ -0,0 +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 * 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 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,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;CAGA;CACA;CACD"}
|
|
@@ -1,55 +1,71 @@
|
|
|
1
|
-
const
|
|
2
|
-
let
|
|
3
|
-
effect_Effect = require_rolldown_runtime.__toESM(effect_Effect);
|
|
4
|
-
let effect_Layer = require("effect/Layer");
|
|
5
|
-
effect_Layer = require_rolldown_runtime.__toESM(effect_Layer);
|
|
6
|
-
let effect_Context = require("effect/Context");
|
|
7
|
-
effect_Context = require_rolldown_runtime.__toESM(effect_Context);
|
|
1
|
+
const require_Errors = require('./Errors.cjs');
|
|
2
|
+
let effect = require("effect");
|
|
8
3
|
|
|
9
4
|
//#region src/MimicAuthService.ts
|
|
10
5
|
/**
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* @voidhash/mimic-effect - MimicAuthService
|
|
7
|
+
*
|
|
8
|
+
* Authentication and authorization service interface and implementations.
|
|
14
9
|
*/
|
|
15
|
-
var MimicAuthService_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
16
|
-
MimicAuthServiceTag: () => MimicAuthServiceTag,
|
|
17
|
-
layer: () => layer,
|
|
18
|
-
layerEffect: () => layerEffect,
|
|
19
|
-
layerService: () => layerService,
|
|
20
|
-
make: () => make,
|
|
21
|
-
makeEffect: () => makeEffect
|
|
22
|
-
});
|
|
23
10
|
/**
|
|
24
|
-
* Context tag for MimicAuthService
|
|
11
|
+
* Context tag for MimicAuthService
|
|
25
12
|
*/
|
|
26
|
-
var MimicAuthServiceTag = class extends
|
|
13
|
+
var MimicAuthServiceTag = class extends effect.Context.Tag("@voidhash/mimic-effect/MimicAuthService")() {};
|
|
27
14
|
/**
|
|
28
|
-
* Create a MimicAuthService layer from an
|
|
15
|
+
* Create a MimicAuthService layer from an Effect that produces the service.
|
|
16
|
+
*
|
|
17
|
+
* This allows you to access other Effect services when implementing authentication.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const Auth = MimicAuthService.make(
|
|
22
|
+
* Effect.gen(function*() {
|
|
23
|
+
* const db = yield* DatabaseService
|
|
24
|
+
* const jwt = yield* JwtService
|
|
25
|
+
*
|
|
26
|
+
* return {
|
|
27
|
+
* authenticate: (token, documentId) =>
|
|
28
|
+
* Effect.gen(function*() {
|
|
29
|
+
* const payload = yield* jwt.verify(token).pipe(
|
|
30
|
+
* Effect.mapError(() => new AuthenticationError({ reason: "Invalid token" }))
|
|
31
|
+
* )
|
|
32
|
+
*
|
|
33
|
+
* const permission = yield* db.getDocumentPermission(payload.userId, documentId)
|
|
34
|
+
*
|
|
35
|
+
* return { userId: payload.userId, permission }
|
|
36
|
+
* })
|
|
37
|
+
* }
|
|
38
|
+
* })
|
|
39
|
+
* )
|
|
40
|
+
* ```
|
|
29
41
|
*/
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
const make = (effect$1) => effect.Layer.effect(MimicAuthServiceTag, effect$1);
|
|
43
|
+
let NoAuth;
|
|
44
|
+
(function(_NoAuth) {
|
|
45
|
+
_NoAuth.make = () => effect.Layer.succeed(MimicAuthServiceTag, { authenticate: (_token, _documentId) => effect.Effect.succeed({
|
|
46
|
+
userId: "anonymous",
|
|
47
|
+
permission: "write"
|
|
48
|
+
}) });
|
|
49
|
+
})(NoAuth || (NoAuth = {}));
|
|
50
|
+
let Static;
|
|
51
|
+
(function(_Static) {
|
|
52
|
+
_Static.make = (options) => effect.Layer.succeed(MimicAuthServiceTag, { authenticate: (token, _documentId) => {
|
|
53
|
+
var _options$permissions$;
|
|
54
|
+
const permission = (_options$permissions$ = options.permissions[token]) !== null && _options$permissions$ !== void 0 ? _options$permissions$ : options.defaultPermission;
|
|
55
|
+
if (permission === void 0) return effect.Effect.fail(new require_Errors.AuthenticationError({ reason: "Unknown user" }));
|
|
56
|
+
return effect.Effect.succeed({
|
|
57
|
+
userId: token,
|
|
58
|
+
permission
|
|
59
|
+
});
|
|
60
|
+
} });
|
|
61
|
+
})(Static || (Static = {}));
|
|
62
|
+
const MimicAuthService = {
|
|
63
|
+
Tag: MimicAuthServiceTag,
|
|
64
|
+
make,
|
|
65
|
+
NoAuth,
|
|
66
|
+
Static
|
|
67
|
+
};
|
|
47
68
|
|
|
48
69
|
//#endregion
|
|
49
|
-
exports.
|
|
50
|
-
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function () {
|
|
53
|
-
return MimicAuthService_exports;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
70
|
+
exports.MimicAuthService = MimicAuthService;
|
|
71
|
+
exports.MimicAuthServiceTag = MimicAuthServiceTag;
|
|
@@ -1,65 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { AuthContext, Permission } from "./Types.cjs";
|
|
2
|
+
import { AuthenticationError } from "./Errors.cjs";
|
|
3
|
+
import { Context, Effect, Layer } from "effect";
|
|
4
4
|
|
|
5
5
|
//#region src/MimicAuthService.d.ts
|
|
6
|
-
|
|
7
|
-
export { AuthHandler, AuthResult, MimicAuthService, MimicAuthServiceTag, layer, layerEffect, layerService, make, makeEffect };
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Result of an authentication attempt.
|
|
11
|
-
*/
|
|
12
|
-
type AuthResult = {
|
|
13
|
-
readonly success: true;
|
|
14
|
-
readonly userId?: string;
|
|
15
|
-
} | {
|
|
16
|
-
readonly success: false;
|
|
17
|
-
readonly error: string;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Authentication handler function type.
|
|
21
|
-
* Can be synchronous or return a Promise.
|
|
22
|
-
*/
|
|
23
|
-
type AuthHandler = (token: string) => Promise<AuthResult> | AuthResult;
|
|
6
|
+
|
|
24
7
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
8
|
+
* MimicAuthService interface for authentication and authorization.
|
|
9
|
+
*
|
|
10
|
+
* The `authenticate` method receives the token from the client's auth message
|
|
11
|
+
* and the document ID being accessed. It should return an AuthContext on success
|
|
12
|
+
* or fail with AuthenticationError on failure.
|
|
13
|
+
*
|
|
14
|
+
* The permission in AuthContext determines what the user can do:
|
|
15
|
+
* - "read": Can subscribe, receive transactions, get snapshots
|
|
16
|
+
* - "write": All of the above, plus can submit transactions and set presence
|
|
27
17
|
*/
|
|
28
18
|
interface MimicAuthService {
|
|
29
19
|
/**
|
|
30
|
-
* Authenticate a connection
|
|
31
|
-
*
|
|
32
|
-
* @
|
|
20
|
+
* Authenticate a connection and return authorization context.
|
|
21
|
+
*
|
|
22
|
+
* @param token - The token provided by the client
|
|
23
|
+
* @param documentId - The document ID being accessed
|
|
24
|
+
* @returns AuthContext with userId and permission level
|
|
33
25
|
*/
|
|
34
|
-
readonly authenticate: (token: string) => Effect.Effect<
|
|
26
|
+
readonly authenticate: (token: string, documentId: string) => Effect.Effect<AuthContext, AuthenticationError>;
|
|
35
27
|
}
|
|
36
|
-
declare const MimicAuthServiceTag_base: Context.TagClass<MimicAuthServiceTag, "@voidhash/mimic-
|
|
28
|
+
declare const MimicAuthServiceTag_base: Context.TagClass<MimicAuthServiceTag, "@voidhash/mimic-effect/MimicAuthService", MimicAuthService>;
|
|
37
29
|
/**
|
|
38
|
-
* Context tag for MimicAuthService
|
|
30
|
+
* Context tag for MimicAuthService
|
|
39
31
|
*/
|
|
40
32
|
declare class MimicAuthServiceTag extends MimicAuthServiceTag_base {}
|
|
41
33
|
/**
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}) => Layer.Layer<MimicAuthServiceTag>;
|
|
47
|
-
/**
|
|
48
|
-
* Create a MimicAuthService layer from an auth service implementation.
|
|
49
|
-
*/
|
|
50
|
-
declare const layerService: (service: MimicAuthService) => Layer.Layer<MimicAuthServiceTag>;
|
|
51
|
-
/**
|
|
52
|
-
* Create a MimicAuthService layer from an Effect that produces an auth service.
|
|
53
|
-
*/
|
|
54
|
-
declare const layerEffect: <E, R>(effect: Effect.Effect<MimicAuthService, E, R>) => Layer.Layer<MimicAuthServiceTag, E, R>;
|
|
55
|
-
/**
|
|
56
|
-
* Create an auth service from an auth handler function.
|
|
34
|
+
* No-authentication implementation.
|
|
35
|
+
*
|
|
36
|
+
* Everyone gets write access with userId "anonymous".
|
|
37
|
+
* ONLY USE FOR DEVELOPMENT/TESTING.
|
|
57
38
|
*/
|
|
58
|
-
declare
|
|
39
|
+
declare namespace NoAuth {
|
|
40
|
+
/**
|
|
41
|
+
* Create a NoAuth layer.
|
|
42
|
+
* All connections are authenticated with write permission.
|
|
43
|
+
*/
|
|
44
|
+
const make: () => Layer.Layer<MimicAuthServiceTag>;
|
|
45
|
+
}
|
|
59
46
|
/**
|
|
60
|
-
*
|
|
47
|
+
* Static permissions implementation.
|
|
48
|
+
*
|
|
49
|
+
* Permissions are defined at configuration time.
|
|
50
|
+
* The token is treated as the userId.
|
|
61
51
|
*/
|
|
62
|
-
declare
|
|
52
|
+
declare namespace Static {
|
|
53
|
+
interface Options {
|
|
54
|
+
/**
|
|
55
|
+
* Map of userId (token) to permission level
|
|
56
|
+
*/
|
|
57
|
+
readonly permissions: Record<string, Permission>;
|
|
58
|
+
/**
|
|
59
|
+
* Default permission for users not in the permissions map.
|
|
60
|
+
* If undefined, unknown users will fail authentication.
|
|
61
|
+
*/
|
|
62
|
+
readonly defaultPermission?: Permission;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create a Static auth layer.
|
|
66
|
+
* The token is treated as the userId, and permissions are looked up from the config.
|
|
67
|
+
*/
|
|
68
|
+
const make: (options: Options) => Layer.Layer<MimicAuthServiceTag>;
|
|
69
|
+
}
|
|
70
|
+
declare const MimicAuthService: {
|
|
71
|
+
Tag: typeof MimicAuthServiceTag;
|
|
72
|
+
make: <E, R>(effect: Effect.Effect<MimicAuthService, E, R>) => Layer.Layer<MimicAuthServiceTag, E, R>;
|
|
73
|
+
NoAuth: typeof NoAuth;
|
|
74
|
+
Static: typeof Static;
|
|
75
|
+
};
|
|
63
76
|
//#endregion
|
|
64
|
-
export {
|
|
77
|
+
export { MimicAuthService, MimicAuthServiceTag };
|
|
65
78
|
//# sourceMappingURL=MimicAuthService.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MimicAuthService.d.cts","names":[],"sources":["../src/MimicAuthService.ts"],"sourcesContent":[],"mappings":"
|
|
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"}
|