foldkit 0.97.1 → 0.97.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.
|
@@ -13,7 +13,11 @@ type Hot = NonNullable<ImportMeta['hot']>;
|
|
|
13
13
|
*
|
|
14
14
|
* `dispatch` enqueues a Message into the runtime's message queue; the bridge
|
|
15
15
|
* uses it to fulfill `RequestDispatchMessage` after decoding the payload
|
|
16
|
-
* against
|
|
16
|
+
* against a JSON-canonical derivation of `maybeMessageSchema` (via
|
|
17
|
+
* `Schema.toCodecJson`). The derivation reconstructs runtime values like
|
|
18
|
+
* `Option`, `Date`, `Map`, and `Set` from their JSON-tagged shapes, so
|
|
19
|
+
* application Message Schemas using stdlib types Just Work over dispatch
|
|
20
|
+
* without author-side changes. When `maybeMessageSchema` is `None`, dispatch
|
|
17
21
|
* requests are rejected with an informative error.
|
|
18
22
|
*
|
|
19
23
|
* Production-safe: callers must check `import.meta.hot` is defined before
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webSocketBridge.d.ts","sourceRoot":"","sources":["../../src/devTools/webSocketBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAIN,MAAM,EAEN,MAAM,IAAI,CAAC,EAGZ,MAAM,QAAQ,CAAA;AA+Bf,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,YAAY,CAAA;AAQ3D,KAAK,GAAG,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AAczC
|
|
1
|
+
{"version":3,"file":"webSocketBridge.d.ts","sourceRoot":"","sources":["../../src/devTools/webSocketBridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAIN,MAAM,EAEN,MAAM,IAAI,CAAC,EAGZ,MAAM,QAAQ,CAAA;AA+Bf,OAAO,EAAE,KAAK,aAAa,EAAc,MAAM,YAAY,CAAA;AAQ3D,KAAK,GAAG,GAAG,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAA;AAczC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,aAAa,EACpB,KAAK,GAAG,EACR,UAAU,CAAC,OAAO,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EACnD,oBAAoB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,KACnD,MAAM,CAAC,MAAM,CAAC,IAAI,CAiFjB,CAAA"}
|
|
@@ -21,7 +21,11 @@ const currentAbsoluteIndex = (entriesLength, startIndex) => (entriesLength === 0
|
|
|
21
21
|
*
|
|
22
22
|
* `dispatch` enqueues a Message into the runtime's message queue; the bridge
|
|
23
23
|
* uses it to fulfill `RequestDispatchMessage` after decoding the payload
|
|
24
|
-
* against
|
|
24
|
+
* against a JSON-canonical derivation of `maybeMessageSchema` (via
|
|
25
|
+
* `Schema.toCodecJson`). The derivation reconstructs runtime values like
|
|
26
|
+
* `Option`, `Date`, `Map`, and `Set` from their JSON-tagged shapes, so
|
|
27
|
+
* application Message Schemas using stdlib types Just Work over dispatch
|
|
28
|
+
* without author-side changes. When `maybeMessageSchema` is `None`, dispatch
|
|
25
29
|
* requests are rejected with an informative error.
|
|
26
30
|
*
|
|
27
31
|
* Production-safe: callers must check `import.meta.hot` is defined before
|
|
@@ -30,6 +34,7 @@ const currentAbsoluteIndex = (entriesLength, startIndex) => (entriesLength === 0
|
|
|
30
34
|
export const startWebSocketBridge = (store, hot, dispatch, maybeMessageSchema) => Effect.gen(function* () {
|
|
31
35
|
const connectionId = generateConnectionId();
|
|
32
36
|
const capturedContext = yield* Effect.context();
|
|
37
|
+
const maybeDispatchSchema = Option.map(maybeMessageSchema, S.toCodecJson);
|
|
33
38
|
const encodeEventFrame = S.encodeUnknownSync(EventFrame);
|
|
34
39
|
const encodeResponseFrame = S.encodeUnknownSync(ResponseFrame);
|
|
35
40
|
const sendEvent = (event) => {
|
|
@@ -49,7 +54,7 @@ export const startWebSocketBridge = (store, hot, dispatch, maybeMessageSchema) =
|
|
|
49
54
|
}),
|
|
50
55
|
}));
|
|
51
56
|
const handleRequest = (id, request) => Effect.gen(function* () {
|
|
52
|
-
const response = yield* dispatchRequest(store, dispatch,
|
|
57
|
+
const response = yield* dispatchRequest(store, dispatch, maybeDispatchSchema, request);
|
|
53
58
|
sendResponse(id, response);
|
|
54
59
|
});
|
|
55
60
|
const handleRequestFrame = (frame) => {
|
|
@@ -94,7 +99,7 @@ const readModelResponse = (store, index, maybePath, expand) => Effect.gen(functi
|
|
|
94
99
|
}).pipe(Effect.catchCause(cause => Effect.succeed(ResponseError({
|
|
95
100
|
reason: `Failed to read Model at index ${index}: ${Cause.pretty(cause)}`,
|
|
96
101
|
}))));
|
|
97
|
-
const dispatchRequest = (store, dispatch,
|
|
102
|
+
const dispatchRequest = (store, dispatch, maybeDispatchSchema, request) => Match.value(request).pipe(Match.tagsExhaustive({
|
|
98
103
|
RequestGetModel: ({ maybePath, expand }) => Effect.gen(function* () {
|
|
99
104
|
const state = yield* SubscriptionRef.get(store.stateRef);
|
|
100
105
|
const index = currentAbsoluteIndex(state.entries.length, state.startIndex);
|
|
@@ -147,12 +152,12 @@ const dispatchRequest = (store, dispatch, maybeMessageSchema, request) => Match.
|
|
|
147
152
|
}).pipe(Effect.catchCause(cause => Effect.succeed(ResponseError({
|
|
148
153
|
reason: `Failed to resume: ${Cause.pretty(cause)}`,
|
|
149
154
|
})))),
|
|
150
|
-
RequestDispatchMessage: ({ message }) => Option.match(
|
|
155
|
+
RequestDispatchMessage: ({ message }) => Option.match(maybeDispatchSchema, {
|
|
151
156
|
onNone: () => Effect.succeed(ResponseError({
|
|
152
157
|
reason: 'Cannot dispatch: DevToolsConfig.Message not configured. Pass your Message Schema to enable dispatch.',
|
|
153
158
|
})),
|
|
154
|
-
onSome:
|
|
155
|
-
const decodedMessage = yield* S.decodeUnknownEffect(
|
|
159
|
+
onSome: dispatchSchema => Effect.gen(function* () {
|
|
160
|
+
const decodedMessage = yield* S.decodeUnknownEffect(dispatchSchema)(message);
|
|
156
161
|
const stateBefore = yield* SubscriptionRef.get(store.stateRef);
|
|
157
162
|
const acceptedAtIndex = stateBefore.startIndex + stateBefore.entries.length;
|
|
158
163
|
yield* dispatch(decodedMessage);
|