@graffiti-garden/implementation-decentralized 0.1.3 → 0.1.4
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/1-services/4-inboxes/cache.d.ts +34 -0
- package/dist/1-services/4-inboxes/cache.d.ts.map +1 -0
- package/dist/1-services/4-inboxes/messages.d.ts +70 -0
- package/dist/1-services/4-inboxes/messages.d.ts.map +1 -0
- package/dist/1-services/4-inboxes.d.ts +28 -67
- package/dist/1-services/4-inboxes.d.ts.map +1 -1
- package/dist/3-protocol/4-graffiti.d.ts +1 -0
- package/dist/3-protocol/4-graffiti.d.ts.map +1 -1
- package/dist/browser/index.js +7 -7
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/1-services/4-inboxes/cache.js +186 -0
- package/dist/cjs/1-services/4-inboxes/cache.js.map +7 -0
- package/dist/cjs/1-services/4-inboxes/messages.js +69 -0
- package/dist/cjs/1-services/4-inboxes/messages.js.map +7 -0
- package/dist/cjs/1-services/4-inboxes-tests.js +339 -9
- package/dist/cjs/1-services/4-inboxes-tests.js.map +3 -3
- package/dist/cjs/1-services/4-inboxes.js +210 -399
- package/dist/cjs/1-services/4-inboxes.js.map +3 -3
- package/dist/cjs/3-protocol/4-graffiti.js +19 -10
- package/dist/cjs/3-protocol/4-graffiti.js.map +2 -2
- package/dist/cjs/index.spec.js +1 -0
- package/dist/cjs/index.spec.js.map +2 -2
- package/dist/esm/1-services/4-inboxes/cache.js +156 -0
- package/dist/esm/1-services/4-inboxes/cache.js.map +7 -0
- package/dist/esm/1-services/4-inboxes/messages.js +60 -0
- package/dist/esm/1-services/4-inboxes/messages.js.map +7 -0
- package/dist/esm/1-services/4-inboxes-tests.js +340 -10
- package/dist/esm/1-services/4-inboxes-tests.js.map +3 -3
- package/dist/esm/1-services/4-inboxes.js +222 -383
- package/dist/esm/1-services/4-inboxes.js.map +3 -3
- package/dist/esm/3-protocol/4-graffiti.js +19 -10
- package/dist/esm/3-protocol/4-graffiti.js.map +2 -2
- package/dist/esm/index.spec.js +2 -1
- package/dist/esm/index.spec.js.map +2 -2
- package/package.json +1 -1
- package/src/1-services/4-inboxes/cache.ts +227 -0
- package/src/1-services/4-inboxes/messages.ts +63 -0
- package/src/1-services/4-inboxes-tests.ts +387 -2
- package/src/1-services/4-inboxes.ts +297 -512
- package/src/3-protocol/4-graffiti.ts +26 -10
- package/src/index.spec.ts +3 -1
|
@@ -1191,6 +1191,19 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1191
1191
|
}
|
|
1192
1192
|
}
|
|
1193
1193
|
|
|
1194
|
+
// Labeling is advisory and should not hold up discovery, but its failure
|
|
1195
|
+
// must be handled even if the caller has already stopped reading the stream.
|
|
1196
|
+
protected labelInboxMessage(
|
|
1197
|
+
inboxEndpoint: string,
|
|
1198
|
+
messageId: string,
|
|
1199
|
+
label: number,
|
|
1200
|
+
inboxToken?: string | null,
|
|
1201
|
+
): void {
|
|
1202
|
+
void this.inboxes.label(inboxEndpoint, messageId, label, inboxToken).catch(
|
|
1203
|
+
(error) => console.error("Could not label inbox message:", error),
|
|
1204
|
+
);
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1194
1207
|
protected async processOneLabeledMessage<Schema extends JSONSchema>(
|
|
1195
1208
|
inboxEndpoint: string,
|
|
1196
1209
|
result: LabeledMessage<Schema>,
|
|
@@ -1214,7 +1227,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1214
1227
|
const metadataRaw = dagCborDecode(metadataBytes);
|
|
1215
1228
|
metadata = MessageMetadataSchema.parse(metadataRaw);
|
|
1216
1229
|
} catch (e) {
|
|
1217
|
-
this.
|
|
1230
|
+
this.labelInboxMessage(
|
|
1218
1231
|
inboxEndpoint,
|
|
1219
1232
|
messageId,
|
|
1220
1233
|
MESSAGE_LABEL_INVALID,
|
|
@@ -1267,7 +1280,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1267
1280
|
// device and the device cache is out of date.
|
|
1268
1281
|
if (past[LABELED_MESSAGE_LABEL_KEY] !== MESSAGE_LABEL_TRASH) {
|
|
1269
1282
|
// Label the message as trash
|
|
1270
|
-
this.
|
|
1283
|
+
this.labelInboxMessage(
|
|
1271
1284
|
inboxEndpoint,
|
|
1272
1285
|
tombstonedMessageId,
|
|
1273
1286
|
MESSAGE_LABEL_TRASH,
|
|
@@ -1343,7 +1356,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1343
1356
|
if (tombstonedMessageId) {
|
|
1344
1357
|
if (validationError instanceof GraffitiErrorNotFound) {
|
|
1345
1358
|
// Not found == The tombstone is correct
|
|
1346
|
-
this.inboxes
|
|
1359
|
+
void this.inboxes
|
|
1347
1360
|
// Get the referenced message
|
|
1348
1361
|
.get(inboxEndpoint, tombstonedMessageId, inboxToken)
|
|
1349
1362
|
.then((result) => {
|
|
@@ -1356,7 +1369,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1356
1369
|
result[LABELED_MESSAGE_LABEL_KEY] !== MESSAGE_LABEL_TRASH
|
|
1357
1370
|
) {
|
|
1358
1371
|
// If valid but not yet trash, label the message as trash
|
|
1359
|
-
this.
|
|
1372
|
+
this.labelInboxMessage(
|
|
1360
1373
|
inboxEndpoint,
|
|
1361
1374
|
tombstonedMessageId,
|
|
1362
1375
|
MESSAGE_LABEL_TRASH,
|
|
@@ -1365,13 +1378,16 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1365
1378
|
}
|
|
1366
1379
|
|
|
1367
1380
|
// Then, label the tombstone message as trash
|
|
1368
|
-
this.
|
|
1381
|
+
this.labelInboxMessage(
|
|
1369
1382
|
inboxEndpoint,
|
|
1370
1383
|
messageId,
|
|
1371
1384
|
MESSAGE_LABEL_TRASH,
|
|
1372
1385
|
inboxToken,
|
|
1373
1386
|
);
|
|
1374
|
-
})
|
|
1387
|
+
})
|
|
1388
|
+
.catch((error) =>
|
|
1389
|
+
console.error("Could not inspect tombstone message:", error),
|
|
1390
|
+
);
|
|
1375
1391
|
|
|
1376
1392
|
return {
|
|
1377
1393
|
messageId,
|
|
@@ -1385,7 +1401,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1385
1401
|
} else {
|
|
1386
1402
|
console.error("Recieved an incorrect tombstone object");
|
|
1387
1403
|
console.error(validationError);
|
|
1388
|
-
this.
|
|
1404
|
+
this.labelInboxMessage(
|
|
1389
1405
|
inboxEndpoint,
|
|
1390
1406
|
messageId,
|
|
1391
1407
|
MESSAGE_LABEL_INVALID,
|
|
@@ -1394,7 +1410,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1394
1410
|
}
|
|
1395
1411
|
} else {
|
|
1396
1412
|
if (validationError === undefined) {
|
|
1397
|
-
this.
|
|
1413
|
+
this.labelInboxMessage(
|
|
1398
1414
|
inboxEndpoint,
|
|
1399
1415
|
messageId,
|
|
1400
1416
|
MESSAGE_LABEL_VALID,
|
|
@@ -1411,7 +1427,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1411
1427
|
} else if (validationError instanceof GraffitiErrorNotFound) {
|
|
1412
1428
|
// Item was deleted before we got a chance to
|
|
1413
1429
|
// validate it. Just label the message as trash.
|
|
1414
|
-
this.
|
|
1430
|
+
this.labelInboxMessage(
|
|
1415
1431
|
inboxEndpoint,
|
|
1416
1432
|
messageId,
|
|
1417
1433
|
MESSAGE_LABEL_TRASH,
|
|
@@ -1420,7 +1436,7 @@ export class GraffitiDecentralized implements Graffiti {
|
|
|
1420
1436
|
} else {
|
|
1421
1437
|
console.error("Recieved an incorrect object");
|
|
1422
1438
|
console.error(validationError);
|
|
1423
|
-
this.
|
|
1439
|
+
this.labelInboxMessage(
|
|
1424
1440
|
inboxEndpoint,
|
|
1425
1441
|
messageId,
|
|
1426
1442
|
MESSAGE_LABEL_INVALID,
|
package/src/index.spec.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { decode as dagCborDecode, encode as dagCborEncode } from "@ipld/dag-cbor
|
|
|
18
18
|
import { Handles } from "./3-protocol/2-handles";
|
|
19
19
|
import { didTests } from "./1-services/2-dids-tests";
|
|
20
20
|
import { storageBucketTests } from "./1-services/3-storage-buckets-tests";
|
|
21
|
-
import { inboxTests } from "./1-services/4-inboxes-tests";
|
|
21
|
+
import { inboxTests, inboxUnitTests } from "./1-services/4-inboxes-tests";
|
|
22
22
|
import { stringEncodingTests } from "./2-primitives/1-string-encoding-tests";
|
|
23
23
|
import { contentAddressesTests } from "./2-primitives/2-content-addresses-tests";
|
|
24
24
|
import { channelAttestationTests } from "./2-primitives/3-channel-attestations-tests";
|
|
@@ -276,3 +276,5 @@ describe("GraffitiDecentralized Tests", () => {
|
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
278
|
});
|
|
279
|
+
|
|
280
|
+
inboxUnitTests();
|