Skip to content

Commit 12cf5fb

Browse files
committed
[do] Transport easy override
1 parent 869726e commit 12cf5fb

3 files changed

Lines changed: 58 additions & 54 deletions

File tree

src/@types/durable-object/docs.js

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@
6161
* @example
6262
* ```typescript
6363
* class MySyncletDurableObject extends SyncletDurableObject {
64-
* getCreateComponents() {
65-
* return {
66-
* dataConnector: createDurableObjectSqliteDataConnector({
67-
* depth: 3,
68-
* sqlStorage: this.ctx.storage.sql,
69-
* }),
70-
* };
64+
* getCreateDataConnector() {
65+
* return createDurableObjectSqliteDataConnector({
66+
* depth: 3,
67+
* sqlStorage: this.ctx.storage.sql,
68+
* });
7169
* }
7270
* }
7371
* ```
@@ -130,13 +128,11 @@
130128
* @example
131129
* ```typescript
132130
* class MySyncletDurableObject extends SyncletDurableObject {
133-
* getCreateComponents() {
134-
* return {
135-
* metaConnector: createDurableObjectSqliteMetaConnector({
136-
* depth: 3,
137-
* sqlStorage: this.ctx.storage.sql,
138-
* }),
139-
* };
131+
* getCreateMetaConnector() {
132+
* return createDurableObjectSqliteMetaConnector({
133+
* depth: 3,
134+
* sqlStorage: this.ctx.storage.sql,
135+
* });
140136
* }
141137
* }
142138
* ```
@@ -254,14 +250,12 @@
254250
* @example
255251
* ```typescript
256252
* class MyBrokerDurableObject extends SyncletDurableObject {
257-
* getCreateComponents() {
258-
* return {
259-
* transport: createDurableObjectBrokerTransport({
260-
* durableObject: this,
261-
* path: null, // Broker-only mode
262-
* brokerPaths: /^room-[a-z0-9]+$/, // Only accept specific room paths
263-
* }),
264-
* };
253+
* getCreateTransport() {
254+
* return createDurableObjectBrokerTransport({
255+
* durableObject: this,
256+
* path: null, // Broker-only mode
257+
* brokerPaths: /^room-[a-z0-9]+$/, // Only accept specific room paths
258+
* });
265259
* }
266260
* }
267261
* ```
@@ -274,23 +268,24 @@
274268
* The SyncletDurableObject class is an abstract base class for creating
275269
* Synclet-powered Durable Objects.
276270
*
277-
* Extend this class and optionally implement the `createDataConnector` and
278-
* `createMetaConnector` methods to define how your Durable Object stores data
279-
* and metadata. The class automatically manages the Synclet lifecycle
280-
* internally - you don't need to initialize or access the synclet directly.
271+
* Extend this class and optionally implement the `getCreateDataConnector`,
272+
* `getCreateMetaConnector`, and `getCreateTransport` methods to define how
273+
* your Durable Object stores data and metadata, and how it communicates. The
274+
* class automatically manages the Synclet lifecycle internally - you don't
275+
* need to initialize or access the synclet directly.
281276
*
282-
* Optionally implement `getSyncletImplementations` or `getSyncletOptions` to
277+
* Optionally implement `getCreateImplementations` or `getCreateOptions` to
283278
* configure custom implementations or other options.
284279
* @example
285280
* ```typescript
286281
* class MySyncletDurableObject extends SyncletDurableObject {
287-
* createDataConnector() {
282+
* getCreateDataConnector() {
288283
* return createMemoryDataConnector({depth: 3});
289284
* }
290-
* createMetaConnector() {
285+
* getCreateMetaConnector() {
291286
* return createMemoryMetaConnector({depth: 3});
292287
* }
293-
* getSyncletOptions() {
288+
* getCreateOptions() {
294289
* return {logLevel: 'debug'};
295290
* }
296291
* }
@@ -309,13 +304,29 @@
309304
*/
310305
/// SyncletDurableObject.constructor
311306
/**
312-
* The getCreateComponents method can optionally be implemented to provide
313-
* components for creating the Synclet, including data and meta connectors.
314-
* @returns A SyncletComponents object.
307+
* The getCreateDataConnector method can optionally be implemented to provide
308+
* a data connector for the Synclet.
309+
* @returns A DataConnector instance.
315310
* @category Creation
316311
* @since v0.0.0
317312
*/
318-
/// SyncletDurableObject.getCreateComponents
313+
/// SyncletDurableObject.getCreateDataConnector
314+
/**
315+
* The getCreateMetaConnector method can optionally be implemented to provide
316+
* a meta connector for the Synclet.
317+
* @returns A MetaConnector instance.
318+
* @category Creation
319+
* @since v0.0.0
320+
*/
321+
/// SyncletDurableObject.getCreateMetaConnector
322+
/**
323+
* The getCreateTransport method can optionally be implemented to provide
324+
* a transport or array of transports for the Synclet.
325+
* @returns A Transport instance or array of Transport instances.
326+
* @category Creation
327+
* @since v0.0.0
328+
*/
329+
/// SyncletDurableObject.getCreateTransport
319330
/**
320331
* The getCreateImplementations method can optionally be implemented to
321332
* provide custom implementations for Synclet lifecycle hooks, conflict

src/@types/durable-object/index.d.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import type {
1515
LogLevel,
1616
Meta,
1717
MetaConnector,
18-
SyncletComponents,
1918
SyncletImplementations,
2019
SyncletOptions,
2120
Transport,
@@ -108,12 +107,14 @@ export abstract class SyncletDurableObject<
108107
/// SyncletDurableObject.constructor
109108
constructor(ctx: DurableObjectState, env: Env);
110109

111-
/// SyncletDurableObject.getCreateComponents
112-
getCreateComponents?(): SyncletComponents<
113-
Depth,
114-
DataConnectorType,
115-
MetaConnectorType
116-
>;
110+
/// SyncletDurableObject.getCreateDataConnector
111+
getCreateDataConnector?(): DataConnectorType;
112+
113+
/// SyncletDurableObject.getCreateMetaConnector
114+
getCreateMetaConnector?(): MetaConnectorType;
115+
116+
/// SyncletDurableObject.getCreateTransport
117+
getCreateTransport?(): Transport | Transport[];
117118

118119
/// SyncletDurableObject.getCreateImplementations
119120
getCreateImplementations?(): SyncletImplementations<Depth>;

src/durable-object/synclet.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ export abstract class SyncletDurableObject<
4444
super(ctx, env);
4545
this.ctx.blockConcurrencyWhile(async () => {
4646
this.#synclet = await createSynclet(
47-
this.getCreateComponents?.(),
47+
{
48+
dataConnector: this.getCreateDataConnector?.(),
49+
metaConnector: this.getCreateMetaConnector?.(),
50+
transport: this.getCreateTransport?.(),
51+
} as SyncletComponents<Depth, DataConnectorType, MetaConnectorType>,
4852
this.getCreateImplementations?.(),
4953
this.getCreateOptions?.(),
5054
);
@@ -68,18 +72,6 @@ export abstract class SyncletDurableObject<
6872
return createNotImplementedResponse();
6973
}
7074

71-
getCreateComponents?(): SyncletComponents<
72-
Depth,
73-
DataConnectorType,
74-
MetaConnectorType
75-
> {
76-
return {
77-
dataConnector: this.getCreateDataConnector?.(),
78-
metaConnector: this.getCreateMetaConnector?.(),
79-
transport: this.getCreateTransport?.(),
80-
} as SyncletComponents<Depth, DataConnectorType, MetaConnectorType>;
81-
}
82-
8375
getCreateDataConnector?(): DataConnectorType;
8476

8577
getCreateMetaConnector?(): MetaConnectorType;

0 commit comments

Comments
 (0)