@shivaedev/contract 0.36.1 → 0.39.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 +30 -0
- package/README.md +46 -2
- package/dist/CommandGuard.d.ts.map +1 -1
- package/dist/CommandGuard.js +10 -3
- package/dist/CommandGuard.js.map +1 -1
- package/dist/CommandResultKeys.d.ts +4 -0
- package/dist/CommandResultKeys.d.ts.map +1 -0
- package/dist/CommandResultKeys.js +3 -0
- package/dist/CommandResultKeys.js.map +1 -0
- package/dist/LiveServer.js +3 -3
- package/dist/LiveServer.js.map +1 -1
- package/dist/SocketClock.d.ts +3 -0
- package/dist/SocketClock.d.ts.map +1 -0
- package/dist/SocketClock.js +5 -0
- package/dist/SocketClock.js.map +1 -0
- package/dist/adapters/activityState.d.ts +1 -0
- package/dist/adapters/activityState.d.ts.map +1 -1
- package/dist/adapters/activityState.js +16 -1
- package/dist/adapters/activityState.js.map +1 -1
- package/dist/adapters/clientConnection.d.ts +5 -2
- package/dist/adapters/clientConnection.d.ts.map +1 -1
- package/dist/adapters/clientConnection.js +11 -2
- package/dist/adapters/clientConnection.js.map +1 -1
- package/dist/adapters/resumeSocket.d.ts +7 -0
- package/dist/adapters/resumeSocket.d.ts.map +1 -0
- package/dist/adapters/resumeSocket.js +57 -0
- package/dist/adapters/resumeSocket.js.map +1 -0
- package/dist/aggregateLiveStatus.d.ts.map +1 -0
- package/dist/aggregateLiveStatus.js.map +1 -0
- package/dist/automaticLive.d.ts.map +1 -1
- package/dist/automaticLive.js +7 -7
- package/dist/automaticLive.js.map +1 -1
- package/dist/automaticQuery.d.ts.map +1 -0
- package/dist/{internal/automaticQuery.js → automaticQuery.js} +3 -3
- package/dist/automaticQuery.js.map +1 -0
- package/dist/bind.d.ts.map +1 -1
- package/dist/bind.js +2 -2
- package/dist/bind.js.map +1 -1
- package/dist/changesSuccess.d.ts.map +1 -0
- package/dist/changesSuccess.js.map +1 -0
- package/dist/clientActivities.d.ts +30 -0
- package/dist/clientActivities.d.ts.map +1 -0
- package/dist/{internal/clientActivity.js → clientActivities.js} +4 -3
- package/dist/clientActivities.js.map +1 -0
- package/dist/clientActivity.d.ts +1 -1
- package/dist/clientActivity.d.ts.map +1 -1
- package/dist/clientOperations.d.ts.map +1 -0
- package/dist/{internal/clientOperations.js → clientOperations.js} +5 -4
- package/dist/clientOperations.js.map +1 -0
- package/dist/commandPayload.d.ts.map +1 -0
- package/dist/commandPayload.js.map +1 -0
- package/dist/commandResult.d.ts +7 -0
- package/dist/commandResult.d.ts.map +1 -0
- package/dist/commandResult.js +11 -0
- package/dist/commandResult.js.map +1 -0
- package/dist/compareQueries.d.ts.map +1 -0
- package/dist/{internal/compareQueries.js → compareQueries.js} +5 -6
- package/dist/compareQueries.js.map +1 -0
- package/dist/connectionProtocol.d.ts +17 -0
- package/dist/connectionProtocol.d.ts.map +1 -0
- package/dist/connectionProtocol.js +14 -0
- package/dist/connectionProtocol.js.map +1 -0
- package/dist/connectionReadiness.d.ts +20 -0
- package/dist/connectionReadiness.d.ts.map +1 -0
- package/dist/connectionReadiness.js +23 -0
- package/dist/connectionReadiness.js.map +1 -0
- package/dist/contract.d.ts +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +2 -2
- package/dist/contract.js.map +1 -1
- package/dist/declarationError.d.ts.map +1 -0
- package/dist/declarationError.js.map +1 -0
- package/dist/live-server/resync.d.ts.map +1 -0
- package/dist/live-server/resync.js.map +1 -0
- package/dist/live-server/stream.d.ts.map +1 -0
- package/dist/live-server/stream.js.map +1 -0
- package/dist/live-server/subscribe.d.ts.map +1 -0
- package/dist/live-server/subscribe.js.map +1 -0
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +5 -5
- package/dist/live.js.map +1 -1
- package/dist/liveAttempt.d.ts.map +1 -0
- package/dist/liveAttempt.js.map +1 -0
- package/dist/liveHintQueue.d.ts.map +1 -0
- package/dist/liveHintQueue.js.map +1 -0
- package/dist/liveInvalidation.d.ts.map +1 -0
- package/dist/liveInvalidation.js.map +1 -0
- package/dist/livePending.d.ts.map +1 -0
- package/dist/livePending.js.map +1 -0
- package/dist/liveRetry.d.ts.map +1 -0
- package/dist/liveRetry.js.map +1 -0
- package/dist/makeLiveServer.js +2 -2
- package/dist/makeLiveServer.js.map +1 -1
- package/dist/operation.d.ts +1 -1
- package/dist/operation.d.ts.map +1 -1
- package/dist/operation.js +1 -1
- package/dist/operation.js.map +1 -1
- package/dist/operationDeclaration.d.ts.map +1 -0
- package/dist/operationDeclaration.js.map +1 -0
- package/dist/policyContext.d.ts.map +1 -0
- package/dist/policyContext.js.map +1 -0
- package/dist/prependMiddleware.d.ts.map +1 -0
- package/dist/prependMiddleware.js.map +1 -0
- package/dist/queryDelivery.d.ts.map +1 -0
- package/dist/queryDelivery.js.map +1 -0
- package/dist/queryFailure.d.ts.map +1 -0
- package/dist/queryFailure.js.map +1 -0
- package/dist/queryHints.d.ts.map +1 -0
- package/dist/queryHints.js.map +1 -0
- package/dist/queryKeys.d.ts.map +1 -1
- package/dist/queryKeys.js +2 -2
- package/dist/queryKeys.js.map +1 -1
- package/dist/{internal/querySignals.d.ts → queryProgress.d.ts} +1 -1
- package/dist/queryProgress.d.ts.map +1 -0
- package/dist/{internal/querySignals.js → queryProgress.js} +1 -1
- package/dist/queryProgress.js.map +1 -0
- package/dist/queryReactivity.d.ts.map +1 -0
- package/dist/queryReactivity.js.map +1 -0
- package/dist/queryReadKeys.d.ts.map +1 -0
- package/dist/queryReadKeys.js.map +1 -0
- package/dist/queryResult.d.ts.map +1 -0
- package/dist/queryResult.js.map +1 -0
- package/dist/querySubscription.js +2 -2
- package/dist/querySubscription.js.map +1 -1
- package/dist/readPolicy.d.ts.map +1 -1
- package/dist/readPolicy.js +1 -1
- package/dist/readPolicy.js.map +1 -1
- package/dist/resolveQueries.d.ts.map +1 -0
- package/dist/resolveQueries.js.map +1 -0
- package/dist/resume.d.ts +2 -2
- package/dist/resume.d.ts.map +1 -1
- package/dist/resume.js +3 -14
- package/dist/resume.js.map +1 -1
- package/dist/resumeSources.d.ts +3 -0
- package/dist/resumeSources.d.ts.map +1 -0
- package/dist/resumeSources.js +16 -0
- package/dist/resumeSources.js.map +1 -0
- package/dist/retryOnChange.d.ts.map +1 -0
- package/dist/retryOnChange.js.map +1 -0
- package/dist/rpcClient.d.ts.map +1 -0
- package/dist/rpcClient.js +70 -0
- package/dist/rpcClient.js.map +1 -0
- package/dist/serverMetadata.d.ts +1 -1
- package/dist/serverMetadata.d.ts.map +1 -1
- package/dist/serverMetadata.js +2 -2
- package/dist/serverMetadata.js.map +1 -1
- package/dist/socketProtocol.d.ts +15 -0
- package/dist/socketProtocol.d.ts.map +1 -0
- package/dist/socketProtocol.js +47 -0
- package/dist/socketProtocol.js.map +1 -0
- package/dist/subject.d.ts +1 -1
- package/dist/subject.d.ts.map +1 -1
- package/dist/subjectLayers.d.ts +1 -1
- package/dist/subjectLayers.d.ts.map +1 -1
- package/dist/subjectLayers.js +1 -1
- package/dist/subjectLayers.js.map +1 -1
- package/dist/subjectMiddleware.d.ts.map +1 -0
- package/dist/subjectMiddleware.js.map +1 -0
- package/dist/wrapAtom.d.ts.map +1 -0
- package/dist/wrapAtom.js.map +1 -0
- package/package.json +15 -15
- package/src/CommandGuard.ts +16 -6
- package/src/CommandResultKeys.ts +4 -0
- package/src/LiveServer.ts +3 -3
- package/src/SocketClock.ts +5 -0
- package/src/adapters/activityState.ts +18 -3
- package/src/adapters/clientConnection.ts +22 -3
- package/src/adapters/resumeSocket.ts +79 -0
- package/src/automaticLive.ts +7 -7
- package/src/{internal/automaticQuery.ts → automaticQuery.ts} +3 -3
- package/src/bind.ts +2 -2
- package/src/{internal/clientActivity.ts → clientActivities.ts} +10 -2
- package/src/clientActivity.ts +1 -1
- package/src/{internal/clientOperations.ts → clientOperations.ts} +5 -3
- package/src/commandResult.ts +15 -0
- package/src/{internal/compareQueries.ts → compareQueries.ts} +5 -6
- package/src/connectionProtocol.ts +27 -0
- package/src/connectionReadiness.ts +32 -0
- package/src/contract.ts +2 -2
- package/src/live.ts +5 -5
- package/src/makeLiveServer.ts +2 -2
- package/src/operation.ts +1 -1
- package/src/queryKeys.ts +2 -2
- package/src/querySubscription.ts +2 -2
- package/src/readPolicy.ts +1 -1
- package/src/resume.ts +4 -16
- package/src/resumeSources.ts +19 -0
- package/src/rpcClient.ts +90 -0
- package/src/serverMetadata.ts +2 -2
- package/src/socketProtocol.ts +73 -0
- package/src/subject.ts +1 -1
- package/src/subjectLayers.ts +1 -1
- package/dist/internal/aggregateLiveStatus.d.ts.map +0 -1
- package/dist/internal/aggregateLiveStatus.js.map +0 -1
- package/dist/internal/automaticQuery.d.ts.map +0 -1
- package/dist/internal/automaticQuery.js.map +0 -1
- package/dist/internal/changesSuccess.d.ts.map +0 -1
- package/dist/internal/changesSuccess.js.map +0 -1
- package/dist/internal/clientActivity.d.ts +0 -28
- package/dist/internal/clientActivity.d.ts.map +0 -1
- package/dist/internal/clientActivity.js.map +0 -1
- package/dist/internal/clientOperations.d.ts.map +0 -1
- package/dist/internal/clientOperations.js.map +0 -1
- package/dist/internal/commandPayload.d.ts.map +0 -1
- package/dist/internal/commandPayload.js.map +0 -1
- package/dist/internal/compareQueries.d.ts.map +0 -1
- package/dist/internal/compareQueries.js.map +0 -1
- package/dist/internal/declarationError.d.ts.map +0 -1
- package/dist/internal/declarationError.js.map +0 -1
- package/dist/internal/live-server/resync.d.ts.map +0 -1
- package/dist/internal/live-server/resync.js.map +0 -1
- package/dist/internal/live-server/stream.d.ts.map +0 -1
- package/dist/internal/live-server/stream.js.map +0 -1
- package/dist/internal/live-server/subscribe.d.ts.map +0 -1
- package/dist/internal/live-server/subscribe.js.map +0 -1
- package/dist/internal/liveAttempt.d.ts.map +0 -1
- package/dist/internal/liveAttempt.js.map +0 -1
- package/dist/internal/liveHintQueue.d.ts.map +0 -1
- package/dist/internal/liveHintQueue.js.map +0 -1
- package/dist/internal/liveInvalidation.d.ts.map +0 -1
- package/dist/internal/liveInvalidation.js.map +0 -1
- package/dist/internal/livePending.d.ts.map +0 -1
- package/dist/internal/livePending.js.map +0 -1
- package/dist/internal/liveRetry.d.ts.map +0 -1
- package/dist/internal/liveRetry.js.map +0 -1
- package/dist/internal/operationDeclaration.d.ts.map +0 -1
- package/dist/internal/operationDeclaration.js.map +0 -1
- package/dist/internal/policyContext.d.ts.map +0 -1
- package/dist/internal/policyContext.js.map +0 -1
- package/dist/internal/prependMiddleware.d.ts.map +0 -1
- package/dist/internal/prependMiddleware.js.map +0 -1
- package/dist/internal/queryDelivery.d.ts.map +0 -1
- package/dist/internal/queryDelivery.js.map +0 -1
- package/dist/internal/queryFailure.d.ts.map +0 -1
- package/dist/internal/queryFailure.js.map +0 -1
- package/dist/internal/queryHints.d.ts.map +0 -1
- package/dist/internal/queryHints.js.map +0 -1
- package/dist/internal/queryReactivity.d.ts.map +0 -1
- package/dist/internal/queryReactivity.js.map +0 -1
- package/dist/internal/queryReadKeys.d.ts.map +0 -1
- package/dist/internal/queryReadKeys.js.map +0 -1
- package/dist/internal/queryResult.d.ts.map +0 -1
- package/dist/internal/queryResult.js.map +0 -1
- package/dist/internal/querySignals.d.ts.map +0 -1
- package/dist/internal/querySignals.js.map +0 -1
- package/dist/internal/resolveQueries.d.ts.map +0 -1
- package/dist/internal/resolveQueries.js.map +0 -1
- package/dist/internal/retryOnChange.d.ts.map +0 -1
- package/dist/internal/retryOnChange.js.map +0 -1
- package/dist/internal/rpcClient.d.ts.map +0 -1
- package/dist/internal/rpcClient.js +0 -66
- package/dist/internal/rpcClient.js.map +0 -1
- package/dist/internal/subjectMiddleware.d.ts.map +0 -1
- package/dist/internal/subjectMiddleware.js.map +0 -1
- package/dist/internal/wrapAtom.d.ts.map +0 -1
- package/dist/internal/wrapAtom.js.map +0 -1
- package/src/internal/rpcClient.ts +0 -96
- /package/dist/{internal/aggregateLiveStatus.d.ts → aggregateLiveStatus.d.ts} +0 -0
- /package/dist/{internal/aggregateLiveStatus.js → aggregateLiveStatus.js} +0 -0
- /package/dist/{internal/automaticQuery.d.ts → automaticQuery.d.ts} +0 -0
- /package/dist/{internal/changesSuccess.d.ts → changesSuccess.d.ts} +0 -0
- /package/dist/{internal/changesSuccess.js → changesSuccess.js} +0 -0
- /package/dist/{internal/clientOperations.d.ts → clientOperations.d.ts} +0 -0
- /package/dist/{internal/commandPayload.d.ts → commandPayload.d.ts} +0 -0
- /package/dist/{internal/commandPayload.js → commandPayload.js} +0 -0
- /package/dist/{internal/compareQueries.d.ts → compareQueries.d.ts} +0 -0
- /package/dist/{internal/declarationError.d.ts → declarationError.d.ts} +0 -0
- /package/dist/{internal/declarationError.js → declarationError.js} +0 -0
- /package/dist/{internal/live-server → live-server}/resync.d.ts +0 -0
- /package/dist/{internal/live-server → live-server}/resync.js +0 -0
- /package/dist/{internal/live-server → live-server}/stream.d.ts +0 -0
- /package/dist/{internal/live-server → live-server}/stream.js +0 -0
- /package/dist/{internal/live-server → live-server}/subscribe.d.ts +0 -0
- /package/dist/{internal/live-server → live-server}/subscribe.js +0 -0
- /package/dist/{internal/liveAttempt.d.ts → liveAttempt.d.ts} +0 -0
- /package/dist/{internal/liveAttempt.js → liveAttempt.js} +0 -0
- /package/dist/{internal/liveHintQueue.d.ts → liveHintQueue.d.ts} +0 -0
- /package/dist/{internal/liveHintQueue.js → liveHintQueue.js} +0 -0
- /package/dist/{internal/liveInvalidation.d.ts → liveInvalidation.d.ts} +0 -0
- /package/dist/{internal/liveInvalidation.js → liveInvalidation.js} +0 -0
- /package/dist/{internal/livePending.d.ts → livePending.d.ts} +0 -0
- /package/dist/{internal/livePending.js → livePending.js} +0 -0
- /package/dist/{internal/liveRetry.d.ts → liveRetry.d.ts} +0 -0
- /package/dist/{internal/liveRetry.js → liveRetry.js} +0 -0
- /package/dist/{internal/operationDeclaration.d.ts → operationDeclaration.d.ts} +0 -0
- /package/dist/{internal/operationDeclaration.js → operationDeclaration.js} +0 -0
- /package/dist/{internal/policyContext.d.ts → policyContext.d.ts} +0 -0
- /package/dist/{internal/policyContext.js → policyContext.js} +0 -0
- /package/dist/{internal/prependMiddleware.d.ts → prependMiddleware.d.ts} +0 -0
- /package/dist/{internal/prependMiddleware.js → prependMiddleware.js} +0 -0
- /package/dist/{internal/queryDelivery.d.ts → queryDelivery.d.ts} +0 -0
- /package/dist/{internal/queryDelivery.js → queryDelivery.js} +0 -0
- /package/dist/{internal/queryFailure.d.ts → queryFailure.d.ts} +0 -0
- /package/dist/{internal/queryFailure.js → queryFailure.js} +0 -0
- /package/dist/{internal/queryHints.d.ts → queryHints.d.ts} +0 -0
- /package/dist/{internal/queryHints.js → queryHints.js} +0 -0
- /package/dist/{internal/queryReactivity.d.ts → queryReactivity.d.ts} +0 -0
- /package/dist/{internal/queryReactivity.js → queryReactivity.js} +0 -0
- /package/dist/{internal/queryReadKeys.d.ts → queryReadKeys.d.ts} +0 -0
- /package/dist/{internal/queryReadKeys.js → queryReadKeys.js} +0 -0
- /package/dist/{internal/queryResult.d.ts → queryResult.d.ts} +0 -0
- /package/dist/{internal/queryResult.js → queryResult.js} +0 -0
- /package/dist/{internal/resolveQueries.d.ts → resolveQueries.d.ts} +0 -0
- /package/dist/{internal/resolveQueries.js → resolveQueries.js} +0 -0
- /package/dist/{internal/retryOnChange.d.ts → retryOnChange.d.ts} +0 -0
- /package/dist/{internal/retryOnChange.js → retryOnChange.js} +0 -0
- /package/dist/{internal/rpcClient.d.ts → rpcClient.d.ts} +0 -0
- /package/dist/{internal/subjectMiddleware.d.ts → subjectMiddleware.d.ts} +0 -0
- /package/dist/{internal/subjectMiddleware.js → subjectMiddleware.js} +0 -0
- /package/dist/{internal/wrapAtom.d.ts → wrapAtom.d.ts} +0 -0
- /package/dist/{internal/wrapAtom.js → wrapAtom.js} +0 -0
- /package/src/{internal/aggregateLiveStatus.ts → aggregateLiveStatus.ts} +0 -0
- /package/src/{internal/changesSuccess.ts → changesSuccess.ts} +0 -0
- /package/src/{internal/commandPayload.ts → commandPayload.ts} +0 -0
- /package/src/{internal/declarationError.ts → declarationError.ts} +0 -0
- /package/src/{internal/live-server → live-server}/resync.ts +0 -0
- /package/src/{internal/live-server → live-server}/stream.ts +0 -0
- /package/src/{internal/live-server → live-server}/subscribe.ts +0 -0
- /package/src/{internal/liveAttempt.ts → liveAttempt.ts} +0 -0
- /package/src/{internal/liveHintQueue.ts → liveHintQueue.ts} +0 -0
- /package/src/{internal/liveInvalidation.ts → liveInvalidation.ts} +0 -0
- /package/src/{internal/livePending.ts → livePending.ts} +0 -0
- /package/src/{internal/liveRetry.ts → liveRetry.ts} +0 -0
- /package/src/{internal/operationDeclaration.ts → operationDeclaration.ts} +0 -0
- /package/src/{internal/policyContext.ts → policyContext.ts} +0 -0
- /package/src/{internal/prependMiddleware.ts → prependMiddleware.ts} +0 -0
- /package/src/{internal/queryDelivery.ts → queryDelivery.ts} +0 -0
- /package/src/{internal/queryFailure.ts → queryFailure.ts} +0 -0
- /package/src/{internal/queryHints.ts → queryHints.ts} +0 -0
- /package/src/{internal/querySignals.ts → queryProgress.ts} +0 -0
- /package/src/{internal/queryReactivity.ts → queryReactivity.ts} +0 -0
- /package/src/{internal/queryReadKeys.ts → queryReadKeys.ts} +0 -0
- /package/src/{internal/queryResult.ts → queryResult.ts} +0 -0
- /package/src/{internal/resolveQueries.ts → resolveQueries.ts} +0 -0
- /package/src/{internal/retryOnChange.ts → retryOnChange.ts} +0 -0
- /package/src/{internal/subjectMiddleware.ts → subjectMiddleware.ts} +0 -0
- /package/src/{internal/wrapAtom.ts → wrapAtom.ts} +0 -0
package/dist/subject.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subject.d.ts","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"subject.d.ts","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;CACtE;AAED,MAAM,MAAM,eAAe,CAAC,QAAQ,SAAS,kBAAkB,IAC9D,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,SAAS,aAAa,CAAC,aAAa,CAAC,MAAM,SAAS,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC;AAErI,MAAM,MAAM,WAAW,CAAC,KAAK,SAAS,GAAG,CAAC,GAAG,EAAE,QAAQ,SAAS,kBAAkB,GAAG,SAAS,IAAI,QAAQ,SAAS,kBAAkB,GAClI,GAAG,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,GACxE,KAAK,CAAC"}
|
package/dist/subjectLayers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Context, type Effect, Layer } from "effect";
|
|
2
2
|
import { Rpc, type RpcGroup } from "effect/rpc";
|
|
3
|
-
import { SUBJECT_TYPE_ID } from "#internal/subjectMiddleware.ts";
|
|
4
3
|
import type { SubjectDeclaration } from "#subject.ts";
|
|
4
|
+
import { SUBJECT_TYPE_ID } from "#subjectMiddleware.ts";
|
|
5
5
|
type Middleware<R extends Rpc.Any> = R extends {
|
|
6
6
|
readonly middlewares: ReadonlySet<infer TMiddleware>;
|
|
7
7
|
} ? Extract<TMiddleware, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subjectLayers.d.ts","sourceRoot":"","sources":["../src/subjectLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,KAAK,QAAQ,EAAsB,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"subjectLayers.d.ts","sourceRoot":"","sources":["../src/subjectLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAE,KAAK,QAAQ,EAAsB,MAAM,YAAY,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,KAAK,UAAU,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS;IAAE,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,WAAW,CAAC,CAAA;CAAE,GACpG,OAAO,CAAC,WAAW,EAAE;IAAE,QAAQ,CAAC,CAAC,eAAe,CAAC,EAAE,kBAAkB,CAAA;CAAE,CAAC,GACxE,KAAK,CAAC;AAQT,wBAAgB,aAAa,CAAC,CAAC,SAAS,GAAG,CAAC,GAAG,EAC9C,KAAK,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,GACzB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,eAAe,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/subjectLayers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
2
|
import { Rpc } from "effect/rpc";
|
|
3
|
-
import { SUBJECT_TYPE_ID } from "#
|
|
3
|
+
import { SUBJECT_TYPE_ID } from "#subjectMiddleware.ts";
|
|
4
4
|
function isSubject(middleware) {
|
|
5
5
|
return SUBJECT_TYPE_ID in middleware;
|
|
6
6
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subjectLayers.js","sourceRoot":"","sources":["../src/subjectLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAqC,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"subjectLayers.js","sourceRoot":"","sources":["../src/subjectLayers.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,GAAG,EAAqC,MAAM,YAAY,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAMxD,SAAS,SAAS,CAAC,UAA6C;IAG/D,OAAO,eAAe,IAAI,UAAU,CAAC;AACtC,CAAC;AAKD,MAAM,UAAU,aAAa,CAAC,KAAiC;IAC9D,MAAM,MAAM,GAAyC,EAAE,CAAC;IACxD,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QAC3C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,SAAS;QACV,CAAC;QACD,MAAM,WAAW,GAAmD,GAAG,CAAC,WAAW,CAAC;QACpF,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;YACtC,IAAI,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC3B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;YAC/E,CAAC;QACF,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,MAAM,CAAC,CAAC;AAC/C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subjectMiddleware.d.ts","sourceRoot":"","sources":["../src/subjectMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEvE,eAAO,MAAM,eAAe,2CAA2C,CAAC;AAExE,MAAM,WAAW,iBAAiB,CAAC,QAAQ,SAAS,kBAAkB,CAAE,SAAQ,aAAa,CAAC,KAAK;IAClG,QAAQ,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE;QAChC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC7C,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;QACzB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,CAAC;QAClC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC;KAC5B,CAAC;CACF;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,SAAS,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;;EAOrG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subjectMiddleware.js","sourceRoot":"","sources":["../src/subjectMiddleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,CAAC,MAAM,eAAe,GAAG,wCAAwC,CAAC;AAWxE,MAAM,UAAU,iBAAiB,CAAsC,IAAY,EAAE,OAAiB;IACrG,MAAM,KAAK,GAAsB,OAAO,CAAC,KAAK,CAAC;IAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,EAAwE,CAC/G,+BAA+B,IAAI,EAAE,EACrC,EAAE,KAAK,EAAE,CACT,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapAtom.d.ts","sourceRoot":"","sources":["../src/wrapAtom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,wBAAgB,QAAQ,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,KAAK,CAAC,EAAE,MAAM,GAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAW7H"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wrapAtom.js","sourceRoot":"","sources":["../src/wrapAtom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAE/C,MAAM,UAAU,QAAQ,CAAI,IAAkB,EAAE,IAAkC,EAAE,MAAM,GAAiB,IAAI;IAC9G,IAAI,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,kBAAkB,EAAE,MAAM,EAAE,CAAC,CAAC;IAC3E,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACpB,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;SAAM,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.39.0",
|
|
4
4
|
"description": "Typed query and command contracts over native Effect RPC and reactivity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -43,30 +43,30 @@
|
|
|
43
43
|
"README.md"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@shivaedev/changes": "0.
|
|
47
|
-
"@shivaedev/service": "0.
|
|
46
|
+
"@shivaedev/changes": "0.11.0",
|
|
47
|
+
"@shivaedev/service": "0.8.0",
|
|
48
48
|
"@shivaedev/types": "0.4.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@effect/platform-node": "4.0
|
|
52
|
-
"@effect/vitest": "4.0
|
|
53
|
-
"@shivaedev/errors": "0.
|
|
54
|
-
"@shivaedev/identity": "0.
|
|
55
|
-
"@shivaedev/quality": "0.
|
|
56
|
-
"@shivaedev/server": "0.
|
|
57
|
-
"@shivaedev/sql": "0.
|
|
58
|
-
"@shivaedev/test-kits": "0.
|
|
59
|
-
"@shivaedev/test-sql": "0.
|
|
60
|
-
"@shivaedev/test-story": "0.
|
|
51
|
+
"@effect/platform-node": "4.1.0",
|
|
52
|
+
"@effect/vitest": "4.1.0",
|
|
53
|
+
"@shivaedev/errors": "0.10.0",
|
|
54
|
+
"@shivaedev/identity": "0.27.0",
|
|
55
|
+
"@shivaedev/quality": "0.65.0",
|
|
56
|
+
"@shivaedev/server": "0.27.0",
|
|
57
|
+
"@shivaedev/sql": "0.42.0",
|
|
58
|
+
"@shivaedev/test-kits": "0.8.0",
|
|
59
|
+
"@shivaedev/test-sql": "0.24.0",
|
|
60
|
+
"@shivaedev/test-story": "0.42.0",
|
|
61
61
|
"@types/node": "24.19.2",
|
|
62
|
-
"effect": "4.0
|
|
62
|
+
"effect": "4.1.0",
|
|
63
63
|
"esbuild": "0.28.2",
|
|
64
64
|
"happy-dom": "21.0.4",
|
|
65
65
|
"typescript": "7.0.2",
|
|
66
66
|
"vitest": "5.0.5"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"effect": "4.0
|
|
69
|
+
"effect": "4.1.0"
|
|
70
70
|
},
|
|
71
71
|
"engines": {
|
|
72
72
|
"node": ">=24"
|
package/src/CommandGuard.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Context, Effect, Layer, Option } from "effect";
|
|
1
|
+
import { Context, Effect, Layer, Option, Ref } from "effect";
|
|
2
2
|
import { type Rpc, type RpcGroup, RpcMiddleware } from "effect/rpc";
|
|
3
|
-
import { invalidationKeys } from "@shivaedev/changes/keys.ts";
|
|
4
|
-
import {
|
|
3
|
+
import { invalidationKeys, type Key } from "@shivaedev/changes/keys.ts";
|
|
4
|
+
import { CommandResultKeys } from "#CommandResultKeys.ts";
|
|
5
|
+
import { prependMiddleware } from "#prependMiddleware.ts";
|
|
5
6
|
import { CurrentViewer } from "#readPolicy.ts";
|
|
6
7
|
import { CommandInvalidation } from "#serverMetadata.ts";
|
|
7
8
|
|
|
@@ -14,9 +15,18 @@ export function commandGuardLayer(boundary: CommandBoundary): Layer.Layer<Comman
|
|
|
14
15
|
const declaration = Context.getOption(rpc.annotations, CommandInvalidation);
|
|
15
16
|
return Option.isNone(declaration)
|
|
16
17
|
? effect
|
|
17
|
-
: Effect.
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
: Effect.gen(function* () {
|
|
19
|
+
const viewer = yield* CurrentViewer;
|
|
20
|
+
const keys = yield* Ref.make<readonly Key[]>([]);
|
|
21
|
+
const completed = effect.pipe(
|
|
22
|
+
Effect.provideService(CommandResultKeys, keys),
|
|
23
|
+
Effect.flatMap((result) => Effect.map(Ref.get(keys), (extra) => ({ extra, result }))),
|
|
24
|
+
);
|
|
25
|
+
const published = yield* boundary(completed, ({ extra, result }) =>
|
|
26
|
+
invalidationKeys([...declaration.value.invalidates(payload, result, viewer), ...extra]),
|
|
27
|
+
);
|
|
28
|
+
return published.result;
|
|
29
|
+
});
|
|
20
30
|
});
|
|
21
31
|
}
|
|
22
32
|
|
package/src/LiveServer.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
2
2
|
import { defineService } from "@shivaedev/service/defineService.ts";
|
|
3
3
|
import { genericMethod } from "@shivaedev/service/genericMethod.ts";
|
|
4
|
-
import { resync } from "#
|
|
5
|
-
import { stream } from "#
|
|
6
|
-
import { subscribe } from "#
|
|
4
|
+
import { resync } from "#live-server/resync.ts";
|
|
5
|
+
import { stream } from "#live-server/stream.ts";
|
|
6
|
+
import { subscribe } from "#live-server/subscribe.ts";
|
|
7
7
|
import { makeLiveServer } from "#makeLiveServer.ts";
|
|
8
8
|
|
|
9
9
|
export const LiveServer = defineService({
|
|
@@ -2,18 +2,33 @@ import { Effect, SubscriptionRef } from "effect";
|
|
|
2
2
|
import type { ClientActivityState, ConnectionStatus } from "#clientActivity.ts";
|
|
3
3
|
|
|
4
4
|
export function activityState() {
|
|
5
|
+
let held = 0;
|
|
6
|
+
let connection: ConnectionStatus = "live";
|
|
5
7
|
const state = Effect.runSync(
|
|
6
8
|
SubscriptionRef.make<ClientActivityState>({ connectionStatus: "live", liveHints: 0, liveInvalidations: 0, refreshingAtoms: 0, rpcCalls: 0 }),
|
|
7
9
|
);
|
|
10
|
+
function publish() {
|
|
11
|
+
const connectionStatus = held > 0 ? "waiting-for-connection" : connection;
|
|
12
|
+
Effect.runSync(
|
|
13
|
+
SubscriptionRef.update(state, (current) => (current.connectionStatus === connectionStatus ? current : { ...current, connectionStatus })),
|
|
14
|
+
);
|
|
15
|
+
}
|
|
8
16
|
return {
|
|
9
17
|
activity: Object.assign(SubscriptionRef.changes(state), { current: SubscriptionRef.get(state) }),
|
|
10
18
|
change: (key: Exclude<keyof ClientActivityState, "connectionStatus">, delta: number) => {
|
|
11
19
|
Effect.runSync(SubscriptionRef.update(state, (current) => ({ ...current, [key]: current[key] + delta })));
|
|
12
20
|
},
|
|
21
|
+
hold: () => {
|
|
22
|
+
held += 1;
|
|
23
|
+
publish();
|
|
24
|
+
return () => {
|
|
25
|
+
held -= 1;
|
|
26
|
+
publish();
|
|
27
|
+
};
|
|
28
|
+
},
|
|
13
29
|
setConnection: (connectionStatus: ConnectionStatus) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
);
|
|
30
|
+
connection = connectionStatus;
|
|
31
|
+
publish();
|
|
17
32
|
},
|
|
18
33
|
};
|
|
19
34
|
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { Effect, Layer, Option, Stream } from "effect";
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
|
-
import type { ConnectionStatus } from "#clientActivity.ts";
|
|
4
|
+
import type { ClientActivityState, ConnectionStatus } from "#clientActivity.ts";
|
|
5
5
|
import type { LiveStatus } from "#live.ts";
|
|
6
6
|
|
|
7
|
-
export function clientConnection(
|
|
7
|
+
export function clientConnection(
|
|
8
|
+
factory: Atom.RuntimeFactory,
|
|
9
|
+
publish: (status: ConnectionStatus) => void,
|
|
10
|
+
activity: Stream.Stream<ClientActivityState> & { readonly current: Effect.Effect<ClientActivityState> },
|
|
11
|
+
) {
|
|
8
12
|
const statuses = Atom.make<ReadonlyMap<object, LiveStatus<unknown>>>(new Map());
|
|
9
13
|
const current = Atom.map(
|
|
10
14
|
statuses,
|
|
@@ -12,7 +16,7 @@ export function clientConnection(factory: Atom.RuntimeFactory, publish: (status:
|
|
|
12
16
|
[...values.values()].some(({ connection }) => connection === "connecting" || connection === "reconnecting") ? "reconnecting" : "live",
|
|
13
17
|
);
|
|
14
18
|
const runtime = factory(Layer.empty);
|
|
15
|
-
const
|
|
19
|
+
const debounced = Atom.make((get): ConnectionStatus => {
|
|
16
20
|
const context = AsyncResult.value(get(runtime));
|
|
17
21
|
if (Option.isNone(context)) {
|
|
18
22
|
return "live";
|
|
@@ -33,5 +37,20 @@ export function clientConnection(factory: Atom.RuntimeFactory, publish: (status:
|
|
|
33
37
|
get.addFinalizer(cancel);
|
|
34
38
|
return "live";
|
|
35
39
|
});
|
|
40
|
+
const status = Atom.make((get): ConnectionStatus => {
|
|
41
|
+
get.mount(debounced);
|
|
42
|
+
const context = AsyncResult.value(get(runtime));
|
|
43
|
+
if (Option.isSome(context)) {
|
|
44
|
+
const cancel = Effect.runCallbackWith(context.value)(
|
|
45
|
+
activity.pipe(
|
|
46
|
+
Stream.map((state) => state.connectionStatus),
|
|
47
|
+
Stream.changes,
|
|
48
|
+
Stream.runForEach((value) => Effect.sync(() => get.setSelf(value))),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
get.addFinalizer(cancel);
|
|
52
|
+
}
|
|
53
|
+
return Effect.runSync(activity.current).connectionStatus;
|
|
54
|
+
});
|
|
36
55
|
return { status, statuses };
|
|
37
56
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Deferred, Effect } from "effect";
|
|
2
|
+
import { RpcMessage, RpcSerialization } from "effect/rpc";
|
|
3
|
+
import * as Socket from "effect/socket/Socket";
|
|
4
|
+
import { ConnectionReadiness } from "#connectionReadiness.ts";
|
|
5
|
+
import type { ResumeOptions } from "#resume.ts";
|
|
6
|
+
import { resumeSources } from "#resumeSources.ts";
|
|
7
|
+
|
|
8
|
+
export const resumeSocket = Effect.fnUntraced(function* (options: ResumeOptions) {
|
|
9
|
+
const socket = yield* Socket.Socket;
|
|
10
|
+
const connection = yield* ConnectionReadiness;
|
|
11
|
+
const serialization = yield* RpcSerialization.RpcSerialization;
|
|
12
|
+
const writer = yield* socket.writer;
|
|
13
|
+
return Socket.make({
|
|
14
|
+
reader: Effect.gen(function* () {
|
|
15
|
+
const reader = yield* socket.reader;
|
|
16
|
+
const scope = yield* Effect.scope;
|
|
17
|
+
const context = yield* Effect.context();
|
|
18
|
+
const parser = serialization.makeUnsafe();
|
|
19
|
+
const failed = yield* Deferred.make<never, Socket.SocketError>();
|
|
20
|
+
let pending: Deferred.Deferred<void> | undefined;
|
|
21
|
+
const probe = Effect.suspend(() => {
|
|
22
|
+
if (pending !== undefined) {
|
|
23
|
+
return Effect.void;
|
|
24
|
+
}
|
|
25
|
+
const pong = Deferred.makeUnsafe<void>();
|
|
26
|
+
pending = pong;
|
|
27
|
+
return connection.close.pipe(
|
|
28
|
+
Effect.andThen(
|
|
29
|
+
Effect.suspend(() => {
|
|
30
|
+
const ping = parser.encode(RpcMessage.constPing);
|
|
31
|
+
return ping === undefined ? Effect.void : writer.write(ping);
|
|
32
|
+
}),
|
|
33
|
+
),
|
|
34
|
+
Effect.andThen(Deferred.await(pong)),
|
|
35
|
+
Effect.timeoutOrElse({
|
|
36
|
+
duration: "2500 millis",
|
|
37
|
+
orElse: () => Effect.fail(new Socket.SocketError({ reason: new Socket.SocketReadError({ cause: "Resume probe timed out" }) })),
|
|
38
|
+
}),
|
|
39
|
+
Effect.andThen(connection.open),
|
|
40
|
+
Effect.catch((error) => Deferred.fail(failed, error)),
|
|
41
|
+
Effect.ensuring(
|
|
42
|
+
Effect.sync(() => {
|
|
43
|
+
pending = undefined;
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
for (const source of resumeSources(options)) {
|
|
49
|
+
yield* Effect.acquireRelease(
|
|
50
|
+
Effect.sync(() =>
|
|
51
|
+
source(() => {
|
|
52
|
+
Effect.runForkWith(context)(Effect.forkIn(probe, scope));
|
|
53
|
+
}),
|
|
54
|
+
),
|
|
55
|
+
(stop) => Effect.sync(stop),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
function observe(frames: ReadonlyArray<Uint8Array | string>) {
|
|
59
|
+
for (const frame of frames) {
|
|
60
|
+
const responses = parser.decode(frame);
|
|
61
|
+
if (pending !== undefined && Array.isArray(responses) && responses.some((response) => response._tag === "Pong")) {
|
|
62
|
+
Deferred.doneUnsafe(pending, Effect.void);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const pull = reader.pull.pipe(
|
|
67
|
+
Effect.tap((frames) =>
|
|
68
|
+
Effect.try({
|
|
69
|
+
catch: (cause) => new Socket.SocketError({ reason: new Socket.SocketReadError({ cause }) }),
|
|
70
|
+
try: () => observe(frames),
|
|
71
|
+
}),
|
|
72
|
+
),
|
|
73
|
+
Effect.raceFirst(Deferred.await(failed)),
|
|
74
|
+
);
|
|
75
|
+
return { ...reader, pull };
|
|
76
|
+
}),
|
|
77
|
+
writer: Effect.succeed(writer),
|
|
78
|
+
});
|
|
79
|
+
});
|
package/src/automaticLive.ts
CHANGED
|
@@ -6,17 +6,17 @@ import type * as AtomRpc from "effect/reactivity/AtomRpc";
|
|
|
6
6
|
import type { Rpc, RpcSchema } from "effect/rpc";
|
|
7
7
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
8
8
|
import type { BindingOwner } from "#adapters/bindingOwner.ts";
|
|
9
|
-
import { aggregateLiveStatus } from "#
|
|
10
|
-
import { automaticQuery } from "#
|
|
11
|
-
import { clientActivities } from "#
|
|
12
|
-
import { queryDelivery } from "#internal/queryDelivery.ts";
|
|
13
|
-
import { localQueryKeys, queryHint } from "#internal/queryHints.ts";
|
|
14
|
-
import { queryProgress } from "#internal/querySignals.ts";
|
|
15
|
-
import { socketIdentity } from "#internal/rpcClient.ts";
|
|
9
|
+
import { aggregateLiveStatus } from "#aggregateLiveStatus.ts";
|
|
10
|
+
import { automaticQuery } from "#automaticQuery.ts";
|
|
11
|
+
import { clientActivities } from "#clientActivities.ts";
|
|
16
12
|
import { type LiveStatus, live } from "#live.ts";
|
|
13
|
+
import { queryDelivery } from "#queryDelivery.ts";
|
|
14
|
+
import { localQueryKeys, queryHint } from "#queryHints.ts";
|
|
15
|
+
import { queryProgress } from "#queryProgress.ts";
|
|
17
16
|
import { querySignals, shareQuerySignals } from "#querySignals.ts";
|
|
18
17
|
import type { QueryUpdate } from "#queryUpdate.ts";
|
|
19
18
|
import { type ResumeSource, type ResumeWindow, resumeSignal } from "#resume.ts";
|
|
19
|
+
import { socketIdentity } from "#rpcClient.ts";
|
|
20
20
|
import type { QueryReference } from "#serverMetadata.ts";
|
|
21
21
|
|
|
22
22
|
declare const window: ResumeWindow | undefined;
|
|
@@ -2,11 +2,11 @@ import { Cause, type Duration, Option, Predicate } from "effect";
|
|
|
2
2
|
import * as AsyncResult from "effect/reactivity/AsyncResult";
|
|
3
3
|
import * as Atom from "effect/reactivity/Atom";
|
|
4
4
|
import type { LiveBound, LiveConnection } from "#automaticLive.ts";
|
|
5
|
-
import { queryFailure } from "#internal/queryFailure.ts";
|
|
6
|
-
import { queryResult } from "#internal/queryResult.ts";
|
|
7
|
-
import { recordCompletion, recordSubscription } from "#internal/querySignals.ts";
|
|
8
5
|
import type { LiveStatus } from "#live.ts";
|
|
9
6
|
import { queryCoalesceWindow } from "#queryCoalesceWindow.ts";
|
|
7
|
+
import { queryFailure } from "#queryFailure.ts";
|
|
8
|
+
import { recordCompletion, recordSubscription } from "#queryProgress.ts";
|
|
9
|
+
import { queryResult } from "#queryResult.ts";
|
|
10
10
|
import type { QuerySignals } from "#querySignals.ts";
|
|
11
11
|
|
|
12
12
|
interface GateOptions<A, E> {
|
package/src/bind.ts
CHANGED
|
@@ -9,13 +9,13 @@ import type { Rpc, RpcGroup } from "effect/rpc";
|
|
|
9
9
|
import type { RpcClientError } from "effect/rpc/RpcClientError";
|
|
10
10
|
import { bindingOwner } from "#adapters/bindingOwner.ts";
|
|
11
11
|
import { automaticLive, type LiveBound, LiveConnection } from "#automaticLive.ts";
|
|
12
|
+
import { clientOperations } from "#clientOperations.ts";
|
|
12
13
|
import type { ClientOptions, MadeClient } from "#clientOptions.ts";
|
|
13
14
|
import type { Contract, Declared } from "#contract.ts";
|
|
14
|
-
import { clientOperations } from "#internal/clientOperations.ts";
|
|
15
|
-
import { type RpcSource, rpcClient } from "#internal/rpcClient.ts";
|
|
16
15
|
import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
17
16
|
import type { Tag } from "#operationRpc.ts";
|
|
18
17
|
import type { ResumeSource, ResumeWindow } from "#resume.ts";
|
|
18
|
+
import { type RpcSource, rpcClient } from "#rpcClient.ts";
|
|
19
19
|
|
|
20
20
|
export type Failure<R extends Rpc.Any> =
|
|
21
21
|
R extends Rpc.Rpc<infer _Tag, infer _Payload, infer _Success, infer _Error, infer TMiddleware, infer _Requires>
|
|
@@ -10,8 +10,8 @@ type ActivityTracker = ReturnType<typeof makeActivity>;
|
|
|
10
10
|
export const clientActivities = new WeakMap<object, ActivityTracker>();
|
|
11
11
|
|
|
12
12
|
export function makeActivity(factory: Atom.RuntimeFactory) {
|
|
13
|
-
const { activity, change, setConnection } = activityState();
|
|
14
|
-
const connection = clientConnection(factory, setConnection);
|
|
13
|
+
const { activity, change, hold, setConnection } = activityState();
|
|
14
|
+
const connection = clientConnection(factory, setConnection, activity);
|
|
15
15
|
function begin(key: "rpcCalls" | "liveInvalidations") {
|
|
16
16
|
change(key, 1);
|
|
17
17
|
return () => change(key, -1);
|
|
@@ -65,6 +65,14 @@ export function makeActivity(factory: Atom.RuntimeFactory) {
|
|
|
65
65
|
return {
|
|
66
66
|
activity: Object.assign(activity, { connectionStatus: connection.status }),
|
|
67
67
|
hint: () => change("liveHints", 1),
|
|
68
|
+
hold: <A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
69
|
+
track(
|
|
70
|
+
Effect.acquireUseRelease(
|
|
71
|
+
Effect.sync(hold),
|
|
72
|
+
() => effect,
|
|
73
|
+
(end) => Effect.sync(end),
|
|
74
|
+
),
|
|
75
|
+
),
|
|
68
76
|
queued: () => begin("liveInvalidations"),
|
|
69
77
|
statuses: connection.statuses,
|
|
70
78
|
track,
|
package/src/clientActivity.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Stream } from "effect";
|
|
2
2
|
import type * as Atom from "effect/reactivity/Atom";
|
|
3
3
|
|
|
4
|
-
export type ConnectionStatus = "live" | "reconnecting";
|
|
4
|
+
export type ConnectionStatus = "live" | "reconnecting" | "waiting-for-connection";
|
|
5
5
|
|
|
6
6
|
export interface ClientActivityState {
|
|
7
7
|
readonly connectionStatus: ConnectionStatus;
|
|
@@ -9,11 +9,12 @@ import type { BindingOwner } from "#adapters/bindingOwner.ts";
|
|
|
9
9
|
import { clientId } from "#adapters/clientId.ts";
|
|
10
10
|
import type { automaticLive } from "#automaticLive.ts";
|
|
11
11
|
import type { QueryOptions } from "#bind.ts";
|
|
12
|
+
import { clientActivities } from "#clientActivities.ts";
|
|
12
13
|
import { clientInvalidationKeys, clientReadKeys } from "#clientKeys.ts";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import { queryReactivity } from "#internal/queryReactivity.ts";
|
|
14
|
+
import { commandPayload } from "#commandPayload.ts";
|
|
15
|
+
import { waitForConnection } from "#connectionReadiness.ts";
|
|
16
16
|
import type { CommandShape, QueryShape } from "#operation.ts";
|
|
17
|
+
import { queryReactivity } from "#queryReactivity.ts";
|
|
17
18
|
import { shareQuerySignals } from "#querySignals.ts";
|
|
18
19
|
|
|
19
20
|
type ErasedClient = AtomRpc.AtomRpcClient<unknown, string, Rpc.Rpc<string, Schema.Top, Schema.Top, Schema.Top>>;
|
|
@@ -79,6 +80,7 @@ function boundCommand(service: ErasedClient, tag: string, command: CommandShape,
|
|
|
79
80
|
service,
|
|
80
81
|
service.use((client) =>
|
|
81
82
|
commandPayload(command, payload).pipe(
|
|
83
|
+
Effect.tap(() => waitForConnection(client)),
|
|
82
84
|
Effect.flatMap((validated) => client(tag, validated)),
|
|
83
85
|
Effect.tap((result) => invalidate(payload, result)),
|
|
84
86
|
),
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Effect, Option, Ref } from "effect";
|
|
2
|
+
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
import { CommandResultKeys } from "#CommandResultKeys.ts";
|
|
4
|
+
|
|
5
|
+
export const commandResult = Effect.fnUntraced(function* <A>(value: {
|
|
6
|
+
readonly result: A;
|
|
7
|
+
readonly invalidates: readonly Key[];
|
|
8
|
+
}): Effect.fn.Return<A> {
|
|
9
|
+
const keys = yield* Effect.serviceOption(CommandResultKeys);
|
|
10
|
+
if (Option.isNone(keys)) {
|
|
11
|
+
return yield* Effect.die("commandResult requires the command guard");
|
|
12
|
+
}
|
|
13
|
+
yield* Ref.update(keys.value, (previous) => [...previous, ...value.invalidates]);
|
|
14
|
+
return value.result;
|
|
15
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Digest } from "effect/crypto";
|
|
3
3
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
4
|
-
import { changedHint } from "#internal/queryHints.ts";
|
|
5
4
|
import type { LiveHint } from "#live.ts";
|
|
5
|
+
import { changedHint } from "#queryHints.ts";
|
|
6
6
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
7
7
|
import type { QueryResult, QueryUnchanged, QueryUpdate } from "#queryUpdate.ts";
|
|
8
8
|
import type { QueryRequest } from "#serverMetadata.ts";
|
|
@@ -36,9 +36,8 @@ export function compareQueries<E, R>(subscription: QuerySubscription<unknown, un
|
|
|
36
36
|
}
|
|
37
37
|
const value = yield* read(request);
|
|
38
38
|
const encoded = yield* Schema.encodeUnknownEffect(Schema.toCodecJson(request.query.success))(value).pipe(Effect.orDie);
|
|
39
|
-
const
|
|
40
|
-
const
|
|
41
|
-
const hash = Hex.encode(digest);
|
|
39
|
+
const digest = yield* Digest.Digest;
|
|
40
|
+
const hash = yield* digest.digestHex(Digest.sha256, new TextEncoder().encode(JSON.stringify(encoded)));
|
|
42
41
|
if (hash === hashes.get(index)) {
|
|
43
42
|
return { _tag: "Unchanged", queryIndex: index } satisfies QueryUnchanged;
|
|
44
43
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Context, Effect, Layer, Option } from "effect";
|
|
2
|
+
import * as Atom from "effect/reactivity/Atom";
|
|
3
|
+
import { RpcClient } from "effect/rpc";
|
|
4
|
+
import { ConnectionReadiness, connectionReadiness } from "./connectionReadiness.ts";
|
|
5
|
+
|
|
6
|
+
export const protocolConnections = new WeakMap<RpcClient.Protocol["Service"], Effect.Success<typeof connectionReadiness>>();
|
|
7
|
+
|
|
8
|
+
export const connectionProtocol = Atom.family((protocol: Layer.Layer<RpcClient.Protocol, never, ConnectionReadiness>) =>
|
|
9
|
+
Layer.unwrap(
|
|
10
|
+
Effect.gen(function* () {
|
|
11
|
+
const connection = yield* connectionReadiness;
|
|
12
|
+
const hooks = yield* Effect.serviceOption(RpcClient.ConnectionHooks);
|
|
13
|
+
return protocol.pipe(
|
|
14
|
+
Layer.provide(
|
|
15
|
+
Layer.merge(
|
|
16
|
+
Layer.succeed(ConnectionReadiness, connection),
|
|
17
|
+
Layer.succeed(RpcClient.ConnectionHooks, {
|
|
18
|
+
onConnect: connection.open.pipe(Effect.andThen(Option.isSome(hooks) ? hooks.value.onConnect : Effect.void)),
|
|
19
|
+
onDisconnect: connection.close.pipe(Effect.andThen(Option.isSome(hooks) ? hooks.value.onDisconnect : Effect.void)),
|
|
20
|
+
}),
|
|
21
|
+
),
|
|
22
|
+
),
|
|
23
|
+
Layer.tap((context) => Effect.sync(() => protocolConnections.set(Context.get(context, RpcClient.Protocol), connection))),
|
|
24
|
+
);
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Clock, Context, Effect, Latch } from "effect";
|
|
2
|
+
import { RpcClientError } from "effect/rpc/RpcClientError";
|
|
3
|
+
import { SocketOpenError } from "effect/socket/Socket";
|
|
4
|
+
|
|
5
|
+
export const connectionReadiness = Effect.gen(function* () {
|
|
6
|
+
const clock = yield* Clock.Clock;
|
|
7
|
+
const ready = Latch.makeUnsafe(true);
|
|
8
|
+
return {
|
|
9
|
+
close: Effect.asVoid(ready.close),
|
|
10
|
+
isReady: () => ready.isOpen(),
|
|
11
|
+
open: Effect.asVoid(ready.open),
|
|
12
|
+
wait: Effect.suspend(() =>
|
|
13
|
+
ready.await.pipe(
|
|
14
|
+
Effect.timeoutOrElse({
|
|
15
|
+
duration: "10 seconds",
|
|
16
|
+
orElse: () => Effect.fail(new RpcClientError({ reason: new SocketOpenError({ cause: "Waiting for a live connection", kind: "Timeout" }) })),
|
|
17
|
+
}),
|
|
18
|
+
Effect.provideService(Clock.Clock, clock),
|
|
19
|
+
),
|
|
20
|
+
),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export class ConnectionReadiness extends Context.Service<ConnectionReadiness, Effect.Success<typeof connectionReadiness>>()(
|
|
25
|
+
"@shivaedev/contract/ConnectionReadiness",
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
export const commandConnections = new WeakMap<object, Effect.Effect<void, RpcClientError>>();
|
|
29
|
+
|
|
30
|
+
export function waitForConnection(client: object) {
|
|
31
|
+
return commandConnections.get(client) ?? Effect.void;
|
|
32
|
+
}
|
package/src/contract.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { Rpc, RpcGroup, type RpcMiddleware } from "effect/rpc";
|
|
3
|
-
import { declarationError, type Unique } from "#
|
|
4
|
-
import { subjectMiddleware } from "#internal/subjectMiddleware.ts";
|
|
3
|
+
import { declarationError, type Unique } from "#declarationError.ts";
|
|
5
4
|
import type { CommandShape, QueryShape, StreamShape } from "#operation.ts";
|
|
6
5
|
import type { OperationRpc } from "#operationRpc.ts";
|
|
7
6
|
import { ReadPolicyGuard } from "#ReadPolicyGuard.ts";
|
|
8
7
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
9
8
|
import { changesRpc, KeyScope, operationAnnotations } from "#serverMetadata.ts";
|
|
10
9
|
import type { SubjectDeclaration, WithSubject } from "#subject.ts";
|
|
10
|
+
import { subjectMiddleware } from "#subjectMiddleware.ts";
|
|
11
11
|
|
|
12
12
|
export type QueryServices<TQuery> = TQuery extends QueryShape<unknown, infer R> ? R : never;
|
|
13
13
|
|
package/src/live.ts
CHANGED
|
@@ -4,13 +4,13 @@ import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
|
4
4
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
5
5
|
import { Key } from "@shivaedev/changes/keys.ts";
|
|
6
6
|
import { clientInvalidationKeys, clientReadKeys, type KeyContext } from "#clientKeys.ts";
|
|
7
|
-
import { liveAttempt } from "#
|
|
8
|
-
import { invalidateLive } from "#
|
|
9
|
-
import { livePending } from "#
|
|
10
|
-
import { liveRetry } from "#
|
|
11
|
-
import { retryOnChange } from "#internal/retryOnChange.ts";
|
|
7
|
+
import { liveAttempt } from "#liveAttempt.ts";
|
|
8
|
+
import { invalidateLive } from "#liveInvalidation.ts";
|
|
9
|
+
import { livePending } from "#livePending.ts";
|
|
10
|
+
import { liveRetry } from "#liveRetry.ts";
|
|
12
11
|
import type { SubscriptionHint } from "#queryUpdate.ts";
|
|
13
12
|
import type { QueryReadDenied } from "#readPolicyErrors.ts";
|
|
13
|
+
import { retryOnChange } from "#retryOnChange.ts";
|
|
14
14
|
|
|
15
15
|
export const LiveHint = Schema.Union([
|
|
16
16
|
Schema.Struct({ _tag: Schema.Literal("Changed"), keys: Schema.Array(Key), queryIndexes: Schema.optional(Schema.Array(Schema.Number)) }),
|
package/src/makeLiveServer.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Effect, Queue, Random, Scheduler, Stream } from "effect";
|
|
2
2
|
import * as Reactivity from "effect/reactivity/Reactivity";
|
|
3
3
|
import { type Key, readKeys } from "@shivaedev/changes/keys.ts";
|
|
4
|
-
import { compareQueries } from "#
|
|
5
|
-
import { liveHintQueue } from "#internal/liveHintQueue.ts";
|
|
4
|
+
import { compareQueries } from "#compareQueries.ts";
|
|
6
5
|
import type { LiveHint } from "#live.ts";
|
|
6
|
+
import { liveHintQueue } from "#liveHintQueue.ts";
|
|
7
7
|
import type { QueryRerun, QuerySubscription } from "#querySubscription.ts";
|
|
8
8
|
import type { QueryUpdate, SubscriptionHint } from "#queryUpdate.ts";
|
|
9
9
|
import { QueryReadDenied } from "#readPolicyErrors.ts";
|
package/src/operation.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Option, Schema } from "effect";
|
|
2
2
|
import type { Key } from "@shivaedev/changes/keys.ts";
|
|
3
3
|
import type { Bivariant } from "@shivaedev/types/Bivariant.ts";
|
|
4
|
-
import { type Declaration, type Loose, operation, type QueryDeclaration } from "#
|
|
4
|
+
import { type Declaration, type Loose, operation, type QueryDeclaration } from "#operationDeclaration.ts";
|
|
5
5
|
import type { QueryServerReads } from "#QueryServerReads.ts";
|
|
6
6
|
import type { QueryReadPolicy, Viewer } from "#readPolicy.ts";
|
|
7
7
|
import type { Reject, RejectedBy, RejectionSpecs, Rejections, RejectionUnion } from "#rejection.ts";
|