@livestore/sync-electric 0.4.0-dev.1 → 0.4.0-dev.10
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/api-schema.d.ts +13 -0
- package/dist/api-schema.d.ts.map +1 -1
- package/dist/api-schema.js +3 -0
- package/dist/api-schema.js.map +1 -1
- package/dist/index.d.ts +30 -40
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +111 -90
- package/dist/index.js.map +1 -1
- package/dist/make-electric-url.d.ts +42 -0
- package/dist/make-electric-url.d.ts.map +1 -0
- package/dist/make-electric-url.js +60 -0
- package/dist/make-electric-url.js.map +1 -0
- package/package.json +3 -3
- package/src/api-schema.ts +4 -0
- package/src/index.ts +179 -160
- package/src/make-electric-url.ts +110 -0
package/dist/api-schema.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export declare const PullPayload: Schema.Struct<{
|
|
|
21
21
|
offset: typeof Schema.String;
|
|
22
22
|
handle: typeof Schema.String;
|
|
23
23
|
}>>;
|
|
24
|
+
live: typeof Schema.Boolean;
|
|
24
25
|
}>;
|
|
25
26
|
export declare const ApiPayload: Schema.Union<[Schema.Struct<{
|
|
26
27
|
_tag: Schema.tag<"@livestore/sync-electric.Pull">;
|
|
@@ -31,6 +32,7 @@ export declare const ApiPayload: Schema.Union<[Schema.Struct<{
|
|
|
31
32
|
offset: typeof Schema.String;
|
|
32
33
|
handle: typeof Schema.String;
|
|
33
34
|
}>>;
|
|
35
|
+
live: typeof Schema.Boolean;
|
|
34
36
|
}>, Schema.Struct<{
|
|
35
37
|
_tag: Schema.tag<"@livestore/sync-electric.Push">;
|
|
36
38
|
} & {
|
|
@@ -44,4 +46,15 @@ export declare const ApiPayload: Schema.Union<[Schema.Struct<{
|
|
|
44
46
|
sessionId: typeof Schema.String;
|
|
45
47
|
}>>;
|
|
46
48
|
}>]>;
|
|
49
|
+
export declare const ArgsSchema: Schema.transform<Schema.transformOrFail<Schema.SchemaClass<string, string, never>, typeof Schema.String, never>, Schema.transform<Schema.SchemaClass<unknown, string, never>, Schema.Struct<{
|
|
50
|
+
_tag: Schema.tag<"@livestore/sync-electric.Pull">;
|
|
51
|
+
} & {
|
|
52
|
+
storeId: typeof Schema.String;
|
|
53
|
+
payload: Schema.UndefinedOr<Schema.Schema<Schema.JsonValue, Schema.JsonValue, never>>;
|
|
54
|
+
handle: Schema.Option<Schema.Struct<{
|
|
55
|
+
offset: typeof Schema.String;
|
|
56
|
+
handle: typeof Schema.String;
|
|
57
|
+
}>>;
|
|
58
|
+
live: typeof Schema.Boolean;
|
|
59
|
+
}>>>;
|
|
47
60
|
//# sourceMappingURL=api-schema.d.ts.map
|
package/dist/api-schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-schema.d.ts","sourceRoot":"","sources":["../src/api-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,eAAO,MAAM,WAAW;;;;;;;;;;;;EAGyC,CAAA;AAEjE,eAAO,MAAM,WAAW
|
|
1
|
+
{"version":3,"file":"api-schema.d.ts","sourceRoot":"","sources":["../src/api-schema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,eAAO,MAAM,WAAW;;;;;;;;;;;;EAGyC,CAAA;AAEjE,eAAO,MAAM,WAAW;;;;;;;;;;EAUyC,CAAA;AAEjE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;IAAyC,CAAA;AAGhE,eAAO,MAAM,UAAU;;;;;;;;;;IAA+E,CAAA"}
|
package/dist/api-schema.js
CHANGED
|
@@ -11,6 +11,9 @@ export const PullPayload = Schema.TaggedStruct('@livestore/sync-electric.Pull',
|
|
|
11
11
|
offset: Schema.String,
|
|
12
12
|
handle: Schema.String,
|
|
13
13
|
})),
|
|
14
|
+
live: Schema.Boolean,
|
|
14
15
|
}).annotations({ title: '@livestore/sync-electric.PullPayload' });
|
|
15
16
|
export const ApiPayload = Schema.Union(PullPayload, PushPayload);
|
|
17
|
+
// Format for the query params
|
|
18
|
+
export const ArgsSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PullPayload));
|
|
16
19
|
//# sourceMappingURL=api-schema.js.map
|
package/dist/api-schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-schema.js","sourceRoot":"","sources":["../src/api-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,+BAA+B,EAAE;IAC9E,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;CACrD,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,sCAAsC,EAAE,CAAC,CAAA;AAEjE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,+BAA+B,EAAE;IAC9E,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CACH;
|
|
1
|
+
{"version":3,"file":"api-schema.js","sourceRoot":"","sources":["../src/api-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAEhD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,+BAA+B,EAAE;IAC9E,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC;CACrD,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,sCAAsC,EAAE,CAAC,CAAA;AAEjE,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,+BAA+B,EAAE;IAC9E,OAAO,EAAE,MAAM,CAAC,MAAM;IACtB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC,MAAM,CACnB,MAAM,CAAC,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CACH;IACD,IAAI,EAAE,MAAM,CAAC,OAAO;CACrB,CAAC,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,sCAAsC,EAAE,CAAC,CAAA;AAEjE,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAA;AAEhE,8BAA8B;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Schema } from '@livestore/utils/effect';
|
|
1
|
+
import { SyncBackend } from '@livestore/common';
|
|
2
|
+
import { type Duration, Schema } from '@livestore/utils/effect';
|
|
3
|
+
declare const InvalidOperationError_base: Schema.TaggedErrorClass<InvalidOperationError, "InvalidOperationError", {
|
|
4
|
+
readonly _tag: Schema.tag<"InvalidOperationError">;
|
|
5
|
+
} & {
|
|
6
|
+
operation: Schema.Union<[Schema.Literal<["delete"]>, Schema.Literal<["update"]>]>;
|
|
7
|
+
message: typeof Schema.String;
|
|
8
|
+
}>;
|
|
9
|
+
export declare class InvalidOperationError extends InvalidOperationError_base {
|
|
10
|
+
}
|
|
3
11
|
export * as ApiSchema from './api-schema.ts';
|
|
4
|
-
export
|
|
12
|
+
export * from './make-electric-url.ts';
|
|
5
13
|
export declare const syncBackendOptions: <TOptions extends SyncBackendOptions>(options: TOptions) => TOptions;
|
|
6
|
-
/**
|
|
7
|
-
* This function should be called in a trusted environment (e.g. a proxy server) as it
|
|
8
|
-
* requires access to senstive information (e.g. `apiSecret` / `sourceSecret`).
|
|
9
|
-
*/
|
|
10
|
-
export declare const makeElectricUrl: ({ electricHost, searchParams: providedSearchParams, sourceId, sourceSecret, apiSecret, }: {
|
|
11
|
-
electricHost: string;
|
|
12
|
-
/**
|
|
13
|
-
* Needed to extract information from the search params which the `@livestore/sync-electric`
|
|
14
|
-
* client implementation automatically adds:
|
|
15
|
-
* - `handle`: the ElectricSQL handle
|
|
16
|
-
* - `storeId`: the Livestore storeId
|
|
17
|
-
*/
|
|
18
|
-
searchParams: URLSearchParams;
|
|
19
|
-
/** Needed for Electric Cloud */
|
|
20
|
-
sourceId?: string;
|
|
21
|
-
/** Needed for Electric Cloud */
|
|
22
|
-
sourceSecret?: string;
|
|
23
|
-
/** For self-hosted ElectricSQL */
|
|
24
|
-
apiSecret?: string;
|
|
25
|
-
}) => {
|
|
26
|
-
url: string;
|
|
27
|
-
storeId: string;
|
|
28
|
-
needsInit: boolean;
|
|
29
|
-
payload: Schema.JsonValue | undefined;
|
|
30
|
-
};
|
|
31
14
|
export interface SyncBackendOptions {
|
|
32
15
|
/**
|
|
33
16
|
* The endpoint to pull/push events. Pull is a `GET` request, push is a `POST` request.
|
|
@@ -40,22 +23,29 @@ export interface SyncBackendOptions {
|
|
|
40
23
|
endpoint: string | {
|
|
41
24
|
push: string;
|
|
42
25
|
pull: string;
|
|
26
|
+
ping: string;
|
|
27
|
+
};
|
|
28
|
+
ping?: {
|
|
29
|
+
/**
|
|
30
|
+
* @default true
|
|
31
|
+
*/
|
|
32
|
+
enabled?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* How long to wait for a ping response before timing out
|
|
35
|
+
* @default 10 seconds
|
|
36
|
+
*/
|
|
37
|
+
requestTimeout?: Duration.DurationInput;
|
|
38
|
+
/**
|
|
39
|
+
* How often to send ping requests
|
|
40
|
+
* @default 10 seconds
|
|
41
|
+
*/
|
|
42
|
+
requestInterval?: Duration.DurationInput;
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
45
|
export declare const SyncMetadata: Schema.Struct<{
|
|
46
46
|
offset: typeof Schema.String;
|
|
47
47
|
handle: typeof Schema.String;
|
|
48
48
|
}>;
|
|
49
|
-
type SyncMetadata =
|
|
50
|
-
|
|
51
|
-
handle: string;
|
|
52
|
-
};
|
|
53
|
-
export declare const makeSyncBackend: ({ endpoint }: SyncBackendOptions) => SyncBackendConstructor<SyncMetadata>;
|
|
54
|
-
/**
|
|
55
|
-
* Needs to be bumped when the storage format changes (e.g. eventlogTable schema changes)
|
|
56
|
-
*
|
|
57
|
-
* Changing this version number will lead to a "soft reset".
|
|
58
|
-
*/
|
|
59
|
-
export declare const PERSISTENCE_FORMAT_VERSION = 6;
|
|
60
|
-
export declare const toTableName: (storeId: string) => string;
|
|
49
|
+
export type SyncMetadata = typeof SyncMetadata.Type;
|
|
50
|
+
export declare const makeSyncBackend: ({ endpoint, ...options }: SyncBackendOptions) => SyncBackend.SyncBackendConstructor<SyncMetadata>;
|
|
61
51
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,WAAW,EAEZ,MAAM,mBAAmB,CAAA;AAG1B,OAAO,EACL,KAAK,QAAQ,EAQb,MAAM,EAGP,MAAM,yBAAyB,CAAA;;;;;;;AAIhC,qBAAa,qBAAsB,SAAQ,0BAGzC;CAAG;AAEL,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AAuFtC,eAAO,MAAM,kBAAkB,GAAI,QAAQ,SAAS,kBAAkB,EAAE,SAAS,QAAQ,aAAY,CAAA;AAErG,MAAM,WAAW,kBAAkB;IACjC;;;;;;;OAOG;IACH,QAAQ,EACJ,MAAM,GACN;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;KACb,CAAA;IAEL,IAAI,CAAC,EAAE;QACL;;WAEG;QACH,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB;;;WAGG;QACH,cAAc,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;QACvC;;;WAGG;QACH,eAAe,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAA;KACzC,CAAA;CACF;AAED,eAAO,MAAM,YAAY;;;EAIvB,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAA;AAEnD,eAAO,MAAM,eAAe,GACzB,0BAA0B,kBAAkB,KAAG,WAAW,CAAC,sBAAsB,CAAC,YAAY,CA2M3F,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { InvalidPullError, InvalidPushError, UnexpectedError } from '@livestore/common';
|
|
1
|
+
import { InvalidPullError, InvalidPushError, SyncBackend, UnexpectedError, } from '@livestore/common';
|
|
2
2
|
import { LiveStoreEvent } from '@livestore/common/schema';
|
|
3
|
-
import { notYetImplemented
|
|
4
|
-
import {
|
|
3
|
+
import { notYetImplemented } from '@livestore/utils';
|
|
4
|
+
import { Effect, HttpClient, HttpClientRequest, HttpClientResponse, Option, ReadonlyArray, Schedule, Schema, Stream, SubscriptionRef, } from '@livestore/utils/effect';
|
|
5
5
|
import * as ApiSchema from "./api-schema.js";
|
|
6
|
+
export class InvalidOperationError extends Schema.TaggedError()('InvalidOperationError', {
|
|
7
|
+
operation: Schema.Union(Schema.Literal('delete'), Schema.Literal('update')),
|
|
8
|
+
message: Schema.String,
|
|
9
|
+
}) {
|
|
10
|
+
}
|
|
6
11
|
export * as ApiSchema from "./api-schema.js";
|
|
12
|
+
export * from "./make-electric-url.js";
|
|
7
13
|
/*
|
|
8
14
|
Example data:
|
|
9
15
|
|
|
@@ -50,83 +56,63 @@ const LiveStoreEventGlobalFromStringRecord = Schema.Struct({
|
|
|
50
56
|
args: Schema.parseJson(Schema.Any),
|
|
51
57
|
clientId: Schema.String,
|
|
52
58
|
sessionId: Schema.String,
|
|
53
|
-
})
|
|
59
|
+
})
|
|
60
|
+
.pipe(Schema.transform(LiveStoreEvent.AnyEncodedGlobal, {
|
|
54
61
|
decode: (_) => _,
|
|
55
62
|
encode: (_) => _,
|
|
56
|
-
}))
|
|
57
|
-
|
|
63
|
+
}))
|
|
64
|
+
.annotations({ title: '@livestore/sync-electric:LiveStoreEventGlobalFromStringRecord' });
|
|
65
|
+
const ResponseItemInsert = Schema.Struct({
|
|
58
66
|
/** Postgres path (e.g. `"public"."events_9069baf0_b3e6_42f7_980f_188416eab3fx3"/"0"`) */
|
|
59
67
|
key: Schema.optional(Schema.String),
|
|
60
|
-
value:
|
|
61
|
-
headers: Schema.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
})
|
|
68
|
+
value: LiveStoreEventGlobalFromStringRecord,
|
|
69
|
+
headers: Schema.Struct({ operation: Schema.Literal('insert'), relation: Schema.Array(Schema.String) }),
|
|
70
|
+
}).annotations({ title: '@livestore/sync-electric:ResponseItemInsert' });
|
|
71
|
+
const ResponseItemInvalid = Schema.Struct({
|
|
72
|
+
/** Postgres path (e.g. `"public"."events_9069baf0_b3e6_42f7_980f_188416eab3fx3"/"0"`) */
|
|
73
|
+
key: Schema.optional(Schema.String),
|
|
74
|
+
value: Schema.Any,
|
|
75
|
+
headers: Schema.Struct({ operation: Schema.Literal('update', 'delete'), relation: Schema.Array(Schema.String) }),
|
|
76
|
+
}).annotations({ title: '@livestore/sync-electric:ResponseItemInvalid' });
|
|
77
|
+
const ResponseItemControl = Schema.Struct({
|
|
78
|
+
key: Schema.optional(Schema.String),
|
|
79
|
+
value: Schema.optional(Schema.Any),
|
|
80
|
+
headers: Schema.Struct({ control: Schema.String }),
|
|
81
|
+
}).annotations({ title: '@livestore/sync-electric:ResponseItemControl' });
|
|
82
|
+
const ResponseItem = Schema.Union(ResponseItemInsert, ResponseItemInvalid, ResponseItemControl);
|
|
68
83
|
const ResponseHeaders = Schema.Struct({
|
|
69
84
|
'electric-handle': Schema.String,
|
|
70
85
|
// 'electric-schema': Schema.parseJson(Schema.Any),
|
|
71
86
|
/** e.g. 26799576_0 */
|
|
72
87
|
'electric-offset': Schema.String,
|
|
73
88
|
});
|
|
74
|
-
export const syncBackend = {};
|
|
75
89
|
export const syncBackendOptions = (options) => options;
|
|
76
|
-
/**
|
|
77
|
-
* This function should be called in a trusted environment (e.g. a proxy server) as it
|
|
78
|
-
* requires access to senstive information (e.g. `apiSecret` / `sourceSecret`).
|
|
79
|
-
*/
|
|
80
|
-
export const makeElectricUrl = ({ electricHost, searchParams: providedSearchParams, sourceId, sourceSecret, apiSecret, }) => {
|
|
81
|
-
const endpointUrl = `${electricHost}/v1/shape`;
|
|
82
|
-
const argsResult = Schema.decodeUnknownEither(Schema.Struct({ args: Schema.parseJson(ApiSchema.PullPayload) }))(Object.fromEntries(providedSearchParams.entries()));
|
|
83
|
-
if (argsResult._tag === 'Left') {
|
|
84
|
-
return shouldNeverHappen('Invalid search params provided to makeElectricUrl', providedSearchParams, Object.fromEntries(providedSearchParams.entries()));
|
|
85
|
-
}
|
|
86
|
-
const args = argsResult.right.args;
|
|
87
|
-
const tableName = toTableName(args.storeId);
|
|
88
|
-
const searchParams = new URLSearchParams();
|
|
89
|
-
searchParams.set('table', tableName);
|
|
90
|
-
if (sourceId !== undefined) {
|
|
91
|
-
searchParams.set('source_id', sourceId);
|
|
92
|
-
}
|
|
93
|
-
if (sourceSecret !== undefined) {
|
|
94
|
-
searchParams.set('source_secret', sourceSecret);
|
|
95
|
-
}
|
|
96
|
-
if (apiSecret !== undefined) {
|
|
97
|
-
searchParams.set('api_secret', apiSecret);
|
|
98
|
-
}
|
|
99
|
-
if (args.handle._tag === 'None') {
|
|
100
|
-
searchParams.set('offset', '-1');
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
searchParams.set('offset', args.handle.value.offset);
|
|
104
|
-
searchParams.set('handle', args.handle.value.handle);
|
|
105
|
-
searchParams.set('live', 'true');
|
|
106
|
-
}
|
|
107
|
-
const payload = args.payload;
|
|
108
|
-
const url = `${endpointUrl}?${searchParams.toString()}`;
|
|
109
|
-
return { url, storeId: args.storeId, needsInit: args.handle._tag === 'None', payload };
|
|
110
|
-
};
|
|
111
90
|
export const SyncMetadata = Schema.Struct({
|
|
112
91
|
offset: Schema.String,
|
|
113
92
|
// TODO move this into some kind of "global" sync metadata as it's the same for each event
|
|
114
93
|
handle: Schema.String,
|
|
115
94
|
});
|
|
116
|
-
export const makeSyncBackend = ({ endpoint }) => ({ storeId, payload }) => Effect.gen(function* () {
|
|
117
|
-
const isConnected = yield* SubscriptionRef.make(
|
|
95
|
+
export const makeSyncBackend = ({ endpoint, ...options }) => ({ storeId, payload }) => Effect.gen(function* () {
|
|
96
|
+
const isConnected = yield* SubscriptionRef.make(false);
|
|
118
97
|
const pullEndpoint = typeof endpoint === 'string' ? endpoint : endpoint.pull;
|
|
119
98
|
const pushEndpoint = typeof endpoint === 'string' ? endpoint : endpoint.push;
|
|
120
|
-
const
|
|
121
|
-
|
|
99
|
+
const pingEndpoint = typeof endpoint === 'string' ? endpoint : endpoint.ping;
|
|
100
|
+
const httpClient = yield* HttpClient.HttpClient;
|
|
101
|
+
const runPull = (handle, { live }) => Effect.gen(function* () {
|
|
102
|
+
const argsJson = yield* Schema.encode(ApiSchema.ArgsSchema)(ApiSchema.PullPayload.make({ storeId, handle, payload, live }));
|
|
122
103
|
const url = `${pullEndpoint}?args=${argsJson}`;
|
|
123
|
-
const resp = yield*
|
|
104
|
+
const resp = yield* httpClient.get(url);
|
|
124
105
|
if (resp.status === 401) {
|
|
125
106
|
const body = yield* resp.text.pipe(Effect.catchAll(() => Effect.succeed('-')));
|
|
126
107
|
return yield* InvalidPullError.make({
|
|
127
|
-
|
|
108
|
+
cause: new Error(`Unauthorized (401): Couldn't connect to ElectricSQL: ${body}`),
|
|
128
109
|
});
|
|
129
110
|
}
|
|
111
|
+
else if (resp.status === 400) {
|
|
112
|
+
// Electric returns 400 when table doesn't exist
|
|
113
|
+
// Return empty result for non-existent tables
|
|
114
|
+
return Option.some([[], Option.none()]);
|
|
115
|
+
}
|
|
130
116
|
else if (resp.status === 409) {
|
|
131
117
|
// https://electric-sql.com/openapi.html#/paths/~1v1~1shape/get
|
|
132
118
|
// {
|
|
@@ -140,8 +126,9 @@ export const makeSyncBackend = ({ endpoint }) => ({ storeId, payload }) => Effec
|
|
|
140
126
|
return notYetImplemented(`Electric shape not found`);
|
|
141
127
|
}
|
|
142
128
|
else if (resp.status < 200 || resp.status >= 300) {
|
|
129
|
+
const body = yield* resp.text;
|
|
143
130
|
return yield* InvalidPullError.make({
|
|
144
|
-
|
|
131
|
+
cause: new Error(`Unexpected status code: ${resp.status}: ${body}`),
|
|
145
132
|
});
|
|
146
133
|
}
|
|
147
134
|
const headers = yield* HttpClientResponse.schemaHeaders(ResponseHeaders)(resp);
|
|
@@ -152,39 +139,77 @@ export const makeSyncBackend = ({ endpoint }) => ({ storeId, payload }) => Effec
|
|
|
152
139
|
// Electric completes the long-poll request after ~20 seconds with a 204 status
|
|
153
140
|
// In this case we just retry where we left off
|
|
154
141
|
if (resp.status === 204) {
|
|
155
|
-
return Option.some([
|
|
142
|
+
return Option.some([[], Option.some(nextHandle)]);
|
|
156
143
|
}
|
|
157
|
-
const
|
|
144
|
+
const allItems = yield* HttpClientResponse.schemaBodyJson(Schema.Array(ResponseItem), {
|
|
158
145
|
onExcessProperty: 'preserve',
|
|
159
146
|
})(resp);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
147
|
+
// Check for delete/update operations and throw descriptive error
|
|
148
|
+
const invalidOperations = ReadonlyArray.filterMap(allItems, (item) => Schema.is(ResponseItemInvalid)(item) ? Option.some(item.headers.operation) : Option.none());
|
|
149
|
+
if (invalidOperations.length > 0) {
|
|
150
|
+
const operation = invalidOperations[0];
|
|
151
|
+
return yield* new InvalidOperationError({
|
|
152
|
+
operation,
|
|
153
|
+
message: `ElectricSQL '${operation}' event received. This results from directly mutating the event log. Append a series of events that produce the desired state instead of mutating the event log.`,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
const items = allItems.filter(Schema.is(ResponseItemInsert)).map((item) => ({
|
|
163
157
|
metadata: Option.some({ offset: nextHandle.offset, handle: nextHandle.handle }),
|
|
164
158
|
eventEncoded: item.value,
|
|
165
159
|
}));
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// return Option.none()
|
|
170
|
-
// }
|
|
171
|
-
return Option.some([Chunk.fromIterable(items), Option.some(nextHandle)]);
|
|
172
|
-
}).pipe(Effect.scoped, Effect.mapError((cause) => cause._tag === 'InvalidPullError' ? cause : InvalidPullError.make({ message: cause.toString() })));
|
|
160
|
+
yield* Effect.annotateCurrentSpan({ itemsCount: items.length, nextHandle });
|
|
161
|
+
return Option.some([items, Option.some(nextHandle)]);
|
|
162
|
+
}).pipe(Effect.scoped, Effect.mapError((cause) => (cause._tag === 'InvalidPullError' ? cause : InvalidPullError.make({ cause }))), Effect.withSpan('electric-provider:runPull', { attributes: { handle, live } }));
|
|
173
163
|
const pullEndpointHasSameOrigin = pullEndpoint.startsWith('/') ||
|
|
174
164
|
(globalThis.location !== undefined && globalThis.location.origin === new URL(pullEndpoint).origin);
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
165
|
+
const pingTimeout = options.ping?.requestTimeout ?? 10_000;
|
|
166
|
+
const ping = Effect.gen(function* () {
|
|
167
|
+
yield* httpClient.pipe(HttpClient.filterStatusOk).head(pingEndpoint);
|
|
168
|
+
yield* SubscriptionRef.set(isConnected, true);
|
|
169
|
+
}).pipe(UnexpectedError.mapToUnexpectedError, Effect.timeout(pingTimeout), Effect.catchTag('TimeoutException', () => SubscriptionRef.set(isConnected, false)), Effect.withSpan('electric-provider:ping'));
|
|
170
|
+
const pingInterval = options.ping?.requestInterval ?? 10_000;
|
|
171
|
+
if (options.ping?.enabled !== false) {
|
|
172
|
+
// Automatically ping the server to keep the connection alive
|
|
173
|
+
yield* ping.pipe(Effect.repeat(Schedule.spaced(pingInterval)), Effect.tapCauseLogPretty, Effect.forkScoped);
|
|
174
|
+
}
|
|
175
|
+
// If the pull endpoint has the same origin as the current page, we can assume that we already have a connection
|
|
176
|
+
// otherwise we send a HEAD request to speed up the connection process
|
|
177
|
+
const connect = pullEndpointHasSameOrigin
|
|
178
|
+
? Effect.void
|
|
179
|
+
: ping.pipe(UnexpectedError.mapToUnexpectedError);
|
|
180
|
+
return SyncBackend.of({
|
|
181
|
+
connect,
|
|
182
|
+
pull: (cursor, options) => {
|
|
183
|
+
let hasEmittedAtLeastOnce = false;
|
|
184
|
+
return Stream.unfoldEffect(cursor.pipe(Option.flatMap((_) => _.metadata)), (metadataOption) => Effect.gen(function* () {
|
|
185
|
+
const result = yield* runPull(metadataOption, { live: options?.live ?? false });
|
|
186
|
+
if (Option.isNone(result))
|
|
187
|
+
return Option.none();
|
|
188
|
+
const [batch, nextMetadataOption] = result.value;
|
|
189
|
+
// Continue pagination if we have data
|
|
190
|
+
if (batch.length > 0) {
|
|
191
|
+
hasEmittedAtLeastOnce = true;
|
|
192
|
+
return Option.some([{ batch, hasMore: true }, nextMetadataOption]);
|
|
193
|
+
}
|
|
194
|
+
// Make sure we emit at least once even if there's no data or we're live-pulling
|
|
195
|
+
if (hasEmittedAtLeastOnce === false || options?.live) {
|
|
196
|
+
hasEmittedAtLeastOnce = true;
|
|
197
|
+
return Option.some([{ batch, hasMore: false }, nextMetadataOption]);
|
|
198
|
+
}
|
|
199
|
+
// Stop on empty batch (when not live)
|
|
200
|
+
return Option.none();
|
|
201
|
+
})).pipe(Stream.map(({ batch, hasMore }) => ({
|
|
202
|
+
batch,
|
|
203
|
+
pageInfo: hasMore ? SyncBackend.pageInfoMoreUnknown : SyncBackend.pageInfoNoMore,
|
|
204
|
+
})), Stream.withSpan('electric-provider:pull'));
|
|
205
|
+
},
|
|
182
206
|
push: (batch) => Effect.gen(function* () {
|
|
183
|
-
const resp = yield* HttpClientRequest.schemaBodyJson(ApiSchema.PushPayload)(HttpClientRequest.post(pushEndpoint), ApiSchema.PushPayload.make({ storeId, batch })).pipe(Effect.andThen(HttpClient.execute), Effect.andThen(HttpClientResponse.schemaBodyJson(Schema.Struct({ success: Schema.Boolean }))), Effect.scoped, Effect.mapError((cause) => InvalidPushError.make({
|
|
207
|
+
const resp = yield* HttpClientRequest.schemaBodyJson(ApiSchema.PushPayload)(HttpClientRequest.post(pushEndpoint), ApiSchema.PushPayload.make({ storeId, batch })).pipe(Effect.andThen(httpClient.pipe(HttpClient.filterStatusOk).execute), Effect.andThen(HttpClientResponse.schemaBodyJson(Schema.Struct({ success: Schema.Boolean }))), Effect.scoped, Effect.mapError((cause) => InvalidPushError.make({ cause: UnexpectedError.make({ cause }) })));
|
|
184
208
|
if (!resp.success) {
|
|
185
|
-
yield* InvalidPushError.make({
|
|
209
|
+
return yield* InvalidPushError.make({ cause: new UnexpectedError({ cause: new Error('Push failed') }) });
|
|
186
210
|
}
|
|
187
|
-
}),
|
|
211
|
+
}).pipe(Effect.withSpan('electric-provider:push')),
|
|
212
|
+
ping,
|
|
188
213
|
isConnected,
|
|
189
214
|
metadata: {
|
|
190
215
|
name: '@livestore/sync-electric',
|
|
@@ -192,16 +217,12 @@ export const makeSyncBackend = ({ endpoint }) => ({ storeId, payload }) => Effec
|
|
|
192
217
|
protocol: 'http',
|
|
193
218
|
endpoint,
|
|
194
219
|
},
|
|
195
|
-
|
|
220
|
+
supports: {
|
|
221
|
+
// Given Electric is heavily optimized for immutable caching, we can't know the remaining count
|
|
222
|
+
// until we've reached the end of the stream
|
|
223
|
+
pullPageInfoKnown: false,
|
|
224
|
+
pullLive: true,
|
|
225
|
+
},
|
|
226
|
+
});
|
|
196
227
|
});
|
|
197
|
-
/**
|
|
198
|
-
* Needs to be bumped when the storage format changes (e.g. eventlogTable schema changes)
|
|
199
|
-
*
|
|
200
|
-
* Changing this version number will lead to a "soft reset".
|
|
201
|
-
*/
|
|
202
|
-
export const PERSISTENCE_FORMAT_VERSION = 6;
|
|
203
|
-
export const toTableName = (storeId) => {
|
|
204
|
-
const escapedStoreId = storeId.replaceAll(/[^a-zA-Z0-9_]/g, '_');
|
|
205
|
-
return `eventlog_${PERSISTENCE_FORMAT_VERSION}_${escapedStoreId}`;
|
|
206
|
-
};
|
|
207
228
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAEhB,WAAW,EACX,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAEL,MAAM,EACN,UAA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CAAC,EAAE,CAAC,EAAE,CAAC,CAAA;YAC1G,CAAC;QACH,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;QACpD,IAAI;QACJ,WAAW;QACX,QAAQ,EAAE;YACR,IAAI,EAAE,0BAA0B;YAChC,WAAW,EAAE,yDAAyD;YACtE,QAAQ,EAAE,MAAM;YAChB,QAAQ;SACT;QACD,QAAQ,EAAE;YACR,+FAA+F;YAC/F,4CAA4C;YAC5C,iBAAiB,EAAE,KAAK;YACxB,QAAQ,EAAE,IAAI;SACf;KACF,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Schema } from '@livestore/utils/effect';
|
|
2
|
+
/**
|
|
3
|
+
* This function should be called in a trusted environment (e.g. a proxy server) as it
|
|
4
|
+
* requires access to senstive information (e.g. `apiSecret` / `sourceSecret`).
|
|
5
|
+
*/
|
|
6
|
+
export declare const makeElectricUrl: ({ electricHost, searchParams: providedSearchParams, sourceId, sourceSecret, apiSecret, }: {
|
|
7
|
+
electricHost: string;
|
|
8
|
+
/**
|
|
9
|
+
* Needed to extract information from the search params which the `@livestore/sync-electric`
|
|
10
|
+
* client implementation automatically adds:
|
|
11
|
+
* - `handle`: the ElectricSQL handle
|
|
12
|
+
* - `storeId`: the Livestore storeId
|
|
13
|
+
*/
|
|
14
|
+
searchParams: URLSearchParams;
|
|
15
|
+
/** Needed for Electric Cloud */
|
|
16
|
+
sourceId?: string;
|
|
17
|
+
/** Needed for Electric Cloud */
|
|
18
|
+
sourceSecret?: string;
|
|
19
|
+
/** For self-hosted ElectricSQL */
|
|
20
|
+
apiSecret?: string;
|
|
21
|
+
}) => {
|
|
22
|
+
/**
|
|
23
|
+
* The URL to the ElectricSQL API endpoint with needed search params.
|
|
24
|
+
*/
|
|
25
|
+
url: string;
|
|
26
|
+
/** The Livestore storeId */
|
|
27
|
+
storeId: string;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the Postgres table needs to be created.
|
|
30
|
+
*/
|
|
31
|
+
needsInit: boolean;
|
|
32
|
+
/** Sync payload provided by the client */
|
|
33
|
+
payload: Schema.JsonValue | undefined;
|
|
34
|
+
};
|
|
35
|
+
export declare const toTableName: (storeId: string) => string;
|
|
36
|
+
/**
|
|
37
|
+
* Needs to be bumped when the storage format changes (e.g. eventlogTable schema changes)
|
|
38
|
+
*
|
|
39
|
+
* Changing this version number will lead to a "soft reset".
|
|
40
|
+
*/
|
|
41
|
+
export declare const PERSISTENCE_FORMAT_VERSION = 6;
|
|
42
|
+
//# sourceMappingURL=make-electric-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-electric-url.d.ts","sourceRoot":"","sources":["../src/make-electric-url.ts"],"names":[],"mappings":"AACA,OAAO,EAAQ,MAAM,EAAE,MAAM,yBAAyB,CAAA;AAGtD;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,0FAM7B;IACD,YAAY,EAAE,MAAM,CAAA;IACpB;;;;;OAKG;IACH,YAAY,EAAE,eAAe,CAAA;IAC7B,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gCAAgC;IAChC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,KAAG;IACF;;OAEG;IACH,GAAG,EAAE,MAAM,CAAA;IACX,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,SAAS,EAAE,OAAO,CAAA;IAClB,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC,SAAS,GAAG,SAAS,CAAA;CA4CtC,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,SAAS,MAAM,WAe1C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,IAAI,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { shouldNeverHappen } from '@livestore/utils';
|
|
2
|
+
import { Hash, Schema } from '@livestore/utils/effect';
|
|
3
|
+
import * as ApiSchema from "./api-schema.js";
|
|
4
|
+
/**
|
|
5
|
+
* This function should be called in a trusted environment (e.g. a proxy server) as it
|
|
6
|
+
* requires access to senstive information (e.g. `apiSecret` / `sourceSecret`).
|
|
7
|
+
*/
|
|
8
|
+
export const makeElectricUrl = ({ electricHost, searchParams: providedSearchParams, sourceId, sourceSecret, apiSecret, }) => {
|
|
9
|
+
const endpointUrl = `${electricHost}/v1/shape`;
|
|
10
|
+
const UrlParamsSchema = Schema.Struct({ args: ApiSchema.ArgsSchema });
|
|
11
|
+
const argsResult = Schema.decodeUnknownEither(UrlParamsSchema)(Object.fromEntries(providedSearchParams.entries()));
|
|
12
|
+
if (argsResult._tag === 'Left') {
|
|
13
|
+
return shouldNeverHappen('Invalid search params provided to makeElectricUrl', providedSearchParams, Object.fromEntries(providedSearchParams.entries()));
|
|
14
|
+
}
|
|
15
|
+
const args = argsResult.right.args;
|
|
16
|
+
const tableName = toTableName(args.storeId);
|
|
17
|
+
// TODO refactor with Effect URLSearchParams schema
|
|
18
|
+
// https://electric-sql.com/openapi.html
|
|
19
|
+
const searchParams = new URLSearchParams();
|
|
20
|
+
// Electric requires table names with capital letters to be quoted
|
|
21
|
+
// Since our table names include the storeId which may have capitals, we always quote
|
|
22
|
+
searchParams.set('table', `"${tableName}"`);
|
|
23
|
+
if (sourceId !== undefined) {
|
|
24
|
+
searchParams.set('source_id', sourceId);
|
|
25
|
+
}
|
|
26
|
+
if (sourceSecret !== undefined) {
|
|
27
|
+
searchParams.set('source_secret', sourceSecret);
|
|
28
|
+
}
|
|
29
|
+
if (apiSecret !== undefined) {
|
|
30
|
+
searchParams.set('api_secret', apiSecret);
|
|
31
|
+
}
|
|
32
|
+
if (args.handle._tag === 'None') {
|
|
33
|
+
searchParams.set('offset', '-1');
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
searchParams.set('offset', args.handle.value.offset);
|
|
37
|
+
searchParams.set('handle', args.handle.value.handle);
|
|
38
|
+
searchParams.set('live', args.live ? 'true' : 'false');
|
|
39
|
+
}
|
|
40
|
+
const payload = args.payload;
|
|
41
|
+
const url = `${endpointUrl}?${searchParams.toString()}`;
|
|
42
|
+
return { url, storeId: args.storeId, needsInit: args.handle._tag === 'None', payload };
|
|
43
|
+
};
|
|
44
|
+
export const toTableName = (storeId) => {
|
|
45
|
+
const escapedStoreId = storeId.replaceAll(/[^a-zA-Z0-9_]/g, '_');
|
|
46
|
+
const tableName = `eventlog_${PERSISTENCE_FORMAT_VERSION}_${escapedStoreId}`;
|
|
47
|
+
if (tableName.length > 63) {
|
|
48
|
+
const hashedStoreId = Hash.string(storeId);
|
|
49
|
+
console.warn(`Table name is too long: "${tableName}". Postgres table names are limited to 63 characters. Using hashed storeId instead: "${hashedStoreId}".`);
|
|
50
|
+
return `eventlog_${PERSISTENCE_FORMAT_VERSION}_hash_${hashedStoreId}`;
|
|
51
|
+
}
|
|
52
|
+
return tableName;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Needs to be bumped when the storage format changes (e.g. eventlogTable schema changes)
|
|
56
|
+
*
|
|
57
|
+
* Changing this version number will lead to a "soft reset".
|
|
58
|
+
*/
|
|
59
|
+
export const PERSISTENCE_FORMAT_VERSION = 6;
|
|
60
|
+
//# sourceMappingURL=make-electric-url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-electric-url.js","sourceRoot":"","sources":["../src/make-electric-url.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AACtD,OAAO,KAAK,SAAS,MAAM,iBAAiB,CAAA;AAE5C;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAC9B,YAAY,EACZ,YAAY,EAAE,oBAAoB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AED;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livestore/sync-electric",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@livestore/common": "0.4.0-dev.
|
|
11
|
-
"@livestore/utils": "0.4.0-dev.
|
|
10
|
+
"@livestore/common": "0.4.0-dev.10",
|
|
11
|
+
"@livestore/utils": "0.4.0-dev.10"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {},
|
|
14
14
|
"files": [
|
package/src/api-schema.ts
CHANGED
|
@@ -15,6 +15,10 @@ export const PullPayload = Schema.TaggedStruct('@livestore/sync-electric.Pull',
|
|
|
15
15
|
handle: Schema.String,
|
|
16
16
|
}),
|
|
17
17
|
),
|
|
18
|
+
live: Schema.Boolean,
|
|
18
19
|
}).annotations({ title: '@livestore/sync-electric.PullPayload' })
|
|
19
20
|
|
|
20
21
|
export const ApiPayload = Schema.Union(PullPayload, PushPayload)
|
|
22
|
+
|
|
23
|
+
// Format for the query params
|
|
24
|
+
export const ArgsSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PullPayload))
|