foldkit-sync 0.15.0 → 0.17.0
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/README.md +567 -41
- package/dist/diagnostics.d.ts +74 -3
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +60 -4
- package/dist/diagnostics.js.map +1 -1
- package/dist/do.d.ts +49 -7
- package/dist/do.d.ts.map +1 -1
- package/dist/do.js +91 -8
- package/dist/do.js.map +1 -1
- package/dist/errors.d.ts +92 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +87 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/journal.d.ts +52 -27
- package/dist/journal.d.ts.map +1 -1
- package/dist/journal.js +176 -64
- package/dist/journal.js.map +1 -1
- package/dist/make.d.ts +48 -17
- package/dist/make.d.ts.map +1 -1
- package/dist/make.js +11 -4
- package/dist/make.js.map +1 -1
- package/dist/migrations.d.ts +37 -0
- package/dist/migrations.d.ts.map +1 -0
- package/dist/migrations.js +56 -0
- package/dist/migrations.js.map +1 -0
- package/dist/mount.d.ts +1 -1
- package/dist/mount.d.ts.map +1 -1
- package/dist/mount.js +12 -6
- package/dist/mount.js.map +1 -1
- package/dist/refusal.d.ts +33 -0
- package/dist/refusal.d.ts.map +1 -0
- package/dist/refusal.js +47 -0
- package/dist/refusal.js.map +1 -0
- package/dist/serverJournal.d.ts +143 -0
- package/dist/serverJournal.d.ts.map +1 -0
- package/dist/serverJournal.js +503 -0
- package/dist/serverJournal.js.map +1 -0
- package/dist/sync.d.ts +150 -14
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +273 -64
- package/dist/sync.js.map +1 -1
- package/dist/transport.d.ts +10 -6
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js.map +1 -1
- package/package.json +11 -8
package/dist/errors.d.ts
CHANGED
|
@@ -77,6 +77,97 @@ declare const UnsupportedReplicaVersionError_base: Schema.Class<UnsupportedRepli
|
|
|
77
77
|
}>, import("effect/Cause").YieldableError>;
|
|
78
78
|
/** The stored replica state targets a protocol or schema version this build does not support. */
|
|
79
79
|
export declare class UnsupportedReplicaVersionError extends UnsupportedReplicaVersionError_base {}
|
|
80
|
+
declare const UnsupportedMessageVersionError_base: Schema.Class<UnsupportedMessageVersionError, Schema.TaggedStruct<"UnsupportedMessageVersionError", {
|
|
81
|
+
readonly opId: Schema.String;
|
|
82
|
+
/** The version the operation was written at. */
|
|
83
|
+
readonly found: Schema.Number;
|
|
84
|
+
/** The newest version this build reads. */
|
|
85
|
+
readonly supported: Schema.Number;
|
|
86
|
+
readonly message: Schema.String;
|
|
87
|
+
}>, import("effect/Cause").YieldableError>;
|
|
88
|
+
/**
|
|
89
|
+
* An operation was written at a Message version above this build's: a newer
|
|
90
|
+
* build wrote it. Nothing is removed; a build that has the version reads it.
|
|
91
|
+
* The replica refuses to open on one in its outbox, and an exchange fails on
|
|
92
|
+
* one the server committed: this client is older than its server, and reads
|
|
93
|
+
* the document once it runs the new build.
|
|
94
|
+
*/
|
|
95
|
+
export declare class UnsupportedMessageVersionError extends UnsupportedMessageVersionError_base {}
|
|
96
|
+
declare const UnreadableMessageError_base: Schema.Class<UnreadableMessageError, Schema.TaggedStruct<"UnreadableMessageError", {
|
|
97
|
+
readonly opId: Schema.String;
|
|
98
|
+
readonly version: Schema.Number;
|
|
99
|
+
readonly message: Schema.String;
|
|
100
|
+
readonly cause: Schema.optional<Schema.Unknown>;
|
|
101
|
+
}>, import("effect/Cause").YieldableError>;
|
|
102
|
+
/**
|
|
103
|
+
* An operation written at an older Message version that no step of the
|
|
104
|
+
* history reads: a step's Schema refused it, or its `up` threw. Thrown by
|
|
105
|
+
* Sync's operation codec; a replica moves such a pending operation to
|
|
106
|
+
* `refused`, and `journalExchange` rejects one as `Unreadable`.
|
|
107
|
+
*/
|
|
108
|
+
export declare class UnreadableMessageError extends UnreadableMessageError_base {}
|
|
109
|
+
declare const ServerOnlyMessageError_base: Schema.Class<ServerOnlyMessageError, Schema.TaggedStruct<"ServerOnlyMessageError", {
|
|
110
|
+
readonly opId: Schema.String;
|
|
111
|
+
readonly message: Schema.String;
|
|
112
|
+
}>, import("effect/Cause").YieldableError>;
|
|
113
|
+
/**
|
|
114
|
+
* A sent entry carries a Message only the server appends (`serverOnly`),
|
|
115
|
+
* judged after upcasting. Thrown by every reader of an entry someone sent
|
|
116
|
+
* (`codec.writtenFrom`, `normalizeOperation`, `operationFrom`);
|
|
117
|
+
* `journalExchange` rejects it as `Forbidden`. History reads it.
|
|
118
|
+
*/
|
|
119
|
+
export declare class ServerOnlyMessageError extends ServerOnlyMessageError_base {}
|
|
120
|
+
declare const AmbiguousMessageError_base: Schema.Class<AmbiguousMessageError, Schema.TaggedStruct<"AmbiguousMessageError", {
|
|
121
|
+
readonly opId: Schema.String;
|
|
122
|
+
readonly message: Schema.String;
|
|
123
|
+
}>, import("effect/Cause").YieldableError>;
|
|
124
|
+
/**
|
|
125
|
+
* A Message both `durable` and `serverOnly` accept: `Sync.define`'s two
|
|
126
|
+
* predicates overlap, which cannot be told when they are given. It is refused
|
|
127
|
+
* wherever it is read, never treated as either.
|
|
128
|
+
*/
|
|
129
|
+
export declare class AmbiguousMessageError extends AmbiguousMessageError_base {}
|
|
130
|
+
declare const ServerKeyReusedError_base: Schema.Class<ServerKeyReusedError, Schema.TaggedStruct<"SyncServerKeyReusedError", {
|
|
131
|
+
readonly key: Schema.String;
|
|
132
|
+
}>, import("effect/Cause").YieldableError>;
|
|
133
|
+
/**
|
|
134
|
+
* `appendAsServer` was given a key already used for another Message: the
|
|
135
|
+
* first fact stands, and nothing was appended.
|
|
136
|
+
*/
|
|
137
|
+
export declare class ServerKeyReusedError extends ServerKeyReusedError_base {
|
|
138
|
+
get message(): string;
|
|
139
|
+
}
|
|
140
|
+
declare const StaleParkedRunError_base: Schema.Class<StaleParkedRunError, Schema.TaggedStruct<"SyncStaleParkedRunError", {
|
|
141
|
+
readonly reaction: Schema.String;
|
|
142
|
+
readonly opId: Schema.String;
|
|
143
|
+
}>, import("effect/Cause").YieldableError>;
|
|
144
|
+
/**
|
|
145
|
+
* `retry` was given a run parked in a history since reset: its sequence names
|
|
146
|
+
* whatever the new history committed there. Dismiss it; if its operation is
|
|
147
|
+
* sent again, it commits and is reacted to in the new history.
|
|
148
|
+
*/
|
|
149
|
+
export declare class StaleParkedRunError extends StaleParkedRunError_base {
|
|
150
|
+
get message(): string;
|
|
151
|
+
}
|
|
152
|
+
declare const UnreadableHistoryError_base: Schema.Class<UnreadableHistoryError, Schema.TaggedStruct<"UnreadableHistoryError", {
|
|
153
|
+
readonly documentId: Schema.String;
|
|
154
|
+
readonly opId: Schema.String;
|
|
155
|
+
readonly version: Schema.Number;
|
|
156
|
+
readonly message: Schema.String;
|
|
157
|
+
}>, import("effect/Cause").YieldableError>;
|
|
158
|
+
/**
|
|
159
|
+
* A committed operation of the document will not read: written at a version
|
|
160
|
+
* this server's history lacks, or at one no step reads. The journal reads a
|
|
161
|
+
* stored row only when it needs it, so this fails what needs that row: an
|
|
162
|
+
* exchange from a replica whose cursor is before it (after appending what
|
|
163
|
+
* that replica sent, which commits, and is acknowledged on a retry once a
|
|
164
|
+
* build reads the row), a retransmission of its id, and, while the row is
|
|
165
|
+
* after the stored snapshot, every append and load of the document. A
|
|
166
|
+
* replica past the row is served. Other documents are not affected.
|
|
167
|
+
* Server-side only: its fields are for the server's logs, and its message,
|
|
168
|
+
* which a socket sends, names neither.
|
|
169
|
+
*/
|
|
170
|
+
export declare class UnreadableHistoryError extends UnreadableHistoryError_base {}
|
|
80
171
|
declare const ReplayError_base: Schema.Class<ReplayError, Schema.TaggedStruct<"ReplayError", {
|
|
81
172
|
readonly message: Schema.String;
|
|
82
173
|
readonly cause: Schema.optional<Schema.Unknown>;
|
|
@@ -86,6 +177,6 @@ declare const ReplayError_base: Schema.Class<ReplayError, Schema.TaggedStruct<"R
|
|
|
86
177
|
* on any other replica; nothing was written.
|
|
87
178
|
*/
|
|
88
179
|
export declare class ReplayError extends ReplayError_base {}
|
|
89
|
-
export type ReplicaError = StorageError | ReplayError | WrongReplicaStorageError | InvalidReplicaHistoryError | InvalidExchangeError | UnsupportedReplicaVersionError | InvalidOutboxError | CheckpointRegressionError | CommittedOrderError | ForeignRejectionError | ForeignAcknowledgementError | ReplicaClosedError;
|
|
180
|
+
export type ReplicaError = StorageError | ReplayError | WrongReplicaStorageError | InvalidReplicaHistoryError | InvalidExchangeError | UnsupportedReplicaVersionError | UnsupportedMessageVersionError | InvalidOutboxError | CheckpointRegressionError | CommittedOrderError | ForeignRejectionError | ForeignAcknowledgementError | ReplicaClosedError;
|
|
90
181
|
export {};
|
|
91
182
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;qBAGa,qBAAqB;;;;;;qBAMrB,qCAAqC;;;;;;;qBASrC,iCAAiC;;;;;;qBAUjC,mCAAmC;;;;;;qBASnC,6BAA6B;;;;;qBAS7B,2BAA2B;;;;;;;qBAQ3B,kCAAkC;;;;;;;qBAUlC,4BAA4B;;;;;;qBAU5B,8BAA8B;;;;;;;;;;qBAa9B,oCAAoC;;;;;qBASpC,2BAA2B;;;;;;;qBAQ3B,uCAAuC;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":[],"sources":["../src/errors.ts"],"mappings":";;;;;;qBAGa,qBAAqB;;;;;;qBAMrB,qCAAqC;;;;;;;qBASrC,iCAAiC;;;;;;qBAUjC,mCAAmC;;;;;;qBASnC,6BAA6B;;;;;qBAS7B,2BAA2B;;;;;;;qBAQ3B,kCAAkC;;;;;;;qBAUlC,4BAA4B;;;;;;qBAU5B,8BAA8B;;;;;;;;;;qBAa9B,oCAAoC;;;;;qBASpC,2BAA2B;;;;;;;qBAQ3B,uCAAuC;;;;;;;;;;;;;;;;qBAgBvC,uCAAuC;;;;;;;;;;;;;qBAkBvC,+BAA+B;;;;;;;;;;;qBAgB/B,+BAA+B;;;;;;;;;;qBAa/B,8BAA8B;;;;;;;;qBAY9B,6BAA6B;MAI3B;;;;;;;;;;;qBAUF,4BAA4B;MAI1B;;;;;;;;;;;;;;;;;;;;qBAiBF,+BAA+B;;;;;;;;;qBAc/B,oBAAoB;YAKrB,eACR,eACA,cACA,2BACA,6BACA,uBACA,iCACA,iCACA,qBACA,4BACA,sBACA,wBACA,8BACA"}
|
package/dist/errors.js
CHANGED
|
@@ -63,6 +63,92 @@ var UnsupportedReplicaVersionError = class extends Schema.TaggedError()("Unsuppo
|
|
|
63
63
|
message: Schema.String
|
|
64
64
|
}) {};
|
|
65
65
|
/**
|
|
66
|
+
* An operation was written at a Message version above this build's: a newer
|
|
67
|
+
* build wrote it. Nothing is removed; a build that has the version reads it.
|
|
68
|
+
* The replica refuses to open on one in its outbox, and an exchange fails on
|
|
69
|
+
* one the server committed: this client is older than its server, and reads
|
|
70
|
+
* the document once it runs the new build.
|
|
71
|
+
*/
|
|
72
|
+
var UnsupportedMessageVersionError = class extends Schema.TaggedError()("UnsupportedMessageVersionError", {
|
|
73
|
+
opId: Schema.String,
|
|
74
|
+
/** The version the operation was written at. */
|
|
75
|
+
found: Schema.Number,
|
|
76
|
+
/** The newest version this build reads. */
|
|
77
|
+
supported: Schema.Number,
|
|
78
|
+
message: Schema.String
|
|
79
|
+
}) {};
|
|
80
|
+
/**
|
|
81
|
+
* An operation written at an older Message version that no step of the
|
|
82
|
+
* history reads: a step's Schema refused it, or its `up` threw. Thrown by
|
|
83
|
+
* Sync's operation codec; a replica moves such a pending operation to
|
|
84
|
+
* `refused`, and `journalExchange` rejects one as `Unreadable`.
|
|
85
|
+
*/
|
|
86
|
+
var UnreadableMessageError = class extends Schema.TaggedError()("UnreadableMessageError", {
|
|
87
|
+
opId: Schema.String,
|
|
88
|
+
version: Schema.Number,
|
|
89
|
+
message: Schema.String,
|
|
90
|
+
cause: Schema.optional(Schema.Unknown)
|
|
91
|
+
}) {};
|
|
92
|
+
/**
|
|
93
|
+
* A sent entry carries a Message only the server appends (`serverOnly`),
|
|
94
|
+
* judged after upcasting. Thrown by every reader of an entry someone sent
|
|
95
|
+
* (`codec.writtenFrom`, `normalizeOperation`, `operationFrom`);
|
|
96
|
+
* `journalExchange` rejects it as `Forbidden`. History reads it.
|
|
97
|
+
*/
|
|
98
|
+
var ServerOnlyMessageError = class extends Schema.TaggedError()("ServerOnlyMessageError", {
|
|
99
|
+
opId: Schema.String,
|
|
100
|
+
message: Schema.String
|
|
101
|
+
}) {};
|
|
102
|
+
/**
|
|
103
|
+
* A Message both `durable` and `serverOnly` accept: `Sync.define`'s two
|
|
104
|
+
* predicates overlap, which cannot be told when they are given. It is refused
|
|
105
|
+
* wherever it is read, never treated as either.
|
|
106
|
+
*/
|
|
107
|
+
var AmbiguousMessageError = class extends Schema.TaggedError()("AmbiguousMessageError", {
|
|
108
|
+
opId: Schema.String,
|
|
109
|
+
message: Schema.String
|
|
110
|
+
}) {};
|
|
111
|
+
/**
|
|
112
|
+
* `appendAsServer` was given a key already used for another Message: the
|
|
113
|
+
* first fact stands, and nothing was appended.
|
|
114
|
+
*/
|
|
115
|
+
var ServerKeyReusedError = class extends Schema.TaggedError()("SyncServerKeyReusedError", { key: Schema.String }) {
|
|
116
|
+
get message() {
|
|
117
|
+
return `The server key "${this.key}" was already used for another Message`;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* `retry` was given a run parked in a history since reset: its sequence names
|
|
122
|
+
* whatever the new history committed there. Dismiss it; if its operation is
|
|
123
|
+
* sent again, it commits and is reacted to in the new history.
|
|
124
|
+
*/
|
|
125
|
+
var StaleParkedRunError = class extends Schema.TaggedError()("SyncStaleParkedRunError", {
|
|
126
|
+
reaction: Schema.String,
|
|
127
|
+
opId: Schema.String
|
|
128
|
+
}) {
|
|
129
|
+
get message() {
|
|
130
|
+
return `The run of ${this.reaction} at ${this.opId} was parked before the document was reset`;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* A committed operation of the document will not read: written at a version
|
|
135
|
+
* this server's history lacks, or at one no step reads. The journal reads a
|
|
136
|
+
* stored row only when it needs it, so this fails what needs that row: an
|
|
137
|
+
* exchange from a replica whose cursor is before it (after appending what
|
|
138
|
+
* that replica sent, which commits, and is acknowledged on a retry once a
|
|
139
|
+
* build reads the row), a retransmission of its id, and, while the row is
|
|
140
|
+
* after the stored snapshot, every append and load of the document. A
|
|
141
|
+
* replica past the row is served. Other documents are not affected.
|
|
142
|
+
* Server-side only: its fields are for the server's logs, and its message,
|
|
143
|
+
* which a socket sends, names neither.
|
|
144
|
+
*/
|
|
145
|
+
var UnreadableHistoryError = class extends Schema.TaggedError()("UnreadableHistoryError", {
|
|
146
|
+
documentId: Schema.String,
|
|
147
|
+
opId: Schema.String,
|
|
148
|
+
version: Schema.Number,
|
|
149
|
+
message: Schema.String
|
|
150
|
+
}) {};
|
|
151
|
+
/**
|
|
66
152
|
* `replay` threw for a submitted Message, so it could never be applied here or
|
|
67
153
|
* on any other replica; nothing was written.
|
|
68
154
|
*/
|
|
@@ -70,6 +156,6 @@ var ReplayError = class extends Schema.TaggedError()("ReplayError", {
|
|
|
70
156
|
message: Schema.String,
|
|
71
157
|
cause: Schema.optional(Schema.Unknown)
|
|
72
158
|
}) {};
|
|
73
|
-
export { CheckpointRegressionError, CommittedOrderError, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, ReplayError, ReplicaClosedError, StorageError, UnsupportedClockVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError };
|
|
159
|
+
export { AmbiguousMessageError, CheckpointRegressionError, CommittedOrderError, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, ReplayError, ReplicaClosedError, ServerKeyReusedError, ServerOnlyMessageError, StaleParkedRunError, StorageError, UnreadableHistoryError, UnreadableMessageError, UnsupportedClockVersionError, UnsupportedMessageVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError };
|
|
74
160
|
|
|
75
161
|
//# sourceMappingURL=errors.js.map
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Schema } from 'effect'\n\n/** The persisted storage could not be read or written. */\nexport class StorageError extends Schema.TaggedError<StorageError>()('StorageError', {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n}) {}\n\n/** The stored clock state targets a schema version this build does not support. */\nexport class UnsupportedClockVersionError extends Schema.TaggedError<UnsupportedClockVersionError>()(\n 'UnsupportedClockVersionError',\n {\n schemaVersion: Schema.NullOr(Schema.Number),\n message: Schema.String,\n },\n) {}\n\n/** The storage holds a different replica's state. */\nexport class WrongReplicaStorageError extends Schema.TaggedError<WrongReplicaStorageError>()(\n 'WrongReplicaStorageError',\n {\n documentId: Schema.String,\n replicaId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/** The persisted replica history is internally inconsistent. */\nexport class InvalidReplicaHistoryError extends Schema.TaggedError<InvalidReplicaHistoryError>()(\n 'InvalidReplicaHistoryError',\n {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n },\n) {}\n\n/** The server's exchange response did not match the protocol schema. */\nexport class InvalidExchangeError extends Schema.TaggedError<InvalidExchangeError>()(\n 'InvalidExchangeError',\n {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n },\n) {}\n\n/** A persisted pending operation could not have been produced by this replica. */\nexport class InvalidOutboxError extends Schema.TaggedError<InvalidOutboxError>()(\n 'InvalidOutboxError',\n {\n message: Schema.String,\n },\n) {}\n\n/** The server sent a checkpoint older than the replica's cursor. */\nexport class CheckpointRegressionError extends Schema.TaggedError<CheckpointRegressionError>()(\n 'CheckpointRegressionError',\n {\n cursor: Schema.Number,\n checkpointCursor: Schema.Number,\n message: Schema.String,\n },\n) {}\n\n/** Committed operations were not contiguous from the replica's cursor. */\nexport class CommittedOrderError extends Schema.TaggedError<CommittedOrderError>()(\n 'CommittedOrderError',\n {\n expected: Schema.Number,\n actual: Schema.Number,\n message: Schema.String,\n },\n) {}\n\n/** The server rejected an operation the replica never sent. */\nexport class ForeignRejectionError extends Schema.TaggedError<ForeignRejectionError>()(\n 'ForeignRejectionError',\n {\n opId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/**\n * The server answered an operation this request never sent, or both\n * acknowledged and rejected it. Acting on either would let a faulty or hostile\n * server delete local work.\n */\nexport class ForeignAcknowledgementError extends Schema.TaggedError<ForeignAcknowledgementError>()(\n 'ForeignAcknowledgementError',\n {\n opId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/** The replica was closed while work was still being submitted. */\nexport class ReplicaClosedError extends Schema.TaggedError<ReplicaClosedError>()(\n 'ReplicaClosedError',\n {\n message: Schema.String,\n },\n) {}\n\n/** The stored replica state targets a protocol or schema version this build does not support. */\nexport class UnsupportedReplicaVersionError extends Schema.TaggedError<UnsupportedReplicaVersionError>()(\n 'UnsupportedReplicaVersionError',\n {\n protocolVersion: Schema.NullOr(Schema.Number),\n schemaVersion: Schema.NullOr(Schema.Number),\n message: Schema.String,\n },\n) {}\n\n/**\n * `replay` threw for a submitted Message, so it could never be applied here or\n * on any other replica; nothing was written.\n */\nexport class ReplayError extends Schema.TaggedError<ReplayError>()('ReplayError', {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n}) {}\n\nexport type ReplicaError =\n | StorageError\n | ReplayError\n | WrongReplicaStorageError\n | InvalidReplicaHistoryError\n | InvalidExchangeError\n | UnsupportedReplicaVersionError\n | InvalidOutboxError\n | CheckpointRegressionError\n | CommittedOrderError\n | ForeignRejectionError\n | ForeignAcknowledgementError\n | ReplicaClosedError\n"],"mappings":";;;AAGA,IAA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8BAAb,cAAiD,OAAO,YAAyC,CAAC,CAChG,+BACA;CACE,MAAM,OAAO;CACb,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,qBAAb,cAAwC,OAAO,YAAgC,CAAC,CAC9E,sBACA,EACE,SAAS,OAAO,OAClB,CACF,CAAC,CAAC,CAAC;;AAGH,IAAa,iCAAb,cAAoD,OAAO,YAA4C,CAAC,CACtG,kCACA;CACE,iBAAiB,OAAO,OAAO,OAAO,MAAM;CAC5C,eAAe,OAAO,OAAO,OAAO,MAAM;CAC1C,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,cAAb,cAAiC,OAAO,YAAyB,CAAC,CAAC,eAAe;CAChF,SAAS,OAAO;CAChB,OAAO,OAAO,SAAS,OAAO,OAAO;AACvC,CAAC,CAAC,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Schema } from 'effect'\n\n/** The persisted storage could not be read or written. */\nexport class StorageError extends Schema.TaggedError<StorageError>()('StorageError', {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n}) {}\n\n/** The stored clock state targets a schema version this build does not support. */\nexport class UnsupportedClockVersionError extends Schema.TaggedError<UnsupportedClockVersionError>()(\n 'UnsupportedClockVersionError',\n {\n schemaVersion: Schema.NullOr(Schema.Number),\n message: Schema.String,\n },\n) {}\n\n/** The storage holds a different replica's state. */\nexport class WrongReplicaStorageError extends Schema.TaggedError<WrongReplicaStorageError>()(\n 'WrongReplicaStorageError',\n {\n documentId: Schema.String,\n replicaId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/** The persisted replica history is internally inconsistent. */\nexport class InvalidReplicaHistoryError extends Schema.TaggedError<InvalidReplicaHistoryError>()(\n 'InvalidReplicaHistoryError',\n {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n },\n) {}\n\n/** The server's exchange response did not match the protocol schema. */\nexport class InvalidExchangeError extends Schema.TaggedError<InvalidExchangeError>()(\n 'InvalidExchangeError',\n {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n },\n) {}\n\n/** A persisted pending operation could not have been produced by this replica. */\nexport class InvalidOutboxError extends Schema.TaggedError<InvalidOutboxError>()(\n 'InvalidOutboxError',\n {\n message: Schema.String,\n },\n) {}\n\n/** The server sent a checkpoint older than the replica's cursor. */\nexport class CheckpointRegressionError extends Schema.TaggedError<CheckpointRegressionError>()(\n 'CheckpointRegressionError',\n {\n cursor: Schema.Number,\n checkpointCursor: Schema.Number,\n message: Schema.String,\n },\n) {}\n\n/** Committed operations were not contiguous from the replica's cursor. */\nexport class CommittedOrderError extends Schema.TaggedError<CommittedOrderError>()(\n 'CommittedOrderError',\n {\n expected: Schema.Number,\n actual: Schema.Number,\n message: Schema.String,\n },\n) {}\n\n/** The server rejected an operation the replica never sent. */\nexport class ForeignRejectionError extends Schema.TaggedError<ForeignRejectionError>()(\n 'ForeignRejectionError',\n {\n opId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/**\n * The server answered an operation this request never sent, or both\n * acknowledged and rejected it. Acting on either would let a faulty or hostile\n * server delete local work.\n */\nexport class ForeignAcknowledgementError extends Schema.TaggedError<ForeignAcknowledgementError>()(\n 'ForeignAcknowledgementError',\n {\n opId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/** The replica was closed while work was still being submitted. */\nexport class ReplicaClosedError extends Schema.TaggedError<ReplicaClosedError>()(\n 'ReplicaClosedError',\n {\n message: Schema.String,\n },\n) {}\n\n/** The stored replica state targets a protocol or schema version this build does not support. */\nexport class UnsupportedReplicaVersionError extends Schema.TaggedError<UnsupportedReplicaVersionError>()(\n 'UnsupportedReplicaVersionError',\n {\n protocolVersion: Schema.NullOr(Schema.Number),\n schemaVersion: Schema.NullOr(Schema.Number),\n message: Schema.String,\n },\n) {}\n\n/**\n * An operation was written at a Message version above this build's: a newer\n * build wrote it. Nothing is removed; a build that has the version reads it.\n * The replica refuses to open on one in its outbox, and an exchange fails on\n * one the server committed: this client is older than its server, and reads\n * the document once it runs the new build.\n */\nexport class UnsupportedMessageVersionError extends Schema.TaggedError<UnsupportedMessageVersionError>()(\n 'UnsupportedMessageVersionError',\n {\n opId: Schema.String,\n /** The version the operation was written at. */\n found: Schema.Number,\n /** The newest version this build reads. */\n supported: Schema.Number,\n message: Schema.String,\n },\n) {}\n\n/**\n * An operation written at an older Message version that no step of the\n * history reads: a step's Schema refused it, or its `up` threw. Thrown by\n * Sync's operation codec; a replica moves such a pending operation to\n * `refused`, and `journalExchange` rejects one as `Unreadable`.\n */\nexport class UnreadableMessageError extends Schema.TaggedError<UnreadableMessageError>()(\n 'UnreadableMessageError',\n {\n opId: Schema.String,\n version: Schema.Number,\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n },\n) {}\n\n/**\n * A sent entry carries a Message only the server appends (`serverOnly`),\n * judged after upcasting. Thrown by every reader of an entry someone sent\n * (`codec.writtenFrom`, `normalizeOperation`, `operationFrom`);\n * `journalExchange` rejects it as `Forbidden`. History reads it.\n */\nexport class ServerOnlyMessageError extends Schema.TaggedError<ServerOnlyMessageError>()(\n 'ServerOnlyMessageError',\n {\n opId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/**\n * A Message both `durable` and `serverOnly` accept: `Sync.define`'s two\n * predicates overlap, which cannot be told when they are given. It is refused\n * wherever it is read, never treated as either.\n */\nexport class AmbiguousMessageError extends Schema.TaggedError<AmbiguousMessageError>()(\n 'AmbiguousMessageError',\n {\n opId: Schema.String,\n message: Schema.String,\n },\n) {}\n\n/**\n * `appendAsServer` was given a key already used for another Message: the\n * first fact stands, and nothing was appended.\n */\nexport class ServerKeyReusedError extends Schema.TaggedError<ServerKeyReusedError>()(\n 'SyncServerKeyReusedError',\n { key: Schema.String },\n) {\n override get message(): string {\n return `The server key \"${this.key}\" was already used for another Message`\n }\n}\n\n/**\n * `retry` was given a run parked in a history since reset: its sequence names\n * whatever the new history committed there. Dismiss it; if its operation is\n * sent again, it commits and is reacted to in the new history.\n */\nexport class StaleParkedRunError extends Schema.TaggedError<StaleParkedRunError>()(\n 'SyncStaleParkedRunError',\n { reaction: Schema.String, opId: Schema.String },\n) {\n override get message(): string {\n return `The run of ${this.reaction} at ${this.opId} was parked before the document was reset`\n }\n}\n\n/**\n * A committed operation of the document will not read: written at a version\n * this server's history lacks, or at one no step reads. The journal reads a\n * stored row only when it needs it, so this fails what needs that row: an\n * exchange from a replica whose cursor is before it (after appending what\n * that replica sent, which commits, and is acknowledged on a retry once a\n * build reads the row), a retransmission of its id, and, while the row is\n * after the stored snapshot, every append and load of the document. A\n * replica past the row is served. Other documents are not affected.\n * Server-side only: its fields are for the server's logs, and its message,\n * which a socket sends, names neither.\n */\nexport class UnreadableHistoryError extends Schema.TaggedError<UnreadableHistoryError>()(\n 'UnreadableHistoryError',\n {\n documentId: Schema.String,\n opId: Schema.String,\n version: Schema.Number,\n message: Schema.String,\n },\n) {}\n\n/**\n * `replay` threw for a submitted Message, so it could never be applied here or\n * on any other replica; nothing was written.\n */\nexport class ReplayError extends Schema.TaggedError<ReplayError>()('ReplayError', {\n message: Schema.String,\n cause: Schema.optional(Schema.Unknown),\n}) {}\n\nexport type ReplicaError =\n | StorageError\n | ReplayError\n | WrongReplicaStorageError\n | InvalidReplicaHistoryError\n | InvalidExchangeError\n | UnsupportedReplicaVersionError\n | UnsupportedMessageVersionError\n | InvalidOutboxError\n | CheckpointRegressionError\n | CommittedOrderError\n | ForeignRejectionError\n | ForeignAcknowledgementError\n | ReplicaClosedError\n"],"mappings":";;;AAGA,IAAa,eAAb,cAAkC,OAAO,YAA0B,CAAC,CAAC,gBAAgB;CACnF,SAAS,OAAO;CAChB,OAAO,OAAO,SAAS,OAAO,OAAO;AACvC,CAAC,CAAC,CAAC,CAAC;;AAGJ,IAAa,+BAAb,cAAkD,OAAO,YAA0C,CAAC,CAClG,gCACA;CACE,eAAe,OAAO,OAAO,OAAO,MAAM;CAC1C,SAAS,O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;CACb,SAAS,OAAO;CAChB,SAAS,OAAO;AAClB,CACF,CAAC,CAAC,CAAC;;;;;AAMH,IAAa,cAAb,cAAiC,OAAO,YAAyB,CAAC,CAAC,eAAe;CAChF,SAAS,OAAO;CAChB,OAAO,OAAO,SAAS,OAAO,OAAO;AACvC,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { ExchangeFailed, HistoryRebuilt, HostDefect, HostStage, ListenerFailed, ListenerSite, SyncDiagnostic } from "./diagnostics.js";
|
|
1
|
+
import { ExchangeFailed, HistoryRebuilt, HostDefect, HostStage, ListenerFailed, ListenerSite, ReactionFailed, ReactionParked, ReactionSkipped, ServerOnlySubmitted, SyncDiagnostic, UnknownRefusal } from "./diagnostics.js";
|
|
2
2
|
import { ExchangeFrame, ExchangeReply, NotifyFrame, SocketLike, SocketOptions, Transport, TransportError, TransportShape, TransportSocket, layerFromPromise, layerFromPromise as layerFromPromise$1, layerLoopback, layerLoopback as layerLoopback$1, layerSocket, layerSocket as layerSocket$1, nativeSocket, nativeSocket as nativeSocket$1, portSocket, portSocket as portSocket$1, serveSocket, serveSocket as serveSocket$1, toPromise, toPromise as toPromise$1, workerSocket, workerSocket as workerSocket$1 } from "./transport.js";
|
|
3
3
|
import { OutboxEntry, Storage, TabStorageOptions, indexedDb, tabStorage } from "./indexedDb.js";
|
|
4
4
|
import { LwwClock, LwwClockState, lwwRegister, lwwRegister as lwwRegister$1, openLwwClock } from "./lww.js";
|
|
5
|
-
import { ApplicationSync, AuthorizeDecision, AuthorizePolicy, AuthorizeRequest, DefinedSync, FragmentMessages, MakeOptions, MsgOf, PolicyJournalContract, StampPolicy, SyncFragment, forApplication, forApplication as forApplication$1 } from "./make.js";
|
|
5
|
+
import { ApplicationSync, AuthorizeDecision, AuthorizePolicy, AuthorizeRequest, DefinedSync, FragmentMessages, HistoryOption, MakeOptions, MsgOf, PolicyJournalContract, ServerMsgOf, StampPolicy, SyncFragment, forApplication, forApplication as forApplication$1 } from "./make.js";
|
|
6
|
+
import { Migrations, migrations, migrations as migrations$1 } from "./migrations.js";
|
|
6
7
|
import { CommittedView, MountOptions, MountUrl, Mounted, Reinstall, fact, fact as fact$1, mount, mount as mount$1 } from "./mount.js";
|
|
7
8
|
import { Presence, PresenceChannel, PresenceHub, PresenceOptions, PresencePeer, PresenceUpdate, createPresence, createPresenceHub, createPresenceHub as createPresenceHub$1, loopbackPresenceChannel, servePresence, servePresence as servePresence$1, socketPresenceChannel, socketPresenceChannel as socketPresenceChannel$1 } from "./presence.js";
|
|
8
|
-
import { Checkpoint, CommitStamp, CommittedOperation, Exchange, JournalContract, OpenReplicaOptions, Operation, Rejection, Replica, ReplicaSnapshot, ReplicaState, ReplicaStatus, Sync as Sync$1, SyncDefinition, TransportClient, defineSync, defineSync as defineSync$1, syncMetrics } from "./sync.js";
|
|
9
|
+
import { Checkpoint, CommitStamp, CommittedOperation, Exchange, JournalContract, MessageHistory, OpenReplicaOptions, Operation, Rejection, Replica, ReplicaSnapshot, ReplicaState, ReplicaStatus, Sync as Sync$1, SyncDefinition, SyncDefinitionOptions, TransportClient, WrittenOperation, defineSync, defineSync as defineSync$1, syncMetrics } from "./sync.js";
|
|
10
|
+
import { SyncRefusal } from "./refusal.js";
|
|
9
11
|
import { DocumentId, LocalSequence, OpId, ReplicaId, Sequence, documentId, localSequence, opId, replicaId, sequence } from "./ids.js";
|
|
10
|
-
import { CheckpointRegressionError, CommittedOrderError, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, ReplayError, ReplicaClosedError, ReplicaError, StorageError, UnsupportedClockVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError } from "./errors.js";
|
|
12
|
+
import { AmbiguousMessageError, CheckpointRegressionError, CommittedOrderError, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, ReplayError, ReplicaClosedError, ReplicaError, ServerKeyReusedError, ServerOnlyMessageError, StaleParkedRunError, StorageError, UnreadableHistoryError, UnreadableMessageError, UnsupportedClockVersionError, UnsupportedMessageVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError } from "./errors.js";
|
|
11
13
|
/**
|
|
12
14
|
* The contract `Sync.define` and `Sync.forApplication(App).make` produce: the
|
|
13
15
|
* wire codecs, the server journal's contract, and `openReplica`.
|
|
@@ -22,6 +24,8 @@ export declare const Sync: {
|
|
|
22
24
|
forApplication: typeof forApplication$1;
|
|
23
25
|
/** The protocol primitive, for a client with no Foldkit application to derive from. */
|
|
24
26
|
define: typeof defineSync$1;
|
|
27
|
+
/** Starts a document's Message history: `Sync.migrations(V1).next(V2, up)`. */
|
|
28
|
+
migrations: typeof migrations$1;
|
|
25
29
|
/** Runs a Foldkit application over an open replica with one reducer. */
|
|
26
30
|
mount: typeof mount$1;
|
|
27
31
|
/** A Command whose Message the mount applies within the transition that returned it. */
|
|
@@ -102,5 +106,5 @@ export declare const Sync: {
|
|
|
102
106
|
}, import("./errors.js").StorageError | import("./errors.js").UnsupportedClockVersionError, never>;
|
|
103
107
|
};
|
|
104
108
|
};
|
|
105
|
-
export { type ApplicationSync, type AuthorizeDecision, type AuthorizePolicy, type AuthorizeRequest, type Checkpoint, CheckpointRegressionError, type CommitStamp, type CommittedOperation, CommittedOrderError, type CommittedView, type DefinedSync, DocumentId, type Exchange, type ExchangeFailed, type ExchangeFrame, type ExchangeReply, ForeignAcknowledgementError, ForeignRejectionError, type FragmentMessages, type HistoryRebuilt, type HostDefect, type HostStage, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, type JournalContract, type ListenerFailed, type ListenerSite, LocalSequence, type LwwClock, type LwwClockState, type MakeOptions, type MountOptions, type MountUrl, type Mounted, type MsgOf, type NotifyFrame, OpId, type OpenReplicaOptions, type Operation, type OutboxEntry, type PolicyJournalContract, type Presence, type PresenceChannel, type PresenceHub, type PresenceOptions, type PresencePeer, type PresenceUpdate, type Reinstall, type Rejection, ReplayError, type Replica, ReplicaClosedError, type ReplicaError, ReplicaId, type ReplicaSnapshot, type ReplicaState, type ReplicaStatus, Sequence, type SocketLike, type SocketOptions, type StampPolicy, type Storage, StorageError, type SyncDefinition, type SyncDiagnostic, type SyncFragment, type TabStorageOptions, Transport, type TransportClient, TransportError, type TransportShape, TransportSocket, UnsupportedClockVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError, createPresence, createPresenceHub, defineSync, documentId, fact, forApplication, indexedDb, layerFromPromise, layerLoopback, layerSocket, localSequence, loopbackPresenceChannel, lwwRegister, mount, nativeSocket, opId, openLwwClock, portSocket, replicaId, sequence, servePresence, serveSocket, socketPresenceChannel, syncMetrics, tabStorage, toPromise, workerSocket };
|
|
109
|
+
export { AmbiguousMessageError, type ApplicationSync, type AuthorizeDecision, type AuthorizePolicy, type AuthorizeRequest, type Checkpoint, CheckpointRegressionError, type CommitStamp, type CommittedOperation, CommittedOrderError, type CommittedView, type DefinedSync, DocumentId, type Exchange, type ExchangeFailed, type ExchangeFrame, type ExchangeReply, ForeignAcknowledgementError, ForeignRejectionError, type FragmentMessages, type HistoryOption, type HistoryRebuilt, type HostDefect, type HostStage, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, type JournalContract, type ListenerFailed, type ListenerSite, LocalSequence, type LwwClock, type LwwClockState, type MakeOptions, type MessageHistory, type Migrations, type MountOptions, type MountUrl, type Mounted, type MsgOf, type NotifyFrame, OpId, type OpenReplicaOptions, type Operation, type OutboxEntry, type PolicyJournalContract, type Presence, type PresenceChannel, type PresenceHub, type PresenceOptions, type PresencePeer, type PresenceUpdate, type ReactionFailed, type ReactionParked, type ReactionSkipped, type Reinstall, type Rejection, ReplayError, type Replica, ReplicaClosedError, type ReplicaError, ReplicaId, type ReplicaSnapshot, type ReplicaState, type ReplicaStatus, Sequence, ServerKeyReusedError, type ServerMsgOf, ServerOnlyMessageError, type ServerOnlySubmitted, type SocketLike, type SocketOptions, StaleParkedRunError, type StampPolicy, type Storage, StorageError, type SyncDefinition, type SyncDefinitionOptions, type SyncDiagnostic, type SyncFragment, SyncRefusal, type TabStorageOptions, Transport, type TransportClient, TransportError, type TransportShape, TransportSocket, type UnknownRefusal, UnreadableHistoryError, UnreadableMessageError, UnsupportedClockVersionError, UnsupportedMessageVersionError, UnsupportedReplicaVersionError, type WrittenOperation, WrongReplicaStorageError, createPresence, createPresenceHub, defineSync, documentId, fact, forApplication, indexedDb, layerFromPromise, layerLoopback, layerSocket, localSequence, loopbackPresenceChannel, lwwRegister, migrations, mount, nativeSocket, opId, openLwwClock, portSocket, replicaId, sequence, servePresence, serveSocket, socketPresenceChannel, syncMetrics, tabStorage, toPromise, workerSocket };
|
|
106
110
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["SyncContract","forApplication","defineSync","mount","fact","layerSocket","layerLoopback","layerFromPromise","toPromise","serveSocket","workerSocket","nativeSocket","portSocket","createPresenceHub","servePresence","socketPresenceChannel","lwwRegister"],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["SyncContract","forApplication","defineSync","migrations","mount","fact","layerSocket","layerLoopback","layerFromPromise","toPromise","serveSocket","workerSocket","nativeSocket","portSocket","createPresenceHub","servePresence","socketPresenceChannel","lwwRegister"],"sources":["../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;YA2CY,KAAK,SAAS,QAAQ,UAAU,WAAWA,OAAa,SAAS,QAAQ;;qBAGxE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwCT,OAAI,QAAA,iCAAA,gBAAA,oCAAA;;;;;;;;;;;;;;;;;;IAEJ,YAAGc;;IAEH,cAAKC;IACL,sBAAaC;IACb,kBAAe,qCAAA;;;;;;;IAKf,iBAAQC;;IAER,YAAS"}
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,13 @@ import { Transport, TransportError, TransportSocket, layerFromPromise, layerFrom
|
|
|
2
2
|
import { indexedDb, indexedDb as indexedDb$1, tabStorage, tabStorage as tabStorage$1 } from "./indexedDb.js";
|
|
3
3
|
import { lwwRegister, lwwRegister as lwwRegister$1, openLwwClock, openLwwClock as openLwwClock$1 } from "./lww.js";
|
|
4
4
|
import { forApplication, forApplication as forApplication$1 } from "./make.js";
|
|
5
|
+
import { migrations, migrations as migrations$1 } from "./migrations.js";
|
|
5
6
|
import { fact, fact as fact$1, mount, mount as mount$1 } from "./mount.js";
|
|
6
7
|
import { createPresence, createPresence as createPresence$1, createPresenceHub, createPresenceHub as createPresenceHub$1, loopbackPresenceChannel, loopbackPresenceChannel as loopbackPresenceChannel$1, servePresence, servePresence as servePresence$1, socketPresenceChannel, socketPresenceChannel as socketPresenceChannel$1 } from "./presence.js";
|
|
7
8
|
import { defineSync, defineSync as defineSync$1, syncMetrics, syncMetrics as syncMetrics$1 } from "./sync.js";
|
|
9
|
+
import { SyncRefusal } from "./refusal.js";
|
|
8
10
|
import { DocumentId, LocalSequence, OpId, ReplicaId, Sequence, documentId, localSequence, opId, replicaId, sequence } from "./ids.js";
|
|
9
|
-
import { CheckpointRegressionError, CommittedOrderError, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, ReplayError, ReplicaClosedError, StorageError, UnsupportedClockVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError } from "./errors.js";
|
|
11
|
+
import { AmbiguousMessageError, CheckpointRegressionError, CommittedOrderError, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, ReplayError, ReplicaClosedError, ServerKeyReusedError, ServerOnlyMessageError, StaleParkedRunError, StorageError, UnreadableHistoryError, UnreadableMessageError, UnsupportedClockVersionError, UnsupportedMessageVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError } from "./errors.js";
|
|
10
12
|
// src/index.ts
|
|
11
13
|
/**
|
|
12
14
|
* `foldkit-sync` — a local-first replica of a shared Foldkit projection.
|
|
@@ -26,6 +28,8 @@ const Sync = {
|
|
|
26
28
|
forApplication: forApplication$1,
|
|
27
29
|
/** The protocol primitive, for a client with no Foldkit application to derive from. */
|
|
28
30
|
define: defineSync$1,
|
|
31
|
+
/** Starts a document's Message history: `Sync.migrations(V1).next(V2, up)`. */
|
|
32
|
+
migrations: migrations$1,
|
|
29
33
|
/** Runs a Foldkit application over an open replica with one reducer. */
|
|
30
34
|
mount: mount$1,
|
|
31
35
|
/** A Command whose Message the mount applies within the transition that returned it. */
|
|
@@ -72,6 +76,6 @@ const Sync = {
|
|
|
72
76
|
openClock: openLwwClock$1
|
|
73
77
|
}
|
|
74
78
|
};
|
|
75
|
-
export { CheckpointRegressionError, CommittedOrderError, DocumentId, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, LocalSequence, OpId, ReplayError, ReplicaClosedError, ReplicaId, Sequence, StorageError, Sync, Transport, TransportError, TransportSocket, UnsupportedClockVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError, createPresence, createPresenceHub, defineSync, documentId, fact, forApplication, indexedDb, layerFromPromise, layerLoopback, layerSocket, localSequence, loopbackPresenceChannel, lwwRegister, mount, nativeSocket, opId, openLwwClock, portSocket, replicaId, sequence, servePresence, serveSocket, socketPresenceChannel, syncMetrics, tabStorage, toPromise, workerSocket };
|
|
79
|
+
export { AmbiguousMessageError, CheckpointRegressionError, CommittedOrderError, DocumentId, ForeignAcknowledgementError, ForeignRejectionError, InvalidExchangeError, InvalidOutboxError, InvalidReplicaHistoryError, LocalSequence, OpId, ReplayError, ReplicaClosedError, ReplicaId, Sequence, ServerKeyReusedError, ServerOnlyMessageError, StaleParkedRunError, StorageError, Sync, SyncRefusal, Transport, TransportError, TransportSocket, UnreadableHistoryError, UnreadableMessageError, UnsupportedClockVersionError, UnsupportedMessageVersionError, UnsupportedReplicaVersionError, WrongReplicaStorageError, createPresence, createPresenceHub, defineSync, documentId, fact, forApplication, indexedDb, layerFromPromise, layerLoopback, layerSocket, localSequence, loopbackPresenceChannel, lwwRegister, migrations, mount, nativeSocket, opId, openLwwClock, portSocket, replicaId, sequence, servePresence, serveSocket, socketPresenceChannel, syncMetrics, tabStorage, toPromise, workerSocket };
|
|
76
80
|
|
|
77
81
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["defineSync","syncMetrics","layerSocket","layerLoopback","layerFromPromise","serveSocket","createPresence","createPresenceHub","servePresence","socketPresenceChannel","loopbackPresenceChannel","lwwRegister","openLwwClock"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-sync` — a local-first replica of a shared Foldkit projection.\n *\n * The application's Message union and update function stay authoritative: sync\n * wraps them rather than introducing a second reducer. The replica owns the\n * local outbox, optimistic projection, and reconciliation; a durable server\n * journal provides authoritative order.\n *\n * `Sync` is the namespace: `Sync.forApplication`, `Sync.mount`,\n * `Sync.transport.socket`. Ids are branded schemas, so they construct through\n * `DocumentId.make('todos')`. Every name is also exported on its own.\n */\nimport { indexedDb, tabStorage } from './indexedDb.js'\nimport { lwwRegister, openLwwClock } from './lww.js'\nimport { forApplication } from './make.js'\nimport { fact, mount } from './mount.js'\nimport {\n createPresence,\n createPresenceHub,\n loopbackPresenceChannel,\n servePresence,\n socketPresenceChannel,\n} from './presence.js'\nimport { defineSync, syncMetrics, type Sync as SyncContract } from './sync.js'\nimport {\n layerFromPromise,\n layerLoopback,\n layerSocket,\n nativeSocket,\n portSocket,\n serveSocket,\n toPromise,\n workerSocket,\n} from './transport.js'\n\n/**\n * The contract `Sync.define` and `Sync.forApplication(App).make` produce: the\n * wire codecs, the server journal's contract, and `openReplica`.\n *\n * This is the type; `Sync` is also the value namespace below, the way\n * `Effect.Effect` is both.\n */\nexport type Sync<Message, Shared, Durable = Message> = SyncContract<Message, Shared, Durable>\n\n/** The package's public surface, grouped. Each entry is the exported function itself. */\nexport const Sync = {\n /** Derives a sync contract from a Foldkit application: `Sync.forApplication(App).make({…})`. */\n forApplication,\n /** The protocol primitive, for a client with no Foldkit application to derive from. */\n define: defineSync,\n /** Runs a Foldkit application over an open replica with one reducer. */\n mount,\n /** A Command whose Message the mount applies within the transition that returned it. */\n fact,\n /** Counters and a histogram an application can scrape. */\n metrics: syncMetrics,\n /** The storage adapter: one IndexedDB database per replica, named by the caller. */\n indexedDb,\n /** This tab's IndexedDB store, kept across reloads: what a browser opens a replica on. */\n tabStorage,\n\n /** The `Transport` service's layers, and the bridges to and from a promise client. */\n transport: {\n /** A reconnecting WebSocket client layer. */\n socket: layerSocket,\n /** An in-process layer, for tests and single-process demos. */\n loopback: layerLoopback,\n /** Wraps the promise-based client the replica already speaks. */\n fromPromise: layerFromPromise,\n /** Bridges the service back to that promise client. */\n toPromise,\n /** The server side of one accepted socket connection. */\n serve: serveSocket,\n /** The accepted end of a Cloudflare `WebSocketPair`, for `serve`. */\n workerSocket,\n /** The default socket factory: the platform `WebSocket`. */\n nativeSocket,\n /** A socket over a `MessagePort`, closed by `close()` or an abort signal. */\n portSocket,\n },\n\n /** An ephemeral, TTL'd peer registry, deliberately outside the durable log. */\n presence: {\n make: createPresence,\n /** Broadcasts presence updates among connected peers, on the server. */\n hub: createPresenceHub,\n /** Serves presence frames on an accepted socket, stamping the connection's identity. */\n serve: servePresence,\n socketChannel: socketPresenceChannel,\n loopbackChannel: loopbackPresenceChannel,\n },\n\n /** Last-writer-wins registers (experimental): a per-field merge on logical time. */\n lww: {\n register: lwwRegister,\n /** The durable counter a stamp is allocated from, before dispatch. */\n openClock: openLwwClock,\n },\n}\n\nexport type {\n ExchangeFailed,\n HistoryRebuilt,\n HostDefect,\n HostStage,\n ListenerFailed,\n ListenerSite,\n SyncDiagnostic,\n} from './diagnostics.js'\nexport {\n indexedDb,\n tabStorage,\n type OutboxEntry,\n type Storage,\n type TabStorageOptions,\n} from './indexedDb.js'\nexport {\n fact,\n mount,\n type CommittedView,\n type MountOptions,\n type Reinstall,\n type MountUrl,\n type Mounted,\n} from './mount.js'\nexport {\n forApplication,\n type ApplicationSync,\n type AuthorizeDecision,\n type AuthorizePolicy,\n type AuthorizeRequest,\n type DefinedSync,\n type FragmentMessages,\n type MakeOptions,\n type MsgOf,\n type PolicyJournalContract,\n type StampPolicy,\n type SyncFragment,\n} from './make.js'\nexport {\n DocumentId,\n LocalSequence,\n OpId,\n ReplicaId,\n Sequence,\n documentId,\n localSequence,\n opId,\n replicaId,\n sequence,\n} from './ids.js'\nexport {\n CheckpointRegressionError,\n CommittedOrderError,\n ForeignAcknowledgementError,\n ForeignRejectionError,\n InvalidExchangeError,\n InvalidOutboxError,\n InvalidReplicaHistoryError,\n ReplayError,\n ReplicaClosedError,\n StorageError,\n UnsupportedClockVersionError,\n UnsupportedReplicaVersionError,\n WrongReplicaStorageError,\n type ReplicaError,\n} from './errors.js'\nexport { lwwRegister, openLwwClock, type LwwClock, type LwwClockState } from './lww.js'\nexport {\n createPresence,\n createPresenceHub,\n loopbackPresenceChannel,\n servePresence,\n socketPresenceChannel,\n type Presence,\n type PresenceChannel,\n type PresenceHub,\n type PresenceOptions,\n type PresencePeer,\n type PresenceUpdate,\n} from './presence.js'\nexport {\n layerFromPromise,\n layerLoopback,\n layerSocket,\n nativeSocket,\n portSocket,\n serveSocket,\n toPromise,\n workerSocket,\n Transport,\n TransportSocket,\n TransportError,\n type ExchangeFrame,\n type ExchangeReply,\n type NotifyFrame,\n type SocketLike,\n type SocketOptions,\n type TransportShape,\n} from './transport.js'\nexport {\n defineSync,\n syncMetrics,\n type Checkpoint,\n type CommitStamp,\n type CommittedOperation,\n type Exchange,\n type JournalContract,\n type OpenReplicaOptions,\n type Operation,\n type Rejection,\n type Replica,\n type ReplicaSnapshot,\n type ReplicaState,\n type ReplicaStatus,\n type SyncDefinition,\n type TransportClient,\n} from './sync.js'\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["defineSync","syncMetrics","layerSocket","layerLoopback","layerFromPromise","serveSocket","createPresence","createPresenceHub","servePresence","socketPresenceChannel","loopbackPresenceChannel","lwwRegister","openLwwClock"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-sync` — a local-first replica of a shared Foldkit projection.\n *\n * The application's Message union and update function stay authoritative: sync\n * wraps them rather than introducing a second reducer. The replica owns the\n * local outbox, optimistic projection, and reconciliation; a durable server\n * journal provides authoritative order.\n *\n * `Sync` is the namespace: `Sync.forApplication`, `Sync.mount`,\n * `Sync.transport.socket`. Ids are branded schemas, so they construct through\n * `DocumentId.make('todos')`. Every name is also exported on its own.\n */\nimport { indexedDb, tabStorage } from './indexedDb.js'\nimport { lwwRegister, openLwwClock } from './lww.js'\nimport { forApplication } from './make.js'\nimport { migrations } from './migrations.js'\nimport { fact, mount } from './mount.js'\nimport {\n createPresence,\n createPresenceHub,\n loopbackPresenceChannel,\n servePresence,\n socketPresenceChannel,\n} from './presence.js'\nimport { defineSync, syncMetrics, type Sync as SyncContract } from './sync.js'\nimport {\n layerFromPromise,\n layerLoopback,\n layerSocket,\n nativeSocket,\n portSocket,\n serveSocket,\n toPromise,\n workerSocket,\n} from './transport.js'\n\n/**\n * The contract `Sync.define` and `Sync.forApplication(App).make` produce: the\n * wire codecs, the server journal's contract, and `openReplica`.\n *\n * This is the type; `Sync` is also the value namespace below, the way\n * `Effect.Effect` is both.\n */\nexport type Sync<Message, Shared, Durable = Message> = SyncContract<Message, Shared, Durable>\n\n/** The package's public surface, grouped. Each entry is the exported function itself. */\nexport const Sync = {\n /** Derives a sync contract from a Foldkit application: `Sync.forApplication(App).make({…})`. */\n forApplication,\n /** The protocol primitive, for a client with no Foldkit application to derive from. */\n define: defineSync,\n /** Starts a document's Message history: `Sync.migrations(V1).next(V2, up)`. */\n migrations,\n /** Runs a Foldkit application over an open replica with one reducer. */\n mount,\n /** A Command whose Message the mount applies within the transition that returned it. */\n fact,\n /** Counters and a histogram an application can scrape. */\n metrics: syncMetrics,\n /** The storage adapter: one IndexedDB database per replica, named by the caller. */\n indexedDb,\n /** This tab's IndexedDB store, kept across reloads: what a browser opens a replica on. */\n tabStorage,\n\n /** The `Transport` service's layers, and the bridges to and from a promise client. */\n transport: {\n /** A reconnecting WebSocket client layer. */\n socket: layerSocket,\n /** An in-process layer, for tests and single-process demos. */\n loopback: layerLoopback,\n /** Wraps the promise-based client the replica already speaks. */\n fromPromise: layerFromPromise,\n /** Bridges the service back to that promise client. */\n toPromise,\n /** The server side of one accepted socket connection. */\n serve: serveSocket,\n /** The accepted end of a Cloudflare `WebSocketPair`, for `serve`. */\n workerSocket,\n /** The default socket factory: the platform `WebSocket`. */\n nativeSocket,\n /** A socket over a `MessagePort`, closed by `close()` or an abort signal. */\n portSocket,\n },\n\n /** An ephemeral, TTL'd peer registry, deliberately outside the durable log. */\n presence: {\n make: createPresence,\n /** Broadcasts presence updates among connected peers, on the server. */\n hub: createPresenceHub,\n /** Serves presence frames on an accepted socket, stamping the connection's identity. */\n serve: servePresence,\n socketChannel: socketPresenceChannel,\n loopbackChannel: loopbackPresenceChannel,\n },\n\n /** Last-writer-wins registers (experimental): a per-field merge on logical time. */\n lww: {\n register: lwwRegister,\n /** The durable counter a stamp is allocated from, before dispatch. */\n openClock: openLwwClock,\n },\n}\n\nexport type {\n ExchangeFailed,\n HistoryRebuilt,\n HostDefect,\n HostStage,\n ListenerFailed,\n ListenerSite,\n ReactionFailed,\n ReactionParked,\n ReactionSkipped,\n ServerOnlySubmitted,\n SyncDiagnostic,\n UnknownRefusal,\n} from './diagnostics.js'\nexport { SyncRefusal } from './refusal.js'\nexport {\n indexedDb,\n tabStorage,\n type OutboxEntry,\n type Storage,\n type TabStorageOptions,\n} from './indexedDb.js'\nexport {\n fact,\n mount,\n type CommittedView,\n type MountOptions,\n type Reinstall,\n type MountUrl,\n type Mounted,\n} from './mount.js'\nexport {\n forApplication,\n type ApplicationSync,\n type AuthorizeDecision,\n type AuthorizePolicy,\n type AuthorizeRequest,\n type DefinedSync,\n type FragmentMessages,\n type HistoryOption,\n type MakeOptions,\n type MsgOf,\n type PolicyJournalContract,\n type ServerMsgOf,\n type StampPolicy,\n type SyncFragment,\n} from './make.js'\nexport {\n DocumentId,\n LocalSequence,\n OpId,\n ReplicaId,\n Sequence,\n documentId,\n localSequence,\n opId,\n replicaId,\n sequence,\n} from './ids.js'\nexport {\n AmbiguousMessageError,\n CheckpointRegressionError,\n CommittedOrderError,\n ForeignAcknowledgementError,\n ForeignRejectionError,\n InvalidExchangeError,\n InvalidOutboxError,\n InvalidReplicaHistoryError,\n ReplayError,\n ReplicaClosedError,\n ServerKeyReusedError,\n ServerOnlyMessageError,\n StaleParkedRunError,\n StorageError,\n UnreadableHistoryError,\n UnreadableMessageError,\n UnsupportedClockVersionError,\n UnsupportedMessageVersionError,\n UnsupportedReplicaVersionError,\n WrongReplicaStorageError,\n type ReplicaError,\n} from './errors.js'\nexport { migrations, type Migrations } from './migrations.js'\nexport { lwwRegister, openLwwClock, type LwwClock, type LwwClockState } from './lww.js'\nexport {\n createPresence,\n createPresenceHub,\n loopbackPresenceChannel,\n servePresence,\n socketPresenceChannel,\n type Presence,\n type PresenceChannel,\n type PresenceHub,\n type PresenceOptions,\n type PresencePeer,\n type PresenceUpdate,\n} from './presence.js'\nexport {\n layerFromPromise,\n layerLoopback,\n layerSocket,\n nativeSocket,\n portSocket,\n serveSocket,\n toPromise,\n workerSocket,\n Transport,\n TransportSocket,\n TransportError,\n type ExchangeFrame,\n type ExchangeReply,\n type NotifyFrame,\n type SocketLike,\n type SocketOptions,\n type TransportShape,\n} from './transport.js'\nexport {\n defineSync,\n syncMetrics,\n type Checkpoint,\n type CommitStamp,\n type CommittedOperation,\n type Exchange,\n type JournalContract,\n type MessageHistory,\n type OpenReplicaOptions,\n type Operation,\n type Rejection,\n type Replica,\n type ReplicaSnapshot,\n type ReplicaState,\n type ReplicaStatus,\n type SyncDefinition,\n type SyncDefinitionOptions,\n type TransportClient,\n type WrittenOperation,\n} from './sync.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,OAAO;;CAElB,gBAAA;;CAEA,QAAQA;;CAER,YAAA;;CAEA,OAAA;;CAEA,MAAA;;CAEA,SAASC;;CAET,WAAA;;CAEA,YAAA;;CAGA,WAAW;;EAET,QAAQC;;EAER,UAAUC;;EAEV,aAAaC;;EAEb,WAAA;;EAEA,OAAOC;;EAEP,cAAA;;EAEA,cAAA;;EAEA,YAAA;CACF;;CAGA,UAAU;EACR,MAAMC;;EAEN,KAAKC;;EAEL,OAAOC;EACP,eAAeC;EACf,iBAAiBC;CACnB;;CAGA,KAAK;EACH,UAAUC;;EAEV,WAAWC;CACb;AACF"}
|
package/dist/journal.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Cause, Duration, Effect, Layer, Option, Result, Schema } from "effect";
|
|
2
2
|
import { Diagnostic, ReportDiagnostic } from "foldkit-surface";
|
|
3
|
+
import { Journal } from "foldkit-durable/core";
|
|
3
4
|
import { HostDefect, HostStage } from "./diagnostics.js";
|
|
4
5
|
import { SocketLike } from "./transport.js";
|
|
6
|
+
import { Parked, Reaction, ReactionOptions, Requires, ServerJournal, ServerJournal as ServerJournal$1, ServerJournalOptions, Trigger, reaction, serverJournal } from "./serverJournal.js";
|
|
5
7
|
import { AuthorizeDecision } from "./make.js";
|
|
6
|
-
import { Operation, Sync, TransportClient } from "./sync.js";
|
|
7
|
-
import { Journal } from "foldkit-durable/core";
|
|
8
|
+
import { Operation, Sync, TransportClient, WrittenOperation } from "./sync.js";
|
|
8
9
|
import { RemoteUnauthenticated } from "foldkit-remote";
|
|
9
10
|
export interface JournalExchangeOptions<Message, Shared, Principal> {
|
|
10
11
|
/** The document's contract: its codecs, and the snapshot a checkpoint encodes. */
|
|
@@ -13,7 +14,7 @@ export interface JournalExchangeOptions<Message, Shared, Principal> {
|
|
|
13
14
|
* The journal made from `sync.journalContract()`, which orders and keeps the
|
|
14
15
|
* document. One that takes any input, or only operations, is accepted.
|
|
15
16
|
*/
|
|
16
|
-
readonly journal: Journal<Operation, Shared, Principal,
|
|
17
|
+
readonly journal: Journal<Operation, Shared, Principal, WrittenOperation>;
|
|
17
18
|
/**
|
|
18
19
|
* Who is exchanging, as the transport established it. The journal's
|
|
19
20
|
* `authorize` reads it; a refused operation is reported as rejected.
|
|
@@ -43,17 +44,28 @@ export interface JournalExchangeOptions<Message, Shared, Principal> {
|
|
|
43
44
|
readonly admit?: ((operation: Operation) => AuthorizeDecision | Effect.Effect<AuthorizeDecision, unknown>) | undefined;
|
|
44
45
|
/** The most committed operations one reply carries; a replica further behind asks again. Default 500. */
|
|
45
46
|
readonly limit?: number | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Where a `ServerOnlySubmitted` goes: a replica sent a Message only the
|
|
49
|
+
* server appends. The reporter in context when not given, by default the log.
|
|
50
|
+
*/
|
|
51
|
+
readonly diagnostics?: ReportDiagnostic | undefined;
|
|
46
52
|
}
|
|
47
53
|
/**
|
|
48
54
|
* One replica's exchanges with the journal, as the replica's transport
|
|
49
55
|
* speaks them (`Sync.transport.fromPromise`, or behind
|
|
50
56
|
* `Sync.transport.serve` on a socket). Each pending operation is appended in
|
|
51
|
-
* order, and acknowledged once committed, or already
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
+
* order, as received, and acknowledged once committed, or already
|
|
58
|
+
* committed. Every hook (`admit`, and the journal's `validate`, `authorize`,
|
|
59
|
+
* `reduce` and `stamp`) sees its Message upcast to the current version. One
|
|
60
|
+
* is rejected by its id when its message does not decode, it names another
|
|
61
|
+
* document, the journal refuses it (`authorize`, `validate`), or it was
|
|
62
|
+
* written at an older version no step reads (`Unreadable`); the replica drops
|
|
63
|
+
* it, or keeps an unreadable one in `refused`, rather than send it again. An
|
|
64
|
+
* entry written at a version newer than this server's fails the exchange
|
|
65
|
+
* before anything is appended, so its replica waits with its outbox whole; so
|
|
66
|
+
* do an entry with no id at all, a cursor ahead of the journal's, a
|
|
67
|
+
* connection `opens` refuses, `admit` or the journal failing, and a stored
|
|
68
|
+
* operation that will not read (`UnreadableHistoryError`). The reply carries what committed
|
|
57
69
|
* after the replica's cursor, a checkpoint when that history was compacted,
|
|
58
70
|
* and the journal's epoch, so a replica of a reset journal starts again.
|
|
59
71
|
*/
|
|
@@ -65,7 +77,7 @@ export declare const journalExchange: <Message, Shared, Principal>(options: Jour
|
|
|
65
77
|
* the next commit; a commit stream that breaks is reported as `HostDefect`
|
|
66
78
|
* (`Changes`), since no notice follows it.
|
|
67
79
|
*/
|
|
68
|
-
export declare const journalChanges: <Shared, Principal>(journal: Journal<Operation, Shared, Principal,
|
|
80
|
+
export declare const journalChanges: <Shared, Principal>(journal: Journal<Operation, Shared, Principal, WrittenOperation>, documentId: string, options?: {
|
|
69
81
|
/** Where a failure is reported; the default reporter when not given, since this runs outside any context. */
|
|
70
82
|
readonly diagnostics?: ReportDiagnostic | undefined;
|
|
71
83
|
}) => ((listener: () => void) => () => void);
|
|
@@ -94,11 +106,11 @@ declare const TableAheadOfJournalError_base: Schema.Class<TableAheadOfJournalErr
|
|
|
94
106
|
export declare class TableAheadOfJournalError extends TableAheadOfJournalError_base {
|
|
95
107
|
get message(): string;
|
|
96
108
|
}
|
|
97
|
-
export interface EditsJournalOptions<Shared, Principal, Change> {
|
|
109
|
+
export interface EditsJournalOptions<Shared, Principal, Change, Absorbed = never> {
|
|
98
110
|
/** The document whose edits the table reads. */
|
|
99
111
|
readonly documentId: string;
|
|
100
112
|
/** The journal the edits commit to. */
|
|
101
|
-
readonly journal: Journal<Operation, Shared, Principal,
|
|
113
|
+
readonly journal: Journal<Operation, Shared, Principal, WrittenOperation>;
|
|
102
114
|
/**
|
|
103
115
|
* The cells an operation edits, with the sequence its stamp wrote in; none
|
|
104
116
|
* for an operation that edits nothing. An edit committed without a sequence
|
|
@@ -130,13 +142,25 @@ export interface EditsJournalOptions<Shared, Principal, Change> {
|
|
|
130
142
|
/** Whether the snapshot still keeps an edit committed through `through`: whether to absorb. */
|
|
131
143
|
readonly holdsThrough: (snapshot: Shared, through: number) => boolean;
|
|
132
144
|
/**
|
|
133
|
-
*
|
|
134
|
-
* `through
|
|
135
|
-
* edits on hearing
|
|
145
|
+
* Records that the table holds every edit through `through`, as the
|
|
146
|
+
* server: `absorbed(through)` is the server-only Message the replicas drop
|
|
147
|
+
* those edits on hearing, appended under the key `absorbed/<through>`. The
|
|
148
|
+
* log is compacted no further than the server journal's `settledThrough`,
|
|
149
|
+
* so its reactions see every commit first.
|
|
150
|
+
*/
|
|
151
|
+
readonly asServer?: {
|
|
152
|
+
readonly journal: ServerJournal$1<Absorbed, any>;
|
|
153
|
+
readonly absorbed: (through: number) => Absorbed;
|
|
154
|
+
} | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated Declare the Message `serverOnly` and pass `asServer`; removed
|
|
157
|
+
* in the next release. The server's operation saying the table holds every
|
|
158
|
+
* edit through `through`, sequenced from `cursor`, the journal's, appended
|
|
159
|
+
* as written.
|
|
136
160
|
*/
|
|
137
|
-
readonly absorbed
|
|
138
|
-
/**
|
|
139
|
-
readonly server
|
|
161
|
+
readonly absorbed?: ((through: number, cursor: number) => WrittenOperation) | undefined;
|
|
162
|
+
/** @deprecated With `absorbed`: who the server commits it as. */
|
|
163
|
+
readonly server?: Principal | undefined;
|
|
140
164
|
}
|
|
141
165
|
/**
|
|
142
166
|
* The table as the journal's read model: `settle` applies each committed
|
|
@@ -144,13 +168,14 @@ export interface EditsJournalOptions<Shared, Principal, Change> {
|
|
|
144
168
|
* journal what the table holds and compacts the log behind it. For
|
|
145
169
|
* `journalExchange`'s `settle`, and a clock that absorbs.
|
|
146
170
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
171
|
+
* How far the table holds is a cursor the journal stores (`journal.cursors`),
|
|
172
|
+
* started at the journal's floor, where compaction left it, so a server
|
|
173
|
+
* restarted over a journal that outlived it neither walks the log again nor
|
|
174
|
+
* asks for history that is gone. Intents are keyed by the journal's epoch as
|
|
175
|
+
* well as the operation, so after a reset an operation sent again is applied
|
|
176
|
+
* again, not taken as already run.
|
|
152
177
|
*/
|
|
153
|
-
export declare const editsJournal: <Shared, Principal, Change>(options: EditsJournalOptions<Shared, Principal, Change>) => {
|
|
178
|
+
export declare const editsJournal: <Shared, Principal, Change, Absorbed = never>(options: EditsJournalOptions<Shared, Principal, Change, Absorbed>) => {
|
|
154
179
|
readonly settle: Effect.Effect<void, unknown>;
|
|
155
180
|
readonly absorb: Effect.Effect<void, unknown>;
|
|
156
181
|
};
|
|
@@ -176,7 +201,7 @@ export interface DocumentHostOptions<Message, Shared, Principal, RP = never> {
|
|
|
176
201
|
* The document's journal, asked on each upgrade a principal passed; keep
|
|
177
202
|
* it open between calls. A rejection answers the upgrade with a 500.
|
|
178
203
|
*/
|
|
179
|
-
readonly journal: () => Promise<Journal<Operation, Shared, Principal,
|
|
204
|
+
readonly journal: () => Promise<Journal<Operation, Shared, Principal, WrittenOperation>>;
|
|
180
205
|
/**
|
|
181
206
|
* Who is opening the socket, from the upgrade request. Fails with a
|
|
182
207
|
* `RemoteUnauthenticated` (`RemoteServer.unauthenticated()`) to refuse it:
|
|
@@ -198,7 +223,7 @@ export interface DocumentHostOptions<Message, Shared, Principal, RP = never> {
|
|
|
198
223
|
readonly key?: ((principal: Principal) => unknown) | undefined;
|
|
199
224
|
} | undefined;
|
|
200
225
|
/** After each exchange's appends, given the journal. See `journalExchange`'s `settle`. */
|
|
201
|
-
readonly settle?: ((journal: Journal<Operation, Shared, Principal,
|
|
226
|
+
readonly settle?: ((journal: Journal<Operation, Shared, Principal, WrittenOperation>) => Effect.Effect<void, unknown>) | undefined;
|
|
202
227
|
/** Whether `principal` may open the document. See `journalExchange`'s `opens`. */
|
|
203
228
|
readonly opens?: ((principal: Principal) => Effect.Effect<boolean>) | undefined;
|
|
204
229
|
/** Whether an operation from `principal` may be appended. See `journalExchange`'s `admit`. */
|
|
@@ -234,5 +259,5 @@ export type DocumentHostOptionsLayer<RP> = [RP] extends [never] ? {
|
|
|
234
259
|
* never will, which releases what the upgrade built.
|
|
235
260
|
*/
|
|
236
261
|
export declare const documentHost: <Message, Shared, Principal, RP = never>(options: DocumentHostOptions<Message, Shared, Principal, RP> & DocumentHostOptionsLayer<RP>) => ((request: Request) => Promise<Result.Result<Accepted, Response>>);
|
|
237
|
-
export type
|
|
262
|
+
export { type HostDefect, type HostStage, type Parked, type Reaction, type ReactionOptions, type Requires, type ServerJournal, type ServerJournalOptions, type Trigger, reaction, serverJournal };
|
|
238
263
|
//# sourceMappingURL=journal.d.ts.map
|
package/dist/journal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"journal.d.ts","names":[],"sources":["../src/journal.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"journal.d.ts","names":["ServerJournal"],"sources":["../src/journal.ts"],"mappings":";;;;;;;;;iBAsEiB,uBAAuB,SAAS,QAAQ;;WAE9C,MAAM,KAAK,SAAS;;;;;WAKpB,SAAS,QAAQ,WAAW,QAAQ,WAAW;;;;;WAK/C,WAAW;;;;;;WAMX,SAAS,OAAO;;;;;;WAMhB,QAAQ,OAAO;;;;;;;;;;WAUf,UACH,WAAW,cAAc,oBAAoB,OAAO,OAAO;;WAGxD;;;;;WAKA,cAAc;;;;;;;;;;;;;;;;;;;;;qBAqFZ,kBAAmB,SAAS,QAAQ,WAAS,SAC/C,uBAAuB,SAAS,QAAQ,eAChD;;;;;;;;qBAqNU,iBACV,QAAQ,WAAS,SACP,QAAQ,WAAW,QAAQ,WAAW,mBAAiB,oBAC9C;;WAGP,cAAc;QAEtB;;;;;;qBA0BM,eAAgB,SAAS,QAAQ,WAAS,QAC7C,YAAU,SACT,uBAAuB,SAAS,QAAQ;;;;;WAKtC,cAAc;;;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