@graffiti-garden/implementation-local 0.6.0 → 0.6.2
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 +4 -1
- package/dist/browser/index.js +2 -20
- package/dist/browser/index.js.map +4 -4
- package/dist/cjs/database.js +166 -129
- package/dist/cjs/database.js.map +3 -3
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/utilities.js.map +2 -2
- package/dist/database.d.ts +10 -4
- package/dist/database.d.ts.map +1 -1
- package/dist/esm/database.js +166 -129
- package/dist/esm/database.js.map +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/utilities.js +0 -1
- package/dist/esm/utilities.js.map +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/utilities.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/database.ts +249 -191
- package/src/index.ts +3 -3
- package/src/utilities.ts +0 -1
package/dist/database.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Graffiti, GraffitiObjectBase, GraffitiObjectUrl, JSONSchema, GraffitiSession,
|
|
1
|
+
import type { Graffiti, GraffitiObjectBase, GraffitiObjectUrl, JSONSchema, GraffitiSession, GraffitiObjectStreamContinue, GraffitiObjectStreamContinueEntry } from "@graffiti-garden/api";
|
|
2
|
+
import { compileGraffitiObjectSchema } from "./utilities.js";
|
|
2
3
|
import type Ajv from "ajv";
|
|
3
4
|
import type { applyPatch } from "fast-json-patch";
|
|
4
5
|
/**
|
|
@@ -83,12 +84,17 @@ export declare class GraffitiLocalDatabase implements Omit<Graffiti, "login" | "
|
|
|
83
84
|
startKeySuffix: string;
|
|
84
85
|
endKeySuffix: string;
|
|
85
86
|
};
|
|
86
|
-
protected
|
|
87
|
+
protected streamObjects<Schema extends JSONSchema>(index: string, startkey: string, endkey: string, validate: ReturnType<typeof compileGraffitiObjectSchema<Schema>>, session: GraffitiSession | undefined | null, ifModifiedSince: number | undefined, channels?: string[], processedIds?: Set<string>): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>>;
|
|
88
|
+
protected discoverMeta<Schema extends JSONSchema>(args: Parameters<typeof Graffiti.prototype.discover<Schema>>, ifModifiedSince?: number): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>, number | undefined>;
|
|
89
|
+
protected recoverOrphansMeta<Schema extends JSONSchema>(args: Parameters<typeof Graffiti.prototype.recoverOrphans<Schema>>, ifModifiedSince?: number): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>, number | undefined>;
|
|
90
|
+
protected discoverCursor(args: Parameters<typeof Graffiti.prototype.discover<{}>>, ifModifiedSince?: number): string;
|
|
91
|
+
protected discoverContinue<Schema extends JSONSchema>(args: Parameters<typeof Graffiti.prototype.discover<Schema>>, ifModifiedSince?: number): GraffitiObjectStreamContinue<Schema>;
|
|
87
92
|
discover: Graffiti["discover"];
|
|
88
|
-
protected
|
|
93
|
+
protected recoverOrphansCursor(args: Parameters<typeof Graffiti.prototype.recoverOrphans<{}>>, ifModifiedSince?: number): string;
|
|
94
|
+
protected recoverOrphansContinue<Schema extends JSONSchema>(args: Parameters<typeof Graffiti.prototype.recoverOrphans<Schema>>, ifModifiedSince?: number): GraffitiObjectStreamContinue<Schema>;
|
|
89
95
|
recoverOrphans: Graffiti["recoverOrphans"];
|
|
90
96
|
channelStats: Graffiti["channelStats"];
|
|
91
|
-
|
|
97
|
+
continueObjectStream: Graffiti["continueObjectStream"];
|
|
92
98
|
}
|
|
93
99
|
export {};
|
|
94
100
|
//# sourceMappingURL=database.d.ts.map
|
package/dist/database.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,
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CAAC,gBAAgB,CAAC,CAsBxC;IAEF,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CA2BpC;IAEF,oBAAoB,EAAE,QAAQ,CAAC,sBAAsB,CAAC,CAiCpD;CACH"}
|
package/dist/esm/database.js
CHANGED
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
compileGraffitiObjectSchema,
|
|
13
13
|
unpackObjectUrl
|
|
14
14
|
} from "./utilities.js";
|
|
15
|
-
import { Repeater } from "@repeaterjs/repeater";
|
|
16
15
|
const DEFAULT_ORIGIN = "graffiti:local:";
|
|
16
|
+
const LAST_MODIFIED_BUFFER = 6e4;
|
|
17
17
|
class GraffitiLocalDatabase {
|
|
18
18
|
db_;
|
|
19
19
|
applyPatch_;
|
|
@@ -79,8 +79,8 @@ class GraffitiLocalDatabase {
|
|
|
79
79
|
get applyPatch() {
|
|
80
80
|
if (!this.applyPatch_) {
|
|
81
81
|
this.applyPatch_ = (async () => {
|
|
82
|
-
const
|
|
83
|
-
return applyPatch;
|
|
82
|
+
const imported = await import("fast-json-patch");
|
|
83
|
+
return imported.applyPatch || imported.default.applyPatch;
|
|
84
84
|
})();
|
|
85
85
|
}
|
|
86
86
|
return this.applyPatch_;
|
|
@@ -373,64 +373,63 @@ class GraffitiLocalDatabase {
|
|
|
373
373
|
endKeySuffix
|
|
374
374
|
};
|
|
375
375
|
}
|
|
376
|
-
|
|
376
|
+
async *streamObjects(index, startkey, endkey, validate, session, ifModifiedSince, channels, processedIds) {
|
|
377
|
+
const showTombstones = ifModifiedSince !== void 0;
|
|
378
|
+
const result = await (await this.db).query(index, {
|
|
379
|
+
startkey,
|
|
380
|
+
endkey,
|
|
381
|
+
include_docs: true
|
|
382
|
+
});
|
|
383
|
+
for (const row of result.rows) {
|
|
384
|
+
const doc = row.doc;
|
|
385
|
+
if (!doc) continue;
|
|
386
|
+
if (processedIds?.has(doc._id)) continue;
|
|
387
|
+
processedIds?.add(doc._id);
|
|
388
|
+
if (!showTombstones && doc.tombstone) continue;
|
|
389
|
+
const object = this.extractGraffitiObject(doc);
|
|
390
|
+
if (channels) {
|
|
391
|
+
if (!isActorAllowedGraffitiObject(object, session)) continue;
|
|
392
|
+
maskGraffitiObject(object, channels, session);
|
|
393
|
+
}
|
|
394
|
+
if (!validate(object)) continue;
|
|
395
|
+
yield doc.tombstone ? {
|
|
396
|
+
tombstone: true,
|
|
397
|
+
object: {
|
|
398
|
+
url: object.url,
|
|
399
|
+
lastModified: object.lastModified
|
|
400
|
+
}
|
|
401
|
+
} : { object };
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
async *discoverMeta(args, ifModifiedSince) {
|
|
405
|
+
const [channels, schema, session] = args;
|
|
406
|
+
const validate = compileGraffitiObjectSchema(await this.ajv, schema);
|
|
377
407
|
const { startKeySuffix, endKeySuffix } = this.queryLastModifiedSuffixes(
|
|
378
408
|
schema,
|
|
379
409
|
ifModifiedSince
|
|
380
410
|
);
|
|
381
|
-
const
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (!ifModifiedSince || object.lastModified > ifModifiedSince) {
|
|
401
|
-
ifModifiedSince = object.lastModified;
|
|
402
|
-
}
|
|
403
|
-
if (processedIds.has(doc._id)) continue;
|
|
404
|
-
processedIds.add(doc._id);
|
|
405
|
-
if (!isActorAllowedGraffitiObject(doc, session)) continue;
|
|
406
|
-
maskGraffitiObject(object, channels, session);
|
|
407
|
-
if (validate(object)) {
|
|
408
|
-
await push({
|
|
409
|
-
value: object,
|
|
410
|
-
...doc.tombstone ? { tombstone: true } : {}
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
stop();
|
|
416
|
-
const cursor = "discover:" + JSON.stringify({
|
|
417
|
-
channels,
|
|
418
|
-
schema,
|
|
419
|
-
ifModifiedSince,
|
|
420
|
-
actor: session?.actor
|
|
421
|
-
});
|
|
422
|
-
return {
|
|
423
|
-
cursor,
|
|
424
|
-
continue: () => this.continueStream(cursor, session)
|
|
425
|
-
};
|
|
426
|
-
})
|
|
427
|
-
);
|
|
428
|
-
return repeater;
|
|
411
|
+
const processedIds = /* @__PURE__ */ new Set();
|
|
412
|
+
const startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
413
|
+
for (const channel of channels) {
|
|
414
|
+
const keyPrefix = encodeURIComponent(channel) + "/";
|
|
415
|
+
const startkey = keyPrefix + startKeySuffix;
|
|
416
|
+
const endkey = keyPrefix + endKeySuffix;
|
|
417
|
+
const iterator = this.streamObjects(
|
|
418
|
+
"indexes/objectsPerChannelAndLastModified",
|
|
419
|
+
startkey,
|
|
420
|
+
endkey,
|
|
421
|
+
validate,
|
|
422
|
+
session,
|
|
423
|
+
ifModifiedSince,
|
|
424
|
+
channels,
|
|
425
|
+
processedIds
|
|
426
|
+
);
|
|
427
|
+
for await (const result of iterator) yield result;
|
|
428
|
+
}
|
|
429
|
+
return startTime - LAST_MODIFIED_BUFFER;
|
|
429
430
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
};
|
|
433
|
-
recoverOrphansMeta(schema, session, ifModifiedSince) {
|
|
431
|
+
async *recoverOrphansMeta(args, ifModifiedSince) {
|
|
432
|
+
const [schema, session] = args;
|
|
434
433
|
const { startKeySuffix, endKeySuffix } = this.queryLastModifiedSuffixes(
|
|
435
434
|
schema,
|
|
436
435
|
ifModifiedSince
|
|
@@ -438,55 +437,104 @@ class GraffitiLocalDatabase {
|
|
|
438
437
|
const keyPrefix = encodeURIComponent(session.actor) + "/";
|
|
439
438
|
const startkey = keyPrefix + startKeySuffix;
|
|
440
439
|
const endkey = keyPrefix + endKeySuffix;
|
|
441
|
-
const
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
440
|
+
const validate = compileGraffitiObjectSchema(await this.ajv, schema);
|
|
441
|
+
const startTime = (/* @__PURE__ */ new Date()).getTime();
|
|
442
|
+
const iterator = this.streamObjects(
|
|
443
|
+
"indexes/orphansPerActorAndLastModified",
|
|
444
|
+
startkey,
|
|
445
|
+
endkey,
|
|
446
|
+
validate,
|
|
447
|
+
session,
|
|
448
|
+
ifModifiedSince
|
|
449
|
+
);
|
|
450
|
+
for await (const result of iterator) yield result;
|
|
451
|
+
return startTime - LAST_MODIFIED_BUFFER;
|
|
452
|
+
}
|
|
453
|
+
discoverCursor(args, ifModifiedSince) {
|
|
454
|
+
return "discover:" + JSON.stringify({
|
|
455
|
+
channels: args[0],
|
|
456
|
+
schema: args[1],
|
|
457
|
+
actor: args[2]?.actor,
|
|
458
|
+
ifModifiedSince
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
async *discoverContinue(args, ifModifiedSince) {
|
|
462
|
+
const iterator = this.discoverMeta(args, ifModifiedSince);
|
|
463
|
+
while (true) {
|
|
464
|
+
const result = await iterator.next();
|
|
465
|
+
if (result.done) {
|
|
466
|
+
const ifModifiedSince2 = result.value;
|
|
467
|
+
return {
|
|
468
|
+
continue: () => this.discoverContinue(args, ifModifiedSince2),
|
|
469
|
+
cursor: this.discoverCursor(args, ifModifiedSince2)
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
yield result.value;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
discover = (...args) => {
|
|
476
|
+
const iterator = this.discoverMeta(args);
|
|
477
|
+
const this_ = this;
|
|
478
|
+
return async function* () {
|
|
479
|
+
while (true) {
|
|
480
|
+
const result = await iterator.next();
|
|
481
|
+
if (result.done) {
|
|
482
|
+
return {
|
|
483
|
+
continue: () => this_.discoverContinue(args, result.value),
|
|
484
|
+
cursor: this_.discoverCursor(args, result.value)
|
|
485
|
+
};
|
|
468
486
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
487
|
+
if (result.value.tombstone) continue;
|
|
488
|
+
yield result.value;
|
|
489
|
+
}
|
|
490
|
+
}();
|
|
491
|
+
};
|
|
492
|
+
recoverOrphansCursor(args, ifModifiedSince) {
|
|
493
|
+
return "orphans:" + JSON.stringify({
|
|
494
|
+
schema: args[0],
|
|
495
|
+
actor: args[1]?.actor,
|
|
496
|
+
ifModifiedSince
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
async *recoverOrphansContinue(args, ifModifiedSince) {
|
|
500
|
+
const iterator = this.recoverOrphansMeta(args, ifModifiedSince);
|
|
501
|
+
while (true) {
|
|
502
|
+
const result = await iterator.next();
|
|
503
|
+
if (result.done) {
|
|
504
|
+
const ifModifiedSince2 = result.value;
|
|
475
505
|
return {
|
|
476
|
-
|
|
477
|
-
|
|
506
|
+
continue: () => this.recoverOrphansContinue(args, ifModifiedSince2),
|
|
507
|
+
cursor: this.recoverOrphansCursor(args, ifModifiedSince2)
|
|
478
508
|
};
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
|
|
509
|
+
}
|
|
510
|
+
yield result.value;
|
|
511
|
+
}
|
|
482
512
|
}
|
|
483
513
|
recoverOrphans = (...args) => {
|
|
484
|
-
|
|
514
|
+
const iterator = this.recoverOrphansMeta(args);
|
|
515
|
+
const this_ = this;
|
|
516
|
+
return async function* () {
|
|
517
|
+
while (true) {
|
|
518
|
+
const result = await iterator.next();
|
|
519
|
+
if (result.done) {
|
|
520
|
+
return {
|
|
521
|
+
continue: () => this_.recoverOrphansContinue(
|
|
522
|
+
args,
|
|
523
|
+
result.value
|
|
524
|
+
),
|
|
525
|
+
cursor: this_.recoverOrphansCursor(args, result.value)
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
if (result.value.tombstone) continue;
|
|
529
|
+
yield result.value;
|
|
530
|
+
}
|
|
531
|
+
}();
|
|
485
532
|
};
|
|
486
533
|
channelStats = (session) => {
|
|
487
|
-
const
|
|
534
|
+
const this_ = this;
|
|
535
|
+
return async function* () {
|
|
488
536
|
const keyPrefix = encodeURIComponent(session.actor) + "/";
|
|
489
|
-
const result = await (await
|
|
537
|
+
const result = await (await this_.db).query("indexes/channelStatsPerActor", {
|
|
490
538
|
startkey: keyPrefix,
|
|
491
539
|
endkey: keyPrefix + "\uFFFF",
|
|
492
540
|
reduce: true,
|
|
@@ -498,54 +546,43 @@ class GraffitiLocalDatabase {
|
|
|
498
546
|
const { count, max: lastModified } = row.value;
|
|
499
547
|
if (typeof count !== "number" || typeof lastModified !== "number")
|
|
500
548
|
continue;
|
|
501
|
-
|
|
549
|
+
yield {
|
|
502
550
|
value: {
|
|
503
551
|
channel: decodeURIComponent(channelEncoded),
|
|
504
552
|
count,
|
|
505
553
|
lastModified
|
|
506
554
|
}
|
|
507
|
-
}
|
|
555
|
+
};
|
|
508
556
|
}
|
|
509
|
-
|
|
510
|
-
const cursor = "channel-stats";
|
|
511
|
-
return {
|
|
512
|
-
cursor,
|
|
513
|
-
continue: () => this.continueStream(
|
|
514
|
-
cursor,
|
|
515
|
-
session
|
|
516
|
-
)
|
|
517
|
-
};
|
|
518
|
-
});
|
|
519
|
-
return repeater;
|
|
557
|
+
}();
|
|
520
558
|
};
|
|
521
|
-
|
|
522
|
-
if (cursor
|
|
523
|
-
|
|
559
|
+
continueObjectStream = (cursor, session) => {
|
|
560
|
+
if (cursor.startsWith("discover:")) {
|
|
561
|
+
const { channels, schema, actor, ifModifiedSince } = JSON.parse(
|
|
562
|
+
cursor.slice("discover:".length)
|
|
563
|
+
);
|
|
564
|
+
if (actor && actor !== session?.actor) {
|
|
524
565
|
throw new GraffitiErrorForbidden(
|
|
525
|
-
"
|
|
566
|
+
"Cannot continue a cursor for another actor"
|
|
526
567
|
);
|
|
527
568
|
}
|
|
528
|
-
return this.
|
|
529
|
-
|
|
569
|
+
return this.discoverContinue(
|
|
570
|
+
[channels, schema, session],
|
|
571
|
+
ifModifiedSince
|
|
572
|
+
);
|
|
573
|
+
} else if (cursor.startsWith("orphans:")) {
|
|
530
574
|
const { schema, actor, ifModifiedSince } = JSON.parse(
|
|
531
|
-
cursor.slice("
|
|
575
|
+
cursor.slice("orphans:".length)
|
|
532
576
|
);
|
|
533
|
-
if (!session ||
|
|
577
|
+
if (!session || actor !== session?.actor) {
|
|
534
578
|
throw new GraffitiErrorForbidden(
|
|
535
|
-
"
|
|
579
|
+
"Cannot continue a cursor for another actor"
|
|
536
580
|
);
|
|
537
581
|
}
|
|
538
|
-
return this.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
cursor.slice("discover:".length)
|
|
582
|
+
return this.recoverOrphansContinue(
|
|
583
|
+
[schema, session],
|
|
584
|
+
ifModifiedSince
|
|
542
585
|
);
|
|
543
|
-
if (session?.actor !== actor) {
|
|
544
|
-
throw new GraffitiErrorForbidden(
|
|
545
|
-
"You must be logged in as the actor same actor who started the stream"
|
|
546
|
-
);
|
|
547
|
-
}
|
|
548
|
-
return this.discoverMeta(channels, schema, session, ifModifiedSince);
|
|
549
586
|
} else {
|
|
550
587
|
throw new GraffitiErrorNotFound("Cursor not found");
|
|
551
588
|
}
|
package/dist/esm/database.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/database.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n Graffiti,\n GraffitiObjectBase,\n GraffitiObjectUrl,\n JSONSchema,\n GraffitiSession,\n GraffitiObject,\n GraffitiStream,\n ChannelStats,\n} from \"@graffiti-garden/api\";\nimport {\n GraffitiErrorNotFound,\n GraffitiErrorSchemaMismatch,\n GraffitiErrorForbidden,\n GraffitiErrorPatchError,\n} from \"@graffiti-garden/api\";\nimport {\n randomBase64,\n applyGraffitiPatch,\n maskGraffitiObject,\n isActorAllowedGraffitiObject,\n compileGraffitiObjectSchema,\n unpackObjectUrl,\n} from \"./utilities.js\";\nimport { Repeater } from \"@repeaterjs/repeater\";\nimport type Ajv from \"ajv\";\nimport type { applyPatch } from \"fast-json-patch\";\n\n/**\n * Constructor options for the GraffitiPoubchDB class.\n */\nexport interface GraffitiLocalOptions {\n /**\n * Options to pass to the PouchDB constructor.\n * Defaults to `{ name: \"graffitiDb\" }`.\n *\n * See the [PouchDB documentation](https://pouchdb.com/api.html#create_database)\n * for available options.\n */\n pouchDBOptions?: PouchDB.Configuration.DatabaseConfiguration;\n /**\n * Includes the scheme and other information (possibly domain name)\n * to prefix prefixes all URLs put in the system. Defaults to `graffiti:local`.\n */\n origin?: string;\n /**\n * Whether to allow putting objects at arbtirary URLs, i.e.\n * URLs that are *not* prefixed with the origin or not generated\n * by the system. Defaults to `false`.\n *\n * Allows this implementation to be used as a client-side cache\n * for remote sources.\n */\n allowSettingArbitraryUrls?: boolean;\n /**\n * Whether to allow the user to set the lastModified field\n * when putting objects. Defaults to `false`.\n *\n * Allows this implementation to be used as a client-side cache\n * for remote sources.\n */\n allowSettinngLastModified?: boolean;\n /**\n * An optional Ajv instance to use for schema validation.\n * If not provided, an internal instance will be created.\n */\n ajv?: Ajv;\n}\n\nconst DEFAULT_ORIGIN = \"graffiti:local:\";\n\ntype GraffitiObjectWithTombstone = GraffitiObjectBase & { tombstone: boolean };\n\n/**\n * An implementation of only the database operations of the\n * GraffitiAPI without synchronization or session management.\n */\nexport class GraffitiLocalDatabase\n implements Omit<Graffiti, \"login\" | \"logout\" | \"sessionEvents\">\n{\n protected db_:\n | Promise<PouchDB.Database<GraffitiObjectWithTombstone>>\n | undefined;\n protected applyPatch_: Promise<typeof applyPatch> | undefined;\n protected ajv_: Promise<Ajv> | undefined;\n protected readonly options: GraffitiLocalOptions;\n protected readonly origin: string;\n\n get db() {\n if (!this.db_) {\n this.db_ = (async () => {\n const { default: PouchDB } = await import(\"pouchdb\");\n const pouchDbOptions = {\n name: \"graffitiDb\",\n ...this.options.pouchDBOptions,\n };\n const db = new PouchDB<GraffitiObjectWithTombstone>(\n pouchDbOptions.name,\n pouchDbOptions,\n );\n await db\n //@ts-ignore\n .put({\n _id: \"_design/indexes\",\n views: {\n objectsPerChannelAndLastModified: {\n map: function (object: GraffitiObjectWithTombstone) {\n const paddedLastModified = object.lastModified\n .toString()\n .padStart(15, \"0\");\n object.channels.forEach(function (channel) {\n const id =\n encodeURIComponent(channel) + \"/\" + paddedLastModified;\n //@ts-ignore\n emit(id);\n });\n }.toString(),\n },\n orphansPerActorAndLastModified: {\n map: function (object: GraffitiObjectWithTombstone) {\n if (object.channels.length === 0) {\n const paddedLastModified = object.lastModified\n .toString()\n .padStart(15, \"0\");\n const id =\n encodeURIComponent(object.actor) +\n \"/\" +\n paddedLastModified;\n //@ts-ignore\n emit(id);\n }\n }.toString(),\n },\n channelStatsPerActor: {\n map: function (object: GraffitiObjectWithTombstone) {\n if (object.tombstone) return;\n object.channels.forEach(function (channel) {\n const id =\n encodeURIComponent(object.actor) +\n \"/\" +\n encodeURIComponent(channel);\n //@ts-ignore\n emit(id, object.lastModified);\n });\n }.toString(),\n reduce: \"_stats\",\n },\n },\n })\n //@ts-ignore\n .catch((error) => {\n if (\n error &&\n typeof error === \"object\" &&\n \"name\" in error &&\n error.name === \"conflict\"\n ) {\n // Design document already exists\n return;\n } else {\n throw error;\n }\n });\n return db;\n })();\n }\n return this.db_;\n }\n\n protected get applyPatch() {\n if (!this.applyPatch_) {\n this.applyPatch_ = (async () => {\n const { applyPatch } = await import(\"fast-json-patch\");\n return applyPatch;\n })();\n }\n return this.applyPatch_;\n }\n\n protected get ajv() {\n if (!this.ajv_) {\n this.ajv_ = this.options.ajv\n ? Promise.resolve(this.options.ajv)\n : (async () => {\n const { default: Ajv } = await import(\"ajv\");\n return new Ajv({ strict: false });\n })();\n }\n return this.ajv_;\n }\n\n protected extractGraffitiObject(\n object: GraffitiObjectWithTombstone,\n ): GraffitiObjectBase {\n const { value, channels, allowed, url, actor, lastModified } = object;\n return {\n value,\n channels,\n allowed,\n url,\n actor,\n lastModified,\n };\n }\n\n constructor(options?: GraffitiLocalOptions) {\n this.options = options ?? {};\n this.origin = this.options.origin ?? DEFAULT_ORIGIN;\n if (!this.origin.endsWith(\":\") && !this.origin.endsWith(\"/\")) {\n this.origin += \"/\";\n }\n }\n\n protected async allDocsAtLocation(objectUrl: string | GraffitiObjectUrl) {\n const url = unpackObjectUrl(objectUrl) + \"/\";\n const results = await (\n await this.db\n ).allDocs({\n startkey: url,\n endkey: url + \"\\uffff\", // \\uffff is the last unicode character\n include_docs: true,\n });\n const docs = results.rows\n .map((row) => row.doc)\n // Remove undefined docs\n .reduce<\n PouchDB.Core.ExistingDocument<\n GraffitiObjectWithTombstone & PouchDB.Core.AllDocsMeta\n >[]\n >((acc, doc) => {\n if (doc) acc.push(doc);\n return acc;\n }, []);\n return docs;\n }\n\n protected docId(objectUrl: GraffitiObjectUrl) {\n return objectUrl.url + \"/\" + randomBase64();\n }\n\n get: Graffiti[\"get\"] = async (...args) => {\n const [urlObject, schema, session] = args;\n\n const docsAll = await this.allDocsAtLocation(urlObject);\n\n // Filter out ones not allowed\n const docs = docsAll.filter((doc) =>\n isActorAllowedGraffitiObject(doc, session),\n );\n if (!docs.length)\n throw new GraffitiErrorNotFound(\n \"The object you are trying to get either does not exist or you are not allowed to see it\",\n );\n\n // Get the most recent document\n const doc = docs.reduce((a, b) =>\n a.lastModified > b.lastModified ||\n (a.lastModified === b.lastModified && !a.tombstone && b.tombstone)\n ? a\n : b,\n );\n\n if (doc.tombstone) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to get either does not exist or you are not allowed to see it\",\n );\n }\n\n const object = this.extractGraffitiObject(doc);\n\n // Mask out the allowed list and channels\n // if the user is not the owner\n maskGraffitiObject(object, [], session);\n\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n if (!validate(object)) {\n throw new GraffitiErrorSchemaMismatch();\n }\n return object;\n };\n\n /**\n * Deletes all docs at a particular location.\n * If the `keepLatest` flag is set to true,\n * the doc with the most recent timestamp will be\n * spared. If there are multiple docs with the same\n * timestamp, the one with the highest `_id` will be\n * spared.\n */\n protected async deleteAtLocation(\n url: GraffitiObjectUrl | string,\n options: {\n keepLatest?: boolean;\n session?: GraffitiSession;\n } = {\n keepLatest: false,\n },\n ) {\n const docsAtLocationAll = await this.allDocsAtLocation(url);\n const docsAtLocationAllowed = options.session\n ? docsAtLocationAll.filter((doc) =>\n isActorAllowedGraffitiObject(doc, options.session),\n )\n : docsAtLocationAll;\n if (!docsAtLocationAllowed.length) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to delete either does not exist or you are not allowed to see it\",\n );\n } else if (\n options.session &&\n docsAtLocationAllowed.some((doc) => doc.actor !== options.session?.actor)\n ) {\n throw new GraffitiErrorForbidden(\n \"You cannot delete an object owned by another actor\",\n );\n }\n const docsAtLocation = docsAtLocationAllowed.filter(\n (doc) => !doc.tombstone,\n );\n if (!docsAtLocation.length) return undefined;\n\n // Get the most recent lastModified timestamp.\n const latestModified = docsAtLocation\n .map((doc) => doc.lastModified)\n .reduce((a, b) => (a > b ? a : b));\n\n // Delete all old docs\n const docsToDelete = docsAtLocation.filter(\n (doc) => !options.keepLatest || doc.lastModified < latestModified,\n );\n\n // For docs with the same timestamp,\n // keep the one with the highest _id\n // to break concurrency ties\n const concurrentDocsAll = docsAtLocation.filter(\n (doc) => options.keepLatest && doc.lastModified === latestModified,\n );\n if (concurrentDocsAll.length) {\n const keepDocId = concurrentDocsAll\n .map((doc) => doc._id)\n .reduce((a, b) => (a > b ? a : b));\n const concurrentDocsToDelete = concurrentDocsAll.filter(\n (doc) => doc._id !== keepDocId,\n );\n docsToDelete.push(...concurrentDocsToDelete);\n }\n\n const lastModified = options.keepLatest\n ? latestModified\n : new Date().getTime();\n\n const deleteResults = await (\n await this.db\n ).bulkDocs<GraffitiObjectBase>(\n docsToDelete.map((doc) => ({\n ...doc,\n tombstone: true,\n lastModified,\n })),\n );\n\n // Get one of the docs that was deleted\n let deletedObject: GraffitiObjectBase | undefined = undefined;\n for (const resultOrError of deleteResults) {\n if (\"ok\" in resultOrError) {\n const { id } = resultOrError;\n const deletedDoc = docsToDelete.find((doc) => doc._id === id);\n if (deletedDoc) {\n deletedObject = {\n ...this.extractGraffitiObject(deletedDoc),\n lastModified,\n };\n break;\n }\n }\n }\n\n return deletedObject;\n }\n\n delete: Graffiti[\"delete\"] = async (...args) => {\n const [url, session] = args;\n const deletedObject = await this.deleteAtLocation(url, {\n session,\n });\n if (!deletedObject) {\n throw new GraffitiErrorNotFound(\"The object has already been deleted\");\n }\n return deletedObject;\n };\n\n put: Graffiti[\"put\"] = async (...args) => {\n const [objectPartial, session] = args;\n if (objectPartial.actor && objectPartial.actor !== session.actor) {\n throw new GraffitiErrorForbidden(\n \"Cannot put an object with a different actor than the session actor\",\n );\n }\n\n if (objectPartial.url) {\n let oldObject: GraffitiObjectBase | undefined;\n try {\n oldObject = await this.get(objectPartial.url, {}, session);\n } catch (e) {\n if (e instanceof GraffitiErrorNotFound) {\n if (!this.options.allowSettingArbitraryUrls) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to replace does not exist or you are not allowed to see it\",\n );\n }\n } else {\n throw e;\n }\n }\n if (oldObject?.actor !== session.actor) {\n throw new GraffitiErrorForbidden(\n \"The object you are trying to replace is owned by another actor\",\n );\n }\n }\n\n const lastModified =\n ((this.options.allowSettinngLastModified ?? false) &&\n objectPartial.lastModified) ||\n new Date().getTime();\n\n const object: GraffitiObjectWithTombstone = {\n value: objectPartial.value,\n channels: objectPartial.channels,\n allowed: objectPartial.allowed,\n url: objectPartial.url ?? this.origin + randomBase64(),\n actor: session.actor,\n tombstone: false,\n lastModified,\n };\n\n await (\n await this.db\n ).put({\n _id: this.docId(object),\n ...object,\n });\n\n // Delete the old object\n const previousObject = await this.deleteAtLocation(object, {\n keepLatest: true,\n });\n if (previousObject) {\n return previousObject;\n } else {\n return {\n ...object,\n value: {},\n channels: [],\n allowed: [],\n tombstone: true,\n };\n }\n };\n\n patch: Graffiti[\"patch\"] = async (...args) => {\n const [patch, url, session] = args;\n let originalObject: GraffitiObjectBase;\n try {\n originalObject = await this.get(url, {}, session);\n } catch (e) {\n if (e instanceof GraffitiErrorNotFound) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to patch does not exist or you are not allowed to see it\",\n );\n } else {\n throw e;\n }\n }\n if (originalObject.actor !== session.actor) {\n throw new GraffitiErrorForbidden(\n \"The object you are trying to patch is owned by another actor\",\n );\n }\n\n // Patch it outside of the database\n const patchObject: GraffitiObjectBase = { ...originalObject };\n for (const prop of [\"value\", \"channels\", \"allowed\"] as const) {\n applyGraffitiPatch(await this.applyPatch, prop, patch, patchObject);\n }\n\n // Make sure the value is an object\n if (\n typeof patchObject.value !== \"object\" ||\n Array.isArray(patchObject.value) ||\n !patchObject.value\n ) {\n throw new GraffitiErrorPatchError(\"value is no longer an object\");\n }\n\n // Make sure the channels are an array of strings\n if (\n !Array.isArray(patchObject.channels) ||\n !patchObject.channels.every((channel) => typeof channel === \"string\")\n ) {\n throw new GraffitiErrorPatchError(\n \"channels are no longer an array of strings\",\n );\n }\n\n // Make sure the allowed list is an array of strings or undefined\n if (\n patchObject.allowed &&\n (!Array.isArray(patchObject.allowed) ||\n !patchObject.allowed.every((allowed) => typeof allowed === \"string\"))\n ) {\n throw new GraffitiErrorPatchError(\n \"allowed list is not an array of strings\",\n );\n }\n\n patchObject.lastModified = new Date().getTime();\n await (\n await this.db\n ).put({\n ...patchObject,\n tombstone: false,\n _id: this.docId(patchObject),\n });\n\n // Delete the old object\n await this.deleteAtLocation(patchObject, {\n keepLatest: true,\n });\n\n return {\n ...originalObject,\n lastModified: patchObject.lastModified,\n };\n };\n\n protected queryLastModifiedSuffixes(\n schema: JSONSchema,\n lastModified?: number,\n ) {\n // Use the index for queries over ranges of lastModified\n let startKeySuffix = \"\";\n let endKeySuffix = \"\\uffff\";\n if (\n typeof schema === \"object\" &&\n schema.properties?.lastModified &&\n typeof schema.properties.lastModified === \"object\"\n ) {\n const lastModifiedSchema = schema.properties.lastModified;\n\n const minimum =\n lastModified && lastModifiedSchema.minimum\n ? Math.max(lastModified, lastModifiedSchema.minimum)\n : (lastModified ?? lastModifiedSchema.minimum);\n const exclusiveMinimum = lastModifiedSchema.exclusiveMinimum;\n\n let intMinimum: number | undefined;\n if (exclusiveMinimum !== undefined) {\n intMinimum = Math.ceil(exclusiveMinimum);\n intMinimum === exclusiveMinimum && intMinimum++;\n } else if (minimum !== undefined) {\n intMinimum = Math.ceil(minimum);\n }\n\n if (intMinimum !== undefined) {\n startKeySuffix = intMinimum.toString().padStart(15, \"0\");\n }\n\n const maximum = lastModifiedSchema.maximum;\n const exclusiveMaximum = lastModifiedSchema.exclusiveMaximum;\n\n let intMaximum: number | undefined;\n if (exclusiveMaximum !== undefined) {\n intMaximum = Math.floor(exclusiveMaximum);\n intMaximum === exclusiveMaximum && intMaximum--;\n } else if (maximum !== undefined) {\n intMaximum = Math.floor(maximum);\n }\n\n if (intMaximum !== undefined) {\n endKeySuffix = intMaximum.toString().padStart(15, \"0\");\n }\n }\n return {\n startKeySuffix,\n endKeySuffix,\n };\n }\n\n protected discoverMeta<Schema extends JSONSchema>(\n channels: string[],\n schema: Schema,\n session?: GraffitiSession | null,\n ifModifiedSince?: number,\n ): GraffitiStream<GraffitiObject<Schema>> {\n const { startKeySuffix, endKeySuffix } = this.queryLastModifiedSuffixes(\n schema,\n ifModifiedSince,\n );\n\n // Don't return tombstones on the first pass\n const showTombstones = ifModifiedSince !== undefined;\n\n const repeater: GraffitiStream<GraffitiObject<typeof schema>> =\n // @ts-ignore\n new Repeater(async (push, stop) => {\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n\n const processedIds = new Set<string>();\n\n for (const channel of channels) {\n const keyPrefix = encodeURIComponent(channel) + \"/\";\n const startkey = keyPrefix + startKeySuffix;\n const endkey = keyPrefix + endKeySuffix;\n\n const result = await (\n await this.db\n ).query<GraffitiObjectWithTombstone>(\n \"indexes/objectsPerChannelAndLastModified\",\n { startkey, endkey, include_docs: true },\n );\n\n for (const row of result.rows) {\n const doc = row.doc;\n if (!doc) continue;\n\n if (!showTombstones && doc.tombstone) continue;\n\n const object = this.extractGraffitiObject(doc);\n\n if (!ifModifiedSince || object.lastModified > ifModifiedSince) {\n ifModifiedSince = object.lastModified;\n }\n\n // Don't double return the same object\n // (which can happen if it's in multiple channels)\n if (processedIds.has(doc._id)) continue;\n processedIds.add(doc._id);\n\n // Make sure the user is allowed to see it\n if (!isActorAllowedGraffitiObject(doc, session)) continue;\n\n // Mask out the allowed list and channels\n // if the user is not the owner\n maskGraffitiObject(object, channels, session);\n\n // Check that it matches the schema\n if (validate(object)) {\n await push({\n value: object,\n ...(doc.tombstone ? { tombstone: true } : {}),\n });\n }\n }\n }\n stop();\n\n const cursor: string =\n \"discover:\" +\n JSON.stringify({\n channels,\n schema,\n ifModifiedSince,\n actor: session?.actor,\n });\n return {\n cursor,\n continue: () =>\n this.continueStream(cursor, session) as GraffitiStream<\n GraffitiObject<Schema>\n >,\n };\n });\n\n return repeater;\n }\n\n discover: Graffiti[\"discover\"] = (...args) => {\n return this.discoverMeta<(typeof args)[1]>(...args);\n };\n\n protected recoverOrphansMeta<Schema extends JSONSchema>(\n schema: Schema,\n session: GraffitiSession,\n ifModifiedSince?: number,\n ): GraffitiStream<GraffitiObject<Schema>> {\n const { startKeySuffix, endKeySuffix } = this.queryLastModifiedSuffixes(\n schema,\n ifModifiedSince,\n );\n const keyPrefix = encodeURIComponent(session.actor) + \"/\";\n const startkey = keyPrefix + startKeySuffix;\n const endkey = keyPrefix + endKeySuffix;\n\n // Don't return tombstones on the first pass\n const showTombstones = ifModifiedSince !== undefined;\n\n const repeater: GraffitiStream<GraffitiObject<Schema>> =\n // @ts-ignore\n new Repeater(async (push, stop) => {\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n\n const result = await (\n await this.db\n ).query<GraffitiObjectWithTombstone>(\n \"indexes/orphansPerActorAndLastModified\",\n {\n startkey,\n endkey,\n include_docs: true,\n },\n );\n\n for (const row of result.rows) {\n const doc = row.doc;\n if (!doc) continue;\n\n if (!showTombstones && doc.tombstone) continue;\n\n if (!ifModifiedSince || doc.lastModified > ifModifiedSince) {\n ifModifiedSince = doc.lastModified;\n }\n\n // No masking/access necessary because\n // the objects are all owned by the querier\n\n const object = this.extractGraffitiObject(doc);\n if (validate(object)) {\n await push({\n value: object,\n ...(doc.tombstone ? { tombstone: true } : {}),\n });\n }\n }\n stop();\n const cursor: string =\n \"recover-orphans:\" +\n JSON.stringify({\n schema,\n actor: session.actor,\n ifModifiedSince,\n });\n return {\n cursor,\n continue: () =>\n this.continueStream(cursor, session) as GraffitiStream<\n GraffitiObject<Schema>\n >,\n };\n });\n\n return repeater;\n }\n\n recoverOrphans: Graffiti[\"recoverOrphans\"] = (...args) => {\n return this.recoverOrphansMeta<(typeof args)[0]>(...args);\n };\n\n channelStats: Graffiti[\"channelStats\"] = (session) => {\n const repeater: ReturnType<typeof Graffiti.prototype.channelStats> =\n new Repeater(async (push, stop) => {\n const keyPrefix = encodeURIComponent(session.actor) + \"/\";\n const result = await (\n await this.db\n ).query(\"indexes/channelStatsPerActor\", {\n startkey: keyPrefix,\n endkey: keyPrefix + \"\\uffff\",\n reduce: true,\n group: true,\n });\n for (const row of result.rows) {\n const channelEncoded = row.key.split(\"/\")[1];\n if (typeof channelEncoded !== \"string\") continue;\n const { count, max: lastModified } = row.value;\n if (typeof count !== \"number\" || typeof lastModified !== \"number\")\n continue;\n await push({\n value: {\n channel: decodeURIComponent(channelEncoded),\n count,\n lastModified,\n },\n });\n }\n stop();\n const cursor = \"channel-stats\";\n return {\n cursor,\n continue: () =>\n this.continueStream(\n cursor,\n session,\n ) as GraffitiStream<ChannelStats>,\n };\n });\n\n return repeater;\n };\n\n continueStream: Graffiti[\"continueStream\"] = (cursor, session) => {\n if (cursor === \"channel-stats\") {\n if (!session) {\n throw new GraffitiErrorForbidden(\n \"You must be logged in to continue the stream\",\n );\n }\n return this.channelStats(session);\n } else if (cursor.startsWith(\"recover-orphans:\")) {\n const { schema, actor, ifModifiedSince } = JSON.parse(\n cursor.slice(\"recover-orphans:\".length),\n );\n if (!session || session.actor !== actor) {\n throw new GraffitiErrorForbidden(\n \"You must be logged in as the actor same actor who started the stream\",\n );\n }\n return this.recoverOrphansMeta(schema, session, ifModifiedSince);\n } else if (cursor.startsWith(\"discover:\")) {\n const { channels, schema, actor, ifModifiedSince } = JSON.parse(\n cursor.slice(\"discover:\".length),\n );\n if (session?.actor !== actor) {\n throw new GraffitiErrorForbidden(\n \"You must be logged in as the actor same actor who started the stream\",\n );\n }\n return this.discoverMeta(channels, schema, session, ifModifiedSince);\n } else {\n throw new GraffitiErrorNotFound(\"Cursor not found\");\n }\n };\n}\n"],
|
|
5
|
-
"mappings": "AAUA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AA6CzB,MAAM,iBAAiB;AAQhB,MAAM,sBAEb;AAAA,EACY;AAAA,EAGA;AAAA,EACA;AAAA,EACS;AAAA,EACA;AAAA,EAEnB,IAAI,KAAK;AACP,QAAI,CAAC,KAAK,KAAK;AACb,WAAK,OAAO,YAAY;AACtB,cAAM,EAAE,SAAS,QAAQ,IAAI,MAAM,OAAO,SAAS;AACnD,cAAM,iBAAiB;AAAA,UACrB,MAAM;AAAA,UACN,GAAG,KAAK,QAAQ;AAAA,QAClB;AACA,cAAM,KAAK,I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AAChD,YAAM,EAAE,QAAQ,OAAO,gBAAgB,IAAI,KAAK;AAAA,QAC9C,OAAO,MAAM,mBAAmB,MAAM;AAAA,MACxC;AACA,UAAI,CAAC,WAAW,QAAQ,UAAU,OAAO;AACvC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK,mBAAmB,QAAQ,SAAS,eAAe;AAAA,IACjE,WAAW,OAAO,WAAW,WAAW,GAAG;AACzC,YAAM,EAAE,UAAU,QAAQ,OAAO,gBAAgB,IAAI,KAAK;AAAA,QACxD,OAAO,MAAM,YAAY,MAAM;AAAA,MACjC;AACA,UAAI,SAAS,UAAU,OAAO;AAC5B,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK,aAAa,UAAU,QAAQ,SAAS,eAAe;AAAA,IACrE,OAAO;AACL,YAAM,IAAI,sBAAsB,kBAAkB;AAAA,IACpD;AAAA,EACF;AACF;",
|
|
6
|
-
"names": ["doc"]
|
|
4
|
+
"sourcesContent": ["import type {\n Graffiti,\n GraffitiObjectBase,\n GraffitiObjectUrl,\n JSONSchema,\n GraffitiSession,\n GraffitiObjectStreamContinue,\n GraffitiObjectStreamContinueEntry,\n} from \"@graffiti-garden/api\";\nimport {\n GraffitiErrorNotFound,\n GraffitiErrorSchemaMismatch,\n GraffitiErrorForbidden,\n GraffitiErrorPatchError,\n} from \"@graffiti-garden/api\";\nimport {\n randomBase64,\n applyGraffitiPatch,\n maskGraffitiObject,\n isActorAllowedGraffitiObject,\n compileGraffitiObjectSchema,\n unpackObjectUrl,\n} from \"./utilities.js\";\nimport type Ajv from \"ajv\";\nimport type { applyPatch } from \"fast-json-patch\";\n\n/**\n * Constructor options for the GraffitiPoubchDB class.\n */\nexport interface GraffitiLocalOptions {\n /**\n * Options to pass to the PouchDB constructor.\n * Defaults to `{ name: \"graffitiDb\" }`.\n *\n * See the [PouchDB documentation](https://pouchdb.com/api.html#create_database)\n * for available options.\n */\n pouchDBOptions?: PouchDB.Configuration.DatabaseConfiguration;\n /**\n * Includes the scheme and other information (possibly domain name)\n * to prefix prefixes all URLs put in the system. Defaults to `graffiti:local`.\n */\n origin?: string;\n /**\n * Whether to allow putting objects at arbtirary URLs, i.e.\n * URLs that are *not* prefixed with the origin or not generated\n * by the system. Defaults to `false`.\n *\n * Allows this implementation to be used as a client-side cache\n * for remote sources.\n */\n allowSettingArbitraryUrls?: boolean;\n /**\n * Whether to allow the user to set the lastModified field\n * when putting objects. Defaults to `false`.\n *\n * Allows this implementation to be used as a client-side cache\n * for remote sources.\n */\n allowSettinngLastModified?: boolean;\n /**\n * An optional Ajv instance to use for schema validation.\n * If not provided, an internal instance will be created.\n */\n ajv?: Ajv;\n}\n\nconst DEFAULT_ORIGIN = \"graffiti:local:\";\nconst LAST_MODIFIED_BUFFER = 60000;\n\ntype GraffitiObjectWithTombstone = GraffitiObjectBase & { tombstone: boolean };\n\n/**\n * An implementation of only the database operations of the\n * GraffitiAPI without synchronization or session management.\n */\nexport class GraffitiLocalDatabase\n implements Omit<Graffiti, \"login\" | \"logout\" | \"sessionEvents\">\n{\n protected db_:\n | Promise<PouchDB.Database<GraffitiObjectWithTombstone>>\n | undefined;\n protected applyPatch_: Promise<typeof applyPatch> | undefined;\n protected ajv_: Promise<Ajv> | undefined;\n protected readonly options: GraffitiLocalOptions;\n protected readonly origin: string;\n\n get db() {\n if (!this.db_) {\n this.db_ = (async () => {\n const { default: PouchDB } = await import(\"pouchdb\");\n const pouchDbOptions = {\n name: \"graffitiDb\",\n ...this.options.pouchDBOptions,\n };\n const db = new PouchDB<GraffitiObjectWithTombstone>(\n pouchDbOptions.name,\n pouchDbOptions,\n );\n await db\n //@ts-ignore\n .put({\n _id: \"_design/indexes\",\n views: {\n objectsPerChannelAndLastModified: {\n map: function (object: GraffitiObjectWithTombstone) {\n const paddedLastModified = object.lastModified\n .toString()\n .padStart(15, \"0\");\n object.channels.forEach(function (channel) {\n const id =\n encodeURIComponent(channel) + \"/\" + paddedLastModified;\n //@ts-ignore\n emit(id);\n });\n }.toString(),\n },\n orphansPerActorAndLastModified: {\n map: function (object: GraffitiObjectWithTombstone) {\n if (object.channels.length === 0) {\n const paddedLastModified = object.lastModified\n .toString()\n .padStart(15, \"0\");\n const id =\n encodeURIComponent(object.actor) +\n \"/\" +\n paddedLastModified;\n //@ts-ignore\n emit(id);\n }\n }.toString(),\n },\n channelStatsPerActor: {\n map: function (object: GraffitiObjectWithTombstone) {\n if (object.tombstone) return;\n object.channels.forEach(function (channel) {\n const id =\n encodeURIComponent(object.actor) +\n \"/\" +\n encodeURIComponent(channel);\n //@ts-ignore\n emit(id, object.lastModified);\n });\n }.toString(),\n reduce: \"_stats\",\n },\n },\n })\n //@ts-ignore\n .catch((error) => {\n if (\n error &&\n typeof error === \"object\" &&\n \"name\" in error &&\n error.name === \"conflict\"\n ) {\n // Design document already exists\n return;\n } else {\n throw error;\n }\n });\n return db;\n })();\n }\n return this.db_;\n }\n\n protected get applyPatch() {\n if (!this.applyPatch_) {\n this.applyPatch_ = (async () => {\n const imported = await import(\"fast-json-patch\");\n return imported.applyPatch || imported.default.applyPatch;\n })();\n }\n return this.applyPatch_;\n }\n\n protected get ajv() {\n if (!this.ajv_) {\n this.ajv_ = this.options.ajv\n ? Promise.resolve(this.options.ajv)\n : (async () => {\n const { default: Ajv } = await import(\"ajv\");\n return new Ajv({ strict: false });\n })();\n }\n return this.ajv_;\n }\n\n protected extractGraffitiObject(\n object: GraffitiObjectWithTombstone,\n ): GraffitiObjectBase {\n const { value, channels, allowed, url, actor, lastModified } = object;\n return {\n value,\n channels,\n allowed,\n url,\n actor,\n lastModified,\n };\n }\n\n constructor(options?: GraffitiLocalOptions) {\n this.options = options ?? {};\n this.origin = this.options.origin ?? DEFAULT_ORIGIN;\n if (!this.origin.endsWith(\":\") && !this.origin.endsWith(\"/\")) {\n this.origin += \"/\";\n }\n }\n\n protected async allDocsAtLocation(objectUrl: string | GraffitiObjectUrl) {\n const url = unpackObjectUrl(objectUrl) + \"/\";\n const results = await (\n await this.db\n ).allDocs({\n startkey: url,\n endkey: url + \"\\uffff\", // \\uffff is the last unicode character\n include_docs: true,\n });\n const docs = results.rows\n .map((row) => row.doc)\n // Remove undefined docs\n .reduce<\n PouchDB.Core.ExistingDocument<\n GraffitiObjectWithTombstone & PouchDB.Core.AllDocsMeta\n >[]\n >((acc, doc) => {\n if (doc) acc.push(doc);\n return acc;\n }, []);\n return docs;\n }\n\n protected docId(objectUrl: GraffitiObjectUrl) {\n return objectUrl.url + \"/\" + randomBase64();\n }\n\n get: Graffiti[\"get\"] = async (...args) => {\n const [urlObject, schema, session] = args;\n\n const docsAll = await this.allDocsAtLocation(urlObject);\n\n // Filter out ones not allowed\n const docs = docsAll.filter((doc) =>\n isActorAllowedGraffitiObject(doc, session),\n );\n if (!docs.length)\n throw new GraffitiErrorNotFound(\n \"The object you are trying to get either does not exist or you are not allowed to see it\",\n );\n\n // Get the most recent document\n const doc = docs.reduce((a, b) =>\n a.lastModified > b.lastModified ||\n (a.lastModified === b.lastModified && !a.tombstone && b.tombstone)\n ? a\n : b,\n );\n\n if (doc.tombstone) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to get either does not exist or you are not allowed to see it\",\n );\n }\n\n const object = this.extractGraffitiObject(doc);\n\n // Mask out the allowed list and channels\n // if the user is not the owner\n maskGraffitiObject(object, [], session);\n\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n if (!validate(object)) {\n throw new GraffitiErrorSchemaMismatch();\n }\n return object;\n };\n\n /**\n * Deletes all docs at a particular location.\n * If the `keepLatest` flag is set to true,\n * the doc with the most recent timestamp will be\n * spared. If there are multiple docs with the same\n * timestamp, the one with the highest `_id` will be\n * spared.\n */\n protected async deleteAtLocation(\n url: GraffitiObjectUrl | string,\n options: {\n keepLatest?: boolean;\n session?: GraffitiSession;\n } = {\n keepLatest: false,\n },\n ) {\n const docsAtLocationAll = await this.allDocsAtLocation(url);\n const docsAtLocationAllowed = options.session\n ? docsAtLocationAll.filter((doc) =>\n isActorAllowedGraffitiObject(doc, options.session),\n )\n : docsAtLocationAll;\n if (!docsAtLocationAllowed.length) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to delete either does not exist or you are not allowed to see it\",\n );\n } else if (\n options.session &&\n docsAtLocationAllowed.some((doc) => doc.actor !== options.session?.actor)\n ) {\n throw new GraffitiErrorForbidden(\n \"You cannot delete an object owned by another actor\",\n );\n }\n const docsAtLocation = docsAtLocationAllowed.filter(\n (doc) => !doc.tombstone,\n );\n if (!docsAtLocation.length) return undefined;\n\n // Get the most recent lastModified timestamp.\n const latestModified = docsAtLocation\n .map((doc) => doc.lastModified)\n .reduce((a, b) => (a > b ? a : b));\n\n // Delete all old docs\n const docsToDelete = docsAtLocation.filter(\n (doc) => !options.keepLatest || doc.lastModified < latestModified,\n );\n\n // For docs with the same timestamp,\n // keep the one with the highest _id\n // to break concurrency ties\n const concurrentDocsAll = docsAtLocation.filter(\n (doc) => options.keepLatest && doc.lastModified === latestModified,\n );\n if (concurrentDocsAll.length) {\n const keepDocId = concurrentDocsAll\n .map((doc) => doc._id)\n .reduce((a, b) => (a > b ? a : b));\n const concurrentDocsToDelete = concurrentDocsAll.filter(\n (doc) => doc._id !== keepDocId,\n );\n docsToDelete.push(...concurrentDocsToDelete);\n }\n\n const lastModified = options.keepLatest\n ? latestModified\n : new Date().getTime();\n\n const deleteResults = await (\n await this.db\n ).bulkDocs<GraffitiObjectBase>(\n docsToDelete.map((doc) => ({\n ...doc,\n tombstone: true,\n lastModified,\n })),\n );\n\n // Get one of the docs that was deleted\n let deletedObject: GraffitiObjectBase | undefined = undefined;\n for (const resultOrError of deleteResults) {\n if (\"ok\" in resultOrError) {\n const { id } = resultOrError;\n const deletedDoc = docsToDelete.find((doc) => doc._id === id);\n if (deletedDoc) {\n deletedObject = {\n ...this.extractGraffitiObject(deletedDoc),\n lastModified,\n };\n break;\n }\n }\n }\n\n return deletedObject;\n }\n\n delete: Graffiti[\"delete\"] = async (...args) => {\n const [url, session] = args;\n const deletedObject = await this.deleteAtLocation(url, {\n session,\n });\n if (!deletedObject) {\n throw new GraffitiErrorNotFound(\"The object has already been deleted\");\n }\n return deletedObject;\n };\n\n put: Graffiti[\"put\"] = async (...args) => {\n const [objectPartial, session] = args;\n if (objectPartial.actor && objectPartial.actor !== session.actor) {\n throw new GraffitiErrorForbidden(\n \"Cannot put an object with a different actor than the session actor\",\n );\n }\n\n if (objectPartial.url) {\n let oldObject: GraffitiObjectBase | undefined;\n try {\n oldObject = await this.get(objectPartial.url, {}, session);\n } catch (e) {\n if (e instanceof GraffitiErrorNotFound) {\n if (!this.options.allowSettingArbitraryUrls) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to replace does not exist or you are not allowed to see it\",\n );\n }\n } else {\n throw e;\n }\n }\n if (oldObject?.actor !== session.actor) {\n throw new GraffitiErrorForbidden(\n \"The object you are trying to replace is owned by another actor\",\n );\n }\n }\n\n const lastModified =\n ((this.options.allowSettinngLastModified ?? false) &&\n objectPartial.lastModified) ||\n new Date().getTime();\n\n const object: GraffitiObjectWithTombstone = {\n value: objectPartial.value,\n channels: objectPartial.channels,\n allowed: objectPartial.allowed,\n url: objectPartial.url ?? this.origin + randomBase64(),\n actor: session.actor,\n tombstone: false,\n lastModified,\n };\n\n await (\n await this.db\n ).put({\n _id: this.docId(object),\n ...object,\n });\n\n // Delete the old object\n const previousObject = await this.deleteAtLocation(object, {\n keepLatest: true,\n });\n if (previousObject) {\n return previousObject;\n } else {\n return {\n ...object,\n value: {},\n channels: [],\n allowed: [],\n tombstone: true,\n };\n }\n };\n\n patch: Graffiti[\"patch\"] = async (...args) => {\n const [patch, url, session] = args;\n let originalObject: GraffitiObjectBase;\n try {\n originalObject = await this.get(url, {}, session);\n } catch (e) {\n if (e instanceof GraffitiErrorNotFound) {\n throw new GraffitiErrorNotFound(\n \"The object you are trying to patch does not exist or you are not allowed to see it\",\n );\n } else {\n throw e;\n }\n }\n if (originalObject.actor !== session.actor) {\n throw new GraffitiErrorForbidden(\n \"The object you are trying to patch is owned by another actor\",\n );\n }\n\n // Patch it outside of the database\n const patchObject: GraffitiObjectBase = { ...originalObject };\n for (const prop of [\"value\", \"channels\", \"allowed\"] as const) {\n applyGraffitiPatch(await this.applyPatch, prop, patch, patchObject);\n }\n\n // Make sure the value is an object\n if (\n typeof patchObject.value !== \"object\" ||\n Array.isArray(patchObject.value) ||\n !patchObject.value\n ) {\n throw new GraffitiErrorPatchError(\"value is no longer an object\");\n }\n\n // Make sure the channels are an array of strings\n if (\n !Array.isArray(patchObject.channels) ||\n !patchObject.channels.every((channel) => typeof channel === \"string\")\n ) {\n throw new GraffitiErrorPatchError(\n \"channels are no longer an array of strings\",\n );\n }\n\n // Make sure the allowed list is an array of strings or undefined\n if (\n patchObject.allowed &&\n (!Array.isArray(patchObject.allowed) ||\n !patchObject.allowed.every((allowed) => typeof allowed === \"string\"))\n ) {\n throw new GraffitiErrorPatchError(\n \"allowed list is not an array of strings\",\n );\n }\n\n patchObject.lastModified = new Date().getTime();\n await (\n await this.db\n ).put({\n ...patchObject,\n tombstone: false,\n _id: this.docId(patchObject),\n });\n\n // Delete the old object\n await this.deleteAtLocation(patchObject, {\n keepLatest: true,\n });\n\n return {\n ...originalObject,\n lastModified: patchObject.lastModified,\n };\n };\n\n protected queryLastModifiedSuffixes(\n schema: JSONSchema,\n lastModified?: number,\n ) {\n // Use the index for queries over ranges of lastModified\n let startKeySuffix = \"\";\n let endKeySuffix = \"\\uffff\";\n if (\n typeof schema === \"object\" &&\n schema.properties?.lastModified &&\n typeof schema.properties.lastModified === \"object\"\n ) {\n const lastModifiedSchema = schema.properties.lastModified;\n\n const minimum =\n lastModified && lastModifiedSchema.minimum\n ? Math.max(lastModified, lastModifiedSchema.minimum)\n : (lastModified ?? lastModifiedSchema.minimum);\n const exclusiveMinimum = lastModifiedSchema.exclusiveMinimum;\n\n let intMinimum: number | undefined;\n if (exclusiveMinimum !== undefined) {\n intMinimum = Math.ceil(exclusiveMinimum);\n intMinimum === exclusiveMinimum && intMinimum++;\n } else if (minimum !== undefined) {\n intMinimum = Math.ceil(minimum);\n }\n\n if (intMinimum !== undefined) {\n startKeySuffix = intMinimum.toString().padStart(15, \"0\");\n }\n\n const maximum = lastModifiedSchema.maximum;\n const exclusiveMaximum = lastModifiedSchema.exclusiveMaximum;\n\n let intMaximum: number | undefined;\n if (exclusiveMaximum !== undefined) {\n intMaximum = Math.floor(exclusiveMaximum);\n intMaximum === exclusiveMaximum && intMaximum--;\n } else if (maximum !== undefined) {\n intMaximum = Math.floor(maximum);\n }\n\n if (intMaximum !== undefined) {\n endKeySuffix = intMaximum.toString().padStart(15, \"0\");\n }\n }\n return {\n startKeySuffix,\n endKeySuffix,\n };\n }\n\n protected async *streamObjects<Schema extends JSONSchema>(\n index: string,\n startkey: string,\n endkey: string,\n validate: ReturnType<typeof compileGraffitiObjectSchema<Schema>>,\n session: GraffitiSession | undefined | null,\n ifModifiedSince: number | undefined,\n channels?: string[],\n processedIds?: Set<string>,\n ): AsyncGenerator<GraffitiObjectStreamContinueEntry<Schema>> {\n const showTombstones = ifModifiedSince !== undefined;\n\n const result = await (\n await this.db\n ).query<GraffitiObjectWithTombstone>(index, {\n startkey,\n endkey,\n include_docs: true,\n });\n\n for (const row of result.rows) {\n const doc = row.doc;\n if (!doc) continue;\n\n if (processedIds?.has(doc._id)) continue;\n processedIds?.add(doc._id);\n\n if (!showTombstones && doc.tombstone) continue;\n\n const object = this.extractGraffitiObject(doc);\n\n if (channels) {\n if (!isActorAllowedGraffitiObject(object, session)) continue;\n maskGraffitiObject(object, channels, session);\n }\n\n if (!validate(object)) continue;\n\n yield doc.tombstone\n ? {\n tombstone: true,\n object: {\n url: object.url,\n lastModified: object.lastModified,\n },\n }\n : { object };\n }\n }\n\n protected async *discoverMeta<Schema extends JSONSchema>(\n args: Parameters<typeof Graffiti.prototype.discover<Schema>>,\n ifModifiedSince?: number,\n ): AsyncGenerator<\n GraffitiObjectStreamContinueEntry<Schema>,\n number | undefined\n > {\n const [channels, schema, session] = args;\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n const { startKeySuffix, endKeySuffix } = this.queryLastModifiedSuffixes(\n schema,\n ifModifiedSince,\n );\n\n const processedIds = new Set<string>();\n\n const startTime = new Date().getTime();\n\n for (const channel of channels) {\n const keyPrefix = encodeURIComponent(channel) + \"/\";\n const startkey = keyPrefix + startKeySuffix;\n const endkey = keyPrefix + endKeySuffix;\n\n const iterator = this.streamObjects<Schema>(\n \"indexes/objectsPerChannelAndLastModified\",\n startkey,\n endkey,\n validate,\n session,\n ifModifiedSince,\n channels,\n processedIds,\n );\n\n for await (const result of iterator) yield result;\n }\n\n // Subtract a minute to make sure we don't miss any objects\n return startTime - LAST_MODIFIED_BUFFER;\n }\n\n protected async *recoverOrphansMeta<Schema extends JSONSchema>(\n args: Parameters<typeof Graffiti.prototype.recoverOrphans<Schema>>,\n ifModifiedSince?: number,\n ): AsyncGenerator<\n GraffitiObjectStreamContinueEntry<Schema>,\n number | undefined\n > {\n const [schema, session] = args;\n const { startKeySuffix, endKeySuffix } = this.queryLastModifiedSuffixes(\n schema,\n ifModifiedSince,\n );\n const keyPrefix = encodeURIComponent(session.actor) + \"/\";\n const startkey = keyPrefix + startKeySuffix;\n const endkey = keyPrefix + endKeySuffix;\n\n const validate = compileGraffitiObjectSchema(await this.ajv, schema);\n\n const startTime = new Date().getTime();\n\n const iterator = this.streamObjects<Schema>(\n \"indexes/orphansPerActorAndLastModified\",\n startkey,\n endkey,\n validate,\n session,\n ifModifiedSince,\n );\n\n for await (const result of iterator) yield result;\n\n return startTime - LAST_MODIFIED_BUFFER;\n }\n\n protected discoverCursor(\n args: Parameters<typeof Graffiti.prototype.discover<{}>>,\n ifModifiedSince?: number,\n ): string {\n return (\n \"discover:\" +\n JSON.stringify({\n channels: args[0],\n schema: args[1],\n actor: args[2]?.actor,\n ifModifiedSince: ifModifiedSince,\n })\n );\n }\n\n protected async *discoverContinue<Schema extends JSONSchema>(\n args: Parameters<typeof Graffiti.prototype.discover<Schema>>,\n ifModifiedSince?: number,\n ): GraffitiObjectStreamContinue<Schema> {\n const iterator = this.discoverMeta(args, ifModifiedSince);\n\n while (true) {\n const result = await iterator.next();\n if (result.done) {\n const ifModifiedSince = result.value;\n return {\n continue: () => this.discoverContinue<Schema>(args, ifModifiedSince),\n cursor: this.discoverCursor(args, ifModifiedSince),\n };\n }\n yield result.value;\n }\n }\n\n discover: Graffiti[\"discover\"] = (...args) => {\n const iterator = this.discoverMeta(args);\n\n const this_ = this;\n return (async function* () {\n while (true) {\n const result = await iterator.next();\n if (result.done) {\n return {\n continue: () =>\n this_.discoverContinue<(typeof args)[1]>(args, result.value),\n cursor: this_.discoverCursor(args, result.value),\n };\n }\n // Make sure to filter out tombstones\n if (result.value.tombstone) continue;\n yield result.value;\n }\n })();\n };\n\n protected recoverOrphansCursor(\n args: Parameters<typeof Graffiti.prototype.recoverOrphans<{}>>,\n ifModifiedSince?: number,\n ): string {\n return (\n \"orphans:\" +\n JSON.stringify({\n schema: args[0],\n actor: args[1]?.actor,\n ifModifiedSince,\n })\n );\n }\n\n protected async *recoverOrphansContinue<Schema extends JSONSchema>(\n args: Parameters<typeof Graffiti.prototype.recoverOrphans<Schema>>,\n ifModifiedSince?: number,\n ): GraffitiObjectStreamContinue<Schema> {\n const iterator = this.recoverOrphansMeta(args, ifModifiedSince);\n\n while (true) {\n const result = await iterator.next();\n if (result.done) {\n const ifModifiedSince = result.value;\n return {\n continue: () =>\n this.recoverOrphansContinue<Schema>(args, ifModifiedSince),\n cursor: this.recoverOrphansCursor(args, ifModifiedSince),\n };\n }\n yield result.value;\n }\n }\n\n recoverOrphans: Graffiti[\"recoverOrphans\"] = (...args) => {\n const iterator = this.recoverOrphansMeta(args);\n\n const this_ = this;\n return (async function* () {\n while (true) {\n const result = await iterator.next();\n if (result.done) {\n return {\n continue: () =>\n this_.recoverOrphansContinue<(typeof args)[0]>(\n args,\n result.value,\n ),\n cursor: this_.recoverOrphansCursor(args, result.value),\n };\n }\n // Make sure to filter out tombstones\n if (result.value.tombstone) continue;\n yield result.value;\n }\n })();\n };\n\n channelStats: Graffiti[\"channelStats\"] = (session) => {\n const this_ = this;\n return (async function* () {\n const keyPrefix = encodeURIComponent(session.actor) + \"/\";\n const result = await (\n await this_.db\n ).query(\"indexes/channelStatsPerActor\", {\n startkey: keyPrefix,\n endkey: keyPrefix + \"\\uffff\",\n reduce: true,\n group: true,\n });\n for (const row of result.rows) {\n const channelEncoded = row.key.split(\"/\")[1];\n if (typeof channelEncoded !== \"string\") continue;\n const { count, max: lastModified } = row.value;\n if (typeof count !== \"number\" || typeof lastModified !== \"number\")\n continue;\n yield {\n value: {\n channel: decodeURIComponent(channelEncoded),\n count,\n lastModified,\n },\n };\n }\n })();\n };\n\n continueObjectStream: Graffiti[\"continueObjectStream\"] = (\n cursor,\n session,\n ) => {\n if (cursor.startsWith(\"discover:\")) {\n const { channels, schema, actor, ifModifiedSince } = JSON.parse(\n cursor.slice(\"discover:\".length),\n );\n if (actor && actor !== session?.actor) {\n throw new GraffitiErrorForbidden(\n \"Cannot continue a cursor for another actor\",\n );\n }\n return this.discoverContinue<{}>(\n [channels, schema, session],\n ifModifiedSince,\n );\n } else if (cursor.startsWith(\"orphans:\")) {\n const { schema, actor, ifModifiedSince } = JSON.parse(\n cursor.slice(\"orphans:\".length),\n );\n if (!session || actor !== session?.actor) {\n throw new GraffitiErrorForbidden(\n \"Cannot continue a cursor for another actor\",\n );\n }\n return this.recoverOrphansContinue<{}>(\n [schema, session],\n ifModifiedSince,\n );\n } else {\n throw new GraffitiErrorNotFound(\"Cursor not found\");\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA6CP,MAAM,iBAAiB;AACvB,MAAM,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AAA,QACxD,OAAO,MAAM,YAAY,MAAM;AAAA,MACjC;AACA,UAAI,SAAS,UAAU,SAAS,OAAO;AACrC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK;AAAA,QACV,CAAC,UAAU,QAAQ,OAAO;AAAA,QAC1B;AAAA,MACF;AAAA,IACF,WAAW,OAAO,WAAW,UAAU,GAAG;AACxC,YAAM,EAAE,QAAQ,OAAO,gBAAgB,IAAI,KAAK;AAAA,QAC9C,OAAO,MAAM,WAAW,MAAM;AAAA,MAChC;AACA,UAAI,CAAC,WAAW,UAAU,SAAS,OAAO;AACxC,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,aAAO,KAAK;AAAA,QACV,CAAC,QAAQ,OAAO;AAAA,QAChB;AAAA,MACF;AAAA,IACF,OAAO;AACL,YAAM,IAAI,sBAAsB,kBAAkB;AAAA,IACpD;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["doc", "ifModifiedSince"]
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -15,7 +15,7 @@ class GraffitiLocal extends Graffiti {
|
|
|
15
15
|
discover;
|
|
16
16
|
recoverOrphans;
|
|
17
17
|
channelStats;
|
|
18
|
-
|
|
18
|
+
continueObjectStream;
|
|
19
19
|
constructor(options) {
|
|
20
20
|
super();
|
|
21
21
|
const graffitiPouchDbBase = new GraffitiLocalDatabase(options);
|
|
@@ -26,7 +26,7 @@ class GraffitiLocal extends Graffiti {
|
|
|
26
26
|
this.discover = graffitiPouchDbBase.discover.bind(graffitiPouchDbBase);
|
|
27
27
|
this.recoverOrphans = graffitiPouchDbBase.recoverOrphans.bind(graffitiPouchDbBase);
|
|
28
28
|
this.channelStats = graffitiPouchDbBase.channelStats.bind(graffitiPouchDbBase);
|
|
29
|
-
this.
|
|
29
|
+
this.continueObjectStream = graffitiPouchDbBase.continueObjectStream.bind(graffitiPouchDbBase);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
export {
|