@workers-community/workers-types 4.20260405.1 → 4.20260409.1

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.
Files changed (3) hide show
  1. package/index.d.ts +166 -0
  2. package/index.ts +166 -0
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -557,6 +557,9 @@ interface AlarmInvocationInfo {
557
557
  interface Cloudflare {
558
558
  readonly compatibilityFlags: Record<string, boolean>;
559
559
  }
560
+ declare abstract class ColoLocalActorNamespace {
561
+ get(actorId: string): Fetcher;
562
+ }
560
563
  interface DurableObject {
561
564
  fetch(request: Request): Response | Promise<Response>;
562
565
  connect?(socket: Socket): void | Promise<void>;
@@ -636,6 +639,7 @@ interface DurableObjectState<Props = unknown> {
636
639
  readonly id: DurableObjectId;
637
640
  readonly storage: DurableObjectStorage;
638
641
  container?: Container;
642
+ facets: DurableObjectFacets;
639
643
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
640
644
  acceptWebSocket(ws: WebSocket, tags?: string[]): void;
641
645
  getWebSockets(tag?: string): WebSocket[];
@@ -750,6 +754,22 @@ declare class WebSocketRequestResponsePair {
750
754
  get request(): string;
751
755
  get response(): string;
752
756
  }
757
+ interface DurableObjectFacets {
758
+ get<T extends Rpc.DurableObjectBranded | undefined = undefined>(
759
+ name: string,
760
+ getStartupOptions: () =>
761
+ | FacetStartupOptions<T>
762
+ | Promise<FacetStartupOptions<T>>,
763
+ ): Fetcher<T>;
764
+ abort(name: string, reason: any): void;
765
+ delete(name: string): void;
766
+ }
767
+ interface FacetStartupOptions<
768
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
769
+ > {
770
+ id?: DurableObjectId | string;
771
+ class: DurableObjectClass<T>;
772
+ }
753
773
  interface AnalyticsEngineDataset {
754
774
  writeDataPoint(event?: AnalyticsEngineDataPoint): void;
755
775
  }
@@ -3864,6 +3884,8 @@ type LoopbackDurableObjectClass<
3864
3884
  (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3865
3885
  ? (opts: { props?: Props }) => DurableObjectClass<T>
3866
3886
  : (opts: { props?: any }) => DurableObjectClass<T>);
3887
+ interface LoopbackDurableObjectNamespace extends DurableObjectNamespace {}
3888
+ interface LoopbackColoLocalActorNamespace extends ColoLocalActorNamespace {}
3867
3889
  interface SyncKvStorage {
3868
3890
  get<T = unknown>(key: string): T | undefined;
3869
3891
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3883,6 +3905,10 @@ interface WorkerStub {
3883
3905
  name?: string,
3884
3906
  options?: WorkerStubEntrypointOptions,
3885
3907
  ): Fetcher<T>;
3908
+ getDurableObjectClass<T extends Rpc.DurableObjectBranded | undefined>(
3909
+ name?: string,
3910
+ options?: WorkerStubEntrypointOptions,
3911
+ ): DurableObjectClass<T>;
3886
3912
  }
3887
3913
  interface WorkerStubEntrypointOptions {
3888
3914
  props?: any;
@@ -12006,6 +12032,140 @@ declare module "cloudflare:email" {
12006
12032
  };
12007
12033
  export { _EmailMessage as EmailMessage };
12008
12034
  }
12035
+ /**
12036
+ * Evaluation context for targeting rules.
12037
+ * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12038
+ */
12039
+ type EvaluationContext = Record<string, string | number | boolean>;
12040
+ interface EvaluationDetails<T> {
12041
+ flagKey: string;
12042
+ value: T;
12043
+ variant?: string | undefined;
12044
+ reason?: string | undefined;
12045
+ errorCode?: string | undefined;
12046
+ errorMessage?: string | undefined;
12047
+ }
12048
+ interface FlagEvaluationError extends Error {}
12049
+ /**
12050
+ * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12051
+ *
12052
+ * @example
12053
+ * ```typescript
12054
+ * // Get a boolean flag value with a default
12055
+ * const enabled = await env.FLAGS.getBooleanValue('my-feature', false);
12056
+ *
12057
+ * // Get a flag value with evaluation context for targeting
12058
+ * const variant = await env.FLAGS.getStringValue('experiment', 'control', {
12059
+ * userId: 'user-123',
12060
+ * country: 'US',
12061
+ * });
12062
+ *
12063
+ * // Get full evaluation details including variant and reason
12064
+ * const details = await env.FLAGS.getBooleanDetails('my-feature', false);
12065
+ * console.log(details.variant, details.reason);
12066
+ * ```
12067
+ */
12068
+ declare abstract class Flags {
12069
+ /**
12070
+ * Get a flag value without type checking.
12071
+ * @param flagKey The key of the flag to evaluate.
12072
+ * @param defaultValue Optional default value returned when evaluation fails.
12073
+ * @param context Optional evaluation context for targeting rules.
12074
+ */
12075
+ get(
12076
+ flagKey: string,
12077
+ defaultValue?: unknown,
12078
+ context?: EvaluationContext,
12079
+ ): Promise<unknown>;
12080
+ /**
12081
+ * Get a boolean flag value.
12082
+ * @param flagKey The key of the flag to evaluate.
12083
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12084
+ * @param context Optional evaluation context for targeting rules.
12085
+ */
12086
+ getBooleanValue(
12087
+ flagKey: string,
12088
+ defaultValue: boolean,
12089
+ context?: EvaluationContext,
12090
+ ): Promise<boolean>;
12091
+ /**
12092
+ * Get a string flag value.
12093
+ * @param flagKey The key of the flag to evaluate.
12094
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12095
+ * @param context Optional evaluation context for targeting rules.
12096
+ */
12097
+ getStringValue(
12098
+ flagKey: string,
12099
+ defaultValue: string,
12100
+ context?: EvaluationContext,
12101
+ ): Promise<string>;
12102
+ /**
12103
+ * Get a number flag value.
12104
+ * @param flagKey The key of the flag to evaluate.
12105
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12106
+ * @param context Optional evaluation context for targeting rules.
12107
+ */
12108
+ getNumberValue(
12109
+ flagKey: string,
12110
+ defaultValue: number,
12111
+ context?: EvaluationContext,
12112
+ ): Promise<number>;
12113
+ /**
12114
+ * Get an object flag value.
12115
+ * @param flagKey The key of the flag to evaluate.
12116
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12117
+ * @param context Optional evaluation context for targeting rules.
12118
+ */
12119
+ getObjectValue<T extends object>(
12120
+ flagKey: string,
12121
+ defaultValue: T,
12122
+ context?: EvaluationContext,
12123
+ ): Promise<T>;
12124
+ /**
12125
+ * Get a boolean flag value with full evaluation details.
12126
+ * @param flagKey The key of the flag to evaluate.
12127
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12128
+ * @param context Optional evaluation context for targeting rules.
12129
+ */
12130
+ getBooleanDetails(
12131
+ flagKey: string,
12132
+ defaultValue: boolean,
12133
+ context?: EvaluationContext,
12134
+ ): Promise<EvaluationDetails<boolean>>;
12135
+ /**
12136
+ * Get a string flag value with full evaluation details.
12137
+ * @param flagKey The key of the flag to evaluate.
12138
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12139
+ * @param context Optional evaluation context for targeting rules.
12140
+ */
12141
+ getStringDetails(
12142
+ flagKey: string,
12143
+ defaultValue: string,
12144
+ context?: EvaluationContext,
12145
+ ): Promise<EvaluationDetails<string>>;
12146
+ /**
12147
+ * Get a number flag value with full evaluation details.
12148
+ * @param flagKey The key of the flag to evaluate.
12149
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12150
+ * @param context Optional evaluation context for targeting rules.
12151
+ */
12152
+ getNumberDetails(
12153
+ flagKey: string,
12154
+ defaultValue: number,
12155
+ context?: EvaluationContext,
12156
+ ): Promise<EvaluationDetails<number>>;
12157
+ /**
12158
+ * Get an object flag value with full evaluation details.
12159
+ * @param flagKey The key of the flag to evaluate.
12160
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12161
+ * @param context Optional evaluation context for targeting rules.
12162
+ */
12163
+ getObjectDetails<T extends object>(
12164
+ flagKey: string,
12165
+ defaultValue: T,
12166
+ context?: EvaluationContext,
12167
+ ): Promise<EvaluationDetails<T>>;
12168
+ }
12009
12169
  /**
12010
12170
  * Hello World binding to serve as an explanatory example. DO NOT USE
12011
12171
  */
@@ -13844,6 +14004,11 @@ declare namespace TailStream {
13844
14004
  readonly tag?: string;
13845
14005
  readonly message?: string;
13846
14006
  }
14007
+ interface TracePreviewInfo {
14008
+ readonly id: string;
14009
+ readonly slug: string;
14010
+ readonly name: string;
14011
+ }
13847
14012
  interface Onset {
13848
14013
  readonly type: "onset";
13849
14014
  readonly attributes: Attribute[];
@@ -13855,6 +14020,7 @@ declare namespace TailStream {
13855
14020
  readonly scriptName?: string;
13856
14021
  readonly scriptTags?: string[];
13857
14022
  readonly scriptVersion?: ScriptVersion;
14023
+ readonly preview?: TracePreviewInfo;
13858
14024
  readonly info:
13859
14025
  | FetchEventInfo
13860
14026
  | ConnectEventInfo
package/index.ts CHANGED
@@ -559,6 +559,9 @@ export interface AlarmInvocationInfo {
559
559
  export interface Cloudflare {
560
560
  readonly compatibilityFlags: Record<string, boolean>;
561
561
  }
562
+ export declare abstract class ColoLocalActorNamespace {
563
+ get(actorId: string): Fetcher;
564
+ }
562
565
  export interface DurableObject {
563
566
  fetch(request: Request): Response | Promise<Response>;
564
567
  connect?(socket: Socket): void | Promise<void>;
@@ -638,6 +641,7 @@ export interface DurableObjectState<Props = unknown> {
638
641
  readonly id: DurableObjectId;
639
642
  readonly storage: DurableObjectStorage;
640
643
  container?: Container;
644
+ facets: DurableObjectFacets;
641
645
  blockConcurrencyWhile<T>(callback: () => Promise<T>): Promise<T>;
642
646
  acceptWebSocket(ws: WebSocket, tags?: string[]): void;
643
647
  getWebSockets(tag?: string): WebSocket[];
@@ -752,6 +756,22 @@ export declare class WebSocketRequestResponsePair {
752
756
  get request(): string;
753
757
  get response(): string;
754
758
  }
759
+ export interface DurableObjectFacets {
760
+ get<T extends Rpc.DurableObjectBranded | undefined = undefined>(
761
+ name: string,
762
+ getStartupOptions: () =>
763
+ | FacetStartupOptions<T>
764
+ | Promise<FacetStartupOptions<T>>,
765
+ ): Fetcher<T>;
766
+ abort(name: string, reason: any): void;
767
+ delete(name: string): void;
768
+ }
769
+ export interface FacetStartupOptions<
770
+ T extends Rpc.DurableObjectBranded | undefined = undefined,
771
+ > {
772
+ id?: DurableObjectId | string;
773
+ class: DurableObjectClass<T>;
774
+ }
755
775
  export interface AnalyticsEngineDataset {
756
776
  writeDataPoint(event?: AnalyticsEngineDataPoint): void;
757
777
  }
@@ -3870,6 +3890,8 @@ export type LoopbackDurableObjectClass<
3870
3890
  (T extends CloudflareWorkersModule.DurableObject<any, infer Props>
3871
3891
  ? (opts: { props?: Props }) => DurableObjectClass<T>
3872
3892
  : (opts: { props?: any }) => DurableObjectClass<T>);
3893
+ export interface LoopbackDurableObjectNamespace extends DurableObjectNamespace {}
3894
+ export interface LoopbackColoLocalActorNamespace extends ColoLocalActorNamespace {}
3873
3895
  export interface SyncKvStorage {
3874
3896
  get<T = unknown>(key: string): T | undefined;
3875
3897
  list<T = unknown>(options?: SyncKvListOptions): Iterable<[string, T]>;
@@ -3889,6 +3911,10 @@ export interface WorkerStub {
3889
3911
  name?: string,
3890
3912
  options?: WorkerStubEntrypointOptions,
3891
3913
  ): Fetcher<T>;
3914
+ getDurableObjectClass<T extends Rpc.DurableObjectBranded | undefined>(
3915
+ name?: string,
3916
+ options?: WorkerStubEntrypointOptions,
3917
+ ): DurableObjectClass<T>;
3892
3918
  }
3893
3919
  export interface WorkerStubEntrypointOptions {
3894
3920
  props?: any;
@@ -12022,6 +12048,140 @@ export declare type EmailExportedHandler<Env = unknown, Props = unknown> = (
12022
12048
  env: Env,
12023
12049
  ctx: ExecutionContext<Props>,
12024
12050
  ) => void | Promise<void>;
12051
+ /**
12052
+ * Evaluation context for targeting rules.
12053
+ * Keys are attribute names (e.g. "userId", "country"), values are the attribute values.
12054
+ */
12055
+ export type EvaluationContext = Record<string, string | number | boolean>;
12056
+ export interface EvaluationDetails<T> {
12057
+ flagKey: string;
12058
+ value: T;
12059
+ variant?: string | undefined;
12060
+ reason?: string | undefined;
12061
+ errorCode?: string | undefined;
12062
+ errorMessage?: string | undefined;
12063
+ }
12064
+ export interface FlagEvaluationError extends Error {}
12065
+ /**
12066
+ * Feature flags binding for evaluating feature flags from a Cloudflare Workers script.
12067
+ *
12068
+ * @example
12069
+ * ```typescript
12070
+ * // Get a boolean flag value with a default
12071
+ * const enabled = await env.FLAGS.getBooleanValue('my-feature', false);
12072
+ *
12073
+ * // Get a flag value with evaluation context for targeting
12074
+ * const variant = await env.FLAGS.getStringValue('experiment', 'control', {
12075
+ * userId: 'user-123',
12076
+ * country: 'US',
12077
+ * });
12078
+ *
12079
+ * // Get full evaluation details including variant and reason
12080
+ * const details = await env.FLAGS.getBooleanDetails('my-feature', false);
12081
+ * console.log(details.variant, details.reason);
12082
+ * ```
12083
+ */
12084
+ export declare abstract class Flags {
12085
+ /**
12086
+ * Get a flag value without type checking.
12087
+ * @param flagKey The key of the flag to evaluate.
12088
+ * @param defaultValue Optional default value returned when evaluation fails.
12089
+ * @param context Optional evaluation context for targeting rules.
12090
+ */
12091
+ get(
12092
+ flagKey: string,
12093
+ defaultValue?: unknown,
12094
+ context?: EvaluationContext,
12095
+ ): Promise<unknown>;
12096
+ /**
12097
+ * Get a boolean flag value.
12098
+ * @param flagKey The key of the flag to evaluate.
12099
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12100
+ * @param context Optional evaluation context for targeting rules.
12101
+ */
12102
+ getBooleanValue(
12103
+ flagKey: string,
12104
+ defaultValue: boolean,
12105
+ context?: EvaluationContext,
12106
+ ): Promise<boolean>;
12107
+ /**
12108
+ * Get a string flag value.
12109
+ * @param flagKey The key of the flag to evaluate.
12110
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12111
+ * @param context Optional evaluation context for targeting rules.
12112
+ */
12113
+ getStringValue(
12114
+ flagKey: string,
12115
+ defaultValue: string,
12116
+ context?: EvaluationContext,
12117
+ ): Promise<string>;
12118
+ /**
12119
+ * Get a number flag value.
12120
+ * @param flagKey The key of the flag to evaluate.
12121
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12122
+ * @param context Optional evaluation context for targeting rules.
12123
+ */
12124
+ getNumberValue(
12125
+ flagKey: string,
12126
+ defaultValue: number,
12127
+ context?: EvaluationContext,
12128
+ ): Promise<number>;
12129
+ /**
12130
+ * Get an object flag value.
12131
+ * @param flagKey The key of the flag to evaluate.
12132
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12133
+ * @param context Optional evaluation context for targeting rules.
12134
+ */
12135
+ getObjectValue<T extends object>(
12136
+ flagKey: string,
12137
+ defaultValue: T,
12138
+ context?: EvaluationContext,
12139
+ ): Promise<T>;
12140
+ /**
12141
+ * Get a boolean flag value with full evaluation details.
12142
+ * @param flagKey The key of the flag to evaluate.
12143
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12144
+ * @param context Optional evaluation context for targeting rules.
12145
+ */
12146
+ getBooleanDetails(
12147
+ flagKey: string,
12148
+ defaultValue: boolean,
12149
+ context?: EvaluationContext,
12150
+ ): Promise<EvaluationDetails<boolean>>;
12151
+ /**
12152
+ * Get a string flag value with full evaluation details.
12153
+ * @param flagKey The key of the flag to evaluate.
12154
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12155
+ * @param context Optional evaluation context for targeting rules.
12156
+ */
12157
+ getStringDetails(
12158
+ flagKey: string,
12159
+ defaultValue: string,
12160
+ context?: EvaluationContext,
12161
+ ): Promise<EvaluationDetails<string>>;
12162
+ /**
12163
+ * Get a number flag value with full evaluation details.
12164
+ * @param flagKey The key of the flag to evaluate.
12165
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12166
+ * @param context Optional evaluation context for targeting rules.
12167
+ */
12168
+ getNumberDetails(
12169
+ flagKey: string,
12170
+ defaultValue: number,
12171
+ context?: EvaluationContext,
12172
+ ): Promise<EvaluationDetails<number>>;
12173
+ /**
12174
+ * Get an object flag value with full evaluation details.
12175
+ * @param flagKey The key of the flag to evaluate.
12176
+ * @param defaultValue Default value returned when evaluation fails or the flag type does not match.
12177
+ * @param context Optional evaluation context for targeting rules.
12178
+ */
12179
+ getObjectDetails<T extends object>(
12180
+ flagKey: string,
12181
+ defaultValue: T,
12182
+ context?: EvaluationContext,
12183
+ ): Promise<EvaluationDetails<T>>;
12184
+ }
12025
12185
  /**
12026
12186
  * Hello World binding to serve as an explanatory example. DO NOT USE
12027
12187
  */
@@ -13801,6 +13961,11 @@ export declare namespace TailStream {
13801
13961
  readonly tag?: string;
13802
13962
  readonly message?: string;
13803
13963
  }
13964
+ interface TracePreviewInfo {
13965
+ readonly id: string;
13966
+ readonly slug: string;
13967
+ readonly name: string;
13968
+ }
13804
13969
  interface Onset {
13805
13970
  readonly type: "onset";
13806
13971
  readonly attributes: Attribute[];
@@ -13812,6 +13977,7 @@ export declare namespace TailStream {
13812
13977
  readonly scriptName?: string;
13813
13978
  readonly scriptTags?: string[];
13814
13979
  readonly scriptVersion?: ScriptVersion;
13980
+ readonly preview?: TracePreviewInfo;
13815
13981
  readonly info:
13816
13982
  | FetchEventInfo
13817
13983
  | ConnectEventInfo
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "author": "Workers Community",
9
9
  "license": "MIT OR Apache-2.0",
10
- "version": "4.20260405.1",
10
+ "version": "4.20260409.1",
11
11
  "exports": {
12
12
  ".": {
13
13
  "types": "./index.d.ts",