effect 4.0.0-beta.44 → 4.0.0-beta.46
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/dist/Equal.d.ts.map +1 -1
- package/dist/Equal.js +16 -0
- package/dist/Equal.js.map +1 -1
- package/dist/Hash.js +1 -1
- package/dist/Hash.js.map +1 -1
- package/dist/Semaphore.d.ts +1 -1
- package/dist/Semaphore.d.ts.map +1 -1
- package/dist/Semaphore.js +1 -3
- package/dist/Semaphore.js.map +1 -1
- package/dist/unstable/ai/McpServer.d.ts.map +1 -1
- package/dist/unstable/ai/McpServer.js +24 -21
- package/dist/unstable/ai/McpServer.js.map +1 -1
- package/dist/unstable/eventlog/Event.d.ts +0 -6
- package/dist/unstable/eventlog/Event.d.ts.map +1 -1
- package/dist/unstable/eventlog/Event.js +0 -5
- package/dist/unstable/eventlog/Event.js.map +1 -1
- package/dist/unstable/eventlog/EventGroup.d.ts +0 -2
- package/dist/unstable/eventlog/EventGroup.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventGroup.js +0 -2
- package/dist/unstable/eventlog/EventGroup.js.map +1 -1
- package/dist/unstable/eventlog/EventJournal.d.ts +22 -5
- package/dist/unstable/eventlog/EventJournal.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventJournal.js +126 -67
- package/dist/unstable/eventlog/EventJournal.js.map +1 -1
- package/dist/unstable/eventlog/EventLog.d.ts +88 -34
- package/dist/unstable/eventlog/EventLog.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLog.js +215 -141
- package/dist/unstable/eventlog/EventLog.js.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.d.ts +9 -7
- package/dist/unstable/eventlog/EventLogEncryption.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogEncryption.js +13 -15
- package/dist/unstable/eventlog/EventLogEncryption.js.map +1 -1
- package/dist/unstable/eventlog/EventLogMessage.d.ts +228 -0
- package/dist/unstable/eventlog/EventLogMessage.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogMessage.js +214 -0
- package/dist/unstable/eventlog/EventLogMessage.js.map +1 -0
- package/dist/unstable/eventlog/EventLogRemote.d.ts +109 -194
- package/dist/unstable/eventlog/EventLogRemote.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogRemote.js +165 -320
- package/dist/unstable/eventlog/EventLogRemote.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServer.d.ts +25 -47
- package/dist/unstable/eventlog/EventLogServer.d.ts.map +1 -1
- package/dist/unstable/eventlog/EventLogServer.js +127 -198
- package/dist/unstable/eventlog/EventLogServer.js.map +1 -1
- package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts +60 -0
- package/dist/unstable/eventlog/EventLogServerEncrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogServerEncrypted.js +166 -0
- package/dist/unstable/eventlog/EventLogServerEncrypted.js.map +1 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts +183 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js +461 -0
- package/dist/unstable/eventlog/EventLogServerUnencrypted.js.map +1 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.d.ts +117 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.d.ts.map +1 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.js +284 -0
- package/dist/unstable/eventlog/EventLogSessionAuth.js.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogJournal.d.ts → SqlEventJournal.d.ts} +2 -2
- package/dist/unstable/eventlog/SqlEventJournal.d.ts.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogJournal.js → SqlEventJournal.js} +20 -14
- package/dist/unstable/eventlog/SqlEventJournal.js.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogServer.d.ts → SqlEventLogServerEncrypted.d.ts} +5 -5
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/{SqlEventLogServer.js → SqlEventLogServerEncrypted.js} +65 -24
- package/dist/unstable/eventlog/SqlEventLogServerEncrypted.js.map +1 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts +25 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.d.ts.map +1 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js +354 -0
- package/dist/unstable/eventlog/SqlEventLogServerUnencrypted.js.map +1 -0
- package/dist/unstable/eventlog/index.d.ts +22 -2
- package/dist/unstable/eventlog/index.d.ts.map +1 -1
- package/dist/unstable/eventlog/index.js +22 -2
- package/dist/unstable/eventlog/index.js.map +1 -1
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.d.ts +2 -0
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.d.ts.map +1 -0
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js +89 -0
- package/dist/unstable/eventlog/internal/identityRootSecretDerivation.js.map +1 -0
- package/dist/unstable/reactivity/AtomHttpApi.d.ts +1 -2
- package/dist/unstable/reactivity/AtomHttpApi.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomHttpApi.js +2 -2
- package/dist/unstable/reactivity/AtomHttpApi.js.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.d.ts +1 -2
- package/dist/unstable/reactivity/AtomRpc.d.ts.map +1 -1
- package/dist/unstable/reactivity/AtomRpc.js +3 -3
- package/dist/unstable/reactivity/AtomRpc.js.map +1 -1
- package/dist/unstable/rpc/Rpc.d.ts +25 -4
- package/dist/unstable/rpc/Rpc.d.ts.map +1 -1
- package/dist/unstable/rpc/Rpc.js +26 -0
- package/dist/unstable/rpc/Rpc.js.map +1 -1
- package/dist/unstable/rpc/RpcClient.d.ts +3 -13
- package/dist/unstable/rpc/RpcClient.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcClient.js +47 -23
- package/dist/unstable/rpc/RpcClient.js.map +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts +1 -1
- package/dist/unstable/rpc/RpcGroup.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcMiddleware.d.ts +2 -2
- package/dist/unstable/rpc/RpcMiddleware.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.d.ts.map +1 -1
- package/dist/unstable/rpc/RpcServer.js +3 -2
- package/dist/unstable/rpc/RpcServer.js.map +1 -1
- package/dist/unstable/rpc/Utils.d.ts +6 -0
- package/dist/unstable/rpc/Utils.d.ts.map +1 -1
- package/dist/unstable/rpc/Utils.js +44 -0
- package/dist/unstable/rpc/Utils.js.map +1 -1
- package/dist/unstable/schema/Model.d.ts +2 -2
- package/dist/unstable/schema/Model.d.ts.map +1 -1
- package/dist/unstable/schema/Model.js +2 -4
- package/dist/unstable/schema/Model.js.map +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts +1 -1
- package/dist/unstable/schema/VariantSchema.d.ts.map +1 -1
- package/dist/unstable/schema/VariantSchema.js +1 -12
- package/dist/unstable/schema/VariantSchema.js.map +1 -1
- package/dist/unstable/workers/Transferable.d.ts +1 -1
- package/dist/unstable/workers/Transferable.d.ts.map +1 -1
- package/dist/unstable/workers/Transferable.js +1 -1
- package/dist/unstable/workers/Transferable.js.map +1 -1
- package/package.json +1 -1
- package/src/Equal.ts +17 -0
- package/src/Hash.ts +2 -2
- package/src/Semaphore.ts +2 -4
- package/src/unstable/ai/McpServer.ts +24 -22
- package/src/unstable/eventlog/Event.ts +0 -8
- package/src/unstable/eventlog/EventGroup.ts +0 -4
- package/src/unstable/eventlog/EventJournal.ts +144 -76
- package/src/unstable/eventlog/EventLog.ts +342 -221
- package/src/unstable/eventlog/EventLogEncryption.ts +16 -30
- package/src/unstable/eventlog/EventLogMessage.ts +277 -0
- package/src/unstable/eventlog/EventLogRemote.ts +261 -408
- package/src/unstable/eventlog/EventLogServer.ts +182 -274
- package/src/unstable/eventlog/EventLogServerEncrypted.ts +206 -0
- package/src/unstable/eventlog/EventLogServerUnencrypted.ts +749 -0
- package/src/unstable/eventlog/EventLogSessionAuth.ts +437 -0
- package/src/unstable/eventlog/{SqlEventLogJournal.ts → SqlEventJournal.ts} +26 -18
- package/src/unstable/eventlog/{SqlEventLogServer.ts → SqlEventLogServerEncrypted.ts} +102 -40
- package/src/unstable/eventlog/SqlEventLogServerUnencrypted.ts +500 -0
- package/src/unstable/eventlog/index.ts +27 -2
- package/src/unstable/eventlog/internal/identityRootSecretDerivation.ts +153 -0
- package/src/unstable/reactivity/AtomHttpApi.ts +23 -8
- package/src/unstable/reactivity/AtomRpc.ts +16 -5
- package/src/unstable/rpc/Rpc.ts +42 -4
- package/src/unstable/rpc/RpcClient.ts +59 -24
- package/src/unstable/rpc/RpcGroup.ts +1 -1
- package/src/unstable/rpc/RpcMiddleware.ts +2 -2
- package/src/unstable/rpc/RpcServer.ts +5 -3
- package/src/unstable/rpc/Utils.ts +59 -0
- package/src/unstable/schema/Model.ts +4 -6
- package/src/unstable/schema/VariantSchema.ts +4 -17
- package/src/unstable/workers/Transferable.ts +9 -11
- package/dist/unstable/eventlog/SqlEventLogJournal.d.ts.map +0 -1
- package/dist/unstable/eventlog/SqlEventLogJournal.js.map +0 -1
- package/dist/unstable/eventlog/SqlEventLogServer.d.ts.map +0 -1
- package/dist/unstable/eventlog/SqlEventLogServer.js.map +0 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 4.0.0
|
|
3
|
+
*/
|
|
4
|
+
import * as Uuid from "uuid"
|
|
5
|
+
import * as Arr from "../../Array.ts"
|
|
6
|
+
import * as Context from "../../Context.ts"
|
|
7
|
+
import * as Effect from "../../Effect.ts"
|
|
8
|
+
import * as Layer from "../../Layer.ts"
|
|
9
|
+
import * as PubSub from "../../PubSub.ts"
|
|
10
|
+
import * as RcMap from "../../RcMap.ts"
|
|
11
|
+
import * as Schema from "../../Schema.ts"
|
|
12
|
+
import type * as Scope from "../../Scope.ts"
|
|
13
|
+
import * as Stream from "../../Stream.ts"
|
|
14
|
+
import * as RpcServer from "../rpc/RpcServer.ts"
|
|
15
|
+
import * as Transferable from "../workers/Transferable.ts"
|
|
16
|
+
import { EntryId, makeRemoteIdUnsafe, type RemoteId } from "./EventJournal.ts"
|
|
17
|
+
import type { EncryptedRemoteEntry } from "./EventLogEncryption.ts"
|
|
18
|
+
import { ChangesRpc, EventLogProtocolError, EventLogRemoteRpcs, type StoreId, WriteEntries } from "./EventLogMessage.ts"
|
|
19
|
+
import * as EventLogServer from "./EventLogServer.ts"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @since 4.0.0
|
|
23
|
+
* @category Layers
|
|
24
|
+
*/
|
|
25
|
+
export const layerRpcHandlers = Layer.unwrap(Effect.gen(function*() {
|
|
26
|
+
const storage = yield* Storage
|
|
27
|
+
const remoteId = yield* storage.getId
|
|
28
|
+
|
|
29
|
+
return EventLogServer.layerRpcHandlers({
|
|
30
|
+
remoteId,
|
|
31
|
+
getOrCreateSessionAuthBinding: (publicKey, signingPublicKey) =>
|
|
32
|
+
storage.getOrCreateSessionAuthBinding(publicKey, signingPublicKey),
|
|
33
|
+
onWrite: Effect.fnUntraced(function*(data) {
|
|
34
|
+
const request = yield* WriteEntries.decode(data).pipe(
|
|
35
|
+
Effect.mapError((_) =>
|
|
36
|
+
new EventLogProtocolError({
|
|
37
|
+
requestTag: "WriteEntries",
|
|
38
|
+
publicKey: undefined,
|
|
39
|
+
code: "InternalServerError",
|
|
40
|
+
message: "Decoding failure"
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
if (request.encryptedEntries.length === 0) return
|
|
45
|
+
const entries = request.encryptedEntries.map(({ encryptedEntry, entryId }) =>
|
|
46
|
+
new PersistedEntry({
|
|
47
|
+
entryId,
|
|
48
|
+
iv: request.iv,
|
|
49
|
+
encryptedEntry
|
|
50
|
+
})
|
|
51
|
+
)
|
|
52
|
+
return yield* storage.write(request.publicKey, request.storeId, entries).pipe(
|
|
53
|
+
Effect.catchCause((_) =>
|
|
54
|
+
Effect.fail(
|
|
55
|
+
new EventLogProtocolError({
|
|
56
|
+
requestTag: "WriteEntries",
|
|
57
|
+
publicKey: request.publicKey,
|
|
58
|
+
code: "InternalServerError",
|
|
59
|
+
message: "Persistence failure"
|
|
60
|
+
})
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
)
|
|
64
|
+
}),
|
|
65
|
+
changes: ({ publicKey, storeId, startSequence }) =>
|
|
66
|
+
storage.changes(publicKey, storeId, startSequence).pipe(
|
|
67
|
+
Stream.mapArrayEffect((entries) => Effect.map(ChangesRpc.encodeEncrypted(entries), Arr.of))
|
|
68
|
+
)
|
|
69
|
+
})
|
|
70
|
+
}))
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @since 4.0.0
|
|
74
|
+
* @category Layers
|
|
75
|
+
*/
|
|
76
|
+
export const layer: Layer.Layer<never, never, RpcServer.Protocol | Storage> = RpcServer.layer(EventLogRemoteRpcs).pipe(
|
|
77
|
+
Layer.provide(layerRpcHandlers)
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @since 4.0.0
|
|
82
|
+
* @category storage
|
|
83
|
+
*/
|
|
84
|
+
export class PersistedEntry extends Schema.Class<PersistedEntry>(
|
|
85
|
+
"effect/eventlog/EventLogServerEncrypted/PersistedEntry"
|
|
86
|
+
)({
|
|
87
|
+
entryId: EntryId,
|
|
88
|
+
iv: Transferable.Uint8Array,
|
|
89
|
+
encryptedEntry: Transferable.Uint8Array
|
|
90
|
+
}) {
|
|
91
|
+
/**
|
|
92
|
+
* @since 4.0.0
|
|
93
|
+
*/
|
|
94
|
+
get entryIdString(): string {
|
|
95
|
+
return Uuid.stringify(this.entryId)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @since 4.0.0
|
|
101
|
+
* @category storage
|
|
102
|
+
*/
|
|
103
|
+
export class Storage extends Context.Service<Storage, {
|
|
104
|
+
readonly getId: Effect.Effect<RemoteId>
|
|
105
|
+
readonly getOrCreateSessionAuthBinding: (
|
|
106
|
+
publicKey: string,
|
|
107
|
+
signingPublicKey: Uint8Array<ArrayBuffer>
|
|
108
|
+
) => Effect.Effect<Uint8Array<ArrayBuffer>>
|
|
109
|
+
readonly write: (
|
|
110
|
+
publicKey: string,
|
|
111
|
+
storeId: StoreId,
|
|
112
|
+
entries: ReadonlyArray<PersistedEntry>
|
|
113
|
+
) => Effect.Effect<ReadonlyArray<EncryptedRemoteEntry>>
|
|
114
|
+
readonly changes: (
|
|
115
|
+
publicKey: string,
|
|
116
|
+
storeId: StoreId,
|
|
117
|
+
startSequence: number
|
|
118
|
+
) => Stream.Stream<EncryptedRemoteEntry>
|
|
119
|
+
}>()("effect/eventlog/EventLogServer/Storage") {}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @since 4.0.0
|
|
123
|
+
* @category storage
|
|
124
|
+
*/
|
|
125
|
+
export const makeStorageMemory: Effect.Effect<Storage["Service"], never, Scope.Scope> = Effect.gen(function*() {
|
|
126
|
+
const knownIds = new Map<string, Map<string, number>>()
|
|
127
|
+
const journals = new Map<string, Array<EncryptedRemoteEntry>>()
|
|
128
|
+
const sessionAuthBindings = new Map<string, Uint8Array<ArrayBuffer>>()
|
|
129
|
+
const remoteId = makeRemoteIdUnsafe()
|
|
130
|
+
const ensureKnownIds = (scopeKey: string): Map<string, number> => {
|
|
131
|
+
let storeKnownIds = knownIds.get(scopeKey)
|
|
132
|
+
if (storeKnownIds) return storeKnownIds
|
|
133
|
+
storeKnownIds = new Map<string, number>()
|
|
134
|
+
knownIds.set(scopeKey, storeKnownIds)
|
|
135
|
+
return storeKnownIds
|
|
136
|
+
}
|
|
137
|
+
const ensureJournal = (scopeKey: string) => {
|
|
138
|
+
let journal = journals.get(scopeKey)
|
|
139
|
+
if (journal) return journal
|
|
140
|
+
journal = []
|
|
141
|
+
journals.set(scopeKey, journal)
|
|
142
|
+
return journal
|
|
143
|
+
}
|
|
144
|
+
const pubsubs = yield* RcMap.make({
|
|
145
|
+
lookup: (_scopeKey: string) =>
|
|
146
|
+
Effect.acquireRelease(
|
|
147
|
+
PubSub.unbounded<EncryptedRemoteEntry>(),
|
|
148
|
+
PubSub.shutdown
|
|
149
|
+
),
|
|
150
|
+
idleTimeToLive: 60000
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
return Storage.of({
|
|
154
|
+
getId: Effect.succeed(remoteId),
|
|
155
|
+
getOrCreateSessionAuthBinding: (publicKey, signingPublicKey) =>
|
|
156
|
+
Effect.sync(() => {
|
|
157
|
+
let existing = sessionAuthBindings.get(publicKey)
|
|
158
|
+
if (existing) return existing
|
|
159
|
+
sessionAuthBindings.set(publicKey, signingPublicKey)
|
|
160
|
+
return signingPublicKey
|
|
161
|
+
}),
|
|
162
|
+
write: Effect.fnUntraced(function*(publicKey, storeId, entries) {
|
|
163
|
+
const scopeKey = makeEncryptedScopeKey({ publicKey, storeId })
|
|
164
|
+
const pubsub = yield* RcMap.get(pubsubs, scopeKey)
|
|
165
|
+
const storeKnownIds = ensureKnownIds(scopeKey)
|
|
166
|
+
const journal = ensureJournal(scopeKey)
|
|
167
|
+
const encryptedEntries: Array<EncryptedRemoteEntry> = []
|
|
168
|
+
for (const entry of entries) {
|
|
169
|
+
const idString = entry.entryIdString
|
|
170
|
+
if (storeKnownIds.has(idString)) continue
|
|
171
|
+
const encrypted: EncryptedRemoteEntry = {
|
|
172
|
+
sequence: journal.length,
|
|
173
|
+
entryId: entry.entryId,
|
|
174
|
+
iv: entry.iv,
|
|
175
|
+
encryptedEntry: entry.encryptedEntry
|
|
176
|
+
}
|
|
177
|
+
encryptedEntries.push(encrypted)
|
|
178
|
+
storeKnownIds.set(idString, encrypted.sequence)
|
|
179
|
+
journal.push(encrypted)
|
|
180
|
+
PubSub.publishUnsafe(pubsub, encrypted)
|
|
181
|
+
}
|
|
182
|
+
return encryptedEntries
|
|
183
|
+
}, Effect.scoped),
|
|
184
|
+
changes: Effect.fnUntraced(function*(publicKey, storeId, startSequence) {
|
|
185
|
+
const scopeKey = makeEncryptedScopeKey({ publicKey, storeId })
|
|
186
|
+
const pubsub = yield* RcMap.get(pubsubs, scopeKey)
|
|
187
|
+
const subscription = yield* PubSub.subscribe(pubsub)
|
|
188
|
+
return Stream.fromArray(ensureJournal(scopeKey).slice(startSequence)).pipe(
|
|
189
|
+
Stream.concat(Stream.fromSubscription(subscription))
|
|
190
|
+
)
|
|
191
|
+
}, Stream.unwrap)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @since 4.0.0
|
|
197
|
+
* @category storage
|
|
198
|
+
*/
|
|
199
|
+
export const layerStorageMemory: Layer.Layer<Storage> = Layer.effect(Storage)(makeStorageMemory)
|
|
200
|
+
|
|
201
|
+
const makeEncryptedScopeKey = ({ publicKey, storeId }: {
|
|
202
|
+
readonly publicKey: string
|
|
203
|
+
readonly storeId: StoreId
|
|
204
|
+
}): string => {
|
|
205
|
+
return `${publicKey}/${storeId}`
|
|
206
|
+
}
|