@effect-agent/storage-cloudflare 0.1.0-beta.76 → 0.1.0-beta.78

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/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@effect-agent/storage-cloudflare","version":"0.1.0-beta.76","dependencies":{"@effect-agent/core":"0.1.0-beta.76","@effect-agent/thread":"0.1.0-beta.76","@effect/platform-browser":"4.0.0-rc.112","@effect/sql-sqlite-do":"4.0.0-rc.112"},"devDependencies":{"@cloudflare/vitest-pool-workers":"0.21.3","@cloudflare/workers-types":"5.20260825.1","@effect-agent/testing":"0.1.0-beta.76","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","typescript":"7.0.2","vite-plus":"0.3.0","vitest":"4.1.11"},"peerDependencies":{"effect":"^4.0.0-rc.112"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./DoMemoryStore":{"types":"./dist/DoMemoryStore.d.mts","default":"./dist/DoMemoryStore.mjs"},"./DoScheduleStore":{"types":"./dist/DoScheduleStore.d.mts","default":"./dist/DoScheduleStore.mjs"},"./DoStorageConfig":{"types":"./dist/DoStorageConfig.d.mts","default":"./dist/DoStorageConfig.mjs"},"./DoStorageError":{"types":"./dist/DoStorageError.d.mts","default":"./dist/DoStorageError.mjs"},"./DoStorageFailpoint":{"types":"./dist/DoStorageFailpoint.d.mts","default":"./dist/DoStorageFailpoint.mjs"},"./DoStorageVersion":{"types":"./dist/DoStorageVersion.d.mts","default":"./dist/DoStorageVersion.mjs"},"./DoSubmissionLedger":{"types":"./dist/DoSubmissionLedger.d.mts","default":"./dist/DoSubmissionLedger.mjs"},"./DoSubscriptionStore":{"types":"./dist/DoSubscriptionStore.d.mts","default":"./dist/DoSubscriptionStore.mjs"},"./DoThreadStore":{"types":"./dist/DoThreadStore.d.mts","default":"./dist/DoThreadStore.mjs"},"./MemoryProtocol":{"types":"./dist/MemoryProtocol.d.mts","default":"./dist/MemoryProtocol.mjs"},"./PortProtocol":{"types":"./dist/PortProtocol.d.mts","default":"./dist/PortProtocol.mjs"},"./PortRouting":{"types":"./dist/PortRouting.d.mts","default":"./dist/PortRouting.mjs"},"./testing/DoStorageFailpointTesting":{"types":"./dist/DoStorageFailpointTesting.d.mts","default":"./dist/DoStorageFailpointTesting.mjs"},"./DoMessageDeliveryStore":{"types":"./dist/DoMessageDeliveryStore.d.mts","default":"./dist/DoMessageDeliveryStore.mjs"}},"description":"Durable Object SQLite storage adapters and the routed port protocol for Effect Agent on Cloudflare.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/storage-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"}}
1
+ {"name":"@effect-agent/storage-cloudflare","version":"0.1.0-beta.78","dependencies":{"@effect-agent/core":"0.1.0-beta.78","@effect-agent/thread":"0.1.0-beta.78","@effect/platform-browser":"4.0.0-rc.112","@effect/sql-sqlite-do":"4.0.0-rc.112"},"devDependencies":{"@cloudflare/vitest-pool-workers":"0.21.3","@cloudflare/workers-types":"5.20260825.1","@effect-agent/testing":"0.1.0-beta.78","@effect/vitest":"4.0.0-rc.112","effect":"4.0.0-rc.112","typescript":"7.0.2","vite-plus":"0.3.0","vitest":"4.1.11"},"peerDependencies":{"effect":"^4.0.0-rc.112"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./DoMemoryStore":{"types":"./dist/DoMemoryStore.d.mts","default":"./dist/DoMemoryStore.mjs"},"./DoScheduleStore":{"types":"./dist/DoScheduleStore.d.mts","default":"./dist/DoScheduleStore.mjs"},"./DoStorageConfig":{"types":"./dist/DoStorageConfig.d.mts","default":"./dist/DoStorageConfig.mjs"},"./DoStorageError":{"types":"./dist/DoStorageError.d.mts","default":"./dist/DoStorageError.mjs"},"./DoStorageFailpoint":{"types":"./dist/DoStorageFailpoint.d.mts","default":"./dist/DoStorageFailpoint.mjs"},"./DoStorageVersion":{"types":"./dist/DoStorageVersion.d.mts","default":"./dist/DoStorageVersion.mjs"},"./DoSubmissionLedger":{"types":"./dist/DoSubmissionLedger.d.mts","default":"./dist/DoSubmissionLedger.mjs"},"./DoSubscriptionStore":{"types":"./dist/DoSubscriptionStore.d.mts","default":"./dist/DoSubscriptionStore.mjs"},"./DoThreadStore":{"types":"./dist/DoThreadStore.d.mts","default":"./dist/DoThreadStore.mjs"},"./MemoryProtocol":{"types":"./dist/MemoryProtocol.d.mts","default":"./dist/MemoryProtocol.mjs"},"./PortProtocol":{"types":"./dist/PortProtocol.d.mts","default":"./dist/PortProtocol.mjs"},"./PortRouting":{"types":"./dist/PortRouting.d.mts","default":"./dist/PortRouting.mjs"},"./testing/DoStorageFailpointTesting":{"types":"./dist/DoStorageFailpointTesting.d.mts","default":"./dist/DoStorageFailpointTesting.mjs"},"./DoMessageDeliveryStore":{"types":"./dist/DoMessageDeliveryStore.d.mts","default":"./dist/DoMessageDeliveryStore.mjs"}},"description":"Durable Object SQLite storage adapters and the routed port protocol for Effect Agent on Cloudflare.","license":"MIT","repository":{"type":"git","url":"git+https://github.com/danieljvdm/effect-agent.git","directory":"packages/storage-cloudflare"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json"}}
@@ -5,8 +5,9 @@ import {
5
5
  MemoryRecallLimits,
6
6
  } from "@effect-agent/core/MemoryReference";
7
7
  import { MemoryAccess, revalidateMemoryLookup } from "@effect-agent/core/MemoryRevalidation";
8
- import { type MemoryReader } from "@effect-agent/core/MemoryStore";
9
8
  import {
9
+ MemoryKey,
10
+ MemoryReader,
10
11
  MemoryConflict,
11
12
  MemoryDocument,
12
13
  MemoryMutationFailure,
@@ -68,6 +69,8 @@ const RevalidateRequest = Schema.TaggedStruct("Revalidate", {
68
69
 
69
70
  const ChangeRequest = Schema.TaggedStruct("Change", { ...RequestFields, write: MemoryWrite.Wire });
70
71
 
72
+ const GetRequest = Schema.TaggedStruct("Get", { ...RequestFields, key: MemoryKey.Wire });
73
+
71
74
  const SemanticRequest: Schema.TaggedStruct<
72
75
  "RevalidateSemantic",
73
76
  typeof RequestFields & {
@@ -83,8 +86,8 @@ const SemanticRequest: Schema.TaggedStruct<
83
86
  });
84
87
 
85
88
  export const MemoryOwnerRequest: Schema.Union<
86
- [typeof RevalidateRequest, typeof ChangeRequest, typeof SemanticRequest]
87
- > = Schema.Union([RevalidateRequest, ChangeRequest, SemanticRequest]);
89
+ [typeof RevalidateRequest, typeof ChangeRequest, typeof SemanticRequest, typeof GetRequest]
90
+ > = Schema.Union([RevalidateRequest, ChangeRequest, SemanticRequest, GetRequest]);
88
91
 
89
92
  export type MemoryOwnerRequest = typeof MemoryOwnerRequest.Type;
90
93
 
@@ -102,16 +105,52 @@ export const MemoryOwnerFailure = Schema.Union([
102
105
 
103
106
  export type MemoryOwnerFailure = typeof MemoryOwnerFailure.Type;
104
107
 
105
- export const MemoryOwnerResponse = Schema.Union([
106
- Schema.TaggedStruct("Lookup", { access: MemoryAccess.Wire, lookup: MemoryLookup }),
107
- Schema.TaggedStruct("Changed", { access: MemoryAccess.Wire, document: MemoryDocument.Wire }),
108
- Schema.TaggedStruct("Semantic", { access: MemoryAccess.Wire, result: SemanticCandidateResult }),
109
- Schema.TaggedStruct("Failed", { failure: MemoryOwnerFailure }),
108
+ const LookupResponse = Schema.TaggedStruct("Lookup", {
109
+ access: MemoryAccess.Wire,
110
+ lookup: MemoryLookup,
111
+ });
112
+
113
+ const ChangedResponse = Schema.TaggedStruct("Changed", {
114
+ access: MemoryAccess.Wire,
115
+ document: MemoryDocument.Wire,
116
+ });
117
+
118
+ const SemanticResponse = Schema.TaggedStruct("Semantic", {
119
+ access: MemoryAccess.Wire,
120
+ result: SemanticCandidateResult,
121
+ });
122
+
123
+ const DocumentResponse = Schema.TaggedStruct("Document", {
124
+ access: MemoryAccess.Wire,
125
+ key: MemoryKey.Wire,
126
+ document: Schema.NullOr(MemoryDocument.Wire),
127
+ });
128
+
129
+ const FailedResponse = Schema.TaggedStruct("Failed", { failure: MemoryOwnerFailure });
130
+
131
+ export const MemoryOwnerResponse: Schema.Union<
132
+ [
133
+ typeof LookupResponse,
134
+ typeof ChangedResponse,
135
+ typeof SemanticResponse,
136
+ typeof DocumentResponse,
137
+ typeof FailedResponse,
138
+ ]
139
+ > = Schema.Union([
140
+ LookupResponse,
141
+ ChangedResponse,
142
+ SemanticResponse,
143
+ DocumentResponse,
144
+ FailedResponse,
110
145
  ]);
111
146
 
112
147
  export type MemoryOwnerResponse = typeof MemoryOwnerResponse.Type;
113
148
 
114
- /** Fail-closed application policy. Authorize the namespace, principal, scope, and full command. */
149
+ /**
150
+ * Fail-closed application policy. Authorize the namespace, principal, scope, and full command.
151
+ * Get requires exact-key authority, including application source/provenance checks where needed.
152
+ * Possession of a key or scope is not authorization, including for absent or withdrawn documents.
153
+ */
115
154
  export class MemoryOwnerAuthorizer extends Context.Service<
116
155
  MemoryOwnerAuthorizer,
117
156
  {
@@ -161,7 +200,7 @@ export const encodeMemoryWire = Effect.fn("encodeMemoryWire")(function* <A, I>(
161
200
  return encoded;
162
201
  });
163
202
 
164
- /** One local read per distinct candidate source, with no per-document network calls. */
203
+ /** One local read for Get, or per distinct candidate source. No discovery or background work. */
165
204
  export const handleMemoryOwnerRequest = Effect.fn("MemoryOwner.handleRequest")(function* (
166
205
  raw: unknown,
167
206
  limits: MemoryRpcLimits = defaultMemoryRpcLimits,
@@ -183,6 +222,7 @@ export const handleMemoryOwnerRequest = Effect.fn("MemoryOwner.handleRequest")(f
183
222
 
184
223
  if (
185
224
  !MemoryNamespace.equals(namespace, request.access.namespace) ||
225
+ (request._tag === "Get" && !MemoryNamespace.equals(namespace, request.key.namespace)) ||
186
226
  (request._tag === "Change" &&
187
227
  !MemoryNamespace.equals(namespace, request.write.key.namespace)) ||
188
228
  (request._tag === "RevalidateSemantic" &&
@@ -207,6 +247,30 @@ export const handleMemoryOwnerRequest = Effect.fn("MemoryOwner.handleRequest")(f
207
247
  const authorizer = yield* MemoryOwnerAuthorizer;
208
248
 
209
249
  yield* authorizer.authorize(request);
250
+ if (request._tag === "Get") {
251
+ const reader = yield* MemoryReader;
252
+ const current = yield* reader.get(request.key);
253
+
254
+ const document =
255
+ current === null ? null : yield* MemoryDocument.restore(namespace, current);
256
+
257
+ if (document !== null) {
258
+ if (document.key.id !== request.key.id || document.source.id !== request.key.id)
259
+ return yield* MemoryStorageError.make({
260
+ operation: "validate memory read identity",
261
+ reason: "corrupt",
262
+ });
263
+ if (
264
+ document._tag === "ActiveMemoryDocument" &&
265
+ !document.scopes.includes(request.access.scope)
266
+ )
267
+ return yield* MemoryRpcError.make({ reason: "denied" });
268
+
269
+ yield* encodeMemoryWire(MemoryDocument.Wire, document, limits.maxSourceBytes);
270
+ }
271
+
272
+ return { _tag: "Document", access: request.access, key: request.key, document };
273
+ }
210
274
  if (request._tag === "Change") {
211
275
  const writer = yield* MemoryWriter;
212
276