@shivaedev/server 0.34.1 → 0.35.0
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/CHANGELOG.md +16 -0
- package/README.md +6 -6
- package/dist/adapters/defaultTraceStore.d.ts +8 -0
- package/dist/adapters/defaultTraceStore.d.ts.map +1 -0
- package/dist/adapters/defaultTraceStore.js +40 -0
- package/dist/adapters/defaultTraceStore.js.map +1 -0
- package/dist/appDatabase.d.ts +1 -1
- package/dist/appDatabase.d.ts.map +1 -1
- package/dist/appDatabase.js +1 -0
- package/dist/appDatabase.js.map +1 -1
- package/dist/appDatabaseHttp.d.ts +98 -62
- package/dist/appDatabaseHttp.d.ts.map +1 -1
- package/dist/appHost.d.ts +49 -31
- package/dist/appHost.d.ts.map +1 -1
- package/dist/appHostHttp.d.ts +49 -31
- package/dist/appHostHttp.d.ts.map +1 -1
- package/dist/hostChanges.d.ts.map +1 -1
- package/dist/hostChanges.js +2 -1
- package/dist/hostChanges.js.map +1 -1
- package/dist/hostRpc.d.ts +4 -0
- package/dist/hostRpc.d.ts.map +1 -1
- package/dist/hostRpc.js +2 -1
- package/dist/hostRpc.js.map +1 -1
- package/dist/hostRpcRoutes.d.ts +17 -11
- package/dist/hostRpcRoutes.d.ts.map +1 -1
- package/dist/hostRpcRoutes.js +2 -1
- package/dist/hostRpcRoutes.js.map +1 -1
- package/dist/liveSyncLayer.d.ts +2 -0
- package/dist/liveSyncLayer.d.ts.map +1 -0
- package/dist/liveSyncLayer.js +4 -0
- package/dist/liveSyncLayer.js.map +1 -0
- package/dist/localTracing.d.ts +1 -1
- package/dist/localTracing.d.ts.map +1 -1
- package/dist/localTracing.js +15 -1
- package/dist/localTracing.js.map +1 -1
- package/dist/otlpTracing.js +2 -2
- package/dist/otlpTracing.js.map +1 -1
- package/dist/publishCommand.d.ts +2 -1
- package/dist/publishCommand.d.ts.map +1 -1
- package/dist/publishCommand.js +9 -5
- package/dist/publishCommand.js.map +1 -1
- package/package.json +13 -13
- package/src/adapters/defaultTraceStore.ts +43 -0
- package/src/appDatabase.ts +2 -1
- package/src/hostChanges.ts +5 -1
- package/src/hostRpc.ts +2 -1
- package/src/hostRpcRoutes.ts +2 -0
- package/src/liveSyncLayer.ts +4 -0
- package/src/localTracing.ts +18 -1
- package/src/otlpTracing.ts +2 -2
- package/src/publishCommand.ts +9 -4
package/src/publishCommand.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { Effect, Option, Schedule } from "effect";
|
|
1
|
+
import { Effect, identity, Option, Schedule } from "effect";
|
|
2
2
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
3
|
import { CommandPublication, type CommandPublicationError } from "@shivaedev/changes/commandPublication.ts";
|
|
4
|
+
import { SyncDelivery, type SyncToken } from "@shivaedev/changes/syncToken.ts";
|
|
5
|
+
import { LiveServer } from "@shivaedev/contract/live-server/service.ts";
|
|
4
6
|
import { ChangeObserver } from "@shivaedev/sql/transact.ts";
|
|
5
7
|
|
|
6
8
|
const recoverPublication = Effect.fnUntraced(function* (cause: CommandPublicationError) {
|
|
@@ -11,7 +13,7 @@ const recoverPublication = Effect.fnUntraced(function* (cause: CommandPublicatio
|
|
|
11
13
|
);
|
|
12
14
|
});
|
|
13
15
|
|
|
14
|
-
export function publishCommand<A, E, R>(effect: Effect.Effect<A, E, R>, declaredKeys: (result: A) => readonly unknown[]) {
|
|
16
|
+
export function publishCommand<A, E, R>(effect: Effect.Effect<A, E, R>, declaredKeys: (result: A) => readonly unknown[], sync?: SyncToken) {
|
|
15
17
|
return Effect.uninterruptibleMask((restore) =>
|
|
16
18
|
Effect.gen(function* () {
|
|
17
19
|
const reactivity = yield* Effect.serviceOption(Reactivity.Reactivity);
|
|
@@ -31,12 +33,15 @@ export function publishCommand<A, E, R>(effect: Effect.Effect<A, E, R>, declared
|
|
|
31
33
|
}),
|
|
32
34
|
);
|
|
33
35
|
const keys = declaredKeys(result).filter((key) => !published.has(key));
|
|
34
|
-
if (keys.length > 0) {
|
|
36
|
+
if (keys.length > 0 || sync !== undefined) {
|
|
35
37
|
const publication = yield* CommandPublication;
|
|
38
|
+
const live = yield* Effect.serviceOption(LiveServer);
|
|
39
|
+
// The token leaves after the handler's last commit and behind the declared keys, so a stream that passes it has applied them all.
|
|
36
40
|
yield* publication
|
|
37
|
-
.publish(keys)
|
|
41
|
+
.publish(keys, sync)
|
|
38
42
|
.pipe(
|
|
39
43
|
Effect.provideService(Reactivity.Reactivity, reactivity.value),
|
|
44
|
+
Option.isSome(live) ? Effect.provideService(SyncDelivery, live.value.synced) : identity,
|
|
40
45
|
Effect.retry({ schedule: Schedule.exponential("50 millis"), times: 2 }),
|
|
41
46
|
Effect.catch(recoverPublication),
|
|
42
47
|
);
|