@voidhash/mimic-effect 0.0.1 → 0.0.3
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 +99 -14
- package/dist/DocumentManager.cjs +118 -0
- package/dist/DocumentManager.d.cts +45 -0
- package/dist/DocumentManager.d.cts.map +1 -0
- package/dist/DocumentManager.d.mts +45 -0
- package/dist/DocumentManager.d.mts.map +1 -0
- package/dist/DocumentManager.mjs +105 -0
- package/dist/DocumentManager.mjs.map +1 -0
- package/dist/DocumentProtocol.cjs +94 -0
- package/dist/DocumentProtocol.d.cts +113 -0
- package/dist/DocumentProtocol.d.cts.map +1 -0
- package/dist/DocumentProtocol.d.mts +113 -0
- package/dist/DocumentProtocol.d.mts.map +1 -0
- package/dist/DocumentProtocol.mjs +89 -0
- package/dist/DocumentProtocol.mjs.map +1 -0
- package/dist/MimicAuthService.cjs +55 -0
- package/dist/MimicAuthService.d.cts +65 -0
- package/dist/MimicAuthService.d.cts.map +1 -0
- package/dist/MimicAuthService.d.mts +65 -0
- package/dist/MimicAuthService.d.mts.map +1 -0
- package/dist/MimicAuthService.mjs +47 -0
- package/dist/MimicAuthService.mjs.map +1 -0
- package/dist/MimicConfig.cjs +50 -0
- package/dist/MimicConfig.d.cts +99 -0
- package/dist/MimicConfig.d.cts.map +1 -0
- package/dist/MimicConfig.d.mts +99 -0
- package/dist/MimicConfig.d.mts.map +1 -0
- package/dist/MimicConfig.mjs +41 -0
- package/dist/MimicConfig.mjs.map +1 -0
- package/dist/MimicDataStorage.cjs +83 -0
- package/dist/MimicDataStorage.d.cts +113 -0
- package/dist/MimicDataStorage.d.cts.map +1 -0
- package/dist/MimicDataStorage.d.mts +113 -0
- package/dist/MimicDataStorage.d.mts.map +1 -0
- package/dist/MimicDataStorage.mjs +74 -0
- package/dist/MimicDataStorage.mjs.map +1 -0
- package/dist/MimicServer.cjs +230 -0
- package/dist/MimicServer.d.cts +192 -0
- package/dist/MimicServer.d.cts.map +1 -0
- package/dist/MimicServer.d.mts +192 -0
- package/dist/MimicServer.d.mts.map +1 -0
- package/dist/MimicServer.mjs +223 -0
- package/dist/MimicServer.mjs.map +1 -0
- package/dist/PresenceManager.cjs +108 -0
- package/dist/PresenceManager.d.cts +91 -0
- package/dist/PresenceManager.d.cts.map +1 -0
- package/dist/PresenceManager.d.mts +91 -0
- package/dist/PresenceManager.d.mts.map +1 -0
- package/dist/PresenceManager.mjs +95 -0
- package/dist/PresenceManager.mjs.map +1 -0
- package/dist/WebSocketHandler.cjs +366 -0
- package/dist/WebSocketHandler.d.cts +34 -0
- package/dist/WebSocketHandler.d.cts.map +1 -0
- package/dist/WebSocketHandler.d.mts +34 -0
- package/dist/WebSocketHandler.d.mts.map +1 -0
- package/dist/WebSocketHandler.mjs +355 -0
- package/dist/WebSocketHandler.mjs.map +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.cjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/defineProperty.mjs +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.cjs +27 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/objectSpread2.mjs +27 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.cjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPrimitive.mjs +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/toPropertyKey.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.cjs +18 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/typeof.mjs +12 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/{chunk-C6wwvPpM.mjs → _virtual/rolldown_runtime.mjs} +1 -1
- package/dist/auth/NoAuth.cjs +43 -0
- package/dist/auth/NoAuth.d.cts +22 -0
- package/dist/auth/NoAuth.d.cts.map +1 -0
- package/dist/auth/NoAuth.d.mts +22 -0
- package/dist/auth/NoAuth.d.mts.map +1 -0
- package/dist/auth/NoAuth.mjs +36 -0
- package/dist/auth/NoAuth.mjs.map +1 -0
- package/dist/errors.cjs +74 -0
- package/dist/errors.d.cts +89 -0
- package/dist/errors.d.cts.map +1 -0
- package/dist/errors.d.mts +89 -0
- package/dist/errors.d.mts.map +1 -0
- package/dist/errors.mjs +67 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/index.cjs +29 -1227
- package/dist/index.d.cts +12 -795
- package/dist/index.d.mts +12 -795
- package/dist/index.mjs +13 -1162
- package/dist/storage/InMemoryDataStorage.cjs +57 -0
- package/dist/storage/InMemoryDataStorage.d.cts +19 -0
- package/dist/storage/InMemoryDataStorage.d.cts.map +1 -0
- package/dist/storage/InMemoryDataStorage.d.mts +19 -0
- package/dist/storage/InMemoryDataStorage.d.mts.map +1 -0
- package/dist/storage/InMemoryDataStorage.mjs +48 -0
- package/dist/storage/InMemoryDataStorage.mjs.map +1 -0
- package/package.json +3 -3
- package/src/MimicServer.ts +1 -1
- package/tsdown.config.ts +1 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import { Presence, Primitive } from "@voidhash/mimic";
|
|
4
|
+
import * as Duration from "effect/Duration";
|
|
5
|
+
import { DurationInput } from "effect/Duration";
|
|
6
|
+
|
|
7
|
+
//#region src/MimicConfig.d.ts
|
|
8
|
+
declare namespace MimicConfig_d_exports {
|
|
9
|
+
export { MimicServerConfig, MimicServerConfigOptions, MimicServerConfigTag, layer, make };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for the Mimic server.
|
|
13
|
+
*
|
|
14
|
+
* Note: Authentication and persistence are now handled by injectable services
|
|
15
|
+
* (MimicAuthService and MimicDataStorage) rather than config options.
|
|
16
|
+
*/
|
|
17
|
+
interface MimicServerConfig<TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive> {
|
|
18
|
+
/**
|
|
19
|
+
* The schema defining the document structure.
|
|
20
|
+
*/
|
|
21
|
+
readonly schema: TSchema;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum idle time for a document before it is cleaned up.
|
|
24
|
+
* @default "5 minutes"
|
|
25
|
+
*/
|
|
26
|
+
readonly maxIdleTime: Duration.Duration;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of processed transaction IDs to track for deduplication.
|
|
29
|
+
* @default 1000
|
|
30
|
+
*/
|
|
31
|
+
readonly maxTransactionHistory: number;
|
|
32
|
+
/**
|
|
33
|
+
* Heartbeat interval for WebSocket connections.
|
|
34
|
+
* @default "30 seconds"
|
|
35
|
+
*/
|
|
36
|
+
readonly heartbeatInterval: Duration.Duration;
|
|
37
|
+
/**
|
|
38
|
+
* Timeout for heartbeat responses before considering connection dead.
|
|
39
|
+
* @default "10 seconds"
|
|
40
|
+
*/
|
|
41
|
+
readonly heartbeatTimeout: Duration.Duration;
|
|
42
|
+
/**
|
|
43
|
+
* Optional presence schema for ephemeral per-user data.
|
|
44
|
+
* When provided, enables presence features on WebSocket connections.
|
|
45
|
+
* @default undefined (presence disabled)
|
|
46
|
+
*/
|
|
47
|
+
readonly presence: Presence.AnyPresence | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for creating a MimicServerConfig.
|
|
51
|
+
*/
|
|
52
|
+
interface MimicServerConfigOptions<TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive> {
|
|
53
|
+
/**
|
|
54
|
+
* The schema defining the document structure.
|
|
55
|
+
*/
|
|
56
|
+
readonly schema: TSchema;
|
|
57
|
+
/**
|
|
58
|
+
* Maximum idle time for a document before it is cleaned up.
|
|
59
|
+
* @default "5 minutes"
|
|
60
|
+
*/
|
|
61
|
+
readonly maxIdleTime?: DurationInput;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum number of processed transaction IDs to track for deduplication.
|
|
64
|
+
* @default 1000
|
|
65
|
+
*/
|
|
66
|
+
readonly maxTransactionHistory?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Heartbeat interval for WebSocket connections.
|
|
69
|
+
* @default "30 seconds"
|
|
70
|
+
*/
|
|
71
|
+
readonly heartbeatInterval?: DurationInput;
|
|
72
|
+
/**
|
|
73
|
+
* Timeout for heartbeat responses.
|
|
74
|
+
* @default "10 seconds"
|
|
75
|
+
*/
|
|
76
|
+
readonly heartbeatTimeout?: DurationInput;
|
|
77
|
+
/**
|
|
78
|
+
* Optional presence schema for ephemeral per-user data.
|
|
79
|
+
* When provided, enables presence features on WebSocket connections.
|
|
80
|
+
* @default undefined (presence disabled)
|
|
81
|
+
*/
|
|
82
|
+
readonly presence?: Presence.AnyPresence;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a MimicServerConfig from options.
|
|
86
|
+
*/
|
|
87
|
+
declare const make: <TSchema extends Primitive.AnyPrimitive>(options: MimicServerConfigOptions<TSchema>) => MimicServerConfig<TSchema>;
|
|
88
|
+
declare const MimicServerConfigTag_base: Context.TagClass<MimicServerConfigTag, "@voidhash/mimic-server-effect/MimicServerConfig", MimicServerConfig<Primitive.AnyPrimitive>>;
|
|
89
|
+
/**
|
|
90
|
+
* Context tag for MimicServerConfig.
|
|
91
|
+
*/
|
|
92
|
+
declare class MimicServerConfigTag extends MimicServerConfigTag_base {}
|
|
93
|
+
/**
|
|
94
|
+
* Create a Layer that provides MimicServerConfig.
|
|
95
|
+
*/
|
|
96
|
+
declare const layer: <TSchema extends Primitive.AnyPrimitive>(options: MimicServerConfigOptions<TSchema>) => Layer.Layer<MimicServerConfigTag>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { MimicConfig_d_exports, MimicServerConfigOptions, MimicServerConfigTag };
|
|
99
|
+
//# sourceMappingURL=MimicConfig.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MimicConfig.d.cts","names":[],"sources":["../src/MimicConfig.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;AAoBiB,UAAA,iBAAiB,CAAA,gBAAiB,SAAA,CAAU,YAA3B,GAA0C,SAAA,CAAU,YAApD,CAAA,CAAA;EAAiB;;;EAU3B,SAAS,MAAA,EANd,OAMc;EAYH;;;;EAmBb,SAAA,WAAA,EA/BO,QAAA,CAAS,QA+BQ;EAAiB;;;;EAsB3B,SAAA,qBAAA,EAAA,MAAA;EAMD;;;AAa9B;EAAqC,SAAU,iBAAA,EA5DjB,QAAA,CAAS,QA4DQ;EACX;;;;EAChB,SAAA,gBAAA,EAxDS,QAAA,CAAS,QAwDlB;EAOjB;;;;;qBAxDkB,QAAA,CAAS;AAiE9B;AAOA;;;AACW,UAnEM,wBAmEN,CAAA,gBAnE+C,SAAA,CAAU,YAmEzD,GAnEwE,SAAA,CAAU,YAmElF,CAAA,CAAA;EACI;;;mBAhEI;;;;;yBAMM;;;;;;;;;;+BAYM;;;;;8BAMD;;;;;;sBAOR,QAAA,CAAS;;;;;cAMlB,uBAAwB,SAAA,CAAU,uBACpC,yBAAyB,aACjC,kBAAkB;cAOlB;;;;cASU,oBAAA,SAA6B,yBAAA;;;;cAO7B,wBAAyB,SAAA,CAAU,uBACrC,yBAAyB,aACjC,KAAA,CAAM,MAAM"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as Layer from "effect/Layer";
|
|
2
|
+
import * as Context from "effect/Context";
|
|
3
|
+
import * as Duration from "effect/Duration";
|
|
4
|
+
import { DurationInput } from "effect/Duration";
|
|
5
|
+
import { Presence, Primitive } from "@voidhash/mimic";
|
|
6
|
+
|
|
7
|
+
//#region src/MimicConfig.d.ts
|
|
8
|
+
declare namespace MimicConfig_d_exports {
|
|
9
|
+
export { MimicServerConfig, MimicServerConfigOptions, MimicServerConfigTag, layer, make };
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration for the Mimic server.
|
|
13
|
+
*
|
|
14
|
+
* Note: Authentication and persistence are now handled by injectable services
|
|
15
|
+
* (MimicAuthService and MimicDataStorage) rather than config options.
|
|
16
|
+
*/
|
|
17
|
+
interface MimicServerConfig<TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive> {
|
|
18
|
+
/**
|
|
19
|
+
* The schema defining the document structure.
|
|
20
|
+
*/
|
|
21
|
+
readonly schema: TSchema;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum idle time for a document before it is cleaned up.
|
|
24
|
+
* @default "5 minutes"
|
|
25
|
+
*/
|
|
26
|
+
readonly maxIdleTime: Duration.Duration;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum number of processed transaction IDs to track for deduplication.
|
|
29
|
+
* @default 1000
|
|
30
|
+
*/
|
|
31
|
+
readonly maxTransactionHistory: number;
|
|
32
|
+
/**
|
|
33
|
+
* Heartbeat interval for WebSocket connections.
|
|
34
|
+
* @default "30 seconds"
|
|
35
|
+
*/
|
|
36
|
+
readonly heartbeatInterval: Duration.Duration;
|
|
37
|
+
/**
|
|
38
|
+
* Timeout for heartbeat responses before considering connection dead.
|
|
39
|
+
* @default "10 seconds"
|
|
40
|
+
*/
|
|
41
|
+
readonly heartbeatTimeout: Duration.Duration;
|
|
42
|
+
/**
|
|
43
|
+
* Optional presence schema for ephemeral per-user data.
|
|
44
|
+
* When provided, enables presence features on WebSocket connections.
|
|
45
|
+
* @default undefined (presence disabled)
|
|
46
|
+
*/
|
|
47
|
+
readonly presence: Presence.AnyPresence | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Options for creating a MimicServerConfig.
|
|
51
|
+
*/
|
|
52
|
+
interface MimicServerConfigOptions<TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive> {
|
|
53
|
+
/**
|
|
54
|
+
* The schema defining the document structure.
|
|
55
|
+
*/
|
|
56
|
+
readonly schema: TSchema;
|
|
57
|
+
/**
|
|
58
|
+
* Maximum idle time for a document before it is cleaned up.
|
|
59
|
+
* @default "5 minutes"
|
|
60
|
+
*/
|
|
61
|
+
readonly maxIdleTime?: DurationInput;
|
|
62
|
+
/**
|
|
63
|
+
* Maximum number of processed transaction IDs to track for deduplication.
|
|
64
|
+
* @default 1000
|
|
65
|
+
*/
|
|
66
|
+
readonly maxTransactionHistory?: number;
|
|
67
|
+
/**
|
|
68
|
+
* Heartbeat interval for WebSocket connections.
|
|
69
|
+
* @default "30 seconds"
|
|
70
|
+
*/
|
|
71
|
+
readonly heartbeatInterval?: DurationInput;
|
|
72
|
+
/**
|
|
73
|
+
* Timeout for heartbeat responses.
|
|
74
|
+
* @default "10 seconds"
|
|
75
|
+
*/
|
|
76
|
+
readonly heartbeatTimeout?: DurationInput;
|
|
77
|
+
/**
|
|
78
|
+
* Optional presence schema for ephemeral per-user data.
|
|
79
|
+
* When provided, enables presence features on WebSocket connections.
|
|
80
|
+
* @default undefined (presence disabled)
|
|
81
|
+
*/
|
|
82
|
+
readonly presence?: Presence.AnyPresence;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Create a MimicServerConfig from options.
|
|
86
|
+
*/
|
|
87
|
+
declare const make: <TSchema extends Primitive.AnyPrimitive>(options: MimicServerConfigOptions<TSchema>) => MimicServerConfig<TSchema>;
|
|
88
|
+
declare const MimicServerConfigTag_base: Context.TagClass<MimicServerConfigTag, "@voidhash/mimic-server-effect/MimicServerConfig", MimicServerConfig<Primitive.AnyPrimitive>>;
|
|
89
|
+
/**
|
|
90
|
+
* Context tag for MimicServerConfig.
|
|
91
|
+
*/
|
|
92
|
+
declare class MimicServerConfigTag extends MimicServerConfigTag_base {}
|
|
93
|
+
/**
|
|
94
|
+
* Create a Layer that provides MimicServerConfig.
|
|
95
|
+
*/
|
|
96
|
+
declare const layer: <TSchema extends Primitive.AnyPrimitive>(options: MimicServerConfigOptions<TSchema>) => Layer.Layer<MimicServerConfigTag>;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { MimicConfig_d_exports, MimicServerConfigOptions, MimicServerConfigTag };
|
|
99
|
+
//# sourceMappingURL=MimicConfig.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MimicConfig.d.mts","names":[],"sources":["../src/MimicConfig.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;AAoBiB,UAAA,iBAAiB,CAAA,gBAAiB,SAAA,CAAU,YAA3B,GAA0C,SAAA,CAAU,YAApD,CAAA,CAAA;EAAiB;;;EAU3B,SAAS,MAAA,EANd,OAMc;EAYH;;;;EAmBb,SAAA,WAAA,EA/BO,QAAA,CAAS,QA+BQ;EAAiB;;;;EAsB3B,SAAA,qBAAA,EAAA,MAAA;EAMD;;;AAa9B;EAAqC,SAAU,iBAAA,EA5DjB,QAAA,CAAS,QA4DQ;EACX;;;;EAChB,SAAA,gBAAA,EAxDS,QAAA,CAAS,QAwDlB;EAOjB;;;;;qBAxDkB,QAAA,CAAS;AAiE9B;AAOA;;;AACW,UAnEM,wBAmEN,CAAA,gBAnE+C,SAAA,CAAU,YAmEzD,GAnEwE,SAAA,CAAU,YAmElF,CAAA,CAAA;EACI;;;mBAhEI;;;;;yBAMM;;;;;;;;;;+BAYM;;;;;8BAMD;;;;;;sBAOR,QAAA,CAAS;;;;;cAMlB,uBAAwB,SAAA,CAAU,uBACpC,yBAAyB,aACjC,kBAAkB;cAOlB;;;;cASU,oBAAA,SAA6B,yBAAA;;;;cAO7B,wBAAyB,SAAA,CAAU,uBACrC,yBAAyB,aACjC,KAAA,CAAM,MAAM"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as Duration from "effect/Duration";
|
|
5
|
+
|
|
6
|
+
//#region src/MimicConfig.ts
|
|
7
|
+
/**
|
|
8
|
+
* @since 0.0.1
|
|
9
|
+
* Configuration types for the Mimic server.
|
|
10
|
+
*/
|
|
11
|
+
var MimicConfig_exports = /* @__PURE__ */ __export({
|
|
12
|
+
MimicServerConfigTag: () => MimicServerConfigTag,
|
|
13
|
+
layer: () => layer,
|
|
14
|
+
make: () => make
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Create a MimicServerConfig from options.
|
|
18
|
+
*/
|
|
19
|
+
const make = (options) => {
|
|
20
|
+
var _options$maxIdleTime, _options$maxTransacti, _options$heartbeatInt, _options$heartbeatTim;
|
|
21
|
+
return {
|
|
22
|
+
schema: options.schema,
|
|
23
|
+
maxIdleTime: Duration.decode((_options$maxIdleTime = options.maxIdleTime) !== null && _options$maxIdleTime !== void 0 ? _options$maxIdleTime : "5 minutes"),
|
|
24
|
+
maxTransactionHistory: (_options$maxTransacti = options.maxTransactionHistory) !== null && _options$maxTransacti !== void 0 ? _options$maxTransacti : 1e3,
|
|
25
|
+
heartbeatInterval: Duration.decode((_options$heartbeatInt = options.heartbeatInterval) !== null && _options$heartbeatInt !== void 0 ? _options$heartbeatInt : "30 seconds"),
|
|
26
|
+
heartbeatTimeout: Duration.decode((_options$heartbeatTim = options.heartbeatTimeout) !== null && _options$heartbeatTim !== void 0 ? _options$heartbeatTim : "10 seconds"),
|
|
27
|
+
presence: options.presence
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Context tag for MimicServerConfig.
|
|
32
|
+
*/
|
|
33
|
+
var MimicServerConfigTag = class extends Context.Tag("@voidhash/mimic-server-effect/MimicServerConfig")() {};
|
|
34
|
+
/**
|
|
35
|
+
* Create a Layer that provides MimicServerConfig.
|
|
36
|
+
*/
|
|
37
|
+
const layer = (options) => Layer.succeed(MimicServerConfigTag, make(options));
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { MimicConfig_exports, MimicServerConfigTag, layer };
|
|
41
|
+
//# sourceMappingURL=MimicConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MimicConfig.mjs","names":[],"sources":["../src/MimicConfig.ts"],"sourcesContent":["/**\n * @since 0.0.1\n * Configuration types for the Mimic server.\n */\nimport * as Context from \"effect/Context\";\nimport * as Duration from \"effect/Duration\";\nimport type { DurationInput } from \"effect/Duration\";\nimport * as Layer from \"effect/Layer\";\nimport type { Primitive, Presence } from \"@voidhash/mimic\";\n\n// =============================================================================\n// Mimic Server Configuration\n// =============================================================================\n\n/**\n * Configuration for the Mimic server.\n * \n * Note: Authentication and persistence are now handled by injectable services\n * (MimicAuthService and MimicDataStorage) rather than config options.\n */\nexport interface MimicServerConfig<TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive> {\n /**\n * The schema defining the document structure.\n */\n readonly schema: TSchema;\n\n /**\n * Maximum idle time for a document before it is cleaned up.\n * @default \"5 minutes\"\n */\n readonly maxIdleTime: Duration.Duration;\n\n /**\n * Maximum number of processed transaction IDs to track for deduplication.\n * @default 1000\n */\n readonly maxTransactionHistory: number;\n\n /**\n * Heartbeat interval for WebSocket connections.\n * @default \"30 seconds\"\n */\n readonly heartbeatInterval: Duration.Duration;\n\n /**\n * Timeout for heartbeat responses before considering connection dead.\n * @default \"10 seconds\"\n */\n readonly heartbeatTimeout: Duration.Duration;\n\n /**\n * Optional presence schema for ephemeral per-user data.\n * When provided, enables presence features on WebSocket connections.\n * @default undefined (presence disabled)\n */\n readonly presence: Presence.AnyPresence | undefined;\n}\n\n/**\n * Options for creating a MimicServerConfig.\n */\nexport interface MimicServerConfigOptions<TSchema extends Primitive.AnyPrimitive = Primitive.AnyPrimitive> {\n /**\n * The schema defining the document structure.\n */\n readonly schema: TSchema;\n\n /**\n * Maximum idle time for a document before it is cleaned up.\n * @default \"5 minutes\"\n */\n readonly maxIdleTime?: DurationInput;\n\n /**\n * Maximum number of processed transaction IDs to track for deduplication.\n * @default 1000\n */\n readonly maxTransactionHistory?: number;\n\n /**\n * Heartbeat interval for WebSocket connections.\n * @default \"30 seconds\"\n */\n readonly heartbeatInterval?: DurationInput;\n\n /**\n * Timeout for heartbeat responses.\n * @default \"10 seconds\"\n */\n readonly heartbeatTimeout?: DurationInput;\n\n /**\n * Optional presence schema for ephemeral per-user data.\n * When provided, enables presence features on WebSocket connections.\n * @default undefined (presence disabled)\n */\n readonly presence?: Presence.AnyPresence;\n}\n\n/**\n * Create a MimicServerConfig from options.\n */\nexport const make = <TSchema extends Primitive.AnyPrimitive>(\n options: MimicServerConfigOptions<TSchema>\n): MimicServerConfig<TSchema> => ({\n schema: options.schema,\n maxIdleTime: Duration.decode(options.maxIdleTime ?? \"5 minutes\"),\n maxTransactionHistory: options.maxTransactionHistory ?? 1000,\n heartbeatInterval: Duration.decode(options.heartbeatInterval ?? \"30 seconds\"),\n heartbeatTimeout: Duration.decode(options.heartbeatTimeout ?? \"10 seconds\"),\n presence: options.presence,\n});\n\n// =============================================================================\n// Context Tag\n// =============================================================================\n\n/**\n * Context tag for MimicServerConfig.\n */\nexport class MimicServerConfigTag extends Context.Tag(\n \"@voidhash/mimic-server-effect/MimicServerConfig\"\n)<MimicServerConfigTag, MimicServerConfig>() {}\n\n/**\n * Create a Layer that provides MimicServerConfig.\n */\nexport const layer = <TSchema extends Primitive.AnyPrimitive>(\n options: MimicServerConfigOptions<TSchema>\n): Layer.Layer<MimicServerConfigTag> =>\n Layer.succeed(MimicServerConfigTag, make(options));\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsGA,MAAa,QACX,YAC+B;;QAAC;EAChC,QAAQ,QAAQ;EAChB,aAAa,SAAS,+BAAO,QAAQ,kFAAe,YAAY;EAChE,gDAAuB,QAAQ,8FAAyB;EACxD,mBAAmB,SAAS,gCAAO,QAAQ,0FAAqB,aAAa;EAC7E,kBAAkB,SAAS,gCAAO,QAAQ,yFAAoB,aAAa;EAC3E,UAAU,QAAQ;EACnB;;;;;AASD,IAAa,uBAAb,cAA0C,QAAQ,IAChD,kDACD,EAA2C,CAAC;;;;AAK7C,MAAa,SACX,YAEA,MAAM,QAAQ,sBAAsB,KAAK,QAAQ,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let effect_Effect = require("effect/Effect");
|
|
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);
|
|
8
|
+
let effect_Data = require("effect/Data");
|
|
9
|
+
effect_Data = require_rolldown_runtime.__toESM(effect_Data);
|
|
10
|
+
|
|
11
|
+
//#region src/MimicDataStorage.ts
|
|
12
|
+
/**
|
|
13
|
+
* @since 0.0.1
|
|
14
|
+
* Data storage service interface for Mimic documents.
|
|
15
|
+
* Provides pluggable storage adapters with load/save hooks for data transformation.
|
|
16
|
+
*/
|
|
17
|
+
var MimicDataStorage_exports = /* @__PURE__ */ require_rolldown_runtime.__export({
|
|
18
|
+
MimicDataStorageTag: () => MimicDataStorageTag,
|
|
19
|
+
StorageDeleteError: () => StorageDeleteError,
|
|
20
|
+
StorageLoadError: () => StorageLoadError,
|
|
21
|
+
StorageSaveError: () => StorageSaveError,
|
|
22
|
+
layer: () => layer,
|
|
23
|
+
layerEffect: () => layerEffect,
|
|
24
|
+
make: () => make
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Error when loading a document from storage fails.
|
|
28
|
+
*/
|
|
29
|
+
var StorageLoadError = class extends effect_Data.TaggedError("StorageLoadError") {
|
|
30
|
+
get message() {
|
|
31
|
+
return `Failed to load document ${this.documentId}: ${String(this.cause)}`;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Error when saving a document to storage fails.
|
|
36
|
+
*/
|
|
37
|
+
var StorageSaveError = class extends effect_Data.TaggedError("StorageSaveError") {
|
|
38
|
+
get message() {
|
|
39
|
+
return `Failed to save document ${this.documentId}: ${String(this.cause)}`;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Error when deleting a document from storage fails.
|
|
44
|
+
*/
|
|
45
|
+
var StorageDeleteError = class extends effect_Data.TaggedError("StorageDeleteError") {
|
|
46
|
+
get message() {
|
|
47
|
+
return `Failed to delete document ${this.documentId}: ${String(this.cause)}`;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Context tag for MimicDataStorage service.
|
|
52
|
+
*/
|
|
53
|
+
var MimicDataStorageTag = class extends effect_Context.Tag("@voidhash/mimic-server-effect/MimicDataStorage")() {};
|
|
54
|
+
/**
|
|
55
|
+
* Create a MimicDataStorage layer from a storage implementation.
|
|
56
|
+
*/
|
|
57
|
+
const layer = (storage) => effect_Layer.succeed(MimicDataStorageTag, storage);
|
|
58
|
+
/**
|
|
59
|
+
* Create a MimicDataStorage layer from an Effect that produces a storage implementation.
|
|
60
|
+
*/
|
|
61
|
+
const layerEffect = (effect) => effect_Layer.effect(MimicDataStorageTag, effect);
|
|
62
|
+
/**
|
|
63
|
+
* Create a simple storage implementation with minimal configuration.
|
|
64
|
+
*/
|
|
65
|
+
const make = (options) => {
|
|
66
|
+
var _options$delete, _options$onLoad, _options$onSave;
|
|
67
|
+
return {
|
|
68
|
+
load: options.load,
|
|
69
|
+
save: options.save,
|
|
70
|
+
delete: (_options$delete = options.delete) !== null && _options$delete !== void 0 ? _options$delete : (() => effect_Effect.void),
|
|
71
|
+
onLoad: (_options$onLoad = options.onLoad) !== null && _options$onLoad !== void 0 ? _options$onLoad : ((state) => effect_Effect.succeed(state)),
|
|
72
|
+
onSave: (_options$onSave = options.onSave) !== null && _options$onSave !== void 0 ? _options$onSave : ((state) => effect_Effect.succeed(state))
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
//#endregion
|
|
77
|
+
exports.MimicDataStorageTag = MimicDataStorageTag;
|
|
78
|
+
Object.defineProperty(exports, 'MimicDataStorage_exports', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return MimicDataStorage_exports;
|
|
82
|
+
}
|
|
83
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as effect_Types6 from "effect/Types";
|
|
5
|
+
import * as effect_Cause6 from "effect/Cause";
|
|
6
|
+
|
|
7
|
+
//#region src/MimicDataStorage.d.ts
|
|
8
|
+
declare namespace MimicDataStorage_d_exports {
|
|
9
|
+
export { MimicDataStorage, MimicDataStorageTag, StorageDeleteError, StorageError, StorageLoadError, StorageSaveError, layer, layerEffect, make };
|
|
10
|
+
}
|
|
11
|
+
declare const StorageLoadError_base: new <A extends Record<string, any> = {}>(args: effect_Types6.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause6.YieldableError & {
|
|
12
|
+
readonly _tag: "StorageLoadError";
|
|
13
|
+
} & Readonly<A>;
|
|
14
|
+
/**
|
|
15
|
+
* Error when loading a document from storage fails.
|
|
16
|
+
*/
|
|
17
|
+
declare class StorageLoadError extends StorageLoadError_base<{
|
|
18
|
+
readonly documentId: string;
|
|
19
|
+
readonly cause: unknown;
|
|
20
|
+
}> {
|
|
21
|
+
get message(): string;
|
|
22
|
+
}
|
|
23
|
+
declare const StorageSaveError_base: new <A extends Record<string, any> = {}>(args: effect_Types6.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause6.YieldableError & {
|
|
24
|
+
readonly _tag: "StorageSaveError";
|
|
25
|
+
} & Readonly<A>;
|
|
26
|
+
/**
|
|
27
|
+
* Error when saving a document to storage fails.
|
|
28
|
+
*/
|
|
29
|
+
declare class StorageSaveError extends StorageSaveError_base<{
|
|
30
|
+
readonly documentId: string;
|
|
31
|
+
readonly cause: unknown;
|
|
32
|
+
}> {
|
|
33
|
+
get message(): string;
|
|
34
|
+
}
|
|
35
|
+
declare const StorageDeleteError_base: new <A extends Record<string, any> = {}>(args: effect_Types6.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause6.YieldableError & {
|
|
36
|
+
readonly _tag: "StorageDeleteError";
|
|
37
|
+
} & Readonly<A>;
|
|
38
|
+
/**
|
|
39
|
+
* Error when deleting a document from storage fails.
|
|
40
|
+
*/
|
|
41
|
+
declare class StorageDeleteError extends StorageDeleteError_base<{
|
|
42
|
+
readonly documentId: string;
|
|
43
|
+
readonly cause: unknown;
|
|
44
|
+
}> {
|
|
45
|
+
get message(): string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Union of all storage errors.
|
|
49
|
+
*/
|
|
50
|
+
type StorageError = StorageLoadError | StorageSaveError | StorageDeleteError;
|
|
51
|
+
/**
|
|
52
|
+
* Data storage service interface.
|
|
53
|
+
* Implementations can persist documents to various backends (memory, S3, database, etc.)
|
|
54
|
+
*/
|
|
55
|
+
interface MimicDataStorage {
|
|
56
|
+
/**
|
|
57
|
+
* Load a document's state from storage.
|
|
58
|
+
* @param documentId - The unique identifier for the document
|
|
59
|
+
* @returns The document state, or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
readonly load: (documentId: string) => Effect.Effect<unknown | undefined, StorageLoadError>;
|
|
62
|
+
/**
|
|
63
|
+
* Save a document's state to storage.
|
|
64
|
+
* @param documentId - The unique identifier for the document
|
|
65
|
+
* @param state - The document state to persist
|
|
66
|
+
*/
|
|
67
|
+
readonly save: (documentId: string, state: unknown) => Effect.Effect<void, StorageSaveError>;
|
|
68
|
+
/**
|
|
69
|
+
* Delete a document from storage.
|
|
70
|
+
* @param documentId - The unique identifier for the document
|
|
71
|
+
*/
|
|
72
|
+
readonly delete: (documentId: string) => Effect.Effect<void, StorageDeleteError>;
|
|
73
|
+
/**
|
|
74
|
+
* Transform data after loading from storage.
|
|
75
|
+
* Useful for migrations, decryption, decompression, etc.
|
|
76
|
+
* @param state - The raw state loaded from storage
|
|
77
|
+
* @returns The transformed state
|
|
78
|
+
*/
|
|
79
|
+
readonly onLoad: (state: unknown) => Effect.Effect<unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* Transform/validate data before saving to storage.
|
|
82
|
+
* Useful for encryption, compression, validation, etc.
|
|
83
|
+
* @param state - The state to be saved
|
|
84
|
+
* @returns The transformed state
|
|
85
|
+
*/
|
|
86
|
+
readonly onSave: (state: unknown) => Effect.Effect<unknown>;
|
|
87
|
+
}
|
|
88
|
+
declare const MimicDataStorageTag_base: Context.TagClass<MimicDataStorageTag, "@voidhash/mimic-server-effect/MimicDataStorage", MimicDataStorage>;
|
|
89
|
+
/**
|
|
90
|
+
* Context tag for MimicDataStorage service.
|
|
91
|
+
*/
|
|
92
|
+
declare class MimicDataStorageTag extends MimicDataStorageTag_base {}
|
|
93
|
+
/**
|
|
94
|
+
* Create a MimicDataStorage layer from a storage implementation.
|
|
95
|
+
*/
|
|
96
|
+
declare const layer: (storage: MimicDataStorage) => Layer.Layer<MimicDataStorageTag>;
|
|
97
|
+
/**
|
|
98
|
+
* Create a MimicDataStorage layer from an Effect that produces a storage implementation.
|
|
99
|
+
*/
|
|
100
|
+
declare const layerEffect: <E, R>(effect: Effect.Effect<MimicDataStorage, E, R>) => Layer.Layer<MimicDataStorageTag, E, R>;
|
|
101
|
+
/**
|
|
102
|
+
* Create a simple storage implementation with minimal configuration.
|
|
103
|
+
*/
|
|
104
|
+
declare const make: (options: {
|
|
105
|
+
readonly load: (documentId: string) => Effect.Effect<unknown | undefined, StorageLoadError>;
|
|
106
|
+
readonly save: (documentId: string, state: unknown) => Effect.Effect<void, StorageSaveError>;
|
|
107
|
+
readonly delete?: (documentId: string) => Effect.Effect<void, StorageDeleteError>;
|
|
108
|
+
readonly onLoad?: (state: unknown) => Effect.Effect<unknown>;
|
|
109
|
+
readonly onSave?: (state: unknown) => Effect.Effect<unknown>;
|
|
110
|
+
}) => MimicDataStorage;
|
|
111
|
+
//#endregion
|
|
112
|
+
export { MimicDataStorageTag, MimicDataStorage_d_exports };
|
|
113
|
+
//# sourceMappingURL=MimicDataStorage.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MimicDataStorage.d.cts","names":[],"sources":["../src/MimicDataStorage.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAOsC;;;;;;cAUzB,gBAAA,SAAyB;;;;;AAVA;cAiBrC;;;;;;cAKY,gBAAA,SAAyB;;;;;;AAZtC,cAmBC,uBAnBqC,EAAA,IAAA,CAAA,gBAAA,CAAA,MAAA,EAAA,GAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,IAAA,sBAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,IAAA,GAAA,IAAA,GAAA,iBAAA,OAAA,KAAA,SAAA,MAAA,GAAA,KAAA,IAAA,IAAA,EAAA,CAAA,EAAA,EAAA,kCAAA;EAOrC,SAAA,IAAA,EAAA,oBAAA;;;;;cAiBY,kBAAA,SAA2B;;;;;;;;AAZxC;AAOC,KAiBW,YAAA,GAAe,gBAjB1B,GAiB6C,gBAjB7C,GAiBgE,kBAjBhE;;;;;UA2BgB,gBAAA;;;;;;yCAQV,MAAA,CAAO,4BAA4B;;AA9B1C;AAYA;;;EAAiE,SAAA,IAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAAA,OAAA,EAAA,GA4B1D,MAAA,CAAO,MA5BmD,CAAA,IAAA,EA4BtC,gBA5BsC,CAAA;EAAkB;AAUnF;;;EAkB2B,SAAA,MAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAQpB,MAAA,CAAO,MARa,CAAA,IAAA,EAQA,kBARA,CAAA;EAApB;;;;;;EAyBN,SAAA,MAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GATsC,MAAA,CAAO,MAS7C,CAAA,OAAA,CAAA;;;;;AASD;AAWA;EAA+B,SAAA,MAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GArBQ,MAAA,CAAO,MAqBf,CAAA,OAAA,CAAA;;cApB9B,wBAoBuD,kBAAA,oBAAA,EAAA,gDAAA,kBAAA,CAAA;;AAMxD;;AAC0C,cAlB7B,mBAAA,SAA4B,wBAAA,CAkBC;;;;AACH,cAR1B,KAQ0B,EAAA,CAAA,OAAA,EARR,gBAQQ,EAAA,GARW,KAAA,CAAM,KAQjB,CARuB,mBAQvB,CAAA;;;AAUvC;AAC4E,cAb/D,WAa+D,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,MAAA,EAZlE,MAAA,CAAO,MAY2D,CAZpD,gBAYoD,EAZlC,CAYkC,EAZ/B,CAY+B,CAAA,EAAA,GAXzE,KAAA,CAAM,KAWmE,CAX7D,mBAW6D,EAXxC,CAWwC,EAXrC,CAWqC,CAAA;;;;AAEZ,cAHnD,IAGmD,EAAA,CAAA,OAAA,EAAA;EAApB,SAAO,IAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAFV,MAAA,CAAO,MAEG,CAAA,OAAA,GAAA,SAAA,EAFyB,gBAEzB,CAAA;EACX,SAAO,IAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAAA,OAAA,EAAA,GAFU,MAAA,CAAO,MAEjB,CAAA,IAAA,EAF8B,gBAE9B,CAAA;EACP,SAAO,MAAA,CAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAFH,MAAA,CAAO,MAEJ,CAAA,IAAA,EAFiB,kBAEjB,CAAA;EAC3C,SAAA,MAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAFoC,MAAA,CAAO,MAE3C,CAAA,OAAA,CAAA;EAMF,SAAA,MAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAPsC,MAAA,CAAO,MAO7C,CAAA,OAAA,CAAA;MANE"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import * as Context from "effect/Context";
|
|
4
|
+
import * as effect_Types6 from "effect/Types";
|
|
5
|
+
import * as effect_Cause6 from "effect/Cause";
|
|
6
|
+
|
|
7
|
+
//#region src/MimicDataStorage.d.ts
|
|
8
|
+
declare namespace MimicDataStorage_d_exports {
|
|
9
|
+
export { MimicDataStorage, MimicDataStorageTag, StorageDeleteError, StorageError, StorageLoadError, StorageSaveError, layer, layerEffect, make };
|
|
10
|
+
}
|
|
11
|
+
declare const StorageLoadError_base: new <A extends Record<string, any> = {}>(args: effect_Types6.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause6.YieldableError & {
|
|
12
|
+
readonly _tag: "StorageLoadError";
|
|
13
|
+
} & Readonly<A>;
|
|
14
|
+
/**
|
|
15
|
+
* Error when loading a document from storage fails.
|
|
16
|
+
*/
|
|
17
|
+
declare class StorageLoadError extends StorageLoadError_base<{
|
|
18
|
+
readonly documentId: string;
|
|
19
|
+
readonly cause: unknown;
|
|
20
|
+
}> {
|
|
21
|
+
get message(): string;
|
|
22
|
+
}
|
|
23
|
+
declare const StorageSaveError_base: new <A extends Record<string, any> = {}>(args: effect_Types6.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause6.YieldableError & {
|
|
24
|
+
readonly _tag: "StorageSaveError";
|
|
25
|
+
} & Readonly<A>;
|
|
26
|
+
/**
|
|
27
|
+
* Error when saving a document to storage fails.
|
|
28
|
+
*/
|
|
29
|
+
declare class StorageSaveError extends StorageSaveError_base<{
|
|
30
|
+
readonly documentId: string;
|
|
31
|
+
readonly cause: unknown;
|
|
32
|
+
}> {
|
|
33
|
+
get message(): string;
|
|
34
|
+
}
|
|
35
|
+
declare const StorageDeleteError_base: new <A extends Record<string, any> = {}>(args: effect_Types6.Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P] }) => effect_Cause6.YieldableError & {
|
|
36
|
+
readonly _tag: "StorageDeleteError";
|
|
37
|
+
} & Readonly<A>;
|
|
38
|
+
/**
|
|
39
|
+
* Error when deleting a document from storage fails.
|
|
40
|
+
*/
|
|
41
|
+
declare class StorageDeleteError extends StorageDeleteError_base<{
|
|
42
|
+
readonly documentId: string;
|
|
43
|
+
readonly cause: unknown;
|
|
44
|
+
}> {
|
|
45
|
+
get message(): string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Union of all storage errors.
|
|
49
|
+
*/
|
|
50
|
+
type StorageError = StorageLoadError | StorageSaveError | StorageDeleteError;
|
|
51
|
+
/**
|
|
52
|
+
* Data storage service interface.
|
|
53
|
+
* Implementations can persist documents to various backends (memory, S3, database, etc.)
|
|
54
|
+
*/
|
|
55
|
+
interface MimicDataStorage {
|
|
56
|
+
/**
|
|
57
|
+
* Load a document's state from storage.
|
|
58
|
+
* @param documentId - The unique identifier for the document
|
|
59
|
+
* @returns The document state, or undefined if not found
|
|
60
|
+
*/
|
|
61
|
+
readonly load: (documentId: string) => Effect.Effect<unknown | undefined, StorageLoadError>;
|
|
62
|
+
/**
|
|
63
|
+
* Save a document's state to storage.
|
|
64
|
+
* @param documentId - The unique identifier for the document
|
|
65
|
+
* @param state - The document state to persist
|
|
66
|
+
*/
|
|
67
|
+
readonly save: (documentId: string, state: unknown) => Effect.Effect<void, StorageSaveError>;
|
|
68
|
+
/**
|
|
69
|
+
* Delete a document from storage.
|
|
70
|
+
* @param documentId - The unique identifier for the document
|
|
71
|
+
*/
|
|
72
|
+
readonly delete: (documentId: string) => Effect.Effect<void, StorageDeleteError>;
|
|
73
|
+
/**
|
|
74
|
+
* Transform data after loading from storage.
|
|
75
|
+
* Useful for migrations, decryption, decompression, etc.
|
|
76
|
+
* @param state - The raw state loaded from storage
|
|
77
|
+
* @returns The transformed state
|
|
78
|
+
*/
|
|
79
|
+
readonly onLoad: (state: unknown) => Effect.Effect<unknown>;
|
|
80
|
+
/**
|
|
81
|
+
* Transform/validate data before saving to storage.
|
|
82
|
+
* Useful for encryption, compression, validation, etc.
|
|
83
|
+
* @param state - The state to be saved
|
|
84
|
+
* @returns The transformed state
|
|
85
|
+
*/
|
|
86
|
+
readonly onSave: (state: unknown) => Effect.Effect<unknown>;
|
|
87
|
+
}
|
|
88
|
+
declare const MimicDataStorageTag_base: Context.TagClass<MimicDataStorageTag, "@voidhash/mimic-server-effect/MimicDataStorage", MimicDataStorage>;
|
|
89
|
+
/**
|
|
90
|
+
* Context tag for MimicDataStorage service.
|
|
91
|
+
*/
|
|
92
|
+
declare class MimicDataStorageTag extends MimicDataStorageTag_base {}
|
|
93
|
+
/**
|
|
94
|
+
* Create a MimicDataStorage layer from a storage implementation.
|
|
95
|
+
*/
|
|
96
|
+
declare const layer: (storage: MimicDataStorage) => Layer.Layer<MimicDataStorageTag>;
|
|
97
|
+
/**
|
|
98
|
+
* Create a MimicDataStorage layer from an Effect that produces a storage implementation.
|
|
99
|
+
*/
|
|
100
|
+
declare const layerEffect: <E, R>(effect: Effect.Effect<MimicDataStorage, E, R>) => Layer.Layer<MimicDataStorageTag, E, R>;
|
|
101
|
+
/**
|
|
102
|
+
* Create a simple storage implementation with minimal configuration.
|
|
103
|
+
*/
|
|
104
|
+
declare const make: (options: {
|
|
105
|
+
readonly load: (documentId: string) => Effect.Effect<unknown | undefined, StorageLoadError>;
|
|
106
|
+
readonly save: (documentId: string, state: unknown) => Effect.Effect<void, StorageSaveError>;
|
|
107
|
+
readonly delete?: (documentId: string) => Effect.Effect<void, StorageDeleteError>;
|
|
108
|
+
readonly onLoad?: (state: unknown) => Effect.Effect<unknown>;
|
|
109
|
+
readonly onSave?: (state: unknown) => Effect.Effect<unknown>;
|
|
110
|
+
}) => MimicDataStorage;
|
|
111
|
+
//#endregion
|
|
112
|
+
export { MimicDataStorageTag, MimicDataStorage_d_exports };
|
|
113
|
+
//# sourceMappingURL=MimicDataStorage.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MimicDataStorage.d.mts","names":[],"sources":["../src/MimicDataStorage.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;cAOsC;;;;;;cAUzB,gBAAA,SAAyB;;;;;AAVA;cAiBrC;;;;;;cAKY,gBAAA,SAAyB;;;;;;AAZtC,cAmBC,uBAnBqC,EAAA,IAAA,CAAA,gBAAA,CAAA,MAAA,EAAA,GAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,IAAA,sBAAA,EAAA,EAAA,CAAA,CAAA,CAAA,SAAA,IAAA,GAAA,IAAA,GAAA,iBAAA,OAAA,KAAA,SAAA,MAAA,GAAA,KAAA,IAAA,IAAA,EAAA,CAAA,EAAA,EAAA,kCAAA;EAOrC,SAAA,IAAA,EAAA,oBAAA;;;;;cAiBY,kBAAA,SAA2B;;;;;;;;AAZxC;AAOC,KAiBW,YAAA,GAAe,gBAjB1B,GAiB6C,gBAjB7C,GAiBgE,kBAjBhE;;;;;UA2BgB,gBAAA;;;;;;yCAQV,MAAA,CAAO,4BAA4B;;AA9B1C;AAYA;;;EAAiE,SAAA,IAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAAA,OAAA,EAAA,GA4B1D,MAAA,CAAO,MA5BmD,CAAA,IAAA,EA4BtC,gBA5BsC,CAAA;EAAkB;AAUnF;;;EAkB2B,SAAA,MAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAQpB,MAAA,CAAO,MARa,CAAA,IAAA,EAQA,kBARA,CAAA;EAApB;;;;;;EAyBN,SAAA,MAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GATsC,MAAA,CAAO,MAS7C,CAAA,OAAA,CAAA;;;;;AASD;AAWA;EAA+B,SAAA,MAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GArBQ,MAAA,CAAO,MAqBf,CAAA,OAAA,CAAA;;cApB9B,wBAoBuD,kBAAA,oBAAA,EAAA,gDAAA,kBAAA,CAAA;;AAMxD;;AAC0C,cAlB7B,mBAAA,SAA4B,wBAAA,CAkBC;;;;AACH,cAR1B,KAQ0B,EAAA,CAAA,OAAA,EARR,gBAQQ,EAAA,GARW,KAAA,CAAM,KAQjB,CARuB,mBAQvB,CAAA;;;AAUvC;AAC4E,cAb/D,WAa+D,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,MAAA,EAZlE,MAAA,CAAO,MAY2D,CAZpD,gBAYoD,EAZlC,CAYkC,EAZ/B,CAY+B,CAAA,EAAA,GAXzE,KAAA,CAAM,KAWmE,CAX7D,mBAW6D,EAXxC,CAWwC,EAXrC,CAWqC,CAAA;;;;AAEZ,cAHnD,IAGmD,EAAA,CAAA,OAAA,EAAA;EAApB,SAAO,IAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAFV,MAAA,CAAO,MAEG,CAAA,OAAA,GAAA,SAAA,EAFyB,gBAEzB,CAAA;EACX,SAAO,IAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,KAAA,EAAA,OAAA,EAAA,GAFU,MAAA,CAAO,MAEjB,CAAA,IAAA,EAF8B,gBAE9B,CAAA;EACP,SAAO,MAAA,CAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAFH,MAAA,CAAO,MAEJ,CAAA,IAAA,EAFiB,kBAEjB,CAAA;EAC3C,SAAA,MAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAFoC,MAAA,CAAO,MAE3C,CAAA,OAAA,CAAA;EAMF,SAAA,MAAA,CAAA,EAAA,CAAA,KAAA,EAAA,OAAA,EAAA,GAPsC,MAAA,CAAO,MAO7C,CAAA,OAAA,CAAA;MANE"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { __export } from "./_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Data from "effect/Data";
|
|
6
|
+
|
|
7
|
+
//#region src/MimicDataStorage.ts
|
|
8
|
+
/**
|
|
9
|
+
* @since 0.0.1
|
|
10
|
+
* Data storage service interface for Mimic documents.
|
|
11
|
+
* Provides pluggable storage adapters with load/save hooks for data transformation.
|
|
12
|
+
*/
|
|
13
|
+
var MimicDataStorage_exports = /* @__PURE__ */ __export({
|
|
14
|
+
MimicDataStorageTag: () => MimicDataStorageTag,
|
|
15
|
+
StorageDeleteError: () => StorageDeleteError,
|
|
16
|
+
StorageLoadError: () => StorageLoadError,
|
|
17
|
+
StorageSaveError: () => StorageSaveError,
|
|
18
|
+
layer: () => layer,
|
|
19
|
+
layerEffect: () => layerEffect,
|
|
20
|
+
make: () => make
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Error when loading a document from storage fails.
|
|
24
|
+
*/
|
|
25
|
+
var StorageLoadError = class extends Data.TaggedError("StorageLoadError") {
|
|
26
|
+
get message() {
|
|
27
|
+
return `Failed to load document ${this.documentId}: ${String(this.cause)}`;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Error when saving a document to storage fails.
|
|
32
|
+
*/
|
|
33
|
+
var StorageSaveError = class extends Data.TaggedError("StorageSaveError") {
|
|
34
|
+
get message() {
|
|
35
|
+
return `Failed to save document ${this.documentId}: ${String(this.cause)}`;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Error when deleting a document from storage fails.
|
|
40
|
+
*/
|
|
41
|
+
var StorageDeleteError = class extends Data.TaggedError("StorageDeleteError") {
|
|
42
|
+
get message() {
|
|
43
|
+
return `Failed to delete document ${this.documentId}: ${String(this.cause)}`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Context tag for MimicDataStorage service.
|
|
48
|
+
*/
|
|
49
|
+
var MimicDataStorageTag = class extends Context.Tag("@voidhash/mimic-server-effect/MimicDataStorage")() {};
|
|
50
|
+
/**
|
|
51
|
+
* Create a MimicDataStorage layer from a storage implementation.
|
|
52
|
+
*/
|
|
53
|
+
const layer = (storage) => Layer.succeed(MimicDataStorageTag, storage);
|
|
54
|
+
/**
|
|
55
|
+
* Create a MimicDataStorage layer from an Effect that produces a storage implementation.
|
|
56
|
+
*/
|
|
57
|
+
const layerEffect = (effect) => Layer.effect(MimicDataStorageTag, effect);
|
|
58
|
+
/**
|
|
59
|
+
* Create a simple storage implementation with minimal configuration.
|
|
60
|
+
*/
|
|
61
|
+
const make = (options) => {
|
|
62
|
+
var _options$delete, _options$onLoad, _options$onSave;
|
|
63
|
+
return {
|
|
64
|
+
load: options.load,
|
|
65
|
+
save: options.save,
|
|
66
|
+
delete: (_options$delete = options.delete) !== null && _options$delete !== void 0 ? _options$delete : (() => Effect.void),
|
|
67
|
+
onLoad: (_options$onLoad = options.onLoad) !== null && _options$onLoad !== void 0 ? _options$onLoad : ((state) => Effect.succeed(state)),
|
|
68
|
+
onSave: (_options$onSave = options.onSave) !== null && _options$onSave !== void 0 ? _options$onSave : ((state) => Effect.succeed(state))
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { MimicDataStorageTag, MimicDataStorage_exports };
|
|
74
|
+
//# sourceMappingURL=MimicDataStorage.mjs.map
|