@livestore/common 0.4.0-dev.3 → 0.4.0-dev.5
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/dist/.tsbuildinfo +1 -1
- package/dist/adapter-types.d.ts +4 -3
- package/dist/adapter-types.d.ts.map +1 -1
- package/dist/adapter-types.js.map +1 -1
- package/dist/devtools/devtools-messages-client-session.d.ts +21 -21
- package/dist/devtools/devtools-messages-common.d.ts +6 -6
- package/dist/devtools/devtools-messages-leader.d.ts +24 -24
- package/dist/errors.d.ts +15 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -2
- package/dist/errors.js.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.d.ts +4 -3
- package/dist/leader-thread/LeaderSyncProcessor.d.ts.map +1 -1
- package/dist/leader-thread/LeaderSyncProcessor.js +43 -24
- package/dist/leader-thread/LeaderSyncProcessor.js.map +1 -1
- package/dist/leader-thread/eventlog.d.ts +4 -10
- package/dist/leader-thread/eventlog.d.ts.map +1 -1
- package/dist/leader-thread/eventlog.js +3 -5
- package/dist/leader-thread/eventlog.js.map +1 -1
- package/dist/leader-thread/leader-worker-devtools.d.ts +1 -1
- package/dist/leader-thread/leader-worker-devtools.js +1 -1
- package/dist/leader-thread/leader-worker-devtools.js.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.d.ts +1 -2
- package/dist/leader-thread/make-leader-thread-layer.d.ts.map +1 -1
- package/dist/leader-thread/make-leader-thread-layer.js +34 -15
- package/dist/leader-thread/make-leader-thread-layer.js.map +1 -1
- package/dist/leader-thread/materialize-event.d.ts +2 -2
- package/dist/leader-thread/materialize-event.d.ts.map +1 -1
- package/dist/leader-thread/materialize-event.js +4 -6
- package/dist/leader-thread/materialize-event.js.map +1 -1
- package/dist/leader-thread/recreate-db.d.ts +2 -3
- package/dist/leader-thread/recreate-db.d.ts.map +1 -1
- package/dist/leader-thread/recreate-db.js +1 -1
- package/dist/leader-thread/recreate-db.js.map +1 -1
- package/dist/leader-thread/shutdown-channel.d.ts +2 -2
- package/dist/leader-thread/shutdown-channel.d.ts.map +1 -1
- package/dist/leader-thread/shutdown-channel.js +2 -2
- package/dist/leader-thread/shutdown-channel.js.map +1 -1
- package/dist/leader-thread/types.d.ts +5 -5
- package/dist/leader-thread/types.d.ts.map +1 -1
- package/dist/materializer-helper.d.ts.map +1 -1
- package/dist/materializer-helper.js +8 -2
- package/dist/materializer-helper.js.map +1 -1
- package/dist/rematerialize-from-eventlog.d.ts +1 -1
- package/dist/rematerialize-from-eventlog.d.ts.map +1 -1
- package/dist/schema/EventDef.d.ts +3 -0
- package/dist/schema/EventDef.d.ts.map +1 -1
- package/dist/schema/EventDef.js.map +1 -1
- package/dist/schema/LiveStoreEvent.d.ts.map +1 -1
- package/dist/schema/LiveStoreEvent.js +1 -2
- package/dist/schema/LiveStoreEvent.js.map +1 -1
- package/dist/schema/schema.js +1 -1
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.d.ts +30 -2
- package/dist/schema/state/sqlite/client-document-def.d.ts.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.js +93 -2
- package/dist/schema/state/sqlite/client-document-def.js.map +1 -1
- package/dist/schema/state/sqlite/client-document-def.test.js +3 -2
- package/dist/schema/state/sqlite/client-document-def.test.js.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts +2 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.d.ts.map +1 -1
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js +21 -3
- package/dist/schema/state/sqlite/db-schema/ast/sqlite.js.map +1 -1
- package/dist/schema/state/sqlite/mod.d.ts +1 -1
- package/dist/schema/state/sqlite/mod.d.ts.map +1 -1
- package/dist/schema/state/sqlite/mod.js +1 -1
- package/dist/schema/state/sqlite/mod.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.d.ts.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.js +6 -2
- package/dist/schema/state/sqlite/query-builder/impl.js.map +1 -1
- package/dist/schema/state/sqlite/query-builder/impl.test.js +54 -0
- package/dist/schema/state/sqlite/query-builder/impl.test.js.map +1 -1
- package/dist/schema/state/sqlite/system-tables.d.ts +36 -0
- package/dist/schema/state/sqlite/system-tables.d.ts.map +1 -1
- package/dist/schema/state/sqlite/system-tables.js +2 -0
- package/dist/schema/state/sqlite/system-tables.js.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.d.ts +6 -9
- package/dist/sync/ClientSessionSyncProcessor.d.ts.map +1 -1
- package/dist/sync/ClientSessionSyncProcessor.js +17 -17
- package/dist/sync/ClientSessionSyncProcessor.js.map +1 -1
- package/dist/sync/errors.d.ts +61 -0
- package/dist/sync/errors.d.ts.map +1 -0
- package/dist/sync/errors.js +36 -0
- package/dist/sync/errors.js.map +1 -0
- package/dist/sync/index.d.ts +1 -0
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +1 -0
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/mock-sync-backend.d.ts +14 -0
- package/dist/sync/mock-sync-backend.d.ts.map +1 -0
- package/dist/sync/mock-sync-backend.js +62 -0
- package/dist/sync/mock-sync-backend.js.map +1 -0
- package/dist/sync/next/history-dag.d.ts.map +1 -1
- package/dist/sync/next/history-dag.js +3 -1
- package/dist/sync/next/history-dag.js.map +1 -1
- package/dist/sync/sync-backend-kv.d.ts +7 -0
- package/dist/sync/sync-backend-kv.d.ts.map +1 -0
- package/dist/sync/sync-backend-kv.js +18 -0
- package/dist/sync/sync-backend-kv.js.map +1 -0
- package/dist/sync/sync-backend.d.ts +85 -0
- package/dist/sync/sync-backend.d.ts.map +1 -0
- package/dist/sync/sync-backend.js +24 -0
- package/dist/sync/sync-backend.js.map +1 -0
- package/dist/sync/sync.d.ts +6 -84
- package/dist/sync/sync.d.ts.map +1 -1
- package/dist/sync/sync.js +2 -27
- package/dist/sync/sync.js.map +1 -1
- package/dist/sync/validate-push-payload.d.ts +1 -1
- package/dist/sync/validate-push-payload.d.ts.map +1 -1
- package/dist/sync/validate-push-payload.js +6 -6
- package/dist/sync/validate-push-payload.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/package.json +4 -4
- package/src/adapter-types.ts +8 -3
- package/src/errors.ts +14 -3
- package/src/leader-thread/LeaderSyncProcessor.ts +79 -30
- package/src/leader-thread/eventlog.ts +9 -5
- package/src/leader-thread/leader-worker-devtools.ts +1 -1
- package/src/leader-thread/make-leader-thread-layer.ts +64 -22
- package/src/leader-thread/materialize-event.ts +5 -6
- package/src/leader-thread/recreate-db.ts +11 -3
- package/src/leader-thread/shutdown-channel.ts +16 -2
- package/src/leader-thread/types.ts +5 -5
- package/src/materializer-helper.ts +9 -3
- package/src/schema/EventDef.ts +3 -0
- package/src/schema/LiveStoreEvent.ts +1 -2
- package/src/schema/schema.ts +1 -1
- package/src/schema/state/sqlite/client-document-def.test.ts +3 -2
- package/src/schema/state/sqlite/client-document-def.ts +108 -2
- package/src/schema/state/sqlite/db-schema/ast/sqlite.ts +24 -3
- package/src/schema/state/sqlite/mod.ts +1 -0
- package/src/schema/state/sqlite/query-builder/impl.test.ts +64 -0
- package/src/schema/state/sqlite/query-builder/impl.ts +8 -2
- package/src/schema/state/sqlite/system-tables.ts +2 -0
- package/src/sync/ClientSessionSyncProcessor.ts +32 -32
- package/src/sync/errors.ts +38 -0
- package/src/sync/index.ts +1 -0
- package/src/sync/mock-sync-backend.ts +96 -0
- package/src/sync/next/history-dag.ts +3 -1
- package/src/sync/sync-backend-kv.ts +22 -0
- package/src/sync/sync-backend.ts +137 -0
- package/src/sync/sync.ts +6 -89
- package/src/sync/validate-push-payload.ts +6 -7
- package/src/version.ts +2 -2
@@ -0,0 +1,85 @@
|
|
1
|
+
import { type Cause, type Effect, type HttpClient, type KeyValueStore, Option, Schema, type Scope, type Stream, type SubscriptionRef } from '@livestore/utils/effect';
|
2
|
+
import type { UnexpectedError } from '../adapter-types.ts';
|
3
|
+
import type * as LiveStoreEvent from '../schema/LiveStoreEvent.ts';
|
4
|
+
import type { EventSequenceNumber } from '../schema/mod.ts';
|
5
|
+
import type { InvalidPullError, InvalidPushError, IsOfflineError } from './errors.ts';
|
6
|
+
export * from './sync-backend-kv.ts';
|
7
|
+
/**
|
8
|
+
* Those arguments can be used to implement multi-tenancy etc and are passed in from the store.
|
9
|
+
*/
|
10
|
+
export type MakeBackendArgs = {
|
11
|
+
storeId: string;
|
12
|
+
clientId: string;
|
13
|
+
payload: Schema.JsonValue | undefined;
|
14
|
+
};
|
15
|
+
export type SyncBackendConstructor<TSyncMetadata = Schema.JsonValue> = (args: MakeBackendArgs) => Effect.Effect<SyncBackend<TSyncMetadata>, UnexpectedError, Scope.Scope | HttpClient.HttpClient | KeyValueStore.KeyValueStore>;
|
16
|
+
export type SyncBackend<TSyncMetadata = Schema.JsonValue> = {
|
17
|
+
/**
|
18
|
+
* Can be implemented to prepare a connection to the sync backend to speed up the first pull/push.
|
19
|
+
*/
|
20
|
+
connect: Effect.Effect<void, IsOfflineError | UnexpectedError, Scope.Scope>;
|
21
|
+
pull: (cursor: Option.Option<{
|
22
|
+
eventSequenceNumber: EventSequenceNumber.GlobalEventSequenceNumber;
|
23
|
+
/** Metadata is needed by some sync backends */
|
24
|
+
metadata: Option.Option<TSyncMetadata>;
|
25
|
+
}>, options?: {
|
26
|
+
/**
|
27
|
+
* If true, the sync backend will return a stream of events that have been pushed after the cursor.
|
28
|
+
*
|
29
|
+
* @default false
|
30
|
+
*/
|
31
|
+
live?: boolean;
|
32
|
+
}) => Stream.Stream<PullResItem<TSyncMetadata>, IsOfflineError | InvalidPullError>;
|
33
|
+
push: (
|
34
|
+
/**
|
35
|
+
* Constraints for batch:
|
36
|
+
* - Number of events: 1-100
|
37
|
+
* - sequence numbers must be in ascending order
|
38
|
+
* */
|
39
|
+
batch: ReadonlyArray<LiveStoreEvent.AnyEncodedGlobal>) => Effect.Effect<void, IsOfflineError | InvalidPushError>;
|
40
|
+
ping: Effect.Effect<void, IsOfflineError | UnexpectedError | Cause.TimeoutException>;
|
41
|
+
isConnected: SubscriptionRef.SubscriptionRef<boolean>;
|
42
|
+
/**
|
43
|
+
* Metadata describing the sync backend. (Currently only used by devtools.)
|
44
|
+
*/
|
45
|
+
metadata: {
|
46
|
+
name: string;
|
47
|
+
description: string;
|
48
|
+
} & Record<string, Schema.JsonValue>;
|
49
|
+
/** Information about the sync backend capabilities. */
|
50
|
+
supports: {
|
51
|
+
/**
|
52
|
+
* Whether the sync backend supports the `hasMore` field in the pull response.
|
53
|
+
*/
|
54
|
+
pullPageInfoKnown: boolean;
|
55
|
+
/**
|
56
|
+
* Whether the sync backend supports the `live` option for the pull method and thus
|
57
|
+
* long-lived, reactive pull streams.
|
58
|
+
*/
|
59
|
+
pullLive: boolean;
|
60
|
+
};
|
61
|
+
};
|
62
|
+
export declare const PullResPageInfo: Schema.Union<[Schema.TaggedStruct<"MoreUnknown", {}>, Schema.TaggedStruct<"MoreKnown", {
|
63
|
+
remaining: typeof Schema.Number;
|
64
|
+
}>, Schema.TaggedStruct<"NoMore", {}>]>;
|
65
|
+
export type PullResPageInfo = typeof PullResPageInfo.Type;
|
66
|
+
export declare const pageInfoNoMore: PullResPageInfo;
|
67
|
+
export declare const pageInfoMoreUnknown: PullResPageInfo;
|
68
|
+
export declare const pageInfoMoreKnown: (remaining: number) => PullResPageInfo;
|
69
|
+
export declare const pullResItemEmpty: <TSyncMetadata = Schema.JsonValue>() => PullResItem<TSyncMetadata>;
|
70
|
+
export interface PullResItem<TSyncMetadata = Schema.JsonValue> {
|
71
|
+
batch: ReadonlyArray<{
|
72
|
+
eventEncoded: LiveStoreEvent.AnyEncodedGlobal;
|
73
|
+
metadata: Option.Option<TSyncMetadata>;
|
74
|
+
}>;
|
75
|
+
pageInfo: PullResPageInfo;
|
76
|
+
}
|
77
|
+
export declare const of: <TSyncMetadata = Schema.JsonValue>(obj: SyncBackend<TSyncMetadata>) => SyncBackend<TSyncMetadata>;
|
78
|
+
/**
|
79
|
+
* Useful to continue pulling from the last event in the batch.
|
80
|
+
*/
|
81
|
+
export declare const cursorFromPullResItem: <TSyncMetadata = Schema.JsonValue>(item: PullResItem<TSyncMetadata>) => Option.Option<{
|
82
|
+
eventSequenceNumber: EventSequenceNumber.GlobalEventSequenceNumber;
|
83
|
+
metadata: Option.Option<TSyncMetadata>;
|
84
|
+
}>;
|
85
|
+
//# sourceMappingURL=sync-backend.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sync-backend.d.ts","sourceRoot":"","sources":["../../src/sync/sync-backend.ts"],"names":[],"mappings":"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"}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Option, Schema, } from '@livestore/utils/effect';
|
2
|
+
export * from "./sync-backend-kv.js";
|
3
|
+
export const PullResPageInfo = Schema.Union(Schema.TaggedStruct('MoreUnknown', {}), Schema.TaggedStruct('MoreKnown', {
|
4
|
+
remaining: Schema.Number,
|
5
|
+
}), Schema.TaggedStruct('NoMore', {}));
|
6
|
+
export const pageInfoNoMore = { _tag: 'NoMore' };
|
7
|
+
export const pageInfoMoreUnknown = { _tag: 'MoreUnknown' };
|
8
|
+
export const pageInfoMoreKnown = (remaining) => ({ _tag: 'MoreKnown', remaining });
|
9
|
+
export const pullResItemEmpty = () => ({
|
10
|
+
batch: [],
|
11
|
+
pageInfo: pageInfoNoMore,
|
12
|
+
});
|
13
|
+
export const of = (obj) => obj;
|
14
|
+
/**
|
15
|
+
* Useful to continue pulling from the last event in the batch.
|
16
|
+
*/
|
17
|
+
export const cursorFromPullResItem = (item) => {
|
18
|
+
const lastEvent = item.batch.at(-1);
|
19
|
+
if (!lastEvent) {
|
20
|
+
return Option.none();
|
21
|
+
}
|
22
|
+
return Option.some({ eventSequenceNumber: lastEvent.eventEncoded.seqNum, metadata: lastEvent.metadata });
|
23
|
+
};
|
24
|
+
//# sourceMappingURL=sync-backend.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"sync-backend.js","sourceRoot":"","sources":["../../src/sync/sync-backend.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,MAAM,EACN,MAAM,GAIP,MAAM,yBAAyB,CAAA;AAMhC,cAAc,sBAAsB,CAAA;AA6EpC,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CACzC,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,EAAE,CAAC,EACtC,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE;IAC/B,SAAS,EAAE,MAAM,CAAC,MAAM;CACzB,CAAC,EACF,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAClC,CAAA;AAID,MAAM,CAAC,MAAM,cAAc,GAAoB,EAAE,IAAI,EAAE,QAAQ,EAAW,CAAA;AAC1E,MAAM,CAAC,MAAM,mBAAmB,GAAoB,EAAE,IAAI,EAAE,aAAa,EAAW,CAAA;AACpF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAAiB,EAAmB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAA;AAE3G,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAiE,EAAE,CAAC,CAAC;IACnG,KAAK,EAAE,EAAE;IACT,QAAQ,EAAE,cAAc;CACzB,CAAC,CAAA;AAUF,MAAM,CAAC,MAAM,EAAE,GAAG,CAAmC,GAA+B,EAAE,EAAE,CAAC,GAAG,CAAA;AAE5F;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,IAAgC,EAI/B,EAAE;IACH,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IACnC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;IACtB,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,mBAAmB,EAAE,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAA;AAC1G,CAAC,CAAA"}
|
package/dist/sync/sync.d.ts
CHANGED
@@ -1,17 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import type { UnexpectedError } from '../adapter-types.ts';
|
1
|
+
export * from './errors.ts';
|
2
|
+
export * as SyncBackend from './sync-backend.ts';
|
4
3
|
import type { InitialSyncOptions } from '../leader-thread/types.ts';
|
5
|
-
import
|
6
|
-
import type * as LiveStoreEvent from '../schema/LiveStoreEvent.ts';
|
7
|
-
/**
|
8
|
-
* Those arguments can be used to implement multi-tenancy etc and are passed in from the store.
|
9
|
-
*/
|
10
|
-
export type MakeBackendArgs = {
|
11
|
-
storeId: string;
|
12
|
-
clientId: string;
|
13
|
-
payload: Schema.JsonValue | undefined;
|
14
|
-
};
|
4
|
+
import type { SyncBackendConstructor } from './sync-backend.ts';
|
15
5
|
export type SyncOptions = {
|
16
6
|
backend?: SyncBackendConstructor<any>;
|
17
7
|
/** @default { _tag: 'Skip' } */
|
@@ -26,78 +16,10 @@ export type SyncOptions = {
|
|
26
16
|
* @default 'ignore'
|
27
17
|
* */
|
28
18
|
onSyncError?: 'shutdown' | 'ignore';
|
29
|
-
};
|
30
|
-
export type SyncBackendConstructor<TSyncMetadata = Schema.JsonValue> = (args: MakeBackendArgs) => Effect.Effect<SyncBackend<TSyncMetadata>, UnexpectedError, Scope.Scope | HttpClient.HttpClient>;
|
31
|
-
export type SyncBackend<TSyncMetadata = Schema.JsonValue> = {
|
32
|
-
/**
|
33
|
-
* Can be implemented to prepare a connection to the sync backend to speed up the first pull/push.
|
34
|
-
*/
|
35
|
-
connect: Effect.Effect<void, IsOfflineError | UnexpectedError, HttpClient.HttpClient | Scope.Scope>;
|
36
|
-
pull: (args: Option.Option<{
|
37
|
-
cursor: EventSequenceNumber.EventSequenceNumber;
|
38
|
-
metadata: Option.Option<TSyncMetadata>;
|
39
|
-
}>) => Stream.Stream<{
|
40
|
-
batch: ReadonlyArray<{
|
41
|
-
eventEncoded: LiveStoreEvent.AnyEncodedGlobal;
|
42
|
-
metadata: Option.Option<TSyncMetadata>;
|
43
|
-
}>;
|
44
|
-
remaining: number;
|
45
|
-
}, IsOfflineError | InvalidPullError, HttpClient.HttpClient>;
|
46
|
-
push: (
|
47
|
-
/**
|
48
|
-
* Constraints for batch:
|
49
|
-
* - Number of events: 1-100
|
50
|
-
* - sequence numbers must be in ascending order
|
51
|
-
* */
|
52
|
-
batch: ReadonlyArray<LiveStoreEvent.AnyEncodedGlobal>) => Effect.Effect<void, IsOfflineError | InvalidPushError, HttpClient.HttpClient>;
|
53
|
-
isConnected: SubscriptionRef.SubscriptionRef<boolean>;
|
54
19
|
/**
|
55
|
-
*
|
20
|
+
* Whether the sync backend should reactively pull new events from the sync backend
|
21
|
+
* @default true
|
56
22
|
*/
|
57
|
-
|
58
|
-
name: string;
|
59
|
-
description: string;
|
60
|
-
} & Record<string, Schema.JsonValue>;
|
23
|
+
livePull?: boolean;
|
61
24
|
};
|
62
|
-
declare const IsOfflineError_base: Schema.TaggedErrorClass<IsOfflineError, "IsOfflineError", {
|
63
|
-
readonly _tag: Schema.tag<"IsOfflineError">;
|
64
|
-
}>;
|
65
|
-
export declare class IsOfflineError extends IsOfflineError_base {
|
66
|
-
}
|
67
|
-
declare const InvalidPushError_base: Schema.TaggedErrorClass<InvalidPushError, "InvalidPushError", {
|
68
|
-
readonly _tag: Schema.tag<"InvalidPushError">;
|
69
|
-
} & {
|
70
|
-
reason: Schema.Union<[Schema.TaggedStruct<"Unexpected", {
|
71
|
-
message: typeof Schema.String;
|
72
|
-
}>, Schema.TaggedStruct<"ServerAhead", {
|
73
|
-
minimumExpectedNum: typeof Schema.Number;
|
74
|
-
providedNum: typeof Schema.Number;
|
75
|
-
}>]>;
|
76
|
-
}>;
|
77
|
-
export declare class InvalidPushError extends InvalidPushError_base {
|
78
|
-
}
|
79
|
-
declare const InvalidPullError_base: Schema.TaggedErrorClass<InvalidPullError, "InvalidPullError", {
|
80
|
-
readonly _tag: Schema.tag<"InvalidPullError">;
|
81
|
-
} & {
|
82
|
-
message: typeof Schema.String;
|
83
|
-
}>;
|
84
|
-
export declare class InvalidPullError extends InvalidPullError_base {
|
85
|
-
}
|
86
|
-
declare const LeaderAheadError_base: Schema.TaggedErrorClass<LeaderAheadError, "LeaderAheadError", {
|
87
|
-
readonly _tag: Schema.tag<"LeaderAheadError">;
|
88
|
-
} & {
|
89
|
-
minimumExpectedNum: Schema.Struct<{
|
90
|
-
global: Schema.BrandSchema<number & import("effect/Brand").Brand<"GlobalEventSequenceNumber">, number, never>;
|
91
|
-
client: Schema.BrandSchema<number & import("effect/Brand").Brand<"ClientEventSequenceNumber">, number, never>;
|
92
|
-
rebaseGeneration: typeof Schema.Int;
|
93
|
-
}>;
|
94
|
-
providedNum: Schema.Struct<{
|
95
|
-
global: Schema.BrandSchema<number & import("effect/Brand").Brand<"GlobalEventSequenceNumber">, number, never>;
|
96
|
-
client: Schema.BrandSchema<number & import("effect/Brand").Brand<"ClientEventSequenceNumber">, number, never>;
|
97
|
-
rebaseGeneration: typeof Schema.Int;
|
98
|
-
}>;
|
99
|
-
}>;
|
100
|
-
export declare class LeaderAheadError extends LeaderAheadError_base {
|
101
|
-
}
|
102
|
-
export {};
|
103
25
|
//# sourceMappingURL=sync.d.ts.map
|
package/dist/sync/sync.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA;AAEhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAA;AAE/D,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,EAAE,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACrC,gCAAgC;IAChC,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;IACvC;;;;;;;;SAQK;IACL,WAAW,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAA;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA"}
|
package/dist/sync/sync.js
CHANGED
@@ -1,28 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
export class IsOfflineError extends Schema.TaggedError()('IsOfflineError', {}) {
|
4
|
-
}
|
5
|
-
// TODO gt rid of this error in favour of SyncError
|
6
|
-
export class InvalidPushError extends Schema.TaggedError()('InvalidPushError', {
|
7
|
-
reason: Schema.Union(Schema.TaggedStruct('Unexpected', {
|
8
|
-
message: Schema.String,
|
9
|
-
}), Schema.TaggedStruct('ServerAhead', {
|
10
|
-
minimumExpectedNum: Schema.Number,
|
11
|
-
providedNum: Schema.Number,
|
12
|
-
})),
|
13
|
-
}) {
|
14
|
-
}
|
15
|
-
// TODO gt rid of this error in favour of SyncError
|
16
|
-
export class InvalidPullError extends Schema.TaggedError()('InvalidPullError', {
|
17
|
-
message: Schema.String,
|
18
|
-
}) {
|
19
|
-
}
|
20
|
-
// TODO gt rid of this error in favour of SyncError
|
21
|
-
export class LeaderAheadError extends Schema.TaggedError()('LeaderAheadError', {
|
22
|
-
minimumExpectedNum: EventSequenceNumber.EventSequenceNumber,
|
23
|
-
providedNum: EventSequenceNumber.EventSequenceNumber,
|
24
|
-
/** Generation number the client session should use for subsequent pushes */
|
25
|
-
// nextGeneration: Schema.Number,
|
26
|
-
}) {
|
27
|
-
}
|
1
|
+
export * from "./errors.js";
|
2
|
+
export * as SyncBackend from "./sync-backend.js";
|
28
3
|
//# sourceMappingURL=sync.js.map
|
package/dist/sync/sync.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync/sync.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,OAAO,KAAK,WAAW,MAAM,mBAAmB,CAAA"}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Effect } from '@livestore/utils/effect';
|
2
|
-
import
|
2
|
+
import { EventSequenceNumber, type LiveStoreEvent } from '../schema/mod.ts';
|
3
3
|
import { InvalidPushError } from './sync.ts';
|
4
4
|
export declare const validatePushPayload: (batch: ReadonlyArray<LiveStoreEvent.AnyEncodedGlobal>, currentEventSequenceNumber: EventSequenceNumber.GlobalEventSequenceNumber) => Effect.Effect<undefined, InvalidPushError, never>;
|
5
5
|
//# sourceMappingURL=validate-push-payload.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validate-push-payload.d.ts","sourceRoot":"","sources":["../../src/sync/validate-push-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,
|
1
|
+
{"version":3,"file":"validate-push-payload.d.ts","sourceRoot":"","sources":["../../src/sync/validate-push-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAE,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAoB,MAAM,WAAW,CAAA;AAG9D,eAAO,MAAM,mBAAmB,GAC9B,OAAO,aAAa,CAAC,cAAc,CAAC,gBAAgB,CAAC,EACrD,4BAA4B,mBAAmB,CAAC,yBAAyB,sDAWvE,CAAA"}
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { Effect } from '@livestore/utils/effect';
|
2
|
-
import {
|
2
|
+
import { EventSequenceNumber } from "../schema/mod.js";
|
3
|
+
import { InvalidPushError, ServerAheadError } from "./sync.js";
|
3
4
|
// TODO proper batch validation
|
4
5
|
export const validatePushPayload = (batch, currentEventSequenceNumber) => Effect.gen(function* () {
|
5
6
|
if (batch[0].seqNum <= currentEventSequenceNumber) {
|
6
7
|
return yield* InvalidPushError.make({
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
},
|
8
|
+
cause: new ServerAheadError({
|
9
|
+
minimumExpectedNum: EventSequenceNumber.globalEventSequenceNumber(currentEventSequenceNumber + 1),
|
10
|
+
providedNum: EventSequenceNumber.globalEventSequenceNumber(batch[0].seqNum),
|
11
|
+
}),
|
12
12
|
});
|
13
13
|
}
|
14
14
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"validate-push-payload.js","sourceRoot":"","sources":["../../src/sync/validate-push-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;
|
1
|
+
{"version":3,"file":"validate-push-payload.js","sourceRoot":"","sources":["../../src/sync/validate-push-payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAAuB,MAAM,kBAAkB,CAAA;AAC3E,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE9D,+BAA+B;AAC/B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAqD,EACrD,0BAAyE,EACzE,EAAE,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,IAAI,KAAK,CAAC,CAAC,CAAE,CAAC,MAAM,IAAI,0BAA0B,EAAE,CAAC;QACnD,OAAO,KAAK,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC;YAClC,KAAK,EAAE,IAAI,gBAAgB,CAAC;gBAC1B,kBAAkB,EAAE,mBAAmB,CAAC,yBAAyB,CAAC,0BAA0B,GAAG,CAAC,CAAC;gBACjG,WAAW,EAAE,mBAAmB,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,MAAM,CAAC;aAC7E,CAAC;SACH,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAC,CAAA"}
|
package/dist/version.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export declare const liveStoreVersion: "0.4.0-dev.
|
1
|
+
export declare const liveStoreVersion: "0.4.0-dev.5";
|
2
2
|
/**
|
3
3
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|
4
4
|
* Whenever this version changes, LiveStore will start with fresh database files. Old database files are not deleted.
|
@@ -6,5 +6,5 @@ export declare const liveStoreVersion: "0.4.0-dev.3";
|
|
6
6
|
* While LiveStore is in beta, this might happen more frequently.
|
7
7
|
* In the future, LiveStore will provide a migration path for older database files to avoid the impression of data loss.
|
8
8
|
*/
|
9
|
-
export declare const liveStoreStorageFormatVersion =
|
9
|
+
export declare const liveStoreStorageFormatVersion = 6;
|
10
10
|
//# sourceMappingURL=version.d.ts.map
|
package/dist/version.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// TODO bring back when Expo and Playwright supports `with` imports
|
2
2
|
// import packageJson from '../package.json' with { type: 'json' }
|
3
3
|
// export const liveStoreVersion = packageJson.version
|
4
|
-
export const liveStoreVersion = '0.4.0-dev.
|
4
|
+
export const liveStoreVersion = '0.4.0-dev.5';
|
5
5
|
/**
|
6
6
|
* This version number is incremented whenever the internal storage format changes in a breaking way.
|
7
7
|
* Whenever this version changes, LiveStore will start with fresh database files. Old database files are not deleted.
|
@@ -9,5 +9,5 @@ export const liveStoreVersion = '0.4.0-dev.3';
|
|
9
9
|
* While LiveStore is in beta, this might happen more frequently.
|
10
10
|
* In the future, LiveStore will provide a migration path for older database files to avoid the impression of data loss.
|
11
11
|
*/
|
12
|
-
export const liveStoreStorageFormatVersion =
|
12
|
+
export const liveStoreStorageFormatVersion = 6;
|
13
13
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@livestore/common",
|
3
|
-
"version": "0.4.0-dev.
|
3
|
+
"version": "0.4.0-dev.5",
|
4
4
|
"type": "module",
|
5
5
|
"sideEffects": false,
|
6
6
|
"exports": {
|
@@ -16,12 +16,12 @@
|
|
16
16
|
"graphology": "0.26.0-alpha1",
|
17
17
|
"graphology-dag": "0.4.1",
|
18
18
|
"graphology-types": "0.24.8",
|
19
|
-
"@livestore/utils": "0.4.0-dev.
|
20
|
-
"@livestore/webmesh": "0.4.0-dev.
|
19
|
+
"@livestore/utils": "0.4.0-dev.5",
|
20
|
+
"@livestore/webmesh": "0.4.0-dev.5"
|
21
21
|
},
|
22
22
|
"devDependencies": {
|
23
23
|
"vitest": "3.2.4",
|
24
|
-
"@livestore/utils-dev": "0.4.0-dev.
|
24
|
+
"@livestore/utils-dev": "0.4.0-dev.5"
|
25
25
|
},
|
26
26
|
"files": [
|
27
27
|
"package.json",
|
package/src/adapter-types.ts
CHANGED
@@ -10,9 +10,10 @@ import {
|
|
10
10
|
|
11
11
|
import type { ClientSessionLeaderThreadProxy } from './ClientSessionLeaderThreadProxy.ts'
|
12
12
|
import type * as Devtools from './devtools/mod.ts'
|
13
|
-
import type { IntentionalShutdownCause,
|
13
|
+
import type { IntentionalShutdownCause, MaterializeError, UnexpectedError } from './errors.ts'
|
14
14
|
import type { LiveStoreSchema } from './schema/mod.ts'
|
15
15
|
import type { SqliteDb } from './sqlite-types.ts'
|
16
|
+
import type { IsOfflineError, SyncError } from './sync/index.js'
|
16
17
|
|
17
18
|
export * as ClientSessionLeaderThreadProxy from './ClientSessionLeaderThreadProxy.ts'
|
18
19
|
export * from './defs.ts'
|
@@ -27,7 +28,9 @@ export interface ClientSession {
|
|
27
28
|
sessionId: string
|
28
29
|
/** Status info whether current session is leader or not */
|
29
30
|
lockStatus: SubscriptionRef.SubscriptionRef<LockStatus>
|
30
|
-
shutdown: (
|
31
|
+
shutdown: (
|
32
|
+
cause: Exit.Exit<IntentionalShutdownCause, UnexpectedError | SyncError | MaterializeError>,
|
33
|
+
) => Effect.Effect<void>
|
31
34
|
/** A proxy API to communicate with the leader thread */
|
32
35
|
leaderThread: ClientSessionLeaderThreadProxy
|
33
36
|
/** A unique identifier for the current instance of the client session. Used for debugging purposes. */
|
@@ -121,7 +124,9 @@ export interface AdapterArgs {
|
|
121
124
|
devtoolsEnabled: boolean
|
122
125
|
debugInstanceId: string
|
123
126
|
bootStatusQueue: Queue.Queue<BootStatus>
|
124
|
-
shutdown: (
|
127
|
+
shutdown: (
|
128
|
+
exit: Exit.Exit<IntentionalShutdownCause, UnexpectedError | SyncError | MaterializeError | IsOfflineError>,
|
129
|
+
) => Effect.Effect<void>
|
125
130
|
connectDevtoolsToStore: ConnectDevtoolsToStore
|
126
131
|
/**
|
127
132
|
* Payload that will be passed to the sync backend when connecting
|
package/src/errors.ts
CHANGED
@@ -17,9 +17,15 @@ export class UnexpectedError extends Schema.TaggedError<UnexpectedError>()('Live
|
|
17
17
|
)
|
18
18
|
}
|
19
19
|
|
20
|
-
export class
|
21
|
-
|
22
|
-
|
20
|
+
export class MaterializerHashMismatchError extends Schema.TaggedError<MaterializerHashMismatchError>()(
|
21
|
+
'LiveStore.MaterializerHashMismatchError',
|
22
|
+
{
|
23
|
+
eventName: Schema.String,
|
24
|
+
note: Schema.optionalWith(Schema.String, {
|
25
|
+
default: () => 'Please make sure your event materializer is a pure function without side effects.',
|
26
|
+
}),
|
27
|
+
},
|
28
|
+
) {}
|
23
29
|
|
24
30
|
export class IntentionalShutdownCause extends Schema.TaggedError<IntentionalShutdownCause>()(
|
25
31
|
'LiveStore.IntentionalShutdownCause',
|
@@ -47,3 +53,8 @@ export class SqliteError extends Schema.TaggedError<SqliteError>()('LiveStore.Sq
|
|
47
53
|
cause: Schema.Defect,
|
48
54
|
note: Schema.optional(Schema.String),
|
49
55
|
}) {}
|
56
|
+
|
57
|
+
export class MaterializeError extends Schema.TaggedError<MaterializeError>()('LiveStore.MaterializeError', {
|
58
|
+
cause: Schema.Union(MaterializerHashMismatchError, SqliteError),
|
59
|
+
note: Schema.optional(Schema.String),
|
60
|
+
}) {}
|