@livestore/adapter-cloudflare 0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5 → 0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e

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.
@@ -39,6 +39,71 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState>
39
39
  */
40
40
  resetPersistence?: boolean;
41
41
  } & LogConfig.WithLoggerOptions;
42
+ /**
43
+ * Creates a LiveStore instance inside a Cloudflare Durable Object.
44
+ *
45
+ * This function bootstraps a full LiveStore client within a Durable Object, enabling
46
+ * persistent state management with automatic sync to a sync backend. Use this when you
47
+ * need server-side LiveStore instances that can communicate with other clients.
48
+ *
49
+ * Returns an Effect that resolves to a Store instance. For a Promise-based API,
50
+ * use `createStoreDoPromise` instead.
51
+ *
52
+ * @example
53
+ * ```ts
54
+ * import { createStoreDo } from '@livestore/adapter-cloudflare'
55
+ * import { schema } from './schema'
56
+ *
57
+ * export class MyDurableObject extends DurableObject {
58
+ * store: Store | undefined
59
+ *
60
+ * async fetch(request: Request) {
61
+ * if (!this.store) {
62
+ * this.store = await createStoreDo({
63
+ * schema,
64
+ * storeId: 'my-store',
65
+ * clientId: this.ctx.id.toString(),
66
+ * sessionId: 'do-session',
67
+ * durableObject: {
68
+ * ctx: this.ctx,
69
+ * env: this.env,
70
+ * bindingName: 'MY_DO',
71
+ * },
72
+ * syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
73
+ * }).pipe(Effect.runPromise)
74
+ * }
75
+ * // Use this.store...
76
+ * }
77
+ * }
78
+ * ```
79
+ *
80
+ * @see https://livestore.dev/docs/reference/adapters/cloudflare for setup guide
81
+ */
42
82
  export declare const createStoreDo: <TSchema extends LiveStoreSchema, TEnv, TState extends CfTypes.DurableObjectState = CfTypes.DurableObjectState>({ schema, storeId, clientId, sessionId, durableObject, syncBackendStub, livePull, resetPersistence, }: CreateStoreDoOptions<TSchema, TEnv, TState>) => Effect.Effect<import("@livestore/livestore").Store<TSchema, {}>, import("@livestore/common").UnknownError, never>;
83
+ /**
84
+ * Promise-based wrapper around `createStoreDo` for simpler async/await usage.
85
+ *
86
+ * Equivalent to calling `createStoreDo(options).pipe(Effect.runPromise)` with
87
+ * logging configured automatically.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { createStoreDoPromise } from '@livestore/adapter-cloudflare'
92
+ *
93
+ * export class MyDurableObject extends DurableObject {
94
+ * async fetch(request: Request) {
95
+ * const store = await createStoreDoPromise({
96
+ * schema,
97
+ * storeId: 'my-store',
98
+ * clientId: this.ctx.id.toString(),
99
+ * sessionId: 'do-session',
100
+ * durableObject: { ctx: this.ctx, env: this.env, bindingName: 'MY_DO' },
101
+ * syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
102
+ * })
103
+ * // Use store...
104
+ * }
105
+ * }
106
+ * ```
107
+ */
43
108
  export declare const createStoreDoPromise: <TSchema extends LiveStoreSchema, TEnv, TState extends CfTypes.DurableObjectState = CfTypes.DurableObjectState>(options: CreateStoreDoOptions<TSchema, TEnv, TState>) => Promise<import("@livestore/livestore").Store<TSchema, {}>>;
44
109
  //# sourceMappingURL=create-store-do.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-store-do.d.ts","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAChE,OAAO,EAAe,KAAK,eAAe,EAAe,MAAM,sBAAsB,CAAA;AACrF,OAAO,KAAK,KAAK,aAAa,MAAM,8BAA8B,CAAA;AAElE,OAAO,EAAE,MAAM,EAAiB,MAAM,yBAAyB,CAAA;AAG/D,MAAM,MAAM,GAAG,GAAG;IAChB,eAAe,EAAE,OAAO,CAAC,sBAAsB,CA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GACxB,OAAO,SAAS,eAAe,EAC/B,IAAI,EACJ,MAAM,SAAS,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,EACtE,uGASC,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,sHAuB1C,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,oBAAoB,GAC/B,OAAO,SAAS,eAAe,EAC/B,IAAI,EACJ,MAAM,SAAS,OAAO,CAAC,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,EAEtE,SAAS,oBAAoB,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,+DASnD,CAAA"}
@@ -3,6 +3,46 @@ import { createStore, provideOtel } from '@livestore/livestore';
3
3
  import { makeDoRpcSync } from '@livestore/sync-cf/client';
4
4
  import { Effect, Logger, Scope } from '@livestore/utils/effect';
5
5
  import { makeAdapter } from "./make-adapter.js";
6
+ /**
7
+ * Creates a LiveStore instance inside a Cloudflare Durable Object.
8
+ *
9
+ * This function bootstraps a full LiveStore client within a Durable Object, enabling
10
+ * persistent state management with automatic sync to a sync backend. Use this when you
11
+ * need server-side LiveStore instances that can communicate with other clients.
12
+ *
13
+ * Returns an Effect that resolves to a Store instance. For a Promise-based API,
14
+ * use `createStoreDoPromise` instead.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { createStoreDo } from '@livestore/adapter-cloudflare'
19
+ * import { schema } from './schema'
20
+ *
21
+ * export class MyDurableObject extends DurableObject {
22
+ * store: Store | undefined
23
+ *
24
+ * async fetch(request: Request) {
25
+ * if (!this.store) {
26
+ * this.store = await createStoreDo({
27
+ * schema,
28
+ * storeId: 'my-store',
29
+ * clientId: this.ctx.id.toString(),
30
+ * sessionId: 'do-session',
31
+ * durableObject: {
32
+ * ctx: this.ctx,
33
+ * env: this.env,
34
+ * bindingName: 'MY_DO',
35
+ * },
36
+ * syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
37
+ * }).pipe(Effect.runPromise)
38
+ * }
39
+ * // Use this.store...
40
+ * }
41
+ * }
42
+ * ```
43
+ *
44
+ * @see https://livestore.dev/docs/reference/adapters/cloudflare for setup guide
45
+ */
6
46
  // TODO Also support in Cloudflare workers outside of a durable object context.
7
47
  export const createStoreDo = ({ schema, storeId, clientId, sessionId, durableObject, syncBackendStub, livePull = false, resetPersistence = false, }) => Effect.gen(function* () {
8
48
  const { ctx, bindingName } = durableObject;
@@ -25,6 +65,31 @@ export const createStoreDo = ({ schema, storeId, clientId, sessionId, durableObj
25
65
  });
26
66
  return yield* createStore({ schema, adapter, storeId }).pipe(Scope.extend(scope), provideOtel({}));
27
67
  });
68
+ /**
69
+ * Promise-based wrapper around `createStoreDo` for simpler async/await usage.
70
+ *
71
+ * Equivalent to calling `createStoreDo(options).pipe(Effect.runPromise)` with
72
+ * logging configured automatically.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * import { createStoreDoPromise } from '@livestore/adapter-cloudflare'
77
+ *
78
+ * export class MyDurableObject extends DurableObject {
79
+ * async fetch(request: Request) {
80
+ * const store = await createStoreDoPromise({
81
+ * schema,
82
+ * storeId: 'my-store',
83
+ * clientId: this.ctx.id.toString(),
84
+ * sessionId: 'do-session',
85
+ * durableObject: { ctx: this.ctx, env: this.env, bindingName: 'MY_DO' },
86
+ * syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
87
+ * })
88
+ * // Use store...
89
+ * }
90
+ * }
91
+ * ```
92
+ */
28
93
  export const createStoreDoPromise = (options) => createStoreDo(options).pipe(LogConfig.withLoggerConfig(options, {
29
94
  threadName: 'DoClient',
30
95
  defaultLogger: Logger.consoleWithThread('DoClient'),
@@ -1 +1 @@
1
- {"version":3,"file":"create-store-do.js","sourceRoot":"","sources":["../src/create-store-do.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAE7C,OAAO,EAAE,WAAW,EAAwB,WAAW,EAAE,MA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O,GAAG,WAAW,CAAC;QAC1B,QAAQ;QACR,SAAS;QACT,OAAO;QACP,gBAAgB;QAChB,WAAW,EAAE;YACX,OAAO,EAAE,aAAa,CAAC;gBACrB,eAAe;gBACf,oBAAoB,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE;aACvD,CAAC;YACF,QAAQ,EAAE,0CAA0C;YACpD,kBAAkB,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE;SACvD;KACF,CAAC,CAAA;IAEF,OAAO,KAAK,CAAC,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC,CAAA;AACpG,CAAC,CAAC,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAKlC,OAAoD,EACpD,EAAE,CACF,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,CACzB,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE;IAClC,UAAU,EAAE,UAAU;IACtB,aAAa,EAAE,MAAM,CAAC,iBAAiB,CAAC,UAAU,CAAC;CACpD,CAAC,EACF,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,UAAU,CAClB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/adapter-cloudflare",
3
- "version": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5",
3
+ "version": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "./src/polyfill.ts",
@@ -12,12 +12,12 @@
12
12
  },
13
13
  "dependencies": {
14
14
  "@cloudflare/workers-types": "4.20251118.0",
15
- "@livestore/common": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5",
16
- "@livestore/livestore": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5",
17
- "@livestore/sqlite-wasm": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5",
18
- "@livestore/common-cf": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5",
19
- "@livestore/sync-cf": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5",
20
- "@livestore/utils": "0.0.0-snapshot-ed6be451622dfe970d9d5c49210810509b9723c5"
15
+ "@livestore/common": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e",
16
+ "@livestore/livestore": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e",
17
+ "@livestore/sqlite-wasm": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e",
18
+ "@livestore/common-cf": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e",
19
+ "@livestore/sync-cf": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e",
20
+ "@livestore/utils": "0.0.0-snapshot-917fd8f04f4f97fb79b7e4568ab3d702377aaf4e"
21
21
  },
22
22
  "devDependencies": {
23
23
  "wrangler": "4.42.2"
@@ -44,6 +44,46 @@ export type CreateStoreDoOptions<TSchema extends LiveStoreSchema, TEnv, TState>
44
44
  resetPersistence?: boolean
45
45
  } & LogConfig.WithLoggerOptions
46
46
 
47
+ /**
48
+ * Creates a LiveStore instance inside a Cloudflare Durable Object.
49
+ *
50
+ * This function bootstraps a full LiveStore client within a Durable Object, enabling
51
+ * persistent state management with automatic sync to a sync backend. Use this when you
52
+ * need server-side LiveStore instances that can communicate with other clients.
53
+ *
54
+ * Returns an Effect that resolves to a Store instance. For a Promise-based API,
55
+ * use `createStoreDoPromise` instead.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { createStoreDo } from '@livestore/adapter-cloudflare'
60
+ * import { schema } from './schema'
61
+ *
62
+ * export class MyDurableObject extends DurableObject {
63
+ * store: Store | undefined
64
+ *
65
+ * async fetch(request: Request) {
66
+ * if (!this.store) {
67
+ * this.store = await createStoreDo({
68
+ * schema,
69
+ * storeId: 'my-store',
70
+ * clientId: this.ctx.id.toString(),
71
+ * sessionId: 'do-session',
72
+ * durableObject: {
73
+ * ctx: this.ctx,
74
+ * env: this.env,
75
+ * bindingName: 'MY_DO',
76
+ * },
77
+ * syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
78
+ * }).pipe(Effect.runPromise)
79
+ * }
80
+ * // Use this.store...
81
+ * }
82
+ * }
83
+ * ```
84
+ *
85
+ * @see https://livestore.dev/docs/reference/adapters/cloudflare for setup guide
86
+ */
47
87
  // TODO Also support in Cloudflare workers outside of a durable object context.
48
88
  export const createStoreDo = <
49
89
  TSchema extends LiveStoreSchema,
@@ -83,6 +123,31 @@ export const createStoreDo = <
83
123
  return yield* createStore({ schema, adapter, storeId }).pipe(Scope.extend(scope), provideOtel({}))
84
124
  })
85
125
 
126
+ /**
127
+ * Promise-based wrapper around `createStoreDo` for simpler async/await usage.
128
+ *
129
+ * Equivalent to calling `createStoreDo(options).pipe(Effect.runPromise)` with
130
+ * logging configured automatically.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import { createStoreDoPromise } from '@livestore/adapter-cloudflare'
135
+ *
136
+ * export class MyDurableObject extends DurableObject {
137
+ * async fetch(request: Request) {
138
+ * const store = await createStoreDoPromise({
139
+ * schema,
140
+ * storeId: 'my-store',
141
+ * clientId: this.ctx.id.toString(),
142
+ * sessionId: 'do-session',
143
+ * durableObject: { ctx: this.ctx, env: this.env, bindingName: 'MY_DO' },
144
+ * syncBackendStub: this.env.SYNC_BACKEND_DO.get(syncBackendId),
145
+ * })
146
+ * // Use store...
147
+ * }
148
+ * }
149
+ * ```
150
+ */
86
151
  export const createStoreDoPromise = <
87
152
  TSchema extends LiveStoreSchema,
88
153
  TEnv,