effect-cf 0.23.1 → 0.25.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.
@@ -132,15 +132,7 @@ export interface AnalyticsEngineWriteOptions {
132
132
  readonly onInvalid?: AnalyticsEngineInvalidWritePolicy;
133
133
  }
134
134
 
135
- export interface AnalyticsEngineWriteBatchOptions extends AnalyticsEngineWriteOptions {
136
- /**
137
- * Maximum points per native batch call. Values are clamped to Cloudflare's
138
- * per-invocation limit.
139
- */
140
- readonly batchSize?: number;
141
- }
142
-
143
- export type AnalyticsEngineWritePolicy = AnalyticsEngineWriteBatchOptions;
135
+ export type AnalyticsEngineWritePolicy = AnalyticsEngineWriteOptions;
144
136
 
145
137
  export interface AnalyticsEngineQueryResult<Row = AnalyticsEngineQueryRow> {
146
138
  readonly meta: ReadonlyArray<AnalyticsEngineQueryColumn>;
@@ -167,17 +159,9 @@ export interface AnalyticsEngineClient {
167
159
  dataPoint?: AnalyticsEngineDataPoint,
168
160
  options?: AnalyticsEngineWriteOptions,
169
161
  ) => Effect.Effect<void, AnalyticsEngineWriteError>;
170
- readonly write: (
171
- dataPoint?: AnalyticsEngineDataPoint,
172
- options?: AnalyticsEngineWriteOptions,
173
- ) => Effect.Effect<void, AnalyticsEngineWriteError>;
174
162
  readonly writeDataPoints: (
175
163
  dataPoints: ReadonlyArray<AnalyticsEngineDataPoint>,
176
- options?: AnalyticsEngineWriteBatchOptions,
177
- ) => Effect.Effect<void, AnalyticsEngineWriteError>;
178
- readonly writeBatch: (
179
- dataPoints: ReadonlyArray<AnalyticsEngineDataPoint>,
180
- options?: AnalyticsEngineWriteBatchOptions,
164
+ options?: AnalyticsEngineWriteOptions,
181
165
  ) => Effect.Effect<void, AnalyticsEngineWriteError>;
182
166
  readonly rawUnsafe: Effect.Effect<AnalyticsEngineBinding>;
183
167
  readonly definition: AnalyticsEngineDefinition;
@@ -320,20 +304,11 @@ const tryAnalyticsEngineSync = <A>(
320
304
  catch: (cause) => analyticsEngineError(binding, operation, cause),
321
305
  });
322
306
 
323
- const normalizeBatchSize = (batchSize: number | undefined) => {
324
- if (batchSize === undefined || !Number.isFinite(batchSize) || batchSize <= 0) {
325
- return writeLimits.maxDataPointsPerInvocation;
326
- }
327
-
328
- return Math.min(Math.floor(batchSize), writeLimits.maxDataPointsPerInvocation);
329
- };
330
-
331
307
  const resolveWritePolicy = (
332
308
  defaults: AnalyticsEngineWritePolicy | undefined,
333
- options: AnalyticsEngineWriteBatchOptions | undefined,
309
+ options: AnalyticsEngineWriteOptions | undefined,
334
310
  ) => ({
335
311
  onInvalid: options?.onInvalid ?? defaults?.onInvalid ?? "error",
336
- batchSize: normalizeBatchSize(options?.batchSize ?? defaults?.batchSize),
337
312
  });
338
313
 
339
314
  const fieldPath = (prefix: string, field: string) => (prefix === "" ? field : `${prefix}.${field}`);
@@ -544,23 +519,10 @@ const writeChunks = (
544
519
  operation: string,
545
520
  dataset: AnalyticsEngineBinding,
546
521
  dataPoints: ReadonlyArray<AnalyticsEngineDataPoint>,
547
- batchSize: number,
548
522
  ): Effect.Effect<void, AnalyticsEngineOperationError> =>
549
523
  Effect.gen(function* () {
550
- const writeDataPoints = Reflect.get(dataset, "writeDataPoints");
551
-
552
- for (let index = 0; index < dataPoints.length; index += batchSize) {
553
- const chunk = dataPoints.slice(index, index + batchSize);
554
-
555
- if (typeof writeDataPoints === "function") {
556
- yield* tryAnalyticsEngineSync(binding, operation, () =>
557
- writeDataPoints.call(dataset, chunk),
558
- );
559
- } else {
560
- for (const point of chunk) {
561
- yield* tryAnalyticsEngineSync(binding, operation, () => dataset.writeDataPoint(point));
562
- }
563
- }
524
+ for (const point of dataPoints) {
525
+ yield* tryAnalyticsEngineSync(binding, operation, () => dataset.writeDataPoint(point));
564
526
  }
565
527
  });
566
528
 
@@ -747,7 +709,7 @@ export const makeClient =
747
709
 
748
710
  const writeDataPoints = Effect.fn("AnalyticsEngine.writeDataPoints")(function* (
749
711
  dataPoints: ReadonlyArray<AnalyticsEngineDataPoint>,
750
- options?: AnalyticsEngineWriteBatchOptions,
712
+ options?: AnalyticsEngineWriteOptions,
751
713
  ) {
752
714
  const policy = resolveWritePolicy(defaults, options);
753
715
  const validPoints = yield* validateDataPoints(
@@ -757,21 +719,13 @@ export const makeClient =
757
719
  policy,
758
720
  );
759
721
 
760
- yield* writeChunks(
761
- definition.binding,
762
- "writeDataPoints",
763
- dataset,
764
- validPoints,
765
- policy.batchSize,
766
- );
722
+ yield* writeChunks(definition.binding, "writeDataPoints", dataset, validPoints);
767
723
  });
768
724
 
769
725
  return {
770
726
  definition,
771
727
  writeDataPoint,
772
- write: writeDataPoint,
773
728
  writeDataPoints,
774
- writeBatch: writeDataPoints,
775
729
  rawUnsafe: Effect.succeed(dataset),
776
730
  };
777
731
  };
@@ -457,8 +457,6 @@ export const processDue = <R = never, E = never, OnFailureR = never, OnFailureE
457
457
  return yield* durableObjectAlarm.processDueAlarms(handle, options);
458
458
  });
459
459
 
460
- export const process = processDue;
461
-
462
460
  export type AlarmPayloadSchema = S.Codec<any, any, never, never>;
463
461
 
464
462
  export type AlarmFailurePolicy = "ordered" | "retry" | "skip-and-advance-repeat";
package/src/Email.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import type {
2
2
  EmailAddress as CloudflareEmailAddress,
3
3
  EmailAttachment as CloudflareEmailAttachment,
4
- EmailMessage as CloudflareEmailMessage,
5
4
  EmailSendResult as CloudflareEmailSendResult,
6
5
  SendEmail as CloudflareSendEmail,
7
6
  } from "@cloudflare/workers-types";
@@ -110,9 +109,7 @@ export interface EmailDefinition {
110
109
 
111
110
  export type EmailAddress = CloudflareEmailAddress;
112
111
  export type EmailAttachment = CloudflareEmailAttachment;
113
- export type EmailMessage = CloudflareEmailMessage;
114
112
  export type EmailMessageBuilder = Parameters<CloudflareSendEmail["send"]>[0];
115
- export type EmailSendInput = EmailMessage | EmailMessageBuilder;
116
113
  export type EmailSendResult = CloudflareEmailSendResult;
117
114
  export type EmailBinding = CloudflareSendEmail;
118
115
  export type EmailRecipients = string | EmailAddress | ReadonlyArray<string | EmailAddress>;
@@ -124,14 +121,11 @@ export interface EmailSendOptions {
124
121
  }
125
122
 
126
123
  interface EmailRuntimeBinding {
127
- readonly send: (message: EmailSendInput) => Promise<EmailSendResult>;
124
+ readonly send: (message: EmailMessageBuilder) => Promise<EmailSendResult>;
128
125
  }
129
126
 
130
127
  export interface EmailClient {
131
- readonly send: {
132
- (message: EmailMessage): Effect.Effect<EmailSendResult, EmailSendError>;
133
- (builder: EmailMessageBuilder): Effect.Effect<EmailSendResult, EmailSendError>;
134
- };
128
+ readonly send: (message: EmailMessageBuilder) => Effect.Effect<EmailSendResult, EmailSendError>;
135
129
  readonly rawUnsafe: Effect.Effect<EmailBinding>;
136
130
  readonly definition: EmailDefinition;
137
131
  }
@@ -200,29 +194,6 @@ const tryEmailPromise = <A>(
200
194
  catch: (cause) => emailError(binding, operation, cause),
201
195
  });
202
196
 
203
- const builderFields = [
204
- "subject",
205
- "html",
206
- "text",
207
- "cc",
208
- "bcc",
209
- "replyTo",
210
- "attachments",
211
- "headers",
212
- ] as const;
213
-
214
- /**
215
- * Distinguishes structured Email Sending messages from raw MIME `EmailMessage`
216
- * values, which only carry envelope `from` and `to` addresses.
217
- */
218
- export const isEmailMessageBuilder = (message: EmailSendInput): message is EmailMessageBuilder => {
219
- if (typeof message !== "object" || message === null) {
220
- return false;
221
- }
222
-
223
- return builderFields.some((field) => Reflect.get(message, field) !== undefined);
224
- };
225
-
226
197
  const byteLength = (value: string) => textEncoder.encode(value).byteLength;
227
198
 
228
199
  const limitViolation = (
@@ -469,13 +440,13 @@ export const makeClient =
469
440
  (email: EmailBinding): EmailClient => {
470
441
  const runtime = email as EmailRuntimeBinding;
471
442
  const validate = options?.validate ?? true;
472
- const send = Effect.fn("Email.send")(function* (message: EmailSendInput) {
473
- if (validate && isEmailMessageBuilder(message)) {
443
+ const send = Effect.fn("Email.send")(function* (message: EmailMessageBuilder) {
444
+ if (validate) {
474
445
  yield* validateSendInput(definition.binding, "send", message);
475
446
  }
476
447
 
477
448
  return yield* tryEmailPromise(definition.binding, "send", () => runtime.send(message));
478
- }) as EmailClient["send"];
449
+ });
479
450
 
480
451
  return {
481
452
  definition,
@@ -41,7 +41,7 @@ type ScalarConfigKey = Extract<
41
41
  * const program = Effect.gen(function* () {
42
42
  * const config = yield* AppConfig;
43
43
  * // ...
44
- * }).pipe(Effect.provide(WorkerConfig.layer));
44
+ * }).pipe(Effect.provide(WorkerConfig.providerLayer));
45
45
  * ```
46
46
  *
47
47
  * Keys are constrained to scalar `Cloudflare.Env` properties (`string`,
@@ -109,9 +109,6 @@ export namespace WorkerConfig {
109
109
  export const providerLayer: Layer.Layer<never, never, WorkerEnvironment> =
110
110
  ConfigProvider.layer(provider);
111
111
 
112
- /** Alias for `providerLayer` for concise use in worker layers. */
113
- export const layer: Layer.Layer<never, never, WorkerEnvironment> = providerLayer;
114
-
115
112
  /** Build a `ConfigProvider` layer with a custom `env` conversion function. */
116
113
  export const layerWith = (
117
114
  makeProvider: (env: WorkerEnv) => ConfigProvider.ConfigProvider,