@peerbit/native-backbone 0.1.2 → 0.1.3
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/wasm/native_backbone.d.ts +64 -64
- package/dist/wasm/native_backbone.js +3 -0
- package/dist/wasm/native_backbone_bg.wasm +0 -0
- package/dist/wasm/native_backbone_bg.wasm.d.ts +64 -64
- package/package.json +1 -1
- package/src/append_tx/committed_latest.rs +390 -317
- package/src/append_tx/committed_no_next.rs +66 -64
- package/src/append_tx/facts.rs +213 -147
- package/src/append_tx/mod.rs +160 -58
- package/src/append_tx/storage.rs +52 -28
- package/src/coordinates.rs +135 -44
- package/src/documents.rs +340 -100
- package/src/error.rs +244 -0
- package/src/js_interop.rs +230 -90
- package/src/lib.rs +4 -0
- package/src/raw_receive.rs +182 -107
- package/src/shared_log_plan.rs +65 -23
- package/src/sync_send.rs +19 -3
- package/src/time.rs +14 -0
- package/src/wire_sync.rs +147 -36
package/src/error.rs
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
use peerbit_indexer_core::persistence::DecodeError;
|
|
2
|
+
use peerbit_indexer_core::schema::SchemaError;
|
|
3
|
+
use peerbit_indexer_core::wire::WireError;
|
|
4
|
+
use peerbit_log_rust::LogError;
|
|
5
|
+
use peerbit_shared_log_rust::SharedLogError;
|
|
6
|
+
use wasm_bindgen::JsValue;
|
|
7
|
+
|
|
8
|
+
/// Error type for the native backbone core. Every failure path in the core
|
|
9
|
+
/// modules reports one of these variants instead of constructing a
|
|
10
|
+
/// `JsValue`, so the crate can be consumed as a plain rlib on non-wasm
|
|
11
|
+
/// targets without aborting the process. The `Display` output reproduces
|
|
12
|
+
/// the exact message strings historically thrown across the wasm boundary.
|
|
13
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
14
|
+
pub enum BackboneError {
|
|
15
|
+
Expected(&'static str),
|
|
16
|
+
ExpectedArray(&'static str),
|
|
17
|
+
ExpectedString(&'static str),
|
|
18
|
+
ExpectedBoolean(&'static str),
|
|
19
|
+
ExpectedNumber(&'static str),
|
|
20
|
+
ExpectedBytes(&'static str),
|
|
21
|
+
ExpectedU64String(&'static str),
|
|
22
|
+
ExpectedStringArray,
|
|
23
|
+
ExpectedBytesArray,
|
|
24
|
+
ExpectedUnsignedIntegerArray,
|
|
25
|
+
MismatchedInputLengths(&'static str),
|
|
26
|
+
MismatchedCompactCoordinateFacts(&'static str),
|
|
27
|
+
MustBeNumber(&'static str),
|
|
28
|
+
MustBeArray(&'static str),
|
|
29
|
+
MissingOrInvalid(&'static str),
|
|
30
|
+
HashDigestTooShortU32,
|
|
31
|
+
HashDigestTooShortU64,
|
|
32
|
+
ResolutionMustBeU32OrU64,
|
|
33
|
+
ExpectedReservedBytes,
|
|
34
|
+
WireSyncStashFrameTaken,
|
|
35
|
+
WireSyncPinnedEntryMissing,
|
|
36
|
+
CoordinateCountOverflow,
|
|
37
|
+
Truncated(&'static str),
|
|
38
|
+
InvalidBool(&'static str),
|
|
39
|
+
InvalidProjectionOptionMarker,
|
|
40
|
+
UnsupportedDocumentProjectionFieldType,
|
|
41
|
+
UnsupportedProjectedDocumentFieldType,
|
|
42
|
+
ProjectionValueOutputTypeMismatch,
|
|
43
|
+
DocumentProjectionPlanLengthMismatch,
|
|
44
|
+
ProjectionPlanLengthMismatch,
|
|
45
|
+
TrailingDocumentSignerFactBytes,
|
|
46
|
+
MissingDocumentVariant,
|
|
47
|
+
InvalidDocumentVariant,
|
|
48
|
+
DocumentVariantMismatch,
|
|
49
|
+
UnsupportedDocumentVariantType,
|
|
50
|
+
MissingOutputVariant,
|
|
51
|
+
InvalidOutputVariant,
|
|
52
|
+
UnsupportedOutputVariantType,
|
|
53
|
+
UnsupportedContextProjectionSource,
|
|
54
|
+
UnsupportedProjectionSourceKind,
|
|
55
|
+
PlainPutPayloadTooShort,
|
|
56
|
+
PlainPutPayloadLengthMismatch,
|
|
57
|
+
DocumentContextSuffixCapacityOverflow,
|
|
58
|
+
DocumentSchemaIrNotConfigured,
|
|
59
|
+
MissingCachedDocumentProjectionPlan,
|
|
60
|
+
MissingPlainPutPayloadForDocumentIndex,
|
|
61
|
+
MissingPlainPutPayloadForDocumentProjection,
|
|
62
|
+
MissingDocumentContextField(&'static str),
|
|
63
|
+
MaxReplicasMustBeNumber,
|
|
64
|
+
RawReceiveOriginalIndexOverflow,
|
|
65
|
+
RawReceiveSelectedIndexOverflow,
|
|
66
|
+
RawReceiveGroupIndexOverflow,
|
|
67
|
+
MissingPreparedRawReceiveEntry,
|
|
68
|
+
MismatchedPreparedRawReceiveVerifyLengths,
|
|
69
|
+
MissingPartialVerifyHashes,
|
|
70
|
+
Wire(WireError),
|
|
71
|
+
SharedLog(SharedLogError),
|
|
72
|
+
Schema(SchemaError),
|
|
73
|
+
Decode(DecodeError),
|
|
74
|
+
Log(LogError),
|
|
75
|
+
Message(String),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
impl std::fmt::Display for BackboneError {
|
|
79
|
+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
80
|
+
match self {
|
|
81
|
+
BackboneError::Expected(label) => write!(f, "Expected {label}"),
|
|
82
|
+
BackboneError::ExpectedArray(label) => write!(f, "Expected {label} array"),
|
|
83
|
+
BackboneError::ExpectedString(label) => write!(f, "Expected {label} string"),
|
|
84
|
+
BackboneError::ExpectedBoolean(label) => write!(f, "Expected {label} boolean"),
|
|
85
|
+
BackboneError::ExpectedNumber(label) => write!(f, "Expected {label} number"),
|
|
86
|
+
BackboneError::ExpectedBytes(label) => write!(f, "Expected {label} bytes"),
|
|
87
|
+
BackboneError::ExpectedU64String(label) => {
|
|
88
|
+
write!(f, "Expected {label} u64 string")
|
|
89
|
+
}
|
|
90
|
+
BackboneError::ExpectedStringArray => f.write_str("Expected string array"),
|
|
91
|
+
BackboneError::ExpectedBytesArray => f.write_str("Expected bytes array"),
|
|
92
|
+
BackboneError::ExpectedUnsignedIntegerArray => {
|
|
93
|
+
f.write_str("Expected unsigned integer array")
|
|
94
|
+
}
|
|
95
|
+
BackboneError::MismatchedInputLengths(label) => {
|
|
96
|
+
write!(f, "Mismatched {label} input lengths")
|
|
97
|
+
}
|
|
98
|
+
BackboneError::MismatchedCompactCoordinateFacts(label) => f.write_str(label),
|
|
99
|
+
BackboneError::MustBeNumber(label) => write!(f, "{label} must be a number"),
|
|
100
|
+
BackboneError::MustBeArray(field) => write!(f, "{field} must be an array"),
|
|
101
|
+
BackboneError::MissingOrInvalid(field) => write!(f, "Missing or invalid {field}"),
|
|
102
|
+
BackboneError::HashDigestTooShortU32 => {
|
|
103
|
+
f.write_str("hash digest must have at least 4 bytes")
|
|
104
|
+
}
|
|
105
|
+
BackboneError::HashDigestTooShortU64 => {
|
|
106
|
+
f.write_str("hash digest must have at least 8 bytes")
|
|
107
|
+
}
|
|
108
|
+
BackboneError::ResolutionMustBeU32OrU64 => f.write_str("resolution must be u32 or u64"),
|
|
109
|
+
BackboneError::ExpectedReservedBytes => f.write_str("expected 4 reserved bytes"),
|
|
110
|
+
BackboneError::WireSyncStashFrameTaken => {
|
|
111
|
+
f.write_str("wire sync stash frame already taken")
|
|
112
|
+
}
|
|
113
|
+
BackboneError::WireSyncPinnedEntryMissing => {
|
|
114
|
+
f.write_str("wire sync pinned stash entry missing")
|
|
115
|
+
}
|
|
116
|
+
BackboneError::CoordinateCountOverflow => f.write_str("Coordinate count overflow"),
|
|
117
|
+
BackboneError::Truncated(label) => write!(f, "Truncated {label}"),
|
|
118
|
+
BackboneError::InvalidBool(label) => write!(f, "Invalid bool {label}"),
|
|
119
|
+
BackboneError::InvalidProjectionOptionMarker => {
|
|
120
|
+
f.write_str("Invalid projection option marker")
|
|
121
|
+
}
|
|
122
|
+
BackboneError::UnsupportedDocumentProjectionFieldType => {
|
|
123
|
+
f.write_str("Unsupported document projection field type")
|
|
124
|
+
}
|
|
125
|
+
BackboneError::UnsupportedProjectedDocumentFieldType => {
|
|
126
|
+
f.write_str("Unsupported projected document field type")
|
|
127
|
+
}
|
|
128
|
+
BackboneError::ProjectionValueOutputTypeMismatch => {
|
|
129
|
+
f.write_str("Projection value does not match output type")
|
|
130
|
+
}
|
|
131
|
+
BackboneError::DocumentProjectionPlanLengthMismatch => {
|
|
132
|
+
f.write_str("Document projection plan length mismatch")
|
|
133
|
+
}
|
|
134
|
+
BackboneError::ProjectionPlanLengthMismatch => {
|
|
135
|
+
f.write_str("Projection plan length mismatch")
|
|
136
|
+
}
|
|
137
|
+
BackboneError::TrailingDocumentSignerFactBytes => {
|
|
138
|
+
f.write_str("Trailing document signer fact bytes")
|
|
139
|
+
}
|
|
140
|
+
BackboneError::MissingDocumentVariant => f.write_str("Missing document variant"),
|
|
141
|
+
BackboneError::InvalidDocumentVariant => f.write_str("Invalid document variant"),
|
|
142
|
+
BackboneError::DocumentVariantMismatch => f.write_str("Document variant mismatch"),
|
|
143
|
+
BackboneError::UnsupportedDocumentVariantType => {
|
|
144
|
+
f.write_str("Unsupported document variant type")
|
|
145
|
+
}
|
|
146
|
+
BackboneError::MissingOutputVariant => f.write_str("Missing output variant"),
|
|
147
|
+
BackboneError::InvalidOutputVariant => f.write_str("Invalid output variant"),
|
|
148
|
+
BackboneError::UnsupportedOutputVariantType => {
|
|
149
|
+
f.write_str("Unsupported output variant type")
|
|
150
|
+
}
|
|
151
|
+
BackboneError::UnsupportedContextProjectionSource => {
|
|
152
|
+
f.write_str("Unsupported context projection source")
|
|
153
|
+
}
|
|
154
|
+
BackboneError::UnsupportedProjectionSourceKind => {
|
|
155
|
+
f.write_str("Unsupported projection source kind")
|
|
156
|
+
}
|
|
157
|
+
BackboneError::PlainPutPayloadTooShort => f.write_str("Plain put payload is too short"),
|
|
158
|
+
BackboneError::PlainPutPayloadLengthMismatch => {
|
|
159
|
+
f.write_str("Plain put payload length mismatch")
|
|
160
|
+
}
|
|
161
|
+
BackboneError::DocumentContextSuffixCapacityOverflow => {
|
|
162
|
+
f.write_str("Document context suffix capacity overflow")
|
|
163
|
+
}
|
|
164
|
+
BackboneError::DocumentSchemaIrNotConfigured => {
|
|
165
|
+
f.write_str("Native backbone document schema IR has not been configured")
|
|
166
|
+
}
|
|
167
|
+
BackboneError::MissingCachedDocumentProjectionPlan => {
|
|
168
|
+
f.write_str("Missing cached document projection plan")
|
|
169
|
+
}
|
|
170
|
+
BackboneError::MissingPlainPutPayloadForDocumentIndex => {
|
|
171
|
+
f.write_str("Missing plain put payload for document index")
|
|
172
|
+
}
|
|
173
|
+
BackboneError::MissingPlainPutPayloadForDocumentProjection => {
|
|
174
|
+
f.write_str("Missing plain put payload for document projection")
|
|
175
|
+
}
|
|
176
|
+
BackboneError::MissingDocumentContextField(label) => {
|
|
177
|
+
write!(f, "Missing document context {label} field")
|
|
178
|
+
}
|
|
179
|
+
BackboneError::MaxReplicasMustBeNumber => f.write_str("maxReplicas must be a number"),
|
|
180
|
+
BackboneError::RawReceiveOriginalIndexOverflow => {
|
|
181
|
+
f.write_str("Raw receive original index overflow")
|
|
182
|
+
}
|
|
183
|
+
BackboneError::RawReceiveSelectedIndexOverflow => {
|
|
184
|
+
f.write_str("Raw receive selected index overflow")
|
|
185
|
+
}
|
|
186
|
+
BackboneError::RawReceiveGroupIndexOverflow => {
|
|
187
|
+
f.write_str("Raw receive group index overflow")
|
|
188
|
+
}
|
|
189
|
+
BackboneError::MissingPreparedRawReceiveEntry => {
|
|
190
|
+
f.write_str("Missing prepared raw receive entry")
|
|
191
|
+
}
|
|
192
|
+
BackboneError::MismatchedPreparedRawReceiveVerifyLengths => {
|
|
193
|
+
f.write_str("Expected equal prepared raw receive verify lengths")
|
|
194
|
+
}
|
|
195
|
+
BackboneError::MissingPartialVerifyHashes => {
|
|
196
|
+
f.write_str("Missing partial verify hashes")
|
|
197
|
+
}
|
|
198
|
+
BackboneError::Wire(error) => write!(f, "{error}"),
|
|
199
|
+
BackboneError::SharedLog(error) => write!(f, "{error}"),
|
|
200
|
+
BackboneError::Schema(error) => write!(f, "{error}"),
|
|
201
|
+
BackboneError::Decode(error) => write!(f, "{error}"),
|
|
202
|
+
BackboneError::Log(error) => write!(f, "{error}"),
|
|
203
|
+
BackboneError::Message(message) => f.write_str(message),
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
impl std::error::Error for BackboneError {}
|
|
209
|
+
|
|
210
|
+
impl From<WireError> for BackboneError {
|
|
211
|
+
fn from(error: WireError) -> Self {
|
|
212
|
+
BackboneError::Wire(error)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
impl From<SchemaError> for BackboneError {
|
|
217
|
+
fn from(error: SchemaError) -> Self {
|
|
218
|
+
BackboneError::Schema(error)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
impl From<DecodeError> for BackboneError {
|
|
223
|
+
fn from(error: DecodeError) -> Self {
|
|
224
|
+
BackboneError::Decode(error)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
impl From<LogError> for BackboneError {
|
|
229
|
+
fn from(error: LogError) -> Self {
|
|
230
|
+
BackboneError::Log(error)
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
impl From<SharedLogError> for BackboneError {
|
|
235
|
+
fn from(error: SharedLogError) -> Self {
|
|
236
|
+
BackboneError::SharedLog(error)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
impl From<BackboneError> for JsValue {
|
|
241
|
+
fn from(error: BackboneError) -> Self {
|
|
242
|
+
JsValue::from_str(&error.to_string())
|
|
243
|
+
}
|
|
244
|
+
}
|